From nobody Fri Jun 12 21:11:38 2026 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EA7F93C37B6; Tue, 12 May 2026 15:43:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.154.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778600630; cv=none; b=sST9TMju6rfdKTfJ9eLUjmqBvcO2farBfPopOYq+h7Mz3ltnMBP5fRwXcEUTYWCoIR1wLODn4qHeFMIr7+/ACDnm0f2EALlmGO0oj0+HyNZDkghapRZCX5BtVbgaxcHyMI/2+ZwLY4uohhfbv1q7V8YnRgy22ijwWvva3tUt5+s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778600630; c=relaxed/simple; bh=X0YmPiVlS70Xa4jOMVrIitInitNKZcj46Ur/AgTBx4U=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=iC6+W3dEBPy7ouzn59C8a5XuusLMqCvJJtbP8gkAfWWsvaEW3tjuVM1MnLeZWtj8x309CT7cJ1vd0tOI5kPxAnCZUY4m96AVQy2d0yVhtD5WGVsDRPTAn0t+E6DE17ukX/oa38z5lXShLOEf4ZXo6XMvMoMStlpaHUw2gNNnJqE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=XuzUpvjt; arc=none smtp.client-ip=68.232.154.123 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.b="XuzUpvjt" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1778600627; x=1810136627; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=X0YmPiVlS70Xa4jOMVrIitInitNKZcj46Ur/AgTBx4U=; b=XuzUpvjtOKSbhooPQbyzSPYgp04GrMepTojeRhn3oQL+A16DpTWEINmr OrvCzUc1aCSKPdZDhwB3y5BJqiH3U3fzNga32gWITIVCqIYDkkQ33/IaA mrZYUgqtcmY1MYPkoKuhdsn4Vg0qdLQSIavNZ4PuEKHIBfNFDF1mtKMun Ccwl1RNQATc3O0nqLqRmsDuYVbm38JNU4WPKbS/lpfdLTKrIoUiBaZ2Lj H/QJQ/IVc2a9YGqdnXFJgHLbopVT7ZzJdSqTRN4FRjwPNAZMIU9KX6fkx MmBvx6muwBsW94Z6cVYCi9Iz2vaJ+AduVOL+oK8bqyh2OVPx+2CeIO/nc A==; X-CSE-ConnectionGUID: xBvZ00UpT4WXHpH9pnALyw== X-CSE-MsgGUID: AJjLFOFeQl+GYZrg3tunCA== X-IronPort-AV: E=Sophos;i="6.23,231,1770620400"; d="scan'208";a="224633687" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa6.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 12 May 2026 08:43:46 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.58; Tue, 12 May 2026 08:43:46 -0700 Received: from che-ll-i71840.microchip.com (10.10.85.11) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.58 via Frontend Transport; Tue, 12 May 2026 08:43:43 -0700 From: Balakrishnan Sambath To: CC: , , , , , Subject: [PATCH v2 01/15] media: microchip-isc: fix SBGGR10 Bayer pattern Date: Tue, 12 May 2026 21:13:25 +0530 Message-ID: <20260512154339.210444-2-balakrishnan.s@microchip.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260512154339.210444-1-balakrishnan.s@microchip.com> References: <20251009155251.102472-1-balamanikandan.gunasundar@microchip.com> <20260512154339.210444-1-balakrishnan.s@microchip.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" SBGGR10 was mapped to ISC_BAY_CFG_RGRG instead of ISC_BAY_CFG_BGBG, causing red/blue channel swap. Fixes: 91b4e487b0c6 ("media: microchip: add ISC driver as Microchip ISC") Cc: stable@vger.kernel.org Signed-off-by: Balakrishnan Sambath --- drivers/media/platform/microchip/microchip-sama7g5-isc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/platform/microchip/microchip-sama7g5-isc.c b/dri= vers/media/platform/microchip/microchip-sama7g5-isc.c index b0302dfc3278..ca23e8adecbd 100644 --- a/drivers/media/platform/microchip/microchip-sama7g5-isc.c +++ b/drivers/media/platform/microchip/microchip-sama7g5-isc.c @@ -156,7 +156,7 @@ static struct isc_format sama7g5_formats_list[] =3D { .fourcc =3D V4L2_PIX_FMT_SBGGR10, .mbus_code =3D MEDIA_BUS_FMT_SBGGR10_1X10, .pfe_cfg0_bps =3D ISC_PFG_CFG0_BPS_TEN, - .cfa_baycfg =3D ISC_BAY_CFG_RGRG, + .cfa_baycfg =3D ISC_BAY_CFG_BGBG, }, { .fourcc =3D V4L2_PIX_FMT_SGBRG10, --=20 2.34.1 From nobody Fri Jun 12 21:11:38 2026 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A9EF3C417B; Tue, 12 May 2026 15:43:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.153.233 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778600633; cv=none; b=XY7AbvqTUyTEX0Vd2zAl63wEcJ6UFnP2fDj3dGfNlVIz8pMw0AEtgHx77RAcvyu8AsRNkf0Nt4qwFprCg5IMlxWp+7ZV3yCnpPLpFzNz80ampo1G8KbbDMWDkaOidrn9YZPcLT/xdw/rA2Uw1SDnhaiUV2KpkxKd+zIp/Th0l6I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778600633; c=relaxed/simple; bh=OZ/NoQcSk903dsmx/KLriu0QXhQ9xFJlOklwE77v3A8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sjFpqt+c5lo6XWM7ZQUNohstdy1LPulHzNqAgJTtZ52UgvAglsqoL4l9rs223CA5MHoN4f5zCQrZaSulCZw0ZaO06h6dvbxhsgSBd1G6EzUngLOQ7q8IHVlccjOmxN9LGZeFGA6w02IkGgDatsH7TcraKFf6cXnECTyRe0momzk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=J3cjX2SQ; arc=none smtp.client-ip=68.232.153.233 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.b="J3cjX2SQ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1778600632; x=1810136632; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OZ/NoQcSk903dsmx/KLriu0QXhQ9xFJlOklwE77v3A8=; b=J3cjX2SQoWW4HpMvxQPCPRc4u5axH2oNylkOksjijIHNb5DMS2XWfWHR dl0eX3S0KPdz0o852hgXrPAnMvrgSQMzgHz5uF0fyRgXQeqd8vLLFx7u0 44XrgEqw+h+exWbV+ssGM5YmsiX9B7vd9/VPA+lZb4OEQ0/shvW0wppMw oAbRIYN8OCNXfWZEAhzG7jE3m2lslnyMqBgXHctICYLZ4XOMrWhBdPu/0 1qd+uj/UHdovIWFjaPHZeOY8l8vpJCDY2/2KZCm2apTWPlp1ViXNDrX+6 O2QaIF4QYZNTKxnvv01fEobCTtZ6QS6M7ZaWE6GJWgi9OpzzGl11SmcUc g==; X-CSE-ConnectionGUID: UGBbjlKIQjemmeMGCtx39A== X-CSE-MsgGUID: Gc1JeymaQ3a9f02GofXFFQ== X-IronPort-AV: E=Sophos;i="6.23,231,1770620400"; d="scan'208";a="288760437" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa5.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 May 2026 08:43:51 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.87.72) by chn-vm-ex1.mchp-main.com (10.10.87.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.2562.37; Tue, 12 May 2026 08:43:49 -0700 Received: from che-ll-i71840.microchip.com (10.10.85.11) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.58 via Frontend Transport; Tue, 12 May 2026 08:43:46 -0700 From: Balakrishnan Sambath To: CC: , , , , , Subject: [PATCH v2 02/15] media: microchip-isc: mask WB offset and gain register fields Date: Tue, 12 May 2026 21:13:26 +0530 Message-ID: <20260512154339.210444-3-balakrishnan.s@microchip.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260512154339.210444-1-balakrishnan.s@microchip.com> References: <20251009155251.102472-1-balamanikandan.gunasundar@microchip.com> <20260512154339.210444-1-balakrishnan.s@microchip.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" ISC_WB_O_* and ISC_WB_G_* pack two 13-bit fields per register. Sign extension from negative offsets corrupts the upper field. Mask both fields to 13 bits before packing. Fixes: 3308bec11098 ("at91: isc: integrate pipeline") Cc: stable@vger.kernel.org Signed-off-by: Balakrishnan Sambath --- .../platform/microchip/microchip-isc-base.c | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/drivers/media/platform/microchip/microchip-isc-base.c b/driver= s/media/platform/microchip/microchip-isc-base.c index a7cdc743fda7..45b94f1e89d8 100644 --- a/drivers/media/platform/microchip/microchip-isc-base.c +++ b/drivers/media/platform/microchip/microchip-isc-base.c @@ -61,18 +61,23 @@ static inline void isc_update_awb_ctrls(struct isc_devi= ce *isc) =20 /* In here we set our actual hw pipeline config */ =20 + /* + * Mask offset fields to 13 bits. Sign extension of negative s32 + * values would otherwise corrupt the adjacent field. + */ regmap_write(isc->regmap, ISC_WB_O_RGR, - ((ctrls->offset[ISC_HIS_CFG_MODE_R])) | - ((ctrls->offset[ISC_HIS_CFG_MODE_GR]) << 16)); + ((u32)ctrls->offset[ISC_HIS_CFG_MODE_R] & GENMASK(12, 0)) | + (((u32)ctrls->offset[ISC_HIS_CFG_MODE_GR] & GENMASK(12, 0)) << 16)); regmap_write(isc->regmap, ISC_WB_O_BGB, - ((ctrls->offset[ISC_HIS_CFG_MODE_B])) | - ((ctrls->offset[ISC_HIS_CFG_MODE_GB]) << 16)); + ((u32)ctrls->offset[ISC_HIS_CFG_MODE_B] & GENMASK(12, 0)) | + (((u32)ctrls->offset[ISC_HIS_CFG_MODE_GB] & GENMASK(12, 0)) << 16)); + /* Gains are 13-bit unsigned fields [12:0] and [28:16] */ regmap_write(isc->regmap, ISC_WB_G_RGR, - ctrls->gain[ISC_HIS_CFG_MODE_R] | - (ctrls->gain[ISC_HIS_CFG_MODE_GR] << 16)); + (ctrls->gain[ISC_HIS_CFG_MODE_R] & GENMASK(12, 0)) | + ((ctrls->gain[ISC_HIS_CFG_MODE_GR] & GENMASK(12, 0)) << 16)); regmap_write(isc->regmap, ISC_WB_G_BGB, - ctrls->gain[ISC_HIS_CFG_MODE_B] | - (ctrls->gain[ISC_HIS_CFG_MODE_GB] << 16)); + (ctrls->gain[ISC_HIS_CFG_MODE_B] & GENMASK(12, 0)) | + ((ctrls->gain[ISC_HIS_CFG_MODE_GB] & GENMASK(12, 0)) << 16)); } =20 static inline void isc_reset_awb_ctrls(struct isc_device *isc) --=20 2.34.1 From nobody Fri Jun 12 21:11:38 2026 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 815493C4165; Tue, 12 May 2026 15:43:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.154.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778600636; cv=none; b=rU7V1nMrioHx5GOthh5gHJABTqz/mJpEsuZt4+Wc39RYhso91Pjujc7QBF9dorPx4LpqKgsp9DEUehUgQdVyUfo907ZDyOC9lWUzyTX0rHhJqC4fQA60HecM1nRdY1/pAnJ1fperP74xtISb/bsPT9NQCW2grf8O1BGbGOsrAOk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778600636; c=relaxed/simple; bh=JsQDnXvipvbo4kWLlUqj0uQttCJfUclcjuvwV9jSCyo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VFkbIr8u4/b1mK6EKDhY96t3klhJsVO2o5GNAL8QnW3gFwcIC+d3H9DlAUQHPKZKhvJj6Vxfyg9Ub7/c/Ks2P0rM4UW/Io8/lBvSviEbcPodXDM4NSqzEZuMCmic1dvsjbrF42hh+HtNH3uTkDJKrZx8MVxeqCNsQQU8o86l330= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=tXFGhD/I; arc=none smtp.client-ip=68.232.154.123 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.b="tXFGhD/I" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1778600633; x=1810136633; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JsQDnXvipvbo4kWLlUqj0uQttCJfUclcjuvwV9jSCyo=; b=tXFGhD/IRwmVFKRGbg2uhytG/wTIielU8fVWBq6jCeQgeeNR1DGI7fq8 ZC/AOU/CxOtB93iTumGLCEGTsdBiumWdW63np8BIv2gr1C2a+D3pcHHrS ic44Xr9BctK+hzxTO08axaDiJpYg2xZkLuCIS1frgW3o+nl0ENqg/8ZzA sdpnTWpj2WpGt0XOlI3Gdqi+Fqf5eBV4cziZYtNPYwqd+cDQ1IdIOXUb0 dpxcyd4J66fE75+MJy3A4z7RWDx1agtlDI4Xq/pmW4WkcQCVvuDbWMkfG cxSIQ469WxqFgCajR6xjodJB0t39znVSe4297oCvZw88oraTBSNFGtz4w g==; X-CSE-ConnectionGUID: yOttjrTKT6K8nLB7BgKmQg== X-CSE-MsgGUID: CIreHTtkRfCwHv0OO5uaRg== X-IronPort-AV: E=Sophos;i="6.23,231,1770620400"; d="scan'208";a="224633694" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa6.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 May 2026 08:43:52 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.87.72) by chn-vm-ex3.mchp-main.com (10.10.87.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.2562.37; Tue, 12 May 2026 08:43:52 -0700 Received: from che-ll-i71840.microchip.com (10.10.85.11) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.58 via Frontend Transport; Tue, 12 May 2026 08:43:49 -0700 From: Balakrishnan Sambath To: CC: , , , , , Subject: [PATCH v2 03/15] media: microchip-isc: fix race condition on stream stop Date: Tue, 12 May 2026 21:13:27 +0530 Message-ID: <20260512154339.210444-4-balakrishnan.s@microchip.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260512154339.210444-1-balakrishnan.s@microchip.com> References: <20251009155251.102472-1-balamanikandan.gunasundar@microchip.com> <20260512154339.210444-1-balakrishnan.s@microchip.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Disable histogram and drain AWB work queue before releasing DMA buffers to prevent use-after-free if histogram IRQ fires during stream stop. Fixes: 91b4e487b0c6 ("media: microchip: add ISC driver as Microchip ISC") Cc: stable@vger.kernel.org Signed-off-by: Balakrishnan Sambath --- .../platform/microchip/microchip-isc-base.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/microchip/microchip-isc-base.c b/driver= s/media/platform/microchip/microchip-isc-base.c index 45b94f1e89d8..b19c5a63b4bd 100644 --- a/drivers/media/platform/microchip/microchip-isc-base.c +++ b/drivers/media/platform/microchip/microchip-isc-base.c @@ -427,6 +427,14 @@ static void isc_stop_streaming(struct vb2_queue *vq) =20 mutex_unlock(&isc->awb_mutex); =20 + /* + * Disable the histogram so the ISR stops firing HISREQ, then drain + * any work that was already queued before returning. This must happen + * after releasing awb_mutex because isc_awb_work also takes it. + */ + isc_set_histogram(isc, false); + cancel_work_sync(&isc->awb_work); + /* Disable DMA interrupt */ regmap_write(isc->regmap, ISC_INTDIS, ISC_INT_DDONE); =20 @@ -1519,10 +1527,17 @@ static int isc_s_awb_ctrl(struct v4l2_ctrl *ctrl) } mutex_unlock(&isc->awb_mutex); =20 - /* if we have autowhitebalance on, start histogram procedure */ + /* + * If AWB auto mode is requested and we are streaming RAW, + * start the histogram procedure, but only if it is not + * already running. Repeated enable requests would reset + * hist_id, preventing the 4-channel Bayer cycle from + * completing. + */ if (ctrls->awb =3D=3D ISC_WB_AUTO && vb2_is_streaming(&isc->vb2_vidq) && - ISC_IS_FORMAT_RAW(isc->config.sd_format->mbus_code)) + ISC_IS_FORMAT_RAW(isc->config.sd_format->mbus_code) && + ctrls->hist_stat !=3D HIST_ENABLED) isc_set_histogram(isc, true); =20 /* --=20 2.34.1 From nobody Fri Jun 12 21:11:38 2026 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 40B303C5855; Tue, 12 May 2026 15:43:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.153.233 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778600638; cv=none; b=oUlbreo3Ae/Dnuo+u8RlYbpQ4Y7r9jHb9foc4uoKDqVZsj5zFnlF6TqSjp3j5qRA7Xtn63/C4KgqhKtRAMhraTxqy3LQBMDDtLwoevBbBUuW7WJ/X1klHBwcy/kjoIkocIcZtsLrLY9V3dbjbh+0/yrqSw2+/mY17pH5M3xDFIg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778600638; c=relaxed/simple; bh=KBOyCfytO59B3eLkt3W3y4OYYEa4q8H0EU2Rolfcwok=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EdAklZTxw2KZMY6Aj48tP7WKwtoPcYMaTALmRUcieppooPtufZI6/RRlOmxDgmzE/h1dArXcyxOUYgXS4unfvt+Ti2Qo8Ta4brnhP9bh8XK+QSw1Hhc/SssbgTxfDRQ6k4wOI1REfGbX8nWAFP5iUQdCuIt4NWN11Gm7mIe8bLc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=hJHVujOY; arc=none smtp.client-ip=68.232.153.233 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.b="hJHVujOY" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1778600637; x=1810136637; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KBOyCfytO59B3eLkt3W3y4OYYEa4q8H0EU2Rolfcwok=; b=hJHVujOY1lgsCIQdqqR7yMU82xcX0Ae1kenjSGpvxhXvbq+zx85ISFzY 2bKvXeVtC3FB6l/sI82jWal1HnX11K/JXkHlkZRBGvqsL0rSoq0PAThWM HvwEQ2TF1JYmePH4Z7VUz0iHUzawifj99ZB5lKG5lFTHb/3gDPuytMEze Jw9ycgTwk0xjYvobZcFrhpZ1HosKgiyMpopcRTR71FF4D1wZoCpzxVMTG zK7wAzcehdtTCk1pvEl/LDh6rOnalre9/2iUY2bbqMf64TIt6eOKcpVUz weAAtrckWYHoWT6ls/EyavG0L4eVO30Wzdftx2riQj0BqmXGZPSXB6jec w==; X-CSE-ConnectionGUID: beovU07SRTqav/gjPHMA9g== X-CSE-MsgGUID: k1wnj1dJTC2tyhVpjTBbXA== X-IronPort-AV: E=Sophos;i="6.23,231,1770620400"; d="scan'208";a="65713094" 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; 12 May 2026 08:43:56 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.58; Tue, 12 May 2026 08:43:56 -0700 Received: from che-ll-i71840.microchip.com (10.10.85.11) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.58 via Frontend Transport; Tue, 12 May 2026 08:43:53 -0700 From: Balakrishnan Sambath To: CC: , , , , , Subject: [PATCH v2 04/15] media: microchip-isc: fix PM runtime leak in AWB work handler Date: Tue, 12 May 2026 21:13:28 +0530 Message-ID: <20260512154339.210444-5-balakrishnan.s@microchip.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260512154339.210444-1-balakrishnan.s@microchip.com> References: <20251009155251.102472-1-balamanikandan.gunasundar@microchip.com> <20260512154339.210444-1-balakrishnan.s@microchip.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Early return when streaming stops skips pm_runtime_put_sync(), leaking the reference and preventing runtime suspend. Fixes: 91b4e487b0c6 ("media: microchip: add ISC driver as Microchip ISC") Cc: stable@vger.kernel.org Signed-off-by: Balakrishnan Sambath --- drivers/media/platform/microchip/microchip-isc-base.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/microchip/microchip-isc-base.c b/driver= s/media/platform/microchip/microchip-isc-base.c index b19c5a63b4bd..f61a5d5a3e04 100644 --- a/drivers/media/platform/microchip/microchip-isc-base.c +++ b/drivers/media/platform/microchip/microchip-isc-base.c @@ -1429,7 +1429,7 @@ static void isc_awb_work(struct work_struct *w) /* streaming is not active anymore */ if (isc->stop) { mutex_unlock(&isc->awb_mutex); - return; + goto out_pm_put; } =20 isc_update_profile(isc); @@ -1440,6 +1440,7 @@ static void isc_awb_work(struct work_struct *w) if (ctrls->awb) regmap_write(regmap, ISC_CTRLEN, ISC_CTRL_HISREQ); =20 +out_pm_put: pm_runtime_put_sync(isc->dev); } =20 --=20 2.34.1 From nobody Fri Jun 12 21:11:38 2026 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1F1563C4B7A; Tue, 12 May 2026 15:43:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.153.233 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778600641; cv=none; b=YdL2MMKpHBe+XLzGhCDoQUSS+L8oLPwqHIsuyWy8woj41cvOL9Rehos/zwT2seOl0Xryoa57uc0nNuzZctIbo/K7J/vUDR3XtqqZHBAv5G4QfX5E3eAldZh7OxPNIYxMbYp/Z/FLUrYDb8aVhJXu6OF0Nz1DT9CVZfzcRMTgjyI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778600641; c=relaxed/simple; bh=plHrpEXuH6kFYdgM+b8Q8Q2nKexGKx87z+mC65uBPnM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Mz4n3kl6QNeQHH1Z4P14EK22HIy5pxB1x2uLPXkrqWgyUFqLajxH35iHUh9/Ag9z5N9Ir6MYV5jQLLc8HESSO4g+SN69DulAU7yLh6pGQY65SctgKW1coz756WtOO+rUvibxhT6dzN0H+m0FMJYDo75kt5L+c6Bxt23P1Trt/6U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=0E0mrICE; arc=none smtp.client-ip=68.232.153.233 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.b="0E0mrICE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1778600641; x=1810136641; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=plHrpEXuH6kFYdgM+b8Q8Q2nKexGKx87z+mC65uBPnM=; b=0E0mrICE2S7M/w2nhCZHJrCVfbQX9fWXjfjeiuJY4c5IZtlvghKFS/Qw /vC9PDaKwLRwxcL33TV55G65iOQ8RfCYtyZse9GrxZx5BW3DoMDe9gSqY 9eIog8q2e8iL/gP0bygaBUAl8uSR8Fc4XR15QTM+0GcdR194K9p4WDY+6 eCQBm99y9nNBj6IyVwthd6JKCO0GaUEfzAd0Q++ROo1XCpxxxC+m7VM1K +KNHLl0xztNvBDZs3iGMzB0Df0zge4oHEXTJaXEjjqbhYW4gKzI7GIVlY hPVtRWq4PK5DBc55/o7+QGkrNbFoJ96cFXS574hYxpSuBL0ZNkuxoavEy g==; X-CSE-ConnectionGUID: jmb0ONz/SJGxTZK1UAwgDA== X-CSE-MsgGUID: tYUWy06mSqGsHLL3RlJfBw== X-IronPort-AV: E=Sophos;i="6.23,231,1770620400"; d="scan'208";a="288760443" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa5.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 12 May 2026 08:44:00 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.58; Tue, 12 May 2026 08:43:59 -0700 Received: from che-ll-i71840.microchip.com (10.10.85.11) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.58 via Frontend Transport; Tue, 12 May 2026 08:43:56 -0700 From: Balakrishnan Sambath To: CC: , , , , Subject: [PATCH v2 05/15] media: microchip-isc: add driver documentation Date: Tue, 12 May 2026 21:13:29 +0530 Message-ID: <20260512154339.210444-6-balakrishnan.s@microchip.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260512154339.210444-1-balakrishnan.s@microchip.com> References: <20251009155251.102472-1-balamanikandan.gunasundar@microchip.com> <20260512154339.210444-1-balakrishnan.s@microchip.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Document V4L2 controls and pipeline modes for ISC/XISC camera interface on SAMA5D2, SAMA7G5, and SAM9X7. Signed-off-by: Balakrishnan Sambath --- .../userspace-api/media/drivers/index.rst | 1 + .../media/drivers/microchip-isc.rst | 71 +++++++++++++++++++ MAINTAINERS | 1 + 3 files changed, 73 insertions(+) create mode 100644 Documentation/userspace-api/media/drivers/microchip-isc= .rst diff --git a/Documentation/userspace-api/media/drivers/index.rst b/Document= ation/userspace-api/media/drivers/index.rst index 02967c9b18d6..65ef6ba3523e 100644 --- a/Documentation/userspace-api/media/drivers/index.rst +++ b/Documentation/userspace-api/media/drivers/index.rst @@ -34,6 +34,7 @@ For more details see the file COPYING in the source distr= ibution of Linux. imx-uapi mali-c55 max2175 + microchip-isc npcm-video omap3isp-uapi thp7312 diff --git a/Documentation/userspace-api/media/drivers/microchip-isc.rst b/= Documentation/userspace-api/media/drivers/microchip-isc.rst new file mode 100644 index 000000000000..2a436fd19272 --- /dev/null +++ b/Documentation/userspace-api/media/drivers/microchip-isc.rst @@ -0,0 +1,71 @@ +.. SPDX-License-Identifier: GPL-2.0 + +Microchip ISC/XISC Driver +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D + +The Image Sensor Controller (ISC) on SAMA5D2 and eXtended ISC (XISC) on +SAMA7G5/SAM9X7 provide camera capture with hardware image processing. + +Supported Hardware +------------------ + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +SoC Controller Max Resolution Interface Hue/Saturation +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +SAMA5D2 ISC 2592x1944 12-bit parallel No +SAMA7G5 XISC 3264x2464 12-bit + CSI-2 Yes +SAM9X7 XISC 2560x1920 12-bit + CSI-2 Yes +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +SAM9X7 shares the XISC pipeline with SAMA7G5 but has a smaller internal +line buffer, limiting horizontal resolution to 2560 pixels. + +Controls +-------- + +Standard V4L2 controls: + +* ``V4L2_CID_BRIGHTNESS``: -1024..1023, default 0 +* ``V4L2_CID_CONTRAST``: -2048..2047, default 256 (1.0x) +* ``V4L2_CID_GAMMA``: 0..2 selects curve (0=3D2.4, 1=3D2.2, 2=3D1.8) +* ``V4L2_CID_AUTO_WHITE_BALANCE``: Enable kernel Grey World AWB +* ``V4L2_CID_DO_WHITE_BALANCE``: Trigger one-shot AWB + +SAMA7G5/SAM9X7 add: + +* ``V4L2_CID_HUE``: -180..180 degrees +* ``V4L2_CID_SATURATION``: 0..255, default 16 + +Custom controls (defined in ``atmel-isc-media.h``): + +* ``ISC_CID_R_GAIN``, ``ISC_CID_B_GAIN``, ``ISC_CID_GR_GAIN``, + ``ISC_CID_GB_GAIN``: WB gains, 0..8191, Q2.9 (512 =3D 1.0x) +* ``ISC_CID_R_OFFSET``, ``ISC_CID_B_OFFSET``, ``ISC_CID_GR_OFFSET``, + ``ISC_CID_GB_OFFSET``: WB offsets, -4096..4095 +* ``ISC_CID_CC_RR`` ... ``ISC_CID_CC_BB``: 3x3 color correction matrix, + signed Q4.8 (256 =3D 1.0) +* ``ISC_CID_CC_OR``, ``ISC_CID_CC_OG``, ``ISC_CID_CC_OB``: RGB offsets +* ``ISC_CID_GAMMA_R_LUT``, ``ISC_CID_GAMMA_G_LUT``, + ``ISC_CID_GAMMA_B_LUT``: Per-channel gamma LUTs, 64-entry arrays + +Pipeline +-------- + +Pipeline modules: DPC -> WB -> CFA -> CC -> GAM -> CBHS/CBC -> CSC -> SUB + +* DPC: Defective Pixel Correction (XISC only), black level subtraction + to sensor bit depth, green disparity correction +* WB: White Balance gains/offsets +* CFA: Color Filter Array interpolation (demosaic) +* CC: Color Correction matrix +* GAM: Gamma correction (preset or per-channel LUT) +* CBHS: Contrast/Brightness/Hue/Saturation (XISC only) +* CBC: Contrast/Brightness (ISC only) +* CSC: Color Space Conversion (RGB to YCbCr) +* SUB: Chroma subsampling (4:2:2, 4:2:0) + +Pipeline usage depends on input and output formats: + +* Raw Bayer input, RGB output: DPC, WB, CFA, CC, GAM +* Raw Bayer input, YUV output: Full pipeline including CSC, CBHS/CBC, SUB +* Non-RAW input (YUV/RGB sensor): Pipeline bypassed diff --git a/MAINTAINERS b/MAINTAINERS index 0efa8cc6775b..fe5c3bb03e60 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -17052,6 +17052,7 @@ L: linux-media@vger.kernel.org S: Supported F: Documentation/devicetree/bindings/media/atmel,isc.yaml F: Documentation/devicetree/bindings/media/microchip,xisc.yaml +F: Documentation/userspace-api/media/drivers/microchip-isc.rst F: drivers/media/platform/microchip/microchip-isc* F: drivers/media/platform/microchip/microchip-sama*-isc* F: drivers/staging/media/deprecated/atmel/atmel-isc* --=20 2.34.1 From nobody Fri Jun 12 21:11:38 2026 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 219E53C415C; Tue, 12 May 2026 15:44:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.153.233 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778600644; cv=none; b=cZMIiNt4BQYcIGgr7naSc8HJ88ou0+F3IcYSYhNnQ0do6QEVnX+HlQX6ktENCm4ViPp/cE81Q6Cm3SRqBlxRhW9pcebgfMx9nojnayo/jMrRMv3jBpXPJI90bdFcjEwFG5DBSiAwuan0GGc/ObNp5X8mGuQAyoL3IlVvyKBvaE0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778600644; c=relaxed/simple; bh=w8nsmoBvI5Nekh0BFmQzq54RK2uOMPbGBgKqBFyL42o=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Ug8VX3H/NBv5TArLGyiqmVfRWEu6HfRBbFIhtu9OoYxc76GAzyofvZhzvDpNdLlF3NylWT4bmONnUBOHbvdd1rJLo8MtzAVpfPO8nOmEGZ9BEYBk3gFyCb117KQdqbxnRy5wUlGbCy53Od00Vi8qgnZ9GUxx7atDhQPpWzxuy5I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=BY9AypQy; arc=none smtp.client-ip=68.232.153.233 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.b="BY9AypQy" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1778600644; x=1810136644; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=w8nsmoBvI5Nekh0BFmQzq54RK2uOMPbGBgKqBFyL42o=; b=BY9AypQymnGocYmGyusb09QNbqGCX1YDwngpOFJ6OVZ0WZySii0Yi5rW DieuxTdf5AY0ei72QR29OhJ4dpkAssYolSyNJoqQ3Tnp5HSaop6WMJ40P MnNoC+WOpjZBnf8TXaluYYflsK1yWCpSesGVCtNRCP93HlTtk8eCyaRYh 8Sw8Rmmlsnneyuk5xuk9aMvc/BbHCQ8a5/6IdN8sTmr9EipmEhc0Z7aER d6n6YCQoAuuzyTaCXvLi3q760a+0EWTJ6dfvKRxkUrSfaQGJe0VYhL6G7 CgtiHOo3bNsAwdq/bs16rH4RaI+Q0yWz23yLiKnp5HiBLnGKxgT8END/+ g==; X-CSE-ConnectionGUID: zMjq2GC+Sk+xobAr1B/09A== X-CSE-MsgGUID: jpnBOucYS7SjGmq2CErA/A== X-IronPort-AV: E=Sophos;i="6.23,231,1770620400"; d="scan'208";a="288760449" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa5.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 12 May 2026 08:44:03 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.58; Tue, 12 May 2026 08:44:02 -0700 Received: from che-ll-i71840.microchip.com (10.10.85.11) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.58 via Frontend Transport; Tue, 12 May 2026 08:43:59 -0700 From: Balakrishnan Sambath To: CC: , , , , , "Balamanikandan Gunasundar" Subject: [PATCH v2 06/15] media: microchip-isc: set SAM9X7 maximum resolution to 2560x1920 Date: Tue, 12 May 2026 21:13:30 +0530 Message-ID: <20260512154339.210444-7-balakrishnan.s@microchip.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260512154339.210444-1-balakrishnan.s@microchip.com> References: <20251009155251.102472-1-balamanikandan.gunasundar@microchip.com> <20260512154339.210444-1-balakrishnan.s@microchip.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" SAM9X7 XISC uses the same image processing pipeline as SAMA7G5 but has a smaller internal line buffer. The reduced RAM constrains the maximum horizontal resolution to 2560 pixels (compared to 3264 on SAMA7G5), resulting in a maximum capture resolution of 2560x1920. Signed-off-by: Balamanikandan Gunasundar Signed-off-by: Balakrishnan Sambath --- .../media/platform/microchip/microchip-sama7g5-isc.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/microchip/microchip-sama7g5-isc.c b/dri= vers/media/platform/microchip/microchip-sama7g5-isc.c index ca23e8adecbd..4119cfe12cdf 100644 --- a/drivers/media/platform/microchip/microchip-sama7g5-isc.c +++ b/drivers/media/platform/microchip/microchip-sama7g5-isc.c @@ -55,6 +55,9 @@ #define ISC_SAMA7G5_MAX_SUPPORT_WIDTH 3264 #define ISC_SAMA7G5_MAX_SUPPORT_HEIGHT 2464 =20 +#define ISC_SAM9X7_MAX_SUPPORT_WIDTH 2560 +#define ISC_SAM9X7_MAX_SUPPORT_HEIGHT 1920 + #define ISC_SAMA7G5_PIPELINE \ (WB_ENABLE | CFA_ENABLE | CC_ENABLE | GAM_ENABLES | CSC_ENABLE | \ CBC_ENABLE | SUB422_ENABLE | SUB420_ENABLE) @@ -432,8 +435,13 @@ static int microchip_xisc_probe(struct platform_device= *pdev) isc->gamma_table =3D isc_sama7g5_gamma_table; isc->gamma_max =3D 0; =20 - isc->max_width =3D ISC_SAMA7G5_MAX_SUPPORT_WIDTH; - isc->max_height =3D ISC_SAMA7G5_MAX_SUPPORT_HEIGHT; + if (of_machine_is_compatible("microchip,sam9x7")) { + isc->max_width =3D ISC_SAM9X7_MAX_SUPPORT_WIDTH; + isc->max_height =3D ISC_SAM9X7_MAX_SUPPORT_HEIGHT; + } else { + isc->max_width =3D ISC_SAMA7G5_MAX_SUPPORT_WIDTH; + isc->max_height =3D ISC_SAMA7G5_MAX_SUPPORT_HEIGHT; + } =20 isc->config_dpc =3D isc_sama7g5_config_dpc; isc->config_csc =3D isc_sama7g5_config_csc; --=20 2.34.1 From nobody Fri Jun 12 21:11:38 2026 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E25A3C4B89; Tue, 12 May 2026 15:44:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.154.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778600648; cv=none; b=LmqqftAn2xWf6THxdGytEdhf7iz0iSZ+JoE/sBBygv4XrgbqMkaxIQvNQfNJsv3CV8dcEOTVrdJGlE6yHRAH0kJbNNiz7gzxwZ/c43WxAt+Ybka/7f68TvS3PlWUY62X7e+U7lYh0DxywzJR7VRYALX1y0VkygN9Aw20+UeOWlE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778600648; c=relaxed/simple; bh=RhJYAoeL6NtWiQnFs8Rwn3lmLWMOs3QTN0Vdn5x96s4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dS7n4uKsMln0a1NlIjfU1VOQY+POa9KRE8AQqLFMtvYgIpr3tu8xfpquNmvhV4Y+gkXzLrN152Lx6GzHv8tKjmGEPYjBSMVeFWUaz4aoog1Tur6i2txTKxq/aQCha+xxVSkCuurjRG9Ohsw76Dmi7/HNsTI7/ZiwKdiARYolIuE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=RwG0mOtH; arc=none smtp.client-ip=68.232.154.123 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.b="RwG0mOtH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1778600646; x=1810136646; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RhJYAoeL6NtWiQnFs8Rwn3lmLWMOs3QTN0Vdn5x96s4=; b=RwG0mOtHKYYc1YNBGNii47z/65Pra8TVCQ44TEal6IjBkTnJm5nN4/kz glIVrhLRV6exXfeHT/UfU163SMJY95tNrRLxdOt6M7dSpmRQ8TjIlNvmW enf08cQjh6ZsIRCGBM07kVXHDvi0XpYlAgTidEv51apGCH5jQgN3QkS7U dkcxyEWs9keungAX6tJMEIkGEg7WFcY7x6HWxBhMEXNlkooIDnGTMvGE1 q08iL6dXkngr72CKuC3FXLXEerWD7w+H4a+ITudwc+uPAY2Oa+ZFiXKLZ YqLuVICCSp9/8gVUAIE1R60YjqA+i5kdmkgHPvQotd2GPggXhjki+uLQm Q==; X-CSE-ConnectionGUID: c/d2dmHeT12wfTerVaKHaA== X-CSE-MsgGUID: 1n1mzC1ORyWxnWw6kFNLRw== X-IronPort-AV: E=Sophos;i="6.23,231,1770620400"; d="scan'208";a="224633710" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa6.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 May 2026 08:44:06 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.87.72) by chn-vm-ex3.mchp-main.com (10.10.87.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.2562.37; Tue, 12 May 2026 08:44:05 -0700 Received: from che-ll-i71840.microchip.com (10.10.85.11) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.58 via Frontend Transport; Tue, 12 May 2026 08:44:02 -0700 From: Balakrishnan Sambath To: CC: , , , , , "Balamanikandan Gunasundar" Subject: [PATCH v2 07/15] media: microchip-isc: configure DPC and pipeline for SAMA7G5 Date: Tue, 12 May 2026 21:13:31 +0530 Message-ID: <20260512154339.210444-8-balakrishnan.s@microchip.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260512154339.210444-1-balakrishnan.s@microchip.com> References: <20251009155251.102472-1-balamanikandan.gunasundar@microchip.com> <20260512154339.210444-1-balakrishnan.s@microchip.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Enable DPC_GDCENABLE for RGB output. Disable pipeline for raw Bayer passthrough to provide unmodified sensor data for software ISP. Signed-off-by: Balamanikandan Gunasundar Signed-off-by: Balakrishnan Sambath --- drivers/media/platform/microchip/microchip-isc-base.c | 7 ++----- drivers/media/platform/microchip/microchip-sama7g5-isc.c | 3 ++- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/media/platform/microchip/microchip-isc-base.c b/driver= s/media/platform/microchip/microchip-isc-base.c index f61a5d5a3e04..23a09ed12946 100644 --- a/drivers/media/platform/microchip/microchip-isc-base.c +++ b/drivers/media/platform/microchip/microchip-isc-base.c @@ -800,7 +800,7 @@ static int isc_try_configure_pipeline(struct isc_device= *isc) if (ISC_IS_FORMAT_RAW(isc->try_config.sd_format->mbus_code)) { isc->try_config.bits_pipeline =3D CFA_ENABLE | WB_ENABLE | GAM_ENABLES | DPC_BLCENABLE | - CC_ENABLE; + DPC_GDCENABLE | CC_ENABLE; } else { isc->try_config.bits_pipeline =3D 0x0; } @@ -850,10 +850,7 @@ static int isc_try_configure_pipeline(struct isc_devic= e *isc) } break; default: - if (ISC_IS_FORMAT_RAW(isc->try_config.sd_format->mbus_code)) - isc->try_config.bits_pipeline =3D WB_ENABLE | DPC_BLCENABLE; - else - isc->try_config.bits_pipeline =3D 0x0; + isc->try_config.bits_pipeline =3D 0x0; } =20 /* Tune the pipeline to product specific */ diff --git a/drivers/media/platform/microchip/microchip-sama7g5-isc.c b/dri= vers/media/platform/microchip/microchip-sama7g5-isc.c index 4119cfe12cdf..04930aa0f289 100644 --- a/drivers/media/platform/microchip/microchip-sama7g5-isc.c +++ b/drivers/media/platform/microchip/microchip-sama7g5-isc.c @@ -59,7 +59,8 @@ #define ISC_SAM9X7_MAX_SUPPORT_HEIGHT 1920 =20 #define ISC_SAMA7G5_PIPELINE \ - (WB_ENABLE | CFA_ENABLE | CC_ENABLE | GAM_ENABLES | CSC_ENABLE | \ + (DPC_DPCENABLE | DPC_GDCENABLE | DPC_BLCENABLE | \ + WB_ENABLE | CFA_ENABLE | CC_ENABLE | GAM_ENABLES | CSC_ENABLE | \ CBC_ENABLE | SUB422_ENABLE | SUB420_ENABLE) =20 /* This is a list of the formats that the ISC can *output* */ --=20 2.34.1 From nobody Fri Jun 12 21:11:38 2026 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 30C833C5826; Tue, 12 May 2026 15:44:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.153.233 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778600651; cv=none; b=U0qMvW4LG/5A22/gjH4qnliulIhd5ogwwV15j1o0GpMC1ADA2Q13FnbWp4T0bkCgfuZCi8F3x/RrBaZXBV2PYQi2przVPjRElAgb15DIXHJRRno6I0fJY1KM3BGSr2Es++xKanX000UnJkVkYcFDO8OGw8EA3smK5Ts7z0mbHKE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778600651; c=relaxed/simple; bh=uYJv336XuF21R7tlG7gdsFm+BJb9UM1WlGAQfCOXfXo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=T7SiprFVlJT+ar5hTX24PKHzbDAdtTkYxByiAVACyDUiXwOWJyE2tcSLw86whsAchOJ0jA6lnv9NORd7b/+29JbqT2uCFRXEmFe1dUl7LK34ZV0EY1pms4IknsJFL4iKHuUeva1u5io/zpCVlrgkXJ5BvE4SZWg/JIr65Z19Olg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=UJxThwQh; arc=none smtp.client-ip=68.232.153.233 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.b="UJxThwQh" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1778600650; x=1810136650; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uYJv336XuF21R7tlG7gdsFm+BJb9UM1WlGAQfCOXfXo=; b=UJxThwQhzDRbwsWNGEl5YU0kUyYK47T/iA2IDN2n3HN7kOxGPHOdCTg2 mLDUInyWQ1I7LblWfbeXPunY+SMyTwJ7+Kj6yyjVbzo8+/3AHdrZ0p/Rc kn4DLaedc2dxB11xkr409dSf6ZCNlP2kbFJp/gKM3pcoy4l3Y0M6Pxm32 46ljunew852iCpgrELls0/LTMx+9ruXWnVBHaLhtNwcS9NoOngdfyXEka ByNGLPOkoIT2LbbC2urDkXKLVtMI/+x4ZwcjWcSqCSM07anMnJ6fuT8Z0 M1kMfn9oV6zMff11HyDaELv5Xis6TQJN5jiSDCgaDh9ywFbf23WQvwTfn Q==; X-CSE-ConnectionGUID: UpSH/YpTSxqlzkc+jPyXEw== X-CSE-MsgGUID: jAqw9u3UQS2paxLkY75+GQ== X-IronPort-AV: E=Sophos;i="6.23,231,1770620400"; d="scan'208";a="65713106" 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-AES256-GCM-SHA384; 12 May 2026 08:44:09 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.87.72) by chn-vm-ex3.mchp-main.com (10.10.87.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.2562.37; Tue, 12 May 2026 08:44:09 -0700 Received: from che-ll-i71840.microchip.com (10.10.85.11) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.58 via Frontend Transport; Tue, 12 May 2026 08:44:06 -0700 From: Balakrishnan Sambath To: CC: , , , , , "Balamanikandan Gunasundar" Subject: [PATCH v2 08/15] media: microchip-isc: add gamma 1.8 and 2.4 correction curves Date: Tue, 12 May 2026 21:13:32 +0530 Message-ID: <20260512154339.210444-9-balakrishnan.s@microchip.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260512154339.210444-1-balakrishnan.s@microchip.com> References: <20251009155251.102472-1-balamanikandan.gunasundar@microchip.com> <20260512154339.210444-1-balakrishnan.s@microchip.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add gamma 1.8 and 2.4 curves alongside the existing 2.2 (sRGB). V4L2_CID_GAMMA selects preset curves: 0=3D2.4, 1=3D2.2, 2=3D1.8. Signed-off-by: Balamanikandan Gunasundar Signed-off-by: Balakrishnan Sambath --- .../platform/microchip/microchip-isc-base.c | 3 +- .../microchip/microchip-sama7g5-isc.c | 54 ++++++++++++++----- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/drivers/media/platform/microchip/microchip-isc-base.c b/driver= s/media/platform/microchip/microchip-isc-base.c index 23a09ed12946..ae2a0c6ba566 100644 --- a/drivers/media/platform/microchip/microchip-isc-base.c +++ b/drivers/media/platform/microchip/microchip-isc-base.c @@ -1647,8 +1647,7 @@ static int isc_ctrl_init(struct isc_device *isc) ctrls->brightness =3D 0; =20 v4l2_ctrl_new_std(hdl, ops, V4L2_CID_BRIGHTNESS, -1024, 1023, 1, 0); - v4l2_ctrl_new_std(hdl, ops, V4L2_CID_GAMMA, 0, isc->gamma_max, 1, - isc->gamma_max); + v4l2_ctrl_new_std(hdl, ops, V4L2_CID_GAMMA, 0, isc->gamma_max, 1, 1); isc->awb_ctrl =3D v4l2_ctrl_new_std(hdl, &isc_awb_ops, V4L2_CID_AUTO_WHITE_BALANCE, 0, 1, 1, 1); diff --git a/drivers/media/platform/microchip/microchip-sama7g5-isc.c b/dri= vers/media/platform/microchip/microchip-sama7g5-isc.c index 04930aa0f289..8b73b625d92b 100644 --- a/drivers/media/platform/microchip/microchip-sama7g5-isc.c +++ b/drivers/media/platform/microchip/microchip-sama7g5-isc.c @@ -320,21 +320,47 @@ static void isc_sama7g5_adapt_pipeline(struct isc_dev= ice *isc) isc->try_config.bits_pipeline &=3D ISC_SAMA7G5_PIPELINE; } =20 -/* Gamma table with gamma 1/2.2 */ +/* Gamma tables with gamma values 0.42, 0.45(Default), 0.56 */ static const u32 isc_sama7g5_gamma_table[][GAMMA_ENTRIES] =3D { - /* index 0 --> gamma bipartite */ + /* index 0 --> gamma bipartite 1/2.4(=3D0.42) */ { - 0x980, 0x4c0320, 0x650260, 0x7801e0, 0x8701a0, 0x940180, - 0xa00160, 0xab0120, 0xb40120, 0xbd0120, 0xc60100, 0xce0100, - 0xd600e0, 0xdd00e0, 0xe400e0, 0xeb00c0, 0xf100c0, 0xf700c0, - 0xfd00c0, 0x10300a0, 0x10800c0, 0x10e00a0, 0x11300a0, 0x11800a0, - 0x11d00a0, 0x12200a0, 0x12700a0, 0x12c0080, 0x13000a0, 0x1350080, - 0x13900a0, 0x13e0080, 0x1420076, 0x17d0062, 0x1ae0054, 0x1d8004a, - 0x1fd0044, 0x21f003e, 0x23e003a, 0x25b0036, 0x2760032, 0x28f0030, - 0x2a7002e, 0x2be002c, 0x2d4002c, 0x2ea0028, 0x2fe0028, 0x3120026, - 0x3250024, 0x3370024, 0x3490022, 0x35a0022, 0x36b0020, 0x37b0020, - 0x38b0020, 0x39b001e, 0x3aa001e, 0x3b9001c, 0x3c7001c, 0x3d5001c, - 0x3e3001c, 0x3f1001c, 0x3ff001a, 0x40c001a }, + 0x940, 0x4b0310, 0x630250, 0x7601d0, 0x840190, 0x910170, + 0x9d0150, 0xa80110, 0xb10110, 0xba0110, 0xc300f0, 0xcb00f0, + 0xd300e0, 0xda00e0, 0xe100c0, 0xe800c0, 0xee00c0, 0xf400c0, + 0xfa00a0, 0x10000a0, 0x10500a0, 0x10b00a0, 0x11000a0, 0x11500a0, + 0x11a0080, 0x11f0080, 0x1240080, 0x1290080, 0x12e0080, 0x1330070, + 0x1380070, 0x13c0070, 0x1410070, 0x17a0060, 0x1aa0052, 0x1d40046, + 0x1f90042, 0x21b003c, 0x23a0038, 0x2570034, 0x2720030, 0x28b002e, + 0x2a3002c, 0x2ba002a, 0x2d0002a, 0x2e60028, 0x2fa0026, 0x30e0026, + 0x3210024, 0x3330022, 0x3450022, 0x3560020, 0x3670020, 0x3770020, + 0x387001e, 0x396001e, 0x3a5001c, 0x3b3001c, 0x3c1001c, 0x3cf001a, + 0x3dd001a, 0x3eb0018, 0x3f90018, 0x4070016 }, + /* index 1 --> gamma bipartite 1/2.2(=3D0.45) */ + { + 0x980, 0x4c0320, 0x650260, 0x7801e0, 0x8701a0, 0x940180, + 0xa00160, 0xab0120, 0xb40120, 0xbd0120, 0xc60100, 0xce0100, + 0xd600e0, 0xdd00e0, 0xe400e0, 0xeb00c0, 0xf100c0, 0xf700c0, + 0xfd00c0, 0x10300a0, 0x10800c0, 0x10e00a0, 0x11300a0, 0x11800a0, + 0x11d00a0, 0x12200a0, 0x12700a0, 0x12c0080, 0x13000a0, 0x1350080, + 0x13900a0, 0x13e0080, 0x1420076, 0x17d0062, 0x1ae0054, 0x1d8004a, + 0x1fd0044, 0x21f003e, 0x23e003a, 0x25b0036, 0x2760032, 0x28f0030, + 0x2a7002e, 0x2be002c, 0x2d4002c, 0x2ea0028, 0x2fe0028, 0x3120026, + 0x3250024, 0x3370024, 0x3490022, 0x35a0022, 0x36b0020, 0x37b0020, + 0x38b0020, 0x39b001e, 0x3aa001e, 0x3b9001c, 0x3c7001c, 0x3d5001c, + 0x3e3001c, 0x3f1001c, 0x3ff001a, 0x40c001a }, + /* index 2 --> gamma bipartite 1/1.8(=3D0.56) */ + { + 0xa62, 0x4f0350, 0x680280, 0x7e0200, 0x8d01c0, 0x9a01a0, + 0xa50180, 0xb00140, 0xb90140, 0xc20120, 0xcb0120, 0xd30100, + 0xdb0100, 0xe300e0, 0xea00e0, 0xf100e0, 0xf700c0, 0xfd00c0, + 0x10300c0, 0x10900a0, 0x10e00a0, 0x11400a0, 0x11900a0, 0x11e00a0, + 0x12300a0, 0x12800a0, 0x12d0080, 0x1320080, 0x1370080, 0x13c0080, + 0x1410080, 0x1460080, 0x14a0070, 0x1830060, 0x1b40052, 0x1df0048, + 0x2040042, 0x2250040, 0x2440038, 0x2600036, 0x27b0032, 0x2940030, + 0x2ac002e, 0x2c4002c, 0x2da002a, 0x2f0002a, 0x3050028, 0x3190026, + 0x32c0026, 0x33e0024, 0x3500024, 0x3610022, 0x3720020, 0x3820020, + 0x3920020, 0x3a2001e, 0x3b1001e, 0x3c0001c, 0x3ce001c, 0x3dc001c, + 0x3ea001a, 0x3f8001a, 0x4060018, 0x4130018 }, }; =20 static int xisc_parse_dt(struct device *dev, struct isc_device *isc) @@ -434,7 +460,7 @@ static int microchip_xisc_probe(struct platform_device = *pdev) } =20 isc->gamma_table =3D isc_sama7g5_gamma_table; - isc->gamma_max =3D 0; + isc->gamma_max =3D 2; =20 if (of_machine_is_compatible("microchip,sam9x7")) { isc->max_width =3D ISC_SAM9X7_MAX_SUPPORT_WIDTH; --=20 2.34.1 From nobody Fri Jun 12 21:11:38 2026 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5496B3C4149; Tue, 12 May 2026 15:44:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.154.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778600655; cv=none; b=PyqJGUm/aXcLX/5ku/nCdpqbPwVdcHXUEraOgIlHGTJzxrjf2PgOf2KFNS6aX4RMHBwTsZ9GJjxjMjQk7bODZHfEM9zQbtrrK5F3JaIH0cBZ9WHWTlvvqtDeDx5oE30g32JXC1zbXwSAlGFT1Ryvs4nv3wVzwDDWhhU4Pe2/j/o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778600655; c=relaxed/simple; bh=SIMhATjX2Gs8fwNcRK0PpGZJe5yokfJFEpzZs4KSvqA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tRjbVq0677oxhIsOVN6sddVl2A1Ly2EJ6YAndPZRz00H/3PY2JhrDvIX7WLhJDcHkQEmpkbuL4aTMuCBYE12TBIx2CZG90EiGyOkoI4T5n1yPp3eR7/WBsGsGtNnkC11ub/Gbkqg53FGusHHyIjtfIBleUyPQZxyd/Z5sff9oZA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=Hn7O45Hx; arc=none smtp.client-ip=68.232.154.123 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.b="Hn7O45Hx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1778600653; x=1810136653; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SIMhATjX2Gs8fwNcRK0PpGZJe5yokfJFEpzZs4KSvqA=; b=Hn7O45HxUWXegRnPb9wRduUbK+0NzX737yFPOfNH4d2AjEMYa36SK7Xl mMMdGAjCrzpIM0wcc+RU8AOENsSOruhG4KfHnLpwQJVH/Nd28FKAVLfEN Br0QifBI35bHIjNrvMUZ6otNYc4HznkSfbdMcqsfHpS2WHjqcUOOpEvOW gEapSMDca2t4mnmmR7A5BCaQqUhfSiTr6Yhafyed7WelVZ8wok7I8m4vR SOnCjNWwaHaVlbJsD2Gm73R/PtGBu/9kAPInRfCRIX9bRW2xNFuLmBd1G ivKt+DbPb/RdrZzvgNTwvkxFDZ4wQJltY1RhlEnxwrK7ESUATnqiKkb3h Q==; X-CSE-ConnectionGUID: k0jnvHzBRcKS0TR21V2SCg== X-CSE-MsgGUID: G59cTcCNQOmYiU3Fe7ys4Q== X-IronPort-AV: E=Sophos;i="6.23,231,1770620400"; d="scan'208";a="57798658" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa2.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 May 2026 08:44:12 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.87.72) by chn-vm-ex3.mchp-main.com (10.10.87.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.2562.37; Tue, 12 May 2026 08:44:12 -0700 Received: from che-ll-i71840.microchip.com (10.10.85.11) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.58 via Frontend Transport; Tue, 12 May 2026 08:44:09 -0700 From: Balakrishnan Sambath To: CC: , , , , , "Balamanikandan Gunasundar" Subject: [PATCH v2 09/15] media: microchip-isc: add SAMA7G5 hue and saturation controls Date: Tue, 12 May 2026 21:13:33 +0530 Message-ID: <20260512154339.210444-10-balakrishnan.s@microchip.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260512154339.210444-1-balakrishnan.s@microchip.com> References: <20251009155251.102472-1-balamanikandan.gunasundar@microchip.com> <20260512154339.210444-1-balakrishnan.s@microchip.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" SAMA7G5 extends CBC with hue and saturation. Add V4L2_CID_HUE and V4L2_CID_SATURATION controls. Disable CBHS for RGB output since it operates in YCbCr domain. Signed-off-by: Balamanikandan Gunasundar Signed-off-by: Balakrishnan Sambath --- .../platform/microchip/microchip-isc-base.c | 86 ++++++++++++++++++- .../platform/microchip/microchip-isc-regs.h | 11 ++- .../media/platform/microchip/microchip-isc.h | 5 +- .../microchip/microchip-sama5d2-isc.c | 2 +- .../microchip/microchip-sama7g5-isc.c | 8 +- 5 files changed, 98 insertions(+), 14 deletions(-) diff --git a/drivers/media/platform/microchip/microchip-isc-base.c b/driver= s/media/platform/microchip/microchip-isc-base.c index ae2a0c6ba566..7e140af51912 100644 --- a/drivers/media/platform/microchip/microchip-isc-base.c +++ b/drivers/media/platform/microchip/microchip-isc-base.c @@ -810,7 +810,7 @@ static int isc_try_configure_pipeline(struct isc_device= *isc) if (ISC_IS_FORMAT_RAW(isc->try_config.sd_format->mbus_code)) { isc->try_config.bits_pipeline =3D CFA_ENABLE | CSC_ENABLE | GAM_ENABLES | WB_ENABLE | - SUB420_ENABLE | SUB422_ENABLE | CBC_ENABLE | + SUB420_ENABLE | SUB422_ENABLE | CBHS_ENABLE | DPC_BLCENABLE; } else { isc->try_config.bits_pipeline =3D 0x0; @@ -821,7 +821,7 @@ static int isc_try_configure_pipeline(struct isc_device= *isc) if (ISC_IS_FORMAT_RAW(isc->try_config.sd_format->mbus_code)) { isc->try_config.bits_pipeline =3D CFA_ENABLE | CSC_ENABLE | WB_ENABLE | GAM_ENABLES | - SUB422_ENABLE | CBC_ENABLE | DPC_BLCENABLE; + SUB422_ENABLE | CBHS_ENABLE | DPC_BLCENABLE; } else { isc->try_config.bits_pipeline =3D 0x0; } @@ -833,7 +833,7 @@ static int isc_try_configure_pipeline(struct isc_device= *isc) if (ISC_IS_FORMAT_RAW(isc->try_config.sd_format->mbus_code)) { isc->try_config.bits_pipeline =3D CFA_ENABLE | CSC_ENABLE | WB_ENABLE | GAM_ENABLES | - SUB422_ENABLE | CBC_ENABLE | DPC_BLCENABLE; + SUB422_ENABLE | CBHS_ENABLE | DPC_BLCENABLE; } else { isc->try_config.bits_pipeline =3D 0x0; } @@ -844,7 +844,7 @@ static int isc_try_configure_pipeline(struct isc_device= *isc) if (ISC_IS_FORMAT_RAW(isc->try_config.sd_format->mbus_code)) { isc->try_config.bits_pipeline =3D CFA_ENABLE | CSC_ENABLE | WB_ENABLE | GAM_ENABLES | - CBC_ENABLE | DPC_BLCENABLE; + CBHS_ENABLE | DPC_BLCENABLE; } else { isc->try_config.bits_pipeline =3D 0x0; } @@ -859,6 +859,56 @@ static int isc_try_configure_pipeline(struct isc_devic= e *isc) return 0; } =20 +static bool isc_format_has_chroma(u32 fourcc) +{ + switch (fourcc) { + case V4L2_PIX_FMT_YUV420: + case V4L2_PIX_FMT_YUV422P: + case V4L2_PIX_FMT_YUYV: + case V4L2_PIX_FMT_UYVY: + case V4L2_PIX_FMT_VYUY: + return true; + default: + return false; + } +} + +/* + * isc_update_cbc_ctrl_activity() - Activate/deactivate CBC controls + * + * Called from isc_set_fmt(), isc_link_validate(), and isc_ctrl_init(). + * At isc_ctrl_init() time isc->config.bits_pipeline is zero (no format + * has been negotiated yet), so all CBC controls are initially marked + * inactive. They become active once a format that includes CBHS in the + * pipeline is configured via VIDIOC_S_FMT or link validation. + */ +static void isc_update_cbc_ctrl_activity(struct isc_device *isc) +{ + struct v4l2_ctrl_handler *hdl =3D &isc->ctrls.handler; + struct v4l2_ctrl *brightness; + struct v4l2_ctrl *contrast; + struct v4l2_ctrl *hue; + struct v4l2_ctrl *saturation; + bool cbc_active =3D isc->config.bits_pipeline & CBHS_ENABLE; + bool chroma_active =3D cbc_active && isc_format_has_chroma(isc->config.fo= urcc); + + brightness =3D v4l2_ctrl_find(hdl, V4L2_CID_BRIGHTNESS); + if (brightness) + v4l2_ctrl_activate(brightness, cbc_active); + + contrast =3D v4l2_ctrl_find(hdl, V4L2_CID_CONTRAST); + if (contrast) + v4l2_ctrl_activate(contrast, cbc_active); + + hue =3D v4l2_ctrl_find(hdl, V4L2_CID_HUE); + if (hue) + v4l2_ctrl_activate(hue, chroma_active); + + saturation =3D v4l2_ctrl_find(hdl, V4L2_CID_SATURATION); + if (saturation) + v4l2_ctrl_activate(saturation, chroma_active); +} + static int isc_try_fmt(struct isc_device *isc, struct v4l2_format *f) { struct v4l2_pix_format *pixfmt =3D &f->fmt.pix; @@ -902,6 +952,7 @@ static int isc_set_fmt(struct isc_device *isc, struct v= 4l2_format *f) /* make the try configuration active */ isc->config =3D isc->try_config; isc->fmt =3D isc->try_fmt; + isc_update_cbc_ctrl_activity(isc); =20 dev_dbg(isc->dev, "ISC set_fmt to %.4s @%dx%d\n", (char *)&f->fmt.pix.pixelformat, @@ -989,6 +1040,7 @@ static int isc_link_validate(struct media_link *link) return ret; =20 isc->config =3D isc->try_config; + isc_update_cbc_ctrl_activity(isc); =20 dev_dbg(isc->dev, "New ISC configuration in place\n"); =20 @@ -1453,9 +1505,30 @@ static int isc_s_ctrl(struct v4l2_ctrl *ctrl) switch (ctrl->id) { case V4L2_CID_BRIGHTNESS: ctrls->brightness =3D ctrl->val & ISC_CBC_BRIGHT_MASK; + regmap_write(regmap, ISC_CBC_BRIGHT + isc->offsets.cbc, ctrls->brightnes= s); break; case V4L2_CID_CONTRAST: ctrls->contrast =3D ctrl->val & ISC_CBC_CONTRAST_MASK; + regmap_write(regmap, ISC_CBC_CONTRAST + isc->offsets.cbc, ctrls->contras= t); + break; + case V4L2_CID_HUE: + if (isc->has_cbhs) { + ctrls->hue =3D ctrl->val & ISC_CBHS_HUE_MASK; + regmap_write(regmap, ISC_CBHS_HUE, ctrls->hue); + } + break; + case V4L2_CID_SATURATION: + if (isc->has_cbhs) { + /* + * The ISC CBHS SAT register holds a Q4 fixed-point + * coefficient: 0 =3D grayscale, 16 =3D 1.0 (no change), + * values above 16 boost saturation. The V4L2 range + * 0-100 (default 16) maps directly to this hardware + * value; no unit conversion is applied. + */ + ctrls->saturation =3D ctrl->val & ISC_CBHS_SAT_MASK; + regmap_write(regmap, ISC_CBHS_SAT, ctrls->saturation); + } break; case V4L2_CID_GAMMA: ctrls->gamma_index =3D ctrl->val; @@ -1647,6 +1720,10 @@ static int isc_ctrl_init(struct isc_device *isc) ctrls->brightness =3D 0; =20 v4l2_ctrl_new_std(hdl, ops, V4L2_CID_BRIGHTNESS, -1024, 1023, 1, 0); + if (isc->has_cbhs) { + v4l2_ctrl_new_std(hdl, ops, V4L2_CID_HUE, -180, 180, 1, 0); + v4l2_ctrl_new_std(hdl, ops, V4L2_CID_SATURATION, 0, 100, 1, 16); + } v4l2_ctrl_new_std(hdl, ops, V4L2_CID_GAMMA, 0, isc->gamma_max, 1, 1); isc->awb_ctrl =3D v4l2_ctrl_new_std(hdl, &isc_awb_ops, V4L2_CID_AUTO_WHITE_BALANCE, @@ -1664,6 +1741,7 @@ static int isc_ctrl_init(struct isc_device *isc) } =20 v4l2_ctrl_activate(isc->do_wb_ctrl, false); + isc_update_cbc_ctrl_activity(isc); =20 isc->r_gain_ctrl =3D v4l2_ctrl_new_custom(hdl, &isc_r_gain_ctrl, NULL); isc->b_gain_ctrl =3D v4l2_ctrl_new_custom(hdl, &isc_b_gain_ctrl, NULL); diff --git a/drivers/media/platform/microchip/microchip-isc-regs.h b/driver= s/media/platform/microchip/microchip-isc-regs.h index e77e1d9a1db8..2fd8916abf21 100644 --- a/drivers/media/platform/microchip/microchip-isc-regs.h +++ b/drivers/media/platform/microchip/microchip-isc-regs.h @@ -268,10 +268,13 @@ #define ISC_CBC_CONTRAST 0x000003c0 #define ISC_CBC_CONTRAST_MASK GENMASK(11, 0) =20 -/* Hue Register */ -#define ISC_CBCHS_HUE 0x4e0 -/* Saturation Register */ -#define ISC_CBCHS_SAT 0x4e4 +/* Hue Register: signed 9-bit two's complement, covers -180 to +180 degree= s */ +#define ISC_CBHS_HUE 0x4e0 +#define ISC_CBHS_HUE_MASK GENMASK(8, 0) + +/* Saturation Register: unsigned Q4 fixed-point (1.0 =3D 16, V4L2 range 0-= 100) */ +#define ISC_CBHS_SAT 0x4e4 +#define ISC_CBHS_SAT_MASK GENMASK(6, 0) =20 /* Offset for SUB422 register specific to sama5d2 product */ #define ISC_SAMA5D2_SUB422_OFFSET 0 diff --git a/drivers/media/platform/microchip/microchip-isc.h b/drivers/med= ia/platform/microchip/microchip-isc.h index ad4e98a1dd8f..2c8bcaaa26ea 100644 --- a/drivers/media/platform/microchip/microchip-isc.h +++ b/drivers/media/platform/microchip/microchip-isc.h @@ -88,7 +88,7 @@ struct isc_format { #define GAM_RENABLE BIT(9) #define VHXS_ENABLE BIT(10) #define CSC_ENABLE BIT(11) -#define CBC_ENABLE BIT(12) +#define CBHS_ENABLE BIT(12) #define SUB422_ENABLE BIT(13) #define SUB420_ENABLE BIT(14) =20 @@ -139,6 +139,8 @@ struct isc_ctrls { =20 u32 brightness; u32 contrast; + u32 hue; + u32 saturation; u8 gamma_index; #define ISC_WB_NONE 0 #define ISC_WB_AUTO 1 @@ -342,6 +344,7 @@ struct isc_device { /* pointer to the defined gamma table */ const u32 (*gamma_table)[GAMMA_ENTRIES]; u32 gamma_max; + bool has_cbhs; =20 u32 max_width; u32 max_height; diff --git a/drivers/media/platform/microchip/microchip-sama5d2-isc.c b/dri= vers/media/platform/microchip/microchip-sama5d2-isc.c index 66d3d7891991..239aac170472 100644 --- a/drivers/media/platform/microchip/microchip-sama5d2-isc.c +++ b/drivers/media/platform/microchip/microchip-sama5d2-isc.c @@ -54,7 +54,7 @@ =20 #define ISC_SAMA5D2_PIPELINE \ (WB_ENABLE | CFA_ENABLE | CC_ENABLE | GAM_ENABLES | CSC_ENABLE | \ - CBC_ENABLE | SUB422_ENABLE | SUB420_ENABLE) + CBHS_ENABLE | SUB422_ENABLE | SUB420_ENABLE) =20 /* This is a list of the formats that the ISC can *output* */ static const struct isc_format sama5d2_controller_formats[] =3D { diff --git a/drivers/media/platform/microchip/microchip-sama7g5-isc.c b/dri= vers/media/platform/microchip/microchip-sama7g5-isc.c index 8b73b625d92b..6705011edc2a 100644 --- a/drivers/media/platform/microchip/microchip-sama7g5-isc.c +++ b/drivers/media/platform/microchip/microchip-sama7g5-isc.c @@ -61,7 +61,7 @@ #define ISC_SAMA7G5_PIPELINE \ (DPC_DPCENABLE | DPC_GDCENABLE | DPC_BLCENABLE | \ WB_ENABLE | CFA_ENABLE | CC_ENABLE | GAM_ENABLES | CSC_ENABLE | \ - CBC_ENABLE | SUB422_ENABLE | SUB420_ENABLE) + CBHS_ENABLE | SUB422_ENABLE | SUB420_ENABLE) =20 /* This is a list of the formats that the ISC can *output* */ static const struct isc_format sama7g5_controller_formats[] =3D { @@ -257,9 +257,8 @@ static void isc_sama7g5_config_cbc(struct isc_device *i= sc) /* Configure what is set via v4l2 ctrls */ regmap_write(regmap, ISC_CBC_BRIGHT + isc->offsets.cbc, isc->ctrls.bright= ness); regmap_write(regmap, ISC_CBC_CONTRAST + isc->offsets.cbc, isc->ctrls.cont= rast); - /* Configure Hue and Saturation as neutral midpoint */ - regmap_write(regmap, ISC_CBCHS_HUE, 0); - regmap_write(regmap, ISC_CBCHS_SAT, (1 << 4)); + regmap_write(regmap, ISC_CBHS_HUE, isc->ctrls.hue); + regmap_write(regmap, ISC_CBHS_SAT, isc->ctrls.saturation); } =20 static void isc_sama7g5_config_cc(struct isc_device *isc) @@ -461,6 +460,7 @@ static int microchip_xisc_probe(struct platform_device = *pdev) =20 isc->gamma_table =3D isc_sama7g5_gamma_table; isc->gamma_max =3D 2; + isc->has_cbhs =3D true; =20 if (of_machine_is_compatible("microchip,sam9x7")) { isc->max_width =3D ISC_SAM9X7_MAX_SUPPORT_WIDTH; --=20 2.34.1 From nobody Fri Jun 12 21:11:38 2026 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E8DEE3C8C7D; Tue, 12 May 2026 15:44:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.153.233 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778600658; cv=none; b=TDtLHYq7ZVlgKNVgd9XgQy7NxmUikono2YM0J8xfkuHDhKl2qoiIPnfMZjLyyPvo8uivBdZdjjF5+w/QVP3Y8iJsLnfPxw19h3r85mdKGxU76NhfrhHkArqqHsXLj6V5yV+7TP7ZxJqLjL3Wy9eWy20LyplhkaPsnKcoM9qlXLA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778600658; c=relaxed/simple; bh=5yCExlH+Lzz0uNStrjzI+Z50N3UCUAbboRtJptlwOd4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=s9BOCrVjohqeWIvWyWbY0muhKrqaD/XyinaijUswoFaeEIFG6xCj8eVxYlGJFhcywj0E0NSVSPUArv3/FRvqDEwUVjjTovfwqmiPudBdDahqMWzIcxvloSQEleBTek8d/9dGZnAoM0FPhvZwjat9TFLW/z3GispKUcK47h98sw4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=S7yO9oq0; arc=none smtp.client-ip=68.232.153.233 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.b="S7yO9oq0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1778600657; x=1810136657; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5yCExlH+Lzz0uNStrjzI+Z50N3UCUAbboRtJptlwOd4=; b=S7yO9oq0isHyN89KDS6EW955HHRTf66oPXziZKnwBvM3oooUVz3qEKjl d+YPpd/lxkk4vL9iGCBMDwqV4Si+EwKsPibZFum7BwiVlm/f/ZSm3siHk eLDDDaJmpWGoEOfssNboNUywiuSXS9plo5f45rUUj15AQecOtVUuTTRoj Qz+QaJW9YC4IBloz99RYt/+/WIPhS2N3ApfuczrCGbnksxvwb/KrfPF2z lhWaLf748X0OJcmFLDvz90Ag4xvD/5/zbpE39W8v8GBwmH1id7KnaNsRy 9lNjnJ5V9jOjvxlg/U6j8QznZcoMUUxsGRdZ5TpGRumzKkfslOB5NUlZR Q==; X-CSE-ConnectionGUID: 8v2vbvooQ3afilXTCFNQoA== X-CSE-MsgGUID: F2/xLscwR2iAP+AHDCI7Ow== X-IronPort-AV: E=Sophos;i="6.23,231,1770620400"; d="scan'208";a="288760457" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa5.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 May 2026 08:44:17 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.87.72) by chn-vm-ex3.mchp-main.com (10.10.87.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.2562.37; Tue, 12 May 2026 08:44:15 -0700 Received: from che-ll-i71840.microchip.com (10.10.85.11) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.58 via Frontend Transport; Tue, 12 May 2026 08:44:12 -0700 From: Balakrishnan Sambath To: CC: , , , , , "Balamanikandan Gunasundar" Subject: [PATCH v2 10/15] media: microchip-isc: expose color correction matrix as V4L2 controls Date: Tue, 12 May 2026 21:13:34 +0530 Message-ID: <20260512154339.210444-11-balakrishnan.s@microchip.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260512154339.210444-1-balakrishnan.s@microchip.com> References: <20251009155251.102472-1-balamanikandan.gunasundar@microchip.com> <20260512154339.210444-1-balakrishnan.s@microchip.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add custom controls for 3x3 color correction matrix and RGB offsets. Used by libcamera IPA for sensor color calibration. Signed-off-by: Balamanikandan Gunasundar Signed-off-by: Balakrishnan Sambath --- .../platform/microchip/microchip-isc-base.c | 247 +++++++++++++++++- .../media/platform/microchip/microchip-isc.h | 23 ++ include/linux/atmel-isc-media.h | 13 + 3 files changed, 281 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/microchip/microchip-isc-base.c b/driver= s/media/platform/microchip/microchip-isc-base.c index 7e140af51912..f78145820e40 100644 --- a/drivers/media/platform/microchip/microchip-isc-base.c +++ b/drivers/media/platform/microchip/microchip-isc-base.c @@ -32,7 +32,7 @@ #include "microchip-isc-regs.h" #include "microchip-isc.h" =20 -#define ISC_IS_FORMAT_RAW(mbus_code) \ +#define ISC_IS_FORMAT_RAW(mbus_code) \ (((mbus_code) & 0xf000) =3D=3D 0x3000) =20 #define ISC_IS_FORMAT_GREY(mbus_code) \ @@ -55,6 +55,46 @@ static inline void isc_update_v4l2_ctrls(struct isc_devi= ce *isc) v4l2_ctrl_s_ctrl(isc->gb_off_ctrl, ctrls->offset[ISC_HIS_CFG_MODE_GB]); } =20 +static void isc_apply_gamma(struct isc_device *isc); + +/* commit CC shadow to hardware; called while ISC is powered */ +static void isc_update_cc_ctrls(struct isc_device *isc) +{ + struct isc_ctrls *ctrls =3D &isc->ctrls; + struct regmap *regmap =3D isc->regmap; + u32 m =3D GENMASK(11, 0); + + if (!ctrls->cc_dirty) + return; + + regmap_update_bits(regmap, ISC_CC_RR_RG, m, + (u32)ctrls->cc_coeff[0] & m); + regmap_update_bits(regmap, ISC_CC_RR_RG, GENMASK(27, 16), + ((u32)ctrls->cc_coeff[1] & m) << 16); + regmap_update_bits(regmap, ISC_CC_RB_OR, m, + (u32)ctrls->cc_coeff[2] & m); + regmap_update_bits(regmap, ISC_CC_RB_OR, GENMASK(27, 16), + ((u32)ctrls->cc_offset[0] & m) << 16); + regmap_update_bits(regmap, ISC_CC_GR_GG, m, + (u32)ctrls->cc_coeff[3] & m); + regmap_update_bits(regmap, ISC_CC_GR_GG, GENMASK(27, 16), + ((u32)ctrls->cc_coeff[4] & m) << 16); + regmap_update_bits(regmap, ISC_CC_GB_OG, m, + (u32)ctrls->cc_coeff[5] & m); + regmap_update_bits(regmap, ISC_CC_GB_OG, GENMASK(27, 16), + ((u32)ctrls->cc_offset[1] & m) << 16); + regmap_update_bits(regmap, ISC_CC_BR_BG, m, + (u32)ctrls->cc_coeff[6] & m); + regmap_update_bits(regmap, ISC_CC_BR_BG, GENMASK(27, 16), + ((u32)ctrls->cc_coeff[7] & m) << 16); + regmap_update_bits(regmap, ISC_CC_BB_OB, m, + (u32)ctrls->cc_coeff[8] & m); + regmap_update_bits(regmap, ISC_CC_BB_OB, GENMASK(27, 16), + ((u32)ctrls->cc_offset[2] & m) << 16); + + ctrls->cc_dirty =3D false; +} + static inline void isc_update_awb_ctrls(struct isc_device *isc) { struct isc_ctrls *ctrls =3D &isc->ctrls; @@ -90,6 +130,14 @@ static inline void isc_reset_awb_ctrls(struct isc_devic= e *isc) /* offsets are in 2's complements */ isc->ctrls.offset[c] =3D 0; } + + /* identity matrix: diagonal =3D 1.0 in Q4.8 =3D 256, off-diagonal =3D 0 = */ + memset(isc->ctrls.cc_coeff, 0, sizeof(isc->ctrls.cc_coeff)); + isc->ctrls.cc_coeff[0] =3D 256; /* RR */ + isc->ctrls.cc_coeff[4] =3D 256; /* GG */ + isc->ctrls.cc_coeff[8] =3D 256; /* BB */ + memset(isc->ctrls.cc_offset, 0, sizeof(isc->ctrls.cc_offset)); + isc->ctrls.cc_dirty =3D false; } =20 static int isc_queue_setup(struct vb2_queue *vq, @@ -235,7 +283,8 @@ static void isc_set_pipeline(struct isc_device *isc, u3= 2 pipeline) isc->config_dpc(isc); isc->config_csc(isc); isc->config_cbc(isc); - isc->config_cc(isc); + /* use shadow; config_cc() always resets to identity */ + isc_update_cc_ctrls(isc); isc->config_gam(isc); } =20 @@ -1481,6 +1530,8 @@ static void isc_awb_work(struct work_struct *w) goto out_pm_put; } =20 + /* write pending CC matrix from shadow to hardware registers */ + isc_update_cc_ctrls(isc); isc_update_profile(isc); =20 mutex_unlock(&isc->awb_mutex); @@ -1659,6 +1710,161 @@ static int isc_g_volatile_awb_ctrl(struct v4l2_ctrl= *ctrl) return 0; } =20 +static int isc_cc_s_ctrl(struct v4l2_ctrl *ctrl) +{ + struct isc_device *isc =3D container_of(ctrl->handler, + struct isc_device, ctrls.handler); + struct isc_ctrls *ctrls =3D &isc->ctrls; + + dev_dbg(isc->dev, "id =3D 0x%x; val =3D 0x%x", ctrl->id, ctrl->val); + + /* + * CC registers need pm_runtime active for access. + * Store to shadow here; isc_update_cc_ctrls() writes to hardware + * from isc_awb_work() where ISC is powered. + */ + switch (ctrl->id) { + case ISC_CID_CC_RR: + ctrls->cc_coeff[0] =3D ctrl->val; + break; + case ISC_CID_CC_RG: + ctrls->cc_coeff[1] =3D ctrl->val; + break; + case ISC_CID_CC_RB: + ctrls->cc_coeff[2] =3D ctrl->val; + break; + case ISC_CID_CC_OR: + ctrls->cc_offset[0] =3D ctrl->val; + break; + case ISC_CID_CC_GR: + ctrls->cc_coeff[3] =3D ctrl->val; + break; + case ISC_CID_CC_GG: + ctrls->cc_coeff[4] =3D ctrl->val; + break; + case ISC_CID_CC_GB: + ctrls->cc_coeff[5] =3D ctrl->val; + break; + case ISC_CID_CC_OG: + ctrls->cc_offset[1] =3D ctrl->val; + break; + case ISC_CID_CC_BR: + ctrls->cc_coeff[6] =3D ctrl->val; + break; + case ISC_CID_CC_BG: + ctrls->cc_coeff[7] =3D ctrl->val; + break; + case ISC_CID_CC_BB: + ctrls->cc_coeff[8] =3D ctrl->val; + break; + case ISC_CID_CC_OB: + ctrls->cc_offset[2] =3D ctrl->val; + break; + default: + return -EINVAL; + } + + ctrls->cc_dirty =3D true; + return 0; +} + +static int isc_cc_g_volatile_ctrl(struct v4l2_ctrl *ctrl) +{ + struct isc_device *isc =3D container_of(ctrl->handler, + struct isc_device, ctrls.handler); + struct regmap *regmap =3D isc->regmap; + unsigned int reg; + + switch (ctrl->id) { + case ISC_CID_CC_RR: + regmap_read(regmap, ISC_CC_RR_RG, ®); + ctrl->val =3D sign_extend32(reg & GENMASK(11, 0), 11); + break; + case ISC_CID_CC_RG: + regmap_read(regmap, ISC_CC_RR_RG, ®); + ctrl->val =3D sign_extend32((reg & GENMASK(27, 16)) >> 16, 11); + break; + case ISC_CID_CC_RB: + regmap_read(regmap, ISC_CC_RB_OR, ®); + ctrl->val =3D sign_extend32(reg & GENMASK(11, 0), 11); + break; + case ISC_CID_CC_OR: + regmap_read(regmap, ISC_CC_RB_OR, ®); + ctrl->val =3D sign_extend32((reg & GENMASK(27, 16)) >> 16, 11); + break; + case ISC_CID_CC_GR: + regmap_read(regmap, ISC_CC_GR_GG, ®); + ctrl->val =3D sign_extend32(reg & GENMASK(11, 0), 11); + break; + case ISC_CID_CC_GG: + regmap_read(regmap, ISC_CC_GR_GG, ®); + ctrl->val =3D sign_extend32((reg & GENMASK(27, 16)) >> 16, 11); + break; + case ISC_CID_CC_GB: + regmap_read(regmap, ISC_CC_GB_OG, ®); + ctrl->val =3D sign_extend32(reg & GENMASK(11, 0), 11); + break; + case ISC_CID_CC_OG: + regmap_read(regmap, ISC_CC_GB_OG, ®); + ctrl->val =3D sign_extend32((reg & GENMASK(27, 16)) >> 16, 11); + break; + case ISC_CID_CC_BR: + regmap_read(regmap, ISC_CC_BR_BG, ®); + ctrl->val =3D sign_extend32(reg & GENMASK(11, 0), 11); + break; + case ISC_CID_CC_BG: + regmap_read(regmap, ISC_CC_BR_BG, ®); + ctrl->val =3D sign_extend32((reg & GENMASK(27, 16)) >> 16, 11); + break; + case ISC_CID_CC_BB: + regmap_read(regmap, ISC_CC_BB_OB, ®); + ctrl->val =3D sign_extend32(reg & GENMASK(11, 0), 11); + break; + case ISC_CID_CC_OB: + regmap_read(regmap, ISC_CC_BB_OB, ®); + ctrl->val =3D sign_extend32((reg & GENMASK(27, 16)) >> 16, 11); + break; + default: + return -EINVAL; + } + + dev_dbg(isc->dev, "id =3D 0x%x; val =3D 0x%x", ctrl->id, ctrl->val); + + return 0; +} + +static const struct v4l2_ctrl_ops isc_cc_ops =3D { + .s_ctrl =3D isc_cc_s_ctrl, + .g_volatile_ctrl =3D isc_cc_g_volatile_ctrl, +}; + +#define ISC_CTRL_CC(_name, _id, _name_str, _def) \ + static const struct v4l2_ctrl_config _name =3D { \ + .ops =3D &isc_cc_ops, \ + .id =3D _id, \ + .name =3D _name_str, \ + .type =3D V4L2_CTRL_TYPE_INTEGER, \ + .flags =3D V4L2_CTRL_FLAG_SLIDER | V4L2_CTRL_FLAG_VOLATILE | \ + V4L2_CTRL_FLAG_EXECUTE_ON_WRITE, \ + .min =3D -2048, \ + .max =3D 2047, \ + .step =3D 1, \ + .def =3D _def, \ + } + +ISC_CTRL_CC(isc_cc_rr_ctrl, ISC_CID_CC_RR, "CC RR", 256); +ISC_CTRL_CC(isc_cc_rg_ctrl, ISC_CID_CC_RG, "CC RG", 0); +ISC_CTRL_CC(isc_cc_rb_ctrl, ISC_CID_CC_RB, "CC RB", 0); +ISC_CTRL_CC(isc_cc_or_ctrl, ISC_CID_CC_OR, "CC OR", 0); +ISC_CTRL_CC(isc_cc_gr_ctrl, ISC_CID_CC_GR, "CC GR", 0); +ISC_CTRL_CC(isc_cc_gg_ctrl, ISC_CID_CC_GG, "CC GG", 256); +ISC_CTRL_CC(isc_cc_gb_ctrl, ISC_CID_CC_GB, "CC GB", 0); +ISC_CTRL_CC(isc_cc_og_ctrl, ISC_CID_CC_OG, "CC OG", 0); +ISC_CTRL_CC(isc_cc_br_ctrl, ISC_CID_CC_BR, "CC BR", 0); +ISC_CTRL_CC(isc_cc_bg_ctrl, ISC_CID_CC_BG, "CC BG", 0); +ISC_CTRL_CC(isc_cc_bb_ctrl, ISC_CID_CC_BB, "CC BB", 256); +ISC_CTRL_CC(isc_cc_ob_ctrl, ISC_CID_CC_OB, "CC OB", 0); + static const struct v4l2_ctrl_ops isc_awb_ops =3D { .s_ctrl =3D isc_s_awb_ctrl, .g_volatile_ctrl =3D isc_g_volatile_awb_ctrl, @@ -1700,6 +1906,29 @@ ISC_CTRL_GAIN(isc_b_gain_ctrl, ISC_CID_B_GAIN, "Blue= Component Gain"); ISC_CTRL_GAIN(isc_gr_gain_ctrl, ISC_CID_GR_GAIN, "Green Red Component Gain= "); ISC_CTRL_GAIN(isc_gb_gain_ctrl, ISC_CID_GB_GAIN, "Green Blue Component Gai= n"); =20 +/* + * Per-channel gamma LUT controls (64-element U32 arrays, range 0-1023). + * Setting any of these activates the custom tone curve and overrides the + * preset V4L2_CID_GAMMA curve. One macro expands to a static v4l2_ctrl_c= onfig. + */ +#define ISC_CTRL_GAMMA_LUT(_name, _id, _name_str) \ + static const struct v4l2_ctrl_config _name =3D { \ + .ops =3D &isc_ctrl_ops, \ + .id =3D _id, \ + .name =3D _name_str, \ + .type =3D V4L2_CTRL_TYPE_U32, \ + .flags =3D V4L2_CTRL_FLAG_EXECUTE_ON_WRITE, \ + .dims =3D { GAMMA_ENTRIES }, \ + .min =3D 0, \ + .max =3D 1023, \ + .step =3D 1, \ + .def =3D 0, \ + } + +ISC_CTRL_GAMMA_LUT(isc_gamma_b_lut_ctrl, ISC_CID_GAMMA_B_LUT, "Blue Gamma = LUT"); +ISC_CTRL_GAMMA_LUT(isc_gamma_g_lut_ctrl, ISC_CID_GAMMA_G_LUT, "Green Gamma= LUT"); +ISC_CTRL_GAMMA_LUT(isc_gamma_r_lut_ctrl, ISC_CID_GAMMA_R_LUT, "Red Gamma L= UT"); + static int isc_ctrl_init(struct isc_device *isc) { const struct v4l2_ctrl_ops *ops =3D &isc_ctrl_ops; @@ -1752,6 +1981,20 @@ static int isc_ctrl_init(struct isc_device *isc) isc->gr_off_ctrl =3D v4l2_ctrl_new_custom(hdl, &isc_gr_off_ctrl, NULL); isc->gb_off_ctrl =3D v4l2_ctrl_new_custom(hdl, &isc_gb_off_ctrl, NULL); =20 + /* Color correction control */ + isc->cc_rr =3D v4l2_ctrl_new_custom(hdl, &isc_cc_rr_ctrl, NULL); + isc->cc_rg =3D v4l2_ctrl_new_custom(hdl, &isc_cc_rg_ctrl, NULL); + isc->cc_rb =3D v4l2_ctrl_new_custom(hdl, &isc_cc_rb_ctrl, NULL); + isc->cc_or =3D v4l2_ctrl_new_custom(hdl, &isc_cc_or_ctrl, NULL); + isc->cc_gr =3D v4l2_ctrl_new_custom(hdl, &isc_cc_gr_ctrl, NULL); + isc->cc_gg =3D v4l2_ctrl_new_custom(hdl, &isc_cc_gg_ctrl, NULL); + isc->cc_gb =3D v4l2_ctrl_new_custom(hdl, &isc_cc_gb_ctrl, NULL); + isc->cc_og =3D v4l2_ctrl_new_custom(hdl, &isc_cc_og_ctrl, NULL); + isc->cc_br =3D v4l2_ctrl_new_custom(hdl, &isc_cc_br_ctrl, NULL); + isc->cc_bg =3D v4l2_ctrl_new_custom(hdl, &isc_cc_bg_ctrl, NULL); + isc->cc_bb =3D v4l2_ctrl_new_custom(hdl, &isc_cc_bb_ctrl, NULL); + isc->cc_ob =3D v4l2_ctrl_new_custom(hdl, &isc_cc_ob_ctrl, NULL); + /* * The cluster is in auto mode with autowhitebalance enabled * and manual mode otherwise. diff --git a/drivers/media/platform/microchip/microchip-isc.h b/drivers/med= ia/platform/microchip/microchip-isc.h index 2c8bcaaa26ea..db651c9f1387 100644 --- a/drivers/media/platform/microchip/microchip-isc.h +++ b/drivers/media/platform/microchip/microchip-isc.h @@ -134,6 +134,12 @@ enum{ HIST_DISABLED, }; =20 +#define GAMMA_ENTRIES 64 + +/* CC matrix coefficients (3x3 row-major) and per-channel offsets */ +#define ISC_CC_COEFF_NUM 9 +#define ISC_CC_OFFSET_NUM 3 + struct isc_ctrls { struct v4l2_ctrl_handler handler; =20 @@ -158,6 +164,11 @@ struct isc_ctrls { #define HIST_MIN_INDEX 0 #define HIST_MAX_INDEX 1 u32 hist_minmax[HIST_BAYER][2]; + + /* CC matrix shadow; committed from isc_set_pipeline() and isc_awb_work()= */ + s32 cc_coeff[ISC_CC_COEFF_NUM]; + s32 cc_offset[ISC_CC_OFFSET_NUM]; + bool cc_dirty; }; =20 #define ISC_PIPE_LINE_NODE_NUM 15 @@ -338,6 +349,18 @@ struct isc_device { struct v4l2_ctrl *b_off_ctrl; struct v4l2_ctrl *gr_off_ctrl; struct v4l2_ctrl *gb_off_ctrl; + struct v4l2_ctrl *cc_rr; + struct v4l2_ctrl *cc_rg; + struct v4l2_ctrl *cc_rb; + struct v4l2_ctrl *cc_or; + struct v4l2_ctrl *cc_gr; + struct v4l2_ctrl *cc_gg; + struct v4l2_ctrl *cc_gb; + struct v4l2_ctrl *cc_og; + struct v4l2_ctrl *cc_br; + struct v4l2_ctrl *cc_bg; + struct v4l2_ctrl *cc_bb; + struct v4l2_ctrl *cc_ob; }; =20 #define GAMMA_ENTRIES 64 diff --git a/include/linux/atmel-isc-media.h b/include/linux/atmel-isc-medi= a.h index 79a320fb724e..028d34c8de81 100644 --- a/include/linux/atmel-isc-media.h +++ b/include/linux/atmel-isc-media.h @@ -53,6 +53,19 @@ enum atmel_isc_ctrl_id { ISC_CID_GR_OFFSET, /* Green Blue component offset control */ ISC_CID_GB_OFFSET, + /* Color correction registers */ + ISC_CID_CC_RR, + ISC_CID_CC_RG, + ISC_CID_CC_RB, + ISC_CID_CC_OR, + ISC_CID_CC_GR, + ISC_CID_CC_GG, + ISC_CID_CC_GB, + ISC_CID_CC_OG, + ISC_CID_CC_BR, + ISC_CID_CC_BG, + ISC_CID_CC_BB, + ISC_CID_CC_OB, }; =20 #endif --=20 2.34.1 From nobody Fri Jun 12 21:11:38 2026 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B416E3C988E; Tue, 12 May 2026 15:44:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.153.233 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778600661; cv=none; b=McCg7S3bzMVprrZyB9ZCA5F+uuxA//O4mQLkNMC/qIGvWMUosteks/rigBD7odr2Jsn9iw7Dn3vMB0SZvP/a+mIt7VJC79xfa80oil3TAbsoATVuOp4Qk2oIhv8f3oI3VaSrTNm7JwgSvtnRdrHecA0gK4zycFyYU+Q9dK6EjeQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778600661; c=relaxed/simple; bh=qgJRjDdDKYUCbpz0CUdEc9ue5jBEBqdWfm0LHbVTgaY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=syrPBRRFUq6OVadoaGN9sVm6VbdqutNx+61zSY7ZV0lbQWFgYADPKkHAjREQpAvVC5r7v2TinCfNfOSeWU3i8GN7+3Qy19PdX4PmxV/stwNLRVL7tVGc1HjJTXh6uxyFTpJcrXl4SWS8dhpWoCcNCqhWoDHEiDB9BcyJMirrXv0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=hwNwyKPn; arc=none smtp.client-ip=68.232.153.233 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.b="hwNwyKPn" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1778600660; x=1810136660; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qgJRjDdDKYUCbpz0CUdEc9ue5jBEBqdWfm0LHbVTgaY=; b=hwNwyKPnMjG+S3/V8Z913o5aITH7EmKpU92WvFHnrn4fwqLXNqgPlwx5 UrN/1UGXCowaGHw1pFDTm+xXcUfO3JYPhKtfP9clsoZ28sdFW0MgFoIwn 89HnDuGfw/cMN/ALZTEgQOmtW4cTJWDJbc+26ISYqP4dMPhhCt2CCwc2i NezUWMoV9PaSeU1z2/AK0TLEH5SFFSoiL8eqoJcC+vj33z4Pvyk2BlQYn J7Dvn5vZVg+G0aNmKKwvVzj2XT4R/X2yHznoJ9/Emgk47BjwpIi2OdVhq 7pW/Ev5wHb1/U8OlV/IepZUGLwavBtWw0Dvvgm0AsLE+EqoIUPUoPRFmh Q==; X-CSE-ConnectionGUID: HnGOENH1Q6mvjZ1NizDJbQ== X-CSE-MsgGUID: e0c2Ojg3S12e0yNXxmz0ww== X-IronPort-AV: E=Sophos;i="6.23,231,1770620400"; d="scan'208";a="57399286" 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; 12 May 2026 08:44:19 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.58; Tue, 12 May 2026 08:44:18 -0700 Received: from che-ll-i71840.microchip.com (10.10.85.11) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.58 via Frontend Transport; Tue, 12 May 2026 08:44:16 -0700 From: Balakrishnan Sambath To: CC: , , , , Subject: [PATCH v2 11/15] media: microchip-isc: add per-channel gamma LUT controls Date: Tue, 12 May 2026 21:13:35 +0530 Message-ID: <20260512154339.210444-12-balakrishnan.s@microchip.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260512154339.210444-1-balakrishnan.s@microchip.com> References: <20251009155251.102472-1-balamanikandan.gunasundar@microchip.com> <20260512154339.210444-1-balakrishnan.s@microchip.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add 64-entry gamma LUT controls for R/G/B channels. Setting any LUT overrides V4L2_CID_GAMMA; writing V4L2_CID_GAMMA restores presets. Supports SAMA7G5 bipartite encoding. Signed-off-by: Balakrishnan Sambath --- .../platform/microchip/microchip-isc-base.c | 148 +++++++++++++++++- .../media/platform/microchip/microchip-isc.h | 25 ++- .../microchip/microchip-sama7g5-isc.c | 1 + include/linux/atmel-isc-media.h | 18 +++ 4 files changed, 184 insertions(+), 8 deletions(-) diff --git a/drivers/media/platform/microchip/microchip-isc-base.c b/driver= s/media/platform/microchip/microchip-isc-base.c index f78145820e40..3749f473c3c6 100644 --- a/drivers/media/platform/microchip/microchip-isc-base.c +++ b/drivers/media/platform/microchip/microchip-isc-base.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -250,12 +251,83 @@ static void isc_start_dma(struct isc_device *isc) spin_unlock(&isc->awb_lock); } =20 -static void isc_set_pipeline(struct isc_device *isc, u32 pipeline) +/** + * isc_lut_to_hw() - Convert a 64-entry 10-bit LUT to ISC register format + * @lut: 64-element array of 10-bit output values (0-1023); element i + * is the desired output for input range [i*16 .. (i+1)*16 - 1]. + * @hw: 64-element output array to receive the packed hardware values. + * @bipartite: true for SAMA7G5 (ISC_GAM_CTRL_BIPART active): delta is sto= red + * as a Q9 per-step increment (multiply by 32 =3D 512/16). + * false for SAMA5D2: delta is a plain per-segment increment. + * + * Each hardware register word packs two fields: + * bits[31:16] =3D 10-bit output value at the start of segment i + * bits[15:0] =3D interpolation delta + * + * In bipartite mode the hardware uses the delta to linearly interpolate + * across all 16 input steps within the segment (Q9 fixed-point: delta/512 + * per step). In non-bipartite mode the hardware applies a constant output + * across the whole segment. + */ +static void isc_lut_to_hw(const u32 *lut, u32 *hw, bool bipartite) +{ + unsigned int i; + u32 cur, next, delta; + + for (i =3D 0; i < GAMMA_ENTRIES; i++) { + cur =3D lut[i]; + next =3D (i < GAMMA_ENTRIES - 1) ? lut[i + 1] : 1023; + + /* + * Bipartite (SAMA7G5): delta =3D per-step increment in Q9 + * =3D (next - cur) * 512 / 16 =3D (next - cur) * 32 + * Non-bipartite (SAMA5D2): delta =3D per-segment increment + * =3D (next - cur) + */ + delta =3D bipartite ? (next - cur) * 32 : (next - cur); + + hw[i] =3D (cur << 16) | (delta & 0xffff); + } +} + +/** + * isc_apply_gamma() - Write gamma LUT registers from current ctrls state + * @isc: ISC device + * + * Converts ctrls->gamma_lut_{b,g,r}[] to hardware format via isc_lut_to_h= w() + * and writes all three ISC_GAM_*ENTRY register banks. Falls back to the + * preset gamma_table when gamma_lut_override is false. + * + * Must be called before isc_update_profile() whenever the gamma curve cha= nges + * mid-stream, since isc_update_profile() only commits whatever is already= in + * the registers to the active pipeline shadow. + */ +static void isc_apply_gamma(struct isc_device *isc) { struct regmap *regmap =3D isc->regmap; struct isc_ctrls *ctrls =3D &isc->ctrls; - u32 val, bay_cfg; const u32 *gamma; + u32 hw[GAMMA_ENTRIES]; + + if (ctrls->gamma_lut_override) { + isc_lut_to_hw(ctrls->gamma_lut_b, hw, isc->gamma_bipartite); + regmap_bulk_write(regmap, ISC_GAM_BENTRY, hw, GAMMA_ENTRIES); + isc_lut_to_hw(ctrls->gamma_lut_g, hw, isc->gamma_bipartite); + regmap_bulk_write(regmap, ISC_GAM_GENTRY, hw, GAMMA_ENTRIES); + isc_lut_to_hw(ctrls->gamma_lut_r, hw, isc->gamma_bipartite); + regmap_bulk_write(regmap, ISC_GAM_RENTRY, hw, GAMMA_ENTRIES); + } else { + gamma =3D &isc->gamma_table[ctrls->gamma_index][0]; + regmap_bulk_write(regmap, ISC_GAM_BENTRY, gamma, GAMMA_ENTRIES); + regmap_bulk_write(regmap, ISC_GAM_GENTRY, gamma, GAMMA_ENTRIES); + regmap_bulk_write(regmap, ISC_GAM_RENTRY, gamma, GAMMA_ENTRIES); + } +} + +static void isc_set_pipeline(struct isc_device *isc, u32 pipeline) +{ + struct regmap *regmap =3D isc->regmap; + u32 val, bay_cfg; unsigned int i; =20 /* WB-->CFA-->CC-->GAM-->CSC-->CBC-->SUB422-->SUB420 */ @@ -275,10 +347,7 @@ static void isc_set_pipeline(struct isc_device *isc, u= 32 pipeline) =20 regmap_write(regmap, ISC_CFA_CFG, bay_cfg | ISC_CFA_CFG_EITPOL); =20 - gamma =3D &isc->gamma_table[ctrls->gamma_index][0]; - regmap_bulk_write(regmap, ISC_GAM_BENTRY, gamma, GAMMA_ENTRIES); - regmap_bulk_write(regmap, ISC_GAM_GENTRY, gamma, GAMMA_ENTRIES); - regmap_bulk_write(regmap, ISC_GAM_RENTRY, gamma, GAMMA_ENTRIES); + isc_apply_gamma(isc); =20 isc->config_dpc(isc); isc->config_csc(isc); @@ -1544,11 +1613,35 @@ static void isc_awb_work(struct work_struct *w) pm_runtime_put_sync(isc->dev); } =20 +/* + * isc_update_gamma_lut_override() - Evaluate gamma LUT override flag + * + * Activates the per-channel LUT override only when at least one entry + * across any channel is non-zero. An all-zero write (including the + * default initialisation from v4l2_ctrl_handler_setup) disables the + * override so the built-in gamma table remains active. + */ +static void isc_update_gamma_lut_override(struct isc_ctrls *ctrls) +{ + unsigned int i; + bool any_nonzero =3D false; + + for (i =3D 0; i < GAMMA_ENTRIES && !any_nonzero; i++) { + if (ctrls->gamma_lut_b[i] || + ctrls->gamma_lut_g[i] || + ctrls->gamma_lut_r[i]) + any_nonzero =3D true; + } + ctrls->gamma_lut_override =3D any_nonzero; +} + static int isc_s_ctrl(struct v4l2_ctrl *ctrl) { struct isc_device *isc =3D container_of(ctrl->handler, struct isc_device, ctrls.handler); struct isc_ctrls *ctrls =3D &isc->ctrls; + struct regmap *regmap =3D isc->regmap; + bool apply_gamma =3D false; =20 if (ctrl->flags & V4L2_CTRL_FLAG_INACTIVE) return 0; @@ -1583,11 +1676,42 @@ static int isc_s_ctrl(struct v4l2_ctrl *ctrl) break; case V4L2_CID_GAMMA: ctrls->gamma_index =3D ctrl->val; + ctrls->gamma_lut_override =3D false; + apply_gamma =3D true; + break; + case ISC_CID_GAMMA_B_LUT: + memcpy(ctrls->gamma_lut_b, ctrl->p_new.p_u32, + GAMMA_ENTRIES * sizeof(u32)); + isc_update_gamma_lut_override(ctrls); + apply_gamma =3D true; + break; + case ISC_CID_GAMMA_G_LUT: + memcpy(ctrls->gamma_lut_g, ctrl->p_new.p_u32, + GAMMA_ENTRIES * sizeof(u32)); + isc_update_gamma_lut_override(ctrls); + apply_gamma =3D true; + break; + case ISC_CID_GAMMA_R_LUT: + memcpy(ctrls->gamma_lut_r, ctrl->p_new.p_u32, + GAMMA_ENTRIES * sizeof(u32)); + isc_update_gamma_lut_override(ctrls); + apply_gamma =3D true; break; default: return -EINVAL; } =20 + /* + * isc_apply_gamma() writes gamma LUT registers; it must be called + * under awb_mutex so it does not race with isc_awb_work() which also + * calls isc_update_profile() under the same lock. + */ + mutex_lock(&isc->awb_mutex); + if (apply_gamma) + isc_apply_gamma(isc); + isc_update_profile(isc); + mutex_unlock(&isc->awb_mutex); + return 0; } =20 @@ -1939,7 +2063,12 @@ static int isc_ctrl_init(struct isc_device *isc) ctrls->hist_stat =3D HIST_INIT; isc_reset_awb_ctrls(isc); =20 - ret =3D v4l2_ctrl_handler_init(hdl, 13); + /* + * 30 controls maximum (SAMA7G5 with CBHS): + * contrast(1) + brightness(1) + hue+saturation(2) + gamma(1) + + * awb+do_wb(2) + 4=C3=97gain + 4=C3=97offset + 12=C3=97CC + 3=C3=97gam= ma_LUT + */ + ret =3D v4l2_ctrl_handler_init(hdl, 30); if (ret < 0) return ret; =20 @@ -1995,6 +2124,11 @@ static int isc_ctrl_init(struct isc_device *isc) isc->cc_bb =3D v4l2_ctrl_new_custom(hdl, &isc_cc_bb_ctrl, NULL); isc->cc_ob =3D v4l2_ctrl_new_custom(hdl, &isc_cc_ob_ctrl, NULL); =20 + /* Per-channel gamma LUT controls */ + isc->gamma_b_lut_ctrl =3D v4l2_ctrl_new_custom(hdl, &isc_gamma_b_lut_ctrl= , NULL); + isc->gamma_g_lut_ctrl =3D v4l2_ctrl_new_custom(hdl, &isc_gamma_g_lut_ctrl= , NULL); + isc->gamma_r_lut_ctrl =3D v4l2_ctrl_new_custom(hdl, &isc_gamma_r_lut_ctrl= , NULL); + /* * The cluster is in auto mode with autowhitebalance enabled * and manual mode otherwise. diff --git a/drivers/media/platform/microchip/microchip-isc.h b/drivers/med= ia/platform/microchip/microchip-isc.h index db651c9f1387..a4f1e6c22e44 100644 --- a/drivers/media/platform/microchip/microchip-isc.h +++ b/drivers/media/platform/microchip/microchip-isc.h @@ -165,6 +165,17 @@ struct isc_ctrls { #define HIST_MAX_INDEX 1 u32 hist_minmax[HIST_BAYER][2]; =20 + /* + * Custom per-channel gamma LUT (10-bit output values, 64 entries). + * Set via ISC_CID_GAMMA_{R,G,B}_LUT controls. When gamma_lut_override + * is true these arrays are converted to hardware format at pipeline + * start-up, overriding the preset curve from gamma_index. + */ + u32 gamma_lut_r[GAMMA_ENTRIES]; + u32 gamma_lut_g[GAMMA_ENTRIES]; + u32 gamma_lut_b[GAMMA_ENTRIES]; + bool gamma_lut_override; + /* CC matrix shadow; committed from isc_set_pipeline() and isc_awb_work()= */ s32 cc_coeff[ISC_CC_COEFF_NUM]; s32 cc_offset[ISC_CC_OFFSET_NUM]; @@ -363,12 +374,24 @@ struct isc_device { struct v4l2_ctrl *cc_ob; }; =20 -#define GAMMA_ENTRIES 64 /* pointer to the defined gamma table */ const u32 (*gamma_table)[GAMMA_ENTRIES]; u32 gamma_max; bool has_cbhs; =20 + /* + * When true the GAM block operates in bipartite piecewise-linear + * interpolation mode (ISC_GAM_CTRL_BIPART set). The LUT-to-hardware + * conversion uses a Q9 per-step delta; without bipartite mode the + * delta is a plain per-segment increment. + */ + bool gamma_bipartite; + + /* V4L2 ctrl handles for the per-channel gamma LUT override */ + struct v4l2_ctrl *gamma_b_lut_ctrl; + struct v4l2_ctrl *gamma_g_lut_ctrl; + struct v4l2_ctrl *gamma_r_lut_ctrl; + u32 max_width; u32 max_height; =20 diff --git a/drivers/media/platform/microchip/microchip-sama7g5-isc.c b/dri= vers/media/platform/microchip/microchip-sama7g5-isc.c index 6705011edc2a..9110690a49e4 100644 --- a/drivers/media/platform/microchip/microchip-sama7g5-isc.c +++ b/drivers/media/platform/microchip/microchip-sama7g5-isc.c @@ -461,6 +461,7 @@ static int microchip_xisc_probe(struct platform_device = *pdev) isc->gamma_table =3D isc_sama7g5_gamma_table; isc->gamma_max =3D 2; isc->has_cbhs =3D true; + isc->gamma_bipartite =3D true; =20 if (of_machine_is_compatible("microchip,sam9x7")) { isc->max_width =3D ISC_SAM9X7_MAX_SUPPORT_WIDTH; diff --git a/include/linux/atmel-isc-media.h b/include/linux/atmel-isc-medi= a.h index 028d34c8de81..459e96170d9e 100644 --- a/include/linux/atmel-isc-media.h +++ b/include/linux/atmel-isc-media.h @@ -66,6 +66,24 @@ enum atmel_isc_ctrl_id { ISC_CID_CC_BG, ISC_CID_CC_BB, ISC_CID_CC_OB, + + /* + * Per-channel gamma LUT override controls. + * + * Each control is a 64-element U32 array. Element i holds the + * desired 10-bit output value (0-1023) for sensor input values in + * the range [i*16 .. (i+1)*16 - 1]. The driver converts the + * simple linear array to the hardware piecewise-linear (bipartite) + * register format internally. + * + * Setting any of these controls activates the custom LUT for all + * three channels and overrides the preset curve selected by + * V4L2_CID_GAMMA. Writing V4L2_CID_GAMMA deactivates the custom + * LUT and restores the selected preset curve. + */ + ISC_CID_GAMMA_B_LUT, + ISC_CID_GAMMA_G_LUT, + ISC_CID_GAMMA_R_LUT, }; =20 #endif --=20 2.34.1 From nobody Fri Jun 12 21:11:38 2026 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F057B3C9898; Tue, 12 May 2026 15:44:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.153.233 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778600664; cv=none; b=qsTux7lo0/JsdAYxMznDdRTJnDqmhPTA7c3jk0P5LuZkxFh19cC4Ygh8mZm0nZl5ONNd3IkrswQAOV/sRZKO8SNYO1I/ECYUXQiZMo5mY5Sp1/Qde10a8v0Ngb3Wbv7rWJWrw2AMeXz6sPNFeXAWgFU94UQlLFyGTc00mir5YBE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778600664; c=relaxed/simple; bh=1iseWDcRf6EDPp88AY5mtnrMFZ7P423KfW/rfCuNG1w=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=n1N6uYR6CIeeAve68uNzzcNfR0rfdeWzsH3lLntvxmC6Z5QrzkF1DzO29MKQh+AW4RqH5EN6rudEZE6LWf0UEQXl1h3+pkCM8gNfO4ve1VkgwtpftWg/3YEcYAXk841OXE82V/GC86qNaN9rE//lozFF6TVBLqnPxynv3lW6KDI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=jHorsZA9; arc=none smtp.client-ip=68.232.153.233 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.b="jHorsZA9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1778600662; x=1810136662; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1iseWDcRf6EDPp88AY5mtnrMFZ7P423KfW/rfCuNG1w=; b=jHorsZA9HqQXcTjSnakVXcStgD4AK7l81K0CutCa1VQBb+fOyGjwUvG1 ov9kJcMCYDd0UGOlNa3xGPZ4pVlj/0j8/pfSPXQfaNw/fLSaNLzb3rjSA ZrzXPhxBBgR0zlj3cIyhqMw4j7rRNe0AKWZnwthAV4u1O6AzihPWtkEiE G1ukIWqB+kMx9PvphZn8Ts1HyAXco30BR+5/+mBovj6o83d9VcPmGn6vs 2vZ6oc6/YFXzw1vg0DMRx+fHkA57fTBnbKQ2xLGaCgBus7vSv8ZtXuSyt jdqW19Q/fdYRD91PfQ+fuJrZPWAXEzRznNv6SpMjvSx4XFFX+izsTnOcz Q==; X-CSE-ConnectionGUID: 1LHL1LrlQSWeonkBZq/K0w== X-CSE-MsgGUID: UPnM6DQqQyWFoiffY2LRAA== X-IronPort-AV: E=Sophos;i="6.23,231,1770620400"; d="scan'208";a="65713131" 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; 12 May 2026 08:44:22 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.58; Tue, 12 May 2026 08:44:21 -0700 Received: from che-ll-i71840.microchip.com (10.10.85.11) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.58 via Frontend Transport; Tue, 12 May 2026 08:44:19 -0700 From: Balakrishnan Sambath To: CC: , , , , Subject: [PATCH v2 12/15] media: microchip-isc: reset pipeline state on kernel AWB enable Date: Tue, 12 May 2026 21:13:36 +0530 Message-ID: <20260512154339.210444-13-balakrishnan.s@microchip.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260512154339.210444-1-balakrishnan.s@microchip.com> References: <20251009155251.102472-1-balamanikandan.gunasundar@microchip.com> <20260512154339.210444-1-balakrishnan.s@microchip.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" gamma_lut_override and cc_coeff[] persist across control writes. When kernel AWB is enabled after userspace has customized the gamma curve or color correction matrix, the stale settings produce incorrect color. Clear gamma_lut_override and reset cc_coeff[] to identity when V4L2_CID_AUTO_WHITE_BALANCE is set to 1. Signed-off-by: Balakrishnan Sambath --- .../platform/microchip/microchip-isc-base.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/microchip/microchip-isc-base.c b/driver= s/media/platform/microchip/microchip-isc-base.c index 3749f473c3c6..e6386f8852e5 100644 --- a/drivers/media/platform/microchip/microchip-isc-base.c +++ b/drivers/media/platform/microchip/microchip-isc-base.c @@ -1730,10 +1730,22 @@ static int isc_s_awb_ctrl(struct v4l2_ctrl *ctrl) =20 switch (ctrl->id) { case V4L2_CID_AUTO_WHITE_BALANCE: - if (ctrl->val =3D=3D 1) + if (ctrl->val =3D=3D 1) { ctrls->awb =3D ISC_WB_AUTO; - else + /* + * Reset gamma and CC to defaults when enabling kernel + * AWB so it starts with a clean pipeline. + */ + ctrls->gamma_lut_override =3D false; + memset(ctrls->cc_coeff, 0, sizeof(ctrls->cc_coeff)); + ctrls->cc_coeff[0] =3D 256; /* RR */ + ctrls->cc_coeff[4] =3D 256; /* GG */ + ctrls->cc_coeff[8] =3D 256; /* BB */ + memset(ctrls->cc_offset, 0, sizeof(ctrls->cc_offset)); + ctrls->cc_dirty =3D true; + } else { ctrls->awb =3D ISC_WB_NONE; + } =20 /* configure the controls with new values from v4l2 */ if (ctrl->cluster[ISC_CTRL_R_GAIN]->is_new) --=20 2.34.1 From nobody Fri Jun 12 21:11:38 2026 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 495DE3ABD91; Tue, 12 May 2026 15:44:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.154.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778600668; cv=none; b=G9DIt6iMJWAVCJPTEdjmd7otNxQwJidRbMFGRoKHNe+1aT5xsk0Sc6/VVGUWfrtdOQB+bzt/EuZYKblwNe8KkWmP1QyZj7L2KDnyfE1+scQ5Ym2iMqODGSObUwFbrvrnZZGOEEGBNcH9GBjEmac75oSSxlj0mEixXXDFXjoI/vc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778600668; c=relaxed/simple; bh=GlKaxV0bBjGbvBXUWvk0e5s7WtjX09HZUeoJL6n7wpQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bfFAEfkBcPYYK/YrSRhNtb7mLN1tSoqcoS5QSIEvKUG2G+jwIZdL84BbNySGm3JKlGGQlKkq19jhiKimxbOrC0rVXOWDokDeKdNXbt0iFBzWsvQ6pUaMzdv/dimdy+Toc8Ec3KwLr3qrizUsemgk+1wl6AuOOobBnf4Md3ADQiw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=QRDUtoFh; arc=none smtp.client-ip=68.232.154.123 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.b="QRDUtoFh" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1778600666; x=1810136666; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GlKaxV0bBjGbvBXUWvk0e5s7WtjX09HZUeoJL6n7wpQ=; b=QRDUtoFhWYSNada3rJYhCNEbaSEottFYWFYvP6mAHqgzrVTLhwEfSC7F u0axZ/J5lvhGmrNUk33i+uY95U8m5sX6tKzmzP6WiEdoY7QM2l0RnhDcR XbUVWidtyYzysfcJsdaSkvy3j+36MFxtj1ov09NHFui3sUN78/5TqHC+I M3X1+a1GcyC838R2wA1SH6CMpOvRBR76fWyYn+XA2pDbad+JF1fCcKll+ egXXCWRS+VPnquumFlv/AZ7cJDE6AKQYRK+RHY9Y7WYYyImkrqVgkSY14 ZB254cvleqpDmqAPmYj+Q8p9DgAXxq7UR+ozUQ6hwnk5OwUKIBTEsM+eq g==; X-CSE-ConnectionGUID: 8Svjjv0QRlCA5HY5ZrUlOA== X-CSE-MsgGUID: bhCy90YaS/+67pOTIpqsAw== X-IronPort-AV: E=Sophos;i="6.23,231,1770620400"; d="scan'208";a="56617614" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa4.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 May 2026 08:44:25 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.87.72) by chn-vm-ex3.mchp-main.com (10.10.87.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.2562.37; Tue, 12 May 2026 08:44:24 -0700 Received: from che-ll-i71840.microchip.com (10.10.85.11) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.58 via Frontend Transport; Tue, 12 May 2026 08:44:22 -0700 From: Balakrishnan Sambath To: CC: , , , , Subject: [PATCH v2 13/15] media: microchip-isc: use weighted averages for Grey World AWB Date: Tue, 12 May 2026 21:13:37 +0530 Message-ID: <20260512154339.210444-14-balakrishnan.s@microchip.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260512154339.210444-1-balakrishnan.s@microchip.com> References: <20251009155251.102472-1-balamanikandan.gunasundar@microchip.com> <20260512154339.210444-1-balakrishnan.s@microchip.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Replace pixel counts with intensity-weighted averages. Add 2% outlier rejection at histogram tails. Signed-off-by: Balakrishnan Sambath --- .../platform/microchip/microchip-isc-base.c | 167 +++++++++++++----- .../media/platform/microchip/microchip-isc.h | 2 + 2 files changed, 125 insertions(+), 44 deletions(-) diff --git a/drivers/media/platform/microchip/microchip-isc-base.c b/driver= s/media/platform/microchip/microchip-isc-base.c index e6386f8852e5..8fcf64708dc8 100644 --- a/drivers/media/platform/microchip/microchip-isc-base.c +++ b/drivers/media/platform/microchip/microchip-isc-base.c @@ -40,6 +40,12 @@ (((mbus_code) =3D=3D MEDIA_BUS_FMT_Y10_1X10) | \ (((mbus_code) =3D=3D MEDIA_BUS_FMT_Y8_1X8))) =20 +/* 4.0 in Q9 fixed-point: cap grey-world correction at 4x. */ +#define ISC_AWB_GW_GAIN_MAX (4u << 9) + +/* Outlier rejection: skip darkest/brightest 2% of histogram. */ +#define ISC_AWB_OUTLIER_DIV 50 + static inline void isc_update_v4l2_ctrls(struct isc_device *isc) { struct isc_ctrls *ctrls =3D &isc->ctrls; @@ -1404,6 +1410,11 @@ static void isc_hist_count(struct isc_device *isc, u= 32 *min, u32 *max) u32 *hist_count =3D &ctrls->hist_count[ctrls->hist_id]; u32 *hist_entry =3D &ctrls->hist_entry[0]; u32 i; + u32 total_pixels; + u32 dark_threshold, bright_threshold; + u32 cumulative; + u64 weighted_sum; + u32 pixel_count; =20 *min =3D 0; *max =3D HIST_ENTRIES; @@ -1411,44 +1422,103 @@ static void isc_hist_count(struct isc_device *isc,= u32 *min, u32 *max) regmap_bulk_read(regmap, ISC_HIS_ENTRY + isc->offsets.his_entry, hist_entry, HIST_ENTRIES); =20 - *hist_count =3D 0; - /* - * we deliberately ignore the end of the histogram, - * the most white pixels - */ + /* Calculate total pixels */ + total_pixels =3D 0; + for (i =3D 0; i < HIST_ENTRIES; i++) + total_pixels +=3D hist_entry[i]; + + /* Handle empty histogram case */ + if (total_pixels =3D=3D 0) { + *hist_count =3D 0; + ctrls->channel_avg[ctrls->hist_id] =3D 256; /* Default middle value */ + ctrls->total_pixels[ctrls->hist_id] =3D 0; + *min =3D 1; + *max =3D HIST_ENTRIES - 1; + dev_dbg(isc->dev, + "isc wb: no pixels in histogram for channel %u\n", + ctrls->hist_id); + return; + } + + /* Outlier rejection: skip darkest/brightest 2% of histogram */ + dark_threshold =3D total_pixels / ISC_AWB_OUTLIER_DIV; + bright_threshold =3D total_pixels / ISC_AWB_OUTLIER_DIV; + cumulative =3D 0; + + /* Find effective minimum (skip dark noise) */ + *min =3D 1; for (i =3D 1; i < HIST_ENTRIES; i++) { - if (*hist_entry && !*min) + cumulative +=3D hist_entry[i]; + if (cumulative > dark_threshold) { *min =3D i; - if (*hist_entry) + break; + } + } + + /* Find effective maximum (skip bright saturation) */ + cumulative =3D 0; + *max =3D HIST_ENTRIES - 1; + for (i =3D HIST_ENTRIES - 1; i > *min; i--) { + cumulative +=3D hist_entry[i]; + if (cumulative > bright_threshold) { *max =3D i; - *hist_count +=3D i * (*hist_entry++); + break; + } } =20 + /* Ensure reasonable range */ + if (*max <=3D *min) { + *min =3D HIST_ENTRIES / 4; + *max =3D (HIST_ENTRIES * 3) / 4; + } + + /* Calculate both pixel count and weighted average for useful range */ + *hist_count =3D 0; + weighted_sum =3D 0; + + for (i =3D *min; i <=3D *max; i++) { + pixel_count =3D hist_entry[i]; + *hist_count +=3D pixel_count; + weighted_sum +=3D (u64)i * pixel_count; + } + + /* Store total useful pixels for this channel */ + ctrls->total_pixels[ctrls->hist_id] =3D *hist_count; + + /* Calculate channel average */ + if (*hist_count > 0) + ctrls->channel_avg[ctrls->hist_id] =3D + div64_u64(weighted_sum, *hist_count); + else + /* Default middle value */ + ctrls->channel_avg[ctrls->hist_id] =3D 256; + if (!*min) *min =3D 1; =20 - dev_dbg(isc->dev, "isc wb: hist_id %u, hist_count %u", - ctrls->hist_id, *hist_count); + dev_dbg(isc->dev, + "isc wb: hist_id %u, avg %u, count %u, range [%u,%u], total %u\n", + ctrls->hist_id, ctrls->channel_avg[ctrls->hist_id], + *hist_count, *min, *max, total_pixels); } =20 static void isc_wb_update(struct isc_ctrls *ctrls) { struct isc_device *isc =3D container_of(ctrls, struct isc_device, ctrls); - u32 *hist_count =3D &ctrls->hist_count[0]; u32 c, offset[4]; u64 avg =3D 0; - /* We compute two gains, stretch gain and grey world gain */ - u32 s_gain[4], gw_gain[4]; + u32 gain, gw_gain, s_gain; + u32 min_pixels; + u32 frame_pixels; =20 /* * According to Grey World, we need to set gains for R/B to normalize * them towards the green channel. - * Thus we want to keep Green as fixed and adjust only Red/Blue - * Compute the average of the both green channels first + * Thus we want to keep Green as fixed and adjust only Red/Blue. + * Compute the average of the both green channels first. */ - avg =3D (u64)hist_count[ISC_HIS_CFG_MODE_GR] + - (u64)hist_count[ISC_HIS_CFG_MODE_GB]; - avg >>=3D 1; + avg =3D (ctrls->channel_avg[ISC_HIS_CFG_MODE_GR] + + ctrls->channel_avg[ISC_HIS_CFG_MODE_GB]) >> 1; =20 dev_dbg(isc->dev, "isc wb: green components average %llu\n", avg); =20 @@ -1456,7 +1526,23 @@ static void isc_wb_update(struct isc_ctrls *ctrls) if (!avg) return; =20 + /* + * Require a minimum pixel count for both black-level offset and + * grey-world gain: 1/64 of the frame area, which equals ~6.25% of + * one Bayer channel's expected pixel count. This scales with sensor + * resolution and prevents noise-dominated histograms (from very small + * crops or a nearly-empty frame) from producing wild corrections. + * A floor of 64 ensures the guard is non-zero for tiny crops. + */ + frame_pixels =3D isc->fmt.fmt.pix.width * isc->fmt.fmt.pix.height; + min_pixels =3D frame_pixels ? max(frame_pixels >> 6, 64u) : 64u; + for (c =3D ISC_HIS_CFG_MODE_GR; c <=3D ISC_HIS_CFG_MODE_B; c++) { + u32 hist_min =3D ctrls->hist_minmax[c][HIST_MIN_INDEX]; + u32 hist_max =3D ctrls->hist_minmax[c][HIST_MAX_INDEX]; + u32 channel_avg =3D ctrls->channel_avg[c]; + u32 total_pixels =3D ctrls->total_pixels[c]; + /* * the color offset is the minimum value of the histogram. * we stretch this color to the full range by substracting @@ -1482,40 +1568,33 @@ static void isc_wb_update(struct isc_ctrls *ctrls) ctrls->offset[c] =3D -ctrls->offset[c]; =20 /* - * the stretch gain is the total number of histogram bins - * divided by the actual range of color component (Max - Min) - * If we compute gain like this, the actual color component - * will be stretched to the full histogram. - * We need to shift 9 bits for precision, we have 9 bits for - * decimals + * Stretch gain: scale the histogram range [hist_min, hist_max] + * to the full 512-bin span. Result is in Q9 fixed-point + * (1.0 =3D 512). */ - s_gain[c] =3D (HIST_ENTRIES << 9) / - (ctrls->hist_minmax[c][HIST_MAX_INDEX] - - ctrls->hist_minmax[c][HIST_MIN_INDEX] + 1); + s_gain =3D (HIST_ENTRIES << 9) / (hist_max - hist_min + 1); =20 /* - * Now we have to compute the gain w.r.t. the average. - * Add/lose gain to the component towards the average. - * If it happens that the component is zero, use the - * fixed point value : 1.0 gain. + * Grey-world gain: scale each channel towards the green + * average. Require a minimum pixel count so noise-dominated + * channels do not produce wild corrections. */ - if (hist_count[c]) - gw_gain[c] =3D div_u64(avg << 9, hist_count[c]); + if (channel_avg > 0 && total_pixels >=3D min_pixels) + gw_gain =3D div64_u64((avg << 9), channel_avg); else - gw_gain[c] =3D 1 << 9; + gw_gain =3D 1 << 9; =20 - dev_dbg(isc->dev, - "isc wb: component %d, s_gain %u, gw_gain %u\n", - c, s_gain[c], gw_gain[c]); - /* multiply both gains and adjust for decimals */ - ctrls->gain[c] =3D s_gain[c] * gw_gain[c]; - ctrls->gain[c] >>=3D 9; + /* Cap grey-world correction at 4x to avoid over-amplification. */ + gw_gain =3D min_t(u32, gw_gain, ISC_AWB_GW_GAIN_MAX); =20 - /* make sure we are not out of range */ - ctrls->gain[c] =3D clamp_val(ctrls->gain[c], 0, GENMASK(12, 0)); + /* Combine stretch and grey-world gains; result stays in Q9. */ + gain =3D (s_gain * gw_gain) >> 9; =20 - dev_dbg(isc->dev, "isc wb: component %d, final gain %u\n", - c, ctrls->gain[c]); + ctrls->gain[c] =3D clamp_val(gain, 0, GENMASK(12, 0)); + + dev_dbg(isc->dev, + "isc wb: c=3D%u black=3D%u avg=3D%u s_gain=3D%u gw_gain=3D%u gain=3D%u", + c, hist_min, channel_avg, s_gain, gw_gain, gain); } } =20 diff --git a/drivers/media/platform/microchip/microchip-isc.h b/drivers/med= ia/platform/microchip/microchip-isc.h index a4f1e6c22e44..44d54404250d 100644 --- a/drivers/media/platform/microchip/microchip-isc.h +++ b/drivers/media/platform/microchip/microchip-isc.h @@ -164,6 +164,8 @@ struct isc_ctrls { #define HIST_MIN_INDEX 0 #define HIST_MAX_INDEX 1 u32 hist_minmax[HIST_BAYER][2]; + u32 channel_avg[HIST_BAYER]; /* Average pixel intensity per channel = */ + u32 total_pixels[HIST_BAYER]; /* Total pixels per channel */ =20 /* * Custom per-channel gamma LUT (10-bit output values, 64 entries). --=20 2.34.1 From nobody Fri Jun 12 21:11:38 2026 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0FE713CB8F5; Tue, 12 May 2026 15:44:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.153.233 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778600670; cv=none; b=YYwoJZ024T2YWfBVvKvrRYIo2TaJ4RjtZbhu09A0RZv9B162+PyqupiWC7y08TcoJV2xkCOpZCnKnFhWLzWaXYTVlgzcI6sRmWl7bFttoqUC022jCzE5wc4jLLp/LozBvAUyalWja2Vazmi1ywscckc2fkUiKL3Y+EQ2ROx8CQ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778600670; c=relaxed/simple; bh=sUg/FdHhKpneoz83f5ukXAk07OBSKcQTvrRyENYAQqc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rNCMWUNdNs39NJiVtI51vWsZNnSdBtbCwLOyl8SchLdtpEgX4nXdF98eiEDn2H2xcU4kc0J9Ttn3hiUJOwBPAPr5zL4C3T9a6ZuiF7w+azMEGdMY5ufjsoEwvx5fJYNyjkoFQ5ric/J/HE/hMK91NAwAKs490te72+bztaKTS3w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=V+1c4W7I; arc=none smtp.client-ip=68.232.153.233 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.b="V+1c4W7I" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1778600670; x=1810136670; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sUg/FdHhKpneoz83f5ukXAk07OBSKcQTvrRyENYAQqc=; b=V+1c4W7IcgDuKK2A/eLCTY3vc/rEagtxR/817/zfTE2gHIlEf9IvY7Ao 0B/PKLLHYQKHnda80cHnuBTJnRD+6NxESvyDxcTRmlfJB0GFBzXWQvkzp 7bCG5n6G0AljjGcZQ+YK5z8IG61iXdiQV1vlKjoJX+nG8xthvaTBDR2Q0 ga6wncwUI9UoIwjVGcbhsT7kfNfIBEu+69SPvuakYDTuCEwIjEnNq0pQq f8riMQ3TVBGRNEKuucODaZyhSlCsC9ImJ4TO7J0jLw4s3N/DZCC0+K+jB jdjOTCTHgPGNs9ZI/Ml8bRYZRYin+p5hXq+0LQJ+EJThm1Izsx6157BVp g==; X-CSE-ConnectionGUID: XbB0UJlXTyWhbhgmk7NgVQ== X-CSE-MsgGUID: YcUDCRPpT0WNLM73Gd8ogA== X-IronPort-AV: E=Sophos;i="6.23,231,1770620400"; d="scan'208";a="288760485" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa5.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 12 May 2026 08:44:29 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.58; Tue, 12 May 2026 08:44:27 -0700 Received: from che-ll-i71840.microchip.com (10.10.85.11) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.58 via Frontend Transport; Tue, 12 May 2026 08:44:25 -0700 From: Balakrishnan Sambath To: CC: , , , , Subject: [PATCH v2 14/15] media: microchip-isc: smooth AWB gains with EMA filter Date: Tue, 12 May 2026 21:13:38 +0530 Message-ID: <20260512154339.210444-15-balakrishnan.s@microchip.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260512154339.210444-1-balakrishnan.s@microchip.com> References: <20251009155251.102472-1-balamanikandan.gunasundar@microchip.com> <20260512154339.210444-1-balakrishnan.s@microchip.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Apply exponential moving average (alpha=3D0.25) to reduce per-frame flicker from sensor noise. Signed-off-by: Balakrishnan Sambath --- .../platform/microchip/microchip-isc-base.c | 19 ++++++++++++++++--- .../media/platform/microchip/microchip-isc.h | 1 + 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/drivers/media/platform/microchip/microchip-isc-base.c b/driver= s/media/platform/microchip/microchip-isc-base.c index 8fcf64708dc8..072386aa2d73 100644 --- a/drivers/media/platform/microchip/microchip-isc-base.c +++ b/drivers/media/platform/microchip/microchip-isc-base.c @@ -134,6 +134,7 @@ static inline void isc_reset_awb_ctrls(struct isc_devic= e *isc) for (c =3D ISC_HIS_CFG_MODE_GR; c <=3D ISC_HIS_CFG_MODE_B; c++) { /* gains have a fixed point at 9 decimals */ isc->ctrls.gain[c] =3D 1 << 9; + isc->ctrls.gain_smooth[c] =3D 1 << 9; /* offsets are in 2's complements */ isc->ctrls.offset[c] =3D 0; } @@ -1590,11 +1591,23 @@ static void isc_wb_update(struct isc_ctrls *ctrls) /* Combine stretch and grey-world gains; result stays in Q9. */ gain =3D (s_gain * gw_gain) >> 9; =20 - ctrls->gain[c] =3D clamp_val(gain, 0, GENMASK(12, 0)); + /* + * Smooth gain updates with an exponential weighted average + * to suppress per-frame flicker: + * smooth[n] =3D (3 * smooth[n-1] + gain) / 4 + * Clamp to the hardware register width to prevent unbounded + * accumulation under degenerate (near-empty histogram) inputs. + */ + ctrls->gain_smooth[c] =3D (3 * ctrls->gain_smooth[c] + gain) / 4; + ctrls->gain_smooth[c] =3D min_t(u32, ctrls->gain_smooth[c], + GENMASK(12, 0)); + + ctrls->gain[c] =3D ctrls->gain_smooth[c]; =20 dev_dbg(isc->dev, - "isc wb: c=3D%u black=3D%u avg=3D%u s_gain=3D%u gw_gain=3D%u gain=3D%u", - c, hist_min, channel_avg, s_gain, gw_gain, gain); + "isc wb: c=3D%u black=3D%u avg=3D%u s_gain=3D%u gw_gain=3D%u gain=3D%u = smooth=3D%u\n", + c, hist_min, channel_avg, s_gain, gw_gain, gain, + ctrls->gain_smooth[c]); } } =20 diff --git a/drivers/media/platform/microchip/microchip-isc.h b/drivers/med= ia/platform/microchip/microchip-isc.h index 44d54404250d..e558f1a65b33 100644 --- a/drivers/media/platform/microchip/microchip-isc.h +++ b/drivers/media/platform/microchip/microchip-isc.h @@ -155,6 +155,7 @@ struct isc_ctrls { =20 /* one for each component : GR, R, GB, B */ u32 gain[HIST_BAYER]; + u32 gain_smooth[HIST_BAYER]; s32 offset[HIST_BAYER]; =20 u32 hist_entry[HIST_ENTRIES]; --=20 2.34.1 From nobody Fri Jun 12 21:11:38 2026 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 13C3D3CC32E; Tue, 12 May 2026 15:44:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.153.233 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778600673; cv=none; b=JwY/ADmPJIMIgqYLHsZZKI+6lBMYJpqZI9hNwQhj6qImaTQsFeHyAObgFnRua6toI/SlIJwjbmHx6C/l/iuvaOj88nRLjm3+G4fRHcZwBj8koE3t0Z2bdeyZs03TcukJKbvdLKGWXQNmMJddjDOUu/7guQtAb3JgowMuIo8veII= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778600673; c=relaxed/simple; bh=pYFtLLi3SuyNLJBpvcInLmiZVX11uNDvUzoUsZ/OyFk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Cq47sZnH+Db7sQUypsLEHaFzhug67E2puVrDXYL1b9GHK8CcwWLnlBf9pK2UvS0EpyCi3+h7qOL23Q6p7e2KIbEZgID6fE0pJ6+dFFZi2YIaovmZiR9FxYsOscbvpOua+apYSGdCBTv1VG3HFrpMYf6DBKaLdRngBmxxUyqWUEI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=2V65yl0K; arc=none smtp.client-ip=68.232.153.233 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.b="2V65yl0K" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1778600671; x=1810136671; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pYFtLLi3SuyNLJBpvcInLmiZVX11uNDvUzoUsZ/OyFk=; b=2V65yl0KiGeu4whg8abvnulNFKVsk+E5jNLjB0dLaitG6FwjvpIe56Af FvG7e2Pw01DGi24u1dibiHRBjRqtgJAofiFJe0zOJfhFUbNVQIiAPQDKL Vk3n1WUJDDsDnUIurUg6k8xF17lDZH+mtINr3KFFap9ifb7syUu29qnlt E1H6NN3b+ihJ7PNpkBntWroa6kYdyIvEByptdTEIu3LNyqtDztcgi1GMT BlkLhIYTvBJNFO62H2bdKT5BXGtPITC3CCGwgXA6vcvwHL7ks3kfnt2Ye pDrkW5VT7DEyMHT0jlK+/5XoUwDkij08HkN68/w33LJkSpw7Y+yb06Ws3 g==; X-CSE-ConnectionGUID: 7VKwAiZmTNKMDu6LJmODwA== X-CSE-MsgGUID: 690o/XQFRj6HCTZVC6gTBQ== X-IronPort-AV: E=Sophos;i="6.23,231,1770620400"; d="scan'208";a="65713144" 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; 12 May 2026 08:44:31 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.58; Tue, 12 May 2026 08:44:31 -0700 Received: from che-ll-i71840.microchip.com (10.10.85.11) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.58 via Frontend Transport; Tue, 12 May 2026 08:44:28 -0700 From: Balakrishnan Sambath To: CC: , , , , Subject: [PATCH v2 15/15] media: microchip-isc: scale DPC black level to sensor bit depth Date: Tue, 12 May 2026 21:13:39 +0530 Message-ID: <20260512154339.210444-16-balakrishnan.s@microchip.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260512154339.210444-1-balakrishnan.s@microchip.com> References: <20251009155251.102472-1-balamanikandan.gunasundar@microchip.com> <20260512154339.210444-1-balakrishnan.s@microchip.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Scale the nominal 10-bit black level (64 counts) to match 8/10/12-bit sensor bus width. Signed-off-by: Balakrishnan Sambath --- .../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/dri= vers/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 */ =20 +#include #include #include #include @@ -289,9 +290,25 @@ static void isc_sama7g5_config_dpc(struct isc_device *= isc) { u32 bay_cfg =3D isc->config.sd_format->cfa_baycfg; struct regmap *regmap =3D 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 =3D 4 -> 8-bit -> bloff =3D 64 >> 2 =3D 16 + * BPS_TEN =3D 2 -> 10-bit -> bloff =3D 64 + * BPS_TWELVE =3D 0 -> 12-bit -> bloff =3D min(64 << 2, 255) =3D 255 + * The BLOFF hardware field is 8-bit so values are clamped to 255. + */ + bps =3D FIELD_GET(ISC_PFE_CFG0_BPS_MASK, isc->config.sd_format->pfe_cfg0_= bps); + if (bps >=3D 2) + bloff =3D 64u >> (bps - 2); + else + bloff =3D min(64u << (2 - bps), 255u); =20 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)); } --=20 2.34.1