xhci-plat.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /*
  2. * xhci-plat.c - xHCI host controller driver platform Bus Glue.
  3. *
  4. * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com
  5. * Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
  6. *
  7. * A lot of code borrowed from the Linux xHCI driver.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * version 2 as published by the Free Software Foundation.
  12. */
  13. #include <linux/platform_device.h>
  14. #include <linux/module.h>
  15. #include <linux/slab.h>
  16. #include <linux/of.h>
  17. #include "xhci.h"
  18. static void xhci_plat_quirks(struct device *dev, struct xhci_hcd *xhci)
  19. {
  20. /*
  21. * As of now platform drivers don't provide MSI support so we ensure
  22. * here that the generic code does not try to make a pci_dev from our
  23. * dev struct in order to setup MSI
  24. */
  25. xhci->quirks |= XHCI_BROKEN_MSI;
  26. }
  27. /* called during probe() after chip reset completes */
  28. static int xhci_plat_setup(struct usb_hcd *hcd)
  29. {
  30. return xhci_gen_setup(hcd, xhci_plat_quirks);
  31. }
  32. static const struct hc_driver xhci_plat_xhci_driver = {
  33. .description = "xhci-hcd",
  34. .product_desc = "xHCI Host Controller",
  35. .hcd_priv_size = sizeof(struct xhci_hcd *),
  36. /*
  37. * generic hardware linkage
  38. */
  39. .irq = xhci_irq,
  40. .flags = HCD_MEMORY | HCD_USB3 | HCD_SHARED,
  41. /*
  42. * basic lifecycle operations
  43. */
  44. .reset = xhci_plat_setup,
  45. .start = xhci_run,
  46. .stop = xhci_stop,
  47. .shutdown = xhci_shutdown,
  48. /*
  49. * managing i/o requests and associated device resources
  50. */
  51. .urb_enqueue = xhci_urb_enqueue,
  52. .urb_dequeue = xhci_urb_dequeue,
  53. .alloc_dev = xhci_alloc_dev,
  54. .free_dev = xhci_free_dev,
  55. .alloc_streams = xhci_alloc_streams,
  56. .free_streams = xhci_free_streams,
  57. .add_endpoint = xhci_add_endpoint,
  58. .drop_endpoint = xhci_drop_endpoint,
  59. .endpoint_reset = xhci_endpoint_reset,
  60. .check_bandwidth = xhci_check_bandwidth,
  61. .reset_bandwidth = xhci_reset_bandwidth,
  62. .address_device = xhci_address_device,
  63. .update_hub_device = xhci_update_hub_device,
  64. .reset_device = xhci_discover_or_reset_device,
  65. /*
  66. * scheduling support
  67. */
  68. .get_frame_number = xhci_get_frame,
  69. /* Root hub support */
  70. .hub_control = xhci_hub_control,
  71. .hub_status_data = xhci_hub_status_data,
  72. .bus_suspend = xhci_bus_suspend,
  73. .bus_resume = xhci_bus_resume,
  74. };
  75. static int xhci_plat_probe(struct platform_device *pdev)
  76. {
  77. const struct hc_driver *driver;
  78. struct xhci_hcd *xhci;
  79. struct resource *res;
  80. struct usb_hcd *hcd;
  81. int ret;
  82. int irq;
  83. if (usb_disabled())
  84. return -ENODEV;
  85. driver = &xhci_plat_xhci_driver;
  86. irq = platform_get_irq(pdev, 0);
  87. if (irq < 0)
  88. return -ENODEV;
  89. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  90. if (!res)
  91. return -ENODEV;
  92. hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
  93. if (!hcd)
  94. return -ENOMEM;
  95. hcd->rsrc_start = res->start;
  96. hcd->rsrc_len = resource_size(res);
  97. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
  98. driver->description)) {
  99. dev_dbg(&pdev->dev, "controller already in use\n");
  100. ret = -EBUSY;
  101. goto put_hcd;
  102. }
  103. hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
  104. if (!hcd->regs) {
  105. dev_dbg(&pdev->dev, "error mapping memory\n");
  106. ret = -EFAULT;
  107. goto release_mem_region;
  108. }
  109. ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
  110. if (ret)
  111. goto unmap_registers;
  112. /* USB 2.0 roothub is stored in the platform_device now. */
  113. hcd = platform_get_drvdata(pdev);
  114. xhci = hcd_to_xhci(hcd);
  115. xhci->shared_hcd = usb_create_shared_hcd(driver, &pdev->dev,
  116. dev_name(&pdev->dev), hcd);
  117. if (!xhci->shared_hcd) {
  118. ret = -ENOMEM;
  119. goto dealloc_usb2_hcd;
  120. }
  121. /*
  122. * Set the xHCI pointer before xhci_plat_setup() (aka hcd_driver.reset)
  123. * is called by usb_add_hcd().
  124. */
  125. *((struct xhci_hcd **) xhci->shared_hcd->hcd_priv) = xhci;
  126. ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED);
  127. if (ret)
  128. goto put_usb3_hcd;
  129. return 0;
  130. put_usb3_hcd:
  131. usb_put_hcd(xhci->shared_hcd);
  132. dealloc_usb2_hcd:
  133. usb_remove_hcd(hcd);
  134. unmap_registers:
  135. iounmap(hcd->regs);
  136. release_mem_region:
  137. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  138. put_hcd:
  139. usb_put_hcd(hcd);
  140. return ret;
  141. }
  142. static int xhci_plat_remove(struct platform_device *dev)
  143. {
  144. struct usb_hcd *hcd = platform_get_drvdata(dev);
  145. struct xhci_hcd *xhci = hcd_to_xhci(hcd);
  146. usb_remove_hcd(xhci->shared_hcd);
  147. usb_put_hcd(xhci->shared_hcd);
  148. usb_remove_hcd(hcd);
  149. iounmap(hcd->regs);
  150. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  151. usb_put_hcd(hcd);
  152. kfree(xhci);
  153. return 0;
  154. }
  155. #ifdef CONFIG_PM
  156. static int xhci_plat_suspend(struct device *dev)
  157. {
  158. struct usb_hcd *hcd = dev_get_drvdata(dev);
  159. struct xhci_hcd *xhci = hcd_to_xhci(hcd);
  160. return xhci_suspend(xhci);
  161. }
  162. static int xhci_plat_resume(struct device *dev)
  163. {
  164. struct usb_hcd *hcd = dev_get_drvdata(dev);
  165. struct xhci_hcd *xhci = hcd_to_xhci(hcd);
  166. return xhci_resume(xhci, 0);
  167. }
  168. static const struct dev_pm_ops xhci_plat_pm_ops = {
  169. SET_SYSTEM_SLEEP_PM_OPS(xhci_plat_suspend, xhci_plat_resume)
  170. };
  171. #define DEV_PM_OPS (&xhci_plat_pm_ops)
  172. #else
  173. #define DEV_PM_OPS NULL
  174. #endif /* CONFIG_PM */
  175. #ifdef CONFIG_OF
  176. static const struct of_device_id usb_xhci_of_match[] = {
  177. { .compatible = "xhci-platform" },
  178. { },
  179. };
  180. MODULE_DEVICE_TABLE(of, usb_xhci_of_match);
  181. #endif
  182. static struct platform_driver usb_xhci_driver = {
  183. .probe = xhci_plat_probe,
  184. .remove = xhci_plat_remove,
  185. .driver = {
  186. .name = "xhci-hcd",
  187. .pm = DEV_PM_OPS,
  188. .of_match_table = of_match_ptr(usb_xhci_of_match),
  189. },
  190. };
  191. MODULE_ALIAS("platform:xhci-hcd");
  192. int xhci_register_plat(void)
  193. {
  194. return platform_driver_register(&usb_xhci_driver);
  195. }
  196. void xhci_unregister_plat(void)
  197. {
  198. platform_driver_unregister(&usb_xhci_driver);
  199. }