USB Consolidate descriptor definitions
authorTom Rix <Tom.Rix@windriver.com>
Sat, 31 Oct 2009 17:37:38 +0000 (12:37 -0500)
committerRemy Bohmer <linux@bohmer.net>
Sun, 20 Dec 2009 11:47:37 +0000 (12:47 +0100)
The header files usb.h and usbdescriptors.h have the same nameed
structure definitions for

usb_config_descriptor
usb_interface_descriptor
usb_endpoint_descriptor
usb_device_descriptor
usb_string_descriptor

These are out right duplicates in usb.h

usb_device_descriptor
usb_string_descriptor

This one has extra unused elements

usb_endpoint_descriptor

unsigned char bRefresh
unsigned char bSynchAddress;

These in usb.h have extra elements at the end of the usb 2.0
specified descriptor and are used.

usb_config_descriptor
usb_interface_descriptor

The change is to consolidate the definition of the descriptors
to usbdescriptors.h.  The dublicates in usb.h are removed.
The extra element structure will have their name shorted by
removing the '_descriptor' suffix.

So

usb_config_descriptor -> usb_config
usb_interface_descriptor -> usb_interface

For these, the common descriptor elements are accessed now
by an element 'desc'.

As an example

- if (iface->bInterfaceClass != USB_CLASS_HUB)
+ if (iface->desc.bInterfaceClass != USB_CLASS_HUB)

This has been compile tested on MAKEALL arm, ppc and mips.

Signed-off-by: Tom Rix <Tom.Rix@windriver.com>
common/cmd_usb.c
common/usb.c
common/usb_kbd.c
common/usb_storage.c
cpu/ppc4xx/usbdev.c
drivers/usb/host/ehci-hcd.c
drivers/usb/musb/musb_hcd.c
include/usb.h

index 7b8ee6b..1e297d5 100644 (file)
@@ -157,7 +157,7 @@ void usb_display_desc(struct usb_device *dev)
 {
        if (dev->descriptor.bDescriptorType == USB_DT_DEVICE) {
                printf("%d: %s,  USB Revision %x.%x\n", dev->devnum,
-               usb_get_class_desc(dev->config.if_desc[0].bInterfaceClass),
+               usb_get_class_desc(dev->config.if_desc[0].desc.bInterfaceClass),
                                   (dev->descriptor.bcdUSB>>8) & 0xff,
                                   dev->descriptor.bcdUSB & 0xff);
 
@@ -174,7 +174,7 @@ void usb_display_desc(struct usb_device *dev)
                } else {
                        printf(" - Class: (from Interface) %s\n",
                               usb_get_class_desc(
-                               dev->config.if_desc[0].bInterfaceClass));
+                               dev->config.if_desc[0].desc.bInterfaceClass));
                }
                printf(" - PacketSize: %d  Configurations: %d\n",
                        dev->descriptor.bMaxPacketSize0,
@@ -187,14 +187,14 @@ void usb_display_desc(struct usb_device *dev)
 
 }
 
-void usb_display_conf_desc(struct usb_config_descriptor *config,
+void usb_display_conf_desc(struct usb_configuration_descriptor *config,
                           struct usb_device *dev)
 {
        printf("   Configuration: %d\n", config->bConfigurationValue);
        printf("   - Interfaces: %d %s%s%dmA\n", config->bNumInterfaces,
               (config->bmAttributes & 0x40) ? "Self Powered " : "Bus Powered ",
               (config->bmAttributes & 0x20) ? "Remote Wakeup " : "",
-               config->MaxPower*2);
+               config->bMaxPower*2);
        if (config->iConfiguration) {
                printf("   - ");
                usb_display_string(dev, config->iConfiguration);
@@ -246,16 +246,16 @@ void usb_display_ep_desc(struct usb_endpoint_descriptor *epdesc)
 /* main routine to diasplay the configs, interfaces and endpoints */
 void usb_display_config(struct usb_device *dev)
 {
-       struct usb_config_descriptor *config;
-       struct usb_interface_descriptor *ifdesc;
+       struct usb_config *config;
+       struct usb_interface *ifdesc;
        struct usb_endpoint_descriptor *epdesc;
        int i, ii;
 
        config = &dev->config;
-       usb_display_conf_desc(config, dev);
+       usb_display_conf_desc(&config->desc, dev);
        for (i = 0; i < config->no_of_if; i++) {
                ifdesc = &config->if_desc[i];
-               usb_display_if_desc(ifdesc, dev);
+               usb_display_if_desc(&ifdesc->desc, dev);
                for (ii = 0; ii < ifdesc->no_of_ep; ii++) {
                        epdesc = &ifdesc->ep_desc[ii];
                        usb_display_ep_desc(epdesc);
@@ -319,9 +319,9 @@ void usb_show_tree_graph(struct usb_device *dev, char *pre)
        pre[index++] = has_child ? '|' : ' ';
        pre[index] = 0;
        printf(" %s (%s, %dmA)\n", usb_get_class_desc(
-                                       dev->config.if_desc[0].bInterfaceClass),
+                                       dev->config.if_desc[0].desc.bInterfaceClass),
                                        portspeed(dev->speed),
-                                       dev->config.MaxPower * 2);
+                                       dev->config.desc.bMaxPower * 2);
        if (strlen(dev->mf) || strlen(dev->prod) || strlen(dev->serial))
                printf(" %s  %s %s %s\n", pre, dev->mf, dev->prod, dev->serial);
        printf(" %s\n", pre);
index 87fca70..eef4b34 100644 (file)
@@ -299,8 +299,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 +330,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 +350,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 +440,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 +488,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 +896,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;
@@ -1347,21 +1346,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.. */
index b458d77..9957dcc 100644 (file)
@@ -229,7 +229,7 @@ int usb_kbd_deregister(void)
 
 static void usb_kbd_setled(struct usb_device *dev)
 {
-       struct usb_interface_descriptor *iface;
+       struct usb_interface *iface;
        iface = &dev->config.if_desc[0];
        leds=0;
        if(scroll_lock!=0)
@@ -242,7 +242,7 @@ static void usb_kbd_setled(struct usb_device *dev)
                leds|=1;
        usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
                USB_REQ_SET_REPORT, USB_TYPE_CLASS | USB_RECIP_INTERFACE,
-               0x200, iface->bInterfaceNumber,(void *)&leds, 1, 0);
+               0x200, iface->desc.bInterfaceNumber, (void *)&leds, 1, 0);
 
 }
 
@@ -348,17 +348,21 @@ static int usb_kbd_irq(struct usb_device *dev)
 /* probes the USB device dev for keyboard type */
 static int usb_kbd_probe(struct usb_device *dev, unsigned int ifnum)
 {
-       struct usb_interface_descriptor *iface;
+       struct usb_interface *iface;
        struct usb_endpoint_descriptor *ep;
        int pipe,maxp;
 
        if (dev->descriptor.bNumConfigurations != 1) return 0;
        iface = &dev->config.if_desc[ifnum];
 
-       if (iface->bInterfaceClass != 3) return 0;
-       if (iface->bInterfaceSubClass != 1) return 0;
-       if (iface->bInterfaceProtocol != 1) return 0;
-       if (iface->bNumEndpoints != 1) return 0;
+       if (iface->desc.bInterfaceClass != 3)
+               return 0;
+       if (iface->desc.bInterfaceSubClass != 1)
+               return 0;
+       if (iface->desc.bInterfaceProtocol != 1)
+               return 0;
+       if (iface->desc.bNumEndpoints != 1)
+               return 0;
 
        ep = &iface->ep_desc[0];
 
@@ -367,9 +371,9 @@ static int usb_kbd_probe(struct usb_device *dev, unsigned int ifnum)
        USB_KBD_PRINTF("USB KBD found set protocol...\n");
        /* ok, we found a USB Keyboard, install it */
        /* usb_kbd_get_hid_desc(dev); */
-       usb_set_protocol(dev, iface->bInterfaceNumber, 0);
+       usb_set_protocol(dev, iface->desc.bInterfaceNumber, 0);
        USB_KBD_PRINTF("USB KBD found set idle...\n");
-       usb_set_idle(dev, iface->bInterfaceNumber, REPEAT_RATE, 0);
+       usb_set_idle(dev, iface->desc.bInterfaceNumber, REPEAT_RATE, 0);
        memset(&new[0], 0, 8);
        memset(&old[0], 0, 8);
        repeat_delay=0;
index 19613f2..391948b 100644 (file)
@@ -1070,7 +1070,7 @@ retry_it:
 int usb_storage_probe(struct usb_device *dev, unsigned int ifnum,
                      struct us_data *ss)
 {
-       struct usb_interface_descriptor *iface;
+       struct usb_interface *iface;
        int i;
        unsigned int flags = 0;
 
@@ -1094,9 +1094,9 @@ int usb_storage_probe(struct usb_device *dev, unsigned int ifnum,
 #endif
 
        if (dev->descriptor.bDeviceClass != 0 ||
-                       iface->bInterfaceClass != USB_CLASS_MASS_STORAGE ||
-                       iface->bInterfaceSubClass < US_SC_MIN ||
-                       iface->bInterfaceSubClass > US_SC_MAX) {
+                       iface->desc.bInterfaceClass != USB_CLASS_MASS_STORAGE ||
+                       iface->desc.bInterfaceSubClass < US_SC_MIN ||
+                       iface->desc.bInterfaceSubClass > US_SC_MAX) {
                /* if it's not a mass storage, we go no further */
                return 0;
        }
@@ -1119,8 +1119,8 @@ int usb_storage_probe(struct usb_device *dev, unsigned int ifnum,
                ss->subclass = subclass;
                ss->protocol = protocol;
        } else {
-               ss->subclass = iface->bInterfaceSubClass;
-               ss->protocol = iface->bInterfaceProtocol;
+               ss->subclass = iface->desc.bInterfaceSubClass;
+               ss->protocol = iface->desc.bInterfaceProtocol;
        }
 
        /* set the handler pointers based on the protocol */
@@ -1153,7 +1153,7 @@ int usb_storage_probe(struct usb_device *dev, unsigned int ifnum,
         * An optional interrupt is OK (necessary for CBI protocol).
         * We will ignore any others.
         */
-       for (i = 0; i < iface->bNumEndpoints; i++) {
+       for (i = 0; i < iface->desc.bNumEndpoints; i++) {
                /* is it an BULK endpoint? */
                if ((iface->ep_desc[i].bmAttributes &
                     USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK) {
@@ -1178,7 +1178,7 @@ int usb_storage_probe(struct usb_device *dev, unsigned int ifnum,
                  ss->ep_in, ss->ep_out, ss->ep_int);
 
        /* Do some basic sanity checks, and bail if we find a problem */
-       if (usb_set_interface(dev, iface->bInterfaceNumber, 0) ||
+       if (usb_set_interface(dev, iface->desc.bInterfaceNumber, 0) ||
            !ss->ep_in || !ss->ep_out ||
            (ss->protocol == US_PR_CBI && ss->ep_int == 0)) {
                USB_STOR_PRINTF("Problems with device\n");
index 5bb4f3c..fe398af 100644 (file)
@@ -21,7 +21,7 @@ void process_endpoints(unsigned short usb2d0_intrin)
 {
        /*will hold the packet received */
        struct usb_device_descriptor usb_device_packet;
-       struct usb_config_descriptor usb_config_packet;
+       struct usb_configuration_descriptor usb_config_packet;
        struct usb_string_descriptor usb_string_packet;
        struct devrequest setup_packet;
        unsigned int *setup_packet_pt;
@@ -99,7 +99,7 @@ void process_endpoints(unsigned short usb2d0_intrin)
                                usb_config_packet.bConfigurationValue = 1;
                                usb_config_packet.iConfiguration = 0;
                                usb_config_packet.bmAttributes = 0x40;
-                               usb_config_packet.MaxPower = 0;
+                               usb_config_packet.bMaxPower = 0;
 
                                /*put packet in fifo */
                                packet_pt = (unsigned char *)&usb_config_packet;
index 324c308..ba85991 100644 (file)
@@ -96,7 +96,7 @@ static struct descriptor {
                                 * UE_DIR_IN | EHCI_INTR_ENDPT
                                 */
                3,              /* bmAttributes: UE_INTERRUPT */
-               8, 0,           /* wMaxPacketSize */
+               8,              /* wMaxPacketSize */
                255             /* bInterval */
        },
 };
index 4ca94cb..555d2dc 100644 (file)
@@ -803,7 +803,7 @@ void usb_event_poll()
 {
        struct stdio_dev *dev;
        struct usb_device *usb_kbd_dev;
-       struct usb_interface_descriptor *iface;
+       struct usb_interface *iface;
        struct usb_endpoint_descriptor *ep;
        int pipe;
        int maxp;
index 7c47098..4148d67 100644 (file)
@@ -27,6 +27,7 @@
 #define _USB_H_
 
 #include <usb_defs.h>
+#include <usbdescriptors.h>
 
 /* Everything is aribtrary */
 #define USB_ALTSETTINGALLOC            4
 
 #define USB_CNTL_TIMEOUT 100 /* 100ms timeout */
 
-/* String descriptor */
-struct usb_string_descriptor {
-       unsigned char   bLength;
-       unsigned char   bDescriptorType;
-       unsigned short  wData[1];
-} __attribute__ ((packed));
-
 /* device request (setup) */
 struct devrequest {
        unsigned char   requesttype;
@@ -63,47 +57,9 @@ struct usb_descriptor_header {
        unsigned char   bDescriptorType;
 } __attribute__ ((packed));
 
-/* Device descriptor */
-struct usb_device_descriptor {
-       unsigned char   bLength;
-       unsigned char   bDescriptorType;
-       unsigned short  bcdUSB;
-       unsigned char   bDeviceClass;
-       unsigned char   bDeviceSubClass;
-       unsigned char   bDeviceProtocol;
-       unsigned char   bMaxPacketSize0;
-       unsigned short  idVendor;
-       unsigned short  idProduct;
-       unsigned short  bcdDevice;
-       unsigned char   iManufacturer;
-       unsigned char   iProduct;
-       unsigned char   iSerialNumber;
-       unsigned char   bNumConfigurations;
-} __attribute__ ((packed));
-
-/* Endpoint descriptor */
-struct usb_endpoint_descriptor {
-       unsigned char   bLength;
-       unsigned char   bDescriptorType;
-       unsigned char   bEndpointAddress;
-       unsigned char   bmAttributes;
-       unsigned short  wMaxPacketSize;
-       unsigned char   bInterval;
-       unsigned char   bRefresh;
-       unsigned char   bSynchAddress;
-} __attribute__ ((packed)) __attribute__ ((aligned(2)));
-
-/* Interface descriptor */
-struct usb_interface_descriptor {
-       unsigned char   bLength;
-       unsigned char   bDescriptorType;
-       unsigned char   bInterfaceNumber;
-       unsigned char   bAlternateSetting;
-       unsigned char   bNumEndpoints;
-       unsigned char   bInterfaceClass;
-       unsigned char   bInterfaceSubClass;
-       unsigned char   bInterfaceProtocol;
-       unsigned char   iInterface;
+/* Interface */
+struct usb_interface {
+       struct usb_interface_descriptor desc;
 
        unsigned char   no_of_ep;
        unsigned char   num_altsetting;
@@ -112,20 +68,12 @@ struct usb_interface_descriptor {
        struct usb_endpoint_descriptor ep_desc[USB_MAXENDPOINTS];
 } __attribute__ ((packed));
 
-
-/* Configuration descriptor information.. */
-struct usb_config_descriptor {
-       unsigned char   bLength;
-       unsigned char   bDescriptorType;
-       unsigned short  wTotalLength;
-       unsigned char   bNumInterfaces;
-       unsigned char   bConfigurationValue;
-       unsigned char   iConfiguration;
-       unsigned char   bmAttributes;
-       unsigned char   MaxPower;
+/* Configuration information.. */
+struct usb_config {
+       struct usb_configuration_descriptor desc;
 
        unsigned char   no_of_if;       /* number of interfaces */
-       struct usb_interface_descriptor if_desc[USB_MAXINTERFACES];
+       struct usb_interface if_desc[USB_MAXINTERFACES];
 } __attribute__ ((packed));
 
 enum {
@@ -156,7 +104,7 @@ struct usb_device {
 
        int configno;                   /* selected config number */
        struct usb_device_descriptor descriptor; /* Device Descriptor */
-       struct usb_config_descriptor config; /* config descriptor */
+       struct usb_config config; /* config descriptor */
 
        int have_langid;                /* whether string_langid is valid yet */
        int string_langid;              /* language ID for strings */