ehci-spear.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. if (!pdev->dev.coherent_dma_mask)
  71. pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
  72. usbh_clk = devm_clk_get(&pdev->dev, NULL);
  73. if (IS_ERR(usbh_clk)) {
  74. dev_err(&pdev->dev, "Error getting interface clock\n");
  75. retval = PTR_ERR(usbh_clk);
  76. goto fail;
  77. }
  78. hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
  79. if (!hcd) {
  80. retval = -ENOMEM;
  81. goto fail;
  82. }
  83. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  84. if (!res) {
  85. retval = -ENODEV;
  86. goto err_put_hcd;
  87. }
  88. hcd->rsrc_start = res->start;
  89. hcd->rsrc_len = resource_size(res);
  90. if (!devm_request_mem_region(&pdev->dev, hcd->rsrc_start, hcd->rsrc_len,
  91. driver->description)) {
  92. retval = -EBUSY;
  93. goto err_put_hcd;
  94. }
  95. hcd->regs = devm_ioremap(&pdev->dev, hcd->rsrc_start, hcd->rsrc_len);
  96. if (hcd->regs == NULL) {
  97. dev_dbg(&pdev->dev, "error mapping memory\n");
  98. retval = -ENOMEM;
  99. goto err_put_hcd;
  100. }
  101. sehci = to_spear_ehci(hcd);
  102. sehci->clk = usbh_clk;
  103. /* registers start at offset 0x0 */
  104. hcd_to_ehci(hcd)->caps = hcd->regs;
  105. clk_prepare_enable(sehci->clk);
  106. retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
  107. if (retval)
  108. goto err_stop_ehci;
  109. return retval;
  110. err_stop_ehci:
  111. clk_disable_unprepare(sehci->clk);
  112. err_put_hcd:
  113. usb_put_hcd(hcd);
  114. fail:
  115. dev_err(&pdev->dev, "init fail, %d\n", retval);
  116. return retval ;
  117. }
  118. static int spear_ehci_hcd_drv_remove(struct platform_device *pdev)
  119. {
  120. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  121. struct spear_ehci *sehci = to_spear_ehci(hcd);
  122. usb_remove_hcd(hcd);
  123. if (sehci->clk)
  124. clk_disable_unprepare(sehci->clk);
  125. usb_put_hcd(hcd);
  126. return 0;
  127. }
  128. static struct of_device_id spear_ehci_id_table[] = {
  129. { .compatible = "st,spear600-ehci", },
  130. { },
  131. };
  132. static struct platform_driver spear_ehci_hcd_driver = {
  133. .probe = spear_ehci_hcd_drv_probe,
  134. .remove = spear_ehci_hcd_drv_remove,
  135. .shutdown = usb_hcd_platform_shutdown,
  136. .driver = {
  137. .name = "spear-ehci",
  138. .bus = &platform_bus_type,
  139. .pm = &ehci_spear_pm_ops,
  140. .of_match_table = spear_ehci_id_table,
  141. }
  142. };
  143. static const struct ehci_driver_overrides spear_overrides __initdata = {
  144. .extra_priv_size = sizeof(struct spear_ehci),
  145. };
  146. static int __init ehci_spear_init(void)
  147. {
  148. if (usb_disabled())
  149. return -ENODEV;
  150. pr_info("%s: " DRIVER_DESC "\n", hcd_name);
  151. ehci_init_driver(&ehci_spear_hc_driver, &spear_overrides);
  152. return platform_driver_register(&spear_ehci_hcd_driver);
  153. }
  154. module_init(ehci_spear_init);
  155. static void __exit ehci_spear_cleanup(void)
  156. {
  157. platform_driver_unregister(&spear_ehci_hcd_driver);
  158. }
  159. module_exit(ehci_spear_cleanup);
  160. MODULE_DESCRIPTION(DRIVER_DESC);
  161. MODULE_ALIAS("platform:spear-ehci");
  162. MODULE_AUTHOR("Deepak Sikri");
  163. MODULE_LICENSE("GPL");