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 /*-------------------------------------------------------------------------*/
34 ohci_pci_reset (struct usb_hcd *hcd)
36 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
38 ohci->regs = hcd->regs;
39 return hc_reset (ohci);
43 ohci_pci_start (struct usb_hcd *hcd)
45 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
48 ohci->hcca = dma_alloc_coherent (hcd->self.controller,
49 sizeof *ohci->hcca, &ohci->hcca_dma, 0);
53 if(hcd->self.controller && hcd->self.controller->bus == &pci_bus_type) {
54 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
56 /* AMD 756, for most chips (early revs), corrupts register
57 * values on read ... so enable the vendor workaround.
59 if (pdev->vendor == PCI_VENDOR_ID_AMD
60 && pdev->device == 0x740c) {
61 ohci->flags = OHCI_QUIRK_AMD756;
62 ohci_info (ohci, "AMD756 erratum 4 workaround\n");
65 /* FIXME for some of the early AMD 760 southbridges, OHCI
66 * won't work at all. blacklist them.
69 /* Apple's OHCI driver has a lot of bizarre workarounds
70 * for this chip. Evidently control and bulk lists
71 * can get confused. (B&W G3 models, and ...)
73 else if (pdev->vendor == PCI_VENDOR_ID_OPTI
74 && pdev->device == 0xc861) {
76 "WARNING: OPTi workarounds unavailable\n");
79 /* Check for NSC87560. We have to look at the bridge (fn1) to
80 * identify the USB (fn2). This quirk might apply to more or
83 else if (pdev->vendor == PCI_VENDOR_ID_NS) {
86 b = pci_find_slot (pdev->bus->number,
87 PCI_DEVFN (PCI_SLOT (pdev->devfn), 1));
88 if (b && b->device == PCI_DEVICE_ID_NS_87560_LIO
89 && b->vendor == PCI_VENDOR_ID_NS) {
90 ohci->flags |= OHCI_QUIRK_SUPERIO;
91 ohci_info (ohci, "Using NSC SuperIO setup\n");
97 memset (ohci->hcca, 0, sizeof (struct ohci_hcca));
98 if ((ret = ohci_mem_init (ohci)) < 0) {
103 if (hc_start (ohci) < 0) {
104 ohci_err (ohci, "can't start\n");
108 create_debug_files (ohci);
118 static int ohci_pci_suspend (struct usb_hcd *hcd, u32 state)
120 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
124 if ((ohci->hc_control & OHCI_CTRL_HCFS) != OHCI_USB_OPER) {
125 ohci_dbg (ohci, "can't suspend (state is %s)\n",
126 hcfs2string (ohci->hc_control & OHCI_CTRL_HCFS));
130 /* act as if usb suspend can always be used */
131 ohci_dbg (ohci, "suspend to %d\n", state);
133 /* First stop processing */
134 spin_lock_irq (&ohci->lock);
136 ~(OHCI_CTRL_PLE|OHCI_CTRL_CLE|OHCI_CTRL_BLE|OHCI_CTRL_IE);
137 writel (ohci->hc_control, &ohci->regs->control);
138 writel (OHCI_INTR_SF, &ohci->regs->intrstatus);
139 (void) readl (&ohci->regs->intrstatus);
140 spin_unlock_irq (&ohci->lock);
142 /* Wait a frame or two */
144 if (!readl (&ohci->regs->intrstatus) & OHCI_INTR_SF)
147 #ifdef CONFIG_PMAC_PBOOK
148 if (_machine == _MACH_Pmac)
149 disable_irq ((to_pci_dev(hcd->self.controller))->irq);
150 /* else, 2.4 assumes shared irqs -- don't disable */
153 /* Enable remote wakeup */
154 writel (readl (&ohci->regs->intrenable) | OHCI_INTR_RD,
155 &ohci->regs->intrenable);
157 /* Suspend chip and let things settle down a bit */
158 spin_lock_irq (&ohci->lock);
159 ohci->hc_control = OHCI_USB_SUSPEND;
160 writel (ohci->hc_control, &ohci->regs->control);
161 (void) readl (&ohci->regs->control);
162 spin_unlock_irq (&ohci->lock);
164 set_current_state (TASK_UNINTERRUPTIBLE);
165 schedule_timeout (HZ/2);
167 tmp = readl (&ohci->regs->control) | OHCI_CTRL_HCFS;
170 case OHCI_USB_RESUME:
172 ohci_err (ohci, "can't suspend; hcfs %d\n", tmp);
174 case OHCI_USB_SUSPEND:
175 ohci_dbg (ohci, "suspended\n");
179 /* In some rare situations, Apple's OHCI have happily trashed
180 * memory during sleep. We disable its bus master bit during
183 pci_read_config_word (to_pci_dev(hcd->self.controller), PCI_COMMAND,
185 cmd &= ~PCI_COMMAND_MASTER;
186 pci_write_config_word (to_pci_dev(hcd->self.controller), PCI_COMMAND,
188 #ifdef CONFIG_PMAC_PBOOK
190 struct device_node *of_node;
192 /* Disable USB PAD & cell clock */
193 of_node = pci_device_to_OF_node (to_pci_dev(hcd->self.controller));
195 pmac_call_feature(PMAC_FTR_USB_ENABLE, of_node, 0, 0);
202 static int ohci_pci_resume (struct usb_hcd *hcd)
204 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
208 #ifdef CONFIG_PMAC_PBOOK
210 struct device_node *of_node;
212 /* Re-enable USB PAD & cell clock */
213 of_node = pci_device_to_OF_node (to_pci_dev(hcd->self.controller));
215 pmac_call_feature (PMAC_FTR_USB_ENABLE, of_node, 0, 1);
218 /* did we suspend, or were we powered off? */
219 ohci->hc_control = readl (&ohci->regs->control);
220 temp = ohci->hc_control & OHCI_CTRL_HCFS;
223 /* the registers may look crazy here */
224 ohci_dump_status (ohci, 0, 0);
227 /* Re-enable bus mastering */
228 pci_set_master (to_pci_dev(ohci->hcd.self.controller));
232 case OHCI_USB_RESET: // lost power
234 ohci_info (ohci, "USB restart\n");
235 retval = hc_restart (ohci);
238 case OHCI_USB_SUSPEND: // host wakeup
239 case OHCI_USB_RESUME: // remote wakeup
240 ohci_info (ohci, "USB continue from %s wakeup\n",
241 (temp == OHCI_USB_SUSPEND)
242 ? "host" : "remote");
244 /* we "should" only need RESUME if we're SUSPENDed ... */
245 ohci->hc_control = OHCI_USB_RESUME;
246 writel (ohci->hc_control, &ohci->regs->control);
247 (void) readl (&ohci->regs->control);
248 /* Some controllers (lucent) need extra-long delays */
249 mdelay (35); /* no schedule 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");
255 /* maybe we can reset */
259 /* Then re-enable operations */
260 writel (OHCI_USB_OPER, &ohci->regs->control);
261 (void) readl (&ohci->regs->control);
264 spin_lock_irq (&ohci->lock);
265 ohci->hc_control = OHCI_CONTROL_INIT | OHCI_USB_OPER;
266 if (!ohci->ed_rm_list) {
267 if (ohci->ed_controltail)
268 ohci->hc_control |= OHCI_CTRL_CLE;
269 if (ohci->ed_bulktail)
270 ohci->hc_control |= OHCI_CTRL_BLE;
272 if (hcd_to_bus (&ohci->hcd)->bandwidth_isoc_reqs
273 || hcd_to_bus (&ohci->hcd)->bandwidth_int_reqs)
274 ohci->hc_control |= OHCI_CTRL_PLE|OHCI_CTRL_IE;
275 hcd->state = USB_STATE_RUNNING;
276 writel (ohci->hc_control, &ohci->regs->control);
278 /* trigger a start-frame interrupt (why?) */
279 writel (OHCI_INTR_SF, &ohci->regs->intrstatus);
280 writel (OHCI_INTR_SF, &ohci->regs->intrenable);
282 writel (OHCI_INTR_WDH, &ohci->regs->intrdisable);
283 (void) readl (&ohci->regs->intrdisable);
284 spin_unlock_irq (&ohci->lock);
286 #ifdef CONFIG_PMAC_PBOOK
287 if (_machine == _MACH_Pmac)
288 enable_irq (to_pci_dev(hcd->self.controller)->irq);
291 /* Check for a pending done list */
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);
301 ohci_warn (ohci, "odd PCI resume\n");
306 #endif /* CONFIG_PM */
309 /*-------------------------------------------------------------------------*/
311 static const struct hc_driver ohci_pci_hc_driver = {
312 .description = hcd_name,
315 * generic hardware linkage
318 .flags = HCD_MEMORY | HCD_USB11,
321 * basic lifecycle operations
323 .reset = ohci_pci_reset,
324 .start = ohci_pci_start,
326 .suspend = ohci_pci_suspend,
327 .resume = ohci_pci_resume,
332 * memory lifecycle (except per-request)
334 .hcd_alloc = ohci_hcd_alloc,
335 .hcd_free = ohci_hcd_free,
338 * managing i/o requests and associated device resources
340 .urb_enqueue = ohci_urb_enqueue,
341 .urb_dequeue = ohci_urb_dequeue,
342 .endpoint_disable = ohci_endpoint_disable,
347 .get_frame_number = ohci_get_frame,
352 .hub_status_data = ohci_hub_status_data,
353 .hub_control = ohci_hub_control,
356 /*-------------------------------------------------------------------------*/
359 static const struct pci_device_id pci_ids [] = { {
360 /* handle any USB OHCI controller */
361 PCI_DEVICE_CLASS((PCI_CLASS_SERIAL_USB << 8) | 0x10, ~0),
362 .driver_data = (unsigned long) &ohci_pci_hc_driver,
363 }, { /* end: all zeroes */ }
365 MODULE_DEVICE_TABLE (pci, pci_ids);
367 /* pci driver glue; this is a "new style" PCI driver module */
368 static struct pci_driver ohci_pci_driver = {
369 .name = (char *) hcd_name,
372 .probe = usb_hcd_pci_probe,
373 .remove = usb_hcd_pci_remove,
376 .suspend = usb_hcd_pci_suspend,
377 .resume = usb_hcd_pci_resume,
382 static int __init ohci_hcd_pci_init (void)
384 printk (KERN_DEBUG "%s: " DRIVER_INFO " (PCI)\n", hcd_name);
388 printk (KERN_DEBUG "%s: block sizes: ed %Zd td %Zd\n", hcd_name,
389 sizeof (struct ed), sizeof (struct td));
390 return pci_module_init (&ohci_pci_driver);
392 module_init (ohci_hcd_pci_init);
394 /*-------------------------------------------------------------------------*/
396 static void __exit ohci_hcd_pci_cleanup (void)
398 pci_unregister_driver (&ohci_pci_driver);
400 module_exit (ohci_hcd_pci_cleanup);