5cf9cc6c0e6e24785b0f785d066f2d87ff5b67ff
[deliverable/linux.git] / drivers / media / pci / saa7134 / saa7134-video.c
1 /*
2 *
3 * device driver for philips saa7134 based TV cards
4 * video4linux video interface
5 *
6 * (c) 2001-03 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include <linux/init.h>
24 #include <linux/list.h>
25 #include <linux/module.h>
26 #include <linux/kernel.h>
27 #include <linux/slab.h>
28 #include <linux/sort.h>
29
30 #include <media/v4l2-common.h>
31 #include <media/v4l2-event.h>
32 #include <media/saa6588.h>
33
34 #include "saa7134-reg.h"
35 #include "saa7134.h"
36
37 /* ------------------------------------------------------------------ */
38
39 unsigned int video_debug;
40 static unsigned int gbuffers = 8;
41 static unsigned int noninterlaced; /* 0 */
42 static unsigned int gbufsize = 720*576*4;
43 static unsigned int gbufsize_max = 720*576*4;
44 static char secam[] = "--";
45 module_param(video_debug, int, 0644);
46 MODULE_PARM_DESC(video_debug,"enable debug messages [video]");
47 module_param(gbuffers, int, 0444);
48 MODULE_PARM_DESC(gbuffers,"number of capture buffers, range 2-32");
49 module_param(noninterlaced, int, 0644);
50 MODULE_PARM_DESC(noninterlaced,"capture non interlaced video");
51 module_param_string(secam, secam, sizeof(secam), 0644);
52 MODULE_PARM_DESC(secam, "force SECAM variant, either DK,L or Lc");
53
54
55 #define dprintk(fmt, arg...) if (video_debug&0x04) \
56 printk(KERN_DEBUG "%s/video: " fmt, dev->name , ## arg)
57
58 /* ------------------------------------------------------------------ */
59 /* Defines for Video Output Port Register at address 0x191 */
60
61 /* Bit 0: VIP code T bit polarity */
62
63 #define VP_T_CODE_P_NON_INVERTED 0x00
64 #define VP_T_CODE_P_INVERTED 0x01
65
66 /* ------------------------------------------------------------------ */
67 /* Defines for Video Output Port Register at address 0x195 */
68
69 /* Bit 2: Video output clock delay control */
70
71 #define VP_CLK_CTRL2_NOT_DELAYED 0x00
72 #define VP_CLK_CTRL2_DELAYED 0x04
73
74 /* Bit 1: Video output clock invert control */
75
76 #define VP_CLK_CTRL1_NON_INVERTED 0x00
77 #define VP_CLK_CTRL1_INVERTED 0x02
78
79 /* ------------------------------------------------------------------ */
80 /* Defines for Video Output Port Register at address 0x196 */
81
82 /* Bits 2 to 0: VSYNC pin video vertical sync type */
83
84 #define VP_VS_TYPE_MASK 0x07
85
86 #define VP_VS_TYPE_OFF 0x00
87 #define VP_VS_TYPE_V123 0x01
88 #define VP_VS_TYPE_V_ITU 0x02
89 #define VP_VS_TYPE_VGATE_L 0x03
90 #define VP_VS_TYPE_RESERVED1 0x04
91 #define VP_VS_TYPE_RESERVED2 0x05
92 #define VP_VS_TYPE_F_ITU 0x06
93 #define VP_VS_TYPE_SC_FID 0x07
94
95 /* ------------------------------------------------------------------ */
96 /* data structs for video */
97
98 static int video_out[][9] = {
99 [CCIR656] = { 0x00, 0xb1, 0x00, 0xa1, 0x00, 0x04, 0x06, 0x00, 0x00 },
100 };
101
102 static struct saa7134_format formats[] = {
103 {
104 .name = "8 bpp gray",
105 .fourcc = V4L2_PIX_FMT_GREY,
106 .depth = 8,
107 .pm = 0x06,
108 },{
109 .name = "15 bpp RGB, le",
110 .fourcc = V4L2_PIX_FMT_RGB555,
111 .depth = 16,
112 .pm = 0x13 | 0x80,
113 },{
114 .name = "15 bpp RGB, be",
115 .fourcc = V4L2_PIX_FMT_RGB555X,
116 .depth = 16,
117 .pm = 0x13 | 0x80,
118 .bswap = 1,
119 },{
120 .name = "16 bpp RGB, le",
121 .fourcc = V4L2_PIX_FMT_RGB565,
122 .depth = 16,
123 .pm = 0x10 | 0x80,
124 },{
125 .name = "16 bpp RGB, be",
126 .fourcc = V4L2_PIX_FMT_RGB565X,
127 .depth = 16,
128 .pm = 0x10 | 0x80,
129 .bswap = 1,
130 },{
131 .name = "24 bpp RGB, le",
132 .fourcc = V4L2_PIX_FMT_BGR24,
133 .depth = 24,
134 .pm = 0x11,
135 },{
136 .name = "24 bpp RGB, be",
137 .fourcc = V4L2_PIX_FMT_RGB24,
138 .depth = 24,
139 .pm = 0x11,
140 .bswap = 1,
141 },{
142 .name = "32 bpp RGB, le",
143 .fourcc = V4L2_PIX_FMT_BGR32,
144 .depth = 32,
145 .pm = 0x12,
146 },{
147 .name = "32 bpp RGB, be",
148 .fourcc = V4L2_PIX_FMT_RGB32,
149 .depth = 32,
150 .pm = 0x12,
151 .bswap = 1,
152 .wswap = 1,
153 },{
154 .name = "4:2:2 packed, YUYV",
155 .fourcc = V4L2_PIX_FMT_YUYV,
156 .depth = 16,
157 .pm = 0x00,
158 .bswap = 1,
159 .yuv = 1,
160 },{
161 .name = "4:2:2 packed, UYVY",
162 .fourcc = V4L2_PIX_FMT_UYVY,
163 .depth = 16,
164 .pm = 0x00,
165 .yuv = 1,
166 },{
167 .name = "4:2:2 planar, Y-Cb-Cr",
168 .fourcc = V4L2_PIX_FMT_YUV422P,
169 .depth = 16,
170 .pm = 0x09,
171 .yuv = 1,
172 .planar = 1,
173 .hshift = 1,
174 .vshift = 0,
175 },{
176 .name = "4:2:0 planar, Y-Cb-Cr",
177 .fourcc = V4L2_PIX_FMT_YUV420,
178 .depth = 12,
179 .pm = 0x0a,
180 .yuv = 1,
181 .planar = 1,
182 .hshift = 1,
183 .vshift = 1,
184 },{
185 .name = "4:2:0 planar, Y-Cb-Cr",
186 .fourcc = V4L2_PIX_FMT_YVU420,
187 .depth = 12,
188 .pm = 0x0a,
189 .yuv = 1,
190 .planar = 1,
191 .uvswap = 1,
192 .hshift = 1,
193 .vshift = 1,
194 }
195 };
196 #define FORMATS ARRAY_SIZE(formats)
197
198 #define NORM_625_50 \
199 .h_start = 0, \
200 .h_stop = 719, \
201 .video_v_start = 24, \
202 .video_v_stop = 311, \
203 .vbi_v_start_0 = 7, \
204 .vbi_v_stop_0 = 22, \
205 .vbi_v_start_1 = 319, \
206 .src_timing = 4
207
208 #define NORM_525_60 \
209 .h_start = 0, \
210 .h_stop = 719, \
211 .video_v_start = 23, \
212 .video_v_stop = 262, \
213 .vbi_v_start_0 = 10, \
214 .vbi_v_stop_0 = 21, \
215 .vbi_v_start_1 = 273, \
216 .src_timing = 7
217
218 static struct saa7134_tvnorm tvnorms[] = {
219 {
220 .name = "PAL", /* autodetect */
221 .id = V4L2_STD_PAL,
222 NORM_625_50,
223
224 .sync_control = 0x18,
225 .luma_control = 0x40,
226 .chroma_ctrl1 = 0x81,
227 .chroma_gain = 0x2a,
228 .chroma_ctrl2 = 0x06,
229 .vgate_misc = 0x1c,
230
231 },{
232 .name = "PAL-BG",
233 .id = V4L2_STD_PAL_BG,
234 NORM_625_50,
235
236 .sync_control = 0x18,
237 .luma_control = 0x40,
238 .chroma_ctrl1 = 0x81,
239 .chroma_gain = 0x2a,
240 .chroma_ctrl2 = 0x06,
241 .vgate_misc = 0x1c,
242
243 },{
244 .name = "PAL-I",
245 .id = V4L2_STD_PAL_I,
246 NORM_625_50,
247
248 .sync_control = 0x18,
249 .luma_control = 0x40,
250 .chroma_ctrl1 = 0x81,
251 .chroma_gain = 0x2a,
252 .chroma_ctrl2 = 0x06,
253 .vgate_misc = 0x1c,
254
255 },{
256 .name = "PAL-DK",
257 .id = V4L2_STD_PAL_DK,
258 NORM_625_50,
259
260 .sync_control = 0x18,
261 .luma_control = 0x40,
262 .chroma_ctrl1 = 0x81,
263 .chroma_gain = 0x2a,
264 .chroma_ctrl2 = 0x06,
265 .vgate_misc = 0x1c,
266
267 },{
268 .name = "NTSC",
269 .id = V4L2_STD_NTSC,
270 NORM_525_60,
271
272 .sync_control = 0x59,
273 .luma_control = 0x40,
274 .chroma_ctrl1 = 0x89,
275 .chroma_gain = 0x2a,
276 .chroma_ctrl2 = 0x0e,
277 .vgate_misc = 0x18,
278
279 },{
280 .name = "SECAM",
281 .id = V4L2_STD_SECAM,
282 NORM_625_50,
283
284 .sync_control = 0x18,
285 .luma_control = 0x1b,
286 .chroma_ctrl1 = 0xd1,
287 .chroma_gain = 0x80,
288 .chroma_ctrl2 = 0x00,
289 .vgate_misc = 0x1c,
290
291 },{
292 .name = "SECAM-DK",
293 .id = V4L2_STD_SECAM_DK,
294 NORM_625_50,
295
296 .sync_control = 0x18,
297 .luma_control = 0x1b,
298 .chroma_ctrl1 = 0xd1,
299 .chroma_gain = 0x80,
300 .chroma_ctrl2 = 0x00,
301 .vgate_misc = 0x1c,
302
303 },{
304 .name = "SECAM-L",
305 .id = V4L2_STD_SECAM_L,
306 NORM_625_50,
307
308 .sync_control = 0x18,
309 .luma_control = 0x1b,
310 .chroma_ctrl1 = 0xd1,
311 .chroma_gain = 0x80,
312 .chroma_ctrl2 = 0x00,
313 .vgate_misc = 0x1c,
314
315 },{
316 .name = "SECAM-Lc",
317 .id = V4L2_STD_SECAM_LC,
318 NORM_625_50,
319
320 .sync_control = 0x18,
321 .luma_control = 0x1b,
322 .chroma_ctrl1 = 0xd1,
323 .chroma_gain = 0x80,
324 .chroma_ctrl2 = 0x00,
325 .vgate_misc = 0x1c,
326
327 },{
328 .name = "PAL-M",
329 .id = V4L2_STD_PAL_M,
330 NORM_525_60,
331
332 .sync_control = 0x59,
333 .luma_control = 0x40,
334 .chroma_ctrl1 = 0xb9,
335 .chroma_gain = 0x2a,
336 .chroma_ctrl2 = 0x0e,
337 .vgate_misc = 0x18,
338
339 },{
340 .name = "PAL-Nc",
341 .id = V4L2_STD_PAL_Nc,
342 NORM_625_50,
343
344 .sync_control = 0x18,
345 .luma_control = 0x40,
346 .chroma_ctrl1 = 0xa1,
347 .chroma_gain = 0x2a,
348 .chroma_ctrl2 = 0x06,
349 .vgate_misc = 0x1c,
350
351 },{
352 .name = "PAL-60",
353 .id = V4L2_STD_PAL_60,
354
355 .h_start = 0,
356 .h_stop = 719,
357 .video_v_start = 23,
358 .video_v_stop = 262,
359 .vbi_v_start_0 = 10,
360 .vbi_v_stop_0 = 21,
361 .vbi_v_start_1 = 273,
362 .src_timing = 7,
363
364 .sync_control = 0x18,
365 .luma_control = 0x40,
366 .chroma_ctrl1 = 0x81,
367 .chroma_gain = 0x2a,
368 .chroma_ctrl2 = 0x06,
369 .vgate_misc = 0x1c,
370 }
371 };
372 #define TVNORMS ARRAY_SIZE(tvnorms)
373
374 static struct saa7134_format* format_by_fourcc(unsigned int fourcc)
375 {
376 unsigned int i;
377
378 for (i = 0; i < FORMATS; i++)
379 if (formats[i].fourcc == fourcc)
380 return formats+i;
381 return NULL;
382 }
383
384 /* ----------------------------------------------------------------------- */
385 /* resource management */
386
387 static int res_get(struct saa7134_dev *dev, struct saa7134_fh *fh, unsigned int bit)
388 {
389 if (fh->resources & bit)
390 /* have it already allocated */
391 return 1;
392
393 /* is it free? */
394 mutex_lock(&dev->lock);
395 if (dev->resources & bit) {
396 /* no, someone else uses it */
397 mutex_unlock(&dev->lock);
398 return 0;
399 }
400 /* it's free, grab it */
401 fh->resources |= bit;
402 dev->resources |= bit;
403 dprintk("res: get %d\n",bit);
404 mutex_unlock(&dev->lock);
405 return 1;
406 }
407
408 static
409 void res_free(struct saa7134_dev *dev, struct saa7134_fh *fh, unsigned int bits)
410 {
411 BUG_ON((fh->resources & bits) != bits);
412
413 mutex_lock(&dev->lock);
414 fh->resources &= ~bits;
415 dev->resources &= ~bits;
416 dprintk("res: put %d\n",bits);
417 mutex_unlock(&dev->lock);
418 }
419
420 /* ------------------------------------------------------------------ */
421
422 static void set_tvnorm(struct saa7134_dev *dev, struct saa7134_tvnorm *norm)
423 {
424 dprintk("set tv norm = %s\n",norm->name);
425 dev->tvnorm = norm;
426
427 /* setup cropping */
428 dev->crop_bounds.left = norm->h_start;
429 dev->crop_defrect.left = norm->h_start;
430 dev->crop_bounds.width = norm->h_stop - norm->h_start +1;
431 dev->crop_defrect.width = norm->h_stop - norm->h_start +1;
432
433 dev->crop_bounds.top = (norm->vbi_v_stop_0+1)*2;
434 dev->crop_defrect.top = norm->video_v_start*2;
435 dev->crop_bounds.height = ((norm->id & V4L2_STD_525_60) ? 524 : 624)
436 - dev->crop_bounds.top;
437 dev->crop_defrect.height = (norm->video_v_stop - norm->video_v_start +1)*2;
438
439 dev->crop_current = dev->crop_defrect;
440
441 saa7134_set_tvnorm_hw(dev);
442 }
443
444 static void video_mux(struct saa7134_dev *dev, int input)
445 {
446 dprintk("video input = %d [%s]\n", input, card_in(dev, input).name);
447 dev->ctl_input = input;
448 set_tvnorm(dev, dev->tvnorm);
449 saa7134_tvaudio_setinput(dev, &card_in(dev, input));
450 }
451
452
453 static void saa7134_set_decoder(struct saa7134_dev *dev)
454 {
455 int luma_control, sync_control, mux;
456
457 struct saa7134_tvnorm *norm = dev->tvnorm;
458 mux = card_in(dev, dev->ctl_input).vmux;
459
460 luma_control = norm->luma_control;
461 sync_control = norm->sync_control;
462
463 if (mux > 5)
464 luma_control |= 0x80; /* svideo */
465 if (noninterlaced || dev->nosignal)
466 sync_control |= 0x20;
467
468 /* setup video decoder */
469 saa_writeb(SAA7134_INCR_DELAY, 0x08);
470 saa_writeb(SAA7134_ANALOG_IN_CTRL1, 0xc0 | mux);
471 saa_writeb(SAA7134_ANALOG_IN_CTRL2, 0x00);
472
473 saa_writeb(SAA7134_ANALOG_IN_CTRL3, 0x90);
474 saa_writeb(SAA7134_ANALOG_IN_CTRL4, 0x90);
475 saa_writeb(SAA7134_HSYNC_START, 0xeb);
476 saa_writeb(SAA7134_HSYNC_STOP, 0xe0);
477 saa_writeb(SAA7134_SOURCE_TIMING1, norm->src_timing);
478
479 saa_writeb(SAA7134_SYNC_CTRL, sync_control);
480 saa_writeb(SAA7134_LUMA_CTRL, luma_control);
481 saa_writeb(SAA7134_DEC_LUMA_BRIGHT, dev->ctl_bright);
482
483 saa_writeb(SAA7134_DEC_LUMA_CONTRAST,
484 dev->ctl_invert ? -dev->ctl_contrast : dev->ctl_contrast);
485
486 saa_writeb(SAA7134_DEC_CHROMA_SATURATION,
487 dev->ctl_invert ? -dev->ctl_saturation : dev->ctl_saturation);
488
489 saa_writeb(SAA7134_DEC_CHROMA_HUE, dev->ctl_hue);
490 saa_writeb(SAA7134_CHROMA_CTRL1, norm->chroma_ctrl1);
491 saa_writeb(SAA7134_CHROMA_GAIN, norm->chroma_gain);
492
493 saa_writeb(SAA7134_CHROMA_CTRL2, norm->chroma_ctrl2);
494 saa_writeb(SAA7134_MODE_DELAY_CTRL, 0x00);
495
496 saa_writeb(SAA7134_ANALOG_ADC, 0x01);
497 saa_writeb(SAA7134_VGATE_START, 0x11);
498 saa_writeb(SAA7134_VGATE_STOP, 0xfe);
499 saa_writeb(SAA7134_MISC_VGATE_MSB, norm->vgate_misc);
500 saa_writeb(SAA7134_RAW_DATA_GAIN, 0x40);
501 saa_writeb(SAA7134_RAW_DATA_OFFSET, 0x80);
502 }
503
504 void saa7134_set_tvnorm_hw(struct saa7134_dev *dev)
505 {
506 saa7134_set_decoder(dev);
507
508 if (card_in(dev, dev->ctl_input).tv)
509 saa_call_all(dev, core, s_std, dev->tvnorm->id);
510 /* Set the correct norm for the saa6752hs. This function
511 does nothing if there is no saa6752hs. */
512 saa_call_empress(dev, core, s_std, dev->tvnorm->id);
513 }
514
515 static void set_h_prescale(struct saa7134_dev *dev, int task, int prescale)
516 {
517 static const struct {
518 int xpsc;
519 int xacl;
520 int xc2_1;
521 int xdcg;
522 int vpfy;
523 } vals[] = {
524 /* XPSC XACL XC2_1 XDCG VPFY */
525 { 1, 0, 0, 0, 0 },
526 { 2, 2, 1, 2, 2 },
527 { 3, 4, 1, 3, 2 },
528 { 4, 8, 1, 4, 2 },
529 { 5, 8, 1, 4, 2 },
530 { 6, 8, 1, 4, 3 },
531 { 7, 8, 1, 4, 3 },
532 { 8, 15, 0, 4, 3 },
533 { 9, 15, 0, 4, 3 },
534 { 10, 16, 1, 5, 3 },
535 };
536 static const int count = ARRAY_SIZE(vals);
537 int i;
538
539 for (i = 0; i < count; i++)
540 if (vals[i].xpsc == prescale)
541 break;
542 if (i == count)
543 return;
544
545 saa_writeb(SAA7134_H_PRESCALE(task), vals[i].xpsc);
546 saa_writeb(SAA7134_ACC_LENGTH(task), vals[i].xacl);
547 saa_writeb(SAA7134_LEVEL_CTRL(task),
548 (vals[i].xc2_1 << 3) | (vals[i].xdcg));
549 saa_andorb(SAA7134_FIR_PREFILTER_CTRL(task), 0x0f,
550 (vals[i].vpfy << 2) | vals[i].vpfy);
551 }
552
553 static void set_v_scale(struct saa7134_dev *dev, int task, int yscale)
554 {
555 int val,mirror;
556
557 saa_writeb(SAA7134_V_SCALE_RATIO1(task), yscale & 0xff);
558 saa_writeb(SAA7134_V_SCALE_RATIO2(task), yscale >> 8);
559
560 mirror = (dev->ctl_mirror) ? 0x02 : 0x00;
561 if (yscale < 2048) {
562 /* LPI */
563 dprintk("yscale LPI yscale=%d\n",yscale);
564 saa_writeb(SAA7134_V_FILTER(task), 0x00 | mirror);
565 saa_writeb(SAA7134_LUMA_CONTRAST(task), 0x40);
566 saa_writeb(SAA7134_CHROMA_SATURATION(task), 0x40);
567 } else {
568 /* ACM */
569 val = 0x40 * 1024 / yscale;
570 dprintk("yscale ACM yscale=%d val=0x%x\n",yscale,val);
571 saa_writeb(SAA7134_V_FILTER(task), 0x01 | mirror);
572 saa_writeb(SAA7134_LUMA_CONTRAST(task), val);
573 saa_writeb(SAA7134_CHROMA_SATURATION(task), val);
574 }
575 saa_writeb(SAA7134_LUMA_BRIGHT(task), 0x80);
576 }
577
578 static void set_size(struct saa7134_dev *dev, int task,
579 int width, int height, int interlace)
580 {
581 int prescale,xscale,yscale,y_even,y_odd;
582 int h_start, h_stop, v_start, v_stop;
583 int div = interlace ? 2 : 1;
584
585 /* setup video scaler */
586 h_start = dev->crop_current.left;
587 v_start = dev->crop_current.top/2;
588 h_stop = (dev->crop_current.left + dev->crop_current.width -1);
589 v_stop = (dev->crop_current.top + dev->crop_current.height -1)/2;
590
591 saa_writeb(SAA7134_VIDEO_H_START1(task), h_start & 0xff);
592 saa_writeb(SAA7134_VIDEO_H_START2(task), h_start >> 8);
593 saa_writeb(SAA7134_VIDEO_H_STOP1(task), h_stop & 0xff);
594 saa_writeb(SAA7134_VIDEO_H_STOP2(task), h_stop >> 8);
595 saa_writeb(SAA7134_VIDEO_V_START1(task), v_start & 0xff);
596 saa_writeb(SAA7134_VIDEO_V_START2(task), v_start >> 8);
597 saa_writeb(SAA7134_VIDEO_V_STOP1(task), v_stop & 0xff);
598 saa_writeb(SAA7134_VIDEO_V_STOP2(task), v_stop >> 8);
599
600 prescale = dev->crop_current.width / width;
601 if (0 == prescale)
602 prescale = 1;
603 xscale = 1024 * dev->crop_current.width / prescale / width;
604 yscale = 512 * div * dev->crop_current.height / height;
605 dprintk("prescale=%d xscale=%d yscale=%d\n",prescale,xscale,yscale);
606 set_h_prescale(dev,task,prescale);
607 saa_writeb(SAA7134_H_SCALE_INC1(task), xscale & 0xff);
608 saa_writeb(SAA7134_H_SCALE_INC2(task), xscale >> 8);
609 set_v_scale(dev,task,yscale);
610
611 saa_writeb(SAA7134_VIDEO_PIXELS1(task), width & 0xff);
612 saa_writeb(SAA7134_VIDEO_PIXELS2(task), width >> 8);
613 saa_writeb(SAA7134_VIDEO_LINES1(task), height/div & 0xff);
614 saa_writeb(SAA7134_VIDEO_LINES2(task), height/div >> 8);
615
616 /* deinterlace y offsets */
617 y_odd = dev->ctl_y_odd;
618 y_even = dev->ctl_y_even;
619 saa_writeb(SAA7134_V_PHASE_OFFSET0(task), y_odd);
620 saa_writeb(SAA7134_V_PHASE_OFFSET1(task), y_even);
621 saa_writeb(SAA7134_V_PHASE_OFFSET2(task), y_odd);
622 saa_writeb(SAA7134_V_PHASE_OFFSET3(task), y_even);
623 }
624
625 /* ------------------------------------------------------------------ */
626
627 struct cliplist {
628 __u16 position;
629 __u8 enable;
630 __u8 disable;
631 };
632
633 static void set_cliplist(struct saa7134_dev *dev, int reg,
634 struct cliplist *cl, int entries, char *name)
635 {
636 __u8 winbits = 0;
637 int i;
638
639 for (i = 0; i < entries; i++) {
640 winbits |= cl[i].enable;
641 winbits &= ~cl[i].disable;
642 if (i < 15 && cl[i].position == cl[i+1].position)
643 continue;
644 saa_writeb(reg + 0, winbits);
645 saa_writeb(reg + 2, cl[i].position & 0xff);
646 saa_writeb(reg + 3, cl[i].position >> 8);
647 dprintk("clip: %s winbits=%02x pos=%d\n",
648 name,winbits,cl[i].position);
649 reg += 8;
650 }
651 for (; reg < 0x400; reg += 8) {
652 saa_writeb(reg+ 0, 0);
653 saa_writeb(reg + 1, 0);
654 saa_writeb(reg + 2, 0);
655 saa_writeb(reg + 3, 0);
656 }
657 }
658
659 static int clip_range(int val)
660 {
661 if (val < 0)
662 val = 0;
663 return val;
664 }
665
666 /* Sort into smallest position first order */
667 static int cliplist_cmp(const void *a, const void *b)
668 {
669 const struct cliplist *cla = a;
670 const struct cliplist *clb = b;
671 if (cla->position < clb->position)
672 return -1;
673 if (cla->position > clb->position)
674 return 1;
675 return 0;
676 }
677
678 static int setup_clipping(struct saa7134_dev *dev, struct v4l2_clip *clips,
679 int nclips, int interlace)
680 {
681 struct cliplist col[16], row[16];
682 int cols = 0, rows = 0, i;
683 int div = interlace ? 2 : 1;
684
685 memset(col, 0, sizeof(col));
686 memset(row, 0, sizeof(row));
687 for (i = 0; i < nclips && i < 8; i++) {
688 col[cols].position = clip_range(clips[i].c.left);
689 col[cols].enable = (1 << i);
690 cols++;
691 col[cols].position = clip_range(clips[i].c.left+clips[i].c.width);
692 col[cols].disable = (1 << i);
693 cols++;
694 row[rows].position = clip_range(clips[i].c.top / div);
695 row[rows].enable = (1 << i);
696 rows++;
697 row[rows].position = clip_range((clips[i].c.top + clips[i].c.height)
698 / div);
699 row[rows].disable = (1 << i);
700 rows++;
701 }
702 sort(col, cols, sizeof col[0], cliplist_cmp, NULL);
703 sort(row, rows, sizeof row[0], cliplist_cmp, NULL);
704 set_cliplist(dev,0x380,col,cols,"cols");
705 set_cliplist(dev,0x384,row,rows,"rows");
706 return 0;
707 }
708
709 static int verify_preview(struct saa7134_dev *dev, struct v4l2_window *win, bool try)
710 {
711 enum v4l2_field field;
712 int maxw, maxh;
713
714 if (!try && (dev->ovbuf.base == NULL || dev->ovfmt == NULL))
715 return -EINVAL;
716 if (win->w.width < 48)
717 win->w.width = 48;
718 if (win->w.height < 32)
719 win->w.height = 32;
720 if (win->clipcount > 8)
721 win->clipcount = 8;
722
723 win->chromakey = 0;
724 win->global_alpha = 0;
725 field = win->field;
726 maxw = dev->crop_current.width;
727 maxh = dev->crop_current.height;
728
729 if (V4L2_FIELD_ANY == field) {
730 field = (win->w.height > maxh/2)
731 ? V4L2_FIELD_INTERLACED
732 : V4L2_FIELD_TOP;
733 }
734 switch (field) {
735 case V4L2_FIELD_TOP:
736 case V4L2_FIELD_BOTTOM:
737 maxh = maxh / 2;
738 break;
739 default:
740 field = V4L2_FIELD_INTERLACED;
741 break;
742 }
743
744 win->field = field;
745 if (win->w.width > maxw)
746 win->w.width = maxw;
747 if (win->w.height > maxh)
748 win->w.height = maxh;
749 return 0;
750 }
751
752 static int start_preview(struct saa7134_dev *dev)
753 {
754 unsigned long base,control,bpl;
755 int err;
756
757 err = verify_preview(dev, &dev->win, false);
758 if (0 != err)
759 return err;
760
761 dev->ovfield = dev->win.field;
762 dprintk("start_preview %dx%d+%d+%d %s field=%s\n",
763 dev->win.w.width, dev->win.w.height,
764 dev->win.w.left, dev->win.w.top,
765 dev->ovfmt->name, v4l2_field_names[dev->ovfield]);
766
767 /* setup window + clipping */
768 set_size(dev, TASK_B, dev->win.w.width, dev->win.w.height,
769 V4L2_FIELD_HAS_BOTH(dev->ovfield));
770 setup_clipping(dev, dev->clips, dev->nclips,
771 V4L2_FIELD_HAS_BOTH(dev->ovfield));
772 if (dev->ovfmt->yuv)
773 saa_andorb(SAA7134_DATA_PATH(TASK_B), 0x3f, 0x03);
774 else
775 saa_andorb(SAA7134_DATA_PATH(TASK_B), 0x3f, 0x01);
776 saa_writeb(SAA7134_OFMT_VIDEO_B, dev->ovfmt->pm | 0x20);
777
778 /* dma: setup channel 1 (= Video Task B) */
779 base = (unsigned long)dev->ovbuf.base;
780 base += dev->ovbuf.fmt.bytesperline * dev->win.w.top;
781 base += dev->ovfmt->depth/8 * dev->win.w.left;
782 bpl = dev->ovbuf.fmt.bytesperline;
783 control = SAA7134_RS_CONTROL_BURST_16;
784 if (dev->ovfmt->bswap)
785 control |= SAA7134_RS_CONTROL_BSWAP;
786 if (dev->ovfmt->wswap)
787 control |= SAA7134_RS_CONTROL_WSWAP;
788 if (V4L2_FIELD_HAS_BOTH(dev->ovfield)) {
789 saa_writel(SAA7134_RS_BA1(1),base);
790 saa_writel(SAA7134_RS_BA2(1),base+bpl);
791 saa_writel(SAA7134_RS_PITCH(1),bpl*2);
792 saa_writel(SAA7134_RS_CONTROL(1),control);
793 } else {
794 saa_writel(SAA7134_RS_BA1(1),base);
795 saa_writel(SAA7134_RS_BA2(1),base);
796 saa_writel(SAA7134_RS_PITCH(1),bpl);
797 saa_writel(SAA7134_RS_CONTROL(1),control);
798 }
799
800 /* start dma */
801 dev->ovenable = 1;
802 saa7134_set_dmabits(dev);
803
804 return 0;
805 }
806
807 static int stop_preview(struct saa7134_dev *dev)
808 {
809 dev->ovenable = 0;
810 saa7134_set_dmabits(dev);
811 return 0;
812 }
813
814 /* ------------------------------------------------------------------ */
815
816 static int buffer_activate(struct saa7134_dev *dev,
817 struct saa7134_buf *buf,
818 struct saa7134_buf *next)
819 {
820 unsigned long base,control,bpl;
821 unsigned long bpl_uv,lines_uv,base2,base3,tmp; /* planar */
822
823 dprintk("buffer_activate buf=%p\n",buf);
824 buf->vb.state = VIDEOBUF_ACTIVE;
825 buf->top_seen = 0;
826
827 set_size(dev,TASK_A,buf->vb.width,buf->vb.height,
828 V4L2_FIELD_HAS_BOTH(buf->vb.field));
829 if (buf->fmt->yuv)
830 saa_andorb(SAA7134_DATA_PATH(TASK_A), 0x3f, 0x03);
831 else
832 saa_andorb(SAA7134_DATA_PATH(TASK_A), 0x3f, 0x01);
833 saa_writeb(SAA7134_OFMT_VIDEO_A, buf->fmt->pm);
834
835 /* DMA: setup channel 0 (= Video Task A0) */
836 base = saa7134_buffer_base(buf);
837 if (buf->fmt->planar)
838 bpl = buf->vb.width;
839 else
840 bpl = (buf->vb.width * buf->fmt->depth) / 8;
841 control = SAA7134_RS_CONTROL_BURST_16 |
842 SAA7134_RS_CONTROL_ME |
843 (buf->pt->dma >> 12);
844 if (buf->fmt->bswap)
845 control |= SAA7134_RS_CONTROL_BSWAP;
846 if (buf->fmt->wswap)
847 control |= SAA7134_RS_CONTROL_WSWAP;
848 if (V4L2_FIELD_HAS_BOTH(buf->vb.field)) {
849 /* interlaced */
850 saa_writel(SAA7134_RS_BA1(0),base);
851 saa_writel(SAA7134_RS_BA2(0),base+bpl);
852 saa_writel(SAA7134_RS_PITCH(0),bpl*2);
853 } else {
854 /* non-interlaced */
855 saa_writel(SAA7134_RS_BA1(0),base);
856 saa_writel(SAA7134_RS_BA2(0),base);
857 saa_writel(SAA7134_RS_PITCH(0),bpl);
858 }
859 saa_writel(SAA7134_RS_CONTROL(0),control);
860
861 if (buf->fmt->planar) {
862 /* DMA: setup channel 4+5 (= planar task A) */
863 bpl_uv = bpl >> buf->fmt->hshift;
864 lines_uv = buf->vb.height >> buf->fmt->vshift;
865 base2 = base + bpl * buf->vb.height;
866 base3 = base2 + bpl_uv * lines_uv;
867 if (buf->fmt->uvswap)
868 tmp = base2, base2 = base3, base3 = tmp;
869 dprintk("uv: bpl=%ld lines=%ld base2/3=%ld/%ld\n",
870 bpl_uv,lines_uv,base2,base3);
871 if (V4L2_FIELD_HAS_BOTH(buf->vb.field)) {
872 /* interlaced */
873 saa_writel(SAA7134_RS_BA1(4),base2);
874 saa_writel(SAA7134_RS_BA2(4),base2+bpl_uv);
875 saa_writel(SAA7134_RS_PITCH(4),bpl_uv*2);
876 saa_writel(SAA7134_RS_BA1(5),base3);
877 saa_writel(SAA7134_RS_BA2(5),base3+bpl_uv);
878 saa_writel(SAA7134_RS_PITCH(5),bpl_uv*2);
879 } else {
880 /* non-interlaced */
881 saa_writel(SAA7134_RS_BA1(4),base2);
882 saa_writel(SAA7134_RS_BA2(4),base2);
883 saa_writel(SAA7134_RS_PITCH(4),bpl_uv);
884 saa_writel(SAA7134_RS_BA1(5),base3);
885 saa_writel(SAA7134_RS_BA2(5),base3);
886 saa_writel(SAA7134_RS_PITCH(5),bpl_uv);
887 }
888 saa_writel(SAA7134_RS_CONTROL(4),control);
889 saa_writel(SAA7134_RS_CONTROL(5),control);
890 }
891
892 /* start DMA */
893 saa7134_set_dmabits(dev);
894 mod_timer(&dev->video_q.timeout, jiffies+BUFFER_TIMEOUT);
895 return 0;
896 }
897
898 static int buffer_prepare(struct videobuf_queue *q,
899 struct videobuf_buffer *vb,
900 enum v4l2_field field)
901 {
902 struct saa7134_dev *dev = q->priv_data;
903 struct saa7134_buf *buf = container_of(vb,struct saa7134_buf,vb);
904 unsigned int size;
905 int err;
906
907 /* sanity checks */
908 if (NULL == dev->fmt)
909 return -EINVAL;
910 if (dev->width < 48 ||
911 dev->height < 32 ||
912 dev->width/4 > dev->crop_current.width ||
913 dev->height/4 > dev->crop_current.height ||
914 dev->width > dev->crop_bounds.width ||
915 dev->height > dev->crop_bounds.height)
916 return -EINVAL;
917 size = (dev->width * dev->height * dev->fmt->depth) >> 3;
918 if (0 != buf->vb.baddr && buf->vb.bsize < size)
919 return -EINVAL;
920
921 dprintk("buffer_prepare [%d,size=%dx%d,bytes=%d,fields=%s,%s]\n",
922 vb->i, dev->width, dev->height, size, v4l2_field_names[field],
923 dev->fmt->name);
924 if (buf->vb.width != dev->width ||
925 buf->vb.height != dev->height ||
926 buf->vb.size != size ||
927 buf->vb.field != field ||
928 buf->fmt != dev->fmt) {
929 saa7134_dma_free(q,buf);
930 }
931
932 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
933 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
934
935 buf->vb.width = dev->width;
936 buf->vb.height = dev->height;
937 buf->vb.size = size;
938 buf->vb.field = field;
939 buf->fmt = dev->fmt;
940 buf->pt = &dev->pt_cap;
941 dev->video_q.curr = NULL;
942
943 err = videobuf_iolock(q,&buf->vb,&dev->ovbuf);
944 if (err)
945 goto oops;
946 err = saa7134_pgtable_build(dev->pci,buf->pt,
947 dma->sglist,
948 dma->sglen,
949 saa7134_buffer_startpage(buf));
950 if (err)
951 goto oops;
952 }
953 buf->vb.state = VIDEOBUF_PREPARED;
954 buf->activate = buffer_activate;
955 return 0;
956
957 oops:
958 saa7134_dma_free(q,buf);
959 return err;
960 }
961
962 static int
963 buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size)
964 {
965 struct saa7134_dev *dev = q->priv_data;
966
967 *size = dev->fmt->depth * dev->width * dev->height >> 3;
968 if (0 == *count)
969 *count = gbuffers;
970 *count = saa7134_buffer_count(*size,*count);
971 return 0;
972 }
973
974 static void buffer_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
975 {
976 struct saa7134_dev *dev = q->priv_data;
977 struct saa7134_buf *buf = container_of(vb,struct saa7134_buf,vb);
978
979 saa7134_buffer_queue(dev, &dev->video_q, buf);
980 }
981
982 static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
983 {
984 struct saa7134_buf *buf = container_of(vb,struct saa7134_buf,vb);
985
986 saa7134_dma_free(q,buf);
987 }
988
989 static struct videobuf_queue_ops video_qops = {
990 .buf_setup = buffer_setup,
991 .buf_prepare = buffer_prepare,
992 .buf_queue = buffer_queue,
993 .buf_release = buffer_release,
994 };
995
996 /* ------------------------------------------------------------------ */
997
998 static int saa7134_s_ctrl(struct v4l2_ctrl *ctrl)
999 {
1000 struct saa7134_dev *dev = container_of(ctrl->handler, struct saa7134_dev, ctrl_handler);
1001 unsigned long flags;
1002 int restart_overlay = 0;
1003
1004 switch (ctrl->id) {
1005 case V4L2_CID_BRIGHTNESS:
1006 dev->ctl_bright = ctrl->val;
1007 saa_writeb(SAA7134_DEC_LUMA_BRIGHT, ctrl->val);
1008 break;
1009 case V4L2_CID_HUE:
1010 dev->ctl_hue = ctrl->val;
1011 saa_writeb(SAA7134_DEC_CHROMA_HUE, ctrl->val);
1012 break;
1013 case V4L2_CID_CONTRAST:
1014 dev->ctl_contrast = ctrl->val;
1015 saa_writeb(SAA7134_DEC_LUMA_CONTRAST,
1016 dev->ctl_invert ? -dev->ctl_contrast : dev->ctl_contrast);
1017 break;
1018 case V4L2_CID_SATURATION:
1019 dev->ctl_saturation = ctrl->val;
1020 saa_writeb(SAA7134_DEC_CHROMA_SATURATION,
1021 dev->ctl_invert ? -dev->ctl_saturation : dev->ctl_saturation);
1022 break;
1023 case V4L2_CID_AUDIO_MUTE:
1024 dev->ctl_mute = ctrl->val;
1025 saa7134_tvaudio_setmute(dev);
1026 break;
1027 case V4L2_CID_AUDIO_VOLUME:
1028 dev->ctl_volume = ctrl->val;
1029 saa7134_tvaudio_setvolume(dev,dev->ctl_volume);
1030 break;
1031 case V4L2_CID_PRIVATE_INVERT:
1032 dev->ctl_invert = ctrl->val;
1033 saa_writeb(SAA7134_DEC_LUMA_CONTRAST,
1034 dev->ctl_invert ? -dev->ctl_contrast : dev->ctl_contrast);
1035 saa_writeb(SAA7134_DEC_CHROMA_SATURATION,
1036 dev->ctl_invert ? -dev->ctl_saturation : dev->ctl_saturation);
1037 break;
1038 case V4L2_CID_HFLIP:
1039 dev->ctl_mirror = ctrl->val;
1040 restart_overlay = 1;
1041 break;
1042 case V4L2_CID_PRIVATE_Y_EVEN:
1043 dev->ctl_y_even = ctrl->val;
1044 restart_overlay = 1;
1045 break;
1046 case V4L2_CID_PRIVATE_Y_ODD:
1047 dev->ctl_y_odd = ctrl->val;
1048 restart_overlay = 1;
1049 break;
1050 case V4L2_CID_PRIVATE_AUTOMUTE:
1051 {
1052 struct v4l2_priv_tun_config tda9887_cfg;
1053
1054 tda9887_cfg.tuner = TUNER_TDA9887;
1055 tda9887_cfg.priv = &dev->tda9887_conf;
1056
1057 dev->ctl_automute = ctrl->val;
1058 if (dev->tda9887_conf) {
1059 if (dev->ctl_automute)
1060 dev->tda9887_conf |= TDA9887_AUTOMUTE;
1061 else
1062 dev->tda9887_conf &= ~TDA9887_AUTOMUTE;
1063
1064 saa_call_all(dev, tuner, s_config, &tda9887_cfg);
1065 }
1066 break;
1067 }
1068 default:
1069 return -EINVAL;
1070 }
1071 if (restart_overlay && res_locked(dev, RESOURCE_OVERLAY)) {
1072 spin_lock_irqsave(&dev->slock, flags);
1073 stop_preview(dev);
1074 start_preview(dev);
1075 spin_unlock_irqrestore(&dev->slock, flags);
1076 }
1077 return 0;
1078 }
1079
1080 /* ------------------------------------------------------------------ */
1081
1082 static struct videobuf_queue *saa7134_queue(struct file *file)
1083 {
1084 struct video_device *vdev = video_devdata(file);
1085 struct saa7134_dev *dev = video_drvdata(file);
1086 struct saa7134_fh *fh = file->private_data;
1087 struct videobuf_queue *q = NULL;
1088
1089 switch (vdev->vfl_type) {
1090 case VFL_TYPE_GRABBER:
1091 q = fh->is_empress ? &dev->empress_tsq : &dev->cap;
1092 break;
1093 case VFL_TYPE_VBI:
1094 q = &dev->vbi;
1095 break;
1096 default:
1097 BUG();
1098 }
1099 return q;
1100 }
1101
1102 static int saa7134_resource(struct file *file)
1103 {
1104 struct video_device *vdev = video_devdata(file);
1105 struct saa7134_fh *fh = file->private_data;
1106
1107 if (vdev->vfl_type == VFL_TYPE_GRABBER)
1108 return fh->is_empress ? RESOURCE_EMPRESS : RESOURCE_VIDEO;
1109
1110 if (vdev->vfl_type == VFL_TYPE_VBI)
1111 return RESOURCE_VBI;
1112
1113 BUG();
1114 return 0;
1115 }
1116
1117 static int video_open(struct file *file)
1118 {
1119 struct video_device *vdev = video_devdata(file);
1120 struct saa7134_dev *dev = video_drvdata(file);
1121 struct saa7134_fh *fh;
1122
1123 /* allocate + initialize per filehandle data */
1124 fh = kzalloc(sizeof(*fh),GFP_KERNEL);
1125 if (NULL == fh)
1126 return -ENOMEM;
1127
1128 v4l2_fh_init(&fh->fh, vdev);
1129 file->private_data = fh;
1130
1131 if (vdev->vfl_type == VFL_TYPE_RADIO) {
1132 /* switch to radio mode */
1133 saa7134_tvaudio_setinput(dev,&card(dev).radio);
1134 saa_call_all(dev, tuner, s_radio);
1135 } else {
1136 /* switch to video/vbi mode */
1137 video_mux(dev,dev->ctl_input);
1138 }
1139 v4l2_fh_add(&fh->fh);
1140
1141 return 0;
1142 }
1143
1144 static ssize_t
1145 video_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
1146 {
1147 struct video_device *vdev = video_devdata(file);
1148 struct saa7134_dev *dev = video_drvdata(file);
1149 struct saa7134_fh *fh = file->private_data;
1150
1151 switch (vdev->vfl_type) {
1152 case VFL_TYPE_GRABBER:
1153 if (res_locked(dev, RESOURCE_VIDEO))
1154 return -EBUSY;
1155 return videobuf_read_one(saa7134_queue(file),
1156 data, count, ppos,
1157 file->f_flags & O_NONBLOCK);
1158 case VFL_TYPE_VBI:
1159 if (!res_get(dev, fh, RESOURCE_VBI))
1160 return -EBUSY;
1161 return videobuf_read_stream(saa7134_queue(file),
1162 data, count, ppos, 1,
1163 file->f_flags & O_NONBLOCK);
1164 break;
1165 default:
1166 BUG();
1167 return 0;
1168 }
1169 }
1170
1171 static unsigned int
1172 video_poll(struct file *file, struct poll_table_struct *wait)
1173 {
1174 unsigned long req_events = poll_requested_events(wait);
1175 struct video_device *vdev = video_devdata(file);
1176 struct saa7134_dev *dev = video_drvdata(file);
1177 struct saa7134_fh *fh = file->private_data;
1178 struct videobuf_buffer *buf = NULL;
1179 unsigned int rc = 0;
1180
1181 if (v4l2_event_pending(&fh->fh))
1182 rc = POLLPRI;
1183 else if (req_events & POLLPRI)
1184 poll_wait(file, &fh->fh.wait, wait);
1185
1186 if (vdev->vfl_type == VFL_TYPE_VBI)
1187 return rc | videobuf_poll_stream(file, &dev->vbi, wait);
1188
1189 if (res_check(fh, RESOURCE_VIDEO)) {
1190 mutex_lock(&dev->cap.vb_lock);
1191 if (!list_empty(&dev->cap.stream))
1192 buf = list_entry(dev->cap.stream.next, struct videobuf_buffer, stream);
1193 } else {
1194 mutex_lock(&dev->cap.vb_lock);
1195 if (UNSET == dev->cap.read_off) {
1196 /* need to capture a new frame */
1197 if (res_locked(dev, RESOURCE_VIDEO))
1198 goto err;
1199 if (0 != dev->cap.ops->buf_prepare(&dev->cap,
1200 dev->cap.read_buf, dev->cap.field))
1201 goto err;
1202 dev->cap.ops->buf_queue(&dev->cap, dev->cap.read_buf);
1203 dev->cap.read_off = 0;
1204 }
1205 buf = dev->cap.read_buf;
1206 }
1207
1208 if (!buf)
1209 goto err;
1210
1211 poll_wait(file, &buf->done, wait);
1212 if (buf->state == VIDEOBUF_DONE || buf->state == VIDEOBUF_ERROR)
1213 rc |= POLLIN | POLLRDNORM;
1214 mutex_unlock(&dev->cap.vb_lock);
1215 return rc;
1216
1217 err:
1218 mutex_unlock(&dev->cap.vb_lock);
1219 return rc | POLLERR;
1220 }
1221
1222 static int video_release(struct file *file)
1223 {
1224 struct video_device *vdev = video_devdata(file);
1225 struct saa7134_dev *dev = video_drvdata(file);
1226 struct saa7134_fh *fh = file->private_data;
1227 struct saa6588_command cmd;
1228 unsigned long flags;
1229
1230 saa7134_tvaudio_close(dev);
1231
1232 /* turn off overlay */
1233 if (res_check(fh, RESOURCE_OVERLAY)) {
1234 spin_lock_irqsave(&dev->slock,flags);
1235 stop_preview(dev);
1236 spin_unlock_irqrestore(&dev->slock,flags);
1237 res_free(dev, fh, RESOURCE_OVERLAY);
1238 }
1239
1240 /* stop video capture */
1241 if (res_check(fh, RESOURCE_VIDEO)) {
1242 pm_qos_remove_request(&dev->qos_request);
1243 videobuf_streamoff(&dev->cap);
1244 res_free(dev, fh, RESOURCE_VIDEO);
1245 videobuf_mmap_free(&dev->cap);
1246 }
1247 if (dev->cap.read_buf) {
1248 buffer_release(&dev->cap, dev->cap.read_buf);
1249 kfree(dev->cap.read_buf);
1250 }
1251
1252 /* stop vbi capture */
1253 if (res_check(fh, RESOURCE_VBI)) {
1254 videobuf_stop(&dev->vbi);
1255 res_free(dev, fh, RESOURCE_VBI);
1256 videobuf_mmap_free(&dev->vbi);
1257 }
1258
1259 /* ts-capture will not work in planar mode, so turn it off Hac: 04.05*/
1260 saa_andorb(SAA7134_OFMT_VIDEO_A, 0x1f, 0);
1261 saa_andorb(SAA7134_OFMT_VIDEO_B, 0x1f, 0);
1262 saa_andorb(SAA7134_OFMT_DATA_A, 0x1f, 0);
1263 saa_andorb(SAA7134_OFMT_DATA_B, 0x1f, 0);
1264
1265 saa_call_all(dev, core, s_power, 0);
1266 if (vdev->vfl_type == VFL_TYPE_RADIO)
1267 saa_call_all(dev, core, ioctl, SAA6588_CMD_CLOSE, &cmd);
1268
1269 v4l2_fh_del(&fh->fh);
1270 v4l2_fh_exit(&fh->fh);
1271 file->private_data = NULL;
1272 kfree(fh);
1273 return 0;
1274 }
1275
1276 static int video_mmap(struct file *file, struct vm_area_struct * vma)
1277 {
1278 return videobuf_mmap_mapper(saa7134_queue(file), vma);
1279 }
1280
1281 static ssize_t radio_read(struct file *file, char __user *data,
1282 size_t count, loff_t *ppos)
1283 {
1284 struct saa7134_dev *dev = video_drvdata(file);
1285 struct saa6588_command cmd;
1286
1287 cmd.block_count = count/3;
1288 cmd.buffer = data;
1289 cmd.instance = file;
1290 cmd.result = -ENODEV;
1291
1292 saa_call_all(dev, core, ioctl, SAA6588_CMD_READ, &cmd);
1293
1294 return cmd.result;
1295 }
1296
1297 static unsigned int radio_poll(struct file *file, poll_table *wait)
1298 {
1299 struct saa7134_dev *dev = video_drvdata(file);
1300 struct saa6588_command cmd;
1301 unsigned int rc = v4l2_ctrl_poll(file, wait);
1302
1303 cmd.instance = file;
1304 cmd.event_list = wait;
1305 cmd.result = 0;
1306 saa_call_all(dev, core, ioctl, SAA6588_CMD_POLL, &cmd);
1307
1308 return rc | cmd.result;
1309 }
1310
1311 /* ------------------------------------------------------------------ */
1312
1313 static int saa7134_try_get_set_fmt_vbi_cap(struct file *file, void *priv,
1314 struct v4l2_format *f)
1315 {
1316 struct saa7134_dev *dev = video_drvdata(file);
1317 struct saa7134_tvnorm *norm = dev->tvnorm;
1318
1319 memset(&f->fmt.vbi.reserved, 0, sizeof(f->fmt.vbi.reserved));
1320 f->fmt.vbi.sampling_rate = 6750000 * 4;
1321 f->fmt.vbi.samples_per_line = 2048 /* VBI_LINE_LENGTH */;
1322 f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
1323 f->fmt.vbi.offset = 64 * 4;
1324 f->fmt.vbi.start[0] = norm->vbi_v_start_0;
1325 f->fmt.vbi.count[0] = norm->vbi_v_stop_0 - norm->vbi_v_start_0 +1;
1326 f->fmt.vbi.start[1] = norm->vbi_v_start_1;
1327 f->fmt.vbi.count[1] = f->fmt.vbi.count[0];
1328 f->fmt.vbi.flags = 0; /* VBI_UNSYNC VBI_INTERLACED */
1329
1330 return 0;
1331 }
1332
1333 static int saa7134_g_fmt_vid_cap(struct file *file, void *priv,
1334 struct v4l2_format *f)
1335 {
1336 struct saa7134_dev *dev = video_drvdata(file);
1337
1338 f->fmt.pix.width = dev->width;
1339 f->fmt.pix.height = dev->height;
1340 f->fmt.pix.field = dev->cap.field;
1341 f->fmt.pix.pixelformat = dev->fmt->fourcc;
1342 f->fmt.pix.bytesperline =
1343 (f->fmt.pix.width * dev->fmt->depth) >> 3;
1344 f->fmt.pix.sizeimage =
1345 f->fmt.pix.height * f->fmt.pix.bytesperline;
1346 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
1347 f->fmt.pix.priv = 0;
1348 return 0;
1349 }
1350
1351 static int saa7134_g_fmt_vid_overlay(struct file *file, void *priv,
1352 struct v4l2_format *f)
1353 {
1354 struct saa7134_dev *dev = video_drvdata(file);
1355 struct v4l2_clip __user *clips = f->fmt.win.clips;
1356 u32 clipcount = f->fmt.win.clipcount;
1357 int err = 0;
1358 int i;
1359
1360 if (saa7134_no_overlay > 0) {
1361 printk(KERN_ERR "V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n");
1362 return -EINVAL;
1363 }
1364 mutex_lock(&dev->lock);
1365 f->fmt.win = dev->win;
1366 f->fmt.win.clips = clips;
1367 if (clips == NULL)
1368 clipcount = 0;
1369 if (dev->nclips < clipcount)
1370 clipcount = dev->nclips;
1371 f->fmt.win.clipcount = clipcount;
1372
1373 for (i = 0; !err && i < clipcount; i++) {
1374 if (copy_to_user(&f->fmt.win.clips[i].c, &dev->clips[i].c,
1375 sizeof(struct v4l2_rect)))
1376 err = -EFAULT;
1377 }
1378 mutex_unlock(&dev->lock);
1379
1380 return err;
1381 }
1382
1383 static int saa7134_try_fmt_vid_cap(struct file *file, void *priv,
1384 struct v4l2_format *f)
1385 {
1386 struct saa7134_dev *dev = video_drvdata(file);
1387 struct saa7134_format *fmt;
1388 enum v4l2_field field;
1389 unsigned int maxw, maxh;
1390
1391 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
1392 if (NULL == fmt)
1393 return -EINVAL;
1394
1395 field = f->fmt.pix.field;
1396 maxw = min(dev->crop_current.width*4, dev->crop_bounds.width);
1397 maxh = min(dev->crop_current.height*4, dev->crop_bounds.height);
1398
1399 if (V4L2_FIELD_ANY == field) {
1400 field = (f->fmt.pix.height > maxh/2)
1401 ? V4L2_FIELD_INTERLACED
1402 : V4L2_FIELD_BOTTOM;
1403 }
1404 switch (field) {
1405 case V4L2_FIELD_TOP:
1406 case V4L2_FIELD_BOTTOM:
1407 maxh = maxh / 2;
1408 break;
1409 default:
1410 field = V4L2_FIELD_INTERLACED;
1411 break;
1412 }
1413
1414 f->fmt.pix.field = field;
1415 if (f->fmt.pix.width < 48)
1416 f->fmt.pix.width = 48;
1417 if (f->fmt.pix.height < 32)
1418 f->fmt.pix.height = 32;
1419 if (f->fmt.pix.width > maxw)
1420 f->fmt.pix.width = maxw;
1421 if (f->fmt.pix.height > maxh)
1422 f->fmt.pix.height = maxh;
1423 f->fmt.pix.width &= ~0x03;
1424 f->fmt.pix.bytesperline =
1425 (f->fmt.pix.width * fmt->depth) >> 3;
1426 f->fmt.pix.sizeimage =
1427 f->fmt.pix.height * f->fmt.pix.bytesperline;
1428 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
1429 f->fmt.pix.priv = 0;
1430
1431 return 0;
1432 }
1433
1434 static int saa7134_try_fmt_vid_overlay(struct file *file, void *priv,
1435 struct v4l2_format *f)
1436 {
1437 struct saa7134_dev *dev = video_drvdata(file);
1438
1439 if (saa7134_no_overlay > 0) {
1440 printk(KERN_ERR "V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n");
1441 return -EINVAL;
1442 }
1443
1444 if (f->fmt.win.clips == NULL)
1445 f->fmt.win.clipcount = 0;
1446 return verify_preview(dev, &f->fmt.win, true);
1447 }
1448
1449 static int saa7134_s_fmt_vid_cap(struct file *file, void *priv,
1450 struct v4l2_format *f)
1451 {
1452 struct saa7134_dev *dev = video_drvdata(file);
1453 int err;
1454
1455 err = saa7134_try_fmt_vid_cap(file, priv, f);
1456 if (0 != err)
1457 return err;
1458
1459 dev->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
1460 dev->width = f->fmt.pix.width;
1461 dev->height = f->fmt.pix.height;
1462 dev->cap.field = f->fmt.pix.field;
1463 return 0;
1464 }
1465
1466 static int saa7134_s_fmt_vid_overlay(struct file *file, void *priv,
1467 struct v4l2_format *f)
1468 {
1469 struct saa7134_dev *dev = video_drvdata(file);
1470 int err;
1471 unsigned long flags;
1472
1473 if (saa7134_no_overlay > 0) {
1474 printk(KERN_ERR "V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n");
1475 return -EINVAL;
1476 }
1477 if (f->fmt.win.clips == NULL)
1478 f->fmt.win.clipcount = 0;
1479 err = verify_preview(dev, &f->fmt.win, true);
1480 if (0 != err)
1481 return err;
1482
1483 mutex_lock(&dev->lock);
1484
1485 dev->win = f->fmt.win;
1486 dev->nclips = f->fmt.win.clipcount;
1487
1488 if (copy_from_user(dev->clips, f->fmt.win.clips,
1489 sizeof(struct v4l2_clip) * dev->nclips)) {
1490 mutex_unlock(&dev->lock);
1491 return -EFAULT;
1492 }
1493
1494 if (res_check(priv, RESOURCE_OVERLAY)) {
1495 spin_lock_irqsave(&dev->slock, flags);
1496 stop_preview(dev);
1497 start_preview(dev);
1498 spin_unlock_irqrestore(&dev->slock, flags);
1499 }
1500
1501 mutex_unlock(&dev->lock);
1502 return 0;
1503 }
1504
1505 int saa7134_enum_input(struct file *file, void *priv, struct v4l2_input *i)
1506 {
1507 struct saa7134_dev *dev = video_drvdata(file);
1508 unsigned int n;
1509
1510 n = i->index;
1511 if (n >= SAA7134_INPUT_MAX)
1512 return -EINVAL;
1513 if (NULL == card_in(dev, i->index).name)
1514 return -EINVAL;
1515 i->index = n;
1516 i->type = V4L2_INPUT_TYPE_CAMERA;
1517 strcpy(i->name, card_in(dev, n).name);
1518 if (card_in(dev, n).tv)
1519 i->type = V4L2_INPUT_TYPE_TUNER;
1520 if (n == dev->ctl_input) {
1521 int v1 = saa_readb(SAA7134_STATUS_VIDEO1);
1522 int v2 = saa_readb(SAA7134_STATUS_VIDEO2);
1523
1524 if (0 != (v1 & 0x40))
1525 i->status |= V4L2_IN_ST_NO_H_LOCK;
1526 if (0 != (v2 & 0x40))
1527 i->status |= V4L2_IN_ST_NO_SYNC;
1528 if (0 != (v2 & 0x0e))
1529 i->status |= V4L2_IN_ST_MACROVISION;
1530 }
1531 i->std = SAA7134_NORMS;
1532 return 0;
1533 }
1534 EXPORT_SYMBOL_GPL(saa7134_enum_input);
1535
1536 int saa7134_g_input(struct file *file, void *priv, unsigned int *i)
1537 {
1538 struct saa7134_dev *dev = video_drvdata(file);
1539
1540 *i = dev->ctl_input;
1541 return 0;
1542 }
1543 EXPORT_SYMBOL_GPL(saa7134_g_input);
1544
1545 int saa7134_s_input(struct file *file, void *priv, unsigned int i)
1546 {
1547 struct saa7134_dev *dev = video_drvdata(file);
1548
1549 if (i >= SAA7134_INPUT_MAX)
1550 return -EINVAL;
1551 if (NULL == card_in(dev, i).name)
1552 return -EINVAL;
1553 mutex_lock(&dev->lock);
1554 video_mux(dev, i);
1555 mutex_unlock(&dev->lock);
1556 return 0;
1557 }
1558 EXPORT_SYMBOL_GPL(saa7134_s_input);
1559
1560 int saa7134_querycap(struct file *file, void *priv,
1561 struct v4l2_capability *cap)
1562 {
1563 struct saa7134_dev *dev = video_drvdata(file);
1564 struct video_device *vdev = video_devdata(file);
1565 struct saa7134_fh *fh = priv;
1566 u32 radio_caps, video_caps, vbi_caps;
1567
1568 unsigned int tuner_type = dev->tuner_type;
1569
1570 strcpy(cap->driver, "saa7134");
1571 strlcpy(cap->card, saa7134_boards[dev->board].name,
1572 sizeof(cap->card));
1573 sprintf(cap->bus_info, "PCI:%s", pci_name(dev->pci));
1574
1575 cap->device_caps = V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
1576 if ((tuner_type != TUNER_ABSENT) && (tuner_type != UNSET))
1577 cap->device_caps |= V4L2_CAP_TUNER;
1578
1579 radio_caps = V4L2_CAP_RADIO;
1580 if (dev->has_rds)
1581 radio_caps |= V4L2_CAP_RDS_CAPTURE;
1582
1583 video_caps = V4L2_CAP_VIDEO_CAPTURE;
1584 if (saa7134_no_overlay <= 0 && !fh->is_empress)
1585 video_caps |= V4L2_CAP_VIDEO_OVERLAY;
1586
1587 vbi_caps = V4L2_CAP_VBI_CAPTURE;
1588
1589 switch (vdev->vfl_type) {
1590 case VFL_TYPE_RADIO:
1591 cap->device_caps |= radio_caps;
1592 break;
1593 case VFL_TYPE_GRABBER:
1594 cap->device_caps |= video_caps;
1595 break;
1596 case VFL_TYPE_VBI:
1597 cap->device_caps |= vbi_caps;
1598 break;
1599 }
1600 cap->capabilities = radio_caps | video_caps | vbi_caps |
1601 cap->device_caps | V4L2_CAP_DEVICE_CAPS;
1602 if (vdev->vfl_type == VFL_TYPE_RADIO) {
1603 cap->device_caps &= ~V4L2_CAP_STREAMING;
1604 if (!dev->has_rds)
1605 cap->device_caps &= ~V4L2_CAP_READWRITE;
1606 }
1607
1608 return 0;
1609 }
1610 EXPORT_SYMBOL_GPL(saa7134_querycap);
1611
1612 int saa7134_s_std(struct file *file, void *priv, v4l2_std_id id)
1613 {
1614 struct saa7134_dev *dev = video_drvdata(file);
1615 struct saa7134_fh *fh = priv;
1616 unsigned long flags;
1617 unsigned int i;
1618 v4l2_std_id fixup;
1619
1620 if (fh->is_empress && res_locked(dev, RESOURCE_OVERLAY)) {
1621 /* Don't change the std from the mpeg device
1622 if overlay is active. */
1623 return -EBUSY;
1624 }
1625
1626 for (i = 0; i < TVNORMS; i++)
1627 if (id == tvnorms[i].id)
1628 break;
1629
1630 if (i == TVNORMS)
1631 for (i = 0; i < TVNORMS; i++)
1632 if (id & tvnorms[i].id)
1633 break;
1634 if (i == TVNORMS)
1635 return -EINVAL;
1636
1637 if ((id & V4L2_STD_SECAM) && (secam[0] != '-')) {
1638 if (secam[0] == 'L' || secam[0] == 'l') {
1639 if (secam[1] == 'C' || secam[1] == 'c')
1640 fixup = V4L2_STD_SECAM_LC;
1641 else
1642 fixup = V4L2_STD_SECAM_L;
1643 } else {
1644 if (secam[0] == 'D' || secam[0] == 'd')
1645 fixup = V4L2_STD_SECAM_DK;
1646 else
1647 fixup = V4L2_STD_SECAM;
1648 }
1649 for (i = 0; i < TVNORMS; i++) {
1650 if (fixup == tvnorms[i].id)
1651 break;
1652 }
1653 if (i == TVNORMS)
1654 return -EINVAL;
1655 }
1656
1657 id = tvnorms[i].id;
1658
1659 mutex_lock(&dev->lock);
1660 if (!fh->is_empress && res_check(fh, RESOURCE_OVERLAY)) {
1661 spin_lock_irqsave(&dev->slock, flags);
1662 stop_preview(dev);
1663 spin_unlock_irqrestore(&dev->slock, flags);
1664
1665 set_tvnorm(dev, &tvnorms[i]);
1666
1667 spin_lock_irqsave(&dev->slock, flags);
1668 start_preview(dev);
1669 spin_unlock_irqrestore(&dev->slock, flags);
1670 } else
1671 set_tvnorm(dev, &tvnorms[i]);
1672
1673 saa7134_tvaudio_do_scan(dev);
1674 mutex_unlock(&dev->lock);
1675 return 0;
1676 }
1677 EXPORT_SYMBOL_GPL(saa7134_s_std);
1678
1679 int saa7134_g_std(struct file *file, void *priv, v4l2_std_id *id)
1680 {
1681 struct saa7134_dev *dev = video_drvdata(file);
1682
1683 *id = dev->tvnorm->id;
1684 return 0;
1685 }
1686 EXPORT_SYMBOL_GPL(saa7134_g_std);
1687
1688 static int saa7134_cropcap(struct file *file, void *priv,
1689 struct v4l2_cropcap *cap)
1690 {
1691 struct saa7134_dev *dev = video_drvdata(file);
1692
1693 if (cap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
1694 cap->type != V4L2_BUF_TYPE_VIDEO_OVERLAY)
1695 return -EINVAL;
1696 cap->bounds = dev->crop_bounds;
1697 cap->defrect = dev->crop_defrect;
1698 cap->pixelaspect.numerator = 1;
1699 cap->pixelaspect.denominator = 1;
1700 if (dev->tvnorm->id & V4L2_STD_525_60) {
1701 cap->pixelaspect.numerator = 11;
1702 cap->pixelaspect.denominator = 10;
1703 }
1704 if (dev->tvnorm->id & V4L2_STD_625_50) {
1705 cap->pixelaspect.numerator = 54;
1706 cap->pixelaspect.denominator = 59;
1707 }
1708 return 0;
1709 }
1710
1711 static int saa7134_g_crop(struct file *file, void *f, struct v4l2_crop *crop)
1712 {
1713 struct saa7134_dev *dev = video_drvdata(file);
1714
1715 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
1716 crop->type != V4L2_BUF_TYPE_VIDEO_OVERLAY)
1717 return -EINVAL;
1718 crop->c = dev->crop_current;
1719 return 0;
1720 }
1721
1722 static int saa7134_s_crop(struct file *file, void *f, const struct v4l2_crop *crop)
1723 {
1724 struct saa7134_dev *dev = video_drvdata(file);
1725 struct v4l2_rect *b = &dev->crop_bounds;
1726 struct v4l2_rect *c = &dev->crop_current;
1727
1728 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
1729 crop->type != V4L2_BUF_TYPE_VIDEO_OVERLAY)
1730 return -EINVAL;
1731 if (crop->c.height < 0)
1732 return -EINVAL;
1733 if (crop->c.width < 0)
1734 return -EINVAL;
1735
1736 if (res_locked(dev, RESOURCE_OVERLAY))
1737 return -EBUSY;
1738 if (res_locked(dev, RESOURCE_VIDEO))
1739 return -EBUSY;
1740
1741 *c = crop->c;
1742 if (c->top < b->top)
1743 c->top = b->top;
1744 if (c->top > b->top + b->height)
1745 c->top = b->top + b->height;
1746 if (c->height > b->top - c->top + b->height)
1747 c->height = b->top - c->top + b->height;
1748
1749 if (c->left < b->left)
1750 c->left = b->left;
1751 if (c->left > b->left + b->width)
1752 c->left = b->left + b->width;
1753 if (c->width > b->left - c->left + b->width)
1754 c->width = b->left - c->left + b->width;
1755 return 0;
1756 }
1757
1758 int saa7134_g_tuner(struct file *file, void *priv,
1759 struct v4l2_tuner *t)
1760 {
1761 struct saa7134_dev *dev = video_drvdata(file);
1762 int n;
1763
1764 if (0 != t->index)
1765 return -EINVAL;
1766 memset(t, 0, sizeof(*t));
1767 for (n = 0; n < SAA7134_INPUT_MAX; n++) {
1768 if (card_in(dev, n).tv)
1769 break;
1770 }
1771 if (n == SAA7134_INPUT_MAX)
1772 return -EINVAL;
1773 if (NULL != card_in(dev, n).name) {
1774 strcpy(t->name, "Television");
1775 t->type = V4L2_TUNER_ANALOG_TV;
1776 saa_call_all(dev, tuner, g_tuner, t);
1777 t->capability = V4L2_TUNER_CAP_NORM |
1778 V4L2_TUNER_CAP_STEREO |
1779 V4L2_TUNER_CAP_LANG1 |
1780 V4L2_TUNER_CAP_LANG2;
1781 t->rxsubchans = saa7134_tvaudio_getstereo(dev);
1782 t->audmode = saa7134_tvaudio_rx2mode(t->rxsubchans);
1783 }
1784 if (0 != (saa_readb(SAA7134_STATUS_VIDEO1) & 0x03))
1785 t->signal = 0xffff;
1786 return 0;
1787 }
1788 EXPORT_SYMBOL_GPL(saa7134_g_tuner);
1789
1790 int saa7134_s_tuner(struct file *file, void *priv,
1791 const struct v4l2_tuner *t)
1792 {
1793 struct saa7134_dev *dev = video_drvdata(file);
1794 int rx, mode;
1795
1796 if (0 != t->index)
1797 return -EINVAL;
1798
1799 mode = dev->thread.mode;
1800 if (UNSET == mode) {
1801 rx = saa7134_tvaudio_getstereo(dev);
1802 mode = saa7134_tvaudio_rx2mode(rx);
1803 }
1804 if (mode != t->audmode)
1805 dev->thread.mode = t->audmode;
1806
1807 return 0;
1808 }
1809 EXPORT_SYMBOL_GPL(saa7134_s_tuner);
1810
1811 int saa7134_g_frequency(struct file *file, void *priv,
1812 struct v4l2_frequency *f)
1813 {
1814 struct saa7134_dev *dev = video_drvdata(file);
1815
1816 if (0 != f->tuner)
1817 return -EINVAL;
1818
1819 saa_call_all(dev, tuner, g_frequency, f);
1820
1821 return 0;
1822 }
1823 EXPORT_SYMBOL_GPL(saa7134_g_frequency);
1824
1825 int saa7134_s_frequency(struct file *file, void *priv,
1826 const struct v4l2_frequency *f)
1827 {
1828 struct saa7134_dev *dev = video_drvdata(file);
1829
1830 if (0 != f->tuner)
1831 return -EINVAL;
1832 mutex_lock(&dev->lock);
1833
1834 saa_call_all(dev, tuner, s_frequency, f);
1835
1836 saa7134_tvaudio_do_scan(dev);
1837 mutex_unlock(&dev->lock);
1838 return 0;
1839 }
1840 EXPORT_SYMBOL_GPL(saa7134_s_frequency);
1841
1842 static int saa7134_enum_fmt_vid_cap(struct file *file, void *priv,
1843 struct v4l2_fmtdesc *f)
1844 {
1845 if (f->index >= FORMATS)
1846 return -EINVAL;
1847
1848 strlcpy(f->description, formats[f->index].name,
1849 sizeof(f->description));
1850
1851 f->pixelformat = formats[f->index].fourcc;
1852
1853 return 0;
1854 }
1855
1856 static int saa7134_enum_fmt_vid_overlay(struct file *file, void *priv,
1857 struct v4l2_fmtdesc *f)
1858 {
1859 if (saa7134_no_overlay > 0) {
1860 printk(KERN_ERR "V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n");
1861 return -EINVAL;
1862 }
1863
1864 if ((f->index >= FORMATS) || formats[f->index].planar)
1865 return -EINVAL;
1866
1867 strlcpy(f->description, formats[f->index].name,
1868 sizeof(f->description));
1869
1870 f->pixelformat = formats[f->index].fourcc;
1871
1872 return 0;
1873 }
1874
1875 static int saa7134_g_fbuf(struct file *file, void *f,
1876 struct v4l2_framebuffer *fb)
1877 {
1878 struct saa7134_dev *dev = video_drvdata(file);
1879
1880 *fb = dev->ovbuf;
1881 fb->capability = V4L2_FBUF_CAP_LIST_CLIPPING;
1882
1883 return 0;
1884 }
1885
1886 static int saa7134_s_fbuf(struct file *file, void *f,
1887 const struct v4l2_framebuffer *fb)
1888 {
1889 struct saa7134_dev *dev = video_drvdata(file);
1890 struct saa7134_format *fmt;
1891
1892 if (!capable(CAP_SYS_ADMIN) &&
1893 !capable(CAP_SYS_RAWIO))
1894 return -EPERM;
1895
1896 /* check args */
1897 fmt = format_by_fourcc(fb->fmt.pixelformat);
1898 if (NULL == fmt)
1899 return -EINVAL;
1900
1901 /* ok, accept it */
1902 dev->ovbuf = *fb;
1903 dev->ovfmt = fmt;
1904 if (0 == dev->ovbuf.fmt.bytesperline)
1905 dev->ovbuf.fmt.bytesperline =
1906 dev->ovbuf.fmt.width*fmt->depth/8;
1907 return 0;
1908 }
1909
1910 static int saa7134_overlay(struct file *file, void *priv, unsigned int on)
1911 {
1912 struct saa7134_dev *dev = video_drvdata(file);
1913 unsigned long flags;
1914
1915 if (on) {
1916 if (saa7134_no_overlay > 0) {
1917 dprintk("no_overlay\n");
1918 return -EINVAL;
1919 }
1920
1921 if (!res_get(dev, priv, RESOURCE_OVERLAY))
1922 return -EBUSY;
1923 spin_lock_irqsave(&dev->slock, flags);
1924 start_preview(dev);
1925 spin_unlock_irqrestore(&dev->slock, flags);
1926 }
1927 if (!on) {
1928 if (!res_check(priv, RESOURCE_OVERLAY))
1929 return -EINVAL;
1930 spin_lock_irqsave(&dev->slock, flags);
1931 stop_preview(dev);
1932 spin_unlock_irqrestore(&dev->slock, flags);
1933 res_free(dev, priv, RESOURCE_OVERLAY);
1934 }
1935 return 0;
1936 }
1937
1938 int saa7134_reqbufs(struct file *file, void *priv,
1939 struct v4l2_requestbuffers *p)
1940 {
1941 return videobuf_reqbufs(saa7134_queue(file), p);
1942 }
1943 EXPORT_SYMBOL_GPL(saa7134_reqbufs);
1944
1945 int saa7134_querybuf(struct file *file, void *priv,
1946 struct v4l2_buffer *b)
1947 {
1948 return videobuf_querybuf(saa7134_queue(file), b);
1949 }
1950 EXPORT_SYMBOL_GPL(saa7134_querybuf);
1951
1952 int saa7134_qbuf(struct file *file, void *priv, struct v4l2_buffer *b)
1953 {
1954 return videobuf_qbuf(saa7134_queue(file), b);
1955 }
1956 EXPORT_SYMBOL_GPL(saa7134_qbuf);
1957
1958 int saa7134_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b)
1959 {
1960 return videobuf_dqbuf(saa7134_queue(file), b,
1961 file->f_flags & O_NONBLOCK);
1962 }
1963 EXPORT_SYMBOL_GPL(saa7134_dqbuf);
1964
1965 int saa7134_streamon(struct file *file, void *priv,
1966 enum v4l2_buf_type type)
1967 {
1968 struct saa7134_dev *dev = video_drvdata(file);
1969 int res = saa7134_resource(file);
1970
1971 if (!res_get(dev, priv, res))
1972 return -EBUSY;
1973
1974 /* The SAA7134 has a 1K FIFO; the datasheet suggests that when
1975 * configured conservatively, there's 22 usec of buffering for video.
1976 * We therefore request a DMA latency of 20 usec, giving us 2 usec of
1977 * margin in case the FIFO is configured differently to the datasheet.
1978 * Unfortunately, I lack register-level documentation to check the
1979 * Linux FIFO setup and confirm the perfect value.
1980 */
1981 if (res != RESOURCE_EMPRESS)
1982 pm_qos_add_request(&dev->qos_request,
1983 PM_QOS_CPU_DMA_LATENCY, 20);
1984
1985 return videobuf_streamon(saa7134_queue(file));
1986 }
1987 EXPORT_SYMBOL_GPL(saa7134_streamon);
1988
1989 int saa7134_streamoff(struct file *file, void *priv,
1990 enum v4l2_buf_type type)
1991 {
1992 struct saa7134_dev *dev = video_drvdata(file);
1993 int err;
1994 int res = saa7134_resource(file);
1995
1996 if (res != RESOURCE_EMPRESS)
1997 pm_qos_remove_request(&dev->qos_request);
1998
1999 err = videobuf_streamoff(saa7134_queue(file));
2000 if (err < 0)
2001 return err;
2002 res_free(dev, priv, res);
2003 return 0;
2004 }
2005 EXPORT_SYMBOL_GPL(saa7134_streamoff);
2006
2007 #ifdef CONFIG_VIDEO_ADV_DEBUG
2008 static int vidioc_g_register (struct file *file, void *priv,
2009 struct v4l2_dbg_register *reg)
2010 {
2011 struct saa7134_dev *dev = video_drvdata(file);
2012
2013 reg->val = saa_readb(reg->reg & 0xffffff);
2014 reg->size = 1;
2015 return 0;
2016 }
2017
2018 static int vidioc_s_register (struct file *file, void *priv,
2019 const struct v4l2_dbg_register *reg)
2020 {
2021 struct saa7134_dev *dev = video_drvdata(file);
2022
2023 saa_writeb(reg->reg & 0xffffff, reg->val);
2024 return 0;
2025 }
2026 #endif
2027
2028 static int radio_g_tuner(struct file *file, void *priv,
2029 struct v4l2_tuner *t)
2030 {
2031 struct saa7134_dev *dev = video_drvdata(file);
2032
2033 if (0 != t->index)
2034 return -EINVAL;
2035
2036 strcpy(t->name, "Radio");
2037
2038 saa_call_all(dev, tuner, g_tuner, t);
2039 t->audmode &= V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO;
2040 if (dev->input->amux == TV) {
2041 t->signal = 0xf800 - ((saa_readb(0x581) & 0x1f) << 11);
2042 t->rxsubchans = (saa_readb(0x529) & 0x08) ?
2043 V4L2_TUNER_SUB_STEREO : V4L2_TUNER_SUB_MONO;
2044 }
2045 return 0;
2046 }
2047 static int radio_s_tuner(struct file *file, void *priv,
2048 const struct v4l2_tuner *t)
2049 {
2050 struct saa7134_dev *dev = video_drvdata(file);
2051
2052 if (0 != t->index)
2053 return -EINVAL;
2054
2055 saa_call_all(dev, tuner, s_tuner, t);
2056 return 0;
2057 }
2058
2059 static const struct v4l2_file_operations video_fops =
2060 {
2061 .owner = THIS_MODULE,
2062 .open = video_open,
2063 .release = video_release,
2064 .read = video_read,
2065 .poll = video_poll,
2066 .mmap = video_mmap,
2067 .ioctl = video_ioctl2,
2068 };
2069
2070 static const struct v4l2_ioctl_ops video_ioctl_ops = {
2071 .vidioc_querycap = saa7134_querycap,
2072 .vidioc_enum_fmt_vid_cap = saa7134_enum_fmt_vid_cap,
2073 .vidioc_g_fmt_vid_cap = saa7134_g_fmt_vid_cap,
2074 .vidioc_try_fmt_vid_cap = saa7134_try_fmt_vid_cap,
2075 .vidioc_s_fmt_vid_cap = saa7134_s_fmt_vid_cap,
2076 .vidioc_enum_fmt_vid_overlay = saa7134_enum_fmt_vid_overlay,
2077 .vidioc_g_fmt_vid_overlay = saa7134_g_fmt_vid_overlay,
2078 .vidioc_try_fmt_vid_overlay = saa7134_try_fmt_vid_overlay,
2079 .vidioc_s_fmt_vid_overlay = saa7134_s_fmt_vid_overlay,
2080 .vidioc_g_fmt_vbi_cap = saa7134_try_get_set_fmt_vbi_cap,
2081 .vidioc_try_fmt_vbi_cap = saa7134_try_get_set_fmt_vbi_cap,
2082 .vidioc_s_fmt_vbi_cap = saa7134_try_get_set_fmt_vbi_cap,
2083 .vidioc_cropcap = saa7134_cropcap,
2084 .vidioc_reqbufs = saa7134_reqbufs,
2085 .vidioc_querybuf = saa7134_querybuf,
2086 .vidioc_qbuf = saa7134_qbuf,
2087 .vidioc_dqbuf = saa7134_dqbuf,
2088 .vidioc_s_std = saa7134_s_std,
2089 .vidioc_g_std = saa7134_g_std,
2090 .vidioc_enum_input = saa7134_enum_input,
2091 .vidioc_g_input = saa7134_g_input,
2092 .vidioc_s_input = saa7134_s_input,
2093 .vidioc_streamon = saa7134_streamon,
2094 .vidioc_streamoff = saa7134_streamoff,
2095 .vidioc_g_tuner = saa7134_g_tuner,
2096 .vidioc_s_tuner = saa7134_s_tuner,
2097 .vidioc_g_crop = saa7134_g_crop,
2098 .vidioc_s_crop = saa7134_s_crop,
2099 .vidioc_g_fbuf = saa7134_g_fbuf,
2100 .vidioc_s_fbuf = saa7134_s_fbuf,
2101 .vidioc_overlay = saa7134_overlay,
2102 .vidioc_g_frequency = saa7134_g_frequency,
2103 .vidioc_s_frequency = saa7134_s_frequency,
2104 #ifdef CONFIG_VIDEO_ADV_DEBUG
2105 .vidioc_g_register = vidioc_g_register,
2106 .vidioc_s_register = vidioc_s_register,
2107 #endif
2108 .vidioc_log_status = v4l2_ctrl_log_status,
2109 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
2110 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
2111 };
2112
2113 static const struct v4l2_file_operations radio_fops = {
2114 .owner = THIS_MODULE,
2115 .open = video_open,
2116 .read = radio_read,
2117 .release = video_release,
2118 .ioctl = video_ioctl2,
2119 .poll = radio_poll,
2120 };
2121
2122 static const struct v4l2_ioctl_ops radio_ioctl_ops = {
2123 .vidioc_querycap = saa7134_querycap,
2124 .vidioc_g_tuner = radio_g_tuner,
2125 .vidioc_s_tuner = radio_s_tuner,
2126 .vidioc_g_frequency = saa7134_g_frequency,
2127 .vidioc_s_frequency = saa7134_s_frequency,
2128 .vidioc_log_status = v4l2_ctrl_log_status,
2129 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
2130 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
2131 };
2132
2133 /* ----------------------------------------------------------- */
2134 /* exported stuff */
2135
2136 struct video_device saa7134_video_template = {
2137 .name = "saa7134-video",
2138 .fops = &video_fops,
2139 .ioctl_ops = &video_ioctl_ops,
2140 .tvnorms = SAA7134_NORMS,
2141 };
2142
2143 struct video_device saa7134_radio_template = {
2144 .name = "saa7134-radio",
2145 .fops = &radio_fops,
2146 .ioctl_ops = &radio_ioctl_ops,
2147 };
2148
2149 static const struct v4l2_ctrl_ops saa7134_ctrl_ops = {
2150 .s_ctrl = saa7134_s_ctrl,
2151 };
2152
2153 static const struct v4l2_ctrl_config saa7134_ctrl_invert = {
2154 .ops = &saa7134_ctrl_ops,
2155 .id = V4L2_CID_PRIVATE_INVERT,
2156 .name = "Invert",
2157 .type = V4L2_CTRL_TYPE_BOOLEAN,
2158 .min = 0,
2159 .max = 1,
2160 .step = 1,
2161 };
2162
2163 static const struct v4l2_ctrl_config saa7134_ctrl_y_odd = {
2164 .ops = &saa7134_ctrl_ops,
2165 .id = V4L2_CID_PRIVATE_Y_ODD,
2166 .name = "Y Offset Odd Field",
2167 .type = V4L2_CTRL_TYPE_INTEGER,
2168 .min = 0,
2169 .max = 128,
2170 .step = 1,
2171 };
2172
2173 static const struct v4l2_ctrl_config saa7134_ctrl_y_even = {
2174 .ops = &saa7134_ctrl_ops,
2175 .id = V4L2_CID_PRIVATE_Y_EVEN,
2176 .name = "Y Offset Even Field",
2177 .type = V4L2_CTRL_TYPE_INTEGER,
2178 .min = 0,
2179 .max = 128,
2180 .step = 1,
2181 };
2182
2183 static const struct v4l2_ctrl_config saa7134_ctrl_automute = {
2184 .ops = &saa7134_ctrl_ops,
2185 .id = V4L2_CID_PRIVATE_AUTOMUTE,
2186 .name = "Automute",
2187 .type = V4L2_CTRL_TYPE_BOOLEAN,
2188 .min = 0,
2189 .max = 1,
2190 .step = 1,
2191 .def = 1,
2192 };
2193
2194 int saa7134_video_init1(struct saa7134_dev *dev)
2195 {
2196 struct v4l2_ctrl_handler *hdl = &dev->ctrl_handler;
2197
2198 /* sanitycheck insmod options */
2199 if (gbuffers < 2 || gbuffers > VIDEO_MAX_FRAME)
2200 gbuffers = 2;
2201 if (gbufsize > gbufsize_max)
2202 gbufsize = gbufsize_max;
2203 gbufsize = (gbufsize + PAGE_SIZE - 1) & PAGE_MASK;
2204
2205 v4l2_ctrl_handler_init(hdl, 11);
2206 v4l2_ctrl_new_std(hdl, &saa7134_ctrl_ops,
2207 V4L2_CID_BRIGHTNESS, 0, 255, 1, 128);
2208 v4l2_ctrl_new_std(hdl, &saa7134_ctrl_ops,
2209 V4L2_CID_CONTRAST, 0, 127, 1, 68);
2210 v4l2_ctrl_new_std(hdl, &saa7134_ctrl_ops,
2211 V4L2_CID_SATURATION, 0, 127, 1, 64);
2212 v4l2_ctrl_new_std(hdl, &saa7134_ctrl_ops,
2213 V4L2_CID_HUE, -128, 127, 1, 0);
2214 v4l2_ctrl_new_std(hdl, &saa7134_ctrl_ops,
2215 V4L2_CID_HFLIP, 0, 1, 1, 0);
2216 v4l2_ctrl_new_std(hdl, &saa7134_ctrl_ops,
2217 V4L2_CID_AUDIO_MUTE, 0, 1, 1, 0);
2218 v4l2_ctrl_new_std(hdl, &saa7134_ctrl_ops,
2219 V4L2_CID_AUDIO_VOLUME, -15, 15, 1, 0);
2220 v4l2_ctrl_new_custom(hdl, &saa7134_ctrl_invert, NULL);
2221 v4l2_ctrl_new_custom(hdl, &saa7134_ctrl_y_odd, NULL);
2222 v4l2_ctrl_new_custom(hdl, &saa7134_ctrl_y_even, NULL);
2223 v4l2_ctrl_new_custom(hdl, &saa7134_ctrl_automute, NULL);
2224 if (hdl->error)
2225 return hdl->error;
2226 if (card_has_radio(dev)) {
2227 hdl = &dev->radio_ctrl_handler;
2228 v4l2_ctrl_handler_init(hdl, 2);
2229 v4l2_ctrl_add_handler(hdl, &dev->ctrl_handler,
2230 v4l2_ctrl_radio_filter);
2231 if (hdl->error)
2232 return hdl->error;
2233 }
2234 dev->ctl_mute = 1;
2235
2236 if (dev->tda9887_conf && saa7134_ctrl_automute.def)
2237 dev->tda9887_conf |= TDA9887_AUTOMUTE;
2238 dev->automute = 0;
2239
2240 INIT_LIST_HEAD(&dev->video_q.queue);
2241 init_timer(&dev->video_q.timeout);
2242 dev->video_q.timeout.function = saa7134_buffer_timeout;
2243 dev->video_q.timeout.data = (unsigned long)(&dev->video_q);
2244 dev->video_q.dev = dev;
2245 dev->fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24);
2246 dev->width = 720;
2247 dev->height = 576;
2248 dev->win.w.width = dev->width;
2249 dev->win.w.height = dev->height;
2250 dev->win.field = V4L2_FIELD_INTERLACED;
2251 dev->ovbuf.fmt.width = dev->width;
2252 dev->ovbuf.fmt.height = dev->height;
2253 dev->ovbuf.fmt.pixelformat = dev->fmt->fourcc;
2254 dev->ovbuf.fmt.colorspace = V4L2_COLORSPACE_SMPTE170M;
2255
2256 if (saa7134_boards[dev->board].video_out)
2257 saa7134_videoport_init(dev);
2258
2259 videobuf_queue_sg_init(&dev->cap, &video_qops,
2260 &dev->pci->dev, &dev->slock,
2261 V4L2_BUF_TYPE_VIDEO_CAPTURE,
2262 V4L2_FIELD_INTERLACED,
2263 sizeof(struct saa7134_buf),
2264 dev, NULL);
2265 videobuf_queue_sg_init(&dev->vbi, &saa7134_vbi_qops,
2266 &dev->pci->dev, &dev->slock,
2267 V4L2_BUF_TYPE_VBI_CAPTURE,
2268 V4L2_FIELD_SEQ_TB,
2269 sizeof(struct saa7134_buf),
2270 dev, NULL);
2271 saa7134_pgtable_alloc(dev->pci, &dev->pt_cap);
2272 saa7134_pgtable_alloc(dev->pci, &dev->pt_vbi);
2273
2274 return 0;
2275 }
2276
2277 void saa7134_video_fini(struct saa7134_dev *dev)
2278 {
2279 /* free stuff */
2280 saa7134_pgtable_free(dev->pci, &dev->pt_cap);
2281 saa7134_pgtable_free(dev->pci, &dev->pt_vbi);
2282 v4l2_ctrl_handler_free(&dev->ctrl_handler);
2283 if (card_has_radio(dev))
2284 v4l2_ctrl_handler_free(&dev->radio_ctrl_handler);
2285 }
2286
2287 int saa7134_videoport_init(struct saa7134_dev *dev)
2288 {
2289 /* enable video output */
2290 int vo = saa7134_boards[dev->board].video_out;
2291 int video_reg;
2292 unsigned int vid_port_opts = saa7134_boards[dev->board].vid_port_opts;
2293
2294 /* Configure videoport */
2295 saa_writeb(SAA7134_VIDEO_PORT_CTRL0, video_out[vo][0]);
2296 video_reg = video_out[vo][1];
2297 if (vid_port_opts & SET_T_CODE_POLARITY_NON_INVERTED)
2298 video_reg &= ~VP_T_CODE_P_INVERTED;
2299 saa_writeb(SAA7134_VIDEO_PORT_CTRL1, video_reg);
2300 saa_writeb(SAA7134_VIDEO_PORT_CTRL2, video_out[vo][2]);
2301 saa_writeb(SAA7134_VIDEO_PORT_CTRL4, video_out[vo][4]);
2302 video_reg = video_out[vo][5];
2303 if (vid_port_opts & SET_CLOCK_NOT_DELAYED)
2304 video_reg &= ~VP_CLK_CTRL2_DELAYED;
2305 if (vid_port_opts & SET_CLOCK_INVERTED)
2306 video_reg |= VP_CLK_CTRL1_INVERTED;
2307 saa_writeb(SAA7134_VIDEO_PORT_CTRL5, video_reg);
2308 video_reg = video_out[vo][6];
2309 if (vid_port_opts & SET_VSYNC_OFF) {
2310 video_reg &= ~VP_VS_TYPE_MASK;
2311 video_reg |= VP_VS_TYPE_OFF;
2312 }
2313 saa_writeb(SAA7134_VIDEO_PORT_CTRL6, video_reg);
2314 saa_writeb(SAA7134_VIDEO_PORT_CTRL7, video_out[vo][7]);
2315 saa_writeb(SAA7134_VIDEO_PORT_CTRL8, video_out[vo][8]);
2316
2317 /* Start videoport */
2318 saa_writeb(SAA7134_VIDEO_PORT_CTRL3, video_out[vo][3]);
2319
2320 return 0;
2321 }
2322
2323 int saa7134_video_init2(struct saa7134_dev *dev)
2324 {
2325 /* init video hw */
2326 set_tvnorm(dev,&tvnorms[0]);
2327 video_mux(dev,0);
2328 v4l2_ctrl_handler_setup(&dev->ctrl_handler);
2329 saa7134_tvaudio_setmute(dev);
2330 saa7134_tvaudio_setvolume(dev,dev->ctl_volume);
2331 return 0;
2332 }
2333
2334 void saa7134_irq_video_signalchange(struct saa7134_dev *dev)
2335 {
2336 static const char *st[] = {
2337 "(no signal)", "NTSC", "PAL", "SECAM" };
2338 u32 st1,st2;
2339
2340 st1 = saa_readb(SAA7134_STATUS_VIDEO1);
2341 st2 = saa_readb(SAA7134_STATUS_VIDEO2);
2342 dprintk("DCSDT: pll: %s, sync: %s, norm: %s\n",
2343 (st1 & 0x40) ? "not locked" : "locked",
2344 (st2 & 0x40) ? "no" : "yes",
2345 st[st1 & 0x03]);
2346 dev->nosignal = (st1 & 0x40) || (st2 & 0x40) || !(st2 & 0x1);
2347
2348 if (dev->nosignal) {
2349 /* no video signal -> mute audio */
2350 if (dev->ctl_automute)
2351 dev->automute = 1;
2352 saa7134_tvaudio_setmute(dev);
2353 } else {
2354 /* wake up tvaudio audio carrier scan thread */
2355 saa7134_tvaudio_do_scan(dev);
2356 }
2357
2358 if ((st2 & 0x80) && !noninterlaced && !dev->nosignal)
2359 saa_clearb(SAA7134_SYNC_CTRL, 0x20);
2360 else
2361 saa_setb(SAA7134_SYNC_CTRL, 0x20);
2362
2363 if (dev->mops && dev->mops->signal_change)
2364 dev->mops->signal_change(dev);
2365 }
2366
2367
2368 void saa7134_irq_video_done(struct saa7134_dev *dev, unsigned long status)
2369 {
2370 enum v4l2_field field;
2371
2372 spin_lock(&dev->slock);
2373 if (dev->video_q.curr) {
2374 dev->video_fieldcount++;
2375 field = dev->video_q.curr->vb.field;
2376 if (V4L2_FIELD_HAS_BOTH(field)) {
2377 /* make sure we have seen both fields */
2378 if ((status & 0x10) == 0x00) {
2379 dev->video_q.curr->top_seen = 1;
2380 goto done;
2381 }
2382 if (!dev->video_q.curr->top_seen)
2383 goto done;
2384 } else if (field == V4L2_FIELD_TOP) {
2385 if ((status & 0x10) != 0x10)
2386 goto done;
2387 } else if (field == V4L2_FIELD_BOTTOM) {
2388 if ((status & 0x10) != 0x00)
2389 goto done;
2390 }
2391 dev->video_q.curr->vb.field_count = dev->video_fieldcount;
2392 saa7134_buffer_finish(dev,&dev->video_q,VIDEOBUF_DONE);
2393 }
2394 saa7134_buffer_next(dev,&dev->video_q);
2395
2396 done:
2397 spin_unlock(&dev->slock);
2398 }
2399
2400 /* ----------------------------------------------------------- */
2401 /*
2402 * Local variables:
2403 * c-basic-offset: 8
2404 * End:
2405 */
This page took 0.07826 seconds and 4 git commands to generate.