ehci-msm.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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/clk.h>
  25. #include <linux/err.h>
  26. #include <linux/io.h>
  27. #include <linux/kernel.h>
  28. #include <linux/module.h>
  29. #include <linux/platform_device.h>
  30. #include <linux/pm_runtime.h>
  31. #include <linux/usb/otg.h>
  32. #include <linux/usb/msm_hsusb_hw.h>
  33. #include <linux/usb.h>
  34. #include <linux/usb/hcd.h>
  35. #include <linux/acpi.h>
  36. #include "ehci.h"
  37. #define MSM_USB_BASE (hcd->regs)
  38. #define DRIVER_DESC "Qualcomm On-Chip EHCI Host Controller"
  39. static const char hcd_name[] = "ehci-msm";
  40. static struct hc_driver __read_mostly msm_hc_driver;
  41. static int ehci_msm_reset(struct usb_hcd *hcd)
  42. {
  43. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  44. int retval;
  45. ehci->caps = USB_CAPLENGTH;
  46. hcd->has_tt = 1;
  47. retval = ehci_setup(hcd);
  48. if (retval)
  49. return retval;
  50. /* select ULPI phy and clear other status/control bits in PORTSC */
  51. writel(PORTSC_PTS_ULPI, USB_PORTSC);
  52. /* bursts of unspecified length. */
  53. writel(0, USB_AHBBURST);
  54. /* Use the AHB transactor, allow posted data writes */
  55. writel(0x8, USB_AHBMODE);
  56. /* Disable streaming mode and select host mode */
  57. writel(0x13, USB_USBMODE);
  58. /* Disable ULPI_TX_PKT_EN_CLR_FIX which is valid only for HSIC */
  59. writel(readl(USB_GENCONFIG_2) & ~ULPI_TX_PKT_EN_CLR_FIX, USB_GENCONFIG_2);
  60. return 0;
  61. }
  62. static int ehci_msm_probe(struct platform_device *pdev)
  63. {
  64. struct usb_hcd *hcd;
  65. struct resource *res;
  66. struct usb_phy *phy;
  67. int ret;
  68. dev_dbg(&pdev->dev, "ehci_msm proble\n");
  69. hcd = usb_create_hcd(&msm_hc_driver, &pdev->dev, dev_name(&pdev->dev));
  70. if (!hcd) {
  71. dev_err(&pdev->dev, "Unable to create HCD\n");
  72. return -ENOMEM;
  73. }
  74. ret = platform_get_irq(pdev, 0);
  75. if (ret < 0) {
  76. dev_err(&pdev->dev, "Unable to get IRQ resource\n");
  77. goto put_hcd;
  78. }
  79. hcd->irq = ret;
  80. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  81. if (!res) {
  82. dev_err(&pdev->dev, "Unable to get memory resource\n");
  83. ret = -ENODEV;
  84. goto put_hcd;
  85. }
  86. hcd->rsrc_start = res->start;
  87. hcd->rsrc_len = resource_size(res);
  88. hcd->regs = devm_ioremap(&pdev->dev, hcd->rsrc_start, hcd->rsrc_len);
  89. if (!hcd->regs) {
  90. dev_err(&pdev->dev, "ioremap failed\n");
  91. ret = -ENOMEM;
  92. goto put_hcd;
  93. }
  94. /*
  95. * If there is an OTG driver, let it take care of PHY initialization,
  96. * clock management, powering up VBUS, mapping of registers address
  97. * space and power management.
  98. */
  99. if (pdev->dev.of_node)
  100. phy = devm_usb_get_phy_by_phandle(&pdev->dev, "usb-phy", 0);
  101. else
  102. phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
  103. if (IS_ERR(phy)) {
  104. if (PTR_ERR(phy) == -EPROBE_DEFER) {
  105. dev_err(&pdev->dev, "unable to find transceiver\n");
  106. ret = -EPROBE_DEFER;
  107. goto put_hcd;
  108. }
  109. phy = NULL;
  110. }
  111. hcd->usb_phy = phy;
  112. device_init_wakeup(&pdev->dev, 1);
  113. if (phy && phy->otg) {
  114. /*
  115. * MSM OTG driver takes care of adding the HCD and
  116. * placing hardware into low power mode via runtime PM.
  117. */
  118. ret = otg_set_host(phy->otg, &hcd->self);
  119. if (ret < 0) {
  120. dev_err(&pdev->dev, "unable to register with transceiver\n");
  121. goto put_hcd;
  122. }
  123. pm_runtime_no_callbacks(&pdev->dev);
  124. pm_runtime_enable(&pdev->dev);
  125. } else {
  126. ret = usb_add_hcd(hcd, hcd->irq, IRQF_SHARED);
  127. if (ret)
  128. goto put_hcd;
  129. }
  130. return 0;
  131. put_hcd:
  132. usb_put_hcd(hcd);
  133. return ret;
  134. }
  135. static int ehci_msm_remove(struct platform_device *pdev)
  136. {
  137. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  138. device_init_wakeup(&pdev->dev, 0);
  139. pm_runtime_disable(&pdev->dev);
  140. pm_runtime_set_suspended(&pdev->dev);
  141. if (hcd->usb_phy && hcd->usb_phy->otg)
  142. otg_set_host(hcd->usb_phy->otg, NULL);
  143. else
  144. usb_remove_hcd(hcd);
  145. usb_put_hcd(hcd);
  146. return 0;
  147. }
  148. #ifdef CONFIG_PM
  149. static int ehci_msm_pm_suspend(struct device *dev)
  150. {
  151. struct usb_hcd *hcd = dev_get_drvdata(dev);
  152. bool do_wakeup = device_may_wakeup(dev);
  153. dev_dbg(dev, "ehci-msm PM suspend\n");
  154. return ehci_suspend(hcd, do_wakeup);
  155. }
  156. static int ehci_msm_pm_resume(struct device *dev)
  157. {
  158. struct usb_hcd *hcd = dev_get_drvdata(dev);
  159. dev_dbg(dev, "ehci-msm PM resume\n");
  160. ehci_resume(hcd, false);
  161. return 0;
  162. }
  163. #else
  164. #define ehci_msm_pm_suspend NULL
  165. #define ehci_msm_pm_resume NULL
  166. #endif
  167. static const struct dev_pm_ops ehci_msm_dev_pm_ops = {
  168. .suspend = ehci_msm_pm_suspend,
  169. .resume = ehci_msm_pm_resume,
  170. };
  171. static const struct acpi_device_id msm_ehci_acpi_ids[] = {
  172. { "QCOM8040", 0 },
  173. { }
  174. };
  175. MODULE_DEVICE_TABLE(acpi, msm_ehci_acpi_ids);
  176. static const struct of_device_id msm_ehci_dt_match[] = {
  177. { .compatible = "qcom,ehci-host", },
  178. {}
  179. };
  180. MODULE_DEVICE_TABLE(of, msm_ehci_dt_match);
  181. static struct platform_driver ehci_msm_driver = {
  182. .probe = ehci_msm_probe,
  183. .remove = ehci_msm_remove,
  184. .shutdown = usb_hcd_platform_shutdown,
  185. .driver = {
  186. .name = "msm_hsusb_host",
  187. .pm = &ehci_msm_dev_pm_ops,
  188. .of_match_table = msm_ehci_dt_match,
  189. .acpi_match_table = ACPI_PTR(msm_ehci_acpi_ids),
  190. },
  191. };
  192. static const struct ehci_driver_overrides msm_overrides __initdata = {
  193. .reset = ehci_msm_reset,
  194. };
  195. static int __init ehci_msm_init(void)
  196. {
  197. if (usb_disabled())
  198. return -ENODEV;
  199. pr_info("%s: " DRIVER_DESC "\n", hcd_name);
  200. ehci_init_driver(&msm_hc_driver, &msm_overrides);
  201. return platform_driver_register(&ehci_msm_driver);
  202. }
  203. module_init(ehci_msm_init);
  204. static void __exit ehci_msm_cleanup(void)
  205. {
  206. platform_driver_unregister(&ehci_msm_driver);
  207. }
  208. module_exit(ehci_msm_cleanup);
  209. MODULE_DESCRIPTION(DRIVER_DESC);
  210. MODULE_ALIAS("platform:msm-ehci");
  211. MODULE_LICENSE("GPL");