2 * URB OHCI HCD (Host Controller Driver) for USB on the AT91RM9200 and PCI bus.
4 * Interrupt support is added. Now, it has been tested
5 * on ULI1575 chip and works well with USB keyboard.
8 * Zhang Wei, Freescale Semiconductor, Inc. <wei.zhang@freescale.com>
11 * Gary Jennejohn, DENX Software Engineering <garyj@denx.de>
13 * Note: Much of this code has been derived from Linux 2.4
14 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
15 * (C) Copyright 2000-2002 David Brownell
17 * Modified for the MP2USB by (C) Copyright 2005 Eric Benard
18 * ebenard@eukrea.com - based on s3c24x0's driver
20 * SPDX-License-Identifier: GPL-2.0+
24 * 1 - Read doc/README.generic_usb_ohci
25 * 2 - this driver is intended for use with USB Mass Storage Devices
26 * (BBB) and USB keyboard. There is NO support for Isochronous pipes!
27 * 2 - when running on a PQFP208 AT91RM9200, define CONFIG_AT91C_PQFP_UHPBUG
28 * to activate workaround for bug #41 or this driver will NOT work!
32 #include <asm/byteorder.h>
34 #if defined(CONFIG_PCI_OHCI)
36 #if !defined(CONFIG_PCI_OHCI_DEVNO)
37 #define CONFIG_PCI_OHCI_DEVNO 0
46 #ifdef CONFIG_AT91RM9200
47 #include <asm/arch/hardware.h> /* needed for AT91_USB_HOST_BASE */
50 #if defined(CONFIG_CPU_ARM920T) || \
51 defined(CONFIG_S3C24X0) || \
52 defined(CONFIG_440EP) || \
53 defined(CONFIG_PCI_OHCI) || \
54 defined(CONFIG_MPC5200) || \
55 defined(CONFIG_SYS_OHCI_USE_NPS)
56 # define OHCI_USE_NPS /* force NoPowerSwitching mode */
59 #undef OHCI_VERBOSE_DEBUG /* not always helpful */
62 #undef OHCI_FILL_TRACE
64 /* For initializing controller (mask in an HCFS mode too) */
65 #define OHCI_CONTROL_INIT \
66 (OHCI_CTRL_CBSR & 0x3) | OHCI_CTRL_IE | OHCI_CTRL_PLE
68 #ifdef CONFIG_PCI_OHCI
69 static struct pci_device_id ohci_pci_ids[] = {
70 {0x10b9, 0x5237}, /* ULI1575 PCI OHCI module ids */
71 {0x1033, 0x0035}, /* NEC PCI OHCI module ids */
72 {0x1131, 0x1561}, /* Philips 1561 PCI OHCI module ids */
73 /* Please add supported PCI OHCI controller ids here */
78 #ifdef CONFIG_PCI_EHCI_DEVNO
79 static struct pci_device_id ehci_pci_ids[] = {
80 {0x1131, 0x1562}, /* Philips 1562 PCI EHCI module ids */
81 /* Please add supported PCI EHCI controller ids here */
87 #define dbg(format, arg...) printf("DEBUG: " format "\n", ## arg)
89 #define dbg(format, arg...) do {} while (0)
91 #define err(format, arg...) printf("ERROR: " format "\n", ## arg)
93 #define info(format, arg...) printf("INFO: " format "\n", ## arg)
95 #define info(format, arg...) do {} while (0)
98 #ifdef CONFIG_SYS_OHCI_BE_CONTROLLER
99 # define m16_swap(x) cpu_to_be16(x)
100 # define m32_swap(x) cpu_to_be32(x)
102 # define m16_swap(x) cpu_to_le16(x)
103 # define m32_swap(x) cpu_to_le32(x)
104 #endif /* CONFIG_SYS_OHCI_BE_CONTROLLER */
108 /* this must be aligned to a 256 byte boundary */
109 struct ohci_hcca ghcca[1];
110 /* a pointer to the aligned storage */
111 struct ohci_hcca *phcca;
113 static inline u32 roothub_a(struct ohci *hc)
114 { return ohci_readl(&hc->regs->roothub.a); }
115 static inline u32 roothub_b(struct ohci *hc)
116 { return ohci_readl(&hc->regs->roothub.b); }
117 static inline u32 roothub_status(struct ohci *hc)
118 { return ohci_readl(&hc->regs->roothub.status); }
119 static inline u32 roothub_portstatus(struct ohci *hc, int i)
120 { return ohci_readl(&hc->regs->roothub.portstatus[i]); }
122 /* forward declaration */
123 static int hc_interrupt(ohci_t *ohci);
124 static void td_submit_job(ohci_t *ohci, struct usb_device *dev,
125 unsigned long pipe, void *buffer, int transfer_len,
126 struct devrequest *setup, urb_priv_t *urb,
129 /*-------------------------------------------------------------------------*
130 * URB support functions
131 *-------------------------------------------------------------------------*/
133 /* free HCD-private data associated with this URB */
135 static void urb_free_priv(urb_priv_t *urb)
141 last = urb->length - 1;
143 for (i = 0; i <= last; i++) {
154 /*-------------------------------------------------------------------------*/
157 static int sohci_get_current_frame_number(ohci_t *ohci);
159 /* debug| print the main components of an URB
160 * small: 0) header + data packets 1) just header */
162 static void pkt_print(ohci_t *ohci, urb_priv_t *purb, struct usb_device *dev,
163 unsigned long pipe, void *buffer, int transfer_len,
164 struct devrequest *setup, char *str, int small)
166 dbg("%s URB:[%4x] dev:%2lu,ep:%2lu-%c,type:%s,len:%d/%d stat:%#lx",
168 sohci_get_current_frame_number(ohci),
169 usb_pipedevice(pipe),
170 usb_pipeendpoint(pipe),
171 usb_pipeout(pipe)? 'O': 'I',
172 usb_pipetype(pipe) < 2 ? \
173 (usb_pipeint(pipe)? "INTR": "ISOC"): \
174 (usb_pipecontrol(pipe)? "CTRL": "BULK"),
175 (purb ? purb->actual_length : 0),
176 transfer_len, dev->status);
177 #ifdef OHCI_VERBOSE_DEBUG
181 if (usb_pipecontrol(pipe)) {
182 printf(__FILE__ ": cmd(8):");
183 for (i = 0; i < 8 ; i++)
184 printf(" %02x", ((__u8 *) setup) [i]);
187 if (transfer_len > 0 && buffer) {
188 printf(__FILE__ ": data(%d/%d):",
189 (purb ? purb->actual_length : 0),
191 len = usb_pipeout(pipe)? transfer_len:
192 (purb ? purb->actual_length : 0);
193 for (i = 0; i < 16 && i < len; i++)
194 printf(" %02x", ((__u8 *) buffer) [i]);
195 printf("%s\n", i < len? "...": "");
201 /* just for debugging; prints non-empty branches of the int ed tree
202 * inclusive iso eds */
203 void ep_print_int_eds(ohci_t *ohci, char *str)
207 for (i = 0; i < 32; i++) {
209 ed_p = &(ohci->hcca->int_table [i]);
212 printf(__FILE__ ": %s branch int %2d(%2x):", str, i, i);
213 while (*ed_p != 0 && j--) {
214 ed_t *ed = (ed_t *)m32_swap(ed_p);
215 printf(" ed: %4x;", ed->hwINFO);
216 ed_p = &ed->hwNextED;
222 static void ohci_dump_intr_mask(char *label, __u32 mask)
224 dbg("%s: 0x%08x%s%s%s%s%s%s%s%s%s",
227 (mask & OHCI_INTR_MIE) ? " MIE" : "",
228 (mask & OHCI_INTR_OC) ? " OC" : "",
229 (mask & OHCI_INTR_RHSC) ? " RHSC" : "",
230 (mask & OHCI_INTR_FNO) ? " FNO" : "",
231 (mask & OHCI_INTR_UE) ? " UE" : "",
232 (mask & OHCI_INTR_RD) ? " RD" : "",
233 (mask & OHCI_INTR_SF) ? " SF" : "",
234 (mask & OHCI_INTR_WDH) ? " WDH" : "",
235 (mask & OHCI_INTR_SO) ? " SO" : ""
239 static void maybe_print_eds(char *label, __u32 value)
241 ed_t *edp = (ed_t *)value;
244 dbg("%s %08x", label, value);
245 dbg("%08x", edp->hwINFO);
246 dbg("%08x", edp->hwTailP);
247 dbg("%08x", edp->hwHeadP);
248 dbg("%08x", edp->hwNextED);
252 static char *hcfs2string(int state)
255 case OHCI_USB_RESET: return "reset";
256 case OHCI_USB_RESUME: return "resume";
257 case OHCI_USB_OPER: return "operational";
258 case OHCI_USB_SUSPEND: return "suspend";
263 /* dump control and status registers */
264 static void ohci_dump_status(ohci_t *controller)
266 struct ohci_regs *regs = controller->regs;
269 temp = ohci_readl(®s->revision) & 0xff;
271 dbg("spec %d.%d", (temp >> 4), (temp & 0x0f));
273 temp = ohci_readl(®s->control);
274 dbg("control: 0x%08x%s%s%s HCFS=%s%s%s%s%s CBSR=%d", temp,
275 (temp & OHCI_CTRL_RWE) ? " RWE" : "",
276 (temp & OHCI_CTRL_RWC) ? " RWC" : "",
277 (temp & OHCI_CTRL_IR) ? " IR" : "",
278 hcfs2string(temp & OHCI_CTRL_HCFS),
279 (temp & OHCI_CTRL_BLE) ? " BLE" : "",
280 (temp & OHCI_CTRL_CLE) ? " CLE" : "",
281 (temp & OHCI_CTRL_IE) ? " IE" : "",
282 (temp & OHCI_CTRL_PLE) ? " PLE" : "",
283 temp & OHCI_CTRL_CBSR
286 temp = ohci_readl(®s->cmdstatus);
287 dbg("cmdstatus: 0x%08x SOC=%d%s%s%s%s", temp,
288 (temp & OHCI_SOC) >> 16,
289 (temp & OHCI_OCR) ? " OCR" : "",
290 (temp & OHCI_BLF) ? " BLF" : "",
291 (temp & OHCI_CLF) ? " CLF" : "",
292 (temp & OHCI_HCR) ? " HCR" : ""
295 ohci_dump_intr_mask("intrstatus", ohci_readl(®s->intrstatus));
296 ohci_dump_intr_mask("intrenable", ohci_readl(®s->intrenable));
298 maybe_print_eds("ed_periodcurrent",
299 ohci_readl(®s->ed_periodcurrent));
301 maybe_print_eds("ed_controlhead", ohci_readl(®s->ed_controlhead));
302 maybe_print_eds("ed_controlcurrent",
303 ohci_readl(®s->ed_controlcurrent));
305 maybe_print_eds("ed_bulkhead", ohci_readl(®s->ed_bulkhead));
306 maybe_print_eds("ed_bulkcurrent", ohci_readl(®s->ed_bulkcurrent));
308 maybe_print_eds("donehead", ohci_readl(®s->donehead));
311 static void ohci_dump_roothub(ohci_t *controller, int verbose)
315 temp = roothub_a(controller);
316 ndp = (temp & RH_A_NDP);
317 #ifdef CONFIG_AT91C_PQFP_UHPBUG
318 ndp = (ndp == 2) ? 1:0;
321 dbg("roothub.a: %08x POTPGT=%d%s%s%s%s%s NDP=%d", temp,
322 ((temp & RH_A_POTPGT) >> 24) & 0xff,
323 (temp & RH_A_NOCP) ? " NOCP" : "",
324 (temp & RH_A_OCPM) ? " OCPM" : "",
325 (temp & RH_A_DT) ? " DT" : "",
326 (temp & RH_A_NPS) ? " NPS" : "",
327 (temp & RH_A_PSM) ? " PSM" : "",
330 temp = roothub_b(controller);
331 dbg("roothub.b: %08x PPCM=%04x DR=%04x",
333 (temp & RH_B_PPCM) >> 16,
336 temp = roothub_status(controller);
337 dbg("roothub.status: %08x%s%s%s%s%s%s",
339 (temp & RH_HS_CRWE) ? " CRWE" : "",
340 (temp & RH_HS_OCIC) ? " OCIC" : "",
341 (temp & RH_HS_LPSC) ? " LPSC" : "",
342 (temp & RH_HS_DRWE) ? " DRWE" : "",
343 (temp & RH_HS_OCI) ? " OCI" : "",
344 (temp & RH_HS_LPS) ? " LPS" : ""
348 for (i = 0; i < ndp; i++) {
349 temp = roothub_portstatus(controller, i);
350 dbg("roothub.portstatus [%d] = 0x%08x%s%s%s%s%s%s%s%s%s%s%s%s",
353 (temp & RH_PS_PRSC) ? " PRSC" : "",
354 (temp & RH_PS_OCIC) ? " OCIC" : "",
355 (temp & RH_PS_PSSC) ? " PSSC" : "",
356 (temp & RH_PS_PESC) ? " PESC" : "",
357 (temp & RH_PS_CSC) ? " CSC" : "",
359 (temp & RH_PS_LSDA) ? " LSDA" : "",
360 (temp & RH_PS_PPS) ? " PPS" : "",
361 (temp & RH_PS_PRS) ? " PRS" : "",
362 (temp & RH_PS_POCI) ? " POCI" : "",
363 (temp & RH_PS_PSS) ? " PSS" : "",
365 (temp & RH_PS_PES) ? " PES" : "",
366 (temp & RH_PS_CCS) ? " CCS" : ""
371 static void ohci_dump(ohci_t *controller, int verbose)
373 dbg("OHCI controller usb-%s state", controller->slot_name);
375 /* dumps some of the state we know about */
376 ohci_dump_status(controller);
378 ep_print_int_eds(controller, "hcca");
379 dbg("hcca frame #%04x", controller->hcca->frame_no);
380 ohci_dump_roothub(controller, 1);
384 /*-------------------------------------------------------------------------*
385 * Interface functions (URB)
386 *-------------------------------------------------------------------------*/
388 /* get a transfer request */
390 int sohci_submit_job(ohci_t *ohci, ohci_dev_t *ohci_dev, urb_priv_t *urb,
391 struct devrequest *setup)
394 urb_priv_t *purb_priv = urb;
396 struct usb_device *dev = urb->dev;
397 unsigned long pipe = urb->pipe;
398 void *buffer = urb->transfer_buffer;
399 int transfer_len = urb->transfer_buffer_length;
400 int interval = urb->interval;
402 /* when controller's hung, permit only roothub cleanup attempts
403 * such as powering down ports */
404 if (ohci->disabled) {
405 err("sohci_submit_job: EPIPE");
409 /* we're about to begin a new transaction here so mark the
413 /* every endpoint has a ed, locate and fill it */
414 ed = ep_add_ed(ohci_dev, dev, pipe, interval, 1);
416 err("sohci_submit_job: ENOMEM");
420 /* for the private part of the URB we need the number of TDs (size) */
421 switch (usb_pipetype(pipe)) {
422 case PIPE_BULK: /* one TD for every 4096 Byte */
423 size = (transfer_len - 1) / 4096 + 1;
425 case PIPE_CONTROL:/* 1 TD for setup, 1 for ACK and 1 for every 4096 B */
426 size = (transfer_len == 0)? 2:
427 (transfer_len - 1) / 4096 + 3;
429 case PIPE_INTERRUPT: /* 1 TD */
436 if (size >= (N_URB_TD - 1)) {
437 err("need %d TDs, only have %d", size, N_URB_TD);
440 purb_priv->pipe = pipe;
442 /* fill the private part of the URB */
443 purb_priv->length = size;
445 purb_priv->actual_length = 0;
447 /* allocate the TDs */
448 /* note that td[0] was allocated in ep_add_ed */
449 for (i = 0; i < size; i++) {
450 purb_priv->td[i] = td_alloc(dev);
451 if (!purb_priv->td[i]) {
452 purb_priv->length = i;
453 urb_free_priv(purb_priv);
454 err("sohci_submit_job: ENOMEM");
459 if (ed->state == ED_NEW || (ed->state & ED_DEL)) {
460 urb_free_priv(purb_priv);
461 err("sohci_submit_job: EINVAL");
465 /* link the ed into a chain if is not already */
466 if (ed->state != ED_OPER)
469 /* fill the TDs and link it to the ed */
470 td_submit_job(ohci, dev, pipe, buffer, transfer_len,
471 setup, purb_priv, interval);
476 static inline int sohci_return_job(struct ohci *hc, urb_priv_t *urb)
478 struct ohci_regs *regs = hc->regs;
480 switch (usb_pipetype(urb->pipe)) {
482 /* implicitly requeued */
483 if (urb->dev->irq_handle &&
484 (urb->dev->irq_act_len = urb->actual_length)) {
485 ohci_writel(OHCI_INTR_WDH, ®s->intrenable);
486 ohci_readl(®s->intrenable); /* PCI posting flush */
487 urb->dev->irq_handle(urb->dev);
488 ohci_writel(OHCI_INTR_WDH, ®s->intrdisable);
489 ohci_readl(®s->intrdisable); /* PCI posting flush */
491 urb->actual_length = 0;
495 urb->transfer_buffer,
496 urb->transfer_buffer_length,
510 /*-------------------------------------------------------------------------*/
513 /* tell us the current USB frame number */
514 static int sohci_get_current_frame_number(ohci_t *ohci)
516 return m16_swap(ohci->hcca->frame_no);
520 /*-------------------------------------------------------------------------*
521 * ED handling functions
522 *-------------------------------------------------------------------------*/
524 /* search for the right branch to insert an interrupt ed into the int tree
525 * do some load ballancing;
526 * returns the branch and
527 * sets the interval to interval = 2^integer (ld (interval)) */
529 static int ep_int_ballance(ohci_t *ohci, int interval, int load)
533 /* search for the least loaded interrupt endpoint
534 * branch of all 32 branches
536 for (i = 0; i < 32; i++)
537 if (ohci->ohci_int_load [branch] > ohci->ohci_int_load [i])
540 branch = branch % interval;
541 for (i = branch; i < 32; i += interval)
542 ohci->ohci_int_load [i] += load;
547 /*-------------------------------------------------------------------------*/
549 /* 2^int( ld (inter)) */
551 static int ep_2_n_interval(int inter)
554 for (i = 0; ((inter >> i) > 1) && (i < 5); i++);
558 /*-------------------------------------------------------------------------*/
560 /* the int tree is a binary tree
561 * in order to process it sequentially the indexes of the branches have to
562 * be mapped the mapping reverses the bits of a word of num_bits length */
563 static int ep_rev(int num_bits, int word)
567 for (i = 0; i < num_bits; i++)
568 wout |= (((word >> i) & 1) << (num_bits - i - 1));
572 /*-------------------------------------------------------------------------*
573 * ED handling functions
574 *-------------------------------------------------------------------------*/
576 /* link an ed into one of the HC chains */
578 static int ep_link(ohci_t *ohci, ed_t *edi)
580 volatile ed_t *ed = edi;
589 ed->int_interval = 0;
594 if (ohci->ed_controltail == NULL)
595 ohci_writel(ed, &ohci->regs->ed_controlhead);
597 ohci->ed_controltail->hwNextED =
598 m32_swap((unsigned long)ed);
600 ed->ed_prev = ohci->ed_controltail;
601 if (!ohci->ed_controltail && !ohci->ed_rm_list[0] &&
602 !ohci->ed_rm_list[1] && !ohci->sleeping) {
603 ohci->hc_control |= OHCI_CTRL_CLE;
604 ohci_writel(ohci->hc_control, &ohci->regs->control);
606 ohci->ed_controltail = edi;
611 if (ohci->ed_bulktail == NULL)
612 ohci_writel(ed, &ohci->regs->ed_bulkhead);
614 ohci->ed_bulktail->hwNextED =
615 m32_swap((unsigned long)ed);
617 ed->ed_prev = ohci->ed_bulktail;
618 if (!ohci->ed_bulktail && !ohci->ed_rm_list[0] &&
619 !ohci->ed_rm_list[1] && !ohci->sleeping) {
620 ohci->hc_control |= OHCI_CTRL_BLE;
621 ohci_writel(ohci->hc_control, &ohci->regs->control);
623 ohci->ed_bulktail = edi;
628 interval = ep_2_n_interval(ed->int_period);
629 ed->int_interval = interval;
630 int_branch = ep_int_ballance(ohci, interval, load);
631 ed->int_branch = int_branch;
633 for (i = 0; i < ep_rev(6, interval); i += inter) {
635 for (ed_p = &(ohci->hcca->int_table[\
636 ep_rev(5, i) + int_branch]);
638 (((ed_t *)ed_p)->int_interval >= interval);
639 ed_p = &(((ed_t *)ed_p)->hwNextED))
641 ((ed_t *)ed_p)->int_interval);
642 ed->hwNextED = *ed_p;
643 *ed_p = m32_swap((unsigned long)ed);
650 /*-------------------------------------------------------------------------*/
652 /* scan the periodic table to find and unlink this ED */
653 static void periodic_unlink(struct ohci *ohci, volatile struct ed *ed,
654 unsigned index, unsigned period)
656 for (; index < NUM_INTS; index += period) {
657 __u32 *ed_p = &ohci->hcca->int_table [index];
659 /* ED might have been unlinked through another path */
662 m32_swap((unsigned long)ed_p)) == ed) {
663 *ed_p = ed->hwNextED;
666 ed_p = &(((struct ed *)
667 m32_swap((unsigned long)ed_p))->hwNextED);
672 /* unlink an ed from one of the HC chains.
673 * just the link to the ed is unlinked.
674 * the link from the ed still points to another operational ed or 0
675 * so the HC can eventually finish the processing of the unlinked ed */
677 static int ep_unlink(ohci_t *ohci, ed_t *edi)
679 volatile ed_t *ed = edi;
682 ed->hwINFO |= m32_swap(OHCI_ED_SKIP);
686 if (ed->ed_prev == NULL) {
688 ohci->hc_control &= ~OHCI_CTRL_CLE;
689 ohci_writel(ohci->hc_control,
690 &ohci->regs->control);
692 ohci_writel(m32_swap(*((__u32 *)&ed->hwNextED)),
693 &ohci->regs->ed_controlhead);
695 ed->ed_prev->hwNextED = ed->hwNextED;
697 if (ohci->ed_controltail == ed) {
698 ohci->ed_controltail = ed->ed_prev;
701 *((__u32 *)&ed->hwNextED)))->ed_prev = ed->ed_prev;
706 if (ed->ed_prev == NULL) {
708 ohci->hc_control &= ~OHCI_CTRL_BLE;
709 ohci_writel(ohci->hc_control,
710 &ohci->regs->control);
712 ohci_writel(m32_swap(*((__u32 *)&ed->hwNextED)),
713 &ohci->regs->ed_bulkhead);
715 ed->ed_prev->hwNextED = ed->hwNextED;
717 if (ohci->ed_bulktail == ed) {
718 ohci->ed_bulktail = ed->ed_prev;
721 *((__u32 *)&ed->hwNextED)))->ed_prev = ed->ed_prev;
726 periodic_unlink(ohci, ed, 0, 1);
727 for (i = ed->int_branch; i < 32; i += ed->int_interval)
728 ohci->ohci_int_load[i] -= ed->int_load;
731 ed->state = ED_UNLINK;
735 /*-------------------------------------------------------------------------*/
737 /* add/reinit an endpoint; this should be done once at the
738 * usb_set_configuration command, but the USB stack is a little bit
739 * stateless so we do it at every transaction if the state of the ed
740 * is ED_NEW then a dummy td is added and the state is changed to
741 * ED_UNLINK in all other cases the state is left unchanged the ed
742 * info fields are setted anyway even though most of them should not
745 static ed_t *ep_add_ed(ohci_dev_t *ohci_dev, struct usb_device *usb_dev,
746 unsigned long pipe, int interval, int load)
752 ed = ed_ret = &ohci_dev->ed[(usb_pipeendpoint(pipe) << 1) |
753 (usb_pipecontrol(pipe)? 0: usb_pipeout(pipe))];
755 if ((ed->state & ED_DEL) || (ed->state & ED_URB_DEL)) {
756 err("ep_add_ed: pending delete");
757 /* pending delete request */
761 if (ed->state == ED_NEW) {
762 /* dummy td; end of td list for ed */
763 td = td_alloc(usb_dev);
764 ed->hwTailP = m32_swap((unsigned long)td);
765 ed->hwHeadP = ed->hwTailP;
766 ed->state = ED_UNLINK;
767 ed->type = usb_pipetype(pipe);
771 ed->hwINFO = m32_swap(usb_pipedevice(pipe)
772 | usb_pipeendpoint(pipe) << 7
773 | (usb_pipeisoc(pipe)? 0x8000: 0)
774 | (usb_pipecontrol(pipe)? 0: \
775 (usb_pipeout(pipe)? 0x800: 0x1000))
776 | (usb_dev->speed == USB_SPEED_LOW) << 13
777 | usb_maxpacket(usb_dev, pipe) << 16);
779 if (ed->type == PIPE_INTERRUPT && ed->state == ED_UNLINK) {
780 ed->int_period = interval;
787 /*-------------------------------------------------------------------------*
788 * TD handling functions
789 *-------------------------------------------------------------------------*/
791 /* enqueue next TD for this URB (OHCI spec 5.2.8.2) */
793 static void td_fill(ohci_t *ohci, unsigned int info,
795 struct usb_device *dev, int index, urb_priv_t *urb_priv)
797 volatile td_t *td, *td_pt;
798 #ifdef OHCI_FILL_TRACE
802 if (index > urb_priv->length) {
803 err("index > length");
806 /* use this td as the next dummy */
807 td_pt = urb_priv->td [index];
810 /* fill the old dummy TD */
811 td = urb_priv->td [index] =
812 (td_t *)(m32_swap(urb_priv->ed->hwTailP) & ~0xf);
814 td->ed = urb_priv->ed;
815 td->next_dl_td = NULL;
817 td->data = (__u32)data;
818 #ifdef OHCI_FILL_TRACE
819 if (usb_pipebulk(urb_priv->pipe) && usb_pipeout(urb_priv->pipe)) {
820 for (i = 0; i < len; i++)
821 printf("td->data[%d] %#2x ", i, ((unsigned char *)td->data)[i]);
828 td->hwINFO = m32_swap(info);
829 td->hwCBP = m32_swap((unsigned long)data);
831 td->hwBE = m32_swap((unsigned long)(data + len - 1));
835 td->hwNextTD = m32_swap((unsigned long)td_pt);
837 /* append to queue */
838 td->ed->hwTailP = td->hwNextTD;
841 /*-------------------------------------------------------------------------*/
843 /* prepare all TDs of a transfer */
845 static void td_submit_job(ohci_t *ohci, struct usb_device *dev,
846 unsigned long pipe, void *buffer, int transfer_len,
847 struct devrequest *setup, urb_priv_t *urb,
850 int data_len = transfer_len;
854 unsigned int toggle = 0;
856 /* OHCI handles the DATA-toggles itself, we just use the USB-toggle
857 * bits for reseting */
858 if (usb_gettoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe))) {
859 toggle = TD_T_TOGGLE;
862 usb_settoggle(dev, usb_pipeendpoint(pipe),
863 usb_pipeout(pipe), 1);
871 switch (usb_pipetype(pipe)) {
873 info = usb_pipeout(pipe)?
874 TD_CC | TD_DP_OUT : TD_CC | TD_DP_IN ;
875 while (data_len > 4096) {
876 td_fill(ohci, info | (cnt? TD_T_TOGGLE:toggle),
877 data, 4096, dev, cnt, urb);
878 data += 4096; data_len -= 4096; cnt++;
880 info = usb_pipeout(pipe)?
881 TD_CC | TD_DP_OUT : TD_CC | TD_R | TD_DP_IN ;
882 td_fill(ohci, info | (cnt? TD_T_TOGGLE:toggle), data,
883 data_len, dev, cnt, urb);
886 if (!ohci->sleeping) {
887 /* start bulk list */
888 ohci_writel(OHCI_BLF, &ohci->regs->cmdstatus);
894 info = TD_CC | TD_DP_SETUP | TD_T_DATA0;
895 td_fill(ohci, info, setup, 8, dev, cnt++, urb);
897 /* Optional Data phase */
899 info = usb_pipeout(pipe)?
900 TD_CC | TD_R | TD_DP_OUT | TD_T_DATA1 :
901 TD_CC | TD_R | TD_DP_IN | TD_T_DATA1;
902 /* NOTE: mishandles transfers >8K, some >4K */
903 td_fill(ohci, info, data, data_len, dev, cnt++, urb);
907 info = usb_pipeout(pipe)?
908 TD_CC | TD_DP_IN | TD_T_DATA1:
909 TD_CC | TD_DP_OUT | TD_T_DATA1;
910 td_fill(ohci, info, data, 0, dev, cnt++, urb);
912 if (!ohci->sleeping) {
913 /* start Control list */
914 ohci_writel(OHCI_CLF, &ohci->regs->cmdstatus);
919 info = usb_pipeout(urb->pipe)?
920 TD_CC | TD_DP_OUT | toggle:
921 TD_CC | TD_R | TD_DP_IN | toggle;
922 td_fill(ohci, info, data, data_len, dev, cnt++, urb);
925 if (urb->length != cnt)
926 dbg("TD LENGTH %d != CNT %d", urb->length, cnt);
929 /*-------------------------------------------------------------------------*
930 * Done List handling functions
931 *-------------------------------------------------------------------------*/
933 /* calculate the transfer length and update the urb */
935 static void dl_transfer_length(td_t *td)
938 urb_priv_t *lurb_priv = td->ed->purb;
940 tdBE = m32_swap(td->hwBE);
941 tdCBP = m32_swap(td->hwCBP);
943 if (!(usb_pipecontrol(lurb_priv->pipe) &&
944 ((td->index == 0) || (td->index == lurb_priv->length - 1)))) {
947 lurb_priv->actual_length += tdBE - td->data + 1;
949 lurb_priv->actual_length += tdCBP - td->data;
954 /*-------------------------------------------------------------------------*/
955 static void check_status(td_t *td_list)
957 urb_priv_t *lurb_priv = td_list->ed->purb;
958 int urb_len = lurb_priv->length;
959 __u32 *phwHeadP = &td_list->ed->hwHeadP;
962 cc = TD_CC_GET(m32_swap(td_list->hwINFO));
964 err(" USB-error: %s (%x)", cc_to_string[cc], cc);
966 if (*phwHeadP & m32_swap(0x1)) {
968 ((td_list->index + 1) < urb_len)) {
970 (lurb_priv->td[urb_len - 1]->hwNextTD &\
971 m32_swap(0xfffffff0)) |
972 (*phwHeadP & m32_swap(0x2));
974 lurb_priv->td_cnt += urb_len -
977 *phwHeadP &= m32_swap(0xfffffff2);
979 #ifdef CONFIG_MPC5200
980 td_list->hwNextTD = 0;
985 /* replies to the request have to be on a FIFO basis so
986 * we reverse the reversed done-list */
987 static td_t *dl_reverse_done_list(ohci_t *ohci)
991 td_t *td_list = NULL;
993 td_list_hc = m32_swap(ohci->hcca->done_head) & 0xfffffff0;
994 ohci->hcca->done_head = 0;
997 td_list = (td_t *)td_list_hc;
998 check_status(td_list);
999 td_list->next_dl_td = td_rev;
1001 td_list_hc = m32_swap(td_list->hwNextTD) & 0xfffffff0;
1006 /*-------------------------------------------------------------------------*/
1007 /*-------------------------------------------------------------------------*/
1009 static void finish_urb(ohci_t *ohci, urb_priv_t *urb, int status)
1011 if ((status & (ED_OPER | ED_UNLINK)) && (urb->state != URB_DEL))
1012 urb->finished = sohci_return_job(ohci, urb);
1014 dbg("finish_urb: strange.., ED state %x, \n", status);
1018 * Used to take back a TD from the host controller. This would normally be
1019 * called from within dl_done_list, however it may be called directly if the
1020 * HC no longer sees the TD and it has not appeared on the donelist (after
1021 * two frames). This bug has been observed on ZF Micro systems.
1023 static int takeback_td(ohci_t *ohci, td_t *td_list)
1029 urb_priv_t *lurb_priv;
1030 __u32 tdINFO, edHeadP, edTailP;
1032 tdINFO = m32_swap(td_list->hwINFO);
1035 lurb_priv = ed->purb;
1037 dl_transfer_length(td_list);
1039 lurb_priv->td_cnt++;
1041 /* error code of transfer */
1042 cc = TD_CC_GET(tdINFO);
1044 err("USB-error: %s (%x)", cc_to_string[cc], cc);
1045 stat = cc_to_error[cc];
1048 /* see if this done list makes for all TD's of current URB,
1049 * and mark the URB finished if so */
1050 if (lurb_priv->td_cnt == lurb_priv->length)
1051 finish_urb(ohci, lurb_priv, ed->state);
1053 dbg("dl_done_list: processing TD %x, len %x\n",
1054 lurb_priv->td_cnt, lurb_priv->length);
1056 if (ed->state != ED_NEW && (!usb_pipeint(lurb_priv->pipe))) {
1057 edHeadP = m32_swap(ed->hwHeadP) & 0xfffffff0;
1058 edTailP = m32_swap(ed->hwTailP);
1060 /* unlink eds if they are not busy */
1061 if ((edHeadP == edTailP) && (ed->state == ED_OPER))
1062 ep_unlink(ohci, ed);
1067 static int dl_done_list(ohci_t *ohci)
1070 td_t *td_list = dl_reverse_done_list(ohci);
1073 td_t *td_next = td_list->next_dl_td;
1074 stat = takeback_td(ohci, td_list);
1080 /*-------------------------------------------------------------------------*
1082 *-------------------------------------------------------------------------*/
1084 #include <usbroothubdes.h>
1086 /* Hub class-specific descriptor is constructed dynamically */
1088 /*-------------------------------------------------------------------------*/
1090 #define OK(x) len = (x); break
1092 #define WR_RH_STAT(x) {info("WR:status %#8x", (x)); ohci_writel((x), \
1093 &ohci->regs->roothub.status); }
1094 #define WR_RH_PORTSTAT(x) {info("WR:portstatus[%d] %#8x", wIndex-1, \
1095 (x)); ohci_writel((x), &ohci->regs->roothub.portstatus[wIndex-1]); }
1097 #define WR_RH_STAT(x) ohci_writel((x), &ohci->regs->roothub.status)
1098 #define WR_RH_PORTSTAT(x) ohci_writel((x), \
1099 &ohci->regs->roothub.portstatus[wIndex-1])
1101 #define RD_RH_STAT roothub_status(ohci)
1102 #define RD_RH_PORTSTAT roothub_portstatus(ohci, wIndex-1)
1104 /* request to virtual root hub */
1106 int rh_check_port_status(ohci_t *controller)
1112 temp = roothub_a(controller);
1113 ndp = (temp & RH_A_NDP);
1114 #ifdef CONFIG_AT91C_PQFP_UHPBUG
1115 ndp = (ndp == 2) ? 1:0;
1117 for (i = 0; i < ndp; i++) {
1118 temp = roothub_portstatus(controller, i);
1119 /* check for a device disconnect */
1120 if (((temp & (RH_PS_PESC | RH_PS_CSC)) ==
1121 (RH_PS_PESC | RH_PS_CSC)) &&
1122 ((temp & RH_PS_CCS) == 0)) {
1130 static int ohci_submit_rh_msg(ohci_t *ohci, struct usb_device *dev,
1131 unsigned long pipe, void *buffer, int transfer_len,
1132 struct devrequest *cmd)
1134 void *data = buffer;
1135 int leni = transfer_len;
1142 ALLOC_ALIGN_BUFFER(__u8, databuf, 16, sizeof(u32));
1145 pkt_print(ohci, NULL, dev, pipe, buffer, transfer_len,
1146 cmd, "SUB(rh)", usb_pipein(pipe));
1150 if (usb_pipeint(pipe)) {
1151 info("Root-Hub submit IRQ: NOT implemented");
1155 bmRType_bReq = cmd->requesttype | (cmd->request << 8);
1156 wValue = le16_to_cpu(cmd->value);
1157 wIndex = le16_to_cpu(cmd->index);
1158 wLength = le16_to_cpu(cmd->length);
1160 info("Root-Hub: adr: %2x cmd(%1x): %08x %04x %04x %04x",
1161 dev->devnum, 8, bmRType_bReq, wValue, wIndex, wLength);
1163 switch (bmRType_bReq) {
1164 /* Request Destination:
1165 without flags: Device,
1166 RH_INTERFACE: interface,
1167 RH_ENDPOINT: endpoint,
1168 RH_CLASS means HUB here,
1169 RH_OTHER | RH_CLASS almost ever means HUB_PORT here
1173 *(u16 *)databuf = cpu_to_le16(1);
1175 case RH_GET_STATUS | RH_INTERFACE:
1176 *(u16 *)databuf = cpu_to_le16(0);
1178 case RH_GET_STATUS | RH_ENDPOINT:
1179 *(u16 *)databuf = cpu_to_le16(0);
1181 case RH_GET_STATUS | RH_CLASS:
1182 *(u32 *)databuf = cpu_to_le32(
1183 RD_RH_STAT & ~(RH_HS_CRWE | RH_HS_DRWE));
1185 case RH_GET_STATUS | RH_OTHER | RH_CLASS:
1186 *(u32 *)databuf = cpu_to_le32(RD_RH_PORTSTAT);
1189 case RH_CLEAR_FEATURE | RH_ENDPOINT:
1191 case (RH_ENDPOINT_STALL):
1196 case RH_CLEAR_FEATURE | RH_CLASS:
1198 case RH_C_HUB_LOCAL_POWER:
1200 case (RH_C_HUB_OVER_CURRENT):
1201 WR_RH_STAT(RH_HS_OCIC);
1206 case RH_CLEAR_FEATURE | RH_OTHER | RH_CLASS:
1208 case (RH_PORT_ENABLE): WR_RH_PORTSTAT(RH_PS_CCS); OK(0);
1209 case (RH_PORT_SUSPEND): WR_RH_PORTSTAT(RH_PS_POCI); OK(0);
1210 case (RH_PORT_POWER): WR_RH_PORTSTAT(RH_PS_LSDA); OK(0);
1211 case (RH_C_PORT_CONNECTION): WR_RH_PORTSTAT(RH_PS_CSC); OK(0);
1212 case (RH_C_PORT_ENABLE): WR_RH_PORTSTAT(RH_PS_PESC); OK(0);
1213 case (RH_C_PORT_SUSPEND): WR_RH_PORTSTAT(RH_PS_PSSC); OK(0);
1214 case (RH_C_PORT_OVER_CURRENT):WR_RH_PORTSTAT(RH_PS_OCIC); OK(0);
1215 case (RH_C_PORT_RESET): WR_RH_PORTSTAT(RH_PS_PRSC); OK(0);
1219 case RH_SET_FEATURE | RH_OTHER | RH_CLASS:
1221 case (RH_PORT_SUSPEND):
1222 WR_RH_PORTSTAT(RH_PS_PSS); OK(0);
1223 case (RH_PORT_RESET): /* BUG IN HUP CODE *********/
1224 if (RD_RH_PORTSTAT & RH_PS_CCS)
1225 WR_RH_PORTSTAT(RH_PS_PRS);
1227 case (RH_PORT_POWER):
1228 WR_RH_PORTSTAT(RH_PS_PPS);
1231 case (RH_PORT_ENABLE): /* BUG IN HUP CODE *********/
1232 if (RD_RH_PORTSTAT & RH_PS_CCS)
1233 WR_RH_PORTSTAT(RH_PS_PES);
1238 case RH_SET_ADDRESS:
1239 ohci->rh.devnum = wValue;
1242 case RH_GET_DESCRIPTOR:
1243 switch ((wValue & 0xff00) >> 8) {
1244 case (0x01): /* device descriptor */
1245 len = min_t(unsigned int,
1248 sizeof(root_hub_dev_des),
1250 databuf = root_hub_dev_des; OK(len);
1251 case (0x02): /* configuration descriptor */
1252 len = min_t(unsigned int,
1255 sizeof(root_hub_config_des),
1257 databuf = root_hub_config_des; OK(len);
1258 case (0x03): /* string descriptors */
1259 if (wValue == 0x0300) {
1260 len = min_t(unsigned int,
1263 sizeof(root_hub_str_index0),
1265 databuf = root_hub_str_index0;
1268 if (wValue == 0x0301) {
1269 len = min_t(unsigned int,
1272 sizeof(root_hub_str_index1),
1274 databuf = root_hub_str_index1;
1278 stat = USB_ST_STALLED;
1282 case RH_GET_DESCRIPTOR | RH_CLASS:
1284 __u32 temp = roothub_a(ohci);
1286 databuf[0] = 9; /* min length; */
1288 databuf[2] = temp & RH_A_NDP;
1289 #ifdef CONFIG_AT91C_PQFP_UHPBUG
1290 databuf[2] = (databuf[2] == 2) ? 1 : 0;
1293 if (temp & RH_A_PSM) /* per-port power switching? */
1295 if (temp & RH_A_NOCP) /* no overcurrent reporting? */
1297 else if (temp & RH_A_OCPM)/* per-port overcurrent reporting? */
1301 databuf[5] = (temp & RH_A_POTPGT) >> 24;
1303 temp = roothub_b(ohci);
1304 databuf[7] = temp & RH_B_DR;
1305 if (databuf[2] < 7) {
1309 databuf[8] = (temp & RH_B_DR) >> 8;
1310 databuf[10] = databuf[9] = 0xff;
1313 len = min_t(unsigned int, leni,
1314 min_t(unsigned int, databuf[0], wLength));
1318 case RH_GET_CONFIGURATION:
1322 case RH_SET_CONFIGURATION:
1323 WR_RH_STAT(0x10000);
1327 dbg("unsupported root hub command");
1328 stat = USB_ST_STALLED;
1332 ohci_dump_roothub(ohci, 1);
1337 len = min_t(int, len, leni);
1338 if (data != databuf)
1339 memcpy(data, databuf, len);
1344 pkt_print(ohci, NULL, dev, pipe, buffer,
1345 transfer_len, cmd, "RET(rh)", 0/*usb_pipein(pipe)*/);
1353 /*-------------------------------------------------------------------------*/
1355 /* common code for handling submit messages - used for all but root hub */
1357 static int submit_common_msg(ohci_t *ohci, struct usb_device *dev,
1358 unsigned long pipe, void *buffer, int transfer_len,
1359 struct devrequest *setup, int interval)
1362 int maxsize = usb_maxpacket(dev, pipe);
1366 urb = malloc(sizeof(urb_priv_t));
1367 memset(urb, 0, sizeof(urb_priv_t));
1371 urb->transfer_buffer = buffer;
1372 urb->transfer_buffer_length = transfer_len;
1373 urb->interval = interval;
1376 urb->actual_length = 0;
1377 pkt_print(ohci, urb, dev, pipe, buffer, transfer_len,
1378 setup, "SUB", usb_pipein(pipe));
1383 err("submit_common_message: pipesize for pipe %lx is zero",
1388 if (sohci_submit_job(ohci, &ohci->ohci_dev, urb, setup) < 0) {
1389 err("sohci_submit_job failed");
1395 /* ohci_dump_status(ohci); */
1398 timeout = USB_TIMEOUT_MS(pipe);
1400 /* wait for it to complete */
1402 /* check whether the controller is done */
1403 stat = hc_interrupt(ohci);
1405 stat = USB_ST_CRC_ERR;
1409 /* NOTE: since we are not interrupt driven in U-Boot and always
1410 * handle only one URB at a time, we cannot assume the
1411 * transaction finished on the first successful return from
1412 * hc_interrupt().. unless the flag for current URB is set,
1413 * meaning that all TD's to/from device got actually
1414 * transferred and processed. If the current URB is not
1415 * finished we need to re-iterate this loop so as
1416 * hc_interrupt() gets called again as there needs to be some
1417 * more TD's to process still */
1418 if ((stat >= 0) && (stat != 0xff) && (urb->finished)) {
1419 /* 0xff is returned for an SF-interrupt */
1429 err("CTL:TIMEOUT ");
1430 dbg("submit_common_msg: TO status %x\n", stat);
1432 stat = USB_ST_CRC_ERR;
1438 dev->act_len = urb->actual_length;
1441 pkt_print(ohci, urb, dev, pipe, buffer, transfer_len,
1442 setup, "RET(ctlr)", usb_pipein(pipe));
1447 /* free TDs in urb_priv */
1448 if (!usb_pipeint(pipe))
1453 /* submit routines called from usb.c */
1454 int submit_bulk_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
1457 info("submit_bulk_msg");
1458 return submit_common_msg(&gohci, dev, pipe, buffer, transfer_len,
1462 int submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
1463 int transfer_len, int interval)
1465 info("submit_int_msg");
1466 return submit_common_msg(&gohci, dev, pipe, buffer, transfer_len, NULL,
1470 static int _ohci_submit_control_msg(ohci_t *ohci, struct usb_device *dev,
1471 unsigned long pipe, void *buffer, int transfer_len,
1472 struct devrequest *setup)
1474 int maxsize = usb_maxpacket(dev, pipe);
1476 info("submit_control_msg");
1478 pkt_print(ohci, NULL, dev, pipe, buffer, transfer_len,
1479 setup, "SUB", usb_pipein(pipe));
1484 err("submit_control_message: pipesize for pipe %lx is zero",
1488 if (((pipe >> 8) & 0x7f) == ohci->rh.devnum) {
1490 /* root hub - redirect */
1491 return ohci_submit_rh_msg(ohci, dev, pipe, buffer,
1492 transfer_len, setup);
1495 return submit_common_msg(ohci, dev, pipe, buffer, transfer_len,
1499 /*-------------------------------------------------------------------------*
1501 *-------------------------------------------------------------------------*/
1503 /* reset the HC and BUS */
1505 static int hc_reset(ohci_t *ohci)
1507 #ifdef CONFIG_PCI_EHCI_DEVNO
1511 int smm_timeout = 50; /* 0,5 sec */
1513 dbg("%s\n", __FUNCTION__);
1515 #ifdef CONFIG_PCI_EHCI_DEVNO
1517 * Some multi-function controllers (e.g. ISP1562) allow root hub
1518 * resetting via EHCI registers only.
1520 pdev = pci_find_devices(ehci_pci_ids, CONFIG_PCI_EHCI_DEVNO);
1525 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &base);
1526 base += EHCI_USBCMD_OFF;
1527 ohci_writel(ohci_readl(base) | EHCI_USBCMD_HCRESET, base);
1529 while (ohci_readl(base) & EHCI_USBCMD_HCRESET) {
1530 if (timeout-- <= 0) {
1531 printf("USB RootHub reset timed out!");
1537 printf("No EHCI func at %d index!\n", CONFIG_PCI_EHCI_DEVNO);
1539 if (ohci_readl(&ohci->regs->control) & OHCI_CTRL_IR) {
1540 /* SMM owns the HC, request ownership */
1541 ohci_writel(OHCI_OCR, &ohci->regs->cmdstatus);
1542 info("USB HC TakeOver from SMM");
1543 while (ohci_readl(&ohci->regs->control) & OHCI_CTRL_IR) {
1545 if (--smm_timeout == 0) {
1546 err("USB HC TakeOver failed!");
1552 /* Disable HC interrupts */
1553 ohci_writel(OHCI_INTR_MIE, &ohci->regs->intrdisable);
1555 dbg("USB HC reset_hc usb-%s: ctrl = 0x%X ;\n",
1557 ohci_readl(&ohci->regs->control));
1559 /* Reset USB (needed by some controllers) */
1560 ohci->hc_control = 0;
1561 ohci_writel(ohci->hc_control, &ohci->regs->control);
1563 /* HC Reset requires max 10 us delay */
1564 ohci_writel(OHCI_HCR, &ohci->regs->cmdstatus);
1565 while ((ohci_readl(&ohci->regs->cmdstatus) & OHCI_HCR) != 0) {
1566 if (--timeout == 0) {
1567 err("USB HC reset timed out!");
1575 /*-------------------------------------------------------------------------*/
1577 /* Start an OHCI controller, set the BUS operational
1579 * connect the virtual root hub */
1581 static int hc_start(ohci_t *ohci)
1584 unsigned int fminterval;
1588 /* Tell the controller where the control and bulk lists are
1589 * The lists are empty now. */
1591 ohci_writel(0, &ohci->regs->ed_controlhead);
1592 ohci_writel(0, &ohci->regs->ed_bulkhead);
1594 ohci_writel((__u32)ohci->hcca,
1595 &ohci->regs->hcca); /* reset clears this */
1597 fminterval = 0x2edf;
1598 ohci_writel((fminterval * 9) / 10, &ohci->regs->periodicstart);
1599 fminterval |= ((((fminterval - 210) * 6) / 7) << 16);
1600 ohci_writel(fminterval, &ohci->regs->fminterval);
1601 ohci_writel(0x628, &ohci->regs->lsthresh);
1603 /* start controller operations */
1604 ohci->hc_control = OHCI_CONTROL_INIT | OHCI_USB_OPER;
1606 ohci_writel(ohci->hc_control, &ohci->regs->control);
1608 /* disable all interrupts */
1609 mask = (OHCI_INTR_SO | OHCI_INTR_WDH | OHCI_INTR_SF | OHCI_INTR_RD |
1610 OHCI_INTR_UE | OHCI_INTR_FNO | OHCI_INTR_RHSC |
1611 OHCI_INTR_OC | OHCI_INTR_MIE);
1612 ohci_writel(mask, &ohci->regs->intrdisable);
1613 /* clear all interrupts */
1614 mask &= ~OHCI_INTR_MIE;
1615 ohci_writel(mask, &ohci->regs->intrstatus);
1616 /* Choose the interrupts we care about now - but w/o MIE */
1617 mask = OHCI_INTR_RHSC | OHCI_INTR_UE | OHCI_INTR_WDH | OHCI_INTR_SO;
1618 ohci_writel(mask, &ohci->regs->intrenable);
1621 /* required for AMD-756 and some Mac platforms */
1622 ohci_writel((roothub_a(ohci) | RH_A_NPS) & ~RH_A_PSM,
1623 &ohci->regs->roothub.a);
1624 ohci_writel(RH_HS_LPSC, &ohci->regs->roothub.status);
1625 #endif /* OHCI_USE_NPS */
1627 /* POTPGT delay is bits 24-31, in 2 ms units. */
1628 mdelay((roothub_a(ohci) >> 23) & 0x1fe);
1630 /* connect the virtual root hub */
1631 ohci->rh.devnum = 0;
1636 /*-------------------------------------------------------------------------*/
1638 /* an interrupt happens */
1640 static int hc_interrupt(ohci_t *ohci)
1642 struct ohci_regs *regs = ohci->regs;
1646 if ((ohci->hcca->done_head != 0) &&
1647 !(m32_swap(ohci->hcca->done_head) & 0x01)) {
1648 ints = OHCI_INTR_WDH;
1650 ints = ohci_readl(®s->intrstatus);
1651 if (ints == ~(u32)0) {
1653 err("%s device removed!", ohci->slot_name);
1656 ints &= ohci_readl(®s->intrenable);
1658 dbg("hc_interrupt: returning..\n");
1664 /* dbg("Interrupt: %x frame: %x", ints,
1665 le16_to_cpu(ohci->hcca->frame_no)); */
1667 if (ints & OHCI_INTR_RHSC)
1670 if (ints & OHCI_INTR_UE) {
1672 err("OHCI Unrecoverable Error, controller usb-%s disabled",
1674 /* e.g. due to PCI Master/Target Abort */
1681 /* FIXME: be optimistic, hope that bug won't repeat often. */
1682 /* Make some non-interrupt context restart the controller. */
1683 /* Count and limit the retries though; either hardware or */
1684 /* software errors can go forever... */
1689 if (ints & OHCI_INTR_WDH) {
1691 ohci_writel(OHCI_INTR_WDH, ®s->intrdisable);
1692 (void)ohci_readl(®s->intrdisable); /* flush */
1693 stat = dl_done_list(ohci);
1694 ohci_writel(OHCI_INTR_WDH, ®s->intrenable);
1695 (void)ohci_readl(®s->intrdisable); /* flush */
1698 if (ints & OHCI_INTR_SO) {
1699 dbg("USB Schedule overrun\n");
1700 ohci_writel(OHCI_INTR_SO, ®s->intrenable);
1704 /* FIXME: this assumes SOF (1/ms) interrupts don't get lost... */
1705 if (ints & OHCI_INTR_SF) {
1706 unsigned int frame = m16_swap(ohci->hcca->frame_no) & 1;
1708 ohci_writel(OHCI_INTR_SF, ®s->intrdisable);
1709 if (ohci->ed_rm_list[frame] != NULL)
1710 ohci_writel(OHCI_INTR_SF, ®s->intrenable);
1714 ohci_writel(ints, ®s->intrstatus);
1718 /*-------------------------------------------------------------------------*/
1720 /*-------------------------------------------------------------------------*/
1722 /* De-allocate all resources.. */
1724 static void hc_release_ohci(ohci_t *ohci)
1726 dbg("USB HC release ohci usb-%s", ohci->slot_name);
1728 if (!ohci->disabled)
1732 /*-------------------------------------------------------------------------*/
1735 * low level initalisation routine, called from usb.c
1737 static char ohci_inited = 0;
1739 int usb_lowlevel_init(int index, enum usb_init_type init, void **controller)
1741 #ifdef CONFIG_PCI_OHCI
1745 #ifdef CONFIG_SYS_USB_OHCI_CPU_INIT
1746 /* cpu dependant init */
1751 #ifdef CONFIG_SYS_USB_OHCI_BOARD_INIT
1752 /* board dependant init */
1753 if (board_usb_init(index, USB_INIT_HOST))
1756 memset(&gohci, 0, sizeof(ohci_t));
1758 /* align the storage */
1759 if ((__u32)&ghcca[0] & 0xff) {
1760 err("HCCA not aligned!!");
1764 info("aligned ghcca %p", phcca);
1765 memset(gtd, 0, sizeof(td_t) * (NUM_TD + 1));
1766 if ((__u32)gtd & 0x7) {
1767 err("TDs not aligned!!");
1772 memset(phcca, 0, sizeof(struct ohci_hcca));
1777 #ifdef CONFIG_PCI_OHCI
1778 pdev = pci_find_devices(ohci_pci_ids, CONFIG_PCI_OHCI_DEVNO);
1783 pci_read_config_word(pdev, PCI_VENDOR_ID, &vid);
1784 pci_read_config_word(pdev, PCI_DEVICE_ID, &did);
1785 printf("OHCI pci controller (%04x, %04x) found @(%d:%d:%d)\n",
1786 vid, did, (pdev >> 16) & 0xff,
1787 (pdev >> 11) & 0x1f, (pdev >> 8) & 0x7);
1788 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &base);
1789 printf("OHCI regs address 0x%08x\n", base);
1790 gohci.regs = (struct ohci_regs *)base;
1794 gohci.regs = (struct ohci_regs *)CONFIG_SYS_USB_OHCI_REGS_BASE;
1798 gohci.slot_name = CONFIG_SYS_USB_OHCI_SLOT_NAME;
1800 if (hc_reset (&gohci) < 0) {
1801 hc_release_ohci (&gohci);
1802 err ("can't reset usb-%s", gohci.slot_name);
1803 #ifdef CONFIG_SYS_USB_OHCI_BOARD_INIT
1804 /* board dependant cleanup */
1805 board_usb_cleanup(index, USB_INIT_HOST);
1808 #ifdef CONFIG_SYS_USB_OHCI_CPU_INIT
1809 /* cpu dependant cleanup */
1810 usb_cpu_init_fail();
1815 if (hc_start(&gohci) < 0) {
1816 err("can't start usb-%s", gohci.slot_name);
1817 hc_release_ohci(&gohci);
1818 /* Initialization failed */
1819 #ifdef CONFIG_SYS_USB_OHCI_BOARD_INIT
1820 /* board dependant cleanup */
1824 #ifdef CONFIG_SYS_USB_OHCI_CPU_INIT
1825 /* cpu dependant cleanup */
1832 ohci_dump(&gohci, 1);
1840 int usb_lowlevel_stop(int index)
1842 /* this gets called really early - before the controller has */
1843 /* even been initialized! */
1846 /* TODO release any interrupts, etc. */
1847 /* call hc_release_ohci() here ? */
1850 #ifdef CONFIG_SYS_USB_OHCI_BOARD_INIT
1851 /* board dependant cleanup */
1852 if (usb_board_stop())
1856 #ifdef CONFIG_SYS_USB_OHCI_CPU_INIT
1857 /* cpu dependant cleanup */
1861 /* This driver is no longer initialised. It needs a new low-level
1862 * init (board/cpu) before it can be used again. */
1867 int submit_control_msg(struct usb_device *dev, unsigned long pipe,
1868 void *buffer, int transfer_len, struct devrequest *setup)
1870 return _ohci_submit_control_msg(&gohci, dev, pipe, buffer,
1871 transfer_len, setup);