blob: d7b4f40f9ff4eb82178020573011b2b64ab9c0bd [file] [log] [blame]
Greg Kroah-Hartman5fd54ac2017-11-03 11:28:30 +01001// SPDX-License-Identifier: GPL-1.0+
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * OHCI HCD (Host Controller Driver) for USB.
4 *
5 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
6 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
David Brownelldd9048a2006-12-05 03:18:31 -08007 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * [ Initialisation is based on Linus' ]
9 * [ uhci code and gregs ohci fragments ]
10 * [ (C) Copyright 1999 Linus Torvalds ]
11 * [ (C) Copyright 1999 Gregory P. Smith]
David Brownelldd9048a2006-12-05 03:18:31 -080012 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 * PCI Bus Glue
14 *
15 * This file is licenced under the GPL.
16 */
David Brownelldd9048a2006-12-05 03:18:31 -080017
Libin Yangab1666c2008-08-08 15:03:31 +080018#include <linux/io.h>
Manjunath Goudarc1117af2013-05-28 18:34:51 +053019#include <linux/kernel.h>
20#include <linux/module.h>
21#include <linux/pci.h>
22#include <linux/usb.h>
23#include <linux/usb/hcd.h>
24
25#include "ohci.h"
26#include "pci-quirks.h"
27
28#define DRIVER_DESC "OHCI PCI platform driver"
29
30static const char hcd_name[] = "ohci-pci";
Libin Yangab1666c2008-08-08 15:03:31 +080031
32
Linus Torvalds1da177e2005-04-16 15:20:36 -070033/*-------------------------------------------------------------------------*/
34
David Brownell931384f2007-04-17 13:06:29 -070035static int broken_suspend(struct usb_hcd *hcd)
36{
37 device_init_wakeup(&hcd->self.root_hub->dev, 0);
38 return 0;
39}
40
Benjamin Herrenschmidt4302a5952006-12-15 06:53:55 +110041/* AMD 756, for most chips (early revs), corrupts register
42 * values on read ... so enable the vendor workaround.
43 */
David Brownell931384f2007-04-17 13:06:29 -070044static int ohci_quirk_amd756(struct usb_hcd *hcd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070045{
46 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
47
Benjamin Herrenschmidt4302a5952006-12-15 06:53:55 +110048 ohci->flags = OHCI_QUIRK_AMD756;
49 ohci_dbg (ohci, "AMD756 erratum 4 workaround\n");
50
51 /* also erratum 10 (suspend/resume issues) */
David Brownell931384f2007-04-17 13:06:29 -070052 return broken_suspend(hcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053}
54
Benjamin Herrenschmidt4302a5952006-12-15 06:53:55 +110055/* Apple's OHCI driver has a lot of bizarre workarounds
56 * for this chip. Evidently control and bulk lists
57 * can get confused. (B&W G3 models, and ...)
58 */
David Brownell931384f2007-04-17 13:06:29 -070059static int ohci_quirk_opti(struct usb_hcd *hcd)
Benjamin Herrenschmidt4302a5952006-12-15 06:53:55 +110060{
61 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
62
63 ohci_dbg (ohci, "WARNING: OPTi workarounds unavailable\n");
64
65 return 0;
66}
67
68/* Check for NSC87560. We have to look at the bridge (fn1) to
69 * identify the USB (fn2). This quirk might apply to more or
70 * even all NSC stuff.
71 */
David Brownell931384f2007-04-17 13:06:29 -070072static int ohci_quirk_ns(struct usb_hcd *hcd)
Benjamin Herrenschmidt4302a5952006-12-15 06:53:55 +110073{
74 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
75 struct pci_dev *b;
76
77 b = pci_get_slot (pdev->bus, PCI_DEVFN (PCI_SLOT (pdev->devfn), 1));
78 if (b && b->device == PCI_DEVICE_ID_NS_87560_LIO
79 && b->vendor == PCI_VENDOR_ID_NS) {
80 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
81
82 ohci->flags |= OHCI_QUIRK_SUPERIO;
83 ohci_dbg (ohci, "Using NSC SuperIO setup\n");
84 }
85 pci_dev_put(b);
86
87 return 0;
88}
89
90/* Check for Compaq's ZFMicro chipset, which needs short
91 * delays before control or bulk queues get re-activated
92 * in finish_unlinks()
93 */
David Brownell931384f2007-04-17 13:06:29 -070094static int ohci_quirk_zfmicro(struct usb_hcd *hcd)
Benjamin Herrenschmidt4302a5952006-12-15 06:53:55 +110095{
96 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
97
98 ohci->flags |= OHCI_QUIRK_ZFMICRO;
Mike Nuss89a0fd12007-08-01 13:24:30 -070099 ohci_dbg(ohci, "enabled Compaq ZFMicro chipset quirks\n");
Benjamin Herrenschmidt4302a5952006-12-15 06:53:55 +1100100
101 return 0;
102}
103
Benjamin Herrenschmidt11d1a4a2006-12-15 06:54:03 +1100104/* Check for Toshiba SCC OHCI which has big endian registers
105 * and little endian in memory data structures
106 */
David Brownell931384f2007-04-17 13:06:29 -0700107static int ohci_quirk_toshiba_scc(struct usb_hcd *hcd)
Benjamin Herrenschmidt11d1a4a2006-12-15 06:54:03 +1100108{
109 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
110
111 /* That chip is only present in the southbridge of some
112 * cell based platforms which are supposed to select
113 * CONFIG_USB_OHCI_BIG_ENDIAN_MMIO. We verify here if
114 * that was the case though.
115 */
116#ifdef CONFIG_USB_OHCI_BIG_ENDIAN_MMIO
117 ohci->flags |= OHCI_QUIRK_BE_MMIO;
118 ohci_dbg (ohci, "enabled big endian Toshiba quirk\n");
119 return 0;
120#else
121 ohci_err (ohci, "unsupported big endian Toshiba quirk\n");
122 return -ENXIO;
123#endif
124}
Benjamin Herrenschmidt4302a5952006-12-15 06:53:55 +1100125
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200126/* Check for NEC chip and apply quirk for allegedly lost interrupts.
127 */
Mike Nuss89a0fd12007-08-01 13:24:30 -0700128
129static void ohci_quirk_nec_worker(struct work_struct *work)
130{
131 struct ohci_hcd *ohci = container_of(work, struct ohci_hcd, nec_work);
132 int status;
133
Mike Nuss89a0fd12007-08-01 13:24:30 -0700134 status = ohci_restart(ohci);
135 if (status != 0)
136 ohci_err(ohci, "Restarting NEC controller failed in %s, %d\n",
137 "ohci_restart", status);
138}
139
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200140static int ohci_quirk_nec(struct usb_hcd *hcd)
141{
142 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
143
144 ohci->flags |= OHCI_QUIRK_NEC;
Mike Nuss89a0fd12007-08-01 13:24:30 -0700145 INIT_WORK(&ohci->nec_work, ohci_quirk_nec_worker);
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200146 ohci_dbg (ohci, "enabled NEC chipset lost interrupt quirk\n");
147
148 return 0;
149}
150
Libin Yangab1666c2008-08-08 15:03:31 +0800151static int ohci_quirk_amd700(struct usb_hcd *hcd)
152{
153 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
Libin Yangab1666c2008-08-08 15:03:31 +0800154
Ryan Kennedy4fbb8aa2019-07-04 11:35:29 -0400155 if (usb_amd_quirk_pll_check())
Andiry Xuad935622011-03-01 14:57:05 +0800156 ohci->flags |= OHCI_QUIRK_AMD_PLL;
157
Libin Yanga1f17a872009-11-04 14:55:18 +0800158 /* SB800 needs pre-fetch fix */
Huang Rui02c123e2013-10-03 23:37:13 +0800159 if (usb_amd_prefetch_quirk()) {
Libin Yanga1f17a872009-11-04 14:55:18 +0800160 ohci->flags |= OHCI_QUIRK_AMD_PREFETCH;
161 ohci_dbg(ohci, "enabled AMD prefetch quirk\n");
162 }
163
Alan Sternc1db30a2014-05-01 15:21:42 -0400164 ohci->flags |= OHCI_QUIRK_GLOBAL_SUSPEND;
Libin Yangab1666c2008-08-08 15:03:31 +0800165 return 0;
166}
167
Gerd Hoffmann21a60f62017-03-20 09:11:49 +0100168static int ohci_quirk_qemu(struct usb_hcd *hcd)
169{
170 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
171
172 ohci->flags |= OHCI_QUIRK_QEMU;
173 ohci_dbg(ohci, "enabled qemu quirk\n");
174 return 0;
175}
176
Benjamin Herrenschmidt4302a5952006-12-15 06:53:55 +1100177/* List of quirks for OHCI */
178static const struct pci_device_id ohci_pci_quirks[] = {
179 {
180 PCI_DEVICE(PCI_VENDOR_ID_AMD, 0x740c),
181 .driver_data = (unsigned long)ohci_quirk_amd756,
182 },
183 {
184 PCI_DEVICE(PCI_VENDOR_ID_OPTI, 0xc861),
185 .driver_data = (unsigned long)ohci_quirk_opti,
186 },
187 {
188 PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_ANY_ID),
189 .driver_data = (unsigned long)ohci_quirk_ns,
190 },
191 {
192 PCI_DEVICE(PCI_VENDOR_ID_COMPAQ, 0xa0f8),
193 .driver_data = (unsigned long)ohci_quirk_zfmicro,
194 },
Benjamin Herrenschmidt11d1a4a2006-12-15 06:54:03 +1100195 {
196 PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA_2, 0x01b6),
197 .driver_data = (unsigned long)ohci_quirk_toshiba_scc,
198 },
David Brownell931384f2007-04-17 13:06:29 -0700199 {
Michael Hanselmannd576bb92007-05-31 23:34:27 +0200200 PCI_DEVICE(PCI_VENDOR_ID_NEC, PCI_DEVICE_ID_NEC_USB),
201 .driver_data = (unsigned long)ohci_quirk_nec,
202 },
203 {
David Brownell931384f2007-04-17 13:06:29 -0700204 /* Toshiba portege 4000 */
205 .vendor = PCI_VENDOR_ID_AL,
206 .device = 0x5237,
Andrey Borzenkov8ab5e8c02007-05-19 14:23:28 -0700207 .subvendor = PCI_VENDOR_ID_TOSHIBA,
David Brownell931384f2007-04-17 13:06:29 -0700208 .subdevice = 0x0004,
209 .driver_data = (unsigned long) broken_suspend,
210 },
Raphael Assenat33f73e52007-04-17 13:09:18 -0700211 {
212 PCI_DEVICE(PCI_VENDOR_ID_ITE, 0x8152),
213 .driver_data = (unsigned long) broken_suspend,
214 },
Libin Yangab1666c2008-08-08 15:03:31 +0800215 {
216 PCI_DEVICE(PCI_VENDOR_ID_ATI, 0x4397),
217 .driver_data = (unsigned long)ohci_quirk_amd700,
218 },
219 {
220 PCI_DEVICE(PCI_VENDOR_ID_ATI, 0x4398),
221 .driver_data = (unsigned long)ohci_quirk_amd700,
222 },
223 {
224 PCI_DEVICE(PCI_VENDOR_ID_ATI, 0x4399),
225 .driver_data = (unsigned long)ohci_quirk_amd700,
226 },
Gerd Hoffmann21a60f62017-03-20 09:11:49 +0100227 {
228 .vendor = PCI_VENDOR_ID_APPLE,
229 .device = 0x003f,
230 .subvendor = PCI_SUBVENDOR_ID_REDHAT_QUMRANET,
231 .subdevice = PCI_SUBDEVICE_ID_QEMU,
232 .driver_data = (unsigned long)ohci_quirk_qemu,
233 },
Libin Yangab1666c2008-08-08 15:03:31 +0800234
Benjamin Herrenschmidt4302a5952006-12-15 06:53:55 +1100235 {},
236};
237
238static int ohci_pci_reset (struct usb_hcd *hcd)
239{
240 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
Manjunath Goudarc1117af2013-05-28 18:34:51 +0530241 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
Benjamin Herrenschmidt4302a5952006-12-15 06:53:55 +1100242 int ret = 0;
243
244 if (hcd->self.controller) {
Benjamin Herrenschmidt4302a5952006-12-15 06:53:55 +1100245 const struct pci_device_id *quirk_id;
246
247 quirk_id = pci_match_id(ohci_pci_quirks, pdev);
248 if (quirk_id != NULL) {
249 int (*quirk)(struct usb_hcd *ohci);
250 quirk = (void *)quirk_id->driver_data;
251 ret = quirk(hcd);
252 }
253 }
Manjunath Goudarc1117af2013-05-28 18:34:51 +0530254
255 if (ret == 0)
256 ret = ohci_setup(hcd);
257 /*
258 * After ohci setup RWC may not be set for add-in PCI cards.
259 * This transfers PCI PM wakeup capabilities.
260 */
261 if (device_can_wakeup(&pdev->dev))
262 ohci->hc_control |= OHCI_CTRL_RWC;
Benjamin Herrenschmidt4302a5952006-12-15 06:53:55 +1100263 return ret;
264}
265
Manjunath Goudarc1117af2013-05-28 18:34:51 +0530266static struct hc_driver __read_mostly ohci_pci_hc_driver;
Benjamin Herrenschmidt4302a5952006-12-15 06:53:55 +1100267
Manjunath Goudarc1117af2013-05-28 18:34:51 +0530268static const struct ohci_driver_overrides pci_overrides __initconst = {
269 .product_desc = "OHCI PCI host controller",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 .reset = ohci_pci_reset,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271};
272
Naveen Kumar Parna4e4feee2019-05-16 20:49:23 +0530273static const struct pci_device_id pci_ids[] = { {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 /* handle any USB OHCI controller */
Jean Delvarec67808e2006-04-09 20:07:35 +0200275 PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_OHCI, ~0),
Alessandro Rubini3a0bac02012-01-06 13:33:28 +0100276 }, {
277 /* The device in the ConneXT I/O hub has no class reg */
278 PCI_VDEVICE(STMICRO, PCI_DEVICE_ID_STMICRO_USB_OHCI),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 }, { /* end: all zeroes */ }
280};
281MODULE_DEVICE_TABLE (pci, pci_ids);
282
Vinod Koulff4c65c2020-05-14 17:50:36 +0530283static int ohci_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
284{
Heikki Krogerus4e55e222022-08-31 15:50:52 +0300285 return usb_hcd_pci_probe(dev, &ohci_pci_hc_driver);
Vinod Koulff4c65c2020-05-14 17:50:36 +0530286}
287
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288/* pci driver glue; this is a "new style" PCI driver module */
289static struct pci_driver ohci_pci_driver = {
Corentin Labbecd3d8cf2020-02-18 19:32:59 +0000290 .name = hcd_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 .id_table = pci_ids,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
Vinod Koulff4c65c2020-05-14 17:50:36 +0530293 .probe = ohci_pci_probe,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 .remove = usb_hcd_pci_remove,
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700295 .shutdown = usb_hcd_pci_shutdown,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
Alan Stern69820e02013-08-26 15:01:40 -0400297#ifdef CONFIG_PM
Alan Sternabb30642009-04-27 13:33:24 -0400298 .driver = {
299 .pm = &usb_hcd_pci_pm_ops
300 },
301#endif
302};
Manjunath Goudarc1117af2013-05-28 18:34:51 +0530303
304static int __init ohci_pci_init(void)
305{
306 if (usb_disabled())
307 return -ENODEV;
308
Manjunath Goudarc1117af2013-05-28 18:34:51 +0530309 ohci_init_driver(&ohci_pci_hc_driver, &pci_overrides);
Alan Stern9a118992013-08-21 10:33:17 -0400310
Alan Sternd3474042013-08-26 10:53:53 -0400311#ifdef CONFIG_PM
Alan Stern9a118992013-08-21 10:33:17 -0400312 /* Entries for the PCI suspend/resume callbacks are special */
313 ohci_pci_hc_driver.pci_suspend = ohci_suspend;
314 ohci_pci_hc_driver.pci_resume = ohci_resume;
Alan Sternd3474042013-08-26 10:53:53 -0400315#endif
Alan Stern9a118992013-08-21 10:33:17 -0400316
Manjunath Goudarc1117af2013-05-28 18:34:51 +0530317 return pci_register_driver(&ohci_pci_driver);
318}
319module_init(ohci_pci_init);
320
321static void __exit ohci_pci_cleanup(void)
322{
323 pci_unregister_driver(&ohci_pci_driver);
324}
325module_exit(ohci_pci_cleanup);
326
327MODULE_DESCRIPTION(DRIVER_DESC);
328MODULE_LICENSE("GPL");
Tom Gundersen05c92da2013-09-10 23:30:14 +0200329MODULE_SOFTDEP("pre: ehci_pci");