ehci-platform.c 5.1 KB

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