ohci-spear.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. * OHCI HCD (Host Controller Driver) for USB.
  3. *
  4. * Copyright (C) 2010 ST Microelectronics.
  5. * Deepak Sikri<deepak.sikri@st.com>
  6. *
  7. * Based on various ohci-*.c drivers
  8. *
  9. * This file is licensed under the terms of the GNU General Public
  10. * License version 2. This program is licensed "as is" without any
  11. * warranty of any kind, whether express or implied.
  12. */
  13. #include <linux/clk.h>
  14. #include <linux/dma-mapping.h>
  15. #include <linux/io.h>
  16. #include <linux/kernel.h>
  17. #include <linux/module.h>
  18. #include <linux/of.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/signal.h>
  21. #include <linux/usb.h>
  22. #include <linux/usb/hcd.h>
  23. #include "ohci.h"
  24. #define DRIVER_DESC "OHCI SPEAr driver"
  25. static const char hcd_name[] = "SPEAr-ohci";
  26. struct spear_ohci {
  27. struct clk *clk;
  28. };
  29. #define to_spear_ohci(hcd) (struct spear_ohci *)(hcd_to_ohci(hcd)->priv)
  30. static struct hc_driver __read_mostly ohci_spear_hc_driver;
  31. static int spear_ohci_hcd_drv_probe(struct platform_device *pdev)
  32. {
  33. const struct hc_driver *driver = &ohci_spear_hc_driver;
  34. struct ohci_hcd *ohci;
  35. struct usb_hcd *hcd = NULL;
  36. struct clk *usbh_clk;
  37. struct spear_ohci *sohci_p;
  38. struct resource *res;
  39. int retval, irq;
  40. irq = platform_get_irq(pdev, 0);
  41. if (irq < 0) {
  42. retval = irq;
  43. goto fail;
  44. }
  45. /*
  46. * Right now device-tree probed devices don't get dma_mask set.
  47. * Since shared usb code relies on it, set it here for now.
  48. * Once we have dma capability bindings this can go away.
  49. */
  50. if (!pdev->dev.dma_mask)
  51. pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
  52. if (!pdev->dev.coherent_dma_mask)
  53. pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
  54. usbh_clk = devm_clk_get(&pdev->dev, NULL);
  55. if (IS_ERR(usbh_clk)) {
  56. dev_err(&pdev->dev, "Error getting interface clock\n");
  57. retval = PTR_ERR(usbh_clk);
  58. goto fail;
  59. }
  60. hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
  61. if (!hcd) {
  62. retval = -ENOMEM;
  63. goto fail;
  64. }
  65. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  66. if (!res) {
  67. retval = -ENODEV;
  68. goto err_put_hcd;
  69. }
  70. hcd->rsrc_start = pdev->resource[0].start;
  71. hcd->rsrc_len = resource_size(res);
  72. if (!devm_request_mem_region(&pdev->dev, hcd->rsrc_start, hcd->rsrc_len,
  73. hcd_name)) {
  74. dev_dbg(&pdev->dev, "request_mem_region failed\n");
  75. retval = -EBUSY;
  76. goto err_put_hcd;
  77. }
  78. hcd->regs = devm_ioremap(&pdev->dev, hcd->rsrc_start, hcd->rsrc_len);
  79. if (!hcd->regs) {
  80. dev_dbg(&pdev->dev, "ioremap failed\n");
  81. retval = -ENOMEM;
  82. goto err_put_hcd;
  83. }
  84. sohci_p = to_spear_ohci(hcd);
  85. sohci_p->clk = usbh_clk;
  86. clk_prepare_enable(sohci_p->clk);
  87. ohci = hcd_to_ohci(hcd);
  88. retval = usb_add_hcd(hcd, platform_get_irq(pdev, 0), 0);
  89. if (retval == 0)
  90. return retval;
  91. clk_disable_unprepare(sohci_p->clk);
  92. err_put_hcd:
  93. usb_put_hcd(hcd);
  94. fail:
  95. dev_err(&pdev->dev, "init fail, %d\n", retval);
  96. return retval;
  97. }
  98. static int spear_ohci_hcd_drv_remove(struct platform_device *pdev)
  99. {
  100. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  101. struct spear_ohci *sohci_p = to_spear_ohci(hcd);
  102. usb_remove_hcd(hcd);
  103. if (sohci_p->clk)
  104. clk_disable_unprepare(sohci_p->clk);
  105. usb_put_hcd(hcd);
  106. return 0;
  107. }
  108. #if defined(CONFIG_PM)
  109. static int spear_ohci_hcd_drv_suspend(struct platform_device *dev,
  110. pm_message_t message)
  111. {
  112. struct usb_hcd *hcd = platform_get_drvdata(dev);
  113. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  114. struct spear_ohci *sohci_p = to_spear_ohci(hcd);
  115. if (time_before(jiffies, ohci->next_statechange))
  116. msleep(5);
  117. ohci->next_statechange = jiffies;
  118. clk_disable_unprepare(sohci_p->clk);
  119. return 0;
  120. }
  121. static int spear_ohci_hcd_drv_resume(struct platform_device *dev)
  122. {
  123. struct usb_hcd *hcd = platform_get_drvdata(dev);
  124. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  125. struct spear_ohci *sohci_p = to_spear_ohci(hcd);
  126. if (time_before(jiffies, ohci->next_statechange))
  127. msleep(5);
  128. ohci->next_statechange = jiffies;
  129. clk_prepare_enable(sohci_p->clk);
  130. ohci_resume(hcd, false);
  131. return 0;
  132. }
  133. #endif
  134. static struct of_device_id spear_ohci_id_table[] = {
  135. { .compatible = "st,spear600-ohci", },
  136. { },
  137. };
  138. /* Driver definition to register with the platform bus */
  139. static struct platform_driver spear_ohci_hcd_driver = {
  140. .probe = spear_ohci_hcd_drv_probe,
  141. .remove = spear_ohci_hcd_drv_remove,
  142. #ifdef CONFIG_PM
  143. .suspend = spear_ohci_hcd_drv_suspend,
  144. .resume = spear_ohci_hcd_drv_resume,
  145. #endif
  146. .driver = {
  147. .owner = THIS_MODULE,
  148. .name = "spear-ohci",
  149. .of_match_table = spear_ohci_id_table,
  150. },
  151. };
  152. static const struct ohci_driver_overrides spear_overrides __initconst = {
  153. .extra_priv_size = sizeof(struct spear_ohci),
  154. };
  155. static int __init ohci_spear_init(void)
  156. {
  157. if (usb_disabled())
  158. return -ENODEV;
  159. pr_info("%s: " DRIVER_DESC "\n", hcd_name);
  160. ohci_init_driver(&ohci_spear_hc_driver, &spear_overrides);
  161. return platform_driver_register(&spear_ohci_hcd_driver);
  162. }
  163. module_init(ohci_spear_init);
  164. static void __exit ohci_spear_cleanup(void)
  165. {
  166. platform_driver_unregister(&spear_ohci_hcd_driver);
  167. }
  168. module_exit(ohci_spear_cleanup);
  169. MODULE_DESCRIPTION(DRIVER_DESC);
  170. MODULE_AUTHOR("Deepak Sikri");
  171. MODULE_LICENSE("GPL v2");
  172. MODULE_ALIAS("platform:spear-ohci");