Skip to content

Commit 98ec633

Browse files
Hans VerkuilMauro Carvalho Chehab
authored andcommitted
V4L/DVB (11021): v4l2-device: add a notify callback.
Add a notify callback to v4l2_device to let sub-devices notify their parent of special events. Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
1 parent 0057596 commit 98ec633

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

‎Documentation/video4linux/v4l2-framework.txt‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ usb_device or platform_device. It is rare for dev to be NULL, but it happens
9494
with ISA devices or when one device creates multiple PCI devices, thus making
9595
it impossible to associate v4l2_dev with a particular parent.
9696

97+
You can also supply a notify() callback that can be called by sub-devices to
98+
notify you of events. Whether you need to set this depends on the sub-device.
99+
Any notifications a sub-device supports must be defined in a header in
100+
include/media/<subdevice>.h.
101+
97102
You unregister with:
98103

99104
v4l2_device_unregister(struct v4l2_device *v4l2_dev);
@@ -281,6 +286,11 @@ e.g. AUDIO_CONTROLLER and specify that as the group ID value when calling
281286
v4l2_device_call_all(). That ensures that it will only go to the subdev
282287
that needs it.
283288

289+
If the sub-device needs to notify its v4l2_device parent of an event, then
290+
it can call v4l2_subdev_notify(sd, notification, arg). This macro checks
291+
whether there is a notify() callback defined and returns -ENODEV if not.
292+
Otherwise the result of the notify() call is returned.
293+
284294
The advantage of using v4l2_subdev is that it is a generic struct and does
285295
not contain any knowledge about the underlying hardware. So a driver might
286296
contain several subdevs that use an I2C bus, but also a subdev that is

‎include/media/v4l2-device.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ struct v4l2_device {
4444
spinlock_t lock;
4545
/* unique device name, by default the driver name + bus ID */
4646
char name[V4L2_DEVICE_NAME_SIZE];
47+
/* notify callback called by some sub-devices. */
48+
void (*notify)(struct v4l2_subdev *sd,
49+
unsigned int notification, void *arg);
4750
};
4851

4952
/* Initialize v4l2_dev and make dev->driver_data point to v4l2_dev.

‎include/media/v4l2-subdev.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,9 @@ static inline void v4l2_subdev_init(struct v4l2_subdev *sd,
191191
(!(sd) ? -ENODEV : (((sd) && (sd)->ops->o && (sd)->ops->o->f) ? \
192192
(sd)->ops->o->f((sd) , ##args) : -ENOIOCTLCMD))
193193

194+
/* Send a notification to v4l2_device. */
195+
#define v4l2_subdev_notify(sd, notification, arg) \
196+
((!(sd) || !(sd)->v4l2_dev || !(sd)->v4l2_dev->notify) ? -ENODEV : \
197+
(sd)->v4l2_dev->notify((sd), (notification), (arg)))
198+
194199
#endif

0 commit comments

Comments
 (0)