ohci-hcd.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357
  1. // SPDX-License-Identifier: GPL-1.0+
  2. /*
  3. * Open Host Controller Interface (OHCI) driver for USB.
  4. *
  5. * Maintainer: Alan Stern <stern@rowland.harvard.edu>
  6. *
  7. * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
  8. * (C) Copyright 2000-2004 David Brownell <dbrownell@users.sourceforge.net>
  9. *
  10. * [ Initialisation is based on Linus' ]
  11. * [ uhci code and gregs ohci fragments ]
  12. * [ (C) Copyright 1999 Linus Torvalds ]
  13. * [ (C) Copyright 1999 Gregory P. Smith]
  14. *
  15. *
  16. * OHCI is the main "non-Intel/VIA" standard for USB 1.1 host controller
  17. * interfaces (though some non-x86 Intel chips use it). It supports
  18. * smarter hardware than UHCI. A download link for the spec available
  19. * through the http://www.usb.org website.
  20. *
  21. * This file is licenced under the GPL.
  22. */
  23. #include <linux/module.h>
  24. #include <linux/moduleparam.h>
  25. #include <linux/pci.h>
  26. #include <linux/kernel.h>
  27. #include <linux/delay.h>
  28. #include <linux/ioport.h>
  29. #include <linux/sched.h>
  30. #include <linux/slab.h>
  31. #include <linux/errno.h>
  32. #include <linux/init.h>
  33. #include <linux/timer.h>
  34. #include <linux/list.h>
  35. #include <linux/usb.h>
  36. #include <linux/usb/otg.h>
  37. #include <linux/usb/hcd.h>
  38. #include <linux/dma-mapping.h>
  39. #include <linux/dmapool.h>
  40. #include <linux/workqueue.h>
  41. #include <linux/debugfs.h>
  42. #include <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(struct timer_list *t);
  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;
  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. /* 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. timer_setup(&ohci->io_watchdog, io_watchdog_func, 0);
  437. ohci->prev_frame_no = IO_WATCHDOG_OFF;
  438. ohci->hcca = dma_alloc_coherent (hcd->self.controller,
  439. sizeof(*ohci->hcca), &ohci->hcca_dma, GFP_KERNEL);
  440. if (!ohci->hcca)
  441. return -ENOMEM;
  442. if ((ret = ohci_mem_init (ohci)) < 0)
  443. ohci_stop (hcd);
  444. else {
  445. create_debug_files (ohci);
  446. }
  447. return ret;
  448. }
  449. /*-------------------------------------------------------------------------*/
  450. /* Start an OHCI controller, set the BUS operational
  451. * resets USB and controller
  452. * enable interrupts
  453. */
  454. static int ohci_run (struct ohci_hcd *ohci)
  455. {
  456. u32 mask, val;
  457. int first = ohci->fminterval == 0;
  458. struct usb_hcd *hcd = ohci_to_hcd(ohci);
  459. ohci->rh_state = OHCI_RH_HALTED;
  460. /* boot firmware should have set this up (5.1.1.3.1) */
  461. if (first) {
  462. val = ohci_readl (ohci, &ohci->regs->fminterval);
  463. ohci->fminterval = val & 0x3fff;
  464. if (ohci->fminterval != FI)
  465. ohci_dbg (ohci, "fminterval delta %d\n",
  466. ohci->fminterval - FI);
  467. ohci->fminterval |= FSMP (ohci->fminterval) << 16;
  468. /* also: power/overcurrent flags in roothub.a */
  469. }
  470. /* Reset USB nearly "by the book". RemoteWakeupConnected has
  471. * to be checked in case boot firmware (BIOS/SMM/...) has set up
  472. * wakeup in a way the bus isn't aware of (e.g., legacy PCI PM).
  473. * If the bus glue detected wakeup capability then it should
  474. * already be enabled; if so we'll just enable it again.
  475. */
  476. if ((ohci->hc_control & OHCI_CTRL_RWC) != 0)
  477. device_set_wakeup_capable(hcd->self.controller, 1);
  478. switch (ohci->hc_control & OHCI_CTRL_HCFS) {
  479. case OHCI_USB_OPER:
  480. val = 0;
  481. break;
  482. case OHCI_USB_SUSPEND:
  483. case OHCI_USB_RESUME:
  484. ohci->hc_control &= OHCI_CTRL_RWC;
  485. ohci->hc_control |= OHCI_USB_RESUME;
  486. val = 10 /* msec wait */;
  487. break;
  488. // case OHCI_USB_RESET:
  489. default:
  490. ohci->hc_control &= OHCI_CTRL_RWC;
  491. ohci->hc_control |= OHCI_USB_RESET;
  492. val = 50 /* msec wait */;
  493. break;
  494. }
  495. ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
  496. // flush the writes
  497. (void) ohci_readl (ohci, &ohci->regs->control);
  498. msleep(val);
  499. memset (ohci->hcca, 0, sizeof (struct ohci_hcca));
  500. /* 2msec timelimit here means no irqs/preempt */
  501. spin_lock_irq (&ohci->lock);
  502. retry:
  503. /* HC Reset requires max 10 us delay */
  504. ohci_writel (ohci, OHCI_HCR, &ohci->regs->cmdstatus);
  505. val = 30; /* ... allow extra time */
  506. while ((ohci_readl (ohci, &ohci->regs->cmdstatus) & OHCI_HCR) != 0) {
  507. if (--val == 0) {
  508. spin_unlock_irq (&ohci->lock);
  509. ohci_err (ohci, "USB HC reset timed out!\n");
  510. return -1;
  511. }
  512. udelay (1);
  513. }
  514. /* now we're in the SUSPEND state ... must go OPERATIONAL
  515. * within 2msec else HC enters RESUME
  516. *
  517. * ... but some hardware won't init fmInterval "by the book"
  518. * (SiS, OPTi ...), so reset again instead. SiS doesn't need
  519. * this if we write fmInterval after we're OPERATIONAL.
  520. * Unclear about ALi, ServerWorks, and others ... this could
  521. * easily be a longstanding bug in chip init on Linux.
  522. */
  523. if (ohci->flags & OHCI_QUIRK_INITRESET) {
  524. ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
  525. // flush those writes
  526. (void) ohci_readl (ohci, &ohci->regs->control);
  527. }
  528. /* Tell the controller where the control and bulk lists are
  529. * The lists are empty now. */
  530. ohci_writel (ohci, 0, &ohci->regs->ed_controlhead);
  531. ohci_writel (ohci, 0, &ohci->regs->ed_bulkhead);
  532. /* a reset clears this */
  533. ohci_writel (ohci, (u32) ohci->hcca_dma, &ohci->regs->hcca);
  534. periodic_reinit (ohci);
  535. /* some OHCI implementations are finicky about how they init.
  536. * bogus values here mean not even enumeration could work.
  537. */
  538. if ((ohci_readl (ohci, &ohci->regs->fminterval) & 0x3fff0000) == 0
  539. || !ohci_readl (ohci, &ohci->regs->periodicstart)) {
  540. if (!(ohci->flags & OHCI_QUIRK_INITRESET)) {
  541. ohci->flags |= OHCI_QUIRK_INITRESET;
  542. ohci_dbg (ohci, "enabling initreset quirk\n");
  543. goto retry;
  544. }
  545. spin_unlock_irq (&ohci->lock);
  546. ohci_err (ohci, "init err (%08x %04x)\n",
  547. ohci_readl (ohci, &ohci->regs->fminterval),
  548. ohci_readl (ohci, &ohci->regs->periodicstart));
  549. return -EOVERFLOW;
  550. }
  551. /* use rhsc irqs after hub_wq is allocated */
  552. set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
  553. hcd->uses_new_polling = 1;
  554. /* start controller operations */
  555. ohci->hc_control &= OHCI_CTRL_RWC;
  556. ohci->hc_control |= OHCI_CONTROL_INIT | OHCI_USB_OPER;
  557. ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
  558. ohci->rh_state = OHCI_RH_RUNNING;
  559. /* wake on ConnectStatusChange, matching external hubs */
  560. ohci_writel (ohci, RH_HS_DRWE, &ohci->regs->roothub.status);
  561. /* Choose the interrupts we care about now, others later on demand */
  562. mask = OHCI_INTR_INIT;
  563. ohci_writel (ohci, ~0, &ohci->regs->intrstatus);
  564. ohci_writel (ohci, mask, &ohci->regs->intrenable);
  565. /* handle root hub init quirks ... */
  566. val = roothub_a (ohci);
  567. /* Configure for per-port over-current protection by default */
  568. val &= ~RH_A_NOCP;
  569. val |= RH_A_OCPM;
  570. if (ohci->flags & OHCI_QUIRK_SUPERIO) {
  571. /* NSC 87560 and maybe others.
  572. * Ganged power switching, no over-current protection.
  573. */
  574. val |= RH_A_NOCP;
  575. val &= ~(RH_A_POTPGT | RH_A_NPS | RH_A_PSM | RH_A_OCPM);
  576. } else if ((ohci->flags & OHCI_QUIRK_AMD756) ||
  577. (ohci->flags & OHCI_QUIRK_HUB_POWER)) {
  578. /* hub power always on; required for AMD-756 and some
  579. * Mac platforms.
  580. */
  581. val |= RH_A_NPS;
  582. }
  583. ohci_writel(ohci, val, &ohci->regs->roothub.a);
  584. ohci_writel (ohci, RH_HS_LPSC, &ohci->regs->roothub.status);
  585. ohci_writel (ohci, (val & RH_A_NPS) ? 0 : RH_B_PPCM,
  586. &ohci->regs->roothub.b);
  587. // flush those writes
  588. (void) ohci_readl (ohci, &ohci->regs->control);
  589. ohci->next_statechange = jiffies + STATECHANGE_DELAY;
  590. spin_unlock_irq (&ohci->lock);
  591. // POTPGT delay is bits 24-31, in 2 ms units.
  592. mdelay ((val >> 23) & 0x1fe);
  593. ohci_dump(ohci);
  594. return 0;
  595. }
  596. /* ohci_setup routine for generic controller initialization */
  597. int ohci_setup(struct usb_hcd *hcd)
  598. {
  599. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  600. ohci_hcd_init(ohci);
  601. return ohci_init(ohci);
  602. }
  603. EXPORT_SYMBOL_GPL(ohci_setup);
  604. /* ohci_start routine for generic controller start of all OHCI bus glue */
  605. static int ohci_start(struct usb_hcd *hcd)
  606. {
  607. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  608. int ret;
  609. ret = ohci_run(ohci);
  610. if (ret < 0) {
  611. ohci_err(ohci, "can't start\n");
  612. ohci_stop(hcd);
  613. }
  614. return ret;
  615. }
  616. /*-------------------------------------------------------------------------*/
  617. /*
  618. * Some OHCI controllers are known to lose track of completed TDs. They
  619. * don't add the TDs to the hardware done queue, which means we never see
  620. * them as being completed.
  621. *
  622. * This watchdog routine checks for such problems. Without some way to
  623. * tell when those TDs have completed, we would never take their EDs off
  624. * the unlink list. As a result, URBs could never be dequeued and
  625. * endpoints could never be released.
  626. */
  627. static void io_watchdog_func(struct timer_list *t)
  628. {
  629. struct ohci_hcd *ohci = from_timer(ohci, t, io_watchdog);
  630. bool takeback_all_pending = false;
  631. u32 status;
  632. u32 head;
  633. struct ed *ed;
  634. struct td *td, *td_start, *td_next;
  635. unsigned frame_no, prev_frame_no = IO_WATCHDOG_OFF;
  636. unsigned long flags;
  637. spin_lock_irqsave(&ohci->lock, flags);
  638. /*
  639. * One way to lose track of completed TDs is if the controller
  640. * never writes back the done queue head. If it hasn't been
  641. * written back since the last time this function ran and if it
  642. * was non-empty at that time, something is badly wrong with the
  643. * hardware.
  644. */
  645. status = ohci_readl(ohci, &ohci->regs->intrstatus);
  646. if (!(status & OHCI_INTR_WDH) && ohci->wdh_cnt == ohci->prev_wdh_cnt) {
  647. if (ohci->prev_donehead) {
  648. ohci_err(ohci, "HcDoneHead not written back; disabled\n");
  649. died:
  650. usb_hc_died(ohci_to_hcd(ohci));
  651. ohci_dump(ohci);
  652. _ohci_shutdown(ohci_to_hcd(ohci));
  653. goto done;
  654. } else {
  655. /* No write back because the done queue was empty */
  656. takeback_all_pending = true;
  657. }
  658. }
  659. /* Check every ED which might have pending TDs */
  660. list_for_each_entry(ed, &ohci->eds_in_use, in_use_list) {
  661. if (ed->pending_td) {
  662. if (takeback_all_pending ||
  663. OKAY_TO_TAKEBACK(ohci, ed)) {
  664. unsigned tmp = hc32_to_cpu(ohci, ed->hwINFO);
  665. ohci_dbg(ohci, "takeback pending TD for dev %d ep 0x%x\n",
  666. 0x007f & tmp,
  667. (0x000f & (tmp >> 7)) +
  668. ((tmp & ED_IN) >> 5));
  669. add_to_done_list(ohci, ed->pending_td);
  670. }
  671. }
  672. /* Starting from the latest pending TD, */
  673. td = ed->pending_td;
  674. /* or the last TD on the done list, */
  675. if (!td) {
  676. list_for_each_entry(td_next, &ed->td_list, td_list) {
  677. if (!td_next->next_dl_td)
  678. break;
  679. td = td_next;
  680. }
  681. }
  682. /* find the last TD processed by the controller. */
  683. head = hc32_to_cpu(ohci, READ_ONCE(ed->hwHeadP)) & TD_MASK;
  684. td_start = td;
  685. td_next = list_prepare_entry(td, &ed->td_list, td_list);
  686. list_for_each_entry_continue(td_next, &ed->td_list, td_list) {
  687. if (head == (u32) td_next->td_dma)
  688. break;
  689. td = td_next; /* head pointer has passed this TD */
  690. }
  691. if (td != td_start) {
  692. /*
  693. * In case a WDH cycle is in progress, we will wait
  694. * for the next two cycles to complete before assuming
  695. * this TD will never get on the done queue.
  696. */
  697. ed->takeback_wdh_cnt = ohci->wdh_cnt + 2;
  698. ed->pending_td = td;
  699. }
  700. }
  701. ohci_work(ohci);
  702. if (ohci->rh_state == OHCI_RH_RUNNING) {
  703. /*
  704. * Sometimes a controller just stops working. We can tell
  705. * by checking that the frame counter has advanced since
  706. * the last time we ran.
  707. *
  708. * But be careful: Some controllers violate the spec by
  709. * stopping their frame counter when no ports are active.
  710. */
  711. frame_no = ohci_frame_no(ohci);
  712. if (frame_no == ohci->prev_frame_no) {
  713. int active_cnt = 0;
  714. int i;
  715. unsigned tmp;
  716. for (i = 0; i < ohci->num_ports; ++i) {
  717. tmp = roothub_portstatus(ohci, i);
  718. /* Enabled and not suspended? */
  719. if ((tmp & RH_PS_PES) && !(tmp & RH_PS_PSS))
  720. ++active_cnt;
  721. }
  722. if (active_cnt > 0) {
  723. ohci_err(ohci, "frame counter not updating; disabled\n");
  724. goto died;
  725. }
  726. }
  727. if (!list_empty(&ohci->eds_in_use)) {
  728. prev_frame_no = frame_no;
  729. ohci->prev_wdh_cnt = ohci->wdh_cnt;
  730. ohci->prev_donehead = ohci_readl(ohci,
  731. &ohci->regs->donehead);
  732. mod_timer(&ohci->io_watchdog,
  733. jiffies + IO_WATCHDOG_DELAY);
  734. }
  735. }
  736. done:
  737. ohci->prev_frame_no = prev_frame_no;
  738. spin_unlock_irqrestore(&ohci->lock, flags);
  739. }
  740. /* an interrupt happens */
  741. static irqreturn_t ohci_irq (struct usb_hcd *hcd)
  742. {
  743. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  744. struct ohci_regs __iomem *regs = ohci->regs;
  745. int ints;
  746. /* Read interrupt status (and flush pending writes). We ignore the
  747. * optimization of checking the LSB of hcca->done_head; it doesn't
  748. * work on all systems (edge triggering for OHCI can be a factor).
  749. */
  750. ints = ohci_readl(ohci, &regs->intrstatus);
  751. /* Check for an all 1's result which is a typical consequence
  752. * of dead, unclocked, or unplugged (CardBus...) devices
  753. */
  754. if (ints == ~(u32)0) {
  755. ohci->rh_state = OHCI_RH_HALTED;
  756. ohci_dbg (ohci, "device removed!\n");
  757. usb_hc_died(hcd);
  758. return IRQ_HANDLED;
  759. }
  760. /* We only care about interrupts that are enabled */
  761. ints &= ohci_readl(ohci, &regs->intrenable);
  762. /* interrupt for some other device? */
  763. if (ints == 0 || unlikely(ohci->rh_state == OHCI_RH_HALTED))
  764. return IRQ_NOTMINE;
  765. if (ints & OHCI_INTR_UE) {
  766. // e.g. due to PCI Master/Target Abort
  767. if (quirk_nec(ohci)) {
  768. /* Workaround for a silicon bug in some NEC chips used
  769. * in Apple's PowerBooks. Adapted from Darwin code.
  770. */
  771. ohci_err (ohci, "OHCI Unrecoverable Error, scheduling NEC chip restart\n");
  772. ohci_writel (ohci, OHCI_INTR_UE, &regs->intrdisable);
  773. schedule_work (&ohci->nec_work);
  774. } else {
  775. ohci_err (ohci, "OHCI Unrecoverable Error, disabled\n");
  776. ohci->rh_state = OHCI_RH_HALTED;
  777. usb_hc_died(hcd);
  778. }
  779. ohci_dump(ohci);
  780. ohci_usb_reset (ohci);
  781. }
  782. if (ints & OHCI_INTR_RHSC) {
  783. ohci_dbg(ohci, "rhsc\n");
  784. ohci->next_statechange = jiffies + STATECHANGE_DELAY;
  785. ohci_writel(ohci, OHCI_INTR_RD | OHCI_INTR_RHSC,
  786. &regs->intrstatus);
  787. /* NOTE: Vendors didn't always make the same implementation
  788. * choices for RHSC. Many followed the spec; RHSC triggers
  789. * on an edge, like setting and maybe clearing a port status
  790. * change bit. With others it's level-triggered, active
  791. * until hub_wq clears all the port status change bits. We'll
  792. * always disable it here and rely on polling until hub_wq
  793. * re-enables it.
  794. */
  795. ohci_writel(ohci, OHCI_INTR_RHSC, &regs->intrdisable);
  796. usb_hcd_poll_rh_status(hcd);
  797. }
  798. /* For connect and disconnect events, we expect the controller
  799. * to turn on RHSC along with RD. But for remote wakeup events
  800. * this might not happen.
  801. */
  802. else if (ints & OHCI_INTR_RD) {
  803. ohci_dbg(ohci, "resume detect\n");
  804. ohci_writel(ohci, OHCI_INTR_RD, &regs->intrstatus);
  805. set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
  806. if (ohci->autostop) {
  807. spin_lock (&ohci->lock);
  808. ohci_rh_resume (ohci);
  809. spin_unlock (&ohci->lock);
  810. } else
  811. usb_hcd_resume_root_hub(hcd);
  812. }
  813. spin_lock(&ohci->lock);
  814. if (ints & OHCI_INTR_WDH)
  815. update_done_list(ohci);
  816. /* could track INTR_SO to reduce available PCI/... bandwidth */
  817. /* handle any pending URB/ED unlinks, leaving INTR_SF enabled
  818. * when there's still unlinking to be done (next frame).
  819. */
  820. ohci_work(ohci);
  821. if ((ints & OHCI_INTR_SF) != 0 && !ohci->ed_rm_list
  822. && ohci->rh_state == OHCI_RH_RUNNING)
  823. ohci_writel (ohci, OHCI_INTR_SF, &regs->intrdisable);
  824. if (ohci->rh_state == OHCI_RH_RUNNING) {
  825. ohci_writel (ohci, ints, &regs->intrstatus);
  826. if (ints & OHCI_INTR_WDH)
  827. ++ohci->wdh_cnt;
  828. ohci_writel (ohci, OHCI_INTR_MIE, &regs->intrenable);
  829. // flush those writes
  830. (void) ohci_readl (ohci, &ohci->regs->control);
  831. }
  832. spin_unlock(&ohci->lock);
  833. return IRQ_HANDLED;
  834. }
  835. /*-------------------------------------------------------------------------*/
  836. static void ohci_stop (struct usb_hcd *hcd)
  837. {
  838. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  839. ohci_dump(ohci);
  840. if (quirk_nec(ohci))
  841. flush_work(&ohci->nec_work);
  842. del_timer_sync(&ohci->io_watchdog);
  843. ohci->prev_frame_no = IO_WATCHDOG_OFF;
  844. ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
  845. ohci_usb_reset(ohci);
  846. free_irq(hcd->irq, hcd);
  847. hcd->irq = 0;
  848. if (quirk_amdiso(ohci))
  849. usb_amd_dev_put();
  850. remove_debug_files (ohci);
  851. ohci_mem_cleanup (ohci);
  852. if (ohci->hcca) {
  853. dma_free_coherent (hcd->self.controller,
  854. sizeof *ohci->hcca,
  855. ohci->hcca, ohci->hcca_dma);
  856. ohci->hcca = NULL;
  857. ohci->hcca_dma = 0;
  858. }
  859. }
  860. /*-------------------------------------------------------------------------*/
  861. #if defined(CONFIG_PM) || defined(CONFIG_USB_PCI)
  862. /* must not be called from interrupt context */
  863. int ohci_restart(struct ohci_hcd *ohci)
  864. {
  865. int temp;
  866. int i;
  867. struct urb_priv *priv;
  868. ohci_init(ohci);
  869. spin_lock_irq(&ohci->lock);
  870. ohci->rh_state = OHCI_RH_HALTED;
  871. /* Recycle any "live" eds/tds (and urbs). */
  872. if (!list_empty (&ohci->pending))
  873. ohci_dbg(ohci, "abort schedule...\n");
  874. list_for_each_entry (priv, &ohci->pending, pending) {
  875. struct urb *urb = priv->td[0]->urb;
  876. struct ed *ed = priv->ed;
  877. switch (ed->state) {
  878. case ED_OPER:
  879. ed->state = ED_UNLINK;
  880. ed->hwINFO |= cpu_to_hc32(ohci, ED_DEQUEUE);
  881. ed_deschedule (ohci, ed);
  882. ed->ed_next = ohci->ed_rm_list;
  883. ed->ed_prev = NULL;
  884. ohci->ed_rm_list = ed;
  885. /* FALLTHROUGH */
  886. case ED_UNLINK:
  887. break;
  888. default:
  889. ohci_dbg(ohci, "bogus ed %p state %d\n",
  890. ed, ed->state);
  891. }
  892. if (!urb->unlinked)
  893. urb->unlinked = -ESHUTDOWN;
  894. }
  895. ohci_work(ohci);
  896. spin_unlock_irq(&ohci->lock);
  897. /* paranoia, in case that didn't work: */
  898. /* empty the interrupt branches */
  899. for (i = 0; i < NUM_INTS; i++) ohci->load [i] = 0;
  900. for (i = 0; i < NUM_INTS; i++) ohci->hcca->int_table [i] = 0;
  901. /* no EDs to remove */
  902. ohci->ed_rm_list = NULL;
  903. /* empty control and bulk lists */
  904. ohci->ed_controltail = NULL;
  905. ohci->ed_bulktail = NULL;
  906. if ((temp = ohci_run (ohci)) < 0) {
  907. ohci_err (ohci, "can't restart, %d\n", temp);
  908. return temp;
  909. }
  910. ohci_dbg(ohci, "restart complete\n");
  911. return 0;
  912. }
  913. EXPORT_SYMBOL_GPL(ohci_restart);
  914. #endif
  915. #ifdef CONFIG_PM
  916. int ohci_suspend(struct usb_hcd *hcd, bool do_wakeup)
  917. {
  918. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  919. unsigned long flags;
  920. int rc = 0;
  921. /* Disable irq emission and mark HW unaccessible. Use
  922. * the spinlock to properly synchronize with possible pending
  923. * RH suspend or resume activity.
  924. */
  925. spin_lock_irqsave (&ohci->lock, flags);
  926. ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
  927. (void)ohci_readl(ohci, &ohci->regs->intrdisable);
  928. clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  929. spin_unlock_irqrestore (&ohci->lock, flags);
  930. synchronize_irq(hcd->irq);
  931. if (do_wakeup && HCD_WAKEUP_PENDING(hcd)) {
  932. ohci_resume(hcd, false);
  933. rc = -EBUSY;
  934. }
  935. return rc;
  936. }
  937. EXPORT_SYMBOL_GPL(ohci_suspend);
  938. int ohci_resume(struct usb_hcd *hcd, bool hibernated)
  939. {
  940. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  941. int port;
  942. bool need_reinit = false;
  943. set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  944. /* Make sure resume from hibernation re-enumerates everything */
  945. if (hibernated)
  946. ohci_usb_reset(ohci);
  947. /* See if the controller is already running or has been reset */
  948. ohci->hc_control = ohci_readl(ohci, &ohci->regs->control);
  949. if (ohci->hc_control & (OHCI_CTRL_IR | OHCI_SCHED_ENABLES)) {
  950. need_reinit = true;
  951. } else {
  952. switch (ohci->hc_control & OHCI_CTRL_HCFS) {
  953. case OHCI_USB_OPER:
  954. case OHCI_USB_RESET:
  955. need_reinit = true;
  956. }
  957. }
  958. /* If needed, reinitialize and suspend the root hub */
  959. if (need_reinit) {
  960. spin_lock_irq(&ohci->lock);
  961. ohci_rh_resume(ohci);
  962. ohci_rh_suspend(ohci, 0);
  963. spin_unlock_irq(&ohci->lock);
  964. }
  965. /* Normally just turn on port power and enable interrupts */
  966. else {
  967. ohci_dbg(ohci, "powerup ports\n");
  968. for (port = 0; port < ohci->num_ports; port++)
  969. ohci_writel(ohci, RH_PS_PPS,
  970. &ohci->regs->roothub.portstatus[port]);
  971. ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrenable);
  972. ohci_readl(ohci, &ohci->regs->intrenable);
  973. msleep(20);
  974. }
  975. usb_hcd_resume_root_hub(hcd);
  976. return 0;
  977. }
  978. EXPORT_SYMBOL_GPL(ohci_resume);
  979. #endif
  980. /*-------------------------------------------------------------------------*/
  981. /*
  982. * Generic structure: This gets copied for platform drivers so that
  983. * individual entries can be overridden as needed.
  984. */
  985. static const struct hc_driver ohci_hc_driver = {
  986. .description = hcd_name,
  987. .product_desc = "OHCI Host Controller",
  988. .hcd_priv_size = sizeof(struct ohci_hcd),
  989. /*
  990. * generic hardware linkage
  991. */
  992. .irq = ohci_irq,
  993. .flags = HCD_MEMORY | HCD_USB11,
  994. /*
  995. * basic lifecycle operations
  996. */
  997. .reset = ohci_setup,
  998. .start = ohci_start,
  999. .stop = ohci_stop,
  1000. .shutdown = ohci_shutdown,
  1001. /*
  1002. * managing i/o requests and associated device resources
  1003. */
  1004. .urb_enqueue = ohci_urb_enqueue,
  1005. .urb_dequeue = ohci_urb_dequeue,
  1006. .endpoint_disable = ohci_endpoint_disable,
  1007. /*
  1008. * scheduling support
  1009. */
  1010. .get_frame_number = ohci_get_frame,
  1011. /*
  1012. * root hub support
  1013. */
  1014. .hub_status_data = ohci_hub_status_data,
  1015. .hub_control = ohci_hub_control,
  1016. #ifdef CONFIG_PM
  1017. .bus_suspend = ohci_bus_suspend,
  1018. .bus_resume = ohci_bus_resume,
  1019. #endif
  1020. .start_port_reset = ohci_start_port_reset,
  1021. };
  1022. void ohci_init_driver(struct hc_driver *drv,
  1023. const struct ohci_driver_overrides *over)
  1024. {
  1025. /* Copy the generic table to drv and then apply the overrides */
  1026. *drv = ohci_hc_driver;
  1027. if (over) {
  1028. drv->product_desc = over->product_desc;
  1029. drv->hcd_priv_size += over->extra_priv_size;
  1030. if (over->reset)
  1031. drv->reset = over->reset;
  1032. }
  1033. }
  1034. EXPORT_SYMBOL_GPL(ohci_init_driver);
  1035. /*-------------------------------------------------------------------------*/
  1036. MODULE_AUTHOR (DRIVER_AUTHOR);
  1037. MODULE_DESCRIPTION(DRIVER_DESC);
  1038. MODULE_LICENSE ("GPL");
  1039. #if defined(CONFIG_ARCH_SA1100) && defined(CONFIG_SA1111)
  1040. #include "ohci-sa1111.c"
  1041. #define SA1111_DRIVER ohci_hcd_sa1111_driver
  1042. #endif
  1043. #ifdef CONFIG_USB_OHCI_HCD_PPC_OF
  1044. #include "ohci-ppc-of.c"
  1045. #define OF_PLATFORM_DRIVER ohci_hcd_ppc_of_driver
  1046. #endif
  1047. #ifdef CONFIG_PPC_PS3
  1048. #include "ohci-ps3.c"
  1049. #define PS3_SYSTEM_BUS_DRIVER ps3_ohci_driver
  1050. #endif
  1051. #ifdef CONFIG_MFD_SM501
  1052. #include "ohci-sm501.c"
  1053. #define SM501_OHCI_DRIVER ohci_hcd_sm501_driver
  1054. #endif
  1055. #ifdef CONFIG_MFD_TC6393XB
  1056. #include "ohci-tmio.c"
  1057. #define TMIO_OHCI_DRIVER ohci_hcd_tmio_driver
  1058. #endif
  1059. static int __init ohci_hcd_mod_init(void)
  1060. {
  1061. int retval = 0;
  1062. if (usb_disabled())
  1063. return -ENODEV;
  1064. printk(KERN_INFO "%s: " DRIVER_DESC "\n", hcd_name);
  1065. pr_debug ("%s: block sizes: ed %zd td %zd\n", hcd_name,
  1066. sizeof (struct ed), sizeof (struct td));
  1067. set_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
  1068. ohci_debug_root = debugfs_create_dir("ohci", usb_debug_root);
  1069. #ifdef PS3_SYSTEM_BUS_DRIVER
  1070. retval = ps3_ohci_driver_register(&PS3_SYSTEM_BUS_DRIVER);
  1071. if (retval < 0)
  1072. goto error_ps3;
  1073. #endif
  1074. #ifdef OF_PLATFORM_DRIVER
  1075. retval = platform_driver_register(&OF_PLATFORM_DRIVER);
  1076. if (retval < 0)
  1077. goto error_of_platform;
  1078. #endif
  1079. #ifdef SA1111_DRIVER
  1080. retval = sa1111_driver_register(&SA1111_DRIVER);
  1081. if (retval < 0)
  1082. goto error_sa1111;
  1083. #endif
  1084. #ifdef SM501_OHCI_DRIVER
  1085. retval = platform_driver_register(&SM501_OHCI_DRIVER);
  1086. if (retval < 0)
  1087. goto error_sm501;
  1088. #endif
  1089. #ifdef TMIO_OHCI_DRIVER
  1090. retval = platform_driver_register(&TMIO_OHCI_DRIVER);
  1091. if (retval < 0)
  1092. goto error_tmio;
  1093. #endif
  1094. return retval;
  1095. /* Error path */
  1096. #ifdef TMIO_OHCI_DRIVER
  1097. platform_driver_unregister(&TMIO_OHCI_DRIVER);
  1098. error_tmio:
  1099. #endif
  1100. #ifdef SM501_OHCI_DRIVER
  1101. platform_driver_unregister(&SM501_OHCI_DRIVER);
  1102. error_sm501:
  1103. #endif
  1104. #ifdef SA1111_DRIVER
  1105. sa1111_driver_unregister(&SA1111_DRIVER);
  1106. error_sa1111:
  1107. #endif
  1108. #ifdef OF_PLATFORM_DRIVER
  1109. platform_driver_unregister(&OF_PLATFORM_DRIVER);
  1110. error_of_platform:
  1111. #endif
  1112. #ifdef PS3_SYSTEM_BUS_DRIVER
  1113. ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
  1114. error_ps3:
  1115. #endif
  1116. debugfs_remove(ohci_debug_root);
  1117. ohci_debug_root = NULL;
  1118. clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
  1119. return retval;
  1120. }
  1121. module_init(ohci_hcd_mod_init);
  1122. static void __exit ohci_hcd_mod_exit(void)
  1123. {
  1124. #ifdef TMIO_OHCI_DRIVER
  1125. platform_driver_unregister(&TMIO_OHCI_DRIVER);
  1126. #endif
  1127. #ifdef SM501_OHCI_DRIVER
  1128. platform_driver_unregister(&SM501_OHCI_DRIVER);
  1129. #endif
  1130. #ifdef SA1111_DRIVER
  1131. sa1111_driver_unregister(&SA1111_DRIVER);
  1132. #endif
  1133. #ifdef OF_PLATFORM_DRIVER
  1134. platform_driver_unregister(&OF_PLATFORM_DRIVER);
  1135. #endif
  1136. #ifdef PS3_SYSTEM_BUS_DRIVER
  1137. ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
  1138. #endif
  1139. debugfs_remove(ohci_debug_root);
  1140. clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
  1141. }
  1142. module_exit(ohci_hcd_mod_exit);