ohci-hcd.c 35 KB

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