media: i2c: ov5645: add HAS_EVENTS support
Subsystems (2)
PATCH 1/1 media: i2c: ov5645: add HAS_EVENTS support
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().
--- drivers/media/i2c/ov5645.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/media/i2c/ov5645.c +9 -1
@@ -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 ; ov5645->pad.flags =MEDIA_PAD_FL_SOURCE ; ov5645->sd.dev = &client->dev; ov5645->sd.entity.function =MEDIA_ENT_F_CAM_SENSOR ;
Signature · 1 line
2.34.1
Hi Tommaso,
Thank you for the patch.
Quoted 43 lines · Tommaso Merciai
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 missingHAS_EVENTSsupport: flag and .(un)subscribe_event().Signed-off-by Tommaso Merciai <[email protected]>--- drivers/media/i2c/ov5645.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)drivers/media/i2c/ov5645.c +7
-0@@ -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, };
drivers/media/i2c/ov5645.c static int ov5645_probe(struct i2c_client *client) · line 1189
Quoted 6 lines
drivers/media/i2c/ov5645.c +2
-1@@ -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.
Quoted 3 lines
drivers/media/i2c/ov5645.c +0
-0ov5645->pad.flags =MEDIA_PAD_FL_SOURCE ; ov5645->sd.dev = &client->dev; ov5645->sd.entity.function =MEDIA_ENT_F_CAM_SENSOR ;
Signature · 3 lines
Regards, Laurent Pinchart
Hi Laurent,
Thanks for your review.
Quoted 49 lines · Laurent Pinchart
Hi Tommaso,
Thank you for the patch.
Quoted 44 lines · Tommaso Merciai
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 missingHAS_EVENTSsupport: flag and .(un)subscribe_event().Signed-off-by Tommaso Merciai <[email protected]>--- drivers/media/i2c/ov5645.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)drivers/media/i2c/ov5645.c +7
-0@@ -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)
Quoted 11 lines
drivers/media/i2c/ov5645.c static int ov5645_probe(struct i2c_client *client) · line 1189
Quoted 5 lines
drivers/media/i2c/ov5645.c +2
-1v4l2_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_EVENTSflag automatically, and default tov4l2_ctrl_subdev_subscribe_event()andv4l2_event_subdev_unsubscribe()if there are no control operations.
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 :)
Quoted 9 lines
Quoted 4 lines
drivers/media/i2c/ov5645.c +0
-0ov5645->pad.flags =MEDIA_PAD_FL_SOURCE ; ov5645->sd.dev = &client->dev; ov5645->sd.entity.function =MEDIA_ENT_F_CAM_SENSOR ;Signature · 3 lines
Regards, Laurent Pinchart
Thanks & Regards,
Tommaso
Re: [PATCH] media: i2c: ov5645: add HAS_EVENTS supporty
Hi Laurent,
Back on the topic.
Quoted 64 lines · Tommaso Merciai
Hi Laurent,
Thanks for your review.Quoted 60 lines · Laurent Pinchart
Hi Tommaso,
Thank you for the patch.
Quoted 43 lines · Tommaso Merciai
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 missingHAS_EVENTSsupport: flag and .(un)subscribe_event().Signed-off-by Tommaso Merciai <[email protected]>--- drivers/media/i2c/ov5645.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)drivers/media/i2c/ov5645.c +7
-0@@ -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, };drivers/media/i2c/ov5645.c static int ov5645_probe(struct i2c_client *client) · line 1189
Quoted 6 lines
drivers/media/i2c/ov5645.c +2
-1@@ -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_EVENTSflag automatically, and default tov4l2_ctrl_subdev_subscribe_event()andv4l2_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
Quoted 26 lines
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-subdev1test VIDIOC_G/S/TRY_EXT_CTRLS: OK
fail: v4l2-test-controls.cpp(1108): subscribe event for control 'User Controls' failedJoke apart fully agree and thanks for your hint!
I will take a look :)Quoted 9 lines
Quoted 4 lines
drivers/media/i2c/ov5645.c +0
-0ov5645->pad.flags =MEDIA_PAD_FL_SOURCE ; ov5645->sd.dev = &client->dev; ov5645->sd.entity.function =MEDIA_ENT_F_CAM_SENSOR ;Signature · 3 lines
Regards, Laurent PinchartThanks & Regards,
Tommaso
Re: [PATCH] media: i2c: ov5645: add HAS_EVENTS supporty
Hi Tommaso,
Quoted 59 lines · Tommaso Merciai
Quoted 46 lines · Tommaso Merciai
Quoted 45 lines · Laurent Pinchart
Quoted 44 lines · Tommaso Merciai
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 missingHAS_EVENTSsupport: flag and .(un)subscribe_event().Signed-off-by Tommaso Merciai <[email protected]>--- drivers/media/i2c/ov5645.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)drivers/media/i2c/ov5645.c +7
-0@@ -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)Quoted 11 lines
Quoted 11 lines
drivers/media/i2c/ov5645.c static int ov5645_probe(struct i2c_client *client) · line 1189
Quoted 5 lines
drivers/media/i2c/ov5645.c +2
-1v4l2_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_EVENTSflag automatically, and default tov4l2_ctrl_subdev_subscribe_event()andv4l2_event_subdev_unsubscribe()if there are no control operations.
Quoted 2 lines
Premit:
- Don't know if I'm wrong eh.
Nobody knows :-)
Quoted 15 lines
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;
boolhas_unsubscribe_event;
Quoted 5 lines
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)
assignv4l2_ctrl_subdev_subscribe_eventas default .subscribe ops(somehow)
We can't change the ops structure as it's constant. Something like this could do:
drivers/media/v4l2-core/v4l2-subdev.c +16 -2
@@ -691,10 +691,24 @@ 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); +else if ((sd->flags &V4L2_SUBDEV_FL_HAS_EVENTS ) && + vfh->ctrl_handler) +return v4l2_ctrl_subdev_subscribe_event (sd, vfh, arg); +else +return -ENOIOCTLCMD ;case VIDIOC_UNSUBSCRIBE_EVENT : -return v4l2_subdev_call (sd, core, unsubscribe_event, vfh, arg); +if (!(sd->flags &V4L2_SUBDEV_FL_HAS_EVENTS )) +return -ENOIOCTLCMD ; + +if (v4l2_subdev_has_op (sd, core, unsubscribe_event)) +return v4l2_subdev_call (sd, core, unsubscribe_event, + vfh, arg); +else +return v4l2_event_subdev_unsubscribe (sd, vfh, sub);#ifdef CONFIG_VIDEO_ADV_DEBUG case VIDIOC_DBG_G_REGISTER :
Quoted 6 lines
if (!has_unsubscribe_event)
assignv4l2_event_subdev_unsubscribeas default .unsubscribe ops (somehow)Or maybe
v4l2_subdev_init_finalize()it's too late? I'm completely wrong? What do you think?
I like v4l2_subdev_init_finalize() as we're pushing all subdev drivers to use it, so it's an extra incentive.
Quoted 16 lines
Quoted 16 lines
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-subdev1test VIDIOC_G/S/TRY_EXT_CTRLS: OK
fail: v4l2-test-controls.cpp(1108): subscribe event for control 'User Controls' failedJoke apart fully agree and thanks for your hint!
I will take a look :)Quoted 3 lines
Quoted 3 lines
drivers/media/i2c/ov5645.c +0
-0ov5645->pad.flags =MEDIA_PAD_FL_SOURCE ; ov5645->sd.dev = &client->dev; ov5645->sd.entity.function =MEDIA_ENT_F_CAM_SENSOR ;
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH] media: i2c: ov5645: add HAS_EVENTS supporty
Hi Laurent,
Quoted 108 lines · Laurent Pinchart
Hi Tommaso,
Quoted 59 lines · Tommaso Merciai
Quoted 46 lines · Tommaso Merciai
Quoted 45 lines · Laurent Pinchart
Quoted 44 lines · Tommaso Merciai
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 missingHAS_EVENTSsupport: flag and .(un)subscribe_event().Signed-off-by Tommaso Merciai <[email protected]>--- drivers/media/i2c/ov5645.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)drivers/media/i2c/ov5645.c +7
-0@@ -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)Quoted 11 lines
Quoted 11 lines
drivers/media/i2c/ov5645.c static int ov5645_probe(struct i2c_client *client) · line 1189
Quoted 5 lines
drivers/media/i2c/ov5645.c +2
-1v4l2_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_EVENTSflag automatically, and default tov4l2_ctrl_subdev_subscribe_event()andv4l2_event_subdev_unsubscribe()if there are no control operations.Quoted 2 lines
Premit:
- Don't know if I'm wrong eh.Nobody knows :-)
Quoted 15 lines
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;
boolhas_unsubscribe_event;Quoted 5 lines
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)
assignv4l2_ctrl_subdev_subscribe_eventas default .subscribe ops(somehow)We can't change the ops structure as it's constant. Something like this could do:
drivers/media/v4l2-core/v4l2-subdev.c +8
-1@@ -691,10 +691,24 @@ 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); +else if ((sd->flags &V4L2_SUBDEV_FL_HAS_EVENTS ) && + vfh->ctrl_handler) +return v4l2_ctrl_subdev_subscribe_event (sd, vfh, arg); +else +return -ENOIOCTLCMD ;
drivers/media/v4l2-core/v4l2-subdev.c static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg, · line 710
Quoted 10 lines
drivers/media/v4l2-core/v4l2-subdev.c +7
-1case VIDIOC_UNSUBSCRIBE_EVENT : -return v4l2_subdev_call (sd, core, unsubscribe_event, vfh, arg); +if (!(sd->flags &V4L2_SUBDEV_FL_HAS_EVENTS )) +return -ENOIOCTLCMD ; + +if (v4l2_subdev_has_op (sd, core, unsubscribe_event)) +return v4l2_subdev_call (sd, core, unsubscribe_event, + vfh, arg); +else
+ return v4l2_event_subdev_unsubscribe(sd, vfh, arg);
Thanks for your "more than an hint :)"
I'm able to test this on ov5645:
Adding:
+++ b/drivers/media/i2c/ov5645.c
@@ -1238,6 +1238,12 @@ static int ov5645_probe(struct i2c_client *client)
ov5645_init_state(&ov5645->sd, NULL);
+ ret = v4l2_subdev_init_finalize(&ov5645->sd);
+ if (ret < 0) {
+ dev_err(dev, "subdev initialization error %d\n", ret);
+ goto err_free_state;
+ }
+
ret = v4l2_async_register_subdev(&ov5645->sd);
if (ret < 0) {
dev_err(dev, "could not register v4l2 device\n");@@ -1251,6 +1257,8 @@ static int ov5645_probe(struct i2c_client *client)
return 0;
+err_free_state:
+ v4l2_subdev_cleanup(&ov5645->sd);
err_pm_runtime:
pm_runtime_disable(dev);
pm_runtime_put_noidle(dev);@@ -1272,6 +1280,7 @@ static void ov5645_remove(struct i2c_client *client)
v4l2_async_unregister_subdev(&ov5645->sd);
media_entity_cleanup(&ov5645->sd.entity);
+ v4l2_subdev_cleanup(&ov5645->sd);
v4l2_ctrl_handler_free(&ov5645->ctrls);
pm_runtime_disable(ov5645->dev);
if (!pm_runtime_status_suspended(ov5645->dev))Then from the compliance tool I'm getting now good results:
Total for device /dev/v4l-subdev1: 44, Succeeded: 44, Failed: 0, Warnings: 0
I will send these 2 patches later if you agree (1 v4l2-subdev 1 ov5645.c) Thanks again.
Regards,
Tommaso
Quoted 35 lines
drivers/media/v4l2-core/v4l2-subdev.c +0
-0#ifdef CONFIG_VIDEO_ADV_DEBUG case VIDIOC_DBG_G_REGISTER :Quoted 6 lines
if (!has_unsubscribe_event)
assignv4l2_event_subdev_unsubscribeas default .unsubscribe ops (somehow)Or maybe
v4l2_subdev_init_finalize()it's too late? I'm completely wrong? What do you think?I like
v4l2_subdev_init_finalize()as we're pushing all subdev drivers to use it, so it's an extra incentive.Quoted 16 lines
Quoted 16 lines
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-subdev1test VIDIOC_G/S/TRY_EXT_CTRLS: OK
fail: v4l2-test-controls.cpp(1108): subscribe event for control 'User Controls' failedJoke apart fully agree and thanks for your hint!
I will take a look :)Quoted 3 lines
Quoted 3 lines
drivers/media/i2c/ov5645.c +0
-0ov5645->pad.flags =MEDIA_PAD_FL_SOURCE ; ov5645->sd.dev = &client->dev; ov5645->sd.entity.function =MEDIA_ENT_F_CAM_SENSOR ;Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH] media: i2c: ov5645: add HAS_EVENTS supporty
Hi Tommaso,
Quoted 161 lines · Tommaso Merciai
Hi Laurent,
Quoted 108 lines · Laurent Pinchart
Hi Tommaso,
Quoted 59 lines · Tommaso Merciai
Quoted 46 lines · Tommaso Merciai
Quoted 45 lines · Laurent Pinchart
Quoted 44 lines · Tommaso Merciai
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 missingHAS_EVENTSsupport: flag and .(un)subscribe_event().Signed-off-by Tommaso Merciai <[email protected]>--- drivers/media/i2c/ov5645.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)drivers/media/i2c/ov5645.c +7
-0@@ -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)Quoted 11 lines
Quoted 11 lines
drivers/media/i2c/ov5645.c static int ov5645_probe(struct i2c_client *client) · line 1189
Quoted 5 lines
drivers/media/i2c/ov5645.c +2
-1v4l2_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_EVENTSflag automatically, and default tov4l2_ctrl_subdev_subscribe_event()andv4l2_event_subdev_unsubscribe()if there are no control operations.Quoted 2 lines
Premit:
- Don't know if I'm wrong eh.Nobody knows :-)
Quoted 15 lines
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;
boolhas_unsubscribe_event;Quoted 5 lines
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)
assignv4l2_ctrl_subdev_subscribe_eventas default .subscribe ops(somehow)We can't change the ops structure as it's constant. Something like this could do:
drivers/media/v4l2-core/v4l2-subdev.c +8
-1@@ -691,10 +691,24 @@ 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); +else if ((sd->flags &V4L2_SUBDEV_FL_HAS_EVENTS ) && + vfh->ctrl_handler) +return v4l2_ctrl_subdev_subscribe_event (sd, vfh, arg); +else +return -ENOIOCTLCMD ;drivers/media/v4l2-core/v4l2-subdev.c static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg, · line 710
Quoted 10 lines
drivers/media/v4l2-core/v4l2-subdev.c +7
-1case VIDIOC_UNSUBSCRIBE_EVENT : -return v4l2_subdev_call (sd, core, unsubscribe_event, vfh, arg); +if (!(sd->flags &V4L2_SUBDEV_FL_HAS_EVENTS )) +return -ENOIOCTLCMD ; + +if (v4l2_subdev_has_op (sd, core, unsubscribe_event)) +return v4l2_subdev_call (sd, core, unsubscribe_event, + vfh, arg); +else + return
v4l2_event_subdev_unsubscribe(sd, vfh, arg);Thanks for your "more than an hint :)"
I'm able to test this on ov5645:Adding:
+++
b/drivers/media/i2c/ov5645.c(quoted diff) +9
-0@@ -1238,6 +1238,12 @@ static int ov5645_probe(struct i2c_client *client) ov5645_init_state(&ov5645->sd, NULL); + ret = v4l2_subdev_init_finalize(&ov5645->sd); + if (ret < 0) { + dev_err(dev, "subdev initialization error %d\n", ret); + goto err_free_state; + } + ret = v4l2_async_register_subdev(&ov5645->sd); if (ret < 0) { dev_err(dev, "could not register v4l2 device\n");@@ -1251,6 +1257,8 @@ static int ov5645_probe(struct i2c_client *client) return 0; +err_free_state: + v4l2_subdev_cleanup(&ov5645->sd); err_pm_runtime: pm_runtime_disable(dev); pm_runtime_put_noidle(dev);@@ -1272,6 +1280,7 @@ static void ov5645_remove(struct i2c_client *client) v4l2_async_unregister_subdev(&ov5645->sd); media_entity_cleanup(&ov5645->sd.entity); + v4l2_subdev_cleanup(&ov5645->sd); v4l2_ctrl_handler_free(&ov5645->ctrls); pm_runtime_disable(ov5645->dev); if (!pm_runtime_status_suspended(ov5645->dev))
Quoted 7 lines
Then from the compliance tool I'm getting now good results:
Total for device
/dev/v4l-subdev1: 44, Succeeded: 44, Failed: 0, Warnings: 0I will send these 2 patches later if you agree (1 v4l2-subdev 1
ov5645.c) Thanks again.
Thank you for the patch.
I am currently working on adding support for V4L2_SUBDEV_FL_HAS_EVENTS and subscribe hooks[1] (and some more features [0] for ov5645 driver), since the patch series adds internal pad which needs rework based on patch series from Sakari which I will do soon and send v3 patches for ov5645 driver.
[0] https://lore.kernel.org/all/[email protected]/
[1] https://lore.kernel.org/all/[email protected]/
Cheers,
Prabhakar
Re: [PATCH] media: i2c: ov5645: add HAS_EVENTS supporty
Hi Prabhakar,
Thanks for your comments.
Quoted 173 lines · Prabhakar
Hi Tommaso,
Quoted 161 lines · Tommaso Merciai
Hi Laurent,
Quoted 108 lines · Laurent Pinchart
Hi Tommaso,
Quoted 59 lines · Tommaso Merciai
Quoted 46 lines · Tommaso Merciai
Quoted 45 lines · Laurent Pinchart
Quoted 44 lines · Tommaso Merciai
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 missingHAS_EVENTSsupport: flag and .(un)subscribe_event().Signed-off-by Tommaso Merciai <[email protected]>--- drivers/media/i2c/ov5645.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)drivers/media/i2c/ov5645.c +7
-0@@ -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)Quoted 11 lines
Quoted 11 lines
drivers/media/i2c/ov5645.c static int ov5645_probe(struct i2c_client *client) · line 1189
Quoted 5 lines
drivers/media/i2c/ov5645.c +2
-1v4l2_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_EVENTSflag automatically, and default tov4l2_ctrl_subdev_subscribe_event()andv4l2_event_subdev_unsubscribe()if there are no control operations.Quoted 2 lines
Premit:
- Don't know if I'm wrong eh.Nobody knows :-)
Quoted 15 lines
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;
boolhas_unsubscribe_event;Quoted 5 lines
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)
assignv4l2_ctrl_subdev_subscribe_eventas default .subscribe ops(somehow)We can't change the ops structure as it's constant. Something like this could do:
drivers/media/v4l2-core/v4l2-subdev.c +8
-1@@ -691,10 +691,24 @@ 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); +else if ((sd->flags &V4L2_SUBDEV_FL_HAS_EVENTS ) && + vfh->ctrl_handler) +return v4l2_ctrl_subdev_subscribe_event (sd, vfh, arg); +else +return -ENOIOCTLCMD ;drivers/media/v4l2-core/v4l2-subdev.c static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg, · line 710
Quoted 10 lines
drivers/media/v4l2-core/v4l2-subdev.c +7
-1case VIDIOC_UNSUBSCRIBE_EVENT : -return v4l2_subdev_call (sd, core, unsubscribe_event, vfh, arg); +if (!(sd->flags &V4L2_SUBDEV_FL_HAS_EVENTS )) +return -ENOIOCTLCMD ; + +if (v4l2_subdev_has_op (sd, core, unsubscribe_event)) +return v4l2_subdev_call (sd, core, unsubscribe_event, + vfh, arg); +else + return
v4l2_event_subdev_unsubscribe(sd, vfh, arg);Thanks for your "more than an hint :)"
I'm able to test this on ov5645:Adding:
+++
b/drivers/media/i2c/ov5645.c(quoted diff) +9
-0@@ -1238,6 +1238,12 @@ static int ov5645_probe(struct i2c_client *client) ov5645_init_state(&ov5645->sd, NULL); + ret = v4l2_subdev_init_finalize(&ov5645->sd); + if (ret < 0) { + dev_err(dev, "subdev initialization error %d\n", ret); + goto err_free_state; + } + ret = v4l2_async_register_subdev(&ov5645->sd); if (ret < 0) { dev_err(dev, "could not register v4l2 device\n");@@ -1251,6 +1257,8 @@ static int ov5645_probe(struct i2c_client *client) return 0; +err_free_state: + v4l2_subdev_cleanup(&ov5645->sd); err_pm_runtime: pm_runtime_disable(dev); pm_runtime_put_noidle(dev);@@ -1272,6 +1280,7 @@ static void ov5645_remove(struct i2c_client *client) v4l2_async_unregister_subdev(&ov5645->sd); media_entity_cleanup(&ov5645->sd.entity); + v4l2_subdev_cleanup(&ov5645->sd); v4l2_ctrl_handler_free(&ov5645->ctrls); pm_runtime_disable(ov5645->dev); if (!pm_runtime_status_suspended(ov5645->dev))Quoted 7 lines
Then from the compliance tool I'm getting now good results:
Total for device
/dev/v4l-subdev1: 44, Succeeded: 44, Failed: 0, Warnings: 0I will send these 2 patches later if you agree (1 v4l2-subdev 1
ov5645.c) Thanks again.Thank you for the patch.
Quoted 8 lines
I am currently working on adding support for
V4L2_SUBDEV_FL_HAS_EVENTSand subscribe hooks[1] (and some more features [0] for ov5645 driver), since the patch series adds internal pad which needs rework based on patch series from Sakari which I will do soon and send v3 patches for ov5645 driver.[0] https://lore.kernel.org/all/[email protected]/
[1] https://lore.kernel.org/all/[email protected]/
Thanks for sharing this.
Nice! then I can drop ov5645 patch and send only v4l2-subdev patch :)
Plan as suggested by Laurent is:
"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"
Using:
drivers/media/v4l2-core/v4l2-subdev.c +19 -2
@@ -691,10 +691,24 @@ 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); +else if ((sd->flags &V4L2_SUBDEV_FL_HAS_EVENTS ) && + vfh->ctrl_handler) +return v4l2_ctrl_subdev_subscribe_event (sd, vfh, arg); +else +return -ENOIOCTLCMD ;case VIDIOC_UNSUBSCRIBE_EVENT : -return v4l2_subdev_call (sd, core, unsubscribe_event, vfh, arg); +if (!(sd->flags &V4L2_SUBDEV_FL_HAS_EVENTS )) +return -ENOIOCTLCMD ; + +if (v4l2_subdev_has_op (sd, core, unsubscribe_event)) +return v4l2_subdev_call (sd, core, unsubscribe_event, + vfh, arg); +else +return v4l2_event_subdev_unsubscribe (sd, vfh, arg);#ifdef CONFIG_VIDEO_ADV_DEBUG case VIDIOC_DBG_G_REGISTER :
@@ -1641,6 +1655,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);
In theory v4l2_subdev_init_finalize() and subdev_do_ioctl() will handle this.
Please Laurent correct me if I'm wrong.
Prabhakar what do you think?
Thanks in advance.
Regards,
Tommaso
Quoted 3 lines
Cheers,
Prabhakar
Sakari Ailus
maintainerRe: [PATCH] media: i2c: ov5645: add HAS_EVENTS supporty
Hi folks,
Quoted 204 lines · Tommaso Merciai
Hi Prabhakar,
Thanks for your comments.Quoted 173 lines · Prabhakar
Hi Tommaso,
Quoted 161 lines · Tommaso Merciai
Hi Laurent,
Quoted 108 lines · Laurent Pinchart
Hi Tommaso,
Quoted 59 lines · Tommaso Merciai
Quoted 46 lines · Tommaso Merciai
Quoted 45 lines · Laurent Pinchart
Quoted 44 lines · Tommaso Merciai
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 missingHAS_EVENTSsupport: flag and .(un)subscribe_event().Signed-off-by Tommaso Merciai <[email protected]>--- drivers/media/i2c/ov5645.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)drivers/media/i2c/ov5645.c +7
-0@@ -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)Quoted 11 lines
Quoted 11 lines
drivers/media/i2c/ov5645.c static int ov5645_probe(struct i2c_client *client) · line 1189
Quoted 5 lines
drivers/media/i2c/ov5645.c +2
-1v4l2_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_EVENTSflag automatically, and default tov4l2_ctrl_subdev_subscribe_event()andv4l2_event_subdev_unsubscribe()if there are no control operations.Quoted 2 lines
Premit:
- Don't know if I'm wrong eh.Nobody knows :-)
Quoted 15 lines
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;
boolhas_unsubscribe_event;Quoted 5 lines
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)
assignv4l2_ctrl_subdev_subscribe_eventas default .subscribe ops(somehow)We can't change the ops structure as it's constant. Something like this could do:
drivers/media/v4l2-core/v4l2-subdev.c +8
-1@@ -691,10 +691,24 @@ 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); +else if ((sd->flags &V4L2_SUBDEV_FL_HAS_EVENTS ) && + vfh->ctrl_handler) +return v4l2_ctrl_subdev_subscribe_event (sd, vfh, arg); +else +return -ENOIOCTLCMD ;drivers/media/v4l2-core/v4l2-subdev.c static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg, · line 710
Quoted 10 lines
drivers/media/v4l2-core/v4l2-subdev.c +7
-1case VIDIOC_UNSUBSCRIBE_EVENT : -return v4l2_subdev_call (sd, core, unsubscribe_event, vfh, arg); +if (!(sd->flags &V4L2_SUBDEV_FL_HAS_EVENTS )) +return -ENOIOCTLCMD ; + +if (v4l2_subdev_has_op (sd, core, unsubscribe_event)) +return v4l2_subdev_call (sd, core, unsubscribe_event, + vfh, arg); +else + return
v4l2_event_subdev_unsubscribe(sd, vfh, arg);Thanks for your "more than an hint :)"
I'm able to test this on ov5645:Adding:
+++
b/drivers/media/i2c/ov5645.c(quoted diff) +9
-0@@ -1238,6 +1238,12 @@ static int ov5645_probe(struct i2c_client *client) ov5645_init_state(&ov5645->sd, NULL); + ret = v4l2_subdev_init_finalize(&ov5645->sd); + if (ret < 0) { + dev_err(dev, "subdev initialization error %d\n", ret); + goto err_free_state; + } + ret = v4l2_async_register_subdev(&ov5645->sd); if (ret < 0) { dev_err(dev, "could not register v4l2 device\n");@@ -1251,6 +1257,8 @@ static int ov5645_probe(struct i2c_client *client) return 0; +err_free_state: + v4l2_subdev_cleanup(&ov5645->sd); err_pm_runtime: pm_runtime_disable(dev); pm_runtime_put_noidle(dev);@@ -1272,6 +1280,7 @@ static void ov5645_remove(struct i2c_client *client) v4l2_async_unregister_subdev(&ov5645->sd); media_entity_cleanup(&ov5645->sd.entity); + v4l2_subdev_cleanup(&ov5645->sd); v4l2_ctrl_handler_free(&ov5645->ctrls); pm_runtime_disable(ov5645->dev); if (!pm_runtime_status_suspended(ov5645->dev))Quoted 7 lines
Then from the compliance tool I'm getting now good results:
Total for device
/dev/v4l-subdev1: 44, Succeeded: 44, Failed: 0, Warnings: 0I will send these 2 patches later if you agree (1 v4l2-subdev 1
ov5645.c) Thanks again.Thank you for the patch.
Quoted 8 lines
I am currently working on adding support for
V4L2_SUBDEV_FL_HAS_EVENTSand subscribe hooks[1] (and some more features [0] for ov5645 driver), since the patch series adds internal pad which needs rework based on patch series from Sakari which I will do soon and send v3 patches for ov5645 driver.[0] https://lore.kernel.org/all/[email protected]/
[1] https://lore.kernel.org/all/[email protected]/Thanks for sharing this.
Nice! then I can drop ov5645 patch and send only v4l2-subdev patch :)Plan as suggested by Laurent is:
"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_EVENTSflag automatically, and default tov4l2_ctrl_subdev_subscribe_event()andv4l2_event_subdev_unsubscribe()if there are no control operations"Using:
drivers/media/v4l2-core/v4l2-subdev.c +0
-0
drivers/media/v4l2-core/v4l2-subdev.c static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg, · line 697
Quoted 8 lines
drivers/media/v4l2-core/v4l2-subdev.c +4
-1@@ -691,10 +691,24 @@ 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); + else if ((sd->flags & V4L2_SUBDEV_FL_HAS_EVENTS) &&
Useless use of else. Same below.
Quoted 29 lines
drivers/media/v4l2-core/v4l2-subdev.c +15
-1+ vfh->ctrl_handler) + return v4l2_ctrl_subdev_subscribe_event(sd, vfh, arg); + else + return -ENOIOCTLCMD;case VIDIOC_UNSUBSCRIBE_EVENT : -return v4l2_subdev_call (sd, core, unsubscribe_event, vfh, arg); +if (!(sd->flags &V4L2_SUBDEV_FL_HAS_EVENTS )) +return -ENOIOCTLCMD ; + +if (v4l2_subdev_has_op (sd, core, unsubscribe_event)) +return v4l2_subdev_call (sd, core, unsubscribe_event, + vfh, arg); +else +return v4l2_event_subdev_unsubscribe (sd, vfh, arg);#ifdef CONFIG_VIDEO_ADV_DEBUG case VIDIOC_DBG_G_REGISTER :@@ -1641,6 +1655,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);
Quoted 6 lines
In theory
v4l2_subdev_init_finalize()andsubdev_do_ioctl()will handle this.Please Laurent correct me if I'm wrong.
Prabhakar what do you think?
Thanks in advance.
Looks good to me, with the above comment.
Signature · 3 lines
Kind regards, Sakari Ailus
Re: [PATCH] media: i2c: ov5645: add HAS_EVENTS supporty
Hi Sakari,
Thanks for your review.
Quoted 209 lines · Sakari Ailus
Hi folks,
Quoted 206 lines · Tommaso Merciai
Hi Prabhakar,
Thanks for your comments.Quoted 173 lines · Prabhakar
Hi Tommaso,
Quoted 161 lines · Tommaso Merciai
Hi Laurent,
Quoted 108 lines · Laurent Pinchart
Hi Tommaso,
Quoted 59 lines · Tommaso Merciai
Quoted 46 lines · Tommaso Merciai
Quoted 45 lines · Laurent Pinchart
Quoted 44 lines · Tommaso Merciai
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 missingHAS_EVENTSsupport: flag and .(un)subscribe_event().Signed-off-by Tommaso Merciai <[email protected]>--- drivers/media/i2c/ov5645.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)drivers/media/i2c/ov5645.c +7
-0@@ -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)Quoted 11 lines
Quoted 11 lines
drivers/media/i2c/ov5645.c static int ov5645_probe(struct i2c_client *client) · line 1189
Quoted 5 lines
drivers/media/i2c/ov5645.c +2
-1v4l2_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_EVENTSflag automatically, and default tov4l2_ctrl_subdev_subscribe_event()andv4l2_event_subdev_unsubscribe()if there are no control operations.Quoted 2 lines
Premit:
- Don't know if I'm wrong eh.Nobody knows :-)
Quoted 15 lines
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;
boolhas_unsubscribe_event;Quoted 5 lines
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)
assignv4l2_ctrl_subdev_subscribe_eventas default .subscribe ops(somehow)We can't change the ops structure as it's constant. Something like this could do:
drivers/media/v4l2-core/v4l2-subdev.c +8
-1@@ -691,10 +691,24 @@ 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); +else if ((sd->flags &V4L2_SUBDEV_FL_HAS_EVENTS ) && + vfh->ctrl_handler) +return v4l2_ctrl_subdev_subscribe_event (sd, vfh, arg); +else +return -ENOIOCTLCMD ;drivers/media/v4l2-core/v4l2-subdev.c static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg, · line 710
Quoted 10 lines
drivers/media/v4l2-core/v4l2-subdev.c +7
-1case VIDIOC_UNSUBSCRIBE_EVENT : -return v4l2_subdev_call (sd, core, unsubscribe_event, vfh, arg); +if (!(sd->flags &V4L2_SUBDEV_FL_HAS_EVENTS )) +return -ENOIOCTLCMD ; + +if (v4l2_subdev_has_op (sd, core, unsubscribe_event)) +return v4l2_subdev_call (sd, core, unsubscribe_event, + vfh, arg); +else + return
v4l2_event_subdev_unsubscribe(sd, vfh, arg);Thanks for your "more than an hint :)"
I'm able to test this on ov5645:Adding:
+++
b/drivers/media/i2c/ov5645.c(quoted diff) +9
-0@@ -1238,6 +1238,12 @@ static int ov5645_probe(struct i2c_client *client) ov5645_init_state(&ov5645->sd, NULL); + ret = v4l2_subdev_init_finalize(&ov5645->sd); + if (ret < 0) { + dev_err(dev, "subdev initialization error %d\n", ret); + goto err_free_state; + } + ret = v4l2_async_register_subdev(&ov5645->sd); if (ret < 0) { dev_err(dev, "could not register v4l2 device\n");@@ -1251,6 +1257,8 @@ static int ov5645_probe(struct i2c_client *client) return 0; +err_free_state: + v4l2_subdev_cleanup(&ov5645->sd); err_pm_runtime: pm_runtime_disable(dev); pm_runtime_put_noidle(dev);@@ -1272,6 +1280,7 @@ static void ov5645_remove(struct i2c_client *client) v4l2_async_unregister_subdev(&ov5645->sd); media_entity_cleanup(&ov5645->sd.entity); + v4l2_subdev_cleanup(&ov5645->sd); v4l2_ctrl_handler_free(&ov5645->ctrls); pm_runtime_disable(ov5645->dev); if (!pm_runtime_status_suspended(ov5645->dev))Quoted 7 lines
Then from the compliance tool I'm getting now good results:
Total for device
/dev/v4l-subdev1: 44, Succeeded: 44, Failed: 0, Warnings: 0I will send these 2 patches later if you agree (1 v4l2-subdev 1
ov5645.c) Thanks again.Thank you for the patch.
Quoted 8 lines
I am currently working on adding support for
V4L2_SUBDEV_FL_HAS_EVENTSand subscribe hooks[1] (and some more features [0] for ov5645 driver), since the patch series adds internal pad which needs rework based on patch series from Sakari which I will do soon and send v3 patches for ov5645 driver.[0] https://lore.kernel.org/all/[email protected]/
[1] https://lore.kernel.org/all/[email protected]/Thanks for sharing this.
Nice! then I can drop ov5645 patch and send only v4l2-subdev patch :)Plan as suggested by Laurent is:
"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_EVENTSflag automatically, and default tov4l2_ctrl_subdev_subscribe_event()andv4l2_event_subdev_unsubscribe()if there are no control operations"Using:
drivers/media/v4l2-core/v4l2-subdev.c +0
-0@@ -691,10 +691,24 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg,return v4l2_event_dequeue (vfh, arg, file->f_flags &O_NONBLOCK );
Quoted 8 lines
drivers/media/v4l2-core/v4l2-subdev.c static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg, · line 697
Quoted 6 lines
drivers/media/v4l2-core/v4l2-subdev.c +4
-1case 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); + else if ((sd->flags & V4L2_SUBDEV_FL_HAS_EVENTS) &&Useless use of else. Same below.
Better:
case VIDIOC_SUBSCRIBE_EVENT: if (v4l2_subdev_has_op(sd, core, subscribe_event)) return v4l2_subdev_call(sd, core, subscribe_event, vfh, arg); return v4l2_ctrl_subdev_subscribe_event(sd, vfh, arg); case VIDIOC_UNSUBSCRIBE_EVENT: if (v4l2_subdev_has_op(sd, core, unsubscribe_event)) return v4l2_subdev_call(sd, core, unsubscribe_event, vfh, arg); return v4l2_event_subdev_unsubscribe(sd, vfh, arg);
Because V4L2_SUBDEV_FL_HAS_EVENTS and vfh->ctrl_handler are already check right?
Thanks & Regards,
Tommaso
Quoted 43 lines
Quoted 30 lines
drivers/media/v4l2-core/v4l2-subdev.c +15
-1+ vfh->ctrl_handler) + return v4l2_ctrl_subdev_subscribe_event(sd, vfh, arg); + else + return -ENOIOCTLCMD;case VIDIOC_UNSUBSCRIBE_EVENT : -return v4l2_subdev_call (sd, core, unsubscribe_event, vfh, arg); +if (!(sd->flags &V4L2_SUBDEV_FL_HAS_EVENTS )) +return -ENOIOCTLCMD ; + +if (v4l2_subdev_has_op (sd, core, unsubscribe_event)) +return v4l2_subdev_call (sd, core, unsubscribe_event, + vfh, arg); +else +return v4l2_event_subdev_unsubscribe (sd, vfh, arg);#ifdef CONFIG_VIDEO_ADV_DEBUG case VIDIOC_DBG_G_REGISTER :@@ -1641,6 +1655,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);Quoted 6 lines
In theory
v4l2_subdev_init_finalize()andsubdev_do_ioctl()will handle this.Please Laurent correct me if I'm wrong.
Prabhakar what do you think?
Thanks in advance.Looks good to me, with the above comment.
Signature · 3 lines
Kind regards, Sakari Ailus
Sakari Ailus
maintainerRe: [PATCH] media: i2c: ov5645: add HAS_EVENTS supporty
Hi Tommaso,
Quoted 238 lines · Tommaso Merciai
Hi Sakari,
Thanks for your review.Quoted 209 lines · Sakari Ailus
Hi folks,
Quoted 206 lines · Tommaso Merciai
Hi Prabhakar,
Thanks for your comments.Quoted 173 lines · Prabhakar
Hi Tommaso,
Quoted 161 lines · Tommaso Merciai
Hi Laurent,
Quoted 108 lines · Laurent Pinchart
Hi Tommaso,
Quoted 59 lines · Tommaso Merciai
Quoted 46 lines · Tommaso Merciai
Quoted 45 lines · Laurent Pinchart
Quoted 44 lines · Tommaso Merciai
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 missingHAS_EVENTSsupport: flag and .(un)subscribe_event().Signed-off-by Tommaso Merciai <[email protected]>--- drivers/media/i2c/ov5645.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)drivers/media/i2c/ov5645.c +7
-0@@ -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)Quoted 11 lines
Quoted 11 lines
drivers/media/i2c/ov5645.c static int ov5645_probe(struct i2c_client *client) · line 1189
Quoted 5 lines
drivers/media/i2c/ov5645.c +2
-1v4l2_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_EVENTSflag automatically, and default tov4l2_ctrl_subdev_subscribe_event()andv4l2_event_subdev_unsubscribe()if there are no control operations.Quoted 2 lines
Premit:
- Don't know if I'm wrong eh.Nobody knows :-)
Quoted 15 lines
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;
boolhas_unsubscribe_event;Quoted 5 lines
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)
assignv4l2_ctrl_subdev_subscribe_eventas default .subscribe ops(somehow)We can't change the ops structure as it's constant. Something like this could do:
drivers/media/v4l2-core/v4l2-subdev.c +8
-1@@ -691,10 +691,24 @@ 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); +else if ((sd->flags &V4L2_SUBDEV_FL_HAS_EVENTS ) && + vfh->ctrl_handler) +return v4l2_ctrl_subdev_subscribe_event (sd, vfh, arg); +else +return -ENOIOCTLCMD ;drivers/media/v4l2-core/v4l2-subdev.c static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg, · line 710
Quoted 10 lines
drivers/media/v4l2-core/v4l2-subdev.c +7
-1case VIDIOC_UNSUBSCRIBE_EVENT : -return v4l2_subdev_call (sd, core, unsubscribe_event, vfh, arg); +if (!(sd->flags &V4L2_SUBDEV_FL_HAS_EVENTS )) +return -ENOIOCTLCMD ; + +if (v4l2_subdev_has_op (sd, core, unsubscribe_event)) +return v4l2_subdev_call (sd, core, unsubscribe_event, + vfh, arg); +else + return
v4l2_event_subdev_unsubscribe(sd, vfh, arg);Thanks for your "more than an hint :)"
I'm able to test this on ov5645:Adding:
+++
b/drivers/media/i2c/ov5645.c(quoted diff) +9
-0@@ -1238,6 +1238,12 @@ static int ov5645_probe(struct i2c_client *client) ov5645_init_state(&ov5645->sd, NULL); + ret = v4l2_subdev_init_finalize(&ov5645->sd); + if (ret < 0) { + dev_err(dev, "subdev initialization error %d\n", ret); + goto err_free_state; + } + ret = v4l2_async_register_subdev(&ov5645->sd); if (ret < 0) { dev_err(dev, "could not register v4l2 device\n");@@ -1251,6 +1257,8 @@ static int ov5645_probe(struct i2c_client *client) return 0; +err_free_state: + v4l2_subdev_cleanup(&ov5645->sd); err_pm_runtime: pm_runtime_disable(dev); pm_runtime_put_noidle(dev);@@ -1272,6 +1280,7 @@ static void ov5645_remove(struct i2c_client *client) v4l2_async_unregister_subdev(&ov5645->sd); media_entity_cleanup(&ov5645->sd.entity); + v4l2_subdev_cleanup(&ov5645->sd); v4l2_ctrl_handler_free(&ov5645->ctrls); pm_runtime_disable(ov5645->dev); if (!pm_runtime_status_suspended(ov5645->dev))Quoted 7 lines
Then from the compliance tool I'm getting now good results:
Total for device
/dev/v4l-subdev1: 44, Succeeded: 44, Failed: 0, Warnings: 0I will send these 2 patches later if you agree (1 v4l2-subdev 1
ov5645.c) Thanks again.Thank you for the patch.
Quoted 8 lines
I am currently working on adding support for
V4L2_SUBDEV_FL_HAS_EVENTSand subscribe hooks[1] (and some more features [0] for ov5645 driver), since the patch series adds internal pad which needs rework based on patch series from Sakari which I will do soon and send v3 patches for ov5645 driver.[0] https://lore.kernel.org/all/[email protected]/
[1] https://lore.kernel.org/all/[email protected]/Thanks for sharing this.
Nice! then I can drop ov5645 patch and send only v4l2-subdev patch :)Plan as suggested by Laurent is:
"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_EVENTSflag automatically, and default tov4l2_ctrl_subdev_subscribe_event()andv4l2_event_subdev_unsubscribe()if there are no control operations"Using:
drivers/media/v4l2-core/v4l2-subdev.c +0
-0@@ -691,10 +691,24 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg,return v4l2_event_dequeue (vfh, arg, file->f_flags &O_NONBLOCK );Quoted 8 lines
drivers/media/v4l2-core/v4l2-subdev.c static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg, · line 697
Quoted 6 lines
drivers/media/v4l2-core/v4l2-subdev.c +4
-1case 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); + else if ((sd->flags & V4L2_SUBDEV_FL_HAS_EVENTS) &&Useless use of else. Same below.
Better:
case VIDIOC_SUBSCRIBE_EVENT: if (v4l2_subdev_has_op(sd, core, subscribe_event)) return v4l2_subdev_call(sd, core, subscribe_event, vfh, arg); return v4l2_ctrl_subdev_subscribe_event(sd, vfh, arg); case VIDIOC_UNSUBSCRIBE_EVENT: if (v4l2_subdev_has_op(sd, core, unsubscribe_event)) return v4l2_subdev_call(sd, core, unsubscribe_event, vfh, arg); return v4l2_event_subdev_unsubscribe(sd, vfh, arg);
Quoted 2 lines
Because
V4L2_SUBDEV_FL_HAS_EVENTSandvfh->ctrl_handlerare already check right?
v4l2_ctrl_subdev_{,un}subscribe_event() does check for the presence of the control handler, but return -EINVAL if one doesn't exist. We should however return -ENOIOCTLCMD, to indicate there's no such IOCTL if the HAS_EVENTS flag is missing.
Quoted 38 lines
Quoted 38 lines
Quoted 30 lines
drivers/media/v4l2-core/v4l2-subdev.c +15
-1+ vfh->ctrl_handler) + return v4l2_ctrl_subdev_subscribe_event(sd, vfh, arg); + else + return -ENOIOCTLCMD;case VIDIOC_UNSUBSCRIBE_EVENT : -return v4l2_subdev_call (sd, core, unsubscribe_event, vfh, arg); +if (!(sd->flags &V4L2_SUBDEV_FL_HAS_EVENTS )) +return -ENOIOCTLCMD ; + +if (v4l2_subdev_has_op (sd, core, unsubscribe_event)) +return v4l2_subdev_call (sd, core, unsubscribe_event, + vfh, arg); +else +return v4l2_event_subdev_unsubscribe (sd, vfh, arg);#ifdef CONFIG_VIDEO_ADV_DEBUG case VIDIOC_DBG_G_REGISTER :@@ -1641,6 +1655,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);Quoted 6 lines
In theory
v4l2_subdev_init_finalize()andsubdev_do_ioctl()will handle this.Please Laurent correct me if I'm wrong.
Prabhakar what do you think?
Thanks in advance.Looks good to me, with the above comment.
Signature · 3 lines
Kind regards, Sakari Ailus
Re: [PATCH] media: i2c: ov5645: add HAS_EVENTS supporty
Hi Sakari,
Thanks for your comment.
Quoted 241 lines · Sakari Ailus
Hi Tommaso,
Quoted 238 lines · Tommaso Merciai
Hi Sakari,
Thanks for your review.Quoted 209 lines · Sakari Ailus
Hi folks,
Quoted 206 lines · Tommaso Merciai
Hi Prabhakar,
Thanks for your comments.Quoted 173 lines · Prabhakar
Hi Tommaso,
Quoted 161 lines · Tommaso Merciai
Hi Laurent,
Quoted 108 lines · Laurent Pinchart
Hi Tommaso,
Quoted 59 lines · Tommaso Merciai
Quoted 46 lines · Tommaso Merciai
Quoted 45 lines · Laurent Pinchart
Quoted 44 lines · Tommaso Merciai
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 missingHAS_EVENTSsupport: flag and .(un)subscribe_event().Signed-off-by Tommaso Merciai <[email protected]>--- drivers/media/i2c/ov5645.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)drivers/media/i2c/ov5645.c +7
-0@@ -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)Quoted 11 lines
Quoted 11 lines
drivers/media/i2c/ov5645.c static int ov5645_probe(struct i2c_client *client) · line 1189
Quoted 5 lines
drivers/media/i2c/ov5645.c +2
-1v4l2_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_EVENTSflag automatically, and default tov4l2_ctrl_subdev_subscribe_event()andv4l2_event_subdev_unsubscribe()if there are no control operations.Quoted 2 lines
Premit:
- Don't know if I'm wrong eh.Nobody knows :-)
Quoted 15 lines
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;
boolhas_unsubscribe_event;Quoted 5 lines
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)
assignv4l2_ctrl_subdev_subscribe_eventas default .subscribe ops(somehow)We can't change the ops structure as it's constant. Something like this could do:
drivers/media/v4l2-core/v4l2-subdev.c +8
-1@@ -691,10 +691,24 @@ 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); +else if ((sd->flags &V4L2_SUBDEV_FL_HAS_EVENTS ) && + vfh->ctrl_handler) +return v4l2_ctrl_subdev_subscribe_event (sd, vfh, arg); +else +return -ENOIOCTLCMD ;drivers/media/v4l2-core/v4l2-subdev.c static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg, · line 710
Quoted 10 lines
drivers/media/v4l2-core/v4l2-subdev.c +7
-1case VIDIOC_UNSUBSCRIBE_EVENT : -return v4l2_subdev_call (sd, core, unsubscribe_event, vfh, arg); +if (!(sd->flags &V4L2_SUBDEV_FL_HAS_EVENTS )) +return -ENOIOCTLCMD ; + +if (v4l2_subdev_has_op (sd, core, unsubscribe_event)) +return v4l2_subdev_call (sd, core, unsubscribe_event, + vfh, arg); +else + return
v4l2_event_subdev_unsubscribe(sd, vfh, arg);Thanks for your "more than an hint :)"
I'm able to test this on ov5645:Adding:
+++
b/drivers/media/i2c/ov5645.c(quoted diff) +9
-0@@ -1238,6 +1238,12 @@ static int ov5645_probe(struct i2c_client *client) ov5645_init_state(&ov5645->sd, NULL); + ret = v4l2_subdev_init_finalize(&ov5645->sd); + if (ret < 0) { + dev_err(dev, "subdev initialization error %d\n", ret); + goto err_free_state; + } + ret = v4l2_async_register_subdev(&ov5645->sd); if (ret < 0) { dev_err(dev, "could not register v4l2 device\n");@@ -1251,6 +1257,8 @@ static int ov5645_probe(struct i2c_client *client) return 0; +err_free_state: + v4l2_subdev_cleanup(&ov5645->sd); err_pm_runtime: pm_runtime_disable(dev); pm_runtime_put_noidle(dev);@@ -1272,6 +1280,7 @@ static void ov5645_remove(struct i2c_client *client) v4l2_async_unregister_subdev(&ov5645->sd); media_entity_cleanup(&ov5645->sd.entity); + v4l2_subdev_cleanup(&ov5645->sd); v4l2_ctrl_handler_free(&ov5645->ctrls); pm_runtime_disable(ov5645->dev); if (!pm_runtime_status_suspended(ov5645->dev))Quoted 7 lines
Then from the compliance tool I'm getting now good results:
Total for device
/dev/v4l-subdev1: 44, Succeeded: 44, Failed: 0, Warnings: 0I will send these 2 patches later if you agree (1 v4l2-subdev 1
ov5645.c) Thanks again.Thank you for the patch.
Quoted 8 lines
I am currently working on adding support for
V4L2_SUBDEV_FL_HAS_EVENTSand subscribe hooks[1] (and some more features [0] for ov5645 driver), since the patch series adds internal pad which needs rework based on patch series from Sakari which I will do soon and send v3 patches for ov5645 driver.[0] https://lore.kernel.org/all/[email protected]/
[1] https://lore.kernel.org/all/[email protected]/Thanks for sharing this.
Nice! then I can drop ov5645 patch and send only v4l2-subdev patch :)Plan as suggested by Laurent is:
"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_EVENTSflag automatically, and default tov4l2_ctrl_subdev_subscribe_event()andv4l2_event_subdev_unsubscribe()if there are no control operations"Using:
drivers/media/v4l2-core/v4l2-subdev.c +0
-0@@ -691,10 +691,24 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg,return v4l2_event_dequeue (vfh, arg, file->f_flags &O_NONBLOCK );Quoted 8 lines
drivers/media/v4l2-core/v4l2-subdev.c static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg, · line 697
Quoted 6 lines
drivers/media/v4l2-core/v4l2-subdev.c +4
-1case 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); + else if ((sd->flags & V4L2_SUBDEV_FL_HAS_EVENTS) &&Useless use of else. Same below.
Better:
case VIDIOC_SUBSCRIBE_EVENT: if (v4l2_subdev_has_op(sd, core, subscribe_event)) return v4l2_subdev_call(sd, core, subscribe_event, vfh, arg); return v4l2_ctrl_subdev_subscribe_event(sd, vfh, arg); case VIDIOC_UNSUBSCRIBE_EVENT: if (v4l2_subdev_has_op(sd, core, unsubscribe_event)) return v4l2_subdev_call(sd, core, unsubscribe_event, vfh, arg); return v4l2_event_subdev_unsubscribe(sd, vfh, arg);
Quoted 7 lines
Quoted 2 lines
Because
V4L2_SUBDEV_FL_HAS_EVENTSandvfh->ctrl_handlerare already check right?v4l2_ctrl_subdev_{,un}subscribe_event() does check for the presence of the control handler, but return
-EINVALif one doesn't exist. We should however return-ENOIOCTLCMD, to indicate there's no such IOCTL if theHAS_EVENTSflag is missing.
Got it thanks.
I think with your review will be:
drivers/media/v4l2-core/v4l2-subdev.c +20 -2
@@ -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 (!(sd->flags &V4L2_SUBDEV_FL_HAS_EVENTS )) +return -ENOIOCTLCMD ; + +if (v4l2_subdev_has_op (sd, core, unsubscribe_event)) +return v4l2_subdev_call (sd, core, unsubscribe_event, + vfh, arg); + +return v4l2_event_subdev_unsubscribe (sd, vfh, arg);#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);
Just dropping else.
I will send a patch later if you all agree.
Thanks All. :)
Regards,
Tommaso
Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
drivers/media/v4l2-core/v4l2-subdev.c +15
-1+ vfh->ctrl_handler) + return v4l2_ctrl_subdev_subscribe_event(sd, vfh, arg); + else + return -ENOIOCTLCMD;case VIDIOC_UNSUBSCRIBE_EVENT : -return v4l2_subdev_call (sd, core, unsubscribe_event, vfh, arg); +if (!(sd->flags &V4L2_SUBDEV_FL_HAS_EVENTS )) +return -ENOIOCTLCMD ; + +if (v4l2_subdev_has_op (sd, core, unsubscribe_event)) +return v4l2_subdev_call (sd, core, unsubscribe_event, + vfh, arg); +else +return v4l2_event_subdev_unsubscribe (sd, vfh, arg);#ifdef CONFIG_VIDEO_ADV_DEBUG case VIDIOC_DBG_G_REGISTER :@@ -1641,6 +1655,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);
Quoted 13 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
In theory
v4l2_subdev_init_finalize()andsubdev_do_ioctl()will handle this.Please Laurent correct me if I'm wrong.
Prabhakar what do you think?
Thanks in advance.Looks good to me, with the above comment.
Signature · 3 lines
Kind regards, Sakari Ailus
Thanks & Regards,
Tommaso