ohci-hcd.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299
  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/system.h>
  44. #include <asm/unaligned.h>
  45. #include <asm/byteorder.h>
  46. #define DRIVER_AUTHOR "Roman Weissgaerber, David Brownell"
  47. #define DRIVER_DESC "USB 1.1 'Open' Host Controller (OHCI) Driver"
  48. /*-------------------------------------------------------------------------*/
  49. #undef OHCI_VERBOSE_DEBUG /* not always helpful */
  50. /* For initializing controller (mask in an HCFS mode too) */
  51. #define OHCI_CONTROL_INIT OHCI_CTRL_CBSR
  52. #define OHCI_INTR_INIT \
  53. (OHCI_INTR_MIE | OHCI_INTR_RHSC | OHCI_INTR_UE \
  54. | OHCI_INTR_RD | OHCI_INTR_WDH)
  55. #ifdef __hppa__
  56. /* On PA-RISC, PDC can leave IR set incorrectly; ignore it there. */
  57. #define IR_DISABLE
  58. #endif
  59. #ifdef CONFIG_ARCH_OMAP
  60. /* OMAP doesn't support IR (no SMM; not needed) */
  61. #define IR_DISABLE
  62. #endif
  63. /*-------------------------------------------------------------------------*/
  64. static const char hcd_name [] = "ohci_hcd";
  65. #define STATECHANGE_DELAY msecs_to_jiffies(300)
  66. #include "ohci.h"
  67. #include "pci-quirks.h"
  68. static void ohci_dump (struct ohci_hcd *ohci, int verbose);
  69. static int ohci_init (struct ohci_hcd *ohci);
  70. static void ohci_stop (struct usb_hcd *hcd);
  71. #if defined(CONFIG_PM) || defined(CONFIG_PCI)
  72. static int ohci_restart (struct ohci_hcd *ohci);
  73. #endif
  74. #ifdef CONFIG_PCI
  75. static void sb800_prefetch(struct ohci_hcd *ohci, int on);
  76. #else
  77. static inline void sb800_prefetch(struct ohci_hcd *ohci, int on)
  78. {
  79. return;
  80. }
  81. #endif
  82. #include "ohci-hub.c"
  83. #include "ohci-dbg.c"
  84. #include "ohci-mem.c"
  85. #include "ohci-q.c"
  86. /*
  87. * On architectures with edge-triggered interrupts we must never return
  88. * IRQ_NONE.
  89. */
  90. #if defined(CONFIG_SA1111) /* ... or other edge-triggered systems */
  91. #define IRQ_NOTMINE IRQ_HANDLED
  92. #else
  93. #define IRQ_NOTMINE IRQ_NONE
  94. #endif
  95. /* Some boards misreport power switching/overcurrent */
  96. static int distrust_firmware = 1;
  97. module_param (distrust_firmware, bool, 0);
  98. MODULE_PARM_DESC (distrust_firmware,
  99. "true to distrust firmware power/overcurrent setup");
  100. /* Some boards leave IR set wrongly, since they fail BIOS/SMM handshakes */
  101. static int no_handshake = 0;
  102. module_param (no_handshake, bool, 0);
  103. MODULE_PARM_DESC (no_handshake, "true (not default) disables BIOS handshake");
  104. /*-------------------------------------------------------------------------*/
  105. /*
  106. * queue up an urb for anything except the root hub
  107. */
  108. static int ohci_urb_enqueue (
  109. struct usb_hcd *hcd,
  110. struct urb *urb,
  111. gfp_t mem_flags
  112. ) {
  113. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  114. struct ed *ed;
  115. urb_priv_t *urb_priv;
  116. unsigned int pipe = urb->pipe;
  117. int i, size = 0;
  118. unsigned long flags;
  119. int retval = 0;
  120. #ifdef OHCI_VERBOSE_DEBUG
  121. urb_print(urb, "SUB", usb_pipein(pipe), -EINPROGRESS);
  122. #endif
  123. /* every endpoint has a ed, locate and maybe (re)initialize it */
  124. if (! (ed = ed_get (ohci, urb->ep, urb->dev, pipe, urb->interval)))
  125. return -ENOMEM;
  126. /* for the private part of the URB we need the number of TDs (size) */
  127. switch (ed->type) {
  128. case PIPE_CONTROL:
  129. /* td_submit_urb() doesn't yet handle these */
  130. if (urb->transfer_buffer_length > 4096)
  131. return -EMSGSIZE;
  132. /* 1 TD for setup, 1 for ACK, plus ... */
  133. size = 2;
  134. /* FALLTHROUGH */
  135. // case PIPE_INTERRUPT:
  136. // case PIPE_BULK:
  137. default:
  138. /* one TD for every 4096 Bytes (can be up to 8K) */
  139. size += urb->transfer_buffer_length / 4096;
  140. /* ... and for any remaining bytes ... */
  141. if ((urb->transfer_buffer_length % 4096) != 0)
  142. size++;
  143. /* ... and maybe a zero length packet to wrap it up */
  144. if (size == 0)
  145. size++;
  146. else if ((urb->transfer_flags & URB_ZERO_PACKET) != 0
  147. && (urb->transfer_buffer_length
  148. % usb_maxpacket (urb->dev, pipe,
  149. usb_pipeout (pipe))) == 0)
  150. size++;
  151. break;
  152. case PIPE_ISOCHRONOUS: /* number of packets from URB */
  153. size = urb->number_of_packets;
  154. break;
  155. }
  156. /* allocate the private part of the URB */
  157. urb_priv = kzalloc (sizeof (urb_priv_t) + size * sizeof (struct td *),
  158. mem_flags);
  159. if (!urb_priv)
  160. return -ENOMEM;
  161. INIT_LIST_HEAD (&urb_priv->pending);
  162. urb_priv->length = size;
  163. urb_priv->ed = ed;
  164. /* allocate the TDs (deferring hash chain updates) */
  165. for (i = 0; i < size; i++) {
  166. urb_priv->td [i] = td_alloc (ohci, mem_flags);
  167. if (!urb_priv->td [i]) {
  168. urb_priv->length = i;
  169. urb_free_priv (ohci, urb_priv);
  170. return -ENOMEM;
  171. }
  172. }
  173. spin_lock_irqsave (&ohci->lock, flags);
  174. /* don't submit to a dead HC */
  175. if (!HCD_HW_ACCESSIBLE(hcd)) {
  176. retval = -ENODEV;
  177. goto fail;
  178. }
  179. if (!HC_IS_RUNNING(hcd->state)) {
  180. retval = -ENODEV;
  181. goto fail;
  182. }
  183. retval = usb_hcd_link_urb_to_ep(hcd, urb);
  184. if (retval)
  185. goto fail;
  186. /* schedule the ed if needed */
  187. if (ed->state == ED_IDLE) {
  188. retval = ed_schedule (ohci, ed);
  189. if (retval < 0) {
  190. usb_hcd_unlink_urb_from_ep(hcd, urb);
  191. goto fail;
  192. }
  193. if (ed->type == PIPE_ISOCHRONOUS) {
  194. u16 frame = ohci_frame_no(ohci);
  195. /* delay a few frames before the first TD */
  196. frame += max_t (u16, 8, ed->interval);
  197. frame &= ~(ed->interval - 1);
  198. frame |= ed->branch;
  199. urb->start_frame = frame;
  200. /* yes, only URB_ISO_ASAP is supported, and
  201. * urb->start_frame is never used as input.
  202. */
  203. }
  204. } else if (ed->type == PIPE_ISOCHRONOUS)
  205. urb->start_frame = ed->last_iso + ed->interval;
  206. /* fill the TDs and link them to the ed; and
  207. * enable that part of the schedule, if needed
  208. * and update count of queued periodic urbs
  209. */
  210. urb->hcpriv = urb_priv;
  211. td_submit_urb (ohci, urb);
  212. fail:
  213. if (retval)
  214. urb_free_priv (ohci, urb_priv);
  215. spin_unlock_irqrestore (&ohci->lock, flags);
  216. return retval;
  217. }
  218. /*
  219. * decouple the URB from the HC queues (TDs, urb_priv).
  220. * reporting is always done
  221. * asynchronously, and we might be dealing with an urb that's
  222. * partially transferred, or an ED with other urbs being unlinked.
  223. */
  224. static int ohci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
  225. {
  226. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  227. unsigned long flags;
  228. int rc;
  229. #ifdef OHCI_VERBOSE_DEBUG
  230. urb_print(urb, "UNLINK", 1, status);
  231. #endif
  232. spin_lock_irqsave (&ohci->lock, flags);
  233. rc = usb_hcd_check_unlink_urb(hcd, urb, status);
  234. if (rc) {
  235. ; /* Do nothing */
  236. } else if (HC_IS_RUNNING(hcd->state)) {
  237. urb_priv_t *urb_priv;
  238. /* Unless an IRQ completed the unlink while it was being
  239. * handed to us, flag it for unlink and giveback, and force
  240. * some upcoming INTR_SF to call finish_unlinks()
  241. */
  242. urb_priv = urb->hcpriv;
  243. if (urb_priv) {
  244. if (urb_priv->ed->state == ED_OPER)
  245. start_ed_unlink (ohci, urb_priv->ed);
  246. }
  247. } else {
  248. /*
  249. * with HC dead, we won't respect hc queue pointers
  250. * any more ... just clean up every urb's memory.
  251. */
  252. if (urb->hcpriv)
  253. finish_urb(ohci, urb, status);
  254. }
  255. spin_unlock_irqrestore (&ohci->lock, flags);
  256. return rc;
  257. }
  258. /*-------------------------------------------------------------------------*/
  259. /* frees config/altsetting state for endpoints,
  260. * including ED memory, dummy TD, and bulk/intr data toggle
  261. */
  262. static void
  263. ohci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  264. {
  265. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  266. unsigned long flags;
  267. struct ed *ed = ep->hcpriv;
  268. unsigned limit = 1000;
  269. /* ASSERT: any requests/urbs are being unlinked */
  270. /* ASSERT: nobody can be submitting urbs for this any more */
  271. if (!ed)
  272. return;
  273. rescan:
  274. spin_lock_irqsave (&ohci->lock, flags);
  275. if (!HC_IS_RUNNING (hcd->state)) {
  276. sanitize:
  277. ed->state = ED_IDLE;
  278. if (quirk_zfmicro(ohci) && ed->type == PIPE_INTERRUPT)
  279. ohci->eds_scheduled--;
  280. finish_unlinks (ohci, 0);
  281. }
  282. switch (ed->state) {
  283. case ED_UNLINK: /* wait for hw to finish? */
  284. /* major IRQ delivery trouble loses INTR_SF too... */
  285. if (limit-- == 0) {
  286. ohci_warn(ohci, "ED unlink timeout\n");
  287. if (quirk_zfmicro(ohci)) {
  288. ohci_warn(ohci, "Attempting ZF TD recovery\n");
  289. ohci->ed_to_check = ed;
  290. ohci->zf_delay = 2;
  291. }
  292. goto sanitize;
  293. }
  294. spin_unlock_irqrestore (&ohci->lock, flags);
  295. schedule_timeout_uninterruptible(1);
  296. goto rescan;
  297. case ED_IDLE: /* fully unlinked */
  298. if (list_empty (&ed->td_list)) {
  299. td_free (ohci, ed->dummy);
  300. ed_free (ohci, ed);
  301. break;
  302. }
  303. /* else FALL THROUGH */
  304. default:
  305. /* caller was supposed to have unlinked any requests;
  306. * that's not our job. can't recover; must leak ed.
  307. */
  308. ohci_err (ohci, "leak ed %p (#%02x) state %d%s\n",
  309. ed, ep->desc.bEndpointAddress, ed->state,
  310. list_empty (&ed->td_list) ? "" : " (has tds)");
  311. td_free (ohci, ed->dummy);
  312. break;
  313. }
  314. ep->hcpriv = NULL;
  315. spin_unlock_irqrestore (&ohci->lock, flags);
  316. }
  317. static int ohci_get_frame (struct usb_hcd *hcd)
  318. {
  319. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  320. return ohci_frame_no(ohci);
  321. }
  322. static void ohci_usb_reset (struct ohci_hcd *ohci)
  323. {
  324. ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
  325. ohci->hc_control &= OHCI_CTRL_RWC;
  326. ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
  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, OHCI_INTR_MIE, &ohci->regs->intrdisable);
  338. ohci->hc_control = ohci_readl(ohci, &ohci->regs->control);
  339. /* If the SHUTDOWN quirk is set, don't put the controller in RESET */
  340. ohci->hc_control &= (ohci->flags & OHCI_QUIRK_SHUTDOWN ?
  341. OHCI_CTRL_RWC | OHCI_CTRL_HCFS :
  342. OHCI_CTRL_RWC);
  343. ohci_writel(ohci, ohci->hc_control, &ohci->regs->control);
  344. /* flush the writes */
  345. (void) ohci_readl (ohci, &ohci->regs->control);
  346. }
  347. static int check_ed(struct ohci_hcd *ohci, struct ed *ed)
  348. {
  349. return (hc32_to_cpu(ohci, ed->hwINFO) & ED_IN) != 0
  350. && (hc32_to_cpu(ohci, ed->hwHeadP) & TD_MASK)
  351. == (hc32_to_cpu(ohci, ed->hwTailP) & TD_MASK)
  352. && !list_empty(&ed->td_list);
  353. }
  354. /* ZF Micro watchdog timer callback. The ZF Micro chipset sometimes completes
  355. * an interrupt TD but neglects to add it to the donelist. On systems with
  356. * this chipset, we need to periodically check the state of the queues to look
  357. * for such "lost" TDs.
  358. */
  359. static void unlink_watchdog_func(unsigned long _ohci)
  360. {
  361. unsigned long flags;
  362. unsigned max;
  363. unsigned seen_count = 0;
  364. unsigned i;
  365. struct ed **seen = NULL;
  366. struct ohci_hcd *ohci = (struct ohci_hcd *) _ohci;
  367. spin_lock_irqsave(&ohci->lock, flags);
  368. max = ohci->eds_scheduled;
  369. if (!max)
  370. goto done;
  371. if (ohci->ed_to_check)
  372. goto out;
  373. seen = kcalloc(max, sizeof *seen, GFP_ATOMIC);
  374. if (!seen)
  375. goto out;
  376. for (i = 0; i < NUM_INTS; i++) {
  377. struct ed *ed = ohci->periodic[i];
  378. while (ed) {
  379. unsigned temp;
  380. /* scan this branch of the periodic schedule tree */
  381. for (temp = 0; temp < seen_count; temp++) {
  382. if (seen[temp] == ed) {
  383. /* we've checked it and what's after */
  384. ed = NULL;
  385. break;
  386. }
  387. }
  388. if (!ed)
  389. break;
  390. seen[seen_count++] = ed;
  391. if (!check_ed(ohci, ed)) {
  392. ed = ed->ed_next;
  393. continue;
  394. }
  395. /* HC's TD list is empty, but HCD sees at least one
  396. * TD that's not been sent through the donelist.
  397. */
  398. ohci->ed_to_check = ed;
  399. ohci->zf_delay = 2;
  400. /* The HC may wait until the next frame to report the
  401. * TD as done through the donelist and INTR_WDH. (We
  402. * just *assume* it's not a multi-TD interrupt URB;
  403. * those could defer the IRQ more than one frame, using
  404. * DI...) Check again after the next INTR_SF.
  405. */
  406. ohci_writel(ohci, OHCI_INTR_SF,
  407. &ohci->regs->intrstatus);
  408. ohci_writel(ohci, OHCI_INTR_SF,
  409. &ohci->regs->intrenable);
  410. /* flush those writes */
  411. (void) ohci_readl(ohci, &ohci->regs->control);
  412. goto out;
  413. }
  414. }
  415. out:
  416. kfree(seen);
  417. if (ohci->eds_scheduled)
  418. mod_timer(&ohci->unlink_watchdog, round_jiffies(jiffies + HZ));
  419. done:
  420. spin_unlock_irqrestore(&ohci->lock, flags);
  421. }
  422. /*-------------------------------------------------------------------------*
  423. * HC functions
  424. *-------------------------------------------------------------------------*/
  425. /* init memory, and kick BIOS/SMM off */
  426. static int ohci_init (struct ohci_hcd *ohci)
  427. {
  428. int ret;
  429. struct usb_hcd *hcd = ohci_to_hcd(ohci);
  430. if (distrust_firmware)
  431. ohci->flags |= OHCI_QUIRK_HUB_POWER;
  432. disable (ohci);
  433. ohci->regs = hcd->regs;
  434. /* REVISIT this BIOS handshake is now moved into PCI "quirks", and
  435. * was never needed for most non-PCI systems ... remove the code?
  436. */
  437. #ifndef IR_DISABLE
  438. /* SMM owns the HC? not for long! */
  439. if (!no_handshake && ohci_readl (ohci,
  440. &ohci->regs->control) & OHCI_CTRL_IR) {
  441. u32 temp;
  442. ohci_dbg (ohci, "USB HC TakeOver from BIOS/SMM\n");
  443. /* this timeout is arbitrary. we make it long, so systems
  444. * depending on usb keyboards may be usable even if the
  445. * BIOS/SMM code seems pretty broken.
  446. */
  447. temp = 500; /* arbitrary: five seconds */
  448. ohci_writel (ohci, OHCI_INTR_OC, &ohci->regs->intrenable);
  449. ohci_writel (ohci, OHCI_OCR, &ohci->regs->cmdstatus);
  450. while (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_IR) {
  451. msleep (10);
  452. if (--temp == 0) {
  453. ohci_err (ohci, "USB HC takeover failed!"
  454. " (BIOS/SMM bug)\n");
  455. return -EBUSY;
  456. }
  457. }
  458. ohci_usb_reset (ohci);
  459. }
  460. #endif
  461. /* Disable HC interrupts */
  462. ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
  463. /* flush the writes, and save key bits like RWC */
  464. if (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_RWC)
  465. ohci->hc_control |= OHCI_CTRL_RWC;
  466. /* Read the number of ports unless overridden */
  467. if (ohci->num_ports == 0)
  468. ohci->num_ports = roothub_a(ohci) & RH_A_NDP;
  469. if (ohci->hcca)
  470. return 0;
  471. ohci->hcca = dma_alloc_coherent (hcd->self.controller,
  472. sizeof *ohci->hcca, &ohci->hcca_dma, 0);
  473. if (!ohci->hcca)
  474. return -ENOMEM;
  475. if ((ret = ohci_mem_init (ohci)) < 0)
  476. ohci_stop (hcd);
  477. else {
  478. create_debug_files (ohci);
  479. }
  480. return ret;
  481. }
  482. /*-------------------------------------------------------------------------*/
  483. /* Start an OHCI controller, set the BUS operational
  484. * resets USB and controller
  485. * enable interrupts
  486. */
  487. static int ohci_run (struct ohci_hcd *ohci)
  488. {
  489. u32 mask, val;
  490. int first = ohci->fminterval == 0;
  491. struct usb_hcd *hcd = ohci_to_hcd(ohci);
  492. disable (ohci);
  493. /* boot firmware should have set this up (5.1.1.3.1) */
  494. if (first) {
  495. val = ohci_readl (ohci, &ohci->regs->fminterval);
  496. ohci->fminterval = val & 0x3fff;
  497. if (ohci->fminterval != FI)
  498. ohci_dbg (ohci, "fminterval delta %d\n",
  499. ohci->fminterval - FI);
  500. ohci->fminterval |= FSMP (ohci->fminterval) << 16;
  501. /* also: power/overcurrent flags in roothub.a */
  502. }
  503. /* Reset USB nearly "by the book". RemoteWakeupConnected has
  504. * to be checked in case boot firmware (BIOS/SMM/...) has set up
  505. * wakeup in a way the bus isn't aware of (e.g., legacy PCI PM).
  506. * If the bus glue detected wakeup capability then it should
  507. * already be enabled; if so we'll just enable it again.
  508. */
  509. if ((ohci->hc_control & OHCI_CTRL_RWC) != 0)
  510. device_set_wakeup_capable(hcd->self.controller, 1);
  511. switch (ohci->hc_control & OHCI_CTRL_HCFS) {
  512. case OHCI_USB_OPER:
  513. val = 0;
  514. break;
  515. case OHCI_USB_SUSPEND:
  516. case OHCI_USB_RESUME:
  517. ohci->hc_control &= OHCI_CTRL_RWC;
  518. ohci->hc_control |= OHCI_USB_RESUME;
  519. val = 10 /* msec wait */;
  520. break;
  521. // case OHCI_USB_RESET:
  522. default:
  523. ohci->hc_control &= OHCI_CTRL_RWC;
  524. ohci->hc_control |= OHCI_USB_RESET;
  525. val = 50 /* msec wait */;
  526. break;
  527. }
  528. ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
  529. // flush the writes
  530. (void) ohci_readl (ohci, &ohci->regs->control);
  531. msleep(val);
  532. memset (ohci->hcca, 0, sizeof (struct ohci_hcca));
  533. /* 2msec timelimit here means no irqs/preempt */
  534. spin_lock_irq (&ohci->lock);
  535. retry:
  536. /* HC Reset requires max 10 us delay */
  537. ohci_writel (ohci, OHCI_HCR, &ohci->regs->cmdstatus);
  538. val = 30; /* ... allow extra time */
  539. while ((ohci_readl (ohci, &ohci->regs->cmdstatus) & OHCI_HCR) != 0) {
  540. if (--val == 0) {
  541. spin_unlock_irq (&ohci->lock);
  542. ohci_err (ohci, "USB HC reset timed out!\n");
  543. return -1;
  544. }
  545. udelay (1);
  546. }
  547. /* now we're in the SUSPEND state ... must go OPERATIONAL
  548. * within 2msec else HC enters RESUME
  549. *
  550. * ... but some hardware won't init fmInterval "by the book"
  551. * (SiS, OPTi ...), so reset again instead. SiS doesn't need
  552. * this if we write fmInterval after we're OPERATIONAL.
  553. * Unclear about ALi, ServerWorks, and others ... this could
  554. * easily be a longstanding bug in chip init on Linux.
  555. */
  556. if (ohci->flags & OHCI_QUIRK_INITRESET) {
  557. ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
  558. // flush those writes
  559. (void) ohci_readl (ohci, &ohci->regs->control);
  560. }
  561. /* Tell the controller where the control and bulk lists are
  562. * The lists are empty now. */
  563. ohci_writel (ohci, 0, &ohci->regs->ed_controlhead);
  564. ohci_writel (ohci, 0, &ohci->regs->ed_bulkhead);
  565. /* a reset clears this */
  566. ohci_writel (ohci, (u32) ohci->hcca_dma, &ohci->regs->hcca);
  567. periodic_reinit (ohci);
  568. /* some OHCI implementations are finicky about how they init.
  569. * bogus values here mean not even enumeration could work.
  570. */
  571. if ((ohci_readl (ohci, &ohci->regs->fminterval) & 0x3fff0000) == 0
  572. || !ohci_readl (ohci, &ohci->regs->periodicstart)) {
  573. if (!(ohci->flags & OHCI_QUIRK_INITRESET)) {
  574. ohci->flags |= OHCI_QUIRK_INITRESET;
  575. ohci_dbg (ohci, "enabling initreset quirk\n");
  576. goto retry;
  577. }
  578. spin_unlock_irq (&ohci->lock);
  579. ohci_err (ohci, "init err (%08x %04x)\n",
  580. ohci_readl (ohci, &ohci->regs->fminterval),
  581. ohci_readl (ohci, &ohci->regs->periodicstart));
  582. return -EOVERFLOW;
  583. }
  584. /* use rhsc irqs after khubd is fully initialized */
  585. set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
  586. hcd->uses_new_polling = 1;
  587. /* start controller operations */
  588. ohci->hc_control &= OHCI_CTRL_RWC;
  589. ohci->hc_control |= OHCI_CONTROL_INIT | OHCI_USB_OPER;
  590. ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
  591. hcd->state = HC_STATE_RUNNING;
  592. /* wake on ConnectStatusChange, matching external hubs */
  593. ohci_writel (ohci, RH_HS_DRWE, &ohci->regs->roothub.status);
  594. /* Choose the interrupts we care about now, others later on demand */
  595. mask = OHCI_INTR_INIT;
  596. ohci_writel (ohci, ~0, &ohci->regs->intrstatus);
  597. ohci_writel (ohci, mask, &ohci->regs->intrenable);
  598. /* handle root hub init quirks ... */
  599. val = roothub_a (ohci);
  600. val &= ~(RH_A_PSM | RH_A_OCPM);
  601. if (ohci->flags & OHCI_QUIRK_SUPERIO) {
  602. /* NSC 87560 and maybe others */
  603. val |= RH_A_NOCP;
  604. val &= ~(RH_A_POTPGT | RH_A_NPS);
  605. ohci_writel (ohci, val, &ohci->regs->roothub.a);
  606. } else if ((ohci->flags & OHCI_QUIRK_AMD756) ||
  607. (ohci->flags & OHCI_QUIRK_HUB_POWER)) {
  608. /* hub power always on; required for AMD-756 and some
  609. * Mac platforms. ganged overcurrent reporting, if any.
  610. */
  611. val |= RH_A_NPS;
  612. ohci_writel (ohci, val, &ohci->regs->roothub.a);
  613. }
  614. ohci_writel (ohci, RH_HS_LPSC, &ohci->regs->roothub.status);
  615. ohci_writel (ohci, (val & RH_A_NPS) ? 0 : RH_B_PPCM,
  616. &ohci->regs->roothub.b);
  617. // flush those writes
  618. (void) ohci_readl (ohci, &ohci->regs->control);
  619. ohci->next_statechange = jiffies + STATECHANGE_DELAY;
  620. spin_unlock_irq (&ohci->lock);
  621. // POTPGT delay is bits 24-31, in 2 ms units.
  622. mdelay ((val >> 23) & 0x1fe);
  623. hcd->state = HC_STATE_RUNNING;
  624. if (quirk_zfmicro(ohci)) {
  625. /* Create timer to watch for bad queue state on ZF Micro */
  626. setup_timer(&ohci->unlink_watchdog, unlink_watchdog_func,
  627. (unsigned long) ohci);
  628. ohci->eds_scheduled = 0;
  629. ohci->ed_to_check = NULL;
  630. }
  631. ohci_dump (ohci, 1);
  632. return 0;
  633. }
  634. /*-------------------------------------------------------------------------*/
  635. /* an interrupt happens */
  636. static irqreturn_t ohci_irq (struct usb_hcd *hcd)
  637. {
  638. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  639. struct ohci_regs __iomem *regs = ohci->regs;
  640. int ints;
  641. /* Read interrupt status (and flush pending writes). We ignore the
  642. * optimization of checking the LSB of hcca->done_head; it doesn't
  643. * work on all systems (edge triggering for OHCI can be a factor).
  644. */
  645. ints = ohci_readl(ohci, &regs->intrstatus);
  646. /* Check for an all 1's result which is a typical consequence
  647. * of dead, unclocked, or unplugged (CardBus...) devices
  648. */
  649. if (ints == ~(u32)0) {
  650. disable (ohci);
  651. ohci_dbg (ohci, "device removed!\n");
  652. usb_hc_died(hcd);
  653. return IRQ_HANDLED;
  654. }
  655. /* We only care about interrupts that are enabled */
  656. ints &= ohci_readl(ohci, &regs->intrenable);
  657. /* interrupt for some other device? */
  658. if (ints == 0 || unlikely(hcd->state == HC_STATE_HALT))
  659. return IRQ_NOTMINE;
  660. if (ints & OHCI_INTR_UE) {
  661. // e.g. due to PCI Master/Target Abort
  662. if (quirk_nec(ohci)) {
  663. /* Workaround for a silicon bug in some NEC chips used
  664. * in Apple's PowerBooks. Adapted from Darwin code.
  665. */
  666. ohci_err (ohci, "OHCI Unrecoverable Error, scheduling NEC chip restart\n");
  667. ohci_writel (ohci, OHCI_INTR_UE, &regs->intrdisable);
  668. schedule_work (&ohci->nec_work);
  669. } else {
  670. disable (ohci);
  671. ohci_err (ohci, "OHCI Unrecoverable Error, disabled\n");
  672. usb_hc_died(hcd);
  673. }
  674. ohci_dump (ohci, 1);
  675. ohci_usb_reset (ohci);
  676. }
  677. if (ints & OHCI_INTR_RHSC) {
  678. ohci_vdbg(ohci, "rhsc\n");
  679. ohci->next_statechange = jiffies + STATECHANGE_DELAY;
  680. ohci_writel(ohci, OHCI_INTR_RD | OHCI_INTR_RHSC,
  681. &regs->intrstatus);
  682. /* NOTE: Vendors didn't always make the same implementation
  683. * choices for RHSC. Many followed the spec; RHSC triggers
  684. * on an edge, like setting and maybe clearing a port status
  685. * change bit. With others it's level-triggered, active
  686. * until khubd clears all the port status change bits. We'll
  687. * always disable it here and rely on polling until khubd
  688. * re-enables it.
  689. */
  690. ohci_writel(ohci, OHCI_INTR_RHSC, &regs->intrdisable);
  691. usb_hcd_poll_rh_status(hcd);
  692. }
  693. /* For connect and disconnect events, we expect the controller
  694. * to turn on RHSC along with RD. But for remote wakeup events
  695. * this might not happen.
  696. */
  697. else if (ints & OHCI_INTR_RD) {
  698. ohci_vdbg(ohci, "resume detect\n");
  699. ohci_writel(ohci, OHCI_INTR_RD, &regs->intrstatus);
  700. set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
  701. if (ohci->autostop) {
  702. spin_lock (&ohci->lock);
  703. ohci_rh_resume (ohci);
  704. spin_unlock (&ohci->lock);
  705. } else
  706. usb_hcd_resume_root_hub(hcd);
  707. }
  708. if (ints & OHCI_INTR_WDH) {
  709. spin_lock (&ohci->lock);
  710. dl_done_list (ohci);
  711. spin_unlock (&ohci->lock);
  712. }
  713. if (quirk_zfmicro(ohci) && (ints & OHCI_INTR_SF)) {
  714. spin_lock(&ohci->lock);
  715. if (ohci->ed_to_check) {
  716. struct ed *ed = ohci->ed_to_check;
  717. if (check_ed(ohci, ed)) {
  718. /* HC thinks the TD list is empty; HCD knows
  719. * at least one TD is outstanding
  720. */
  721. if (--ohci->zf_delay == 0) {
  722. struct td *td = list_entry(
  723. ed->td_list.next,
  724. struct td, td_list);
  725. ohci_warn(ohci,
  726. "Reclaiming orphan TD %p\n",
  727. td);
  728. takeback_td(ohci, td);
  729. ohci->ed_to_check = NULL;
  730. }
  731. } else
  732. ohci->ed_to_check = NULL;
  733. }
  734. spin_unlock(&ohci->lock);
  735. }
  736. /* could track INTR_SO to reduce available PCI/... bandwidth */
  737. /* handle any pending URB/ED unlinks, leaving INTR_SF enabled
  738. * when there's still unlinking to be done (next frame).
  739. */
  740. spin_lock (&ohci->lock);
  741. if (ohci->ed_rm_list)
  742. finish_unlinks (ohci, ohci_frame_no(ohci));
  743. if ((ints & OHCI_INTR_SF) != 0
  744. && !ohci->ed_rm_list
  745. && !ohci->ed_to_check
  746. && HC_IS_RUNNING(hcd->state))
  747. ohci_writel (ohci, OHCI_INTR_SF, &regs->intrdisable);
  748. spin_unlock (&ohci->lock);
  749. if (HC_IS_RUNNING(hcd->state)) {
  750. ohci_writel (ohci, ints, &regs->intrstatus);
  751. ohci_writel (ohci, OHCI_INTR_MIE, &regs->intrenable);
  752. // flush those writes
  753. (void) ohci_readl (ohci, &ohci->regs->control);
  754. }
  755. return IRQ_HANDLED;
  756. }
  757. /*-------------------------------------------------------------------------*/
  758. static void ohci_stop (struct usb_hcd *hcd)
  759. {
  760. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  761. ohci_dump (ohci, 1);
  762. if (quirk_nec(ohci))
  763. flush_work_sync(&ohci->nec_work);
  764. ohci_usb_reset (ohci);
  765. ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
  766. free_irq(hcd->irq, hcd);
  767. hcd->irq = -1;
  768. if (quirk_zfmicro(ohci))
  769. del_timer(&ohci->unlink_watchdog);
  770. if (quirk_amdiso(ohci))
  771. usb_amd_dev_put();
  772. remove_debug_files (ohci);
  773. ohci_mem_cleanup (ohci);
  774. if (ohci->hcca) {
  775. dma_free_coherent (hcd->self.controller,
  776. sizeof *ohci->hcca,
  777. ohci->hcca, ohci->hcca_dma);
  778. ohci->hcca = NULL;
  779. ohci->hcca_dma = 0;
  780. }
  781. }
  782. /*-------------------------------------------------------------------------*/
  783. #if defined(CONFIG_PM) || defined(CONFIG_PCI)
  784. /* must not be called from interrupt context */
  785. static int ohci_restart (struct ohci_hcd *ohci)
  786. {
  787. int temp;
  788. int i;
  789. struct urb_priv *priv;
  790. spin_lock_irq(&ohci->lock);
  791. disable (ohci);
  792. /* Recycle any "live" eds/tds (and urbs). */
  793. if (!list_empty (&ohci->pending))
  794. ohci_dbg(ohci, "abort schedule...\n");
  795. list_for_each_entry (priv, &ohci->pending, pending) {
  796. struct urb *urb = priv->td[0]->urb;
  797. struct ed *ed = priv->ed;
  798. switch (ed->state) {
  799. case ED_OPER:
  800. ed->state = ED_UNLINK;
  801. ed->hwINFO |= cpu_to_hc32(ohci, ED_DEQUEUE);
  802. ed_deschedule (ohci, ed);
  803. ed->ed_next = ohci->ed_rm_list;
  804. ed->ed_prev = NULL;
  805. ohci->ed_rm_list = ed;
  806. /* FALLTHROUGH */
  807. case ED_UNLINK:
  808. break;
  809. default:
  810. ohci_dbg(ohci, "bogus ed %p state %d\n",
  811. ed, ed->state);
  812. }
  813. if (!urb->unlinked)
  814. urb->unlinked = -ESHUTDOWN;
  815. }
  816. finish_unlinks (ohci, 0);
  817. spin_unlock_irq(&ohci->lock);
  818. /* paranoia, in case that didn't work: */
  819. /* empty the interrupt branches */
  820. for (i = 0; i < NUM_INTS; i++) ohci->load [i] = 0;
  821. for (i = 0; i < NUM_INTS; i++) ohci->hcca->int_table [i] = 0;
  822. /* no EDs to remove */
  823. ohci->ed_rm_list = NULL;
  824. /* empty control and bulk lists */
  825. ohci->ed_controltail = NULL;
  826. ohci->ed_bulktail = NULL;
  827. if ((temp = ohci_run (ohci)) < 0) {
  828. ohci_err (ohci, "can't restart, %d\n", temp);
  829. return temp;
  830. }
  831. ohci_dbg(ohci, "restart complete\n");
  832. return 0;
  833. }
  834. #endif
  835. /*-------------------------------------------------------------------------*/
  836. MODULE_AUTHOR (DRIVER_AUTHOR);
  837. MODULE_DESCRIPTION(DRIVER_DESC);
  838. MODULE_LICENSE ("GPL");
  839. #ifdef CONFIG_PCI
  840. #include "ohci-pci.c"
  841. #define PCI_DRIVER ohci_pci_driver
  842. #endif
  843. #if defined(CONFIG_ARCH_SA1100) && defined(CONFIG_SA1111)
  844. #include "ohci-sa1111.c"
  845. #define SA1111_DRIVER ohci_hcd_sa1111_driver
  846. #endif
  847. #if defined(CONFIG_ARCH_S3C2410) || defined(CONFIG_ARCH_S3C64XX)
  848. #include "ohci-s3c2410.c"
  849. #define PLATFORM_DRIVER ohci_hcd_s3c2410_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. #ifdef CONFIG_ARCH_PNX4008
  884. #include "ohci-pnx4008.c"
  885. #define PLATFORM_DRIVER usb_hcd_pnx4008_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_USB_OHCI_ATH79
  932. #include "ohci-ath79.c"
  933. #define PLATFORM_DRIVER ohci_hcd_ath79_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 = platform_driver_register(&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. platform_driver_unregister(&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. platform_driver_unregister(&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);