diff mbox series

[05/13] usb: dwc3: meson-g12a: refactor usb2 phy init

Message ID 20200324102030.31000-6-narmstrong@baylibre.com (mailing list archive)
State Superseded
Headers show
Series usb: dwc3: meson: add OTG support for GXL/GXM | expand

Commit Message

Neil Armstrong March 24, 2020, 10:20 a.m. UTC
Refactor the USB2 PHY init code patch to handle the Amlogic GXL/GXM
not having the PHY mode control registers in the Glue but in the PHY
registers.

The Amlogic GXL/GXM will call phy_set_mode() instead of programming the
PHY mode control registers, thus add two new callbacks to the SoC match
data.

Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
---
 drivers/usb/dwc3/dwc3-meson-g12a.c | 78 +++++++++++++++++++++---------
 1 file changed, 56 insertions(+), 22 deletions(-)

Comments

Martin Blumenstingl March 24, 2020, 2:33 p.m. UTC | #1
Hi Neil,

On Tue, Mar 24, 2020 at 11:20 AM Neil Armstrong <narmstrong@baylibre.com> wrote:
[...]
> @@ -195,23 +239,9 @@ static int dwc3_meson_g12a_usb2_init(struct dwc3_meson_g12a *priv)
>                 if (!strstr(priv->drvdata->phy_names[i], "usb2"))
>                         continue;
>
> -               regmap_update_bits(priv->u2p_regmap[i], U2P_R0,
> -                                  U2P_R0_POWER_ON_RESET,
> -                                  U2P_R0_POWER_ON_RESET);
> -
> -               if (priv->drvdata->otg_switch_supported && i == USB2_OTG_PHY) {
> -                       regmap_update_bits(priv->u2p_regmap[i], U2P_R0,
> -                               U2P_R0_ID_PULLUP | U2P_R0_DRV_VBUS,
> -                               U2P_R0_ID_PULLUP | U2P_R0_DRV_VBUS);
> -
> -                       dwc3_meson_g12a_usb2_set_mode(priv, i,
> -                                                     priv->otg_phy_mode);
> -               } else
> -                       dwc3_meson_g12a_usb2_set_mode(priv, i,
> -                                                     PHY_MODE_USB_HOST);
> -
> -               regmap_update_bits(priv->u2p_regmap[i], U2P_R0,
> -                                  U2P_R0_POWER_ON_RESET, 0);
> +               ret = priv->drvdata->usb2_init_phy(priv, i, mode);
> +               if (ret)
> +                       return ret;
>         }
this doesn't compile for me, it complains that mode is undefined
I believe we need something like the attached patch on top.

[...]
> @@ -580,7 +612,9 @@ static int dwc3_meson_g12a_probe(struct platform_device *pdev)
>         /* Get dr_mode */
>         priv->otg_mode = usb_get_dr_mode(dev);
>
> -       dwc3_meson_g12a_usb_init(priv);
> +       ret = dwc3_meson_g12a_usb_init(priv);
> +       if (ret)
> +               goto err_disable_clks;
this looks like an unrelated fix, dwc3_meson_g12a_usb_init has always
returned int (as potential error)
also the same check is missing in dwc3_meson_g12a_resume
can you please move this to a separate patch with the appropriate tag:
Fixes: c99993376f72ca ("usb: dwc3: Add Amlogic G12A DWC3 glue")


Martin
Neil Armstrong March 24, 2020, 2:35 p.m. UTC | #2
On 24/03/2020 15:33, Martin Blumenstingl wrote:
> Hi Neil,
> 
> On Tue, Mar 24, 2020 at 11:20 AM Neil Armstrong <narmstrong@baylibre.com> wrote:
> [...]
>> @@ -195,23 +239,9 @@ static int dwc3_meson_g12a_usb2_init(struct dwc3_meson_g12a *priv)
>>                 if (!strstr(priv->drvdata->phy_names[i], "usb2"))
>>                         continue;
>>
>> -               regmap_update_bits(priv->u2p_regmap[i], U2P_R0,
>> -                                  U2P_R0_POWER_ON_RESET,
>> -                                  U2P_R0_POWER_ON_RESET);
>> -
>> -               if (priv->drvdata->otg_switch_supported && i == USB2_OTG_PHY) {
>> -                       regmap_update_bits(priv->u2p_regmap[i], U2P_R0,
>> -                               U2P_R0_ID_PULLUP | U2P_R0_DRV_VBUS,
>> -                               U2P_R0_ID_PULLUP | U2P_R0_DRV_VBUS);
>> -
>> -                       dwc3_meson_g12a_usb2_set_mode(priv, i,
>> -                                                     priv->otg_phy_mode);
>> -               } else
>> -                       dwc3_meson_g12a_usb2_set_mode(priv, i,
>> -                                                     PHY_MODE_USB_HOST);
>> -
>> -               regmap_update_bits(priv->u2p_regmap[i], U2P_R0,
>> -                                  U2P_R0_POWER_ON_RESET, 0);
>> +               ret = priv->drvdata->usb2_init_phy(priv, i, mode);
>> +               if (ret)
>> +                       return ret;
>>         }
> this doesn't compile for me, it complains that mode is undefined
> I believe we need something like the attached patch on top.

I'll investigate

> 
> [...]
>> @@ -580,7 +612,9 @@ static int dwc3_meson_g12a_probe(struct platform_device *pdev)
>>         /* Get dr_mode */
>>         priv->otg_mode = usb_get_dr_mode(dev);
>>
>> -       dwc3_meson_g12a_usb_init(priv);
>> +       ret = dwc3_meson_g12a_usb_init(priv);
>> +       if (ret)
>> +               goto err_disable_clks;
> this looks like an unrelated fix, dwc3_meson_g12a_usb_init has always
> returned int (as potential error)
> also the same check is missing in dwc3_meson_g12a_resume
> can you please move this to a separate patch with the appropriate tag:
> Fixes: c99993376f72ca ("usb: dwc3: Add Amlogic G12A DWC3 glue")

Ok

Thanks,
Neil

> 
> 
> Martin
>
diff mbox series

Patch

diff --git a/drivers/usb/dwc3/dwc3-meson-g12a.c b/drivers/usb/dwc3/dwc3-meson-g12a.c
index 24a50dde685c..74d07ded8a7e 100644
--- a/drivers/usb/dwc3/dwc3-meson-g12a.c
+++ b/drivers/usb/dwc3/dwc3-meson-g12a.c
@@ -128,11 +128,21 @@  struct dwc3_meson_g12a_drvdata {
 	const char **phy_names;
 	int num_phys;
 	int (*setup_regmaps)(struct dwc3_meson_g12a *priv, void __iomem *base);
+	int (*usb2_init_phy)(struct dwc3_meson_g12a *priv, int i,
+			     enum phy_mode mode);
+	int (*set_phy_mode)(struct dwc3_meson_g12a *priv, int i,
+			    enum phy_mode mode);
 };
 
 static int dwc3_meson_g12a_setup_regmaps(struct dwc3_meson_g12a *priv,
 					 void __iomem *base);
 
+static int dwc3_meson_g12a_usb2_init_phy(struct dwc3_meson_g12a *priv, int i,
+					  enum phy_mode mode);
+
+static int dwc3_meson_g12a_set_phy_mode(struct dwc3_meson_g12a *priv,
+					int i, enum phy_mode mode);
+
 static struct dwc3_meson_g12a_drvdata g12a_drvdata = {
 	.otg_switch_supported = true,
 	.clks = meson_g12a_clocks,
@@ -140,6 +150,8 @@  static struct dwc3_meson_g12a_drvdata g12a_drvdata = {
 	.phy_names = meson_g12a_phy_names,
 	.num_phys = ARRAY_SIZE(meson_g12a_phy_names),
 	.setup_regmaps = dwc3_meson_g12a_setup_regmaps,
+	.usb2_init_phy = dwc3_meson_g12a_usb2_init_phy,
+	.set_phy_mode = dwc3_meson_g12a_set_phy_mode,
 };
 
 static struct dwc3_meson_g12a_drvdata a1_drvdata = {
@@ -149,6 +161,8 @@  static struct dwc3_meson_g12a_drvdata a1_drvdata = {
 	.phy_names = meson_a1_phy_names,
 	.num_phys = ARRAY_SIZE(meson_a1_phy_names),
 	.setup_regmaps = dwc3_meson_g12a_setup_regmaps,
+	.usb2_init_phy = dwc3_meson_g12a_usb2_init_phy,
+	.set_phy_mode = dwc3_meson_g12a_set_phy_mode,
 };
 
 struct dwc3_meson_g12a {
@@ -167,8 +181,8 @@  struct dwc3_meson_g12a {
 	const struct dwc3_meson_g12a_drvdata *drvdata;
 };
 
-static void dwc3_meson_g12a_usb2_set_mode(struct dwc3_meson_g12a *priv,
-					  int i, enum phy_mode mode)
+static int dwc3_meson_g12a_set_phy_mode(struct dwc3_meson_g12a *priv,
+					 int i, enum phy_mode mode)
 {
 	if (mode == PHY_MODE_USB_HOST)
 		regmap_update_bits(priv->u2p_regmap[i], U2P_R0,
@@ -177,11 +191,41 @@  static void dwc3_meson_g12a_usb2_set_mode(struct dwc3_meson_g12a *priv,
 	else
 		regmap_update_bits(priv->u2p_regmap[i], U2P_R0,
 				U2P_R0_HOST_DEVICE, 0);
+
+	return 0;
+}
+
+static int dwc3_meson_g12a_usb2_init_phy(struct dwc3_meson_g12a *priv, int i,
+					 enum phy_mode mode)
+{
+	int ret;
+
+	regmap_update_bits(priv->u2p_regmap[i], U2P_R0,
+			U2P_R0_POWER_ON_RESET,
+			U2P_R0_POWER_ON_RESET);
+
+	if (priv->drvdata->otg_switch_supported && i == USB2_OTG_PHY) {
+		regmap_update_bits(priv->u2p_regmap[i], U2P_R0,
+				   U2P_R0_ID_PULLUP | U2P_R0_DRV_VBUS,
+				   U2P_R0_ID_PULLUP | U2P_R0_DRV_VBUS);
+
+		ret = priv->drvdata->set_phy_mode(priv, i, mode);
+	} else
+		ret = priv->drvdata->set_phy_mode(priv, i,
+						  PHY_MODE_USB_HOST);
+
+	if (ret)
+		return ret;
+
+	regmap_update_bits(priv->u2p_regmap[i], U2P_R0,
+			U2P_R0_POWER_ON_RESET, 0);
+
+	return 0;
 }
 
 static int dwc3_meson_g12a_usb2_init(struct dwc3_meson_g12a *priv)
 {
-	int i;
+	int i, ret;
 
 	if (priv->otg_mode == USB_DR_MODE_PERIPHERAL)
 		priv->otg_phy_mode = PHY_MODE_USB_DEVICE;
@@ -195,23 +239,9 @@  static int dwc3_meson_g12a_usb2_init(struct dwc3_meson_g12a *priv)
 		if (!strstr(priv->drvdata->phy_names[i], "usb2"))
 			continue;
 
-		regmap_update_bits(priv->u2p_regmap[i], U2P_R0,
-				   U2P_R0_POWER_ON_RESET,
-				   U2P_R0_POWER_ON_RESET);
-
-		if (priv->drvdata->otg_switch_supported && i == USB2_OTG_PHY) {
-			regmap_update_bits(priv->u2p_regmap[i], U2P_R0,
-				U2P_R0_ID_PULLUP | U2P_R0_DRV_VBUS,
-				U2P_R0_ID_PULLUP | U2P_R0_DRV_VBUS);
-
-			dwc3_meson_g12a_usb2_set_mode(priv, i,
-						      priv->otg_phy_mode);
-		} else
-			dwc3_meson_g12a_usb2_set_mode(priv, i,
-						      PHY_MODE_USB_HOST);
-
-		regmap_update_bits(priv->u2p_regmap[i], U2P_R0,
-				   U2P_R0_POWER_ON_RESET, 0);
+		ret = priv->drvdata->usb2_init_phy(priv, i, mode);
+		if (ret)
+			return ret;
 	}
 
 	return 0;
@@ -364,7 +394,9 @@  static int dwc3_meson_g12a_otg_mode_set(struct dwc3_meson_g12a *priv,
 
 	priv->otg_phy_mode = mode;
 
-	dwc3_meson_g12a_usb2_set_mode(priv, USB2_OTG_PHY, mode);
+	ret = priv->drvdata->set_phy_mode(priv, USB2_OTG_PHY, mode);
+	if (ret)
+		return ret;
 
 	dwc3_meson_g12a_usb_otg_apply_mode(priv);
 
@@ -580,7 +612,9 @@  static int dwc3_meson_g12a_probe(struct platform_device *pdev)
 	/* Get dr_mode */
 	priv->otg_mode = usb_get_dr_mode(dev);
 
-	dwc3_meson_g12a_usb_init(priv);
+	ret = dwc3_meson_g12a_usb_init(priv);
+	if (ret)
+		goto err_disable_clks;
 
 	/* Init PHYs */
 	for (i = 0 ; i < PHY_COUNT ; ++i) {