Commit 6f5794a6f78b313231256958fd73673c6aacc116

Authored by Remy Bohmer
Committed by Markus Klotzbuecher
1 parent be19d324ed

Refactoring parts of the common USB OHCI code

This patch refactors some large routines of the USB OHCI code by
making some routines smaller and more readable which helps
debugging and understanding the code. (Makes the code looks
somewhat more like the Linux implementation.)

Also made entire file compliant to Linux Coding Rules (checkpatch.pl compliant)

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: Markus Klotzbuecher <mk@denx.de>

Showing 3 changed files with 862 additions and 687 deletions Side-by-side Diff

Changes suppressed. Click to show
... ... @@ -58,9 +58,9 @@
58 58 #undef USB_DEBUG
59 59  
60 60 #ifdef USB_DEBUG
61   -#define USB_PRINTF(fmt,args...) printf (fmt ,##args)
  61 +#define USB_PRINTF(fmt, args...) printf (fmt , ##args)
62 62 #else
63   -#define USB_PRINTF(fmt,args...)
  63 +#define USB_PRINTF(fmt, args...)
64 64 #endif
65 65  
66 66 #define USB_BUFSIZ 512
... ... @@ -88,7 +88,7 @@
88 88  
89 89 void __inline__ wait_ms(unsigned long ms)
90 90 {
91   - while(ms-->0)
  91 + while (ms-- > 0)
92 92 udelay(1000);
93 93 }
94 94 /***************************************************************************
95 95  
96 96  
97 97  
... ... @@ -99,22 +99,22 @@
99 99 {
100 100 int result;
101 101  
102   - running=0;
103   - dev_index=0;
104   - asynch_allowed=1;
  102 + running = 0;
  103 + dev_index = 0;
  104 + asynch_allowed = 1;
105 105 usb_hub_reset();
106 106 /* init low_level USB */
107 107 printf("USB: ");
108 108 result = usb_lowlevel_init();
109   - /* if lowlevel init is OK, scan the bus for devices i.e. search HUBs and configure them */
110   - if(result==0) {
  109 + /* if lowlevel init is OK, scan the bus for devices
  110 + * i.e. search HUBs and configure them */
  111 + if (result == 0) {
111 112 printf("scanning bus for devices... ");
112   - running=1;
  113 + running = 1;
113 114 usb_scan_devices();
114 115 usb_started = 1;
115 116 return 0;
116   - }
117   - else {
  117 + } else {
118 118 printf("Error, couldn't init Lowlevel part\n");
119 119 usb_started = 0;
120 120 return -1;
... ... @@ -143,7 +143,7 @@
143 143 */
144 144 void usb_disable_asynch(int disable)
145 145 {
146   - asynch_allowed=!disable;
  146 + asynch_allowed = !disable;
147 147 }
148 148  
149 149  
150 150  
... ... @@ -156,9 +156,9 @@
156 156 * submits an Interrupt Message
157 157 */
158 158 int usb_submit_int_msg(struct usb_device *dev, unsigned long pipe,
159   - void *buffer,int transfer_len, int interval)
  159 + void *buffer, int transfer_len, int interval)
160 160 {
161   - return submit_int_msg(dev,pipe,buffer,transfer_len,interval);
  161 + return submit_int_msg(dev, pipe, buffer, transfer_len, interval);
162 162 }
163 163  
164 164 /*
165 165  
... ... @@ -175,8 +175,10 @@
175 175 unsigned short value, unsigned short index,
176 176 void *data, unsigned short size, int timeout)
177 177 {
178   - if((timeout==0)&&(!asynch_allowed)) /* request for a asynch control pipe is not allowed */
  178 + if ((timeout == 0) && (!asynch_allowed)) {
  179 + /* request for a asynch control pipe is not allowed */
179 180 return -1;
  181 + }
180 182  
181 183 /* set setup command */
182 184 setup_packet.requesttype = requesttype;
183 185  
184 186  
185 187  
186 188  
187 189  
... ... @@ -184,24 +186,24 @@
184 186 setup_packet.value = cpu_to_le16(value);
185 187 setup_packet.index = cpu_to_le16(index);
186 188 setup_packet.length = cpu_to_le16(size);
187   - USB_PRINTF("usb_control_msg: request: 0x%X, requesttype: 0x%X, value 0x%X index 0x%X length 0x%X\n",
188   - request,requesttype,value,index,size);
189   - dev->status=USB_ST_NOT_PROC; /*not yet processed */
  189 + USB_PRINTF("usb_control_msg: request: 0x%X, requesttype: 0x%X, " \
  190 + "value 0x%X index 0x%X length 0x%X\n",
  191 + request, requesttype, value, index, size);
  192 + dev->status = USB_ST_NOT_PROC; /*not yet processed */
190 193  
191   - submit_control_msg(dev,pipe,data,size,&setup_packet);
192   - if(timeout==0) {
  194 + submit_control_msg(dev, pipe, data, size, &setup_packet);
  195 + if (timeout == 0)
193 196 return (int)size;
194   - }
195   - while(timeout--) {
196   - if(!((volatile unsigned long)dev->status & USB_ST_NOT_PROC))
  197 +
  198 + while (timeout--) {
  199 + if (!((volatile unsigned long)dev->status & USB_ST_NOT_PROC))
197 200 break;
198 201 wait_ms(1);
199 202 }
200   - if(dev->status==0)
  203 + if (dev->status == 0)
201 204 return dev->act_len;
202   - else {
  205 + else
203 206 return -1;
204   - }
205 207 }
206 208  
207 209 /*-------------------------------------------------------------------
208 210  
... ... @@ -214,15 +216,15 @@
214 216 {
215 217 if (len < 0)
216 218 return -1;
217   - dev->status=USB_ST_NOT_PROC; /*not yet processed */
218   - submit_bulk_msg(dev,pipe,data,len);
219   - while(timeout--) {
220   - if(!((volatile unsigned long)dev->status & USB_ST_NOT_PROC))
  219 + dev->status = USB_ST_NOT_PROC; /*not yet processed */
  220 + submit_bulk_msg(dev, pipe, data, len);
  221 + while (timeout--) {
  222 + if (!((volatile unsigned long)dev->status & USB_ST_NOT_PROC))
221 223 break;
222 224 wait_ms(1);
223 225 }
224   - *actual_length=dev->act_len;
225   - if(dev->status==0)
  226 + *actual_length = dev->act_len;
  227 + if (dev->status == 0)
226 228 return 0;
227 229 else
228 230 return -1;
229 231  
... ... @@ -237,9 +239,10 @@
237 239 * returns the max packet size, depending on the pipe direction and
238 240 * the configurations values
239 241 */
240   -int usb_maxpacket(struct usb_device *dev,unsigned long pipe)
  242 +int usb_maxpacket(struct usb_device *dev, unsigned long pipe)
241 243 {
242   - if((pipe & USB_DIR_IN)==0) /* direction is out -> use emaxpacket out */
  244 + /* direction is out -> use emaxpacket out */
  245 + if ((pipe & USB_DIR_IN) == 0)
243 246 return(dev->epmaxpacketout[((pipe>>15) & 0xf)]);
244 247 else
245 248 return(dev->epmaxpacketin[((pipe>>15) & 0xf)]);
... ... @@ -318,8 +321,9 @@
318 321  
319 322 dev->configno = cfgno;
320 323 head = (struct usb_descriptor_header *) &buffer[0];
321   - if(head->bDescriptorType != USB_DT_CONFIG) {
322   - printf(" ERROR: NOT USB_CONFIG_DESC %x\n", head->bDescriptorType);
  324 + if (head->bDescriptorType != USB_DT_CONFIG) {
  325 + printf(" ERROR: NOT USB_CONFIG_DESC %x\n",
  326 + head->bDescriptorType);
323 327 return -1;
324 328 }
325 329 memcpy(&dev->config, buffer, buffer[0]);
326 330  
327 331  
... ... @@ -327,45 +331,52 @@
327 331 dev->config.no_of_if = 0;
328 332  
329 333 index = dev->config.bLength;
330   - /* Ok the first entry must be a configuration entry, now process the others */
  334 + /* Ok the first entry must be a configuration entry,
  335 + * now process the others */
331 336 head = (struct usb_descriptor_header *) &buffer[index];
332   - while(index + 1 < dev->config.wTotalLength) {
333   - switch(head->bDescriptorType) {
334   - case USB_DT_INTERFACE:
335   - if(((struct usb_interface_descriptor *) &buffer[index])->
336   - bInterfaceNumber != curr_if_num) {
337   - /* this is a new interface, copy new desc */
338   - ifno = dev->config.no_of_if;
339   - dev->config.no_of_if++;
340   - memcpy(&dev->config.if_desc[ifno],
341   - &buffer[index], buffer[index]);
342   - dev->config.if_desc[ifno].no_of_ep = 0;
343   - dev->config.if_desc[ifno].num_altsetting = 1;
344   - curr_if_num = dev->config.if_desc[ifno].bInterfaceNumber;
345   - } else {
346   - /* found alternate setting for the interface */
347   - dev->config.if_desc[ifno].num_altsetting++;
348   - }
349   - break;
350   - case USB_DT_ENDPOINT:
351   - epno = dev->config.if_desc[ifno].no_of_ep;
352   - dev->config.if_desc[ifno].no_of_ep++; /* found an endpoint */
353   - memcpy(&dev->config.if_desc[ifno].ep_desc[epno],
  337 + while (index + 1 < dev->config.wTotalLength) {
  338 + switch (head->bDescriptorType) {
  339 + case USB_DT_INTERFACE:
  340 + if (((struct usb_interface_descriptor *) \
  341 + &buffer[index])->bInterfaceNumber != curr_if_num) {
  342 + /* this is a new interface, copy new desc */
  343 + ifno = dev->config.no_of_if;
  344 + dev->config.no_of_if++;
  345 + memcpy(&dev->config.if_desc[ifno],
354 346 &buffer[index], buffer[index]);
355   - le16_to_cpus(&(dev->config.if_desc[ifno].ep_desc[epno].wMaxPacketSize));
356   - USB_PRINTF("if %d, ep %d\n", ifno, epno);
357   - break;
358   - default:
359   - if(head->bLength == 0)
360   - return 1;
361   - USB_PRINTF("unknown Description Type : %x\n", head->bDescriptorType);
362   - {
363   - ch = (unsigned char *)head;
364   - for(i = 0; i < head->bLength; i++)
365   - USB_PRINTF("%02X ", *ch++);
366   - USB_PRINTF("\n\n\n");
367   - }
368   - break;
  347 + dev->config.if_desc[ifno].no_of_ep = 0;
  348 + dev->config.if_desc[ifno].num_altsetting = 1;
  349 + curr_if_num =
  350 + dev->config.if_desc[ifno].bInterfaceNumber;
  351 + } else {
  352 + /* found alternate setting for the interface */
  353 + dev->config.if_desc[ifno].num_altsetting++;
  354 + }
  355 + break;
  356 + case USB_DT_ENDPOINT:
  357 + epno = dev->config.if_desc[ifno].no_of_ep;
  358 + /* found an endpoint */
  359 + dev->config.if_desc[ifno].no_of_ep++;
  360 + memcpy(&dev->config.if_desc[ifno].ep_desc[epno],
  361 + &buffer[index], buffer[index]);
  362 + le16_to_cpus(&(dev->config.if_desc[ifno].ep_desc[epno].\
  363 + wMaxPacketSize));
  364 + USB_PRINTF("if %d, ep %d\n", ifno, epno);
  365 + break;
  366 + default:
  367 + if (head->bLength == 0)
  368 + return 1;
  369 +
  370 + USB_PRINTF("unknown Description Type : %x\n",
  371 + head->bDescriptorType);
  372 +
  373 + {
  374 + ch = (unsigned char *)head;
  375 + for (i = 0; i < head->bLength; i++)
  376 + USB_PRINTF("%02X ", *ch++);
  377 + USB_PRINTF("\n\n\n");
  378 + }
  379 + break;
369 380 }
370 381 index += head->bLength;
371 382 head = (struct usb_descriptor_header *)&buffer[index];
... ... @@ -384,7 +395,8 @@
384 395 int endp = usb_pipeendpoint(pipe)|(usb_pipein(pipe)<<7);
385 396  
386 397 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
387   - USB_REQ_CLEAR_FEATURE, USB_RECIP_ENDPOINT, 0, endp, NULL, 0, USB_CNTL_TIMEOUT * 3);
  398 + USB_REQ_CLEAR_FEATURE, USB_RECIP_ENDPOINT, 0,
  399 + endp, NULL, 0, USB_CNTL_TIMEOUT * 3);
388 400  
389 401 /* don't clear if failed */
390 402 if (result < 0)
... ... @@ -406,7 +418,8 @@
406 418 /**********************************************************************
407 419 * get_descriptor type
408 420 */
409   -int usb_get_descriptor(struct usb_device *dev, unsigned char type, unsigned char index, void *buf, int size)
  421 +int usb_get_descriptor(struct usb_device *dev, unsigned char type,
  422 + unsigned char index, void *buf, int size)
410 423 {
411 424 int res;
412 425 res = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
413 426  
414 427  
415 428  
416 429  
417 430  
... ... @@ -419,32 +432,36 @@
419 432 /**********************************************************************
420 433 * gets configuration cfgno and store it in the buffer
421 434 */
422   -int usb_get_configuration_no(struct usb_device *dev,unsigned char *buffer,int cfgno)
  435 +int usb_get_configuration_no(struct usb_device *dev,
  436 + unsigned char *buffer, int cfgno)
423 437 {
424 438 int result;
425 439 unsigned int tmp;
426 440 struct usb_config_descriptor *config;
427 441  
428 442  
429   - config=(struct usb_config_descriptor *)&buffer[0];
  443 + config = (struct usb_config_descriptor *)&buffer[0];
430 444 result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno, buffer, 8);
431 445 if (result < 8) {
432 446 if (result < 0)
433   - printf("unable to get descriptor, error %lX\n",dev->status);
  447 + printf("unable to get descriptor, error %lX\n",
  448 + dev->status);
434 449 else
435   - printf("config descriptor too short (expected %i, got %i)\n",8,result);
  450 + printf("config descriptor too short " \
  451 + "(expected %i, got %i)\n", 8, result);
436 452 return -1;
437 453 }
438 454 tmp = le16_to_cpu(config->wTotalLength);
439 455  
440 456 if (tmp > USB_BUFSIZ) {
441   - USB_PRINTF("usb_get_configuration_no: failed to get descriptor - too long: %d\n",
442   - tmp);
  457 + USB_PRINTF("usb_get_configuration_no: failed to get " \
  458 + "descriptor - too long: %d\n", tmp);
443 459 return -1;
444 460 }
445 461  
446 462 result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno, buffer, tmp);
447   - USB_PRINTF("get_conf_no %d Result %d, wLength %d\n",cfgno,result,tmp);
  463 + USB_PRINTF("get_conf_no %d Result %d, wLength %d\n",
  464 + cfgno, result, tmp);
448 465 return result;
449 466 }
450 467  
... ... @@ -456,11 +473,11 @@
456 473 {
457 474 int res;
458 475  
459   - USB_PRINTF("set address %d\n",dev->devnum);
460   - res=usb_control_msg(dev, usb_snddefctrl(dev),
461   - USB_REQ_SET_ADDRESS, 0,
462   - (dev->devnum),0,
463   - NULL,0, USB_CNTL_TIMEOUT);
  476 + USB_PRINTF("set address %d\n", dev->devnum);
  477 + res = usb_control_msg(dev, usb_snddefctrl(dev),
  478 + USB_REQ_SET_ADDRESS, 0,
  479 + (dev->devnum), 0,
  480 + NULL, 0, USB_CNTL_TIMEOUT);
464 481 return res;
465 482 }
466 483  
467 484  
... ... @@ -484,16 +501,19 @@
484 501 }
485 502 /*
486 503 * We should return now for devices with only one alternate setting.
487   - * According to 9.4.10 of the Universal Serial Bus Specification Revision 2.0
488   - * such devices can return with a STALL. This results in some USB sticks
489   - * timeouting during initialization and then being unusable in U-Boot.
  504 + * According to 9.4.10 of the Universal Serial Bus Specification
  505 + * Revision 2.0 such devices can return with a STALL. This results in
  506 + * some USB sticks timeouting during initialization and then being
  507 + * unusable in U-Boot.
490 508 */
491 509 if (if_face->num_altsetting == 1)
492 510 return 0;
493 511  
494   - if ((ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
495   - USB_REQ_SET_INTERFACE, USB_RECIP_INTERFACE, alternate,
496   - interface, NULL, 0, USB_CNTL_TIMEOUT * 5)) < 0)
  512 + ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
  513 + USB_REQ_SET_INTERFACE, USB_RECIP_INTERFACE,
  514 + alternate, interface, NULL, 0,
  515 + USB_CNTL_TIMEOUT * 5);
  516 + if (ret < 0)
497 517 return ret;
498 518  
499 519 return 0;
500 520  
501 521  
... ... @@ -505,18 +525,17 @@
505 525 int usb_set_configuration(struct usb_device *dev, int configuration)
506 526 {
507 527 int res;
508   - USB_PRINTF("set configuration %d\n",configuration);
  528 + USB_PRINTF("set configuration %d\n", configuration);
509 529 /* set setup command */
510   - res=usb_control_msg(dev, usb_sndctrlpipe(dev,0),
511   - USB_REQ_SET_CONFIGURATION, 0,
512   - configuration,0,
513   - NULL,0, USB_CNTL_TIMEOUT);
514   - if(res==0) {
  530 + res = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
  531 + USB_REQ_SET_CONFIGURATION, 0,
  532 + configuration, 0,
  533 + NULL, 0, USB_CNTL_TIMEOUT);
  534 + if (res == 0) {
515 535 dev->toggle[0] = 0;
516 536 dev->toggle[1] = 0;
517 537 return 0;
518   - }
519   - else
  538 + } else
520 539 return -1;
521 540 }
522 541  
523 542  
... ... @@ -543,11 +562,13 @@
543 562 /********************************************************************
544 563 * get report
545 564 */
546   -int usb_get_report(struct usb_device *dev, int ifnum, unsigned char type, unsigned char id, void *buf, int size)
  565 +int usb_get_report(struct usb_device *dev, int ifnum, unsigned char type,
  566 + unsigned char id, void *buf, int size)
547 567 {
548 568 return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
549   - USB_REQ_GET_REPORT, USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
550   - (type << 8) + id, ifnum, buf, size, USB_CNTL_TIMEOUT);
  569 + USB_REQ_GET_REPORT,
  570 + USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
  571 + (type << 8) + id, ifnum, buf, size, USB_CNTL_TIMEOUT);
551 572 }
552 573  
553 574 /********************************************************************
... ... @@ -564,7 +585,8 @@
564 585 /********************************************************************
565 586 * get string index in buffer
566 587 */
567   -int usb_get_string(struct usb_device *dev, unsigned short langid, unsigned char index, void *buf, int size)
  588 +int usb_get_string(struct usb_device *dev, unsigned short langid,
  589 + unsigned char index, void *buf, int size)
568 590 {
569 591 int i;
570 592 int result;
571 593  
572 594  
... ... @@ -655,17 +677,19 @@
655 677 if (!dev->have_langid) {
656 678 err = usb_string_sub(dev, 0, 0, tbuf);
657 679 if (err < 0) {
658   - USB_PRINTF("error getting string descriptor 0 (error=%x)\n",dev->status);
  680 + USB_PRINTF("error getting string descriptor 0 " \
  681 + "(error=%x)\n", dev->status);
659 682 return -1;
660 683 } else if (tbuf[0] < 4) {
661 684 USB_PRINTF("string descriptor 0 too short\n");
662 685 return -1;
663 686 } else {
664 687 dev->have_langid = -1;
665   - dev->string_langid = tbuf[2] | (tbuf[3]<< 8);
  688 + dev->string_langid = tbuf[2] | (tbuf[3] << 8);
666 689 /* always use the first langid listed */
667   - USB_PRINTF("USB device number %d default language ID 0x%x\n",
668   - dev->devnum, dev->string_langid);
  690 + USB_PRINTF("USB device number %d default " \
  691 + "language ID 0x%x\n",
  692 + dev->devnum, dev->string_langid);
669 693 }
670 694 }
671 695  
672 696  
... ... @@ -697,9 +721,9 @@
697 721 /* returns a pointer to the device with the index [index].
698 722 * if the device is not assigned (dev->devnum==-1) returns NULL
699 723 */
700   -struct usb_device * usb_get_dev_index(int index)
  724 +struct usb_device *usb_get_dev_index(int index)
701 725 {
702   - if(usb_dev[index].devnum==-1)
  726 + if (usb_dev[index].devnum == -1)
703 727 return NULL;
704 728 else
705 729 return &usb_dev[index];
706 730  
707 731  
708 732  
... ... @@ -709,21 +733,22 @@
709 733 /* returns a pointer of a new device structure or NULL, if
710 734 * no device struct is available
711 735 */
712   -struct usb_device * usb_alloc_new_device(void)
  736 +struct usb_device *usb_alloc_new_device(void)
713 737 {
714 738 int i;
715   - USB_PRINTF("New Device %d\n",dev_index);
716   - if(dev_index==USB_MAX_DEVICE) {
717   - printf("ERROR, too many USB Devices, max=%d\n",USB_MAX_DEVICE);
  739 + USB_PRINTF("New Device %d\n", dev_index);
  740 + if (dev_index == USB_MAX_DEVICE) {
  741 + printf("ERROR, too many USB Devices, max=%d\n", USB_MAX_DEVICE);
718 742 return NULL;
719 743 }
720   - usb_dev[dev_index].devnum=dev_index+1; /* default Address is 0, real addresses start with 1 */
721   - usb_dev[dev_index].maxchild=0;
722   - for(i=0;i<USB_MAXCHILDREN;i++)
723   - usb_dev[dev_index].children[i]=NULL;
724   - usb_dev[dev_index].parent=NULL;
  744 + /* default Address is 0, real addresses start with 1 */
  745 + usb_dev[dev_index].devnum = dev_index + 1;
  746 + usb_dev[dev_index].maxchild = 0;
  747 + for (i = 0; i < USB_MAXCHILDREN; i++)
  748 + usb_dev[dev_index].children[i] = NULL;
  749 + usb_dev[dev_index].parent = NULL;
725 750 dev_index++;
726   - return &usb_dev[dev_index-1];
  751 + return &usb_dev[dev_index - 1];
727 752 }
728 753  
729 754  
... ... @@ -788,7 +813,7 @@
788 813 }
789 814 }
790 815 if (port < 0) {
791   - printf("usb_new_device: cannot locate device's port..\n");
  816 + printf("usb_new_device:cannot locate device's port.\n");
792 817 return 1;
793 818 }
794 819  
... ... @@ -803,7 +828,8 @@
803 828 /* and this is the old and known way of initializing devices */
804 829 err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, &dev->descriptor, 8);
805 830 if (err < 8) {
806   - printf("\n USB device not responding, giving up (status=%lX)\n",dev->status);
  831 + printf("\n USB device not responding, " \
  832 + "giving up (status=%lX)\n", dev->status);
807 833 return 1;
808 834 }
809 835 #endif
810 836  
... ... @@ -811,17 +837,18 @@
811 837 dev->epmaxpacketin [0] = dev->descriptor.bMaxPacketSize0;
812 838 dev->epmaxpacketout[0] = dev->descriptor.bMaxPacketSize0;
813 839 switch (dev->descriptor.bMaxPacketSize0) {
814   - case 8: dev->maxpacketsize = 0; break;
815   - case 16: dev->maxpacketsize = 1; break;
816   - case 32: dev->maxpacketsize = 2; break;
817   - case 64: dev->maxpacketsize = 3; break;
  840 + case 8: dev->maxpacketsize = 0; break;
  841 + case 16: dev->maxpacketsize = 1; break;
  842 + case 32: dev->maxpacketsize = 2; break;
  843 + case 64: dev->maxpacketsize = 3; break;
818 844 }
819 845 dev->devnum = addr;
820 846  
821 847 err = usb_set_address(dev); /* set address */
822 848  
823 849 if (err < 0) {
824   - printf("\n USB device not accepting new address (error=%lX)\n", dev->status);
  850 + printf("\n USB device not accepting new address " \
  851 + "(error=%lX)\n", dev->status);
825 852 return 1;
826 853 }
827 854  
828 855  
829 856  
... ... @@ -829,12 +856,15 @@
829 856  
830 857 tmp = sizeof(dev->descriptor);
831 858  
832   - err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, &dev->descriptor, sizeof(dev->descriptor));
  859 + err = usb_get_descriptor(dev, USB_DT_DEVICE, 0,
  860 + &dev->descriptor, sizeof(dev->descriptor));
833 861 if (err < tmp) {
834 862 if (err < 0)
835   - printf("unable to get device descriptor (error=%d)\n",err);
  863 + printf("unable to get device descriptor (error=%d)\n",
  864 + err);
836 865 else
837   - printf("USB device descriptor short read (expected %i, got %i)\n",tmp,err);
  866 + printf("USB device descriptor short read " \
  867 + "(expected %i, got %i)\n", tmp, err);
838 868 return 1;
839 869 }
840 870 /* correct le values */
841 871  
842 872  
843 873  
844 874  
845 875  
846 876  
... ... @@ -843,30 +873,35 @@
843 873 le16_to_cpus(&dev->descriptor.idProduct);
844 874 le16_to_cpus(&dev->descriptor.bcdDevice);
845 875 /* only support for one config for now */
846   - usb_get_configuration_no(dev,&tmpbuf[0],0);
847   - usb_parse_config(dev,&tmpbuf[0],0);
  876 + usb_get_configuration_no(dev, &tmpbuf[0], 0);
  877 + usb_parse_config(dev, &tmpbuf[0], 0);
848 878 usb_set_maxpacket(dev);
849 879 /* we set the default configuration here */
850 880 if (usb_set_configuration(dev, dev->config.bConfigurationValue)) {
851   - printf("failed to set default configuration len %d, status %lX\n",dev->act_len,dev->status);
  881 + printf("failed to set default configuration " \
  882 + "len %d, status %lX\n", dev->act_len, dev->status);
852 883 return -1;
853 884 }
854 885 USB_PRINTF("new device strings: Mfr=%d, Product=%d, SerialNumber=%d\n",
855   - dev->descriptor.iManufacturer, dev->descriptor.iProduct, dev->descriptor.iSerialNumber);
  886 + dev->descriptor.iManufacturer, dev->descriptor.iProduct,
  887 + dev->descriptor.iSerialNumber);
856 888 memset(dev->mf, 0, sizeof(dev->mf));
857 889 memset(dev->prod, 0, sizeof(dev->prod));
858 890 memset(dev->serial, 0, sizeof(dev->serial));
859 891 if (dev->descriptor.iManufacturer)
860   - usb_string(dev, dev->descriptor.iManufacturer, dev->mf, sizeof(dev->mf));
  892 + usb_string(dev, dev->descriptor.iManufacturer,
  893 + dev->mf, sizeof(dev->mf));
861 894 if (dev->descriptor.iProduct)
862   - usb_string(dev, dev->descriptor.iProduct, dev->prod, sizeof(dev->prod));
  895 + usb_string(dev, dev->descriptor.iProduct,
  896 + dev->prod, sizeof(dev->prod));
863 897 if (dev->descriptor.iSerialNumber)
864   - usb_string(dev, dev->descriptor.iSerialNumber, dev->serial, sizeof(dev->serial));
  898 + usb_string(dev, dev->descriptor.iSerialNumber,
  899 + dev->serial, sizeof(dev->serial));
865 900 USB_PRINTF("Manufacturer %s\n", dev->mf);
866 901 USB_PRINTF("Product %s\n", dev->prod);
867 902 USB_PRINTF("SerialNumber %s\n", dev->serial);
868 903 /* now prode if the device is a hub */
869   - usb_hub_probe(dev,0);
  904 + usb_hub_probe(dev, 0);
870 905 return 0;
871 906 }
872 907  
873 908  
874 909  
875 910  
... ... @@ -877,15 +912,15 @@
877 912 struct usb_device *dev;
878 913  
879 914 /* first make all devices unknown */
880   - for(i=0;i<USB_MAX_DEVICE;i++) {
881   - memset(&usb_dev[i],0,sizeof(struct usb_device));
  915 + for (i = 0; i < USB_MAX_DEVICE; i++) {
  916 + memset(&usb_dev[i], 0, sizeof(struct usb_device));
882 917 usb_dev[i].devnum = -1;
883 918 }
884   - dev_index=0;
  919 + dev_index = 0;
885 920 /* device 0 is always present (root hub, so let it analyze) */
886   - dev=usb_alloc_new_device();
  921 + dev = usb_alloc_new_device();
887 922 usb_new_device(dev);
888   - printf("%d USB Device(s) found\n",dev_index);
  923 + printf("%d USB Device(s) found\n", dev_index);
889 924 /* insert "driver" if possible */
890 925 #ifdef CONFIG_USB_KEYBOARD
891 926 drv_usb_kbd_init();
892 927  
... ... @@ -902,9 +937,9 @@
902 937 #undef USB_HUB_DEBUG
903 938  
904 939 #ifdef USB_HUB_DEBUG
905   -#define USB_HUB_PRINTF(fmt,args...) printf (fmt ,##args)
  940 +#define USB_HUB_PRINTF(fmt, args...) printf (fmt , ##args)
906 941 #else
907   -#define USB_HUB_PRINTF(fmt,args...)
  942 +#define USB_HUB_PRINTF(fmt, args...)
908 943 #endif
909 944  
910 945  
911 946  
912 947  
... ... @@ -922,19 +957,22 @@
922 957 int usb_clear_hub_feature(struct usb_device *dev, int feature)
923 958 {
924 959 return usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
925   - USB_REQ_CLEAR_FEATURE, USB_RT_HUB, feature, 0, NULL, 0, USB_CNTL_TIMEOUT);
  960 + USB_REQ_CLEAR_FEATURE, USB_RT_HUB, feature,
  961 + 0, NULL, 0, USB_CNTL_TIMEOUT);
926 962 }
927 963  
928 964 int usb_clear_port_feature(struct usb_device *dev, int port, int feature)
929 965 {
930 966 return usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
931   - USB_REQ_CLEAR_FEATURE, USB_RT_PORT, feature, port, NULL, 0, USB_CNTL_TIMEOUT);
  967 + USB_REQ_CLEAR_FEATURE, USB_RT_PORT, feature,
  968 + port, NULL, 0, USB_CNTL_TIMEOUT);
932 969 }
933 970  
934 971 int usb_set_port_feature(struct usb_device *dev, int port, int feature)
935 972 {
936 973 return usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
937   - USB_REQ_SET_FEATURE, USB_RT_PORT, feature, port, NULL, 0, USB_CNTL_TIMEOUT);
  974 + USB_REQ_SET_FEATURE, USB_RT_PORT, feature,
  975 + port, NULL, 0, USB_CNTL_TIMEOUT);
938 976 }
939 977  
940 978 int usb_get_hub_status(struct usb_device *dev, void *data)
941 979  
942 980  
943 981  
944 982  
... ... @@ -957,27 +995,27 @@
957 995 int i;
958 996 struct usb_device *dev;
959 997  
960   - dev=hub->pusb_dev;
  998 + dev = hub->pusb_dev;
961 999 /* Enable power to the ports */
962 1000 USB_HUB_PRINTF("enabling power on all ports\n");
963 1001 for (i = 0; i < dev->maxchild; i++) {
964 1002 usb_set_port_feature(dev, i + 1, USB_PORT_FEAT_POWER);
965   - USB_HUB_PRINTF("port %d returns %lX\n",i+1,dev->status);
  1003 + USB_HUB_PRINTF("port %d returns %lX\n", i + 1, dev->status);
966 1004 wait_ms(hub->desc.bPwrOn2PwrGood * 2);
967 1005 }
968 1006 }
969 1007  
970 1008 void usb_hub_reset(void)
971 1009 {
972   - usb_hub_index=0;
  1010 + usb_hub_index = 0;
973 1011 }
974 1012  
975 1013 struct usb_hub_device *usb_hub_allocate(void)
976 1014 {
977   - if(usb_hub_index<USB_MAX_HUB) {
  1015 + if (usb_hub_index < USB_MAX_HUB)
978 1016 return &hub_dev[usb_hub_index++];
979   - }
980   - printf("ERROR: USB_MAX_HUB (%d) reached\n",USB_MAX_HUB);
  1017 +
  1018 + printf("ERROR: USB_MAX_HUB (%d) reached\n", USB_MAX_HUB);
981 1019 return NULL;
982 1020 }
983 1021  
984 1022  
985 1023  
986 1024  
987 1025  
988 1026  
989 1027  
990 1028  
... ... @@ -990,39 +1028,42 @@
990 1028 struct usb_port_status portsts;
991 1029 unsigned short portstatus, portchange;
992 1030  
993   -
994 1031 USB_HUB_PRINTF("hub_port_reset: resetting port %d...\n", port);
995   - for(tries=0;tries<MAX_TRIES;tries++) {
  1032 + for (tries = 0; tries < MAX_TRIES; tries++) {
996 1033  
997 1034 usb_set_port_feature(dev, port + 1, USB_PORT_FEAT_RESET);
998 1035 wait_ms(200);
999 1036  
1000   - if (usb_get_port_status(dev, port + 1, &portsts)<0) {
1001   - USB_HUB_PRINTF("get_port_status failed status %lX\n",dev->status);
  1037 + if (usb_get_port_status(dev, port + 1, &portsts) < 0) {
  1038 + USB_HUB_PRINTF("get_port_status failed status %lX\n",
  1039 + dev->status);
1002 1040 return -1;
1003 1041 }
1004 1042 portstatus = le16_to_cpu(portsts.wPortStatus);
1005 1043 portchange = le16_to_cpu(portsts.wPortChange);
1006   - USB_HUB_PRINTF("portstatus %x, change %x, %s\n", portstatus ,portchange,
1007   - portstatus&(1<<USB_PORT_FEAT_LOWSPEED) ? "Low Speed" : "High Speed");
1008   - USB_HUB_PRINTF("STAT_C_CONNECTION = %d STAT_CONNECTION = %d USB_PORT_STAT_ENABLE %d\n",
  1044 + USB_HUB_PRINTF("portstatus %x, change %x, %s\n",
  1045 + portstatus, portchange,
  1046 + portstatus&(1<<USB_PORT_FEAT_LOWSPEED) ? \
  1047 + "Low Speed" : "High Speed");
  1048 + USB_HUB_PRINTF("STAT_C_CONNECTION = %d STAT_CONNECTION = %d" \
  1049 + " USB_PORT_STAT_ENABLE %d\n",
1009 1050 (portchange & USB_PORT_STAT_C_CONNECTION) ? 1 : 0,
1010 1051 (portstatus & USB_PORT_STAT_CONNECTION) ? 1 : 0,
1011 1052 (portstatus & USB_PORT_STAT_ENABLE) ? 1 : 0);
  1053 +
1012 1054 if ((portchange & USB_PORT_STAT_C_CONNECTION) ||
1013 1055 !(portstatus & USB_PORT_STAT_CONNECTION))
1014 1056 return -1;
1015 1057  
1016   - if (portstatus & USB_PORT_STAT_ENABLE) {
1017   -
  1058 + if (portstatus & USB_PORT_STAT_ENABLE)
1018 1059 break;
1019   - }
1020 1060  
1021 1061 wait_ms(200);
1022 1062 }
1023 1063  
1024   - if (tries==MAX_TRIES) {
1025   - USB_HUB_PRINTF("Cannot enable port %i after %i retries, disabling port.\n", port+1, MAX_TRIES);
  1064 + if (tries == MAX_TRIES) {
  1065 + USB_HUB_PRINTF("Cannot enable port %i after %i retries, " \
  1066 + "disabling port.\n", port + 1, MAX_TRIES);
1026 1067 USB_HUB_PRINTF("Maybe the USB cable is bad?\n");
1027 1068 return -1;
1028 1069 }
... ... @@ -1030,7 +1071,6 @@
1030 1071 usb_clear_port_feature(dev, port + 1, USB_PORT_FEAT_C_RESET);
1031 1072 *portstat = portstatus;
1032 1073 return 0;
1033   -
1034 1074 }
1035 1075  
1036 1076  
1037 1077  
1038 1078  
... ... @@ -1041,22 +1081,24 @@
1041 1081 unsigned short portstatus, portchange;
1042 1082  
1043 1083 /* Check status */
1044   - if (usb_get_port_status(dev, port + 1, &portsts)<0) {
  1084 + if (usb_get_port_status(dev, port + 1, &portsts) < 0) {
1045 1085 USB_HUB_PRINTF("get_port_status failed\n");
1046 1086 return;
1047 1087 }
1048 1088  
1049 1089 portstatus = le16_to_cpu(portsts.wPortStatus);
1050 1090 portchange = le16_to_cpu(portsts.wPortChange);
1051   - USB_HUB_PRINTF("portstatus %x, change %x, %s\n", portstatus, portchange,
1052   - portstatus&(1<<USB_PORT_FEAT_LOWSPEED) ? "Low Speed" : "High Speed");
  1091 + USB_HUB_PRINTF("portstatus %x, change %x, %s\n",
  1092 + portstatus, portchange,
  1093 + portstatus&(1 << USB_PORT_FEAT_LOWSPEED) ? \
  1094 + "Low Speed" : "High Speed");
1053 1095  
1054 1096 /* Clear the connection change status */
1055 1097 usb_clear_port_feature(dev, port + 1, USB_PORT_FEAT_C_CONNECTION);
1056 1098  
1057 1099 /* Disconnect any existing devices under this port */
1058 1100 if (((!(portstatus & USB_PORT_STAT_CONNECTION)) &&
1059   - (!(portstatus & USB_PORT_STAT_ENABLE)))|| (dev->children[port])) {
  1101 + (!(portstatus & USB_PORT_STAT_ENABLE))) || (dev->children[port])) {
1060 1102 USB_HUB_PRINTF("usb_disconnect(&hub->children[port]);\n");
1061 1103 /* Return now if nothing is connected */
1062 1104 if (!(portstatus & USB_PORT_STAT_CONNECTION))
1063 1105  
... ... @@ -1073,11 +1115,11 @@
1073 1115 wait_ms(200);
1074 1116  
1075 1117 /* Allocate a new device struct for it */
1076   - usb=usb_alloc_new_device();
  1118 + usb = usb_alloc_new_device();
1077 1119 usb->slow = (portstatus & USB_PORT_STAT_LOW_SPEED) ? 1 : 0;
1078 1120  
1079 1121 dev->children[port] = usb;
1080   - usb->parent=dev;
  1122 + usb->parent = dev;
1081 1123 /* Run it through the hoops (find a driver, etc) */
1082 1124 if (usb_new_device(usb)) {
1083 1125 /* Woops, disable the port */
1084 1126  
1085 1127  
... ... @@ -1096,13 +1138,14 @@
1096 1138 struct usb_hub_device *hub;
1097 1139  
1098 1140 /* "allocate" Hub device */
1099   - hub=usb_hub_allocate();
1100   - if(hub==NULL)
  1141 + hub = usb_hub_allocate();
  1142 + if (hub == NULL)
1101 1143 return -1;
1102   - hub->pusb_dev=dev;
  1144 + hub->pusb_dev = dev;
1103 1145 /* Get the the hub descriptor */
1104 1146 if (usb_get_hub_descriptor(dev, buffer, 4) < 0) {
1105   - USB_HUB_PRINTF("usb_hub_configure: failed to get hub descriptor, giving up %lX\n",dev->status);
  1147 + USB_HUB_PRINTF("usb_hub_configure: failed to get hub " \
  1148 + "descriptor, giving up %lX\n", dev->status);
1106 1149 return -1;
1107 1150 }
1108 1151 descriptor = (struct usb_hub_descriptor *)buffer;
1109 1152  
1110 1153  
1111 1154  
1112 1155  
1113 1156  
... ... @@ -1110,43 +1153,48 @@
1110 1153 /* silence compiler warning if USB_BUFSIZ is > 256 [= sizeof(char)] */
1111 1154 i = descriptor->bLength;
1112 1155 if (i > USB_BUFSIZ) {
1113   - USB_HUB_PRINTF("usb_hub_configure: failed to get hub descriptor - too long: %d\n",
1114   - descriptor->bLength);
  1156 + USB_HUB_PRINTF("usb_hub_configure: failed to get hub " \
  1157 + "descriptor - too long: %d\n",
  1158 + descriptor->bLength);
1115 1159 return -1;
1116 1160 }
1117 1161  
1118 1162 if (usb_get_hub_descriptor(dev, buffer, descriptor->bLength) < 0) {
1119   - USB_HUB_PRINTF("usb_hub_configure: failed to get hub descriptor 2nd giving up %lX\n",dev->status);
  1163 + USB_HUB_PRINTF("usb_hub_configure: failed to get hub " \
  1164 + "descriptor 2nd giving up %lX\n", dev->status);
1120 1165 return -1;
1121 1166 }
1122   - memcpy((unsigned char *)&hub->desc,buffer,descriptor->bLength);
  1167 + memcpy((unsigned char *)&hub->desc, buffer, descriptor->bLength);
1123 1168 /* adjust 16bit values */
1124   - hub->desc.wHubCharacteristics = le16_to_cpu(descriptor->wHubCharacteristics);
  1169 + hub->desc.wHubCharacteristics =
  1170 + le16_to_cpu(descriptor->wHubCharacteristics);
1125 1171 /* set the bitmap */
1126   - bitmap=(unsigned char *)&hub->desc.DeviceRemovable[0];
1127   - memset(bitmap,0xff,(USB_MAXCHILDREN+1+7)/8); /* devices not removable by default */
1128   - bitmap=(unsigned char *)&hub->desc.PortPowerCtrlMask[0];
1129   - memset(bitmap,0xff,(USB_MAXCHILDREN+1+7)/8); /* PowerMask = 1B */
1130   - for(i=0;i<((hub->desc.bNbrPorts + 1 + 7)/8);i++) {
1131   - hub->desc.DeviceRemovable[i]=descriptor->DeviceRemovable[i];
1132   - }
1133   - for(i=0;i<((hub->desc.bNbrPorts + 1 + 7)/8);i++) {
1134   - hub->desc.DeviceRemovable[i]=descriptor->PortPowerCtrlMask[i];
1135   - }
  1172 + bitmap = (unsigned char *)&hub->desc.DeviceRemovable[0];
  1173 + /* devices not removable by default */
  1174 + memset(bitmap, 0xff, (USB_MAXCHILDREN+1+7)/8);
  1175 + bitmap = (unsigned char *)&hub->desc.PortPowerCtrlMask[0];
  1176 + memset(bitmap, 0xff, (USB_MAXCHILDREN+1+7)/8); /* PowerMask = 1B */
  1177 +
  1178 + for (i = 0; i < ((hub->desc.bNbrPorts + 1 + 7)/8); i++)
  1179 + hub->desc.DeviceRemovable[i] = descriptor->DeviceRemovable[i];
  1180 +
  1181 + for (i = 0; i < ((hub->desc.bNbrPorts + 1 + 7)/8); i++)
  1182 + hub->desc.DeviceRemovable[i] = descriptor->PortPowerCtrlMask[i];
  1183 +
1136 1184 dev->maxchild = descriptor->bNbrPorts;
1137 1185 USB_HUB_PRINTF("%d ports detected\n", dev->maxchild);
1138 1186  
1139 1187 switch (hub->desc.wHubCharacteristics & HUB_CHAR_LPSM) {
1140   - case 0x00:
1141   - USB_HUB_PRINTF("ganged power switching\n");
1142   - break;
1143   - case 0x01:
1144   - USB_HUB_PRINTF("individual port power switching\n");
1145   - break;
1146   - case 0x02:
1147   - case 0x03:
1148   - USB_HUB_PRINTF("unknown reserved power switching mode\n");
1149   - break;
  1188 + case 0x00:
  1189 + USB_HUB_PRINTF("ganged power switching\n");
  1190 + break;
  1191 + case 0x01:
  1192 + USB_HUB_PRINTF("individual port power switching\n");
  1193 + break;
  1194 + case 0x02:
  1195 + case 0x03:
  1196 + USB_HUB_PRINTF("unknown reserved power switching mode\n");
  1197 + break;
1150 1198 }
1151 1199  
1152 1200 if (hub->desc.wHubCharacteristics & HUB_CHAR_COMPOUND)
1153 1201  
1154 1202  
1155 1203  
1156 1204  
1157 1205  
1158 1206  
1159 1207  
1160 1208  
1161 1209  
... ... @@ -1155,40 +1203,52 @@
1155 1203 USB_HUB_PRINTF("standalone hub\n");
1156 1204  
1157 1205 switch (hub->desc.wHubCharacteristics & HUB_CHAR_OCPM) {
1158   - case 0x00:
1159   - USB_HUB_PRINTF("global over-current protection\n");
1160   - break;
1161   - case 0x08:
1162   - USB_HUB_PRINTF("individual port over-current protection\n");
1163   - break;
1164   - case 0x10:
1165   - case 0x18:
1166   - USB_HUB_PRINTF("no over-current protection\n");
1167   - break;
  1206 + case 0x00:
  1207 + USB_HUB_PRINTF("global over-current protection\n");
  1208 + break;
  1209 + case 0x08:
  1210 + USB_HUB_PRINTF("individual port over-current protection\n");
  1211 + break;
  1212 + case 0x10:
  1213 + case 0x18:
  1214 + USB_HUB_PRINTF("no over-current protection\n");
  1215 + break;
1168 1216 }
1169   - USB_HUB_PRINTF("power on to power good time: %dms\n", descriptor->bPwrOn2PwrGood * 2);
1170   - USB_HUB_PRINTF("hub controller current requirement: %dmA\n", descriptor->bHubContrCurrent);
  1217 +
  1218 + USB_HUB_PRINTF("power on to power good time: %dms\n",
  1219 + descriptor->bPwrOn2PwrGood * 2);
  1220 + USB_HUB_PRINTF("hub controller current requirement: %dmA\n",
  1221 + descriptor->bHubContrCurrent);
  1222 +
1171 1223 for (i = 0; i < dev->maxchild; i++)
1172 1224 USB_HUB_PRINTF("port %d is%s removable\n", i + 1,
1173   - hub->desc.DeviceRemovable[(i + 1)/8] & (1 << ((i + 1)%8)) ? " not" : "");
  1225 + hub->desc.DeviceRemovable[(i + 1) / 8] & \
  1226 + (1 << ((i + 1) % 8)) ? " not" : "");
  1227 +
1174 1228 if (sizeof(struct usb_hub_status) > USB_BUFSIZ) {
1175   - USB_HUB_PRINTF("usb_hub_configure: failed to get Status - too long: %d\n",
1176   - descriptor->bLength);
  1229 + USB_HUB_PRINTF("usb_hub_configure: failed to get Status - " \
  1230 + "too long: %d\n", descriptor->bLength);
1177 1231 return -1;
1178 1232 }
1179 1233  
1180 1234 if (usb_get_hub_status(dev, buffer) < 0) {
1181   - USB_HUB_PRINTF("usb_hub_configure: failed to get Status %lX\n",dev->status);
  1235 + USB_HUB_PRINTF("usb_hub_configure: failed to get Status %lX\n",
  1236 + dev->status);
1182 1237 return -1;
1183 1238 }
  1239 +
1184 1240 hubsts = (struct usb_hub_status *)buffer;
1185 1241 USB_HUB_PRINTF("get_hub_status returned status %X, change %X\n",
1186   - le16_to_cpu(hubsts->wHubStatus),le16_to_cpu(hubsts->wHubChange));
  1242 + le16_to_cpu(hubsts->wHubStatus),
  1243 + le16_to_cpu(hubsts->wHubChange));
1187 1244 USB_HUB_PRINTF("local power source is %s\n",
1188   - (le16_to_cpu(hubsts->wHubStatus) & HUB_STATUS_LOCAL_POWER) ? "lost (inactive)" : "good");
  1245 + (le16_to_cpu(hubsts->wHubStatus) & HUB_STATUS_LOCAL_POWER) ? \
  1246 + "lost (inactive)" : "good");
1189 1247 USB_HUB_PRINTF("%sover-current condition exists\n",
1190   - (le16_to_cpu(hubsts->wHubStatus) & HUB_STATUS_OVERCURRENT) ? "" : "no ");
  1248 + (le16_to_cpu(hubsts->wHubStatus) & HUB_STATUS_OVERCURRENT) ? \
  1249 + "" : "no ");
1191 1250 usb_hub_power_on(hub);
  1251 +
1192 1252 for (i = 0; i < dev->maxchild; i++) {
1193 1253 struct usb_port_status portsts;
1194 1254 unsigned short portstatus, portchange;
1195 1255  
1196 1256  
1197 1257  
1198 1258  
1199 1259  
1200 1260  
1201 1261  
... ... @@ -1197,41 +1257,51 @@
1197 1257 USB_HUB_PRINTF("get_port_status failed\n");
1198 1258 continue;
1199 1259 }
  1260 +
1200 1261 portstatus = le16_to_cpu(portsts.wPortStatus);
1201 1262 portchange = le16_to_cpu(portsts.wPortChange);
1202   - USB_HUB_PRINTF("Port %d Status %X Change %X\n",i+1,portstatus,portchange);
  1263 + USB_HUB_PRINTF("Port %d Status %X Change %X\n",
  1264 + i + 1, portstatus, portchange);
  1265 +
1203 1266 if (portchange & USB_PORT_STAT_C_CONNECTION) {
1204 1267 USB_HUB_PRINTF("port %d connection change\n", i + 1);
1205 1268 usb_hub_port_connect_change(dev, i);
1206 1269 }
1207 1270 if (portchange & USB_PORT_STAT_C_ENABLE) {
1208   - USB_HUB_PRINTF("port %d enable change, status %x\n", i + 1, portstatus);
1209   - usb_clear_port_feature(dev, i + 1, USB_PORT_FEAT_C_ENABLE);
  1271 + USB_HUB_PRINTF("port %d enable change, status %x\n",
  1272 + i + 1, portstatus);
  1273 + usb_clear_port_feature(dev, i + 1,
  1274 + USB_PORT_FEAT_C_ENABLE);
1210 1275  
1211   - /* EM interference sometimes causes bad shielded USB devices to
1212   - * be shutdown by the hub, this hack enables them again.
1213   - * Works at least with mouse driver */
  1276 + /* EM interference sometimes causes bad shielded USB
  1277 + * devices to be shutdown by the hub, this hack enables
  1278 + * them again. Works at least with mouse driver */
1214 1279 if (!(portstatus & USB_PORT_STAT_ENABLE) &&
1215   - (portstatus & USB_PORT_STAT_CONNECTION) && (dev->children[i])) {
1216   - USB_HUB_PRINTF("already running port %i disabled by hub (EMI?), re-enabling...\n",
1217   - i + 1);
  1280 + (portstatus & USB_PORT_STAT_CONNECTION) &&
  1281 + ((dev->children[i]))) {
  1282 + USB_HUB_PRINTF("already running port %i " \
  1283 + "disabled by hub (EMI?), " \
  1284 + "re-enabling...\n", i + 1);
1218 1285 usb_hub_port_connect_change(dev, i);
1219 1286 }
1220 1287 }
1221 1288 if (portstatus & USB_PORT_STAT_SUSPEND) {
1222 1289 USB_HUB_PRINTF("port %d suspend change\n", i + 1);
1223   - usb_clear_port_feature(dev, i + 1, USB_PORT_FEAT_SUSPEND);
  1290 + usb_clear_port_feature(dev, i + 1,
  1291 + USB_PORT_FEAT_SUSPEND);
1224 1292 }
1225 1293  
1226 1294 if (portchange & USB_PORT_STAT_C_OVERCURRENT) {
1227 1295 USB_HUB_PRINTF("port %d over-current change\n", i + 1);
1228   - usb_clear_port_feature(dev, i + 1, USB_PORT_FEAT_C_OVER_CURRENT);
  1296 + usb_clear_port_feature(dev, i + 1,
  1297 + USB_PORT_FEAT_C_OVER_CURRENT);
1229 1298 usb_hub_power_on(hub);
1230 1299 }
1231 1300  
1232 1301 if (portchange & USB_PORT_STAT_C_RESET) {
1233 1302 USB_HUB_PRINTF("port %d reset change\n", i + 1);
1234   - usb_clear_port_feature(dev, i + 1, USB_PORT_FEAT_C_RESET);
  1303 + usb_clear_port_feature(dev, i + 1,
  1304 + USB_PORT_FEAT_C_RESET);
1235 1305 }
1236 1306 } /* end for i all ports */
1237 1307  
... ... @@ -1265,7 +1335,7 @@
1265 1335 return 0;
1266 1336 /* We found a hub */
1267 1337 USB_HUB_PRINTF("USB hub found\n");
1268   - ret=usb_hub_configure(dev);
  1338 + ret = usb_hub_configure(dev);
1269 1339 return ret;
1270 1340 }
1271 1341  
drivers/usb/usb_ohci.c
Changes suppressed. Click to show
... ... @@ -97,7 +97,8 @@
97 97 # define writel(a, b) (*((volatile u32 *)(b)) = ((volatile u32)a))
98 98 #endif /* CFG_OHCI_SWAP_REG_ACCESS */
99 99  
100   -#define min_t(type,x,y) ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
  100 +#define min_t(type, x, y) \
  101 + ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
101 102  
102 103 #ifdef CONFIG_PCI_OHCI
103 104 static struct pci_device_id ohci_pci_ids[] = {
104 105  
... ... @@ -120,13 +121,13 @@
120 121 #ifdef DEBUG
121 122 #define dbg(format, arg...) printf("DEBUG: " format "\n", ## arg)
122 123 #else
123   -#define dbg(format, arg...) do {} while(0)
  124 +#define dbg(format, arg...) do {} while (0)
124 125 #endif /* DEBUG */
125 126 #define err(format, arg...) printf("ERROR: " format "\n", ## arg)
126 127 #ifdef SHOW_INFO
127 128 #define info(format, arg...) printf("INFO: " format "\n", ## arg)
128 129 #else
129   -#define info(format, arg...) do {} while(0)
  130 +#define info(format, arg...) do {} while (0)
130 131 #endif
131 132  
132 133 #ifdef CFG_OHCI_BE_CONTROLLER
133 134  
134 135  
... ... @@ -145,25 +146,24 @@
145 146 struct ohci_hcca *phcca;
146 147 /* this allocates EDs for all possible endpoints */
147 148 struct ohci_device ohci_dev;
148   -/* RHSC flag */
149   -int got_rhsc;
150 149 /* device which was disconnected */
151 150 struct usb_device *devgone;
152 151  
153   -static inline u32 roothub_a (struct ohci *hc)
154   - { return readl (&hc->regs->roothub.a); }
155   -static inline u32 roothub_b (struct ohci *hc)
156   - { return readl (&hc->regs->roothub.b); }
157   -static inline u32 roothub_status (struct ohci *hc)
158   - { return readl (&hc->regs->roothub.status); }
159   -static inline u32 roothub_portstatus (struct ohci *hc, int i)
160   - { return readl (&hc->regs->roothub.portstatus[i]); }
  152 +static inline u32 roothub_a(struct ohci *hc)
  153 + { return readl(&hc->regs->roothub.a); }
  154 +static inline u32 roothub_b(struct ohci *hc)
  155 + { return readl(&hc->regs->roothub.b); }
  156 +static inline u32 roothub_status(struct ohci *hc)
  157 + { return readl(&hc->regs->roothub.status); }
  158 +static inline u32 roothub_portstatus(struct ohci *hc, int i)
  159 + { return readl(&hc->regs->roothub.portstatus[i]); }
161 160  
162 161 /* forward declaration */
163   -static int hc_interrupt (void);
164   -static void
165   -td_submit_job (struct usb_device * dev, unsigned long pipe, void * buffer,
166   - int transfer_len, struct devrequest * setup, urb_priv_t * urb, int interval);
  162 +static int hc_interrupt(void);
  163 +static void td_submit_job(struct usb_device *dev, unsigned long pipe,
  164 + void *buffer, int transfer_len,
  165 + struct devrequest *setup, urb_priv_t *urb,
  166 + int interval);
167 167  
168 168 /*-------------------------------------------------------------------------*
169 169 * URB support functions
170 170  
... ... @@ -171,11 +171,11 @@
171 171  
172 172 /* free HCD-private data associated with this URB */
173 173  
174   -static void urb_free_priv (urb_priv_t * urb)
  174 +static void urb_free_priv(urb_priv_t *urb)
175 175 {
176 176 int i;
177 177 int last;
178   - struct td * td;
  178 + struct td *td;
179 179  
180 180 last = urb->length - 1;
181 181 if (last >= 0) {
182 182  
183 183  
184 184  
185 185  
186 186  
187 187  
188 188  
189 189  
190 190  
191 191  
192 192  
193 193  
194 194  
195 195  
196 196  
... ... @@ -193,72 +193,74 @@
193 193 /*-------------------------------------------------------------------------*/
194 194  
195 195 #ifdef DEBUG
196   -static int sohci_get_current_frame_number (struct usb_device * dev);
  196 +static int sohci_get_current_frame_number(struct usb_device *dev);
197 197  
198 198 /* debug| print the main components of an URB
199 199 * small: 0) header + data packets 1) just header */
200 200  
201   -static void pkt_print (urb_priv_t *purb, struct usb_device * dev,
202   - unsigned long pipe, void * buffer,
203   - int transfer_len, struct devrequest * setup, char * str, int small)
  201 +static void pkt_print(urb_priv_t *purb, struct usb_device *dev,
  202 + unsigned long pipe, void *buffer, int transfer_len,
  203 + struct devrequest *setup, char *str, int small)
204 204 {
205   - dbg("%s URB:[%4x] dev:%2d,ep:%2d-%c,type:%s,len:%d/%d stat:%#lx",
  205 + dbg("%s URB:[%4x] dev:%2lu,ep:%2lu-%c,type:%s,len:%d/%d stat:%#lx",
206 206 str,
207   - sohci_get_current_frame_number (dev),
208   - usb_pipedevice (pipe),
209   - usb_pipeendpoint (pipe),
210   - usb_pipeout (pipe)? 'O': 'I',
211   - usb_pipetype (pipe) < 2? (usb_pipeint (pipe)? "INTR": "ISOC"):
212   - (usb_pipecontrol (pipe)? "CTRL": "BULK"),
  207 + sohci_get_current_frame_number(dev),
  208 + usb_pipedevice(pipe),
  209 + usb_pipeendpoint(pipe),
  210 + usb_pipeout(pipe)? 'O': 'I',
  211 + usb_pipetype(pipe) < 2 ? \
  212 + (usb_pipeint(pipe)? "INTR": "ISOC"): \
  213 + (usb_pipecontrol(pipe)? "CTRL": "BULK"),
213 214 (purb ? purb->actual_length : 0),
214 215 transfer_len, dev->status);
215 216 #ifdef OHCI_VERBOSE_DEBUG
216 217 if (!small) {
217 218 int i, len;
218 219  
219   - if (usb_pipecontrol (pipe)) {
220   - printf (__FILE__ ": cmd(8):");
  220 + if (usb_pipecontrol(pipe)) {
  221 + printf(__FILE__ ": cmd(8):");
221 222 for (i = 0; i < 8 ; i++)
222   - printf (" %02x", ((__u8 *) setup) [i]);
223   - printf ("\n");
  223 + printf(" %02x", ((__u8 *) setup) [i]);
  224 + printf("\n");
224 225 }
225 226 if (transfer_len > 0 && buffer) {
226   - printf (__FILE__ ": data(%d/%d):",
  227 + printf(__FILE__ ": data(%d/%d):",
227 228 (purb ? purb->actual_length : 0),
228 229 transfer_len);
229   - len = usb_pipeout (pipe)?
230   - transfer_len:
  230 + len = usb_pipeout(pipe)? transfer_len:
231 231 (purb ? purb->actual_length : 0);
232 232 for (i = 0; i < 16 && i < len; i++)
233   - printf (" %02x", ((__u8 *) buffer) [i]);
234   - printf ("%s\n", i < len? "...": "");
  233 + printf(" %02x", ((__u8 *) buffer) [i]);
  234 + printf("%s\n", i < len? "...": "");
235 235 }
236 236 }
237 237 #endif
238 238 }
239 239  
240   -/* just for debugging; prints non-empty branches of the int ed tree inclusive iso eds*/
241   -void ep_print_int_eds (ohci_t *ohci, char * str) {
  240 +/* just for debugging; prints non-empty branches of the int ed tree
  241 + * inclusive iso eds */
  242 +void ep_print_int_eds(ohci_t *ohci, char *str)
  243 +{
242 244 int i, j;
243   - __u32 * ed_p;
244   - for (i= 0; i < 32; i++) {
  245 + __u32 *ed_p;
  246 + for (i = 0; i < 32; i++) {
245 247 j = 5;
246 248 ed_p = &(ohci->hcca->int_table [i]);
247 249 if (*ed_p == 0)
248 250 continue;
249   - printf (__FILE__ ": %s branch int %2d(%2x):", str, i, i);
  251 + printf(__FILE__ ": %s branch int %2d(%2x):", str, i, i);
250 252 while (*ed_p != 0 && j--) {
251 253 ed_t *ed = (ed_t *)m32_swap(ed_p);
252   - printf (" ed: %4x;", ed->hwINFO);
  254 + printf(" ed: %4x;", ed->hwINFO);
253 255 ed_p = &ed->hwNextED;
254 256 }
255   - printf ("\n");
  257 + printf("\n");
256 258 }
257 259 }
258 260  
259   -static void ohci_dump_intr_mask (char *label, __u32 mask)
  261 +static void ohci_dump_intr_mask(char *label, __u32 mask)
260 262 {
261   - dbg ("%s: 0x%08x%s%s%s%s%s%s%s%s%s",
  263 + dbg("%s: 0x%08x%s%s%s%s%s%s%s%s%s",
262 264 label,
263 265 mask,
264 266 (mask & OHCI_INTR_MIE) ? " MIE" : "",
265 267  
266 268  
267 269  
268 270  
269 271  
270 272  
271 273  
272 274  
... ... @@ -273,46 +275,46 @@
273 275 );
274 276 }
275 277  
276   -static void maybe_print_eds (char *label, __u32 value)
  278 +static void maybe_print_eds(char *label, __u32 value)
277 279 {
278 280 ed_t *edp = (ed_t *)value;
279 281  
280 282 if (value) {
281   - dbg ("%s %08x", label, value);
282   - dbg ("%08x", edp->hwINFO);
283   - dbg ("%08x", edp->hwTailP);
284   - dbg ("%08x", edp->hwHeadP);
285   - dbg ("%08x", edp->hwNextED);
  283 + dbg("%s %08x", label, value);
  284 + dbg("%08x", edp->hwINFO);
  285 + dbg("%08x", edp->hwTailP);
  286 + dbg("%08x", edp->hwHeadP);
  287 + dbg("%08x", edp->hwNextED);
286 288 }
287 289 }
288 290  
289   -static char * hcfs2string (int state)
  291 +static char *hcfs2string(int state)
290 292 {
291 293 switch (state) {
292   - case OHCI_USB_RESET: return "reset";
293   - case OHCI_USB_RESUME: return "resume";
294   - case OHCI_USB_OPER: return "operational";
295   - case OHCI_USB_SUSPEND: return "suspend";
  294 + case OHCI_USB_RESET: return "reset";
  295 + case OHCI_USB_RESUME: return "resume";
  296 + case OHCI_USB_OPER: return "operational";
  297 + case OHCI_USB_SUSPEND: return "suspend";
296 298 }
297 299 return "?";
298 300 }
299 301  
300 302 /* dump control and status registers */
301   -static void ohci_dump_status (ohci_t *controller)
  303 +static void ohci_dump_status(ohci_t *controller)
302 304 {
303 305 struct ohci_regs *regs = controller->regs;
304 306 __u32 temp;
305 307  
306   - temp = readl (&regs->revision) & 0xff;
  308 + temp = readl(&regs->revision) & 0xff;
307 309 if (temp != 0x10)
308   - dbg ("spec %d.%d", (temp >> 4), (temp & 0x0f));
  310 + dbg("spec %d.%d", (temp >> 4), (temp & 0x0f));
309 311  
310   - temp = readl (&regs->control);
311   - dbg ("control: 0x%08x%s%s%s HCFS=%s%s%s%s%s CBSR=%d", temp,
  312 + temp = readl(&regs->control);
  313 + dbg("control: 0x%08x%s%s%s HCFS=%s%s%s%s%s CBSR=%d", temp,
312 314 (temp & OHCI_CTRL_RWE) ? " RWE" : "",
313 315 (temp & OHCI_CTRL_RWC) ? " RWC" : "",
314 316 (temp & OHCI_CTRL_IR) ? " IR" : "",
315   - hcfs2string (temp & OHCI_CTRL_HCFS),
  317 + hcfs2string(temp & OHCI_CTRL_HCFS),
316 318 (temp & OHCI_CTRL_BLE) ? " BLE" : "",
317 319 (temp & OHCI_CTRL_CLE) ? " CLE" : "",
318 320 (temp & OHCI_CTRL_IE) ? " IE" : "",
... ... @@ -320,8 +322,8 @@
320 322 temp & OHCI_CTRL_CBSR
321 323 );
322 324  
323   - temp = readl (&regs->cmdstatus);
324   - dbg ("cmdstatus: 0x%08x SOC=%d%s%s%s%s", temp,
  325 + temp = readl(&regs->cmdstatus);
  326 + dbg("cmdstatus: 0x%08x SOC=%d%s%s%s%s", temp,
325 327 (temp & OHCI_SOC) >> 16,
326 328 (temp & OHCI_OCR) ? " OCR" : "",
327 329 (temp & OHCI_BLF) ? " BLF" : "",
328 330  
329 331  
330 332  
331 333  
332 334  
333 335  
334 336  
... ... @@ -329,31 +331,31 @@
329 331 (temp & OHCI_HCR) ? " HCR" : ""
330 332 );
331 333  
332   - ohci_dump_intr_mask ("intrstatus", readl (&regs->intrstatus));
333   - ohci_dump_intr_mask ("intrenable", readl (&regs->intrenable));
  334 + ohci_dump_intr_mask("intrstatus", readl(&regs->intrstatus));
  335 + ohci_dump_intr_mask("intrenable", readl(&regs->intrenable));
334 336  
335   - maybe_print_eds ("ed_periodcurrent", readl (&regs->ed_periodcurrent));
  337 + maybe_print_eds("ed_periodcurrent", readl(&regs->ed_periodcurrent));
336 338  
337   - maybe_print_eds ("ed_controlhead", readl (&regs->ed_controlhead));
338   - maybe_print_eds ("ed_controlcurrent", readl (&regs->ed_controlcurrent));
  339 + maybe_print_eds("ed_controlhead", readl(&regs->ed_controlhead));
  340 + maybe_print_eds("ed_controlcurrent", readl(&regs->ed_controlcurrent));
339 341  
340   - maybe_print_eds ("ed_bulkhead", readl (&regs->ed_bulkhead));
341   - maybe_print_eds ("ed_bulkcurrent", readl (&regs->ed_bulkcurrent));
  342 + maybe_print_eds("ed_bulkhead", readl(&regs->ed_bulkhead));
  343 + maybe_print_eds("ed_bulkcurrent", readl(&regs->ed_bulkcurrent));
342 344  
343   - maybe_print_eds ("donehead", readl (&regs->donehead));
  345 + maybe_print_eds("donehead", readl(&regs->donehead));
344 346 }
345 347  
346   -static void ohci_dump_roothub (ohci_t *controller, int verbose)
  348 +static void ohci_dump_roothub(ohci_t *controller, int verbose)
347 349 {
348 350 __u32 temp, ndp, i;
349 351  
350   - temp = roothub_a (controller);
  352 + temp = roothub_a(controller);
351 353 ndp = (temp & RH_A_NDP);
352 354 #ifdef CONFIG_AT91C_PQFP_UHPBUG
353 355 ndp = (ndp == 2) ? 1:0;
354 356 #endif
355 357 if (verbose) {
356   - dbg ("roothub.a: %08x POTPGT=%d%s%s%s%s%s NDP=%d", temp,
  358 + dbg("roothub.a: %08x POTPGT=%d%s%s%s%s%s NDP=%d", temp,
357 359 ((temp & RH_A_POTPGT) >> 24) & 0xff,
358 360 (temp & RH_A_NOCP) ? " NOCP" : "",
359 361 (temp & RH_A_OCPM) ? " OCPM" : "",
360 362  
... ... @@ -362,14 +364,14 @@
362 364 (temp & RH_A_PSM) ? " PSM" : "",
363 365 ndp
364 366 );
365   - temp = roothub_b (controller);
366   - dbg ("roothub.b: %08x PPCM=%04x DR=%04x",
  367 + temp = roothub_b(controller);
  368 + dbg("roothub.b: %08x PPCM=%04x DR=%04x",
367 369 temp,
368 370 (temp & RH_B_PPCM) >> 16,
369 371 (temp & RH_B_DR)
370 372 );
371   - temp = roothub_status (controller);
372   - dbg ("roothub.status: %08x%s%s%s%s%s%s",
  373 + temp = roothub_status(controller);
  374 + dbg("roothub.status: %08x%s%s%s%s%s%s",
373 375 temp,
374 376 (temp & RH_HS_CRWE) ? " CRWE" : "",
375 377 (temp & RH_HS_OCIC) ? " OCIC" : "",
... ... @@ -381,8 +383,8 @@
381 383 }
382 384  
383 385 for (i = 0; i < ndp; i++) {
384   - temp = roothub_portstatus (controller, i);
385   - dbg ("roothub.portstatus [%d] = 0x%08x%s%s%s%s%s%s%s%s%s%s%s%s",
  386 + temp = roothub_portstatus(controller, i);
  387 + dbg("roothub.portstatus [%d] = 0x%08x%s%s%s%s%s%s%s%s%s%s%s%s",
386 388 i,
387 389 temp,
388 390 (temp & RH_PS_PRSC) ? " PRSC" : "",
389 391  
390 392  
391 393  
... ... @@ -403,16 +405,16 @@
403 405 }
404 406 }
405 407  
406   -static void ohci_dump (ohci_t *controller, int verbose)
  408 +static void ohci_dump(ohci_t *controller, int verbose)
407 409 {
408   - dbg ("OHCI controller usb-%s state", controller->slot_name);
  410 + dbg("OHCI controller usb-%s state", controller->slot_name);
409 411  
410 412 /* dumps some of the state we know about */
411   - ohci_dump_status (controller);
  413 + ohci_dump_status(controller);
412 414 if (verbose)
413   - ep_print_int_eds (controller, "hcca");
414   - dbg ("hcca frame #%04x", controller->hcca->frame_no);
415   - ohci_dump_roothub (controller, 1);
  415 + ep_print_int_eds(controller, "hcca");
  416 + dbg("hcca frame #%04x", controller->hcca->frame_no);
  417 + ohci_dump_roothub(controller, 1);
416 418 }
417 419 #endif /* DEBUG */
418 420  
... ... @@ -425,7 +427,7 @@
425 427 int sohci_submit_job(urb_priv_t *urb, struct devrequest *setup)
426 428 {
427 429 ohci_t *ohci;
428   - ed_t * ed;
  430 + ed_t *ed;
429 431 urb_priv_t *purb_priv = urb;
430 432 int i, size = 0;
431 433 struct usb_device *dev = urb->dev;
432 434  
433 435  
... ... @@ -443,27 +445,29 @@
443 445 return -1;
444 446 }
445 447  
446   - /* we're about to begin a new transaction here so mark the URB unfinished */
  448 + /* we're about to begin a new transaction here so mark the
  449 + * URB unfinished */
447 450 urb->finished = 0;
448 451  
449 452 /* every endpoint has a ed, locate and fill it */
450   - if (!(ed = ep_add_ed (dev, pipe, interval, 1))) {
  453 + ed = ep_add_ed(dev, pipe, interval, 1);
  454 + if (!ed) {
451 455 err("sohci_submit_job: ENOMEM");
452 456 return -1;
453 457 }
454 458  
455 459 /* for the private part of the URB we need the number of TDs (size) */
456   - switch (usb_pipetype (pipe)) {
457   - case PIPE_BULK: /* one TD for every 4096 Byte */
458   - size = (transfer_len - 1) / 4096 + 1;
459   - break;
460   - case PIPE_CONTROL: /* 1 TD for setup, 1 for ACK and 1 for every 4096 B */
461   - size = (transfer_len == 0)? 2:
462   - (transfer_len - 1) / 4096 + 3;
463   - break;
464   - case PIPE_INTERRUPT: /* 1 TD */
465   - size = 1;
466   - break;
  460 + switch (usb_pipetype(pipe)) {
  461 + case PIPE_BULK: /* one TD for every 4096 Byte */
  462 + size = (transfer_len - 1) / 4096 + 1;
  463 + break;
  464 + case PIPE_CONTROL:/* 1 TD for setup, 1 for ACK and 1 for every 4096 B */
  465 + size = (transfer_len == 0)? 2:
  466 + (transfer_len - 1) / 4096 + 3;
  467 + break;
  468 + case PIPE_INTERRUPT: /* 1 TD */
  469 + size = 1;
  470 + break;
467 471 }
468 472  
469 473 ed->purb = urb;
470 474  
471 475  
472 476  
473 477  
... ... @@ -482,27 +486,28 @@
482 486 /* allocate the TDs */
483 487 /* note that td[0] was allocated in ep_add_ed */
484 488 for (i = 0; i < size; i++) {
485   - purb_priv->td[i] = td_alloc (dev);
  489 + purb_priv->td[i] = td_alloc(dev);
486 490 if (!purb_priv->td[i]) {
487 491 purb_priv->length = i;
488   - urb_free_priv (purb_priv);
  492 + urb_free_priv(purb_priv);
489 493 err("sohci_submit_job: ENOMEM");
490 494 return -1;
491 495 }
492 496 }
493 497  
494 498 if (ed->state == ED_NEW || (ed->state & ED_DEL)) {
495   - urb_free_priv (purb_priv);
  499 + urb_free_priv(purb_priv);
496 500 err("sohci_submit_job: EINVAL");
497 501 return -1;
498 502 }
499 503  
500 504 /* link the ed into a chain if is not already */
501 505 if (ed->state != ED_OPER)
502   - ep_link (ohci, ed);
  506 + ep_link(ohci, ed);
503 507  
504 508 /* fill the TDs and link it to the ed */
505   - td_submit_job(dev, pipe, buffer, transfer_len, setup, purb_priv, interval);
  509 + td_submit_job(dev, pipe, buffer, transfer_len,
  510 + setup, purb_priv, interval);
506 511  
507 512 return 0;
508 513 }
509 514  
510 515  
511 516  
... ... @@ -511,19 +516,19 @@
511 516 {
512 517 struct ohci_regs *regs = hc->regs;
513 518  
514   - switch (usb_pipetype (urb->pipe)) {
  519 + switch (usb_pipetype(urb->pipe)) {
515 520 case PIPE_INTERRUPT:
516 521 /* implicitly requeued */
517 522 if (urb->dev->irq_handle &&
518 523 (urb->dev->irq_act_len = urb->actual_length)) {
519   - writel (OHCI_INTR_WDH, &regs->intrenable);
520   - readl (&regs->intrenable); /* PCI posting flush */
  524 + writel(OHCI_INTR_WDH, &regs->intrenable);
  525 + readl(&regs->intrenable); /* PCI posting flush */
521 526 urb->dev->irq_handle(urb->dev);
522   - writel (OHCI_INTR_WDH, &regs->intrdisable);
523   - readl (&regs->intrdisable); /* PCI posting flush */
  527 + writel(OHCI_INTR_WDH, &regs->intrdisable);
  528 + readl(&regs->intrdisable); /* PCI posting flush */
524 529 }
525 530 urb->actual_length = 0;
526   - td_submit_job (
  531 + td_submit_job(
527 532 urb->dev,
528 533 urb->pipe,
529 534 urb->transfer_buffer,
530 535  
... ... @@ -546,11 +551,11 @@
546 551 #ifdef DEBUG
547 552 /* tell us the current USB frame number */
548 553  
549   -static int sohci_get_current_frame_number (struct usb_device *usb_dev)
  554 +static int sohci_get_current_frame_number(struct usb_device *usb_dev)
550 555 {
551 556 ohci_t *ohci = &gohci;
552 557  
553   - return m16_swap (ohci->hcca->frame_no);
  558 + return m16_swap(ohci->hcca->frame_no);
554 559 }
555 560 #endif
556 561  
... ... @@ -563,7 +568,7 @@
563 568 * returns the branch and
564 569 * sets the interval to interval = 2^integer (ld (interval)) */
565 570  
566   -static int ep_int_ballance (ohci_t * ohci, int interval, int load)
  571 +static int ep_int_ballance(ohci_t *ohci, int interval, int load)
567 572 {
568 573 int i, branch = 0;
569 574  
570 575  
571 576  
... ... @@ -585,20 +590,19 @@
585 590  
586 591 /* 2^int( ld (inter)) */
587 592  
588   -static int ep_2_n_interval (int inter)
  593 +static int ep_2_n_interval(int inter)
589 594 {
590 595 int i;
591   - for (i = 0; ((inter >> i) > 1 ) && (i < 5); i++);
  596 + for (i = 0; ((inter >> i) > 1) && (i < 5); i++);
592 597 return 1 << i;
593 598 }
594 599  
595 600 /*-------------------------------------------------------------------------*/
596 601  
597 602 /* the int tree is a binary tree
598   - * in order to process it sequentially the indexes of the branches have to be mapped
599   - * the mapping reverses the bits of a word of num_bits length */
600   -
601   -static int ep_rev (int num_bits, int word)
  603 + * in order to process it sequentially the indexes of the branches have to
  604 + * be mapped the mapping reverses the bits of a word of num_bits length */
  605 +static int ep_rev(int num_bits, int word)
602 606 {
603 607 int i, wout = 0;
604 608  
... ... @@ -613,7 +617,7 @@
613 617  
614 618 /* link an ed into one of the HC chains */
615 619  
616   -static int ep_link (ohci_t *ohci, ed_t *edi)
  620 +static int ep_link(ohci_t *ohci, ed_t *edi)
617 621 {
618 622 volatile ed_t *ed = edi;
619 623 int int_branch;
... ... @@ -621,7 +625,7 @@
621 625 int inter;
622 626 int interval;
623 627 int load;
624   - __u32 * ed_p;
  628 + __u32 *ed_p;
625 629  
626 630 ed->state = ED_OPER;
627 631 ed->int_interval = 0;
628 632  
629 633  
630 634  
631 635  
632 636  
633 637  
634 638  
635 639  
... ... @@ -629,49 +633,54 @@
629 633 switch (ed->type) {
630 634 case PIPE_CONTROL:
631 635 ed->hwNextED = 0;
632   - if (ohci->ed_controltail == NULL) {
633   - writel (ed, &ohci->regs->ed_controlhead);
634   - } else {
635   - ohci->ed_controltail->hwNextED = m32_swap ((unsigned long)ed);
636   - }
  636 + if (ohci->ed_controltail == NULL)
  637 + writel(ed, &ohci->regs->ed_controlhead);
  638 + else
  639 + ohci->ed_controltail->hwNextED =
  640 + m32_swap((unsigned long)ed);
  641 +
637 642 ed->ed_prev = ohci->ed_controltail;
638 643 if (!ohci->ed_controltail && !ohci->ed_rm_list[0] &&
639 644 !ohci->ed_rm_list[1] && !ohci->sleeping) {
640 645 ohci->hc_control |= OHCI_CTRL_CLE;
641   - writel (ohci->hc_control, &ohci->regs->control);
  646 + writel(ohci->hc_control, &ohci->regs->control);
642 647 }
643 648 ohci->ed_controltail = edi;
644 649 break;
645 650  
646 651 case PIPE_BULK:
647 652 ed->hwNextED = 0;
648   - if (ohci->ed_bulktail == NULL) {
649   - writel (ed, &ohci->regs->ed_bulkhead);
650   - } else {
651   - ohci->ed_bulktail->hwNextED = m32_swap ((unsigned long)ed);
652   - }
  653 + if (ohci->ed_bulktail == NULL)
  654 + writel(ed, &ohci->regs->ed_bulkhead);
  655 + else
  656 + ohci->ed_bulktail->hwNextED =
  657 + m32_swap((unsigned long)ed);
  658 +
653 659 ed->ed_prev = ohci->ed_bulktail;
654 660 if (!ohci->ed_bulktail && !ohci->ed_rm_list[0] &&
655 661 !ohci->ed_rm_list[1] && !ohci->sleeping) {
656 662 ohci->hc_control |= OHCI_CTRL_BLE;
657   - writel (ohci->hc_control, &ohci->regs->control);
  663 + writel(ohci->hc_control, &ohci->regs->control);
658 664 }
659 665 ohci->ed_bulktail = edi;
660 666 break;
661 667  
662 668 case PIPE_INTERRUPT:
663 669 load = ed->int_load;
664   - interval = ep_2_n_interval (ed->int_period);
  670 + interval = ep_2_n_interval(ed->int_period);
665 671 ed->int_interval = interval;
666   - int_branch = ep_int_ballance (ohci, interval, load);
  672 + int_branch = ep_int_ballance(ohci, interval, load);
667 673 ed->int_branch = int_branch;
668 674  
669   - for (i = 0; i < ep_rev (6, interval); i += inter) {
  675 + for (i = 0; i < ep_rev(6, interval); i += inter) {
670 676 inter = 1;
671   - for (ed_p = &(ohci->hcca->int_table[ep_rev (5, i) + int_branch]);
672   - (*ed_p != 0) && (((ed_t *)ed_p)->int_interval >= interval);
  677 + for (ed_p = &(ohci->hcca->int_table[\
  678 + ep_rev(5, i) + int_branch]);
  679 + (*ed_p != 0) &&
  680 + (((ed_t *)ed_p)->int_interval >= interval);
673 681 ed_p = &(((ed_t *)ed_p)->hwNextED))
674   - inter = ep_rev (6, ((ed_t *)ed_p)->int_interval);
  682 + inter = ep_rev(6,
  683 + ((ed_t *)ed_p)->int_interval);
675 684 ed->hwNextED = *ed_p;
676 685 *ed_p = m32_swap((unsigned long)ed);
677 686 }
678 687  
679 688  
... ... @@ -683,19 +692,21 @@
683 692 /*-------------------------------------------------------------------------*/
684 693  
685 694 /* scan the periodic table to find and unlink this ED */
686   -static void periodic_unlink ( struct ohci *ohci, volatile struct ed *ed,
687   - unsigned index, unsigned period)
  695 +static void periodic_unlink(struct ohci *ohci, volatile struct ed *ed,
  696 + unsigned index, unsigned period)
688 697 {
689 698 for (; index < NUM_INTS; index += period) {
690 699 __u32 *ed_p = &ohci->hcca->int_table [index];
691 700  
692 701 /* ED might have been unlinked through another path */
693 702 while (*ed_p != 0) {
694   - if (((struct ed *)m32_swap ((unsigned long)ed_p)) == ed) {
  703 + if (((struct ed *)
  704 + m32_swap((unsigned long)ed_p)) == ed) {
695 705 *ed_p = ed->hwNextED;
696 706 break;
697 707 }
698   - ed_p = & (((struct ed *)m32_swap ((unsigned long)ed_p))->hwNextED);
  708 + ed_p = &(((struct ed *)
  709 + m32_swap((unsigned long)ed_p))->hwNextED);
699 710 }
700 711 }
701 712 }
702 713  
703 714  
704 715  
705 716  
... ... @@ -705,28 +716,30 @@
705 716 * the link from the ed still points to another operational ed or 0
706 717 * so the HC can eventually finish the processing of the unlinked ed */
707 718  
708   -static int ep_unlink (ohci_t *ohci, ed_t *edi)
  719 +static int ep_unlink(ohci_t *ohci, ed_t *edi)
709 720 {
710 721 volatile ed_t *ed = edi;
711 722 int i;
712 723  
713   - ed->hwINFO |= m32_swap (OHCI_ED_SKIP);
  724 + ed->hwINFO |= m32_swap(OHCI_ED_SKIP);
714 725  
715 726 switch (ed->type) {
716 727 case PIPE_CONTROL:
717 728 if (ed->ed_prev == NULL) {
718 729 if (!ed->hwNextED) {
719 730 ohci->hc_control &= ~OHCI_CTRL_CLE;
720   - writel (ohci->hc_control, &ohci->regs->control);
  731 + writel(ohci->hc_control, &ohci->regs->control);
721 732 }
722   - writel (m32_swap (*((__u32 *)&ed->hwNextED)), &ohci->regs->ed_controlhead);
  733 + writel(m32_swap(*((__u32 *)&ed->hwNextED)),
  734 + &ohci->regs->ed_controlhead);
723 735 } else {
724 736 ed->ed_prev->hwNextED = ed->hwNextED;
725 737 }
726 738 if (ohci->ed_controltail == ed) {
727 739 ohci->ed_controltail = ed->ed_prev;
728 740 } else {
729   - ((ed_t *)m32_swap (*((__u32 *)&ed->hwNextED)))->ed_prev = ed->ed_prev;
  741 + ((ed_t *)m32_swap(
  742 + *((__u32 *)&ed->hwNextED)))->ed_prev = ed->ed_prev;
730 743 }
731 744 break;
732 745  
733 746  
734 747  
735 748  
... ... @@ -734,21 +747,23 @@
734 747 if (ed->ed_prev == NULL) {
735 748 if (!ed->hwNextED) {
736 749 ohci->hc_control &= ~OHCI_CTRL_BLE;
737   - writel (ohci->hc_control, &ohci->regs->control);
  750 + writel(ohci->hc_control, &ohci->regs->control);
738 751 }
739   - writel (m32_swap (*((__u32 *)&ed->hwNextED)), &ohci->regs->ed_bulkhead);
  752 + writel(m32_swap(*((__u32 *)&ed->hwNextED)),
  753 + &ohci->regs->ed_bulkhead);
740 754 } else {
741 755 ed->ed_prev->hwNextED = ed->hwNextED;
742 756 }
743 757 if (ohci->ed_bulktail == ed) {
744 758 ohci->ed_bulktail = ed->ed_prev;
745 759 } else {
746   - ((ed_t *)m32_swap (*((__u32 *)&ed->hwNextED)))->ed_prev = ed->ed_prev;
  760 + ((ed_t *)m32_swap(
  761 + *((__u32 *)&ed->hwNextED)))->ed_prev = ed->ed_prev;
747 762 }
748 763 break;
749 764  
750 765 case PIPE_INTERRUPT:
751   - periodic_unlink (ohci, ed, 0, 1);
  766 + periodic_unlink(ohci, ed, 0, 1);
752 767 for (i = ed->int_branch; i < 32; i += ed->int_interval)
753 768 ohci->ohci_int_load[i] -= ed->int_load;
754 769 break;
755 770  
... ... @@ -767,15 +782,15 @@
767 782 * info fields are setted anyway even though most of them should not
768 783 * change
769 784 */
770   -static ed_t * ep_add_ed (struct usb_device *usb_dev, unsigned long pipe,
771   - int interval, int load)
  785 +static ed_t *ep_add_ed(struct usb_device *usb_dev, unsigned long pipe,
  786 + int interval, int load)
772 787 {
773 788 td_t *td;
774 789 ed_t *ed_ret;
775 790 volatile ed_t *ed;
776 791  
777   - ed = ed_ret = &ohci_dev.ed[(usb_pipeendpoint (pipe) << 1) |
778   - (usb_pipecontrol (pipe)? 0: usb_pipeout (pipe))];
  792 + ed = ed_ret = &ohci_dev.ed[(usb_pipeendpoint(pipe) << 1) |
  793 + (usb_pipecontrol(pipe)? 0: usb_pipeout(pipe))];
779 794  
780 795 if ((ed->state & ED_DEL) || (ed->state & ED_URB_DEL)) {
781 796 err("ep_add_ed: pending delete");
782 797  
783 798  
784 799  
... ... @@ -784,22 +799,22 @@
784 799 }
785 800  
786 801 if (ed->state == ED_NEW) {
787   - ed->hwINFO = m32_swap (OHCI_ED_SKIP); /* skip ed */
788 802 /* dummy td; end of td list for ed */
789   - td = td_alloc (usb_dev);
790   - ed->hwTailP = m32_swap ((unsigned long)td);
  803 + td = td_alloc(usb_dev);
  804 + ed->hwTailP = m32_swap((unsigned long)td);
791 805 ed->hwHeadP = ed->hwTailP;
792 806 ed->state = ED_UNLINK;
793   - ed->type = usb_pipetype (pipe);
  807 + ed->type = usb_pipetype(pipe);
794 808 ohci_dev.ed_cnt++;
795 809 }
796 810  
797   - ed->hwINFO = m32_swap (usb_pipedevice (pipe)
798   - | usb_pipeendpoint (pipe) << 7
799   - | (usb_pipeisoc (pipe)? 0x8000: 0)
800   - | (usb_pipecontrol (pipe)? 0: (usb_pipeout (pipe)? 0x800: 0x1000))
801   - | usb_pipeslow (pipe) << 13
802   - | usb_maxpacket (usb_dev, pipe) << 16);
  811 + ed->hwINFO = m32_swap(usb_pipedevice(pipe)
  812 + | usb_pipeendpoint(pipe) << 7
  813 + | (usb_pipeisoc(pipe)? 0x8000: 0)
  814 + | (usb_pipecontrol(pipe)? 0: \
  815 + (usb_pipeout(pipe)? 0x800: 0x1000))
  816 + | usb_pipeslow(pipe) << 13
  817 + | usb_maxpacket(usb_dev, pipe) << 16);
803 818  
804 819 if (ed->type == PIPE_INTERRUPT && ed->state == ED_UNLINK) {
805 820 ed->int_period = interval;
... ... @@ -815,7 +830,7 @@
815 830  
816 831 /* enqueue next TD for this URB (OHCI spec 5.2.8.2) */
817 832  
818   -static void td_fill (ohci_t *ohci, unsigned int info,
  833 +static void td_fill(ohci_t *ohci, unsigned int info,
819 834 void *data, int len,
820 835 struct usb_device *dev, int index, urb_priv_t *urb_priv)
821 836 {
822 837  
823 838  
824 839  
825 840  
826 841  
827 842  
... ... @@ -833,30 +848,33 @@
833 848 td_pt->hwNextTD = 0;
834 849  
835 850 /* fill the old dummy TD */
836   - td = urb_priv->td [index] = (td_t *)(m32_swap (urb_priv->ed->hwTailP) & ~0xf);
  851 + td = urb_priv->td [index] =
  852 + (td_t *)(m32_swap(urb_priv->ed->hwTailP) & ~0xf);
837 853  
838 854 td->ed = urb_priv->ed;
839 855 td->next_dl_td = NULL;
840 856 td->index = index;
841 857 td->data = (__u32)data;
842 858 #ifdef OHCI_FILL_TRACE
843   - if ((usb_pipetype(urb_priv->pipe) == PIPE_BULK) && usb_pipeout(urb_priv->pipe)) {
  859 + if ((usb_pipetype(urb_priv->pipe) == PIPE_BULK) &&
  860 + usb_pipeout(urb_priv->pipe)) {
844 861 for (i = 0; i < len; i++)
845   - printf("td->data[%d] %#2x ",i, ((unsigned char *)td->data)[i]);
  862 + printf("td->data[%d] %#2x ", i, ((unsigned char *)td->data)[i]);
846 863 printf("\n");
847 864 }
848 865 #endif
849 866 if (!len)
850 867 data = 0;
851 868  
852   - td->hwINFO = m32_swap (info);
853   - td->hwCBP = m32_swap ((unsigned long)data);
  869 + td->hwINFO = m32_swap(info);
  870 + td->hwCBP = m32_swap((unsigned long)data);
854 871 if (data)
855   - td->hwBE = m32_swap ((unsigned long)(data + len - 1));
  872 + td->hwBE = m32_swap((unsigned long)(data + len - 1));
856 873 else
857 874 td->hwBE = 0;
858   - td->hwNextTD = m32_swap ((unsigned long)td_pt);
859 875  
  876 + td->hwNextTD = m32_swap((unsigned long)td_pt);
  877 +
860 878 /* append to queue */
861 879 td->ed->hwTailP = td->hwNextTD;
862 880 }
... ... @@ -865,8 +883,10 @@
865 883  
866 884 /* prepare all TDs of a transfer */
867 885  
868   -static void td_submit_job (struct usb_device *dev, unsigned long pipe, void *buffer,
869   - int transfer_len, struct devrequest *setup, urb_priv_t *urb, int interval)
  886 +static void td_submit_job(struct usb_device *dev, unsigned long pipe,
  887 + void *buffer, int transfer_len,
  888 + struct devrequest *setup, urb_priv_t *urb,
  889 + int interval)
870 890 {
871 891 ohci_t *ohci = &gohci;
872 892 int data_len = transfer_len;
873 893  
... ... @@ -875,12 +895,14 @@
875 895 __u32 info = 0;
876 896 unsigned int toggle = 0;
877 897  
878   - /* OHCI handles the DATA-toggles itself, we just use the USB-toggle bits for reseting */
879   - if(usb_gettoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe))) {
  898 + /* OHCI handles the DATA-toggles itself, we just use the USB-toggle
  899 + * bits for reseting */
  900 + if (usb_gettoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe))) {
880 901 toggle = TD_T_TOGGLE;
881 902 } else {
882 903 toggle = TD_T_DATA0;
883   - usb_settoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe), 1);
  904 + usb_settoggle(dev, usb_pipeendpoint(pipe),
  905 + usb_pipeout(pipe), 1);
884 906 }
885 907 urb->td_cnt = 0;
886 908 if (data_len)
887 909  
888 910  
889 911  
890 912  
891 913  
892 914  
893 915  
894 916  
895 917  
896 918  
897 919  
898 920  
... ... @@ -888,44 +910,58 @@
888 910 else
889 911 data = 0;
890 912  
891   - switch (usb_pipetype (pipe)) {
  913 + switch (usb_pipetype(pipe)) {
892 914 case PIPE_BULK:
893   - info = usb_pipeout (pipe)?
  915 + info = usb_pipeout(pipe)?
894 916 TD_CC | TD_DP_OUT : TD_CC | TD_DP_IN ;
895   - while(data_len > 4096) {
896   - td_fill (ohci, info | (cnt? TD_T_TOGGLE:toggle), data, 4096, dev, cnt, urb);
  917 + while (data_len > 4096) {
  918 + td_fill(ohci, info | (cnt? TD_T_TOGGLE:toggle),
  919 + data, 4096, dev, cnt, urb);
897 920 data += 4096; data_len -= 4096; cnt++;
898 921 }
899   - info = usb_pipeout (pipe)?
  922 + info = usb_pipeout(pipe)?
900 923 TD_CC | TD_DP_OUT : TD_CC | TD_R | TD_DP_IN ;
901   - td_fill (ohci, info | (cnt? TD_T_TOGGLE:toggle), data, data_len, dev, cnt, urb);
  924 + td_fill(ohci, info | (cnt? TD_T_TOGGLE:toggle), data,
  925 + data_len, dev, cnt, urb);
902 926 cnt++;
903 927  
904   - if (!ohci->sleeping)
905   - writel (OHCI_BLF, &ohci->regs->cmdstatus); /* start bulk list */
  928 + if (!ohci->sleeping) {
  929 + /* start bulk list */
  930 + writel(OHCI_BLF, &ohci->regs->cmdstatus);
  931 + }
906 932 break;
907 933  
908 934 case PIPE_CONTROL:
  935 + /* Setup phase */
909 936 info = TD_CC | TD_DP_SETUP | TD_T_DATA0;
910   - td_fill (ohci, info, setup, 8, dev, cnt++, urb);
  937 + td_fill(ohci, info, setup, 8, dev, cnt++, urb);
  938 +
  939 + /* Optional Data phase */
911 940 if (data_len > 0) {
912   - info = usb_pipeout (pipe)?
913   - TD_CC | TD_R | TD_DP_OUT | TD_T_DATA1 : TD_CC | TD_R | TD_DP_IN | TD_T_DATA1;
  941 + info = usb_pipeout(pipe)?
  942 + TD_CC | TD_R | TD_DP_OUT | TD_T_DATA1 :
  943 + TD_CC | TD_R | TD_DP_IN | TD_T_DATA1;
914 944 /* NOTE: mishandles transfers >8K, some >4K */
915   - td_fill (ohci, info, data, data_len, dev, cnt++, urb);
  945 + td_fill(ohci, info, data, data_len, dev, cnt++, urb);
916 946 }
917   - info = usb_pipeout (pipe)?
918   - TD_CC | TD_DP_IN | TD_T_DATA1: TD_CC | TD_DP_OUT | TD_T_DATA1;
919   - td_fill (ohci, info, data, 0, dev, cnt++, urb);
920   - if (!ohci->sleeping)
921   - writel (OHCI_CLF, &ohci->regs->cmdstatus); /* start Control list */
  947 +
  948 + /* Status phase */
  949 + info = usb_pipeout(pipe)?
  950 + TD_CC | TD_DP_IN | TD_T_DATA1:
  951 + TD_CC | TD_DP_OUT | TD_T_DATA1;
  952 + td_fill(ohci, info, data, 0, dev, cnt++, urb);
  953 +
  954 + if (!ohci->sleeping) {
  955 + /* start Control list */
  956 + writel(OHCI_CLF, &ohci->regs->cmdstatus);
  957 + }
922 958 break;
923 959  
924 960 case PIPE_INTERRUPT:
925   - info = usb_pipeout (urb->pipe)?
  961 + info = usb_pipeout(urb->pipe)?
926 962 TD_CC | TD_DP_OUT | toggle:
927 963 TD_CC | TD_R | TD_DP_IN | toggle;
928   - td_fill (ohci, info, data, data_len, dev, cnt++, urb);
  964 + td_fill(ohci, info, data, data_len, dev, cnt++, urb);
929 965 break;
930 966 }
931 967 if (urb->length != cnt)
932 968  
933 969  
... ... @@ -938,16 +974,16 @@
938 974  
939 975 /* calculate the transfer length and update the urb */
940 976  
941   -static void dl_transfer_length(td_t * td)
  977 +static void dl_transfer_length(td_t *td)
942 978 {
943 979 __u32 tdINFO, tdBE, tdCBP;
944 980 urb_priv_t *lurb_priv = td->ed->purb;
945 981  
946   - tdINFO = m32_swap (td->hwINFO);
947   - tdBE = m32_swap (td->hwBE);
948   - tdCBP = m32_swap (td->hwCBP);
  982 + tdINFO = m32_swap(td->hwINFO);
  983 + tdBE = m32_swap(td->hwBE);
  984 + tdCBP = m32_swap(td->hwCBP);
949 985  
950   - if (!(usb_pipetype (lurb_priv->pipe) == PIPE_CONTROL &&
  986 + if (!(usb_pipetype(lurb_priv->pipe) == PIPE_CONTROL &&
951 987 ((td->index == 0) || (td->index == lurb_priv->length - 1)))) {
952 988 if (tdBE != 0) {
953 989 if (td->hwCBP == 0)
954 990  
955 991  
956 992  
957 993  
958 994  
959 995  
960 996  
961 997  
962 998  
963 999  
964 1000  
965 1001  
966 1002  
967 1003  
968 1004  
969 1005  
970 1006  
971 1007  
972 1008  
... ... @@ -959,109 +995,132 @@
959 995 }
960 996  
961 997 /*-------------------------------------------------------------------------*/
  998 +static void check_status(td_t *td_list)
  999 +{
  1000 + urb_priv_t *lurb_priv = td_list->ed->purb;
  1001 + int urb_len = lurb_priv->length;
  1002 + __u32 *phwHeadP = &td_list->ed->hwHeadP;
  1003 + int cc;
962 1004  
  1005 + cc = TD_CC_GET(m32_swap(td_list->hwINFO));
  1006 + if (cc) {
  1007 + err(" USB-error: %s (%x)", cc_to_string[cc], cc);
  1008 +
  1009 + if (*phwHeadP & m32_swap(0x1)) {
  1010 + if (lurb_priv &&
  1011 + ((td_list->index + 1) < urb_len)) {
  1012 + *phwHeadP =
  1013 + (lurb_priv->td[urb_len - 1]->hwNextTD &\
  1014 + m32_swap(0xfffffff0)) |
  1015 + (*phwHeadP & m32_swap(0x2));
  1016 +
  1017 + lurb_priv->td_cnt += urb_len -
  1018 + td_list->index - 1;
  1019 + } else
  1020 + *phwHeadP &= m32_swap(0xfffffff2);
  1021 + }
  1022 +#ifdef CONFIG_MPC5200
  1023 + td_list->hwNextTD = 0;
  1024 +#endif
  1025 + }
  1026 +}
  1027 +
963 1028 /* replies to the request have to be on a FIFO basis so
964 1029 * we reverse the reversed done-list */
965   -
966   -static td_t * dl_reverse_done_list (ohci_t *ohci)
  1030 +static td_t *dl_reverse_done_list(ohci_t *ohci)
967 1031 {
968 1032 __u32 td_list_hc;
969 1033 td_t *td_rev = NULL;
970 1034 td_t *td_list = NULL;
971   - urb_priv_t *lurb_priv = NULL;
972 1035  
973   - td_list_hc = m32_swap (ohci->hcca->done_head) & 0xfffffff0;
  1036 + td_list_hc = m32_swap(ohci->hcca->done_head) & 0xfffffff0;
974 1037 ohci->hcca->done_head = 0;
975 1038  
976 1039 while (td_list_hc) {
977 1040 td_list = (td_t *)td_list_hc;
978   -
979   - if (TD_CC_GET (m32_swap (td_list->hwINFO))) {
980   - lurb_priv = td_list->ed->purb;
981   - dbg(" USB-error/status: %x : %p",
982   - TD_CC_GET (m32_swap (td_list->hwINFO)), td_list);
983   - if (td_list->ed->hwHeadP & m32_swap (0x1)) {
984   - if (lurb_priv && ((td_list->index + 1) < lurb_priv->length)) {
985   - td_list->ed->hwHeadP =
986   - (lurb_priv->td[lurb_priv->length - 1]->hwNextTD & m32_swap (0xfffffff0)) |
987   - (td_list->ed->hwHeadP & m32_swap (0x2));
988   - lurb_priv->td_cnt += lurb_priv->length - td_list->index - 1;
989   - } else
990   - td_list->ed->hwHeadP &= m32_swap (0xfffffff2);
991   - }
992   -#ifdef CONFIG_MPC5200
993   - td_list->hwNextTD = 0;
994   -#endif
995   - }
996   -
  1041 + check_status(td_list);
997 1042 td_list->next_dl_td = td_rev;
998 1043 td_rev = td_list;
999   - td_list_hc = m32_swap (td_list->hwNextTD) & 0xfffffff0;
  1044 + td_list_hc = m32_swap(td_list->hwNextTD) & 0xfffffff0;
1000 1045 }
1001 1046 return td_list;
1002 1047 }
1003 1048  
1004 1049 /*-------------------------------------------------------------------------*/
  1050 +/*-------------------------------------------------------------------------*/
1005 1051  
1006   -/* td done list */
1007   -static int dl_done_list (ohci_t *ohci, td_t *td_list)
  1052 +static void finish_urb(ohci_t *ohci, urb_priv_t *urb, int status)
1008 1053 {
1009   - td_t *td_list_next = NULL;
  1054 + if ((status & (ED_OPER | ED_UNLINK)) && (urb->state != URB_DEL))
  1055 + urb->finished = sohci_return_job(ohci, urb);
  1056 + else
  1057 + dbg("finish_urb: strange.., ED state %x, \n", status);
  1058 +}
  1059 +
  1060 +/*
  1061 + * Used to take back a TD from the host controller. This would normally be
  1062 + * called from within dl_done_list, however it may be called directly if the
  1063 + * HC no longer sees the TD and it has not appeared on the donelist (after
  1064 + * two frames). This bug has been observed on ZF Micro systems.
  1065 + */
  1066 +static int takeback_td(ohci_t *ohci, td_t *td_list)
  1067 +{
1010 1068 ed_t *ed;
1011   - int cc = 0;
  1069 + int cc;
1012 1070 int stat = 0;
1013 1071 /* urb_t *urb; */
1014 1072 urb_priv_t *lurb_priv;
1015 1073 __u32 tdINFO, edHeadP, edTailP;
1016 1074  
1017   - while (td_list) {
1018   - td_list_next = td_list->next_dl_td;
  1075 + tdINFO = m32_swap(td_list->hwINFO);
1019 1076  
1020   - tdINFO = m32_swap (td_list->hwINFO);
  1077 + ed = td_list->ed;
  1078 + lurb_priv = ed->purb;
1021 1079  
1022   - ed = td_list->ed;
1023   - lurb_priv = ed->purb;
  1080 + dl_transfer_length(td_list);
1024 1081  
1025   - dl_transfer_length(td_list);
  1082 + lurb_priv->td_cnt++;
1026 1083  
1027   - /* error code of transfer */
1028   - cc = TD_CC_GET (tdINFO);
1029   - if (cc != 0) {
1030   - dbg("ConditionCode %#x", cc);
1031   - stat = cc_to_error[cc];
1032   - }
  1084 + /* error code of transfer */
  1085 + cc = TD_CC_GET(tdINFO);
  1086 + if (cc) {
  1087 + err("USB-error: %s (%x)", cc_to_string[cc], cc);
  1088 + stat = cc_to_error[cc];
  1089 + }
1033 1090  
1034   - /* see if this done list makes for all TD's of current URB,
1035   - * and mark the URB finished if so */
1036   - if (++(lurb_priv->td_cnt) == lurb_priv->length) {
1037   -#if 1
1038   - if ((ed->state & (ED_OPER | ED_UNLINK)) &&
1039   - (lurb_priv->state != URB_DEL))
1040   -#else
1041   - if ((ed->state & (ED_OPER | ED_UNLINK)))
1042   -#endif
1043   - lurb_priv->finished = sohci_return_job(ohci,
1044   - lurb_priv);
1045   - else
1046   - dbg("dl_done_list: strange.., ED state %x, ed->state\n");
1047   - } else
1048   - dbg("dl_done_list: processing TD %x, len %x\n", lurb_priv->td_cnt,
1049   - lurb_priv->length);
1050   - if (ed->state != ED_NEW &&
1051   - (usb_pipetype (lurb_priv->pipe) != PIPE_INTERRUPT)) {
1052   - edHeadP = m32_swap (ed->hwHeadP) & 0xfffffff0;
1053   - edTailP = m32_swap (ed->hwTailP);
  1091 + /* see if this done list makes for all TD's of current URB,
  1092 + * and mark the URB finished if so */
  1093 + if (lurb_priv->td_cnt == lurb_priv->length)
  1094 + finish_urb(ohci, lurb_priv, ed->state);
1054 1095  
1055   - /* unlink eds if they are not busy */
1056   - if ((edHeadP == edTailP) && (ed->state == ED_OPER))
1057   - ep_unlink (ohci, ed);
1058   - }
  1096 + dbg("dl_done_list: processing TD %x, len %x\n",
  1097 + lurb_priv->td_cnt, lurb_priv->length);
1059 1098  
1060   - td_list = td_list_next;
  1099 + if (ed->state != ED_NEW &&
  1100 + (usb_pipetype(lurb_priv->pipe) != PIPE_INTERRUPT)) {
  1101 + edHeadP = m32_swap(ed->hwHeadP) & 0xfffffff0;
  1102 + edTailP = m32_swap(ed->hwTailP);
  1103 +
  1104 + /* unlink eds if they are not busy */
  1105 + if ((edHeadP == edTailP) && (ed->state == ED_OPER))
  1106 + ep_unlink(ohci, ed);
1061 1107 }
1062 1108 return stat;
1063 1109 }
1064 1110  
  1111 +static int dl_done_list(ohci_t *ohci)
  1112 +{
  1113 + int stat = 0;
  1114 + td_t *td_list = dl_reverse_done_list(ohci);
  1115 +
  1116 + while (td_list) {
  1117 + td_t *td_next = td_list->next_dl_td;
  1118 + stat = takeback_td(ohci, td_list);
  1119 + td_list = td_next;
  1120 + }
  1121 + return stat;
  1122 +}
  1123 +
1065 1124 /*-------------------------------------------------------------------------*
1066 1125 * Virtual Root Hub
1067 1126 *-------------------------------------------------------------------------*/
... ... @@ -1100,7 +1159,7 @@
1100 1159 0x01, /* __u8 bConfigurationValue; */
1101 1160 0x00, /* __u8 iConfiguration; */
1102 1161 0x40, /* __u8 bmAttributes;
1103   - Bit 7: Bus-powered, 6: Self-powered, 5 Remote-wakwup, 4..0: resvd */
  1162 + Bit 7: Bus-powered, 6: Self-powered, 5 Remote-wakwup, 4..0: resvd */
1104 1163 0x00, /* __u8 MaxPower; */
1105 1164  
1106 1165 /* interface */
1107 1166  
1108 1167  
... ... @@ -1170,14 +1229,17 @@
1170 1229  
1171 1230 #define OK(x) len = (x); break
1172 1231 #ifdef DEBUG
1173   -#define WR_RH_STAT(x) {info("WR:status %#8x", (x));writel((x), &gohci.regs->roothub.status);}
1174   -#define WR_RH_PORTSTAT(x) {info("WR:portstatus[%d] %#8x", wIndex-1, (x));writel((x), &gohci.regs->roothub.portstatus[wIndex-1]);}
  1232 +#define WR_RH_STAT(x) {info("WR:status %#8x", (x)); writel((x), \
  1233 + &gohci.regs->roothub.status); }
  1234 +#define WR_RH_PORTSTAT(x) {info("WR:portstatus[%d] %#8x", wIndex-1, \
  1235 + (x)); writel((x), &gohci.regs->roothub.portstatus[wIndex-1]); }
1175 1236 #else
1176 1237 #define WR_RH_STAT(x) writel((x), &gohci.regs->roothub.status)
1177   -#define WR_RH_PORTSTAT(x) writel((x), &gohci.regs->roothub.portstatus[wIndex-1])
  1238 +#define WR_RH_PORTSTAT(x) writel((x), \
  1239 + &gohci.regs->roothub.portstatus[wIndex-1])
1178 1240 #endif
1179 1241 #define RD_RH_STAT roothub_status(&gohci)
1180   -#define RD_RH_PORTSTAT roothub_portstatus(&gohci,wIndex-1)
  1242 +#define RD_RH_PORTSTAT roothub_portstatus(&gohci, wIndex-1)
1181 1243  
1182 1244 /* request to virtual root hub */
1183 1245  
1184 1246  
... ... @@ -1187,13 +1249,13 @@
1187 1249 int res;
1188 1250  
1189 1251 res = -1;
1190   - temp = roothub_a (controller);
  1252 + temp = roothub_a(controller);
1191 1253 ndp = (temp & RH_A_NDP);
1192 1254 #ifdef CONFIG_AT91C_PQFP_UHPBUG
1193 1255 ndp = (ndp == 2) ? 1:0;
1194 1256 #endif
1195 1257 for (i = 0; i < ndp; i++) {
1196   - temp = roothub_portstatus (controller, i);
  1258 + temp = roothub_portstatus(controller, i);
1197 1259 /* check for a device disconnect */
1198 1260 if (((temp & (RH_PS_PESC | RH_PS_CSC)) ==
1199 1261 (RH_PS_PESC | RH_PS_CSC)) &&
... ... @@ -1208,7 +1270,7 @@
1208 1270 static int ohci_submit_rh_msg(struct usb_device *dev, unsigned long pipe,
1209 1271 void *buffer, int transfer_len, struct devrequest *cmd)
1210 1272 {
1211   - void * data = buffer;
  1273 + void *data = buffer;
1212 1274 int leni = transfer_len;
1213 1275 int len = 0;
1214 1276 int stat = 0;
... ... @@ -1220,7 +1282,8 @@
1220 1282 __u16 wLength;
1221 1283  
1222 1284 #ifdef DEBUG
1223   -pkt_print(NULL, dev, pipe, buffer, transfer_len, cmd, "SUB(rh)", usb_pipein(pipe));
  1285 +pkt_print(NULL, dev, pipe, buffer, transfer_len,
  1286 + cmd, "SUB(rh)", usb_pipein(pipe));
1224 1287 #else
1225 1288 wait_ms(1);
1226 1289 #endif
... ... @@ -1230,9 +1293,9 @@
1230 1293 }
1231 1294  
1232 1295 bmRType_bReq = cmd->requesttype | (cmd->request << 8);
1233   - wValue = le16_to_cpu (cmd->value);
1234   - wIndex = le16_to_cpu (cmd->index);
1235   - wLength = le16_to_cpu (cmd->length);
  1296 + wValue = le16_to_cpu(cmd->value);
  1297 + wIndex = le16_to_cpu(cmd->index);
  1298 + wLength = le16_to_cpu(cmd->length);
1236 1299  
1237 1300 info("Root-Hub: adr: %2x cmd(%1x): %08x %04x %04x %04x",
1238 1301 dev->devnum, 8, bmRType_bReq, wValue, wIndex, wLength);
1239 1302  
1240 1303  
1241 1304  
1242 1305  
1243 1306  
1244 1307  
1245 1308  
1246 1309  
1247 1310  
1248 1311  
1249 1312  
1250 1313  
1251 1314  
1252 1315  
1253 1316  
... ... @@ -1247,118 +1310,118 @@
1247 1310 */
1248 1311  
1249 1312 case RH_GET_STATUS:
1250   - *(__u16 *) data_buf = cpu_to_le16 (1); OK (2);
  1313 + *(__u16 *) data_buf = cpu_to_le16(1);
  1314 + OK(2);
1251 1315 case RH_GET_STATUS | RH_INTERFACE:
1252   - *(__u16 *) data_buf = cpu_to_le16 (0); OK (2);
  1316 + *(__u16 *) data_buf = cpu_to_le16(0);
  1317 + OK(2);
1253 1318 case RH_GET_STATUS | RH_ENDPOINT:
1254   - *(__u16 *) data_buf = cpu_to_le16 (0); OK (2);
  1319 + *(__u16 *) data_buf = cpu_to_le16(0);
  1320 + OK(2);
1255 1321 case RH_GET_STATUS | RH_CLASS:
1256   - *(__u32 *) data_buf = cpu_to_le32 (
  1322 + *(__u32 *) data_buf = cpu_to_le32(
1257 1323 RD_RH_STAT & ~(RH_HS_CRWE | RH_HS_DRWE));
1258   - OK (4);
  1324 + OK(4);
1259 1325 case RH_GET_STATUS | RH_OTHER | RH_CLASS:
1260   - *(__u32 *) data_buf = cpu_to_le32 (RD_RH_PORTSTAT); OK (4);
  1326 + *(__u32 *) data_buf = cpu_to_le32(RD_RH_PORTSTAT);
  1327 + OK(4);
1261 1328  
1262 1329 case RH_CLEAR_FEATURE | RH_ENDPOINT:
1263 1330 switch (wValue) {
1264   - case (RH_ENDPOINT_STALL): OK (0);
  1331 + case (RH_ENDPOINT_STALL):
  1332 + OK(0);
1265 1333 }
1266 1334 break;
1267 1335  
1268 1336 case RH_CLEAR_FEATURE | RH_CLASS:
1269 1337 switch (wValue) {
1270   - case RH_C_HUB_LOCAL_POWER:
1271   - OK(0);
1272   - case (RH_C_HUB_OVER_CURRENT):
1273   - WR_RH_STAT(RH_HS_OCIC); OK (0);
  1338 + case RH_C_HUB_LOCAL_POWER:
  1339 + OK(0);
  1340 + case (RH_C_HUB_OVER_CURRENT):
  1341 + WR_RH_STAT(RH_HS_OCIC);
  1342 + OK(0);
1274 1343 }
1275 1344 break;
1276 1345  
1277 1346 case RH_CLEAR_FEATURE | RH_OTHER | RH_CLASS:
1278 1347 switch (wValue) {
1279   - case (RH_PORT_ENABLE):
1280   - WR_RH_PORTSTAT (RH_PS_CCS ); OK (0);
1281   - case (RH_PORT_SUSPEND):
1282   - WR_RH_PORTSTAT (RH_PS_POCI); OK (0);
1283   - case (RH_PORT_POWER):
1284   - WR_RH_PORTSTAT (RH_PS_LSDA); OK (0);
1285   - case (RH_C_PORT_CONNECTION):
1286   - WR_RH_PORTSTAT (RH_PS_CSC ); OK (0);
1287   - case (RH_C_PORT_ENABLE):
1288   - WR_RH_PORTSTAT (RH_PS_PESC); OK (0);
1289   - case (RH_C_PORT_SUSPEND):
1290   - WR_RH_PORTSTAT (RH_PS_PSSC); OK (0);
1291   - case (RH_C_PORT_OVER_CURRENT):
1292   - WR_RH_PORTSTAT (RH_PS_OCIC); OK (0);
1293   - case (RH_C_PORT_RESET):
1294   - WR_RH_PORTSTAT (RH_PS_PRSC); OK (0);
  1348 + case (RH_PORT_ENABLE): WR_RH_PORTSTAT(RH_PS_CCS); OK(0);
  1349 + case (RH_PORT_SUSPEND): WR_RH_PORTSTAT(RH_PS_POCI); OK(0);
  1350 + case (RH_PORT_POWER): WR_RH_PORTSTAT(RH_PS_LSDA); OK(0);
  1351 + case (RH_C_PORT_CONNECTION): WR_RH_PORTSTAT(RH_PS_CSC); OK(0);
  1352 + case (RH_C_PORT_ENABLE): WR_RH_PORTSTAT(RH_PS_PESC); OK(0);
  1353 + case (RH_C_PORT_SUSPEND): WR_RH_PORTSTAT(RH_PS_PSSC); OK(0);
  1354 + case (RH_C_PORT_OVER_CURRENT):WR_RH_PORTSTAT(RH_PS_OCIC); OK(0);
  1355 + case (RH_C_PORT_RESET): WR_RH_PORTSTAT(RH_PS_PRSC); OK(0);
1295 1356 }
1296 1357 break;
1297 1358  
1298 1359 case RH_SET_FEATURE | RH_OTHER | RH_CLASS:
1299 1360 switch (wValue) {
1300   - case (RH_PORT_SUSPEND):
1301   - WR_RH_PORTSTAT (RH_PS_PSS ); OK (0);
1302   - case (RH_PORT_RESET): /* BUG IN HUP CODE *********/
1303   - if (RD_RH_PORTSTAT & RH_PS_CCS)
1304   - WR_RH_PORTSTAT (RH_PS_PRS);
1305   - OK (0);
1306   - case (RH_PORT_POWER):
1307   - WR_RH_PORTSTAT (RH_PS_PPS );
1308   - wait_ms(100);
1309   - OK (0);
1310   - case (RH_PORT_ENABLE): /* BUG IN HUP CODE *********/
1311   - if (RD_RH_PORTSTAT & RH_PS_CCS)
1312   - WR_RH_PORTSTAT (RH_PS_PES );
1313   - OK (0);
  1361 + case (RH_PORT_SUSPEND):
  1362 + WR_RH_PORTSTAT(RH_PS_PSS); OK(0);
  1363 + case (RH_PORT_RESET): /* BUG IN HUP CODE *********/
  1364 + if (RD_RH_PORTSTAT & RH_PS_CCS)
  1365 + WR_RH_PORTSTAT(RH_PS_PRS);
  1366 + OK(0);
  1367 + case (RH_PORT_POWER):
  1368 + WR_RH_PORTSTAT(RH_PS_PPS);
  1369 + wait_ms(100);
  1370 + OK(0);
  1371 + case (RH_PORT_ENABLE): /* BUG IN HUP CODE *********/
  1372 + if (RD_RH_PORTSTAT & RH_PS_CCS)
  1373 + WR_RH_PORTSTAT(RH_PS_PES);
  1374 + OK(0);
1314 1375 }
1315 1376 break;
1316 1377  
1317   - case RH_SET_ADDRESS: gohci.rh.devnum = wValue; OK(0);
  1378 + case RH_SET_ADDRESS:
  1379 + gohci.rh.devnum = wValue;
  1380 + OK(0);
1318 1381  
1319 1382 case RH_GET_DESCRIPTOR:
1320 1383 switch ((wValue & 0xff00) >> 8) {
1321   - case (0x01): /* device descriptor */
  1384 + case (0x01): /* device descriptor */
  1385 + len = min_t(unsigned int,
  1386 + leni,
  1387 + min_t(unsigned int,
  1388 + sizeof(root_hub_dev_des),
  1389 + wLength));
  1390 + data_buf = root_hub_dev_des; OK(len);
  1391 + case (0x02): /* configuration descriptor */
  1392 + len = min_t(unsigned int,
  1393 + leni,
  1394 + min_t(unsigned int,
  1395 + sizeof(root_hub_config_des),
  1396 + wLength));
  1397 + data_buf = root_hub_config_des; OK(len);
  1398 + case (0x03): /* string descriptors */
  1399 + if (wValue == 0x0300) {
1322 1400 len = min_t(unsigned int,
1323   - leni,
1324   - min_t(unsigned int,
1325   - sizeof (root_hub_dev_des),
1326   - wLength));
1327   - data_buf = root_hub_dev_des; OK(len);
1328   - case (0x02): /* configuration descriptor */
1329   - len = min_t(unsigned int,
1330   - leni,
1331   - min_t(unsigned int,
1332   - sizeof (root_hub_config_des),
1333   - wLength));
1334   - data_buf = root_hub_config_des; OK(len);
1335   - case (0x03): /* string descriptors */
1336   - if(wValue==0x0300) {
1337   - len = min_t(unsigned int,
1338   - leni,
1339   - min_t(unsigned int,
1340   - sizeof (root_hub_str_index0),
1341   - wLength));
1342   - data_buf = root_hub_str_index0;
1343   - OK(len);
1344   - }
1345   - if(wValue==0x0301) {
1346   - len = min_t(unsigned int,
1347   - leni,
1348   - min_t(unsigned int,
1349   - sizeof (root_hub_str_index1),
1350   - wLength));
1351   - data_buf = root_hub_str_index1;
1352   - OK(len);
  1401 + leni,
  1402 + min_t(unsigned int,
  1403 + sizeof(root_hub_str_index0),
  1404 + wLength));
  1405 + data_buf = root_hub_str_index0;
  1406 + OK(len);
1353 1407 }
1354   - default:
1355   - stat = USB_ST_STALLED;
  1408 + if (wValue == 0x0301) {
  1409 + len = min_t(unsigned int,
  1410 + leni,
  1411 + min_t(unsigned int,
  1412 + sizeof(root_hub_str_index1),
  1413 + wLength));
  1414 + data_buf = root_hub_str_index1;
  1415 + OK(len);
1356 1416 }
  1417 + default:
  1418 + stat = USB_ST_STALLED;
  1419 + }
1357 1420 break;
1358 1421  
1359 1422 case RH_GET_DESCRIPTOR | RH_CLASS:
1360 1423 {
1361   - __u32 temp = roothub_a (&gohci);
  1424 + __u32 temp = roothub_a(&gohci);
1362 1425  
1363 1426 data_buf [0] = 9; /* min length; */
1364 1427 data_buf [1] = 0x29;
1365 1428  
... ... @@ -1371,13 +1434,13 @@
1371 1434 data_buf [3] |= 0x1;
1372 1435 if (temp & RH_A_NOCP) /* no overcurrent reporting? */
1373 1436 data_buf [3] |= 0x10;
1374   - else if (temp & RH_A_OCPM) /* per-port overcurrent reporting? */
  1437 + else if (temp & RH_A_OCPM)/* per-port overcurrent reporting? */
1375 1438 data_buf [3] |= 0x8;
1376 1439  
1377 1440 /* corresponds to data_buf[4-7] */
1378 1441 datab [1] = 0;
1379 1442 data_buf [5] = (temp & RH_A_POTPGT) >> 24;
1380   - temp = roothub_b (&gohci);
  1443 + temp = roothub_b(&gohci);
1381 1444 data_buf [7] = temp & RH_B_DR;
1382 1445 if (data_buf [2] < 7) {
1383 1446 data_buf [8] = 0xff;
1384 1447  
1385 1448  
1386 1449  
1387 1450  
1388 1451  
1389 1452  
... ... @@ -1389,32 +1452,33 @@
1389 1452  
1390 1453 len = min_t(unsigned int, leni,
1391 1454 min_t(unsigned int, data_buf [0], wLength));
1392   - OK (len);
  1455 + OK(len);
1393 1456 }
1394 1457  
1395   - case RH_GET_CONFIGURATION: *(__u8 *) data_buf = 0x01; OK (1);
  1458 + case RH_GET_CONFIGURATION: *(__u8 *) data_buf = 0x01; OK(1);
1396 1459  
1397   - case RH_SET_CONFIGURATION: WR_RH_STAT (0x10000); OK (0);
  1460 + case RH_SET_CONFIGURATION: WR_RH_STAT(0x10000); OK(0);
1398 1461  
1399 1462 default:
1400   - dbg ("unsupported root hub command");
  1463 + dbg("unsupported root hub command");
1401 1464 stat = USB_ST_STALLED;
1402 1465 }
1403 1466  
1404 1467 #ifdef DEBUG
1405   - ohci_dump_roothub (&gohci, 1);
  1468 + ohci_dump_roothub(&gohci, 1);
1406 1469 #else
1407 1470 wait_ms(1);
1408 1471 #endif
1409 1472  
1410 1473 len = min_t(int, len, leni);
1411 1474 if (data != data_buf)
1412   - memcpy (data, data_buf, len);
  1475 + memcpy(data, data_buf, len);
1413 1476 dev->act_len = len;
1414 1477 dev->status = stat;
1415 1478  
1416 1479 #ifdef DEBUG
1417   - pkt_print(NULL, dev, pipe, buffer, transfer_len, cmd, "RET(rh)", 0/*usb_pipein(pipe)*/);
  1480 + pkt_print(NULL, dev, pipe, buffer,
  1481 + transfer_len, cmd, "RET(rh)", 0/*usb_pipein(pipe)*/);
1418 1482 #else
1419 1483 wait_ms(1);
1420 1484 #endif
... ... @@ -1451,7 +1515,8 @@
1451 1515  
1452 1516 #ifdef DEBUG
1453 1517 urb->actual_length = 0;
1454   - pkt_print(urb, dev, pipe, buffer, transfer_len, setup, "SUB", usb_pipein(pipe));
  1518 + pkt_print(urb, dev, pipe, buffer, transfer_len,
  1519 + setup, "SUB", usb_pipein(pipe));
1455 1520 #else
1456 1521 wait_ms(1);
1457 1522 #endif
... ... @@ -1473,7 +1538,7 @@
1473 1538  
1474 1539 /* allow more time for a BULK device to react - some are slow */
1475 1540 #define BULK_TO 5000 /* timeout in milliseconds */
1476   - if (usb_pipetype (pipe) == PIPE_BULK)
  1541 + if (usb_pipetype(pipe) == PIPE_BULK)
1477 1542 timeout = BULK_TO;
1478 1543 else
1479 1544 timeout = 100;
... ... @@ -1504,7 +1569,7 @@
1504 1569 if (--timeout) {
1505 1570 wait_ms(1);
1506 1571 if (!urb->finished)
1507   - dbg("\%");
  1572 + dbg("*");
1508 1573  
1509 1574 } else {
1510 1575 err("CTL:TIMEOUT ");
1511 1576  
... ... @@ -1519,14 +1584,15 @@
1519 1584 dev->act_len = transfer_len;
1520 1585  
1521 1586 #ifdef DEBUG
1522   - pkt_print(urb, dev, pipe, buffer, transfer_len, setup, "RET(ctlr)", usb_pipein(pipe));
  1587 + pkt_print(urb, dev, pipe, buffer, transfer_len,
  1588 + setup, "RET(ctlr)", usb_pipein(pipe));
1523 1589 #else
1524 1590 wait_ms(1);
1525 1591 #endif
1526 1592  
1527 1593 /* free TDs in urb_priv */
1528   - if (usb_pipetype (pipe) != PIPE_INTERRUPT)
1529   - urb_free_priv (urb);
  1594 + if (usb_pipetype(pipe) != PIPE_INTERRUPT)
  1595 + urb_free_priv(urb);
1530 1596 return 0;
1531 1597 }
1532 1598  
... ... @@ -1545,7 +1611,8 @@
1545 1611  
1546 1612 info("submit_control_msg");
1547 1613 #ifdef DEBUG
1548   - pkt_print(NULL, dev, pipe, buffer, transfer_len, setup, "SUB", usb_pipein(pipe));
  1614 + pkt_print(NULL, dev, pipe, buffer, transfer_len,
  1615 + setup, "SUB", usb_pipein(pipe));
1549 1616 #else
1550 1617 wait_ms(1);
1551 1618 #endif
... ... @@ -1578,7 +1645,7 @@
1578 1645  
1579 1646 /* reset the HC and BUS */
1580 1647  
1581   -static int hc_reset (ohci_t *ohci)
  1648 +static int hc_reset(ohci_t *ohci)
1582 1649 {
1583 1650 #ifdef CONFIG_PCI_EHCI_DEVNO
1584 1651 pci_dev_t pdev;
... ... @@ -1599,7 +1666,7 @@
1599 1666 int timeout = 1000;
1600 1667  
1601 1668 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &base);
1602   - writel (readl(base + EHCI_USBCMD_OFF) | EHCI_USBCMD_HCRESET,
  1669 + writel(readl(base + EHCI_USBCMD_OFF) | EHCI_USBCMD_HCRESET,
1603 1670 base + EHCI_USBCMD_OFF);
1604 1671  
1605 1672 while (readl(base + EHCI_USBCMD_OFF) & EHCI_USBCMD_HCRESET) {
1606 1673  
... ... @@ -1612,11 +1679,12 @@
1612 1679 } else
1613 1680 printf("No EHCI func at %d index!\n", CONFIG_PCI_EHCI_DEVNO);
1614 1681 #endif
1615   - if (readl (&ohci->regs->control) & OHCI_CTRL_IR) { /* SMM owns the HC */
1616   - writel (OHCI_OCR, &ohci->regs->cmdstatus); /* request ownership */
  1682 + if (readl(&ohci->regs->control) & OHCI_CTRL_IR) {
  1683 + /* SMM owns the HC */
  1684 + writel(OHCI_OCR, &ohci->regs->cmdstatus);/* request ownership */
1617 1685 info("USB HC TakeOver from SMM");
1618   - while (readl (&ohci->regs->control) & OHCI_CTRL_IR) {
1619   - wait_ms (10);
  1686 + while (readl(&ohci->regs->control) & OHCI_CTRL_IR) {
  1687 + wait_ms(10);
1620 1688 if (--smm_timeout == 0) {
1621 1689 err("USB HC TakeOver failed!");
1622 1690 return -1;
... ... @@ -1625,7 +1693,7 @@
1625 1693 }
1626 1694  
1627 1695 /* Disable HC interrupts */
1628   - writel (OHCI_INTR_MIE, &ohci->regs->intrdisable);
  1696 + writel(OHCI_INTR_MIE, &ohci->regs->intrdisable);
1629 1697  
1630 1698 dbg("USB HC reset_hc usb-%s: ctrl = 0x%X ;\n",
1631 1699 ohci->slot_name,
1632 1700  
1633 1701  
... ... @@ -1633,16 +1701,16 @@
1633 1701  
1634 1702 /* Reset USB (needed by some controllers) */
1635 1703 ohci->hc_control = 0;
1636   - writel (ohci->hc_control, &ohci->regs->control);
  1704 + writel(ohci->hc_control, &ohci->regs->control);
1637 1705  
1638 1706 /* HC Reset requires max 10 us delay */
1639   - writel (OHCI_HCR, &ohci->regs->cmdstatus);
1640   - while ((readl (&ohci->regs->cmdstatus) & OHCI_HCR) != 0) {
  1707 + writel(OHCI_HCR, &ohci->regs->cmdstatus);
  1708 + while ((readl(&ohci->regs->cmdstatus) & OHCI_HCR) != 0) {
1641 1709 if (--timeout == 0) {
1642 1710 err("USB HC reset timed out!");
1643 1711 return -1;
1644 1712 }
1645   - udelay (1);
  1713 + udelay(1);
1646 1714 }
1647 1715 return 0;
1648 1716 }
... ... @@ -1653,7 +1721,7 @@
1653 1721 * enable interrupts
1654 1722 * connect the virtual root hub */
1655 1723  
1656   -static int hc_start (ohci_t * ohci)
  1724 +static int hc_start(ohci_t *ohci)
1657 1725 {
1658 1726 __u32 mask;
1659 1727 unsigned int fminterval;
1660 1728  
1661 1729  
1662 1730  
1663 1731  
1664 1732  
1665 1733  
1666 1734  
1667 1735  
1668 1736  
1669 1737  
1670 1738  
... ... @@ -1663,44 +1731,44 @@
1663 1731 /* Tell the controller where the control and bulk lists are
1664 1732 * The lists are empty now. */
1665 1733  
1666   - writel (0, &ohci->regs->ed_controlhead);
1667   - writel (0, &ohci->regs->ed_bulkhead);
  1734 + writel(0, &ohci->regs->ed_controlhead);
  1735 + writel(0, &ohci->regs->ed_bulkhead);
1668 1736  
1669   - writel ((__u32)ohci->hcca, &ohci->regs->hcca); /* a reset clears this */
  1737 + writel((__u32)ohci->hcca, &ohci->regs->hcca); /* a reset clears this */
1670 1738  
1671 1739 fminterval = 0x2edf;
1672   - writel ((fminterval * 9) / 10, &ohci->regs->periodicstart);
  1740 + writel((fminterval * 9) / 10, &ohci->regs->periodicstart);
1673 1741 fminterval |= ((((fminterval - 210) * 6) / 7) << 16);
1674   - writel (fminterval, &ohci->regs->fminterval);
1675   - writel (0x628, &ohci->regs->lsthresh);
  1742 + writel(fminterval, &ohci->regs->fminterval);
  1743 + writel(0x628, &ohci->regs->lsthresh);
1676 1744  
1677 1745 /* start controller operations */
1678 1746 ohci->hc_control = OHCI_CONTROL_INIT | OHCI_USB_OPER;
1679 1747 ohci->disabled = 0;
1680   - writel (ohci->hc_control, &ohci->regs->control);
  1748 + writel(ohci->hc_control, &ohci->regs->control);
1681 1749  
1682 1750 /* disable all interrupts */
1683 1751 mask = (OHCI_INTR_SO | OHCI_INTR_WDH | OHCI_INTR_SF | OHCI_INTR_RD |
1684 1752 OHCI_INTR_UE | OHCI_INTR_FNO | OHCI_INTR_RHSC |
1685 1753 OHCI_INTR_OC | OHCI_INTR_MIE);
1686   - writel (mask, &ohci->regs->intrdisable);
  1754 + writel(mask, &ohci->regs->intrdisable);
1687 1755 /* clear all interrupts */
1688 1756 mask &= ~OHCI_INTR_MIE;
1689   - writel (mask, &ohci->regs->intrstatus);
  1757 + writel(mask, &ohci->regs->intrstatus);
1690 1758 /* Choose the interrupts we care about now - but w/o MIE */
1691 1759 mask = OHCI_INTR_RHSC | OHCI_INTR_UE | OHCI_INTR_WDH | OHCI_INTR_SO;
1692   - writel (mask, &ohci->regs->intrenable);
  1760 + writel(mask, &ohci->regs->intrenable);
1693 1761  
1694 1762 #ifdef OHCI_USE_NPS
1695 1763 /* required for AMD-756 and some Mac platforms */
1696   - writel ((roothub_a (ohci) | RH_A_NPS) & ~RH_A_PSM,
  1764 + writel((roothub_a(ohci) | RH_A_NPS) & ~RH_A_PSM,
1697 1765 &ohci->regs->roothub.a);
1698   - writel (RH_HS_LPSC, &ohci->regs->roothub.status);
  1766 + writel(RH_HS_LPSC, &ohci->regs->roothub.status);
1699 1767 #endif /* OHCI_USE_NPS */
1700 1768  
1701   -#define mdelay(n) ({unsigned long msec=(n); while (msec--) udelay(1000);})
  1769 +#define mdelay(n) ({unsigned long msec = (n); while (msec--) udelay(1000); })
1702 1770 /* POTPGT delay is bits 24-31, in 2 ms units. */
1703   - mdelay ((roothub_a (ohci) >> 23) & 0x1fe);
  1771 + mdelay((roothub_a(ohci) >> 23) & 0x1fe);
1704 1772  
1705 1773 /* connect the virtual root hub */
1706 1774 ohci->rh.devnum = 0;
... ... @@ -1718,7 +1786,7 @@
1718 1786  
1719 1787 /* an interrupt happens */
1720 1788  
1721   -static int hc_interrupt (void)
  1789 +static int hc_interrupt(void)
1722 1790 {
1723 1791 ohci_t *ohci = &gohci;
1724 1792 struct ohci_regs *regs = ohci->regs;
1725 1793  
1726 1794  
1727 1795  
1728 1796  
1729 1797  
1730 1798  
1731 1799  
1732 1800  
1733 1801  
1734 1802  
1735 1803  
1736 1804  
1737 1805  
1738 1806  
... ... @@ -1726,69 +1794,74 @@
1726 1794 int stat = -1;
1727 1795  
1728 1796 if ((ohci->hcca->done_head != 0) &&
1729   - !(m32_swap (ohci->hcca->done_head) & 0x01)) {
  1797 + !(m32_swap(ohci->hcca->done_head) & 0x01)) {
1730 1798 ints = OHCI_INTR_WDH;
1731   - } else if ((ints = readl (&regs->intrstatus)) == ~(u32)0) {
1732   - ohci->disabled++;
1733   - err ("%s device removed!", ohci->slot_name);
1734   - return -1;
1735   - } else if ((ints &= readl (&regs->intrenable)) == 0) {
1736   - dbg("hc_interrupt: returning..\n");
1737   - return 0xff;
  1799 + } else {
  1800 + ints = readl(&regs->intrstatus);
  1801 + if (ints == ~(u32)0) {
  1802 + ohci->disabled++;
  1803 + err("%s device removed!", ohci->slot_name);
  1804 + return -1;
  1805 + } else {
  1806 + ints &= readl(&regs->intrenable);
  1807 + if (ints == 0) {
  1808 + dbg("hc_interrupt: returning..\n");
  1809 + return 0xff;
  1810 + }
  1811 + }
1738 1812 }
1739 1813  
1740   - /* dbg("Interrupt: %x frame: %x", ints, le16_to_cpu (ohci->hcca->frame_no)); */
  1814 + /* dbg("Interrupt: %x frame: %x", ints,
  1815 + le16_to_cpu(ohci->hcca->frame_no)); */
1741 1816  
1742   - if (ints & OHCI_INTR_RHSC) {
1743   - got_rhsc = 1;
  1817 + if (ints & OHCI_INTR_RHSC)
1744 1818 stat = 0xff;
1745   - }
1746 1819  
1747 1820 if (ints & OHCI_INTR_UE) {
1748 1821 ohci->disabled++;
1749   - err ("OHCI Unrecoverable Error, controller usb-%s disabled",
  1822 + err("OHCI Unrecoverable Error, controller usb-%s disabled",
1750 1823 ohci->slot_name);
1751 1824 /* e.g. due to PCI Master/Target Abort */
1752 1825  
1753 1826 #ifdef DEBUG
1754   - ohci_dump (ohci, 1);
  1827 + ohci_dump(ohci, 1);
1755 1828 #else
1756   - wait_ms(1);
  1829 + wait_ms(1);
1757 1830 #endif
1758 1831 /* FIXME: be optimistic, hope that bug won't repeat often. */
1759 1832 /* Make some non-interrupt context restart the controller. */
1760 1833 /* Count and limit the retries though; either hardware or */
1761 1834 /* software errors can go forever... */
1762   - hc_reset (ohci);
  1835 + hc_reset(ohci);
1763 1836 return -1;
1764 1837 }
1765 1838  
1766 1839 if (ints & OHCI_INTR_WDH) {
1767 1840 wait_ms(1);
1768   - writel (OHCI_INTR_WDH, &regs->intrdisable);
1769   - (void)readl (&regs->intrdisable); /* flush */
1770   - stat = dl_done_list (&gohci, dl_reverse_done_list (&gohci));
1771   - writel (OHCI_INTR_WDH, &regs->intrenable);
1772   - (void)readl (&regs->intrdisable); /* flush */
  1841 + writel(OHCI_INTR_WDH, &regs->intrdisable);
  1842 + (void)readl(&regs->intrdisable); /* flush */
  1843 + stat = dl_done_list(&gohci);
  1844 + writel(OHCI_INTR_WDH, &regs->intrenable);
  1845 + (void)readl(&regs->intrdisable); /* flush */
1773 1846 }
1774 1847  
1775 1848 if (ints & OHCI_INTR_SO) {
1776 1849 dbg("USB Schedule overrun\n");
1777   - writel (OHCI_INTR_SO, &regs->intrenable);
  1850 + writel(OHCI_INTR_SO, &regs->intrenable);
1778 1851 stat = -1;
1779 1852 }
1780 1853  
1781 1854 /* FIXME: this assumes SOF (1/ms) interrupts don't get lost... */
1782 1855 if (ints & OHCI_INTR_SF) {
1783   - unsigned int frame = m16_swap (ohci->hcca->frame_no) & 1;
  1856 + unsigned int frame = m16_swap(ohci->hcca->frame_no) & 1;
1784 1857 wait_ms(1);
1785   - writel (OHCI_INTR_SF, &regs->intrdisable);
  1858 + writel(OHCI_INTR_SF, &regs->intrdisable);
1786 1859 if (ohci->ed_rm_list[frame] != NULL)
1787   - writel (OHCI_INTR_SF, &regs->intrenable);
  1860 + writel(OHCI_INTR_SF, &regs->intrenable);
1788 1861 stat = 0xff;
1789 1862 }
1790 1863  
1791   - writel (ints, &regs->intrstatus);
  1864 + writel(ints, &regs->intrstatus);
1792 1865 return stat;
1793 1866 }
1794 1867  
1795 1868  
1796 1869  
... ... @@ -1798,12 +1871,12 @@
1798 1871  
1799 1872 /* De-allocate all resources.. */
1800 1873  
1801   -static void hc_release_ohci (ohci_t *ohci)
  1874 +static void hc_release_ohci(ohci_t *ohci)
1802 1875 {
1803   - dbg ("USB HC release ohci usb-%s", ohci->slot_name);
  1876 + dbg("USB HC release ohci usb-%s", ohci->slot_name);
1804 1877  
1805 1878 if (!ohci->disabled)
1806   - hc_reset (ohci);
  1879 + hc_reset(ohci);
1807 1880 }
1808 1881  
1809 1882 /*-------------------------------------------------------------------------*/
1810 1883  
1811 1884  
... ... @@ -1821,16 +1894,16 @@
1821 1894  
1822 1895 #ifdef CFG_USB_OHCI_CPU_INIT
1823 1896 /* cpu dependant init */
1824   - if(usb_cpu_init())
  1897 + if (usb_cpu_init())
1825 1898 return -1;
1826 1899 #endif
1827 1900  
1828 1901 #ifdef CFG_USB_OHCI_BOARD_INIT
1829 1902 /* board dependant init */
1830   - if(usb_board_init())
  1903 + if (usb_board_init())
1831 1904 return -1;
1832 1905 #endif
1833   - memset (&gohci, 0, sizeof (ohci_t));
  1906 + memset(&gohci, 0, sizeof(ohci_t));
1834 1907  
1835 1908 /* align the storage */
1836 1909 if ((__u32)&ghcca[0] & 0xff) {
... ... @@ -1851,7 +1924,7 @@
1851 1924 }
1852 1925 ptd = gtd;
1853 1926 gohci.hcca = phcca;
1854   - memset (phcca, 0, sizeof (struct ohci_hcca));
  1927 + memset(phcca, 0, sizeof(struct ohci_hcca));
1855 1928  
1856 1929 gohci.disabled = 1;
1857 1930 gohci.sleeping = 0;
... ... @@ -1879,9 +1952,9 @@
1879 1952 gohci.flags = 0;
1880 1953 gohci.slot_name = CFG_USB_OHCI_SLOT_NAME;
1881 1954  
1882   - if (hc_reset (&gohci) < 0) {
1883   - hc_release_ohci (&gohci);
1884   - err ("can't reset usb-%s", gohci.slot_name);
  1955 + if (hc_reset(&gohci) < 0) {
  1956 + hc_release_ohci(&gohci);
  1957 + err("can't reset usb-%s", gohci.slot_name);
1885 1958 #ifdef CFG_USB_OHCI_BOARD_INIT
1886 1959 /* board dependant cleanup */
1887 1960 usb_board_init_fail();
... ... @@ -1894,12 +1967,9 @@
1894 1967 return -1;
1895 1968 }
1896 1969  
1897   - /* FIXME this is a second HC reset; why?? */
1898   - /* writel(gohci.hc_control = OHCI_USB_RESET, &gohci.regs->control);
1899   - wait_ms(10); */
1900   - if (hc_start (&gohci) < 0) {
1901   - err ("can't start usb-%s", gohci.slot_name);
1902   - hc_release_ohci (&gohci);
  1970 + if (hc_start(&gohci) < 0) {
  1971 + err("can't start usb-%s", gohci.slot_name);
  1972 + hc_release_ohci(&gohci);
1903 1973 /* Initialization failed */
1904 1974 #ifdef CFG_USB_OHCI_BOARD_INIT
1905 1975 /* board dependant cleanup */
... ... @@ -1914,7 +1984,7 @@
1914 1984 }
1915 1985  
1916 1986 #ifdef DEBUG
1917   - ohci_dump (&gohci, 1);
  1987 + ohci_dump(&gohci, 1);
1918 1988 #else
1919 1989 wait_ms(1);
1920 1990 #endif
1921 1991  
1922 1992  
... ... @@ -1930,17 +2000,17 @@
1930 2000 return 0;
1931 2001 /* TODO release any interrupts, etc. */
1932 2002 /* call hc_release_ohci() here ? */
1933   - hc_reset (&gohci);
  2003 + hc_reset(&gohci);
1934 2004  
1935 2005 #ifdef CFG_USB_OHCI_BOARD_INIT
1936 2006 /* board dependant cleanup */
1937   - if(usb_board_stop())
  2007 + if (usb_board_stop())
1938 2008 return -1;
1939 2009 #endif
1940 2010  
1941 2011 #ifdef CFG_USB_OHCI_CPU_INIT
1942 2012 /* cpu dependant cleanup */
1943   - if(usb_cpu_stop())
  2013 + if (usb_cpu_stop())
1944 2014 return -1;
1945 2015 #endif
1946 2016 /* This driver is no longer initialised. It needs a new low-level
drivers/usb/usb_ohci.h
... ... @@ -38,6 +38,41 @@
38 38 /* Not Access */ -1
39 39 };
40 40  
  41 +static const char *cc_to_string[16] = {
  42 + "No Error",
  43 + "CRC: Last data packet from endpoint contained a CRC error.",
  44 + "BITSTUFFING: Last data packet from endpoint contained a bit " \
  45 + "stuffing violation",
  46 + "DATATOGGLEMISMATCH: Last packet from endpoint had data toggle PID\n" \
  47 + "that did not match the expected value.",
  48 + "STALL: TD was moved to the Done Queue because the endpoint returned" \
  49 + " a STALL PID",
  50 + "DEVICENOTRESPONDING: Device did not respond to token (IN) or did\n" \
  51 + "not provide a handshake (OUT)",
  52 + "PIDCHECKFAILURE: Check bits on PID from endpoint failed on data PID\n"\
  53 + "(IN) or handshake (OUT)",
  54 + "UNEXPECTEDPID: Receive PID was not valid when encountered or PID\n" \
  55 + "value is not defined.",
  56 + "DATAOVERRUN: The amount of data returned by the endpoint exceeded\n" \
  57 + "either the size of the maximum data packet allowed\n" \
  58 + "from the endpoint (found in MaximumPacketSize field\n" \
  59 + "of ED) or the remaining buffer size.",
  60 + "DATAUNDERRUN: The endpoint returned less than MaximumPacketSize\n" \
  61 + "and that amount was not sufficient to fill the\n" \
  62 + "specified buffer",
  63 + "reserved1",
  64 + "reserved2",
  65 + "BUFFEROVERRUN: During an IN, HC received data from endpoint faster\n" \
  66 + "than it could be written to system memory",
  67 + "BUFFERUNDERRUN: During an OUT, HC could not retrieve data from\n" \
  68 + "system memory fast enough to keep up with data USB " \
  69 + "data rate.",
  70 + "NOT ACCESSED: This code is set by software before the TD is placed" \
  71 + "on a list to be processed by the HC.(1)",
  72 + "NOT ACCESSED: This code is set by software before the TD is placed" \
  73 + "on a list to be processed by the HC.(2)",
  74 +};
  75 +
41 76 /* ED States */
42 77  
43 78 #define ED_NEW 0x00