usb: gadget: udc: Fix initialization sequence with extcon present
authorKamil Debski <k.debski@samsung.com>
Mon, 9 Jun 2014 12:12:41 +0000 (14:12 +0200)
committerChanho Park <chanho61.park@samsung.com>
Thu, 7 Aug 2014 06:16:10 +0000 (15:16 +0900)
Prior to this patch during initialization the udc would switch off regardless
of the current state of the cable. Then it would be enabled if the cable is
present. After applying this patch the udc would be disabled only if the cable
is not present during initialization.

Change-Id: Icfd7e42f9890798afb92428f4041dcffefaa2a08
Signed-off-by: Kamil Debski <k.debski@samsung.com>
drivers/usb/gadget/udc-core.c

index bdd7336..e7ab8c9 100644 (file)
@@ -376,6 +376,8 @@ static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *dri
        udc->gadget->dev.driver = &driver->driver;
 
        node = udc->gadget->dev.of_node;
+
+       edev = 0;
        /* Check if we have an extcon associated with the UDC driver */
        if (node && of_property_read_bool(node, "extcon")) {
                edev = extcon_get_edev_by_phandle(&udc->gadget->dev, 0);
@@ -402,20 +404,25 @@ static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *dri
        ret = driver->bind(udc->gadget, driver);
        if (ret)
                goto err2;
-       ret = usb_gadget_udc_start(udc->gadget, driver);
-       if (ret) {
-               driver->unbind(udc->gadget);
-               goto err2;
-       }
-
-       usb_gadget_connect(udc->gadget);
 
        if (udc->extcon_usb_dev.edev) {
-               udc->enabled = 1;
+               udc->enabled = 0;
                udc->cable_state = extcon_get_cable_state_(
                                        udc->extcon_usb_dev.edev,
                                        udc->extcon_usb_dev.cable_index);
-               queue_work(udc->pwr_workqueue, &udc->pwr_work);
+       } else {
+               udc->cable_state = 1;
+       }
+
+       if (udc->cable_state) {
+               ret = usb_gadget_udc_start(udc->gadget, driver);
+               if (ret) {
+                       driver->unbind(udc->gadget);
+                       goto err2;
+               }
+
+               usb_gadget_connect(udc->gadget);
+               udc->enabled = 1;
        }
 
        kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE);