2 * URB OHCI HCD (Host Controller Driver) for USB on the PPC440EP.
4 * (C) Copyright 2003-2004
5 * Gary Jennejohn, DENX Software Engineering <garyj@denx.de>
8 * Pierre Aubert, Staubli Faverges <p.aubert@staubli.com>
10 * Note: Much of this code has been derived from Linux 2.4
11 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
12 * (C) Copyright 2000-2002 David Brownell
14 * SPDX-License-Identifier: GPL-2.0+
18 * 1 - this driver is intended for use with USB Mass Storage Devices
19 * (BBB) ONLY. There is NO support for Interrupt or Isochronous pipes!
24 #ifdef CONFIG_USB_OHCI
30 #define OHCI_USE_NPS /* force NoPowerSwitching mode */
31 #undef OHCI_VERBOSE_DEBUG /* not always helpful */
34 #undef OHCI_FILL_TRACE
36 /* For initializing controller (mask in an HCFS mode too) */
37 #define OHCI_CONTROL_INIT \
38 (OHCI_CTRL_CBSR & 0x3) | OHCI_CTRL_IE | OHCI_CTRL_PLE
40 #define readl(a) (*((volatile u32 *)(a)))
41 #define writel(a, b) (*((volatile u32 *)(b)) = ((volatile u32)a))
44 #define dbg(format, arg...) printf("DEBUG: " format "\n", ## arg)
46 #define dbg(format, arg...) do {} while(0)
48 #define err(format, arg...) printf("ERROR: " format "\n", ## arg)
50 #define info(format, arg...) printf("INFO: " format "\n", ## arg)
52 #define info(format, arg...) do {} while(0)
55 #define m16_swap(x) swap_16(x)
56 #define m32_swap(x) swap_32(x)
58 #if defined(CONFIG_405EZ) || defined(CONFIG_440EP) || defined(CONFIG_440EPX)
59 #define ohci_cpu_to_le16(x) (x)
60 #define ohci_cpu_to_le32(x) (x)
62 #define ohci_cpu_to_le16(x) swap_16(x)
63 #define ohci_cpu_to_le32(x) swap_32(x)
68 /* this must be aligned to a 256 byte boundary */
69 struct ohci_hcca ghcca
[1];
70 /* a pointer to the aligned storage */
71 struct ohci_hcca
*phcca
;
72 /* this allocates EDs for all possible endpoints */
73 struct ohci_device ohci_dev
;
78 /* device which was disconnected */
79 struct usb_device
*devgone
;
80 /* flag guarding URB transation */
83 /*-------------------------------------------------------------------------*/
85 /* AMD-756 (D2 rev) reports corrupt register contents in some cases.
86 * The erratum (#4) description is incorrect. AMD's workaround waits
87 * till some bits (mostly reserved) are clear; ok for all revs.
89 #define OHCI_QUIRK_AMD756 0xabcd
90 #define read_roothub(hc, register, mask) ({ \
91 u32 temp = readl (&hc->regs->roothub.register); \
92 if (hc->flags & OHCI_QUIRK_AMD756) \
94 temp = readl (&hc->regs->roothub.register); \
97 static u32
roothub_a (struct ohci
*hc
)
98 { return read_roothub (hc
, a
, 0xfc0fe000); }
99 static inline u32
roothub_b (struct ohci
*hc
)
100 { return readl (&hc
->regs
->roothub
.b
); }
101 static inline u32
roothub_status (struct ohci
*hc
)
102 { return readl (&hc
->regs
->roothub
.status
); }
103 static u32
roothub_portstatus (struct ohci
*hc
, int i
)
104 { return read_roothub (hc
, portstatus
[i
], 0xffe0fce0); }
107 /* forward declaration */
108 static int hc_interrupt (void);
110 td_submit_job (struct usb_device
* dev
, unsigned long pipe
, void * buffer
,
111 int transfer_len
, struct devrequest
* setup
, urb_priv_t
* urb
, int interval
);
113 /*-------------------------------------------------------------------------*
114 * URB support functions
115 *-------------------------------------------------------------------------*/
117 /* free HCD-private data associated with this URB */
119 static void urb_free_priv (urb_priv_t
* urb
)
125 last
= urb
->length
- 1;
127 for (i
= 0; i
<= last
; i
++) {
137 /*-------------------------------------------------------------------------*/
140 static int sohci_get_current_frame_number (struct usb_device
* dev
);
142 /* debug| print the main components of an URB
143 * small: 0) header + data packets 1) just header */
145 static void pkt_print (struct usb_device
* dev
, unsigned long pipe
, void * buffer
,
146 int transfer_len
, struct devrequest
* setup
, char * str
, int small
)
148 urb_priv_t
* purb
= &urb_priv
;
150 dbg("%s URB:[%4x] dev:%2d,ep:%2d-%c,type:%s,len:%d/%d stat:%#lx",
152 sohci_get_current_frame_number (dev
),
153 usb_pipedevice (pipe
),
154 usb_pipeendpoint (pipe
),
155 usb_pipeout (pipe
)? 'O': 'I',
156 usb_pipetype (pipe
) < 2? (usb_pipeint (pipe
)? "INTR": "ISOC"):
157 (usb_pipecontrol (pipe
)? "CTRL": "BULK"),
159 transfer_len
, dev
->status
);
160 #ifdef OHCI_VERBOSE_DEBUG
164 if (usb_pipecontrol (pipe
)) {
165 printf (__FILE__
": cmd(8):");
166 for (i
= 0; i
< 8 ; i
++)
167 printf (" %02x", ((__u8
*) setup
) [i
]);
170 if (transfer_len
> 0 && buffer
) {
171 printf (__FILE__
": data(%d/%d):",
174 len
= usb_pipeout (pipe
)?
175 transfer_len
: purb
->actual_length
;
176 for (i
= 0; i
< 16 && i
< len
; i
++)
177 printf (" %02x", ((__u8
*) buffer
) [i
]);
178 printf ("%s\n", i
< len
? "...": "");
184 /* just for debugging; prints non-empty branches of the int ed tree inclusive iso eds*/
185 void ep_print_int_eds (ohci_t
*ohci
, char * str
) {
188 for (i
= 0; i
< 32; i
++) {
190 ed_p
= &(ohci
->hcca
->int_table
[i
]);
193 printf (__FILE__
": %s branch int %2d(%2x):", str
, i
, i
);
194 while (*ed_p
!= 0 && j
--) {
195 ed_t
*ed
= (ed_t
*)ohci_cpu_to_le32(ed_p
);
196 printf (" ed: %4x;", ed
->hwINFO
);
197 ed_p
= &ed
->hwNextED
;
203 static void ohci_dump_intr_mask (char *label
, __u32 mask
)
205 dbg ("%s: 0x%08x%s%s%s%s%s%s%s%s%s",
208 (mask
& OHCI_INTR_MIE
) ? " MIE" : "",
209 (mask
& OHCI_INTR_OC
) ? " OC" : "",
210 (mask
& OHCI_INTR_RHSC
) ? " RHSC" : "",
211 (mask
& OHCI_INTR_FNO
) ? " FNO" : "",
212 (mask
& OHCI_INTR_UE
) ? " UE" : "",
213 (mask
& OHCI_INTR_RD
) ? " RD" : "",
214 (mask
& OHCI_INTR_SF
) ? " SF" : "",
215 (mask
& OHCI_INTR_WDH
) ? " WDH" : "",
216 (mask
& OHCI_INTR_SO
) ? " SO" : ""
220 static void maybe_print_eds (char *label
, __u32 value
)
222 ed_t
*edp
= (ed_t
*)value
;
225 dbg ("%s %08x", label
, value
);
226 dbg ("%08x", edp
->hwINFO
);
227 dbg ("%08x", edp
->hwTailP
);
228 dbg ("%08x", edp
->hwHeadP
);
229 dbg ("%08x", edp
->hwNextED
);
233 static char * hcfs2string (int state
)
236 case OHCI_USB_RESET
: return "reset";
237 case OHCI_USB_RESUME
: return "resume";
238 case OHCI_USB_OPER
: return "operational";
239 case OHCI_USB_SUSPEND
: return "suspend";
244 /* dump control and status registers */
245 static void ohci_dump_status (ohci_t
*controller
)
247 struct ohci_regs
*regs
= controller
->regs
;
250 temp
= readl (®s
->revision
) & 0xff;
252 dbg ("spec %d.%d", (temp
>> 4), (temp
& 0x0f));
254 temp
= readl (®s
->control
);
255 dbg ("control: 0x%08x%s%s%s HCFS=%s%s%s%s%s CBSR=%d", temp
,
256 (temp
& OHCI_CTRL_RWE
) ? " RWE" : "",
257 (temp
& OHCI_CTRL_RWC
) ? " RWC" : "",
258 (temp
& OHCI_CTRL_IR
) ? " IR" : "",
259 hcfs2string (temp
& OHCI_CTRL_HCFS
),
260 (temp
& OHCI_CTRL_BLE
) ? " BLE" : "",
261 (temp
& OHCI_CTRL_CLE
) ? " CLE" : "",
262 (temp
& OHCI_CTRL_IE
) ? " IE" : "",
263 (temp
& OHCI_CTRL_PLE
) ? " PLE" : "",
264 temp
& OHCI_CTRL_CBSR
267 temp
= readl (®s
->cmdstatus
);
268 dbg ("cmdstatus: 0x%08x SOC=%d%s%s%s%s", temp
,
269 (temp
& OHCI_SOC
) >> 16,
270 (temp
& OHCI_OCR
) ? " OCR" : "",
271 (temp
& OHCI_BLF
) ? " BLF" : "",
272 (temp
& OHCI_CLF
) ? " CLF" : "",
273 (temp
& OHCI_HCR
) ? " HCR" : ""
276 ohci_dump_intr_mask ("intrstatus", readl (®s
->intrstatus
));
277 ohci_dump_intr_mask ("intrenable", readl (®s
->intrenable
));
279 maybe_print_eds ("ed_periodcurrent", readl (®s
->ed_periodcurrent
));
281 maybe_print_eds ("ed_controlhead", readl (®s
->ed_controlhead
));
282 maybe_print_eds ("ed_controlcurrent", readl (®s
->ed_controlcurrent
));
284 maybe_print_eds ("ed_bulkhead", readl (®s
->ed_bulkhead
));
285 maybe_print_eds ("ed_bulkcurrent", readl (®s
->ed_bulkcurrent
));
287 maybe_print_eds ("donehead", readl (®s
->donehead
));
290 static void ohci_dump_roothub (ohci_t
*controller
, int verbose
)
294 temp
= roothub_a (controller
);
295 ndp
= (temp
& RH_A_NDP
);
298 dbg ("roothub.a: %08x POTPGT=%d%s%s%s%s%s NDP=%d", temp
,
299 ((temp
& RH_A_POTPGT
) >> 24) & 0xff,
300 (temp
& RH_A_NOCP
) ? " NOCP" : "",
301 (temp
& RH_A_OCPM
) ? " OCPM" : "",
302 (temp
& RH_A_DT
) ? " DT" : "",
303 (temp
& RH_A_NPS
) ? " NPS" : "",
304 (temp
& RH_A_PSM
) ? " PSM" : "",
307 temp
= roothub_b (controller
);
308 dbg ("roothub.b: %08x PPCM=%04x DR=%04x",
310 (temp
& RH_B_PPCM
) >> 16,
313 temp
= roothub_status (controller
);
314 dbg ("roothub.status: %08x%s%s%s%s%s%s",
316 (temp
& RH_HS_CRWE
) ? " CRWE" : "",
317 (temp
& RH_HS_OCIC
) ? " OCIC" : "",
318 (temp
& RH_HS_LPSC
) ? " LPSC" : "",
319 (temp
& RH_HS_DRWE
) ? " DRWE" : "",
320 (temp
& RH_HS_OCI
) ? " OCI" : "",
321 (temp
& RH_HS_LPS
) ? " LPS" : ""
325 for (i
= 0; i
< ndp
; i
++) {
326 temp
= roothub_portstatus (controller
, i
);
327 dbg ("roothub.portstatus [%d] = 0x%08x%s%s%s%s%s%s%s%s%s%s%s%s",
330 (temp
& RH_PS_PRSC
) ? " PRSC" : "",
331 (temp
& RH_PS_OCIC
) ? " OCIC" : "",
332 (temp
& RH_PS_PSSC
) ? " PSSC" : "",
333 (temp
& RH_PS_PESC
) ? " PESC" : "",
334 (temp
& RH_PS_CSC
) ? " CSC" : "",
336 (temp
& RH_PS_LSDA
) ? " LSDA" : "",
337 (temp
& RH_PS_PPS
) ? " PPS" : "",
338 (temp
& RH_PS_PRS
) ? " PRS" : "",
339 (temp
& RH_PS_POCI
) ? " POCI" : "",
340 (temp
& RH_PS_PSS
) ? " PSS" : "",
342 (temp
& RH_PS_PES
) ? " PES" : "",
343 (temp
& RH_PS_CCS
) ? " CCS" : ""
348 static void ohci_dump (ohci_t
*controller
, int verbose
)
350 dbg ("OHCI controller usb-%s state", controller
->slot_name
);
352 /* dumps some of the state we know about */
353 ohci_dump_status (controller
);
355 ep_print_int_eds (controller
, "hcca");
356 dbg ("hcca frame #%04x", controller
->hcca
->frame_no
);
357 ohci_dump_roothub (controller
, 1);
363 /*-------------------------------------------------------------------------*
364 * Interface functions (URB)
365 *-------------------------------------------------------------------------*/
367 /* get a transfer request */
369 int sohci_submit_job(struct usb_device
*dev
, unsigned long pipe
, void *buffer
,
370 int transfer_len
, struct devrequest
*setup
, int interval
)
374 urb_priv_t
*purb_priv
;
379 /* when controller's hung, permit only roothub cleanup attempts
380 * such as powering down ports */
381 if (ohci
->disabled
) {
382 err("sohci_submit_job: EPIPE");
386 /* if we have an unfinished URB from previous transaction let's
387 * fail and scream as quickly as possible so as not to corrupt
388 * further communication */
390 err("sohci_submit_job: URB NOT FINISHED");
393 /* we're about to begin a new transaction here so mark the URB unfinished */
396 /* every endpoint has a ed, locate and fill it */
397 if (!(ed
= ep_add_ed (dev
, pipe
))) {
398 err("sohci_submit_job: ENOMEM");
402 /* for the private part of the URB we need the number of TDs (size) */
403 switch (usb_pipetype (pipe
)) {
404 case PIPE_BULK
: /* one TD for every 4096 Byte */
405 size
= (transfer_len
- 1) / 4096 + 1;
407 case PIPE_CONTROL
: /* 1 TD for setup, 1 for ACK and 1 for every 4096 B */
408 size
= (transfer_len
== 0)? 2:
409 (transfer_len
- 1) / 4096 + 3;
413 if (size
>= (N_URB_TD
- 1)) {
414 err("need %d TDs, only have %d", size
, N_URB_TD
);
417 purb_priv
= &urb_priv
;
418 purb_priv
->pipe
= pipe
;
420 /* fill the private part of the URB */
421 purb_priv
->length
= size
;
423 purb_priv
->actual_length
= 0;
425 /* allocate the TDs */
426 /* note that td[0] was allocated in ep_add_ed */
427 for (i
= 0; i
< size
; i
++) {
428 purb_priv
->td
[i
] = td_alloc (dev
);
429 if (!purb_priv
->td
[i
]) {
430 purb_priv
->length
= i
;
431 urb_free_priv (purb_priv
);
432 err("sohci_submit_job: ENOMEM");
437 if (ed
->state
== ED_NEW
|| (ed
->state
& ED_DEL
)) {
438 urb_free_priv (purb_priv
);
439 err("sohci_submit_job: EINVAL");
443 /* link the ed into a chain if is not already */
444 if (ed
->state
!= ED_OPER
)
447 /* fill the TDs and link it to the ed */
448 td_submit_job(dev
, pipe
, buffer
, transfer_len
, setup
, purb_priv
, interval
);
453 /*-------------------------------------------------------------------------*/
456 /* tell us the current USB frame number */
458 static int sohci_get_current_frame_number (struct usb_device
*usb_dev
)
460 ohci_t
*ohci
= &gohci
;
462 return ohci_cpu_to_le16 (ohci
->hcca
->frame_no
);
466 /*-------------------------------------------------------------------------*
467 * ED handling functions
468 *-------------------------------------------------------------------------*/
470 /* link an ed into one of the HC chains */
472 static int ep_link (ohci_t
*ohci
, ed_t
*edi
)
474 volatile ed_t
*ed
= edi
;
481 if (ohci
->ed_controltail
== NULL
) {
482 writel (ed
, &ohci
->regs
->ed_controlhead
);
484 ohci
->ed_controltail
->hwNextED
= ohci_cpu_to_le32 ((unsigned long)ed
);
486 ed
->ed_prev
= ohci
->ed_controltail
;
487 if (!ohci
->ed_controltail
&& !ohci
->ed_rm_list
[0] &&
488 !ohci
->ed_rm_list
[1] && !ohci
->sleeping
) {
489 ohci
->hc_control
|= OHCI_CTRL_CLE
;
490 writel (ohci
->hc_control
, &ohci
->regs
->control
);
492 ohci
->ed_controltail
= edi
;
497 if (ohci
->ed_bulktail
== NULL
) {
498 writel (ed
, &ohci
->regs
->ed_bulkhead
);
500 ohci
->ed_bulktail
->hwNextED
= ohci_cpu_to_le32 ((unsigned long)ed
);
502 ed
->ed_prev
= ohci
->ed_bulktail
;
503 if (!ohci
->ed_bulktail
&& !ohci
->ed_rm_list
[0] &&
504 !ohci
->ed_rm_list
[1] && !ohci
->sleeping
) {
505 ohci
->hc_control
|= OHCI_CTRL_BLE
;
506 writel (ohci
->hc_control
, &ohci
->regs
->control
);
508 ohci
->ed_bulktail
= edi
;
514 /*-------------------------------------------------------------------------*/
516 /* unlink an ed from one of the HC chains.
517 * just the link to the ed is unlinked.
518 * the link from the ed still points to another operational ed or 0
519 * so the HC can eventually finish the processing of the unlinked ed */
521 static int ep_unlink (ohci_t
*ohci
, ed_t
*edi
)
523 volatile ed_t
*ed
= edi
;
525 ed
->hwINFO
|= ohci_cpu_to_le32 (OHCI_ED_SKIP
);
529 if (ed
->ed_prev
== NULL
) {
531 ohci
->hc_control
&= ~OHCI_CTRL_CLE
;
532 writel (ohci
->hc_control
, &ohci
->regs
->control
);
534 writel (ohci_cpu_to_le32 (*((__u32
*)&ed
->hwNextED
)), &ohci
->regs
->ed_controlhead
);
536 ed
->ed_prev
->hwNextED
= ed
->hwNextED
;
538 if (ohci
->ed_controltail
== ed
) {
539 ohci
->ed_controltail
= ed
->ed_prev
;
541 ((ed_t
*)ohci_cpu_to_le32 (*((__u32
*)&ed
->hwNextED
)))->ed_prev
= ed
->ed_prev
;
546 if (ed
->ed_prev
== NULL
) {
548 ohci
->hc_control
&= ~OHCI_CTRL_BLE
;
549 writel (ohci
->hc_control
, &ohci
->regs
->control
);
551 writel (ohci_cpu_to_le32 (*((__u32
*)&ed
->hwNextED
)), &ohci
->regs
->ed_bulkhead
);
553 ed
->ed_prev
->hwNextED
= ed
->hwNextED
;
555 if (ohci
->ed_bulktail
== ed
) {
556 ohci
->ed_bulktail
= ed
->ed_prev
;
558 ((ed_t
*)ohci_cpu_to_le32 (*((__u32
*)&ed
->hwNextED
)))->ed_prev
= ed
->ed_prev
;
562 ed
->state
= ED_UNLINK
;
567 /*-------------------------------------------------------------------------*/
569 /* add/reinit an endpoint; this should be done once at the usb_set_configuration command,
570 * but the USB stack is a little bit stateless so we do it at every transaction
571 * if the state of the ed is ED_NEW then a dummy td is added and the state is changed to ED_UNLINK
572 * in all other cases the state is left unchanged
573 * the ed info fields are setted anyway even though most of them should not change */
575 static ed_t
* ep_add_ed (struct usb_device
*usb_dev
, unsigned long pipe
)
581 ed
= ed_ret
= &ohci_dev
.ed
[(usb_pipeendpoint (pipe
) << 1) |
582 (usb_pipecontrol (pipe
)? 0: usb_pipeout (pipe
))];
584 if ((ed
->state
& ED_DEL
) || (ed
->state
& ED_URB_DEL
)) {
585 err("ep_add_ed: pending delete");
586 /* pending delete request */
590 if (ed
->state
== ED_NEW
) {
591 ed
->hwINFO
= ohci_cpu_to_le32 (OHCI_ED_SKIP
); /* skip ed */
592 /* dummy td; end of td list for ed */
593 td
= td_alloc (usb_dev
);
594 ed
->hwTailP
= ohci_cpu_to_le32 ((unsigned long)td
);
595 ed
->hwHeadP
= ed
->hwTailP
;
596 ed
->state
= ED_UNLINK
;
597 ed
->type
= usb_pipetype (pipe
);
601 ed
->hwINFO
= ohci_cpu_to_le32 (usb_pipedevice (pipe
)
602 | usb_pipeendpoint (pipe
) << 7
603 | (usb_pipeisoc (pipe
)? 0x8000: 0)
604 | (usb_pipecontrol (pipe
)? 0: (usb_pipeout (pipe
)? 0x800: 0x1000))
605 | (usb_dev
->speed
== USB_SPEED_LOW
) << 13
606 | usb_maxpacket (usb_dev
, pipe
) << 16);
611 /*-------------------------------------------------------------------------*
612 * TD handling functions
613 *-------------------------------------------------------------------------*/
615 /* enqueue next TD for this URB (OHCI spec 5.2.8.2) */
617 static void td_fill (ohci_t
*ohci
, unsigned int info
,
619 struct usb_device
*dev
, int index
, urb_priv_t
*urb_priv
)
621 volatile td_t
*td
, *td_pt
;
622 #ifdef OHCI_FILL_TRACE
626 if (index
> urb_priv
->length
) {
627 err("index > length");
630 /* use this td as the next dummy */
631 td_pt
= urb_priv
->td
[index
];
634 /* fill the old dummy TD */
635 td
= urb_priv
->td
[index
] = (td_t
*)(ohci_cpu_to_le32 (urb_priv
->ed
->hwTailP
) & ~0xf);
637 td
->ed
= urb_priv
->ed
;
638 td
->next_dl_td
= NULL
;
640 td
->data
= (__u32
)data
;
641 #ifdef OHCI_FILL_TRACE
642 if (usb_pipebulk(urb_priv
->pipe
) && usb_pipeout(urb_priv
->pipe
)) {
643 for (i
= 0; i
< len
; i
++)
644 printf("td->data[%d] %#2x ",i
, ((unsigned char *)td
->data
)[i
]);
651 td
->hwINFO
= ohci_cpu_to_le32 (info
);
652 td
->hwCBP
= ohci_cpu_to_le32 ((unsigned long)data
);
654 td
->hwBE
= ohci_cpu_to_le32 ((unsigned long)(data
+ len
- 1));
657 td
->hwNextTD
= ohci_cpu_to_le32 ((unsigned long)td_pt
);
659 /* append to queue */
660 td
->ed
->hwTailP
= td
->hwNextTD
;
663 /*-------------------------------------------------------------------------*/
665 /* prepare all TDs of a transfer */
666 static void td_submit_job (struct usb_device
*dev
, unsigned long pipe
, void *buffer
,
667 int transfer_len
, struct devrequest
*setup
, urb_priv_t
*urb
, int interval
)
669 ohci_t
*ohci
= &gohci
;
670 int data_len
= transfer_len
;
674 unsigned int toggle
= 0;
676 /* OHCI handles the DATA-toggles itself, we just use the
677 USB-toggle bits for resetting */
678 if(usb_gettoggle(dev
, usb_pipeendpoint(pipe
), usb_pipeout(pipe
))) {
679 toggle
= TD_T_TOGGLE
;
682 usb_settoggle(dev
, usb_pipeendpoint(pipe
), usb_pipeout(pipe
), 1);
690 switch (usb_pipetype (pipe
)) {
692 info
= usb_pipeout (pipe
)?
693 TD_CC
| TD_DP_OUT
: TD_CC
| TD_DP_IN
;
694 while(data_len
> 4096) {
695 td_fill (ohci
, info
| (cnt
? TD_T_TOGGLE
:toggle
), data
, 4096, dev
, cnt
, urb
);
696 data
+= 4096; data_len
-= 4096; cnt
++;
698 info
= usb_pipeout (pipe
)?
699 TD_CC
| TD_DP_OUT
: TD_CC
| TD_R
| TD_DP_IN
;
700 td_fill (ohci
, info
| (cnt
? TD_T_TOGGLE
:toggle
), data
, data_len
, dev
, cnt
, urb
);
704 writel (OHCI_BLF
, &ohci
->regs
->cmdstatus
); /* start bulk list */
708 info
= TD_CC
| TD_DP_SETUP
| TD_T_DATA0
;
709 td_fill (ohci
, info
, setup
, 8, dev
, cnt
++, urb
);
711 info
= usb_pipeout (pipe
)?
712 TD_CC
| TD_R
| TD_DP_OUT
| TD_T_DATA1
: TD_CC
| TD_R
| TD_DP_IN
| TD_T_DATA1
;
713 /* NOTE: mishandles transfers >8K, some >4K */
714 td_fill (ohci
, info
, data
, data_len
, dev
, cnt
++, urb
);
716 info
= usb_pipeout (pipe
)?
717 TD_CC
| TD_DP_IN
| TD_T_DATA1
: TD_CC
| TD_DP_OUT
| TD_T_DATA1
;
718 td_fill (ohci
, info
, data
, 0, dev
, cnt
++, urb
);
720 writel (OHCI_CLF
, &ohci
->regs
->cmdstatus
); /* start Control list */
723 if (urb
->length
!= cnt
)
724 dbg("TD LENGTH %d != CNT %d", urb
->length
, cnt
);
727 /*-------------------------------------------------------------------------*
728 * Done List handling functions
729 *-------------------------------------------------------------------------*/
732 /* calculate the transfer length and update the urb */
734 static void dl_transfer_length(td_t
* td
)
737 urb_priv_t
*lurb_priv
= &urb_priv
;
739 tdBE
= ohci_cpu_to_le32 (td
->hwBE
);
740 tdCBP
= ohci_cpu_to_le32 (td
->hwCBP
);
743 if (!(usb_pipecontrol(lurb_priv
->pipe
) &&
744 ((td
->index
== 0) || (td
->index
== lurb_priv
->length
- 1)))) {
747 lurb_priv
->actual_length
+= tdBE
- td
->data
+ 1;
749 lurb_priv
->actual_length
+= tdCBP
- td
->data
;
754 /*-------------------------------------------------------------------------*/
756 /* replies to the request have to be on a FIFO basis so
757 * we reverse the reversed done-list */
759 static td_t
* dl_reverse_done_list (ohci_t
*ohci
)
763 td_t
*td_list
= NULL
;
764 urb_priv_t
*lurb_priv
= NULL
;
766 td_list_hc
= ohci_cpu_to_le32 (ohci
->hcca
->done_head
) & 0xfffffff0;
767 ohci
->hcca
->done_head
= 0;
770 td_list
= (td_t
*)td_list_hc
;
772 if (TD_CC_GET (ohci_cpu_to_le32 (td_list
->hwINFO
))) {
773 lurb_priv
= &urb_priv
;
774 dbg(" USB-error/status: %x : %p",
775 TD_CC_GET (ohci_cpu_to_le32 (td_list
->hwINFO
)), td_list
);
776 if (td_list
->ed
->hwHeadP
& ohci_cpu_to_le32 (0x1)) {
777 if (lurb_priv
&& ((td_list
->index
+ 1) < lurb_priv
->length
)) {
778 td_list
->ed
->hwHeadP
=
779 (lurb_priv
->td
[lurb_priv
->length
- 1]->hwNextTD
& ohci_cpu_to_le32 (0xfffffff0)) |
780 (td_list
->ed
->hwHeadP
& ohci_cpu_to_le32 (0x2));
781 lurb_priv
->td_cnt
+= lurb_priv
->length
- td_list
->index
- 1;
783 td_list
->ed
->hwHeadP
&= ohci_cpu_to_le32 (0xfffffff2);
787 td_list
->next_dl_td
= td_rev
;
789 td_list_hc
= ohci_cpu_to_le32 (td_list
->hwNextTD
) & 0xfffffff0;
794 /*-------------------------------------------------------------------------*/
797 static int dl_done_list (ohci_t
*ohci
, td_t
*td_list
)
799 td_t
*td_list_next
= NULL
;
804 urb_priv_t
*lurb_priv
;
805 __u32 tdINFO
, edHeadP
, edTailP
;
808 td_list_next
= td_list
->next_dl_td
;
810 lurb_priv
= &urb_priv
;
811 tdINFO
= ohci_cpu_to_le32 (td_list
->hwINFO
);
815 dl_transfer_length(td_list
);
817 /* error code of transfer */
818 cc
= TD_CC_GET (tdINFO
);
819 if (++(lurb_priv
->td_cnt
) == lurb_priv
->length
) {
820 if ((ed
->state
& (ED_OPER
| ED_UNLINK
))
821 && (lurb_priv
->state
!= URB_DEL
)) {
822 dbg("ConditionCode %#x", cc
);
823 stat
= cc_to_error
[cc
];
828 if (ed
->state
!= ED_NEW
) {
829 edHeadP
= ohci_cpu_to_le32 (ed
->hwHeadP
) & 0xfffffff0;
830 edTailP
= ohci_cpu_to_le32 (ed
->hwTailP
);
832 /* unlink eds if they are not busy */
833 if ((edHeadP
== edTailP
) && (ed
->state
== ED_OPER
))
834 ep_unlink (ohci
, ed
);
837 td_list
= td_list_next
;
842 /*-------------------------------------------------------------------------*
844 *-------------------------------------------------------------------------*/
846 #include <usbroothubdes.h>
848 /* Hub class-specific descriptor is constructed dynamically */
851 /*-------------------------------------------------------------------------*/
853 #define OK(x) len = (x); break
855 #define WR_RH_STAT(x) {info("WR:status %#8x", (x));writel((x), &gohci.regs->roothub.status);}
856 #define WR_RH_PORTSTAT(x) {info("WR:portstatus[%d] %#8x", wIndex-1, (x));writel((x), &gohci.regs->roothub.portstatus[wIndex-1]);}
858 #define WR_RH_STAT(x) writel((x), &gohci.regs->roothub.status)
859 #define WR_RH_PORTSTAT(x) writel((x), &gohci.regs->roothub.portstatus[wIndex-1])
861 #define RD_RH_STAT roothub_status(&gohci)
862 #define RD_RH_PORTSTAT roothub_portstatus(&gohci,wIndex-1)
864 /* request to virtual root hub */
866 int rh_check_port_status(ohci_t
*controller
)
872 temp
= roothub_a (controller
);
873 ndp
= (temp
& RH_A_NDP
);
874 for (i
= 0; i
< ndp
; i
++) {
875 temp
= roothub_portstatus (controller
, i
);
876 /* check for a device disconnect */
877 if (((temp
& (RH_PS_PESC
| RH_PS_CSC
)) ==
878 (RH_PS_PESC
| RH_PS_CSC
)) &&
879 ((temp
& RH_PS_CCS
) == 0)) {
887 static int ohci_submit_rh_msg(struct usb_device
*dev
, unsigned long pipe
,
888 void *buffer
, int transfer_len
, struct devrequest
*cmd
)
890 void * data
= buffer
;
891 int leni
= transfer_len
;
895 __u8
*data_buf
= (__u8
*)datab
;
902 urb_priv
.actual_length
= 0;
903 pkt_print(dev
, pipe
, buffer
, transfer_len
, cmd
, "SUB(rh)", usb_pipein(pipe
));
905 if (usb_pipeint(pipe
)) {
906 info("Root-Hub submit IRQ: NOT implemented");
910 bmRType_bReq
= cmd
->requesttype
| (cmd
->request
<< 8);
911 wValue
= m16_swap (cmd
->value
);
912 wIndex
= m16_swap (cmd
->index
);
913 wLength
= m16_swap (cmd
->length
);
915 info("Root-Hub: adr: %2x cmd(%1x): %08x %04x %04x %04x",
916 dev
->devnum
, 8, bmRType_bReq
, wValue
, wIndex
, wLength
);
918 switch (bmRType_bReq
) {
919 /* Request Destination:
920 without flags: Device,
921 RH_INTERFACE: interface,
922 RH_ENDPOINT: endpoint,
923 RH_CLASS means HUB here,
924 RH_OTHER | RH_CLASS almost ever means HUB_PORT here
928 *(__u16
*) data_buf
= m16_swap (1); OK (2);
929 case RH_GET_STATUS
| RH_INTERFACE
:
930 *(__u16
*) data_buf
= m16_swap (0); OK (2);
931 case RH_GET_STATUS
| RH_ENDPOINT
:
932 *(__u16
*) data_buf
= m16_swap (0); OK (2);
933 case RH_GET_STATUS
| RH_CLASS
:
934 *(__u32
*) data_buf
= m32_swap (
935 RD_RH_STAT
& ~(RH_HS_CRWE
| RH_HS_DRWE
));
937 case RH_GET_STATUS
| RH_OTHER
| RH_CLASS
:
938 *(__u32
*) data_buf
= m32_swap (RD_RH_PORTSTAT
); OK (4);
940 case RH_CLEAR_FEATURE
| RH_ENDPOINT
:
942 case (RH_ENDPOINT_STALL
): OK (0);
946 case RH_CLEAR_FEATURE
| RH_CLASS
:
948 case RH_C_HUB_LOCAL_POWER
:
950 case (RH_C_HUB_OVER_CURRENT
):
951 WR_RH_STAT(RH_HS_OCIC
); OK (0);
955 case RH_CLEAR_FEATURE
| RH_OTHER
| RH_CLASS
:
957 case (RH_PORT_ENABLE
):
958 WR_RH_PORTSTAT (RH_PS_CCS
); OK (0);
959 case (RH_PORT_SUSPEND
):
960 WR_RH_PORTSTAT (RH_PS_POCI
); OK (0);
961 case (RH_PORT_POWER
):
962 WR_RH_PORTSTAT (RH_PS_LSDA
); OK (0);
963 case (RH_C_PORT_CONNECTION
):
964 WR_RH_PORTSTAT (RH_PS_CSC
); OK (0);
965 case (RH_C_PORT_ENABLE
):
966 WR_RH_PORTSTAT (RH_PS_PESC
); OK (0);
967 case (RH_C_PORT_SUSPEND
):
968 WR_RH_PORTSTAT (RH_PS_PSSC
); OK (0);
969 case (RH_C_PORT_OVER_CURRENT
):
970 WR_RH_PORTSTAT (RH_PS_OCIC
); OK (0);
971 case (RH_C_PORT_RESET
):
972 WR_RH_PORTSTAT (RH_PS_PRSC
); OK (0);
976 case RH_SET_FEATURE
| RH_OTHER
| RH_CLASS
:
978 case (RH_PORT_SUSPEND
):
979 WR_RH_PORTSTAT (RH_PS_PSS
); OK (0);
980 case (RH_PORT_RESET
): /* BUG IN HUP CODE *********/
981 if (RD_RH_PORTSTAT
& RH_PS_CCS
)
982 WR_RH_PORTSTAT (RH_PS_PRS
);
984 case (RH_PORT_POWER
):
985 WR_RH_PORTSTAT (RH_PS_PPS
); OK (0);
986 case (RH_PORT_ENABLE
): /* BUG IN HUP CODE *********/
987 if (RD_RH_PORTSTAT
& RH_PS_CCS
)
988 WR_RH_PORTSTAT (RH_PS_PES
);
993 case RH_SET_ADDRESS
: gohci
.rh
.devnum
= wValue
; OK(0);
995 case RH_GET_DESCRIPTOR
:
996 switch ((wValue
& 0xff00) >> 8) {
997 case (0x01): /* device descriptor */
998 len
= min_t(unsigned int,
1001 sizeof (root_hub_dev_des
),
1003 data_buf
= root_hub_dev_des
; OK(len
);
1004 case (0x02): /* configuration descriptor */
1005 len
= min_t(unsigned int,
1008 sizeof (root_hub_config_des
),
1010 data_buf
= root_hub_config_des
; OK(len
);
1011 case (0x03): /* string descriptors */
1012 if(wValue
==0x0300) {
1013 len
= min_t(unsigned int,
1016 sizeof (root_hub_str_index0
),
1018 data_buf
= root_hub_str_index0
;
1021 if(wValue
==0x0301) {
1022 len
= min_t(unsigned int,
1025 sizeof (root_hub_str_index1
),
1027 data_buf
= root_hub_str_index1
;
1031 stat
= USB_ST_STALLED
;
1035 case RH_GET_DESCRIPTOR
| RH_CLASS
:
1037 __u32 temp
= roothub_a (&gohci
);
1039 data_buf
[0] = 9; /* min length; */
1040 data_buf
[1] = 0x29;
1041 data_buf
[2] = temp
& RH_A_NDP
;
1043 if (temp
& RH_A_PSM
) /* per-port power switching? */
1044 data_buf
[3] |= 0x1;
1045 if (temp
& RH_A_NOCP
) /* no overcurrent reporting? */
1046 data_buf
[3] |= 0x10;
1047 else if (temp
& RH_A_OCPM
) /* per-port overcurrent reporting? */
1048 data_buf
[3] |= 0x8;
1050 /* corresponds to data_buf[4-7] */
1052 data_buf
[5] = (temp
& RH_A_POTPGT
) >> 24;
1053 temp
= roothub_b (&gohci
);
1054 data_buf
[7] = temp
& RH_B_DR
;
1055 if (data_buf
[2] < 7) {
1056 data_buf
[8] = 0xff;
1059 data_buf
[8] = (temp
& RH_B_DR
) >> 8;
1060 data_buf
[10] = data_buf
[9] = 0xff;
1063 len
= min_t(unsigned int, leni
,
1064 min_t(unsigned int, data_buf
[0], wLength
));
1068 case RH_GET_CONFIGURATION
: *(__u8
*) data_buf
= 0x01; OK (1);
1070 case RH_SET_CONFIGURATION
: WR_RH_STAT (0x10000); OK (0);
1073 dbg ("unsupported root hub command");
1074 stat
= USB_ST_STALLED
;
1078 ohci_dump_roothub (&gohci
, 1);
1081 len
= min_t(int, len
, leni
);
1082 if (data
!= data_buf
)
1083 memcpy (data
, data_buf
, len
);
1089 urb_priv
.actual_length
= transfer_len
;
1090 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
));
1118 err("submit_common_message: pipesize for pipe %lx is zero",
1123 if (sohci_submit_job(dev
, pipe
, buffer
, transfer_len
, setup
, interval
) < 0) {
1124 err("sohci_submit_job failed");
1128 /* allow more time for a BULK device to react - some are slow */
1129 #define BULK_TO 5000 /* timeout in milliseconds */
1130 if (usb_pipebulk(pipe
))
1135 /* wait for it to complete */
1137 /* check whether the controller is done */
1138 stat
= hc_interrupt();
1140 stat
= USB_ST_CRC_ERR
;
1144 /* NOTE: since we are not interrupt driven in U-Boot and always
1145 * handle only one URB at a time, we cannot assume the
1146 * transaction finished on the first successful return from
1147 * hc_interrupt().. unless the flag for current URB is set,
1148 * meaning that all TD's to/from device got actually
1149 * transferred and processed. If the current URB is not
1150 * finished we need to re-iterate this loop so as
1151 * hc_interrupt() gets called again as there needs to be some
1152 * more TD's to process still */
1153 if ((stat
>= 0) && (stat
!= 0xff) && (urb_finished
)) {
1154 /* 0xff is returned for an SF-interrupt */
1164 err("CTL:TIMEOUT ");
1165 dbg("submit_common_msg: TO status %x\n", stat
);
1166 stat
= USB_ST_CRC_ERR
;
1172 /* we got an Root Hub Status Change interrupt */
1175 ohci_dump_roothub (&gohci
, 1);
1179 timeout
= rh_check_port_status(&gohci
);
1181 #if 0 /* this does nothing useful, but leave it here in case that changes */
1182 /* the called routine adds 1 to the passed value */
1183 usb_hub_port_connect_change(gohci
.rh
.dev
, timeout
- 1);
1187 * This is potentially dangerous because it assumes
1188 * that only one device is ever plugged in!
1196 dev
->act_len
= transfer_len
;
1199 pkt_print(dev
, pipe
, buffer
, transfer_len
, setup
, "RET(ctlr)", usb_pipein(pipe
));
1202 /* free TDs in urb_priv */
1203 urb_free_priv (&urb_priv
);
1207 /* submit routines called from usb.c */
1208 int submit_bulk_msg(struct usb_device
*dev
, unsigned long pipe
, void *buffer
,
1211 info("submit_bulk_msg");
1212 return submit_common_msg(dev
, pipe
, buffer
, transfer_len
, NULL
, 0);
1215 int submit_control_msg(struct usb_device
*dev
, unsigned long pipe
, void *buffer
,
1216 int transfer_len
, struct devrequest
*setup
)
1218 int maxsize
= usb_maxpacket(dev
, pipe
);
1220 info("submit_control_msg");
1222 urb_priv
.actual_length
= 0;
1223 pkt_print(dev
, pipe
, buffer
, transfer_len
, setup
, "SUB", usb_pipein(pipe
));
1226 err("submit_control_message: pipesize for pipe %lx is zero",
1230 if (((pipe
>> 8) & 0x7f) == gohci
.rh
.devnum
) {
1232 /* root hub - redirect */
1233 return ohci_submit_rh_msg(dev
, pipe
, buffer
, transfer_len
,
1237 return submit_common_msg(dev
, pipe
, buffer
, transfer_len
, setup
, 0);
1240 int submit_int_msg(struct usb_device
*dev
, unsigned long pipe
, void *buffer
,
1241 int transfer_len
, int interval
)
1243 info("submit_int_msg");
1247 /*-------------------------------------------------------------------------*
1249 *-------------------------------------------------------------------------*/
1251 /* reset the HC and BUS */
1253 static int hc_reset (ohci_t
*ohci
)
1256 int smm_timeout
= 50; /* 0,5 sec */
1258 if (readl (&ohci
->regs
->control
) & OHCI_CTRL_IR
) { /* SMM owns the HC */
1259 writel (OHCI_OCR
, &ohci
->regs
->cmdstatus
); /* request ownership */
1260 info("USB HC TakeOver from SMM");
1261 while (readl (&ohci
->regs
->control
) & OHCI_CTRL_IR
) {
1263 if (--smm_timeout
== 0) {
1264 err("USB HC TakeOver failed!");
1270 /* Disable HC interrupts */
1271 writel (OHCI_INTR_MIE
, &ohci
->regs
->intrdisable
);
1273 dbg("USB HC reset_hc usb-%s: ctrl = 0x%X ;",
1275 readl (&ohci
->regs
->control
));
1277 /* Reset USB (needed by some controllers) */
1278 ohci
->hc_control
= 0;
1279 writel (ohci
->hc_control
, &ohci
->regs
->control
);
1281 /* HC Reset requires max 10 us delay */
1282 writel (OHCI_HCR
, &ohci
->regs
->cmdstatus
);
1283 while ((readl (&ohci
->regs
->cmdstatus
) & OHCI_HCR
) != 0) {
1284 if (--timeout
== 0) {
1285 err("USB HC reset timed out!");
1293 /*-------------------------------------------------------------------------*/
1295 /* Start an OHCI controller, set the BUS operational
1297 * connect the virtual root hub */
1299 static int hc_start (ohci_t
* ohci
)
1302 unsigned int fminterval
;
1306 /* Tell the controller where the control and bulk lists are
1307 * The lists are empty now. */
1309 writel (0, &ohci
->regs
->ed_controlhead
);
1310 writel (0, &ohci
->regs
->ed_bulkhead
);
1312 writel ((__u32
)ohci
->hcca
, &ohci
->regs
->hcca
); /* a reset clears this */
1314 fminterval
= 0x2edf;
1315 writel ((fminterval
* 9) / 10, &ohci
->regs
->periodicstart
);
1316 fminterval
|= ((((fminterval
- 210) * 6) / 7) << 16);
1317 writel (fminterval
, &ohci
->regs
->fminterval
);
1318 writel (0x628, &ohci
->regs
->lsthresh
);
1320 /* start controller operations */
1321 ohci
->hc_control
= OHCI_CONTROL_INIT
| OHCI_USB_OPER
;
1323 writel (ohci
->hc_control
, &ohci
->regs
->control
);
1325 /* disable all interrupts */
1326 mask
= (OHCI_INTR_SO
| OHCI_INTR_WDH
| OHCI_INTR_SF
| OHCI_INTR_RD
|
1327 OHCI_INTR_UE
| OHCI_INTR_FNO
| OHCI_INTR_RHSC
|
1328 OHCI_INTR_OC
| OHCI_INTR_MIE
);
1329 writel (mask
, &ohci
->regs
->intrdisable
);
1330 /* clear all interrupts */
1331 mask
&= ~OHCI_INTR_MIE
;
1332 writel (mask
, &ohci
->regs
->intrstatus
);
1333 /* Choose the interrupts we care about now - but w/o MIE */
1334 mask
= OHCI_INTR_RHSC
| OHCI_INTR_UE
| OHCI_INTR_WDH
| OHCI_INTR_SO
;
1335 writel (mask
, &ohci
->regs
->intrenable
);
1338 /* required for AMD-756 and some Mac platforms */
1339 writel ((roothub_a (ohci
) | RH_A_NPS
) & ~RH_A_PSM
,
1340 &ohci
->regs
->roothub
.a
);
1341 writel (RH_HS_LPSC
, &ohci
->regs
->roothub
.status
);
1342 #endif /* OHCI_USE_NPS */
1344 /* POTPGT delay is bits 24-31, in 2 ms units. */
1345 mdelay ((roothub_a (ohci
) >> 23) & 0x1fe);
1347 /* connect the virtual root hub */
1348 ohci
->rh
.devnum
= 0;
1353 /*-------------------------------------------------------------------------*/
1355 /* an interrupt happens */
1360 ohci_t
*ohci
= &gohci
;
1361 struct ohci_regs
*regs
= ohci
->regs
;
1365 if ((ohci
->hcca
->done_head
!= 0) &&
1366 !(ohci_cpu_to_le32(ohci
->hcca
->done_head
) & 0x01)) {
1368 ints
= OHCI_INTR_WDH
;
1370 } else if ((ints
= readl (®s
->intrstatus
)) == ~(u32
)0) {
1372 err ("%s device removed!", ohci
->slot_name
);
1375 } else if ((ints
&= readl (®s
->intrenable
)) == 0) {
1376 dbg("hc_interrupt: returning..\n");
1380 /* dbg("Interrupt: %x frame: %x", ints, le16_to_cpu (ohci->hcca->frame_no)); */
1382 if (ints
& OHCI_INTR_RHSC
) {
1387 if (ints
& OHCI_INTR_UE
) {
1389 err ("OHCI Unrecoverable Error, controller usb-%s disabled",
1391 /* e.g. due to PCI Master/Target Abort */
1394 ohci_dump (ohci
, 1);
1396 /* FIXME: be optimistic, hope that bug won't repeat often. */
1397 /* Make some non-interrupt context restart the controller. */
1398 /* Count and limit the retries though; either hardware or */
1399 /* software errors can go forever... */
1404 if (ints
& OHCI_INTR_WDH
) {
1405 writel (OHCI_INTR_WDH
, ®s
->intrdisable
);
1406 stat
= dl_done_list (&gohci
, dl_reverse_done_list (&gohci
));
1407 writel (OHCI_INTR_WDH
, ®s
->intrenable
);
1410 if (ints
& OHCI_INTR_SO
) {
1411 dbg("USB Schedule overrun\n");
1412 writel (OHCI_INTR_SO
, ®s
->intrenable
);
1416 /* FIXME: this assumes SOF (1/ms) interrupts don't get lost... */
1417 if (ints
& OHCI_INTR_SF
) {
1418 unsigned int frame
= ohci_cpu_to_le16 (ohci
->hcca
->frame_no
) & 1;
1420 writel (OHCI_INTR_SF
, ®s
->intrdisable
);
1421 if (ohci
->ed_rm_list
[frame
] != NULL
)
1422 writel (OHCI_INTR_SF
, ®s
->intrenable
);
1426 writel (ints
, ®s
->intrstatus
);
1430 /*-------------------------------------------------------------------------*/
1432 /*-------------------------------------------------------------------------*/
1434 /* De-allocate all resources.. */
1436 static void hc_release_ohci (ohci_t
*ohci
)
1438 dbg ("USB HC release ohci usb-%s", ohci
->slot_name
);
1440 if (!ohci
->disabled
)
1444 /*-------------------------------------------------------------------------*/
1447 * low level initalisation routine, called from usb.c
1449 static char ohci_inited
= 0;
1451 int usb_lowlevel_init(int index
, enum usb_init_type init
, void **controller
)
1453 memset (&gohci
, 0, sizeof (ohci_t
));
1454 memset (&urb_priv
, 0, sizeof (urb_priv_t
));
1456 /* align the storage */
1457 if ((__u32
)&ghcca
[0] & 0xff) {
1458 err("HCCA not aligned!!");
1462 info("aligned ghcca %p", phcca
);
1463 memset(&ohci_dev
, 0, sizeof(struct ohci_device
));
1464 if ((__u32
)&ohci_dev
.ed
[0] & 0x7) {
1465 err("EDs not aligned!!");
1468 memset(gtd
, 0, sizeof(td_t
) * (NUM_TD
+ 1));
1469 if ((__u32
)gtd
& 0x7) {
1470 err("TDs not aligned!!");
1475 memset (phcca
, 0, sizeof (struct ohci_hcca
));
1480 #if defined(CONFIG_440EP)
1481 gohci
.regs
= (struct ohci_regs
*)(CONFIG_SYS_PERIPHERAL_BASE
| 0x1000);
1482 #elif defined(CONFIG_440EPX) || defined(CONFIG_SYS_USB_HOST)
1483 gohci
.regs
= (struct ohci_regs
*)(CONFIG_SYS_USB_HOST
);
1487 gohci
.slot_name
= "ppc440";
1489 if (hc_reset (&gohci
) < 0) {
1490 hc_release_ohci (&gohci
);
1494 if (hc_start (&gohci
) < 0) {
1495 err ("can't start usb-%s", gohci
.slot_name
);
1496 hc_release_ohci (&gohci
);
1501 ohci_dump (&gohci
, 1);
1509 int usb_lowlevel_stop(int index
)
1511 /* this gets called really early - before the controller has */
1512 /* even been initialized! */
1515 /* TODO release any interrupts, etc. */
1516 /* call hc_release_ohci() here ? */
1521 #endif /* CONFIG_USB_OHCI */