From: Balakrishnan Sambath <balakrishnan.s@microchip.com>
To: <ehristev@kernel.org>
Cc: <linux-kernel@vger.kernel.org>,
Balakrishnan Sambath <balakrishnan.s@microchip.com>
Subject: [PATCH 09/15] media: microchip-isc: fix histogram bin index for AWB
Date: Wed, 2 Dec 2026 12:46:15 +0530 [thread overview]
Message-ID: <20261202-isc-series-v1-v1-9-4e2f17c0271c@microchip.com> (raw)
In-Reply-To: <20261202-isc-series-v1-v1-0-4e2f17c0271c@microchip.com>
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 <balakrishnan.s@microchip.com>
---
.../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
next prev parent reply other threads:[~2026-12-02 7:16 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 7:16 [PATCH 00/15] media: microchip-isc: fix SAMA7G5 image pipeline and AWB Balakrishnan Sambath
2026-12-02 7:16 ` [PATCH 01/15] dt-bindings: media: microchip,xisc: add SAM9X7 compatible Balakrishnan Sambath
2026-12-02 7:16 ` [PATCH 02/15] media: microchip-isc: set SAM9X7 maximum resolution per SoC Balakrishnan Sambath
2026-12-02 7:16 ` [PATCH 03/15] media: microchip-isc: fix DPC black level scale Balakrishnan Sambath
2026-12-02 7:16 ` [PATCH 04/15] media: microchip-isc: enable black level correction on SAMA7G5 Balakrishnan Sambath
2026-12-02 7:16 ` [PATCH 05/15] media: microchip-isc: bypass SAMA7G5 pipeline for Bayer output Balakrishnan Sambath
2026-12-02 7:16 ` [PATCH 06/15] media: microchip-isc: add gamma 1.8 and 2.4 curves for SAMA7G5 Balakrishnan Sambath
2026-12-02 7:16 ` [PATCH 07/15] media: microchip-isc: fix CBHS register names Balakrishnan Sambath
2026-12-02 7:16 ` [PATCH 08/15] media: microchip-isc: add SAMA7G5 hue and saturation controls Balakrishnan Sambath
2026-12-02 7:16 ` Balakrishnan Sambath [this message]
2026-12-02 7:16 ` [PATCH 10/15] media: microchip-isc: trim outliers in the AWB average Balakrishnan Sambath
2026-12-02 7:16 ` [PATCH 11/15] media: microchip-isc: skip AWB on near-empty channels Balakrishnan Sambath
2026-12-02 7:16 ` [PATCH 12/15] media: microchip-isc: do the AWB gain product in 64 bits Balakrishnan Sambath
2026-12-02 7:16 ` [PATCH 13/15] media: microchip-isc: smooth AWB gains with an EMA filter Balakrishnan Sambath
2026-12-02 7:16 ` [PATCH 14/15] media: microchip-isc: use an unsigned contrast range Balakrishnan Sambath
2026-12-02 7:16 ` [PATCH 15/15] media: microchip-isc: add driver documentation Balakrishnan Sambath
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261202-isc-series-v1-v1-9-4e2f17c0271c@microchip.com \
--to=balakrishnan.s@microchip.com \
--cc=ehristev@kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®