Re: [PATCH] USB: dwc2: handle gadget mode disconnect correctly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxx <linux-usb@xxxxxxxxxxxxxxx>
> Cc: Minas Harutyunyan <hminas@xxxxxxxxxxxx>
> Signed-off-by: Adrian Carpenter <adrian@xxxxxxxxxxxx>
> ---
>   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




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux