diff mbox series

[v2,3/5] phy: meson-gxl-usb2: remove phy_meson_gxl_usb2_set_mode

Message ID 20240620-u-boot-usb-gxl-phy-set-mode-v2-3-b81c027bc02c@linaro.org
State New
Headers show
Series usb: meson: switch to set_mode callback and other cleanup | expand

Commit Message

Neil Armstrong June 20, 2024, 7:42 a.m. UTC
Remove the public phy_meson_gxl_usb2_set_mode and move
the implementation in the the set_mode callback.

Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
---
 arch/arm/include/asm/arch-meson/usb-gx.h |  3 ---
 drivers/phy/meson-gxl-usb2.c             | 45 ++++++++++----------------------
 2 files changed, 14 insertions(+), 34 deletions(-)

Comments

Marek Vasut June 20, 2024, 11:54 a.m. UTC | #1
On 6/20/24 9:42 AM, Neil Armstrong wrote:
> Remove the public phy_meson_gxl_usb2_set_mode and move
> the implementation in the the set_mode callback.
> 
> Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>

Reviewed-by: Marek Vasut <marex@denx.de>

> -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);
> +		val |= U2P_R0_DM_PULLDOWN;
> +		val |= U2P_R0_DP_PULLDOWN;

btw this could be a one-liner val |= macro1 | macro2 ;
diff mbox series

Patch

diff --git a/arch/arm/include/asm/arch-meson/usb-gx.h b/arch/arm/include/asm/arch-meson/usb-gx.h
index 61f1809df9..966d401730 100644
--- a/arch/arm/include/asm/arch-meson/usb-gx.h
+++ b/arch/arm/include/asm/arch-meson/usb-gx.h
@@ -9,9 +9,6 @@ 
 #include <generic-phy.h>
 #include <linux/usb/otg.h>
 
-/* TOFIX add set_mode to struct phy_ops */
-void phy_meson_gxl_usb2_set_mode(struct phy *phy, enum usb_dr_mode mode);
-
 int dwc3_meson_gxl_force_mode(struct udevice *dev, enum usb_dr_mode mode);
 
 #endif
diff --git a/drivers/phy/meson-gxl-usb2.c b/drivers/phy/meson-gxl-usb2.c
index e051e66224..140e936b47 100644
--- a/drivers/phy/meson-gxl-usb2.c
+++ b/drivers/phy/meson-gxl-usb2.c
@@ -19,8 +19,6 @@ 
 #include <linux/printk.h>
 #include <linux/usb/otg.h>
 
-#include <asm/arch/usb-gx.h>
-
 #include <linux/bitops.h>
 #include <linux/compat.h>
 
@@ -121,54 +119,39 @@  static void phy_meson_gxl_usb2_reset(struct phy_meson_gxl_usb2_priv *priv)
 	udelay(RESET_COMPLETE_TIME);
 }
 
-void phy_meson_gxl_usb2_set_mode(struct phy *phy, enum usb_dr_mode mode)
+static int phy_meson_gxl_usb2_set_mode(struct phy *phy, enum phy_mode mode, int submode)
 {
 	struct udevice *dev = phy->dev;
 	struct phy_meson_gxl_usb2_priv *priv = dev_get_priv(dev);
 	uint val;
 
+	if (submode)
+		return -EOPNOTSUPP;
+
 	regmap_read(priv->regmap, U2P_R0, &val);
 
 	switch (mode) {
-	case USB_DR_MODE_UNKNOWN:
-	case USB_DR_MODE_HOST:
-	case USB_DR_MODE_OTG:
-		val |= U2P_R0_DM_PULLDOWN;
-		val |= U2P_R0_DP_PULLDOWN;
-		val &= ~U2P_R0_ID_PULLUP;
-		break;
-
-	case USB_DR_MODE_PERIPHERAL:
+	case PHY_MODE_USB_DEVICE:
 		val &= ~U2P_R0_DM_PULLDOWN;
 		val &= ~U2P_R0_DP_PULLDOWN;
 		val |= U2P_R0_ID_PULLUP;
 		break;
-	}
-
-	regmap_write(priv->regmap, U2P_R0, val);
-
-	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);
+		val |= U2P_R0_DM_PULLDOWN;
+		val |= U2P_R0_DP_PULLDOWN;
+		val &= ~U2P_R0_ID_PULLUP;
 		break;
 
 	default:
 		return -EINVAL;
 	}
 
+	regmap_write(priv->regmap, U2P_R0, val);
+
+	phy_meson_gxl_usb2_reset(priv);
+
 	return 0;
 }
 
@@ -183,7 +166,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, PHY_MODE_USB_HOST, 0);
+	phy_meson_gxl_usb2_set_mode(phy, PHY_MODE_USB_HOST, 0);
 
 	return 0;
 }
@@ -205,7 +188,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,
+	.set_mode = phy_meson_gxl_usb2_set_mode,
 };
 
 int meson_gxl_usb2_phy_probe(struct udevice *dev)