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