[PATCH v3 14/15] media: microchip-isc: smooth AWB gains with EMA filter
From: Balakrishnan Sambath
Date: Wed May 13 2026 - 03:21:01 EST
Apply exponential moving average (alpha=0.25) to reduce per-frame
flicker from sensor noise.
Signed-off-by: Balakrishnan Sambath <balakrishnan.s@xxxxxxxxxxxxx>
---
.../platform/microchip/microchip-isc-base.c | 19 ++++++++++++++++---
.../media/platform/microchip/microchip-isc.h | 1 +
2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/drivers/media/platform/microchip/microchip-isc-base.c b/drivers/media/platform/microchip/microchip-isc-base.c
index ea71cf50eb58..80ae8db1ce01 100644
--- a/drivers/media/platform/microchip/microchip-isc-base.c
+++ b/drivers/media/platform/microchip/microchip-isc-base.c
@@ -132,6 +132,7 @@ static inline void isc_reset_awb_ctrls(struct isc_device *isc)
for (c = ISC_HIS_CFG_MODE_GR; c <= ISC_HIS_CFG_MODE_B; c++) {
/* gains have a fixed point at 9 decimals */
isc->ctrls.gain[c] = 1 << 9;
+ isc->ctrls.gain_smooth[c] = 1 << 9;
/* offsets are in 2's complements */
isc->ctrls.offset[c] = 0;
}
@@ -1588,11 +1589,23 @@ static void isc_wb_update(struct isc_ctrls *ctrls)
/* Combine stretch and grey-world gains; result stays in Q9. */
gain = (s_gain * gw_gain) >> 9;
- ctrls->gain[c] = clamp_val(gain, 0, GENMASK(12, 0));
+ /*
+ * Smooth gain updates with an exponential weighted average
+ * to suppress per-frame flicker:
+ * smooth[n] = (3 * smooth[n-1] + gain) / 4
+ * Clamp to the hardware register width to prevent unbounded
+ * accumulation under degenerate (near-empty histogram) inputs.
+ */
+ ctrls->gain_smooth[c] = (3 * ctrls->gain_smooth[c] + gain) / 4;
+ ctrls->gain_smooth[c] = min_t(u32, ctrls->gain_smooth[c],
+ GENMASK(12, 0));
+
+ ctrls->gain[c] = ctrls->gain_smooth[c];
dev_dbg(isc->dev,
- "isc wb: c=%u black=%u avg=%u s_gain=%u gw_gain=%u gain=%u",
- c, hist_min, channel_avg, s_gain, gw_gain, gain);
+ "isc wb: c=%u black=%u avg=%u s_gain=%u gw_gain=%u gain=%u smooth=%u\n",
+ c, hist_min, channel_avg, s_gain, gw_gain, gain,
+ ctrls->gain_smooth[c]);
}
}
diff --git a/drivers/media/platform/microchip/microchip-isc.h b/drivers/media/platform/microchip/microchip-isc.h
index 44d54404250d..e558f1a65b33 100644
--- a/drivers/media/platform/microchip/microchip-isc.h
+++ b/drivers/media/platform/microchip/microchip-isc.h
@@ -155,6 +155,7 @@ struct isc_ctrls {
/* one for each component : GR, R, GB, B */
u32 gain[HIST_BAYER];
+ u32 gain_smooth[HIST_BAYER];
s32 offset[HIST_BAYER];
u32 hist_entry[HIST_ENTRIES];
--
2.34.1