[PATCH v2 15/15] media: microchip-isc: scale DPC black level to sensor bit depth
From: Balakrishnan Sambath
Date: Tue May 12 2026 - 11:54:31 EST
Scale the nominal 10-bit black level (64 counts) to match 8/10/12-bit
sensor bus width.
Signed-off-by: Balakrishnan Sambath <balakrishnan.s@xxxxxxxxxxxxx>
---
.../microchip/microchip-sama7g5-isc.c | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/drivers/media/platform/microchip/microchip-sama7g5-isc.c b/drivers/media/platform/microchip/microchip-sama7g5-isc.c
index 9110690a49e4..46a721d76453 100644
--- a/drivers/media/platform/microchip/microchip-sama7g5-isc.c
+++ b/drivers/media/platform/microchip/microchip-sama7g5-isc.c
@@ -26,6 +26,7 @@
* HIS: Histogram module performs statistic counters on the frames
*/
+#include <linux/bitfield.h>
#include <linux/clk.h>
#include <linux/clkdev.h>
#include <linux/clk-provider.h>
@@ -289,9 +290,25 @@ static void isc_sama7g5_config_dpc(struct isc_device *isc)
{
u32 bay_cfg = isc->config.sd_format->cfa_baycfg;
struct regmap *regmap = isc->regmap;
+ u32 bps, bloff;
+
+ /*
+ * Scale the nominal 10-bit black level offset (64 counts) to the
+ * actual sensor bus width.
+ * ISC_PFE_CFG0_BPS encodes (12 - bit_depth) / 2 in bits[30:28]:
+ * BPS_EIGHT = 4 -> 8-bit -> bloff = 64 >> 2 = 16
+ * BPS_TEN = 2 -> 10-bit -> bloff = 64
+ * BPS_TWELVE = 0 -> 12-bit -> bloff = min(64 << 2, 255) = 255
+ * The BLOFF hardware field is 8-bit so values are clamped to 255.
+ */
+ bps = FIELD_GET(ISC_PFE_CFG0_BPS_MASK, isc->config.sd_format->pfe_cfg0_bps);
+ if (bps >= 2)
+ bloff = 64u >> (bps - 2);
+ else
+ bloff = min(64u << (2 - bps), 255u);
regmap_update_bits(regmap, ISC_DPC_CFG, ISC_DPC_CFG_BLOFF_MASK,
- (64 << ISC_DPC_CFG_BLOFF_SHIFT));
+ (bloff << ISC_DPC_CFG_BLOFF_SHIFT));
regmap_update_bits(regmap, ISC_DPC_CFG, ISC_DPC_CFG_BAYCFG_MASK,
(bay_cfg << ISC_DPC_CFG_BAYCFG_SHIFT));
}
--
2.34.1