ohci-omap3.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. * ohci-omap3.c - driver for OHCI on OMAP3 and later processors
  3. *
  4. * Bus Glue for OMAP3 USBHOST 3 port OHCI controller
  5. * This controller is also used in later OMAPs and AM35x chips
  6. *
  7. * Copyright (C) 2007-2010 Texas Instruments, Inc.
  8. * Author: Vikram Pandita <vikram.pandita@ti.com>
  9. * Author: Anand Gadiyar <gadiyar@ti.com>
  10. * Author: Keshava Munegowda <keshava_mgowda@ti.com>
  11. *
  12. * Based on ehci-omap.c and some other ohci glue layers
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  27. *
  28. * TODO (last updated Feb 27, 2011):
  29. * - add kernel-doc
  30. */
  31. #include <linux/platform_device.h>
  32. #include <plat/usb.h>
  33. #include <linux/pm_runtime.h>
  34. /*-------------------------------------------------------------------------*/
  35. static int ohci_omap3_init(struct usb_hcd *hcd)
  36. {
  37. dev_dbg(hcd->self.controller, "starting OHCI controller\n");
  38. return ohci_init(hcd_to_ohci(hcd));
  39. }
  40. /*-------------------------------------------------------------------------*/
  41. static int ohci_omap3_start(struct usb_hcd *hcd)
  42. {
  43. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  44. int ret;
  45. /*
  46. * RemoteWakeupConnected has to be set explicitly before
  47. * calling ohci_run. The reset value of RWC is 0.
  48. */
  49. ohci->hc_control = OHCI_CTRL_RWC;
  50. writel(OHCI_CTRL_RWC, &ohci->regs->control);
  51. ret = ohci_run(ohci);
  52. if (ret < 0) {
  53. dev_err(hcd->self.controller, "can't start\n");
  54. ohci_stop(hcd);
  55. }
  56. return ret;
  57. }
  58. /*-------------------------------------------------------------------------*/
  59. static const struct hc_driver ohci_omap3_hc_driver = {
  60. .description = hcd_name,
  61. .product_desc = "OMAP3 OHCI Host Controller",
  62. .hcd_priv_size = sizeof(struct ohci_hcd),
  63. /*
  64. * generic hardware linkage
  65. */
  66. .irq = ohci_irq,
  67. .flags = HCD_USB11 | HCD_MEMORY,
  68. /*
  69. * basic lifecycle operations
  70. */
  71. .reset = ohci_omap3_init,
  72. .start = ohci_omap3_start,
  73. .stop = ohci_stop,
  74. .shutdown = ohci_shutdown,
  75. /*
  76. * managing i/o requests and associated device resources
  77. */
  78. .urb_enqueue = ohci_urb_enqueue,
  79. .urb_dequeue = ohci_urb_dequeue,
  80. .endpoint_disable = ohci_endpoint_disable,
  81. /*
  82. * scheduling support
  83. */
  84. .get_frame_number = ohci_get_frame,
  85. /*
  86. * root hub support
  87. */
  88. .hub_status_data = ohci_hub_status_data,
  89. .hub_control = ohci_hub_control,
  90. #ifdef CONFIG_PM
  91. .bus_suspend = ohci_bus_suspend,
  92. .bus_resume = ohci_bus_resume,
  93. #endif
  94. .start_port_reset = ohci_start_port_reset,
  95. };
  96. /*-------------------------------------------------------------------------*/
  97. /*
  98. * configure so an HC device and id are always provided
  99. * always called with process context; sleeping is OK
  100. */
  101. /**
  102. * ohci_hcd_omap3_probe - initialize OMAP-based HCDs
  103. *
  104. * Allocates basic resources for this USB host controller, and
  105. * then invokes the start() method for the HCD associated with it
  106. * through the hotplug entry's driver_data.
  107. */
  108. static int __devinit ohci_hcd_omap3_probe(struct platform_device *pdev)
  109. {
  110. struct device *dev = &pdev->dev;
  111. struct usb_hcd *hcd = NULL;
  112. void __iomem *regs = NULL;
  113. struct resource *res;
  114. int ret = -ENODEV;
  115. int irq;
  116. if (usb_disabled())
  117. return -ENODEV;
  118. if (!dev->parent) {
  119. dev_err(dev, "Missing parent device\n");
  120. return -ENODEV;
  121. }
  122. irq = platform_get_irq_byname(pdev, "ohci-irq");
  123. if (irq < 0) {
  124. dev_err(dev, "OHCI irq failed\n");
  125. return -ENODEV;
  126. }
  127. res = platform_get_resource_byname(pdev,
  128. IORESOURCE_MEM, "ohci");
  129. if (!res) {
  130. dev_err(dev, "UHH OHCI get resource failed\n");
  131. return -ENOMEM;
  132. }
  133. regs = ioremap(res->start, resource_size(res));
  134. if (!regs) {
  135. dev_err(dev, "UHH OHCI ioremap failed\n");
  136. return -ENOMEM;
  137. }
  138. hcd = usb_create_hcd(&ohci_omap3_hc_driver, dev,
  139. dev_name(dev));
  140. if (!hcd) {
  141. dev_err(dev, "usb_create_hcd failed\n");
  142. goto err_io;
  143. }
  144. hcd->rsrc_start = res->start;
  145. hcd->rsrc_len = resource_size(res);
  146. hcd->regs = regs;
  147. pm_runtime_enable(dev);
  148. pm_runtime_get_sync(dev);
  149. ohci_hcd_init(hcd_to_ohci(hcd));
  150. ret = usb_add_hcd(hcd, irq, 0);
  151. if (ret) {
  152. dev_dbg(dev, "failed to add hcd with err %d\n", ret);
  153. goto err_add_hcd;
  154. }
  155. return 0;
  156. err_add_hcd:
  157. pm_runtime_put_sync(dev);
  158. usb_put_hcd(hcd);
  159. err_io:
  160. iounmap(regs);
  161. return ret;
  162. }
  163. /*
  164. * may be called without controller electrically present
  165. * may be called with controller, bus, and devices active
  166. */
  167. /**
  168. * ohci_hcd_omap3_remove - shutdown processing for OHCI HCDs
  169. * @pdev: USB Host Controller being removed
  170. *
  171. * Reverses the effect of ohci_hcd_omap3_probe(), first invoking
  172. * the HCD's stop() method. It is always called from a thread
  173. * context, normally "rmmod", "apmd", or something similar.
  174. */
  175. static int __devexit ohci_hcd_omap3_remove(struct platform_device *pdev)
  176. {
  177. struct device *dev = &pdev->dev;
  178. struct usb_hcd *hcd = dev_get_drvdata(dev);
  179. iounmap(hcd->regs);
  180. usb_remove_hcd(hcd);
  181. pm_runtime_put_sync(dev);
  182. pm_runtime_disable(dev);
  183. usb_put_hcd(hcd);
  184. return 0;
  185. }
  186. static void ohci_hcd_omap3_shutdown(struct platform_device *pdev)
  187. {
  188. struct usb_hcd *hcd = dev_get_drvdata(&pdev->dev);
  189. if (hcd->driver->shutdown)
  190. hcd->driver->shutdown(hcd);
  191. }
  192. static struct platform_driver ohci_hcd_omap3_driver = {
  193. .probe = ohci_hcd_omap3_probe,
  194. .remove = __devexit_p(ohci_hcd_omap3_remove),
  195. .shutdown = ohci_hcd_omap3_shutdown,
  196. .driver = {
  197. .name = "ohci-omap3",
  198. },
  199. };
  200. MODULE_ALIAS("platform:ohci-omap3");
  201. MODULE_AUTHOR("Anand Gadiyar <gadiyar@ti.com>");