ehci-spear.c 4.1 KB

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