]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - include/media/v4l2-dev.h
V4L/DVB (9973): v4l2-dev: use the release callback from device instead of cdev
[mirror_ubuntu-artful-kernel.git] / include / media / v4l2-dev.h
CommitLineData
401998fa
MCC
1/*
2 *
3 * V 4 L 2 D R I V E R H E L P E R A P I
4 *
5 * Moved from videodev2.h
6 *
7 * Some commonly needed functions for drivers (v4l2-common.o module)
8 */
9#ifndef _V4L2_DEV_H
10#define _V4L2_DEV_H
11
401998fa
MCC
12#include <linux/poll.h>
13#include <linux/fs.h>
14#include <linux/device.h>
7f8ecfab 15#include <linux/cdev.h>
401998fa 16#include <linux/mutex.h>
401998fa 17#include <linux/videodev2.h>
401998fa 18
401998fa 19#define VIDEO_MAJOR 81
bfa8a273 20
401998fa
MCC
21#define VFL_TYPE_GRABBER 0
22#define VFL_TYPE_VBI 1
23#define VFL_TYPE_RADIO 2
24#define VFL_TYPE_VTX 3
dd89601d 25#define VFL_TYPE_MAX 4
401998fa 26
a399810c
HV
27struct v4l2_ioctl_callbacks;
28
dc93a70c
HV
29/* Flag to mark the video_device struct as unregistered.
30 Drivers can set this flag if they want to block all future
31 device access. It is set by video_unregister_device. */
32#define V4L2_FL_UNREGISTERED (0)
33
401998fa
MCC
34/*
35 * Newer version of video_device, handled by videodev2.c
36 * This version moves redundant code from video device code to
37 * the common handler
38 */
401998fa
MCC
39
40struct video_device
41{
42 /* device ops */
5e87efa3 43 const struct file_operations *fops;
401998fa 44
54bd5b66 45 /* sysfs */
22a04f10 46 struct device dev; /* v4l device */
dc93a70c 47 struct cdev *cdev; /* character device */
5e85e732 48 struct device *parent; /* device parent */
54bd5b66 49
401998fa 50 /* device info */
401998fa 51 char name[32];
0ea6bc8d 52 int vfl_type;
dc93a70c 53 /* 'minor' is set to -1 if the registration failed */
401998fa 54 int minor;
dd89601d 55 u16 num;
dc93a70c
HV
56 /* use bitops to set/clear/test flags */
57 unsigned long flags;
de1e575d 58 /* attribute to differentiate multiple indices on one physical device */
539a7555 59 int index;
401998fa 60
22a04f10 61 int debug; /* Activates debug level*/
401998fa
MCC
62
63 /* Video standard vars */
e75f9cee
MCC
64 v4l2_std_id tvnorms; /* Supported tv norms */
65 v4l2_std_id current_norm; /* Current tvnorm */
401998fa
MCC
66
67 /* callbacks */
dc93a70c 68 void (*release)(struct video_device *vdev);
401998fa
MCC
69
70 /* ioctl callbacks */
a399810c 71 const struct v4l2_ioctl_ops *ioctl_ops;
401998fa
MCC
72};
73
bfa8a273 74/* dev to video-device */
22a04f10 75#define to_video_device(cd) container_of(cd, struct video_device, dev)
e90ff923 76
dc93a70c 77/* Register video devices. Note that if video_register_device fails,
bfa8a273
HV
78 the release() callback of the video_device structure is *not* called, so
79 the caller is responsible for freeing any data. Usually that means that
dc93a70c
HV
80 you call video_device_release() on failure.
81
82 Also note that vdev->minor is set to -1 if the registration failed. */
83int __must_check video_register_device(struct video_device *vdev, int type, int nr);
84int __must_check video_register_device_index(struct video_device *vdev,
bfa8a273 85 int type, int nr, int index);
dc93a70c
HV
86
87/* Unregister video devices. Will do nothing if vdev == NULL or
88 vdev->minor < 0. */
89void video_unregister_device(struct video_device *vdev);
401998fa 90
bfa8a273
HV
91/* helper functions to alloc/release struct video_device, the
92 latter can also be used for video_device->release(). */
e138c592 93struct video_device * __must_check video_device_alloc(void);
bfa8a273 94
dc93a70c
HV
95/* this release function frees the vdev pointer */
96void video_device_release(struct video_device *vdev);
bfa8a273 97
f9e86b5e
HV
98/* this release function does nothing, use when the video_device is a
99 static global struct. Note that having a static video_device is
100 a dubious construction at best. */
dc93a70c 101void video_device_release_empty(struct video_device *vdev);
401998fa 102
401998fa 103/* helper functions to access driver private data. */
dc93a70c 104static inline void *video_get_drvdata(struct video_device *vdev)
401998fa 105{
dc93a70c 106 return dev_get_drvdata(&vdev->dev);
401998fa
MCC
107}
108
dc93a70c 109static inline void video_set_drvdata(struct video_device *vdev, void *data)
401998fa 110{
dc93a70c 111 dev_set_drvdata(&vdev->dev, data);
401998fa 112}
38ee04f0 113
bfa8a273
HV
114struct video_device *video_devdata(struct file *file);
115
116/* Combine video_get_drvdata and video_devdata as this is
117 used very often. */
118static inline void *video_drvdata(struct file *file)
119{
120 return video_get_drvdata(video_devdata(file));
121}
401998fa 122
dc93a70c
HV
123static inline int video_is_unregistered(struct video_device *vdev)
124{
125 return test_bit(V4L2_FL_UNREGISTERED, &vdev->flags);
126}
127
401998fa 128#endif /* _V4L2_DEV_H */