ohci-pci.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  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. /* nVidia controllers continue to drive Reset signalling on the bus
  165. * even after system shutdown, wasting power. This flag tells the
  166. * shutdown routine to leave the controller OPERATIONAL instead of RESET.
  167. */
  168. static int ohci_quirk_nvidia_shutdown(struct usb_hcd *hcd)
  169. {
  170. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  171. ohci->flags |= OHCI_QUIRK_SHUTDOWN;
  172. ohci_dbg(ohci, "enabled nVidia shutdown quirk\n");
  173. return 0;
  174. }
  175. /*
  176. * The hardware normally enables the A-link power management feature, which
  177. * lets the system lower the power consumption in idle states.
  178. *
  179. * Assume the system is configured to have USB 1.1 ISO transfers going
  180. * to or from a USB device. Without this quirk, that stream may stutter
  181. * or have breaks occasionally. For transfers going to speakers, this
  182. * makes a very audible mess...
  183. *
  184. * That audio playback corruption is due to the audio stream getting
  185. * interrupted occasionally when the link goes in lower power state
  186. * This USB quirk prevents the link going into that lower power state
  187. * during audio playback or other ISO operations.
  188. */
  189. static void quirk_amd_pll(int on)
  190. {
  191. u32 addr;
  192. u32 val;
  193. u32 bit = (on > 0) ? 1 : 0;
  194. pci_read_config_dword(amd_smbus_dev, AB_REG_BAR, &addr);
  195. /* BIT names/meanings are NDA-protected, sorry ... */
  196. outl(AX_INDXC, AB_INDX(addr));
  197. outl(0x40, AB_DATA(addr));
  198. outl(AX_DATAC, AB_INDX(addr));
  199. val = inl(AB_DATA(addr));
  200. val &= ~((1 << 3) | (1 << 4) | (1 << 9));
  201. val |= (bit << 3) | ((!bit) << 4) | ((!bit) << 9);
  202. outl(val, AB_DATA(addr));
  203. if (amd_hb_dev) {
  204. addr = PCIE_P_CNTL;
  205. pci_write_config_dword(amd_hb_dev, NB_PCIE_INDX_ADDR, addr);
  206. pci_read_config_dword(amd_hb_dev, NB_PCIE_INDX_DATA, &val);
  207. val &= ~(1 | (1 << 3) | (1 << 4) | (1 << 9) | (1 << 12));
  208. val |= bit | (bit << 3) | (bit << 12);
  209. val |= ((!bit) << 4) | ((!bit) << 9);
  210. pci_write_config_dword(amd_hb_dev, NB_PCIE_INDX_DATA, val);
  211. addr = BIF_NB;
  212. pci_write_config_dword(amd_hb_dev, NB_PCIE_INDX_ADDR, addr);
  213. pci_read_config_dword(amd_hb_dev, NB_PCIE_INDX_DATA, &val);
  214. val &= ~(1 << 8);
  215. val |= bit << 8;
  216. pci_write_config_dword(amd_hb_dev, NB_PCIE_INDX_DATA, val);
  217. }
  218. }
  219. static void amd_iso_dev_put(void)
  220. {
  221. amd_ohci_iso_count--;
  222. if (amd_ohci_iso_count == 0) {
  223. if (amd_smbus_dev) {
  224. pci_dev_put(amd_smbus_dev);
  225. amd_smbus_dev = NULL;
  226. }
  227. if (amd_hb_dev) {
  228. pci_dev_put(amd_hb_dev);
  229. amd_hb_dev = NULL;
  230. }
  231. }
  232. }
  233. static void sb800_prefetch(struct ohci_hcd *ohci, int on)
  234. {
  235. struct pci_dev *pdev;
  236. u16 misc;
  237. pdev = to_pci_dev(ohci_to_hcd(ohci)->self.controller);
  238. pci_read_config_word(pdev, 0x50, &misc);
  239. if (on == 0)
  240. pci_write_config_word(pdev, 0x50, misc & 0xfcff);
  241. else
  242. pci_write_config_word(pdev, 0x50, misc | 0x0300);
  243. }
  244. /* List of quirks for OHCI */
  245. static const struct pci_device_id ohci_pci_quirks[] = {
  246. {
  247. PCI_DEVICE(PCI_VENDOR_ID_AMD, 0x740c),
  248. .driver_data = (unsigned long)ohci_quirk_amd756,
  249. },
  250. {
  251. PCI_DEVICE(PCI_VENDOR_ID_OPTI, 0xc861),
  252. .driver_data = (unsigned long)ohci_quirk_opti,
  253. },
  254. {
  255. PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_ANY_ID),
  256. .driver_data = (unsigned long)ohci_quirk_ns,
  257. },
  258. {
  259. PCI_DEVICE(PCI_VENDOR_ID_COMPAQ, 0xa0f8),
  260. .driver_data = (unsigned long)ohci_quirk_zfmicro,
  261. },
  262. {
  263. PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA_2, 0x01b6),
  264. .driver_data = (unsigned long)ohci_quirk_toshiba_scc,
  265. },
  266. {
  267. PCI_DEVICE(PCI_VENDOR_ID_NEC, PCI_DEVICE_ID_NEC_USB),
  268. .driver_data = (unsigned long)ohci_quirk_nec,
  269. },
  270. {
  271. /* Toshiba portege 4000 */
  272. .vendor = PCI_VENDOR_ID_AL,
  273. .device = 0x5237,
  274. .subvendor = PCI_VENDOR_ID_TOSHIBA,
  275. .subdevice = 0x0004,
  276. .driver_data = (unsigned long) broken_suspend,
  277. },
  278. {
  279. PCI_DEVICE(PCI_VENDOR_ID_ITE, 0x8152),
  280. .driver_data = (unsigned long) broken_suspend,
  281. },
  282. {
  283. PCI_DEVICE(PCI_VENDOR_ID_ATI, 0x4397),
  284. .driver_data = (unsigned long)ohci_quirk_amd700,
  285. },
  286. {
  287. PCI_DEVICE(PCI_VENDOR_ID_ATI, 0x4398),
  288. .driver_data = (unsigned long)ohci_quirk_amd700,
  289. },
  290. {
  291. PCI_DEVICE(PCI_VENDOR_ID_ATI, 0x4399),
  292. .driver_data = (unsigned long)ohci_quirk_amd700,
  293. },
  294. {
  295. PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID),
  296. .driver_data = (unsigned long) ohci_quirk_nvidia_shutdown,
  297. },
  298. /* FIXME for some of the early AMD 760 southbridges, OHCI
  299. * won't work at all. blacklist them.
  300. */
  301. {},
  302. };
  303. static int ohci_pci_reset (struct usb_hcd *hcd)
  304. {
  305. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  306. int ret = 0;
  307. if (hcd->self.controller) {
  308. struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
  309. const struct pci_device_id *quirk_id;
  310. quirk_id = pci_match_id(ohci_pci_quirks, pdev);
  311. if (quirk_id != NULL) {
  312. int (*quirk)(struct usb_hcd *ohci);
  313. quirk = (void *)quirk_id->driver_data;
  314. ret = quirk(hcd);
  315. }
  316. }
  317. if (ret == 0) {
  318. ohci_hcd_init (ohci);
  319. return ohci_init (ohci);
  320. }
  321. return ret;
  322. }
  323. static int __devinit ohci_pci_start (struct usb_hcd *hcd)
  324. {
  325. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  326. int ret;
  327. #ifdef CONFIG_PM /* avoid warnings about unused pdev */
  328. if (hcd->self.controller) {
  329. struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
  330. /* RWC may not be set for add-in PCI cards, since boot
  331. * firmware probably ignored them. This transfers PCI
  332. * PM wakeup capabilities.
  333. */
  334. if (device_can_wakeup(&pdev->dev))
  335. ohci->hc_control |= OHCI_CTRL_RWC;
  336. }
  337. #endif /* CONFIG_PM */
  338. ret = ohci_run (ohci);
  339. if (ret < 0) {
  340. ohci_err (ohci, "can't start\n");
  341. ohci_stop (hcd);
  342. }
  343. return ret;
  344. }
  345. #ifdef CONFIG_PM
  346. static int ohci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
  347. {
  348. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  349. unsigned long flags;
  350. int rc = 0;
  351. /* Root hub was already suspended. Disable irq emission and
  352. * mark HW unaccessible, bail out if RH has been resumed. Use
  353. * the spinlock to properly synchronize with possible pending
  354. * RH suspend or resume activity.
  355. *
  356. * This is still racy as hcd->state is manipulated outside of
  357. * any locks =P But that will be a different fix.
  358. */
  359. spin_lock_irqsave (&ohci->lock, flags);
  360. if (hcd->state != HC_STATE_SUSPENDED) {
  361. rc = -EINVAL;
  362. goto bail;
  363. }
  364. ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
  365. (void)ohci_readl(ohci, &ohci->regs->intrdisable);
  366. clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  367. bail:
  368. spin_unlock_irqrestore (&ohci->lock, flags);
  369. return rc;
  370. }
  371. static int ohci_pci_resume(struct usb_hcd *hcd, bool hibernated)
  372. {
  373. set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  374. /* Make sure resume from hibernation re-enumerates everything */
  375. if (hibernated)
  376. ohci_usb_reset(hcd_to_ohci(hcd));
  377. ohci_finish_controller_resume(hcd);
  378. return 0;
  379. }
  380. #endif /* CONFIG_PM */
  381. /*-------------------------------------------------------------------------*/
  382. static const struct hc_driver ohci_pci_hc_driver = {
  383. .description = hcd_name,
  384. .product_desc = "OHCI Host Controller",
  385. .hcd_priv_size = sizeof(struct ohci_hcd),
  386. /*
  387. * generic hardware linkage
  388. */
  389. .irq = ohci_irq,
  390. .flags = HCD_MEMORY | HCD_USB11,
  391. /*
  392. * basic lifecycle operations
  393. */
  394. .reset = ohci_pci_reset,
  395. .start = ohci_pci_start,
  396. .stop = ohci_stop,
  397. .shutdown = ohci_shutdown,
  398. #ifdef CONFIG_PM
  399. .pci_suspend = ohci_pci_suspend,
  400. .pci_resume = ohci_pci_resume,
  401. #endif
  402. /*
  403. * managing i/o requests and associated device resources
  404. */
  405. .urb_enqueue = ohci_urb_enqueue,
  406. .urb_dequeue = ohci_urb_dequeue,
  407. .endpoint_disable = ohci_endpoint_disable,
  408. /*
  409. * scheduling support
  410. */
  411. .get_frame_number = ohci_get_frame,
  412. /*
  413. * root hub support
  414. */
  415. .hub_status_data = ohci_hub_status_data,
  416. .hub_control = ohci_hub_control,
  417. #ifdef CONFIG_PM
  418. .bus_suspend = ohci_bus_suspend,
  419. .bus_resume = ohci_bus_resume,
  420. #endif
  421. .start_port_reset = ohci_start_port_reset,
  422. };
  423. /*-------------------------------------------------------------------------*/
  424. static const struct pci_device_id pci_ids [] = { {
  425. /* handle any USB OHCI controller */
  426. PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_OHCI, ~0),
  427. .driver_data = (unsigned long) &ohci_pci_hc_driver,
  428. }, { /* end: all zeroes */ }
  429. };
  430. MODULE_DEVICE_TABLE (pci, pci_ids);
  431. /* pci driver glue; this is a "new style" PCI driver module */
  432. static struct pci_driver ohci_pci_driver = {
  433. .name = (char *) hcd_name,
  434. .id_table = pci_ids,
  435. .probe = usb_hcd_pci_probe,
  436. .remove = usb_hcd_pci_remove,
  437. .shutdown = usb_hcd_pci_shutdown,
  438. #ifdef CONFIG_PM_SLEEP
  439. .driver = {
  440. .pm = &usb_hcd_pci_pm_ops
  441. },
  442. #endif
  443. };