Skip to content

Commit 4f2ee0a

Browse files
dangowrtdlezcano
authored andcommitted
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 <[email protected]> Signed-off-by: Daniel Golle <[email protected]> Reviewed-by: Matthias Brugger <[email protected]> Link: https://lore.kernel.org/r/69c17529e8418da3eec703dde31e1b01e5b0f7e8.1674055882.git.daniel@makrotopia.org Signed-off-by: Daniel Lezcano <[email protected]>
1 parent d69e704 commit 4f2ee0a

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

drivers/thermal/mtk_thermal.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@ struct mtk_thermal {
292292

293293
const struct mtk_thermal_data *conf;
294294
struct mtk_thermal_bank banks[MAX_NUM_ZONES];
295+
296+
int (*raw_to_mcelsius)(struct mtk_thermal *mt, int sensno, s32 raw);
295297
};
296298

297299
/* MT8183 thermal sensor data */
@@ -656,13 +658,9 @@ static int mtk_thermal_bank_temperature(struct mtk_thermal_bank *bank)
656658
for (i = 0; i < conf->bank_data[bank->id].num_sensors; i++) {
657659
raw = readl(mt->thermal_base + conf->msr[i]);
658660

659-
if (mt->conf->version == MTK_THERMAL_V1) {
660-
temp = raw_to_mcelsius_v1(
661-
mt, conf->bank_data[bank->id].sensors[i], raw);
662-
} else {
663-
temp = raw_to_mcelsius_v2(
664-
mt, conf->bank_data[bank->id].sensors[i], raw);
665-
}
661+
temp = mt->raw_to_mcelsius(
662+
mt, conf->bank_data[bank->id].sensors[i], raw);
663+
666664

667665
/*
668666
* The first read of a sensor often contains very high bogus
@@ -1073,6 +1071,11 @@ static int mtk_thermal_probe(struct platform_device *pdev)
10731071
mtk_thermal_release_periodic_ts(mt, auxadc_base);
10741072
}
10751073

1074+
if (mt->conf->version == MTK_THERMAL_V1)
1075+
mt->raw_to_mcelsius = raw_to_mcelsius_v1;
1076+
else
1077+
mt->raw_to_mcelsius = raw_to_mcelsius_v2;
1078+
10761079
for (ctrl_id = 0; ctrl_id < mt->conf->num_controller ; ctrl_id++)
10771080
for (i = 0; i < mt->conf->num_banks; i++)
10781081
mtk_thermal_init_bank(mt, i, apmixed_phys_base,

0 commit comments

Comments
 (0)