blob: 5444ecdbfb92797203cb2de3e6892f8c5e2e9e21 [file] [log] [blame]
Sarah Sharp66d4ead2009-04-27 19:52:28 -07001/*
2 * xHCI host controller driver PCI Bus Glue.
3 *
4 * Copyright (C) 2008 Intel Corp.
5 *
6 * Author: Sarah Sharp
7 * Some code borrowed from the Linux EHCI driver.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 * for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23#include <linux/pci.h>
Ben Hutchings7fc2a612011-04-25 16:54:28 +010024#include <linux/slab.h>
Paul Gortmaker6eb0de82011-07-03 16:09:31 -040025#include <linux/module.h>
Sarah Sharp66d4ead2009-04-27 19:52:28 -070026
27#include "xhci.h"
Xenia Ragiadakou4bdfe4c2013-08-06 07:52:45 +030028#include "xhci-trace.h"
Sarah Sharp66d4ead2009-04-27 19:52:28 -070029
Sarah Sharpac9d8fe2009-08-07 14:04:55 -070030/* Device for a quirk */
31#define PCI_VENDOR_ID_FRESCO_LOGIC 0x1b73
32#define PCI_DEVICE_ID_FRESCO_LOGIC_PDK 0x1000
Sarah Sharpbba18e32012-10-17 13:44:06 -070033#define PCI_DEVICE_ID_FRESCO_LOGIC_FL1400 0x1400
Sarah Sharpac9d8fe2009-08-07 14:04:55 -070034
Maarten Lankhorstc877b3b2011-06-15 23:47:21 +020035#define PCI_VENDOR_ID_ETRON 0x1b6f
36#define PCI_DEVICE_ID_ASROCK_P67 0x7023
37
Sarah Sharp66d4ead2009-04-27 19:52:28 -070038static const char hcd_name[] = "xhci_hcd";
39
40/* called after powerup, by probe or system-pm "wakeup" */
41static int xhci_pci_reinit(struct xhci_hcd *xhci, struct pci_dev *pdev)
42{
43 /*
44 * TODO: Implement finding debug ports later.
45 * TODO: see if there are any quirks that need to be added to handle
46 * new extended capabilities.
47 */
48
49 /* PCI Memory-Write-Invalidate cycle support is optional (uncommon) */
50 if (!pci_set_mwi(pdev))
51 xhci_dbg(xhci, "MWI active\n");
52
53 xhci_dbg(xhci, "Finished xhci_pci_reinit\n");
54 return 0;
55}
56
Sebastian Andrzej Siewiorda3c9c42011-09-23 14:20:00 -070057static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
58{
59 struct pci_dev *pdev = to_pci_dev(dev);
60
Sarah Sharpac9d8fe2009-08-07 14:04:55 -070061 /* Look for vendor-specific quirks */
62 if (pdev->vendor == PCI_VENDOR_ID_FRESCO_LOGIC &&
Sarah Sharpbba18e32012-10-17 13:44:06 -070063 (pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_PDK ||
64 pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_FL1400)) {
65 if (pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_PDK &&
66 pdev->revision == 0x0) {
Sarah Sharpac9d8fe2009-08-07 14:04:55 -070067 xhci->quirks |= XHCI_RESET_EP_QUIRK;
Xenia Ragiadakou4bdfe4c2013-08-06 07:52:45 +030068 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
69 "QUIRK: Fresco Logic xHC needs configure"
70 " endpoint cmd after reset endpoint");
Sarah Sharpf5182b42011-06-02 11:33:02 -070071 }
Oliver Neukum455f5892013-09-30 15:50:54 +020072 if (pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_PDK &&
73 pdev->revision == 0x4) {
74 xhci->quirks |= XHCI_SLOW_SUSPEND;
75 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
76 "QUIRK: Fresco Logic xHC revision %u"
77 "must be suspended extra slowly",
78 pdev->revision);
79 }
Sarah Sharpf5182b42011-06-02 11:33:02 -070080 /* Fresco Logic confirms: all revisions of this chip do not
81 * support MSI, even though some of them claim to in their PCI
82 * capabilities.
83 */
84 xhci->quirks |= XHCI_BROKEN_MSI;
Xenia Ragiadakou4bdfe4c2013-08-06 07:52:45 +030085 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
86 "QUIRK: Fresco Logic revision %u "
87 "has broken MSI implementation",
Sarah Sharpf5182b42011-06-02 11:33:02 -070088 pdev->revision);
Sarah Sharp1530bbc62012-05-08 09:22:49 -070089 xhci->quirks |= XHCI_TRUST_TX_LENGTH;
Sarah Sharpac9d8fe2009-08-07 14:04:55 -070090 }
Sarah Sharpf5182b42011-06-02 11:33:02 -070091
Sarah Sharp02386342010-05-24 13:25:28 -070092 if (pdev->vendor == PCI_VENDOR_ID_NEC)
93 xhci->quirks |= XHCI_NEC_HOST;
Sarah Sharpac9d8fe2009-08-07 14:04:55 -070094
Andiry Xu7e393a82011-09-23 14:19:54 -070095 if (pdev->vendor == PCI_VENDOR_ID_AMD && xhci->hci_version == 0x96)
96 xhci->quirks |= XHCI_AMD_0x96_HOST;
97
Andiry Xuc41136b2011-03-22 17:08:14 +080098 /* AMD PLL quirk */
99 if (pdev->vendor == PCI_VENDOR_ID_AMD && usb_amd_find_chipset_info())
100 xhci->quirks |= XHCI_AMD_PLL_FIX;
Sarah Sharpe3567d22012-05-16 13:36:24 -0700101 if (pdev->vendor == PCI_VENDOR_ID_INTEL) {
102 xhci->quirks |= XHCI_LPM_SUPPORT;
103 xhci->quirks |= XHCI_INTEL_HOST;
104 }
Sarah Sharpad808332011-05-25 10:43:56 -0700105 if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
106 pdev->device == PCI_DEVICE_ID_INTEL_PANTHERPOINT_XHCI) {
Sarah Sharp2cf95c12011-05-11 16:14:58 -0700107 xhci->quirks |= XHCI_EP_LIMIT_QUIRK;
108 xhci->limit_active_eps = 64;
Sarah Sharp86cc5582011-09-02 11:05:54 -0700109 xhci->quirks |= XHCI_SW_BW_CHECKING;
Sarah Sharpe95829f2012-07-23 18:59:30 +0300110 /*
111 * PPT desktop boards DH77EB and DH77DF will power back on after
112 * a few seconds of being shutdown. The fix for this is to
113 * switch the ports from xHCI to EHCI on shutdown. We can't use
114 * DMI information to find those particular boards (since each
115 * vendor will change the board name), so we have to key off all
116 * PPT chipsets.
117 */
118 xhci->quirks |= XHCI_SPURIOUS_REBOOT;
Sarah Sharp80fab3b2012-09-19 16:27:26 -0700119 xhci->quirks |= XHCI_AVOID_BEI;
Sarah Sharpad808332011-05-25 10:43:56 -0700120 }
Maarten Lankhorstc877b3b2011-06-15 23:47:21 +0200121 if (pdev->vendor == PCI_VENDOR_ID_ETRON &&
122 pdev->device == PCI_DEVICE_ID_ASROCK_P67) {
123 xhci->quirks |= XHCI_RESET_ON_RESUME;
Xenia Ragiadakou4bdfe4c2013-08-06 07:52:45 +0300124 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
125 "QUIRK: Resetting on resume");
Sarah Sharp5cb7df22012-07-02 13:36:23 -0700126 xhci->quirks |= XHCI_TRUST_TX_LENGTH;
Maarten Lankhorstc877b3b2011-06-15 23:47:21 +0200127 }
Elric Fu457a4f62012-03-29 15:47:50 +0800128 if (pdev->vendor == PCI_VENDOR_ID_VIA)
129 xhci->quirks |= XHCI_RESET_ON_RESUME;
Sebastian Andrzej Siewiorda3c9c42011-09-23 14:20:00 -0700130}
Andiry Xuc41136b2011-03-22 17:08:14 +0800131
Sebastian Andrzej Siewiorda3c9c42011-09-23 14:20:00 -0700132/* called during probe() after chip reset completes */
133static int xhci_pci_setup(struct usb_hcd *hcd)
134{
135 struct xhci_hcd *xhci;
136 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
137 int retval;
138
139 retval = xhci_gen_setup(hcd, xhci_pci_quirks);
Sarah Sharp66d4ead2009-04-27 19:52:28 -0700140 if (retval)
Sebastian Andrzej Siewiorda3c9c42011-09-23 14:20:00 -0700141 return retval;
Sarah Sharp66d4ead2009-04-27 19:52:28 -0700142
Sebastian Andrzej Siewiorda3c9c42011-09-23 14:20:00 -0700143 xhci = hcd_to_xhci(hcd);
144 if (!usb_hcd_is_primary_hcd(hcd))
145 return 0;
Sarah Sharp66d4ead2009-04-27 19:52:28 -0700146
147 pci_read_config_byte(pdev, XHCI_SBRN_OFFSET, &xhci->sbrn);
148 xhci_dbg(xhci, "Got SBRN %u\n", (unsigned int) xhci->sbrn);
149
150 /* Find any debug ports */
Sarah Sharpb02d0ed2010-10-26 11:03:44 -0700151 retval = xhci_pci_reinit(xhci, pdev);
152 if (!retval)
153 return retval;
154
Sarah Sharpb02d0ed2010-10-26 11:03:44 -0700155 kfree(xhci);
156 return retval;
157}
158
Sarah Sharpf6ff0ac2010-12-16 11:21:10 -0800159/*
160 * We need to register our own PCI probe function (instead of the USB core's
161 * function) in order to create a second roothub under xHCI.
162 */
163static int xhci_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
164{
165 int retval;
166 struct xhci_hcd *xhci;
167 struct hc_driver *driver;
168 struct usb_hcd *hcd;
169
170 driver = (struct hc_driver *)id->driver_data;
171 /* Register the USB 2.0 roothub.
172 * FIXME: USB core must know to register the USB 2.0 roothub first.
173 * This is sort of silly, because we could just set the HCD driver flags
174 * to say USB 2.0, but I'm not sure what the implications would be in
175 * the other parts of the HCD code.
176 */
177 retval = usb_hcd_pci_probe(dev, id);
178
179 if (retval)
180 return retval;
181
182 /* USB 2.0 roothub is stored in the PCI device now. */
183 hcd = dev_get_drvdata(&dev->dev);
184 xhci = hcd_to_xhci(hcd);
185 xhci->shared_hcd = usb_create_shared_hcd(driver, &dev->dev,
186 pci_name(dev), hcd);
187 if (!xhci->shared_hcd) {
188 retval = -ENOMEM;
189 goto dealloc_usb2_hcd;
190 }
191
192 /* Set the xHCI pointer before xhci_pci_setup() (aka hcd_driver.reset)
193 * is called by usb_add_hcd().
194 */
195 *((struct xhci_hcd **) xhci->shared_hcd->hcd_priv) = xhci;
196
197 retval = usb_add_hcd(xhci->shared_hcd, dev->irq,
Yong Zhangb5dd18d2011-09-07 16:10:52 +0800198 IRQF_SHARED);
Sarah Sharpf6ff0ac2010-12-16 11:21:10 -0800199 if (retval)
200 goto put_usb3_hcd;
201 /* Roothub already marked as USB 3.0 speed */
Sarah Sharp3b3db022012-05-09 10:55:03 -0700202
203 /* We know the LPM timeout algorithms for this host, let the USB core
204 * enable and disable LPM for devices under the USB 3.0 roothub.
205 */
206 if (xhci->quirks & XHCI_LPM_SUPPORT)
207 hcd_to_bus(xhci->shared_hcd)->root_hub->lpm_capable = 1;
208
Sarah Sharpf6ff0ac2010-12-16 11:21:10 -0800209 return 0;
210
211put_usb3_hcd:
212 usb_put_hcd(xhci->shared_hcd);
213dealloc_usb2_hcd:
214 usb_hcd_pci_remove(dev);
215 return retval;
216}
217
Sarah Sharpb02d0ed2010-10-26 11:03:44 -0700218static void xhci_pci_remove(struct pci_dev *dev)
219{
220 struct xhci_hcd *xhci;
221
222 xhci = hcd_to_xhci(pci_get_drvdata(dev));
Sarah Sharpf6ff0ac2010-12-16 11:21:10 -0800223 if (xhci->shared_hcd) {
224 usb_remove_hcd(xhci->shared_hcd);
225 usb_put_hcd(xhci->shared_hcd);
226 }
Sarah Sharpb02d0ed2010-10-26 11:03:44 -0700227 usb_hcd_pci_remove(dev);
228 kfree(xhci);
Sarah Sharp66d4ead2009-04-27 19:52:28 -0700229}
230
Andiry Xu5535b1d52010-10-14 07:23:06 -0700231#ifdef CONFIG_PM
232static int xhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
233{
234 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
Sarah Sharpc3897aa2013-04-18 10:02:03 -0700235 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
236
237 /*
238 * Systems with the TI redriver that loses port status change events
239 * need to have the registers polled during D3, so avoid D3cold.
240 */
241 if (xhci_compliance_mode_recovery_timer_quirk_check())
242 pdev->no_d3cold = true;
Andiry Xu5535b1d52010-10-14 07:23:06 -0700243
Felipe Balbi77b84762012-10-19 10:55:16 +0300244 return xhci_suspend(xhci);
Andiry Xu5535b1d52010-10-14 07:23:06 -0700245}
246
247static int xhci_pci_resume(struct usb_hcd *hcd, bool hibernated)
248{
249 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
Sarah Sharp69e848c2011-02-22 09:57:15 -0800250 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
Andiry Xu5535b1d52010-10-14 07:23:06 -0700251 int retval = 0;
252
Sarah Sharp69e848c2011-02-22 09:57:15 -0800253 /* The BIOS on systems with the Intel Panther Point chipset may or may
254 * not support xHCI natively. That means that during system resume, it
255 * may switch the ports back to EHCI so that users can use their
256 * keyboard to select a kernel from GRUB after resume from hibernate.
257 *
258 * The BIOS is supposed to remember whether the OS had xHCI ports
259 * enabled before resume, and switch the ports back to xHCI when the
260 * BIOS/OS semaphore is written, but we all know we can't trust BIOS
261 * writers.
262 *
263 * Unconditionally switch the ports back to xHCI after a system resume.
Mathias Nyman26b76792013-07-23 11:35:47 +0300264 * It should not matter whether the EHCI or xHCI controller is
265 * resumed first. It's enough to do the switchover in xHCI because
266 * USB core won't notice anything as the hub driver doesn't start
267 * running again until after all the devices (including both EHCI and
268 * xHCI host controllers) have been resumed.
Sarah Sharp69e848c2011-02-22 09:57:15 -0800269 */
Mathias Nyman26b76792013-07-23 11:35:47 +0300270
271 if (pdev->vendor == PCI_VENDOR_ID_INTEL)
272 usb_enable_intel_xhci_ports(pdev);
Sarah Sharp69e848c2011-02-22 09:57:15 -0800273
Andiry Xu5535b1d52010-10-14 07:23:06 -0700274 retval = xhci_resume(xhci, hibernated);
275 return retval;
276}
277#endif /* CONFIG_PM */
278
Sarah Sharp66d4ead2009-04-27 19:52:28 -0700279static const struct hc_driver xhci_pci_hc_driver = {
280 .description = hcd_name,
281 .product_desc = "xHCI Host Controller",
Sarah Sharpb02d0ed2010-10-26 11:03:44 -0700282 .hcd_priv_size = sizeof(struct xhci_hcd *),
Sarah Sharp66d4ead2009-04-27 19:52:28 -0700283
284 /*
285 * generic hardware linkage
286 */
Sarah Sharp7f84eef2009-04-27 19:53:56 -0700287 .irq = xhci_irq,
Sarah Sharpf6ff0ac2010-12-16 11:21:10 -0800288 .flags = HCD_MEMORY | HCD_USB3 | HCD_SHARED,
Sarah Sharp66d4ead2009-04-27 19:52:28 -0700289
290 /*
291 * basic lifecycle operations
292 */
293 .reset = xhci_pci_setup,
294 .start = xhci_run,
Andiry Xu5535b1d52010-10-14 07:23:06 -0700295#ifdef CONFIG_PM
296 .pci_suspend = xhci_pci_suspend,
297 .pci_resume = xhci_pci_resume,
298#endif
Sarah Sharp66d4ead2009-04-27 19:52:28 -0700299 .stop = xhci_stop,
300 .shutdown = xhci_shutdown,
301
302 /*
Sarah Sharp3ffbba92009-04-27 19:57:38 -0700303 * managing i/o requests and associated device resources
304 */
Sarah Sharpd0e96f52009-04-27 19:58:01 -0700305 .urb_enqueue = xhci_urb_enqueue,
306 .urb_dequeue = xhci_urb_dequeue,
Sarah Sharp3ffbba92009-04-27 19:57:38 -0700307 .alloc_dev = xhci_alloc_dev,
308 .free_dev = xhci_free_dev,
Sarah Sharpeab1caf2010-04-05 10:55:58 -0700309 .alloc_streams = xhci_alloc_streams,
310 .free_streams = xhci_free_streams,
Sarah Sharpf94e01862009-04-27 19:58:38 -0700311 .add_endpoint = xhci_add_endpoint,
312 .drop_endpoint = xhci_drop_endpoint,
Sarah Sharpa1587d92009-07-27 12:03:15 -0700313 .endpoint_reset = xhci_endpoint_reset,
Sarah Sharpf94e01862009-04-27 19:58:38 -0700314 .check_bandwidth = xhci_check_bandwidth,
315 .reset_bandwidth = xhci_reset_bandwidth,
Sarah Sharp3ffbba92009-04-27 19:57:38 -0700316 .address_device = xhci_address_device,
Sarah Sharpb356b7c2009-09-04 10:53:24 -0700317 .update_hub_device = xhci_update_hub_device,
Andiry Xuf0615c42010-10-14 07:22:48 -0700318 .reset_device = xhci_discover_or_reset_device,
Sarah Sharp3ffbba92009-04-27 19:57:38 -0700319
320 /*
Sarah Sharp66d4ead2009-04-27 19:52:28 -0700321 * scheduling support
322 */
323 .get_frame_number = xhci_get_frame,
324
Sarah Sharp0f2a7932009-04-27 19:57:12 -0700325 /* Root hub support */
326 .hub_control = xhci_hub_control,
327 .hub_status_data = xhci_hub_status_data,
Andiry Xu9777e3c2010-10-14 07:23:03 -0700328 .bus_suspend = xhci_bus_suspend,
329 .bus_resume = xhci_bus_resume,
Andiry Xu95743232011-09-23 14:19:51 -0700330 /*
331 * call back when device connected and addressed
332 */
333 .update_device = xhci_update_device,
Andiry Xu65580b432011-09-23 14:19:52 -0700334 .set_usb2_hw_lpm = xhci_set_usb2_hardware_lpm,
Sarah Sharp3b3db022012-05-09 10:55:03 -0700335 .enable_usb3_lpm_timeout = xhci_enable_usb3_lpm_timeout,
336 .disable_usb3_lpm_timeout = xhci_disable_usb3_lpm_timeout,
Lan Tianyu3f5eb142013-03-19 16:48:12 +0800337 .find_raw_port_number = xhci_find_raw_port_number,
Sarah Sharp66d4ead2009-04-27 19:52:28 -0700338};
339
340/*-------------------------------------------------------------------------*/
341
342/* PCI driver selection metadata; PCI hotplugging uses this */
343static const struct pci_device_id pci_ids[] = { {
344 /* handle any USB 3.0 xHCI controller */
345 PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_XHCI, ~0),
346 .driver_data = (unsigned long) &xhci_pci_hc_driver,
347 },
348 { /* end: all zeroes */ }
349};
350MODULE_DEVICE_TABLE(pci, pci_ids);
351
352/* pci driver glue; this is a "new style" PCI driver module */
353static struct pci_driver xhci_pci_driver = {
354 .name = (char *) hcd_name,
355 .id_table = pci_ids,
356
Sarah Sharpf6ff0ac2010-12-16 11:21:10 -0800357 .probe = xhci_pci_probe,
Sarah Sharpb02d0ed2010-10-26 11:03:44 -0700358 .remove = xhci_pci_remove,
Sarah Sharp66d4ead2009-04-27 19:52:28 -0700359 /* suspend and resume implemented later */
360
361 .shutdown = usb_hcd_pci_shutdown,
Alan Sternf875fdb2013-09-24 15:45:25 -0400362#ifdef CONFIG_PM
Andiry Xu5535b1d52010-10-14 07:23:06 -0700363 .driver = {
364 .pm = &usb_hcd_pci_pm_ops
365 },
366#endif
Sarah Sharp66d4ead2009-04-27 19:52:28 -0700367};
368
Sebastian Andrzej Siewior0cc47d52011-09-23 14:20:02 -0700369int __init xhci_register_pci(void)
Sarah Sharp66d4ead2009-04-27 19:52:28 -0700370{
371 return pci_register_driver(&xhci_pci_driver);
372}
373
Gerard Snitselaara46c46a2012-03-16 11:34:11 -0700374void xhci_unregister_pci(void)
Sarah Sharp66d4ead2009-04-27 19:52:28 -0700375{
376 pci_unregister_driver(&xhci_pci_driver);
377}