ehci-spear.c 4.3 KB

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