ohci-pxa27x.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. /*
  2. * OHCI HCD (Host Controller Driver) for USB.
  3. *
  4. * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
  5. * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
  6. * (C) Copyright 2002 Hewlett-Packard Company
  7. *
  8. * Bus Glue for pxa27x
  9. *
  10. * Written by Christopher Hoover <ch@hpl.hp.com>
  11. * Based on fragments of previous driver by Russell King et al.
  12. *
  13. * Modified for LH7A404 from ohci-sa1111.c
  14. * by Durgesh Pattamatta <pattamattad@sharpsec.com>
  15. *
  16. * Modified for pxa27x from ohci-lh7a404.c
  17. * by Nick Bane <nick@cecomputing.co.uk> 26-8-2004
  18. *
  19. * This file is licenced under the GPL.
  20. */
  21. #include <linux/device.h>
  22. #include <linux/signal.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/clk.h>
  25. #include <mach/hardware.h>
  26. #include <mach/pxa2xx-regs.h> /* FIXME: for PSSR */
  27. #include <mach/ohci.h>
  28. /*
  29. * UHC: USB Host Controller (OHCI-like) register definitions
  30. */
  31. #define UHC_BASE_PHYS (0x4C000000)
  32. #define UHCREV __REG(0x4C000000) /* UHC HCI Spec Revision */
  33. #define UHCHCON __REG(0x4C000004) /* UHC Host Control Register */
  34. #define UHCCOMS __REG(0x4C000008) /* UHC Command Status Register */
  35. #define UHCINTS __REG(0x4C00000C) /* UHC Interrupt Status Register */
  36. #define UHCINTE __REG(0x4C000010) /* UHC Interrupt Enable */
  37. #define UHCINTD __REG(0x4C000014) /* UHC Interrupt Disable */
  38. #define UHCHCCA __REG(0x4C000018) /* UHC Host Controller Comm. Area */
  39. #define UHCPCED __REG(0x4C00001C) /* UHC Period Current Endpt Descr */
  40. #define UHCCHED __REG(0x4C000020) /* UHC Control Head Endpt Descr */
  41. #define UHCCCED __REG(0x4C000024) /* UHC Control Current Endpt Descr */
  42. #define UHCBHED __REG(0x4C000028) /* UHC Bulk Head Endpt Descr */
  43. #define UHCBCED __REG(0x4C00002C) /* UHC Bulk Current Endpt Descr */
  44. #define UHCDHEAD __REG(0x4C000030) /* UHC Done Head */
  45. #define UHCFMI __REG(0x4C000034) /* UHC Frame Interval */
  46. #define UHCFMR __REG(0x4C000038) /* UHC Frame Remaining */
  47. #define UHCFMN __REG(0x4C00003C) /* UHC Frame Number */
  48. #define UHCPERS __REG(0x4C000040) /* UHC Periodic Start */
  49. #define UHCLS __REG(0x4C000044) /* UHC Low Speed Threshold */
  50. #define UHCRHDA __REG(0x4C000048) /* UHC Root Hub Descriptor A */
  51. #define UHCRHDA_NOCP (1 << 12) /* No over current protection */
  52. #define UHCRHDA_OCPM (1 << 11) /* Over Current Protection Mode */
  53. #define UHCRHDA_POTPGT(x) \
  54. (((x) & 0xff) << 24) /* Power On To Power Good Time */
  55. #define UHCRHDB __REG(0x4C00004C) /* UHC Root Hub Descriptor B */
  56. #define UHCRHS __REG(0x4C000050) /* UHC Root Hub Status */
  57. #define UHCRHPS1 __REG(0x4C000054) /* UHC Root Hub Port 1 Status */
  58. #define UHCRHPS2 __REG(0x4C000058) /* UHC Root Hub Port 2 Status */
  59. #define UHCRHPS3 __REG(0x4C00005C) /* UHC Root Hub Port 3 Status */
  60. #define UHCSTAT __REG(0x4C000060) /* UHC Status Register */
  61. #define UHCSTAT_UPS3 (1 << 16) /* USB Power Sense Port3 */
  62. #define UHCSTAT_SBMAI (1 << 15) /* System Bus Master Abort Interrupt*/
  63. #define UHCSTAT_SBTAI (1 << 14) /* System Bus Target Abort Interrupt*/
  64. #define UHCSTAT_UPRI (1 << 13) /* USB Port Resume Interrupt */
  65. #define UHCSTAT_UPS2 (1 << 12) /* USB Power Sense Port 2 */
  66. #define UHCSTAT_UPS1 (1 << 11) /* USB Power Sense Port 1 */
  67. #define UHCSTAT_HTA (1 << 10) /* HCI Target Abort */
  68. #define UHCSTAT_HBA (1 << 8) /* HCI Buffer Active */
  69. #define UHCSTAT_RWUE (1 << 7) /* HCI Remote Wake Up Event */
  70. #define UHCHR __REG(0x4C000064) /* UHC Reset Register */
  71. #define UHCHR_SSEP3 (1 << 11) /* Sleep Standby Enable for Port3 */
  72. #define UHCHR_SSEP2 (1 << 10) /* Sleep Standby Enable for Port2 */
  73. #define UHCHR_SSEP1 (1 << 9) /* Sleep Standby Enable for Port1 */
  74. #define UHCHR_PCPL (1 << 7) /* Power control polarity low */
  75. #define UHCHR_PSPL (1 << 6) /* Power sense polarity low */
  76. #define UHCHR_SSE (1 << 5) /* Sleep Standby Enable */
  77. #define UHCHR_UIT (1 << 4) /* USB Interrupt Test */
  78. #define UHCHR_SSDC (1 << 3) /* Simulation Scale Down Clock */
  79. #define UHCHR_CGR (1 << 2) /* Clock Generation Reset */
  80. #define UHCHR_FHR (1 << 1) /* Force Host Controller Reset */
  81. #define UHCHR_FSBIR (1 << 0) /* Force System Bus Iface Reset */
  82. #define UHCHIE __REG(0x4C000068) /* UHC Interrupt Enable Register*/
  83. #define UHCHIE_UPS3IE (1 << 14) /* Power Sense Port3 IntEn */
  84. #define UHCHIE_UPRIE (1 << 13) /* Port Resume IntEn */
  85. #define UHCHIE_UPS2IE (1 << 12) /* Power Sense Port2 IntEn */
  86. #define UHCHIE_UPS1IE (1 << 11) /* Power Sense Port1 IntEn */
  87. #define UHCHIE_TAIE (1 << 10) /* HCI Interface Transfer Abort
  88. Interrupt Enable*/
  89. #define UHCHIE_HBAIE (1 << 8) /* HCI Buffer Active IntEn */
  90. #define UHCHIE_RWIE (1 << 7) /* Remote Wake-up IntEn */
  91. #define UHCHIT __REG(0x4C00006C) /* UHC Interrupt Test register */
  92. #define PXA_UHC_MAX_PORTNUM 3
  93. #define UHCRHPS(x) __REG2( 0x4C000050, (x)<<2 )
  94. static struct clk *usb_clk;
  95. /*
  96. PMM_NPS_MODE -- PMM Non-power switching mode
  97. Ports are powered continuously.
  98. PMM_GLOBAL_MODE -- PMM global switching mode
  99. All ports are powered at the same time.
  100. PMM_PERPORT_MODE -- PMM per port switching mode
  101. Ports are powered individually.
  102. */
  103. static int pxa27x_ohci_select_pmm( int mode )
  104. {
  105. switch ( mode ) {
  106. case PMM_NPS_MODE:
  107. UHCRHDA |= RH_A_NPS;
  108. break;
  109. case PMM_GLOBAL_MODE:
  110. UHCRHDA &= ~(RH_A_NPS & RH_A_PSM);
  111. break;
  112. case PMM_PERPORT_MODE:
  113. UHCRHDA &= ~(RH_A_NPS);
  114. UHCRHDA |= RH_A_PSM;
  115. /* Set port power control mask bits, only 3 ports. */
  116. UHCRHDB |= (0x7<<17);
  117. break;
  118. default:
  119. printk( KERN_ERR
  120. "Invalid mode %d, set to non-power switch mode.\n",
  121. mode );
  122. UHCRHDA |= RH_A_NPS;
  123. }
  124. return 0;
  125. }
  126. extern int usb_disabled(void);
  127. /*-------------------------------------------------------------------------*/
  128. static inline void pxa27x_setup_hc(struct pxaohci_platform_data *inf)
  129. {
  130. uint32_t uhchr = UHCHR;
  131. uint32_t uhcrhda = UHCRHDA;
  132. if (inf->flags & ENABLE_PORT1)
  133. uhchr &= ~UHCHR_SSEP1;
  134. if (inf->flags & ENABLE_PORT2)
  135. uhchr &= ~UHCHR_SSEP2;
  136. if (inf->flags & ENABLE_PORT3)
  137. uhchr &= ~UHCHR_SSEP3;
  138. if (inf->flags & POWER_CONTROL_LOW)
  139. uhchr |= UHCHR_PCPL;
  140. if (inf->flags & POWER_SENSE_LOW)
  141. uhchr |= UHCHR_PSPL;
  142. if (inf->flags & NO_OC_PROTECTION)
  143. uhcrhda |= UHCRHDA_NOCP;
  144. if (inf->flags & OC_MODE_PERPORT)
  145. uhcrhda |= UHCRHDA_OCPM;
  146. if (inf->power_on_delay) {
  147. uhcrhda &= ~UHCRHDA_POTPGT(0xff);
  148. uhcrhda |= UHCRHDA_POTPGT(inf->power_on_delay / 2);
  149. }
  150. UHCHR = uhchr;
  151. UHCRHDA = uhcrhda;
  152. }
  153. static int pxa27x_start_hc(struct device *dev)
  154. {
  155. int retval = 0;
  156. struct pxaohci_platform_data *inf;
  157. inf = dev->platform_data;
  158. clk_enable(usb_clk);
  159. UHCHR |= UHCHR_FHR;
  160. udelay(11);
  161. UHCHR &= ~UHCHR_FHR;
  162. UHCHR |= UHCHR_FSBIR;
  163. while (UHCHR & UHCHR_FSBIR)
  164. cpu_relax();
  165. pxa27x_setup_hc(inf);
  166. if (inf->init)
  167. retval = inf->init(dev);
  168. if (retval < 0)
  169. return retval;
  170. UHCHR &= ~UHCHR_SSE;
  171. UHCHIE = (UHCHIE_UPRIE | UHCHIE_RWIE);
  172. /* Clear any OTG Pin Hold */
  173. if (cpu_is_pxa27x() && (PSSR & PSSR_OTGPH))
  174. PSSR |= PSSR_OTGPH;
  175. return 0;
  176. }
  177. static void pxa27x_stop_hc(struct device *dev)
  178. {
  179. struct pxaohci_platform_data *inf;
  180. inf = dev->platform_data;
  181. if (inf->exit)
  182. inf->exit(dev);
  183. UHCHR |= UHCHR_FHR;
  184. udelay(11);
  185. UHCHR &= ~UHCHR_FHR;
  186. UHCCOMS |= 1;
  187. udelay(10);
  188. clk_disable(usb_clk);
  189. }
  190. /*-------------------------------------------------------------------------*/
  191. /* configure so an HC device and id are always provided */
  192. /* always called with process context; sleeping is OK */
  193. /**
  194. * usb_hcd_pxa27x_probe - initialize pxa27x-based HCDs
  195. * Context: !in_interrupt()
  196. *
  197. * Allocates basic resources for this USB host controller, and
  198. * then invokes the start() method for the HCD associated with it
  199. * through the hotplug entry's driver_data.
  200. *
  201. */
  202. int usb_hcd_pxa27x_probe (const struct hc_driver *driver, struct platform_device *pdev)
  203. {
  204. int retval, irq;
  205. struct usb_hcd *hcd;
  206. struct pxaohci_platform_data *inf;
  207. struct resource *r;
  208. inf = pdev->dev.platform_data;
  209. if (!inf)
  210. return -ENODEV;
  211. irq = platform_get_irq(pdev, 0);
  212. if (irq < 0) {
  213. pr_err("no resource of IORESOURCE_IRQ");
  214. return -ENXIO;
  215. }
  216. usb_clk = clk_get(&pdev->dev, "USBCLK");
  217. if (IS_ERR(usb_clk))
  218. return PTR_ERR(usb_clk);
  219. hcd = usb_create_hcd (driver, &pdev->dev, "pxa27x");
  220. if (!hcd)
  221. return -ENOMEM;
  222. r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  223. if (!r) {
  224. pr_err("no resource of IORESOURCE_MEM");
  225. retval = -ENXIO;
  226. goto err1;
  227. }
  228. hcd->rsrc_start = r->start;
  229. hcd->rsrc_len = resource_size(r);
  230. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  231. pr_debug("request_mem_region failed");
  232. retval = -EBUSY;
  233. goto err1;
  234. }
  235. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  236. if (!hcd->regs) {
  237. pr_debug("ioremap failed");
  238. retval = -ENOMEM;
  239. goto err2;
  240. }
  241. if ((retval = pxa27x_start_hc(&pdev->dev)) < 0) {
  242. pr_debug("pxa27x_start_hc failed");
  243. goto err3;
  244. }
  245. /* Select Power Management Mode */
  246. pxa27x_ohci_select_pmm(inf->port_mode);
  247. if (inf->power_budget)
  248. hcd->power_budget = inf->power_budget;
  249. ohci_hcd_init(hcd_to_ohci(hcd));
  250. retval = usb_add_hcd(hcd, irq, IRQF_DISABLED);
  251. if (retval == 0)
  252. return retval;
  253. pxa27x_stop_hc(&pdev->dev);
  254. err3:
  255. iounmap(hcd->regs);
  256. err2:
  257. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  258. err1:
  259. usb_put_hcd(hcd);
  260. clk_put(usb_clk);
  261. return retval;
  262. }
  263. /* may be called without controller electrically present */
  264. /* may be called with controller, bus, and devices active */
  265. /**
  266. * usb_hcd_pxa27x_remove - shutdown processing for pxa27x-based HCDs
  267. * @dev: USB Host Controller being removed
  268. * Context: !in_interrupt()
  269. *
  270. * Reverses the effect of usb_hcd_pxa27x_probe(), first invoking
  271. * the HCD's stop() method. It is always called from a thread
  272. * context, normally "rmmod", "apmd", or something similar.
  273. *
  274. */
  275. void usb_hcd_pxa27x_remove (struct usb_hcd *hcd, struct platform_device *pdev)
  276. {
  277. usb_remove_hcd(hcd);
  278. pxa27x_stop_hc(&pdev->dev);
  279. iounmap(hcd->regs);
  280. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  281. usb_put_hcd(hcd);
  282. clk_put(usb_clk);
  283. }
  284. /*-------------------------------------------------------------------------*/
  285. static int __devinit
  286. ohci_pxa27x_start (struct usb_hcd *hcd)
  287. {
  288. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  289. int ret;
  290. ohci_dbg (ohci, "ohci_pxa27x_start, ohci:%p", ohci);
  291. /* The value of NDP in roothub_a is incorrect on this hardware */
  292. ohci->num_ports = 3;
  293. if ((ret = ohci_init(ohci)) < 0)
  294. return ret;
  295. if ((ret = ohci_run (ohci)) < 0) {
  296. err ("can't start %s", hcd->self.bus_name);
  297. ohci_stop (hcd);
  298. return ret;
  299. }
  300. return 0;
  301. }
  302. /*-------------------------------------------------------------------------*/
  303. static const struct hc_driver ohci_pxa27x_hc_driver = {
  304. .description = hcd_name,
  305. .product_desc = "PXA27x OHCI",
  306. .hcd_priv_size = sizeof(struct ohci_hcd),
  307. /*
  308. * generic hardware linkage
  309. */
  310. .irq = ohci_irq,
  311. .flags = HCD_USB11 | HCD_MEMORY,
  312. /*
  313. * basic lifecycle operations
  314. */
  315. .start = ohci_pxa27x_start,
  316. .stop = ohci_stop,
  317. .shutdown = ohci_shutdown,
  318. /*
  319. * managing i/o requests and associated device resources
  320. */
  321. .urb_enqueue = ohci_urb_enqueue,
  322. .urb_dequeue = ohci_urb_dequeue,
  323. .endpoint_disable = ohci_endpoint_disable,
  324. /*
  325. * scheduling support
  326. */
  327. .get_frame_number = ohci_get_frame,
  328. /*
  329. * root hub support
  330. */
  331. .hub_status_data = ohci_hub_status_data,
  332. .hub_control = ohci_hub_control,
  333. #ifdef CONFIG_PM
  334. .bus_suspend = ohci_bus_suspend,
  335. .bus_resume = ohci_bus_resume,
  336. #endif
  337. .start_port_reset = ohci_start_port_reset,
  338. };
  339. /*-------------------------------------------------------------------------*/
  340. static int ohci_hcd_pxa27x_drv_probe(struct platform_device *pdev)
  341. {
  342. pr_debug ("In ohci_hcd_pxa27x_drv_probe");
  343. if (usb_disabled())
  344. return -ENODEV;
  345. return usb_hcd_pxa27x_probe(&ohci_pxa27x_hc_driver, pdev);
  346. }
  347. static int ohci_hcd_pxa27x_drv_remove(struct platform_device *pdev)
  348. {
  349. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  350. usb_hcd_pxa27x_remove(hcd, pdev);
  351. platform_set_drvdata(pdev, NULL);
  352. return 0;
  353. }
  354. #ifdef CONFIG_PM
  355. static int ohci_hcd_pxa27x_drv_suspend(struct platform_device *pdev, pm_message_t state)
  356. {
  357. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  358. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  359. if (time_before(jiffies, ohci->next_statechange))
  360. msleep(5);
  361. ohci->next_statechange = jiffies;
  362. pxa27x_stop_hc(&pdev->dev);
  363. hcd->state = HC_STATE_SUSPENDED;
  364. return 0;
  365. }
  366. static int ohci_hcd_pxa27x_drv_resume(struct platform_device *pdev)
  367. {
  368. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  369. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  370. int status;
  371. if (time_before(jiffies, ohci->next_statechange))
  372. msleep(5);
  373. ohci->next_statechange = jiffies;
  374. if ((status = pxa27x_start_hc(&pdev->dev)) < 0)
  375. return status;
  376. ohci_finish_controller_resume(hcd);
  377. return 0;
  378. }
  379. #endif
  380. /* work with hotplug and coldplug */
  381. MODULE_ALIAS("platform:pxa27x-ohci");
  382. static struct platform_driver ohci_hcd_pxa27x_driver = {
  383. .probe = ohci_hcd_pxa27x_drv_probe,
  384. .remove = ohci_hcd_pxa27x_drv_remove,
  385. .shutdown = usb_hcd_platform_shutdown,
  386. #ifdef CONFIG_PM
  387. .suspend = ohci_hcd_pxa27x_drv_suspend,
  388. .resume = ohci_hcd_pxa27x_drv_resume,
  389. #endif
  390. .driver = {
  391. .name = "pxa27x-ohci",
  392. .owner = THIS_MODULE,
  393. },
  394. };