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)
88 /* Fill in the fields of a v4l2_standard structure according to the
89 'id' and 'transmission' parameters. Returns negative on error. */
90 int v4l2_video_std_construct(struct v4l2_standard *vs,
93 u32 index = vs->index;
95 memset(vs, 0, sizeof(struct v4l2_standard));
98 if (id & (V4L2_STD_NTSC | V4L2_STD_PAL_M)) {
99 vs->frameperiod.numerator = 1001;
100 vs->frameperiod.denominator = 30000;
101 vs->framelines = 525;
103 vs->frameperiod.numerator = 1;
104 vs->frameperiod.denominator = 25;
105 vs->framelines = 625;
107 strlcpy(vs->name,name,sizeof(vs->name));
112 /* ----------------------------------------------------------------- */
113 /* priority handling */
115 #define V4L2_PRIO_VALID(val) (val == V4L2_PRIORITY_BACKGROUND || \
116 val == V4L2_PRIORITY_INTERACTIVE || \
117 val == V4L2_PRIORITY_RECORD)
119 int v4l2_prio_init(struct v4l2_prio_state *global)
121 memset(global,0,sizeof(*global));
125 int v4l2_prio_change(struct v4l2_prio_state *global, enum v4l2_priority *local,
126 enum v4l2_priority new)
128 if (!V4L2_PRIO_VALID(new))
133 atomic_inc(&global->prios[new]);
134 if (V4L2_PRIO_VALID(*local))
135 atomic_dec(&global->prios[*local]);
140 int v4l2_prio_open(struct v4l2_prio_state *global, enum v4l2_priority *local)
142 return v4l2_prio_change(global,local,V4L2_PRIORITY_DEFAULT);
145 int v4l2_prio_close(struct v4l2_prio_state *global, enum v4l2_priority *local)
147 if (V4L2_PRIO_VALID(*local))
148 atomic_dec(&global->prios[*local]);
152 enum v4l2_priority v4l2_prio_max(struct v4l2_prio_state *global)
154 if (atomic_read(&global->prios[V4L2_PRIORITY_RECORD]) > 0)
155 return V4L2_PRIORITY_RECORD;
156 if (atomic_read(&global->prios[V4L2_PRIORITY_INTERACTIVE]) > 0)
157 return V4L2_PRIORITY_INTERACTIVE;
158 if (atomic_read(&global->prios[V4L2_PRIORITY_BACKGROUND]) > 0)
159 return V4L2_PRIORITY_BACKGROUND;
160 return V4L2_PRIORITY_UNSET;
163 int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority *local)
165 if (*local < v4l2_prio_max(global))
171 /* ----------------------------------------------------------------- */
172 /* some arrays for pretty-printing debug messages */
174 char *v4l2_field_names[] = {
175 [V4L2_FIELD_ANY] = "any",
176 [V4L2_FIELD_NONE] = "none",
177 [V4L2_FIELD_TOP] = "top",
178 [V4L2_FIELD_BOTTOM] = "bottom",
179 [V4L2_FIELD_INTERLACED] = "interlaced",
180 [V4L2_FIELD_SEQ_TB] = "seq-tb",
181 [V4L2_FIELD_SEQ_BT] = "seq-bt",
182 [V4L2_FIELD_ALTERNATE] = "alternate",
185 char *v4l2_type_names[] = {
186 [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "video-cap",
187 [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "video-over",
188 [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "video-out",
189 [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap",
190 [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out",
193 char *v4l2_ioctl_names[256] = {
195 [0 ... 255] = "UNKNOWN",
197 [_IOC_NR(VIDIOC_QUERYCAP)] = "VIDIOC_QUERYCAP",
198 [_IOC_NR(VIDIOC_RESERVED)] = "VIDIOC_RESERVED",
199 [_IOC_NR(VIDIOC_ENUM_FMT)] = "VIDIOC_ENUM_FMT",
200 [_IOC_NR(VIDIOC_G_FMT)] = "VIDIOC_G_FMT",
201 [_IOC_NR(VIDIOC_S_FMT)] = "VIDIOC_S_FMT",
202 [_IOC_NR(VIDIOC_REQBUFS)] = "VIDIOC_REQBUFS",
203 [_IOC_NR(VIDIOC_QUERYBUF)] = "VIDIOC_QUERYBUF",
204 [_IOC_NR(VIDIOC_G_FBUF)] = "VIDIOC_G_FBUF",
205 [_IOC_NR(VIDIOC_S_FBUF)] = "VIDIOC_S_FBUF",
206 [_IOC_NR(VIDIOC_OVERLAY)] = "VIDIOC_OVERLAY",
207 [_IOC_NR(VIDIOC_QBUF)] = "VIDIOC_QBUF",
208 [_IOC_NR(VIDIOC_DQBUF)] = "VIDIOC_DQBUF",
209 [_IOC_NR(VIDIOC_STREAMON)] = "VIDIOC_STREAMON",
210 [_IOC_NR(VIDIOC_STREAMOFF)] = "VIDIOC_STREAMOFF",
211 [_IOC_NR(VIDIOC_G_PARM)] = "VIDIOC_G_PARM",
212 [_IOC_NR(VIDIOC_S_PARM)] = "VIDIOC_S_PARM",
213 [_IOC_NR(VIDIOC_G_STD)] = "VIDIOC_G_STD",
214 [_IOC_NR(VIDIOC_S_STD)] = "VIDIOC_S_STD",
215 [_IOC_NR(VIDIOC_ENUMSTD)] = "VIDIOC_ENUMSTD",
216 [_IOC_NR(VIDIOC_ENUMINPUT)] = "VIDIOC_ENUMINPUT",
217 [_IOC_NR(VIDIOC_G_CTRL)] = "VIDIOC_G_CTRL",
218 [_IOC_NR(VIDIOC_S_CTRL)] = "VIDIOC_S_CTRL",
219 [_IOC_NR(VIDIOC_G_TUNER)] = "VIDIOC_G_TUNER",
220 [_IOC_NR(VIDIOC_S_TUNER)] = "VIDIOC_S_TUNER",
221 [_IOC_NR(VIDIOC_G_AUDIO)] = "VIDIOC_G_AUDIO",
222 [_IOC_NR(VIDIOC_S_AUDIO)] = "VIDIOC_S_AUDIO",
223 [_IOC_NR(VIDIOC_QUERYCTRL)] = "VIDIOC_QUERYCTRL",
224 [_IOC_NR(VIDIOC_QUERYMENU)] = "VIDIOC_QUERYMENU",
225 [_IOC_NR(VIDIOC_G_INPUT)] = "VIDIOC_G_INPUT",
226 [_IOC_NR(VIDIOC_S_INPUT)] = "VIDIOC_S_INPUT",
227 [_IOC_NR(VIDIOC_G_OUTPUT)] = "VIDIOC_G_OUTPUT",
228 [_IOC_NR(VIDIOC_S_OUTPUT)] = "VIDIOC_S_OUTPUT",
229 [_IOC_NR(VIDIOC_ENUMOUTPUT)] = "VIDIOC_ENUMOUTPUT",
230 [_IOC_NR(VIDIOC_G_AUDOUT)] = "VIDIOC_G_AUDOUT",
231 [_IOC_NR(VIDIOC_S_AUDOUT)] = "VIDIOC_S_AUDOUT",
232 [_IOC_NR(VIDIOC_G_MODULATOR)] = "VIDIOC_G_MODULATOR",
233 [_IOC_NR(VIDIOC_S_MODULATOR)] = "VIDIOC_S_MODULATOR",
234 [_IOC_NR(VIDIOC_G_FREQUENCY)] = "VIDIOC_G_FREQUENCY",
235 [_IOC_NR(VIDIOC_S_FREQUENCY)] = "VIDIOC_S_FREQUENCY",
236 [_IOC_NR(VIDIOC_CROPCAP)] = "VIDIOC_CROPCAP",
237 [_IOC_NR(VIDIOC_G_CROP)] = "VIDIOC_G_CROP",
238 [_IOC_NR(VIDIOC_S_CROP)] = "VIDIOC_S_CROP",
239 [_IOC_NR(VIDIOC_G_JPEGCOMP)] = "VIDIOC_G_JPEGCOMP",
240 [_IOC_NR(VIDIOC_S_JPEGCOMP)] = "VIDIOC_S_JPEGCOMP",
241 [_IOC_NR(VIDIOC_QUERYSTD)] = "VIDIOC_QUERYSTD",
242 [_IOC_NR(VIDIOC_TRY_FMT)] = "VIDIOC_TRY_FMT",
245 /* ----------------------------------------------------------------- */
247 EXPORT_SYMBOL(v4l2_video_std_construct);
249 EXPORT_SYMBOL(v4l2_prio_init);
250 EXPORT_SYMBOL(v4l2_prio_change);
251 EXPORT_SYMBOL(v4l2_prio_open);
252 EXPORT_SYMBOL(v4l2_prio_close);
253 EXPORT_SYMBOL(v4l2_prio_max);
254 EXPORT_SYMBOL(v4l2_prio_check);
256 EXPORT_SYMBOL(v4l2_field_names);
257 EXPORT_SYMBOL(v4l2_type_names);
258 EXPORT_SYMBOL(v4l2_ioctl_names);