linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Peng Fan (OSS)" <peng.fan@oss.nxp.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>,
	 Daniel Lezcano <daniel.lezcano@linaro.org>,
	Zhang Rui <rui.zhang@intel.com>,
	 Lukasz Luba <lukasz.luba@arm.com>,
	Shawn Guo <shawnguo@kernel.org>,
	 Sascha Hauer <s.hauer@pengutronix.de>,
	 Pengutronix Kernel Team <kernel@pengutronix.de>,
	 Fabio Estevam <festevam@gmail.com>, Frank Li <frank.li@nxp.com>
Cc: linux-pm@vger.kernel.org, imx@lists.linux.dev,
	 linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org,  Peng Fan <peng.fan@nxp.com>
Subject: [PATCH 1/3] thermal/drivers/imx91: Check status before reading data
Date: Fri, 12 Dec 2025 15:51:14 +0800	[thread overview]
Message-ID: <20251212-imx91-thermal-v1-1-c208545b44cb@nxp.com> (raw)
In-Reply-To: <20251212-imx91-thermal-v1-0-c208545b44cb@nxp.com>

From: Peng Fan <peng.fan@nxp.com>

Per periodic mode from reference mannual:
Write 1b to CTRL1[START]. Wait until STATm[DRDYn] becomes 1.
Read DATAn[DATA_VAL]. It clears the corresponding STATm[DRDYn].
DATAn[DATA_VAL] and STATm[DRDYn_IF] keep refreshing at a periodic interval
of time, corresponding to PERIOD_CTRL[MEAS_FREQ].

Need to check STAT[DRDY] before reading the DATA register.

And check the returned temperature to make sure it fits into the supported
range (-40°C to +125°C).

Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 drivers/thermal/imx91_thermal.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/thermal/imx91_thermal.c b/drivers/thermal/imx91_thermal.c
index 9b20be03d6dec18553967548d0ca31d1c1fb387c..77e8e6a921c6af308b830c36721293c007256ca6 100644
--- a/drivers/thermal/imx91_thermal.c
+++ b/drivers/thermal/imx91_thermal.c
@@ -108,10 +108,20 @@ static int imx91_tmu_get_temp(struct thermal_zone_device *tz, int *temp)
 {
 	struct imx91_tmu *tmu = thermal_zone_device_priv(tz);
 	s16 data;
+	int ret;
+	u32 val;
+
+	ret = readl_relaxed_poll_timeout(tmu->base + IMX91_TMU_STAT0, val,
+					 val & IMX91_TMU_STAT0_DRDY0_IF_MASK, 1000,
+					 40000);
+	if (ret)
+		return -EAGAIN;
 
 	/* DATA0 is 16bit signed number */
 	data = readw_relaxed(tmu->base + IMX91_TMU_DATA0);
 	*temp = imx91_tmu_to_mcelsius(data);
+	if (*temp < IMX91_TMU_TEMP_LOW_LIMIT || *temp > IMX91_TMU_TEMP_HIGH_LIMIT)
+		return -EAGAIN;
 
 	return 0;
 }

-- 
2.37.1


  reply	other threads:[~2025-12-12  7:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-12  7:51 [PATCH 0/3] thermal/drivers/imx91: minor updates Peng Fan (OSS)
2025-12-12  7:51 ` Peng Fan (OSS) [this message]
2025-12-12 17:25   ` [PATCH 1/3] thermal/drivers/imx91: Check status before reading data Frank Li
2025-12-15  1:36     ` Peng Fan
2025-12-12  7:51 ` [PATCH 2/3] thermal/drivers/imx91: Drop extra spaces Peng Fan (OSS)
2025-12-12 17:29   ` Frank Li
2025-12-12  7:51 ` [PATCH 3/3] thermal/drivers/imx91: Drop macro for continues mode Peng Fan (OSS)

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=20251212-imx91-thermal-v1-1-c208545b44cb@nxp.com \
    --to=peng.fan@oss.nxp.com \
    --cc=daniel.lezcano@linaro.org \
    --cc=festevam@gmail.com \
    --cc=frank.li@nxp.com \
    --cc=imx@lists.linux.dev \
    --cc=kernel@pengutronix.de \
    --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=peng.fan@nxp.com \
    --cc=rafael@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).