All of lore.kernel.org
 help / color / mirror / Atom feed
From: Frank Li <Frank.li@oss.nxp.com>
To: Haoning.CHENG@cn.bosch.com
Cc: "Rafael J. Wysocki" <rafael@kernel.org>,
	Daniel Lezcano <daniel.lezcano@linaro.org>,
	Zhang Rui <rui.zhang@intel.com>,
	Lukasz Luba <lukasz.luba@arm.com>, Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Shawn Guo <shawnguo@kernel.org>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	Fabio Estevam <festevam@gmail.com>,
	linux-pm@vger.kernel.org, devicetree@vger.kernel.org,
	imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v8 2/3] thermal/drivers/imx: Fix rounding and clamp for i.MX7D alarm
Date: Tue, 14 Jul 2026 09:29:51 -0500	[thread overview]
Message-ID: <alZH33GsKgWdUDOi@SMW015318> (raw)
In-Reply-To: <20260714-b4-symana21-11221-imx-thermal-support-upstream-6-18-v8-2-d54d8690e16e@cn.bosch.com>

On Tue, Jul 14, 2026 at 06:28:42PM +0800, Haoning CHENG via B4 Relay wrote:
> From: Haoning CHENG <Haoning.CHENG@cn.bosch.com>
>
> Convert the alarm temperature from millicelsius to degrees for i.MX7D
> using ceiling division instead of integer division, ensuring rounding
> errors do not cause the alarm to trigger below the intended threshold.
> Use DIV_ROUND_UP() for non-negative values and plain integer division
> for negative values, since C rounds toward zero which is equivalent to
> ceiling when the divisor is positive.
>
> Add clamp() to ensure the hardware register value stays within the 9-bit
> range (0..0x1ff) of the i.MX7D alarm field, preventing silent truncation
> if an out-of-range value is written.
>
> Signed-off-by: Haoning CHENG <Haoning.CHENG@cn.bosch.com>
> ---

Reviewed-by: Frank Li <Frank.Li@nxp.com>

>  drivers/thermal/imx_thermal.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c
> index 38c993d1bcb3..7f7d1116b9d6 100644
> --- a/drivers/thermal/imx_thermal.c
> +++ b/drivers/thermal/imx_thermal.c
> @@ -240,10 +240,16 @@ 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) {
> +		if (alarm_temp >= 0)
> +			alarm_temp = DIV_ROUND_UP(alarm_temp, 1000);
> +		else
> +			alarm_temp /= 1000;
> +		alarm_value = alarm_temp + data->c1 - 25;
> +		alarm_value = clamp(alarm_value, 0, 0x1ff);
> +	} else {
>  		alarm_value = (data->c2 - alarm_temp) / data->c1;
> +	}
>
>  	regmap_write(map, soc_data->high_alarm_ctrl + REG_CLR,
>  		     soc_data->high_alarm_mask);
>
> --
> 2.43.0
>
>
>

  reply	other threads:[~2026-07-14 14:30 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-14 10:28 [PATCH v8 0/3] thermal: imx: Add calibration offset support Haoning CHENG via B4 Relay
2026-07-14 10:28 ` Haoning CHENG
2026-07-14 10:28 ` [PATCH v8 1/3] dt-bindings: thermal: imx: Document calibration offset property Haoning CHENG via B4 Relay
2026-07-14 10:28   ` Haoning CHENG
2026-07-15  7:24   ` Lukasz Luba
2026-07-14 10:28 ` [PATCH v8 2/3] thermal/drivers/imx: Fix rounding and clamp for i.MX7D alarm Haoning CHENG via B4 Relay
2026-07-14 10:28   ` Haoning CHENG
2026-07-14 14:29   ` Frank Li [this message]
2026-07-15  7:29   ` Lukasz Luba
2026-07-14 10:28 ` [PATCH v8 3/3] thermal/drivers/imx: Add calibration offset support Haoning CHENG via B4 Relay
2026-07-14 10:28   ` Haoning CHENG
2026-07-14 11:00   ` sashiko-bot
2026-07-14 14:35   ` Frank Li
2026-07-15  7:30   ` Lukasz Luba
2026-07-15  9:06   ` Frieder Schrempf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alZH33GsKgWdUDOi@SMW015318 \
    --to=frank.li@oss.nxp.com \
    --cc=Haoning.CHENG@cn.bosch.com \
    --cc=conor+dt@kernel.org \
    --cc=daniel.lezcano@linaro.org \
    --cc=devicetree@vger.kernel.org \
    --cc=festevam@gmail.com \
    --cc=imx@lists.linux.dev \
    --cc=kernel@pengutronix.de \
    --cc=krzk+dt@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=lukasz.luba@arm.com \
    --cc=rafael@kernel.org \
    --cc=robh@kernel.org \
    --cc=rui.zhang@intel.com \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.