0001
0002
0003
0004
0005
0006
0007
0008 #include <linux/kernel.h>
0009 #include <linux/module.h>
0010 #include <linux/pci.h>
0011 #include <linux/usb.h>
0012 #include <linux/usb/hcd.h>
0013
0014 #include "ehci.h"
0015 #include "pci-quirks.h"
0016
0017 #define DRIVER_DESC "EHCI PCI platform driver"
0018
0019 static const char hcd_name[] = "ehci-pci";
0020
0021
0022 #define PCI_DEVICE_ID_INTEL_CE4100_USB 0x2e70
0023
0024 #define PCI_VENDOR_ID_ASPEED 0x1a03
0025 #define PCI_DEVICE_ID_ASPEED_EHCI 0x2603
0026
0027
0028 #define PCI_DEVICE_ID_INTEL_QUARK_X1000_SOC 0x0939
0029 static inline bool is_intel_quark_x1000(struct pci_dev *pdev)
0030 {
0031 return pdev->vendor == PCI_VENDOR_ID_INTEL &&
0032 pdev->device == PCI_DEVICE_ID_INTEL_QUARK_X1000_SOC;
0033 }
0034
0035
0036
0037
0038
0039
0040 static const struct pci_device_id bypass_pci_id_table[] = {
0041
0042 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0811), },
0043 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0829), },
0044 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0xe006), },
0045 {}
0046 };
0047
0048 static inline bool is_bypassed_id(struct pci_dev *pdev)
0049 {
0050 return !!pci_match_id(bypass_pci_id_table, pdev);
0051 }
0052
0053
0054
0055
0056
0057 #define intel_quark_x1000_insnreg01 hostpc
0058
0059
0060 #define INTEL_QUARK_X1000_EHCI_MAX_THRESHOLD 0x007f007f
0061
0062
0063 static int ehci_pci_reinit(struct ehci_hcd *ehci, struct pci_dev *pdev)
0064 {
0065 int retval;
0066
0067
0068
0069
0070
0071
0072 retval = pci_set_mwi(pdev);
0073 if (!retval)
0074 ehci_dbg(ehci, "MWI active\n");
0075
0076
0077 if (is_intel_quark_x1000(pdev)) {
0078
0079
0080
0081
0082 ehci_writel(ehci, INTEL_QUARK_X1000_EHCI_MAX_THRESHOLD,
0083 ehci->regs->intel_quark_x1000_insnreg01);
0084 }
0085
0086 return 0;
0087 }
0088
0089
0090 static int ehci_pci_setup(struct usb_hcd *hcd)
0091 {
0092 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
0093 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
0094 u32 temp;
0095 int retval;
0096
0097 ehci->caps = hcd->regs;
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108 switch (pdev->vendor) {
0109 case PCI_VENDOR_ID_TOSHIBA_2:
0110
0111 if (pdev->device == 0x01b5) {
0112 #ifdef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO
0113 ehci->big_endian_mmio = 1;
0114 #else
0115 ehci_warn(ehci,
0116 "unsupported big endian Toshiba quirk\n");
0117 #endif
0118 }
0119 break;
0120 case PCI_VENDOR_ID_NVIDIA:
0121
0122
0123
0124
0125 switch (pdev->device) {
0126 case 0x003c:
0127 case 0x005b:
0128 case 0x00d8:
0129 case 0x00e8:
0130 if (dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(31)) < 0)
0131 ehci_warn(ehci, "can't enable NVidia "
0132 "workaround for >2GB RAM\n");
0133 break;
0134
0135
0136
0137
0138 case 0x0068:
0139 if (pdev->revision < 0xa4)
0140 ehci->no_selective_suspend = 1;
0141 break;
0142 }
0143 break;
0144 case PCI_VENDOR_ID_INTEL:
0145 if (pdev->device == PCI_DEVICE_ID_INTEL_CE4100_USB)
0146 hcd->has_tt = 1;
0147 break;
0148 case PCI_VENDOR_ID_TDI:
0149 if (pdev->device == PCI_DEVICE_ID_TDI_EHCI)
0150 hcd->has_tt = 1;
0151 break;
0152 case PCI_VENDOR_ID_AMD:
0153
0154 if (usb_amd_quirk_pll_check())
0155 ehci->amd_pll_fix = 1;
0156
0157 if (pdev->device == 0x7463) {
0158 ehci_info(ehci, "ignoring AMD8111 (errata)\n");
0159 retval = -EIO;
0160 goto done;
0161 }
0162
0163
0164
0165
0166
0167
0168
0169
0170 if (pdev->device == 0x7808) {
0171 ehci->use_dummy_qh = 1;
0172 ehci_info(ehci, "applying AMD SB700/SB800/Hudson-2/3 EHCI dummy qh workaround\n");
0173 }
0174 break;
0175 case PCI_VENDOR_ID_VIA:
0176 if (pdev->device == 0x3104 && (pdev->revision & 0xf0) == 0x60) {
0177 u8 tmp;
0178
0179
0180
0181
0182
0183 pci_read_config_byte(pdev, 0x4b, &tmp);
0184 if (tmp & 0x20)
0185 break;
0186 pci_write_config_byte(pdev, 0x4b, tmp | 0x20);
0187 }
0188 break;
0189 case PCI_VENDOR_ID_ATI:
0190
0191 if (usb_amd_quirk_pll_check())
0192 ehci->amd_pll_fix = 1;
0193
0194
0195
0196
0197
0198
0199
0200
0201 if (pdev->device == 0x4396) {
0202 ehci->use_dummy_qh = 1;
0203 ehci_info(ehci, "applying AMD SB700/SB800/Hudson-2/3 EHCI dummy qh workaround\n");
0204 }
0205
0206
0207
0208 if ((pdev->device == 0x4386 || pdev->device == 0x4396) &&
0209 usb_amd_hang_symptom_quirk()) {
0210 u8 tmp;
0211 ehci_info(ehci, "applying AMD SB600/SB700 USB freeze workaround\n");
0212 pci_read_config_byte(pdev, 0x53, &tmp);
0213 pci_write_config_byte(pdev, 0x53, tmp | (1<<3));
0214 }
0215 break;
0216 case PCI_VENDOR_ID_NETMOS:
0217
0218 ehci_info(ehci, "applying MosChip frame-index workaround\n");
0219 ehci->frame_index_bug = 1;
0220 break;
0221 case PCI_VENDOR_ID_HUAWEI:
0222
0223 if (pdev->device == 0xa239) {
0224 ehci_info(ehci, "applying Synopsys HC workaround\n");
0225 ehci->has_synopsys_hc_bug = 1;
0226 }
0227 break;
0228 case PCI_VENDOR_ID_ASPEED:
0229 if (pdev->device == PCI_DEVICE_ID_ASPEED_EHCI) {
0230 ehci_info(ehci, "applying Aspeed HC workaround\n");
0231 ehci->is_aspeed = 1;
0232 }
0233 break;
0234 case PCI_VENDOR_ID_ZHAOXIN:
0235 if (pdev->device == 0x3104 && (pdev->revision & 0xf0) == 0x90)
0236 ehci->zx_wakeup_clear_needed = 1;
0237 break;
0238 }
0239
0240
0241 temp = pci_find_capability(pdev, PCI_CAP_ID_DBG);
0242 if (temp) {
0243 pci_read_config_dword(pdev, temp, &temp);
0244 temp >>= 16;
0245 if (((temp >> 13) & 7) == 1) {
0246 u32 hcs_params = ehci_readl(ehci,
0247 &ehci->caps->hcs_params);
0248
0249 temp &= 0x1fff;
0250 ehci->debug = hcd->regs + temp;
0251 temp = ehci_readl(ehci, &ehci->debug->control);
0252 ehci_info(ehci, "debug port %d%s\n",
0253 HCS_DEBUG_PORT(hcs_params),
0254 (temp & DBGP_ENABLED) ? " IN USE" : "");
0255 if (!(temp & DBGP_ENABLED))
0256 ehci->debug = NULL;
0257 }
0258 }
0259
0260 retval = ehci_setup(hcd);
0261 if (retval)
0262 return retval;
0263
0264
0265 switch (pdev->vendor) {
0266 case PCI_VENDOR_ID_NEC:
0267 case PCI_VENDOR_ID_INTEL:
0268 case PCI_VENDOR_ID_AMD:
0269 ehci->need_io_watchdog = 0;
0270 break;
0271 case PCI_VENDOR_ID_NVIDIA:
0272 switch (pdev->device) {
0273
0274
0275
0276
0277
0278 case 0x0d9d:
0279 ehci_info(ehci, "disable ppcd for nvidia mcp89\n");
0280 ehci->has_ppcd = 0;
0281 ehci->command &= ~CMD_PPCEE;
0282 break;
0283 }
0284 break;
0285 }
0286
0287
0288 temp = HCS_N_CC(ehci->hcs_params) * HCS_N_PCC(ehci->hcs_params);
0289 temp &= 0x0f;
0290 if (temp && HCS_N_PORTS(ehci->hcs_params) > temp) {
0291 ehci_dbg(ehci, "bogus port configuration: "
0292 "cc=%d x pcc=%d < ports=%d\n",
0293 HCS_N_CC(ehci->hcs_params),
0294 HCS_N_PCC(ehci->hcs_params),
0295 HCS_N_PORTS(ehci->hcs_params));
0296
0297 switch (pdev->vendor) {
0298 case 0x17a0:
0299
0300 temp |= (ehci->hcs_params & ~0xf);
0301 ehci->hcs_params = temp;
0302 break;
0303 case PCI_VENDOR_ID_NVIDIA:
0304
0305 break;
0306 }
0307 }
0308
0309
0310 if (pdev->vendor == PCI_VENDOR_ID_STMICRO
0311 && pdev->device == PCI_DEVICE_ID_STMICRO_USB_HOST)
0312 ;
0313 else if (pdev->vendor == PCI_VENDOR_ID_HUAWEI
0314 && pdev->device == 0xa239)
0315 ;
0316 else
0317 pci_read_config_byte(pdev, 0x60, &ehci->sbrn);
0318
0319
0320
0321
0322
0323
0324 if (!device_can_wakeup(&pdev->dev)) {
0325 u16 port_wake;
0326
0327 pci_read_config_word(pdev, 0x62, &port_wake);
0328 if (port_wake & 0x0001) {
0329 dev_warn(&pdev->dev, "Enabling legacy PCI PM\n");
0330 device_set_wakeup_capable(&pdev->dev, 1);
0331 }
0332 }
0333
0334 #ifdef CONFIG_PM
0335 if (ehci->no_selective_suspend && device_can_wakeup(&pdev->dev))
0336 ehci_warn(ehci, "selective suspend/wakeup unavailable\n");
0337 #endif
0338
0339 retval = ehci_pci_reinit(ehci, pdev);
0340 done:
0341 return retval;
0342 }
0343
0344
0345
0346 #ifdef CONFIG_PM
0347
0348
0349
0350
0351
0352
0353
0354
0355
0356
0357 static int ehci_pci_resume(struct usb_hcd *hcd, bool hibernated)
0358 {
0359 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
0360 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
0361
0362 if (ehci_resume(hcd, hibernated) != 0)
0363 (void) ehci_pci_reinit(ehci, pdev);
0364 return 0;
0365 }
0366
0367 #else
0368
0369 #define ehci_suspend NULL
0370 #define ehci_pci_resume NULL
0371 #endif
0372
0373 static struct hc_driver __read_mostly ehci_pci_hc_driver;
0374
0375 static const struct ehci_driver_overrides pci_overrides __initconst = {
0376 .reset = ehci_pci_setup,
0377 };
0378
0379
0380
0381 static int ehci_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
0382 {
0383 if (is_bypassed_id(pdev))
0384 return -ENODEV;
0385 return usb_hcd_pci_probe(pdev, id, &ehci_pci_hc_driver);
0386 }
0387
0388 static void ehci_pci_remove(struct pci_dev *pdev)
0389 {
0390 pci_clear_mwi(pdev);
0391 usb_hcd_pci_remove(pdev);
0392 }
0393
0394
0395 static const struct pci_device_id pci_ids [] = { {
0396
0397 PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_EHCI, ~0),
0398 }, {
0399 PCI_VDEVICE(STMICRO, PCI_DEVICE_ID_STMICRO_USB_HOST),
0400 },
0401 { }
0402 };
0403 MODULE_DEVICE_TABLE(pci, pci_ids);
0404
0405
0406 static struct pci_driver ehci_pci_driver = {
0407 .name = hcd_name,
0408 .id_table = pci_ids,
0409
0410 .probe = ehci_pci_probe,
0411 .remove = ehci_pci_remove,
0412 .shutdown = usb_hcd_pci_shutdown,
0413
0414 #ifdef CONFIG_PM
0415 .driver = {
0416 .pm = &usb_hcd_pci_pm_ops
0417 },
0418 #endif
0419 };
0420
0421 static int __init ehci_pci_init(void)
0422 {
0423 if (usb_disabled())
0424 return -ENODEV;
0425
0426 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
0427
0428 ehci_init_driver(&ehci_pci_hc_driver, &pci_overrides);
0429
0430
0431 ehci_pci_hc_driver.pci_suspend = ehci_suspend;
0432 ehci_pci_hc_driver.pci_resume = ehci_pci_resume;
0433
0434 return pci_register_driver(&ehci_pci_driver);
0435 }
0436 module_init(ehci_pci_init);
0437
0438 static void __exit ehci_pci_cleanup(void)
0439 {
0440 pci_unregister_driver(&ehci_pci_driver);
0441 }
0442 module_exit(ehci_pci_cleanup);
0443
0444 MODULE_DESCRIPTION(DRIVER_DESC);
0445 MODULE_AUTHOR("David Brownell");
0446 MODULE_AUTHOR("Alan Stern");
0447 MODULE_LICENSE("GPL");