blob: e12bbd8c3f0b8da63f8418e6a00bc803f883963a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/kernel.h>
27#include <linux/slab.h>
Heikki Orsila9040b322007-04-27 12:31:18 -030028#include <linux/sort.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
30#include "saa7134-reg.h"
31#include "saa7134.h"
Michael Krufky5e453dc2006-01-09 15:32:31 -020032#include <media/v4l2-common.h>
Hans Verkuilb9218f22010-12-27 12:22:46 -030033#include <media/saa6588.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Linus Torvalds1da177e2005-04-16 15:20:36 -070035/* ------------------------------------------------------------------ */
36
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -030037unsigned int video_debug;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038static unsigned int gbuffers = 8;
Douglas Schilling Landgrafff699e62008-04-22 14:41:48 -030039static unsigned int noninterlaced; /* 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070040static unsigned int gbufsize = 720*576*4;
41static unsigned int gbufsize_max = 720*576*4;
Hartmut Hackmann17b10a72006-10-02 19:55:07 -030042static char secam[] = "--";
Linus Torvalds1da177e2005-04-16 15:20:36 -070043module_param(video_debug, int, 0644);
44MODULE_PARM_DESC(video_debug,"enable debug messages [video]");
45module_param(gbuffers, int, 0444);
46MODULE_PARM_DESC(gbuffers,"number of capture buffers, range 2-32");
47module_param(noninterlaced, int, 0644);
Hartmut Hackmannd5fdd132006-07-15 09:45:34 -030048MODULE_PARM_DESC(noninterlaced,"capture non interlaced video");
Hartmut Hackmann17b10a72006-10-02 19:55:07 -030049module_param_string(secam, secam, sizeof(secam), 0644);
50MODULE_PARM_DESC(secam, "force SECAM variant, either DK,L or Lc");
51
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -030053#define dprintk(fmt, arg...) if (video_debug&0x04) \
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 printk(KERN_DEBUG "%s/video: " fmt, dev->name , ## arg)
55
56/* ------------------------------------------------------------------ */
Robert W. Boone2f8d4f52005-11-08 21:37:10 -080057/* Defines for Video Output Port Register at address 0x191 */
58
59/* Bit 0: VIP code T bit polarity */
60
61#define VP_T_CODE_P_NON_INVERTED 0x00
62#define VP_T_CODE_P_INVERTED 0x01
63
64/* ------------------------------------------------------------------ */
65/* Defines for Video Output Port Register at address 0x195 */
66
67/* Bit 2: Video output clock delay control */
68
69#define VP_CLK_CTRL2_NOT_DELAYED 0x00
70#define VP_CLK_CTRL2_DELAYED 0x04
71
72/* Bit 1: Video output clock invert control */
73
74#define VP_CLK_CTRL1_NON_INVERTED 0x00
75#define VP_CLK_CTRL1_INVERTED 0x02
76
77/* ------------------------------------------------------------------ */
78/* Defines for Video Output Port Register at address 0x196 */
79
80/* Bits 2 to 0: VSYNC pin video vertical sync type */
81
82#define VP_VS_TYPE_MASK 0x07
83
84#define VP_VS_TYPE_OFF 0x00
85#define VP_VS_TYPE_V123 0x01
86#define VP_VS_TYPE_V_ITU 0x02
87#define VP_VS_TYPE_VGATE_L 0x03
88#define VP_VS_TYPE_RESERVED1 0x04
89#define VP_VS_TYPE_RESERVED2 0x05
90#define VP_VS_TYPE_F_ITU 0x06
91#define VP_VS_TYPE_SC_FID 0x07
92
93/* ------------------------------------------------------------------ */
Linus Torvalds1da177e2005-04-16 15:20:36 -070094/* data structs for video */
95
96static int video_out[][9] = {
97 [CCIR656] = { 0x00, 0xb1, 0x00, 0xa1, 0x00, 0x04, 0x06, 0x00, 0x00 },
98};
99
100static struct saa7134_format formats[] = {
101 {
102 .name = "8 bpp gray",
103 .fourcc = V4L2_PIX_FMT_GREY,
104 .depth = 8,
105 .pm = 0x06,
106 },{
107 .name = "15 bpp RGB, le",
108 .fourcc = V4L2_PIX_FMT_RGB555,
109 .depth = 16,
110 .pm = 0x13 | 0x80,
111 },{
112 .name = "15 bpp RGB, be",
113 .fourcc = V4L2_PIX_FMT_RGB555X,
114 .depth = 16,
115 .pm = 0x13 | 0x80,
116 .bswap = 1,
117 },{
118 .name = "16 bpp RGB, le",
119 .fourcc = V4L2_PIX_FMT_RGB565,
120 .depth = 16,
121 .pm = 0x10 | 0x80,
122 },{
123 .name = "16 bpp RGB, be",
124 .fourcc = V4L2_PIX_FMT_RGB565X,
125 .depth = 16,
126 .pm = 0x10 | 0x80,
127 .bswap = 1,
128 },{
129 .name = "24 bpp RGB, le",
130 .fourcc = V4L2_PIX_FMT_BGR24,
131 .depth = 24,
132 .pm = 0x11,
133 },{
134 .name = "24 bpp RGB, be",
135 .fourcc = V4L2_PIX_FMT_RGB24,
136 .depth = 24,
137 .pm = 0x11,
138 .bswap = 1,
139 },{
140 .name = "32 bpp RGB, le",
141 .fourcc = V4L2_PIX_FMT_BGR32,
142 .depth = 32,
143 .pm = 0x12,
144 },{
145 .name = "32 bpp RGB, be",
146 .fourcc = V4L2_PIX_FMT_RGB32,
147 .depth = 32,
148 .pm = 0x12,
149 .bswap = 1,
150 .wswap = 1,
151 },{
152 .name = "4:2:2 packed, YUYV",
153 .fourcc = V4L2_PIX_FMT_YUYV,
154 .depth = 16,
155 .pm = 0x00,
156 .bswap = 1,
157 .yuv = 1,
158 },{
159 .name = "4:2:2 packed, UYVY",
160 .fourcc = V4L2_PIX_FMT_UYVY,
161 .depth = 16,
162 .pm = 0x00,
163 .yuv = 1,
164 },{
165 .name = "4:2:2 planar, Y-Cb-Cr",
166 .fourcc = V4L2_PIX_FMT_YUV422P,
167 .depth = 16,
168 .pm = 0x09,
169 .yuv = 1,
170 .planar = 1,
171 .hshift = 1,
172 .vshift = 0,
173 },{
174 .name = "4:2:0 planar, Y-Cb-Cr",
175 .fourcc = V4L2_PIX_FMT_YUV420,
176 .depth = 12,
177 .pm = 0x0a,
178 .yuv = 1,
179 .planar = 1,
180 .hshift = 1,
181 .vshift = 1,
182 },{
183 .name = "4:2:0 planar, Y-Cb-Cr",
184 .fourcc = V4L2_PIX_FMT_YVU420,
185 .depth = 12,
186 .pm = 0x0a,
187 .yuv = 1,
188 .planar = 1,
189 .uvswap = 1,
190 .hshift = 1,
191 .vshift = 1,
192 }
193};
194#define FORMATS ARRAY_SIZE(formats)
195
196#define NORM_625_50 \
197 .h_start = 0, \
198 .h_stop = 719, \
199 .video_v_start = 24, \
200 .video_v_stop = 311, \
Michael Schimekf246a812005-06-23 22:04:47 -0700201 .vbi_v_start_0 = 7, \
202 .vbi_v_stop_0 = 22, \
203 .vbi_v_start_1 = 319, \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 .src_timing = 4
205
206#define NORM_525_60 \
207 .h_start = 0, \
Sean Youngdd6ed862010-02-06 10:58:41 -0300208 .h_stop = 719, \
Michael Schimekf246a812005-06-23 22:04:47 -0700209 .video_v_start = 23, \
210 .video_v_stop = 262, \
211 .vbi_v_start_0 = 10, \
212 .vbi_v_stop_0 = 21, \
213 .vbi_v_start_1 = 273, \
214 .src_timing = 7
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
216static struct saa7134_tvnorm tvnorms[] = {
217 {
218 .name = "PAL", /* autodetect */
219 .id = V4L2_STD_PAL,
220 NORM_625_50,
221
222 .sync_control = 0x18,
223 .luma_control = 0x40,
224 .chroma_ctrl1 = 0x81,
225 .chroma_gain = 0x2a,
226 .chroma_ctrl2 = 0x06,
227 .vgate_misc = 0x1c,
228
229 },{
230 .name = "PAL-BG",
231 .id = V4L2_STD_PAL_BG,
232 NORM_625_50,
233
234 .sync_control = 0x18,
235 .luma_control = 0x40,
236 .chroma_ctrl1 = 0x81,
237 .chroma_gain = 0x2a,
238 .chroma_ctrl2 = 0x06,
239 .vgate_misc = 0x1c,
240
241 },{
242 .name = "PAL-I",
243 .id = V4L2_STD_PAL_I,
244 NORM_625_50,
245
246 .sync_control = 0x18,
247 .luma_control = 0x40,
248 .chroma_ctrl1 = 0x81,
249 .chroma_gain = 0x2a,
250 .chroma_ctrl2 = 0x06,
251 .vgate_misc = 0x1c,
252
253 },{
254 .name = "PAL-DK",
255 .id = V4L2_STD_PAL_DK,
256 NORM_625_50,
257
258 .sync_control = 0x18,
259 .luma_control = 0x40,
260 .chroma_ctrl1 = 0x81,
261 .chroma_gain = 0x2a,
262 .chroma_ctrl2 = 0x06,
263 .vgate_misc = 0x1c,
264
265 },{
266 .name = "NTSC",
267 .id = V4L2_STD_NTSC,
268 NORM_525_60,
269
270 .sync_control = 0x59,
271 .luma_control = 0x40,
272 .chroma_ctrl1 = 0x89,
273 .chroma_gain = 0x2a,
274 .chroma_ctrl2 = 0x0e,
275 .vgate_misc = 0x18,
276
277 },{
278 .name = "SECAM",
279 .id = V4L2_STD_SECAM,
280 NORM_625_50,
281
Hartmut Hackmann17b10a72006-10-02 19:55:07 -0300282 .sync_control = 0x18,
283 .luma_control = 0x1b,
284 .chroma_ctrl1 = 0xd1,
285 .chroma_gain = 0x80,
286 .chroma_ctrl2 = 0x00,
287 .vgate_misc = 0x1c,
288
289 },{
290 .name = "SECAM-DK",
291 .id = V4L2_STD_SECAM_DK,
292 NORM_625_50,
293
294 .sync_control = 0x18,
295 .luma_control = 0x1b,
296 .chroma_ctrl1 = 0xd1,
297 .chroma_gain = 0x80,
298 .chroma_ctrl2 = 0x00,
299 .vgate_misc = 0x1c,
300
301 },{
302 .name = "SECAM-L",
303 .id = V4L2_STD_SECAM_L,
304 NORM_625_50,
305
306 .sync_control = 0x18,
307 .luma_control = 0x1b,
308 .chroma_ctrl1 = 0xd1,
309 .chroma_gain = 0x80,
310 .chroma_ctrl2 = 0x00,
311 .vgate_misc = 0x1c,
312
313 },{
314 .name = "SECAM-Lc",
315 .id = V4L2_STD_SECAM_LC,
316 NORM_625_50,
317
318 .sync_control = 0x18,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 .luma_control = 0x1b,
320 .chroma_ctrl1 = 0xd1,
321 .chroma_gain = 0x80,
322 .chroma_ctrl2 = 0x00,
323 .vgate_misc = 0x1c,
324
325 },{
326 .name = "PAL-M",
327 .id = V4L2_STD_PAL_M,
328 NORM_525_60,
329
330 .sync_control = 0x59,
331 .luma_control = 0x40,
332 .chroma_ctrl1 = 0xb9,
333 .chroma_gain = 0x2a,
334 .chroma_ctrl2 = 0x0e,
335 .vgate_misc = 0x18,
336
337 },{
338 .name = "PAL-Nc",
339 .id = V4L2_STD_PAL_Nc,
340 NORM_625_50,
341
342 .sync_control = 0x18,
343 .luma_control = 0x40,
344 .chroma_ctrl1 = 0xa1,
345 .chroma_gain = 0x2a,
346 .chroma_ctrl2 = 0x06,
347 .vgate_misc = 0x1c,
348
349 },{
350 .name = "PAL-60",
351 .id = V4L2_STD_PAL_60,
352
353 .h_start = 0,
354 .h_stop = 719,
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800355 .video_v_start = 23,
356 .video_v_stop = 262,
357 .vbi_v_start_0 = 10,
358 .vbi_v_stop_0 = 21,
359 .vbi_v_start_1 = 273,
360 .src_timing = 7,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
362 .sync_control = 0x18,
363 .luma_control = 0x40,
364 .chroma_ctrl1 = 0x81,
365 .chroma_gain = 0x2a,
366 .chroma_ctrl2 = 0x06,
367 .vgate_misc = 0x1c,
368 }
369};
370#define TVNORMS ARRAY_SIZE(tvnorms)
371
372#define V4L2_CID_PRIVATE_INVERT (V4L2_CID_PRIVATE_BASE + 0)
373#define V4L2_CID_PRIVATE_Y_ODD (V4L2_CID_PRIVATE_BASE + 1)
374#define V4L2_CID_PRIVATE_Y_EVEN (V4L2_CID_PRIVATE_BASE + 2)
375#define V4L2_CID_PRIVATE_AUTOMUTE (V4L2_CID_PRIVATE_BASE + 3)
376#define V4L2_CID_PRIVATE_LASTP1 (V4L2_CID_PRIVATE_BASE + 4)
377
378static const struct v4l2_queryctrl no_ctrl = {
379 .name = "42",
380 .flags = V4L2_CTRL_FLAG_DISABLED,
381};
382static const struct v4l2_queryctrl video_ctrls[] = {
383 /* --- video --- */
384 {
385 .id = V4L2_CID_BRIGHTNESS,
386 .name = "Brightness",
387 .minimum = 0,
388 .maximum = 255,
389 .step = 1,
390 .default_value = 128,
391 .type = V4L2_CTRL_TYPE_INTEGER,
392 },{
393 .id = V4L2_CID_CONTRAST,
394 .name = "Contrast",
395 .minimum = 0,
396 .maximum = 127,
397 .step = 1,
398 .default_value = 68,
399 .type = V4L2_CTRL_TYPE_INTEGER,
400 },{
401 .id = V4L2_CID_SATURATION,
402 .name = "Saturation",
403 .minimum = 0,
404 .maximum = 127,
405 .step = 1,
406 .default_value = 64,
407 .type = V4L2_CTRL_TYPE_INTEGER,
408 },{
409 .id = V4L2_CID_HUE,
410 .name = "Hue",
411 .minimum = -128,
412 .maximum = 127,
413 .step = 1,
414 .default_value = 0,
415 .type = V4L2_CTRL_TYPE_INTEGER,
416 },{
Michael Schimekf246a812005-06-23 22:04:47 -0700417 .id = V4L2_CID_HFLIP,
418 .name = "Mirror",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 .minimum = 0,
420 .maximum = 1,
421 .type = V4L2_CTRL_TYPE_BOOLEAN,
422 },
423 /* --- audio --- */
424 {
425 .id = V4L2_CID_AUDIO_MUTE,
426 .name = "Mute",
427 .minimum = 0,
428 .maximum = 1,
429 .type = V4L2_CTRL_TYPE_BOOLEAN,
430 },{
431 .id = V4L2_CID_AUDIO_VOLUME,
432 .name = "Volume",
433 .minimum = -15,
434 .maximum = 15,
435 .step = 1,
436 .default_value = 0,
437 .type = V4L2_CTRL_TYPE_INTEGER,
438 },
439 /* --- private --- */
440 {
441 .id = V4L2_CID_PRIVATE_INVERT,
442 .name = "Invert",
443 .minimum = 0,
444 .maximum = 1,
445 .type = V4L2_CTRL_TYPE_BOOLEAN,
446 },{
447 .id = V4L2_CID_PRIVATE_Y_ODD,
448 .name = "y offset odd field",
449 .minimum = 0,
450 .maximum = 128,
Mauro Carvalho Chehab553d3c52009-02-09 05:33:54 -0300451 .step = 1,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 .default_value = 0,
453 .type = V4L2_CTRL_TYPE_INTEGER,
454 },{
455 .id = V4L2_CID_PRIVATE_Y_EVEN,
456 .name = "y offset even field",
457 .minimum = 0,
458 .maximum = 128,
Mauro Carvalho Chehab553d3c52009-02-09 05:33:54 -0300459 .step = 1,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 .default_value = 0,
461 .type = V4L2_CTRL_TYPE_INTEGER,
462 },{
463 .id = V4L2_CID_PRIVATE_AUTOMUTE,
464 .name = "automute",
465 .minimum = 0,
466 .maximum = 1,
467 .default_value = 1,
468 .type = V4L2_CTRL_TYPE_BOOLEAN,
469 }
470};
471static const unsigned int CTRLS = ARRAY_SIZE(video_ctrls);
472
473static const struct v4l2_queryctrl* ctrl_by_id(unsigned int id)
474{
475 unsigned int i;
476
477 for (i = 0; i < CTRLS; i++)
478 if (video_ctrls[i].id == id)
479 return video_ctrls+i;
480 return NULL;
481}
482
483static struct saa7134_format* format_by_fourcc(unsigned int fourcc)
484{
485 unsigned int i;
486
487 for (i = 0; i < FORMATS; i++)
488 if (formats[i].fourcc == fourcc)
489 return formats+i;
490 return NULL;
491}
492
493/* ----------------------------------------------------------------------- */
494/* resource management */
495
496static int res_get(struct saa7134_dev *dev, struct saa7134_fh *fh, unsigned int bit)
497{
498 if (fh->resources & bit)
499 /* have it already allocated */
500 return 1;
501
502 /* is it free? */
Ingo Molnar3593cab2006-02-07 06:49:14 -0200503 mutex_lock(&dev->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 if (dev->resources & bit) {
505 /* no, someone else uses it */
Ingo Molnar3593cab2006-02-07 06:49:14 -0200506 mutex_unlock(&dev->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 return 0;
508 }
509 /* it's free, grab it */
510 fh->resources |= bit;
511 dev->resources |= bit;
512 dprintk("res: get %d\n",bit);
Ingo Molnar3593cab2006-02-07 06:49:14 -0200513 mutex_unlock(&dev->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 return 1;
515}
516
Heikki Orsila9040b322007-04-27 12:31:18 -0300517static int res_check(struct saa7134_fh *fh, unsigned int bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518{
519 return (fh->resources & bit);
520}
521
Heikki Orsila9040b322007-04-27 12:31:18 -0300522static int res_locked(struct saa7134_dev *dev, unsigned int bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523{
524 return (dev->resources & bit);
525}
526
527static
528void res_free(struct saa7134_dev *dev, struct saa7134_fh *fh, unsigned int bits)
529{
Eric Sesterhennae246012006-03-13 13:17:11 -0300530 BUG_ON((fh->resources & bits) != bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
Ingo Molnar3593cab2006-02-07 06:49:14 -0200532 mutex_lock(&dev->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 fh->resources &= ~bits;
534 dev->resources &= ~bits;
535 dprintk("res: put %d\n",bits);
Ingo Molnar3593cab2006-02-07 06:49:14 -0200536 mutex_unlock(&dev->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537}
538
539/* ------------------------------------------------------------------ */
540
Adrian Bunkb02044d2007-10-24 13:23:14 -0300541static void set_tvnorm(struct saa7134_dev *dev, struct saa7134_tvnorm *norm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 dprintk("set tv norm = %s\n",norm->name);
544 dev->tvnorm = norm;
545
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 /* setup cropping */
547 dev->crop_bounds.left = norm->h_start;
548 dev->crop_defrect.left = norm->h_start;
549 dev->crop_bounds.width = norm->h_stop - norm->h_start +1;
550 dev->crop_defrect.width = norm->h_stop - norm->h_start +1;
551
Michael Schimekf246a812005-06-23 22:04:47 -0700552 dev->crop_bounds.top = (norm->vbi_v_stop_0+1)*2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 dev->crop_defrect.top = norm->video_v_start*2;
554 dev->crop_bounds.height = ((norm->id & V4L2_STD_525_60) ? 524 : 624)
555 - dev->crop_bounds.top;
556 dev->crop_defrect.height = (norm->video_v_stop - norm->video_v_start +1)*2;
557
558 dev->crop_current = dev->crop_defrect;
559
Maxim Levitskyc4584732007-10-12 00:57:15 -0300560 saa7134_set_tvnorm_hw(dev);
Maxim Levitskycb712012007-09-27 20:34:25 -0300561}
562
563static void video_mux(struct saa7134_dev *dev, int input)
564{
565 dprintk("video input = %d [%s]\n", input, card_in(dev, input).name);
566 dev->ctl_input = input;
567 set_tvnorm(dev, dev->tvnorm);
568 saa7134_tvaudio_setinput(dev, &card_in(dev, input));
569}
570
Maxim Levitskyc4584732007-10-12 00:57:15 -0300571
572static void saa7134_set_decoder(struct saa7134_dev *dev)
Maxim Levitskycb712012007-09-27 20:34:25 -0300573{
574 int luma_control, sync_control, mux;
575
576 struct saa7134_tvnorm *norm = dev->tvnorm;
577 mux = card_in(dev, dev->ctl_input).vmux;
578
579 luma_control = norm->luma_control;
580 sync_control = norm->sync_control;
581
582 if (mux > 5)
583 luma_control |= 0x80; /* svideo */
584 if (noninterlaced || dev->nosignal)
585 sync_control |= 0x20;
586
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 /* setup video decoder */
588 saa_writeb(SAA7134_INCR_DELAY, 0x08);
589 saa_writeb(SAA7134_ANALOG_IN_CTRL1, 0xc0 | mux);
590 saa_writeb(SAA7134_ANALOG_IN_CTRL2, 0x00);
591
592 saa_writeb(SAA7134_ANALOG_IN_CTRL3, 0x90);
593 saa_writeb(SAA7134_ANALOG_IN_CTRL4, 0x90);
594 saa_writeb(SAA7134_HSYNC_START, 0xeb);
595 saa_writeb(SAA7134_HSYNC_STOP, 0xe0);
596 saa_writeb(SAA7134_SOURCE_TIMING1, norm->src_timing);
597
598 saa_writeb(SAA7134_SYNC_CTRL, sync_control);
599 saa_writeb(SAA7134_LUMA_CTRL, luma_control);
600 saa_writeb(SAA7134_DEC_LUMA_BRIGHT, dev->ctl_bright);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
Maxim Levitskyf5a1ac62007-09-27 20:34:20 -0300602 saa_writeb(SAA7134_DEC_LUMA_CONTRAST,
603 dev->ctl_invert ? -dev->ctl_contrast : dev->ctl_contrast);
604
605 saa_writeb(SAA7134_DEC_CHROMA_SATURATION,
606 dev->ctl_invert ? -dev->ctl_saturation : dev->ctl_saturation);
607
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 saa_writeb(SAA7134_DEC_CHROMA_HUE, dev->ctl_hue);
609 saa_writeb(SAA7134_CHROMA_CTRL1, norm->chroma_ctrl1);
610 saa_writeb(SAA7134_CHROMA_GAIN, norm->chroma_gain);
611
612 saa_writeb(SAA7134_CHROMA_CTRL2, norm->chroma_ctrl2);
613 saa_writeb(SAA7134_MODE_DELAY_CTRL, 0x00);
614
615 saa_writeb(SAA7134_ANALOG_ADC, 0x01);
616 saa_writeb(SAA7134_VGATE_START, 0x11);
617 saa_writeb(SAA7134_VGATE_STOP, 0xfe);
618 saa_writeb(SAA7134_MISC_VGATE_MSB, norm->vgate_misc);
619 saa_writeb(SAA7134_RAW_DATA_GAIN, 0x40);
620 saa_writeb(SAA7134_RAW_DATA_OFFSET, 0x80);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621}
622
Maxim Levitskyc4584732007-10-12 00:57:15 -0300623void saa7134_set_tvnorm_hw(struct saa7134_dev *dev)
624{
625 saa7134_set_decoder(dev);
626
Hartmut Hackmann7bff4b42008-04-22 14:46:08 -0300627 if (card_in(dev, dev->ctl_input).tv)
Hans Verkuilf41737e2009-04-01 03:52:39 -0300628 saa_call_all(dev, core, s_std, dev->tvnorm->id);
Hans Verkuil9afb7372008-09-06 06:34:44 -0300629 /* Set the correct norm for the saa6752hs. This function
630 does nothing if there is no saa6752hs. */
Hans Verkuilf41737e2009-04-01 03:52:39 -0300631 saa_call_empress(dev, core, s_std, dev->tvnorm->id);
Maxim Levitskyc4584732007-10-12 00:57:15 -0300632}
633
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634static void set_h_prescale(struct saa7134_dev *dev, int task, int prescale)
635{
636 static const struct {
637 int xpsc;
638 int xacl;
639 int xc2_1;
640 int xdcg;
641 int vpfy;
642 } vals[] = {
643 /* XPSC XACL XC2_1 XDCG VPFY */
644 { 1, 0, 0, 0, 0 },
645 { 2, 2, 1, 2, 2 },
646 { 3, 4, 1, 3, 2 },
647 { 4, 8, 1, 4, 2 },
648 { 5, 8, 1, 4, 2 },
649 { 6, 8, 1, 4, 3 },
650 { 7, 8, 1, 4, 3 },
651 { 8, 15, 0, 4, 3 },
652 { 9, 15, 0, 4, 3 },
653 { 10, 16, 1, 5, 3 },
654 };
655 static const int count = ARRAY_SIZE(vals);
656 int i;
657
658 for (i = 0; i < count; i++)
659 if (vals[i].xpsc == prescale)
660 break;
661 if (i == count)
662 return;
663
664 saa_writeb(SAA7134_H_PRESCALE(task), vals[i].xpsc);
665 saa_writeb(SAA7134_ACC_LENGTH(task), vals[i].xacl);
666 saa_writeb(SAA7134_LEVEL_CTRL(task),
667 (vals[i].xc2_1 << 3) | (vals[i].xdcg));
668 saa_andorb(SAA7134_FIR_PREFILTER_CTRL(task), 0x0f,
669 (vals[i].vpfy << 2) | vals[i].vpfy);
670}
671
672static void set_v_scale(struct saa7134_dev *dev, int task, int yscale)
673{
674 int val,mirror;
675
676 saa_writeb(SAA7134_V_SCALE_RATIO1(task), yscale & 0xff);
677 saa_writeb(SAA7134_V_SCALE_RATIO2(task), yscale >> 8);
678
679 mirror = (dev->ctl_mirror) ? 0x02 : 0x00;
680 if (yscale < 2048) {
681 /* LPI */
682 dprintk("yscale LPI yscale=%d\n",yscale);
683 saa_writeb(SAA7134_V_FILTER(task), 0x00 | mirror);
684 saa_writeb(SAA7134_LUMA_CONTRAST(task), 0x40);
685 saa_writeb(SAA7134_CHROMA_SATURATION(task), 0x40);
686 } else {
687 /* ACM */
688 val = 0x40 * 1024 / yscale;
689 dprintk("yscale ACM yscale=%d val=0x%x\n",yscale,val);
690 saa_writeb(SAA7134_V_FILTER(task), 0x01 | mirror);
691 saa_writeb(SAA7134_LUMA_CONTRAST(task), val);
692 saa_writeb(SAA7134_CHROMA_SATURATION(task), val);
693 }
694 saa_writeb(SAA7134_LUMA_BRIGHT(task), 0x80);
695}
696
697static void set_size(struct saa7134_dev *dev, int task,
698 int width, int height, int interlace)
699{
700 int prescale,xscale,yscale,y_even,y_odd;
701 int h_start, h_stop, v_start, v_stop;
702 int div = interlace ? 2 : 1;
703
704 /* setup video scaler */
705 h_start = dev->crop_current.left;
706 v_start = dev->crop_current.top/2;
707 h_stop = (dev->crop_current.left + dev->crop_current.width -1);
708 v_stop = (dev->crop_current.top + dev->crop_current.height -1)/2;
709
710 saa_writeb(SAA7134_VIDEO_H_START1(task), h_start & 0xff);
711 saa_writeb(SAA7134_VIDEO_H_START2(task), h_start >> 8);
712 saa_writeb(SAA7134_VIDEO_H_STOP1(task), h_stop & 0xff);
713 saa_writeb(SAA7134_VIDEO_H_STOP2(task), h_stop >> 8);
714 saa_writeb(SAA7134_VIDEO_V_START1(task), v_start & 0xff);
715 saa_writeb(SAA7134_VIDEO_V_START2(task), v_start >> 8);
716 saa_writeb(SAA7134_VIDEO_V_STOP1(task), v_stop & 0xff);
717 saa_writeb(SAA7134_VIDEO_V_STOP2(task), v_stop >> 8);
718
719 prescale = dev->crop_current.width / width;
720 if (0 == prescale)
721 prescale = 1;
722 xscale = 1024 * dev->crop_current.width / prescale / width;
723 yscale = 512 * div * dev->crop_current.height / height;
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800724 dprintk("prescale=%d xscale=%d yscale=%d\n",prescale,xscale,yscale);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 set_h_prescale(dev,task,prescale);
726 saa_writeb(SAA7134_H_SCALE_INC1(task), xscale & 0xff);
727 saa_writeb(SAA7134_H_SCALE_INC2(task), xscale >> 8);
728 set_v_scale(dev,task,yscale);
729
730 saa_writeb(SAA7134_VIDEO_PIXELS1(task), width & 0xff);
731 saa_writeb(SAA7134_VIDEO_PIXELS2(task), width >> 8);
732 saa_writeb(SAA7134_VIDEO_LINES1(task), height/div & 0xff);
733 saa_writeb(SAA7134_VIDEO_LINES2(task), height/div >> 8);
734
735 /* deinterlace y offsets */
736 y_odd = dev->ctl_y_odd;
737 y_even = dev->ctl_y_even;
738 saa_writeb(SAA7134_V_PHASE_OFFSET0(task), y_odd);
739 saa_writeb(SAA7134_V_PHASE_OFFSET1(task), y_even);
740 saa_writeb(SAA7134_V_PHASE_OFFSET2(task), y_odd);
741 saa_writeb(SAA7134_V_PHASE_OFFSET3(task), y_even);
742}
743
744/* ------------------------------------------------------------------ */
745
746struct cliplist {
747 __u16 position;
748 __u8 enable;
749 __u8 disable;
750};
751
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752static void set_cliplist(struct saa7134_dev *dev, int reg,
753 struct cliplist *cl, int entries, char *name)
754{
755 __u8 winbits = 0;
756 int i;
757
758 for (i = 0; i < entries; i++) {
759 winbits |= cl[i].enable;
760 winbits &= ~cl[i].disable;
761 if (i < 15 && cl[i].position == cl[i+1].position)
762 continue;
763 saa_writeb(reg + 0, winbits);
764 saa_writeb(reg + 2, cl[i].position & 0xff);
765 saa_writeb(reg + 3, cl[i].position >> 8);
766 dprintk("clip: %s winbits=%02x pos=%d\n",
767 name,winbits,cl[i].position);
768 reg += 8;
769 }
770 for (; reg < 0x400; reg += 8) {
771 saa_writeb(reg+ 0, 0);
772 saa_writeb(reg + 1, 0);
773 saa_writeb(reg + 2, 0);
774 saa_writeb(reg + 3, 0);
775 }
776}
777
778static int clip_range(int val)
779{
780 if (val < 0)
781 val = 0;
782 return val;
783}
784
Heikki Orsila9040b322007-04-27 12:31:18 -0300785/* Sort into smallest position first order */
786static int cliplist_cmp(const void *a, const void *b)
787{
788 const struct cliplist *cla = a;
789 const struct cliplist *clb = b;
790 if (cla->position < clb->position)
791 return -1;
792 if (cla->position > clb->position)
793 return 1;
794 return 0;
795}
796
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797static int setup_clipping(struct saa7134_dev *dev, struct v4l2_clip *clips,
798 int nclips, int interlace)
799{
800 struct cliplist col[16], row[16];
Heikki Orsila9040b322007-04-27 12:31:18 -0300801 int cols = 0, rows = 0, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 int div = interlace ? 2 : 1;
803
Heikki Orsila9040b322007-04-27 12:31:18 -0300804 memset(col, 0, sizeof(col));
805 memset(row, 0, sizeof(row));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 for (i = 0; i < nclips && i < 8; i++) {
807 col[cols].position = clip_range(clips[i].c.left);
808 col[cols].enable = (1 << i);
809 cols++;
810 col[cols].position = clip_range(clips[i].c.left+clips[i].c.width);
811 col[cols].disable = (1 << i);
812 cols++;
813 row[rows].position = clip_range(clips[i].c.top / div);
814 row[rows].enable = (1 << i);
815 rows++;
816 row[rows].position = clip_range((clips[i].c.top + clips[i].c.height)
817 / div);
818 row[rows].disable = (1 << i);
819 rows++;
820 }
Heikki Orsila9040b322007-04-27 12:31:18 -0300821 sort(col, cols, sizeof col[0], cliplist_cmp, NULL);
822 sort(row, rows, sizeof row[0], cliplist_cmp, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 set_cliplist(dev,0x380,col,cols,"cols");
824 set_cliplist(dev,0x384,row,rows,"rows");
825 return 0;
826}
827
Hans Verkuil3a0a5a72013-05-31 11:48:50 -0300828static int verify_preview(struct saa7134_dev *dev, struct v4l2_window *win, bool try)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829{
830 enum v4l2_field field;
831 int maxw, maxh;
832
Hans Verkuil3a0a5a72013-05-31 11:48:50 -0300833 if (!try && (dev->ovbuf.base == NULL || dev->ovfmt == NULL))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 return -EINVAL;
Hans Verkuil3a0a5a72013-05-31 11:48:50 -0300835 if (win->w.width < 48)
836 win->w.width = 48;
837 if (win->w.height < 32)
838 win->w.height = 32;
839 if (win->clipcount > 8)
840 win->clipcount = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841
Hans Verkuil3a0a5a72013-05-31 11:48:50 -0300842 win->chromakey = 0;
843 win->global_alpha = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 field = win->field;
845 maxw = dev->crop_current.width;
846 maxh = dev->crop_current.height;
847
848 if (V4L2_FIELD_ANY == field) {
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800849 field = (win->w.height > maxh/2)
850 ? V4L2_FIELD_INTERLACED
851 : V4L2_FIELD_TOP;
852 }
853 switch (field) {
854 case V4L2_FIELD_TOP:
855 case V4L2_FIELD_BOTTOM:
856 maxh = maxh / 2;
857 break;
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800858 default:
Hans Verkuil3a0a5a72013-05-31 11:48:50 -0300859 field = V4L2_FIELD_INTERLACED;
860 break;
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800861 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862
863 win->field = field;
864 if (win->w.width > maxw)
865 win->w.width = maxw;
866 if (win->w.height > maxh)
867 win->w.height = maxh;
868 return 0;
869}
870
871static int start_preview(struct saa7134_dev *dev, struct saa7134_fh *fh)
872{
873 unsigned long base,control,bpl;
874 int err;
875
Hans Verkuil3a0a5a72013-05-31 11:48:50 -0300876 err = verify_preview(dev, &dev->win, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 if (0 != err)
878 return err;
879
Hans Verkuilb12262f2013-05-31 08:22:24 -0300880 dev->ovfield = dev->win.field;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 dprintk("start_preview %dx%d+%d+%d %s field=%s\n",
Hans Verkuilb12262f2013-05-31 08:22:24 -0300882 dev->win.w.width, dev->win.w.height,
883 dev->win.w.left, dev->win.w.top,
884 dev->ovfmt->name, v4l2_field_names[dev->ovfield]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885
886 /* setup window + clipping */
Hans Verkuilb12262f2013-05-31 08:22:24 -0300887 set_size(dev, TASK_B, dev->win.w.width, dev->win.w.height,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 V4L2_FIELD_HAS_BOTH(dev->ovfield));
Hans Verkuilb12262f2013-05-31 08:22:24 -0300889 setup_clipping(dev, dev->clips, dev->nclips,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 V4L2_FIELD_HAS_BOTH(dev->ovfield));
891 if (dev->ovfmt->yuv)
892 saa_andorb(SAA7134_DATA_PATH(TASK_B), 0x3f, 0x03);
893 else
894 saa_andorb(SAA7134_DATA_PATH(TASK_B), 0x3f, 0x01);
895 saa_writeb(SAA7134_OFMT_VIDEO_B, dev->ovfmt->pm | 0x20);
896
897 /* dma: setup channel 1 (= Video Task B) */
898 base = (unsigned long)dev->ovbuf.base;
Hans Verkuilb12262f2013-05-31 08:22:24 -0300899 base += dev->ovbuf.fmt.bytesperline * dev->win.w.top;
900 base += dev->ovfmt->depth/8 * dev->win.w.left;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 bpl = dev->ovbuf.fmt.bytesperline;
902 control = SAA7134_RS_CONTROL_BURST_16;
903 if (dev->ovfmt->bswap)
904 control |= SAA7134_RS_CONTROL_BSWAP;
905 if (dev->ovfmt->wswap)
906 control |= SAA7134_RS_CONTROL_WSWAP;
907 if (V4L2_FIELD_HAS_BOTH(dev->ovfield)) {
908 saa_writel(SAA7134_RS_BA1(1),base);
909 saa_writel(SAA7134_RS_BA2(1),base+bpl);
910 saa_writel(SAA7134_RS_PITCH(1),bpl*2);
911 saa_writel(SAA7134_RS_CONTROL(1),control);
912 } else {
913 saa_writel(SAA7134_RS_BA1(1),base);
914 saa_writel(SAA7134_RS_BA2(1),base);
915 saa_writel(SAA7134_RS_PITCH(1),bpl);
916 saa_writel(SAA7134_RS_CONTROL(1),control);
917 }
918
919 /* start dma */
920 dev->ovenable = 1;
921 saa7134_set_dmabits(dev);
922
923 return 0;
924}
925
926static int stop_preview(struct saa7134_dev *dev, struct saa7134_fh *fh)
927{
928 dev->ovenable = 0;
929 saa7134_set_dmabits(dev);
930 return 0;
931}
932
933/* ------------------------------------------------------------------ */
934
935static int buffer_activate(struct saa7134_dev *dev,
936 struct saa7134_buf *buf,
937 struct saa7134_buf *next)
938{
939 unsigned long base,control,bpl;
940 unsigned long bpl_uv,lines_uv,base2,base3,tmp; /* planar */
941
942 dprintk("buffer_activate buf=%p\n",buf);
Brandon Philips0fc06862007-11-06 20:02:36 -0300943 buf->vb.state = VIDEOBUF_ACTIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 buf->top_seen = 0;
945
946 set_size(dev,TASK_A,buf->vb.width,buf->vb.height,
947 V4L2_FIELD_HAS_BOTH(buf->vb.field));
948 if (buf->fmt->yuv)
949 saa_andorb(SAA7134_DATA_PATH(TASK_A), 0x3f, 0x03);
950 else
951 saa_andorb(SAA7134_DATA_PATH(TASK_A), 0x3f, 0x01);
952 saa_writeb(SAA7134_OFMT_VIDEO_A, buf->fmt->pm);
953
954 /* DMA: setup channel 0 (= Video Task A0) */
955 base = saa7134_buffer_base(buf);
956 if (buf->fmt->planar)
957 bpl = buf->vb.width;
958 else
959 bpl = (buf->vb.width * buf->fmt->depth) / 8;
960 control = SAA7134_RS_CONTROL_BURST_16 |
961 SAA7134_RS_CONTROL_ME |
962 (buf->pt->dma >> 12);
963 if (buf->fmt->bswap)
964 control |= SAA7134_RS_CONTROL_BSWAP;
965 if (buf->fmt->wswap)
966 control |= SAA7134_RS_CONTROL_WSWAP;
967 if (V4L2_FIELD_HAS_BOTH(buf->vb.field)) {
968 /* interlaced */
969 saa_writel(SAA7134_RS_BA1(0),base);
970 saa_writel(SAA7134_RS_BA2(0),base+bpl);
971 saa_writel(SAA7134_RS_PITCH(0),bpl*2);
972 } else {
973 /* non-interlaced */
974 saa_writel(SAA7134_RS_BA1(0),base);
975 saa_writel(SAA7134_RS_BA2(0),base);
976 saa_writel(SAA7134_RS_PITCH(0),bpl);
977 }
978 saa_writel(SAA7134_RS_CONTROL(0),control);
979
980 if (buf->fmt->planar) {
981 /* DMA: setup channel 4+5 (= planar task A) */
982 bpl_uv = bpl >> buf->fmt->hshift;
983 lines_uv = buf->vb.height >> buf->fmt->vshift;
984 base2 = base + bpl * buf->vb.height;
985 base3 = base2 + bpl_uv * lines_uv;
986 if (buf->fmt->uvswap)
987 tmp = base2, base2 = base3, base3 = tmp;
988 dprintk("uv: bpl=%ld lines=%ld base2/3=%ld/%ld\n",
989 bpl_uv,lines_uv,base2,base3);
990 if (V4L2_FIELD_HAS_BOTH(buf->vb.field)) {
991 /* interlaced */
992 saa_writel(SAA7134_RS_BA1(4),base2);
993 saa_writel(SAA7134_RS_BA2(4),base2+bpl_uv);
994 saa_writel(SAA7134_RS_PITCH(4),bpl_uv*2);
995 saa_writel(SAA7134_RS_BA1(5),base3);
996 saa_writel(SAA7134_RS_BA2(5),base3+bpl_uv);
997 saa_writel(SAA7134_RS_PITCH(5),bpl_uv*2);
998 } else {
999 /* non-interlaced */
1000 saa_writel(SAA7134_RS_BA1(4),base2);
1001 saa_writel(SAA7134_RS_BA2(4),base2);
1002 saa_writel(SAA7134_RS_PITCH(4),bpl_uv);
1003 saa_writel(SAA7134_RS_BA1(5),base3);
1004 saa_writel(SAA7134_RS_BA2(5),base3);
1005 saa_writel(SAA7134_RS_PITCH(5),bpl_uv);
1006 }
1007 saa_writel(SAA7134_RS_CONTROL(4),control);
1008 saa_writel(SAA7134_RS_CONTROL(5),control);
1009 }
1010
1011 /* start DMA */
1012 saa7134_set_dmabits(dev);
1013 mod_timer(&dev->video_q.timeout, jiffies+BUFFER_TIMEOUT);
1014 return 0;
1015}
1016
1017static int buffer_prepare(struct videobuf_queue *q,
1018 struct videobuf_buffer *vb,
1019 enum v4l2_field field)
1020{
1021 struct saa7134_fh *fh = q->priv_data;
1022 struct saa7134_dev *dev = fh->dev;
1023 struct saa7134_buf *buf = container_of(vb,struct saa7134_buf,vb);
1024 unsigned int size;
1025 int err;
1026
1027 /* sanity checks */
Hans Verkuil813b9df2013-05-31 08:30:49 -03001028 if (NULL == dev->fmt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 return -EINVAL;
Hans Verkuil813b9df2013-05-31 08:30:49 -03001030 if (dev->width < 48 ||
1031 dev->height < 32 ||
1032 dev->width/4 > dev->crop_current.width ||
1033 dev->height/4 > dev->crop_current.height ||
1034 dev->width > dev->crop_bounds.width ||
1035 dev->height > dev->crop_bounds.height)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 return -EINVAL;
Hans Verkuil813b9df2013-05-31 08:30:49 -03001037 size = (dev->width * dev->height * dev->fmt->depth) >> 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 if (0 != buf->vb.baddr && buf->vb.bsize < size)
1039 return -EINVAL;
1040
1041 dprintk("buffer_prepare [%d,size=%dx%d,bytes=%d,fields=%s,%s]\n",
Hans Verkuil813b9df2013-05-31 08:30:49 -03001042 vb->i, dev->width, dev->height, size, v4l2_field_names[field],
1043 dev->fmt->name);
1044 if (buf->vb.width != dev->width ||
1045 buf->vb.height != dev->height ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 buf->vb.size != size ||
1047 buf->vb.field != field ||
Hans Verkuil813b9df2013-05-31 08:30:49 -03001048 buf->fmt != dev->fmt) {
Mauro Carvalho Chehabc7b0ac02006-03-10 12:29:15 -03001049 saa7134_dma_free(q,buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 }
1051
Brandon Philips0fc06862007-11-06 20:02:36 -03001052 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
Mauro Carvalho Chehabc1accaa2007-08-23 16:37:49 -03001053 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
1054
Hans Verkuil813b9df2013-05-31 08:30:49 -03001055 buf->vb.width = dev->width;
1056 buf->vb.height = dev->height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 buf->vb.size = size;
1058 buf->vb.field = field;
Hans Verkuil813b9df2013-05-31 08:30:49 -03001059 buf->fmt = dev->fmt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 buf->pt = &fh->pt_cap;
figo.zhangd5709a02009-05-07 23:31:02 -03001061 dev->video_q.curr = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062
Mauro Carvalho Chehabc7b0ac02006-03-10 12:29:15 -03001063 err = videobuf_iolock(q,&buf->vb,&dev->ovbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 if (err)
1065 goto oops;
1066 err = saa7134_pgtable_build(dev->pci,buf->pt,
Mauro Carvalho Chehabc1accaa2007-08-23 16:37:49 -03001067 dma->sglist,
1068 dma->sglen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 saa7134_buffer_startpage(buf));
1070 if (err)
1071 goto oops;
1072 }
Brandon Philips0fc06862007-11-06 20:02:36 -03001073 buf->vb.state = VIDEOBUF_PREPARED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 buf->activate = buffer_activate;
1075 return 0;
1076
1077 oops:
Mauro Carvalho Chehabc7b0ac02006-03-10 12:29:15 -03001078 saa7134_dma_free(q,buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 return err;
1080}
1081
1082static int
1083buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size)
1084{
1085 struct saa7134_fh *fh = q->priv_data;
Hans Verkuil813b9df2013-05-31 08:30:49 -03001086 struct saa7134_dev *dev = fh->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087
Hans Verkuil813b9df2013-05-31 08:30:49 -03001088 *size = dev->fmt->depth * dev->width * dev->height >> 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 if (0 == *count)
1090 *count = gbuffers;
1091 *count = saa7134_buffer_count(*size,*count);
1092 return 0;
1093}
1094
1095static void buffer_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
1096{
1097 struct saa7134_fh *fh = q->priv_data;
1098 struct saa7134_buf *buf = container_of(vb,struct saa7134_buf,vb);
1099
1100 saa7134_buffer_queue(fh->dev,&fh->dev->video_q,buf);
1101}
1102
1103static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
1104{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 struct saa7134_buf *buf = container_of(vb,struct saa7134_buf,vb);
1106
Mauro Carvalho Chehabc7b0ac02006-03-10 12:29:15 -03001107 saa7134_dma_free(q,buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108}
1109
1110static struct videobuf_queue_ops video_qops = {
1111 .buf_setup = buffer_setup,
1112 .buf_prepare = buffer_prepare,
1113 .buf_queue = buffer_queue,
1114 .buf_release = buffer_release,
1115};
1116
1117/* ------------------------------------------------------------------ */
1118
Hans Verkuil531d83a2008-07-26 09:04:06 -03001119int saa7134_g_ctrl_internal(struct saa7134_dev *dev, struct saa7134_fh *fh, struct v4l2_control *c)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120{
1121 const struct v4l2_queryctrl* ctrl;
1122
1123 ctrl = ctrl_by_id(c->id);
1124 if (NULL == ctrl)
1125 return -EINVAL;
1126 switch (c->id) {
1127 case V4L2_CID_BRIGHTNESS:
1128 c->value = dev->ctl_bright;
1129 break;
1130 case V4L2_CID_HUE:
1131 c->value = dev->ctl_hue;
1132 break;
1133 case V4L2_CID_CONTRAST:
1134 c->value = dev->ctl_contrast;
1135 break;
1136 case V4L2_CID_SATURATION:
1137 c->value = dev->ctl_saturation;
1138 break;
1139 case V4L2_CID_AUDIO_MUTE:
1140 c->value = dev->ctl_mute;
1141 break;
1142 case V4L2_CID_AUDIO_VOLUME:
1143 c->value = dev->ctl_volume;
1144 break;
1145 case V4L2_CID_PRIVATE_INVERT:
1146 c->value = dev->ctl_invert;
1147 break;
Michael Schimekf246a812005-06-23 22:04:47 -07001148 case V4L2_CID_HFLIP:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 c->value = dev->ctl_mirror;
1150 break;
1151 case V4L2_CID_PRIVATE_Y_EVEN:
1152 c->value = dev->ctl_y_even;
1153 break;
1154 case V4L2_CID_PRIVATE_Y_ODD:
1155 c->value = dev->ctl_y_odd;
1156 break;
1157 case V4L2_CID_PRIVATE_AUTOMUTE:
1158 c->value = dev->ctl_automute;
1159 break;
1160 default:
1161 return -EINVAL;
1162 }
1163 return 0;
1164}
Hans Verkuil531d83a2008-07-26 09:04:06 -03001165EXPORT_SYMBOL_GPL(saa7134_g_ctrl_internal);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166
Hans Verkuil531d83a2008-07-26 09:04:06 -03001167static int saa7134_g_ctrl(struct file *file, void *priv, struct v4l2_control *c)
1168{
1169 struct saa7134_fh *fh = priv;
1170
1171 return saa7134_g_ctrl_internal(fh->dev, fh, c);
1172}
1173
1174int saa7134_s_ctrl_internal(struct saa7134_dev *dev, struct saa7134_fh *fh, struct v4l2_control *c)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175{
1176 const struct v4l2_queryctrl* ctrl;
1177 unsigned long flags;
1178 int restart_overlay = 0;
Hans Verkuil531d83a2008-07-26 09:04:06 -03001179 int err;
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03001180
Hans Verkuil531d83a2008-07-26 09:04:06 -03001181 err = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03001183 mutex_lock(&dev->lock);
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03001184
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 ctrl = ctrl_by_id(c->id);
1186 if (NULL == ctrl)
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03001187 goto error;
1188
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 dprintk("set_control name=%s val=%d\n",ctrl->name,c->value);
1190 switch (ctrl->type) {
1191 case V4L2_CTRL_TYPE_BOOLEAN:
1192 case V4L2_CTRL_TYPE_MENU:
1193 case V4L2_CTRL_TYPE_INTEGER:
1194 if (c->value < ctrl->minimum)
1195 c->value = ctrl->minimum;
1196 if (c->value > ctrl->maximum)
1197 c->value = ctrl->maximum;
1198 break;
1199 default:
1200 /* nothing */;
Peter Senna Tschudinc2c1b412012-09-28 05:37:22 -03001201 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 switch (c->id) {
1203 case V4L2_CID_BRIGHTNESS:
1204 dev->ctl_bright = c->value;
1205 saa_writeb(SAA7134_DEC_LUMA_BRIGHT, dev->ctl_bright);
1206 break;
1207 case V4L2_CID_HUE:
1208 dev->ctl_hue = c->value;
1209 saa_writeb(SAA7134_DEC_CHROMA_HUE, dev->ctl_hue);
1210 break;
1211 case V4L2_CID_CONTRAST:
1212 dev->ctl_contrast = c->value;
1213 saa_writeb(SAA7134_DEC_LUMA_CONTRAST,
1214 dev->ctl_invert ? -dev->ctl_contrast : dev->ctl_contrast);
1215 break;
1216 case V4L2_CID_SATURATION:
1217 dev->ctl_saturation = c->value;
1218 saa_writeb(SAA7134_DEC_CHROMA_SATURATION,
1219 dev->ctl_invert ? -dev->ctl_saturation : dev->ctl_saturation);
1220 break;
1221 case V4L2_CID_AUDIO_MUTE:
1222 dev->ctl_mute = c->value;
1223 saa7134_tvaudio_setmute(dev);
1224 break;
1225 case V4L2_CID_AUDIO_VOLUME:
1226 dev->ctl_volume = c->value;
1227 saa7134_tvaudio_setvolume(dev,dev->ctl_volume);
1228 break;
1229 case V4L2_CID_PRIVATE_INVERT:
1230 dev->ctl_invert = c->value;
1231 saa_writeb(SAA7134_DEC_LUMA_CONTRAST,
1232 dev->ctl_invert ? -dev->ctl_contrast : dev->ctl_contrast);
1233 saa_writeb(SAA7134_DEC_CHROMA_SATURATION,
1234 dev->ctl_invert ? -dev->ctl_saturation : dev->ctl_saturation);
1235 break;
Michael Schimekf246a812005-06-23 22:04:47 -07001236 case V4L2_CID_HFLIP:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 dev->ctl_mirror = c->value;
1238 restart_overlay = 1;
1239 break;
1240 case V4L2_CID_PRIVATE_Y_EVEN:
1241 dev->ctl_y_even = c->value;
1242 restart_overlay = 1;
1243 break;
1244 case V4L2_CID_PRIVATE_Y_ODD:
1245 dev->ctl_y_odd = c->value;
1246 restart_overlay = 1;
1247 break;
1248 case V4L2_CID_PRIVATE_AUTOMUTE:
Mauro Carvalho Chehab7f171122007-10-18 19:56:47 -03001249 {
1250 struct v4l2_priv_tun_config tda9887_cfg;
1251
1252 tda9887_cfg.tuner = TUNER_TDA9887;
1253 tda9887_cfg.priv = &dev->tda9887_conf;
1254
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 dev->ctl_automute = c->value;
1256 if (dev->tda9887_conf) {
1257 if (dev->ctl_automute)
1258 dev->tda9887_conf |= TDA9887_AUTOMUTE;
1259 else
1260 dev->tda9887_conf &= ~TDA9887_AUTOMUTE;
Mauro Carvalho Chehab7f171122007-10-18 19:56:47 -03001261
Hans Verkuilfac69862009-01-17 12:17:14 -03001262 saa_call_all(dev, tuner, s_config, &tda9887_cfg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 }
1264 break;
Mauro Carvalho Chehab7f171122007-10-18 19:56:47 -03001265 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 default:
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03001267 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 }
1269 if (restart_overlay && fh && res_check(fh, RESOURCE_OVERLAY)) {
1270 spin_lock_irqsave(&dev->slock,flags);
1271 stop_preview(dev,fh);
1272 start_preview(dev,fh);
1273 spin_unlock_irqrestore(&dev->slock,flags);
1274 }
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03001275 err = 0;
1276
1277error:
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03001278 mutex_unlock(&dev->lock);
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03001279 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280}
Hans Verkuil531d83a2008-07-26 09:04:06 -03001281EXPORT_SYMBOL_GPL(saa7134_s_ctrl_internal);
1282
1283static int saa7134_s_ctrl(struct file *file, void *f, struct v4l2_control *c)
1284{
1285 struct saa7134_fh *fh = f;
1286
1287 return saa7134_s_ctrl_internal(fh->dev, fh, c);
1288}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289
1290/* ------------------------------------------------------------------ */
1291
Hans Verkuil8fcd4762013-05-31 07:57:10 -03001292static struct videobuf_queue *saa7134_queue(struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293{
Hans Verkuil8fcd4762013-05-31 07:57:10 -03001294 struct video_device *vdev = video_devdata(file);
1295 struct saa7134_fh *fh = file->private_data;
1296 struct videobuf_queue *q = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297
Hans Verkuil8fcd4762013-05-31 07:57:10 -03001298 switch (vdev->vfl_type) {
1299 case VFL_TYPE_GRABBER:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 q = &fh->cap;
1301 break;
Hans Verkuil8fcd4762013-05-31 07:57:10 -03001302 case VFL_TYPE_VBI:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 q = &fh->vbi;
1304 break;
1305 default:
1306 BUG();
1307 }
1308 return q;
1309}
1310
Hans Verkuil8fcd4762013-05-31 07:57:10 -03001311static int saa7134_resource(struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312{
Hans Verkuil8fcd4762013-05-31 07:57:10 -03001313 struct video_device *vdev = video_devdata(file);
1314
1315 if (vdev->vfl_type == VFL_TYPE_GRABBER)
Heikki Orsila9040b322007-04-27 12:31:18 -03001316 return RESOURCE_VIDEO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317
Hans Verkuil8fcd4762013-05-31 07:57:10 -03001318 if (vdev->vfl_type == VFL_TYPE_VBI)
Heikki Orsila9040b322007-04-27 12:31:18 -03001319 return RESOURCE_VBI;
1320
1321 BUG();
1322 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323}
1324
Hans Verkuilbec43662008-12-30 06:58:20 -03001325static int video_open(struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326{
Laurent Pinchart63b0d5a2009-12-10 11:44:04 -02001327 struct video_device *vdev = video_devdata(file);
1328 struct saa7134_dev *dev = video_drvdata(file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 struct saa7134_fh *fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330
1331 /* allocate + initialize per filehandle data */
Panagiotis Issaris74081872006-01-11 19:40:56 -02001332 fh = kzalloc(sizeof(*fh),GFP_KERNEL);
Mauro Carvalho Chehabbefd6e62009-02-09 12:27:03 -03001333 if (NULL == fh)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 return -ENOMEM;
Mauro Carvalho Chehabbefd6e62009-02-09 12:27:03 -03001335
Ondrej Zary3bbaa3a2013-02-01 20:01:16 -03001336 v4l2_fh_init(&fh->fh, vdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 file->private_data = fh;
1338 fh->dev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339
Guennadi Liakhovetski07051352008-04-22 14:42:13 -03001340 videobuf_queue_sg_init(&fh->cap, &video_qops,
1341 &dev->pci->dev, &dev->slock,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 V4L2_BUF_TYPE_VIDEO_CAPTURE,
1343 V4L2_FIELD_INTERLACED,
1344 sizeof(struct saa7134_buf),
Hans Verkuil08bff032010-09-20 17:39:46 -03001345 fh, NULL);
Guennadi Liakhovetski07051352008-04-22 14:42:13 -03001346 videobuf_queue_sg_init(&fh->vbi, &saa7134_vbi_qops,
1347 &dev->pci->dev, &dev->slock,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 V4L2_BUF_TYPE_VBI_CAPTURE,
1349 V4L2_FIELD_SEQ_TB,
1350 sizeof(struct saa7134_buf),
Hans Verkuil08bff032010-09-20 17:39:46 -03001351 fh, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 saa7134_pgtable_alloc(dev->pci,&fh->pt_cap);
1353 saa7134_pgtable_alloc(dev->pci,&fh->pt_vbi);
1354
Hans Verkuil8fcd4762013-05-31 07:57:10 -03001355 if (vdev->vfl_type == VFL_TYPE_RADIO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 /* switch to radio mode */
1357 saa7134_tvaudio_setinput(dev,&card(dev).radio);
Hans Verkuilfac69862009-01-17 12:17:14 -03001358 saa_call_all(dev, tuner, s_radio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 } else {
1360 /* switch to video/vbi mode */
1361 video_mux(dev,dev->ctl_input);
1362 }
Ondrej Zary3bbaa3a2013-02-01 20:01:16 -03001363 v4l2_fh_add(&fh->fh);
1364
Mauro Carvalho Chehab330a1152005-07-12 13:59:01 -07001365 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366}
1367
1368static ssize_t
1369video_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
1370{
Hans Verkuil8fcd4762013-05-31 07:57:10 -03001371 struct video_device *vdev = video_devdata(file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 struct saa7134_fh *fh = file->private_data;
1373
Hans Verkuil8fcd4762013-05-31 07:57:10 -03001374 switch (vdev->vfl_type) {
1375 case VFL_TYPE_GRABBER:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 if (res_locked(fh->dev,RESOURCE_VIDEO))
1377 return -EBUSY;
Hans Verkuil8fcd4762013-05-31 07:57:10 -03001378 return videobuf_read_one(saa7134_queue(file),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 data, count, ppos,
1380 file->f_flags & O_NONBLOCK);
Hans Verkuil8fcd4762013-05-31 07:57:10 -03001381 case VFL_TYPE_VBI:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 if (!res_get(fh->dev,fh,RESOURCE_VBI))
1383 return -EBUSY;
Hans Verkuil8fcd4762013-05-31 07:57:10 -03001384 return videobuf_read_stream(saa7134_queue(file),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 data, count, ppos, 1,
1386 file->f_flags & O_NONBLOCK);
1387 break;
1388 default:
1389 BUG();
1390 return 0;
1391 }
1392}
1393
1394static unsigned int
1395video_poll(struct file *file, struct poll_table_struct *wait)
1396{
Hans Verkuil8fcd4762013-05-31 07:57:10 -03001397 struct video_device *vdev = video_devdata(file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 struct saa7134_fh *fh = file->private_data;
1399 struct videobuf_buffer *buf = NULL;
figo.zhang4a567392009-05-17 23:13:13 -03001400 unsigned int rc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401
Hans Verkuil8fcd4762013-05-31 07:57:10 -03001402 if (vdev->vfl_type == VFL_TYPE_VBI)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 return videobuf_poll_stream(file, &fh->vbi, wait);
1404
1405 if (res_check(fh,RESOURCE_VIDEO)) {
figo.zhang4a567392009-05-17 23:13:13 -03001406 mutex_lock(&fh->cap.vb_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 if (!list_empty(&fh->cap.stream))
1408 buf = list_entry(fh->cap.stream.next, struct videobuf_buffer, stream);
1409 } else {
Mauro Carvalho Chehab64f94772008-01-31 13:57:53 -03001410 mutex_lock(&fh->cap.vb_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 if (UNSET == fh->cap.read_off) {
Mauro Carvalho Chehab330a1152005-07-12 13:59:01 -07001412 /* need to capture a new frame */
Mauro Carvalho Chehab64f94772008-01-31 13:57:53 -03001413 if (res_locked(fh->dev,RESOURCE_VIDEO))
1414 goto err;
1415 if (0 != fh->cap.ops->buf_prepare(&fh->cap,fh->cap.read_buf,fh->cap.field))
1416 goto err;
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -08001417 fh->cap.ops->buf_queue(&fh->cap,fh->cap.read_buf);
1418 fh->cap.read_off = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 buf = fh->cap.read_buf;
1421 }
1422
1423 if (!buf)
figo.zhang4a567392009-05-17 23:13:13 -03001424 goto err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425
1426 poll_wait(file, &buf->done, wait);
Brandon Philips0fc06862007-11-06 20:02:36 -03001427 if (buf->state == VIDEOBUF_DONE ||
1428 buf->state == VIDEOBUF_ERROR)
figo.zhang4a567392009-05-17 23:13:13 -03001429 rc = POLLIN|POLLRDNORM;
1430 mutex_unlock(&fh->cap.vb_lock);
1431 return rc;
Mauro Carvalho Chehab64f94772008-01-31 13:57:53 -03001432
1433err:
1434 mutex_unlock(&fh->cap.vb_lock);
1435 return POLLERR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436}
1437
Hans Verkuilbec43662008-12-30 06:58:20 -03001438static int video_release(struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439{
Hans Verkuil8fcd4762013-05-31 07:57:10 -03001440 struct video_device *vdev = video_devdata(file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441 struct saa7134_fh *fh = file->private_data;
1442 struct saa7134_dev *dev = fh->dev;
Hans Verkuilb9218f22010-12-27 12:22:46 -03001443 struct saa6588_command cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 unsigned long flags;
1445
Stas Sergeeva1dca1e2011-12-03 16:40:45 -03001446 saa7134_tvaudio_close(dev);
1447
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 /* turn off overlay */
1449 if (res_check(fh, RESOURCE_OVERLAY)) {
1450 spin_lock_irqsave(&dev->slock,flags);
1451 stop_preview(dev,fh);
1452 spin_unlock_irqrestore(&dev->slock,flags);
1453 res_free(dev,fh,RESOURCE_OVERLAY);
1454 }
1455
1456 /* stop video capture */
1457 if (res_check(fh, RESOURCE_VIDEO)) {
1458 videobuf_streamoff(&fh->cap);
1459 res_free(dev,fh,RESOURCE_VIDEO);
1460 }
1461 if (fh->cap.read_buf) {
1462 buffer_release(&fh->cap,fh->cap.read_buf);
1463 kfree(fh->cap.read_buf);
1464 }
1465
1466 /* stop vbi capture */
1467 if (res_check(fh, RESOURCE_VBI)) {
Brandon Philips053fcb62007-11-13 20:11:26 -03001468 videobuf_stop(&fh->vbi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469 res_free(dev,fh,RESOURCE_VBI);
1470 }
1471
Mauro Carvalho Chehab330a1152005-07-12 13:59:01 -07001472 /* ts-capture will not work in planar mode, so turn it off Hac: 04.05*/
1473 saa_andorb(SAA7134_OFMT_VIDEO_A, 0x1f, 0);
1474 saa_andorb(SAA7134_OFMT_VIDEO_B, 0x1f, 0);
1475 saa_andorb(SAA7134_OFMT_DATA_A, 0x1f, 0);
1476 saa_andorb(SAA7134_OFMT_DATA_B, 0x1f, 0);
1477
Laurent Pinchart622b8282009-10-05 10:48:17 -03001478 saa_call_all(dev, core, s_power, 0);
Hans Verkuil8fcd4762013-05-31 07:57:10 -03001479 if (vdev->vfl_type == VFL_TYPE_RADIO)
Hans Verkuilb9218f22010-12-27 12:22:46 -03001480 saa_call_all(dev, core, ioctl, SAA6588_CMD_CLOSE, &cmd);
Mauro Carvalho Chehab330a1152005-07-12 13:59:01 -07001481
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 /* free stuff */
1483 videobuf_mmap_free(&fh->cap);
1484 videobuf_mmap_free(&fh->vbi);
1485 saa7134_pgtable_free(dev->pci,&fh->pt_cap);
1486 saa7134_pgtable_free(dev->pci,&fh->pt_vbi);
1487
Ondrej Zary3bbaa3a2013-02-01 20:01:16 -03001488 v4l2_fh_del(&fh->fh);
1489 v4l2_fh_exit(&fh->fh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 file->private_data = NULL;
1491 kfree(fh);
1492 return 0;
1493}
1494
Heikki Orsila9040b322007-04-27 12:31:18 -03001495static int video_mmap(struct file *file, struct vm_area_struct * vma)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496{
Hans Verkuil8fcd4762013-05-31 07:57:10 -03001497 return videobuf_mmap_mapper(saa7134_queue(file), vma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498}
1499
Hans Verkuil2983baf2009-03-29 06:26:27 -03001500static ssize_t radio_read(struct file *file, char __user *data,
1501 size_t count, loff_t *ppos)
1502{
1503 struct saa7134_fh *fh = file->private_data;
1504 struct saa7134_dev *dev = fh->dev;
Hans Verkuilb9218f22010-12-27 12:22:46 -03001505 struct saa6588_command cmd;
Hans Verkuil2983baf2009-03-29 06:26:27 -03001506
1507 cmd.block_count = count/3;
1508 cmd.buffer = data;
1509 cmd.instance = file;
1510 cmd.result = -ENODEV;
1511
Hans Verkuilb9218f22010-12-27 12:22:46 -03001512 saa_call_all(dev, core, ioctl, SAA6588_CMD_READ, &cmd);
Hans Verkuil2983baf2009-03-29 06:26:27 -03001513
1514 return cmd.result;
1515}
1516
1517static unsigned int radio_poll(struct file *file, poll_table *wait)
1518{
1519 struct saa7134_fh *fh = file->private_data;
1520 struct saa7134_dev *dev = fh->dev;
Hans Verkuilb9218f22010-12-27 12:22:46 -03001521 struct saa6588_command cmd;
Hans Verkuil2983baf2009-03-29 06:26:27 -03001522
1523 cmd.instance = file;
1524 cmd.event_list = wait;
1525 cmd.result = -ENODEV;
Hans Verkuilb9218f22010-12-27 12:22:46 -03001526 saa_call_all(dev, core, ioctl, SAA6588_CMD_POLL, &cmd);
Hans Verkuil2983baf2009-03-29 06:26:27 -03001527
1528 return cmd.result;
1529}
1530
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531/* ------------------------------------------------------------------ */
1532
Hans Verkuil78b526a2008-05-28 12:16:41 -03001533static int saa7134_try_get_set_fmt_vbi_cap(struct file *file, void *priv,
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03001534 struct v4l2_format *f)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535{
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03001536 struct saa7134_fh *fh = priv;
1537 struct saa7134_dev *dev = fh->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 struct saa7134_tvnorm *norm = dev->tvnorm;
1539
Ondrej Zaryd0477952013-02-01 20:01:21 -03001540 memset(&f->fmt.vbi.reserved, 0, sizeof(f->fmt.vbi.reserved));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 f->fmt.vbi.sampling_rate = 6750000 * 4;
1542 f->fmt.vbi.samples_per_line = 2048 /* VBI_LINE_LENGTH */;
1543 f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
1544 f->fmt.vbi.offset = 64 * 4;
Michael Schimekf246a812005-06-23 22:04:47 -07001545 f->fmt.vbi.start[0] = norm->vbi_v_start_0;
1546 f->fmt.vbi.count[0] = norm->vbi_v_stop_0 - norm->vbi_v_start_0 +1;
1547 f->fmt.vbi.start[1] = norm->vbi_v_start_1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 f->fmt.vbi.count[1] = f->fmt.vbi.count[0];
1549 f->fmt.vbi.flags = 0; /* VBI_UNSYNC VBI_INTERLACED */
1550
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03001551 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552}
1553
Hans Verkuil78b526a2008-05-28 12:16:41 -03001554static int saa7134_g_fmt_vid_cap(struct file *file, void *priv,
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03001555 struct v4l2_format *f)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556{
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03001557 struct saa7134_fh *fh = priv;
Hans Verkuil813b9df2013-05-31 08:30:49 -03001558 struct saa7134_dev *dev = fh->dev;
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03001559
Hans Verkuil813b9df2013-05-31 08:30:49 -03001560 f->fmt.pix.width = dev->width;
1561 f->fmt.pix.height = dev->height;
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03001562 f->fmt.pix.field = fh->cap.field;
Hans Verkuil813b9df2013-05-31 08:30:49 -03001563 f->fmt.pix.pixelformat = dev->fmt->fourcc;
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03001564 f->fmt.pix.bytesperline =
Hans Verkuil813b9df2013-05-31 08:30:49 -03001565 (f->fmt.pix.width * dev->fmt->depth) >> 3;
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03001566 f->fmt.pix.sizeimage =
1567 f->fmt.pix.height * f->fmt.pix.bytesperline;
Hans Verkuil3a0a5a72013-05-31 11:48:50 -03001568 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
1569 f->fmt.pix.priv = 0;
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03001570 return 0;
1571}
1572
Hans Verkuil78b526a2008-05-28 12:16:41 -03001573static int saa7134_g_fmt_vid_overlay(struct file *file, void *priv,
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03001574 struct v4l2_format *f)
1575{
1576 struct saa7134_fh *fh = priv;
Hans Verkuilb12262f2013-05-31 08:22:24 -03001577 struct saa7134_dev *dev = fh->dev;
Emil Goode12d866e2013-06-22 08:02:52 -03001578 struct v4l2_clip __user *clips = f->fmt.win.clips;
Hans Verkuil3a0a5a72013-05-31 11:48:50 -03001579 u32 clipcount = f->fmt.win.clipcount;
1580 int err = 0;
1581 int i;
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03001582
1583 if (saa7134_no_overlay > 0) {
1584 printk(KERN_ERR "V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585 return -EINVAL;
1586 }
Hans Verkuil3a0a5a72013-05-31 11:48:50 -03001587 mutex_lock(&dev->lock);
Hans Verkuilb12262f2013-05-31 08:22:24 -03001588 f->fmt.win = dev->win;
Hans Verkuil3a0a5a72013-05-31 11:48:50 -03001589 f->fmt.win.clips = clips;
1590 if (clips == NULL)
1591 clipcount = 0;
1592 if (dev->nclips < clipcount)
1593 clipcount = dev->nclips;
1594 f->fmt.win.clipcount = clipcount;
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03001595
Hans Verkuil3a0a5a72013-05-31 11:48:50 -03001596 for (i = 0; !err && i < clipcount; i++) {
1597 if (copy_to_user(&f->fmt.win.clips[i].c, &dev->clips[i].c,
1598 sizeof(struct v4l2_rect)))
1599 err = -EFAULT;
1600 }
1601 mutex_unlock(&dev->lock);
1602
1603 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604}
1605
Hans Verkuil78b526a2008-05-28 12:16:41 -03001606static int saa7134_try_fmt_vid_cap(struct file *file, void *priv,
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03001607 struct v4l2_format *f)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608{
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03001609 struct saa7134_fh *fh = priv;
1610 struct saa7134_dev *dev = fh->dev;
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03001611 struct saa7134_format *fmt;
1612 enum v4l2_field field;
1613 unsigned int maxw, maxh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03001615 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
1616 if (NULL == fmt)
1617 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03001619 field = f->fmt.pix.field;
1620 maxw = min(dev->crop_current.width*4, dev->crop_bounds.width);
1621 maxh = min(dev->crop_current.height*4, dev->crop_bounds.height);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03001623 if (V4L2_FIELD_ANY == field) {
1624 field = (f->fmt.pix.height > maxh/2)
1625 ? V4L2_FIELD_INTERLACED
1626 : V4L2_FIELD_BOTTOM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 }
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03001628 switch (field) {
1629 case V4L2_FIELD_TOP:
1630 case V4L2_FIELD_BOTTOM:
1631 maxh = maxh / 2;
1632 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633 default:
Hans Verkuil3a0a5a72013-05-31 11:48:50 -03001634 field = V4L2_FIELD_INTERLACED;
1635 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636 }
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03001637
1638 f->fmt.pix.field = field;
Herton Ronaldo Krzesinski0a062032010-03-19 14:58:23 -03001639 if (f->fmt.pix.width < 48)
1640 f->fmt.pix.width = 48;
1641 if (f->fmt.pix.height < 32)
1642 f->fmt.pix.height = 32;
1643 if (f->fmt.pix.width > maxw)
1644 f->fmt.pix.width = maxw;
1645 if (f->fmt.pix.height > maxh)
1646 f->fmt.pix.height = maxh;
1647 f->fmt.pix.width &= ~0x03;
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03001648 f->fmt.pix.bytesperline =
1649 (f->fmt.pix.width * fmt->depth) >> 3;
1650 f->fmt.pix.sizeimage =
1651 f->fmt.pix.height * f->fmt.pix.bytesperline;
Hans Verkuil3a0a5a72013-05-31 11:48:50 -03001652 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
1653 f->fmt.pix.priv = 0;
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03001654
1655 return 0;
1656}
1657
Hans Verkuil78b526a2008-05-28 12:16:41 -03001658static int saa7134_try_fmt_vid_overlay(struct file *file, void *priv,
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03001659 struct v4l2_format *f)
1660{
1661 struct saa7134_fh *fh = priv;
1662 struct saa7134_dev *dev = fh->dev;
1663
1664 if (saa7134_no_overlay > 0) {
1665 printk(KERN_ERR "V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n");
1666 return -EINVAL;
1667 }
1668
Hans Verkuil3a0a5a72013-05-31 11:48:50 -03001669 if (f->fmt.win.clips == NULL)
1670 f->fmt.win.clipcount = 0;
1671 return verify_preview(dev, &f->fmt.win, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672}
1673
Hans Verkuil78b526a2008-05-28 12:16:41 -03001674static int saa7134_s_fmt_vid_cap(struct file *file, void *priv,
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03001675 struct v4l2_format *f)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676{
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03001677 struct saa7134_fh *fh = priv;
Hans Verkuil813b9df2013-05-31 08:30:49 -03001678 struct saa7134_dev *dev = fh->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 int err;
1680
Hans Verkuil78b526a2008-05-28 12:16:41 -03001681 err = saa7134_try_fmt_vid_cap(file, priv, f);
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03001682 if (0 != err)
1683 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684
Hans Verkuil813b9df2013-05-31 08:30:49 -03001685 dev->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
1686 dev->width = f->fmt.pix.width;
1687 dev->height = f->fmt.pix.height;
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03001688 fh->cap.field = f->fmt.pix.field;
1689 return 0;
1690}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691
Hans Verkuil78b526a2008-05-28 12:16:41 -03001692static int saa7134_s_fmt_vid_overlay(struct file *file, void *priv,
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03001693 struct v4l2_format *f)
1694{
1695 struct saa7134_fh *fh = priv;
1696 struct saa7134_dev *dev = fh->dev;
1697 int err;
Steven Rostedta8b1ecf2008-05-06 20:42:29 -07001698 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03001700 if (saa7134_no_overlay > 0) {
1701 printk(KERN_ERR "V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 return -EINVAL;
1703 }
Hans Verkuil3a0a5a72013-05-31 11:48:50 -03001704 if (f->fmt.win.clips == NULL)
1705 f->fmt.win.clipcount = 0;
1706 err = verify_preview(dev, &f->fmt.win, true);
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03001707 if (0 != err)
1708 return err;
1709
1710 mutex_lock(&dev->lock);
1711
Hans Verkuilb12262f2013-05-31 08:22:24 -03001712 dev->win = f->fmt.win;
1713 dev->nclips = f->fmt.win.clipcount;
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03001714
Hans Verkuilb12262f2013-05-31 08:22:24 -03001715 if (copy_from_user(dev->clips, f->fmt.win.clips,
1716 sizeof(struct v4l2_clip) * dev->nclips)) {
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03001717 mutex_unlock(&dev->lock);
1718 return -EFAULT;
1719 }
1720
1721 if (res_check(fh, RESOURCE_OVERLAY)) {
1722 spin_lock_irqsave(&dev->slock, flags);
1723 stop_preview(dev, fh);
1724 start_preview(dev, fh);
1725 spin_unlock_irqrestore(&dev->slock, flags);
1726 }
1727
1728 mutex_unlock(&dev->lock);
1729 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730}
1731
Mauro Carvalho Chehab2c10e8a2007-12-11 12:56:23 -03001732int saa7134_queryctrl(struct file *file, void *priv, struct v4l2_queryctrl *c)
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03001733{
1734 const struct v4l2_queryctrl *ctrl;
1735
1736 if ((c->id < V4L2_CID_BASE ||
1737 c->id >= V4L2_CID_LASTP1) &&
1738 (c->id < V4L2_CID_PRIVATE_BASE ||
1739 c->id >= V4L2_CID_PRIVATE_LASTP1))
1740 return -EINVAL;
1741 ctrl = ctrl_by_id(c->id);
1742 *c = (NULL != ctrl) ? *ctrl : no_ctrl;
1743 return 0;
1744}
Mauro Carvalho Chehabf6e90a62007-12-11 15:01:57 -03001745EXPORT_SYMBOL_GPL(saa7134_queryctrl);
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03001746
Mauro Carvalho Chehabbfb12e32007-12-11 11:51:53 -03001747static int saa7134_enum_input(struct file *file, void *priv,
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03001748 struct v4l2_input *i)
1749{
1750 struct saa7134_fh *fh = priv;
1751 struct saa7134_dev *dev = fh->dev;
1752 unsigned int n;
1753
1754 n = i->index;
1755 if (n >= SAA7134_INPUT_MAX)
1756 return -EINVAL;
1757 if (NULL == card_in(dev, i->index).name)
1758 return -EINVAL;
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03001759 i->index = n;
1760 i->type = V4L2_INPUT_TYPE_CAMERA;
1761 strcpy(i->name, card_in(dev, n).name);
1762 if (card_in(dev, n).tv)
1763 i->type = V4L2_INPUT_TYPE_TUNER;
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03001764 if (n == dev->ctl_input) {
1765 int v1 = saa_readb(SAA7134_STATUS_VIDEO1);
1766 int v2 = saa_readb(SAA7134_STATUS_VIDEO2);
1767
1768 if (0 != (v1 & 0x40))
1769 i->status |= V4L2_IN_ST_NO_H_LOCK;
1770 if (0 != (v2 & 0x40))
1771 i->status |= V4L2_IN_ST_NO_SYNC;
1772 if (0 != (v2 & 0x0e))
1773 i->status |= V4L2_IN_ST_MACROVISION;
1774 }
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03001775 i->std = SAA7134_NORMS;
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03001776 return 0;
1777}
1778
Mauro Carvalho Chehabbfb12e32007-12-11 11:51:53 -03001779static int saa7134_g_input(struct file *file, void *priv, unsigned int *i)
Mauro Carvalho Chehab90bdc142007-12-07 17:23:38 -03001780{
1781 struct saa7134_fh *fh = priv;
1782 struct saa7134_dev *dev = fh->dev;
1783
1784 *i = dev->ctl_input;
1785 return 0;
1786}
1787
Mauro Carvalho Chehabbfb12e32007-12-11 11:51:53 -03001788static int saa7134_s_input(struct file *file, void *priv, unsigned int i)
Mauro Carvalho Chehab90bdc142007-12-07 17:23:38 -03001789{
1790 struct saa7134_fh *fh = priv;
1791 struct saa7134_dev *dev = fh->dev;
1792
Roel Kluinde81c3c2009-07-02 16:09:25 -03001793 if (i >= SAA7134_INPUT_MAX)
Mauro Carvalho Chehab90bdc142007-12-07 17:23:38 -03001794 return -EINVAL;
1795 if (NULL == card_in(dev, i).name)
1796 return -EINVAL;
1797 mutex_lock(&dev->lock);
1798 video_mux(dev, i);
1799 mutex_unlock(&dev->lock);
1800 return 0;
1801}
1802
Mauro Carvalho Chehabbfb12e32007-12-11 11:51:53 -03001803static int saa7134_querycap(struct file *file, void *priv,
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03001804 struct v4l2_capability *cap)
1805{
1806 struct saa7134_fh *fh = priv;
1807 struct saa7134_dev *dev = fh->dev;
Ondrej Zaryc3b3e0c2013-02-01 20:01:14 -03001808 struct video_device *vdev = video_devdata(file);
1809 u32 radio_caps, video_caps, vbi_caps;
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03001810
1811 unsigned int tuner_type = dev->tuner_type;
1812
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03001813 strcpy(cap->driver, "saa7134");
1814 strlcpy(cap->card, saa7134_boards[dev->board].name,
1815 sizeof(cap->card));
1816 sprintf(cap->bus_info, "PCI:%s", pci_name(dev->pci));
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03001817
Ondrej Zaryc3b3e0c2013-02-01 20:01:14 -03001818 cap->device_caps = V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
1819 if ((tuner_type != TUNER_ABSENT) && (tuner_type != UNSET))
1820 cap->device_caps |= V4L2_CAP_TUNER;
1821
1822 radio_caps = V4L2_CAP_RADIO;
1823 if (dev->has_rds)
1824 radio_caps |= V4L2_CAP_RDS_CAPTURE;
1825
1826 video_caps = V4L2_CAP_VIDEO_CAPTURE;
1827 if (saa7134_no_overlay <= 0)
1828 video_caps |= V4L2_CAP_VIDEO_OVERLAY;
1829
1830 vbi_caps = V4L2_CAP_VBI_CAPTURE;
1831
1832 switch (vdev->vfl_type) {
1833 case VFL_TYPE_RADIO:
1834 cap->device_caps |= radio_caps;
1835 break;
1836 case VFL_TYPE_GRABBER:
1837 cap->device_caps |= video_caps;
1838 break;
1839 case VFL_TYPE_VBI:
1840 cap->device_caps |= vbi_caps;
1841 break;
1842 }
1843 cap->capabilities = radio_caps | video_caps | vbi_caps |
1844 cap->device_caps | V4L2_CAP_DEVICE_CAPS;
1845 if (vdev->vfl_type == VFL_TYPE_RADIO) {
1846 cap->device_caps &= ~V4L2_CAP_STREAMING;
1847 if (!dev->has_rds)
1848 cap->device_caps &= ~V4L2_CAP_READWRITE;
1849 }
1850
Julia Lawall473d8022010-08-05 17:22:44 -03001851 return 0;
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03001852}
1853
Hans Verkuil314527a2013-03-15 06:10:40 -03001854int saa7134_s_std_internal(struct saa7134_dev *dev, struct saa7134_fh *fh, v4l2_std_id id)
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03001855{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 unsigned long flags;
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03001857 unsigned int i;
1858 v4l2_std_id fixup;
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03001859
Ondrej Zary3bbaa3a2013-02-01 20:01:16 -03001860 if (!fh && res_locked(dev, RESOURCE_OVERLAY)) {
Hans Verkuil9afb7372008-09-06 06:34:44 -03001861 /* Don't change the std from the mpeg device
1862 if overlay is active. */
1863 return -EBUSY;
1864 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03001866 for (i = 0; i < TVNORMS; i++)
Hans Verkuil314527a2013-03-15 06:10:40 -03001867 if (id == tvnorms[i].id)
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03001868 break;
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03001869
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03001870 if (i == TVNORMS)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 for (i = 0; i < TVNORMS; i++)
Hans Verkuil314527a2013-03-15 06:10:40 -03001872 if (id & tvnorms[i].id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 break;
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03001874 if (i == TVNORMS)
1875 return -EINVAL;
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03001876
Hans Verkuil314527a2013-03-15 06:10:40 -03001877 if ((id & V4L2_STD_SECAM) && (secam[0] != '-')) {
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03001878 if (secam[0] == 'L' || secam[0] == 'l') {
1879 if (secam[1] == 'C' || secam[1] == 'c')
1880 fixup = V4L2_STD_SECAM_LC;
1881 else
1882 fixup = V4L2_STD_SECAM_L;
1883 } else {
1884 if (secam[0] == 'D' || secam[0] == 'd')
1885 fixup = V4L2_STD_SECAM_DK;
1886 else
1887 fixup = V4L2_STD_SECAM;
Hartmut Hackmann17b10a72006-10-02 19:55:07 -03001888 }
Dan Carpenter06e65882010-10-04 16:28:01 -03001889 for (i = 0; i < TVNORMS; i++) {
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03001890 if (fixup == tvnorms[i].id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 break;
Dan Carpenter06e65882010-10-04 16:28:01 -03001892 }
1893 if (i == TVNORMS)
1894 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895 }
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03001896
Hans Verkuil314527a2013-03-15 06:10:40 -03001897 id = tvnorms[i].id;
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03001898
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03001899 mutex_lock(&dev->lock);
Hans Verkuil9afb7372008-09-06 06:34:44 -03001900 if (fh && res_check(fh, RESOURCE_OVERLAY)) {
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03001901 spin_lock_irqsave(&dev->slock, flags);
1902 stop_preview(dev, fh);
1903 spin_unlock_irqrestore(&dev->slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03001905 set_tvnorm(dev, &tvnorms[i]);
1906
1907 spin_lock_irqsave(&dev->slock, flags);
1908 start_preview(dev, fh);
1909 spin_unlock_irqrestore(&dev->slock, flags);
1910 } else
1911 set_tvnorm(dev, &tvnorms[i]);
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03001912
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03001913 saa7134_tvaudio_do_scan(dev);
1914 mutex_unlock(&dev->lock);
1915 return 0;
1916}
Hans Verkuil9afb7372008-09-06 06:34:44 -03001917EXPORT_SYMBOL_GPL(saa7134_s_std_internal);
1918
Hans Verkuil314527a2013-03-15 06:10:40 -03001919static int saa7134_s_std(struct file *file, void *priv, v4l2_std_id id)
Hans Verkuil9afb7372008-09-06 06:34:44 -03001920{
1921 struct saa7134_fh *fh = priv;
1922
1923 return saa7134_s_std_internal(fh->dev, fh, id);
1924}
1925
1926static int saa7134_g_std(struct file *file, void *priv, v4l2_std_id *id)
1927{
1928 struct saa7134_fh *fh = priv;
1929 struct saa7134_dev *dev = fh->dev;
1930
1931 *id = dev->tvnorm->id;
1932 return 0;
1933}
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03001934
Mauro Carvalho Chehabbfb12e32007-12-11 11:51:53 -03001935static int saa7134_cropcap(struct file *file, void *priv,
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03001936 struct v4l2_cropcap *cap)
1937{
1938 struct saa7134_fh *fh = priv;
1939 struct saa7134_dev *dev = fh->dev;
1940
1941 if (cap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
1942 cap->type != V4L2_BUF_TYPE_VIDEO_OVERLAY)
1943 return -EINVAL;
1944 cap->bounds = dev->crop_bounds;
1945 cap->defrect = dev->crop_defrect;
1946 cap->pixelaspect.numerator = 1;
1947 cap->pixelaspect.denominator = 1;
1948 if (dev->tvnorm->id & V4L2_STD_525_60) {
1949 cap->pixelaspect.numerator = 11;
1950 cap->pixelaspect.denominator = 10;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 }
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03001952 if (dev->tvnorm->id & V4L2_STD_625_50) {
1953 cap->pixelaspect.numerator = 54;
1954 cap->pixelaspect.denominator = 59;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955 }
1956 return 0;
1957}
1958
Mauro Carvalho Chehabbfb12e32007-12-11 11:51:53 -03001959static int saa7134_g_crop(struct file *file, void *f, struct v4l2_crop *crop)
Mauro Carvalho Chehab90bdc142007-12-07 17:23:38 -03001960{
1961 struct saa7134_fh *fh = f;
1962 struct saa7134_dev *dev = fh->dev;
1963
1964 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
1965 crop->type != V4L2_BUF_TYPE_VIDEO_OVERLAY)
1966 return -EINVAL;
1967 crop->c = dev->crop_current;
1968 return 0;
1969}
1970
Hans Verkuil4f9965942012-09-05 05:10:48 -03001971static int saa7134_s_crop(struct file *file, void *f, const struct v4l2_crop *crop)
Mauro Carvalho Chehab90bdc142007-12-07 17:23:38 -03001972{
1973 struct saa7134_fh *fh = f;
1974 struct saa7134_dev *dev = fh->dev;
1975 struct v4l2_rect *b = &dev->crop_bounds;
Hans Verkuil4f9965942012-09-05 05:10:48 -03001976 struct v4l2_rect *c = &dev->crop_current;
Mauro Carvalho Chehab90bdc142007-12-07 17:23:38 -03001977
1978 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
1979 crop->type != V4L2_BUF_TYPE_VIDEO_OVERLAY)
1980 return -EINVAL;
1981 if (crop->c.height < 0)
1982 return -EINVAL;
1983 if (crop->c.width < 0)
1984 return -EINVAL;
1985
1986 if (res_locked(fh->dev, RESOURCE_OVERLAY))
1987 return -EBUSY;
1988 if (res_locked(fh->dev, RESOURCE_VIDEO))
1989 return -EBUSY;
1990
Hans Verkuil4f9965942012-09-05 05:10:48 -03001991 *c = crop->c;
1992 if (c->top < b->top)
1993 c->top = b->top;
1994 if (c->top > b->top + b->height)
1995 c->top = b->top + b->height;
1996 if (c->height > b->top - c->top + b->height)
1997 c->height = b->top - c->top + b->height;
Mauro Carvalho Chehab90bdc142007-12-07 17:23:38 -03001998
Hans Verkuil4f9965942012-09-05 05:10:48 -03001999 if (c->left < b->left)
2000 c->left = b->left;
2001 if (c->left > b->left + b->width)
2002 c->left = b->left + b->width;
2003 if (c->width > b->left - c->left + b->width)
2004 c->width = b->left - c->left + b->width;
Mauro Carvalho Chehab90bdc142007-12-07 17:23:38 -03002005 return 0;
2006}
2007
Mauro Carvalho Chehabbfb12e32007-12-11 11:51:53 -03002008static int saa7134_g_tuner(struct file *file, void *priv,
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03002009 struct v4l2_tuner *t)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010{
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03002011 struct saa7134_fh *fh = priv;
2012 struct saa7134_dev *dev = fh->dev;
2013 int n;
2014
2015 if (0 != t->index)
2016 return -EINVAL;
2017 memset(t, 0, sizeof(*t));
Dan Carpenter06e65882010-10-04 16:28:01 -03002018 for (n = 0; n < SAA7134_INPUT_MAX; n++) {
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03002019 if (card_in(dev, n).tv)
2020 break;
Dan Carpenter06e65882010-10-04 16:28:01 -03002021 }
2022 if (n == SAA7134_INPUT_MAX)
2023 return -EINVAL;
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03002024 if (NULL != card_in(dev, n).name) {
2025 strcpy(t->name, "Television");
2026 t->type = V4L2_TUNER_ANALOG_TV;
Ondrej Zaryce5bdd52013-02-01 20:01:18 -03002027 saa_call_all(dev, tuner, g_tuner, t);
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03002028 t->capability = V4L2_TUNER_CAP_NORM |
2029 V4L2_TUNER_CAP_STEREO |
2030 V4L2_TUNER_CAP_LANG1 |
2031 V4L2_TUNER_CAP_LANG2;
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03002032 t->rxsubchans = saa7134_tvaudio_getstereo(dev);
2033 t->audmode = saa7134_tvaudio_rx2mode(t->rxsubchans);
2034 }
2035 if (0 != (saa_readb(SAA7134_STATUS_VIDEO1) & 0x03))
2036 t->signal = 0xffff;
2037 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038}
2039
Mauro Carvalho Chehabbfb12e32007-12-11 11:51:53 -03002040static int saa7134_s_tuner(struct file *file, void *priv,
Hans Verkuil2f73c7c2013-03-15 06:10:06 -03002041 const struct v4l2_tuner *t)
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03002042{
2043 struct saa7134_fh *fh = priv;
2044 struct saa7134_dev *dev = fh->dev;
Ondrej Zary3bbaa3a2013-02-01 20:01:16 -03002045 int rx, mode;
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03002046
Ondrej Zaryce5bdd52013-02-01 20:01:18 -03002047 if (0 != t->index)
2048 return -EINVAL;
2049
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03002050 mode = dev->thread.mode;
2051 if (UNSET == mode) {
2052 rx = saa7134_tvaudio_getstereo(dev);
Hans Verkuile92ba282012-05-14 10:17:35 -03002053 mode = saa7134_tvaudio_rx2mode(rx);
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03002054 }
2055 if (mode != t->audmode)
2056 dev->thread.mode = t->audmode;
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03002057
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03002058 return 0;
2059}
2060
Mauro Carvalho Chehabbfb12e32007-12-11 11:51:53 -03002061static int saa7134_g_frequency(struct file *file, void *priv,
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03002062 struct v4l2_frequency *f)
2063{
2064 struct saa7134_fh *fh = priv;
2065 struct saa7134_dev *dev = fh->dev;
2066
Ondrej Zary0a5ea882013-02-01 20:01:17 -03002067 if (0 != f->tuner)
2068 return -EINVAL;
2069
Ondrej Zary0a5ea882013-02-01 20:01:17 -03002070 saa_call_all(dev, tuner, g_frequency, f);
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03002071
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03002072 return 0;
2073}
2074
Mauro Carvalho Chehabbfb12e32007-12-11 11:51:53 -03002075static int saa7134_s_frequency(struct file *file, void *priv,
Hans Verkuilb530a442013-03-19 04:09:26 -03002076 const struct v4l2_frequency *f)
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03002077{
2078 struct saa7134_fh *fh = priv;
2079 struct saa7134_dev *dev = fh->dev;
2080
2081 if (0 != f->tuner)
2082 return -EINVAL;
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03002083 mutex_lock(&dev->lock);
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03002084
Hans Verkuilfac69862009-01-17 12:17:14 -03002085 saa_call_all(dev, tuner, s_frequency, f);
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03002086
2087 saa7134_tvaudio_do_scan(dev);
2088 mutex_unlock(&dev->lock);
2089 return 0;
2090}
2091
Hans Verkuil78b526a2008-05-28 12:16:41 -03002092static int saa7134_enum_fmt_vid_cap(struct file *file, void *priv,
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03002093 struct v4l2_fmtdesc *f)
2094{
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03002095 if (f->index >= FORMATS)
2096 return -EINVAL;
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03002097
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03002098 strlcpy(f->description, formats[f->index].name,
2099 sizeof(f->description));
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03002100
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03002101 f->pixelformat = formats[f->index].fourcc;
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03002102
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03002103 return 0;
2104}
2105
Hans Verkuil78b526a2008-05-28 12:16:41 -03002106static int saa7134_enum_fmt_vid_overlay(struct file *file, void *priv,
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03002107 struct v4l2_fmtdesc *f)
2108{
2109 if (saa7134_no_overlay > 0) {
2110 printk(KERN_ERR "V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n");
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03002111 return -EINVAL;
2112 }
Mauro Carvalho Chehab8c854542007-12-07 17:34:48 -03002113
2114 if ((f->index >= FORMATS) || formats[f->index].planar)
2115 return -EINVAL;
2116
2117 strlcpy(f->description, formats[f->index].name,
2118 sizeof(f->description));
2119
2120 f->pixelformat = formats[f->index].fourcc;
2121
2122 return 0;
2123}
2124
Mauro Carvalho Chehabbfb12e32007-12-11 11:51:53 -03002125static int saa7134_g_fbuf(struct file *file, void *f,
Mauro Carvalho Chehab90bdc142007-12-07 17:23:38 -03002126 struct v4l2_framebuffer *fb)
2127{
2128 struct saa7134_fh *fh = f;
2129 struct saa7134_dev *dev = fh->dev;
2130
2131 *fb = dev->ovbuf;
2132 fb->capability = V4L2_FBUF_CAP_LIST_CLIPPING;
2133
2134 return 0;
2135}
2136
Mauro Carvalho Chehabbfb12e32007-12-11 11:51:53 -03002137static int saa7134_s_fbuf(struct file *file, void *f,
Hans Verkuile6eb28c2012-09-04 10:26:45 -03002138 const struct v4l2_framebuffer *fb)
Mauro Carvalho Chehab90bdc142007-12-07 17:23:38 -03002139{
2140 struct saa7134_fh *fh = f;
2141 struct saa7134_dev *dev = fh->dev;
2142 struct saa7134_format *fmt;
2143
2144 if (!capable(CAP_SYS_ADMIN) &&
2145 !capable(CAP_SYS_RAWIO))
2146 return -EPERM;
2147
2148 /* check args */
2149 fmt = format_by_fourcc(fb->fmt.pixelformat);
2150 if (NULL == fmt)
2151 return -EINVAL;
2152
2153 /* ok, accept it */
2154 dev->ovbuf = *fb;
2155 dev->ovfmt = fmt;
2156 if (0 == dev->ovbuf.fmt.bytesperline)
2157 dev->ovbuf.fmt.bytesperline =
2158 dev->ovbuf.fmt.width*fmt->depth/8;
2159 return 0;
2160}
2161
Mauro Carvalho Chehabbfb12e32007-12-11 11:51:53 -03002162static int saa7134_overlay(struct file *file, void *f, unsigned int on)
Mauro Carvalho Chehab90bdc142007-12-07 17:23:38 -03002163{
2164 struct saa7134_fh *fh = f;
2165 struct saa7134_dev *dev = fh->dev;
2166 unsigned long flags;
2167
2168 if (on) {
2169 if (saa7134_no_overlay > 0) {
2170 dprintk("no_overlay\n");
2171 return -EINVAL;
2172 }
2173
2174 if (!res_get(dev, fh, RESOURCE_OVERLAY))
2175 return -EBUSY;
2176 spin_lock_irqsave(&dev->slock, flags);
2177 start_preview(dev, fh);
2178 spin_unlock_irqrestore(&dev->slock, flags);
2179 }
2180 if (!on) {
2181 if (!res_check(fh, RESOURCE_OVERLAY))
2182 return -EINVAL;
2183 spin_lock_irqsave(&dev->slock, flags);
2184 stop_preview(dev, fh);
2185 spin_unlock_irqrestore(&dev->slock, flags);
2186 res_free(dev, fh, RESOURCE_OVERLAY);
2187 }
2188 return 0;
2189}
2190
Mauro Carvalho Chehabbfb12e32007-12-11 11:51:53 -03002191static int saa7134_reqbufs(struct file *file, void *priv,
Mauro Carvalho Chehab90bdc142007-12-07 17:23:38 -03002192 struct v4l2_requestbuffers *p)
2193{
Hans Verkuil8fcd4762013-05-31 07:57:10 -03002194 return videobuf_reqbufs(saa7134_queue(file), p);
Mauro Carvalho Chehab90bdc142007-12-07 17:23:38 -03002195}
2196
Mauro Carvalho Chehabbfb12e32007-12-11 11:51:53 -03002197static int saa7134_querybuf(struct file *file, void *priv,
Mauro Carvalho Chehab90bdc142007-12-07 17:23:38 -03002198 struct v4l2_buffer *b)
2199{
Hans Verkuil8fcd4762013-05-31 07:57:10 -03002200 return videobuf_querybuf(saa7134_queue(file), b);
Mauro Carvalho Chehab90bdc142007-12-07 17:23:38 -03002201}
2202
Mauro Carvalho Chehabbfb12e32007-12-11 11:51:53 -03002203static int saa7134_qbuf(struct file *file, void *priv, struct v4l2_buffer *b)
Mauro Carvalho Chehab90bdc142007-12-07 17:23:38 -03002204{
Hans Verkuil8fcd4762013-05-31 07:57:10 -03002205 return videobuf_qbuf(saa7134_queue(file), b);
Mauro Carvalho Chehab90bdc142007-12-07 17:23:38 -03002206}
2207
Mauro Carvalho Chehabbfb12e32007-12-11 11:51:53 -03002208static int saa7134_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b)
Mauro Carvalho Chehab90bdc142007-12-07 17:23:38 -03002209{
Hans Verkuil8fcd4762013-05-31 07:57:10 -03002210 return videobuf_dqbuf(saa7134_queue(file), b,
Mauro Carvalho Chehab90bdc142007-12-07 17:23:38 -03002211 file->f_flags & O_NONBLOCK);
2212}
2213
Mauro Carvalho Chehabbfb12e32007-12-11 11:51:53 -03002214static int saa7134_streamon(struct file *file, void *priv,
Mauro Carvalho Chehab90bdc142007-12-07 17:23:38 -03002215 enum v4l2_buf_type type)
2216{
2217 struct saa7134_fh *fh = priv;
2218 struct saa7134_dev *dev = fh->dev;
Hans Verkuil8fcd4762013-05-31 07:57:10 -03002219 int res = saa7134_resource(file);
Mauro Carvalho Chehab90bdc142007-12-07 17:23:38 -03002220
2221 if (!res_get(dev, fh, res))
2222 return -EBUSY;
2223
Simon Farnsworth87739862012-12-10 08:35:09 -03002224 /* The SAA7134 has a 1K FIFO; the datasheet suggests that when
2225 * configured conservatively, there's 22 usec of buffering for video.
2226 * We therefore request a DMA latency of 20 usec, giving us 2 usec of
2227 * margin in case the FIFO is configured differently to the datasheet.
2228 * Unfortunately, I lack register-level documentation to check the
2229 * Linux FIFO setup and confirm the perfect value.
2230 */
Hans Verkuil89f3a142013-05-31 08:44:58 -03002231 pm_qos_add_request(&dev->qos_request,
Simon Farnsworth87739862012-12-10 08:35:09 -03002232 PM_QOS_CPU_DMA_LATENCY,
2233 20);
2234
Hans Verkuil8fcd4762013-05-31 07:57:10 -03002235 return videobuf_streamon(saa7134_queue(file));
Mauro Carvalho Chehab90bdc142007-12-07 17:23:38 -03002236}
2237
Mauro Carvalho Chehabbfb12e32007-12-11 11:51:53 -03002238static int saa7134_streamoff(struct file *file, void *priv,
Mauro Carvalho Chehab90bdc142007-12-07 17:23:38 -03002239 enum v4l2_buf_type type)
2240{
2241 int err;
2242 struct saa7134_fh *fh = priv;
2243 struct saa7134_dev *dev = fh->dev;
Hans Verkuil8fcd4762013-05-31 07:57:10 -03002244 int res = saa7134_resource(file);
Mauro Carvalho Chehab90bdc142007-12-07 17:23:38 -03002245
Hans Verkuil89f3a142013-05-31 08:44:58 -03002246 pm_qos_remove_request(&dev->qos_request);
Simon Farnsworth87739862012-12-10 08:35:09 -03002247
Hans Verkuil8fcd4762013-05-31 07:57:10 -03002248 err = videobuf_streamoff(saa7134_queue(file));
Mauro Carvalho Chehab90bdc142007-12-07 17:23:38 -03002249 if (err < 0)
2250 return err;
2251 res_free(dev, fh, res);
2252 return 0;
2253}
2254
Mauro Carvalho Chehabc121ba12008-06-16 12:31:57 -03002255#ifdef CONFIG_VIDEO_ADV_DEBUG
2256static int vidioc_g_register (struct file *file, void *priv,
Hans Verkuilaecde8b2008-12-30 07:14:19 -03002257 struct v4l2_dbg_register *reg)
Mauro Carvalho Chehabc121ba12008-06-16 12:31:57 -03002258{
2259 struct saa7134_fh *fh = priv;
2260 struct saa7134_dev *dev = fh->dev;
2261
Hans Verkuilb8300702013-05-29 06:59:59 -03002262 reg->val = saa_readb(reg->reg & 0xffffff);
Hans Verkuilaecde8b2008-12-30 07:14:19 -03002263 reg->size = 1;
Mauro Carvalho Chehabc121ba12008-06-16 12:31:57 -03002264 return 0;
2265}
2266
2267static int vidioc_s_register (struct file *file, void *priv,
Hans Verkuil977ba3b2013-03-24 08:28:46 -03002268 const struct v4l2_dbg_register *reg)
Mauro Carvalho Chehabc121ba12008-06-16 12:31:57 -03002269{
2270 struct saa7134_fh *fh = priv;
2271 struct saa7134_dev *dev = fh->dev;
2272
Hans Verkuilb8300702013-05-29 06:59:59 -03002273 saa_writeb(reg->reg & 0xffffff, reg->val);
Mauro Carvalho Chehabc121ba12008-06-16 12:31:57 -03002274 return 0;
2275}
2276#endif
2277
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03002278static int radio_g_tuner(struct file *file, void *priv,
2279 struct v4l2_tuner *t)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280{
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03002281 struct saa7134_fh *fh = file->private_data;
2282 struct saa7134_dev *dev = fh->dev;
2283
2284 if (0 != t->index)
2285 return -EINVAL;
2286
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03002287 strcpy(t->name, "Radio");
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03002288
Hans Verkuilfac69862009-01-17 12:17:14 -03002289 saa_call_all(dev, tuner, g_tuner, t);
Ondrej Zary82456702013-02-01 20:01:15 -03002290 t->audmode &= V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO;
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03002291 if (dev->input->amux == TV) {
2292 t->signal = 0xf800 - ((saa_readb(0x581) & 0x1f) << 11);
2293 t->rxsubchans = (saa_readb(0x529) & 0x08) ?
2294 V4L2_TUNER_SUB_STEREO : V4L2_TUNER_SUB_MONO;
2295 }
2296 return 0;
2297}
2298static int radio_s_tuner(struct file *file, void *priv,
Hans Verkuil2f73c7c2013-03-15 06:10:06 -03002299 const struct v4l2_tuner *t)
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03002300{
2301 struct saa7134_fh *fh = file->private_data;
2302 struct saa7134_dev *dev = fh->dev;
2303
2304 if (0 != t->index)
2305 return -EINVAL;
2306
Hans Verkuilfac69862009-01-17 12:17:14 -03002307 saa_call_all(dev, tuner, s_tuner, t);
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03002308 return 0;
2309}
2310
2311static int radio_enum_input(struct file *file, void *priv,
2312 struct v4l2_input *i)
2313{
2314 if (i->index != 0)
2315 return -EINVAL;
2316
2317 strcpy(i->name, "Radio");
2318 i->type = V4L2_INPUT_TYPE_TUNER;
2319
2320 return 0;
2321}
2322
2323static int radio_g_input(struct file *filp, void *priv, unsigned int *i)
2324{
2325 *i = 0;
2326 return 0;
2327}
2328
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03002329static int radio_s_input(struct file *filp, void *priv, unsigned int i)
2330{
2331 return 0;
2332}
2333
Hans Verkuil314527a2013-03-15 06:10:40 -03002334static int radio_s_std(struct file *file, void *fh, v4l2_std_id norm)
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03002335{
2336 return 0;
2337}
2338
2339static int radio_queryctrl(struct file *file, void *priv,
2340 struct v4l2_queryctrl *c)
2341{
2342 const struct v4l2_queryctrl *ctrl;
2343
2344 if (c->id < V4L2_CID_BASE ||
2345 c->id >= V4L2_CID_LASTP1)
2346 return -EINVAL;
2347 if (c->id == V4L2_CID_AUDIO_MUTE) {
2348 ctrl = ctrl_by_id(c->id);
2349 *c = *ctrl;
2350 } else
2351 *c = no_ctrl;
2352 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353}
2354
Hans Verkuilbec43662008-12-30 06:58:20 -03002355static const struct v4l2_file_operations video_fops =
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356{
2357 .owner = THIS_MODULE,
2358 .open = video_open,
2359 .release = video_release,
2360 .read = video_read,
2361 .poll = video_poll,
2362 .mmap = video_mmap,
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03002363 .ioctl = video_ioctl2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364};
2365
Hans Verkuila3998102008-07-21 02:57:38 -03002366static const struct v4l2_ioctl_ops video_ioctl_ops = {
Mauro Carvalho Chehabbfb12e32007-12-11 11:51:53 -03002367 .vidioc_querycap = saa7134_querycap,
Hans Verkuil78b526a2008-05-28 12:16:41 -03002368 .vidioc_enum_fmt_vid_cap = saa7134_enum_fmt_vid_cap,
2369 .vidioc_g_fmt_vid_cap = saa7134_g_fmt_vid_cap,
2370 .vidioc_try_fmt_vid_cap = saa7134_try_fmt_vid_cap,
2371 .vidioc_s_fmt_vid_cap = saa7134_s_fmt_vid_cap,
2372 .vidioc_enum_fmt_vid_overlay = saa7134_enum_fmt_vid_overlay,
2373 .vidioc_g_fmt_vid_overlay = saa7134_g_fmt_vid_overlay,
2374 .vidioc_try_fmt_vid_overlay = saa7134_try_fmt_vid_overlay,
2375 .vidioc_s_fmt_vid_overlay = saa7134_s_fmt_vid_overlay,
Hans Verkuil78b526a2008-05-28 12:16:41 -03002376 .vidioc_g_fmt_vbi_cap = saa7134_try_get_set_fmt_vbi_cap,
2377 .vidioc_try_fmt_vbi_cap = saa7134_try_get_set_fmt_vbi_cap,
2378 .vidioc_s_fmt_vbi_cap = saa7134_try_get_set_fmt_vbi_cap,
Mauro Carvalho Chehabbfb12e32007-12-11 11:51:53 -03002379 .vidioc_cropcap = saa7134_cropcap,
2380 .vidioc_reqbufs = saa7134_reqbufs,
2381 .vidioc_querybuf = saa7134_querybuf,
2382 .vidioc_qbuf = saa7134_qbuf,
2383 .vidioc_dqbuf = saa7134_dqbuf,
2384 .vidioc_s_std = saa7134_s_std,
Hans Verkuil9afb7372008-09-06 06:34:44 -03002385 .vidioc_g_std = saa7134_g_std,
Mauro Carvalho Chehabbfb12e32007-12-11 11:51:53 -03002386 .vidioc_enum_input = saa7134_enum_input,
2387 .vidioc_g_input = saa7134_g_input,
2388 .vidioc_s_input = saa7134_s_input,
2389 .vidioc_queryctrl = saa7134_queryctrl,
2390 .vidioc_g_ctrl = saa7134_g_ctrl,
2391 .vidioc_s_ctrl = saa7134_s_ctrl,
2392 .vidioc_streamon = saa7134_streamon,
2393 .vidioc_streamoff = saa7134_streamoff,
2394 .vidioc_g_tuner = saa7134_g_tuner,
2395 .vidioc_s_tuner = saa7134_s_tuner,
Mauro Carvalho Chehabbfb12e32007-12-11 11:51:53 -03002396 .vidioc_g_crop = saa7134_g_crop,
2397 .vidioc_s_crop = saa7134_s_crop,
2398 .vidioc_g_fbuf = saa7134_g_fbuf,
2399 .vidioc_s_fbuf = saa7134_s_fbuf,
2400 .vidioc_overlay = saa7134_overlay,
Mauro Carvalho Chehabbfb12e32007-12-11 11:51:53 -03002401 .vidioc_g_frequency = saa7134_g_frequency,
2402 .vidioc_s_frequency = saa7134_s_frequency,
Mauro Carvalho Chehabc121ba12008-06-16 12:31:57 -03002403#ifdef CONFIG_VIDEO_ADV_DEBUG
2404 .vidioc_g_register = vidioc_g_register,
2405 .vidioc_s_register = vidioc_s_register,
2406#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407};
2408
Hans Verkuilbec43662008-12-30 06:58:20 -03002409static const struct v4l2_file_operations radio_fops = {
Hans Verkuila3998102008-07-21 02:57:38 -03002410 .owner = THIS_MODULE,
2411 .open = video_open,
Hans Verkuil2983baf2009-03-29 06:26:27 -03002412 .read = radio_read,
Hans Verkuila3998102008-07-21 02:57:38 -03002413 .release = video_release,
2414 .ioctl = video_ioctl2,
Hans Verkuil2983baf2009-03-29 06:26:27 -03002415 .poll = radio_poll,
Hans Verkuila3998102008-07-21 02:57:38 -03002416};
2417
2418static const struct v4l2_ioctl_ops radio_ioctl_ops = {
Ondrej Zaryc3b3e0c2013-02-01 20:01:14 -03002419 .vidioc_querycap = saa7134_querycap,
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03002420 .vidioc_g_tuner = radio_g_tuner,
2421 .vidioc_enum_input = radio_enum_input,
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03002422 .vidioc_s_tuner = radio_s_tuner,
Douglas Schilling Landgraf8f61ae22007-12-07 17:09:53 -03002423 .vidioc_s_input = radio_s_input,
2424 .vidioc_s_std = radio_s_std,
2425 .vidioc_queryctrl = radio_queryctrl,
2426 .vidioc_g_input = radio_g_input,
Mauro Carvalho Chehabbfb12e32007-12-11 11:51:53 -03002427 .vidioc_g_ctrl = saa7134_g_ctrl,
2428 .vidioc_s_ctrl = saa7134_s_ctrl,
2429 .vidioc_g_frequency = saa7134_g_frequency,
2430 .vidioc_s_frequency = saa7134_s_frequency,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431};
2432
Hans Verkuila3998102008-07-21 02:57:38 -03002433/* ----------------------------------------------------------- */
2434/* exported stuff */
2435
2436struct video_device saa7134_video_template = {
2437 .name = "saa7134-video",
Hans Verkuila3998102008-07-21 02:57:38 -03002438 .fops = &video_fops,
2439 .ioctl_ops = &video_ioctl_ops,
Hans Verkuila3998102008-07-21 02:57:38 -03002440 .tvnorms = SAA7134_NORMS,
Hans Verkuila3998102008-07-21 02:57:38 -03002441};
2442
2443struct video_device saa7134_radio_template = {
2444 .name = "saa7134-radio",
Hans Verkuila3998102008-07-21 02:57:38 -03002445 .fops = &radio_fops,
2446 .ioctl_ops = &radio_ioctl_ops,
Hans Verkuila3998102008-07-21 02:57:38 -03002447};
2448
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449int saa7134_video_init1(struct saa7134_dev *dev)
2450{
2451 /* sanitycheck insmod options */
2452 if (gbuffers < 2 || gbuffers > VIDEO_MAX_FRAME)
2453 gbuffers = 2;
Mauro Carvalho Chehab3eeba4a2012-10-27 16:20:27 -03002454 if (gbufsize > gbufsize_max)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 gbufsize = gbufsize_max;
2456 gbufsize = (gbufsize + PAGE_SIZE - 1) & PAGE_MASK;
2457
2458 /* put some sensible defaults into the data structures ... */
2459 dev->ctl_bright = ctrl_by_id(V4L2_CID_BRIGHTNESS)->default_value;
2460 dev->ctl_contrast = ctrl_by_id(V4L2_CID_CONTRAST)->default_value;
2461 dev->ctl_hue = ctrl_by_id(V4L2_CID_HUE)->default_value;
2462 dev->ctl_saturation = ctrl_by_id(V4L2_CID_SATURATION)->default_value;
2463 dev->ctl_volume = ctrl_by_id(V4L2_CID_AUDIO_VOLUME)->default_value;
2464 dev->ctl_mute = 1; // ctrl_by_id(V4L2_CID_AUDIO_MUTE)->default_value;
2465 dev->ctl_invert = ctrl_by_id(V4L2_CID_PRIVATE_INVERT)->default_value;
2466 dev->ctl_automute = ctrl_by_id(V4L2_CID_PRIVATE_AUTOMUTE)->default_value;
2467
2468 if (dev->tda9887_conf && dev->ctl_automute)
2469 dev->tda9887_conf |= TDA9887_AUTOMUTE;
2470 dev->automute = 0;
2471
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -08002472 INIT_LIST_HEAD(&dev->video_q.queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473 init_timer(&dev->video_q.timeout);
2474 dev->video_q.timeout.function = saa7134_buffer_timeout;
2475 dev->video_q.timeout.data = (unsigned long)(&dev->video_q);
2476 dev->video_q.dev = dev;
Hans Verkuil813b9df2013-05-31 08:30:49 -03002477 dev->fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24);
2478 dev->width = 720;
2479 dev->height = 576;
Hans Verkuil3a0a5a72013-05-31 11:48:50 -03002480 dev->win.w.width = dev->width;
2481 dev->win.w.height = dev->height;
2482 dev->win.field = V4L2_FIELD_INTERLACED;
2483 dev->ovbuf.fmt.width = dev->width;
2484 dev->ovbuf.fmt.height = dev->height;
2485 dev->ovbuf.fmt.pixelformat = dev->fmt->fourcc;
2486 dev->ovbuf.fmt.colorspace = V4L2_COLORSPACE_SMPTE170M;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487
Maxim Levitskycb712012007-09-27 20:34:25 -03002488 if (saa7134_boards[dev->board].video_out)
2489 saa7134_videoport_init(dev);
2490
2491 return 0;
2492}
2493
2494int saa7134_videoport_init(struct saa7134_dev *dev)
2495{
2496 /* enable video output */
2497 int vo = saa7134_boards[dev->board].video_out;
2498 int video_reg;
2499 unsigned int vid_port_opts = saa7134_boards[dev->board].vid_port_opts;
Dmitry Belimov37df96d2008-06-10 12:43:58 -03002500
2501 /* Configure videoport */
Maxim Levitskycb712012007-09-27 20:34:25 -03002502 saa_writeb(SAA7134_VIDEO_PORT_CTRL0, video_out[vo][0]);
2503 video_reg = video_out[vo][1];
2504 if (vid_port_opts & SET_T_CODE_POLARITY_NON_INVERTED)
2505 video_reg &= ~VP_T_CODE_P_INVERTED;
2506 saa_writeb(SAA7134_VIDEO_PORT_CTRL1, video_reg);
2507 saa_writeb(SAA7134_VIDEO_PORT_CTRL2, video_out[vo][2]);
Maxim Levitskycb712012007-09-27 20:34:25 -03002508 saa_writeb(SAA7134_VIDEO_PORT_CTRL4, video_out[vo][4]);
2509 video_reg = video_out[vo][5];
2510 if (vid_port_opts & SET_CLOCK_NOT_DELAYED)
2511 video_reg &= ~VP_CLK_CTRL2_DELAYED;
2512 if (vid_port_opts & SET_CLOCK_INVERTED)
2513 video_reg |= VP_CLK_CTRL1_INVERTED;
2514 saa_writeb(SAA7134_VIDEO_PORT_CTRL5, video_reg);
2515 video_reg = video_out[vo][6];
2516 if (vid_port_opts & SET_VSYNC_OFF) {
2517 video_reg &= ~VP_VS_TYPE_MASK;
2518 video_reg |= VP_VS_TYPE_OFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519 }
Maxim Levitskycb712012007-09-27 20:34:25 -03002520 saa_writeb(SAA7134_VIDEO_PORT_CTRL6, video_reg);
2521 saa_writeb(SAA7134_VIDEO_PORT_CTRL7, video_out[vo][7]);
2522 saa_writeb(SAA7134_VIDEO_PORT_CTRL8, video_out[vo][8]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523
Dmitry Belimov37df96d2008-06-10 12:43:58 -03002524 /* Start videoport */
2525 saa_writeb(SAA7134_VIDEO_PORT_CTRL3, video_out[vo][3]);
2526
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527 return 0;
2528}
2529
2530int saa7134_video_init2(struct saa7134_dev *dev)
2531{
2532 /* init video hw */
2533 set_tvnorm(dev,&tvnorms[0]);
2534 video_mux(dev,0);
2535 saa7134_tvaudio_setmute(dev);
2536 saa7134_tvaudio_setvolume(dev,dev->ctl_volume);
2537 return 0;
2538}
2539
Maxim Levitsky11f70782007-09-27 20:44:39 -03002540void saa7134_irq_video_signalchange(struct saa7134_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541{
2542 static const char *st[] = {
2543 "(no signal)", "NTSC", "PAL", "SECAM" };
2544 u32 st1,st2;
2545
2546 st1 = saa_readb(SAA7134_STATUS_VIDEO1);
2547 st2 = saa_readb(SAA7134_STATUS_VIDEO2);
2548 dprintk("DCSDT: pll: %s, sync: %s, norm: %s\n",
2549 (st1 & 0x40) ? "not locked" : "locked",
2550 (st2 & 0x40) ? "no" : "yes",
2551 st[st1 & 0x03]);
Maxim Levitsky11f70782007-09-27 20:44:39 -03002552 dev->nosignal = (st1 & 0x40) || (st2 & 0x40) || !(st2 & 0x1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553
2554 if (dev->nosignal) {
2555 /* no video signal -> mute audio */
2556 if (dev->ctl_automute)
2557 dev->automute = 1;
2558 saa7134_tvaudio_setmute(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559 } else {
2560 /* wake up tvaudio audio carrier scan thread */
2561 saa7134_tvaudio_do_scan(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562 }
Maxim Levitsky11f70782007-09-27 20:44:39 -03002563
2564 if ((st2 & 0x80) && !noninterlaced && !dev->nosignal)
2565 saa_clearb(SAA7134_SYNC_CTRL, 0x20);
2566 else
2567 saa_setb(SAA7134_SYNC_CTRL, 0x20);
2568
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569 if (dev->mops && dev->mops->signal_change)
2570 dev->mops->signal_change(dev);
2571}
2572
Maxim Levitsky11f70782007-09-27 20:44:39 -03002573
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574void saa7134_irq_video_done(struct saa7134_dev *dev, unsigned long status)
2575{
2576 enum v4l2_field field;
2577
2578 spin_lock(&dev->slock);
2579 if (dev->video_q.curr) {
2580 dev->video_fieldcount++;
2581 field = dev->video_q.curr->vb.field;
2582 if (V4L2_FIELD_HAS_BOTH(field)) {
2583 /* make sure we have seen both fields */
2584 if ((status & 0x10) == 0x00) {
2585 dev->video_q.curr->top_seen = 1;
2586 goto done;
2587 }
2588 if (!dev->video_q.curr->top_seen)
2589 goto done;
2590 } else if (field == V4L2_FIELD_TOP) {
2591 if ((status & 0x10) != 0x10)
2592 goto done;
2593 } else if (field == V4L2_FIELD_BOTTOM) {
2594 if ((status & 0x10) != 0x00)
2595 goto done;
2596 }
2597 dev->video_q.curr->vb.field_count = dev->video_fieldcount;
Brandon Philips0fc06862007-11-06 20:02:36 -03002598 saa7134_buffer_finish(dev,&dev->video_q,VIDEOBUF_DONE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599 }
2600 saa7134_buffer_next(dev,&dev->video_q);
2601
2602 done:
2603 spin_unlock(&dev->slock);
2604}
2605
2606/* ----------------------------------------------------------- */
2607/*
2608 * Local variables:
2609 * c-basic-offset: 8
2610 * End:
2611 */