Signed-off-by: Hans Verkuil <hans.verkuil@xxxxxxxxx> --- drivers/media/video/v4l2-ctrls.c | 25 ++++++++++++++++++++++++- drivers/media/video/v4l2-event.c | 2 +- include/linux/videodev2.h | 5 ++++- include/media/v4l2-ctrls.h | 4 +++- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/drivers/media/video/v4l2-ctrls.c b/drivers/media/video/v4l2-ctrls.c index 122c6da..e6fa9be 100644 --- a/drivers/media/video/v4l2-ctrls.c +++ b/drivers/media/video/v4l2-ctrls.c @@ -1912,10 +1912,33 @@ int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val) } EXPORT_SYMBOL(v4l2_ctrl_s_ctrl); -void v4l2_ctrl_add_fh(struct v4l2_ctrl *ctrl, struct v4l2_ctrl_fh *ctrl_fh) +void v4l2_ctrl_add_fh(struct v4l2_ctrl *ctrl, struct v4l2_ctrl_fh *ctrl_fh, + struct v4l2_event_subscription *sub) { v4l2_ctrl_lock(ctrl); list_add_tail(&ctrl_fh->node, &ctrl->fhs); + if (sub->flags & V4L2_EVENT_SUB_FL_SEND_INITIAL) { + struct v4l2_event ev; + + ev.type = sub->type; + ev.id = ctrl->id; + switch (ev.type) { + case V4L2_EVENT_CTRL_CH_VALUE: + /* TODO: shouldn't be done for write-only or button/ctrl_class + controls. */ + if (ctrl->type == V4L2_CTRL_TYPE_INTEGER64) + ev.u.ctrl_ch_value.value64 = ctrl->cur.val64; + else + ev.u.ctrl_ch_value.value = ctrl->cur.val; + v4l2_event_queue_fh(ctrl_fh->fh, &ev); + break; + case V4L2_EVENT_CTRL_CH_STATE: + ev.u.ctrl_ch_state.flags = ctrl->flags; + v4l2_event_queue_fh(ctrl_fh->fh, &ev); + default: + break; + } + } v4l2_ctrl_unlock(ctrl); } EXPORT_SYMBOL(v4l2_ctrl_add_fh); diff --git a/drivers/media/video/v4l2-event.c b/drivers/media/video/v4l2-event.c index 9b503aa..06608e7 100644 --- a/drivers/media/video/v4l2-event.c +++ b/drivers/media/video/v4l2-event.c @@ -293,7 +293,7 @@ int v4l2_event_subscribe(struct v4l2_fh *fh, /* v4l2_ctrl_add_fh uses a mutex, so do this outside the spin lock */ if (!found_ev && ctrl) - v4l2_ctrl_add_fh(ctrl, ctrl_fh); + v4l2_ctrl_add_fh(ctrl, ctrl_fh, sub); kfree(sev); diff --git a/include/linux/videodev2.h b/include/linux/videodev2.h index eb56685..2a20dd9 100644 --- a/include/linux/videodev2.h +++ b/include/linux/videodev2.h @@ -1827,10 +1827,13 @@ struct v4l2_event { __u32 reserved[8]; }; +#define V4L2_EVENT_SUB_FL_SEND_INITIAL (1 << 0) + struct v4l2_event_subscription { __u32 type; __u32 id; - __u32 reserved[6]; + __u32 flags; + __u32 reserved[5]; }; /* diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h index e6917f4..27714c9 100644 --- a/include/media/v4l2-ctrls.h +++ b/include/media/v4l2-ctrls.h @@ -30,6 +30,7 @@ struct v4l2_ctrl_handler; struct v4l2_ctrl; struct video_device; struct v4l2_subdev; +struct v4l2_event_subscription; struct v4l2_fh; /** struct v4l2_ctrl_ops - The control operations that the driver has to provide. @@ -445,7 +446,8 @@ s32 v4l2_ctrl_g_ctrl(struct v4l2_ctrl *ctrl); */ int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val); -void v4l2_ctrl_add_fh(struct v4l2_ctrl *ctrl, struct v4l2_ctrl_fh *ctrl_fh); +void v4l2_ctrl_add_fh(struct v4l2_ctrl *ctrl, struct v4l2_ctrl_fh *ctrl_fh, + struct v4l2_event_subscription *sub); void v4l2_ctrl_del_fh(struct v4l2_ctrl *ctrl, struct v4l2_fh *fh); /* Helpers for ioctl_ops. If hdl == NULL then they will all return -EINVAL. */ -- 1.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html