c88bf984fa7952a51cf52bf52e645deb97f09ce3
[openwrt/staging/blocktrron.git] /
1 From c2ab54ab0425388e65901a7af2fbf69ead968708 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, 13 Jul 2023 11:42:37 -0400
5 Subject: [PATCH 33/42] thermal/drivers/mediatek/lvts_thermal: Make readings
6 valid in filtered mode
7 MIME-Version: 1.0
8 Content-Type: text/plain; charset=UTF-8
9 Content-Transfer-Encoding: 8bit
10
11 Currently, when a controller is configured to use filtered mode, thermal
12 readings are valid only about 30% of the time.
13
14 Upon testing, it was noticed that lowering any of the interval settings
15 resulted in an improved rate of valid data. The same was observed when
16 decreasing the number of samples for each sensor (which also results in
17 quicker measurements).
18
19 Retrying the read with a timeout longer than the time it takes to
20 resample (about 344us with these settings and 4 sensors) also improves
21 the rate.
22
23 Lower all timing settings to the minimum, configure the filtering to
24 single sample, and poll the measurement register for at least one period
25 to improve the data validity on filtered mode. With these changes in
26 place, out of 100000 reads, a single one failed, ie 99.999% of the data
27 was valid.
28
29 Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
30 Tested-by: Chen-Yu Tsai <wenst@chromium.org>
31 Signed-off-by: NĂ­colas F. R. A. Prado <nfraprado@collabora.com>
32 Reviewed-by: Alexandre Mergnat <amergnat@baylibre.com>
33 Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
34 Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
35 Link: https://lore.kernel.org/r/20230713154743.611870-1-nfraprado@collabora.com
36 ---
37 drivers/thermal/mediatek/lvts_thermal.c | 19 ++++++++++++-------
38 1 file changed, 12 insertions(+), 7 deletions(-)
39
40 --- a/drivers/thermal/mediatek/lvts_thermal.c
41 +++ b/drivers/thermal/mediatek/lvts_thermal.c
42 @@ -58,11 +58,11 @@
43 #define LVTS_PROTTC(__base) (__base + 0x00CC)
44 #define LVTS_CLKEN(__base) (__base + 0x00E4)
45
46 -#define LVTS_PERIOD_UNIT ((118 * 1000) / (256 * 38))
47 -#define LVTS_GROUP_INTERVAL 1
48 -#define LVTS_FILTER_INTERVAL 1
49 -#define LVTS_SENSOR_INTERVAL 1
50 -#define LVTS_HW_FILTER 0x2
51 +#define LVTS_PERIOD_UNIT 0
52 +#define LVTS_GROUP_INTERVAL 0
53 +#define LVTS_FILTER_INTERVAL 0
54 +#define LVTS_SENSOR_INTERVAL 0
55 +#define LVTS_HW_FILTER 0x0
56 #define LVTS_TSSEL_CONF 0x13121110
57 #define LVTS_CALSCALE_CONF 0x300
58 #define LVTS_MONINT_CONF 0x8300318C
59 @@ -86,6 +86,9 @@
60 #define LVTS_MSR_IMMEDIATE_MODE 0
61 #define LVTS_MSR_FILTERED_MODE 1
62
63 +#define LVTS_MSR_READ_TIMEOUT_US 400
64 +#define LVTS_MSR_READ_WAIT_US (LVTS_MSR_READ_TIMEOUT_US / 2)
65 +
66 #define LVTS_HW_SHUTDOWN_MT8195 105000
67
68 #define LVTS_MINIMUM_THRESHOLD 20000
69 @@ -268,6 +271,7 @@ static int lvts_get_temp(struct thermal_
70 struct lvts_sensor *lvts_sensor = thermal_zone_device_priv(tz);
71 void __iomem *msr = lvts_sensor->msr;
72 u32 value;
73 + int rc;
74
75 /*
76 * Measurement registers:
77 @@ -280,7 +284,8 @@ static int lvts_get_temp(struct thermal_
78 * 16 : Valid temperature
79 * 15-0 : Raw temperature
80 */
81 - value = readl(msr);
82 + rc = readl_poll_timeout(msr, value, value & BIT(16),
83 + LVTS_MSR_READ_WAIT_US, LVTS_MSR_READ_TIMEOUT_US);
84
85 /*
86 * As the thermal zone temperature will read before the
87 @@ -293,7 +298,7 @@ static int lvts_get_temp(struct thermal_
88 * functionning temperature and directly jump to a system
89 * shutdown.
90 */
91 - if (!(value & BIT(16)))
92 + if (rc)
93 return -EAGAIN;
94
95 *temp = lvts_raw_to_temp(value & 0xFFFF);