2 * URB OHCI HCD (Host Controller Driver) for USB on the AT91RM9200.
5 * Gary Jennejohn, DENX Software Engineering <gj@denx.de>
7 * Note: Much of this code has been derived from Linux 2.4
8 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
9 * (C) Copyright 2000-2002 David Brownell
11 * Modified for the MP2USB by (C) Copyright 2005 Eric Benard
12 * ebenard@eukrea.com - based on s3c24x0's driver
14 * See file CREDITS for list of people who contributed to this
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License as
19 * published by the Free Software Foundation; either version 2 of
20 * the License, or (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
35 * 1 - you MUST define LITTLEENDIAN in the configuration file for the
36 * board or this driver will NOT work!
37 * 2 - this driver is intended for use with USB Mass Storage Devices
38 * (BBB) ONLY. There is NO support for Interrupt or Isochronous pipes!
39 * 3 - when running on a PQFP208 AT91RM9200, define CONFIG_AT91C_PQFP_UHPBUG
40 * to activate workaround for bug #41 or this driver will NOT work!
44 /* #include <pci.h> no PCI on the S3C24X0 */
46 #ifdef CONFIG_USB_OHCI_NEW
48 /* mk: are these really required? */
49 #if defined(CONFIG_S3C2400)
51 #elif defined(CONFIG_S3C2410)
53 #elif defined(CONFIG_ARM920T)
54 # include <asm/arch/hardware.h>
55 #elif defined(CONFIG_CPU_MONAHANS)
56 # include <asm/arch/pxa-regs.h>
57 #elif defined(CONFIG_MPC5200)
67 #if defined(CONFIG_ARM920T) || \
68 defined(CONFIG_S3C2400) || \
69 defined(CONFIG_S3C2410) || \
70 defined(CONFIG_440EP) || \
71 defined(CONFIG_MPC5200)
72 # define OHCI_USE_NPS /* force NoPowerSwitching mode */
75 #undef OHCI_VERBOSE_DEBUG /* not always helpful */
78 #undef OHCI_FILL_TRACE
80 /* For initializing controller (mask in an HCFS mode too) */
81 #define OHCI_CONTROL_INIT \
82 (OHCI_CTRL_CBSR & 0x3) | OHCI_CTRL_IE | OHCI_CTRL_PLE
84 #define readl(a) (*((vu_long *)(a)))
85 #define writel(a, b) (*((vu_long *)(b)) = ((vu_long)a))
87 #define min_t(type,x,y) ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
91 #define dbg(format, arg...) printf("DEBUG: " format "\n", ## arg)
93 #define dbg(format, arg...) do {} while(0)
95 #define err(format, arg...) printf("ERROR: " format "\n", ## arg)
98 #define info(format, arg...) printf("INFO: " format "\n", ## arg)
100 #define info(format, arg...) do {} while(0)
103 #if defined(CONFIG_440EP) || defined(CONFIG_MPC5200)
104 # define m16_swap(x) (x)
105 # define m32_swap(x) (x)
107 # define m16_swap(x) swap_16(x)
108 # define m32_swap(x) swap_32(x)
113 /* this must be aligned to a 256 byte boundary */
114 struct ohci_hcca ghcca[1];
115 /* a pointer to the aligned storage */
116 struct ohci_hcca *phcca;
117 /* this allocates EDs for all possible endpoints */
118 struct ohci_device ohci_dev;
123 /* device which was disconnected */
124 struct usb_device *devgone;
127 /* flag guarding URB transation */
128 int urb_finished = 0;
132 /*-------------------------------------------------------------------------*/
134 /* AMD-756 (D2 rev) reports corrupt register contents in some cases.
135 * The erratum (#4) description is incorrect. AMD's workaround waits
136 * till some bits (mostly reserved) are clear; ok for all revs.
138 #define OHCI_QUIRK_AMD756 0xabcd
139 #define read_roothub(hc, register, mask) ({ \
140 u32 temp = readl (&hc->regs->roothub.register); \
141 if (hc->flags & OHCI_QUIRK_AMD756) \
142 while (temp & mask) \
143 temp = readl (&hc->regs->roothub.register); \
146 static u32 roothub_a (struct ohci *hc)
147 { return read_roothub (hc, a, 0xfc0fe000); }
148 static inline u32 roothub_b (struct ohci *hc)
149 { return readl (&hc->regs->roothub.b); }
150 static inline u32 roothub_status (struct ohci *hc)
151 { return readl (&hc->regs->roothub.status); }
152 static u32 roothub_portstatus (struct ohci *hc, int i)
153 { return read_roothub (hc, portstatus [i], 0xffe0fce0); }
156 /* forward declaration */
157 static int hc_interrupt (void);
159 td_submit_job (struct usb_device * dev, unsigned long pipe, void * buffer,
160 int transfer_len, struct devrequest * setup, urb_priv_t * urb, int interval);
162 /*-------------------------------------------------------------------------*
163 * URB support functions
164 *-------------------------------------------------------------------------*/
166 /* free HCD-private data associated with this URB */
168 static void urb_free_priv (urb_priv_t * urb)
174 last = urb->length - 1;
176 for (i = 0; i <= last; i++) {
186 /*-------------------------------------------------------------------------*/
189 static int sohci_get_current_frame_number (struct usb_device * dev);
191 /* debug| print the main components of an URB
192 * small: 0) header + data packets 1) just header */
194 static void pkt_print (struct usb_device * dev, unsigned long pipe, void * buffer,
195 int transfer_len, struct devrequest * setup, char * str, int small)
197 urb_priv_t * purb = &urb_priv;
199 dbg("%s URB:[%4x] dev:%2d,ep:%2d-%c,type:%s,len:%d/%d stat:%#lx",
201 sohci_get_current_frame_number (dev),
202 usb_pipedevice (pipe),
203 usb_pipeendpoint (pipe),
204 usb_pipeout (pipe)? 'O': 'I',
205 usb_pipetype (pipe) < 2? (usb_pipeint (pipe)? "INTR": "ISOC"):
206 (usb_pipecontrol (pipe)? "CTRL": "BULK"),
208 transfer_len, dev->status);
209 #ifdef OHCI_VERBOSE_DEBUG
213 if (usb_pipecontrol (pipe)) {
214 printf (__FILE__ ": cmd(8):");
215 for (i = 0; i < 8 ; i++)
216 printf (" %02x", ((__u8 *) setup) [i]);
219 if (transfer_len > 0 && buffer) {
220 printf (__FILE__ ": data(%d/%d):",
223 len = usb_pipeout (pipe)?
224 transfer_len: purb->actual_length;
225 for (i = 0; i < 16 && i < len; i++)
226 printf (" %02x", ((__u8 *) buffer) [i]);
227 printf ("%s\n", i < len? "...": "");
233 /* just for debugging; prints non-empty branches of the int ed tree inclusive iso eds*/
234 void ep_print_int_eds (ohci_t *ohci, char * str) {
237 for (i= 0; i < 32; i++) {
239 ed_p = &(ohci->hcca->int_table [i]);
242 printf (__FILE__ ": %s branch int %2d(%2x):", str, i, i);
243 while (*ed_p != 0 && j--) {
244 ed_t *ed = (ed_t *)m32_swap(ed_p);
245 printf (" ed: %4x;", ed->hwINFO);
246 ed_p = &ed->hwNextED;
252 static void ohci_dump_intr_mask (char *label, __u32 mask)
254 dbg ("%s: 0x%08x%s%s%s%s%s%s%s%s%s",
257 (mask & OHCI_INTR_MIE) ? " MIE" : "",
258 (mask & OHCI_INTR_OC) ? " OC" : "",
259 (mask & OHCI_INTR_RHSC) ? " RHSC" : "",
260 (mask & OHCI_INTR_FNO) ? " FNO" : "",
261 (mask & OHCI_INTR_UE) ? " UE" : "",
262 (mask & OHCI_INTR_RD) ? " RD" : "",
263 (mask & OHCI_INTR_SF) ? " SF" : "",
264 (mask & OHCI_INTR_WDH) ? " WDH" : "",
265 (mask & OHCI_INTR_SO) ? " SO" : ""
269 static void maybe_print_eds (char *label, __u32 value)
271 ed_t *edp = (ed_t *)value;
274 dbg ("%s %08x", label, value);
275 dbg ("%08x", edp->hwINFO);
276 dbg ("%08x", edp->hwTailP);
277 dbg ("%08x", edp->hwHeadP);
278 dbg ("%08x", edp->hwNextED);
282 static char * hcfs2string (int state)
285 case OHCI_USB_RESET: return "reset";
286 case OHCI_USB_RESUME: return "resume";
287 case OHCI_USB_OPER: return "operational";
288 case OHCI_USB_SUSPEND: return "suspend";
293 /* dump control and status registers */
294 static void ohci_dump_status (ohci_t *controller)
296 struct ohci_regs *regs = controller->regs;
299 temp = readl (®s->revision) & 0xff;
301 dbg ("spec %d.%d", (temp >> 4), (temp & 0x0f));
303 temp = readl (®s->control);
304 dbg ("control: 0x%08x%s%s%s HCFS=%s%s%s%s%s CBSR=%d", temp,
305 (temp & OHCI_CTRL_RWE) ? " RWE" : "",
306 (temp & OHCI_CTRL_RWC) ? " RWC" : "",
307 (temp & OHCI_CTRL_IR) ? " IR" : "",
308 hcfs2string (temp & OHCI_CTRL_HCFS),
309 (temp & OHCI_CTRL_BLE) ? " BLE" : "",
310 (temp & OHCI_CTRL_CLE) ? " CLE" : "",
311 (temp & OHCI_CTRL_IE) ? " IE" : "",
312 (temp & OHCI_CTRL_PLE) ? " PLE" : "",
313 temp & OHCI_CTRL_CBSR
316 temp = readl (®s->cmdstatus);
317 dbg ("cmdstatus: 0x%08x SOC=%d%s%s%s%s", temp,
318 (temp & OHCI_SOC) >> 16,
319 (temp & OHCI_OCR) ? " OCR" : "",
320 (temp & OHCI_BLF) ? " BLF" : "",
321 (temp & OHCI_CLF) ? " CLF" : "",
322 (temp & OHCI_HCR) ? " HCR" : ""
325 ohci_dump_intr_mask ("intrstatus", readl (®s->intrstatus));
326 ohci_dump_intr_mask ("intrenable", readl (®s->intrenable));
328 maybe_print_eds ("ed_periodcurrent", readl (®s->ed_periodcurrent));
330 maybe_print_eds ("ed_controlhead", readl (®s->ed_controlhead));
331 maybe_print_eds ("ed_controlcurrent", readl (®s->ed_controlcurrent));
333 maybe_print_eds ("ed_bulkhead", readl (®s->ed_bulkhead));
334 maybe_print_eds ("ed_bulkcurrent", readl (®s->ed_bulkcurrent));
336 maybe_print_eds ("donehead", readl (®s->donehead));
339 static void ohci_dump_roothub (ohci_t *controller, int verbose)
343 temp = roothub_a (controller);
344 ndp = (temp & RH_A_NDP);
345 #ifdef CONFIG_AT91C_PQFP_UHPBUG
346 ndp = (ndp == 2) ? 1:0;
349 dbg ("roothub.a: %08x POTPGT=%d%s%s%s%s%s NDP=%d", temp,
350 ((temp & RH_A_POTPGT) >> 24) & 0xff,
351 (temp & RH_A_NOCP) ? " NOCP" : "",
352 (temp & RH_A_OCPM) ? " OCPM" : "",
353 (temp & RH_A_DT) ? " DT" : "",
354 (temp & RH_A_NPS) ? " NPS" : "",
355 (temp & RH_A_PSM) ? " PSM" : "",
358 temp = roothub_b (controller);
359 dbg ("roothub.b: %08x PPCM=%04x DR=%04x",
361 (temp & RH_B_PPCM) >> 16,
364 temp = roothub_status (controller);
365 dbg ("roothub.status: %08x%s%s%s%s%s%s",
367 (temp & RH_HS_CRWE) ? " CRWE" : "",
368 (temp & RH_HS_OCIC) ? " OCIC" : "",
369 (temp & RH_HS_LPSC) ? " LPSC" : "",
370 (temp & RH_HS_DRWE) ? " DRWE" : "",
371 (temp & RH_HS_OCI) ? " OCI" : "",
372 (temp & RH_HS_LPS) ? " LPS" : ""
376 for (i = 0; i < ndp; i++) {
377 temp = roothub_portstatus (controller, i);
378 dbg ("roothub.portstatus [%d] = 0x%08x%s%s%s%s%s%s%s%s%s%s%s%s",
381 (temp & RH_PS_PRSC) ? " PRSC" : "",
382 (temp & RH_PS_OCIC) ? " OCIC" : "",
383 (temp & RH_PS_PSSC) ? " PSSC" : "",
384 (temp & RH_PS_PESC) ? " PESC" : "",
385 (temp & RH_PS_CSC) ? " CSC" : "",
387 (temp & RH_PS_LSDA) ? " LSDA" : "",
388 (temp & RH_PS_PPS) ? " PPS" : "",
389 (temp & RH_PS_PRS) ? " PRS" : "",
390 (temp & RH_PS_POCI) ? " POCI" : "",
391 (temp & RH_PS_PSS) ? " PSS" : "",
393 (temp & RH_PS_PES) ? " PES" : "",
394 (temp & RH_PS_CCS) ? " CCS" : ""
399 static void ohci_dump (ohci_t *controller, int verbose)
401 dbg ("OHCI controller usb-%s state", controller->slot_name);
403 /* dumps some of the state we know about */
404 ohci_dump_status (controller);
406 ep_print_int_eds (controller, "hcca");
407 dbg ("hcca frame #%04x", controller->hcca->frame_no);
408 ohci_dump_roothub (controller, 1);
414 /*-------------------------------------------------------------------------*
415 * Interface functions (URB)
416 *-------------------------------------------------------------------------*/
418 /* get a transfer request */
420 int sohci_submit_job(struct usb_device *dev, unsigned long pipe, void *buffer,
421 int transfer_len, struct devrequest *setup, int interval)
425 urb_priv_t *purb_priv;
430 /* when controller's hung, permit only roothub cleanup attempts
431 * such as powering down ports */
432 if (ohci->disabled) {
433 err("sohci_submit_job: EPIPE");
437 /* if we have an unfinished URB from previous transaction let's
438 * fail and scream as quickly as possible so as not to corrupt
439 * further communication */
441 err("sohci_submit_job: URB NOT FINISHED");
444 /* we're about to begin a new transaction here so mark the URB unfinished */
448 /* every endpoint has a ed, locate and fill it */
449 if (!(ed = ep_add_ed (dev, pipe))) {
450 err("sohci_submit_job: ENOMEM");
454 /* for the private part of the URB we need the number of TDs (size) */
455 switch (usb_pipetype (pipe)) {
456 case PIPE_BULK: /* one TD for every 4096 Byte */
457 size = (transfer_len - 1) / 4096 + 1;
459 case PIPE_CONTROL: /* 1 TD for setup, 1 for ACK and 1 for every 4096 B */
460 size = (transfer_len == 0)? 2:
461 (transfer_len - 1) / 4096 + 3;
465 if (size >= (N_URB_TD - 1)) {
466 err("need %d TDs, only have %d", size, N_URB_TD);
469 purb_priv = &urb_priv;
470 purb_priv->pipe = pipe;
472 /* fill the private part of the URB */
473 purb_priv->length = size;
475 purb_priv->actual_length = 0;
477 /* allocate the TDs */
478 /* note that td[0] was allocated in ep_add_ed */
479 for (i = 0; i < size; i++) {
480 purb_priv->td[i] = td_alloc (dev);
481 if (!purb_priv->td[i]) {
482 purb_priv->length = i;
483 urb_free_priv (purb_priv);
484 err("sohci_submit_job: ENOMEM");
489 if (ed->state == ED_NEW || (ed->state & ED_DEL)) {
490 urb_free_priv (purb_priv);
491 err("sohci_submit_job: EINVAL");
495 /* link the ed into a chain if is not already */
496 if (ed->state != ED_OPER)
499 /* fill the TDs and link it to the ed */
500 td_submit_job(dev, pipe, buffer, transfer_len, setup, purb_priv, interval);
505 /*-------------------------------------------------------------------------*/
508 /* tell us the current USB frame number */
510 static int sohci_get_current_frame_number (struct usb_device *usb_dev)
512 ohci_t *ohci = &gohci;
514 return m16_swap (ohci->hcca->frame_no);
518 /*-------------------------------------------------------------------------*
519 * ED handling functions
520 *-------------------------------------------------------------------------*/
522 /* link an ed into one of the HC chains */
524 static int ep_link (ohci_t *ohci, ed_t *edi)
526 volatile ed_t *ed = edi;
533 if (ohci->ed_controltail == NULL) {
534 writel (ed, &ohci->regs->ed_controlhead);
536 ohci->ed_controltail->hwNextED = m32_swap ((unsigned long)ed);
538 ed->ed_prev = ohci->ed_controltail;
539 if (!ohci->ed_controltail && !ohci->ed_rm_list[0] &&
540 !ohci->ed_rm_list[1] && !ohci->sleeping) {
541 ohci->hc_control |= OHCI_CTRL_CLE;
542 writel (ohci->hc_control, &ohci->regs->control);
544 ohci->ed_controltail = edi;
549 if (ohci->ed_bulktail == NULL) {
550 writel (ed, &ohci->regs->ed_bulkhead);
552 ohci->ed_bulktail->hwNextED = m32_swap ((unsigned long)ed);
554 ed->ed_prev = ohci->ed_bulktail;
555 if (!ohci->ed_bulktail && !ohci->ed_rm_list[0] &&
556 !ohci->ed_rm_list[1] && !ohci->sleeping) {
557 ohci->hc_control |= OHCI_CTRL_BLE;
558 writel (ohci->hc_control, &ohci->regs->control);
560 ohci->ed_bulktail = edi;
566 /*-------------------------------------------------------------------------*/
568 /* unlink an ed from one of the HC chains.
569 * just the link to the ed is unlinked.
570 * the link from the ed still points to another operational ed or 0
571 * so the HC can eventually finish the processing of the unlinked ed */
573 static int ep_unlink (ohci_t *ohci, ed_t *edi)
575 volatile ed_t *ed = edi;
577 ed->hwINFO |= m32_swap (OHCI_ED_SKIP);
581 if (ed->ed_prev == NULL) {
583 ohci->hc_control &= ~OHCI_CTRL_CLE;
584 writel (ohci->hc_control, &ohci->regs->control);
586 writel (m32_swap (*((__u32 *)&ed->hwNextED)), &ohci->regs->ed_controlhead);
588 ed->ed_prev->hwNextED = ed->hwNextED;
590 if (ohci->ed_controltail == ed) {
591 ohci->ed_controltail = ed->ed_prev;
593 ((ed_t *)m32_swap (*((__u32 *)&ed->hwNextED)))->ed_prev = ed->ed_prev;
598 if (ed->ed_prev == NULL) {
600 ohci->hc_control &= ~OHCI_CTRL_BLE;
601 writel (ohci->hc_control, &ohci->regs->control);
603 writel (m32_swap (*((__u32 *)&ed->hwNextED)), &ohci->regs->ed_bulkhead);
605 ed->ed_prev->hwNextED = ed->hwNextED;
607 if (ohci->ed_bulktail == ed) {
608 ohci->ed_bulktail = ed->ed_prev;
610 ((ed_t *)m32_swap (*((__u32 *)&ed->hwNextED)))->ed_prev = ed->ed_prev;
614 ed->state = ED_UNLINK;
619 /*-------------------------------------------------------------------------*/
621 /* add/reinit an endpoint; this should be done once at the
622 * usb_set_configuration command, but the USB stack is a little bit
623 * stateless so we do it at every transaction if the state of the ed
624 * is ED_NEW then a dummy td is added and the state is changed to
625 * ED_UNLINK in all other cases the state is left unchanged the ed
626 * info fields are setted anyway even though most of them should not
629 static ed_t * ep_add_ed (struct usb_device *usb_dev, unsigned long pipe)
635 ed = ed_ret = &ohci_dev.ed[(usb_pipeendpoint (pipe) << 1) |
636 (usb_pipecontrol (pipe)? 0: usb_pipeout (pipe))];
638 if ((ed->state & ED_DEL) || (ed->state & ED_URB_DEL)) {
639 err("ep_add_ed: pending delete");
640 /* pending delete request */
644 if (ed->state == ED_NEW) {
645 ed->hwINFO = m32_swap (OHCI_ED_SKIP); /* skip ed */
646 /* dummy td; end of td list for ed */
647 td = td_alloc (usb_dev);
648 ed->hwTailP = m32_swap ((unsigned long)td);
649 ed->hwHeadP = ed->hwTailP;
650 ed->state = ED_UNLINK;
651 ed->type = usb_pipetype (pipe);
655 ed->hwINFO = m32_swap (usb_pipedevice (pipe)
656 | usb_pipeendpoint (pipe) << 7
657 | (usb_pipeisoc (pipe)? 0x8000: 0)
658 | (usb_pipecontrol (pipe)? 0: (usb_pipeout (pipe)? 0x800: 0x1000))
659 | usb_pipeslow (pipe) << 13
660 | usb_maxpacket (usb_dev, pipe) << 16);
665 /*-------------------------------------------------------------------------*
666 * TD handling functions
667 *-------------------------------------------------------------------------*/
669 /* enqueue next TD for this URB (OHCI spec 5.2.8.2) */
671 static void td_fill (ohci_t *ohci, unsigned int info,
673 struct usb_device *dev, int index, urb_priv_t *urb_priv)
675 volatile td_t *td, *td_pt;
676 #ifdef OHCI_FILL_TRACE
680 if (index > urb_priv->length) {
681 err("index > length");
684 /* use this td as the next dummy */
685 td_pt = urb_priv->td [index];
688 /* fill the old dummy TD */
689 td = urb_priv->td [index] = (td_t *)(m32_swap (urb_priv->ed->hwTailP) & ~0xf);
691 td->ed = urb_priv->ed;
692 td->next_dl_td = NULL;
694 td->data = (__u32)data;
695 #ifdef OHCI_FILL_TRACE
696 if ((usb_pipetype(urb_priv->pipe) == PIPE_BULK) && usb_pipeout(urb_priv->pipe)) {
697 for (i = 0; i < len; i++)
698 printf("td->data[%d] %#2x ",i, ((unsigned char *)td->data)[i]);
705 td->hwINFO = m32_swap (info);
706 td->hwCBP = m32_swap ((unsigned long)data);
708 td->hwBE = m32_swap ((unsigned long)(data + len - 1));
711 td->hwNextTD = m32_swap ((unsigned long)td_pt);
712 #ifndef S3C24X0_merge
713 td->hwPSW [0] = m16_swap (((__u32)data & 0x0FFF) | 0xE000);
716 /* append to queue */
717 td->ed->hwTailP = td->hwNextTD;
720 /*-------------------------------------------------------------------------*/
722 /* prepare all TDs of a transfer */
724 static void td_submit_job (struct usb_device *dev, unsigned long pipe, void *buffer,
725 int transfer_len, struct devrequest *setup, urb_priv_t *urb, int interval)
727 ohci_t *ohci = &gohci;
728 int data_len = transfer_len;
732 unsigned int toggle = 0;
734 /* OHCI handles the DATA-toggles itself, we just use the USB-toggle bits for reseting */
735 if(usb_gettoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe))) {
736 toggle = TD_T_TOGGLE;
739 usb_settoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe), 1);
747 switch (usb_pipetype (pipe)) {
749 info = usb_pipeout (pipe)?
750 TD_CC | TD_DP_OUT : TD_CC | TD_DP_IN ;
751 while(data_len > 4096) {
752 td_fill (ohci, info | (cnt? TD_T_TOGGLE:toggle), data, 4096, dev, cnt, urb);
753 data += 4096; data_len -= 4096; cnt++;
755 info = usb_pipeout (pipe)?
756 TD_CC | TD_DP_OUT : TD_CC | TD_R | TD_DP_IN ;
757 td_fill (ohci, info | (cnt? TD_T_TOGGLE:toggle), data, data_len, dev, cnt, urb);
761 writel (OHCI_BLF, &ohci->regs->cmdstatus); /* start bulk list */
765 info = TD_CC | TD_DP_SETUP | TD_T_DATA0;
766 td_fill (ohci, info, setup, 8, dev, cnt++, urb);
768 info = usb_pipeout (pipe)?
769 TD_CC | TD_R | TD_DP_OUT | TD_T_DATA1 : TD_CC | TD_R | TD_DP_IN | TD_T_DATA1;
770 /* NOTE: mishandles transfers >8K, some >4K */
771 td_fill (ohci, info, data, data_len, dev, cnt++, urb);
773 info = usb_pipeout (pipe)?
774 TD_CC | TD_DP_IN | TD_T_DATA1: TD_CC | TD_DP_OUT | TD_T_DATA1;
775 td_fill (ohci, info, data, 0, dev, cnt++, urb);
777 writel (OHCI_CLF, &ohci->regs->cmdstatus); /* start Control list */
780 if (urb->length != cnt)
781 dbg("TD LENGTH %d != CNT %d", urb->length, cnt);
784 /*-------------------------------------------------------------------------*
785 * Done List handling functions
786 *-------------------------------------------------------------------------*/
789 /* calculate the transfer length and update the urb */
791 static void dl_transfer_length(td_t * td)
793 __u32 tdINFO, tdBE, tdCBP;
794 urb_priv_t *lurb_priv = &urb_priv;
796 tdINFO = m32_swap (td->hwINFO);
797 tdBE = m32_swap (td->hwBE);
798 tdCBP = m32_swap (td->hwCBP);
801 if (!(usb_pipetype (lurb_priv->pipe) == PIPE_CONTROL &&
802 ((td->index == 0) || (td->index == lurb_priv->length - 1)))) {
805 lurb_priv->actual_length += tdBE - td->data + 1;
807 lurb_priv->actual_length += tdCBP - td->data;
812 /*-------------------------------------------------------------------------*/
814 /* replies to the request have to be on a FIFO basis so
815 * we reverse the reversed done-list */
817 static td_t * dl_reverse_done_list (ohci_t *ohci)
821 td_t *td_list = NULL;
822 urb_priv_t *lurb_priv = NULL;
824 td_list_hc = m32_swap (ohci->hcca->done_head) & 0xfffffff0;
825 ohci->hcca->done_head = 0;
828 td_list = (td_t *)td_list_hc;
830 if (TD_CC_GET (m32_swap (td_list->hwINFO))) {
831 lurb_priv = &urb_priv;
832 dbg(" USB-error/status: %x : %p",
833 TD_CC_GET (m32_swap (td_list->hwINFO)), td_list);
834 if (td_list->ed->hwHeadP & m32_swap (0x1)) {
835 if (lurb_priv && ((td_list->index + 1) < lurb_priv->length)) {
836 td_list->ed->hwHeadP =
837 (lurb_priv->td[lurb_priv->length - 1]->hwNextTD & m32_swap (0xfffffff0)) |
838 (td_list->ed->hwHeadP & m32_swap (0x2));
839 lurb_priv->td_cnt += lurb_priv->length - td_list->index - 1;
841 td_list->ed->hwHeadP &= m32_swap (0xfffffff2);
843 #ifdef CONFIG_MPC5200
844 td_list->hwNextTD = 0;
848 td_list->next_dl_td = td_rev;
850 td_list_hc = m32_swap (td_list->hwNextTD) & 0xfffffff0;
855 /*-------------------------------------------------------------------------*/
858 static int dl_done_list (ohci_t *ohci, td_t *td_list)
860 td_t *td_list_next = NULL;
865 urb_priv_t *lurb_priv;
866 __u32 tdINFO, edHeadP, edTailP;
869 td_list_next = td_list->next_dl_td;
871 lurb_priv = &urb_priv;
872 tdINFO = m32_swap (td_list->hwINFO);
876 dl_transfer_length(td_list);
878 /* error code of transfer */
879 cc = TD_CC_GET (tdINFO);
881 dbg("ConditionCode %#x", cc);
882 stat = cc_to_error[cc];
885 /* see if this done list makes for all TD's of current URB,
886 * and mark the URB finished if so */
887 if (++(lurb_priv->td_cnt) == lurb_priv->length) {
889 if ((ed->state & (ED_OPER | ED_UNLINK)) &&
890 (lurb_priv->state != URB_DEL))
892 if ((ed->state & (ED_OPER | ED_UNLINK)))
896 dbg("dl_done_list: strange.., ED state %x, ed->state\n");
898 dbg("dl_done_list: processing TD %x, len %x\n", lurb_priv->td_cnt,
901 if (ed->state != ED_NEW) {
902 edHeadP = m32_swap (ed->hwHeadP) & 0xfffffff0;
903 edTailP = m32_swap (ed->hwTailP);
905 /* unlink eds if they are not busy */
906 if ((edHeadP == edTailP) && (ed->state == ED_OPER))
907 ep_unlink (ohci, ed);
910 td_list = td_list_next;
915 /*-------------------------------------------------------------------------*
917 *-------------------------------------------------------------------------*/
919 /* Device descriptor */
920 static __u8 root_hub_dev_des[] =
922 0x12, /* __u8 bLength; */
923 0x01, /* __u8 bDescriptorType; Device */
924 0x10, /* __u16 bcdUSB; v1.1 */
926 0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */
927 0x00, /* __u8 bDeviceSubClass; */
928 0x00, /* __u8 bDeviceProtocol; */
929 0x08, /* __u8 bMaxPacketSize0; 8 Bytes */
930 0x00, /* __u16 idVendor; */
932 0x00, /* __u16 idProduct; */
934 0x00, /* __u16 bcdDevice; */
936 0x00, /* __u8 iManufacturer; */
937 0x01, /* __u8 iProduct; */
938 0x00, /* __u8 iSerialNumber; */
939 0x01 /* __u8 bNumConfigurations; */
943 /* Configuration descriptor */
944 static __u8 root_hub_config_des[] =
946 0x09, /* __u8 bLength; */
947 0x02, /* __u8 bDescriptorType; Configuration */
948 0x19, /* __u16 wTotalLength; */
950 0x01, /* __u8 bNumInterfaces; */
951 0x01, /* __u8 bConfigurationValue; */
952 0x00, /* __u8 iConfiguration; */
953 0x40, /* __u8 bmAttributes;
954 Bit 7: Bus-powered, 6: Self-powered, 5 Remote-wakwup, 4..0: resvd */
955 0x00, /* __u8 MaxPower; */
958 0x09, /* __u8 if_bLength; */
959 0x04, /* __u8 if_bDescriptorType; Interface */
960 0x00, /* __u8 if_bInterfaceNumber; */
961 0x00, /* __u8 if_bAlternateSetting; */
962 0x01, /* __u8 if_bNumEndpoints; */
963 0x09, /* __u8 if_bInterfaceClass; HUB_CLASSCODE */
964 0x00, /* __u8 if_bInterfaceSubClass; */
965 0x00, /* __u8 if_bInterfaceProtocol; */
966 0x00, /* __u8 if_iInterface; */
969 0x07, /* __u8 ep_bLength; */
970 0x05, /* __u8 ep_bDescriptorType; Endpoint */
971 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */
972 0x03, /* __u8 ep_bmAttributes; Interrupt */
973 0x02, /* __u16 ep_wMaxPacketSize; ((MAX_ROOT_PORTS + 1) / 8 */
975 0xff /* __u8 ep_bInterval; 255 ms */
978 static unsigned char root_hub_str_index0[] =
980 0x04, /* __u8 bLength; */
981 0x03, /* __u8 bDescriptorType; String-descriptor */
982 0x09, /* __u8 lang ID */
983 0x04, /* __u8 lang ID */
986 static unsigned char root_hub_str_index1[] =
988 28, /* __u8 bLength; */
989 0x03, /* __u8 bDescriptorType; String-descriptor */
990 'O', /* __u8 Unicode */
991 0, /* __u8 Unicode */
992 'H', /* __u8 Unicode */
993 0, /* __u8 Unicode */
994 'C', /* __u8 Unicode */
995 0, /* __u8 Unicode */
996 'I', /* __u8 Unicode */
997 0, /* __u8 Unicode */
998 ' ', /* __u8 Unicode */
999 0, /* __u8 Unicode */
1000 'R', /* __u8 Unicode */
1001 0, /* __u8 Unicode */
1002 'o', /* __u8 Unicode */
1003 0, /* __u8 Unicode */
1004 'o', /* __u8 Unicode */
1005 0, /* __u8 Unicode */
1006 't', /* __u8 Unicode */
1007 0, /* __u8 Unicode */
1008 ' ', /* __u8 Unicode */
1009 0, /* __u8 Unicode */
1010 'H', /* __u8 Unicode */
1011 0, /* __u8 Unicode */
1012 'u', /* __u8 Unicode */
1013 0, /* __u8 Unicode */
1014 'b', /* __u8 Unicode */
1015 0, /* __u8 Unicode */
1018 /* Hub class-specific descriptor is constructed dynamically */
1021 /*-------------------------------------------------------------------------*/
1023 #define OK(x) len = (x); break
1025 #define WR_RH_STAT(x) {info("WR:status %#8x", (x));writel((x), &gohci.regs->roothub.status);}
1026 #define WR_RH_PORTSTAT(x) {info("WR:portstatus[%d] %#8x", wIndex-1, (x));writel((x), &gohci.regs->roothub.portstatus[wIndex-1]);}
1028 #define WR_RH_STAT(x) writel((x), &gohci.regs->roothub.status)
1029 #define WR_RH_PORTSTAT(x) writel((x), &gohci.regs->roothub.portstatus[wIndex-1])
1031 #define RD_RH_STAT roothub_status(&gohci)
1032 #define RD_RH_PORTSTAT roothub_portstatus(&gohci,wIndex-1)
1034 /* request to virtual root hub */
1036 int rh_check_port_status(ohci_t *controller)
1042 temp = roothub_a (controller);
1043 ndp = (temp & RH_A_NDP);
1044 #ifdef CONFIG_AT91C_PQFP_UHPBUG
1045 ndp = (ndp == 2) ? 1:0;
1047 for (i = 0; i < ndp; i++) {
1048 temp = roothub_portstatus (controller, i);
1049 /* check for a device disconnect */
1050 if (((temp & (RH_PS_PESC | RH_PS_CSC)) ==
1051 (RH_PS_PESC | RH_PS_CSC)) &&
1052 ((temp & RH_PS_CCS) == 0)) {
1060 static int ohci_submit_rh_msg(struct usb_device *dev, unsigned long pipe,
1061 void *buffer, int transfer_len, struct devrequest *cmd)
1063 void * data = buffer;
1064 int leni = transfer_len;
1068 __u8 *data_buf = (__u8 *)datab;
1075 urb_priv.actual_length = 0;
1076 pkt_print(dev, pipe, buffer, transfer_len, cmd, "SUB(rh)", usb_pipein(pipe));
1080 if ((pipe & PIPE_INTERRUPT) == PIPE_INTERRUPT) {
1081 info("Root-Hub submit IRQ: NOT implemented");
1085 bmRType_bReq = cmd->requesttype | (cmd->request << 8);
1086 #if defined(CONFIG_440EP) || defined(CONFIG_MPC5200)
1087 wValue = __swap_16(cmd->value);
1088 wIndex = __swap_16(cmd->index);
1089 wLength = __swap_16(cmd->length);
1091 wValue = m16_swap (cmd->value);
1092 wIndex = m16_swap (cmd->index);
1093 wLength = m16_swap (cmd->length);
1094 #endif /* CONFIG_440EP || CONFIG_MPC5200 */
1096 info("Root-Hub: adr: %2x cmd(%1x): %08x %04x %04x %04x",
1097 dev->devnum, 8, bmRType_bReq, wValue, wIndex, wLength);
1099 switch (bmRType_bReq) {
1100 /* Request Destination:
1101 without flags: Device,
1102 RH_INTERFACE: interface,
1103 RH_ENDPOINT: endpoint,
1104 RH_CLASS means HUB here,
1105 RH_OTHER | RH_CLASS almost ever means HUB_PORT here
1108 #if defined(CONFIG_440EP) || defined(CONFIG_MPC5200)
1110 *(__u16 *) data_buf = __swap_16(1); OK (2);
1111 case RH_GET_STATUS | RH_INTERFACE:
1112 *(__u16 *) data_buf = __swap_16(0); OK (2);
1113 case RH_GET_STATUS | RH_ENDPOINT:
1114 *(__u16 *) data_buf = __swap_16(0); OK (2);
1115 case RH_GET_STATUS | RH_CLASS:
1116 *(__u32 *) data_buf = __swap_32(
1117 RD_RH_STAT & ~(RH_HS_CRWE | RH_HS_DRWE));
1119 case RH_GET_STATUS | RH_OTHER | RH_CLASS:
1120 *(__u32 *) data_buf = __swap_32(RD_RH_PORTSTAT); OK (4);
1123 *(__u16 *) data_buf = m16_swap (1); OK (2);
1124 case RH_GET_STATUS | RH_INTERFACE:
1125 *(__u16 *) data_buf = m16_swap (0); OK (2);
1126 case RH_GET_STATUS | RH_ENDPOINT:
1127 *(__u16 *) data_buf = m16_swap (0); OK (2);
1128 case RH_GET_STATUS | RH_CLASS:
1129 *(__u32 *) data_buf = m32_swap (
1130 RD_RH_STAT & ~(RH_HS_CRWE | RH_HS_DRWE));
1132 case RH_GET_STATUS | RH_OTHER | RH_CLASS:
1133 *(__u32 *) data_buf = m32_swap (RD_RH_PORTSTAT); OK (4);
1134 #endif /* CONFIG_440EP || CONFIG_MPC5200 */
1136 case RH_CLEAR_FEATURE | RH_ENDPOINT:
1138 case (RH_ENDPOINT_STALL): OK (0);
1142 case RH_CLEAR_FEATURE | RH_CLASS:
1144 case RH_C_HUB_LOCAL_POWER:
1146 case (RH_C_HUB_OVER_CURRENT):
1147 WR_RH_STAT(RH_HS_OCIC); OK (0);
1151 case RH_CLEAR_FEATURE | RH_OTHER | RH_CLASS:
1153 case (RH_PORT_ENABLE):
1154 WR_RH_PORTSTAT (RH_PS_CCS ); OK (0);
1155 case (RH_PORT_SUSPEND):
1156 WR_RH_PORTSTAT (RH_PS_POCI); OK (0);
1157 case (RH_PORT_POWER):
1158 WR_RH_PORTSTAT (RH_PS_LSDA); OK (0);
1159 case (RH_C_PORT_CONNECTION):
1160 WR_RH_PORTSTAT (RH_PS_CSC ); OK (0);
1161 case (RH_C_PORT_ENABLE):
1162 WR_RH_PORTSTAT (RH_PS_PESC); OK (0);
1163 case (RH_C_PORT_SUSPEND):
1164 WR_RH_PORTSTAT (RH_PS_PSSC); OK (0);
1165 case (RH_C_PORT_OVER_CURRENT):
1166 WR_RH_PORTSTAT (RH_PS_OCIC); OK (0);
1167 case (RH_C_PORT_RESET):
1168 WR_RH_PORTSTAT (RH_PS_PRSC); OK (0);
1172 case RH_SET_FEATURE | RH_OTHER | RH_CLASS:
1174 case (RH_PORT_SUSPEND):
1175 WR_RH_PORTSTAT (RH_PS_PSS ); OK (0);
1176 case (RH_PORT_RESET): /* BUG IN HUP CODE *********/
1177 if (RD_RH_PORTSTAT & RH_PS_CCS)
1178 WR_RH_PORTSTAT (RH_PS_PRS);
1180 case (RH_PORT_POWER):
1181 WR_RH_PORTSTAT (RH_PS_PPS ); OK (0);
1182 case (RH_PORT_ENABLE): /* BUG IN HUP CODE *********/
1183 if (RD_RH_PORTSTAT & RH_PS_CCS)
1184 WR_RH_PORTSTAT (RH_PS_PES );
1189 case RH_SET_ADDRESS: gohci.rh.devnum = wValue; OK(0);
1191 case RH_GET_DESCRIPTOR:
1192 switch ((wValue & 0xff00) >> 8) {
1193 case (0x01): /* device descriptor */
1194 len = min_t(unsigned int,
1197 sizeof (root_hub_dev_des),
1199 data_buf = root_hub_dev_des; OK(len);
1200 case (0x02): /* configuration descriptor */
1201 len = min_t(unsigned int,
1204 sizeof (root_hub_config_des),
1206 data_buf = root_hub_config_des; OK(len);
1207 case (0x03): /* string descriptors */
1208 if(wValue==0x0300) {
1209 len = min_t(unsigned int,
1212 sizeof (root_hub_str_index0),
1214 data_buf = root_hub_str_index0;
1217 if(wValue==0x0301) {
1218 len = min_t(unsigned int,
1221 sizeof (root_hub_str_index1),
1223 data_buf = root_hub_str_index1;
1227 stat = USB_ST_STALLED;
1231 case RH_GET_DESCRIPTOR | RH_CLASS:
1233 __u32 temp = roothub_a (&gohci);
1235 data_buf [0] = 9; /* min length; */
1236 data_buf [1] = 0x29;
1237 data_buf [2] = temp & RH_A_NDP;
1238 #ifdef CONFIG_AT91C_PQFP_UHPBUG
1239 data_buf [2] = (data_buf [2] == 2) ? 1:0;
1242 if (temp & RH_A_PSM) /* per-port power switching? */
1243 data_buf [3] |= 0x1;
1244 if (temp & RH_A_NOCP) /* no overcurrent reporting? */
1245 data_buf [3] |= 0x10;
1246 else if (temp & RH_A_OCPM) /* per-port overcurrent reporting? */
1247 data_buf [3] |= 0x8;
1249 /* corresponds to data_buf[4-7] */
1251 data_buf [5] = (temp & RH_A_POTPGT) >> 24;
1252 temp = roothub_b (&gohci);
1253 data_buf [7] = temp & RH_B_DR;
1254 if (data_buf [2] < 7) {
1255 data_buf [8] = 0xff;
1258 data_buf [8] = (temp & RH_B_DR) >> 8;
1259 data_buf [10] = data_buf [9] = 0xff;
1262 len = min_t(unsigned int, leni,
1263 min_t(unsigned int, data_buf [0], wLength));
1267 case RH_GET_CONFIGURATION: *(__u8 *) data_buf = 0x01; OK (1);
1269 case RH_SET_CONFIGURATION: WR_RH_STAT (0x10000); OK (0);
1272 dbg ("unsupported root hub command");
1273 stat = USB_ST_STALLED;
1277 ohci_dump_roothub (&gohci, 1);
1282 len = min_t(int, len, leni);
1283 if (data != data_buf)
1284 memcpy (data, data_buf, len);
1290 urb_priv.actual_length = transfer_len;
1291 pkt_print(dev, pipe, buffer, transfer_len, cmd, "RET(rh)", 0/*usb_pipein(pipe)*/);
1299 /*-------------------------------------------------------------------------*/
1301 /* common code for handling submit messages - used for all but root hub */
1303 int submit_common_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
1304 int transfer_len, struct devrequest *setup, int interval)
1307 int maxsize = usb_maxpacket(dev, pipe);
1310 /* device pulled? Shortcut the action. */
1311 if (devgone == dev) {
1312 dev->status = USB_ST_CRC_ERR;
1317 urb_priv.actual_length = 0;
1318 pkt_print(dev, pipe, buffer, transfer_len, setup, "SUB", usb_pipein(pipe));
1323 err("submit_common_message: pipesize for pipe %lx is zero",
1328 if (sohci_submit_job(dev, pipe, buffer, transfer_len, setup, interval) < 0) {
1329 err("sohci_submit_job failed");
1335 /* ohci_dump_status(&gohci); */
1338 /* allow more time for a BULK device to react - some are slow */
1339 #define BULK_TO 5000 /* timeout in milliseconds */
1340 if (usb_pipetype (pipe) == PIPE_BULK)
1345 /* wait for it to complete */
1347 /* check whether the controller is done */
1348 stat = hc_interrupt();
1350 stat = USB_ST_CRC_ERR;
1354 #ifdef S3C24X0_merge
1355 /* NOTE: since we are not interrupt driven in U-Boot and always
1356 * handle only one URB at a time, we cannot assume the
1357 * transaction finished on the first successful return from
1358 * hc_interrupt().. unless the flag for current URB is set,
1359 * meaning that all TD's to/from device got actually
1360 * transferred and processed. If the current URB is not
1361 * finished we need to re-iterate this loop so as
1362 * hc_interrupt() gets called again as there needs to be some
1363 * more TD's to process still */
1364 if ((stat >= 0) && (stat != 0xff) && (urb_finished)) {
1366 if (stat >= 0 && stat != 0xff) {
1368 /* 0xff is returned for an SF-interrupt */
1375 err("CTL:TIMEOUT ");
1376 #ifdef S3C24X0_merge
1377 dbg("submit_common_msg: TO status %x\n", stat);
1378 stat = USB_ST_CRC_ERR;
1381 stat = USB_ST_CRC_ERR;
1385 #ifndef S3C24X0_merge
1386 /* we got an Root Hub Status Change interrupt */
1389 ohci_dump_roothub (&gohci, 1);
1393 timeout = rh_check_port_status(&gohci);
1395 #if 0 /* this does nothing useful, but leave it here in case that changes */
1396 /* the called routine adds 1 to the passed value */
1397 usb_hub_port_connect_change(gohci.rh.dev, timeout - 1);
1401 * This is potentially dangerous because it assumes
1402 * that only one device is ever plugged in!
1407 #endif /* S3C24X0_merge */
1410 dev->act_len = transfer_len;
1413 pkt_print(dev, pipe, buffer, transfer_len, setup, "RET(ctlr)", usb_pipein(pipe));
1418 /* free TDs in urb_priv */
1419 urb_free_priv (&urb_priv);
1423 /* submit routines called from usb.c */
1424 int submit_bulk_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
1427 info("submit_bulk_msg");
1428 return submit_common_msg(dev, pipe, buffer, transfer_len, NULL, 0);
1431 int submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
1432 int transfer_len, struct devrequest *setup)
1434 int maxsize = usb_maxpacket(dev, pipe);
1436 info("submit_control_msg");
1438 urb_priv.actual_length = 0;
1439 pkt_print(dev, pipe, buffer, transfer_len, setup, "SUB", usb_pipein(pipe));
1444 err("submit_control_message: pipesize for pipe %lx is zero",
1448 if (((pipe >> 8) & 0x7f) == gohci.rh.devnum) {
1450 /* root hub - redirect */
1451 return ohci_submit_rh_msg(dev, pipe, buffer, transfer_len,
1455 return submit_common_msg(dev, pipe, buffer, transfer_len, setup, 0);
1458 int submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
1459 int transfer_len, int interval)
1461 info("submit_int_msg");
1465 /*-------------------------------------------------------------------------*
1467 *-------------------------------------------------------------------------*/
1469 /* reset the HC and BUS */
1471 static int hc_reset (ohci_t *ohci)
1474 int smm_timeout = 50; /* 0,5 sec */
1476 dbg("%s\n", __FUNCTION__);
1478 if (readl (&ohci->regs->control) & OHCI_CTRL_IR) { /* SMM owns the HC */
1479 writel (OHCI_OCR, &ohci->regs->cmdstatus); /* request ownership */
1480 info("USB HC TakeOver from SMM");
1481 while (readl (&ohci->regs->control) & OHCI_CTRL_IR) {
1483 if (--smm_timeout == 0) {
1484 err("USB HC TakeOver failed!");
1490 /* Disable HC interrupts */
1491 writel (OHCI_INTR_MIE, &ohci->regs->intrdisable);
1493 dbg("USB HC reset_hc usb-%s: ctrl = 0x%X ;\n",
1495 readl(&ohci->regs->control));
1497 /* Reset USB (needed by some controllers) */
1498 ohci->hc_control = 0;
1499 writel (ohci->hc_control, &ohci->regs->control);
1501 /* HC Reset requires max 10 us delay */
1502 writel (OHCI_HCR, &ohci->regs->cmdstatus);
1503 while ((readl (&ohci->regs->cmdstatus) & OHCI_HCR) != 0) {
1504 if (--timeout == 0) {
1505 err("USB HC reset timed out!");
1513 /*-------------------------------------------------------------------------*/
1515 /* Start an OHCI controller, set the BUS operational
1517 * connect the virtual root hub */
1519 static int hc_start (ohci_t * ohci)
1522 unsigned int fminterval;
1526 /* Tell the controller where the control and bulk lists are
1527 * The lists are empty now. */
1529 writel (0, &ohci->regs->ed_controlhead);
1530 writel (0, &ohci->regs->ed_bulkhead);
1532 writel ((__u32)ohci->hcca, &ohci->regs->hcca); /* a reset clears this */
1534 fminterval = 0x2edf;
1535 writel ((fminterval * 9) / 10, &ohci->regs->periodicstart);
1536 fminterval |= ((((fminterval - 210) * 6) / 7) << 16);
1537 writel (fminterval, &ohci->regs->fminterval);
1538 writel (0x628, &ohci->regs->lsthresh);
1540 /* start controller operations */
1541 ohci->hc_control = OHCI_CONTROL_INIT | OHCI_USB_OPER;
1543 writel (ohci->hc_control, &ohci->regs->control);
1545 /* disable all interrupts */
1546 mask = (OHCI_INTR_SO | OHCI_INTR_WDH | OHCI_INTR_SF | OHCI_INTR_RD |
1547 OHCI_INTR_UE | OHCI_INTR_FNO | OHCI_INTR_RHSC |
1548 OHCI_INTR_OC | OHCI_INTR_MIE);
1549 writel (mask, &ohci->regs->intrdisable);
1550 /* clear all interrupts */
1551 mask &= ~OHCI_INTR_MIE;
1552 writel (mask, &ohci->regs->intrstatus);
1553 /* Choose the interrupts we care about now - but w/o MIE */
1554 mask = OHCI_INTR_RHSC | OHCI_INTR_UE | OHCI_INTR_WDH | OHCI_INTR_SO;
1555 writel (mask, &ohci->regs->intrenable);
1558 /* required for AMD-756 and some Mac platforms */
1559 writel ((roothub_a (ohci) | RH_A_NPS) & ~RH_A_PSM,
1560 &ohci->regs->roothub.a);
1561 writel (RH_HS_LPSC, &ohci->regs->roothub.status);
1562 #endif /* OHCI_USE_NPS */
1564 #define mdelay(n) ({unsigned long msec=(n); while (msec--) udelay(1000);})
1565 /* POTPGT delay is bits 24-31, in 2 ms units. */
1566 mdelay ((roothub_a (ohci) >> 23) & 0x1fe);
1568 /* connect the virtual root hub */
1569 ohci->rh.devnum = 0;
1574 /*-------------------------------------------------------------------------*/
1576 /* an interrupt happens */
1578 static int hc_interrupt (void)
1580 ohci_t *ohci = &gohci;
1581 struct ohci_regs *regs = ohci->regs;
1585 #ifdef S3C24X0_merge
1587 if ((ohci->hcca->done_head != 0) &&
1588 !(m32_swap (ohci->hcca->done_head) & 0x01)) {
1589 ints = OHCI_INTR_WDH;
1590 } else if ((ints = readl (®s->intrstatus)) == ~(u32)0) {
1592 err ("%s device removed!", ohci->slot_name);
1594 } else if ((ints &= readl (®s->intrenable)) == 0) {
1595 dbg("hc_interrupt: returning..\n");
1599 if ((ohci->hcca->done_head != 0) && !(m32_swap (ohci->hcca->done_head) & 0x01)) {
1600 ints = OHCI_INTR_WDH;
1602 ints = readl (®s->intrstatus);
1605 /* dbg("Interrupt: %x frame: %x", ints, le16_to_cpu (ohci->hcca->frame_no)); */
1607 if (ints & OHCI_INTR_RHSC) {
1609 #ifdef S3C24X0_merge
1614 if (ints & OHCI_INTR_UE) {
1616 err ("OHCI Unrecoverable Error, controller usb-%s disabled",
1618 /* e.g. due to PCI Master/Target Abort */
1621 ohci_dump (ohci, 1);
1625 /* FIXME: be optimistic, hope that bug won't repeat often. */
1626 /* Make some non-interrupt context restart the controller. */
1627 /* Count and limit the retries though; either hardware or */
1628 /* software errors can go forever... */
1633 if (ints & OHCI_INTR_WDH) {
1635 writel (OHCI_INTR_WDH, ®s->intrdisable);
1636 stat = dl_done_list (&gohci, dl_reverse_done_list (&gohci));
1637 writel (OHCI_INTR_WDH, ®s->intrenable);
1640 if (ints & OHCI_INTR_SO) {
1641 dbg("USB Schedule overrun\n");
1642 writel (OHCI_INTR_SO, ®s->intrenable);
1646 /* FIXME: this assumes SOF (1/ms) interrupts don't get lost... */
1647 if (ints & OHCI_INTR_SF) {
1648 unsigned int frame = m16_swap (ohci->hcca->frame_no) & 1;
1650 writel (OHCI_INTR_SF, ®s->intrdisable);
1651 if (ohci->ed_rm_list[frame] != NULL)
1652 writel (OHCI_INTR_SF, ®s->intrenable);
1656 writel (ints, ®s->intrstatus);
1660 /*-------------------------------------------------------------------------*/
1662 /*-------------------------------------------------------------------------*/
1664 /* De-allocate all resources.. */
1666 static void hc_release_ohci (ohci_t *ohci)
1668 dbg ("USB HC release ohci usb-%s", ohci->slot_name);
1670 if (!ohci->disabled)
1674 /*-------------------------------------------------------------------------*/
1677 * low level initalisation routine, called from usb.c
1679 static char ohci_inited = 0;
1681 int usb_lowlevel_init(void)
1684 #ifdef CFG_USB_OHCI_CPU_INIT
1685 /* cpu dependant init */
1690 #ifdef CFG_USB_OHCI_BOARD_INIT
1691 /* board dependant init */
1692 if(usb_board_init())
1695 memset (&gohci, 0, sizeof (ohci_t));
1696 memset (&urb_priv, 0, sizeof (urb_priv_t));
1698 /* align the storage */
1699 if ((__u32)&ghcca[0] & 0xff) {
1700 err("HCCA not aligned!!");
1704 info("aligned ghcca %p", phcca);
1705 memset(&ohci_dev, 0, sizeof(struct ohci_device));
1706 if ((__u32)&ohci_dev.ed[0] & 0x7) {
1707 err("EDs not aligned!!");
1710 memset(gtd, 0, sizeof(td_t) * (NUM_TD + 1));
1711 if ((__u32)gtd & 0x7) {
1712 err("TDs not aligned!!");
1717 memset (phcca, 0, sizeof (struct ohci_hcca));
1722 gohci.regs = (struct ohci_regs *)CFG_USB_OHCI_REGS_BASE;
1725 gohci.slot_name = CFG_USB_OHCI_SLOT_NAME;
1727 if (hc_reset (&gohci) < 0) {
1728 hc_release_ohci (&gohci);
1729 err ("can't reset usb-%s", gohci.slot_name);
1730 #ifdef CFG_USB_OHCI_BOARD_INIT
1731 /* board dependant cleanup */
1732 usb_board_init_fail();
1735 #ifdef CFG_USB_OHCI_CPU_INIT
1736 /* cpu dependant cleanup */
1737 usb_cpu_init_fail();
1742 /* FIXME this is a second HC reset; why?? */
1743 /* writel(gohci.hc_control = OHCI_USB_RESET, &gohci.regs->control);
1745 if (hc_start (&gohci) < 0) {
1746 err ("can't start usb-%s", gohci.slot_name);
1747 hc_release_ohci (&gohci);
1748 /* Initialization failed */
1749 #ifdef CFG_USB_OHCI_BOARD_INIT
1750 /* board dependant cleanup */
1754 #ifdef CFG_USB_OHCI_CPU_INIT
1755 /* cpu dependant cleanup */
1762 ohci_dump (&gohci, 1);
1765 # ifdef S3C24X0_merge
1773 int usb_lowlevel_stop(void)
1775 /* this gets called really early - before the controller has */
1776 /* even been initialized! */
1779 /* TODO release any interrupts, etc. */
1780 /* call hc_release_ohci() here ? */
1783 #ifdef CFG_USB_OHCI_BOARD_INIT
1784 /* board dependant cleanup */
1785 if(usb_board_stop())
1789 #ifdef CFG_USB_OHCI_CPU_INIT
1790 /* cpu dependant cleanup */
1797 #endif /* CONFIG_USB_OHCI_NEW */