1
2
3
4
5
6
7
8
9#ifndef _V4L2_DEV_H
10#define _V4L2_DEV_H
11
12#include <linux/poll.h>
13#include <linux/fs.h>
14#include <linux/device.h>
15#include <linux/cdev.h>
16#include <linux/mutex.h>
17#include <linux/videodev2.h>
18
19#include <media/media-entity.h>
20
21#define VIDEO_MAJOR 81
22
23#define VFL_TYPE_GRABBER 0
24#define VFL_TYPE_VBI 1
25#define VFL_TYPE_RADIO 2
26#define VFL_TYPE_SUBDEV 3
27#define VFL_TYPE_MAX 4
28
29struct v4l2_ioctl_callbacks;
30struct video_device;
31struct v4l2_device;
32struct v4l2_ctrl_handler;
33
34
35
36
37#define V4L2_FL_REGISTERED (0)
38
39#define V4L2_FL_USES_V4L2_FH (1)
40
41#define V4L2_FL_USE_FH_PRIO (2)
42
43
44
45struct v4l2_prio_state {
46 atomic_t prios[4];
47};
48
49void v4l2_prio_init(struct v4l2_prio_state *global);
50int v4l2_prio_change(struct v4l2_prio_state *global, enum v4l2_priority *local,
51 enum v4l2_priority new);
52void v4l2_prio_open(struct v4l2_prio_state *global, enum v4l2_priority *local);
53void v4l2_prio_close(struct v4l2_prio_state *global, enum v4l2_priority local);
54enum v4l2_priority v4l2_prio_max(struct v4l2_prio_state *global);
55int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local);
56
57
58struct v4l2_file_operations {
59 struct module *owner;
60 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
61 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
62 unsigned int (*poll) (struct file *, struct poll_table_struct *);
63 long (*ioctl) (struct file *, unsigned int, unsigned long);
64 long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
65#ifdef CONFIG_COMPAT
66 long (*compat_ioctl32) (struct file *, unsigned int, unsigned long);
67#endif
68 unsigned long (*get_unmapped_area) (struct file *, unsigned long,
69 unsigned long, unsigned long, unsigned long);
70 int (*mmap) (struct file *, struct vm_area_struct *);
71 int (*open) (struct file *);
72 int (*release) (struct file *);
73};
74
75
76
77
78
79
80
81struct video_device
82{
83#if defined(CONFIG_MEDIA_CONTROLLER)
84 struct media_entity entity;
85#endif
86
87 const struct v4l2_file_operations *fops;
88
89
90 struct device dev;
91 struct cdev *cdev;
92
93
94 struct device *parent;
95 struct v4l2_device *v4l2_dev;
96
97
98 struct v4l2_ctrl_handler *ctrl_handler;
99
100
101 struct v4l2_prio_state *prio;
102
103
104 char name[32];
105 int vfl_type;
106
107 int minor;
108 u16 num;
109
110 unsigned long flags;
111
112 int index;
113
114
115 spinlock_t fh_lock;
116 struct list_head fh_list;
117
118 int debug;
119
120
121 v4l2_std_id tvnorms;
122 v4l2_std_id current_norm;
123
124
125 void (*release)(struct video_device *vdev);
126
127
128 const struct v4l2_ioctl_ops *ioctl_ops;
129
130
131 struct mutex *lock;
132};
133
134#define media_entity_to_video_device(__e) \
135 container_of(__e, struct video_device, entity)
136
137#define to_video_device(cd) container_of(cd, struct video_device, dev)
138
139int __must_check __video_register_device(struct video_device *vdev, int type,
140 int nr, int warn_if_nr_in_use, struct module *owner);
141
142
143
144
145
146static inline int __must_check video_register_device(struct video_device *vdev,
147 int type, int nr)
148{
149 return __video_register_device(vdev, type, nr, 1, vdev->fops->owner);
150}
151
152
153
154static inline int __must_check video_register_device_no_warn(
155 struct video_device *vdev, int type, int nr)
156{
157 return __video_register_device(vdev, type, nr, 0, vdev->fops->owner);
158}
159
160
161
162void video_unregister_device(struct video_device *vdev);
163
164
165
166struct video_device * __must_check video_device_alloc(void);
167
168
169void video_device_release(struct video_device *vdev);
170
171
172
173
174void video_device_release_empty(struct video_device *vdev);
175
176
177static inline void *video_get_drvdata(struct video_device *vdev)
178{
179 return dev_get_drvdata(&vdev->dev);
180}
181
182static inline void video_set_drvdata(struct video_device *vdev, void *data)
183{
184 dev_set_drvdata(&vdev->dev, data);
185}
186
187struct video_device *video_devdata(struct file *file);
188
189
190
191static inline void *video_drvdata(struct file *file)
192{
193 return video_get_drvdata(video_devdata(file));
194}
195
196static inline const char *video_device_node_name(struct video_device *vdev)
197{
198 return dev_name(&vdev->dev);
199}
200
201static inline int video_is_registered(struct video_device *vdev)
202{
203 return test_bit(V4L2_FL_REGISTERED, &vdev->flags);
204}
205
206#endif
207