diff mbox series

[1/5] phy: meson-gxl-usb2: add set_mode callback

Message ID 20240618-u-boot-usb-gxl-phy-set-mode-v1-1-6b41efa46e35@linaro.org
State Superseded
Headers show
Series usb: meson: switch to set_mode callback and other cleanup | expand

Commit Message

Neil Armstrong June 18, 2024, 7:55 a.m. UTC
Implement set_mode callback by calling the current public
function.

Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
---
 drivers/phy/meson-gxl-usb2.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

Comments

Marek Vasut June 18, 2024, 2:54 p.m. UTC | #1
On 6/18/24 9:55 AM, Neil Armstrong wrote:
> Implement set_mode callback by calling the current public
> function.
> 
> Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
> ---
>   drivers/phy/meson-gxl-usb2.c | 25 ++++++++++++++++++++++++-
>   1 file changed, 24 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/phy/meson-gxl-usb2.c b/drivers/phy/meson-gxl-usb2.c
> index 92c285103c..e051e66224 100644
> --- a/drivers/phy/meson-gxl-usb2.c
> +++ b/drivers/phy/meson-gxl-usb2.c
> @@ -150,6 +150,28 @@ void phy_meson_gxl_usb2_set_mode(struct phy *phy, enum usb_dr_mode mode)
>   	phy_meson_gxl_usb2_reset(priv);
>   }
>   
> +static int _phy_meson_gxl_usb2_set_mode(struct phy *phy, enum phy_mode mode, int submode)
> +{
> +	if (submode)
> +		return -EOPNOTSUPP;
> +
> +	switch (mode) {
> +	case PHY_MODE_USB_DEVICE:
> +		phy_meson_gxl_usb2_set_mode(phy, USB_DR_MODE_PERIPHERAL);
> +		break;
> +
> +	case PHY_MODE_USB_HOST:
> +	case PHY_MODE_USB_OTG:
> +		phy_meson_gxl_usb2_set_mode(phy, USB_DR_MODE_HOST);
> +		break;
> +
> +	default:
> +		return -EINVAL;
> +	}
> +
> +	return 0;
> +}
> +
>   static int phy_meson_gxl_usb2_power_on(struct phy *phy)
>   {
>   	struct udevice *dev = phy->dev;
> @@ -161,7 +183,7 @@ static int phy_meson_gxl_usb2_power_on(struct phy *phy)
>   	val &= ~U2P_R0_POWER_ON_RESET;
>   	regmap_write(priv->regmap, U2P_R0, val);
>   
> -	phy_meson_gxl_usb2_set_mode(phy, USB_DR_MODE_HOST);

Could you rename this ^ to some phy_meson_gxl_usb2_set_mode_inner() and ...

> +	_phy_meson_gxl_usb2_set_mode(phy, PHY_MODE_USB_HOST, 0);

... remove the leading underscore here.

>   	return 0;
>   }
> @@ -183,6 +205,7 @@ static int phy_meson_gxl_usb2_power_off(struct phy *phy)
>   struct phy_ops meson_gxl_usb2_phy_ops = {
>   	.power_on = phy_meson_gxl_usb2_power_on,
>   	.power_off = phy_meson_gxl_usb2_power_off,
> +	.set_mode = _phy_meson_gxl_usb2_set_mode,

... and here ?

[...]
diff mbox series

Patch

diff --git a/drivers/phy/meson-gxl-usb2.c b/drivers/phy/meson-gxl-usb2.c
index 92c285103c..e051e66224 100644
--- a/drivers/phy/meson-gxl-usb2.c
+++ b/drivers/phy/meson-gxl-usb2.c
@@ -150,6 +150,28 @@  void phy_meson_gxl_usb2_set_mode(struct phy *phy, enum usb_dr_mode mode)
 	phy_meson_gxl_usb2_reset(priv);
 }
 
+static int _phy_meson_gxl_usb2_set_mode(struct phy *phy, enum phy_mode mode, int submode)
+{
+	if (submode)
+		return -EOPNOTSUPP;
+
+	switch (mode) {
+	case PHY_MODE_USB_DEVICE:
+		phy_meson_gxl_usb2_set_mode(phy, USB_DR_MODE_PERIPHERAL);
+		break;
+
+	case PHY_MODE_USB_HOST:
+	case PHY_MODE_USB_OTG:
+		phy_meson_gxl_usb2_set_mode(phy, USB_DR_MODE_HOST);
+		break;
+
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
 static int phy_meson_gxl_usb2_power_on(struct phy *phy)
 {
 	struct udevice *dev = phy->dev;
@@ -161,7 +183,7 @@  static int phy_meson_gxl_usb2_power_on(struct phy *phy)
 	val &= ~U2P_R0_POWER_ON_RESET;
 	regmap_write(priv->regmap, U2P_R0, val);
 
-	phy_meson_gxl_usb2_set_mode(phy, USB_DR_MODE_HOST);
+	_phy_meson_gxl_usb2_set_mode(phy, PHY_MODE_USB_HOST, 0);
 
 	return 0;
 }
@@ -183,6 +205,7 @@  static int phy_meson_gxl_usb2_power_off(struct phy *phy)
 struct phy_ops meson_gxl_usb2_phy_ops = {
 	.power_on = phy_meson_gxl_usb2_power_on,
 	.power_off = phy_meson_gxl_usb2_power_off,
+	.set_mode = _phy_meson_gxl_usb2_set_mode,
 };
 
 int meson_gxl_usb2_phy_probe(struct udevice *dev)