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.
18 #error "This file is PCI bus glue. CONFIG_PCI must be defined."
21 #include <linux/pci.h>
25 /* constants used to work around PM-related transfer
26 * glitches in some AMD 700 series southbridges
28 #define AB_REG_BAR 0xf0
29 #define AB_INDX(addr) ((addr) + 0x00)
30 #define AB_DATA(addr) ((addr) + 0x04)
34 #define NB_PCIE_INDX_ADDR 0xe0
35 #define NB_PCIE_INDX_DATA 0xe4
36 #define PCIE_P_CNTL 0x10040
37 #define BIF_NB 0x10002
39 static struct pci_dev
*amd_smbus_dev
;
40 static struct pci_dev
*amd_hb_dev
;
41 static int amd_ohci_iso_count
;
43 /*-------------------------------------------------------------------------*/
45 static int broken_suspend(struct usb_hcd
*hcd
)
47 device_init_wakeup(&hcd
->self
.root_hub
->dev
, 0);
51 /* AMD 756, for most chips (early revs), corrupts register
52 * values on read ... so enable the vendor workaround.
54 static int ohci_quirk_amd756(struct usb_hcd
*hcd
)
56 struct ohci_hcd
*ohci
= hcd_to_ohci (hcd
);
58 ohci
->flags
= OHCI_QUIRK_AMD756
;
59 ohci_dbg (ohci
, "AMD756 erratum 4 workaround\n");
61 /* also erratum 10 (suspend/resume issues) */
62 return broken_suspend(hcd
);
65 /* Apple's OHCI driver has a lot of bizarre workarounds
66 * for this chip. Evidently control and bulk lists
67 * can get confused. (B&W G3 models, and ...)
69 static int ohci_quirk_opti(struct usb_hcd
*hcd
)
71 struct ohci_hcd
*ohci
= hcd_to_ohci (hcd
);
73 ohci_dbg (ohci
, "WARNING: OPTi workarounds unavailable\n");
78 /* Check for NSC87560. We have to look at the bridge (fn1) to
79 * identify the USB (fn2). This quirk might apply to more or
82 static int ohci_quirk_ns(struct usb_hcd
*hcd
)
84 struct pci_dev
*pdev
= to_pci_dev(hcd
->self
.controller
);
87 b
= pci_get_slot (pdev
->bus
, 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 struct ohci_hcd
*ohci
= hcd_to_ohci (hcd
);
92 ohci
->flags
|= OHCI_QUIRK_SUPERIO
;
93 ohci_dbg (ohci
, "Using NSC SuperIO setup\n");
100 /* Check for Compaq's ZFMicro chipset, which needs short
101 * delays before control or bulk queues get re-activated
102 * in finish_unlinks()
104 static int ohci_quirk_zfmicro(struct usb_hcd
*hcd
)
106 struct ohci_hcd
*ohci
= hcd_to_ohci (hcd
);
108 ohci
->flags
|= OHCI_QUIRK_ZFMICRO
;
109 ohci_dbg(ohci
, "enabled Compaq ZFMicro chipset quirks\n");
114 /* Check for Toshiba SCC OHCI which has big endian registers
115 * and little endian in memory data structures
117 static int ohci_quirk_toshiba_scc(struct usb_hcd
*hcd
)
119 struct ohci_hcd
*ohci
= hcd_to_ohci (hcd
);
121 /* That chip is only present in the southbridge of some
122 * cell based platforms which are supposed to select
123 * CONFIG_USB_OHCI_BIG_ENDIAN_MMIO. We verify here if
124 * that was the case though.
126 #ifdef CONFIG_USB_OHCI_BIG_ENDIAN_MMIO
127 ohci
->flags
|= OHCI_QUIRK_BE_MMIO
;
128 ohci_dbg (ohci
, "enabled big endian Toshiba quirk\n");
131 ohci_err (ohci
, "unsupported big endian Toshiba quirk\n");
136 /* Check for NEC chip and apply quirk for allegedly lost interrupts.
139 static void ohci_quirk_nec_worker(struct work_struct
*work
)
141 struct ohci_hcd
*ohci
= container_of(work
, struct ohci_hcd
, nec_work
);
144 status
= ohci_init(ohci
);
146 ohci_err(ohci
, "Restarting NEC controller failed in %s, %d\n",
147 "ohci_init", status
);
151 status
= ohci_restart(ohci
);
153 ohci_err(ohci
, "Restarting NEC controller failed in %s, %d\n",
154 "ohci_restart", status
);
157 static int ohci_quirk_nec(struct usb_hcd
*hcd
)
159 struct ohci_hcd
*ohci
= hcd_to_ohci (hcd
);
161 ohci
->flags
|= OHCI_QUIRK_NEC
;
162 INIT_WORK(&ohci
->nec_work
, ohci_quirk_nec_worker
);
163 ohci_dbg (ohci
, "enabled NEC chipset lost interrupt quirk\n");
168 static int ohci_quirk_amd700(struct usb_hcd
*hcd
)
170 struct ohci_hcd
*ohci
= hcd_to_ohci(hcd
);
174 amd_smbus_dev
= pci_get_device(PCI_VENDOR_ID_ATI
,
175 PCI_DEVICE_ID_ATI_SBX00_SMBUS
, NULL
);
179 pci_read_config_byte(amd_smbus_dev
, PCI_REVISION_ID
, &rev
);
181 /* SB800 needs pre-fetch fix */
182 if ((rev
>= 0x40) && (rev
<= 0x4f)) {
183 ohci
->flags
|= OHCI_QUIRK_AMD_PREFETCH
;
184 ohci_dbg(ohci
, "enabled AMD prefetch quirk\n");
187 if ((rev
> 0x3b) || (rev
< 0x30)) {
188 pci_dev_put(amd_smbus_dev
);
189 amd_smbus_dev
= NULL
;
193 amd_ohci_iso_count
++;
196 amd_hb_dev
= pci_get_device(PCI_VENDOR_ID_AMD
, 0x9600, NULL
);
198 ohci
->flags
|= OHCI_QUIRK_AMD_ISO
;
199 ohci_dbg(ohci
, "enabled AMD ISO transfers quirk\n");
204 /* nVidia controllers continue to drive Reset signalling on the bus
205 * even after system shutdown, wasting power. This flag tells the
206 * shutdown routine to leave the controller OPERATIONAL instead of RESET.
208 static int ohci_quirk_nvidia_shutdown(struct usb_hcd
*hcd
)
210 struct pci_dev
*pdev
= to_pci_dev(hcd
->self
.controller
);
211 struct ohci_hcd
*ohci
= hcd_to_ohci(hcd
);
213 /* Evidently nVidia fixed their later hardware; this is a guess at
214 * the changeover point.
216 #define PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_USB 0x026d
218 if (pdev
->device
< PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_USB
) {
219 ohci
->flags
|= OHCI_QUIRK_SHUTDOWN
;
220 ohci_dbg(ohci
, "enabled nVidia shutdown quirk\n");
227 * The hardware normally enables the A-link power management feature, which
228 * lets the system lower the power consumption in idle states.
230 * Assume the system is configured to have USB 1.1 ISO transfers going
231 * to or from a USB device. Without this quirk, that stream may stutter
232 * or have breaks occasionally. For transfers going to speakers, this
233 * makes a very audible mess...
235 * That audio playback corruption is due to the audio stream getting
236 * interrupted occasionally when the link goes in lower power state
237 * This USB quirk prevents the link going into that lower power state
238 * during audio playback or other ISO operations.
240 static void quirk_amd_pll(int on
)
244 u32 bit
= (on
> 0) ? 1 : 0;
246 pci_read_config_dword(amd_smbus_dev
, AB_REG_BAR
, &addr
);
248 /* BIT names/meanings are NDA-protected, sorry ... */
250 outl(AX_INDXC
, AB_INDX(addr
));
251 outl(0x40, AB_DATA(addr
));
252 outl(AX_DATAC
, AB_INDX(addr
));
253 val
= inl(AB_DATA(addr
));
254 val
&= ~((1 << 3) | (1 << 4) | (1 << 9));
255 val
|= (bit
<< 3) | ((!bit
) << 4) | ((!bit
) << 9);
256 outl(val
, AB_DATA(addr
));
260 pci_write_config_dword(amd_hb_dev
, NB_PCIE_INDX_ADDR
, addr
);
262 pci_read_config_dword(amd_hb_dev
, NB_PCIE_INDX_DATA
, &val
);
263 val
&= ~(1 | (1 << 3) | (1 << 4) | (1 << 9) | (1 << 12));
264 val
|= bit
| (bit
<< 3) | (bit
<< 12);
265 val
|= ((!bit
) << 4) | ((!bit
) << 9);
266 pci_write_config_dword(amd_hb_dev
, NB_PCIE_INDX_DATA
, val
);
269 pci_write_config_dword(amd_hb_dev
, NB_PCIE_INDX_ADDR
, addr
);
271 pci_read_config_dword(amd_hb_dev
, NB_PCIE_INDX_DATA
, &val
);
274 pci_write_config_dword(amd_hb_dev
, NB_PCIE_INDX_DATA
, val
);
278 static void amd_iso_dev_put(void)
280 amd_ohci_iso_count
--;
281 if (amd_ohci_iso_count
== 0) {
283 pci_dev_put(amd_smbus_dev
);
284 amd_smbus_dev
= NULL
;
287 pci_dev_put(amd_hb_dev
);
294 static void sb800_prefetch(struct ohci_hcd
*ohci
, int on
)
296 struct pci_dev
*pdev
;
299 pdev
= to_pci_dev(ohci_to_hcd(ohci
)->self
.controller
);
300 pci_read_config_word(pdev
, 0x50, &misc
);
302 pci_write_config_word(pdev
, 0x50, misc
& 0xfcff);
304 pci_write_config_word(pdev
, 0x50, misc
| 0x0300);
307 /* List of quirks for OHCI */
308 static const struct pci_device_id ohci_pci_quirks
[] = {
310 PCI_DEVICE(PCI_VENDOR_ID_AMD
, 0x740c),
311 .driver_data
= (unsigned long)ohci_quirk_amd756
,
314 PCI_DEVICE(PCI_VENDOR_ID_OPTI
, 0xc861),
315 .driver_data
= (unsigned long)ohci_quirk_opti
,
318 PCI_DEVICE(PCI_VENDOR_ID_NS
, PCI_ANY_ID
),
319 .driver_data
= (unsigned long)ohci_quirk_ns
,
322 PCI_DEVICE(PCI_VENDOR_ID_COMPAQ
, 0xa0f8),
323 .driver_data
= (unsigned long)ohci_quirk_zfmicro
,
326 PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA_2
, 0x01b6),
327 .driver_data
= (unsigned long)ohci_quirk_toshiba_scc
,
330 PCI_DEVICE(PCI_VENDOR_ID_NEC
, PCI_DEVICE_ID_NEC_USB
),
331 .driver_data
= (unsigned long)ohci_quirk_nec
,
334 /* Toshiba portege 4000 */
335 .vendor
= PCI_VENDOR_ID_AL
,
337 .subvendor
= PCI_VENDOR_ID_TOSHIBA
,
339 .driver_data
= (unsigned long) broken_suspend
,
342 PCI_DEVICE(PCI_VENDOR_ID_ITE
, 0x8152),
343 .driver_data
= (unsigned long) broken_suspend
,
346 PCI_DEVICE(PCI_VENDOR_ID_ATI
, 0x4397),
347 .driver_data
= (unsigned long)ohci_quirk_amd700
,
350 PCI_DEVICE(PCI_VENDOR_ID_ATI
, 0x4398),
351 .driver_data
= (unsigned long)ohci_quirk_amd700
,
354 PCI_DEVICE(PCI_VENDOR_ID_ATI
, 0x4399),
355 .driver_data
= (unsigned long)ohci_quirk_amd700
,
358 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA
, PCI_ANY_ID
),
359 .driver_data
= (unsigned long) ohci_quirk_nvidia_shutdown
,
362 /* FIXME for some of the early AMD 760 southbridges, OHCI
363 * won't work at all. blacklist them.
369 static int ohci_pci_reset (struct usb_hcd
*hcd
)
371 struct ohci_hcd
*ohci
= hcd_to_ohci (hcd
);
374 if (hcd
->self
.controller
) {
375 struct pci_dev
*pdev
= to_pci_dev(hcd
->self
.controller
);
376 const struct pci_device_id
*quirk_id
;
378 quirk_id
= pci_match_id(ohci_pci_quirks
, pdev
);
379 if (quirk_id
!= NULL
) {
380 int (*quirk
)(struct usb_hcd
*ohci
);
381 quirk
= (void *)quirk_id
->driver_data
;
386 ohci_hcd_init (ohci
);
387 return ohci_init (ohci
);
393 static int __devinit
ohci_pci_start (struct usb_hcd
*hcd
)
395 struct ohci_hcd
*ohci
= hcd_to_ohci (hcd
);
398 #ifdef CONFIG_PM /* avoid warnings about unused pdev */
399 if (hcd
->self
.controller
) {
400 struct pci_dev
*pdev
= to_pci_dev(hcd
->self
.controller
);
402 /* RWC may not be set for add-in PCI cards, since boot
403 * firmware probably ignored them. This transfers PCI
404 * PM wakeup capabilities.
406 if (device_can_wakeup(&pdev
->dev
))
407 ohci
->hc_control
|= OHCI_CTRL_RWC
;
409 #endif /* CONFIG_PM */
411 ret
= ohci_run (ohci
);
413 ohci_err (ohci
, "can't start\n");
421 static int ohci_pci_suspend(struct usb_hcd
*hcd
)
423 struct ohci_hcd
*ohci
= hcd_to_ohci (hcd
);
427 /* Root hub was already suspended. Disable irq emission and
428 * mark HW unaccessible, bail out if RH has been resumed. Use
429 * the spinlock to properly synchronize with possible pending
430 * RH suspend or resume activity.
432 * This is still racy as hcd->state is manipulated outside of
433 * any locks =P But that will be a different fix.
435 spin_lock_irqsave (&ohci
->lock
, flags
);
436 if (hcd
->state
!= HC_STATE_SUSPENDED
) {
440 ohci_writel(ohci
, OHCI_INTR_MIE
, &ohci
->regs
->intrdisable
);
441 (void)ohci_readl(ohci
, &ohci
->regs
->intrdisable
);
443 clear_bit(HCD_FLAG_HW_ACCESSIBLE
, &hcd
->flags
);
445 spin_unlock_irqrestore (&ohci
->lock
, flags
);
451 static int ohci_pci_resume(struct usb_hcd
*hcd
, bool hibernated
)
453 set_bit(HCD_FLAG_HW_ACCESSIBLE
, &hcd
->flags
);
455 /* Make sure resume from hibernation re-enumerates everything */
457 ohci_usb_reset(hcd_to_ohci(hcd
));
459 ohci_finish_controller_resume(hcd
);
463 #endif /* CONFIG_PM */
466 /*-------------------------------------------------------------------------*/
468 static const struct hc_driver ohci_pci_hc_driver
= {
469 .description
= hcd_name
,
470 .product_desc
= "OHCI Host Controller",
471 .hcd_priv_size
= sizeof(struct ohci_hcd
),
474 * generic hardware linkage
477 .flags
= HCD_MEMORY
| HCD_USB11
,
480 * basic lifecycle operations
482 .reset
= ohci_pci_reset
,
483 .start
= ohci_pci_start
,
485 .shutdown
= ohci_shutdown
,
488 .pci_suspend
= ohci_pci_suspend
,
489 .pci_resume
= ohci_pci_resume
,
493 * managing i/o requests and associated device resources
495 .urb_enqueue
= ohci_urb_enqueue
,
496 .urb_dequeue
= ohci_urb_dequeue
,
497 .endpoint_disable
= ohci_endpoint_disable
,
502 .get_frame_number
= ohci_get_frame
,
507 .hub_status_data
= ohci_hub_status_data
,
508 .hub_control
= ohci_hub_control
,
510 .bus_suspend
= ohci_bus_suspend
,
511 .bus_resume
= ohci_bus_resume
,
513 .start_port_reset
= ohci_start_port_reset
,
516 /*-------------------------------------------------------------------------*/
519 static const struct pci_device_id pci_ids
[] = { {
520 /* handle any USB OHCI controller */
521 PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_OHCI
, ~0),
522 .driver_data
= (unsigned long) &ohci_pci_hc_driver
,
523 }, { /* end: all zeroes */ }
525 MODULE_DEVICE_TABLE (pci
, pci_ids
);
527 /* pci driver glue; this is a "new style" PCI driver module */
528 static struct pci_driver ohci_pci_driver
= {
529 .name
= (char *) hcd_name
,
532 .probe
= usb_hcd_pci_probe
,
533 .remove
= usb_hcd_pci_remove
,
534 .shutdown
= usb_hcd_pci_shutdown
,
536 #ifdef CONFIG_PM_SLEEP
538 .pm
= &usb_hcd_pci_pm_ops