ohci-hcd.c 36 KB

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