ehci-platform.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. platform_set_drvdata(dev, NULL);
  130. if (pdata->power_off)
  131. pdata->power_off(dev);
  132. if (pdata == &ehci_platform_defaults)
  133. dev->dev.platform_data = NULL;
  134. return 0;
  135. }
  136. #ifdef CONFIG_PM
  137. static int ehci_platform_suspend(struct device *dev)
  138. {
  139. struct usb_hcd *hcd = dev_get_drvdata(dev);
  140. struct usb_ehci_pdata *pdata = dev->platform_data;
  141. struct platform_device *pdev =
  142. container_of(dev, struct platform_device, dev);
  143. bool do_wakeup = device_may_wakeup(dev);
  144. int ret;
  145. ret = ehci_suspend(hcd, do_wakeup);
  146. if (pdata->power_suspend)
  147. pdata->power_suspend(pdev);
  148. return ret;
  149. }
  150. static int ehci_platform_resume(struct device *dev)
  151. {
  152. struct usb_hcd *hcd = dev_get_drvdata(dev);
  153. struct usb_ehci_pdata *pdata = dev->platform_data;
  154. struct platform_device *pdev =
  155. container_of(dev, struct platform_device, dev);
  156. if (pdata->power_on) {
  157. int err = pdata->power_on(pdev);
  158. if (err < 0)
  159. return err;
  160. }
  161. ehci_resume(hcd, false);
  162. return 0;
  163. }
  164. #else /* !CONFIG_PM */
  165. #define ehci_platform_suspend NULL
  166. #define ehci_platform_resume NULL
  167. #endif /* CONFIG_PM */
  168. static const struct of_device_id vt8500_ehci_ids[] = {
  169. { .compatible = "via,vt8500-ehci", },
  170. { .compatible = "wm,prizm-ehci", },
  171. {}
  172. };
  173. static const struct platform_device_id ehci_platform_table[] = {
  174. { "ehci-platform", 0 },
  175. { }
  176. };
  177. MODULE_DEVICE_TABLE(platform, ehci_platform_table);
  178. static const struct dev_pm_ops ehci_platform_pm_ops = {
  179. .suspend = ehci_platform_suspend,
  180. .resume = ehci_platform_resume,
  181. };
  182. static struct platform_driver ehci_platform_driver = {
  183. .id_table = ehci_platform_table,
  184. .probe = ehci_platform_probe,
  185. .remove = ehci_platform_remove,
  186. .shutdown = usb_hcd_platform_shutdown,
  187. .driver = {
  188. .owner = THIS_MODULE,
  189. .name = "ehci-platform",
  190. .pm = &ehci_platform_pm_ops,
  191. .of_match_table = of_match_ptr(vt8500_ehci_ids),
  192. }
  193. };
  194. static int __init ehci_platform_init(void)
  195. {
  196. if (usb_disabled())
  197. return -ENODEV;
  198. pr_info("%s: " DRIVER_DESC "\n", hcd_name);
  199. ehci_init_driver(&ehci_platform_hc_driver, &platform_overrides);
  200. return platform_driver_register(&ehci_platform_driver);
  201. }
  202. module_init(ehci_platform_init);
  203. static void __exit ehci_platform_cleanup(void)
  204. {
  205. platform_driver_unregister(&ehci_platform_driver);
  206. }
  207. module_exit(ehci_platform_cleanup);
  208. MODULE_DESCRIPTION(DRIVER_DESC);
  209. MODULE_AUTHOR("Hauke Mehrtens");
  210. MODULE_AUTHOR("Alan Stern");
  211. MODULE_LICENSE("GPL");