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