2022-02-18 10:01:34

by Aswath Govindraju

[permalink] [raw]
Subject: [PATCH] usb: dwc3: drd: Add support for extcon drd notifier even with usb role switch config enabled

In AM62x SoC, the USB controller supports USB role switching by using the
extcon drd notifiers. The current implementation does not accommodate this.
If usb role switching is enabled then drd notifiers are not added. If usb
role switching is not enabled then the dr_mode is forced to peripheral
(dwc3_get_dr_mode) and role switching will not be possible(dwc3_set_mode).

Therefore, rearrange the "if else" logic such that extcon drd notifiers can
be added even with usb role switching enabled.

Signed-off-by: Aswath Govindraju <[email protected]>
---
drivers/usb/dwc3/drd.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c
index b919ea3d87f2..0e86b1d8b50c 100644
--- a/drivers/usb/dwc3/drd.c
+++ b/drivers/usb/dwc3/drd.c
@@ -583,12 +583,7 @@ int dwc3_drd_init(struct dwc3 *dwc)
if (IS_ERR(dwc->edev))
return PTR_ERR(dwc->edev);

- if (ROLE_SWITCH &&
- device_property_read_bool(dwc->dev, "usb-role-switch")) {
- ret = dwc3_setup_role_switch(dwc);
- if (ret < 0)
- return ret;
- } else if (dwc->edev) {
+ if (dwc->edev) {
dwc->edev_nb.notifier_call = dwc3_drd_notifier;
ret = extcon_register_notifier(dwc->edev, EXTCON_USB_HOST,
&dwc->edev_nb);
@@ -598,7 +593,14 @@ int dwc3_drd_init(struct dwc3 *dwc)
}

dwc3_drd_update(dwc);
- } else {
+ }
+
+ if (ROLE_SWITCH &&
+ device_property_read_bool(dwc->dev, "usb-role-switch")) {
+ ret = dwc3_setup_role_switch(dwc);
+ if (ret < 0)
+ return ret;
+ } else if (!dwc->edev) {
dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_OTG);

/* use OTG block to get ID event */
--
2.17.1


2022-02-23 05:29:42

by Thinh Nguyen

[permalink] [raw]
Subject: Re: [PATCH] usb: dwc3: drd: Add support for extcon drd notifier even with usb role switch config enabled

Hi,

Aswath Govindraju wrote:
> In AM62x SoC, the USB controller supports USB role switching by using the
> extcon drd notifiers. The current implementation does not accommodate this.
> If usb role switching is enabled then drd notifiers are not added. If usb
> role switching is not enabled then the dr_mode is forced to peripheral
> (dwc3_get_dr_mode) and role switching will not be possible(dwc3_set_mode).
>
> Therefore, rearrange the "if else" logic such that extcon drd notifiers can
> be added even with usb role switching enabled.
>
> Signed-off-by: Aswath Govindraju <[email protected]>
> ---
> drivers/usb/dwc3/drd.c | 16 +++++++++-------
> 1 file changed, 9 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c
> index b919ea3d87f2..0e86b1d8b50c 100644
> --- a/drivers/usb/dwc3/drd.c
> +++ b/drivers/usb/dwc3/drd.c
> @@ -583,12 +583,7 @@ int dwc3_drd_init(struct dwc3 *dwc)
> if (IS_ERR(dwc->edev))
> return PTR_ERR(dwc->edev);
>
> - if (ROLE_SWITCH &&
> - device_property_read_bool(dwc->dev, "usb-role-switch")) {
> - ret = dwc3_setup_role_switch(dwc);
> - if (ret < 0)
> - return ret;
> - } else if (dwc->edev) {
> + if (dwc->edev) {
> dwc->edev_nb.notifier_call = dwc3_drd_notifier;
> ret = extcon_register_notifier(dwc->edev, EXTCON_USB_HOST,
> &dwc->edev_nb);
> @@ -598,7 +593,14 @@ int dwc3_drd_init(struct dwc3 *dwc)
> }
>
> dwc3_drd_update(dwc);
> - } else {
> + }
> +
> + if (ROLE_SWITCH &&
> + device_property_read_bool(dwc->dev, "usb-role-switch")) {
> + ret = dwc3_setup_role_switch(dwc);
> + if (ret < 0)
> + return ret;
> + } else if (!dwc->edev) {
> dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_OTG);
>
> /* use OTG block to get ID event */


Please check the patch by Andrey Smirnov and see if it works for you:
https://lore.kernel.org/linux-usb/[email protected]/

Thanks,
Thinh

2022-02-23 10:03:16

by Aswath Govindraju

[permalink] [raw]
Subject: Re: [PATCH] usb: dwc3: drd: Add support for extcon drd notifier even with usb role switch config enabled

Hi Thinh,

On 23/02/22 6:33 am, Thinh Nguyen wrote:
> Hi,
>
> Aswath Govindraju wrote:
>> In AM62x SoC, the USB controller supports USB role switching by using the
>> extcon drd notifiers. The current implementation does not accommodate this.
>> If usb role switching is enabled then drd notifiers are not added. If usb
>> role switching is not enabled then the dr_mode is forced to peripheral
>> (dwc3_get_dr_mode) and role switching will not be possible(dwc3_set_mode).
>>
>> Therefore, rearrange the "if else" logic such that extcon drd notifiers can
>> be added even with usb role switching enabled.
>>
>> Signed-off-by: Aswath Govindraju <[email protected]>
>> ---
>> drivers/usb/dwc3/drd.c | 16 +++++++++-------
>> 1 file changed, 9 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c
>> index b919ea3d87f2..0e86b1d8b50c 100644
>> --- a/drivers/usb/dwc3/drd.c
>> +++ b/drivers/usb/dwc3/drd.c
>> @@ -583,12 +583,7 @@ int dwc3_drd_init(struct dwc3 *dwc)
>> if (IS_ERR(dwc->edev))
>> return PTR_ERR(dwc->edev);
>>
>> - if (ROLE_SWITCH &&
>> - device_property_read_bool(dwc->dev, "usb-role-switch")) {
>> - ret = dwc3_setup_role_switch(dwc);
>> - if (ret < 0)
>> - return ret;
>> - } else if (dwc->edev) {
>> + if (dwc->edev) {
>> dwc->edev_nb.notifier_call = dwc3_drd_notifier;
>> ret = extcon_register_notifier(dwc->edev, EXTCON_USB_HOST,
>> &dwc->edev_nb);
>> @@ -598,7 +593,14 @@ int dwc3_drd_init(struct dwc3 *dwc)
>> }
>>
>> dwc3_drd_update(dwc);
>> - } else {
>> + }
>> +
>> + if (ROLE_SWITCH &&
>> + device_property_read_bool(dwc->dev, "usb-role-switch")) {
>> + ret = dwc3_setup_role_switch(dwc);
>> + if (ret < 0)
>> + return ret;
>> + } else if (!dwc->edev) {
>> dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_OTG);
>>
>> /* use OTG block to get ID event */
>
>
> Please check the patch by Andrey Smirnov and see if it works for you:
> https://lore.kernel.org/linux-usb/[email protected]/
>

Thank you for pointing me this patch. I does solve my issue.


Regards,
Aswath

> Thanks,
> Thinh
>