Commit 4f2ee0aa authored by Daniel Golle's avatar Daniel Golle Committed by Daniel Lezcano
Browse files

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: default avatarAngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Signed-off-by: default avatarDaniel Golle <daniel@makrotopia.org>
Reviewed-by: default avatarMatthias Brugger <matthias.bgg@gmail.com>
Link: https://lore.kernel.org/r/69c17529e8418da3eec703dde31e1b01e5b0f7e8.1674055882.git.daniel@makrotopia.org


Signed-off-by: default avatarDaniel Lezcano <daniel.lezcano@linaro.org>
parent d69e7041
Loading
Loading
Loading
Loading
+10 −7
Original line number Diff line number Diff line
@@ -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(struct mtk_thermal_bank *bank)
	for (i = 0; i < conf->bank_data[bank->id].num_sensors; i++) {
		raw = readl(mt->thermal_base + conf->msr[i]);

		if (mt->conf->version == MTK_THERMAL_V1) {
			temp = raw_to_mcelsius_v1(
		temp = mt->raw_to_mcelsius(
			mt, conf->bank_data[bank->id].sensors[i], raw);
		} else {
			temp = raw_to_mcelsius_v2(
				mt, conf->bank_data[bank->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 platform_device *pdev)
		mtk_thermal_release_periodic_ts(mt, auxadc_base);
	}

	if (mt->conf->version == MTK_THERMAL_V1)
		mt->raw_to_mcelsius = raw_to_mcelsius_v1;
	else
		mt->raw_to_mcelsius = raw_to_mcelsius_v2;

	for (ctrl_id = 0; ctrl_id < mt->conf->num_controller ; ctrl_id++)
		for (i = 0; i < mt->conf->num_banks; i++)
			mtk_thermal_init_bank(mt, i, apmixed_phys_base,