2 * URB OHCI HCD (Host Controller Driver) for USB on the AT91RM9200 and PCI bus.
4 * Interrupt support is added. Now, it has been tested
5 * on ULI1575 chip and works well with USB keyboard.
8 * Zhang Wei, Freescale Semiconductor, Inc. <wei.zhang@freescale.com>
11 * Gary Jennejohn, DENX Software Engineering <gj@denx.de>
13 * Note: Much of this code has been derived from Linux 2.4
14 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
15 * (C) Copyright 2000-2002 David Brownell
17 * Modified for the MP2USB by (C) Copyright 2005 Eric Benard
18 * ebenard@eukrea.com - based on s3c24x0's driver
20 * See file CREDITS for list of people who contributed to this
23 * This program is free software; you can redistribute it and/or
24 * modify it under the terms of the GNU General Public License as
25 * published by the Free Software Foundation; either version 2 of
26 * the License, or (at your option) any later version.
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the Free Software
35 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
41 * 1 - Read doc/README.generic_usb_ohci
42 * 2 - this driver is intended for use with USB Mass Storage Devices
43 * (BBB) and USB keyboard. There is NO support for Isochronous pipes!
44 * 2 - when running on a PQFP208 AT91RM9200, define CONFIG_AT91C_PQFP_UHPBUG
45 * to activate workaround for bug #41 or this driver will NOT work!
50 #ifdef CONFIG_USB_OHCI_NEW
52 #include <asm/byteorder.h>
54 #if defined(CONFIG_PCI_OHCI)
56 #if !defined(CONFIG_PCI_OHCI_DEVNO)
57 #define CONFIG_PCI_OHCI_DEVNO 0
65 #ifdef CONFIG_AT91RM9200
66 #include <asm/arch/hardware.h> /* needed for AT91_USB_HOST_BASE */
69 #if defined(CONFIG_ARM920T) || \
70 defined(CONFIG_S3C2400) || \
71 defined(CONFIG_S3C2410) || \
72 defined(CONFIG_S3C6400) || \
73 defined(CONFIG_440EP) || \
74 defined(CONFIG_PCI_OHCI) || \
75 defined(CONFIG_MPC5200) || \
76 defined(CONFIG_SYS_OHCI_USE_NPS)
77 # define OHCI_USE_NPS /* force NoPowerSwitching mode */
80 #undef OHCI_VERBOSE_DEBUG /* not always helpful */
83 #undef OHCI_FILL_TRACE
85 /* For initializing controller (mask in an HCFS mode too) */
86 #define OHCI_CONTROL_INIT \
87 (OHCI_CTRL_CBSR & 0x3) | OHCI_CTRL_IE | OHCI_CTRL_PLE
90 * e.g. PCI controllers need this
92 #ifdef CONFIG_SYS_OHCI_SWAP_REG_ACCESS
93 # define readl(a) __swap_32(*((volatile u32 *)(a)))
94 # define writel(a, b) (*((volatile u32 *)(b)) = __swap_32((volatile u32)a))
96 # define readl(a) (*((volatile u32 *)(a)))
97 # define writel(a, b) (*((volatile u32 *)(b)) = ((volatile u32)a))
98 #endif /* CONFIG_SYS_OHCI_SWAP_REG_ACCESS */
100 #define min_t(type,x,y) ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
102 #ifdef CONFIG_PCI_OHCI
103 static struct pci_device_id ohci_pci_ids
[] = {
104 {0x10b9, 0x5237}, /* ULI1575 PCI OHCI module ids */
105 {0x1033, 0x0035}, /* NEC PCI OHCI module ids */
106 {0x1131, 0x1561}, /* Philips 1561 PCI OHCI module ids */
107 /* Please add supported PCI OHCI controller ids here */
112 #ifdef CONFIG_PCI_EHCI_DEVNO
113 static struct pci_device_id ehci_pci_ids
[] = {
114 {0x1131, 0x1562}, /* Philips 1562 PCI EHCI module ids */
115 /* Please add supported PCI EHCI controller ids here */
121 #define dbg(format, arg...) printf("DEBUG: " format "\n", ## arg)
123 #define dbg(format, arg...) do {} while(0)
125 #define err(format, arg...) printf("ERROR: " format "\n", ## arg)
127 #define info(format, arg...) printf("INFO: " format "\n", ## arg)
129 #define info(format, arg...) do {} while(0)
132 #ifdef CONFIG_SYS_OHCI_BE_CONTROLLER
133 # define m16_swap(x) cpu_to_be16(x)
134 # define m32_swap(x) cpu_to_be32(x)
136 # define m16_swap(x) cpu_to_le16(x)
137 # define m32_swap(x) cpu_to_le32(x)
138 #endif /* CONFIG_SYS_OHCI_BE_CONTROLLER */
142 /* this must be aligned to a 256 byte boundary */
143 struct ohci_hcca ghcca
[1];
144 /* a pointer to the aligned storage */
145 struct ohci_hcca
*phcca
;
146 /* this allocates EDs for all possible endpoints */
147 struct ohci_device ohci_dev
;
150 /* device which was disconnected */
151 struct usb_device
*devgone
;
153 static inline u32
roothub_a (struct ohci
*hc
)
154 { return readl (&hc
->regs
->roothub
.a
); }
155 static inline u32
roothub_b (struct ohci
*hc
)
156 { return readl (&hc
->regs
->roothub
.b
); }
157 static inline u32
roothub_status (struct ohci
*hc
)
158 { return readl (&hc
->regs
->roothub
.status
); }
159 static inline u32
roothub_portstatus (struct ohci
*hc
, int i
)
160 { return readl (&hc
->regs
->roothub
.portstatus
[i
]); }
162 /* forward declaration */
163 static int hc_interrupt (void);
165 td_submit_job (struct usb_device
* dev
, unsigned long pipe
, void * buffer
,
166 int transfer_len
, struct devrequest
* setup
, urb_priv_t
* urb
, int interval
);
168 /*-------------------------------------------------------------------------*
169 * URB support functions
170 *-------------------------------------------------------------------------*/
172 /* free HCD-private data associated with this URB */
174 static void urb_free_priv (urb_priv_t
* urb
)
180 last
= urb
->length
- 1;
182 for (i
= 0; i
<= last
; i
++) {
193 /*-------------------------------------------------------------------------*/
196 static int sohci_get_current_frame_number (struct usb_device
* dev
);
198 /* debug| print the main components of an URB
199 * small: 0) header + data packets 1) just header */
201 static void pkt_print (urb_priv_t
*purb
, struct usb_device
* dev
,
202 unsigned long pipe
, void * buffer
,
203 int transfer_len
, struct devrequest
* setup
, char * str
, int small
)
205 dbg("%s URB:[%4x] dev:%2d,ep:%2d-%c,type:%s,len:%d/%d stat:%#lx",
207 sohci_get_current_frame_number (dev
),
208 usb_pipedevice (pipe
),
209 usb_pipeendpoint (pipe
),
210 usb_pipeout (pipe
)? 'O': 'I',
211 usb_pipetype (pipe
) < 2? (usb_pipeint (pipe
)? "INTR": "ISOC"):
212 (usb_pipecontrol (pipe
)? "CTRL": "BULK"),
213 (purb
? purb
->actual_length
: 0),
214 transfer_len
, dev
->status
);
215 #ifdef OHCI_VERBOSE_DEBUG
219 if (usb_pipecontrol (pipe
)) {
220 printf (__FILE__
": cmd(8):");
221 for (i
= 0; i
< 8 ; i
++)
222 printf (" %02x", ((__u8
*) setup
) [i
]);
225 if (transfer_len
> 0 && buffer
) {
226 printf (__FILE__
": data(%d/%d):",
227 (purb
? purb
->actual_length
: 0),
229 len
= usb_pipeout (pipe
)?
231 (purb
? purb
->actual_length
: 0);
232 for (i
= 0; i
< 16 && i
< len
; i
++)
233 printf (" %02x", ((__u8
*) buffer
) [i
]);
234 printf ("%s\n", i
< len
? "...": "");
240 /* just for debugging; prints non-empty branches of the int ed tree inclusive iso eds*/
241 void ep_print_int_eds (ohci_t
*ohci
, char * str
) {
244 for (i
= 0; i
< 32; i
++) {
246 ed_p
= &(ohci
->hcca
->int_table
[i
]);
249 printf (__FILE__
": %s branch int %2d(%2x):", str
, i
, i
);
250 while (*ed_p
!= 0 && j
--) {
251 ed_t
*ed
= (ed_t
*)m32_swap(ed_p
);
252 printf (" ed: %4x;", ed
->hwINFO
);
253 ed_p
= &ed
->hwNextED
;
259 static void ohci_dump_intr_mask (char *label
, __u32 mask
)
261 dbg ("%s: 0x%08x%s%s%s%s%s%s%s%s%s",
264 (mask
& OHCI_INTR_MIE
) ? " MIE" : "",
265 (mask
& OHCI_INTR_OC
) ? " OC" : "",
266 (mask
& OHCI_INTR_RHSC
) ? " RHSC" : "",
267 (mask
& OHCI_INTR_FNO
) ? " FNO" : "",
268 (mask
& OHCI_INTR_UE
) ? " UE" : "",
269 (mask
& OHCI_INTR_RD
) ? " RD" : "",
270 (mask
& OHCI_INTR_SF
) ? " SF" : "",
271 (mask
& OHCI_INTR_WDH
) ? " WDH" : "",
272 (mask
& OHCI_INTR_SO
) ? " SO" : ""
276 static void maybe_print_eds (char *label
, __u32 value
)
278 ed_t
*edp
= (ed_t
*)value
;
281 dbg ("%s %08x", label
, value
);
282 dbg ("%08x", edp
->hwINFO
);
283 dbg ("%08x", edp
->hwTailP
);
284 dbg ("%08x", edp
->hwHeadP
);
285 dbg ("%08x", edp
->hwNextED
);
289 static char * hcfs2string (int state
)
292 case OHCI_USB_RESET
: return "reset";
293 case OHCI_USB_RESUME
: return "resume";
294 case OHCI_USB_OPER
: return "operational";
295 case OHCI_USB_SUSPEND
: return "suspend";
300 /* dump control and status registers */
301 static void ohci_dump_status (ohci_t
*controller
)
303 struct ohci_regs
*regs
= controller
->regs
;
306 temp
= readl (®s
->revision
) & 0xff;
308 dbg ("spec %d.%d", (temp
>> 4), (temp
& 0x0f));
310 temp
= readl (®s
->control
);
311 dbg ("control: 0x%08x%s%s%s HCFS=%s%s%s%s%s CBSR=%d", temp
,
312 (temp
& OHCI_CTRL_RWE
) ? " RWE" : "",
313 (temp
& OHCI_CTRL_RWC
) ? " RWC" : "",
314 (temp
& OHCI_CTRL_IR
) ? " IR" : "",
315 hcfs2string (temp
& OHCI_CTRL_HCFS
),
316 (temp
& OHCI_CTRL_BLE
) ? " BLE" : "",
317 (temp
& OHCI_CTRL_CLE
) ? " CLE" : "",
318 (temp
& OHCI_CTRL_IE
) ? " IE" : "",
319 (temp
& OHCI_CTRL_PLE
) ? " PLE" : "",
320 temp
& OHCI_CTRL_CBSR
323 temp
= readl (®s
->cmdstatus
);
324 dbg ("cmdstatus: 0x%08x SOC=%d%s%s%s%s", temp
,
325 (temp
& OHCI_SOC
) >> 16,
326 (temp
& OHCI_OCR
) ? " OCR" : "",
327 (temp
& OHCI_BLF
) ? " BLF" : "",
328 (temp
& OHCI_CLF
) ? " CLF" : "",
329 (temp
& OHCI_HCR
) ? " HCR" : ""
332 ohci_dump_intr_mask ("intrstatus", readl (®s
->intrstatus
));
333 ohci_dump_intr_mask ("intrenable", readl (®s
->intrenable
));
335 maybe_print_eds ("ed_periodcurrent", readl (®s
->ed_periodcurrent
));
337 maybe_print_eds ("ed_controlhead", readl (®s
->ed_controlhead
));
338 maybe_print_eds ("ed_controlcurrent", readl (®s
->ed_controlcurrent
));
340 maybe_print_eds ("ed_bulkhead", readl (®s
->ed_bulkhead
));
341 maybe_print_eds ("ed_bulkcurrent", readl (®s
->ed_bulkcurrent
));
343 maybe_print_eds ("donehead", readl (®s
->donehead
));
346 static void ohci_dump_roothub (ohci_t
*controller
, int verbose
)
350 temp
= roothub_a (controller
);
351 ndp
= (temp
& RH_A_NDP
);
352 #ifdef CONFIG_AT91C_PQFP_UHPBUG
353 ndp
= (ndp
== 2) ? 1:0;
356 dbg ("roothub.a: %08x POTPGT=%d%s%s%s%s%s NDP=%d", temp
,
357 ((temp
& RH_A_POTPGT
) >> 24) & 0xff,
358 (temp
& RH_A_NOCP
) ? " NOCP" : "",
359 (temp
& RH_A_OCPM
) ? " OCPM" : "",
360 (temp
& RH_A_DT
) ? " DT" : "",
361 (temp
& RH_A_NPS
) ? " NPS" : "",
362 (temp
& RH_A_PSM
) ? " PSM" : "",
365 temp
= roothub_b (controller
);
366 dbg ("roothub.b: %08x PPCM=%04x DR=%04x",
368 (temp
& RH_B_PPCM
) >> 16,
371 temp
= roothub_status (controller
);
372 dbg ("roothub.status: %08x%s%s%s%s%s%s",
374 (temp
& RH_HS_CRWE
) ? " CRWE" : "",
375 (temp
& RH_HS_OCIC
) ? " OCIC" : "",
376 (temp
& RH_HS_LPSC
) ? " LPSC" : "",
377 (temp
& RH_HS_DRWE
) ? " DRWE" : "",
378 (temp
& RH_HS_OCI
) ? " OCI" : "",
379 (temp
& RH_HS_LPS
) ? " LPS" : ""
383 for (i
= 0; i
< ndp
; i
++) {
384 temp
= roothub_portstatus (controller
, i
);
385 dbg ("roothub.portstatus [%d] = 0x%08x%s%s%s%s%s%s%s%s%s%s%s%s",
388 (temp
& RH_PS_PRSC
) ? " PRSC" : "",
389 (temp
& RH_PS_OCIC
) ? " OCIC" : "",
390 (temp
& RH_PS_PSSC
) ? " PSSC" : "",
391 (temp
& RH_PS_PESC
) ? " PESC" : "",
392 (temp
& RH_PS_CSC
) ? " CSC" : "",
394 (temp
& RH_PS_LSDA
) ? " LSDA" : "",
395 (temp
& RH_PS_PPS
) ? " PPS" : "",
396 (temp
& RH_PS_PRS
) ? " PRS" : "",
397 (temp
& RH_PS_POCI
) ? " POCI" : "",
398 (temp
& RH_PS_PSS
) ? " PSS" : "",
400 (temp
& RH_PS_PES
) ? " PES" : "",
401 (temp
& RH_PS_CCS
) ? " CCS" : ""
406 static void ohci_dump (ohci_t
*controller
, int verbose
)
408 dbg ("OHCI controller usb-%s state", controller
->slot_name
);
410 /* dumps some of the state we know about */
411 ohci_dump_status (controller
);
413 ep_print_int_eds (controller
, "hcca");
414 dbg ("hcca frame #%04x", controller
->hcca
->frame_no
);
415 ohci_dump_roothub (controller
, 1);
419 /*-------------------------------------------------------------------------*
420 * Interface functions (URB)
421 *-------------------------------------------------------------------------*/
423 /* get a transfer request */
425 int sohci_submit_job(urb_priv_t
*urb
, struct devrequest
*setup
)
429 urb_priv_t
*purb_priv
= urb
;
431 struct usb_device
*dev
= urb
->dev
;
432 unsigned long pipe
= urb
->pipe
;
433 void *buffer
= urb
->transfer_buffer
;
434 int transfer_len
= urb
->transfer_buffer_length
;
435 int interval
= urb
->interval
;
439 /* when controller's hung, permit only roothub cleanup attempts
440 * such as powering down ports */
441 if (ohci
->disabled
) {
442 err("sohci_submit_job: EPIPE");
446 /* we're about to begin a new transaction here so mark the URB unfinished */
449 /* every endpoint has a ed, locate and fill it */
450 if (!(ed
= ep_add_ed (dev
, pipe
, interval
, 1))) {
451 err("sohci_submit_job: ENOMEM");
455 /* for the private part of the URB we need the number of TDs (size) */
456 switch (usb_pipetype (pipe
)) {
457 case PIPE_BULK
: /* one TD for every 4096 Byte */
458 size
= (transfer_len
- 1) / 4096 + 1;
460 case PIPE_CONTROL
: /* 1 TD for setup, 1 for ACK and 1 for every 4096 B */
461 size
= (transfer_len
== 0)? 2:
462 (transfer_len
- 1) / 4096 + 3;
464 case PIPE_INTERRUPT
: /* 1 TD */
471 if (size
>= (N_URB_TD
- 1)) {
472 err("need %d TDs, only have %d", size
, N_URB_TD
);
475 purb_priv
->pipe
= pipe
;
477 /* fill the private part of the URB */
478 purb_priv
->length
= size
;
480 purb_priv
->actual_length
= 0;
482 /* allocate the TDs */
483 /* note that td[0] was allocated in ep_add_ed */
484 for (i
= 0; i
< size
; i
++) {
485 purb_priv
->td
[i
] = td_alloc (dev
);
486 if (!purb_priv
->td
[i
]) {
487 purb_priv
->length
= i
;
488 urb_free_priv (purb_priv
);
489 err("sohci_submit_job: ENOMEM");
494 if (ed
->state
== ED_NEW
|| (ed
->state
& ED_DEL
)) {
495 urb_free_priv (purb_priv
);
496 err("sohci_submit_job: EINVAL");
500 /* link the ed into a chain if is not already */
501 if (ed
->state
!= ED_OPER
)
504 /* fill the TDs and link it to the ed */
505 td_submit_job(dev
, pipe
, buffer
, transfer_len
, setup
, purb_priv
, interval
);
510 static inline int sohci_return_job(struct ohci
*hc
, urb_priv_t
*urb
)
512 struct ohci_regs
*regs
= hc
->regs
;
514 switch (usb_pipetype (urb
->pipe
)) {
516 /* implicitly requeued */
517 if (urb
->dev
->irq_handle
&&
518 (urb
->dev
->irq_act_len
= urb
->actual_length
)) {
519 writel (OHCI_INTR_WDH
, ®s
->intrenable
);
520 readl (®s
->intrenable
); /* PCI posting flush */
521 urb
->dev
->irq_handle(urb
->dev
);
522 writel (OHCI_INTR_WDH
, ®s
->intrdisable
);
523 readl (®s
->intrdisable
); /* PCI posting flush */
525 urb
->actual_length
= 0;
529 urb
->transfer_buffer
,
530 urb
->transfer_buffer_length
,
544 /*-------------------------------------------------------------------------*/
547 /* tell us the current USB frame number */
549 static int sohci_get_current_frame_number (struct usb_device
*usb_dev
)
551 ohci_t
*ohci
= &gohci
;
553 return m16_swap (ohci
->hcca
->frame_no
);
557 /*-------------------------------------------------------------------------*
558 * ED handling functions
559 *-------------------------------------------------------------------------*/
561 /* search for the right branch to insert an interrupt ed into the int tree
562 * do some load ballancing;
563 * returns the branch and
564 * sets the interval to interval = 2^integer (ld (interval)) */
566 static int ep_int_ballance (ohci_t
* ohci
, int interval
, int load
)
570 /* search for the least loaded interrupt endpoint
571 * branch of all 32 branches
573 for (i
= 0; i
< 32; i
++)
574 if (ohci
->ohci_int_load
[branch
] > ohci
->ohci_int_load
[i
])
577 branch
= branch
% interval
;
578 for (i
= branch
; i
< 32; i
+= interval
)
579 ohci
->ohci_int_load
[i
] += load
;
584 /*-------------------------------------------------------------------------*/
586 /* 2^int( ld (inter)) */
588 static int ep_2_n_interval (int inter
)
591 for (i
= 0; ((inter
>> i
) > 1 ) && (i
< 5); i
++);
595 /*-------------------------------------------------------------------------*/
597 /* the int tree is a binary tree
598 * in order to process it sequentially the indexes of the branches have to be mapped
599 * the mapping reverses the bits of a word of num_bits length */
601 static int ep_rev (int num_bits
, int word
)
605 for (i
= 0; i
< num_bits
; i
++)
606 wout
|= (((word
>> i
) & 1) << (num_bits
- i
- 1));
610 /*-------------------------------------------------------------------------*
611 * ED handling functions
612 *-------------------------------------------------------------------------*/
614 /* link an ed into one of the HC chains */
616 static int ep_link (ohci_t
*ohci
, ed_t
*edi
)
618 volatile ed_t
*ed
= edi
;
627 ed
->int_interval
= 0;
632 if (ohci
->ed_controltail
== NULL
) {
633 writel (ed
, &ohci
->regs
->ed_controlhead
);
635 ohci
->ed_controltail
->hwNextED
= m32_swap ((unsigned long)ed
);
637 ed
->ed_prev
= ohci
->ed_controltail
;
638 if (!ohci
->ed_controltail
&& !ohci
->ed_rm_list
[0] &&
639 !ohci
->ed_rm_list
[1] && !ohci
->sleeping
) {
640 ohci
->hc_control
|= OHCI_CTRL_CLE
;
641 writel (ohci
->hc_control
, &ohci
->regs
->control
);
643 ohci
->ed_controltail
= edi
;
648 if (ohci
->ed_bulktail
== NULL
) {
649 writel (ed
, &ohci
->regs
->ed_bulkhead
);
651 ohci
->ed_bulktail
->hwNextED
= m32_swap ((unsigned long)ed
);
653 ed
->ed_prev
= ohci
->ed_bulktail
;
654 if (!ohci
->ed_bulktail
&& !ohci
->ed_rm_list
[0] &&
655 !ohci
->ed_rm_list
[1] && !ohci
->sleeping
) {
656 ohci
->hc_control
|= OHCI_CTRL_BLE
;
657 writel (ohci
->hc_control
, &ohci
->regs
->control
);
659 ohci
->ed_bulktail
= edi
;
664 interval
= ep_2_n_interval (ed
->int_period
);
665 ed
->int_interval
= interval
;
666 int_branch
= ep_int_ballance (ohci
, interval
, load
);
667 ed
->int_branch
= int_branch
;
669 for (i
= 0; i
< ep_rev (6, interval
); i
+= inter
) {
671 for (ed_p
= &(ohci
->hcca
->int_table
[ep_rev (5, i
) + int_branch
]);
672 (*ed_p
!= 0) && (((ed_t
*)ed_p
)->int_interval
>= interval
);
673 ed_p
= &(((ed_t
*)ed_p
)->hwNextED
))
674 inter
= ep_rev (6, ((ed_t
*)ed_p
)->int_interval
);
675 ed
->hwNextED
= *ed_p
;
676 *ed_p
= m32_swap((unsigned long)ed
);
683 /*-------------------------------------------------------------------------*/
685 /* scan the periodic table to find and unlink this ED */
686 static void periodic_unlink ( struct ohci
*ohci
, volatile struct ed
*ed
,
687 unsigned index
, unsigned period
)
689 for (; index
< NUM_INTS
; index
+= period
) {
690 __u32
*ed_p
= &ohci
->hcca
->int_table
[index
];
692 /* ED might have been unlinked through another path */
694 if (((struct ed
*)m32_swap ((unsigned long)ed_p
)) == ed
) {
695 *ed_p
= ed
->hwNextED
;
698 ed_p
= & (((struct ed
*)m32_swap ((unsigned long)ed_p
))->hwNextED
);
703 /* unlink an ed from one of the HC chains.
704 * just the link to the ed is unlinked.
705 * the link from the ed still points to another operational ed or 0
706 * so the HC can eventually finish the processing of the unlinked ed */
708 static int ep_unlink (ohci_t
*ohci
, ed_t
*edi
)
710 volatile ed_t
*ed
= edi
;
713 ed
->hwINFO
|= m32_swap (OHCI_ED_SKIP
);
717 if (ed
->ed_prev
== NULL
) {
719 ohci
->hc_control
&= ~OHCI_CTRL_CLE
;
720 writel (ohci
->hc_control
, &ohci
->regs
->control
);
722 writel (m32_swap (*((__u32
*)&ed
->hwNextED
)), &ohci
->regs
->ed_controlhead
);
724 ed
->ed_prev
->hwNextED
= ed
->hwNextED
;
726 if (ohci
->ed_controltail
== ed
) {
727 ohci
->ed_controltail
= ed
->ed_prev
;
729 ((ed_t
*)m32_swap (*((__u32
*)&ed
->hwNextED
)))->ed_prev
= ed
->ed_prev
;
734 if (ed
->ed_prev
== NULL
) {
736 ohci
->hc_control
&= ~OHCI_CTRL_BLE
;
737 writel (ohci
->hc_control
, &ohci
->regs
->control
);
739 writel (m32_swap (*((__u32
*)&ed
->hwNextED
)), &ohci
->regs
->ed_bulkhead
);
741 ed
->ed_prev
->hwNextED
= ed
->hwNextED
;
743 if (ohci
->ed_bulktail
== ed
) {
744 ohci
->ed_bulktail
= ed
->ed_prev
;
746 ((ed_t
*)m32_swap (*((__u32
*)&ed
->hwNextED
)))->ed_prev
= ed
->ed_prev
;
751 periodic_unlink (ohci
, ed
, 0, 1);
752 for (i
= ed
->int_branch
; i
< 32; i
+= ed
->int_interval
)
753 ohci
->ohci_int_load
[i
] -= ed
->int_load
;
756 ed
->state
= ED_UNLINK
;
760 /*-------------------------------------------------------------------------*/
762 /* add/reinit an endpoint; this should be done once at the
763 * usb_set_configuration command, but the USB stack is a little bit
764 * stateless so we do it at every transaction if the state of the ed
765 * is ED_NEW then a dummy td is added and the state is changed to
766 * ED_UNLINK in all other cases the state is left unchanged the ed
767 * info fields are setted anyway even though most of them should not
770 static ed_t
* ep_add_ed (struct usb_device
*usb_dev
, unsigned long pipe
,
771 int interval
, int load
)
777 ed
= ed_ret
= &ohci_dev
.ed
[(usb_pipeendpoint (pipe
) << 1) |
778 (usb_pipecontrol (pipe
)? 0: usb_pipeout (pipe
))];
780 if ((ed
->state
& ED_DEL
) || (ed
->state
& ED_URB_DEL
)) {
781 err("ep_add_ed: pending delete");
782 /* pending delete request */
786 if (ed
->state
== ED_NEW
) {
787 ed
->hwINFO
= m32_swap (OHCI_ED_SKIP
); /* skip ed */
788 /* dummy td; end of td list for ed */
789 td
= td_alloc (usb_dev
);
790 ed
->hwTailP
= m32_swap ((unsigned long)td
);
791 ed
->hwHeadP
= ed
->hwTailP
;
792 ed
->state
= ED_UNLINK
;
793 ed
->type
= usb_pipetype (pipe
);
797 ed
->hwINFO
= m32_swap (usb_pipedevice (pipe
)
798 | usb_pipeendpoint (pipe
) << 7
799 | (usb_pipeisoc (pipe
)? 0x8000: 0)
800 | (usb_pipecontrol (pipe
)? 0: (usb_pipeout (pipe
)? 0x800: 0x1000))
801 | usb_pipeslow (pipe
) << 13
802 | usb_maxpacket (usb_dev
, pipe
) << 16);
804 if (ed
->type
== PIPE_INTERRUPT
&& ed
->state
== ED_UNLINK
) {
805 ed
->int_period
= interval
;
812 /*-------------------------------------------------------------------------*
813 * TD handling functions
814 *-------------------------------------------------------------------------*/
816 /* enqueue next TD for this URB (OHCI spec 5.2.8.2) */
818 static void td_fill (ohci_t
*ohci
, unsigned int info
,
820 struct usb_device
*dev
, int index
, urb_priv_t
*urb_priv
)
822 volatile td_t
*td
, *td_pt
;
823 #ifdef OHCI_FILL_TRACE
827 if (index
> urb_priv
->length
) {
828 err("index > length");
831 /* use this td as the next dummy */
832 td_pt
= urb_priv
->td
[index
];
835 /* fill the old dummy TD */
836 td
= urb_priv
->td
[index
] = (td_t
*)(m32_swap (urb_priv
->ed
->hwTailP
) & ~0xf);
838 td
->ed
= urb_priv
->ed
;
839 td
->next_dl_td
= NULL
;
841 td
->data
= (__u32
)data
;
842 #ifdef OHCI_FILL_TRACE
843 if ((usb_pipetype(urb_priv
->pipe
) == PIPE_BULK
) && usb_pipeout(urb_priv
->pipe
)) {
844 for (i
= 0; i
< len
; i
++)
845 printf("td->data[%d] %#2x ",i
, ((unsigned char *)td
->data
)[i
]);
852 td
->hwINFO
= m32_swap (info
);
853 td
->hwCBP
= m32_swap ((unsigned long)data
);
855 td
->hwBE
= m32_swap ((unsigned long)(data
+ len
- 1));
858 td
->hwNextTD
= m32_swap ((unsigned long)td_pt
);
860 /* append to queue */
861 td
->ed
->hwTailP
= td
->hwNextTD
;
864 /*-------------------------------------------------------------------------*/
866 /* prepare all TDs of a transfer */
868 static void td_submit_job (struct usb_device
*dev
, unsigned long pipe
, void *buffer
,
869 int transfer_len
, struct devrequest
*setup
, urb_priv_t
*urb
, int interval
)
871 ohci_t
*ohci
= &gohci
;
872 int data_len
= transfer_len
;
876 unsigned int toggle
= 0;
878 /* OHCI handles the DATA-toggles itself, we just use the USB-toggle bits for reseting */
879 if(usb_gettoggle(dev
, usb_pipeendpoint(pipe
), usb_pipeout(pipe
))) {
880 toggle
= TD_T_TOGGLE
;
883 usb_settoggle(dev
, usb_pipeendpoint(pipe
), usb_pipeout(pipe
), 1);
891 switch (usb_pipetype (pipe
)) {
893 info
= usb_pipeout (pipe
)?
894 TD_CC
| TD_DP_OUT
: TD_CC
| TD_DP_IN
;
895 while(data_len
> 4096) {
896 td_fill (ohci
, info
| (cnt
? TD_T_TOGGLE
:toggle
), data
, 4096, dev
, cnt
, urb
);
897 data
+= 4096; data_len
-= 4096; cnt
++;
899 info
= usb_pipeout (pipe
)?
900 TD_CC
| TD_DP_OUT
: TD_CC
| TD_R
| TD_DP_IN
;
901 td_fill (ohci
, info
| (cnt
? TD_T_TOGGLE
:toggle
), data
, data_len
, dev
, cnt
, urb
);
905 writel (OHCI_BLF
, &ohci
->regs
->cmdstatus
); /* start bulk list */
909 info
= TD_CC
| TD_DP_SETUP
| TD_T_DATA0
;
910 td_fill (ohci
, info
, setup
, 8, dev
, cnt
++, urb
);
912 info
= usb_pipeout (pipe
)?
913 TD_CC
| TD_R
| TD_DP_OUT
| TD_T_DATA1
: TD_CC
| TD_R
| TD_DP_IN
| TD_T_DATA1
;
914 /* NOTE: mishandles transfers >8K, some >4K */
915 td_fill (ohci
, info
, data
, data_len
, dev
, cnt
++, urb
);
917 info
= usb_pipeout (pipe
)?
918 TD_CC
| TD_DP_IN
| TD_T_DATA1
: TD_CC
| TD_DP_OUT
| TD_T_DATA1
;
919 td_fill (ohci
, info
, data
, 0, dev
, cnt
++, urb
);
921 writel (OHCI_CLF
, &ohci
->regs
->cmdstatus
); /* start Control list */
925 info
= usb_pipeout (urb
->pipe
)?
926 TD_CC
| TD_DP_OUT
| toggle
:
927 TD_CC
| TD_R
| TD_DP_IN
| toggle
;
928 td_fill (ohci
, info
, data
, data_len
, dev
, cnt
++, urb
);
931 if (urb
->length
!= cnt
)
932 dbg("TD LENGTH %d != CNT %d", urb
->length
, cnt
);
935 /*-------------------------------------------------------------------------*
936 * Done List handling functions
937 *-------------------------------------------------------------------------*/
939 /* calculate the transfer length and update the urb */
941 static void dl_transfer_length(td_t
* td
)
943 __u32 tdINFO
, tdBE
, tdCBP
;
944 urb_priv_t
*lurb_priv
= td
->ed
->purb
;
946 tdINFO
= m32_swap (td
->hwINFO
);
947 tdBE
= m32_swap (td
->hwBE
);
948 tdCBP
= m32_swap (td
->hwCBP
);
950 if (!(usb_pipetype (lurb_priv
->pipe
) == PIPE_CONTROL
&&
951 ((td
->index
== 0) || (td
->index
== lurb_priv
->length
- 1)))) {
954 lurb_priv
->actual_length
+= tdBE
- td
->data
+ 1;
956 lurb_priv
->actual_length
+= tdCBP
- td
->data
;
961 /*-------------------------------------------------------------------------*/
963 /* replies to the request have to be on a FIFO basis so
964 * we reverse the reversed done-list */
966 static td_t
* dl_reverse_done_list (ohci_t
*ohci
)
970 td_t
*td_list
= NULL
;
971 urb_priv_t
*lurb_priv
= NULL
;
973 td_list_hc
= m32_swap (ohci
->hcca
->done_head
) & 0xfffffff0;
974 ohci
->hcca
->done_head
= 0;
977 td_list
= (td_t
*)td_list_hc
;
979 if (TD_CC_GET (m32_swap (td_list
->hwINFO
))) {
980 lurb_priv
= td_list
->ed
->purb
;
981 dbg(" USB-error/status: %x : %p",
982 TD_CC_GET (m32_swap (td_list
->hwINFO
)), td_list
);
983 if (td_list
->ed
->hwHeadP
& m32_swap (0x1)) {
984 if (lurb_priv
&& ((td_list
->index
+ 1) < lurb_priv
->length
)) {
985 td_list
->ed
->hwHeadP
=
986 (lurb_priv
->td
[lurb_priv
->length
- 1]->hwNextTD
& m32_swap (0xfffffff0)) |
987 (td_list
->ed
->hwHeadP
& m32_swap (0x2));
988 lurb_priv
->td_cnt
+= lurb_priv
->length
- td_list
->index
- 1;
990 td_list
->ed
->hwHeadP
&= m32_swap (0xfffffff2);
992 #ifdef CONFIG_MPC5200
993 td_list
->hwNextTD
= 0;
997 td_list
->next_dl_td
= td_rev
;
999 td_list_hc
= m32_swap (td_list
->hwNextTD
) & 0xfffffff0;
1004 /*-------------------------------------------------------------------------*/
1007 static int dl_done_list (ohci_t
*ohci
, td_t
*td_list
)
1009 td_t
*td_list_next
= NULL
;
1014 urb_priv_t
*lurb_priv
;
1015 __u32 tdINFO
, edHeadP
, edTailP
;
1018 td_list_next
= td_list
->next_dl_td
;
1020 tdINFO
= m32_swap (td_list
->hwINFO
);
1023 lurb_priv
= ed
->purb
;
1025 dl_transfer_length(td_list
);
1027 /* error code of transfer */
1028 cc
= TD_CC_GET (tdINFO
);
1030 dbg("ConditionCode %#x", cc
);
1031 stat
= cc_to_error
[cc
];
1034 /* see if this done list makes for all TD's of current URB,
1035 * and mark the URB finished if so */
1036 if (++(lurb_priv
->td_cnt
) == lurb_priv
->length
) {
1038 if ((ed
->state
& (ED_OPER
| ED_UNLINK
)) &&
1039 (lurb_priv
->state
!= URB_DEL
))
1041 if ((ed
->state
& (ED_OPER
| ED_UNLINK
)))
1043 lurb_priv
->finished
= sohci_return_job(ohci
,
1046 dbg("dl_done_list: strange.., ED state %x, ed->state\n");
1048 dbg("dl_done_list: processing TD %x, len %x\n", lurb_priv
->td_cnt
,
1050 if (ed
->state
!= ED_NEW
&&
1051 (usb_pipetype (lurb_priv
->pipe
) != PIPE_INTERRUPT
)) {
1052 edHeadP
= m32_swap (ed
->hwHeadP
) & 0xfffffff0;
1053 edTailP
= m32_swap (ed
->hwTailP
);
1055 /* unlink eds if they are not busy */
1056 if ((edHeadP
== edTailP
) && (ed
->state
== ED_OPER
))
1057 ep_unlink (ohci
, ed
);
1060 td_list
= td_list_next
;
1065 /*-------------------------------------------------------------------------*
1067 *-------------------------------------------------------------------------*/
1069 /* Device descriptor */
1070 static __u8 root_hub_dev_des
[] =
1072 0x12, /* __u8 bLength; */
1073 0x01, /* __u8 bDescriptorType; Device */
1074 0x10, /* __u16 bcdUSB; v1.1 */
1076 0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */
1077 0x00, /* __u8 bDeviceSubClass; */
1078 0x00, /* __u8 bDeviceProtocol; */
1079 0x08, /* __u8 bMaxPacketSize0; 8 Bytes */
1080 0x00, /* __u16 idVendor; */
1082 0x00, /* __u16 idProduct; */
1084 0x00, /* __u16 bcdDevice; */
1086 0x00, /* __u8 iManufacturer; */
1087 0x01, /* __u8 iProduct; */
1088 0x00, /* __u8 iSerialNumber; */
1089 0x01 /* __u8 bNumConfigurations; */
1092 /* Configuration descriptor */
1093 static __u8 root_hub_config_des
[] =
1095 0x09, /* __u8 bLength; */
1096 0x02, /* __u8 bDescriptorType; Configuration */
1097 0x19, /* __u16 wTotalLength; */
1099 0x01, /* __u8 bNumInterfaces; */
1100 0x01, /* __u8 bConfigurationValue; */
1101 0x00, /* __u8 iConfiguration; */
1102 0x40, /* __u8 bmAttributes;
1103 Bit 7: Bus-powered, 6: Self-powered, 5 Remote-wakwup, 4..0: resvd */
1104 0x00, /* __u8 MaxPower; */
1107 0x09, /* __u8 if_bLength; */
1108 0x04, /* __u8 if_bDescriptorType; Interface */
1109 0x00, /* __u8 if_bInterfaceNumber; */
1110 0x00, /* __u8 if_bAlternateSetting; */
1111 0x01, /* __u8 if_bNumEndpoints; */
1112 0x09, /* __u8 if_bInterfaceClass; HUB_CLASSCODE */
1113 0x00, /* __u8 if_bInterfaceSubClass; */
1114 0x00, /* __u8 if_bInterfaceProtocol; */
1115 0x00, /* __u8 if_iInterface; */
1118 0x07, /* __u8 ep_bLength; */
1119 0x05, /* __u8 ep_bDescriptorType; Endpoint */
1120 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */
1121 0x03, /* __u8 ep_bmAttributes; Interrupt */
1122 0x02, /* __u16 ep_wMaxPacketSize; ((MAX_ROOT_PORTS + 1) / 8 */
1124 0xff /* __u8 ep_bInterval; 255 ms */
1127 static unsigned char root_hub_str_index0
[] =
1129 0x04, /* __u8 bLength; */
1130 0x03, /* __u8 bDescriptorType; String-descriptor */
1131 0x09, /* __u8 lang ID */
1132 0x04, /* __u8 lang ID */
1135 static unsigned char root_hub_str_index1
[] =
1137 28, /* __u8 bLength; */
1138 0x03, /* __u8 bDescriptorType; String-descriptor */
1139 'O', /* __u8 Unicode */
1140 0, /* __u8 Unicode */
1141 'H', /* __u8 Unicode */
1142 0, /* __u8 Unicode */
1143 'C', /* __u8 Unicode */
1144 0, /* __u8 Unicode */
1145 'I', /* __u8 Unicode */
1146 0, /* __u8 Unicode */
1147 ' ', /* __u8 Unicode */
1148 0, /* __u8 Unicode */
1149 'R', /* __u8 Unicode */
1150 0, /* __u8 Unicode */
1151 'o', /* __u8 Unicode */
1152 0, /* __u8 Unicode */
1153 'o', /* __u8 Unicode */
1154 0, /* __u8 Unicode */
1155 't', /* __u8 Unicode */
1156 0, /* __u8 Unicode */
1157 ' ', /* __u8 Unicode */
1158 0, /* __u8 Unicode */
1159 'H', /* __u8 Unicode */
1160 0, /* __u8 Unicode */
1161 'u', /* __u8 Unicode */
1162 0, /* __u8 Unicode */
1163 'b', /* __u8 Unicode */
1164 0, /* __u8 Unicode */
1167 /* Hub class-specific descriptor is constructed dynamically */
1169 /*-------------------------------------------------------------------------*/
1171 #define OK(x) len = (x); break
1173 #define WR_RH_STAT(x) {info("WR:status %#8x", (x));writel((x), &gohci.regs->roothub.status);}
1174 #define WR_RH_PORTSTAT(x) {info("WR:portstatus[%d] %#8x", wIndex-1, (x));writel((x), &gohci.regs->roothub.portstatus[wIndex-1]);}
1176 #define WR_RH_STAT(x) writel((x), &gohci.regs->roothub.status)
1177 #define WR_RH_PORTSTAT(x) writel((x), &gohci.regs->roothub.portstatus[wIndex-1])
1179 #define RD_RH_STAT roothub_status(&gohci)
1180 #define RD_RH_PORTSTAT roothub_portstatus(&gohci,wIndex-1)
1182 /* request to virtual root hub */
1184 int rh_check_port_status(ohci_t
*controller
)
1190 temp
= roothub_a (controller
);
1191 ndp
= (temp
& RH_A_NDP
);
1192 #ifdef CONFIG_AT91C_PQFP_UHPBUG
1193 ndp
= (ndp
== 2) ? 1:0;
1195 for (i
= 0; i
< ndp
; i
++) {
1196 temp
= roothub_portstatus (controller
, i
);
1197 /* check for a device disconnect */
1198 if (((temp
& (RH_PS_PESC
| RH_PS_CSC
)) ==
1199 (RH_PS_PESC
| RH_PS_CSC
)) &&
1200 ((temp
& RH_PS_CCS
) == 0)) {
1208 static int ohci_submit_rh_msg(struct usb_device
*dev
, unsigned long pipe
,
1209 void *buffer
, int transfer_len
, struct devrequest
*cmd
)
1211 void * data
= buffer
;
1212 int leni
= transfer_len
;
1216 __u8
*data_buf
= (__u8
*)datab
;
1223 pkt_print(NULL
, dev
, pipe
, buffer
, transfer_len
, cmd
, "SUB(rh)", usb_pipein(pipe
));
1227 if ((pipe
& PIPE_INTERRUPT
) == PIPE_INTERRUPT
) {
1228 info("Root-Hub submit IRQ: NOT implemented");
1232 bmRType_bReq
= cmd
->requesttype
| (cmd
->request
<< 8);
1233 wValue
= le16_to_cpu (cmd
->value
);
1234 wIndex
= le16_to_cpu (cmd
->index
);
1235 wLength
= le16_to_cpu (cmd
->length
);
1237 info("Root-Hub: adr: %2x cmd(%1x): %08x %04x %04x %04x",
1238 dev
->devnum
, 8, bmRType_bReq
, wValue
, wIndex
, wLength
);
1240 switch (bmRType_bReq
) {
1241 /* Request Destination:
1242 without flags: Device,
1243 RH_INTERFACE: interface,
1244 RH_ENDPOINT: endpoint,
1245 RH_CLASS means HUB here,
1246 RH_OTHER | RH_CLASS almost ever means HUB_PORT here
1250 *(__u16
*) data_buf
= cpu_to_le16 (1); OK (2);
1251 case RH_GET_STATUS
| RH_INTERFACE
:
1252 *(__u16
*) data_buf
= cpu_to_le16 (0); OK (2);
1253 case RH_GET_STATUS
| RH_ENDPOINT
:
1254 *(__u16
*) data_buf
= cpu_to_le16 (0); OK (2);
1255 case RH_GET_STATUS
| RH_CLASS
:
1256 *(__u32
*) data_buf
= cpu_to_le32 (
1257 RD_RH_STAT
& ~(RH_HS_CRWE
| RH_HS_DRWE
));
1259 case RH_GET_STATUS
| RH_OTHER
| RH_CLASS
:
1260 *(__u32
*) data_buf
= cpu_to_le32 (RD_RH_PORTSTAT
); OK (4);
1262 case RH_CLEAR_FEATURE
| RH_ENDPOINT
:
1264 case (RH_ENDPOINT_STALL
): OK (0);
1268 case RH_CLEAR_FEATURE
| RH_CLASS
:
1270 case RH_C_HUB_LOCAL_POWER
:
1272 case (RH_C_HUB_OVER_CURRENT
):
1273 WR_RH_STAT(RH_HS_OCIC
); OK (0);
1277 case RH_CLEAR_FEATURE
| RH_OTHER
| RH_CLASS
:
1279 case (RH_PORT_ENABLE
):
1280 WR_RH_PORTSTAT (RH_PS_CCS
); OK (0);
1281 case (RH_PORT_SUSPEND
):
1282 WR_RH_PORTSTAT (RH_PS_POCI
); OK (0);
1283 case (RH_PORT_POWER
):
1284 WR_RH_PORTSTAT (RH_PS_LSDA
); OK (0);
1285 case (RH_C_PORT_CONNECTION
):
1286 WR_RH_PORTSTAT (RH_PS_CSC
); OK (0);
1287 case (RH_C_PORT_ENABLE
):
1288 WR_RH_PORTSTAT (RH_PS_PESC
); OK (0);
1289 case (RH_C_PORT_SUSPEND
):
1290 WR_RH_PORTSTAT (RH_PS_PSSC
); OK (0);
1291 case (RH_C_PORT_OVER_CURRENT
):
1292 WR_RH_PORTSTAT (RH_PS_OCIC
); OK (0);
1293 case (RH_C_PORT_RESET
):
1294 WR_RH_PORTSTAT (RH_PS_PRSC
); OK (0);
1298 case RH_SET_FEATURE
| RH_OTHER
| RH_CLASS
:
1300 case (RH_PORT_SUSPEND
):
1301 WR_RH_PORTSTAT (RH_PS_PSS
); OK (0);
1302 case (RH_PORT_RESET
): /* BUG IN HUP CODE *********/
1303 if (RD_RH_PORTSTAT
& RH_PS_CCS
)
1304 WR_RH_PORTSTAT (RH_PS_PRS
);
1306 case (RH_PORT_POWER
):
1307 WR_RH_PORTSTAT (RH_PS_PPS
);
1310 case (RH_PORT_ENABLE
): /* BUG IN HUP CODE *********/
1311 if (RD_RH_PORTSTAT
& RH_PS_CCS
)
1312 WR_RH_PORTSTAT (RH_PS_PES
);
1317 case RH_SET_ADDRESS
: gohci
.rh
.devnum
= wValue
; OK(0);
1319 case RH_GET_DESCRIPTOR
:
1320 switch ((wValue
& 0xff00) >> 8) {
1321 case (0x01): /* device descriptor */
1322 len
= min_t(unsigned int,
1325 sizeof (root_hub_dev_des
),
1327 data_buf
= root_hub_dev_des
; OK(len
);
1328 case (0x02): /* configuration descriptor */
1329 len
= min_t(unsigned int,
1332 sizeof (root_hub_config_des
),
1334 data_buf
= root_hub_config_des
; OK(len
);
1335 case (0x03): /* string descriptors */
1336 if(wValue
==0x0300) {
1337 len
= min_t(unsigned int,
1340 sizeof (root_hub_str_index0
),
1342 data_buf
= root_hub_str_index0
;
1345 if(wValue
==0x0301) {
1346 len
= min_t(unsigned int,
1349 sizeof (root_hub_str_index1
),
1351 data_buf
= root_hub_str_index1
;
1355 stat
= USB_ST_STALLED
;
1359 case RH_GET_DESCRIPTOR
| RH_CLASS
:
1361 __u32 temp
= roothub_a (&gohci
);
1363 data_buf
[0] = 9; /* min length; */
1364 data_buf
[1] = 0x29;
1365 data_buf
[2] = temp
& RH_A_NDP
;
1366 #ifdef CONFIG_AT91C_PQFP_UHPBUG
1367 data_buf
[2] = (data_buf
[2] == 2) ? 1:0;
1370 if (temp
& RH_A_PSM
) /* per-port power switching? */
1371 data_buf
[3] |= 0x1;
1372 if (temp
& RH_A_NOCP
) /* no overcurrent reporting? */
1373 data_buf
[3] |= 0x10;
1374 else if (temp
& RH_A_OCPM
) /* per-port overcurrent reporting? */
1375 data_buf
[3] |= 0x8;
1377 /* corresponds to data_buf[4-7] */
1379 data_buf
[5] = (temp
& RH_A_POTPGT
) >> 24;
1380 temp
= roothub_b (&gohci
);
1381 data_buf
[7] = temp
& RH_B_DR
;
1382 if (data_buf
[2] < 7) {
1383 data_buf
[8] = 0xff;
1386 data_buf
[8] = (temp
& RH_B_DR
) >> 8;
1387 data_buf
[10] = data_buf
[9] = 0xff;
1390 len
= min_t(unsigned int, leni
,
1391 min_t(unsigned int, data_buf
[0], wLength
));
1395 case RH_GET_CONFIGURATION
: *(__u8
*) data_buf
= 0x01; OK (1);
1397 case RH_SET_CONFIGURATION
: WR_RH_STAT (0x10000); OK (0);
1400 dbg ("unsupported root hub command");
1401 stat
= USB_ST_STALLED
;
1405 ohci_dump_roothub (&gohci
, 1);
1410 len
= min_t(int, len
, leni
);
1411 if (data
!= data_buf
)
1412 memcpy (data
, data_buf
, len
);
1417 pkt_print(NULL
, dev
, pipe
, buffer
, transfer_len
, cmd
, "RET(rh)", 0/*usb_pipein(pipe)*/);
1425 /*-------------------------------------------------------------------------*/
1427 /* common code for handling submit messages - used for all but root hub */
1429 int submit_common_msg(struct usb_device
*dev
, unsigned long pipe
, void *buffer
,
1430 int transfer_len
, struct devrequest
*setup
, int interval
)
1433 int maxsize
= usb_maxpacket(dev
, pipe
);
1437 urb
= malloc(sizeof(urb_priv_t
));
1438 memset(urb
, 0, sizeof(urb_priv_t
));
1442 urb
->transfer_buffer
= buffer
;
1443 urb
->transfer_buffer_length
= transfer_len
;
1444 urb
->interval
= interval
;
1446 /* device pulled? Shortcut the action. */
1447 if (devgone
== dev
) {
1448 dev
->status
= USB_ST_CRC_ERR
;
1453 urb
->actual_length
= 0;
1454 pkt_print(urb
, dev
, pipe
, buffer
, transfer_len
, setup
, "SUB", usb_pipein(pipe
));
1459 err("submit_common_message: pipesize for pipe %lx is zero",
1464 if (sohci_submit_job(urb
, setup
) < 0) {
1465 err("sohci_submit_job failed");
1471 /* ohci_dump_status(&gohci); */
1474 /* allow more time for a BULK device to react - some are slow */
1475 #define BULK_TO 5000 /* timeout in milliseconds */
1476 if (usb_pipetype (pipe
) == PIPE_BULK
)
1481 /* wait for it to complete */
1483 /* check whether the controller is done */
1484 stat
= hc_interrupt();
1486 stat
= USB_ST_CRC_ERR
;
1490 /* NOTE: since we are not interrupt driven in U-Boot and always
1491 * handle only one URB at a time, we cannot assume the
1492 * transaction finished on the first successful return from
1493 * hc_interrupt().. unless the flag for current URB is set,
1494 * meaning that all TD's to/from device got actually
1495 * transferred and processed. If the current URB is not
1496 * finished we need to re-iterate this loop so as
1497 * hc_interrupt() gets called again as there needs to be some
1498 * more TD's to process still */
1499 if ((stat
>= 0) && (stat
!= 0xff) && (urb
->finished
)) {
1500 /* 0xff is returned for an SF-interrupt */
1510 err("CTL:TIMEOUT ");
1511 dbg("submit_common_msg: TO status %x\n", stat
);
1513 stat
= USB_ST_CRC_ERR
;
1519 dev
->act_len
= transfer_len
;
1522 pkt_print(urb
, dev
, pipe
, buffer
, transfer_len
, setup
, "RET(ctlr)", usb_pipein(pipe
));
1527 /* free TDs in urb_priv */
1528 if (usb_pipetype (pipe
) != PIPE_INTERRUPT
)
1529 urb_free_priv (urb
);
1533 /* submit routines called from usb.c */
1534 int submit_bulk_msg(struct usb_device
*dev
, unsigned long pipe
, void *buffer
,
1537 info("submit_bulk_msg");
1538 return submit_common_msg(dev
, pipe
, buffer
, transfer_len
, NULL
, 0);
1541 int submit_control_msg(struct usb_device
*dev
, unsigned long pipe
, void *buffer
,
1542 int transfer_len
, struct devrequest
*setup
)
1544 int maxsize
= usb_maxpacket(dev
, pipe
);
1546 info("submit_control_msg");
1548 pkt_print(NULL
, dev
, pipe
, buffer
, transfer_len
, setup
, "SUB", usb_pipein(pipe
));
1553 err("submit_control_message: pipesize for pipe %lx is zero",
1557 if (((pipe
>> 8) & 0x7f) == gohci
.rh
.devnum
) {
1559 /* root hub - redirect */
1560 return ohci_submit_rh_msg(dev
, pipe
, buffer
, transfer_len
,
1564 return submit_common_msg(dev
, pipe
, buffer
, transfer_len
, setup
, 0);
1567 int submit_int_msg(struct usb_device
*dev
, unsigned long pipe
, void *buffer
,
1568 int transfer_len
, int interval
)
1570 info("submit_int_msg");
1571 return submit_common_msg(dev
, pipe
, buffer
, transfer_len
, NULL
,
1575 /*-------------------------------------------------------------------------*
1577 *-------------------------------------------------------------------------*/
1579 /* reset the HC and BUS */
1581 static int hc_reset (ohci_t
*ohci
)
1583 #ifdef CONFIG_PCI_EHCI_DEVNO
1587 int smm_timeout
= 50; /* 0,5 sec */
1589 dbg("%s\n", __FUNCTION__
);
1591 #ifdef CONFIG_PCI_EHCI_DEVNO
1593 * Some multi-function controllers (e.g. ISP1562) allow root hub
1594 * resetting via EHCI registers only.
1596 pdev
= pci_find_devices(ehci_pci_ids
, CONFIG_PCI_EHCI_DEVNO
);
1601 pci_read_config_dword(pdev
, PCI_BASE_ADDRESS_0
, &base
);
1602 writel (readl(base
+ EHCI_USBCMD_OFF
) | EHCI_USBCMD_HCRESET
,
1603 base
+ EHCI_USBCMD_OFF
);
1605 while (readl(base
+ EHCI_USBCMD_OFF
) & EHCI_USBCMD_HCRESET
) {
1606 if (timeout
-- <= 0) {
1607 printf("USB RootHub reset timed out!");
1613 printf("No EHCI func at %d index!\n", CONFIG_PCI_EHCI_DEVNO
);
1615 if (readl (&ohci
->regs
->control
) & OHCI_CTRL_IR
) { /* SMM owns the HC */
1616 writel (OHCI_OCR
, &ohci
->regs
->cmdstatus
); /* request ownership */
1617 info("USB HC TakeOver from SMM");
1618 while (readl (&ohci
->regs
->control
) & OHCI_CTRL_IR
) {
1620 if (--smm_timeout
== 0) {
1621 err("USB HC TakeOver failed!");
1627 /* Disable HC interrupts */
1628 writel (OHCI_INTR_MIE
, &ohci
->regs
->intrdisable
);
1630 dbg("USB HC reset_hc usb-%s: ctrl = 0x%X ;\n",
1632 readl(&ohci
->regs
->control
));
1634 /* Reset USB (needed by some controllers) */
1635 ohci
->hc_control
= 0;
1636 writel (ohci
->hc_control
, &ohci
->regs
->control
);
1638 /* HC Reset requires max 10 us delay */
1639 writel (OHCI_HCR
, &ohci
->regs
->cmdstatus
);
1640 while ((readl (&ohci
->regs
->cmdstatus
) & OHCI_HCR
) != 0) {
1641 if (--timeout
== 0) {
1642 err("USB HC reset timed out!");
1650 /*-------------------------------------------------------------------------*/
1652 /* Start an OHCI controller, set the BUS operational
1654 * connect the virtual root hub */
1656 static int hc_start (ohci_t
* ohci
)
1659 unsigned int fminterval
;
1663 /* Tell the controller where the control and bulk lists are
1664 * The lists are empty now. */
1666 writel (0, &ohci
->regs
->ed_controlhead
);
1667 writel (0, &ohci
->regs
->ed_bulkhead
);
1669 writel ((__u32
)ohci
->hcca
, &ohci
->regs
->hcca
); /* a reset clears this */
1671 fminterval
= 0x2edf;
1672 writel ((fminterval
* 9) / 10, &ohci
->regs
->periodicstart
);
1673 fminterval
|= ((((fminterval
- 210) * 6) / 7) << 16);
1674 writel (fminterval
, &ohci
->regs
->fminterval
);
1675 writel (0x628, &ohci
->regs
->lsthresh
);
1677 /* start controller operations */
1678 ohci
->hc_control
= OHCI_CONTROL_INIT
| OHCI_USB_OPER
;
1680 writel (ohci
->hc_control
, &ohci
->regs
->control
);
1682 /* disable all interrupts */
1683 mask
= (OHCI_INTR_SO
| OHCI_INTR_WDH
| OHCI_INTR_SF
| OHCI_INTR_RD
|
1684 OHCI_INTR_UE
| OHCI_INTR_FNO
| OHCI_INTR_RHSC
|
1685 OHCI_INTR_OC
| OHCI_INTR_MIE
);
1686 writel (mask
, &ohci
->regs
->intrdisable
);
1687 /* clear all interrupts */
1688 mask
&= ~OHCI_INTR_MIE
;
1689 writel (mask
, &ohci
->regs
->intrstatus
);
1690 /* Choose the interrupts we care about now - but w/o MIE */
1691 mask
= OHCI_INTR_RHSC
| OHCI_INTR_UE
| OHCI_INTR_WDH
| OHCI_INTR_SO
;
1692 writel (mask
, &ohci
->regs
->intrenable
);
1695 /* required for AMD-756 and some Mac platforms */
1696 writel ((roothub_a (ohci
) | RH_A_NPS
) & ~RH_A_PSM
,
1697 &ohci
->regs
->roothub
.a
);
1698 writel (RH_HS_LPSC
, &ohci
->regs
->roothub
.status
);
1699 #endif /* OHCI_USE_NPS */
1701 #define mdelay(n) ({unsigned long msec=(n); while (msec--) udelay(1000);})
1702 /* POTPGT delay is bits 24-31, in 2 ms units. */
1703 mdelay ((roothub_a (ohci
) >> 23) & 0x1fe);
1705 /* connect the virtual root hub */
1706 ohci
->rh
.devnum
= 0;
1711 /*-------------------------------------------------------------------------*/
1713 /* Poll USB interrupt. */
1714 void usb_event_poll(void)
1719 /* an interrupt happens */
1721 static int hc_interrupt (void)
1723 ohci_t
*ohci
= &gohci
;
1724 struct ohci_regs
*regs
= ohci
->regs
;
1728 if ((ohci
->hcca
->done_head
!= 0) &&
1729 !(m32_swap (ohci
->hcca
->done_head
) & 0x01)) {
1730 ints
= OHCI_INTR_WDH
;
1731 } else if ((ints
= readl (®s
->intrstatus
)) == ~(u32
)0) {
1733 err ("%s device removed!", ohci
->slot_name
);
1735 } else if ((ints
&= readl (®s
->intrenable
)) == 0) {
1736 dbg("hc_interrupt: returning..\n");
1740 /* dbg("Interrupt: %x frame: %x", ints, le16_to_cpu (ohci->hcca->frame_no)); */
1742 if (ints
& OHCI_INTR_RHSC
) {
1747 if (ints
& OHCI_INTR_UE
) {
1749 err ("OHCI Unrecoverable Error, controller usb-%s disabled",
1751 /* e.g. due to PCI Master/Target Abort */
1754 ohci_dump (ohci
, 1);
1758 /* FIXME: be optimistic, hope that bug won't repeat often. */
1759 /* Make some non-interrupt context restart the controller. */
1760 /* Count and limit the retries though; either hardware or */
1761 /* software errors can go forever... */
1766 if (ints
& OHCI_INTR_WDH
) {
1768 writel (OHCI_INTR_WDH
, ®s
->intrdisable
);
1769 (void)readl (®s
->intrdisable
); /* flush */
1770 stat
= dl_done_list (&gohci
, dl_reverse_done_list (&gohci
));
1771 writel (OHCI_INTR_WDH
, ®s
->intrenable
);
1772 (void)readl (®s
->intrdisable
); /* flush */
1775 if (ints
& OHCI_INTR_SO
) {
1776 dbg("USB Schedule overrun\n");
1777 writel (OHCI_INTR_SO
, ®s
->intrenable
);
1781 /* FIXME: this assumes SOF (1/ms) interrupts don't get lost... */
1782 if (ints
& OHCI_INTR_SF
) {
1783 unsigned int frame
= m16_swap (ohci
->hcca
->frame_no
) & 1;
1785 writel (OHCI_INTR_SF
, ®s
->intrdisable
);
1786 if (ohci
->ed_rm_list
[frame
] != NULL
)
1787 writel (OHCI_INTR_SF
, ®s
->intrenable
);
1791 writel (ints
, ®s
->intrstatus
);
1795 /*-------------------------------------------------------------------------*/
1797 /*-------------------------------------------------------------------------*/
1799 /* De-allocate all resources.. */
1801 static void hc_release_ohci (ohci_t
*ohci
)
1803 dbg ("USB HC release ohci usb-%s", ohci
->slot_name
);
1805 if (!ohci
->disabled
)
1809 /*-------------------------------------------------------------------------*/
1812 * low level initalisation routine, called from usb.c
1814 static char ohci_inited
= 0;
1816 int usb_lowlevel_init(void)
1818 #ifdef CONFIG_PCI_OHCI
1822 #ifdef CONFIG_SYS_USB_OHCI_CPU_INIT
1823 /* cpu dependant init */
1828 #ifdef CONFIG_SYS_USB_OHCI_BOARD_INIT
1829 /* board dependant init */
1830 if(usb_board_init())
1833 memset (&gohci
, 0, sizeof (ohci_t
));
1835 /* align the storage */
1836 if ((__u32
)&ghcca
[0] & 0xff) {
1837 err("HCCA not aligned!!");
1841 info("aligned ghcca %p", phcca
);
1842 memset(&ohci_dev
, 0, sizeof(struct ohci_device
));
1843 if ((__u32
)&ohci_dev
.ed
[0] & 0x7) {
1844 err("EDs not aligned!!");
1847 memset(gtd
, 0, sizeof(td_t
) * (NUM_TD
+ 1));
1848 if ((__u32
)gtd
& 0x7) {
1849 err("TDs not aligned!!");
1854 memset (phcca
, 0, sizeof (struct ohci_hcca
));
1859 #ifdef CONFIG_PCI_OHCI
1860 pdev
= pci_find_devices(ohci_pci_ids
, CONFIG_PCI_OHCI_DEVNO
);
1865 pci_read_config_word(pdev
, PCI_VENDOR_ID
, &vid
);
1866 pci_read_config_word(pdev
, PCI_DEVICE_ID
, &did
);
1867 printf("OHCI pci controller (%04x, %04x) found @(%d:%d:%d)\n",
1868 vid
, did
, (pdev
>> 16) & 0xff,
1869 (pdev
>> 11) & 0x1f, (pdev
>> 8) & 0x7);
1870 pci_read_config_dword(pdev
, PCI_BASE_ADDRESS_0
, &base
);
1871 printf("OHCI regs address 0x%08x\n", base
);
1872 gohci
.regs
= (struct ohci_regs
*)base
;
1876 gohci
.regs
= (struct ohci_regs
*)CONFIG_SYS_USB_OHCI_REGS_BASE
;
1880 gohci
.slot_name
= CONFIG_SYS_USB_OHCI_SLOT_NAME
;
1882 if (hc_reset (&gohci
) < 0) {
1883 hc_release_ohci (&gohci
);
1884 err ("can't reset usb-%s", gohci
.slot_name
);
1885 #ifdef CONFIG_SYS_USB_OHCI_BOARD_INIT
1886 /* board dependant cleanup */
1887 usb_board_init_fail();
1890 #ifdef CONFIG_SYS_USB_OHCI_CPU_INIT
1891 /* cpu dependant cleanup */
1892 usb_cpu_init_fail();
1897 /* FIXME this is a second HC reset; why?? */
1898 /* writel(gohci.hc_control = OHCI_USB_RESET, &gohci.regs->control);
1900 if (hc_start (&gohci
) < 0) {
1901 err ("can't start usb-%s", gohci
.slot_name
);
1902 hc_release_ohci (&gohci
);
1903 /* Initialization failed */
1904 #ifdef CONFIG_SYS_USB_OHCI_BOARD_INIT
1905 /* board dependant cleanup */
1909 #ifdef CONFIG_SYS_USB_OHCI_CPU_INIT
1910 /* cpu dependant cleanup */
1917 ohci_dump (&gohci
, 1);
1925 int usb_lowlevel_stop(void)
1927 /* this gets called really early - before the controller has */
1928 /* even been initialized! */
1931 /* TODO release any interrupts, etc. */
1932 /* call hc_release_ohci() here ? */
1935 #ifdef CONFIG_SYS_USB_OHCI_BOARD_INIT
1936 /* board dependant cleanup */
1937 if(usb_board_stop())
1941 #ifdef CONFIG_SYS_USB_OHCI_CPU_INIT
1942 /* cpu dependant cleanup */
1946 /* This driver is no longer initialised. It needs a new low-level
1947 * init (board/cpu) before it can be used again. */
1951 #endif /* CONFIG_USB_OHCI_NEW */