830-v6.4-30-thermal-drivers-mediatek-lvts_thermal-Honor-sensors-.patch 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. From 6d827142643ee10c13ff9a1d90f38fb399aa9fff Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?N=C3=ADcolas=20F=2E=20R=2E=20A=2E=20Prado?=
  3. <[email protected]>
  4. Date: Thu, 6 Jul 2023 11:37:33 -0400
  5. Subject: [PATCH 26/42] thermal/drivers/mediatek/lvts_thermal: Honor sensors in
  6. immediate mode
  7. MIME-Version: 1.0
  8. Content-Type: text/plain; charset=UTF-8
  9. Content-Transfer-Encoding: 8bit
  10. Each controller can be configured to operate on immediate or filtered
  11. mode. On filtered mode, the sensors are enabled by setting the
  12. corresponding bits in MONCTL0, while on immediate mode, by setting
  13. MSRCTL1.
  14. Previously, the code would set MSRCTL1 for all four sensors when
  15. configured to immediate mode, but given that the controller might not
  16. have all four sensors connected, this would cause interrupts to trigger
  17. for non-existent sensors. Fix this by handling the MSRCTL1 register
  18. analogously to the MONCTL0: only enable the sensors that were declared.
  19. Fixes: f5f633b18234 ("thermal/drivers/mediatek: Add the Low Voltage Thermal Sensor driver")
  20. Reviewed-by: AngeloGioacchino Del Regno <[email protected]>
  21. Tested-by: Chen-Yu Tsai <[email protected]>
  22. Signed-off-by: Nícolas F. R. A. Prado <[email protected]>
  23. Reviewed-by: Alexandre Mergnat <[email protected]>
  24. Signed-off-by: Daniel Lezcano <[email protected]>
  25. Link: https://lore.kernel.org/r/[email protected]
  26. ---
  27. drivers/thermal/mediatek/lvts_thermal.c | 57 ++++++++++++++-----------
  28. 1 file changed, 33 insertions(+), 24 deletions(-)
  29. --- a/drivers/thermal/mediatek/lvts_thermal.c
  30. +++ b/drivers/thermal/mediatek/lvts_thermal.c
  31. @@ -897,24 +897,6 @@ static int lvts_ctrl_configure(struct de
  32. writel(value, LVTS_MSRCTL0(lvts_ctrl->base));
  33. /*
  34. - * LVTS_MSRCTL1 : Measurement control
  35. - *
  36. - * Bits:
  37. - *
  38. - * 9: Ignore MSRCTL0 config and do immediate measurement on sensor3
  39. - * 6: Ignore MSRCTL0 config and do immediate measurement on sensor2
  40. - * 5: Ignore MSRCTL0 config and do immediate measurement on sensor1
  41. - * 4: Ignore MSRCTL0 config and do immediate measurement on sensor0
  42. - *
  43. - * That configuration will ignore the filtering and the delays
  44. - * introduced below in MONCTL1 and MONCTL2
  45. - */
  46. - if (lvts_ctrl->mode == LVTS_MSR_IMMEDIATE_MODE) {
  47. - value = BIT(9) | BIT(6) | BIT(5) | BIT(4);
  48. - writel(value, LVTS_MSRCTL1(lvts_ctrl->base));
  49. - }
  50. -
  51. - /*
  52. * LVTS_MONCTL1 : Period unit and group interval configuration
  53. *
  54. * The clock source of LVTS thermal controller is 26MHz.
  55. @@ -979,6 +961,15 @@ static int lvts_ctrl_start(struct device
  56. struct thermal_zone_device *tz;
  57. u32 sensor_map = 0;
  58. int i;
  59. + /*
  60. + * Bitmaps to enable each sensor on immediate and filtered modes, as
  61. + * described in MSRCTL1 and MONCTL0 registers below, respectively.
  62. + */
  63. + u32 sensor_imm_bitmap[] = { BIT(4), BIT(5), BIT(6), BIT(9) };
  64. + u32 sensor_filt_bitmap[] = { BIT(0), BIT(1), BIT(2), BIT(3) };
  65. +
  66. + u32 *sensor_bitmap = lvts_ctrl->mode == LVTS_MSR_IMMEDIATE_MODE ?
  67. + sensor_imm_bitmap : sensor_filt_bitmap;
  68. for (i = 0; i < lvts_ctrl->num_lvts_sensor; i++) {
  69. @@ -1016,20 +1007,38 @@ static int lvts_ctrl_start(struct device
  70. * map, so we can enable the temperature monitoring in
  71. * the hardware thermal controller.
  72. */
  73. - sensor_map |= BIT(i);
  74. + sensor_map |= sensor_bitmap[i];
  75. }
  76. /*
  77. - * Bits:
  78. - * 9: Single point access flow
  79. - * 0-3: Enable sensing point 0-3
  80. - *
  81. * The initialization of the thermal zones give us
  82. * which sensor point to enable. If any thermal zone
  83. * was not described in the device tree, it won't be
  84. * enabled here in the sensor map.
  85. */
  86. - writel(sensor_map | BIT(9), LVTS_MONCTL0(lvts_ctrl->base));
  87. + if (lvts_ctrl->mode == LVTS_MSR_IMMEDIATE_MODE) {
  88. + /*
  89. + * LVTS_MSRCTL1 : Measurement control
  90. + *
  91. + * Bits:
  92. + *
  93. + * 9: Ignore MSRCTL0 config and do immediate measurement on sensor3
  94. + * 6: Ignore MSRCTL0 config and do immediate measurement on sensor2
  95. + * 5: Ignore MSRCTL0 config and do immediate measurement on sensor1
  96. + * 4: Ignore MSRCTL0 config and do immediate measurement on sensor0
  97. + *
  98. + * That configuration will ignore the filtering and the delays
  99. + * introduced in MONCTL1 and MONCTL2
  100. + */
  101. + writel(sensor_map, LVTS_MSRCTL1(lvts_ctrl->base));
  102. + } else {
  103. + /*
  104. + * Bits:
  105. + * 9: Single point access flow
  106. + * 0-3: Enable sensing point 0-3
  107. + */
  108. + writel(sensor_map | BIT(9), LVTS_MONCTL0(lvts_ctrl->base));
  109. + }
  110. return 0;
  111. }