c58ae96403ad7d92adea111b6f2bcf0fcab7af07
[openwrt/staging/ansuel.git] /
1 From 69c17529e8418da3eec703dde31e1b01e5b0f7e8 Mon Sep 17 00:00:00 2001
2 From: Daniel Golle <daniel@makrotopia.org>
3 Date: Wed, 18 Jan 2023 02:48:41 +0000
4 Subject: [PATCH 1/2] thermal/drivers/mtk: use function pointer for
5 raw_to_mcelsius
6
7 Instead of having if-else logic selecting either raw_to_mcelsius_v1 or
8 raw_to_mcelsius_v2 in mtk_thermal_bank_temperature introduce a function
9 pointer raw_to_mcelsius to struct mtk_thermal which is initialized in the
10 probe function.
11
12 Signed-off-by: Daniel Golle <daniel@makrotopia.org>
13 ---
14 drivers/thermal/mtk_thermal.c | 17 ++++++++++-------
15 1 file changed, 10 insertions(+), 7 deletions(-)
16
17 --- a/drivers/thermal/mtk_thermal.c
18 +++ b/drivers/thermal/mtk_thermal.c
19 @@ -292,6 +292,8 @@ struct mtk_thermal {
20
21 const struct mtk_thermal_data *conf;
22 struct mtk_thermal_bank banks[MAX_NUM_ZONES];
23 +
24 + int (*raw_to_mcelsius)(struct mtk_thermal *mt, int sensno, s32 raw);
25 };
26
27 /* MT8183 thermal sensor data */
28 @@ -656,13 +658,9 @@ static int mtk_thermal_bank_temperature(
29 for (i = 0; i < conf->bank_data[bank->id].num_sensors; i++) {
30 raw = readl(mt->thermal_base + conf->msr[i]);
31
32 - if (mt->conf->version == MTK_THERMAL_V1) {
33 - temp = raw_to_mcelsius_v1(
34 - mt, conf->bank_data[bank->id].sensors[i], raw);
35 - } else {
36 - temp = raw_to_mcelsius_v2(
37 - mt, conf->bank_data[bank->id].sensors[i], raw);
38 - }
39 + temp = mt->raw_to_mcelsius(
40 + mt, conf->bank_data[bank->id].sensors[i], raw);
41 +
42
43 /*
44 * The first read of a sensor often contains very high bogus
45 @@ -1075,6 +1073,11 @@ static int mtk_thermal_probe(struct plat
46 mtk_thermal_release_periodic_ts(mt, auxadc_base);
47 }
48
49 + if (mt->conf->version == MTK_THERMAL_V1)
50 + mt->raw_to_mcelsius = raw_to_mcelsius_v1;
51 + else
52 + mt->raw_to_mcelsius = raw_to_mcelsius_v2;
53 +
54 for (ctrl_id = 0; ctrl_id < mt->conf->num_controller ; ctrl_id++)
55 for (i = 0; i < mt->conf->num_banks; i++)
56 mtk_thermal_init_bank(mt, i, apmixed_phys_base,