ohci-pxa27x.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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. ohci_hcd_init(hcd_to_ohci(hcd));
  146. retval = usb_add_hcd(hcd, pdev->resource[1].start, SA_INTERRUPT);
  147. if (retval == 0)
  148. return retval;
  149. pxa27x_stop_hc(&pdev->dev);
  150. err3:
  151. iounmap(hcd->regs);
  152. err2:
  153. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  154. err1:
  155. usb_put_hcd(hcd);
  156. return retval;
  157. }
  158. /* may be called without controller electrically present */
  159. /* may be called with controller, bus, and devices active */
  160. /**
  161. * usb_hcd_pxa27x_remove - shutdown processing for pxa27x-based HCDs
  162. * @dev: USB Host Controller being removed
  163. * Context: !in_interrupt()
  164. *
  165. * Reverses the effect of usb_hcd_pxa27x_probe(), first invoking
  166. * the HCD's stop() method. It is always called from a thread
  167. * context, normally "rmmod", "apmd", or something similar.
  168. *
  169. */
  170. void usb_hcd_pxa27x_remove (struct usb_hcd *hcd, struct platform_device *pdev)
  171. {
  172. usb_remove_hcd(hcd);
  173. pxa27x_stop_hc(&pdev->dev);
  174. iounmap(hcd->regs);
  175. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  176. usb_put_hcd(hcd);
  177. }
  178. /*-------------------------------------------------------------------------*/
  179. static int __devinit
  180. ohci_pxa27x_start (struct usb_hcd *hcd)
  181. {
  182. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  183. int ret;
  184. ohci_dbg (ohci, "ohci_pxa27x_start, ohci:%p", ohci);
  185. /* The value of NDP in roothub_a is incorrect on this hardware */
  186. ohci->num_ports = 3;
  187. if ((ret = ohci_init(ohci)) < 0)
  188. return ret;
  189. if ((ret = ohci_run (ohci)) < 0) {
  190. err ("can't start %s", hcd->self.bus_name);
  191. ohci_stop (hcd);
  192. return ret;
  193. }
  194. return 0;
  195. }
  196. /*-------------------------------------------------------------------------*/
  197. static const struct hc_driver ohci_pxa27x_hc_driver = {
  198. .description = hcd_name,
  199. .product_desc = "PXA27x OHCI",
  200. .hcd_priv_size = sizeof(struct ohci_hcd),
  201. /*
  202. * generic hardware linkage
  203. */
  204. .irq = ohci_irq,
  205. .flags = HCD_USB11 | HCD_MEMORY,
  206. /*
  207. * basic lifecycle operations
  208. */
  209. .start = ohci_pxa27x_start,
  210. .stop = ohci_stop,
  211. /*
  212. * managing i/o requests and associated device resources
  213. */
  214. .urb_enqueue = ohci_urb_enqueue,
  215. .urb_dequeue = ohci_urb_dequeue,
  216. .endpoint_disable = ohci_endpoint_disable,
  217. /*
  218. * scheduling support
  219. */
  220. .get_frame_number = ohci_get_frame,
  221. /*
  222. * root hub support
  223. */
  224. .hub_status_data = ohci_hub_status_data,
  225. .hub_control = ohci_hub_control,
  226. #ifdef CONFIG_PM
  227. .bus_suspend = ohci_bus_suspend,
  228. .bus_resume = ohci_bus_resume,
  229. #endif
  230. .start_port_reset = ohci_start_port_reset,
  231. };
  232. /*-------------------------------------------------------------------------*/
  233. static int ohci_hcd_pxa27x_drv_probe(struct platform_device *pdev)
  234. {
  235. pr_debug ("In ohci_hcd_pxa27x_drv_probe");
  236. if (usb_disabled())
  237. return -ENODEV;
  238. return usb_hcd_pxa27x_probe(&ohci_pxa27x_hc_driver, pdev);
  239. }
  240. static int ohci_hcd_pxa27x_drv_remove(struct platform_device *pdev)
  241. {
  242. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  243. usb_hcd_pxa27x_remove(hcd, pdev);
  244. platform_set_drvdata(pdev, NULL);
  245. return 0;
  246. }
  247. #ifdef CONFIG_PM
  248. static int ohci_hcd_pxa27x_drv_suspend(struct platform_device *pdev, pm_message_t state)
  249. {
  250. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  251. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  252. if (time_before(jiffies, ohci->next_statechange))
  253. msleep(5);
  254. ohci->next_statechange = jiffies;
  255. pxa27x_stop_hc(&pdev->dev);
  256. hcd->state = HC_STATE_SUSPENDED;
  257. pdev->dev.power.power_state = PMSG_SUSPEND;
  258. return 0;
  259. }
  260. static int ohci_hcd_pxa27x_drv_resume(struct platform_device *pdev)
  261. {
  262. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  263. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  264. int status;
  265. if (time_before(jiffies, ohci->next_statechange))
  266. msleep(5);
  267. ohci->next_statechange = jiffies;
  268. if ((status = pxa27x_start_hc(&pdev->dev)) < 0)
  269. return status;
  270. pdev->dev.power.power_state = PMSG_ON;
  271. usb_hcd_resume_root_hub(hcd);
  272. return 0;
  273. }
  274. #endif
  275. static struct platform_driver ohci_hcd_pxa27x_driver = {
  276. .probe = ohci_hcd_pxa27x_drv_probe,
  277. .remove = ohci_hcd_pxa27x_drv_remove,
  278. #ifdef CONFIG_PM
  279. .suspend = ohci_hcd_pxa27x_drv_suspend,
  280. .resume = ohci_hcd_pxa27x_drv_resume,
  281. #endif
  282. .driver = {
  283. .name = "pxa27x-ohci",
  284. },
  285. };
  286. static int __init ohci_hcd_pxa27x_init (void)
  287. {
  288. pr_debug (DRIVER_INFO " (pxa27x)");
  289. pr_debug ("block sizes: ed %d td %d\n",
  290. sizeof (struct ed), sizeof (struct td));
  291. return platform_driver_register(&ohci_hcd_pxa27x_driver);
  292. }
  293. static void __exit ohci_hcd_pxa27x_cleanup (void)
  294. {
  295. platform_driver_unregister(&ohci_hcd_pxa27x_driver);
  296. }
  297. module_init (ohci_hcd_pxa27x_init);
  298. module_exit (ohci_hcd_pxa27x_cleanup);