usb_uhci.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152
  1. /*
  2. * (C) Copyright 2001
  3. * Denis Peter, MPL AG Switzerland
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. *
  23. * Note: Part of this code has been derived from linux
  24. *
  25. */
  26. /**********************************************************************
  27. * How it works:
  28. * -------------
  29. * The framelist / Transfer descriptor / Queue Heads are similar like
  30. * in the linux usb_uhci.c.
  31. *
  32. * During initialization, the following skeleton is allocated in init_skel:
  33. *
  34. * framespecific | common chain
  35. *
  36. * framelist[]
  37. * [ 0 ]-----> TD ---------\
  38. * [ 1 ]-----> TD ----------> TD ------> QH -------> QH -------> QH ---> NULL
  39. * ... TD ---------/
  40. * [1023]-----> TD --------/
  41. *
  42. * ^^ ^^ ^^ ^^ ^^
  43. * 7 TDs for 1 TD for Start of Start of End Chain
  44. * INT (2-128ms) 1ms-INT CTRL Chain BULK Chain
  45. *
  46. *
  47. * Since this is a bootloader, the isochronous transfer descriptor have been removed.
  48. *
  49. * Interrupt Transfers.
  50. * --------------------
  51. * For Interupt transfers USB_MAX_TEMP_INT_TD Transfer descriptor are available. They
  52. * will be inserted after the appropriate (depending the interval setting) skeleton TD.
  53. * If an interrupt has been detected the dev->irqhandler is called. The status and number
  54. * of transfered bytes is stored in dev->irq_status resp. dev->irq_act_len. If the
  55. * dev->irqhandler returns 0, the interrupt TD is removed and disabled. If an 1 is returned,
  56. * the interrupt TD will be reactivated.
  57. *
  58. * Control Transfers
  59. * -----------------
  60. * Control Transfers are issued by filling the tmp_td with the appropriate data and connect
  61. * them to the qh_cntrl queue header. Before other control/bulk transfers can be issued,
  62. * the programm has to wait for completion. This does not allows asynchronous data transfer.
  63. *
  64. * Bulk Transfers
  65. * --------------
  66. * Bulk Transfers are issued by filling the tmp_td with the appropriate data and connect
  67. * them to the qh_bulk queue header. Before other control/bulk transfers can be issued,
  68. * the programm has to wait for completion. This does not allows asynchronous data transfer.
  69. *
  70. *
  71. */
  72. #include <common.h>
  73. #include <pci.h>
  74. #ifdef CONFIG_USB_UHCI
  75. #include <usb.h>
  76. #include "usb_uhci.h"
  77. #define USB_MAX_TEMP_TD 128 /* number of temporary TDs for bulk and control transfers */
  78. #define USB_MAX_TEMP_INT_TD 32 /* number of temporary TDs for Interrupt transfers */
  79. #undef USB_UHCI_DEBUG
  80. #ifdef USB_UHCI_DEBUG
  81. #define USB_UHCI_PRINTF(fmt,args...) printf (fmt ,##args)
  82. #else
  83. #define USB_UHCI_PRINTF(fmt,args...)
  84. #endif
  85. static int irqvec = -1; /* irq vector, if -1 uhci is stopped / reseted */
  86. unsigned int usb_base_addr; /* base address */
  87. static uhci_td_t td_int[8]; /* Interrupt Transfer descriptors */
  88. static uhci_qh_t qh_cntrl; /* control Queue Head */
  89. static uhci_qh_t qh_bulk; /* bulk Queue Head */
  90. static uhci_qh_t qh_end; /* end Queue Head */
  91. static uhci_td_t td_last; /* last TD (linked with end chain) */
  92. /* temporary tds */
  93. static uhci_td_t tmp_td[USB_MAX_TEMP_TD]; /* temporary bulk/control td's */
  94. static uhci_td_t tmp_int_td[USB_MAX_TEMP_INT_TD]; /* temporary interrupt td's */
  95. static unsigned long framelist[1024] __attribute__ ((aligned (0x1000))); /* frame list */
  96. static struct virt_root_hub rh; /* struct for root hub */
  97. /**********************************************************************
  98. * some forward decleration
  99. */
  100. int uhci_submit_rh_msg(struct usb_device *dev, unsigned long pipe,
  101. void *buffer, int transfer_len,struct devrequest *setup);
  102. /* fill a td with the approproiate data. Link, status, info and buffer
  103. * are used by the USB controller itselfes, dev is used to identify the
  104. * "connected" device
  105. */
  106. void usb_fill_td(uhci_td_t* td,unsigned long link,unsigned long status,
  107. unsigned long info, unsigned long buffer, unsigned long dev)
  108. {
  109. td->link=swap_32(link);
  110. td->status=swap_32(status);
  111. td->info=swap_32(info);
  112. td->buffer=swap_32(buffer);
  113. td->dev_ptr=dev;
  114. }
  115. /* fill a qh with the approproiate data. Head and element are used by the USB controller
  116. * itselfes. As soon as a valid dev_ptr is filled, a td chain is connected to the qh.
  117. * Please note, that after completion of the td chain, the entry element is removed /
  118. * marked invalid by the USB controller.
  119. */
  120. void usb_fill_qh(uhci_qh_t* qh,unsigned long head,unsigned long element)
  121. {
  122. qh->head=swap_32(head);
  123. qh->element=swap_32(element);
  124. qh->dev_ptr=0L;
  125. }
  126. /* get the status of a td->status
  127. */
  128. unsigned long usb_uhci_td_stat(unsigned long status)
  129. {
  130. unsigned long result=0;
  131. result |= (status & TD_CTRL_NAK) ? USB_ST_NAK_REC : 0;
  132. result |= (status & TD_CTRL_STALLED) ? USB_ST_STALLED : 0;
  133. result |= (status & TD_CTRL_DBUFERR) ? USB_ST_BUF_ERR : 0;
  134. result |= (status & TD_CTRL_BABBLE) ? USB_ST_BABBLE_DET : 0;
  135. result |= (status & TD_CTRL_CRCTIMEO) ? USB_ST_CRC_ERR : 0;
  136. result |= (status & TD_CTRL_BITSTUFF) ? USB_ST_BIT_ERR : 0;
  137. result |= (status & TD_CTRL_ACTIVE) ? USB_ST_NOT_PROC : 0;
  138. return result;
  139. }
  140. /* get the status and the transfered len of a td chain.
  141. * called from the completion handler
  142. */
  143. int usb_get_td_status(uhci_td_t *td,struct usb_device *dev)
  144. {
  145. unsigned long temp,info;
  146. unsigned long stat;
  147. uhci_td_t *mytd=td;
  148. if(dev->devnum==rh.devnum)
  149. return 0;
  150. dev->act_len=0;
  151. stat=0;
  152. do {
  153. temp=swap_32((unsigned long)mytd->status);
  154. stat=usb_uhci_td_stat(temp);
  155. info=swap_32((unsigned long)mytd->info);
  156. if(((info & 0xff)!= USB_PID_SETUP) &&
  157. (((info >> 21) & 0x7ff)!= 0x7ff) &&
  158. (temp & 0x7FF)!=0x7ff)
  159. { /* if not setup and not null data pack */
  160. dev->act_len+=(temp & 0x7FF) + 1; /* the transfered len is act_len + 1 */
  161. }
  162. if(stat) { /* status no ok */
  163. dev->status=stat;
  164. return -1;
  165. }
  166. temp=swap_32((unsigned long)mytd->link);
  167. mytd=(uhci_td_t *)(temp & 0xfffffff0);
  168. }while((temp & 0x1)==0); /* process all TDs */
  169. dev->status=stat;
  170. return 0; /* Ok */
  171. }
  172. /*-------------------------------------------------------------------
  173. * LOW LEVEL STUFF
  174. * assembles QHs und TDs for control, bulk and iso
  175. *-------------------------------------------------------------------*/
  176. /* Submits a control message. That is a Setup, Data and Status transfer.
  177. * Routine does not wait for completion.
  178. */
  179. int submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
  180. int transfer_len,struct devrequest *setup)
  181. {
  182. unsigned long destination, status;
  183. int maxsze = usb_maxpacket(dev, pipe);
  184. unsigned long dataptr;
  185. int len;
  186. int pktsze;
  187. int i=0;
  188. if (!maxsze) {
  189. USB_UHCI_PRINTF("uhci_submit_control_urb: pipesize for pipe %lx is zero\n", pipe);
  190. return -1;
  191. }
  192. if(((pipe>>8)&0x7f)==rh.devnum) {
  193. /* this is the root hub -> redirect it */
  194. return uhci_submit_rh_msg(dev,pipe,buffer,transfer_len,setup);
  195. }
  196. USB_UHCI_PRINTF("uhci_submit_control start len %x, maxsize %x\n",transfer_len,maxsze);
  197. /* The "pipe" thing contains the destination in bits 8--18 */
  198. destination = (pipe & PIPE_DEVEP_MASK) | USB_PID_SETUP; /* Setup stage */
  199. /* 3 errors */
  200. status = (pipe & TD_CTRL_LS) | TD_CTRL_ACTIVE | (3 << 27);
  201. /* (urb->transfer_flags & USB_DISABLE_SPD ? 0 : TD_CTRL_SPD); */
  202. /* Build the TD for the control request, try forever, 8 bytes of data */
  203. usb_fill_td(&tmp_td[i],UHCI_PTR_TERM ,status, destination | (7 << 21),(unsigned long)setup,(unsigned long)dev);
  204. #if 0
  205. {
  206. char *sp=(char *)setup;
  207. printf("SETUP to pipe %lx: %x %x %x %x %x %x %x %x\n", pipe,
  208. sp[0],sp[1],sp[2],sp[3],sp[4],sp[5],sp[6],sp[7]);
  209. }
  210. #endif
  211. dataptr = (unsigned long)buffer;
  212. len=transfer_len;
  213. /* If direction is "send", change the frame from SETUP (0x2D)
  214. to OUT (0xE1). Else change it from SETUP to IN (0x69). */
  215. destination = (pipe & PIPE_DEVEP_MASK) | ((pipe & USB_DIR_IN)==0 ? USB_PID_OUT : USB_PID_IN);
  216. while (len > 0) {
  217. /* data stage */
  218. pktsze = len;
  219. i++;
  220. if (pktsze > maxsze)
  221. pktsze = maxsze;
  222. destination ^= 1 << TD_TOKEN_TOGGLE; /* toggle DATA0/1 */
  223. usb_fill_td(&tmp_td[i],UHCI_PTR_TERM, status, destination | ((pktsze - 1) << 21),dataptr,(unsigned long)dev); /* Status, pktsze bytes of data */
  224. tmp_td[i-1].link=swap_32((unsigned long)&tmp_td[i]);
  225. dataptr += pktsze;
  226. len -= pktsze;
  227. }
  228. /* Build the final TD for control status */
  229. /* It's only IN if the pipe is out AND we aren't expecting data */
  230. destination &= ~UHCI_PID;
  231. if (((pipe & USB_DIR_IN)==0) || (transfer_len == 0))
  232. destination |= USB_PID_IN;
  233. else
  234. destination |= USB_PID_OUT;
  235. destination |= 1 << TD_TOKEN_TOGGLE; /* End in Data1 */
  236. i++;
  237. status &=~TD_CTRL_SPD;
  238. /* no limit on errors on final packet , 0 bytes of data */
  239. usb_fill_td(&tmp_td[i],UHCI_PTR_TERM, status | TD_CTRL_IOC, destination | (UHCI_NULL_DATA_SIZE << 21),0,(unsigned long)dev);
  240. tmp_td[i-1].link=swap_32((unsigned long)&tmp_td[i]); /* queue status td */
  241. /* usb_show_td(i+1);*/
  242. USB_UHCI_PRINTF("uhci_submit_control end (%d tmp_tds used)\n",i);
  243. /* first mark the control QH element terminated */
  244. qh_cntrl.element=0xffffffffL;
  245. /* set qh active */
  246. qh_cntrl.dev_ptr=(unsigned long)dev;
  247. /* fill in tmp_td_chain */
  248. qh_cntrl.element=swap_32((unsigned long)&tmp_td[0]);
  249. return 0;
  250. }
  251. /*-------------------------------------------------------------------
  252. * Prepare TDs for bulk transfers.
  253. */
  254. int submit_bulk_msg(struct usb_device *dev, unsigned long pipe, void *buffer,int transfer_len)
  255. {
  256. unsigned long destination, status,info;
  257. unsigned long dataptr;
  258. int maxsze = usb_maxpacket(dev, pipe);
  259. int len;
  260. int i=0;
  261. if(transfer_len < 0) {
  262. printf("Negative transfer length in submit_bulk\n");
  263. return -1;
  264. }
  265. if (!maxsze)
  266. return -1;
  267. /* The "pipe" thing contains the destination in bits 8--18. */
  268. destination = (pipe & PIPE_DEVEP_MASK) | usb_packetid (pipe);
  269. /* 3 errors */
  270. status = (pipe & TD_CTRL_LS) | TD_CTRL_ACTIVE | (3 << 27);
  271. /* ((urb->transfer_flags & USB_DISABLE_SPD) ? 0 : TD_CTRL_SPD) | (3 << 27); */
  272. /* Build the TDs for the bulk request */
  273. len = transfer_len;
  274. dataptr = (unsigned long)buffer;
  275. do {
  276. int pktsze = len;
  277. if (pktsze > maxsze)
  278. pktsze = maxsze;
  279. /* pktsze bytes of data */
  280. info = destination | (((pktsze - 1)&UHCI_NULL_DATA_SIZE) << 21) |
  281. (usb_gettoggle (dev, usb_pipeendpoint (pipe), usb_pipeout (pipe)) << TD_TOKEN_TOGGLE);
  282. if((len-pktsze)==0)
  283. status |= TD_CTRL_IOC; /* last one generates INT */
  284. usb_fill_td(&tmp_td[i],UHCI_PTR_TERM, status, info,dataptr,(unsigned long)dev); /* Status, pktsze bytes of data */
  285. if(i>0)
  286. tmp_td[i-1].link=swap_32((unsigned long)&tmp_td[i]);
  287. i++;
  288. dataptr += pktsze;
  289. len -= pktsze;
  290. usb_dotoggle (dev, usb_pipeendpoint (pipe), usb_pipeout (pipe));
  291. } while (len > 0);
  292. /* first mark the bulk QH element terminated */
  293. qh_bulk.element=0xffffffffL;
  294. /* set qh active */
  295. qh_bulk.dev_ptr=(unsigned long)dev;
  296. /* fill in tmp_td_chain */
  297. qh_bulk.element=swap_32((unsigned long)&tmp_td[0]);
  298. return 0;
  299. }
  300. /* search a free interrupt td
  301. */
  302. uhci_td_t *uhci_alloc_int_td(void)
  303. {
  304. int i;
  305. for(i=0;i<USB_MAX_TEMP_INT_TD;i++) {
  306. if(tmp_int_td[i].dev_ptr==0) /* no device assigned -> free TD */
  307. return &tmp_int_td[i];
  308. }
  309. return NULL;
  310. }
  311. #if 0
  312. void uhci_show_temp_int_td(void)
  313. {
  314. int i;
  315. for(i=0;i<USB_MAX_TEMP_INT_TD;i++) {
  316. if((tmp_int_td[i].dev_ptr&0x01)!=0x1L) /* no device assigned -> free TD */
  317. printf("temp_td %d is assigned to dev %lx\n",i,tmp_int_td[i].dev_ptr);
  318. }
  319. printf("all others temp_tds are free\n");
  320. }
  321. #endif
  322. /*-------------------------------------------------------------------
  323. * submits USB interrupt (ie. polling ;-)
  324. */
  325. int submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer,int transfer_len, int interval)
  326. {
  327. int nint, n;
  328. unsigned long status, destination;
  329. unsigned long info,tmp;
  330. uhci_td_t *mytd;
  331. if (interval < 0 || interval >= 256)
  332. return -1;
  333. if (interval == 0)
  334. nint = 0;
  335. else {
  336. for (nint = 0, n = 1; nint <= 8; nint++, n += n) /* round interval down to 2^n */
  337. {
  338. if(interval < n) {
  339. interval = n / 2;
  340. break;
  341. }
  342. }
  343. nint--;
  344. }
  345. USB_UHCI_PRINTF("Rounded interval to %i, chain %i\n", interval, nint);
  346. mytd=uhci_alloc_int_td();
  347. if(mytd==NULL) {
  348. printf("No free INT TDs found\n");
  349. return -1;
  350. }
  351. status = (pipe & TD_CTRL_LS) | TD_CTRL_ACTIVE | TD_CTRL_IOC | (3 << 27);
  352. /* (urb->transfer_flags & USB_DISABLE_SPD ? 0 : TD_CTRL_SPD) | (3 << 27);
  353. */
  354. destination =(pipe & PIPE_DEVEP_MASK) | usb_packetid (pipe) | (((transfer_len - 1) & 0x7ff) << 21);
  355. info = destination | (usb_gettoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe)) << TD_TOKEN_TOGGLE);
  356. tmp = swap_32(td_int[nint].link);
  357. usb_fill_td(mytd,tmp,status, info,(unsigned long)buffer,(unsigned long)dev);
  358. /* Link it */
  359. tmp = swap_32((unsigned long)mytd);
  360. td_int[nint].link=tmp;
  361. usb_dotoggle (dev, usb_pipeendpoint (pipe), usb_pipeout (pipe));
  362. return 0;
  363. }
  364. /**********************************************************************
  365. * Low Level functions
  366. */
  367. void reset_hc(void)
  368. {
  369. /* Global reset for 100ms */
  370. out16r( usb_base_addr + USBPORTSC1,0x0204);
  371. out16r( usb_base_addr + USBPORTSC2,0x0204);
  372. out16r( usb_base_addr + USBCMD,USBCMD_GRESET | USBCMD_RS);
  373. /* Turn off all interrupts */
  374. out16r(usb_base_addr + USBINTR,0);
  375. wait_ms(50);
  376. out16r( usb_base_addr + USBCMD,0);
  377. wait_ms(10);
  378. }
  379. void start_hc(void)
  380. {
  381. int timeout = 1000;
  382. while(in16r(usb_base_addr + USBCMD) & USBCMD_HCRESET) {
  383. if (!--timeout) {
  384. printf("USBCMD_HCRESET timed out!\n");
  385. break;
  386. }
  387. }
  388. /* Turn on all interrupts */
  389. out16r(usb_base_addr + USBINTR,USBINTR_TIMEOUT | USBINTR_RESUME | USBINTR_IOC | USBINTR_SP);
  390. /* Start at frame 0 */
  391. out16r(usb_base_addr + USBFRNUM,0);
  392. /* set Framebuffer base address */
  393. out32r(usb_base_addr+USBFLBASEADD,(unsigned long)&framelist);
  394. /* Run and mark it configured with a 64-byte max packet */
  395. out16r(usb_base_addr + USBCMD,USBCMD_RS | USBCMD_CF | USBCMD_MAXP);
  396. }
  397. /* Initialize the skeleton
  398. */
  399. void usb_init_skel(void)
  400. {
  401. unsigned long temp;
  402. int n;
  403. for(n=0;n<USB_MAX_TEMP_INT_TD;n++)
  404. tmp_int_td[n].dev_ptr=0L; /* no devices connected */
  405. /* last td */
  406. usb_fill_td(&td_last,UHCI_PTR_TERM,TD_CTRL_IOC ,0,0,0L);
  407. /* usb_fill_td(&td_last,UHCI_PTR_TERM,0,0,0); */
  408. /* End Queue Header */
  409. usb_fill_qh(&qh_end,UHCI_PTR_TERM,(unsigned long)&td_last);
  410. /* Bulk Queue Header */
  411. temp=(unsigned long)&qh_end;
  412. usb_fill_qh(&qh_bulk,temp | UHCI_PTR_QH,UHCI_PTR_TERM);
  413. /* Control Queue Header */
  414. temp=(unsigned long)&qh_bulk;
  415. usb_fill_qh(&qh_cntrl, temp | UHCI_PTR_QH,UHCI_PTR_TERM);
  416. /* 1ms Interrupt td */
  417. temp=(unsigned long)&qh_cntrl;
  418. usb_fill_td(&td_int[0],temp | UHCI_PTR_QH,0,0,0,0L);
  419. temp=(unsigned long)&td_int[0];
  420. for(n=1; n<8; n++)
  421. usb_fill_td(&td_int[n],temp,0,0,0,0L);
  422. for (n = 0; n < 1024; n++) {
  423. /* link all framelist pointers to one of the interrupts */
  424. int m, o;
  425. if ((n&127)==127)
  426. framelist[n]= swap_32((unsigned long)&td_int[0]);
  427. else
  428. for (o = 1, m = 2; m <= 128; o++, m += m)
  429. if ((n & (m - 1)) == ((m - 1) / 2))
  430. framelist[n]= swap_32((unsigned long)&td_int[o]);
  431. }
  432. }
  433. /* check the common skeleton for completed transfers, and update the status
  434. * of the "connected" device. Called from the IRQ routine.
  435. */
  436. void usb_check_skel(void)
  437. {
  438. struct usb_device *dev;
  439. /* start with the control qh */
  440. if(qh_cntrl.dev_ptr!=0) /* it's a device assigned check if this caused IRQ */
  441. {
  442. dev=(struct usb_device *)qh_cntrl.dev_ptr;
  443. usb_get_td_status(&tmp_td[0],dev); /* update status */
  444. if(!(dev->status & USB_ST_NOT_PROC)) { /* is not active anymore, disconnect devices */
  445. qh_cntrl.dev_ptr=0;
  446. }
  447. }
  448. /* now process the bulk */
  449. if(qh_bulk.dev_ptr!=0) /* it's a device assigned check if this caused IRQ */
  450. {
  451. dev=(struct usb_device *)qh_bulk.dev_ptr;
  452. usb_get_td_status(&tmp_td[0],dev); /* update status */
  453. if(!(dev->status & USB_ST_NOT_PROC)) { /* is not active anymore, disconnect devices */
  454. qh_bulk.dev_ptr=0;
  455. }
  456. }
  457. }
  458. /* check the interrupt chain, ubdate the status of the appropriate device,
  459. * call the appropriate irqhandler and reactivate the TD if the irqhandler
  460. * returns with 1
  461. */
  462. void usb_check_int_chain(void)
  463. {
  464. int i,res;
  465. unsigned long link,status;
  466. struct usb_device *dev;
  467. uhci_td_t *td,*prevtd;
  468. for(i=0;i<8;i++) {
  469. prevtd=&td_int[i]; /* the first previous td is the skeleton td */
  470. link=swap_32(td_int[i].link) & 0xfffffff0; /* next in chain */
  471. td=(uhci_td_t *)link; /* assign it */
  472. /* all interrupt TDs are finally linked to the td_int[0].
  473. * so we process all until we find the td_int[0].
  474. * if int0 chain points to a QH, we're also done
  475. */
  476. while(((i>0) && (link != (unsigned long)&td_int[0])) ||
  477. ((i==0) && !(swap_32(td->link) & UHCI_PTR_QH)))
  478. {
  479. /* check if a device is assigned with this td */
  480. status=swap_32(td->status);
  481. if((td->dev_ptr!=0L) && !(status & TD_CTRL_ACTIVE)) {
  482. /* td is not active and a device is assigned -> call irqhandler */
  483. dev=(struct usb_device *)td->dev_ptr;
  484. dev->irq_act_len=((status & 0x7FF)==0x7FF) ? 0 : (status & 0x7FF) + 1; /* transfered length */
  485. dev->irq_status=usb_uhci_td_stat(status); /* get status */
  486. res=dev->irq_handle(dev); /* call irqhandler */
  487. if(res==1) {
  488. /* reactivate */
  489. status|=TD_CTRL_ACTIVE;
  490. td->status=swap_32(status);
  491. prevtd=td; /* previous td = this td */
  492. }
  493. else {
  494. prevtd->link=td->link; /* link previous td directly to the nex td -> unlinked */
  495. /* remove device pointer */
  496. td->dev_ptr=0L;
  497. }
  498. } /* if we call the irq handler */
  499. link=swap_32(td->link) & 0xfffffff0; /* next in chain */
  500. td=(uhci_td_t *)link; /* assign it */
  501. } /* process all td in this int chain */
  502. } /* next interrupt chain */
  503. }
  504. /* usb interrupt service routine.
  505. */
  506. void handle_usb_interrupt(void)
  507. {
  508. unsigned short status;
  509. /*
  510. * Read the interrupt status, and write it back to clear the
  511. * interrupt cause
  512. */
  513. status = in16r(usb_base_addr + USBSTS);
  514. if (!status) /* shared interrupt, not mine */
  515. return;
  516. if (status != 1) {
  517. /* remove host controller halted state */
  518. if ((status&0x20) && ((in16r(usb_base_addr+USBCMD) && USBCMD_RS)==0)) {
  519. out16r(usb_base_addr + USBCMD, USBCMD_RS | in16r(usb_base_addr + USBCMD));
  520. }
  521. }
  522. usb_check_int_chain(); /* call interrupt handlers for int tds */
  523. usb_check_skel(); /* call completion handler for common transfer routines */
  524. out16r(usb_base_addr+USBSTS,status);
  525. }
  526. /* init uhci
  527. */
  528. int usb_lowlevel_init(void)
  529. {
  530. unsigned char temp;
  531. int busdevfunc;
  532. busdevfunc=pci_find_device(USB_UHCI_VEND_ID,USB_UHCI_DEV_ID,0); /* get PCI Device ID */
  533. if(busdevfunc==-1) {
  534. printf("Error USB UHCI (%04X,%04X) not found\n",USB_UHCI_VEND_ID,USB_UHCI_DEV_ID);
  535. return -1;
  536. }
  537. pci_read_config_byte(busdevfunc,PCI_INTERRUPT_LINE,&temp);
  538. irqvec = temp;
  539. irq_free_handler(irqvec);
  540. USB_UHCI_PRINTF("Interrupt Line = %d, is %d\n",irqvec);
  541. pci_read_config_byte(busdevfunc,PCI_INTERRUPT_PIN,&temp);
  542. USB_UHCI_PRINTF("Interrupt Pin = %ld\n",temp);
  543. pci_read_config_dword(busdevfunc,PCI_BASE_ADDRESS_4,&usb_base_addr);
  544. USB_UHCI_PRINTF("IO Base Address = 0x%lx\n",usb_base_addr);
  545. usb_base_addr&=0xFFFFFFF0;
  546. usb_base_addr+=CFG_ISA_IO_BASE_ADDRESS;
  547. rh.devnum = 0;
  548. usb_init_skel();
  549. reset_hc();
  550. start_hc();
  551. irq_install_handler(irqvec, (interrupt_handler_t *)handle_usb_interrupt, NULL);
  552. return 0;
  553. }
  554. /* stop uhci
  555. */
  556. int usb_lowlevel_stop(void)
  557. {
  558. if(irqvec==-1)
  559. return 1;
  560. irq_free_handler(irqvec);
  561. reset_hc();
  562. irqvec=-1;
  563. return 0;
  564. }
  565. /*******************************************************************************************
  566. * Virtual Root Hub
  567. * Since the uhci does not have a real HUB, we simulate one ;-)
  568. */
  569. #undef USB_RH_DEBUG
  570. #ifdef USB_RH_DEBUG
  571. #define USB_RH_PRINTF(fmt,args...) printf (fmt ,##args)
  572. static void usb_display_wValue(unsigned short wValue,unsigned short wIndex);
  573. static void usb_display_Req(unsigned short req);
  574. #else
  575. #define USB_RH_PRINTF(fmt,args...)
  576. static void usb_display_wValue(unsigned short wValue,unsigned short wIndex) {}
  577. static void usb_display_Req(unsigned short req) {}
  578. #endif
  579. static unsigned char root_hub_dev_des[] =
  580. {
  581. 0x12, /* __u8 bLength; */
  582. 0x01, /* __u8 bDescriptorType; Device */
  583. 0x00, /* __u16 bcdUSB; v1.0 */
  584. 0x01,
  585. 0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */
  586. 0x00, /* __u8 bDeviceSubClass; */
  587. 0x00, /* __u8 bDeviceProtocol; */
  588. 0x08, /* __u8 bMaxPacketSize0; 8 Bytes */
  589. 0x00, /* __u16 idVendor; */
  590. 0x00,
  591. 0x00, /* __u16 idProduct; */
  592. 0x00,
  593. 0x00, /* __u16 bcdDevice; */
  594. 0x00,
  595. 0x01, /* __u8 iManufacturer; */
  596. 0x00, /* __u8 iProduct; */
  597. 0x00, /* __u8 iSerialNumber; */
  598. 0x01 /* __u8 bNumConfigurations; */
  599. };
  600. /* Configuration descriptor */
  601. static unsigned char root_hub_config_des[] =
  602. {
  603. 0x09, /* __u8 bLength; */
  604. 0x02, /* __u8 bDescriptorType; Configuration */
  605. 0x19, /* __u16 wTotalLength; */
  606. 0x00,
  607. 0x01, /* __u8 bNumInterfaces; */
  608. 0x01, /* __u8 bConfigurationValue; */
  609. 0x00, /* __u8 iConfiguration; */
  610. 0x40, /* __u8 bmAttributes;
  611. Bit 7: Bus-powered, 6: Self-powered, 5 Remote-wakwup, 4..0: resvd */
  612. 0x00, /* __u8 MaxPower; */
  613. /* interface */
  614. 0x09, /* __u8 if_bLength; */
  615. 0x04, /* __u8 if_bDescriptorType; Interface */
  616. 0x00, /* __u8 if_bInterfaceNumber; */
  617. 0x00, /* __u8 if_bAlternateSetting; */
  618. 0x01, /* __u8 if_bNumEndpoints; */
  619. 0x09, /* __u8 if_bInterfaceClass; HUB_CLASSCODE */
  620. 0x00, /* __u8 if_bInterfaceSubClass; */
  621. 0x00, /* __u8 if_bInterfaceProtocol; */
  622. 0x00, /* __u8 if_iInterface; */
  623. /* endpoint */
  624. 0x07, /* __u8 ep_bLength; */
  625. 0x05, /* __u8 ep_bDescriptorType; Endpoint */
  626. 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */
  627. 0x03, /* __u8 ep_bmAttributes; Interrupt */
  628. 0x08, /* __u16 ep_wMaxPacketSize; 8 Bytes */
  629. 0x00,
  630. 0xff /* __u8 ep_bInterval; 255 ms */
  631. };
  632. static unsigned char root_hub_hub_des[] =
  633. {
  634. 0x09, /* __u8 bLength; */
  635. 0x29, /* __u8 bDescriptorType; Hub-descriptor */
  636. 0x02, /* __u8 bNbrPorts; */
  637. 0x00, /* __u16 wHubCharacteristics; */
  638. 0x00,
  639. 0x01, /* __u8 bPwrOn2pwrGood; 2ms */
  640. 0x00, /* __u8 bHubContrCurrent; 0 mA */
  641. 0x00, /* __u8 DeviceRemovable; *** 7 Ports max *** */
  642. 0xff /* __u8 PortPwrCtrlMask; *** 7 ports max *** */
  643. };
  644. static unsigned char root_hub_str_index0[] =
  645. {
  646. 0x04, /* __u8 bLength; */
  647. 0x03, /* __u8 bDescriptorType; String-descriptor */
  648. 0x09, /* __u8 lang ID */
  649. 0x04, /* __u8 lang ID */
  650. };
  651. static unsigned char root_hub_str_index1[] =
  652. {
  653. 28, /* __u8 bLength; */
  654. 0x03, /* __u8 bDescriptorType; String-descriptor */
  655. 'U', /* __u8 Unicode */
  656. 0, /* __u8 Unicode */
  657. 'H', /* __u8 Unicode */
  658. 0, /* __u8 Unicode */
  659. 'C', /* __u8 Unicode */
  660. 0, /* __u8 Unicode */
  661. 'I', /* __u8 Unicode */
  662. 0, /* __u8 Unicode */
  663. ' ', /* __u8 Unicode */
  664. 0, /* __u8 Unicode */
  665. 'R', /* __u8 Unicode */
  666. 0, /* __u8 Unicode */
  667. 'o', /* __u8 Unicode */
  668. 0, /* __u8 Unicode */
  669. 'o', /* __u8 Unicode */
  670. 0, /* __u8 Unicode */
  671. 't', /* __u8 Unicode */
  672. 0, /* __u8 Unicode */
  673. ' ', /* __u8 Unicode */
  674. 0, /* __u8 Unicode */
  675. 'H', /* __u8 Unicode */
  676. 0, /* __u8 Unicode */
  677. 'u', /* __u8 Unicode */
  678. 0, /* __u8 Unicode */
  679. 'b', /* __u8 Unicode */
  680. 0, /* __u8 Unicode */
  681. };
  682. /*
  683. * Root Hub Control Pipe (interrupt Pipes are not supported)
  684. */
  685. int uhci_submit_rh_msg(struct usb_device *dev, unsigned long pipe, void *buffer,int transfer_len,struct devrequest *cmd)
  686. {
  687. void *data = buffer;
  688. int leni = transfer_len;
  689. int len = 0;
  690. int status = 0;
  691. int stat = 0;
  692. int i;
  693. unsigned short cstatus;
  694. unsigned short bmRType_bReq;
  695. unsigned short wValue;
  696. unsigned short wIndex;
  697. unsigned short wLength;
  698. if ((pipe & PIPE_INTERRUPT) == PIPE_INTERRUPT) {
  699. printf("Root-Hub submit IRQ: NOT implemented\n");
  700. #if 0
  701. uhci->rh.urb = urb;
  702. uhci->rh.send = 1;
  703. uhci->rh.interval = urb->interval;
  704. rh_init_int_timer (urb);
  705. #endif
  706. return 0;
  707. }
  708. bmRType_bReq = cmd->requesttype | cmd->request << 8;
  709. wValue = swap_16(cmd->value);
  710. wIndex = swap_16(cmd->index);
  711. wLength = swap_16(cmd->length);
  712. usb_display_Req(bmRType_bReq);
  713. for (i = 0; i < 8; i++)
  714. rh.c_p_r[i] = 0;
  715. USB_RH_PRINTF("Root-Hub: adr: %2x cmd(%1x): %02x%02x %04x %04x %04x\n",
  716. dev->devnum, 8, cmd->requesttype,cmd->request, wValue, wIndex, wLength);
  717. switch (bmRType_bReq) {
  718. /* Request Destination:
  719. without flags: Device,
  720. RH_INTERFACE: interface,
  721. RH_ENDPOINT: endpoint,
  722. RH_CLASS means HUB here,
  723. RH_OTHER | RH_CLASS almost ever means HUB_PORT here
  724. */
  725. case RH_GET_STATUS:
  726. *(unsigned short *) data = swap_16(1);
  727. len=2;
  728. break;
  729. case RH_GET_STATUS | RH_INTERFACE:
  730. *(unsigned short *) data = swap_16(0);
  731. len=2;
  732. break;
  733. case RH_GET_STATUS | RH_ENDPOINT:
  734. *(unsigned short *) data = swap_16(0);
  735. len=2;
  736. break;
  737. case RH_GET_STATUS | RH_CLASS:
  738. *(unsigned long *) data = swap_32(0);
  739. len=4;
  740. break; /* hub power ** */
  741. case RH_GET_STATUS | RH_OTHER | RH_CLASS:
  742. status = in16r(usb_base_addr + USBPORTSC1 + 2 * (wIndex - 1));
  743. cstatus = ((status & USBPORTSC_CSC) >> (1 - 0)) |
  744. ((status & USBPORTSC_PEC) >> (3 - 1)) |
  745. (rh.c_p_r[wIndex - 1] << (0 + 4));
  746. status = (status & USBPORTSC_CCS) |
  747. ((status & USBPORTSC_PE) >> (2 - 1)) |
  748. ((status & USBPORTSC_SUSP) >> (12 - 2)) |
  749. ((status & USBPORTSC_PR) >> (9 - 4)) |
  750. (1 << 8) | /* power on ** */
  751. ((status & USBPORTSC_LSDA) << (-8 + 9));
  752. *(unsigned short *) data = swap_16(status);
  753. *(unsigned short *) (data + 2) = swap_16(cstatus);
  754. len=4;
  755. break;
  756. case RH_CLEAR_FEATURE | RH_ENDPOINT:
  757. switch (wValue) {
  758. case (RH_ENDPOINT_STALL):
  759. len=0;
  760. break;
  761. }
  762. break;
  763. case RH_CLEAR_FEATURE | RH_CLASS:
  764. switch (wValue) {
  765. case (RH_C_HUB_OVER_CURRENT):
  766. len=0; /* hub power over current ** */
  767. break;
  768. }
  769. break;
  770. case RH_CLEAR_FEATURE | RH_OTHER | RH_CLASS:
  771. usb_display_wValue(wValue,wIndex);
  772. switch (wValue) {
  773. case (RH_PORT_ENABLE):
  774. status = in16r(usb_base_addr+USBPORTSC1+2*(wIndex-1));
  775. status = (status & 0xfff5) & ~USBPORTSC_PE;
  776. out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
  777. len=0;
  778. break;
  779. case (RH_PORT_SUSPEND):
  780. status = in16r(usb_base_addr+USBPORTSC1+2*(wIndex-1));
  781. status = (status & 0xfff5) & ~USBPORTSC_SUSP;
  782. out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
  783. len=0;
  784. break;
  785. case (RH_PORT_POWER):
  786. len=0; /* port power ** */
  787. break;
  788. case (RH_C_PORT_CONNECTION):
  789. status = in16r(usb_base_addr+USBPORTSC1+2*(wIndex-1));
  790. status = (status & 0xfff5) | USBPORTSC_CSC;
  791. out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
  792. len=0;
  793. break;
  794. case (RH_C_PORT_ENABLE):
  795. status = in16r(usb_base_addr+USBPORTSC1+2*(wIndex-1));
  796. status = (status & 0xfff5) | USBPORTSC_PEC;
  797. out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
  798. len=0;
  799. break;
  800. case (RH_C_PORT_SUSPEND):
  801. /*** WR_RH_PORTSTAT(RH_PS_PSSC); */
  802. len=0;
  803. break;
  804. case (RH_C_PORT_OVER_CURRENT):
  805. len=0;
  806. break;
  807. case (RH_C_PORT_RESET):
  808. rh.c_p_r[wIndex - 1] = 0;
  809. len=0;
  810. break;
  811. }
  812. break;
  813. case RH_SET_FEATURE | RH_OTHER | RH_CLASS:
  814. usb_display_wValue(wValue,wIndex);
  815. switch (wValue) {
  816. case (RH_PORT_SUSPEND):
  817. status = in16r(usb_base_addr+USBPORTSC1+2*(wIndex-1));
  818. status = (status & 0xfff5) | USBPORTSC_SUSP;
  819. out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
  820. len=0;
  821. break;
  822. case (RH_PORT_RESET):
  823. status = in16r(usb_base_addr+USBPORTSC1+2*(wIndex-1));
  824. status = (status & 0xfff5) | USBPORTSC_PR;
  825. out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
  826. wait_ms(10);
  827. status = (status & 0xfff5) & ~USBPORTSC_PR;
  828. out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
  829. udelay(10);
  830. status = (status & 0xfff5) | USBPORTSC_PE;
  831. out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
  832. wait_ms(10);
  833. status = (status & 0xfff5) | 0xa;
  834. out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
  835. len=0;
  836. break;
  837. case (RH_PORT_POWER):
  838. len=0; /* port power ** */
  839. break;
  840. case (RH_PORT_ENABLE):
  841. status = in16r(usb_base_addr+USBPORTSC1+2*(wIndex-1));
  842. status = (status & 0xfff5) | USBPORTSC_PE;
  843. out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
  844. len=0;
  845. break;
  846. }
  847. break;
  848. case RH_SET_ADDRESS:
  849. rh.devnum = wValue;
  850. len=0;
  851. break;
  852. case RH_GET_DESCRIPTOR:
  853. switch ((wValue & 0xff00) >> 8) {
  854. case (0x01): /* device descriptor */
  855. i=sizeof(root_hub_config_des);
  856. status=i > wLength ? wLength : i;
  857. len = leni > status ? status : leni;
  858. memcpy (data, root_hub_dev_des, len);
  859. break;
  860. case (0x02): /* configuration descriptor */
  861. i=sizeof(root_hub_config_des);
  862. status=i > wLength ? wLength : i;
  863. len = leni > status ? status : leni;
  864. memcpy (data, root_hub_config_des, len);
  865. break;
  866. case (0x03): /*string descriptors */
  867. if(wValue==0x0300) {
  868. i=sizeof(root_hub_str_index0);
  869. status = i > wLength ? wLength : i;
  870. len = leni > status ? status : leni;
  871. memcpy (data, root_hub_str_index0, len);
  872. break;
  873. }
  874. if(wValue==0x0301) {
  875. i=sizeof(root_hub_str_index1);
  876. status = i > wLength ? wLength : i;
  877. len = leni > status ? status : leni;
  878. memcpy (data, root_hub_str_index1, len);
  879. break;
  880. }
  881. stat = USB_ST_STALLED;
  882. }
  883. break;
  884. case RH_GET_DESCRIPTOR | RH_CLASS:
  885. root_hub_hub_des[2] = 2;
  886. i=sizeof(root_hub_hub_des);
  887. status= i > wLength ? wLength : i;
  888. len = leni > status ? status : leni;
  889. memcpy (data, root_hub_hub_des, len);
  890. break;
  891. case RH_GET_CONFIGURATION:
  892. *(unsigned char *) data = 0x01;
  893. len = 1;
  894. break;
  895. case RH_SET_CONFIGURATION:
  896. len=0;
  897. break;
  898. default:
  899. stat = USB_ST_STALLED;
  900. }
  901. USB_RH_PRINTF("Root-Hub stat %lx port1: %x port2: %x\n\n",stat,
  902. in16r(usb_base_addr + USBPORTSC1), in16r(usb_base_addr + USBPORTSC2));
  903. dev->act_len=len;
  904. dev->status=stat;
  905. return stat;
  906. }
  907. /********************************************************************************
  908. * Some Debug Routines
  909. */
  910. #ifdef USB_RH_DEBUG
  911. static void usb_display_Req(unsigned short req)
  912. {
  913. USB_RH_PRINTF("- Root-Hub Request: ");
  914. switch (req) {
  915. case RH_GET_STATUS:
  916. USB_RH_PRINTF("Get Status ");
  917. break;
  918. case RH_GET_STATUS | RH_INTERFACE:
  919. USB_RH_PRINTF("Get Status Interface ");
  920. break;
  921. case RH_GET_STATUS | RH_ENDPOINT:
  922. USB_RH_PRINTF("Get Status Endpoint ");
  923. break;
  924. case RH_GET_STATUS | RH_CLASS:
  925. USB_RH_PRINTF("Get Status Class");
  926. break; /* hub power ** */
  927. case RH_GET_STATUS | RH_OTHER | RH_CLASS:
  928. USB_RH_PRINTF("Get Status Class Others");
  929. break;
  930. case RH_CLEAR_FEATURE | RH_ENDPOINT:
  931. USB_RH_PRINTF("Clear Feature Endpoint ");
  932. break;
  933. case RH_CLEAR_FEATURE | RH_CLASS:
  934. USB_RH_PRINTF("Clear Feature Class ");
  935. break;
  936. case RH_CLEAR_FEATURE | RH_OTHER | RH_CLASS:
  937. USB_RH_PRINTF("Clear Feature Other Class ");
  938. break;
  939. case RH_SET_FEATURE | RH_OTHER | RH_CLASS:
  940. USB_RH_PRINTF("Set Feature Other Class ");
  941. break;
  942. case RH_SET_ADDRESS:
  943. USB_RH_PRINTF("Set Address ");
  944. break;
  945. case RH_GET_DESCRIPTOR:
  946. USB_RH_PRINTF("Get Descriptor ");
  947. break;
  948. case RH_GET_DESCRIPTOR | RH_CLASS:
  949. USB_RH_PRINTF("Get Descriptor Class ");
  950. break;
  951. case RH_GET_CONFIGURATION:
  952. USB_RH_PRINTF("Get Configuration ");
  953. break;
  954. case RH_SET_CONFIGURATION:
  955. USB_RH_PRINTF("Get Configuration ");
  956. break;
  957. default:
  958. USB_RH_PRINTF("****UNKNOWN**** 0x%04X ",req);
  959. }
  960. USB_RH_PRINTF("\n");
  961. }
  962. static void usb_display_wValue(unsigned short wValue,unsigned short wIndex)
  963. {
  964. switch (wValue) {
  965. case (RH_PORT_ENABLE):
  966. USB_RH_PRINTF("Root-Hub: Enable Port %d\n",wIndex);
  967. break;
  968. case (RH_PORT_SUSPEND):
  969. USB_RH_PRINTF("Root-Hub: Suspend Port %d\n",wIndex);
  970. break;
  971. case (RH_PORT_POWER):
  972. USB_RH_PRINTF("Root-Hub: Port Power %d\n",wIndex);
  973. break;
  974. case (RH_C_PORT_CONNECTION):
  975. USB_RH_PRINTF("Root-Hub: C Port Connection Port %d\n",wIndex);
  976. break;
  977. case (RH_C_PORT_ENABLE):
  978. USB_RH_PRINTF("Root-Hub: C Port Enable Port %d\n",wIndex);
  979. break;
  980. case (RH_C_PORT_SUSPEND):
  981. USB_RH_PRINTF("Root-Hub: C Port Suspend Port %d\n",wIndex);
  982. break;
  983. case (RH_C_PORT_OVER_CURRENT):
  984. USB_RH_PRINTF("Root-Hub: C Port Over Current Port %d\n",wIndex);
  985. break;
  986. case (RH_C_PORT_RESET):
  987. USB_RH_PRINTF("Root-Hub: C Port reset Port %d\n",wIndex);
  988. break;
  989. default:
  990. USB_RH_PRINTF("Root-Hub: unknown %x %x\n",wValue,wIndex);
  991. break;
  992. }
  993. }
  994. #endif
  995. #ifdef USB_UHCI_DEBUG
  996. static int usb_display_td(uhci_td_t *td)
  997. {
  998. unsigned long tmp;
  999. int valid;
  1000. printf("TD at %p:\n",td);
  1001. tmp=swap_32(td->link);
  1002. printf("Link points to 0x%08lX, %s first, %s, %s\n",tmp&0xfffffff0,
  1003. ((tmp & 0x4)==0x4) ? "Depth" : "Breath",
  1004. ((tmp & 0x2)==0x2) ? "QH" : "TD",
  1005. ((tmp & 0x1)==0x1) ? "invalid" : "valid");
  1006. valid=((tmp & 0x1)==0x0);
  1007. tmp=swap_32(td->status);
  1008. printf(" %s %ld Errors %s %s %s \n %s %s %s %s %s %s\n Len 0x%lX\n",
  1009. (((tmp>>29)&0x1)==0x1) ? "SPD Enable" : "SPD Disable",
  1010. ((tmp>>28)&0x3),
  1011. (((tmp>>26)&0x1)==0x1) ? "Low Speed" : "Full Speed",
  1012. (((tmp>>25)&0x1)==0x1) ? "ISO " : "",
  1013. (((tmp>>24)&0x1)==0x1) ? "IOC " : "",
  1014. (((tmp>>23)&0x1)==0x1) ? "Active " : "Inactive ",
  1015. (((tmp>>22)&0x1)==0x1) ? "Stalled" : "",
  1016. (((tmp>>21)&0x1)==0x1) ? "Data Buffer Error" : "",
  1017. (((tmp>>20)&0x1)==0x1) ? "Babble" : "",
  1018. (((tmp>>19)&0x1)==0x1) ? "NAK" : "",
  1019. (((tmp>>18)&0x1)==0x1) ? "Bitstuff Error" : "",
  1020. (tmp&0x7ff));
  1021. tmp=swap_32(td->info);
  1022. printf(" MaxLen 0x%lX\n",((tmp>>21)&0x7FF));
  1023. printf(" %s Endpoint 0x%lX Dev Addr 0x%lX PID 0x%lX\n",((tmp>>19)&0x1)==0x1 ? "TOGGLE" : "",
  1024. ((tmp>>15)&0xF),((tmp>>8)&0x7F),tmp&0xFF);
  1025. tmp=swap_32(td->buffer);
  1026. printf(" Buffer 0x%08lX\n",tmp);
  1027. printf(" DEV %08lX\n",td->dev_ptr);
  1028. return valid;
  1029. }
  1030. void usb_show_td(int max)
  1031. {
  1032. int i;
  1033. if(max>0) {
  1034. for(i=0;i<max;i++) {
  1035. usb_display_td(&tmp_td[i]);
  1036. }
  1037. }
  1038. else {
  1039. i=0;
  1040. do {
  1041. printf("tmp_td[%d]\n",i);
  1042. }while(usb_display_td(&tmp_td[i++]));
  1043. }
  1044. }
  1045. #endif
  1046. #endif /* CONFIG_USB_UHCI */
  1047. /* EOF */