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