blob: 0ddf4dd55308f991dac27348de2c4915c60d88a1 [file] [log] [blame]
Hans Verkuil1c1e45d2008-04-28 20:24:33 -03001/*
2 * cx18 ioctl system call
3 *
4 * Derived from ivtv-ioctl.c
5 *
6 * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl>
Andy Walls1ed9dcc2008-11-22 01:37:34 -03007 * Copyright (C) 2008 Andy Walls <awalls@radix.net>
Hans Verkuil1c1e45d2008-04-28 20:24:33 -03008 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 * 02111-1307 USA
23 */
24
25#include "cx18-driver.h"
Andy Wallsb1526422008-08-30 16:03:44 -030026#include "cx18-io.h"
Hans Verkuil1c1e45d2008-04-28 20:24:33 -030027#include "cx18-version.h"
28#include "cx18-mailbox.h"
29#include "cx18-i2c.h"
30#include "cx18-queue.h"
31#include "cx18-fileops.h"
32#include "cx18-vbi.h"
33#include "cx18-audio.h"
34#include "cx18-video.h"
35#include "cx18-streams.h"
36#include "cx18-ioctl.h"
37#include "cx18-gpio.h"
38#include "cx18-controls.h"
39#include "cx18-cards.h"
40#include "cx18-av-core.h"
41#include <media/tveeprom.h>
42#include <media/v4l2-chip-ident.h>
43#include <linux/i2c-id.h>
44
Mauro Carvalho Chehabaed6abd2008-04-29 21:38:51 -030045u16 cx18_service2vbi(int type)
Hans Verkuil1c1e45d2008-04-28 20:24:33 -030046{
47 switch (type) {
48 case V4L2_SLICED_TELETEXT_B:
49 return CX18_SLICED_TYPE_TELETEXT_B;
50 case V4L2_SLICED_CAPTION_525:
51 return CX18_SLICED_TYPE_CAPTION_525;
52 case V4L2_SLICED_WSS_625:
53 return CX18_SLICED_TYPE_WSS_625;
54 case V4L2_SLICED_VPS:
55 return CX18_SLICED_TYPE_VPS;
56 default:
57 return 0;
58 }
59}
60
Andy Wallsc1994082009-02-05 22:37:49 -030061/* Check if VBI services are allowed on the (field, line) for the video std */
Hans Verkuil1c1e45d2008-04-28 20:24:33 -030062static int valid_service_line(int field, int line, int is_pal)
63{
Andy Wallsc1994082009-02-05 22:37:49 -030064 return (is_pal && line >= 6 &&
65 ((field == 0 && line <= 23) || (field == 1 && line <= 22))) ||
Hans Verkuil1c1e45d2008-04-28 20:24:33 -030066 (!is_pal && line >= 10 && line < 22);
67}
68
Andy Wallsc1994082009-02-05 22:37:49 -030069/*
70 * For a (field, line, std) and inbound potential set of services for that line,
71 * return the first valid service of those passed in the incoming set for that
72 * line in priority order:
73 * CC, VPS, or WSS over TELETEXT for well known lines
74 * TELETEXT, before VPS, before CC, before WSS, for other lines
75 */
Hans Verkuil1c1e45d2008-04-28 20:24:33 -030076static u16 select_service_from_set(int field, int line, u16 set, int is_pal)
77{
78 u16 valid_set = (is_pal ? V4L2_SLICED_VBI_625 : V4L2_SLICED_VBI_525);
79 int i;
80
81 set = set & valid_set;
82 if (set == 0 || !valid_service_line(field, line, is_pal))
83 return 0;
84 if (!is_pal) {
85 if (line == 21 && (set & V4L2_SLICED_CAPTION_525))
86 return V4L2_SLICED_CAPTION_525;
87 } else {
88 if (line == 16 && field == 0 && (set & V4L2_SLICED_VPS))
89 return V4L2_SLICED_VPS;
90 if (line == 23 && field == 0 && (set & V4L2_SLICED_WSS_625))
91 return V4L2_SLICED_WSS_625;
92 if (line == 23)
93 return 0;
94 }
95 for (i = 0; i < 32; i++) {
96 if ((1 << i) & set)
97 return 1 << i;
98 }
99 return 0;
100}
101
Andy Wallsc1994082009-02-05 22:37:49 -0300102/*
103 * Expand the service_set of *fmt into valid service_lines for the std,
104 * and clear the passed in fmt->service_set
105 */
Mauro Carvalho Chehabaed6abd2008-04-29 21:38:51 -0300106void cx18_expand_service_set(struct v4l2_sliced_vbi_format *fmt, int is_pal)
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300107{
108 u16 set = fmt->service_set;
109 int f, l;
110
111 fmt->service_set = 0;
112 for (f = 0; f < 2; f++) {
113 for (l = 0; l < 24; l++)
114 fmt->service_lines[f][l] = select_service_from_set(f, l, set, is_pal);
115 }
116}
117
Andy Wallsc1994082009-02-05 22:37:49 -0300118/*
119 * Sanitize the service_lines in *fmt per the video std, and return 1
120 * if any service_line is left as valid after santization
121 */
Andy Walls302df972009-01-31 00:33:02 -0300122static int check_service_set(struct v4l2_sliced_vbi_format *fmt, int is_pal)
123{
124 int f, l;
125 u16 set = 0;
126
127 for (f = 0; f < 2; f++) {
128 for (l = 0; l < 24; l++) {
129 fmt->service_lines[f][l] = select_service_from_set(f, l, fmt->service_lines[f][l], is_pal);
130 set |= fmt->service_lines[f][l];
131 }
132 }
133 return set != 0;
134}
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300135
Andy Wallsc1994082009-02-05 22:37:49 -0300136/* Compute the service_set from the assumed valid service_lines of *fmt */
Mauro Carvalho Chehabaed6abd2008-04-29 21:38:51 -0300137u16 cx18_get_service_set(struct v4l2_sliced_vbi_format *fmt)
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300138{
139 int f, l;
140 u16 set = 0;
141
142 for (f = 0; f < 2; f++) {
143 for (l = 0; l < 24; l++)
144 set |= fmt->service_lines[f][l];
145 }
146 return set;
147}
148
Andy Walls3b6fe582008-06-21 08:36:31 -0300149static int cx18_g_fmt_vid_cap(struct file *file, void *fh,
150 struct v4l2_format *fmt)
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300151{
Andy Walls3b6fe582008-06-21 08:36:31 -0300152 struct cx18_open_id *id = fh;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300153 struct cx18 *cx = id->cx;
Hans Verkuil0b5a30e2008-06-21 09:22:19 -0300154 struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300155
Hans Verkuil0b5a30e2008-06-21 09:22:19 -0300156 pixfmt->width = cx->params.width;
157 pixfmt->height = cx->params.height;
158 pixfmt->colorspace = V4L2_COLORSPACE_SMPTE170M;
159 pixfmt->field = V4L2_FIELD_INTERLACED;
160 pixfmt->priv = 0;
Andy Walls3b6fe582008-06-21 08:36:31 -0300161 if (id->type == CX18_ENC_STREAM_TYPE_YUV) {
Hans Verkuil0b5a30e2008-06-21 09:22:19 -0300162 pixfmt->pixelformat = V4L2_PIX_FMT_HM12;
Hans Verkuila4a78712009-02-06 15:31:59 -0300163 /* YUV size is (Y=(h*720) + UV=(h*(720/2))) */
164 pixfmt->sizeimage = pixfmt->height * 720 * 3 / 2;
Hans Verkuil0b5a30e2008-06-21 09:22:19 -0300165 pixfmt->bytesperline = 720;
Andy Walls3b6fe582008-06-21 08:36:31 -0300166 } else {
Hans Verkuil0b5a30e2008-06-21 09:22:19 -0300167 pixfmt->pixelformat = V4L2_PIX_FMT_MPEG;
168 pixfmt->sizeimage = 128 * 1024;
169 pixfmt->bytesperline = 0;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300170 }
171 return 0;
172}
173
Andy Walls3b6fe582008-06-21 08:36:31 -0300174static int cx18_g_fmt_vbi_cap(struct file *file, void *fh,
175 struct v4l2_format *fmt)
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300176{
Andy Walls3b6fe582008-06-21 08:36:31 -0300177 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
Hans Verkuil0b5a30e2008-06-21 09:22:19 -0300178 struct v4l2_vbi_format *vbifmt = &fmt->fmt.vbi;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300179
Hans Verkuil0b5a30e2008-06-21 09:22:19 -0300180 vbifmt->sampling_rate = 27000000;
Andy Wallsc1994082009-02-05 22:37:49 -0300181 vbifmt->offset = 248; /* FIXME - slightly wrong for both 50 & 60 Hz */
Andy Walls302df972009-01-31 00:33:02 -0300182 vbifmt->samples_per_line = vbi_active_samples - 4;
Hans Verkuil0b5a30e2008-06-21 09:22:19 -0300183 vbifmt->sample_format = V4L2_PIX_FMT_GREY;
184 vbifmt->start[0] = cx->vbi.start[0];
185 vbifmt->start[1] = cx->vbi.start[1];
186 vbifmt->count[0] = vbifmt->count[1] = cx->vbi.count;
187 vbifmt->flags = 0;
188 vbifmt->reserved[0] = 0;
189 vbifmt->reserved[1] = 0;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300190 return 0;
191}
192
Andy Walls3b6fe582008-06-21 08:36:31 -0300193static int cx18_g_fmt_sliced_vbi_cap(struct file *file, void *fh,
194 struct v4l2_format *fmt)
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300195{
Andy Walls302df972009-01-31 00:33:02 -0300196 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
197 struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced;
198
Andy Wallsc1994082009-02-05 22:37:49 -0300199 /* sane, V4L2 spec compliant, defaults */
Andy Walls302df972009-01-31 00:33:02 -0300200 vbifmt->reserved[0] = 0;
201 vbifmt->reserved[1] = 0;
202 vbifmt->io_size = sizeof(struct v4l2_sliced_vbi_data) * 36;
203 memset(vbifmt->service_lines, 0, sizeof(vbifmt->service_lines));
Andy Wallsc1994082009-02-05 22:37:49 -0300204 vbifmt->service_set = 0;
Andy Walls302df972009-01-31 00:33:02 -0300205
Andy Wallsc1994082009-02-05 22:37:49 -0300206 /*
207 * Fetch the configured service_lines and total service_set from the
208 * digitizer/slicer. Note, cx18_av_vbi() wipes the passed in
209 * fmt->fmt.sliced under valid calling conditions
210 */
Andy Wallsfa3e7032009-02-16 02:23:25 -0300211 if (v4l2_subdev_call(cx->sd_av, video, g_fmt, fmt))
Andy Wallsc1994082009-02-05 22:37:49 -0300212 return -EINVAL;
213
214 /* Ensure V4L2 spec compliant output */
215 vbifmt->reserved[0] = 0;
216 vbifmt->reserved[1] = 0;
217 vbifmt->io_size = sizeof(struct v4l2_sliced_vbi_data) * 36;
Andy Walls302df972009-01-31 00:33:02 -0300218 vbifmt->service_set = cx18_get_service_set(vbifmt);
219 return 0;
Andy Walls3b6fe582008-06-21 08:36:31 -0300220}
221
222static int cx18_try_fmt_vid_cap(struct file *file, void *fh,
223 struct v4l2_format *fmt)
224{
225 struct cx18_open_id *id = fh;
226 struct cx18 *cx = id->cx;
Andy Walls3b6fe582008-06-21 08:36:31 -0300227 int w = fmt->fmt.pix.width;
228 int h = fmt->fmt.pix.height;
Hans Verkuila4a78712009-02-06 15:31:59 -0300229 int min_h = 2;
Andy Walls3b6fe582008-06-21 08:36:31 -0300230
Andy Walls3b6fe582008-06-21 08:36:31 -0300231 w = min(w, 720);
Hans Verkuila4a78712009-02-06 15:31:59 -0300232 w = max(w, 2);
233 if (id->type == CX18_ENC_STREAM_TYPE_YUV) {
234 /* YUV height must be a multiple of 32 */
235 h &= ~0x1f;
236 min_h = 32;
237 }
Andy Walls3b6fe582008-06-21 08:36:31 -0300238 h = min(h, cx->is_50hz ? 576 : 480);
Hans Verkuila4a78712009-02-06 15:31:59 -0300239 h = max(h, min_h);
240
Andy Walls3b6fe582008-06-21 08:36:31 -0300241 cx18_g_fmt_vid_cap(file, fh, fmt);
242 fmt->fmt.pix.width = w;
243 fmt->fmt.pix.height = h;
244 return 0;
245}
246
247static int cx18_try_fmt_vbi_cap(struct file *file, void *fh,
248 struct v4l2_format *fmt)
249{
Andy Walls3b6fe582008-06-21 08:36:31 -0300250 return cx18_g_fmt_vbi_cap(file, fh, fmt);
251}
252
253static int cx18_try_fmt_sliced_vbi_cap(struct file *file, void *fh,
254 struct v4l2_format *fmt)
255{
Andy Walls302df972009-01-31 00:33:02 -0300256 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
257 struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced;
258
259 vbifmt->io_size = sizeof(struct v4l2_sliced_vbi_data) * 36;
260 vbifmt->reserved[0] = 0;
261 vbifmt->reserved[1] = 0;
262
Andy Wallsc1994082009-02-05 22:37:49 -0300263 /* If given a service set, expand it validly & clear passed in set */
Andy Walls302df972009-01-31 00:33:02 -0300264 if (vbifmt->service_set)
265 cx18_expand_service_set(vbifmt, cx->is_50hz);
Andy Wallsc1994082009-02-05 22:37:49 -0300266 /* Sanitize the service_lines, and compute the new set if any valid */
267 if (check_service_set(vbifmt, cx->is_50hz))
268 vbifmt->service_set = cx18_get_service_set(vbifmt);
Andy Walls302df972009-01-31 00:33:02 -0300269 return 0;
Andy Walls3b6fe582008-06-21 08:36:31 -0300270}
271
272static int cx18_s_fmt_vid_cap(struct file *file, void *fh,
273 struct v4l2_format *fmt)
274{
275 struct cx18_open_id *id = fh;
276 struct cx18 *cx = id->cx;
277 int ret;
Hans Verkuileffc3462008-09-06 08:24:37 -0300278 int w, h;
Andy Walls3b6fe582008-06-21 08:36:31 -0300279
280 ret = v4l2_prio_check(&cx->prio, &id->prio);
281 if (ret)
282 return ret;
283
Andy Walls3b6fe582008-06-21 08:36:31 -0300284 ret = cx18_try_fmt_vid_cap(file, fh, fmt);
285 if (ret)
286 return ret;
Hans Verkuileffc3462008-09-06 08:24:37 -0300287 w = fmt->fmt.pix.width;
288 h = fmt->fmt.pix.height;
Andy Walls3b6fe582008-06-21 08:36:31 -0300289
290 if (cx->params.width == w && cx->params.height == h)
291 return 0;
292
293 if (atomic_read(&cx->ana_capturing) > 0)
294 return -EBUSY;
295
296 cx->params.width = w;
297 cx->params.height = h;
Andy Wallsfa3e7032009-02-16 02:23:25 -0300298 v4l2_subdev_call(cx->sd_av, video, s_fmt, fmt);
Andy Walls3b6fe582008-06-21 08:36:31 -0300299 return cx18_g_fmt_vid_cap(file, fh, fmt);
300}
301
302static int cx18_s_fmt_vbi_cap(struct file *file, void *fh,
303 struct v4l2_format *fmt)
304{
305 struct cx18_open_id *id = fh;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300306 struct cx18 *cx = id->cx;
307 int ret;
308
Andy Walls3b6fe582008-06-21 08:36:31 -0300309 ret = v4l2_prio_check(&cx->prio, &id->prio);
310 if (ret)
311 return ret;
312
Andy Wallsdcc0ef82009-02-06 18:33:43 -0300313 /*
314 * Changing the Encoder's Raw VBI parameters won't have any effect
315 * if any analog capture is ongoing
316 */
317 if (!cx18_raw_vbi(cx) && atomic_read(&cx->ana_capturing) > 0)
Andy Walls3b6fe582008-06-21 08:36:31 -0300318 return -EBUSY;
319
Andy Wallsc1994082009-02-05 22:37:49 -0300320 /*
321 * Set the digitizer registers for raw active VBI.
322 * Note cx18_av_vbi_wipes out alot of the passed in fmt under valid
323 * calling conditions
324 */
Andy Wallsfa3e7032009-02-16 02:23:25 -0300325 ret = v4l2_subdev_call(cx->sd_av, video, s_fmt, fmt);
Andy Wallsc1994082009-02-05 22:37:49 -0300326 if (ret)
327 return ret;
328
329 /* Store our new v4l2 (non-)sliced VBI state */
Andy Walls3b6fe582008-06-21 08:36:31 -0300330 cx->vbi.sliced_in->service_set = 0;
Andy Wallsdd073432008-12-12 16:24:04 -0300331 cx->vbi.in.type = V4L2_BUF_TYPE_VBI_CAPTURE;
Andy Wallsc1994082009-02-05 22:37:49 -0300332
Andy Walls3b6fe582008-06-21 08:36:31 -0300333 return cx18_g_fmt_vbi_cap(file, fh, fmt);
334}
335
336static int cx18_s_fmt_sliced_vbi_cap(struct file *file, void *fh,
337 struct v4l2_format *fmt)
338{
Andy Walls302df972009-01-31 00:33:02 -0300339 struct cx18_open_id *id = fh;
340 struct cx18 *cx = id->cx;
341 int ret;
342 struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced;
343
344 ret = v4l2_prio_check(&cx->prio, &id->prio);
345 if (ret)
346 return ret;
347
Andy Wallsc1994082009-02-05 22:37:49 -0300348 cx18_try_fmt_sliced_vbi_cap(file, fh, fmt);
349
Andy Wallsdcc0ef82009-02-06 18:33:43 -0300350 /*
351 * Changing the Encoder's Raw VBI parameters won't have any effect
352 * if any analog capture is ongoing
353 */
354 if (cx18_raw_vbi(cx) && atomic_read(&cx->ana_capturing) > 0)
Andy Wallsc1994082009-02-05 22:37:49 -0300355 return -EBUSY;
Andy Wallsdcc0ef82009-02-06 18:33:43 -0300356
Andy Wallsc1994082009-02-05 22:37:49 -0300357 /*
358 * Set the service_lines requested in the digitizer/slicer registers.
359 * Note, cx18_av_vbi() wipes some "impossible" service lines in the
360 * passed in fmt->fmt.sliced under valid calling conditions
361 */
Andy Wallsfa3e7032009-02-16 02:23:25 -0300362 ret = v4l2_subdev_call(cx->sd_av, video, s_fmt, fmt);
Andy Walls302df972009-01-31 00:33:02 -0300363 if (ret)
364 return ret;
Andy Wallsc1994082009-02-05 22:37:49 -0300365 /* Store our current v4l2 sliced VBI settings */
Andy Walls302df972009-01-31 00:33:02 -0300366 cx->vbi.in.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE;
Andy Walls302df972009-01-31 00:33:02 -0300367 memcpy(cx->vbi.sliced_in, vbifmt, sizeof(*cx->vbi.sliced_in));
368 return 0;
Andy Walls3b6fe582008-06-21 08:36:31 -0300369}
370
371static int cx18_g_chip_ident(struct file *file, void *fh,
Hans Verkuilaecde8b2008-12-30 07:14:19 -0300372 struct v4l2_dbg_chip_ident *chip)
Andy Walls3b6fe582008-06-21 08:36:31 -0300373{
374 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
375
Andy Walls3b6fe582008-06-21 08:36:31 -0300376 chip->ident = V4L2_IDENT_NONE;
377 chip->revision = 0;
Hans Verkuilaecde8b2008-12-30 07:14:19 -0300378 if (v4l2_chip_match_host(&chip->match)) {
379 chip->ident = V4L2_IDENT_CX23418;
Andy Walls3b6fe582008-06-21 08:36:31 -0300380 return 0;
381 }
Hans Verkuilaecde8b2008-12-30 07:14:19 -0300382 cx18_call_i2c_clients(cx, VIDIOC_DBG_G_CHIP_IDENT, chip);
383 return 0;
Andy Walls3b6fe582008-06-21 08:36:31 -0300384}
385
Hans Verkuil36ecd492008-06-25 06:00:17 -0300386#ifdef CONFIG_VIDEO_ADV_DEBUG
387static int cx18_cxc(struct cx18 *cx, unsigned int cmd, void *arg)
388{
Hans Verkuilaecde8b2008-12-30 07:14:19 -0300389 struct v4l2_dbg_register *regs = arg;
Hans Verkuil36ecd492008-06-25 06:00:17 -0300390
391 if (!capable(CAP_SYS_ADMIN))
392 return -EPERM;
393 if (regs->reg >= CX18_MEM_OFFSET + CX18_MEM_SIZE)
394 return -EINVAL;
395
Hans Verkuilaecde8b2008-12-30 07:14:19 -0300396 regs->size = 4;
Hans Verkuil36ecd492008-06-25 06:00:17 -0300397 if (cmd == VIDIOC_DBG_G_REGISTER)
Andy Wallsb1526422008-08-30 16:03:44 -0300398 regs->val = cx18_read_enc(cx, regs->reg);
Hans Verkuil36ecd492008-06-25 06:00:17 -0300399 else
Andy Wallsb1526422008-08-30 16:03:44 -0300400 cx18_write_enc(cx, regs->val, regs->reg);
Hans Verkuil36ecd492008-06-25 06:00:17 -0300401 return 0;
402}
403
Andy Walls3b6fe582008-06-21 08:36:31 -0300404static int cx18_g_register(struct file *file, void *fh,
Hans Verkuilaecde8b2008-12-30 07:14:19 -0300405 struct v4l2_dbg_register *reg)
Andy Walls3b6fe582008-06-21 08:36:31 -0300406{
407 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
408
Hans Verkuilaecde8b2008-12-30 07:14:19 -0300409 if (v4l2_chip_match_host(&reg->match))
Andy Walls3b6fe582008-06-21 08:36:31 -0300410 return cx18_cxc(cx, VIDIOC_DBG_G_REGISTER, reg);
Hans Verkuilaecde8b2008-12-30 07:14:19 -0300411 cx18_call_i2c_clients(cx, VIDIOC_DBG_G_REGISTER, reg);
412 return 0;
Andy Walls3b6fe582008-06-21 08:36:31 -0300413}
414
415static int cx18_s_register(struct file *file, void *fh,
Hans Verkuilaecde8b2008-12-30 07:14:19 -0300416 struct v4l2_dbg_register *reg)
Andy Walls3b6fe582008-06-21 08:36:31 -0300417{
418 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
419
Hans Verkuilaecde8b2008-12-30 07:14:19 -0300420 if (v4l2_chip_match_host(&reg->match))
Andy Walls3b6fe582008-06-21 08:36:31 -0300421 return cx18_cxc(cx, VIDIOC_DBG_S_REGISTER, reg);
Hans Verkuilaecde8b2008-12-30 07:14:19 -0300422 cx18_call_i2c_clients(cx, VIDIOC_DBG_S_REGISTER, reg);
423 return 0;
Andy Walls3b6fe582008-06-21 08:36:31 -0300424}
Hans Verkuil36ecd492008-06-25 06:00:17 -0300425#endif
Andy Walls3b6fe582008-06-21 08:36:31 -0300426
427static int cx18_g_priority(struct file *file, void *fh, enum v4l2_priority *p)
428{
429 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
430
Andy Walls3b6fe582008-06-21 08:36:31 -0300431 *p = v4l2_prio_max(&cx->prio);
432 return 0;
433}
434
435static int cx18_s_priority(struct file *file, void *fh, enum v4l2_priority prio)
436{
437 struct cx18_open_id *id = fh;
438 struct cx18 *cx = id->cx;
439
Andy Walls3b6fe582008-06-21 08:36:31 -0300440 return v4l2_prio_change(&cx->prio, &id->prio, prio);
441}
442
443static int cx18_querycap(struct file *file, void *fh,
444 struct v4l2_capability *vcap)
445{
446 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
447
Andy Walls3b6fe582008-06-21 08:36:31 -0300448 strlcpy(vcap->driver, CX18_DRIVER_NAME, sizeof(vcap->driver));
449 strlcpy(vcap->card, cx->card_name, sizeof(vcap->card));
Andy Walls3d059132009-01-10 21:54:39 -0300450 snprintf(vcap->bus_info, sizeof(vcap->bus_info),
451 "PCI:%s", pci_name(cx->pci_dev));
Andy Walls3b6fe582008-06-21 08:36:31 -0300452 vcap->version = CX18_DRIVER_VERSION; /* version */
453 vcap->capabilities = cx->v4l2_cap; /* capabilities */
454 return 0;
455}
456
457static int cx18_enumaudio(struct file *file, void *fh, struct v4l2_audio *vin)
458{
459 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
460
Andy Walls3b6fe582008-06-21 08:36:31 -0300461 return cx18_get_audio_input(cx, vin->index, vin);
462}
463
464static int cx18_g_audio(struct file *file, void *fh, struct v4l2_audio *vin)
465{
466 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
467
Andy Walls3b6fe582008-06-21 08:36:31 -0300468 vin->index = cx->audio_input;
469 return cx18_get_audio_input(cx, vin->index, vin);
470}
471
472static int cx18_s_audio(struct file *file, void *fh, struct v4l2_audio *vout)
473{
474 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
475
Andy Walls3b6fe582008-06-21 08:36:31 -0300476 if (vout->index >= cx->nof_audio_inputs)
477 return -EINVAL;
478 cx->audio_input = vout->index;
479 cx18_audio_set_io(cx);
480 return 0;
481}
482
483static int cx18_enum_input(struct file *file, void *fh, struct v4l2_input *vin)
484{
485 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
486
Andy Walls3b6fe582008-06-21 08:36:31 -0300487 /* set it to defaults from our table */
488 return cx18_get_input(cx, vin->index, vin);
489}
490
491static int cx18_cropcap(struct file *file, void *fh,
492 struct v4l2_cropcap *cropcap)
493{
494 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
495
Andy Walls3b6fe582008-06-21 08:36:31 -0300496 if (cropcap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
497 return -EINVAL;
498 cropcap->bounds.top = cropcap->bounds.left = 0;
499 cropcap->bounds.width = 720;
500 cropcap->bounds.height = cx->is_50hz ? 576 : 480;
501 cropcap->pixelaspect.numerator = cx->is_50hz ? 59 : 10;
502 cropcap->pixelaspect.denominator = cx->is_50hz ? 54 : 11;
503 cropcap->defrect = cropcap->bounds;
504 return 0;
505}
506
507static int cx18_s_crop(struct file *file, void *fh, struct v4l2_crop *crop)
508{
509 struct cx18_open_id *id = fh;
510 struct cx18 *cx = id->cx;
511 int ret;
512
513 ret = v4l2_prio_check(&cx->prio, &id->prio);
514 if (ret)
515 return ret;
516
Andy Walls3b6fe582008-06-21 08:36:31 -0300517 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
518 return -EINVAL;
Andy Wallsfa3e7032009-02-16 02:23:25 -0300519 CX18_DEBUG_WARN("VIDIOC_S_CROP not implemented\n");
520 return -EINVAL;
Andy Walls3b6fe582008-06-21 08:36:31 -0300521}
522
523static int cx18_g_crop(struct file *file, void *fh, struct v4l2_crop *crop)
524{
525 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
526
Andy Walls3b6fe582008-06-21 08:36:31 -0300527 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
528 return -EINVAL;
Andy Wallsfa3e7032009-02-16 02:23:25 -0300529 CX18_DEBUG_WARN("VIDIOC_G_CROP not implemented\n");
530 return -EINVAL;
Andy Walls3b6fe582008-06-21 08:36:31 -0300531}
532
533static int cx18_enum_fmt_vid_cap(struct file *file, void *fh,
534 struct v4l2_fmtdesc *fmt)
535{
536 static struct v4l2_fmtdesc formats[] = {
537 { 0, V4L2_BUF_TYPE_VIDEO_CAPTURE, 0,
538 "HM12 (YUV 4:1:1)", V4L2_PIX_FMT_HM12, { 0, 0, 0, 0 }
539 },
540 { 1, V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FMT_FLAG_COMPRESSED,
541 "MPEG", V4L2_PIX_FMT_MPEG, { 0, 0, 0, 0 }
542 }
543 };
544
Andy Walls3b6fe582008-06-21 08:36:31 -0300545 if (fmt->index > 1)
546 return -EINVAL;
547 *fmt = formats[fmt->index];
548 return 0;
549}
550
551static int cx18_g_input(struct file *file, void *fh, unsigned int *i)
552{
553 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
554
Andy Walls3b6fe582008-06-21 08:36:31 -0300555 *i = cx->active_input;
556 return 0;
557}
558
559int cx18_s_input(struct file *file, void *fh, unsigned int inp)
560{
561 struct cx18_open_id *id = fh;
562 struct cx18 *cx = id->cx;
563 int ret;
564
565 ret = v4l2_prio_check(&cx->prio, &id->prio);
566 if (ret)
567 return ret;
568
Andy Walls3b6fe582008-06-21 08:36:31 -0300569 if (inp < 0 || inp >= cx->nof_inputs)
570 return -EINVAL;
571
572 if (inp == cx->active_input) {
573 CX18_DEBUG_INFO("Input unchanged\n");
574 return 0;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300575 }
576
Andy Walls3b6fe582008-06-21 08:36:31 -0300577 CX18_DEBUG_INFO("Changing input from %d to %d\n",
578 cx->active_input, inp);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300579
Andy Walls3b6fe582008-06-21 08:36:31 -0300580 cx->active_input = inp;
581 /* Set the audio input to whatever is appropriate for the input type. */
582 cx->audio_input = cx->card->video_inputs[inp].audio_index;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300583
Andy Walls3b6fe582008-06-21 08:36:31 -0300584 /* prevent others from messing with the streams until
585 we're finished changing inputs. */
586 cx18_mute(cx);
587 cx18_video_set_io(cx);
588 cx18_audio_set_io(cx);
589 cx18_unmute(cx);
590 return 0;
591}
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300592
Andy Walls3b6fe582008-06-21 08:36:31 -0300593static int cx18_g_frequency(struct file *file, void *fh,
594 struct v4l2_frequency *vf)
595{
596 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
597
Andy Walls3b6fe582008-06-21 08:36:31 -0300598 if (vf->tuner != 0)
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300599 return -EINVAL;
Andy Walls3b6fe582008-06-21 08:36:31 -0300600
601 cx18_call_i2c_clients(cx, VIDIOC_G_FREQUENCY, vf);
602 return 0;
603}
604
605int cx18_s_frequency(struct file *file, void *fh, struct v4l2_frequency *vf)
606{
607 struct cx18_open_id *id = fh;
608 struct cx18 *cx = id->cx;
609 int ret;
610
611 ret = v4l2_prio_check(&cx->prio, &id->prio);
612 if (ret)
613 return ret;
614
Andy Walls3b6fe582008-06-21 08:36:31 -0300615 if (vf->tuner != 0)
616 return -EINVAL;
617
618 cx18_mute(cx);
619 CX18_DEBUG_INFO("v4l2 ioctl: set frequency %d\n", vf->frequency);
620 cx18_call_i2c_clients(cx, VIDIOC_S_FREQUENCY, vf);
621 cx18_unmute(cx);
622 return 0;
623}
624
625static int cx18_g_std(struct file *file, void *fh, v4l2_std_id *std)
626{
627 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
628
Andy Walls3b6fe582008-06-21 08:36:31 -0300629 *std = cx->std;
630 return 0;
631}
632
633int cx18_s_std(struct file *file, void *fh, v4l2_std_id *std)
634{
635 struct cx18_open_id *id = fh;
636 struct cx18 *cx = id->cx;
637 int ret;
638
639 ret = v4l2_prio_check(&cx->prio, &id->prio);
640 if (ret)
641 return ret;
642
Andy Walls3b6fe582008-06-21 08:36:31 -0300643 if ((*std & V4L2_STD_ALL) == 0)
644 return -EINVAL;
645
646 if (*std == cx->std)
647 return 0;
648
649 if (test_bit(CX18_F_I_RADIO_USER, &cx->i_flags) ||
650 atomic_read(&cx->ana_capturing) > 0) {
651 /* Switching standard would turn off the radio or mess
652 with already running streams, prevent that by
653 returning EBUSY. */
654 return -EBUSY;
655 }
656
657 cx->std = *std;
658 cx->is_60hz = (*std & V4L2_STD_525_60) ? 1 : 0;
659 cx->params.is_50hz = cx->is_50hz = !cx->is_60hz;
660 cx->params.width = 720;
661 cx->params.height = cx->is_50hz ? 576 : 480;
662 cx->vbi.count = cx->is_50hz ? 18 : 12;
663 cx->vbi.start[0] = cx->is_50hz ? 6 : 10;
664 cx->vbi.start[1] = cx->is_50hz ? 318 : 273;
Andy Walls3b6fe582008-06-21 08:36:31 -0300665 CX18_DEBUG_INFO("Switching standard to %llx.\n",
666 (unsigned long long) cx->std);
667
668 /* Tuner */
669 cx18_call_i2c_clients(cx, VIDIOC_S_STD, &cx->std);
670 return 0;
671}
672
673static int cx18_s_tuner(struct file *file, void *fh, struct v4l2_tuner *vt)
674{
675 struct cx18_open_id *id = fh;
676 struct cx18 *cx = id->cx;
677 int ret;
678
679 ret = v4l2_prio_check(&cx->prio, &id->prio);
680 if (ret)
681 return ret;
682
Andy Walls3b6fe582008-06-21 08:36:31 -0300683 if (vt->index != 0)
684 return -EINVAL;
685
686 /* Setting tuner can only set audio mode */
687 cx18_call_i2c_clients(cx, VIDIOC_S_TUNER, vt);
688
689 return 0;
690}
691
692static int cx18_g_tuner(struct file *file, void *fh, struct v4l2_tuner *vt)
693{
694 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
695
Andy Walls3b6fe582008-06-21 08:36:31 -0300696 if (vt->index != 0)
697 return -EINVAL;
698
699 cx18_call_i2c_clients(cx, VIDIOC_G_TUNER, vt);
700
701 if (test_bit(CX18_F_I_RADIO_USER, &cx->i_flags)) {
702 strlcpy(vt->name, "cx18 Radio Tuner", sizeof(vt->name));
703 vt->type = V4L2_TUNER_RADIO;
704 } else {
705 strlcpy(vt->name, "cx18 TV Tuner", sizeof(vt->name));
706 vt->type = V4L2_TUNER_ANALOG_TV;
707 }
708
709 return 0;
710}
711
712static int cx18_g_sliced_vbi_cap(struct file *file, void *fh,
713 struct v4l2_sliced_vbi_cap *cap)
714{
Andy Walls302df972009-01-31 00:33:02 -0300715 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
716 int set = cx->is_50hz ? V4L2_SLICED_VBI_625 : V4L2_SLICED_VBI_525;
717 int f, l;
718
Andy Wallsc1994082009-02-05 22:37:49 -0300719 if (cap->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE)
720 return -EINVAL;
721
722 cap->service_set = 0;
723 for (f = 0; f < 2; f++) {
724 for (l = 0; l < 24; l++) {
725 if (valid_service_line(f, l, cx->is_50hz)) {
726 /*
727 * We can find all v4l2 supported vbi services
728 * for the standard, on a valid line for the std
729 */
730 cap->service_lines[f][l] = set;
731 cap->service_set |= set;
732 } else
733 cap->service_lines[f][l] = 0;
Andy Walls302df972009-01-31 00:33:02 -0300734 }
Andy Walls302df972009-01-31 00:33:02 -0300735 }
Andy Wallsc1994082009-02-05 22:37:49 -0300736 for (f = 0; f < 3; f++)
737 cap->reserved[f] = 0;
738 return 0;
Andy Walls3b6fe582008-06-21 08:36:31 -0300739}
740
741static int cx18_g_enc_index(struct file *file, void *fh,
742 struct v4l2_enc_idx *idx)
743{
744 return -EINVAL;
745}
746
747static int cx18_encoder_cmd(struct file *file, void *fh,
748 struct v4l2_encoder_cmd *enc)
749{
750 struct cx18_open_id *id = fh;
751 struct cx18 *cx = id->cx;
Andy Wallsd3c5e702008-08-23 16:42:29 -0300752 u32 h;
Andy Walls3b6fe582008-06-21 08:36:31 -0300753
Andy Walls3b6fe582008-06-21 08:36:31 -0300754 switch (enc->cmd) {
755 case V4L2_ENC_CMD_START:
756 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_START\n");
757 enc->flags = 0;
758 return cx18_start_capture(id);
759
760 case V4L2_ENC_CMD_STOP:
761 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_STOP\n");
762 enc->flags &= V4L2_ENC_CMD_STOP_AT_GOP_END;
763 cx18_stop_capture(id,
764 enc->flags & V4L2_ENC_CMD_STOP_AT_GOP_END);
765 break;
766
767 case V4L2_ENC_CMD_PAUSE:
768 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_PAUSE\n");
769 enc->flags = 0;
770 if (!atomic_read(&cx->ana_capturing))
771 return -EPERM;
772 if (test_and_set_bit(CX18_F_I_ENC_PAUSED, &cx->i_flags))
773 return 0;
Andy Wallsd3c5e702008-08-23 16:42:29 -0300774 h = cx18_find_handle(cx);
775 if (h == CX18_INVALID_TASK_HANDLE) {
776 CX18_ERR("Can't find valid task handle for "
777 "V4L2_ENC_CMD_PAUSE\n");
778 return -EBADFD;
779 }
Andy Walls3b6fe582008-06-21 08:36:31 -0300780 cx18_mute(cx);
Andy Wallsd3c5e702008-08-23 16:42:29 -0300781 cx18_vapi(cx, CX18_CPU_CAPTURE_PAUSE, 1, h);
Andy Walls3b6fe582008-06-21 08:36:31 -0300782 break;
783
784 case V4L2_ENC_CMD_RESUME:
785 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_RESUME\n");
786 enc->flags = 0;
787 if (!atomic_read(&cx->ana_capturing))
788 return -EPERM;
789 if (!test_and_clear_bit(CX18_F_I_ENC_PAUSED, &cx->i_flags))
790 return 0;
Andy Wallsd3c5e702008-08-23 16:42:29 -0300791 h = cx18_find_handle(cx);
792 if (h == CX18_INVALID_TASK_HANDLE) {
793 CX18_ERR("Can't find valid task handle for "
794 "V4L2_ENC_CMD_RESUME\n");
795 return -EBADFD;
796 }
797 cx18_vapi(cx, CX18_CPU_CAPTURE_RESUME, 1, h);
Andy Walls3b6fe582008-06-21 08:36:31 -0300798 cx18_unmute(cx);
799 break;
800
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300801 default:
Andy Walls3b6fe582008-06-21 08:36:31 -0300802 CX18_DEBUG_IOCTL("Unknown cmd %d\n", enc->cmd);
803 return -EINVAL;
804 }
805 return 0;
806}
807
808static int cx18_try_encoder_cmd(struct file *file, void *fh,
809 struct v4l2_encoder_cmd *enc)
810{
811 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
812
Andy Walls3b6fe582008-06-21 08:36:31 -0300813 switch (enc->cmd) {
814 case V4L2_ENC_CMD_START:
815 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_START\n");
816 enc->flags = 0;
817 break;
818
819 case V4L2_ENC_CMD_STOP:
820 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_STOP\n");
821 enc->flags &= V4L2_ENC_CMD_STOP_AT_GOP_END;
822 break;
823
824 case V4L2_ENC_CMD_PAUSE:
825 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_PAUSE\n");
826 enc->flags = 0;
827 break;
828
829 case V4L2_ENC_CMD_RESUME:
830 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_RESUME\n");
831 enc->flags = 0;
832 break;
833
834 default:
835 CX18_DEBUG_IOCTL("Unknown cmd %d\n", enc->cmd);
836 return -EINVAL;
837 }
838 return 0;
839}
840
841static int cx18_log_status(struct file *file, void *fh)
842{
843 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
844 struct v4l2_input vidin;
845 struct v4l2_audio audin;
846 int i;
847
Andy Wallse0f28b62009-01-10 14:13:46 -0300848 CX18_INFO("================= START STATUS CARD #%d "
Andy Walls5811cf92009-02-14 17:08:37 -0300849 "=================\n", cx->instance);
Andy Wallse0f28b62009-01-10 14:13:46 -0300850 CX18_INFO("Version: %s Card: %s\n", CX18_VERSION, cx->card_name);
Andy Walls3b6fe582008-06-21 08:36:31 -0300851 if (cx->hw_flags & CX18_HW_TVEEPROM) {
852 struct tveeprom tv;
853
854 cx18_read_eeprom(cx, &tv);
855 }
856 cx18_call_i2c_clients(cx, VIDIOC_LOG_STATUS, NULL);
857 cx18_get_input(cx, cx->active_input, &vidin);
858 cx18_get_audio_input(cx, cx->audio_input, &audin);
859 CX18_INFO("Video Input: %s\n", vidin.name);
860 CX18_INFO("Audio Input: %s\n", audin.name);
Andy Walls8abdd002008-07-13 19:05:25 -0300861 mutex_lock(&cx->gpio_lock);
Hans Verkuil3d66c402008-06-21 11:19:34 -0300862 CX18_INFO("GPIO: direction 0x%08x, value 0x%08x\n",
863 cx->gpio_dir, cx->gpio_val);
Andy Walls8abdd002008-07-13 19:05:25 -0300864 mutex_unlock(&cx->gpio_lock);
Andy Walls3b6fe582008-06-21 08:36:31 -0300865 CX18_INFO("Tuner: %s\n",
866 test_bit(CX18_F_I_RADIO_USER, &cx->i_flags) ? "Radio" : "TV");
Andy Walls5811cf92009-02-14 17:08:37 -0300867 cx2341x_log_status(&cx->params, cx->v4l2_dev.name);
Andy Walls3b6fe582008-06-21 08:36:31 -0300868 CX18_INFO("Status flags: 0x%08lx\n", cx->i_flags);
869 for (i = 0; i < CX18_MAX_STREAMS; i++) {
870 struct cx18_stream *s = &cx->streams[i];
871
Andy Walls3d059132009-01-10 21:54:39 -0300872 if (s->video_dev == NULL || s->buffers == 0)
Andy Walls3b6fe582008-06-21 08:36:31 -0300873 continue;
874 CX18_INFO("Stream %s: status 0x%04lx, %d%% of %d KiB (%d buffers) in use\n",
875 s->name, s->s_flags,
Andy Walls66c2a6b2008-12-08 23:02:45 -0300876 atomic_read(&s->q_full.buffers) * 100 / s->buffers,
Andy Walls3b6fe582008-06-21 08:36:31 -0300877 (s->buffers * s->buf_size) / 1024, s->buffers);
878 }
879 CX18_INFO("Read MPEG/VBI: %lld/%lld bytes\n",
880 (long long)cx->mpg_data_received,
881 (long long)cx->vbi_data_inserted);
Andy Walls5811cf92009-02-14 17:08:37 -0300882 CX18_INFO("================== END STATUS CARD #%d "
883 "==================\n", cx->instance);
Andy Walls3b6fe582008-06-21 08:36:31 -0300884 return 0;
885}
886
Hans Verkuil069b7472008-12-30 07:04:34 -0300887static long cx18_default(struct file *file, void *fh, int cmd, void *arg)
Andy Walls3b6fe582008-06-21 08:36:31 -0300888{
889 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
890
891 switch (cmd) {
892 case VIDIOC_INT_S_AUDIO_ROUTING: {
893 struct v4l2_routing *route = arg;
Hans Verkuil37f89f92008-06-22 11:57:31 -0300894
895 CX18_DEBUG_IOCTL("VIDIOC_INT_S_AUDIO_ROUTING(%d, %d)\n",
896 route->input, route->output);
Andy Walls3b6fe582008-06-21 08:36:31 -0300897 cx18_audio_set_route(cx, route);
898 break;
899 }
Andy Walls02fa2722008-07-13 19:30:15 -0300900
901 case VIDIOC_INT_RESET: {
902 u32 val = *(u32 *)arg;
903
904 if ((val == 0) || (val & 0x01))
905 cx18_reset_ir_gpio(&cx->i2c_algo_cb_data[0]);
906 break;
907 }
908
Andy Walls3b6fe582008-06-21 08:36:31 -0300909 default:
Andy Walls3b6fe582008-06-21 08:36:31 -0300910 return -EINVAL;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300911 }
912 return 0;
913}
914
Hans Verkuil069b7472008-12-30 07:04:34 -0300915long cx18_v4l2_ioctl(struct file *filp, unsigned int cmd,
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300916 unsigned long arg)
917{
Hans Verkuil37f89f92008-06-22 11:57:31 -0300918 struct video_device *vfd = video_devdata(filp);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300919 struct cx18_open_id *id = (struct cx18_open_id *)filp->private_data;
920 struct cx18 *cx = id->cx;
Hans Verkuil069b7472008-12-30 07:04:34 -0300921 long res;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300922
923 mutex_lock(&cx->serialize_lock);
Hans Verkuil37f89f92008-06-22 11:57:31 -0300924
925 if (cx18_debug & CX18_DBGFLG_IOCTL)
926 vfd->debug = V4L2_DEBUG_IOCTL | V4L2_DEBUG_IOCTL_ARG;
Hans Verkuilbec43662008-12-30 06:58:20 -0300927 res = video_ioctl2(filp, cmd, arg);
Hans Verkuil37f89f92008-06-22 11:57:31 -0300928 vfd->debug = 0;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300929 mutex_unlock(&cx->serialize_lock);
930 return res;
931}
Andy Walls3b6fe582008-06-21 08:36:31 -0300932
Hans Verkuila3998102008-07-21 02:57:38 -0300933static const struct v4l2_ioctl_ops cx18_ioctl_ops = {
934 .vidioc_querycap = cx18_querycap,
935 .vidioc_g_priority = cx18_g_priority,
936 .vidioc_s_priority = cx18_s_priority,
937 .vidioc_s_audio = cx18_s_audio,
938 .vidioc_g_audio = cx18_g_audio,
939 .vidioc_enumaudio = cx18_enumaudio,
940 .vidioc_enum_input = cx18_enum_input,
941 .vidioc_cropcap = cx18_cropcap,
942 .vidioc_s_crop = cx18_s_crop,
943 .vidioc_g_crop = cx18_g_crop,
944 .vidioc_g_input = cx18_g_input,
945 .vidioc_s_input = cx18_s_input,
946 .vidioc_g_frequency = cx18_g_frequency,
947 .vidioc_s_frequency = cx18_s_frequency,
948 .vidioc_s_tuner = cx18_s_tuner,
949 .vidioc_g_tuner = cx18_g_tuner,
950 .vidioc_g_enc_index = cx18_g_enc_index,
951 .vidioc_g_std = cx18_g_std,
952 .vidioc_s_std = cx18_s_std,
953 .vidioc_log_status = cx18_log_status,
954 .vidioc_enum_fmt_vid_cap = cx18_enum_fmt_vid_cap,
955 .vidioc_encoder_cmd = cx18_encoder_cmd,
956 .vidioc_try_encoder_cmd = cx18_try_encoder_cmd,
957 .vidioc_g_fmt_vid_cap = cx18_g_fmt_vid_cap,
958 .vidioc_g_fmt_vbi_cap = cx18_g_fmt_vbi_cap,
959 .vidioc_g_fmt_sliced_vbi_cap = cx18_g_fmt_sliced_vbi_cap,
960 .vidioc_s_fmt_vid_cap = cx18_s_fmt_vid_cap,
961 .vidioc_s_fmt_vbi_cap = cx18_s_fmt_vbi_cap,
962 .vidioc_s_fmt_sliced_vbi_cap = cx18_s_fmt_sliced_vbi_cap,
963 .vidioc_try_fmt_vid_cap = cx18_try_fmt_vid_cap,
964 .vidioc_try_fmt_vbi_cap = cx18_try_fmt_vbi_cap,
965 .vidioc_try_fmt_sliced_vbi_cap = cx18_try_fmt_sliced_vbi_cap,
966 .vidioc_g_sliced_vbi_cap = cx18_g_sliced_vbi_cap,
967 .vidioc_g_chip_ident = cx18_g_chip_ident,
968#ifdef CONFIG_VIDEO_ADV_DEBUG
969 .vidioc_g_register = cx18_g_register,
970 .vidioc_s_register = cx18_s_register,
971#endif
972 .vidioc_default = cx18_default,
973 .vidioc_queryctrl = cx18_queryctrl,
974 .vidioc_querymenu = cx18_querymenu,
975 .vidioc_g_ext_ctrls = cx18_g_ext_ctrls,
976 .vidioc_s_ext_ctrls = cx18_s_ext_ctrls,
977 .vidioc_try_ext_ctrls = cx18_try_ext_ctrls,
978};
979
Andy Walls3b6fe582008-06-21 08:36:31 -0300980void cx18_set_funcs(struct video_device *vdev)
981{
Hans Verkuila3998102008-07-21 02:57:38 -0300982 vdev->ioctl_ops = &cx18_ioctl_ops;
Andy Walls3b6fe582008-06-21 08:36:31 -0300983}