Linux-USB Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] USB: dwc2: handle gadget mode disconnect correctly
@ 2020-01-13 18:20 Adrian Carpenter
  2020-01-15  7:45 ` Minas Harutyunyan
  0 siblings, 1 reply; 2+ messages in thread
From: Adrian Carpenter @ 2020-01-13 18:20 UTC (permalink / raw)
  To: linux-usb, hminas

dwc2 usb driver does not handle disconnect in gadget mode correctly,
this results in the gadget still thinking it is connected to a host.

Changing the suspend interrupt handling in gadget mode to reflect the
correct disconnected state fixes this.

Cc: linux-usb@vger.kernel.org <linux-usb@vger.kernel.org>
Cc: Minas Harutyunyan <hminas@synopsys.com>
Signed-off-by: Adrian Carpenter <adrian@fizzyade.com>
---
 drivers/usb/dwc2/core_intr.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff -uprN -X usb-vanilla/Documentation/dontdiff
usb-vanilla/drivers/usb/dwc2/core_intr.c
usb/drivers/usb/dwc2/core_intr.c
--- usb-vanilla/drivers/usb/dwc2/core_intr.c    2020-01-13
13:56:03.988950132 +0000
+++ usb/drivers/usb/dwc2/core_intr.c    2020-01-13 17:29:03.496377075 +0000
@@ -536,13 +536,12 @@ static void dwc2_handle_usb_suspend_intr
                        }
 skip_power_saving:
                        /*
-                        * Change to L2 (suspend) state before releasing
-                        * spinlock
+                        * Suspend seems to be called in then event
+                        * of gadget mode disconnect
                         */
-                       hsotg->lx_state = DWC2_L2;
+                       hsotg->lx_state = DWC2_L3;

-                       /* Call gadget suspend callback */
-                       call_gadget(hsotg, suspend);
+                       usb_gadget_set_state(&hsotg->gadget,
USB_STATE_NOTATTACHED);
                }
        } else {
                if (hsotg->op_state == OTG_STATE_A_PERIPHERAL) {

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

* Re: [PATCH] USB: dwc2: handle gadget mode disconnect correctly
  2020-01-13 18:20 [PATCH] USB: dwc2: handle gadget mode disconnect correctly Adrian Carpenter
@ 2020-01-15  7:45 ` Minas Harutyunyan
  0 siblings, 0 replies; 2+ messages in thread
From: Minas Harutyunyan @ 2020-01-15  7:45 UTC (permalink / raw)
  To: Adrian Carpenter, linux-usb

Hi Adrian,


On 1/13/2020 10:20 PM, Adrian Carpenter wrote:
> dwc2 usb driver does not handle disconnect in gadget mode correctly,
> this results in the gadget still thinking it is connected to a host.
> 
> Changing the suspend interrupt handling in gadget mode to reflect the
> correct disconnected state fixes this.
> 
> Cc: linux-usb@vger.kernel.org <linux-usb@vger.kernel.org>
> Cc: Minas Harutyunyan <hminas@synopsys.com>
> Signed-off-by: Adrian Carpenter <adrian@fizzyade.com>
> ---
>   drivers/usb/dwc2/core_intr.c | 9 ++++-----
>   1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff -uprN -X usb-vanilla/Documentation/dontdiff
> usb-vanilla/drivers/usb/dwc2/core_intr.c
> usb/drivers/usb/dwc2/core_intr.c
> --- usb-vanilla/drivers/usb/dwc2/core_intr.c    2020-01-13
> 13:56:03.988950132 +0000
> +++ usb/drivers/usb/dwc2/core_intr.c    2020-01-13 17:29:03.496377075 +0000
> @@ -536,13 +536,12 @@ static void dwc2_handle_usb_suspend_intr
>                          }
>   skip_power_saving:
>                          /*
> -                        * Change to L2 (suspend) state before releasing
> -                        * spinlock
> +                        * Suspend seems to be called in then event
> +                        * of gadget mode disconnect
>                           */
> -                       hsotg->lx_state = DWC2_L2;
> +                       hsotg->lx_state = DWC2_L3;
> 
> -                       /* Call gadget suspend callback */
> -                       call_gadget(hsotg, suspend);
> +                       usb_gadget_set_state(&hsotg->gadget,
> USB_STATE_NOTATTACHED);
>                  }
>          } else {
>                  if (hsotg->op_state == OTG_STATE_A_PERIPHERAL) {
> 
So, per your patch if host will suspend device then it will treated as 
disconnect and on resume should be re-enumerated again?
Actually, suspend/disconnect flow very dependent on HSOTG core and 
platform architecture, PHY's.

Below chirp from programming guide for HSOTG core on device disconnect flow.

7.3 Device Disconnection
The device session ends when the USB cable is disconnected or if the 
VBUS is switched off by the Host. The device disconnect flow varies 
depending on the value of the OTG_MODE configuration parameter.

When OTG_MODE = 0,1, or 3
When OTG_MODE is set to 0,1, or 3, the device disconnect flow is as follows:
1. When the USB cable is unplugged or when the VBUS is switched off by 
the Host, the Device controller trigger GINTSTS.OTGInt [bit 2] interrupt 
bit.
2. When the device application detects GINTSTS.OTGInt interrupt, it 
checks that the GOTGINT.SesEndDet (Session End Detected) bit is set to 1’b1.

When OTG_MODE =2, or 4
When OTG_MODE is set to 2, or 4, the device disconnect flow is as follows:
1. When the USB cable is unplugged or when the VBUS is switched off by 
the Host, the Device controller triggers GINTSTS.USBRst [bit 12] 
interrupt bit.
2. When the device application detects GINTSTS.USBRst, the application 
sets a time-out check for SET ADDRESS Control Xfer from Host.
3. If application does not receive SET ADDRESS Control Xfer from Host 
before the time-out period, it is treated as a device disconnection.

Thanks,
Minas

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

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-13 18:20 [PATCH] USB: dwc2: handle gadget mode disconnect correctly Adrian Carpenter
2020-01-15  7:45 ` Minas Harutyunyan

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
	public-inbox-index linux-usb

Example config snippet for mirrors

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.git