ehci-spear.c 4.5 KB

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