ehci-msm.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /* ehci-msm.c - HSUSB Host Controller Driver Implementation
  2. *
  3. * Copyright (c) 2008-2011, Code Aurora Forum. All rights reserved.
  4. *
  5. * Partly derived from ehci-fsl.c and ehci-hcd.c
  6. * Copyright (c) 2000-2004 by David Brownell
  7. * Copyright (c) 2005 MontaVista Software
  8. *
  9. * All source code in this file is licensed under the following license except
  10. * where indicated.
  11. *
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License version 2 as published
  14. * by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  19. *
  20. * See the GNU General Public License for more details.
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, you can find it at http://www.fsf.org
  23. */
  24. #include <linux/platform_device.h>
  25. #include <linux/clk.h>
  26. #include <linux/err.h>
  27. #include <linux/pm_runtime.h>
  28. #include <linux/usb/otg.h>
  29. #include <linux/usb/msm_hsusb_hw.h>
  30. #define MSM_USB_BASE (hcd->regs)
  31. static struct otg_transceiver *otg;
  32. static int ehci_msm_reset(struct usb_hcd *hcd)
  33. {
  34. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  35. int retval;
  36. ehci->caps = USB_CAPLENGTH;
  37. hcd->has_tt = 1;
  38. retval = ehci_setup(hcd);
  39. if (retval)
  40. return retval;
  41. /* bursts of unspecified length. */
  42. writel(0, USB_AHBBURST);
  43. /* Use the AHB transactor */
  44. writel(0, USB_AHBMODE);
  45. /* Disable streaming mode and select host mode */
  46. writel(0x13, USB_USBMODE);
  47. ehci_port_power(ehci, 1);
  48. return 0;
  49. }
  50. static struct hc_driver msm_hc_driver = {
  51. .description = hcd_name,
  52. .product_desc = "Qualcomm On-Chip EHCI Host Controller",
  53. .hcd_priv_size = sizeof(struct ehci_hcd),
  54. /*
  55. * generic hardware linkage
  56. */
  57. .irq = ehci_irq,
  58. .flags = HCD_USB2 | HCD_MEMORY,
  59. .reset = ehci_msm_reset,
  60. .start = ehci_run,
  61. .stop = ehci_stop,
  62. .shutdown = ehci_shutdown,
  63. /*
  64. * managing i/o requests and associated device resources
  65. */
  66. .urb_enqueue = ehci_urb_enqueue,
  67. .urb_dequeue = ehci_urb_dequeue,
  68. .endpoint_disable = ehci_endpoint_disable,
  69. .endpoint_reset = ehci_endpoint_reset,
  70. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  71. /*
  72. * scheduling support
  73. */
  74. .get_frame_number = ehci_get_frame,
  75. /*
  76. * root hub support
  77. */
  78. .hub_status_data = ehci_hub_status_data,
  79. .hub_control = ehci_hub_control,
  80. .relinquish_port = ehci_relinquish_port,
  81. .port_handed_over = ehci_port_handed_over,
  82. /*
  83. * PM support
  84. */
  85. .bus_suspend = ehci_bus_suspend,
  86. .bus_resume = ehci_bus_resume,
  87. };
  88. static int ehci_msm_probe(struct platform_device *pdev)
  89. {
  90. struct usb_hcd *hcd;
  91. struct resource *res;
  92. int ret;
  93. dev_dbg(&pdev->dev, "ehci_msm proble\n");
  94. hcd = usb_create_hcd(&msm_hc_driver, &pdev->dev, dev_name(&pdev->dev));
  95. if (!hcd) {
  96. dev_err(&pdev->dev, "Unable to create HCD\n");
  97. return -ENOMEM;
  98. }
  99. hcd->irq = platform_get_irq(pdev, 0);
  100. if (hcd->irq < 0) {
  101. dev_err(&pdev->dev, "Unable to get IRQ resource\n");
  102. ret = hcd->irq;
  103. goto put_hcd;
  104. }
  105. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  106. if (!res) {
  107. dev_err(&pdev->dev, "Unable to get memory resource\n");
  108. ret = -ENODEV;
  109. goto put_hcd;
  110. }
  111. hcd->rsrc_start = res->start;
  112. hcd->rsrc_len = resource_size(res);
  113. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  114. if (!hcd->regs) {
  115. dev_err(&pdev->dev, "ioremap failed\n");
  116. ret = -ENOMEM;
  117. goto put_hcd;
  118. }
  119. /*
  120. * OTG driver takes care of PHY initialization, clock management,
  121. * powering up VBUS, mapping of registers address space and power
  122. * management.
  123. */
  124. otg = otg_get_transceiver();
  125. if (!otg) {
  126. dev_err(&pdev->dev, "unable to find transceiver\n");
  127. ret = -ENODEV;
  128. goto unmap;
  129. }
  130. ret = otg_set_host(otg, &hcd->self);
  131. if (ret < 0) {
  132. dev_err(&pdev->dev, "unable to register with transceiver\n");
  133. goto put_transceiver;
  134. }
  135. device_init_wakeup(&pdev->dev, 1);
  136. /*
  137. * OTG device parent of HCD takes care of putting
  138. * hardware into low power mode.
  139. */
  140. pm_runtime_no_callbacks(&pdev->dev);
  141. pm_runtime_enable(&pdev->dev);
  142. return 0;
  143. put_transceiver:
  144. otg_put_transceiver(otg);
  145. unmap:
  146. iounmap(hcd->regs);
  147. put_hcd:
  148. usb_put_hcd(hcd);
  149. return ret;
  150. }
  151. static int __devexit ehci_msm_remove(struct platform_device *pdev)
  152. {
  153. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  154. device_init_wakeup(&pdev->dev, 0);
  155. pm_runtime_disable(&pdev->dev);
  156. pm_runtime_set_suspended(&pdev->dev);
  157. otg_set_host(otg, NULL);
  158. otg_put_transceiver(otg);
  159. usb_put_hcd(hcd);
  160. return 0;
  161. }
  162. #ifdef CONFIG_PM
  163. static int ehci_msm_pm_suspend(struct device *dev)
  164. {
  165. struct usb_hcd *hcd = dev_get_drvdata(dev);
  166. bool wakeup = device_may_wakeup(dev);
  167. dev_dbg(dev, "ehci-msm PM suspend\n");
  168. /*
  169. * EHCI helper function has also the same check before manipulating
  170. * port wakeup flags. We do check here the same condition before
  171. * calling the same helper function to avoid bringing hardware
  172. * from Low power mode when there is no need for adjusting port
  173. * wakeup flags.
  174. */
  175. if (hcd->self.root_hub->do_remote_wakeup && !wakeup) {
  176. pm_runtime_resume(dev);
  177. ehci_prepare_ports_for_controller_suspend(hcd_to_ehci(hcd),
  178. wakeup);
  179. }
  180. return 0;
  181. }
  182. static int ehci_msm_pm_resume(struct device *dev)
  183. {
  184. struct usb_hcd *hcd = dev_get_drvdata(dev);
  185. dev_dbg(dev, "ehci-msm PM resume\n");
  186. ehci_prepare_ports_for_controller_resume(hcd_to_ehci(hcd));
  187. return 0;
  188. }
  189. #else
  190. #define ehci_msm_pm_suspend NULL
  191. #define ehci_msm_pm_resume NULL
  192. #endif
  193. static const struct dev_pm_ops ehci_msm_dev_pm_ops = {
  194. .suspend = ehci_msm_pm_suspend,
  195. .resume = ehci_msm_pm_resume,
  196. };
  197. static struct platform_driver ehci_msm_driver = {
  198. .probe = ehci_msm_probe,
  199. .remove = __devexit_p(ehci_msm_remove),
  200. .driver = {
  201. .name = "msm_hsusb_host",
  202. .pm = &ehci_msm_dev_pm_ops,
  203. },
  204. };