usb_uhci.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178
  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. /*#define 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. /*
  533. * HJF - configure IRQ and base from variables optionally.
  534. */
  535. char *s;
  536. busdevfunc=pci_find_device(USB_UHCI_VEND_ID,USB_UHCI_DEV_ID,0); /* get PCI Device ID */
  537. if(busdevfunc==-1) {
  538. printf("Error USB UHCI (%04X,%04X) not found\n",USB_UHCI_VEND_ID,USB_UHCI_DEV_ID);
  539. return -1;
  540. }
  541. #if 1
  542. s = getenv("usb_irq");
  543. if (s)
  544. {
  545. temp = atoi(s);
  546. pci_write_config_byte(busdevfunc, PCI_INTERRUPT_LINE, temp);
  547. }
  548. else
  549. #endif
  550. pci_read_config_byte(busdevfunc,PCI_INTERRUPT_LINE,&temp);
  551. s = getenv("usb_base");
  552. if (s)
  553. {
  554. unsigned long temp2;
  555. temp2 = atoi(s);
  556. pci_write_config_dword(busdevfunc, PCI_BASE_ADDRESS_4, temp2|0x01);
  557. }
  558. irqvec = temp;
  559. irq_free_handler(irqvec);
  560. USB_UHCI_PRINTF("Interrupt Line = %d\n",irqvec);
  561. pci_read_config_byte(busdevfunc,PCI_INTERRUPT_PIN,&temp);
  562. USB_UHCI_PRINTF("Interrupt Pin = %ld\n",temp);
  563. pci_read_config_dword(busdevfunc,PCI_BASE_ADDRESS_4,&usb_base_addr);
  564. USB_UHCI_PRINTF("IO Base Address = 0x%lx\n",usb_base_addr);
  565. usb_base_addr&=0xFFFFFFF0;
  566. usb_base_addr+=CFG_ISA_IO_BASE_ADDRESS;
  567. rh.devnum = 0;
  568. usb_init_skel();
  569. reset_hc();
  570. start_hc();
  571. irq_install_handler(irqvec, (interrupt_handler_t *)handle_usb_interrupt, NULL);
  572. irq_install_handler(0, (interrupt_handler_t *)handle_usb_interrupt, NULL);
  573. return 0;
  574. }
  575. /* stop uhci
  576. */
  577. int usb_lowlevel_stop(void)
  578. {
  579. if(irqvec==-1)
  580. return 1;
  581. irq_free_handler(irqvec);
  582. irq_free_handler(0);
  583. reset_hc();
  584. irqvec=-1;
  585. return 0;
  586. }
  587. /*******************************************************************************************
  588. * Virtual Root Hub
  589. * Since the uhci does not have a real HUB, we simulate one ;-)
  590. */
  591. #undef USB_RH_DEBUG
  592. #ifdef USB_RH_DEBUG
  593. #define USB_RH_PRINTF(fmt,args...) printf (fmt ,##args)
  594. static void usb_display_wValue(unsigned short wValue,unsigned short wIndex);
  595. static void usb_display_Req(unsigned short req);
  596. #else
  597. #define USB_RH_PRINTF(fmt,args...)
  598. static void usb_display_wValue(unsigned short wValue,unsigned short wIndex) {}
  599. static void usb_display_Req(unsigned short req) {}
  600. #endif
  601. static unsigned char root_hub_dev_des[] =
  602. {
  603. 0x12, /* __u8 bLength; */
  604. 0x01, /* __u8 bDescriptorType; Device */
  605. 0x00, /* __u16 bcdUSB; v1.0 */
  606. 0x01,
  607. 0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */
  608. 0x00, /* __u8 bDeviceSubClass; */
  609. 0x00, /* __u8 bDeviceProtocol; */
  610. 0x08, /* __u8 bMaxPacketSize0; 8 Bytes */
  611. 0x00, /* __u16 idVendor; */
  612. 0x00,
  613. 0x00, /* __u16 idProduct; */
  614. 0x00,
  615. 0x00, /* __u16 bcdDevice; */
  616. 0x00,
  617. 0x01, /* __u8 iManufacturer; */
  618. 0x00, /* __u8 iProduct; */
  619. 0x00, /* __u8 iSerialNumber; */
  620. 0x01 /* __u8 bNumConfigurations; */
  621. };
  622. /* Configuration descriptor */
  623. static unsigned char root_hub_config_des[] =
  624. {
  625. 0x09, /* __u8 bLength; */
  626. 0x02, /* __u8 bDescriptorType; Configuration */
  627. 0x19, /* __u16 wTotalLength; */
  628. 0x00,
  629. 0x01, /* __u8 bNumInterfaces; */
  630. 0x01, /* __u8 bConfigurationValue; */
  631. 0x00, /* __u8 iConfiguration; */
  632. 0x40, /* __u8 bmAttributes;
  633. Bit 7: Bus-powered, 6: Self-powered, 5 Remote-wakwup, 4..0: resvd */
  634. 0x00, /* __u8 MaxPower; */
  635. /* interface */
  636. 0x09, /* __u8 if_bLength; */
  637. 0x04, /* __u8 if_bDescriptorType; Interface */
  638. 0x00, /* __u8 if_bInterfaceNumber; */
  639. 0x00, /* __u8 if_bAlternateSetting; */
  640. 0x01, /* __u8 if_bNumEndpoints; */
  641. 0x09, /* __u8 if_bInterfaceClass; HUB_CLASSCODE */
  642. 0x00, /* __u8 if_bInterfaceSubClass; */
  643. 0x00, /* __u8 if_bInterfaceProtocol; */
  644. 0x00, /* __u8 if_iInterface; */
  645. /* endpoint */
  646. 0x07, /* __u8 ep_bLength; */
  647. 0x05, /* __u8 ep_bDescriptorType; Endpoint */
  648. 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */
  649. 0x03, /* __u8 ep_bmAttributes; Interrupt */
  650. 0x08, /* __u16 ep_wMaxPacketSize; 8 Bytes */
  651. 0x00,
  652. 0xff /* __u8 ep_bInterval; 255 ms */
  653. };
  654. static unsigned char root_hub_hub_des[] =
  655. {
  656. 0x09, /* __u8 bLength; */
  657. 0x29, /* __u8 bDescriptorType; Hub-descriptor */
  658. 0x02, /* __u8 bNbrPorts; */
  659. 0x00, /* __u16 wHubCharacteristics; */
  660. 0x00,
  661. 0x01, /* __u8 bPwrOn2pwrGood; 2ms */
  662. 0x00, /* __u8 bHubContrCurrent; 0 mA */
  663. 0x00, /* __u8 DeviceRemovable; *** 7 Ports max *** */
  664. 0xff /* __u8 PortPwrCtrlMask; *** 7 ports max *** */
  665. };
  666. static unsigned char root_hub_str_index0[] =
  667. {
  668. 0x04, /* __u8 bLength; */
  669. 0x03, /* __u8 bDescriptorType; String-descriptor */
  670. 0x09, /* __u8 lang ID */
  671. 0x04, /* __u8 lang ID */
  672. };
  673. static unsigned char root_hub_str_index1[] =
  674. {
  675. 28, /* __u8 bLength; */
  676. 0x03, /* __u8 bDescriptorType; String-descriptor */
  677. 'U', /* __u8 Unicode */
  678. 0, /* __u8 Unicode */
  679. 'H', /* __u8 Unicode */
  680. 0, /* __u8 Unicode */
  681. 'C', /* __u8 Unicode */
  682. 0, /* __u8 Unicode */
  683. 'I', /* __u8 Unicode */
  684. 0, /* __u8 Unicode */
  685. ' ', /* __u8 Unicode */
  686. 0, /* __u8 Unicode */
  687. 'R', /* __u8 Unicode */
  688. 0, /* __u8 Unicode */
  689. 'o', /* __u8 Unicode */
  690. 0, /* __u8 Unicode */
  691. 'o', /* __u8 Unicode */
  692. 0, /* __u8 Unicode */
  693. 't', /* __u8 Unicode */
  694. 0, /* __u8 Unicode */
  695. ' ', /* __u8 Unicode */
  696. 0, /* __u8 Unicode */
  697. 'H', /* __u8 Unicode */
  698. 0, /* __u8 Unicode */
  699. 'u', /* __u8 Unicode */
  700. 0, /* __u8 Unicode */
  701. 'b', /* __u8 Unicode */
  702. 0, /* __u8 Unicode */
  703. };
  704. /*
  705. * Root Hub Control Pipe (interrupt Pipes are not supported)
  706. */
  707. int uhci_submit_rh_msg(struct usb_device *dev, unsigned long pipe, void *buffer,int transfer_len,struct devrequest *cmd)
  708. {
  709. void *data = buffer;
  710. int leni = transfer_len;
  711. int len = 0;
  712. int status = 0;
  713. int stat = 0;
  714. int i;
  715. unsigned short cstatus;
  716. unsigned short bmRType_bReq;
  717. unsigned short wValue;
  718. unsigned short wIndex;
  719. unsigned short wLength;
  720. if ((pipe & PIPE_INTERRUPT) == PIPE_INTERRUPT) {
  721. printf("Root-Hub submit IRQ: NOT implemented\n");
  722. #if 0
  723. uhci->rh.urb = urb;
  724. uhci->rh.send = 1;
  725. uhci->rh.interval = urb->interval;
  726. rh_init_int_timer (urb);
  727. #endif
  728. return 0;
  729. }
  730. bmRType_bReq = cmd->requesttype | cmd->request << 8;
  731. wValue = swap_16(cmd->value);
  732. wIndex = swap_16(cmd->index);
  733. wLength = swap_16(cmd->length);
  734. usb_display_Req(bmRType_bReq);
  735. for (i = 0; i < 8; i++)
  736. rh.c_p_r[i] = 0;
  737. USB_RH_PRINTF("Root-Hub: adr: %2x cmd(%1x): %02x%02x %04x %04x %04x\n",
  738. dev->devnum, 8, cmd->requesttype,cmd->request, wValue, wIndex, wLength);
  739. switch (bmRType_bReq) {
  740. /* Request Destination:
  741. without flags: Device,
  742. RH_INTERFACE: interface,
  743. RH_ENDPOINT: endpoint,
  744. RH_CLASS means HUB here,
  745. RH_OTHER | RH_CLASS almost ever means HUB_PORT here
  746. */
  747. case RH_GET_STATUS:
  748. *(unsigned short *) data = swap_16(1);
  749. len=2;
  750. break;
  751. case RH_GET_STATUS | RH_INTERFACE:
  752. *(unsigned short *) data = swap_16(0);
  753. len=2;
  754. break;
  755. case RH_GET_STATUS | RH_ENDPOINT:
  756. *(unsigned short *) data = swap_16(0);
  757. len=2;
  758. break;
  759. case RH_GET_STATUS | RH_CLASS:
  760. *(unsigned long *) data = swap_32(0);
  761. len=4;
  762. break; /* hub power ** */
  763. case RH_GET_STATUS | RH_OTHER | RH_CLASS:
  764. status = in16r(usb_base_addr + USBPORTSC1 + 2 * (wIndex - 1));
  765. cstatus = ((status & USBPORTSC_CSC) >> (1 - 0)) |
  766. ((status & USBPORTSC_PEC) >> (3 - 1)) |
  767. (rh.c_p_r[wIndex - 1] << (0 + 4));
  768. status = (status & USBPORTSC_CCS) |
  769. ((status & USBPORTSC_PE) >> (2 - 1)) |
  770. ((status & USBPORTSC_SUSP) >> (12 - 2)) |
  771. ((status & USBPORTSC_PR) >> (9 - 4)) |
  772. (1 << 8) | /* power on ** */
  773. ((status & USBPORTSC_LSDA) << (-8 + 9));
  774. *(unsigned short *) data = swap_16(status);
  775. *(unsigned short *) (data + 2) = swap_16(cstatus);
  776. len=4;
  777. break;
  778. case RH_CLEAR_FEATURE | RH_ENDPOINT:
  779. switch (wValue) {
  780. case (RH_ENDPOINT_STALL):
  781. len=0;
  782. break;
  783. }
  784. break;
  785. case RH_CLEAR_FEATURE | RH_CLASS:
  786. switch (wValue) {
  787. case (RH_C_HUB_OVER_CURRENT):
  788. len=0; /* hub power over current ** */
  789. break;
  790. }
  791. break;
  792. case RH_CLEAR_FEATURE | RH_OTHER | RH_CLASS:
  793. usb_display_wValue(wValue,wIndex);
  794. switch (wValue) {
  795. case (RH_PORT_ENABLE):
  796. status = in16r(usb_base_addr+USBPORTSC1+2*(wIndex-1));
  797. status = (status & 0xfff5) & ~USBPORTSC_PE;
  798. out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
  799. len=0;
  800. break;
  801. case (RH_PORT_SUSPEND):
  802. status = in16r(usb_base_addr+USBPORTSC1+2*(wIndex-1));
  803. status = (status & 0xfff5) & ~USBPORTSC_SUSP;
  804. out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
  805. len=0;
  806. break;
  807. case (RH_PORT_POWER):
  808. len=0; /* port power ** */
  809. break;
  810. case (RH_C_PORT_CONNECTION):
  811. status = in16r(usb_base_addr+USBPORTSC1+2*(wIndex-1));
  812. status = (status & 0xfff5) | USBPORTSC_CSC;
  813. out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
  814. len=0;
  815. break;
  816. case (RH_C_PORT_ENABLE):
  817. status = in16r(usb_base_addr+USBPORTSC1+2*(wIndex-1));
  818. status = (status & 0xfff5) | USBPORTSC_PEC;
  819. out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
  820. len=0;
  821. break;
  822. case (RH_C_PORT_SUSPEND):
  823. /*** WR_RH_PORTSTAT(RH_PS_PSSC); */
  824. len=0;
  825. break;
  826. case (RH_C_PORT_OVER_CURRENT):
  827. len=0;
  828. break;
  829. case (RH_C_PORT_RESET):
  830. rh.c_p_r[wIndex - 1] = 0;
  831. len=0;
  832. break;
  833. }
  834. break;
  835. case RH_SET_FEATURE | RH_OTHER | RH_CLASS:
  836. usb_display_wValue(wValue,wIndex);
  837. switch (wValue) {
  838. case (RH_PORT_SUSPEND):
  839. status = in16r(usb_base_addr+USBPORTSC1+2*(wIndex-1));
  840. status = (status & 0xfff5) | USBPORTSC_SUSP;
  841. out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
  842. len=0;
  843. break;
  844. case (RH_PORT_RESET):
  845. status = in16r(usb_base_addr+USBPORTSC1+2*(wIndex-1));
  846. status = (status & 0xfff5) | USBPORTSC_PR;
  847. out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
  848. wait_ms(10);
  849. status = (status & 0xfff5) & ~USBPORTSC_PR;
  850. out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
  851. udelay(10);
  852. status = (status & 0xfff5) | USBPORTSC_PE;
  853. out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
  854. wait_ms(10);
  855. status = (status & 0xfff5) | 0xa;
  856. out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
  857. len=0;
  858. break;
  859. case (RH_PORT_POWER):
  860. len=0; /* port power ** */
  861. break;
  862. case (RH_PORT_ENABLE):
  863. status = in16r(usb_base_addr+USBPORTSC1+2*(wIndex-1));
  864. status = (status & 0xfff5) | USBPORTSC_PE;
  865. out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
  866. len=0;
  867. break;
  868. }
  869. break;
  870. case RH_SET_ADDRESS:
  871. rh.devnum = wValue;
  872. len=0;
  873. break;
  874. case RH_GET_DESCRIPTOR:
  875. switch ((wValue & 0xff00) >> 8) {
  876. case (0x01): /* device descriptor */
  877. i=sizeof(root_hub_config_des);
  878. status=i > wLength ? wLength : i;
  879. len = leni > status ? status : leni;
  880. memcpy (data, root_hub_dev_des, len);
  881. break;
  882. case (0x02): /* configuration descriptor */
  883. i=sizeof(root_hub_config_des);
  884. status=i > wLength ? wLength : i;
  885. len = leni > status ? status : leni;
  886. memcpy (data, root_hub_config_des, len);
  887. break;
  888. case (0x03): /*string descriptors */
  889. if(wValue==0x0300) {
  890. i=sizeof(root_hub_str_index0);
  891. status = i > wLength ? wLength : i;
  892. len = leni > status ? status : leni;
  893. memcpy (data, root_hub_str_index0, len);
  894. break;
  895. }
  896. if(wValue==0x0301) {
  897. i=sizeof(root_hub_str_index1);
  898. status = i > wLength ? wLength : i;
  899. len = leni > status ? status : leni;
  900. memcpy (data, root_hub_str_index1, len);
  901. break;
  902. }
  903. stat = USB_ST_STALLED;
  904. }
  905. break;
  906. case RH_GET_DESCRIPTOR | RH_CLASS:
  907. root_hub_hub_des[2] = 2;
  908. i=sizeof(root_hub_hub_des);
  909. status= i > wLength ? wLength : i;
  910. len = leni > status ? status : leni;
  911. memcpy (data, root_hub_hub_des, len);
  912. break;
  913. case RH_GET_CONFIGURATION:
  914. *(unsigned char *) data = 0x01;
  915. len = 1;
  916. break;
  917. case RH_SET_CONFIGURATION:
  918. len=0;
  919. break;
  920. default:
  921. stat = USB_ST_STALLED;
  922. }
  923. USB_RH_PRINTF("Root-Hub stat %lx port1: %x port2: %x\n\n",stat,
  924. in16r(usb_base_addr + USBPORTSC1), in16r(usb_base_addr + USBPORTSC2));
  925. dev->act_len=len;
  926. dev->status=stat;
  927. return stat;
  928. }
  929. /********************************************************************************
  930. * Some Debug Routines
  931. */
  932. #ifdef USB_RH_DEBUG
  933. static void usb_display_Req(unsigned short req)
  934. {
  935. USB_RH_PRINTF("- Root-Hub Request: ");
  936. switch (req) {
  937. case RH_GET_STATUS:
  938. USB_RH_PRINTF("Get Status ");
  939. break;
  940. case RH_GET_STATUS | RH_INTERFACE:
  941. USB_RH_PRINTF("Get Status Interface ");
  942. break;
  943. case RH_GET_STATUS | RH_ENDPOINT:
  944. USB_RH_PRINTF("Get Status Endpoint ");
  945. break;
  946. case RH_GET_STATUS | RH_CLASS:
  947. USB_RH_PRINTF("Get Status Class");
  948. break; /* hub power ** */
  949. case RH_GET_STATUS | RH_OTHER | RH_CLASS:
  950. USB_RH_PRINTF("Get Status Class Others");
  951. break;
  952. case RH_CLEAR_FEATURE | RH_ENDPOINT:
  953. USB_RH_PRINTF("Clear Feature Endpoint ");
  954. break;
  955. case RH_CLEAR_FEATURE | RH_CLASS:
  956. USB_RH_PRINTF("Clear Feature Class ");
  957. break;
  958. case RH_CLEAR_FEATURE | RH_OTHER | RH_CLASS:
  959. USB_RH_PRINTF("Clear Feature Other Class ");
  960. break;
  961. case RH_SET_FEATURE | RH_OTHER | RH_CLASS:
  962. USB_RH_PRINTF("Set Feature Other Class ");
  963. break;
  964. case RH_SET_ADDRESS:
  965. USB_RH_PRINTF("Set Address ");
  966. break;
  967. case RH_GET_DESCRIPTOR:
  968. USB_RH_PRINTF("Get Descriptor ");
  969. break;
  970. case RH_GET_DESCRIPTOR | RH_CLASS:
  971. USB_RH_PRINTF("Get Descriptor Class ");
  972. break;
  973. case RH_GET_CONFIGURATION:
  974. USB_RH_PRINTF("Get Configuration ");
  975. break;
  976. case RH_SET_CONFIGURATION:
  977. USB_RH_PRINTF("Get Configuration ");
  978. break;
  979. default:
  980. USB_RH_PRINTF("****UNKNOWN**** 0x%04X ",req);
  981. }
  982. USB_RH_PRINTF("\n");
  983. }
  984. static void usb_display_wValue(unsigned short wValue,unsigned short wIndex)
  985. {
  986. switch (wValue) {
  987. case (RH_PORT_ENABLE):
  988. USB_RH_PRINTF("Root-Hub: Enable Port %d\n",wIndex);
  989. break;
  990. case (RH_PORT_SUSPEND):
  991. USB_RH_PRINTF("Root-Hub: Suspend Port %d\n",wIndex);
  992. break;
  993. case (RH_PORT_POWER):
  994. USB_RH_PRINTF("Root-Hub: Port Power %d\n",wIndex);
  995. break;
  996. case (RH_C_PORT_CONNECTION):
  997. USB_RH_PRINTF("Root-Hub: C Port Connection Port %d\n",wIndex);
  998. break;
  999. case (RH_C_PORT_ENABLE):
  1000. USB_RH_PRINTF("Root-Hub: C Port Enable Port %d\n",wIndex);
  1001. break;
  1002. case (RH_C_PORT_SUSPEND):
  1003. USB_RH_PRINTF("Root-Hub: C Port Suspend Port %d\n",wIndex);
  1004. break;
  1005. case (RH_C_PORT_OVER_CURRENT):
  1006. USB_RH_PRINTF("Root-Hub: C Port Over Current Port %d\n",wIndex);
  1007. break;
  1008. case (RH_C_PORT_RESET):
  1009. USB_RH_PRINTF("Root-Hub: C Port reset Port %d\n",wIndex);
  1010. break;
  1011. default:
  1012. USB_RH_PRINTF("Root-Hub: unknown %x %x\n",wValue,wIndex);
  1013. break;
  1014. }
  1015. }
  1016. #endif
  1017. #ifdef USB_UHCI_DEBUG
  1018. static int usb_display_td(uhci_td_t *td)
  1019. {
  1020. unsigned long tmp;
  1021. int valid;
  1022. printf("TD at %p:\n",td);
  1023. tmp=swap_32(td->link);
  1024. printf("Link points to 0x%08lX, %s first, %s, %s\n",tmp&0xfffffff0,
  1025. ((tmp & 0x4)==0x4) ? "Depth" : "Breath",
  1026. ((tmp & 0x2)==0x2) ? "QH" : "TD",
  1027. ((tmp & 0x1)==0x1) ? "invalid" : "valid");
  1028. valid=((tmp & 0x1)==0x0);
  1029. tmp=swap_32(td->status);
  1030. printf(" %s %ld Errors %s %s %s \n %s %s %s %s %s %s\n Len 0x%lX\n",
  1031. (((tmp>>29)&0x1)==0x1) ? "SPD Enable" : "SPD Disable",
  1032. ((tmp>>28)&0x3),
  1033. (((tmp>>26)&0x1)==0x1) ? "Low Speed" : "Full Speed",
  1034. (((tmp>>25)&0x1)==0x1) ? "ISO " : "",
  1035. (((tmp>>24)&0x1)==0x1) ? "IOC " : "",
  1036. (((tmp>>23)&0x1)==0x1) ? "Active " : "Inactive ",
  1037. (((tmp>>22)&0x1)==0x1) ? "Stalled" : "",
  1038. (((tmp>>21)&0x1)==0x1) ? "Data Buffer Error" : "",
  1039. (((tmp>>20)&0x1)==0x1) ? "Babble" : "",
  1040. (((tmp>>19)&0x1)==0x1) ? "NAK" : "",
  1041. (((tmp>>18)&0x1)==0x1) ? "Bitstuff Error" : "",
  1042. (tmp&0x7ff));
  1043. tmp=swap_32(td->info);
  1044. printf(" MaxLen 0x%lX\n",((tmp>>21)&0x7FF));
  1045. printf(" %s Endpoint 0x%lX Dev Addr 0x%lX PID 0x%lX\n",((tmp>>19)&0x1)==0x1 ? "TOGGLE" : "",
  1046. ((tmp>>15)&0xF),((tmp>>8)&0x7F),tmp&0xFF);
  1047. tmp=swap_32(td->buffer);
  1048. printf(" Buffer 0x%08lX\n",tmp);
  1049. printf(" DEV %08lX\n",td->dev_ptr);
  1050. return valid;
  1051. }
  1052. void usb_show_td(int max)
  1053. {
  1054. int i;
  1055. if(max>0) {
  1056. for(i=0;i<max;i++) {
  1057. usb_display_td(&tmp_td[i]);
  1058. }
  1059. }
  1060. else {
  1061. i=0;
  1062. do {
  1063. printf("tmp_td[%d]\n",i);
  1064. }while(usb_display_td(&tmp_td[i++]));
  1065. }
  1066. }
  1067. #endif
  1068. #endif /* CONFIG_USB_UHCI */
  1069. /* EOF */