2 * OHCI HCD (Host Controller Driver) for USB.
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
7 * [ Initialisation is based on Linus' ]
8 * [ uhci code and gregs ohci fragments ]
9 * [ (C) Copyright 1999 Linus Torvalds ]
10 * [ (C) Copyright 1999 Gregory P. Smith]
14 * This file is licenced under the GPL.
17 #ifdef CONFIG_PMAC_PBOOK
18 #include <asm/machdep.h>
19 #include <asm/pmac_feature.h>
20 #include <asm/pci-bridge.h>
28 #error "This file is PCI bus glue. CONFIG_PCI must be defined."
31 #include "../linux/pci_ids.h"
33 /*-------------------------------------------------------------------------*/
36 ohci_pci_start (struct usb_hcd
*hcd
)
38 struct ohci_hcd
*ohci
= hcd_to_ohci (hcd
);
41 DPRINT("ohci_pci_start()\n");
44 ohci
->hcca
= pci_alloc_consistent (hcd
->pdev
,
45 sizeof *ohci
->hcca
, &ohci
->hcca_dma
);
49 /* AMD 756, for most chips (early revs), corrupts register
50 * values on read ... so enable the vendor workaround.
52 if (hcd
->pdev
->vendor
== PCI_VENDOR_ID_AMD
53 && hcd
->pdev
->device
== 0x740c) {
54 ohci
->flags
= OHCI_QUIRK_AMD756
;
55 ohci_info (ohci
, "AMD756 erratum 4 workaround\n");
58 /* FIXME for some of the early AMD 760 southbridges, OHCI
59 * won't work at all. blacklist them.
62 /* Apple's OHCI driver has a lot of bizarre workarounds
63 * for this chip. Evidently control and bulk lists
64 * can get confused. (B&W G3 models, and ...)
66 else if (hcd
->pdev
->vendor
== PCI_VENDOR_ID_OPTI
67 && hcd
->pdev
->device
== 0xc861) {
69 "WARNING: OPTi workarounds unavailable\n");
72 /* Check for NSC87560. We have to look at the bridge (fn1) to
73 * identify the USB (fn2). This quirk might apply to more or
76 else if (hcd
->pdev
->vendor
== PCI_VENDOR_ID_NS
) {
77 struct pci_dev
*b
, *hc
;
80 b
= pci_find_slot (hc
->bus
->number
,
81 PCI_DEVFN (PCI_SLOT (hc
->devfn
), 1));
82 if (b
&& b
->device
== PCI_DEVICE_ID_NS_87560_LIO
83 && b
->vendor
== PCI_VENDOR_ID_NS
) {
84 ohci
->flags
|= OHCI_QUIRK_SUPERIO
;
85 ohci_info (ohci
, "Using NSC SuperIO setup\n");
91 memset (ohci
->hcca
, 0, sizeof (struct ohci_hcca
));
92 if ((ret
= ohci_mem_init (ohci
)) < 0) {
96 ohci
->regs
= hcd
->regs
;
98 DPRINT("Controller memory init done\n");
100 if (hc_reset (ohci
) < 0) {
104 DPRINT("Controller reset done\n");
106 if (hc_start (ohci
) < 0) {
107 ohci_err (ohci
, "can't start\n");
111 DPRINT("Controller start done\n");
121 static int ohci_pci_suspend (struct usb_hcd
*hcd
, u32 state
)
123 struct ohci_hcd
*ohci
= hcd_to_ohci (hcd
);
127 if ((ohci
->hc_control
& OHCI_CTRL_HCFS
) != OHCI_USB_OPER
) {
128 ohci_dbg (ohci
, "can't suspend (state is %s)\n",
129 hcfs2string (ohci
->hc_control
& OHCI_CTRL_HCFS
));
133 /* act as if usb suspend can always be used */
134 ohci_dbg (ohci
, "suspend to %d\n", state
);
137 /* First stop processing */
138 spin_lock_irqsave (&ohci
->lock
, flags
);
140 ~(OHCI_CTRL_PLE
|OHCI_CTRL_CLE
|OHCI_CTRL_BLE
|OHCI_CTRL_IE
);
141 writel (ohci
->hc_control
, &ohci
->regs
->control
);
142 writel (OHCI_INTR_SF
, &ohci
->regs
->intrstatus
);
143 (void) readl (&ohci
->regs
->intrstatus
);
144 spin_unlock_irqrestore (&ohci
->lock
, flags
);
146 /* Wait a frame or two */
148 if (!readl (&ohci
->regs
->intrstatus
) & OHCI_INTR_SF
)
151 #ifdef CONFIG_PMAC_PBOOK
152 if (_machine
== _MACH_Pmac
)
153 disable_irq (hcd
->pdev
->irq
);
154 /* else, 2.4 assumes shared irqs -- don't disable */
157 /* Enable remote wakeup */
158 writel (readl (&ohci
->regs
->intrenable
) | OHCI_INTR_RD
,
159 &ohci
->regs
->intrenable
);
161 /* Suspend chip and let things settle down a bit */
162 ohci
->hc_control
= OHCI_USB_SUSPEND
;
163 writel (ohci
->hc_control
, &ohci
->regs
->control
);
164 (void) readl (&ohci
->regs
->control
);
165 mdelay (500); /* No schedule here ! */
167 switch (readl (&ohci
->regs
->control
) & OHCI_CTRL_HCFS
) {
169 ohci_dbg (ohci
, "suspend->reset ?\n");
171 case OHCI_USB_RESUME
:
172 ohci_dbg (ohci
, "suspend->resume ?\n");
175 ohci_dbg (ohci
, "suspend->operational ?\n");
177 case OHCI_USB_SUSPEND
:
178 ohci_dbg (ohci
, "suspended\n");
182 /* In some rare situations, Apple's OHCI have happily trashed
183 * memory during sleep. We disable its bus master bit during
186 pci_read_config_word (hcd
->pdev
, PCI_COMMAND
, &cmd
);
187 cmd
&= ~PCI_COMMAND_MASTER
;
188 pci_write_config_word (hcd
->pdev
, PCI_COMMAND
, cmd
);
189 #ifdef CONFIG_PMAC_PBOOK
191 struct device_node
*of_node
;
193 /* Disable USB PAD & cell clock */
194 of_node
= pci_device_to_OF_node (hcd
->pdev
);
196 pmac_call_feature(PMAC_FTR_USB_ENABLE
, of_node
, 0, 0);
203 static int ohci_pci_resume (struct usb_hcd
*hcd
)
205 struct ohci_hcd
*ohci
= hcd_to_ohci (hcd
);
210 #ifdef CONFIG_PMAC_PBOOK
212 struct device_node
*of_node
;
214 /* Re-enable USB PAD & cell clock */
215 of_node
= pci_device_to_OF_node (hcd
->pdev
);
217 pmac_call_feature (PMAC_FTR_USB_ENABLE
, of_node
, 0, 1);
220 /* did we suspend, or were we powered off? */
221 ohci
->hc_control
= readl (&ohci
->regs
->control
);
222 temp
= ohci
->hc_control
& OHCI_CTRL_HCFS
;
225 /* the registers may look crazy here */
226 ohci_dump_status (ohci
, 0, 0);
229 /* Re-enable bus mastering */
230 pci_set_master (ohci
->hcd
.pdev
);
234 case OHCI_USB_RESET
: // lost power
235 ohci_info (ohci
, "USB restart\n");
236 retval
= hc_restart (ohci
);
239 case OHCI_USB_SUSPEND
: // host wakeup
240 case OHCI_USB_RESUME
: // remote wakeup
241 ohci_info (ohci
, "USB continue from %s wakeup\n",
242 (temp
== OHCI_USB_SUSPEND
)
243 ? "host" : "remote");
244 ohci
->hc_control
= OHCI_USB_RESUME
;
245 writel (ohci
->hc_control
, &ohci
->regs
->control
);
246 (void) readl (&ohci
->regs
->control
);
247 mdelay (20); /* no schedule here ! */
248 /* Some controllers (lucent) need a longer delay here */
251 temp
= readl (&ohci
->regs
->control
);
252 temp
= ohci
->hc_control
& OHCI_CTRL_HCFS
;
253 if (temp
!= OHCI_USB_RESUME
) {
254 ohci_err (ohci
, "controller won't resume\n");
260 /* Some chips likes being resumed first */
261 writel (OHCI_USB_OPER
, &ohci
->regs
->control
);
262 (void) readl (&ohci
->regs
->control
);
265 /* Then re-enable operations */
266 spin_lock_irqsave (&ohci
->lock
, flags
);
269 ohci
->hc_control
= OHCI_CONTROL_INIT
| OHCI_USB_OPER
;
270 if (!ohci
->ed_rm_list
) {
271 if (ohci
->ed_controltail
)
272 ohci
->hc_control
|= OHCI_CTRL_CLE
;
273 if (ohci
->ed_bulktail
)
274 ohci
->hc_control
|= OHCI_CTRL_BLE
;
276 hcd
->state
= USB_STATE_READY
;
277 writel (ohci
->hc_control
, &ohci
->regs
->control
);
279 /* trigger a start-frame interrupt (why?) */
280 writel (OHCI_INTR_SF
, &ohci
->regs
->intrstatus
);
281 writel (OHCI_INTR_SF
, &ohci
->regs
->intrenable
);
283 /* Check for a pending done list */
284 writel (OHCI_INTR_WDH
, &ohci
->regs
->intrdisable
);
285 (void) readl (&ohci
->regs
->intrdisable
);
286 spin_unlock_irqrestore (&ohci
->lock
, flags
);
288 #ifdef CONFIG_PMAC_PBOOK
289 if (_machine
== _MACH_Pmac
)
290 enable_irq (hcd
->pdev
->irq
);
292 if (ohci
->hcca
->done_head
)
293 dl_done_list (ohci
, dl_reverse_done_list (ohci
), NULL
);
294 writel (OHCI_INTR_WDH
, &ohci
->regs
->intrenable
);
296 /* assume there are TDs on the bulk and control lists */
297 writel (OHCI_BLF
| OHCI_CLF
, &ohci
->regs
->cmdstatus
);
299 // ohci_dump_status (ohci);
300 ohci_dbg (ohci
, "sleeping = %d, disabled = %d\n",
301 ohci
->sleeping
, ohci
->disabled
);
305 ohci_warn (ohci
, "odd PCI resume\n");
310 #endif /* CONFIG_PM */
313 /*-------------------------------------------------------------------------*/
315 static const struct hc_driver ohci_pci_hc_driver
= {
316 .description
= hcd_name
,
319 * generic hardware linkage
322 .flags
= HCD_MEMORY
| HCD_USB11
,
325 * basic lifecycle operations
327 .start
= ohci_pci_start
,
329 .suspend
= ohci_pci_suspend
,
330 .resume
= ohci_pci_resume
,
335 * memory lifecycle (except per-request)
337 .hcd_alloc
= ohci_hcd_alloc
,
338 .hcd_free
= ohci_hcd_free
,
341 * managing i/o requests and associated device resources
343 .urb_enqueue
= ohci_urb_enqueue
,
344 .urb_dequeue
= ohci_urb_dequeue
,
345 .endpoint_disable
= ohci_endpoint_disable
,
350 .get_frame_number
= ohci_get_frame
,
355 .hub_status_data
= ohci_hub_status_data
,
356 .hub_control
= ohci_hub_control
,
359 /*-------------------------------------------------------------------------*/
361 const struct pci_device_id __devinitdata pci_ids
[] = { {
363 /* handle any USB OHCI controller */
364 .class = (PCI_CLASS_SERIAL_USB
<< 8) | 0x10,
366 .driver_data
= (unsigned long) &ohci_pci_hc_driver
,
368 /* no matter who makes it */
369 .vendor
= PCI_ANY_ID
,
370 .device
= PCI_ANY_ID
,
371 .subvendor
= PCI_ANY_ID
,
372 .subdevice
= PCI_ANY_ID
,
374 }, { /* end: all zeroes */ }
376 MODULE_DEVICE_TABLE (pci
, pci_ids
);
378 /* pci driver glue; this is a "new style" PCI driver module */
379 struct pci_driver ohci_pci_driver
= {
380 .name
= (char *) hcd_name
,
383 .probe
= usb_hcd_pci_probe
,
384 .remove
= usb_hcd_pci_remove
,
387 .suspend
= usb_hcd_pci_suspend
,
388 .resume
= usb_hcd_pci_resume
,
393 int ohci_hcd_pci_init (void)
395 printk (KERN_DEBUG
"%s: " DRIVER_INFO
" (PCI)\n", hcd_name
);
399 // causes page fault in reactos
400 //printk (KERN_DEBUG "%s: block sizes: ed %Zd td %Zd\n", hcd_name,
401 // sizeof (struct ed), sizeof (struct td));
402 return pci_module_init (&ohci_pci_driver
);
404 /*module_init (ohci_hcd_pci_init);*/
406 /*-------------------------------------------------------------------------*/
408 void ohci_hcd_pci_cleanup (void)
410 pci_unregister_driver (&ohci_pci_driver
);
412 /*module_exit (ohci_hcd_pci_cleanup);*/