ohci-hcd.c 36 KB

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