xref: /openbmc/linux/include/media/v4l2-event.h (revision d0034a7a4ac7fae708146ac0059b9c47a1543f0d)
11802d0beSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2c3b5b024SSakari Ailus /*
3c3b5b024SSakari Ailus  * v4l2-event.h
4c3b5b024SSakari Ailus  *
5c3b5b024SSakari Ailus  * V4L2 events.
6c3b5b024SSakari Ailus  *
7c3b5b024SSakari Ailus  * Copyright (C) 2009--2010 Nokia Corporation.
8c3b5b024SSakari Ailus  *
98c5dff90SSakari Ailus  * Contact: Sakari Ailus <sakari.ailus@iki.fi>
10c3b5b024SSakari Ailus  */
11c3b5b024SSakari Ailus 
12c3b5b024SSakari Ailus #ifndef V4L2_EVENT_H
13c3b5b024SSakari Ailus #define V4L2_EVENT_H
14c3b5b024SSakari Ailus 
15c3b5b024SSakari Ailus #include <linux/types.h>
16c3b5b024SSakari Ailus #include <linux/videodev2.h>
17c3b5b024SSakari Ailus #include <linux/wait.h>
18c3b5b024SSakari Ailus 
19c3b5b024SSakari Ailus struct v4l2_fh;
204f4d14b7SSylwester Nawrocki struct v4l2_subdev;
21f1e393deSHans Verkuil struct v4l2_subscribed_event;
22c3b5b024SSakari Ailus struct video_device;
23c3b5b024SSakari Ailus 
24b6fce850SMauro Carvalho Chehab /**
25b6fce850SMauro Carvalho Chehab  * struct v4l2_kevent - Internal kernel event struct.
263f66f0edSHans Verkuil  * @list:	List node for the v4l2_fh->available list.
273f66f0edSHans Verkuil  * @sev:	Pointer to parent v4l2_subscribed_event.
283f66f0edSHans Verkuil  * @event:	The event itself.
2963635b54SHans Verkuil  * @ts:		The timestamp of the event.
303f66f0edSHans Verkuil  */
31c3b5b024SSakari Ailus struct v4l2_kevent {
32c3b5b024SSakari Ailus 	struct list_head	list;
33f1e393deSHans Verkuil 	struct v4l2_subscribed_event *sev;
34c3b5b024SSakari Ailus 	struct v4l2_event	event;
3563635b54SHans Verkuil 	u64			ts;
36c3b5b024SSakari Ailus };
37c3b5b024SSakari Ailus 
389d4ee1adSMauro Carvalho Chehab /**
399d4ee1adSMauro Carvalho Chehab  * struct v4l2_subscribed_event_ops - Subscribed event operations.
40b6fce850SMauro Carvalho Chehab  *
41c53c2549SHans de Goede  * @add:	Optional callback, called when a new listener is added
42c53c2549SHans de Goede  * @del:	Optional callback, called when a listener stops listening
43c53c2549SHans de Goede  * @replace:	Optional callback that can replace event 'old' with event 'new'.
44c53c2549SHans de Goede  * @merge:	Optional callback that can merge event 'old' into event 'new'.
45c53c2549SHans de Goede  */
46c53c2549SHans de Goede struct v4l2_subscribed_event_ops {
479d4ee1adSMauro Carvalho Chehab 	int  (*add)(struct v4l2_subscribed_event *sev, unsigned int elems);
48c53c2549SHans de Goede 	void (*del)(struct v4l2_subscribed_event *sev);
49c53c2549SHans de Goede 	void (*replace)(struct v4l2_event *old, const struct v4l2_event *new);
50c53c2549SHans de Goede 	void (*merge)(const struct v4l2_event *old, struct v4l2_event *new);
51c53c2549SHans de Goede };
52c53c2549SHans de Goede 
53b6fce850SMauro Carvalho Chehab /**
549d4ee1adSMauro Carvalho Chehab  * struct v4l2_subscribed_event - Internal struct representing a subscribed
559d4ee1adSMauro Carvalho Chehab  *		event.
569d4ee1adSMauro Carvalho Chehab  *
573f66f0edSHans Verkuil  * @list:	List node for the v4l2_fh->subscribed list.
583f66f0edSHans Verkuil  * @type:	Event type.
593f66f0edSHans Verkuil  * @id:	Associated object ID (e.g. control ID). 0 if there isn't any.
603f66f0edSHans Verkuil  * @flags:	Copy of v4l2_event_subscription->flags.
613f66f0edSHans Verkuil  * @fh:	Filehandle that subscribed to this event.
629d4ee1adSMauro Carvalho Chehab  * @node:	List node that hooks into the object's event list
639d4ee1adSMauro Carvalho Chehab  *		(if there is one).
64c53c2549SHans de Goede  * @ops:	v4l2_subscribed_event_ops
653f66f0edSHans Verkuil  * @elems:	The number of elements in the events array.
663f66f0edSHans Verkuil  * @first:	The index of the events containing the oldest available event.
673f66f0edSHans Verkuil  * @in_use:	The number of queued events.
683f66f0edSHans Verkuil  * @events:	An array of @elems events.
693f66f0edSHans Verkuil  */
70c3b5b024SSakari Ailus struct v4l2_subscribed_event {
71c3b5b024SSakari Ailus 	struct list_head	list;
72c3b5b024SSakari Ailus 	u32			type;
736e239399SHans Verkuil 	u32			id;
7477068d36SHans Verkuil 	u32			flags;
7577068d36SHans Verkuil 	struct v4l2_fh		*fh;
7677068d36SHans Verkuil 	struct list_head	node;
77c53c2549SHans de Goede 	const struct v4l2_subscribed_event_ops *ops;
789d4ee1adSMauro Carvalho Chehab 	unsigned int		elems;
799d4ee1adSMauro Carvalho Chehab 	unsigned int		first;
809d4ee1adSMauro Carvalho Chehab 	unsigned int		in_use;
81f1e393deSHans Verkuil 	struct v4l2_kevent	events[];
82c3b5b024SSakari Ailus };
83c3b5b024SSakari Ailus 
849d4ee1adSMauro Carvalho Chehab /**
859d4ee1adSMauro Carvalho Chehab  * v4l2_event_dequeue - Dequeue events from video device.
869d4ee1adSMauro Carvalho Chehab  *
879d4ee1adSMauro Carvalho Chehab  * @fh: pointer to struct v4l2_fh
889d4ee1adSMauro Carvalho Chehab  * @event: pointer to struct v4l2_event
899d4ee1adSMauro Carvalho Chehab  * @nonblocking: if not zero, waits for an event to arrive
909d4ee1adSMauro Carvalho Chehab  */
91c3b5b024SSakari Ailus int v4l2_event_dequeue(struct v4l2_fh *fh, struct v4l2_event *event,
92c3b5b024SSakari Ailus 		       int nonblocking);
939d4ee1adSMauro Carvalho Chehab 
949d4ee1adSMauro Carvalho Chehab /**
959d4ee1adSMauro Carvalho Chehab  * v4l2_event_queue - Queue events to video device.
969d4ee1adSMauro Carvalho Chehab  *
979d4ee1adSMauro Carvalho Chehab  * @vdev: pointer to &struct video_device
989d4ee1adSMauro Carvalho Chehab  * @ev: pointer to &struct v4l2_event
999d4ee1adSMauro Carvalho Chehab  *
1009d4ee1adSMauro Carvalho Chehab  * The event will be queued for all &struct v4l2_fh file handlers.
1019d4ee1adSMauro Carvalho Chehab  *
1029d4ee1adSMauro Carvalho Chehab  * .. note::
1039d4ee1adSMauro Carvalho Chehab  *    The driver's only responsibility is to fill in the type and the data
1049d4ee1adSMauro Carvalho Chehab  *    fields. The other fields will be filled in by V4L2.
1059d4ee1adSMauro Carvalho Chehab  */
106c3b5b024SSakari Ailus void v4l2_event_queue(struct video_device *vdev, const struct v4l2_event *ev);
1079d4ee1adSMauro Carvalho Chehab 
1089d4ee1adSMauro Carvalho Chehab /**
1099d4ee1adSMauro Carvalho Chehab  * v4l2_event_queue_fh - Queue events to video device.
1109d4ee1adSMauro Carvalho Chehab  *
1119d4ee1adSMauro Carvalho Chehab  * @fh: pointer to &struct v4l2_fh
1129d4ee1adSMauro Carvalho Chehab  * @ev: pointer to &struct v4l2_event
1139d4ee1adSMauro Carvalho Chehab  *
1149d4ee1adSMauro Carvalho Chehab  *
1159d4ee1adSMauro Carvalho Chehab  * The event will be queued only for the specified &struct v4l2_fh file handler.
1169d4ee1adSMauro Carvalho Chehab  *
1179d4ee1adSMauro Carvalho Chehab  * .. note::
1189d4ee1adSMauro Carvalho Chehab  *    The driver's only responsibility is to fill in the type and the data
1199d4ee1adSMauro Carvalho Chehab  *    fields. The other fields will be filled in by V4L2.
1209d4ee1adSMauro Carvalho Chehab  */
1216e239399SHans Verkuil void v4l2_event_queue_fh(struct v4l2_fh *fh, const struct v4l2_event *ev);
122*28955a61SHans Verkuil 
123*28955a61SHans Verkuil /**
124*28955a61SHans Verkuil  * v4l2_event_wake_all - Wake all filehandles.
125*28955a61SHans Verkuil  *
126*28955a61SHans Verkuil  * Used when unregistering a video device.
127*28955a61SHans Verkuil  *
128*28955a61SHans Verkuil  * @vdev: pointer to &struct video_device
129*28955a61SHans Verkuil  */
130*28955a61SHans Verkuil void v4l2_event_wake_all(struct video_device *vdev);
1319d4ee1adSMauro Carvalho Chehab 
1329d4ee1adSMauro Carvalho Chehab /**
1339d4ee1adSMauro Carvalho Chehab  * v4l2_event_pending - Check if an event is available
1349d4ee1adSMauro Carvalho Chehab  *
1359d4ee1adSMauro Carvalho Chehab  * @fh: pointer to &struct v4l2_fh
1369d4ee1adSMauro Carvalho Chehab  *
1379d4ee1adSMauro Carvalho Chehab  * Returns the number of pending events.
1389d4ee1adSMauro Carvalho Chehab  */
139c3b5b024SSakari Ailus int v4l2_event_pending(struct v4l2_fh *fh);
1409d4ee1adSMauro Carvalho Chehab 
1419d4ee1adSMauro Carvalho Chehab /**
1429d4ee1adSMauro Carvalho Chehab  * v4l2_event_subscribe - Subscribes to an event
1439d4ee1adSMauro Carvalho Chehab  *
1449d4ee1adSMauro Carvalho Chehab  * @fh: pointer to &struct v4l2_fh
1459d4ee1adSMauro Carvalho Chehab  * @sub: pointer to &struct v4l2_event_subscription
1469d4ee1adSMauro Carvalho Chehab  * @elems: size of the events queue
1479d4ee1adSMauro Carvalho Chehab  * @ops: pointer to &v4l2_subscribed_event_ops
1489d4ee1adSMauro Carvalho Chehab  *
1499d4ee1adSMauro Carvalho Chehab  * .. note::
1509d4ee1adSMauro Carvalho Chehab  *
1519d4ee1adSMauro Carvalho Chehab  *    if @elems is zero, the framework will fill in a default value,
1529d4ee1adSMauro Carvalho Chehab  *    with is currently 1 element.
1539d4ee1adSMauro Carvalho Chehab  */
154c3b5b024SSakari Ailus int v4l2_event_subscribe(struct v4l2_fh *fh,
1559d4ee1adSMauro Carvalho Chehab 			 const struct v4l2_event_subscription *sub,
1569d4ee1adSMauro Carvalho Chehab 			 unsigned int elems,
157c53c2549SHans de Goede 			 const struct v4l2_subscribed_event_ops *ops);
1589d4ee1adSMauro Carvalho Chehab /**
1599d4ee1adSMauro Carvalho Chehab  * v4l2_event_unsubscribe - Unsubscribes to an event
1609d4ee1adSMauro Carvalho Chehab  *
1619d4ee1adSMauro Carvalho Chehab  * @fh: pointer to &struct v4l2_fh
1629d4ee1adSMauro Carvalho Chehab  * @sub: pointer to &struct v4l2_event_subscription
1639d4ee1adSMauro Carvalho Chehab  */
164c3b5b024SSakari Ailus int v4l2_event_unsubscribe(struct v4l2_fh *fh,
16585f5fe39SHans Verkuil 			   const struct v4l2_event_subscription *sub);
1669d4ee1adSMauro Carvalho Chehab /**
1679d4ee1adSMauro Carvalho Chehab  * v4l2_event_unsubscribe_all - Unsubscribes to all events
1689d4ee1adSMauro Carvalho Chehab  *
1699d4ee1adSMauro Carvalho Chehab  * @fh: pointer to &struct v4l2_fh
1709d4ee1adSMauro Carvalho Chehab  */
171f1e393deSHans Verkuil void v4l2_event_unsubscribe_all(struct v4l2_fh *fh);
1729d4ee1adSMauro Carvalho Chehab 
1739d4ee1adSMauro Carvalho Chehab /**
1749d4ee1adSMauro Carvalho Chehab  * v4l2_event_subdev_unsubscribe - Subdev variant of v4l2_event_unsubscribe()
1759d4ee1adSMauro Carvalho Chehab  *
1769d4ee1adSMauro Carvalho Chehab  * @sd: pointer to &struct v4l2_subdev
1779d4ee1adSMauro Carvalho Chehab  * @fh: pointer to &struct v4l2_fh
1789d4ee1adSMauro Carvalho Chehab  * @sub: pointer to &struct v4l2_event_subscription
1799d4ee1adSMauro Carvalho Chehab  *
1809d4ee1adSMauro Carvalho Chehab  * .. note::
1819d4ee1adSMauro Carvalho Chehab  *
1829d4ee1adSMauro Carvalho Chehab  *	This function should be used for the &struct v4l2_subdev_core_ops
1839d4ee1adSMauro Carvalho Chehab  *	%unsubscribe_event field.
1849d4ee1adSMauro Carvalho Chehab  */
1859d4ee1adSMauro Carvalho Chehab int v4l2_event_subdev_unsubscribe(struct v4l2_subdev *sd,
1869d4ee1adSMauro Carvalho Chehab 				  struct v4l2_fh *fh,
1874f4d14b7SSylwester Nawrocki 				  struct v4l2_event_subscription *sub);
1889d4ee1adSMauro Carvalho Chehab /**
189e383ce07SMauro Carvalho Chehab  * v4l2_src_change_event_subscribe - helper function that calls
190e383ce07SMauro Carvalho Chehab  *	v4l2_event_subscribe() if the event is %V4L2_EVENT_SOURCE_CHANGE.
1919d4ee1adSMauro Carvalho Chehab  *
1929d4ee1adSMauro Carvalho Chehab  * @fh: pointer to struct v4l2_fh
1939d4ee1adSMauro Carvalho Chehab  * @sub: pointer to &struct v4l2_event_subscription
1949d4ee1adSMauro Carvalho Chehab  */
1953cbe6e5bSArun Kumar K int v4l2_src_change_event_subscribe(struct v4l2_fh *fh,
1963cbe6e5bSArun Kumar K 				    const struct v4l2_event_subscription *sub);
1979d4ee1adSMauro Carvalho Chehab /**
1989d4ee1adSMauro Carvalho Chehab  * v4l2_src_change_event_subdev_subscribe - Variant of v4l2_event_subscribe(),
1999d4ee1adSMauro Carvalho Chehab  *	meant to subscribe only events of the type %V4L2_EVENT_SOURCE_CHANGE.
2009d4ee1adSMauro Carvalho Chehab  *
2019d4ee1adSMauro Carvalho Chehab  * @sd: pointer to &struct v4l2_subdev
2029d4ee1adSMauro Carvalho Chehab  * @fh: pointer to &struct v4l2_fh
2039d4ee1adSMauro Carvalho Chehab  * @sub: pointer to &struct v4l2_event_subscription
2049d4ee1adSMauro Carvalho Chehab  */
2053cbe6e5bSArun Kumar K int v4l2_src_change_event_subdev_subscribe(struct v4l2_subdev *sd,
2069d4ee1adSMauro Carvalho Chehab 					   struct v4l2_fh *fh,
2079d4ee1adSMauro Carvalho Chehab 					   struct v4l2_event_subscription *sub);
208c3b5b024SSakari Ailus #endif /* V4L2_EVENT_H */
209