usb_uhci.c 35 KB

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