reformatted, added diagnostics, removed unneeded defines

This commit is contained in:
Markus Fröschle
2013-11-03 18:18:34 +00:00
parent 3b2ab0a284
commit a8a989191c

View File

@@ -56,7 +56,7 @@
extern int usb_stor_curr_dev;
extern uint32_t usb_1st_disk_drive;
#undef USB_DEBUG
#define USB_DEBUG
#ifdef USB_DEBUG
#define USB_PRINTF(fmt, args...) xprintf(fmt , ##args)
@@ -115,20 +115,20 @@ int usb_init(long handle, const struct pci_device_id *ent)
{
void *priv;
int res = 0;
if(bus_index >= USB_MAX_BUS)
if (bus_index >= USB_MAX_BUS)
return(-1);
dev_index[bus_index] = 0;
asynch_allowed = 1;
if(handle && (ent != NULL))
if (handle && (ent != NULL))
{
if(usb_mem_init())
if (usb_mem_init())
{
usb_started = 0;
return -1; /* out of memoy */
}
if(usb_dev == NULL)
if (usb_dev == NULL)
usb_dev = (struct usb_device *)usb_malloc(sizeof(struct usb_device) * USB_MAX_BUS * USB_MAX_DEVICE);
if(usb_dev == NULL)
if (usb_dev == NULL)
{
usb_started = 0;
return -1; /* out of memoy */
@@ -138,12 +138,12 @@ int usb_init(long handle, const struct pci_device_id *ent)
{
int i;
res = 0;
for(i = 0; i < USB_MAX_BUS; i++)
for (i = 0; i < USB_MAX_BUS; i++)
{
if(controller_priv[i] != NULL)
if (controller_priv[i] != NULL)
{
long handle = controller_priv[i]->handle;
if(handle)
if (handle)
res |= usb_init(handle, NULL);
}
}
@@ -169,13 +169,13 @@ int usb_init(long handle, const struct pci_device_id *ent)
break;
default: res = -1; break;
}
if(!res)
if (!res)
{
/* if lowlevel init is OK, scan the bus for devices
* i.e. search HUBs and configure them */
if(setup_packet == NULL)
if (setup_packet == NULL)
setup_packet = (void *)usb_malloc(sizeof(struct devrequest));
if(setup_packet == NULL)
if (setup_packet == NULL)
{
usb_started = 0;
return -1; /* out of memoy */
@@ -202,16 +202,16 @@ int usb_init(long handle, const struct pci_device_id *ent)
int usb_stop(void)
{
int i, res = 0;
if(usb_started)
if (usb_started)
{
asynch_allowed = 1;
usb_started = 0;
usb_hub_reset(bus_index);
usb_free(setup_packet);
for(i = 0; i < USB_MAX_BUS; i++)
for (i = 0; i < USB_MAX_BUS; i++)
{
struct hci *priv = controller_priv[i];
if(priv != NULL)
if (priv != NULL)
{
switch(priv->ent->class)
{
@@ -293,7 +293,7 @@ int usb_control_msg(struct usb_device *dev, unsigned int pipe,
void *data, unsigned short size, int timeout)
{
struct hci *priv = (struct hci *)dev->priv_hcd;
if((timeout == 0) && (!asynch_allowed))
if ((timeout == 0) && (!asynch_allowed))
{
/* request for a asynch control pipe is not allowed */
return -1;
@@ -318,9 +318,9 @@ int usb_control_msg(struct usb_device *dev, unsigned int pipe,
default:
return -1;
}
if(timeout == 0)
if (timeout == 0)
return (int)size;
if(dev->status != 0)
if (dev->status != 0)
{
/*
* Let's wait a while for the timeout to elapse.
@@ -340,7 +340,7 @@ int usb_control_msg(struct usb_device *dev, unsigned int pipe,
int usb_bulk_msg(struct usb_device *dev, unsigned int pipe, void *data, int len, int *actual_length, int timeout)
{
struct hci *priv = (struct hci *)dev->priv_hcd;
if(len < 0)
if (len < 0)
return -1;
switch(priv->ent->class)
{
@@ -357,12 +357,12 @@ int usb_bulk_msg(struct usb_device *dev, unsigned int pipe, void *data, int len,
}
while(timeout--)
{
if(!((volatile uint32_t)dev->status & USB_ST_NOT_PROC))
if (!((volatile uint32_t)dev->status & USB_ST_NOT_PROC))
break;
wait(1 * 1000);
}
*actual_length = dev->act_len;
if(dev->status == 0)
if (dev->status == 0)
return 0;
else
return -1;
@@ -380,7 +380,7 @@ int usb_bulk_msg(struct usb_device *dev, unsigned int pipe, void *data, int len,
int usb_maxpacket(struct usb_device *dev, uint32_t pipe)
{
/* direction is out -> use emaxpacket out */
if((pipe & USB_DIR_IN) == 0)
if ((pipe & USB_DIR_IN) == 0)
return dev->epmaxpacketout[((pipe>>15) & 0xf)];
else
return dev->epmaxpacketin[((pipe>>15) & 0xf)];
@@ -398,7 +398,7 @@ static void __attribute__((noinline))usb_set_maxpacket_ep(struct usb_device *dev
{
int b;
b = ep->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
if((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_CONTROL)
if ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_CONTROL)
{
/* Control => bidirectional */
dev->epmaxpacketout[b] = ep->wMaxPacketSize;
@@ -407,10 +407,10 @@ static void __attribute__((noinline))usb_set_maxpacket_ep(struct usb_device *dev
}
else
{
if((ep->bEndpointAddress & 0x80) == 0)
if ((ep->bEndpointAddress & 0x80) == 0)
{
/* OUT Endpoint */
if(ep->wMaxPacketSize > dev->epmaxpacketout[b])
if (ep->wMaxPacketSize > dev->epmaxpacketout[b])
{
dev->epmaxpacketout[b] = ep->wMaxPacketSize;
USB_PRINTF("##EP epmaxpacketout[%d] = %d\r\n", b, dev->epmaxpacketout[b]);
@@ -419,7 +419,7 @@ static void __attribute__((noinline))usb_set_maxpacket_ep(struct usb_device *dev
else
{
/* IN Endpoint */
if(ep->wMaxPacketSize > dev->epmaxpacketin[b])
if (ep->wMaxPacketSize > dev->epmaxpacketin[b])
{
dev->epmaxpacketin[b] = ep->wMaxPacketSize;
USB_PRINTF("##EP epmaxpacketin[%d] = %d\r\n", b, dev->epmaxpacketin[b]);
@@ -434,8 +434,8 @@ static void __attribute__((noinline))usb_set_maxpacket_ep(struct usb_device *dev
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.bNumInterfaces; i++)
for (ii = 0; ii < dev->config.if_desc[i].bNumEndpoints; ii++)
usb_set_maxpacket_ep(dev,&dev->config.if_desc[i].ep_desc[ii]);
return 0;
}
@@ -455,7 +455,7 @@ int usb_parse_config(struct usb_device *dev, unsigned char *buffer, int cfgno)
curr_if_num = -1;
dev->configno = cfgno;
head = (struct usb_descriptor_header *)&buffer[0];
if(head->bDescriptorType != USB_DT_CONFIG)
if (head->bDescriptorType != USB_DT_CONFIG)
{
xprintf(" ERROR: NOT USB_CONFIG_DESC %x\r\n", head->bDescriptorType);
return -1;
@@ -472,7 +472,7 @@ int usb_parse_config(struct usb_device *dev, unsigned char *buffer, int cfgno)
switch (head->bDescriptorType)
{
case USB_DT_INTERFACE:
if(((struct usb_interface_descriptor *)&buffer[index])->bInterfaceNumber != curr_if_num)
if (((struct usb_interface_descriptor *)&buffer[index])->bInterfaceNumber != curr_if_num)
{
/* this is a new interface, copy new desc */
ifno = dev->config.no_of_if;
@@ -497,7 +497,7 @@ int usb_parse_config(struct usb_device *dev, unsigned char *buffer, int cfgno)
USB_PRINTF("if %d, ep %d\r\n", ifno, epno);
break;
default:
if(head->bLength == 0)
if (head->bLength == 0)
return 1;
USB_PRINTF("unknown Description Type : %x\r\n", head->bDescriptorType);
{
@@ -526,7 +526,7 @@ int usb_clear_halt(struct usb_device *dev, int pipe)
result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
USB_REQ_CLEAR_FEATURE, USB_RECIP_ENDPOINT, 0, endp, NULL, 0, USB_CNTL_TIMEOUT * 3);
/* don't clear if failed */
if(result < 0)
if (result < 0)
return result;
/*
* NOTE: we do not get status and verify reset was successful
@@ -559,16 +559,16 @@ int usb_get_configuration_no(struct usb_device *dev, unsigned char *buffer, int
struct usb_config_descriptor *config;
config = (struct usb_config_descriptor *)&buffer[0];
result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno, buffer, 9);
if(result < 9)
if (result < 9)
{
if(result < 0)
if (result < 0)
xprintf("unable to get descriptor, error %lX\r\n", dev->status);
else
xprintf("config descriptor too short (expected %i, got %i)\n", 9, result);
return -1;
}
tmp = swpw(config->wTotalLength);
if(tmp > USB_BUFSIZ)
if (tmp > USB_BUFSIZ)
{
USB_PRINTF("usb_get_configuration_no: failed to get descriptor - too long: %d\r\n", tmp);
return -1;
@@ -597,15 +597,15 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate)
{
struct usb_interface_descriptor *if_face = NULL;
int ret, i;
for(i = 0; i < dev->config.bNumInterfaces; i++)
for (i = 0; i < dev->config.bNumInterfaces; i++)
{
if(dev->config.if_desc[i].bInterfaceNumber == interface)
if (dev->config.if_desc[i].bInterfaceNumber == interface)
{
if_face = &dev->config.if_desc[i];
break;
}
}
if(!if_face)
if (!if_face)
{
xprintf("selecting invalid interface %d", interface);
return -1;
@@ -617,11 +617,11 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate)
* some USB sticks timeouting during initialization and then being
* unusable in U-Boot.
*/
if(if_face->num_altsetting == 1)
if (if_face->num_altsetting == 1)
return 0;
ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
USB_REQ_SET_INTERFACE, USB_RECIP_INTERFACE, alternate, interface, NULL, 0, USB_CNTL_TIMEOUT * 5);
if(ret < 0)
if (ret < 0)
return ret;
return 0;
}
@@ -636,7 +636,7 @@ int usb_set_configuration(struct usb_device *dev, int configuration)
/* set setup command */
res = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
USB_REQ_SET_CONFIGURATION, 0, configuration, 0, NULL, 0, USB_CNTL_TIMEOUT);
if(res == 0)
if (res == 0)
{
dev->toggle[0] = 0;
dev->toggle[1] = 0;
@@ -695,12 +695,12 @@ int usb_get_string(struct usb_device *dev, unsigned short langid, unsigned char
{
int i;
int result;
for(i = 0; i < 3; ++i)
for (i = 0; i < 3; ++i)
{
/* some devices are flaky */
result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), USB_REQ_GET_DESCRIPTOR, USB_DIR_IN,
(USB_DT_STRING << 8) + index, langid, buf, size, USB_CNTL_TIMEOUT);
if(result > 0)
if (result > 0)
break;
}
return result;
@@ -709,13 +709,13 @@ int usb_get_string(struct usb_device *dev, unsigned short langid, unsigned char
static void usb_try_string_workarounds(unsigned char *buf, int *length)
{
int newlength, oldlength = *length;
for(newlength = 2; newlength + 1 < oldlength; newlength += 2)
for (newlength = 2; newlength + 1 < oldlength; newlength += 2)
{
char c = buf[newlength];
if((c < ' ') || (c >= 127) || buf[newlength + 1])
if ((c < ' ') || (c >= 127) || buf[newlength + 1])
break;
}
if(newlength > 2)
if (newlength > 2)
{
buf[0] = newlength;
*length = newlength;
@@ -730,13 +730,13 @@ static int usb_string_sub(struct usb_device *dev, unsigned int langid, unsigned
rc = usb_get_string(dev, langid, index, buf, 255);
/* If that failed try to read the descriptor length, then
* ask for just that many bytes */
if(rc < 2)
if (rc < 2)
{
rc = usb_get_string(dev, langid, index, buf, 2);
if(rc == 2)
if (rc == 2)
rc = usb_get_string(dev, langid, index, buf, buf[0]);
}
if(rc >= 2)
if (rc >= 2)
{
if (!buf[0] && !buf[1])
usb_try_string_workarounds(buf, &rc);
@@ -745,7 +745,7 @@ static int usb_string_sub(struct usb_device *dev, unsigned int langid, unsigned
rc = buf[0];
rc = rc - (rc & 1); /* force a multiple of two */
}
if(rc < 2)
if (rc < 2)
rc = -1;
return rc;
}
@@ -760,26 +760,26 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size)
unsigned char *tbuf;
int err;
unsigned int u, idx;
if(size <= 0 || !buf || !index)
if (size <= 0 || !buf || !index)
return -1;
buf[0] = 0;
tbuf = (unsigned char *)usb_malloc(USB_BUFSIZ);
if(tbuf == NULL)
if (tbuf == NULL)
{
USB_PRINTF("usb_string: malloc failure\r\n");
return -1;
}
/* get langid for strings if it's not yet known */
if(!dev->have_langid)
if (!dev->have_langid)
{
err = usb_string_sub(dev, 0, 0, tbuf);
if(err < 0)
if (err < 0)
{
USB_PRINTF("error getting string descriptor 0 (error=%lx)\r\n", dev->status);
usb_free(tbuf);
return -1;
}
else if(tbuf[0] < 4)
else if (tbuf[0] < 4)
{
USB_PRINTF("string descriptor 0 too short\r\n");
usb_free(tbuf);
@@ -794,17 +794,17 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size)
}
}
err = usb_string_sub(dev, dev->string_langid, index, tbuf);
if(err < 0)
if (err < 0)
{
usb_free(tbuf);
return err;
}
size--; /* leave room for trailing NULL char in output buffer */
for(idx = 0, u = 2; u < err; u += 2)
for (idx = 0, u = 2; u < err; u += 2)
{
if(idx >= size)
if (idx >= size)
break;
if(tbuf[u+1]) /* high byte */
if (tbuf[u+1]) /* high byte */
buf[idx++] = '?'; /* non-ASCII character */
else
buf[idx++] = tbuf[u];
@@ -826,17 +826,17 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size)
void usb_disconnect(struct usb_device **pdev)
{
struct usb_device *dev = *pdev;
if(dev != NULL)
if (dev != NULL)
{
int i;
USB_PRINTF("USB %d disconnect on device %d\r\n", dev->parent->usbnum, dev->parent->devnum);
USB_PRINTF("USB %d disconnected, device number %d\r\n", dev->usbnum, dev->devnum);
if(dev->deregister != NULL)
if (dev->deregister != NULL)
dev->deregister(dev);
/* Free up all the children.. */
for(i = 0; i < USB_MAXCHILDREN; i++)
for (i = 0; i < USB_MAXCHILDREN; i++)
{
if(dev->children[i] != NULL)
if (dev->children[i] != NULL)
{
USB_PRINTF("USB %d, disconnect children %d\r\n", dev->usbnum, dev->children[i]->devnum);
usb_disconnect(&dev->children[i]);
@@ -844,7 +844,7 @@ void usb_disconnect(struct usb_device **pdev)
}
}
/* Free up the device itself, including its device number */
if(dev->devnum > 0)
if (dev->devnum > 0)
{
dev_index[dev->usbnum]--;
memset(dev, 0, sizeof(struct usb_device));
@@ -860,11 +860,11 @@ void usb_disconnect(struct usb_device **pdev)
struct usb_device *usb_get_dev_index(int index, int index_bus)
{
struct usb_device *dev;
if((index_bus >= USB_MAX_BUS) || (index_bus < 0)
if ((index_bus >= USB_MAX_BUS) || (index_bus < 0)
|| (index >= USB_MAX_DEVICE) || (index < 0))
return NULL;
dev = &usb_dev[(index_bus * USB_MAX_DEVICE) + index];
if((controller_priv[index_bus] == NULL) || (dev->devnum == -1))
if ((controller_priv[index_bus] == NULL) || (dev->devnum == -1))
return NULL;
return dev;
}
@@ -877,7 +877,7 @@ struct usb_device *usb_alloc_new_device(int bus_index, void *priv)
int i, index = dev_index[bus_index];
struct usb_device *dev;
USB_PRINTF("USB %d new device %d\r\n", bus_index, index);
if(index >= USB_MAX_DEVICE)
if (index >= USB_MAX_DEVICE)
{
xprintf("ERROR, too many USB Devices, max=%d\r\n", USB_MAX_DEVICE);
return NULL;
@@ -886,7 +886,7 @@ struct usb_device *usb_alloc_new_device(int bus_index, void *priv)
dev = &usb_dev[(bus_index * USB_MAX_DEVICE) + index];
dev->devnum = index + 1;
dev->maxchild = 0;
for(i = 0; i < USB_MAXCHILDREN; dev->children[i++] = NULL);
for (i = 0; i < USB_MAXCHILDREN; dev->children[i++] = NULL);
dev->parent = NULL;
dev->priv_hcd = priv;
dev->usbnum = bus_index;
@@ -911,13 +911,13 @@ int usb_new_device(struct usb_device *dev)
struct usb_device *parent = dev->parent;
unsigned short portstatus;
#endif
if(dev == NULL)
if (dev == NULL)
return 1;
/* We still haven't set the Address yet */
addr = dev->devnum;
dev->devnum = 0;
tmpbuf = (unsigned char *)usb_malloc(USB_BUFSIZ);
if(tmpbuf == NULL)
if (tmpbuf == NULL)
{
USB_PRINTF("usb_new_device: malloc failure\r\n");
return 1;
@@ -933,7 +933,7 @@ int usb_new_device(struct usb_device *dev)
dev->epmaxpacketin[0] = 8;
dev->epmaxpacketout[0] = 8;
err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, &dev->descriptor, 8);
if(err < 8)
if (err < 8)
{
xprintf("\r\nUSB device not responding, giving up (status=%lX)\r\n", dev->status);
usb_free(tmpbuf);
@@ -958,7 +958,7 @@ int usb_new_device(struct usb_device *dev)
dev->epmaxpacketin[0] = 64;
dev->epmaxpacketout[0] = 64;
err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, desc, 64);
if(err < 0)
if (err < 0)
{
USB_PRINTF("usb_new_device: usb_get_descriptor() failed\r\n");
usb_free(tmpbuf);
@@ -966,18 +966,18 @@ int usb_new_device(struct usb_device *dev)
}
dev->descriptor.bMaxPacketSize0 = desc->bMaxPacketSize0;
/* find the port number we're at */
if(parent)
if (parent)
{
int j;
for(j = 0; j < parent->maxchild; j++)
for (j = 0; j < parent->maxchild; j++)
{
if(parent->children[j] == dev)
if (parent->children[j] == dev)
{
port = j;
break;
}
}
if(port < 0)
if (port < 0)
{
xprintf("usb_new_device: cannot locate device's port.\r\n");
usb_free(tmpbuf);
@@ -985,7 +985,7 @@ int usb_new_device(struct usb_device *dev)
}
/* reset the port for the second time */
err = hub_port_reset(dev->parent, port, &portstatus);
if(err < 0)
if (err < 0)
{
xprintf("\r\nCouldn't reset port %i\r\n", port);
usb_free(tmpbuf);
@@ -1004,7 +1004,7 @@ int usb_new_device(struct usb_device *dev)
}
dev->devnum = addr;
err = usb_set_address(dev); /* set address */
if(err < 0)
if (err < 0)
{
xprintf("\r\nUSB device not accepting new address (error=%lX)\r\n", dev->status);
usb_free(tmpbuf);
@@ -1013,9 +1013,9 @@ int usb_new_device(struct usb_device *dev)
wait(10 * 1000); /* Let the SET_ADDRESS settle */
tmp = sizeof(dev->descriptor);
err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, &dev->descriptor, sizeof(dev->descriptor));
if(err < tmp)
if (err < tmp)
{
if(err < 0)
if (err < 0)
xprintf("unable to get device descriptor (error=%d)\r\n", err);
else
xprintf("USB device descriptor short read (expected %i, got %i)\r\n", tmp, err);
@@ -1032,7 +1032,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.bConfigurationValue))
{
xprintf("failed to set default configuration len %d, status %lX\r\n", dev->act_len, dev->status);
usb_free(tmpbuf);
@@ -1044,11 +1044,11 @@ int usb_new_device(struct usb_device *dev)
memset(dev->mf, 0, sizeof(dev->mf));
memset(dev->prod, 0, sizeof(dev->prod));
memset(dev->serial, 0, sizeof(dev->serial));
if(dev->descriptor.iManufacturer)
if (dev->descriptor.iManufacturer)
usb_string(dev, dev->descriptor.iManufacturer, dev->mf, sizeof(dev->mf));
if(dev->descriptor.iProduct)
if (dev->descriptor.iProduct)
usb_string(dev, dev->descriptor.iProduct, dev->prod, sizeof(dev->prod));
if(dev->descriptor.iSerialNumber)
if (dev->descriptor.iSerialNumber)
usb_string(dev, dev->descriptor.iSerialNumber, dev->serial, sizeof(dev->serial));
USB_PRINTF("Manufacturer %s\r\n", dev->mf);
USB_PRINTF("Product %s\r\n", dev->prod);
@@ -1065,7 +1065,7 @@ void usb_scan_devices(void *priv)
int i;
struct usb_device *dev;
/* first make all devices unknown */
for(i = 0; i < USB_MAX_DEVICE; i++)
for (i = 0; i < USB_MAX_DEVICE; i++)
{
memset(&usb_dev[(bus_index * USB_MAX_DEVICE) + i], 0, sizeof(struct usb_device));
usb_dev[(bus_index * USB_MAX_DEVICE) + i].devnum = -1;
@@ -1073,10 +1073,10 @@ void usb_scan_devices(void *priv)
dev_index[bus_index] = 0;
/* device 0 is always present (root hub, so let it analyze) */
dev = usb_alloc_new_device(bus_index, priv);
if(usb_new_device(dev))
if (usb_new_device(dev))
{
xprintf("No USB Device found\r\n");
if(dev != NULL)
if (dev != NULL)
dev_index[bus_index]--;
}
else
@@ -1090,7 +1090,7 @@ void usb_scan_devices(void *priv)
xprintf("No USB keyboard found\r\n");
else
xprintf("USB HID keyboard driver installed\r\n");
if(drv_usb_mouse_init() < 0)
if (drv_usb_mouse_init() < 0)
xprintf("No USB mouse found\r\n");
else
xprintf("USB HID mouse driver installed\r\n");
@@ -1104,7 +1104,7 @@ void usb_scan_devices(void *priv)
* Probes device for being a hub and configurate it
*/
#undef USB_HUB_DEBUG
#define USB_HUB_DEBUG
#ifdef USB_HUB_DEBUG
#define USB_HUB_PRINTF(fmt, args...) xprintf(fmt , ##args)
@@ -1173,7 +1173,7 @@ void usb_hub_reset(int bus_index)
struct usb_hub_device *usb_hub_allocate(void)
{
if(usb_hub_index[bus_index] < USB_MAX_HUB)
if (usb_hub_index[bus_index] < USB_MAX_HUB)
return &hub_dev[bus_index][usb_hub_index[bus_index]++];
xprintf("ERROR: USB_MAX_HUB (%d) reached\r\n", USB_MAX_HUB);
return NULL;
@@ -1183,9 +1183,9 @@ struct usb_hub_device *usb_hub_allocate(void)
static inline char *portspeed(int portstatus)
{
if(portstatus & (1 << USB_PORT_FEAT_HIGHSPEED))
if (portstatus & (1 << USB_PORT_FEAT_HIGHSPEED))
return "480 Mb/s";
else if(portstatus & (1 << USB_PORT_FEAT_LOWSPEED))
else if (portstatus & (1 << USB_PORT_FEAT_LOWSPEED))
return "1.5 Mb/s";
else
return "12 Mb/s";
@@ -1197,16 +1197,16 @@ static int hub_port_reset(struct usb_device *dev, int port, unsigned short *port
struct usb_port_status portsts;
unsigned short portstatus, portchange;
USB_HUB_PRINTF("hub_port_reset: resetting port %d...\r\n", port + 1);
for(tries = 0; tries < MAX_TRIES; tries++)
for (tries = 0; tries < MAX_TRIES; tries++)
{
usb_set_port_feature(dev, port + 1, USB_PORT_FEAT_RESET);
#ifdef USB_POLL_HUB
if(pxCurrentTCB != NULL)
if (pxCurrentTCB != NULL)
vTaskDelay((200*configTICK_RATE_HZ)/1000);
else
#endif
wait(200 * 1000);
if(usb_get_port_status(dev, port + 1, &portsts) < 0)
if (usb_get_port_status(dev, port + 1, &portsts) < 0)
{
USB_HUB_PRINTF("get_port_status failed status %lX\r\n", dev->status);
return -1;
@@ -1216,18 +1216,18 @@ static int hub_port_reset(struct usb_device *dev, int port, unsigned short *port
USB_HUB_PRINTF("USB %d portstatus %x, change %x, %s\r\n", dev->usbnum, portstatus, portchange, portspeed(portstatus));
USB_HUB_PRINTF("STAT_C_CONNECTION = %d STAT_CONNECTION = %d USB_PORT_STAT_ENABLE = %d\r\n",
(portchange & USB_PORT_STAT_C_CONNECTION) ? 1 : 0, (portstatus & USB_PORT_STAT_CONNECTION) ? 1 : 0, (portstatus & USB_PORT_STAT_ENABLE) ? 1 : 0);
if((portchange & USB_PORT_STAT_C_CONNECTION) || !(portstatus & USB_PORT_STAT_CONNECTION))
if ((portchange & USB_PORT_STAT_C_CONNECTION) || !(portstatus & USB_PORT_STAT_CONNECTION))
return -1;
if(portstatus & USB_PORT_STAT_ENABLE)
if (portstatus & USB_PORT_STAT_ENABLE)
break;
#ifdef USB_POLL_HUB
if(pxCurrentTCB != NULL)
if (pxCurrentTCB != NULL)
vTaskDelay((200*configTICK_RATE_HZ)/1000);
else
#endif
wait(200 * 1000);
}
if(tries == MAX_TRIES)
if (tries == MAX_TRIES)
{
USB_HUB_PRINTF("USB %d, cannot enable port %i after %i retries, disabling port.\r\n", dev->usbnum, port + 1, MAX_TRIES);
USB_HUB_PRINTF("Maybe the USB cable is bad?\r\n");
@@ -1244,7 +1244,7 @@ void usb_hub_port_connect_change(struct usb_device *dev, int port)
struct usb_port_status portsts;
unsigned short portstatus, portchange;
/* Check status */
if(usb_get_port_status(dev, port + 1, &portsts) < 0)
if (usb_get_port_status(dev, port + 1, &portsts) < 0)
{
USB_HUB_PRINTF("USB %d get_port_status failed\r\n", dev->usbnum);
return;
@@ -1255,52 +1255,52 @@ void usb_hub_port_connect_change(struct usb_device *dev, int port)
/* Clear the connection change status */
usb_clear_port_feature(dev, port + 1, USB_PORT_FEAT_C_CONNECTION);
/* Disconnect any existing devices under this port */
if(((!(portstatus & USB_PORT_STAT_CONNECTION))
if (((!(portstatus & USB_PORT_STAT_CONNECTION))
&& (!(portstatus & USB_PORT_STAT_ENABLE))) || (dev->children[port]))
{
USB_HUB_PRINTF("USB %d port %i disconnected\r\n", dev->usbnum, port + 1);
usb_disconnect(&dev->children[port]);
/* Return now if nothing is connected */
if(!(portstatus & USB_PORT_STAT_CONNECTION))
if (!(portstatus & USB_PORT_STAT_CONNECTION))
return;
}
#ifdef USB_POLL_HUB
if(pxCurrentTCB != NULL)
if (pxCurrentTCB != NULL)
vTaskDelay((200*configTICK_RATE_HZ)/1000);
else
#endif
wait(200 * 1000);
/* Reset the port */
if(hub_port_reset(dev, port, &portstatus) < 0)
if (hub_port_reset(dev, port, &portstatus) < 0)
{
USB_HUB_PRINTF("USB %d cannot reset port %i!?\r\n", dev->usbnum, port + 1);
return;
}
#ifdef USB_POLL_HUB
if(pxCurrentTCB != NULL)
if (pxCurrentTCB != NULL)
vTaskDelay((200*configTICK_RATE_HZ)/1000);
else
#endif
wait(200 * 1000);
/* Allocate a new device struct for it */
usb = usb_alloc_new_device(dev->usbnum, dev->priv_hcd);
if(portstatus & USB_PORT_STAT_HIGH_SPEED)
if (portstatus & USB_PORT_STAT_HIGH_SPEED)
usb->speed = USB_SPEED_HIGH;
else if(portstatus & USB_PORT_STAT_LOW_SPEED)
else if (portstatus & USB_PORT_STAT_LOW_SPEED)
usb->speed = USB_SPEED_LOW;
else
usb->speed = USB_SPEED_FULL;
dev->children[port] = usb;
usb->parent = dev;
/* Run it through the hoops (find a driver, etc) */
if(usb_new_device(usb))
if (usb_new_device(usb))
{
/* Woops, disable the port */
USB_HUB_PRINTF("USB %d hub: disabling port %d\r\n", dev->usbnum, port + 1);
usb_clear_port_feature(dev, port + 1, USB_PORT_FEAT_ENABLE);
}
#ifdef USB_POLL_HUB
else if(pxCurrentTCB != NULL)
else if (pxCurrentTCB != NULL)
{
#ifdef CONFIG_USB_KEYBOARD
usb_kbd_register(usb);
@@ -1319,13 +1319,13 @@ static void usb_hub_events(struct usb_device *dev)
{
int i;
struct usb_hub_device *hub = dev->hub;
if(hub == NULL)
if (hub == NULL)
return;
for(i = 0; i < dev->maxchild; i++)
for (i = 0; i < dev->maxchild; i++)
{
struct usb_port_status portsts;
unsigned short portstatus, portchange;
if(usb_get_port_status(dev, i + 1, &portsts) < 0)
if (usb_get_port_status(dev, i + 1, &portsts) < 0)
{
USB_HUB_PRINTF("get_port_status failed\r\n");
continue;
@@ -1333,36 +1333,36 @@ static void usb_hub_events(struct usb_device *dev)
portstatus = swpw(portsts.wPortStatus);
portchange = swpw(portsts.wPortChange);
// USB_HUB_PRINTF("USB %d Port %d Status %X Change %X\r\n", dev->usbnum, i + 1, portstatus, portchange);
if(portchange & USB_PORT_STAT_C_CONNECTION)
if (portchange & USB_PORT_STAT_C_CONNECTION)
{
USB_HUB_PRINTF("USB %d port %d connection change\r\n", dev->usbnum, i + 1);
usb_hub_port_connect_change(dev, i);
}
if(portchange & USB_PORT_STAT_C_ENABLE)
if (portchange & USB_PORT_STAT_C_ENABLE)
{
USB_HUB_PRINTF("USB %d port %d enable change, status %x\r\n", dev->usbnum, i + 1, portstatus);
usb_clear_port_feature(dev, i + 1, USB_PORT_FEAT_C_ENABLE);
/* EM interference sometimes causes bad shielded USB
* devices to be shutdown by the hub, this hack enables
* them again. Works at least with mouse driver */
if(!(portstatus & USB_PORT_STAT_ENABLE) && (portstatus & USB_PORT_STAT_CONNECTION) && ((dev->children[i])))
if (!(portstatus & USB_PORT_STAT_ENABLE) && (portstatus & USB_PORT_STAT_CONNECTION) && ((dev->children[i])))
{
USB_HUB_PRINTF("USB %d already running port %i disabled by hub (EMI?), re-enabling...\r\n", dev->usbnum, i + 1);
usb_hub_port_connect_change(dev, i);
}
}
if(portstatus & USB_PORT_STAT_SUSPEND)
if (portstatus & USB_PORT_STAT_SUSPEND)
{
USB_HUB_PRINTF("USB %d port %d suspend change\r\n", dev->usbnum, i + 1);
usb_clear_port_feature(dev, i + 1, USB_PORT_FEAT_SUSPEND);
}
if(portchange & USB_PORT_STAT_C_OVERCURRENT)
if (portchange & USB_PORT_STAT_C_OVERCURRENT)
{
USB_HUB_PRINTF("USB %d port %d over-current change\r\n", dev->usbnum, i + 1);
usb_clear_port_feature(dev, i + 1, USB_PORT_FEAT_C_OVER_CURRENT);
usb_hub_power_on(hub);
}
if(portchange & USB_PORT_STAT_C_RESET)
if (portchange & USB_PORT_STAT_C_RESET)
{
USB_HUB_PRINTF("USB %d port %d reset change\r\n", dev->usbnum, i + 1);
usb_clear_port_feature(dev, i + 1, USB_PORT_FEAT_C_RESET);
@@ -1375,12 +1375,12 @@ void usb_poll_hub_task(void *pvParameters)
{
int index_bus = 0;
portTickType timeout = configTICK_RATE_HZ/10;
if(pvParameters);
if (pvParameters);
while(1)
{
if(xQueueAltReceive(queue_poll_hub, &index_bus, timeout) == pdPASS)
if (xQueueAltReceive(queue_poll_hub, &index_bus, timeout) == pdPASS)
{
if((index_bus >= 0) && (index_bus < USB_MAX_BUS) && (controller_priv[index_bus] != NULL))
if ((index_bus >= 0) && (index_bus < USB_MAX_BUS) && (controller_priv[index_bus] != NULL))
{
USB_HUB_PRINTF("USB %d event change\r\n", index_bus);
#ifdef CONFIG_USB_INTERRUPT_POLLING
@@ -1398,9 +1398,9 @@ void usb_poll_hub_task(void *pvParameters)
#ifdef CONFIG_USB_INTERRUPT_POLLING
*vblsem = 0;
#endif
for(i = 0; i < USB_MAX_BUS ; i++)
for (i = 0; i < USB_MAX_BUS ; i++)
{
if(controller_priv[i] != NULL)
if (controller_priv[i] != NULL)
usb_hub_events(&usb_dev[i * USB_MAX_DEVICE]);
}
#ifdef CONFIG_USB_INTERRUPT_POLLING
@@ -1422,17 +1422,17 @@ int usb_hub_configure(struct usb_device *dev)
/* "allocate" Hub device */
hub = usb_hub_allocate();
dev->hub = hub;
if(hub == NULL)
if (hub == NULL)
return -1;
hub->pusb_dev = dev;
buffer = (unsigned char *)usb_malloc(USB_BUFSIZ);
if(buffer == NULL)
if (buffer == NULL)
{
USB_HUB_PRINTF("usb_hub_configure: malloc failure\r\n");
return -1;
}
/* Get the the hub descriptor */
if(usb_get_hub_descriptor(dev, buffer, 4) < 0)
if (usb_get_hub_descriptor(dev, buffer, 4) < 0)
{
USB_HUB_PRINTF("usb_hub_configure: failed to get hub descriptor, giving up %lX\r\n", dev->status);
usb_free(buffer);
@@ -1442,13 +1442,13 @@ int usb_hub_configure(struct usb_device *dev)
descriptor = (struct usb_hub_descriptor *)buffer;
/* silence compiler warning if USB_BUFSIZ is > 256 [= sizeof(char)] */
i = descriptor->bLength;
if(i > USB_BUFSIZ)
if (i > USB_BUFSIZ)
{
USB_HUB_PRINTF("usb_hub_configure: failed to get hub descriptor - too long: %d\r\n", descriptor->bLength);
usb_free(buffer);
return -1;
}
if(usb_get_hub_descriptor(dev, buffer, descriptor->bLength) < 0)
if (usb_get_hub_descriptor(dev, buffer, descriptor->bLength) < 0)
{
USB_HUB_PRINTF("usb_hub_configure: failed to get hub descriptor 2nd giving up %lX\r\n", dev->status);
usb_free(buffer);
@@ -1463,13 +1463,13 @@ int usb_hub_configure(struct usb_device *dev)
memset(bitmap, 0xff, (USB_MAXCHILDREN+1+7)/8);
bitmap = (unsigned char *)&hub->desc.PortPowerCtrlMask[0];
memset(bitmap, 0xff, (USB_MAXCHILDREN+1+7)/8); /* PowerMask = 1B */
for(i = 0; i < ((hub->desc.bNbrPorts + 1 + 7)/8); i++)
for (i = 0; i < ((hub->desc.bNbrPorts + 1 + 7)/8); i++)
hub->desc.DeviceRemovable[i] = descriptor->DeviceRemovable[i];
for(i = 0; i < ((hub->desc.bNbrPorts + 1 + 7)/8); i++)
for (i = 0; i < ((hub->desc.bNbrPorts + 1 + 7)/8); i++)
hub->desc.DeviceRemovable[i] = descriptor->PortPowerCtrlMask[i];
dev->maxchild = descriptor->bNbrPorts;
USB_HUB_PRINTF("USB %d, %d ports detected\r\n", dev->usbnum, dev->maxchild);
if(dev->maxchild >= 10)
if (dev->maxchild >= 10)
dev->maxchild = 10;
switch(hub->desc.wHubCharacteristics & HUB_CHAR_LPSM)
{
@@ -1478,7 +1478,7 @@ int usb_hub_configure(struct usb_device *dev)
case 0x02:
case 0x03: USB_HUB_PRINTF("unknown reserved power switching mode\r\n"); break;
}
if(hub->desc.wHubCharacteristics & HUB_CHAR_COMPOUND)
if (hub->desc.wHubCharacteristics & HUB_CHAR_COMPOUND)
{
USB_HUB_PRINTF("part of a compound device\r\n");
}
@@ -1495,17 +1495,17 @@ int usb_hub_configure(struct usb_device *dev)
}
USB_HUB_PRINTF("power on to power good time: %dms\r\n", descriptor->bPwrOn2PwrGood * 2);
USB_HUB_PRINTF("hub controller current requirement: %dmA\r\n", descriptor->bHubContrCurrent);
for(i = 0; i < dev->maxchild; i++)
for (i = 0; i < dev->maxchild; i++)
{
USB_HUB_PRINTF("USB %d port %d is%s removable\r\n", dev->usbnum, i + 1, hub->desc.DeviceRemovable[(i + 1) / 8] & (1 << ((i + 1) % 8)) ? " not" : "");
}
if(sizeof(struct usb_hub_status) > USB_BUFSIZ)
if (sizeof(struct usb_hub_status) > USB_BUFSIZ)
{
USB_HUB_PRINTF("usb_hub_configure: failed to get Status - too long: %d\r\n", descriptor->bLength);
usb_free(buffer);
return -1;
}
if(usb_get_hub_status(dev, buffer) < 0)
if (usb_get_hub_status(dev, buffer) < 0)
{
USB_HUB_PRINTF("usb_hub_configure: failed to get Status %lX\r\n", dev->status);
usb_free(buffer);
@@ -1517,13 +1517,13 @@ int usb_hub_configure(struct usb_device *dev)
USB_HUB_PRINTF("%sover-current condition exists\r\n", (swpw(hubsts->wHubStatus) & HUB_STATUS_OVERCURRENT) ? "" : "no ");
usb_hub_power_on(hub);
#ifdef USB_POLL_HUB
if((queue_poll_hub == NULL) && (pxCurrentTCB != NULL))
if ((queue_poll_hub == NULL) && (pxCurrentTCB != NULL))
{
queue_poll_hub = xQueueCreate(64, sizeof(int));
if(queue_poll_hub != NULL)
if (queue_poll_hub != NULL)
{
/* Create poll/event task */
if(xTaskCreate(usb_poll_hub_task, (void *)"USBHub", configMINIMAL_STACK_SIZE, NULL, 16, NULL) != pdPASS)
if (xTaskCreate(usb_poll_hub_task, (void *)"USBHub", configMINIMAL_STACK_SIZE, NULL, 16, NULL) != pdPASS)
{
vQueueDelete(queue_poll_hub);
queue_poll_hub = NULL;
@@ -1531,7 +1531,7 @@ int usb_hub_configure(struct usb_device *dev)
}
vTaskDelay(configTICK_RATE_HZ);
}
if(queue_poll_hub == NULL)
if (queue_poll_hub == NULL)
#endif
usb_hub_events(dev);
usb_free(buffer);
@@ -1545,21 +1545,21 @@ int usb_hub_probe(struct usb_device *dev, int ifnum)
int ret;
iface = &dev->config.if_desc[ifnum];
/* Is it a hub? */
if(iface->bInterfaceClass != USB_CLASS_HUB)
if (iface->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->bInterfaceSubClass != 0) && (iface->bInterfaceSubClass != 1))
return 0;
/* Multiple endpoints? What kind of mutant ninja-hub is this? */
if(iface->bNumEndpoints != 1)
if (iface->bNumEndpoints != 1)
return 0;
ep = &iface->ep_desc[0];
/* Output endpoint? Curiousier and curiousier.. */
if(!(ep->bEndpointAddress & USB_DIR_IN))
if (!(ep->bEndpointAddress & USB_DIR_IN))
return 0;
/* If it's not an interrupt endpoint, we'd better punt! */
if((ep->bmAttributes & 3) != 3)
if ((ep->bmAttributes & 3) != 3)
return 0;
/* We found a hub */
USB_HUB_PRINTF("USB %d hub found\r\n", dev->usbnum);