ohci-hcd.c 38 KB

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