ehci-spear.c 4.2 KB

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