Skip to content

Commit 185673c

Browse files
nfrapradodlezcano
authored andcommitted
thermal/drivers/mediatek/lvts_thermal: Make readings valid in filtered mode
Currently, when a controller is configured to use filtered mode, thermal readings are valid only about 30% of the time. Upon testing, it was noticed that lowering any of the interval settings resulted in an improved rate of valid data. The same was observed when decreasing the number of samples for each sensor (which also results in quicker measurements). Retrying the read with a timeout longer than the time it takes to resample (about 344us with these settings and 4 sensors) also improves the rate. Lower all timing settings to the minimum, configure the filtering to single sample, and poll the measurement register for at least one period to improve the data validity on filtered mode. With these changes in place, out of 100000 reads, a single one failed, ie 99.999% of the data was valid. Reviewed-by: Chen-Yu Tsai <[email protected]> Tested-by: Chen-Yu Tsai <[email protected]> Signed-off-by: Nícolas F. R. A. Prado <[email protected]> Reviewed-by: Alexandre Mergnat <[email protected]> Reviewed-by: AngeloGioacchino Del Regno <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 3ee1f79 commit 185673c

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

drivers/thermal/mediatek/lvts_thermal.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@
5858
#define LVTS_PROTTC(__base) (__base + 0x00CC)
5959
#define LVTS_CLKEN(__base) (__base + 0x00E4)
6060

61-
#define LVTS_PERIOD_UNIT ((118 * 1000) / (256 * 38))
62-
#define LVTS_GROUP_INTERVAL 1
63-
#define LVTS_FILTER_INTERVAL 1
64-
#define LVTS_SENSOR_INTERVAL 1
65-
#define LVTS_HW_FILTER 0x2
61+
#define LVTS_PERIOD_UNIT 0
62+
#define LVTS_GROUP_INTERVAL 0
63+
#define LVTS_FILTER_INTERVAL 0
64+
#define LVTS_SENSOR_INTERVAL 0
65+
#define LVTS_HW_FILTER 0x0
6666
#define LVTS_TSSEL_CONF 0x13121110
6767
#define LVTS_CALSCALE_CONF 0x300
6868
#define LVTS_MONINT_CONF 0x8300318C
@@ -86,6 +86,9 @@
8686
#define LVTS_MSR_IMMEDIATE_MODE 0
8787
#define LVTS_MSR_FILTERED_MODE 1
8888

89+
#define LVTS_MSR_READ_TIMEOUT_US 400
90+
#define LVTS_MSR_READ_WAIT_US (LVTS_MSR_READ_TIMEOUT_US / 2)
91+
8992
#define LVTS_HW_SHUTDOWN_MT8195 105000
9093

9194
#define LVTS_MINIMUM_THRESHOLD 20000
@@ -268,6 +271,7 @@ static int lvts_get_temp(struct thermal_zone_device *tz, int *temp)
268271
struct lvts_sensor *lvts_sensor = thermal_zone_device_priv(tz);
269272
void __iomem *msr = lvts_sensor->msr;
270273
u32 value;
274+
int rc;
271275

272276
/*
273277
* Measurement registers:
@@ -280,7 +284,8 @@ static int lvts_get_temp(struct thermal_zone_device *tz, int *temp)
280284
* 16 : Valid temperature
281285
* 15-0 : Raw temperature
282286
*/
283-
value = readl(msr);
287+
rc = readl_poll_timeout(msr, value, value & BIT(16),
288+
LVTS_MSR_READ_WAIT_US, LVTS_MSR_READ_TIMEOUT_US);
284289

285290
/*
286291
* As the thermal zone temperature will read before the
@@ -293,7 +298,7 @@ static int lvts_get_temp(struct thermal_zone_device *tz, int *temp)
293298
* functionning temperature and directly jump to a system
294299
* shutdown.
295300
*/
296-
if (!(value & BIT(16)))
301+
if (rc)
297302
return -EAGAIN;
298303

299304
*temp = lvts_raw_to_temp(value & 0xFFFF);

0 commit comments

Comments
 (0)