Hi Marek

On 3/19/23 18:09, Marek Vasut wrote:
> Add two new callbacks matching the Linux ones. The .set_mode is used to set
> PHY mode and submode, where mode is either USB, Ethernet, and so on, while
> submode is e.g. for Ethernet case RGMII, RMII, and so on. The .set_speed is
> used to configure link speed into the PHY. Unlike the existing configure
> callback, which is used to pass arbitrary custom information to the PHY,
> these two callbacks are used to pass standardized set of information to
> the PHY.
> 
> Signed-off-by: Marek Vasut <marek.vasut+rene...@mailbox.org>
> ---
> Cc: Jim Liu <jim.t90...@gmail.com>
> Cc: Neil Armstrong <neil.armstr...@linaro.org>
> Cc: Patrice Chotard <patrice.chot...@foss.st.com>
> Cc: Samuel Holland <sam...@sholland.org>
> Cc: Sumit Garg <sumit.g...@linaro.org>
> Cc: Weijie Gao <weijie....@mediatek.com>
> ---
>  drivers/phy/phy-uclass.c | 22 ++++++++++++
>  include/generic-phy.h    | 77 ++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 99 insertions(+)
> 
> diff --git a/drivers/phy/phy-uclass.c b/drivers/phy/phy-uclass.c
> index 3fef5135a9c..83e4b63079d 100644
> --- a/drivers/phy/phy-uclass.c
> +++ b/drivers/phy/phy-uclass.c
> @@ -351,6 +351,28 @@ int generic_phy_configure(struct phy *phy, void *params)
>       return ops->configure ? ops->configure(phy, params) : 0;
>  }
>  
> +int generic_phy_set_mode(struct phy *phy, enum phy_mode mode, int submode)
> +{
> +     struct phy_ops const *ops;
> +
> +     if (!generic_phy_valid(phy))
> +             return 0;
> +     ops = phy_dev_ops(phy->dev);
> +
> +     return ops->set_mode ? ops->set_mode(phy, mode, submode) : 0;
> +}
> +
> +int generic_phy_set_speed(struct phy *phy, int speed)
> +{
> +     struct phy_ops const *ops;
> +
> +     if (!generic_phy_valid(phy))
> +             return 0;
> +     ops = phy_dev_ops(phy->dev);
> +
> +     return ops->set_speed ? ops->set_speed(phy, speed) : 0;
> +}
> +
>  int generic_phy_get_bulk(struct udevice *dev, struct phy_bulk *bulk)
>  {
>       int i, ret, count;
> diff --git a/include/generic-phy.h b/include/generic-phy.h
> index 8dca21b1283..bee4de8a0ba 100644
> --- a/include/generic-phy.h
> +++ b/include/generic-phy.h
> @@ -11,6 +11,29 @@
>  
>  struct ofnode_phandle_args;
>  
> +enum phy_mode {
> +     PHY_MODE_INVALID,
> +     PHY_MODE_USB_HOST,
> +     PHY_MODE_USB_HOST_LS,
> +     PHY_MODE_USB_HOST_FS,
> +     PHY_MODE_USB_HOST_HS,
> +     PHY_MODE_USB_HOST_SS,
> +     PHY_MODE_USB_DEVICE,
> +     PHY_MODE_USB_DEVICE_LS,
> +     PHY_MODE_USB_DEVICE_FS,
> +     PHY_MODE_USB_DEVICE_HS,
> +     PHY_MODE_USB_DEVICE_SS,
> +     PHY_MODE_USB_OTG,
> +     PHY_MODE_UFS_HS_A,
> +     PHY_MODE_UFS_HS_B,
> +     PHY_MODE_PCIE,
> +     PHY_MODE_ETHERNET,
> +     PHY_MODE_MIPI_DPHY,
> +     PHY_MODE_SATA,
> +     PHY_MODE_LVDS,
> +     PHY_MODE_DP
> +};
> +
>  /**
>   * struct phy - A handle to (allowing control of) a single phy port.
>   *
> @@ -136,6 +159,32 @@ struct phy_ops {
>        * Return: 0 if OK, or a negative error code
>        */
>       int     (*configure)(struct phy *phy, void *params);
> +
> +     /**
> +      * set_mode - set PHY device mode
> +      *
> +      * @phy:        PHY port to be configured
> +      * @mode: PHY mode
> +      * @submode: PHY submode
> +      *
> +      * Configure PHY mode (e.g. USB, Ethernet, ...) and submode
> +      * (e.g. for Ethernet this can be RGMII).
> +      *
> +      * Return: 0 if OK, or a negative error code
> +      */
> +     int     (*set_mode)(struct phy *phy, enum phy_mode mode, int submode);
> +
> +     /**
> +      * set_speed - set PHY device speed
> +      *
> +      * @phy:        PHY port to be configured
> +      * @speed: PHY speed
> +      *
> +      * Configure PHY speed (e.g. for Ethernet, this could be 10 or 100 ...).
> +      *
> +      * Return: 0 if OK, or a negative error code
> +      */
> +     int     (*set_speed)(struct phy *phy, int speed);
>  };
>  
>  /**
> @@ -206,6 +255,24 @@ int generic_phy_power_off(struct phy *phy);
>   */
>  int generic_phy_configure(struct phy *phy, void *params);
>  
> +/**
> + * generic_phy_set_mode() - set PHY device mode
> + *
> + * @phy:     PHY port to be configured
> + * @mode: PHY mode
> + * @submode: PHY submode
> + * Return: 0 if OK, or a negative error code
> + */
> +int generic_phy_set_mode(struct phy *phy, enum phy_mode mode, int submode);
> +
> +/**
> + * generic_phy_set_speed() - set PHY device speed
> + *
> + * @phy:     PHY port to be configured
> + * @speed: PHY speed
> + * Return: 0 if OK, or a negative error code
> + */
> +int generic_phy_set_speed(struct phy *phy, int speed);
>  
>  /**
>   * generic_phy_get_by_index() - Get a PHY device by integer index.
> @@ -394,6 +461,16 @@ static inline int generic_phy_configure(struct phy *phy, 
> void *params)
>       return 0;
>  }
>  
> +static inline int generic_phy_set_mode(struct phy *phy, enum phy_mode mode, 
> int submode)
> +{
> +     return 0;
> +}
> +
> +static inline int generic_phy_set_speed(struct phy *phy, int speed)
> +{
> +     return 0;
> +}
> +
>  static inline int generic_phy_get_by_index(struct udevice *user, int index,
>                            struct phy *phy)
>  {
Reviewed-by: Patrice Chotard <patrice.chot...@foss.st.com>

Thanks
Patrice

Reply via email to