2 * URB OHCI HCD (Host Controller Driver) for USB on the S3C2400.
5 * Gary Jennejohn, DENX Software Engineering <garyj@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 * See file CREDITS for list of people who contributed to this
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of
17 * the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 * 1 - this driver is intended for use with USB Mass Storage Devices
33 * (BBB) ONLY. There is NO support for Interrupt or Isochronous pipes!
37 /* #include <pci.h> no PCI on the S3C24X0 */
39 #ifdef CONFIG_USB_OHCI
41 #if defined(CONFIG_S3C2400)
42 #include <asm/arch/s3c2400.h>
43 #elif defined(CONFIG_S3C2410)
44 #include <asm/arch/s3c2410.h>
52 #define OHCI_USE_NPS /* force NoPowerSwitching mode */
53 #undef OHCI_VERBOSE_DEBUG /* not always helpful */
56 /* For initializing controller (mask in an HCFS mode too) */
57 #define OHCI_CONTROL_INIT \
58 (OHCI_CTRL_CBSR & 0x3) | OHCI_CTRL_IE | OHCI_CTRL_PLE
60 #define min_t(type, x, y) \
61 ({ type __x = (x); type __y = (y); __x < __y ? __x : __y; })
65 #define dbg(format, arg...) printf("DEBUG: " format "\n", ## arg)
67 #define dbg(format, arg...) do {} while(0)
69 #define err(format, arg...) printf("ERROR: " format "\n", ## arg)
72 #define info(format, arg...) printf("INFO: " format "\n", ## arg)
74 #define info(format, arg...) do {} while(0)
77 #define m16_swap(x) swap_16(x)
78 #define m32_swap(x) swap_32(x)
80 /* global struct ohci */
81 static struct ohci gohci;
82 /* this must be aligned to a 256 byte boundary */
83 struct ohci_hcca ghcca[1];
84 /* a pointer to the aligned storage */
85 struct ohci_hcca *phcca;
86 /* this allocates EDs for all possible endpoints */
87 struct ohci_device ohci_dev;
89 struct urb_priv urb_priv;
92 /* device which was disconnected */
93 struct usb_device *devgone;
94 /* flag guarding URB transation */
97 /*-------------------------------------------------------------------------*/
99 /* AMD-756 (D2 rev) reports corrupt register contents in some cases.
100 * The erratum (#4) description is incorrect. AMD's workaround waits
101 * till some bits (mostly reserved) are clear; ok for all revs.
103 #define OHCI_QUIRK_AMD756 0xabcd
104 #define read_roothub(hc, register, mask) ({ \
105 u32 temp = readl (&hc->regs->roothub.register); \
106 if (hc->flags & OHCI_QUIRK_AMD756) \
107 while (temp & mask) \
108 temp = readl (&hc->regs->roothub.register); \
111 static u32 roothub_a(struct ohci *hc)
113 return read_roothub(hc, a, 0xfc0fe000);
115 static inline u32 roothub_b(struct ohci *hc)
117 return readl(&hc->regs->roothub.b);
119 static inline u32 roothub_status(struct ohci *hc)
121 return readl(&hc->regs->roothub.status);
123 static u32 roothub_portstatus(struct ohci *hc, int i)
125 return read_roothub(hc, portstatus[i], 0xffe0fce0);
128 /* forward declaration */
129 static int hc_interrupt(void);
130 static void td_submit_job(struct usb_device *dev, unsigned long pipe,
131 void *buffer, int transfer_len,
132 struct devrequest *setup, struct urb_priv *urb,
135 /*-------------------------------------------------------------------------*
136 * URB support functions
137 *-------------------------------------------------------------------------*/
139 /* free HCD-private data associated with this URB */
141 static void urb_free_priv(struct urb_priv *urb)
147 last = urb->length - 1;
149 for (i = 0; i <= last; i++) {
159 /*-------------------------------------------------------------------------*/
162 static int sohci_get_current_frame_number(struct usb_device *dev);
164 /* debug| print the main components of an URB
165 * small: 0) header + data packets 1) just header */
167 static void pkt_print(struct usb_device *dev, unsigned long pipe, void *buffer,
168 int transfer_len, struct devrequest *setup, char *str,
171 struct urb_priv *purb = &urb_priv;
173 dbg("%s URB:[%4x] dev:%2d,ep:%2d-%c,type:%s,len:%d/%d stat:%#lx",
175 sohci_get_current_frame_number(dev),
176 usb_pipedevice(pipe),
177 usb_pipeendpoint(pipe),
178 usb_pipeout(pipe) ? 'O' : 'I',
179 usb_pipetype(pipe) < 2 ?
180 (usb_pipeint(pipe) ? "INTR" : "ISOC") :
181 (usb_pipecontrol(pipe) ? "CTRL" : "BULK"),
182 purb->actual_length, transfer_len, dev->status);
183 #ifdef OHCI_VERBOSE_DEBUG
187 if (usb_pipecontrol(pipe)) {
188 printf(__FILE__ ": cmd(8):");
189 for (i = 0; i < 8; i++)
190 printf(" %02x", ((__u8 *) setup)[i]);
193 if (transfer_len > 0 && buffer) {
194 printf(__FILE__ ": data(%d/%d):",
195 purb->actual_length, transfer_len);
196 len = usb_pipeout(pipe) ?
197 transfer_len : purb->actual_length;
198 for (i = 0; i < 16 && i < len; i++)
199 printf(" %02x", ((__u8 *) buffer)[i]);
200 printf("%s\n", i < len ? "..." : "");
206 /* just for debugging; prints non-empty branches of the
207 int ed tree inclusive iso eds*/
208 void ep_print_int_eds(struct ohci *ohci, char *str)
212 for (i = 0; i < 32; i++) {
214 ed_p = &(ohci->hcca->int_table[i]);
217 printf(__FILE__ ": %s branch int %2d(%2x):", str, i, i);
218 while (*ed_p != 0 && j--) {
219 struct ed *ed = (struct ed *) m32_swap(ed_p);
220 printf(" ed: %4x;", ed->hwINFO);
221 ed_p = &ed->hwNextED;
227 static void ohci_dump_intr_mask(char *label, __u32 mask)
229 dbg("%s: 0x%08x%s%s%s%s%s%s%s%s%s",
232 (mask & OHCI_INTR_MIE) ? " MIE" : "",
233 (mask & OHCI_INTR_OC) ? " OC" : "",
234 (mask & OHCI_INTR_RHSC) ? " RHSC" : "",
235 (mask & OHCI_INTR_FNO) ? " FNO" : "",
236 (mask & OHCI_INTR_UE) ? " UE" : "",
237 (mask & OHCI_INTR_RD) ? " RD" : "",
238 (mask & OHCI_INTR_SF) ? " SF" : "",
239 (mask & OHCI_INTR_WDH) ? " WDH" : "",
240 (mask & OHCI_INTR_SO) ? " SO" : "");
243 static void maybe_print_eds(char *label, __u32 value)
245 struct ed *edp = (struct ed *) value;
248 dbg("%s %08x", label, value);
249 dbg("%08x", edp->hwINFO);
250 dbg("%08x", edp->hwTailP);
251 dbg("%08x", edp->hwHeadP);
252 dbg("%08x", edp->hwNextED);
256 static char *hcfs2string(int state)
261 case OHCI_USB_RESUME:
264 return "operational";
265 case OHCI_USB_SUSPEND:
271 /* dump control and status registers */
272 static void ohci_dump_status(struct ohci *controller)
274 struct ohci_regs *regs = controller->regs;
277 temp = readl(®s->revision) & 0xff;
279 dbg("spec %d.%d", (temp >> 4), (temp & 0x0f));
281 temp = readl(®s->control);
282 dbg("control: 0x%08x%s%s%s HCFS=%s%s%s%s%s CBSR=%d", temp,
283 (temp & OHCI_CTRL_RWE) ? " RWE" : "",
284 (temp & OHCI_CTRL_RWC) ? " RWC" : "",
285 (temp & OHCI_CTRL_IR) ? " IR" : "",
286 hcfs2string(temp & OHCI_CTRL_HCFS),
287 (temp & OHCI_CTRL_BLE) ? " BLE" : "",
288 (temp & OHCI_CTRL_CLE) ? " CLE" : "",
289 (temp & OHCI_CTRL_IE) ? " IE" : "",
290 (temp & OHCI_CTRL_PLE) ? " PLE" : "", temp & OHCI_CTRL_CBSR);
292 temp = readl(®s->cmdstatus);
293 dbg("cmdstatus: 0x%08x SOC=%d%s%s%s%s", temp,
294 (temp & OHCI_SOC) >> 16,
295 (temp & OHCI_OCR) ? " OCR" : "",
296 (temp & OHCI_BLF) ? " BLF" : "",
297 (temp & OHCI_CLF) ? " CLF" : "", (temp & OHCI_HCR) ? " HCR" : "");
299 ohci_dump_intr_mask("intrstatus", readl(®s->intrstatus));
300 ohci_dump_intr_mask("intrenable", readl(®s->intrenable));
302 maybe_print_eds("ed_periodcurrent", readl(®s->ed_periodcurrent));
304 maybe_print_eds("ed_controlhead", readl(®s->ed_controlhead));
305 maybe_print_eds("ed_controlcurrent", readl(®s->ed_controlcurrent));
307 maybe_print_eds("ed_bulkhead", readl(®s->ed_bulkhead));
308 maybe_print_eds("ed_bulkcurrent", readl(®s->ed_bulkcurrent));
310 maybe_print_eds("donehead", readl(®s->donehead));
313 static void ohci_dump_roothub(struct ohci *controller, int verbose)
317 temp = roothub_a(controller);
318 ndp = (temp & RH_A_NDP);
321 dbg("roothub.a: %08x POTPGT=%d%s%s%s%s%s NDP=%d", temp,
322 ((temp & RH_A_POTPGT) >> 24) & 0xff,
323 (temp & RH_A_NOCP) ? " NOCP" : "",
324 (temp & RH_A_OCPM) ? " OCPM" : "",
325 (temp & RH_A_DT) ? " DT" : "",
326 (temp & RH_A_NPS) ? " NPS" : "",
327 (temp & RH_A_PSM) ? " PSM" : "", ndp);
328 temp = roothub_b(controller);
329 dbg("roothub.b: %08x PPCM=%04x DR=%04x",
330 temp, (temp & RH_B_PPCM) >> 16, (temp & RH_B_DR)
332 temp = roothub_status(controller);
333 dbg("roothub.status: %08x%s%s%s%s%s%s",
335 (temp & RH_HS_CRWE) ? " CRWE" : "",
336 (temp & RH_HS_OCIC) ? " OCIC" : "",
337 (temp & RH_HS_LPSC) ? " LPSC" : "",
338 (temp & RH_HS_DRWE) ? " DRWE" : "",
339 (temp & RH_HS_OCI) ? " OCI" : "",
340 (temp & RH_HS_LPS) ? " LPS" : "");
343 for (i = 0; i < ndp; i++) {
344 temp = roothub_portstatus(controller, i);
345 dbg("roothub.portstatus [%d] = 0x%08x%s%s%s%s%s%s%s%s%s%s%s%s",
348 (temp & RH_PS_PRSC) ? " PRSC" : "",
349 (temp & RH_PS_OCIC) ? " OCIC" : "",
350 (temp & RH_PS_PSSC) ? " PSSC" : "",
351 (temp & RH_PS_PESC) ? " PESC" : "",
352 (temp & RH_PS_CSC) ? " CSC" : "",
353 (temp & RH_PS_LSDA) ? " LSDA" : "",
354 (temp & RH_PS_PPS) ? " PPS" : "",
355 (temp & RH_PS_PRS) ? " PRS" : "",
356 (temp & RH_PS_POCI) ? " POCI" : "",
357 (temp & RH_PS_PSS) ? " PSS" : "",
358 (temp & RH_PS_PES) ? " PES" : "",
359 (temp & RH_PS_CCS) ? " CCS" : "");
363 static void ohci_dump(struct ohci *controller, int verbose)
365 dbg("OHCI controller usb-%s state", controller->slot_name);
367 /* dumps some of the state we know about */
368 ohci_dump_status(controller);
370 ep_print_int_eds(controller, "hcca");
371 dbg("hcca frame #%04x", controller->hcca->frame_no);
372 ohci_dump_roothub(controller, 1);
377 /*-------------------------------------------------------------------------*
378 * Interface functions (URB)
379 *-------------------------------------------------------------------------*/
381 /* get a transfer request */
383 int sohci_submit_job(struct usb_device *dev, unsigned long pipe, void *buffer,
384 int transfer_len, struct devrequest *setup, int interval)
388 struct urb_priv *purb_priv;
393 /* when controller's hung, permit only roothub cleanup attempts
394 * such as powering down ports */
395 if (ohci->disabled) {
396 err("sohci_submit_job: EPIPE");
400 /* if we have an unfinished URB from previous transaction let's
401 * fail and scream as quickly as possible so as not to corrupt
402 * further communication */
404 err("sohci_submit_job: URB NOT FINISHED");
407 /* we're about to begin a new transaction here
408 so mark the URB unfinished */
411 /* every endpoint has a ed, locate and fill it */
412 ed = ep_add_ed(dev, pipe);
414 err("sohci_submit_job: ENOMEM");
418 /* for the private part of the URB we need the number of TDs (size) */
419 switch (usb_pipetype(pipe)) {
421 /* one TD for every 4096 Byte */
422 size = (transfer_len - 1) / 4096 + 1;
425 /* 1 TD for setup, 1 for ACK and 1 for every 4096 B */
426 size = (transfer_len == 0) ? 2 : (transfer_len - 1) / 4096 + 3;
430 if (size >= (N_URB_TD - 1)) {
431 err("need %d TDs, only have %d", size, N_URB_TD);
434 purb_priv = &urb_priv;
435 purb_priv->pipe = pipe;
437 /* fill the private part of the URB */
438 purb_priv->length = size;
440 purb_priv->actual_length = 0;
442 /* allocate the TDs */
443 /* note that td[0] was allocated in ep_add_ed */
444 for (i = 0; i < size; i++) {
445 purb_priv->td[i] = td_alloc(dev);
446 if (!purb_priv->td[i]) {
447 purb_priv->length = i;
448 urb_free_priv(purb_priv);
449 err("sohci_submit_job: ENOMEM");
454 if (ed->state == ED_NEW || (ed->state & ED_DEL)) {
455 urb_free_priv(purb_priv);
456 err("sohci_submit_job: EINVAL");
460 /* link the ed into a chain if is not already */
461 if (ed->state != ED_OPER)
464 /* fill the TDs and link it to the ed */
465 td_submit_job(dev, pipe, buffer, transfer_len, setup, purb_priv,
471 /*-------------------------------------------------------------------------*/
474 /* tell us the current USB frame number */
476 static int sohci_get_current_frame_number(struct usb_device *usb_dev)
478 struct ohci *ohci = &gohci;
480 return m16_swap(ohci->hcca->frame_no);
484 /*-------------------------------------------------------------------------*
485 * ED handling functions
486 *-------------------------------------------------------------------------*/
488 /* link an ed into one of the HC chains */
490 static int ep_link(struct ohci *ohci, struct ed *edi)
499 if (ohci->ed_controltail == NULL) {
500 writel((u32)ed, &ohci->regs->ed_controlhead);
502 ohci->ed_controltail->hwNextED = (__u32) m32_swap(ed);
504 ed->ed_prev = ohci->ed_controltail;
505 if (!ohci->ed_controltail && !ohci->ed_rm_list[0] &&
506 !ohci->ed_rm_list[1] && !ohci->sleeping) {
507 ohci->hc_control |= OHCI_CTRL_CLE;
508 writel(ohci->hc_control, &ohci->regs->control);
510 ohci->ed_controltail = edi;
515 if (ohci->ed_bulktail == NULL) {
516 writel((u32)ed, &ohci->regs->ed_bulkhead);
518 ohci->ed_bulktail->hwNextED = (__u32) m32_swap(ed);
520 ed->ed_prev = ohci->ed_bulktail;
521 if (!ohci->ed_bulktail && !ohci->ed_rm_list[0] &&
522 !ohci->ed_rm_list[1] && !ohci->sleeping) {
523 ohci->hc_control |= OHCI_CTRL_BLE;
524 writel(ohci->hc_control, &ohci->regs->control);
526 ohci->ed_bulktail = edi;
532 /*-------------------------------------------------------------------------*/
534 /* unlink an ed from one of the HC chains.
535 * just the link to the ed is unlinked.
536 * the link from the ed still points to another operational ed or 0
537 * so the HC can eventually finish the processing of the unlinked ed */
539 static int ep_unlink(struct ohci *ohci, struct ed *ed)
542 ed->hwINFO |= m32_swap(OHCI_ED_SKIP);
546 if (ed->ed_prev == NULL) {
548 ohci->hc_control &= ~OHCI_CTRL_CLE;
549 writel(ohci->hc_control, &ohci->regs->control);
551 writel(m32_swap(*((__u32 *) &ed->hwNextED)),
552 &ohci->regs->ed_controlhead);
554 ed->ed_prev->hwNextED = ed->hwNextED;
556 if (ohci->ed_controltail == ed) {
557 ohci->ed_controltail = ed->ed_prev;
559 next = (struct ed *)m32_swap(*((__u32 *)&ed->hwNextED));
560 next->ed_prev = ed->ed_prev;
565 if (ed->ed_prev == NULL) {
567 ohci->hc_control &= ~OHCI_CTRL_BLE;
568 writel(ohci->hc_control, &ohci->regs->control);
570 writel(m32_swap(*((__u32 *) &ed->hwNextED)),
571 &ohci->regs->ed_bulkhead);
573 ed->ed_prev->hwNextED = ed->hwNextED;
575 if (ohci->ed_bulktail == ed) {
576 ohci->ed_bulktail = ed->ed_prev;
578 next = (struct ed *)m32_swap(*((__u32 *)&ed->hwNextED));
579 next->ed_prev = ed->ed_prev;
583 ed->state = ED_UNLINK;
587 /*-------------------------------------------------------------------------*/
589 /* add/reinit an endpoint; this should be done once at the usb_set_configuration
590 * command, but the USB stack is a little bit stateless so we do it at every
591 * transaction. If the state of the ed is ED_NEW then a dummy td is added and
592 * the state is changed to ED_UNLINK. In all other cases the state is left
593 * unchanged. The ed info fields are setted anyway even though most of them
594 * should not change */
596 static struct ed *ep_add_ed(struct usb_device *usb_dev, unsigned long pipe)
602 ed = ed_ret = &ohci_dev.ed[(usb_pipeendpoint(pipe) << 1) |
603 (usb_pipecontrol(pipe) ? 0 :
606 if ((ed->state & ED_DEL) || (ed->state & ED_URB_DEL)) {
607 err("ep_add_ed: pending delete");
608 /* pending delete request */
612 if (ed->state == ED_NEW) {
613 ed->hwINFO = m32_swap(OHCI_ED_SKIP); /* skip ed */
614 /* dummy td; end of td list for ed */
615 td = td_alloc(usb_dev);
616 ed->hwTailP = (__u32) m32_swap(td);
617 ed->hwHeadP = ed->hwTailP;
618 ed->state = ED_UNLINK;
619 ed->type = usb_pipetype(pipe);
623 ed->hwINFO = m32_swap(usb_pipedevice(pipe)
624 | usb_pipeendpoint(pipe) << 7
625 | (usb_pipeisoc(pipe) ? 0x8000 : 0)
626 | (usb_pipecontrol(pipe) ? 0 :
627 (usb_pipeout(pipe) ? 0x800 : 0x1000))
628 | usb_pipeslow(pipe) << 13 |
629 usb_maxpacket(usb_dev, pipe) << 16);
634 /*-------------------------------------------------------------------------*
635 * TD handling functions
636 *-------------------------------------------------------------------------*/
638 /* enqueue next TD for this URB (OHCI spec 5.2.8.2) */
640 static void td_fill(struct ohci *ohci, unsigned int info, void *data, int len,
641 struct usb_device *dev, int index,
642 struct urb_priv *urb_priv)
644 struct td *td, *td_pt;
645 #ifdef OHCI_FILL_TRACE
649 if (index > urb_priv->length) {
650 err("index > length");
653 /* use this td as the next dummy */
654 td_pt = urb_priv->td[index];
657 /* fill the old dummy TD */
658 td = urb_priv->td[index] =
659 (struct td *) (m32_swap(urb_priv->ed->hwTailP) & ~0xf);
661 td->ed = urb_priv->ed;
662 td->next_dl_td = NULL;
664 td->data = (__u32) data;
665 #ifdef OHCI_FILL_TRACE
666 if (usb_pipebulk(urb_priv->pipe) && usb_pipeout(urb_priv->pipe)) {
667 for (i = 0; i < len; i++)
668 printf("td->data[%d] %#2x ", i,
669 ((unsigned char *)td->data)[i]);
676 td->hwINFO = (__u32) m32_swap(info);
677 td->hwCBP = (__u32) m32_swap(data);
679 td->hwBE = (__u32) m32_swap(data + len - 1);
682 td->hwNextTD = (__u32) m32_swap(td_pt);
684 /* append to queue */
685 td->ed->hwTailP = td->hwNextTD;
688 /*-------------------------------------------------------------------------*/
690 /* prepare all TDs of a transfer */
692 static void td_submit_job(struct usb_device *dev, unsigned long pipe,
693 void *buffer, int transfer_len,
694 struct devrequest *setup, struct urb_priv *urb,
697 struct ohci *ohci = &gohci;
698 int data_len = transfer_len;
702 unsigned int toggle = 0;
704 /* OHCI handles the DATA-toggles itself, we just
705 use the USB-toggle bits for reseting */
706 if (usb_gettoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe))) {
707 toggle = TD_T_TOGGLE;
710 usb_settoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe),
719 switch (usb_pipetype(pipe)) {
721 info = usb_pipeout(pipe) ? TD_CC | TD_DP_OUT : TD_CC | TD_DP_IN;
722 while (data_len > 4096) {
723 td_fill(ohci, info | (cnt ? TD_T_TOGGLE : toggle), data,
724 4096, dev, cnt, urb);
729 info = usb_pipeout(pipe) ?
731 TD_CC | TD_R | TD_DP_IN;
732 td_fill(ohci, info | (cnt ? TD_T_TOGGLE : toggle), data,
733 data_len, dev, cnt, urb);
737 /* start bulk list */
738 writel(OHCI_BLF, &ohci->regs->cmdstatus);
742 info = TD_CC | TD_DP_SETUP | TD_T_DATA0;
743 td_fill(ohci, info, setup, 8, dev, cnt++, urb);
745 info = usb_pipeout(pipe) ?
746 TD_CC | TD_R | TD_DP_OUT | TD_T_DATA1 :
747 TD_CC | TD_R | TD_DP_IN | TD_T_DATA1;
748 /* NOTE: mishandles transfers >8K, some >4K */
749 td_fill(ohci, info, data, data_len, dev, cnt++, urb);
751 info = usb_pipeout(pipe) ?
752 TD_CC | TD_DP_IN | TD_T_DATA1 :
753 TD_CC | TD_DP_OUT | TD_T_DATA1;
754 td_fill(ohci, info, data, 0, dev, cnt++, urb);
756 /* start Control list */
757 writel(OHCI_CLF, &ohci->regs->cmdstatus);
760 if (urb->length != cnt)
761 dbg("TD LENGTH %d != CNT %d", urb->length, cnt);
764 /*-------------------------------------------------------------------------*
765 * Done List handling functions
766 *-------------------------------------------------------------------------*/
769 /* calculate the transfer length and update the urb */
771 static void dl_transfer_length(struct td *td)
773 __u32 tdINFO, tdBE, tdCBP;
774 struct urb_priv *lurb_priv = &urb_priv;
776 tdINFO = m32_swap(td->hwINFO);
777 tdBE = m32_swap(td->hwBE);
778 tdCBP = m32_swap(td->hwCBP);
780 if (!(usb_pipecontrol(lurb_priv->pipe) &&
781 ((td->index == 0) || (td->index == lurb_priv->length - 1)))) {
784 lurb_priv->actual_length += tdBE - td->data + 1;
786 lurb_priv->actual_length += tdCBP - td->data;
791 /*-------------------------------------------------------------------------*/
793 /* replies to the request have to be on a FIFO basis so
794 * we reverse the reversed done-list */
796 static struct td *dl_reverse_done_list(struct ohci *ohci)
800 struct td *td_rev = NULL;
801 struct td *td_list = NULL;
802 struct urb_priv *lurb_priv = NULL;
804 td_list_hc = m32_swap(ohci->hcca->done_head) & 0xfffffff0;
805 ohci->hcca->done_head = 0;
808 td_list = (struct td *) td_list_hc;
810 if (TD_CC_GET(m32_swap(td_list->hwINFO))) {
811 lurb_priv = &urb_priv;
812 dbg(" USB-error/status: %x : %p",
813 TD_CC_GET(m32_swap(td_list->hwINFO)), td_list);
814 if (td_list->ed->hwHeadP & m32_swap(0x1)) {
816 ((td_list->index+1) < lurb_priv->length)) {
817 tmp = lurb_priv->length - 1;
818 td_list->ed->hwHeadP =
819 (lurb_priv->td[tmp]->hwNextTD &
820 m32_swap(0xfffffff0)) |
821 (td_list->ed->hwHeadP &
823 lurb_priv->td_cnt += lurb_priv->length -
826 td_list->ed->hwHeadP &=
827 m32_swap(0xfffffff2);
831 td_list->next_dl_td = td_rev;
833 td_list_hc = m32_swap(td_list->hwNextTD) & 0xfffffff0;
839 /*-------------------------------------------------------------------------*/
842 static int dl_done_list(struct ohci *ohci, struct td *td_list)
844 struct td *td_list_next = NULL;
849 struct urb_priv *lurb_priv;
850 __u32 tdINFO, edHeadP, edTailP;
853 td_list_next = td_list->next_dl_td;
855 lurb_priv = &urb_priv;
856 tdINFO = m32_swap(td_list->hwINFO);
860 dl_transfer_length(td_list);
862 /* error code of transfer */
863 cc = TD_CC_GET(tdINFO);
865 dbg("ConditionCode %#x", cc);
866 stat = cc_to_error[cc];
869 /* see if this done list makes for all TD's of current URB,
870 * and mark the URB finished if so */
871 if (++(lurb_priv->td_cnt) == lurb_priv->length) {
872 if ((ed->state & (ED_OPER | ED_UNLINK)))
875 dbg("dl_done_list: strange.., ED state %x, "
878 dbg("dl_done_list: processing TD %x, len %x\n",
879 lurb_priv->td_cnt, lurb_priv->length);
881 if (ed->state != ED_NEW) {
882 edHeadP = m32_swap(ed->hwHeadP) & 0xfffffff0;
883 edTailP = m32_swap(ed->hwTailP);
885 /* unlink eds if they are not busy */
886 if ((edHeadP == edTailP) && (ed->state == ED_OPER))
890 td_list = td_list_next;
895 /*-------------------------------------------------------------------------*
897 *-------------------------------------------------------------------------*/
899 /* Device descriptor */
900 static __u8 root_hub_dev_des[] = {
901 0x12, /* __u8 bLength; */
902 0x01, /* __u8 bDescriptorType; Device */
903 0x10, /* __u16 bcdUSB; v1.1 */
905 0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */
906 0x00, /* __u8 bDeviceSubClass; */
907 0x00, /* __u8 bDeviceProtocol; */
908 0x08, /* __u8 bMaxPacketSize0; 8 Bytes */
909 0x00, /* __u16 idVendor; */
911 0x00, /* __u16 idProduct; */
913 0x00, /* __u16 bcdDevice; */
915 0x00, /* __u8 iManufacturer; */
916 0x01, /* __u8 iProduct; */
917 0x00, /* __u8 iSerialNumber; */
918 0x01 /* __u8 bNumConfigurations; */
921 /* Configuration descriptor */
922 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,
932 5 Remote-wakwup, 4..0: resvd */
933 0x00, /* __u8 MaxPower; */
936 0x09, /* __u8 if_bLength; */
937 0x04, /* __u8 if_bDescriptorType; Interface */
938 0x00, /* __u8 if_bInterfaceNumber; */
939 0x00, /* __u8 if_bAlternateSetting; */
940 0x01, /* __u8 if_bNumEndpoints; */
941 0x09, /* __u8 if_bInterfaceClass; HUB_CLASSCODE */
942 0x00, /* __u8 if_bInterfaceSubClass; */
943 0x00, /* __u8 if_bInterfaceProtocol; */
944 0x00, /* __u8 if_iInterface; */
947 0x07, /* __u8 ep_bLength; */
948 0x05, /* __u8 ep_bDescriptorType; Endpoint */
949 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */
950 0x03, /* __u8 ep_bmAttributes; Interrupt */
951 0x02, /* __u16 ep_wMaxPacketSize; ((MAX_ROOT_PORTS + 1) / 8 */
953 0xff /* __u8 ep_bInterval; 255 ms */
956 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[] = {
964 28, /* __u8 bLength; */
965 0x03, /* __u8 bDescriptorType; String-descriptor */
966 'O', /* __u8 Unicode */
967 0, /* __u8 Unicode */
968 'H', /* __u8 Unicode */
969 0, /* __u8 Unicode */
970 'C', /* __u8 Unicode */
971 0, /* __u8 Unicode */
972 'I', /* __u8 Unicode */
973 0, /* __u8 Unicode */
974 ' ', /* __u8 Unicode */
975 0, /* __u8 Unicode */
976 'R', /* __u8 Unicode */
977 0, /* __u8 Unicode */
978 'o', /* __u8 Unicode */
979 0, /* __u8 Unicode */
980 'o', /* __u8 Unicode */
981 0, /* __u8 Unicode */
982 't', /* __u8 Unicode */
983 0, /* __u8 Unicode */
984 ' ', /* __u8 Unicode */
985 0, /* __u8 Unicode */
986 'H', /* __u8 Unicode */
987 0, /* __u8 Unicode */
988 'u', /* __u8 Unicode */
989 0, /* __u8 Unicode */
990 'b', /* __u8 Unicode */
991 0, /* __u8 Unicode */
994 /* Hub class-specific descriptor is constructed dynamically */
997 /*-------------------------------------------------------------------------*/
999 #define OK(x) len = (x); break
1001 #define WR_RH_STAT(x) \
1003 info("WR:status %#8x", (x)); \
1004 writel((x), &gohci.regs->roothub.status); \
1006 #define WR_RH_PORTSTAT(x) \
1008 info("WR:portstatus[%d] %#8x", wIndex-1, (x)); \
1009 writel((x), &gohci.regs->roothub.portstatus[wIndex-1]); \
1012 #define WR_RH_STAT(x) \
1013 writel((x), &gohci.regs->roothub.status)
1014 #define WR_RH_PORTSTAT(x)\
1015 writel((x), &gohci.regs->roothub.portstatus[wIndex-1])
1017 #define RD_RH_STAT roothub_status(&gohci)
1018 #define RD_RH_PORTSTAT roothub_portstatus(&gohci, wIndex-1)
1020 /* request to virtual root hub */
1022 int rh_check_port_status(struct ohci *controller)
1028 temp = roothub_a(controller);
1029 ndp = (temp & RH_A_NDP);
1030 for (i = 0; i < ndp; i++) {
1031 temp = roothub_portstatus(controller, i);
1032 /* check for a device disconnect */
1033 if (((temp & (RH_PS_PESC | RH_PS_CSC)) ==
1034 (RH_PS_PESC | RH_PS_CSC)) && ((temp & RH_PS_CCS) == 0)) {
1042 static int ohci_submit_rh_msg(struct usb_device *dev, unsigned long pipe,
1043 void *buffer, int transfer_len,
1044 struct devrequest *cmd)
1046 void *data = buffer;
1047 int leni = transfer_len;
1051 __u8 *data_buf = (__u8 *) datab;
1058 urb_priv.actual_length = 0;
1059 pkt_print(dev, pipe, buffer, transfer_len, cmd, "SUB(rh)",
1064 if (usb_pipeint(pipe)) {
1065 info("Root-Hub submit IRQ: NOT implemented");
1069 bmRType_bReq = cmd->requesttype | (cmd->request << 8);
1070 wValue = m16_swap(cmd->value);
1071 wIndex = m16_swap(cmd->index);
1072 wLength = m16_swap(cmd->length);
1074 info("Root-Hub: adr: %2x cmd(%1x): %08x %04x %04x %04x",
1075 dev->devnum, 8, bmRType_bReq, wValue, wIndex, wLength);
1077 switch (bmRType_bReq) {
1078 /* Request Destination:
1079 without flags: Device,
1080 RH_INTERFACE: interface,
1081 RH_ENDPOINT: endpoint,
1082 RH_CLASS means HUB here,
1083 RH_OTHER | RH_CLASS almost ever means HUB_PORT here
1087 *(__u16 *) data_buf = m16_swap(1);
1089 case RH_GET_STATUS | RH_INTERFACE:
1090 *(__u16 *) data_buf = m16_swap(0);
1092 case RH_GET_STATUS | RH_ENDPOINT:
1093 *(__u16 *) data_buf = m16_swap(0);
1095 case RH_GET_STATUS | RH_CLASS:
1096 *(__u32 *) data_buf =
1097 m32_swap(RD_RH_STAT & ~(RH_HS_CRWE | RH_HS_DRWE));
1099 case RH_GET_STATUS | RH_OTHER | RH_CLASS:
1100 *(__u32 *) data_buf = m32_swap(RD_RH_PORTSTAT);
1103 case RH_CLEAR_FEATURE | RH_ENDPOINT:
1105 case (RH_ENDPOINT_STALL):
1110 case RH_CLEAR_FEATURE | RH_CLASS:
1112 case RH_C_HUB_LOCAL_POWER:
1114 case (RH_C_HUB_OVER_CURRENT):
1115 WR_RH_STAT(RH_HS_OCIC);
1120 case RH_CLEAR_FEATURE | RH_OTHER | RH_CLASS:
1122 case (RH_PORT_ENABLE):
1123 WR_RH_PORTSTAT(RH_PS_CCS);
1125 case (RH_PORT_SUSPEND):
1126 WR_RH_PORTSTAT(RH_PS_POCI);
1128 case (RH_PORT_POWER):
1129 WR_RH_PORTSTAT(RH_PS_LSDA);
1131 case (RH_C_PORT_CONNECTION):
1132 WR_RH_PORTSTAT(RH_PS_CSC);
1134 case (RH_C_PORT_ENABLE):
1135 WR_RH_PORTSTAT(RH_PS_PESC);
1137 case (RH_C_PORT_SUSPEND):
1138 WR_RH_PORTSTAT(RH_PS_PSSC);
1140 case (RH_C_PORT_OVER_CURRENT):
1141 WR_RH_PORTSTAT(RH_PS_OCIC);
1143 case (RH_C_PORT_RESET):
1144 WR_RH_PORTSTAT(RH_PS_PRSC);
1149 case RH_SET_FEATURE | RH_OTHER | RH_CLASS:
1151 case (RH_PORT_SUSPEND):
1152 WR_RH_PORTSTAT(RH_PS_PSS);
1154 case (RH_PORT_RESET): /* BUG IN HUP CODE ******** */
1155 if (RD_RH_PORTSTAT & RH_PS_CCS)
1156 WR_RH_PORTSTAT(RH_PS_PRS);
1158 case (RH_PORT_POWER):
1159 WR_RH_PORTSTAT(RH_PS_PPS);
1161 case (RH_PORT_ENABLE): /* BUG IN HUP CODE ******** */
1162 if (RD_RH_PORTSTAT & RH_PS_CCS)
1163 WR_RH_PORTSTAT(RH_PS_PES);
1168 case RH_SET_ADDRESS:
1169 gohci.rh.devnum = wValue;
1172 case RH_GET_DESCRIPTOR:
1173 switch ((wValue & 0xff00) >> 8) {
1174 case (0x01): /* device descriptor */
1175 len = min_t(unsigned int,
1178 sizeof(root_hub_dev_des), wLength));
1179 data_buf = root_hub_dev_des;
1181 case (0x02): /* configuration descriptor */
1182 len = min_t(unsigned int,
1185 sizeof(root_hub_config_des),
1187 data_buf = root_hub_config_des;
1189 case (0x03): /* string descriptors */
1190 if (wValue == 0x0300) {
1191 len = min_t(unsigned int,
1194 sizeof(root_hub_str_index0),
1196 data_buf = root_hub_str_index0;
1199 if (wValue == 0x0301) {
1200 len = min_t(unsigned int,
1203 sizeof(root_hub_str_index1),
1205 data_buf = root_hub_str_index1;
1209 stat = USB_ST_STALLED;
1213 case RH_GET_DESCRIPTOR | RH_CLASS:
1215 __u32 temp = roothub_a(&gohci);
1217 data_buf[0] = 9; /* min length; */
1219 data_buf[2] = temp & RH_A_NDP;
1221 if (temp & RH_A_PSM)
1222 /* per-port power switching? */
1224 if (temp & RH_A_NOCP)
1225 /* no overcurrent reporting? */
1226 data_buf[3] |= 0x10;
1227 else if (temp & RH_A_OCPM)
1228 /* per-port overcurrent reporting? */
1231 /* corresponds to data_buf[4-7] */
1233 data_buf[5] = (temp & RH_A_POTPGT) >> 24;
1234 temp = roothub_b(&gohci);
1235 data_buf[7] = temp & RH_B_DR;
1236 if (data_buf[2] < 7) {
1240 data_buf[8] = (temp & RH_B_DR) >> 8;
1241 data_buf[10] = data_buf[9] = 0xff;
1244 len = min_t(unsigned int, leni,
1245 min_t(unsigned int, data_buf[0], wLength));
1249 case RH_GET_CONFIGURATION:
1250 *(__u8 *) data_buf = 0x01;
1253 case RH_SET_CONFIGURATION:
1254 WR_RH_STAT(0x10000);
1258 dbg("unsupported root hub command");
1259 stat = USB_ST_STALLED;
1263 ohci_dump_roothub(&gohci, 1);
1268 len = min_t(int, len, leni);
1269 if (data != data_buf)
1270 memcpy(data, data_buf, len);
1276 urb_priv.actual_length = transfer_len;
1277 pkt_print(dev, pipe, buffer, transfer_len, cmd, "RET(rh)",
1278 0 /*usb_pipein(pipe) */);
1286 /*-------------------------------------------------------------------------*/
1288 /* common code for handling submit messages - used for all but root hub */
1290 int submit_common_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
1291 int transfer_len, struct devrequest *setup, int interval)
1294 int maxsize = usb_maxpacket(dev, pipe);
1297 /* device pulled? Shortcut the action. */
1298 if (devgone == dev) {
1299 dev->status = USB_ST_CRC_ERR;
1303 urb_priv.actual_length = 0;
1304 pkt_print(dev, pipe, buffer, transfer_len, setup, "SUB",
1310 err("submit_common_message: pipesize for pipe %lx is zero",
1315 if (sohci_submit_job(dev, pipe, buffer, transfer_len, setup, interval) <
1317 err("sohci_submit_job failed");
1322 /* ohci_dump_status(&gohci); */
1324 /* allow more time for a BULK device to react - some are slow */
1325 #define BULK_TO 5000 /* timeout in milliseconds */
1326 if (usb_pipebulk(pipe))
1331 /* wait for it to complete */
1333 /* check whether the controller is done */
1334 stat = hc_interrupt();
1337 stat = USB_ST_CRC_ERR;
1341 /* NOTE: since we are not interrupt driven in U-Boot and always
1342 * handle only one URB at a time, we cannot assume the
1343 * transaction finished on the first successful return from
1344 * hc_interrupt().. unless the flag for current URB is set,
1345 * meaning that all TD's to/from device got actually
1346 * transferred and processed. If the current URB is not
1347 * finished we need to re-iterate this loop so as
1348 * hc_interrupt() gets called again as there needs to be some
1349 * more TD's to process still */
1350 if ((stat >= 0) && (stat != 0xff) && (urb_finished)) {
1351 /* 0xff is returned for an SF-interrupt */
1361 err("CTL:TIMEOUT ");
1362 dbg("submit_common_msg: TO status %x\n", stat);
1363 stat = USB_ST_CRC_ERR;
1370 /* we got an Root Hub Status Change interrupt */
1373 ohci_dump_roothub(&gohci, 1);
1377 timeout = rh_check_port_status(&gohci);
1379 #if 0 /* this does nothing useful, but leave it here
1380 in case that changes */
1381 /* the called routine adds 1 to the passed value */
1382 usb_hub_port_connect_change(gohci.rh.dev, timeout - 1);
1386 * This is potentially dangerous because it assumes
1387 * that only one device is ever plugged in!
1395 dev->act_len = transfer_len;
1398 pkt_print(dev, pipe, buffer, transfer_len, setup, "RET(ctlr)",
1404 /* free TDs in urb_priv */
1405 urb_free_priv(&urb_priv);
1409 /* submit routines called from usb.c */
1410 int submit_bulk_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
1413 info("submit_bulk_msg");
1414 return submit_common_msg(dev, pipe, buffer, transfer_len, NULL, 0);
1417 int submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
1418 int transfer_len, struct devrequest *setup)
1420 int maxsize = usb_maxpacket(dev, pipe);
1422 info("submit_control_msg");
1424 urb_priv.actual_length = 0;
1425 pkt_print(dev, pipe, buffer, transfer_len, setup, "SUB",
1431 err("submit_control_message: pipesize for pipe %lx is zero",
1435 if (((pipe >> 8) & 0x7f) == gohci.rh.devnum) {
1437 /* root hub - redirect */
1438 return ohci_submit_rh_msg(dev, pipe, buffer, transfer_len,
1442 return submit_common_msg(dev, pipe, buffer, transfer_len, setup, 0);
1445 int submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
1446 int transfer_len, int interval)
1448 info("submit_int_msg");
1452 /*-------------------------------------------------------------------------*
1454 *-------------------------------------------------------------------------*/
1456 /* reset the HC and BUS */
1458 static int hc_reset(struct ohci *ohci)
1461 int smm_timeout = 50; /* 0,5 sec */
1463 if (readl(&ohci->regs->control) & OHCI_CTRL_IR) {
1464 /* SMM owns the HC - request ownership */
1465 writel(OHCI_OCR, &ohci->regs->cmdstatus);
1466 info("USB HC TakeOver from SMM");
1467 while (readl(&ohci->regs->control) & OHCI_CTRL_IR) {
1469 if (--smm_timeout == 0) {
1470 err("USB HC TakeOver failed!");
1476 /* Disable HC interrupts */
1477 writel(OHCI_INTR_MIE, &ohci->regs->intrdisable);
1479 dbg("USB HC reset_hc usb-%s: ctrl = 0x%X ;",
1480 ohci->slot_name, readl(&ohci->regs->control));
1482 /* Reset USB (needed by some controllers) */
1483 writel(0, &ohci->regs->control);
1485 /* HC Reset requires max 10 us delay */
1486 writel(OHCI_HCR, &ohci->regs->cmdstatus);
1487 while ((readl(&ohci->regs->cmdstatus) & OHCI_HCR) != 0) {
1488 if (--timeout == 0) {
1489 err("USB HC reset timed out!");
1497 /*-------------------------------------------------------------------------*/
1499 /* Start an OHCI controller, set the BUS operational
1501 * connect the virtual root hub */
1503 static int hc_start(struct ohci *ohci)
1506 unsigned int fminterval;
1510 /* Tell the controller where the control and bulk lists are
1511 * The lists are empty now. */
1513 writel(0, &ohci->regs->ed_controlhead);
1514 writel(0, &ohci->regs->ed_bulkhead);
1516 /* a reset clears this */
1517 writel((__u32) ohci->hcca, &ohci->regs->hcca);
1519 fminterval = 0x2edf;
1520 writel((fminterval * 9) / 10, &ohci->regs->periodicstart);
1521 fminterval |= ((((fminterval - 210) * 6) / 7) << 16);
1522 writel(fminterval, &ohci->regs->fminterval);
1523 writel(0x628, &ohci->regs->lsthresh);
1525 /* start controller operations */
1526 ohci->hc_control = OHCI_CONTROL_INIT | OHCI_USB_OPER;
1528 writel(ohci->hc_control, &ohci->regs->control);
1530 /* disable all interrupts */
1531 mask = (OHCI_INTR_SO | OHCI_INTR_WDH | OHCI_INTR_SF | OHCI_INTR_RD |
1532 OHCI_INTR_UE | OHCI_INTR_FNO | OHCI_INTR_RHSC |
1533 OHCI_INTR_OC | OHCI_INTR_MIE);
1534 writel(mask, &ohci->regs->intrdisable);
1535 /* clear all interrupts */
1536 mask &= ~OHCI_INTR_MIE;
1537 writel(mask, &ohci->regs->intrstatus);
1538 /* Choose the interrupts we care about now - but w/o MIE */
1539 mask = OHCI_INTR_RHSC | OHCI_INTR_UE | OHCI_INTR_WDH | OHCI_INTR_SO;
1540 writel(mask, &ohci->regs->intrenable);
1543 /* required for AMD-756 and some Mac platforms */
1544 writel((roothub_a(ohci) | RH_A_NPS) & ~RH_A_PSM,
1545 &ohci->regs->roothub.a);
1546 writel(RH_HS_LPSC, &ohci->regs->roothub.status);
1547 #endif /* OHCI_USE_NPS */
1549 #define mdelay(n) ({unsigned long msec=(n); while (msec--) udelay(1000);})
1550 /* POTPGT delay is bits 24-31, in 2 ms units. */
1551 mdelay((roothub_a(ohci) >> 23) & 0x1fe);
1553 /* connect the virtual root hub */
1554 ohci->rh.devnum = 0;
1559 /*-------------------------------------------------------------------------*/
1561 /* an interrupt happens */
1563 static int hc_interrupt(void)
1565 struct ohci *ohci = &gohci;
1566 struct ohci_regs *regs = ohci->regs;
1570 if ((ohci->hcca->done_head != 0) &&
1571 !(m32_swap(ohci->hcca->done_head) & 0x01)) {
1573 ints = OHCI_INTR_WDH;
1576 ints = readl(®s->intrstatus);
1577 if (ints == ~(u32) 0) {
1579 err("%s device removed!", ohci->slot_name);
1582 ints &= readl(®s->intrenable);
1584 dbg("hc_interrupt: returning..\n");
1589 /* dbg("Interrupt: %x frame: %x", ints,
1590 le16_to_cpu(ohci->hcca->frame_no)); */
1592 if (ints & OHCI_INTR_RHSC) {
1597 if (ints & OHCI_INTR_UE) {
1599 err("OHCI Unrecoverable Error, controller usb-%s disabled",
1601 /* e.g. due to PCI Master/Target Abort */
1608 /* FIXME: be optimistic, hope that bug won't repeat often. */
1609 /* Make some non-interrupt context restart the controller. */
1610 /* Count and limit the retries though; either hardware or */
1611 /* software errors can go forever... */
1616 if (ints & OHCI_INTR_WDH) {
1619 writel(OHCI_INTR_WDH, ®s->intrdisable);
1620 stat = dl_done_list(&gohci, dl_reverse_done_list(&gohci));
1621 writel(OHCI_INTR_WDH, ®s->intrenable);
1624 if (ints & OHCI_INTR_SO) {
1625 dbg("USB Schedule overrun\n");
1626 writel(OHCI_INTR_SO, ®s->intrenable);
1630 /* FIXME: this assumes SOF (1/ms) interrupts don't get lost... */
1631 if (ints & OHCI_INTR_SF) {
1632 unsigned int frame = m16_swap(ohci->hcca->frame_no) & 1;
1634 writel(OHCI_INTR_SF, ®s->intrdisable);
1635 if (ohci->ed_rm_list[frame] != NULL)
1636 writel(OHCI_INTR_SF, ®s->intrenable);
1640 writel(ints, ®s->intrstatus);
1644 /*-------------------------------------------------------------------------*/
1646 /*-------------------------------------------------------------------------*/
1648 /* De-allocate all resources.. */
1650 static void hc_release_ohci(struct ohci *ohci)
1652 dbg("USB HC release ohci usb-%s", ohci->slot_name);
1654 if (!ohci->disabled)
1658 /*-------------------------------------------------------------------------*/
1661 * low level initalisation routine, called from usb.c
1663 static char ohci_inited = 0;
1665 int usb_lowlevel_init(void)
1667 struct s3c24x0_clock_power *clk_power = s3c24x0_get_base_clock_power();
1668 struct s3c24x0_gpio *gpio = s3c24x0_get_base_gpio();
1671 * Set the 48 MHz UPLL clocking. Values are taken from
1672 * "PLL value selection guide", 6-23, s3c2400_UM.pdf.
1674 clk_power->UPLLCON = ((40 << 12) + (1 << 4) + 2);
1675 gpio->MISCCR |= 0x8; /* 1 = use pads related USB for USB host */
1678 * Enable USB host clock.
1680 clk_power->CLKCON |= (1 << 4);
1682 memset(&gohci, 0, sizeof(struct ohci));
1683 memset(&urb_priv, 0, sizeof(struct urb_priv));
1685 /* align the storage */
1686 if ((__u32) &ghcca[0] & 0xff) {
1687 err("HCCA not aligned!!");
1691 info("aligned ghcca %p", phcca);
1692 memset(&ohci_dev, 0, sizeof(struct ohci_device));
1693 if ((__u32) &ohci_dev.ed[0] & 0x7) {
1694 err("EDs not aligned!!");
1697 memset(gtd, 0, sizeof(struct td) * (NUM_TD + 1));
1698 if ((__u32) gtd & 0x7) {
1699 err("TDs not aligned!!");
1704 memset(phcca, 0, sizeof(struct ohci_hcca));
1709 gohci.regs = (struct ohci_regs *)S3C24X0_USB_HOST_BASE;
1712 gohci.slot_name = "s3c2400";
1714 if (hc_reset(&gohci) < 0) {
1715 hc_release_ohci(&gohci);
1716 /* Initialization failed */
1717 clk_power->CLKCON &= ~(1 << 4);
1721 /* FIXME this is a second HC reset; why?? */
1722 gohci.hc_control = OHCI_USB_RESET;
1723 writel(gohci.hc_control, &gohci.regs->control);
1726 if (hc_start(&gohci) < 0) {
1727 err("can't start usb-%s", gohci.slot_name);
1728 hc_release_ohci(&gohci);
1729 /* Initialization failed */
1730 clk_power->CLKCON &= ~(1 << 4);
1734 ohci_dump(&gohci, 1);
1744 int usb_lowlevel_stop(void)
1746 struct s3c24x0_clock_power *clk_power = s3c24x0_get_base_clock_power();
1748 /* this gets called really early - before the controller has */
1749 /* even been initialized! */
1752 /* TODO release any interrupts, etc. */
1753 /* call hc_release_ohci() here ? */
1755 /* may not want to do this */
1756 clk_power->CLKCON &= ~(1 << 4);
1760 #endif /* CONFIG_USB_OHCI */