blob: ec337c2bd5e0b5294efa467691ef1807742aa1bc [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * OHCI HCD (Host Controller Driver) for USB.
3 *
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
David Brownelldd9048a2006-12-05 03:18:31 -08006 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * [ 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]
David Brownelldd9048a2006-12-05 03:18:31 -080011 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * PCI Bus Glue
13 *
14 * This file is licenced under the GPL.
15 */
David Brownelldd9048a2006-12-05 03:18:31 -080016
Libin Yangab1666c2008-08-08 15:03:31 +080017#include <linux/io.h>
Manjunath Goudarc1117af2013-05-28 18:34:51 +053018#include <linux/kernel.h>
19#include <linux/module.h>
20#include <linux/pci.h>
21#include <linux/usb.h>
22#include <linux/usb/hcd.h>
23
24#include "ohci.h"
25#include "pci-quirks.h"
26
27#define DRIVER_DESC "OHCI PCI platform driver"
28
29static const char hcd_name[] = "ohci-pci";
Libin Yangab1666c2008-08-08 15:03:31 +080030
31
Linus Torvalds1da177e2005-04-16 15:20:36 -070032/*-------------------------------------------------------------------------*/
33
David Brownell931384f2007-04-17 13:06:29 -070034static int broken_suspend(struct usb_hcd *hcd)
35{
36 device_init_wakeup(&hcd->self.root_hub->dev, 0);
37 return 0;
38}
39
Benjamin Herrenschmidt4302a5952006-12-15 06:53:55 +110040/* AMD 756, for most chips (early revs), corrupts register
41 * values on read ... so enable the vendor workaround.
42 */
David Brownell931384f2007-04-17 13:06:29 -070043static int ohci_quirk_amd756(struct usb_hcd *hcd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070044{
45 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
46
Benjamin Herrenschmidt4302a5952006-12-15 06:53:55 +110047 ohci->flags = OHCI_QUIRK_AMD756;
48 ohci_dbg (ohci, "AMD756 erratum 4 workaround\n");
49
50 /* also erratum 10 (suspend/resume issues) */
David Brownell931384f2007-04-17 13:06:29 -070051 return broken_suspend(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052}
53
Benjamin Herrenschmidt4302a5952006-12-15 06:53:55 +110054/* Apple's OHCI driver has a lot of bizarre workarounds
55 * for this chip. Evidently control and bulk lists
56 * can get confused. (B&W G3 models, and ...)
57 */
David Brownell931384f2007-04-17 13:06:29 -070058static int ohci_quirk_opti(struct usb_hcd *hcd)
Benjamin Herrenschmidt4302a5952006-12-15 06:53:55 +110059{
60 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
61
62 ohci_dbg (ohci, "WARNING: OPTi workarounds unavailable\n");
63
64 return 0;
65}
66
67/* Check for NSC87560. We have to look at the bridge (fn1) to
68 * identify the USB (fn2). This quirk might apply to more or
69 * even all NSC stuff.
70 */
David Brownell931384f2007-04-17 13:06:29 -070071static int ohci_quirk_ns(struct usb_hcd *hcd)
Benjamin Herrenschmidt4302a5952006-12-15 06:53:55 +110072{
73 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
74 struct pci_dev *b;
75
76 b = pci_get_slot (pdev->bus, PCI_DEVFN (PCI_SLOT (pdev->devfn), 1));
77 if (b && b->device == PCI_DEVICE_ID_NS_87560_LIO
78 && b->vendor == PCI_VENDOR_ID_NS) {
79 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
80
81 ohci->flags |= OHCI_QUIRK_SUPERIO;
82 ohci_dbg (ohci, "Using NSC SuperIO setup\n");
83 }
84 pci_dev_put(b);
85
86 return 0;
87}
88
89/* Check for Compaq's ZFMicro chipset, which needs short
90 * delays before control or bulk queues get re-activated
91 * in finish_unlinks()
92 */
David Brownell931384f2007-04-17 13:06:29 -070093static int ohci_quirk_zfmicro(struct usb_hcd *hcd)
Benjamin Herrenschmidt4302a5952006-12-15 06:53:55 +110094{
95 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
96
97 ohci->flags |= OHCI_QUIRK_ZFMICRO;
Mike Nuss89a0fd12007-08-01 13:24:30 -070098 ohci_dbg(ohci, "enabled Compaq ZFMicro chipset quirks\n");
Benjamin Herrenschmidt4302a5952006-12-15 06:53:55 +110099
100 return 0;
101}
102
Benjamin Herrenschmidt11d1a4a2006-12-15 06:54:03 +1100103/* Check for Toshiba SCC OHCI which has big endian registers
104 * and little endian in memory data structures
105 */
David Brownell931384f2007-04-17 13:06:29 -0700106static int ohci_quirk_toshiba_scc(struct usb_hcd *hcd)
Benjamin Herrenschmidt11d1a4a2006-12-15 06:54:03 +1100107{
108 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
109
110 /* That chip is only present in the southbridge of some
111 * cell based platforms which are supposed to select
112 * CONFIG_USB_OHCI_BIG_ENDIAN_MMIO. We verify here if
113 * that was the case though.
114 */
115#ifdef CONFIG_USB_OHCI_BIG_ENDIAN_MMIO
116 ohci->flags |= OHCI_QUIRK_BE_MMIO;
117 ohci_dbg (ohci, "enabled big endian Toshiba quirk\n");
118 return 0;
119#else
120 ohci_err (ohci, "unsupported big endian Toshiba quirk\n");
121 return -ENXIO;
122#endif
123}
Benjamin Herrenschmidt4302a5952006-12-15 06:53:55 +1100124
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200125/* Check for NEC chip and apply quirk for allegedly lost interrupts.
126 */
Mike Nuss89a0fd12007-08-01 13:24:30 -0700127
128static void ohci_quirk_nec_worker(struct work_struct *work)
129{
130 struct ohci_hcd *ohci = container_of(work, struct ohci_hcd, nec_work);
131 int status;
132
Mike Nuss89a0fd12007-08-01 13:24:30 -0700133 status = ohci_restart(ohci);
134 if (status != 0)
135 ohci_err(ohci, "Restarting NEC controller failed in %s, %d\n",
136 "ohci_restart", status);
137}
138
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200139static int ohci_quirk_nec(struct usb_hcd *hcd)
140{
141 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
142
143 ohci->flags |= OHCI_QUIRK_NEC;
Mike Nuss89a0fd12007-08-01 13:24:30 -0700144 INIT_WORK(&ohci->nec_work, ohci_quirk_nec_worker);
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200145 ohci_dbg (ohci, "enabled NEC chipset lost interrupt quirk\n");
146
147 return 0;
148}
149
Libin Yangab1666c2008-08-08 15:03:31 +0800150static int ohci_quirk_amd700(struct usb_hcd *hcd)
151{
152 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
Andiry Xuad935622011-03-01 14:57:05 +0800153 struct pci_dev *amd_smbus_dev;
Sergei Shtylyovfa417c32011-03-03 21:10:05 +0300154 u8 rev;
Libin Yangab1666c2008-08-08 15:03:31 +0800155
Andiry Xuad935622011-03-01 14:57:05 +0800156 if (usb_amd_find_chipset_info())
157 ohci->flags |= OHCI_QUIRK_AMD_PLL;
158
159 amd_smbus_dev = pci_get_device(PCI_VENDOR_ID_ATI,
160 PCI_DEVICE_ID_ATI_SBX00_SMBUS, NULL);
Libin Yangab1666c2008-08-08 15:03:31 +0800161 if (!amd_smbus_dev)
162 return 0;
163
Sergei Shtylyovfa417c32011-03-03 21:10:05 +0300164 rev = amd_smbus_dev->revision;
Libin Yanga1f17a872009-11-04 14:55:18 +0800165
166 /* SB800 needs pre-fetch fix */
167 if ((rev >= 0x40) && (rev <= 0x4f)) {
168 ohci->flags |= OHCI_QUIRK_AMD_PREFETCH;
169 ohci_dbg(ohci, "enabled AMD prefetch quirk\n");
170 }
171
Andiry Xuad935622011-03-01 14:57:05 +0800172 pci_dev_put(amd_smbus_dev);
173 amd_smbus_dev = NULL;
Libin Yangab1666c2008-08-08 15:03:31 +0800174
175 return 0;
176}
177
Benjamin Herrenschmidt4302a5952006-12-15 06:53:55 +1100178/* List of quirks for OHCI */
179static const struct pci_device_id ohci_pci_quirks[] = {
180 {
181 PCI_DEVICE(PCI_VENDOR_ID_AMD, 0x740c),
182 .driver_data = (unsigned long)ohci_quirk_amd756,
183 },
184 {
185 PCI_DEVICE(PCI_VENDOR_ID_OPTI, 0xc861),
186 .driver_data = (unsigned long)ohci_quirk_opti,
187 },
188 {
189 PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_ANY_ID),
190 .driver_data = (unsigned long)ohci_quirk_ns,
191 },
192 {
193 PCI_DEVICE(PCI_VENDOR_ID_COMPAQ, 0xa0f8),
194 .driver_data = (unsigned long)ohci_quirk_zfmicro,
195 },
Benjamin Herrenschmidt11d1a4a2006-12-15 06:54:03 +1100196 {
197 PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA_2, 0x01b6),
198 .driver_data = (unsigned long)ohci_quirk_toshiba_scc,
199 },
David Brownell931384f2007-04-17 13:06:29 -0700200 {
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200201 PCI_DEVICE(PCI_VENDOR_ID_NEC, PCI_DEVICE_ID_NEC_USB),
202 .driver_data = (unsigned long)ohci_quirk_nec,
203 },
204 {
David Brownell931384f2007-04-17 13:06:29 -0700205 /* Toshiba portege 4000 */
206 .vendor = PCI_VENDOR_ID_AL,
207 .device = 0x5237,
Andrey Borzenkov8ab5e8c2007-05-19 14:23:28 -0700208 .subvendor = PCI_VENDOR_ID_TOSHIBA,
David Brownell931384f2007-04-17 13:06:29 -0700209 .subdevice = 0x0004,
210 .driver_data = (unsigned long) broken_suspend,
211 },
Raphael Assenat33f73e52007-04-17 13:09:18 -0700212 {
213 PCI_DEVICE(PCI_VENDOR_ID_ITE, 0x8152),
214 .driver_data = (unsigned long) broken_suspend,
215 },
Libin Yangab1666c2008-08-08 15:03:31 +0800216 {
217 PCI_DEVICE(PCI_VENDOR_ID_ATI, 0x4397),
218 .driver_data = (unsigned long)ohci_quirk_amd700,
219 },
220 {
221 PCI_DEVICE(PCI_VENDOR_ID_ATI, 0x4398),
222 .driver_data = (unsigned long)ohci_quirk_amd700,
223 },
224 {
225 PCI_DEVICE(PCI_VENDOR_ID_ATI, 0x4399),
226 .driver_data = (unsigned long)ohci_quirk_amd700,
227 },
228
Benjamin Herrenschmidt4302a5952006-12-15 06:53:55 +1100229 /* FIXME for some of the early AMD 760 southbridges, OHCI
230 * won't work at all. blacklist them.
231 */
Benjamin Herrenschmidt11d1a4a2006-12-15 06:54:03 +1100232
Benjamin Herrenschmidt4302a5952006-12-15 06:53:55 +1100233 {},
234};
235
236static int ohci_pci_reset (struct usb_hcd *hcd)
237{
238 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
Manjunath Goudarc1117af2013-05-28 18:34:51 +0530239 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
Benjamin Herrenschmidt4302a5952006-12-15 06:53:55 +1100240 int ret = 0;
241
242 if (hcd->self.controller) {
Benjamin Herrenschmidt4302a5952006-12-15 06:53:55 +1100243 const struct pci_device_id *quirk_id;
244
245 quirk_id = pci_match_id(ohci_pci_quirks, pdev);
246 if (quirk_id != NULL) {
247 int (*quirk)(struct usb_hcd *ohci);
248 quirk = (void *)quirk_id->driver_data;
249 ret = quirk(hcd);
250 }
251 }
Manjunath Goudarc1117af2013-05-28 18:34:51 +0530252
253 if (ret == 0)
254 ret = ohci_setup(hcd);
255 /*
256 * After ohci setup RWC may not be set for add-in PCI cards.
257 * This transfers PCI PM wakeup capabilities.
258 */
259 if (device_can_wakeup(&pdev->dev))
260 ohci->hc_control |= OHCI_CTRL_RWC;
Benjamin Herrenschmidt4302a5952006-12-15 06:53:55 +1100261 return ret;
262}
263
Manjunath Goudarc1117af2013-05-28 18:34:51 +0530264static struct hc_driver __read_mostly ohci_pci_hc_driver;
Benjamin Herrenschmidt4302a5952006-12-15 06:53:55 +1100265
Manjunath Goudarc1117af2013-05-28 18:34:51 +0530266static const struct ohci_driver_overrides pci_overrides __initconst = {
267 .product_desc = "OHCI PCI host controller",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 .reset = ohci_pci_reset,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269};
270
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271static const struct pci_device_id pci_ids [] = { {
272 /* handle any USB OHCI controller */
Jean Delvarec67808e2006-04-09 20:07:35 +0200273 PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_OHCI, ~0),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 .driver_data = (unsigned long) &ohci_pci_hc_driver,
Alessandro Rubini3a0bac02012-01-06 13:33:28 +0100275 }, {
276 /* The device in the ConneXT I/O hub has no class reg */
277 PCI_VDEVICE(STMICRO, PCI_DEVICE_ID_STMICRO_USB_OHCI),
278 .driver_data = (unsigned long) &ohci_pci_hc_driver,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 }, { /* end: all zeroes */ }
280};
281MODULE_DEVICE_TABLE (pci, pci_ids);
282
283/* pci driver glue; this is a "new style" PCI driver module */
284static struct pci_driver ohci_pci_driver = {
285 .name = (char *) hcd_name,
286 .id_table = pci_ids,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
288 .probe = usb_hcd_pci_probe,
289 .remove = usb_hcd_pci_remove,
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700290 .shutdown = usb_hcd_pci_shutdown,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
Alan Stern69820e02013-08-26 15:01:40 -0400292#ifdef CONFIG_PM
Alan Sternabb30642009-04-27 13:33:24 -0400293 .driver = {
294 .pm = &usb_hcd_pci_pm_ops
295 },
296#endif
297};
Manjunath Goudarc1117af2013-05-28 18:34:51 +0530298
299static int __init ohci_pci_init(void)
300{
301 if (usb_disabled())
302 return -ENODEV;
303
304 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
305
306 ohci_init_driver(&ohci_pci_hc_driver, &pci_overrides);
Alan Stern9a118992013-08-21 10:33:17 -0400307
Alan Sternd3474042013-08-26 10:53:53 -0400308#ifdef CONFIG_PM
Alan Stern9a118992013-08-21 10:33:17 -0400309 /* Entries for the PCI suspend/resume callbacks are special */
310 ohci_pci_hc_driver.pci_suspend = ohci_suspend;
311 ohci_pci_hc_driver.pci_resume = ohci_resume;
Alan Sternd3474042013-08-26 10:53:53 -0400312#endif
Alan Stern9a118992013-08-21 10:33:17 -0400313
Manjunath Goudarc1117af2013-05-28 18:34:51 +0530314 return pci_register_driver(&ohci_pci_driver);
315}
316module_init(ohci_pci_init);
317
318static void __exit ohci_pci_cleanup(void)
319{
320 pci_unregister_driver(&ohci_pci_driver);
321}
322module_exit(ohci_pci_cleanup);
323
324MODULE_DESCRIPTION(DRIVER_DESC);
325MODULE_LICENSE("GPL");