[PATCH v2 4/9] thermal: mediatek: lvts: Add platform ops to support alternative conversion logic
AngeloGioacchino Del Regno
angelogioacchino.delregno at collabora.com
Fri Aug 1 00:28:44 PDT 2025
Il 30/07/25 17:21, Laura Nao ha scritto:
> Introduce lvts_platform_ops struct to support SoC-specific versions of
> lvts_raw_to_temp() and lvts_temp_to_raw() conversion functions.
>
> This is in preparation for supporting SoCs like MT8196/MT6991, which
> require a different lvts_temp_to_raw() implementation.
>
> Signed-off-by: Laura Nao <laura.nao at collabora.com>
> ---
> drivers/thermal/mediatek/lvts_thermal.c | 46 +++++++++++++++++++++++--
> 1 file changed, 43 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c
> index 8398af657ba2..6e4a35ecaf34 100644
> --- a/drivers/thermal/mediatek/lvts_thermal.c
> +++ b/drivers/thermal/mediatek/lvts_thermal.c
> @@ -125,8 +125,14 @@ struct lvts_ctrl_data {
> continue; \
> else
>
> +struct lvts_platform_ops {
> + int (*lvts_raw_to_temp)(u32 raw_temp, int temp_factor);
> + u32 (*lvts_temp_to_raw)(int temperature, int temp_factor);
> +};
> +
> struct lvts_data {
> const struct lvts_ctrl_data *lvts_ctrl;
> + struct lvts_platform_ops ops;
You can constify this one - but then there's something else that we can do here
to waste a bit less memory.
const struct lvts_platform_ops *ops;
const struct lvts_platform_ops lvts_platform_ops_v1 = {
.lvts_raw_to_temp = lvts_raw_to_temp,
.lvts_temp_to_raw = lvts_temp_to_raw,
};
static const struct lvts_data mt8195_lvts_mcu_data = {
[..... stuff .....],
.ops = lvts_platform_ops_v1,
};
....and goes on the same for all the others.
> const u32 *conn_cmd;
> const u32 *init_cmd;
> int num_cal_offsets;
> @@ -300,6 +306,7 @@ static int lvts_get_temp(struct thermal_zone_device *tz, int *temp)
> struct lvts_ctrl *lvts_ctrl = container_of(lvts_sensor, struct lvts_ctrl,
> sensors[lvts_sensor->id]);
> const struct lvts_data *lvts_data = lvts_ctrl->lvts_data;
> + const struct lvts_platform_ops *ops = &lvts_data->ops;
...then here, and everywhere else, it would be just
const struct lvts_platform_ops *ops = lvts_data->ops;
After implementing the proposed change, exactly how I wrote them:
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno at collabora.com>
Cheers,
Angelo
More information about the linux-arm-kernel
mailing list