diff mbox series

[2/4] rcar-vin: Route events to correct video device

Message ID 20201112225147.1672622-3-niklas.soderlund+renesas@ragnatech.se (mailing list archive)
State New, archived
Headers show
Series rcar-csi2: Update handling of transfer error | expand

Commit Message

Niklas Söderlund Nov. 12, 2020, 10:51 p.m. UTC
The event route for VIN running with a media controller (Gen3) is
incorrect as all events are only routed to the video device that are
used to register the async notifier.

Remedy this be examining which subdevice generated the event and route
it to all VIN(s) that are connected to that subdevice.

Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
---
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 44 ++++++++++++++++++---
 1 file changed, 38 insertions(+), 6 deletions(-)

Comments

Jacopo Mondi Nov. 16, 2020, 4:54 p.m. UTC | #1
Hi Niklas,

On Thu, Nov 12, 2020 at 11:51:45PM +0100, Niklas Söderlund wrote:
> The event route for VIN running with a media controller (Gen3) is
> incorrect as all events are only routed to the video device that are
> used to register the async notifier.
>
> Remedy this be examining which subdevice generated the event and route
> it to all VIN(s) that are connected to that subdevice.
>
> Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>

This was easy to miss indeed!

Reviewed-by: Jacopo Mondi <jacopo+renesas@jmondi.org>

Thanks
  j

> ---
>  drivers/media/platform/rcar-vin/rcar-v4l2.c | 44 ++++++++++++++++++---
>  1 file changed, 38 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c b/drivers/media/platform/rcar-vin/rcar-v4l2.c
> index 3e7a3ae2a6b97045..dca3ab1656a66cef 100644
> --- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
> +++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
> @@ -966,18 +966,50 @@ void rvin_v4l2_unregister(struct rvin_dev *vin)
>  	video_unregister_device(&vin->vdev);
>  }
>
> +static void rvin_notify_video_device(struct rvin_dev *vin,
> +				     unsigned int notification, void *arg)
> +{
> +	switch (notification) {
> +	case V4L2_DEVICE_NOTIFY_EVENT:
> +		v4l2_event_queue(&vin->vdev, arg);
> +		break;
> +	default:
> +		break;
> +	}
> +}
> +
>  static void rvin_notify(struct v4l2_subdev *sd,
>  			unsigned int notification, void *arg)
>  {
> +	struct v4l2_subdev *remote;
> +	struct rvin_group *group;
> +	struct media_pad *pad;
>  	struct rvin_dev *vin =
>  		container_of(sd->v4l2_dev, struct rvin_dev, v4l2_dev);
> +	unsigned int i;
>
> -	switch (notification) {
> -	case V4L2_DEVICE_NOTIFY_EVENT:
> -		v4l2_event_queue(&vin->vdev, arg);
> -		break;
> -	default:
> -		break;
> +	/* If no media controller, no need to route the event. */
> +	if (!vin->info->use_mc) {
> +		rvin_notify_video_device(vin, notification, arg);
> +		return;
> +	}
> +
> +	group = vin->group;
> +
> +	for (i = 0; i < RCAR_VIN_NUM; i++) {
> +		vin = group->vin[i];
> +		if (!vin)
> +			continue;
> +
> +		pad = media_entity_remote_pad(&vin->pad);
> +		if (!pad)
> +			continue;
> +
> +		remote = media_entity_to_v4l2_subdev(pad->entity);
> +		if (remote != sd)
> +			continue;
> +
> +		rvin_notify_video_device(vin, notification, arg);
>  	}
>  }
>
> --
> 2.29.2
>
diff mbox series

Patch

diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c b/drivers/media/platform/rcar-vin/rcar-v4l2.c
index 3e7a3ae2a6b97045..dca3ab1656a66cef 100644
--- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
+++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
@@ -966,18 +966,50 @@  void rvin_v4l2_unregister(struct rvin_dev *vin)
 	video_unregister_device(&vin->vdev);
 }
 
+static void rvin_notify_video_device(struct rvin_dev *vin,
+				     unsigned int notification, void *arg)
+{
+	switch (notification) {
+	case V4L2_DEVICE_NOTIFY_EVENT:
+		v4l2_event_queue(&vin->vdev, arg);
+		break;
+	default:
+		break;
+	}
+}
+
 static void rvin_notify(struct v4l2_subdev *sd,
 			unsigned int notification, void *arg)
 {
+	struct v4l2_subdev *remote;
+	struct rvin_group *group;
+	struct media_pad *pad;
 	struct rvin_dev *vin =
 		container_of(sd->v4l2_dev, struct rvin_dev, v4l2_dev);
+	unsigned int i;
 
-	switch (notification) {
-	case V4L2_DEVICE_NOTIFY_EVENT:
-		v4l2_event_queue(&vin->vdev, arg);
-		break;
-	default:
-		break;
+	/* If no media controller, no need to route the event. */
+	if (!vin->info->use_mc) {
+		rvin_notify_video_device(vin, notification, arg);
+		return;
+	}
+
+	group = vin->group;
+
+	for (i = 0; i < RCAR_VIN_NUM; i++) {
+		vin = group->vin[i];
+		if (!vin)
+			continue;
+
+		pad = media_entity_remote_pad(&vin->pad);
+		if (!pad)
+			continue;
+
+		remote = media_entity_to_v4l2_subdev(pad->entity);
+		if (remote != sd)
+			continue;
+
+		rvin_notify_video_device(vin, notification, arg);
 	}
 }