From nobody Mon Jun 8 18:55:45 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 4DF473F58EB; Wed, 27 May 2026 11:07:28 +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=1779880049; cv=none; b=PrFzUgr5ds7BfNL6G2zljIpZOq8Aed/2jSRipBp86DIIz54seCBH6Yo2q6yfPWN4HFn1YeV46WFN0KyJQtB6bPs9JxL1q5qnhtsFp/NirsNE2aS1v/+ASNeXTsrSDqpWZQEHE/v0byXBk5LUFcRP0qycQIPQitf2ny5Ctn+jMZc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779880049; c=relaxed/simple; bh=s5FEVHROvLP2S0pgM+SNM27cVGpm3APnhg11Q3HsKK4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=B30//z2jmrsuvqQYLqTjJCthmzhOeUP6VyxujKv8OpvuwfbI+JvppU8x98jAilGdNCbaC779ow3yg33x2brT4xcn6UlLysati2bVKJidFy40Pcg/IAf032amZm20x+cjqhgBHEA2BiQtIVA4Ra2zktIGzmz/B1UuMPtrvQv+Nb4= 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=wSNkOKFN; 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="wSNkOKFN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1779880048; x=1811416048; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=s5FEVHROvLP2S0pgM+SNM27cVGpm3APnhg11Q3HsKK4=; b=wSNkOKFN+oaR+wHVi4i4nr+Zs2RCcsX8cDD0gNA9/ajj5iybFlkKawY8 /cLvo6QQ1puBd5bcABzF5CLBSH3D7r9Y1gjovsL6nrUOEOnZZj1hRLCb+ 0jXkGwFwP6MqE74N9Pu92whtFtutZKIhki2/CLI0Ky5xE05TalY14DCgz j8fCgHGHDx/SNCB61XMbE5HSthZHfZUsC9S8iGmqpBGSck3uSnqPrYsZr IgL4z5Nq9bERbAS7d0IERoZgGhdpPiEwsJzrjHIauPZ+uZdO6l8m5kbVN P0Cs6RZYfJPNN/hBBNCNs7VtPge0rSzu7K5+0Zc9nw8oQKe4B1x/N8b0K Q==; X-CSE-ConnectionGUID: 1EldW+AvQGWYm3JvHnSnBQ== X-CSE-MsgGUID: eEUW60PeTDS8WOMR8cBH6A== X-IronPort-AV: E=Sophos;i="6.24,171,1774335600"; d="scan'208";a="66995028" 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; 27 May 2026 04:07:27 -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; Wed, 27 May 2026 04:07:27 -0700 Received: from [127.0.0.1] (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; Wed, 27 May 2026 04:07:22 -0700 From: Balakrishnan Sambath Date: Wed, 27 May 2026 16:37:17 +0530 Subject: [PATCH v5 01/12] media: microchip-isc: fix SBGGR10 Bayer pattern Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20260527-microchip-isc-fixes-v5-1-b0ec1bb954be@microchip.com> References: <20260527-microchip-isc-fixes-v5-0-b0ec1bb954be@microchip.com> In-Reply-To: <20260527-microchip-isc-fixes-v5-0-b0ec1bb954be@microchip.com> To: Eugen Hristev , Mauro Carvalho Chehab , Hans Verkuil CC: Laurent Pinchart , Kieran Bingham , Sakari Ailus , Balamanikandan Gunasundar , , , , "Balakrishnan Sambath" X-Mailer: b4 0.14.3 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 Reviewed-by: Eugen Hristev --- drivers/media/platform/microchip/microchip-sama5d2-isc.c | 2 +- drivers/media/platform/microchip/microchip-sama7g5-isc.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/microchip/microchip-sama5d2-isc.c b/dri= vers/media/platform/microchip/microchip-sama5d2-isc.c index 66d3d7891991..0ddff1e7b0a0 100644 --- a/drivers/media/platform/microchip/microchip-sama5d2-isc.c +++ b/drivers/media/platform/microchip/microchip-sama5d2-isc.c @@ -147,7 +147,7 @@ static struct isc_format sama5d2_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, 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 Mon Jun 8 18:55:45 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 AD4FD3F4111; Wed, 27 May 2026 11:07:32 +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=1779880054; cv=none; b=vAU2Rxlfpvv/AVaFh7rbVtp99dVtYYsLmRZxQVAo41866pzjAPrUnLu4w1n9Qt/JxbaPy6lRMg7LVVO2zoKMLMz2qe/J4+Phuu+CInzIlv6eVJGs90BEX62GGuXjDv6dVCV8tIc8lT1KWHPbklr+6hTaHKNEhzPheXXdjcM9AfE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779880054; c=relaxed/simple; bh=gvdrgbWAjTx1CGi+PD6csR2l/AwBIyyRN8PqO/RwaYE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=L5igZyvxWs3VNu5GchLLkSDv1E0r3XNF7MS6qonhuspv6nhhtA+tpaiRJGCBSgXZBVV3PbrunUkyjhf/BEatOMlLtdUk/R33cFOF7yP45Cuepwan3u1wGY/XErJP2EYh9XGCZm7sSlpaLPrHGMZk9lg7mqku1FxV3j6vj3Q2hEg= 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=WoU41Uo0; 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="WoU41Uo0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1779880052; x=1811416052; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=gvdrgbWAjTx1CGi+PD6csR2l/AwBIyyRN8PqO/RwaYE=; b=WoU41Uo0wX2RJ3HKnowbc3o3WVlO3iRk8vZ+iRnzhiK43F6eG5wWPriM a/KiC2/nB/g7PmLKYWiG2q74WRLH7oMJfAR9DvAbaCs+vJsXISoB1lTFu jn0qVSGyg/1TpM4uO6EPXTQp22x+a381No6to7BB8QjlO4dr/HdBUri/b g99OmtUROawqWChwUzywVDrucz++E/YtYSYFQmsJiwItl++e+I4EQDAz/ OZMxwE4kTjIeGG6kxQ4RP0ENOVDwdqUYybk5zSRD2ovbdVGE3/rde/2Xm s6eyRhS1uLpfZLMAedagVUziKkj9XwDjObhuKWC5CKNXjIbrRemz03aOF w==; X-CSE-ConnectionGUID: 0DJN6ARWQbmuWsxbhB66lA== X-CSE-MsgGUID: ghkaf6t8SkqkKEMPqifvQA== X-IronPort-AV: E=Sophos;i="6.24,171,1774335600"; d="scan'208";a="225356274" 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; 27 May 2026 04:07:31 -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.41; Wed, 27 May 2026 04:07:31 -0700 Received: from [127.0.0.1] (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; Wed, 27 May 2026 04:07:27 -0700 From: Balakrishnan Sambath Date: Wed, 27 May 2026 16:37:18 +0530 Subject: [PATCH v5 02/12] media: microchip-isc: fix WB offset and gain register field masking Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20260527-microchip-isc-fixes-v5-2-b0ec1bb954be@microchip.com> References: <20260527-microchip-isc-fixes-v5-0-b0ec1bb954be@microchip.com> In-Reply-To: <20260527-microchip-isc-fixes-v5-0-b0ec1bb954be@microchip.com> To: Eugen Hristev , Mauro Carvalho Chehab , Hans Verkuil CC: Laurent Pinchart , Kieran Bingham , Sakari Ailus , Balamanikandan Gunasundar , , , , "Balakrishnan Sambath" X-Mailer: b4 0.14.3 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: 91b4e487b0c6 ("media: microchip: add ISC driver as Microchip ISC") Cc: stable@vger.kernel.org Signed-off-by: Balakrishnan Sambath --- .../media/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 Mon Jun 8 18:55:45 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 0BBC13F4111; Wed, 27 May 2026 11:07:36 +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=1779880058; cv=none; b=b+VhCuGUIh8Zd0HXmAWx54IWnMecs5bmJrZ2laSK6sSKkI8q3zEESVYHZA0LdKky0Rla61BCTs7ImgmWEq/OjvoZODKsCn2cSUSLmp6A42hcRZFWNnipIxq0dMOkh4+bIyIWChZRt+aKyYrXS0+XDudYmxMk2V7bYNruLEhqleA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779880058; c=relaxed/simple; bh=aU0h4iGXClnIzKcybJRuKFUv+3+oLLIWDAVu+DcXYDk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=GpYt6IPIkCVpF97fW9aOM2MCjWa3GATQNRQcOshosGArhYY7HUyDsn398wBjhtGI0mdbIkR1cL/8AmFSIjjioHU3+raEzFkmZ8okOJXN67TY61hZ6JISa2kxAE9QhYr+bAPbIUME2q3musZc79ppIklgRRA7+g2qfZRQBurcwUs= 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=fT0osknP; 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="fT0osknP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1779880057; x=1811416057; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=aU0h4iGXClnIzKcybJRuKFUv+3+oLLIWDAVu+DcXYDk=; b=fT0osknPYLdvV9Oko0XrFey7mz/czp7mTOu9mvHWiMLfKVHE/AhybzuO uWbZ9zN/9U7l0tNz189LCwI7j/GfUAHb7QUMKDYWmAgNvxslgXlHelfBg FsRRpsf8jPUIxeB312NEV8XkBaQcl41ehbYJE9FC2iBEH+w1iBLGJv+ar 8Hy7GcJi6XcNfYukePDXHqk9EMRMOx3mAVr2zQEAyYKNsoIe45gwW7ofb aV3tSDJmxsES4G0vlk6GwXyOIcg8oT8dOaZAe+fcGZnLd57vKEfdzB7BU FH64dQsWZcQXVOJPjXltK6rLoEZcJ1PTid8Zs9bhJPdoZI+Lw97Pf7Ie4 Q==; X-CSE-ConnectionGUID: +GzW8YAjRs6BAuMWdf9HmQ== X-CSE-MsgGUID: opLibaBLR92WJ3T96Y/opA== X-IronPort-AV: E=Sophos;i="6.24,171,1774335600"; d="scan'208";a="58112116" 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; 27 May 2026 04:07:36 -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; Wed, 27 May 2026 04:07:35 -0700 Received: from [127.0.0.1] (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; Wed, 27 May 2026 04:07:32 -0700 From: Balakrishnan Sambath Date: Wed, 27 May 2026 16:37:19 +0530 Subject: [PATCH v5 03/12] media: microchip-isc: fix race condition on stream stop Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20260527-microchip-isc-fixes-v5-3-b0ec1bb954be@microchip.com> References: <20260527-microchip-isc-fixes-v5-0-b0ec1bb954be@microchip.com> In-Reply-To: <20260527-microchip-isc-fixes-v5-0-b0ec1bb954be@microchip.com> To: Eugen Hristev , Mauro Carvalho Chehab , Hans Verkuil CC: Laurent Pinchart , Kieran Bingham , Sakari Ailus , Balamanikandan Gunasundar , , , , "Balakrishnan Sambath" X-Mailer: b4 0.14.3 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 --- drivers/media/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 Mon Jun 8 18:55:45 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 6C9C23F4111; Wed, 27 May 2026 11:07:41 +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=1779880062; cv=none; b=Nv/4sKrNdXfBpqxl0TPFnphZfbDjtbUizYuaUT54iySaXFVjVi9zj7eAWLDxUm5bAZQiLOZDfsrlDz3ygEkWj5xkO7A1JC0IfsRLGOLjwZmbk/dcBTatsMeqNELodC+h+6rnyoXZFgaUV6MKkwRdWB0XU5ffZu3juuQ4YpAoNao= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779880062; c=relaxed/simple; bh=nN9+zsfRheHiwR0iNWCgcstHm1IznAMW4+4pvqexfH0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=svPEjRqScADleS4m+pCucoqCKSOoTNGgitJG3kZqiHWZsuH3E3keWmC+4fQcrDsoz3AJhybBDvCjPNdDPv1lFvCRCQJg5HlCMbQ6zb2LkvjI5F8V9v+t24T/+vYmpD5zwco6aw08wQ8GVCULtx4LGu0Qae/cRu9HdVYUvy+LeSM= 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=tEbf/UHL; 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="tEbf/UHL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1779880061; x=1811416061; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=nN9+zsfRheHiwR0iNWCgcstHm1IznAMW4+4pvqexfH0=; b=tEbf/UHLGu+cbddBrs3HdAtTPGStfCF3BldA78haL9nJwNi8Tt1IR1aZ Tr0A64FHLxhAL2YmTAkFYmQnePJafbSg/8Ws8dFwJa523NDppfffwuJoP OrO81JmgdFUf0YJ6AAjUWAR8Y4Lum9D1skNmxPdyzGr9rDh36fdjiIhHU mOGHu9JcmLiYaP+x3bAupWqG/CoBZLQUmBKKlGJBQWpiyNzrZwSPqfC54 QlGDF31xVbHP0mnJ352iFiFw5MWUDD6Ai+v0E+bW0ryGdowsNdxQlI79w /+QOhWNFloFr0akZG5efutmdPTFGtVnAM9w22NkMiJz2zz/yhABExtM3r w==; X-CSE-ConnectionGUID: 3z9xbcEeTsOTnYxEXs0bdg== X-CSE-MsgGUID: R9ZdlWdFQ8y1OwvuWZyL5w== X-IronPort-AV: E=Sophos;i="6.24,171,1774335600"; d="scan'208";a="66995036" 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; 27 May 2026 04:07:40 -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; Wed, 27 May 2026 04:07:40 -0700 Received: from [127.0.0.1] (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; Wed, 27 May 2026 04:07:36 -0700 From: Balakrishnan Sambath Date: Wed, 27 May 2026 16:37:20 +0530 Subject: [PATCH v5 04/12] media: microchip-isc: fix PM runtime leak in AWB work handler Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20260527-microchip-isc-fixes-v5-4-b0ec1bb954be@microchip.com> References: <20260527-microchip-isc-fixes-v5-0-b0ec1bb954be@microchip.com> In-Reply-To: <20260527-microchip-isc-fixes-v5-0-b0ec1bb954be@microchip.com> To: Eugen Hristev , Mauro Carvalho Chehab , Hans Verkuil CC: Laurent Pinchart , Kieran Bingham , Sakari Ailus , Balamanikandan Gunasundar , , , , "Balakrishnan Sambath" X-Mailer: b4 0.14.3 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 Reviewed-by: Eugen Hristev --- 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 Mon Jun 8 18:55:45 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 E470F3F4111; Wed, 27 May 2026 11:07:45 +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=1779880067; cv=none; b=MXUmwnGpvRqiUkJA+zt0K1Ni2ifGE4lttFiY5nfcvnnCFtYj8Nfw8dAaoc/yY5GKvUoOTWHgAsoK6GG1Tc49HRzwG4Xx93mYVcqhMhlAsHZod5CZjHF8VJz4s+wPFygrh/wCY5EsKIut8Wclz+nOi4W8WyqTOLg1X2+llG0O5SA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779880067; c=relaxed/simple; bh=4p1nOK1AL01zVsZFng11HLuCgzoGQIn2GfQDSRycJVc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=Ks3PBIanbAseBK51mWyFs126roobdS/t9QV7kFhSAYF5jA31yckApGaDVJ3xyIMYdcm9F+PKPF72QpNfSZn/RXbr2vIGLKxnH5+DVBoQkEnR5Y4CtESLeIgWPOC8R0fZFr5rogAFwksyb39TEKDjwaCEaIjvDJfwX99eXw3gDos= 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=O7x1pt+A; 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="O7x1pt+A" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1779880066; x=1811416066; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=4p1nOK1AL01zVsZFng11HLuCgzoGQIn2GfQDSRycJVc=; b=O7x1pt+AGUAI7NGU+EDgrfyNapPCS6dvnJ7v3bdbEQBrVbvPKzDjbTVd cnYxQA9/D0GuOl07H+8jSZsm62GWeO4rHh5GKYBqTyX36/egOvXrwAxfK H7QlNjEU/r5iXNHyxxTP8oj71pWdus8yloLdMQC5U8M3qnLi95qZscqXN SBDZr6Cn1Xw2WOupnY0LLhj2Cg0sh7zvGDRh6tbXIaB+2E88uVNf8CkaC p7+XvIvcJvC/IHssETNfAu3RVhNqi8wzcy10P4vtGyAM01T6qK8QxsCIF fFJNMxi/UJ5hL3QQYkF2Ugs4qzM5JUtZGWjsRhXcH1TZOVB5C6hn0W/09 g==; X-CSE-ConnectionGUID: O0EhRf+aT1q32V+UXNzCkg== X-CSE-MsgGUID: m1eQuSuiRlGAVYJwcBKfVg== X-IronPort-AV: E=Sophos;i="6.24,171,1774335600"; d="scan'208";a="58112117" 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; 27 May 2026 04:07:45 -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; Wed, 27 May 2026 04:07:44 -0700 Received: from [127.0.0.1] (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; Wed, 27 May 2026 04:07:40 -0700 From: Balakrishnan Sambath Date: Wed, 27 May 2026 16:37:21 +0530 Subject: [PATCH v5 05/12] media: microchip-isc: add driver documentation Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20260527-microchip-isc-fixes-v5-5-b0ec1bb954be@microchip.com> References: <20260527-microchip-isc-fixes-v5-0-b0ec1bb954be@microchip.com> In-Reply-To: <20260527-microchip-isc-fixes-v5-0-b0ec1bb954be@microchip.com> To: Eugen Hristev , Mauro Carvalho Chehab , Hans Verkuil CC: Laurent Pinchart , Kieran Bingham , Sakari Ailus , Balamanikandan Gunasundar , , , , "Balakrishnan Sambath" X-Mailer: b4 0.14.3 Document the driver topology, supported formats, controls, the AWB algorithm, the gamma table layout, and the Microchip-specific custom controls exposed via atmel-isc-media.h. Signed-off-by: Balakrishnan Sambath --- .../userspace-api/media/drivers/index.rst | 1 + .../userspace-api/media/drivers/microchip-isc.rst | 68 ++++++++++++++++++= ++++ MAINTAINERS | 1 + 3 files changed, 70 insertions(+) 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..7272ccec0169 --- /dev/null +++ b/Documentation/userspace-api/media/drivers/microchip-isc.rst @@ -0,0 +1,68 @@ +.. 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 a preset curve. Indices differ + per SoC: SAMA7G5/SAM9X7 use 0=3D1/2.4, 1=3D1/2.2 (default), 2=3D1/1.8; + SAMA5D2 uses 0=3D1/1.8, 1=3D1/2.0, 2=3D1/2.2 (default). +* ``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..127, default 16 (Q4 fixed-point, 16 =3D 1.0x) + +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 + +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) +* 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 e08767323763..d4aa7e86e2bd 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -17057,6 +17057,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 Mon Jun 8 18:55:45 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 9486A3F58E1; Wed, 27 May 2026 11:07:50 +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=1779880072; cv=none; b=D4lVsQYgYj6j0T88PmhJgT9GFQvhdJIq58CqWAkc9KuLMSEwLj18nWVRmjWI7iUs7kdbxj9IsjXBOUprnZdds2o4ClF8Jd1HDE6iplIaf/8zZSnm7i8g5E3bb9mj6NCuoJZx8fpKrvZ94x3a3Lr8+weMEemhMhffeg4cUFT22PM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779880072; c=relaxed/simple; bh=T+zVygOBokk79HhCYGyT4FwHbQ8HXxSoWftezh8efK0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=dk5k8LMIQavbSXdFPcLvXEe+a0U8AuNTPJoNPghyiObI1MDn/ZeJt0spUjTOrpzjSqfQPyFWg8ttDlZm0zaF4QOEl5vgephEYKGJCpjo1foljcHBJGYyJdwXrkHfGM1KqvlYGul9j3uxRKOdQWIr5ucWghkcYht3UK+hGjx+XC8= 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=BjT3WbEZ; 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="BjT3WbEZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1779880070; x=1811416070; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=T+zVygOBokk79HhCYGyT4FwHbQ8HXxSoWftezh8efK0=; b=BjT3WbEZvH1yyK3yDwurNtqVIEY2KhJvAlkqguKoUOgp+AWKz/EXv9/w 7H5JAaYUvMDmQ2wpxnQVMPl7SWhH+74d8fhAAp9jJJwkqSDaekOzVv80e WX89oOiX8r4/nZ8KZEFq1tQ2e5MXUCQT5lyC91nkQZqsyrZHWsgnv4/DM IMGQmKW6S2NCfGsfS5LwiKLAxCagjn+sHkt3ufWsTuhccNwDfxjdwC4Df jAe5Bh45q1Itc46SKKrYQ/2l6LE21oLZTF1FT6taqYlNpAHq8f0YWCPWu Yi9i512K+v//zV7Jf2VDmY8xFFw4slOTwyXsSfLthtzhYFebCkw3iByCF A==; X-CSE-ConnectionGUID: 6nWmiUMtR9a3WXDcAPLN3w== X-CSE-MsgGUID: SKCZIK8XSBek6xvzva+nNQ== X-IronPort-AV: E=Sophos;i="6.24,171,1774335600"; d="scan'208";a="58532060" 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; 27 May 2026 04:07:50 -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.41; Wed, 27 May 2026 04:07:49 -0700 Received: from [127.0.0.1] (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; Wed, 27 May 2026 04:07:45 -0700 From: Balakrishnan Sambath Date: Wed, 27 May 2026 16:37:22 +0530 Subject: [PATCH v5 06/12] media: microchip-isc: set SAM9X7 maximum resolution to 2560x1920 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20260527-microchip-isc-fixes-v5-6-b0ec1bb954be@microchip.com> References: <20260527-microchip-isc-fixes-v5-0-b0ec1bb954be@microchip.com> In-Reply-To: <20260527-microchip-isc-fixes-v5-0-b0ec1bb954be@microchip.com> To: Eugen Hristev , Mauro Carvalho Chehab , Hans Verkuil CC: Laurent Pinchart , Kieran Bingham , Sakari Ailus , Balamanikandan Gunasundar , , , , "Balakrishnan Sambath" X-Mailer: b4 0.14.3 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. Co-developed-by: Balamanikandan Gunasundar Signed-off-by: Balamanikandan Gunasundar Signed-off-by: Balakrishnan Sambath --- drivers/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 Mon Jun 8 18:55:45 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 38FBF3F58E1; Wed, 27 May 2026 11:07:55 +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=1779880076; cv=none; b=syhxKLOPz6VZXynBudjTOY0IFFDJzAJpTrK1m6osFo3whe5rdxaSct6FzCGa3O935/kRIOOQx+0WSK2d0NINox/mfff06ZxXUVFTiKdfpoSK1Y14YlXQYRfArShbwArkVf+KHhIb4t8b6XgCZRh0MgcX3cUD5UsZ/jkJkn0jP+g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779880076; c=relaxed/simple; bh=drHEvYa4YJpTMJ4qYN35cNY20m8cHSTXYxTJca/Jg9M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=KBHAtLTfX3TZa2i48QUsBVdpu9kn6W0RVWJk/oQyNYEyYg6yT8m/U0zmw2M/g/LQfe+cuvMp5sAAHgnCqCx+aJFrYKzH783PwrmKU9yK0LiLI5KFu4m5lOAaD9CWVlOWkn4GoW/q7GD1FXkqHtLDx0quPMWK2fdrzQvwK4VDQpI= 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=sws3Ucj2; 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="sws3Ucj2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1779880075; x=1811416075; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=drHEvYa4YJpTMJ4qYN35cNY20m8cHSTXYxTJca/Jg9M=; b=sws3Ucj2HIt+CsVKFTClmF2tEhaNhOpHwcFa//GHFNlvo3r23CZ6eNRX zrqRTb/8T/h6YBHqcjfaMWe3NpF39erpYPB+Q191FM+HCu5UnJDN8Dbgf bAgDOOfG2Y8HfFE31EaGOjq6kmwimU53bEbB8N3CglYLmEXriruJv7yDR vZzj0Wop8mmA68hisUWnVPTnWfpTUekb+iuzPtKmwFkP9Pt+DHfkP4Vog uoel004W0nVOoKAjGe5EUxCxb4+RRV0YyzrgzsVa00RoyF2OmbUyoRmV2 qWYGfySfH7TlIyfV4tY8tb1Z0pZ4PImDHrLK6BHD27qW+z2f/C+I22T16 A==; X-CSE-ConnectionGUID: drKn2R8hTNqdHpaPYCXNqg== X-CSE-MsgGUID: hR9f2rnwRs2uBJj3UU84qg== X-IronPort-AV: E=Sophos;i="6.24,171,1774335600"; d="scan'208";a="289504005" 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; 27 May 2026 04:07:55 -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.41; Wed, 27 May 2026 04:07:53 -0700 Received: from [127.0.0.1] (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; Wed, 27 May 2026 04:07:49 -0700 From: Balakrishnan Sambath Date: Wed, 27 May 2026 16:37:23 +0530 Subject: [PATCH v5 07/12] media: microchip-isc: configure DPC and pipeline for SAMA7G5 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20260527-microchip-isc-fixes-v5-7-b0ec1bb954be@microchip.com> References: <20260527-microchip-isc-fixes-v5-0-b0ec1bb954be@microchip.com> In-Reply-To: <20260527-microchip-isc-fixes-v5-0-b0ec1bb954be@microchip.com> To: Eugen Hristev , Mauro Carvalho Chehab , Hans Verkuil CC: Laurent Pinchart , Kieran Bingham , Sakari Ailus , Balamanikandan Gunasundar , , , , "Balakrishnan Sambath" X-Mailer: b4 0.14.3 Enable DPC black level and green disparity correction for raw Bayer to RGB conversion. Bypass the pipeline for raw Bayer output so software ISPs (libcamera) receive unmodified sensor data. Rename CBC_ENABLE to CBHS_ENABLE to match the SAMA7G5 block name; SAMA5D2's CBC sub-block uses the same bitmap bit. Co-developed-by: Balamanikandan Gunasundar Signed-off-by: Balamanikandan Gunasundar Signed-off-by: Balakrishnan Sambath --- drivers/media/platform/microchip/microchip-isc-base.c | 15 ++++++------= --- drivers/media/platform/microchip/microchip-isc.h | 2 +- drivers/media/platform/microchip/microchip-sama5d2-isc.c | 2 +- drivers/media/platform/microchip/microchip-sama7g5-isc.c | 5 +++-- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/drivers/media/platform/microchip/microchip-isc-base.c b/driver= s/media/platform/microchip/microchip-isc-base.c index f61a5d5a3e04..ff920019fe37 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; } @@ -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,16 +844,13 @@ static int isc_try_configure_pipeline(struct isc_devi= ce *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; } 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-isc.h b/drivers/med= ia/platform/microchip/microchip-isc.h index ad4e98a1dd8f..a943b072f6be 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 diff --git a/drivers/media/platform/microchip/microchip-sama5d2-isc.c b/dri= vers/media/platform/microchip/microchip-sama5d2-isc.c index 0ddff1e7b0a0..71609a93358a 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 4119cfe12cdf..daa3978a89bd 100644 --- a/drivers/media/platform/microchip/microchip-sama7g5-isc.c +++ b/drivers/media/platform/microchip/microchip-sama7g5-isc.c @@ -59,8 +59,9 @@ #define ISC_SAM9X7_MAX_SUPPORT_HEIGHT 1920 =20 #define ISC_SAMA7G5_PIPELINE \ - (WB_ENABLE | CFA_ENABLE | CC_ENABLE | GAM_ENABLES | CSC_ENABLE | \ - CBC_ENABLE | SUB422_ENABLE | SUB420_ENABLE) + (DPC_DPCENABLE | DPC_GDCENABLE | DPC_BLCENABLE | \ + WB_ENABLE | CFA_ENABLE | CC_ENABLE | GAM_ENABLES | CSC_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 { --=20 2.34.1 From nobody Mon Jun 8 18:55:45 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 BB8D13F7AAB; Wed, 27 May 2026 11:07: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=1779880081; cv=none; b=lR6YNwI5j/kVXU6lFR5QY5t0Q2WDuc+zak27odX+4xLsxvifxG6zf+VPV2fqKi3fBZjGtDzDk0Xkf0MZ8qXglR3qM92tnihfrPv3di5GSWuuBhuuXtala6ysYh6CjjqZNnoN0OqPixnRChCO6zFDwP2ZAzwCcrdlMKiIHhc/kWU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779880081; c=relaxed/simple; bh=ZqH+yL0Lzbq6SNGKJGY6TU/qVgWm+YEoZ09E0XBTFMI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=iraYc3jF7Ds6/m1Wu1oaAFZCGMn1mKHGZJlN3dCzihj5LUPecEZPpR9G1AyYcc0YM4Q30lkM3A0rJX6ccA1k8lm8J0C/fdkkF9Vs085n2gPLQtRmpqLEFO/E220U06IZU6bUzNcmqlbEIpIhvMcyl0j2/jw4HLiTN9FL95j1qSI= 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=mr8RK9JB; 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="mr8RK9JB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1779880079; x=1811416079; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=ZqH+yL0Lzbq6SNGKJGY6TU/qVgWm+YEoZ09E0XBTFMI=; b=mr8RK9JBfrb6R4YtJr/ROP1TGsjRHKAKlD5wi1JT/mtFeXWPhJT2JtVU sjgkSqCElxCvPgcH7PXyfXyhWqHVRMh+rI0Rumz/pC5W8k4tORlLQQnOD U7hVbhy01zKXNGk3cisiqpp4yaj7kY6WprF+HWcbEOgebF70e2vENAw/g 1vFtpSSoYTdISCPnpMDNpwgTHD8b8T4fglPe9xqPFNCPxYYhNuwyICrR6 g9kTtfYB+XKjhpLKeIYwUlv86LPxxnMWVUx2yAMBePMTOX+GML7NCJOWl Uvgp4K1uCKC3OySFIlecytcJlkkwjJmkOnuvuukpcxvUliqxVpTyb1oPV w==; X-CSE-ConnectionGUID: IkHmY59wTXaNgxtHpBF2TQ== X-CSE-MsgGUID: r4xRdowBR6iYOoLXCj8E2A== X-IronPort-AV: E=Sophos;i="6.24,171,1774335600"; d="scan'208";a="66995047" 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; 27 May 2026 04:07:58 -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; Wed, 27 May 2026 04:07:58 -0700 Received: from [127.0.0.1] (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; Wed, 27 May 2026 04:07:54 -0700 From: Balakrishnan Sambath Date: Wed, 27 May 2026 16:37:24 +0530 Subject: [PATCH v5 08/12] media: microchip-isc: add gamma 1.8 and 2.4 correction curves Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20260527-microchip-isc-fixes-v5-8-b0ec1bb954be@microchip.com> References: <20260527-microchip-isc-fixes-v5-0-b0ec1bb954be@microchip.com> In-Reply-To: <20260527-microchip-isc-fixes-v5-0-b0ec1bb954be@microchip.com> To: Eugen Hristev , Mauro Carvalho Chehab , Hans Verkuil CC: Laurent Pinchart , Kieran Bingham , Sakari Ailus , Balamanikandan Gunasundar , , , , "Balakrishnan Sambath" X-Mailer: b4 0.14.3 Display profiles for older macOS content (gamma 1.8) and HDR pipelines (gamma 2.4) need curves not covered by the existing sRGB 2.2 default. Add the two extra curves to the SAMA7G5 table so userspace can pick a curve matching the target display profile. The two SoCs put gamma 1/2.2 at different indices in their tables (SAMA5D2 at index 2, SAMA7G5 at index 1), so introduce a gamma_default field on struct isc_device and let each platform set it. The SAMA5D2 default of index 2 matches the historical behaviour. Co-developed-by: Balamanikandan Gunasundar Signed-off-by: Balamanikandan Gunasundar Signed-off-by: Balakrishnan Sambath --- .../media/platform/microchip/microchip-isc-base.c | 2 +- drivers/media/platform/microchip/microchip-isc.h | 1 + .../platform/microchip/microchip-sama5d2-isc.c | 2 + .../platform/microchip/microchip-sama7g5-isc.c | 56 ++++++++++++++++--= ---- 4 files changed, 46 insertions(+), 15 deletions(-) diff --git a/drivers/media/platform/microchip/microchip-isc-base.c b/driver= s/media/platform/microchip/microchip-isc-base.c index ff920019fe37..04187127070d 100644 --- a/drivers/media/platform/microchip/microchip-isc-base.c +++ b/drivers/media/platform/microchip/microchip-isc-base.c @@ -1648,7 +1648,7 @@ static int isc_ctrl_init(struct isc_device *isc) =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); + isc->gamma_default); 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-isc.h b/drivers/med= ia/platform/microchip/microchip-isc.h index a943b072f6be..2282ef7dd596 100644 --- a/drivers/media/platform/microchip/microchip-isc.h +++ b/drivers/media/platform/microchip/microchip-isc.h @@ -342,6 +342,7 @@ struct isc_device { /* pointer to the defined gamma table */ const u32 (*gamma_table)[GAMMA_ENTRIES]; u32 gamma_max; + u32 gamma_default; =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 71609a93358a..9fa8413c74c7 100644 --- a/drivers/media/platform/microchip/microchip-sama5d2-isc.c +++ b/drivers/media/platform/microchip/microchip-sama5d2-isc.c @@ -442,6 +442,8 @@ static int microchip_isc_probe(struct platform_device *= pdev) =20 isc->gamma_table =3D isc_sama5d2_gamma_table; isc->gamma_max =3D 2; + /* Index 2 in the SAMA5D2 table is gamma 1/2.2 (sRGB). */ + isc->gamma_default =3D 2; =20 isc->max_width =3D ISC_SAMA5D2_MAX_SUPPORT_WIDTH; isc->max_height =3D ISC_SAMA5D2_MAX_SUPPORT_HEIGHT; diff --git a/drivers/media/platform/microchip/microchip-sama7g5-isc.c b/dri= vers/media/platform/microchip/microchip-sama7g5-isc.c index daa3978a89bd..06aa801b88f9 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,9 @@ 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; + /* Index 1 in the SAMA7G5 table is gamma 1/2.2 (sRGB). */ + isc->gamma_default =3D 1; =20 if (of_machine_is_compatible("microchip,sam9x7")) { isc->max_width =3D ISC_SAM9X7_MAX_SUPPORT_WIDTH; --=20 2.34.1 From nobody Mon Jun 8 18:55:45 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 CC4793EDE4E; Wed, 27 May 2026 11:08: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=1779880085; cv=none; b=NOF3t8qPcCqSXwRrR9nvinpEXLFdzkm/MglkCyqWx7Dlbx+LeK/wpBNZ8Pu/8jnnN6klN/RIJThIywx4ABK+Sqe/rDKFgQnH1PKTRRGNXGwppHGthlghll5puXvoB1Y09t45bLPjTKT1thRpS/ePYRu0rQCH6TQl5f1wXrrAe/g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779880085; c=relaxed/simple; bh=pVmGDAZOYpvv6zhC4vesYSgi0PH4UdqqtX59FCdftXs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=QdCDvJD/iNpAoR7nvEuow24xENxgFM5Ehh9o/T0OmVQOWGhpr0Ifq/BCd8tjIBghHuw+OZ03ZvKsAMM50o/jmMR9lBDMotd938mPl191s5AQPV1+ZfzL48sl/8mFav9qdkZ55wNp+qEzmn59uMCg4YjZGPwQtBv8gHrLYwRfVrI= 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=Cl3TObE8; 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="Cl3TObE8" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1779880083; x=1811416083; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=pVmGDAZOYpvv6zhC4vesYSgi0PH4UdqqtX59FCdftXs=; b=Cl3TObE8sl2iRif58hK5p4ul2M2BENtRv6c8WvRITH7q4DocTRPRvoMb F0tZ1IHU+4HoCPGiVcjELH+bKKz741tUAmh/8fH5qfoahjHVVEZkdk5n5 uZDv2Bcat+HXlyez3bKkyTMJtXiO/HJCfkkaKe8KnqyNFcsQUo5knX0wh 371puUlBE1DSeTe4S32UUIp1gZ6ERNvcJjwCb6FA6dVz8PAPZKzFIKG77 5LIkISx+5mUVGLPdTm/kXBPB42nc3l4BsbGD2xGKpXc03JvGoVoP0b0tm DvOtpbjVTKfusN2I6QuE7ylyRRkV+5+v97h4Qzhl3WDAuadfQO9HJdZ9h g==; X-CSE-ConnectionGUID: syUvuG+5QGGvHUuuXW9bSg== X-CSE-MsgGUID: Njo5+PNoTLyhxF33SUaa+A== X-IronPort-AV: E=Sophos;i="6.24,171,1774335600"; d="scan'208";a="66995049" 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; 27 May 2026 04:08: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; Wed, 27 May 2026 04:08:02 -0700 Received: from [127.0.0.1] (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; Wed, 27 May 2026 04:07:58 -0700 From: Balakrishnan Sambath Date: Wed, 27 May 2026 16:37:25 +0530 Subject: [PATCH v5 09/12] media: microchip-isc: add SAMA7G5 hue and saturation controls Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20260527-microchip-isc-fixes-v5-9-b0ec1bb954be@microchip.com> References: <20260527-microchip-isc-fixes-v5-0-b0ec1bb954be@microchip.com> In-Reply-To: <20260527-microchip-isc-fixes-v5-0-b0ec1bb954be@microchip.com> To: Eugen Hristev , Mauro Carvalho Chehab , Hans Verkuil CC: Laurent Pinchart , Kieran Bingham , Sakari Ailus , Balamanikandan Gunasundar , , , , "Balakrishnan Sambath" X-Mailer: b4 0.14.3 The CBHS (Contrast/Brightness/Hue/Saturation) block on SAMA7G5 operates in YCbCr space; expose hue and saturation as V4L2 controls for the YUV/RGB output paths only. The SAMA5D2 has only the CBC block (no hue/saturation), so the controls are gated on a new has_cbhs flag. Saturation uses the Q4 fixed-point range 0..127 with default 16 (1.0x) directly matching the CBHS_SAT register field. The control state is initialised to neutral at probe so the first config_cbc() write after streaming starts does not produce a grayscale image. Co-developed-by: Balamanikandan Gunasundar Signed-off-by: Balamanikandan Gunasundar Signed-off-by: Balakrishnan Sambath --- .../media/platform/microchip/microchip-isc-base.c | 75 ++++++++++++++++++= ++++ .../media/platform/microchip/microchip-isc-regs.h | 11 ++-- drivers/media/platform/microchip/microchip-isc.h | 3 + .../platform/microchip/microchip-sama7g5-isc.c | 6 +- 4 files changed, 88 insertions(+), 7 deletions(-) diff --git a/drivers/media/platform/microchip/microchip-isc-base.c b/driver= s/media/platform/microchip/microchip-isc-base.c index 04187127070d..cb338133d03f 100644 --- a/drivers/media/platform/microchip/microchip-isc-base.c +++ b/drivers/media/platform/microchip/microchip-isc-base.c @@ -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 @@ -1457,6 +1509,14 @@ static int isc_s_ctrl(struct v4l2_ctrl *ctrl) case V4L2_CID_CONTRAST: ctrls->contrast =3D ctrl->val & ISC_CBC_CONTRAST_MASK; break; + case V4L2_CID_HUE: + if (isc->has_cbhs) + ctrls->hue =3D ctrl->val & ISC_CBHS_HUE_MASK; + break; + case V4L2_CID_SATURATION: + if (isc->has_cbhs) + ctrls->saturation =3D ctrl->val & ISC_CBHS_SAT_MASK; + break; case V4L2_CID_GAMMA: ctrls->gamma_index =3D ctrl->val; break; @@ -1464,6 +1524,7 @@ static int isc_s_ctrl(struct v4l2_ctrl *ctrl) return -EINVAL; } =20 + /* config_cbc() flushes ctrls to hardware at stream start. */ return 0; } =20 @@ -1647,6 +1708,19 @@ 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) { + /* + * CBHS_HUE is a signed 9-bit value in degrees. + * CBHS_SAT is Q4 unsigned 7-bit, 16 =3D 1.0x. + * Initialize the kernel-side state to neutral here so the + * first config_cbc() call after streaming starts does not + * write zero (grayscale) to the hardware. + */ + ctrls->hue =3D 0; + ctrls->saturation =3D 16; + v4l2_ctrl_new_std(hdl, ops, V4L2_CID_HUE, -180, 180, 1, 0); + v4l2_ctrl_new_std(hdl, ops, V4L2_CID_SATURATION, 0, 127, 1, 16); + } v4l2_ctrl_new_std(hdl, ops, V4L2_CID_GAMMA, 0, isc->gamma_max, 1, isc->gamma_default); isc->awb_ctrl =3D v4l2_ctrl_new_std(hdl, &isc_awb_ops, @@ -1665,6 +1739,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..7f5c2e50e74b 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.= .127) */ +#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 2282ef7dd596..36a9c0cb241f 100644 --- a/drivers/media/platform/microchip/microchip-isc.h +++ b/drivers/media/platform/microchip/microchip-isc.h @@ -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 @@ -343,6 +345,7 @@ struct isc_device { const u32 (*gamma_table)[GAMMA_ENTRIES]; u32 gamma_max; u32 gamma_default; + bool has_cbhs; =20 u32 max_width; u32 max_height; diff --git a/drivers/media/platform/microchip/microchip-sama7g5-isc.c b/dri= vers/media/platform/microchip/microchip-sama7g5-isc.c index 06aa801b88f9..f51c7cac25df 100644 --- a/drivers/media/platform/microchip/microchip-sama7g5-isc.c +++ b/drivers/media/platform/microchip/microchip-sama7g5-isc.c @@ -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) @@ -463,6 +462,7 @@ static int microchip_xisc_probe(struct platform_device = *pdev) isc->gamma_max =3D 2; /* Index 1 in the SAMA7G5 table is gamma 1/2.2 (sRGB). */ isc->gamma_default =3D 1; + 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 Mon Jun 8 18:55:45 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 7058E3F9A0E; Wed, 27 May 2026 11:08:08 +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=1779880090; cv=none; b=KtfL6Bu9KgGDzNNv3l2tZbpWPviJKAafAXVm1d4aylDbEz5qeaNjrwOtzjB0vBdevyBhcnnA3LDVcwGEYlXhpbIjhQERwu+GOUkBi2n8qWUmwZhPaL7Qp2yiEoxtaHhWtJJphY/xmOd4omecvo880EL51bB7h/7u5xNv8Qufm6s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779880090; c=relaxed/simple; bh=rR5fr4ULf0Sv1WhGtPh+ZjjLvGC7YLPlCd1eOcLdS3E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=MHWYM1/3IXAAyMo0WQrZ3SEiziRZtDggV5riZPS7gpANni0XJjLb5n+QDJBuJDyMf0F3Ng5PPzB/x0mSd4Uw+LUe57D1u6GZptltEvVQZ1INJ5WEpOnDmfZFpT4bhjRe3G5F5cYquxVsXnsCPNrV6UtnC0dvz5ztbt//hQ5K44Y= 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=AyGD2JEW; 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="AyGD2JEW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1779880088; x=1811416088; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=rR5fr4ULf0Sv1WhGtPh+ZjjLvGC7YLPlCd1eOcLdS3E=; b=AyGD2JEW7YuMG345xjZULE9aZGecZFrsnm54iv+kI9hqOiQeyFDk6TbL kkbLEUFfBIusIjYRRIAZPKThFGZbCo89kbN5Zkkel9TV8dhHNgO3t8IxY u7UM1BjPe7pM11quxL83sft5ib+yOQ6RyDaJtH/fTLN4jchNzPMh84Kjr dtxhkjCBXis6Azndl7GlNao8z0ky5yFuVeJH5sUivVQ+WUR4jGrwEDGg8 OajpvgoTbE4aEvKFuPfmjYi+YBYxvww2FWe2+dyX6pE1IEGzj3hPasRL8 fkPIjw0WaO9sfRVpqfJynxOFQkiDiNB4Ti9fA0aE5eZlKTCfdGtrSYvzT w==; X-CSE-ConnectionGUID: ufsSEcUISVS0eHZh21I99A== X-CSE-MsgGUID: +LLr6lLPQoKbmAarJluQvw== X-IronPort-AV: E=Sophos;i="6.24,171,1774335600"; d="scan'208";a="66995052" 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; 27 May 2026 04:08:07 -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.41; Wed, 27 May 2026 04:08:07 -0700 Received: from [127.0.0.1] (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; Wed, 27 May 2026 04:08:03 -0700 From: Balakrishnan Sambath Date: Wed, 27 May 2026 16:37:26 +0530 Subject: [PATCH v5 10/12] media: microchip-isc: use weighted averages for Grey World AWB Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20260527-microchip-isc-fixes-v5-10-b0ec1bb954be@microchip.com> References: <20260527-microchip-isc-fixes-v5-0-b0ec1bb954be@microchip.com> In-Reply-To: <20260527-microchip-isc-fixes-v5-0-b0ec1bb954be@microchip.com> To: Eugen Hristev , Mauro Carvalho Chehab , Hans Verkuil CC: Laurent Pinchart , Kieran Bingham , Sakari Ailus , Balamanikandan Gunasundar , , , , "Balakrishnan Sambath" X-Mailer: b4 0.14.3 Bright highlights dominate the unweighted pixel-count average and bias grey-world estimates toward overexposed regions. Replace pixel counts with intensity-weighted averages and add 2% outlier rejection at the histogram tails so saturated highlights and the noise floor do not dominate the gain calculation. Also reset the new per-channel histogram statistics in isc_reset_awb_ctrls() so a fresh streaming session does not feed the first AWB cycle with stale values from a previous session. Co-developed-by: Balamanikandan Gunasundar Signed-off-by: Balamanikandan Gunasundar Signed-off-by: Balakrishnan Sambath --- .../media/platform/microchip/microchip-isc-base.c | 180 +++++++++++++++--= ---- drivers/media/platform/microchip/microchip-isc.h | 2 + 2 files changed, 134 insertions(+), 48 deletions(-) diff --git a/drivers/media/platform/microchip/microchip-isc-base.c b/driver= s/media/platform/microchip/microchip-isc-base.c index cb338133d03f..a2719830d39b 100644 --- a/drivers/media/platform/microchip/microchip-isc-base.c +++ b/drivers/media/platform/microchip/microchip-isc-base.c @@ -39,6 +39,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; @@ -82,14 +88,24 @@ static inline void isc_update_awb_ctrls(struct isc_devi= ce *isc) =20 static inline void isc_reset_awb_ctrls(struct isc_device *isc) { + struct isc_ctrls *ctrls =3D &isc->ctrls; unsigned int c; =20 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; + ctrls->gain[c] =3D 1 << 9; /* offsets are in 2's complements */ - isc->ctrls.offset[c] =3D 0; + ctrls->offset[c] =3D 0; } + + /* + * Reset histogram statistics so the first AWB cycle of a new + * streaming session does not feed isc_wb_update with stale + * values left over from a previous session. + */ + memset(ctrls->channel_avg, 0, sizeof(ctrls->channel_avg)); + memset(ctrls->total_pixels, 0, sizeof(ctrls->total_pixels)); + memset(ctrls->hist_minmax, 0, sizeof(ctrls->hist_minmax)); } =20 static int isc_queue_setup(struct vb2_queue *vq, @@ -1286,6 +1302,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; @@ -1293,44 +1314,98 @@ 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 - if (!*min) - *min =3D 1; + /* 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; + } =20 - dev_dbg(isc->dev, "isc wb: hist_id %u, hist_count %u", - ctrls->hist_id, *hist_count); + /* Store total useful pixels for this channel */ + ctrls->total_pixels[ctrls->hist_id] =3D *hist_count; + + if (*hist_count > 0) + ctrls->channel_avg[ctrls->hist_id] =3D + div64_u64(weighted_sum, *hist_count); + else + ctrls->channel_avg[ctrls->hist_id] =3D 256; + + 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 @@ -1338,7 +1413,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 @@ -1364,40 +1455,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 36a9c0cb241f..45168c62e3bc 100644 --- a/drivers/media/platform/microchip/microchip-isc.h +++ b/drivers/media/platform/microchip/microchip-isc.h @@ -158,6 +158,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]; + u32 total_pixels[HIST_BAYER]; }; =20 #define ISC_PIPE_LINE_NODE_NUM 15 --=20 2.34.1 From nobody Mon Jun 8 18:55:45 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 E4CC43FD957; Wed, 27 May 2026 11:08:12 +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=1779880094; cv=none; b=efi3+jw2JBbpTxegKJxaVTUPyK06XFucDzBymqA1eikK3VsGj/gEkd68dh8lmPkALy0B4xTxDJVzcpeBIiWdlQI16pwke2AtiueGwEO0SNHJj4WQvEHRnRb2Ped+7KEJGT0vXoHz/aUKD0ThiAADtgIQLzR5gcFJMwyLO+NY9zg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779880094; c=relaxed/simple; bh=qDvEDWXEKa8hkWcJmwTKKABkJC3pfZSaCyEoriecjCc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=N45wKIDLyeXfznPsZ1S/KB0fZrMCsTCc6nS4UsWoYgYLrzVS8OU2lnQAl09Ehl4osvZHsPHfTnagwu5cYXQiAiMbY+cKSQv8m1NsMUe6IsO+kzTPaOaTg1PIyQr45emcQAWj/UWC4UjDKKwn7e30LAKdcgw0C+yZ8q5FqQ9mZ6Y= 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=eTLg6Fr5; 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="eTLg6Fr5" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1779880093; x=1811416093; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=qDvEDWXEKa8hkWcJmwTKKABkJC3pfZSaCyEoriecjCc=; b=eTLg6Fr5ThyS3lOupe7PqEorhrfg1WFnSYSUVhQPM8ePGz829ADvJXfw gTaI8eOXo4CWNW6ktNuR2ubwFLXJnw40heM/TT4dtQlzbpGEn5EYWHQU2 XkvNFqMCes9Np/RskxswudFeTVN2kUcCjsz3hh2fFUAfMHuemUQ43aSfn BSOzCJIORV+hiZdFtTwyOk6tV1T7G66zTxUoMqCRPnijAAUe4a0rpSBLZ x96Cif3Jq0vJPxuhVEiLcpsWfZoW8JA+WMTuDR6hoWPHGIoCmgh3h7teT mmcSDkJFCkYQxe9NgODYYig9P+iUfOIJ7zK4it5fFz/6YDUZxdSUvLBzc Q==; X-CSE-ConnectionGUID: 2CtCAwlxSXCVN3qBpWODfQ== X-CSE-MsgGUID: AjSiTKxHRj2rMAiwG66s8Q== X-IronPort-AV: E=Sophos;i="6.24,171,1774335600"; d="scan'208";a="58532069" 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; 27 May 2026 04:08: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.41; Wed, 27 May 2026 04:08:11 -0700 Received: from [127.0.0.1] (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; Wed, 27 May 2026 04:08:07 -0700 From: Balakrishnan Sambath Date: Wed, 27 May 2026 16:37:27 +0530 Subject: [PATCH v5 11/12] media: microchip-isc: smooth AWB gains with EMA filter Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20260527-microchip-isc-fixes-v5-11-b0ec1bb954be@microchip.com> References: <20260527-microchip-isc-fixes-v5-0-b0ec1bb954be@microchip.com> In-Reply-To: <20260527-microchip-isc-fixes-v5-0-b0ec1bb954be@microchip.com> To: Eugen Hristev , Mauro Carvalho Chehab , Hans Verkuil CC: Laurent Pinchart , Kieran Bingham , Sakari Ailus , Balamanikandan Gunasundar , , , , "Balakrishnan Sambath" X-Mailer: b4 0.14.3 Apply exponential moving average (alpha=3D0.25) to reduce per-frame flicker from sensor noise. Signed-off-by: Balakrishnan Sambath --- drivers/media/platform/microchip/microchip-isc-base.c | 19 +++++++++++++++= +--- drivers/media/platform/microchip/microchip-isc.h | 1 + 2 files changed, 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 a2719830d39b..d07ea2fa33c6 100644 --- a/drivers/media/platform/microchip/microchip-isc-base.c +++ b/drivers/media/platform/microchip/microchip-isc-base.c @@ -94,6 +94,7 @@ static inline void isc_reset_awb_ctrls(struct isc_device = *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 */ ctrls->gain[c] =3D 1 << 9; + ctrls->gain_smooth[c] =3D 1 << 9; /* offsets are in 2's complements */ ctrls->offset[c] =3D 0; } @@ -1477,11 +1478,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 45168c62e3bc..0ae9b4e8f32d 100644 --- a/drivers/media/platform/microchip/microchip-isc.h +++ b/drivers/media/platform/microchip/microchip-isc.h @@ -149,6 +149,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 Mon Jun 8 18:55:45 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 A10DB3F39EA; Wed, 27 May 2026 11:08:17 +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=1779880098; cv=none; b=PTd98bJXt7Xxlgr1HUL5Fcdh/VOth1dko4wfOKb7iPKEbqrW44tbiNmONhDfJrKP8bLq0hLMlXrS28SBumr6cZvGvvAguQJW5meY+FOEh1/5CBPav52KjWSR/lIIkcj2PdJIHaBkajf4tkJ8jyHIdnAuF2u/8IdgmzLfqRK3ylc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779880098; c=relaxed/simple; bh=ReiDdwkcSLe/Nn2wIdWLLJpIXqoldTX9ysS+Ik/I7zA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=HNByagAPiuiYq04/jRUo+ZXgevzhjG4HiGmQvFeDSnvXhCvXvze0fEK+Xebax/IeSzPzCt8GP7zvjlIQWw2RM0Yh/A7FRWBtTZW+gKuegiiGEqjXAeore1/9KsmTDFrPLI9kaoTFLeZ6qBjECLJI3aMjycSu1PvqNqzIVoafot8= 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=jh3KTMZk; 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="jh3KTMZk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1779880098; x=1811416098; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=ReiDdwkcSLe/Nn2wIdWLLJpIXqoldTX9ysS+Ik/I7zA=; b=jh3KTMZk3rLwTlk7IlxADdHm25NgZjHLSHV4YfP4O2SUw0FOT+p25alz aONPNZq3LKKCBjn4UoM40C20cY8JTBP/lve65h0u7D1IFk7/9dWL/Y8+G qtYB6oGnj4Uvyh2maYFxd0drFhAgEPzGo4d8b3qNGocbF/4qoMMUQ7TXg RwneBYPHEvnznjuVhM/w2absvCQ/e2sLLCbcJ17Y7uMumDA90EhFVd9CY YbEyibate0XUMcZ3lasdjjNoPa4fuXAlhg+Arxvupxx5jvhsKk0lD57Ma SosYog3sb8KmvCoG1pPFRTqLwb+qFZRDaH0PeiwuJBkShT8dOTZxO6G85 g==; X-CSE-ConnectionGUID: YtkCLYPYRH+rVljlFN//UA== X-CSE-MsgGUID: zq6Q3617RFqRIFdRKtuy8A== X-IronPort-AV: E=Sophos;i="6.24,171,1774335600"; d="scan'208";a="58112124" 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-AES256-GCM-SHA384; 27 May 2026 04:08: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.41; Wed, 27 May 2026 04:08:16 -0700 Received: from [127.0.0.1] (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; Wed, 27 May 2026 04:08:12 -0700 From: Balakrishnan Sambath Date: Wed, 27 May 2026 16:37:28 +0530 Subject: [PATCH v5 12/12] media: microchip-isc: scale DPC black level to sensor bit depth Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20260527-microchip-isc-fixes-v5-12-b0ec1bb954be@microchip.com> References: <20260527-microchip-isc-fixes-v5-0-b0ec1bb954be@microchip.com> In-Reply-To: <20260527-microchip-isc-fixes-v5-0-b0ec1bb954be@microchip.com> To: Eugen Hristev , Mauro Carvalho Chehab , Hans Verkuil CC: Laurent Pinchart , Kieran Bingham , Sakari Ailus , Balamanikandan Gunasundar , , , , "Balakrishnan Sambath" X-Mailer: b4 0.14.3 The DPC_BLCFG black level register expects counts in the sensor's native bit depth. The previous fixed 10-bit value (64 counts) under- corrects 12-bit sensors and over-corrects 8-bit ones, producing an incorrect black point. Scale the nominal 10-bit value to match the 8/10/12-bit sensor bus width derived from pfe_cfg0_bps. Co-developed-by: Balamanikandan Gunasundar Signed-off-by: Balamanikandan Gunasundar Signed-off-by: Balakrishnan Sambath --- .../media/platform/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 f51c7cac25df..067a6e1558d3 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