host.c 3.3 KB

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