191-usb-xhci-add-Broadcom-specific-fake-doorbell.patch 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. From dd0e5f9a6a4aed849bdb80641c2a2350476cede7 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
  3. Date: Sun, 21 Jun 2015 11:10:49 +0200
  4. Subject: [PATCH v3 2/6] usb: xhci: add Broadcom specific fake doorbell
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. This fixes problem with controller seeing devices only in some small
  9. percentage of cold boots.
  10. This quirk is also added to the platform data so we can activate it
  11. when we register our platform driver.
  12. Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
  13. Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
  14. ---
  15. drivers/usb/host/xhci-plat.c | 3 +++
  16. drivers/usb/host/xhci.c | 57 +++++++++++++++++++++++++++++++++++++---
  17. drivers/usb/host/xhci.h | 1 +
  18. include/linux/usb/xhci_pdriver.h | 1 +
  19. 4 files changed, 59 insertions(+), 3 deletions(-)
  20. --- a/drivers/usb/host/xhci-plat.c
  21. +++ b/drivers/usb/host/xhci-plat.c
  22. @@ -52,6 +52,9 @@ static void xhci_plat_quirks(struct devi
  23. if ((node && of_property_read_bool(node, "usb3-lpm-capable")) ||
  24. (pdata && pdata->usb3_lpm_capable))
  25. xhci->quirks |= XHCI_LPM_SUPPORT;
  26. +
  27. + if (pdata && pdata->usb3_fake_doorbell)
  28. + xhci->quirks |= XHCI_FAKE_DOORBELL;
  29. }
  30. /* called during probe() after chip reset completes */
  31. --- a/drivers/usb/host/xhci.c
  32. +++ b/drivers/usb/host/xhci.c
  33. @@ -121,6 +121,39 @@ int xhci_halt(struct xhci_hcd *xhci)
  34. return ret;
  35. }
  36. +static int xhci_fake_doorbell(struct xhci_hcd *xhci, int slot_id)
  37. +{
  38. + u32 temp;
  39. +
  40. + /* alloc a virt device for slot */
  41. + if (!xhci_alloc_virt_device(xhci, slot_id, NULL, GFP_NOIO)) {
  42. + xhci_warn(xhci, "Could not allocate xHCI USB device data structures\n");
  43. + return -ENOMEM;
  44. + }
  45. +
  46. + /* ring fake doorbell for slot_id ep 0 */
  47. + xhci_ring_ep_doorbell(xhci, slot_id, 0, 0);
  48. + usleep_range(1000, 1500);
  49. +
  50. + /* read the status register to check if HSE is set or not? */
  51. + temp = readl(&xhci->op_regs->status);
  52. +
  53. + /* clear HSE if set */
  54. + if (temp & STS_FATAL) {
  55. + xhci_dbg(xhci, "HSE problem detected, status: 0x%x\n", temp);
  56. + temp &= ~(0x1fff);
  57. + temp |= STS_FATAL;
  58. + writel(temp, &xhci->op_regs->status);
  59. + usleep_range(1000, 1500);
  60. + readl(&xhci->op_regs->status);
  61. + }
  62. +
  63. + /* Free virt device */
  64. + xhci_free_virt_device(xhci, slot_id);
  65. +
  66. + return 0;
  67. +}
  68. +
  69. /*
  70. * Set the run bit and wait for the host to be running.
  71. */
  72. @@ -568,10 +601,25 @@ int xhci_init(struct usb_hcd *hcd)
  73. static int xhci_run_finished(struct xhci_hcd *xhci)
  74. {
  75. - if (xhci_start(xhci)) {
  76. - xhci_halt(xhci);
  77. - return -ENODEV;
  78. + int err;
  79. +
  80. + err = xhci_start(xhci);
  81. + if (err) {
  82. + err = -ENODEV;
  83. + goto out_err;
  84. + }
  85. + if (xhci->quirks & XHCI_FAKE_DOORBELL) {
  86. + err = xhci_fake_doorbell(xhci, 1);
  87. + if (err)
  88. + goto out_err;
  89. +
  90. + err = xhci_start(xhci);
  91. + if (err) {
  92. + err = -ENODEV;
  93. + goto out_err;
  94. + }
  95. }
  96. +
  97. xhci->shared_hcd->state = HC_STATE_RUNNING;
  98. xhci->cmd_ring_state = CMD_RING_STATE_RUNNING;
  99. @@ -581,6 +629,9 @@ static int xhci_run_finished(struct xhci
  100. xhci_dbg_trace(xhci, trace_xhci_dbg_init,
  101. "Finished xhci_run for USB3 roothub");
  102. return 0;
  103. +out_err:
  104. + xhci_halt(xhci);
  105. + return err;
  106. }
  107. /*
  108. --- a/drivers/usb/host/xhci.h
  109. +++ b/drivers/usb/host/xhci.h
  110. @@ -1631,6 +1631,7 @@ struct xhci_hcd {
  111. /* For controllers with a broken beyond repair streams implementation */
  112. #define XHCI_BROKEN_STREAMS (1 << 19)
  113. #define XHCI_PME_STUCK_QUIRK (1 << 20)
  114. +#define XHCI_FAKE_DOORBELL (1 << 21)
  115. unsigned int num_active_eps;
  116. unsigned int limit_active_eps;
  117. /* There are two roothubs to keep track of bus suspend info for */
  118. --- a/include/linux/usb/xhci_pdriver.h
  119. +++ b/include/linux/usb/xhci_pdriver.h
  120. @@ -22,6 +22,7 @@
  121. */
  122. struct usb_xhci_pdata {
  123. unsigned usb3_lpm_capable:1;
  124. + unsigned usb3_fake_doorbell:1;
  125. };
  126. #endif /* __USB_CORE_XHCI_PDRIVER_H */