Skip to contentSkip to conversation

fix fwnode API usage and remove v4l2_mbus_config field

PATCH Superseded Dafna Hirschfeld 2 participants 4 messages Feb 17, 2020

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover fix fwnode API usage and remove v4l2_mbus_config field

This patchset fixes usage of the APIs.
This fixes the item in the TODO file:

* Don't use v4l2_async_notifier_parse_fwnode_endpoints_by_port(). e.g. isp_parse_of_endpoints in drivers/media/platform/omap3isp/isp.c cio2_parse_firmware in drivers/media/pci/intel/ipu3/ipu3-cio2.c.

Patches summary:

- The first patch removes the field v4l2_mbus_config from 'struct rkisp1_sensor_async'.

- The second patch removes the usage of v4l2_async_notifier_parse_fwnode_endpoints_by_port.
The code is very similar to the code in the function cio2_parse_firmware but instead of iterating the ports it iterates the id's.
The patch also removes the relevant item from the TODO file.

Dafna Hirschfeld (2):
media: staging: rkisp1: remove mbus field from rkisp1_sensor_async
media: staging: rkisp1: replace the call to
v4l2_async_notifier_parse_fwnode_endpoints_by_port

 drivers/staging/media/rkisp1/TODO            |   3 -
 drivers/staging/media/rkisp1/rkisp1-common.h |   3 +-
 drivers/staging/media/rkisp1/rkisp1-dev.c    | 108 ++++++++++---------
 drivers/staging/media/rkisp1/rkisp1-isp.c    |  52 +++------
 4 files changed, 76 insertions(+), 90 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/2 media: staging: rkisp1: remove mbus field from rkisp1_sensor_async

'struct v4l2_mbus_config' is a legacy struct that should not be used in new drivers. So replace it with the fields:

enum v4l2_mbus_type mbus_type;
unsigned int parallel_bus_flags;

The field 'parallel_bus_flags' is used only for buses of types V4L2_MBUS_BT656, V4L2_MBUS_PARALLEL which are not yet supported so they are set to 0.

---
 drivers/staging/media/rkisp1/rkisp1-common.h |  3 +-
 drivers/staging/media/rkisp1/rkisp1-dev.c    | 22 ++-------
 drivers/staging/media/rkisp1/rkisp1-isp.c    | 52 +++++++-------------
 3 files changed, 24 insertions(+), 53 deletions(-)
drivers/staging/media/rkisp1/rkisp1-common.h +2 -1
index 4e773d611d1b..743916940965 100644
@@ -80,8 +80,9 @@ enum rkisp1_isp_pad {
  */
 struct rkisp1_sensor_async {
 	struct v4l2_async_subdev asd;
-	struct v4l2_mbus_config mbus;
 	unsigned int lanes;
+	enum v4l2_mbus_type mbus_type;
+	unsigned int parallel_bus_flags;
 	struct v4l2_subdev *sd;
 	struct v4l2_ctrl *pixel_rate_ctrl;
 	struct phy *dphy;
drivers/staging/media/rkisp1/rkisp1-dev.c +5 -17
index 21837d4dc9e1..72ab08a4e42d 100644
@@ -251,26 +251,14 @@ static int rkisp1_fwnode_parse(struct device *dev,
 		return -EINVAL;
 	}
 
-	s_asd->mbus.type = vep->bus_type;
-	s_asd->mbus.flags = vep->bus.mipi_csi2.flags;
+	s_asd->mbus_type = vep->bus_type;
 	s_asd->lanes = vep->bus.mipi_csi2.num_data_lanes;
 
-	switch (vep->bus.mipi_csi2.num_data_lanes) {
-	case 1:
-		s_asd->mbus.flags |= V4L2_MBUS_CSI2_1_LANE;
-		break;
-	case 2:
-		s_asd->mbus.flags |= V4L2_MBUS_CSI2_2_LANE;
-		break;
-	case 3:
-		s_asd->mbus.flags |= V4L2_MBUS_CSI2_3_LANE;
-		break;
-	case 4:
-		s_asd->mbus.flags |= V4L2_MBUS_CSI2_4_LANE;
-		break;
-	default:
+	/* Parallel bus is currently not supported */
+	s_asd->parallel_bus_flags = 0;
+
+	if (s_asd->lanes < 1 || s_asd->lanes > 4)
 		return -EINVAL;
-	}
 
 	return 0;
 }
drivers/staging/media/rkisp1/rkisp1-isp.c +17 -35

112 lines not on this page · raw message

Signature · 1 line
2.17.1
#2 lore raw

PATCH 2/2 media: staging: rkisp1: replace the call to v4l2_async_notifier_parse_fwnode_endpoints_by_port

In reply to Dafna Hirschfeld

don't call 'v4l2_async_notifier_parse_fwnode_endpoints_by_port' in order to register async subdevices. Instead call 'v4l2_fwnode_endpoint_parse' to parse the remote endpoints and then register each async subdev with 'v4l2_async_notifier_add_fwnode_remote_subdev'

Also remove the relevant item in the TODO file

---
 drivers/staging/media/rkisp1/TODO         |  3 -
 drivers/staging/media/rkisp1/rkisp1-dev.c | 96 ++++++++++++++---------
 2 files changed, 57 insertions(+), 42 deletions(-)
drivers/staging/media/rkisp1/TODO +0 -3
index 03cd9a4e70f7..8c4d50b5b5fc 100644
@@ -1,7 +1,4 @@
 * Fix serialization on subdev ops.
-* Don't use v4l2_async_notifier_parse_fwnode_endpoints_by_port().
-e.g. isp_parse_of_endpoints in drivers/media/platform/omap3isp/isp.c
-cio2_parse_firmware in drivers/media/pci/intel/ipu3/ipu3-cio2.c.
 * Fix pad format size for statistics and parameters entities.
 * Use threaded interrupt for rkisp1_stats_isr(), remove work queue.
 * Fix checkpatch errors.
drivers/staging/media/rkisp1/rkisp1-dev.c +57 -39

115 lines not on this page · raw message

Signature · 1 line
2.17.1
#3 lore raw

Re: [PATCH 2/2] media: staging: rkisp1: replace the call to v4l2_async_notifier_parse_fwnode_endpoints_by_port

Hi Dafna,

Thanks for the patch.
Please see my comments below.

Quoted 87 lines · Dafna Hirschfeld

don't call 'v4l2_async_notifier_parse_fwnode_endpoints_by_port' in order to register async subdevices. Instead call 'v4l2_fwnode_endpoint_parse' to parse the remote endpoints and then register each async subdev with 'v4l2_async_notifier_add_fwnode_remote_subdev'

Also remove the relevant item in the TODO file

---
 drivers/staging/media/rkisp1/TODO         |  3 -
 drivers/staging/media/rkisp1/rkisp1-dev.c | 96 ++++++++++++++---------
 2 files changed, 57 insertions(+), 42 deletions(-)
drivers/staging/media/rkisp1/TODO +0 -3
index 03cd9a4e70f7..8c4d50b5b5fc 100644
@@ -1,7 +1,4 @@
 * Fix serialization on subdev ops.
-* Don't use v4l2_async_notifier_parse_fwnode_endpoints_by_port().
-e.g. isp_parse_of_endpoints in drivers/media/platform/omap3isp/isp.c
-cio2_parse_firmware in drivers/media/pci/intel/ipu3/ipu3-cio2.c.
 * Fix pad format size for statistics and parameters entities.
 * Use threaded interrupt for rkisp1_stats_isr(), remove work queue.
 * Fix checkpatch errors.
drivers/staging/media/rkisp1/rkisp1-dev.c +7 -35
index 72ab08a4e42d..922f7bb83530 100644
@@ -234,35 +234,6 @@ static int rkisp1_subdev_notifier_complete(struct v4l2_async_notifier *notifier)
 	return ret;
 }
 
-static int rkisp1_fwnode_parse(struct device *dev,
-			       struct v4l2_fwnode_endpoint *vep,
-			       struct v4l2_async_subdev *asd)
-{
-	struct rkisp1_sensor_async *s_asd =
-			container_of(asd, struct rkisp1_sensor_async, asd);
-
-	if (vep->bus_type != V4L2_MBUS_CSI2_DPHY) {
-		dev_err(dev, "Only CSI2 bus type is currently supported\n");
-		return -EINVAL;
-	}
-
-	if (vep->base.port != 0) {
-		dev_err(dev, "The ISP has only port 0\n");
-		return -EINVAL;
-	}
-
-	s_asd->mbus_type = vep->bus_type;
-	s_asd->lanes = vep->bus.mipi_csi2.num_data_lanes;
-
-	/* Parallel bus is currently not supported */
-	s_asd->parallel_bus_flags = 0;
-
-	if (s_asd->lanes < 1 || s_asd->lanes > 4)
-		return -EINVAL;
-
-	return 0;
-}
-
 static const struct v4l2_async_notifier_operations rkisp1_subdev_notifier_ops = {
 	.bound = rkisp1_subdev_notifier_bound,
 	.unbind = rkisp1_subdev_notifier_unbind,
@@ -272,23 +243,70 @@ static const struct v4l2_async_notifier_operations rkisp1_subdev_notifier_ops =
 static int rkisp1_subdev_notifier(struct rkisp1_device *rkisp1)
 {
 	struct v4l2_async_notifier *ntf = &rkisp1->notifier;
-	struct device *dev = rkisp1->dev;
+	int next_id = 0;
 	int ret;
 
 	v4l2_async_notifier_init(ntf);
 
-	ret = v4l2_async_notifier_parse_fwnode_endpoints_by_port(dev, ntf,
-					sizeof(struct rkisp1_sensor_async),
-					0, rkisp1_fwnode_parse);
-	if (ret)
-		return ret;
+	while (1) {
+		struct v4l2_fwnode_endpoint vep = {
+			.bus_type = V4L2_MBUS_CSI2_DPHY
+		};
+		struct rkisp1_sensor_async *rk_asd = NULL;
+		struct fwnode_handle *ep;

drivers/staging/media/rkisp1/rkisp1-dev.c static const struct v4l2_async_notifier_operations rkisp1_subdev_notifier_ops = · line 263

Quoted 10 lines
drivers/staging/media/rkisp1/rkisp1-dev.c +5 -3
 
-	if (list_empty(&ntf->asd_list))
-		return -ENODEV;
+		ep = fwnode_graph_get_endpoint_by_id(dev_fwnode(rkisp1->dev),
+			0, next_id, FWNODE_GRAPH_ENDPOINT_NEXT);
 
-	ntf->ops = &rkisp1_subdev_notifier_ops;
+		if (!ep) {
+			if (next_id == 0)
+				dev_warn(rkisp1->dev, "no remote subdevice found\n");

This check can be done after the loop, then you can remove the curly braces. Also, please use if (!next_id)

Quoted 33 lines
drivers/staging/media/rkisp1/rkisp1-dev.c +31 -1
+			break;
+		}
 
-	return v4l2_async_notifier_register(&rkisp1->v4l2_dev, ntf);
+		ret = v4l2_fwnode_endpoint_parse(ep, &vep);
+		if (ret)
+			goto err_parse;
+
+		rk_asd = kzalloc(sizeof(*rk_asd), GFP_KERNEL);
+		if (!rk_asd) {
+			ret = -ENOMEM;
+			goto err_parse;
+		}
+
+		rk_asd->lanes = vep.bus.mipi_csi2.num_data_lanes;
+		rk_asd->mbus_type = vep.bus_type;
+
+		/* Parallel bus is currently not supported */
+		rk_asd->parallel_bus_flags = 0;
+		ret = v4l2_async_notifier_add_fwnode_remote_subdev(ntf, ep,
+								   &rk_asd->asd);
+		if (ret)
+			goto err_parse;
+
+		dev_dbg(rkisp1->dev, "registered ep id %d with %d lanes\n",
+			vep.base.id, rk_asd->lanes);
+
+		next_id = vep.base.id + 1;
+
+		fwnode_handle_put(ep);
+
+		continue;
+err_parse:

drivers/staging/media/rkisp1/rkisp1-dev.c static const struct v4l2_async_notifier_operations rkisp1_subdev_notifier_ops = · line 305

Quoted 10 lines
drivers/staging/media/rkisp1/rkisp1-dev.c +10 -0
+		fwnode_handle_put(ep);
+		kfree(rk_asd);
+		v4l2_async_notifier_cleanup(ntf);
+		return ret;
+	}
+
+	ntf->ops = &rkisp1_subdev_notifier_ops;
+	ret = v4l2_async_notifier_register(&rkisp1->v4l2_dev, ntf);
+	if (ret)
+		goto end;

This is the only place you use the end label, so you could just do a simple:

if (ret) {
	v4l2_async_notifier_cleanup(ntf);
	return ret;
}

return 0;

drivers/staging/media/rkisp1/rkisp1-dev.c static const struct v4l2_async_notifier_operations rkisp1_subdev_notifier_ops = · line 312

Quoted 8 lines
drivers/staging/media/rkisp1/rkisp1-dev.c +4 -0
+	return 0;
+end:
+	v4l2_async_notifier_cleanup(ntf);
+	return ret;
 }
 
 /* ----------------------------------------------------------------------------

Regards,
Helen