]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/usb.c
Add a cli command to test the TPM device.
[karo-tx-uboot.git] / common / usb.c
index 44a435af6e67ed7de122a55e770c3d09f7ec95c5..4418c70f462c9282b2c911a65addf74680ad7059 100644 (file)
 #endif
 
 #ifdef DEBUG
-#define USB_DEBUG
-#define USB_HUB_DEBUG
-#endif
-
-#ifdef USB_DEBUG
-#define        USB_PRINTF(fmt, args...)        printf(fmt , ##args)
+#define USB_DEBUG      1
+#define USB_HUB_DEBUG  1
 #else
-#define USB_PRINTF(fmt, args...)
+#define USB_DEBUG      0
+#define USB_HUB_DEBUG  0
 #endif
 
+#define USB_PRINTF(fmt, args...)       debug_cond(USB_DEBUG, fmt, ##args)
+#define USB_HUB_PRINTF(fmt, args...)   debug_cond(USB_HUB_DEBUG, fmt, ##args)
+
 #define USB_BUFSIZ     512
 
 static struct usb_device usb_dev[USB_MAX_DEVICE];
@@ -145,10 +145,14 @@ int usb_stop(void)
 /*
  * disables the asynch behaviour of the control message. This is used for data
  * transfers that uses the exclusiv access to the control and bulk messages.
+ * Returns the old value so it can be restored later.
  */
-void usb_disable_asynch(int disable)
+int usb_disable_asynch(int disable)
 {
+       int old_value = asynch_allowed;
+
        asynch_allowed = !disable;
+       return old_value;
 }
 
 
@@ -259,18 +263,24 @@ int usb_maxpacket(struct usb_device *dev, unsigned long pipe)
                return dev->epmaxpacketin[((pipe>>15) & 0xf)];
 }
 
-/* The routine usb_set_maxpacket_ep() is extracted from the loop of routine
+/*
+ * The routine usb_set_maxpacket_ep() is extracted from the loop of routine
  * usb_set_maxpacket(), because the optimizer of GCC 4.x chokes on this routine
  * when it is inlined in 1 single routine. What happens is that the register r3
  * is used as loop-count 'i', but gets overwritten later on.
  * This is clearly a compiler bug, but it is easier to workaround it here than
  * to update the compiler (Occurs with at least several GCC 4.{1,2},x
  * CodeSourcery compilers like e.g. 2007q3, 2008q1, 2008q3 lite editions on ARM)
+ *
+ * NOTE: Similar behaviour was observed with GCC4.6 on ARMv5.
  */
 static void  __attribute__((noinline))
-usb_set_maxpacket_ep(struct usb_device *dev, struct usb_endpoint_descriptor *ep)
+usb_set_maxpacket_ep(struct usb_device *dev, int if_idx, int ep_idx)
 {
        int b;
+       struct usb_endpoint_descriptor *ep;
+
+       ep = &dev->config.if_desc[if_idx].ep_desc[ep_idx];
 
        b = ep->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
 
@@ -309,8 +319,7 @@ int usb_set_maxpacket(struct usb_device *dev)
 
        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]);
+                       usb_set_maxpacket_ep(dev, i, ii);
 
        return 0;
 }
@@ -324,7 +333,6 @@ int usb_parse_config(struct usb_device *dev, unsigned char *buffer, int cfgno)
        struct usb_descriptor_header *head;
        int index, ifno, epno, curr_if_num;
        int i;
-       unsigned char *ch;
 
        ifno = -1;
        epno = -1;
@@ -382,7 +390,9 @@ int usb_parse_config(struct usb_device *dev, unsigned char *buffer, int cfgno)
                                   head->bDescriptorType);
 
                        {
-                               ch = (unsigned char *)head;
+#ifdef USB_DEBUG
+                               unsigned char *ch = (unsigned char *)head;
+#endif
                                for (i = 0; i < head->bLength; i++)
                                        USB_PRINTF("%02X ", *ch++);
                                USB_PRINTF("\n\n\n");
@@ -953,8 +963,8 @@ void usb_scan_devices(void)
        /* insert "driver" if possible */
 #ifdef CONFIG_USB_KEYBOARD
        drv_usb_kbd_init();
-       USB_PRINTF("scan end\n");
 #endif
+       USB_PRINTF("scan end\n");
 }
 
 
@@ -963,13 +973,6 @@ void usb_scan_devices(void)
  * Probes device for being a hub and configurate it
  */
 
-#ifdef USB_HUB_DEBUG
-#define        USB_HUB_PRINTF(fmt, args...)    printf(fmt , ##args)
-#else
-#define USB_HUB_PRINTF(fmt, args...)
-#endif
-
-
 static struct usb_hub_device hub_dev[USB_MAX_HUB];
 static int usb_hub_index;
 
@@ -1116,7 +1119,7 @@ void usb_hub_port_connect_change(struct usb_device *dev, int port)
 {
        struct usb_device *usb;
        struct usb_port_status portsts;
-       unsigned short portstatus, portchange;
+       unsigned short portstatus;
 
        /* Check status */
        if (usb_get_port_status(dev, port + 1, &portsts) < 0) {
@@ -1125,9 +1128,10 @@ void usb_hub_port_connect_change(struct usb_device *dev, int port)
        }
 
        portstatus = le16_to_cpu(portsts.wPortStatus);
-       portchange = le16_to_cpu(portsts.wPortChange);
        USB_HUB_PRINTF("portstatus %x, change %x, %s\n",
-                       portstatus, portchange, portspeed(portstatus));
+                       portstatus,
+                       le16_to_cpu(portsts.wPortChange),
+                       portspeed(portstatus));
 
        /* Clear the connection change status */
        usb_clear_port_feature(dev, port + 1, USB_PORT_FEAT_C_CONNECTION);
@@ -1162,6 +1166,7 @@ void usb_hub_port_connect_change(struct usb_device *dev, int port)
 
        dev->children[port] = usb;
        usb->parent = dev;
+       usb->portnr = port + 1;
        /* Run it through the hoops (find a driver, etc) */
        if (usb_new_device(usb)) {
                /* Woops, disable the port */
@@ -1173,11 +1178,13 @@ void usb_hub_port_connect_change(struct usb_device *dev, int port)
 
 int usb_hub_configure(struct usb_device *dev)
 {
+       int i;
        unsigned char buffer[USB_BUFSIZ], *bitmap;
        struct usb_hub_descriptor *descriptor;
-       struct usb_hub_status *hubsts;
-       int i;
        struct usb_hub_device *hub;
+#ifdef USB_HUB_DEBUG
+       struct usb_hub_status *hubsts;
+#endif
 
        /* "allocate" Hub device */
        hub = usb_hub_allocate();
@@ -1279,7 +1286,9 @@ int usb_hub_configure(struct usb_device *dev)
                return -1;
        }
 
+#ifdef USB_HUB_DEBUG
        hubsts = (struct usb_hub_status *)buffer;
+#endif
        USB_HUB_PRINTF("get_hub_status returned status %X, change %X\n",
                        le16_to_cpu(hubsts->wHubStatus),
                        le16_to_cpu(hubsts->wHubChange));