ehci-msm.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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/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_hw.h>
  30. #define MSM_USB_BASE (hcd->regs)
  31. static struct otg_transceiver *otg;
  32. static int ehci_msm_reset(struct usb_hcd *hcd)
  33. {
  34. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  35. int retval;
  36. ehci->caps = USB_CAPLENGTH;
  37. ehci->regs = USB_CAPLENGTH +
  38. HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
  39. dbg_hcs_params(ehci, "reset");
  40. dbg_hcc_params(ehci, "reset");
  41. /* cache the data to minimize the chip reads*/
  42. ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
  43. hcd->has_tt = 1;
  44. ehci->sbrn = HCD_USB2;
  45. retval = ehci_halt(ehci);
  46. if (retval)
  47. return retval;
  48. /* data structure init */
  49. retval = ehci_init(hcd);
  50. if (retval)
  51. return retval;
  52. retval = ehci_reset(ehci);
  53. if (retval)
  54. return retval;
  55. /* bursts of unspecified length. */
  56. writel(0, USB_AHBBURST);
  57. /* Use the AHB transactor */
  58. writel(0, USB_AHBMODE);
  59. /* Disable streaming mode and select host mode */
  60. writel(0x13, USB_USBMODE);
  61. ehci_port_power(ehci, 1);
  62. return 0;
  63. }
  64. static struct hc_driver msm_hc_driver = {
  65. .description = hcd_name,
  66. .product_desc = "Qualcomm On-Chip EHCI Host Controller",
  67. .hcd_priv_size = sizeof(struct ehci_hcd),
  68. /*
  69. * generic hardware linkage
  70. */
  71. .irq = ehci_irq,
  72. .flags = HCD_USB2 | HCD_MEMORY,
  73. .reset = ehci_msm_reset,
  74. .start = ehci_run,
  75. .stop = ehci_stop,
  76. .shutdown = ehci_shutdown,
  77. /*
  78. * managing i/o requests and associated device resources
  79. */
  80. .urb_enqueue = ehci_urb_enqueue,
  81. .urb_dequeue = ehci_urb_dequeue,
  82. .endpoint_disable = ehci_endpoint_disable,
  83. .endpoint_reset = ehci_endpoint_reset,
  84. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  85. /*
  86. * scheduling support
  87. */
  88. .get_frame_number = ehci_get_frame,
  89. /*
  90. * root hub support
  91. */
  92. .hub_status_data = ehci_hub_status_data,
  93. .hub_control = ehci_hub_control,
  94. .relinquish_port = ehci_relinquish_port,
  95. .port_handed_over = ehci_port_handed_over,
  96. /*
  97. * PM support
  98. */
  99. .bus_suspend = ehci_bus_suspend,
  100. .bus_resume = ehci_bus_resume,
  101. };
  102. static int ehci_msm_probe(struct platform_device *pdev)
  103. {
  104. struct usb_hcd *hcd;
  105. struct resource *res;
  106. int ret;
  107. dev_dbg(&pdev->dev, "ehci_msm proble\n");
  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->irq = platform_get_irq(pdev, 0);
  114. if (hcd->irq < 0) {
  115. dev_err(&pdev->dev, "Unable to get IRQ resource\n");
  116. ret = hcd->irq;
  117. goto put_hcd;
  118. }
  119. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  120. if (!res) {
  121. dev_err(&pdev->dev, "Unable to get memory resource\n");
  122. ret = -ENODEV;
  123. goto put_hcd;
  124. }
  125. hcd->rsrc_start = res->start;
  126. hcd->rsrc_len = resource_size(res);
  127. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  128. if (!hcd->regs) {
  129. dev_err(&pdev->dev, "ioremap failed\n");
  130. ret = -ENOMEM;
  131. goto put_hcd;
  132. }
  133. /*
  134. * OTG driver takes care of PHY initialization, clock management,
  135. * powering up VBUS, mapping of registers address space and power
  136. * management.
  137. */
  138. otg = otg_get_transceiver();
  139. if (!otg) {
  140. dev_err(&pdev->dev, "unable to find transceiver\n");
  141. ret = -ENODEV;
  142. goto unmap;
  143. }
  144. ret = otg_set_host(otg, &hcd->self);
  145. if (ret < 0) {
  146. dev_err(&pdev->dev, "unable to register with transceiver\n");
  147. goto put_transceiver;
  148. }
  149. device_init_wakeup(&pdev->dev, 1);
  150. /*
  151. * OTG device parent of HCD takes care of putting
  152. * hardware into low power mode.
  153. */
  154. pm_runtime_no_callbacks(&pdev->dev);
  155. pm_runtime_enable(&pdev->dev);
  156. return 0;
  157. put_transceiver:
  158. otg_put_transceiver(otg);
  159. unmap:
  160. iounmap(hcd->regs);
  161. put_hcd:
  162. usb_put_hcd(hcd);
  163. return ret;
  164. }
  165. static int __devexit ehci_msm_remove(struct platform_device *pdev)
  166. {
  167. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  168. device_init_wakeup(&pdev->dev, 0);
  169. pm_runtime_disable(&pdev->dev);
  170. pm_runtime_set_suspended(&pdev->dev);
  171. otg_set_host(otg, NULL);
  172. otg_put_transceiver(otg);
  173. usb_put_hcd(hcd);
  174. return 0;
  175. }
  176. #ifdef CONFIG_PM
  177. static int ehci_msm_pm_suspend(struct device *dev)
  178. {
  179. struct usb_hcd *hcd = dev_get_drvdata(dev);
  180. bool wakeup = device_may_wakeup(dev);
  181. dev_dbg(dev, "ehci-msm PM suspend\n");
  182. /*
  183. * EHCI helper function has also the same check before manipulating
  184. * port wakeup flags. We do check here the same condition before
  185. * calling the same helper function to avoid bringing hardware
  186. * from Low power mode when there is no need for adjusting port
  187. * wakeup flags.
  188. */
  189. if (hcd->self.root_hub->do_remote_wakeup && !wakeup) {
  190. pm_runtime_resume(dev);
  191. ehci_prepare_ports_for_controller_suspend(hcd_to_ehci(hcd),
  192. wakeup);
  193. }
  194. return 0;
  195. }
  196. static int ehci_msm_pm_resume(struct device *dev)
  197. {
  198. struct usb_hcd *hcd = dev_get_drvdata(dev);
  199. dev_dbg(dev, "ehci-msm PM resume\n");
  200. ehci_prepare_ports_for_controller_resume(hcd_to_ehci(hcd));
  201. return 0;
  202. }
  203. #else
  204. #define ehci_msm_pm_suspend NULL
  205. #define ehci_msm_pm_resume NULL
  206. #endif
  207. static const struct dev_pm_ops ehci_msm_dev_pm_ops = {
  208. .suspend = ehci_msm_pm_suspend,
  209. .resume = ehci_msm_pm_resume,
  210. };
  211. static struct platform_driver ehci_msm_driver = {
  212. .probe = ehci_msm_probe,
  213. .remove = __devexit_p(ehci_msm_remove),
  214. .driver = {
  215. .name = "msm_hsusb_host",
  216. .pm = &ehci_msm_dev_pm_ops,
  217. },
  218. };