60942fdb895dd90c83e01094edb2930cd6439966
[openwrt/staging/ansuel.git] /
1 From bd1ccf9408e6155564530af5e09b53ae497fe332 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?N=C3=ADcolas=20F=2E=20R=2E=20A=2E=20Prado?=
3 <nfraprado@collabora.com>
4 Date: Thu, 6 Jul 2023 11:37:36 -0400
5 Subject: [PATCH 29/42] thermal/drivers/mediatek/lvts_thermal: Don't leave
6 threshold zeroed
7 MIME-Version: 1.0
8 Content-Type: text/plain; charset=UTF-8
9 Content-Transfer-Encoding: 8bit
10
11 The thermal framework might leave the low threshold unset if there
12 aren't any lower trip points. This leaves the register zeroed, which
13 translates to a very high temperature for the low threshold. The
14 interrupt for this threshold is then immediately triggered, and the
15 state machine gets stuck, preventing any other temperature monitoring
16 interrupts to ever trigger.
17
18 (The same happens by not setting the Cold or Hot to Normal thresholds
19 when using those)
20
21 Set the unused threshold to a valid low value. This value was chosen so
22 that for any valid golden temperature read from the efuse, when the
23 value is converted to raw and back again to milliCelsius, the result
24 doesn't underflow.
25
26 Fixes: f5f633b18234 ("thermal/drivers/mediatek: Add the Low Voltage Thermal Sensor driver")
27 Signed-off-by: NĂ­colas F. R. A. Prado <nfraprado@collabora.com>
28 Reviewed-by: Alexandre Mergnat <amergnat@baylibre.com>
29 Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
30 Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
31 Link: https://lore.kernel.org/r/20230706153823.201943-6-nfraprado@collabora.com
32 ---
33 drivers/thermal/mediatek/lvts_thermal.c | 12 ++++++------
34 1 file changed, 6 insertions(+), 6 deletions(-)
35
36 --- a/drivers/thermal/mediatek/lvts_thermal.c
37 +++ b/drivers/thermal/mediatek/lvts_thermal.c
38 @@ -83,6 +83,8 @@
39
40 #define LVTS_HW_SHUTDOWN_MT8195 105000
41
42 +#define LVTS_MINIMUM_THRESHOLD 20000
43 +
44 static int golden_temp = LVTS_GOLDEN_TEMP_DEFAULT;
45 static int coeff_b = LVTS_COEFF_B;
46
47 @@ -294,7 +296,7 @@ static int lvts_set_trips(struct thermal
48 {
49 struct lvts_sensor *lvts_sensor = thermal_zone_device_priv(tz);
50 void __iomem *base = lvts_sensor->base;
51 - u32 raw_low = lvts_temp_to_raw(low);
52 + u32 raw_low = lvts_temp_to_raw(low != -INT_MAX ? low : LVTS_MINIMUM_THRESHOLD);
53 u32 raw_high = lvts_temp_to_raw(high);
54
55 /*
56 @@ -306,11 +308,9 @@ static int lvts_set_trips(struct thermal
57 *
58 * 14-0 : Raw temperature for threshold
59 */
60 - if (low != -INT_MAX) {
61 - pr_debug("%s: Setting low limit temperature interrupt: %d\n",
62 - thermal_zone_device_type(tz), low);
63 - writel(raw_low, LVTS_OFFSETL(base));
64 - }
65 + pr_debug("%s: Setting low limit temperature interrupt: %d\n",
66 + thermal_zone_device_type(tz), low);
67 + writel(raw_low, LVTS_OFFSETL(base));
68
69 /*
70 * High offset temperature threshold