Merge branch 'timers-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[pandora-kernel.git] / drivers / staging / easycap / easycap_settings.c
1 /******************************************************************************
2 *                                                                             *
3 *  easycap_settings.c                                                         *
4 *                                                                             *
5 ******************************************************************************/
6 /*
7  *
8  *  Copyright (C) 2010 R.M. Thomas  <rmthomas@sciolus.org>
9  *
10  *
11  *  This is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  The software is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this software; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24  *
25 */
26 /*****************************************************************************/
27
28 #include "easycap.h"
29 #include "easycap_debug.h"
30
31 /*---------------------------------------------------------------------------*/
32 /*
33  *  THE LEAST SIGNIFICANT BIT OF easycap_standard.mask HAS MEANING:
34  *                         0 => 25 fps
35  *                         1 => 30 fps
36  */
37 /*---------------------------------------------------------------------------*/
38 const struct easycap_standard easycap_standard[] = {
39 {
40 .mask = 0x000F & PAL_BGHIN ,
41 .v4l2_standard = {
42         .index = PAL_BGHIN,
43         .id = (V4L2_STD_PAL_B | V4L2_STD_PAL_G | V4L2_STD_PAL_H | \
44                                         V4L2_STD_PAL_I | V4L2_STD_PAL_N),
45         .name = "PAL_BGHIN",
46         .frameperiod = {1, 25},
47         .framelines = 625,
48         .reserved = {0, 0, 0, 0}
49         }
50 },
51 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
52 {
53 .mask = 0x000F & NTSC_N_443 ,
54 .v4l2_standard = {
55         .index = NTSC_N_443,
56         .id = V4L2_STD_UNKNOWN,
57         .name = "NTSC_N_443",
58         .frameperiod = {1, 25},
59         .framelines = 480,
60         .reserved = {0, 0, 0, 0}
61 }
62 },
63 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
64 {
65 .mask = 0x000F & PAL_Nc ,
66 .v4l2_standard = {
67         .index = PAL_Nc,
68         .id = V4L2_STD_PAL_Nc,
69         .name = "PAL_Nc",
70         .frameperiod = {1, 25},
71         .framelines = 625,
72         .reserved = {0, 0, 0, 0}
73 }
74 },
75 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
76 {
77 .mask = 0x000F & NTSC_N ,
78 .v4l2_standard = {
79         .index = NTSC_N,
80         .id = V4L2_STD_UNKNOWN,
81         .name = "NTSC_N",
82         .frameperiod = {1, 25},
83         .framelines = 525,
84         .reserved = {0, 0, 0, 0}
85 }
86 },
87 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
88 {
89 .mask = 0x000F & SECAM ,
90 .v4l2_standard = {
91         .index = SECAM,
92         .id = V4L2_STD_SECAM,
93         .name = "SECAM",
94         .frameperiod = {1, 25},
95         .framelines = 625,
96         .reserved = {0, 0, 0, 0}
97 }
98 },
99 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
100 {
101 .mask = 0x000F & NTSC_M ,
102 .v4l2_standard = {
103         .index = NTSC_M,
104         .id = V4L2_STD_NTSC_M,
105         .name = "NTSC_M",
106         .frameperiod = {1, 30},
107         .framelines = 525,
108         .reserved = {0, 0, 0, 0}
109 }
110 },
111 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
112 {
113 .mask = 0x000F & NTSC_M_JP ,
114 .v4l2_standard = {
115         .index = NTSC_M_JP,
116         .id = V4L2_STD_NTSC_M_JP,
117         .name = "NTSC_M_JP",
118         .frameperiod = {1, 30},
119         .framelines = 525,
120         .reserved = {0, 0, 0, 0}
121 }
122 },
123 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
124 {
125 .mask = 0x000F & PAL_60 ,
126 .v4l2_standard = {
127         .index = PAL_60,
128         .id = V4L2_STD_PAL_60,
129         .name = "PAL_60",
130         .frameperiod = {1, 30},
131         .framelines = 525,
132         .reserved = {0, 0, 0, 0}
133 }
134 },
135 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
136 {
137 .mask = 0x000F & NTSC_443 ,
138 .v4l2_standard = {
139         .index = NTSC_443,
140         .id = V4L2_STD_NTSC_443,
141         .name = "NTSC_443",
142         .frameperiod = {1, 30},
143         .framelines = 525,
144         .reserved = {0, 0, 0, 0}
145 }
146 },
147 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
148 {
149 .mask = 0x000F & PAL_M ,
150 .v4l2_standard = {
151         .index = PAL_M,
152         .id = V4L2_STD_PAL_M,
153         .name = "PAL_M",
154         .frameperiod = {1, 30},
155         .framelines = 525,
156         .reserved = {0, 0, 0, 0}
157 }
158 },
159 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
160 {
161 .mask = 0xFFFF
162 }
163 };
164 /*---------------------------------------------------------------------------*/
165 /*
166  *  THE 16-BIT easycap_format.mask HAS MEANING:
167  *    (least significant) BIT  0:     0 => PAL, 25 FPS;   1 => NTSC, 30 FPS
168  *                        BITS 1-3:   RESERVED FOR DIFFERENTIATING STANDARDS
169  *                        BITS 4-7:   NUMBER OF BYTES PER PIXEL
170  *                        BIT  8:     0 => NATIVE BYTE ORDER;  1 => SWAPPED
171  *                        BITS 9-10:  RESERVED FOR OTHER BYTE PERMUTATIONS
172  *                        BIT 11:     0 => UNDECIMATED;  1 => DECIMATED
173  *                        BIT 12:     0 => OFFER FRAMES; 1 => OFFER FIELDS
174  *     (most significant) BITS 13-15: RESERVED FOR OTHER FIELD ORDER OPTIONS
175  *  IT FOLLOWS THAT:
176  *     bytesperpixel IS         ((0x00F0 & easycap_format.mask) >> 4)
177  *     byteswaporder IS true IF (0 != (0x0100 & easycap_format.mask))
178  *
179  *     decimatepixel IS true IF (0 != (0x0800 & easycap_format.mask))
180  *
181  *       offerfields IS true IF (0 != (0x1000 & easycap_format.mask))
182  */
183 /*---------------------------------------------------------------------------*/
184
185 struct easycap_format easycap_format[1 + SETTINGS_MANY];
186
187 int
188 fillin_formats(void)
189 {
190 int i, j, k, m, n;
191 __u32 width, height, pixelformat, bytesperline, sizeimage;
192 __u32 field, colorspace;
193 __u16 mask1, mask2, mask3, mask4;
194 char name1[32], name2[32], name3[32], name4[32];
195
196 for (i = 0, n = 0; i < STANDARD_MANY; i++) {
197         mask1 = 0x0000;
198         switch (i) {
199         case PAL_BGHIN: {
200                 mask1 = PAL_BGHIN;
201                 strcpy(&name1[0], "PAL_BGHIN");
202                 colorspace = V4L2_COLORSPACE_470_SYSTEM_BG;
203                 break;
204         }
205         case SECAM: {
206                 mask1 = SECAM;
207                 strcpy(&name1[0], "SECAM");
208                 colorspace = V4L2_COLORSPACE_470_SYSTEM_BG;
209                 break;
210         }
211         case PAL_Nc: {
212                 mask1 = PAL_Nc;
213                 strcpy(&name1[0], "PAL_Nc");
214                 colorspace = V4L2_COLORSPACE_470_SYSTEM_BG;
215                 break;
216         }
217         case PAL_60: {
218                 mask1 = PAL_60;
219                 strcpy(&name1[0], "PAL_60");
220                 colorspace = V4L2_COLORSPACE_470_SYSTEM_BG;
221                 break;
222         }
223         case PAL_M: {
224                 mask1 = PAL_M;
225                 strcpy(&name1[0], "PAL_M");
226                 colorspace = V4L2_COLORSPACE_470_SYSTEM_BG;
227                 break;
228         }
229         case NTSC_M: {
230                 mask1 = NTSC_M;
231                 strcpy(&name1[0], "NTSC_M");
232                 colorspace = V4L2_COLORSPACE_470_SYSTEM_M;
233                 break;
234         }
235         case NTSC_443: {
236                 mask1 = NTSC_443;
237                 strcpy(&name1[0], "NTSC_443");
238                 colorspace = V4L2_COLORSPACE_470_SYSTEM_M;
239                 break;
240         }
241         case NTSC_M_JP: {
242                 mask1 = NTSC_M_JP;
243                 strcpy(&name1[0], "NTSC_M_JP");
244                 colorspace = V4L2_COLORSPACE_470_SYSTEM_M;
245                 break;
246         }
247         case NTSC_N: {
248                 mask1 = NTSC_M;
249                 strcpy(&name1[0], "NTSC_N");
250                 colorspace = V4L2_COLORSPACE_470_SYSTEM_M;
251                 break;
252         }
253         case NTSC_N_443: {
254                 mask1 = NTSC_N_443;
255                 strcpy(&name1[0], "NTSC_N_443");
256                 colorspace = V4L2_COLORSPACE_470_SYSTEM_M;
257                 break;
258         }
259         default:
260                 return -1;
261         }
262
263         for (j = 0; j < RESOLUTION_MANY; j++) {
264                 mask2 = 0x0000;
265                 switch (j) {
266                 case AT_720x576: {
267                         if (0x1 & mask1)
268                                 continue;
269                         strcpy(&name2[0], "_AT_720x576");
270                         width = 720; height = 576; break;
271                 }
272                 case AT_704x576: {
273                         if (0x1 & mask1)
274                                 continue;
275                         strcpy(&name2[0], "_AT_704x576");
276                         width = 704; height = 576; break;
277                 }
278                 case AT_640x480: {
279                         strcpy(&name2[0], "_AT_640x480");
280                         width = 640; height = 480; break;
281                 }
282                 case AT_720x480: {
283                         if (!(0x1 & mask1))
284                                 continue;
285                         strcpy(&name2[0], "_AT_720x480");
286                         width = 720; height = 480; break;
287                 }
288                 case AT_360x288: {
289                         if (0x1 & mask1)
290                                 continue;
291                         strcpy(&name2[0], "_AT_360x288");
292                         width = 360; height = 288; mask2 = 0x0800; break;
293                 }
294                 case AT_320x240: {
295                         strcpy(&name2[0], "_AT_320x240");
296                         width = 320; height = 240; mask2 = 0x0800; break;
297                 }
298                 case AT_360x240: {
299                         if (!(0x1 & mask1))
300                                 continue;
301                         strcpy(&name2[0], "_AT_360x240");
302                         width = 360; height = 240; mask2 = 0x0800; break;
303                 }
304                 default:
305                         return -2;
306                 }
307
308                 for (k = 0; k < PIXELFORMAT_MANY; k++) {
309                         mask3 = 0x0000;
310                         switch (k) {
311                         case FMT_UYVY: {
312                                 strcpy(&name3[0], "_" STRINGIZE(FMT_UYVY));
313                                 pixelformat = V4L2_PIX_FMT_UYVY;
314                                 mask3 |= (0x02 << 4);
315                                 break;
316                         }
317                         case FMT_YUY2: {
318                                 strcpy(&name3[0], "_" STRINGIZE(FMT_YUY2));
319                                 pixelformat = V4L2_PIX_FMT_YUYV;
320                                 mask3 |= (0x02 << 4);
321                                 mask3 |= 0x0100;
322                                 break;
323                         }
324                         case FMT_RGB24: {
325                                 strcpy(&name3[0], "_" STRINGIZE(FMT_RGB24));
326                                 pixelformat = V4L2_PIX_FMT_RGB24;
327                                 mask3 |= (0x03 << 4);
328                                 break;
329                         }
330                         case FMT_RGB32: {
331                                 strcpy(&name3[0], "_" STRINGIZE(FMT_RGB32));
332                                 pixelformat = V4L2_PIX_FMT_RGB32;
333                                 mask3 |= (0x04 << 4);
334                                 break;
335                         }
336                         case FMT_BGR24: {
337                                 strcpy(&name3[0], "_" STRINGIZE(FMT_BGR24));
338                                 pixelformat = V4L2_PIX_FMT_BGR24;
339                                 mask3 |= (0x03 << 4);
340                                 mask3 |= 0x0100;
341                                 break;
342                         }
343                         case FMT_BGR32: {
344                                 strcpy(&name3[0], "_" STRINGIZE(FMT_BGR32));
345                                 pixelformat = V4L2_PIX_FMT_BGR32;
346                                 mask3 |= (0x04 << 4);
347                                 mask3 |= 0x0100;
348                                 break;
349                         }
350                         default:
351                                 return -3;
352                         }
353                         bytesperline = width * ((mask3 & 0x00F0) >> 4);
354                         sizeimage =  bytesperline * height;
355
356                         for (m = 0; m < INTERLACE_MANY; m++) {
357                                 mask4 = 0x0000;
358                                 switch (m) {
359                                 case FIELD_NONE: {
360                                         strcpy(&name4[0], "-n");
361                                         field = V4L2_FIELD_NONE;
362                                         break;
363                                 }
364                                 case FIELD_INTERLACED: {
365                                         strcpy(&name4[0], "-i");
366                                         field = V4L2_FIELD_INTERLACED;
367                                         break;
368                                 }
369                                 case FIELD_ALTERNATE: {
370                                         strcpy(&name4[0], "-a");
371                                         mask4 |= 0x1000;
372                                         field = V4L2_FIELD_ALTERNATE;
373                                         break;
374                                 }
375                                 default:
376                                         return -4;
377                                 }
378                                 if (SETTINGS_MANY <= n)
379                                         return -5;
380                                 strcpy(&easycap_format[n].name[0], &name1[0]);
381                                 strcat(&easycap_format[n].name[0], &name2[0]);
382                                 strcat(&easycap_format[n].name[0], &name3[0]);
383                                 strcat(&easycap_format[n].name[0], &name4[0]);
384                                 easycap_format[n].mask = \
385                                                 mask1 | mask2 | mask3 | mask4;
386                                 easycap_format[n].v4l2_format\
387                                         .type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
388                                 easycap_format[n].v4l2_format\
389                                         .fmt.pix.width = width;
390                                 easycap_format[n].v4l2_format\
391                                         .fmt.pix.height = height;
392                                 easycap_format[n].v4l2_format\
393                                         .fmt.pix.pixelformat = pixelformat;
394                                 easycap_format[n].v4l2_format\
395                                         .fmt.pix.field = field;
396                                 easycap_format[n].v4l2_format\
397                                         .fmt.pix.bytesperline = bytesperline;
398                                 easycap_format[n].v4l2_format\
399                                         .fmt.pix.sizeimage = sizeimage;
400                                 easycap_format[n].v4l2_format\
401                                         .fmt.pix.colorspace = colorspace;
402                                 easycap_format[n].v4l2_format\
403                                         .fmt.pix.priv = 0;
404                                 n++;
405                         }
406                 }
407         }
408 }
409 if ((1 + SETTINGS_MANY) <= n)
410         return -6;
411 easycap_format[n].mask = 0xFFFF;
412 return n;
413 }
414 /*---------------------------------------------------------------------------*/
415 struct v4l2_queryctrl easycap_control[] = \
416  {{
417 .id       = V4L2_CID_BRIGHTNESS,
418 .type     = V4L2_CTRL_TYPE_INTEGER,
419 .name     = "Brightness",
420 .minimum  = 0,
421 .maximum  = 255,
422 .step     =  1,
423 .default_value = SAA_0A_DEFAULT,
424 .flags    = 0,
425 .reserved = {0, 0}
426 },
427 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
428 {
429 .id       = V4L2_CID_CONTRAST,
430 .type     = V4L2_CTRL_TYPE_INTEGER,
431 .name     = "Contrast",
432 .minimum  = 0,
433 .maximum  = 255,
434 .step     =   1,
435 .default_value = SAA_0B_DEFAULT + 128,
436 .flags    = 0,
437 .reserved = {0, 0}
438 },
439 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
440 {
441 .id       = V4L2_CID_SATURATION,
442 .type     = V4L2_CTRL_TYPE_INTEGER,
443 .name     = "Saturation",
444 .minimum  = 0,
445 .maximum  = 255,
446 .step     =   1,
447 .default_value = SAA_0C_DEFAULT + 128,
448 .flags    = 0,
449 .reserved = {0, 0}
450 },
451 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
452 {
453 .id       = V4L2_CID_HUE,
454 .type     = V4L2_CTRL_TYPE_INTEGER,
455 .name     = "Hue",
456 .minimum  = 0,
457 .maximum  = 255,
458 .step     =   1,
459 .default_value = SAA_0D_DEFAULT + 128,
460 .flags    = 0,
461 .reserved = {0, 0}
462 },
463 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
464 {
465 .id       = V4L2_CID_AUDIO_VOLUME,
466 .type     = V4L2_CTRL_TYPE_INTEGER,
467 .name     = "Volume",
468 .minimum  = 0,
469 .maximum  = 31,
470 .step     =   1,
471 .default_value = 16,
472 .flags    = 0,
473 .reserved = {0, 0}
474 },
475 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
476 {
477 .id       = V4L2_CID_AUDIO_MUTE,
478 .type     = V4L2_CTRL_TYPE_BOOLEAN,
479 .name     = "Mute",
480 .default_value = true,
481 .flags    = 0,
482 .reserved = {0, 0}
483 },
484 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
485 {
486 .id = 0xFFFFFFFF
487 }
488  };
489 /*****************************************************************************/