host.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. xhci->dev.parent = dwc->dev;
  67. dwc->xhci = xhci;
  68. ret = platform_device_add_resources(xhci, dwc->xhci_resources,
  69. DWC3_XHCI_RESOURCES_NUM);
  70. if (ret) {
  71. dev_err(dwc->dev, "couldn't add resources to xHCI device\n");
  72. goto err1;
  73. }
  74. memset(props, 0, sizeof(struct property_entry) * ARRAY_SIZE(props));
  75. if (dwc->usb3_lpm_capable)
  76. props[prop_idx++].name = "usb3-lpm-capable";
  77. /**
  78. * WORKAROUND: dwc3 revisions <=3.00a have a limitation
  79. * where Port Disable command doesn't work.
  80. *
  81. * The suggested workaround is that we avoid Port Disable
  82. * completely.
  83. *
  84. * This following flag tells XHCI to do just that.
  85. */
  86. if (dwc->revision <= DWC3_REVISION_300A)
  87. props[prop_idx++].name = "quirk-broken-port-ped";
  88. if (prop_idx) {
  89. ret = platform_device_add_properties(xhci, props);
  90. if (ret) {
  91. dev_err(dwc->dev, "failed to add properties to xHCI\n");
  92. goto err1;
  93. }
  94. }
  95. phy_create_lookup(dwc->usb2_generic_phy, "usb2-phy",
  96. dev_name(dwc->dev));
  97. phy_create_lookup(dwc->usb3_generic_phy, "usb3-phy",
  98. dev_name(dwc->dev));
  99. ret = platform_device_add(xhci);
  100. if (ret) {
  101. dev_err(dwc->dev, "failed to register xHCI device\n");
  102. goto err2;
  103. }
  104. return 0;
  105. err2:
  106. phy_remove_lookup(dwc->usb2_generic_phy, "usb2-phy",
  107. dev_name(dwc->dev));
  108. phy_remove_lookup(dwc->usb3_generic_phy, "usb3-phy",
  109. dev_name(dwc->dev));
  110. err1:
  111. platform_device_put(xhci);
  112. return ret;
  113. }
  114. void dwc3_host_exit(struct dwc3 *dwc)
  115. {
  116. phy_remove_lookup(dwc->usb2_generic_phy, "usb2-phy",
  117. dev_name(dwc->dev));
  118. phy_remove_lookup(dwc->usb3_generic_phy, "usb3-phy",
  119. dev_name(dwc->dev));
  120. platform_device_unregister(dwc->xhci);
  121. }