Re: [PATCH] media: i2c: ov5645: add HAS_EVENTS supporty

From: Tommaso Merciai
Date: Tue Oct 15 2024 - 12:38:13 EST


Hi Laurent,
Back on the topic.

On Tue, Oct 15, 2024 at 08:16:13AM +0200, Tommaso Merciai wrote:
> Hi Laurent,
> Thanks for your review.
>
> On Mon, Oct 14, 2024 at 08:54:52PM +0300, Laurent Pinchart wrote:
> > Hi Tommaso,
> >
> > Thank you for the patch.
> >
> > On Mon, Oct 14, 2024 at 07:38:40PM +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.
> > > Add missing HAS_EVENTS support: flag and .(un)subscribe_event().
> > >
> > > Signed-off-by: Tommaso Merciai <tomm.merciai@xxxxxxxxx>
> > > ---
> > > drivers/media/i2c/ov5645.c | 10 +++++++++-
> > > 1 file changed, 9 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c
> > > index 0c32bd2940ec..2c5145d5c616 100644
> > > --- a/drivers/media/i2c/ov5645.c
> > > +++ b/drivers/media/i2c/ov5645.c
> > > @@ -29,6 +29,7 @@
> > > #include <linux/slab.h>
> > > #include <linux/types.h>
> > > #include <media/v4l2-ctrls.h>
> > > +#include <media/v4l2-event.h>
> > > #include <media/v4l2-fwnode.h>
> > > #include <media/v4l2-subdev.h>
> > >
> > > @@ -1034,6 +1035,11 @@ static const struct v4l2_subdev_video_ops ov5645_video_ops = {
> > > .s_stream = ov5645_s_stream,
> > > };
> > >
> > > +static const struct v4l2_subdev_core_ops ov5645_subdev_core_ops = {
> > > + .subscribe_event = v4l2_ctrl_subdev_subscribe_event,
> > > + .unsubscribe_event = v4l2_event_subdev_unsubscribe,
> > > +};
> > > +
> > > static const struct v4l2_subdev_pad_ops ov5645_subdev_pad_ops = {
> > > .enum_mbus_code = ov5645_enum_mbus_code,
> > > .enum_frame_size = ov5645_enum_frame_size,
> > > @@ -1043,6 +1049,7 @@ static const struct v4l2_subdev_pad_ops ov5645_subdev_pad_ops = {
> > > };
> > >
> > > static const struct v4l2_subdev_ops ov5645_subdev_ops = {
> > > + .core = &ov5645_subdev_core_ops,
> > > .video = &ov5645_video_ops,
> > > .pad = &ov5645_subdev_pad_ops,
> > > };
> > > @@ -1178,7 +1185,8 @@ static int ov5645_probe(struct i2c_client *client)
> > >
> > > v4l2_i2c_subdev_init(&ov5645->sd, client, &ov5645_subdev_ops);
> > > ov5645->sd.internal_ops = &ov5645_internal_ops;
> > > - ov5645->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
> > > + ov5645->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE |
> > > + V4L2_SUBDEV_FL_HAS_EVENTS;
> >
> > Instead of patching every subdev driver, should we handle all of this in
> > the subdev core ? If a control handler is set for the subdev, we could
> > set the HAS_EVENTS flag automatically, and default to
> > v4l2_ctrl_subdev_subscribe_event() and v4l2_event_subdev_unsubscribe()
> > if there are no control operations.

Premit:
- Don't know if I'm wrong eh.

This can be done into:

__v4l2_subdev_init_finalize()

Adding:

if (sd->ctrl_handler)
sd->flags |= V4L2_SUBDEV_FL_HAS_EVENTS;

And check if there are no control operations using:

bool has_subscribe_event;
bool has_unsubscribe_event;


has_subscribe_event = v4l2_subdev_has_op(sd, core, subscribe_event);
has_unsubscribe_event = v4l2_subdev_has_op(sd, core, unsubscribe_event);

if (!has_subscribe_event)
assign v4l2_ctrl_subdev_subscribe_event as default .subscribe ops(somehow)

if (!has_unsubscribe_event)
assign v4l2_event_subdev_unsubscribe as default .unsubscribe ops (somehow)


Or maybe v4l2_subdev_init_finalize() it's too late?
I'm completely wrong? What do you think?

Thanks in advance,
Tommaso

>
> Well :)
> Not every subdev drivers, but only the ones I'm testing.
>
> Yesterday I was playing with ov5645 :) And I got:
>
> v4l2-compliance -d /dev/v4l-subdev1
>
> test VIDIOC_G/S/TRY_EXT_CTRLS: OK
> fail: v4l2-test-controls.cpp(1108): subscribe event for control 'User Controls' failed
>
> Joke apart fully agree and thanks for your hint!
> I will take a look :)
>
> >
> > > ov5645->pad.flags = MEDIA_PAD_FL_SOURCE;
> > > ov5645->sd.dev = &client->dev;
> > > ov5645->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
> >
> > --
> > Regards,
> >
> > Laurent Pinchart
>
> Thanks & Regards,
> Tommaso