usb_uhci.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195
  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 transferred 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. DECLARE_GLOBAL_DATA_PTR;
  84. #define USB_MAX_TEMP_TD 128 /* number of temporary TDs for bulk and control transfers */
  85. #define USB_MAX_TEMP_INT_TD 32 /* number of temporary TDs for Interrupt transfers */
  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 transferred 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 transferred 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 (!gd->arch.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 (!gd->arch.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; /* transferred 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. ambapp_ahbdev ahbdev;
  636. /* Find GRUSB core using AMBA Plug&Play information */
  637. if (ambapp_ahbslv_find(&ambapp_plb, VENDOR_GAISLER, GAISLER_UHCI,
  638. CONFIG_SYS_GRLIB_GRUSB_INDEX, &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 */