3d01a507fac3956b915154ad886c58f89643f3f4
[openwrt/staging/blogic.git] /
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
5 sensors
6
7 The H616 SoC resembles the H6 thermal sensor controller, with a few
8 changes like four sensors.
9
10 Extend sun50i_h6_ths_calibrate() function to support calibration of
11 these sensors.
12
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
22 ---
23 drivers/thermal/sun8i_thermal.c | 28 ++++++++++++++++++++--------
24 1 file changed, 20 insertions(+), 8 deletions(-)
25
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;
30 int i, ft_temp;
31
32 - if (!caldata[0] || callen < 2 + 2 * tmdev->chip->sensor_num)
33 + if (!caldata[0])
34 return -EINVAL;
35
36 /*
37 * efuse layout:
38 *
39 - * 0 11 16 32
40 - * +-------+-------+-------+
41 - * |temp| |sensor0|sensor1|
42 - * +-------+-------+-------+
43 + * 0 11 16 27 32 43 48 57
44 + * +----------+-----------+-----------+-----------+
45 + * | temp | |sensor0| |sensor1| |sensor2| |
46 + * +----------+-----------+-----------+-----------+
47 + * ^ ^ ^
48 + * | | |
49 + * | | sensor3[11:8]
50 + * | sensor3[7:4]
51 + * sensor3[3:0]
52 *
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;
57
58 for (i = 0; i < tmdev->chip->sensor_num; i++) {
59 - int sensor_reg = caldata[i + 1] & TEMP_CALIB_MASK;
60 - int cdata, offset;
61 - int sensor_temp = tmdev->chip->calc_temp(tmdev, i, sensor_reg);
62 + int sensor_reg, sensor_temp, cdata, offset;
63 +
64 + if (i == 3)
65 + sensor_reg = (caldata[1] >> 12)
66 + | ((caldata[2] >> 12) << 4)
67 + | ((caldata[3] >> 12) << 8);
68 + else
69 + sensor_reg = caldata[i + 1] & TEMP_CALIB_MASK;
70 +
71 + sensor_temp = tmdev->chip->calc_temp(tmdev, i, sensor_reg);
72
73 /*
74 * Calibration data is CALIBRATE_DEFAULT - (calculated