18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * v4l2-event.h 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * V4L2 events. 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Copyright (C) 2009--2010 Nokia Corporation. 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * Contact: Sakari Ailus <sakari.ailus@iki.fi> 108c2ecf20Sopenharmony_ci */ 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#ifndef V4L2_EVENT_H 138c2ecf20Sopenharmony_ci#define V4L2_EVENT_H 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#include <linux/types.h> 168c2ecf20Sopenharmony_ci#include <linux/videodev2.h> 178c2ecf20Sopenharmony_ci#include <linux/wait.h> 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_cistruct v4l2_fh; 208c2ecf20Sopenharmony_cistruct v4l2_subdev; 218c2ecf20Sopenharmony_cistruct v4l2_subscribed_event; 228c2ecf20Sopenharmony_cistruct video_device; 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci/** 258c2ecf20Sopenharmony_ci * struct v4l2_kevent - Internal kernel event struct. 268c2ecf20Sopenharmony_ci * @list: List node for the v4l2_fh->available list. 278c2ecf20Sopenharmony_ci * @sev: Pointer to parent v4l2_subscribed_event. 288c2ecf20Sopenharmony_ci * @event: The event itself. 298c2ecf20Sopenharmony_ci * @ts: The timestamp of the event. 308c2ecf20Sopenharmony_ci */ 318c2ecf20Sopenharmony_cistruct v4l2_kevent { 328c2ecf20Sopenharmony_ci struct list_head list; 338c2ecf20Sopenharmony_ci struct v4l2_subscribed_event *sev; 348c2ecf20Sopenharmony_ci struct v4l2_event event; 358c2ecf20Sopenharmony_ci u64 ts; 368c2ecf20Sopenharmony_ci}; 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci/** 398c2ecf20Sopenharmony_ci * struct v4l2_subscribed_event_ops - Subscribed event operations. 408c2ecf20Sopenharmony_ci * 418c2ecf20Sopenharmony_ci * @add: Optional callback, called when a new listener is added 428c2ecf20Sopenharmony_ci * @del: Optional callback, called when a listener stops listening 438c2ecf20Sopenharmony_ci * @replace: Optional callback that can replace event 'old' with event 'new'. 448c2ecf20Sopenharmony_ci * @merge: Optional callback that can merge event 'old' into event 'new'. 458c2ecf20Sopenharmony_ci */ 468c2ecf20Sopenharmony_cistruct v4l2_subscribed_event_ops { 478c2ecf20Sopenharmony_ci int (*add)(struct v4l2_subscribed_event *sev, unsigned int elems); 488c2ecf20Sopenharmony_ci void (*del)(struct v4l2_subscribed_event *sev); 498c2ecf20Sopenharmony_ci void (*replace)(struct v4l2_event *old, const struct v4l2_event *new); 508c2ecf20Sopenharmony_ci void (*merge)(const struct v4l2_event *old, struct v4l2_event *new); 518c2ecf20Sopenharmony_ci}; 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci/** 548c2ecf20Sopenharmony_ci * struct v4l2_subscribed_event - Internal struct representing a subscribed 558c2ecf20Sopenharmony_ci * event. 568c2ecf20Sopenharmony_ci * 578c2ecf20Sopenharmony_ci * @list: List node for the v4l2_fh->subscribed list. 588c2ecf20Sopenharmony_ci * @type: Event type. 598c2ecf20Sopenharmony_ci * @id: Associated object ID (e.g. control ID). 0 if there isn't any. 608c2ecf20Sopenharmony_ci * @flags: Copy of v4l2_event_subscription->flags. 618c2ecf20Sopenharmony_ci * @fh: Filehandle that subscribed to this event. 628c2ecf20Sopenharmony_ci * @node: List node that hooks into the object's event list 638c2ecf20Sopenharmony_ci * (if there is one). 648c2ecf20Sopenharmony_ci * @ops: v4l2_subscribed_event_ops 658c2ecf20Sopenharmony_ci * @elems: The number of elements in the events array. 668c2ecf20Sopenharmony_ci * @first: The index of the events containing the oldest available event. 678c2ecf20Sopenharmony_ci * @in_use: The number of queued events. 688c2ecf20Sopenharmony_ci * @events: An array of @elems events. 698c2ecf20Sopenharmony_ci */ 708c2ecf20Sopenharmony_cistruct v4l2_subscribed_event { 718c2ecf20Sopenharmony_ci struct list_head list; 728c2ecf20Sopenharmony_ci u32 type; 738c2ecf20Sopenharmony_ci u32 id; 748c2ecf20Sopenharmony_ci u32 flags; 758c2ecf20Sopenharmony_ci struct v4l2_fh *fh; 768c2ecf20Sopenharmony_ci struct list_head node; 778c2ecf20Sopenharmony_ci const struct v4l2_subscribed_event_ops *ops; 788c2ecf20Sopenharmony_ci unsigned int elems; 798c2ecf20Sopenharmony_ci unsigned int first; 808c2ecf20Sopenharmony_ci unsigned int in_use; 818c2ecf20Sopenharmony_ci struct v4l2_kevent events[]; 828c2ecf20Sopenharmony_ci}; 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci/** 858c2ecf20Sopenharmony_ci * v4l2_event_dequeue - Dequeue events from video device. 868c2ecf20Sopenharmony_ci * 878c2ecf20Sopenharmony_ci * @fh: pointer to struct v4l2_fh 888c2ecf20Sopenharmony_ci * @event: pointer to struct v4l2_event 898c2ecf20Sopenharmony_ci * @nonblocking: if not zero, waits for an event to arrive 908c2ecf20Sopenharmony_ci */ 918c2ecf20Sopenharmony_ciint v4l2_event_dequeue(struct v4l2_fh *fh, struct v4l2_event *event, 928c2ecf20Sopenharmony_ci int nonblocking); 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci/** 958c2ecf20Sopenharmony_ci * v4l2_event_queue - Queue events to video device. 968c2ecf20Sopenharmony_ci * 978c2ecf20Sopenharmony_ci * @vdev: pointer to &struct video_device 988c2ecf20Sopenharmony_ci * @ev: pointer to &struct v4l2_event 998c2ecf20Sopenharmony_ci * 1008c2ecf20Sopenharmony_ci * The event will be queued for all &struct v4l2_fh file handlers. 1018c2ecf20Sopenharmony_ci * 1028c2ecf20Sopenharmony_ci * .. note:: 1038c2ecf20Sopenharmony_ci * The driver's only responsibility is to fill in the type and the data 1048c2ecf20Sopenharmony_ci * fields.The other fields will be filled in by V4L2. 1058c2ecf20Sopenharmony_ci */ 1068c2ecf20Sopenharmony_civoid v4l2_event_queue(struct video_device *vdev, const struct v4l2_event *ev); 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci/** 1098c2ecf20Sopenharmony_ci * v4l2_event_queue_fh - Queue events to video device. 1108c2ecf20Sopenharmony_ci * 1118c2ecf20Sopenharmony_ci * @fh: pointer to &struct v4l2_fh 1128c2ecf20Sopenharmony_ci * @ev: pointer to &struct v4l2_event 1138c2ecf20Sopenharmony_ci * 1148c2ecf20Sopenharmony_ci * 1158c2ecf20Sopenharmony_ci * The event will be queued only for the specified &struct v4l2_fh file handler. 1168c2ecf20Sopenharmony_ci * 1178c2ecf20Sopenharmony_ci * .. note:: 1188c2ecf20Sopenharmony_ci * The driver's only responsibility is to fill in the type and the data 1198c2ecf20Sopenharmony_ci * fields.The other fields will be filled in by V4L2. 1208c2ecf20Sopenharmony_ci */ 1218c2ecf20Sopenharmony_civoid v4l2_event_queue_fh(struct v4l2_fh *fh, const struct v4l2_event *ev); 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci/** 1248c2ecf20Sopenharmony_ci * v4l2_event_pending - Check if an event is available 1258c2ecf20Sopenharmony_ci * 1268c2ecf20Sopenharmony_ci * @fh: pointer to &struct v4l2_fh 1278c2ecf20Sopenharmony_ci * 1288c2ecf20Sopenharmony_ci * Returns the number of pending events. 1298c2ecf20Sopenharmony_ci */ 1308c2ecf20Sopenharmony_ciint v4l2_event_pending(struct v4l2_fh *fh); 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci/** 1338c2ecf20Sopenharmony_ci * v4l2_event_subscribe - Subscribes to an event 1348c2ecf20Sopenharmony_ci * 1358c2ecf20Sopenharmony_ci * @fh: pointer to &struct v4l2_fh 1368c2ecf20Sopenharmony_ci * @sub: pointer to &struct v4l2_event_subscription 1378c2ecf20Sopenharmony_ci * @elems: size of the events queue 1388c2ecf20Sopenharmony_ci * @ops: pointer to &v4l2_subscribed_event_ops 1398c2ecf20Sopenharmony_ci * 1408c2ecf20Sopenharmony_ci * .. note:: 1418c2ecf20Sopenharmony_ci * 1428c2ecf20Sopenharmony_ci * if @elems is zero, the framework will fill in a default value, 1438c2ecf20Sopenharmony_ci * with is currently 1 element. 1448c2ecf20Sopenharmony_ci */ 1458c2ecf20Sopenharmony_ciint v4l2_event_subscribe(struct v4l2_fh *fh, 1468c2ecf20Sopenharmony_ci const struct v4l2_event_subscription *sub, 1478c2ecf20Sopenharmony_ci unsigned int elems, 1488c2ecf20Sopenharmony_ci const struct v4l2_subscribed_event_ops *ops); 1498c2ecf20Sopenharmony_ci/** 1508c2ecf20Sopenharmony_ci * v4l2_event_unsubscribe - Unsubscribes to an event 1518c2ecf20Sopenharmony_ci * 1528c2ecf20Sopenharmony_ci * @fh: pointer to &struct v4l2_fh 1538c2ecf20Sopenharmony_ci * @sub: pointer to &struct v4l2_event_subscription 1548c2ecf20Sopenharmony_ci */ 1558c2ecf20Sopenharmony_ciint v4l2_event_unsubscribe(struct v4l2_fh *fh, 1568c2ecf20Sopenharmony_ci const struct v4l2_event_subscription *sub); 1578c2ecf20Sopenharmony_ci/** 1588c2ecf20Sopenharmony_ci * v4l2_event_unsubscribe_all - Unsubscribes to all events 1598c2ecf20Sopenharmony_ci * 1608c2ecf20Sopenharmony_ci * @fh: pointer to &struct v4l2_fh 1618c2ecf20Sopenharmony_ci */ 1628c2ecf20Sopenharmony_civoid v4l2_event_unsubscribe_all(struct v4l2_fh *fh); 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci/** 1658c2ecf20Sopenharmony_ci * v4l2_event_subdev_unsubscribe - Subdev variant of v4l2_event_unsubscribe() 1668c2ecf20Sopenharmony_ci * 1678c2ecf20Sopenharmony_ci * @sd: pointer to &struct v4l2_subdev 1688c2ecf20Sopenharmony_ci * @fh: pointer to &struct v4l2_fh 1698c2ecf20Sopenharmony_ci * @sub: pointer to &struct v4l2_event_subscription 1708c2ecf20Sopenharmony_ci * 1718c2ecf20Sopenharmony_ci * .. note:: 1728c2ecf20Sopenharmony_ci * 1738c2ecf20Sopenharmony_ci * This function should be used for the &struct v4l2_subdev_core_ops 1748c2ecf20Sopenharmony_ci * %unsubscribe_event field. 1758c2ecf20Sopenharmony_ci */ 1768c2ecf20Sopenharmony_ciint v4l2_event_subdev_unsubscribe(struct v4l2_subdev *sd, 1778c2ecf20Sopenharmony_ci struct v4l2_fh *fh, 1788c2ecf20Sopenharmony_ci struct v4l2_event_subscription *sub); 1798c2ecf20Sopenharmony_ci/** 1808c2ecf20Sopenharmony_ci * v4l2_src_change_event_subscribe - helper function that calls 1818c2ecf20Sopenharmony_ci * v4l2_event_subscribe() if the event is %V4L2_EVENT_SOURCE_CHANGE. 1828c2ecf20Sopenharmony_ci * 1838c2ecf20Sopenharmony_ci * @fh: pointer to struct v4l2_fh 1848c2ecf20Sopenharmony_ci * @sub: pointer to &struct v4l2_event_subscription 1858c2ecf20Sopenharmony_ci */ 1868c2ecf20Sopenharmony_ciint v4l2_src_change_event_subscribe(struct v4l2_fh *fh, 1878c2ecf20Sopenharmony_ci const struct v4l2_event_subscription *sub); 1888c2ecf20Sopenharmony_ci/** 1898c2ecf20Sopenharmony_ci * v4l2_src_change_event_subdev_subscribe - Variant of v4l2_event_subscribe(), 1908c2ecf20Sopenharmony_ci * meant to subscribe only events of the type %V4L2_EVENT_SOURCE_CHANGE. 1918c2ecf20Sopenharmony_ci * 1928c2ecf20Sopenharmony_ci * @sd: pointer to &struct v4l2_subdev 1938c2ecf20Sopenharmony_ci * @fh: pointer to &struct v4l2_fh 1948c2ecf20Sopenharmony_ci * @sub: pointer to &struct v4l2_event_subscription 1958c2ecf20Sopenharmony_ci */ 1968c2ecf20Sopenharmony_ciint v4l2_src_change_event_subdev_subscribe(struct v4l2_subdev *sd, 1978c2ecf20Sopenharmony_ci struct v4l2_fh *fh, 1988c2ecf20Sopenharmony_ci struct v4l2_event_subscription *sub); 1998c2ecf20Sopenharmony_ci#endif /* V4L2_EVENT_H */ 200