ohci-hcd.c 33 KB

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