On Thu, May 02, 2024 at 04:23:16PM +0200, Niklas Söderlund wrote: > Hi Jacopo, > > Thanks for your work. > > On 2024-04-30 12:39:51 +0200, Jacopo Mondi wrote: > > Create and initialize the v4l2_subdev_state for the R-Car CSI-2 receiver > > in order to prepare to support multiplexed transmitters. > > > > Create the subdevice state with v4l2_subdev_init_finalize() and > > implement the init_state() operation to guarantee the state is initialized. > > > > The routing table within the R-Car CSI-2 receiver is fixed, streams > > received on source_stream X will be directed to pad (X + 1) by default. > > Initialize a static routing table with such routes set as active. > > > > While at it, disable runtime_pm() in the probe() function error path. s/runtime_pm()/runtime PM/ > Can we break this out in a separate patch? As the multiplexed stream > work will not be ready for v6.10 if I understood the tendencies > correctly (?), we can at least fix this issue before that. Agreed, the fix should be a separate patch, with a Fixes: tag. > > Signed-off-by: Jacopo Mondi <jacopo.mondi@xxxxxxxxxxxxxxxx> > > --- > > drivers/media/platform/renesas/rcar-csi2.c | 74 +++++++++++++++++++++- > > 1 file changed, 72 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/media/platform/renesas/rcar-csi2.c b/drivers/media/platform/renesas/rcar-csi2.c > > index 582d5e35db0e..82dc0b92b8d3 100644 > > --- a/drivers/media/platform/renesas/rcar-csi2.c > > +++ b/drivers/media/platform/renesas/rcar-csi2.c > > @@ -1226,6 +1226,65 @@ static const struct v4l2_subdev_ops rcar_csi2_subdev_ops = { > > .pad = &rcar_csi2_pad_ops, > > }; > > > > +static int rcsi2_init_state(struct v4l2_subdev *sd, > > + struct v4l2_subdev_state *state) > > +{ > > + /* > > + * Routing is fixed for this device: streams sent on sink_stream X > > + * are directed to pad (X + 1). Which streams goes to the next > > + * processing block (VIN) is controlled by link enablement between the > > + * CSI-2 and the VIN itself and not by the CSI-2 routing table. > > + * > > + * The routing table is then fixed, as stream X will be directed to > > + * csi:(X + 1)/0 and will be transmitted to VINs the on media link > > + * csi2:(x + 1)->vin:0. > > + * > > + * For example, to route stream #3 to VIN #1 : "csi2:4/0 -> vin1:0" and > > + * to route stream #2 to VIN #4 : "csi2:3/0 -> vin4:0". > > + */ > > + struct v4l2_subdev_route routes[] = { > > + { > > + .sink_pad = RCAR_CSI2_SINK, > > + .sink_stream = 0, > > + .source_pad = RCAR_CSI2_SOURCE_VC0, > > + .source_stream = 0, > > + .flags = V4L2_SUBDEV_ROUTE_FL_ACTIVE, > > + }, > > + { > > + .sink_pad = RCAR_CSI2_SINK, > > + .sink_stream = 1, > > + .source_pad = RCAR_CSI2_SOURCE_VC1, > > + .source_stream = 0, > > + .flags = V4L2_SUBDEV_ROUTE_FL_ACTIVE, > > + }, > > + { > > + .sink_pad = RCAR_CSI2_SINK, > > + .sink_stream = 2, > > + .source_pad = RCAR_CSI2_SOURCE_VC2, > > + .source_stream = 0, > > + .flags = V4L2_SUBDEV_ROUTE_FL_ACTIVE, > > + }, > > + { > > + .sink_pad = RCAR_CSI2_SINK, > > + .sink_stream = 3, > > + .source_pad = RCAR_CSI2_SOURCE_VC3, > > + .source_stream = 0, > > + .flags = V4L2_SUBDEV_ROUTE_FL_ACTIVE, > > + }, > > + }; > > + > > + struct v4l2_subdev_krouting routing = { > > + .num_routes = ARRAY_SIZE(routes), > > + .routes = routes, > > + }; > > Should not the two structs above be static const as you return a pointer > to them? v4l2_subdev_set_routing() takes a non-const v4l2_subdev_krouting argument. Unless I'm missing something, this function doesn't return a pointer to the local structures. > > + > > + return v4l2_subdev_set_routing(sd, state, &routing); > > +} > > + > > +static const struct v4l2_subdev_internal_ops rcar_csi2_internal_ops = { > > + .init_state = rcsi2_init_state, > > +}; > > + > > static irqreturn_t rcsi2_irq(int irq, void *data) > > { > > struct rcar_csi2 *priv = data; > > @@ -1887,11 +1946,13 @@ static int rcsi2_probe(struct platform_device *pdev) > > > > priv->subdev.owner = THIS_MODULE; > > priv->subdev.dev = &pdev->dev; > > + priv->subdev.internal_ops = &rcar_csi2_internal_ops; > > v4l2_subdev_init(&priv->subdev, &rcar_csi2_subdev_ops); > > v4l2_set_subdevdata(&priv->subdev, &pdev->dev); > > snprintf(priv->subdev.name, sizeof(priv->subdev.name), "%s %s", > > KBUILD_MODNAME, dev_name(&pdev->dev)); > > - priv->subdev.flags = V4L2_SUBDEV_FL_HAS_DEVNODE; > > + priv->subdev.flags = V4L2_SUBDEV_FL_HAS_DEVNODE | > > + V4L2_SUBDEV_FL_STREAMS; > > > > priv->subdev.entity.function = MEDIA_ENT_F_PROC_VIDEO_PIXEL_FORMATTER; > > priv->subdev.entity.ops = &rcar_csi2_entity_ops; > > @@ -1912,14 +1973,22 @@ static int rcsi2_probe(struct platform_device *pdev) > > > > pm_runtime_enable(&pdev->dev); > > > > + ret = v4l2_subdev_init_finalize(&priv->subdev); > > + if (ret) > > + goto error_pm_runtime; > > + > > ret = v4l2_async_register_subdev(&priv->subdev); > > if (ret < 0) > > - goto error_async; > > + goto error_subdev; > > > > dev_info(priv->dev, "%d lanes found\n", priv->lanes); > > > > return 0; > > > > +error_subdev: > > + v4l2_subdev_cleanup(&priv->subdev); > > +error_pm_runtime: > > + pm_runtime_disable(&pdev->dev); > > error_async: > > v4l2_async_nf_unregister(&priv->notifier); > > v4l2_async_nf_cleanup(&priv->notifier); > > @@ -1936,6 +2005,7 @@ static void rcsi2_remove(struct platform_device *pdev) > > v4l2_async_nf_unregister(&priv->notifier); > > v4l2_async_nf_cleanup(&priv->notifier); > > v4l2_async_unregister_subdev(&priv->subdev); > > + v4l2_subdev_cleanup(&priv->subdev); > > > > pm_runtime_disable(&pdev->dev); > > -- Regards, Laurent Pinchart