<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">From ca86dbd309ba03bef38ae91f037e2030bb671ab7 Mon Sep 17 00:00:00 2001
From: Daniel Golle &lt;daniel@makrotopia.org&gt;
Date: Wed, 18 Jan 2023 15:40:39 +0000
Subject: [PATCH 03/42] thermal/drivers/mtk: Use function pointer for
 raw_to_mcelsius

Instead of having if-else logic selecting either raw_to_mcelsius_v1 or
raw_to_mcelsius_v2 in mtk_thermal_bank_temperature introduce a function
pointer raw_to_mcelsius to struct mtk_thermal which is initialized in the
probe function.

Reviewed-by: AngeloGioacchino Del Regno &lt;angelogioacchino.delregno@collabora.com&gt;
Signed-off-by: Daniel Golle &lt;daniel@makrotopia.org&gt;
Reviewed-by: Matthias Brugger &lt;matthias.bgg@gmail.com&gt;
Link: https://lore.kernel.org/r/69c17529e8418da3eec703dde31e1b01e5b0f7e8.1674055882.git.daniel@makrotopia.org
Signed-off-by: Daniel Lezcano &lt;daniel.lezcano@linaro.org&gt;
---
 drivers/thermal/mtk_thermal.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

--- a/drivers/thermal/mtk_thermal.c
+++ b/drivers/thermal/mtk_thermal.c
@@ -292,6 +292,8 @@ struct mtk_thermal {
 
 	const struct mtk_thermal_data *conf;
 	struct mtk_thermal_bank banks[MAX_NUM_ZONES];
+
+	int (*raw_to_mcelsius)(struct mtk_thermal *mt, int sensno, s32 raw);
 };
 
 /* MT8183 thermal sensor data */
@@ -656,13 +658,9 @@ static int mtk_thermal_bank_temperature(
 	for (i = 0; i &lt; conf-&gt;bank_data[bank-&gt;id].num_sensors; i++) {
 		raw = readl(mt-&gt;thermal_base + conf-&gt;msr[i]);
 
-		if (mt-&gt;conf-&gt;version == MTK_THERMAL_V1) {
-			temp = raw_to_mcelsius_v1(
-				mt, conf-&gt;bank_data[bank-&gt;id].sensors[i], raw);
-		} else {
-			temp = raw_to_mcelsius_v2(
-				mt, conf-&gt;bank_data[bank-&gt;id].sensors[i], raw);
-		}
+		temp = mt-&gt;raw_to_mcelsius(
+			mt, conf-&gt;bank_data[bank-&gt;id].sensors[i], raw);
+
 
 		/*
 		 * The first read of a sensor often contains very high bogus
@@ -1073,6 +1071,11 @@ static int mtk_thermal_probe(struct plat
 		mtk_thermal_release_periodic_ts(mt, auxadc_base);
 	}
 
+	if (mt-&gt;conf-&gt;version == MTK_THERMAL_V1)
+		mt-&gt;raw_to_mcelsius = raw_to_mcelsius_v1;
+	else
+		mt-&gt;raw_to_mcelsius = raw_to_mcelsius_v2;
+
 	for (ctrl_id = 0; ctrl_id &lt; mt-&gt;conf-&gt;num_controller ; ctrl_id++)
 		for (i = 0; i &lt; mt-&gt;conf-&gt;num_banks; i++)
 			mtk_thermal_init_bank(mt, i, apmixed_phys_base,
</pre></body></html>