ehci-platform.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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/kernel.h>
  22. #include <linux/hrtimer.h>
  23. #include <linux/io.h>
  24. #include <linux/module.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/usb.h>
  27. #include <linux/usb/hcd.h>
  28. #include <linux/usb/ehci_pdriver.h>
  29. #include "ehci.h"
  30. #define DRIVER_DESC "EHCI generic platform driver"
  31. static const char hcd_name[] = "ehci-platform";
  32. static int ehci_platform_reset(struct usb_hcd *hcd)
  33. {
  34. struct platform_device *pdev = to_platform_device(hcd->self.controller);
  35. struct usb_ehci_pdata *pdata = pdev->dev.platform_data;
  36. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  37. int retval;
  38. hcd->has_tt = pdata->has_tt;
  39. ehci->has_synopsys_hc_bug = pdata->has_synopsys_hc_bug;
  40. ehci->big_endian_desc = pdata->big_endian_desc;
  41. ehci->big_endian_mmio = pdata->big_endian_mmio;
  42. ehci->caps = hcd->regs + pdata->caps_offset;
  43. retval = ehci_setup(hcd);
  44. if (retval)
  45. return retval;
  46. if (pdata->no_io_watchdog)
  47. ehci->need_io_watchdog = 0;
  48. return 0;
  49. }
  50. static struct hc_driver __read_mostly ehci_platform_hc_driver;
  51. static const struct ehci_driver_overrides platform_overrides __initdata = {
  52. .reset = ehci_platform_reset,
  53. };
  54. static int ehci_platform_probe(struct platform_device *dev)
  55. {
  56. struct usb_hcd *hcd;
  57. struct resource *res_mem;
  58. struct usb_ehci_pdata *pdata = dev->dev.platform_data;
  59. int irq;
  60. int err = -ENOMEM;
  61. if (!pdata) {
  62. WARN_ON(1);
  63. return -ENODEV;
  64. }
  65. if (usb_disabled())
  66. return -ENODEV;
  67. irq = platform_get_irq(dev, 0);
  68. if (irq < 0) {
  69. dev_err(&dev->dev, "no irq provided");
  70. return irq;
  71. }
  72. res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
  73. if (!res_mem) {
  74. dev_err(&dev->dev, "no memory resource provided");
  75. return -ENXIO;
  76. }
  77. if (pdata->power_on) {
  78. err = pdata->power_on(dev);
  79. if (err < 0)
  80. return err;
  81. }
  82. hcd = usb_create_hcd(&ehci_platform_hc_driver, &dev->dev,
  83. dev_name(&dev->dev));
  84. if (!hcd) {
  85. err = -ENOMEM;
  86. goto err_power;
  87. }
  88. hcd->rsrc_start = res_mem->start;
  89. hcd->rsrc_len = resource_size(res_mem);
  90. hcd->regs = devm_request_and_ioremap(&dev->dev, res_mem);
  91. if (!hcd->regs) {
  92. err = -ENOMEM;
  93. goto err_put_hcd;
  94. }
  95. err = usb_add_hcd(hcd, irq, IRQF_SHARED);
  96. if (err)
  97. goto err_put_hcd;
  98. platform_set_drvdata(dev, hcd);
  99. return err;
  100. err_put_hcd:
  101. usb_put_hcd(hcd);
  102. err_power:
  103. if (pdata->power_off)
  104. pdata->power_off(dev);
  105. return err;
  106. }
  107. static int ehci_platform_remove(struct platform_device *dev)
  108. {
  109. struct usb_hcd *hcd = platform_get_drvdata(dev);
  110. struct usb_ehci_pdata *pdata = dev->dev.platform_data;
  111. usb_remove_hcd(hcd);
  112. usb_put_hcd(hcd);
  113. platform_set_drvdata(dev, NULL);
  114. if (pdata->power_off)
  115. pdata->power_off(dev);
  116. return 0;
  117. }
  118. #ifdef CONFIG_PM
  119. static int ehci_platform_suspend(struct device *dev)
  120. {
  121. struct usb_hcd *hcd = dev_get_drvdata(dev);
  122. struct usb_ehci_pdata *pdata = dev->platform_data;
  123. struct platform_device *pdev =
  124. container_of(dev, struct platform_device, dev);
  125. bool do_wakeup = device_may_wakeup(dev);
  126. int ret;
  127. ret = ehci_suspend(hcd, do_wakeup);
  128. if (pdata->power_suspend)
  129. pdata->power_suspend(pdev);
  130. return ret;
  131. }
  132. static int ehci_platform_resume(struct device *dev)
  133. {
  134. struct usb_hcd *hcd = dev_get_drvdata(dev);
  135. struct usb_ehci_pdata *pdata = dev->platform_data;
  136. struct platform_device *pdev =
  137. container_of(dev, struct platform_device, dev);
  138. if (pdata->power_on) {
  139. int err = pdata->power_on(pdev);
  140. if (err < 0)
  141. return err;
  142. }
  143. ehci_resume(hcd, false);
  144. return 0;
  145. }
  146. #else /* !CONFIG_PM */
  147. #define ehci_platform_suspend NULL
  148. #define ehci_platform_resume NULL
  149. #endif /* CONFIG_PM */
  150. static const struct platform_device_id ehci_platform_table[] = {
  151. { "ehci-platform", 0 },
  152. { }
  153. };
  154. MODULE_DEVICE_TABLE(platform, ehci_platform_table);
  155. static const struct dev_pm_ops ehci_platform_pm_ops = {
  156. .suspend = ehci_platform_suspend,
  157. .resume = ehci_platform_resume,
  158. };
  159. static struct platform_driver ehci_platform_driver = {
  160. .id_table = ehci_platform_table,
  161. .probe = ehci_platform_probe,
  162. .remove = ehci_platform_remove,
  163. .shutdown = usb_hcd_platform_shutdown,
  164. .driver = {
  165. .owner = THIS_MODULE,
  166. .name = "ehci-platform",
  167. .pm = &ehci_platform_pm_ops,
  168. }
  169. };
  170. static int __init ehci_platform_init(void)
  171. {
  172. if (usb_disabled())
  173. return -ENODEV;
  174. pr_info("%s: " DRIVER_DESC "\n", hcd_name);
  175. ehci_init_driver(&ehci_platform_hc_driver, &platform_overrides);
  176. return platform_driver_register(&ehci_platform_driver);
  177. }
  178. module_init(ehci_platform_init);
  179. static void __exit ehci_platform_cleanup(void)
  180. {
  181. platform_driver_unregister(&ehci_platform_driver);
  182. }
  183. module_exit(ehci_platform_cleanup);
  184. MODULE_DESCRIPTION(DRIVER_DESC);
  185. MODULE_AUTHOR("Hauke Mehrtens");
  186. MODULE_AUTHOR("Alan Stern");
  187. MODULE_LICENSE("GPL");