ohci-hcd.c 36 KB

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