180-usb-xhci-add-support-for-performing-fake-doorbell.patch 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <[email protected]>
  2. Date: Sat, 1 Oct 2016 22:54:48 +0200
  3. Subject: [PATCH] usb: xhci: add support for performing fake doorbell
  4. Broadcom's Northstar XHCI controllers seem to need a special start
  5. procedure to work correctly. There isn't any official documentation of
  6. this, the problem is that controller doesn't detect any connected
  7. devices with default setup. Moreover connecting USB device to controller
  8. that doesn't run properly can cause SoC's watchdog issues.
  9. A workaround that was successfully tested on multiple devices is to
  10. perform a fake doorbell. This patch adds code for doing this and enables
  11. it on BCM4708 family.
  12. ---
  13. drivers/usb/host/xhci-plat.c | 6 +++++
  14. drivers/usb/host/xhci.c | 63 +++++++++++++++++++++++++++++++++++++++++---
  15. drivers/usb/host/xhci.h | 1 +
  16. 3 files changed, 67 insertions(+), 3 deletions(-)
  17. --- a/drivers/usb/host/xhci-plat.c
  18. +++ b/drivers/usb/host/xhci-plat.c
  19. @@ -67,12 +67,18 @@ static int xhci_priv_resume_quirk(struct
  20. static void xhci_plat_quirks(struct device *dev, struct xhci_hcd *xhci)
  21. {
  22. + struct platform_device *pdev = to_platform_device(dev);
  23. + struct device_node *node = pdev->dev.of_node;
  24. +
  25. /*
  26. * As of now platform drivers don't provide MSI support so we ensure
  27. * here that the generic code does not try to make a pci_dev from our
  28. * dev struct in order to setup MSI
  29. */
  30. xhci->quirks |= XHCI_PLAT;
  31. +
  32. + if (node && of_machine_is_compatible("brcm,bcm4708"))
  33. + xhci->quirks |= XHCI_FAKE_DOORBELL;
  34. }
  35. /* called during probe() after chip reset completes */
  36. --- a/drivers/usb/host/xhci.c
  37. +++ b/drivers/usb/host/xhci.c
  38. @@ -168,6 +168,49 @@ int xhci_start(struct xhci_hcd *xhci)
  39. return ret;
  40. }
  41. +/**
  42. + * xhci_fake_doorbell - Perform a fake doorbell on a specified slot
  43. + *
  44. + * Some controllers require a fake doorbell to start correctly. Without that
  45. + * they simply don't detect any devices.
  46. + */
  47. +static int xhci_fake_doorbell(struct xhci_hcd *xhci, int slot_id)
  48. +{
  49. + u32 temp;
  50. +
  51. + /* Alloc a virt device for that slot */
  52. + if (!xhci_alloc_virt_device(xhci, slot_id, NULL, GFP_NOIO)) {
  53. + xhci_warn(xhci, "Could not allocate xHCI USB device data structures\n");
  54. + return -ENOMEM;
  55. + }
  56. +
  57. + /* Ring fake doorbell for slot_id ep 0 */
  58. + xhci_ring_ep_doorbell(xhci, slot_id, 0, 0);
  59. + usleep_range(1000, 1500);
  60. +
  61. + /* Read the status to check if HSE is set or not */
  62. + temp = readl(&xhci->op_regs->status);
  63. +
  64. + /* Clear HSE if set */
  65. + if (temp & STS_FATAL) {
  66. + xhci_dbg(xhci, "HSE problem detected, status: 0x%08x\n", temp);
  67. + temp &= ~0x1fff;
  68. + temp |= STS_FATAL;
  69. + writel(temp, &xhci->op_regs->status);
  70. + usleep_range(1000, 1500);
  71. + readl(&xhci->op_regs->status);
  72. + }
  73. +
  74. + /* Free virt device */
  75. + xhci_free_virt_device(xhci, slot_id);
  76. +
  77. + /* We're done if controller is already running */
  78. + if (readl(&xhci->op_regs->command) & CMD_RUN)
  79. + return 0;
  80. +
  81. + return xhci_start(xhci);
  82. +}
  83. +
  84. /*
  85. * Reset a halted HC.
  86. *
  87. @@ -551,10 +594,20 @@ static int xhci_init(struct usb_hcd *hcd
  88. static int xhci_run_finished(struct xhci_hcd *xhci)
  89. {
  90. - if (xhci_start(xhci)) {
  91. - xhci_halt(xhci);
  92. - return -ENODEV;
  93. + int err;
  94. +
  95. + err = xhci_start(xhci);
  96. + if (err) {
  97. + err = -ENODEV;
  98. + goto err_halt;
  99. }
  100. +
  101. + if (xhci->quirks & XHCI_FAKE_DOORBELL) {
  102. + err = xhci_fake_doorbell(xhci, 1);
  103. + if (err)
  104. + goto err_halt;
  105. + }
  106. +
  107. xhci->shared_hcd->state = HC_STATE_RUNNING;
  108. xhci->cmd_ring_state = CMD_RING_STATE_RUNNING;
  109. @@ -564,6 +617,10 @@ static int xhci_run_finished(struct xhci
  110. xhci_dbg_trace(xhci, trace_xhci_dbg_init,
  111. "Finished xhci_run for USB3 roothub");
  112. return 0;
  113. +
  114. +err_halt:
  115. + xhci_halt(xhci);
  116. + return err;
  117. }
  118. /*
  119. --- a/drivers/usb/host/xhci.h
  120. +++ b/drivers/usb/host/xhci.h
  121. @@ -1835,6 +1835,7 @@ struct xhci_hcd {
  122. #define XHCI_LIMIT_ENDPOINT_INTERVAL_7 (1 << 26)
  123. #define XHCI_U2_DISABLE_WAKE (1 << 27)
  124. #define XHCI_ASMEDIA_MODIFY_FLOWCONTROL (1 << 28)
  125. +#define XHCI_FAKE_DOORBELL (1 << 29)
  126. #define XHCI_SUSPEND_DELAY (1 << 30)
  127. unsigned int num_active_eps;