ehci-msm.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. /* ehci-msm.c - HSUSB Host Controller Driver Implementation
  2. *
  3. * Copyright (c) 2008-2013, The Linux Foundation. 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.h>
  30. #include <linux/usb/msm_hsusb_hw.h>
  31. #define MSM_USB_BASE (hcd->regs)
  32. static struct usb_phy *phy;
  33. static int ehci_msm_reset(struct usb_hcd *hcd)
  34. {
  35. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  36. int retval;
  37. ehci->caps = USB_CAPLENGTH;
  38. hcd->has_tt = 1;
  39. retval = ehci_setup(hcd);
  40. if (retval)
  41. return retval;
  42. /* bursts of unspecified length. */
  43. writel_relaxed(0, USB_AHBBURST);
  44. /* Use the AHB transactor */
  45. writel_relaxed(0x08, USB_AHBMODE);
  46. /* Disable streaming mode and select host mode */
  47. writel_relaxed(0x13, USB_USBMODE);
  48. if (ehci->transceiver->flags & ENABLE_SECONDARY_PHY) {
  49. ehci_dbg(ehci, "using secondary hsphy\n");
  50. writel_relaxed(readl_relaxed(USB_PHY_CTRL2) | (1<<16),
  51. USB_PHY_CTRL2);
  52. }
  53. /* Disable ULPI_TX_PKT_EN_CLR_FIX which is valid only for HSIC */
  54. writel_relaxed(readl_relaxed(USB_GENCONFIG2) & ~(1<<19),
  55. USB_GENCONFIG2);
  56. ehci_port_power(ehci, 1);
  57. return 0;
  58. }
  59. static struct hc_driver msm_hc_driver = {
  60. .description = hcd_name,
  61. .product_desc = "Qualcomm On-Chip EHCI Host Controller",
  62. .hcd_priv_size = sizeof(struct ehci_hcd),
  63. /*
  64. * generic hardware linkage
  65. */
  66. .irq = ehci_irq,
  67. .flags = HCD_USB2 | HCD_MEMORY,
  68. .reset = ehci_msm_reset,
  69. .start = ehci_run,
  70. .stop = ehci_stop,
  71. .shutdown = ehci_shutdown,
  72. /*
  73. * managing i/o requests and associated device resources
  74. */
  75. .urb_enqueue = ehci_urb_enqueue,
  76. .urb_dequeue = ehci_urb_dequeue,
  77. .endpoint_disable = ehci_endpoint_disable,
  78. .endpoint_reset = ehci_endpoint_reset,
  79. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  80. /*
  81. * scheduling support
  82. */
  83. .get_frame_number = ehci_get_frame,
  84. /*
  85. * root hub support
  86. */
  87. .hub_status_data = ehci_hub_status_data,
  88. .hub_control = ehci_hub_control,
  89. .relinquish_port = ehci_relinquish_port,
  90. .port_handed_over = ehci_port_handed_over,
  91. /*
  92. * PM support
  93. */
  94. .bus_suspend = ehci_bus_suspend,
  95. .bus_resume = ehci_bus_resume,
  96. };
  97. static u64 msm_ehci_dma_mask = DMA_BIT_MASK(64);
  98. static int ehci_msm_probe(struct platform_device *pdev)
  99. {
  100. struct usb_hcd *hcd;
  101. struct resource *res;
  102. int ret;
  103. dev_dbg(&pdev->dev, "ehci_msm proble\n");
  104. if (!pdev->dev.dma_mask)
  105. pdev->dev.dma_mask = &msm_ehci_dma_mask;
  106. if (!pdev->dev.coherent_dma_mask)
  107. pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
  108. hcd = usb_create_hcd(&msm_hc_driver, &pdev->dev, dev_name(&pdev->dev));
  109. if (!hcd) {
  110. dev_err(&pdev->dev, "Unable to create HCD\n");
  111. return -ENOMEM;
  112. }
  113. hcd_to_bus(hcd)->skip_resume = true;
  114. hcd->irq = platform_get_irq(pdev, 0);
  115. if (hcd->irq < 0) {
  116. dev_err(&pdev->dev, "Unable to get IRQ resource\n");
  117. ret = hcd->irq;
  118. goto put_hcd;
  119. }
  120. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  121. if (!res) {
  122. dev_err(&pdev->dev, "Unable to get memory resource\n");
  123. ret = -ENODEV;
  124. goto put_hcd;
  125. }
  126. hcd->rsrc_start = res->start;
  127. hcd->rsrc_len = resource_size(res);
  128. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  129. if (!hcd->regs) {
  130. dev_err(&pdev->dev, "ioremap failed\n");
  131. ret = -ENOMEM;
  132. goto put_hcd;
  133. }
  134. /*
  135. * OTG driver takes care of PHY initialization, clock management,
  136. * powering up VBUS, mapping of registers address space and power
  137. * management.
  138. */
  139. phy = usb_get_transceiver();
  140. if (!phy) {
  141. dev_err(&pdev->dev, "unable to find transceiver\n");
  142. ret = -ENODEV;
  143. goto unmap;
  144. }
  145. ret = otg_set_host(phy->otg, &hcd->self);
  146. if (ret < 0) {
  147. dev_err(&pdev->dev, "unable to register with transceiver\n");
  148. goto put_transceiver;
  149. }
  150. hcd_to_ehci(hcd)->transceiver = phy;
  151. device_init_wakeup(&pdev->dev, 1);
  152. pm_runtime_enable(&pdev->dev);
  153. return 0;
  154. put_transceiver:
  155. usb_put_transceiver(phy);
  156. unmap:
  157. iounmap(hcd->regs);
  158. put_hcd:
  159. usb_put_hcd(hcd);
  160. return ret;
  161. }
  162. static int __devexit ehci_msm_remove(struct platform_device *pdev)
  163. {
  164. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  165. device_init_wakeup(&pdev->dev, 0);
  166. pm_runtime_disable(&pdev->dev);
  167. pm_runtime_set_suspended(&pdev->dev);
  168. hcd_to_ehci(hcd)->transceiver = NULL;
  169. otg_set_host(phy->otg, NULL);
  170. usb_put_transceiver(phy);
  171. usb_put_hcd(hcd);
  172. return 0;
  173. }
  174. #ifdef CONFIG_PM_RUNTIME
  175. static int ehci_msm_runtime_idle(struct device *dev)
  176. {
  177. dev_dbg(dev, "ehci runtime idle\n");
  178. return 0;
  179. }
  180. static int ehci_msm_runtime_suspend(struct device *dev)
  181. {
  182. dev_dbg(dev, "ehci runtime suspend\n");
  183. /*
  184. * Notify OTG about suspend. It takes care of
  185. * putting the hardware in LPM.
  186. */
  187. return usb_phy_set_suspend(phy, 1);
  188. }
  189. static int ehci_msm_runtime_resume(struct device *dev)
  190. {
  191. dev_dbg(dev, "ehci runtime resume\n");
  192. return usb_phy_set_suspend(phy, 0);
  193. }
  194. #endif
  195. #ifdef CONFIG_PM_SLEEP
  196. static int ehci_msm_pm_suspend(struct device *dev)
  197. {
  198. struct usb_hcd *hcd = dev_get_drvdata(dev);
  199. bool wakeup = device_may_wakeup(dev);
  200. dev_dbg(dev, "ehci-msm PM suspend\n");
  201. if (!hcd->rh_registered)
  202. return 0;
  203. /*
  204. * EHCI helper function has also the same check before manipulating
  205. * port wakeup flags. We do check here the same condition before
  206. * calling the same helper function to avoid bringing hardware
  207. * from Low power mode when there is no need for adjusting port
  208. * wakeup flags.
  209. */
  210. if (hcd->self.root_hub->do_remote_wakeup && !wakeup) {
  211. pm_runtime_resume(dev);
  212. ehci_prepare_ports_for_controller_suspend(hcd_to_ehci(hcd),
  213. wakeup);
  214. }
  215. return usb_phy_set_suspend(phy, 1);
  216. }
  217. static int ehci_msm_pm_resume(struct device *dev)
  218. {
  219. struct usb_hcd *hcd = dev_get_drvdata(dev);
  220. int ret;
  221. dev_dbg(dev, "ehci-msm PM resume\n");
  222. if (!hcd->rh_registered)
  223. return 0;
  224. /* Notify OTG to bring hw out of LPM before restoring wakeup flags */
  225. ret = usb_phy_set_suspend(phy, 0);
  226. if (ret)
  227. return ret;
  228. ehci_prepare_ports_for_controller_resume(hcd_to_ehci(hcd));
  229. /* Resume root-hub to handle USB event if any else initiate LPM again */
  230. usb_hcd_resume_root_hub(hcd);
  231. return ret;
  232. }
  233. #endif
  234. static const struct dev_pm_ops ehci_msm_dev_pm_ops = {
  235. SET_SYSTEM_SLEEP_PM_OPS(ehci_msm_pm_suspend, ehci_msm_pm_resume)
  236. SET_RUNTIME_PM_OPS(ehci_msm_runtime_suspend, ehci_msm_runtime_resume,
  237. ehci_msm_runtime_idle)
  238. };
  239. static struct platform_driver ehci_msm_driver = {
  240. .probe = ehci_msm_probe,
  241. .remove = __devexit_p(ehci_msm_remove),
  242. .driver = {
  243. .name = "msm_hsusb_host",
  244. .pm = &ehci_msm_dev_pm_ops,
  245. },
  246. };