]> git.sur5r.net Git - u-boot/blobdiff - drivers/usb/host/usb-uclass.c
arm: mx6: usb: kconfig: add USB_EHCI_MX6 kconfig option
[u-boot] / drivers / usb / host / usb-uclass.c
index c5ece584070b123b999e7ca2b03ae05b3a7377d4..6e86f4a24a48ff26e19013ed7746d60212a66705 100644 (file)
@@ -21,6 +21,10 @@ DECLARE_GLOBAL_DATA_PTR;
 extern bool usb_started; /* flag for the started/stopped USB status */
 static bool asynch_allowed;
 
+struct usb_uclass_priv {
+       int companion_device_count;
+};
+
 int usb_disable_asynch(int disable)
 {
        int old_value = asynch_allowed;
@@ -46,11 +50,22 @@ int submit_control_msg(struct usb_device *udev, unsigned long pipe,
 {
        struct udevice *bus = udev->controller_dev;
        struct dm_usb_ops *ops = usb_get_ops(bus);
+       struct usb_uclass_priv *uc_priv = bus->uclass->priv;
+       int err;
 
        if (!ops->control)
                return -ENOSYS;
 
-       return ops->control(bus, udev, pipe, buffer, length, setup);
+       err = ops->control(bus, udev, pipe, buffer, length, setup);
+       if (setup->request == USB_REQ_SET_FEATURE &&
+           setup->requesttype == USB_RT_PORT &&
+           setup->value == cpu_to_le16(USB_PORT_FEAT_RESET) &&
+           err == -ENXIO) {
+               /* Device handed over to companion after port reset */
+               uc_priv->companion_device_count++;
+       }
+
+       return err;
 }
 
 int submit_bulk_msg(struct usb_device *udev, unsigned long pipe, void *buffer,
@@ -65,6 +80,42 @@ int submit_bulk_msg(struct usb_device *udev, unsigned long pipe, void *buffer,
        return ops->bulk(bus, udev, pipe, buffer, length);
 }
 
+struct int_queue *create_int_queue(struct usb_device *udev,
+               unsigned long pipe, int queuesize, int elementsize,
+               void *buffer, int interval)
+{
+       struct udevice *bus = udev->controller_dev;
+       struct dm_usb_ops *ops = usb_get_ops(bus);
+
+       if (!ops->create_int_queue)
+               return NULL;
+
+       return ops->create_int_queue(bus, udev, pipe, queuesize, elementsize,
+                                    buffer, interval);
+}
+
+void *poll_int_queue(struct usb_device *udev, struct int_queue *queue)
+{
+       struct udevice *bus = udev->controller_dev;
+       struct dm_usb_ops *ops = usb_get_ops(bus);
+
+       if (!ops->poll_int_queue)
+               return NULL;
+
+       return ops->poll_int_queue(bus, udev, queue);
+}
+
+int destroy_int_queue(struct usb_device *udev, struct int_queue *queue)
+{
+       struct udevice *bus = udev->controller_dev;
+       struct dm_usb_ops *ops = usb_get_ops(bus);
+
+       if (!ops->destroy_int_queue)
+               return -ENOSYS;
+
+       return ops->destroy_int_queue(bus, udev, queue);
+}
+
 int usb_alloc_device(struct usb_device *udev)
 {
        struct udevice *bus = udev->controller_dev;
@@ -81,12 +132,16 @@ int usb_stop(void)
 {
        struct udevice *bus;
        struct uclass *uc;
+       struct usb_uclass_priv *uc_priv;
        int err = 0, ret;
 
        /* De-activate any devices that have been activated */
        ret = uclass_get(UCLASS_USB, &uc);
        if (ret)
                return ret;
+
+       uc_priv = uc->priv;
+
        uclass_foreach_dev(bus, uc) {
                ret = device_remove(bus);
                if (ret && !err)
@@ -106,12 +161,13 @@ int usb_stop(void)
 #endif
        usb_stor_reset();
        usb_hub_reset();
+       uc_priv->companion_device_count = 0;
        usb_started = 0;
 
        return err;
 }
 
-static int usb_scan_bus(struct udevice *bus, bool recurse)
+static void usb_scan_bus(struct udevice *bus, bool recurse)
 {
        struct usb_bus_priv *priv;
        struct udevice *dev;
@@ -121,16 +177,22 @@ static int usb_scan_bus(struct udevice *bus, bool recurse)
 
        assert(recurse);        /* TODO: Support non-recusive */
 
+       printf("scanning bus %d for devices... ", bus->seq);
+       debug("\n");
        ret = usb_scan_device(bus, 0, USB_SPEED_FULL, &dev);
        if (ret)
-               return ret;
-
-       return priv->next_addr;
+               printf("failed, error %d\n", ret);
+       else if (priv->next_addr == 0)
+               printf("No USB Device found\n");
+       else
+               printf("%d USB Device(s) found\n", priv->next_addr);
 }
 
 int usb_init(void)
 {
        int controllers_initialized = 0;
+       struct usb_uclass_priv *uc_priv;
+       struct usb_bus_priv *priv;
        struct udevice *bus;
        struct uclass *uc;
        int count = 0;
@@ -143,6 +205,8 @@ int usb_init(void)
        if (ret)
                return ret;
 
+       uc_priv = uc->priv;
+
        uclass_foreach_dev(bus, uc) {
                /* init low_level USB */
                printf("USB%d:   ", count);
@@ -158,23 +222,39 @@ int usb_init(void)
                        printf("probe failed, error %d\n", ret);
                        continue;
                }
-               /*
-                * lowlevel init is OK, now scan the bus for devices
-                * i.e. search HUBs and configure them
-                */
                controllers_initialized++;
-               printf("scanning bus %d for devices... ", bus->seq);
-               debug("\n");
-               ret = usb_scan_bus(bus, true);
-               if (ret < 0)
-                       printf("failed, error %d\n", ret);
-               else if (!ret)
-                       printf("No USB Device found\n");
-               else
-                       printf("%d USB Device(s) found\n", ret);
                usb_started = true;
        }
 
+       /*
+        * lowlevel init done, now scan the bus for devices i.e. search HUBs
+        * and configure them, first scan primary controllers.
+        */
+       uclass_foreach_dev(bus, uc) {
+               if (!device_active(bus))
+                       continue;
+
+               priv = dev_get_uclass_priv(bus);
+               if (!priv->companion)
+                       usb_scan_bus(bus, true);
+       }
+
+       /*
+        * Now that the primary controllers have been scanned and have handed
+        * over any devices they do not understand to their companions, scan
+        * the companions if necessary.
+        */
+       if (uc_priv->companion_device_count) {
+               uclass_foreach_dev(bus, uc) {
+                       if (!device_active(bus))
+                               continue;
+
+                       priv = dev_get_uclass_priv(bus);
+                       if (priv->companion)
+                               usb_scan_bus(bus, true);
+               }
+       }
+
        debug("scan end\n");
        /* if we were not able to find at least one working bus, bail out */
        if (!count)
@@ -548,6 +628,49 @@ int usb_scan_device(struct udevice *parent, int port,
        return 0;
 }
 
+/*
+ * Detect if a USB device has been plugged or unplugged.
+ */
+int usb_detect_change(void)
+{
+       struct udevice *hub;
+       struct uclass *uc;
+       int change = 0;
+       int ret;
+
+       ret = uclass_get(UCLASS_USB_HUB, &uc);
+       if (ret)
+               return ret;
+
+       uclass_foreach_dev(hub, uc) {
+               struct usb_device *udev;
+               struct udevice *dev;
+
+               if (!device_active(hub))
+                       continue;
+               for (device_find_first_child(hub, &dev);
+                    dev;
+                    device_find_next_child(&dev)) {
+                       struct usb_port_status status;
+
+                       if (!device_active(dev))
+                               continue;
+
+                       udev = dev_get_parentdata(dev);
+                       if (usb_get_port_status(udev, udev->portnr, &status)
+                                       < 0)
+                               /* USB request failed */
+                               continue;
+
+                       if (le16_to_cpu(status.wPortChange) &
+                           USB_PORT_STAT_C_CONNECTION)
+                               change++;
+               }
+       }
+
+       return change;
+}
+
 int usb_child_post_bind(struct udevice *dev)
 {
        struct usb_dev_platdata *plat = dev_get_parent_platdata(dev);
@@ -630,6 +753,7 @@ UCLASS_DRIVER(usb) = {
        .name           = "usb",
        .flags          = DM_UC_FLAG_SEQ_ALIAS,
        .post_bind      = usb_post_bind,
+       .priv_auto_alloc_size = sizeof(struct usb_uclass_priv),
        .per_child_auto_alloc_size = sizeof(struct usb_device),
        .per_device_auto_alloc_size = sizeof(struct usb_bus_priv),
        .child_post_bind = usb_child_post_bind,