[PATCH v3 18/31] media: synopsys: csi2: Remove deprecated s_stream and use v4l2_subdev_pad_ops

Frank Li posted 31 patches 1 month, 1 week ago
[PATCH v3 18/31] media: synopsys: csi2: Remove deprecated s_stream and use v4l2_subdev_pad_ops
Posted by Frank Li 1 month, 1 week ago
Use new v4l2_subdev_pad_ops.enable_streams(disalbe_stream) replace
deprecated s_stream interface.

Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
 drivers/media/platform/synopsys/mipi-csi2.c | 52 +++++++++++++++++------------
 1 file changed, 31 insertions(+), 21 deletions(-)

diff --git a/drivers/media/platform/synopsys/mipi-csi2.c b/drivers/media/platform/synopsys/mipi-csi2.c
index 22e0021fab17f3c8e9a6c41c2f2109f5112dd6e5..922b59670383db7c920625f8a149009fa4dc5f22 100644
--- a/drivers/media/platform/synopsys/mipi-csi2.c
+++ b/drivers/media/platform/synopsys/mipi-csi2.c
@@ -342,7 +342,9 @@ static void csi2_stop(struct dw_mipi_csi2_dev *csi2)
  * V4L2 subdev operations.
  */
 
-static int csi2_s_stream(struct v4l2_subdev *sd, int enable)
+static int dw_csi2_enable_streams(struct v4l2_subdev *sd,
+				  struct v4l2_subdev_state *state, u32 pad,
+				  u64 streams_mask)
 {
 	struct dw_mipi_csi2_dev *csi2 = sd_to_dev(sd);
 	int i, ret = 0;
@@ -359,28 +361,39 @@ static int csi2_s_stream(struct v4l2_subdev *sd, int enable)
 	if (i >= csi2->num_sink_pads)
 		return -EPIPE;
 
-	/*
-	 * enable/disable streaming only if stream_count is
-	 * going from 0 to 1 / 1 to 0.
-	 */
-	if (csi2->stream_count != !enable)
-		goto update_count;
+	if (csi2->stream_count)
+		return 0;
 
-	dev_dbg(csi2->dev, "stream %s\n", enable ? "ON" : "OFF");
-	if (enable)
-		ret = csi2_start(csi2);
-	else
-		csi2_stop(csi2);
+	ret = csi2_start(csi2);
 	if (ret)
 		return ret;
 
-update_count:
-	csi2->stream_count += enable ? 1 : -1;
-	if (csi2->stream_count < 0)
-		csi2->stream_count = 0;
+	csi2->stream_count++;
+
 	return ret;
 }
 
+static int dw_csi2_disable_streams(struct v4l2_subdev *sd,
+				   struct v4l2_subdev_state *state, u32 pad,
+				   u64 streams_mask)
+{
+	struct dw_mipi_csi2_dev *csi2 = sd_to_dev(sd);
+
+	guard(mutex)(&csi2->lock);
+
+	if (!csi2->stream_count) {
+		dev_err(csi2->dev, "Error: csi2 enable count already be 0\n");
+		return 0;
+	}
+
+	csi2->stream_count--;
+
+	if (!csi2->stream_count)
+		csi2_stop(csi2);
+
+	return 0;
+}
+
 static int csi2_link_setup(struct media_entity *entity,
 			   const struct media_pad *local,
 			   const struct media_pad *remote, u32 flags)
@@ -507,18 +520,15 @@ static const struct media_entity_operations csi2_entity_ops = {
 	.get_fwnode_pad = v4l2_subdev_get_fwnode_pad_1_to_1,
 };
 
-static const struct v4l2_subdev_video_ops csi2_video_ops = {
-	.s_stream = csi2_s_stream,
-};
-
 static const struct v4l2_subdev_pad_ops csi2_pad_ops = {
 	.get_fmt = csi2_get_fmt,
 	.set_fmt = csi2_set_fmt,
+	.enable_streams = dw_csi2_enable_streams,
+	.disable_streams = dw_csi2_disable_streams,
 };
 
 static const struct v4l2_subdev_ops csi2_subdev_ops = {
 	.core = &csi2_core_ops,
-	.video = &csi2_video_ops,
 	.pad = &csi2_pad_ops,
 };
 

-- 
2.34.1