ohci-hcd.c 33 KB

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