xhci-plat.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 "xhci.h"
  17. static void xhci_plat_quirks(struct device *dev, struct xhci_hcd *xhci)
  18. {
  19. /*
  20. * As of now platform drivers don't provide MSI support so we ensure
  21. * here that the generic code does not try to make a pci_dev from our
  22. * dev struct in order to setup MSI
  23. */
  24. xhci->quirks |= XHCI_BROKEN_MSI;
  25. }
  26. /* called during probe() after chip reset completes */
  27. static int xhci_plat_setup(struct usb_hcd *hcd)
  28. {
  29. return xhci_gen_setup(hcd, xhci_plat_quirks);
  30. }
  31. static const struct hc_driver xhci_plat_xhci_driver = {
  32. .description = "xhci-hcd",
  33. .product_desc = "xHCI Host Controller",
  34. .hcd_priv_size = sizeof(struct xhci_hcd *),
  35. /*
  36. * generic hardware linkage
  37. */
  38. .irq = xhci_irq,
  39. .flags = HCD_MEMORY | HCD_USB3 | HCD_SHARED,
  40. /*
  41. * basic lifecycle operations
  42. */
  43. .reset = xhci_plat_setup,
  44. .start = xhci_run,
  45. .stop = xhci_stop,
  46. .shutdown = xhci_shutdown,
  47. /*
  48. * managing i/o requests and associated device resources
  49. */
  50. .urb_enqueue = xhci_urb_enqueue,
  51. .urb_dequeue = xhci_urb_dequeue,
  52. .alloc_dev = xhci_alloc_dev,
  53. .free_dev = xhci_free_dev,
  54. .alloc_streams = xhci_alloc_streams,
  55. .free_streams = xhci_free_streams,
  56. .add_endpoint = xhci_add_endpoint,
  57. .drop_endpoint = xhci_drop_endpoint,
  58. .endpoint_reset = xhci_endpoint_reset,
  59. .check_bandwidth = xhci_check_bandwidth,
  60. .reset_bandwidth = xhci_reset_bandwidth,
  61. .address_device = xhci_address_device,
  62. .update_hub_device = xhci_update_hub_device,
  63. .reset_device = xhci_discover_or_reset_device,
  64. /*
  65. * scheduling support
  66. */
  67. .get_frame_number = xhci_get_frame,
  68. /* Root hub support */
  69. .hub_control = xhci_hub_control,
  70. .hub_status_data = xhci_hub_status_data,
  71. .bus_suspend = xhci_bus_suspend,
  72. .bus_resume = xhci_bus_resume,
  73. };
  74. static int xhci_plat_probe(struct platform_device *pdev)
  75. {
  76. const struct hc_driver *driver;
  77. struct xhci_hcd *xhci;
  78. struct resource *res;
  79. struct usb_hcd *hcd;
  80. int ret;
  81. int irq;
  82. if (usb_disabled())
  83. return -ENODEV;
  84. driver = &xhci_plat_xhci_driver;
  85. irq = platform_get_irq(pdev, 0);
  86. if (irq < 0)
  87. return -ENODEV;
  88. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  89. if (!res)
  90. return -ENODEV;
  91. hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
  92. if (!hcd)
  93. return -ENOMEM;
  94. hcd->rsrc_start = res->start;
  95. hcd->rsrc_len = resource_size(res);
  96. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
  97. driver->description)) {
  98. dev_dbg(&pdev->dev, "controller already in use\n");
  99. ret = -EBUSY;
  100. goto put_hcd;
  101. }
  102. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  103. if (!hcd->regs) {
  104. dev_dbg(&pdev->dev, "error mapping memory\n");
  105. ret = -EFAULT;
  106. goto release_mem_region;
  107. }
  108. ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
  109. if (ret)
  110. goto unmap_registers;
  111. /* USB 2.0 roothub is stored in the platform_device now. */
  112. hcd = dev_get_drvdata(&pdev->dev);
  113. xhci = hcd_to_xhci(hcd);
  114. xhci->shared_hcd = usb_create_shared_hcd(driver, &pdev->dev,
  115. dev_name(&pdev->dev), hcd);
  116. if (!xhci->shared_hcd) {
  117. ret = -ENOMEM;
  118. goto dealloc_usb2_hcd;
  119. }
  120. /*
  121. * Set the xHCI pointer before xhci_plat_setup() (aka hcd_driver.reset)
  122. * is called by usb_add_hcd().
  123. */
  124. *((struct xhci_hcd **) xhci->shared_hcd->hcd_priv) = xhci;
  125. ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED);
  126. if (ret)
  127. goto put_usb3_hcd;
  128. return 0;
  129. put_usb3_hcd:
  130. usb_put_hcd(xhci->shared_hcd);
  131. dealloc_usb2_hcd:
  132. usb_remove_hcd(hcd);
  133. unmap_registers:
  134. iounmap(hcd->regs);
  135. release_mem_region:
  136. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  137. put_hcd:
  138. usb_put_hcd(hcd);
  139. return ret;
  140. }
  141. static int xhci_plat_remove(struct platform_device *dev)
  142. {
  143. struct usb_hcd *hcd = platform_get_drvdata(dev);
  144. struct xhci_hcd *xhci = hcd_to_xhci(hcd);
  145. usb_remove_hcd(xhci->shared_hcd);
  146. usb_put_hcd(xhci->shared_hcd);
  147. usb_remove_hcd(hcd);
  148. iounmap(hcd->regs);
  149. usb_put_hcd(hcd);
  150. kfree(xhci);
  151. return 0;
  152. }
  153. static struct platform_driver usb_xhci_driver = {
  154. .probe = xhci_plat_probe,
  155. .remove = xhci_plat_remove,
  156. .driver = {
  157. .name = "xhci-hcd",
  158. },
  159. };
  160. MODULE_ALIAS("platform:xhci-hcd");
  161. int xhci_register_plat(void)
  162. {
  163. return platform_driver_register(&usb_xhci_driver);
  164. }
  165. void xhci_unregister_plat(void)
  166. {
  167. platform_driver_unregister(&usb_xhci_driver);
  168. }