1 From 6c04a419a4c5fb18edefc44dd676fb95c7f6c55d Mon Sep 17 00:00:00 2001
2 From: Maksim Kiselev <bigunclemax@gmail.com>
3 Date: Mon, 19 Feb 2024 15:36:36 +0000
4 Subject: [PATCH] thermal/drivers/sun8i: Extend H6 calibration to support 4
7 The H616 SoC resembles the H6 thermal sensor controller, with a few
8 changes like four sensors.
10 Extend sun50i_h6_ths_calibrate() function to support calibration of
13 Co-developed-by: Martin Botka <martin.botka@somainline.org>
14 Signed-off-by: Martin Botka <martin.botka@somainline.org>
15 Signed-off-by: Maksim Kiselev <bigunclemax@gmail.com>
16 Reviewed-by: Andre Przywara <andre.przywara@arm.com>
17 Signed-off-by: Andre Przywara <andre.przywara@arm.com>
18 Reviewed-by: Jernej Skrabec <jernej.skrabec@gmail.com>
19 Acked-by: Vasily Khoruzhick <anarsoul@gmail.com>
20 Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
21 Link: https://lore.kernel.org/r/20240219153639.179814-5-andre.przywara@arm.com
23 drivers/thermal/sun8i_thermal.c | 28 ++++++++++++++++++++--------
24 1 file changed, 20 insertions(+), 8 deletions(-)
26 --- a/drivers/thermal/sun8i_thermal.c
27 +++ b/drivers/thermal/sun8i_thermal.c
28 @@ -224,16 +224,21 @@ static int sun50i_h6_ths_calibrate(struc
29 struct device *dev = tmdev->dev;
32 - if (!caldata[0] || callen < 2 + 2 * tmdev->chip->sensor_num)
40 - * +-------+-------+-------+
41 - * |temp| |sensor0|sensor1|
42 - * +-------+-------+-------+
43 + * 0 11 16 27 32 43 48 57
44 + * +----------+-----------+-----------+-----------+
45 + * | temp | |sensor0| |sensor1| |sensor2| |
46 + * +----------+-----------+-----------+-----------+
53 * The calibration data on the H6 is the ambient temperature and
54 * sensor values that are filled during the factory test stage.
55 @@ -246,9 +251,16 @@ static int sun50i_h6_ths_calibrate(struc
56 ft_temp = (caldata[0] & FT_TEMP_MASK) * 100;
58 for (i = 0; i < tmdev->chip->sensor_num; i++) {
59 - int sensor_reg = caldata[i + 1] & TEMP_CALIB_MASK;
61 - int sensor_temp = tmdev->chip->calc_temp(tmdev, i, sensor_reg);
62 + int sensor_reg, sensor_temp, cdata, offset;
65 + sensor_reg = (caldata[1] >> 12)
66 + | ((caldata[2] >> 12) << 4)
67 + | ((caldata[3] >> 12) << 8);
69 + sensor_reg = caldata[i + 1] & TEMP_CALIB_MASK;
71 + sensor_temp = tmdev->chip->calc_temp(tmdev, i, sensor_reg);
74 * Calibration data is CALIBRATE_DEFAULT - (calculated