pci-quirks.c 32 KB

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