usb: dwc3: Prioritize extcon over USB role switching API
Subsystems (2)
PATCH 1/1 usb: dwc3: Prioritize extcon over USB role switching API
It is necessary that:
ROLE_SWITCH && device_property_read_bool(dwc->dev, "usb-role-switch")
is true in order for dwc3_get_dr_mode() to _not_ force us from OTG to PERIPHERAL mode here:
if (mode == USB_DR_MODE_OTG &&
(!IS_ENABLED(CONFIG_USB_ROLE_SWITCH) ||
!device_property_read_bool(dwc->dev, "usb-role-switch")) &&
!DWC3_VER_IS_PRIOR(DWC3, 330A))
mode = USB_DR_MODE_PERIPHERAL;and dwc3_drd_init() to be called later in dwc3_core_init_mode(). So, to avoid always ignoring extcon device returned by dwc3_get_extcon() change dwc3_drd_init() to check and use it first, before checking if dwc3_setup_role_switch() should be called.
---
Hopefully I didn't miss something important making this patch unnecessary. Don't know if this is a good solution or not, part of me thinks than maybe changing the aforementioned code in dwc3_get_dr_mode() to account for extcon wopuld be simpler/better. Happy to rework this.
drivers/usb/dwc3/drd.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/usb/dwc3/drd.c +6 -6
@@ -579,12 +579,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);
@@ -594,6 +589,11 @@ 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 {dwc3_set_prtcap (dwc,DWC3_GCTL_PRTCAP_OTG ); dwc->current_dr_role =DWC3_GCTL_PRTCAP_OTG ;
--
2.25.1
Thinh Nguyen
maintainerQuoted 23 lines · Andrey Smirnov
It is necessary that:
ROLE_SWITCH && device_property_read_bool(dwc->dev, "usb-role-switch")is true in order for
dwc3_get_dr_mode()to _not_ force us from OTG to PERIPHERAL mode here:if (mode == USB_DR_MODE_OTG && (!IS_ENABLED(CONFIG_USB_ROLE_SWITCH) || !device_property_read_bool(dwc->dev, "usb-role-switch")) && !DWC3_VER_IS_PRIOR(DWC3, 330A)) mode = USB_DR_MODE_PERIPHERAL;and
dwc3_drd_init()to be called later indwc3_core_init_mode(). So, to avoid always ignoring extcon device returned bydwc3_get_extcon()changedwc3_drd_init()to check and use it first, before checking ifdwc3_setup_role_switch()should be called.Cc Felipe Balbi <[email protected]>Cc Thinh Nguyen <[email protected]>Signed-off-by Andrey Smirnov <[email protected]>
Quoted 7 lines
---
Hopefully I didn't miss something important making this patch unnecessary. Don't know if this is a good solution or not, part of me thinks than maybe changing the aforementioned code in
dwc3_get_dr_mode()to account for extcon wopuld be simpler/better. Happy to rework this.
The driver either use extcon or usb-role-switch. It doesn't make sense to enable usb-role-switch for extcon just so the driver doesn't default the dr_mode to peripheral.
Perhaps, this is what you're looking for? (code is not tested)
drivers/usb/dwc3/core.c +8 -1
@@ -86,7 +86,7 @@ static int dwc3_get_dr_mode(struct dwc3 *dwc)* mode. If the controller supports DRD but the dr_mode is not * specified or set to OTG, then set the mode to peripheral. */ -if (mode ==USB_DR_MODE_OTG && +if (mode ==USB_DR_MODE_OTG && !dwc->edev && (!IS_ENABLED (CONFIG_USB_ROLE_SWITCH ) || !device_property_read_bool (dwc->dev,"usb-role-switch" )) && !DWC3_VER_IS_PRIOR(DWC3, 330A))
@@ -1715,6 +1715,13 @@ static int dwc3_probe(struct platform_device *pdev) goto err2; } + dwc->edev =dwc3_get_extcon (dwc); +if (IS_ERR (dwc->edev)) { + ret =PTR_ERR (dwc->edev); +dev_err (dwc->dev,"failed to get extcon %d\n" , ret); + goto err3; + } + ret =dwc3_get_dr_mode (dwc);if (ret) goto err3;
drivers/usb/dwc3/drd.c +6 -10
@@ -585,16 +585,7 @@ int dwc3_drd_init(struct dwc3 *dwc) {int ret, irq; - dwc->edev =dwc3_get_extcon (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);
@@ -604,6 +595,11 @@ 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 {dwc3_set_prtcap (dwc,DWC3_GCTL_PRTCAP_OTG );
Quoted 33 lines · Thinh Nguyen
Quoted 23 lines · Andrey Smirnov
It is necessary that:
ROLE_SWITCH && device_property_read_bool(dwc->dev, "usb-role-switch")is true in order for
dwc3_get_dr_mode()to _not_ force us from OTG to PERIPHERAL mode here:if (mode == USB_DR_MODE_OTG && (!IS_ENABLED(CONFIG_USB_ROLE_SWITCH) || !device_property_read_bool(dwc->dev, "usb-role-switch")) && !DWC3_VER_IS_PRIOR(DWC3, 330A)) mode = USB_DR_MODE_PERIPHERAL;and
dwc3_drd_init()to be called later indwc3_core_init_mode(). So, to avoid always ignoring extcon device returned bydwc3_get_extcon()changedwc3_drd_init()to check and use it first, before checking ifdwc3_setup_role_switch()should be called.Cc Felipe Balbi <[email protected]>Cc Thinh Nguyen <[email protected]>Signed-off-by Andrey Smirnov <[email protected]>Quoted 7 lines
---
Hopefully I didn't miss something important making this patch unnecessary. Don't know if this is a good solution or not, part of me thinks than maybe changing the aforementioned code in
dwc3_get_dr_mode()to account for extcon wopuld be simpler/better. Happy to rework this.
Quoted 6 lines
The driver either use extcon or usb-role-switch. It doesn't make sense to enable usb-role-switch for extcon just so the driver doesn't default the
dr_modeto peripheral.Perhaps, this is what you're looking for? (code is not tested)
Yeah that kind of what I meant by "maybe changing the aforementioned code in dwc3_get_dr_mode() to account for extcon wopuld be simpler/better." OK let me rework the patch to do that.
Quoted 35 lines
drivers/usb/dwc3/core.c +8
-1@@ -86,7 +86,7 @@ static int dwc3_get_dr_mode(struct dwc3 *dwc)* mode. If the controller supports DRD but the dr_mode is not * specified or set to OTG, then set the mode to peripheral. */ -if (mode ==USB_DR_MODE_OTG && +if (mode ==USB_DR_MODE_OTG && !dwc->edev && (!IS_ENABLED (CONFIG_USB_ROLE_SWITCH ) || !device_property_read_bool (dwc->dev,"usb-role-switch" )) && !DWC3_VER_IS_PRIOR(DWC3, 330A))@@ -1715,6 +1715,13 @@ static int dwc3_probe(struct platform_device *pdev) goto err2; } + dwc->edev =dwc3_get_extcon (dwc); +if (IS_ERR (dwc->edev)) { + ret =PTR_ERR (dwc->edev); +dev_err (dwc->dev,"failed to get extcon %d\n" , ret); + goto err3; + } + ret =dwc3_get_dr_mode (dwc);if (ret) goto err3;drivers/usb/dwc3/drd.c +0
-0@@ -585,16 +585,7 @@ int dwc3_drd_init(struct dwc3 *dwc) {int ret, irq;
drivers/usb/dwc3/drd.c int dwc3_drd_init(struct dwc3 *dwc) · line 597
Quoted 10 lines
drivers/usb/dwc3/drd.c +0
-10- dwc->edev =dwc3_get_extcon (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) {
We probably don't even need to move this around. If "usb-role-switch" isn't going to be set then that "if" could go first and not interfere.
Quoted 17 lines
drivers/usb/dwc3/drd.c +6
-0+if (dwc->edev) { dwc->edev_nb.notifier_call = dwc3_drd_notifier; ret =extcon_register_notifier (dwc->edev,EXTCON_USB_HOST , &dwc->edev_nb);@@ -604,6 +595,11 @@ 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 {dwc3_set_prtcap (dwc,DWC3_GCTL_PRTCAP_OTG );
Thinh Nguyen
maintainerQuoted 80 lines · Andrey Smirnov
Quoted 33 lines · Thinh Nguyen
Quoted 23 lines · Andrey Smirnov
It is necessary that:
ROLE_SWITCH && device_property_read_bool(dwc->dev, "usb-role-switch")is true in order for
dwc3_get_dr_mode()to _not_ force us from OTG to PERIPHERAL mode here:if (mode == USB_DR_MODE_OTG && (!IS_ENABLED(CONFIG_USB_ROLE_SWITCH) || !device_property_read_bool(dwc->dev, "usb-role-switch")) && !DWC3_VER_IS_PRIOR(DWC3, 330A)) mode = USB_DR_MODE_PERIPHERAL;and
dwc3_drd_init()to be called later indwc3_core_init_mode(). So, to avoid always ignoring extcon device returned bydwc3_get_extcon()changedwc3_drd_init()to check and use it first, before checking ifdwc3_setup_role_switch()should be called.Cc Felipe Balbi <[email protected]>Cc Thinh Nguyen <[email protected]>Signed-off-by Andrey Smirnov <[email protected]>Quoted 7 lines
---
Hopefully I didn't miss something important making this patch unnecessary. Don't know if this is a good solution or not, part of me thinks than maybe changing the aforementioned code in
dwc3_get_dr_mode()to account for extcon wopuld be simpler/better. Happy to rework this.Quoted 6 lines
The driver either use extcon or usb-role-switch. It doesn't make sense to enable usb-role-switch for extcon just so the driver doesn't default the
dr_modeto peripheral.Perhaps, this is what you're looking for? (code is not tested)
Yeah that kind of what I meant by "maybe changing the aforementioned code in
dwc3_get_dr_mode()to account for extcon wopuld be simpler/better." OK let me rework the patch to do that.Quoted 35 lines
drivers/usb/dwc3/core.c +8
-1@@ -86,7 +86,7 @@ static int dwc3_get_dr_mode(struct dwc3 *dwc)* mode. If the controller supports DRD but the dr_mode is not * specified or set to OTG, then set the mode to peripheral. */ -if (mode ==USB_DR_MODE_OTG && +if (mode ==USB_DR_MODE_OTG && !dwc->edev && (!IS_ENABLED (CONFIG_USB_ROLE_SWITCH ) || !device_property_read_bool (dwc->dev,"usb-role-switch" )) && !DWC3_VER_IS_PRIOR(DWC3, 330A))@@ -1715,6 +1715,13 @@ static int dwc3_probe(struct platform_device *pdev) goto err2; } + dwc->edev =dwc3_get_extcon (dwc); +if (IS_ERR (dwc->edev)) { + ret =PTR_ERR (dwc->edev); +dev_err (dwc->dev,"failed to get extcon %d\n" , ret); + goto err3; + } + ret =dwc3_get_dr_mode (dwc);if (ret) goto err3;drivers/usb/dwc3/drd.c +0
-0@@ -585,16 +585,7 @@ int dwc3_drd_init(struct dwc3 *dwc) {int ret, irq;
Quoted 14 lines
drivers/usb/dwc3/drd.c int dwc3_drd_init(struct dwc3 *dwc) · line 597
Quoted 10 lines
drivers/usb/dwc3/drd.c +0
-10- dwc->edev =dwc3_get_extcon (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) {We probably don't even need to move this around. If "usb-role-switch" isn't going to be set then that "if" could go first and not interfere.
Yeah, this is unnecessary.
Quoted 7 lines
Quoted 7 lines
drivers/usb/dwc3/drd.c +1
-0+if (dwc->edev) { dwc->edev_nb.notifier_call = dwc3_drd_notifier; ret =extcon_register_notifier (dwc->edev,EXTCON_USB_HOST , &dwc->edev_nb);@@ -604,6 +595,11 @@ int dwc3_drd_init(struct dwc3 *dwc) }
Quoted 10 lines
drivers/usb/dwc3/drd.c int dwc3_drd_init(struct dwc3 *dwc) · line 605
Quoted 10 lines
drivers/usb/dwc3/drd.c +5
-0dwc3_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 {dwc3_set_prtcap (dwc,DWC3_GCTL_PRTCAP_OTG );
Thanks,
Thinh