ohci-hcd.c 39 KB

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