From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=68.232.153.233 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796195793; b=2UVqr0cJSwRyBj1CI/lozKzLKykXmyA9OSHx3MH02t+gGuU0ZSIe1pgVJcAM0EU4yHup avM+VtdCv9dAZKuYGm/qoX5kW/WlHY/sDjGG0gRLnVgM8wZ1AJEPwtE/p5hXfJl3cdrLQ 9I7GQekctctSst6FNzcyRCmPqhbAXaFdXaLh7fs8lz1gU8kGkX/Khqb5t58exvcriFfT8 gL4oG1EHiwaX+g7pkh5tgif9Q644xvH/C9Ft0VCpYV6RQ5i/EdzelOdwQeAc9NKp32Zyl LEwjbSB3dR+ZM/wMD0fuOCzLkEvTjnxAfQ7xSwdbdNLu/vJyLfe8E+wgVU2VD5a7UyA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796195793; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-Amp-Result:Received:Received:Received:From:Date: Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-ID:References:In-Reply-To:To:CC:X-Mailer; bh=MpvWZtZJR5/oTPcZkVtxL5Ul1CASWfzKUOYSyXno/5s=; b=W+eVjSW7WTW19Ssog/IFU/xlofyVIuf3ry9USrcqEGgfgbEGMJwmzzUNQIqeGAQ30C9e +gagI7WcuF9lHHxKhocSC3Y1lkgdK1V00DZ0THT5AFBR/bmIaucI1iXaektZIvRvBiZHQ m1HK/4E1++u85INUsZAg8rCcmMtmxJ8goZEUlH/8ZKpJMdLmYd+I4mf41veh8eBf4HCOb TfBhT8jgtC35WinWCpcgesB9suwWnaq7n0NYP/HpKRHhjKLXYRxWe1ETAZJiofBZK6yG+ u8nlw+atnqk6kXixrxTFT7MK6yuMuFSji5uRhLql/eR1MbialwoPaIqGAi/vHvhxU9w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass header.d=microchip.com header.i=@microchip.com header.a=rsa-sha256 header.s=mchp header.b=e97OZF8h; arc=none smtp.remote-ip=68.232.153.233 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 69655606A692 for ; Wed, 2 Dec 2026 07:16:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 69655606A692 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=microchip.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.a=rsa-sha256 header.s=mchp header.b=e97OZF8h DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1796195793; x=1827731793; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=zB6pjG6bE9BdIbjMZF35hzm1jUeLV4cCr1nui4Di854=; b=e97OZF8hqhT4TUgeO3pDex3nAyFFuee9TxaoNkVXEhQwBF/ukePlMBCQ qmsswK2FuoAyk1CsUbrmwSLqyatFLK9BYtCnftRbBJ5OcpoSJqeJQmILR aMeNWcjIIE/T6vrLm4nw7SgTuyqvTE5Pa+DOATXiL/6pz2nR136oUknNW MT9WlAxhc3Y/j3MUpcszyYbrg768uDYg7OamO0QsJ7bsyX9miuu/mS/3p sMBlz3XsqlTWYmrJkX8SWSfdZF+nVwhmWNWGAnyPd+oYL3h+ili7Dut82 liQvxiVB0LlWxLdwTpiPlUUQWuisK1HhkPn0uJpZV0FgZs/wiK05gE/Mg Q==; X-CSE-ConnectionGUID: csFog11fSb2bm71p9V+cfg== X-CSE-MsgGUID: borzFbTsQ5GyDy8kqWWXCQ== X-IronPort-AV: E=Sophos;i="6.27,246,1787036400"; d="scan'208";a="78213274" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa1.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Dec 2026 00:16:32 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.58; Wed, 2 Dec 2026 00:16:32 -0700 Received: from [127.0.0.1] (10.10.85.11) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2507.58 via Frontend Transport; Wed, 2 Dec 2026 00:16:30 -0700 From: Balakrishnan Sambath Date: Wed, 2 Dec 2026 12:46:17 +0530 Subject: [PATCH 11/15] media: microchip-isc: skip AWB on near-empty channels X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-ID: <20261202-isc-series-v1-v1-11-4e2f17c0271c@microchip.com> References: <20261202-isc-series-v1-v1-0-4e2f17c0271c@microchip.com> In-Reply-To: <20261202-isc-series-v1-v1-0-4e2f17c0271c@microchip.com> To: CC: , Balakrishnan Sambath X-Mailer: b4 0.14.3 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 --- 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