3 * Denis Peter, MPL AG Switzerland
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 * Note: Part of this code has been derived from linux
27 /**********************************************************************
30 * The framelist / Transfer descriptor / Queue Heads are similar like
31 * in the linux usb_uhci.c.
33 * During initialization, the following skeleton is allocated in init_skel:
35 * framespecific | common chain
38 * [ 0 ]-----> TD ---------\
39 * [ 1 ]-----> TD ----------> TD ------> QH -------> QH -------> QH ---> NULL
41 * [1023]-----> TD --------/
44 * 7 TDs for 1 TD for Start of Start of End Chain
45 * INT (2-128ms) 1ms-INT CTRL Chain BULK Chain
48 * Since this is a bootloader, the isochronous transfer descriptor have been removed.
50 * Interrupt Transfers.
51 * --------------------
52 * For Interupt transfers USB_MAX_TEMP_INT_TD Transfer descriptor are available. They
53 * will be inserted after the appropriate (depending the interval setting) skeleton TD.
54 * If an interrupt has been detected the dev->irqhandler is called. The status and number
55 * of transfered bytes is stored in dev->irq_status resp. dev->irq_act_len. If the
56 * dev->irqhandler returns 0, the interrupt TD is removed and disabled. If an 1 is returned,
57 * the interrupt TD will be reactivated.
61 * Control Transfers are issued by filling the tmp_td with the appropriate data and connect
62 * them to the qh_cntrl queue header. Before other control/bulk transfers can be issued,
63 * the programm has to wait for completion. This does not allows asynchronous data transfer.
67 * Bulk Transfers are issued by filling the tmp_td with the appropriate data and connect
68 * them to the qh_bulk queue header. Before other control/bulk transfers can be issued,
69 * the programm has to wait for completion. This does not allows asynchronous data transfer.
77 #ifdef CONFIG_USB_UHCI
82 #define USB_MAX_TEMP_TD 128 /* number of temporary TDs for bulk and control transfers */
83 #define USB_MAX_TEMP_INT_TD 32 /* number of temporary TDs for Interrupt transfers */
89 #define USB_UHCI_PRINTF(fmt,args...) printf (fmt ,##args)
91 #define USB_UHCI_PRINTF(fmt,args...)
95 static int irqvec = -1; /* irq vector, if -1 uhci is stopped / reseted */
96 unsigned int usb_base_addr; /* base address */
98 static uhci_td_t td_int[8]; /* Interrupt Transfer descriptors */
99 static uhci_qh_t qh_cntrl; /* control Queue Head */
100 static uhci_qh_t qh_bulk; /* bulk Queue Head */
101 static uhci_qh_t qh_end; /* end Queue Head */
102 static uhci_td_t td_last; /* last TD (linked with end chain) */
105 static uhci_td_t tmp_td[USB_MAX_TEMP_TD]; /* temporary bulk/control td's */
106 static uhci_td_t tmp_int_td[USB_MAX_TEMP_INT_TD]; /* temporary interrupt td's */
108 static unsigned long framelist[1024] __attribute__ ((aligned (0x1000))); /* frame list */
110 static struct virt_root_hub rh; /* struct for root hub */
112 /**********************************************************************
113 * some forward decleration
115 int uhci_submit_rh_msg(struct usb_device *dev, unsigned long pipe,
116 void *buffer, int transfer_len,struct devrequest *setup);
118 /* fill a td with the approproiate data. Link, status, info and buffer
119 * are used by the USB controller itselfes, dev is used to identify the
122 void usb_fill_td(uhci_td_t* td,unsigned long link,unsigned long status,
123 unsigned long info, unsigned long buffer, unsigned long dev)
125 td->link=swap_32(link);
126 td->status=swap_32(status);
127 td->info=swap_32(info);
128 td->buffer=swap_32(buffer);
132 /* fill a qh with the approproiate data. Head and element are used by the USB controller
133 * itselfes. As soon as a valid dev_ptr is filled, a td chain is connected to the qh.
134 * Please note, that after completion of the td chain, the entry element is removed /
135 * marked invalid by the USB controller.
137 void usb_fill_qh(uhci_qh_t* qh,unsigned long head,unsigned long element)
139 qh->head=swap_32(head);
140 qh->element=swap_32(element);
144 /* get the status of a td->status
146 unsigned long usb_uhci_td_stat(unsigned long status)
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;
159 /* get the status and the transfered len of a td chain.
160 * called from the completion handler
162 int usb_get_td_status(uhci_td_t *td,struct usb_device *dev)
164 unsigned long temp,info;
168 if(dev->devnum==rh.devnum)
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 { /* if not setup and not null data pack */
180 dev->act_len+=(temp & 0x7FF) + 1; /* the transfered len is act_len + 1 */
182 if(stat) { /* status no ok */
186 temp=swap_32((unsigned long)mytd->link);
187 mytd=(uhci_td_t *)(temp & 0xfffffff0);
188 }while((temp & 0x1)==0); /* process all TDs */
194 /*-------------------------------------------------------------------
196 * assembles QHs und TDs for control, bulk and iso
197 *-------------------------------------------------------------------*/
199 /* Submits a control message. That is a Setup, Data and Status transfer.
200 * Routine does not wait for completion.
202 int submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
203 int transfer_len,struct devrequest *setup)
205 unsigned long destination, status;
206 int maxsze = usb_maxpacket(dev, pipe);
207 unsigned long dataptr;
213 USB_UHCI_PRINTF("uhci_submit_control_urb: pipesize for pipe %lx is zero\n", pipe);
216 if(((pipe>>8)&0x7f)==rh.devnum) {
217 /* this is the root hub -> redirect it */
218 return uhci_submit_rh_msg(dev,pipe,buffer,transfer_len,setup);
220 USB_UHCI_PRINTF("uhci_submit_control start len %x, maxsize %x\n",transfer_len,maxsze);
221 /* The "pipe" thing contains the destination in bits 8--18 */
222 destination = (pipe & PIPE_DEVEP_MASK) | USB_PID_SETUP; /* Setup stage */
224 status = (pipe & TD_CTRL_LS) | TD_CTRL_ACTIVE | (3 << 27);
225 /* (urb->transfer_flags & USB_DISABLE_SPD ? 0 : TD_CTRL_SPD); */
226 /* Build the TD for the control request, try forever, 8 bytes of data */
227 usb_fill_td(&tmp_td[i],UHCI_PTR_TERM ,status, destination | (7 << 21),(unsigned long)setup,(unsigned long)dev);
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]);
235 dataptr = (unsigned long)buffer;
238 /* If direction is "send", change the frame from SETUP (0x2D)
239 to OUT (0xE1). Else change it from SETUP to IN (0x69). */
240 destination = (pipe & PIPE_DEVEP_MASK) | ((pipe & USB_DIR_IN)==0 ? USB_PID_OUT : USB_PID_IN);
247 destination ^= 1 << TD_TOKEN_TOGGLE; /* toggle DATA0/1 */
248 usb_fill_td(&tmp_td[i],UHCI_PTR_TERM, status, destination | ((pktsze - 1) << 21),dataptr,(unsigned long)dev); /* Status, pktsze bytes of data */
249 tmp_td[i-1].link=swap_32((unsigned long)&tmp_td[i]);
255 /* Build the final TD for control status */
256 /* It's only IN if the pipe is out AND we aren't expecting data */
258 destination &= ~UHCI_PID;
259 if (((pipe & USB_DIR_IN)==0) || (transfer_len == 0))
260 destination |= USB_PID_IN;
262 destination |= USB_PID_OUT;
263 destination |= 1 << TD_TOKEN_TOGGLE; /* End in Data1 */
265 status &=~TD_CTRL_SPD;
266 /* no limit on errors on final packet , 0 bytes of data */
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]); /* queue status td */
269 /* usb_show_td(i+1);*/
270 USB_UHCI_PRINTF("uhci_submit_control end (%d tmp_tds used)\n",i);
271 /* first mark the control QH element terminated */
272 qh_cntrl.element=0xffffffffL;
274 qh_cntrl.dev_ptr=(unsigned long)dev;
275 /* fill in tmp_td_chain */
276 qh_cntrl.element=swap_32((unsigned long)&tmp_td[0]);
280 /*-------------------------------------------------------------------
281 * Prepare TDs for bulk transfers.
283 int submit_bulk_msg(struct usb_device *dev, unsigned long pipe, void *buffer,int transfer_len)
285 unsigned long destination, status,info;
286 unsigned long dataptr;
287 int maxsze = usb_maxpacket(dev, pipe);
291 if(transfer_len < 0) {
292 printf("Negative transfer length in submit_bulk\n");
297 /* The "pipe" thing contains the destination in bits 8--18. */
298 destination = (pipe & PIPE_DEVEP_MASK) | usb_packetid (pipe);
300 status = (pipe & TD_CTRL_LS) | TD_CTRL_ACTIVE | (3 << 27);
301 /* ((urb->transfer_flags & USB_DISABLE_SPD) ? 0 : TD_CTRL_SPD) | (3 << 27); */
302 /* Build the TDs for the bulk request */
304 dataptr = (unsigned long)buffer;
309 /* pktsze bytes of data */
310 info = destination | (((pktsze - 1)&UHCI_NULL_DATA_SIZE) << 21) |
311 (usb_gettoggle (dev, usb_pipeendpoint (pipe), usb_pipeout (pipe)) << TD_TOKEN_TOGGLE);
314 status |= TD_CTRL_IOC; /* last one generates INT */
316 usb_fill_td(&tmp_td[i],UHCI_PTR_TERM, status, info,dataptr,(unsigned long)dev); /* Status, pktsze bytes of data */
318 tmp_td[i-1].link=swap_32((unsigned long)&tmp_td[i]);
322 usb_dotoggle (dev, usb_pipeendpoint (pipe), usb_pipeout (pipe));
324 /* first mark the bulk QH element terminated */
325 qh_bulk.element=0xffffffffL;
327 qh_bulk.dev_ptr=(unsigned long)dev;
328 /* fill in tmp_td_chain */
329 qh_bulk.element=swap_32((unsigned long)&tmp_td[0]);
334 /* search a free interrupt td
336 uhci_td_t *uhci_alloc_int_td(void)
339 for(i=0;i<USB_MAX_TEMP_INT_TD;i++) {
340 if(tmp_int_td[i].dev_ptr==0) /* no device assigned -> free TD */
341 return &tmp_int_td[i];
347 void uhci_show_temp_int_td(void)
350 for(i=0;i<USB_MAX_TEMP_INT_TD;i++) {
351 if((tmp_int_td[i].dev_ptr&0x01)!=0x1L) /* no device assigned -> free TD */
352 printf("temp_td %d is assigned to dev %lx\n",i,tmp_int_td[i].dev_ptr);
354 printf("all others temp_tds are free\n");
357 /*-------------------------------------------------------------------
358 * submits USB interrupt (ie. polling ;-)
360 int submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer,int transfer_len, int interval)
363 unsigned long status, destination;
364 unsigned long info,tmp;
366 if (interval < 0 || interval >= 256)
372 for (nint = 0, n = 1; nint <= 8; nint++, n += n) /* round interval down to 2^n */
382 USB_UHCI_PRINTF("Rounded interval to %i, chain %i\n", interval, nint);
383 mytd=uhci_alloc_int_td();
385 printf("No free INT TDs found\n");
388 status = (pipe & TD_CTRL_LS) | TD_CTRL_ACTIVE | TD_CTRL_IOC | (3 << 27);
389 /* (urb->transfer_flags & USB_DISABLE_SPD ? 0 : TD_CTRL_SPD) | (3 << 27);
392 destination =(pipe & PIPE_DEVEP_MASK) | usb_packetid (pipe) | (((transfer_len - 1) & 0x7ff) << 21);
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);
398 tmp = swap_32((unsigned long)mytd);
399 td_int[nint].link=tmp;
401 usb_dotoggle (dev, usb_pipeendpoint (pipe), usb_pipeout (pipe));
406 /**********************************************************************
407 * Low Level functions
414 /* Global reset for 100ms */
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 /* Turn off all interrupts */
419 out16r(usb_base_addr + USBINTR,0);
421 out16r( usb_base_addr + USBCMD,0);
429 while(in16r(usb_base_addr + USBCMD) & USBCMD_HCRESET) {
431 printf("USBCMD_HCRESET timed out!\n");
435 /* Turn on all interrupts */
436 out16r(usb_base_addr + USBINTR,USBINTR_TIMEOUT | USBINTR_RESUME | USBINTR_IOC | USBINTR_SP);
437 /* Start at frame 0 */
438 out16r(usb_base_addr + USBFRNUM,0);
439 /* set Framebuffer base address */
440 out32r(usb_base_addr+USBFLBASEADD,(unsigned long)&framelist);
441 /* Run and mark it configured with a 64-byte max packet */
442 out16r(usb_base_addr + USBCMD,USBCMD_RS | USBCMD_CF | USBCMD_MAXP);
445 /* Initialize the skeleton
447 void usb_init_skel(void)
452 for(n=0;n<USB_MAX_TEMP_INT_TD;n++)
453 tmp_int_td[n].dev_ptr=0L; /* no devices connected */
455 usb_fill_td(&td_last,UHCI_PTR_TERM,TD_CTRL_IOC ,0,0,0L);
456 /* usb_fill_td(&td_last,UHCI_PTR_TERM,0,0,0); */
457 /* End Queue Header */
458 usb_fill_qh(&qh_end,UHCI_PTR_TERM,(unsigned long)&td_last);
459 /* Bulk Queue Header */
460 temp=(unsigned long)&qh_end;
461 usb_fill_qh(&qh_bulk,temp | UHCI_PTR_QH,UHCI_PTR_TERM);
462 /* Control Queue Header */
463 temp=(unsigned long)&qh_bulk;
464 usb_fill_qh(&qh_cntrl, temp | UHCI_PTR_QH,UHCI_PTR_TERM);
465 /* 1ms Interrupt td */
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];
470 usb_fill_td(&td_int[n],temp,0,0,0,0L);
471 for (n = 0; n < 1024; n++) {
472 /* link all framelist pointers to one of the interrupts */
475 framelist[n]= swap_32((unsigned long)&td_int[0]);
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]);
483 /* check the common skeleton for completed transfers, and update the status
484 * of the "connected" device. Called from the IRQ routine.
486 void usb_check_skel(void)
488 struct usb_device *dev;
489 /* start with the control qh */
490 if(qh_cntrl.dev_ptr!=0) /* it's a device assigned check if this caused IRQ */
492 dev=(struct usb_device *)qh_cntrl.dev_ptr;
493 usb_get_td_status(&tmp_td[0],dev); /* update status */
494 if(!(dev->status & USB_ST_NOT_PROC)) { /* is not active anymore, disconnect devices */
498 /* now process the bulk */
499 if(qh_bulk.dev_ptr!=0) /* it's a device assigned check if this caused IRQ */
501 dev=(struct usb_device *)qh_bulk.dev_ptr;
502 usb_get_td_status(&tmp_td[0],dev); /* update status */
503 if(!(dev->status & USB_ST_NOT_PROC)) { /* is not active anymore, disconnect devices */
509 /* check the interrupt chain, ubdate the status of the appropriate device,
510 * call the appropriate irqhandler and reactivate the TD if the irqhandler
513 void usb_check_int_chain(void)
516 unsigned long link,status;
517 struct usb_device *dev;
518 uhci_td_t *td,*prevtd;
521 prevtd=&td_int[i]; /* the first previous td is the skeleton td */
522 link=swap_32(td_int[i].link) & 0xfffffff0; /* next in chain */
523 td=(uhci_td_t *)link; /* assign it */
524 /* all interrupt TDs are finally linked to the td_int[0].
525 * so we process all until we find the td_int[0].
526 * if int0 chain points to a QH, we're also done
528 while(((i>0) && (link != (unsigned long)&td_int[0])) ||
529 ((i==0) && !(swap_32(td->link) & UHCI_PTR_QH)))
531 /* check if a device is assigned with this td */
532 status=swap_32(td->status);
533 if((td->dev_ptr!=0L) && !(status & TD_CTRL_ACTIVE)) {
534 /* td is not active and a device is assigned -> call irqhandler */
535 dev=(struct usb_device *)td->dev_ptr;
536 dev->irq_act_len=((status & 0x7FF)==0x7FF) ? 0 : (status & 0x7FF) + 1; /* transfered length */
537 dev->irq_status=usb_uhci_td_stat(status); /* get status */
538 res=dev->irq_handle(dev); /* call irqhandler */
541 status|=TD_CTRL_ACTIVE;
542 td->status=swap_32(status);
543 prevtd=td; /* previous td = this td */
546 prevtd->link=td->link; /* link previous td directly to the nex td -> unlinked */
547 /* remove device pointer */
550 } /* if we call the irq handler */
551 link=swap_32(td->link) & 0xfffffff0; /* next in chain */
552 td=(uhci_td_t *)link; /* assign it */
553 } /* process all td in this int chain */
554 } /* next interrupt chain */
558 /* usb interrupt service routine.
560 void handle_usb_interrupt(void)
562 unsigned short status;
565 * Read the interrupt status, and write it back to clear the
569 status = in16r(usb_base_addr + USBSTS);
571 if (!status) /* shared interrupt, not mine */
574 /* remove host controller halted state */
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));
579 usb_check_int_chain(); /* call interrupt handlers for int tds */
580 usb_check_skel(); /* call completion handler for common transfer routines */
581 out16r(usb_base_addr+USBSTS,status);
587 int usb_lowlevel_init(void)
592 busdevfunc=pci_find_device(USB_UHCI_VEND_ID,USB_UHCI_DEV_ID,0); /* get PCI Device ID */
594 printf("Error USB UHCI (%04X,%04X) not found\n",USB_UHCI_VEND_ID,USB_UHCI_DEV_ID);
597 pci_read_config_byte(busdevfunc,PCI_INTERRUPT_LINE,&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+=CFG_ISA_IO_BASE_ADDRESS;
611 irq_install_handler(irqvec, (interrupt_handler_t *)handle_usb_interrupt, NULL);
617 int usb_lowlevel_stop(void)
621 irq_free_handler(irqvec);
627 /*******************************************************************************************
629 * Since the uhci does not have a real HUB, we simulate one ;-)
634 #define USB_RH_PRINTF(fmt,args...) printf (fmt ,##args)
635 static void usb_display_wValue(unsigned short wValue,unsigned short wIndex);
636 static void usb_display_Req(unsigned short req);
638 #define USB_RH_PRINTF(fmt,args...)
639 static void usb_display_wValue(unsigned short wValue,unsigned short wIndex) {}
640 static void usb_display_Req(unsigned short req) {}
643 static unsigned char root_hub_dev_des[] =
645 0x12, /* __u8 bLength; */
646 0x01, /* __u8 bDescriptorType; Device */
647 0x00, /* __u16 bcdUSB; v1.0 */
649 0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */
650 0x00, /* __u8 bDeviceSubClass; */
651 0x00, /* __u8 bDeviceProtocol; */
652 0x08, /* __u8 bMaxPacketSize0; 8 Bytes */
653 0x00, /* __u16 idVendor; */
655 0x00, /* __u16 idProduct; */
657 0x00, /* __u16 bcdDevice; */
659 0x01, /* __u8 iManufacturer; */
660 0x00, /* __u8 iProduct; */
661 0x00, /* __u8 iSerialNumber; */
662 0x01 /* __u8 bNumConfigurations; */
666 /* Configuration descriptor */
667 static unsigned char root_hub_config_des[] =
669 0x09, /* __u8 bLength; */
670 0x02, /* __u8 bDescriptorType; Configuration */
671 0x19, /* __u16 wTotalLength; */
673 0x01, /* __u8 bNumInterfaces; */
674 0x01, /* __u8 bConfigurationValue; */
675 0x00, /* __u8 iConfiguration; */
676 0x40, /* __u8 bmAttributes;
677 Bit 7: Bus-powered, 6: Self-powered, 5 Remote-wakwup, 4..0: resvd */
678 0x00, /* __u8 MaxPower; */
681 0x09, /* __u8 if_bLength; */
682 0x04, /* __u8 if_bDescriptorType; Interface */
683 0x00, /* __u8 if_bInterfaceNumber; */
684 0x00, /* __u8 if_bAlternateSetting; */
685 0x01, /* __u8 if_bNumEndpoints; */
686 0x09, /* __u8 if_bInterfaceClass; HUB_CLASSCODE */
687 0x00, /* __u8 if_bInterfaceSubClass; */
688 0x00, /* __u8 if_bInterfaceProtocol; */
689 0x00, /* __u8 if_iInterface; */
692 0x07, /* __u8 ep_bLength; */
693 0x05, /* __u8 ep_bDescriptorType; Endpoint */
694 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */
695 0x03, /* __u8 ep_bmAttributes; Interrupt */
696 0x08, /* __u16 ep_wMaxPacketSize; 8 Bytes */
698 0xff /* __u8 ep_bInterval; 255 ms */
702 static unsigned char root_hub_hub_des[] =
704 0x09, /* __u8 bLength; */
705 0x29, /* __u8 bDescriptorType; Hub-descriptor */
706 0x02, /* __u8 bNbrPorts; */
707 0x00, /* __u16 wHubCharacteristics; */
709 0x01, /* __u8 bPwrOn2pwrGood; 2ms */
710 0x00, /* __u8 bHubContrCurrent; 0 mA */
711 0x00, /* __u8 DeviceRemovable; *** 7 Ports max *** */
712 0xff /* __u8 PortPwrCtrlMask; *** 7 ports max *** */
715 static unsigned char root_hub_str_index0[] =
717 0x04, /* __u8 bLength; */
718 0x03, /* __u8 bDescriptorType; String-descriptor */
719 0x09, /* __u8 lang ID */
720 0x04, /* __u8 lang ID */
723 static unsigned char root_hub_str_index1[] =
725 28, /* __u8 bLength; */
726 0x03, /* __u8 bDescriptorType; String-descriptor */
727 'U', /* __u8 Unicode */
728 0, /* __u8 Unicode */
729 'H', /* __u8 Unicode */
730 0, /* __u8 Unicode */
731 'C', /* __u8 Unicode */
732 0, /* __u8 Unicode */
733 'I', /* __u8 Unicode */
734 0, /* __u8 Unicode */
735 ' ', /* __u8 Unicode */
736 0, /* __u8 Unicode */
737 'R', /* __u8 Unicode */
738 0, /* __u8 Unicode */
739 'o', /* __u8 Unicode */
740 0, /* __u8 Unicode */
741 'o', /* __u8 Unicode */
742 0, /* __u8 Unicode */
743 't', /* __u8 Unicode */
744 0, /* __u8 Unicode */
745 ' ', /* __u8 Unicode */
746 0, /* __u8 Unicode */
747 'H', /* __u8 Unicode */
748 0, /* __u8 Unicode */
749 'u', /* __u8 Unicode */
750 0, /* __u8 Unicode */
751 'b', /* __u8 Unicode */
752 0, /* __u8 Unicode */
757 * Root Hub Control Pipe (interrupt Pipes are not supported)
761 int uhci_submit_rh_msg(struct usb_device *dev, unsigned long pipe, void *buffer,int transfer_len,struct devrequest *cmd)
764 int leni = transfer_len;
770 unsigned short cstatus;
772 unsigned short bmRType_bReq;
773 unsigned short wValue;
774 unsigned short wIndex;
775 unsigned short wLength;
777 if ((pipe & PIPE_INTERRUPT) == PIPE_INTERRUPT) {
778 printf("Root-Hub submit IRQ: NOT implemented\n");
782 uhci->rh.interval = urb->interval;
783 rh_init_int_timer (urb);
787 bmRType_bReq = cmd->requesttype | cmd->request << 8;
788 wValue = swap_16(cmd->value);
789 wIndex = swap_16(cmd->index);
790 wLength = swap_16(cmd->length);
791 usb_display_Req(bmRType_bReq);
792 for (i = 0; i < 8; i++)
794 USB_RH_PRINTF("Root-Hub: adr: %2x cmd(%1x): %02x%02x %04x %04x %04x\n",
795 dev->devnum, 8, cmd->requesttype,cmd->request, wValue, wIndex, wLength);
797 switch (bmRType_bReq) {
798 /* Request Destination:
799 without flags: Device,
800 RH_INTERFACE: interface,
801 RH_ENDPOINT: endpoint,
802 RH_CLASS means HUB here,
803 RH_OTHER | RH_CLASS almost ever means HUB_PORT here
807 *(unsigned short *) data = swap_16(1);
810 case RH_GET_STATUS | RH_INTERFACE:
811 *(unsigned short *) data = swap_16(0);
814 case RH_GET_STATUS | RH_ENDPOINT:
815 *(unsigned short *) data = swap_16(0);
818 case RH_GET_STATUS | RH_CLASS:
819 *(unsigned long *) data = swap_32(0);
821 break; /* hub power ** */
822 case RH_GET_STATUS | RH_OTHER | RH_CLASS:
824 status = in16r(usb_base_addr + USBPORTSC1 + 2 * (wIndex - 1));
825 cstatus = ((status & USBPORTSC_CSC) >> (1 - 0)) |
826 ((status & USBPORTSC_PEC) >> (3 - 1)) |
827 (rh.c_p_r[wIndex - 1] << (0 + 4));
828 status = (status & USBPORTSC_CCS) |
829 ((status & USBPORTSC_PE) >> (2 - 1)) |
830 ((status & USBPORTSC_SUSP) >> (12 - 2)) |
831 ((status & USBPORTSC_PR) >> (9 - 4)) |
832 (1 << 8) | /* power on ** */
833 ((status & USBPORTSC_LSDA) << (-8 + 9));
835 *(unsigned short *) data = swap_16(status);
836 *(unsigned short *) (data + 2) = swap_16(cstatus);
839 case RH_CLEAR_FEATURE | RH_ENDPOINT:
841 case (RH_ENDPOINT_STALL):
847 case RH_CLEAR_FEATURE | RH_CLASS:
849 case (RH_C_HUB_OVER_CURRENT):
850 len=0; /* hub power over current ** */
855 case RH_CLEAR_FEATURE | RH_OTHER | RH_CLASS:
856 usb_display_wValue(wValue,wIndex);
858 case (RH_PORT_ENABLE):
859 status = in16r(usb_base_addr+USBPORTSC1+2*(wIndex-1));
860 status = (status & 0xfff5) & ~USBPORTSC_PE;
861 out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
864 case (RH_PORT_SUSPEND):
865 status = in16r(usb_base_addr+USBPORTSC1+2*(wIndex-1));
866 status = (status & 0xfff5) & ~USBPORTSC_SUSP;
867 out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
870 case (RH_PORT_POWER):
871 len=0; /* port power ** */
873 case (RH_C_PORT_CONNECTION):
874 status = in16r(usb_base_addr+USBPORTSC1+2*(wIndex-1));
875 status = (status & 0xfff5) | USBPORTSC_CSC;
876 out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
879 case (RH_C_PORT_ENABLE):
880 status = in16r(usb_base_addr+USBPORTSC1+2*(wIndex-1));
881 status = (status & 0xfff5) | USBPORTSC_PEC;
882 out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
885 case (RH_C_PORT_SUSPEND):
886 /*** WR_RH_PORTSTAT(RH_PS_PSSC); */
889 case (RH_C_PORT_OVER_CURRENT):
892 case (RH_C_PORT_RESET):
893 rh.c_p_r[wIndex - 1] = 0;
898 case RH_SET_FEATURE | RH_OTHER | RH_CLASS:
899 usb_display_wValue(wValue,wIndex);
901 case (RH_PORT_SUSPEND):
902 status = in16r(usb_base_addr+USBPORTSC1+2*(wIndex-1));
903 status = (status & 0xfff5) | USBPORTSC_SUSP;
904 out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
907 case (RH_PORT_RESET):
908 status = in16r(usb_base_addr+USBPORTSC1+2*(wIndex-1));
909 status = (status & 0xfff5) | USBPORTSC_PR;
910 out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
912 status = (status & 0xfff5) & ~USBPORTSC_PR;
913 out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
915 status = (status & 0xfff5) | USBPORTSC_PE;
916 out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
918 status = (status & 0xfff5) | 0xa;
919 out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
922 case (RH_PORT_POWER):
923 len=0; /* port power ** */
925 case (RH_PORT_ENABLE):
926 status = in16r(usb_base_addr+USBPORTSC1+2*(wIndex-1));
927 status = (status & 0xfff5) | USBPORTSC_PE;
928 out16r(usb_base_addr+USBPORTSC1+2*(wIndex-1),status);
938 case RH_GET_DESCRIPTOR:
939 switch ((wValue & 0xff00) >> 8) {
940 case (0x01): /* device descriptor */
941 i=sizeof(root_hub_config_des);
942 status=i > wLength ? wLength : i;
943 len = leni > status ? status : leni;
944 memcpy (data, root_hub_dev_des, len);
946 case (0x02): /* configuration descriptor */
947 i=sizeof(root_hub_config_des);
948 status=i > wLength ? wLength : i;
949 len = leni > status ? status : leni;
950 memcpy (data, root_hub_config_des, len);
952 case (0x03): /*string descriptors */
954 i=sizeof(root_hub_str_index0);
955 status = i > wLength ? wLength : i;
956 len = leni > status ? status : leni;
957 memcpy (data, root_hub_str_index0, len);
961 i=sizeof(root_hub_str_index1);
962 status = i > wLength ? wLength : i;
963 len = leni > status ? status : leni;
964 memcpy (data, root_hub_str_index1, len);
967 stat = USB_ST_STALLED;
971 case RH_GET_DESCRIPTOR | RH_CLASS:
972 root_hub_hub_des[2] = 2;
973 i=sizeof(root_hub_hub_des);
974 status= i > wLength ? wLength : i;
975 len = leni > status ? status : leni;
976 memcpy (data, root_hub_hub_des, len);
978 case RH_GET_CONFIGURATION:
979 *(unsigned char *) data = 0x01;
982 case RH_SET_CONFIGURATION:
986 stat = USB_ST_STALLED;
988 USB_RH_PRINTF("Root-Hub stat %lx port1: %x port2: %x\n\n",stat,
989 in16r(usb_base_addr + USBPORTSC1), in16r(usb_base_addr + USBPORTSC2));
996 /********************************************************************************
997 * Some Debug Routines
1002 static void usb_display_Req(unsigned short req)
1004 USB_RH_PRINTF("- Root-Hub Request: ");
1007 USB_RH_PRINTF("Get Status ");
1009 case RH_GET_STATUS | RH_INTERFACE:
1010 USB_RH_PRINTF("Get Status Interface ");
1012 case RH_GET_STATUS | RH_ENDPOINT:
1013 USB_RH_PRINTF("Get Status Endpoint ");
1015 case RH_GET_STATUS | RH_CLASS:
1016 USB_RH_PRINTF("Get Status Class");
1017 break; /* hub power ** */
1018 case RH_GET_STATUS | RH_OTHER | RH_CLASS:
1019 USB_RH_PRINTF("Get Status Class Others");
1021 case RH_CLEAR_FEATURE | RH_ENDPOINT:
1022 USB_RH_PRINTF("Clear Feature Endpoint ");
1024 case RH_CLEAR_FEATURE | RH_CLASS:
1025 USB_RH_PRINTF("Clear Feature Class ");
1027 case RH_CLEAR_FEATURE | RH_OTHER | RH_CLASS:
1028 USB_RH_PRINTF("Clear Feature Other Class ");
1030 case RH_SET_FEATURE | RH_OTHER | RH_CLASS:
1031 USB_RH_PRINTF("Set Feature Other Class ");
1033 case RH_SET_ADDRESS:
1034 USB_RH_PRINTF("Set Address ");
1036 case RH_GET_DESCRIPTOR:
1037 USB_RH_PRINTF("Get Descriptor ");
1039 case RH_GET_DESCRIPTOR | RH_CLASS:
1040 USB_RH_PRINTF("Get Descriptor Class ");
1042 case RH_GET_CONFIGURATION:
1043 USB_RH_PRINTF("Get Configuration ");
1045 case RH_SET_CONFIGURATION:
1046 USB_RH_PRINTF("Get Configuration ");
1049 USB_RH_PRINTF("****UNKNOWN**** 0x%04X ",req);
1051 USB_RH_PRINTF("\n");
1055 static void usb_display_wValue(unsigned short wValue,unsigned short wIndex)
1058 case (RH_PORT_ENABLE):
1059 USB_RH_PRINTF("Root-Hub: Enable Port %d\n",wIndex);
1061 case (RH_PORT_SUSPEND):
1062 USB_RH_PRINTF("Root-Hub: Suspend Port %d\n",wIndex);
1064 case (RH_PORT_POWER):
1065 USB_RH_PRINTF("Root-Hub: Port Power %d\n",wIndex);
1067 case (RH_C_PORT_CONNECTION):
1068 USB_RH_PRINTF("Root-Hub: C Port Connection Port %d\n",wIndex);
1070 case (RH_C_PORT_ENABLE):
1071 USB_RH_PRINTF("Root-Hub: C Port Enable Port %d\n",wIndex);
1073 case (RH_C_PORT_SUSPEND):
1074 USB_RH_PRINTF("Root-Hub: C Port Suspend Port %d\n",wIndex);
1076 case (RH_C_PORT_OVER_CURRENT):
1077 USB_RH_PRINTF("Root-Hub: C Port Over Current Port %d\n",wIndex);
1079 case (RH_C_PORT_RESET):
1080 USB_RH_PRINTF("Root-Hub: C Port reset Port %d\n",wIndex);
1083 USB_RH_PRINTF("Root-Hub: unknown %x %x\n",wValue,wIndex);
1091 #ifdef USB_UHCI_DEBUG
1093 static int usb_display_td(uhci_td_t *td)
1098 printf("TD at %p:\n",td);
1100 tmp=swap_32(td->link);
1101 printf("Link points to 0x%08lX, %s first, %s, %s\n",tmp&0xfffffff0,
1102 ((tmp & 0x4)==0x4) ? "Depth" : "Breath",
1103 ((tmp & 0x2)==0x2) ? "QH" : "TD",
1104 ((tmp & 0x1)==0x1) ? "invalid" : "valid");
1105 valid=((tmp & 0x1)==0x0);
1106 tmp=swap_32(td->status);
1107 printf(" %s %ld Errors %s %s %s \n %s %s %s %s %s %s\n Len 0x%lX\n",
1108 (((tmp>>29)&0x1)==0x1) ? "SPD Enable" : "SPD Disable",
1110 (((tmp>>26)&0x1)==0x1) ? "Low Speed" : "Full Speed",
1111 (((tmp>>25)&0x1)==0x1) ? "ISO " : "",
1112 (((tmp>>24)&0x1)==0x1) ? "IOC " : "",
1113 (((tmp>>23)&0x1)==0x1) ? "Active " : "Inactive ",
1114 (((tmp>>22)&0x1)==0x1) ? "Stalled" : "",
1115 (((tmp>>21)&0x1)==0x1) ? "Data Buffer Error" : "",
1116 (((tmp>>20)&0x1)==0x1) ? "Babble" : "",
1117 (((tmp>>19)&0x1)==0x1) ? "NAK" : "",
1118 (((tmp>>18)&0x1)==0x1) ? "Bitstuff Error" : "",
1120 tmp=swap_32(td->info);
1121 printf(" MaxLen 0x%lX\n",((tmp>>21)&0x7FF));
1122 printf(" %s Endpoint 0x%lX Dev Addr 0x%lX PID 0x%lX\n",((tmp>>19)&0x1)==0x1 ? "TOGGLE" : "",
1123 ((tmp>>15)&0xF),((tmp>>8)&0x7F),tmp&0xFF);
1124 tmp=swap_32(td->buffer);
1125 printf(" Buffer 0x%08lX\n",tmp);
1126 printf(" DEV %08lX\n",td->dev_ptr);
1131 void usb_show_td(int max)
1135 for(i=0;i<max;i++) {
1136 usb_display_td(&tmp_td[i]);
1142 printf("tmp_td[%d]\n",i);
1143 }while(usb_display_td(&tmp_td[i++]));
1149 #endif /* CONFIG_USB_UHCI */