USB style patch, 80 chars strict

USB Code style patch

Signed-off-by: Michael Trimarchi <trimarchi@gandalf.sssup.it>
Signed-off-by: Remy Böhmer <linux@bohmer.net>
This commit is contained in:
Michael Trimarchi 2008-11-26 17:41:34 +01:00 committed by Remy Böhmer
parent d10c5a87cb
commit de39f8c19d
3 changed files with 462 additions and 389 deletions

View File

@ -40,29 +40,30 @@ char * usb_get_class_desc(unsigned char dclass)
{ {
switch (dclass) { switch (dclass) {
case USB_CLASS_PER_INTERFACE: case USB_CLASS_PER_INTERFACE:
return("See Interface"); return "See Interface";
case USB_CLASS_AUDIO: case USB_CLASS_AUDIO:
return("Audio"); return "Audio";
case USB_CLASS_COMM: case USB_CLASS_COMM:
return("Communication"); return "Communication";
case USB_CLASS_HID: case USB_CLASS_HID:
return("Human Interface"); return "Human Interface";
case USB_CLASS_PRINTER: case USB_CLASS_PRINTER:
return("Printer"); return "Printer";
case USB_CLASS_MASS_STORAGE: case USB_CLASS_MASS_STORAGE:
return("Mass Storage"); return "Mass Storage";
case USB_CLASS_HUB: case USB_CLASS_HUB:
return("Hub"); return "Hub";
case USB_CLASS_DATA: case USB_CLASS_DATA:
return("CDC Data"); return "CDC Data";
case USB_CLASS_VENDOR_SPEC: case USB_CLASS_VENDOR_SPEC:
return("Vendor specific"); return "Vendor specific";
default: default:
return(""); return "";
} }
} }
void usb_display_class_sub(unsigned char dclass,unsigned char subclass,unsigned char proto) void usb_display_class_sub(unsigned char dclass, unsigned char subclass,
unsigned char proto)
{ {
switch (dclass) { switch (dclass) {
case USB_CLASS_PER_INTERFACE: case USB_CLASS_PER_INTERFACE:
@ -88,10 +89,12 @@ void usb_display_class_sub(unsigned char dclass,unsigned char subclass,unsigned
break; break;
default: default:
printf("reserved"); printf("reserved");
break;
} }
break; break;
default: default:
printf("reserved"); printf("reserved");
break;
} }
break; break;
case USB_CLASS_MASS_STORAGE: case USB_CLASS_MASS_STORAGE:
@ -132,10 +135,12 @@ void usb_display_class_sub(unsigned char dclass,unsigned char subclass,unsigned
break; break;
default: default:
printf("reserved"); printf("reserved");
break;
} }
break; break;
default: default:
printf("%s", usb_get_class_desc(dclass)); printf("%s", usb_get_class_desc(dclass));
break;
} }
} }
@ -143,7 +148,7 @@ void usb_display_string(struct usb_device *dev,int index)
{ {
char buffer[256]; char buffer[256];
if (index != 0) { if (index != 0) {
if (usb_string(dev,index,&buffer[0],256)>0); if (usb_string(dev, index, &buffer[0], 256) > 0)
printf("String: \"%s\"", buffer); printf("String: \"%s\"", buffer);
} }
} }
@ -151,29 +156,45 @@ void usb_display_string(struct usb_device *dev,int index)
void usb_display_desc(struct usb_device *dev) void usb_display_desc(struct usb_device *dev)
{ {
if (dev->descriptor.bDescriptorType == USB_DT_DEVICE) { 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), printf("%d: %s, USB Revision %x.%x\n", dev->devnum,
(dev->descriptor.bcdUSB>>8) & 0xff,dev->descriptor.bcdUSB & 0xff); usb_get_class_desc(dev->config.if_desc[0].bInterfaceClass),
if (strlen(dev->mf) || strlen(dev->prod) || strlen(dev->serial)) (dev->descriptor.bcdUSB>>8) & 0xff,
printf(" - %s %s %s\n",dev->mf,dev->prod,dev->serial); dev->descriptor.bcdUSB & 0xff);
if (strlen(dev->mf) || strlen(dev->prod) ||
strlen(dev->serial))
printf(" - %s %s %s\n", dev->mf, dev->prod,
dev->serial);
if (dev->descriptor.bDeviceClass) { if (dev->descriptor.bDeviceClass) {
printf(" - Class: "); printf(" - Class: ");
usb_display_class_sub(dev->descriptor.bDeviceClass,dev->descriptor.bDeviceSubClass,dev->descriptor.bDeviceProtocol); usb_display_class_sub(dev->descriptor.bDeviceClass,
dev->descriptor.bDeviceSubClass,
dev->descriptor.bDeviceProtocol);
printf("\n"); printf("\n");
} else {
printf(" - Class: (from Interface) %s\n",
usb_get_class_desc(
dev->config.if_desc[0].bInterfaceClass));
} }
else { printf(" - PacketSize: %d Configurations: %d\n",
printf(" - Class: (from Interface) %s\n",usb_get_class_desc(dev->config.if_desc[0].bInterfaceClass)); dev->descriptor.bMaxPacketSize0,
} dev->descriptor.bNumConfigurations);
printf(" - PacketSize: %d Configurations: %d\n",dev->descriptor.bMaxPacketSize0,dev->descriptor.bNumConfigurations); printf(" - Vendor: 0x%04x Product 0x%04x Version %d.%d\n",
printf(" - Vendor: 0x%04x Product 0x%04x Version %d.%d\n",dev->descriptor.idVendor,dev->descriptor.idProduct,(dev->descriptor.bcdDevice>>8) & 0xff,dev->descriptor.bcdDevice & 0xff); dev->descriptor.idVendor, dev->descriptor.idProduct,
(dev->descriptor.bcdDevice>>8) & 0xff,
dev->descriptor.bcdDevice & 0xff);
} }
} }
void usb_display_conf_desc(struct usb_config_descriptor *config,struct usb_device *dev) void usb_display_conf_desc(struct usb_config_descriptor *config,
struct usb_device *dev)
{ {
printf(" Configuration: %d\n", config->bConfigurationValue); printf(" Configuration: %d\n", config->bConfigurationValue);
printf(" - Interfaces: %d %s%s%dmA\n",config->bNumInterfaces,(config->bmAttributes & 0x40) ? "Self Powered " : "Bus Powered ", printf(" - Interfaces: %d %s%s%dmA\n", config->bNumInterfaces,
(config->bmAttributes & 0x20) ? "Remote Wakeup " : "",config->MaxPower*2); (config->bmAttributes & 0x40) ? "Self Powered " : "Bus Powered ",
(config->bmAttributes & 0x20) ? "Remote Wakeup " : "",
config->MaxPower*2);
if (config->iConfiguration) { if (config->iConfiguration) {
printf(" - "); printf(" - ");
usb_display_string(dev, config->iConfiguration); usb_display_string(dev, config->iConfiguration);
@ -181,12 +202,15 @@ void usb_display_conf_desc(struct usb_config_descriptor *config,struct usb_devic
} }
} }
void usb_display_if_desc(struct usb_interface_descriptor *ifdesc,struct usb_device *dev) void usb_display_if_desc(struct usb_interface_descriptor *ifdesc,
struct usb_device *dev)
{ {
printf(" Interface: %d\n", ifdesc->bInterfaceNumber); printf(" Interface: %d\n", ifdesc->bInterfaceNumber);
printf(" - Alternate Setting %d, Endpoints: %d\n",ifdesc->bAlternateSetting,ifdesc->bNumEndpoints); printf(" - Alternate Setting %d, Endpoints: %d\n",
ifdesc->bAlternateSetting, ifdesc->bNumEndpoints);
printf(" - Class "); printf(" - Class ");
usb_display_class_sub(ifdesc->bInterfaceClass,ifdesc->bInterfaceSubClass,ifdesc->bInterfaceProtocol); usb_display_class_sub(ifdesc->bInterfaceClass,
ifdesc->bInterfaceSubClass, ifdesc->bInterfaceProtocol);
printf("\n"); printf("\n");
if (ifdesc->iInterface) { if (ifdesc->iInterface) {
printf(" - "); printf(" - ");
@ -197,13 +221,21 @@ void usb_display_if_desc(struct usb_interface_descriptor *ifdesc,struct usb_devi
void usb_display_ep_desc(struct usb_endpoint_descriptor *epdesc) void usb_display_ep_desc(struct usb_endpoint_descriptor *epdesc)
{ {
printf(" - Endpoint %d %s ",epdesc->bEndpointAddress & 0xf,(epdesc->bEndpointAddress & 0x80) ? "In" : "Out"); printf(" - Endpoint %d %s ", epdesc->bEndpointAddress & 0xf,
switch((epdesc->bmAttributes & 0x03)) (epdesc->bEndpointAddress & 0x80) ? "In" : "Out");
{ switch ((epdesc->bmAttributes & 0x03)) {
case 0: printf("Control"); break; case 0:
case 1: printf("Isochronous"); break; printf("Control");
case 2: printf("Bulk"); break; break;
case 3: printf("Interrupt"); break; case 1:
printf("Isochronous");
break;
case 2:
printf("Bulk");
break;
case 3:
printf("Interrupt");
break;
} }
printf(" MaxPacket %d", epdesc->wMaxPacketSize); printf(" MaxPacket %d", epdesc->wMaxPacketSize);
if ((epdesc->bmAttributes & 0x03) == 0x3) if ((epdesc->bmAttributes & 0x03) == 0x3)
@ -252,7 +284,9 @@ void usb_show_tree_graph(struct usb_device *dev,char *pre)
for (i = 0; i < dev->parent->maxchild; i++) { for (i = 0; i < dev->parent->maxchild; i++) {
/* search for children */ /* search for children */
if (dev->parent->children[i] == dev) { if (dev->parent->children[i] == dev) {
/* found our pointer, see if we have a little sister */ /* found our pointer, see if we have a
* little sister
*/
port = i; port = i;
while (i++ < dev->parent->maxchild) { while (i++ < dev->parent->maxchild) {
if (dev->parent->children[i] != NULL) { if (dev->parent->children[i] != NULL) {
@ -265,9 +299,8 @@ void usb_show_tree_graph(struct usb_device *dev,char *pre)
} /* for all children of the parent */ } /* for all children of the parent */
printf("\b+-"); printf("\b+-");
/* correct last child */ /* correct last child */
if (last_child) { if (last_child)
pre[index-1] = ' '; pre[index-1] = ' ';
}
} /* if not root hub */ } /* if not root hub */
else else
printf(" "); printf(" ");
@ -275,11 +308,11 @@ void usb_show_tree_graph(struct usb_device *dev,char *pre)
pre[index++] = ' '; pre[index++] = ' ';
pre[index++] = has_child ? '|' : ' '; pre[index++] = has_child ? '|' : ' ';
pre[index] = 0; pre[index] = 0;
printf(" %s (%s, %dmA)\n",usb_get_class_desc(dev->config.if_desc[0].bInterfaceClass), printf(" %s (%s, %dmA)\n", usb_get_class_desc(
dev->slow ? "1.5MBit/s" : "12MBit/s",dev->config.MaxPower * 2); dev->config.if_desc[0].bInterfaceClass),
if (strlen(dev->mf) || dev->slow ? "1.5MBit/s" : "12MBit/s",
strlen(dev->prod) || dev->config.MaxPower * 2);
strlen(dev->serial)) 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 %s %s %s\n", pre, dev->mf, dev->prod, dev->serial);
printf(" %s\n", pre); printf(" %s\n", pre);
if (dev->maxchild > 0) { if (dev->maxchild > 0) {
@ -362,15 +395,18 @@ int do_usbboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
if (get_partition_info(stor_dev, part, &info)) { if (get_partition_info(stor_dev, part, &info)) {
/* try to boot raw .... */ /* try to boot raw .... */
strncpy((char *)&info.type[0], BOOT_PART_TYPE, sizeof(BOOT_PART_TYPE)); strncpy((char *)&info.type[0], BOOT_PART_TYPE,
sizeof(BOOT_PART_TYPE));
strncpy((char *)&info.name[0], "Raw", 4); strncpy((char *)&info.name[0], "Raw", 4);
info.start = 0; info.start = 0;
info.blksz = 0x200; info.blksz = 0x200;
info.size = 2880; info.size = 2880;
printf("error reading partinfo...try to boot raw\n"); printf("error reading partinfo...try to boot raw\n");
} }
if ((strncmp((char *)info.type, BOOT_PART_TYPE, sizeof(info.type)) != 0) && if ((strncmp((char *)info.type, BOOT_PART_TYPE,
(strncmp((char *)info.type, BOOT_PART_COMP, sizeof(info.type)) != 0)) { sizeof(info.type)) != 0) &&
(strncmp((char *)info.type, BOOT_PART_COMP,
sizeof(info.type)) != 0)) {
printf("\n** Invalid partition type \"%.32s\"" printf("\n** Invalid partition type \"%.32s\""
" (expect \"" BOOT_PART_TYPE "\")\n", " (expect \"" BOOT_PART_TYPE "\")\n",
info.type); info.type);
@ -425,7 +461,9 @@ int do_usbboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
} }
#if defined(CONFIG_FIT) #if defined(CONFIG_FIT)
/* This cannot be done earlier, we need complete FIT image in RAM first */ /* This cannot be done earlier, we need complete FIT image in RAM
* first
*/
if (genimg_get_format((void *)addr) == IMAGE_FORMAT_FIT) { if (genimg_get_format((void *)addr) == IMAGE_FORMAT_FIT) {
if (!fit_check_format(fit_hdr)) { if (!fit_check_format(fit_hdr)) {
puts("** Bad FIT image format\n"); puts("** Bad FIT image format\n");
@ -455,7 +493,7 @@ int do_usbboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
#endif /* CONFIG_USB_STORAGE */ #endif /* CONFIG_USB_STORAGE */
/********************************************************************************* /******************************************************************************
* usb command intepreter * usb command intepreter
*/ */
int do_usb(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) int do_usb(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
@ -484,11 +522,12 @@ int do_usb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
#ifdef CONFIG_USB_KEYBOARD #ifdef CONFIG_USB_KEYBOARD
if (argc == 2) { if (argc == 2) {
if (usb_kbd_deregister() != 0) { if (usb_kbd_deregister() != 0) {
printf("USB not stopped: usbkbd still using USB\n"); printf("USB not stopped: usbkbd still"
" using USB\n");
return 1; return 1;
} }
} } else {
else { /* forced stop, switch console in to serial */ /* forced stop, switch console in to serial */
console_assign(stdin, "serial"); console_assign(stdin, "serial");
usb_kbd_deregister(); usb_kbd_deregister();
} }
@ -517,8 +556,7 @@ int do_usb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
usb_display_config(dev); usb_display_config(dev);
} }
return 0; return 0;
} } else {
else {
int d; int d;
i = simple_strtoul(argv[2], NULL, 16); i = simple_strtoul(argv[2], NULL, 16);
@ -533,8 +571,7 @@ int do_usb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
if (dev == NULL) { if (dev == NULL) {
printf("*** NO Device avaiable ***\n"); printf("*** NO Device avaiable ***\n");
return 0; return 0;
} } else {
else {
usb_display_desc(dev); usb_display_desc(dev);
usb_display_config(dev); usb_display_config(dev);
} }
@ -543,15 +580,16 @@ int do_usb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
} }
#ifdef CONFIG_USB_STORAGE #ifdef CONFIG_USB_STORAGE
if (strncmp(argv[1], "scan", 4) == 0) { if (strncmp(argv[1], "scan", 4) == 0) {
printf(" NOTE: this command is obsolete and will be phased out\n"); printf(" NOTE: this command is obsolete and will be"
printf(" please use 'usb storage' for USB storage devices information\n\n"); " phased out\n");
printf(" please use 'usb storage' for USB storage devices"
" information\n\n");
usb_stor_info(); usb_stor_info();
return 0; return 0;
} }
if (strncmp(argv[1], "stor", 4) == 0) { if (strncmp(argv[1], "stor", 4) == 0)
return usb_stor_info(); return usb_stor_info();
}
if (strncmp(argv[1], "part", 4) == 0) { if (strncmp(argv[1], "part", 4) == 0) {
int devno, ok = 0; int devno, ok = 0;
@ -566,8 +604,7 @@ int do_usb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
print_part(stor_dev); print_part(stor_dev);
} }
} }
} } else {
else {
devno = simple_strtoul(argv[2], NULL, 16); devno = simple_strtoul(argv[2], NULL, 16);
stor_dev = usb_stor_get_dev(devno); stor_dev = usb_stor_get_dev(devno);
if (stor_dev->type != DEV_TYPE_UNKNOWN) { if (stor_dev->type != DEV_TYPE_UNKNOWN) {
@ -592,11 +629,13 @@ int do_usb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
unsigned long blk = simple_strtoul(argv[3], NULL, 16); unsigned long blk = simple_strtoul(argv[3], NULL, 16);
unsigned long cnt = simple_strtoul(argv[4], NULL, 16); unsigned long cnt = simple_strtoul(argv[4], NULL, 16);
unsigned long n; unsigned long n;
printf ("\nUSB read: device %d block # %ld, count %ld ... ", printf("\nUSB read: device %d block # %ld, count %ld"
usb_stor_curr_dev, blk, cnt); " ... ", usb_stor_curr_dev, blk, cnt);
stor_dev = usb_stor_get_dev(usb_stor_curr_dev); stor_dev = usb_stor_get_dev(usb_stor_curr_dev);
n = stor_dev->block_read(usb_stor_curr_dev, blk, cnt, (ulong *)addr); n = stor_dev->block_read(usb_stor_curr_dev, blk, cnt,
printf ("%ld blocks read: %s\n",n,(n==cnt) ? "OK" : "ERROR"); (ulong *)addr);
printf("%ld blocks read: %s\n", n,
(n == cnt) ? "OK" : "ERROR");
if (n == cnt) if (n == cnt)
return 0; return 0;
return 1; return 1;
@ -613,20 +652,17 @@ int do_usb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
printf("\n Device %d: ", dev); printf("\n Device %d: ", dev);
stor_dev = usb_stor_get_dev(dev); stor_dev = usb_stor_get_dev(dev);
dev_print(stor_dev); dev_print(stor_dev);
if (stor_dev->type == DEV_TYPE_UNKNOWN) { if (stor_dev->type == DEV_TYPE_UNKNOWN)
return 1; return 1;
}
usb_stor_curr_dev = dev; usb_stor_curr_dev = dev;
printf("... is now current device\n"); printf("... is now current device\n");
return 0; return 0;
} } else {
else {
printf("\nUSB device %d: ", usb_stor_curr_dev); printf("\nUSB device %d: ", usb_stor_curr_dev);
stor_dev = usb_stor_get_dev(usb_stor_curr_dev); stor_dev = usb_stor_get_dev(usb_stor_curr_dev);
dev_print(stor_dev); dev_print(stor_dev);
if (stor_dev->type == DEV_TYPE_UNKNOWN) { if (stor_dev->type == DEV_TYPE_UNKNOWN)
return 1; return 1;
}
return 0; return 0;
} }
return 0; return 0;
@ -646,7 +682,8 @@ U_BOOT_CMD(
"usb info [dev] - show available USB devices\n" "usb info [dev] - show available USB devices\n"
"usb storage - show details of USB storage devices\n" "usb storage - show details of USB storage devices\n"
"usb dev [dev] - show or set current USB storage device\n" "usb dev [dev] - show or set current USB storage device\n"
"usb part [dev] - print partition table of one or all USB storage devices\n" "usb part [dev] - print partition table of one or all USB storage"
" devices\n"
"usb read addr blk# cnt - read `cnt' blocks starting at block `blk#'\n" "usb read addr blk# cnt - read `cnt' blocks starting at block `blk#'\n"
" to memory address `addr'\n" " to memory address `addr'\n"
); );

View File

@ -87,11 +87,12 @@ static int hub_port_reset(struct usb_device *dev, int port,
* wait_ms * wait_ms
*/ */
void __inline__ wait_ms(unsigned long ms) inline void wait_ms(unsigned long ms)
{ {
while (ms-- > 0) while (ms-- > 0)
udelay(1000); udelay(1000);
} }
/*************************************************************************** /***************************************************************************
* Init USB Device * Init USB Device
*/ */
@ -245,9 +246,9 @@ int usb_maxpacket(struct usb_device *dev, unsigned long pipe)
{ {
/* direction is out -> use emaxpacket out */ /* direction is out -> use emaxpacket out */
if ((pipe & USB_DIR_IN) == 0) if ((pipe & USB_DIR_IN) == 0)
return(dev->epmaxpacketout[((pipe>>15) & 0xf)]); return dev->epmaxpacketout[((pipe>>15) & 0xf)];
else else
return(dev->epmaxpacketin[((pipe>>15) & 0xf)]); 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
@ -793,7 +794,8 @@ int usb_new_device(struct usb_device *dev)
* reset of the device (Linux uses the same sequence) * reset of the device (Linux uses the same sequence)
* Some equipment is said to work only with such init sequence; this * Some equipment is said to work only with such init sequence; this
* patch is based on the work by Alan Stern: * patch is based on the work by Alan Stern:
* http://sourceforge.net/mailarchive/forum.php?thread_id=5729457&forum_id=5398 * http://sourceforge.net/mailarchive/forum.php?
* thread_id=5729457&forum_id=5398
*/ */
struct usb_device_descriptor *desc; struct usb_device_descriptor *desc;
int port = -1; int port = -1;
@ -847,10 +849,18 @@ int usb_new_device(struct usb_device *dev)
dev->epmaxpacketin[0] = dev->descriptor.bMaxPacketSize0; dev->epmaxpacketin[0] = dev->descriptor.bMaxPacketSize0;
dev->epmaxpacketout[0] = dev->descriptor.bMaxPacketSize0; dev->epmaxpacketout[0] = dev->descriptor.bMaxPacketSize0;
switch (dev->descriptor.bMaxPacketSize0) { switch (dev->descriptor.bMaxPacketSize0) {
case 8: dev->maxpacketsize = PACKET_SIZE_8; break; case 8:
case 16: dev->maxpacketsize = PACKET_SIZE_16; break; dev->maxpacketsize = PACKET_SIZE_8;
case 32: dev->maxpacketsize = PACKET_SIZE_32; break; break;
case 64: dev->maxpacketsize = PACKET_SIZE_64; break; case 16:
dev->maxpacketsize = PACKET_SIZE_16;
break;
case 32:
dev->maxpacketsize = PACKET_SIZE_32;
break;
case 64:
dev->maxpacketsize = PACKET_SIZE_64;
break;
} }
dev->devnum = addr; dev->devnum = addr;

View File

@ -57,7 +57,6 @@ struct devrequest {
unsigned short length; unsigned short length;
} __attribute__ ((packed)); } __attribute__ ((packed));
/* All standard descriptors have these 2 fields in common */ /* All standard descriptors have these 2 fields in common */
struct usb_descriptor_header { struct usb_descriptor_header {
unsigned char bLength; unsigned char bLength;
@ -82,7 +81,6 @@ struct usb_device_descriptor {
unsigned char bNumConfigurations; unsigned char bNumConfigurations;
} __attribute__ ((packed)); } __attribute__ ((packed));
/* Endpoint descriptor */ /* Endpoint descriptor */
struct usb_endpoint_descriptor { struct usb_endpoint_descriptor {
unsigned char bLength; unsigned char bLength;
@ -93,8 +91,8 @@ struct usb_endpoint_descriptor {
unsigned char bInterval; unsigned char bInterval;
unsigned char bRefresh; unsigned char bRefresh;
unsigned char bSynchAddress; unsigned char bSynchAddress;
} __attribute__ ((packed)); } __attribute__ ((packed));
/* Interface descriptor */ /* Interface descriptor */
struct usb_interface_descriptor { struct usb_interface_descriptor {
unsigned char bLength; unsigned char bLength;
@ -110,6 +108,7 @@ struct usb_interface_descriptor {
unsigned char no_of_ep; unsigned char no_of_ep;
unsigned char num_altsetting; unsigned char num_altsetting;
unsigned char act_altsetting; unsigned char act_altsetting;
struct usb_endpoint_descriptor ep_desc[USB_MAXENDPOINTS]; struct usb_endpoint_descriptor ep_desc[USB_MAXENDPOINTS];
} __attribute__ ((packed)); } __attribute__ ((packed));
@ -148,9 +147,10 @@ struct usb_device {
int maxpacketsize; int maxpacketsize;
/* one bit for each endpoint ([0] = IN, [1] = OUT) */ /* one bit for each endpoint ([0] = IN, [1] = OUT) */
unsigned int toggle[2]; unsigned int toggle[2];
/* endpoint halts; one bit per endpoint # & direction; */ /* endpoint halts; one bit per endpoint # & direction;
* [0] = IN, [1] = OUT
*/
unsigned int halted[2]; unsigned int halted[2];
/* [0] = IN, [1] = OUT */
int epmaxpacketin[16]; /* INput endpoint specific maximums */ int epmaxpacketin[16]; /* INput endpoint specific maximums */
int epmaxpacketout[16]; /* OUTput endpoint specific maximums */ int epmaxpacketout[16]; /* OUTput endpoint specific maximums */
@ -185,7 +185,8 @@ struct usb_device {
int usb_lowlevel_init(void); int usb_lowlevel_init(void);
int usb_lowlevel_stop(void); int usb_lowlevel_stop(void);
int submit_bulk_msg(struct usb_device *dev, unsigned long pipe, void *buffer,int transfer_len); int submit_bulk_msg(struct usb_device *dev, unsigned long pipe,
void *buffer, int transfer_len);
int submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer, int submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
int transfer_len, struct devrequest *setup); int transfer_len, struct devrequest *setup);
int submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer, int submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
@ -221,7 +222,8 @@ int usb_stop(void); /* stop the USB Controller */
int usb_set_protocol(struct usb_device *dev, int ifnum, int protocol); int usb_set_protocol(struct usb_device *dev, int ifnum, int protocol);
int usb_set_idle(struct usb_device *dev, int ifnum, int duration, int report_id); int usb_set_idle(struct usb_device *dev, int ifnum, int duration,
int report_id);
struct usb_device *usb_get_dev_index(int index); struct usb_device *usb_get_dev_index(int index);
int usb_control_msg(struct usb_device *dev, unsigned int pipe, int usb_control_msg(struct usb_device *dev, unsigned int pipe,
unsigned char request, unsigned char requesttype, unsigned char request, unsigned char requesttype,
@ -233,11 +235,14 @@ int usb_submit_int_msg(struct usb_device *dev, unsigned long pipe,
void *buffer, int transfer_len, int interval); void *buffer, int transfer_len, int interval);
void usb_disable_asynch(int disable); void usb_disable_asynch(int disable);
int usb_maxpacket(struct usb_device *dev, unsigned long pipe); int usb_maxpacket(struct usb_device *dev, unsigned long pipe);
void __inline__ wait_ms(unsigned long ms); inline void wait_ms(unsigned long ms);
int usb_get_configuration_no(struct usb_device *dev,unsigned char *buffer,int cfgno); int usb_get_configuration_no(struct usb_device *dev, unsigned char *buffer,
int usb_get_report(struct usb_device *dev, int ifnum, unsigned char type, unsigned char id, void *buf, int size); int cfgno);
int usb_get_report(struct usb_device *dev, int ifnum, unsigned char type,
unsigned char id, void *buf, int size);
int usb_get_class_descriptor(struct usb_device *dev, int ifnum, int usb_get_class_descriptor(struct usb_device *dev, int ifnum,
unsigned char type, unsigned char id, void *buf, int size); unsigned char type, unsigned char id, void *buf,
int size);
int usb_clear_halt(struct usb_device *dev, int pipe); int usb_clear_halt(struct usb_device *dev, int pipe);
int usb_string(struct usb_device *dev, int index, char *buf, size_t size); int usb_string(struct usb_device *dev, int index, char *buf, size_t size);
int usb_set_interface(struct usb_device *dev, int interface, int alternate); int usb_set_interface(struct usb_device *dev, int interface, int alternate);
@ -286,12 +291,14 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate);
* unsigned int. The encoding is: * unsigned int. The encoding is:
* *
* - max size: bits 0-1 (00 = 8, 01 = 16, 10 = 32, 11 = 64) * - max size: bits 0-1 (00 = 8, 01 = 16, 10 = 32, 11 = 64)
* - direction: bit 7 (0 = Host-to-Device [Out], 1 = Device-to-Host [In]) * - direction: bit 7 (0 = Host-to-Device [Out],
* (1 = Device-to-Host [In])
* - device: bits 8-14 * - device: bits 8-14
* - endpoint: bits 15-18 * - endpoint: bits 15-18
* - Data0/1: bit 19 * - Data0/1: bit 19
* - speed: bit 26 (0 = Full, 1 = Low Speed) * - speed: bit 26 (0 = Full, 1 = Low Speed)
* - pipe type: bits 30-31 (00 = isochronous, 01 = interrupt, 10 = control, 11 = bulk) * - pipe type: bits 30-31 (00 = isochronous, 01 = interrupt,
* 10 = control, 11 = bulk)
* *
* Why? Because it's arbitrary, and whatever encoding we select is really * Why? Because it's arbitrary, and whatever encoding we select is really
* up to us. This one happens to share a lot of bit positions with the UHCI * up to us. This one happens to share a lot of bit positions with the UHCI
@ -300,24 +307,42 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate);
*/ */
/* Create various pipes... */ /* Create various pipes... */
#define create_pipe(dev,endpoint) \ #define create_pipe(dev,endpoint) \
(((dev)->devnum << 8) | (endpoint << 15) | ((dev)->slow << 26) | (dev)->maxpacketsize) (((dev)->devnum << 8) | (endpoint << 15) | \
((dev)->slow << 26) | (dev)->maxpacketsize)
#define default_pipe(dev) ((dev)->slow << 26) #define default_pipe(dev) ((dev)->slow << 26)
#define usb_sndctrlpipe(dev,endpoint) ((PIPE_CONTROL << 30) | create_pipe(dev,endpoint)) #define usb_sndctrlpipe(dev, endpoint) ((PIPE_CONTROL << 30) | \
#define usb_rcvctrlpipe(dev,endpoint) ((PIPE_CONTROL << 30) | create_pipe(dev,endpoint) | USB_DIR_IN) create_pipe(dev, endpoint))
#define usb_sndisocpipe(dev,endpoint) ((PIPE_ISOCHRONOUS << 30) | create_pipe(dev,endpoint)) #define usb_rcvctrlpipe(dev, endpoint) ((PIPE_CONTROL << 30) | \
#define usb_rcvisocpipe(dev,endpoint) ((PIPE_ISOCHRONOUS << 30) | create_pipe(dev,endpoint) | USB_DIR_IN) create_pipe(dev, endpoint) | \
#define usb_sndbulkpipe(dev,endpoint) ((PIPE_BULK << 30) | create_pipe(dev,endpoint)) USB_DIR_IN)
#define usb_rcvbulkpipe(dev,endpoint) ((PIPE_BULK << 30) | create_pipe(dev,endpoint) | USB_DIR_IN) #define usb_sndisocpipe(dev, endpoint) ((PIPE_ISOCHRONOUS << 30) | \
#define usb_sndintpipe(dev,endpoint) ((PIPE_INTERRUPT << 30) | create_pipe(dev,endpoint)) create_pipe(dev, endpoint))
#define usb_rcvintpipe(dev,endpoint) ((PIPE_INTERRUPT << 30) | create_pipe(dev,endpoint) | USB_DIR_IN) #define usb_rcvisocpipe(dev, endpoint) ((PIPE_ISOCHRONOUS << 30) | \
#define usb_snddefctrl(dev) ((PIPE_CONTROL << 30) | default_pipe(dev)) create_pipe(dev, endpoint) | \
#define usb_rcvdefctrl(dev) ((PIPE_CONTROL << 30) | default_pipe(dev) | USB_DIR_IN) USB_DIR_IN)
#define usb_sndbulkpipe(dev, endpoint) ((PIPE_BULK << 30) | \
create_pipe(dev, endpoint))
#define usb_rcvbulkpipe(dev, endpoint) ((PIPE_BULK << 30) | \
create_pipe(dev, endpoint) | \
USB_DIR_IN)
#define usb_sndintpipe(dev, endpoint) ((PIPE_INTERRUPT << 30) | \
create_pipe(dev, endpoint))
#define usb_rcvintpipe(dev, endpoint) ((PIPE_INTERRUPT << 30) | \
create_pipe(dev, endpoint) | \
USB_DIR_IN)
#define usb_snddefctrl(dev) ((PIPE_CONTROL << 30) | \
default_pipe(dev))
#define usb_rcvdefctrl(dev) ((PIPE_CONTROL << 30) | \
default_pipe(dev) | \
USB_DIR_IN)
/* The D0/D1 toggle bits */ /* The D0/D1 toggle bits */
#define usb_gettoggle(dev, ep, out) (((dev)->toggle[out] >> ep) & 1) #define usb_gettoggle(dev, ep, out) (((dev)->toggle[out] >> ep) & 1)
#define usb_dotoggle(dev, ep, out) ((dev)->toggle[out] ^= (1 << ep)) #define usb_dotoggle(dev, ep, out) ((dev)->toggle[out] ^= (1 << ep))
#define usb_settoggle(dev, ep, out, bit) ((dev)->toggle[out] = ((dev)->toggle[out] & ~(1 << ep)) | ((bit) << ep)) #define usb_settoggle(dev, ep, out, bit) ((dev)->toggle[out] = \
((dev)->toggle[out] & \
~(1 << ep)) | ((bit) << ep))
/* Endpoint halt control/status */ /* Endpoint halt control/status */
#define usb_endpoint_out(ep_dir) (((ep_dir >> 7) & 1) ^ 1) #define usb_endpoint_out(ep_dir) (((ep_dir >> 7) & 1) ^ 1)
@ -325,7 +350,8 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate);
#define usb_endpoint_running(dev, ep, out) ((dev)->halted[out] &= ~(1 << (ep))) #define usb_endpoint_running(dev, ep, out) ((dev)->halted[out] &= ~(1 << (ep)))
#define usb_endpoint_halted(dev, ep, out) ((dev)->halted[out] & (1 << (ep))) #define usb_endpoint_halted(dev, ep, out) ((dev)->halted[out] & (1 << (ep)))
#define usb_packetid(pipe) (((pipe) & USB_DIR_IN) ? USB_PID_IN : USB_PID_OUT) #define usb_packetid(pipe) (((pipe) & USB_DIR_IN) ? USB_PID_IN : \
USB_PID_OUT)
#define usb_pipeout(pipe) ((((pipe) >> 7) & 1) ^ 1) #define usb_pipeout(pipe) ((((pipe) >> 7) & 1) ^ 1)
#define usb_pipein(pipe) (((pipe) >> 7) & 1) #define usb_pipein(pipe) (((pipe) >> 7) & 1)