/* SPDX-License-Identifier: GPL-2.0-only */1/*2* v4l2-event.h3*4* V4L2 events.5*6* Copyright (C) 2009--2010 Nokia Corporation.7*8* Contact: Sakari Ailus <[email protected]>9*/1011#ifndef V4L2_EVENT_H12#define V4L2_EVENT_H1314#include <linux/types.h>15#include <linux/videodev2.h>16#include <linux/wait.h>1718struct v4l2_fh;19struct v4l2_subdev;20struct v4l2_subscribed_event;21struct video_device;2223/**24* struct v4l2_kevent - Internal kernel event struct.25* @list: List node for the v4l2_fh->available list.26* @sev: Pointer to parent v4l2_subscribed_event.27* @event: The event itself.28* @ts: The timestamp of the event.29*/30struct v4l2_kevent {31struct list_head list;32struct v4l2_subscribed_event *sev;33struct v4l2_event event;34u64 ts;35};3637/**38* struct v4l2_subscribed_event_ops - Subscribed event operations.39*40* @add: Optional callback, called when a new listener is added41* @del: Optional callback, called when a listener stops listening42* @replace: Optional callback that can replace event 'old' with event 'new'.43* @merge: Optional callback that can merge event 'old' into event 'new'.44*/45struct v4l2_subscribed_event_ops {46int (*add)(struct v4l2_subscribed_event *sev, unsigned int elems);47void (*del)(struct v4l2_subscribed_event *sev);48void (*replace)(struct v4l2_event *old, const struct v4l2_event *new);49void (*merge)(const struct v4l2_event *old, struct v4l2_event *new);50};5152/**53* struct v4l2_subscribed_event - Internal struct representing a subscribed54* event.55*56* @list: List node for the v4l2_fh->subscribed list.57* @type: Event type.58* @id: Associated object ID (e.g. control ID). 0 if there isn't any.59* @flags: Copy of v4l2_event_subscription->flags.60* @fh: Filehandle that subscribed to this event.61* @node: List node that hooks into the object's event list62* (if there is one).63* @ops: v4l2_subscribed_event_ops64* @elems: The number of elements in the events array.65* @first: The index of the events containing the oldest available event.66* @in_use: The number of queued events.67* @events: An array of @elems events.68*/69struct v4l2_subscribed_event {70struct list_head list;71u32 type;72u32 id;73u32 flags;74struct v4l2_fh *fh;75struct list_head node;76const struct v4l2_subscribed_event_ops *ops;77unsigned int elems;78unsigned int first;79unsigned int in_use;80struct v4l2_kevent events[] __counted_by(elems);81};8283/**84* v4l2_event_dequeue - Dequeue events from video device.85*86* @fh: pointer to struct v4l2_fh87* @event: pointer to struct v4l2_event88* @nonblocking: if not zero, waits for an event to arrive89*/90int v4l2_event_dequeue(struct v4l2_fh *fh, struct v4l2_event *event,91int nonblocking);9293/**94* v4l2_event_queue - Queue events to video device.95*96* @vdev: pointer to &struct video_device97* @ev: pointer to &struct v4l2_event98*99* The event will be queued for all &struct v4l2_fh file handlers.100*101* .. note::102* The driver's only responsibility is to fill in the type and the data103* fields. The other fields will be filled in by V4L2.104*/105void v4l2_event_queue(struct video_device *vdev, const struct v4l2_event *ev);106107/**108* v4l2_event_queue_fh - Queue events to video device.109*110* @fh: pointer to &struct v4l2_fh111* @ev: pointer to &struct v4l2_event112*113*114* The event will be queued only for the specified &struct v4l2_fh file handler.115*116* .. note::117* The driver's only responsibility is to fill in the type and the data118* fields. The other fields will be filled in by V4L2.119*/120void v4l2_event_queue_fh(struct v4l2_fh *fh, const struct v4l2_event *ev);121122/**123* v4l2_event_wake_all - Wake all filehandles.124*125* Used when unregistering a video device.126*127* @vdev: pointer to &struct video_device128*/129void v4l2_event_wake_all(struct video_device *vdev);130131/**132* v4l2_event_pending - Check if an event is available133*134* @fh: pointer to &struct v4l2_fh135*136* Returns the number of pending events.137*/138int v4l2_event_pending(struct v4l2_fh *fh);139140/**141* v4l2_event_subscribe - Subscribes to an event142*143* @fh: pointer to &struct v4l2_fh144* @sub: pointer to &struct v4l2_event_subscription145* @elems: size of the events queue146* @ops: pointer to &v4l2_subscribed_event_ops147*148* .. note::149*150* if @elems is zero, the framework will fill in a default value,151* with is currently 1 element.152*/153int v4l2_event_subscribe(struct v4l2_fh *fh,154const struct v4l2_event_subscription *sub,155unsigned int elems,156const struct v4l2_subscribed_event_ops *ops);157/**158* v4l2_event_unsubscribe - Unsubscribes to an event159*160* @fh: pointer to &struct v4l2_fh161* @sub: pointer to &struct v4l2_event_subscription162*/163int v4l2_event_unsubscribe(struct v4l2_fh *fh,164const struct v4l2_event_subscription *sub);165/**166* v4l2_event_unsubscribe_all - Unsubscribes to all events167*168* @fh: pointer to &struct v4l2_fh169*/170void v4l2_event_unsubscribe_all(struct v4l2_fh *fh);171172/**173* v4l2_event_subdev_unsubscribe - Subdev variant of v4l2_event_unsubscribe()174*175* @sd: pointer to &struct v4l2_subdev176* @fh: pointer to &struct v4l2_fh177* @sub: pointer to &struct v4l2_event_subscription178*179* .. note::180*181* This function should be used for the &struct v4l2_subdev_core_ops182* %unsubscribe_event field.183*/184int v4l2_event_subdev_unsubscribe(struct v4l2_subdev *sd,185struct v4l2_fh *fh,186struct v4l2_event_subscription *sub);187/**188* v4l2_src_change_event_subscribe - helper function that calls189* v4l2_event_subscribe() if the event is %V4L2_EVENT_SOURCE_CHANGE.190*191* @fh: pointer to struct v4l2_fh192* @sub: pointer to &struct v4l2_event_subscription193*/194int v4l2_src_change_event_subscribe(struct v4l2_fh *fh,195const struct v4l2_event_subscription *sub);196/**197* v4l2_src_change_event_subdev_subscribe - Variant of v4l2_event_subscribe(),198* meant to subscribe only events of the type %V4L2_EVENT_SOURCE_CHANGE.199*200* @sd: pointer to &struct v4l2_subdev201* @fh: pointer to &struct v4l2_fh202* @sub: pointer to &struct v4l2_event_subscription203*/204int v4l2_src_change_event_subdev_subscribe(struct v4l2_subdev *sd,205struct v4l2_fh *fh,206struct v4l2_event_subscription *sub);207#endif /* V4L2_EVENT_H */208209210