]> Pileus Git - ~andy/linux/blob - drivers/media/video/v4l2-common.c
V4L/DVB: v4l2-common: add ability to use v4l2_ctrl_query_fill for chroma gain
[~andy/linux] / drivers / media / video / v4l2-common.c
1 /*
2  *      Video for Linux Two
3  *
4  *      A generic video device interface for the LINUX operating system
5  *      using a set of device structures/vectors for low level operations.
6  *
7  *      This file replaces the videodev.c file that comes with the
8  *      regular kernel distribution.
9  *
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.
14  *
15  * Author:      Bill Dirks <bill@thedirks.org>
16  *              based on code by Alan Cox, <alan@cymru.net>
17  *
18  */
19
20 /*
21  * Video capture interface for Linux
22  *
23  *      A generic video device interface for the LINUX operating system
24  *      using a set of device structures/vectors for low level operations.
25  *
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.
30  *
31  * Author:      Alan Cox, <alan@lxorguk.ukuu.org.uk>
32  *
33  * Fixes:
34  */
35
36 /*
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)
45  */
46
47 #include <linux/module.h>
48 #include <linux/types.h>
49 #include <linux/kernel.h>
50 #include <linux/mm.h>
51 #include <linux/string.h>
52 #include <linux/errno.h>
53 #include <linux/i2c.h>
54 #include <asm/uaccess.h>
55 #include <asm/system.h>
56 #include <asm/pgtable.h>
57 #include <asm/io.h>
58 #include <asm/div64.h>
59 #define __OLD_VIDIOC_ /* To allow fixing old calls*/
60 #include <media/v4l2-common.h>
61 #include <media/v4l2-device.h>
62 #include <media/v4l2-chip-ident.h>
63
64 #include <linux/videodev2.h>
65
66 MODULE_AUTHOR("Bill Dirks, Justin Schoeman, Gerd Knorr");
67 MODULE_DESCRIPTION("misc helper functions for v4l2 device drivers");
68 MODULE_LICENSE("GPL");
69
70 /*
71  *
72  *      V 4 L 2   D R I V E R   H E L P E R   A P I
73  *
74  */
75
76 /*
77  *  Video Standard Operations (contributed by Michael Schimek)
78  */
79
80
81 /* ----------------------------------------------------------------- */
82 /* priority handling                                                 */
83
84 #define V4L2_PRIO_VALID(val) (val == V4L2_PRIORITY_BACKGROUND   || \
85                               val == V4L2_PRIORITY_INTERACTIVE  || \
86                               val == V4L2_PRIORITY_RECORD)
87
88 int v4l2_prio_init(struct v4l2_prio_state *global)
89 {
90         memset(global,0,sizeof(*global));
91         return 0;
92 }
93 EXPORT_SYMBOL(v4l2_prio_init);
94
95 int v4l2_prio_change(struct v4l2_prio_state *global, enum v4l2_priority *local,
96                      enum v4l2_priority new)
97 {
98         if (!V4L2_PRIO_VALID(new))
99                 return -EINVAL;
100         if (*local == new)
101                 return 0;
102
103         atomic_inc(&global->prios[new]);
104         if (V4L2_PRIO_VALID(*local))
105                 atomic_dec(&global->prios[*local]);
106         *local = new;
107         return 0;
108 }
109 EXPORT_SYMBOL(v4l2_prio_change);
110
111 int v4l2_prio_open(struct v4l2_prio_state *global, enum v4l2_priority *local)
112 {
113         return v4l2_prio_change(global,local,V4L2_PRIORITY_DEFAULT);
114 }
115 EXPORT_SYMBOL(v4l2_prio_open);
116
117 int v4l2_prio_close(struct v4l2_prio_state *global, enum v4l2_priority *local)
118 {
119         if (V4L2_PRIO_VALID(*local))
120                 atomic_dec(&global->prios[*local]);
121         return 0;
122 }
123 EXPORT_SYMBOL(v4l2_prio_close);
124
125 enum v4l2_priority v4l2_prio_max(struct v4l2_prio_state *global)
126 {
127         if (atomic_read(&global->prios[V4L2_PRIORITY_RECORD]) > 0)
128                 return V4L2_PRIORITY_RECORD;
129         if (atomic_read(&global->prios[V4L2_PRIORITY_INTERACTIVE]) > 0)
130                 return V4L2_PRIORITY_INTERACTIVE;
131         if (atomic_read(&global->prios[V4L2_PRIORITY_BACKGROUND]) > 0)
132                 return V4L2_PRIORITY_BACKGROUND;
133         return V4L2_PRIORITY_UNSET;
134 }
135 EXPORT_SYMBOL(v4l2_prio_max);
136
137 int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority *local)
138 {
139         if (*local < v4l2_prio_max(global))
140                 return -EBUSY;
141         return 0;
142 }
143 EXPORT_SYMBOL(v4l2_prio_check);
144
145 /* ----------------------------------------------------------------- */
146
147 /* Helper functions for control handling                             */
148
149 /* Check for correctness of the ctrl's value based on the data from
150    struct v4l2_queryctrl and the available menu items. Note that
151    menu_items may be NULL, in that case it is ignored. */
152 int v4l2_ctrl_check(struct v4l2_ext_control *ctrl, struct v4l2_queryctrl *qctrl,
153                 const char **menu_items)
154 {
155         if (qctrl->flags & V4L2_CTRL_FLAG_DISABLED)
156                 return -EINVAL;
157         if (qctrl->flags & V4L2_CTRL_FLAG_GRABBED)
158                 return -EBUSY;
159         if (qctrl->type == V4L2_CTRL_TYPE_STRING)
160                 return 0;
161         if (qctrl->type == V4L2_CTRL_TYPE_BUTTON ||
162             qctrl->type == V4L2_CTRL_TYPE_INTEGER64 ||
163             qctrl->type == V4L2_CTRL_TYPE_CTRL_CLASS)
164                 return 0;
165         if (ctrl->value < qctrl->minimum || ctrl->value > qctrl->maximum)
166                 return -ERANGE;
167         if (qctrl->type == V4L2_CTRL_TYPE_MENU && menu_items != NULL) {
168                 if (menu_items[ctrl->value] == NULL ||
169                     menu_items[ctrl->value][0] == '\0')
170                         return -EINVAL;
171         }
172         return 0;
173 }
174 EXPORT_SYMBOL(v4l2_ctrl_check);
175
176 /* Returns NULL or a character pointer array containing the menu for
177    the given control ID. The pointer array ends with a NULL pointer.
178    An empty string signifies a menu entry that is invalid. This allows
179    drivers to disable certain options if it is not supported. */
180 const char **v4l2_ctrl_get_menu(u32 id)
181 {
182         static const char *mpeg_audio_sampling_freq[] = {
183                 "44.1 kHz",
184                 "48 kHz",
185                 "32 kHz",
186                 NULL
187         };
188         static const char *mpeg_audio_encoding[] = {
189                 "MPEG-1/2 Layer I",
190                 "MPEG-1/2 Layer II",
191                 "MPEG-1/2 Layer III",
192                 "MPEG-2/4 AAC",
193                 "AC-3",
194                 NULL
195         };
196         static const char *mpeg_audio_l1_bitrate[] = {
197                 "32 kbps",
198                 "64 kbps",
199                 "96 kbps",
200                 "128 kbps",
201                 "160 kbps",
202                 "192 kbps",
203                 "224 kbps",
204                 "256 kbps",
205                 "288 kbps",
206                 "320 kbps",
207                 "352 kbps",
208                 "384 kbps",
209                 "416 kbps",
210                 "448 kbps",
211                 NULL
212         };
213         static const char *mpeg_audio_l2_bitrate[] = {
214                 "32 kbps",
215                 "48 kbps",
216                 "56 kbps",
217                 "64 kbps",
218                 "80 kbps",
219                 "96 kbps",
220                 "112 kbps",
221                 "128 kbps",
222                 "160 kbps",
223                 "192 kbps",
224                 "224 kbps",
225                 "256 kbps",
226                 "320 kbps",
227                 "384 kbps",
228                 NULL
229         };
230         static const char *mpeg_audio_l3_bitrate[] = {
231                 "32 kbps",
232                 "40 kbps",
233                 "48 kbps",
234                 "56 kbps",
235                 "64 kbps",
236                 "80 kbps",
237                 "96 kbps",
238                 "112 kbps",
239                 "128 kbps",
240                 "160 kbps",
241                 "192 kbps",
242                 "224 kbps",
243                 "256 kbps",
244                 "320 kbps",
245                 NULL
246         };
247         static const char *mpeg_audio_ac3_bitrate[] = {
248                 "32 kbps",
249                 "40 kbps",
250                 "48 kbps",
251                 "56 kbps",
252                 "64 kbps",
253                 "80 kbps",
254                 "96 kbps",
255                 "112 kbps",
256                 "128 kbps",
257                 "160 kbps",
258                 "192 kbps",
259                 "224 kbps",
260                 "256 kbps",
261                 "320 kbps",
262                 "384 kbps",
263                 "448 kbps",
264                 "512 kbps",
265                 "576 kbps",
266                 "640 kbps",
267                 NULL
268         };
269         static const char *mpeg_audio_mode[] = {
270                 "Stereo",
271                 "Joint Stereo",
272                 "Dual",
273                 "Mono",
274                 NULL
275         };
276         static const char *mpeg_audio_mode_extension[] = {
277                 "Bound 4",
278                 "Bound 8",
279                 "Bound 12",
280                 "Bound 16",
281                 NULL
282         };
283         static const char *mpeg_audio_emphasis[] = {
284                 "No Emphasis",
285                 "50/15 us",
286                 "CCITT J17",
287                 NULL
288         };
289         static const char *mpeg_audio_crc[] = {
290                 "No CRC",
291                 "16-bit CRC",
292                 NULL
293         };
294         static const char *mpeg_video_encoding[] = {
295                 "MPEG-1",
296                 "MPEG-2",
297                 "MPEG-4 AVC",
298                 NULL
299         };
300         static const char *mpeg_video_aspect[] = {
301                 "1x1",
302                 "4x3",
303                 "16x9",
304                 "2.21x1",
305                 NULL
306         };
307         static const char *mpeg_video_bitrate_mode[] = {
308                 "Variable Bitrate",
309                 "Constant Bitrate",
310                 NULL
311         };
312         static const char *mpeg_stream_type[] = {
313                 "MPEG-2 Program Stream",
314                 "MPEG-2 Transport Stream",
315                 "MPEG-1 System Stream",
316                 "MPEG-2 DVD-compatible Stream",
317                 "MPEG-1 VCD-compatible Stream",
318                 "MPEG-2 SVCD-compatible Stream",
319                 NULL
320         };
321         static const char *mpeg_stream_vbi_fmt[] = {
322                 "No VBI",
323                 "Private packet, IVTV format",
324                 NULL
325         };
326         static const char *camera_power_line_frequency[] = {
327                 "Disabled",
328                 "50 Hz",
329                 "60 Hz",
330                 NULL
331         };
332         static const char *camera_exposure_auto[] = {
333                 "Auto Mode",
334                 "Manual Mode",
335                 "Shutter Priority Mode",
336                 "Aperture Priority Mode",
337                 NULL
338         };
339         static const char *colorfx[] = {
340                 "None",
341                 "Black & White",
342                 "Sepia",
343                 NULL
344         };
345         static const char *tune_preemphasis[] = {
346                 "No preemphasis",
347                 "50 useconds",
348                 "75 useconds",
349                 NULL,
350         };
351
352         switch (id) {
353                 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
354                         return mpeg_audio_sampling_freq;
355                 case V4L2_CID_MPEG_AUDIO_ENCODING:
356                         return mpeg_audio_encoding;
357                 case V4L2_CID_MPEG_AUDIO_L1_BITRATE:
358                         return mpeg_audio_l1_bitrate;
359                 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
360                         return mpeg_audio_l2_bitrate;
361                 case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
362                         return mpeg_audio_l3_bitrate;
363                 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
364                         return mpeg_audio_ac3_bitrate;
365                 case V4L2_CID_MPEG_AUDIO_MODE:
366                         return mpeg_audio_mode;
367                 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
368                         return mpeg_audio_mode_extension;
369                 case V4L2_CID_MPEG_AUDIO_EMPHASIS:
370                         return mpeg_audio_emphasis;
371                 case V4L2_CID_MPEG_AUDIO_CRC:
372                         return mpeg_audio_crc;
373                 case V4L2_CID_MPEG_VIDEO_ENCODING:
374                         return mpeg_video_encoding;
375                 case V4L2_CID_MPEG_VIDEO_ASPECT:
376                         return mpeg_video_aspect;
377                 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
378                         return mpeg_video_bitrate_mode;
379                 case V4L2_CID_MPEG_STREAM_TYPE:
380                         return mpeg_stream_type;
381                 case V4L2_CID_MPEG_STREAM_VBI_FMT:
382                         return mpeg_stream_vbi_fmt;
383                 case V4L2_CID_POWER_LINE_FREQUENCY:
384                         return camera_power_line_frequency;
385                 case V4L2_CID_EXPOSURE_AUTO:
386                         return camera_exposure_auto;
387                 case V4L2_CID_COLORFX:
388                         return colorfx;
389                 case V4L2_CID_TUNE_PREEMPHASIS:
390                         return tune_preemphasis;
391                 default:
392                         return NULL;
393         }
394 }
395 EXPORT_SYMBOL(v4l2_ctrl_get_menu);
396
397 /* Return the control name. */
398 const char *v4l2_ctrl_get_name(u32 id)
399 {
400         switch (id) {
401         /* USER controls */
402         case V4L2_CID_USER_CLASS:               return "User Controls";
403         case V4L2_CID_BRIGHTNESS:               return "Brightness";
404         case V4L2_CID_CONTRAST:                 return "Contrast";
405         case V4L2_CID_SATURATION:               return "Saturation";
406         case V4L2_CID_HUE:                      return "Hue";
407         case V4L2_CID_AUDIO_VOLUME:             return "Volume";
408         case V4L2_CID_AUDIO_BALANCE:            return "Balance";
409         case V4L2_CID_AUDIO_BASS:               return "Bass";
410         case V4L2_CID_AUDIO_TREBLE:             return "Treble";
411         case V4L2_CID_AUDIO_MUTE:               return "Mute";
412         case V4L2_CID_AUDIO_LOUDNESS:           return "Loudness";
413         case V4L2_CID_BLACK_LEVEL:              return "Black Level";
414         case V4L2_CID_AUTO_WHITE_BALANCE:       return "White Balance, Automatic";
415         case V4L2_CID_DO_WHITE_BALANCE:         return "Do White Balance";
416         case V4L2_CID_RED_BALANCE:              return "Red Balance";
417         case V4L2_CID_BLUE_BALANCE:             return "Blue Balance";
418         case V4L2_CID_GAMMA:                    return "Gamma";
419         case V4L2_CID_EXPOSURE:                 return "Exposure";
420         case V4L2_CID_AUTOGAIN:                 return "Gain, Automatic";
421         case V4L2_CID_GAIN:                     return "Gain";
422         case V4L2_CID_HFLIP:                    return "Horizontal Flip";
423         case V4L2_CID_VFLIP:                    return "Vertical Flip";
424         case V4L2_CID_HCENTER:                  return "Horizontal Center";
425         case V4L2_CID_VCENTER:                  return "Vertical Center";
426         case V4L2_CID_POWER_LINE_FREQUENCY:     return "Power Line Frequency";
427         case V4L2_CID_HUE_AUTO:                 return "Hue, Automatic";
428         case V4L2_CID_WHITE_BALANCE_TEMPERATURE: return "White Balance Temperature";
429         case V4L2_CID_SHARPNESS:                return "Sharpness";
430         case V4L2_CID_BACKLIGHT_COMPENSATION:   return "Backlight Compensation";
431         case V4L2_CID_CHROMA_AGC:               return "Chroma AGC";
432         case V4L2_CID_CHROMA_GAIN:              return "Chroma Gain";
433         case V4L2_CID_COLOR_KILLER:             return "Color Killer";
434         case V4L2_CID_COLORFX:                  return "Color Effects";
435         case V4L2_CID_AUTOBRIGHTNESS:           return "Brightness, Automatic";
436         case V4L2_CID_BAND_STOP_FILTER:         return "Band-Stop Filter";
437         case V4L2_CID_ROTATE:                   return "Rotate";
438         case V4L2_CID_BG_COLOR:                 return "Background Color";
439
440         /* MPEG controls */
441         case V4L2_CID_MPEG_CLASS:               return "MPEG Encoder Controls";
442         case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: return "Audio Sampling Frequency";
443         case V4L2_CID_MPEG_AUDIO_ENCODING:      return "Audio Encoding";
444         case V4L2_CID_MPEG_AUDIO_L1_BITRATE:    return "Audio Layer I Bitrate";
445         case V4L2_CID_MPEG_AUDIO_L2_BITRATE:    return "Audio Layer II Bitrate";
446         case V4L2_CID_MPEG_AUDIO_L3_BITRATE:    return "Audio Layer III Bitrate";
447         case V4L2_CID_MPEG_AUDIO_AAC_BITRATE:   return "Audio AAC Bitrate";
448         case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:   return "Audio AC-3 Bitrate";
449         case V4L2_CID_MPEG_AUDIO_MODE:          return "Audio Stereo Mode";
450         case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: return "Audio Stereo Mode Extension";
451         case V4L2_CID_MPEG_AUDIO_EMPHASIS:      return "Audio Emphasis";
452         case V4L2_CID_MPEG_AUDIO_CRC:           return "Audio CRC";
453         case V4L2_CID_MPEG_AUDIO_MUTE:          return "Audio Mute";
454         case V4L2_CID_MPEG_VIDEO_ENCODING:      return "Video Encoding";
455         case V4L2_CID_MPEG_VIDEO_ASPECT:        return "Video Aspect";
456         case V4L2_CID_MPEG_VIDEO_B_FRAMES:      return "Video B Frames";
457         case V4L2_CID_MPEG_VIDEO_GOP_SIZE:      return "Video GOP Size";
458         case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE:   return "Video GOP Closure";
459         case V4L2_CID_MPEG_VIDEO_PULLDOWN:      return "Video Pulldown";
460         case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:  return "Video Bitrate Mode";
461         case V4L2_CID_MPEG_VIDEO_BITRATE:       return "Video Bitrate";
462         case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:  return "Video Peak Bitrate";
463         case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION: return "Video Temporal Decimation";
464         case V4L2_CID_MPEG_VIDEO_MUTE:          return "Video Mute";
465         case V4L2_CID_MPEG_VIDEO_MUTE_YUV:      return "Video Mute YUV";
466         case V4L2_CID_MPEG_STREAM_TYPE:         return "Stream Type";
467         case V4L2_CID_MPEG_STREAM_PID_PMT:      return "Stream PMT Program ID";
468         case V4L2_CID_MPEG_STREAM_PID_AUDIO:    return "Stream Audio Program ID";
469         case V4L2_CID_MPEG_STREAM_PID_VIDEO:    return "Stream Video Program ID";
470         case V4L2_CID_MPEG_STREAM_PID_PCR:      return "Stream PCR Program ID";
471         case V4L2_CID_MPEG_STREAM_PES_ID_AUDIO: return "Stream PES Audio ID";
472         case V4L2_CID_MPEG_STREAM_PES_ID_VIDEO: return "Stream PES Video ID";
473         case V4L2_CID_MPEG_STREAM_VBI_FMT:      return "Stream VBI Format";
474
475         /* CAMERA controls */
476         case V4L2_CID_CAMERA_CLASS:             return "Camera Controls";
477         case V4L2_CID_EXPOSURE_AUTO:            return "Auto Exposure";
478         case V4L2_CID_EXPOSURE_ABSOLUTE:        return "Exposure Time, Absolute";
479         case V4L2_CID_EXPOSURE_AUTO_PRIORITY:   return "Exposure, Dynamic Framerate";
480         case V4L2_CID_PAN_RELATIVE:             return "Pan, Relative";
481         case V4L2_CID_TILT_RELATIVE:            return "Tilt, Relative";
482         case V4L2_CID_PAN_RESET:                return "Pan, Reset";
483         case V4L2_CID_TILT_RESET:               return "Tilt, Reset";
484         case V4L2_CID_PAN_ABSOLUTE:             return "Pan, Absolute";
485         case V4L2_CID_TILT_ABSOLUTE:            return "Tilt, Absolute";
486         case V4L2_CID_FOCUS_ABSOLUTE:           return "Focus, Absolute";
487         case V4L2_CID_FOCUS_RELATIVE:           return "Focus, Relative";
488         case V4L2_CID_FOCUS_AUTO:               return "Focus, Automatic";
489         case V4L2_CID_ZOOM_ABSOLUTE:            return "Zoom, Absolute";
490         case V4L2_CID_ZOOM_RELATIVE:            return "Zoom, Relative";
491         case V4L2_CID_ZOOM_CONTINUOUS:          return "Zoom, Continuous";
492         case V4L2_CID_PRIVACY:                  return "Privacy";
493
494         /* FM Radio Modulator control */
495         case V4L2_CID_FM_TX_CLASS:              return "FM Radio Modulator Controls";
496         case V4L2_CID_RDS_TX_DEVIATION:         return "RDS Signal Deviation";
497         case V4L2_CID_RDS_TX_PI:                return "RDS Program ID";
498         case V4L2_CID_RDS_TX_PTY:               return "RDS Program Type";
499         case V4L2_CID_RDS_TX_PS_NAME:           return "RDS PS Name";
500         case V4L2_CID_RDS_TX_RADIO_TEXT:        return "RDS Radio Text";
501         case V4L2_CID_AUDIO_LIMITER_ENABLED:    return "Audio Limiter Feature Enabled";
502         case V4L2_CID_AUDIO_LIMITER_RELEASE_TIME: return "Audio Limiter Release Time";
503         case V4L2_CID_AUDIO_LIMITER_DEVIATION:  return "Audio Limiter Deviation";
504         case V4L2_CID_AUDIO_COMPRESSION_ENABLED: return "Audio Compression Feature Enabled";
505         case V4L2_CID_AUDIO_COMPRESSION_GAIN:   return "Audio Compression Gain";
506         case V4L2_CID_AUDIO_COMPRESSION_THRESHOLD: return "Audio Compression Threshold";
507         case V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME: return "Audio Compression Attack Time";
508         case V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME: return "Audio Compression Release Time";
509         case V4L2_CID_PILOT_TONE_ENABLED:       return "Pilot Tone Feature Enabled";
510         case V4L2_CID_PILOT_TONE_DEVIATION:     return "Pilot Tone Deviation";
511         case V4L2_CID_PILOT_TONE_FREQUENCY:     return "Pilot Tone Frequency";
512         case V4L2_CID_TUNE_PREEMPHASIS: return "Pre-emphasis settings";
513         case V4L2_CID_TUNE_POWER_LEVEL:         return "Tune Power Level";
514         case V4L2_CID_TUNE_ANTENNA_CAPACITOR:   return "Tune Antenna Capacitor";
515
516         default:
517                 return NULL;
518         }
519 }
520 EXPORT_SYMBOL(v4l2_ctrl_get_name);
521
522 /* Fill in a struct v4l2_queryctrl */
523 int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 step, s32 def)
524 {
525         const char *name = v4l2_ctrl_get_name(qctrl->id);
526
527         qctrl->flags = 0;
528         if (name == NULL)
529                 return -EINVAL;
530
531         switch (qctrl->id) {
532         case V4L2_CID_AUDIO_MUTE:
533         case V4L2_CID_AUDIO_LOUDNESS:
534         case V4L2_CID_AUTO_WHITE_BALANCE:
535         case V4L2_CID_AUTOGAIN:
536         case V4L2_CID_HFLIP:
537         case V4L2_CID_VFLIP:
538         case V4L2_CID_HUE_AUTO:
539         case V4L2_CID_CHROMA_AGC:
540         case V4L2_CID_COLOR_KILLER:
541         case V4L2_CID_MPEG_AUDIO_MUTE:
542         case V4L2_CID_MPEG_VIDEO_MUTE:
543         case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE:
544         case V4L2_CID_MPEG_VIDEO_PULLDOWN:
545         case V4L2_CID_EXPOSURE_AUTO_PRIORITY:
546         case V4L2_CID_FOCUS_AUTO:
547         case V4L2_CID_PRIVACY:
548         case V4L2_CID_AUDIO_LIMITER_ENABLED:
549         case V4L2_CID_AUDIO_COMPRESSION_ENABLED:
550         case V4L2_CID_PILOT_TONE_ENABLED:
551                 qctrl->type = V4L2_CTRL_TYPE_BOOLEAN;
552                 min = 0;
553                 max = step = 1;
554                 break;
555         case V4L2_CID_PAN_RESET:
556         case V4L2_CID_TILT_RESET:
557                 qctrl->type = V4L2_CTRL_TYPE_BUTTON;
558                 qctrl->flags |= V4L2_CTRL_FLAG_WRITE_ONLY;
559                 min = max = step = def = 0;
560                 break;
561         case V4L2_CID_POWER_LINE_FREQUENCY:
562         case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
563         case V4L2_CID_MPEG_AUDIO_ENCODING:
564         case V4L2_CID_MPEG_AUDIO_L1_BITRATE:
565         case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
566         case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
567         case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
568         case V4L2_CID_MPEG_AUDIO_MODE:
569         case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
570         case V4L2_CID_MPEG_AUDIO_EMPHASIS:
571         case V4L2_CID_MPEG_AUDIO_CRC:
572         case V4L2_CID_MPEG_VIDEO_ENCODING:
573         case V4L2_CID_MPEG_VIDEO_ASPECT:
574         case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
575         case V4L2_CID_MPEG_STREAM_TYPE:
576         case V4L2_CID_MPEG_STREAM_VBI_FMT:
577         case V4L2_CID_EXPOSURE_AUTO:
578         case V4L2_CID_COLORFX:
579         case V4L2_CID_TUNE_PREEMPHASIS:
580                 qctrl->type = V4L2_CTRL_TYPE_MENU;
581                 step = 1;
582                 break;
583         case V4L2_CID_RDS_TX_PS_NAME:
584         case V4L2_CID_RDS_TX_RADIO_TEXT:
585                 qctrl->type = V4L2_CTRL_TYPE_STRING;
586                 break;
587         case V4L2_CID_USER_CLASS:
588         case V4L2_CID_CAMERA_CLASS:
589         case V4L2_CID_MPEG_CLASS:
590         case V4L2_CID_FM_TX_CLASS:
591                 qctrl->type = V4L2_CTRL_TYPE_CTRL_CLASS;
592                 qctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
593                 min = max = step = def = 0;
594                 break;
595         case V4L2_CID_BG_COLOR:
596                 qctrl->type = V4L2_CTRL_TYPE_INTEGER;
597                 step = 1;
598                 min = 0;
599                 /* Max is calculated as RGB888 that is 2^24 */
600                 max = 0xFFFFFF;
601                 break;
602         default:
603                 qctrl->type = V4L2_CTRL_TYPE_INTEGER;
604                 break;
605         }
606         switch (qctrl->id) {
607         case V4L2_CID_MPEG_AUDIO_ENCODING:
608         case V4L2_CID_MPEG_AUDIO_MODE:
609         case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
610         case V4L2_CID_MPEG_VIDEO_B_FRAMES:
611         case V4L2_CID_MPEG_STREAM_TYPE:
612                 qctrl->flags |= V4L2_CTRL_FLAG_UPDATE;
613                 break;
614         case V4L2_CID_AUDIO_VOLUME:
615         case V4L2_CID_AUDIO_BALANCE:
616         case V4L2_CID_AUDIO_BASS:
617         case V4L2_CID_AUDIO_TREBLE:
618         case V4L2_CID_BRIGHTNESS:
619         case V4L2_CID_CONTRAST:
620         case V4L2_CID_SATURATION:
621         case V4L2_CID_HUE:
622         case V4L2_CID_RED_BALANCE:
623         case V4L2_CID_BLUE_BALANCE:
624         case V4L2_CID_GAMMA:
625         case V4L2_CID_SHARPNESS:
626         case V4L2_CID_CHROMA_GAIN:
627         case V4L2_CID_RDS_TX_DEVIATION:
628         case V4L2_CID_AUDIO_LIMITER_RELEASE_TIME:
629         case V4L2_CID_AUDIO_LIMITER_DEVIATION:
630         case V4L2_CID_AUDIO_COMPRESSION_GAIN:
631         case V4L2_CID_AUDIO_COMPRESSION_THRESHOLD:
632         case V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME:
633         case V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME:
634         case V4L2_CID_PILOT_TONE_DEVIATION:
635         case V4L2_CID_PILOT_TONE_FREQUENCY:
636         case V4L2_CID_TUNE_POWER_LEVEL:
637         case V4L2_CID_TUNE_ANTENNA_CAPACITOR:
638                 qctrl->flags |= V4L2_CTRL_FLAG_SLIDER;
639                 break;
640         case V4L2_CID_PAN_RELATIVE:
641         case V4L2_CID_TILT_RELATIVE:
642         case V4L2_CID_FOCUS_RELATIVE:
643         case V4L2_CID_ZOOM_RELATIVE:
644                 qctrl->flags |= V4L2_CTRL_FLAG_WRITE_ONLY;
645                 break;
646         }
647         qctrl->minimum = min;
648         qctrl->maximum = max;
649         qctrl->step = step;
650         qctrl->default_value = def;
651         qctrl->reserved[0] = qctrl->reserved[1] = 0;
652         strlcpy(qctrl->name, name, sizeof(qctrl->name));
653         return 0;
654 }
655 EXPORT_SYMBOL(v4l2_ctrl_query_fill);
656
657 /* Fill in a struct v4l2_querymenu based on the struct v4l2_queryctrl and
658    the menu. The qctrl pointer may be NULL, in which case it is ignored.
659    If menu_items is NULL, then the menu items are retrieved using
660    v4l2_ctrl_get_menu. */
661 int v4l2_ctrl_query_menu(struct v4l2_querymenu *qmenu, struct v4l2_queryctrl *qctrl,
662                const char **menu_items)
663 {
664         int i;
665
666         qmenu->reserved = 0;
667         if (menu_items == NULL)
668                 menu_items = v4l2_ctrl_get_menu(qmenu->id);
669         if (menu_items == NULL ||
670             (qctrl && (qmenu->index < qctrl->minimum || qmenu->index > qctrl->maximum)))
671                 return -EINVAL;
672         for (i = 0; i < qmenu->index && menu_items[i]; i++) ;
673         if (menu_items[i] == NULL || menu_items[i][0] == '\0')
674                 return -EINVAL;
675         strlcpy(qmenu->name, menu_items[qmenu->index], sizeof(qmenu->name));
676         return 0;
677 }
678 EXPORT_SYMBOL(v4l2_ctrl_query_menu);
679
680 /* Fill in a struct v4l2_querymenu based on the specified array of valid
681    menu items (terminated by V4L2_CTRL_MENU_IDS_END).
682    Use this if there are 'holes' in the list of valid menu items. */
683 int v4l2_ctrl_query_menu_valid_items(struct v4l2_querymenu *qmenu, const u32 *ids)
684 {
685         const char **menu_items = v4l2_ctrl_get_menu(qmenu->id);
686
687         qmenu->reserved = 0;
688         if (menu_items == NULL || ids == NULL)
689                 return -EINVAL;
690         while (*ids != V4L2_CTRL_MENU_IDS_END) {
691                 if (*ids++ == qmenu->index) {
692                         strlcpy(qmenu->name, menu_items[qmenu->index],
693                                         sizeof(qmenu->name));
694                         return 0;
695                 }
696         }
697         return -EINVAL;
698 }
699 EXPORT_SYMBOL(v4l2_ctrl_query_menu_valid_items);
700
701 /* ctrl_classes points to an array of u32 pointers, the last element is
702    a NULL pointer. Each u32 array is a 0-terminated array of control IDs.
703    Each array must be sorted low to high and belong to the same control
704    class. The array of u32 pointers must also be sorted, from low class IDs
705    to high class IDs.
706
707    This function returns the first ID that follows after the given ID.
708    When no more controls are available 0 is returned. */
709 u32 v4l2_ctrl_next(const u32 * const * ctrl_classes, u32 id)
710 {
711         u32 ctrl_class = V4L2_CTRL_ID2CLASS(id);
712         const u32 *pctrl;
713
714         if (ctrl_classes == NULL)
715                 return 0;
716
717         /* if no query is desired, then check if the ID is part of ctrl_classes */
718         if ((id & V4L2_CTRL_FLAG_NEXT_CTRL) == 0) {
719                 /* find class */
720                 while (*ctrl_classes && V4L2_CTRL_ID2CLASS(**ctrl_classes) != ctrl_class)
721                         ctrl_classes++;
722                 if (*ctrl_classes == NULL)
723                         return 0;
724                 pctrl = *ctrl_classes;
725                 /* find control ID */
726                 while (*pctrl && *pctrl != id) pctrl++;
727                 return *pctrl ? id : 0;
728         }
729         id &= V4L2_CTRL_ID_MASK;
730         id++;   /* select next control */
731         /* find first class that matches (or is greater than) the class of
732            the ID */
733         while (*ctrl_classes && V4L2_CTRL_ID2CLASS(**ctrl_classes) < ctrl_class)
734                 ctrl_classes++;
735         /* no more classes */
736         if (*ctrl_classes == NULL)
737                 return 0;
738         pctrl = *ctrl_classes;
739         /* find first ctrl within the class that is >= ID */
740         while (*pctrl && *pctrl < id) pctrl++;
741         if (*pctrl)
742                 return *pctrl;
743         /* we are at the end of the controls of the current class. */
744         /* continue with next class if available */
745         ctrl_classes++;
746         if (*ctrl_classes == NULL)
747                 return 0;
748         return **ctrl_classes;
749 }
750 EXPORT_SYMBOL(v4l2_ctrl_next);
751
752 int v4l2_chip_match_host(const struct v4l2_dbg_match *match)
753 {
754         switch (match->type) {
755         case V4L2_CHIP_MATCH_HOST:
756                 return match->addr == 0;
757         default:
758                 return 0;
759         }
760 }
761 EXPORT_SYMBOL(v4l2_chip_match_host);
762
763 #if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE))
764 int v4l2_chip_match_i2c_client(struct i2c_client *c, const struct v4l2_dbg_match *match)
765 {
766         int len;
767
768         if (c == NULL || match == NULL)
769                 return 0;
770
771         switch (match->type) {
772         case V4L2_CHIP_MATCH_I2C_DRIVER:
773                 if (c->driver == NULL || c->driver->driver.name == NULL)
774                         return 0;
775                 len = strlen(c->driver->driver.name);
776                 /* legacy drivers have a ' suffix, don't try to match that */
777                 if (len && c->driver->driver.name[len - 1] == '\'')
778                         len--;
779                 return len && !strncmp(c->driver->driver.name, match->name, len);
780         case V4L2_CHIP_MATCH_I2C_ADDR:
781                 return c->addr == match->addr;
782         default:
783                 return 0;
784         }
785 }
786 EXPORT_SYMBOL(v4l2_chip_match_i2c_client);
787
788 int v4l2_chip_ident_i2c_client(struct i2c_client *c, struct v4l2_dbg_chip_ident *chip,
789                 u32 ident, u32 revision)
790 {
791         if (!v4l2_chip_match_i2c_client(c, &chip->match))
792                 return 0;
793         if (chip->ident == V4L2_IDENT_NONE) {
794                 chip->ident = ident;
795                 chip->revision = revision;
796         }
797         else {
798                 chip->ident = V4L2_IDENT_AMBIGUOUS;
799                 chip->revision = 0;
800         }
801         return 0;
802 }
803 EXPORT_SYMBOL(v4l2_chip_ident_i2c_client);
804
805 /* ----------------------------------------------------------------- */
806
807 /* I2C Helper functions */
808
809
810 void v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client,
811                 const struct v4l2_subdev_ops *ops)
812 {
813         v4l2_subdev_init(sd, ops);
814         sd->flags |= V4L2_SUBDEV_FL_IS_I2C;
815         /* the owner is the same as the i2c_client's driver owner */
816         sd->owner = client->driver->driver.owner;
817         /* i2c_client and v4l2_subdev point to one another */
818         v4l2_set_subdevdata(sd, client);
819         i2c_set_clientdata(client, sd);
820         /* initialize name */
821         snprintf(sd->name, sizeof(sd->name), "%s %d-%04x",
822                 client->driver->driver.name, i2c_adapter_id(client->adapter),
823                 client->addr);
824 }
825 EXPORT_SYMBOL_GPL(v4l2_i2c_subdev_init);
826
827
828
829 /* Load an i2c sub-device. */
830 struct v4l2_subdev *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev,
831                 struct i2c_adapter *adapter, const char *module_name,
832                 struct i2c_board_info *info, const unsigned short *probe_addrs)
833 {
834         struct v4l2_subdev *sd = NULL;
835         struct i2c_client *client;
836
837         BUG_ON(!v4l2_dev);
838
839         if (module_name)
840                 request_module(module_name);
841
842         /* Create the i2c client */
843         if (info->addr == 0 && probe_addrs)
844                 client = i2c_new_probed_device(adapter, info, probe_addrs);
845         else
846                 client = i2c_new_device(adapter, info);
847
848         /* Note: by loading the module first we are certain that c->driver
849            will be set if the driver was found. If the module was not loaded
850            first, then the i2c core tries to delay-load the module for us,
851            and then c->driver is still NULL until the module is finally
852            loaded. This delay-load mechanism doesn't work if other drivers
853            want to use the i2c device, so explicitly loading the module
854            is the best alternative. */
855         if (client == NULL || client->driver == NULL)
856                 goto error;
857
858         /* Lock the module so we can safely get the v4l2_subdev pointer */
859         if (!try_module_get(client->driver->driver.owner))
860                 goto error;
861         sd = i2c_get_clientdata(client);
862
863         /* Register with the v4l2_device which increases the module's
864            use count as well. */
865         if (v4l2_device_register_subdev(v4l2_dev, sd))
866                 sd = NULL;
867         /* Decrease the module use count to match the first try_module_get. */
868         module_put(client->driver->driver.owner);
869
870         if (sd) {
871                 /* We return errors from v4l2_subdev_call only if we have the
872                    callback as the .s_config is not mandatory */
873                 int err = v4l2_subdev_call(sd, core, s_config,
874                                 info->irq, info->platform_data);
875
876                 if (err && err != -ENOIOCTLCMD) {
877                         v4l2_device_unregister_subdev(sd);
878                         sd = NULL;
879                 }
880         }
881
882 error:
883         /* If we have a client but no subdev, then something went wrong and
884            we must unregister the client. */
885         if (client && sd == NULL)
886                 i2c_unregister_device(client);
887         return sd;
888 }
889 EXPORT_SYMBOL_GPL(v4l2_i2c_new_subdev_board);
890
891 struct v4l2_subdev *v4l2_i2c_new_subdev_cfg(struct v4l2_device *v4l2_dev,
892                 struct i2c_adapter *adapter,
893                 const char *module_name, const char *client_type,
894                 int irq, void *platform_data,
895                 u8 addr, const unsigned short *probe_addrs)
896 {
897         struct i2c_board_info info;
898
899         /* Setup the i2c board info with the device type and
900            the device address. */
901         memset(&info, 0, sizeof(info));
902         strlcpy(info.type, client_type, sizeof(info.type));
903         info.addr = addr;
904         info.irq = irq;
905         info.platform_data = platform_data;
906
907         return v4l2_i2c_new_subdev_board(v4l2_dev, adapter, module_name,
908                         &info, probe_addrs);
909 }
910 EXPORT_SYMBOL_GPL(v4l2_i2c_new_subdev_cfg);
911
912 /* Return i2c client address of v4l2_subdev. */
913 unsigned short v4l2_i2c_subdev_addr(struct v4l2_subdev *sd)
914 {
915         struct i2c_client *client = v4l2_get_subdevdata(sd);
916
917         return client ? client->addr : I2C_CLIENT_END;
918 }
919 EXPORT_SYMBOL_GPL(v4l2_i2c_subdev_addr);
920
921 /* Return a list of I2C tuner addresses to probe. Use only if the tuner
922    addresses are unknown. */
923 const unsigned short *v4l2_i2c_tuner_addrs(enum v4l2_i2c_tuner_type type)
924 {
925         static const unsigned short radio_addrs[] = {
926 #if defined(CONFIG_MEDIA_TUNER_TEA5761) || defined(CONFIG_MEDIA_TUNER_TEA5761_MODULE)
927                 0x10,
928 #endif
929                 0x60,
930                 I2C_CLIENT_END
931         };
932         static const unsigned short demod_addrs[] = {
933                 0x42, 0x43, 0x4a, 0x4b,
934                 I2C_CLIENT_END
935         };
936         static const unsigned short tv_addrs[] = {
937                 0x42, 0x43, 0x4a, 0x4b,         /* tda8290 */
938                 0x60, 0x61, 0x62, 0x63, 0x64,
939                 I2C_CLIENT_END
940         };
941
942         switch (type) {
943         case ADDRS_RADIO:
944                 return radio_addrs;
945         case ADDRS_DEMOD:
946                 return demod_addrs;
947         case ADDRS_TV:
948                 return tv_addrs;
949         case ADDRS_TV_WITH_DEMOD:
950                 return tv_addrs + 4;
951         }
952         return NULL;
953 }
954 EXPORT_SYMBOL_GPL(v4l2_i2c_tuner_addrs);
955
956 #endif /* defined(CONFIG_I2C) */
957
958 /* Clamp x to be between min and max, aligned to a multiple of 2^align.  min
959  * and max don't have to be aligned, but there must be at least one valid
960  * value.  E.g., min=17,max=31,align=4 is not allowed as there are no multiples
961  * of 16 between 17 and 31.  */
962 static unsigned int clamp_align(unsigned int x, unsigned int min,
963                                 unsigned int max, unsigned int align)
964 {
965         /* Bits that must be zero to be aligned */
966         unsigned int mask = ~((1 << align) - 1);
967
968         /* Round to nearest aligned value */
969         if (align)
970                 x = (x + (1 << (align - 1))) & mask;
971
972         /* Clamp to aligned value of min and max */
973         if (x < min)
974                 x = (min + ~mask) & mask;
975         else if (x > max)
976                 x = max & mask;
977
978         return x;
979 }
980
981 /* Bound an image to have a width between wmin and wmax, and height between
982  * hmin and hmax, inclusive.  Additionally, the width will be a multiple of
983  * 2^walign, the height will be a multiple of 2^halign, and the overall size
984  * (width*height) will be a multiple of 2^salign.  The image may be shrunk
985  * or enlarged to fit the alignment constraints.
986  *
987  * The width or height maximum must not be smaller than the corresponding
988  * minimum.  The alignments must not be so high there are no possible image
989  * sizes within the allowed bounds.  wmin and hmin must be at least 1
990  * (don't use 0).  If you don't care about a certain alignment, specify 0,
991  * as 2^0 is 1 and one byte alignment is equivalent to no alignment.  If
992  * you only want to adjust downward, specify a maximum that's the same as
993  * the initial value.
994  */
995 void v4l_bound_align_image(u32 *w, unsigned int wmin, unsigned int wmax,
996                            unsigned int walign,
997                            u32 *h, unsigned int hmin, unsigned int hmax,
998                            unsigned int halign, unsigned int salign)
999 {
1000         *w = clamp_align(*w, wmin, wmax, walign);
1001         *h = clamp_align(*h, hmin, hmax, halign);
1002
1003         /* Usually we don't need to align the size and are done now. */
1004         if (!salign)
1005                 return;
1006
1007         /* How much alignment do we have? */
1008         walign = __ffs(*w);
1009         halign = __ffs(*h);
1010         /* Enough to satisfy the image alignment? */
1011         if (walign + halign < salign) {
1012                 /* Max walign where there is still a valid width */
1013                 unsigned int wmaxa = __fls(wmax ^ (wmin - 1));
1014                 /* Max halign where there is still a valid height */
1015                 unsigned int hmaxa = __fls(hmax ^ (hmin - 1));
1016
1017                 /* up the smaller alignment until we have enough */
1018                 do {
1019                         if (halign >= hmaxa ||
1020                             (walign <= halign && walign < wmaxa)) {
1021                                 *w = clamp_align(*w, wmin, wmax, walign + 1);
1022                                 walign = __ffs(*w);
1023                         } else {
1024                                 *h = clamp_align(*h, hmin, hmax, halign + 1);
1025                                 halign = __ffs(*h);
1026                         }
1027                 } while (halign + walign < salign);
1028         }
1029 }
1030 EXPORT_SYMBOL_GPL(v4l_bound_align_image);
1031
1032 /**
1033  * v4l_fill_dv_preset_info - fill description of a digital video preset
1034  * @preset - preset value
1035  * @info - pointer to struct v4l2_dv_enum_preset
1036  *
1037  * drivers can use this helper function to fill description of dv preset
1038  * in info.
1039  */
1040 int v4l_fill_dv_preset_info(u32 preset, struct v4l2_dv_enum_preset *info)
1041 {
1042         static const struct v4l2_dv_preset_info {
1043                 u16 width;
1044                 u16 height;
1045                 const char *name;
1046         } dv_presets[] = {
1047                 { 0, 0, "Invalid" },            /* V4L2_DV_INVALID */
1048                 { 720,  480, "480p@59.94" },    /* V4L2_DV_480P59_94 */
1049                 { 720,  576, "576p@50" },       /* V4L2_DV_576P50 */
1050                 { 1280, 720, "720p@24" },       /* V4L2_DV_720P24 */
1051                 { 1280, 720, "720p@25" },       /* V4L2_DV_720P25 */
1052                 { 1280, 720, "720p@30" },       /* V4L2_DV_720P30 */
1053                 { 1280, 720, "720p@50" },       /* V4L2_DV_720P50 */
1054                 { 1280, 720, "720p@59.94" },    /* V4L2_DV_720P59_94 */
1055                 { 1280, 720, "720p@60" },       /* V4L2_DV_720P60 */
1056                 { 1920, 1080, "1080i@29.97" },  /* V4L2_DV_1080I29_97 */
1057                 { 1920, 1080, "1080i@30" },     /* V4L2_DV_1080I30 */
1058                 { 1920, 1080, "1080i@25" },     /* V4L2_DV_1080I25 */
1059                 { 1920, 1080, "1080i@50" },     /* V4L2_DV_1080I50 */
1060                 { 1920, 1080, "1080i@60" },     /* V4L2_DV_1080I60 */
1061                 { 1920, 1080, "1080p@24" },     /* V4L2_DV_1080P24 */
1062                 { 1920, 1080, "1080p@25" },     /* V4L2_DV_1080P25 */
1063                 { 1920, 1080, "1080p@30" },     /* V4L2_DV_1080P30 */
1064                 { 1920, 1080, "1080p@50" },     /* V4L2_DV_1080P50 */
1065                 { 1920, 1080, "1080p@60" },     /* V4L2_DV_1080P60 */
1066         };
1067
1068         if (info == NULL || preset >= ARRAY_SIZE(dv_presets))
1069                 return -EINVAL;
1070
1071         info->preset = preset;
1072         info->width = dv_presets[preset].width;
1073         info->height = dv_presets[preset].height;
1074         strlcpy(info->name, dv_presets[preset].name, sizeof(info->name));
1075         return 0;
1076 }
1077 EXPORT_SYMBOL_GPL(v4l_fill_dv_preset_info);