ehci-msm.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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 struct usb_phy *phy;
  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. /* bursts of unspecified length. */
  51. writel(0, USB_AHBBURST);
  52. /* Use the AHB transactor */
  53. writel(0, USB_AHBMODE);
  54. /* Disable streaming mode and select host mode */
  55. writel(0x13, USB_USBMODE);
  56. return 0;
  57. }
  58. static int ehci_msm_probe(struct platform_device *pdev)
  59. {
  60. struct usb_hcd *hcd;
  61. struct resource *res;
  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. 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. phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
  95. if (IS_ERR(phy)) {
  96. dev_err(&pdev->dev, "unable to find transceiver\n");
  97. ret = -ENODEV;
  98. goto put_hcd;
  99. }
  100. ret = otg_set_host(phy->otg, &hcd->self);
  101. if (ret < 0) {
  102. dev_err(&pdev->dev, "unable to register with transceiver\n");
  103. goto put_hcd;
  104. }
  105. device_init_wakeup(&pdev->dev, 1);
  106. /*
  107. * OTG device parent of HCD takes care of putting
  108. * hardware into low power mode.
  109. */
  110. pm_runtime_no_callbacks(&pdev->dev);
  111. pm_runtime_enable(&pdev->dev);
  112. /* FIXME: need to call usb_add_hcd() here? */
  113. return 0;
  114. put_hcd:
  115. usb_put_hcd(hcd);
  116. return ret;
  117. }
  118. static int ehci_msm_remove(struct platform_device *pdev)
  119. {
  120. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  121. device_init_wakeup(&pdev->dev, 0);
  122. pm_runtime_disable(&pdev->dev);
  123. pm_runtime_set_suspended(&pdev->dev);
  124. otg_set_host(phy->otg, NULL);
  125. /* FIXME: need to call usb_remove_hcd() here? */
  126. usb_put_hcd(hcd);
  127. return 0;
  128. }
  129. #ifdef CONFIG_PM
  130. static int ehci_msm_pm_suspend(struct device *dev)
  131. {
  132. struct usb_hcd *hcd = dev_get_drvdata(dev);
  133. bool do_wakeup = device_may_wakeup(dev);
  134. dev_dbg(dev, "ehci-msm PM suspend\n");
  135. return ehci_suspend(hcd, do_wakeup);
  136. }
  137. static int ehci_msm_pm_resume(struct device *dev)
  138. {
  139. struct usb_hcd *hcd = dev_get_drvdata(dev);
  140. dev_dbg(dev, "ehci-msm PM resume\n");
  141. ehci_resume(hcd, false);
  142. return 0;
  143. }
  144. #else
  145. #define ehci_msm_pm_suspend NULL
  146. #define ehci_msm_pm_resume NULL
  147. #endif
  148. static const struct dev_pm_ops ehci_msm_dev_pm_ops = {
  149. .suspend = ehci_msm_pm_suspend,
  150. .resume = ehci_msm_pm_resume,
  151. };
  152. static struct platform_driver ehci_msm_driver = {
  153. .probe = ehci_msm_probe,
  154. .remove = ehci_msm_remove,
  155. .driver = {
  156. .name = "msm_hsusb_host",
  157. .pm = &ehci_msm_dev_pm_ops,
  158. },
  159. };
  160. static const struct ehci_driver_overrides msm_overrides __initdata = {
  161. .reset = ehci_msm_reset,
  162. };
  163. static int __init ehci_msm_init(void)
  164. {
  165. if (usb_disabled())
  166. return -ENODEV;
  167. pr_info("%s: " DRIVER_DESC "\n", hcd_name);
  168. ehci_init_driver(&msm_hc_driver, &msm_overrides);
  169. return platform_driver_register(&ehci_msm_driver);
  170. }
  171. module_init(ehci_msm_init);
  172. static void __exit ehci_msm_cleanup(void)
  173. {
  174. platform_driver_unregister(&ehci_msm_driver);
  175. }
  176. module_exit(ehci_msm_cleanup);
  177. MODULE_DESCRIPTION(DRIVER_DESC);
  178. MODULE_ALIAS("platform:msm-ehci");
  179. MODULE_LICENSE("GPL");