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 217ff71d6aSMatt Porter #ifndef CONFIG_PCI 227ff71d6aSMatt Porter #error "This file is PCI bus glue. CONFIG_PCI must be defined." 237ff71d6aSMatt Porter #endif 247ff71d6aSMatt Porter 254f683843SDirk Brandewie /* defined here to avoid adding to pci_ids.h for single instance use */ 264f683843SDirk Brandewie #define PCI_DEVICE_ID_INTEL_CE4100_USB 0x2e70 274f683843SDirk Brandewie 287ff71d6aSMatt Porter /*-------------------------------------------------------------------------*/ 297ff71d6aSMatt Porter 3018807521SDavid Brownell /* called after powerup, by probe or system-pm "wakeup" */ 3118807521SDavid Brownell static int ehci_pci_reinit(struct ehci_hcd *ehci, struct pci_dev *pdev) 3218807521SDavid Brownell { 3318807521SDavid Brownell int retval; 3418807521SDavid Brownell 35401feafaSDavid Brownell /* we expect static quirk code to handle the "extended capabilities" 36401feafaSDavid Brownell * (currently just BIOS handoff) allowed starting with EHCI 0.96 37401feafaSDavid Brownell */ 3818807521SDavid Brownell 3918807521SDavid Brownell /* PCI Memory-Write-Invalidate cycle support is optional (uncommon) */ 4018807521SDavid Brownell retval = pci_set_mwi(pdev); 4118807521SDavid Brownell if (!retval) 4218807521SDavid Brownell ehci_dbg(ehci, "MWI active\n"); 4318807521SDavid Brownell 4418807521SDavid Brownell return 0; 4518807521SDavid Brownell } 4618807521SDavid Brownell 478926bfa7SDavid Brownell /* called during probe() after chip reset completes */ 488926bfa7SDavid Brownell static int ehci_pci_setup(struct usb_hcd *hcd) 497ff71d6aSMatt Porter { 507ff71d6aSMatt Porter struct ehci_hcd *ehci = hcd_to_ehci(hcd); 51abcc9448SDavid Brownell struct pci_dev *pdev = to_pci_dev(hcd->self.controller); 52b09bc6cbSAndiry Xu struct pci_dev *p_smbus; 53b09bc6cbSAndiry Xu u8 rev; 547ff71d6aSMatt Porter u32 temp; 5518807521SDavid Brownell int retval; 567ff71d6aSMatt Porter 57083522d7SBenjamin Herrenschmidt switch (pdev->vendor) { 58083522d7SBenjamin Herrenschmidt case PCI_VENDOR_ID_TOSHIBA_2: 59083522d7SBenjamin Herrenschmidt /* celleb's companion chip */ 60083522d7SBenjamin Herrenschmidt if (pdev->device == 0x01b5) { 61083522d7SBenjamin Herrenschmidt #ifdef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO 62083522d7SBenjamin Herrenschmidt ehci->big_endian_mmio = 1; 63083522d7SBenjamin Herrenschmidt #else 64083522d7SBenjamin Herrenschmidt ehci_warn(ehci, 65083522d7SBenjamin Herrenschmidt "unsupported big endian Toshiba quirk\n"); 66083522d7SBenjamin Herrenschmidt #endif 67083522d7SBenjamin Herrenschmidt } 68083522d7SBenjamin Herrenschmidt break; 69083522d7SBenjamin Herrenschmidt } 70083522d7SBenjamin Herrenschmidt 717ff71d6aSMatt Porter ehci->caps = hcd->regs; 72083522d7SBenjamin Herrenschmidt ehci->regs = hcd->regs + 73*c430131aSJan Andersson HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase)); 74083522d7SBenjamin Herrenschmidt 757ff71d6aSMatt Porter dbg_hcs_params(ehci, "reset"); 767ff71d6aSMatt Porter dbg_hcc_params(ehci, "reset"); 777ff71d6aSMatt Porter 78c32ba30fSPaul Serice /* ehci_init() causes memory for DMA transfers to be 79c32ba30fSPaul Serice * allocated. Thus, any vendor-specific workarounds based on 80c32ba30fSPaul Serice * limiting the type of memory used for DMA transfers must 81c32ba30fSPaul Serice * happen before ehci_init() is called. */ 82c32ba30fSPaul Serice switch (pdev->vendor) { 83c32ba30fSPaul Serice case PCI_VENDOR_ID_NVIDIA: 84c32ba30fSPaul Serice /* NVidia reports that certain chips don't handle 85c32ba30fSPaul Serice * QH, ITD, or SITD addresses above 2GB. (But TD, 86c32ba30fSPaul Serice * data buffer, and periodic schedule are normal.) 87c32ba30fSPaul Serice */ 88c32ba30fSPaul Serice switch (pdev->device) { 89c32ba30fSPaul Serice case 0x003c: /* MCP04 */ 90c32ba30fSPaul Serice case 0x005b: /* CK804 */ 91c32ba30fSPaul Serice case 0x00d8: /* CK8 */ 92c32ba30fSPaul Serice case 0x00e8: /* CK8S */ 93c32ba30fSPaul Serice if (pci_set_consistent_dma_mask(pdev, 94929a22a5SYang Hongyang DMA_BIT_MASK(31)) < 0) 95c32ba30fSPaul Serice ehci_warn(ehci, "can't enable NVidia " 96c32ba30fSPaul Serice "workaround for >2GB RAM\n"); 97c32ba30fSPaul Serice break; 98c32ba30fSPaul Serice } 99c32ba30fSPaul Serice break; 100c32ba30fSPaul Serice } 101c32ba30fSPaul Serice 1027ff71d6aSMatt Porter /* cache this readonly data; minimize chip reads */ 103083522d7SBenjamin Herrenschmidt ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); 1047ff71d6aSMatt Porter 10518807521SDavid Brownell retval = ehci_halt(ehci); 10618807521SDavid Brownell if (retval) 10718807521SDavid Brownell return retval; 10818807521SDavid Brownell 1093d091a6fSAndiry Xu if ((pdev->vendor == PCI_VENDOR_ID_AMD && pdev->device == 0x7808) || 1103d091a6fSAndiry Xu (pdev->vendor == PCI_VENDOR_ID_ATI && pdev->device == 0x4396)) { 1113d091a6fSAndiry Xu /* EHCI controller on AMD SB700/SB800/Hudson-2/3 platforms may 1123d091a6fSAndiry Xu * read/write memory space which does not belong to it when 1133d091a6fSAndiry Xu * there is NULL pointer with T-bit set to 1 in the frame list 1143d091a6fSAndiry Xu * table. To avoid the issue, the frame list link pointer 1153d091a6fSAndiry Xu * should always contain a valid pointer to a inactive qh. 1163d091a6fSAndiry Xu */ 1173d091a6fSAndiry Xu ehci->use_dummy_qh = 1; 1183d091a6fSAndiry Xu ehci_info(ehci, "applying AMD SB700/SB800/Hudson-2/3 EHCI " 1193d091a6fSAndiry Xu "dummy qh workaround\n"); 1203d091a6fSAndiry Xu } 1213d091a6fSAndiry Xu 1228926bfa7SDavid Brownell /* data structure init */ 1238926bfa7SDavid Brownell retval = ehci_init(hcd); 1248926bfa7SDavid Brownell if (retval) 1258926bfa7SDavid Brownell return retval; 1268926bfa7SDavid Brownell 1277ff71d6aSMatt Porter switch (pdev->vendor) { 1283681d8f3SDavid Miller case PCI_VENDOR_ID_NEC: 1293681d8f3SDavid Miller ehci->need_io_watchdog = 0; 1303681d8f3SDavid Miller break; 131403dbd36SAlek Du case PCI_VENDOR_ID_INTEL: 132403dbd36SAlek Du ehci->need_io_watchdog = 0; 133ae68a83bSAlan Stern ehci->fs_i_thresh = 1; 134ee4ecb8aSOliver Neukum if (pdev->device == 0x27cc) { 135ee4ecb8aSOliver Neukum ehci->broken_periodic = 1; 136ee4ecb8aSOliver Neukum ehci_info(ehci, "using broken periodic workaround\n"); 137ee4ecb8aSOliver Neukum } 138fc928250SAlek Du if (pdev->device == 0x0806 || pdev->device == 0x0811 139fc928250SAlek Du || pdev->device == 0x0829) { 140fc928250SAlek Du ehci_info(ehci, "disable lpm for langwell/penwell\n"); 141fc928250SAlek Du ehci->has_lpm = 0; 142fc928250SAlek Du } 1434f683843SDirk Brandewie if (pdev->device == PCI_DEVICE_ID_INTEL_CE4100_USB) { 1444f683843SDirk Brandewie hcd->has_tt = 1; 1454f683843SDirk Brandewie tdi_reset(ehci); 1464f683843SDirk Brandewie } 147403dbd36SAlek Du break; 1487ff71d6aSMatt Porter case PCI_VENDOR_ID_TDI: 1497ff71d6aSMatt Porter if (pdev->device == PCI_DEVICE_ID_TDI_EHCI) { 1507329e211SAlan Stern hcd->has_tt = 1; 1517ff71d6aSMatt Porter tdi_reset(ehci); 1527ff71d6aSMatt Porter } 1537ff71d6aSMatt Porter break; 1547ff71d6aSMatt Porter case PCI_VENDOR_ID_AMD: 155ad93562bSAndiry Xu /* AMD PLL quirk */ 156ad93562bSAndiry Xu if (usb_amd_find_chipset_info()) 157ad93562bSAndiry Xu ehci->amd_pll_fix = 1; 1587ff71d6aSMatt Porter /* AMD8111 EHCI doesn't work, according to AMD errata */ 1597ff71d6aSMatt Porter if (pdev->device == 0x7463) { 1607ff71d6aSMatt Porter ehci_info(ehci, "ignoring AMD8111 (errata)\n"); 1618926bfa7SDavid Brownell retval = -EIO; 1628926bfa7SDavid Brownell goto done; 1637ff71d6aSMatt Porter } 1647ff71d6aSMatt Porter break; 1657ff71d6aSMatt Porter case PCI_VENDOR_ID_NVIDIA: 166f8aeb3bbSDavid Brownell switch (pdev->device) { 167f8aeb3bbSDavid Brownell /* Some NForce2 chips have problems with selective suspend; 168f8aeb3bbSDavid Brownell * fixed in newer silicon. 169f8aeb3bbSDavid Brownell */ 170f8aeb3bbSDavid Brownell case 0x0068: 17144c10138SAuke Kok if (pdev->revision < 0xa4) 172f8aeb3bbSDavid Brownell ehci->no_selective_suspend = 1; 173f8aeb3bbSDavid Brownell break; 174a85b4e7fSBrian J. Tarricone 175a85b4e7fSBrian J. Tarricone /* MCP89 chips on the MacBookAir3,1 give EPROTO when 176a85b4e7fSBrian J. Tarricone * fetching device descriptors unless LPM is disabled. 177a85b4e7fSBrian J. Tarricone * There are also intermittent problems enumerating 178a85b4e7fSBrian J. Tarricone * devices with PPCD enabled. 179a85b4e7fSBrian J. Tarricone */ 180a85b4e7fSBrian J. Tarricone case 0x0d9d: 181a85b4e7fSBrian J. Tarricone ehci_info(ehci, "disable lpm/ppcd for nvidia mcp89"); 182a85b4e7fSBrian J. Tarricone ehci->has_lpm = 0; 183a85b4e7fSBrian J. Tarricone ehci->has_ppcd = 0; 184a85b4e7fSBrian J. Tarricone ehci->command &= ~CMD_PPCEE; 185a85b4e7fSBrian J. Tarricone break; 1867ff71d6aSMatt Porter } 1877ff71d6aSMatt Porter break; 188055b93c9SRene Herman case PCI_VENDOR_ID_VIA: 189055b93c9SRene Herman if (pdev->device == 0x3104 && (pdev->revision & 0xf0) == 0x60) { 190055b93c9SRene Herman u8 tmp; 191055b93c9SRene Herman 192055b93c9SRene Herman /* The VT6212 defaults to a 1 usec EHCI sleep time which 193055b93c9SRene Herman * hogs the PCI bus *badly*. Setting bit 5 of 0x4B makes 194055b93c9SRene Herman * that sleep time use the conventional 10 usec. 195055b93c9SRene Herman */ 196055b93c9SRene Herman pci_read_config_byte(pdev, 0x4b, &tmp); 197055b93c9SRene Herman if (tmp & 0x20) 198055b93c9SRene Herman break; 199055b93c9SRene Herman pci_write_config_byte(pdev, 0x4b, tmp | 0x20); 200055b93c9SRene Herman } 201055b93c9SRene Herman break; 202b09bc6cbSAndiry Xu case PCI_VENDOR_ID_ATI: 203ad93562bSAndiry Xu /* AMD PLL quirk */ 204ad93562bSAndiry Xu if (usb_amd_find_chipset_info()) 205ad93562bSAndiry Xu ehci->amd_pll_fix = 1; 2060a99e8acSShane Huang /* SB600 and old version of SB700 have a bug in EHCI controller, 207b09bc6cbSAndiry Xu * which causes usb devices lose response in some cases. 208b09bc6cbSAndiry Xu */ 2090a99e8acSShane Huang if ((pdev->device == 0x4386) || (pdev->device == 0x4396)) { 210b09bc6cbSAndiry Xu p_smbus = pci_get_device(PCI_VENDOR_ID_ATI, 211b09bc6cbSAndiry Xu PCI_DEVICE_ID_ATI_SBX00_SMBUS, 212b09bc6cbSAndiry Xu NULL); 213b09bc6cbSAndiry Xu if (!p_smbus) 214b09bc6cbSAndiry Xu break; 215b09bc6cbSAndiry Xu rev = p_smbus->revision; 2160a99e8acSShane Huang if ((pdev->device == 0x4386) || (rev == 0x3a) 2170a99e8acSShane Huang || (rev == 0x3b)) { 218b09bc6cbSAndiry Xu u8 tmp; 2190a99e8acSShane Huang ehci_info(ehci, "applying AMD SB600/SB700 USB " 2200a99e8acSShane Huang "freeze workaround\n"); 221b09bc6cbSAndiry Xu pci_read_config_byte(pdev, 0x53, &tmp); 222b09bc6cbSAndiry Xu pci_write_config_byte(pdev, 0x53, tmp | (1<<3)); 223b09bc6cbSAndiry Xu } 224b09bc6cbSAndiry Xu pci_dev_put(p_smbus); 225b09bc6cbSAndiry Xu } 226b09bc6cbSAndiry Xu break; 2277ff71d6aSMatt Porter } 2287ff71d6aSMatt Porter 2298d053c79SJason Wessel /* optional debug port, normally in the first BAR */ 2308d053c79SJason Wessel temp = pci_find_capability(pdev, 0x0a); 2318d053c79SJason Wessel if (temp) { 2328d053c79SJason Wessel pci_read_config_dword(pdev, temp, &temp); 2338d053c79SJason Wessel temp >>= 16; 2348d053c79SJason Wessel if ((temp & (3 << 13)) == (1 << 13)) { 2358d053c79SJason Wessel temp &= 0x1fff; 2368d053c79SJason Wessel ehci->debug = ehci_to_hcd(ehci)->regs + temp; 2378d053c79SJason Wessel temp = ehci_readl(ehci, &ehci->debug->control); 2388d053c79SJason Wessel ehci_info(ehci, "debug port %d%s\n", 2398d053c79SJason Wessel HCS_DEBUG_PORT(ehci->hcs_params), 2408d053c79SJason Wessel (temp & DBGP_ENABLED) 2418d053c79SJason Wessel ? " IN USE" 2428d053c79SJason Wessel : ""); 2438d053c79SJason Wessel if (!(temp & DBGP_ENABLED)) 2448d053c79SJason Wessel ehci->debug = NULL; 2458d053c79SJason Wessel } 2468d053c79SJason Wessel } 2478d053c79SJason Wessel 2487ff71d6aSMatt Porter ehci_reset(ehci); 2497ff71d6aSMatt Porter 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 */ 2737ff71d6aSMatt Porter pci_read_config_byte(pdev, 0x60, &ehci->sbrn); 2747ff71d6aSMatt Porter 2756fd9086aSAlan Stern /* Keep this around for a while just in case some EHCI 2766fd9086aSAlan Stern * implementation uses legacy PCI PM support. This test 2776fd9086aSAlan Stern * can be removed on 17 Dec 2009 if the dev_warn() hasn't 2786fd9086aSAlan Stern * been triggered by then. 2792c1c3c4cSDavid Brownell */ 2802c1c3c4cSDavid Brownell if (!device_can_wakeup(&pdev->dev)) { 2812c1c3c4cSDavid Brownell u16 port_wake; 2822c1c3c4cSDavid Brownell 2832c1c3c4cSDavid Brownell pci_read_config_word(pdev, 0x62, &port_wake); 2846fd9086aSAlan Stern if (port_wake & 0x0001) { 2856fd9086aSAlan Stern dev_warn(&pdev->dev, "Enabling legacy PCI PM\n"); 286bcca06efSAlan Stern device_set_wakeup_capable(&pdev->dev, 1); 2872c1c3c4cSDavid Brownell } 2886fd9086aSAlan Stern } 2897ff71d6aSMatt Porter 290f8aeb3bbSDavid Brownell #ifdef CONFIG_USB_SUSPEND 291f8aeb3bbSDavid Brownell /* REVISIT: the controller works fine for wakeup iff the root hub 292f8aeb3bbSDavid Brownell * itself is "globally" suspended, but usbcore currently doesn't 293f8aeb3bbSDavid Brownell * understand such things. 294f8aeb3bbSDavid Brownell * 295f8aeb3bbSDavid Brownell * System suspend currently expects to be able to suspend the entire 296f8aeb3bbSDavid Brownell * device tree, device-at-a-time. If we failed selective suspend 297f8aeb3bbSDavid Brownell * reports, system suspend would fail; so the root hub code must claim 298411c9403SAnand Gadiyar * success. That's lying to usbcore, and it matters for runtime 299f8aeb3bbSDavid Brownell * PM scenarios with selective suspend and remote wakeup... 300f8aeb3bbSDavid Brownell */ 301f8aeb3bbSDavid Brownell if (ehci->no_selective_suspend && device_can_wakeup(&pdev->dev)) 302f8aeb3bbSDavid Brownell ehci_warn(ehci, "selective suspend/wakeup unavailable\n"); 303f8aeb3bbSDavid Brownell #endif 304f8aeb3bbSDavid Brownell 305aff6d18fSAlan Stern ehci_port_power(ehci, 1); 30618807521SDavid Brownell retval = ehci_pci_reinit(ehci, pdev); 3078926bfa7SDavid Brownell done: 3088926bfa7SDavid Brownell return retval; 3097ff71d6aSMatt Porter } 3107ff71d6aSMatt Porter 3117ff71d6aSMatt Porter /*-------------------------------------------------------------------------*/ 3127ff71d6aSMatt Porter 3137ff71d6aSMatt Porter #ifdef CONFIG_PM 3147ff71d6aSMatt Porter 3157ff71d6aSMatt Porter /* suspend/resume, section 4.3 */ 3167ff71d6aSMatt Porter 317f03c17fcSDavid Brownell /* These routines rely on the PCI bus glue 3187ff71d6aSMatt Porter * to handle powerdown and wakeup, and currently also on 3197ff71d6aSMatt Porter * transceivers that don't need any software attention to set up 3207ff71d6aSMatt Porter * the right sort of wakeup. 321f03c17fcSDavid Brownell * Also they depend on separate root hub suspend/resume. 3227ff71d6aSMatt Porter */ 3237ff71d6aSMatt Porter 3244147200dSAlan Stern static int ehci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup) 3257ff71d6aSMatt Porter { 3267ff71d6aSMatt Porter struct ehci_hcd *ehci = hcd_to_ehci(hcd); 3278de98402SBenjamin Herrenschmidt unsigned long flags; 3288de98402SBenjamin Herrenschmidt int rc = 0; 3297ff71d6aSMatt Porter 3307ff71d6aSMatt Porter if (time_before(jiffies, ehci->next_statechange)) 331f03c17fcSDavid Brownell msleep(10); 3327ff71d6aSMatt Porter 3338de98402SBenjamin Herrenschmidt /* Root hub was already suspended. Disable irq emission and 33416032c4fSAlan Stern * mark HW unaccessible. The PM and USB cores make sure that 33516032c4fSAlan Stern * the root hub is either suspended or stopped. 3368de98402SBenjamin Herrenschmidt */ 3374147200dSAlan Stern ehci_prepare_ports_for_controller_suspend(ehci, do_wakeup); 338148fc55fSYin Kangkai spin_lock_irqsave (&ehci->lock, flags); 339083522d7SBenjamin Herrenschmidt ehci_writel(ehci, 0, &ehci->regs->intr_enable); 340083522d7SBenjamin Herrenschmidt (void)ehci_readl(ehci, &ehci->regs->intr_enable); 3418de98402SBenjamin Herrenschmidt 3428de98402SBenjamin Herrenschmidt clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 3438de98402SBenjamin Herrenschmidt spin_unlock_irqrestore (&ehci->lock, flags); 3448de98402SBenjamin Herrenschmidt 345f03c17fcSDavid Brownell // could save FLADJ in case of Vaux power loss 3467ff71d6aSMatt Porter // ... we'd only use it to handle clock skew 3477ff71d6aSMatt Porter 3488de98402SBenjamin Herrenschmidt return rc; 3497ff71d6aSMatt Porter } 3507ff71d6aSMatt Porter 3516ec4beb5SAlan Stern static int ehci_pci_resume(struct usb_hcd *hcd, bool hibernated) 3527ff71d6aSMatt Porter { 3537ff71d6aSMatt Porter struct ehci_hcd *ehci = hcd_to_ehci(hcd); 35418807521SDavid Brownell struct pci_dev *pdev = to_pci_dev(hcd->self.controller); 3557ff71d6aSMatt Porter 356f03c17fcSDavid Brownell // maybe restore FLADJ 3577ff71d6aSMatt Porter 3587ff71d6aSMatt Porter if (time_before(jiffies, ehci->next_statechange)) 3597ff71d6aSMatt Porter msleep(100); 3607ff71d6aSMatt Porter 3618de98402SBenjamin Herrenschmidt /* Mark hardware accessible again as we are out of D3 state by now */ 3628de98402SBenjamin Herrenschmidt set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 3638de98402SBenjamin Herrenschmidt 3646ec4beb5SAlan Stern /* If CF is still set and we aren't resuming from hibernation 3656ec4beb5SAlan Stern * then we maintained PCI Vaux power. 3668c03356aSAlan Stern * Just undo the effect of ehci_pci_suspend(). 3677ff71d6aSMatt Porter */ 3686ec4beb5SAlan Stern if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF && 3696ec4beb5SAlan Stern !hibernated) { 3708c03356aSAlan Stern int mask = INTR_MASK; 3718c03356aSAlan Stern 37216032c4fSAlan Stern ehci_prepare_ports_for_controller_resume(ehci); 37358a97ffeSAlan Stern if (!hcd->self.root_hub->do_remote_wakeup) 3748c03356aSAlan Stern mask &= ~STS_PCD; 375083522d7SBenjamin Herrenschmidt ehci_writel(ehci, mask, &ehci->regs->intr_enable); 376083522d7SBenjamin Herrenschmidt ehci_readl(ehci, &ehci->regs->intr_enable); 377f03c17fcSDavid Brownell return 0; 3787ff71d6aSMatt Porter } 379f03c17fcSDavid Brownell 3801c50c317SAlan Stern usb_root_hub_lost_power(hcd->self.root_hub); 3817ff71d6aSMatt Porter 3827ff71d6aSMatt Porter /* Else reset, to cope with power loss or flush-to-storage 383f03c17fcSDavid Brownell * style "resume" having let BIOS kick in during reboot. 3847ff71d6aSMatt Porter */ 3857ff71d6aSMatt Porter (void) ehci_halt(ehci); 3867ff71d6aSMatt Porter (void) ehci_reset(ehci); 38718807521SDavid Brownell (void) ehci_pci_reinit(ehci, pdev); 3887ff71d6aSMatt Porter 3897ff71d6aSMatt Porter /* emptying the schedule aborts any urbs */ 3907ff71d6aSMatt Porter spin_lock_irq(&ehci->lock); 3917ff71d6aSMatt Porter if (ehci->reclaim) 39207d29b63SAlan Stern end_unlink_async(ehci); 3937d12e780SDavid Howells ehci_work(ehci); 3947ff71d6aSMatt Porter spin_unlock_irq(&ehci->lock); 3957ff71d6aSMatt Porter 396083522d7SBenjamin Herrenschmidt ehci_writel(ehci, ehci->command, &ehci->regs->command); 397083522d7SBenjamin Herrenschmidt ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag); 398083522d7SBenjamin Herrenschmidt ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */ 3998c03356aSAlan Stern 400383975d7SAlan Stern /* here we "know" root ports should always stay powered */ 401383975d7SAlan Stern ehci_port_power(ehci, 1); 402383975d7SAlan Stern 4038c03356aSAlan Stern hcd->state = HC_STATE_SUSPENDED; 4048c03356aSAlan Stern return 0; 4057ff71d6aSMatt Porter } 4067ff71d6aSMatt Porter #endif 4077ff71d6aSMatt Porter 40848f24970SAlek Du static int ehci_update_device(struct usb_hcd *hcd, struct usb_device *udev) 40948f24970SAlek Du { 41048f24970SAlek Du struct ehci_hcd *ehci = hcd_to_ehci(hcd); 41148f24970SAlek Du int rc = 0; 41248f24970SAlek Du 41348f24970SAlek Du if (!udev->parent) /* udev is root hub itself, impossible */ 41448f24970SAlek Du rc = -1; 41548f24970SAlek Du /* we only support lpm device connected to root hub yet */ 41648f24970SAlek Du if (ehci->has_lpm && !udev->parent->parent) { 41748f24970SAlek Du rc = ehci_lpm_set_da(ehci, udev->devnum, udev->portnum); 41848f24970SAlek Du if (!rc) 41948f24970SAlek Du rc = ehci_lpm_check(ehci, udev->portnum); 42048f24970SAlek Du } 42148f24970SAlek Du return rc; 42248f24970SAlek Du } 42348f24970SAlek Du 4247ff71d6aSMatt Porter static const struct hc_driver ehci_pci_hc_driver = { 4257ff71d6aSMatt Porter .description = hcd_name, 4267ff71d6aSMatt Porter .product_desc = "EHCI Host Controller", 4277ff71d6aSMatt Porter .hcd_priv_size = sizeof(struct ehci_hcd), 4287ff71d6aSMatt Porter 4297ff71d6aSMatt Porter /* 4307ff71d6aSMatt Porter * generic hardware linkage 4317ff71d6aSMatt Porter */ 4327ff71d6aSMatt Porter .irq = ehci_irq, 4337ff71d6aSMatt Porter .flags = HCD_MEMORY | HCD_USB2, 4347ff71d6aSMatt Porter 4357ff71d6aSMatt Porter /* 4367ff71d6aSMatt Porter * basic lifecycle operations 4377ff71d6aSMatt Porter */ 4388926bfa7SDavid Brownell .reset = ehci_pci_setup, 43918807521SDavid Brownell .start = ehci_run, 4407ff71d6aSMatt Porter #ifdef CONFIG_PM 4417be7d741SAlan Stern .pci_suspend = ehci_pci_suspend, 4427be7d741SAlan Stern .pci_resume = ehci_pci_resume, 4437ff71d6aSMatt Porter #endif 44418807521SDavid Brownell .stop = ehci_stop, 44564a21d02SAleksey Gorelov .shutdown = ehci_shutdown, 4467ff71d6aSMatt Porter 4477ff71d6aSMatt Porter /* 4487ff71d6aSMatt Porter * managing i/o requests and associated device resources 4497ff71d6aSMatt Porter */ 4507ff71d6aSMatt Porter .urb_enqueue = ehci_urb_enqueue, 4517ff71d6aSMatt Porter .urb_dequeue = ehci_urb_dequeue, 4527ff71d6aSMatt Porter .endpoint_disable = ehci_endpoint_disable, 453b18ffd49SAlan Stern .endpoint_reset = ehci_endpoint_reset, 4547ff71d6aSMatt Porter 4557ff71d6aSMatt Porter /* 4567ff71d6aSMatt Porter * scheduling support 4577ff71d6aSMatt Porter */ 4587ff71d6aSMatt Porter .get_frame_number = ehci_get_frame, 4597ff71d6aSMatt Porter 4607ff71d6aSMatt Porter /* 4617ff71d6aSMatt Porter * root hub support 4627ff71d6aSMatt Porter */ 4637ff71d6aSMatt Porter .hub_status_data = ehci_hub_status_data, 4647ff71d6aSMatt Porter .hub_control = ehci_hub_control, 4650c0382e3SAlan Stern .bus_suspend = ehci_bus_suspend, 4660c0382e3SAlan Stern .bus_resume = ehci_bus_resume, 46790da096eSBalaji Rao .relinquish_port = ehci_relinquish_port, 4683a31155cSAlan Stern .port_handed_over = ehci_port_handed_over, 469914b7012SAlan Stern 47048f24970SAlek Du /* 47148f24970SAlek Du * call back when device connected and addressed 47248f24970SAlek Du */ 47348f24970SAlek Du .update_device = ehci_update_device, 47448f24970SAlek Du 475914b7012SAlan Stern .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, 4767ff71d6aSMatt Porter }; 4777ff71d6aSMatt Porter 4787ff71d6aSMatt Porter /*-------------------------------------------------------------------------*/ 4797ff71d6aSMatt Porter 4807ff71d6aSMatt Porter /* PCI driver selection metadata; PCI hotplugging uses this */ 4817ff71d6aSMatt Porter static const struct pci_device_id pci_ids [] = { { 4827ff71d6aSMatt Porter /* handle any USB 2.0 EHCI controller */ 483c67808eeSJean Delvare PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_EHCI, ~0), 4847ff71d6aSMatt Porter .driver_data = (unsigned long) &ehci_pci_hc_driver, 4857ff71d6aSMatt Porter }, 4867ff71d6aSMatt Porter { /* end: all zeroes */ } 4877ff71d6aSMatt Porter }; 4887ff71d6aSMatt Porter MODULE_DEVICE_TABLE(pci, pci_ids); 4897ff71d6aSMatt Porter 4907ff71d6aSMatt Porter /* pci driver glue; this is a "new style" PCI driver module */ 4917ff71d6aSMatt Porter static struct pci_driver ehci_pci_driver = { 4927ff71d6aSMatt Porter .name = (char *) hcd_name, 4937ff71d6aSMatt Porter .id_table = pci_ids, 4947ff71d6aSMatt Porter 4957ff71d6aSMatt Porter .probe = usb_hcd_pci_probe, 4967ff71d6aSMatt Porter .remove = usb_hcd_pci_remove, 49764a21d02SAleksey Gorelov .shutdown = usb_hcd_pci_shutdown, 498abb30641SAlan Stern 499abb30641SAlan Stern #ifdef CONFIG_PM_SLEEP 500abb30641SAlan Stern .driver = { 501abb30641SAlan Stern .pm = &usb_hcd_pci_pm_ops 502abb30641SAlan Stern }, 503abb30641SAlan Stern #endif 5047ff71d6aSMatt Porter }; 505