Skip to contentSkip to conversation

thermal/drivers/airoha: Fix FIELD_PREP using wrong mask for sensor interval

PATCH In review Wayen.Yan 2 participants 3 messages Jun 14

Subsystems (2)
lore
Share & tools
lore

Wayen.Yan

author
#0 lore raw

PATCH 1/1 thermal/drivers/airoha: Fix FIELD_PREP using wrong mask for sensor interval

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")
---
 drivers/thermal/airoha_thermal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thermal/airoha_thermal.c +1 -1
index b9fd6bfc88..e8a33234e0 100644
@@ -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 */
Signature · 1 line
2.51.0
#1 lore raw
Quoted 46 lines · Wayen.Yan

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")
---
 drivers/thermal/airoha_thermal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thermal/airoha_thermal.c +1 -1
index b9fd6bfc88..e8a33234e0 100644
@@ -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 */
Signature · 1 line
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?

Signature · 1 line
	Ansuel
author Reviewed-by on v1 1/1
#2 lore raw
In reply to Wayen.Yan

Christian Marangi has submitted the same fix in his AN7583 thermal series v5 [1/7] and [2/7]:

https://lore.kernel.org/linux-pm/[email protected]/
https://lore.kernel.org/linux-pm/[email protected]/

I have reviewed his patches and provided Reviewed-by tags. Since his series includes these fixes along with additional AN7583 support, please merge his series instead. This patch can be marked as superseded.