[PATCH v4 2/2] thermal/drivers/imx: Add calibration offset support

Frank Li Frank.li at oss.nxp.com
Fri Jul 10 08:35:12 PDT 2026


On Fri, Jul 10, 2026 at 11:03:37AM +0800, HaoNing Cheng via B4 Relay wrote:
> [You don't often get email from devnull+haoning.cheng.cn.bosch.com at kernel.org. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>
> From: HaoNing Cheng <Haoning.CHENG at cn.bosch.com>
>
> Some boards need a small per-design correction to align the reported CPU
> temperature with board-level measurements.
>
> Read the optional fsl,temp-calibration-offset-millicelsius property from
> DT and apply it to the i.MX6/6SX/7D calibration formulas. When the
> property is not present, the default offset remains 0, preserving the
> current behaviour.
>
> Signed-off-by: HaoNing Cheng <Haoning.CHENG at cn.bosch.com>
> ---
>  drivers/thermal/imx_thermal.c | 18 +++++++++++++-----
>  1 file changed, 13 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c
> index 38c993d1bcb3..8062d34ffed8 100644
> --- a/drivers/thermal/imx_thermal.c
> +++ b/drivers/thermal/imx_thermal.c
> @@ -207,6 +207,7 @@ struct imx_thermal_data {
>         struct regmap *tempmon;
>         u32 c1, c2; /* See formula in imx_init_calib() */
>         int temp_max;
> +       s32 calibration_offset;
>         int alarm_temp;
>         int last_temp;
>         bool irq_enabled;
> @@ -240,10 +241,13 @@ static void imx_set_alarm_temp(struct imx_thermal_data *data,
>
>         data->alarm_temp = alarm_temp;
>
> -       if (data->socdata->version == TEMPMON_IMX7D)
> -               alarm_value = alarm_temp / 1000 + data->c1 - 25;
> -       else
> +       if (data->socdata->version == TEMPMON_IMX7D) {
> +               alarm_value = DIV_ROUND_UP(alarm_temp - data->calibration_offset,
> +                                          1000) + data->c1 - 25;
> +               alarm_value = clamp(alarm_value, 0, 0x1ff);
> +       } else {
>                 alarm_value = (data->c2 - alarm_temp) / data->c1;
> +       }

you can direct change alarm_temp before if block

	alarm_temp -= data->calibration_offset;

which fix for all SoC, not only IMX7D

Frank

>
>         regmap_write(map, soc_data->high_alarm_ctrl + REG_CLR,
>                      soc_data->high_alarm_mask);
> @@ -274,7 +278,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp)
>
>         /* See imx_init_calib() for formula derivation */
>         if (data->socdata->version == TEMPMON_IMX7D)
> -               *temp = (n_meas - data->c1 + 25) * 1000;
> +               *temp = (n_meas - data->c1 + 25) * 1000 + data->calibration_offset;
>         else
>                 *temp = data->c2 - n_meas * data->c1;
>
> @@ -413,7 +417,7 @@ static int imx_init_calib(struct platform_device *pdev, u32 ocotp_ana1)
>         temp64 *= 1000; /* to get result in °mC */
>         do_div(temp64, 15423 * n1 - 4148468);
>         data->c1 = temp64;
> -       data->c2 = n1 * data->c1 + 28581;
> +       data->c2 = n1 * data->c1 + 28581 + data->calibration_offset;
>
>         return 0;
>  }
> @@ -629,6 +633,10 @@ static int imx_thermal_probe(struct platform_device *pdev)
>
>         platform_set_drvdata(pdev, data);
>
> +       of_property_read_s32(dev->of_node,
> +                            "fsl,temp-calibration-offset-millicelsius",
> +                            &data->calibration_offset);
> +
>         if (of_property_present(dev->of_node, "nvmem-cells")) {
>                 ret = imx_init_from_nvmem_cells(pdev);
>                 if (ret)
>
> --
> 2.43.0
>
>
>



More information about the linux-arm-kernel mailing list