All of lore.kernel.org
 help / color / mirror / Atom feed
* usb: dwc2: Detecting cable disconnection in OTG mode?
@ 2021-12-11  9:55 Pavel Hofman
  2021-12-11  9:59 ` Pavel Hofman
  0 siblings, 1 reply; 5+ messages in thread
From: Pavel Hofman @ 2021-12-11  9:55 UTC (permalink / raw)
  To: Minas Harutyunyan; +Cc: linux-usb

Hi Minas,

I am trying to find if dwc2 in OTG mode can pass information to gadget 
functions that the host has been disconnected. I am testing on RPi4. In 
a datasheet for a different dwc2 implementation 
https://www.mouser.cn/datasheet/2/196/Infineon-xmc4500_rm_v1.6_2016-UM-v01_06-EN-598157.pdf 
- chapter "16.8.3 Device Disconnection" I found:


===========
The device session ends when the USB cable is disconnected or if the 
VBUS is switched off by the host.
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 core triggers GINTSTS.OTGInt [bit 2] interrupt bit
============

I put a printk to core_intr.c:dwc2_handle_otg_intr() which is called 
only from handling the OTGInt interrupt 
https://elixir.bootlin.com/linux/v5.1.9/source/drivers/usb/dwc2/core_intr.c#L803 
. But this method is not called at all when disconnecting the USB cable 
on RPi4 in gadget mode.

The reason I need to identigy the disconnection is my work on signalling 
that host has started/stopped audio playback/capture. Everything more or 
less works, but disconnecting the cable (which means stopped 
playback/capture on the gadget) is not identified in any way.

Thanks a lot,

Pavel.



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

* Re: usb: dwc2: Detecting cable disconnection in OTG mode?
  2021-12-11  9:55 usb: dwc2: Detecting cable disconnection in OTG mode? Pavel Hofman
@ 2021-12-11  9:59 ` Pavel Hofman
  2021-12-12 13:47   ` Pavel Hofman
  0 siblings, 1 reply; 5+ messages in thread
From: Pavel Hofman @ 2021-12-11  9:59 UTC (permalink / raw)
  To: Minas Harutyunyan; +Cc: linux-usb

Dne 11. 12. 21 v 10:55 Pavel Hofman napsal(a):
> Hi Minas,
> 
> I am trying to find if dwc2 in OTG mode can pass information to gadget 
> functions that the host has been disconnected. I am testing on RPi4. In 
> a datasheet for a different dwc2 implementation 
> https://www.mouser.cn/datasheet/2/196/Infineon-xmc4500_rm_v1.6_2016-UM-v01_06-EN-598157.pdf 
> - chapter "16.8.3 Device Disconnection" I found:
> 
> 
> ===========
> The device session ends when the USB cable is disconnected or if the 
> VBUS is switched off by the host.
> 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 core triggers GINTSTS.OTGInt [bit 2] interrupt bit
> ============
> 
> I put a printk to core_intr.c:dwc2_handle_otg_intr() which is called 
> only from handling the OTGInt interrupt 
> https://elixir.bootlin.com/linux/v5.1.9/source/drivers/usb/dwc2/core_intr.c#L803 
> . But this method is not called at all when disconnecting the USB cable 
> on RPi4 in gadget mode.
> 

To add, the method dwc2_hsotg_disconnect is called, but after 
reconnecting the cable, as part of the gadget reset  when handling 
reset interrupts (gintsts & (GINTSTS_USBRST | GINTSTS_RESETDET)) here 
https://elixir.bootlin.com/linux/v5.1.9/source/drivers/usb/dwc2/gadget.c#L3653

Thanks a lot,

Pavel.

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

* Re: usb: dwc2: Detecting cable disconnection in OTG mode?
  2021-12-11  9:59 ` Pavel Hofman
@ 2021-12-12 13:47   ` Pavel Hofman
  2021-12-13 10:58     ` Minas Harutyunyan
  0 siblings, 1 reply; 5+ messages in thread
From: Pavel Hofman @ 2021-12-12 13:47 UTC (permalink / raw)
  To: Minas Harutyunyan; +Cc: linux-usb

Dne 11. 12. 21 v 10:59 Pavel Hofman napsal(a):
> Dne 11. 12. 21 v 10:55 Pavel Hofman napsal(a):
>> Hi Minas,
>>
>> I am trying to find if dwc2 in OTG mode can pass information to gadget 
>> functions that the host has been disconnected. I am testing on RPi4. 
>> In a datasheet for a different dwc2 implementation 
>> https://www.mouser.cn/datasheet/2/196/Infineon-xmc4500_rm_v1.6_2016-UM-v01_06-EN-598157.pdf 
>> - chapter "16.8.3 Device Disconnection" I found:
>>
>>
>> ===========
>> The device session ends when the USB cable is disconnected or if the 
>> VBUS is switched off by the host.
>> 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 core triggers GINTSTS.OTGInt [bit 2] interrupt bit
>> ============
>>
>> I put a printk to core_intr.c:dwc2_handle_otg_intr() which is called 
>> only from handling the OTGInt interrupt 
>> https://elixir.bootlin.com/linux/v5.1.9/source/drivers/usb/dwc2/core_intr.c#L803 
>> . But this method is not called at all when disconnecting the USB 
>> cable on RPi4 in gadget mode.
>>
> 
> To add, the method dwc2_hsotg_disconnect is called, but after 
> reconnecting the cable, as part of the gadget reset  when handling reset 
> interrupts (gintsts & (GINTSTS_USBRST | GINTSTS_RESETDET)) here 
> https://elixir.bootlin.com/linux/v5.1.9/source/drivers/usb/dwc2/gadget.c#L3653 
> 


Maybe the reason for the OTGInt not being thrown at cable disconnect is 
the fact that RPi4 most likely does not handle USB_OTG_ID signal. I 
asked about USB_OTG_ID wiring on RPi4 at their forum.

Nevertheless it turns out that DWC2 throws Suspend interrupt 
GINTSTS_USBSUSP (11) at cable disconnection on the RPi4, and the gadget 
composite driver calls suspend hook of struct usb_function. I wonder if 
implementing the suspend handler would be a solution for other dwc2 
implementations, or if the audio function should implement also some 
other handler in order to correctly serve the cable disconnection for 
all dwc2 implementations.

Thanks a lot,

Pavel.




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

* Re: usb: dwc2: Detecting cable disconnection in OTG mode?
  2021-12-12 13:47   ` Pavel Hofman
@ 2021-12-13 10:58     ` Minas Harutyunyan
  2021-12-13 13:38       ` Pavel Hofman
  0 siblings, 1 reply; 5+ messages in thread
From: Minas Harutyunyan @ 2021-12-13 10:58 UTC (permalink / raw)
  To: Pavel Hofman, Minas Harutyunyan; +Cc: linux-usb

Hi Pavel,

On 12/12/2021 5:47 PM, Pavel Hofman wrote:
> Dne 11. 12. 21 v 10:59 Pavel Hofman napsal(a):
>> Dne 11. 12. 21 v 10:55 Pavel Hofman napsal(a):
>>> Hi Minas,
>>>
>>> I am trying to find if dwc2 in OTG mode can pass information to 
>>> gadget functions that the host has been disconnected. I am testing on 
>>> RPi4. In a datasheet for a different dwc2 implementation 
>>> https://urldefense.com/v3/__https://www.mouser.cn/datasheet/2/196/Infineon-xmc4500_rm_v1.6_2016-UM-v01_06-EN-598157.pdf__;!!A4F2R9G_pg!MEHtWBYLNFmrcqrgWFVPEBTCgO8uc0-Csekg1qk6WkiSEqzoGkWH8OMo9aZtgRJGugkkc6Kq$ 
>>> - chapter "16.8.3 Device Disconnection" I found:
>>>
>>>
>>> ===========
>>> The device session ends when the USB cable is disconnected or if the 
>>> VBUS is switched off by the host.
>>> 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 core triggers GINTSTS.OTGInt [bit 2] 
>>> interrupt bit
>>> ============
>>>
>>> I put a printk to core_intr.c:dwc2_handle_otg_intr() which is called 
>>> only from handling the OTGInt interrupt 
>>> https://urldefense.com/v3/__https://elixir.bootlin.com/linux/v5.1.9/source/drivers/usb/dwc2/core_intr.c*L803__;Iw!!A4F2R9G_pg!MEHtWBYLNFmrcqrgWFVPEBTCgO8uc0-Csekg1qk6WkiSEqzoGkWH8OMo9aZtgRJGumkIC5EA$ 
>>> . But this method is not called at all when disconnecting the USB 
>>> cable on RPi4 in gadget mode.
>>>
>>
>> To add, the method dwc2_hsotg_disconnect is called, but after 
>> reconnecting the cable, as part of the gadget reset  when handling 
>> reset interrupts (gintsts & (GINTSTS_USBRST | GINTSTS_RESETDET)) here 
>> https://urldefense.com/v3/__https://elixir.bootlin.com/linux/v5.1.9/source/drivers/usb/dwc2/gadget.c*L3653__;Iw!!A4F2R9G_pg!MEHtWBYLNFmrcqrgWFVPEBTCgO8uc0-Csekg1qk6WkiSEqzoGkWH8OMo9aZtgRJGugg7wbmK$ 
>>
> 
> 
> Maybe the reason for the OTGInt not being thrown at cable disconnect is 
> the fact that RPi4 most likely does not handle USB_OTG_ID signal. I 
> asked about USB_OTG_ID wiring on RPi4 at their forum.
> 
> Nevertheless it turns out that DWC2 throws Suspend interrupt 
> GINTSTS_USBSUSP (11) at cable disconnection on the RPi4, and the gadget 
> composite driver calls suspend hook of struct usb_function. I wonder if 
> implementing the suspend handler would be a solution for other dwc2 
> implementations, or if the audio function should implement also some 
> other handler in order to correctly serve the cable disconnection for 
> all dwc2 implementations.
> 
> Thanks a lot,
> 
> Pavel.
> 
> 
> 
Disconnect event on different platform behave differently. It's depend 
on platform design, PHY, etc. Yes, GINTSTS_USBSUSP (11) at cable 
disconnection can be used to detect disconnect event.

Thanks,
Minas



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

* Re: usb: dwc2: Detecting cable disconnection in OTG mode?
  2021-12-13 10:58     ` Minas Harutyunyan
@ 2021-12-13 13:38       ` Pavel Hofman
  0 siblings, 0 replies; 5+ messages in thread
From: Pavel Hofman @ 2021-12-13 13:38 UTC (permalink / raw)
  To: Minas Harutyunyan; +Cc: linux-usb


Dne 13. 12. 21 v 11:58 Minas Harutyunyan napsal(a):
> Hi Pavel,
> 
> On 12/12/2021 5:47 PM, Pavel Hofman wrote:
>> Dne 11. 12. 21 v 10:59 Pavel Hofman napsal(a):
>>> Dne 11. 12. 21 v 10:55 Pavel Hofman napsal(a):
>>>> Hi Minas,
>>>>
>>>> I am trying to find if dwc2 in OTG mode can pass information to
>>>> gadget functions that the host has been disconnected. I am testing on
>>>> RPi4. In a datasheet for a different dwc2 implementation
>>>> https://urldefense.com/v3/__https://www.mouser.cn/datasheet/2/196/Infineon-xmc4500_rm_v1.6_2016-UM-v01_06-EN-598157.pdf__;!!A4F2R9G_pg!MEHtWBYLNFmrcqrgWFVPEBTCgO8uc0-Csekg1qk6WkiSEqzoGkWH8OMo9aZtgRJGugkkc6Kq$
>>>> - chapter "16.8.3 Device Disconnection" I found:
>>>>
>>>>
>>>> ===========
>>>> The device session ends when the USB cable is disconnected or if the
>>>> VBUS is switched off by the host.
>>>> 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 core triggers GINTSTS.OTGInt [bit 2]
>>>> interrupt bit
>>>> ============
>>>>
>>>> I put a printk to core_intr.c:dwc2_handle_otg_intr() which is called
>>>> only from handling the OTGInt interrupt
>>>> https://urldefense.com/v3/__https://elixir.bootlin.com/linux/v5.1.9/source/drivers/usb/dwc2/core_intr.c*L803__;Iw!!A4F2R9G_pg!MEHtWBYLNFmrcqrgWFVPEBTCgO8uc0-Csekg1qk6WkiSEqzoGkWH8OMo9aZtgRJGumkIC5EA$
>>>> . But this method is not called at all when disconnecting the USB
>>>> cable on RPi4 in gadget mode.
>>>>
>>>
>>> To add, the method dwc2_hsotg_disconnect is called, but after
>>> reconnecting the cable, as part of the gadget reset  when handling
>>> reset interrupts (gintsts & (GINTSTS_USBRST | GINTSTS_RESETDET)) here
>>> https://urldefense.com/v3/__https://elixir.bootlin.com/linux/v5.1.9/source/drivers/usb/dwc2/gadget.c*L3653__;Iw!!A4F2R9G_pg!MEHtWBYLNFmrcqrgWFVPEBTCgO8uc0-Csekg1qk6WkiSEqzoGkWH8OMo9aZtgRJGugg7wbmK$
>>>
>>
>>
>> Maybe the reason for the OTGInt not being thrown at cable disconnect is
>> the fact that RPi4 most likely does not handle USB_OTG_ID signal. I
>> asked about USB_OTG_ID wiring on RPi4 at their forum.
>>
>> Nevertheless it turns out that DWC2 throws Suspend interrupt
>> GINTSTS_USBSUSP (11) at cable disconnection on the RPi4, and the gadget
>> composite driver calls suspend hook of struct usb_function. I wonder if
>> implementing the suspend handler would be a solution for other dwc2
>> implementations, or if the audio function should implement also some
>> other handler in order to correctly serve the cable disconnection for
>> all dwc2 implementations.
>>
>> Thanks a lot,
>>
>> Pavel.
>>
>>
>>
> Disconnect event on different platform behave differently. It's depend
> on platform design, PHY, etc. Yes, GINTSTS_USBSUSP (11) at cable
> disconnection can be used to detect disconnect event.
> 

Minas, thanks for the confirmation, I will base my notification patch on 
GINTSTS_USBSUSP for the cable disconnect detection.

Best regards,

Pavel.

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

end of thread, other threads:[~2021-12-13 13:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-11  9:55 usb: dwc2: Detecting cable disconnection in OTG mode? Pavel Hofman
2021-12-11  9:59 ` Pavel Hofman
2021-12-12 13:47   ` Pavel Hofman
2021-12-13 10:58     ` Minas Harutyunyan
2021-12-13 13:38       ` Pavel Hofman

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.