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