Commit c1cf3d89 authored by Ezequiel Garcia's avatar Ezequiel Garcia Committed by Mauro Carvalho Chehab
Browse files

media: v4l2-async: Clean v4l2_async_notifier_add_fwnode_remote_subdev



Change v4l2_async_notifier_add_fwnode_remote_subdev semantics
so it allocates the struct v4l2_async_subdev pointer.

This makes the API consistent: the v4l2-async subdevice addition
functions have now a unified usage model. This model is simpler,
as it makes v4l2-async responsible for the allocation and release
of the subdevice descriptor, and no longer something the driver
has to worry about.

On the user side, the change makes the API simpler for the drivers
to use and less error-prone.

Signed-off-by: default avatarEzequiel Garcia <ezequiel@collabora.com>
Reviewed-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: default avatarHelen Koike <helen.koike@collabora.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
parent 38a50230
Loading
Loading
Loading
Loading
+7 −10
Original line number Diff line number Diff line
@@ -1464,7 +1464,8 @@ static int cio2_parse_firmware(struct cio2_device *cio2)
		struct v4l2_fwnode_endpoint vep = {
			.bus_type = V4L2_MBUS_CSI2_DPHY
		};
		struct sensor_async_subdev *s_asd = NULL;
		struct sensor_async_subdev *s_asd;
		struct v4l2_async_subdev *asd;
		struct fwnode_handle *ep;

		ep = fwnode_graph_get_endpoint_by_id(
@@ -1478,27 +1479,23 @@ static int cio2_parse_firmware(struct cio2_device *cio2)
		if (ret)
			goto err_parse;

		s_asd = kzalloc(sizeof(*s_asd), GFP_KERNEL);
		if (!s_asd) {
			ret = -ENOMEM;
		asd = v4l2_async_notifier_add_fwnode_remote_subdev(
				&cio2->notifier, ep, sizeof(*s_asd));
		if (IS_ERR(asd)) {
			ret = PTR_ERR(asd);
			goto err_parse;
		}

		s_asd = container_of(asd, struct sensor_async_subdev, asd);
		s_asd->csi2.port = vep.base.port;
		s_asd->csi2.lanes = vep.bus.mipi_csi2.num_data_lanes;

		ret = v4l2_async_notifier_add_fwnode_remote_subdev(
			&cio2->notifier, ep, &s_asd->asd);
		if (ret)
			goto err_parse;

		fwnode_handle_put(ep);

		continue;

err_parse:
		fwnode_handle_put(ep);
		kfree(s_asd);
		return ret;
	}

+33 −46
Original line number Diff line number Diff line
@@ -2126,21 +2126,6 @@ static void isp_parse_of_csi1_endpoint(struct device *dev,
	buscfg->bus.ccp2.crc = 1;
}

static int isp_alloc_isd(struct isp_async_subdev **isd,
			 struct isp_bus_cfg **buscfg)
{
	struct isp_async_subdev *__isd;

	__isd = kzalloc(sizeof(*__isd), GFP_KERNEL);
	if (!__isd)
		return -ENOMEM;

	*isd = __isd;
	*buscfg = &__isd->bus;

	return 0;
}

static struct {
	u32 phy;
	u32 csi2_if;
@@ -2156,7 +2141,7 @@ static int isp_parse_of_endpoints(struct isp_device *isp)
{
	struct fwnode_handle *ep;
	struct isp_async_subdev *isd = NULL;
	struct isp_bus_cfg *buscfg;
	struct v4l2_async_subdev *asd;
	unsigned int i;

	ep = fwnode_graph_get_endpoint_by_id(
@@ -2174,20 +2159,15 @@ static int isp_parse_of_endpoints(struct isp_device *isp)
		ret = v4l2_fwnode_endpoint_parse(ep, &vep);

		if (!ret) {
			ret = isp_alloc_isd(&isd, &buscfg);
			if (ret)
				return ret;
			asd = v4l2_async_notifier_add_fwnode_remote_subdev(
				&isp->notifier, ep, sizeof(*isd));
			if (!IS_ERR(asd)) {
				isd = container_of(asd, struct isp_async_subdev, asd);
				isp_parse_of_parallel_endpoint(isp->dev, &vep, &isd->bus);
			}

		if (!ret) {
			isp_parse_of_parallel_endpoint(isp->dev, &vep, buscfg);
			ret = v4l2_async_notifier_add_fwnode_remote_subdev(
				&isp->notifier, ep, &isd->asd);
		}

		fwnode_handle_put(ep);
		if (ret)
			kfree(isd);
	}

	for (i = 0; i < ARRAY_SIZE(isp_bus_interfaces); i++) {
@@ -2206,15 +2186,8 @@ static int isp_parse_of_endpoints(struct isp_device *isp)
		dev_dbg(isp->dev, "parsing serial interface %u, node %pOF\n", i,
			to_of_node(ep));

		ret = isp_alloc_isd(&isd, &buscfg);
		if (ret)
			return ret;

		ret = v4l2_fwnode_endpoint_parse(ep, &vep);
		if (!ret) {
			buscfg->interface = isp_bus_interfaces[i].csi2_if;
			isp_parse_of_csi2_endpoint(isp->dev, &vep, buscfg);
		} else if (ret == -ENXIO) {
		if (ret == -ENXIO) {
			vep = (struct v4l2_fwnode_endpoint)
				{ .bus_type = V4L2_MBUS_CSI1 };
			ret = v4l2_fwnode_endpoint_parse(ep, &vep);
@@ -2224,21 +2197,35 @@ static int isp_parse_of_endpoints(struct isp_device *isp)
					{ .bus_type = V4L2_MBUS_CCP2 };
				ret = v4l2_fwnode_endpoint_parse(ep, &vep);
			}
		}

		if (!ret) {
				buscfg->interface =
			asd = v4l2_async_notifier_add_fwnode_remote_subdev(
				&isp->notifier, ep, sizeof(*isd));

			if (!IS_ERR(asd)) {
				isd = container_of(asd, struct isp_async_subdev, asd);

				switch (vep.bus_type) {
				case V4L2_MBUS_CSI2_DPHY:
					isd->bus.interface =
						isp_bus_interfaces[i].csi2_if;
					isp_parse_of_csi2_endpoint(isp->dev, &vep, &isd->bus);
					break;
				case V4L2_MBUS_CSI1:
				case V4L2_MBUS_CCP2:
					isd->bus.interface =
						isp_bus_interfaces[i].csi1_if;
					isp_parse_of_csi1_endpoint(isp->dev, &vep,
							   buscfg);
								   &isd->bus);
					break;
				default:
					break;
				}
			}
		}

		if (!ret)
			ret = v4l2_async_notifier_add_fwnode_remote_subdev(
				&isp->notifier, ep, &isd->asd);

		fwnode_handle_put(ep);
		if (ret)
			kfree(isd);
	}

	return 0;
+6 −9
Original line number Diff line number Diff line
@@ -252,6 +252,7 @@ static int rkisp1_subdev_notifier(struct rkisp1_device *rkisp1)
			.bus_type = V4L2_MBUS_CSI2_DPHY
		};
		struct rkisp1_sensor_async *rk_asd = NULL;
		struct v4l2_async_subdev *asd;
		struct fwnode_handle *ep;

		ep = fwnode_graph_get_endpoint_by_id(dev_fwnode(rkisp1->dev),
@@ -264,21 +265,18 @@ static int rkisp1_subdev_notifier(struct rkisp1_device *rkisp1)
		if (ret)
			goto err_parse;

		rk_asd = kzalloc(sizeof(*rk_asd), GFP_KERNEL);
		if (!rk_asd) {
			ret = -ENOMEM;
		asd = v4l2_async_notifier_add_fwnode_remote_subdev(ntf, ep,
							sizeof(*rk_asd));
		if (IS_ERR(asd)) {
			ret = PTR_ERR(asd);
			goto err_parse;
		}

		rk_asd = container_of(asd, struct rkisp1_sensor_async, asd);
		rk_asd->mbus_type = vep.bus_type;
		rk_asd->mbus_flags = vep.bus.mipi_csi2.flags;
		rk_asd->lanes = vep.bus.mipi_csi2.num_data_lanes;

		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);

@@ -289,7 +287,6 @@ static int rkisp1_subdev_notifier(struct rkisp1_device *rkisp1)
		continue;
err_parse:
		fwnode_handle_put(ep);
		kfree(rk_asd);
		v4l2_async_notifier_cleanup(ntf);
		return ret;
	}
+6 −3
Original line number Diff line number Diff line
@@ -118,6 +118,7 @@ static int sun4i_csi_notifier_init(struct sun4i_csi *csi)
	struct v4l2_fwnode_endpoint vep = {
		.bus_type = V4L2_MBUS_PARALLEL,
	};
	struct v4l2_async_subdev *asd;
	struct fwnode_handle *ep;
	int ret;

@@ -134,10 +135,12 @@ static int sun4i_csi_notifier_init(struct sun4i_csi *csi)

	csi->bus = vep.bus.parallel;

	ret = v4l2_async_notifier_add_fwnode_remote_subdev(&csi->notifier,
							   ep, &csi->asd);
	if (ret)
	asd = v4l2_async_notifier_add_fwnode_remote_subdev(&csi->notifier,
							   ep, sizeof(*asd));
	if (IS_ERR(asd)) {
		ret = PTR_ERR(asd);
		goto out;
	}

	csi->notifier.ops = &sun4i_csi_notify_ops;

+0 −1
Original line number Diff line number Diff line
@@ -139,7 +139,6 @@ struct sun4i_csi {
	struct v4l2_mbus_framefmt	subdev_fmt;

	/* V4L2 Async variables */
	struct v4l2_async_subdev	asd;
	struct v4l2_async_notifier	notifier;
	struct v4l2_subdev		*src_subdev;
	int				src_pad;
Loading