^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * v4l2-event.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * V4L2 events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 2009--2010 Nokia Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Contact: Sakari Ailus <sakari.ailus@iki.fi>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #ifndef V4L2_EVENT_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #define V4L2_EVENT_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/videodev2.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) struct v4l2_fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) struct v4l2_subdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) struct v4l2_subscribed_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) struct video_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * struct v4l2_kevent - Internal kernel event struct.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * @list: List node for the v4l2_fh->available list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * @sev: Pointer to parent v4l2_subscribed_event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * @event: The event itself.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * @ts: The timestamp of the event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct v4l2_kevent {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct v4l2_subscribed_event *sev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct v4l2_event event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) u64 ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * struct v4l2_subscribed_event_ops - Subscribed event operations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * @add: Optional callback, called when a new listener is added
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * @del: Optional callback, called when a listener stops listening
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * @replace: Optional callback that can replace event 'old' with event 'new'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * @merge: Optional callback that can merge event 'old' into event 'new'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct v4l2_subscribed_event_ops {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) int (*add)(struct v4l2_subscribed_event *sev, unsigned int elems);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) void (*del)(struct v4l2_subscribed_event *sev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) void (*replace)(struct v4l2_event *old, const struct v4l2_event *new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) void (*merge)(const struct v4l2_event *old, struct v4l2_event *new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * struct v4l2_subscribed_event - Internal struct representing a subscribed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * @list: List node for the v4l2_fh->subscribed list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * @type: Event type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * @id: Associated object ID (e.g. control ID). 0 if there isn't any.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * @flags: Copy of v4l2_event_subscription->flags.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * @fh: Filehandle that subscribed to this event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * @node: List node that hooks into the object's event list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * (if there is one).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * @ops: v4l2_subscribed_event_ops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * @elems: The number of elements in the events array.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * @first: The index of the events containing the oldest available event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * @in_use: The number of queued events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * @events: An array of @elems events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct v4l2_subscribed_event {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) u32 type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) u32 id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) u32 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) struct v4l2_fh *fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) struct list_head node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) const struct v4l2_subscribed_event_ops *ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) unsigned int elems;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) unsigned int first;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) unsigned int in_use;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) struct v4l2_kevent events[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * v4l2_event_dequeue - Dequeue events from video device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * @fh: pointer to struct v4l2_fh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * @event: pointer to struct v4l2_event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * @nonblocking: if not zero, waits for an event to arrive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) int v4l2_event_dequeue(struct v4l2_fh *fh, struct v4l2_event *event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) int nonblocking);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * v4l2_event_queue - Queue events to video device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * @vdev: pointer to &struct video_device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * @ev: pointer to &struct v4l2_event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * The event will be queued for all &struct v4l2_fh file handlers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * .. note::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * The driver's only responsibility is to fill in the type and the data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * fields.The other fields will be filled in by V4L2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) void v4l2_event_queue(struct video_device *vdev, const struct v4l2_event *ev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * v4l2_event_queue_fh - Queue events to video device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * @fh: pointer to &struct v4l2_fh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * @ev: pointer to &struct v4l2_event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * The event will be queued only for the specified &struct v4l2_fh file handler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * .. note::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * The driver's only responsibility is to fill in the type and the data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * fields.The other fields will be filled in by V4L2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) void v4l2_event_queue_fh(struct v4l2_fh *fh, const struct v4l2_event *ev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) * v4l2_event_pending - Check if an event is available
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * @fh: pointer to &struct v4l2_fh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * Returns the number of pending events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) int v4l2_event_pending(struct v4l2_fh *fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * v4l2_event_subscribe - Subscribes to an event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) * @fh: pointer to &struct v4l2_fh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) * @sub: pointer to &struct v4l2_event_subscription
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) * @elems: size of the events queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) * @ops: pointer to &v4l2_subscribed_event_ops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) * .. note::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) * if @elems is zero, the framework will fill in a default value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) * with is currently 1 element.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) int v4l2_event_subscribe(struct v4l2_fh *fh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) const struct v4l2_event_subscription *sub,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) unsigned int elems,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) const struct v4l2_subscribed_event_ops *ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) * v4l2_event_unsubscribe - Unsubscribes to an event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) * @fh: pointer to &struct v4l2_fh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) * @sub: pointer to &struct v4l2_event_subscription
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) int v4l2_event_unsubscribe(struct v4l2_fh *fh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) const struct v4l2_event_subscription *sub);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * v4l2_event_unsubscribe_all - Unsubscribes to all events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * @fh: pointer to &struct v4l2_fh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) void v4l2_event_unsubscribe_all(struct v4l2_fh *fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) * v4l2_event_subdev_unsubscribe - Subdev variant of v4l2_event_unsubscribe()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) * @sd: pointer to &struct v4l2_subdev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) * @fh: pointer to &struct v4l2_fh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) * @sub: pointer to &struct v4l2_event_subscription
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * .. note::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * This function should be used for the &struct v4l2_subdev_core_ops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * %unsubscribe_event field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) int v4l2_event_subdev_unsubscribe(struct v4l2_subdev *sd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) struct v4l2_fh *fh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) struct v4l2_event_subscription *sub);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) * v4l2_src_change_event_subscribe - helper function that calls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) * v4l2_event_subscribe() if the event is %V4L2_EVENT_SOURCE_CHANGE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) * @fh: pointer to struct v4l2_fh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) * @sub: pointer to &struct v4l2_event_subscription
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) int v4l2_src_change_event_subscribe(struct v4l2_fh *fh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) const struct v4l2_event_subscription *sub);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * v4l2_src_change_event_subdev_subscribe - Variant of v4l2_event_subscribe(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * meant to subscribe only events of the type %V4L2_EVENT_SOURCE_CHANGE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) * @sd: pointer to &struct v4l2_subdev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) * @fh: pointer to &struct v4l2_fh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) * @sub: pointer to &struct v4l2_event_subscription
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) int v4l2_src_change_event_subdev_subscribe(struct v4l2_subdev *sd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) struct v4l2_fh *fh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) struct v4l2_event_subscription *sub);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) #endif /* V4L2_EVENT_H */