* [PATCH] usb: dwc2: Don't reset the core after setting turnaround time
@ 2021-06-03 15:59 Clément Lassieur
2021-06-14 12:43 ` Minas Harutyunyan
0 siblings, 1 reply; 2+ messages in thread
From: Clément Lassieur @ 2021-06-03 15:59 UTC (permalink / raw)
To: linux-usb; +Cc: hminas, jmaselbas, felipe.balbi, Clément Lassieur
Every time the hub signals a reset while we (device) are hsotg->connected,
dwc2_hsotg_core_init_disconnected() is called, which in turn calls
dwc2_hs_phy_init().
GUSBCFG.USBTrdTim is cleared upon Core Soft Reset, so if
hsotg->params.phy_utmi_width is 8-bit, the value of GUSBCFG.USBTrdTim (the
default one: 0x5, corresponding to 16-bit) is always different from
hsotg->params.phy_utmi_width, thus dwc2_core_reset() is called every
time (usbcfg != usbcfg_old), which causes 2 issues:
1) The call to dwc2_core_reset() does another reset 300us after the initial
Chirp K of the first reset (which should last at least Tuch = 1ms), and
messes up the High-speed Detection Handshake: both hub and device drive
current into the D+ and D- lines at the same time.
2) GUSBCFG.USBTrdTim is cleared by the second reset, so its value is always
the default one (0x5).
Setting GUSBCFG.USBTrdTim after the potential call to dwc2_core_reset()
fixes both issues. It is now set even when select_phy is false because the
cost of the Core Soft Reset is removed.
Fixes: 1e868545f2bb ("usb: dwc2: gadget: Move gadget phy init into core phy init")
Signed-off-by: Clément Lassieur <clement@lassieur.org>
---
drivers/usb/dwc2/core.c | 30 +++++++++++++++++++++---------
1 file changed, 21 insertions(+), 9 deletions(-)
diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
index 6f70ab9577b4..272ae5722c86 100644
--- a/drivers/usb/dwc2/core.c
+++ b/drivers/usb/dwc2/core.c
@@ -1111,15 +1111,6 @@ static int dwc2_hs_phy_init(struct dwc2_hsotg *hsotg, bool select_phy)
usbcfg &= ~(GUSBCFG_ULPI_UTMI_SEL | GUSBCFG_PHYIF16);
if (hsotg->params.phy_utmi_width == 16)
usbcfg |= GUSBCFG_PHYIF16;
-
- /* Set turnaround time */
- if (dwc2_is_device_mode(hsotg)) {
- usbcfg &= ~GUSBCFG_USBTRDTIM_MASK;
- if (hsotg->params.phy_utmi_width == 16)
- usbcfg |= 5 << GUSBCFG_USBTRDTIM_SHIFT;
- else
- usbcfg |= 9 << GUSBCFG_USBTRDTIM_SHIFT;
- }
break;
default:
dev_err(hsotg->dev, "FS PHY selected at HS!\n");
@@ -1141,6 +1132,24 @@ static int dwc2_hs_phy_init(struct dwc2_hsotg *hsotg, bool select_phy)
return retval;
}
+static void dwc2_set_turnaround_time(struct dwc2_hsotg *hsotg)
+{
+ u32 usbcfg;
+
+ if (hsotg->params.phy_type != DWC2_PHY_TYPE_PARAM_UTMI)
+ return;
+
+ usbcfg = dwc2_readl(hsotg, GUSBCFG);
+
+ usbcfg &= ~GUSBCFG_USBTRDTIM_MASK;
+ if (hsotg->params.phy_utmi_width == 16)
+ usbcfg |= 5 << GUSBCFG_USBTRDTIM_SHIFT;
+ else
+ usbcfg |= 9 << GUSBCFG_USBTRDTIM_SHIFT;
+
+ dwc2_writel(hsotg, usbcfg, GUSBCFG);
+}
+
int dwc2_phy_init(struct dwc2_hsotg *hsotg, bool select_phy)
{
u32 usbcfg;
@@ -1158,6 +1167,9 @@ int dwc2_phy_init(struct dwc2_hsotg *hsotg, bool select_phy)
retval = dwc2_hs_phy_init(hsotg, select_phy);
if (retval)
return retval;
+
+ if (dwc2_is_device_mode(hsotg))
+ dwc2_set_turnaround_time(hsotg);
}
if (hsotg->hw_params.hs_phy_type == GHWCFG2_HS_PHY_TYPE_ULPI &&
--
2.30.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] usb: dwc2: Don't reset the core after setting turnaround time
2021-06-03 15:59 [PATCH] usb: dwc2: Don't reset the core after setting turnaround time Clément Lassieur
@ 2021-06-14 12:43 ` Minas Harutyunyan
0 siblings, 0 replies; 2+ messages in thread
From: Minas Harutyunyan @ 2021-06-14 12:43 UTC (permalink / raw)
To: Clément Lassieur, linux-usb; +Cc: jmaselbas, felipe.balbi
On 6/3/2021 7:59 PM, Clément Lassieur wrote:
> Every time the hub signals a reset while we (device) are hsotg->connected,
> dwc2_hsotg_core_init_disconnected() is called, which in turn calls
> dwc2_hs_phy_init().
>
> GUSBCFG.USBTrdTim is cleared upon Core Soft Reset, so if
> hsotg->params.phy_utmi_width is 8-bit, the value of GUSBCFG.USBTrdTim (the
> default one: 0x5, corresponding to 16-bit) is always different from
> hsotg->params.phy_utmi_width, thus dwc2_core_reset() is called every
> time (usbcfg != usbcfg_old), which causes 2 issues:
>
> 1) The call to dwc2_core_reset() does another reset 300us after the initial
> Chirp K of the first reset (which should last at least Tuch = 1ms), and
> messes up the High-speed Detection Handshake: both hub and device drive
> current into the D+ and D- lines at the same time.
>
> 2) GUSBCFG.USBTrdTim is cleared by the second reset, so its value is always
> the default one (0x5).
>
> Setting GUSBCFG.USBTrdTim after the potential call to dwc2_core_reset()
> fixes both issues. It is now set even when select_phy is false because the
> cost of the Core Soft Reset is removed.
>
> Fixes: 1e868545f2bb ("usb: dwc2: gadget: Move gadget phy init into core phy init")
> Signed-off-by: Clément Lassieur <clement@lassieur.org>
Acked-by: Minas Harutyunyan <Minas.Harutyunyan@synopsys.com>
> ---
> drivers/usb/dwc2/core.c | 30 +++++++++++++++++++++---------
> 1 file changed, 21 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
> index 6f70ab9577b4..272ae5722c86 100644
> --- a/drivers/usb/dwc2/core.c
> +++ b/drivers/usb/dwc2/core.c
> @@ -1111,15 +1111,6 @@ static int dwc2_hs_phy_init(struct dwc2_hsotg *hsotg, bool select_phy)
> usbcfg &= ~(GUSBCFG_ULPI_UTMI_SEL | GUSBCFG_PHYIF16);
> if (hsotg->params.phy_utmi_width == 16)
> usbcfg |= GUSBCFG_PHYIF16;
> -
> - /* Set turnaround time */
> - if (dwc2_is_device_mode(hsotg)) {
> - usbcfg &= ~GUSBCFG_USBTRDTIM_MASK;
> - if (hsotg->params.phy_utmi_width == 16)
> - usbcfg |= 5 << GUSBCFG_USBTRDTIM_SHIFT;
> - else
> - usbcfg |= 9 << GUSBCFG_USBTRDTIM_SHIFT;
> - }
> break;
> default:
> dev_err(hsotg->dev, "FS PHY selected at HS!\n");
> @@ -1141,6 +1132,24 @@ static int dwc2_hs_phy_init(struct dwc2_hsotg *hsotg, bool select_phy)
> return retval;
> }
>
> +static void dwc2_set_turnaround_time(struct dwc2_hsotg *hsotg)
> +{
> + u32 usbcfg;
> +
> + if (hsotg->params.phy_type != DWC2_PHY_TYPE_PARAM_UTMI)
> + return;
> +
> + usbcfg = dwc2_readl(hsotg, GUSBCFG);
> +
> + usbcfg &= ~GUSBCFG_USBTRDTIM_MASK;
> + if (hsotg->params.phy_utmi_width == 16)
> + usbcfg |= 5 << GUSBCFG_USBTRDTIM_SHIFT;
> + else
> + usbcfg |= 9 << GUSBCFG_USBTRDTIM_SHIFT;
> +
> + dwc2_writel(hsotg, usbcfg, GUSBCFG);
> +}
> +
> int dwc2_phy_init(struct dwc2_hsotg *hsotg, bool select_phy)
> {
> u32 usbcfg;
> @@ -1158,6 +1167,9 @@ int dwc2_phy_init(struct dwc2_hsotg *hsotg, bool select_phy)
> retval = dwc2_hs_phy_init(hsotg, select_phy);
> if (retval)
> return retval;
> +
> + if (dwc2_is_device_mode(hsotg))
> + dwc2_set_turnaround_time(hsotg);
> }
>
> if (hsotg->hw_params.hs_phy_type == GHWCFG2_HS_PHY_TYPE_ULPI &&
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-06-14 12:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-03 15:59 [PATCH] usb: dwc2: Don't reset the core after setting turnaround time Clément Lassieur
2021-06-14 12:43 ` Minas Harutyunyan
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.