ohci-omap3.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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/dma-mapping.h>
  32. #include <linux/kernel.h>
  33. #include <linux/module.h>
  34. #include <linux/of.h>
  35. #include <linux/usb/otg.h>
  36. #include <linux/platform_device.h>
  37. #include <linux/pm_runtime.h>
  38. #include <linux/usb.h>
  39. #include <linux/usb/hcd.h>
  40. #include "ohci.h"
  41. #define DRIVER_DESC "OHCI OMAP3 driver"
  42. static const char hcd_name[] = "ohci-omap3";
  43. static struct hc_driver __read_mostly ohci_omap3_hc_driver;
  44. /*
  45. * configure so an HC device and id are always provided
  46. * always called with process context; sleeping is OK
  47. */
  48. /**
  49. * ohci_hcd_omap3_probe - initialize OMAP-based HCDs
  50. *
  51. * Allocates basic resources for this USB host controller, and
  52. * then invokes the start() method for the HCD associated with it
  53. * through the hotplug entry's driver_data.
  54. */
  55. static int ohci_hcd_omap3_probe(struct platform_device *pdev)
  56. {
  57. struct device *dev = &pdev->dev;
  58. struct ohci_hcd *ohci;
  59. struct usb_hcd *hcd = NULL;
  60. void __iomem *regs = NULL;
  61. struct resource *res;
  62. int ret = -ENODEV;
  63. int irq;
  64. if (usb_disabled())
  65. return -ENODEV;
  66. if (!dev->parent) {
  67. dev_err(dev, "Missing parent device\n");
  68. return -ENODEV;
  69. }
  70. irq = platform_get_irq(pdev, 0);
  71. if (irq < 0) {
  72. dev_err(dev, "OHCI irq failed\n");
  73. return -ENODEV;
  74. }
  75. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  76. if (!res) {
  77. dev_err(dev, "UHH OHCI get resource failed\n");
  78. return -ENOMEM;
  79. }
  80. regs = ioremap(res->start, resource_size(res));
  81. if (!regs) {
  82. dev_err(dev, "UHH OHCI ioremap failed\n");
  83. return -ENOMEM;
  84. }
  85. /*
  86. * Right now device-tree probed devices don't get dma_mask set.
  87. * Since shared usb code relies on it, set it here for now.
  88. * Once we have dma capability bindings this can go away.
  89. */
  90. if (!dev->dma_mask)
  91. dev->dma_mask = &dev->coherent_dma_mask;
  92. if (!dev->coherent_dma_mask)
  93. dev->coherent_dma_mask = DMA_BIT_MASK(32);
  94. hcd = usb_create_hcd(&ohci_omap3_hc_driver, dev,
  95. dev_name(dev));
  96. if (!hcd) {
  97. dev_err(dev, "usb_create_hcd failed\n");
  98. goto err_io;
  99. }
  100. hcd->rsrc_start = res->start;
  101. hcd->rsrc_len = resource_size(res);
  102. hcd->regs = regs;
  103. pm_runtime_enable(dev);
  104. pm_runtime_get_sync(dev);
  105. ohci = hcd_to_ohci(hcd);
  106. /*
  107. * RemoteWakeupConnected has to be set explicitly before
  108. * calling ohci_run. The reset value of RWC is 0.
  109. */
  110. ohci->hc_control = OHCI_CTRL_RWC;
  111. ret = usb_add_hcd(hcd, irq, 0);
  112. if (ret) {
  113. dev_dbg(dev, "failed to add hcd with err %d\n", ret);
  114. goto err_add_hcd;
  115. }
  116. return 0;
  117. err_add_hcd:
  118. pm_runtime_put_sync(dev);
  119. usb_put_hcd(hcd);
  120. err_io:
  121. iounmap(regs);
  122. return ret;
  123. }
  124. /*
  125. * may be called without controller electrically present
  126. * may be called with controller, bus, and devices active
  127. */
  128. /**
  129. * ohci_hcd_omap3_remove - shutdown processing for OHCI HCDs
  130. * @pdev: USB Host Controller being removed
  131. *
  132. * Reverses the effect of ohci_hcd_omap3_probe(), first invoking
  133. * the HCD's stop() method. It is always called from a thread
  134. * context, normally "rmmod", "apmd", or something similar.
  135. */
  136. static int ohci_hcd_omap3_remove(struct platform_device *pdev)
  137. {
  138. struct device *dev = &pdev->dev;
  139. struct usb_hcd *hcd = dev_get_drvdata(dev);
  140. iounmap(hcd->regs);
  141. usb_remove_hcd(hcd);
  142. pm_runtime_put_sync(dev);
  143. pm_runtime_disable(dev);
  144. usb_put_hcd(hcd);
  145. return 0;
  146. }
  147. static const struct of_device_id omap_ohci_dt_ids[] = {
  148. { .compatible = "ti,ohci-omap3" },
  149. { }
  150. };
  151. MODULE_DEVICE_TABLE(of, omap_ohci_dt_ids);
  152. static struct platform_driver ohci_hcd_omap3_driver = {
  153. .probe = ohci_hcd_omap3_probe,
  154. .remove = ohci_hcd_omap3_remove,
  155. .shutdown = usb_hcd_platform_shutdown,
  156. .driver = {
  157. .name = "ohci-omap3",
  158. .of_match_table = omap_ohci_dt_ids,
  159. },
  160. };
  161. static int __init ohci_omap3_init(void)
  162. {
  163. if (usb_disabled())
  164. return -ENODEV;
  165. pr_info("%s: " DRIVER_DESC "\n", hcd_name);
  166. ohci_init_driver(&ohci_omap3_hc_driver, NULL);
  167. return platform_driver_register(&ohci_hcd_omap3_driver);
  168. }
  169. module_init(ohci_omap3_init);
  170. static void __exit ohci_omap3_cleanup(void)
  171. {
  172. platform_driver_unregister(&ohci_hcd_omap3_driver);
  173. }
  174. module_exit(ohci_omap3_cleanup);
  175. MODULE_DESCRIPTION(DRIVER_DESC);
  176. MODULE_ALIAS("platform:ohci-omap3");
  177. MODULE_AUTHOR("Anand Gadiyar <gadiyar@ti.com>");
  178. MODULE_LICENSE("GPL");