ehci-platform.c 5.0 KB

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