ohci-ep93xx.c 4.6 KB

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