ohci-hcd.c 35 KB

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