ohci-hcd.c 42 KB

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