Linux-USB Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] usb: dwc3: reset the address and run_stop on init
@ 2019-09-05  9:51 Roman Kapl
  2019-09-05 18:57 ` Thinh Nguyen
  0 siblings, 1 reply; 4+ messages in thread
From: Roman Kapl @ 2019-09-05  9:51 UTC (permalink / raw)
  To: linux-usb; +Cc: Greg Kroah-Hartman, Felipe Balbi, Roman Kapl

The address should be set to zero during reset according to the
documentation. Clearing RunStop ensures that the host disconnects from
the device (it was not cleared by CSFTRST, at least on ls1043).

This allows the dwc3 to properly initialize even if the previous
driver did not shutdown the device (e.g. when using virtualization).

Signed-off-by: Roman Kapl <rka@sysgo.com>
---
 drivers/usb/dwc3/core.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index c9bb93a2c81e..c633f5e0621d 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -250,6 +250,7 @@ static int dwc3_core_soft_reset(struct dwc3 *dwc)
 
 	reg = dwc3_readl(dwc->regs, DWC3_DCTL);
 	reg |= DWC3_DCTL_CSFTRST;
+	reg &= ~DWC3_DCTL_RUN_STOP;
 	dwc3_writel(dwc->regs, DWC3_DCTL, reg);
 
 	do {
@@ -266,6 +267,10 @@ static int dwc3_core_soft_reset(struct dwc3 *dwc)
 	return -ETIMEDOUT;
 
 done:
+	reg = dwc3_readl(dwc->regs, DWC3_DCFG);
+	reg &= ~(DWC3_DCFG_DEVADDR_MASK);
+	dwc3_writel(dwc->regs, DWC3_DCFG, reg);
+
 	/*
 	 * For DWC_usb31 controller, once DWC3_DCTL_CSFTRST bit is cleared,
 	 * we must wait at least 50ms before accessing the PHY domain
-- 
2.22.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] usb: dwc3: reset the address and run_stop on init
  2019-09-05  9:51 [PATCH] usb: dwc3: reset the address and run_stop on init Roman Kapl
@ 2019-09-05 18:57 ` Thinh Nguyen
  2019-09-09  9:32   ` Roman Kapl
  0 siblings, 1 reply; 4+ messages in thread
From: Thinh Nguyen @ 2019-09-05 18:57 UTC (permalink / raw)
  To: Roman Kapl, linux-usb; +Cc: Greg Kroah-Hartman, Felipe Balbi

Hi,

Roman Kapl wrote:
> The address should be set to zero during reset according to the
> documentation.

That is for usb reset and not core soft reset, and dwc3 already handles 
that case.

> Clearing RunStop ensures that the host disconnects from
> the device (it was not cleared by CSFTRST, at least on ls1043).
>
> This allows the dwc3 to properly initialize even if the previous
> driver did not shutdown the device (e.g. when using virtualization).

This sounds like a workaround to some issue that the function driver did 
not handle.

> Signed-off-by: Roman Kapl <rka@sysgo.com>
> ---
>   drivers/usb/dwc3/core.c | 5 +++++
>   1 file changed, 5 insertions(+)
>
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index c9bb93a2c81e..c633f5e0621d 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -250,6 +250,7 @@ static int dwc3_core_soft_reset(struct dwc3 *dwc)
>   
>   	reg = dwc3_readl(dwc->regs, DWC3_DCTL);
>   	reg |= DWC3_DCTL_CSFTRST;
> +	reg &= ~DWC3_DCTL_RUN_STOP;
>   	dwc3_writel(dwc->regs, DWC3_DCTL, reg);
>   
>   	do {
> @@ -266,6 +267,10 @@ static int dwc3_core_soft_reset(struct dwc3 *dwc)
>   	return -ETIMEDOUT;
>   
>   done:
> +	reg = dwc3_readl(dwc->regs, DWC3_DCFG);
> +	reg &= ~(DWC3_DCFG_DEVADDR_MASK);
> +	dwc3_writel(dwc->regs, DWC3_DCFG, reg);
> +
>   	/*
>   	 * For DWC_usb31 controller, once DWC3_DCTL_CSFTRST bit is cleared,
>   	 * we must wait at least 50ms before accessing the PHY domain

BR,
Thinh

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] usb: dwc3: reset the address and run_stop on init
  2019-09-05 18:57 ` Thinh Nguyen
@ 2019-09-09  9:32   ` Roman Kapl
  2019-09-09 17:54     ` Thinh Nguyen
  0 siblings, 1 reply; 4+ messages in thread
From: Roman Kapl @ 2019-09-09  9:32 UTC (permalink / raw)
  To: Thinh Nguyen, Roman Kapl, linux-usb; +Cc: Greg Kroah-Hartman, Felipe Balbi

Hello,

On 9/5/19 8:57 PM, Thinh Nguyen wrote:
> Hi,
> 
> Roman Kapl wrote:
>> The address should be set to zero during reset according to the
>> documentation.
> 
> That is for usb reset and not core soft reset, and dwc3 already handles
> that case.

I thought that core soft reset is part of the USB reset (it is done 
during the init, right?).

> 
>> Clearing RunStop ensures that the host disconnects from
>> the device (it was not cleared by CSFTRST, at least on ls1043).
>>
>> This allows the dwc3 to properly initialize even if the previous
>> driver did not shutdown the device (e.g. when using virtualization).
> 
> This sounds like a workaround to some issue that the function driver did
> not handle.

I am using the ACM function driver. However, as I said, the issue arises 
only when the dwc3 driver is in a guest OS that is rebooted (even if the 
reboot is initiated from within the guest OS, not a hard reset).

Maybe this is out of scope for Linux, trying to 'clean up' after the 
previous driver?

Thank you, Roman Kapl

> 
>> Signed-off-by: Roman Kapl <rka@sysgo.com>
>> ---
>>    drivers/usb/dwc3/core.c | 5 +++++
>>    1 file changed, 5 insertions(+)
>>
>> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
>> index c9bb93a2c81e..c633f5e0621d 100644
>> --- a/drivers/usb/dwc3/core.c
>> +++ b/drivers/usb/dwc3/core.c
>> @@ -250,6 +250,7 @@ static int dwc3_core_soft_reset(struct dwc3 *dwc)
>>    
>>    	reg = dwc3_readl(dwc->regs, DWC3_DCTL);
>>    	reg |= DWC3_DCTL_CSFTRST;
>> +	reg &= ~DWC3_DCTL_RUN_STOP;
>>    	dwc3_writel(dwc->regs, DWC3_DCTL, reg);
>>    
>>    	do {
>> @@ -266,6 +267,10 @@ static int dwc3_core_soft_reset(struct dwc3 *dwc)
>>    	return -ETIMEDOUT;
>>    
>>    done:
>> +	reg = dwc3_readl(dwc->regs, DWC3_DCFG);
>> +	reg &= ~(DWC3_DCFG_DEVADDR_MASK);
>> +	dwc3_writel(dwc->regs, DWC3_DCFG, reg);
>> +
>>    	/*
>>    	 * For DWC_usb31 controller, once DWC3_DCTL_CSFTRST bit is cleared,
>>    	 * we must wait at least 50ms before accessing the PHY domain
> 
> BR,
> Thinh
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] usb: dwc3: reset the address and run_stop on init
  2019-09-09  9:32   ` Roman Kapl
@ 2019-09-09 17:54     ` Thinh Nguyen
  0 siblings, 0 replies; 4+ messages in thread
From: Thinh Nguyen @ 2019-09-09 17:54 UTC (permalink / raw)
  To: Roman Kapl, Thinh Nguyen, Roman Kapl, linux-usb
  Cc: Greg Kroah-Hartman, Felipe Balbi

Hi,

Roman Kapl wrote:
> Hello,
>
> On 9/5/19 8:57 PM, Thinh Nguyen wrote:
>> Hi,
>>
>> Roman Kapl wrote:
>>> The address should be set to zero during reset according to the
>>> documentation.
>>
>> That is for usb reset and not core soft reset, and dwc3 already handles
>> that case.
>
> I thought that core soft reset is part of the USB reset (it is done 
> during the init, right?).

A soft reset is done during device power-on init. It's not part of the 
USB reset.

>
>>
>>> Clearing RunStop ensures that the host disconnects from
>>> the device (it was not cleared by CSFTRST, at least on ls1043).
>>>
>>> This allows the dwc3 to properly initialize even if the previous
>>> driver did not shutdown the device (e.g. when using virtualization).
>>
>> This sounds like a workaround to some issue that the function driver did
>> not handle.
>
> I am using the ACM function driver. However, as I said, the issue 
> arises only when the dwc3 driver is in a guest OS that is rebooted 
> (even if the reboot is initiated from within the guest OS, not a hard 
> reset).

Check why it wasn't de-initialized on reboot. Also please describe what 
problem you saw in the patch.

>
> Maybe this is out of scope for Linux, trying to 'clean up' after the 
> previous driver?
>
> Thank you, Roman Kapl
>

BR,
Thinh

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-05  9:51 [PATCH] usb: dwc3: reset the address and run_stop on init Roman Kapl
2019-09-05 18:57 ` Thinh Nguyen
2019-09-09  9:32   ` Roman Kapl
2019-09-09 17:54     ` Thinh Nguyen

Linux-USB Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-usb/0 linux-usb/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-usb linux-usb/ https://lore.kernel.org/linux-usb \
		linux-usb@vger.kernel.org linux-usb@archiver.kernel.org
	public-inbox-index linux-usb


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-usb


AGPL code for this site: git clone https://public-inbox.org/ public-inbox