From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=68.232.153.233 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796195788; b=aPcGAvTanzkxdqSZm5ShbVBn/JS+pwlA4OR5qSrnHBHAekLtre0e0rJWKZiSol9HYBLT JEO2HV9SIJd0Fl8ojzcyQJpm7vAcd0b1BXGzTTY6Ib8lRMXu6JcV2MgS9klZZZ2fxYJcY krISLa2Mc4lirm3FbxzjwEItRy21vMfKZxzZ1Y77SDAvccmPD7C7DxNB+nHX6ywd+f3AD HwBfCpCFndh4m0j9yyi3G3MYzaiaOETW7G8Yyl2Y9t83mi38omjgfgjoikEhCQ7WYeReR XDmJY6FNbcg9aQbExK19Sykp58Bj7nU/X463fR9omI5ynanrumZsAxc+zLukidhKNnA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796195788; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-Amp-Result:Received:Received:Received:From:Date: Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-ID:References:In-Reply-To:To:CC:X-Mailer; bh=pN3iahsMVfMMWvKUVnbVvivRtvS/9FmkPcqznRl3SSM=; b=E8/CN5omOcodR/IjvkhpVDwaJnckfaDUcfOSEaXP3NXbqvq7RgKVD75XgXHnDnIsFYGW a5/4iwQ+BZ1BIRCXLmFxe54521vpaPPCYZLu4EOIaJcVTqmUuRhmdKnv/h8F92gnO5cQq GorZ6VV0CymdVkwtHPjaO7XPZh81ceEZQzw99G8ltiaSu0sczhAuhtHaBrjPR41GwQ7Ss YywI41SWgm2NxiKyJZ8QuszHBX+twwd++KnGgeqZIlISgjBvZORYiXcBEoaFtSOFBCSlQ v072BGXBUWuCjTuehWHGEdhhfYrvQjyszf28S0KMEaYUjiodNTBVXL8yup4dNr5e/pw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass header.d=microchip.com header.i=@microchip.com header.a=rsa-sha256 header.s=mchp header.b=0iO6IuMI; arc=none smtp.remote-ip=68.232.153.233 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF0BD606A683 for ; Wed, 2 Dec 2026 07:16:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AF0BD606A683 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=microchip.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.a=rsa-sha256 header.s=mchp header.b=0iO6IuMI DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1796195787; x=1827731787; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=uEITgV/nTKD7HTjkHeyp/qj+uT/xe5C2CDADuYy2HZE=; b=0iO6IuMI4RbOXtEzsp3N0b/wBA+XDzdt1wm2IAwO+BfOFFfF0GXZtcM0 NOdGCDeK5tF4AbF2yK7waZ6tT9lLhE3DRCWolyM5xm0KjPlhPb5Phttfc j3wrhQA7vMMgP4XHx61opyKsbQj7n2mQzAu5gK6cOwqP8dTYaVRgXt94G WR88lNpib0Q0+L/XN4XL35s38tEMfiXhFjn0tFBrY/fHRa6u7WoL3XWds KoRUacywVYK9XlNFepSXiFlstRgwFmdU5UEGq43KAltCAQaHvCzj2Vz44 aL65XaeBZ2Cqg3CIG6h7qHw2fNyh7wZWlwLCDLgoZ6hHYz5vO7KjuV6eO A==; X-CSE-ConnectionGUID: LfsAYCiPRBG7Np/Ns5pA+g== X-CSE-MsgGUID: gftuHx6GTxOwedKAvIPITQ== X-IronPort-AV: E=Sophos;i="6.27,246,1787036400"; d="scan'208";a="67334009" 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; 02 Dec 2026 00:16:27 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.87.71) 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.57; Wed, 2 Dec 2026 00:16:26 -0700 Received: from [127.0.0.1] (10.10.85.11) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2507.58 via Frontend Transport; Wed, 2 Dec 2026 00:16:25 -0700 From: Balakrishnan Sambath Date: Wed, 2 Dec 2026 12:46:14 +0530 Subject: [PATCH 08/15] media: microchip-isc: add SAMA7G5 hue and saturation controls X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-ID: <20261202-isc-series-v1-v1-8-4e2f17c0271c@microchip.com> References: <20261202-isc-series-v1-v1-0-4e2f17c0271c@microchip.com> In-Reply-To: <20261202-isc-series-v1-v1-0-4e2f17c0271c@microchip.com> To: CC: , Balamanikandan Gunasundar , Balakrishnan Sambath X-Mailer: b4 0.14.3 The SAMA7G5 CBHS stage adds hue (ISC_CBHS_HUE, 9 bits, 0 to 359 degrees) and saturation (ISC_CBHS_SAT, unsigned 8.4, 16 is unity). Add V4L2_CID_HUE and V4L2_CID_SATURATION when has_cbhs is set, and program them from isc_sama7g5_config_cbc() instead of the neutral 0 and 16. Negative hue is wrapped to 0 to 359 before it is written. The register is unsigned, so writing -30 directly would program 482 degrees. On SAMA7G5 only, mark the CBC controls inactive when the pipeline has no CBC_ENABLE stage, and hue and saturation also when the output format carries no chroma. Other variants keep their controls always active. The flags follow the pipeline validated at stream start, so all four stay active until the first start. Co-developed-by: Balamanikandan Gunasundar Signed-off-by: Balamanikandan Gunasundar Signed-off-by: Balakrishnan Sambath --- .../media/platform/microchip/microchip-isc-base.c | 60 ++++++++++++++++++++-- .../media/platform/microchip/microchip-isc-regs.h | 15 ++++-- drivers/media/platform/microchip/microchip-isc.h | 12 +++++ .../platform/microchip/microchip-sama5d2-isc.c | 3 +- .../platform/microchip/microchip-sama7g5-isc.c | 9 ++-- 5 files changed, 85 insertions(+), 14 deletions(-) diff --git a/drivers/media/platform/microchip/microchip-isc-base.c b/drivers/media/platform/microchip/microchip-isc-base.c index 86f0eb86b76d..3e18933230b8 100644 --- a/drivers/media/platform/microchip/microchip-isc-base.c +++ b/drivers/media/platform/microchip/microchip-isc-base.c @@ -869,6 +869,39 @@ static int isc_try_configure_pipeline(struct isc_device *isc) return 0; } +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; + } +} + +/* Hue and saturation need chroma, so they stay inactive for RGB output */ +static void isc_update_cbc_ctrl_activity(struct isc_device *isc) +{ + bool cbc_active = isc->config.bits_pipeline & CBC_ENABLE; + bool chroma_active = cbc_active && isc_format_has_chroma(isc->config.fourcc); + + /* Controls of the other ISC variants stay always active */ + if (!isc->has_cbhs) + return; + + /* Activation sends events, which walk the subscriber list */ + v4l2_ctrl_lock(isc->brightness_ctrl); + v4l2_ctrl_activate(isc->brightness_ctrl, cbc_active); + v4l2_ctrl_activate(isc->contrast_ctrl, cbc_active); + v4l2_ctrl_activate(isc->hue_ctrl, chroma_active); + v4l2_ctrl_activate(isc->sat_ctrl, chroma_active); + v4l2_ctrl_unlock(isc->brightness_ctrl); +} + static int isc_try_fmt(struct isc_device *isc, struct v4l2_format *f) { struct v4l2_pix_format *pixfmt = &f->fmt.pix; @@ -999,6 +1032,7 @@ static int isc_link_validate(struct media_link *link) return ret; isc->config = isc->try_config; + isc_update_cbc_ctrl_activity(isc); dev_dbg(isc->dev, "New ISC configuration in place\n"); @@ -1457,9 +1491,7 @@ static int isc_s_ctrl(struct v4l2_ctrl *ctrl) struct isc_device, ctrls.handler); struct isc_ctrls *ctrls = &isc->ctrls; - if (ctrl->flags & V4L2_CTRL_FLAG_INACTIVE) - return 0; - + /* Keep values set while inactive, they are programmed on activation */ switch (ctrl->id) { case V4L2_CID_BRIGHTNESS: ctrls->brightness = ctrl->val & ISC_CBC_BRIGHT_MASK; @@ -1467,6 +1499,15 @@ static int isc_s_ctrl(struct v4l2_ctrl *ctrl) case V4L2_CID_CONTRAST: ctrls->contrast = ctrl->val & ISC_CBC_CONTRAST_MASK; break; + case V4L2_CID_HUE: + if (isc->has_cbhs) + ctrls->hue = (ctrl->val + 360) % 360; + break; + case V4L2_CID_SATURATION: + /* Q4 fixed-point written straight to the register */ + if (isc->has_cbhs) + ctrls->saturation = ctrl->val & ISC_CBHS_SAT_MASK; + break; case V4L2_CID_GAMMA: ctrls->gamma_index = ctrl->val; break; @@ -1653,8 +1694,17 @@ static int isc_ctrl_init(struct isc_device *isc) isc->config_ctrls(isc, ops); ctrls->brightness = 0; - - v4l2_ctrl_new_std(hdl, ops, V4L2_CID_BRIGHTNESS, -1024, 1023, 1, 0); + ctrls->saturation = 16; + + isc->brightness_ctrl = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_BRIGHTNESS, + -1024, 1023, 1, 0); + if (isc->has_cbhs) { + isc->hue_ctrl = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_HUE, + -180, 180, 1, 0); + isc->sat_ctrl = v4l2_ctrl_new_std(hdl, ops, + V4L2_CID_SATURATION, + 0, 4095, 1, 16); + } v4l2_ctrl_new_std(hdl, ops, V4L2_CID_GAMMA, 0, isc->gamma_max, 1, isc->gamma_def); isc->awb_ctrl = v4l2_ctrl_new_std(hdl, &isc_awb_ops, diff --git a/drivers/media/platform/microchip/microchip-isc-regs.h b/drivers/media/platform/microchip/microchip-isc-regs.h index f9bc76c6f35d..daf01afd440c 100644 --- a/drivers/media/platform/microchip/microchip-isc-regs.h +++ b/drivers/media/platform/microchip/microchip-isc-regs.h @@ -274,10 +274,17 @@ #define ISC_CBC_CONTRAST 0x000003c0 #define ISC_CBC_CONTRAST_MASK GENMASK(11, 0) -/* Hue Register */ -#define ISC_CBHS_HUE 0x4e0 -/* Saturation Register */ -#define ISC_CBHS_SAT 0x4e4 +/* + * XISC CBHS block. CBC brightness and contrast reach it through + * ISC_SAMA7G5_CBC_OFFSET. HUE and SAT are absolute, no offset. + */ + +/* Hue is unsigned 9-bit, 0 to 359 degrees */ +#define ISC_CBHS_HUE 0x4e0 + +/* Saturation is unsigned 8.4 fixed-point, 16 is unity gain */ +#define ISC_CBHS_SAT 0x4e4 +#define ISC_CBHS_SAT_MASK GENMASK(11, 0) /* 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/media/platform/microchip/microchip-isc.h index 31d9cf84b318..ccb566e5e627 100644 --- a/drivers/media/platform/microchip/microchip-isc.h +++ b/drivers/media/platform/microchip/microchip-isc.h @@ -141,6 +141,8 @@ struct isc_ctrls { u32 brightness; u32 contrast; + u32 hue; + u32 saturation; u8 gamma_index; #define ISC_WB_NONE 0 #define ISC_WB_AUTO 1 @@ -226,6 +228,11 @@ enum isc_scaler_pads { * * @ctrls: holds information about ISC controls * @do_wb_ctrl: control regarding the DO_WHITE_BALANCE button + * @has_cbhs: the CBC stage also has hue and saturation + * @brightness_ctrl: brightness control + * @contrast_ctrl: contrast control + * @hue_ctrl: hue control, only if @has_cbhs + * @sat_ctrl: saturation control, only if @has_cbhs * @awb_work: workqueue reference for autowhitebalance histogram * analysis * @@ -347,6 +354,11 @@ struct isc_device { const u32 (*gamma_table)[GAMMA_ENTRIES]; u32 gamma_max; u32 gamma_def; + bool has_cbhs; + struct v4l2_ctrl *brightness_ctrl; + struct v4l2_ctrl *contrast_ctrl; + struct v4l2_ctrl *hue_ctrl; + struct v4l2_ctrl *sat_ctrl; u32 max_width; u32 max_height; diff --git a/drivers/media/platform/microchip/microchip-sama5d2-isc.c b/drivers/media/platform/microchip/microchip-sama5d2-isc.c index a93f95434270..ef2a0e6d7167 100644 --- a/drivers/media/platform/microchip/microchip-sama5d2-isc.c +++ b/drivers/media/platform/microchip/microchip-sama5d2-isc.c @@ -265,7 +265,8 @@ static void isc_sama5d2_config_ctrls(struct isc_device *isc, ctrls->contrast = 256; - v4l2_ctrl_new_std(hdl, ops, V4L2_CID_CONTRAST, -2048, 2047, 1, 256); + isc->contrast_ctrl = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_CONTRAST, + -2048, 2047, 1, 256); } static void isc_sama5d2_config_dpc(struct isc_device *isc) diff --git a/drivers/media/platform/microchip/microchip-sama7g5-isc.c b/drivers/media/platform/microchip/microchip-sama7g5-isc.c index f182e19a5519..aec88775d09d 100644 --- a/drivers/media/platform/microchip/microchip-sama7g5-isc.c +++ b/drivers/media/platform/microchip/microchip-sama7g5-isc.c @@ -267,9 +267,8 @@ static void isc_sama7g5_config_cbc(struct isc_device *isc) /* Configure what is set via v4l2 ctrls */ regmap_write(regmap, ISC_CBC_BRIGHT + isc->offsets.cbc, isc->ctrls.brightness); regmap_write(regmap, ISC_CBC_CONTRAST + isc->offsets.cbc, isc->ctrls.contrast); - /* Configure Hue and Saturation as neutral midpoint */ - regmap_write(regmap, ISC_CBHS_HUE, 0); - regmap_write(regmap, ISC_CBHS_SAT, (1 << 4)); + regmap_write(regmap, ISC_CBHS_HUE, isc->ctrls.hue); + regmap_write(regmap, ISC_CBHS_SAT, isc->ctrls.saturation); } static void isc_sama7g5_config_cc(struct isc_device *isc) @@ -293,7 +292,8 @@ static void isc_sama7g5_config_ctrls(struct isc_device *isc, ctrls->contrast = 16; - v4l2_ctrl_new_std(hdl, ops, V4L2_CID_CONTRAST, -2048, 2047, 1, 16); + isc->contrast_ctrl = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_CONTRAST, + -2048, 2047, 1, 16); } static void isc_sama7g5_config_dpc(struct isc_device *isc) @@ -510,6 +510,7 @@ static int microchip_xisc_probe(struct platform_device *pdev) isc->gamma_table = isc_sama7g5_gamma_table; isc->gamma_max = 2; isc->gamma_def = 0; + isc->has_cbhs = true; data = of_device_get_match_data(dev); if (!data) -- 2.34.1