ehci-msm.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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 "ehci.h"
  36. #define MSM_USB_BASE (hcd->regs)
  37. #define DRIVER_DESC "Qualcomm On-Chip EHCI Host Controller"
  38. static const char hcd_name[] = "ehci-msm";
  39. static struct hc_driver __read_mostly msm_hc_driver;
  40. static int ehci_msm_reset(struct usb_hcd *hcd)
  41. {
  42. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  43. int retval;
  44. ehci->caps = USB_CAPLENGTH;
  45. hcd->has_tt = 1;
  46. retval = ehci_setup(hcd);
  47. if (retval)
  48. return retval;
  49. /* bursts of unspecified length. */
  50. writel(0, USB_AHBBURST);
  51. /* Use the AHB transactor */
  52. writel(0, USB_AHBMODE);
  53. /* Disable streaming mode and select host mode */
  54. writel(0x13, USB_USBMODE);
  55. return 0;
  56. }
  57. static int ehci_msm_probe(struct platform_device *pdev)
  58. {
  59. struct usb_hcd *hcd;
  60. struct resource *res;
  61. struct usb_phy *phy;
  62. int ret;
  63. dev_dbg(&pdev->dev, "ehci_msm proble\n");
  64. hcd = usb_create_hcd(&msm_hc_driver, &pdev->dev, dev_name(&pdev->dev));
  65. if (!hcd) {
  66. dev_err(&pdev->dev, "Unable to create HCD\n");
  67. return -ENOMEM;
  68. }
  69. ret = platform_get_irq(pdev, 0);
  70. if (ret < 0) {
  71. dev_err(&pdev->dev, "Unable to get IRQ resource\n");
  72. goto put_hcd;
  73. }
  74. hcd->irq = ret;
  75. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  76. if (!res) {
  77. dev_err(&pdev->dev, "Unable to get memory resource\n");
  78. ret = -ENODEV;
  79. goto put_hcd;
  80. }
  81. hcd->rsrc_start = res->start;
  82. hcd->rsrc_len = resource_size(res);
  83. hcd->regs = devm_ioremap(&pdev->dev, hcd->rsrc_start, hcd->rsrc_len);
  84. if (!hcd->regs) {
  85. dev_err(&pdev->dev, "ioremap failed\n");
  86. ret = -ENOMEM;
  87. goto put_hcd;
  88. }
  89. /*
  90. * OTG driver takes care of PHY initialization, clock management,
  91. * powering up VBUS, mapping of registers address space and power
  92. * management.
  93. */
  94. if (pdev->dev.of_node)
  95. phy = devm_usb_get_phy_by_phandle(&pdev->dev, "usb-phy", 0);
  96. else
  97. phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
  98. if (IS_ERR(phy)) {
  99. dev_err(&pdev->dev, "unable to find transceiver\n");
  100. ret = -EPROBE_DEFER;
  101. goto put_hcd;
  102. }
  103. ret = otg_set_host(phy->otg, &hcd->self);
  104. if (ret < 0) {
  105. dev_err(&pdev->dev, "unable to register with transceiver\n");
  106. goto put_hcd;
  107. }
  108. hcd->usb_phy = phy;
  109. device_init_wakeup(&pdev->dev, 1);
  110. /*
  111. * OTG device parent of HCD takes care of putting
  112. * hardware into low power mode.
  113. */
  114. pm_runtime_no_callbacks(&pdev->dev);
  115. pm_runtime_enable(&pdev->dev);
  116. /* FIXME: need to call usb_add_hcd() here? */
  117. return 0;
  118. put_hcd:
  119. usb_put_hcd(hcd);
  120. return ret;
  121. }
  122. static int ehci_msm_remove(struct platform_device *pdev)
  123. {
  124. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  125. device_init_wakeup(&pdev->dev, 0);
  126. pm_runtime_disable(&pdev->dev);
  127. pm_runtime_set_suspended(&pdev->dev);
  128. otg_set_host(hcd->usb_phy->otg, NULL);
  129. /* FIXME: need to call usb_remove_hcd() here? */
  130. usb_put_hcd(hcd);
  131. return 0;
  132. }
  133. #ifdef CONFIG_PM
  134. static int ehci_msm_pm_suspend(struct device *dev)
  135. {
  136. struct usb_hcd *hcd = dev_get_drvdata(dev);
  137. bool do_wakeup = device_may_wakeup(dev);
  138. dev_dbg(dev, "ehci-msm PM suspend\n");
  139. return ehci_suspend(hcd, do_wakeup);
  140. }
  141. static int ehci_msm_pm_resume(struct device *dev)
  142. {
  143. struct usb_hcd *hcd = dev_get_drvdata(dev);
  144. dev_dbg(dev, "ehci-msm PM resume\n");
  145. ehci_resume(hcd, false);
  146. return 0;
  147. }
  148. #else
  149. #define ehci_msm_pm_suspend NULL
  150. #define ehci_msm_pm_resume NULL
  151. #endif
  152. static const struct dev_pm_ops ehci_msm_dev_pm_ops = {
  153. .suspend = ehci_msm_pm_suspend,
  154. .resume = ehci_msm_pm_resume,
  155. };
  156. static const struct of_device_id msm_ehci_dt_match[] = {
  157. { .compatible = "qcom,ehci-host", },
  158. {}
  159. };
  160. MODULE_DEVICE_TABLE(of, msm_ehci_dt_match);
  161. static struct platform_driver ehci_msm_driver = {
  162. .probe = ehci_msm_probe,
  163. .remove = ehci_msm_remove,
  164. .driver = {
  165. .name = "msm_hsusb_host",
  166. .pm = &ehci_msm_dev_pm_ops,
  167. .of_match_table = msm_ehci_dt_match,
  168. },
  169. };
  170. static const struct ehci_driver_overrides msm_overrides __initdata = {
  171. .reset = ehci_msm_reset,
  172. };
  173. static int __init ehci_msm_init(void)
  174. {
  175. if (usb_disabled())
  176. return -ENODEV;
  177. pr_info("%s: " DRIVER_DESC "\n", hcd_name);
  178. ehci_init_driver(&msm_hc_driver, &msm_overrides);
  179. return platform_driver_register(&ehci_msm_driver);
  180. }
  181. module_init(ehci_msm_init);
  182. static void __exit ehci_msm_cleanup(void)
  183. {
  184. platform_driver_unregister(&ehci_msm_driver);
  185. }
  186. module_exit(ehci_msm_cleanup);
  187. MODULE_DESCRIPTION(DRIVER_DESC);
  188. MODULE_ALIAS("platform:msm-ehci");
  189. MODULE_LICENSE("GPL");