mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/5] media: qcom: camss, ccs: Sony IMX376 on SDM660 using the MIPI CCS driver
@ 2026-11-23 20:33 Gianluca Boiano
  2026-11-23 20:33 ` [PATCH 1/5] media: qcom: camss: Don't stream sub-devices upstream of the sensor Gianluca Boiano
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Gianluca Boiano @ 2026-11-23 20:33 UTC (permalink / raw)
  To: Bryan O'Donoghue, Vladimir Zapolskiy, Loic Poulain,
	Mauro Carvalho Chehab, Sakari Ailus, Hans Verkuil
  Cc: linux-media, linux-arm-msm, linux-kernel, phone-devel,
	David Heidelberg, Gianluca Boiano, stable

Hi,

These make the Sony IMX376 work with the mainline MIPI CCS driver behind
the Qualcomm CAMSS on SDM660. Nothing specific to the sensor is added to
the driver: the DT node uses "mipi-ccs-1.1", and the manufacturer specific
register settings come from CCS static data (sensors/sony,imx376.yaml,
https://github.com/M0Rf30/ccs-static-data/pull/1, to be submitted to
ccs-static-data).

Tested on a Xiaomi Mi A2 (SDM660, rear IMX376, 4 lanes, link frequencies
500 and 864 MHz):

  - 2592x1940 (2x2 binned), 36 fps at 500 MHz
  - 5184x3880, 29 fps at 864 MHz
  - switching between the two repeatedly
  - cropping the pixel array (4096x3000 binned to 2048x1500)
  - the front IMX376 and the IMX486, which use dedicated drivers, still
    stream

Patches:

1: CAMSS calls s_stream on every sub-device from the video node up to the
   sensor. For a sensor with several sub-devices (CCS has a pixel array, a
   binner and a scaler) that includes the pixel array, whose s_stream
   fails with -EINVAL as only the CSI-2 source pad can be enabled. Stop at
   the sub-device that is bound to CAMSS, as the other CSI-2 receiver
   drivers do (ipu3-cio2, rkisp1, ti-cal, ipu6, rcar-vin): that
   sub-device is responsible for starting what is upstream of it. This
   touches the loops that Qianhui Xu's "media: camss: video: factor
   pipeline stream on/off into a helper" also changes; I'm happy to
   rebase on top of it.

2: The link frequency and the pixel clock were looked up from the pixel
   array of a CCS sensor, whose pixel rate is not the one on the CSI-2
   bus. Use the sub-device bound to CAMSS instead.

3, 4: Two CCS bugs found while doing the above, both regressions from the
   switch to sub-device active state: the format set on a sink pad is not
   stored, and the format of a source pad does not follow the crop
   rectangle. Link validation fails with -EPIPE for anything but the
   native size.

5: CCS static data can carry manufacturer register blocks conditional on
   sensor register values (rules); the driver parses them but never
   writes them. Apply the matching blocks at stream start. The IMX376
   needs this for its full resolution mode, which uses different
   readout registers than the binned one.

The pipeline is configured the usual way, from the pixel array to the
source of the CSI-2 bus (here the scaler), setting the binning with the
compose rectangle of the binner and then the size of the sink pad of the
scaler:

  media-ctl -V '"ccs binner 2-001a":0[fmt:SRGGB12_1X12/5184x3880 compose:(0,0)/2592x1940]'
  media-ctl -V '"ccs scaler 2-001a":0[fmt:SRGGB12_1X12/2592x1940 crop:(0,0)/2592x1940 compose:(0,0)/2592x1940]'
  media-ctl -V '"ccs scaler 2-001a":1[fmt:SRGGB10_1X10/2592x1940]'

---
Gianluca Boiano (5):
      media: qcom: camss: Don't stream sub-devices upstream of the sensor
      media: qcom: camss: Look up link frequency from the sub-device on the CSI-2 link
      media: ccs: Store the format set on a sink pad
      media: ccs: Make the source pad format follow the crop rectangle
      media: ccs: Apply rule-based manufacturer register blocks at stream start

 drivers/media/i2c/ccs/ccs-core.c                | 106 +++++++++++++++++++++---
 drivers/media/platform/qcom/camss/camss-video.c |  28 +++++++
 drivers/media/platform/qcom/camss/camss.c       |   6 +-
 3 files changed, 129 insertions(+), 11 deletions(-)
---
base-commit: aa0f4c41d4870a18e65772a1817af16427200371
change-id: 20261122-b4-ccs-imx376-03da25278f5b

Best regards,
--  
Gianluca Boiano <morf3089@gmail.com>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/5] media: qcom: camss: Don't stream sub-devices upstream of the sensor
  2026-11-23 20:33 [PATCH 0/5] media: qcom: camss, ccs: Sony IMX376 on SDM660 using the MIPI CCS driver Gianluca Boiano
@ 2026-11-23 20:33 ` Gianluca Boiano
  2026-11-23 20:33 ` [PATCH 2/5] media: qcom: camss: Look up link frequency from the sub-device on the CSI-2 link Gianluca Boiano
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Gianluca Boiano @ 2026-11-23 20:33 UTC (permalink / raw)
  To: Bryan O'Donoghue, Vladimir Zapolskiy, Loic Poulain,
	Mauro Carvalho Chehab, Sakari Ailus, Hans Verkuil
  Cc: linux-media, linux-arm-msm, linux-kernel, phone-devel,
	David Heidelberg, Gianluca Boiano

video_start_streaming() and video_stop_streaming() walk the media
pipeline from the video node upstream and call s_stream on every
sub-device they find, including every sub-device behind the one that is
linked to the CSIPHY. That is fine for a sensor that is a single
sub-device, but a sensor that consists of several sub-devices gets
s_stream called on each of them, not just on the one that is linked to
the CSIPHY.

The MIPI CCS driver is such a sensor: it exposes a pixel array, a binner
and a scaler sub-device, and the scaler (or the binner when there is no
scaler) is the one linked to the CSIPHY. Streaming is started by that
sub-device and covers the whole sensor. Calling s_stream also on the
binner and on the pixel array is at best redundant and, as the CCS
enable_streams operation only accepts the sensor's source pad, makes the
pixel array fail with -EINVAL, so streaming cannot be started.

This is not specific to CCS. Other drivers that have a sensor on one end
of a pipeline, e.g. ipu3-cio2, rkisp1, ti-cal, ipu6 and rcar-vin, start
only the sub-device that is directly connected to them and leave
propagating the start request upstream to that sub-device.

Do the same in CAMSS: after the first sub-device that is not part of CAMSS
(i.e. the one that was bound by the async notifier, which is the one whose
host private data points to the CSIPHY), stop walking the pipeline.

Signed-off-by: Gianluca Boiano <morf3089@gmail.com>
---
 drivers/media/platform/qcom/camss/camss-video.c | 28 +++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/drivers/media/platform/qcom/camss/camss-video.c b/drivers/media/platform/qcom/camss/camss-video.c
index 0852eb6f1315..71ca16f15dab 100644
--- a/drivers/media/platform/qcom/camss/camss-video.c
+++ b/drivers/media/platform/qcom/camss/camss-video.c
@@ -249,6 +249,28 @@ static int video_prepare_streaming(struct vb2_queue *q)
 	return ret;
 }
 
+/*
+ * video_subdev_is_external - Check if a pipeline sub-device is not part of CAMSS
+ * @subdev: Sub-device in the pipeline
+ *
+ * camss_subdev_notifier_bound() sets the host private data of every external
+ * sub-device it binds, i.e. the one that is linked to a CSIPHY, to the CSIPHY.
+ * CAMSS sub-devices never have it set.
+ *
+ * Streaming is controlled from the video node, one CAMSS sub-device at a time.
+ * The external sub-device is the end of that chain: the pipeline upstream of it
+ * is not CAMSS' business, and the sub-device is responsible for starting and
+ * stopping whatever else it is made of. Sensors that consist of several
+ * sub-devices, such as MIPI CCS ones, are not expected to be controlled
+ * separately for each of them.
+ *
+ * Return true if @subdev is not a CAMSS sub-device.
+ */
+static bool video_subdev_is_external(struct v4l2_subdev *subdev)
+{
+	return v4l2_get_subdev_hostdata(subdev);
+}
+
 static int video_start_streaming(struct vb2_queue *q, unsigned int count)
 {
 	struct camss_video *video = vb2_get_drv_priv(q);
@@ -284,6 +306,9 @@ static int video_start_streaming(struct vb2_queue *q, unsigned int count)
 		ret = v4l2_subdev_call(subdev, video, s_stream, 1);
 		if (ret < 0 && ret != -ENOIOCTLCMD)
 			goto error;
+
+		if (video_subdev_is_external(subdev))
+			break;
 	}
 
 	return 0;
@@ -325,6 +350,9 @@ static void video_stop_streaming(struct vb2_queue *q)
 			dev_err(video->camss->dev, "Video pipeline stop failed: %d\n", ret);
 			return;
 		}
+
+		if (video_subdev_is_external(subdev))
+			break;
 	}
 
 	video_device_pipeline_stop(vdev);

-- 
2.56.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/5] media: qcom: camss: Look up link frequency from the sub-device on the CSI-2 link
  2026-11-23 20:33 [PATCH 0/5] media: qcom: camss, ccs: Sony IMX376 on SDM660 using the MIPI CCS driver Gianluca Boiano
  2026-11-23 20:33 ` [PATCH 1/5] media: qcom: camss: Don't stream sub-devices upstream of the sensor Gianluca Boiano
@ 2026-11-23 20:33 ` Gianluca Boiano
  2026-11-23 20:33 ` [PATCH 3/5] media: ccs: Store the format set on a sink pad Gianluca Boiano
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Gianluca Boiano @ 2026-11-23 20:33 UTC (permalink / raw)
  To: Bryan O'Donoghue, Vladimir Zapolskiy, Loic Poulain,
	Mauro Carvalho Chehab, Sakari Ailus, Hans Verkuil
  Cc: linux-media, linux-arm-msm, linux-kernel, phone-devel,
	David Heidelberg, Gianluca Boiano

camss_find_sensor_pad() returns the pad of the first sub-device found
upstream of the CSIPHY that has the MEDIA_ENT_F_CAM_SENSOR function. This
is the pixel array for a sensor that consists of several sub-devices, such
as a MIPI CCS one, and the link frequency and the pixel rate are then
looked up from the controls of the pixel array.

The pixel array does not have a link frequency control, and the pixel rate
it has is the rate at which pixels are read out from the array, not the
one on the CSI-2 bus. The link frequency used for the CSIPHY clock and
the settle count and the pixel clock used for the VFE clock rate are then
derived from the wrong rate. On Sony IMX376 that is 800 MHz instead of
400 MHz at a 500 MHz link frequency, and the kernel warns:

  v4l2_get_link_freq_ctrl: Link frequency estimated using pixel rate:
  result might be inaccurate

The controls describing the CSI-2 bus (V4L2_CID_LINK_FREQ and the CSI-2
V4L2_CID_PIXEL_RATE) are those of the sub-device that transmits on the
bus, i.e. the one that CAMSS has bound. Return the pad of that sub-device
instead, as the other CSI-2 receiver drivers do.

For a sensor consisting of a single sub-device the result is the same.

Signed-off-by: Gianluca Boiano <morf3089@gmail.com>
---
 drivers/media/platform/qcom/camss/camss.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/qcom/camss/camss.c b/drivers/media/platform/qcom/camss/camss.c
index c54185c93a8a..cf86bf04dfe7 100644
--- a/drivers/media/platform/qcom/camss/camss.c
+++ b/drivers/media/platform/qcom/camss/camss.c
@@ -4513,6 +4513,10 @@ void camss_disable_clocks(int nclocks, struct camss_clock *clock)
  * camss_find_sensor_pad - Find the media pad via which the sensor is linked
  * @entity: Media entity to start searching from
  *
+ * The sensor pad is the source pad of the sub-device bound to CAMSS, i.e. the
+ * one that transmits on the CSI-2 bus. For a sensor made of several sub-devices
+ * this is not necessarily the pad of the pixel array.
+ *
  * Return a pointer to sensor media pad or NULL if not found
  */
 struct media_pad *camss_find_sensor_pad(struct media_entity *entity)
@@ -4530,7 +4534,7 @@ struct media_pad *camss_find_sensor_pad(struct media_entity *entity)
 
 		entity = pad->entity;
 
-		if (entity->function == MEDIA_ENT_F_CAM_SENSOR)
+		if (v4l2_get_subdev_hostdata(media_entity_to_v4l2_subdev(entity)))
 			return pad;
 	}
 }

-- 
2.56.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 3/5] media: ccs: Store the format set on a sink pad
  2026-11-23 20:33 [PATCH 0/5] media: qcom: camss, ccs: Sony IMX376 on SDM660 using the MIPI CCS driver Gianluca Boiano
  2026-11-23 20:33 ` [PATCH 1/5] media: qcom: camss: Don't stream sub-devices upstream of the sensor Gianluca Boiano
  2026-11-23 20:33 ` [PATCH 2/5] media: qcom: camss: Look up link frequency from the sub-device on the CSI-2 link Gianluca Boiano
@ 2026-11-23 20:33 ` Gianluca Boiano
  2026-11-23 20:33 ` [PATCH 4/5] media: ccs: Make the source pad format follow the crop rectangle Gianluca Boiano
  2026-11-23 20:33 ` [PATCH 5/5] media: ccs: Apply rule-based manufacturer register blocks at stream start Gianluca Boiano
  4 siblings, 0 replies; 6+ messages in thread
From: Gianluca Boiano @ 2026-11-23 20:33 UTC (permalink / raw)
  To: Bryan O'Donoghue, Vladimir Zapolskiy, Loic Poulain,
	Mauro Carvalho Chehab, Sakari Ailus, Hans Verkuil
  Cc: linux-media, linux-arm-msm, linux-kernel, phone-devel,
	David Heidelberg, stable, Gianluca Boiano

Setting the format on the sink pad of the binner or the scaler only
updated the crop and compose rectangles of the sub-device and its source
pad, the format itself was never stored in the sub-device state. Reading
the format back returned the one set up by ccs_init_state(), i.e. the
size of the pixel array, and the selection rectangles, which depend on
the size of the sink pad format, were bounded by it.

Link validation then fails with -EPIPE for any readout mode that does not
output the full pixel array: the scaler's sink pad format is the pixel
array size whereas the binner's source pad format is the binned size, and
there is no way to make the two match from user space since setting the
sink format has no effect.

Before the sub-device active state was used, the active sink format was
stored in struct ccs_subdev (sink_fmt) in ccs_set_format(). The switch to
the sub-device state dropped storing it. Store it in the state again.

Fixes: d8bca3ed1d70 ("media: ccs: Use sub-device active state")
Cc: stable@vger.kernel.org
Signed-off-by: Gianluca Boiano <morf3089@gmail.com>
---
 drivers/media/i2c/ccs/ccs-core.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/media/i2c/ccs/ccs-core.c b/drivers/media/i2c/ccs/ccs-core.c
index 1cc4350856fd..a4af27de5453 100644
--- a/drivers/media/i2c/ccs/ccs-core.c
+++ b/drivers/media/i2c/ccs/ccs-core.c
@@ -2275,6 +2275,9 @@ static int ccs_set_format(struct v4l2_subdev *subdev,
 		      CCS_LIM(sensor, MIN_Y_OUTPUT_SIZE),
 		      CCS_LIM(sensor, MAX_Y_OUTPUT_SIZE));
 
+	*v4l2_subdev_state_get_format(sd_state, ssd->sink_pad,
+				      CCS_STREAM_PIXEL) = fmt->format;
+
 	crop = v4l2_subdev_state_get_crop(sd_state, ssd->sink_pad,
 					  CCS_STREAM_PIXEL);
 

-- 
2.56.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 4/5] media: ccs: Make the source pad format follow the crop rectangle
  2026-11-23 20:33 [PATCH 0/5] media: qcom: camss, ccs: Sony IMX376 on SDM660 using the MIPI CCS driver Gianluca Boiano
                   ` (2 preceding siblings ...)
  2026-11-23 20:33 ` [PATCH 3/5] media: ccs: Store the format set on a sink pad Gianluca Boiano
@ 2026-11-23 20:33 ` Gianluca Boiano
  2026-11-23 20:33 ` [PATCH 5/5] media: ccs: Apply rule-based manufacturer register blocks at stream start Gianluca Boiano
  4 siblings, 0 replies; 6+ messages in thread
From: Gianluca Boiano @ 2026-11-23 20:33 UTC (permalink / raw)
  To: Bryan O'Donoghue, Vladimir Zapolskiy, Loic Poulain,
	Mauro Carvalho Chehab, Sakari Ailus, Hans Verkuil
  Cc: linux-media, linux-arm-msm, linux-kernel, phone-devel,
	David Heidelberg, stable, Gianluca Boiano

The size of the format on the source pad of the pixel array, and on the
source pad of the sub-device that is the source of the CSI-2 bus, is that
of the crop rectangle on the same pad: the analogue crop of the pixel
array and the digital crop at the end of the pipeline, respectively. The
format was only initialised from the pixel array size or the compose
rectangle and never updated when the crop was set, so after setting such a
crop the format did not match what the sensor outputs.

As the format of a source pad can not be set from user space, and the
format of the sink pad it is linked to has to match it, link validation
fails with -EPIPE for any crop other than the full area.

Update the size of the format when the crop is set. As the size of the
pixel array format is then no longer its native size, use the native size
as the bounds for its crop.

Fixes: d8bca3ed1d70 ("media: ccs: Use sub-device active state")
Cc: stable@vger.kernel.org
Signed-off-by: Gianluca Boiano <morf3089@gmail.com>
---
 drivers/media/i2c/ccs/ccs-core.c | 31 +++++++++++++++++++++----------
 1 file changed, 21 insertions(+), 10 deletions(-)

diff --git a/drivers/media/i2c/ccs/ccs-core.c b/drivers/media/i2c/ccs/ccs-core.c
index a4af27de5453..acea07d906f3 100644
--- a/drivers/media/i2c/ccs/ccs-core.c
+++ b/drivers/media/i2c/ccs/ccs-core.c
@@ -2541,6 +2541,14 @@ static int ccs_sel_supported(struct v4l2_subdev *subdev,
 	}
 }
 
+static void ccs_get_native_size(struct ccs_subdev *ssd, struct v4l2_rect *r)
+{
+	r->top = 0;
+	r->left = 0;
+	r->width = CCS_LIM(ssd->sensor, X_ADDR_MAX) + 1;
+	r->height = CCS_LIM(ssd->sensor, Y_ADDR_MAX) + 1;
+}
+
 static int ccs_set_crop(struct v4l2_subdev *subdev,
 			const struct v4l2_subdev_client_info *ci,
 			struct v4l2_subdev_state *sd_state,
@@ -2556,7 +2564,9 @@ static int ccs_set_crop(struct v4l2_subdev *subdev,
 	comp = v4l2_subdev_state_get_compose(sd_state, ssd->sink_pad,
 					     CCS_STREAM_PIXEL);
 
-	if (sel->pad == ssd->sink_pad) {
+	if (ssd == sensor->pixel_array) {
+		ccs_get_native_size(ssd, &src_size);
+	} else if (sel->pad == ssd->sink_pad) {
 		struct v4l2_mbus_framefmt *mfmt =
 			v4l2_subdev_state_get_format(sd_state, sel->pad);
 
@@ -2579,20 +2589,21 @@ static int ccs_set_crop(struct v4l2_subdev *subdev,
 
 	*crop = sel->r;
 
-	if (ssd != sensor->pixel_array && sel->pad == CCS_PAD_SINK)
+	if (sel->pad == ssd->source_pad) {
+		struct v4l2_mbus_framefmt *fmt =
+			v4l2_subdev_state_get_format(sd_state, sel->pad,
+						     CCS_STREAM_PIXEL);
+
+		/* The size of the source pad format is that of the crop. */
+		fmt->width = crop->width;
+		fmt->height = crop->height;
+	} else {
 		ccs_propagate(subdev, sd_state, V4L2_SEL_TGT_CROP);
+	}
 
 	return 0;
 }
 
-static void ccs_get_native_size(struct ccs_subdev *ssd, struct v4l2_rect *r)
-{
-	r->top = 0;
-	r->left = 0;
-	r->width = CCS_LIM(ssd->sensor, X_ADDR_MAX) + 1;
-	r->height = CCS_LIM(ssd->sensor, Y_ADDR_MAX) + 1;
-}
-
 static int ccs_get_selection(struct v4l2_subdev *subdev,
 			     const struct v4l2_subdev_client_info *ci,
 			     struct v4l2_subdev_state *sd_state,

-- 
2.56.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 5/5] media: ccs: Apply rule-based manufacturer register blocks at stream start
  2026-11-23 20:33 [PATCH 0/5] media: qcom: camss, ccs: Sony IMX376 on SDM660 using the MIPI CCS driver Gianluca Boiano
                   ` (3 preceding siblings ...)
  2026-11-23 20:33 ` [PATCH 4/5] media: ccs: Make the source pad format follow the crop rectangle Gianluca Boiano
@ 2026-11-23 20:33 ` Gianluca Boiano
  4 siblings, 0 replies; 6+ messages in thread
From: Gianluca Boiano @ 2026-11-23 20:33 UTC (permalink / raw)
  To: Bryan O'Donoghue, Vladimir Zapolskiy, Loic Poulain,
	Mauro Carvalho Chehab, Sakari Ailus, Hans Verkuil
  Cc: linux-media, linux-arm-msm, linux-kernel, phone-devel,
	David Heidelberg, Gianluca Boiano

The static data rule based blocks were parsed but never used. Before
streaming, write the base manufacturer register set again (undoing any
earlier rule) and then the manufacturer registers of each sensor and
module rule whose if-rules all match the current register values, e.g.
binning_mode, which is already written at that point. This lets one
static file carry settings that depend on the readout mode.

Tested on a Xiaomi Mi A2 (Sony IMX376) with a static file whose base set
is the 2x2 binned mode and whose rule on binning_mode 0 holds the full
resolution deltas: both 2592x1940 and 5184x3880 stream correctly from the
same file. Without the rule application full resolution output is corrupt.

Signed-off-by: Gianluca Boiano <morf3089@gmail.com>
---
 drivers/media/i2c/ccs/ccs-core.c | 72 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 72 insertions(+)

diff --git a/drivers/media/i2c/ccs/ccs-core.c b/drivers/media/i2c/ccs/ccs-core.c
index acea07d906f3..db98590c1ed6 100644
--- a/drivers/media/i2c/ccs/ccs-core.c
+++ b/drivers/media/i2c/ccs/ccs-core.c
@@ -1620,6 +1620,72 @@ static int ccs_write_msr_regs(struct ccs_sensor *sensor)
 				   sensor->mdata.num_module_manufacturer_regs);
 }
 
+static int ccs_rule_matches(struct ccs_sensor *sensor,
+			    const struct ccs_rule *rule)
+{
+	for (unsigned int i = 0; i < rule->num_if_rules; i++) {
+		const struct ccs_if_rule *if_rule = &rule->if_rules[i];
+		u32 val;
+		int rval;
+
+		rval = ccs_read_addr_8only(sensor, CCI_REG8(if_rule->addr),
+					   &val);
+		if (rval)
+			return rval;
+
+		if ((val & if_rule->mask) != (if_rule->value & if_rule->mask))
+			return 0;
+	}
+
+	return 1;
+}
+
+static int ccs_apply_rule_list(struct ccs_sensor *sensor,
+			       const struct ccs_rule *rules, size_t num_rules)
+{
+	for (unsigned int i = 0; i < num_rules; i++) {
+		int rval = ccs_rule_matches(sensor, &rules[i]);
+
+		if (rval < 0)
+			return rval;
+		if (!rval)
+			continue;
+
+		rval = ccs_write_data_regs(sensor, rules[i].manufacturer_regs,
+					   rules[i].num_manufacturer_regs);
+		if (rval)
+			return rval;
+	}
+
+	return 0;
+}
+
+/*
+ * Apply the manufacturer-specific registers of the matching rule based
+ * blocks. The conditions refer to registers that are already set for this
+ * stream (e.g. binning_mode). The base set is written first, undoing what a
+ * previous stream's rules may have left in the sensor.
+ */
+static int ccs_apply_rules(struct ccs_sensor *sensor)
+{
+	int rval;
+
+	if (!sensor->sdata.num_sensor_rules && !sensor->mdata.num_module_rules)
+		return 0;
+
+	rval = ccs_write_msr_regs(sensor);
+	if (rval)
+		return rval;
+
+	rval = ccs_apply_rule_list(sensor, sensor->sdata.sensor_rules,
+				   sensor->sdata.num_sensor_rules);
+	if (rval)
+		return rval;
+
+	return ccs_apply_rule_list(sensor, sensor->mdata.module_rules,
+				   sensor->mdata.num_module_rules);
+}
+
 static int ccs_update_phy_ctrl(struct ccs_sensor *sensor)
 {
 	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
@@ -1993,6 +2059,12 @@ static int ccs_enable_streams(struct v4l2_subdev *subdev,
 			goto err_pm_put;
 	}
 
+	rval = ccs_apply_rules(sensor);
+	if (rval) {
+		dev_err(&client->dev, "applying rules failed (%d)\n", rval);
+		goto err_pm_put;
+	}
+
 	rval = ccs_call_quirk(sensor, pre_streamon);
 	if (rval) {
 		dev_err(&client->dev, "pre_streamon quirks failed\n");

-- 
2.56.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-11-23 20:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-23 20:33 [PATCH 0/5] media: qcom: camss, ccs: Sony IMX376 on SDM660 using the MIPI CCS driver Gianluca Boiano
2026-11-23 20:33 ` [PATCH 1/5] media: qcom: camss: Don't stream sub-devices upstream of the sensor Gianluca Boiano
2026-11-23 20:33 ` [PATCH 2/5] media: qcom: camss: Look up link frequency from the sub-device on the CSI-2 link Gianluca Boiano
2026-11-23 20:33 ` [PATCH 3/5] media: ccs: Store the format set on a sink pad Gianluca Boiano
2026-11-23 20:33 ` [PATCH 4/5] media: ccs: Make the source pad format follow the crop rectangle Gianluca Boiano
2026-11-23 20:33 ` [PATCH 5/5] media: ccs: Apply rule-based manufacturer register blocks at stream start Gianluca Boiano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®