Skip to contentSkip to conversation

phy: sun4i-usb: Fix PHY0 routing and passby configuration for MUSB

PATCH New Paul Kocialkowski 3 participants 11 messages Mar 14, 2019 – Jul 15, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 phy: sun4i-usb: Fix PHY0 routing and passby configuration for MUSB

Recent Allwinner platforms (starting with the H3) only use the MUSB controller for peripheral mode and use HCI for host mode. As a result, extra steps need to be taken to properly route USB signals to one or the other. More precisely, the following is required:
* Routing the pins to either HCI/MUSB (controlled by PHY);
* Enabling USB PHY passby in HCI mode (controlled by PMU).

The current code will enable passby for each PHY and reroute PHY0 to MUSB, which is inconsistent and results in broken USB peripheral support.

Passby on PHY0 must only be enabled when we want to use HCI. Since host/device mode detection is not available from the PHY code and because U-Boot does not support changing the mode dynamically anyway, we can just mux the controller to MUSB if it is enabled and mux it to HCI otherwise.

This fixes USB peripheral support for platforms with PHY0 dual-route, especially H3/H5 and V3s.

---
 drivers/phy/allwinner/phy-sun4i-usb.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/phy/allwinner/phy-sun4i-usb.c +13 -1
index f206fa3f5d48..4f1c7e519d71 100644
@@ -302,9 +302,21 @@ static int sun4i_usb_phy_init(struct phy *phy)
 				    data->cfg->disc_thresh, PHY_DISCON_TH_LEN);
 	}
 
+#ifdef CONFIG_USB_MUSB_SUNXI
+	/* Needed for HCI and conflicts with MUSB, keep PHY0 on MUSB */
+	if (usb_phy->id != 0)
+		sun4i_usb_phy_passby(phy, true);
+
+	/* Route PHY0 to MUSB to allow USB gadget */
+	if (data->cfg->phy0_dual_route)
+		sun4i_usb_phy0_reroute(data, true);
+#else
 	sun4i_usb_phy_passby(phy, true);
 
-	sun4i_usb_phy0_reroute(data, true);
+	/* Route PHY0 to HCI to allow USB host */
+	if (data->cfg->phy0_dual_route)
+		sun4i_usb_phy0_reroute(data, false);
+#endif
 
 	return 0;
 }
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/1 phy: sun4i-usb: Fix PHY0 routing and passby configuration for MUSB

Quoted 39 lines · Paul Kocialkowski

Recent Allwinner platforms (starting with the H3) only use the MUSB controller for peripheral mode and use HCI for host mode. As a result, extra steps need to be taken to properly route USB signals to one or the other. More precisely, the following is required:
* Routing the pins to either HCI/MUSB (controlled by PHY);
* Enabling USB PHY passby in HCI mode (controlled by PMU).

The current code will enable passby for each PHY and reroute PHY0 to MUSB, which is inconsistent and results in broken USB peripheral support.

Passby on PHY0 must only be enabled when we want to use HCI. Since host/device mode detection is not available from the PHY code and because U-Boot does not support changing the mode dynamically anyway, we can just mux the controller to MUSB if it is enabled and mux it to HCI otherwise.

This fixes USB peripheral support for platforms with PHY0 dual-route, especially H3/H5 and V3s.

---
 drivers/phy/allwinner/phy-sun4i-usb.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/phy/allwinner/phy-sun4i-usb.c +6 -0
index f206fa3f5d48..4f1c7e519d71 100644
@@ -302,9 +302,21 @@ static int sun4i_usb_phy_init(struct phy *phy)
                                    data->cfg->disc_thresh, PHY_DISCON_TH_LEN);
        }
 
+#ifdef CONFIG_USB_MUSB_SUNXI
+       /* Needed for HCI and conflicts with MUSB, keep PHY0 on MUSB */
+       if (usb_phy->id != 0)
+               sun4i_usb_phy_passby(phy, true);
+
+       /* Route PHY0 to MUSB to allow USB gadget */

drivers/phy/allwinner/phy-sun4i-usb.c static int sun4i_usb_phy_init(struct phy *phy) · line 319

Quoted 10 lines
drivers/phy/allwinner/phy-sun4i-usb.c +7 -1
+       if (data->cfg->phy0_dual_route)
+               sun4i_usb_phy0_reroute(data, true);
+#else
        sun4i_usb_phy_passby(phy, true);
 
-       sun4i_usb_phy0_reroute(data, true);
+       /* Route PHY0 to HCI to allow USB host */
+       if (data->cfg->phy0_dual_route)
+               sun4i_usb_phy0_reroute(data, false);
+#endif

I think we can manage this route and passby dynamically by detecting id since we have dr_mode verify the MUSB host or peripheral via usb_get_dr_mode, any chance to try that way?

#2 lore raw

PATCH 1/1 phy: sun4i-usb: Fix PHY0 routing and passby configuration for MUSB

Hi,

Quoted 45 lines · Jagan Teki
Quoted 43 lines · Paul Kocialkowski

Recent Allwinner platforms (starting with the H3) only use the MUSB controller for peripheral mode and use HCI for host mode. As a result, extra steps need to be taken to properly route USB signals to one or the other. More precisely, the following is required:
* Routing the pins to either HCI/MUSB (controlled by PHY);
* Enabling USB PHY passby in HCI mode (controlled by PMU).

The current code will enable passby for each PHY and reroute PHY0 to MUSB, which is inconsistent and results in broken USB peripheral support.

Passby on PHY0 must only be enabled when we want to use HCI. Since host/device mode detection is not available from the PHY code and because U-Boot does not support changing the mode dynamically anyway, we can just mux the controller to MUSB if it is enabled and mux it to HCI otherwise.

This fixes USB peripheral support for platforms with PHY0 dual-route, especially H3/H5 and V3s.

---
 drivers/phy/allwinner/phy-sun4i-usb.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/phy/allwinner/phy-sun4i-usb.c +9 -0
index f206fa3f5d48..4f1c7e519d71 100644
@@ -302,9 +302,21 @@ static int sun4i_usb_phy_init(struct phy *phy)
                                    data->cfg->disc_thresh, PHY_DISCON_TH_LEN);
        }
 
+#ifdef CONFIG_USB_MUSB_SUNXI
+       /* Needed for HCI and conflicts with MUSB, keep PHY0 on MUSB */
+       if (usb_phy->id != 0)
+               sun4i_usb_phy_passby(phy, true);
+
+       /* Route PHY0 to MUSB to allow USB gadget */
+       if (data->cfg->phy0_dual_route)
+               sun4i_usb_phy0_reroute(data, true);
+#else
        sun4i_usb_phy_passby(phy, true);
 
Quoted 9 lines

drivers/phy/allwinner/phy-sun4i-usb.c static int sun4i_usb_phy_init(struct phy *phy) · line 319

Quoted 5 lines
drivers/phy/allwinner/phy-sun4i-usb.c +4 -1
-       sun4i_usb_phy0_reroute(data, true);
+       /* Route PHY0 to HCI to allow USB host */
+       if (data->cfg->phy0_dual_route)
+               sun4i_usb_phy0_reroute(data, false);
+#endif

I think we can manage this route and passby dynamically by detecting id since we have dr_mode verify the MUSB host or peripheral via usb_get_dr_mode, any chance to try that way?

Oh, I didn't know that U-Boot has support for usb_get_dr_mode these days. Thanks!

So far, the sunxi port has been using Kconfig to distinguish between host/device (unless I'm mistaken?) so I feel like this should be a separate follow-up patch to convert the sunxi MUSB glue + PHY to detecting dr_mode using usb_get_dr_mode. This feels like a significant rework, too.

Also, how should we handle the OTG case? I'm not sure we can support having both musb host and gadget built-in at this point. But that would certainly be welcome as part of the rework, too.

What do you think?

Cheers,

Paul

Signature · 3 lines
Paul Kocialkowski, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
#3 lore raw

PATCH 1/1 phy: sun4i-usb: Fix PHY0 routing and passby configuration for MUSB

Quoted 59 lines · Paul Kocialkowski

Hi,

Quoted 45 lines · Jagan Teki
Quoted 43 lines · Paul Kocialkowski

Recent Allwinner platforms (starting with the H3) only use the MUSB controller for peripheral mode and use HCI for host mode. As a result, extra steps need to be taken to properly route USB signals to one or the other. More precisely, the following is required:
* Routing the pins to either HCI/MUSB (controlled by PHY);
* Enabling USB PHY passby in HCI mode (controlled by PMU).

The current code will enable passby for each PHY and reroute PHY0 to MUSB, which is inconsistent and results in broken USB peripheral support.

Passby on PHY0 must only be enabled when we want to use HCI. Since host/device mode detection is not available from the PHY code and because U-Boot does not support changing the mode dynamically anyway, we can just mux the controller to MUSB if it is enabled and mux it to HCI otherwise.

This fixes USB peripheral support for platforms with PHY0 dual-route, especially H3/H5 and V3s.

---
 drivers/phy/allwinner/phy-sun4i-usb.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/phy/allwinner/phy-sun4i-usb.c +9 -0
index f206fa3f5d48..4f1c7e519d71 100644
@@ -302,9 +302,21 @@ static int sun4i_usb_phy_init(struct phy *phy)
                                    data->cfg->disc_thresh, PHY_DISCON_TH_LEN);
        }
 
+#ifdef CONFIG_USB_MUSB_SUNXI
+       /* Needed for HCI and conflicts with MUSB, keep PHY0 on MUSB */
+       if (usb_phy->id != 0)
+               sun4i_usb_phy_passby(phy, true);
+
+       /* Route PHY0 to MUSB to allow USB gadget */
+       if (data->cfg->phy0_dual_route)
+               sun4i_usb_phy0_reroute(data, true);
+#else
        sun4i_usb_phy_passby(phy, true);
 
Quoted 9 lines

drivers/phy/allwinner/phy-sun4i-usb.c static int sun4i_usb_phy_init(struct phy *phy) · line 319

Quoted 5 lines
drivers/phy/allwinner/phy-sun4i-usb.c +4 -1
-       sun4i_usb_phy0_reroute(data, true);
+       /* Route PHY0 to HCI to allow USB host */
+       if (data->cfg->phy0_dual_route)
+               sun4i_usb_phy0_reroute(data, false);
+#endif

I think we can manage this route and passby dynamically by detecting id since we have dr_mode verify the MUSB host or peripheral via usb_get_dr_mode, any chance to try that way?

Quoted 8 lines

Oh, I didn't know that U-Boot has support for usb_get_dr_mode these days. Thanks!

So far, the sunxi port has been using Kconfig to distinguish between host/device (unless I'm mistaken?) so I feel like this should be a separate follow-up patch to convert the sunxi MUSB glue + PHY to detecting dr_mode using usb_get_dr_mode. This feels like a significant rework, too.

Yes.

Quoted 6 lines

Also, how should we handle the OTG case? I'm not sure we can support having both musb host and gadget built-in at this point. But that would certainly be welcome as part of the rework, too.

What do you think?

You mean handling dr_mode at runtime.

If yes, It is bit new where we can register the musb as UCLASS_MISC wrapper and decide to bind driver for host and peripheral by decoding dr_mode. and indeed host should register with UCLASS_USB and peripheral with UCLASS_USB_GADGET_GENERIC.

I tried this wrapper before, not placed in-between because of other work but TI musb has similar code to manage this drivers/usb/musb-new/ti-musb.c

Jagan.

#4 lore raw

PATCH 1/1 phy: sun4i-usb: Fix PHY0 routing and passby configuration for MUSB

Quoted 2 lines · Jagan Teki

On Mon, Apr 15, 2019 at 1:52 PM Paul Kocialkowski
<[email protected]> wrote:

Hi,

Quoted 76 lines
Quoted 56 lines · Jagan Teki
Quoted 45 lines
Quoted 43 lines · Paul Kocialkowski

Recent Allwinner platforms (starting with the H3) only use the MUSB controller for peripheral mode and use HCI for host mode. As a result, extra steps need to be taken to properly route USB signals to one or the other. More precisely, the following is required:
* Routing the pins to either HCI/MUSB (controlled by PHY);
* Enabling USB PHY passby in HCI mode (controlled by PMU).

The current code will enable passby for each PHY and reroute PHY0 to MUSB, which is inconsistent and results in broken USB peripheral support.

Passby on PHY0 must only be enabled when we want to use HCI. Since host/device mode detection is not available from the PHY code and because U-Boot does not support changing the mode dynamically anyway, we can just mux the controller to MUSB if it is enabled and mux it to HCI otherwise.

This fixes USB peripheral support for platforms with PHY0 dual-route, especially H3/H5 and V3s.

---
 drivers/phy/allwinner/phy-sun4i-usb.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/phy/allwinner/phy-sun4i-usb.c +9 -0
index f206fa3f5d48..4f1c7e519d71 100644
@@ -302,9 +302,21 @@ static int sun4i_usb_phy_init(struct phy *phy)
                                    data->cfg->disc_thresh, PHY_DISCON_TH_LEN);
        }
 
+#ifdef CONFIG_USB_MUSB_SUNXI
+       /* Needed for HCI and conflicts with MUSB, keep PHY0 on MUSB */
+       if (usb_phy->id != 0)
+               sun4i_usb_phy_passby(phy, true);
+
+       /* Route PHY0 to MUSB to allow USB gadget */
+       if (data->cfg->phy0_dual_route)
+               sun4i_usb_phy0_reroute(data, true);
+#else
        sun4i_usb_phy_passby(phy, true);
 
Quoted 9 lines

drivers/phy/allwinner/phy-sun4i-usb.c static int sun4i_usb_phy_init(struct phy *phy) · line 319

Quoted 5 lines
drivers/phy/allwinner/phy-sun4i-usb.c +4 -1
-       sun4i_usb_phy0_reroute(data, true);
+       /* Route PHY0 to HCI to allow USB host */
+       if (data->cfg->phy0_dual_route)
+               sun4i_usb_phy0_reroute(data, false);
+#endif

I think we can manage this route and passby dynamically by detecting id since we have dr_mode verify the MUSB host or peripheral via usb_get_dr_mode, any chance to try that way?

Quoted 8 lines

Oh, I didn't know that U-Boot has support for usb_get_dr_mode these days. Thanks!

So far, the sunxi port has been using Kconfig to distinguish between host/device (unless I'm mistaken?) so I feel like this should be a separate follow-up patch to convert the sunxi MUSB glue + PHY to detecting dr_mode using usb_get_dr_mode. This feels like a significant rework, too.

Yes.

Quoted 6 lines

Also, how should we handle the OTG case? I'm not sure we can support having both musb host and gadget built-in at this point. But that would certainly be welcome as part of the rework, too.

What do you think?

You mean handling dr_mode at runtime.

Quoted 8 lines

If yes, It is bit new where we can register the musb as UCLASS_MISC wrapper and decide to bind driver for host and peripheral by decoding dr_mode. and indeed host should register with UCLASS_USB and peripheral with UCLASS_USB_GADGET_GENERIC.

I tried this wrapper before, not placed in-between because of other work but TI musb has similar code to manage this drivers/usb/musb-new/ti-musb.c

Before we go wild with any fancy rework, can we possibly take this patch as it? As I realised, this is basically a better version of the patch I sent two weeks ago [1]. I tried Paul's patch back then, but was missing the phys property in the DT, which I addressed in patch 2/2.

So I would appreciate if we can take this patch, as it solves a real problem (upper USB port not working) on many Pine64 boards (given the small DT change is in place). And on those boards the OTG functionality is not really feasible anyway, as VBUS is either permanently enabled or at least tied to the other host port's supply, so we can't turn it off for peripheral mode.

Cheers,
Andre.

[1] https://lists.denx.de/pipermail/u-boot/2019-May/369521.html

#5 lore raw

PATCH 1/1 phy: sun4i-usb: Fix PHY0 routing and passby configuration for MUSB

Hi,

Quoted 86 lines · André Przywara
Quoted 2 lines · Jagan Teki

On Mon, Apr 15, 2019 at 1:52 PM Paul Kocialkowski
<[email protected]> wrote:

Hi,

Quoted 80 lines
Quoted 56 lines · Jagan Teki
Quoted 45 lines
Quoted 43 lines · Paul Kocialkowski

Recent Allwinner platforms (starting with the H3) only use the MUSB controller for peripheral mode and use HCI for host mode. As a result, extra steps need to be taken to properly route USB signals to one or the other. More precisely, the following is required:
* Routing the pins to either HCI/MUSB (controlled by PHY);
* Enabling USB PHY passby in HCI mode (controlled by PMU).

The current code will enable passby for each PHY and reroute PHY0 to MUSB, which is inconsistent and results in broken USB peripheral support.

Passby on PHY0 must only be enabled when we want to use HCI. Since host/device mode detection is not available from the PHY code and because U-Boot does not support changing the mode dynamically anyway, we can just mux the controller to MUSB if it is enabled and mux it to HCI otherwise.

This fixes USB peripheral support for platforms with PHY0 dual-route, especially H3/H5 and V3s.

---
 drivers/phy/allwinner/phy-sun4i-usb.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/phy/allwinner/phy-sun4i-usb.c +9 -0
index f206fa3f5d48..4f1c7e519d71 100644
@@ -302,9 +302,21 @@ static int sun4i_usb_phy_init(struct phy *phy)
                                    data->cfg->disc_thresh, PHY_DISCON_TH_LEN);
        }
 
+#ifdef CONFIG_USB_MUSB_SUNXI
+       /* Needed for HCI and conflicts with MUSB, keep PHY0 on MUSB */
+       if (usb_phy->id != 0)
+               sun4i_usb_phy_passby(phy, true);
+
+       /* Route PHY0 to MUSB to allow USB gadget */
+       if (data->cfg->phy0_dual_route)
+               sun4i_usb_phy0_reroute(data, true);
+#else
        sun4i_usb_phy_passby(phy, true);
 
Quoted 9 lines

drivers/phy/allwinner/phy-sun4i-usb.c static int sun4i_usb_phy_init(struct phy *phy) · line 319

Quoted 5 lines
drivers/phy/allwinner/phy-sun4i-usb.c +4 -1
-       sun4i_usb_phy0_reroute(data, true);
+       /* Route PHY0 to HCI to allow USB host */
+       if (data->cfg->phy0_dual_route)
+               sun4i_usb_phy0_reroute(data, false);
+#endif

I think we can manage this route and passby dynamically by detecting id since we have dr_mode verify the MUSB host or peripheral via usb_get_dr_mode, any chance to try that way?

Quoted 8 lines

Oh, I didn't know that U-Boot has support for usb_get_dr_mode these days. Thanks!

So far, the sunxi port has been using Kconfig to distinguish between host/device (unless I'm mistaken?) so I feel like this should be a separate follow-up patch to convert the sunxi MUSB glue + PHY to detecting dr_mode using usb_get_dr_mode. This feels like a significant rework, too.

Yes.

Quoted 5 lines

Also, how should we handle the OTG case? I'm not sure we can support having both musb host and gadget built-in at this point. But that would certainly be welcome as part of the rework, too.

What do you think?

You mean handling dr_mode at runtime.

If yes, It is bit new where we can register the musb as UCLASS_MISC wrapper and decide to bind driver for host and peripheral by decoding dr_mode. and indeed host should register with UCLASS_USB and peripheral with UCLASS_USB_GADGET_GENERIC.

Quoted 8 lines
Quoted 3 lines

I tried this wrapper before, not placed in-between because of other work but TI musb has similar code to manage this drivers/usb/musb-new/ti-musb.c

Before we go wild with any fancy rework, can we possibly take this patch as it? As I realised, this is basically a better version of the patch I sent two weeks ago [1]. I tried Paul's patch back then, but was missing the phys property in the DT, which I addressed in patch 2/2.

I fully agree, and believe the rework should be a separate subsequent series.

Quoted 6 lines

So I would appreciate if we can take this patch, as it solves a real problem (upper USB port not working) on many Pine64 boards (given the small DT change is in place). And on those boards the OTG functionality is not really feasible anyway, as VBUS is either permanently enabled or at least tied to the other host port's supply, so we can't turn it off for peripheral mode.

It makes USB OTG work on my V3/V3s boards as well and there's a chance it fixes A83t as well.

Cheers,

Paul

Quoted 4 lines

Cheers,
Andre.

[1] https://lists.denx.de/pipermail/u-boot/2019-May/369521.html

Signature · 3 lines
Paul Kocialkowski, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
#6 lore raw

PATCH 1/1 phy: sun4i-usb: Fix PHY0 routing and passby configuration for MUSB

In reply to André Przywara

Hi,

Quoted 96 lines · André Przywara
Quoted 2 lines · Jagan Teki

On Mon, Apr 15, 2019 at 1:52 PM Paul Kocialkowski
<[email protected]> wrote:

Hi,

Quoted 76 lines
Quoted 56 lines · Jagan Teki
Quoted 45 lines
Quoted 43 lines · Paul Kocialkowski

Recent Allwinner platforms (starting with the H3) only use the MUSB controller for peripheral mode and use HCI for host mode. As a result, extra steps need to be taken to properly route USB signals to one or the other. More precisely, the following is required:
* Routing the pins to either HCI/MUSB (controlled by PHY);
* Enabling USB PHY passby in HCI mode (controlled by PMU).

The current code will enable passby for each PHY and reroute PHY0 to MUSB, which is inconsistent and results in broken USB peripheral support.

Passby on PHY0 must only be enabled when we want to use HCI. Since host/device mode detection is not available from the PHY code and because U-Boot does not support changing the mode dynamically anyway, we can just mux the controller to MUSB if it is enabled and mux it to HCI otherwise.

This fixes USB peripheral support for platforms with PHY0 dual-route, especially H3/H5 and V3s.

---
 drivers/phy/allwinner/phy-sun4i-usb.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/phy/allwinner/phy-sun4i-usb.c +9 -0
index f206fa3f5d48..4f1c7e519d71 100644
@@ -302,9 +302,21 @@ static int sun4i_usb_phy_init(struct phy *phy)
                                    data->cfg->disc_thresh, PHY_DISCON_TH_LEN);
        }
 
+#ifdef CONFIG_USB_MUSB_SUNXI
+       /* Needed for HCI and conflicts with MUSB, keep PHY0 on MUSB */
+       if (usb_phy->id != 0)
+               sun4i_usb_phy_passby(phy, true);
+
+       /* Route PHY0 to MUSB to allow USB gadget */
+       if (data->cfg->phy0_dual_route)
+               sun4i_usb_phy0_reroute(data, true);
+#else
        sun4i_usb_phy_passby(phy, true);
 
Quoted 9 lines

drivers/phy/allwinner/phy-sun4i-usb.c static int sun4i_usb_phy_init(struct phy *phy) · line 319

Quoted 5 lines
drivers/phy/allwinner/phy-sun4i-usb.c +4 -1
-       sun4i_usb_phy0_reroute(data, true);
+       /* Route PHY0 to HCI to allow USB host */
+       if (data->cfg->phy0_dual_route)
+               sun4i_usb_phy0_reroute(data, false);
+#endif

I think we can manage this route and passby dynamically by detecting id since we have dr_mode verify the MUSB host or peripheral via usb_get_dr_mode, any chance to try that way?

Quoted 8 lines

Oh, I didn't know that U-Boot has support for usb_get_dr_mode these days. Thanks!

So far, the sunxi port has been using Kconfig to distinguish between host/device (unless I'm mistaken?) so I feel like this should be a separate follow-up patch to convert the sunxi MUSB glue + PHY to detecting dr_mode using usb_get_dr_mode. This feels like a significant rework, too.

Yes.

Quoted 6 lines

Also, how should we handle the OTG case? I'm not sure we can support having both musb host and gadget built-in at this point. But that would certainly be welcome as part of the rework, too.

What do you think?

You mean handling dr_mode at runtime.

Quoted 8 lines

If yes, It is bit new where we can register the musb as UCLASS_MISC wrapper and decide to bind driver for host and peripheral by decoding dr_mode. and indeed host should register with UCLASS_USB and peripheral with UCLASS_USB_GADGET_GENERIC.

I tried this wrapper before, not placed in-between because of other work but TI musb has similar code to manage this drivers/usb/musb-new/ti-musb.c

Before we go wild with any fancy rework, can we possibly take this patch as it? As I realised, this is basically a better version of the patch I sent two weeks ago [1]. I tried Paul's patch back then, but was missing the phys property in the DT, which I addressed in patch 2/2.

Quoted 6 lines

So I would appreciate if we can take this patch, as it solves a real problem (upper USB port not working) on many Pine64 boards (given the small DT change is in place). And on those boards the OTG functionality is not really feasible anyway, as VBUS is either permanently enabled or at least tied to the other host port's supply, so we can't turn it off for peripheral mode.

Looks like nothing has moved forward on this (quite significant) fixup.

Could we please merge it as soon as time allows?

Cheers and thanks in advance,

Paul

Quoted 4 lines

Cheers,
Andre.

[1] https://lists.denx.de/pipermail/u-boot/2019-May/369521.html

Signature · 3 lines
Paul Kocialkowski, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
#7 lore raw

PATCH 1/1 phy: sun4i-usb: Fix PHY0 routing and passby configuration for MUSB

On Fri, 12 Jul 2019 11:44:38 +0200
Paul Kocialkowski <[email protected]> wrote:

Hi,

Quoted 104 lines · André Przywara
Quoted 96 lines · Jagan Teki
Quoted 2 lines

On Mon, Apr 15, 2019 at 1:52 PM Paul Kocialkowski
<[email protected]> wrote:

Hi,

Quoted 76 lines
Quoted 56 lines · Jagan Teki
Quoted 45 lines
Quoted 43 lines · Paul Kocialkowski

Recent Allwinner platforms (starting with the H3) only use the MUSB controller for peripheral mode and use HCI for host mode. As a result, extra steps need to be taken to properly route USB signals to one or the other. More precisely, the following is required:
* Routing the pins to either HCI/MUSB (controlled by PHY);
* Enabling USB PHY passby in HCI mode (controlled by PMU).

The current code will enable passby for each PHY and reroute PHY0 to MUSB, which is inconsistent and results in broken USB peripheral support.

Passby on PHY0 must only be enabled when we want to use HCI. Since host/device mode detection is not available from the PHY code and because U-Boot does not support changing the mode dynamically anyway, we can just mux the controller to MUSB if it is enabled and mux it to HCI otherwise.

This fixes USB peripheral support for platforms with PHY0 dual-route, especially H3/H5 and V3s.

---
 drivers/phy/allwinner/phy-sun4i-usb.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/phy/allwinner/phy-sun4i-usb.c +9 -0
index f206fa3f5d48..4f1c7e519d71 100644
@@ -302,9 +302,21 @@ static int sun4i_usb_phy_init(struct phy *phy)
                                    data->cfg->disc_thresh, PHY_DISCON_TH_LEN);
        }
 
+#ifdef CONFIG_USB_MUSB_SUNXI
+       /* Needed for HCI and conflicts with MUSB, keep PHY0 on MUSB */
+       if (usb_phy->id != 0)
+               sun4i_usb_phy_passby(phy, true);
+
+       /* Route PHY0 to MUSB to allow USB gadget */
+       if (data->cfg->phy0_dual_route)
+               sun4i_usb_phy0_reroute(data, true);
+#else
        sun4i_usb_phy_passby(phy, true);
 
Quoted 9 lines

drivers/phy/allwinner/phy-sun4i-usb.c static int sun4i_usb_phy_init(struct phy *phy) · line 319

Quoted 5 lines
drivers/phy/allwinner/phy-sun4i-usb.c +4 -1
-       sun4i_usb_phy0_reroute(data, true);
+       /* Route PHY0 to HCI to allow USB host */
+       if (data->cfg->phy0_dual_route)
+               sun4i_usb_phy0_reroute(data, false);
+#endif  

I think we can manage this route and passby dynamically by detecting id since we have dr_mode verify the MUSB host or peripheral via usb_get_dr_mode, any chance to try that way?

Quoted 8 lines

Oh, I didn't know that U-Boot has support for usb_get_dr_mode these days. Thanks!

So far, the sunxi port has been using Kconfig to distinguish between host/device (unless I'm mistaken?) so I feel like this should be a separate follow-up patch to convert the sunxi MUSB glue + PHY to detecting dr_mode using usb_get_dr_mode. This feels like a significant rework, too.

Yes.

Quoted 6 lines

Also, how should we handle the OTG case? I'm not sure we can support having both musb host and gadget built-in at this point. But that would certainly be welcome as part of the rework, too.

What do you think?

You mean handling dr_mode at runtime.

Quoted 8 lines

If yes, It is bit new where we can register the musb as UCLASS_MISC wrapper and decide to bind driver for host and peripheral by decoding dr_mode. and indeed host should register with UCLASS_USB and peripheral with UCLASS_USB_GADGET_GENERIC.

I tried this wrapper before, not placed in-between because of other work but TI musb has similar code to manage this drivers/usb/musb-new/ti-musb.c

Before we go wild with any fancy rework, can we possibly take this patch as it? As I realised, this is basically a better version of the patch I sent two weeks ago [1]. I tried Paul's patch back then, but was missing the phys property in the DT, which I addressed in patch 2/2.

Quoted 6 lines

So I would appreciate if we can take this patch, as it solves a real problem (upper USB port not working) on many Pine64 boards (given the small DT change is in place). And on those boards the OTG functionality is not really feasible anyway, as VBUS is either permanently enabled or at least tied to the other host port's supply, so we can't turn it off for peripheral mode.

Quoted 3 lines

Looks like nothing has moved forward on this (quite significant) fixup.

Could we please merge it as soon as time allows?

Yes, +1.
Jagan, can you please make sure to push this in this merge window?

FWIW:

Thanks,
Andre.

Quoted 10 lines

Cheers and thanks in advance,

Paul

Quoted 4 lines

Cheers,
Andre.

[1] https://lists.denx.de/pipermail/u-boot/2019-May/369521.html

#8 lore raw

PATCH 1/1 phy: sun4i-usb: Fix PHY0 routing and passby configuration for MUSB

In reply to André Przywara
Quoted 88 lines · André Przywara
Quoted 2 lines · Jagan Teki

On Mon, Apr 15, 2019 at 1:52 PM Paul Kocialkowski
<[email protected]> wrote:

Hi,

Quoted 81 lines
Quoted 56 lines · Jagan Teki
Quoted 45 lines
Quoted 43 lines · Paul Kocialkowski

Recent Allwinner platforms (starting with the H3) only use the MUSB controller for peripheral mode and use HCI for host mode. As a result, extra steps need to be taken to properly route USB signals to one or the other. More precisely, the following is required:
* Routing the pins to either HCI/MUSB (controlled by PHY);
* Enabling USB PHY passby in HCI mode (controlled by PMU).

The current code will enable passby for each PHY and reroute PHY0 to MUSB, which is inconsistent and results in broken USB peripheral support.

Passby on PHY0 must only be enabled when we want to use HCI. Since host/device mode detection is not available from the PHY code and because U-Boot does not support changing the mode dynamically anyway, we can just mux the controller to MUSB if it is enabled and mux it to HCI otherwise.

This fixes USB peripheral support for platforms with PHY0 dual-route, especially H3/H5 and V3s.

---
 drivers/phy/allwinner/phy-sun4i-usb.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/phy/allwinner/phy-sun4i-usb.c +9 -0
index f206fa3f5d48..4f1c7e519d71 100644
@@ -302,9 +302,21 @@ static int sun4i_usb_phy_init(struct phy *phy)
                                    data->cfg->disc_thresh, PHY_DISCON_TH_LEN);
        }
 
+#ifdef CONFIG_USB_MUSB_SUNXI
+       /* Needed for HCI and conflicts with MUSB, keep PHY0 on MUSB */
+       if (usb_phy->id != 0)
+               sun4i_usb_phy_passby(phy, true);
+
+       /* Route PHY0 to MUSB to allow USB gadget */
+       if (data->cfg->phy0_dual_route)
+               sun4i_usb_phy0_reroute(data, true);
+#else
        sun4i_usb_phy_passby(phy, true);
 
Quoted 9 lines

drivers/phy/allwinner/phy-sun4i-usb.c static int sun4i_usb_phy_init(struct phy *phy) · line 319

Quoted 5 lines
drivers/phy/allwinner/phy-sun4i-usb.c +4 -1
-       sun4i_usb_phy0_reroute(data, true);
+       /* Route PHY0 to HCI to allow USB host */
+       if (data->cfg->phy0_dual_route)
+               sun4i_usb_phy0_reroute(data, false);
+#endif

I think we can manage this route and passby dynamically by detecting id since we have dr_mode verify the MUSB host or peripheral via usb_get_dr_mode, any chance to try that way?

Quoted 8 lines

Oh, I didn't know that U-Boot has support for usb_get_dr_mode these days. Thanks!

So far, the sunxi port has been using Kconfig to distinguish between host/device (unless I'm mistaken?) so I feel like this should be a separate follow-up patch to convert the sunxi MUSB glue + PHY to detecting dr_mode using usb_get_dr_mode. This feels like a significant rework, too.

Yes.

Quoted 6 lines

Also, how should we handle the OTG case? I'm not sure we can support having both musb host and gadget built-in at this point. But that would certainly be welcome as part of the rework, too.

What do you think?

You mean handling dr_mode at runtime.

If yes, It is bit new where we can register the musb as UCLASS_MISC wrapper and decide to bind driver for host and peripheral by decoding dr_mode. and indeed host should register with UCLASS_USB and peripheral with UCLASS_USB_GADGET_GENERIC.

Quoted 7 lines
Quoted 3 lines

I tried this wrapper before, not placed in-between because of other work but TI musb has similar code to manage this drivers/usb/musb-new/ti-musb.c

Before we go wild with any fancy rework, can we possibly take this patch as it? As I realised, this is basically a better version of the patch I sent two weeks ago [1]. I tried Paul's patch back then, but was missing

Sorry, I missed this. yes rework can be a fancy but it's been discussed months back so I was expected to have this meaningful rework patch in-between so-that it would eventually reviewed and may plan for this MW.

Having said that I'm not so interested to go with ifdef code in dm driver( which we filter many thing before). better have a sample rework patch which still can review know.

#9 lore raw

PATCH 1/1 phy: sun4i-usb: Fix PHY0 routing and passby configuration for MUSB

Hi,

Quoted 93 lines · Jagan Teki
Quoted 92 lines · André Przywara
Quoted 2 lines · Jagan Teki

On Mon, Apr 15, 2019 at 1:52 PM Paul Kocialkowski
<[email protected]> wrote:

Hi,

Quoted 84 lines
Quoted 56 lines · Jagan Teki
Quoted 45 lines
Quoted 43 lines · Paul Kocialkowski

Recent Allwinner platforms (starting with the H3) only use the MUSB controller for peripheral mode and use HCI for host mode. As a result, extra steps need to be taken to properly route USB signals to one or the other. More precisely, the following is required:
* Routing the pins to either HCI/MUSB (controlled by PHY);
* Enabling USB PHY passby in HCI mode (controlled by PMU).

The current code will enable passby for each PHY and reroute PHY0 to MUSB, which is inconsistent and results in broken USB peripheral support.

Passby on PHY0 must only be enabled when we want to use HCI. Since host/device mode detection is not available from the PHY code and because U-Boot does not support changing the mode dynamically anyway, we can just mux the controller to MUSB if it is enabled and mux it to HCI otherwise.

This fixes USB peripheral support for platforms with PHY0 dual-route, especially H3/H5 and V3s.

---
 drivers/phy/allwinner/phy-sun4i-usb.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/phy/allwinner/phy-sun4i-usb.c +9 -0
index f206fa3f5d48..4f1c7e519d71 100644
@@ -302,9 +302,21 @@ static int sun4i_usb_phy_init(struct phy *phy)
                                    data->cfg->disc_thresh, PHY_DISCON_TH_LEN);
        }
 
+#ifdef CONFIG_USB_MUSB_SUNXI
+       /* Needed for HCI and conflicts with MUSB, keep PHY0 on MUSB */
+       if (usb_phy->id != 0)
+               sun4i_usb_phy_passby(phy, true);
+
+       /* Route PHY0 to MUSB to allow USB gadget */
+       if (data->cfg->phy0_dual_route)
+               sun4i_usb_phy0_reroute(data, true);
+#else
        sun4i_usb_phy_passby(phy, true);
 
Quoted 9 lines

drivers/phy/allwinner/phy-sun4i-usb.c static int sun4i_usb_phy_init(struct phy *phy) · line 319

Quoted 5 lines
drivers/phy/allwinner/phy-sun4i-usb.c +4 -1
-       sun4i_usb_phy0_reroute(data, true);
+       /* Route PHY0 to HCI to allow USB host */
+       if (data->cfg->phy0_dual_route)
+               sun4i_usb_phy0_reroute(data, false);
+#endif

I think we can manage this route and passby dynamically by detecting id since we have dr_mode verify the MUSB host or peripheral via usb_get_dr_mode, any chance to try that way?

Quoted 8 lines

Oh, I didn't know that U-Boot has support for usb_get_dr_mode these days. Thanks!

So far, the sunxi port has been using Kconfig to distinguish between host/device (unless I'm mistaken?) so I feel like this should be a separate follow-up patch to convert the sunxi MUSB glue + PHY to detecting dr_mode using usb_get_dr_mode. This feels like a significant rework, too.

Yes.

Quoted 6 lines

Also, how should we handle the OTG case? I'm not sure we can support having both musb host and gadget built-in at this point. But that would certainly be welcome as part of the rework, too.

What do you think?

You mean handling dr_mode at runtime.

If yes, It is bit new where we can register the musb as UCLASS_MISC wrapper and decide to bind driver for host and peripheral by decoding dr_mode. and indeed host should register with UCLASS_USB and peripheral with UCLASS_USB_GADGET_GENERIC.

I tried this wrapper before, not placed in-between because of other work but TI musb has similar code to manage this drivers/usb/musb-new/ti-musb.c

Quoted 8 lines
Quoted 3 lines

Before we go wild with any fancy rework, can we possibly take this patch as it? As I realised, this is basically a better version of the patch I sent two weeks ago [1]. I tried Paul's patch back then, but was missing

Sorry, I missed this. yes rework can be a fancy but it's been discussed months back so I was expected to have this meaningful rework patch in-between so-that it would eventually reviewed and may plan for this MW.

Oh, has anyone started work in this direction so far?

Quoted 2 lines

Having said that I'm not so interested to go with ifdef code in dm driver

Do you have a better option than ifdef to suggest for now?

Quoted 2 lines

( which we filter many thing before). better have a sample rework patch which still can review know.

I'm afraid I don't follow what you mean with that.

Cheers,

Paul

Signature · 3 lines
Paul Kocialkowski, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
#10 lore raw

PATCH 1/1 phy: sun4i-usb: Fix PHY0 routing and passby configuration for MUSB

Quoted 101 lines · Paul Kocialkowski

Hi,

Quoted 97 lines · Jagan Teki
Quoted 95 lines · André Przywara
Quoted 2 lines · Jagan Teki

On Mon, Apr 15, 2019 at 1:52 PM Paul Kocialkowski
<[email protected]> wrote:

Hi,

Quoted 76 lines
Quoted 56 lines · Jagan Teki
Quoted 45 lines
Quoted 43 lines · Paul Kocialkowski

Recent Allwinner platforms (starting with the H3) only use the MUSB controller for peripheral mode and use HCI for host mode. As a result, extra steps need to be taken to properly route USB signals to one or the other. More precisely, the following is required:
* Routing the pins to either HCI/MUSB (controlled by PHY);
* Enabling USB PHY passby in HCI mode (controlled by PMU).

The current code will enable passby for each PHY and reroute PHY0 to MUSB, which is inconsistent and results in broken USB peripheral support.

Passby on PHY0 must only be enabled when we want to use HCI. Since host/device mode detection is not available from the PHY code and because U-Boot does not support changing the mode dynamically anyway, we can just mux the controller to MUSB if it is enabled and mux it to HCI otherwise.

This fixes USB peripheral support for platforms with PHY0 dual-route, especially H3/H5 and V3s.

---
 drivers/phy/allwinner/phy-sun4i-usb.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/phy/allwinner/phy-sun4i-usb.c +9 -0
index f206fa3f5d48..4f1c7e519d71 100644
@@ -302,9 +302,21 @@ static int sun4i_usb_phy_init(struct phy *phy)
                                    data->cfg->disc_thresh, PHY_DISCON_TH_LEN);
        }
 
+#ifdef CONFIG_USB_MUSB_SUNXI
+       /* Needed for HCI and conflicts with MUSB, keep PHY0 on MUSB */
+       if (usb_phy->id != 0)
+               sun4i_usb_phy_passby(phy, true);
+
+       /* Route PHY0 to MUSB to allow USB gadget */
+       if (data->cfg->phy0_dual_route)
+               sun4i_usb_phy0_reroute(data, true);
+#else
        sun4i_usb_phy_passby(phy, true);
 
Quoted 9 lines

drivers/phy/allwinner/phy-sun4i-usb.c static int sun4i_usb_phy_init(struct phy *phy) · line 319

Quoted 5 lines
drivers/phy/allwinner/phy-sun4i-usb.c +4 -1
-       sun4i_usb_phy0_reroute(data, true);
+       /* Route PHY0 to HCI to allow USB host */
+       if (data->cfg->phy0_dual_route)
+               sun4i_usb_phy0_reroute(data, false);
+#endif

I think we can manage this route and passby dynamically by detecting id since we have dr_mode verify the MUSB host or peripheral via usb_get_dr_mode, any chance to try that way?

Quoted 8 lines

Oh, I didn't know that U-Boot has support for usb_get_dr_mode these days. Thanks!

So far, the sunxi port has been using Kconfig to distinguish between host/device (unless I'm mistaken?) so I feel like this should be a separate follow-up patch to convert the sunxi MUSB glue + PHY to detecting dr_mode using usb_get_dr_mode. This feels like a significant rework, too.

Yes.

Quoted 6 lines

Also, how should we handle the OTG case? I'm not sure we can support having both musb host and gadget built-in at this point. But that would certainly be welcome as part of the rework, too.

What do you think?

You mean handling dr_mode at runtime.

Quoted 8 lines

If yes, It is bit new where we can register the musb as UCLASS_MISC wrapper and decide to bind driver for host and peripheral by decoding dr_mode. and indeed host should register with UCLASS_USB and peripheral with UCLASS_USB_GADGET_GENERIC.

I tried this wrapper before, not placed in-between because of other work but TI musb has similar code to manage this drivers/usb/musb-new/ti-musb.c

Before we go wild with any fancy rework, can we possibly take this patch as it? As I realised, this is basically a better version of the patch I sent two weeks ago [1]. I tried Paul's patch back then, but was missing

Quoted 6 lines
Quoted 4 lines

Sorry, I missed this. yes rework can be a fancy but it's been discussed months back so I was expected to have this meaningful rework patch in-between so-that it would eventually reviewed and may plan for this MW.

Oh, has anyone started work in this direction so far?

Not sure, I thought you might have working based on our early communication on this thread.

Quoted 5 lines
Quoted 3 lines

Having said that I'm not so interested to go with ifdef code in dm driver

Do you have a better option than ifdef to suggest for now?

Yes, same like what I mentioned above.

Manage the route and passby dynamically by detecting id since we have dr_mode verify the MUSB host or peripheral via usb_get_dr_mode. drivers/usb/musb-new/ti-musb.c does this if I'm not wrong.

Quoted 5 lines
Quoted 3 lines

( which we filter many thing before). better have a sample rework patch which still can review know.

I'm afraid I don't follow what you mean with that.

We have phy driver with lot of ifdef code, so then we created this dm driver managed those via driver data like Linux does. So, adding ifdef code again to this driver feel like going back ward.