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