[PATCH 08/15] media: microchip-isc: add SAMA7G5 hue and saturation controls

From: Balakrishnan Sambath

Date: Wed Dec 02 2026 - 02:16:42 EST


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 <balamanikandan.gunasundar@xxxxxxxxxxxxx>
Signed-off-by: Balamanikandan Gunasundar <balamanikandan.gunasundar@xxxxxxxxxxxxx>
Signed-off-by: Balakrishnan Sambath <balakrishnan.s@xxxxxxxxxxxxx>
---
.../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