ohci-pci.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. /*
  2. * OHCI HCD (Host Controller Driver) for USB.
  3. *
  4. * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
  5. * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
  6. *
  7. * [ Initialisation is based on Linus' ]
  8. * [ uhci code and gregs ohci fragments ]
  9. * [ (C) Copyright 1999 Linus Torvalds ]
  10. * [ (C) Copyright 1999 Gregory P. Smith]
  11. *
  12. * PCI Bus Glue
  13. *
  14. * This file is licenced under the GPL.
  15. */
  16. #ifndef CONFIG_PCI
  17. #error "This file is PCI bus glue. CONFIG_PCI must be defined."
  18. #endif
  19. #include <linux/pci.h>
  20. #include <linux/io.h>
  21. /* constants used to work around PM-related transfer
  22. * glitches in some AMD 700 series southbridges
  23. */
  24. #define AB_REG_BAR 0xf0
  25. #define AB_INDX(addr) ((addr) + 0x00)
  26. #define AB_DATA(addr) ((addr) + 0x04)
  27. #define AX_INDXC 0X30
  28. #define AX_DATAC 0x34
  29. #define NB_PCIE_INDX_ADDR 0xe0
  30. #define NB_PCIE_INDX_DATA 0xe4
  31. #define PCIE_P_CNTL 0x10040
  32. #define BIF_NB 0x10002
  33. static struct pci_dev *amd_smbus_dev;
  34. static struct pci_dev *amd_hb_dev;
  35. static int amd_ohci_iso_count;
  36. /*-------------------------------------------------------------------------*/
  37. static int broken_suspend(struct usb_hcd *hcd)
  38. {
  39. device_init_wakeup(&hcd->self.root_hub->dev, 0);
  40. return 0;
  41. }
  42. /* AMD 756, for most chips (early revs), corrupts register
  43. * values on read ... so enable the vendor workaround.
  44. */
  45. static int ohci_quirk_amd756(struct usb_hcd *hcd)
  46. {
  47. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  48. ohci->flags = OHCI_QUIRK_AMD756;
  49. ohci_dbg (ohci, "AMD756 erratum 4 workaround\n");
  50. /* also erratum 10 (suspend/resume issues) */
  51. return broken_suspend(hcd);
  52. }
  53. /* Apple's OHCI driver has a lot of bizarre workarounds
  54. * for this chip. Evidently control and bulk lists
  55. * can get confused. (B&W G3 models, and ...)
  56. */
  57. static int ohci_quirk_opti(struct usb_hcd *hcd)
  58. {
  59. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  60. ohci_dbg (ohci, "WARNING: OPTi workarounds unavailable\n");
  61. return 0;
  62. }
  63. /* Check for NSC87560. We have to look at the bridge (fn1) to
  64. * identify the USB (fn2). This quirk might apply to more or
  65. * even all NSC stuff.
  66. */
  67. static int ohci_quirk_ns(struct usb_hcd *hcd)
  68. {
  69. struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
  70. struct pci_dev *b;
  71. b = pci_get_slot (pdev->bus, PCI_DEVFN (PCI_SLOT (pdev->devfn), 1));
  72. if (b && b->device == PCI_DEVICE_ID_NS_87560_LIO
  73. && b->vendor == PCI_VENDOR_ID_NS) {
  74. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  75. ohci->flags |= OHCI_QUIRK_SUPERIO;
  76. ohci_dbg (ohci, "Using NSC SuperIO setup\n");
  77. }
  78. pci_dev_put(b);
  79. return 0;
  80. }
  81. /* Check for Compaq's ZFMicro chipset, which needs short
  82. * delays before control or bulk queues get re-activated
  83. * in finish_unlinks()
  84. */
  85. static int ohci_quirk_zfmicro(struct usb_hcd *hcd)
  86. {
  87. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  88. ohci->flags |= OHCI_QUIRK_ZFMICRO;
  89. ohci_dbg(ohci, "enabled Compaq ZFMicro chipset quirks\n");
  90. return 0;
  91. }
  92. /* Check for Toshiba SCC OHCI which has big endian registers
  93. * and little endian in memory data structures
  94. */
  95. static int ohci_quirk_toshiba_scc(struct usb_hcd *hcd)
  96. {
  97. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  98. /* That chip is only present in the southbridge of some
  99. * cell based platforms which are supposed to select
  100. * CONFIG_USB_OHCI_BIG_ENDIAN_MMIO. We verify here if
  101. * that was the case though.
  102. */
  103. #ifdef CONFIG_USB_OHCI_BIG_ENDIAN_MMIO
  104. ohci->flags |= OHCI_QUIRK_BE_MMIO;
  105. ohci_dbg (ohci, "enabled big endian Toshiba quirk\n");
  106. return 0;
  107. #else
  108. ohci_err (ohci, "unsupported big endian Toshiba quirk\n");
  109. return -ENXIO;
  110. #endif
  111. }
  112. /* Check for NEC chip and apply quirk for allegedly lost interrupts.
  113. */
  114. static void ohci_quirk_nec_worker(struct work_struct *work)
  115. {
  116. struct ohci_hcd *ohci = container_of(work, struct ohci_hcd, nec_work);
  117. int status;
  118. status = ohci_init(ohci);
  119. if (status != 0) {
  120. ohci_err(ohci, "Restarting NEC controller failed in %s, %d\n",
  121. "ohci_init", status);
  122. return;
  123. }
  124. status = ohci_restart(ohci);
  125. if (status != 0)
  126. ohci_err(ohci, "Restarting NEC controller failed in %s, %d\n",
  127. "ohci_restart", status);
  128. }
  129. static int ohci_quirk_nec(struct usb_hcd *hcd)
  130. {
  131. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  132. ohci->flags |= OHCI_QUIRK_NEC;
  133. INIT_WORK(&ohci->nec_work, ohci_quirk_nec_worker);
  134. ohci_dbg (ohci, "enabled NEC chipset lost interrupt quirk\n");
  135. return 0;
  136. }
  137. static int ohci_quirk_amd700(struct usb_hcd *hcd)
  138. {
  139. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  140. u8 rev = 0;
  141. if (!amd_smbus_dev)
  142. amd_smbus_dev = pci_get_device(PCI_VENDOR_ID_ATI,
  143. PCI_DEVICE_ID_ATI_SBX00_SMBUS, NULL);
  144. if (!amd_smbus_dev)
  145. return 0;
  146. pci_read_config_byte(amd_smbus_dev, PCI_REVISION_ID, &rev);
  147. /* SB800 needs pre-fetch fix */
  148. if ((rev >= 0x40) && (rev <= 0x4f)) {
  149. ohci->flags |= OHCI_QUIRK_AMD_PREFETCH;
  150. ohci_dbg(ohci, "enabled AMD prefetch quirk\n");
  151. }
  152. if ((rev > 0x3b) || (rev < 0x30)) {
  153. pci_dev_put(amd_smbus_dev);
  154. amd_smbus_dev = NULL;
  155. return 0;
  156. }
  157. amd_ohci_iso_count++;
  158. if (!amd_hb_dev)
  159. amd_hb_dev = pci_get_device(PCI_VENDOR_ID_AMD, 0x9600, NULL);
  160. ohci->flags |= OHCI_QUIRK_AMD_ISO;
  161. ohci_dbg(ohci, "enabled AMD ISO transfers quirk\n");
  162. return 0;
  163. }
  164. /*
  165. * The hardware normally enables the A-link power management feature, which
  166. * lets the system lower the power consumption in idle states.
  167. *
  168. * Assume the system is configured to have USB 1.1 ISO transfers going
  169. * to or from a USB device. Without this quirk, that stream may stutter
  170. * or have breaks occasionally. For transfers going to speakers, this
  171. * makes a very audible mess...
  172. *
  173. * That audio playback corruption is due to the audio stream getting
  174. * interrupted occasionally when the link goes in lower power state
  175. * This USB quirk prevents the link going into that lower power state
  176. * during audio playback or other ISO operations.
  177. */
  178. static void quirk_amd_pll(int on)
  179. {
  180. u32 addr;
  181. u32 val;
  182. u32 bit = (on > 0) ? 1 : 0;
  183. pci_read_config_dword(amd_smbus_dev, AB_REG_BAR, &addr);
  184. /* BIT names/meanings are NDA-protected, sorry ... */
  185. outl(AX_INDXC, AB_INDX(addr));
  186. outl(0x40, AB_DATA(addr));
  187. outl(AX_DATAC, AB_INDX(addr));
  188. val = inl(AB_DATA(addr));
  189. val &= ~((1 << 3) | (1 << 4) | (1 << 9));
  190. val |= (bit << 3) | ((!bit) << 4) | ((!bit) << 9);
  191. outl(val, AB_DATA(addr));
  192. if (amd_hb_dev) {
  193. addr = PCIE_P_CNTL;
  194. pci_write_config_dword(amd_hb_dev, NB_PCIE_INDX_ADDR, addr);
  195. pci_read_config_dword(amd_hb_dev, NB_PCIE_INDX_DATA, &val);
  196. val &= ~(1 | (1 << 3) | (1 << 4) | (1 << 9) | (1 << 12));
  197. val |= bit | (bit << 3) | (bit << 12);
  198. val |= ((!bit) << 4) | ((!bit) << 9);
  199. pci_write_config_dword(amd_hb_dev, NB_PCIE_INDX_DATA, val);
  200. addr = BIF_NB;
  201. pci_write_config_dword(amd_hb_dev, NB_PCIE_INDX_ADDR, addr);
  202. pci_read_config_dword(amd_hb_dev, NB_PCIE_INDX_DATA, &val);
  203. val &= ~(1 << 8);
  204. val |= bit << 8;
  205. pci_write_config_dword(amd_hb_dev, NB_PCIE_INDX_DATA, val);
  206. }
  207. }
  208. static void amd_iso_dev_put(void)
  209. {
  210. amd_ohci_iso_count--;
  211. if (amd_ohci_iso_count == 0) {
  212. if (amd_smbus_dev) {
  213. pci_dev_put(amd_smbus_dev);
  214. amd_smbus_dev = NULL;
  215. }
  216. if (amd_hb_dev) {
  217. pci_dev_put(amd_hb_dev);
  218. amd_hb_dev = NULL;
  219. }
  220. }
  221. }
  222. static void sb800_prefetch(struct ohci_hcd *ohci, int on)
  223. {
  224. struct pci_dev *pdev;
  225. u16 misc;
  226. pdev = to_pci_dev(ohci_to_hcd(ohci)->self.controller);
  227. pci_read_config_word(pdev, 0x50, &misc);
  228. if (on == 0)
  229. pci_write_config_word(pdev, 0x50, misc & 0xfcff);
  230. else
  231. pci_write_config_word(pdev, 0x50, misc | 0x0300);
  232. }
  233. /* List of quirks for OHCI */
  234. static const struct pci_device_id ohci_pci_quirks[] = {
  235. {
  236. PCI_DEVICE(PCI_VENDOR_ID_AMD, 0x740c),
  237. .driver_data = (unsigned long)ohci_quirk_amd756,
  238. },
  239. {
  240. PCI_DEVICE(PCI_VENDOR_ID_OPTI, 0xc861),
  241. .driver_data = (unsigned long)ohci_quirk_opti,
  242. },
  243. {
  244. PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_ANY_ID),
  245. .driver_data = (unsigned long)ohci_quirk_ns,
  246. },
  247. {
  248. PCI_DEVICE(PCI_VENDOR_ID_COMPAQ, 0xa0f8),
  249. .driver_data = (unsigned long)ohci_quirk_zfmicro,
  250. },
  251. {
  252. PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA_2, 0x01b6),
  253. .driver_data = (unsigned long)ohci_quirk_toshiba_scc,
  254. },
  255. {
  256. PCI_DEVICE(PCI_VENDOR_ID_NEC, PCI_DEVICE_ID_NEC_USB),
  257. .driver_data = (unsigned long)ohci_quirk_nec,
  258. },
  259. {
  260. /* Toshiba portege 4000 */
  261. .vendor = PCI_VENDOR_ID_AL,
  262. .device = 0x5237,
  263. .subvendor = PCI_VENDOR_ID_TOSHIBA,
  264. .subdevice = 0x0004,
  265. .driver_data = (unsigned long) broken_suspend,
  266. },
  267. {
  268. PCI_DEVICE(PCI_VENDOR_ID_ITE, 0x8152),
  269. .driver_data = (unsigned long) broken_suspend,
  270. },
  271. {
  272. PCI_DEVICE(PCI_VENDOR_ID_ATI, 0x4397),
  273. .driver_data = (unsigned long)ohci_quirk_amd700,
  274. },
  275. {
  276. PCI_DEVICE(PCI_VENDOR_ID_ATI, 0x4398),
  277. .driver_data = (unsigned long)ohci_quirk_amd700,
  278. },
  279. {
  280. PCI_DEVICE(PCI_VENDOR_ID_ATI, 0x4399),
  281. .driver_data = (unsigned long)ohci_quirk_amd700,
  282. },
  283. /* FIXME for some of the early AMD 760 southbridges, OHCI
  284. * won't work at all. blacklist them.
  285. */
  286. {},
  287. };
  288. static int ohci_pci_reset (struct usb_hcd *hcd)
  289. {
  290. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  291. int ret = 0;
  292. if (hcd->self.controller) {
  293. struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
  294. const struct pci_device_id *quirk_id;
  295. quirk_id = pci_match_id(ohci_pci_quirks, pdev);
  296. if (quirk_id != NULL) {
  297. int (*quirk)(struct usb_hcd *ohci);
  298. quirk = (void *)quirk_id->driver_data;
  299. ret = quirk(hcd);
  300. }
  301. }
  302. if (ret == 0) {
  303. ohci_hcd_init (ohci);
  304. return ohci_init (ohci);
  305. }
  306. return ret;
  307. }
  308. static int __devinit ohci_pci_start (struct usb_hcd *hcd)
  309. {
  310. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  311. int ret;
  312. #ifdef CONFIG_PM /* avoid warnings about unused pdev */
  313. if (hcd->self.controller) {
  314. struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
  315. /* RWC may not be set for add-in PCI cards, since boot
  316. * firmware probably ignored them. This transfers PCI
  317. * PM wakeup capabilities.
  318. */
  319. if (device_can_wakeup(&pdev->dev))
  320. ohci->hc_control |= OHCI_CTRL_RWC;
  321. }
  322. #endif /* CONFIG_PM */
  323. ret = ohci_run (ohci);
  324. if (ret < 0) {
  325. ohci_err (ohci, "can't start\n");
  326. ohci_stop (hcd);
  327. }
  328. return ret;
  329. }
  330. #ifdef CONFIG_PM
  331. static int ohci_pci_suspend(struct usb_hcd *hcd)
  332. {
  333. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  334. unsigned long flags;
  335. int rc = 0;
  336. /* Root hub was already suspended. Disable irq emission and
  337. * mark HW unaccessible, bail out if RH has been resumed. Use
  338. * the spinlock to properly synchronize with possible pending
  339. * RH suspend or resume activity.
  340. *
  341. * This is still racy as hcd->state is manipulated outside of
  342. * any locks =P But that will be a different fix.
  343. */
  344. spin_lock_irqsave (&ohci->lock, flags);
  345. if (hcd->state != HC_STATE_SUSPENDED) {
  346. rc = -EINVAL;
  347. goto bail;
  348. }
  349. ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
  350. (void)ohci_readl(ohci, &ohci->regs->intrdisable);
  351. clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  352. bail:
  353. spin_unlock_irqrestore (&ohci->lock, flags);
  354. return rc;
  355. }
  356. static int ohci_pci_resume(struct usb_hcd *hcd, bool hibernated)
  357. {
  358. set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  359. /* Make sure resume from hibernation re-enumerates everything */
  360. if (hibernated)
  361. ohci_usb_reset(hcd_to_ohci(hcd));
  362. ohci_finish_controller_resume(hcd);
  363. return 0;
  364. }
  365. #endif /* CONFIG_PM */
  366. /*-------------------------------------------------------------------------*/
  367. static const struct hc_driver ohci_pci_hc_driver = {
  368. .description = hcd_name,
  369. .product_desc = "OHCI Host Controller",
  370. .hcd_priv_size = sizeof(struct ohci_hcd),
  371. /*
  372. * generic hardware linkage
  373. */
  374. .irq = ohci_irq,
  375. .flags = HCD_MEMORY | HCD_USB11,
  376. /*
  377. * basic lifecycle operations
  378. */
  379. .reset = ohci_pci_reset,
  380. .start = ohci_pci_start,
  381. .stop = ohci_stop,
  382. .shutdown = ohci_shutdown,
  383. #ifdef CONFIG_PM
  384. .pci_suspend = ohci_pci_suspend,
  385. .pci_resume = ohci_pci_resume,
  386. #endif
  387. /*
  388. * managing i/o requests and associated device resources
  389. */
  390. .urb_enqueue = ohci_urb_enqueue,
  391. .urb_dequeue = ohci_urb_dequeue,
  392. .endpoint_disable = ohci_endpoint_disable,
  393. /*
  394. * scheduling support
  395. */
  396. .get_frame_number = ohci_get_frame,
  397. /*
  398. * root hub support
  399. */
  400. .hub_status_data = ohci_hub_status_data,
  401. .hub_control = ohci_hub_control,
  402. #ifdef CONFIG_PM
  403. .bus_suspend = ohci_bus_suspend,
  404. .bus_resume = ohci_bus_resume,
  405. #endif
  406. .start_port_reset = ohci_start_port_reset,
  407. };
  408. /*-------------------------------------------------------------------------*/
  409. static const struct pci_device_id pci_ids [] = { {
  410. /* handle any USB OHCI controller */
  411. PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_OHCI, ~0),
  412. .driver_data = (unsigned long) &ohci_pci_hc_driver,
  413. }, { /* end: all zeroes */ }
  414. };
  415. MODULE_DEVICE_TABLE (pci, pci_ids);
  416. /* pci driver glue; this is a "new style" PCI driver module */
  417. static struct pci_driver ohci_pci_driver = {
  418. .name = (char *) hcd_name,
  419. .id_table = pci_ids,
  420. .probe = usb_hcd_pci_probe,
  421. .remove = usb_hcd_pci_remove,
  422. .shutdown = usb_hcd_pci_shutdown,
  423. #ifdef CONFIG_PM_SLEEP
  424. .driver = {
  425. .pm = &usb_hcd_pci_pm_ops
  426. },
  427. #endif
  428. };