ohci-hcd.c 36 KB

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