ohci-omap3.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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;
  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. ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32));
  91. if (ret)
  92. goto err_io;
  93. ret = -ENODEV;
  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. device_wakeup_enable(hcd->self.controller);
  117. return 0;
  118. err_add_hcd:
  119. pm_runtime_put_sync(dev);
  120. usb_put_hcd(hcd);
  121. err_io:
  122. iounmap(regs);
  123. return ret;
  124. }
  125. /*
  126. * may be called without controller electrically present
  127. * may be called with controller, bus, and devices active
  128. */
  129. /**
  130. * ohci_hcd_omap3_remove - shutdown processing for OHCI HCDs
  131. * @pdev: USB Host Controller being removed
  132. *
  133. * Reverses the effect of ohci_hcd_omap3_probe(), first invoking
  134. * the HCD's stop() method. It is always called from a thread
  135. * context, normally "rmmod", "apmd", or something similar.
  136. */
  137. static int ohci_hcd_omap3_remove(struct platform_device *pdev)
  138. {
  139. struct device *dev = &pdev->dev;
  140. struct usb_hcd *hcd = dev_get_drvdata(dev);
  141. iounmap(hcd->regs);
  142. usb_remove_hcd(hcd);
  143. pm_runtime_put_sync(dev);
  144. pm_runtime_disable(dev);
  145. usb_put_hcd(hcd);
  146. return 0;
  147. }
  148. static const struct of_device_id omap_ohci_dt_ids[] = {
  149. { .compatible = "ti,ohci-omap3" },
  150. { }
  151. };
  152. MODULE_DEVICE_TABLE(of, omap_ohci_dt_ids);
  153. static struct platform_driver ohci_hcd_omap3_driver = {
  154. .probe = ohci_hcd_omap3_probe,
  155. .remove = ohci_hcd_omap3_remove,
  156. .shutdown = usb_hcd_platform_shutdown,
  157. .driver = {
  158. .name = "ohci-omap3",
  159. .of_match_table = omap_ohci_dt_ids,
  160. },
  161. };
  162. static int __init ohci_omap3_init(void)
  163. {
  164. if (usb_disabled())
  165. return -ENODEV;
  166. pr_info("%s: " DRIVER_DESC "\n", hcd_name);
  167. ohci_init_driver(&ohci_omap3_hc_driver, NULL);
  168. return platform_driver_register(&ohci_hcd_omap3_driver);
  169. }
  170. module_init(ohci_omap3_init);
  171. static void __exit ohci_omap3_cleanup(void)
  172. {
  173. platform_driver_unregister(&ohci_hcd_omap3_driver);
  174. }
  175. module_exit(ohci_omap3_cleanup);
  176. MODULE_DESCRIPTION(DRIVER_DESC);
  177. MODULE_ALIAS("platform:ohci-omap3");
  178. MODULE_AUTHOR("Anand Gadiyar <gadiyar@ti.com>");
  179. MODULE_LICENSE("GPL");