Skip to content

Commit 64de162

Browse files
nfrapradodlezcano
authored andcommitted
thermal/drivers/mediatek/lvts_thermal: Honor sensors in immediate mode
Each controller can be configured to operate on immediate or filtered mode. On filtered mode, the sensors are enabled by setting the corresponding bits in MONCTL0, while on immediate mode, by setting MSRCTL1. Previously, the code would set MSRCTL1 for all four sensors when configured to immediate mode, but given that the controller might not have all four sensors connected, this would cause interrupts to trigger for non-existent sensors. Fix this by handling the MSRCTL1 register analogously to the MONCTL0: only enable the sensors that were declared. Fixes: f5f633b ("thermal/drivers/mediatek: Add the Low Voltage Thermal Sensor driver") Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Tested-by: Chen-Yu Tsai <wenst@chromium.org> Signed-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com> Reviewed-by: Alexandre Mergnat <amergnat@baylibre.com> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org> Link: https://lore.kernel.org/r/20230706153823.201943-3-nfraprado@collabora.com
1 parent cbd8c5a commit 64de162

1 file changed

Lines changed: 33 additions & 24 deletions

File tree

drivers/thermal/mediatek/lvts_thermal.c

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -896,24 +896,6 @@ static int lvts_ctrl_configure(struct device *dev, struct lvts_ctrl *lvts_ctrl)
896896
LVTS_HW_FILTER << 3 | LVTS_HW_FILTER;
897897
writel(value, LVTS_MSRCTL0(lvts_ctrl->base));
898898

899-
/*
900-
* LVTS_MSRCTL1 : Measurement control
901-
*
902-
* Bits:
903-
*
904-
* 9: Ignore MSRCTL0 config and do immediate measurement on sensor3
905-
* 6: Ignore MSRCTL0 config and do immediate measurement on sensor2
906-
* 5: Ignore MSRCTL0 config and do immediate measurement on sensor1
907-
* 4: Ignore MSRCTL0 config and do immediate measurement on sensor0
908-
*
909-
* That configuration will ignore the filtering and the delays
910-
* introduced below in MONCTL1 and MONCTL2
911-
*/
912-
if (lvts_ctrl->mode == LVTS_MSR_IMMEDIATE_MODE) {
913-
value = BIT(9) | BIT(6) | BIT(5) | BIT(4);
914-
writel(value, LVTS_MSRCTL1(lvts_ctrl->base));
915-
}
916-
917899
/*
918900
* LVTS_MONCTL1 : Period unit and group interval configuration
919901
*
@@ -979,6 +961,15 @@ static int lvts_ctrl_start(struct device *dev, struct lvts_ctrl *lvts_ctrl)
979961
struct thermal_zone_device *tz;
980962
u32 sensor_map = 0;
981963
int i;
964+
/*
965+
* Bitmaps to enable each sensor on immediate and filtered modes, as
966+
* described in MSRCTL1 and MONCTL0 registers below, respectively.
967+
*/
968+
u32 sensor_imm_bitmap[] = { BIT(4), BIT(5), BIT(6), BIT(9) };
969+
u32 sensor_filt_bitmap[] = { BIT(0), BIT(1), BIT(2), BIT(3) };
970+
971+
u32 *sensor_bitmap = lvts_ctrl->mode == LVTS_MSR_IMMEDIATE_MODE ?
972+
sensor_imm_bitmap : sensor_filt_bitmap;
982973

983974
for (i = 0; i < lvts_ctrl->num_lvts_sensor; i++) {
984975

@@ -1016,20 +1007,38 @@ static int lvts_ctrl_start(struct device *dev, struct lvts_ctrl *lvts_ctrl)
10161007
* map, so we can enable the temperature monitoring in
10171008
* the hardware thermal controller.
10181009
*/
1019-
sensor_map |= BIT(i);
1010+
sensor_map |= sensor_bitmap[i];
10201011
}
10211012

10221013
/*
1023-
* Bits:
1024-
* 9: Single point access flow
1025-
* 0-3: Enable sensing point 0-3
1026-
*
10271014
* The initialization of the thermal zones give us
10281015
* which sensor point to enable. If any thermal zone
10291016
* was not described in the device tree, it won't be
10301017
* enabled here in the sensor map.
10311018
*/
1032-
writel(sensor_map | BIT(9), LVTS_MONCTL0(lvts_ctrl->base));
1019+
if (lvts_ctrl->mode == LVTS_MSR_IMMEDIATE_MODE) {
1020+
/*
1021+
* LVTS_MSRCTL1 : Measurement control
1022+
*
1023+
* Bits:
1024+
*
1025+
* 9: Ignore MSRCTL0 config and do immediate measurement on sensor3
1026+
* 6: Ignore MSRCTL0 config and do immediate measurement on sensor2
1027+
* 5: Ignore MSRCTL0 config and do immediate measurement on sensor1
1028+
* 4: Ignore MSRCTL0 config and do immediate measurement on sensor0
1029+
*
1030+
* That configuration will ignore the filtering and the delays
1031+
* introduced in MONCTL1 and MONCTL2
1032+
*/
1033+
writel(sensor_map, LVTS_MSRCTL1(lvts_ctrl->base));
1034+
} else {
1035+
/*
1036+
* Bits:
1037+
* 9: Single point access flow
1038+
* 0-3: Enable sensing point 0-3
1039+
*/
1040+
writel(sensor_map | BIT(9), LVTS_MONCTL0(lvts_ctrl->base));
1041+
}
10331042

10341043
return 0;
10351044
}

0 commit comments

Comments
 (0)