usb: chipidea: udc: add a helper ci_udc_enable_vbus_irq()
PATCH v3 1/2 usb: chipidea: udc: add a helper ci_udc_enable_vbus_irq()
The VBUS interrupt is configured in multiple places, add a helper function ci_udc_enable_vbus_irq() to simplify the code.
---
Changes in v2:
- add R-b and A-b tag
Changes in v3:
- no change
--- drivers/usb/chipidea/udc.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-)
drivers/usb/chipidea/udc.c +17 -15
@@ -1835,6 +1835,20 @@ static const struct usb_ep_ops usb_ep_ops = {* GADGET block *****************************************************************************/ +static void ci_udc_enable_vbus_irq (struct ci_hdrc *ci,bool enable) +{ +u32 reg =OTGSC_BSVIS ; + +if (!ci->is_otg) +return ; + +if (enable) + reg |=OTGSC_BSVIE ; + +/* Clear pending BSVIS and enable/disable BSVIE */ +hw_write_otgsc (ci,OTGSC_BSVIE |OTGSC_BSVIS , reg); +} +static int ci_udc_get_frame (struct usb_gadget *_gadget) { struct ci_hdrc *ci = container_of(_gadget, struct ci_hdrc, gadget);
@@ -2352,23 +2366,13 @@ static int udc_id_switch_for_device(struct ci_hdrc *ci)pinctrl_select_state (ci->platdata->pctl, ci->platdata->pins_device); -if (ci->is_otg) -/* Clear and enable BSV irq */ -hw_write_otgsc (ci,OTGSC_BSVIS |OTGSC_BSVIE , -OTGSC_BSVIS |OTGSC_BSVIE ); - +ci_udc_enable_vbus_irq (ci, true);return 0 ; }static void udc_id_switch_for_host (struct ci_hdrc *ci) { -/* -* host doesn't care B_SESSION_VALID event -* so clear and disable BSV irq -*/ -if (ci->is_otg) -hw_write_otgsc (ci,OTGSC_BSVIE |OTGSC_BSVIS ,OTGSC_BSVIS ); - +ci_udc_enable_vbus_irq (ci, false); ci->vbus_active =0 ;if (ci->platdata->pins_device && ci->platdata->pins_default)
@@ -2395,9 +2399,7 @@ static void udc_suspend(struct ci_hdrc *ci)static void udc_resume (struct ci_hdrc *ci,bool power_lost) {if (power_lost) { -if (ci->is_otg) -hw_write_otgsc (ci,OTGSC_BSVIS |OTGSC_BSVIE , -OTGSC_BSVIS |OTGSC_BSVIE ); +ci_udc_enable_vbus_irq (ci, true);if (ci->vbus_active)usb_gadget_vbus_disconnect (&ci->gadget); } else if (ci->vbus_active && ci->driver &&
Signature · 1 line
2.34.1
PATCH v3 2/2 usb: chipidea: udc: support dynamic gadget add/remove
An asynchronous vbus_event_work() keep running when switch the role from device to host. This affects EHCI host controller initialization.
USBCMD.RUNSTOP bit is set at ehci_run() and cleared by following vbus_event_work() if bus_event_work() run after ehci_run().
The log below shows what happens:
[ 87.819925] ci_hdrc ci_hdrc.0: EHCI Host Controller [ 87.819963] ci_hdrc ci_hdrc.0: new USB bus registered, assigned bus number 1 [ 87.955634] ci_hdrc ci_hdrc.0: USB 2.0, controller refused to start: -110 [ 87.955658] ci_hdrc ci_hdrc.0: startup error -110 [ 87.955682] ci_hdrc ci_hdrc.0: USB bus 1 deregistered
The problem is that the chipidea UDC driver call usb_udc_vbus_handler() to pull down data line but it don't wait for completion before host controller starts running.
Now UDC core can properly delete usb gadget device and make sure that vbus work is cancelled or completed after usb_del_gadget_udc() is returned. But the udc.c only call usb_del_gadget_udc() in ci_hdrc_gadget_destroy(). To avoid above issue, add/remove the gadget device dynamically during USB role switching.
To support dynamic gadget add/remove, do below steps:
- clear ci->gadget and ci->ci_hw_ep at initialization.
- assign udc_[start|stop]() to rdrv->[start|stop] and properly merge the operations in udc_id_switch_for_[device|host]() to udc_[start|stop]()
Adjust the order ci_handle_vbus_change() and ci_role_start() to avoid NULL pointer reference since ci_hdrc_gadget_init() doesn't add gadget anymore.
---
Changes in v2:
- add A-b tag
- refine the commit message
Changes in v3:
- no change
--- drivers/usb/chipidea/core.c | 11 +++---- drivers/usb/chipidea/udc.c | 65 +++++++++++++++++++------------------ 2 files changed, 38 insertions(+), 38 deletions(-)
drivers/usb/chipidea/core.c +4 -7
@@ -1191,19 +1191,16 @@ static int ci_hdrc_probe(struct platform_device *pdev) ci->role =ci_get_role (ci);if (!ci_otg_is_fsm_mode (ci)) { -/* only update vbus status for peripheral */ -if (ci->role ==CI_ROLE_GADGET ) { -/* Pull down DP for possible charger detection */ -hw_write (ci,OP_USBCMD ,USBCMD_RS ,0 ); -ci_handle_vbus_change (ci); - } - ret =ci_role_start (ci, ci->role);if (ret) {dev_err (dev,"can't start %s role\n" ,ci_role (ci)->name); goto stop; } + +/* only update vbus status for peripheral */ +if (ci->role ==CI_ROLE_GADGET ) +ci_handle_vbus_change (ci); } ret = devm_request_irq(dev, ci->irq, ci_irq_handler, IRQF_SHARED,
drivers/usb/chipidea/udc.c +34 -31
118 lines not on this page · raw message
Signature · 1 line
2.34.1