ohci-omap3.c 5.9 KB

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