host.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /**
  2. * host.c - DesignWare USB3 DRD Controller Host Glue
  3. *
  4. * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com
  5. *
  6. * Authors: Felipe Balbi <balbi@ti.com>,
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 of
  10. * the License as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. */
  17. #include <linux/platform_device.h>
  18. #include "core.h"
  19. int dwc3_host_init(struct dwc3 *dwc)
  20. {
  21. struct property_entry props[3];
  22. struct platform_device *xhci;
  23. int ret, irq;
  24. struct resource *res;
  25. struct platform_device *dwc3_pdev = to_platform_device(dwc->dev);
  26. int prop_idx = 0;
  27. irq = platform_get_irq_byname(dwc3_pdev, "host");
  28. if (irq == -EPROBE_DEFER)
  29. return irq;
  30. if (irq <= 0) {
  31. irq = platform_get_irq_byname(dwc3_pdev, "dwc_usb3");
  32. if (irq == -EPROBE_DEFER)
  33. return irq;
  34. if (irq <= 0) {
  35. irq = platform_get_irq(dwc3_pdev, 0);
  36. if (irq <= 0) {
  37. if (irq != -EPROBE_DEFER) {
  38. dev_err(dwc->dev,
  39. "missing host IRQ\n");
  40. }
  41. if (!irq)
  42. irq = -EINVAL;
  43. return irq;
  44. } else {
  45. res = platform_get_resource(dwc3_pdev,
  46. IORESOURCE_IRQ, 0);
  47. }
  48. } else {
  49. res = platform_get_resource_byname(dwc3_pdev,
  50. IORESOURCE_IRQ,
  51. "dwc_usb3");
  52. }
  53. } else {
  54. res = platform_get_resource_byname(dwc3_pdev, IORESOURCE_IRQ,
  55. "host");
  56. }
  57. dwc->xhci_resources[1].start = irq;
  58. dwc->xhci_resources[1].end = irq;
  59. dwc->xhci_resources[1].flags = res->flags;
  60. dwc->xhci_resources[1].name = res->name;
  61. xhci = platform_device_alloc("xhci-hcd", PLATFORM_DEVID_AUTO);
  62. if (!xhci) {
  63. dev_err(dwc->dev, "couldn't allocate xHCI device\n");
  64. return -ENOMEM;
  65. }
  66. dma_set_coherent_mask(&xhci->dev, dwc->dev->coherent_dma_mask);
  67. xhci->dev.parent = dwc->dev;
  68. xhci->dev.dma_mask = dwc->dev->dma_mask;
  69. xhci->dev.dma_parms = dwc->dev->dma_parms;
  70. dwc->xhci = xhci;
  71. ret = platform_device_add_resources(xhci, dwc->xhci_resources,
  72. DWC3_XHCI_RESOURCES_NUM);
  73. if (ret) {
  74. dev_err(dwc->dev, "couldn't add resources to xHCI device\n");
  75. goto err1;
  76. }
  77. memset(props, 0, sizeof(struct property_entry) * ARRAY_SIZE(props));
  78. if (dwc->usb3_lpm_capable)
  79. props[prop_idx++].name = "usb3-lpm-capable";
  80. /**
  81. * WORKAROUND: dwc3 revisions <=3.00a have a limitation
  82. * where Port Disable command doesn't work.
  83. *
  84. * The suggested workaround is that we avoid Port Disable
  85. * completely.
  86. *
  87. * This following flag tells XHCI to do just that.
  88. */
  89. if (dwc->revision <= DWC3_REVISION_300A)
  90. props[prop_idx++].name = "quirk-broken-port-ped";
  91. if (prop_idx) {
  92. ret = platform_device_add_properties(xhci, props);
  93. if (ret) {
  94. dev_err(dwc->dev, "failed to add properties to xHCI\n");
  95. goto err1;
  96. }
  97. }
  98. phy_create_lookup(dwc->usb2_generic_phy, "usb2-phy",
  99. dev_name(&xhci->dev));
  100. phy_create_lookup(dwc->usb3_generic_phy, "usb3-phy",
  101. dev_name(&xhci->dev));
  102. ret = platform_device_add(xhci);
  103. if (ret) {
  104. dev_err(dwc->dev, "failed to register xHCI device\n");
  105. goto err2;
  106. }
  107. return 0;
  108. err2:
  109. phy_remove_lookup(dwc->usb2_generic_phy, "usb2-phy",
  110. dev_name(&xhci->dev));
  111. phy_remove_lookup(dwc->usb3_generic_phy, "usb3-phy",
  112. dev_name(&xhci->dev));
  113. err1:
  114. platform_device_put(xhci);
  115. return ret;
  116. }
  117. void dwc3_host_exit(struct dwc3 *dwc)
  118. {
  119. phy_remove_lookup(dwc->usb2_generic_phy, "usb2-phy",
  120. dev_name(&dwc->xhci->dev));
  121. phy_remove_lookup(dwc->usb3_generic_phy, "usb3-phy",
  122. dev_name(&dwc->xhci->dev));
  123. platform_device_unregister(dwc->xhci);
  124. }