4 * A generic video device interface for the LINUX operating system
5 * using a set of device structures/vectors for low level operations.
7 * This file replaces the videodev.c file that comes with the
8 * regular kernel distribution.
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
15 * Author: Bill Dirks <bdirks@pacbell.net>
16 * based on code by Alan Cox, <alan@cymru.net>
21 * Video capture interface for Linux
23 * A generic video device interface for the LINUX operating system
24 * using a set of device structures/vectors for low level operations.
26 * This program is free software; you can redistribute it and/or
27 * modify it under the terms of the GNU General Public License
28 * as published by the Free Software Foundation; either version
29 * 2 of the License, or (at your option) any later version.
31 * Author: Alan Cox, <alan@redhat.com>
37 * Video4linux 1/2 integration by Justin Schoeman
38 * <justin@suntiger.ee.up.ac.za>
39 * 2.4 PROCFS support ported from 2.4 kernels by
40 * Iñaki García Etxebarria <garetxe@euskalnet.net>
41 * Makefile fix by "W. Michael Petullo" <mike@flyn.org>
42 * 2.4 devfs support ported from 2.4 kernels by
43 * Dan Merillat <dan@merillat.org>
44 * Added Gerd Knorrs v4l1 enhancements (Justin Schoeman)
47 #include <linux/config.h>
48 #include <linux/module.h>
49 #include <linux/types.h>
50 #include <linux/kernel.h>
51 #include <linux/sched.h>
52 #include <linux/smp_lock.h>
54 #include <linux/string.h>
55 #include <linux/errno.h>
56 #include <asm/uaccess.h>
57 #include <asm/system.h>
58 #include <asm/pgtable.h>
60 #include <asm/div64.h>
63 #include <linux/kmod.h>
66 #if defined(CONFIG_UST) || defined(CONFIG_UST_MODULE)
67 #include <linux/ust.h>
71 #include <linux/videodev.h>
73 MODULE_AUTHOR("Bill Dirks, Justin Schoeman, Gerd Knorr");
74 MODULE_DESCRIPTION("misc helper functions for v4l2 device drivers");
75 MODULE_LICENSE("GPL");
79 * V 4 L 2 D R I V E R H E L P E R A P I
84 * Video Standard Operations (contributed by Michael Schimek)
87 #if 0 /* seems to have no users */
88 /* This is the recommended method to deal with the framerate fields. More
89 sophisticated drivers will access the fields directly. */
91 v4l2_video_std_fps(struct v4l2_standard *vs)
93 if (vs->frameperiod.numerator > 0)
94 return (((vs->frameperiod.denominator << 8) /
95 vs->frameperiod.numerator) +
99 EXPORT_SYMBOL(v4l2_video_std_fps);
102 /* Fill in the fields of a v4l2_standard structure according to the
103 'id' and 'transmission' parameters. Returns negative on error. */
104 int v4l2_video_std_construct(struct v4l2_standard *vs,
107 u32 index = vs->index;
109 memset(vs, 0, sizeof(struct v4l2_standard));
112 if (id & (V4L2_STD_NTSC | V4L2_STD_PAL_M)) {
113 vs->frameperiod.numerator = 1001;
114 vs->frameperiod.denominator = 30000;
115 vs->framelines = 525;
117 vs->frameperiod.numerator = 1;
118 vs->frameperiod.denominator = 25;
119 vs->framelines = 625;
121 strlcpy(vs->name,name,sizeof(vs->name));
126 /* ----------------------------------------------------------------- */
127 /* priority handling */
129 #define V4L2_PRIO_VALID(val) (val == V4L2_PRIORITY_BACKGROUND || \
130 val == V4L2_PRIORITY_INTERACTIVE || \
131 val == V4L2_PRIORITY_RECORD)
133 int v4l2_prio_init(struct v4l2_prio_state *global)
135 memset(global,0,sizeof(*global));
139 int v4l2_prio_change(struct v4l2_prio_state *global, enum v4l2_priority *local,
140 enum v4l2_priority new)
142 if (!V4L2_PRIO_VALID(new))
147 atomic_inc(&global->prios[new]);
148 if (V4L2_PRIO_VALID(*local))
149 atomic_dec(&global->prios[*local]);
154 int v4l2_prio_open(struct v4l2_prio_state *global, enum v4l2_priority *local)
156 return v4l2_prio_change(global,local,V4L2_PRIORITY_DEFAULT);
159 int v4l2_prio_close(struct v4l2_prio_state *global, enum v4l2_priority *local)
161 if (V4L2_PRIO_VALID(*local))
162 atomic_dec(&global->prios[*local]);
166 enum v4l2_priority v4l2_prio_max(struct v4l2_prio_state *global)
168 if (atomic_read(&global->prios[V4L2_PRIORITY_RECORD]) > 0)
169 return V4L2_PRIORITY_RECORD;
170 if (atomic_read(&global->prios[V4L2_PRIORITY_INTERACTIVE]) > 0)
171 return V4L2_PRIORITY_INTERACTIVE;
172 if (atomic_read(&global->prios[V4L2_PRIORITY_BACKGROUND]) > 0)
173 return V4L2_PRIORITY_BACKGROUND;
174 return V4L2_PRIORITY_UNSET;
177 int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority *local)
179 if (*local < v4l2_prio_max(global))
185 /* ----------------------------------------------------------------- */
186 /* some arrays for pretty-printing debug messages */
188 char *v4l2_field_names[] = {
189 [V4L2_FIELD_ANY] = "any",
190 [V4L2_FIELD_NONE] = "none",
191 [V4L2_FIELD_TOP] = "top",
192 [V4L2_FIELD_BOTTOM] = "bottom",
193 [V4L2_FIELD_INTERLACED] = "interlaced",
194 [V4L2_FIELD_SEQ_TB] = "seq-tb",
195 [V4L2_FIELD_SEQ_BT] = "seq-bt",
196 [V4L2_FIELD_ALTERNATE] = "alternate",
199 char *v4l2_type_names[] = {
200 [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "video-cap",
201 [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "video-over",
202 [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "video-out",
203 [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap",
204 [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out",
207 char *v4l2_ioctl_names[256] = {
209 [0 ... 255] = "UNKNOWN",
211 [_IOC_NR(VIDIOC_QUERYCAP)] = "VIDIOC_QUERYCAP",
212 [_IOC_NR(VIDIOC_RESERVED)] = "VIDIOC_RESERVED",
213 [_IOC_NR(VIDIOC_ENUM_FMT)] = "VIDIOC_ENUM_FMT",
214 [_IOC_NR(VIDIOC_G_FMT)] = "VIDIOC_G_FMT",
215 [_IOC_NR(VIDIOC_S_FMT)] = "VIDIOC_S_FMT",
217 [_IOC_NR(VIDIOC_G_COMP)] = "VIDIOC_G_COMP",
218 [_IOC_NR(VIDIOC_S_COMP)] = "VIDIOC_S_COMP",
220 [_IOC_NR(VIDIOC_REQBUFS)] = "VIDIOC_REQBUFS",
221 [_IOC_NR(VIDIOC_QUERYBUF)] = "VIDIOC_QUERYBUF",
222 [_IOC_NR(VIDIOC_G_FBUF)] = "VIDIOC_G_FBUF",
223 [_IOC_NR(VIDIOC_S_FBUF)] = "VIDIOC_S_FBUF",
224 [_IOC_NR(VIDIOC_OVERLAY)] = "VIDIOC_OVERLAY",
225 [_IOC_NR(VIDIOC_QBUF)] = "VIDIOC_QBUF",
226 [_IOC_NR(VIDIOC_DQBUF)] = "VIDIOC_DQBUF",
227 [_IOC_NR(VIDIOC_STREAMON)] = "VIDIOC_STREAMON",
228 [_IOC_NR(VIDIOC_STREAMOFF)] = "VIDIOC_STREAMOFF",
229 [_IOC_NR(VIDIOC_G_PARM)] = "VIDIOC_G_PARM",
230 [_IOC_NR(VIDIOC_S_PARM)] = "VIDIOC_S_PARM",
231 [_IOC_NR(VIDIOC_G_STD)] = "VIDIOC_G_STD",
232 [_IOC_NR(VIDIOC_S_STD)] = "VIDIOC_S_STD",
233 [_IOC_NR(VIDIOC_ENUMSTD)] = "VIDIOC_ENUMSTD",
234 [_IOC_NR(VIDIOC_ENUMINPUT)] = "VIDIOC_ENUMINPUT",
235 [_IOC_NR(VIDIOC_G_CTRL)] = "VIDIOC_G_CTRL",
236 [_IOC_NR(VIDIOC_S_CTRL)] = "VIDIOC_S_CTRL",
237 [_IOC_NR(VIDIOC_G_TUNER)] = "VIDIOC_G_TUNER",
238 [_IOC_NR(VIDIOC_S_TUNER)] = "VIDIOC_S_TUNER",
239 [_IOC_NR(VIDIOC_G_AUDIO)] = "VIDIOC_G_AUDIO",
240 [_IOC_NR(VIDIOC_S_AUDIO)] = "VIDIOC_S_AUDIO",
241 [_IOC_NR(VIDIOC_QUERYCTRL)] = "VIDIOC_QUERYCTRL",
242 [_IOC_NR(VIDIOC_QUERYMENU)] = "VIDIOC_QUERYMENU",
243 [_IOC_NR(VIDIOC_G_INPUT)] = "VIDIOC_G_INPUT",
244 [_IOC_NR(VIDIOC_S_INPUT)] = "VIDIOC_S_INPUT",
245 [_IOC_NR(VIDIOC_G_OUTPUT)] = "VIDIOC_G_OUTPUT",
246 [_IOC_NR(VIDIOC_S_OUTPUT)] = "VIDIOC_S_OUTPUT",
247 [_IOC_NR(VIDIOC_ENUMOUTPUT)] = "VIDIOC_ENUMOUTPUT",
248 [_IOC_NR(VIDIOC_G_AUDOUT)] = "VIDIOC_G_AUDOUT",
249 [_IOC_NR(VIDIOC_S_AUDOUT)] = "VIDIOC_S_AUDOUT",
250 [_IOC_NR(VIDIOC_G_MODULATOR)] = "VIDIOC_G_MODULATOR",
251 [_IOC_NR(VIDIOC_S_MODULATOR)] = "VIDIOC_S_MODULATOR",
252 [_IOC_NR(VIDIOC_G_FREQUENCY)] = "VIDIOC_G_FREQUENCY",
253 [_IOC_NR(VIDIOC_S_FREQUENCY)] = "VIDIOC_S_FREQUENCY",
254 [_IOC_NR(VIDIOC_CROPCAP)] = "VIDIOC_CROPCAP",
255 [_IOC_NR(VIDIOC_G_CROP)] = "VIDIOC_G_CROP",
256 [_IOC_NR(VIDIOC_S_CROP)] = "VIDIOC_S_CROP",
257 [_IOC_NR(VIDIOC_G_JPEGCOMP)] = "VIDIOC_G_JPEGCOMP",
258 [_IOC_NR(VIDIOC_S_JPEGCOMP)] = "VIDIOC_S_JPEGCOMP",
259 [_IOC_NR(VIDIOC_QUERYSTD)] = "VIDIOC_QUERYSTD",
260 [_IOC_NR(VIDIOC_TRY_FMT)] = "VIDIOC_TRY_FMT",
263 /* ----------------------------------------------------------------- */
265 EXPORT_SYMBOL(v4l2_video_std_construct);
267 EXPORT_SYMBOL(v4l2_prio_init);
268 EXPORT_SYMBOL(v4l2_prio_change);
269 EXPORT_SYMBOL(v4l2_prio_open);
270 EXPORT_SYMBOL(v4l2_prio_close);
271 EXPORT_SYMBOL(v4l2_prio_max);
272 EXPORT_SYMBOL(v4l2_prio_check);
274 EXPORT_SYMBOL(v4l2_field_names);
275 EXPORT_SYMBOL(v4l2_type_names);
276 EXPORT_SYMBOL(v4l2_ioctl_names);