ohci-hcd.c 35 KB

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