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 <gj@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 * See file CREDITS for list of people who contributed to this
23 * This program is free software; you can redistribute it and/or
24 * modify it under the terms of the GNU General Public License as
25 * published by the Free Software Foundation; either version 2 of
26 * the License, or (at your option) any later version.
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the Free Software
35 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
41 * 1 - Read doc/README.generic_usb_ohci
42 * 2 - this driver is intended for use with USB Mass Storage Devices
43 * (BBB) and USB keyboard. There is NO support for Isochronous pipes!
44 * 2 - when running on a PQFP208 AT91RM9200, define CONFIG_AT91C_PQFP_UHPBUG
45 * to activate workaround for bug #41 or this driver will NOT work!
50 #ifdef CONFIG_USB_OHCI_NEW
52 #include <asm/byteorder.h>
54 #if defined(CONFIG_PCI_OHCI)
62 #if defined(CONFIG_ARM920T) || \
63 defined(CONFIG_S3C2400) || \
64 defined(CONFIG_S3C2410) || \
65 defined(CONFIG_440EP) || \
66 defined(CONFIG_PCI_OHCI) || \
67 defined(CONFIG_MPC5200)
68 # define OHCI_USE_NPS /* force NoPowerSwitching mode */
71 #undef OHCI_VERBOSE_DEBUG /* not always helpful */
74 #undef OHCI_FILL_TRACE
76 /* For initializing controller (mask in an HCFS mode too) */
77 #define OHCI_CONTROL_INIT \
78 (OHCI_CTRL_CBSR & 0x3) | OHCI_CTRL_IE | OHCI_CTRL_PLE
81 * e.g. PCI controllers need this
83 #ifdef CFG_OHCI_SWAP_REG_ACCESS
84 # define readl(a) __swap_32(*((vu_long *)(a)))
85 # define writel(a, b) (*((vu_long *)(b)) = __swap_32((vu_long)a))
87 # define readl(a) (*((vu_long *)(a)))
88 # define writel(a, b) (*((vu_long *)(b)) = ((vu_long)a))
89 #endif /* CFG_OHCI_SWAP_REG_ACCESS */
91 #define min_t(type,x,y) ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
93 #ifdef CONFIG_PCI_OHCI
94 static struct pci_device_id ohci_pci_ids[] = {
95 {0x10b9, 0x5237}, /* ULI1575 PCI OHCI module ids */
96 {0x1033, 0x0035}, /* NEC PCI OHCI module ids */
97 /* Please add supported PCI OHCI controller ids here */
103 #define dbg(format, arg...) printf("DEBUG: " format "\n", ## arg)
105 #define dbg(format, arg...) do {} while(0)
107 #define err(format, arg...) printf("ERROR: " format "\n", ## arg)
110 #define info(format, arg...) printf("INFO: " format "\n", ## arg)
112 #define info(format, arg...) do {} while(0)
115 #ifdef CFG_OHCI_BE_CONTROLLER
116 # define m16_swap(x) cpu_to_be16(x)
117 # define m32_swap(x) cpu_to_be32(x)
119 # define m16_swap(x) cpu_to_le16(x)
120 # define m32_swap(x) cpu_to_le32(x)
121 #endif /* CFG_OHCI_BE_CONTROLLER */
125 /* this must be aligned to a 256 byte boundary */
126 struct ohci_hcca ghcca[1];
127 /* a pointer to the aligned storage */
128 struct ohci_hcca *phcca;
129 /* this allocates EDs for all possible endpoints */
130 struct ohci_device ohci_dev;
133 /* device which was disconnected */
134 struct usb_device *devgone;
136 /*-------------------------------------------------------------------------*/
138 /* AMD-756 (D2 rev) reports corrupt register contents in some cases.
139 * The erratum (#4) description is incorrect. AMD's workaround waits
140 * till some bits (mostly reserved) are clear; ok for all revs.
142 #define OHCI_QUIRK_AMD756 0xabcd
143 #define read_roothub(hc, register, mask) ({ \
144 u32 temp = readl (&hc->regs->roothub.register); \
145 if (hc->flags & OHCI_QUIRK_AMD756) \
146 while (temp & mask) \
147 temp = readl (&hc->regs->roothub.register); \
150 static u32 roothub_a (struct ohci *hc)
151 { return read_roothub (hc, a, 0xfc0fe000); }
152 static inline u32 roothub_b (struct ohci *hc)
153 { return readl (&hc->regs->roothub.b); }
154 static inline u32 roothub_status (struct ohci *hc)
155 { return readl (&hc->regs->roothub.status); }
156 static u32 roothub_portstatus (struct ohci *hc, int i)
157 { return read_roothub (hc, portstatus [i], 0xffe0fce0); }
159 /* forward declaration */
160 static int hc_interrupt (void);
162 td_submit_job (struct usb_device * dev, unsigned long pipe, void * buffer,
163 int transfer_len, struct devrequest * setup, urb_priv_t * urb, int interval);
165 /*-------------------------------------------------------------------------*
166 * URB support functions
167 *-------------------------------------------------------------------------*/
169 /* free HCD-private data associated with this URB */
171 static void urb_free_priv (urb_priv_t * urb)
177 last = urb->length - 1;
179 for (i = 0; i <= last; i++) {
190 /*-------------------------------------------------------------------------*/
193 static int sohci_get_current_frame_number (struct usb_device * dev);
195 /* debug| print the main components of an URB
196 * small: 0) header + data packets 1) just header */
198 static void pkt_print (urb_priv_t *purb, struct usb_device * dev,
199 unsigned long pipe, void * buffer,
200 int transfer_len, struct devrequest * setup, char * str, int small)
202 dbg("%s URB:[%4x] dev:%2d,ep:%2d-%c,type:%s,len:%d/%d stat:%#lx",
204 sohci_get_current_frame_number (dev),
205 usb_pipedevice (pipe),
206 usb_pipeendpoint (pipe),
207 usb_pipeout (pipe)? 'O': 'I',
208 usb_pipetype (pipe) < 2? (usb_pipeint (pipe)? "INTR": "ISOC"):
209 (usb_pipecontrol (pipe)? "CTRL": "BULK"),
210 (purb ? purb->actual_length : 0),
211 transfer_len, dev->status);
212 #ifdef OHCI_VERBOSE_DEBUG
216 if (usb_pipecontrol (pipe)) {
217 printf (__FILE__ ": cmd(8):");
218 for (i = 0; i < 8 ; i++)
219 printf (" %02x", ((__u8 *) setup) [i]);
222 if (transfer_len > 0 && buffer) {
223 printf (__FILE__ ": data(%d/%d):",
224 (purb ? purb->actual_length : 0),
226 len = usb_pipeout (pipe)?
228 (purb ? purb->actual_length : 0);
229 for (i = 0; i < 16 && i < len; i++)
230 printf (" %02x", ((__u8 *) buffer) [i]);
231 printf ("%s\n", i < len? "...": "");
237 /* just for debugging; prints non-empty branches of the int ed tree inclusive iso eds*/
238 void ep_print_int_eds (ohci_t *ohci, char * str) {
241 for (i= 0; i < 32; i++) {
243 ed_p = &(ohci->hcca->int_table [i]);
246 printf (__FILE__ ": %s branch int %2d(%2x):", str, i, i);
247 while (*ed_p != 0 && j--) {
248 ed_t *ed = (ed_t *)m32_swap(ed_p);
249 printf (" ed: %4x;", ed->hwINFO);
250 ed_p = &ed->hwNextED;
256 static void ohci_dump_intr_mask (char *label, __u32 mask)
258 dbg ("%s: 0x%08x%s%s%s%s%s%s%s%s%s",
261 (mask & OHCI_INTR_MIE) ? " MIE" : "",
262 (mask & OHCI_INTR_OC) ? " OC" : "",
263 (mask & OHCI_INTR_RHSC) ? " RHSC" : "",
264 (mask & OHCI_INTR_FNO) ? " FNO" : "",
265 (mask & OHCI_INTR_UE) ? " UE" : "",
266 (mask & OHCI_INTR_RD) ? " RD" : "",
267 (mask & OHCI_INTR_SF) ? " SF" : "",
268 (mask & OHCI_INTR_WDH) ? " WDH" : "",
269 (mask & OHCI_INTR_SO) ? " SO" : ""
273 static void maybe_print_eds (char *label, __u32 value)
275 ed_t *edp = (ed_t *)value;
278 dbg ("%s %08x", label, value);
279 dbg ("%08x", edp->hwINFO);
280 dbg ("%08x", edp->hwTailP);
281 dbg ("%08x", edp->hwHeadP);
282 dbg ("%08x", edp->hwNextED);
286 static char * hcfs2string (int state)
289 case OHCI_USB_RESET: return "reset";
290 case OHCI_USB_RESUME: return "resume";
291 case OHCI_USB_OPER: return "operational";
292 case OHCI_USB_SUSPEND: return "suspend";
297 /* dump control and status registers */
298 static void ohci_dump_status (ohci_t *controller)
300 struct ohci_regs *regs = controller->regs;
303 temp = readl (®s->revision) & 0xff;
305 dbg ("spec %d.%d", (temp >> 4), (temp & 0x0f));
307 temp = readl (®s->control);
308 dbg ("control: 0x%08x%s%s%s HCFS=%s%s%s%s%s CBSR=%d", temp,
309 (temp & OHCI_CTRL_RWE) ? " RWE" : "",
310 (temp & OHCI_CTRL_RWC) ? " RWC" : "",
311 (temp & OHCI_CTRL_IR) ? " IR" : "",
312 hcfs2string (temp & OHCI_CTRL_HCFS),
313 (temp & OHCI_CTRL_BLE) ? " BLE" : "",
314 (temp & OHCI_CTRL_CLE) ? " CLE" : "",
315 (temp & OHCI_CTRL_IE) ? " IE" : "",
316 (temp & OHCI_CTRL_PLE) ? " PLE" : "",
317 temp & OHCI_CTRL_CBSR
320 temp = readl (®s->cmdstatus);
321 dbg ("cmdstatus: 0x%08x SOC=%d%s%s%s%s", temp,
322 (temp & OHCI_SOC) >> 16,
323 (temp & OHCI_OCR) ? " OCR" : "",
324 (temp & OHCI_BLF) ? " BLF" : "",
325 (temp & OHCI_CLF) ? " CLF" : "",
326 (temp & OHCI_HCR) ? " HCR" : ""
329 ohci_dump_intr_mask ("intrstatus", readl (®s->intrstatus));
330 ohci_dump_intr_mask ("intrenable", readl (®s->intrenable));
332 maybe_print_eds ("ed_periodcurrent", readl (®s->ed_periodcurrent));
334 maybe_print_eds ("ed_controlhead", readl (®s->ed_controlhead));
335 maybe_print_eds ("ed_controlcurrent", readl (®s->ed_controlcurrent));
337 maybe_print_eds ("ed_bulkhead", readl (®s->ed_bulkhead));
338 maybe_print_eds ("ed_bulkcurrent", readl (®s->ed_bulkcurrent));
340 maybe_print_eds ("donehead", readl (®s->donehead));
343 static void ohci_dump_roothub (ohci_t *controller, int verbose)
347 temp = roothub_a (controller);
348 ndp = (temp & RH_A_NDP);
349 #ifdef CONFIG_AT91C_PQFP_UHPBUG
350 ndp = (ndp == 2) ? 1:0;
353 dbg ("roothub.a: %08x POTPGT=%d%s%s%s%s%s NDP=%d", temp,
354 ((temp & RH_A_POTPGT) >> 24) & 0xff,
355 (temp & RH_A_NOCP) ? " NOCP" : "",
356 (temp & RH_A_OCPM) ? " OCPM" : "",
357 (temp & RH_A_DT) ? " DT" : "",
358 (temp & RH_A_NPS) ? " NPS" : "",
359 (temp & RH_A_PSM) ? " PSM" : "",
362 temp = roothub_b (controller);
363 dbg ("roothub.b: %08x PPCM=%04x DR=%04x",
365 (temp & RH_B_PPCM) >> 16,
368 temp = roothub_status (controller);
369 dbg ("roothub.status: %08x%s%s%s%s%s%s",
371 (temp & RH_HS_CRWE) ? " CRWE" : "",
372 (temp & RH_HS_OCIC) ? " OCIC" : "",
373 (temp & RH_HS_LPSC) ? " LPSC" : "",
374 (temp & RH_HS_DRWE) ? " DRWE" : "",
375 (temp & RH_HS_OCI) ? " OCI" : "",
376 (temp & RH_HS_LPS) ? " LPS" : ""
380 for (i = 0; i < ndp; i++) {
381 temp = roothub_portstatus (controller, i);
382 dbg ("roothub.portstatus [%d] = 0x%08x%s%s%s%s%s%s%s%s%s%s%s%s",
385 (temp & RH_PS_PRSC) ? " PRSC" : "",
386 (temp & RH_PS_OCIC) ? " OCIC" : "",
387 (temp & RH_PS_PSSC) ? " PSSC" : "",
388 (temp & RH_PS_PESC) ? " PESC" : "",
389 (temp & RH_PS_CSC) ? " CSC" : "",
391 (temp & RH_PS_LSDA) ? " LSDA" : "",
392 (temp & RH_PS_PPS) ? " PPS" : "",
393 (temp & RH_PS_PRS) ? " PRS" : "",
394 (temp & RH_PS_POCI) ? " POCI" : "",
395 (temp & RH_PS_PSS) ? " PSS" : "",
397 (temp & RH_PS_PES) ? " PES" : "",
398 (temp & RH_PS_CCS) ? " CCS" : ""
403 static void ohci_dump (ohci_t *controller, int verbose)
405 dbg ("OHCI controller usb-%s state", controller->slot_name);
407 /* dumps some of the state we know about */
408 ohci_dump_status (controller);
410 ep_print_int_eds (controller, "hcca");
411 dbg ("hcca frame #%04x", controller->hcca->frame_no);
412 ohci_dump_roothub (controller, 1);
416 /*-------------------------------------------------------------------------*
417 * Interface functions (URB)
418 *-------------------------------------------------------------------------*/
420 /* get a transfer request */
422 int sohci_submit_job(urb_priv_t *urb, struct devrequest *setup)
426 urb_priv_t *purb_priv = urb;
428 struct usb_device *dev = urb->dev;
429 unsigned long pipe = urb->pipe;
430 void *buffer = urb->transfer_buffer;
431 int transfer_len = urb->transfer_buffer_length;
432 int interval = urb->interval;
436 /* when controller's hung, permit only roothub cleanup attempts
437 * such as powering down ports */
438 if (ohci->disabled) {
439 err("sohci_submit_job: EPIPE");
443 /* we're about to begin a new transaction here so mark the URB unfinished */
446 /* every endpoint has a ed, locate and fill it */
447 if (!(ed = ep_add_ed (dev, pipe, interval, 1))) {
448 err("sohci_submit_job: ENOMEM");
452 /* for the private part of the URB we need the number of TDs (size) */
453 switch (usb_pipetype (pipe)) {
454 case PIPE_BULK: /* one TD for every 4096 Byte */
455 size = (transfer_len - 1) / 4096 + 1;
457 case PIPE_CONTROL: /* 1 TD for setup, 1 for ACK and 1 for every 4096 B */
458 size = (transfer_len == 0)? 2:
459 (transfer_len - 1) / 4096 + 3;
461 case PIPE_INTERRUPT: /* 1 TD */
468 if (size >= (N_URB_TD - 1)) {
469 err("need %d TDs, only have %d", size, N_URB_TD);
472 purb_priv->pipe = pipe;
474 /* fill the private part of the URB */
475 purb_priv->length = size;
477 purb_priv->actual_length = 0;
479 /* allocate the TDs */
480 /* note that td[0] was allocated in ep_add_ed */
481 for (i = 0; i < size; i++) {
482 purb_priv->td[i] = td_alloc (dev);
483 if (!purb_priv->td[i]) {
484 purb_priv->length = i;
485 urb_free_priv (purb_priv);
486 err("sohci_submit_job: ENOMEM");
491 if (ed->state == ED_NEW || (ed->state & ED_DEL)) {
492 urb_free_priv (purb_priv);
493 err("sohci_submit_job: EINVAL");
497 /* link the ed into a chain if is not already */
498 if (ed->state != ED_OPER)
501 /* fill the TDs and link it to the ed */
502 td_submit_job(dev, pipe, buffer, transfer_len, setup, purb_priv, interval);
507 static inline int sohci_return_job(struct ohci *hc, urb_priv_t *urb)
509 struct ohci_regs *regs = hc->regs;
511 switch (usb_pipetype (urb->pipe)) {
513 /* implicitly requeued */
514 if (urb->dev->irq_handle &&
515 (urb->dev->irq_act_len = urb->actual_length)) {
516 writel (OHCI_INTR_WDH, ®s->intrenable);
517 readl (®s->intrenable); /* PCI posting flush */
518 urb->dev->irq_handle(urb->dev);
519 writel (OHCI_INTR_WDH, ®s->intrdisable);
520 readl (®s->intrdisable); /* PCI posting flush */
522 urb->actual_length = 0;
526 urb->transfer_buffer,
527 urb->transfer_buffer_length,
541 /*-------------------------------------------------------------------------*/
544 /* tell us the current USB frame number */
546 static int sohci_get_current_frame_number (struct usb_device *usb_dev)
548 ohci_t *ohci = &gohci;
550 return m16_swap (ohci->hcca->frame_no);
554 /*-------------------------------------------------------------------------*
555 * ED handling functions
556 *-------------------------------------------------------------------------*/
558 /* search for the right branch to insert an interrupt ed into the int tree
559 * do some load ballancing;
560 * returns the branch and
561 * sets the interval to interval = 2^integer (ld (interval)) */
563 static int ep_int_ballance (ohci_t * ohci, int interval, int load)
567 /* search for the least loaded interrupt endpoint
568 * branch of all 32 branches
570 for (i = 0; i < 32; i++)
571 if (ohci->ohci_int_load [branch] > ohci->ohci_int_load [i])
574 branch = branch % interval;
575 for (i = branch; i < 32; i += interval)
576 ohci->ohci_int_load [i] += load;
581 /*-------------------------------------------------------------------------*/
583 /* 2^int( ld (inter)) */
585 static int ep_2_n_interval (int inter)
588 for (i = 0; ((inter >> i) > 1 ) && (i < 5); i++);
592 /*-------------------------------------------------------------------------*/
594 /* the int tree is a binary tree
595 * in order to process it sequentially the indexes of the branches have to be mapped
596 * the mapping reverses the bits of a word of num_bits length */
598 static int ep_rev (int num_bits, int word)
602 for (i = 0; i < num_bits; i++)
603 wout |= (((word >> i) & 1) << (num_bits - i - 1));
607 /*-------------------------------------------------------------------------*
608 * ED handling functions
609 *-------------------------------------------------------------------------*/
611 /* link an ed into one of the HC chains */
613 static int ep_link (ohci_t *ohci, ed_t *edi)
615 volatile ed_t *ed = edi;
624 ed->int_interval = 0;
629 if (ohci->ed_controltail == NULL) {
630 writel (ed, &ohci->regs->ed_controlhead);
632 ohci->ed_controltail->hwNextED = m32_swap ((unsigned long)ed);
634 ed->ed_prev = ohci->ed_controltail;
635 if (!ohci->ed_controltail && !ohci->ed_rm_list[0] &&
636 !ohci->ed_rm_list[1] && !ohci->sleeping) {
637 ohci->hc_control |= OHCI_CTRL_CLE;
638 writel (ohci->hc_control, &ohci->regs->control);
640 ohci->ed_controltail = edi;
645 if (ohci->ed_bulktail == NULL) {
646 writel (ed, &ohci->regs->ed_bulkhead);
648 ohci->ed_bulktail->hwNextED = m32_swap ((unsigned long)ed);
650 ed->ed_prev = ohci->ed_bulktail;
651 if (!ohci->ed_bulktail && !ohci->ed_rm_list[0] &&
652 !ohci->ed_rm_list[1] && !ohci->sleeping) {
653 ohci->hc_control |= OHCI_CTRL_BLE;
654 writel (ohci->hc_control, &ohci->regs->control);
656 ohci->ed_bulktail = edi;
661 interval = ep_2_n_interval (ed->int_period);
662 ed->int_interval = interval;
663 int_branch = ep_int_ballance (ohci, interval, load);
664 ed->int_branch = int_branch;
666 for (i = 0; i < ep_rev (6, interval); i += inter) {
668 for (ed_p = &(ohci->hcca->int_table[ep_rev (5, i) + int_branch]);
669 (*ed_p != 0) && (((ed_t *)ed_p)->int_interval >= interval);
670 ed_p = &(((ed_t *)ed_p)->hwNextED))
671 inter = ep_rev (6, ((ed_t *)ed_p)->int_interval);
672 ed->hwNextED = *ed_p;
673 *ed_p = m32_swap((unsigned long)ed);
680 /*-------------------------------------------------------------------------*/
682 /* scan the periodic table to find and unlink this ED */
683 static void periodic_unlink ( struct ohci *ohci, volatile struct ed *ed,
684 unsigned index, unsigned period)
686 for (; index < NUM_INTS; index += period) {
687 __u32 *ed_p = &ohci->hcca->int_table [index];
689 /* ED might have been unlinked through another path */
691 if (((struct ed *)m32_swap ((unsigned long)ed_p)) == ed) {
692 *ed_p = ed->hwNextED;
695 ed_p = & (((struct ed *)m32_swap ((unsigned long)ed_p))->hwNextED);
700 /* unlink an ed from one of the HC chains.
701 * just the link to the ed is unlinked.
702 * the link from the ed still points to another operational ed or 0
703 * so the HC can eventually finish the processing of the unlinked ed */
705 static int ep_unlink (ohci_t *ohci, ed_t *edi)
707 volatile ed_t *ed = edi;
710 ed->hwINFO |= m32_swap (OHCI_ED_SKIP);
714 if (ed->ed_prev == NULL) {
716 ohci->hc_control &= ~OHCI_CTRL_CLE;
717 writel (ohci->hc_control, &ohci->regs->control);
719 writel (m32_swap (*((__u32 *)&ed->hwNextED)), &ohci->regs->ed_controlhead);
721 ed->ed_prev->hwNextED = ed->hwNextED;
723 if (ohci->ed_controltail == ed) {
724 ohci->ed_controltail = ed->ed_prev;
726 ((ed_t *)m32_swap (*((__u32 *)&ed->hwNextED)))->ed_prev = ed->ed_prev;
731 if (ed->ed_prev == NULL) {
733 ohci->hc_control &= ~OHCI_CTRL_BLE;
734 writel (ohci->hc_control, &ohci->regs->control);
736 writel (m32_swap (*((__u32 *)&ed->hwNextED)), &ohci->regs->ed_bulkhead);
738 ed->ed_prev->hwNextED = ed->hwNextED;
740 if (ohci->ed_bulktail == ed) {
741 ohci->ed_bulktail = ed->ed_prev;
743 ((ed_t *)m32_swap (*((__u32 *)&ed->hwNextED)))->ed_prev = ed->ed_prev;
748 periodic_unlink (ohci, ed, 0, 1);
749 for (i = ed->int_branch; i < 32; i += ed->int_interval)
750 ohci->ohci_int_load[i] -= ed->int_load;
753 ed->state = ED_UNLINK;
757 /*-------------------------------------------------------------------------*/
759 /* add/reinit an endpoint; this should be done once at the
760 * usb_set_configuration command, but the USB stack is a little bit
761 * stateless so we do it at every transaction if the state of the ed
762 * is ED_NEW then a dummy td is added and the state is changed to
763 * ED_UNLINK in all other cases the state is left unchanged the ed
764 * info fields are setted anyway even though most of them should not
767 static ed_t * ep_add_ed (struct usb_device *usb_dev, unsigned long pipe,
768 int interval, int load)
774 ed = ed_ret = &ohci_dev.ed[(usb_pipeendpoint (pipe) << 1) |
775 (usb_pipecontrol (pipe)? 0: usb_pipeout (pipe))];
777 if ((ed->state & ED_DEL) || (ed->state & ED_URB_DEL)) {
778 err("ep_add_ed: pending delete");
779 /* pending delete request */
783 if (ed->state == ED_NEW) {
784 ed->hwINFO = m32_swap (OHCI_ED_SKIP); /* skip ed */
785 /* dummy td; end of td list for ed */
786 td = td_alloc (usb_dev);
787 ed->hwTailP = m32_swap ((unsigned long)td);
788 ed->hwHeadP = ed->hwTailP;
789 ed->state = ED_UNLINK;
790 ed->type = usb_pipetype (pipe);
794 ed->hwINFO = m32_swap (usb_pipedevice (pipe)
795 | usb_pipeendpoint (pipe) << 7
796 | (usb_pipeisoc (pipe)? 0x8000: 0)
797 | (usb_pipecontrol (pipe)? 0: (usb_pipeout (pipe)? 0x800: 0x1000))
798 | usb_pipeslow (pipe) << 13
799 | usb_maxpacket (usb_dev, pipe) << 16);
801 if (ed->type == PIPE_INTERRUPT && ed->state == ED_UNLINK) {
802 ed->int_period = interval;
809 /*-------------------------------------------------------------------------*
810 * TD handling functions
811 *-------------------------------------------------------------------------*/
813 /* enqueue next TD for this URB (OHCI spec 5.2.8.2) */
815 static void td_fill (ohci_t *ohci, unsigned int info,
817 struct usb_device *dev, int index, urb_priv_t *urb_priv)
819 volatile td_t *td, *td_pt;
820 #ifdef OHCI_FILL_TRACE
824 if (index > urb_priv->length) {
825 err("index > length");
828 /* use this td as the next dummy */
829 td_pt = urb_priv->td [index];
832 /* fill the old dummy TD */
833 td = urb_priv->td [index] = (td_t *)(m32_swap (urb_priv->ed->hwTailP) & ~0xf);
835 td->ed = urb_priv->ed;
836 td->next_dl_td = NULL;
838 td->data = (__u32)data;
839 #ifdef OHCI_FILL_TRACE
840 if ((usb_pipetype(urb_priv->pipe) == PIPE_BULK) && usb_pipeout(urb_priv->pipe)) {
841 for (i = 0; i < len; i++)
842 printf("td->data[%d] %#2x ",i, ((unsigned char *)td->data)[i]);
849 td->hwINFO = m32_swap (info);
850 td->hwCBP = m32_swap ((unsigned long)data);
852 td->hwBE = m32_swap ((unsigned long)(data + len - 1));
855 td->hwNextTD = m32_swap ((unsigned long)td_pt);
857 /* append to queue */
858 td->ed->hwTailP = td->hwNextTD;
861 /*-------------------------------------------------------------------------*/
863 /* prepare all TDs of a transfer */
865 static void td_submit_job (struct usb_device *dev, unsigned long pipe, void *buffer,
866 int transfer_len, struct devrequest *setup, urb_priv_t *urb, int interval)
868 ohci_t *ohci = &gohci;
869 int data_len = transfer_len;
873 unsigned int toggle = 0;
875 /* OHCI handles the DATA-toggles itself, we just use the USB-toggle bits for reseting */
876 if(usb_gettoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe))) {
877 toggle = TD_T_TOGGLE;
880 usb_settoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe), 1);
888 switch (usb_pipetype (pipe)) {
890 info = usb_pipeout (pipe)?
891 TD_CC | TD_DP_OUT : TD_CC | TD_DP_IN ;
892 while(data_len > 4096) {
893 td_fill (ohci, info | (cnt? TD_T_TOGGLE:toggle), data, 4096, dev, cnt, urb);
894 data += 4096; data_len -= 4096; cnt++;
896 info = usb_pipeout (pipe)?
897 TD_CC | TD_DP_OUT : TD_CC | TD_R | TD_DP_IN ;
898 td_fill (ohci, info | (cnt? TD_T_TOGGLE:toggle), data, data_len, dev, cnt, urb);
902 writel (OHCI_BLF, &ohci->regs->cmdstatus); /* start bulk list */
906 info = TD_CC | TD_DP_SETUP | TD_T_DATA0;
907 td_fill (ohci, info, setup, 8, dev, cnt++, urb);
909 info = usb_pipeout (pipe)?
910 TD_CC | TD_R | TD_DP_OUT | TD_T_DATA1 : TD_CC | TD_R | TD_DP_IN | TD_T_DATA1;
911 /* NOTE: mishandles transfers >8K, some >4K */
912 td_fill (ohci, info, data, data_len, dev, cnt++, urb);
914 info = usb_pipeout (pipe)?
915 TD_CC | TD_DP_IN | TD_T_DATA1: TD_CC | TD_DP_OUT | TD_T_DATA1;
916 td_fill (ohci, info, data, 0, dev, cnt++, urb);
918 writel (OHCI_CLF, &ohci->regs->cmdstatus); /* start Control list */
922 info = usb_pipeout (urb->pipe)?
923 TD_CC | TD_DP_OUT | toggle:
924 TD_CC | TD_R | TD_DP_IN | toggle;
925 td_fill (ohci, info, data, data_len, dev, cnt++, urb);
928 if (urb->length != cnt)
929 dbg("TD LENGTH %d != CNT %d", urb->length, cnt);
932 /*-------------------------------------------------------------------------*
933 * Done List handling functions
934 *-------------------------------------------------------------------------*/
936 /* calculate the transfer length and update the urb */
938 static void dl_transfer_length(td_t * td)
940 __u32 tdINFO, tdBE, tdCBP;
941 urb_priv_t *lurb_priv = td->ed->purb;
943 tdINFO = m32_swap (td->hwINFO);
944 tdBE = m32_swap (td->hwBE);
945 tdCBP = m32_swap (td->hwCBP);
947 if (!(usb_pipetype (lurb_priv->pipe) == PIPE_CONTROL &&
948 ((td->index == 0) || (td->index == lurb_priv->length - 1)))) {
951 lurb_priv->actual_length += tdBE - td->data + 1;
953 lurb_priv->actual_length += tdCBP - td->data;
958 /*-------------------------------------------------------------------------*/
960 /* replies to the request have to be on a FIFO basis so
961 * we reverse the reversed done-list */
963 static td_t * dl_reverse_done_list (ohci_t *ohci)
967 td_t *td_list = NULL;
968 urb_priv_t *lurb_priv = NULL;
970 td_list_hc = m32_swap (ohci->hcca->done_head) & 0xfffffff0;
971 ohci->hcca->done_head = 0;
974 td_list = (td_t *)td_list_hc;
976 if (TD_CC_GET (m32_swap (td_list->hwINFO))) {
977 lurb_priv = td_list->ed->purb;
978 dbg(" USB-error/status: %x : %p",
979 TD_CC_GET (m32_swap (td_list->hwINFO)), td_list);
980 if (td_list->ed->hwHeadP & m32_swap (0x1)) {
981 if (lurb_priv && ((td_list->index + 1) < lurb_priv->length)) {
982 td_list->ed->hwHeadP =
983 (lurb_priv->td[lurb_priv->length - 1]->hwNextTD & m32_swap (0xfffffff0)) |
984 (td_list->ed->hwHeadP & m32_swap (0x2));
985 lurb_priv->td_cnt += lurb_priv->length - td_list->index - 1;
987 td_list->ed->hwHeadP &= m32_swap (0xfffffff2);
989 #ifdef CONFIG_MPC5200
990 td_list->hwNextTD = 0;
994 td_list->next_dl_td = td_rev;
996 td_list_hc = m32_swap (td_list->hwNextTD) & 0xfffffff0;
1001 /*-------------------------------------------------------------------------*/
1004 static int dl_done_list (ohci_t *ohci, td_t *td_list)
1006 td_t *td_list_next = NULL;
1011 urb_priv_t *lurb_priv;
1012 __u32 tdINFO, edHeadP, edTailP;
1015 td_list_next = td_list->next_dl_td;
1017 tdINFO = m32_swap (td_list->hwINFO);
1020 lurb_priv = ed->purb;
1022 dl_transfer_length(td_list);
1024 /* error code of transfer */
1025 cc = TD_CC_GET (tdINFO);
1027 dbg("ConditionCode %#x", cc);
1028 stat = cc_to_error[cc];
1031 /* see if this done list makes for all TD's of current URB,
1032 * and mark the URB finished if so */
1033 if (++(lurb_priv->td_cnt) == lurb_priv->length) {
1035 if ((ed->state & (ED_OPER | ED_UNLINK)) &&
1036 (lurb_priv->state != URB_DEL))
1038 if ((ed->state & (ED_OPER | ED_UNLINK)))
1040 lurb_priv->finished = sohci_return_job(ohci,
1043 dbg("dl_done_list: strange.., ED state %x, ed->state\n");
1045 dbg("dl_done_list: processing TD %x, len %x\n", lurb_priv->td_cnt,
1047 if (ed->state != ED_NEW &&
1048 (usb_pipetype (lurb_priv->pipe) != PIPE_INTERRUPT)) {
1049 edHeadP = m32_swap (ed->hwHeadP) & 0xfffffff0;
1050 edTailP = m32_swap (ed->hwTailP);
1052 /* unlink eds if they are not busy */
1053 if ((edHeadP == edTailP) && (ed->state == ED_OPER))
1054 ep_unlink (ohci, ed);
1057 td_list = td_list_next;
1062 /*-------------------------------------------------------------------------*
1064 *-------------------------------------------------------------------------*/
1066 /* Device descriptor */
1067 static __u8 root_hub_dev_des[] =
1069 0x12, /* __u8 bLength; */
1070 0x01, /* __u8 bDescriptorType; Device */
1071 0x10, /* __u16 bcdUSB; v1.1 */
1073 0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */
1074 0x00, /* __u8 bDeviceSubClass; */
1075 0x00, /* __u8 bDeviceProtocol; */
1076 0x08, /* __u8 bMaxPacketSize0; 8 Bytes */
1077 0x00, /* __u16 idVendor; */
1079 0x00, /* __u16 idProduct; */
1081 0x00, /* __u16 bcdDevice; */
1083 0x00, /* __u8 iManufacturer; */
1084 0x01, /* __u8 iProduct; */
1085 0x00, /* __u8 iSerialNumber; */
1086 0x01 /* __u8 bNumConfigurations; */
1089 /* Configuration descriptor */
1090 static __u8 root_hub_config_des[] =
1092 0x09, /* __u8 bLength; */
1093 0x02, /* __u8 bDescriptorType; Configuration */
1094 0x19, /* __u16 wTotalLength; */
1096 0x01, /* __u8 bNumInterfaces; */
1097 0x01, /* __u8 bConfigurationValue; */
1098 0x00, /* __u8 iConfiguration; */
1099 0x40, /* __u8 bmAttributes;
1100 Bit 7: Bus-powered, 6: Self-powered, 5 Remote-wakwup, 4..0: resvd */
1101 0x00, /* __u8 MaxPower; */
1104 0x09, /* __u8 if_bLength; */
1105 0x04, /* __u8 if_bDescriptorType; Interface */
1106 0x00, /* __u8 if_bInterfaceNumber; */
1107 0x00, /* __u8 if_bAlternateSetting; */
1108 0x01, /* __u8 if_bNumEndpoints; */
1109 0x09, /* __u8 if_bInterfaceClass; HUB_CLASSCODE */
1110 0x00, /* __u8 if_bInterfaceSubClass; */
1111 0x00, /* __u8 if_bInterfaceProtocol; */
1112 0x00, /* __u8 if_iInterface; */
1115 0x07, /* __u8 ep_bLength; */
1116 0x05, /* __u8 ep_bDescriptorType; Endpoint */
1117 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */
1118 0x03, /* __u8 ep_bmAttributes; Interrupt */
1119 0x02, /* __u16 ep_wMaxPacketSize; ((MAX_ROOT_PORTS + 1) / 8 */
1121 0xff /* __u8 ep_bInterval; 255 ms */
1124 static unsigned char root_hub_str_index0[] =
1126 0x04, /* __u8 bLength; */
1127 0x03, /* __u8 bDescriptorType; String-descriptor */
1128 0x09, /* __u8 lang ID */
1129 0x04, /* __u8 lang ID */
1132 static unsigned char root_hub_str_index1[] =
1134 28, /* __u8 bLength; */
1135 0x03, /* __u8 bDescriptorType; String-descriptor */
1136 'O', /* __u8 Unicode */
1137 0, /* __u8 Unicode */
1138 'H', /* __u8 Unicode */
1139 0, /* __u8 Unicode */
1140 'C', /* __u8 Unicode */
1141 0, /* __u8 Unicode */
1142 'I', /* __u8 Unicode */
1143 0, /* __u8 Unicode */
1144 ' ', /* __u8 Unicode */
1145 0, /* __u8 Unicode */
1146 'R', /* __u8 Unicode */
1147 0, /* __u8 Unicode */
1148 'o', /* __u8 Unicode */
1149 0, /* __u8 Unicode */
1150 'o', /* __u8 Unicode */
1151 0, /* __u8 Unicode */
1152 't', /* __u8 Unicode */
1153 0, /* __u8 Unicode */
1154 ' ', /* __u8 Unicode */
1155 0, /* __u8 Unicode */
1156 'H', /* __u8 Unicode */
1157 0, /* __u8 Unicode */
1158 'u', /* __u8 Unicode */
1159 0, /* __u8 Unicode */
1160 'b', /* __u8 Unicode */
1161 0, /* __u8 Unicode */
1164 /* Hub class-specific descriptor is constructed dynamically */
1166 /*-------------------------------------------------------------------------*/
1168 #define OK(x) len = (x); break
1170 #define WR_RH_STAT(x) {info("WR:status %#8x", (x));writel((x), &gohci.regs->roothub.status);}
1171 #define WR_RH_PORTSTAT(x) {info("WR:portstatus[%d] %#8x", wIndex-1, (x));writel((x), &gohci.regs->roothub.portstatus[wIndex-1]);}
1173 #define WR_RH_STAT(x) writel((x), &gohci.regs->roothub.status)
1174 #define WR_RH_PORTSTAT(x) writel((x), &gohci.regs->roothub.portstatus[wIndex-1])
1176 #define RD_RH_STAT roothub_status(&gohci)
1177 #define RD_RH_PORTSTAT roothub_portstatus(&gohci,wIndex-1)
1179 /* request to virtual root hub */
1181 int rh_check_port_status(ohci_t *controller)
1187 temp = roothub_a (controller);
1188 ndp = (temp & RH_A_NDP);
1189 #ifdef CONFIG_AT91C_PQFP_UHPBUG
1190 ndp = (ndp == 2) ? 1:0;
1192 for (i = 0; i < ndp; i++) {
1193 temp = roothub_portstatus (controller, i);
1194 /* check for a device disconnect */
1195 if (((temp & (RH_PS_PESC | RH_PS_CSC)) ==
1196 (RH_PS_PESC | RH_PS_CSC)) &&
1197 ((temp & RH_PS_CCS) == 0)) {
1205 static int ohci_submit_rh_msg(struct usb_device *dev, unsigned long pipe,
1206 void *buffer, int transfer_len, struct devrequest *cmd)
1208 void * data = buffer;
1209 int leni = transfer_len;
1213 __u8 *data_buf = (__u8 *)datab;
1220 pkt_print(NULL, dev, pipe, buffer, transfer_len, cmd, "SUB(rh)", usb_pipein(pipe));
1224 if ((pipe & PIPE_INTERRUPT) == PIPE_INTERRUPT) {
1225 info("Root-Hub submit IRQ: NOT implemented");
1229 bmRType_bReq = cmd->requesttype | (cmd->request << 8);
1230 wValue = cpu_to_le16 (cmd->value);
1231 wIndex = cpu_to_le16 (cmd->index);
1232 wLength = cpu_to_le16 (cmd->length);
1234 info("Root-Hub: adr: %2x cmd(%1x): %08x %04x %04x %04x",
1235 dev->devnum, 8, bmRType_bReq, wValue, wIndex, wLength);
1237 switch (bmRType_bReq) {
1238 /* Request Destination:
1239 without flags: Device,
1240 RH_INTERFACE: interface,
1241 RH_ENDPOINT: endpoint,
1242 RH_CLASS means HUB here,
1243 RH_OTHER | RH_CLASS almost ever means HUB_PORT here
1247 *(__u16 *) data_buf = cpu_to_le16 (1); OK (2);
1248 case RH_GET_STATUS | RH_INTERFACE:
1249 *(__u16 *) data_buf = cpu_to_le16 (0); OK (2);
1250 case RH_GET_STATUS | RH_ENDPOINT:
1251 *(__u16 *) data_buf = cpu_to_le16 (0); OK (2);
1252 case RH_GET_STATUS | RH_CLASS:
1253 *(__u32 *) data_buf = cpu_to_le32 (
1254 RD_RH_STAT & ~(RH_HS_CRWE | RH_HS_DRWE));
1256 case RH_GET_STATUS | RH_OTHER | RH_CLASS:
1257 *(__u32 *) data_buf = cpu_to_le32 (RD_RH_PORTSTAT); OK (4);
1259 case RH_CLEAR_FEATURE | RH_ENDPOINT:
1261 case (RH_ENDPOINT_STALL): OK (0);
1265 case RH_CLEAR_FEATURE | RH_CLASS:
1267 case RH_C_HUB_LOCAL_POWER:
1269 case (RH_C_HUB_OVER_CURRENT):
1270 WR_RH_STAT(RH_HS_OCIC); OK (0);
1274 case RH_CLEAR_FEATURE | RH_OTHER | RH_CLASS:
1276 case (RH_PORT_ENABLE):
1277 WR_RH_PORTSTAT (RH_PS_CCS ); OK (0);
1278 case (RH_PORT_SUSPEND):
1279 WR_RH_PORTSTAT (RH_PS_POCI); OK (0);
1280 case (RH_PORT_POWER):
1281 WR_RH_PORTSTAT (RH_PS_LSDA); OK (0);
1282 case (RH_C_PORT_CONNECTION):
1283 WR_RH_PORTSTAT (RH_PS_CSC ); OK (0);
1284 case (RH_C_PORT_ENABLE):
1285 WR_RH_PORTSTAT (RH_PS_PESC); OK (0);
1286 case (RH_C_PORT_SUSPEND):
1287 WR_RH_PORTSTAT (RH_PS_PSSC); OK (0);
1288 case (RH_C_PORT_OVER_CURRENT):
1289 WR_RH_PORTSTAT (RH_PS_OCIC); OK (0);
1290 case (RH_C_PORT_RESET):
1291 WR_RH_PORTSTAT (RH_PS_PRSC); OK (0);
1295 case RH_SET_FEATURE | RH_OTHER | RH_CLASS:
1297 case (RH_PORT_SUSPEND):
1298 WR_RH_PORTSTAT (RH_PS_PSS ); OK (0);
1299 case (RH_PORT_RESET): /* BUG IN HUP CODE *********/
1300 if (RD_RH_PORTSTAT & RH_PS_CCS)
1301 WR_RH_PORTSTAT (RH_PS_PRS);
1303 case (RH_PORT_POWER):
1304 WR_RH_PORTSTAT (RH_PS_PPS );
1307 case (RH_PORT_ENABLE): /* BUG IN HUP CODE *********/
1308 if (RD_RH_PORTSTAT & RH_PS_CCS)
1309 WR_RH_PORTSTAT (RH_PS_PES );
1314 case RH_SET_ADDRESS: gohci.rh.devnum = wValue; OK(0);
1316 case RH_GET_DESCRIPTOR:
1317 switch ((wValue & 0xff00) >> 8) {
1318 case (0x01): /* device descriptor */
1319 len = min_t(unsigned int,
1322 sizeof (root_hub_dev_des),
1324 data_buf = root_hub_dev_des; OK(len);
1325 case (0x02): /* configuration descriptor */
1326 len = min_t(unsigned int,
1329 sizeof (root_hub_config_des),
1331 data_buf = root_hub_config_des; OK(len);
1332 case (0x03): /* string descriptors */
1333 if(wValue==0x0300) {
1334 len = min_t(unsigned int,
1337 sizeof (root_hub_str_index0),
1339 data_buf = root_hub_str_index0;
1342 if(wValue==0x0301) {
1343 len = min_t(unsigned int,
1346 sizeof (root_hub_str_index1),
1348 data_buf = root_hub_str_index1;
1352 stat = USB_ST_STALLED;
1356 case RH_GET_DESCRIPTOR | RH_CLASS:
1358 __u32 temp = roothub_a (&gohci);
1360 data_buf [0] = 9; /* min length; */
1361 data_buf [1] = 0x29;
1362 data_buf [2] = temp & RH_A_NDP;
1363 #ifdef CONFIG_AT91C_PQFP_UHPBUG
1364 data_buf [2] = (data_buf [2] == 2) ? 1:0;
1367 if (temp & RH_A_PSM) /* per-port power switching? */
1368 data_buf [3] |= 0x1;
1369 if (temp & RH_A_NOCP) /* no overcurrent reporting? */
1370 data_buf [3] |= 0x10;
1371 else if (temp & RH_A_OCPM) /* per-port overcurrent reporting? */
1372 data_buf [3] |= 0x8;
1374 /* corresponds to data_buf[4-7] */
1376 data_buf [5] = (temp & RH_A_POTPGT) >> 24;
1377 temp = roothub_b (&gohci);
1378 data_buf [7] = temp & RH_B_DR;
1379 if (data_buf [2] < 7) {
1380 data_buf [8] = 0xff;
1383 data_buf [8] = (temp & RH_B_DR) >> 8;
1384 data_buf [10] = data_buf [9] = 0xff;
1387 len = min_t(unsigned int, leni,
1388 min_t(unsigned int, data_buf [0], wLength));
1392 case RH_GET_CONFIGURATION: *(__u8 *) data_buf = 0x01; OK (1);
1394 case RH_SET_CONFIGURATION: WR_RH_STAT (0x10000); OK (0);
1397 dbg ("unsupported root hub command");
1398 stat = USB_ST_STALLED;
1402 ohci_dump_roothub (&gohci, 1);
1407 len = min_t(int, len, leni);
1408 if (data != data_buf)
1409 memcpy (data, data_buf, len);
1414 pkt_print(NULL, dev, pipe, buffer, transfer_len, cmd, "RET(rh)", 0/*usb_pipein(pipe)*/);
1422 /*-------------------------------------------------------------------------*/
1424 /* common code for handling submit messages - used for all but root hub */
1426 int submit_common_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
1427 int transfer_len, struct devrequest *setup, int interval)
1430 int maxsize = usb_maxpacket(dev, pipe);
1434 urb = malloc(sizeof(urb_priv_t));
1435 memset(urb, 0, sizeof(urb_priv_t));
1439 urb->transfer_buffer = buffer;
1440 urb->transfer_buffer_length = transfer_len;
1441 urb->interval = interval;
1443 /* device pulled? Shortcut the action. */
1444 if (devgone == dev) {
1445 dev->status = USB_ST_CRC_ERR;
1450 urb->actual_length = 0;
1451 pkt_print(urb, dev, pipe, buffer, transfer_len, setup, "SUB", usb_pipein(pipe));
1456 err("submit_common_message: pipesize for pipe %lx is zero",
1461 if (sohci_submit_job(urb, setup) < 0) {
1462 err("sohci_submit_job failed");
1468 /* ohci_dump_status(&gohci); */
1471 /* allow more time for a BULK device to react - some are slow */
1472 #define BULK_TO 5000 /* timeout in milliseconds */
1473 if (usb_pipetype (pipe) == PIPE_BULK)
1478 /* wait for it to complete */
1480 /* check whether the controller is done */
1481 stat = hc_interrupt();
1483 stat = USB_ST_CRC_ERR;
1487 /* NOTE: since we are not interrupt driven in U-Boot and always
1488 * handle only one URB at a time, we cannot assume the
1489 * transaction finished on the first successful return from
1490 * hc_interrupt().. unless the flag for current URB is set,
1491 * meaning that all TD's to/from device got actually
1492 * transferred and processed. If the current URB is not
1493 * finished we need to re-iterate this loop so as
1494 * hc_interrupt() gets called again as there needs to be some
1495 * more TD's to process still */
1496 if ((stat >= 0) && (stat != 0xff) && (urb->finished)) {
1497 /* 0xff is returned for an SF-interrupt */
1507 err("CTL:TIMEOUT ");
1508 dbg("submit_common_msg: TO status %x\n", stat);
1510 stat = USB_ST_CRC_ERR;
1516 dev->act_len = transfer_len;
1519 pkt_print(urb, dev, pipe, buffer, transfer_len, setup, "RET(ctlr)", usb_pipein(pipe));
1524 /* free TDs in urb_priv */
1525 if (usb_pipetype (pipe) != PIPE_INTERRUPT)
1526 urb_free_priv (urb);
1530 /* submit routines called from usb.c */
1531 int submit_bulk_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
1534 info("submit_bulk_msg");
1535 return submit_common_msg(dev, pipe, buffer, transfer_len, NULL, 0);
1538 int submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
1539 int transfer_len, struct devrequest *setup)
1541 int maxsize = usb_maxpacket(dev, pipe);
1543 info("submit_control_msg");
1545 pkt_print(NULL, dev, pipe, buffer, transfer_len, setup, "SUB", usb_pipein(pipe));
1550 err("submit_control_message: pipesize for pipe %lx is zero",
1554 if (((pipe >> 8) & 0x7f) == gohci.rh.devnum) {
1556 /* root hub - redirect */
1557 return ohci_submit_rh_msg(dev, pipe, buffer, transfer_len,
1561 return submit_common_msg(dev, pipe, buffer, transfer_len, setup, 0);
1564 int submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
1565 int transfer_len, int interval)
1567 info("submit_int_msg");
1568 return submit_common_msg(dev, pipe, buffer, transfer_len, NULL,
1572 /*-------------------------------------------------------------------------*
1574 *-------------------------------------------------------------------------*/
1576 /* reset the HC and BUS */
1578 static int hc_reset (ohci_t *ohci)
1581 int smm_timeout = 50; /* 0,5 sec */
1583 dbg("%s\n", __FUNCTION__);
1585 if (readl (&ohci->regs->control) & OHCI_CTRL_IR) { /* SMM owns the HC */
1586 writel (OHCI_OCR, &ohci->regs->cmdstatus); /* request ownership */
1587 info("USB HC TakeOver from SMM");
1588 while (readl (&ohci->regs->control) & OHCI_CTRL_IR) {
1590 if (--smm_timeout == 0) {
1591 err("USB HC TakeOver failed!");
1597 /* Disable HC interrupts */
1598 writel (OHCI_INTR_MIE, &ohci->regs->intrdisable);
1600 dbg("USB HC reset_hc usb-%s: ctrl = 0x%X ;\n",
1602 readl(&ohci->regs->control));
1604 /* Reset USB (needed by some controllers) */
1605 ohci->hc_control = 0;
1606 writel (ohci->hc_control, &ohci->regs->control);
1608 /* HC Reset requires max 10 us delay */
1609 writel (OHCI_HCR, &ohci->regs->cmdstatus);
1610 while ((readl (&ohci->regs->cmdstatus) & OHCI_HCR) != 0) {
1611 if (--timeout == 0) {
1612 err("USB HC reset timed out!");
1620 /*-------------------------------------------------------------------------*/
1622 /* Start an OHCI controller, set the BUS operational
1624 * connect the virtual root hub */
1626 static int hc_start (ohci_t * ohci)
1629 unsigned int fminterval;
1633 /* Tell the controller where the control and bulk lists are
1634 * The lists are empty now. */
1636 writel (0, &ohci->regs->ed_controlhead);
1637 writel (0, &ohci->regs->ed_bulkhead);
1639 writel ((__u32)ohci->hcca, &ohci->regs->hcca); /* a reset clears this */
1641 fminterval = 0x2edf;
1642 writel ((fminterval * 9) / 10, &ohci->regs->periodicstart);
1643 fminterval |= ((((fminterval - 210) * 6) / 7) << 16);
1644 writel (fminterval, &ohci->regs->fminterval);
1645 writel (0x628, &ohci->regs->lsthresh);
1647 /* start controller operations */
1648 ohci->hc_control = OHCI_CONTROL_INIT | OHCI_USB_OPER;
1650 writel (ohci->hc_control, &ohci->regs->control);
1652 /* disable all interrupts */
1653 mask = (OHCI_INTR_SO | OHCI_INTR_WDH | OHCI_INTR_SF | OHCI_INTR_RD |
1654 OHCI_INTR_UE | OHCI_INTR_FNO | OHCI_INTR_RHSC |
1655 OHCI_INTR_OC | OHCI_INTR_MIE);
1656 writel (mask, &ohci->regs->intrdisable);
1657 /* clear all interrupts */
1658 mask &= ~OHCI_INTR_MIE;
1659 writel (mask, &ohci->regs->intrstatus);
1660 /* Choose the interrupts we care about now - but w/o MIE */
1661 mask = OHCI_INTR_RHSC | OHCI_INTR_UE | OHCI_INTR_WDH | OHCI_INTR_SO;
1662 writel (mask, &ohci->regs->intrenable);
1665 /* required for AMD-756 and some Mac platforms */
1666 writel ((roothub_a (ohci) | RH_A_NPS) & ~RH_A_PSM,
1667 &ohci->regs->roothub.a);
1668 writel (RH_HS_LPSC, &ohci->regs->roothub.status);
1669 #endif /* OHCI_USE_NPS */
1671 #define mdelay(n) ({unsigned long msec=(n); while (msec--) udelay(1000);})
1672 /* POTPGT delay is bits 24-31, in 2 ms units. */
1673 mdelay ((roothub_a (ohci) >> 23) & 0x1fe);
1675 /* connect the virtual root hub */
1676 ohci->rh.devnum = 0;
1681 /*-------------------------------------------------------------------------*/
1683 /* Poll USB interrupt. */
1684 void usb_event_poll(void)
1689 /* an interrupt happens */
1691 static int hc_interrupt (void)
1693 ohci_t *ohci = &gohci;
1694 struct ohci_regs *regs = ohci->regs;
1698 if ((ohci->hcca->done_head != 0) &&
1699 !(m32_swap (ohci->hcca->done_head) & 0x01)) {
1700 ints = OHCI_INTR_WDH;
1701 } else if ((ints = readl (®s->intrstatus)) == ~(u32)0) {
1703 err ("%s device removed!", ohci->slot_name);
1705 } else if ((ints &= readl (®s->intrenable)) == 0) {
1706 dbg("hc_interrupt: returning..\n");
1710 /* dbg("Interrupt: %x frame: %x", ints, le16_to_cpu (ohci->hcca->frame_no)); */
1712 if (ints & OHCI_INTR_RHSC) {
1717 if (ints & OHCI_INTR_UE) {
1719 err ("OHCI Unrecoverable Error, controller usb-%s disabled",
1721 /* e.g. due to PCI Master/Target Abort */
1724 ohci_dump (ohci, 1);
1728 /* FIXME: be optimistic, hope that bug won't repeat often. */
1729 /* Make some non-interrupt context restart the controller. */
1730 /* Count and limit the retries though; either hardware or */
1731 /* software errors can go forever... */
1736 if (ints & OHCI_INTR_WDH) {
1738 writel (OHCI_INTR_WDH, ®s->intrdisable);
1739 (void)readl (®s->intrdisable); /* flush */
1740 stat = dl_done_list (&gohci, dl_reverse_done_list (&gohci));
1741 writel (OHCI_INTR_WDH, ®s->intrenable);
1742 (void)readl (®s->intrdisable); /* flush */
1745 if (ints & OHCI_INTR_SO) {
1746 dbg("USB Schedule overrun\n");
1747 writel (OHCI_INTR_SO, ®s->intrenable);
1751 /* FIXME: this assumes SOF (1/ms) interrupts don't get lost... */
1752 if (ints & OHCI_INTR_SF) {
1753 unsigned int frame = m16_swap (ohci->hcca->frame_no) & 1;
1755 writel (OHCI_INTR_SF, ®s->intrdisable);
1756 if (ohci->ed_rm_list[frame] != NULL)
1757 writel (OHCI_INTR_SF, ®s->intrenable);
1761 writel (ints, ®s->intrstatus);
1765 /*-------------------------------------------------------------------------*/
1767 /*-------------------------------------------------------------------------*/
1769 /* De-allocate all resources.. */
1771 static void hc_release_ohci (ohci_t *ohci)
1773 dbg ("USB HC release ohci usb-%s", ohci->slot_name);
1775 if (!ohci->disabled)
1779 /*-------------------------------------------------------------------------*/
1782 * low level initalisation routine, called from usb.c
1784 static char ohci_inited = 0;
1786 int usb_lowlevel_init(void)
1788 #ifdef CONFIG_PCI_OHCI
1792 #ifdef CFG_USB_OHCI_CPU_INIT
1793 /* cpu dependant init */
1798 #ifdef CFG_USB_OHCI_BOARD_INIT
1799 /* board dependant init */
1800 if(usb_board_init())
1803 memset (&gohci, 0, sizeof (ohci_t));
1805 /* align the storage */
1806 if ((__u32)&ghcca[0] & 0xff) {
1807 err("HCCA not aligned!!");
1811 info("aligned ghcca %p", phcca);
1812 memset(&ohci_dev, 0, sizeof(struct ohci_device));
1813 if ((__u32)&ohci_dev.ed[0] & 0x7) {
1814 err("EDs not aligned!!");
1817 memset(gtd, 0, sizeof(td_t) * (NUM_TD + 1));
1818 if ((__u32)gtd & 0x7) {
1819 err("TDs not aligned!!");
1824 memset (phcca, 0, sizeof (struct ohci_hcca));
1829 #ifdef CONFIG_PCI_OHCI
1830 pdev = pci_find_devices(ohci_pci_ids, 0);
1835 pci_read_config_word(pdev, PCI_VENDOR_ID, &vid);
1836 pci_read_config_word(pdev, PCI_DEVICE_ID, &did);
1837 printf("OHCI pci controller (%04x, %04x) found @(%d:%d:%d)\n",
1838 vid, did, (pdev >> 16) & 0xff,
1839 (pdev >> 11) & 0x1f, (pdev >> 8) & 0x7);
1840 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &base);
1841 printf("OHCI regs address 0x%08x\n", base);
1842 gohci.regs = (struct ohci_regs *)base;
1846 gohci.regs = (struct ohci_regs *)CFG_USB_OHCI_REGS_BASE;
1850 gohci.slot_name = CFG_USB_OHCI_SLOT_NAME;
1852 if (hc_reset (&gohci) < 0) {
1853 hc_release_ohci (&gohci);
1854 err ("can't reset usb-%s", gohci.slot_name);
1855 #ifdef CFG_USB_OHCI_BOARD_INIT
1856 /* board dependant cleanup */
1857 usb_board_init_fail();
1860 #ifdef CFG_USB_OHCI_CPU_INIT
1861 /* cpu dependant cleanup */
1862 usb_cpu_init_fail();
1867 /* FIXME this is a second HC reset; why?? */
1868 /* writel(gohci.hc_control = OHCI_USB_RESET, &gohci.regs->control);
1870 if (hc_start (&gohci) < 0) {
1871 err ("can't start usb-%s", gohci.slot_name);
1872 hc_release_ohci (&gohci);
1873 /* Initialization failed */
1874 #ifdef CFG_USB_OHCI_BOARD_INIT
1875 /* board dependant cleanup */
1879 #ifdef CFG_USB_OHCI_CPU_INIT
1880 /* cpu dependant cleanup */
1887 ohci_dump (&gohci, 1);
1895 int usb_lowlevel_stop(void)
1897 /* this gets called really early - before the controller has */
1898 /* even been initialized! */
1901 /* TODO release any interrupts, etc. */
1902 /* call hc_release_ohci() here ? */
1905 #ifdef CFG_USB_OHCI_BOARD_INIT
1906 /* board dependant cleanup */
1907 if(usb_board_stop())
1911 #ifdef CFG_USB_OHCI_CPU_INIT
1912 /* cpu dependant cleanup */
1919 #endif /* CONFIG_USB_OHCI_NEW */