ohci-platform.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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 = pdev->dev.platform_data;
  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->dev.platform_data;
  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. platform_set_drvdata(dev, hcd);
  93. return err;
  94. err_put_hcd:
  95. usb_put_hcd(hcd);
  96. err_power:
  97. if (pdata->power_off)
  98. pdata->power_off(dev);
  99. return err;
  100. }
  101. static int ohci_platform_remove(struct platform_device *dev)
  102. {
  103. struct usb_hcd *hcd = platform_get_drvdata(dev);
  104. struct usb_ohci_pdata *pdata = dev->dev.platform_data;
  105. usb_remove_hcd(hcd);
  106. usb_put_hcd(hcd);
  107. if (pdata->power_off)
  108. pdata->power_off(dev);
  109. return 0;
  110. }
  111. #ifdef CONFIG_PM
  112. static int ohci_platform_suspend(struct device *dev)
  113. {
  114. struct usb_ohci_pdata *pdata = dev->platform_data;
  115. struct platform_device *pdev =
  116. container_of(dev, struct platform_device, dev);
  117. if (pdata->power_suspend)
  118. pdata->power_suspend(pdev);
  119. return 0;
  120. }
  121. static int ohci_platform_resume(struct device *dev)
  122. {
  123. struct usb_hcd *hcd = dev_get_drvdata(dev);
  124. struct usb_ohci_pdata *pdata = dev->platform_data;
  125. struct platform_device *pdev =
  126. container_of(dev, struct platform_device, dev);
  127. if (pdata->power_on) {
  128. int err = pdata->power_on(pdev);
  129. if (err < 0)
  130. return err;
  131. }
  132. ohci_resume(hcd, false);
  133. return 0;
  134. }
  135. #else /* !CONFIG_PM */
  136. #define ohci_platform_suspend NULL
  137. #define ohci_platform_resume NULL
  138. #endif /* CONFIG_PM */
  139. static const struct platform_device_id ohci_platform_table[] = {
  140. { "ohci-platform", 0 },
  141. { }
  142. };
  143. MODULE_DEVICE_TABLE(platform, ohci_platform_table);
  144. static const struct dev_pm_ops ohci_platform_pm_ops = {
  145. .suspend = ohci_platform_suspend,
  146. .resume = ohci_platform_resume,
  147. };
  148. static struct platform_driver ohci_platform_driver = {
  149. .id_table = ohci_platform_table,
  150. .probe = ohci_platform_probe,
  151. .remove = ohci_platform_remove,
  152. .shutdown = usb_hcd_platform_shutdown,
  153. .driver = {
  154. .owner = THIS_MODULE,
  155. .name = "ohci-platform",
  156. .pm = &ohci_platform_pm_ops,
  157. }
  158. };
  159. static int __init ohci_platform_init(void)
  160. {
  161. if (usb_disabled())
  162. return -ENODEV;
  163. pr_info("%s: " DRIVER_DESC "\n", hcd_name);
  164. ohci_init_driver(&ohci_platform_hc_driver, &platform_overrides);
  165. return platform_driver_register(&ohci_platform_driver);
  166. }
  167. module_init(ohci_platform_init);
  168. static void __exit ohci_platform_cleanup(void)
  169. {
  170. platform_driver_unregister(&ohci_platform_driver);
  171. }
  172. module_exit(ohci_platform_cleanup);
  173. MODULE_DESCRIPTION(DRIVER_DESC);
  174. MODULE_AUTHOR("Hauke Mehrtens");
  175. MODULE_AUTHOR("Alan Stern");
  176. MODULE_LICENSE("GPL");