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
48 #if defined(CONFIG_S3C2400)
50 #elif defined(CONFIG_S3C2410)
52 #elif defined(CONFIG_ARM920T)
53 # include <asm/arch/hardware.h>
54 #elif defined(CONFIG_CPU_MONAHANS)
55 # include <asm/arch/pxa-regs.h>
64 #if defined(CONFIG_ARM920T) || \
65 defined(CONFIG_S3C2400) || \
66 defined(CONFIG_S3C2410)
67 # define OHCI_USE_NPS /* force NoPowerSwitching mode */
70 #undef OHCI_VERBOSE_DEBUG /* not always helpful */
72 /* For initializing controller (mask in an HCFS mode too) */
73 #define OHCI_CONTROL_INIT \
74 (OHCI_CTRL_CBSR & 0x3) | OHCI_CTRL_IE | OHCI_CTRL_PLE
76 #define readl(a) (*((vu_long *)(a)))
77 #define writel(a, b) (*((vu_long *)(b)) = ((vu_long)a))
79 #define min_t(type,x,y) ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
83 #define dbg(format, arg...) printf("DEBUG: " format "\n", ## arg)
85 #define dbg(format, arg...) do {} while(0)
87 #define err(format, arg...) printf("ERROR: " format "\n", ## arg)
90 #define info(format, arg...) printf("INFO: " format "\n", ## arg)
92 #define info(format, arg...) do {} while(0)
95 #define m16_swap(x) swap_16(x)
96 #define m32_swap(x) swap_32(x)
100 /* this must be aligned to a 256 byte boundary */
101 struct ohci_hcca ghcca[1];
102 /* a pointer to the aligned storage */
103 struct ohci_hcca *phcca;
104 /* this allocates EDs for all possible endpoints */
105 struct ohci_device ohci_dev;
110 /* device which was disconnected */
111 struct usb_device *devgone;
114 /* flag guarding URB transation */
115 int urb_finished = 0;
119 /*-------------------------------------------------------------------------*/
121 /* AMD-756 (D2 rev) reports corrupt register contents in some cases.
122 * The erratum (#4) description is incorrect. AMD's workaround waits
123 * till some bits (mostly reserved) are clear; ok for all revs.
125 #define OHCI_QUIRK_AMD756 0xabcd
126 #define read_roothub(hc, register, mask) ({ \
127 u32 temp = readl (&hc->regs->roothub.register); \
128 if (hc->flags & OHCI_QUIRK_AMD756) \
129 while (temp & mask) \
130 temp = readl (&hc->regs->roothub.register); \
133 static u32 roothub_a (struct ohci *hc)
134 { return read_roothub (hc, a, 0xfc0fe000); }
135 static inline u32 roothub_b (struct ohci *hc)
136 { return readl (&hc->regs->roothub.b); }
137 static inline u32 roothub_status (struct ohci *hc)
138 { return readl (&hc->regs->roothub.status); }
139 static u32 roothub_portstatus (struct ohci *hc, int i)
140 { return read_roothub (hc, portstatus [i], 0xffe0fce0); }
143 /* forward declaration */
144 static int hc_interrupt (void);
146 td_submit_job (struct usb_device * dev, unsigned long pipe, void * buffer,
147 int transfer_len, struct devrequest * setup, urb_priv_t * urb, int interval);
149 /*-------------------------------------------------------------------------*
150 * URB support functions
151 *-------------------------------------------------------------------------*/
153 /* free HCD-private data associated with this URB */
155 static void urb_free_priv (urb_priv_t * urb)
161 last = urb->length - 1;
163 for (i = 0; i <= last; i++) {
173 /*-------------------------------------------------------------------------*/
176 static int sohci_get_current_frame_number (struct usb_device * dev);
178 /* debug| print the main components of an URB
179 * small: 0) header + data packets 1) just header */
181 static void pkt_print (struct usb_device * dev, unsigned long pipe, void * buffer,
182 int transfer_len, struct devrequest * setup, char * str, int small)
184 urb_priv_t * purb = &urb_priv;
186 dbg("%s URB:[%4x] dev:%2d,ep:%2d-%c,type:%s,len:%d/%d stat:%#lx",
188 sohci_get_current_frame_number (dev),
189 usb_pipedevice (pipe),
190 usb_pipeendpoint (pipe),
191 usb_pipeout (pipe)? 'O': 'I',
192 usb_pipetype (pipe) < 2? (usb_pipeint (pipe)? "INTR": "ISOC"):
193 (usb_pipecontrol (pipe)? "CTRL": "BULK"),
195 transfer_len, dev->status);
196 #ifdef OHCI_VERBOSE_DEBUG
200 if (usb_pipecontrol (pipe)) {
201 printf (__FILE__ ": cmd(8):");
202 for (i = 0; i < 8 ; i++)
203 printf (" %02x", ((__u8 *) setup) [i]);
206 if (transfer_len > 0 && buffer) {
207 printf (__FILE__ ": data(%d/%d):",
210 len = usb_pipeout (pipe)?
211 transfer_len: purb->actual_length;
212 for (i = 0; i < 16 && i < len; i++)
213 printf (" %02x", ((__u8 *) buffer) [i]);
214 printf ("%s\n", i < len? "...": "");
220 /* just for debugging; prints non-empty branches of the int ed tree inclusive iso eds*/
221 void ep_print_int_eds (ohci_t *ohci, char * str) {
224 for (i= 0; i < 32; i++) {
226 ed_p = &(ohci->hcca->int_table [i]);
229 printf (__FILE__ ": %s branch int %2d(%2x):", str, i, i);
230 while (*ed_p != 0 && j--) {
231 ed_t *ed = (ed_t *)m32_swap(ed_p);
232 printf (" ed: %4x;", ed->hwINFO);
233 ed_p = &ed->hwNextED;
239 static void ohci_dump_intr_mask (char *label, __u32 mask)
241 dbg ("%s: 0x%08x%s%s%s%s%s%s%s%s%s",
244 (mask & OHCI_INTR_MIE) ? " MIE" : "",
245 (mask & OHCI_INTR_OC) ? " OC" : "",
246 (mask & OHCI_INTR_RHSC) ? " RHSC" : "",
247 (mask & OHCI_INTR_FNO) ? " FNO" : "",
248 (mask & OHCI_INTR_UE) ? " UE" : "",
249 (mask & OHCI_INTR_RD) ? " RD" : "",
250 (mask & OHCI_INTR_SF) ? " SF" : "",
251 (mask & OHCI_INTR_WDH) ? " WDH" : "",
252 (mask & OHCI_INTR_SO) ? " SO" : ""
256 static void maybe_print_eds (char *label, __u32 value)
258 ed_t *edp = (ed_t *)value;
261 dbg ("%s %08x", label, value);
262 dbg ("%08x", edp->hwINFO);
263 dbg ("%08x", edp->hwTailP);
264 dbg ("%08x", edp->hwHeadP);
265 dbg ("%08x", edp->hwNextED);
269 static char * hcfs2string (int state)
272 case OHCI_USB_RESET: return "reset";
273 case OHCI_USB_RESUME: return "resume";
274 case OHCI_USB_OPER: return "operational";
275 case OHCI_USB_SUSPEND: return "suspend";
280 /* dump control and status registers */
281 static void ohci_dump_status (ohci_t *controller)
283 struct ohci_regs *regs = controller->regs;
286 temp = readl (®s->revision) & 0xff;
288 dbg ("spec %d.%d", (temp >> 4), (temp & 0x0f));
290 temp = readl (®s->control);
291 dbg ("control: 0x%08x%s%s%s HCFS=%s%s%s%s%s CBSR=%d", temp,
292 (temp & OHCI_CTRL_RWE) ? " RWE" : "",
293 (temp & OHCI_CTRL_RWC) ? " RWC" : "",
294 (temp & OHCI_CTRL_IR) ? " IR" : "",
295 hcfs2string (temp & OHCI_CTRL_HCFS),
296 (temp & OHCI_CTRL_BLE) ? " BLE" : "",
297 (temp & OHCI_CTRL_CLE) ? " CLE" : "",
298 (temp & OHCI_CTRL_IE) ? " IE" : "",
299 (temp & OHCI_CTRL_PLE) ? " PLE" : "",
300 temp & OHCI_CTRL_CBSR
303 temp = readl (®s->cmdstatus);
304 dbg ("cmdstatus: 0x%08x SOC=%d%s%s%s%s", temp,
305 (temp & OHCI_SOC) >> 16,
306 (temp & OHCI_OCR) ? " OCR" : "",
307 (temp & OHCI_BLF) ? " BLF" : "",
308 (temp & OHCI_CLF) ? " CLF" : "",
309 (temp & OHCI_HCR) ? " HCR" : ""
312 ohci_dump_intr_mask ("intrstatus", readl (®s->intrstatus));
313 ohci_dump_intr_mask ("intrenable", readl (®s->intrenable));
315 maybe_print_eds ("ed_periodcurrent", readl (®s->ed_periodcurrent));
317 maybe_print_eds ("ed_controlhead", readl (®s->ed_controlhead));
318 maybe_print_eds ("ed_controlcurrent", readl (®s->ed_controlcurrent));
320 maybe_print_eds ("ed_bulkhead", readl (®s->ed_bulkhead));
321 maybe_print_eds ("ed_bulkcurrent", readl (®s->ed_bulkcurrent));
323 maybe_print_eds ("donehead", readl (®s->donehead));
326 static void ohci_dump_roothub (ohci_t *controller, int verbose)
330 temp = roothub_a (controller);
331 ndp = (temp & RH_A_NDP);
332 #ifdef CONFIG_AT91C_PQFP_UHPBUG
333 ndp = (ndp == 2) ? 1:0;
336 dbg ("roothub.a: %08x POTPGT=%d%s%s%s%s%s NDP=%d", temp,
337 ((temp & RH_A_POTPGT) >> 24) & 0xff,
338 (temp & RH_A_NOCP) ? " NOCP" : "",
339 (temp & RH_A_OCPM) ? " OCPM" : "",
340 (temp & RH_A_DT) ? " DT" : "",
341 (temp & RH_A_NPS) ? " NPS" : "",
342 (temp & RH_A_PSM) ? " PSM" : "",
345 temp = roothub_b (controller);
346 dbg ("roothub.b: %08x PPCM=%04x DR=%04x",
348 (temp & RH_B_PPCM) >> 16,
351 temp = roothub_status (controller);
352 dbg ("roothub.status: %08x%s%s%s%s%s%s",
354 (temp & RH_HS_CRWE) ? " CRWE" : "",
355 (temp & RH_HS_OCIC) ? " OCIC" : "",
356 (temp & RH_HS_LPSC) ? " LPSC" : "",
357 (temp & RH_HS_DRWE) ? " DRWE" : "",
358 (temp & RH_HS_OCI) ? " OCI" : "",
359 (temp & RH_HS_LPS) ? " LPS" : ""
363 for (i = 0; i < ndp; i++) {
364 temp = roothub_portstatus (controller, i);
365 dbg ("roothub.portstatus [%d] = 0x%08x%s%s%s%s%s%s%s%s%s%s%s%s",
368 (temp & RH_PS_PRSC) ? " PRSC" : "",
369 (temp & RH_PS_OCIC) ? " OCIC" : "",
370 (temp & RH_PS_PSSC) ? " PSSC" : "",
371 (temp & RH_PS_PESC) ? " PESC" : "",
372 (temp & RH_PS_CSC) ? " CSC" : "",
374 (temp & RH_PS_LSDA) ? " LSDA" : "",
375 (temp & RH_PS_PPS) ? " PPS" : "",
376 (temp & RH_PS_PRS) ? " PRS" : "",
377 (temp & RH_PS_POCI) ? " POCI" : "",
378 (temp & RH_PS_PSS) ? " PSS" : "",
380 (temp & RH_PS_PES) ? " PES" : "",
381 (temp & RH_PS_CCS) ? " CCS" : ""
386 static void ohci_dump (ohci_t *controller, int verbose)
388 dbg ("OHCI controller usb-%s state", controller->slot_name);
390 /* dumps some of the state we know about */
391 ohci_dump_status (controller);
393 ep_print_int_eds (controller, "hcca");
394 dbg ("hcca frame #%04x", controller->hcca->frame_no);
395 ohci_dump_roothub (controller, 1);
401 /*-------------------------------------------------------------------------*
402 * Interface functions (URB)
403 *-------------------------------------------------------------------------*/
405 /* get a transfer request */
407 int sohci_submit_job(struct usb_device *dev, unsigned long pipe, void *buffer,
408 int transfer_len, struct devrequest *setup, int interval)
412 urb_priv_t *purb_priv;
417 /* when controller's hung, permit only roothub cleanup attempts
418 * such as powering down ports */
419 if (ohci->disabled) {
420 err("sohci_submit_job: EPIPE");
424 /* if we have an unfinished URB from previous transaction let's
425 * fail and scream as quickly as possible so as not to corrupt
426 * further communication */
428 err("sohci_submit_job: URB NOT FINISHED");
431 /* we're about to begin a new transaction here so mark the URB unfinished */
435 /* every endpoint has a ed, locate and fill it */
436 if (!(ed = ep_add_ed (dev, pipe))) {
437 err("sohci_submit_job: ENOMEM");
441 /* for the private part of the URB we need the number of TDs (size) */
442 switch (usb_pipetype (pipe)) {
443 case PIPE_BULK: /* one TD for every 4096 Byte */
444 size = (transfer_len - 1) / 4096 + 1;
446 case PIPE_CONTROL: /* 1 TD for setup, 1 for ACK and 1 for every 4096 B */
447 size = (transfer_len == 0)? 2:
448 (transfer_len - 1) / 4096 + 3;
452 if (size >= (N_URB_TD - 1)) {
453 err("need %d TDs, only have %d", size, N_URB_TD);
456 purb_priv = &urb_priv;
457 purb_priv->pipe = pipe;
459 /* fill the private part of the URB */
460 purb_priv->length = size;
462 purb_priv->actual_length = 0;
464 /* allocate the TDs */
465 /* note that td[0] was allocated in ep_add_ed */
466 for (i = 0; i < size; i++) {
467 purb_priv->td[i] = td_alloc (dev);
468 if (!purb_priv->td[i]) {
469 purb_priv->length = i;
470 urb_free_priv (purb_priv);
471 err("sohci_submit_job: ENOMEM");
476 if (ed->state == ED_NEW || (ed->state & ED_DEL)) {
477 urb_free_priv (purb_priv);
478 err("sohci_submit_job: EINVAL");
482 /* link the ed into a chain if is not already */
483 if (ed->state != ED_OPER)
486 /* fill the TDs and link it to the ed */
487 td_submit_job(dev, pipe, buffer, transfer_len, setup, purb_priv, interval);
492 /*-------------------------------------------------------------------------*/
495 /* tell us the current USB frame number */
497 static int sohci_get_current_frame_number (struct usb_device *usb_dev)
499 ohci_t *ohci = &gohci;
501 return m16_swap (ohci->hcca->frame_no);
505 /*-------------------------------------------------------------------------*
506 * ED handling functions
507 *-------------------------------------------------------------------------*/
509 /* link an ed into one of the HC chains */
511 static int ep_link (ohci_t *ohci, ed_t *edi)
513 volatile ed_t *ed = edi;
520 if (ohci->ed_controltail == NULL) {
521 writel (ed, &ohci->regs->ed_controlhead);
523 ohci->ed_controltail->hwNextED = m32_swap (ed);
525 ed->ed_prev = ohci->ed_controltail;
526 if (!ohci->ed_controltail && !ohci->ed_rm_list[0] &&
527 !ohci->ed_rm_list[1] && !ohci->sleeping) {
528 ohci->hc_control |= OHCI_CTRL_CLE;
529 writel (ohci->hc_control, &ohci->regs->control);
531 ohci->ed_controltail = edi;
536 if (ohci->ed_bulktail == NULL) {
537 writel (ed, &ohci->regs->ed_bulkhead);
539 ohci->ed_bulktail->hwNextED = m32_swap (ed);
541 ed->ed_prev = ohci->ed_bulktail;
542 if (!ohci->ed_bulktail && !ohci->ed_rm_list[0] &&
543 !ohci->ed_rm_list[1] && !ohci->sleeping) {
544 ohci->hc_control |= OHCI_CTRL_BLE;
545 writel (ohci->hc_control, &ohci->regs->control);
547 ohci->ed_bulktail = edi;
553 /*-------------------------------------------------------------------------*/
555 /* unlink an ed from one of the HC chains.
556 * just the link to the ed is unlinked.
557 * the link from the ed still points to another operational ed or 0
558 * so the HC can eventually finish the processing of the unlinked ed */
560 static int ep_unlink (ohci_t *ohci, ed_t *ed)
562 ed->hwINFO |= m32_swap (OHCI_ED_SKIP);
566 if (ed->ed_prev == NULL) {
568 ohci->hc_control &= ~OHCI_CTRL_CLE;
569 writel (ohci->hc_control, &ohci->regs->control);
571 writel (m32_swap (*((__u32 *)&ed->hwNextED)), &ohci->regs->ed_controlhead);
573 ed->ed_prev->hwNextED = ed->hwNextED;
575 if (ohci->ed_controltail == ed) {
576 ohci->ed_controltail = ed->ed_prev;
578 ((ed_t *)m32_swap (*((__u32 *)&ed->hwNextED)))->ed_prev = ed->ed_prev;
583 if (ed->ed_prev == NULL) {
585 ohci->hc_control &= ~OHCI_CTRL_BLE;
586 writel (ohci->hc_control, &ohci->regs->control);
588 writel (m32_swap (*((__u32 *)&ed->hwNextED)), &ohci->regs->ed_bulkhead);
590 ed->ed_prev->hwNextED = ed->hwNextED;
592 if (ohci->ed_bulktail == ed) {
593 ohci->ed_bulktail = ed->ed_prev;
595 ((ed_t *)m32_swap (*((__u32 *)&ed->hwNextED)))->ed_prev = ed->ed_prev;
599 ed->state = ED_UNLINK;
604 /*-------------------------------------------------------------------------*/
606 /* add/reinit an endpoint; this should be done once at the
607 * usb_set_configuration command, but the USB stack is a little bit
608 * stateless so we do it at every transaction if the state of the ed
609 * is ED_NEW then a dummy td is added and the state is changed to
610 * ED_UNLINK in all other cases the state is left unchanged the ed
611 * info fields are setted anyway even though most of them should not
614 static ed_t * ep_add_ed (struct usb_device *usb_dev, unsigned long pipe)
620 ed = ed_ret = &ohci_dev.ed[(usb_pipeendpoint (pipe) << 1) |
621 (usb_pipecontrol (pipe)? 0: usb_pipeout (pipe))];
623 if ((ed->state & ED_DEL) || (ed->state & ED_URB_DEL)) {
624 err("ep_add_ed: pending delete");
625 /* pending delete request */
629 if (ed->state == ED_NEW) {
630 ed->hwINFO = m32_swap (OHCI_ED_SKIP); /* skip ed */
631 /* dummy td; end of td list for ed */
632 td = td_alloc (usb_dev);
633 ed->hwTailP = m32_swap (td);
634 ed->hwHeadP = ed->hwTailP;
635 ed->state = ED_UNLINK;
636 ed->type = usb_pipetype (pipe);
640 ed->hwINFO = m32_swap (usb_pipedevice (pipe)
641 | usb_pipeendpoint (pipe) << 7
642 | (usb_pipeisoc (pipe)? 0x8000: 0)
643 | (usb_pipecontrol (pipe)? 0: (usb_pipeout (pipe)? 0x800: 0x1000))
644 | usb_pipeslow (pipe) << 13
645 | usb_maxpacket (usb_dev, pipe) << 16);
650 /*-------------------------------------------------------------------------*
651 * TD handling functions
652 *-------------------------------------------------------------------------*/
654 /* enqueue next TD for this URB (OHCI spec 5.2.8.2) */
656 static void td_fill (ohci_t *ohci, unsigned int info,
658 struct usb_device *dev, int index, urb_priv_t *urb_priv)
660 volatile td_t *td, *td_pt;
661 #ifdef OHCI_FILL_TRACE
665 if (index > urb_priv->length) {
666 err("index > length");
669 /* use this td as the next dummy */
670 td_pt = urb_priv->td [index];
673 /* fill the old dummy TD */
674 td = urb_priv->td [index] = (td_t *)(m32_swap (urb_priv->ed->hwTailP) & ~0xf);
676 td->ed = urb_priv->ed;
677 td->next_dl_td = NULL;
679 td->data = (__u32)data;
680 #ifdef OHCI_FILL_TRACE
681 if ((usb_pipetype(urb_priv->pipe) == PIPE_BULK) && usb_pipeout(urb_priv->pipe)) {
682 for (i = 0; i < len; i++)
683 printf("td->data[%d] %#2x ",i, ((unsigned char *)td->data)[i]);
690 td->hwINFO = m32_swap (info);
691 td->hwCBP = m32_swap (data);
693 td->hwBE = m32_swap (data + len - 1);
696 td->hwNextTD = m32_swap (td_pt);
697 #ifndef S3C24X0_merge
698 td->hwPSW [0] = m16_swap (((__u32)data & 0x0FFF) | 0xE000);
701 /* append to queue */
702 td->ed->hwTailP = td->hwNextTD;
705 /*-------------------------------------------------------------------------*/
707 /* prepare all TDs of a transfer */
709 static void td_submit_job (struct usb_device *dev, unsigned long pipe, void *buffer,
710 int transfer_len, struct devrequest *setup, urb_priv_t *urb, int interval)
712 ohci_t *ohci = &gohci;
713 int data_len = transfer_len;
717 unsigned int toggle = 0;
719 /* OHCI handles the DATA-toggles itself, we just use the USB-toggle bits for reseting */
720 if(usb_gettoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe))) {
721 toggle = TD_T_TOGGLE;
724 usb_settoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe), 1);
732 switch (usb_pipetype (pipe)) {
734 info = usb_pipeout (pipe)?
735 TD_CC | TD_DP_OUT : TD_CC | TD_DP_IN ;
736 while(data_len > 4096) {
737 td_fill (ohci, info | (cnt? TD_T_TOGGLE:toggle), data, 4096, dev, cnt, urb);
738 data += 4096; data_len -= 4096; cnt++;
740 info = usb_pipeout (pipe)?
741 TD_CC | TD_DP_OUT : TD_CC | TD_R | TD_DP_IN ;
742 td_fill (ohci, info | (cnt? TD_T_TOGGLE:toggle), data, data_len, dev, cnt, urb);
746 writel (OHCI_BLF, &ohci->regs->cmdstatus); /* start bulk list */
750 info = TD_CC | TD_DP_SETUP | TD_T_DATA0;
751 td_fill (ohci, info, setup, 8, dev, cnt++, urb);
753 info = usb_pipeout (pipe)?
754 TD_CC | TD_R | TD_DP_OUT | TD_T_DATA1 : TD_CC | TD_R | TD_DP_IN | TD_T_DATA1;
755 /* NOTE: mishandles transfers >8K, some >4K */
756 td_fill (ohci, info, data, data_len, dev, cnt++, urb);
758 info = usb_pipeout (pipe)?
759 TD_CC | TD_DP_IN | TD_T_DATA1: TD_CC | TD_DP_OUT | TD_T_DATA1;
760 td_fill (ohci, info, data, 0, dev, cnt++, urb);
762 writel (OHCI_CLF, &ohci->regs->cmdstatus); /* start Control list */
765 if (urb->length != cnt)
766 dbg("TD LENGTH %d != CNT %d", urb->length, cnt);
769 /*-------------------------------------------------------------------------*
770 * Done List handling functions
771 *-------------------------------------------------------------------------*/
774 /* calculate the transfer length and update the urb */
776 static void dl_transfer_length(td_t * td)
778 __u32 tdINFO, tdBE, tdCBP;
779 urb_priv_t *lurb_priv = &urb_priv;
781 tdINFO = m32_swap (td->hwINFO);
782 tdBE = m32_swap (td->hwBE);
783 tdCBP = m32_swap (td->hwCBP);
786 if (!(usb_pipetype (lurb_priv->pipe) == PIPE_CONTROL &&
787 ((td->index == 0) || (td->index == lurb_priv->length - 1)))) {
790 lurb_priv->actual_length += tdBE - td->data + 1;
792 lurb_priv->actual_length += tdCBP - td->data;
797 /*-------------------------------------------------------------------------*/
799 /* replies to the request have to be on a FIFO basis so
800 * we reverse the reversed done-list */
802 static td_t * dl_reverse_done_list (ohci_t *ohci)
806 td_t *td_list = NULL;
807 urb_priv_t *lurb_priv = NULL;
809 td_list_hc = m32_swap (ohci->hcca->done_head) & 0xfffffff0;
810 ohci->hcca->done_head = 0;
813 td_list = (td_t *)td_list_hc;
815 if (TD_CC_GET (m32_swap (td_list->hwINFO))) {
816 lurb_priv = &urb_priv;
817 dbg(" USB-error/status: %x : %p",
818 TD_CC_GET (m32_swap (td_list->hwINFO)), td_list);
819 if (td_list->ed->hwHeadP & m32_swap (0x1)) {
820 if (lurb_priv && ((td_list->index + 1) < lurb_priv->length)) {
821 td_list->ed->hwHeadP =
822 (lurb_priv->td[lurb_priv->length - 1]->hwNextTD & m32_swap (0xfffffff0)) |
823 (td_list->ed->hwHeadP & m32_swap (0x2));
824 lurb_priv->td_cnt += lurb_priv->length - td_list->index - 1;
826 td_list->ed->hwHeadP &= m32_swap (0xfffffff2);
830 td_list->next_dl_td = td_rev;
832 td_list_hc = m32_swap (td_list->hwNextTD) & 0xfffffff0;
837 /*-------------------------------------------------------------------------*/
840 static int dl_done_list (ohci_t *ohci, td_t *td_list)
842 td_t *td_list_next = NULL;
847 urb_priv_t *lurb_priv;
848 __u32 tdINFO, edHeadP, edTailP;
851 td_list_next = td_list->next_dl_td;
853 lurb_priv = &urb_priv;
854 tdINFO = m32_swap (td_list->hwINFO);
858 dl_transfer_length(td_list);
860 /* error code of transfer */
861 cc = TD_CC_GET (tdINFO);
863 dbg("ConditionCode %#x", cc);
864 stat = cc_to_error[cc];
867 /* see if this done list makes for all TD's of current URB,
868 * and mark the URB finished if so */
869 if (++(lurb_priv->td_cnt) == lurb_priv->length) {
870 if ((ed->state & (ED_OPER | ED_UNLINK)))
873 dbg("dl_done_list: strange.., ED state %x, ed->state\n");
875 dbg("dl_done_list: processing TD %x, len %x\n", lurb_priv->td_cnt,
878 if (ed->state != ED_NEW) {
879 edHeadP = m32_swap (ed->hwHeadP) & 0xfffffff0;
880 edTailP = m32_swap (ed->hwTailP);
882 /* unlink eds if they are not busy */
883 if ((edHeadP == edTailP) && (ed->state == ED_OPER))
884 ep_unlink (ohci, ed);
887 td_list = td_list_next;
892 /*-------------------------------------------------------------------------*
894 *-------------------------------------------------------------------------*/
896 /* Device descriptor */
897 static __u8 root_hub_dev_des[] =
899 0x12, /* __u8 bLength; */
900 0x01, /* __u8 bDescriptorType; Device */
901 0x10, /* __u16 bcdUSB; v1.1 */
903 0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */
904 0x00, /* __u8 bDeviceSubClass; */
905 0x00, /* __u8 bDeviceProtocol; */
906 0x08, /* __u8 bMaxPacketSize0; 8 Bytes */
907 0x00, /* __u16 idVendor; */
909 0x00, /* __u16 idProduct; */
911 0x00, /* __u16 bcdDevice; */
913 0x00, /* __u8 iManufacturer; */
914 0x01, /* __u8 iProduct; */
915 0x00, /* __u8 iSerialNumber; */
916 0x01 /* __u8 bNumConfigurations; */
920 /* Configuration descriptor */
921 static __u8 root_hub_config_des[] =
923 0x09, /* __u8 bLength; */
924 0x02, /* __u8 bDescriptorType; Configuration */
925 0x19, /* __u16 wTotalLength; */
927 0x01, /* __u8 bNumInterfaces; */
928 0x01, /* __u8 bConfigurationValue; */
929 0x00, /* __u8 iConfiguration; */
930 0x40, /* __u8 bmAttributes;
931 Bit 7: Bus-powered, 6: Self-powered, 5 Remote-wakwup, 4..0: resvd */
932 0x00, /* __u8 MaxPower; */
935 0x09, /* __u8 if_bLength; */
936 0x04, /* __u8 if_bDescriptorType; Interface */
937 0x00, /* __u8 if_bInterfaceNumber; */
938 0x00, /* __u8 if_bAlternateSetting; */
939 0x01, /* __u8 if_bNumEndpoints; */
940 0x09, /* __u8 if_bInterfaceClass; HUB_CLASSCODE */
941 0x00, /* __u8 if_bInterfaceSubClass; */
942 0x00, /* __u8 if_bInterfaceProtocol; */
943 0x00, /* __u8 if_iInterface; */
946 0x07, /* __u8 ep_bLength; */
947 0x05, /* __u8 ep_bDescriptorType; Endpoint */
948 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */
949 0x03, /* __u8 ep_bmAttributes; Interrupt */
950 0x02, /* __u16 ep_wMaxPacketSize; ((MAX_ROOT_PORTS + 1) / 8 */
952 0xff /* __u8 ep_bInterval; 255 ms */
955 static unsigned char root_hub_str_index0[] =
957 0x04, /* __u8 bLength; */
958 0x03, /* __u8 bDescriptorType; String-descriptor */
959 0x09, /* __u8 lang ID */
960 0x04, /* __u8 lang ID */
963 static unsigned char root_hub_str_index1[] =
965 28, /* __u8 bLength; */
966 0x03, /* __u8 bDescriptorType; String-descriptor */
967 'O', /* __u8 Unicode */
968 0, /* __u8 Unicode */
969 'H', /* __u8 Unicode */
970 0, /* __u8 Unicode */
971 'C', /* __u8 Unicode */
972 0, /* __u8 Unicode */
973 'I', /* __u8 Unicode */
974 0, /* __u8 Unicode */
975 ' ', /* __u8 Unicode */
976 0, /* __u8 Unicode */
977 'R', /* __u8 Unicode */
978 0, /* __u8 Unicode */
979 'o', /* __u8 Unicode */
980 0, /* __u8 Unicode */
981 'o', /* __u8 Unicode */
982 0, /* __u8 Unicode */
983 't', /* __u8 Unicode */
984 0, /* __u8 Unicode */
985 ' ', /* __u8 Unicode */
986 0, /* __u8 Unicode */
987 'H', /* __u8 Unicode */
988 0, /* __u8 Unicode */
989 'u', /* __u8 Unicode */
990 0, /* __u8 Unicode */
991 'b', /* __u8 Unicode */
992 0, /* __u8 Unicode */
995 /* Hub class-specific descriptor is constructed dynamically */
998 /*-------------------------------------------------------------------------*/
1000 #define OK(x) len = (x); break
1002 #define WR_RH_STAT(x) {info("WR:status %#8x", (x));writel((x), &gohci.regs->roothub.status);}
1003 #define WR_RH_PORTSTAT(x) {info("WR:portstatus[%d] %#8x", wIndex-1, (x));writel((x), &gohci.regs->roothub.portstatus[wIndex-1]);}
1005 #define WR_RH_STAT(x) writel((x), &gohci.regs->roothub.status)
1006 #define WR_RH_PORTSTAT(x) writel((x), &gohci.regs->roothub.portstatus[wIndex-1])
1008 #define RD_RH_STAT roothub_status(&gohci)
1009 #define RD_RH_PORTSTAT roothub_portstatus(&gohci,wIndex-1)
1011 /* request to virtual root hub */
1013 int rh_check_port_status(ohci_t *controller)
1019 temp = roothub_a (controller);
1020 ndp = (temp & RH_A_NDP);
1021 #ifdef CONFIG_AT91C_PQFP_UHPBUG
1022 ndp = (ndp == 2) ? 1:0;
1024 for (i = 0; i < ndp; i++) {
1025 temp = roothub_portstatus (controller, i);
1026 /* check for a device disconnect */
1027 if (((temp & (RH_PS_PESC | RH_PS_CSC)) ==
1028 (RH_PS_PESC | RH_PS_CSC)) &&
1029 ((temp & RH_PS_CCS) == 0)) {
1037 static int ohci_submit_rh_msg(struct usb_device *dev, unsigned long pipe,
1038 void *buffer, int transfer_len, struct devrequest *cmd)
1040 void * data = buffer;
1041 int leni = transfer_len;
1045 __u8 *data_buf = (__u8 *)datab;
1052 urb_priv.actual_length = 0;
1053 pkt_print(dev, pipe, buffer, transfer_len, cmd, "SUB(rh)", usb_pipein(pipe));
1057 if ((pipe & PIPE_INTERRUPT) == PIPE_INTERRUPT) {
1058 info("Root-Hub submit IRQ: NOT implemented");
1062 bmRType_bReq = cmd->requesttype | (cmd->request << 8);
1063 wValue = m16_swap (cmd->value);
1064 wIndex = m16_swap (cmd->index);
1065 wLength = m16_swap (cmd->length);
1067 info("Root-Hub: adr: %2x cmd(%1x): %08x %04x %04x %04x",
1068 dev->devnum, 8, bmRType_bReq, wValue, wIndex, wLength);
1070 switch (bmRType_bReq) {
1071 /* Request Destination:
1072 without flags: Device,
1073 RH_INTERFACE: interface,
1074 RH_ENDPOINT: endpoint,
1075 RH_CLASS means HUB here,
1076 RH_OTHER | RH_CLASS almost ever means HUB_PORT here
1080 *(__u16 *) data_buf = m16_swap (1); OK (2);
1081 case RH_GET_STATUS | RH_INTERFACE:
1082 *(__u16 *) data_buf = m16_swap (0); OK (2);
1083 case RH_GET_STATUS | RH_ENDPOINT:
1084 *(__u16 *) data_buf = m16_swap (0); OK (2);
1085 case RH_GET_STATUS | RH_CLASS:
1086 *(__u32 *) data_buf = m32_swap (
1087 RD_RH_STAT & ~(RH_HS_CRWE | RH_HS_DRWE));
1089 case RH_GET_STATUS | RH_OTHER | RH_CLASS:
1090 *(__u32 *) data_buf = m32_swap (RD_RH_PORTSTAT); OK (4);
1092 case RH_CLEAR_FEATURE | RH_ENDPOINT:
1094 case (RH_ENDPOINT_STALL): OK (0);
1098 case RH_CLEAR_FEATURE | RH_CLASS:
1100 case RH_C_HUB_LOCAL_POWER:
1102 case (RH_C_HUB_OVER_CURRENT):
1103 WR_RH_STAT(RH_HS_OCIC); OK (0);
1107 case RH_CLEAR_FEATURE | RH_OTHER | RH_CLASS:
1109 case (RH_PORT_ENABLE):
1110 WR_RH_PORTSTAT (RH_PS_CCS ); OK (0);
1111 case (RH_PORT_SUSPEND):
1112 WR_RH_PORTSTAT (RH_PS_POCI); OK (0);
1113 case (RH_PORT_POWER):
1114 WR_RH_PORTSTAT (RH_PS_LSDA); OK (0);
1115 case (RH_C_PORT_CONNECTION):
1116 WR_RH_PORTSTAT (RH_PS_CSC ); OK (0);
1117 case (RH_C_PORT_ENABLE):
1118 WR_RH_PORTSTAT (RH_PS_PESC); OK (0);
1119 case (RH_C_PORT_SUSPEND):
1120 WR_RH_PORTSTAT (RH_PS_PSSC); OK (0);
1121 case (RH_C_PORT_OVER_CURRENT):
1122 WR_RH_PORTSTAT (RH_PS_OCIC); OK (0);
1123 case (RH_C_PORT_RESET):
1124 WR_RH_PORTSTAT (RH_PS_PRSC); OK (0);
1128 case RH_SET_FEATURE | RH_OTHER | RH_CLASS:
1130 case (RH_PORT_SUSPEND):
1131 WR_RH_PORTSTAT (RH_PS_PSS ); OK (0);
1132 case (RH_PORT_RESET): /* BUG IN HUP CODE *********/
1133 if (RD_RH_PORTSTAT & RH_PS_CCS)
1134 WR_RH_PORTSTAT (RH_PS_PRS);
1136 case (RH_PORT_POWER):
1137 WR_RH_PORTSTAT (RH_PS_PPS ); OK (0);
1138 case (RH_PORT_ENABLE): /* BUG IN HUP CODE *********/
1139 if (RD_RH_PORTSTAT & RH_PS_CCS)
1140 WR_RH_PORTSTAT (RH_PS_PES );
1145 case RH_SET_ADDRESS: gohci.rh.devnum = wValue; OK(0);
1147 case RH_GET_DESCRIPTOR:
1148 switch ((wValue & 0xff00) >> 8) {
1149 case (0x01): /* device descriptor */
1150 len = min_t(unsigned int,
1153 sizeof (root_hub_dev_des),
1155 data_buf = root_hub_dev_des; OK(len);
1156 case (0x02): /* configuration descriptor */
1157 len = min_t(unsigned int,
1160 sizeof (root_hub_config_des),
1162 data_buf = root_hub_config_des; OK(len);
1163 case (0x03): /* string descriptors */
1164 if(wValue==0x0300) {
1165 len = min_t(unsigned int,
1168 sizeof (root_hub_str_index0),
1170 data_buf = root_hub_str_index0;
1173 if(wValue==0x0301) {
1174 len = min_t(unsigned int,
1177 sizeof (root_hub_str_index1),
1179 data_buf = root_hub_str_index1;
1183 stat = USB_ST_STALLED;
1187 case RH_GET_DESCRIPTOR | RH_CLASS:
1189 __u32 temp = roothub_a (&gohci);
1191 data_buf [0] = 9; /* min length; */
1192 data_buf [1] = 0x29;
1193 data_buf [2] = temp & RH_A_NDP;
1194 #ifdef CONFIG_AT91C_PQFP_UHPBUG
1195 data_buf [2] = (data_buf [2] == 2) ? 1:0;
1198 if (temp & RH_A_PSM) /* per-port power switching? */
1199 data_buf [3] |= 0x1;
1200 if (temp & RH_A_NOCP) /* no overcurrent reporting? */
1201 data_buf [3] |= 0x10;
1202 else if (temp & RH_A_OCPM) /* per-port overcurrent reporting? */
1203 data_buf [3] |= 0x8;
1205 /* corresponds to data_buf[4-7] */
1207 data_buf [5] = (temp & RH_A_POTPGT) >> 24;
1208 temp = roothub_b (&gohci);
1209 data_buf [7] = temp & RH_B_DR;
1210 if (data_buf [2] < 7) {
1211 data_buf [8] = 0xff;
1214 data_buf [8] = (temp & RH_B_DR) >> 8;
1215 data_buf [10] = data_buf [9] = 0xff;
1218 len = min_t(unsigned int, leni,
1219 min_t(unsigned int, data_buf [0], wLength));
1223 case RH_GET_CONFIGURATION: *(__u8 *) data_buf = 0x01; OK (1);
1225 case RH_SET_CONFIGURATION: WR_RH_STAT (0x10000); OK (0);
1228 dbg ("unsupported root hub command");
1229 stat = USB_ST_STALLED;
1233 ohci_dump_roothub (&gohci, 1);
1238 len = min_t(int, len, leni);
1239 if (data != data_buf)
1240 memcpy (data, data_buf, len);
1246 urb_priv.actual_length = transfer_len;
1247 pkt_print(dev, pipe, buffer, transfer_len, cmd, "RET(rh)", 0/*usb_pipein(pipe)*/);
1255 /*-------------------------------------------------------------------------*/
1257 /* common code for handling submit messages - used for all but root hub */
1259 int submit_common_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
1260 int transfer_len, struct devrequest *setup, int interval)
1263 int maxsize = usb_maxpacket(dev, pipe);
1266 /* device pulled? Shortcut the action. */
1267 if (devgone == dev) {
1268 dev->status = USB_ST_CRC_ERR;
1273 urb_priv.actual_length = 0;
1274 pkt_print(dev, pipe, buffer, transfer_len, setup, "SUB", usb_pipein(pipe));
1279 err("submit_common_message: pipesize for pipe %lx is zero",
1284 if (sohci_submit_job(dev, pipe, buffer, transfer_len, setup, interval) < 0) {
1285 err("sohci_submit_job failed");
1290 /* ohci_dump_status(&gohci); */
1292 /* allow more time for a BULK device to react - some are slow */
1293 #define BULK_TO 5000 /* timeout in milliseconds */
1294 if (usb_pipetype (pipe) == PIPE_BULK)
1299 /* wait for it to complete */
1301 /* check whether the controller is done */
1302 stat = hc_interrupt();
1304 stat = USB_ST_CRC_ERR;
1308 #ifdef S3C24X0_merge
1309 /* NOTE: since we are not interrupt driven in U-Boot and always
1310 * handle only one URB at a time, we cannot assume the
1311 * transaction finished on the first successful return from
1312 * hc_interrupt().. unless the flag for current URB is set,
1313 * meaning that all TD's to/from device got actually
1314 * transferred and processed. If the current URB is not
1315 * finished we need to re-iterate this loop so as
1316 * hc_interrupt() gets called again as there needs to be some
1317 * more TD's to process still */
1318 if ((stat >= 0) && (stat != 0xff) && (urb_finished)) {
1320 if (stat >= 0 && stat != 0xff) {
1322 /* 0xff is returned for an SF-interrupt */
1329 err("CTL:TIMEOUT ");
1330 #ifdef S3C24X0_merge
1331 dbg("submit_common_msg: TO status %x\n", stat);
1334 stat = USB_ST_CRC_ERR;
1338 #ifndef S3C24X0_merge
1339 /* we got an Root Hub Status Change interrupt */
1342 ohci_dump_roothub (&gohci, 1);
1346 timeout = rh_check_port_status(&gohci);
1348 #if 0 /* this does nothing useful, but leave it here in case that changes */
1349 /* the called routine adds 1 to the passed value */
1350 usb_hub_port_connect_change(gohci.rh.dev, timeout - 1);
1354 * This is potentially dangerous because it assumes
1355 * that only one device is ever plugged in!
1360 #endif /* S3C24X0_merge */
1363 dev->act_len = transfer_len;
1366 pkt_print(dev, pipe, buffer, transfer_len, setup, "RET(ctlr)", usb_pipein(pipe));
1371 /* free TDs in urb_priv */
1372 urb_free_priv (&urb_priv);
1376 /* submit routines called from usb.c */
1377 int submit_bulk_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
1380 info("submit_bulk_msg");
1381 return submit_common_msg(dev, pipe, buffer, transfer_len, NULL, 0);
1384 int submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
1385 int transfer_len, struct devrequest *setup)
1387 int maxsize = usb_maxpacket(dev, pipe);
1389 info("submit_control_msg");
1391 urb_priv.actual_length = 0;
1392 pkt_print(dev, pipe, buffer, transfer_len, setup, "SUB", usb_pipein(pipe));
1397 err("submit_control_message: pipesize for pipe %lx is zero",
1401 if (((pipe >> 8) & 0x7f) == gohci.rh.devnum) {
1403 /* root hub - redirect */
1404 return ohci_submit_rh_msg(dev, pipe, buffer, transfer_len,
1408 return submit_common_msg(dev, pipe, buffer, transfer_len, setup, 0);
1411 int submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
1412 int transfer_len, int interval)
1414 info("submit_int_msg");
1418 /*-------------------------------------------------------------------------*
1420 *-------------------------------------------------------------------------*/
1422 /* reset the HC and BUS */
1424 static int hc_reset (ohci_t *ohci)
1427 int smm_timeout = 50; /* 0,5 sec */
1429 dbg("%s\n", __FUNCTION__);
1431 if (readl (&ohci->regs->control) & OHCI_CTRL_IR) { /* SMM owns the HC */
1432 writel (OHCI_OCR, &ohci->regs->cmdstatus); /* request ownership */
1433 info("USB HC TakeOver from SMM");
1434 while (readl (&ohci->regs->control) & OHCI_CTRL_IR) {
1436 if (--smm_timeout == 0) {
1437 err("USB HC TakeOver failed!");
1443 /* Disable HC interrupts */
1444 writel (OHCI_INTR_MIE, &ohci->regs->intrdisable);
1446 dbg("USB HC reset_hc usb-%s: ctrl = 0x%X ;\n",
1448 readl(&ohci->regs->control));
1450 /* Reset USB (needed by some controllers) */
1451 writel (0, &ohci->regs->control);
1453 /* HC Reset requires max 10 us delay */
1454 writel (OHCI_HCR, &ohci->regs->cmdstatus);
1455 while ((readl (&ohci->regs->cmdstatus) & OHCI_HCR) != 0) {
1456 if (--timeout == 0) {
1457 err("USB HC reset timed out!");
1465 /*-------------------------------------------------------------------------*/
1467 /* Start an OHCI controller, set the BUS operational
1469 * connect the virtual root hub */
1471 static int hc_start (ohci_t * ohci)
1474 unsigned int fminterval;
1478 /* Tell the controller where the control and bulk lists are
1479 * The lists are empty now. */
1481 writel (0, &ohci->regs->ed_controlhead);
1482 writel (0, &ohci->regs->ed_bulkhead);
1484 writel ((__u32)ohci->hcca, &ohci->regs->hcca); /* a reset clears this */
1486 fminterval = 0x2edf;
1487 writel ((fminterval * 9) / 10, &ohci->regs->periodicstart);
1488 fminterval |= ((((fminterval - 210) * 6) / 7) << 16);
1489 writel (fminterval, &ohci->regs->fminterval);
1490 writel (0x628, &ohci->regs->lsthresh);
1492 /* start controller operations */
1493 ohci->hc_control = OHCI_CONTROL_INIT | OHCI_USB_OPER;
1495 writel (ohci->hc_control, &ohci->regs->control);
1497 /* disable all interrupts */
1498 mask = (OHCI_INTR_SO | OHCI_INTR_WDH | OHCI_INTR_SF | OHCI_INTR_RD |
1499 OHCI_INTR_UE | OHCI_INTR_FNO | OHCI_INTR_RHSC |
1500 OHCI_INTR_OC | OHCI_INTR_MIE);
1501 writel (mask, &ohci->regs->intrdisable);
1502 /* clear all interrupts */
1503 mask &= ~OHCI_INTR_MIE;
1504 writel (mask, &ohci->regs->intrstatus);
1505 /* Choose the interrupts we care about now - but w/o MIE */
1506 mask = OHCI_INTR_RHSC | OHCI_INTR_UE | OHCI_INTR_WDH | OHCI_INTR_SO;
1507 writel (mask, &ohci->regs->intrenable);
1510 /* required for AMD-756 and some Mac platforms */
1511 writel ((roothub_a (ohci) | RH_A_NPS) & ~RH_A_PSM,
1512 &ohci->regs->roothub.a);
1513 writel (RH_HS_LPSC, &ohci->regs->roothub.status);
1514 #endif /* OHCI_USE_NPS */
1516 #define mdelay(n) ({unsigned long msec=(n); while (msec--) udelay(1000);})
1517 /* POTPGT delay is bits 24-31, in 2 ms units. */
1518 mdelay ((roothub_a (ohci) >> 23) & 0x1fe);
1520 /* connect the virtual root hub */
1521 ohci->rh.devnum = 0;
1526 /*-------------------------------------------------------------------------*/
1528 /* an interrupt happens */
1530 static int hc_interrupt (void)
1532 ohci_t *ohci = &gohci;
1533 struct ohci_regs *regs = ohci->regs;
1537 #ifdef S3C24X0_merge
1539 if ((ohci->hcca->done_head != 0) &&
1540 !(m32_swap (ohci->hcca->done_head) & 0x01)) {
1541 ints = OHCI_INTR_WDH;
1542 } else if ((ints = readl (®s->intrstatus)) == ~(u32)0) {
1544 err ("%s device removed!", ohci->slot_name);
1546 } else if ((ints &= readl (®s->intrenable)) == 0) {
1547 dbg("hc_interrupt: returning..\n");
1551 if ((ohci->hcca->done_head != 0) && !(m32_swap (ohci->hcca->done_head) & 0x01)) {
1552 ints = OHCI_INTR_WDH;
1554 ints = readl (®s->intrstatus);
1557 /* dbg("Interrupt: %x frame: %x", ints, le16_to_cpu (ohci->hcca->frame_no)); */
1559 if (ints & OHCI_INTR_RHSC) {
1561 #ifdef S3C24X0_merge
1566 if (ints & OHCI_INTR_UE) {
1568 err ("OHCI Unrecoverable Error, controller usb-%s disabled",
1570 /* e.g. due to PCI Master/Target Abort */
1573 ohci_dump (ohci, 1);
1577 /* FIXME: be optimistic, hope that bug won't repeat often. */
1578 /* Make some non-interrupt context restart the controller. */
1579 /* Count and limit the retries though; either hardware or */
1580 /* software errors can go forever... */
1585 if (ints & OHCI_INTR_WDH) {
1587 writel (OHCI_INTR_WDH, ®s->intrdisable);
1588 stat = dl_done_list (&gohci, dl_reverse_done_list (&gohci));
1589 writel (OHCI_INTR_WDH, ®s->intrenable);
1592 if (ints & OHCI_INTR_SO) {
1593 dbg("USB Schedule overrun\n");
1594 writel (OHCI_INTR_SO, ®s->intrenable);
1598 /* FIXME: this assumes SOF (1/ms) interrupts don't get lost... */
1599 if (ints & OHCI_INTR_SF) {
1600 unsigned int frame = m16_swap (ohci->hcca->frame_no) & 1;
1602 writel (OHCI_INTR_SF, ®s->intrdisable);
1603 if (ohci->ed_rm_list[frame] != NULL)
1604 writel (OHCI_INTR_SF, ®s->intrenable);
1608 writel (ints, ®s->intrstatus);
1612 /*-------------------------------------------------------------------------*/
1614 /*-------------------------------------------------------------------------*/
1616 /* De-allocate all resources.. */
1618 static void hc_release_ohci (ohci_t *ohci)
1620 dbg ("USB HC release ohci usb-%s", ohci->slot_name);
1622 if (!ohci->disabled)
1626 /*-------------------------------------------------------------------------*/
1629 * low level initalisation routine, called from usb.c
1631 static char ohci_inited = 0;
1633 int usb_lowlevel_init(void)
1636 #ifdef CFG_USB_OHCI_CPU_INIT
1637 /* cpu dependant init */
1642 #ifdef CFG_USB_OHCI_BOARD_INIT
1643 /* board dependant init */
1644 if(usb_board_init())
1647 memset (&gohci, 0, sizeof (ohci_t));
1648 memset (&urb_priv, 0, sizeof (urb_priv_t));
1650 /* align the storage */
1651 if ((__u32)&ghcca[0] & 0xff) {
1652 err("HCCA not aligned!!");
1656 info("aligned ghcca %p", phcca);
1657 memset(&ohci_dev, 0, sizeof(struct ohci_device));
1658 if ((__u32)&ohci_dev.ed[0] & 0x7) {
1659 err("EDs not aligned!!");
1662 memset(gtd, 0, sizeof(td_t) * (NUM_TD + 1));
1663 if ((__u32)gtd & 0x7) {
1664 err("TDs not aligned!!");
1669 memset (phcca, 0, sizeof (struct ohci_hcca));
1674 gohci.regs = (struct ohci_regs *)CFG_USB_OHCI_REGS_BASE;
1677 gohci.slot_name = CFG_USB_OHCI_SLOT_NAME;
1679 if (hc_reset (&gohci) < 0) {
1680 hc_release_ohci (&gohci);
1681 err ("can't reset usb-%s", gohci.slot_name);
1682 #ifdef CFG_USB_OHCI_BOARD_INIT
1683 /* board dependant cleanup */
1684 usb_board_init_fail();
1687 #ifdef CFG_USB_OHCI_CPU_INIT
1688 /* cpu dependant cleanup */
1689 usb_cpu_init_fail();
1694 /* FIXME this is a second HC reset; why?? */
1695 /* writel(gohci.hc_control = OHCI_USB_RESET, &gohci.regs->control);
1697 if (hc_start (&gohci) < 0) {
1698 err ("can't start usb-%s", gohci.slot_name);
1699 hc_release_ohci (&gohci);
1700 /* Initialization failed */
1701 #ifdef CFG_USB_OHCI_BOARD_INIT
1702 /* board dependant cleanup */
1706 #ifdef CFG_USB_OHCI_CPU_INIT
1707 /* cpu dependant cleanup */
1714 ohci_dump (&gohci, 1);
1717 # ifdef S3C24X0_merge
1725 int usb_lowlevel_stop(void)
1727 /* this gets called really early - before the controller has */
1728 /* even been initialized! */
1731 /* TODO release any interrupts, etc. */
1732 /* call hc_release_ohci() here ? */
1735 #ifdef CFG_USB_OHCI_BOARD_INIT
1736 /* board dependant cleanup */
1737 if(usb_board_stop())
1741 #ifdef CFG_USB_OHCI_CPU_INIT
1742 /* cpu dependant cleanup */
1750 #endif /* CONFIG_USB_OHCI */