]>
git.ipfire.org Git - people/ms/u-boot.git/blob - arch/mips/cpu/mips32/au1x00/au1x00_usb_ohci.c
2 * URB OHCI HCD (Host Controller Driver) for USB on the AU1x00.
5 * Gary Jennejohn, DENX Software Engineering <garyj@denx.de>
7 * SPDX-License-Identifier: GPL-2.0+
8 * Note: Part of this code has been derived from linux
13 * 1 - this driver is intended for use with USB Mass Storage Devices
14 * (BBB) ONLY. There is NO support for Interrupt or Isochronous pipes!
19 #ifdef CONFIG_USB_OHCI
21 /* #include <pci.h> no PCI on the AU1x00 */
26 #include <asm/au1x00.h>
28 #include "au1x00_usb_ohci.h"
30 #define OHCI_USE_NPS /* force NoPowerSwitching mode */
31 #define OHCI_VERBOSE_DEBUG /* not always helpful */
32 #define OHCI_FILL_TRACE
34 #define USBH_ENABLE_BE (1<<0)
35 #define USBH_ENABLE_C (1<<1)
36 #define USBH_ENABLE_E (1<<2)
37 #define USBH_ENABLE_CE (1<<3)
38 #define USBH_ENABLE_RD (1<<4)
40 #ifdef __LITTLE_ENDIAN
41 #define USBH_ENABLE_INIT (USBH_ENABLE_CE | USBH_ENABLE_E | USBH_ENABLE_C)
43 #define USBH_ENABLE_INIT (USBH_ENABLE_CE | USBH_ENABLE_E | USBH_ENABLE_C | USBH_ENABLE_BE)
47 /* For initializing controller (mask in an HCFS mode too) */
48 #define OHCI_CONTROL_INIT \
49 (OHCI_CTRL_CBSR & 0x3) | OHCI_CTRL_IE | OHCI_CTRL_PLE
54 #define readl(a) au_readl((long)(a))
55 #define writel(v,a) au_writel((v),(int)(a))
59 #define dbg(format, arg...) printf("DEBUG: " format "\n", ## arg)
61 #define dbg(format, arg...) do {} while(0)
63 #define err(format, arg...) printf("ERROR: " format "\n", ## arg)
66 #define info(format, arg...) printf("INFO: " format "\n", ## arg)
68 #define info(format, arg...) do {} while(0)
71 #define m16_swap(x) swap_16(x)
72 #define m32_swap(x) swap_32(x)
76 /* this must be aligned to a 256 byte boundary */
77 struct ohci_hcca ghcca
[1];
78 /* a pointer to the aligned storage */
79 struct ohci_hcca
*phcca
;
80 /* this allocates EDs for all possible endpoints */
81 struct ohci_device ohci_dev
;
86 /* device which was disconnected */
87 struct usb_device
*devgone
;
89 /*-------------------------------------------------------------------------*/
91 /* AMD-756 (D2 rev) reports corrupt register contents in some cases.
92 * The erratum (#4) description is incorrect. AMD's workaround waits
93 * till some bits (mostly reserved) are clear; ok for all revs.
95 #define OHCI_QUIRK_AMD756 0xabcd
96 #define read_roothub(hc, register, mask) ({ \
97 u32 temp = readl (&hc->regs->roothub.register); \
98 if (hc->flags & OHCI_QUIRK_AMD756) \
100 temp = readl (&hc->regs->roothub.register); \
103 static u32
roothub_a (struct ohci
*hc
)
104 { return read_roothub (hc
, a
, 0xfc0fe000); }
105 static inline u32
roothub_b (struct ohci
*hc
)
106 { return readl (&hc
->regs
->roothub
.b
); }
107 static inline u32
roothub_status (struct ohci
*hc
)
108 { return readl (&hc
->regs
->roothub
.status
); }
109 static u32
roothub_portstatus (struct ohci
*hc
, int i
)
110 { return read_roothub (hc
, portstatus
[i
], 0xffe0fce0); }
113 /* forward declaration */
114 static int hc_interrupt (void);
116 td_submit_job (struct usb_device
* dev
, unsigned long pipe
, void * buffer
,
117 int transfer_len
, struct devrequest
* setup
, urb_priv_t
* urb
, int interval
);
119 /*-------------------------------------------------------------------------*
120 * URB support functions
121 *-------------------------------------------------------------------------*/
123 /* free HCD-private data associated with this URB */
125 static void urb_free_priv (urb_priv_t
* urb
)
131 last
= urb
->length
- 1;
133 for (i
= 0; i
<= last
; i
++) {
143 /*-------------------------------------------------------------------------*/
146 static int sohci_get_current_frame_number (struct usb_device
* dev
);
148 /* debug| print the main components of an URB
149 * small: 0) header + data packets 1) just header */
151 static void pkt_print (struct usb_device
* dev
, unsigned long pipe
, void * buffer
,
152 int transfer_len
, struct devrequest
* setup
, char * str
, int small
)
154 urb_priv_t
* purb
= &urb_priv
;
156 dbg("%s URB:[%4x] dev:%2d,ep:%2d-%c,type:%s,len:%d/%d stat:%#lx",
158 sohci_get_current_frame_number (dev
),
159 usb_pipedevice (pipe
),
160 usb_pipeendpoint (pipe
),
161 usb_pipeout (pipe
)? 'O': 'I',
162 usb_pipetype (pipe
) < 2? (usb_pipeint (pipe
)? "INTR": "ISOC"):
163 (usb_pipecontrol (pipe
)? "CTRL": "BULK"),
165 transfer_len
, dev
->status
);
166 #ifdef OHCI_VERBOSE_DEBUG
170 if (usb_pipecontrol (pipe
)) {
171 printf (__FILE__
": cmd(8):");
172 for (i
= 0; i
< 8 ; i
++)
173 printf (" %02x", ((__u8
*) setup
) [i
]);
176 if (transfer_len
> 0 && buffer
) {
177 printf (__FILE__
": data(%d/%d):",
180 len
= usb_pipeout (pipe
)?
181 transfer_len
: purb
->actual_length
;
182 for (i
= 0; i
< 16 && i
< len
; i
++)
183 printf (" %02x", ((__u8
*) buffer
) [i
]);
184 printf ("%s\n", i
< len
? "...": "");
190 /* just for debugging; prints non-empty branches of the int ed tree inclusive iso eds*/
191 void ep_print_int_eds (ohci_t
*ohci
, char * str
) {
194 for (i
= 0; i
< 32; i
++) {
196 ed_p
= &(ohci
->hcca
->int_table
[i
]);
199 printf (__FILE__
": %s branch int %2d(%2x):", str
, i
, i
);
200 while (*ed_p
!= 0 && j
--) {
201 ed_t
*ed
= (ed_t
*)m32_swap(ed_p
);
202 printf (" ed: %4x;", ed
->hwINFO
);
203 ed_p
= &ed
->hwNextED
;
209 static void ohci_dump_intr_mask (char *label
, __u32 mask
)
211 dbg ("%s: 0x%08x%s%s%s%s%s%s%s%s%s",
214 (mask
& OHCI_INTR_MIE
) ? " MIE" : "",
215 (mask
& OHCI_INTR_OC
) ? " OC" : "",
216 (mask
& OHCI_INTR_RHSC
) ? " RHSC" : "",
217 (mask
& OHCI_INTR_FNO
) ? " FNO" : "",
218 (mask
& OHCI_INTR_UE
) ? " UE" : "",
219 (mask
& OHCI_INTR_RD
) ? " RD" : "",
220 (mask
& OHCI_INTR_SF
) ? " SF" : "",
221 (mask
& OHCI_INTR_WDH
) ? " WDH" : "",
222 (mask
& OHCI_INTR_SO
) ? " SO" : ""
226 static void maybe_print_eds (char *label
, __u32 value
)
228 ed_t
*edp
= (ed_t
*)value
;
231 dbg ("%s %08x", label
, value
);
232 dbg ("%08x", edp
->hwINFO
);
233 dbg ("%08x", edp
->hwTailP
);
234 dbg ("%08x", edp
->hwHeadP
);
235 dbg ("%08x", edp
->hwNextED
);
239 static char * hcfs2string (int state
)
242 case OHCI_USB_RESET
: return "reset";
243 case OHCI_USB_RESUME
: return "resume";
244 case OHCI_USB_OPER
: return "operational";
245 case OHCI_USB_SUSPEND
: return "suspend";
250 /* dump control and status registers */
251 static void ohci_dump_status (ohci_t
*controller
)
253 struct ohci_regs
*regs
= controller
->regs
;
256 temp
= readl (®s
->revision
) & 0xff;
258 dbg ("spec %d.%d", (temp
>> 4), (temp
& 0x0f));
260 temp
= readl (®s
->control
);
261 dbg ("control: 0x%08x%s%s%s HCFS=%s%s%s%s%s CBSR=%d", temp
,
262 (temp
& OHCI_CTRL_RWE
) ? " RWE" : "",
263 (temp
& OHCI_CTRL_RWC
) ? " RWC" : "",
264 (temp
& OHCI_CTRL_IR
) ? " IR" : "",
265 hcfs2string (temp
& OHCI_CTRL_HCFS
),
266 (temp
& OHCI_CTRL_BLE
) ? " BLE" : "",
267 (temp
& OHCI_CTRL_CLE
) ? " CLE" : "",
268 (temp
& OHCI_CTRL_IE
) ? " IE" : "",
269 (temp
& OHCI_CTRL_PLE
) ? " PLE" : "",
270 temp
& OHCI_CTRL_CBSR
273 temp
= readl (®s
->cmdstatus
);
274 dbg ("cmdstatus: 0x%08x SOC=%d%s%s%s%s", temp
,
275 (temp
& OHCI_SOC
) >> 16,
276 (temp
& OHCI_OCR
) ? " OCR" : "",
277 (temp
& OHCI_BLF
) ? " BLF" : "",
278 (temp
& OHCI_CLF
) ? " CLF" : "",
279 (temp
& OHCI_HCR
) ? " HCR" : ""
282 ohci_dump_intr_mask ("intrstatus", readl (®s
->intrstatus
));
283 ohci_dump_intr_mask ("intrenable", readl (®s
->intrenable
));
285 maybe_print_eds ("ed_periodcurrent", readl (®s
->ed_periodcurrent
));
287 maybe_print_eds ("ed_controlhead", readl (®s
->ed_controlhead
));
288 maybe_print_eds ("ed_controlcurrent", readl (®s
->ed_controlcurrent
));
290 maybe_print_eds ("ed_bulkhead", readl (®s
->ed_bulkhead
));
291 maybe_print_eds ("ed_bulkcurrent", readl (®s
->ed_bulkcurrent
));
293 maybe_print_eds ("donehead", readl (®s
->donehead
));
296 static void ohci_dump_roothub (ohci_t
*controller
, int verbose
)
300 temp
= roothub_a (controller
);
301 ndp
= (temp
& RH_A_NDP
);
304 dbg ("roothub.a: %08x POTPGT=%d%s%s%s%s%s NDP=%d", temp
,
305 ((temp
& RH_A_POTPGT
) >> 24) & 0xff,
306 (temp
& RH_A_NOCP
) ? " NOCP" : "",
307 (temp
& RH_A_OCPM
) ? " OCPM" : "",
308 (temp
& RH_A_DT
) ? " DT" : "",
309 (temp
& RH_A_NPS
) ? " NPS" : "",
310 (temp
& RH_A_PSM
) ? " PSM" : "",
313 temp
= roothub_b (controller
);
314 dbg ("roothub.b: %08x PPCM=%04x DR=%04x",
316 (temp
& RH_B_PPCM
) >> 16,
319 temp
= roothub_status (controller
);
320 dbg ("roothub.status: %08x%s%s%s%s%s%s",
322 (temp
& RH_HS_CRWE
) ? " CRWE" : "",
323 (temp
& RH_HS_OCIC
) ? " OCIC" : "",
324 (temp
& RH_HS_LPSC
) ? " LPSC" : "",
325 (temp
& RH_HS_DRWE
) ? " DRWE" : "",
326 (temp
& RH_HS_OCI
) ? " OCI" : "",
327 (temp
& RH_HS_LPS
) ? " LPS" : ""
331 for (i
= 0; i
< ndp
; i
++) {
332 temp
= roothub_portstatus (controller
, i
);
333 dbg ("roothub.portstatus [%d] = 0x%08x%s%s%s%s%s%s%s%s%s%s%s%s",
336 (temp
& RH_PS_PRSC
) ? " PRSC" : "",
337 (temp
& RH_PS_OCIC
) ? " OCIC" : "",
338 (temp
& RH_PS_PSSC
) ? " PSSC" : "",
339 (temp
& RH_PS_PESC
) ? " PESC" : "",
340 (temp
& RH_PS_CSC
) ? " CSC" : "",
342 (temp
& RH_PS_LSDA
) ? " LSDA" : "",
343 (temp
& RH_PS_PPS
) ? " PPS" : "",
344 (temp
& RH_PS_PRS
) ? " PRS" : "",
345 (temp
& RH_PS_POCI
) ? " POCI" : "",
346 (temp
& RH_PS_PSS
) ? " PSS" : "",
348 (temp
& RH_PS_PES
) ? " PES" : "",
349 (temp
& RH_PS_CCS
) ? " CCS" : ""
354 static void ohci_dump (ohci_t
*controller
, int verbose
)
356 dbg ("OHCI controller usb-%s state", controller
->slot_name
);
358 /* dumps some of the state we know about */
359 ohci_dump_status (controller
);
361 ep_print_int_eds (controller
, "hcca");
362 dbg ("hcca frame #%04x", controller
->hcca
->frame_no
);
363 ohci_dump_roothub (controller
, 1);
369 /*-------------------------------------------------------------------------*
370 * Interface functions (URB)
371 *-------------------------------------------------------------------------*/
373 /* get a transfer request */
375 int sohci_submit_job(struct usb_device
*dev
, unsigned long pipe
, void *buffer
,
376 int transfer_len
, struct devrequest
*setup
, int interval
)
380 urb_priv_t
*purb_priv
;
385 /* when controller's hung, permit only roothub cleanup attempts
386 * such as powering down ports */
387 if (ohci
->disabled
) {
388 err("sohci_submit_job: EPIPE");
392 /* every endpoint has a ed, locate and fill it */
393 if (!(ed
= ep_add_ed (dev
, pipe
))) {
394 err("sohci_submit_job: ENOMEM");
398 /* for the private part of the URB we need the number of TDs (size) */
399 switch (usb_pipetype (pipe
)) {
400 case PIPE_BULK
: /* one TD for every 4096 Byte */
401 size
= (transfer_len
- 1) / 4096 + 1;
403 case PIPE_CONTROL
: /* 1 TD for setup, 1 for ACK and 1 for every 4096 B */
404 size
= (transfer_len
== 0)? 2:
405 (transfer_len
- 1) / 4096 + 3;
409 if (size
>= (N_URB_TD
- 1)) {
410 err("need %d TDs, only have %d", size
, N_URB_TD
);
413 purb_priv
= &urb_priv
;
414 purb_priv
->pipe
= pipe
;
416 /* fill the private part of the URB */
417 purb_priv
->length
= size
;
419 purb_priv
->actual_length
= 0;
421 /* allocate the TDs */
422 /* note that td[0] was allocated in ep_add_ed */
423 for (i
= 0; i
< size
; i
++) {
424 purb_priv
->td
[i
] = td_alloc (dev
);
425 if (!purb_priv
->td
[i
]) {
426 purb_priv
->length
= i
;
427 urb_free_priv (purb_priv
);
428 err("sohci_submit_job: ENOMEM");
433 if (ed
->state
== ED_NEW
|| (ed
->state
& ED_DEL
)) {
434 urb_free_priv (purb_priv
);
435 err("sohci_submit_job: EINVAL");
439 /* link the ed into a chain if is not already */
440 if (ed
->state
!= ED_OPER
)
443 /* fill the TDs and link it to the ed */
444 td_submit_job(dev
, pipe
, buffer
, transfer_len
, setup
, purb_priv
, interval
);
449 /*-------------------------------------------------------------------------*/
452 /* tell us the current USB frame number */
454 static int sohci_get_current_frame_number (struct usb_device
*usb_dev
)
456 ohci_t
*ohci
= &gohci
;
458 return m16_swap (ohci
->hcca
->frame_no
);
462 /*-------------------------------------------------------------------------*
463 * ED handling functions
464 *-------------------------------------------------------------------------*/
466 /* link an ed into one of the HC chains */
468 static int ep_link (ohci_t
*ohci
, ed_t
*edi
)
470 volatile ed_t
*ed
= edi
;
477 if (ohci
->ed_controltail
== NULL
) {
478 writel ((long)ed
, &ohci
->regs
->ed_controlhead
);
480 ohci
->ed_controltail
->hwNextED
= m32_swap (ed
);
482 ed
->ed_prev
= ohci
->ed_controltail
;
483 if (!ohci
->ed_controltail
&& !ohci
->ed_rm_list
[0] &&
484 !ohci
->ed_rm_list
[1] && !ohci
->sleeping
) {
485 ohci
->hc_control
|= OHCI_CTRL_CLE
;
486 writel (ohci
->hc_control
, &ohci
->regs
->control
);
488 ohci
->ed_controltail
= edi
;
493 if (ohci
->ed_bulktail
== NULL
) {
494 writel ((long)ed
, &ohci
->regs
->ed_bulkhead
);
496 ohci
->ed_bulktail
->hwNextED
= m32_swap (ed
);
498 ed
->ed_prev
= ohci
->ed_bulktail
;
499 if (!ohci
->ed_bulktail
&& !ohci
->ed_rm_list
[0] &&
500 !ohci
->ed_rm_list
[1] && !ohci
->sleeping
) {
501 ohci
->hc_control
|= OHCI_CTRL_BLE
;
502 writel (ohci
->hc_control
, &ohci
->regs
->control
);
504 ohci
->ed_bulktail
= edi
;
510 /*-------------------------------------------------------------------------*/
512 /* unlink an ed from one of the HC chains.
513 * just the link to the ed is unlinked.
514 * the link from the ed still points to another operational ed or 0
515 * so the HC can eventually finish the processing of the unlinked ed */
517 static int ep_unlink (ohci_t
*ohci
, ed_t
*ed
)
519 ed
->hwINFO
|= m32_swap (OHCI_ED_SKIP
);
523 if (ed
->ed_prev
== NULL
) {
525 ohci
->hc_control
&= ~OHCI_CTRL_CLE
;
526 writel (ohci
->hc_control
, &ohci
->regs
->control
);
528 writel (m32_swap (*((__u32
*)&ed
->hwNextED
)), &ohci
->regs
->ed_controlhead
);
530 ed
->ed_prev
->hwNextED
= ed
->hwNextED
;
532 if (ohci
->ed_controltail
== ed
) {
533 ohci
->ed_controltail
= ed
->ed_prev
;
535 ((ed_t
*)m32_swap (*((__u32
*)&ed
->hwNextED
)))->ed_prev
= ed
->ed_prev
;
540 if (ed
->ed_prev
== NULL
) {
542 ohci
->hc_control
&= ~OHCI_CTRL_BLE
;
543 writel (ohci
->hc_control
, &ohci
->regs
->control
);
545 writel (m32_swap (*((__u32
*)&ed
->hwNextED
)), &ohci
->regs
->ed_bulkhead
);
547 ed
->ed_prev
->hwNextED
= ed
->hwNextED
;
549 if (ohci
->ed_bulktail
== ed
) {
550 ohci
->ed_bulktail
= ed
->ed_prev
;
552 ((ed_t
*)m32_swap (*((__u32
*)&ed
->hwNextED
)))->ed_prev
= ed
->ed_prev
;
556 ed
->state
= ED_UNLINK
;
561 /*-------------------------------------------------------------------------*/
563 /* add/reinit an endpoint; this should be done once at the usb_set_configuration command,
564 * but the USB stack is a little bit stateless so we do it at every transaction
565 * if the state of the ed is ED_NEW then a dummy td is added and the state is changed to ED_UNLINK
566 * in all other cases the state is left unchanged
567 * the ed info fields are setted anyway even though most of them should not change */
569 static ed_t
* ep_add_ed (struct usb_device
*usb_dev
, unsigned long pipe
)
575 ed
= ed_ret
= &ohci_dev
.ed
[(usb_pipeendpoint (pipe
) << 1) |
576 (usb_pipecontrol (pipe
)? 0: usb_pipeout (pipe
))];
578 if ((ed
->state
& ED_DEL
) || (ed
->state
& ED_URB_DEL
)) {
579 err("ep_add_ed: pending delete");
580 /* pending delete request */
584 if (ed
->state
== ED_NEW
) {
585 ed
->hwINFO
= m32_swap (OHCI_ED_SKIP
); /* skip ed */
586 /* dummy td; end of td list for ed */
587 td
= td_alloc (usb_dev
);
588 ed
->hwTailP
= m32_swap (td
);
589 ed
->hwHeadP
= ed
->hwTailP
;
590 ed
->state
= ED_UNLINK
;
591 ed
->type
= usb_pipetype (pipe
);
595 ed
->hwINFO
= m32_swap (usb_pipedevice (pipe
)
596 | usb_pipeendpoint (pipe
) << 7
597 | (usb_pipeisoc (pipe
)? 0x8000: 0)
598 | (usb_pipecontrol (pipe
)? 0: (usb_pipeout (pipe
)? 0x800: 0x1000))
599 | (usb_dev
->speed
== USB_SPEED_LOW
) << 13
600 | usb_maxpacket (usb_dev
, pipe
) << 16);
605 /*-------------------------------------------------------------------------*
606 * TD handling functions
607 *-------------------------------------------------------------------------*/
609 /* enqueue next TD for this URB (OHCI spec 5.2.8.2) */
611 static void td_fill (ohci_t
*ohci
, unsigned int info
,
613 struct usb_device
*dev
, int index
, urb_priv_t
*urb_priv
)
615 volatile td_t
*td
, *td_pt
;
616 #ifdef OHCI_FILL_TRACE
620 if (index
> urb_priv
->length
) {
621 err("index > length");
624 /* use this td as the next dummy */
625 td_pt
= urb_priv
->td
[index
];
628 /* fill the old dummy TD */
629 td
= urb_priv
->td
[index
] = (td_t
*)(m32_swap (urb_priv
->ed
->hwTailP
) & ~0xf);
631 td
->ed
= urb_priv
->ed
;
632 td
->next_dl_td
= NULL
;
634 td
->data
= (__u32
)data
;
635 #ifdef OHCI_FILL_TRACE
636 if (1 || (usb_pipebulk(urb_priv
->pipe
) &&
637 usb_pipeout(urb_priv
->pipe
))) {
638 for (i
= 0; i
< len
; i
++)
639 printf("td->data[%d] %#2x\n",i
, ((unsigned char *)(td
->data
+0x80000000))[i
]);
645 td
->hwINFO
= m32_swap (info
);
646 td
->hwCBP
= m32_swap (data
);
648 td
->hwBE
= m32_swap (data
+ len
- 1);
651 td
->hwNextTD
= m32_swap (td_pt
);
652 td
->hwPSW
[0] = m16_swap (((__u32
)data
& 0x0FFF) | 0xE000);
654 /* append to queue */
655 td
->ed
->hwTailP
= td
->hwNextTD
;
658 /*-------------------------------------------------------------------------*/
660 /* prepare all TDs of a transfer */
662 #define kseg_to_phys(x) ((void *)((__u32)(x) - 0x80000000))
664 static void td_submit_job (struct usb_device
*dev
, unsigned long pipe
, void *buffer
,
665 int transfer_len
, struct devrequest
*setup
, urb_priv_t
*urb
, int interval
)
667 ohci_t
*ohci
= &gohci
;
668 int data_len
= transfer_len
;
672 unsigned int toggle
= 0;
674 /* OHCI handles the DATA-toggles itself, we just use the USB-toggle bits for reseting */
675 if(usb_gettoggle(dev
, usb_pipeendpoint(pipe
), usb_pipeout(pipe
))) {
676 toggle
= TD_T_TOGGLE
;
679 usb_settoggle(dev
, usb_pipeendpoint(pipe
), usb_pipeout(pipe
), 1);
683 data
= kseg_to_phys(buffer
);
687 switch (usb_pipetype (pipe
)) {
689 info
= usb_pipeout (pipe
)?
690 TD_CC
| TD_DP_OUT
: TD_CC
| TD_DP_IN
;
691 while(data_len
> 4096) {
692 td_fill (ohci
, info
| (cnt
? TD_T_TOGGLE
:toggle
), data
, 4096, dev
, cnt
, urb
);
693 data
+= 4096; data_len
-= 4096; cnt
++;
695 info
= usb_pipeout (pipe
)?
696 TD_CC
| TD_DP_OUT
: TD_CC
| TD_R
| TD_DP_IN
;
697 td_fill (ohci
, info
| (cnt
? TD_T_TOGGLE
:toggle
), data
, data_len
, dev
, cnt
, urb
);
701 writel (OHCI_BLF
, &ohci
->regs
->cmdstatus
); /* start bulk list */
705 info
= TD_CC
| TD_DP_SETUP
| TD_T_DATA0
;
706 td_fill (ohci
, info
, kseg_to_phys(setup
), 8, dev
, cnt
++, urb
);
708 info
= usb_pipeout (pipe
)?
709 TD_CC
| TD_R
| TD_DP_OUT
| TD_T_DATA1
: TD_CC
| TD_R
| TD_DP_IN
| TD_T_DATA1
;
710 /* NOTE: mishandles transfers >8K, some >4K */
711 td_fill (ohci
, info
, data
, data_len
, dev
, cnt
++, urb
);
713 info
= usb_pipeout (pipe
)?
714 TD_CC
| TD_DP_IN
| TD_T_DATA1
: TD_CC
| TD_DP_OUT
| TD_T_DATA1
;
715 td_fill (ohci
, info
, data
, 0, dev
, cnt
++, urb
);
717 writel (OHCI_CLF
, &ohci
->regs
->cmdstatus
); /* start Control list */
720 if (urb
->length
!= cnt
)
721 dbg("TD LENGTH %d != CNT %d", urb
->length
, cnt
);
724 /*-------------------------------------------------------------------------*
725 * Done List handling functions
726 *-------------------------------------------------------------------------*/
729 /* calculate the transfer length and update the urb */
731 static void dl_transfer_length(td_t
* td
)
733 __u32 tdINFO
, tdBE
, tdCBP
;
734 urb_priv_t
*lurb_priv
= &urb_priv
;
736 tdINFO
= m32_swap (td
->hwINFO
);
737 tdBE
= m32_swap (td
->hwBE
);
738 tdCBP
= m32_swap (td
->hwCBP
);
741 if (!(usb_pipecontrol(lurb_priv
->pipe
) &&
742 ((td
->index
== 0) || (td
->index
== lurb_priv
->length
- 1)))) {
745 lurb_priv
->actual_length
+= tdBE
- td
->data
+ 1;
747 lurb_priv
->actual_length
+= tdCBP
- td
->data
;
752 /*-------------------------------------------------------------------------*/
754 /* replies to the request have to be on a FIFO basis so
755 * we reverse the reversed done-list */
757 static td_t
* dl_reverse_done_list (ohci_t
*ohci
)
761 td_t
*td_list
= NULL
;
762 urb_priv_t
*lurb_priv
= NULL
;
764 td_list_hc
= m32_swap (ohci
->hcca
->done_head
) & 0xfffffff0;
765 ohci
->hcca
->done_head
= 0;
768 td_list
= (td_t
*)td_list_hc
;
770 if (TD_CC_GET (m32_swap (td_list
->hwINFO
))) {
771 lurb_priv
= &urb_priv
;
772 dbg(" USB-error/status: %x : %p",
773 TD_CC_GET (m32_swap (td_list
->hwINFO
)), td_list
);
774 if (td_list
->ed
->hwHeadP
& m32_swap (0x1)) {
775 if (lurb_priv
&& ((td_list
->index
+ 1) < lurb_priv
->length
)) {
776 td_list
->ed
->hwHeadP
=
777 (lurb_priv
->td
[lurb_priv
->length
- 1]->hwNextTD
& m32_swap (0xfffffff0)) |
778 (td_list
->ed
->hwHeadP
& m32_swap (0x2));
779 lurb_priv
->td_cnt
+= lurb_priv
->length
- td_list
->index
- 1;
781 td_list
->ed
->hwHeadP
&= m32_swap (0xfffffff2);
785 td_list
->next_dl_td
= td_rev
;
787 td_list_hc
= m32_swap (td_list
->hwNextTD
) & 0xfffffff0;
792 /*-------------------------------------------------------------------------*/
795 static int dl_done_list (ohci_t
*ohci
, td_t
*td_list
)
797 td_t
*td_list_next
= NULL
;
802 urb_priv_t
*lurb_priv
;
803 __u32 tdINFO
, edHeadP
, edTailP
;
806 td_list_next
= td_list
->next_dl_td
;
808 lurb_priv
= &urb_priv
;
809 tdINFO
= m32_swap (td_list
->hwINFO
);
813 dl_transfer_length(td_list
);
815 /* error code of transfer */
816 cc
= TD_CC_GET (tdINFO
);
818 dbg("ConditionCode %#x", cc
);
819 stat
= cc_to_error
[cc
];
822 if (ed
->state
!= ED_NEW
) {
823 edHeadP
= m32_swap (ed
->hwHeadP
) & 0xfffffff0;
824 edTailP
= m32_swap (ed
->hwTailP
);
826 /* unlink eds if they are not busy */
827 if ((edHeadP
== edTailP
) && (ed
->state
== ED_OPER
))
828 ep_unlink (ohci
, ed
);
831 td_list
= td_list_next
;
836 /*-------------------------------------------------------------------------*
838 *-------------------------------------------------------------------------*/
840 #include <usbroothubdes.h>
842 /* Hub class-specific descriptor is constructed dynamically */
845 /*-------------------------------------------------------------------------*/
847 #define OK(x) len = (x); break
849 #define WR_RH_STAT(x) {info("WR:status %#8x", (x));writel((x), &gohci.regs->roothub.status);}
850 #define WR_RH_PORTSTAT(x) {info("WR:portstatus[%d] %#8x", wIndex-1, (x));writel((x), &gohci.regs->roothub.portstatus[wIndex-1]);}
852 #define WR_RH_STAT(x) writel((x), &gohci.regs->roothub.status)
853 #define WR_RH_PORTSTAT(x) writel((x), &gohci.regs->roothub.portstatus[wIndex-1])
855 #define RD_RH_STAT roothub_status(&gohci)
856 #define RD_RH_PORTSTAT roothub_portstatus(&gohci,wIndex-1)
858 /* request to virtual root hub */
860 int rh_check_port_status(ohci_t
*controller
)
866 temp
= roothub_a (controller
);
867 ndp
= (temp
& RH_A_NDP
);
868 for (i
= 0; i
< ndp
; i
++) {
869 temp
= roothub_portstatus (controller
, i
);
870 /* check for a device disconnect */
871 if (((temp
& (RH_PS_PESC
| RH_PS_CSC
)) ==
872 (RH_PS_PESC
| RH_PS_CSC
)) &&
873 ((temp
& RH_PS_CCS
) == 0)) {
881 static int ohci_submit_rh_msg(struct usb_device
*dev
, unsigned long pipe
,
882 void *buffer
, int transfer_len
, struct devrequest
*cmd
)
884 void * data
= buffer
;
885 int leni
= transfer_len
;
889 __u8
*data_buf
= (__u8
*)datab
;
896 urb_priv
.actual_length
= 0;
897 pkt_print(dev
, pipe
, buffer
, transfer_len
, cmd
, "SUB(rh)", usb_pipein(pipe
));
901 if (usb_pipeint(pipe
)) {
902 info("Root-Hub submit IRQ: NOT implemented");
906 bmRType_bReq
= cmd
->requesttype
| (cmd
->request
<< 8);
907 wValue
= m16_swap (cmd
->value
);
908 wIndex
= m16_swap (cmd
->index
);
909 wLength
= m16_swap (cmd
->length
);
911 info("Root-Hub: adr: %2x cmd(%1x): %08x %04x %04x %04x",
912 dev
->devnum
, 8, bmRType_bReq
, wValue
, wIndex
, wLength
);
914 switch (bmRType_bReq
) {
915 /* Request Destination:
916 without flags: Device,
917 RH_INTERFACE: interface,
918 RH_ENDPOINT: endpoint,
919 RH_CLASS means HUB here,
920 RH_OTHER | RH_CLASS almost ever means HUB_PORT here
924 *(__u16
*) data_buf
= m16_swap (1); OK (2);
925 case RH_GET_STATUS
| RH_INTERFACE
:
926 *(__u16
*) data_buf
= m16_swap (0); OK (2);
927 case RH_GET_STATUS
| RH_ENDPOINT
:
928 *(__u16
*) data_buf
= m16_swap (0); OK (2);
929 case RH_GET_STATUS
| RH_CLASS
:
930 *(__u32
*) data_buf
= m32_swap (
931 RD_RH_STAT
& ~(RH_HS_CRWE
| RH_HS_DRWE
));
933 case RH_GET_STATUS
| RH_OTHER
| RH_CLASS
:
934 *(__u32
*) data_buf
= m32_swap (RD_RH_PORTSTAT
); OK (4);
936 case RH_CLEAR_FEATURE
| RH_ENDPOINT
:
938 case (RH_ENDPOINT_STALL
): OK (0);
942 case RH_CLEAR_FEATURE
| RH_CLASS
:
944 case RH_C_HUB_LOCAL_POWER
:
946 case (RH_C_HUB_OVER_CURRENT
):
947 WR_RH_STAT(RH_HS_OCIC
); OK (0);
951 case RH_CLEAR_FEATURE
| RH_OTHER
| RH_CLASS
:
953 case (RH_PORT_ENABLE
):
954 WR_RH_PORTSTAT (RH_PS_CCS
); OK (0);
955 case (RH_PORT_SUSPEND
):
956 WR_RH_PORTSTAT (RH_PS_POCI
); OK (0);
957 case (RH_PORT_POWER
):
958 WR_RH_PORTSTAT (RH_PS_LSDA
); OK (0);
959 case (RH_C_PORT_CONNECTION
):
960 WR_RH_PORTSTAT (RH_PS_CSC
); OK (0);
961 case (RH_C_PORT_ENABLE
):
962 WR_RH_PORTSTAT (RH_PS_PESC
); OK (0);
963 case (RH_C_PORT_SUSPEND
):
964 WR_RH_PORTSTAT (RH_PS_PSSC
); OK (0);
965 case (RH_C_PORT_OVER_CURRENT
):
966 WR_RH_PORTSTAT (RH_PS_OCIC
); OK (0);
967 case (RH_C_PORT_RESET
):
968 WR_RH_PORTSTAT (RH_PS_PRSC
); OK (0);
972 case RH_SET_FEATURE
| RH_OTHER
| RH_CLASS
:
974 case (RH_PORT_SUSPEND
):
975 WR_RH_PORTSTAT (RH_PS_PSS
); OK (0);
976 case (RH_PORT_RESET
): /* BUG IN HUP CODE *********/
977 if (RD_RH_PORTSTAT
& RH_PS_CCS
)
978 WR_RH_PORTSTAT (RH_PS_PRS
);
980 case (RH_PORT_POWER
):
981 WR_RH_PORTSTAT (RH_PS_PPS
); OK (0);
982 case (RH_PORT_ENABLE
): /* BUG IN HUP CODE *********/
983 if (RD_RH_PORTSTAT
& RH_PS_CCS
)
984 WR_RH_PORTSTAT (RH_PS_PES
);
989 case RH_SET_ADDRESS
: gohci
.rh
.devnum
= wValue
; OK(0);
991 case RH_GET_DESCRIPTOR
:
992 switch ((wValue
& 0xff00) >> 8) {
993 case (0x01): /* device descriptor */
994 len
= min_t(unsigned int,
997 sizeof (root_hub_dev_des
),
999 data_buf
= root_hub_dev_des
; OK(len
);
1000 case (0x02): /* configuration descriptor */
1001 len
= min_t(unsigned int,
1004 sizeof (root_hub_config_des
),
1006 data_buf
= root_hub_config_des
; OK(len
);
1007 case (0x03): /* string descriptors */
1008 if(wValue
==0x0300) {
1009 len
= min_t(unsigned int,
1012 sizeof (root_hub_str_index0
),
1014 data_buf
= root_hub_str_index0
;
1017 if(wValue
==0x0301) {
1018 len
= min_t(unsigned int,
1021 sizeof (root_hub_str_index1
),
1023 data_buf
= root_hub_str_index1
;
1027 stat
= USB_ST_STALLED
;
1031 case RH_GET_DESCRIPTOR
| RH_CLASS
:
1033 __u32 temp
= roothub_a (&gohci
);
1035 data_buf
[0] = 9; /* min length; */
1036 data_buf
[1] = 0x29;
1037 data_buf
[2] = temp
& RH_A_NDP
;
1039 if (temp
& RH_A_PSM
) /* per-port power switching? */
1040 data_buf
[3] |= 0x1;
1041 if (temp
& RH_A_NOCP
) /* no overcurrent reporting? */
1042 data_buf
[3] |= 0x10;
1043 else if (temp
& RH_A_OCPM
) /* per-port overcurrent reporting? */
1044 data_buf
[3] |= 0x8;
1046 /* corresponds to data_buf[4-7] */
1048 data_buf
[5] = (temp
& RH_A_POTPGT
) >> 24;
1049 temp
= roothub_b (&gohci
);
1050 data_buf
[7] = temp
& RH_B_DR
;
1051 if (data_buf
[2] < 7) {
1052 data_buf
[8] = 0xff;
1055 data_buf
[8] = (temp
& RH_B_DR
) >> 8;
1056 data_buf
[10] = data_buf
[9] = 0xff;
1059 len
= min_t(unsigned int, leni
,
1060 min_t(unsigned int, data_buf
[0], wLength
));
1064 case RH_GET_CONFIGURATION
: *(__u8
*) data_buf
= 0x01; OK (1);
1066 case RH_SET_CONFIGURATION
: WR_RH_STAT (0x10000); OK (0);
1069 dbg ("unsupported root hub command");
1070 stat
= USB_ST_STALLED
;
1074 ohci_dump_roothub (&gohci
, 1);
1079 len
= min_t(int, len
, leni
);
1080 if (data
!= data_buf
)
1081 memcpy (data
, data_buf
, len
);
1087 urb_priv
.actual_length
= transfer_len
;
1088 pkt_print(dev
, pipe
, buffer
, transfer_len
, cmd
, "RET(rh)", 0/*usb_pipein(pipe)*/);
1096 /*-------------------------------------------------------------------------*/
1098 /* common code for handling submit messages - used for all but root hub */
1100 int submit_common_msg(struct usb_device
*dev
, unsigned long pipe
, void *buffer
,
1101 int transfer_len
, struct devrequest
*setup
, int interval
)
1104 int maxsize
= usb_maxpacket(dev
, pipe
);
1107 /* device pulled? Shortcut the action. */
1108 if (devgone
== dev
) {
1109 dev
->status
= USB_ST_CRC_ERR
;
1114 urb_priv
.actual_length
= 0;
1115 pkt_print(dev
, pipe
, buffer
, transfer_len
, setup
, "SUB", usb_pipein(pipe
));
1120 err("submit_common_message: pipesize for pipe %lx is zero",
1125 if (sohci_submit_job(dev
, pipe
, buffer
, transfer_len
, setup
, interval
) < 0) {
1126 err("sohci_submit_job failed");
1131 /* ohci_dump_status(&gohci); */
1133 /* allow more time for a BULK device to react - some are slow */
1134 #define BULK_TO 5000 /* timeout in milliseconds */
1135 if (usb_pipebulk(pipe
))
1141 /* wait for it to complete */
1143 /* check whether the controller is done */
1144 stat
= hc_interrupt();
1146 stat
= USB_ST_CRC_ERR
;
1149 if (stat
>= 0 && stat
!= 0xff) {
1150 /* 0xff is returned for an SF-interrupt */
1154 udelay(250); /* mdelay(1); */
1156 err("CTL:TIMEOUT ");
1157 stat
= USB_ST_CRC_ERR
;
1161 /* we got an Root Hub Status Change interrupt */
1164 ohci_dump_roothub (&gohci
, 1);
1168 timeout
= rh_check_port_status(&gohci
);
1170 #if 0 /* this does nothing useful, but leave it here in case that changes */
1171 /* the called routine adds 1 to the passed value */
1172 usb_hub_port_connect_change(gohci
.rh
.dev
, timeout
- 1);
1176 * This is potentially dangerous because it assumes
1177 * that only one device is ever plugged in!
1184 dev
->act_len
= transfer_len
;
1187 pkt_print(dev
, pipe
, buffer
, transfer_len
, setup
, "RET(ctlr)", usb_pipein(pipe
));
1192 /* free TDs in urb_priv */
1193 urb_free_priv (&urb_priv
);
1197 /* submit routines called from usb.c */
1198 int submit_bulk_msg(struct usb_device
*dev
, unsigned long pipe
, void *buffer
,
1201 info("submit_bulk_msg");
1202 return submit_common_msg(dev
, pipe
, buffer
, transfer_len
, NULL
, 0);
1205 int submit_control_msg(struct usb_device
*dev
, unsigned long pipe
, void *buffer
,
1206 int transfer_len
, struct devrequest
*setup
)
1208 int maxsize
= usb_maxpacket(dev
, pipe
);
1210 info("submit_control_msg");
1212 urb_priv
.actual_length
= 0;
1213 pkt_print(dev
, pipe
, buffer
, transfer_len
, setup
, "SUB", usb_pipein(pipe
));
1218 err("submit_control_message: pipesize for pipe %lx is zero",
1222 if (((pipe
>> 8) & 0x7f) == gohci
.rh
.devnum
) {
1224 /* root hub - redirect */
1225 return ohci_submit_rh_msg(dev
, pipe
, buffer
, transfer_len
,
1229 return submit_common_msg(dev
, pipe
, buffer
, transfer_len
, setup
, 0);
1232 int submit_int_msg(struct usb_device
*dev
, unsigned long pipe
, void *buffer
,
1233 int transfer_len
, int interval
)
1235 info("submit_int_msg");
1239 /*-------------------------------------------------------------------------*
1241 *-------------------------------------------------------------------------*/
1243 /* reset the HC and BUS */
1245 static int hc_reset (ohci_t
*ohci
)
1248 int smm_timeout
= 50; /* 0,5 sec */
1250 if (readl (&ohci
->regs
->control
) & OHCI_CTRL_IR
) { /* SMM owns the HC */
1251 writel (OHCI_OCR
, &ohci
->regs
->cmdstatus
); /* request ownership */
1252 info("USB HC TakeOver from SMM");
1253 while (readl (&ohci
->regs
->control
) & OHCI_CTRL_IR
) {
1255 if (--smm_timeout
== 0) {
1256 err("USB HC TakeOver failed!");
1262 /* Disable HC interrupts */
1263 writel (OHCI_INTR_MIE
, &ohci
->regs
->intrdisable
);
1265 dbg("USB HC reset_hc usb-%s: ctrl = 0x%X ;",
1267 readl (&ohci
->regs
->control
));
1269 /* Reset USB (needed by some controllers) */
1270 writel (0, &ohci
->regs
->control
);
1272 /* HC Reset requires max 10 us delay */
1273 writel (OHCI_HCR
, &ohci
->regs
->cmdstatus
);
1274 while ((readl (&ohci
->regs
->cmdstatus
) & OHCI_HCR
) != 0) {
1275 if (--timeout
== 0) {
1276 err("USB HC reset timed out!");
1284 /*-------------------------------------------------------------------------*/
1286 /* Start an OHCI controller, set the BUS operational
1288 * connect the virtual root hub */
1290 static int hc_start (ohci_t
* ohci
)
1293 unsigned int fminterval
;
1297 /* Tell the controller where the control and bulk lists are
1298 * The lists are empty now. */
1300 writel (0, &ohci
->regs
->ed_controlhead
);
1301 writel (0, &ohci
->regs
->ed_bulkhead
);
1303 writel ((__u32
)ohci
->hcca
, &ohci
->regs
->hcca
); /* a reset clears this */
1305 fminterval
= 0x2edf;
1306 writel ((fminterval
* 9) / 10, &ohci
->regs
->periodicstart
);
1307 fminterval
|= ((((fminterval
- 210) * 6) / 7) << 16);
1308 writel (fminterval
, &ohci
->regs
->fminterval
);
1309 writel (0x628, &ohci
->regs
->lsthresh
);
1311 /* start controller operations */
1312 ohci
->hc_control
= OHCI_CONTROL_INIT
| OHCI_USB_OPER
;
1314 writel (ohci
->hc_control
, &ohci
->regs
->control
);
1316 /* disable all interrupts */
1317 mask
= (OHCI_INTR_SO
| OHCI_INTR_WDH
| OHCI_INTR_SF
| OHCI_INTR_RD
|
1318 OHCI_INTR_UE
| OHCI_INTR_FNO
| OHCI_INTR_RHSC
|
1319 OHCI_INTR_OC
| OHCI_INTR_MIE
);
1320 writel (mask
, &ohci
->regs
->intrdisable
);
1321 /* clear all interrupts */
1322 mask
&= ~OHCI_INTR_MIE
;
1323 writel (mask
, &ohci
->regs
->intrstatus
);
1324 /* Choose the interrupts we care about now - but w/o MIE */
1325 mask
= OHCI_INTR_RHSC
| OHCI_INTR_UE
| OHCI_INTR_WDH
| OHCI_INTR_SO
;
1326 writel (mask
, &ohci
->regs
->intrenable
);
1329 /* required for AMD-756 and some Mac platforms */
1330 writel ((roothub_a (ohci
) | RH_A_NPS
) & ~RH_A_PSM
,
1331 &ohci
->regs
->roothub
.a
);
1332 writel (RH_HS_LPSC
, &ohci
->regs
->roothub
.status
);
1333 #endif /* OHCI_USE_NPS */
1335 /* POTPGT delay is bits 24-31, in 2 ms units. */
1336 mdelay ((roothub_a (ohci
) >> 23) & 0x1fe);
1338 /* connect the virtual root hub */
1339 ohci
->rh
.devnum
= 0;
1344 /*-------------------------------------------------------------------------*/
1346 /* an interrupt happens */
1351 ohci_t
*ohci
= &gohci
;
1352 struct ohci_regs
*regs
= ohci
->regs
;
1356 if ((ohci
->hcca
->done_head
!= 0) && !(m32_swap (ohci
->hcca
->done_head
) & 0x01)) {
1357 ints
= OHCI_INTR_WDH
;
1359 ints
= readl (®s
->intrstatus
);
1362 /* dbg("Interrupt: %x frame: %x", ints, le16_to_cpu (ohci->hcca->frame_no)); */
1364 if (ints
& OHCI_INTR_RHSC
) {
1368 if (ints
& OHCI_INTR_UE
) {
1370 err ("OHCI Unrecoverable Error, controller usb-%s disabled",
1372 /* e.g. due to PCI Master/Target Abort */
1375 ohci_dump (ohci
, 1);
1379 /* FIXME: be optimistic, hope that bug won't repeat often. */
1380 /* Make some non-interrupt context restart the controller. */
1381 /* Count and limit the retries though; either hardware or */
1382 /* software errors can go forever... */
1387 if (ints
& OHCI_INTR_WDH
) {
1389 writel (OHCI_INTR_WDH
, ®s
->intrdisable
);
1390 stat
= dl_done_list (&gohci
, dl_reverse_done_list (&gohci
));
1391 writel (OHCI_INTR_WDH
, ®s
->intrenable
);
1394 if (ints
& OHCI_INTR_SO
) {
1395 dbg("USB Schedule overrun\n");
1396 writel (OHCI_INTR_SO
, ®s
->intrenable
);
1400 /* FIXME: this assumes SOF (1/ms) interrupts don't get lost... */
1401 if (ints
& OHCI_INTR_SF
) {
1402 unsigned int frame
= m16_swap (ohci
->hcca
->frame_no
) & 1;
1404 writel (OHCI_INTR_SF
, ®s
->intrdisable
);
1405 if (ohci
->ed_rm_list
[frame
] != NULL
)
1406 writel (OHCI_INTR_SF
, ®s
->intrenable
);
1410 writel (ints
, ®s
->intrstatus
);
1414 /*-------------------------------------------------------------------------*/
1416 /*-------------------------------------------------------------------------*/
1418 /* De-allocate all resources.. */
1420 static void hc_release_ohci (ohci_t
*ohci
)
1422 dbg ("USB HC release ohci usb-%s", ohci
->slot_name
);
1424 if (!ohci
->disabled
)
1428 /*-------------------------------------------------------------------------*/
1430 #define __read_32bit_c0_register(source, sel) \
1433 __asm__ __volatile__( \
1434 "mfc0\t%0, " #source "\n\t" \
1437 __asm__ __volatile__( \
1438 ".set\tmips32\n\t" \
1439 "mfc0\t%0, " #source ", " #sel "\n\t" \
1445 #define read_c0_prid() __read_32bit_c0_register($15, 0)
1448 * low level initalisation routine, called from usb.c
1450 static char ohci_inited
= 0;
1452 int usb_lowlevel_init(int index
, enum usb_init_type init
, void **controller
)
1455 u32 sys_freqctrl
, sys_clksrc
;
1456 u32 prid
= read_c0_prid();
1458 dbg("in usb_lowlevel_init\n");
1460 /* zero and disable FREQ2 */
1461 sys_freqctrl
= au_readl(SYS_FREQCTRL0
);
1462 sys_freqctrl
&= ~0xFFF00000;
1463 au_writel(sys_freqctrl
, SYS_FREQCTRL0
);
1465 /* zero and disable USBH/USBD clocks */
1466 sys_clksrc
= au_readl(SYS_CLKSRC
);
1467 sys_clksrc
&= ~0x00007FE0;
1468 au_writel(sys_clksrc
, SYS_CLKSRC
);
1470 sys_freqctrl
= au_readl(SYS_FREQCTRL0
);
1471 sys_freqctrl
&= ~0xFFF00000;
1473 sys_clksrc
= au_readl(SYS_CLKSRC
);
1474 sys_clksrc
&= ~0x00007FE0;
1476 switch (prid
& 0x000000FF) {
1480 /* CPU core freq to 48MHz to slow it way down... */
1481 au_writel(4, SYS_CPUPLL
);
1484 * Setup 48MHz FREQ2 from CPUPLL for USB Host
1486 /* FRDIV2=3 -> div by 8 of 384MHz -> 48MHz */
1487 sys_freqctrl
|= ((3<<22) | (1<<21) | (0<<20));
1488 au_writel(sys_freqctrl
, SYS_FREQCTRL0
);
1490 /* CPU core freq to 384MHz */
1491 au_writel(0x20, SYS_CPUPLL
);
1493 printf("Au1000: 48MHz OHCI workaround enabled\n");
1496 default: /* HC and newer */
1497 /* FREQ2 = aux/2 = 48 MHz */
1498 sys_freqctrl
|= ((0<<22) | (1<<21) | (1<<20));
1499 au_writel(sys_freqctrl
, SYS_FREQCTRL0
);
1504 * Route 48MHz FREQ2 into USB Host and/or Device
1506 sys_clksrc
|= ((4<<12) | (0<<11) | (0<<10));
1507 au_writel(sys_clksrc
, SYS_CLKSRC
);
1509 /* configure pins GPIO[14:9] as GPIO */
1510 pin_func
= au_readl(SYS_PINFUNC
) & (u32
)(~0x8080);
1512 au_writel(pin_func
, SYS_PINFUNC
);
1513 au_writel(0x2800, SYS_TRIOUTCLR
);
1514 au_writel(0x0030, SYS_OUTPUTCLR
);
1516 dbg("OHCI board setup complete\n");
1518 /* enable host controller */
1519 au_writel(USBH_ENABLE_CE
, USB_HOST_CONFIG
);
1521 au_writel(USBH_ENABLE_INIT
, USB_HOST_CONFIG
);
1524 /* wait for reset complete (read register twice; see au1500 errata) */
1525 while (au_readl(USB_HOST_CONFIG
),
1526 !(au_readl(USB_HOST_CONFIG
) & USBH_ENABLE_RD
))
1529 dbg("OHCI clock running\n");
1531 memset (&gohci
, 0, sizeof (ohci_t
));
1532 memset (&urb_priv
, 0, sizeof (urb_priv_t
));
1534 /* align the storage */
1535 if ((__u32
)&ghcca
[0] & 0xff) {
1536 err("HCCA not aligned!!");
1540 info("aligned ghcca %p", phcca
);
1541 memset(&ohci_dev
, 0, sizeof(struct ohci_device
));
1542 if ((__u32
)&ohci_dev
.ed
[0] & 0x7) {
1543 err("EDs not aligned!!");
1546 memset(gtd
, 0, sizeof(td_t
) * (NUM_TD
+ 1));
1547 if ((__u32
)gtd
& 0x7) {
1548 err("TDs not aligned!!");
1553 memset (phcca
, 0, sizeof (struct ohci_hcca
));
1558 gohci
.regs
= (struct ohci_regs
*)(USB_OHCI_BASE
| 0xA0000000);
1561 gohci
.slot_name
= "au1x00";
1563 dbg("OHCI revision: 0x%08x\n"
1564 " RH: a: 0x%08x b: 0x%08x\n",
1565 readl(&gohci
.regs
->revision
),
1566 readl(&gohci
.regs
->roothub
.a
), readl(&gohci
.regs
->roothub
.b
));
1568 if (hc_reset (&gohci
) < 0)
1571 /* FIXME this is a second HC reset; why?? */
1572 writel (gohci
.hc_control
= OHCI_USB_RESET
, &gohci
.regs
->control
);
1575 if (hc_start (&gohci
) < 0)
1579 ohci_dump (&gohci
, 1);
1587 err("OHCI initialization error\n");
1588 hc_release_ohci (&gohci
);
1589 /* Initialization failed */
1590 au_writel(readl(USB_HOST_CONFIG
) & ~USBH_ENABLE_CE
, USB_HOST_CONFIG
);
1594 int usb_lowlevel_stop(int index
)
1596 /* this gets called really early - before the controller has */
1597 /* even been initialized! */
1600 /* TODO release any interrupts, etc. */
1601 /* call hc_release_ohci() here ? */
1603 /* may not want to do this */
1605 au_writel(readl(USB_HOST_CONFIG
) & ~USBH_ENABLE_CE
, USB_HOST_CONFIG
);
1609 #endif /* CONFIG_USB_OHCI */