Skip to content

Commit a9fae79

Browse files
miquelraynalEduardo Valentin
authored andcommitted
thermal: armada: average over samples to avoid glitches
Configure the sample frequency and number of averaged samples. This is needed for two reasons: 1/ To be bootloader independent. 2/ To prepare the introduction of multi-sensors support by preventing inconsistencies when reading temperatures that could be a mean of samples took from different sensors. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
1 parent 5b5e17a commit a9fae79

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

drivers/thermal/armada_thermal.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@
5454
#define CONTROL0_TSEN_START BIT(0)
5555
#define CONTROL0_TSEN_RESET BIT(1)
5656
#define CONTROL0_TSEN_ENABLE BIT(2)
57+
#define CONTROL0_TSEN_AVG_BYPASS BIT(6)
58+
#define CONTROL0_TSEN_OSR_SHIFT 24
59+
#define CONTROL0_TSEN_OSR_MAX 0x3
5760

61+
#define CONTROL1_TSEN_AVG_SHIFT 0
62+
#define CONTROL1_TSEN_AVG_MASK 0x7
5863
#define CONTROL1_EXT_TSEN_SW_RESET BIT(7)
5964
#define CONTROL1_EXT_TSEN_HW_RESETn BIT(8)
6065

@@ -194,6 +199,13 @@ static void armada_ap806_init(struct platform_device *pdev,
194199
reg = readl_relaxed(priv->control0);
195200
reg &= ~CONTROL0_TSEN_RESET;
196201
reg |= CONTROL0_TSEN_START | CONTROL0_TSEN_ENABLE;
202+
203+
/* Sample every ~2ms */
204+
reg |= CONTROL0_TSEN_OSR_MAX << CONTROL0_TSEN_OSR_SHIFT;
205+
206+
/* Enable average (2 samples by default) */
207+
reg &= ~CONTROL0_TSEN_AVG_BYPASS;
208+
197209
writel(reg, priv->control0);
198210

199211
/* Wait the sensors to be valid or the core will warn the user */
@@ -203,7 +215,20 @@ static void armada_ap806_init(struct platform_device *pdev,
203215
static void armada_cp110_init(struct platform_device *pdev,
204216
struct armada_thermal_priv *priv)
205217
{
218+
u32 reg;
219+
206220
armada380_init(pdev, priv);
221+
222+
/* Sample every ~2ms */
223+
reg = readl_relaxed(priv->control0);
224+
reg |= CONTROL0_TSEN_OSR_MAX << CONTROL0_TSEN_OSR_SHIFT;
225+
writel(reg, priv->control0);
226+
227+
/* Average the output value over 2^1 = 2 samples */
228+
reg = readl_relaxed(priv->control1);
229+
reg &= ~CONTROL1_TSEN_AVG_MASK << CONTROL1_TSEN_AVG_SHIFT;
230+
reg |= 1 << CONTROL1_TSEN_AVG_SHIFT;
231+
writel(reg, priv->control1);
207232
}
208233

209234
static bool armada_is_valid(struct armada_thermal_priv *priv)

0 commit comments

Comments
 (0)