Skip to contentSkip to conversation

IVSC CSI fwnode parsing fixes and cleanups

PATCH In review Sakari Ailus 2 participants 9 messages Oct 26, 2023 – Nov 8, 2023

Subsystems (2)
lore
Share & tools
lore

Sakari Ailus

author maintainer
#0 lore raw

cover IVSC CSI fwnode parsing fixes and cleanups

Hi folks,

This set addresses issues in graph endpoint parsing as well as fixes error handling and cleans up things in general.

The main issue there was the IVSC CSI driver was parsing the endpoints of another device while ignoring its own endpoint on port 1.

Sakari Ailus (6):
media: ivsc: csi: Don't parse remote endpoints
media: ivsc: csi: Clean up V4L2 async notifier on error
media: ivsc: csi: Clean up notifier set-up
media: ivsc: csi: Clean up parsing firmware and setting up async
notifier
media: ivsc: csi: Don't mask v4l2_fwnode_endpoint_parse return value
media: ivsc: csi: Check number of lanes on source, too

 drivers/media/pci/intel/ivsc/mei_csi.c | 65 ++++++++++++++++----------
 1 file changed, 41 insertions(+), 24 deletions(-)
Signature · 1 line
2.39.2
author maintainer
#1 lore raw

PATCH 1/6 media: ivsc: csi: Don't parse remote endpoints

The driver parsed, besides its own endpoint on the sink, the remote upstream endpoint that most likely is a sensor, and took the number of lanes from that. Instead obtain the number of lanes from the local endpoint.

---
 drivers/media/pci/intel/ivsc/mei_csi.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/media/pci/intel/ivsc/mei_csi.c +2 -6
index b2b9d1669a82..b04847e30213 100644
@@ -662,6 +662,8 @@ static int mei_csi_parse_firmware(struct mei_csi *csi)
 		return -EINVAL;
 	}
 
+	csi->nr_of_lanes = v4l2_ep.bus.mipi_csi2.num_data_lanes;
+
 	fwnode = fwnode_graph_get_remote_endpoint(ep);
 	fwnode_handle_put(ep);
 
@@ -675,18 +677,12 @@ static int mei_csi_parse_firmware(struct mei_csi *csi)
 		return PTR_ERR(asd);
 	}
 
-	ret = v4l2_fwnode_endpoint_alloc_parse(fwnode, &v4l2_ep);
 	fwnode_handle_put(fwnode);
-	if (ret)
-		return ret;
-	csi->nr_of_lanes = v4l2_ep.bus.mipi_csi2.num_data_lanes;
 
 	ret = v4l2_async_nf_register(&csi->notifier);
 	if (ret)
 		v4l2_async_nf_cleanup(&csi->notifier);
 
-	v4l2_fwnode_endpoint_free(&v4l2_ep);
-
 	return ret;
 }
 
Signature · 1 line
2.39.2
Reviewed-by on v1 1/6
#2 lore raw

Re: [PATCH 1/6] media: ivsc: csi: Don't parse remote endpoints

Quoted 4 lines · Sakari Ailus

The driver parsed, besides its own endpoint on the sink, the remote upstream endpoint that most likely is a sensor, and took the number of lanes from that. Instead obtain the number of lanes from the local endpoint.

Yes, it's the work of ipu-bridge or device table. ;)

Quoted 30 lines
---
 drivers/media/pci/intel/ivsc/mei_csi.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/media/pci/intel/ivsc/mei_csi.c +2 -4
index b2b9d1669a82..b04847e30213 100644
@@ -662,6 +662,8 @@ static int mei_csi_parse_firmware(struct mei_csi *csi)
 		return -EINVAL;
 	}
 
+	csi->nr_of_lanes = v4l2_ep.bus.mipi_csi2.num_data_lanes;
+
 	fwnode = fwnode_graph_get_remote_endpoint(ep);
 	fwnode_handle_put(ep);
 
@@ -675,18 +677,12 @@ static int mei_csi_parse_firmware(struct mei_csi *csi)
 		return PTR_ERR(asd);
 	}
 
-	ret = v4l2_fwnode_endpoint_alloc_parse(fwnode, &v4l2_ep);
 	fwnode_handle_put(fwnode);
-	if (ret)
-		return ret;
-	csi->nr_of_lanes = v4l2_ep.bus.mipi_csi2.num_data_lanes;

drivers/media/pci/intel/ivsc/mei_csi.c static int mei_csi_parse_firmware(struct mei_csi *csi) · line 688

Quoted 10 lines
drivers/media/pci/intel/ivsc/mei_csi.c +0 -2
 
 	ret = v4l2_async_nf_register(&csi->notifier);
 	if (ret)
 		v4l2_async_nf_cleanup(&csi->notifier);
 
-	v4l2_fwnode_endpoint_free(&v4l2_ep);
-
 	return ret;
 }
 
Signature · 2 lines
Best regards,
Bingbu Cao
author maintainer
#3 lore raw

PATCH 2/6 media: ivsc: csi: Clean up V4L2 async notifier on error

In reply to Sakari Ailus

Clean up the V4L2 async notifier in error handling path, and add label to unify handling.

---
 drivers/media/pci/intel/ivsc/mei_csi.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/media/pci/intel/ivsc/mei_csi.c +9 -5
index b04847e30213..281d7f5e18f9 100644
@@ -672,16 +672,20 @@ static int mei_csi_parse_firmware(struct mei_csi *csi)
 
 	asd = v4l2_async_nf_add_fwnode(&csi->notifier, fwnode,
 				       struct v4l2_async_connection);
+	fwnode_handle_put(fwnode);
 	if (IS_ERR(asd)) {
-		fwnode_handle_put(fwnode);
-		return PTR_ERR(asd);
+		ret = PTR_ERR(asd);
+		goto out_nf_cleanup;
 	}
 
-	fwnode_handle_put(fwnode);
-
 	ret = v4l2_async_nf_register(&csi->notifier);
 	if (ret)
-		v4l2_async_nf_cleanup(&csi->notifier);
+		goto out_nf_cleanup;
+
+	return 0;
+
+out_nf_cleanup:
+	v4l2_async_nf_cleanup(&csi->notifier);
 
 	return ret;
 }
Signature · 1 line
2.39.2
author maintainer
#4 lore raw

PATCH 3/6 media: ivsc: csi: Clean up notifier set-up

In reply to Sakari Ailus

Use v4l2_async_nf_add_fwnode_remote() to add an async fwnode remote sub-device sub-device to the notifier. This avoids dealing with remote endpoints.

---
 drivers/media/pci/intel/ivsc/mei_csi.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/media/pci/intel/ivsc/mei_csi.c +3 -7
index 281d7f5e18f9..cd0dcbbb35df 100644
@@ -645,7 +645,6 @@ static int mei_csi_parse_firmware(struct mei_csi *csi)
 	};
 	struct device *dev = &csi->cldev->dev;
 	struct v4l2_async_connection *asd;
-	struct fwnode_handle *fwnode;
 	struct fwnode_handle *ep;
 	int ret;
 
@@ -664,15 +663,12 @@ static int mei_csi_parse_firmware(struct mei_csi *csi)
 
 	csi->nr_of_lanes = v4l2_ep.bus.mipi_csi2.num_data_lanes;
 
-	fwnode = fwnode_graph_get_remote_endpoint(ep);
-	fwnode_handle_put(ep);
-
 	v4l2_async_subdev_nf_init(&csi->notifier, &csi->subdev);
 	csi->notifier.ops = &mei_csi_notify_ops;
 
-	asd = v4l2_async_nf_add_fwnode(&csi->notifier, fwnode,
-				       struct v4l2_async_connection);
-	fwnode_handle_put(fwnode);
+	asd = v4l2_async_nf_add_fwnode_remote(&csi->notifier, ep,
+					      struct v4l2_async_connection);
+	fwnode_handle_put(ep);
 	if (IS_ERR(asd)) {
 		ret = PTR_ERR(asd);
 		goto out_nf_cleanup;
Signature · 1 line
2.39.2
author maintainer
#5 lore raw

PATCH 4/6 media: ivsc: csi: Clean up parsing firmware and setting up async notifier

In reply to Sakari Ailus

Set up async notifier right after obtaining the local endpoint. This makes error handling straightforward.

---
 drivers/media/pci/intel/ivsc/mei_csi.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/media/pci/intel/ivsc/mei_csi.c +8 -6
index cd0dcbbb35df..c19c944f613b 100644
@@ -654,21 +654,20 @@ static int mei_csi_parse_firmware(struct mei_csi *csi)
 		return -EINVAL;
 	}
 
+	v4l2_async_subdev_nf_init(&csi->notifier, &csi->subdev);
+	csi->notifier.ops = &mei_csi_notify_ops;
+
 	ret = v4l2_fwnode_endpoint_parse(ep, &v4l2_ep);
 	if (ret) {
 		dev_err(dev, "could not parse v4l2 endpoint\n");
-		fwnode_handle_put(ep);
-		return -EINVAL;
+		ret = -EINVAL;
+		goto out_nf_cleanup;
 	}
 
 	csi->nr_of_lanes = v4l2_ep.bus.mipi_csi2.num_data_lanes;
 
-	v4l2_async_subdev_nf_init(&csi->notifier, &csi->subdev);
-	csi->notifier.ops = &mei_csi_notify_ops;
-
 	asd = v4l2_async_nf_add_fwnode_remote(&csi->notifier, ep,
 					      struct v4l2_async_connection);
-	fwnode_handle_put(ep);
 	if (IS_ERR(asd)) {
 		ret = PTR_ERR(asd);
 		goto out_nf_cleanup;
@@ -678,10 +677,13 @@ static int mei_csi_parse_firmware(struct mei_csi *csi)
 	if (ret)
 		goto out_nf_cleanup;
 
+	fwnode_handle_put(ep);
+
 	return 0;
 
 out_nf_cleanup:
 	v4l2_async_nf_cleanup(&csi->notifier);
+	fwnode_handle_put(ep);
 
 	return ret;
 }
Signature · 1 line
2.39.2
author maintainer
#6 lore raw

PATCH 5/6 media: ivsc: csi: Don't mask v4l2_fwnode_endpoint_parse return value

In reply to Sakari Ailus

v4l2_fwnode_endpoint_parse already returns an error value, don't set return value to -EINVAL.

---
 drivers/media/pci/intel/ivsc/mei_csi.c | 1 -
 1 file changed, 1 deletion(-)
drivers/media/pci/intel/ivsc/mei_csi.c +0 -1
index c19c944f613b..07d8c7f82306 100644
@@ -660,7 +660,6 @@ static int mei_csi_parse_firmware(struct mei_csi *csi)
 	ret = v4l2_fwnode_endpoint_parse(ep, &v4l2_ep);
 	if (ret) {
 		dev_err(dev, "could not parse v4l2 endpoint\n");
-		ret = -EINVAL;
 		goto out_nf_cleanup;
 	}
 
Signature · 1 line
2.39.2
author maintainer
#7 lore raw

PATCH 6/6 media: ivsc: csi: Check number of lanes on source, too

In reply to Sakari Ailus

The IVSC has two CSI-2 ports, one receiver and one transmitter, for passing through the CSI-2 image data. Both have the same number of lanes and this information should be also present in firmware. Check this.

---
 drivers/media/pci/intel/ivsc/mei_csi.c | 38 ++++++++++++++++++++------
 1 file changed, 29 insertions(+), 9 deletions(-)
drivers/media/pci/intel/ivsc/mei_csi.c +29 -9
index 07d8c7f82306..99f2e312a1df 100644
@@ -645,27 +645,47 @@ static int mei_csi_parse_firmware(struct mei_csi *csi)
 	};
 	struct device *dev = &csi->cldev->dev;
 	struct v4l2_async_connection *asd;
-	struct fwnode_handle *ep;
+	struct fwnode_handle *sink_ep, *source_ep;
 	int ret;
 
-	ep = fwnode_graph_get_endpoint_by_id(dev_fwnode(dev), 0, 0, 0);
-	if (!ep) {
-		dev_err(dev, "not connected to subdevice\n");
+	sink_ep = fwnode_graph_get_endpoint_by_id(dev_fwnode(dev), 0, 0, 0);
+	if (!sink_ep) {
+		dev_err(dev, "can't obtain sink endpoint\n");
 		return -EINVAL;
 	}
 
 	v4l2_async_subdev_nf_init(&csi->notifier, &csi->subdev);
 	csi->notifier.ops = &mei_csi_notify_ops;
 
-	ret = v4l2_fwnode_endpoint_parse(ep, &v4l2_ep);
+	ret = v4l2_fwnode_endpoint_parse(sink_ep, &v4l2_ep);
 	if (ret) {
-		dev_err(dev, "could not parse v4l2 endpoint\n");
+		dev_err(dev, "could not parse v4l2 sink endpoint\n");
 		goto out_nf_cleanup;
 	}
 
 	csi->nr_of_lanes = v4l2_ep.bus.mipi_csi2.num_data_lanes;
 
-	asd = v4l2_async_nf_add_fwnode_remote(&csi->notifier, ep,
+	source_ep = fwnode_graph_get_endpoint_by_id(dev_fwnode(dev), 1, 0, 0);
+	if (!source_ep) {
+		dev_err(dev, "can't obtain source endpoint\n");
+		return -EINVAL;
+	}
+
+	ret = v4l2_fwnode_endpoint_parse(source_ep, &v4l2_ep);
+	fwnode_handle_put(source_ep);
+	if (ret) {
+		dev_err(dev, "could not parse v4l2 source endpoint\n");
+		goto out_nf_cleanup;
+	}
+
+	if (csi->nr_of_lanes != v4l2_ep.bus.mipi_csi2.num_data_lanes) {
+		dev_err(dev,
+			"the number of lanes does not match (%u vs. %u)\n",
+			csi->nr_of_lanes, v4l2_ep.bus.mipi_csi2.num_data_lanes);
+		goto out_nf_cleanup;
+	}
+
+	asd = v4l2_async_nf_add_fwnode_remote(&csi->notifier, sink_ep,
 					      struct v4l2_async_connection);
 	if (IS_ERR(asd)) {
 		ret = PTR_ERR(asd);
@@ -676,13 +696,13 @@ static int mei_csi_parse_firmware(struct mei_csi *csi)
 	if (ret)
 		goto out_nf_cleanup;
 
-	fwnode_handle_put(ep);
+	fwnode_handle_put(sink_ep);
 
 	return 0;
 
 out_nf_cleanup:
 	v4l2_async_nf_cleanup(&csi->notifier);
-	fwnode_handle_put(ep);
+	fwnode_handle_put(sink_ep);
 
 	return ret;
 }
Signature · 1 line
2.39.2
author maintainer
#8 lore raw

PATCH v2 6/6 media: ivsc: csi: Check number of lanes on source, too

The IVSC has two CSI-2 ports, one receiver and one transmitter, for passing through the CSI-2 image data. Both have the same number of lanes and this information should be also present in firmware. Check this.

---
since v1:

- Set returned error codes correctly.

- Put taken references in error handling (lane number check).

 drivers/media/pci/intel/ivsc/mei_csi.c | 40 ++++++++++++++++++++------
 1 file changed, 31 insertions(+), 9 deletions(-)
drivers/media/pci/intel/ivsc/mei_csi.c +31 -9
index 3f507d0170f9..2ca52390541d 100644
@@ -645,27 +645,49 @@ static int mei_csi_parse_firmware(struct mei_csi *csi)
 	};
 	struct device *dev = &csi->cldev->dev;
 	struct v4l2_async_connection *asd;
-	struct fwnode_handle *ep;
+	struct fwnode_handle *sink_ep, *source_ep;
 	int ret;
 
-	ep = fwnode_graph_get_endpoint_by_id(dev_fwnode(dev), 0, 0, 0);
-	if (!ep) {
-		dev_err(dev, "not connected to subdevice\n");
+	sink_ep = fwnode_graph_get_endpoint_by_id(dev_fwnode(dev), 0, 0, 0);
+	if (!sink_ep) {
+		dev_err(dev, "can't obtain sink endpoint\n");
 		return -EINVAL;
 	}
 
 	v4l2_async_subdev_nf_init(&csi->notifier, &csi->subdev);
 	csi->notifier.ops = &mei_csi_notify_ops;
 
-	ret = v4l2_fwnode_endpoint_parse(ep, &v4l2_ep);
+	ret = v4l2_fwnode_endpoint_parse(sink_ep, &v4l2_ep);
 	if (ret) {
-		dev_err(dev, "could not parse v4l2 endpoint\n");
+		dev_err(dev, "could not parse v4l2 sink endpoint\n");
 		goto out_nf_cleanup;
 	}
 
 	csi->nr_of_lanes = v4l2_ep.bus.mipi_csi2.num_data_lanes;
 
-	asd = v4l2_async_nf_add_fwnode_remote(&csi->notifier, ep,
+	source_ep = fwnode_graph_get_endpoint_by_id(dev_fwnode(dev), 1, 0, 0);
+	if (!source_ep) {
+		ret = -ENOTCONN;
+		dev_err(dev, "can't obtain source endpoint\n");
+		goto out_nf_cleanup;
+	}
+
+	ret = v4l2_fwnode_endpoint_parse(source_ep, &v4l2_ep);
+	fwnode_handle_put(source_ep);
+	if (ret) {
+		dev_err(dev, "could not parse v4l2 source endpoint\n");
+		goto out_nf_cleanup;
+	}
+
+	if (csi->nr_of_lanes != v4l2_ep.bus.mipi_csi2.num_data_lanes) {
+		ret = -EINVAL;
+		dev_err(dev,
+			"the number of lanes does not match (%u vs. %u)\n",
+			csi->nr_of_lanes, v4l2_ep.bus.mipi_csi2.num_data_lanes);
+		goto out_nf_cleanup;
+	}
+
+	asd = v4l2_async_nf_add_fwnode_remote(&csi->notifier, sink_ep,
 					      struct v4l2_async_connection);
 	if (IS_ERR(asd)) {
 		ret = PTR_ERR(asd);
@@ -676,13 +698,13 @@ static int mei_csi_parse_firmware(struct mei_csi *csi)
 	if (ret)
 		goto out_nf_cleanup;
 
-	fwnode_handle_put(ep);
+	fwnode_handle_put(sink_ep);
 
 	return 0;
 
 out_nf_cleanup:
 	v4l2_async_nf_cleanup(&csi->notifier);
-	fwnode_handle_put(ep);
+	fwnode_handle_put(sink_ep);
 
 	return ret;
 }
Signature · 1 line
2.39.2