1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74#include <common.h>
75#include <pci.h>
76
77#ifdef CONFIG_USB_UHCI
78
79#include <usb.h>
80#include "usb_uhci.h"
81
82#define USB_MAX_TEMP_TD 128
83#define USB_MAX_TEMP_INT_TD 32
84
85
86#undef USB_UHCI_DEBUG
87
88#ifdef USB_UHCI_DEBUG
89#define USB_UHCI_PRINTF(fmt,args...) printf (fmt ,##args)
90#else
91#define USB_UHCI_PRINTF(fmt,args...)
92#endif
93
94
95static int irqvec = -1;
96unsigned int usb_base_addr;
97
98static uhci_td_t td_int[8];
99static uhci_qh_t qh_cntrl;
100static uhci_qh_t qh_bulk;
101static uhci_qh_t qh_end;
102static uhci_td_t td_last;
103
104
105static uhci_td_t tmp_td[USB_MAX_TEMP_TD];
106static uhci_td_t tmp_int_td[USB_MAX_TEMP_INT_TD];
107
108static unsigned long framelist[1024] __attribute__ ((aligned (0x1000)));
109
110static struct virt_root_hub rh;
111
112
113
114
115int uhci_submit_rh_msg(struct usb_device *dev, unsigned long pipe,
116 void *buffer, int transfer_len,struct devrequest *setup);
117
118
119
120
121
122void usb_fill_td(uhci_td_t* td,unsigned long link,unsigned long status,
123 unsigned long info, unsigned long buffer, unsigned long dev)
124{
125 td->link=swap_32(link);
126 td->status=swap_32(status);
127 td->info=swap_32(info);
128 td->buffer=swap_32(buffer);
129 td->dev_ptr=dev;
130}
131
132
133
134
135
136
137void usb_fill_qh(uhci_qh_t* qh,unsigned long head,unsigned long element)
138{
139 qh->head=swap_32(head);
140 qh->element=swap_32(element);
141 qh->dev_ptr=0L;
142}
143
144
145
146unsigned long usb_uhci_td_stat(unsigned long status)
147{
148 unsigned long result=0;
149 result |= (status & TD_CTRL_NAK) ? USB_ST_NAK_REC : 0;
150 result |= (status & TD_CTRL_STALLED) ? USB_ST_STALLED : 0;
151 result |= (status & TD_CTRL_DBUFERR) ? USB_ST_BUF_ERR : 0;
152 result |= (status & TD_CTRL_BABBLE) ? USB_ST_BABBLE_DET : 0;
153 result |= (status & TD_CTRL_CRCTIMEO) ? USB_ST_CRC_ERR : 0;
154 result |= (status & TD_CTRL_BITSTUFF) ? USB_ST_BIT_ERR : 0;
155 result |= (status & TD_CTRL_ACTIVE) ? USB_ST_NOT_PROC : 0;
156 return result;
157}
158
159
160
161
162int usb_get_td_status(uhci_td_t *td,struct usb_device *dev)
163{
164 unsigned long temp,info;
165 unsigned long stat;
166 uhci_td_t *mytd=td;
167
168 if(dev->devnum==rh.devnum)
169 return 0;
170 dev->act_len=0;
171 stat=0;
172 do {
173 temp=swap_32((unsigned long)mytd->status);
174 stat=usb_uhci_td_stat(temp);
175 info=swap_32((unsigned long)mytd->info);
176 if(((info & 0xff)!= USB_PID_SETUP) &&
177 (((info >> 21) & 0x7ff)!= 0x7ff) &&
178 (temp & 0x7FF)!=0x7ff)
179 {
180 dev->act_len+=(temp & 0x7FF) + 1;
181 }
182 if(stat) {
183 dev->status=stat;
184 return -1;
185 }
186 temp=swap_32((unsigned long)mytd->link);
187 mytd=(uhci_td_t *)(temp & 0xfffffff0);
188 }while((temp & 0x1)==0);
189 dev->status=stat;
190 return 0;
191}
192
193
194
195
196
197
198
199
200
201
202int submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
203 int transfer_len,struct devrequest *setup)
204{
205 unsigned long destination, status;
206 int maxsze = usb_maxpacket(dev, pipe);
207 unsigned long dataptr;
208 int len;
209 int pktsze;
210 int i=0;
211
212 if (!maxsze) {
213 USB_UHCI_PRINTF("uhci_submit_control_urb: pipesize for pipe %lx is zero\n", pipe);
214 return -1;
215 }
216 if(((pipe>>8)&0x7f)==rh.devnum) {
217
218 return uhci_submit_rh_msg(dev,pipe,buffer,transfer_len,setup);
219 }
220 USB_UHCI_PRINTF("uhci_submit_control start len %x, maxsize %x\n",transfer_len,maxsze);
221
222 destination = (pipe & PIPE_DEVEP_MASK) | USB_PID_SETUP;
223
224 status = (pipe & TD_CTRL_LS) | TD_CTRL_ACTIVE | (3 << 27);
225
226
227 usb_fill_td(&tmp_td[i],UHCI_PTR_TERM ,status, destination | (7 << 21),(unsigned long)setup,(unsigned long)dev);
228#if 0
229 {
230 char *sp=(char *)setup;
231 printf("SETUP to pipe %lx: %x %x %x %x %x %x %x %x\n", pipe,
232 sp[0],sp[1],sp[2],sp[3],sp[4],sp[5],sp[6],sp[7]);
233 }
234#endif
235 dataptr = (unsigned long)buffer;
236 len=transfer_len;
237
238
239
240 destination = (pipe & PIPE_DEVEP_MASK) | ((pipe & USB_DIR_IN)==0 ? USB_PID_OUT : USB_PID_IN);
241 while (len > 0) {
242
243 pktsze = len;
244 i++;
245 if (pktsze > maxsze)
246 pktsze = maxsze;
247 destination ^= 1 << TD_TOKEN_TOGGLE;
248 usb_fill_td(&tmp_td[i],UHCI_PTR_TERM, status, destination | ((pktsze - 1) << 21),dataptr,(unsigned long)dev);
249 tmp_td[i-1].link=swap_32((unsigned long)&tmp_td[i]);
250
251 dataptr += pktsze;
252 len -= pktsze;
253 }
254
255
256
257
258 destination &= ~UHCI_PID;
259 if (((pipe & USB_DIR_IN)==0) || (transfer_len == 0))
260 destination |= USB_PID_IN;
261 else
262 destination |= USB_PID_OUT;
263 destination |= 1 << TD_TOKEN_TOGGLE;
264 i++;
265 status &=~TD_CTRL_SPD;
266
267 usb_fill_td(&tmp_td[i],UHCI_PTR_TERM, status | TD_CTRL_IOC, destination | (UHCI_NULL_DATA_SIZE << 21),0,(unsigned long)dev);
268 tmp_td[i-1].link=swap_32((unsigned long)&tmp_td[i]);
269
270 USB_UHCI_PRINTF("uhci_submit_control end (%d tmp_tds used)\n",i);
271
272 qh_cntrl.element=0xffffffffL;
273
274 qh_cntrl.dev_ptr=(unsigned long)dev;
275
276 qh_cntrl.element=swap_32((unsigned long)&tmp_td[0]);
277 return 0;
278}
279
280
281
282
283int submit_bulk_msg(struct usb_device *dev, unsigned long pipe, void *buffer,int transfer_len)
284{
285 unsigned long destination, status,info;
286 unsigned long dataptr;
287 int maxsze = usb_maxpacket(dev, pipe);
288 int len;
289 int i=0;
290
291 if(transfer_len < 0) {
292 printf("Negative transfer length in submit_bulk\n");
293 return -1;
294 }
295 if (!maxsze)
296 return -1;
297
298 destination = (pipe & PIPE_DEVEP_MASK) | usb_packetid (pipe);
299
300 status = (pipe & TD_CTRL_LS) | TD_CTRL_ACTIVE | (3 << 27);
301
302
303 len = transfer_len;
304 dataptr = (unsigned long)buffer;
305 do {
306 int pktsze = len;
307 if (pktsze > maxsze)
308 pktsze = maxsze;
309
310 info = destination | (((pktsze - 1)&UHCI_NULL_DATA_SIZE) << 21) |
311 (usb_gettoggle (dev, usb_pipeendpoint (pipe), usb_pipeout (pipe)) << TD_TOKEN_TOGGLE);
312
313 if((len-pktsze)==0)
314 status |= TD_CTRL_IOC;
315
316 usb_fill_td(&tmp_td[i],UHCI_PTR_TERM, status, info,dataptr,(unsigned long)dev);
317 if(i>0)
318 tmp_td[i-1].link=swap_32((unsigned long)&tmp_td[i]);
319 i++;
320 dataptr += pktsze;
321 len -= pktsze;
322 usb_dotoggle (dev, usb_pipeendpoint (pipe), usb_pipeout (pipe));
323 } while (len > 0);
324
325 qh_bulk.element=0xffffffffL;
326
327 qh_bulk.dev_ptr=(unsigned long)dev;
328
329 qh_bulk.element=swap_32((unsigned long)&tmp_td[0]);
330 return 0;
331}
332
333
334
335
336uhci_td_t *uhci_alloc_int_td(void)
337{
338 int i;
339 for(i=0;i<USB_MAX_TEMP_INT_TD;i++) {
340 if(tmp_int_td[i].dev_ptr==0)
341 return &tmp_int_td[i];
342 }
343 return NULL;
344}
345
346#if 0
347void uhci_show_temp_int_td(void)
348{
349 int i;
350 for(i=0;i<USB_MAX_TEMP_INT_TD;i++) {
351 if((tmp_int_td[i].dev_ptr&0x01)!=0x1L)
352 printf("temp_td %d is assigned to dev %lx\n",i,tmp_int_td[i].dev_ptr);
353 }
354 printf("all others temp_tds are free\n");
355}
356#endif
357
358
359
360int submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer,int transfer_len, int interval)
361{
362 int nint, n;
363 unsigned long status, destination;
364 unsigned long info,tmp;
365 uhci_td_t *mytd;
366 if (interval < 0 || interval >= 256)
367 return -1;
368
369 if (interval == 0)
370 nint = 0;
371 else {
372 for (nint = 0, n = 1; nint <= 8; nint++, n += n)
373 {
374 if(interval < n) {
375 interval = n / 2;
376 break;
377 }
378 }
379 nint--;
380 }
381
382 USB_UHCI_PRINTF("Rounded interval to %i, chain %i\n", interval, nint);
383 mytd=uhci_alloc_int_td();
384 if(mytd==NULL) {
385 printf("No free INT TDs found\n");
386 return -1;
387 }
388 status = (pipe & TD_CTRL_LS) | TD_CTRL_ACTIVE | TD_CTRL_IOC | (3 << 27);
389
390
391
392 destination =(pipe & PIPE_DEVEP_MASK) | usb_packetid (pipe) | (((transfer_len - 1) & 0x7ff) << 21);
393
394 info = destination | (usb_gettoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe)) << TD_TOKEN_TOGGLE);
395 tmp = swap_32(td_int[nint].link);
396 usb_fill_td(mytd,tmp,status, info,(unsigned long)buffer,(unsigned long)dev);
397
398 tmp = swap_32((unsigned long)mytd);
399 td_int[nint].link=tmp;
400
401 usb_dotoggle (dev, usb_pipeendpoint (pipe), usb_pipeout (pipe));
402
403 return 0;
404}
405
406
407
408
409
410
411void reset_hc(void)
412{
413
414
415 out16r( usb_base_addr + USBPORTSC1,0x0204);
416 out16r( usb_base_addr + USBPORTSC2,0x0204);
417 out16r( usb_base_addr + USBCMD,USBCMD_GRESET | USBCMD_RS);
418
419 out16r(usb_base_addr + USBINTR,0);
420 mdelay(50);
421 out16r( usb_base_addr + USBCMD,0);
422 mdelay(10);
423}
424
425void start_hc(void)
426{
427 int timeout = 1000;
428
429 while(in16r(usb_base_addr + USBCMD) & USBCMD_HCRESET) {
430 if (!--timeout) {
431 printf("USBCMD_HCRESET timed out!\n");
432 break;
433 }
434 }
435
436 out16r(usb_base_addr + USBINTR,USBINTR_TIMEOUT | USBINTR_RESUME | USBINTR_IOC | USBINTR_SP);
437
438 out16r(usb_base_addr + USBFRNUM,0);
439
440 out32r(usb_base_addr+USBFLBASEADD,(unsigned long)&framelist);
441
442 out16r(usb_base_addr + USBCMD,USBCMD_RS | USBCMD_CF | USBCMD_MAXP);
443}
444
445
446
447void usb_init_skel(void)
448{
449 unsigned long temp;
450 int n;
451
452 for(n=0;n<USB_MAX_TEMP_INT_TD;n++)
453 tmp_int_td[n].dev_ptr=0L;
454
455 usb_fill_td(&td_last,UHCI_PTR_TERM,TD_CTRL_IOC ,0,0,0L);
456
457
458 usb_fill_qh(&qh_end,UHCI_PTR_TERM,(unsigned long)&td_last);
459
460 temp=(unsigned long)&qh_end;
461 usb_fill_qh(&qh_bulk,temp | UHCI_PTR_QH,UHCI_PTR_TERM);
462
463 temp=(unsigned long)&qh_bulk;
464 usb_fill_qh(&qh_cntrl, temp | UHCI_PTR_QH,UHCI_PTR_TERM);
465
466 temp=(unsigned long)&qh_cntrl;
467 usb_fill_td(&td_int[0],temp | UHCI_PTR_QH,0,0,0,0L);
468 temp=(unsigned long)&td_int[0];
469 for(n=1; n<8; n++)
470 usb_fill_td(&td_int[n],temp,0,0,0,0L);
471 for (n = 0; n < 1024; n++) {
472
473 int m, o;
474 if ((n&127)==127)
475 framelist[n]= swap_32((unsigned long)&td_int[0]);
476 else
477 for (o = 1, m = 2; m <= 128; o++, m += m)
478 if ((n & (m - 1)) == ((m - 1) / 2))
479 framelist[n]= swap_32((unsigned long)&td_int[o]);
480 }
481}
482
483
484
485
486void usb_check_skel(void)
487{
488 struct usb_device *dev;
489
490 if(qh_cntrl.dev_ptr!=0)
491 {
492 dev=(struct usb_device *)qh_cntrl.dev_ptr;
493 usb_get_td_status(&tmp_td[0],dev);
494 if(!(dev->status & USB_ST_NOT_PROC)) {
495 qh_cntrl.dev_ptr=0;
496 }
497 }
498
499 if(qh_bulk.dev_ptr!=0)
500 {
501 dev=(struct usb_device *)qh_bulk.dev_ptr;
502 usb_get_td_status(&tmp_td[0],dev);
503 if(!(dev->status & USB_ST_NOT_PROC)) {
504 qh_bulk.dev_ptr=0;
505 }
506 }
507}
508
509
510
511
512
513void usb_check_int_chain(void)
514{
515 int i,res;
516 unsigned long link,status;
517 struct usb_device *dev;
518 uhci_td_t *td,*prevtd;
519
520 for(i=0;i<8;i++) {
521 prevtd = &td_int[i];
522 link=swap_32(td_int[i].link) & 0xfffffff0;
523 td=(uhci_td_t *)link;
524
525
526
527
528 while(((i>0) && (link != (unsigned long)&td_int[0])) ||
529 ((i==0) && !(swap_32(td->link) & UHCI_PTR_QH)))
530 {
531
532 status=swap_32(td->status);
533 if((td->dev_ptr!=0L) && !(status & TD_CTRL_ACTIVE)) {
534
535 dev=(struct usb_device *)td->dev_ptr;
536 dev->irq_act_len=((status & 0x7FF)==0x7FF) ? 0 : (status & 0x7FF) + 1;
537 dev->irq_status=usb_uhci_td_stat(status);
538 res=dev->irq_handle(dev);
539 if(res==1) {
540
541 status|=TD_CTRL_ACTIVE;
542 td->status=swap_32(status);
543 prevtd=td;
544 }
545 else {
546 prevtd->link=td->link;
547
548 td->dev_ptr=0L;
549 }
550 }
551 link=swap_32(td->link) & 0xfffffff0;
552 td=(uhci_td_t *)link;
553 }
554 }
555}
556
557
558
559
560void handle_usb_interrupt(void)
561{
562 unsigned short status;
563
564
565
566
567
568
569 status = in16r(usb_base_addr + USBSTS);
570
571 if (!status)
572 return;
573 if (status != 1) {
574
575 if ((status&0x20) && ((in16r(usb_base_addr+USBCMD) && USBCMD_RS)==0)) {
576 out16r(usb_base_addr + USBCMD, USBCMD_RS | in16r(usb_base_addr + USBCMD));
577 }
578 }
579 usb_check_int_chain();
580 usb_check_skel();
581 out16r(usb_base_addr+USBSTS,status);
582}
583
584
585
586
587int usb_lowlevel_init(int index, enum usb_init_type init, void **controller)
588{
589 unsigned char temp;
590 int busdevfunc;
591
592 busdevfunc=pci_find_device(USB_UHCI_VEND_ID,USB_UHCI_DEV_ID,0);
593 if(busdevfunc==-1) {
594 printf("Error USB UHCI (%04X,%04X) not found\n",USB_UHCI_VEND_ID,USB_UHCI_DEV_ID);
595 return -1;
596 }
597 pci_read_config_byte(busdevfunc,PCI_INTERRUPT_LINE,&temp);
598 irqvec = temp;
599 irq_free_handler(irqvec);
600 USB_UHCI_PRINTF("Interrupt Line = %d, is %d\n",irqvec);
601 pci_read_config_byte(busdevfunc,PCI_INTERRUPT_PIN,&temp);
602 USB_UHCI_PRINTF("Interrupt Pin = %ld\n",temp);
603 pci_read_config_dword(busdevfunc,PCI_BASE_ADDRESS_4,&usb_base_addr);
604 USB_UHCI_PRINTF("IO Base Address = 0x%lx\n",usb_base_addr);
605 usb_base_addr&=0xFFFFFFF0;
606 usb_base_addr+=CONFIG_SYS_ISA_IO_BASE_ADDRESS;
607 rh.devnum = 0;
608 usb_init_skel();
609 reset_hc();
610 start_hc();
611 irq_install_handler(irqvec, (interrupt_handler_t *)handle_usb_interrupt, NULL);
612 return 0;
613}
614
615
616
617int usb_lowlevel_stop(int index)
618{
619 if(irqvec==-1)
620 return 1;
621 irq_free_handler(irqvec);
622 reset_hc();
623 irqvec = -1;
624 return 0;
625}
626
627
628
629
630
631#undef USB_RH_DEBUG
632
633#ifdef USB_RH_DEBUG
634#define USB_RH_PRINTF(fmt,args...) printf (fmt ,##args)
635static void usb_display_wValue(unsigned short wValue,unsigned short wIndex);
636static void usb_display_Req(unsigned short req);
637#else
638#define USB_RH_PRINTF(fmt,args...)
639static void usb_display_wValue(unsigned short wValue,unsigned short wIndex) {}
640static void usb_display_Req(unsigned short req) {}
641#endif
642
643#define WANT_USB_ROOT_HUB_HUB_DES
644#include <usbroothubdes.h>
645#undef WANT_USB_ROOT_HUB_HUB_DES
646
647
648
649
650
651
652int uhci_submit_rh_msg(struct usb_device *dev, unsigned long pipe, void *buffer,int transfer_len,struct devrequest *cmd)
653{
654 void *data = buffer;
655 int leni = transfer_len;
656 int len = 0;
657 int status = 0;
658 int stat = 0;
659 int i;
660
661 unsigned short cstatus;
662
663 unsigned short bmRType_bReq;
664 unsigned short wValue;
665 unsigned short wIndex;
666 unsigned short wLength;
667
668 if (usb_pipeint(pipe)) {
669 printf("Root-Hub submit IRQ: NOT implemented\n");
670#if 0
671 uhci->rh.urb = urb;
672 uhci->rh.send = 1;
673 uhci->rh.interval = urb->interval;
674 rh_init_int_timer (urb);
675#endif
676 return 0;
677 }
678 bmRType_bReq = cmd->requesttype | cmd->request << 8;
679 wValue = swap_16(cmd->value);
680 wIndex = swap_16(cmd->index);
681 wLength = swap_16(cmd->length);
682 usb_display_Req(bmRType_bReq);
683 for (i = 0; i < 8; i++)
684 rh.c_p_r[i] = 0;
685 USB_RH_PRINTF("Root-Hub: adr: %2x cmd(%1x): %02x%02x %04x %04x %04x\n",
686 dev->devnum, 8, cmd->requesttype,cmd->request, wValue, wIndex, wLength);
687
688 switch (bmRType_bReq) {
689
690
691
692
693
694
695
696
697 case RH_GET_STATUS:
698 *(unsigned short *) data = swap_16(1);
699 len=2;
700 break;
701 case RH_GET_STATUS | RH_INTERFACE:
702 *(unsigned short *) data = swap_16(0);
703 len=2;
704 break;
705 case RH_GET_STATUS | RH_ENDPOINT:
706 *(unsigned short *) data = swap_16(0);
707 len=2;
708 break;
709 case RH_GET_STATUS | RH_CLASS:
710 *(unsigned long *) data = swap_32(0);
711 len=4;
712 break;
713 case RH_GET_STATUS | RH_OTHER | RH_CLASS:
714
715 status = in16r(usb_base_addr + USBPORTSC1 + 2 * (wIndex - 1));
716 cstatus = ((status & USBPORTSC_CSC) >> (1 - 0)) |
717 ((status & USBPORTSC_PEC) >> (3 - 1)) |
718 (rh.c_p_r[wIndex - 1] << (0 + 4));
719 status = (status & USBPORTSC_CCS) |
720 ((status & USBPORTSC_PE) >> (2 - 1)) |
721 ((status & USBPORTSC_SUSP) >> (12 - 2)) |
722 ((status & USBPORTSC_PR) >> (9 - 4)) |
723 (1 << 8) |
724 ((status & USBPORTSC_LSDA) << (-8 + 9));
725
726 *(unsigned short *) data = swap_16(status);
727 *(unsigned short *) (data + 2) = swap_16(cstatus);
728 len=4;
729 break;
730 case RH_CLEAR_FEATURE | RH_ENDPOINT:
731 switch (wValue) {
732 case (RH_ENDPOINT_STALL):
733 len=0;
734 break;
735 }
736 break;
737
738 case RH_CLEAR_FEATURE | RH_CLASS:
739 switch (wValue) {
740 case (RH_C_HUB_OVER_CURRENT):
741 len=0;
742 break;
743 }
744 break;
745
746 case RH_CLEAR_FEATURE | RH_OTHER | RH_CLASS:
747 usb_display_wValue(wValue,wIndex);
748 switch (wValue) {
749 case (RH_PORT_ENABLE):
750 status = in16r(usb_base_addr+USBPORTSC1+2*(wIndex-1));
751 status = (status & 0xfff5) & ~USBPORTSC_PE;
752 out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
753 len=0;
754 break;
755 case (RH_PORT_SUSPEND):
756 status = in16r(usb_base_addr+USBPORTSC1+2*(wIndex-1));
757 status = (status & 0xfff5) & ~USBPORTSC_SUSP;
758 out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
759 len=0;
760 break;
761 case (RH_PORT_POWER):
762 len=0;
763 break;
764 case (RH_C_PORT_CONNECTION):
765 status = in16r(usb_base_addr+USBPORTSC1+2*(wIndex-1));
766 status = (status & 0xfff5) | USBPORTSC_CSC;
767 out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
768 len=0;
769 break;
770 case (RH_C_PORT_ENABLE):
771 status = in16r(usb_base_addr+USBPORTSC1+2*(wIndex-1));
772 status = (status & 0xfff5) | USBPORTSC_PEC;
773 out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
774 len=0;
775 break;
776 case (RH_C_PORT_SUSPEND):
777
778 len=0;
779 break;
780 case (RH_C_PORT_OVER_CURRENT):
781 len=0;
782 break;
783 case (RH_C_PORT_RESET):
784 rh.c_p_r[wIndex - 1] = 0;
785 len=0;
786 break;
787 }
788 break;
789 case RH_SET_FEATURE | RH_OTHER | RH_CLASS:
790 usb_display_wValue(wValue,wIndex);
791 switch (wValue) {
792 case (RH_PORT_SUSPEND):
793 status = in16r(usb_base_addr+USBPORTSC1+2*(wIndex-1));
794 status = (status & 0xfff5) | USBPORTSC_SUSP;
795 out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
796 len=0;
797 break;
798 case (RH_PORT_RESET):
799 status = in16r(usb_base_addr+USBPORTSC1+2*(wIndex-1));
800 status = (status & 0xfff5) | USBPORTSC_PR;
801 out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
802 mdelay(10);
803 status = (status & 0xfff5) & ~USBPORTSC_PR;
804 out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
805 udelay(10);
806 status = (status & 0xfff5) | USBPORTSC_PE;
807 out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
808 mdelay(10);
809 status = (status & 0xfff5) | 0xa;
810 out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
811 len=0;
812 break;
813 case (RH_PORT_POWER):
814 len=0;
815 break;
816 case (RH_PORT_ENABLE):
817 status = in16r(usb_base_addr+USBPORTSC1+2*(wIndex-1));
818 status = (status & 0xfff5) | USBPORTSC_PE;
819 out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
820 len=0;
821 break;
822 }
823 break;
824
825 case RH_SET_ADDRESS:
826 rh.devnum = wValue;
827 len=0;
828 break;
829 case RH_GET_DESCRIPTOR:
830 switch ((wValue & 0xff00) >> 8) {
831 case (0x01):
832 i=sizeof(root_hub_config_des);
833 status=i > wLength ? wLength : i;
834 len = leni > status ? status : leni;
835 memcpy (data, root_hub_dev_des, len);
836 break;
837 case (0x02):
838 i=sizeof(root_hub_config_des);
839 status=i > wLength ? wLength : i;
840 len = leni > status ? status : leni;
841 memcpy (data, root_hub_config_des, len);
842 break;
843 case (0x03):
844 if(wValue==0x0300) {
845 i=sizeof(root_hub_str_index0);
846 status = i > wLength ? wLength : i;
847 len = leni > status ? status : leni;
848 memcpy (data, root_hub_str_index0, len);
849 break;
850 }
851 if(wValue==0x0301) {
852 i=sizeof(root_hub_str_index1);
853 status = i > wLength ? wLength : i;
854 len = leni > status ? status : leni;
855 memcpy (data, root_hub_str_index1, len);
856 break;
857 }
858 stat = USB_ST_STALLED;
859 }
860 break;
861
862 case RH_GET_DESCRIPTOR | RH_CLASS:
863 root_hub_hub_des[2] = 2;
864 i=sizeof(root_hub_hub_des);
865 status= i > wLength ? wLength : i;
866 len = leni > status ? status : leni;
867 memcpy (data, root_hub_hub_des, len);
868 break;
869 case RH_GET_CONFIGURATION:
870 *(unsigned char *) data = 0x01;
871 len = 1;
872 break;
873 case RH_SET_CONFIGURATION:
874 len=0;
875 break;
876 default:
877 stat = USB_ST_STALLED;
878 }
879 USB_RH_PRINTF("Root-Hub stat %lx port1: %x port2: %x\n\n",stat,
880 in16r(usb_base_addr + USBPORTSC1), in16r(usb_base_addr + USBPORTSC2));
881 dev->act_len=len;
882 dev->status=stat;
883 return stat;
884
885}
886
887
888
889
890
891#ifdef USB_RH_DEBUG
892
893static void usb_display_Req(unsigned short req)
894{
895 USB_RH_PRINTF("- Root-Hub Request: ");
896 switch (req) {
897 case RH_GET_STATUS:
898 USB_RH_PRINTF("Get Status ");
899 break;
900 case RH_GET_STATUS | RH_INTERFACE:
901 USB_RH_PRINTF("Get Status Interface ");
902 break;
903 case RH_GET_STATUS | RH_ENDPOINT:
904 USB_RH_PRINTF("Get Status Endpoint ");
905 break;
906 case RH_GET_STATUS | RH_CLASS:
907 USB_RH_PRINTF("Get Status Class");
908 break;
909 case RH_GET_STATUS | RH_OTHER | RH_CLASS:
910 USB_RH_PRINTF("Get Status Class Others");
911 break;
912 case RH_CLEAR_FEATURE | RH_ENDPOINT:
913 USB_RH_PRINTF("Clear Feature Endpoint ");
914 break;
915 case RH_CLEAR_FEATURE | RH_CLASS:
916 USB_RH_PRINTF("Clear Feature Class ");
917 break;
918 case RH_CLEAR_FEATURE | RH_OTHER | RH_CLASS:
919 USB_RH_PRINTF("Clear Feature Other Class ");
920 break;
921 case RH_SET_FEATURE | RH_OTHER | RH_CLASS:
922 USB_RH_PRINTF("Set Feature Other Class ");
923 break;
924 case RH_SET_ADDRESS:
925 USB_RH_PRINTF("Set Address ");
926 break;
927 case RH_GET_DESCRIPTOR:
928 USB_RH_PRINTF("Get Descriptor ");
929 break;
930 case RH_GET_DESCRIPTOR | RH_CLASS:
931 USB_RH_PRINTF("Get Descriptor Class ");
932 break;
933 case RH_GET_CONFIGURATION:
934 USB_RH_PRINTF("Get Configuration ");
935 break;
936 case RH_SET_CONFIGURATION:
937 USB_RH_PRINTF("Get Configuration ");
938 break;
939 default:
940 USB_RH_PRINTF("****UNKNOWN**** 0x%04X ",req);
941 }
942 USB_RH_PRINTF("\n");
943
944}
945
946static void usb_display_wValue(unsigned short wValue,unsigned short wIndex)
947{
948 switch (wValue) {
949 case (RH_PORT_ENABLE):
950 USB_RH_PRINTF("Root-Hub: Enable Port %d\n",wIndex);
951 break;
952 case (RH_PORT_SUSPEND):
953 USB_RH_PRINTF("Root-Hub: Suspend Port %d\n",wIndex);
954 break;
955 case (RH_PORT_POWER):
956 USB_RH_PRINTF("Root-Hub: Port Power %d\n",wIndex);
957 break;
958 case (RH_C_PORT_CONNECTION):
959 USB_RH_PRINTF("Root-Hub: C Port Connection Port %d\n",wIndex);
960 break;
961 case (RH_C_PORT_ENABLE):
962 USB_RH_PRINTF("Root-Hub: C Port Enable Port %d\n",wIndex);
963 break;
964 case (RH_C_PORT_SUSPEND):
965 USB_RH_PRINTF("Root-Hub: C Port Suspend Port %d\n",wIndex);
966 break;
967 case (RH_C_PORT_OVER_CURRENT):
968 USB_RH_PRINTF("Root-Hub: C Port Over Current Port %d\n",wIndex);
969 break;
970 case (RH_C_PORT_RESET):
971 USB_RH_PRINTF("Root-Hub: C Port reset Port %d\n",wIndex);
972 break;
973 default:
974 USB_RH_PRINTF("Root-Hub: unknown %x %x\n",wValue,wIndex);
975 break;
976 }
977}
978
979#endif
980
981
982#ifdef USB_UHCI_DEBUG
983
984static int usb_display_td(uhci_td_t *td)
985{
986 unsigned long tmp;
987 int valid;
988
989 printf("TD at %p:\n",td);
990
991 tmp=swap_32(td->link);
992 printf("Link points to 0x%08lX, %s first, %s, %s\n",tmp&0xfffffff0,
993 ((tmp & 0x4)==0x4) ? "Depth" : "Breath",
994 ((tmp & 0x2)==0x2) ? "QH" : "TD",
995 ((tmp & 0x1)==0x1) ? "invalid" : "valid");
996 valid=((tmp & 0x1)==0x0);
997 tmp=swap_32(td->status);
998 printf(" %s %ld Errors %s %s %s \n %s %s %s %s %s %s\n Len 0x%lX\n",
999 (((tmp>>29)&0x1)==0x1) ? "SPD Enable" : "SPD Disable",
1000 ((tmp>>28)&0x3),
1001 (((tmp>>26)&0x1)==0x1) ? "Low Speed" : "Full Speed",
1002 (((tmp>>25)&0x1)==0x1) ? "ISO " : "",
1003 (((tmp>>24)&0x1)==0x1) ? "IOC " : "",
1004 (((tmp>>23)&0x1)==0x1) ? "Active " : "Inactive ",
1005 (((tmp>>22)&0x1)==0x1) ? "Stalled" : "",
1006 (((tmp>>21)&0x1)==0x1) ? "Data Buffer Error" : "",
1007 (((tmp>>20)&0x1)==0x1) ? "Babble" : "",
1008 (((tmp>>19)&0x1)==0x1) ? "NAK" : "",
1009 (((tmp>>18)&0x1)==0x1) ? "Bitstuff Error" : "",
1010 (tmp&0x7ff));
1011 tmp=swap_32(td->info);
1012 printf(" MaxLen 0x%lX\n",((tmp>>21)&0x7FF));
1013 printf(" %s Endpoint 0x%lX Dev Addr 0x%lX PID 0x%lX\n",((tmp>>19)&0x1)==0x1 ? "TOGGLE" : "",
1014 ((tmp>>15)&0xF),((tmp>>8)&0x7F),tmp&0xFF);
1015 tmp=swap_32(td->buffer);
1016 printf(" Buffer 0x%08lX\n",tmp);
1017 printf(" DEV %08lX\n",td->dev_ptr);
1018 return valid;
1019}
1020
1021
1022void usb_show_td(int max)
1023{
1024 int i;
1025 if(max>0) {
1026 for(i=0;i<max;i++) {
1027 usb_display_td(&tmp_td[i]);
1028 }
1029 }
1030 else {
1031 i=0;
1032 do {
1033 printf("tmp_td[%d]\n",i);
1034 }while(usb_display_td(&tmp_td[i++]));
1035 }
1036}
1037
1038
1039#endif
1040#endif
1041
1042
1043