ohci-hcd.c 33 KB

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