0002-surface3.patch 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. From 1861d3780461b6a1640979f316576342b1a9c990 Mon Sep 17 00:00:00 2001
  2. From: Tsuchiya Yuto <kitakar@gmail.com>
  3. Date: Sun, 18 Oct 2020 16:42:44 +0900
  4. Subject: [PATCH] (surface3-oemb) add DMI matches for Surface 3 with broken DMI
  5. table
  6. On some Surface 3, the DMI table gets corrupted for unknown reasons
  7. and breaks existing DMI matching used for device-specific quirks.
  8. This commit adds the (broken) DMI data into dmi_system_id tables used
  9. for quirks so that each driver can enable quirks even on the affected
  10. systems.
  11. On affected systems, DMI data will look like this:
  12. $ grep . /sys/devices/virtual/dmi/id/{bios_vendor,board_name,board_vendor,\
  13. chassis_vendor,product_name,sys_vendor}
  14. /sys/devices/virtual/dmi/id/bios_vendor:American Megatrends Inc.
  15. /sys/devices/virtual/dmi/id/board_name:OEMB
  16. /sys/devices/virtual/dmi/id/board_vendor:OEMB
  17. /sys/devices/virtual/dmi/id/chassis_vendor:OEMB
  18. /sys/devices/virtual/dmi/id/product_name:OEMB
  19. /sys/devices/virtual/dmi/id/sys_vendor:OEMB
  20. Expected:
  21. $ grep . /sys/devices/virtual/dmi/id/{bios_vendor,board_name,board_vendor,\
  22. chassis_vendor,product_name,sys_vendor}
  23. /sys/devices/virtual/dmi/id/bios_vendor:American Megatrends Inc.
  24. /sys/devices/virtual/dmi/id/board_name:Surface 3
  25. /sys/devices/virtual/dmi/id/board_vendor:Microsoft Corporation
  26. /sys/devices/virtual/dmi/id/chassis_vendor:Microsoft Corporation
  27. /sys/devices/virtual/dmi/id/product_name:Surface 3
  28. /sys/devices/virtual/dmi/id/sys_vendor:Microsoft Corporation
  29. Signed-off-by: Tsuchiya Yuto <kitakar@gmail.com>
  30. Patchset: surface3
  31. ---
  32. drivers/platform/surface/surface3-wmi.c | 7 +++++++
  33. sound/soc/codecs/rt5645.c | 9 +++++++++
  34. sound/soc/intel/common/soc-acpi-intel-cht-match.c | 8 ++++++++
  35. 3 files changed, 24 insertions(+)
  36. diff --git a/drivers/platform/surface/surface3-wmi.c b/drivers/platform/surface/surface3-wmi.c
  37. index 6c8fb7a4dde4..22797a53f4d8 100644
  38. --- a/drivers/platform/surface/surface3-wmi.c
  39. +++ b/drivers/platform/surface/surface3-wmi.c
  40. @@ -37,6 +37,13 @@ static const struct dmi_system_id surface3_dmi_table[] = {
  41. DMI_MATCH(DMI_PRODUCT_NAME, "Surface 3"),
  42. },
  43. },
  44. + {
  45. + .matches = {
  46. + DMI_MATCH(DMI_BIOS_VENDOR, "American Megatrends Inc."),
  47. + DMI_MATCH(DMI_SYS_VENDOR, "OEMB"),
  48. + DMI_MATCH(DMI_PRODUCT_NAME, "OEMB"),
  49. + },
  50. + },
  51. #endif
  52. { }
  53. };
  54. diff --git a/sound/soc/codecs/rt5645.c b/sound/soc/codecs/rt5645.c
  55. index 51187b1e0ed2..bfb83ce8d8f8 100644
  56. --- a/sound/soc/codecs/rt5645.c
  57. +++ b/sound/soc/codecs/rt5645.c
  58. @@ -3790,6 +3790,15 @@ static const struct dmi_system_id dmi_platform_data[] = {
  59. },
  60. .driver_data = (void *)&intel_braswell_platform_data,
  61. },
  62. + {
  63. + .ident = "Microsoft Surface 3",
  64. + .matches = {
  65. + DMI_MATCH(DMI_BIOS_VENDOR, "American Megatrends Inc."),
  66. + DMI_MATCH(DMI_SYS_VENDOR, "OEMB"),
  67. + DMI_MATCH(DMI_PRODUCT_NAME, "OEMB"),
  68. + },
  69. + .driver_data = (void *)&intel_braswell_platform_data,
  70. + },
  71. {
  72. /*
  73. * Match for the GPDwin which unfortunately uses somewhat
  74. diff --git a/sound/soc/intel/common/soc-acpi-intel-cht-match.c b/sound/soc/intel/common/soc-acpi-intel-cht-match.c
  75. index e4c3492a0c28..0b930c91bccb 100644
  76. --- a/sound/soc/intel/common/soc-acpi-intel-cht-match.c
  77. +++ b/sound/soc/intel/common/soc-acpi-intel-cht-match.c
  78. @@ -27,6 +27,14 @@ static const struct dmi_system_id cht_table[] = {
  79. DMI_MATCH(DMI_PRODUCT_NAME, "Surface 3"),
  80. },
  81. },
  82. + {
  83. + .callback = cht_surface_quirk_cb,
  84. + .matches = {
  85. + DMI_MATCH(DMI_BIOS_VENDOR, "American Megatrends Inc."),
  86. + DMI_MATCH(DMI_SYS_VENDOR, "OEMB"),
  87. + DMI_MATCH(DMI_PRODUCT_NAME, "OEMB"),
  88. + },
  89. + },
  90. { }
  91. };
  92. --
  93. 2.49.0
  94. From d1425f39cb72c625b785ae50b563543f9cdf384b Mon Sep 17 00:00:00 2001
  95. From: kitakar5525 <34676735+kitakar5525@users.noreply.github.com>
  96. Date: Fri, 6 Dec 2019 23:10:30 +0900
  97. Subject: [PATCH] surface3-spi: workaround: disable DMA mode to avoid crash by
  98. default
  99. On Arch Linux kernel at least after 4.19, touch input is broken after suspend
  100. (s2idle).
  101. kern :err : [ +0.203408] Surface3-spi spi-MSHW0037:00: SPI transfer timed out
  102. On recent stable Arch Linux kernel (at least after 5.1), touch input will
  103. crash after the first touch.
  104. kern :err : [ +0.203592] Surface3-spi spi-MSHW0037:00: SPI transfer timed out
  105. kern :err : [ +0.000173] spi_master spi1: failed to transfer one message from queue
  106. I found on an affected system (Arch Linux kernel, etc.), the touchscreen
  107. driver uses DMA mode by default. Then, we found some kernels with different
  108. kernel config (5.1 kernel config from Jakeday [1] or Chromium OS kernel
  109. chromeos-4.19 [2]) will use PIO mode by default and no such issues there.
  110. So, this commit disables DMA mode on the touchscreen driver side as a quick
  111. workaround to avoid touch input crash.
  112. We may need to properly set up DMA mode to use the touchscreen driver with
  113. DMA mode.
  114. You can still switch DMA/PIO mode if you want:
  115. switch to DMA mode (maybe broken)
  116. echo 1 | sudo tee /sys/module/surface3_spi/parameters/use_dma
  117. back to PIO mode
  118. echo 0 | sudo tee /sys/module/surface3_spi/parameters/use_dma
  119. Link to issue: https://github.com/jakeday/linux-surface/issues/596
  120. References:
  121. [1] https://github.com/jakeday/linux-surface/blob/master/configs/5.1/config
  122. [2] https://chromium.googlesource.com/chromiumos/third_party/kernel/+/refs/heads/chromeos-4.19
  123. Tested on Arch Linux 5.4.1 with Surface 3, which will use DMA by default.
  124. This commit made the driver use PIO by default and no touch input crash.
  125. Also tested on chromeos-4.19 4.19.90 with Surface 3, which will use PIO by default
  126. even without this commit. After this commit, it still uses PIO and confirmed
  127. no functional changes regarding touch input.
  128. More details:
  129. We can confirm which mode the touchscreen driver uses; first, enable
  130. debug output:
  131. echo "file drivers/spi/spi-pxa2xx.c +p" | sudo tee /sys/kernel/debug/dynamic_debug/control
  132. echo "file drivers/input/touchscreen/surface3_spi.c +p" | sudo tee /sys/kernel/debug/dynamic_debug/control
  133. Then, try to make a touch input and see dmesg log
  134. (On Arch Linux kernel, uses DMA)
  135. kern :debug : [ +0.006383] Surface3-spi spi-MSHW0037:00: 7692307 Hz actual, DMA
  136. kern :debug : [ +0.000495] Surface3-spi spi-MSHW0037:00: surface3_spi_irq_handler received
  137. -> ff ff ff ff a5 5a e7 7e 01 d2 00 80 01 03 03 18 00 e4 01 00 04 1a 04 1a e3 0c e3 0c b0 00
  138. c5 00 00 00 00 00 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
  139. (On the kernels I referenced above, uses PIO)
  140. kern :debug : [ +0.009260] Surface3-spi spi-MSHW0037:00: 7692307 Hz actual, PIO
  141. kern :debug : [ +0.001105] Surface3-spi spi-MSHW0037:00: surface3_spi_irq_handler received
  142. -> ff ff ff ff a5 5a e7 7e 01 d2 00 80 01 03 03 24 00 e4 01 00 58 0b 58 0b 83 12 83 12 26 01
  143. 95 01 00 00 00 00 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
  144. Note (2025-03-08): This patch was originally dropped due to the
  145. comments in [3]. However, according to the commments in [4] it is still
  146. required.
  147. [3]: https://github.com/linux-surface/kernel/commit/a3421c12bed0e46c28518bcb8c6b22f237c6dc7a
  148. [4]: https://github.com/linux-surface/linux-surface/issues/1184
  149. Patchset: surface3
  150. ---
  151. drivers/input/touchscreen/surface3_spi.c | 26 ++++++++++++++++++++++++
  152. 1 file changed, 26 insertions(+)
  153. diff --git a/drivers/input/touchscreen/surface3_spi.c b/drivers/input/touchscreen/surface3_spi.c
  154. index 6074b7730e86..6aa3e1d6f160 100644
  155. --- a/drivers/input/touchscreen/surface3_spi.c
  156. +++ b/drivers/input/touchscreen/surface3_spi.c
  157. @@ -25,6 +25,12 @@
  158. #define SURFACE3_REPORT_TOUCH 0xd2
  159. #define SURFACE3_REPORT_PEN 0x16
  160. +bool use_dma = false;
  161. +module_param(use_dma, bool, 0644);
  162. +MODULE_PARM_DESC(use_dma,
  163. + "Disable DMA mode if you encounter touch input crash. "
  164. + "(default: false, disabled to avoid crash)");
  165. +
  166. struct surface3_ts_data {
  167. struct spi_device *spi;
  168. struct gpio_desc *gpiod_rst[2];
  169. @@ -317,6 +323,13 @@ static int surface3_spi_create_pen_input(struct surface3_ts_data *data)
  170. return 0;
  171. }
  172. +static bool surface3_spi_can_dma(struct spi_controller *ctlr,
  173. + struct spi_device *spi,
  174. + struct spi_transfer *tfr)
  175. +{
  176. + return use_dma;
  177. +}
  178. +
  179. static int surface3_spi_probe(struct spi_device *spi)
  180. {
  181. struct surface3_ts_data *data;
  182. @@ -359,6 +372,19 @@ static int surface3_spi_probe(struct spi_device *spi)
  183. if (error)
  184. return error;
  185. + /*
  186. + * Set up DMA
  187. + *
  188. + * TODO: Currently, touch input with DMA seems to be broken.
  189. + * On 4.19 LTS, touch input will crash after suspend.
  190. + * On recent stable kernel (at least after 5.1), touch input will crash after
  191. + * the first touch. No problem with PIO on those kernels.
  192. + * Maybe we need to configure DMA here.
  193. + *
  194. + * Link to issue: https://github.com/jakeday/linux-surface/issues/596
  195. + */
  196. + spi->controller->can_dma = surface3_spi_can_dma;
  197. +
  198. return 0;
  199. }
  200. --
  201. 2.49.0