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