[PATCH 11/15] media: microchip-isc: skip AWB on near-empty channels

From: Balakrishnan Sambath

Date: Wed Dec 02 2026 - 02:16:50 EST


A channel with only a few pixels left after the trim gives a noisy min,
max and mean, which swings the gains on dark or flat frames.

Track the kept pixel count in ctrls->total_pixels[]. Leave a channel at
offset 0 and gain 1.0 (1 << 9) when it has fewer than frame_pixels / 64
pixels, 64 at least. Leave all gains alone when either green channel is
under the limit, as the green average is the reference for R and B.

Signed-off-by: Balakrishnan Sambath <balakrishnan.s@xxxxxxxxxxxxx>
---
drivers/media/platform/microchip/microchip-isc-base.c | 19 +++++++++++++++++++
drivers/media/platform/microchip/microchip-isc.h | 1 +
2 files changed, 20 insertions(+)

diff --git a/drivers/media/platform/microchip/microchip-isc-base.c b/drivers/media/platform/microchip/microchip-isc-base.c
index 2787de606b4a..491f710fe08d 100644
--- a/drivers/media/platform/microchip/microchip-isc-base.c
+++ b/drivers/media/platform/microchip/microchip-isc-base.c
@@ -1295,6 +1295,7 @@ static void isc_hist_count(struct isc_device *isc, u32 *min, u32 *max)
/* No pixels, a zero average leaves the gains alone */
if (!total_pixels) {
ctrls->channel_avg[ctrls->hist_id] = 0;
+ ctrls->total_pixels[ctrls->hist_id] = 0;
*min = 0;
*max = HIST_ENTRIES - 2;
return;
@@ -1326,6 +1327,7 @@ static void isc_hist_count(struct isc_device *isc, u32 *min, u32 *max)
}

/* The minimum bin is occupied, so pixels is never zero */
+ ctrls->total_pixels[ctrls->hist_id] = pixels;
ctrls->channel_avg[ctrls->hist_id] = div_u64(weighted_sum, pixels);

dev_dbg(isc->dev,
@@ -1339,6 +1341,7 @@ static void isc_wb_update(struct isc_ctrls *ctrls)
struct isc_device *isc = container_of(ctrls, struct isc_device, ctrls);
u32 *channel_avg = &ctrls->channel_avg[0];
u32 c, offset[4];
+ u32 min_pixels;
u64 avg = 0;
/* We compute two gains, stretch gain and grey world gain */
u32 s_gain[4], gw_gain[4];
@@ -1359,7 +1362,23 @@ static void isc_wb_update(struct isc_ctrls *ctrls)
if (!avg)
return;

+ /* A channel under 1/64 of the frame, 64 pixels at least, is noise */
+ min_pixels = max(isc->fmt.fmt.pix.width * isc->fmt.fmt.pix.height >> 6,
+ 64u);
+
+ /* A noisy green skews the average the other gains aim for */
+ if (ctrls->total_pixels[ISC_HIS_CFG_MODE_GR] < min_pixels ||
+ ctrls->total_pixels[ISC_HIS_CFG_MODE_GB] < min_pixels)
+ return;
+
for (c = ISC_HIS_CFG_MODE_GR; c <= ISC_HIS_CFG_MODE_B; c++) {
+ /* Leave the channel neutral, no offset and a gain of 1.0 */
+ if (ctrls->total_pixels[c] < min_pixels) {
+ ctrls->offset[c] = 0;
+ ctrls->gain[c] = 1 << 9;
+ continue;
+ }
+
/*
* the color offset is the minimum value of the histogram.
* we stretch this color to the full range by substracting
diff --git a/drivers/media/platform/microchip/microchip-isc.h b/drivers/media/platform/microchip/microchip-isc.h
index 1784c0089296..2c3efd2fc56e 100644
--- a/drivers/media/platform/microchip/microchip-isc.h
+++ b/drivers/media/platform/microchip/microchip-isc.h
@@ -160,6 +160,7 @@ struct isc_ctrls {
#define HIST_MAX_INDEX 1
u32 hist_minmax[HIST_BAYER][2];
u32 channel_avg[HIST_BAYER];
+ u32 total_pixels[HIST_BAYER];
};

#define ISC_PIPE_LINE_NODE_NUM 15

--
2.34.1