xref: /linux/drivers/usb/host/ehci-pci.c (revision 1b36810e27a9791878e4694357ab6d4c06acc22d)
17ff71d6aSMatt Porter /*
27ff71d6aSMatt Porter  * EHCI HCD (Host Controller Driver) PCI Bus Glue.
37ff71d6aSMatt Porter  *
47ff71d6aSMatt Porter  * Copyright (c) 2000-2004 by David Brownell
57ff71d6aSMatt Porter  *
67ff71d6aSMatt Porter  * This program is free software; you can redistribute it and/or modify it
77ff71d6aSMatt Porter  * under the terms of the GNU General Public License as published by the
87ff71d6aSMatt Porter  * Free Software Foundation; either version 2 of the License, or (at your
97ff71d6aSMatt Porter  * option) any later version.
107ff71d6aSMatt Porter  *
117ff71d6aSMatt Porter  * This program is distributed in the hope that it will be useful, but
127ff71d6aSMatt Porter  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
137ff71d6aSMatt Porter  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
147ff71d6aSMatt Porter  * for more details.
157ff71d6aSMatt Porter  *
167ff71d6aSMatt Porter  * You should have received a copy of the GNU General Public License
177ff71d6aSMatt Porter  * along with this program; if not, write to the Free Software Foundation,
187ff71d6aSMatt Porter  * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
197ff71d6aSMatt Porter  */
207ff71d6aSMatt Porter 
21adfa79d1SAlan Stern #include <linux/kernel.h>
22adfa79d1SAlan Stern #include <linux/module.h>
23adfa79d1SAlan Stern #include <linux/pci.h>
24adfa79d1SAlan Stern #include <linux/usb.h>
25adfa79d1SAlan Stern #include <linux/usb/hcd.h>
26adfa79d1SAlan Stern 
27adfa79d1SAlan Stern #include "ehci.h"
28adfa79d1SAlan Stern #include "pci-quirks.h"
29adfa79d1SAlan Stern 
30adfa79d1SAlan Stern #define DRIVER_DESC "EHCI PCI platform driver"
31adfa79d1SAlan Stern 
32adfa79d1SAlan Stern static const char hcd_name[] = "ehci-pci";
337ff71d6aSMatt Porter 
344f683843SDirk Brandewie /* defined here to avoid adding to pci_ids.h for single instance use */
354f683843SDirk Brandewie #define PCI_DEVICE_ID_INTEL_CE4100_USB	0x2e70
364f683843SDirk Brandewie 
377ff71d6aSMatt Porter /*-------------------------------------------------------------------------*/
387ff71d6aSMatt Porter 
3918807521SDavid Brownell /* called after powerup, by probe or system-pm "wakeup" */
4018807521SDavid Brownell static int ehci_pci_reinit(struct ehci_hcd *ehci, struct pci_dev *pdev)
4118807521SDavid Brownell {
4218807521SDavid Brownell 	int			retval;
4318807521SDavid Brownell 
44401feafaSDavid Brownell 	/* we expect static quirk code to handle the "extended capabilities"
45401feafaSDavid Brownell 	 * (currently just BIOS handoff) allowed starting with EHCI 0.96
46401feafaSDavid Brownell 	 */
4718807521SDavid Brownell 
4818807521SDavid Brownell 	/* PCI Memory-Write-Invalidate cycle support is optional (uncommon) */
4918807521SDavid Brownell 	retval = pci_set_mwi(pdev);
5018807521SDavid Brownell 	if (!retval)
5118807521SDavid Brownell 		ehci_dbg(ehci, "MWI active\n");
5218807521SDavid Brownell 
5318807521SDavid Brownell 	return 0;
5418807521SDavid Brownell }
5518807521SDavid Brownell 
568926bfa7SDavid Brownell /* called during probe() after chip reset completes */
578926bfa7SDavid Brownell static int ehci_pci_setup(struct usb_hcd *hcd)
587ff71d6aSMatt Porter {
597ff71d6aSMatt Porter 	struct ehci_hcd		*ehci = hcd_to_ehci(hcd);
60abcc9448SDavid Brownell 	struct pci_dev		*pdev = to_pci_dev(hcd->self.controller);
61b09bc6cbSAndiry Xu 	struct pci_dev		*p_smbus;
62b09bc6cbSAndiry Xu 	u8			rev;
637ff71d6aSMatt Porter 	u32			temp;
6418807521SDavid Brownell 	int			retval;
657ff71d6aSMatt Porter 
661a49e2acSAlan Stern 	ehci->caps = hcd->regs;
671a49e2acSAlan Stern 
681a49e2acSAlan Stern 	/*
691a49e2acSAlan Stern 	 * ehci_init() causes memory for DMA transfers to be
701a49e2acSAlan Stern 	 * allocated.  Thus, any vendor-specific workarounds based on
711a49e2acSAlan Stern 	 * limiting the type of memory used for DMA transfers must
721a49e2acSAlan Stern 	 * happen before ehci_setup() is called.
731a49e2acSAlan Stern 	 *
741a49e2acSAlan Stern 	 * Most other workarounds can be done either before or after
751a49e2acSAlan Stern 	 * init and reset; they are located here too.
761a49e2acSAlan Stern 	 */
77083522d7SBenjamin Herrenschmidt 	switch (pdev->vendor) {
78083522d7SBenjamin Herrenschmidt 	case PCI_VENDOR_ID_TOSHIBA_2:
79083522d7SBenjamin Herrenschmidt 		/* celleb's companion chip */
80083522d7SBenjamin Herrenschmidt 		if (pdev->device == 0x01b5) {
81083522d7SBenjamin Herrenschmidt #ifdef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO
82083522d7SBenjamin Herrenschmidt 			ehci->big_endian_mmio = 1;
83083522d7SBenjamin Herrenschmidt #else
84083522d7SBenjamin Herrenschmidt 			ehci_warn(ehci,
85083522d7SBenjamin Herrenschmidt 				  "unsupported big endian Toshiba quirk\n");
86083522d7SBenjamin Herrenschmidt #endif
87083522d7SBenjamin Herrenschmidt 		}
88083522d7SBenjamin Herrenschmidt 		break;
89c32ba30fSPaul Serice 	case PCI_VENDOR_ID_NVIDIA:
90c32ba30fSPaul Serice 		/* NVidia reports that certain chips don't handle
91c32ba30fSPaul Serice 		 * QH, ITD, or SITD addresses above 2GB.  (But TD,
92c32ba30fSPaul Serice 		 * data buffer, and periodic schedule are normal.)
93c32ba30fSPaul Serice 		 */
94c32ba30fSPaul Serice 		switch (pdev->device) {
95c32ba30fSPaul Serice 		case 0x003c:	/* MCP04 */
96c32ba30fSPaul Serice 		case 0x005b:	/* CK804 */
97c32ba30fSPaul Serice 		case 0x00d8:	/* CK8 */
98c32ba30fSPaul Serice 		case 0x00e8:	/* CK8S */
99c32ba30fSPaul Serice 			if (pci_set_consistent_dma_mask(pdev,
100929a22a5SYang Hongyang 						DMA_BIT_MASK(31)) < 0)
101c32ba30fSPaul Serice 				ehci_warn(ehci, "can't enable NVidia "
102c32ba30fSPaul Serice 					"workaround for >2GB RAM\n");
103c32ba30fSPaul Serice 			break;
1041a49e2acSAlan Stern 
1051a49e2acSAlan Stern 		/* Some NForce2 chips have problems with selective suspend;
1061a49e2acSAlan Stern 		 * fixed in newer silicon.
1071a49e2acSAlan Stern 		 */
1081a49e2acSAlan Stern 		case 0x0068:
1091a49e2acSAlan Stern 			if (pdev->revision < 0xa4)
1101a49e2acSAlan Stern 				ehci->no_selective_suspend = 1;
111c32ba30fSPaul Serice 			break;
112c32ba30fSPaul Serice 		}
1133681d8f3SDavid Miller 		break;
114403dbd36SAlek Du 	case PCI_VENDOR_ID_INTEL:
1151a49e2acSAlan Stern 		if (pdev->device == PCI_DEVICE_ID_INTEL_CE4100_USB)
1164f683843SDirk Brandewie 			hcd->has_tt = 1;
117403dbd36SAlek Du 		break;
1187ff71d6aSMatt Porter 	case PCI_VENDOR_ID_TDI:
1191a49e2acSAlan Stern 		if (pdev->device == PCI_DEVICE_ID_TDI_EHCI)
1207329e211SAlan Stern 			hcd->has_tt = 1;
1217ff71d6aSMatt Porter 		break;
1227ff71d6aSMatt Porter 	case PCI_VENDOR_ID_AMD:
123ad93562bSAndiry Xu 		/* AMD PLL quirk */
124ad93562bSAndiry Xu 		if (usb_amd_find_chipset_info())
125ad93562bSAndiry Xu 			ehci->amd_pll_fix = 1;
1267ff71d6aSMatt Porter 		/* AMD8111 EHCI doesn't work, according to AMD errata */
1277ff71d6aSMatt Porter 		if (pdev->device == 0x7463) {
1287ff71d6aSMatt Porter 			ehci_info(ehci, "ignoring AMD8111 (errata)\n");
1298926bfa7SDavid Brownell 			retval = -EIO;
1308926bfa7SDavid Brownell 			goto done;
1317ff71d6aSMatt Porter 		}
132a85b4e7fSBrian J. Tarricone 
1331a49e2acSAlan Stern 		/*
1341a49e2acSAlan Stern 		 * EHCI controller on AMD SB700/SB800/Hudson-2/3 platforms may
1351a49e2acSAlan Stern 		 * read/write memory space which does not belong to it when
1361a49e2acSAlan Stern 		 * there is NULL pointer with T-bit set to 1 in the frame list
1371a49e2acSAlan Stern 		 * table. To avoid the issue, the frame list link pointer
1381a49e2acSAlan Stern 		 * should always contain a valid pointer to a inactive qh.
139a85b4e7fSBrian J. Tarricone 		 */
1401a49e2acSAlan Stern 		if (pdev->device == 0x7808) {
1411a49e2acSAlan Stern 			ehci->use_dummy_qh = 1;
1421a49e2acSAlan Stern 			ehci_info(ehci, "applying AMD SB700/SB800/Hudson-2/3 EHCI dummy qh workaround\n");
1437ff71d6aSMatt Porter 		}
1447ff71d6aSMatt Porter 		break;
145055b93c9SRene Herman 	case PCI_VENDOR_ID_VIA:
146055b93c9SRene Herman 		if (pdev->device == 0x3104 && (pdev->revision & 0xf0) == 0x60) {
147055b93c9SRene Herman 			u8 tmp;
148055b93c9SRene Herman 
149055b93c9SRene Herman 			/* The VT6212 defaults to a 1 usec EHCI sleep time which
150055b93c9SRene Herman 			 * hogs the PCI bus *badly*. Setting bit 5 of 0x4B makes
151055b93c9SRene Herman 			 * that sleep time use the conventional 10 usec.
152055b93c9SRene Herman 			 */
153055b93c9SRene Herman 			pci_read_config_byte(pdev, 0x4b, &tmp);
154055b93c9SRene Herman 			if (tmp & 0x20)
155055b93c9SRene Herman 				break;
156055b93c9SRene Herman 			pci_write_config_byte(pdev, 0x4b, tmp | 0x20);
157055b93c9SRene Herman 		}
158055b93c9SRene Herman 		break;
159b09bc6cbSAndiry Xu 	case PCI_VENDOR_ID_ATI:
160ad93562bSAndiry Xu 		/* AMD PLL quirk */
161ad93562bSAndiry Xu 		if (usb_amd_find_chipset_info())
162ad93562bSAndiry Xu 			ehci->amd_pll_fix = 1;
1631a49e2acSAlan Stern 
1641a49e2acSAlan Stern 		/*
1651a49e2acSAlan Stern 		 * EHCI controller on AMD SB700/SB800/Hudson-2/3 platforms may
1661a49e2acSAlan Stern 		 * read/write memory space which does not belong to it when
1671a49e2acSAlan Stern 		 * there is NULL pointer with T-bit set to 1 in the frame list
1681a49e2acSAlan Stern 		 * table. To avoid the issue, the frame list link pointer
1691a49e2acSAlan Stern 		 * should always contain a valid pointer to a inactive qh.
1701a49e2acSAlan Stern 		 */
1711a49e2acSAlan Stern 		if (pdev->device == 0x4396) {
1721a49e2acSAlan Stern 			ehci->use_dummy_qh = 1;
1731a49e2acSAlan Stern 			ehci_info(ehci, "applying AMD SB700/SB800/Hudson-2/3 EHCI dummy qh workaround\n");
1741a49e2acSAlan Stern 		}
1750a99e8acSShane Huang 		/* SB600 and old version of SB700 have a bug in EHCI controller,
176b09bc6cbSAndiry Xu 		 * which causes usb devices lose response in some cases.
177b09bc6cbSAndiry Xu 		 */
1780a99e8acSShane Huang 		if ((pdev->device == 0x4386) || (pdev->device == 0x4396)) {
179b09bc6cbSAndiry Xu 			p_smbus = pci_get_device(PCI_VENDOR_ID_ATI,
180b09bc6cbSAndiry Xu 						 PCI_DEVICE_ID_ATI_SBX00_SMBUS,
181b09bc6cbSAndiry Xu 						 NULL);
182b09bc6cbSAndiry Xu 			if (!p_smbus)
183b09bc6cbSAndiry Xu 				break;
184b09bc6cbSAndiry Xu 			rev = p_smbus->revision;
1850a99e8acSShane Huang 			if ((pdev->device == 0x4386) || (rev == 0x3a)
1860a99e8acSShane Huang 			    || (rev == 0x3b)) {
187b09bc6cbSAndiry Xu 				u8 tmp;
1880a99e8acSShane Huang 				ehci_info(ehci, "applying AMD SB600/SB700 USB "
1890a99e8acSShane Huang 					"freeze workaround\n");
190b09bc6cbSAndiry Xu 				pci_read_config_byte(pdev, 0x53, &tmp);
191b09bc6cbSAndiry Xu 				pci_write_config_byte(pdev, 0x53, tmp | (1<<3));
192b09bc6cbSAndiry Xu 			}
193b09bc6cbSAndiry Xu 			pci_dev_put(p_smbus);
194b09bc6cbSAndiry Xu 		}
195b09bc6cbSAndiry Xu 		break;
19668aa95d5SAlan Stern 	case PCI_VENDOR_ID_NETMOS:
19768aa95d5SAlan Stern 		/* MosChip frame-index-register bug */
19868aa95d5SAlan Stern 		ehci_info(ehci, "applying MosChip frame-index workaround\n");
19968aa95d5SAlan Stern 		ehci->frame_index_bug = 1;
20068aa95d5SAlan Stern 		break;
2017ff71d6aSMatt Porter 	}
2027ff71d6aSMatt Porter 
2031a49e2acSAlan Stern 	retval = ehci_setup(hcd);
2041a49e2acSAlan Stern 	if (retval)
2051a49e2acSAlan Stern 		return retval;
2061a49e2acSAlan Stern 
2071a49e2acSAlan Stern 	/* These workarounds need to be applied after ehci_setup() */
2081a49e2acSAlan Stern 	switch (pdev->vendor) {
2091a49e2acSAlan Stern 	case PCI_VENDOR_ID_NEC:
2101a49e2acSAlan Stern 		ehci->need_io_watchdog = 0;
2111a49e2acSAlan Stern 		break;
2121a49e2acSAlan Stern 	case PCI_VENDOR_ID_INTEL:
2131a49e2acSAlan Stern 		ehci->need_io_watchdog = 0;
2141a49e2acSAlan Stern 		break;
2151a49e2acSAlan Stern 	case PCI_VENDOR_ID_NVIDIA:
2161a49e2acSAlan Stern 		switch (pdev->device) {
2171a49e2acSAlan Stern 		/* MCP89 chips on the MacBookAir3,1 give EPROTO when
2181a49e2acSAlan Stern 		 * fetching device descriptors unless LPM is disabled.
2191a49e2acSAlan Stern 		 * There are also intermittent problems enumerating
2201a49e2acSAlan Stern 		 * devices with PPCD enabled.
2211a49e2acSAlan Stern 		 */
2221a49e2acSAlan Stern 		case 0x0d9d:
2234968f951SAlan Stern 			ehci_info(ehci, "disable ppcd for nvidia mcp89\n");
2241a49e2acSAlan Stern 			ehci->has_ppcd = 0;
2251a49e2acSAlan Stern 			ehci->command &= ~CMD_PPCEE;
2261a49e2acSAlan Stern 			break;
2271a49e2acSAlan Stern 		}
2281a49e2acSAlan Stern 		break;
2291a49e2acSAlan Stern 	}
2301a49e2acSAlan Stern 
2318d053c79SJason Wessel 	/* optional debug port, normally in the first BAR */
2328d053c79SJason Wessel 	temp = pci_find_capability(pdev, 0x0a);
2338d053c79SJason Wessel 	if (temp) {
2348d053c79SJason Wessel 		pci_read_config_dword(pdev, temp, &temp);
2358d053c79SJason Wessel 		temp >>= 16;
2368d053c79SJason Wessel 		if ((temp & (3 << 13)) == (1 << 13)) {
2378d053c79SJason Wessel 			temp &= 0x1fff;
2381a49e2acSAlan Stern 			ehci->debug = hcd->regs + temp;
2398d053c79SJason Wessel 			temp = ehci_readl(ehci, &ehci->debug->control);
2408d053c79SJason Wessel 			ehci_info(ehci, "debug port %d%s\n",
2418d053c79SJason Wessel 				HCS_DEBUG_PORT(ehci->hcs_params),
2428d053c79SJason Wessel 				(temp & DBGP_ENABLED)
2438d053c79SJason Wessel 					? " IN USE"
2448d053c79SJason Wessel 					: "");
2458d053c79SJason Wessel 			if (!(temp & DBGP_ENABLED))
2468d053c79SJason Wessel 				ehci->debug = NULL;
2478d053c79SJason Wessel 		}
2488d053c79SJason Wessel 	}
2498d053c79SJason Wessel 
2507ff71d6aSMatt Porter 	/* at least the Genesys GL880S needs fixup here */
2517ff71d6aSMatt Porter 	temp = HCS_N_CC(ehci->hcs_params) * HCS_N_PCC(ehci->hcs_params);
2527ff71d6aSMatt Porter 	temp &= 0x0f;
2537ff71d6aSMatt Porter 	if (temp && HCS_N_PORTS(ehci->hcs_params) > temp) {
2547ff71d6aSMatt Porter 		ehci_dbg(ehci, "bogus port configuration: "
2557ff71d6aSMatt Porter 			"cc=%d x pcc=%d < ports=%d\n",
2567ff71d6aSMatt Porter 			HCS_N_CC(ehci->hcs_params),
2577ff71d6aSMatt Porter 			HCS_N_PCC(ehci->hcs_params),
2587ff71d6aSMatt Porter 			HCS_N_PORTS(ehci->hcs_params));
2597ff71d6aSMatt Porter 
2607ff71d6aSMatt Porter 		switch (pdev->vendor) {
2617ff71d6aSMatt Porter 		case 0x17a0:		/* GENESYS */
2627ff71d6aSMatt Porter 			/* GL880S: should be PORTS=2 */
2637ff71d6aSMatt Porter 			temp |= (ehci->hcs_params & ~0xf);
2647ff71d6aSMatt Porter 			ehci->hcs_params = temp;
2657ff71d6aSMatt Porter 			break;
2667ff71d6aSMatt Porter 		case PCI_VENDOR_ID_NVIDIA:
2677ff71d6aSMatt Porter 			/* NF4: should be PCC=10 */
2687ff71d6aSMatt Porter 			break;
2697ff71d6aSMatt Porter 		}
2707ff71d6aSMatt Porter 	}
2717ff71d6aSMatt Porter 
2727ff71d6aSMatt Porter 	/* Serial Bus Release Number is at PCI 0x60 offset */
2733a0bac06SAlessandro Rubini 	if (pdev->vendor == PCI_VENDOR_ID_STMICRO
2743a0bac06SAlessandro Rubini 	    && pdev->device == PCI_DEVICE_ID_STMICRO_USB_HOST)
2751a49e2acSAlan Stern 		;	/* ConneXT has no sbrn register */
2761a49e2acSAlan Stern 	else
2771a49e2acSAlan Stern 		pci_read_config_byte(pdev, 0x60, &ehci->sbrn);
2787ff71d6aSMatt Porter 
2796fd9086aSAlan Stern 	/* Keep this around for a while just in case some EHCI
2806fd9086aSAlan Stern 	 * implementation uses legacy PCI PM support.  This test
2816fd9086aSAlan Stern 	 * can be removed on 17 Dec 2009 if the dev_warn() hasn't
2826fd9086aSAlan Stern 	 * been triggered by then.
2832c1c3c4cSDavid Brownell 	 */
2842c1c3c4cSDavid Brownell 	if (!device_can_wakeup(&pdev->dev)) {
2852c1c3c4cSDavid Brownell 		u16	port_wake;
2862c1c3c4cSDavid Brownell 
2872c1c3c4cSDavid Brownell 		pci_read_config_word(pdev, 0x62, &port_wake);
2886fd9086aSAlan Stern 		if (port_wake & 0x0001) {
2896fd9086aSAlan Stern 			dev_warn(&pdev->dev, "Enabling legacy PCI PM\n");
290bcca06efSAlan Stern 			device_set_wakeup_capable(&pdev->dev, 1);
2912c1c3c4cSDavid Brownell 		}
2926fd9086aSAlan Stern 	}
2937ff71d6aSMatt Porter 
294f8aeb3bbSDavid Brownell #ifdef	CONFIG_USB_SUSPEND
295f8aeb3bbSDavid Brownell 	/* REVISIT: the controller works fine for wakeup iff the root hub
296f8aeb3bbSDavid Brownell 	 * itself is "globally" suspended, but usbcore currently doesn't
297f8aeb3bbSDavid Brownell 	 * understand such things.
298f8aeb3bbSDavid Brownell 	 *
299f8aeb3bbSDavid Brownell 	 * System suspend currently expects to be able to suspend the entire
300f8aeb3bbSDavid Brownell 	 * device tree, device-at-a-time.  If we failed selective suspend
301f8aeb3bbSDavid Brownell 	 * reports, system suspend would fail; so the root hub code must claim
302411c9403SAnand Gadiyar 	 * success.  That's lying to usbcore, and it matters for runtime
303f8aeb3bbSDavid Brownell 	 * PM scenarios with selective suspend and remote wakeup...
304f8aeb3bbSDavid Brownell 	 */
305f8aeb3bbSDavid Brownell 	if (ehci->no_selective_suspend && device_can_wakeup(&pdev->dev))
306f8aeb3bbSDavid Brownell 		ehci_warn(ehci, "selective suspend/wakeup unavailable\n");
307f8aeb3bbSDavid Brownell #endif
308f8aeb3bbSDavid Brownell 
30918807521SDavid Brownell 	retval = ehci_pci_reinit(ehci, pdev);
3108926bfa7SDavid Brownell done:
3118926bfa7SDavid Brownell 	return retval;
3127ff71d6aSMatt Porter }
3137ff71d6aSMatt Porter 
3147ff71d6aSMatt Porter /*-------------------------------------------------------------------------*/
3157ff71d6aSMatt Porter 
3167ff71d6aSMatt Porter #ifdef	CONFIG_PM
3177ff71d6aSMatt Porter 
3187ff71d6aSMatt Porter /* suspend/resume, section 4.3 */
3197ff71d6aSMatt Porter 
320f03c17fcSDavid Brownell /* These routines rely on the PCI bus glue
3217ff71d6aSMatt Porter  * to handle powerdown and wakeup, and currently also on
3227ff71d6aSMatt Porter  * transceivers that don't need any software attention to set up
3237ff71d6aSMatt Porter  * the right sort of wakeup.
324f03c17fcSDavid Brownell  * Also they depend on separate root hub suspend/resume.
3257ff71d6aSMatt Porter  */
3267ff71d6aSMatt Porter 
32769e848c2SSarah Sharp static bool usb_is_intel_switchable_ehci(struct pci_dev *pdev)
32869e848c2SSarah Sharp {
32969e848c2SSarah Sharp 	return pdev->class == PCI_CLASS_SERIAL_USB_EHCI &&
33069e848c2SSarah Sharp 		pdev->vendor == PCI_VENDOR_ID_INTEL &&
3311c12443aSSarah Sharp 		(pdev->device == 0x1E26 ||
3321c12443aSSarah Sharp 		 pdev->device == 0x8C2D ||
3331c12443aSSarah Sharp 		 pdev->device == 0x8C26);
33469e848c2SSarah Sharp }
33569e848c2SSarah Sharp 
33669e848c2SSarah Sharp static void ehci_enable_xhci_companion(void)
33769e848c2SSarah Sharp {
33869e848c2SSarah Sharp 	struct pci_dev		*companion = NULL;
33969e848c2SSarah Sharp 
34069e848c2SSarah Sharp 	/* The xHCI and EHCI controllers are not on the same PCI slot */
34169e848c2SSarah Sharp 	for_each_pci_dev(companion) {
34269e848c2SSarah Sharp 		if (!usb_is_intel_switchable_xhci(companion))
34369e848c2SSarah Sharp 			continue;
34469e848c2SSarah Sharp 		usb_enable_xhci_ports(companion);
34569e848c2SSarah Sharp 		return;
34669e848c2SSarah Sharp 	}
34769e848c2SSarah Sharp }
34869e848c2SSarah Sharp 
3496ec4beb5SAlan Stern static int ehci_pci_resume(struct usb_hcd *hcd, bool hibernated)
3507ff71d6aSMatt Porter {
3517ff71d6aSMatt Porter 	struct ehci_hcd		*ehci = hcd_to_ehci(hcd);
35218807521SDavid Brownell 	struct pci_dev		*pdev = to_pci_dev(hcd->self.controller);
3537ff71d6aSMatt Porter 
35469e848c2SSarah Sharp 	/* The BIOS on systems with the Intel Panther Point chipset may or may
35569e848c2SSarah Sharp 	 * not support xHCI natively.  That means that during system resume, it
35669e848c2SSarah Sharp 	 * may switch the ports back to EHCI so that users can use their
35769e848c2SSarah Sharp 	 * keyboard to select a kernel from GRUB after resume from hibernate.
35869e848c2SSarah Sharp 	 *
35969e848c2SSarah Sharp 	 * The BIOS is supposed to remember whether the OS had xHCI ports
36069e848c2SSarah Sharp 	 * enabled before resume, and switch the ports back to xHCI when the
36169e848c2SSarah Sharp 	 * BIOS/OS semaphore is written, but we all know we can't trust BIOS
36269e848c2SSarah Sharp 	 * writers.
36369e848c2SSarah Sharp 	 *
36469e848c2SSarah Sharp 	 * Unconditionally switch the ports back to xHCI after a system resume.
36569e848c2SSarah Sharp 	 * We can't tell whether the EHCI or xHCI controller will be resumed
36669e848c2SSarah Sharp 	 * first, so we have to do the port switchover in both drivers.  Writing
36769e848c2SSarah Sharp 	 * a '1' to the port switchover registers should have no effect if the
36869e848c2SSarah Sharp 	 * port was already switched over.
36969e848c2SSarah Sharp 	 */
37069e848c2SSarah Sharp 	if (usb_is_intel_switchable_ehci(pdev))
37169e848c2SSarah Sharp 		ehci_enable_xhci_companion();
37269e848c2SSarah Sharp 
373c5cf9212SAlan Stern 	if (ehci_resume(hcd, hibernated) != 0)
37418807521SDavid Brownell 		(void) ehci_pci_reinit(ehci, pdev);
3758c03356aSAlan Stern 	return 0;
3767ff71d6aSMatt Porter }
3777ff71d6aSMatt Porter 
378adfa79d1SAlan Stern #else
3797ff71d6aSMatt Porter 
380adfa79d1SAlan Stern #define ehci_suspend		NULL
381adfa79d1SAlan Stern #define ehci_pci_resume		NULL
382adfa79d1SAlan Stern #endif	/* CONFIG_PM */
3837ff71d6aSMatt Porter 
384adfa79d1SAlan Stern static struct hc_driver __read_mostly ehci_pci_hc_driver;
385adfa79d1SAlan Stern 
386*1b36810eSAlan Stern static const struct ehci_driver_overrides pci_overrides __initdata = {
3878926bfa7SDavid Brownell 	.reset =		ehci_pci_setup,
3887ff71d6aSMatt Porter };
3897ff71d6aSMatt Porter 
3907ff71d6aSMatt Porter /*-------------------------------------------------------------------------*/
3917ff71d6aSMatt Porter 
3927ff71d6aSMatt Porter /* PCI driver selection metadata; PCI hotplugging uses this */
3937ff71d6aSMatt Porter static const struct pci_device_id pci_ids [] = { {
3947ff71d6aSMatt Porter 	/* handle any USB 2.0 EHCI controller */
395c67808eeSJean Delvare 	PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_EHCI, ~0),
3967ff71d6aSMatt Porter 	.driver_data =	(unsigned long) &ehci_pci_hc_driver,
3973a0bac06SAlessandro Rubini 	}, {
3983a0bac06SAlessandro Rubini 	PCI_VDEVICE(STMICRO, PCI_DEVICE_ID_STMICRO_USB_HOST),
3993a0bac06SAlessandro Rubini 	.driver_data = (unsigned long) &ehci_pci_hc_driver,
4007ff71d6aSMatt Porter 	},
4017ff71d6aSMatt Porter 	{ /* end: all zeroes */ }
4027ff71d6aSMatt Porter };
4037ff71d6aSMatt Porter MODULE_DEVICE_TABLE(pci, pci_ids);
4047ff71d6aSMatt Porter 
4057ff71d6aSMatt Porter /* pci driver glue; this is a "new style" PCI driver module */
4067ff71d6aSMatt Porter static struct pci_driver ehci_pci_driver = {
4077ff71d6aSMatt Porter 	.name =		(char *) hcd_name,
4087ff71d6aSMatt Porter 	.id_table =	pci_ids,
4097ff71d6aSMatt Porter 
4107ff71d6aSMatt Porter 	.probe =	usb_hcd_pci_probe,
4117ff71d6aSMatt Porter 	.remove =	usb_hcd_pci_remove,
41264a21d02SAleksey Gorelov 	.shutdown = 	usb_hcd_pci_shutdown,
413abb30641SAlan Stern 
414abb30641SAlan Stern #ifdef CONFIG_PM_SLEEP
415abb30641SAlan Stern 	.driver =	{
416abb30641SAlan Stern 		.pm =	&usb_hcd_pci_pm_ops
417abb30641SAlan Stern 	},
418abb30641SAlan Stern #endif
4197ff71d6aSMatt Porter };
420adfa79d1SAlan Stern 
421adfa79d1SAlan Stern static int __init ehci_pci_init(void)
422adfa79d1SAlan Stern {
423adfa79d1SAlan Stern 	if (usb_disabled())
424adfa79d1SAlan Stern 		return -ENODEV;
425adfa79d1SAlan Stern 
426adfa79d1SAlan Stern 	pr_info("%s: " DRIVER_DESC "\n", hcd_name);
427adfa79d1SAlan Stern 
428*1b36810eSAlan Stern 	ehci_init_driver(&ehci_pci_hc_driver, &pci_overrides);
429adfa79d1SAlan Stern 
430adfa79d1SAlan Stern 	/* Entries for the PCI suspend/resume callbacks are special */
431adfa79d1SAlan Stern 	ehci_pci_hc_driver.pci_suspend = ehci_suspend;
432adfa79d1SAlan Stern 	ehci_pci_hc_driver.pci_resume = ehci_pci_resume;
433adfa79d1SAlan Stern 
434adfa79d1SAlan Stern 	return pci_register_driver(&ehci_pci_driver);
435adfa79d1SAlan Stern }
436adfa79d1SAlan Stern module_init(ehci_pci_init);
437adfa79d1SAlan Stern 
438adfa79d1SAlan Stern static void __exit ehci_pci_cleanup(void)
439adfa79d1SAlan Stern {
440adfa79d1SAlan Stern 	pci_unregister_driver(&ehci_pci_driver);
441adfa79d1SAlan Stern }
442adfa79d1SAlan Stern module_exit(ehci_pci_cleanup);
443adfa79d1SAlan Stern 
444adfa79d1SAlan Stern MODULE_DESCRIPTION(DRIVER_DESC);
445adfa79d1SAlan Stern MODULE_AUTHOR("David Brownell");
446adfa79d1SAlan Stern MODULE_AUTHOR("Alan Stern");
447adfa79d1SAlan Stern MODULE_LICENSE("GPL");
448