From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Tommaso Merciai <tomm.merciai@gmail.com>
Cc: sakari.ailus@linux.intel.com,
"Mauro Carvalho Chehab" <mchehab@kernel.org>,
"Hans Verkuil" <hverkuil@xs4all.nl>,
"Tomi Valkeinen" <tomi.valkeinen@ideasonboard.com>,
"Paweł Anikiel" <panikiel@google.com>,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] media: v4l2-subdev: Refactor events
Date: Sun, 20 Oct 2024 19:43:54 +0300 [thread overview]
Message-ID: <20241020164354.GG7770@pendragon.ideasonboard.com> (raw)
In-Reply-To: <20241020163534.1720297-1-tomm.merciai@gmail.com>
Hi Tommaso,
Thank you for the patch.
On Sun, Oct 20, 2024 at 06:35:32PM +0200, Tommaso Merciai wrote:
> Controls can be exposed to userspace via a v4l-subdevX device, and
> userspace has to be able to subscribe to control events so that it is
> notified when the control changes value.
> If a control handler is set for the subdev then set the HAS_EVENTS
> flag automatically into v4l2_subdev_init_finalize() and use
> v4l2_ctrl_subdev_subscribe_event() and v4l2_event_subdev_unsubscribe()
> as default if subdev don't have .(un)subscribe control operations.
I would add here
This simplifies subdev drivers by avoiding the need to set the
V4L2_SUBDEV_FL_HAS_EVENTS flag and plug the event handlers, and ensures
consistency of the API exposed to userspace.
And you can also add
Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Signed-off-by: Tommaso Merciai <tomm.merciai@gmail.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Now, can we simplify sensor drivers to drop the event handlers and the
flag ? :-)
> ---
> Changes since v1:
> - Aligned event subscription with unsubscription as suggested by LPinchart,
> SAilus
>
> drivers/media/v4l2-core/v4l2-subdev.c | 22 ++++++++++++++++++++--
> 1 file changed, 20 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
> index 3a4ba08810d2..fad8fa1f63e8 100644
> --- a/drivers/media/v4l2-core/v4l2-subdev.c
> +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> @@ -691,10 +691,25 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg,
> return v4l2_event_dequeue(vfh, arg, file->f_flags & O_NONBLOCK);
>
> case VIDIOC_SUBSCRIBE_EVENT:
> - return v4l2_subdev_call(sd, core, subscribe_event, vfh, arg);
> + if (v4l2_subdev_has_op(sd, core, subscribe_event))
> + return v4l2_subdev_call(sd, core, subscribe_event,
> + vfh, arg);
> +
> + if ((sd->flags & V4L2_SUBDEV_FL_HAS_EVENTS) &&
> + vfh->ctrl_handler)
> + return v4l2_ctrl_subdev_subscribe_event(sd, vfh, arg);
> +
> + return -ENOIOCTLCMD;
>
> case VIDIOC_UNSUBSCRIBE_EVENT:
> - return v4l2_subdev_call(sd, core, unsubscribe_event, vfh, arg);
> + if (v4l2_subdev_has_op(sd, core, unsubscribe_event))
> + return v4l2_subdev_call(sd, core, unsubscribe_event,
> + vfh, arg);
> +
> + if (sd->flags & V4L2_SUBDEV_FL_HAS_EVENTS)
> + return v4l2_event_subdev_unsubscribe(sd, vfh, arg);
> +
> + return -ENOIOCTLCMD;
>
> #ifdef CONFIG_VIDEO_ADV_DEBUG
> case VIDIOC_DBG_G_REGISTER:
> @@ -1641,6 +1656,9 @@ int __v4l2_subdev_init_finalize(struct v4l2_subdev *sd, const char *name,
> }
> }
>
> + if (sd->ctrl_handler)
> + sd->flags |= V4L2_SUBDEV_FL_HAS_EVENTS;
> +
> state = __v4l2_subdev_state_alloc(sd, name, key);
> if (IS_ERR(state))
> return PTR_ERR(state);
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2024-10-20 16:44 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-20 16:35 [PATCH v2] media: v4l2-subdev: Refactor events Tommaso Merciai
2024-10-20 16:43 ` Laurent Pinchart [this message]
2024-10-21 6:35 ` Tommaso Merciai
2024-10-21 7:30 ` Laurent Pinchart
2024-10-21 8:12 ` Tommaso Merciai
2024-10-28 17:32 ` Tommaso Merciai
2024-10-28 18:36 ` Laurent Pinchart
2024-10-29 6:42 ` Sakari Ailus
2024-10-21 7:26 ` Sakari Ailus
2024-10-21 8:16 ` Tommaso Merciai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241020164354.GG7770@pendragon.ideasonboard.com \
--to=laurent.pinchart@ideasonboard.com \
--cc=hverkuil@xs4all.nl \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=panikiel@google.com \
--cc=sakari.ailus@linux.intel.com \
--cc=tomi.valkeinen@ideasonboard.com \
--cc=tomm.merciai@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox