usb: dwc2: Fix logic for setup of GUSBCFG->ULPI_UTMI_Sel bit
PATCH 1/1 usb: dwc2: Fix logic for setup of GUSBCFG->ULPI_UTMI_Sel bit
According to the databook "ULPI_UTMI_Sel" bit (#4) in GUSBCFG register selects between ULPI and UTMI+ interfaces such that:
0 - stands for UTMI+ interface
1 - stands for ULPI interface
Currently implemented logic in the driver is incorrect because CONFIG_DWC2_PHY_TYPE is not a "bool" but instead this is an "enum" which starts from 0 in case of full-speed and is either 1 for UTMI or 2 for ULPI.
In dwc2.h we have:
---------------------->8----------------------
#define DWC2_PHY_TYPE_FS 0
#define DWC2_PHY_TYPE_UTMI 1
#define DWC2_PHY_TYPE_ULPI 2
#define CONFIG_DWC2_PHY_TYPE DWC2_PHY_TYPE_UTMI
---------------------->8----------------------
And in dwc2.c we do "|= CONFIG_DWC2_PHY_TYPE << 4" effectively setting "ULPI_UTMI_Sel" bit for UTMI+ and what's even worse for ULMI we keep "ULPI_UTMI_Sel" zeroed while setting the next "FSIntf" bit (#5) unexpectedly selecting Full speed interface!
--- drivers/usb/host/dwc2.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/usb/host/dwc2.c +3 -1
@@ -366,7 +366,9 @@ static void dwc_otg_core_init(struct dwc2_priv *priv)* immediately after setting phyif. */ usbcfg &= ~(DWC2_GUSBCFG_ULPI_UTMI_SEL |DWC2_GUSBCFG_PHYIF ); - usbcfg |=CONFIG_DWC2_PHY_TYPE <<DWC2_GUSBCFG_ULPI_UTMI_SEL_OFFSET ; +#if (CONFIG_DWC2_PHY_TYPE ==DWC2_PHY_TYPE_ULPI ) + usbcfg |=DWC2_GUSBCFG_ULPI_UTMI_SEL ; +#endif if (usbcfg &DWC2_GUSBCFG_ULPI_UTMI_SEL ) {/* ULPI interface */ #ifdef CONFIG_DWC2_PHY_ULPI_DDR
Signature · 1 line
2.14.3
PATCH 1/1 usb: dwc2: Fix logic for setup of GUSBCFG->ULPI_UTMI_Sel bit
Quoted 35 lines · Alexey Brodkin
According to the databook "
ULPI_UTMI_Sel" bit (#4) in GUSBCFG register selects between ULPI and UTMI+ interfaces such that:
0 - stands for UTMI+ interface
1 - stands for ULPI interfaceCurrently implemented logic in the driver is incorrect because
CONFIG_DWC2_PHY_TYPEis not a "bool" but instead this is an "enum" which starts from 0 in case of full-speed and is either 1 for UTMI or 2 for ULPI.In
dwc2.hwe have:
---------------------->8----------------------
#defineDWC2_PHY_TYPE_FS0
#defineDWC2_PHY_TYPE_UTMI1
#defineDWC2_PHY_TYPE_ULPI2
#defineCONFIG_DWC2_PHY_TYPEDWC2_PHY_TYPE_UTMI
---------------------->8----------------------And in
dwc2.cwe do "|=CONFIG_DWC2_PHY_TYPE<< 4" effectively setting "ULPI_UTMI_Sel" bit for UTMI+ and what's even worse for ULMI we keep "ULPI_UTMI_Sel" zeroed while setting the next "FSIntf" bit (#5) unexpectedly selecting Full speed interface!Signed-off-by Alexey Brodkin <[email protected]>Cc Marek Vasut <[email protected]>--- drivers/usb/host/dwc2.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/usb/host/dwc2.c +0
-0
drivers/usb/host/dwc2.c static void dwc_otg_core_init(struct dwc2_priv *priv) · line 369
Quoted 4 lines
drivers/usb/host/dwc2.c +0
-1@@ -366,7 +366,9 @@ static void dwc_otg_core_init(struct dwc2_priv *priv)* immediately after setting phyif. */ usbcfg &= ~(DWC2_GUSBCFG_ULPI_UTMI_SEL |DWC2_GUSBCFG_PHYIF ); - usbcfg |=CONFIG_DWC2_PHY_TYPE <<DWC2_GUSBCFG_ULPI_UTMI_SEL_OFFSET ;
What happens if PHY type is set to FS or UTMI , won't that change the behavior of this code ?
drivers/usb/host/dwc2.c static void dwc_otg_core_init(struct dwc2_priv *priv) · line 373
Quoted 5 lines
drivers/usb/host/dwc2.c +3
-0+#if (CONFIG_DWC2_PHY_TYPE ==DWC2_PHY_TYPE_ULPI ) + usbcfg |=DWC2_GUSBCFG_ULPI_UTMI_SEL ; +#endif if (usbcfg &DWC2_GUSBCFG_ULPI_UTMI_SEL ) {/* ULPI interface */
This condition should be tweaked, I think. You set the ULPI_UTMI_SEL bit above and check for it here again, that's a bit odd.
Quoted 2 lines
drivers/usb/host/dwc2.c +0
-0#ifdef CONFIG_DWC2_PHY_ULPI_DDR
Signature · 2 lines
Best regards, Marek Vasut
PATCH 1/1 usb: dwc2: Fix logic for setup of GUSBCFG->ULPI_UTMI_Sel bit
Hi Marek,
Quoted 37 lines
-----Original Message-----
From: Marek Vasut [mailto:marex at denx.de]
Sent: Monday, February 5, 2018 4:23 PM
To: Alexey Brodkin <[email protected]>; u-boot at lists.denx.de
Subject: Re: [PATCH] usb: dwc2: Fix logic for setup ofGUSBCFG->ULPI_UTMI_SelbitQuoted 30 lines · Alexey Brodkin
According to the databook "
ULPI_UTMI_Sel" bit (#4) in GUSBCFG register selects between ULPI and UTMI+ interfaces such that:
0 - stands for UTMI+ interface
1 - stands for ULPI interfaceCurrently implemented logic in the driver is incorrect because
CONFIG_DWC2_PHY_TYPEis not a "bool" but instead this is an "enum" which starts from 0 in case of full-speed and is either 1 for UTMI or 2 for ULPI.In
dwc2.hwe have:
---------------------->8----------------------
#defineDWC2_PHY_TYPE_FS0
#defineDWC2_PHY_TYPE_UTMI1
#defineDWC2_PHY_TYPE_ULPI2
#defineCONFIG_DWC2_PHY_TYPEDWC2_PHY_TYPE_UTMI
---------------------->8----------------------And in
dwc2.cwe do "|=CONFIG_DWC2_PHY_TYPE<< 4" effectively setting "ULPI_UTMI_Sel" bit for UTMI+ and what's even worse for ULMI we keep "ULPI_UTMI_Sel" zeroed while setting the next "FSIntf" bit (#5) unexpectedly selecting Full speed interface!Signed-off-by Alexey Brodkin <[email protected]>Cc Marek Vasut <[email protected]>--- drivers/usb/host/dwc2.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 12 lines
drivers/usb/host/dwc2.c static void dwc_otg_core_init(struct dwc2_priv *priv) · line 369
Quoted 9 lines
drivers/usb/host/dwc2.c +0
-1@@ -366,7 +366,9 @@ static void dwc_otg_core_init(struct dwc2_priv *priv)* immediately after setting phyif. */ usbcfg &= ~(DWC2_GUSBCFG_ULPI_UTMI_SEL |DWC2_GUSBCFG_PHYIF ); - usbcfg |=CONFIG_DWC2_PHY_TYPE <<DWC2_GUSBCFG_ULPI_UTMI_SEL_OFFSET ;What happens if PHY type is set to FS or UTMI , won't that change the behavior of this code ?
Well if you look a bit more at that driver you'll notice that [there're way too many ifdefs] FS-part is in a separate ifdef section so we don’t need to worry about it in HS-part :)
Quoted 8 lines
drivers/usb/host/dwc2.c static void dwc_otg_core_init(struct dwc2_priv *priv) · line 373
Quoted 5 lines
drivers/usb/host/dwc2.c +3
-0+#if (CONFIG_DWC2_PHY_TYPE ==DWC2_PHY_TYPE_ULPI ) + usbcfg |=DWC2_GUSBCFG_ULPI_UTMI_SEL ; +#endif if (usbcfg &DWC2_GUSBCFG_ULPI_UTMI_SEL ) {/* ULPI interface */ This condition should be tweaked, I think. You set the
ULPI_UTMI_SELbit above and check for it here again, that's a bit odd.
Completely agree but again my intention was to move with very tiny steps Fixing one issue at a time such that heavy refactoring could be escaped... But I would agree that this driver definitely needs refactoring because of those Configuration options, some incorrect checks etc. But I'd think it's still better To have expectedly working code today (i.e. fix existing code) instead of waiting for major rewrite sometime down the line.
-Alexey
PATCH 1/1 usb: dwc2: Fix logic for setup of GUSBCFG->ULPI_UTMI_Sel bit
Quoted 52 lines · Alexey Brodkin
Hi Marek,
Quoted 37 lines
-----Original Message-----
From: Marek Vasut [mailto:marex at denx.de]
Sent: Monday, February 5, 2018 4:23 PM
To: Alexey Brodkin <[email protected]>; u-boot at lists.denx.de
Subject: Re: [PATCH] usb: dwc2: Fix logic for setup ofGUSBCFG->ULPI_UTMI_SelbitQuoted 30 lines · Alexey Brodkin
According to the databook "
ULPI_UTMI_Sel" bit (#4) in GUSBCFG register selects between ULPI and UTMI+ interfaces such that:
0 - stands for UTMI+ interface
1 - stands for ULPI interfaceCurrently implemented logic in the driver is incorrect because
CONFIG_DWC2_PHY_TYPEis not a "bool" but instead this is an "enum" which starts from 0 in case of full-speed and is either 1 for UTMI or 2 for ULPI.In
dwc2.hwe have:
---------------------->8----------------------
#defineDWC2_PHY_TYPE_FS0
#defineDWC2_PHY_TYPE_UTMI1
#defineDWC2_PHY_TYPE_ULPI2
#defineCONFIG_DWC2_PHY_TYPEDWC2_PHY_TYPE_UTMI
---------------------->8----------------------And in
dwc2.cwe do "|=CONFIG_DWC2_PHY_TYPE<< 4" effectively setting "ULPI_UTMI_Sel" bit for UTMI+ and what's even worse for ULMI we keep "ULPI_UTMI_Sel" zeroed while setting the next "FSIntf" bit (#5) unexpectedly selecting Full speed interface!Signed-off-by Alexey Brodkin <[email protected]>Cc Marek Vasut <[email protected]>--- drivers/usb/host/dwc2.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)Quoted 12 lines
drivers/usb/host/dwc2.c static void dwc_otg_core_init(struct dwc2_priv *priv) · line 369
Quoted 9 lines
drivers/usb/host/dwc2.c +0
-1@@ -366,7 +366,9 @@ static void dwc_otg_core_init(struct dwc2_priv *priv)* immediately after setting phyif. */ usbcfg &= ~(DWC2_GUSBCFG_ULPI_UTMI_SEL |DWC2_GUSBCFG_PHYIF ); - usbcfg |=CONFIG_DWC2_PHY_TYPE <<DWC2_GUSBCFG_ULPI_UTMI_SEL_OFFSET ;What happens if PHY type is set to FS or UTMI , won't that change the behavior of this code ?
Quoted 3 lines
Well if you look a bit more at that driver you'll notice that [there're way too many ifdefs] FS-part is in a separate ifdef section so we don’t need to worry about it in HS-part :)
Do you want to clean it up ? :)
Quoted 11 lines
Quoted 8 lines
drivers/usb/host/dwc2.c static void dwc_otg_core_init(struct dwc2_priv *priv) · line 373
Quoted 5 lines
drivers/usb/host/dwc2.c +3
-0+#if (CONFIG_DWC2_PHY_TYPE ==DWC2_PHY_TYPE_ULPI ) + usbcfg |=DWC2_GUSBCFG_ULPI_UTMI_SEL ; +#endif if (usbcfg &DWC2_GUSBCFG_ULPI_UTMI_SEL ) {/* ULPI interface */ This condition should be tweaked, I think. You set the
ULPI_UTMI_SELbit above and check for it here again, that's a bit odd.Completely agree but again my intention was to move with very tiny steps Fixing one issue at a time such that heavy refactoring could be escaped...
I'd like this cleaned, this is really braindead. Feel free to send two patches or squash it into one, I don't care, but this is just braindead.
Quoted 4 lines
But I would agree that this driver definitely needs refactoring because of those Configuration options, some incorrect checks etc. But I'd think it's still better To have expectedly working code today (i.e. fix existing code) instead of waiting for major rewrite sometime down the line.
I'm not debating that part, I'm just cranky about the weirdness above.
Quoted 2 lines
-Alexey
Signature · 2 lines
Best regards, Marek Vasut