ehci-msm.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. hcd->irq = platform_get_irq(pdev, 0);
  70. if (hcd->irq < 0) {
  71. dev_err(&pdev->dev, "Unable to get IRQ resource\n");
  72. ret = hcd->irq;
  73. goto put_hcd;
  74. }
  75. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  76. hcd->regs = devm_ioremap_resource(&pdev->dev, res);
  77. if (IS_ERR(hcd->regs)) {
  78. ret = PTR_ERR(hcd->regs);
  79. goto put_hcd;
  80. }
  81. hcd->rsrc_start = res->start;
  82. hcd->rsrc_len = resource_size(res);
  83. /*
  84. * OTG driver takes care of PHY initialization, clock management,
  85. * powering up VBUS, mapping of registers address space and power
  86. * management.
  87. */
  88. if (pdev->dev.of_node)
  89. phy = devm_usb_get_phy_by_phandle(&pdev->dev, "usb-phy", 0);
  90. else
  91. phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
  92. if (IS_ERR(phy)) {
  93. dev_err(&pdev->dev, "unable to find transceiver\n");
  94. ret = -EPROBE_DEFER;
  95. goto put_hcd;
  96. }
  97. ret = otg_set_host(phy->otg, &hcd->self);
  98. if (ret < 0) {
  99. dev_err(&pdev->dev, "unable to register with transceiver\n");
  100. goto put_hcd;
  101. }
  102. hcd->usb_phy = phy;
  103. device_init_wakeup(&pdev->dev, 1);
  104. /*
  105. * OTG device parent of HCD takes care of putting
  106. * hardware into low power mode.
  107. */
  108. pm_runtime_no_callbacks(&pdev->dev);
  109. pm_runtime_enable(&pdev->dev);
  110. /* FIXME: need to call usb_add_hcd() here? */
  111. return 0;
  112. put_hcd:
  113. usb_put_hcd(hcd);
  114. return ret;
  115. }
  116. static int ehci_msm_remove(struct platform_device *pdev)
  117. {
  118. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  119. device_init_wakeup(&pdev->dev, 0);
  120. pm_runtime_disable(&pdev->dev);
  121. pm_runtime_set_suspended(&pdev->dev);
  122. otg_set_host(hcd->usb_phy->otg, NULL);
  123. /* FIXME: need to call usb_remove_hcd() here? */
  124. usb_put_hcd(hcd);
  125. return 0;
  126. }
  127. #ifdef CONFIG_PM
  128. static int ehci_msm_pm_suspend(struct device *dev)
  129. {
  130. struct usb_hcd *hcd = dev_get_drvdata(dev);
  131. bool do_wakeup = device_may_wakeup(dev);
  132. dev_dbg(dev, "ehci-msm PM suspend\n");
  133. return ehci_suspend(hcd, do_wakeup);
  134. }
  135. static int ehci_msm_pm_resume(struct device *dev)
  136. {
  137. struct usb_hcd *hcd = dev_get_drvdata(dev);
  138. dev_dbg(dev, "ehci-msm PM resume\n");
  139. ehci_resume(hcd, false);
  140. return 0;
  141. }
  142. #else
  143. #define ehci_msm_pm_suspend NULL
  144. #define ehci_msm_pm_resume NULL
  145. #endif
  146. static const struct dev_pm_ops ehci_msm_dev_pm_ops = {
  147. .suspend = ehci_msm_pm_suspend,
  148. .resume = ehci_msm_pm_resume,
  149. };
  150. static const struct of_device_id msm_ehci_dt_match[] = {
  151. { .compatible = "qcom,ehci-host", },
  152. {}
  153. };
  154. MODULE_DEVICE_TABLE(of, msm_ehci_dt_match);
  155. static struct platform_driver ehci_msm_driver = {
  156. .probe = ehci_msm_probe,
  157. .remove = ehci_msm_remove,
  158. .driver = {
  159. .name = "msm_hsusb_host",
  160. .pm = &ehci_msm_dev_pm_ops,
  161. .of_match_table = msm_ehci_dt_match,
  162. },
  163. };
  164. static const struct ehci_driver_overrides msm_overrides __initdata = {
  165. .reset = ehci_msm_reset,
  166. };
  167. static int __init ehci_msm_init(void)
  168. {
  169. if (usb_disabled())
  170. return -ENODEV;
  171. pr_info("%s: " DRIVER_DESC "\n", hcd_name);
  172. ehci_init_driver(&msm_hc_driver, &msm_overrides);
  173. return platform_driver_register(&ehci_msm_driver);
  174. }
  175. module_init(ehci_msm_init);
  176. static void __exit ehci_msm_cleanup(void)
  177. {
  178. platform_driver_unregister(&ehci_msm_driver);
  179. }
  180. module_exit(ehci_msm_cleanup);
  181. MODULE_DESCRIPTION(DRIVER_DESC);
  182. MODULE_ALIAS("platform:msm-ehci");
  183. MODULE_LICENSE("GPL");