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