ohci-omap3.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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 <linux/pm_runtime.h>
  33. #include <linux/of.h>
  34. #include <linux/dma-mapping.h>
  35. /*-------------------------------------------------------------------------*/
  36. static int ohci_omap3_init(struct usb_hcd *hcd)
  37. {
  38. dev_dbg(hcd->self.controller, "starting OHCI controller\n");
  39. return ohci_init(hcd_to_ohci(hcd));
  40. }
  41. /*-------------------------------------------------------------------------*/
  42. static int ohci_omap3_start(struct usb_hcd *hcd)
  43. {
  44. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  45. int ret;
  46. /*
  47. * RemoteWakeupConnected has to be set explicitly before
  48. * calling ohci_run. The reset value of RWC is 0.
  49. */
  50. ohci->hc_control = OHCI_CTRL_RWC;
  51. writel(OHCI_CTRL_RWC, &ohci->regs->control);
  52. ret = ohci_run(ohci);
  53. if (ret < 0) {
  54. dev_err(hcd->self.controller, "can't start\n");
  55. ohci_stop(hcd);
  56. }
  57. return ret;
  58. }
  59. /*-------------------------------------------------------------------------*/
  60. static const struct hc_driver ohci_omap3_hc_driver = {
  61. .description = hcd_name,
  62. .product_desc = "OMAP3 OHCI Host Controller",
  63. .hcd_priv_size = sizeof(struct ohci_hcd),
  64. /*
  65. * generic hardware linkage
  66. */
  67. .irq = ohci_irq,
  68. .flags = HCD_USB11 | HCD_MEMORY,
  69. /*
  70. * basic lifecycle operations
  71. */
  72. .reset = ohci_omap3_init,
  73. .start = ohci_omap3_start,
  74. .stop = ohci_stop,
  75. .shutdown = ohci_shutdown,
  76. /*
  77. * managing i/o requests and associated device resources
  78. */
  79. .urb_enqueue = ohci_urb_enqueue,
  80. .urb_dequeue = ohci_urb_dequeue,
  81. .endpoint_disable = ohci_endpoint_disable,
  82. /*
  83. * scheduling support
  84. */
  85. .get_frame_number = ohci_get_frame,
  86. /*
  87. * root hub support
  88. */
  89. .hub_status_data = ohci_hub_status_data,
  90. .hub_control = ohci_hub_control,
  91. #ifdef CONFIG_PM
  92. .bus_suspend = ohci_bus_suspend,
  93. .bus_resume = ohci_bus_resume,
  94. #endif
  95. .start_port_reset = ohci_start_port_reset,
  96. };
  97. /*-------------------------------------------------------------------------*/
  98. /*
  99. * configure so an HC device and id are always provided
  100. * always called with process context; sleeping is OK
  101. */
  102. /**
  103. * ohci_hcd_omap3_probe - initialize OMAP-based HCDs
  104. *
  105. * Allocates basic resources for this USB host controller, and
  106. * then invokes the start() method for the HCD associated with it
  107. * through the hotplug entry's driver_data.
  108. */
  109. static int ohci_hcd_omap3_probe(struct platform_device *pdev)
  110. {
  111. struct device *dev = &pdev->dev;
  112. struct usb_hcd *hcd = NULL;
  113. void __iomem *regs = NULL;
  114. struct resource *res;
  115. int ret = -ENODEV;
  116. int irq;
  117. if (usb_disabled())
  118. return -ENODEV;
  119. if (!dev->parent) {
  120. dev_err(dev, "Missing parent device\n");
  121. return -ENODEV;
  122. }
  123. irq = platform_get_irq(pdev, 0);
  124. if (irq < 0) {
  125. dev_err(dev, "OHCI irq failed\n");
  126. return -ENODEV;
  127. }
  128. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  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. /*
  139. * Right now device-tree probed devices don't get dma_mask set.
  140. * Since shared usb code relies on it, set it here for now.
  141. * Once we have dma capability bindings this can go away.
  142. */
  143. if (!dev->dma_mask)
  144. dev->dma_mask = &dev->coherent_dma_mask;
  145. if (!dev->coherent_dma_mask)
  146. dev->coherent_dma_mask = DMA_BIT_MASK(32);
  147. hcd = usb_create_hcd(&ohci_omap3_hc_driver, dev,
  148. dev_name(dev));
  149. if (!hcd) {
  150. dev_err(dev, "usb_create_hcd failed\n");
  151. goto err_io;
  152. }
  153. hcd->rsrc_start = res->start;
  154. hcd->rsrc_len = resource_size(res);
  155. hcd->regs = regs;
  156. pm_runtime_enable(dev);
  157. pm_runtime_get_sync(dev);
  158. ohci_hcd_init(hcd_to_ohci(hcd));
  159. ret = usb_add_hcd(hcd, irq, 0);
  160. if (ret) {
  161. dev_dbg(dev, "failed to add hcd with err %d\n", ret);
  162. goto err_add_hcd;
  163. }
  164. return 0;
  165. err_add_hcd:
  166. pm_runtime_put_sync(dev);
  167. usb_put_hcd(hcd);
  168. err_io:
  169. iounmap(regs);
  170. return ret;
  171. }
  172. /*
  173. * may be called without controller electrically present
  174. * may be called with controller, bus, and devices active
  175. */
  176. /**
  177. * ohci_hcd_omap3_remove - shutdown processing for OHCI HCDs
  178. * @pdev: USB Host Controller being removed
  179. *
  180. * Reverses the effect of ohci_hcd_omap3_probe(), first invoking
  181. * the HCD's stop() method. It is always called from a thread
  182. * context, normally "rmmod", "apmd", or something similar.
  183. */
  184. static int ohci_hcd_omap3_remove(struct platform_device *pdev)
  185. {
  186. struct device *dev = &pdev->dev;
  187. struct usb_hcd *hcd = dev_get_drvdata(dev);
  188. iounmap(hcd->regs);
  189. usb_remove_hcd(hcd);
  190. pm_runtime_put_sync(dev);
  191. pm_runtime_disable(dev);
  192. usb_put_hcd(hcd);
  193. return 0;
  194. }
  195. static void ohci_hcd_omap3_shutdown(struct platform_device *pdev)
  196. {
  197. struct usb_hcd *hcd = dev_get_drvdata(&pdev->dev);
  198. if (hcd->driver->shutdown)
  199. hcd->driver->shutdown(hcd);
  200. }
  201. static const struct of_device_id omap_ohci_dt_ids[] = {
  202. { .compatible = "ti,ohci-omap3" },
  203. { }
  204. };
  205. MODULE_DEVICE_TABLE(of, omap_ohci_dt_ids);
  206. static struct platform_driver ohci_hcd_omap3_driver = {
  207. .probe = ohci_hcd_omap3_probe,
  208. .remove = ohci_hcd_omap3_remove,
  209. .shutdown = ohci_hcd_omap3_shutdown,
  210. .driver = {
  211. .name = "ohci-omap3",
  212. .of_match_table = omap_ohci_dt_ids,
  213. },
  214. };
  215. MODULE_ALIAS("platform:ohci-omap3");
  216. MODULE_AUTHOR("Anand Gadiyar <gadiyar@ti.com>");