ohci-hcd.c 40 KB

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