Fix common misspellings
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / media / video / cx18 / cx18-ioctl.c
CommitLineData
1c1e45d1
HV
1/*
2 * cx18 ioctl system call
3 *
4 * Derived from ivtv-ioctl.c
5 *
6 * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl>
6afdeaf8 7 * Copyright (C) 2008 Andy Walls <awalls@md.metrocast.net>
1c1e45d1
HV
8 *
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"
b1526421 26#include "cx18-io.h"
1c1e45d1
HV
27#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>
1c1e45d1 43
aed6abd6 44u16 cx18_service2vbi(int type)
1c1e45d1
HV
45{
46 switch (type) {
47 case V4L2_SLICED_TELETEXT_B:
48 return CX18_SLICED_TYPE_TELETEXT_B;
49 case V4L2_SLICED_CAPTION_525:
50 return CX18_SLICED_TYPE_CAPTION_525;
51 case V4L2_SLICED_WSS_625:
52 return CX18_SLICED_TYPE_WSS_625;
53 case V4L2_SLICED_VPS:
54 return CX18_SLICED_TYPE_VPS;
55 default:
56 return 0;
57 }
58}
59
c1994084 60/* Check if VBI services are allowed on the (field, line) for the video std */
1c1e45d1
HV
61static int valid_service_line(int field, int line, int is_pal)
62{
c1994084
AW
63 return (is_pal && line >= 6 &&
64 ((field == 0 && line <= 23) || (field == 1 && line <= 22))) ||
1c1e45d1
HV
65 (!is_pal && line >= 10 && line < 22);
66}
67
c1994084
AW
68/*
69 * For a (field, line, std) and inbound potential set of services for that line,
70 * return the first valid service of those passed in the incoming set for that
71 * line in priority order:
72 * CC, VPS, or WSS over TELETEXT for well known lines
73 * TELETEXT, before VPS, before CC, before WSS, for other lines
74 */
1c1e45d1
HV
75static u16 select_service_from_set(int field, int line, u16 set, int is_pal)
76{
77 u16 valid_set = (is_pal ? V4L2_SLICED_VBI_625 : V4L2_SLICED_VBI_525);
78 int i;
79
80 set = set & valid_set;
81 if (set == 0 || !valid_service_line(field, line, is_pal))
82 return 0;
83 if (!is_pal) {
84 if (line == 21 && (set & V4L2_SLICED_CAPTION_525))
85 return V4L2_SLICED_CAPTION_525;
86 } else {
87 if (line == 16 && field == 0 && (set & V4L2_SLICED_VPS))
88 return V4L2_SLICED_VPS;
89 if (line == 23 && field == 0 && (set & V4L2_SLICED_WSS_625))
90 return V4L2_SLICED_WSS_625;
91 if (line == 23)
92 return 0;
93 }
94 for (i = 0; i < 32; i++) {
95 if ((1 << i) & set)
96 return 1 << i;
97 }
98 return 0;
99}
100
c1994084
AW
101/*
102 * Expand the service_set of *fmt into valid service_lines for the std,
103 * and clear the passed in fmt->service_set
104 */
aed6abd6 105void cx18_expand_service_set(struct v4l2_sliced_vbi_format *fmt, int is_pal)
1c1e45d1
HV
106{
107 u16 set = fmt->service_set;
108 int f, l;
109
110 fmt->service_set = 0;
111 for (f = 0; f < 2; f++) {
112 for (l = 0; l < 24; l++)
113 fmt->service_lines[f][l] = select_service_from_set(f, l, set, is_pal);
114 }
115}
116
c1994084
AW
117/*
118 * Sanitize the service_lines in *fmt per the video std, and return 1
119 * if any service_line is left as valid after santization
120 */
302df970
AW
121static int check_service_set(struct v4l2_sliced_vbi_format *fmt, int is_pal)
122{
123 int f, l;
124 u16 set = 0;
125
126 for (f = 0; f < 2; f++) {
127 for (l = 0; l < 24; l++) {
128 fmt->service_lines[f][l] = select_service_from_set(f, l, fmt->service_lines[f][l], is_pal);
129 set |= fmt->service_lines[f][l];
130 }
131 }
132 return set != 0;
133}
1c1e45d1 134
c1994084 135/* Compute the service_set from the assumed valid service_lines of *fmt */
aed6abd6 136u16 cx18_get_service_set(struct v4l2_sliced_vbi_format *fmt)
1c1e45d1
HV
137{
138 int f, l;
139 u16 set = 0;
140
141 for (f = 0; f < 2; f++) {
142 for (l = 0; l < 24; l++)
143 set |= fmt->service_lines[f][l];
144 }
145 return set;
146}
147
3b6fe58f
AW
148static int cx18_g_fmt_vid_cap(struct file *file, void *fh,
149 struct v4l2_format *fmt)
150{
0b5f265a 151 struct cx18_open_id *id = fh2id(fh);
3b6fe58f 152 struct cx18 *cx = id->cx;
0b5a30e9 153 struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
1c1e45d1 154
a75b9be1
HV
155 pixfmt->width = cx->cxhdl.width;
156 pixfmt->height = cx->cxhdl.height;
0b5a30e9
HV
157 pixfmt->colorspace = V4L2_COLORSPACE_SMPTE170M;
158 pixfmt->field = V4L2_FIELD_INTERLACED;
159 pixfmt->priv = 0;
3b6fe58f 160 if (id->type == CX18_ENC_STREAM_TYPE_YUV) {
0b5a30e9 161 pixfmt->pixelformat = V4L2_PIX_FMT_HM12;
a4a78718
HV
162 /* YUV size is (Y=(h*720) + UV=(h*(720/2))) */
163 pixfmt->sizeimage = pixfmt->height * 720 * 3 / 2;
0b5a30e9 164 pixfmt->bytesperline = 720;
3b6fe58f 165 } else {
0b5a30e9
HV
166 pixfmt->pixelformat = V4L2_PIX_FMT_MPEG;
167 pixfmt->sizeimage = 128 * 1024;
168 pixfmt->bytesperline = 0;
3b6fe58f
AW
169 }
170 return 0;
171}
1c1e45d1 172
3b6fe58f
AW
173static int cx18_g_fmt_vbi_cap(struct file *file, void *fh,
174 struct v4l2_format *fmt)
175{
0b5f265a 176 struct cx18 *cx = fh2id(fh)->cx;
0b5a30e9 177 struct v4l2_vbi_format *vbifmt = &fmt->fmt.vbi;
1c1e45d1 178
0b5a30e9 179 vbifmt->sampling_rate = 27000000;
c1994084 180 vbifmt->offset = 248; /* FIXME - slightly wrong for both 50 & 60 Hz */
302df970 181 vbifmt->samples_per_line = vbi_active_samples - 4;
0b5a30e9
HV
182 vbifmt->sample_format = V4L2_PIX_FMT_GREY;
183 vbifmt->start[0] = cx->vbi.start[0];
184 vbifmt->start[1] = cx->vbi.start[1];
185 vbifmt->count[0] = vbifmt->count[1] = cx->vbi.count;
186 vbifmt->flags = 0;
187 vbifmt->reserved[0] = 0;
188 vbifmt->reserved[1] = 0;
1c1e45d1
HV
189 return 0;
190}
191
3b6fe58f
AW
192static int cx18_g_fmt_sliced_vbi_cap(struct file *file, void *fh,
193 struct v4l2_format *fmt)
1c1e45d1 194{
0b5f265a 195 struct cx18 *cx = fh2id(fh)->cx;
302df970
AW
196 struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced;
197
c1994084 198 /* sane, V4L2 spec compliant, defaults */
302df970
AW
199 vbifmt->reserved[0] = 0;
200 vbifmt->reserved[1] = 0;
201 vbifmt->io_size = sizeof(struct v4l2_sliced_vbi_data) * 36;
202 memset(vbifmt->service_lines, 0, sizeof(vbifmt->service_lines));
c1994084
AW
203 vbifmt->service_set = 0;
204
205 /*
206 * Fetch the configured service_lines and total service_set from the
207 * digitizer/slicer. Note, cx18_av_vbi() wipes the passed in
208 * fmt->fmt.sliced under valid calling conditions
209 */
add632cd 210 if (v4l2_subdev_call(cx->sd_av, vbi, g_sliced_fmt, &fmt->fmt.sliced))
c1994084 211 return -EINVAL;
302df970 212
c1994084
AW
213 /* Ensure V4L2 spec compliant output */
214 vbifmt->reserved[0] = 0;
215 vbifmt->reserved[1] = 0;
216 vbifmt->io_size = sizeof(struct v4l2_sliced_vbi_data) * 36;
302df970
AW
217 vbifmt->service_set = cx18_get_service_set(vbifmt);
218 return 0;
3b6fe58f 219}
1c1e45d1 220
3b6fe58f
AW
221static int cx18_try_fmt_vid_cap(struct file *file, void *fh,
222 struct v4l2_format *fmt)
223{
0b5f265a 224 struct cx18_open_id *id = fh2id(fh);
3b6fe58f 225 struct cx18 *cx = id->cx;
3b6fe58f
AW
226 int w = fmt->fmt.pix.width;
227 int h = fmt->fmt.pix.height;
a4a78718 228 int min_h = 2;
1c1e45d1 229
3b6fe58f 230 w = min(w, 720);
a4a78718
HV
231 w = max(w, 2);
232 if (id->type == CX18_ENC_STREAM_TYPE_YUV) {
233 /* YUV height must be a multiple of 32 */
234 h &= ~0x1f;
235 min_h = 32;
236 }
3b6fe58f 237 h = min(h, cx->is_50hz ? 576 : 480);
a4a78718
HV
238 h = max(h, min_h);
239
3b6fe58f
AW
240 cx18_g_fmt_vid_cap(file, fh, fmt);
241 fmt->fmt.pix.width = w;
242 fmt->fmt.pix.height = h;
243 return 0;
244}
1c1e45d1 245
3b6fe58f
AW
246static int cx18_try_fmt_vbi_cap(struct file *file, void *fh,
247 struct v4l2_format *fmt)
248{
3b6fe58f
AW
249 return cx18_g_fmt_vbi_cap(file, fh, fmt);
250}
251
252static int cx18_try_fmt_sliced_vbi_cap(struct file *file, void *fh,
253 struct v4l2_format *fmt)
254{
0b5f265a 255 struct cx18 *cx = fh2id(fh)->cx;
302df970
AW
256 struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced;
257
258 vbifmt->io_size = sizeof(struct v4l2_sliced_vbi_data) * 36;
259 vbifmt->reserved[0] = 0;
260 vbifmt->reserved[1] = 0;
261
c1994084 262 /* If given a service set, expand it validly & clear passed in set */
302df970
AW
263 if (vbifmt->service_set)
264 cx18_expand_service_set(vbifmt, cx->is_50hz);
c1994084
AW
265 /* Sanitize the service_lines, and compute the new set if any valid */
266 if (check_service_set(vbifmt, cx->is_50hz))
267 vbifmt->service_set = cx18_get_service_set(vbifmt);
302df970 268 return 0;
3b6fe58f
AW
269}
270
271static int cx18_s_fmt_vid_cap(struct file *file, void *fh,
272 struct v4l2_format *fmt)
273{
0b5f265a 274 struct cx18_open_id *id = fh2id(fh);
3b6fe58f 275 struct cx18 *cx = id->cx;
9e36eabc 276 struct v4l2_mbus_framefmt mbus_fmt;
3b6fe58f 277 int ret;
effc3466 278 int w, h;
3b6fe58f 279
3b6fe58f
AW
280 ret = cx18_try_fmt_vid_cap(file, fh, fmt);
281 if (ret)
282 return ret;
effc3466
HV
283 w = fmt->fmt.pix.width;
284 h = fmt->fmt.pix.height;
1c1e45d1 285
a75b9be1 286 if (cx->cxhdl.width == w && cx->cxhdl.height == h)
1c1e45d1 287 return 0;
3b6fe58f
AW
288
289 if (atomic_read(&cx->ana_capturing) > 0)
1c1e45d1 290 return -EBUSY;
3b6fe58f 291
a75b9be1
HV
292 mbus_fmt.width = cx->cxhdl.width = w;
293 mbus_fmt.height = cx->cxhdl.height = h;
9e36eabc
HV
294 mbus_fmt.code = V4L2_MBUS_FMT_FIXED;
295 v4l2_subdev_call(cx->sd_av, video, s_mbus_fmt, &mbus_fmt);
3b6fe58f 296 return cx18_g_fmt_vid_cap(file, fh, fmt);
1c1e45d1
HV
297}
298
3b6fe58f
AW
299static int cx18_s_fmt_vbi_cap(struct file *file, void *fh,
300 struct v4l2_format *fmt)
1c1e45d1 301{
0b5f265a 302 struct cx18_open_id *id = fh2id(fh);
1c1e45d1 303 struct cx18 *cx = id->cx;
3b6fe58f 304 int ret;
1c1e45d1 305
dcc0ef88
AW
306 /*
307 * Changing the Encoder's Raw VBI parameters won't have any effect
308 * if any analog capture is ongoing
309 */
310 if (!cx18_raw_vbi(cx) && atomic_read(&cx->ana_capturing) > 0)
3b6fe58f 311 return -EBUSY;
1c1e45d1 312
c1994084
AW
313 /*
314 * Set the digitizer registers for raw active VBI.
25985edc 315 * Note cx18_av_vbi_wipes out a lot of the passed in fmt under valid
c1994084
AW
316 * calling conditions
317 */
add632cd 318 ret = v4l2_subdev_call(cx->sd_av, vbi, s_raw_fmt, &fmt->fmt.vbi);
c1994084
AW
319 if (ret)
320 return ret;
321
322 /* Store our new v4l2 (non-)sliced VBI state */
3b6fe58f 323 cx->vbi.sliced_in->service_set = 0;
dd073434 324 cx->vbi.in.type = V4L2_BUF_TYPE_VBI_CAPTURE;
c1994084 325
3b6fe58f
AW
326 return cx18_g_fmt_vbi_cap(file, fh, fmt);
327}
328
329static int cx18_s_fmt_sliced_vbi_cap(struct file *file, void *fh,
330 struct v4l2_format *fmt)
331{
0b5f265a 332 struct cx18_open_id *id = fh2id(fh);
302df970
AW
333 struct cx18 *cx = id->cx;
334 int ret;
335 struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced;
336
c1994084 337 cx18_try_fmt_sliced_vbi_cap(file, fh, fmt);
302df970 338
dcc0ef88
AW
339 /*
340 * Changing the Encoder's Raw VBI parameters won't have any effect
341 * if any analog capture is ongoing
342 */
343 if (cx18_raw_vbi(cx) && atomic_read(&cx->ana_capturing) > 0)
302df970 344 return -EBUSY;
dcc0ef88 345
c1994084
AW
346 /*
347 * Set the service_lines requested in the digitizer/slicer registers.
348 * Note, cx18_av_vbi() wipes some "impossible" service lines in the
349 * passed in fmt->fmt.sliced under valid calling conditions
350 */
add632cd 351 ret = v4l2_subdev_call(cx->sd_av, vbi, s_sliced_fmt, &fmt->fmt.sliced);
c1994084
AW
352 if (ret)
353 return ret;
354 /* Store our current v4l2 sliced VBI settings */
302df970 355 cx->vbi.in.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE;
302df970
AW
356 memcpy(cx->vbi.sliced_in, vbifmt, sizeof(*cx->vbi.sliced_in));
357 return 0;
3b6fe58f
AW
358}
359
360static int cx18_g_chip_ident(struct file *file, void *fh,
aecde8b5 361 struct v4l2_dbg_chip_ident *chip)
3b6fe58f 362{
0b5f265a 363 struct cx18 *cx = fh2id(fh)->cx;
ff2a2001 364 int err = 0;
3b6fe58f 365
3b6fe58f
AW
366 chip->ident = V4L2_IDENT_NONE;
367 chip->revision = 0;
ff2a2001
AW
368 switch (chip->match.type) {
369 case V4L2_CHIP_MATCH_HOST:
370 switch (chip->match.addr) {
371 case 0:
372 chip->ident = V4L2_IDENT_CX23418;
373 chip->revision = cx18_read_reg(cx, 0xC72028);
374 break;
375 case 1:
376 /*
377 * The A/V decoder is always present, but in the rare
378 * case that the card doesn't have analog, we don't
379 * use it. We find it w/o using the cx->sd_av pointer
380 */
381 cx18_call_hw(cx, CX18_HW_418_AV,
382 core, g_chip_ident, chip);
383 break;
384 default:
385 /*
386 * Could return ident = V4L2_IDENT_UNKNOWN if we had
387 * other host chips at higher addresses, but we don't
388 */
389 err = -EINVAL; /* per V4L2 spec */
390 break;
391 }
392 break;
393 case V4L2_CHIP_MATCH_I2C_DRIVER:
394 /* If needed, returns V4L2_IDENT_AMBIGUOUS without extra work */
395 cx18_call_all(cx, core, g_chip_ident, chip);
396 break;
397 case V4L2_CHIP_MATCH_I2C_ADDR:
398 /*
399 * We could return V4L2_IDENT_UNKNOWN, but we don't do the work
400 * to look if a chip is at the address with no driver. That's a
401 * dangerous thing to do with EEPROMs anyway.
402 */
403 cx18_call_all(cx, core, g_chip_ident, chip);
404 break;
405 default:
406 err = -EINVAL;
407 break;
1c1e45d1 408 }
ff2a2001 409 return err;
3b6fe58f
AW
410}
411
36ecd495
HV
412#ifdef CONFIG_VIDEO_ADV_DEBUG
413static int cx18_cxc(struct cx18 *cx, unsigned int cmd, void *arg)
414{
aecde8b5 415 struct v4l2_dbg_register *regs = arg;
36ecd495
HV
416
417 if (!capable(CAP_SYS_ADMIN))
418 return -EPERM;
419 if (regs->reg >= CX18_MEM_OFFSET + CX18_MEM_SIZE)
420 return -EINVAL;
421
aecde8b5 422 regs->size = 4;
ff2a2001 423 if (cmd == VIDIOC_DBG_S_REGISTER)
b1526421 424 cx18_write_enc(cx, regs->val, regs->reg);
ff2a2001
AW
425 else
426 regs->val = cx18_read_enc(cx, regs->reg);
36ecd495
HV
427 return 0;
428}
429
3b6fe58f 430static int cx18_g_register(struct file *file, void *fh,
aecde8b5 431 struct v4l2_dbg_register *reg)
3b6fe58f 432{
0b5f265a 433 struct cx18 *cx = fh2id(fh)->cx;
3b6fe58f 434
aecde8b5 435 if (v4l2_chip_match_host(&reg->match))
3b6fe58f 436 return cx18_cxc(cx, VIDIOC_DBG_G_REGISTER, reg);
ff2a2001
AW
437 /* FIXME - errors shouldn't be ignored */
438 cx18_call_all(cx, core, g_register, reg);
aecde8b5 439 return 0;
3b6fe58f
AW
440}
441
442static int cx18_s_register(struct file *file, void *fh,
aecde8b5 443 struct v4l2_dbg_register *reg)
3b6fe58f 444{
0b5f265a 445 struct cx18 *cx = fh2id(fh)->cx;
3b6fe58f 446
aecde8b5 447 if (v4l2_chip_match_host(&reg->match))
3b6fe58f 448 return cx18_cxc(cx, VIDIOC_DBG_S_REGISTER, reg);
ff2a2001
AW
449 /* FIXME - errors shouldn't be ignored */
450 cx18_call_all(cx, core, s_register, reg);
aecde8b5 451 return 0;
3b6fe58f 452}
36ecd495 453#endif
3b6fe58f 454
3b6fe58f
AW
455static int cx18_querycap(struct file *file, void *fh,
456 struct v4l2_capability *vcap)
457{
0b5f265a 458 struct cx18 *cx = fh2id(fh)->cx;
1c1e45d1 459
3b6fe58f
AW
460 strlcpy(vcap->driver, CX18_DRIVER_NAME, sizeof(vcap->driver));
461 strlcpy(vcap->card, cx->card_name, sizeof(vcap->card));
3d05913d
AW
462 snprintf(vcap->bus_info, sizeof(vcap->bus_info),
463 "PCI:%s", pci_name(cx->pci_dev));
3b6fe58f
AW
464 vcap->version = CX18_DRIVER_VERSION; /* version */
465 vcap->capabilities = cx->v4l2_cap; /* capabilities */
466 return 0;
467}
1c1e45d1 468
3b6fe58f
AW
469static int cx18_enumaudio(struct file *file, void *fh, struct v4l2_audio *vin)
470{
0b5f265a 471 struct cx18 *cx = fh2id(fh)->cx;
1c1e45d1 472
3b6fe58f
AW
473 return cx18_get_audio_input(cx, vin->index, vin);
474}
1c1e45d1 475
3b6fe58f
AW
476static int cx18_g_audio(struct file *file, void *fh, struct v4l2_audio *vin)
477{
0b5f265a 478 struct cx18 *cx = fh2id(fh)->cx;
1c1e45d1 479
3b6fe58f
AW
480 vin->index = cx->audio_input;
481 return cx18_get_audio_input(cx, vin->index, vin);
482}
1c1e45d1 483
3b6fe58f
AW
484static int cx18_s_audio(struct file *file, void *fh, struct v4l2_audio *vout)
485{
0b5f265a 486 struct cx18 *cx = fh2id(fh)->cx;
1c1e45d1 487
3b6fe58f
AW
488 if (vout->index >= cx->nof_audio_inputs)
489 return -EINVAL;
490 cx->audio_input = vout->index;
491 cx18_audio_set_io(cx);
492 return 0;
493}
1c1e45d1 494
3b6fe58f
AW
495static int cx18_enum_input(struct file *file, void *fh, struct v4l2_input *vin)
496{
0b5f265a 497 struct cx18 *cx = fh2id(fh)->cx;
1c1e45d1 498
3b6fe58f
AW
499 /* set it to defaults from our table */
500 return cx18_get_input(cx, vin->index, vin);
501}
1c1e45d1 502
3b6fe58f
AW
503static int cx18_cropcap(struct file *file, void *fh,
504 struct v4l2_cropcap *cropcap)
505{
0b5f265a 506 struct cx18 *cx = fh2id(fh)->cx;
1c1e45d1 507
3b6fe58f
AW
508 if (cropcap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
509 return -EINVAL;
510 cropcap->bounds.top = cropcap->bounds.left = 0;
511 cropcap->bounds.width = 720;
512 cropcap->bounds.height = cx->is_50hz ? 576 : 480;
513 cropcap->pixelaspect.numerator = cx->is_50hz ? 59 : 10;
514 cropcap->pixelaspect.denominator = cx->is_50hz ? 54 : 11;
515 cropcap->defrect = cropcap->bounds;
516 return 0;
517}
1c1e45d1 518
3b6fe58f
AW
519static int cx18_s_crop(struct file *file, void *fh, struct v4l2_crop *crop)
520{
0b5f265a 521 struct cx18_open_id *id = fh2id(fh);
3b6fe58f 522 struct cx18 *cx = id->cx;
1c1e45d1 523
3b6fe58f
AW
524 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
525 return -EINVAL;
fa3e7036
AW
526 CX18_DEBUG_WARN("VIDIOC_S_CROP not implemented\n");
527 return -EINVAL;
3b6fe58f 528}
1c1e45d1 529
3b6fe58f
AW
530static int cx18_g_crop(struct file *file, void *fh, struct v4l2_crop *crop)
531{
0b5f265a 532 struct cx18 *cx = fh2id(fh)->cx;
1c1e45d1 533
3b6fe58f
AW
534 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
535 return -EINVAL;
fa3e7036
AW
536 CX18_DEBUG_WARN("VIDIOC_G_CROP not implemented\n");
537 return -EINVAL;
3b6fe58f
AW
538}
539
540static int cx18_enum_fmt_vid_cap(struct file *file, void *fh,
541 struct v4l2_fmtdesc *fmt)
542{
543 static struct v4l2_fmtdesc formats[] = {
544 { 0, V4L2_BUF_TYPE_VIDEO_CAPTURE, 0,
545 "HM12 (YUV 4:1:1)", V4L2_PIX_FMT_HM12, { 0, 0, 0, 0 }
546 },
547 { 1, V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FMT_FLAG_COMPRESSED,
548 "MPEG", V4L2_PIX_FMT_MPEG, { 0, 0, 0, 0 }
1c1e45d1 549 }
3b6fe58f
AW
550 };
551
3b6fe58f
AW
552 if (fmt->index > 1)
553 return -EINVAL;
554 *fmt = formats[fmt->index];
555 return 0;
556}
557
558static int cx18_g_input(struct file *file, void *fh, unsigned int *i)
559{
0b5f265a 560 struct cx18 *cx = fh2id(fh)->cx;
3b6fe58f 561
3b6fe58f
AW
562 *i = cx->active_input;
563 return 0;
564}
565
566int cx18_s_input(struct file *file, void *fh, unsigned int inp)
567{
0b5f265a 568 struct cx18_open_id *id = fh2id(fh);
3b6fe58f 569 struct cx18 *cx = id->cx;
3b6fe58f 570
de81c3c3 571 if (inp >= cx->nof_inputs)
3b6fe58f
AW
572 return -EINVAL;
573
574 if (inp == cx->active_input) {
575 CX18_DEBUG_INFO("Input unchanged\n");
1c1e45d1
HV
576 return 0;
577 }
578
3b6fe58f
AW
579 CX18_DEBUG_INFO("Changing input from %d to %d\n",
580 cx->active_input, inp);
1c1e45d1 581
3b6fe58f
AW
582 cx->active_input = inp;
583 /* Set the audio input to whatever is appropriate for the input type. */
584 cx->audio_input = cx->card->video_inputs[inp].audio_index;
1c1e45d1 585
3b6fe58f
AW
586 /* prevent others from messing with the streams until
587 we're finished changing inputs. */
588 cx18_mute(cx);
589 cx18_video_set_io(cx);
590 cx18_audio_set_io(cx);
591 cx18_unmute(cx);
592 return 0;
593}
1c1e45d1 594
3b6fe58f
AW
595static int cx18_g_frequency(struct file *file, void *fh,
596 struct v4l2_frequency *vf)
597{
0b5f265a 598 struct cx18 *cx = fh2id(fh)->cx;
1c1e45d1 599
3b6fe58f
AW
600 if (vf->tuner != 0)
601 return -EINVAL;
1c1e45d1 602
ff2a2001 603 cx18_call_all(cx, tuner, g_frequency, vf);
3b6fe58f
AW
604 return 0;
605}
1c1e45d1 606
3b6fe58f
AW
607int cx18_s_frequency(struct file *file, void *fh, struct v4l2_frequency *vf)
608{
0b5f265a 609 struct cx18_open_id *id = fh2id(fh);
3b6fe58f 610 struct cx18 *cx = id->cx;
1c1e45d1 611
3b6fe58f
AW
612 if (vf->tuner != 0)
613 return -EINVAL;
1c1e45d1 614
3b6fe58f
AW
615 cx18_mute(cx);
616 CX18_DEBUG_INFO("v4l2 ioctl: set frequency %d\n", vf->frequency);
ff2a2001 617 cx18_call_all(cx, tuner, s_frequency, vf);
3b6fe58f
AW
618 cx18_unmute(cx);
619 return 0;
620}
1c1e45d1 621
3b6fe58f
AW
622static int cx18_g_std(struct file *file, void *fh, v4l2_std_id *std)
623{
0b5f265a 624 struct cx18 *cx = fh2id(fh)->cx;
1c1e45d1 625
3b6fe58f
AW
626 *std = cx->std;
627 return 0;
628}
1c1e45d1 629
3b6fe58f
AW
630int cx18_s_std(struct file *file, void *fh, v4l2_std_id *std)
631{
0b5f265a 632 struct cx18_open_id *id = fh2id(fh);
3b6fe58f 633 struct cx18 *cx = id->cx;
1c1e45d1 634
3b6fe58f
AW
635 if ((*std & V4L2_STD_ALL) == 0)
636 return -EINVAL;
1c1e45d1 637
3b6fe58f
AW
638 if (*std == cx->std)
639 return 0;
640
641 if (test_bit(CX18_F_I_RADIO_USER, &cx->i_flags) ||
642 atomic_read(&cx->ana_capturing) > 0) {
643 /* Switching standard would turn off the radio or mess
644 with already running streams, prevent that by
645 returning EBUSY. */
646 return -EBUSY;
1c1e45d1
HV
647 }
648
3b6fe58f
AW
649 cx->std = *std;
650 cx->is_60hz = (*std & V4L2_STD_525_60) ? 1 : 0;
a75b9be1
HV
651 cx->is_50hz = !cx->is_60hz;
652 cx2341x_handler_set_50hz(&cx->cxhdl, cx->is_50hz);
653 cx->cxhdl.width = 720;
654 cx->cxhdl.height = cx->is_50hz ? 576 : 480;
3b6fe58f
AW
655 cx->vbi.count = cx->is_50hz ? 18 : 12;
656 cx->vbi.start[0] = cx->is_50hz ? 6 : 10;
657 cx->vbi.start[1] = cx->is_50hz ? 318 : 273;
3b6fe58f
AW
658 CX18_DEBUG_INFO("Switching standard to %llx.\n",
659 (unsigned long long) cx->std);
660
661 /* Tuner */
f41737ec 662 cx18_call_all(cx, core, s_std, cx->std);
3b6fe58f
AW
663 return 0;
664}
1c1e45d1 665
3b6fe58f
AW
666static int cx18_s_tuner(struct file *file, void *fh, struct v4l2_tuner *vt)
667{
0b5f265a 668 struct cx18_open_id *id = fh2id(fh);
3b6fe58f 669 struct cx18 *cx = id->cx;
3b6fe58f 670
3b6fe58f
AW
671 if (vt->index != 0)
672 return -EINVAL;
673
ff2a2001 674 cx18_call_all(cx, tuner, s_tuner, vt);
3b6fe58f
AW
675 return 0;
676}
677
678static int cx18_g_tuner(struct file *file, void *fh, struct v4l2_tuner *vt)
679{
0b5f265a 680 struct cx18 *cx = fh2id(fh)->cx;
3b6fe58f 681
3b6fe58f
AW
682 if (vt->index != 0)
683 return -EINVAL;
684
ff2a2001 685 cx18_call_all(cx, tuner, g_tuner, vt);
3b6fe58f
AW
686
687 if (test_bit(CX18_F_I_RADIO_USER, &cx->i_flags)) {
688 strlcpy(vt->name, "cx18 Radio Tuner", sizeof(vt->name));
689 vt->type = V4L2_TUNER_RADIO;
690 } else {
691 strlcpy(vt->name, "cx18 TV Tuner", sizeof(vt->name));
692 vt->type = V4L2_TUNER_ANALOG_TV;
1c1e45d1
HV
693 }
694
3b6fe58f
AW
695 return 0;
696}
697
698static int cx18_g_sliced_vbi_cap(struct file *file, void *fh,
699 struct v4l2_sliced_vbi_cap *cap)
700{
0b5f265a 701 struct cx18 *cx = fh2id(fh)->cx;
302df970
AW
702 int set = cx->is_50hz ? V4L2_SLICED_VBI_625 : V4L2_SLICED_VBI_525;
703 int f, l;
704
c1994084
AW
705 if (cap->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE)
706 return -EINVAL;
707
708 cap->service_set = 0;
709 for (f = 0; f < 2; f++) {
710 for (l = 0; l < 24; l++) {
711 if (valid_service_line(f, l, cx->is_50hz)) {
712 /*
713 * We can find all v4l2 supported vbi services
714 * for the standard, on a valid line for the std
715 */
716 cap->service_lines[f][l] = set;
717 cap->service_set |= set;
718 } else
719 cap->service_lines[f][l] = 0;
302df970 720 }
302df970 721 }
c1994084
AW
722 for (f = 0; f < 3; f++)
723 cap->reserved[f] = 0;
724 return 0;
3b6fe58f 725}
1c1e45d1 726
82acdc84
AW
727static int _cx18_process_idx_data(struct cx18_buffer *buf,
728 struct v4l2_enc_idx *idx)
729{
730 int consumed, remaining;
731 struct v4l2_enc_idx_entry *e_idx;
732 struct cx18_enc_idx_entry *e_buf;
733
734 /* Frame type lookup: 1=I, 2=P, 4=B */
735 const int mapping[8] = {
736 -1, V4L2_ENC_IDX_FRAME_I, V4L2_ENC_IDX_FRAME_P,
737 -1, V4L2_ENC_IDX_FRAME_B, -1, -1, -1
738 };
739
740 /*
741 * Assumption here is that a buf holds an integral number of
742 * struct cx18_enc_idx_entry objects and is properly aligned.
743 * This is enforced by the module options on IDX buffer sizes.
744 */
745 remaining = buf->bytesused - buf->readpos;
746 consumed = 0;
747 e_idx = &idx->entry[idx->entries];
748 e_buf = (struct cx18_enc_idx_entry *) &buf->buf[buf->readpos];
749
750 while (remaining >= sizeof(struct cx18_enc_idx_entry) &&
751 idx->entries < V4L2_ENC_IDX_ENTRIES) {
752
753 e_idx->offset = (((u64) le32_to_cpu(e_buf->offset_high)) << 32)
754 | le32_to_cpu(e_buf->offset_low);
755
756 e_idx->pts = (((u64) (le32_to_cpu(e_buf->pts_high) & 1)) << 32)
757 | le32_to_cpu(e_buf->pts_low);
758
759 e_idx->length = le32_to_cpu(e_buf->length);
760
761 e_idx->flags = mapping[le32_to_cpu(e_buf->flags) & 0x7];
762
763 e_idx->reserved[0] = 0;
764 e_idx->reserved[1] = 0;
765
766 idx->entries++;
767 e_idx = &idx->entry[idx->entries];
768 e_buf++;
769
770 remaining -= sizeof(struct cx18_enc_idx_entry);
771 consumed += sizeof(struct cx18_enc_idx_entry);
772 }
773
774 /* Swallow any partial entries at the end, if there are any */
775 if (remaining > 0 && remaining < sizeof(struct cx18_enc_idx_entry))
776 consumed += remaining;
777
778 buf->readpos += consumed;
779 return consumed;
780}
781
782static int cx18_process_idx_data(struct cx18_stream *s, struct cx18_mdl *mdl,
783 struct v4l2_enc_idx *idx)
784{
785 if (s->type != CX18_ENC_STREAM_TYPE_IDX)
786 return -EINVAL;
787
788 if (mdl->curr_buf == NULL)
789 mdl->curr_buf = list_first_entry(&mdl->buf_list,
790 struct cx18_buffer, list);
791
792 if (list_entry_is_past_end(mdl->curr_buf, &mdl->buf_list, list)) {
793 /*
794 * For some reason we've exhausted the buffers, but the MDL
795 * object still said some data was unread.
796 * Fix that and bail out.
797 */
798 mdl->readpos = mdl->bytesused;
799 return 0;
800 }
801
802 list_for_each_entry_from(mdl->curr_buf, &mdl->buf_list, list) {
803
804 /* Skip any empty buffers in the MDL */
805 if (mdl->curr_buf->readpos >= mdl->curr_buf->bytesused)
806 continue;
807
808 mdl->readpos += _cx18_process_idx_data(mdl->curr_buf, idx);
809
810 /* exit when MDL drained or request satisfied */
811 if (idx->entries >= V4L2_ENC_IDX_ENTRIES ||
812 mdl->curr_buf->readpos < mdl->curr_buf->bytesused ||
813 mdl->readpos >= mdl->bytesused)
814 break;
815 }
816 return 0;
817}
818
3b6fe58f
AW
819static int cx18_g_enc_index(struct file *file, void *fh,
820 struct v4l2_enc_idx *idx)
821{
0b5f265a 822 struct cx18 *cx = fh2id(fh)->cx;
82acdc84
AW
823 struct cx18_stream *s = &cx->streams[CX18_ENC_STREAM_TYPE_IDX];
824 s32 tmp;
825 struct cx18_mdl *mdl;
826
827 if (!cx18_stream_enabled(s)) /* Module options inhibited IDX stream */
828 return -EINVAL;
829
830 /* Compute the best case number of entries we can buffer */
831 tmp = s->buffers -
832 s->bufs_per_mdl * CX18_ENC_STREAM_TYPE_IDX_FW_MDL_MIN;
833 if (tmp <= 0)
834 tmp = 1;
835 tmp = tmp * s->buf_size / sizeof(struct cx18_enc_idx_entry);
836
837 /* Fill out the header of the return structure */
838 idx->entries = 0;
839 idx->entries_cap = tmp;
840 memset(idx->reserved, 0, sizeof(idx->reserved));
841
842 /* Pull IDX MDLs and buffers from q_full and populate the entries */
843 do {
844 mdl = cx18_dequeue(s, &s->q_full);
845 if (mdl == NULL) /* No more IDX data right now */
846 break;
847
848 /* Extract the Index entry data from the MDL and buffers */
849 cx18_process_idx_data(s, mdl, idx);
850 if (mdl->readpos < mdl->bytesused) {
851 /* We finished with data remaining, push the MDL back */
852 cx18_push(s, mdl, &s->q_full);
853 break;
854 }
855
856 /* We drained this MDL, schedule it to go to the firmware */
857 cx18_enqueue(s, mdl, &s->q_free);
858
859 } while (idx->entries < V4L2_ENC_IDX_ENTRIES);
860
861 /* Tell the work handler to send free IDX MDLs to the firmware */
862 cx18_stream_load_fw_queue(s);
863 return 0;
3b6fe58f 864}
1c1e45d1 865
3b6fe58f
AW
866static int cx18_encoder_cmd(struct file *file, void *fh,
867 struct v4l2_encoder_cmd *enc)
868{
0b5f265a 869 struct cx18_open_id *id = fh2id(fh);
3b6fe58f 870 struct cx18 *cx = id->cx;
d3c5e707 871 u32 h;
1c1e45d1 872
3b6fe58f
AW
873 switch (enc->cmd) {
874 case V4L2_ENC_CMD_START:
875 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_START\n");
876 enc->flags = 0;
877 return cx18_start_capture(id);
878
879 case V4L2_ENC_CMD_STOP:
880 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_STOP\n");
881 enc->flags &= V4L2_ENC_CMD_STOP_AT_GOP_END;
882 cx18_stop_capture(id,
883 enc->flags & V4L2_ENC_CMD_STOP_AT_GOP_END);
1c1e45d1 884 break;
1c1e45d1 885
3b6fe58f
AW
886 case V4L2_ENC_CMD_PAUSE:
887 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_PAUSE\n");
888 enc->flags = 0;
889 if (!atomic_read(&cx->ana_capturing))
890 return -EPERM;
891 if (test_and_set_bit(CX18_F_I_ENC_PAUSED, &cx->i_flags))
1c1e45d1 892 return 0;
d3c5e707
AW
893 h = cx18_find_handle(cx);
894 if (h == CX18_INVALID_TASK_HANDLE) {
895 CX18_ERR("Can't find valid task handle for "
896 "V4L2_ENC_CMD_PAUSE\n");
897 return -EBADFD;
898 }
3b6fe58f 899 cx18_mute(cx);
d3c5e707 900 cx18_vapi(cx, CX18_CPU_CAPTURE_PAUSE, 1, h);
3b6fe58f
AW
901 break;
902
903 case V4L2_ENC_CMD_RESUME:
904 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_RESUME\n");
905 enc->flags = 0;
906 if (!atomic_read(&cx->ana_capturing))
907 return -EPERM;
908 if (!test_and_clear_bit(CX18_F_I_ENC_PAUSED, &cx->i_flags))
909 return 0;
d3c5e707
AW
910 h = cx18_find_handle(cx);
911 if (h == CX18_INVALID_TASK_HANDLE) {
912 CX18_ERR("Can't find valid task handle for "
913 "V4L2_ENC_CMD_RESUME\n");
914 return -EBADFD;
915 }
916 cx18_vapi(cx, CX18_CPU_CAPTURE_RESUME, 1, h);
3b6fe58f
AW
917 cx18_unmute(cx);
918 break;
919
920 default:
921 CX18_DEBUG_IOCTL("Unknown cmd %d\n", enc->cmd);
1c1e45d1
HV
922 return -EINVAL;
923 }
3b6fe58f
AW
924 return 0;
925}
1c1e45d1 926
3b6fe58f
AW
927static int cx18_try_encoder_cmd(struct file *file, void *fh,
928 struct v4l2_encoder_cmd *enc)
929{
0b5f265a 930 struct cx18 *cx = fh2id(fh)->cx;
1c1e45d1 931
3b6fe58f
AW
932 switch (enc->cmd) {
933 case V4L2_ENC_CMD_START:
934 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_START\n");
935 enc->flags = 0;
1c1e45d1 936 break;
1c1e45d1 937
3b6fe58f
AW
938 case V4L2_ENC_CMD_STOP:
939 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_STOP\n");
940 enc->flags &= V4L2_ENC_CMD_STOP_AT_GOP_END;
941 break;
1c1e45d1 942
3b6fe58f
AW
943 case V4L2_ENC_CMD_PAUSE:
944 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_PAUSE\n");
945 enc->flags = 0;
946 break;
1c1e45d1 947
3b6fe58f
AW
948 case V4L2_ENC_CMD_RESUME:
949 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_RESUME\n");
950 enc->flags = 0;
1c1e45d1 951 break;
1c1e45d1
HV
952
953 default:
3b6fe58f 954 CX18_DEBUG_IOCTL("Unknown cmd %d\n", enc->cmd);
1c1e45d1
HV
955 return -EINVAL;
956 }
957 return 0;
958}
959
3b6fe58f 960static int cx18_log_status(struct file *file, void *fh)
1c1e45d1 961{
0b5f265a 962 struct cx18 *cx = fh2id(fh)->cx;
3b6fe58f
AW
963 struct v4l2_input vidin;
964 struct v4l2_audio audin;
965 int i;
1c1e45d1 966
e0f28b6a 967 CX18_INFO("================= START STATUS CARD #%d "
5811cf99 968 "=================\n", cx->instance);
e0f28b6a 969 CX18_INFO("Version: %s Card: %s\n", CX18_VERSION, cx->card_name);
3b6fe58f
AW
970 if (cx->hw_flags & CX18_HW_TVEEPROM) {
971 struct tveeprom tv;
972
973 cx18_read_eeprom(cx, &tv);
974 }
ff2a2001 975 cx18_call_all(cx, core, log_status);
3b6fe58f
AW
976 cx18_get_input(cx, cx->active_input, &vidin);
977 cx18_get_audio_input(cx, cx->audio_input, &audin);
978 CX18_INFO("Video Input: %s\n", vidin.name);
979 CX18_INFO("Audio Input: %s\n", audin.name);
8abdd00d 980 mutex_lock(&cx->gpio_lock);
3d66c405
HV
981 CX18_INFO("GPIO: direction 0x%08x, value 0x%08x\n",
982 cx->gpio_dir, cx->gpio_val);
8abdd00d 983 mutex_unlock(&cx->gpio_lock);
3b6fe58f
AW
984 CX18_INFO("Tuner: %s\n",
985 test_bit(CX18_F_I_RADIO_USER, &cx->i_flags) ? "Radio" : "TV");
a75b9be1 986 v4l2_ctrl_handler_log_status(&cx->cxhdl.hdl, cx->v4l2_dev.name);
3b6fe58f
AW
987 CX18_INFO("Status flags: 0x%08lx\n", cx->i_flags);
988 for (i = 0; i < CX18_MAX_STREAMS; i++) {
989 struct cx18_stream *s = &cx->streams[i];
990
3d05913d 991 if (s->video_dev == NULL || s->buffers == 0)
3b6fe58f
AW
992 continue;
993 CX18_INFO("Stream %s: status 0x%04lx, %d%% of %d KiB (%d buffers) in use\n",
994 s->name, s->s_flags,
52fcb3ec
AW
995 atomic_read(&s->q_full.depth) * s->bufs_per_mdl * 100
996 / s->buffers,
3b6fe58f
AW
997 (s->buffers * s->buf_size) / 1024, s->buffers);
998 }
999 CX18_INFO("Read MPEG/VBI: %lld/%lld bytes\n",
1000 (long long)cx->mpg_data_received,
1001 (long long)cx->vbi_data_inserted);
5811cf99
AW
1002 CX18_INFO("================== END STATUS CARD #%d "
1003 "==================\n", cx->instance);
3b6fe58f
AW
1004 return 0;
1005}
1006
99cd47bc
HV
1007static long cx18_default(struct file *file, void *fh, bool valid_prio,
1008 int cmd, void *arg)
3b6fe58f 1009{
0b5f265a 1010 struct cx18 *cx = fh2id(fh)->cx;
1c1e45d1
HV
1011
1012 switch (cmd) {
02fa272f
AW
1013 case VIDIOC_INT_RESET: {
1014 u32 val = *(u32 *)arg;
1015
1016 if ((val == 0) || (val & 0x01))
eefe1010
AW
1017 cx18_call_hw(cx, CX18_HW_GPIO_RESET_CTRL, core, reset,
1018 (u32) CX18_GPIO_RESET_Z8F0811);
02fa272f
AW
1019 break;
1020 }
1021
3b6fe58f 1022 default:
1c1e45d1 1023 return -EINVAL;
1c1e45d1
HV
1024 }
1025 return 0;
1026}
1027
069b7479 1028long cx18_v4l2_ioctl(struct file *filp, unsigned int cmd,
1c1e45d1
HV
1029 unsigned long arg)
1030{
37f89f95 1031 struct video_device *vfd = video_devdata(filp);
0b5f265a 1032 struct cx18_open_id *id = file2id(filp);
1c1e45d1 1033 struct cx18 *cx = id->cx;
069b7479 1034 long res;
1c1e45d1
HV
1035
1036 mutex_lock(&cx->serialize_lock);
37f89f95
HV
1037
1038 if (cx18_debug & CX18_DBGFLG_IOCTL)
1039 vfd->debug = V4L2_DEBUG_IOCTL | V4L2_DEBUG_IOCTL_ARG;
bec43661 1040 res = video_ioctl2(filp, cmd, arg);
37f89f95 1041 vfd->debug = 0;
1c1e45d1
HV
1042 mutex_unlock(&cx->serialize_lock);
1043 return res;
1044}
3b6fe58f 1045
a399810c
HV
1046static const struct v4l2_ioctl_ops cx18_ioctl_ops = {
1047 .vidioc_querycap = cx18_querycap,
a399810c
HV
1048 .vidioc_s_audio = cx18_s_audio,
1049 .vidioc_g_audio = cx18_g_audio,
1050 .vidioc_enumaudio = cx18_enumaudio,
1051 .vidioc_enum_input = cx18_enum_input,
1052 .vidioc_cropcap = cx18_cropcap,
1053 .vidioc_s_crop = cx18_s_crop,
1054 .vidioc_g_crop = cx18_g_crop,
1055 .vidioc_g_input = cx18_g_input,
1056 .vidioc_s_input = cx18_s_input,
1057 .vidioc_g_frequency = cx18_g_frequency,
1058 .vidioc_s_frequency = cx18_s_frequency,
1059 .vidioc_s_tuner = cx18_s_tuner,
1060 .vidioc_g_tuner = cx18_g_tuner,
1061 .vidioc_g_enc_index = cx18_g_enc_index,
1062 .vidioc_g_std = cx18_g_std,
1063 .vidioc_s_std = cx18_s_std,
1064 .vidioc_log_status = cx18_log_status,
1065 .vidioc_enum_fmt_vid_cap = cx18_enum_fmt_vid_cap,
1066 .vidioc_encoder_cmd = cx18_encoder_cmd,
1067 .vidioc_try_encoder_cmd = cx18_try_encoder_cmd,
1068 .vidioc_g_fmt_vid_cap = cx18_g_fmt_vid_cap,
1069 .vidioc_g_fmt_vbi_cap = cx18_g_fmt_vbi_cap,
1070 .vidioc_g_fmt_sliced_vbi_cap = cx18_g_fmt_sliced_vbi_cap,
1071 .vidioc_s_fmt_vid_cap = cx18_s_fmt_vid_cap,
1072 .vidioc_s_fmt_vbi_cap = cx18_s_fmt_vbi_cap,
1073 .vidioc_s_fmt_sliced_vbi_cap = cx18_s_fmt_sliced_vbi_cap,
1074 .vidioc_try_fmt_vid_cap = cx18_try_fmt_vid_cap,
1075 .vidioc_try_fmt_vbi_cap = cx18_try_fmt_vbi_cap,
1076 .vidioc_try_fmt_sliced_vbi_cap = cx18_try_fmt_sliced_vbi_cap,
1077 .vidioc_g_sliced_vbi_cap = cx18_g_sliced_vbi_cap,
1078 .vidioc_g_chip_ident = cx18_g_chip_ident,
36ecd495 1079#ifdef CONFIG_VIDEO_ADV_DEBUG
a399810c
HV
1080 .vidioc_g_register = cx18_g_register,
1081 .vidioc_s_register = cx18_s_register,
36ecd495 1082#endif
a399810c 1083 .vidioc_default = cx18_default,
a399810c
HV
1084};
1085
1086void cx18_set_funcs(struct video_device *vdev)
1087{
1088 vdev->ioctl_ops = &cx18_ioctl_ops;
3b6fe58f 1089}