ehci-platform.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. ehci->caps = hcd->regs + pdata->caps_offset;
  46. retval = ehci_setup(hcd);
  47. if (retval)
  48. return retval;
  49. if (pdata->no_io_watchdog)
  50. ehci->need_io_watchdog = 0;
  51. return 0;
  52. }
  53. static struct hc_driver __read_mostly ehci_platform_hc_driver;
  54. static const struct ehci_driver_overrides platform_overrides __initconst = {
  55. .reset = ehci_platform_reset,
  56. };
  57. static struct usb_ehci_pdata ehci_platform_defaults;
  58. static int ehci_platform_probe(struct platform_device *dev)
  59. {
  60. struct usb_hcd *hcd;
  61. struct resource *res_mem;
  62. struct usb_ehci_pdata *pdata;
  63. int irq;
  64. int err = -ENOMEM;
  65. if (usb_disabled())
  66. return -ENODEV;
  67. /*
  68. * use reasonable defaults so platforms don't have to provide these.
  69. * with DT probing on ARM, none of these are set.
  70. */
  71. if (!dev->dev.platform_data)
  72. dev->dev.platform_data = &ehci_platform_defaults;
  73. if (!dev->dev.dma_mask)
  74. dev->dev.dma_mask = &dev->dev.coherent_dma_mask;
  75. if (!dev->dev.coherent_dma_mask)
  76. dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
  77. pdata = dev->dev.platform_data;
  78. irq = platform_get_irq(dev, 0);
  79. if (irq < 0) {
  80. dev_err(&dev->dev, "no irq provided");
  81. return irq;
  82. }
  83. res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
  84. if (!res_mem) {
  85. dev_err(&dev->dev, "no memory resource provided");
  86. return -ENXIO;
  87. }
  88. if (pdata->power_on) {
  89. err = pdata->power_on(dev);
  90. if (err < 0)
  91. return err;
  92. }
  93. hcd = usb_create_hcd(&ehci_platform_hc_driver, &dev->dev,
  94. dev_name(&dev->dev));
  95. if (!hcd) {
  96. err = -ENOMEM;
  97. goto err_power;
  98. }
  99. hcd->rsrc_start = res_mem->start;
  100. hcd->rsrc_len = resource_size(res_mem);
  101. hcd->regs = devm_ioremap_resource(&dev->dev, res_mem);
  102. if (IS_ERR(hcd->regs)) {
  103. err = PTR_ERR(hcd->regs);
  104. goto err_put_hcd;
  105. }
  106. err = usb_add_hcd(hcd, irq, IRQF_SHARED);
  107. if (err)
  108. goto err_put_hcd;
  109. platform_set_drvdata(dev, hcd);
  110. return err;
  111. err_put_hcd:
  112. usb_put_hcd(hcd);
  113. err_power:
  114. if (pdata->power_off)
  115. pdata->power_off(dev);
  116. return err;
  117. }
  118. static int ehci_platform_remove(struct platform_device *dev)
  119. {
  120. struct usb_hcd *hcd = platform_get_drvdata(dev);
  121. struct usb_ehci_pdata *pdata = dev->dev.platform_data;
  122. usb_remove_hcd(hcd);
  123. usb_put_hcd(hcd);
  124. if (pdata->power_off)
  125. pdata->power_off(dev);
  126. if (pdata == &ehci_platform_defaults)
  127. dev->dev.platform_data = NULL;
  128. return 0;
  129. }
  130. #ifdef CONFIG_PM
  131. static int ehci_platform_suspend(struct device *dev)
  132. {
  133. struct usb_hcd *hcd = dev_get_drvdata(dev);
  134. struct usb_ehci_pdata *pdata = dev->platform_data;
  135. struct platform_device *pdev =
  136. container_of(dev, struct platform_device, dev);
  137. bool do_wakeup = device_may_wakeup(dev);
  138. int ret;
  139. ret = ehci_suspend(hcd, do_wakeup);
  140. if (pdata->power_suspend)
  141. pdata->power_suspend(pdev);
  142. return ret;
  143. }
  144. static int ehci_platform_resume(struct device *dev)
  145. {
  146. struct usb_hcd *hcd = dev_get_drvdata(dev);
  147. struct usb_ehci_pdata *pdata = dev->platform_data;
  148. struct platform_device *pdev =
  149. container_of(dev, struct platform_device, dev);
  150. if (pdata->power_on) {
  151. int err = pdata->power_on(pdev);
  152. if (err < 0)
  153. return err;
  154. }
  155. ehci_resume(hcd, false);
  156. return 0;
  157. }
  158. #else /* !CONFIG_PM */
  159. #define ehci_platform_suspend NULL
  160. #define ehci_platform_resume NULL
  161. #endif /* CONFIG_PM */
  162. static const struct of_device_id vt8500_ehci_ids[] = {
  163. { .compatible = "via,vt8500-ehci", },
  164. { .compatible = "wm,prizm-ehci", },
  165. {}
  166. };
  167. static const struct platform_device_id ehci_platform_table[] = {
  168. { "ehci-platform", 0 },
  169. { }
  170. };
  171. MODULE_DEVICE_TABLE(platform, ehci_platform_table);
  172. static const struct dev_pm_ops ehci_platform_pm_ops = {
  173. .suspend = ehci_platform_suspend,
  174. .resume = ehci_platform_resume,
  175. };
  176. static struct platform_driver ehci_platform_driver = {
  177. .id_table = ehci_platform_table,
  178. .probe = ehci_platform_probe,
  179. .remove = ehci_platform_remove,
  180. .shutdown = usb_hcd_platform_shutdown,
  181. .driver = {
  182. .owner = THIS_MODULE,
  183. .name = "ehci-platform",
  184. .pm = &ehci_platform_pm_ops,
  185. .of_match_table = of_match_ptr(vt8500_ehci_ids),
  186. }
  187. };
  188. static int __init ehci_platform_init(void)
  189. {
  190. if (usb_disabled())
  191. return -ENODEV;
  192. pr_info("%s: " DRIVER_DESC "\n", hcd_name);
  193. ehci_init_driver(&ehci_platform_hc_driver, &platform_overrides);
  194. return platform_driver_register(&ehci_platform_driver);
  195. }
  196. module_init(ehci_platform_init);
  197. static void __exit ehci_platform_cleanup(void)
  198. {
  199. platform_driver_unregister(&ehci_platform_driver);
  200. }
  201. module_exit(ehci_platform_cleanup);
  202. MODULE_DESCRIPTION(DRIVER_DESC);
  203. MODULE_AUTHOR("Hauke Mehrtens");
  204. MODULE_AUTHOR("Alan Stern");
  205. MODULE_LICENSE("GPL");