ehci-spear.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*
  2. * Driver for EHCI HCD on SPEAR SOC
  3. *
  4. * Copyright (C) 2010 ST Micro Electronics,
  5. * Deepak Sikri <deepak.sikri@st.com>
  6. *
  7. * Based on various ehci-*.c drivers
  8. *
  9. * This file is subject to the terms and conditions of the GNU General Public
  10. * License. See the file COPYING in the main directory of this archive for
  11. * more details.
  12. */
  13. #include <linux/clk.h>
  14. #include <linux/jiffies.h>
  15. #include <linux/of.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/pm.h>
  18. struct spear_ehci {
  19. struct ehci_hcd ehci;
  20. struct clk *clk;
  21. };
  22. #define to_spear_ehci(hcd) (struct spear_ehci *)hcd_to_ehci(hcd)
  23. static void spear_start_ehci(struct spear_ehci *ehci)
  24. {
  25. clk_prepare_enable(ehci->clk);
  26. }
  27. static void spear_stop_ehci(struct spear_ehci *ehci)
  28. {
  29. clk_disable_unprepare(ehci->clk);
  30. }
  31. static int ehci_spear_setup(struct usb_hcd *hcd)
  32. {
  33. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  34. /* registers start at offset 0x0 */
  35. ehci->caps = hcd->regs;
  36. return ehci_setup(hcd);
  37. }
  38. static const struct hc_driver ehci_spear_hc_driver = {
  39. .description = hcd_name,
  40. .product_desc = "SPEAr EHCI",
  41. .hcd_priv_size = sizeof(struct spear_ehci),
  42. /* generic hardware linkage */
  43. .irq = ehci_irq,
  44. .flags = HCD_MEMORY | HCD_USB2,
  45. /* basic lifecycle operations */
  46. .reset = ehci_spear_setup,
  47. .start = ehci_run,
  48. .stop = ehci_stop,
  49. .shutdown = ehci_shutdown,
  50. /* managing i/o requests and associated device resources */
  51. .urb_enqueue = ehci_urb_enqueue,
  52. .urb_dequeue = ehci_urb_dequeue,
  53. .endpoint_disable = ehci_endpoint_disable,
  54. .endpoint_reset = ehci_endpoint_reset,
  55. /* scheduling support */
  56. .get_frame_number = ehci_get_frame,
  57. /* root hub support */
  58. .hub_status_data = ehci_hub_status_data,
  59. .hub_control = ehci_hub_control,
  60. .bus_suspend = ehci_bus_suspend,
  61. .bus_resume = ehci_bus_resume,
  62. .relinquish_port = ehci_relinquish_port,
  63. .port_handed_over = ehci_port_handed_over,
  64. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  65. };
  66. #ifdef CONFIG_PM
  67. static int ehci_spear_drv_suspend(struct device *dev)
  68. {
  69. struct usb_hcd *hcd = dev_get_drvdata(dev);
  70. bool do_wakeup = device_may_wakeup(dev);
  71. return ehci_suspend(hcd, do_wakeup);
  72. }
  73. static int ehci_spear_drv_resume(struct device *dev)
  74. {
  75. struct usb_hcd *hcd = dev_get_drvdata(dev);
  76. ehci_resume(hcd, false);
  77. return 0;
  78. }
  79. #endif /* CONFIG_PM */
  80. static SIMPLE_DEV_PM_OPS(ehci_spear_pm_ops, ehci_spear_drv_suspend,
  81. ehci_spear_drv_resume);
  82. static u64 spear_ehci_dma_mask = DMA_BIT_MASK(32);
  83. static int spear_ehci_hcd_drv_probe(struct platform_device *pdev)
  84. {
  85. struct usb_hcd *hcd ;
  86. struct spear_ehci *ehci;
  87. struct resource *res;
  88. struct clk *usbh_clk;
  89. const struct hc_driver *driver = &ehci_spear_hc_driver;
  90. int irq, retval;
  91. if (usb_disabled())
  92. return -ENODEV;
  93. irq = platform_get_irq(pdev, 0);
  94. if (irq < 0) {
  95. retval = irq;
  96. goto fail;
  97. }
  98. /*
  99. * Right now device-tree probed devices don't get dma_mask set.
  100. * Since shared usb code relies on it, set it here for now.
  101. * Once we have dma capability bindings this can go away.
  102. */
  103. if (!pdev->dev.dma_mask)
  104. pdev->dev.dma_mask = &spear_ehci_dma_mask;
  105. usbh_clk = devm_clk_get(&pdev->dev, NULL);
  106. if (IS_ERR(usbh_clk)) {
  107. dev_err(&pdev->dev, "Error getting interface clock\n");
  108. retval = PTR_ERR(usbh_clk);
  109. goto fail;
  110. }
  111. hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
  112. if (!hcd) {
  113. retval = -ENOMEM;
  114. goto fail;
  115. }
  116. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  117. if (!res) {
  118. retval = -ENODEV;
  119. goto err_put_hcd;
  120. }
  121. hcd->rsrc_start = res->start;
  122. hcd->rsrc_len = resource_size(res);
  123. if (!devm_request_mem_region(&pdev->dev, hcd->rsrc_start, hcd->rsrc_len,
  124. driver->description)) {
  125. retval = -EBUSY;
  126. goto err_put_hcd;
  127. }
  128. hcd->regs = devm_ioremap(&pdev->dev, hcd->rsrc_start, hcd->rsrc_len);
  129. if (hcd->regs == NULL) {
  130. dev_dbg(&pdev->dev, "error mapping memory\n");
  131. retval = -ENOMEM;
  132. goto err_put_hcd;
  133. }
  134. ehci = (struct spear_ehci *)hcd_to_ehci(hcd);
  135. ehci->clk = usbh_clk;
  136. spear_start_ehci(ehci);
  137. retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
  138. if (retval)
  139. goto err_stop_ehci;
  140. return retval;
  141. err_stop_ehci:
  142. spear_stop_ehci(ehci);
  143. err_put_hcd:
  144. usb_put_hcd(hcd);
  145. fail:
  146. dev_err(&pdev->dev, "init fail, %d\n", retval);
  147. return retval ;
  148. }
  149. static int spear_ehci_hcd_drv_remove(struct platform_device *pdev)
  150. {
  151. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  152. struct spear_ehci *ehci_p = to_spear_ehci(hcd);
  153. if (!hcd)
  154. return 0;
  155. if (in_interrupt())
  156. BUG();
  157. usb_remove_hcd(hcd);
  158. if (ehci_p->clk)
  159. spear_stop_ehci(ehci_p);
  160. usb_put_hcd(hcd);
  161. return 0;
  162. }
  163. static struct of_device_id spear_ehci_id_table[] = {
  164. { .compatible = "st,spear600-ehci", },
  165. { },
  166. };
  167. static struct platform_driver spear_ehci_hcd_driver = {
  168. .probe = spear_ehci_hcd_drv_probe,
  169. .remove = spear_ehci_hcd_drv_remove,
  170. .shutdown = usb_hcd_platform_shutdown,
  171. .driver = {
  172. .name = "spear-ehci",
  173. .bus = &platform_bus_type,
  174. .pm = &ehci_spear_pm_ops,
  175. .of_match_table = of_match_ptr(spear_ehci_id_table),
  176. }
  177. };
  178. MODULE_ALIAS("platform:spear-ehci");