ehci-msm.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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 usb_phy *phy;
  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. return 0;
  48. }
  49. static struct hc_driver msm_hc_driver = {
  50. .description = hcd_name,
  51. .product_desc = "Qualcomm On-Chip EHCI Host Controller",
  52. .hcd_priv_size = sizeof(struct ehci_hcd),
  53. /*
  54. * generic hardware linkage
  55. */
  56. .irq = ehci_irq,
  57. .flags = HCD_USB2 | HCD_MEMORY,
  58. .reset = ehci_msm_reset,
  59. .start = ehci_run,
  60. .stop = ehci_stop,
  61. .shutdown = ehci_shutdown,
  62. /*
  63. * managing i/o requests and associated device resources
  64. */
  65. .urb_enqueue = ehci_urb_enqueue,
  66. .urb_dequeue = ehci_urb_dequeue,
  67. .endpoint_disable = ehci_endpoint_disable,
  68. .endpoint_reset = ehci_endpoint_reset,
  69. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  70. /*
  71. * scheduling support
  72. */
  73. .get_frame_number = ehci_get_frame,
  74. /*
  75. * root hub support
  76. */
  77. .hub_status_data = ehci_hub_status_data,
  78. .hub_control = ehci_hub_control,
  79. .relinquish_port = ehci_relinquish_port,
  80. .port_handed_over = ehci_port_handed_over,
  81. /*
  82. * PM support
  83. */
  84. .bus_suspend = ehci_bus_suspend,
  85. .bus_resume = ehci_bus_resume,
  86. };
  87. static int ehci_msm_probe(struct platform_device *pdev)
  88. {
  89. struct usb_hcd *hcd;
  90. struct resource *res;
  91. int ret;
  92. dev_dbg(&pdev->dev, "ehci_msm proble\n");
  93. hcd = usb_create_hcd(&msm_hc_driver, &pdev->dev, dev_name(&pdev->dev));
  94. if (!hcd) {
  95. dev_err(&pdev->dev, "Unable to create HCD\n");
  96. return -ENOMEM;
  97. }
  98. hcd->irq = platform_get_irq(pdev, 0);
  99. if (hcd->irq < 0) {
  100. dev_err(&pdev->dev, "Unable to get IRQ resource\n");
  101. ret = hcd->irq;
  102. goto put_hcd;
  103. }
  104. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  105. if (!res) {
  106. dev_err(&pdev->dev, "Unable to get memory resource\n");
  107. ret = -ENODEV;
  108. goto put_hcd;
  109. }
  110. hcd->rsrc_start = res->start;
  111. hcd->rsrc_len = resource_size(res);
  112. hcd->regs = devm_ioremap(&pdev->dev, hcd->rsrc_start, hcd->rsrc_len);
  113. if (!hcd->regs) {
  114. dev_err(&pdev->dev, "ioremap failed\n");
  115. ret = -ENOMEM;
  116. goto put_hcd;
  117. }
  118. /*
  119. * OTG driver takes care of PHY initialization, clock management,
  120. * powering up VBUS, mapping of registers address space and power
  121. * management.
  122. */
  123. phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
  124. if (IS_ERR_OR_NULL(phy)) {
  125. dev_err(&pdev->dev, "unable to find transceiver\n");
  126. ret = -ENODEV;
  127. goto put_hcd;
  128. }
  129. ret = otg_set_host(phy->otg, &hcd->self);
  130. if (ret < 0) {
  131. dev_err(&pdev->dev, "unable to register with transceiver\n");
  132. goto put_hcd;
  133. }
  134. device_init_wakeup(&pdev->dev, 1);
  135. /*
  136. * OTG device parent of HCD takes care of putting
  137. * hardware into low power mode.
  138. */
  139. pm_runtime_no_callbacks(&pdev->dev);
  140. pm_runtime_enable(&pdev->dev);
  141. return 0;
  142. put_hcd:
  143. usb_put_hcd(hcd);
  144. return ret;
  145. }
  146. static int ehci_msm_remove(struct platform_device *pdev)
  147. {
  148. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  149. device_init_wakeup(&pdev->dev, 0);
  150. pm_runtime_disable(&pdev->dev);
  151. pm_runtime_set_suspended(&pdev->dev);
  152. otg_set_host(phy->otg, NULL);
  153. usb_put_hcd(hcd);
  154. return 0;
  155. }
  156. #ifdef CONFIG_PM
  157. static int ehci_msm_pm_suspend(struct device *dev)
  158. {
  159. struct usb_hcd *hcd = dev_get_drvdata(dev);
  160. bool do_wakeup = device_may_wakeup(dev);
  161. dev_dbg(dev, "ehci-msm PM suspend\n");
  162. return ehci_suspend(hcd, do_wakeup);
  163. }
  164. static int ehci_msm_pm_resume(struct device *dev)
  165. {
  166. struct usb_hcd *hcd = dev_get_drvdata(dev);
  167. dev_dbg(dev, "ehci-msm PM resume\n");
  168. ehci_resume(hcd, false);
  169. return 0;
  170. }
  171. #else
  172. #define ehci_msm_pm_suspend NULL
  173. #define ehci_msm_pm_resume NULL
  174. #endif
  175. static const struct dev_pm_ops ehci_msm_dev_pm_ops = {
  176. .suspend = ehci_msm_pm_suspend,
  177. .resume = ehci_msm_pm_resume,
  178. };
  179. static struct platform_driver ehci_msm_driver = {
  180. .probe = ehci_msm_probe,
  181. .remove = ehci_msm_remove,
  182. .driver = {
  183. .name = "msm_hsusb_host",
  184. .pm = &ehci_msm_dev_pm_ops,
  185. },
  186. };