ohci-ep93xx.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 <mach/hardware.h>
  30. static struct clk *usb_host_clock;
  31. static void ep93xx_start_hc(struct device *dev)
  32. {
  33. clk_enable(usb_host_clock);
  34. }
  35. static void ep93xx_stop_hc(struct device *dev)
  36. {
  37. clk_disable(usb_host_clock);
  38. }
  39. static int usb_hcd_ep93xx_probe(const struct hc_driver *driver,
  40. struct platform_device *pdev)
  41. {
  42. int retval;
  43. struct usb_hcd *hcd;
  44. if (pdev->resource[1].flags != IORESOURCE_IRQ) {
  45. pr_debug("resource[1] is not IORESOURCE_IRQ");
  46. return -ENOMEM;
  47. }
  48. hcd = usb_create_hcd(driver, &pdev->dev, "ep93xx");
  49. if (hcd == NULL)
  50. return -ENOMEM;
  51. hcd->rsrc_start = pdev->resource[0].start;
  52. hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
  53. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  54. usb_put_hcd(hcd);
  55. retval = -EBUSY;
  56. goto err1;
  57. }
  58. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  59. if (hcd->regs == NULL) {
  60. pr_debug("ioremap failed");
  61. retval = -ENOMEM;
  62. goto err2;
  63. }
  64. usb_host_clock = clk_get(&pdev->dev, "usb_host");
  65. ep93xx_start_hc(&pdev->dev);
  66. ohci_hcd_init(hcd_to_ohci(hcd));
  67. retval = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_DISABLED);
  68. if (retval == 0)
  69. return retval;
  70. ep93xx_stop_hc(&pdev->dev);
  71. iounmap(hcd->regs);
  72. err2:
  73. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  74. err1:
  75. usb_put_hcd(hcd);
  76. return retval;
  77. }
  78. static void usb_hcd_ep93xx_remove(struct usb_hcd *hcd,
  79. struct platform_device *pdev)
  80. {
  81. usb_remove_hcd(hcd);
  82. ep93xx_stop_hc(&pdev->dev);
  83. clk_put(usb_host_clock);
  84. iounmap(hcd->regs);
  85. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  86. usb_put_hcd(hcd);
  87. }
  88. static int __devinit ohci_ep93xx_start(struct usb_hcd *hcd)
  89. {
  90. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  91. int ret;
  92. if ((ret = ohci_init(ohci)) < 0)
  93. return ret;
  94. if ((ret = ohci_run(ohci)) < 0) {
  95. err("can't start %s", hcd->self.bus_name);
  96. ohci_stop(hcd);
  97. return ret;
  98. }
  99. return 0;
  100. }
  101. static struct hc_driver ohci_ep93xx_hc_driver = {
  102. .description = hcd_name,
  103. .product_desc = "EP93xx OHCI",
  104. .hcd_priv_size = sizeof(struct ohci_hcd),
  105. .irq = ohci_irq,
  106. .flags = HCD_USB11 | HCD_MEMORY,
  107. .start = ohci_ep93xx_start,
  108. .stop = ohci_stop,
  109. .shutdown = ohci_shutdown,
  110. .urb_enqueue = ohci_urb_enqueue,
  111. .urb_dequeue = ohci_urb_dequeue,
  112. .endpoint_disable = ohci_endpoint_disable,
  113. .get_frame_number = ohci_get_frame,
  114. .hub_status_data = ohci_hub_status_data,
  115. .hub_control = ohci_hub_control,
  116. #ifdef CONFIG_PM
  117. .bus_suspend = ohci_bus_suspend,
  118. .bus_resume = ohci_bus_resume,
  119. #endif
  120. .start_port_reset = ohci_start_port_reset,
  121. };
  122. extern int usb_disabled(void);
  123. static int ohci_hcd_ep93xx_drv_probe(struct platform_device *pdev)
  124. {
  125. int ret;
  126. ret = -ENODEV;
  127. if (!usb_disabled())
  128. ret = usb_hcd_ep93xx_probe(&ohci_ep93xx_hc_driver, pdev);
  129. return ret;
  130. }
  131. static int ohci_hcd_ep93xx_drv_remove(struct platform_device *pdev)
  132. {
  133. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  134. usb_hcd_ep93xx_remove(hcd, pdev);
  135. return 0;
  136. }
  137. #ifdef CONFIG_PM
  138. static int ohci_hcd_ep93xx_drv_suspend(struct platform_device *pdev, pm_message_t state)
  139. {
  140. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  141. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  142. if (time_before(jiffies, ohci->next_statechange))
  143. msleep(5);
  144. ohci->next_statechange = jiffies;
  145. ep93xx_stop_hc(&pdev->dev);
  146. hcd->state = HC_STATE_SUSPENDED;
  147. return 0;
  148. }
  149. static int ohci_hcd_ep93xx_drv_resume(struct platform_device *pdev)
  150. {
  151. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  152. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  153. int status;
  154. if (time_before(jiffies, ohci->next_statechange))
  155. msleep(5);
  156. ohci->next_statechange = jiffies;
  157. ep93xx_start_hc(&pdev->dev);
  158. ohci_finish_controller_resume(hcd);
  159. return 0;
  160. }
  161. #endif
  162. static struct platform_driver ohci_hcd_ep93xx_driver = {
  163. .probe = ohci_hcd_ep93xx_drv_probe,
  164. .remove = ohci_hcd_ep93xx_drv_remove,
  165. .shutdown = usb_hcd_platform_shutdown,
  166. #ifdef CONFIG_PM
  167. .suspend = ohci_hcd_ep93xx_drv_suspend,
  168. .resume = ohci_hcd_ep93xx_drv_resume,
  169. #endif
  170. .driver = {
  171. .name = "ep93xx-ohci",
  172. .owner = THIS_MODULE,
  173. },
  174. };
  175. MODULE_ALIAS("platform:ep93xx-ohci");