ohci-platform.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*
  2. * Generic platform ohci driver
  3. *
  4. * Copyright 2007 Michael Buesch <m@bues.ch>
  5. * Copyright 2011-2012 Hauke Mehrtens <hauke@hauke-m.de>
  6. *
  7. * Derived from the OCHI-SSB driver
  8. * Derived from the OHCI-PCI driver
  9. * Copyright 1999 Roman Weissgaerber
  10. * Copyright 2000-2002 David Brownell
  11. * Copyright 1999 Linus Torvalds
  12. * Copyright 1999 Gregory P. Smith
  13. *
  14. * Licensed under the GNU/GPL. See COPYING for details.
  15. */
  16. #include <linux/hrtimer.h>
  17. #include <linux/io.h>
  18. #include <linux/kernel.h>
  19. #include <linux/module.h>
  20. #include <linux/err.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/usb/ohci_pdriver.h>
  23. #include <linux/usb.h>
  24. #include <linux/usb/hcd.h>
  25. #include "ohci.h"
  26. #define DRIVER_DESC "OHCI generic platform driver"
  27. static const char hcd_name[] = "ohci-platform";
  28. static int ohci_platform_reset(struct usb_hcd *hcd)
  29. {
  30. struct platform_device *pdev = to_platform_device(hcd->self.controller);
  31. struct usb_ohci_pdata *pdata = dev_get_platdata(&pdev->dev);
  32. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  33. if (pdata->big_endian_desc)
  34. ohci->flags |= OHCI_QUIRK_BE_DESC;
  35. if (pdata->big_endian_mmio)
  36. ohci->flags |= OHCI_QUIRK_BE_MMIO;
  37. if (pdata->no_big_frame_no)
  38. ohci->flags |= OHCI_QUIRK_FRAME_NO;
  39. if (pdata->num_ports)
  40. ohci->num_ports = pdata->num_ports;
  41. return ohci_setup(hcd);
  42. }
  43. static struct hc_driver __read_mostly ohci_platform_hc_driver;
  44. static const struct ohci_driver_overrides platform_overrides __initconst = {
  45. .product_desc = "Generic Platform OHCI controller",
  46. .reset = ohci_platform_reset,
  47. };
  48. static int ohci_platform_probe(struct platform_device *dev)
  49. {
  50. struct usb_hcd *hcd;
  51. struct resource *res_mem;
  52. struct usb_ohci_pdata *pdata = dev_get_platdata(&dev->dev);
  53. int irq;
  54. int err = -ENOMEM;
  55. if (!pdata) {
  56. WARN_ON(1);
  57. return -ENODEV;
  58. }
  59. if (usb_disabled())
  60. return -ENODEV;
  61. irq = platform_get_irq(dev, 0);
  62. if (irq < 0) {
  63. dev_err(&dev->dev, "no irq provided");
  64. return irq;
  65. }
  66. res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
  67. if (!res_mem) {
  68. dev_err(&dev->dev, "no memory resource provided");
  69. return -ENXIO;
  70. }
  71. if (pdata->power_on) {
  72. err = pdata->power_on(dev);
  73. if (err < 0)
  74. return err;
  75. }
  76. hcd = usb_create_hcd(&ohci_platform_hc_driver, &dev->dev,
  77. dev_name(&dev->dev));
  78. if (!hcd) {
  79. err = -ENOMEM;
  80. goto err_power;
  81. }
  82. hcd->rsrc_start = res_mem->start;
  83. hcd->rsrc_len = resource_size(res_mem);
  84. hcd->regs = devm_ioremap_resource(&dev->dev, res_mem);
  85. if (IS_ERR(hcd->regs)) {
  86. err = PTR_ERR(hcd->regs);
  87. goto err_put_hcd;
  88. }
  89. err = usb_add_hcd(hcd, irq, IRQF_SHARED);
  90. if (err)
  91. goto err_put_hcd;
  92. device_wakeup_enable(hcd->self.controller);
  93. platform_set_drvdata(dev, hcd);
  94. return err;
  95. err_put_hcd:
  96. usb_put_hcd(hcd);
  97. err_power:
  98. if (pdata->power_off)
  99. pdata->power_off(dev);
  100. return err;
  101. }
  102. static int ohci_platform_remove(struct platform_device *dev)
  103. {
  104. struct usb_hcd *hcd = platform_get_drvdata(dev);
  105. struct usb_ohci_pdata *pdata = dev_get_platdata(&dev->dev);
  106. usb_remove_hcd(hcd);
  107. usb_put_hcd(hcd);
  108. if (pdata->power_off)
  109. pdata->power_off(dev);
  110. return 0;
  111. }
  112. #ifdef CONFIG_PM
  113. static int ohci_platform_suspend(struct device *dev)
  114. {
  115. struct usb_hcd *hcd = dev_get_drvdata(dev);
  116. struct usb_ohci_pdata *pdata = dev->platform_data;
  117. struct platform_device *pdev =
  118. container_of(dev, struct platform_device, dev);
  119. bool do_wakeup = device_may_wakeup(dev);
  120. int ret;
  121. ret = ohci_suspend(hcd, do_wakeup);
  122. if (ret)
  123. return ret;
  124. if (pdata->power_suspend)
  125. pdata->power_suspend(pdev);
  126. return ret;
  127. }
  128. static int ohci_platform_resume(struct device *dev)
  129. {
  130. struct usb_hcd *hcd = dev_get_drvdata(dev);
  131. struct usb_ohci_pdata *pdata = dev_get_platdata(dev);
  132. struct platform_device *pdev =
  133. container_of(dev, struct platform_device, dev);
  134. if (pdata->power_on) {
  135. int err = pdata->power_on(pdev);
  136. if (err < 0)
  137. return err;
  138. }
  139. ohci_resume(hcd, false);
  140. return 0;
  141. }
  142. #else /* !CONFIG_PM */
  143. #define ohci_platform_suspend NULL
  144. #define ohci_platform_resume NULL
  145. #endif /* CONFIG_PM */
  146. static const struct platform_device_id ohci_platform_table[] = {
  147. { "ohci-platform", 0 },
  148. { }
  149. };
  150. MODULE_DEVICE_TABLE(platform, ohci_platform_table);
  151. static const struct dev_pm_ops ohci_platform_pm_ops = {
  152. .suspend = ohci_platform_suspend,
  153. .resume = ohci_platform_resume,
  154. };
  155. static struct platform_driver ohci_platform_driver = {
  156. .id_table = ohci_platform_table,
  157. .probe = ohci_platform_probe,
  158. .remove = ohci_platform_remove,
  159. .shutdown = usb_hcd_platform_shutdown,
  160. .driver = {
  161. .owner = THIS_MODULE,
  162. .name = "ohci-platform",
  163. .pm = &ohci_platform_pm_ops,
  164. }
  165. };
  166. static int __init ohci_platform_init(void)
  167. {
  168. if (usb_disabled())
  169. return -ENODEV;
  170. pr_info("%s: " DRIVER_DESC "\n", hcd_name);
  171. ohci_init_driver(&ohci_platform_hc_driver, &platform_overrides);
  172. return platform_driver_register(&ohci_platform_driver);
  173. }
  174. module_init(ohci_platform_init);
  175. static void __exit ohci_platform_cleanup(void)
  176. {
  177. platform_driver_unregister(&ohci_platform_driver);
  178. }
  179. module_exit(ohci_platform_cleanup);
  180. MODULE_DESCRIPTION(DRIVER_DESC);
  181. MODULE_AUTHOR("Hauke Mehrtens");
  182. MODULE_AUTHOR("Alan Stern");
  183. MODULE_LICENSE("GPL");