ohci-hcd.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297
  1. /*
  2. * OHCI HCD (Host Controller Driver) for USB.
  3. *
  4. * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
  5. * (C) Copyright 2000-2004 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. *
  13. * OHCI is the main "non-Intel/VIA" standard for USB 1.1 host controller
  14. * interfaces (though some non-x86 Intel chips use it). It supports
  15. * smarter hardware than UHCI. A download link for the spec available
  16. * through the http://www.usb.org website.
  17. *
  18. * This file is licenced under the GPL.
  19. */
  20. #include <linux/module.h>
  21. #include <linux/moduleparam.h>
  22. #include <linux/pci.h>
  23. #include <linux/kernel.h>
  24. #include <linux/delay.h>
  25. #include <linux/ioport.h>
  26. #include <linux/sched.h>
  27. #include <linux/slab.h>
  28. #include <linux/errno.h>
  29. #include <linux/init.h>
  30. #include <linux/timer.h>
  31. #include <linux/list.h>
  32. #include <linux/usb.h>
  33. #include <linux/usb/otg.h>
  34. #include <linux/usb/hcd.h>
  35. #include <linux/dma-mapping.h>
  36. #include <linux/dmapool.h>
  37. #include <linux/workqueue.h>
  38. #include <linux/debugfs.h>
  39. #include <asm/io.h>
  40. #include <asm/irq.h>
  41. #include <asm/system.h>
  42. #include <asm/unaligned.h>
  43. #include <asm/byteorder.h>
  44. #define DRIVER_AUTHOR "Roman Weissgaerber, David Brownell"
  45. #define DRIVER_DESC "USB 1.1 'Open' Host Controller (OHCI) Driver"
  46. /*-------------------------------------------------------------------------*/
  47. #undef OHCI_VERBOSE_DEBUG /* not always helpful */
  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. #include "ohci.h"
  65. #include "pci-quirks.h"
  66. static void ohci_dump (struct ohci_hcd *ohci, int verbose);
  67. static int ohci_init (struct ohci_hcd *ohci);
  68. static void ohci_stop (struct usb_hcd *hcd);
  69. #if defined(CONFIG_PM) || defined(CONFIG_PCI)
  70. static int ohci_restart (struct ohci_hcd *ohci);
  71. #endif
  72. #ifdef CONFIG_PCI
  73. static void sb800_prefetch(struct ohci_hcd *ohci, int on);
  74. #else
  75. static inline void sb800_prefetch(struct ohci_hcd *ohci, int on)
  76. {
  77. return;
  78. }
  79. #endif
  80. #include "ohci-hub.c"
  81. #include "ohci-dbg.c"
  82. #include "ohci-mem.c"
  83. #include "ohci-q.c"
  84. /*
  85. * On architectures with edge-triggered interrupts we must never return
  86. * IRQ_NONE.
  87. */
  88. #if defined(CONFIG_SA1111) /* ... or other edge-triggered systems */
  89. #define IRQ_NOTMINE IRQ_HANDLED
  90. #else
  91. #define IRQ_NOTMINE IRQ_NONE
  92. #endif
  93. /* Some boards misreport power switching/overcurrent */
  94. static int distrust_firmware = 1;
  95. module_param (distrust_firmware, bool, 0);
  96. MODULE_PARM_DESC (distrust_firmware,
  97. "true to distrust firmware power/overcurrent setup");
  98. /* Some boards leave IR set wrongly, since they fail BIOS/SMM handshakes */
  99. static int no_handshake = 0;
  100. module_param (no_handshake, bool, 0);
  101. MODULE_PARM_DESC (no_handshake, "true (not default) disables BIOS handshake");
  102. /*-------------------------------------------------------------------------*/
  103. /*
  104. * queue up an urb for anything except the root hub
  105. */
  106. static int ohci_urb_enqueue (
  107. struct usb_hcd *hcd,
  108. struct urb *urb,
  109. gfp_t mem_flags
  110. ) {
  111. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  112. struct ed *ed;
  113. urb_priv_t *urb_priv;
  114. unsigned int pipe = urb->pipe;
  115. int i, size = 0;
  116. unsigned long flags;
  117. int retval = 0;
  118. #ifdef OHCI_VERBOSE_DEBUG
  119. urb_print(urb, "SUB", usb_pipein(pipe), -EINPROGRESS);
  120. #endif
  121. /* every endpoint has a ed, locate and maybe (re)initialize it */
  122. if (! (ed = ed_get (ohci, urb->ep, urb->dev, pipe, urb->interval)))
  123. return -ENOMEM;
  124. /* for the private part of the URB we need the number of TDs (size) */
  125. switch (ed->type) {
  126. case PIPE_CONTROL:
  127. /* td_submit_urb() doesn't yet handle these */
  128. if (urb->transfer_buffer_length > 4096)
  129. return -EMSGSIZE;
  130. /* 1 TD for setup, 1 for ACK, plus ... */
  131. size = 2;
  132. /* FALLTHROUGH */
  133. // case PIPE_INTERRUPT:
  134. // case PIPE_BULK:
  135. default:
  136. /* one TD for every 4096 Bytes (can be up to 8K) */
  137. size += urb->transfer_buffer_length / 4096;
  138. /* ... and for any remaining bytes ... */
  139. if ((urb->transfer_buffer_length % 4096) != 0)
  140. size++;
  141. /* ... and maybe a zero length packet to wrap it up */
  142. if (size == 0)
  143. size++;
  144. else if ((urb->transfer_flags & URB_ZERO_PACKET) != 0
  145. && (urb->transfer_buffer_length
  146. % usb_maxpacket (urb->dev, pipe,
  147. usb_pipeout (pipe))) == 0)
  148. size++;
  149. break;
  150. case PIPE_ISOCHRONOUS: /* number of packets from URB */
  151. size = urb->number_of_packets;
  152. break;
  153. }
  154. /* allocate the private part of the URB */
  155. urb_priv = kzalloc (sizeof (urb_priv_t) + size * sizeof (struct td *),
  156. mem_flags);
  157. if (!urb_priv)
  158. return -ENOMEM;
  159. INIT_LIST_HEAD (&urb_priv->pending);
  160. urb_priv->length = size;
  161. urb_priv->ed = ed;
  162. /* allocate the TDs (deferring hash chain updates) */
  163. for (i = 0; i < size; i++) {
  164. urb_priv->td [i] = td_alloc (ohci, mem_flags);
  165. if (!urb_priv->td [i]) {
  166. urb_priv->length = i;
  167. urb_free_priv (ohci, urb_priv);
  168. return -ENOMEM;
  169. }
  170. }
  171. spin_lock_irqsave (&ohci->lock, flags);
  172. /* don't submit to a dead HC */
  173. if (!HCD_HW_ACCESSIBLE(hcd)) {
  174. retval = -ENODEV;
  175. goto fail;
  176. }
  177. if (!HC_IS_RUNNING(hcd->state)) {
  178. retval = -ENODEV;
  179. goto fail;
  180. }
  181. retval = usb_hcd_link_urb_to_ep(hcd, urb);
  182. if (retval)
  183. goto fail;
  184. /* schedule the ed if needed */
  185. if (ed->state == ED_IDLE) {
  186. retval = ed_schedule (ohci, ed);
  187. if (retval < 0) {
  188. usb_hcd_unlink_urb_from_ep(hcd, urb);
  189. goto fail;
  190. }
  191. if (ed->type == PIPE_ISOCHRONOUS) {
  192. u16 frame = ohci_frame_no(ohci);
  193. /* delay a few frames before the first TD */
  194. frame += max_t (u16, 8, ed->interval);
  195. frame &= ~(ed->interval - 1);
  196. frame |= ed->branch;
  197. urb->start_frame = frame;
  198. /* yes, only URB_ISO_ASAP is supported, and
  199. * urb->start_frame is never used as input.
  200. */
  201. }
  202. } else if (ed->type == PIPE_ISOCHRONOUS)
  203. urb->start_frame = ed->last_iso + ed->interval;
  204. /* fill the TDs and link them to the ed; and
  205. * enable that part of the schedule, if needed
  206. * and update count of queued periodic urbs
  207. */
  208. urb->hcpriv = urb_priv;
  209. td_submit_urb (ohci, urb);
  210. fail:
  211. if (retval)
  212. urb_free_priv (ohci, urb_priv);
  213. spin_unlock_irqrestore (&ohci->lock, flags);
  214. return retval;
  215. }
  216. /*
  217. * decouple the URB from the HC queues (TDs, urb_priv).
  218. * reporting is always done
  219. * asynchronously, and we might be dealing with an urb that's
  220. * partially transferred, or an ED with other urbs being unlinked.
  221. */
  222. static int ohci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
  223. {
  224. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  225. unsigned long flags;
  226. int rc;
  227. #ifdef OHCI_VERBOSE_DEBUG
  228. urb_print(urb, "UNLINK", 1, status);
  229. #endif
  230. spin_lock_irqsave (&ohci->lock, flags);
  231. rc = usb_hcd_check_unlink_urb(hcd, urb, status);
  232. if (rc) {
  233. ; /* Do nothing */
  234. } else if (HC_IS_RUNNING(hcd->state)) {
  235. urb_priv_t *urb_priv;
  236. /* Unless an IRQ completed the unlink while it was being
  237. * handed to us, flag it for unlink and giveback, and force
  238. * some upcoming INTR_SF to call finish_unlinks()
  239. */
  240. urb_priv = urb->hcpriv;
  241. if (urb_priv) {
  242. if (urb_priv->ed->state == ED_OPER)
  243. start_ed_unlink (ohci, urb_priv->ed);
  244. }
  245. } else {
  246. /*
  247. * with HC dead, we won't respect hc queue pointers
  248. * any more ... just clean up every urb's memory.
  249. */
  250. if (urb->hcpriv)
  251. finish_urb(ohci, urb, status);
  252. }
  253. spin_unlock_irqrestore (&ohci->lock, flags);
  254. return rc;
  255. }
  256. /*-------------------------------------------------------------------------*/
  257. /* frees config/altsetting state for endpoints,
  258. * including ED memory, dummy TD, and bulk/intr data toggle
  259. */
  260. static void
  261. ohci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  262. {
  263. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  264. unsigned long flags;
  265. struct ed *ed = ep->hcpriv;
  266. unsigned limit = 1000;
  267. /* ASSERT: any requests/urbs are being unlinked */
  268. /* ASSERT: nobody can be submitting urbs for this any more */
  269. if (!ed)
  270. return;
  271. rescan:
  272. spin_lock_irqsave (&ohci->lock, flags);
  273. if (!HC_IS_RUNNING (hcd->state)) {
  274. sanitize:
  275. ed->state = ED_IDLE;
  276. if (quirk_zfmicro(ohci) && ed->type == PIPE_INTERRUPT)
  277. ohci->eds_scheduled--;
  278. finish_unlinks (ohci, 0);
  279. }
  280. switch (ed->state) {
  281. case ED_UNLINK: /* wait for hw to finish? */
  282. /* major IRQ delivery trouble loses INTR_SF too... */
  283. if (limit-- == 0) {
  284. ohci_warn(ohci, "ED unlink timeout\n");
  285. if (quirk_zfmicro(ohci)) {
  286. ohci_warn(ohci, "Attempting ZF TD recovery\n");
  287. ohci->ed_to_check = ed;
  288. ohci->zf_delay = 2;
  289. }
  290. goto sanitize;
  291. }
  292. spin_unlock_irqrestore (&ohci->lock, flags);
  293. schedule_timeout_uninterruptible(1);
  294. goto rescan;
  295. case ED_IDLE: /* fully unlinked */
  296. if (list_empty (&ed->td_list)) {
  297. td_free (ohci, ed->dummy);
  298. ed_free (ohci, ed);
  299. break;
  300. }
  301. /* else FALL THROUGH */
  302. default:
  303. /* caller was supposed to have unlinked any requests;
  304. * that's not our job. can't recover; must leak ed.
  305. */
  306. ohci_err (ohci, "leak ed %p (#%02x) state %d%s\n",
  307. ed, ep->desc.bEndpointAddress, ed->state,
  308. list_empty (&ed->td_list) ? "" : " (has tds)");
  309. td_free (ohci, ed->dummy);
  310. break;
  311. }
  312. ep->hcpriv = NULL;
  313. spin_unlock_irqrestore (&ohci->lock, flags);
  314. }
  315. static int ohci_get_frame (struct usb_hcd *hcd)
  316. {
  317. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  318. return ohci_frame_no(ohci);
  319. }
  320. static void ohci_usb_reset (struct ohci_hcd *ohci)
  321. {
  322. ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
  323. ohci->hc_control &= OHCI_CTRL_RWC;
  324. ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
  325. }
  326. /* ohci_shutdown forcibly disables IRQs and DMA, helping kexec and
  327. * other cases where the next software may expect clean state from the
  328. * "firmware". this is bus-neutral, unlike shutdown() methods.
  329. */
  330. static void
  331. ohci_shutdown (struct usb_hcd *hcd)
  332. {
  333. struct ohci_hcd *ohci;
  334. ohci = hcd_to_ohci (hcd);
  335. ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
  336. ohci->hc_control = ohci_readl(ohci, &ohci->regs->control);
  337. /* If the SHUTDOWN quirk is set, don't put the controller in RESET */
  338. ohci->hc_control &= (ohci->flags & OHCI_QUIRK_SHUTDOWN ?
  339. OHCI_CTRL_RWC | OHCI_CTRL_HCFS :
  340. OHCI_CTRL_RWC);
  341. ohci_writel(ohci, ohci->hc_control, &ohci->regs->control);
  342. /* flush the writes */
  343. (void) ohci_readl (ohci, &ohci->regs->control);
  344. }
  345. static int check_ed(struct ohci_hcd *ohci, struct ed *ed)
  346. {
  347. return (hc32_to_cpu(ohci, ed->hwINFO) & ED_IN) != 0
  348. && (hc32_to_cpu(ohci, ed->hwHeadP) & TD_MASK)
  349. == (hc32_to_cpu(ohci, ed->hwTailP) & TD_MASK)
  350. && !list_empty(&ed->td_list);
  351. }
  352. /* ZF Micro watchdog timer callback. The ZF Micro chipset sometimes completes
  353. * an interrupt TD but neglects to add it to the donelist. On systems with
  354. * this chipset, we need to periodically check the state of the queues to look
  355. * for such "lost" TDs.
  356. */
  357. static void unlink_watchdog_func(unsigned long _ohci)
  358. {
  359. unsigned long flags;
  360. unsigned max;
  361. unsigned seen_count = 0;
  362. unsigned i;
  363. struct ed **seen = NULL;
  364. struct ohci_hcd *ohci = (struct ohci_hcd *) _ohci;
  365. spin_lock_irqsave(&ohci->lock, flags);
  366. max = ohci->eds_scheduled;
  367. if (!max)
  368. goto done;
  369. if (ohci->ed_to_check)
  370. goto out;
  371. seen = kcalloc(max, sizeof *seen, GFP_ATOMIC);
  372. if (!seen)
  373. goto out;
  374. for (i = 0; i < NUM_INTS; i++) {
  375. struct ed *ed = ohci->periodic[i];
  376. while (ed) {
  377. unsigned temp;
  378. /* scan this branch of the periodic schedule tree */
  379. for (temp = 0; temp < seen_count; temp++) {
  380. if (seen[temp] == ed) {
  381. /* we've checked it and what's after */
  382. ed = NULL;
  383. break;
  384. }
  385. }
  386. if (!ed)
  387. break;
  388. seen[seen_count++] = ed;
  389. if (!check_ed(ohci, ed)) {
  390. ed = ed->ed_next;
  391. continue;
  392. }
  393. /* HC's TD list is empty, but HCD sees at least one
  394. * TD that's not been sent through the donelist.
  395. */
  396. ohci->ed_to_check = ed;
  397. ohci->zf_delay = 2;
  398. /* The HC may wait until the next frame to report the
  399. * TD as done through the donelist and INTR_WDH. (We
  400. * just *assume* it's not a multi-TD interrupt URB;
  401. * those could defer the IRQ more than one frame, using
  402. * DI...) Check again after the next INTR_SF.
  403. */
  404. ohci_writel(ohci, OHCI_INTR_SF,
  405. &ohci->regs->intrstatus);
  406. ohci_writel(ohci, OHCI_INTR_SF,
  407. &ohci->regs->intrenable);
  408. /* flush those writes */
  409. (void) ohci_readl(ohci, &ohci->regs->control);
  410. goto out;
  411. }
  412. }
  413. out:
  414. kfree(seen);
  415. if (ohci->eds_scheduled)
  416. mod_timer(&ohci->unlink_watchdog, round_jiffies(jiffies + HZ));
  417. done:
  418. spin_unlock_irqrestore(&ohci->lock, flags);
  419. }
  420. /*-------------------------------------------------------------------------*
  421. * HC functions
  422. *-------------------------------------------------------------------------*/
  423. /* init memory, and kick BIOS/SMM off */
  424. static int ohci_init (struct ohci_hcd *ohci)
  425. {
  426. int ret;
  427. struct usb_hcd *hcd = ohci_to_hcd(ohci);
  428. if (distrust_firmware)
  429. ohci->flags |= OHCI_QUIRK_HUB_POWER;
  430. disable (ohci);
  431. ohci->regs = hcd->regs;
  432. /* REVISIT this BIOS handshake is now moved into PCI "quirks", and
  433. * was never needed for most non-PCI systems ... remove the code?
  434. */
  435. #ifndef IR_DISABLE
  436. /* SMM owns the HC? not for long! */
  437. if (!no_handshake && ohci_readl (ohci,
  438. &ohci->regs->control) & OHCI_CTRL_IR) {
  439. u32 temp;
  440. ohci_dbg (ohci, "USB HC TakeOver from BIOS/SMM\n");
  441. /* this timeout is arbitrary. we make it long, so systems
  442. * depending on usb keyboards may be usable even if the
  443. * BIOS/SMM code seems pretty broken.
  444. */
  445. temp = 500; /* arbitrary: five seconds */
  446. ohci_writel (ohci, OHCI_INTR_OC, &ohci->regs->intrenable);
  447. ohci_writel (ohci, OHCI_OCR, &ohci->regs->cmdstatus);
  448. while (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_IR) {
  449. msleep (10);
  450. if (--temp == 0) {
  451. ohci_err (ohci, "USB HC takeover failed!"
  452. " (BIOS/SMM bug)\n");
  453. return -EBUSY;
  454. }
  455. }
  456. ohci_usb_reset (ohci);
  457. }
  458. #endif
  459. /* Disable HC interrupts */
  460. ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
  461. /* flush the writes, and save key bits like RWC */
  462. if (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_RWC)
  463. ohci->hc_control |= OHCI_CTRL_RWC;
  464. /* Read the number of ports unless overridden */
  465. if (ohci->num_ports == 0)
  466. ohci->num_ports = roothub_a(ohci) & RH_A_NDP;
  467. if (ohci->hcca)
  468. return 0;
  469. ohci->hcca = dma_alloc_coherent (hcd->self.controller,
  470. sizeof *ohci->hcca, &ohci->hcca_dma, 0);
  471. if (!ohci->hcca)
  472. return -ENOMEM;
  473. if ((ret = ohci_mem_init (ohci)) < 0)
  474. ohci_stop (hcd);
  475. else {
  476. create_debug_files (ohci);
  477. }
  478. return ret;
  479. }
  480. /*-------------------------------------------------------------------------*/
  481. /* Start an OHCI controller, set the BUS operational
  482. * resets USB and controller
  483. * enable interrupts
  484. */
  485. static int ohci_run (struct ohci_hcd *ohci)
  486. {
  487. u32 mask, val;
  488. int first = ohci->fminterval == 0;
  489. struct usb_hcd *hcd = ohci_to_hcd(ohci);
  490. disable (ohci);
  491. /* boot firmware should have set this up (5.1.1.3.1) */
  492. if (first) {
  493. val = ohci_readl (ohci, &ohci->regs->fminterval);
  494. ohci->fminterval = val & 0x3fff;
  495. if (ohci->fminterval != FI)
  496. ohci_dbg (ohci, "fminterval delta %d\n",
  497. ohci->fminterval - FI);
  498. ohci->fminterval |= FSMP (ohci->fminterval) << 16;
  499. /* also: power/overcurrent flags in roothub.a */
  500. }
  501. /* Reset USB nearly "by the book". RemoteWakeupConnected has
  502. * to be checked in case boot firmware (BIOS/SMM/...) has set up
  503. * wakeup in a way the bus isn't aware of (e.g., legacy PCI PM).
  504. * If the bus glue detected wakeup capability then it should
  505. * already be enabled; if so we'll just enable it again.
  506. */
  507. if ((ohci->hc_control & OHCI_CTRL_RWC) != 0)
  508. device_set_wakeup_capable(hcd->self.controller, 1);
  509. switch (ohci->hc_control & OHCI_CTRL_HCFS) {
  510. case OHCI_USB_OPER:
  511. val = 0;
  512. break;
  513. case OHCI_USB_SUSPEND:
  514. case OHCI_USB_RESUME:
  515. ohci->hc_control &= OHCI_CTRL_RWC;
  516. ohci->hc_control |= OHCI_USB_RESUME;
  517. val = 10 /* msec wait */;
  518. break;
  519. // case OHCI_USB_RESET:
  520. default:
  521. ohci->hc_control &= OHCI_CTRL_RWC;
  522. ohci->hc_control |= OHCI_USB_RESET;
  523. val = 50 /* msec wait */;
  524. break;
  525. }
  526. ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
  527. // flush the writes
  528. (void) ohci_readl (ohci, &ohci->regs->control);
  529. msleep(val);
  530. memset (ohci->hcca, 0, sizeof (struct ohci_hcca));
  531. /* 2msec timelimit here means no irqs/preempt */
  532. spin_lock_irq (&ohci->lock);
  533. retry:
  534. /* HC Reset requires max 10 us delay */
  535. ohci_writel (ohci, OHCI_HCR, &ohci->regs->cmdstatus);
  536. val = 30; /* ... allow extra time */
  537. while ((ohci_readl (ohci, &ohci->regs->cmdstatus) & OHCI_HCR) != 0) {
  538. if (--val == 0) {
  539. spin_unlock_irq (&ohci->lock);
  540. ohci_err (ohci, "USB HC reset timed out!\n");
  541. return -1;
  542. }
  543. udelay (1);
  544. }
  545. /* now we're in the SUSPEND state ... must go OPERATIONAL
  546. * within 2msec else HC enters RESUME
  547. *
  548. * ... but some hardware won't init fmInterval "by the book"
  549. * (SiS, OPTi ...), so reset again instead. SiS doesn't need
  550. * this if we write fmInterval after we're OPERATIONAL.
  551. * Unclear about ALi, ServerWorks, and others ... this could
  552. * easily be a longstanding bug in chip init on Linux.
  553. */
  554. if (ohci->flags & OHCI_QUIRK_INITRESET) {
  555. ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
  556. // flush those writes
  557. (void) ohci_readl (ohci, &ohci->regs->control);
  558. }
  559. /* Tell the controller where the control and bulk lists are
  560. * The lists are empty now. */
  561. ohci_writel (ohci, 0, &ohci->regs->ed_controlhead);
  562. ohci_writel (ohci, 0, &ohci->regs->ed_bulkhead);
  563. /* a reset clears this */
  564. ohci_writel (ohci, (u32) ohci->hcca_dma, &ohci->regs->hcca);
  565. periodic_reinit (ohci);
  566. /* some OHCI implementations are finicky about how they init.
  567. * bogus values here mean not even enumeration could work.
  568. */
  569. if ((ohci_readl (ohci, &ohci->regs->fminterval) & 0x3fff0000) == 0
  570. || !ohci_readl (ohci, &ohci->regs->periodicstart)) {
  571. if (!(ohci->flags & OHCI_QUIRK_INITRESET)) {
  572. ohci->flags |= OHCI_QUIRK_INITRESET;
  573. ohci_dbg (ohci, "enabling initreset quirk\n");
  574. goto retry;
  575. }
  576. spin_unlock_irq (&ohci->lock);
  577. ohci_err (ohci, "init err (%08x %04x)\n",
  578. ohci_readl (ohci, &ohci->regs->fminterval),
  579. ohci_readl (ohci, &ohci->regs->periodicstart));
  580. return -EOVERFLOW;
  581. }
  582. /* use rhsc irqs after khubd is fully initialized */
  583. set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
  584. hcd->uses_new_polling = 1;
  585. /* start controller operations */
  586. ohci->hc_control &= OHCI_CTRL_RWC;
  587. ohci->hc_control |= OHCI_CONTROL_INIT | OHCI_USB_OPER;
  588. ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
  589. hcd->state = HC_STATE_RUNNING;
  590. /* wake on ConnectStatusChange, matching external hubs */
  591. ohci_writel (ohci, RH_HS_DRWE, &ohci->regs->roothub.status);
  592. /* Choose the interrupts we care about now, others later on demand */
  593. mask = OHCI_INTR_INIT;
  594. ohci_writel (ohci, ~0, &ohci->regs->intrstatus);
  595. ohci_writel (ohci, mask, &ohci->regs->intrenable);
  596. /* handle root hub init quirks ... */
  597. val = roothub_a (ohci);
  598. val &= ~(RH_A_PSM | RH_A_OCPM);
  599. if (ohci->flags & OHCI_QUIRK_SUPERIO) {
  600. /* NSC 87560 and maybe others */
  601. val |= RH_A_NOCP;
  602. val &= ~(RH_A_POTPGT | RH_A_NPS);
  603. ohci_writel (ohci, val, &ohci->regs->roothub.a);
  604. } else if ((ohci->flags & OHCI_QUIRK_AMD756) ||
  605. (ohci->flags & OHCI_QUIRK_HUB_POWER)) {
  606. /* hub power always on; required for AMD-756 and some
  607. * Mac platforms. ganged overcurrent reporting, if any.
  608. */
  609. val |= RH_A_NPS;
  610. ohci_writel (ohci, val, &ohci->regs->roothub.a);
  611. }
  612. ohci_writel (ohci, RH_HS_LPSC, &ohci->regs->roothub.status);
  613. ohci_writel (ohci, (val & RH_A_NPS) ? 0 : RH_B_PPCM,
  614. &ohci->regs->roothub.b);
  615. // flush those writes
  616. (void) ohci_readl (ohci, &ohci->regs->control);
  617. ohci->next_statechange = jiffies + STATECHANGE_DELAY;
  618. spin_unlock_irq (&ohci->lock);
  619. // POTPGT delay is bits 24-31, in 2 ms units.
  620. mdelay ((val >> 23) & 0x1fe);
  621. hcd->state = HC_STATE_RUNNING;
  622. if (quirk_zfmicro(ohci)) {
  623. /* Create timer to watch for bad queue state on ZF Micro */
  624. setup_timer(&ohci->unlink_watchdog, unlink_watchdog_func,
  625. (unsigned long) ohci);
  626. ohci->eds_scheduled = 0;
  627. ohci->ed_to_check = NULL;
  628. }
  629. ohci_dump (ohci, 1);
  630. return 0;
  631. }
  632. /*-------------------------------------------------------------------------*/
  633. /* an interrupt happens */
  634. static irqreturn_t ohci_irq (struct usb_hcd *hcd)
  635. {
  636. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  637. struct ohci_regs __iomem *regs = ohci->regs;
  638. int ints;
  639. /* Read interrupt status (and flush pending writes). We ignore the
  640. * optimization of checking the LSB of hcca->done_head; it doesn't
  641. * work on all systems (edge triggering for OHCI can be a factor).
  642. */
  643. ints = ohci_readl(ohci, &regs->intrstatus);
  644. /* Check for an all 1's result which is a typical consequence
  645. * of dead, unclocked, or unplugged (CardBus...) devices
  646. */
  647. if (ints == ~(u32)0) {
  648. disable (ohci);
  649. ohci_dbg (ohci, "device removed!\n");
  650. usb_hc_died(hcd);
  651. return IRQ_HANDLED;
  652. }
  653. /* We only care about interrupts that are enabled */
  654. ints &= ohci_readl(ohci, &regs->intrenable);
  655. /* interrupt for some other device? */
  656. if (ints == 0 || unlikely(hcd->state == HC_STATE_HALT))
  657. return IRQ_NOTMINE;
  658. if (ints & OHCI_INTR_UE) {
  659. // e.g. due to PCI Master/Target Abort
  660. if (quirk_nec(ohci)) {
  661. /* Workaround for a silicon bug in some NEC chips used
  662. * in Apple's PowerBooks. Adapted from Darwin code.
  663. */
  664. ohci_err (ohci, "OHCI Unrecoverable Error, scheduling NEC chip restart\n");
  665. ohci_writel (ohci, OHCI_INTR_UE, &regs->intrdisable);
  666. schedule_work (&ohci->nec_work);
  667. } else {
  668. disable (ohci);
  669. ohci_err (ohci, "OHCI Unrecoverable Error, disabled\n");
  670. usb_hc_died(hcd);
  671. }
  672. ohci_dump (ohci, 1);
  673. ohci_usb_reset (ohci);
  674. }
  675. if (ints & OHCI_INTR_RHSC) {
  676. ohci_vdbg(ohci, "rhsc\n");
  677. ohci->next_statechange = jiffies + STATECHANGE_DELAY;
  678. ohci_writel(ohci, OHCI_INTR_RD | OHCI_INTR_RHSC,
  679. &regs->intrstatus);
  680. /* NOTE: Vendors didn't always make the same implementation
  681. * choices for RHSC. Many followed the spec; RHSC triggers
  682. * on an edge, like setting and maybe clearing a port status
  683. * change bit. With others it's level-triggered, active
  684. * until khubd clears all the port status change bits. We'll
  685. * always disable it here and rely on polling until khubd
  686. * re-enables it.
  687. */
  688. ohci_writel(ohci, OHCI_INTR_RHSC, &regs->intrdisable);
  689. usb_hcd_poll_rh_status(hcd);
  690. }
  691. /* For connect and disconnect events, we expect the controller
  692. * to turn on RHSC along with RD. But for remote wakeup events
  693. * this might not happen.
  694. */
  695. else if (ints & OHCI_INTR_RD) {
  696. ohci_vdbg(ohci, "resume detect\n");
  697. ohci_writel(ohci, OHCI_INTR_RD, &regs->intrstatus);
  698. set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
  699. if (ohci->autostop) {
  700. spin_lock (&ohci->lock);
  701. ohci_rh_resume (ohci);
  702. spin_unlock (&ohci->lock);
  703. } else
  704. usb_hcd_resume_root_hub(hcd);
  705. }
  706. if (ints & OHCI_INTR_WDH) {
  707. spin_lock (&ohci->lock);
  708. dl_done_list (ohci);
  709. spin_unlock (&ohci->lock);
  710. }
  711. if (quirk_zfmicro(ohci) && (ints & OHCI_INTR_SF)) {
  712. spin_lock(&ohci->lock);
  713. if (ohci->ed_to_check) {
  714. struct ed *ed = ohci->ed_to_check;
  715. if (check_ed(ohci, ed)) {
  716. /* HC thinks the TD list is empty; HCD knows
  717. * at least one TD is outstanding
  718. */
  719. if (--ohci->zf_delay == 0) {
  720. struct td *td = list_entry(
  721. ed->td_list.next,
  722. struct td, td_list);
  723. ohci_warn(ohci,
  724. "Reclaiming orphan TD %p\n",
  725. td);
  726. takeback_td(ohci, td);
  727. ohci->ed_to_check = NULL;
  728. }
  729. } else
  730. ohci->ed_to_check = NULL;
  731. }
  732. spin_unlock(&ohci->lock);
  733. }
  734. /* could track INTR_SO to reduce available PCI/... bandwidth */
  735. /* handle any pending URB/ED unlinks, leaving INTR_SF enabled
  736. * when there's still unlinking to be done (next frame).
  737. */
  738. spin_lock (&ohci->lock);
  739. if (ohci->ed_rm_list)
  740. finish_unlinks (ohci, ohci_frame_no(ohci));
  741. if ((ints & OHCI_INTR_SF) != 0
  742. && !ohci->ed_rm_list
  743. && !ohci->ed_to_check
  744. && HC_IS_RUNNING(hcd->state))
  745. ohci_writel (ohci, OHCI_INTR_SF, &regs->intrdisable);
  746. spin_unlock (&ohci->lock);
  747. if (HC_IS_RUNNING(hcd->state)) {
  748. ohci_writel (ohci, ints, &regs->intrstatus);
  749. ohci_writel (ohci, OHCI_INTR_MIE, &regs->intrenable);
  750. // flush those writes
  751. (void) ohci_readl (ohci, &ohci->regs->control);
  752. }
  753. return IRQ_HANDLED;
  754. }
  755. /*-------------------------------------------------------------------------*/
  756. static void ohci_stop (struct usb_hcd *hcd)
  757. {
  758. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  759. ohci_dump (ohci, 1);
  760. if (quirk_nec(ohci))
  761. flush_work_sync(&ohci->nec_work);
  762. ohci_usb_reset (ohci);
  763. ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
  764. free_irq(hcd->irq, hcd);
  765. hcd->irq = -1;
  766. if (quirk_zfmicro(ohci))
  767. del_timer(&ohci->unlink_watchdog);
  768. if (quirk_amdiso(ohci))
  769. usb_amd_dev_put();
  770. remove_debug_files (ohci);
  771. ohci_mem_cleanup (ohci);
  772. if (ohci->hcca) {
  773. dma_free_coherent (hcd->self.controller,
  774. sizeof *ohci->hcca,
  775. ohci->hcca, ohci->hcca_dma);
  776. ohci->hcca = NULL;
  777. ohci->hcca_dma = 0;
  778. }
  779. }
  780. /*-------------------------------------------------------------------------*/
  781. #if defined(CONFIG_PM) || defined(CONFIG_PCI)
  782. /* must not be called from interrupt context */
  783. static int ohci_restart (struct ohci_hcd *ohci)
  784. {
  785. int temp;
  786. int i;
  787. struct urb_priv *priv;
  788. spin_lock_irq(&ohci->lock);
  789. disable (ohci);
  790. /* Recycle any "live" eds/tds (and urbs). */
  791. if (!list_empty (&ohci->pending))
  792. ohci_dbg(ohci, "abort schedule...\n");
  793. list_for_each_entry (priv, &ohci->pending, pending) {
  794. struct urb *urb = priv->td[0]->urb;
  795. struct ed *ed = priv->ed;
  796. switch (ed->state) {
  797. case ED_OPER:
  798. ed->state = ED_UNLINK;
  799. ed->hwINFO |= cpu_to_hc32(ohci, ED_DEQUEUE);
  800. ed_deschedule (ohci, ed);
  801. ed->ed_next = ohci->ed_rm_list;
  802. ed->ed_prev = NULL;
  803. ohci->ed_rm_list = ed;
  804. /* FALLTHROUGH */
  805. case ED_UNLINK:
  806. break;
  807. default:
  808. ohci_dbg(ohci, "bogus ed %p state %d\n",
  809. ed, ed->state);
  810. }
  811. if (!urb->unlinked)
  812. urb->unlinked = -ESHUTDOWN;
  813. }
  814. finish_unlinks (ohci, 0);
  815. spin_unlock_irq(&ohci->lock);
  816. /* paranoia, in case that didn't work: */
  817. /* empty the interrupt branches */
  818. for (i = 0; i < NUM_INTS; i++) ohci->load [i] = 0;
  819. for (i = 0; i < NUM_INTS; i++) ohci->hcca->int_table [i] = 0;
  820. /* no EDs to remove */
  821. ohci->ed_rm_list = NULL;
  822. /* empty control and bulk lists */
  823. ohci->ed_controltail = NULL;
  824. ohci->ed_bulktail = NULL;
  825. if ((temp = ohci_run (ohci)) < 0) {
  826. ohci_err (ohci, "can't restart, %d\n", temp);
  827. return temp;
  828. }
  829. ohci_dbg(ohci, "restart complete\n");
  830. return 0;
  831. }
  832. #endif
  833. /*-------------------------------------------------------------------------*/
  834. MODULE_AUTHOR (DRIVER_AUTHOR);
  835. MODULE_DESCRIPTION(DRIVER_DESC);
  836. MODULE_LICENSE ("GPL");
  837. #ifdef CONFIG_PCI
  838. #include "ohci-pci.c"
  839. #define PCI_DRIVER ohci_pci_driver
  840. #endif
  841. #if defined(CONFIG_ARCH_SA1100) && defined(CONFIG_SA1111)
  842. #include "ohci-sa1111.c"
  843. #define SA1111_DRIVER ohci_hcd_sa1111_driver
  844. #endif
  845. #if defined(CONFIG_ARCH_S3C2410) || defined(CONFIG_ARCH_S3C64XX)
  846. #include "ohci-s3c2410.c"
  847. #define PLATFORM_DRIVER ohci_hcd_s3c2410_driver
  848. #endif
  849. #ifdef CONFIG_USB_OHCI_HCD_OMAP1
  850. #include "ohci-omap.c"
  851. #define OMAP1_PLATFORM_DRIVER ohci_hcd_omap_driver
  852. #endif
  853. #ifdef CONFIG_USB_OHCI_HCD_OMAP3
  854. #include "ohci-omap3.c"
  855. #define OMAP3_PLATFORM_DRIVER ohci_hcd_omap3_driver
  856. #endif
  857. #if defined(CONFIG_PXA27x) || defined(CONFIG_PXA3xx)
  858. #include "ohci-pxa27x.c"
  859. #define PLATFORM_DRIVER ohci_hcd_pxa27x_driver
  860. #endif
  861. #ifdef CONFIG_ARCH_EP93XX
  862. #include "ohci-ep93xx.c"
  863. #define PLATFORM_DRIVER ohci_hcd_ep93xx_driver
  864. #endif
  865. #ifdef CONFIG_MIPS_ALCHEMY
  866. #include "ohci-au1xxx.c"
  867. #define PLATFORM_DRIVER ohci_hcd_au1xxx_driver
  868. #endif
  869. #ifdef CONFIG_PNX8550
  870. #include "ohci-pnx8550.c"
  871. #define PLATFORM_DRIVER ohci_hcd_pnx8550_driver
  872. #endif
  873. #ifdef CONFIG_USB_OHCI_HCD_PPC_SOC
  874. #include "ohci-ppc-soc.c"
  875. #define PLATFORM_DRIVER ohci_hcd_ppc_soc_driver
  876. #endif
  877. #ifdef CONFIG_ARCH_AT91
  878. #include "ohci-at91.c"
  879. #define PLATFORM_DRIVER ohci_hcd_at91_driver
  880. #endif
  881. #ifdef CONFIG_ARCH_PNX4008
  882. #include "ohci-pnx4008.c"
  883. #define PLATFORM_DRIVER usb_hcd_pnx4008_driver
  884. #endif
  885. #ifdef CONFIG_ARCH_DAVINCI_DA8XX
  886. #include "ohci-da8xx.c"
  887. #define PLATFORM_DRIVER ohci_hcd_da8xx_driver
  888. #endif
  889. #ifdef CONFIG_USB_OHCI_SH
  890. #include "ohci-sh.c"
  891. #define PLATFORM_DRIVER ohci_hcd_sh_driver
  892. #endif
  893. #ifdef CONFIG_USB_OHCI_HCD_PPC_OF
  894. #include "ohci-ppc-of.c"
  895. #define OF_PLATFORM_DRIVER ohci_hcd_ppc_of_driver
  896. #endif
  897. #ifdef CONFIG_PLAT_SPEAR
  898. #include "ohci-spear.c"
  899. #define PLATFORM_DRIVER spear_ohci_hcd_driver
  900. #endif
  901. #ifdef CONFIG_PPC_PS3
  902. #include "ohci-ps3.c"
  903. #define PS3_SYSTEM_BUS_DRIVER ps3_ohci_driver
  904. #endif
  905. #ifdef CONFIG_USB_OHCI_HCD_SSB
  906. #include "ohci-ssb.c"
  907. #define SSB_OHCI_DRIVER ssb_ohci_driver
  908. #endif
  909. #ifdef CONFIG_MFD_SM501
  910. #include "ohci-sm501.c"
  911. #define SM501_OHCI_DRIVER ohci_hcd_sm501_driver
  912. #endif
  913. #ifdef CONFIG_MFD_TC6393XB
  914. #include "ohci-tmio.c"
  915. #define TMIO_OHCI_DRIVER ohci_hcd_tmio_driver
  916. #endif
  917. #ifdef CONFIG_MACH_JZ4740
  918. #include "ohci-jz4740.c"
  919. #define PLATFORM_DRIVER ohci_hcd_jz4740_driver
  920. #endif
  921. #ifdef CONFIG_USB_OCTEON_OHCI
  922. #include "ohci-octeon.c"
  923. #define PLATFORM_DRIVER ohci_octeon_driver
  924. #endif
  925. #ifdef CONFIG_USB_CNS3XXX_OHCI
  926. #include "ohci-cns3xxx.c"
  927. #define PLATFORM_DRIVER ohci_hcd_cns3xxx_driver
  928. #endif
  929. #ifdef CONFIG_USB_OHCI_ATH79
  930. #include "ohci-ath79.c"
  931. #define PLATFORM_DRIVER ohci_hcd_ath79_driver
  932. #endif
  933. #if !defined(PCI_DRIVER) && \
  934. !defined(PLATFORM_DRIVER) && \
  935. !defined(OMAP1_PLATFORM_DRIVER) && \
  936. !defined(OMAP3_PLATFORM_DRIVER) && \
  937. !defined(OF_PLATFORM_DRIVER) && \
  938. !defined(SA1111_DRIVER) && \
  939. !defined(PS3_SYSTEM_BUS_DRIVER) && \
  940. !defined(SM501_OHCI_DRIVER) && \
  941. !defined(TMIO_OHCI_DRIVER) && \
  942. !defined(SSB_OHCI_DRIVER)
  943. #error "missing bus glue for ohci-hcd"
  944. #endif
  945. static int __init ohci_hcd_mod_init(void)
  946. {
  947. int retval = 0;
  948. if (usb_disabled())
  949. return -ENODEV;
  950. printk(KERN_INFO "%s: " DRIVER_DESC "\n", hcd_name);
  951. pr_debug ("%s: block sizes: ed %Zd td %Zd\n", hcd_name,
  952. sizeof (struct ed), sizeof (struct td));
  953. set_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
  954. #ifdef DEBUG
  955. ohci_debug_root = debugfs_create_dir("ohci", usb_debug_root);
  956. if (!ohci_debug_root) {
  957. retval = -ENOENT;
  958. goto error_debug;
  959. }
  960. #endif
  961. #ifdef PS3_SYSTEM_BUS_DRIVER
  962. retval = ps3_ohci_driver_register(&PS3_SYSTEM_BUS_DRIVER);
  963. if (retval < 0)
  964. goto error_ps3;
  965. #endif
  966. #ifdef PLATFORM_DRIVER
  967. retval = platform_driver_register(&PLATFORM_DRIVER);
  968. if (retval < 0)
  969. goto error_platform;
  970. #endif
  971. #ifdef OMAP1_PLATFORM_DRIVER
  972. retval = platform_driver_register(&OMAP1_PLATFORM_DRIVER);
  973. if (retval < 0)
  974. goto error_omap1_platform;
  975. #endif
  976. #ifdef OMAP3_PLATFORM_DRIVER
  977. retval = platform_driver_register(&OMAP3_PLATFORM_DRIVER);
  978. if (retval < 0)
  979. goto error_omap3_platform;
  980. #endif
  981. #ifdef OF_PLATFORM_DRIVER
  982. retval = platform_driver_register(&OF_PLATFORM_DRIVER);
  983. if (retval < 0)
  984. goto error_of_platform;
  985. #endif
  986. #ifdef SA1111_DRIVER
  987. retval = sa1111_driver_register(&SA1111_DRIVER);
  988. if (retval < 0)
  989. goto error_sa1111;
  990. #endif
  991. #ifdef PCI_DRIVER
  992. retval = pci_register_driver(&PCI_DRIVER);
  993. if (retval < 0)
  994. goto error_pci;
  995. #endif
  996. #ifdef SSB_OHCI_DRIVER
  997. retval = ssb_driver_register(&SSB_OHCI_DRIVER);
  998. if (retval)
  999. goto error_ssb;
  1000. #endif
  1001. #ifdef SM501_OHCI_DRIVER
  1002. retval = platform_driver_register(&SM501_OHCI_DRIVER);
  1003. if (retval < 0)
  1004. goto error_sm501;
  1005. #endif
  1006. #ifdef TMIO_OHCI_DRIVER
  1007. retval = platform_driver_register(&TMIO_OHCI_DRIVER);
  1008. if (retval < 0)
  1009. goto error_tmio;
  1010. #endif
  1011. return retval;
  1012. /* Error path */
  1013. #ifdef TMIO_OHCI_DRIVER
  1014. platform_driver_unregister(&TMIO_OHCI_DRIVER);
  1015. error_tmio:
  1016. #endif
  1017. #ifdef SM501_OHCI_DRIVER
  1018. platform_driver_unregister(&SM501_OHCI_DRIVER);
  1019. error_sm501:
  1020. #endif
  1021. #ifdef SSB_OHCI_DRIVER
  1022. ssb_driver_unregister(&SSB_OHCI_DRIVER);
  1023. error_ssb:
  1024. #endif
  1025. #ifdef PCI_DRIVER
  1026. pci_unregister_driver(&PCI_DRIVER);
  1027. error_pci:
  1028. #endif
  1029. #ifdef SA1111_DRIVER
  1030. sa1111_driver_unregister(&SA1111_DRIVER);
  1031. error_sa1111:
  1032. #endif
  1033. #ifdef OF_PLATFORM_DRIVER
  1034. platform_driver_unregister(&OF_PLATFORM_DRIVER);
  1035. error_of_platform:
  1036. #endif
  1037. #ifdef PLATFORM_DRIVER
  1038. platform_driver_unregister(&PLATFORM_DRIVER);
  1039. error_platform:
  1040. #endif
  1041. #ifdef OMAP1_PLATFORM_DRIVER
  1042. platform_driver_unregister(&OMAP1_PLATFORM_DRIVER);
  1043. error_omap1_platform:
  1044. #endif
  1045. #ifdef OMAP3_PLATFORM_DRIVER
  1046. platform_driver_unregister(&OMAP3_PLATFORM_DRIVER);
  1047. error_omap3_platform:
  1048. #endif
  1049. #ifdef PS3_SYSTEM_BUS_DRIVER
  1050. ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
  1051. error_ps3:
  1052. #endif
  1053. #ifdef DEBUG
  1054. debugfs_remove(ohci_debug_root);
  1055. ohci_debug_root = NULL;
  1056. error_debug:
  1057. #endif
  1058. clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
  1059. return retval;
  1060. }
  1061. module_init(ohci_hcd_mod_init);
  1062. static void __exit ohci_hcd_mod_exit(void)
  1063. {
  1064. #ifdef TMIO_OHCI_DRIVER
  1065. platform_driver_unregister(&TMIO_OHCI_DRIVER);
  1066. #endif
  1067. #ifdef SM501_OHCI_DRIVER
  1068. platform_driver_unregister(&SM501_OHCI_DRIVER);
  1069. #endif
  1070. #ifdef SSB_OHCI_DRIVER
  1071. ssb_driver_unregister(&SSB_OHCI_DRIVER);
  1072. #endif
  1073. #ifdef PCI_DRIVER
  1074. pci_unregister_driver(&PCI_DRIVER);
  1075. #endif
  1076. #ifdef SA1111_DRIVER
  1077. sa1111_driver_unregister(&SA1111_DRIVER);
  1078. #endif
  1079. #ifdef OF_PLATFORM_DRIVER
  1080. platform_driver_unregister(&OF_PLATFORM_DRIVER);
  1081. #endif
  1082. #ifdef PLATFORM_DRIVER
  1083. platform_driver_unregister(&PLATFORM_DRIVER);
  1084. #endif
  1085. #ifdef OMAP3_PLATFORM_DRIVER
  1086. platform_driver_unregister(&OMAP3_PLATFORM_DRIVER);
  1087. #endif
  1088. #ifdef PS3_SYSTEM_BUS_DRIVER
  1089. ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
  1090. #endif
  1091. #ifdef DEBUG
  1092. debugfs_remove(ohci_debug_root);
  1093. #endif
  1094. clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
  1095. }
  1096. module_exit(ohci_hcd_mod_exit);