ohci-hcd.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277
  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 (!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_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. #ifdef CONFIG_ARCH_LH7A404
  860. #include "ohci-lh7a404.c"
  861. #define PLATFORM_DRIVER ohci_hcd_lh7a404_driver
  862. #endif
  863. #if defined(CONFIG_PXA27x) || defined(CONFIG_PXA3xx)
  864. #include "ohci-pxa27x.c"
  865. #define PLATFORM_DRIVER ohci_hcd_pxa27x_driver
  866. #endif
  867. #ifdef CONFIG_ARCH_EP93XX
  868. #include "ohci-ep93xx.c"
  869. #define PLATFORM_DRIVER ohci_hcd_ep93xx_driver
  870. #endif
  871. #ifdef CONFIG_SOC_AU1X00
  872. #include "ohci-au1xxx.c"
  873. #define PLATFORM_DRIVER ohci_hcd_au1xxx_driver
  874. #endif
  875. #ifdef CONFIG_PNX8550
  876. #include "ohci-pnx8550.c"
  877. #define PLATFORM_DRIVER ohci_hcd_pnx8550_driver
  878. #endif
  879. #ifdef CONFIG_USB_OHCI_HCD_PPC_SOC
  880. #include "ohci-ppc-soc.c"
  881. #define PLATFORM_DRIVER ohci_hcd_ppc_soc_driver
  882. #endif
  883. #ifdef CONFIG_ARCH_AT91
  884. #include "ohci-at91.c"
  885. #define PLATFORM_DRIVER ohci_hcd_at91_driver
  886. #endif
  887. #ifdef CONFIG_ARCH_PNX4008
  888. #include "ohci-pnx4008.c"
  889. #define PLATFORM_DRIVER usb_hcd_pnx4008_driver
  890. #endif
  891. #ifdef CONFIG_ARCH_DAVINCI_DA8XX
  892. #include "ohci-da8xx.c"
  893. #define PLATFORM_DRIVER ohci_hcd_da8xx_driver
  894. #endif
  895. #if defined(CONFIG_CPU_SUBTYPE_SH7720) || \
  896. defined(CONFIG_CPU_SUBTYPE_SH7721) || \
  897. defined(CONFIG_CPU_SUBTYPE_SH7763) || \
  898. defined(CONFIG_CPU_SUBTYPE_SH7786)
  899. #include "ohci-sh.c"
  900. #define PLATFORM_DRIVER ohci_hcd_sh_driver
  901. #endif
  902. #ifdef CONFIG_USB_OHCI_HCD_PPC_OF
  903. #include "ohci-ppc-of.c"
  904. #define OF_PLATFORM_DRIVER ohci_hcd_ppc_of_driver
  905. #endif
  906. #ifdef CONFIG_PPC_PS3
  907. #include "ohci-ps3.c"
  908. #define PS3_SYSTEM_BUS_DRIVER ps3_ohci_driver
  909. #endif
  910. #ifdef CONFIG_USB_OHCI_HCD_SSB
  911. #include "ohci-ssb.c"
  912. #define SSB_OHCI_DRIVER ssb_ohci_driver
  913. #endif
  914. #ifdef CONFIG_MFD_SM501
  915. #include "ohci-sm501.c"
  916. #define SM501_OHCI_DRIVER ohci_hcd_sm501_driver
  917. #endif
  918. #ifdef CONFIG_MFD_TC6393XB
  919. #include "ohci-tmio.c"
  920. #define TMIO_OHCI_DRIVER ohci_hcd_tmio_driver
  921. #endif
  922. #if !defined(PCI_DRIVER) && \
  923. !defined(PLATFORM_DRIVER) && \
  924. !defined(OMAP1_PLATFORM_DRIVER) && \
  925. !defined(OMAP3_PLATFORM_DRIVER) && \
  926. !defined(OF_PLATFORM_DRIVER) && \
  927. !defined(SA1111_DRIVER) && \
  928. !defined(PS3_SYSTEM_BUS_DRIVER) && \
  929. !defined(SM501_OHCI_DRIVER) && \
  930. !defined(TMIO_OHCI_DRIVER) && \
  931. !defined(SSB_OHCI_DRIVER)
  932. #error "missing bus glue for ohci-hcd"
  933. #endif
  934. static int __init ohci_hcd_mod_init(void)
  935. {
  936. int retval = 0;
  937. if (usb_disabled())
  938. return -ENODEV;
  939. printk(KERN_INFO "%s: " DRIVER_DESC "\n", hcd_name);
  940. pr_debug ("%s: block sizes: ed %Zd td %Zd\n", hcd_name,
  941. sizeof (struct ed), sizeof (struct td));
  942. set_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
  943. #ifdef DEBUG
  944. ohci_debug_root = debugfs_create_dir("ohci", usb_debug_root);
  945. if (!ohci_debug_root) {
  946. retval = -ENOENT;
  947. goto error_debug;
  948. }
  949. #endif
  950. #ifdef PS3_SYSTEM_BUS_DRIVER
  951. retval = ps3_ohci_driver_register(&PS3_SYSTEM_BUS_DRIVER);
  952. if (retval < 0)
  953. goto error_ps3;
  954. #endif
  955. #ifdef PLATFORM_DRIVER
  956. retval = platform_driver_register(&PLATFORM_DRIVER);
  957. if (retval < 0)
  958. goto error_platform;
  959. #endif
  960. #ifdef OMAP1_PLATFORM_DRIVER
  961. retval = platform_driver_register(&OMAP1_PLATFORM_DRIVER);
  962. if (retval < 0)
  963. goto error_omap1_platform;
  964. #endif
  965. #ifdef OMAP3_PLATFORM_DRIVER
  966. retval = platform_driver_register(&OMAP3_PLATFORM_DRIVER);
  967. if (retval < 0)
  968. goto error_omap3_platform;
  969. #endif
  970. #ifdef OF_PLATFORM_DRIVER
  971. retval = of_register_platform_driver(&OF_PLATFORM_DRIVER);
  972. if (retval < 0)
  973. goto error_of_platform;
  974. #endif
  975. #ifdef SA1111_DRIVER
  976. retval = sa1111_driver_register(&SA1111_DRIVER);
  977. if (retval < 0)
  978. goto error_sa1111;
  979. #endif
  980. #ifdef PCI_DRIVER
  981. retval = pci_register_driver(&PCI_DRIVER);
  982. if (retval < 0)
  983. goto error_pci;
  984. #endif
  985. #ifdef SSB_OHCI_DRIVER
  986. retval = ssb_driver_register(&SSB_OHCI_DRIVER);
  987. if (retval)
  988. goto error_ssb;
  989. #endif
  990. #ifdef SM501_OHCI_DRIVER
  991. retval = platform_driver_register(&SM501_OHCI_DRIVER);
  992. if (retval < 0)
  993. goto error_sm501;
  994. #endif
  995. #ifdef TMIO_OHCI_DRIVER
  996. retval = platform_driver_register(&TMIO_OHCI_DRIVER);
  997. if (retval < 0)
  998. goto error_tmio;
  999. #endif
  1000. return retval;
  1001. /* Error path */
  1002. #ifdef TMIO_OHCI_DRIVER
  1003. platform_driver_unregister(&TMIO_OHCI_DRIVER);
  1004. error_tmio:
  1005. #endif
  1006. #ifdef SM501_OHCI_DRIVER
  1007. platform_driver_unregister(&SM501_OHCI_DRIVER);
  1008. error_sm501:
  1009. #endif
  1010. #ifdef SSB_OHCI_DRIVER
  1011. ssb_driver_unregister(&SSB_OHCI_DRIVER);
  1012. error_ssb:
  1013. #endif
  1014. #ifdef PCI_DRIVER
  1015. pci_unregister_driver(&PCI_DRIVER);
  1016. error_pci:
  1017. #endif
  1018. #ifdef SA1111_DRIVER
  1019. sa1111_driver_unregister(&SA1111_DRIVER);
  1020. error_sa1111:
  1021. #endif
  1022. #ifdef OF_PLATFORM_DRIVER
  1023. of_unregister_platform_driver(&OF_PLATFORM_DRIVER);
  1024. error_of_platform:
  1025. #endif
  1026. #ifdef PLATFORM_DRIVER
  1027. platform_driver_unregister(&PLATFORM_DRIVER);
  1028. error_platform:
  1029. #endif
  1030. #ifdef OMAP1_PLATFORM_DRIVER
  1031. platform_driver_unregister(&OMAP1_PLATFORM_DRIVER);
  1032. error_omap1_platform:
  1033. #endif
  1034. #ifdef OMAP3_PLATFORM_DRIVER
  1035. platform_driver_unregister(&OMAP3_PLATFORM_DRIVER);
  1036. error_omap3_platform:
  1037. #endif
  1038. #ifdef PS3_SYSTEM_BUS_DRIVER
  1039. ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
  1040. error_ps3:
  1041. #endif
  1042. #ifdef DEBUG
  1043. debugfs_remove(ohci_debug_root);
  1044. ohci_debug_root = NULL;
  1045. error_debug:
  1046. #endif
  1047. clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
  1048. return retval;
  1049. }
  1050. module_init(ohci_hcd_mod_init);
  1051. static void __exit ohci_hcd_mod_exit(void)
  1052. {
  1053. #ifdef TMIO_OHCI_DRIVER
  1054. platform_driver_unregister(&TMIO_OHCI_DRIVER);
  1055. #endif
  1056. #ifdef SM501_OHCI_DRIVER
  1057. platform_driver_unregister(&SM501_OHCI_DRIVER);
  1058. #endif
  1059. #ifdef SSB_OHCI_DRIVER
  1060. ssb_driver_unregister(&SSB_OHCI_DRIVER);
  1061. #endif
  1062. #ifdef PCI_DRIVER
  1063. pci_unregister_driver(&PCI_DRIVER);
  1064. #endif
  1065. #ifdef SA1111_DRIVER
  1066. sa1111_driver_unregister(&SA1111_DRIVER);
  1067. #endif
  1068. #ifdef OF_PLATFORM_DRIVER
  1069. of_unregister_platform_driver(&OF_PLATFORM_DRIVER);
  1070. #endif
  1071. #ifdef PLATFORM_DRIVER
  1072. platform_driver_unregister(&PLATFORM_DRIVER);
  1073. #endif
  1074. #ifdef PS3_SYSTEM_BUS_DRIVER
  1075. ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
  1076. #endif
  1077. #ifdef DEBUG
  1078. debugfs_remove(ohci_debug_root);
  1079. #endif
  1080. clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
  1081. }
  1082. module_exit(ohci_hcd_mod_exit);