Linux-mediatek Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] thermal/drivers/airoha: Fix FIELD_PREP using wrong mask for sensor interval
@ 2026-06-14  0:14 Wayen.Yan
  2026-06-14  7:14 ` Christian Marangi
  0 siblings, 1 reply; 2+ messages in thread
From: Wayen.Yan @ 2026-06-14  0:14 UTC (permalink / raw)
  To: linux-pm
  Cc: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
	Christian Marangi, Lorenzo Bianconi, linux-kernel, linux-mediatek

In airoha_thermal_setup_monitor(), the TEMPMONCTL2 register is
programmed with:

  writel(FIELD_PREP(EN7581_FILT_INTERVAL, 1) |
         FIELD_PREP(EN7581_FILT_INTERVAL, 379), ...)

Both FIELD_PREP calls target FILT_INTERVAL (GENMASK(25,16)), so the
second one overwrites the first. The sensor interval field
SEN_INTERVAL (GENMASK(9,0)) is never written and remains zero.

The comment above states: "filt interval is 1 * 52.715us, sen interval
is 379 * 52.715us", confirming the second value should go into
SEN_INTERVAL. This matches the Mediatek auxadc_thermal.c reference
implementation which correctly writes FILTER_INTERVAL and
SENSOR_INTERVAL to their respective non-overlapping bit fields.

Actual effect: FILT=379 (should be 1), SEN=0 (should be 379).
The filter interval runs 379x too long and the sensor sampling
interval is uninitialized, causing incorrect thermal monitoring timing.

Fix by replacing the second FIELD_PREP's mask from FILT_INTERVAL to
SEN_INTERVAL.

Fixes: 42de37f40e1b ("thermal/drivers: Add support for Airoha EN7581 thermal sensor")
Signed-off-by: Wayen <win847@gmail.com>
---
 drivers/thermal/airoha_thermal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/thermal/airoha_thermal.c b/drivers/thermal/airoha_thermal.c
index b9fd6bfc88..e8a33234e0 100644
--- a/drivers/thermal/airoha_thermal.c
+++ b/drivers/thermal/airoha_thermal.c
@@ -403,7 +403,7 @@ static void airoha_thermal_setup_monitor(struct airoha_thermal_priv *priv)
 	 * sen interval is 379 * 52.715us = 19.97ms
 	 */
 	writel(FIELD_PREP(EN7581_FILT_INTERVAL, 1) |
-	       FIELD_PREP(EN7581_FILT_INTERVAL, 379),
+	       FIELD_PREP(EN7581_SEN_INTERVAL, 379),
 	       priv->base + EN7581_TEMPMONCTL2);
 
 	/* AHB poll is set to 146 * 68.64 = 10.02us */
-- 
2.51.0




^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] thermal/drivers/airoha: Fix FIELD_PREP using wrong mask for sensor interval
  2026-06-14  0:14 [PATCH] thermal/drivers/airoha: Fix FIELD_PREP using wrong mask for sensor interval Wayen.Yan
@ 2026-06-14  7:14 ` Christian Marangi
  0 siblings, 0 replies; 2+ messages in thread
From: Christian Marangi @ 2026-06-14  7:14 UTC (permalink / raw)
  To: Wayen.Yan
  Cc: linux-pm, Rafael J. Wysocki, Daniel Lezcano, Zhang Rui,
	Lukasz Luba, Lorenzo Bianconi, linux-kernel, linux-mediatek

On Sun, Jun 14, 2026 at 08:14:28AM +0800, Wayen.Yan wrote:
> In airoha_thermal_setup_monitor(), the TEMPMONCTL2 register is
> programmed with:
> 
>   writel(FIELD_PREP(EN7581_FILT_INTERVAL, 1) |
>          FIELD_PREP(EN7581_FILT_INTERVAL, 379), ...)
> 
> Both FIELD_PREP calls target FILT_INTERVAL (GENMASK(25,16)), so the
> second one overwrites the first. The sensor interval field
> SEN_INTERVAL (GENMASK(9,0)) is never written and remains zero.
> 
> The comment above states: "filt interval is 1 * 52.715us, sen interval
> is 379 * 52.715us", confirming the second value should go into
> SEN_INTERVAL. This matches the Mediatek auxadc_thermal.c reference
> implementation which correctly writes FILTER_INTERVAL and
> SENSOR_INTERVAL to their respective non-overlapping bit fields.
> 
> Actual effect: FILT=379 (should be 1), SEN=0 (should be 379).
> The filter interval runs 379x too long and the sensor sampling
> interval is uninitialized, causing incorrect thermal monitoring timing.
> 
> Fix by replacing the second FIELD_PREP's mask from FILT_INTERVAL to
> SEN_INTERVAL.
> 
> Fixes: 42de37f40e1b ("thermal/drivers: Add support for Airoha EN7581 thermal sensor")
> Signed-off-by: Wayen <win847@gmail.com>
> ---
>  drivers/thermal/airoha_thermal.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/thermal/airoha_thermal.c b/drivers/thermal/airoha_thermal.c
> index b9fd6bfc88..e8a33234e0 100644
> --- a/drivers/thermal/airoha_thermal.c
> +++ b/drivers/thermal/airoha_thermal.c
> @@ -403,7 +403,7 @@ static void airoha_thermal_setup_monitor(struct airoha_thermal_priv *priv)
>  	 * sen interval is 379 * 52.715us = 19.97ms
>  	 */
>  	writel(FIELD_PREP(EN7581_FILT_INTERVAL, 1) |
> -	       FIELD_PREP(EN7581_FILT_INTERVAL, 379),
> +	       FIELD_PREP(EN7581_SEN_INTERVAL, 379),
>  	       priv->base + EN7581_TEMPMONCTL2);
>  
>  	/* AHB poll is set to 146 * 68.64 = 10.02us */
> -- 
> 2.51.0
> 
>

Hi I already submitted the same patch in the AN7583 series. Can you review
that patch so we can try to push this fix? 

-- 
	Ansuel


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-06-14  7:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-14  0:14 [PATCH] thermal/drivers/airoha: Fix FIELD_PREP using wrong mask for sensor interval Wayen.Yan
2026-06-14  7:14 ` Christian Marangi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox