usb: chipidea: use of extcon framework to work for non OTG case
Subsystems (4)
PATCH 1/2 usb: chipidea: use of extcon framework to work for non OTG case
From: Stefan Agner <[email protected]>
The existing usage of extcon in chipidea driver freezes the kernel presumably due to OTGSC register access.
Prevent accessing any OTG registers for SoC with dual role devices but no true OTG support. Use the flag CI_HDRC_DUAL_ROLE_NOT_OTG for those devices and in case extcon is present, do the role switch using extcon only.
---
drivers/usb/chipidea/ci.h | 2 + drivers/usb/chipidea/core.c | 87 +++++++++++++++++++++++++++++++++---- 2 files changed, 80 insertions(+), 9 deletions(-)
drivers/usb/chipidea/ci.h +2 -0
@@ -170,6 +170,7 @@ struct hw_bank {* @enabled_otg_timer_bits: bits of enabled otg timers * @next_otg_timer: next nearest enabled timer to be expired * @work: work for role changing +* @work_dr: work for role changing for non-OTG controllers * @wq: workqueue thread * @qh_pool: allocation pool for queue heads * @td_pool: allocation pool for transfer descriptors
@@ -220,6 +221,7 @@ struct ci_hdrc {enum otg_fsm_timer next_otg_timer;struct usb_role_switch *role_switch;struct work_struct work; +struct work_struct work_dr;struct workqueue_struct *wq;struct dma_pool *qh_pool;
drivers/usb/chipidea/core.c +78 -9
125 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 2/2 ARM: dts: colibri-imx6ull: add extcon for usbotg1
From: Igor Opaniuk <[email protected]>
Add extcon usb gpio configuration for support dual roles for usbotg1.
USB host/gadget switching test (1. USB NIC emulation; 2. USB storage):
[ 52.491957] ci_hdrc ci_hdrc.1: switching to gadget role [ 52.502911] mxs_phy 20c9000.usbphy: vbus is not valid [ 56.749160] using random self ethernet address [ 56.758637] using random host ethernet address [ 65.768968] usb0: HOST MAC 00:14:2d:ff:ff:fe [ 65.887980] usb0: MAC 00:14:2d:ff:ff:ff [ 66.294961] configfs-gadget gadget: high-speed config #1: c [ 78.741971] ci_hdrc ci_hdrc.1: switching to host role [ 78.747522] ci_hdrc ci_hdrc.1: EHCI Host Controller [ 78.790174] ci_hdrc ci_hdrc.1: new USB bus registered, assigned bus number 2 [ 78.868498] ci_hdrc ci_hdrc.1: USB 2.0 started, EHCI 1.00
---
arch/arm/boot/dts/imx6ull-colibri-eval-v3.dtsi | 9 +++++++++ 1 file changed, 9 insertions(+)
arch/arm/boot/dts/imx6ull-colibri-eval-v3.dtsi +9 -0
@@ -29,6 +29,14 @@ clock-frequency = <16000000>; }; + extcon_usbc_det: usbc_det { + compatible = "linux,extcon-usb-gpio"; + debounce = <25>; + id-gpio = <&gpio5 2 GPIO_ACTIVE_HIGH>; + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_snvs_usbc_det>; + }; + panel: panel { compatible = "edt,et057090dhu"; backlight = <&bl>;
@@ -150,6 +158,7 @@ }; &usbotg1 { + extcon = <&extcon_usbc_det &extcon_usbc_det>; status = "okay"; };
Signature · 7 lines
2.17.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v1 2/2] ARM: dts: colibri-imx6ull: add extcon for usbotg1
Quoted 30 lines · Igor Opaniuk
From: Igor Opaniuk <[email protected]>
Add extcon usb gpio configuration for support dual roles for usbotg1.
USB host/gadget switching test (1. USB NIC emulation; 2. USB storage):
[ 52.491957] ci_hdrc ci_hdrc.1: switching to gadget role [ 52.502911] mxs_phy 20c9000.usbphy: vbus is not valid [ 56.749160] using random self ethernet address [ 56.758637] using random host ethernet address [ 65.768968] usb0: HOST MAC 00:14:2d:ff:ff:fe [ 65.887980] usb0: MAC 00:14:2d:ff:ff:ff [ 66.294961] configfs-gadget gadget: high-speed config #1: c [ 78.741971] ci_hdrc ci_hdrc.1: switching to host role [ 78.747522] ci_hdrc ci_hdrc.1: EHCI Host Controller [ 78.790174] ci_hdrc ci_hdrc.1: new USB bus registered, assigned bus number 2 [ 78.868498] ci_hdrc ci_hdrc.1: USB 2.0 started, EHCI 1.00Signed-off-by Igor Opaniuk <[email protected]>---
arch/arm/boot/dts/imx6ull-colibri-eval-v3.dtsi | 9 +++++++++ 1 file changed, 9 insertions(+)arch/arm/boot/dts/imx6ull-colibri-eval-v3.dtsi +0
-0
arch/arm/boot/dts/imx6ull-colibri-eval-v3.dtsi line 32
Quoted 4 lines
arch/arm/boot/dts/imx6ull-colibri-eval-v3.dtsi +1
-0@@ -29,6 +29,14 @@ clock-frequency = <16000000>; }; + extcon_usbc_det: usbc_det {
Can we find a more generic name for the node? Also hyphen is preferred over underscore in node name.
Shawn
Quoted 21 lines
arch/arm/boot/dts/imx6ull-colibri-eval-v3.dtsi +8
-0+ compatible = "linux,extcon-usb-gpio"; + debounce = <25>; + id-gpio = <&gpio5 2 GPIO_ACTIVE_HIGH>; + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_snvs_usbc_det>; + }; + panel: panel { compatible = "edt,et057090dhu"; backlight = <&bl>;@@ -150,6 +158,7 @@ }; &usbotg1 { + extcon = <&extcon_usbc_det &extcon_usbc_det>; status = "okay"; };Signature · 1 line
2.17.1
Quoted 9 lines · Igor Opaniuk
From: Stefan Agner <[email protected]>
The existing usage of extcon in chipidea driver freezes the kernel presumably due to OTGSC register access.
Prevent accessing any OTG registers for SoC with dual role devices but no true OTG support. Use the flag
CI_HDRC_DUAL_ROLE_NOT_OTGfor those devices and in case extcon is present, do the role switch using extcon only.
Hi Igor & Stefan,
I have several questions about the problem you met:
- Which vendor's controller you have used?
- What do you mean "no true OTG"? Does it mean no "OTGSC" register?
drivers/usb/chipidea/core.c static int ci_hdrc_probe(struct platform_device *pdev) · line 1212
Quoted 10 lines
drivers/usb/chipidea/core.c +2
-2if (dr_mode ==USB_DR_MODE_OTG || dr_mode ==USB_DR_MODE_HOST ) { ret =ci_hdrc_host_init (ci);@@ -1145,8 +1208,18 @@ static int ci_hdrc_probe(struct platform_device *pdev)if (!ci_otg_is_fsm_mode (ci)) {/* only update vbus status for peripheral */ -if (ci->role ==CI_ROLE_GADGET ) -ci_handle_vbus_change (ci); +if (dr_mode ==USB_DR_MODE_PERIPHERAL ) { +usb_gadget_vbus_connect (&ci->gadget);
We only use ci->role at runtime, since it has already considered the dts setting, kernel configuration and hardware setting.
If your controller doesn't otgsc register, but do need to support role switch, you may enhance the function ci_get_role
Peter
Quoted 27 lines
drivers/usb/chipidea/core.c +10
-4+ }else if (ci->role ==CI_ROLE_GADGET ) { +struct ci_hdrc_cable *vbus = &ci->platdata->vbus_extcon; + +/* Use vbus state from extcon if provided */ +if (!IS_ERR (vbus->edev) && +extcon_get_state (vbus->edev,EXTCON_USB )) +usb_gadget_vbus_connect (&ci->gadget); +else +ci_handle_vbus_change (ci); + } ret =ci_role_start (ci, ci->role);if (ret) {@@ -1161,10 +1234,6 @@ static int ci_hdrc_probe(struct platform_device *pdev)if (ret) goto stop; - ret =ci_extcon_register (ci); -if (ret) - goto stop; -if (ci->supports_runtime_pm) {pm_runtime_set_active (&pdev->dev);pm_runtime_enable (&pdev->dev);Signature · 1 line
2.17.1
Signature · 2 lines
Thanks, Peter Chen
Hi Peter,
Quoted 12 lines · Peter Chen
Quoted 9 lines · Igor Opaniuk
From: Stefan Agner <[email protected]>
The existing usage of extcon in chipidea driver freezes the kernel presumably due to OTGSC register access.
Prevent accessing any OTG registers for SoC with dual role devices but no true OTG support. Use the flag
CI_HDRC_DUAL_ROLE_NOT_OTGfor those devices and in case extcon is present, do the role switch using extcon only.
Quoted 5 lines
Hi Igor & Stefan,
I have several questions about the problem you met:
- Which vendor's controller you have used?
- What do you mean "no true OTG"? Does it mean no "OTGSC" register?
Probably the commit message adds a bit of confusion here (I've kept the original one from the patch in our downstream kernel, but will probably reword it).
The actual problem is that USB_OTG1_ID pin isn't wired, so we can't rely on the value of ID pin state in OTGSC for the role detection. In our SoM (Colibri iMX6ULL) ID pin from USB connector is wired to SNVS_TAMPER2 which is pinmuxed as GPIO pin (GPIO5_02),
[1] (this is schematic for the Carrier Board, not SoM (isn't publicly available),
but there is a pretty good explanation + schematic
in the section "2.3.2.2 USB 2.0 OTG Schematic Example ").
Quoted 15 lines
drivers/usb/chipidea/core.c static int ci_hdrc_probe(struct platform_device *pdev) · line 1212
Quoted 11 lines
if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_HOST) { ret = ci_hdrc_host_init(ci);drivers/usb/chipidea/core.c +2
-2@@ -1145,8 +1208,18 @@ static int ci_hdrc_probe(struct platform_device *pdev)if (!ci_otg_is_fsm_mode (ci)) {/* only update vbus status for peripheral */ -if (ci->role ==CI_ROLE_GADGET ) -ci_handle_vbus_change (ci); +if (dr_mode ==USB_DR_MODE_PERIPHERAL ) { +usb_gadget_vbus_connect (&ci->gadget);We only use
ci->roleat runtime, since it has already considered the dts setting, kernel configuration and hardware setting.
Quoted 2 lines
If your controller doesn't otgsc register, but do need to support role switch, you may enhance the function
ci_get_role
Btw, ci_get_role() implementation still resides in the NXP dowstream kernel and I've never seen anything posted to the ML (if it was, could you please point me to
the patch?). I can introduce the new one, which wraps both OTGSC handling
+ extcon for CI_HDRC_DUAL_ROLE_NOT_OTG controllers.
Frankly speaking, I don't know the reason why additional workqueue (ci->work_dr) was introduced (will try to reach Stefan regarding this).
As I see it's valid to call extcon_get_state() from the atomic context, so probably
using something like ci_get_role()(or ci_detect_role(), whatever) instead of explicitly
retrieving bits from OTGSC in every ID pin check is a good choice.
Thanks for your feedback!
Quoted 33 lines
Peter
Quoted 25 lines
drivers/usb/chipidea/core.c +10
-5+ }else if (ci->role ==CI_ROLE_GADGET ) { +struct ci_hdrc_cable *vbus = &ci->platdata->vbus_extcon; + +/* Use vbus state from extcon if provided */ +if (!IS_ERR (vbus->edev) && +extcon_get_state (vbus->edev,EXTCON_USB )) +usb_gadget_vbus_connect (&ci->gadget); +else +ci_handle_vbus_change (ci); + } ret =ci_role_start (ci, ci->role);if (ret) {@@ -1161,10 +1234,6 @@ static int ci_hdrc_probe(struct platform_device *pdev)if (ret) goto stop; - ret =ci_extcon_register (ci); -if (ret) - goto stop; -if (ci->supports_runtime_pm) {pm_runtime_set_active (&pdev->dev);pm_runtime_enable (&pdev->dev); --Quoted 2 lines
2.17.1
--
Quoted 2 lines
Thanks,
Peter Chen
[1] https://docs.toradex.com/102491-colibri-arm-carrier-board-design-guide.pdf
Signature · 8 lines
Best regards - Freundliche Grüsse - Meilleures salutations Igor Opaniuk mailto: [email protected] skype: igor.opanyuk +380 (93) 836 40 67 http://ua.linkedin.com/in/iopaniuk
Quoted 25 lines · Igor Opaniuk
Hi Peter,
Quoted 12 lines · Peter Chen
Quoted 9 lines · Igor Opaniuk
From: Stefan Agner <[email protected]>
The existing usage of extcon in chipidea driver freezes the kernel presumably due to OTGSC register access.
Prevent accessing any OTG registers for SoC with dual role devices but no true OTG support. Use the flag
CI_HDRC_DUAL_ROLE_NOT_OTGfor those devices and in case extcon is present, do the role switch using extcon only.Quoted 5 lines
Hi Igor & Stefan,
I have several questions about the problem you met:
- Which vendor's controller you have used?
- What do you mean "no true OTG"? Does it mean no "OTGSC" register?Probably the commit message adds a bit of confusion here (I've kept the original one from the patch in our downstream kernel, but will probably reword it).
Quoted 8 lines
The actual problem is that
USB_OTG1_IDpin isn't wired, so we can't rely on the value of ID pin state in OTGSC for the role detection. In our SoM (Colibri iMX6ULL) ID pin from USB connector is wired toSNVS_TAMPER2which is pinmuxed as GPIO pin (GPIO5_02),
[1] (this is schematic for the Carrier Board, not SoM (isn't publicly available),
but there is a pretty good explanation + schematic
in the section "2.3.2.2 USB 2.0 OTG Schematic Example ").
Ok, I clear now. Then, you may not use CI_HDRC_DUAL_ROLE_NOT_OTG which is for the controller without OTGSC. For imx6ull, access OTGSC will not hang the system if USB is NOT at suspend mode.
Current upstream design has already considered the user case for switch role through GPIO, but there is an issue that the external cable wakeup doesn't work, I will submit it later (see ci_extcon_wakeup_int implementation at downstream kernel).
You could try to disable runtime-pm to see if the behaviour is expected or not, if it is NOT expected, please report what's that?
Quoted 16 lines
Quoted 16 lines
drivers/usb/chipidea/core.c static int ci_hdrc_probe(struct platform_device *pdev) · line 1212
Quoted 12 lines
if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_HOST) { ret = ci_hdrc_host_init(ci);drivers/usb/chipidea/core.c +2
-2@@ -1145,8 +1208,18 @@ static int ci_hdrc_probe(struct platform_device *pdev)if (!ci_otg_is_fsm_mode (ci)) {/* only update vbus status for peripheral */ -if (ci->role ==CI_ROLE_GADGET ) -ci_handle_vbus_change (ci); +if (dr_mode ==USB_DR_MODE_PERIPHERAL ) { +usb_gadget_vbus_connect (&ci->gadget);We only use
ci->roleat runtime, since it has already considered the dts setting, kernel configuration and hardware setting.
Quoted 8 lines
Quoted 2 lines
If your controller doesn't otgsc register, but do need to support role switch, you may enhance the function
ci_get_roleBtw,
ci_get_role()implementation still resides in the NXP dowstream kernel and I've never seen anything posted to the ML (if it was, could you please point me to
the patch?). I can introduce the new one, which wraps both OTGSC handling
+ extcon forCI_HDRC_DUAL_ROLE_NOT_OTGcontrollers.
Sorry about that, I just read code for the upstream kernel with some downstream patches on it.
Quoted 9 lines
Frankly speaking, I don't know the reason why additional workqueue (
ci->work_dr) was introduced (will try to reach Stefan regarding this).
As I see it's valid to callextcon_get_state()from the atomic context, so probably
using something like ci_get_role()(orci_detect_role(), whatever) instead of explicitly
retrieving bits from OTGSC in every ID pin check is a good choice.
There are VBUS and ID events handling which are not non-atomic.
Signature · 2 lines
Thanks, Peter Chen