ehci-spear.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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/dma-mapping.h>
  15. #include <linux/io.h>
  16. #include <linux/jiffies.h>
  17. #include <linux/kernel.h>
  18. #include <linux/module.h>
  19. #include <linux/of.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/pm.h>
  22. #include <linux/usb.h>
  23. #include <linux/usb/hcd.h>
  24. #include "ehci.h"
  25. #define DRIVER_DESC "EHCI SPEAr driver"
  26. static const char hcd_name[] = "SPEAr-ehci";
  27. struct spear_ehci {
  28. struct clk *clk;
  29. };
  30. #define to_spear_ehci(hcd) (struct spear_ehci *)(hcd_to_ehci(hcd)->priv)
  31. static struct hc_driver __read_mostly ehci_spear_hc_driver;
  32. #ifdef CONFIG_PM_SLEEP
  33. static int ehci_spear_drv_suspend(struct device *dev)
  34. {
  35. struct usb_hcd *hcd = dev_get_drvdata(dev);
  36. bool do_wakeup = device_may_wakeup(dev);
  37. return ehci_suspend(hcd, do_wakeup);
  38. }
  39. static int ehci_spear_drv_resume(struct device *dev)
  40. {
  41. struct usb_hcd *hcd = dev_get_drvdata(dev);
  42. ehci_resume(hcd, false);
  43. return 0;
  44. }
  45. #endif /* CONFIG_PM_SLEEP */
  46. static SIMPLE_DEV_PM_OPS(ehci_spear_pm_ops, ehci_spear_drv_suspend,
  47. ehci_spear_drv_resume);
  48. static int spear_ehci_hcd_drv_probe(struct platform_device *pdev)
  49. {
  50. struct usb_hcd *hcd ;
  51. struct spear_ehci *sehci;
  52. struct resource *res;
  53. struct clk *usbh_clk;
  54. const struct hc_driver *driver = &ehci_spear_hc_driver;
  55. int irq, retval;
  56. if (usb_disabled())
  57. return -ENODEV;
  58. irq = platform_get_irq(pdev, 0);
  59. if (irq < 0) {
  60. retval = irq;
  61. goto fail;
  62. }
  63. /*
  64. * Right now device-tree probed devices don't get dma_mask set.
  65. * Since shared usb code relies on it, set it here for now.
  66. * Once we have dma capability bindings this can go away.
  67. */
  68. if (!pdev->dev.dma_mask)
  69. pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
  70. retval = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
  71. if (retval)
  72. goto fail;
  73. usbh_clk = devm_clk_get(&pdev->dev, NULL);
  74. if (IS_ERR(usbh_clk)) {
  75. dev_err(&pdev->dev, "Error getting interface clock\n");
  76. retval = PTR_ERR(usbh_clk);
  77. goto fail;
  78. }
  79. hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
  80. if (!hcd) {
  81. retval = -ENOMEM;
  82. goto fail;
  83. }
  84. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  85. if (!res) {
  86. retval = -ENODEV;
  87. goto err_put_hcd;
  88. }
  89. hcd->rsrc_start = res->start;
  90. hcd->rsrc_len = resource_size(res);
  91. if (!devm_request_mem_region(&pdev->dev, hcd->rsrc_start, hcd->rsrc_len,
  92. driver->description)) {
  93. retval = -EBUSY;
  94. goto err_put_hcd;
  95. }
  96. hcd->regs = devm_ioremap(&pdev->dev, hcd->rsrc_start, hcd->rsrc_len);
  97. if (hcd->regs == NULL) {
  98. dev_dbg(&pdev->dev, "error mapping memory\n");
  99. retval = -ENOMEM;
  100. goto err_put_hcd;
  101. }
  102. sehci = to_spear_ehci(hcd);
  103. sehci->clk = usbh_clk;
  104. /* registers start at offset 0x0 */
  105. hcd_to_ehci(hcd)->caps = hcd->regs;
  106. clk_prepare_enable(sehci->clk);
  107. retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
  108. if (retval)
  109. goto err_stop_ehci;
  110. return retval;
  111. err_stop_ehci:
  112. clk_disable_unprepare(sehci->clk);
  113. err_put_hcd:
  114. usb_put_hcd(hcd);
  115. fail:
  116. dev_err(&pdev->dev, "init fail, %d\n", retval);
  117. return retval ;
  118. }
  119. static int spear_ehci_hcd_drv_remove(struct platform_device *pdev)
  120. {
  121. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  122. struct spear_ehci *sehci = to_spear_ehci(hcd);
  123. usb_remove_hcd(hcd);
  124. if (sehci->clk)
  125. clk_disable_unprepare(sehci->clk);
  126. usb_put_hcd(hcd);
  127. return 0;
  128. }
  129. static struct of_device_id spear_ehci_id_table[] = {
  130. { .compatible = "st,spear600-ehci", },
  131. { },
  132. };
  133. static struct platform_driver spear_ehci_hcd_driver = {
  134. .probe = spear_ehci_hcd_drv_probe,
  135. .remove = spear_ehci_hcd_drv_remove,
  136. .shutdown = usb_hcd_platform_shutdown,
  137. .driver = {
  138. .name = "spear-ehci",
  139. .bus = &platform_bus_type,
  140. .pm = &ehci_spear_pm_ops,
  141. .of_match_table = spear_ehci_id_table,
  142. }
  143. };
  144. static const struct ehci_driver_overrides spear_overrides __initdata = {
  145. .extra_priv_size = sizeof(struct spear_ehci),
  146. };
  147. static int __init ehci_spear_init(void)
  148. {
  149. if (usb_disabled())
  150. return -ENODEV;
  151. pr_info("%s: " DRIVER_DESC "\n", hcd_name);
  152. ehci_init_driver(&ehci_spear_hc_driver, &spear_overrides);
  153. return platform_driver_register(&spear_ehci_hcd_driver);
  154. }
  155. module_init(ehci_spear_init);
  156. static void __exit ehci_spear_cleanup(void)
  157. {
  158. platform_driver_unregister(&spear_ehci_hcd_driver);
  159. }
  160. module_exit(ehci_spear_cleanup);
  161. MODULE_DESCRIPTION(DRIVER_DESC);
  162. MODULE_ALIAS("platform:spear-ehci");
  163. MODULE_AUTHOR("Deepak Sikri");
  164. MODULE_LICENSE("GPL");