diff mbox series

[PATCH/RFC,v1,5/9] media: i2c: ar0144: Add image stream

Message ID 20240630141802.15830-6-laurent.pinchart@ideasonboard.com
State New
Headers show
Series [PATCH/RFC,v1,1/9] media: dt-bindings: media: i2c: Add AR0144 camera sensor | expand

Commit Message

Laurent Pinchart June 30, 2024, 2:17 p.m. UTC
In preparation for embedded data stream support, introduce a new
ar0144_stream_ids enumeration for stream IDs, with a single value,
AR0144_STREAM_IMAGE for the image data stream. Use it when accessing the
formats, crop and compose rectangles on the source pad. This is meant to
reduce the size of further commits, and doesn't introduce any functional
change.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/i2c/ar0144.c | 35 ++++++++++++++++++++++++-----------
 1 file changed, 24 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/drivers/media/i2c/ar0144.c b/drivers/media/i2c/ar0144.c
index 2d3ce05f85ac..edf793f2122e 100644
--- a/drivers/media/i2c/ar0144.c
+++ b/drivers/media/i2c/ar0144.c
@@ -340,6 +340,10 @@  enum ar0144_pad_ids {
 	AR0144_NUM_PADS,
 };
 
+enum ar0144_stream_ids {
+	AR0144_STREAM_IMAGE,
+};
+
 struct ar0144_model {
 	bool mono;
 };
@@ -526,7 +530,8 @@  static int ar0144_start_streaming(struct ar0144 *sensor,
 	int ret = 0;
 	u16 val;
 
-	format = v4l2_subdev_state_get_format(state, AR0144_PAD_SOURCE);
+	format = v4l2_subdev_state_get_format(state, AR0144_PAD_SOURCE,
+					      AR0144_STREAM_IMAGE);
 	crop = v4l2_subdev_state_get_crop(state, AR0144_PAD_IMAGE);
 	compose = v4l2_subdev_state_get_compose(state, AR0144_PAD_IMAGE);
 	info = ar0144_format_info(sensor, format->code, true);
@@ -873,7 +878,8 @@  static int ar0144_s_ctrl(struct v4l2_ctrl *ctrl)
 	 * configuration.
 	 */
 	state = v4l2_subdev_get_locked_active_state(&sensor->sd);
-	format = v4l2_subdev_state_get_format(state, AR0144_PAD_SOURCE);
+	format = v4l2_subdev_state_get_format(state, AR0144_PAD_SOURCE,
+					      AR0144_STREAM_IMAGE);
 	info = ar0144_format_info(sensor, format->code, true);
 	crop = v4l2_subdev_state_get_crop(state, AR0144_PAD_IMAGE);
 
@@ -1166,7 +1172,8 @@  static int ar0144_enum_frame_size(struct v4l2_subdev *sd,
 		if (!info)
 			return -EINVAL;
 
-		fmt = v4l2_subdev_state_get_format(state, AR0144_PAD_SOURCE);
+		fmt = v4l2_subdev_state_get_format(state, AR0144_PAD_SOURCE,
+						   AR0144_STREAM_IMAGE);
 		break;
 
 	default:
@@ -1193,15 +1200,17 @@  static int ar0144_set_fmt(struct v4l2_subdev *sd,
 	    format->which == V4L2_SUBDEV_FORMAT_ACTIVE)
 		return -EBUSY;
 
-	/* The format can only be set on the source pad. */
-	if (format->pad != AR0144_PAD_SOURCE)
+	/* The format can only be set for the image stream on the source pad. */
+	if (format->pad != AR0144_PAD_SOURCE ||
+	    format->stream != AR0144_STREAM_IMAGE)
 		return v4l2_subdev_get_fmt(sd, state, format);
 
 	/*
 	 * Only the media bus code can be updated on the source pad, dimensions
 	 * are set by the compose on the image pad rectangle.
 	 */
-	fmt = v4l2_subdev_state_get_format(state, AR0144_PAD_SOURCE);
+	fmt = v4l2_subdev_state_get_format(state, AR0144_PAD_SOURCE,
+					   AR0144_STREAM_IMAGE);
 	info = ar0144_format_info(sensor, format->format.code, true);
 	fmt->code = ar0144_format_code(sensor, info);
 
@@ -1325,7 +1334,8 @@  static int ar0144_set_selection(struct v4l2_subdev *sd,
 	}
 
 	/* Propagate the compose rectangle to the output format. */
-	fmt = v4l2_subdev_state_get_format(state, AR0144_PAD_SOURCE);
+	fmt = v4l2_subdev_state_get_format(state, AR0144_PAD_SOURCE,
+					   AR0144_STREAM_IMAGE);
 	fmt->width = compose->width;
 	fmt->height = compose->height;
 
@@ -1345,7 +1355,8 @@  static int ar0144_get_frame_desc(struct v4l2_subdev *sd, unsigned int pad,
 		return -EINVAL;
 
 	state = v4l2_subdev_lock_and_get_active_state(sd);
-	fmt = v4l2_subdev_state_get_format(state, AR0144_PAD_SOURCE);
+	fmt = v4l2_subdev_state_get_format(state, AR0144_PAD_SOURCE,
+					   AR0144_STREAM_IMAGE);
 	code = fmt->code;
 	v4l2_subdev_unlock_state(state);
 
@@ -1355,7 +1366,7 @@  static int ar0144_get_frame_desc(struct v4l2_subdev *sd, unsigned int pad,
 	fd->num_entries = 1;
 
 	fd->entry[0].pixelcode = code;
-	fd->entry[0].stream = 0;
+	fd->entry[0].stream = AR0144_STREAM_IMAGE;
 	fd->entry[0].bus.csi2.vc = 0;
 	fd->entry[0].bus.csi2.dt = info->dt;
 
@@ -1453,7 +1464,8 @@  static int ar0144_entity_init_state(struct v4l2_subdev *sd,
 
 	info = ar0144_format_info(sensor, 0, true);
 
-	fmt = v4l2_subdev_state_get_format(state, AR0144_PAD_SOURCE);
+	fmt = v4l2_subdev_state_get_format(state, AR0144_PAD_SOURCE,
+					   AR0144_STREAM_IMAGE);
 	fmt->width = AR0144_DEF_WIDTH;
 	fmt->height = AR0144_DEF_HEIGHT;
 	fmt->code = ar0144_format_code(sensor, info);
@@ -1530,7 +1542,8 @@  static int ar0144_init_subdev(struct ar0144 *sensor)
 	 * rate) and blanking controls.
 	 */
 	state = v4l2_subdev_lock_and_get_active_state(sd);
-	format = v4l2_subdev_state_get_format(state, AR0144_PAD_SOURCE);
+	format = v4l2_subdev_state_get_format(state, AR0144_PAD_SOURCE,
+					      AR0144_STREAM_IMAGE);
 	info = ar0144_format_info(sensor, format->code, true);
 
 	ar0144_update_link_freqs(sensor, info);