ohci-hcd.c 36 KB

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