]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
usb: chipidea: vbus event may exist before starting gadget
authorPeter Chen <peter.chen@nxp.com>
Wed, 19 Oct 2016 07:32:58 +0000 (15:32 +0800)
committerPeter Chen <peter.chen@nxp.com>
Fri, 20 Jan 2017 07:24:59 +0000 (15:24 +0800)
At some situations, the vbus may already be there before starting
gadget. So we need to check vbus event after switching to gadget in
order to handle missing vbus event. The typical use cases are plugging
vbus cable before driver load or the vbus has already been there
after stopping host but before starting gadget.

Signed-off-by: Peter Chen <peter.chen@nxp.com>
Tested-by: Stephen Boyd <stephen.boyd@linaro.org>
Reported-by: Stephen Boyd <stephen.boyd@linaro.org>
drivers/usb/chipidea/otg.c

index 695f3fe3ae212d9f095ae58f971ddd833ff1ab5e..10236fe7152286f5556c519d14f0b6c6b207c68a 100644 (file)
@@ -134,9 +134,9 @@ void ci_handle_vbus_change(struct ci_hdrc *ci)
        if (!ci->is_otg)
                return;
 
-       if (hw_read_otgsc(ci, OTGSC_BSV))
+       if (hw_read_otgsc(ci, OTGSC_BSV) && !ci->vbus_active)
                usb_gadget_vbus_connect(&ci->gadget);
-       else
+       else if (!hw_read_otgsc(ci, OTGSC_BSV) && ci->vbus_active)
                usb_gadget_vbus_disconnect(&ci->gadget);
 }
 
@@ -175,14 +175,21 @@ static void ci_handle_id_switch(struct ci_hdrc *ci)
 
                ci_role_stop(ci);
 
-               if (role == CI_ROLE_GADGET)
+               if (role == CI_ROLE_GADGET &&
+                               IS_ERR(ci->platdata->vbus_extcon.edev))
                        /*
-                        * wait vbus lower than OTGSC_BSV before connecting
-                        * to host
+                        * Wait vbus lower than OTGSC_BSV before connecting
+                        * to host. If connecting status is from an external
+                        * connector instead of register, we don't need to
+                        * care vbus on the board, since it will not affect
+                        * external connector status.
                         */
                        hw_wait_vbus_lower_bsv(ci);
 
                ci_role_start(ci, role);
+               /* vbus change may have already occurred */
+               if (role == CI_ROLE_GADGET)
+                       ci_handle_vbus_change(ci);
        }
 }
 /**