pci-quirks.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002
  1. /*
  2. * This file contains code to reset and initialize USB host controllers.
  3. * Some of it includes work-arounds for PCI hardware and BIOS quirks.
  4. * It may need to run early during booting -- before USB would normally
  5. * initialize -- to ensure that Linux doesn't use any legacy modes.
  6. *
  7. * Copyright (c) 1999 Martin Mares <mj@ucw.cz>
  8. * (and others)
  9. */
  10. #include <linux/types.h>
  11. #include <linux/kconfig.h>
  12. #include <linux/kernel.h>
  13. #include <linux/pci.h>
  14. #include <linux/init.h>
  15. #include <linux/delay.h>
  16. #include <linux/export.h>
  17. #include <linux/acpi.h>
  18. #include <linux/dmi.h>
  19. #include "pci-quirks.h"
  20. #include "xhci-ext-caps.h"
  21. #define UHCI_USBLEGSUP 0xc0 /* legacy support */
  22. #define UHCI_USBCMD 0 /* command register */
  23. #define UHCI_USBINTR 4 /* interrupt register */
  24. #define UHCI_USBLEGSUP_RWC 0x8f00 /* the R/WC bits */
  25. #define UHCI_USBLEGSUP_RO 0x5040 /* R/O and reserved bits */
  26. #define UHCI_USBCMD_RUN 0x0001 /* RUN/STOP bit */
  27. #define UHCI_USBCMD_HCRESET 0x0002 /* Host Controller reset */
  28. #define UHCI_USBCMD_EGSM 0x0008 /* Global Suspend Mode */
  29. #define UHCI_USBCMD_CONFIGURE 0x0040 /* Config Flag */
  30. #define UHCI_USBINTR_RESUME 0x0002 /* Resume interrupt enable */
  31. #define OHCI_CONTROL 0x04
  32. #define OHCI_CMDSTATUS 0x08
  33. #define OHCI_INTRSTATUS 0x0c
  34. #define OHCI_INTRENABLE 0x10
  35. #define OHCI_INTRDISABLE 0x14
  36. #define OHCI_FMINTERVAL 0x34
  37. #define OHCI_HCFS (3 << 6) /* hc functional state */
  38. #define OHCI_HCR (1 << 0) /* host controller reset */
  39. #define OHCI_OCR (1 << 3) /* ownership change request */
  40. #define OHCI_CTRL_RWC (1 << 9) /* remote wakeup connected */
  41. #define OHCI_CTRL_IR (1 << 8) /* interrupt routing */
  42. #define OHCI_INTR_OC (1 << 30) /* ownership change */
  43. #define EHCI_HCC_PARAMS 0x08 /* extended capabilities */
  44. #define EHCI_USBCMD 0 /* command register */
  45. #define EHCI_USBCMD_RUN (1 << 0) /* RUN/STOP bit */
  46. #define EHCI_USBSTS 4 /* status register */
  47. #define EHCI_USBSTS_HALTED (1 << 12) /* HCHalted bit */
  48. #define EHCI_USBINTR 8 /* interrupt register */
  49. #define EHCI_CONFIGFLAG 0x40 /* configured flag register */
  50. #define EHCI_USBLEGSUP 0 /* legacy support register */
  51. #define EHCI_USBLEGSUP_BIOS (1 << 16) /* BIOS semaphore */
  52. #define EHCI_USBLEGSUP_OS (1 << 24) /* OS semaphore */
  53. #define EHCI_USBLEGCTLSTS 4 /* legacy control/status */
  54. #define EHCI_USBLEGCTLSTS_SOOE (1 << 13) /* SMI on ownership change */
  55. /* AMD quirk use */
  56. #define AB_REG_BAR_LOW 0xe0
  57. #define AB_REG_BAR_HIGH 0xe1
  58. #define AB_REG_BAR_SB700 0xf0
  59. #define AB_INDX(addr) ((addr) + 0x00)
  60. #define AB_DATA(addr) ((addr) + 0x04)
  61. #define AX_INDXC 0x30
  62. #define AX_DATAC 0x34
  63. #define NB_PCIE_INDX_ADDR 0xe0
  64. #define NB_PCIE_INDX_DATA 0xe4
  65. #define PCIE_P_CNTL 0x10040
  66. #define BIF_NB 0x10002
  67. #define NB_PIF0_PWRDOWN_0 0x01100012
  68. #define NB_PIF0_PWRDOWN_1 0x01100013
  69. #define USB_INTEL_XUSB2PR 0xD0
  70. #define USB_INTEL_USB2PRM 0xD4
  71. #define USB_INTEL_USB3_PSSEN 0xD8
  72. #define USB_INTEL_USB3PRM 0xDC
  73. static struct amd_chipset_info {
  74. struct pci_dev *nb_dev;
  75. struct pci_dev *smbus_dev;
  76. int nb_type;
  77. int sb_type;
  78. int isoc_reqs;
  79. int probe_count;
  80. int probe_result;
  81. } amd_chipset;
  82. static DEFINE_SPINLOCK(amd_lock);
  83. int usb_amd_find_chipset_info(void)
  84. {
  85. u8 rev = 0;
  86. unsigned long flags;
  87. struct amd_chipset_info info;
  88. int ret;
  89. spin_lock_irqsave(&amd_lock, flags);
  90. /* probe only once */
  91. if (amd_chipset.probe_count > 0) {
  92. amd_chipset.probe_count++;
  93. spin_unlock_irqrestore(&amd_lock, flags);
  94. return amd_chipset.probe_result;
  95. }
  96. memset(&info, 0, sizeof(info));
  97. spin_unlock_irqrestore(&amd_lock, flags);
  98. info.smbus_dev = pci_get_device(PCI_VENDOR_ID_ATI, 0x4385, NULL);
  99. if (info.smbus_dev) {
  100. rev = info.smbus_dev->revision;
  101. if (rev >= 0x40)
  102. info.sb_type = 1;
  103. else if (rev >= 0x30 && rev <= 0x3b)
  104. info.sb_type = 3;
  105. } else {
  106. info.smbus_dev = pci_get_device(PCI_VENDOR_ID_AMD,
  107. 0x780b, NULL);
  108. if (!info.smbus_dev) {
  109. ret = 0;
  110. goto commit;
  111. }
  112. rev = info.smbus_dev->revision;
  113. if (rev >= 0x11 && rev <= 0x18)
  114. info.sb_type = 2;
  115. }
  116. if (info.sb_type == 0) {
  117. if (info.smbus_dev) {
  118. pci_dev_put(info.smbus_dev);
  119. info.smbus_dev = NULL;
  120. }
  121. ret = 0;
  122. goto commit;
  123. }
  124. info.nb_dev = pci_get_device(PCI_VENDOR_ID_AMD, 0x9601, NULL);
  125. if (info.nb_dev) {
  126. info.nb_type = 1;
  127. } else {
  128. info.nb_dev = pci_get_device(PCI_VENDOR_ID_AMD, 0x1510, NULL);
  129. if (info.nb_dev) {
  130. info.nb_type = 2;
  131. } else {
  132. info.nb_dev = pci_get_device(PCI_VENDOR_ID_AMD,
  133. 0x9600, NULL);
  134. if (info.nb_dev)
  135. info.nb_type = 3;
  136. }
  137. }
  138. ret = info.probe_result = 1;
  139. printk(KERN_DEBUG "QUIRK: Enable AMD PLL fix\n");
  140. commit:
  141. spin_lock_irqsave(&amd_lock, flags);
  142. if (amd_chipset.probe_count > 0) {
  143. /* race - someone else was faster - drop devices */
  144. /* Mark that we where here */
  145. amd_chipset.probe_count++;
  146. ret = amd_chipset.probe_result;
  147. spin_unlock_irqrestore(&amd_lock, flags);
  148. if (info.nb_dev)
  149. pci_dev_put(info.nb_dev);
  150. if (info.smbus_dev)
  151. pci_dev_put(info.smbus_dev);
  152. } else {
  153. /* no race - commit the result */
  154. info.probe_count++;
  155. amd_chipset = info;
  156. spin_unlock_irqrestore(&amd_lock, flags);
  157. }
  158. return ret;
  159. }
  160. EXPORT_SYMBOL_GPL(usb_amd_find_chipset_info);
  161. /*
  162. * The hardware normally enables the A-link power management feature, which
  163. * lets the system lower the power consumption in idle states.
  164. *
  165. * This USB quirk prevents the link going into that lower power state
  166. * during isochronous transfers.
  167. *
  168. * Without this quirk, isochronous stream on OHCI/EHCI/xHCI controllers of
  169. * some AMD platforms may stutter or have breaks occasionally.
  170. */
  171. static void usb_amd_quirk_pll(int disable)
  172. {
  173. u32 addr, addr_low, addr_high, val;
  174. u32 bit = disable ? 0 : 1;
  175. unsigned long flags;
  176. spin_lock_irqsave(&amd_lock, flags);
  177. if (disable) {
  178. amd_chipset.isoc_reqs++;
  179. if (amd_chipset.isoc_reqs > 1) {
  180. spin_unlock_irqrestore(&amd_lock, flags);
  181. return;
  182. }
  183. } else {
  184. amd_chipset.isoc_reqs--;
  185. if (amd_chipset.isoc_reqs > 0) {
  186. spin_unlock_irqrestore(&amd_lock, flags);
  187. return;
  188. }
  189. }
  190. if (amd_chipset.sb_type == 1 || amd_chipset.sb_type == 2) {
  191. outb_p(AB_REG_BAR_LOW, 0xcd6);
  192. addr_low = inb_p(0xcd7);
  193. outb_p(AB_REG_BAR_HIGH, 0xcd6);
  194. addr_high = inb_p(0xcd7);
  195. addr = addr_high << 8 | addr_low;
  196. outl_p(0x30, AB_INDX(addr));
  197. outl_p(0x40, AB_DATA(addr));
  198. outl_p(0x34, AB_INDX(addr));
  199. val = inl_p(AB_DATA(addr));
  200. } else if (amd_chipset.sb_type == 3) {
  201. pci_read_config_dword(amd_chipset.smbus_dev,
  202. AB_REG_BAR_SB700, &addr);
  203. outl(AX_INDXC, AB_INDX(addr));
  204. outl(0x40, AB_DATA(addr));
  205. outl(AX_DATAC, AB_INDX(addr));
  206. val = inl(AB_DATA(addr));
  207. } else {
  208. spin_unlock_irqrestore(&amd_lock, flags);
  209. return;
  210. }
  211. if (disable) {
  212. val &= ~0x08;
  213. val |= (1 << 4) | (1 << 9);
  214. } else {
  215. val |= 0x08;
  216. val &= ~((1 << 4) | (1 << 9));
  217. }
  218. outl_p(val, AB_DATA(addr));
  219. if (!amd_chipset.nb_dev) {
  220. spin_unlock_irqrestore(&amd_lock, flags);
  221. return;
  222. }
  223. if (amd_chipset.nb_type == 1 || amd_chipset.nb_type == 3) {
  224. addr = PCIE_P_CNTL;
  225. pci_write_config_dword(amd_chipset.nb_dev,
  226. NB_PCIE_INDX_ADDR, addr);
  227. pci_read_config_dword(amd_chipset.nb_dev,
  228. NB_PCIE_INDX_DATA, &val);
  229. val &= ~(1 | (1 << 3) | (1 << 4) | (1 << 9) | (1 << 12));
  230. val |= bit | (bit << 3) | (bit << 12);
  231. val |= ((!bit) << 4) | ((!bit) << 9);
  232. pci_write_config_dword(amd_chipset.nb_dev,
  233. NB_PCIE_INDX_DATA, val);
  234. addr = BIF_NB;
  235. pci_write_config_dword(amd_chipset.nb_dev,
  236. NB_PCIE_INDX_ADDR, addr);
  237. pci_read_config_dword(amd_chipset.nb_dev,
  238. NB_PCIE_INDX_DATA, &val);
  239. val &= ~(1 << 8);
  240. val |= bit << 8;
  241. pci_write_config_dword(amd_chipset.nb_dev,
  242. NB_PCIE_INDX_DATA, val);
  243. } else if (amd_chipset.nb_type == 2) {
  244. addr = NB_PIF0_PWRDOWN_0;
  245. pci_write_config_dword(amd_chipset.nb_dev,
  246. NB_PCIE_INDX_ADDR, addr);
  247. pci_read_config_dword(amd_chipset.nb_dev,
  248. NB_PCIE_INDX_DATA, &val);
  249. if (disable)
  250. val &= ~(0x3f << 7);
  251. else
  252. val |= 0x3f << 7;
  253. pci_write_config_dword(amd_chipset.nb_dev,
  254. NB_PCIE_INDX_DATA, val);
  255. addr = NB_PIF0_PWRDOWN_1;
  256. pci_write_config_dword(amd_chipset.nb_dev,
  257. NB_PCIE_INDX_ADDR, addr);
  258. pci_read_config_dword(amd_chipset.nb_dev,
  259. NB_PCIE_INDX_DATA, &val);
  260. if (disable)
  261. val &= ~(0x3f << 7);
  262. else
  263. val |= 0x3f << 7;
  264. pci_write_config_dword(amd_chipset.nb_dev,
  265. NB_PCIE_INDX_DATA, val);
  266. }
  267. spin_unlock_irqrestore(&amd_lock, flags);
  268. return;
  269. }
  270. void usb_amd_quirk_pll_disable(void)
  271. {
  272. usb_amd_quirk_pll(1);
  273. }
  274. EXPORT_SYMBOL_GPL(usb_amd_quirk_pll_disable);
  275. void usb_amd_quirk_pll_enable(void)
  276. {
  277. usb_amd_quirk_pll(0);
  278. }
  279. EXPORT_SYMBOL_GPL(usb_amd_quirk_pll_enable);
  280. void usb_amd_dev_put(void)
  281. {
  282. struct pci_dev *nb, *smbus;
  283. unsigned long flags;
  284. spin_lock_irqsave(&amd_lock, flags);
  285. amd_chipset.probe_count--;
  286. if (amd_chipset.probe_count > 0) {
  287. spin_unlock_irqrestore(&amd_lock, flags);
  288. return;
  289. }
  290. /* save them to pci_dev_put outside of spinlock */
  291. nb = amd_chipset.nb_dev;
  292. smbus = amd_chipset.smbus_dev;
  293. amd_chipset.nb_dev = NULL;
  294. amd_chipset.smbus_dev = NULL;
  295. amd_chipset.nb_type = 0;
  296. amd_chipset.sb_type = 0;
  297. amd_chipset.isoc_reqs = 0;
  298. amd_chipset.probe_result = 0;
  299. spin_unlock_irqrestore(&amd_lock, flags);
  300. if (nb)
  301. pci_dev_put(nb);
  302. if (smbus)
  303. pci_dev_put(smbus);
  304. }
  305. EXPORT_SYMBOL_GPL(usb_amd_dev_put);
  306. /*
  307. * Make sure the controller is completely inactive, unable to
  308. * generate interrupts or do DMA.
  309. */
  310. void uhci_reset_hc(struct pci_dev *pdev, unsigned long base)
  311. {
  312. /* Turn off PIRQ enable and SMI enable. (This also turns off the
  313. * BIOS's USB Legacy Support.) Turn off all the R/WC bits too.
  314. */
  315. pci_write_config_word(pdev, UHCI_USBLEGSUP, UHCI_USBLEGSUP_RWC);
  316. /* Reset the HC - this will force us to get a
  317. * new notification of any already connected
  318. * ports due to the virtual disconnect that it
  319. * implies.
  320. */
  321. outw(UHCI_USBCMD_HCRESET, base + UHCI_USBCMD);
  322. mb();
  323. udelay(5);
  324. if (inw(base + UHCI_USBCMD) & UHCI_USBCMD_HCRESET)
  325. dev_warn(&pdev->dev, "HCRESET not completed yet!\n");
  326. /* Just to be safe, disable interrupt requests and
  327. * make sure the controller is stopped.
  328. */
  329. outw(0, base + UHCI_USBINTR);
  330. outw(0, base + UHCI_USBCMD);
  331. }
  332. EXPORT_SYMBOL_GPL(uhci_reset_hc);
  333. /*
  334. * Initialize a controller that was newly discovered or has just been
  335. * resumed. In either case we can't be sure of its previous state.
  336. *
  337. * Returns: 1 if the controller was reset, 0 otherwise.
  338. */
  339. int uhci_check_and_reset_hc(struct pci_dev *pdev, unsigned long base)
  340. {
  341. u16 legsup;
  342. unsigned int cmd, intr;
  343. /*
  344. * When restarting a suspended controller, we expect all the
  345. * settings to be the same as we left them:
  346. *
  347. * PIRQ and SMI disabled, no R/W bits set in USBLEGSUP;
  348. * Controller is stopped and configured with EGSM set;
  349. * No interrupts enabled except possibly Resume Detect.
  350. *
  351. * If any of these conditions are violated we do a complete reset.
  352. */
  353. pci_read_config_word(pdev, UHCI_USBLEGSUP, &legsup);
  354. if (legsup & ~(UHCI_USBLEGSUP_RO | UHCI_USBLEGSUP_RWC)) {
  355. dev_dbg(&pdev->dev, "%s: legsup = 0x%04x\n",
  356. __func__, legsup);
  357. goto reset_needed;
  358. }
  359. cmd = inw(base + UHCI_USBCMD);
  360. if ((cmd & UHCI_USBCMD_RUN) || !(cmd & UHCI_USBCMD_CONFIGURE) ||
  361. !(cmd & UHCI_USBCMD_EGSM)) {
  362. dev_dbg(&pdev->dev, "%s: cmd = 0x%04x\n",
  363. __func__, cmd);
  364. goto reset_needed;
  365. }
  366. intr = inw(base + UHCI_USBINTR);
  367. if (intr & (~UHCI_USBINTR_RESUME)) {
  368. dev_dbg(&pdev->dev, "%s: intr = 0x%04x\n",
  369. __func__, intr);
  370. goto reset_needed;
  371. }
  372. return 0;
  373. reset_needed:
  374. dev_dbg(&pdev->dev, "Performing full reset\n");
  375. uhci_reset_hc(pdev, base);
  376. return 1;
  377. }
  378. EXPORT_SYMBOL_GPL(uhci_check_and_reset_hc);
  379. static inline int io_type_enabled(struct pci_dev *pdev, unsigned int mask)
  380. {
  381. u16 cmd;
  382. return !pci_read_config_word(pdev, PCI_COMMAND, &cmd) && (cmd & mask);
  383. }
  384. #define pio_enabled(dev) io_type_enabled(dev, PCI_COMMAND_IO)
  385. #define mmio_enabled(dev) io_type_enabled(dev, PCI_COMMAND_MEMORY)
  386. static void __devinit quirk_usb_handoff_uhci(struct pci_dev *pdev)
  387. {
  388. unsigned long base = 0;
  389. int i;
  390. if (!pio_enabled(pdev))
  391. return;
  392. for (i = 0; i < PCI_ROM_RESOURCE; i++)
  393. if ((pci_resource_flags(pdev, i) & IORESOURCE_IO)) {
  394. base = pci_resource_start(pdev, i);
  395. break;
  396. }
  397. if (base)
  398. uhci_check_and_reset_hc(pdev, base);
  399. }
  400. static int __devinit mmio_resource_enabled(struct pci_dev *pdev, int idx)
  401. {
  402. return pci_resource_start(pdev, idx) && mmio_enabled(pdev);
  403. }
  404. static void __devinit quirk_usb_handoff_ohci(struct pci_dev *pdev)
  405. {
  406. void __iomem *base;
  407. u32 control;
  408. u32 fminterval = 0;
  409. bool no_fminterval = false;
  410. int cnt;
  411. if (!mmio_resource_enabled(pdev, 0))
  412. return;
  413. base = pci_ioremap_bar(pdev, 0);
  414. if (base == NULL)
  415. return;
  416. /*
  417. * ULi M5237 OHCI controller locks the whole system when accessing
  418. * the OHCI_FMINTERVAL offset.
  419. */
  420. if (pdev->vendor == PCI_VENDOR_ID_AL && pdev->device == 0x5237)
  421. no_fminterval = true;
  422. control = readl(base + OHCI_CONTROL);
  423. /* On PA-RISC, PDC can leave IR set incorrectly; ignore it there. */
  424. #ifdef __hppa__
  425. #define OHCI_CTRL_MASK (OHCI_CTRL_RWC | OHCI_CTRL_IR)
  426. #else
  427. #define OHCI_CTRL_MASK OHCI_CTRL_RWC
  428. if (control & OHCI_CTRL_IR) {
  429. int wait_time = 500; /* arbitrary; 5 seconds */
  430. writel(OHCI_INTR_OC, base + OHCI_INTRENABLE);
  431. writel(OHCI_OCR, base + OHCI_CMDSTATUS);
  432. while (wait_time > 0 &&
  433. readl(base + OHCI_CONTROL) & OHCI_CTRL_IR) {
  434. wait_time -= 10;
  435. msleep(10);
  436. }
  437. if (wait_time <= 0)
  438. dev_warn(&pdev->dev, "OHCI: BIOS handoff failed"
  439. " (BIOS bug?) %08x\n",
  440. readl(base + OHCI_CONTROL));
  441. }
  442. #endif
  443. /* disable interrupts */
  444. writel((u32) ~0, base + OHCI_INTRDISABLE);
  445. /* Reset the USB bus, if the controller isn't already in RESET */
  446. if (control & OHCI_HCFS) {
  447. /* Go into RESET, preserving RWC (and possibly IR) */
  448. writel(control & OHCI_CTRL_MASK, base + OHCI_CONTROL);
  449. readl(base + OHCI_CONTROL);
  450. /* drive bus reset for at least 50 ms (7.1.7.5) */
  451. msleep(50);
  452. }
  453. /* software reset of the controller, preserving HcFmInterval */
  454. if (!no_fminterval)
  455. fminterval = readl(base + OHCI_FMINTERVAL);
  456. writel(OHCI_HCR, base + OHCI_CMDSTATUS);
  457. /* reset requires max 10 us delay */
  458. for (cnt = 30; cnt > 0; --cnt) { /* ... allow extra time */
  459. if ((readl(base + OHCI_CMDSTATUS) & OHCI_HCR) == 0)
  460. break;
  461. udelay(1);
  462. }
  463. if (!no_fminterval)
  464. writel(fminterval, base + OHCI_FMINTERVAL);
  465. /* Now the controller is safely in SUSPEND and nothing can wake it up */
  466. iounmap(base);
  467. }
  468. static const struct dmi_system_id __devinitconst ehci_dmi_nohandoff_table[] = {
  469. {
  470. /* Pegatron Lucid (ExoPC) */
  471. .matches = {
  472. DMI_MATCH(DMI_BOARD_NAME, "EXOPG06411"),
  473. DMI_MATCH(DMI_BIOS_VERSION, "Lucid-CE-133"),
  474. },
  475. },
  476. {
  477. /* Pegatron Lucid (Ordissimo AIRIS) */
  478. .matches = {
  479. DMI_MATCH(DMI_BOARD_NAME, "M11JB"),
  480. DMI_MATCH(DMI_BIOS_VERSION, "Lucid-"),
  481. },
  482. },
  483. {
  484. /* Pegatron Lucid (Ordissimo) */
  485. .matches = {
  486. DMI_MATCH(DMI_BOARD_NAME, "Ordissimo"),
  487. DMI_MATCH(DMI_BIOS_VERSION, "Lucid-"),
  488. },
  489. },
  490. {
  491. /* HASEE E200 */
  492. .matches = {
  493. DMI_MATCH(DMI_BOARD_VENDOR, "HASEE"),
  494. DMI_MATCH(DMI_BOARD_NAME, "E210"),
  495. DMI_MATCH(DMI_BIOS_VERSION, "6.00"),
  496. },
  497. },
  498. { }
  499. };
  500. static void __devinit ehci_bios_handoff(struct pci_dev *pdev,
  501. void __iomem *op_reg_base,
  502. u32 cap, u8 offset)
  503. {
  504. int try_handoff = 1, tried_handoff = 0;
  505. /*
  506. * The Pegatron Lucid tablet sporadically waits for 98 seconds trying
  507. * the handoff on its unused controller. Skip it.
  508. *
  509. * The HASEE E200 hangs when the semaphore is set (bugzilla #77021).
  510. */
  511. if (pdev->vendor == 0x8086 && (pdev->device == 0x283a ||
  512. pdev->device == 0x27cc)) {
  513. if (dmi_check_system(ehci_dmi_nohandoff_table))
  514. try_handoff = 0;
  515. }
  516. if (try_handoff && (cap & EHCI_USBLEGSUP_BIOS)) {
  517. dev_dbg(&pdev->dev, "EHCI: BIOS handoff\n");
  518. #if 0
  519. /* aleksey_gorelov@phoenix.com reports that some systems need SMI forced on,
  520. * but that seems dubious in general (the BIOS left it off intentionally)
  521. * and is known to prevent some systems from booting. so we won't do this
  522. * unless maybe we can determine when we're on a system that needs SMI forced.
  523. */
  524. /* BIOS workaround (?): be sure the pre-Linux code
  525. * receives the SMI
  526. */
  527. pci_read_config_dword(pdev, offset + EHCI_USBLEGCTLSTS, &val);
  528. pci_write_config_dword(pdev, offset + EHCI_USBLEGCTLSTS,
  529. val | EHCI_USBLEGCTLSTS_SOOE);
  530. #endif
  531. /* some systems get upset if this semaphore is
  532. * set for any other reason than forcing a BIOS
  533. * handoff..
  534. */
  535. pci_write_config_byte(pdev, offset + 3, 1);
  536. }
  537. /* if boot firmware now owns EHCI, spin till it hands it over. */
  538. if (try_handoff) {
  539. int msec = 1000;
  540. while ((cap & EHCI_USBLEGSUP_BIOS) && (msec > 0)) {
  541. tried_handoff = 1;
  542. msleep(10);
  543. msec -= 10;
  544. pci_read_config_dword(pdev, offset, &cap);
  545. }
  546. }
  547. if (cap & EHCI_USBLEGSUP_BIOS) {
  548. /* well, possibly buggy BIOS... try to shut it down,
  549. * and hope nothing goes too wrong
  550. */
  551. if (try_handoff)
  552. dev_warn(&pdev->dev, "EHCI: BIOS handoff failed"
  553. " (BIOS bug?) %08x\n", cap);
  554. pci_write_config_byte(pdev, offset + 2, 0);
  555. }
  556. /* just in case, always disable EHCI SMIs */
  557. pci_write_config_dword(pdev, offset + EHCI_USBLEGCTLSTS, 0);
  558. /* If the BIOS ever owned the controller then we can't expect
  559. * any power sessions to remain intact.
  560. */
  561. if (tried_handoff)
  562. writel(0, op_reg_base + EHCI_CONFIGFLAG);
  563. }
  564. static void __devinit quirk_usb_disable_ehci(struct pci_dev *pdev)
  565. {
  566. void __iomem *base, *op_reg_base;
  567. u32 hcc_params, cap, val;
  568. u8 offset, cap_length;
  569. int wait_time, count = 256/4;
  570. if (!mmio_resource_enabled(pdev, 0))
  571. return;
  572. base = pci_ioremap_bar(pdev, 0);
  573. if (base == NULL)
  574. return;
  575. cap_length = readb(base);
  576. op_reg_base = base + cap_length;
  577. /* EHCI 0.96 and later may have "extended capabilities"
  578. * spec section 5.1 explains the bios handoff, e.g. for
  579. * booting from USB disk or using a usb keyboard
  580. */
  581. hcc_params = readl(base + EHCI_HCC_PARAMS);
  582. offset = (hcc_params >> 8) & 0xff;
  583. while (offset && --count) {
  584. pci_read_config_dword(pdev, offset, &cap);
  585. switch (cap & 0xff) {
  586. case 1:
  587. ehci_bios_handoff(pdev, op_reg_base, cap, offset);
  588. break;
  589. case 0: /* Illegal reserved cap, set cap=0 so we exit */
  590. cap = 0; /* then fallthrough... */
  591. default:
  592. dev_warn(&pdev->dev, "EHCI: unrecognized capability "
  593. "%02x\n", cap & 0xff);
  594. }
  595. offset = (cap >> 8) & 0xff;
  596. }
  597. if (!count)
  598. dev_printk(KERN_DEBUG, &pdev->dev, "EHCI: capability loop?\n");
  599. /*
  600. * halt EHCI & disable its interrupts in any case
  601. */
  602. val = readl(op_reg_base + EHCI_USBSTS);
  603. if ((val & EHCI_USBSTS_HALTED) == 0) {
  604. val = readl(op_reg_base + EHCI_USBCMD);
  605. val &= ~EHCI_USBCMD_RUN;
  606. writel(val, op_reg_base + EHCI_USBCMD);
  607. wait_time = 2000;
  608. do {
  609. writel(0x3f, op_reg_base + EHCI_USBSTS);
  610. udelay(100);
  611. wait_time -= 100;
  612. val = readl(op_reg_base + EHCI_USBSTS);
  613. if ((val == ~(u32)0) || (val & EHCI_USBSTS_HALTED)) {
  614. break;
  615. }
  616. } while (wait_time > 0);
  617. }
  618. writel(0, op_reg_base + EHCI_USBINTR);
  619. writel(0x3f, op_reg_base + EHCI_USBSTS);
  620. iounmap(base);
  621. }
  622. /*
  623. * handshake - spin reading a register until handshake completes
  624. * @ptr: address of hc register to be read
  625. * @mask: bits to look at in result of read
  626. * @done: value of those bits when handshake succeeds
  627. * @wait_usec: timeout in microseconds
  628. * @delay_usec: delay in microseconds to wait between polling
  629. *
  630. * Polls a register every delay_usec microseconds.
  631. * Returns 0 when the mask bits have the value done.
  632. * Returns -ETIMEDOUT if this condition is not true after
  633. * wait_usec microseconds have passed.
  634. */
  635. static int handshake(void __iomem *ptr, u32 mask, u32 done,
  636. int wait_usec, int delay_usec)
  637. {
  638. u32 result;
  639. do {
  640. result = readl(ptr);
  641. result &= mask;
  642. if (result == done)
  643. return 0;
  644. udelay(delay_usec);
  645. wait_usec -= delay_usec;
  646. } while (wait_usec > 0);
  647. return -ETIMEDOUT;
  648. }
  649. #define PCI_DEVICE_ID_INTEL_LYNX_POINT_XHCI 0x8C31
  650. #define PCI_DEVICE_ID_INTEL_LYNX_POINT_LP_XHCI 0x9C31
  651. bool usb_is_intel_ppt_switchable_xhci(struct pci_dev *pdev)
  652. {
  653. return pdev->class == PCI_CLASS_SERIAL_USB_XHCI &&
  654. pdev->vendor == PCI_VENDOR_ID_INTEL &&
  655. pdev->device == PCI_DEVICE_ID_INTEL_PANTHERPOINT_XHCI;
  656. }
  657. /* The Intel Lynx Point chipset also has switchable ports. */
  658. bool usb_is_intel_lpt_switchable_xhci(struct pci_dev *pdev)
  659. {
  660. return pdev->class == PCI_CLASS_SERIAL_USB_XHCI &&
  661. pdev->vendor == PCI_VENDOR_ID_INTEL &&
  662. (pdev->device == PCI_DEVICE_ID_INTEL_LYNX_POINT_XHCI ||
  663. pdev->device == PCI_DEVICE_ID_INTEL_LYNX_POINT_LP_XHCI);
  664. }
  665. bool usb_is_intel_switchable_xhci(struct pci_dev *pdev)
  666. {
  667. return usb_is_intel_ppt_switchable_xhci(pdev) ||
  668. usb_is_intel_lpt_switchable_xhci(pdev);
  669. }
  670. EXPORT_SYMBOL_GPL(usb_is_intel_switchable_xhci);
  671. /*
  672. * Intel's Panther Point chipset has two host controllers (EHCI and xHCI) that
  673. * share some number of ports. These ports can be switched between either
  674. * controller. Not all of the ports under the EHCI host controller may be
  675. * switchable.
  676. *
  677. * The ports should be switched over to xHCI before PCI probes for any device
  678. * start. This avoids active devices under EHCI being disconnected during the
  679. * port switchover, which could cause loss of data on USB storage devices, or
  680. * failed boot when the root file system is on a USB mass storage device and is
  681. * enumerated under EHCI first.
  682. *
  683. * We write into the xHC's PCI configuration space in some Intel-specific
  684. * registers to switch the ports over. The USB 3.0 terminations and the USB
  685. * 2.0 data wires are switched separately. We want to enable the SuperSpeed
  686. * terminations before switching the USB 2.0 wires over, so that USB 3.0
  687. * devices connect at SuperSpeed, rather than at USB 2.0 speeds.
  688. */
  689. void usb_enable_xhci_ports(struct pci_dev *xhci_pdev)
  690. {
  691. u32 ports_available;
  692. /* Don't switchover the ports if the user hasn't compiled the xHCI
  693. * driver. Otherwise they will see "dead" USB ports that don't power
  694. * the devices.
  695. */
  696. if (!IS_ENABLED(CONFIG_USB_XHCI_HCD)) {
  697. dev_warn(&xhci_pdev->dev,
  698. "CONFIG_USB_XHCI_HCD is turned off, "
  699. "defaulting to EHCI.\n");
  700. dev_warn(&xhci_pdev->dev,
  701. "USB 3.0 devices will work at USB 2.0 speeds.\n");
  702. usb_disable_xhci_ports(xhci_pdev);
  703. return;
  704. }
  705. /* Read USB3PRM, the USB 3.0 Port Routing Mask Register
  706. * Indicate the ports that can be changed from OS.
  707. */
  708. pci_read_config_dword(xhci_pdev, USB_INTEL_USB3PRM,
  709. &ports_available);
  710. dev_dbg(&xhci_pdev->dev, "Configurable ports to enable SuperSpeed: 0x%x\n",
  711. ports_available);
  712. /* Write USB3_PSSEN, the USB 3.0 Port SuperSpeed Enable
  713. * Register, to turn on SuperSpeed terminations for the
  714. * switchable ports.
  715. */
  716. pci_write_config_dword(xhci_pdev, USB_INTEL_USB3_PSSEN,
  717. cpu_to_le32(ports_available));
  718. pci_read_config_dword(xhci_pdev, USB_INTEL_USB3_PSSEN,
  719. &ports_available);
  720. dev_dbg(&xhci_pdev->dev, "USB 3.0 ports that are now enabled "
  721. "under xHCI: 0x%x\n", ports_available);
  722. /* Read XUSB2PRM, xHCI USB 2.0 Port Routing Mask Register
  723. * Indicate the USB 2.0 ports to be controlled by the xHCI host.
  724. */
  725. pci_read_config_dword(xhci_pdev, USB_INTEL_USB2PRM,
  726. &ports_available);
  727. dev_dbg(&xhci_pdev->dev, "Configurable USB 2.0 ports to hand over to xCHI: 0x%x\n",
  728. ports_available);
  729. /* Write XUSB2PR, the xHC USB 2.0 Port Routing Register, to
  730. * switch the USB 2.0 power and data lines over to the xHCI
  731. * host.
  732. */
  733. pci_write_config_dword(xhci_pdev, USB_INTEL_XUSB2PR,
  734. cpu_to_le32(ports_available));
  735. pci_read_config_dword(xhci_pdev, USB_INTEL_XUSB2PR,
  736. &ports_available);
  737. dev_dbg(&xhci_pdev->dev, "USB 2.0 ports that are now switched over "
  738. "to xHCI: 0x%x\n", ports_available);
  739. }
  740. EXPORT_SYMBOL_GPL(usb_enable_xhci_ports);
  741. void usb_disable_xhci_ports(struct pci_dev *xhci_pdev)
  742. {
  743. pci_write_config_dword(xhci_pdev, USB_INTEL_USB3_PSSEN, 0x0);
  744. pci_write_config_dword(xhci_pdev, USB_INTEL_XUSB2PR, 0x0);
  745. }
  746. EXPORT_SYMBOL_GPL(usb_disable_xhci_ports);
  747. /**
  748. * PCI Quirks for xHCI.
  749. *
  750. * Takes care of the handoff between the Pre-OS (i.e. BIOS) and the OS.
  751. * It signals to the BIOS that the OS wants control of the host controller,
  752. * and then waits 5 seconds for the BIOS to hand over control.
  753. * If we timeout, assume the BIOS is broken and take control anyway.
  754. */
  755. static void __devinit quirk_usb_handoff_xhci(struct pci_dev *pdev)
  756. {
  757. void __iomem *base;
  758. int ext_cap_offset;
  759. void __iomem *op_reg_base;
  760. u32 val;
  761. int timeout;
  762. int len = pci_resource_len(pdev, 0);
  763. if (!mmio_resource_enabled(pdev, 0))
  764. return;
  765. base = ioremap_nocache(pci_resource_start(pdev, 0), len);
  766. if (base == NULL)
  767. return;
  768. /*
  769. * Find the Legacy Support Capability register -
  770. * this is optional for xHCI host controllers.
  771. */
  772. ext_cap_offset = xhci_find_next_cap_offset(base, XHCI_HCC_PARAMS_OFFSET);
  773. do {
  774. if ((ext_cap_offset + sizeof(val)) > len) {
  775. /* We're reading garbage from the controller */
  776. dev_warn(&pdev->dev,
  777. "xHCI controller failing to respond");
  778. return;
  779. }
  780. if (!ext_cap_offset)
  781. /* We've reached the end of the extended capabilities */
  782. goto hc_init;
  783. val = readl(base + ext_cap_offset);
  784. if (XHCI_EXT_CAPS_ID(val) == XHCI_EXT_CAPS_LEGACY)
  785. break;
  786. ext_cap_offset = xhci_find_next_cap_offset(base, ext_cap_offset);
  787. } while (1);
  788. /* If the BIOS owns the HC, signal that the OS wants it, and wait */
  789. if (val & XHCI_HC_BIOS_OWNED) {
  790. writel(val | XHCI_HC_OS_OWNED, base + ext_cap_offset);
  791. /* Wait for 5 seconds with 10 microsecond polling interval */
  792. timeout = handshake(base + ext_cap_offset, XHCI_HC_BIOS_OWNED,
  793. 0, 5000, 10);
  794. /* Assume a buggy BIOS and take HC ownership anyway */
  795. if (timeout) {
  796. dev_warn(&pdev->dev, "xHCI BIOS handoff failed"
  797. " (BIOS bug ?) %08x\n", val);
  798. writel(val & ~XHCI_HC_BIOS_OWNED, base + ext_cap_offset);
  799. }
  800. }
  801. val = readl(base + ext_cap_offset + XHCI_LEGACY_CONTROL_OFFSET);
  802. /* Mask off (turn off) any enabled SMIs */
  803. val &= XHCI_LEGACY_DISABLE_SMI;
  804. /* Mask all SMI events bits, RW1C */
  805. val |= XHCI_LEGACY_SMI_EVENTS;
  806. /* Disable any BIOS SMIs and clear all SMI events*/
  807. writel(val, base + ext_cap_offset + XHCI_LEGACY_CONTROL_OFFSET);
  808. hc_init:
  809. if (usb_is_intel_switchable_xhci(pdev))
  810. usb_enable_xhci_ports(pdev);
  811. op_reg_base = base + XHCI_HC_LENGTH(readl(base));
  812. /* Wait for the host controller to be ready before writing any
  813. * operational or runtime registers. Wait 5 seconds and no more.
  814. */
  815. timeout = handshake(op_reg_base + XHCI_STS_OFFSET, XHCI_STS_CNR, 0,
  816. 5000, 10);
  817. /* Assume a buggy HC and start HC initialization anyway */
  818. if (timeout) {
  819. val = readl(op_reg_base + XHCI_STS_OFFSET);
  820. dev_warn(&pdev->dev,
  821. "xHCI HW not ready after 5 sec (HC bug?) "
  822. "status = 0x%x\n", val);
  823. }
  824. /* Send the halt and disable interrupts command */
  825. val = readl(op_reg_base + XHCI_CMD_OFFSET);
  826. val &= ~(XHCI_CMD_RUN | XHCI_IRQS);
  827. writel(val, op_reg_base + XHCI_CMD_OFFSET);
  828. /* Wait for the HC to halt - poll every 125 usec (one microframe). */
  829. timeout = handshake(op_reg_base + XHCI_STS_OFFSET, XHCI_STS_HALT, 1,
  830. XHCI_MAX_HALT_USEC, 125);
  831. if (timeout) {
  832. val = readl(op_reg_base + XHCI_STS_OFFSET);
  833. dev_warn(&pdev->dev,
  834. "xHCI HW did not halt within %d usec "
  835. "status = 0x%x\n", XHCI_MAX_HALT_USEC, val);
  836. }
  837. iounmap(base);
  838. }
  839. static void __devinit quirk_usb_early_handoff(struct pci_dev *pdev)
  840. {
  841. /* Skip Netlogic mips SoC's internal PCI USB controller.
  842. * This device does not need/support EHCI/OHCI handoff
  843. */
  844. if (pdev->vendor == 0x184e) /* vendor Netlogic */
  845. return;
  846. if (pdev->class != PCI_CLASS_SERIAL_USB_UHCI &&
  847. pdev->class != PCI_CLASS_SERIAL_USB_OHCI &&
  848. pdev->class != PCI_CLASS_SERIAL_USB_EHCI &&
  849. pdev->class != PCI_CLASS_SERIAL_USB_XHCI)
  850. return;
  851. if (pci_enable_device(pdev) < 0) {
  852. dev_warn(&pdev->dev, "Can't enable PCI device, "
  853. "BIOS handoff failed.\n");
  854. return;
  855. }
  856. if (pdev->class == PCI_CLASS_SERIAL_USB_UHCI)
  857. quirk_usb_handoff_uhci(pdev);
  858. else if (pdev->class == PCI_CLASS_SERIAL_USB_OHCI)
  859. quirk_usb_handoff_ohci(pdev);
  860. else if (pdev->class == PCI_CLASS_SERIAL_USB_EHCI)
  861. quirk_usb_disable_ehci(pdev);
  862. else if (pdev->class == PCI_CLASS_SERIAL_USB_XHCI)
  863. quirk_usb_handoff_xhci(pdev);
  864. pci_disable_device(pdev);
  865. }
  866. DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_ANY_ID, PCI_ANY_ID,
  867. PCI_CLASS_SERIAL_USB, 8, quirk_usb_early_handoff);