ohci-hcd.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245
  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/dma-mapping.h>
  35. #include <linux/dmapool.h>
  36. #include <linux/workqueue.h>
  37. #include <linux/debugfs.h>
  38. #include <asm/io.h>
  39. #include <asm/irq.h>
  40. #include <asm/system.h>
  41. #include <asm/unaligned.h>
  42. #include <asm/byteorder.h>
  43. #include "../core/hcd.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 (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) {
  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. return;
  324. }
  325. static int ohci_get_frame (struct usb_hcd *hcd)
  326. {
  327. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  328. return ohci_frame_no(ohci);
  329. }
  330. static void ohci_usb_reset (struct ohci_hcd *ohci)
  331. {
  332. ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
  333. ohci->hc_control &= OHCI_CTRL_RWC;
  334. ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
  335. }
  336. /* ohci_shutdown forcibly disables IRQs and DMA, helping kexec and
  337. * other cases where the next software may expect clean state from the
  338. * "firmware". this is bus-neutral, unlike shutdown() methods.
  339. */
  340. static void
  341. ohci_shutdown (struct usb_hcd *hcd)
  342. {
  343. struct ohci_hcd *ohci;
  344. ohci = hcd_to_ohci (hcd);
  345. ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
  346. ohci_usb_reset (ohci);
  347. /* flush the writes */
  348. (void) ohci_readl (ohci, &ohci->regs->control);
  349. }
  350. static int check_ed(struct ohci_hcd *ohci, struct ed *ed)
  351. {
  352. return (hc32_to_cpu(ohci, ed->hwINFO) & ED_IN) != 0
  353. && (hc32_to_cpu(ohci, ed->hwHeadP) & TD_MASK)
  354. == (hc32_to_cpu(ohci, ed->hwTailP) & TD_MASK)
  355. && !list_empty(&ed->td_list);
  356. }
  357. /* ZF Micro watchdog timer callback. The ZF Micro chipset sometimes completes
  358. * an interrupt TD but neglects to add it to the donelist. On systems with
  359. * this chipset, we need to periodically check the state of the queues to look
  360. * for such "lost" TDs.
  361. */
  362. static void unlink_watchdog_func(unsigned long _ohci)
  363. {
  364. unsigned long flags;
  365. unsigned max;
  366. unsigned seen_count = 0;
  367. unsigned i;
  368. struct ed **seen = NULL;
  369. struct ohci_hcd *ohci = (struct ohci_hcd *) _ohci;
  370. spin_lock_irqsave(&ohci->lock, flags);
  371. max = ohci->eds_scheduled;
  372. if (!max)
  373. goto done;
  374. if (ohci->ed_to_check)
  375. goto out;
  376. seen = kcalloc(max, sizeof *seen, GFP_ATOMIC);
  377. if (!seen)
  378. goto out;
  379. for (i = 0; i < NUM_INTS; i++) {
  380. struct ed *ed = ohci->periodic[i];
  381. while (ed) {
  382. unsigned temp;
  383. /* scan this branch of the periodic schedule tree */
  384. for (temp = 0; temp < seen_count; temp++) {
  385. if (seen[temp] == ed) {
  386. /* we've checked it and what's after */
  387. ed = NULL;
  388. break;
  389. }
  390. }
  391. if (!ed)
  392. break;
  393. seen[seen_count++] = ed;
  394. if (!check_ed(ohci, ed)) {
  395. ed = ed->ed_next;
  396. continue;
  397. }
  398. /* HC's TD list is empty, but HCD sees at least one
  399. * TD that's not been sent through the donelist.
  400. */
  401. ohci->ed_to_check = ed;
  402. ohci->zf_delay = 2;
  403. /* The HC may wait until the next frame to report the
  404. * TD as done through the donelist and INTR_WDH. (We
  405. * just *assume* it's not a multi-TD interrupt URB;
  406. * those could defer the IRQ more than one frame, using
  407. * DI...) Check again after the next INTR_SF.
  408. */
  409. ohci_writel(ohci, OHCI_INTR_SF,
  410. &ohci->regs->intrstatus);
  411. ohci_writel(ohci, OHCI_INTR_SF,
  412. &ohci->regs->intrenable);
  413. /* flush those writes */
  414. (void) ohci_readl(ohci, &ohci->regs->control);
  415. goto out;
  416. }
  417. }
  418. out:
  419. kfree(seen);
  420. if (ohci->eds_scheduled)
  421. mod_timer(&ohci->unlink_watchdog, round_jiffies(jiffies + HZ));
  422. done:
  423. spin_unlock_irqrestore(&ohci->lock, flags);
  424. }
  425. /*-------------------------------------------------------------------------*
  426. * HC functions
  427. *-------------------------------------------------------------------------*/
  428. /* init memory, and kick BIOS/SMM off */
  429. static int ohci_init (struct ohci_hcd *ohci)
  430. {
  431. int ret;
  432. struct usb_hcd *hcd = ohci_to_hcd(ohci);
  433. if (distrust_firmware)
  434. ohci->flags |= OHCI_QUIRK_HUB_POWER;
  435. disable (ohci);
  436. ohci->regs = hcd->regs;
  437. /* REVISIT this BIOS handshake is now moved into PCI "quirks", and
  438. * was never needed for most non-PCI systems ... remove the code?
  439. */
  440. #ifndef IR_DISABLE
  441. /* SMM owns the HC? not for long! */
  442. if (!no_handshake && ohci_readl (ohci,
  443. &ohci->regs->control) & OHCI_CTRL_IR) {
  444. u32 temp;
  445. ohci_dbg (ohci, "USB HC TakeOver from BIOS/SMM\n");
  446. /* this timeout is arbitrary. we make it long, so systems
  447. * depending on usb keyboards may be usable even if the
  448. * BIOS/SMM code seems pretty broken.
  449. */
  450. temp = 500; /* arbitrary: five seconds */
  451. ohci_writel (ohci, OHCI_INTR_OC, &ohci->regs->intrenable);
  452. ohci_writel (ohci, OHCI_OCR, &ohci->regs->cmdstatus);
  453. while (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_IR) {
  454. msleep (10);
  455. if (--temp == 0) {
  456. ohci_err (ohci, "USB HC takeover failed!"
  457. " (BIOS/SMM bug)\n");
  458. return -EBUSY;
  459. }
  460. }
  461. ohci_usb_reset (ohci);
  462. }
  463. #endif
  464. /* Disable HC interrupts */
  465. ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
  466. /* flush the writes, and save key bits like RWC */
  467. if (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_RWC)
  468. ohci->hc_control |= OHCI_CTRL_RWC;
  469. /* Read the number of ports unless overridden */
  470. if (ohci->num_ports == 0)
  471. ohci->num_ports = roothub_a(ohci) & RH_A_NDP;
  472. if (ohci->hcca)
  473. return 0;
  474. ohci->hcca = dma_alloc_coherent (hcd->self.controller,
  475. sizeof *ohci->hcca, &ohci->hcca_dma, 0);
  476. if (!ohci->hcca)
  477. return -ENOMEM;
  478. if ((ret = ohci_mem_init (ohci)) < 0)
  479. ohci_stop (hcd);
  480. else {
  481. create_debug_files (ohci);
  482. }
  483. return ret;
  484. }
  485. /*-------------------------------------------------------------------------*/
  486. /* Start an OHCI controller, set the BUS operational
  487. * resets USB and controller
  488. * enable interrupts
  489. */
  490. static int ohci_run (struct ohci_hcd *ohci)
  491. {
  492. u32 mask, val;
  493. int first = ohci->fminterval == 0;
  494. struct usb_hcd *hcd = ohci_to_hcd(ohci);
  495. disable (ohci);
  496. /* boot firmware should have set this up (5.1.1.3.1) */
  497. if (first) {
  498. val = ohci_readl (ohci, &ohci->regs->fminterval);
  499. ohci->fminterval = val & 0x3fff;
  500. if (ohci->fminterval != FI)
  501. ohci_dbg (ohci, "fminterval delta %d\n",
  502. ohci->fminterval - FI);
  503. ohci->fminterval |= FSMP (ohci->fminterval) << 16;
  504. /* also: power/overcurrent flags in roothub.a */
  505. }
  506. /* Reset USB nearly "by the book". RemoteWakeupConnected has
  507. * to be checked in case boot firmware (BIOS/SMM/...) has set up
  508. * wakeup in a way the bus isn't aware of (e.g., legacy PCI PM).
  509. * If the bus glue detected wakeup capability then it should
  510. * already be enabled; if so we'll just enable it again.
  511. */
  512. if ((ohci->hc_control & OHCI_CTRL_RWC) != 0)
  513. device_set_wakeup_capable(hcd->self.controller, 1);
  514. switch (ohci->hc_control & OHCI_CTRL_HCFS) {
  515. case OHCI_USB_OPER:
  516. val = 0;
  517. break;
  518. case OHCI_USB_SUSPEND:
  519. case OHCI_USB_RESUME:
  520. ohci->hc_control &= OHCI_CTRL_RWC;
  521. ohci->hc_control |= OHCI_USB_RESUME;
  522. val = 10 /* msec wait */;
  523. break;
  524. // case OHCI_USB_RESET:
  525. default:
  526. ohci->hc_control &= OHCI_CTRL_RWC;
  527. ohci->hc_control |= OHCI_USB_RESET;
  528. val = 50 /* msec wait */;
  529. break;
  530. }
  531. ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
  532. // flush the writes
  533. (void) ohci_readl (ohci, &ohci->regs->control);
  534. msleep(val);
  535. memset (ohci->hcca, 0, sizeof (struct ohci_hcca));
  536. /* 2msec timelimit here means no irqs/preempt */
  537. spin_lock_irq (&ohci->lock);
  538. retry:
  539. /* HC Reset requires max 10 us delay */
  540. ohci_writel (ohci, OHCI_HCR, &ohci->regs->cmdstatus);
  541. val = 30; /* ... allow extra time */
  542. while ((ohci_readl (ohci, &ohci->regs->cmdstatus) & OHCI_HCR) != 0) {
  543. if (--val == 0) {
  544. spin_unlock_irq (&ohci->lock);
  545. ohci_err (ohci, "USB HC reset timed out!\n");
  546. return -1;
  547. }
  548. udelay (1);
  549. }
  550. /* now we're in the SUSPEND state ... must go OPERATIONAL
  551. * within 2msec else HC enters RESUME
  552. *
  553. * ... but some hardware won't init fmInterval "by the book"
  554. * (SiS, OPTi ...), so reset again instead. SiS doesn't need
  555. * this if we write fmInterval after we're OPERATIONAL.
  556. * Unclear about ALi, ServerWorks, and others ... this could
  557. * easily be a longstanding bug in chip init on Linux.
  558. */
  559. if (ohci->flags & OHCI_QUIRK_INITRESET) {
  560. ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
  561. // flush those writes
  562. (void) ohci_readl (ohci, &ohci->regs->control);
  563. }
  564. /* Tell the controller where the control and bulk lists are
  565. * The lists are empty now. */
  566. ohci_writel (ohci, 0, &ohci->regs->ed_controlhead);
  567. ohci_writel (ohci, 0, &ohci->regs->ed_bulkhead);
  568. /* a reset clears this */
  569. ohci_writel (ohci, (u32) ohci->hcca_dma, &ohci->regs->hcca);
  570. periodic_reinit (ohci);
  571. /* some OHCI implementations are finicky about how they init.
  572. * bogus values here mean not even enumeration could work.
  573. */
  574. if ((ohci_readl (ohci, &ohci->regs->fminterval) & 0x3fff0000) == 0
  575. || !ohci_readl (ohci, &ohci->regs->periodicstart)) {
  576. if (!(ohci->flags & OHCI_QUIRK_INITRESET)) {
  577. ohci->flags |= OHCI_QUIRK_INITRESET;
  578. ohci_dbg (ohci, "enabling initreset quirk\n");
  579. goto retry;
  580. }
  581. spin_unlock_irq (&ohci->lock);
  582. ohci_err (ohci, "init err (%08x %04x)\n",
  583. ohci_readl (ohci, &ohci->regs->fminterval),
  584. ohci_readl (ohci, &ohci->regs->periodicstart));
  585. return -EOVERFLOW;
  586. }
  587. /* use rhsc irqs after khubd is fully initialized */
  588. hcd->poll_rh = 1;
  589. hcd->uses_new_polling = 1;
  590. /* start controller operations */
  591. ohci->hc_control &= OHCI_CTRL_RWC;
  592. ohci->hc_control |= OHCI_CONTROL_INIT | OHCI_USB_OPER;
  593. ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
  594. hcd->state = HC_STATE_RUNNING;
  595. /* wake on ConnectStatusChange, matching external hubs */
  596. ohci_writel (ohci, RH_HS_DRWE, &ohci->regs->roothub.status);
  597. /* Choose the interrupts we care about now, others later on demand */
  598. mask = OHCI_INTR_INIT;
  599. ohci_writel (ohci, ~0, &ohci->regs->intrstatus);
  600. ohci_writel (ohci, mask, &ohci->regs->intrenable);
  601. /* handle root hub init quirks ... */
  602. val = roothub_a (ohci);
  603. val &= ~(RH_A_PSM | RH_A_OCPM);
  604. if (ohci->flags & OHCI_QUIRK_SUPERIO) {
  605. /* NSC 87560 and maybe others */
  606. val |= RH_A_NOCP;
  607. val &= ~(RH_A_POTPGT | RH_A_NPS);
  608. ohci_writel (ohci, val, &ohci->regs->roothub.a);
  609. } else if ((ohci->flags & OHCI_QUIRK_AMD756) ||
  610. (ohci->flags & OHCI_QUIRK_HUB_POWER)) {
  611. /* hub power always on; required for AMD-756 and some
  612. * Mac platforms. ganged overcurrent reporting, if any.
  613. */
  614. val |= RH_A_NPS;
  615. ohci_writel (ohci, val, &ohci->regs->roothub.a);
  616. }
  617. ohci_writel (ohci, RH_HS_LPSC, &ohci->regs->roothub.status);
  618. ohci_writel (ohci, (val & RH_A_NPS) ? 0 : RH_B_PPCM,
  619. &ohci->regs->roothub.b);
  620. // flush those writes
  621. (void) ohci_readl (ohci, &ohci->regs->control);
  622. ohci->next_statechange = jiffies + STATECHANGE_DELAY;
  623. spin_unlock_irq (&ohci->lock);
  624. // POTPGT delay is bits 24-31, in 2 ms units.
  625. mdelay ((val >> 23) & 0x1fe);
  626. hcd->state = HC_STATE_RUNNING;
  627. if (quirk_zfmicro(ohci)) {
  628. /* Create timer to watch for bad queue state on ZF Micro */
  629. setup_timer(&ohci->unlink_watchdog, unlink_watchdog_func,
  630. (unsigned long) ohci);
  631. ohci->eds_scheduled = 0;
  632. ohci->ed_to_check = NULL;
  633. }
  634. ohci_dump (ohci, 1);
  635. return 0;
  636. }
  637. /*-------------------------------------------------------------------------*/
  638. /* an interrupt happens */
  639. static irqreturn_t ohci_irq (struct usb_hcd *hcd)
  640. {
  641. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  642. struct ohci_regs __iomem *regs = ohci->regs;
  643. int ints;
  644. /* Read interrupt status (and flush pending writes). We ignore the
  645. * optimization of checking the LSB of hcca->done_head; it doesn't
  646. * work on all systems (edge triggering for OHCI can be a factor).
  647. */
  648. ints = ohci_readl(ohci, &regs->intrstatus);
  649. /* Check for an all 1's result which is a typical consequence
  650. * of dead, unclocked, or unplugged (CardBus...) devices
  651. */
  652. if (ints == ~(u32)0) {
  653. disable (ohci);
  654. ohci_dbg (ohci, "device removed!\n");
  655. return IRQ_HANDLED;
  656. }
  657. /* We only care about interrupts that are enabled */
  658. ints &= ohci_readl(ohci, &regs->intrenable);
  659. /* interrupt for some other device? */
  660. if (ints == 0)
  661. return IRQ_NOTMINE;
  662. if (ints & OHCI_INTR_UE) {
  663. // e.g. due to PCI Master/Target Abort
  664. if (quirk_nec(ohci)) {
  665. /* Workaround for a silicon bug in some NEC chips used
  666. * in Apple's PowerBooks. Adapted from Darwin code.
  667. */
  668. ohci_err (ohci, "OHCI Unrecoverable Error, scheduling NEC chip restart\n");
  669. ohci_writel (ohci, OHCI_INTR_UE, &regs->intrdisable);
  670. schedule_work (&ohci->nec_work);
  671. } else {
  672. disable (ohci);
  673. ohci_err (ohci, "OHCI Unrecoverable Error, disabled\n");
  674. }
  675. ohci_dump (ohci, 1);
  676. ohci_usb_reset (ohci);
  677. }
  678. if (ints & OHCI_INTR_RHSC) {
  679. ohci_vdbg(ohci, "rhsc\n");
  680. ohci->next_statechange = jiffies + STATECHANGE_DELAY;
  681. ohci_writel(ohci, OHCI_INTR_RD | OHCI_INTR_RHSC,
  682. &regs->intrstatus);
  683. /* NOTE: Vendors didn't always make the same implementation
  684. * choices for RHSC. Many followed the spec; RHSC triggers
  685. * on an edge, like setting and maybe clearing a port status
  686. * change bit. With others it's level-triggered, active
  687. * until khubd clears all the port status change bits. We'll
  688. * always disable it here and rely on polling until khubd
  689. * re-enables it.
  690. */
  691. ohci_writel(ohci, OHCI_INTR_RHSC, &regs->intrdisable);
  692. usb_hcd_poll_rh_status(hcd);
  693. }
  694. /* For connect and disconnect events, we expect the controller
  695. * to turn on RHSC along with RD. But for remote wakeup events
  696. * this might not happen.
  697. */
  698. else if (ints & OHCI_INTR_RD) {
  699. ohci_vdbg(ohci, "resume detect\n");
  700. ohci_writel(ohci, OHCI_INTR_RD, &regs->intrstatus);
  701. hcd->poll_rh = 1;
  702. if (ohci->autostop) {
  703. spin_lock (&ohci->lock);
  704. ohci_rh_resume (ohci);
  705. spin_unlock (&ohci->lock);
  706. } else
  707. usb_hcd_resume_root_hub(hcd);
  708. }
  709. if (ints & OHCI_INTR_WDH) {
  710. spin_lock (&ohci->lock);
  711. dl_done_list (ohci);
  712. spin_unlock (&ohci->lock);
  713. }
  714. if (quirk_zfmicro(ohci) && (ints & OHCI_INTR_SF)) {
  715. spin_lock(&ohci->lock);
  716. if (ohci->ed_to_check) {
  717. struct ed *ed = ohci->ed_to_check;
  718. if (check_ed(ohci, ed)) {
  719. /* HC thinks the TD list is empty; HCD knows
  720. * at least one TD is outstanding
  721. */
  722. if (--ohci->zf_delay == 0) {
  723. struct td *td = list_entry(
  724. ed->td_list.next,
  725. struct td, td_list);
  726. ohci_warn(ohci,
  727. "Reclaiming orphan TD %p\n",
  728. td);
  729. takeback_td(ohci, td);
  730. ohci->ed_to_check = NULL;
  731. }
  732. } else
  733. ohci->ed_to_check = NULL;
  734. }
  735. spin_unlock(&ohci->lock);
  736. }
  737. /* could track INTR_SO to reduce available PCI/... bandwidth */
  738. /* handle any pending URB/ED unlinks, leaving INTR_SF enabled
  739. * when there's still unlinking to be done (next frame).
  740. */
  741. spin_lock (&ohci->lock);
  742. if (ohci->ed_rm_list)
  743. finish_unlinks (ohci, ohci_frame_no(ohci));
  744. if ((ints & OHCI_INTR_SF) != 0
  745. && !ohci->ed_rm_list
  746. && !ohci->ed_to_check
  747. && HC_IS_RUNNING(hcd->state))
  748. ohci_writel (ohci, OHCI_INTR_SF, &regs->intrdisable);
  749. spin_unlock (&ohci->lock);
  750. if (HC_IS_RUNNING(hcd->state)) {
  751. ohci_writel (ohci, ints, &regs->intrstatus);
  752. ohci_writel (ohci, OHCI_INTR_MIE, &regs->intrenable);
  753. // flush those writes
  754. (void) ohci_readl (ohci, &ohci->regs->control);
  755. }
  756. return IRQ_HANDLED;
  757. }
  758. /*-------------------------------------------------------------------------*/
  759. static void ohci_stop (struct usb_hcd *hcd)
  760. {
  761. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  762. ohci_dump (ohci, 1);
  763. flush_scheduled_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. amd_iso_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_ARCH_OMAP
  852. #include "ohci-omap.c"
  853. #define PLATFORM_DRIVER ohci_hcd_omap_driver
  854. #endif
  855. #ifdef CONFIG_ARCH_LH7A404
  856. #include "ohci-lh7a404.c"
  857. #define PLATFORM_DRIVER ohci_hcd_lh7a404_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_SOC_AU1X00
  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. #if defined(CONFIG_CPU_SUBTYPE_SH7720) || \
  888. defined(CONFIG_CPU_SUBTYPE_SH7721) || \
  889. defined(CONFIG_CPU_SUBTYPE_SH7763) || \
  890. defined(CONFIG_CPU_SUBTYPE_SH7786)
  891. #include "ohci-sh.c"
  892. #define PLATFORM_DRIVER ohci_hcd_sh_driver
  893. #endif
  894. #ifdef CONFIG_USB_OHCI_HCD_PPC_OF
  895. #include "ohci-ppc-of.c"
  896. #define OF_PLATFORM_DRIVER ohci_hcd_ppc_of_driver
  897. #endif
  898. #ifdef CONFIG_PPC_PS3
  899. #include "ohci-ps3.c"
  900. #define PS3_SYSTEM_BUS_DRIVER ps3_ohci_driver
  901. #endif
  902. #ifdef CONFIG_USB_OHCI_HCD_SSB
  903. #include "ohci-ssb.c"
  904. #define SSB_OHCI_DRIVER ssb_ohci_driver
  905. #endif
  906. #ifdef CONFIG_MFD_SM501
  907. #include "ohci-sm501.c"
  908. #define SM501_OHCI_DRIVER ohci_hcd_sm501_driver
  909. #endif
  910. #ifdef CONFIG_MFD_TC6393XB
  911. #include "ohci-tmio.c"
  912. #define TMIO_OHCI_DRIVER ohci_hcd_tmio_driver
  913. #endif
  914. #if !defined(PCI_DRIVER) && \
  915. !defined(PLATFORM_DRIVER) && \
  916. !defined(OF_PLATFORM_DRIVER) && \
  917. !defined(SA1111_DRIVER) && \
  918. !defined(PS3_SYSTEM_BUS_DRIVER) && \
  919. !defined(SM501_OHCI_DRIVER) && \
  920. !defined(TMIO_OHCI_DRIVER) && \
  921. !defined(SSB_OHCI_DRIVER)
  922. #error "missing bus glue for ohci-hcd"
  923. #endif
  924. static int __init ohci_hcd_mod_init(void)
  925. {
  926. int retval = 0;
  927. if (usb_disabled())
  928. return -ENODEV;
  929. printk(KERN_INFO "%s: " DRIVER_DESC "\n", hcd_name);
  930. pr_debug ("%s: block sizes: ed %Zd td %Zd\n", hcd_name,
  931. sizeof (struct ed), sizeof (struct td));
  932. set_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
  933. #ifdef DEBUG
  934. ohci_debug_root = debugfs_create_dir("ohci", usb_debug_root);
  935. if (!ohci_debug_root) {
  936. retval = -ENOENT;
  937. goto error_debug;
  938. }
  939. #endif
  940. #ifdef PS3_SYSTEM_BUS_DRIVER
  941. retval = ps3_ohci_driver_register(&PS3_SYSTEM_BUS_DRIVER);
  942. if (retval < 0)
  943. goto error_ps3;
  944. #endif
  945. #ifdef PLATFORM_DRIVER
  946. retval = platform_driver_register(&PLATFORM_DRIVER);
  947. if (retval < 0)
  948. goto error_platform;
  949. #endif
  950. #ifdef OF_PLATFORM_DRIVER
  951. retval = of_register_platform_driver(&OF_PLATFORM_DRIVER);
  952. if (retval < 0)
  953. goto error_of_platform;
  954. #endif
  955. #ifdef SA1111_DRIVER
  956. retval = sa1111_driver_register(&SA1111_DRIVER);
  957. if (retval < 0)
  958. goto error_sa1111;
  959. #endif
  960. #ifdef PCI_DRIVER
  961. retval = pci_register_driver(&PCI_DRIVER);
  962. if (retval < 0)
  963. goto error_pci;
  964. #endif
  965. #ifdef SSB_OHCI_DRIVER
  966. retval = ssb_driver_register(&SSB_OHCI_DRIVER);
  967. if (retval)
  968. goto error_ssb;
  969. #endif
  970. #ifdef SM501_OHCI_DRIVER
  971. retval = platform_driver_register(&SM501_OHCI_DRIVER);
  972. if (retval < 0)
  973. goto error_sm501;
  974. #endif
  975. #ifdef TMIO_OHCI_DRIVER
  976. retval = platform_driver_register(&TMIO_OHCI_DRIVER);
  977. if (retval < 0)
  978. goto error_tmio;
  979. #endif
  980. return retval;
  981. /* Error path */
  982. #ifdef TMIO_OHCI_DRIVER
  983. platform_driver_unregister(&TMIO_OHCI_DRIVER);
  984. error_tmio:
  985. #endif
  986. #ifdef SM501_OHCI_DRIVER
  987. platform_driver_unregister(&SM501_OHCI_DRIVER);
  988. error_sm501:
  989. #endif
  990. #ifdef SSB_OHCI_DRIVER
  991. ssb_driver_unregister(&SSB_OHCI_DRIVER);
  992. error_ssb:
  993. #endif
  994. #ifdef PCI_DRIVER
  995. pci_unregister_driver(&PCI_DRIVER);
  996. error_pci:
  997. #endif
  998. #ifdef SA1111_DRIVER
  999. sa1111_driver_unregister(&SA1111_DRIVER);
  1000. error_sa1111:
  1001. #endif
  1002. #ifdef OF_PLATFORM_DRIVER
  1003. of_unregister_platform_driver(&OF_PLATFORM_DRIVER);
  1004. error_of_platform:
  1005. #endif
  1006. #ifdef PLATFORM_DRIVER
  1007. platform_driver_unregister(&PLATFORM_DRIVER);
  1008. error_platform:
  1009. #endif
  1010. #ifdef PS3_SYSTEM_BUS_DRIVER
  1011. ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
  1012. error_ps3:
  1013. #endif
  1014. #ifdef DEBUG
  1015. debugfs_remove(ohci_debug_root);
  1016. ohci_debug_root = NULL;
  1017. error_debug:
  1018. #endif
  1019. clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
  1020. return retval;
  1021. }
  1022. module_init(ohci_hcd_mod_init);
  1023. static void __exit ohci_hcd_mod_exit(void)
  1024. {
  1025. #ifdef TMIO_OHCI_DRIVER
  1026. platform_driver_unregister(&TMIO_OHCI_DRIVER);
  1027. #endif
  1028. #ifdef SM501_OHCI_DRIVER
  1029. platform_driver_unregister(&SM501_OHCI_DRIVER);
  1030. #endif
  1031. #ifdef SSB_OHCI_DRIVER
  1032. ssb_driver_unregister(&SSB_OHCI_DRIVER);
  1033. #endif
  1034. #ifdef PCI_DRIVER
  1035. pci_unregister_driver(&PCI_DRIVER);
  1036. #endif
  1037. #ifdef SA1111_DRIVER
  1038. sa1111_driver_unregister(&SA1111_DRIVER);
  1039. #endif
  1040. #ifdef OF_PLATFORM_DRIVER
  1041. of_unregister_platform_driver(&OF_PLATFORM_DRIVER);
  1042. #endif
  1043. #ifdef PLATFORM_DRIVER
  1044. platform_driver_unregister(&PLATFORM_DRIVER);
  1045. #endif
  1046. #ifdef PS3_SYSTEM_BUS_DRIVER
  1047. ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
  1048. #endif
  1049. #ifdef DEBUG
  1050. debugfs_remove(ohci_debug_root);
  1051. #endif
  1052. clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
  1053. }
  1054. module_exit(ohci_hcd_mod_exit);