ehci-platform.c 5.1 KB

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