ohci-pxa27x.c 8.4 KB

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