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