ehci-platform.c 5.8 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 = dev_get_platdata(&pdev->dev);
  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;
  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_get_platdata(&dev->dev))
  77. dev->dev.platform_data = &ehci_platform_defaults;
  78. err = dma_coerce_mask_and_coherent(&dev->dev, DMA_BIT_MASK(32));
  79. if (err)
  80. return err;
  81. pdata = dev_get_platdata(&dev->dev);
  82. irq = platform_get_irq(dev, 0);
  83. if (irq < 0) {
  84. dev_err(&dev->dev, "no irq provided");
  85. return irq;
  86. }
  87. res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
  88. if (!res_mem) {
  89. dev_err(&dev->dev, "no memory resource provided");
  90. return -ENXIO;
  91. }
  92. if (pdata->power_on) {
  93. err = pdata->power_on(dev);
  94. if (err < 0)
  95. return err;
  96. }
  97. hcd = usb_create_hcd(&ehci_platform_hc_driver, &dev->dev,
  98. dev_name(&dev->dev));
  99. if (!hcd) {
  100. err = -ENOMEM;
  101. goto err_power;
  102. }
  103. hcd->rsrc_start = res_mem->start;
  104. hcd->rsrc_len = resource_size(res_mem);
  105. hcd->regs = devm_ioremap_resource(&dev->dev, res_mem);
  106. if (IS_ERR(hcd->regs)) {
  107. err = PTR_ERR(hcd->regs);
  108. goto err_put_hcd;
  109. }
  110. err = usb_add_hcd(hcd, irq, IRQF_SHARED);
  111. if (err)
  112. goto err_put_hcd;
  113. platform_set_drvdata(dev, hcd);
  114. return err;
  115. err_put_hcd:
  116. usb_put_hcd(hcd);
  117. err_power:
  118. if (pdata->power_off)
  119. pdata->power_off(dev);
  120. return err;
  121. }
  122. static int ehci_platform_remove(struct platform_device *dev)
  123. {
  124. struct usb_hcd *hcd = platform_get_drvdata(dev);
  125. struct usb_ehci_pdata *pdata = dev_get_platdata(&dev->dev);
  126. usb_remove_hcd(hcd);
  127. usb_put_hcd(hcd);
  128. if (pdata->power_off)
  129. pdata->power_off(dev);
  130. if (pdata == &ehci_platform_defaults)
  131. dev->dev.platform_data = NULL;
  132. return 0;
  133. }
  134. #ifdef CONFIG_PM
  135. static int ehci_platform_suspend(struct device *dev)
  136. {
  137. struct usb_hcd *hcd = dev_get_drvdata(dev);
  138. struct usb_ehci_pdata *pdata = dev_get_platdata(dev);
  139. struct platform_device *pdev =
  140. container_of(dev, struct platform_device, dev);
  141. bool do_wakeup = device_may_wakeup(dev);
  142. int ret;
  143. ret = ehci_suspend(hcd, do_wakeup);
  144. if (pdata->power_suspend)
  145. pdata->power_suspend(pdev);
  146. return ret;
  147. }
  148. static int ehci_platform_resume(struct device *dev)
  149. {
  150. struct usb_hcd *hcd = dev_get_drvdata(dev);
  151. struct usb_ehci_pdata *pdata = dev_get_platdata(dev);
  152. struct platform_device *pdev =
  153. container_of(dev, struct platform_device, dev);
  154. if (pdata->power_on) {
  155. int err = pdata->power_on(pdev);
  156. if (err < 0)
  157. return err;
  158. }
  159. ehci_resume(hcd, false);
  160. return 0;
  161. }
  162. #else /* !CONFIG_PM */
  163. #define ehci_platform_suspend NULL
  164. #define ehci_platform_resume NULL
  165. #endif /* CONFIG_PM */
  166. static const struct of_device_id vt8500_ehci_ids[] = {
  167. { .compatible = "via,vt8500-ehci", },
  168. { .compatible = "wm,prizm-ehci", },
  169. {}
  170. };
  171. static const struct platform_device_id ehci_platform_table[] = {
  172. { "ehci-platform", 0 },
  173. { }
  174. };
  175. MODULE_DEVICE_TABLE(platform, ehci_platform_table);
  176. static const struct dev_pm_ops ehci_platform_pm_ops = {
  177. .suspend = ehci_platform_suspend,
  178. .resume = ehci_platform_resume,
  179. };
  180. static struct platform_driver ehci_platform_driver = {
  181. .id_table = ehci_platform_table,
  182. .probe = ehci_platform_probe,
  183. .remove = ehci_platform_remove,
  184. .shutdown = usb_hcd_platform_shutdown,
  185. .driver = {
  186. .owner = THIS_MODULE,
  187. .name = "ehci-platform",
  188. .pm = &ehci_platform_pm_ops,
  189. .of_match_table = vt8500_ehci_ids,
  190. }
  191. };
  192. static int __init ehci_platform_init(void)
  193. {
  194. if (usb_disabled())
  195. return -ENODEV;
  196. pr_info("%s: " DRIVER_DESC "\n", hcd_name);
  197. ehci_init_driver(&ehci_platform_hc_driver, &platform_overrides);
  198. return platform_driver_register(&ehci_platform_driver);
  199. }
  200. module_init(ehci_platform_init);
  201. static void __exit ehci_platform_cleanup(void)
  202. {
  203. platform_driver_unregister(&ehci_platform_driver);
  204. }
  205. module_exit(ehci_platform_cleanup);
  206. MODULE_DESCRIPTION(DRIVER_DESC);
  207. MODULE_AUTHOR("Hauke Mehrtens");
  208. MODULE_AUTHOR("Alan Stern");
  209. MODULE_LICENSE("GPL");