ohci-hcd.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357
  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. /* Disable irq emission and mark HW unaccessible. Use
  879. * the spinlock to properly synchronize with possible pending
  880. * RH suspend or resume activity.
  881. */
  882. spin_lock_irqsave (&ohci->lock, flags);
  883. ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
  884. (void)ohci_readl(ohci, &ohci->regs->intrdisable);
  885. clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  886. spin_unlock_irqrestore (&ohci->lock, flags);
  887. return 0;
  888. }
  889. EXPORT_SYMBOL_GPL(ohci_suspend);
  890. int ohci_resume(struct usb_hcd *hcd, bool hibernated)
  891. {
  892. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  893. int port;
  894. bool need_reinit = false;
  895. set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  896. /* Make sure resume from hibernation re-enumerates everything */
  897. if (hibernated)
  898. ohci_usb_reset(ohci);
  899. /* See if the controller is already running or has been reset */
  900. ohci->hc_control = ohci_readl(ohci, &ohci->regs->control);
  901. if (ohci->hc_control & (OHCI_CTRL_IR | OHCI_SCHED_ENABLES)) {
  902. need_reinit = true;
  903. } else {
  904. switch (ohci->hc_control & OHCI_CTRL_HCFS) {
  905. case OHCI_USB_OPER:
  906. case OHCI_USB_RESET:
  907. need_reinit = true;
  908. }
  909. }
  910. /* If needed, reinitialize and suspend the root hub */
  911. if (need_reinit) {
  912. spin_lock_irq(&ohci->lock);
  913. ohci_rh_resume(ohci);
  914. ohci_rh_suspend(ohci, 0);
  915. spin_unlock_irq(&ohci->lock);
  916. }
  917. /* Normally just turn on port power and enable interrupts */
  918. else {
  919. ohci_dbg(ohci, "powerup ports\n");
  920. for (port = 0; port < ohci->num_ports; port++)
  921. ohci_writel(ohci, RH_PS_PPS,
  922. &ohci->regs->roothub.portstatus[port]);
  923. ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrenable);
  924. ohci_readl(ohci, &ohci->regs->intrenable);
  925. msleep(20);
  926. }
  927. usb_hcd_resume_root_hub(hcd);
  928. return 0;
  929. }
  930. EXPORT_SYMBOL_GPL(ohci_resume);
  931. #endif
  932. /*-------------------------------------------------------------------------*/
  933. /*
  934. * Generic structure: This gets copied for platform drivers so that
  935. * individual entries can be overridden as needed.
  936. */
  937. static const struct hc_driver ohci_hc_driver = {
  938. .description = hcd_name,
  939. .product_desc = "OHCI Host Controller",
  940. .hcd_priv_size = sizeof(struct ohci_hcd),
  941. /*
  942. * generic hardware linkage
  943. */
  944. .irq = ohci_irq,
  945. .flags = HCD_MEMORY | HCD_USB11,
  946. /*
  947. * basic lifecycle operations
  948. */
  949. .reset = ohci_setup,
  950. .start = ohci_start,
  951. .stop = ohci_stop,
  952. .shutdown = ohci_shutdown,
  953. /*
  954. * managing i/o requests and associated device resources
  955. */
  956. .urb_enqueue = ohci_urb_enqueue,
  957. .urb_dequeue = ohci_urb_dequeue,
  958. .endpoint_disable = ohci_endpoint_disable,
  959. /*
  960. * scheduling support
  961. */
  962. .get_frame_number = ohci_get_frame,
  963. /*
  964. * root hub support
  965. */
  966. .hub_status_data = ohci_hub_status_data,
  967. .hub_control = ohci_hub_control,
  968. #ifdef CONFIG_PM
  969. .bus_suspend = ohci_bus_suspend,
  970. .bus_resume = ohci_bus_resume,
  971. #endif
  972. .start_port_reset = ohci_start_port_reset,
  973. };
  974. void ohci_init_driver(struct hc_driver *drv,
  975. const struct ohci_driver_overrides *over)
  976. {
  977. /* Copy the generic table to drv and then apply the overrides */
  978. *drv = ohci_hc_driver;
  979. if (over) {
  980. drv->product_desc = over->product_desc;
  981. drv->hcd_priv_size += over->extra_priv_size;
  982. if (over->reset)
  983. drv->reset = over->reset;
  984. }
  985. }
  986. EXPORT_SYMBOL_GPL(ohci_init_driver);
  987. /*-------------------------------------------------------------------------*/
  988. MODULE_AUTHOR (DRIVER_AUTHOR);
  989. MODULE_DESCRIPTION(DRIVER_DESC);
  990. MODULE_LICENSE ("GPL");
  991. #if defined(CONFIG_ARCH_SA1100) && defined(CONFIG_SA1111)
  992. #include "ohci-sa1111.c"
  993. #define SA1111_DRIVER ohci_hcd_sa1111_driver
  994. #endif
  995. #ifdef CONFIG_ARCH_DAVINCI_DA8XX
  996. #include "ohci-da8xx.c"
  997. #define DAVINCI_PLATFORM_DRIVER ohci_hcd_da8xx_driver
  998. #endif
  999. #ifdef CONFIG_USB_OHCI_HCD_PPC_OF
  1000. #include "ohci-ppc-of.c"
  1001. #define OF_PLATFORM_DRIVER ohci_hcd_ppc_of_driver
  1002. #endif
  1003. #ifdef CONFIG_PPC_PS3
  1004. #include "ohci-ps3.c"
  1005. #define PS3_SYSTEM_BUS_DRIVER ps3_ohci_driver
  1006. #endif
  1007. #ifdef CONFIG_MFD_SM501
  1008. #include "ohci-sm501.c"
  1009. #define SM501_OHCI_DRIVER ohci_hcd_sm501_driver
  1010. #endif
  1011. #ifdef CONFIG_MFD_TC6393XB
  1012. #include "ohci-tmio.c"
  1013. #define TMIO_OHCI_DRIVER ohci_hcd_tmio_driver
  1014. #endif
  1015. #ifdef CONFIG_MACH_JZ4740
  1016. #include "ohci-jz4740.c"
  1017. #define PLATFORM_DRIVER ohci_hcd_jz4740_driver
  1018. #endif
  1019. #ifdef CONFIG_USB_OCTEON_OHCI
  1020. #include "ohci-octeon.c"
  1021. #define PLATFORM_DRIVER ohci_octeon_driver
  1022. #endif
  1023. #ifdef CONFIG_TILE_USB
  1024. #include "ohci-tilegx.c"
  1025. #define PLATFORM_DRIVER ohci_hcd_tilegx_driver
  1026. #endif
  1027. static int __init ohci_hcd_mod_init(void)
  1028. {
  1029. int retval = 0;
  1030. if (usb_disabled())
  1031. return -ENODEV;
  1032. printk(KERN_INFO "%s: " DRIVER_DESC "\n", hcd_name);
  1033. pr_debug ("%s: block sizes: ed %Zd td %Zd\n", hcd_name,
  1034. sizeof (struct ed), sizeof (struct td));
  1035. set_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
  1036. #ifdef DEBUG
  1037. ohci_debug_root = debugfs_create_dir("ohci", usb_debug_root);
  1038. if (!ohci_debug_root) {
  1039. retval = -ENOENT;
  1040. goto error_debug;
  1041. }
  1042. #endif
  1043. #ifdef PS3_SYSTEM_BUS_DRIVER
  1044. retval = ps3_ohci_driver_register(&PS3_SYSTEM_BUS_DRIVER);
  1045. if (retval < 0)
  1046. goto error_ps3;
  1047. #endif
  1048. #ifdef PLATFORM_DRIVER
  1049. retval = platform_driver_register(&PLATFORM_DRIVER);
  1050. if (retval < 0)
  1051. goto error_platform;
  1052. #endif
  1053. #ifdef OF_PLATFORM_DRIVER
  1054. retval = platform_driver_register(&OF_PLATFORM_DRIVER);
  1055. if (retval < 0)
  1056. goto error_of_platform;
  1057. #endif
  1058. #ifdef SA1111_DRIVER
  1059. retval = sa1111_driver_register(&SA1111_DRIVER);
  1060. if (retval < 0)
  1061. goto error_sa1111;
  1062. #endif
  1063. #ifdef SM501_OHCI_DRIVER
  1064. retval = platform_driver_register(&SM501_OHCI_DRIVER);
  1065. if (retval < 0)
  1066. goto error_sm501;
  1067. #endif
  1068. #ifdef TMIO_OHCI_DRIVER
  1069. retval = platform_driver_register(&TMIO_OHCI_DRIVER);
  1070. if (retval < 0)
  1071. goto error_tmio;
  1072. #endif
  1073. #ifdef DAVINCI_PLATFORM_DRIVER
  1074. retval = platform_driver_register(&DAVINCI_PLATFORM_DRIVER);
  1075. if (retval < 0)
  1076. goto error_davinci;
  1077. #endif
  1078. return retval;
  1079. /* Error path */
  1080. #ifdef DAVINCI_PLATFORM_DRIVER
  1081. platform_driver_unregister(&DAVINCI_PLATFORM_DRIVER);
  1082. error_davinci:
  1083. #endif
  1084. #ifdef TMIO_OHCI_DRIVER
  1085. platform_driver_unregister(&TMIO_OHCI_DRIVER);
  1086. error_tmio:
  1087. #endif
  1088. #ifdef SM501_OHCI_DRIVER
  1089. platform_driver_unregister(&SM501_OHCI_DRIVER);
  1090. error_sm501:
  1091. #endif
  1092. #ifdef SA1111_DRIVER
  1093. sa1111_driver_unregister(&SA1111_DRIVER);
  1094. error_sa1111:
  1095. #endif
  1096. #ifdef OF_PLATFORM_DRIVER
  1097. platform_driver_unregister(&OF_PLATFORM_DRIVER);
  1098. error_of_platform:
  1099. #endif
  1100. #ifdef PLATFORM_DRIVER
  1101. platform_driver_unregister(&PLATFORM_DRIVER);
  1102. error_platform:
  1103. #endif
  1104. #ifdef PS3_SYSTEM_BUS_DRIVER
  1105. ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
  1106. error_ps3:
  1107. #endif
  1108. #ifdef DEBUG
  1109. debugfs_remove(ohci_debug_root);
  1110. ohci_debug_root = NULL;
  1111. error_debug:
  1112. #endif
  1113. clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
  1114. return retval;
  1115. }
  1116. module_init(ohci_hcd_mod_init);
  1117. static void __exit ohci_hcd_mod_exit(void)
  1118. {
  1119. #ifdef DAVINCI_PLATFORM_DRIVER
  1120. platform_driver_unregister(&DAVINCI_PLATFORM_DRIVER);
  1121. #endif
  1122. #ifdef TMIO_OHCI_DRIVER
  1123. platform_driver_unregister(&TMIO_OHCI_DRIVER);
  1124. #endif
  1125. #ifdef SM501_OHCI_DRIVER
  1126. platform_driver_unregister(&SM501_OHCI_DRIVER);
  1127. #endif
  1128. #ifdef SA1111_DRIVER
  1129. sa1111_driver_unregister(&SA1111_DRIVER);
  1130. #endif
  1131. #ifdef OF_PLATFORM_DRIVER
  1132. platform_driver_unregister(&OF_PLATFORM_DRIVER);
  1133. #endif
  1134. #ifdef PLATFORM_DRIVER
  1135. platform_driver_unregister(&PLATFORM_DRIVER);
  1136. #endif
  1137. #ifdef PS3_SYSTEM_BUS_DRIVER
  1138. ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
  1139. #endif
  1140. #ifdef DEBUG
  1141. debugfs_remove(ohci_debug_root);
  1142. #endif
  1143. clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
  1144. }
  1145. module_exit(ohci_hcd_mod_exit);