]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/usb.c
AT91: reset.c: fix comments, add option
[karo-tx-uboot.git] / common / usb.c
index 5f468315285cbd381fc1bb08f115de1ce36a612c..10e23de6a410b3c5c05692723393896fdd93b340 100644 (file)
@@ -197,16 +197,21 @@ int usb_control_msg(struct usb_device *dev, unsigned int pipe,
        if (timeout == 0)
                return (int)size;
 
-       if (dev->status != 0) {
-               /*
-                * Let's wait a while for the timeout to elapse.
-                * It has no real use, but it keeps the interface happy.
-                */
-               wait_ms(timeout);
-               return -1;
+       /*
+        * Wait for status to update until timeout expires, USB driver
+        * interrupt handler may set the status when the USB operation has
+        * been completed.
+        */
+       while (timeout--) {
+               if (!((volatile unsigned long)dev->status & USB_ST_NOT_PROC))
+                       break;
+               wait_ms(1);
        }
+       if (dev->status)
+               return -1;
 
        return dev->act_len;
+
 }
 
 /*-------------------------------------------------------------------
@@ -299,8 +304,8 @@ int usb_set_maxpacket(struct usb_device *dev)
 {
        int i, ii;
 
-       for (i = 0; i < dev->config.bNumInterfaces; i++)
-               for (ii = 0; ii < dev->config.if_desc[i].bNumEndpoints; ii++)
+       for (i = 0; i < dev->config.desc.bNumInterfaces; i++)
+               for (ii = 0; ii < dev->config.if_desc[i].desc.bNumEndpoints; ii++)
                        usb_set_maxpacket_ep(dev,
                                          &dev->config.if_desc[i].ep_desc[ii]);
 
@@ -330,14 +335,14 @@ int usb_parse_config(struct usb_device *dev, unsigned char *buffer, int cfgno)
                return -1;
        }
        memcpy(&dev->config, buffer, buffer[0]);
-       le16_to_cpus(&(dev->config.wTotalLength));
+       le16_to_cpus(&(dev->config.desc.wTotalLength));
        dev->config.no_of_if = 0;
 
-       index = dev->config.bLength;
+       index = dev->config.desc.bLength;
        /* Ok the first entry must be a configuration entry,
         * now process the others */
        head = (struct usb_descriptor_header *) &buffer[index];
-       while (index + 1 < dev->config.wTotalLength) {
+       while (index + 1 < dev->config.desc.wTotalLength) {
                switch (head->bDescriptorType) {
                case USB_DT_INTERFACE:
                        if (((struct usb_interface_descriptor *) \
@@ -350,7 +355,7 @@ int usb_parse_config(struct usb_device *dev, unsigned char *buffer, int cfgno)
                                dev->config.if_desc[ifno].no_of_ep = 0;
                                dev->config.if_desc[ifno].num_altsetting = 1;
                                curr_if_num =
-                                    dev->config.if_desc[ifno].bInterfaceNumber;
+                                    dev->config.if_desc[ifno].desc.bInterfaceNumber;
                        } else {
                                /* found alternate setting for the interface */
                                dev->config.if_desc[ifno].num_altsetting++;
@@ -440,10 +445,9 @@ int usb_get_configuration_no(struct usb_device *dev,
 {
        int result;
        unsigned int tmp;
-       struct usb_config_descriptor *config;
+       struct usb_configuration_descriptor *config;
 
-
-       config = (struct usb_config_descriptor *)&buffer[0];
+       config = (struct usb_configuration_descriptor *)&buffer[0];
        result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno, buffer, 9);
        if (result < 9) {
                if (result < 0)
@@ -489,11 +493,11 @@ int usb_set_address(struct usb_device *dev)
  */
 int usb_set_interface(struct usb_device *dev, int interface, int alternate)
 {
-       struct usb_interface_descriptor *if_face = NULL;
+       struct usb_interface *if_face = NULL;
        int ret, i;
 
-       for (i = 0; i < dev->config.bNumInterfaces; i++) {
-               if (dev->config.if_desc[i].bInterfaceNumber == interface) {
+       for (i = 0; i < dev->config.desc.bNumInterfaces; i++) {
+               if (dev->config.if_desc[i].desc.bInterfaceNumber == interface) {
                        if_face = &dev->config.if_desc[i];
                        break;
                }
@@ -897,7 +901,7 @@ int usb_new_device(struct usb_device *dev)
        usb_parse_config(dev, &tmpbuf[0], 0);
        usb_set_maxpacket(dev);
        /* we set the default configuration here */
-       if (usb_set_configuration(dev, dev->config.bConfigurationValue)) {
+       if (usb_set_configuration(dev, dev->config.desc.bConfigurationValue)) {
                printf("failed to set default configuration " \
                        "len %d, status %lX\n", dev->act_len, dev->status);
                return -1;
@@ -939,8 +943,10 @@ void usb_scan_devices(void)
        dev_index = 0;
        /* device 0 is always present (root hub, so let it analyze) */
        dev = usb_alloc_new_device();
-       usb_new_device(dev);
-       printf("%d USB Device(s) found\n", dev_index);
+       if (usb_new_device(dev))
+               printf("No USB Device found\n");
+       else
+               printf("%d USB Device(s) found\n", dev_index);
        /* insert "driver" if possible */
 #ifdef CONFIG_USB_KEYBOARD
        drv_usb_kbd_init();
@@ -1345,21 +1351,21 @@ int usb_hub_configure(struct usb_device *dev)
 
 int usb_hub_probe(struct usb_device *dev, int ifnum)
 {
-       struct usb_interface_descriptor *iface;
+       struct usb_interface *iface;
        struct usb_endpoint_descriptor *ep;
        int ret;
 
        iface = &dev->config.if_desc[ifnum];
        /* Is it a hub? */
-       if (iface->bInterfaceClass != USB_CLASS_HUB)
+       if (iface->desc.bInterfaceClass != USB_CLASS_HUB)
                return 0;
        /* Some hubs have a subclass of 1, which AFAICT according to the */
        /*  specs is not defined, but it works */
-       if ((iface->bInterfaceSubClass != 0) &&
-           (iface->bInterfaceSubClass != 1))
+       if ((iface->desc.bInterfaceSubClass != 0) &&
+           (iface->desc.bInterfaceSubClass != 1))
                return 0;
        /* Multiple endpoints? What kind of mutant ninja-hub is this? */
-       if (iface->bNumEndpoints != 1)
+       if (iface->desc.bNumEndpoints != 1)
                return 0;
        ep = &iface->ep_desc[0];
        /* Output endpoint? Curiousier and curiousier.. */