215b0fd7dec9970798d1c5ce48581b89756db142
[openwrt/staging/neocturne.git] /
1 From ca86dbd309ba03bef38ae91f037e2030bb671ab7 Mon Sep 17 00:00:00 2001
2 From: Daniel Golle <daniel@makrotopia.org>
3 Date: Wed, 18 Jan 2023 15:40:39 +0000
4 Subject: [PATCH 03/42] 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 Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
13 Signed-off-by: Daniel Golle <daniel@makrotopia.org>
14 Reviewed-by: Matthias Brugger <matthias.bgg@gmail.com>
15 Link: https://lore.kernel.org/r/69c17529e8418da3eec703dde31e1b01e5b0f7e8.1674055882.git.daniel@makrotopia.org
16 Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
17 ---
18 drivers/thermal/mtk_thermal.c | 17 ++++++++++-------
19 1 file changed, 10 insertions(+), 7 deletions(-)
20
21 --- a/drivers/thermal/mtk_thermal.c
22 +++ b/drivers/thermal/mtk_thermal.c
23 @@ -292,6 +292,8 @@ struct mtk_thermal {
24
25 const struct mtk_thermal_data *conf;
26 struct mtk_thermal_bank banks[MAX_NUM_ZONES];
27 +
28 + int (*raw_to_mcelsius)(struct mtk_thermal *mt, int sensno, s32 raw);
29 };
30
31 /* MT8183 thermal sensor data */
32 @@ -656,13 +658,9 @@ static int mtk_thermal_bank_temperature(
33 for (i = 0; i < conf->bank_data[bank->id].num_sensors; i++) {
34 raw = readl(mt->thermal_base + conf->msr[i]);
35
36 - if (mt->conf->version == MTK_THERMAL_V1) {
37 - temp = raw_to_mcelsius_v1(
38 - mt, conf->bank_data[bank->id].sensors[i], raw);
39 - } else {
40 - temp = raw_to_mcelsius_v2(
41 - mt, conf->bank_data[bank->id].sensors[i], raw);
42 - }
43 + temp = mt->raw_to_mcelsius(
44 + mt, conf->bank_data[bank->id].sensors[i], raw);
45 +
46
47 /*
48 * The first read of a sensor often contains very high bogus
49 @@ -1073,6 +1071,11 @@ static int mtk_thermal_probe(struct plat
50 mtk_thermal_release_periodic_ts(mt, auxadc_base);
51 }
52
53 + if (mt->conf->version == MTK_THERMAL_V1)
54 + mt->raw_to_mcelsius = raw_to_mcelsius_v1;
55 + else
56 + mt->raw_to_mcelsius = raw_to_mcelsius_v2;
57 +
58 for (ctrl_id = 0; ctrl_id < mt->conf->num_controller ; ctrl_id++)
59 for (i = 0; i < mt->conf->num_banks; i++)
60 mtk_thermal_init_bank(mt, i, apmixed_phys_base,