ohci-ep93xx.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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 ep93xx.
  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. * Modified for ep93xx from ohci-pxa27x.c
  20. * by Lennert Buytenhek <buytenh@wantstofly.org> 28-2-2006
  21. * Based on an earlier driver by Ray Lehtiniemi
  22. *
  23. * This file is licenced under the GPL.
  24. */
  25. #include <linux/clk.h>
  26. #include <linux/device.h>
  27. #include <linux/signal.h>
  28. #include <linux/platform_device.h>
  29. #include <asm/mach-types.h>
  30. #include <asm/hardware.h>
  31. static struct clk *usb_host_clock;
  32. static void ep93xx_start_hc(struct device *dev)
  33. {
  34. clk_enable(usb_host_clock);
  35. }
  36. static void ep93xx_stop_hc(struct device *dev)
  37. {
  38. clk_disable(usb_host_clock);
  39. }
  40. static int usb_hcd_ep93xx_probe(const struct hc_driver *driver,
  41. struct platform_device *pdev)
  42. {
  43. int retval;
  44. struct usb_hcd *hcd;
  45. if (pdev->resource[1].flags != IORESOURCE_IRQ) {
  46. pr_debug("resource[1] is not IORESOURCE_IRQ");
  47. return -ENOMEM;
  48. }
  49. hcd = usb_create_hcd(driver, &pdev->dev, "ep93xx");
  50. if (hcd == NULL)
  51. return -ENOMEM;
  52. hcd->rsrc_start = pdev->resource[0].start;
  53. hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
  54. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  55. usb_put_hcd(hcd);
  56. retval = -EBUSY;
  57. goto err1;
  58. }
  59. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  60. if (hcd->regs == NULL) {
  61. pr_debug("ioremap failed");
  62. retval = -ENOMEM;
  63. goto err2;
  64. }
  65. usb_host_clock = clk_get(&pdev->dev, "usb_host");
  66. ep93xx_start_hc(&pdev->dev);
  67. ohci_hcd_init(hcd_to_ohci(hcd));
  68. retval = usb_add_hcd(hcd, pdev->resource[1].start, SA_INTERRUPT);
  69. if (retval == 0)
  70. return retval;
  71. ep93xx_stop_hc(&pdev->dev);
  72. iounmap(hcd->regs);
  73. err2:
  74. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  75. err1:
  76. usb_put_hcd(hcd);
  77. return retval;
  78. }
  79. static void usb_hcd_ep93xx_remove(struct usb_hcd *hcd,
  80. struct platform_device *pdev)
  81. {
  82. usb_remove_hcd(hcd);
  83. ep93xx_stop_hc(&pdev->dev);
  84. clk_put(usb_host_clock);
  85. iounmap(hcd->regs);
  86. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  87. usb_put_hcd(hcd);
  88. }
  89. static int __devinit ohci_ep93xx_start(struct usb_hcd *hcd)
  90. {
  91. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  92. int ret;
  93. if ((ret = ohci_init(ohci)) < 0)
  94. return ret;
  95. if ((ret = ohci_run(ohci)) < 0) {
  96. err("can't start %s", hcd->self.bus_name);
  97. ohci_stop(hcd);
  98. return ret;
  99. }
  100. return 0;
  101. }
  102. static struct hc_driver ohci_ep93xx_hc_driver = {
  103. .description = hcd_name,
  104. .product_desc = "EP93xx OHCI",
  105. .hcd_priv_size = sizeof(struct ohci_hcd),
  106. .irq = ohci_irq,
  107. .flags = HCD_USB11 | HCD_MEMORY,
  108. .start = ohci_ep93xx_start,
  109. .stop = ohci_stop,
  110. .shutdown = ohci_shutdown,
  111. .urb_enqueue = ohci_urb_enqueue,
  112. .urb_dequeue = ohci_urb_dequeue,
  113. .endpoint_disable = ohci_endpoint_disable,
  114. .get_frame_number = ohci_get_frame,
  115. .hub_status_data = ohci_hub_status_data,
  116. .hub_control = ohci_hub_control,
  117. .hub_irq_enable = ohci_rhsc_enable,
  118. #ifdef CONFIG_PM
  119. .bus_suspend = ohci_bus_suspend,
  120. .bus_resume = ohci_bus_resume,
  121. #endif
  122. .start_port_reset = ohci_start_port_reset,
  123. };
  124. extern int usb_disabled(void);
  125. static int ohci_hcd_ep93xx_drv_probe(struct platform_device *pdev)
  126. {
  127. int ret;
  128. ret = -ENODEV;
  129. if (!usb_disabled())
  130. ret = usb_hcd_ep93xx_probe(&ohci_ep93xx_hc_driver, pdev);
  131. return ret;
  132. }
  133. static int ohci_hcd_ep93xx_drv_remove(struct platform_device *pdev)
  134. {
  135. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  136. usb_hcd_ep93xx_remove(hcd, pdev);
  137. return 0;
  138. }
  139. #ifdef CONFIG_PM
  140. static int ohci_hcd_ep93xx_drv_suspend(struct platform_device *pdev, pm_message_t state)
  141. {
  142. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  143. struct ochi_hcd *ohci = hcd_to_ohci(hcd);
  144. if (time_before(jiffies, ohci->next_statechange))
  145. msleep(5);
  146. ohci->next_statechange = jiffies;
  147. ep93xx_stop_hc(&pdev->dev);
  148. hcd->state = HC_STATE_SUSPENDED;
  149. pdev->dev.power.power_state = PMSG_SUSPEND;
  150. return 0;
  151. }
  152. static int ohci_hcd_ep93xx_drv_resume(struct platform_device *pdev)
  153. {
  154. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  155. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  156. int status;
  157. if (time_before(jiffies, ohci->next_statechange))
  158. msleep(5);
  159. ohci->next_statechange = jiffies;
  160. ep93xx_start_hc(&pdev->dev);
  161. pdev->dev.power.power_state = PMSG_ON;
  162. usb_hcd_resume_root_hub(hcd);
  163. return 0;
  164. }
  165. #endif
  166. static struct platform_driver ohci_hcd_ep93xx_driver = {
  167. .probe = ohci_hcd_ep93xx_drv_probe,
  168. .remove = ohci_hcd_ep93xx_drv_remove,
  169. .shutdown = usb_hcd_platform_shutdown,
  170. #ifdef CONFIG_PM
  171. .suspend = ohci_hcd_ep93xx_drv_suspend,
  172. .resume = ohci_hcd_ep93xx_drv_resume,
  173. #endif
  174. .driver = {
  175. .name = "ep93xx-ohci",
  176. },
  177. };
  178. static int __init ohci_hcd_ep93xx_init(void)
  179. {
  180. return platform_driver_register(&ohci_hcd_ep93xx_driver);
  181. }
  182. static void __exit ohci_hcd_ep93xx_cleanup(void)
  183. {
  184. platform_driver_unregister(&ohci_hcd_ep93xx_driver);
  185. }
  186. module_init(ohci_hcd_ep93xx_init);
  187. module_exit(ohci_hcd_ep93xx_cleanup);