The header files usb.h and usbdescriptors.h have the same or
similarly named structure definitions for

usb_device_descriptor
usb_string_descriptor
usb_endpoint_descriptor
usb_config_descriptor vs usb_configuration_descriptor
usb_interface_descriptor

There should only be one definition of these structures.
Some of these structures are element-wise duplicates,
one has unused elements that can be reduced to a duplicate,
and some of the the structures have additional elements.

These are the element-wise duplicates in usb.h

usb_device_descriptor
usb_string_descriptor

For these, the usb.h definition will be removed.

This definition in usb.h has extra unused elements

usb_endpoint_descriptor

        unsigned char   bRefresh
        unsigned char   bSynchAddress;

The definition of usb_endpoint_descriptor in usb.h will
be removed.

These definitions in usb.h have extra elements at the end of
the usb 2.0 specified descriptor:

usb_config_descriptor
usb_interface_descriptor

These structures will have their name shorted by removing the
'_descriptor' suffix.

So

usb_config_descriptor -> usb_config
usb_interface_descriptor -> usb_interface

The common descriptor elements are now defined by the macros

USB_CONFIG_DESCRIPTOR_DEFINITION
USB_INTERFACE_DESCRIPTOR_DEFINITION

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

Signed-off-by: Tom Rix <tom....@windriver.com>
---
 common/cmd_usb.c            |   12 ++++----
 common/usb.c                |    8 ++--
 common/usb_kbd.c            |    4 +-
 common/usb_storage.c        |    2 +-
 cpu/ppc4xx/usbdev.c         |    4 +-
 drivers/usb/host/ehci-hcd.c |    2 +-
 drivers/usb/musb/musb_hcd.c |    2 +-
 include/usb.h               |   70 +++++-------------------------------------
 include/usbdescriptors.h    |   40 ++++++++++++++----------
 9 files changed, 49 insertions(+), 95 deletions(-)

diff --git a/common/cmd_usb.c b/common/cmd_usb.c
index 7b8ee6b..6f3b095 100644
--- a/common/cmd_usb.c
+++ b/common/cmd_usb.c
@@ -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_config *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);
@@ -202,7 +202,7 @@ void usb_display_conf_desc(struct usb_config_descriptor 
*config,
        }
 }
 
-void usb_display_if_desc(struct usb_interface_descriptor *ifdesc,
+void usb_display_if_desc(struct usb_interface *ifdesc,
                         struct usb_device *dev)
 {
        printf("     Interface: %d\n", ifdesc->bInterfaceNumber);
@@ -246,8 +246,8 @@ 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;
 
@@ -321,7 +321,7 @@ void usb_show_tree_graph(struct usb_device *dev, char *pre)
        printf(" %s (%s, %dmA)\n", usb_get_class_desc(
                                        dev->config.if_desc[0].bInterfaceClass),
                                        portspeed(dev->speed),
-                                       dev->config.MaxPower * 2);
+                                       dev->config.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);
diff --git a/common/usb.c b/common/usb.c
index 87fca70..6649f8c 100644
--- a/common/usb.c
+++ b/common/usb.c
@@ -440,10 +440,10 @@ int usb_get_configuration_no(struct usb_device *dev,
 {
        int result;
        unsigned int tmp;
-       struct usb_config_descriptor *config;
+       struct usb_config *config;
 
 
-       config = (struct usb_config_descriptor *)&buffer[0];
+       config = (struct usb_config *)&buffer[0];
        result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno, buffer, 9);
        if (result < 9) {
                if (result < 0)
@@ -489,7 +489,7 @@ 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++) {
@@ -1347,7 +1347,7 @@ 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;
 
diff --git a/common/usb_kbd.c b/common/usb_kbd.c
index b458d77..4e584a2 100644
--- a/common/usb_kbd.c
+++ b/common/usb_kbd.c
@@ -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)
@@ -348,7 +348,7 @@ 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;
 
diff --git a/common/usb_storage.c b/common/usb_storage.c
index 19613f2..4afc8ff 100644
--- a/common/usb_storage.c
+++ b/common/usb_storage.c
@@ -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;
 
diff --git a/cpu/ppc4xx/usbdev.c b/cpu/ppc4xx/usbdev.c
index 5bb4f3c..fe398af 100644
--- a/cpu/ppc4xx/usbdev.c
+++ b/cpu/ppc4xx/usbdev.c
@@ -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;
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 324c308..ba85991 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -96,7 +96,7 @@ static struct descriptor {
                                 * UE_DIR_IN | EHCI_INTR_ENDPT
                                 */
                3,              /* bmAttributes: UE_INTERRUPT */
-               8, 0,           /* wMaxPacketSize */
+               8,              /* wMaxPacketSize */
                255             /* bInterval */
        },
 };
diff --git a/drivers/usb/musb/musb_hcd.c b/drivers/usb/musb/musb_hcd.c
index 4ca94cb..555d2dc 100644
--- a/drivers/usb/musb/musb_hcd.c
+++ b/drivers/usb/musb/musb_hcd.c
@@ -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;
diff --git a/include/usb.h b/include/usb.h
index 7c47098..378a23b 100644
--- a/include/usb.h
+++ b/include/usb.h
@@ -27,6 +27,7 @@
 #define _USB_H_
 
 #include <usb_defs.h>
+#include <usbdescriptors.h>
 
 /* Everything is aribtrary */
 #define USB_ALTSETTINGALLOC            4
@@ -41,13 +42,6 @@
 
 #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 {
+       USB_INTERFACE_DESCRIPTOR_DEFINITION;
 
        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 {
+       USB_CONFIG_DESCRIPTOR_DEFINITION;
 
        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 */
diff --git a/include/usbdescriptors.h b/include/usbdescriptors.h
index a752097..ea05672 100644
--- a/include/usbdescriptors.h
+++ b/include/usbdescriptors.h
@@ -201,27 +201,33 @@ struct usb_endpoint_descriptor {
        u8 bInterval;
 } __attribute__ ((packed));
 
+#define USB_INTERFACE_DESCRIPTOR_DEFINITION    \
+       u8 bLength;                             \
+       u8 bDescriptorType;     /* 0x04 */      \
+       u8 bInterfaceNumber;                    \
+       u8 bAlternateSetting;                   \
+       u8 bNumEndpoints;                       \
+       u8 bInterfaceClass;                     \
+       u8 bInterfaceSubClass;                  \
+       u8 bInterfaceProtocol;                  \
+       u8 iInterface
+
 struct usb_interface_descriptor {
-       u8 bLength;
-       u8 bDescriptorType;     /* 0x04 */
-       u8 bInterfaceNumber;
-       u8 bAlternateSetting;
-       u8 bNumEndpoints;
-       u8 bInterfaceClass;
-       u8 bInterfaceSubClass;
-       u8 bInterfaceProtocol;
-       u8 iInterface;
+       USB_INTERFACE_DESCRIPTOR_DEFINITION;
 } __attribute__ ((packed));
 
+#define USB_CONFIG_DESCRIPTOR_DEFINITION \
+       u8 bLength;                             \
+       u8 bDescriptorType;     /* 0x2 */       \
+       u16 wTotalLength;                       \
+       u8 bNumInterfaces;                      \
+       u8 bConfigurationValue;                 \
+       u8 iConfiguration;                      \
+       u8 bmAttributes;                        \
+       u8 bMaxPower
+
 struct usb_configuration_descriptor {
-       u8 bLength;
-       u8 bDescriptorType;     /* 0x2 */
-       u16 wTotalLength;
-       u8 bNumInterfaces;
-       u8 bConfigurationValue;
-       u8 iConfiguration;
-       u8 bmAttributes;
-       u8 bMaxPower;
+       USB_CONFIG_DESCRIPTOR_DEFINITION;
 } __attribute__ ((packed));
 
 struct usb_device_descriptor {
-- 
1.6.0.6

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to