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=1796195789; b=3IL4teFm9A3YIgduDQ71Yr4vNUwXuW09Qo1smAczO2pRPOEjvxN8GNX58RZdsi+4eevB VrLXh4bBZMZpPjPnVvT8U08/W18Dnu3zqy5GUmL1+159p/Rtp1CxKMjr2y21jpMF1Ol5P segDbBpzy3PTcrANCqMD+ZWawcFpp4D9Vr/KHTLi/4/2vOazOk5uLnSc/2YhewyGXRQwW +3paH0o1jL3aNh063gohbs2OT12kchqvzh1aD88bymzXDXJQvx9dMzF/qLTx3JZP4GeSg hTy8C9abc/PAIpoHcIEHXEgrhNcpSJNNwzC/Mxi8Jn7fRljO26jfNhMnRPX5r/sKTjw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796195789; 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=BJ1zbgyR8ZoilKr1pPALKGFaLtS/2I/eyGICx3fyxT8=; b=oh64JTzqfvBg/mClQY1Qe0kHnjo7u1yyA1z5p+KvsQJVo16RTDqhBoIPQOozY8qLbeyT yMiPq5lp1qd6PX7B/Evgvxu7tgIBAzowObLba8P1lH8+UKnx32/L4UuOXYJ98XtXgH8bQ MhWUBUkbsBPb67JDZiQFir312+28gbQUkcT+JolG2R5LoesUL2HMCv4PHhnYQmT3pFNIm 4zIZsWd7Lj1Q0L1ORXNXsa74zXWKgUBc5d24I8XsY2XhARz5xAN3gjjhgJ4pP1Unhw+zW 5jNo6roL7MCzdhroC3t+WuDKaIbG07wCK4CQoJtKLfR4h0/UcQN1JXJxYBt9+gbtFpA== 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=TfZbRRiP; 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 779D4606A6A6 for ; Wed, 2 Dec 2026 07:16:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 779D4606A6A6 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=TfZbRRiP DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1796195789; x=1827731789; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=YluXCEfjv0UsK1XYHp4LbSfFGWLTTHmb57GMpNazAiw=; b=TfZbRRiPa9KAJ4irBJbl6MPq/qo4ny33NDov2jITsEpAKBxCbAUffIrF yFVgBU097oaQp3Ijlo+RTSSQPg+7RTq81W7PY/7eat4/0oyVUzbNsQMUX BZPkeWAYqRCxuG2x5VniX36UGjV3AwL4IxRKIK5c3yWKkoS5kfRL7v/s5 uIjZMqLR/iF5sglzbjL3dYGFLaPk/L5uU/2FH3wHzajetFVqhKmIspnDh bAJWVerWf+RwkFeKPrHQ5nvryJuJMPZS+44vahLr00xo2/LhwlXdojoI9 hQ+H0n3B2WYhKURkEteV6l2s5bdo6sTmT5DDBs1eUpoGI8LJLT3cm/9rz g==; X-CSE-ConnectionGUID: XrLjD0ifS1GCB6yrHeqthg== X-CSE-MsgGUID: BlaWr2uYR+qrZUco6T1ywQ== X-IronPort-AV: E=Sophos;i="6.27,246,1787036400"; d="scan'208";a="67334012" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa3.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Dec 2026 00:16:29 -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:28 -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:27 -0700 From: Balakrishnan Sambath Date: Wed, 2 Dec 2026 12:46:15 +0530 Subject: [PATCH 09/15] media: microchip-isc: fix histogram bin index for AWB 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-9-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 isc_hist_count() advances hist_entry after each use, so for i = 1..511 it pairs bin i - 1 with weight i. The weighted sum, min and max all come out one bin high. Index hist_entry[i] directly so each bin carries its own weight. The loop still stops short of the last bin, the most white pixels, as the old comment says. min is now the raw bin, so isc_wb_update() uses it as the offset without the old minus one. Fixes: 93d4a26c3dab ("[media] atmel-isc: add the isc pipeline function") Signed-off-by: Balakrishnan Sambath --- .../media/platform/microchip/microchip-isc-base.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/drivers/media/platform/microchip/microchip-isc-base.c b/drivers/media/platform/microchip/microchip-isc-base.c index 3e18933230b8..b2c19879e1c6 100644 --- a/drivers/media/platform/microchip/microchip-isc-base.c +++ b/drivers/media/platform/microchip/microchip-isc-base.c @@ -1277,6 +1277,7 @@ static void isc_hist_count(struct isc_device *isc, u32 *min, u32 *max) struct isc_ctrls *ctrls = &isc->ctrls; u32 *hist_count = &ctrls->hist_count[ctrls->hist_id]; u32 *hist_entry = &ctrls->hist_entry[0]; + bool seen = false; u32 i; *min = 0; @@ -1290,17 +1291,17 @@ static void isc_hist_count(struct isc_device *isc, u32 *min, u32 *max) * we deliberately ignore the end of the histogram, * the most white pixels */ - for (i = 1; i < HIST_ENTRIES; i++) { - if (*hist_entry && !*min) + for (i = 0; i < HIST_ENTRIES - 1; i++) { + if (!hist_entry[i]) + continue; + if (!seen) { *min = i; - if (*hist_entry) - *max = i; - *hist_count += i * (*hist_entry++); + seen = true; + } + *max = i; + *hist_count += i * hist_entry[i]; } - if (!*min) - *min = 1; - dev_dbg(isc->dev, "isc wb: hist_id %u, hist_count %u", ctrls->hist_id, *hist_count); } @@ -1338,15 +1339,13 @@ static void isc_wb_update(struct isc_ctrls *ctrls) */ offset[c] = ctrls->hist_minmax[c][HIST_MIN_INDEX]; /* - * The offset is always at least 1. If the offset is 1, we do - * not need to adjust it, so our result must be zero. * the offset is computed in a histogram on 9 bits (0..512) * but the offset in register is based on * 12 bits pipeline (0..4096). * we need to shift with the 3 bits that the histogram is * ignoring */ - ctrls->offset[c] = (offset[c] - 1) << 3; + ctrls->offset[c] = offset[c] << 3; /* * the offset is then taken and converted to 2's complements, -- 2.34.1