2 * EHCI HCD (Host Controller Driver) PCI Bus Glue.
4 * Copyright (c) 2000-2004 by David Brownell
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <linux/kernel.h>
22 #include <linux/module.h>
23 #include <linux/pci.h>
24 #include <linux/usb.h>
25 #include <linux/usb/hcd.h>
28 #include "pci-quirks.h"
30 #define DRIVER_DESC "EHCI PCI platform driver"
32 static const char hcd_name
[] = "ehci-pci";
34 /* defined here to avoid adding to pci_ids.h for single instance use */
35 #define PCI_DEVICE_ID_INTEL_CE4100_USB 0x2e70
37 /*-------------------------------------------------------------------------*/
39 /* called after powerup, by probe or system-pm "wakeup" */
40 static int ehci_pci_reinit(struct ehci_hcd
*ehci
, struct pci_dev
*pdev
)
44 /* we expect static quirk code to handle the "extended capabilities"
45 * (currently just BIOS handoff) allowed starting with EHCI 0.96
48 /* PCI Memory-Write-Invalidate cycle support is optional (uncommon) */
49 retval
= pci_set_mwi(pdev
);
51 ehci_dbg(ehci
, "MWI active\n");
56 /* called during probe() after chip reset completes */
57 static int ehci_pci_setup(struct usb_hcd
*hcd
)
59 struct ehci_hcd
*ehci
= hcd_to_ehci(hcd
);
60 struct pci_dev
*pdev
= to_pci_dev(hcd
->self
.controller
);
61 struct pci_dev
*p_smbus
;
66 ehci
->caps
= hcd
->regs
;
69 * ehci_init() causes memory for DMA transfers to be
70 * allocated. Thus, any vendor-specific workarounds based on
71 * limiting the type of memory used for DMA transfers must
72 * happen before ehci_setup() is called.
74 * Most other workarounds can be done either before or after
75 * init and reset; they are located here too.
77 switch (pdev
->vendor
) {
78 case PCI_VENDOR_ID_TOSHIBA_2
:
79 /* celleb's companion chip */
80 if (pdev
->device
== 0x01b5) {
81 #ifdef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO
82 ehci
->big_endian_mmio
= 1;
85 "unsupported big endian Toshiba quirk\n");
89 case PCI_VENDOR_ID_NVIDIA
:
90 /* NVidia reports that certain chips don't handle
91 * QH, ITD, or SITD addresses above 2GB. (But TD,
92 * data buffer, and periodic schedule are normal.)
94 switch (pdev
->device
) {
95 case 0x003c: /* MCP04 */
96 case 0x005b: /* CK804 */
97 case 0x00d8: /* CK8 */
98 case 0x00e8: /* CK8S */
99 if (pci_set_consistent_dma_mask(pdev
,
100 DMA_BIT_MASK(31)) < 0)
101 ehci_warn(ehci
, "can't enable NVidia "
102 "workaround for >2GB RAM\n");
105 /* Some NForce2 chips have problems with selective suspend;
106 * fixed in newer silicon.
109 if (pdev
->revision
< 0xa4)
110 ehci
->no_selective_suspend
= 1;
114 case PCI_VENDOR_ID_INTEL
:
115 if (pdev
->device
== PCI_DEVICE_ID_INTEL_CE4100_USB
)
118 case PCI_VENDOR_ID_TDI
:
119 if (pdev
->device
== PCI_DEVICE_ID_TDI_EHCI
)
122 case PCI_VENDOR_ID_AMD
:
124 if (usb_amd_find_chipset_info())
125 ehci
->amd_pll_fix
= 1;
126 /* AMD8111 EHCI doesn't work, according to AMD errata */
127 if (pdev
->device
== 0x7463) {
128 ehci_info(ehci
, "ignoring AMD8111 (errata)\n");
134 * EHCI controller on AMD SB700/SB800/Hudson-2/3 platforms may
135 * read/write memory space which does not belong to it when
136 * there is NULL pointer with T-bit set to 1 in the frame list
137 * table. To avoid the issue, the frame list link pointer
138 * should always contain a valid pointer to a inactive qh.
140 if (pdev
->device
== 0x7808) {
141 ehci
->use_dummy_qh
= 1;
142 ehci_info(ehci
, "applying AMD SB700/SB800/Hudson-2/3 EHCI dummy qh workaround\n");
145 case PCI_VENDOR_ID_VIA
:
146 if (pdev
->device
== 0x3104 && (pdev
->revision
& 0xf0) == 0x60) {
149 /* The VT6212 defaults to a 1 usec EHCI sleep time which
150 * hogs the PCI bus *badly*. Setting bit 5 of 0x4B makes
151 * that sleep time use the conventional 10 usec.
153 pci_read_config_byte(pdev
, 0x4b, &tmp
);
156 pci_write_config_byte(pdev
, 0x4b, tmp
| 0x20);
159 case PCI_VENDOR_ID_ATI
:
161 if (usb_amd_find_chipset_info())
162 ehci
->amd_pll_fix
= 1;
165 * EHCI controller on AMD SB700/SB800/Hudson-2/3 platforms may
166 * read/write memory space which does not belong to it when
167 * there is NULL pointer with T-bit set to 1 in the frame list
168 * table. To avoid the issue, the frame list link pointer
169 * should always contain a valid pointer to a inactive qh.
171 if (pdev
->device
== 0x4396) {
172 ehci
->use_dummy_qh
= 1;
173 ehci_info(ehci
, "applying AMD SB700/SB800/Hudson-2/3 EHCI dummy qh workaround\n");
175 /* SB600 and old version of SB700 have a bug in EHCI controller,
176 * which causes usb devices lose response in some cases.
178 if ((pdev
->device
== 0x4386) || (pdev
->device
== 0x4396)) {
179 p_smbus
= pci_get_device(PCI_VENDOR_ID_ATI
,
180 PCI_DEVICE_ID_ATI_SBX00_SMBUS
,
184 rev
= p_smbus
->revision
;
185 if ((pdev
->device
== 0x4386) || (rev
== 0x3a)
188 ehci_info(ehci
, "applying AMD SB600/SB700 USB "
189 "freeze workaround\n");
190 pci_read_config_byte(pdev
, 0x53, &tmp
);
191 pci_write_config_byte(pdev
, 0x53, tmp
| (1<<3));
193 pci_dev_put(p_smbus
);
196 case PCI_VENDOR_ID_NETMOS
:
197 /* MosChip frame-index-register bug */
198 ehci_info(ehci
, "applying MosChip frame-index workaround\n");
199 ehci
->frame_index_bug
= 1;
203 retval
= ehci_setup(hcd
);
207 /* These workarounds need to be applied after ehci_setup() */
208 switch (pdev
->vendor
) {
209 case PCI_VENDOR_ID_NEC
:
210 ehci
->need_io_watchdog
= 0;
212 case PCI_VENDOR_ID_INTEL
:
213 ehci
->need_io_watchdog
= 0;
215 case PCI_VENDOR_ID_NVIDIA
:
216 switch (pdev
->device
) {
217 /* MCP89 chips on the MacBookAir3,1 give EPROTO when
218 * fetching device descriptors unless LPM is disabled.
219 * There are also intermittent problems enumerating
220 * devices with PPCD enabled.
223 ehci_info(ehci
, "disable ppcd for nvidia mcp89\n");
225 ehci
->command
&= ~CMD_PPCEE
;
231 /* optional debug port, normally in the first BAR */
232 temp
= pci_find_capability(pdev
, 0x0a);
234 pci_read_config_dword(pdev
, temp
, &temp
);
236 if ((temp
& (3 << 13)) == (1 << 13)) {
238 ehci
->debug
= hcd
->regs
+ temp
;
239 temp
= ehci_readl(ehci
, &ehci
->debug
->control
);
240 ehci_info(ehci
, "debug port %d%s\n",
241 HCS_DEBUG_PORT(ehci
->hcs_params
),
242 (temp
& DBGP_ENABLED
)
245 if (!(temp
& DBGP_ENABLED
))
250 /* at least the Genesys GL880S needs fixup here */
251 temp
= HCS_N_CC(ehci
->hcs_params
) * HCS_N_PCC(ehci
->hcs_params
);
253 if (temp
&& HCS_N_PORTS(ehci
->hcs_params
) > temp
) {
254 ehci_dbg(ehci
, "bogus port configuration: "
255 "cc=%d x pcc=%d < ports=%d\n",
256 HCS_N_CC(ehci
->hcs_params
),
257 HCS_N_PCC(ehci
->hcs_params
),
258 HCS_N_PORTS(ehci
->hcs_params
));
260 switch (pdev
->vendor
) {
261 case 0x17a0: /* GENESYS */
262 /* GL880S: should be PORTS=2 */
263 temp
|= (ehci
->hcs_params
& ~0xf);
264 ehci
->hcs_params
= temp
;
266 case PCI_VENDOR_ID_NVIDIA
:
267 /* NF4: should be PCC=10 */
272 /* Serial Bus Release Number is at PCI 0x60 offset */
273 if (pdev
->vendor
== PCI_VENDOR_ID_STMICRO
274 && pdev
->device
== PCI_DEVICE_ID_STMICRO_USB_HOST
)
275 ; /* ConneXT has no sbrn register */
277 pci_read_config_byte(pdev
, 0x60, &ehci
->sbrn
);
279 /* Keep this around for a while just in case some EHCI
280 * implementation uses legacy PCI PM support. This test
281 * can be removed on 17 Dec 2009 if the dev_warn() hasn't
282 * been triggered by then.
284 if (!device_can_wakeup(&pdev
->dev
)) {
287 pci_read_config_word(pdev
, 0x62, &port_wake
);
288 if (port_wake
& 0x0001) {
289 dev_warn(&pdev
->dev
, "Enabling legacy PCI PM\n");
290 device_set_wakeup_capable(&pdev
->dev
, 1);
294 #ifdef CONFIG_USB_SUSPEND
295 /* REVISIT: the controller works fine for wakeup iff the root hub
296 * itself is "globally" suspended, but usbcore currently doesn't
297 * understand such things.
299 * System suspend currently expects to be able to suspend the entire
300 * device tree, device-at-a-time. If we failed selective suspend
301 * reports, system suspend would fail; so the root hub code must claim
302 * success. That's lying to usbcore, and it matters for runtime
303 * PM scenarios with selective suspend and remote wakeup...
305 if (ehci
->no_selective_suspend
&& device_can_wakeup(&pdev
->dev
))
306 ehci_warn(ehci
, "selective suspend/wakeup unavailable\n");
309 retval
= ehci_pci_reinit(ehci
, pdev
);
314 /*-------------------------------------------------------------------------*/
318 /* suspend/resume, section 4.3 */
320 /* These routines rely on the PCI bus glue
321 * to handle powerdown and wakeup, and currently also on
322 * transceivers that don't need any software attention to set up
323 * the right sort of wakeup.
324 * Also they depend on separate root hub suspend/resume.
327 static bool usb_is_intel_switchable_ehci(struct pci_dev
*pdev
)
329 return pdev
->class == PCI_CLASS_SERIAL_USB_EHCI
&&
330 pdev
->vendor
== PCI_VENDOR_ID_INTEL
&&
331 (pdev
->device
== 0x1E26 ||
332 pdev
->device
== 0x8C2D ||
333 pdev
->device
== 0x8C26 ||
334 pdev
->device
== 0x9C26);
337 static void ehci_enable_xhci_companion(void)
339 struct pci_dev
*companion
= NULL
;
341 /* The xHCI and EHCI controllers are not on the same PCI slot */
342 for_each_pci_dev(companion
) {
343 if (!usb_is_intel_switchable_xhci(companion
))
345 usb_enable_xhci_ports(companion
);
350 static int ehci_pci_resume(struct usb_hcd
*hcd
, bool hibernated
)
352 struct ehci_hcd
*ehci
= hcd_to_ehci(hcd
);
353 struct pci_dev
*pdev
= to_pci_dev(hcd
->self
.controller
);
355 /* The BIOS on systems with the Intel Panther Point chipset may or may
356 * not support xHCI natively. That means that during system resume, it
357 * may switch the ports back to EHCI so that users can use their
358 * keyboard to select a kernel from GRUB after resume from hibernate.
360 * The BIOS is supposed to remember whether the OS had xHCI ports
361 * enabled before resume, and switch the ports back to xHCI when the
362 * BIOS/OS semaphore is written, but we all know we can't trust BIOS
365 * Unconditionally switch the ports back to xHCI after a system resume.
366 * We can't tell whether the EHCI or xHCI controller will be resumed
367 * first, so we have to do the port switchover in both drivers. Writing
368 * a '1' to the port switchover registers should have no effect if the
369 * port was already switched over.
371 if (usb_is_intel_switchable_ehci(pdev
))
372 ehci_enable_xhci_companion();
374 if (ehci_resume(hcd
, hibernated
) != 0)
375 (void) ehci_pci_reinit(ehci
, pdev
);
381 #define ehci_suspend NULL
382 #define ehci_pci_resume NULL
383 #endif /* CONFIG_PM */
385 static struct hc_driver __read_mostly ehci_pci_hc_driver
;
387 static const struct ehci_driver_overrides pci_overrides __initdata
= {
388 .reset
= ehci_pci_setup
,
391 /*-------------------------------------------------------------------------*/
393 /* PCI driver selection metadata; PCI hotplugging uses this */
394 static const struct pci_device_id pci_ids
[] = { {
395 /* handle any USB 2.0 EHCI controller */
396 PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_EHCI
, ~0),
397 .driver_data
= (unsigned long) &ehci_pci_hc_driver
,
399 PCI_VDEVICE(STMICRO
, PCI_DEVICE_ID_STMICRO_USB_HOST
),
400 .driver_data
= (unsigned long) &ehci_pci_hc_driver
,
402 { /* end: all zeroes */ }
404 MODULE_DEVICE_TABLE(pci
, pci_ids
);
406 /* pci driver glue; this is a "new style" PCI driver module */
407 static struct pci_driver ehci_pci_driver
= {
408 .name
= (char *) hcd_name
,
411 .probe
= usb_hcd_pci_probe
,
412 .remove
= usb_hcd_pci_remove
,
413 .shutdown
= usb_hcd_pci_shutdown
,
415 #ifdef CONFIG_PM_SLEEP
417 .pm
= &usb_hcd_pci_pm_ops
422 static int __init
ehci_pci_init(void)
427 pr_info("%s: " DRIVER_DESC
"\n", hcd_name
);
429 ehci_init_driver(&ehci_pci_hc_driver
, &pci_overrides
);
431 /* Entries for the PCI suspend/resume callbacks are special */
432 ehci_pci_hc_driver
.pci_suspend
= ehci_suspend
;
433 ehci_pci_hc_driver
.pci_resume
= ehci_pci_resume
;
435 return pci_register_driver(&ehci_pci_driver
);
437 module_init(ehci_pci_init
);
439 static void __exit
ehci_pci_cleanup(void)
441 pci_unregister_driver(&ehci_pci_driver
);
443 module_exit(ehci_pci_cleanup
);
445 MODULE_DESCRIPTION(DRIVER_DESC
);
446 MODULE_AUTHOR("David Brownell");
447 MODULE_AUTHOR("Alan Stern");
448 MODULE_LICENSE("GPL");