ohci-hcd.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384
  1. /*
  2. * Open Host Controller Interface (OHCI) driver for USB.
  3. *
  4. * Maintainer: Alan Stern <stern@rowland.harvard.edu>
  5. *
  6. * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
  7. * (C) Copyright 2000-2004 David Brownell <dbrownell@users.sourceforge.net>
  8. *
  9. * [ Initialisation is based on Linus' ]
  10. * [ uhci code and gregs ohci fragments ]
  11. * [ (C) Copyright 1999 Linus Torvalds ]
  12. * [ (C) Copyright 1999 Gregory P. Smith]
  13. *
  14. *
  15. * OHCI is the main "non-Intel/VIA" standard for USB 1.1 host controller
  16. * interfaces (though some non-x86 Intel chips use it). It supports
  17. * smarter hardware than UHCI. A download link for the spec available
  18. * through the http://www.usb.org website.
  19. *
  20. * This file is licenced under the GPL.
  21. */
  22. #include <linux/module.h>
  23. #include <linux/moduleparam.h>
  24. #include <linux/pci.h>
  25. #include <linux/kernel.h>
  26. #include <linux/delay.h>
  27. #include <linux/ioport.h>
  28. #include <linux/sched.h>
  29. #include <linux/slab.h>
  30. #include <linux/errno.h>
  31. #include <linux/init.h>
  32. #include <linux/timer.h>
  33. #include <linux/list.h>
  34. #include <linux/usb.h>
  35. #include <linux/usb/otg.h>
  36. #include <linux/usb/hcd.h>
  37. #include <linux/dma-mapping.h>
  38. #include <linux/dmapool.h>
  39. #include <linux/workqueue.h>
  40. #include <linux/debugfs.h>
  41. #include <asm/io.h>
  42. #include <asm/irq.h>
  43. #include <asm/unaligned.h>
  44. #include <asm/byteorder.h>
  45. #define DRIVER_AUTHOR "Roman Weissgaerber, David Brownell"
  46. #define DRIVER_DESC "USB 1.1 'Open' Host Controller (OHCI) Driver"
  47. /*-------------------------------------------------------------------------*/
  48. /* For initializing controller (mask in an HCFS mode too) */
  49. #define OHCI_CONTROL_INIT OHCI_CTRL_CBSR
  50. #define OHCI_INTR_INIT \
  51. (OHCI_INTR_MIE | OHCI_INTR_RHSC | OHCI_INTR_UE \
  52. | OHCI_INTR_RD | OHCI_INTR_WDH)
  53. #ifdef __hppa__
  54. /* On PA-RISC, PDC can leave IR set incorrectly; ignore it there. */
  55. #define IR_DISABLE
  56. #endif
  57. #ifdef CONFIG_ARCH_OMAP
  58. /* OMAP doesn't support IR (no SMM; not needed) */
  59. #define IR_DISABLE
  60. #endif
  61. /*-------------------------------------------------------------------------*/
  62. static const char hcd_name [] = "ohci_hcd";
  63. #define STATECHANGE_DELAY msecs_to_jiffies(300)
  64. #define IO_WATCHDOG_DELAY msecs_to_jiffies(250)
  65. #include "ohci.h"
  66. #include "pci-quirks.h"
  67. static void ohci_dump(struct ohci_hcd *ohci);
  68. static void ohci_stop(struct usb_hcd *hcd);
  69. static void io_watchdog_func(unsigned long _ohci);
  70. #include "ohci-hub.c"
  71. #include "ohci-dbg.c"
  72. #include "ohci-mem.c"
  73. #include "ohci-q.c"
  74. /*
  75. * On architectures with edge-triggered interrupts we must never return
  76. * IRQ_NONE.
  77. */
  78. #if defined(CONFIG_SA1111) /* ... or other edge-triggered systems */
  79. #define IRQ_NOTMINE IRQ_HANDLED
  80. #else
  81. #define IRQ_NOTMINE IRQ_NONE
  82. #endif
  83. /* Some boards misreport power switching/overcurrent */
  84. static bool distrust_firmware = 1;
  85. module_param (distrust_firmware, bool, 0);
  86. MODULE_PARM_DESC (distrust_firmware,
  87. "true to distrust firmware power/overcurrent setup");
  88. /* Some boards leave IR set wrongly, since they fail BIOS/SMM handshakes */
  89. static bool no_handshake = 0;
  90. module_param (no_handshake, bool, 0);
  91. MODULE_PARM_DESC (no_handshake, "true (not default) disables BIOS handshake");
  92. /*-------------------------------------------------------------------------*/
  93. static int number_of_tds(struct urb *urb)
  94. {
  95. int len, i, num, this_sg_len;
  96. struct scatterlist *sg;
  97. len = urb->transfer_buffer_length;
  98. i = urb->num_mapped_sgs;
  99. if (len > 0 && i > 0) { /* Scatter-gather transfer */
  100. num = 0;
  101. sg = urb->sg;
  102. for (;;) {
  103. this_sg_len = min_t(int, sg_dma_len(sg), len);
  104. num += DIV_ROUND_UP(this_sg_len, 4096);
  105. len -= this_sg_len;
  106. if (--i <= 0 || len <= 0)
  107. break;
  108. sg = sg_next(sg);
  109. }
  110. } else { /* Non-SG transfer */
  111. /* one TD for every 4096 Bytes (could be up to 8K) */
  112. num = DIV_ROUND_UP(len, 4096);
  113. }
  114. return num;
  115. }
  116. /*
  117. * queue up an urb for anything except the root hub
  118. */
  119. static int ohci_urb_enqueue (
  120. struct usb_hcd *hcd,
  121. struct urb *urb,
  122. gfp_t mem_flags
  123. ) {
  124. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  125. struct ed *ed;
  126. urb_priv_t *urb_priv;
  127. unsigned int pipe = urb->pipe;
  128. int i, size = 0;
  129. unsigned long flags;
  130. int retval = 0;
  131. /* every endpoint has a ed, locate and maybe (re)initialize it */
  132. if (! (ed = ed_get (ohci, urb->ep, urb->dev, pipe, urb->interval)))
  133. return -ENOMEM;
  134. /* for the private part of the URB we need the number of TDs (size) */
  135. switch (ed->type) {
  136. case PIPE_CONTROL:
  137. /* td_submit_urb() doesn't yet handle these */
  138. if (urb->transfer_buffer_length > 4096)
  139. return -EMSGSIZE;
  140. /* 1 TD for setup, 1 for ACK, plus ... */
  141. size = 2;
  142. /* FALLTHROUGH */
  143. // case PIPE_INTERRUPT:
  144. // case PIPE_BULK:
  145. default:
  146. size += number_of_tds(urb);
  147. /* maybe a zero-length packet to wrap it up */
  148. if (size == 0)
  149. size++;
  150. else if ((urb->transfer_flags & URB_ZERO_PACKET) != 0
  151. && (urb->transfer_buffer_length
  152. % usb_maxpacket (urb->dev, pipe,
  153. usb_pipeout (pipe))) == 0)
  154. size++;
  155. break;
  156. case PIPE_ISOCHRONOUS: /* number of packets from URB */
  157. size = urb->number_of_packets;
  158. break;
  159. }
  160. /* allocate the private part of the URB */
  161. urb_priv = kzalloc (sizeof (urb_priv_t) + size * sizeof (struct td *),
  162. mem_flags);
  163. if (!urb_priv)
  164. return -ENOMEM;
  165. INIT_LIST_HEAD (&urb_priv->pending);
  166. urb_priv->length = size;
  167. urb_priv->ed = ed;
  168. /* allocate the TDs (deferring hash chain updates) */
  169. for (i = 0; i < size; i++) {
  170. urb_priv->td [i] = td_alloc (ohci, mem_flags);
  171. if (!urb_priv->td [i]) {
  172. urb_priv->length = i;
  173. urb_free_priv (ohci, urb_priv);
  174. return -ENOMEM;
  175. }
  176. }
  177. spin_lock_irqsave (&ohci->lock, flags);
  178. /* don't submit to a dead HC */
  179. if (!HCD_HW_ACCESSIBLE(hcd)) {
  180. retval = -ENODEV;
  181. goto fail;
  182. }
  183. if (ohci->rh_state != OHCI_RH_RUNNING) {
  184. retval = -ENODEV;
  185. goto fail;
  186. }
  187. retval = usb_hcd_link_urb_to_ep(hcd, urb);
  188. if (retval)
  189. goto fail;
  190. /* schedule the ed if needed */
  191. if (ed->state == ED_IDLE) {
  192. retval = ed_schedule (ohci, ed);
  193. if (retval < 0) {
  194. usb_hcd_unlink_urb_from_ep(hcd, urb);
  195. goto fail;
  196. }
  197. /* Start up the I/O watchdog timer, if it's not running */
  198. if (!timer_pending(&ohci->io_watchdog) &&
  199. list_empty(&ohci->eds_in_use)) {
  200. ohci->prev_frame_no = ohci_frame_no(ohci);
  201. mod_timer(&ohci->io_watchdog,
  202. jiffies + IO_WATCHDOG_DELAY);
  203. }
  204. list_add(&ed->in_use_list, &ohci->eds_in_use);
  205. if (ed->type == PIPE_ISOCHRONOUS) {
  206. u16 frame = ohci_frame_no(ohci);
  207. /* delay a few frames before the first TD */
  208. frame += max_t (u16, 8, ed->interval);
  209. frame &= ~(ed->interval - 1);
  210. frame |= ed->branch;
  211. urb->start_frame = frame;
  212. ed->last_iso = frame + ed->interval * (size - 1);
  213. }
  214. } else if (ed->type == PIPE_ISOCHRONOUS) {
  215. u16 next = ohci_frame_no(ohci) + 1;
  216. u16 frame = ed->last_iso + ed->interval;
  217. u16 length = ed->interval * (size - 1);
  218. /* Behind the scheduling threshold? */
  219. if (unlikely(tick_before(frame, next))) {
  220. /* URB_ISO_ASAP: Round up to the first available slot */
  221. if (urb->transfer_flags & URB_ISO_ASAP) {
  222. frame += (next - frame + ed->interval - 1) &
  223. -ed->interval;
  224. /*
  225. * Not ASAP: Use the next slot in the stream,
  226. * no matter what.
  227. */
  228. } else {
  229. /*
  230. * Some OHCI hardware doesn't handle late TDs
  231. * correctly. After retiring them it proceeds
  232. * to the next ED instead of the next TD.
  233. * Therefore we have to omit the late TDs
  234. * entirely.
  235. */
  236. urb_priv->td_cnt = DIV_ROUND_UP(
  237. (u16) (next - frame),
  238. ed->interval);
  239. if (urb_priv->td_cnt >= urb_priv->length) {
  240. ++urb_priv->td_cnt; /* Mark it */
  241. ohci_dbg(ohci, "iso underrun %p (%u+%u < %u)\n",
  242. urb, frame, length,
  243. next);
  244. }
  245. }
  246. }
  247. urb->start_frame = frame;
  248. ed->last_iso = frame + length;
  249. }
  250. /* fill the TDs and link them to the ed; and
  251. * enable that part of the schedule, if needed
  252. * and update count of queued periodic urbs
  253. */
  254. urb->hcpriv = urb_priv;
  255. td_submit_urb (ohci, urb);
  256. fail:
  257. if (retval)
  258. urb_free_priv (ohci, urb_priv);
  259. spin_unlock_irqrestore (&ohci->lock, flags);
  260. return retval;
  261. }
  262. /*
  263. * decouple the URB from the HC queues (TDs, urb_priv).
  264. * reporting is always done
  265. * asynchronously, and we might be dealing with an urb that's
  266. * partially transferred, or an ED with other urbs being unlinked.
  267. */
  268. static int ohci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
  269. {
  270. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  271. unsigned long flags;
  272. int rc;
  273. urb_priv_t *urb_priv;
  274. spin_lock_irqsave (&ohci->lock, flags);
  275. rc = usb_hcd_check_unlink_urb(hcd, urb, status);
  276. if (rc == 0) {
  277. /* Unless an IRQ completed the unlink while it was being
  278. * handed to us, flag it for unlink and giveback, and force
  279. * some upcoming INTR_SF to call finish_unlinks()
  280. */
  281. urb_priv = urb->hcpriv;
  282. if (urb_priv->ed->state == ED_OPER)
  283. start_ed_unlink(ohci, urb_priv->ed);
  284. if (ohci->rh_state != OHCI_RH_RUNNING) {
  285. /* With HC dead, we can clean up right away */
  286. ohci_work(ohci);
  287. }
  288. }
  289. spin_unlock_irqrestore (&ohci->lock, flags);
  290. return rc;
  291. }
  292. /*-------------------------------------------------------------------------*/
  293. /* frees config/altsetting state for endpoints,
  294. * including ED memory, dummy TD, and bulk/intr data toggle
  295. */
  296. static void
  297. ohci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  298. {
  299. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  300. unsigned long flags;
  301. struct ed *ed = ep->hcpriv;
  302. unsigned limit = 1000;
  303. /* ASSERT: any requests/urbs are being unlinked */
  304. /* ASSERT: nobody can be submitting urbs for this any more */
  305. if (!ed)
  306. return;
  307. rescan:
  308. spin_lock_irqsave (&ohci->lock, flags);
  309. if (ohci->rh_state != OHCI_RH_RUNNING) {
  310. sanitize:
  311. ed->state = ED_IDLE;
  312. ohci_work(ohci);
  313. }
  314. switch (ed->state) {
  315. case ED_UNLINK: /* wait for hw to finish? */
  316. /* major IRQ delivery trouble loses INTR_SF too... */
  317. if (limit-- == 0) {
  318. ohci_warn(ohci, "ED unlink timeout\n");
  319. goto sanitize;
  320. }
  321. spin_unlock_irqrestore (&ohci->lock, flags);
  322. schedule_timeout_uninterruptible(1);
  323. goto rescan;
  324. case ED_IDLE: /* fully unlinked */
  325. if (list_empty (&ed->td_list)) {
  326. td_free (ohci, ed->dummy);
  327. ed_free (ohci, ed);
  328. break;
  329. }
  330. /* else FALL THROUGH */
  331. default:
  332. /* caller was supposed to have unlinked any requests;
  333. * that's not our job. can't recover; must leak ed.
  334. */
  335. ohci_err (ohci, "leak ed %p (#%02x) state %d%s\n",
  336. ed, ep->desc.bEndpointAddress, ed->state,
  337. list_empty (&ed->td_list) ? "" : " (has tds)");
  338. td_free (ohci, ed->dummy);
  339. break;
  340. }
  341. ep->hcpriv = NULL;
  342. spin_unlock_irqrestore (&ohci->lock, flags);
  343. }
  344. static int ohci_get_frame (struct usb_hcd *hcd)
  345. {
  346. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  347. return ohci_frame_no(ohci);
  348. }
  349. static void ohci_usb_reset (struct ohci_hcd *ohci)
  350. {
  351. ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
  352. ohci->hc_control &= OHCI_CTRL_RWC;
  353. ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
  354. ohci->rh_state = OHCI_RH_HALTED;
  355. }
  356. /* ohci_shutdown forcibly disables IRQs and DMA, helping kexec and
  357. * other cases where the next software may expect clean state from the
  358. * "firmware". this is bus-neutral, unlike shutdown() methods.
  359. */
  360. static void
  361. ohci_shutdown (struct usb_hcd *hcd)
  362. {
  363. struct ohci_hcd *ohci;
  364. ohci = hcd_to_ohci (hcd);
  365. ohci_writel(ohci, (u32) ~0, &ohci->regs->intrdisable);
  366. /* Software reset, after which the controller goes into SUSPEND */
  367. ohci_writel(ohci, OHCI_HCR, &ohci->regs->cmdstatus);
  368. ohci_readl(ohci, &ohci->regs->cmdstatus); /* flush the writes */
  369. udelay(10);
  370. ohci_writel(ohci, ohci->fminterval, &ohci->regs->fminterval);
  371. ohci->rh_state = OHCI_RH_HALTED;
  372. }
  373. /*-------------------------------------------------------------------------*
  374. * HC functions
  375. *-------------------------------------------------------------------------*/
  376. /* init memory, and kick BIOS/SMM off */
  377. static int ohci_init (struct ohci_hcd *ohci)
  378. {
  379. int ret;
  380. struct usb_hcd *hcd = ohci_to_hcd(ohci);
  381. /* Accept arbitrarily long scatter-gather lists */
  382. hcd->self.sg_tablesize = ~0;
  383. if (distrust_firmware)
  384. ohci->flags |= OHCI_QUIRK_HUB_POWER;
  385. ohci->rh_state = OHCI_RH_HALTED;
  386. ohci->regs = hcd->regs;
  387. /* REVISIT this BIOS handshake is now moved into PCI "quirks", and
  388. * was never needed for most non-PCI systems ... remove the code?
  389. */
  390. #ifndef IR_DISABLE
  391. /* SMM owns the HC? not for long! */
  392. if (!no_handshake && ohci_readl (ohci,
  393. &ohci->regs->control) & OHCI_CTRL_IR) {
  394. u32 temp;
  395. ohci_dbg (ohci, "USB HC TakeOver from BIOS/SMM\n");
  396. /* this timeout is arbitrary. we make it long, so systems
  397. * depending on usb keyboards may be usable even if the
  398. * BIOS/SMM code seems pretty broken.
  399. */
  400. temp = 500; /* arbitrary: five seconds */
  401. ohci_writel (ohci, OHCI_INTR_OC, &ohci->regs->intrenable);
  402. ohci_writel (ohci, OHCI_OCR, &ohci->regs->cmdstatus);
  403. while (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_IR) {
  404. msleep (10);
  405. if (--temp == 0) {
  406. ohci_err (ohci, "USB HC takeover failed!"
  407. " (BIOS/SMM bug)\n");
  408. return -EBUSY;
  409. }
  410. }
  411. ohci_usb_reset (ohci);
  412. }
  413. #endif
  414. /* Disable HC interrupts */
  415. ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
  416. /* flush the writes, and save key bits like RWC */
  417. if (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_RWC)
  418. ohci->hc_control |= OHCI_CTRL_RWC;
  419. /* Read the number of ports unless overridden */
  420. if (ohci->num_ports == 0)
  421. ohci->num_ports = roothub_a(ohci) & RH_A_NDP;
  422. if (ohci->hcca)
  423. return 0;
  424. setup_timer(&ohci->io_watchdog, io_watchdog_func,
  425. (unsigned long) ohci);
  426. set_timer_slack(&ohci->io_watchdog, msecs_to_jiffies(20));
  427. ohci->hcca = dma_alloc_coherent (hcd->self.controller,
  428. sizeof(*ohci->hcca), &ohci->hcca_dma, GFP_KERNEL);
  429. if (!ohci->hcca)
  430. return -ENOMEM;
  431. if ((ret = ohci_mem_init (ohci)) < 0)
  432. ohci_stop (hcd);
  433. else {
  434. create_debug_files (ohci);
  435. }
  436. return ret;
  437. }
  438. /*-------------------------------------------------------------------------*/
  439. /* Start an OHCI controller, set the BUS operational
  440. * resets USB and controller
  441. * enable interrupts
  442. */
  443. static int ohci_run (struct ohci_hcd *ohci)
  444. {
  445. u32 mask, val;
  446. int first = ohci->fminterval == 0;
  447. struct usb_hcd *hcd = ohci_to_hcd(ohci);
  448. ohci->rh_state = OHCI_RH_HALTED;
  449. /* boot firmware should have set this up (5.1.1.3.1) */
  450. if (first) {
  451. val = ohci_readl (ohci, &ohci->regs->fminterval);
  452. ohci->fminterval = val & 0x3fff;
  453. if (ohci->fminterval != FI)
  454. ohci_dbg (ohci, "fminterval delta %d\n",
  455. ohci->fminterval - FI);
  456. ohci->fminterval |= FSMP (ohci->fminterval) << 16;
  457. /* also: power/overcurrent flags in roothub.a */
  458. }
  459. /* Reset USB nearly "by the book". RemoteWakeupConnected has
  460. * to be checked in case boot firmware (BIOS/SMM/...) has set up
  461. * wakeup in a way the bus isn't aware of (e.g., legacy PCI PM).
  462. * If the bus glue detected wakeup capability then it should
  463. * already be enabled; if so we'll just enable it again.
  464. */
  465. if ((ohci->hc_control & OHCI_CTRL_RWC) != 0)
  466. device_set_wakeup_capable(hcd->self.controller, 1);
  467. switch (ohci->hc_control & OHCI_CTRL_HCFS) {
  468. case OHCI_USB_OPER:
  469. val = 0;
  470. break;
  471. case OHCI_USB_SUSPEND:
  472. case OHCI_USB_RESUME:
  473. ohci->hc_control &= OHCI_CTRL_RWC;
  474. ohci->hc_control |= OHCI_USB_RESUME;
  475. val = 10 /* msec wait */;
  476. break;
  477. // case OHCI_USB_RESET:
  478. default:
  479. ohci->hc_control &= OHCI_CTRL_RWC;
  480. ohci->hc_control |= OHCI_USB_RESET;
  481. val = 50 /* msec wait */;
  482. break;
  483. }
  484. ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
  485. // flush the writes
  486. (void) ohci_readl (ohci, &ohci->regs->control);
  487. msleep(val);
  488. memset (ohci->hcca, 0, sizeof (struct ohci_hcca));
  489. /* 2msec timelimit here means no irqs/preempt */
  490. spin_lock_irq (&ohci->lock);
  491. retry:
  492. /* HC Reset requires max 10 us delay */
  493. ohci_writel (ohci, OHCI_HCR, &ohci->regs->cmdstatus);
  494. val = 30; /* ... allow extra time */
  495. while ((ohci_readl (ohci, &ohci->regs->cmdstatus) & OHCI_HCR) != 0) {
  496. if (--val == 0) {
  497. spin_unlock_irq (&ohci->lock);
  498. ohci_err (ohci, "USB HC reset timed out!\n");
  499. return -1;
  500. }
  501. udelay (1);
  502. }
  503. /* now we're in the SUSPEND state ... must go OPERATIONAL
  504. * within 2msec else HC enters RESUME
  505. *
  506. * ... but some hardware won't init fmInterval "by the book"
  507. * (SiS, OPTi ...), so reset again instead. SiS doesn't need
  508. * this if we write fmInterval after we're OPERATIONAL.
  509. * Unclear about ALi, ServerWorks, and others ... this could
  510. * easily be a longstanding bug in chip init on Linux.
  511. */
  512. if (ohci->flags & OHCI_QUIRK_INITRESET) {
  513. ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
  514. // flush those writes
  515. (void) ohci_readl (ohci, &ohci->regs->control);
  516. }
  517. /* Tell the controller where the control and bulk lists are
  518. * The lists are empty now. */
  519. ohci_writel (ohci, 0, &ohci->regs->ed_controlhead);
  520. ohci_writel (ohci, 0, &ohci->regs->ed_bulkhead);
  521. /* a reset clears this */
  522. ohci_writel (ohci, (u32) ohci->hcca_dma, &ohci->regs->hcca);
  523. periodic_reinit (ohci);
  524. /* some OHCI implementations are finicky about how they init.
  525. * bogus values here mean not even enumeration could work.
  526. */
  527. if ((ohci_readl (ohci, &ohci->regs->fminterval) & 0x3fff0000) == 0
  528. || !ohci_readl (ohci, &ohci->regs->periodicstart)) {
  529. if (!(ohci->flags & OHCI_QUIRK_INITRESET)) {
  530. ohci->flags |= OHCI_QUIRK_INITRESET;
  531. ohci_dbg (ohci, "enabling initreset quirk\n");
  532. goto retry;
  533. }
  534. spin_unlock_irq (&ohci->lock);
  535. ohci_err (ohci, "init err (%08x %04x)\n",
  536. ohci_readl (ohci, &ohci->regs->fminterval),
  537. ohci_readl (ohci, &ohci->regs->periodicstart));
  538. return -EOVERFLOW;
  539. }
  540. /* use rhsc irqs after hub_wq is allocated */
  541. set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
  542. hcd->uses_new_polling = 1;
  543. /* start controller operations */
  544. ohci->hc_control &= OHCI_CTRL_RWC;
  545. ohci->hc_control |= OHCI_CONTROL_INIT | OHCI_USB_OPER;
  546. ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
  547. ohci->rh_state = OHCI_RH_RUNNING;
  548. /* wake on ConnectStatusChange, matching external hubs */
  549. ohci_writel (ohci, RH_HS_DRWE, &ohci->regs->roothub.status);
  550. /* Choose the interrupts we care about now, others later on demand */
  551. mask = OHCI_INTR_INIT;
  552. ohci_writel (ohci, ~0, &ohci->regs->intrstatus);
  553. ohci_writel (ohci, mask, &ohci->regs->intrenable);
  554. /* handle root hub init quirks ... */
  555. val = roothub_a (ohci);
  556. val &= ~(RH_A_PSM | RH_A_OCPM);
  557. if (ohci->flags & OHCI_QUIRK_SUPERIO) {
  558. /* NSC 87560 and maybe others */
  559. val |= RH_A_NOCP;
  560. val &= ~(RH_A_POTPGT | RH_A_NPS);
  561. ohci_writel (ohci, val, &ohci->regs->roothub.a);
  562. } else if ((ohci->flags & OHCI_QUIRK_AMD756) ||
  563. (ohci->flags & OHCI_QUIRK_HUB_POWER)) {
  564. /* hub power always on; required for AMD-756 and some
  565. * Mac platforms. ganged overcurrent reporting, if any.
  566. */
  567. val |= RH_A_NPS;
  568. ohci_writel (ohci, val, &ohci->regs->roothub.a);
  569. }
  570. ohci_writel (ohci, RH_HS_LPSC, &ohci->regs->roothub.status);
  571. ohci_writel (ohci, (val & RH_A_NPS) ? 0 : RH_B_PPCM,
  572. &ohci->regs->roothub.b);
  573. // flush those writes
  574. (void) ohci_readl (ohci, &ohci->regs->control);
  575. ohci->next_statechange = jiffies + STATECHANGE_DELAY;
  576. spin_unlock_irq (&ohci->lock);
  577. // POTPGT delay is bits 24-31, in 2 ms units.
  578. mdelay ((val >> 23) & 0x1fe);
  579. ohci_dump(ohci);
  580. return 0;
  581. }
  582. /* ohci_setup routine for generic controller initialization */
  583. int ohci_setup(struct usb_hcd *hcd)
  584. {
  585. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  586. ohci_hcd_init(ohci);
  587. return ohci_init(ohci);
  588. }
  589. EXPORT_SYMBOL_GPL(ohci_setup);
  590. /* ohci_start routine for generic controller start of all OHCI bus glue */
  591. static int ohci_start(struct usb_hcd *hcd)
  592. {
  593. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  594. int ret;
  595. ret = ohci_run(ohci);
  596. if (ret < 0) {
  597. ohci_err(ohci, "can't start\n");
  598. ohci_stop(hcd);
  599. }
  600. return ret;
  601. }
  602. /*-------------------------------------------------------------------------*/
  603. /*
  604. * Some OHCI controllers are known to lose track of completed TDs. They
  605. * don't add the TDs to the hardware done queue, which means we never see
  606. * them as being completed.
  607. *
  608. * This watchdog routine checks for such problems. Without some way to
  609. * tell when those TDs have completed, we would never take their EDs off
  610. * the unlink list. As a result, URBs could never be dequeued and
  611. * endpoints could never be released.
  612. */
  613. static void io_watchdog_func(unsigned long _ohci)
  614. {
  615. struct ohci_hcd *ohci = (struct ohci_hcd *) _ohci;
  616. bool takeback_all_pending = false;
  617. u32 status;
  618. u32 head;
  619. struct ed *ed;
  620. struct td *td, *td_start, *td_next;
  621. unsigned frame_no;
  622. unsigned long flags;
  623. spin_lock_irqsave(&ohci->lock, flags);
  624. /*
  625. * One way to lose track of completed TDs is if the controller
  626. * never writes back the done queue head. If it hasn't been
  627. * written back since the last time this function ran and if it
  628. * was non-empty at that time, something is badly wrong with the
  629. * hardware.
  630. */
  631. status = ohci_readl(ohci, &ohci->regs->intrstatus);
  632. if (!(status & OHCI_INTR_WDH) && ohci->wdh_cnt == ohci->prev_wdh_cnt) {
  633. if (ohci->prev_donehead) {
  634. ohci_err(ohci, "HcDoneHead not written back; disabled\n");
  635. died:
  636. usb_hc_died(ohci_to_hcd(ohci));
  637. ohci_dump(ohci);
  638. ohci_shutdown(ohci_to_hcd(ohci));
  639. goto done;
  640. } else {
  641. /* No write back because the done queue was empty */
  642. takeback_all_pending = true;
  643. }
  644. }
  645. /* Check every ED which might have pending TDs */
  646. list_for_each_entry(ed, &ohci->eds_in_use, in_use_list) {
  647. if (ed->pending_td) {
  648. if (takeback_all_pending ||
  649. OKAY_TO_TAKEBACK(ohci, ed)) {
  650. unsigned tmp = hc32_to_cpu(ohci, ed->hwINFO);
  651. ohci_dbg(ohci, "takeback pending TD for dev %d ep 0x%x\n",
  652. 0x007f & tmp,
  653. (0x000f & (tmp >> 7)) +
  654. ((tmp & ED_IN) >> 5));
  655. add_to_done_list(ohci, ed->pending_td);
  656. }
  657. }
  658. /* Starting from the latest pending TD, */
  659. td = ed->pending_td;
  660. /* or the last TD on the done list, */
  661. if (!td) {
  662. list_for_each_entry(td_next, &ed->td_list, td_list) {
  663. if (!td_next->next_dl_td)
  664. break;
  665. td = td_next;
  666. }
  667. }
  668. /* find the last TD processed by the controller. */
  669. head = hc32_to_cpu(ohci, ACCESS_ONCE(ed->hwHeadP)) & TD_MASK;
  670. td_start = td;
  671. td_next = list_prepare_entry(td, &ed->td_list, td_list);
  672. list_for_each_entry_continue(td_next, &ed->td_list, td_list) {
  673. if (head == (u32) td_next->td_dma)
  674. break;
  675. td = td_next; /* head pointer has passed this TD */
  676. }
  677. if (td != td_start) {
  678. /*
  679. * In case a WDH cycle is in progress, we will wait
  680. * for the next two cycles to complete before assuming
  681. * this TD will never get on the done queue.
  682. */
  683. ed->takeback_wdh_cnt = ohci->wdh_cnt + 2;
  684. ed->pending_td = td;
  685. }
  686. }
  687. ohci_work(ohci);
  688. if (ohci->rh_state == OHCI_RH_RUNNING) {
  689. /*
  690. * Sometimes a controller just stops working. We can tell
  691. * by checking that the frame counter has advanced since
  692. * the last time we ran.
  693. *
  694. * But be careful: Some controllers violate the spec by
  695. * stopping their frame counter when no ports are active.
  696. */
  697. frame_no = ohci_frame_no(ohci);
  698. if (frame_no == ohci->prev_frame_no) {
  699. int active_cnt = 0;
  700. int i;
  701. unsigned tmp;
  702. for (i = 0; i < ohci->num_ports; ++i) {
  703. tmp = roothub_portstatus(ohci, i);
  704. /* Enabled and not suspended? */
  705. if ((tmp & RH_PS_PES) && !(tmp & RH_PS_PSS))
  706. ++active_cnt;
  707. }
  708. if (active_cnt > 0) {
  709. ohci_err(ohci, "frame counter not updating; disabled\n");
  710. goto died;
  711. }
  712. }
  713. if (!list_empty(&ohci->eds_in_use)) {
  714. ohci->prev_frame_no = frame_no;
  715. ohci->prev_wdh_cnt = ohci->wdh_cnt;
  716. ohci->prev_donehead = ohci_readl(ohci,
  717. &ohci->regs->donehead);
  718. mod_timer(&ohci->io_watchdog,
  719. jiffies + IO_WATCHDOG_DELAY);
  720. }
  721. }
  722. done:
  723. spin_unlock_irqrestore(&ohci->lock, flags);
  724. }
  725. /* an interrupt happens */
  726. static irqreturn_t ohci_irq (struct usb_hcd *hcd)
  727. {
  728. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  729. struct ohci_regs __iomem *regs = ohci->regs;
  730. int ints;
  731. /* Read interrupt status (and flush pending writes). We ignore the
  732. * optimization of checking the LSB of hcca->done_head; it doesn't
  733. * work on all systems (edge triggering for OHCI can be a factor).
  734. */
  735. ints = ohci_readl(ohci, &regs->intrstatus);
  736. /* Check for an all 1's result which is a typical consequence
  737. * of dead, unclocked, or unplugged (CardBus...) devices
  738. */
  739. if (ints == ~(u32)0) {
  740. ohci->rh_state = OHCI_RH_HALTED;
  741. ohci_dbg (ohci, "device removed!\n");
  742. usb_hc_died(hcd);
  743. return IRQ_HANDLED;
  744. }
  745. /* We only care about interrupts that are enabled */
  746. ints &= ohci_readl(ohci, &regs->intrenable);
  747. /* interrupt for some other device? */
  748. if (ints == 0 || unlikely(ohci->rh_state == OHCI_RH_HALTED))
  749. return IRQ_NOTMINE;
  750. if (ints & OHCI_INTR_UE) {
  751. // e.g. due to PCI Master/Target Abort
  752. if (quirk_nec(ohci)) {
  753. /* Workaround for a silicon bug in some NEC chips used
  754. * in Apple's PowerBooks. Adapted from Darwin code.
  755. */
  756. ohci_err (ohci, "OHCI Unrecoverable Error, scheduling NEC chip restart\n");
  757. ohci_writel (ohci, OHCI_INTR_UE, &regs->intrdisable);
  758. schedule_work (&ohci->nec_work);
  759. } else {
  760. ohci_err (ohci, "OHCI Unrecoverable Error, disabled\n");
  761. ohci->rh_state = OHCI_RH_HALTED;
  762. usb_hc_died(hcd);
  763. }
  764. ohci_dump(ohci);
  765. ohci_usb_reset (ohci);
  766. }
  767. if (ints & OHCI_INTR_RHSC) {
  768. ohci_dbg(ohci, "rhsc\n");
  769. ohci->next_statechange = jiffies + STATECHANGE_DELAY;
  770. ohci_writel(ohci, OHCI_INTR_RD | OHCI_INTR_RHSC,
  771. &regs->intrstatus);
  772. /* NOTE: Vendors didn't always make the same implementation
  773. * choices for RHSC. Many followed the spec; RHSC triggers
  774. * on an edge, like setting and maybe clearing a port status
  775. * change bit. With others it's level-triggered, active
  776. * until hub_wq clears all the port status change bits. We'll
  777. * always disable it here and rely on polling until hub_wq
  778. * re-enables it.
  779. */
  780. ohci_writel(ohci, OHCI_INTR_RHSC, &regs->intrdisable);
  781. usb_hcd_poll_rh_status(hcd);
  782. }
  783. /* For connect and disconnect events, we expect the controller
  784. * to turn on RHSC along with RD. But for remote wakeup events
  785. * this might not happen.
  786. */
  787. else if (ints & OHCI_INTR_RD) {
  788. ohci_dbg(ohci, "resume detect\n");
  789. ohci_writel(ohci, OHCI_INTR_RD, &regs->intrstatus);
  790. set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
  791. if (ohci->autostop) {
  792. spin_lock (&ohci->lock);
  793. ohci_rh_resume (ohci);
  794. spin_unlock (&ohci->lock);
  795. } else
  796. usb_hcd_resume_root_hub(hcd);
  797. }
  798. spin_lock(&ohci->lock);
  799. if (ints & OHCI_INTR_WDH)
  800. update_done_list(ohci);
  801. /* could track INTR_SO to reduce available PCI/... bandwidth */
  802. /* handle any pending URB/ED unlinks, leaving INTR_SF enabled
  803. * when there's still unlinking to be done (next frame).
  804. */
  805. ohci_work(ohci);
  806. if ((ints & OHCI_INTR_SF) != 0 && !ohci->ed_rm_list
  807. && ohci->rh_state == OHCI_RH_RUNNING)
  808. ohci_writel (ohci, OHCI_INTR_SF, &regs->intrdisable);
  809. if (ohci->rh_state == OHCI_RH_RUNNING) {
  810. ohci_writel (ohci, ints, &regs->intrstatus);
  811. if (ints & OHCI_INTR_WDH)
  812. ++ohci->wdh_cnt;
  813. ohci_writel (ohci, OHCI_INTR_MIE, &regs->intrenable);
  814. // flush those writes
  815. (void) ohci_readl (ohci, &ohci->regs->control);
  816. }
  817. spin_unlock(&ohci->lock);
  818. return IRQ_HANDLED;
  819. }
  820. /*-------------------------------------------------------------------------*/
  821. static void ohci_stop (struct usb_hcd *hcd)
  822. {
  823. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  824. ohci_dump(ohci);
  825. if (quirk_nec(ohci))
  826. flush_work(&ohci->nec_work);
  827. del_timer_sync(&ohci->io_watchdog);
  828. ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
  829. ohci_usb_reset(ohci);
  830. free_irq(hcd->irq, hcd);
  831. hcd->irq = 0;
  832. if (quirk_amdiso(ohci))
  833. usb_amd_dev_put();
  834. remove_debug_files (ohci);
  835. ohci_mem_cleanup (ohci);
  836. if (ohci->hcca) {
  837. dma_free_coherent (hcd->self.controller,
  838. sizeof *ohci->hcca,
  839. ohci->hcca, ohci->hcca_dma);
  840. ohci->hcca = NULL;
  841. ohci->hcca_dma = 0;
  842. }
  843. }
  844. /*-------------------------------------------------------------------------*/
  845. #if defined(CONFIG_PM) || defined(CONFIG_PCI)
  846. /* must not be called from interrupt context */
  847. int ohci_restart(struct ohci_hcd *ohci)
  848. {
  849. int temp;
  850. int i;
  851. struct urb_priv *priv;
  852. ohci_init(ohci);
  853. spin_lock_irq(&ohci->lock);
  854. ohci->rh_state = OHCI_RH_HALTED;
  855. /* Recycle any "live" eds/tds (and urbs). */
  856. if (!list_empty (&ohci->pending))
  857. ohci_dbg(ohci, "abort schedule...\n");
  858. list_for_each_entry (priv, &ohci->pending, pending) {
  859. struct urb *urb = priv->td[0]->urb;
  860. struct ed *ed = priv->ed;
  861. switch (ed->state) {
  862. case ED_OPER:
  863. ed->state = ED_UNLINK;
  864. ed->hwINFO |= cpu_to_hc32(ohci, ED_DEQUEUE);
  865. ed_deschedule (ohci, ed);
  866. ed->ed_next = ohci->ed_rm_list;
  867. ed->ed_prev = NULL;
  868. ohci->ed_rm_list = ed;
  869. /* FALLTHROUGH */
  870. case ED_UNLINK:
  871. break;
  872. default:
  873. ohci_dbg(ohci, "bogus ed %p state %d\n",
  874. ed, ed->state);
  875. }
  876. if (!urb->unlinked)
  877. urb->unlinked = -ESHUTDOWN;
  878. }
  879. ohci_work(ohci);
  880. spin_unlock_irq(&ohci->lock);
  881. /* paranoia, in case that didn't work: */
  882. /* empty the interrupt branches */
  883. for (i = 0; i < NUM_INTS; i++) ohci->load [i] = 0;
  884. for (i = 0; i < NUM_INTS; i++) ohci->hcca->int_table [i] = 0;
  885. /* no EDs to remove */
  886. ohci->ed_rm_list = NULL;
  887. /* empty control and bulk lists */
  888. ohci->ed_controltail = NULL;
  889. ohci->ed_bulktail = NULL;
  890. if ((temp = ohci_run (ohci)) < 0) {
  891. ohci_err (ohci, "can't restart, %d\n", temp);
  892. return temp;
  893. }
  894. ohci_dbg(ohci, "restart complete\n");
  895. return 0;
  896. }
  897. EXPORT_SYMBOL_GPL(ohci_restart);
  898. #endif
  899. #ifdef CONFIG_PM
  900. int ohci_suspend(struct usb_hcd *hcd, bool do_wakeup)
  901. {
  902. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  903. unsigned long flags;
  904. int rc = 0;
  905. /* Disable irq emission and mark HW unaccessible. Use
  906. * the spinlock to properly synchronize with possible pending
  907. * RH suspend or resume activity.
  908. */
  909. spin_lock_irqsave (&ohci->lock, flags);
  910. ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
  911. (void)ohci_readl(ohci, &ohci->regs->intrdisable);
  912. clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  913. spin_unlock_irqrestore (&ohci->lock, flags);
  914. synchronize_irq(hcd->irq);
  915. if (do_wakeup && HCD_WAKEUP_PENDING(hcd)) {
  916. ohci_resume(hcd, false);
  917. rc = -EBUSY;
  918. }
  919. return rc;
  920. }
  921. EXPORT_SYMBOL_GPL(ohci_suspend);
  922. int ohci_resume(struct usb_hcd *hcd, bool hibernated)
  923. {
  924. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  925. int port;
  926. bool need_reinit = false;
  927. set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  928. /* Make sure resume from hibernation re-enumerates everything */
  929. if (hibernated)
  930. ohci_usb_reset(ohci);
  931. /* See if the controller is already running or has been reset */
  932. ohci->hc_control = ohci_readl(ohci, &ohci->regs->control);
  933. if (ohci->hc_control & (OHCI_CTRL_IR | OHCI_SCHED_ENABLES)) {
  934. need_reinit = true;
  935. } else {
  936. switch (ohci->hc_control & OHCI_CTRL_HCFS) {
  937. case OHCI_USB_OPER:
  938. case OHCI_USB_RESET:
  939. need_reinit = true;
  940. }
  941. }
  942. /* If needed, reinitialize and suspend the root hub */
  943. if (need_reinit) {
  944. spin_lock_irq(&ohci->lock);
  945. ohci_rh_resume(ohci);
  946. ohci_rh_suspend(ohci, 0);
  947. spin_unlock_irq(&ohci->lock);
  948. }
  949. /* Normally just turn on port power and enable interrupts */
  950. else {
  951. ohci_dbg(ohci, "powerup ports\n");
  952. for (port = 0; port < ohci->num_ports; port++)
  953. ohci_writel(ohci, RH_PS_PPS,
  954. &ohci->regs->roothub.portstatus[port]);
  955. ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrenable);
  956. ohci_readl(ohci, &ohci->regs->intrenable);
  957. msleep(20);
  958. }
  959. usb_hcd_resume_root_hub(hcd);
  960. return 0;
  961. }
  962. EXPORT_SYMBOL_GPL(ohci_resume);
  963. #endif
  964. /*-------------------------------------------------------------------------*/
  965. /*
  966. * Generic structure: This gets copied for platform drivers so that
  967. * individual entries can be overridden as needed.
  968. */
  969. static const struct hc_driver ohci_hc_driver = {
  970. .description = hcd_name,
  971. .product_desc = "OHCI Host Controller",
  972. .hcd_priv_size = sizeof(struct ohci_hcd),
  973. /*
  974. * generic hardware linkage
  975. */
  976. .irq = ohci_irq,
  977. .flags = HCD_MEMORY | HCD_USB11,
  978. /*
  979. * basic lifecycle operations
  980. */
  981. .reset = ohci_setup,
  982. .start = ohci_start,
  983. .stop = ohci_stop,
  984. .shutdown = ohci_shutdown,
  985. /*
  986. * managing i/o requests and associated device resources
  987. */
  988. .urb_enqueue = ohci_urb_enqueue,
  989. .urb_dequeue = ohci_urb_dequeue,
  990. .endpoint_disable = ohci_endpoint_disable,
  991. /*
  992. * scheduling support
  993. */
  994. .get_frame_number = ohci_get_frame,
  995. /*
  996. * root hub support
  997. */
  998. .hub_status_data = ohci_hub_status_data,
  999. .hub_control = ohci_hub_control,
  1000. #ifdef CONFIG_PM
  1001. .bus_suspend = ohci_bus_suspend,
  1002. .bus_resume = ohci_bus_resume,
  1003. #endif
  1004. .start_port_reset = ohci_start_port_reset,
  1005. };
  1006. void ohci_init_driver(struct hc_driver *drv,
  1007. const struct ohci_driver_overrides *over)
  1008. {
  1009. /* Copy the generic table to drv and then apply the overrides */
  1010. *drv = ohci_hc_driver;
  1011. if (over) {
  1012. drv->product_desc = over->product_desc;
  1013. drv->hcd_priv_size += over->extra_priv_size;
  1014. if (over->reset)
  1015. drv->reset = over->reset;
  1016. }
  1017. }
  1018. EXPORT_SYMBOL_GPL(ohci_init_driver);
  1019. /*-------------------------------------------------------------------------*/
  1020. MODULE_AUTHOR (DRIVER_AUTHOR);
  1021. MODULE_DESCRIPTION(DRIVER_DESC);
  1022. MODULE_LICENSE ("GPL");
  1023. #if defined(CONFIG_ARCH_SA1100) && defined(CONFIG_SA1111)
  1024. #include "ohci-sa1111.c"
  1025. #define SA1111_DRIVER ohci_hcd_sa1111_driver
  1026. #endif
  1027. #ifdef CONFIG_USB_OHCI_HCD_DAVINCI
  1028. #include "ohci-da8xx.c"
  1029. #define DAVINCI_PLATFORM_DRIVER ohci_hcd_da8xx_driver
  1030. #endif
  1031. #ifdef CONFIG_USB_OHCI_HCD_PPC_OF
  1032. #include "ohci-ppc-of.c"
  1033. #define OF_PLATFORM_DRIVER ohci_hcd_ppc_of_driver
  1034. #endif
  1035. #ifdef CONFIG_PPC_PS3
  1036. #include "ohci-ps3.c"
  1037. #define PS3_SYSTEM_BUS_DRIVER ps3_ohci_driver
  1038. #endif
  1039. #ifdef CONFIG_MFD_SM501
  1040. #include "ohci-sm501.c"
  1041. #define SM501_OHCI_DRIVER ohci_hcd_sm501_driver
  1042. #endif
  1043. #ifdef CONFIG_MFD_TC6393XB
  1044. #include "ohci-tmio.c"
  1045. #define TMIO_OHCI_DRIVER ohci_hcd_tmio_driver
  1046. #endif
  1047. #ifdef CONFIG_MACH_JZ4740
  1048. #include "ohci-jz4740.c"
  1049. #define PLATFORM_DRIVER ohci_hcd_jz4740_driver
  1050. #endif
  1051. #ifdef CONFIG_TILE_USB
  1052. #include "ohci-tilegx.c"
  1053. #define PLATFORM_DRIVER ohci_hcd_tilegx_driver
  1054. #endif
  1055. static int __init ohci_hcd_mod_init(void)
  1056. {
  1057. int retval = 0;
  1058. if (usb_disabled())
  1059. return -ENODEV;
  1060. printk(KERN_INFO "%s: " DRIVER_DESC "\n", hcd_name);
  1061. pr_debug ("%s: block sizes: ed %Zd td %Zd\n", hcd_name,
  1062. sizeof (struct ed), sizeof (struct td));
  1063. set_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
  1064. ohci_debug_root = debugfs_create_dir("ohci", usb_debug_root);
  1065. if (!ohci_debug_root) {
  1066. retval = -ENOENT;
  1067. goto error_debug;
  1068. }
  1069. #ifdef PS3_SYSTEM_BUS_DRIVER
  1070. retval = ps3_ohci_driver_register(&PS3_SYSTEM_BUS_DRIVER);
  1071. if (retval < 0)
  1072. goto error_ps3;
  1073. #endif
  1074. #ifdef PLATFORM_DRIVER
  1075. retval = platform_driver_register(&PLATFORM_DRIVER);
  1076. if (retval < 0)
  1077. goto error_platform;
  1078. #endif
  1079. #ifdef OF_PLATFORM_DRIVER
  1080. retval = platform_driver_register(&OF_PLATFORM_DRIVER);
  1081. if (retval < 0)
  1082. goto error_of_platform;
  1083. #endif
  1084. #ifdef SA1111_DRIVER
  1085. retval = sa1111_driver_register(&SA1111_DRIVER);
  1086. if (retval < 0)
  1087. goto error_sa1111;
  1088. #endif
  1089. #ifdef SM501_OHCI_DRIVER
  1090. retval = platform_driver_register(&SM501_OHCI_DRIVER);
  1091. if (retval < 0)
  1092. goto error_sm501;
  1093. #endif
  1094. #ifdef TMIO_OHCI_DRIVER
  1095. retval = platform_driver_register(&TMIO_OHCI_DRIVER);
  1096. if (retval < 0)
  1097. goto error_tmio;
  1098. #endif
  1099. #ifdef DAVINCI_PLATFORM_DRIVER
  1100. retval = platform_driver_register(&DAVINCI_PLATFORM_DRIVER);
  1101. if (retval < 0)
  1102. goto error_davinci;
  1103. #endif
  1104. return retval;
  1105. /* Error path */
  1106. #ifdef DAVINCI_PLATFORM_DRIVER
  1107. platform_driver_unregister(&DAVINCI_PLATFORM_DRIVER);
  1108. error_davinci:
  1109. #endif
  1110. #ifdef TMIO_OHCI_DRIVER
  1111. platform_driver_unregister(&TMIO_OHCI_DRIVER);
  1112. error_tmio:
  1113. #endif
  1114. #ifdef SM501_OHCI_DRIVER
  1115. platform_driver_unregister(&SM501_OHCI_DRIVER);
  1116. error_sm501:
  1117. #endif
  1118. #ifdef SA1111_DRIVER
  1119. sa1111_driver_unregister(&SA1111_DRIVER);
  1120. error_sa1111:
  1121. #endif
  1122. #ifdef OF_PLATFORM_DRIVER
  1123. platform_driver_unregister(&OF_PLATFORM_DRIVER);
  1124. error_of_platform:
  1125. #endif
  1126. #ifdef PLATFORM_DRIVER
  1127. platform_driver_unregister(&PLATFORM_DRIVER);
  1128. error_platform:
  1129. #endif
  1130. #ifdef PS3_SYSTEM_BUS_DRIVER
  1131. ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
  1132. error_ps3:
  1133. #endif
  1134. debugfs_remove(ohci_debug_root);
  1135. ohci_debug_root = NULL;
  1136. error_debug:
  1137. clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
  1138. return retval;
  1139. }
  1140. module_init(ohci_hcd_mod_init);
  1141. static void __exit ohci_hcd_mod_exit(void)
  1142. {
  1143. #ifdef DAVINCI_PLATFORM_DRIVER
  1144. platform_driver_unregister(&DAVINCI_PLATFORM_DRIVER);
  1145. #endif
  1146. #ifdef TMIO_OHCI_DRIVER
  1147. platform_driver_unregister(&TMIO_OHCI_DRIVER);
  1148. #endif
  1149. #ifdef SM501_OHCI_DRIVER
  1150. platform_driver_unregister(&SM501_OHCI_DRIVER);
  1151. #endif
  1152. #ifdef SA1111_DRIVER
  1153. sa1111_driver_unregister(&SA1111_DRIVER);
  1154. #endif
  1155. #ifdef OF_PLATFORM_DRIVER
  1156. platform_driver_unregister(&OF_PLATFORM_DRIVER);
  1157. #endif
  1158. #ifdef PLATFORM_DRIVER
  1159. platform_driver_unregister(&PLATFORM_DRIVER);
  1160. #endif
  1161. #ifdef PS3_SYSTEM_BUS_DRIVER
  1162. ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
  1163. #endif
  1164. debugfs_remove(ohci_debug_root);
  1165. clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
  1166. }
  1167. module_exit(ohci_hcd_mod_exit);