Skip to content

Commit a26243b

Browse files
Hans VerkuilMauro Carvalho Chehab
authored andcommitted
[media] v4l2-ctrls: add helper functions for control events
Many drivers just support control events, and most radio drivers just need to poll for control events. Add some functions to simplify those jobs. Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
1 parent 42194e7 commit a26243b

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

‎drivers/media/video/v4l2-ctrls.c‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2394,3 +2394,23 @@ int v4l2_ctrl_log_status(struct file *file, void *fh)
23942394
return 0;
23952395
}
23962396
EXPORT_SYMBOL(v4l2_ctrl_log_status);
2397+
2398+
int v4l2_ctrl_subscribe_event(struct v4l2_fh *fh,
2399+
struct v4l2_event_subscription *sub)
2400+
{
2401+
if (sub->type == V4L2_EVENT_CTRL)
2402+
return v4l2_event_subscribe(fh, sub, 0);
2403+
return -EINVAL;
2404+
}
2405+
EXPORT_SYMBOL(v4l2_ctrl_subscribe_event);
2406+
2407+
unsigned int v4l2_ctrl_poll(struct file *file, struct poll_table_struct *wait)
2408+
{
2409+
struct v4l2_fh *fh = file->private_data;
2410+
2411+
if (v4l2_event_pending(fh))
2412+
return POLLPRI;
2413+
poll_wait(file, &fh->wait, wait);
2414+
return 0;
2415+
}
2416+
EXPORT_SYMBOL(v4l2_ctrl_poll);

‎include/media/v4l2-ctrls.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ struct video_device;
3333
struct v4l2_subdev;
3434
struct v4l2_subscribed_event;
3535
struct v4l2_fh;
36+
struct poll_table_struct;
3637

3738
/** struct v4l2_ctrl_ops - The control operations that the driver has to provide.
3839
* @g_volatile_ctrl: Get a new value for this control. Generally only relevant
@@ -496,6 +497,14 @@ void v4l2_ctrl_del_event(struct v4l2_ctrl *ctrl,
496497
associated with the filehandle. */
497498
int v4l2_ctrl_log_status(struct file *file, void *fh);
498499

500+
/* Can be used as a vidioc_subscribe_event function that just subscribes
501+
control events. */
502+
int v4l2_ctrl_subscribe_event(struct v4l2_fh *fh,
503+
struct v4l2_event_subscription *sub);
504+
505+
/* Can be used as a poll function that just polls for control events. */
506+
unsigned int v4l2_ctrl_poll(struct file *file, struct poll_table_struct *wait);
507+
499508
/* Helpers for ioctl_ops. If hdl == NULL then they will all return -EINVAL. */
500509
int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc);
501510
int v4l2_querymenu(struct v4l2_ctrl_handler *hdl, struct v4l2_querymenu *qm);

0 commit comments

Comments
 (0)