ohci-hcd.c 33 KB

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