ehci-spear.c 4.2 KB

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