ohci-pxa27x.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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 <asm/mach-types.h>
  25. #include <asm/hardware.h>
  26. #include <asm/arch/pxa-regs.h>
  27. #include <asm/arch/ohci.h>
  28. #define PXA_UHC_MAX_PORTNUM 3
  29. #define UHCRHPS(x) __REG2( 0x4C000050, (x)<<2 )
  30. /*
  31. PMM_NPS_MODE -- PMM Non-power switching mode
  32. Ports are powered continuously.
  33. PMM_GLOBAL_MODE -- PMM global switching mode
  34. All ports are powered at the same time.
  35. PMM_PERPORT_MODE -- PMM per port switching mode
  36. Ports are powered individually.
  37. */
  38. static int pxa27x_ohci_select_pmm( int mode )
  39. {
  40. switch ( mode ) {
  41. case PMM_NPS_MODE:
  42. UHCRHDA |= RH_A_NPS;
  43. break;
  44. case PMM_GLOBAL_MODE:
  45. UHCRHDA &= ~(RH_A_NPS & RH_A_PSM);
  46. break;
  47. case PMM_PERPORT_MODE:
  48. UHCRHDA &= ~(RH_A_NPS);
  49. UHCRHDA |= RH_A_PSM;
  50. /* Set port power control mask bits, only 3 ports. */
  51. UHCRHDB |= (0x7<<17);
  52. break;
  53. default:
  54. printk( KERN_ERR
  55. "Invalid mode %d, set to non-power switch mode.\n",
  56. mode );
  57. UHCRHDA |= RH_A_NPS;
  58. }
  59. return 0;
  60. }
  61. extern int usb_disabled(void);
  62. /*-------------------------------------------------------------------------*/
  63. static int pxa27x_start_hc(struct device *dev)
  64. {
  65. int retval = 0;
  66. struct pxaohci_platform_data *inf;
  67. inf = dev->platform_data;
  68. pxa_set_cken(CKEN10_USBHOST, 1);
  69. UHCHR |= UHCHR_FHR;
  70. udelay(11);
  71. UHCHR &= ~UHCHR_FHR;
  72. UHCHR |= UHCHR_FSBIR;
  73. while (UHCHR & UHCHR_FSBIR)
  74. cpu_relax();
  75. if (inf->init)
  76. retval = inf->init(dev);
  77. if (retval < 0)
  78. return retval;
  79. UHCHR &= ~UHCHR_SSE;
  80. UHCHIE = (UHCHIE_UPRIE | UHCHIE_RWIE);
  81. /* Clear any OTG Pin Hold */
  82. if (PSSR & PSSR_OTGPH)
  83. PSSR |= PSSR_OTGPH;
  84. return 0;
  85. }
  86. static void pxa27x_stop_hc(struct device *dev)
  87. {
  88. struct pxaohci_platform_data *inf;
  89. inf = dev->platform_data;
  90. if (inf->exit)
  91. inf->exit(dev);
  92. UHCHR |= UHCHR_FHR;
  93. udelay(11);
  94. UHCHR &= ~UHCHR_FHR;
  95. UHCCOMS |= 1;
  96. udelay(10);
  97. pxa_set_cken(CKEN10_USBHOST, 0);
  98. }
  99. /*-------------------------------------------------------------------------*/
  100. /* configure so an HC device and id are always provided */
  101. /* always called with process context; sleeping is OK */
  102. /**
  103. * usb_hcd_pxa27x_probe - initialize pxa27x-based HCDs
  104. * Context: !in_interrupt()
  105. *
  106. * Allocates basic resources for this USB host controller, and
  107. * then invokes the start() method for the HCD associated with it
  108. * through the hotplug entry's driver_data.
  109. *
  110. */
  111. int usb_hcd_pxa27x_probe (const struct hc_driver *driver, struct platform_device *pdev)
  112. {
  113. int retval;
  114. struct usb_hcd *hcd;
  115. struct pxaohci_platform_data *inf;
  116. inf = pdev->dev.platform_data;
  117. if (!inf)
  118. return -ENODEV;
  119. if (pdev->resource[1].flags != IORESOURCE_IRQ) {
  120. pr_debug ("resource[1] is not IORESOURCE_IRQ");
  121. return -ENOMEM;
  122. }
  123. hcd = usb_create_hcd (driver, &pdev->dev, "pxa27x");
  124. if (!hcd)
  125. return -ENOMEM;
  126. hcd->rsrc_start = pdev->resource[0].start;
  127. hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
  128. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  129. pr_debug("request_mem_region failed");
  130. retval = -EBUSY;
  131. goto err1;
  132. }
  133. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  134. if (!hcd->regs) {
  135. pr_debug("ioremap failed");
  136. retval = -ENOMEM;
  137. goto err2;
  138. }
  139. if ((retval = pxa27x_start_hc(&pdev->dev)) < 0) {
  140. pr_debug("pxa27x_start_hc failed");
  141. goto err3;
  142. }
  143. /* Select Power Management Mode */
  144. pxa27x_ohci_select_pmm(inf->port_mode);
  145. if (inf->power_budget)
  146. hcd->power_budget = inf->power_budget;
  147. ohci_hcd_init(hcd_to_ohci(hcd));
  148. retval = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_DISABLED);
  149. if (retval == 0)
  150. return retval;
  151. pxa27x_stop_hc(&pdev->dev);
  152. err3:
  153. iounmap(hcd->regs);
  154. err2:
  155. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  156. err1:
  157. usb_put_hcd(hcd);
  158. return retval;
  159. }
  160. /* may be called without controller electrically present */
  161. /* may be called with controller, bus, and devices active */
  162. /**
  163. * usb_hcd_pxa27x_remove - shutdown processing for pxa27x-based HCDs
  164. * @dev: USB Host Controller being removed
  165. * Context: !in_interrupt()
  166. *
  167. * Reverses the effect of usb_hcd_pxa27x_probe(), first invoking
  168. * the HCD's stop() method. It is always called from a thread
  169. * context, normally "rmmod", "apmd", or something similar.
  170. *
  171. */
  172. void usb_hcd_pxa27x_remove (struct usb_hcd *hcd, struct platform_device *pdev)
  173. {
  174. usb_remove_hcd(hcd);
  175. pxa27x_stop_hc(&pdev->dev);
  176. iounmap(hcd->regs);
  177. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  178. usb_put_hcd(hcd);
  179. }
  180. /*-------------------------------------------------------------------------*/
  181. static int __devinit
  182. ohci_pxa27x_start (struct usb_hcd *hcd)
  183. {
  184. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  185. int ret;
  186. ohci_dbg (ohci, "ohci_pxa27x_start, ohci:%p", ohci);
  187. /* The value of NDP in roothub_a is incorrect on this hardware */
  188. ohci->num_ports = 3;
  189. if ((ret = ohci_init(ohci)) < 0)
  190. return ret;
  191. if ((ret = ohci_run (ohci)) < 0) {
  192. err ("can't start %s", hcd->self.bus_name);
  193. ohci_stop (hcd);
  194. return ret;
  195. }
  196. return 0;
  197. }
  198. /*-------------------------------------------------------------------------*/
  199. static const struct hc_driver ohci_pxa27x_hc_driver = {
  200. .description = hcd_name,
  201. .product_desc = "PXA27x OHCI",
  202. .hcd_priv_size = sizeof(struct ohci_hcd),
  203. /*
  204. * generic hardware linkage
  205. */
  206. .irq = ohci_irq,
  207. .flags = HCD_USB11 | HCD_MEMORY,
  208. /*
  209. * basic lifecycle operations
  210. */
  211. .start = ohci_pxa27x_start,
  212. .stop = ohci_stop,
  213. .shutdown = ohci_shutdown,
  214. /*
  215. * managing i/o requests and associated device resources
  216. */
  217. .urb_enqueue = ohci_urb_enqueue,
  218. .urb_dequeue = ohci_urb_dequeue,
  219. .endpoint_disable = ohci_endpoint_disable,
  220. /*
  221. * scheduling support
  222. */
  223. .get_frame_number = ohci_get_frame,
  224. /*
  225. * root hub support
  226. */
  227. .hub_status_data = ohci_hub_status_data,
  228. .hub_control = ohci_hub_control,
  229. .hub_irq_enable = ohci_rhsc_enable,
  230. #ifdef CONFIG_PM
  231. .bus_suspend = ohci_bus_suspend,
  232. .bus_resume = ohci_bus_resume,
  233. #endif
  234. .start_port_reset = ohci_start_port_reset,
  235. };
  236. /*-------------------------------------------------------------------------*/
  237. static int ohci_hcd_pxa27x_drv_probe(struct platform_device *pdev)
  238. {
  239. pr_debug ("In ohci_hcd_pxa27x_drv_probe");
  240. if (usb_disabled())
  241. return -ENODEV;
  242. return usb_hcd_pxa27x_probe(&ohci_pxa27x_hc_driver, pdev);
  243. }
  244. static int ohci_hcd_pxa27x_drv_remove(struct platform_device *pdev)
  245. {
  246. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  247. usb_hcd_pxa27x_remove(hcd, pdev);
  248. platform_set_drvdata(pdev, NULL);
  249. return 0;
  250. }
  251. #ifdef CONFIG_PM
  252. static int ohci_hcd_pxa27x_drv_suspend(struct platform_device *pdev, pm_message_t state)
  253. {
  254. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  255. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  256. if (time_before(jiffies, ohci->next_statechange))
  257. msleep(5);
  258. ohci->next_statechange = jiffies;
  259. pxa27x_stop_hc(&pdev->dev);
  260. hcd->state = HC_STATE_SUSPENDED;
  261. pdev->dev.power.power_state = PMSG_SUSPEND;
  262. return 0;
  263. }
  264. static int ohci_hcd_pxa27x_drv_resume(struct platform_device *pdev)
  265. {
  266. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  267. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  268. int status;
  269. if (time_before(jiffies, ohci->next_statechange))
  270. msleep(5);
  271. ohci->next_statechange = jiffies;
  272. if ((status = pxa27x_start_hc(&pdev->dev)) < 0)
  273. return status;
  274. pdev->dev.power.power_state = PMSG_ON;
  275. usb_hcd_resume_root_hub(hcd);
  276. return 0;
  277. }
  278. #endif
  279. static struct platform_driver ohci_hcd_pxa27x_driver = {
  280. .probe = ohci_hcd_pxa27x_drv_probe,
  281. .remove = ohci_hcd_pxa27x_drv_remove,
  282. .shutdown = usb_hcd_platform_shutdown,
  283. #ifdef CONFIG_PM
  284. .suspend = ohci_hcd_pxa27x_drv_suspend,
  285. .resume = ohci_hcd_pxa27x_drv_resume,
  286. #endif
  287. .driver = {
  288. .name = "pxa27x-ohci",
  289. },
  290. };
  291. static int __init ohci_hcd_pxa27x_init (void)
  292. {
  293. pr_debug (DRIVER_INFO " (pxa27x)");
  294. pr_debug ("block sizes: ed %d td %d\n",
  295. sizeof (struct ed), sizeof (struct td));
  296. return platform_driver_register(&ohci_hcd_pxa27x_driver);
  297. }
  298. static void __exit ohci_hcd_pxa27x_cleanup (void)
  299. {
  300. platform_driver_unregister(&ohci_hcd_pxa27x_driver);
  301. }
  302. module_init (ohci_hcd_pxa27x_init);
  303. module_exit (ohci_hcd_pxa27x_cleanup);