ehci-platform.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /*
  2. * Generic platform ehci driver
  3. *
  4. * Copyright 2007 Steven Brown <sbrown@cortland.com>
  5. * Copyright 2010-2012 Hauke Mehrtens <hauke@hauke-m.de>
  6. *
  7. * Derived from the ohci-ssb driver
  8. * Copyright 2007 Michael Buesch <m@bues.ch>
  9. *
  10. * Derived from the EHCI-PCI driver
  11. * Copyright (c) 2000-2004 by David Brownell
  12. *
  13. * Derived from the ohci-pci driver
  14. * Copyright 1999 Roman Weissgaerber
  15. * Copyright 2000-2002 David Brownell
  16. * Copyright 1999 Linus Torvalds
  17. * Copyright 1999 Gregory P. Smith
  18. *
  19. * Licensed under the GNU/GPL. See COPYING for details.
  20. */
  21. #include <linux/dma-mapping.h>
  22. #include <linux/err.h>
  23. #include <linux/kernel.h>
  24. #include <linux/hrtimer.h>
  25. #include <linux/io.h>
  26. #include <linux/module.h>
  27. #include <linux/of.h>
  28. #include <linux/platform_device.h>
  29. #include <linux/usb.h>
  30. #include <linux/usb/hcd.h>
  31. #include <linux/usb/ehci_pdriver.h>
  32. #include "ehci.h"
  33. #define DRIVER_DESC "EHCI generic platform driver"
  34. static const char hcd_name[] = "ehci-platform";
  35. static int ehci_platform_reset(struct usb_hcd *hcd)
  36. {
  37. struct platform_device *pdev = to_platform_device(hcd->self.controller);
  38. struct usb_ehci_pdata *pdata = pdev->dev.platform_data;
  39. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  40. int retval;
  41. hcd->has_tt = pdata->has_tt;
  42. ehci->has_synopsys_hc_bug = pdata->has_synopsys_hc_bug;
  43. ehci->big_endian_desc = pdata->big_endian_desc;
  44. ehci->big_endian_mmio = pdata->big_endian_mmio;
  45. if (pdata->pre_setup) {
  46. retval = pdata->pre_setup(hcd);
  47. if (retval < 0)
  48. return retval;
  49. }
  50. ehci->caps = hcd->regs + pdata->caps_offset;
  51. retval = ehci_setup(hcd);
  52. if (retval)
  53. return retval;
  54. if (pdata->no_io_watchdog)
  55. ehci->need_io_watchdog = 0;
  56. return 0;
  57. }
  58. static struct hc_driver __read_mostly ehci_platform_hc_driver;
  59. static const struct ehci_driver_overrides platform_overrides __initconst = {
  60. .reset = ehci_platform_reset,
  61. };
  62. static struct usb_ehci_pdata ehci_platform_defaults;
  63. static int ehci_platform_probe(struct platform_device *dev)
  64. {
  65. struct usb_hcd *hcd;
  66. struct resource *res_mem;
  67. struct usb_ehci_pdata *pdata;
  68. int irq;
  69. int err = -ENOMEM;
  70. if (usb_disabled())
  71. return -ENODEV;
  72. /*
  73. * use reasonable defaults so platforms don't have to provide these.
  74. * with DT probing on ARM, none of these are set.
  75. */
  76. if (!dev->dev.platform_data)
  77. dev->dev.platform_data = &ehci_platform_defaults;
  78. if (!dev->dev.dma_mask)
  79. dev->dev.dma_mask = &dev->dev.coherent_dma_mask;
  80. if (!dev->dev.coherent_dma_mask)
  81. dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
  82. pdata = dev->dev.platform_data;
  83. irq = platform_get_irq(dev, 0);
  84. if (irq < 0) {
  85. dev_err(&dev->dev, "no irq provided");
  86. return irq;
  87. }
  88. res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
  89. if (!res_mem) {
  90. dev_err(&dev->dev, "no memory resource provided");
  91. return -ENXIO;
  92. }
  93. if (pdata->power_on) {
  94. err = pdata->power_on(dev);
  95. if (err < 0)
  96. return err;
  97. }
  98. hcd = usb_create_hcd(&ehci_platform_hc_driver, &dev->dev,
  99. dev_name(&dev->dev));
  100. if (!hcd) {
  101. err = -ENOMEM;
  102. goto err_power;
  103. }
  104. hcd->rsrc_start = res_mem->start;
  105. hcd->rsrc_len = resource_size(res_mem);
  106. hcd->regs = devm_ioremap_resource(&dev->dev, res_mem);
  107. if (IS_ERR(hcd->regs)) {
  108. err = PTR_ERR(hcd->regs);
  109. goto err_put_hcd;
  110. }
  111. err = usb_add_hcd(hcd, irq, IRQF_SHARED);
  112. if (err)
  113. goto err_put_hcd;
  114. platform_set_drvdata(dev, hcd);
  115. return err;
  116. err_put_hcd:
  117. usb_put_hcd(hcd);
  118. err_power:
  119. if (pdata->power_off)
  120. pdata->power_off(dev);
  121. return err;
  122. }
  123. static int ehci_platform_remove(struct platform_device *dev)
  124. {
  125. struct usb_hcd *hcd = platform_get_drvdata(dev);
  126. struct usb_ehci_pdata *pdata = dev->dev.platform_data;
  127. usb_remove_hcd(hcd);
  128. usb_put_hcd(hcd);
  129. if (pdata->power_off)
  130. pdata->power_off(dev);
  131. if (pdata == &ehci_platform_defaults)
  132. dev->dev.platform_data = NULL;
  133. return 0;
  134. }
  135. #ifdef CONFIG_PM
  136. static int ehci_platform_suspend(struct device *dev)
  137. {
  138. struct usb_hcd *hcd = dev_get_drvdata(dev);
  139. struct usb_ehci_pdata *pdata = dev->platform_data;
  140. struct platform_device *pdev =
  141. container_of(dev, struct platform_device, dev);
  142. bool do_wakeup = device_may_wakeup(dev);
  143. int ret;
  144. ret = ehci_suspend(hcd, do_wakeup);
  145. if (pdata->power_suspend)
  146. pdata->power_suspend(pdev);
  147. return ret;
  148. }
  149. static int ehci_platform_resume(struct device *dev)
  150. {
  151. struct usb_hcd *hcd = dev_get_drvdata(dev);
  152. struct usb_ehci_pdata *pdata = dev->platform_data;
  153. struct platform_device *pdev =
  154. container_of(dev, struct platform_device, dev);
  155. if (pdata->power_on) {
  156. int err = pdata->power_on(pdev);
  157. if (err < 0)
  158. return err;
  159. }
  160. ehci_resume(hcd, false);
  161. return 0;
  162. }
  163. #else /* !CONFIG_PM */
  164. #define ehci_platform_suspend NULL
  165. #define ehci_platform_resume NULL
  166. #endif /* CONFIG_PM */
  167. static const struct of_device_id vt8500_ehci_ids[] = {
  168. { .compatible = "via,vt8500-ehci", },
  169. { .compatible = "wm,prizm-ehci", },
  170. {}
  171. };
  172. static const struct platform_device_id ehci_platform_table[] = {
  173. { "ehci-platform", 0 },
  174. { }
  175. };
  176. MODULE_DEVICE_TABLE(platform, ehci_platform_table);
  177. static const struct dev_pm_ops ehci_platform_pm_ops = {
  178. .suspend = ehci_platform_suspend,
  179. .resume = ehci_platform_resume,
  180. };
  181. static struct platform_driver ehci_platform_driver = {
  182. .id_table = ehci_platform_table,
  183. .probe = ehci_platform_probe,
  184. .remove = ehci_platform_remove,
  185. .shutdown = usb_hcd_platform_shutdown,
  186. .driver = {
  187. .owner = THIS_MODULE,
  188. .name = "ehci-platform",
  189. .pm = &ehci_platform_pm_ops,
  190. .of_match_table = vt8500_ehci_ids,
  191. }
  192. };
  193. static int __init ehci_platform_init(void)
  194. {
  195. if (usb_disabled())
  196. return -ENODEV;
  197. pr_info("%s: " DRIVER_DESC "\n", hcd_name);
  198. ehci_init_driver(&ehci_platform_hc_driver, &platform_overrides);
  199. return platform_driver_register(&ehci_platform_driver);
  200. }
  201. module_init(ehci_platform_init);
  202. static void __exit ehci_platform_cleanup(void)
  203. {
  204. platform_driver_unregister(&ehci_platform_driver);
  205. }
  206. module_exit(ehci_platform_cleanup);
  207. MODULE_DESCRIPTION(DRIVER_DESC);
  208. MODULE_AUTHOR("Hauke Mehrtens");
  209. MODULE_AUTHOR("Alan Stern");
  210. MODULE_LICENSE("GPL");