usb_uhci.c 35 KB

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