blob: 0f0cd560226c0889aaee99fa524484a17e29b086 [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 Walls3b6fe58f2008-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 Walls3b6fe58f2008-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 Walls3b6fe58f2008-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;
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300163 /* YUV size is (Y=(h*w) + UV=(h*(w/2))) */
Hans Verkuil0b5a30e2008-06-21 09:22:19 -0300164 pixfmt->sizeimage =
165 pixfmt->height * pixfmt->width +
166 pixfmt->height * (pixfmt->width / 2);
167 pixfmt->bytesperline = 720;
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300168 } else {
Hans Verkuil0b5a30e2008-06-21 09:22:19 -0300169 pixfmt->pixelformat = V4L2_PIX_FMT_MPEG;
170 pixfmt->sizeimage = 128 * 1024;
171 pixfmt->bytesperline = 0;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300172 }
173 return 0;
174}
175
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300176static int cx18_g_fmt_vbi_cap(struct file *file, void *fh,
177 struct v4l2_format *fmt)
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300178{
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300179 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
Hans Verkuil0b5a30e2008-06-21 09:22:19 -0300180 struct v4l2_vbi_format *vbifmt = &fmt->fmt.vbi;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300181
Hans Verkuil0b5a30e2008-06-21 09:22:19 -0300182 vbifmt->sampling_rate = 27000000;
Andy Wallsc1994082009-02-05 22:37:49 -0300183 vbifmt->offset = 248; /* FIXME - slightly wrong for both 50 & 60 Hz */
Andy Walls302df972009-01-31 00:33:02 -0300184 vbifmt->samples_per_line = vbi_active_samples - 4;
Hans Verkuil0b5a30e2008-06-21 09:22:19 -0300185 vbifmt->sample_format = V4L2_PIX_FMT_GREY;
186 vbifmt->start[0] = cx->vbi.start[0];
187 vbifmt->start[1] = cx->vbi.start[1];
188 vbifmt->count[0] = vbifmt->count[1] = cx->vbi.count;
189 vbifmt->flags = 0;
190 vbifmt->reserved[0] = 0;
191 vbifmt->reserved[1] = 0;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300192 return 0;
193}
194
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300195static int cx18_g_fmt_sliced_vbi_cap(struct file *file, void *fh,
196 struct v4l2_format *fmt)
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300197{
Andy Walls302df972009-01-31 00:33:02 -0300198 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
199 struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced;
200
Andy Wallsc1994082009-02-05 22:37:49 -0300201 /* sane, V4L2 spec compliant, defaults */
Andy Walls302df972009-01-31 00:33:02 -0300202 vbifmt->reserved[0] = 0;
203 vbifmt->reserved[1] = 0;
204 vbifmt->io_size = sizeof(struct v4l2_sliced_vbi_data) * 36;
205 memset(vbifmt->service_lines, 0, sizeof(vbifmt->service_lines));
Andy Wallsc1994082009-02-05 22:37:49 -0300206 vbifmt->service_set = 0;
Andy Walls302df972009-01-31 00:33:02 -0300207
Andy Wallsc1994082009-02-05 22:37:49 -0300208 /*
209 * Fetch the configured service_lines and total service_set from the
210 * digitizer/slicer. Note, cx18_av_vbi() wipes the passed in
211 * fmt->fmt.sliced under valid calling conditions
212 */
213 if (cx18_av_cmd(cx, VIDIOC_G_FMT, fmt))
214 return -EINVAL;
215
216 /* Ensure V4L2 spec compliant output */
217 vbifmt->reserved[0] = 0;
218 vbifmt->reserved[1] = 0;
219 vbifmt->io_size = sizeof(struct v4l2_sliced_vbi_data) * 36;
Andy Walls302df972009-01-31 00:33:02 -0300220 vbifmt->service_set = cx18_get_service_set(vbifmt);
221 return 0;
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300222}
223
224static int cx18_try_fmt_vid_cap(struct file *file, void *fh,
225 struct v4l2_format *fmt)
226{
227 struct cx18_open_id *id = fh;
228 struct cx18 *cx = id->cx;
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300229 int w = fmt->fmt.pix.width;
230 int h = fmt->fmt.pix.height;
231
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300232 w = min(w, 720);
233 w = max(w, 1);
234 h = min(h, cx->is_50hz ? 576 : 480);
235 h = max(h, 2);
236 cx18_g_fmt_vid_cap(file, fh, fmt);
237 fmt->fmt.pix.width = w;
238 fmt->fmt.pix.height = h;
239 return 0;
240}
241
242static int cx18_try_fmt_vbi_cap(struct file *file, void *fh,
243 struct v4l2_format *fmt)
244{
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300245 return cx18_g_fmt_vbi_cap(file, fh, fmt);
246}
247
248static int cx18_try_fmt_sliced_vbi_cap(struct file *file, void *fh,
249 struct v4l2_format *fmt)
250{
Andy Walls302df972009-01-31 00:33:02 -0300251 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
252 struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced;
253
254 vbifmt->io_size = sizeof(struct v4l2_sliced_vbi_data) * 36;
255 vbifmt->reserved[0] = 0;
256 vbifmt->reserved[1] = 0;
257
Andy Wallsc1994082009-02-05 22:37:49 -0300258 /* If given a service set, expand it validly & clear passed in set */
Andy Walls302df972009-01-31 00:33:02 -0300259 if (vbifmt->service_set)
260 cx18_expand_service_set(vbifmt, cx->is_50hz);
Andy Wallsc1994082009-02-05 22:37:49 -0300261 /* Sanitize the service_lines, and compute the new set if any valid */
262 if (check_service_set(vbifmt, cx->is_50hz))
263 vbifmt->service_set = cx18_get_service_set(vbifmt);
Andy Walls302df972009-01-31 00:33:02 -0300264 return 0;
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300265}
266
267static int cx18_s_fmt_vid_cap(struct file *file, void *fh,
268 struct v4l2_format *fmt)
269{
270 struct cx18_open_id *id = fh;
271 struct cx18 *cx = id->cx;
272 int ret;
Hans Verkuileffc3462008-09-06 08:24:37 -0300273 int w, h;
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300274
275 ret = v4l2_prio_check(&cx->prio, &id->prio);
276 if (ret)
277 return ret;
278
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300279 ret = cx18_try_fmt_vid_cap(file, fh, fmt);
280 if (ret)
281 return ret;
Hans Verkuileffc3462008-09-06 08:24:37 -0300282 w = fmt->fmt.pix.width;
283 h = fmt->fmt.pix.height;
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300284
285 if (cx->params.width == w && cx->params.height == h)
286 return 0;
287
288 if (atomic_read(&cx->ana_capturing) > 0)
289 return -EBUSY;
290
291 cx->params.width = w;
292 cx->params.height = h;
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300293 cx18_av_cmd(cx, VIDIOC_S_FMT, fmt);
294 return cx18_g_fmt_vid_cap(file, fh, fmt);
295}
296
297static int cx18_s_fmt_vbi_cap(struct file *file, void *fh,
298 struct v4l2_format *fmt)
299{
300 struct cx18_open_id *id = fh;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300301 struct cx18 *cx = id->cx;
302 int ret;
303
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300304 ret = v4l2_prio_check(&cx->prio, &id->prio);
305 if (ret)
306 return ret;
307
Andy Wallsdcc0ef82009-02-06 18:33:43 -0300308 /*
309 * Changing the Encoder's Raw VBI parameters won't have any effect
310 * if any analog capture is ongoing
311 */
312 if (!cx18_raw_vbi(cx) && atomic_read(&cx->ana_capturing) > 0)
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300313 return -EBUSY;
314
Andy Wallsc1994082009-02-05 22:37:49 -0300315 /*
316 * Set the digitizer registers for raw active VBI.
317 * Note cx18_av_vbi_wipes out alot of the passed in fmt under valid
318 * calling conditions
319 */
320 ret = cx18_av_cmd(cx, VIDIOC_S_FMT, fmt);
321 if (ret)
322 return ret;
323
324 /* Store our new v4l2 (non-)sliced VBI state */
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300325 cx->vbi.sliced_in->service_set = 0;
Andy Wallsdd073432008-12-12 16:24:04 -0300326 cx->vbi.in.type = V4L2_BUF_TYPE_VBI_CAPTURE;
Andy Wallsc1994082009-02-05 22:37:49 -0300327
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300328 return cx18_g_fmt_vbi_cap(file, fh, fmt);
329}
330
331static int cx18_s_fmt_sliced_vbi_cap(struct file *file, void *fh,
332 struct v4l2_format *fmt)
333{
Andy Walls302df972009-01-31 00:33:02 -0300334 struct cx18_open_id *id = fh;
335 struct cx18 *cx = id->cx;
336 int ret;
337 struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced;
338
339 ret = v4l2_prio_check(&cx->prio, &id->prio);
340 if (ret)
341 return ret;
342
Andy Wallsc1994082009-02-05 22:37:49 -0300343 cx18_try_fmt_sliced_vbi_cap(file, fh, fmt);
344
Andy Wallsdcc0ef82009-02-06 18:33:43 -0300345 /*
346 * Changing the Encoder's Raw VBI parameters won't have any effect
347 * if any analog capture is ongoing
348 */
349 if (cx18_raw_vbi(cx) && atomic_read(&cx->ana_capturing) > 0)
Andy Wallsc1994082009-02-05 22:37:49 -0300350 return -EBUSY;
Andy Wallsdcc0ef82009-02-06 18:33:43 -0300351
Andy Wallsc1994082009-02-05 22:37:49 -0300352 /*
353 * Set the service_lines requested in the digitizer/slicer registers.
354 * Note, cx18_av_vbi() wipes some "impossible" service lines in the
355 * passed in fmt->fmt.sliced under valid calling conditions
356 */
357 ret = cx18_av_cmd(cx, VIDIOC_S_FMT, fmt);
Andy Walls302df972009-01-31 00:33:02 -0300358 if (ret)
359 return ret;
Andy Wallsc1994082009-02-05 22:37:49 -0300360 /* Store our current v4l2 sliced VBI settings */
Andy Walls302df972009-01-31 00:33:02 -0300361 cx->vbi.in.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE;
Andy Walls302df972009-01-31 00:33:02 -0300362 memcpy(cx->vbi.sliced_in, vbifmt, sizeof(*cx->vbi.sliced_in));
363 return 0;
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300364}
365
366static int cx18_g_chip_ident(struct file *file, void *fh,
Hans Verkuilaecde8b52008-12-30 07:14:19 -0300367 struct v4l2_dbg_chip_ident *chip)
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300368{
369 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
370
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300371 chip->ident = V4L2_IDENT_NONE;
372 chip->revision = 0;
Hans Verkuilaecde8b52008-12-30 07:14:19 -0300373 if (v4l2_chip_match_host(&chip->match)) {
374 chip->ident = V4L2_IDENT_CX23418;
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300375 return 0;
376 }
Hans Verkuilaecde8b52008-12-30 07:14:19 -0300377 cx18_call_i2c_clients(cx, VIDIOC_DBG_G_CHIP_IDENT, chip);
378 return 0;
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300379}
380
Hans Verkuil36ecd492008-06-25 06:00:17 -0300381#ifdef CONFIG_VIDEO_ADV_DEBUG
382static int cx18_cxc(struct cx18 *cx, unsigned int cmd, void *arg)
383{
Hans Verkuilaecde8b52008-12-30 07:14:19 -0300384 struct v4l2_dbg_register *regs = arg;
Hans Verkuil36ecd492008-06-25 06:00:17 -0300385 unsigned long flags;
386
387 if (!capable(CAP_SYS_ADMIN))
388 return -EPERM;
389 if (regs->reg >= CX18_MEM_OFFSET + CX18_MEM_SIZE)
390 return -EINVAL;
391
392 spin_lock_irqsave(&cx18_cards_lock, flags);
Hans Verkuilaecde8b52008-12-30 07:14:19 -0300393 regs->size = 4;
Hans Verkuil36ecd492008-06-25 06:00:17 -0300394 if (cmd == VIDIOC_DBG_G_REGISTER)
Andy Wallsb1526422008-08-30 16:03:44 -0300395 regs->val = cx18_read_enc(cx, regs->reg);
Hans Verkuil36ecd492008-06-25 06:00:17 -0300396 else
Andy Wallsb1526422008-08-30 16:03:44 -0300397 cx18_write_enc(cx, regs->val, regs->reg);
Hans Verkuil36ecd492008-06-25 06:00:17 -0300398 spin_unlock_irqrestore(&cx18_cards_lock, flags);
399 return 0;
400}
401
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300402static int cx18_g_register(struct file *file, void *fh,
Hans Verkuilaecde8b52008-12-30 07:14:19 -0300403 struct v4l2_dbg_register *reg)
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300404{
405 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
406
Hans Verkuilaecde8b52008-12-30 07:14:19 -0300407 if (v4l2_chip_match_host(&reg->match))
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300408 return cx18_cxc(cx, VIDIOC_DBG_G_REGISTER, reg);
Hans Verkuilaecde8b52008-12-30 07:14:19 -0300409 cx18_call_i2c_clients(cx, VIDIOC_DBG_G_REGISTER, reg);
410 return 0;
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300411}
412
413static int cx18_s_register(struct file *file, void *fh,
Hans Verkuilaecde8b52008-12-30 07:14:19 -0300414 struct v4l2_dbg_register *reg)
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300415{
416 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
417
Hans Verkuilaecde8b52008-12-30 07:14:19 -0300418 if (v4l2_chip_match_host(&reg->match))
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300419 return cx18_cxc(cx, VIDIOC_DBG_S_REGISTER, reg);
Hans Verkuilaecde8b52008-12-30 07:14:19 -0300420 cx18_call_i2c_clients(cx, VIDIOC_DBG_S_REGISTER, reg);
421 return 0;
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300422}
Hans Verkuil36ecd492008-06-25 06:00:17 -0300423#endif
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300424
425static int cx18_g_priority(struct file *file, void *fh, enum v4l2_priority *p)
426{
427 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
428
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300429 *p = v4l2_prio_max(&cx->prio);
430 return 0;
431}
432
433static int cx18_s_priority(struct file *file, void *fh, enum v4l2_priority prio)
434{
435 struct cx18_open_id *id = fh;
436 struct cx18 *cx = id->cx;
437
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300438 return v4l2_prio_change(&cx->prio, &id->prio, prio);
439}
440
441static int cx18_querycap(struct file *file, void *fh,
442 struct v4l2_capability *vcap)
443{
444 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
445
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300446 strlcpy(vcap->driver, CX18_DRIVER_NAME, sizeof(vcap->driver));
447 strlcpy(vcap->card, cx->card_name, sizeof(vcap->card));
Andy Walls3d059132009-01-10 21:54:39 -0300448 snprintf(vcap->bus_info, sizeof(vcap->bus_info),
449 "PCI:%s", pci_name(cx->pci_dev));
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300450 vcap->version = CX18_DRIVER_VERSION; /* version */
451 vcap->capabilities = cx->v4l2_cap; /* capabilities */
452 return 0;
453}
454
455static int cx18_enumaudio(struct file *file, void *fh, struct v4l2_audio *vin)
456{
457 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
458
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300459 return cx18_get_audio_input(cx, vin->index, vin);
460}
461
462static int cx18_g_audio(struct file *file, void *fh, struct v4l2_audio *vin)
463{
464 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
465
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300466 vin->index = cx->audio_input;
467 return cx18_get_audio_input(cx, vin->index, vin);
468}
469
470static int cx18_s_audio(struct file *file, void *fh, struct v4l2_audio *vout)
471{
472 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
473
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300474 if (vout->index >= cx->nof_audio_inputs)
475 return -EINVAL;
476 cx->audio_input = vout->index;
477 cx18_audio_set_io(cx);
478 return 0;
479}
480
481static int cx18_enum_input(struct file *file, void *fh, struct v4l2_input *vin)
482{
483 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
484
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300485 /* set it to defaults from our table */
486 return cx18_get_input(cx, vin->index, vin);
487}
488
489static int cx18_cropcap(struct file *file, void *fh,
490 struct v4l2_cropcap *cropcap)
491{
492 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
493
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300494 if (cropcap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
495 return -EINVAL;
496 cropcap->bounds.top = cropcap->bounds.left = 0;
497 cropcap->bounds.width = 720;
498 cropcap->bounds.height = cx->is_50hz ? 576 : 480;
499 cropcap->pixelaspect.numerator = cx->is_50hz ? 59 : 10;
500 cropcap->pixelaspect.denominator = cx->is_50hz ? 54 : 11;
501 cropcap->defrect = cropcap->bounds;
502 return 0;
503}
504
505static int cx18_s_crop(struct file *file, void *fh, struct v4l2_crop *crop)
506{
507 struct cx18_open_id *id = fh;
508 struct cx18 *cx = id->cx;
509 int ret;
510
511 ret = v4l2_prio_check(&cx->prio, &id->prio);
512 if (ret)
513 return ret;
514
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300515 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
516 return -EINVAL;
517 return cx18_av_cmd(cx, VIDIOC_S_CROP, crop);
518}
519
520static int cx18_g_crop(struct file *file, void *fh, struct v4l2_crop *crop)
521{
522 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
523
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300524 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
525 return -EINVAL;
526 return cx18_av_cmd(cx, VIDIOC_G_CROP, crop);
527}
528
529static int cx18_enum_fmt_vid_cap(struct file *file, void *fh,
530 struct v4l2_fmtdesc *fmt)
531{
532 static struct v4l2_fmtdesc formats[] = {
533 { 0, V4L2_BUF_TYPE_VIDEO_CAPTURE, 0,
534 "HM12 (YUV 4:1:1)", V4L2_PIX_FMT_HM12, { 0, 0, 0, 0 }
535 },
536 { 1, V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FMT_FLAG_COMPRESSED,
537 "MPEG", V4L2_PIX_FMT_MPEG, { 0, 0, 0, 0 }
538 }
539 };
540
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300541 if (fmt->index > 1)
542 return -EINVAL;
543 *fmt = formats[fmt->index];
544 return 0;
545}
546
547static int cx18_g_input(struct file *file, void *fh, unsigned int *i)
548{
549 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
550
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300551 *i = cx->active_input;
552 return 0;
553}
554
555int cx18_s_input(struct file *file, void *fh, unsigned int inp)
556{
557 struct cx18_open_id *id = fh;
558 struct cx18 *cx = id->cx;
559 int ret;
560
561 ret = v4l2_prio_check(&cx->prio, &id->prio);
562 if (ret)
563 return ret;
564
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300565 if (inp < 0 || inp >= cx->nof_inputs)
566 return -EINVAL;
567
568 if (inp == cx->active_input) {
569 CX18_DEBUG_INFO("Input unchanged\n");
570 return 0;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300571 }
572
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300573 CX18_DEBUG_INFO("Changing input from %d to %d\n",
574 cx->active_input, inp);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300575
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300576 cx->active_input = inp;
577 /* Set the audio input to whatever is appropriate for the input type. */
578 cx->audio_input = cx->card->video_inputs[inp].audio_index;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300579
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300580 /* prevent others from messing with the streams until
581 we're finished changing inputs. */
582 cx18_mute(cx);
583 cx18_video_set_io(cx);
584 cx18_audio_set_io(cx);
585 cx18_unmute(cx);
586 return 0;
587}
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300588
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300589static int cx18_g_frequency(struct file *file, void *fh,
590 struct v4l2_frequency *vf)
591{
592 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
593
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300594 if (vf->tuner != 0)
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300595 return -EINVAL;
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300596
597 cx18_call_i2c_clients(cx, VIDIOC_G_FREQUENCY, vf);
598 return 0;
599}
600
601int cx18_s_frequency(struct file *file, void *fh, struct v4l2_frequency *vf)
602{
603 struct cx18_open_id *id = fh;
604 struct cx18 *cx = id->cx;
605 int ret;
606
607 ret = v4l2_prio_check(&cx->prio, &id->prio);
608 if (ret)
609 return ret;
610
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300611 if (vf->tuner != 0)
612 return -EINVAL;
613
614 cx18_mute(cx);
615 CX18_DEBUG_INFO("v4l2 ioctl: set frequency %d\n", vf->frequency);
616 cx18_call_i2c_clients(cx, VIDIOC_S_FREQUENCY, vf);
617 cx18_unmute(cx);
618 return 0;
619}
620
621static int cx18_g_std(struct file *file, void *fh, v4l2_std_id *std)
622{
623 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
624
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300625 *std = cx->std;
626 return 0;
627}
628
629int cx18_s_std(struct file *file, void *fh, v4l2_std_id *std)
630{
631 struct cx18_open_id *id = fh;
632 struct cx18 *cx = id->cx;
633 int ret;
634
635 ret = v4l2_prio_check(&cx->prio, &id->prio);
636 if (ret)
637 return ret;
638
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300639 if ((*std & V4L2_STD_ALL) == 0)
640 return -EINVAL;
641
642 if (*std == cx->std)
643 return 0;
644
645 if (test_bit(CX18_F_I_RADIO_USER, &cx->i_flags) ||
646 atomic_read(&cx->ana_capturing) > 0) {
647 /* Switching standard would turn off the radio or mess
648 with already running streams, prevent that by
649 returning EBUSY. */
650 return -EBUSY;
651 }
652
653 cx->std = *std;
654 cx->is_60hz = (*std & V4L2_STD_525_60) ? 1 : 0;
655 cx->params.is_50hz = cx->is_50hz = !cx->is_60hz;
656 cx->params.width = 720;
657 cx->params.height = cx->is_50hz ? 576 : 480;
658 cx->vbi.count = cx->is_50hz ? 18 : 12;
659 cx->vbi.start[0] = cx->is_50hz ? 6 : 10;
660 cx->vbi.start[1] = cx->is_50hz ? 318 : 273;
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300661 CX18_DEBUG_INFO("Switching standard to %llx.\n",
662 (unsigned long long) cx->std);
663
664 /* Tuner */
665 cx18_call_i2c_clients(cx, VIDIOC_S_STD, &cx->std);
666 return 0;
667}
668
669static int cx18_s_tuner(struct file *file, void *fh, struct v4l2_tuner *vt)
670{
671 struct cx18_open_id *id = fh;
672 struct cx18 *cx = id->cx;
673 int ret;
674
675 ret = v4l2_prio_check(&cx->prio, &id->prio);
676 if (ret)
677 return ret;
678
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300679 if (vt->index != 0)
680 return -EINVAL;
681
682 /* Setting tuner can only set audio mode */
683 cx18_call_i2c_clients(cx, VIDIOC_S_TUNER, vt);
684
685 return 0;
686}
687
688static int cx18_g_tuner(struct file *file, void *fh, struct v4l2_tuner *vt)
689{
690 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
691
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300692 if (vt->index != 0)
693 return -EINVAL;
694
695 cx18_call_i2c_clients(cx, VIDIOC_G_TUNER, vt);
696
697 if (test_bit(CX18_F_I_RADIO_USER, &cx->i_flags)) {
698 strlcpy(vt->name, "cx18 Radio Tuner", sizeof(vt->name));
699 vt->type = V4L2_TUNER_RADIO;
700 } else {
701 strlcpy(vt->name, "cx18 TV Tuner", sizeof(vt->name));
702 vt->type = V4L2_TUNER_ANALOG_TV;
703 }
704
705 return 0;
706}
707
708static int cx18_g_sliced_vbi_cap(struct file *file, void *fh,
709 struct v4l2_sliced_vbi_cap *cap)
710{
Andy Walls302df972009-01-31 00:33:02 -0300711 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
712 int set = cx->is_50hz ? V4L2_SLICED_VBI_625 : V4L2_SLICED_VBI_525;
713 int f, l;
714
Andy Wallsc1994082009-02-05 22:37:49 -0300715 if (cap->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE)
716 return -EINVAL;
717
718 cap->service_set = 0;
719 for (f = 0; f < 2; f++) {
720 for (l = 0; l < 24; l++) {
721 if (valid_service_line(f, l, cx->is_50hz)) {
722 /*
723 * We can find all v4l2 supported vbi services
724 * for the standard, on a valid line for the std
725 */
726 cap->service_lines[f][l] = set;
727 cap->service_set |= set;
728 } else
729 cap->service_lines[f][l] = 0;
Andy Walls302df972009-01-31 00:33:02 -0300730 }
Andy Walls302df972009-01-31 00:33:02 -0300731 }
Andy Wallsc1994082009-02-05 22:37:49 -0300732 for (f = 0; f < 3; f++)
733 cap->reserved[f] = 0;
734 return 0;
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300735}
736
737static int cx18_g_enc_index(struct file *file, void *fh,
738 struct v4l2_enc_idx *idx)
739{
740 return -EINVAL;
741}
742
743static int cx18_encoder_cmd(struct file *file, void *fh,
744 struct v4l2_encoder_cmd *enc)
745{
746 struct cx18_open_id *id = fh;
747 struct cx18 *cx = id->cx;
Andy Wallsd3c5e702008-08-23 16:42:29 -0300748 u32 h;
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300749
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300750 switch (enc->cmd) {
751 case V4L2_ENC_CMD_START:
752 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_START\n");
753 enc->flags = 0;
754 return cx18_start_capture(id);
755
756 case V4L2_ENC_CMD_STOP:
757 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_STOP\n");
758 enc->flags &= V4L2_ENC_CMD_STOP_AT_GOP_END;
759 cx18_stop_capture(id,
760 enc->flags & V4L2_ENC_CMD_STOP_AT_GOP_END);
761 break;
762
763 case V4L2_ENC_CMD_PAUSE:
764 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_PAUSE\n");
765 enc->flags = 0;
766 if (!atomic_read(&cx->ana_capturing))
767 return -EPERM;
768 if (test_and_set_bit(CX18_F_I_ENC_PAUSED, &cx->i_flags))
769 return 0;
Andy Wallsd3c5e702008-08-23 16:42:29 -0300770 h = cx18_find_handle(cx);
771 if (h == CX18_INVALID_TASK_HANDLE) {
772 CX18_ERR("Can't find valid task handle for "
773 "V4L2_ENC_CMD_PAUSE\n");
774 return -EBADFD;
775 }
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300776 cx18_mute(cx);
Andy Wallsd3c5e702008-08-23 16:42:29 -0300777 cx18_vapi(cx, CX18_CPU_CAPTURE_PAUSE, 1, h);
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300778 break;
779
780 case V4L2_ENC_CMD_RESUME:
781 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_RESUME\n");
782 enc->flags = 0;
783 if (!atomic_read(&cx->ana_capturing))
784 return -EPERM;
785 if (!test_and_clear_bit(CX18_F_I_ENC_PAUSED, &cx->i_flags))
786 return 0;
Andy Wallsd3c5e702008-08-23 16:42:29 -0300787 h = cx18_find_handle(cx);
788 if (h == CX18_INVALID_TASK_HANDLE) {
789 CX18_ERR("Can't find valid task handle for "
790 "V4L2_ENC_CMD_RESUME\n");
791 return -EBADFD;
792 }
793 cx18_vapi(cx, CX18_CPU_CAPTURE_RESUME, 1, h);
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300794 cx18_unmute(cx);
795 break;
796
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300797 default:
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300798 CX18_DEBUG_IOCTL("Unknown cmd %d\n", enc->cmd);
799 return -EINVAL;
800 }
801 return 0;
802}
803
804static int cx18_try_encoder_cmd(struct file *file, void *fh,
805 struct v4l2_encoder_cmd *enc)
806{
807 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
808
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300809 switch (enc->cmd) {
810 case V4L2_ENC_CMD_START:
811 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_START\n");
812 enc->flags = 0;
813 break;
814
815 case V4L2_ENC_CMD_STOP:
816 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_STOP\n");
817 enc->flags &= V4L2_ENC_CMD_STOP_AT_GOP_END;
818 break;
819
820 case V4L2_ENC_CMD_PAUSE:
821 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_PAUSE\n");
822 enc->flags = 0;
823 break;
824
825 case V4L2_ENC_CMD_RESUME:
826 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_RESUME\n");
827 enc->flags = 0;
828 break;
829
830 default:
831 CX18_DEBUG_IOCTL("Unknown cmd %d\n", enc->cmd);
832 return -EINVAL;
833 }
834 return 0;
835}
836
837static int cx18_log_status(struct file *file, void *fh)
838{
839 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
840 struct v4l2_input vidin;
841 struct v4l2_audio audin;
842 int i;
843
Andy Wallse0f28b62009-01-10 14:13:46 -0300844 CX18_INFO("================= START STATUS CARD #%d "
845 "=================\n", cx->num);
846 CX18_INFO("Version: %s Card: %s\n", CX18_VERSION, cx->card_name);
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300847 if (cx->hw_flags & CX18_HW_TVEEPROM) {
848 struct tveeprom tv;
849
850 cx18_read_eeprom(cx, &tv);
851 }
852 cx18_call_i2c_clients(cx, VIDIOC_LOG_STATUS, NULL);
853 cx18_get_input(cx, cx->active_input, &vidin);
854 cx18_get_audio_input(cx, cx->audio_input, &audin);
855 CX18_INFO("Video Input: %s\n", vidin.name);
856 CX18_INFO("Audio Input: %s\n", audin.name);
Andy Walls8abdd002008-07-13 19:05:25 -0300857 mutex_lock(&cx->gpio_lock);
Hans Verkuil3d66c402008-06-21 11:19:34 -0300858 CX18_INFO("GPIO: direction 0x%08x, value 0x%08x\n",
859 cx->gpio_dir, cx->gpio_val);
Andy Walls8abdd002008-07-13 19:05:25 -0300860 mutex_unlock(&cx->gpio_lock);
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300861 CX18_INFO("Tuner: %s\n",
862 test_bit(CX18_F_I_RADIO_USER, &cx->i_flags) ? "Radio" : "TV");
863 cx2341x_log_status(&cx->params, cx->name);
864 CX18_INFO("Status flags: 0x%08lx\n", cx->i_flags);
865 for (i = 0; i < CX18_MAX_STREAMS; i++) {
866 struct cx18_stream *s = &cx->streams[i];
867
Andy Walls3d059132009-01-10 21:54:39 -0300868 if (s->video_dev == NULL || s->buffers == 0)
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300869 continue;
870 CX18_INFO("Stream %s: status 0x%04lx, %d%% of %d KiB (%d buffers) in use\n",
871 s->name, s->s_flags,
Andy Walls66c2a6b2008-12-08 23:02:45 -0300872 atomic_read(&s->q_full.buffers) * 100 / s->buffers,
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300873 (s->buffers * s->buf_size) / 1024, s->buffers);
874 }
875 CX18_INFO("Read MPEG/VBI: %lld/%lld bytes\n",
876 (long long)cx->mpg_data_received,
877 (long long)cx->vbi_data_inserted);
878 CX18_INFO("================== END STATUS CARD #%d ==================\n", cx->num);
879 return 0;
880}
881
Hans Verkuil069b7472008-12-30 07:04:34 -0300882static long cx18_default(struct file *file, void *fh, int cmd, void *arg)
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300883{
884 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
885
886 switch (cmd) {
887 case VIDIOC_INT_S_AUDIO_ROUTING: {
888 struct v4l2_routing *route = arg;
Hans Verkuil37f89f92008-06-22 11:57:31 -0300889
890 CX18_DEBUG_IOCTL("VIDIOC_INT_S_AUDIO_ROUTING(%d, %d)\n",
891 route->input, route->output);
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300892 cx18_audio_set_route(cx, route);
893 break;
894 }
Andy Walls02fa2722008-07-13 19:30:15 -0300895
896 case VIDIOC_INT_RESET: {
897 u32 val = *(u32 *)arg;
898
899 if ((val == 0) || (val & 0x01))
900 cx18_reset_ir_gpio(&cx->i2c_algo_cb_data[0]);
901 break;
902 }
903
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300904 default:
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300905 return -EINVAL;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300906 }
907 return 0;
908}
909
Hans Verkuil069b7472008-12-30 07:04:34 -0300910long cx18_v4l2_ioctl(struct file *filp, unsigned int cmd,
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300911 unsigned long arg)
912{
Hans Verkuil37f89f92008-06-22 11:57:31 -0300913 struct video_device *vfd = video_devdata(filp);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300914 struct cx18_open_id *id = (struct cx18_open_id *)filp->private_data;
915 struct cx18 *cx = id->cx;
Hans Verkuil069b7472008-12-30 07:04:34 -0300916 long res;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300917
918 mutex_lock(&cx->serialize_lock);
Hans Verkuil37f89f92008-06-22 11:57:31 -0300919
920 if (cx18_debug & CX18_DBGFLG_IOCTL)
921 vfd->debug = V4L2_DEBUG_IOCTL | V4L2_DEBUG_IOCTL_ARG;
Hans Verkuilbec43662008-12-30 06:58:20 -0300922 res = video_ioctl2(filp, cmd, arg);
Hans Verkuil37f89f92008-06-22 11:57:31 -0300923 vfd->debug = 0;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300924 mutex_unlock(&cx->serialize_lock);
925 return res;
926}
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300927
Hans Verkuila3998102008-07-21 02:57:38 -0300928static const struct v4l2_ioctl_ops cx18_ioctl_ops = {
929 .vidioc_querycap = cx18_querycap,
930 .vidioc_g_priority = cx18_g_priority,
931 .vidioc_s_priority = cx18_s_priority,
932 .vidioc_s_audio = cx18_s_audio,
933 .vidioc_g_audio = cx18_g_audio,
934 .vidioc_enumaudio = cx18_enumaudio,
935 .vidioc_enum_input = cx18_enum_input,
936 .vidioc_cropcap = cx18_cropcap,
937 .vidioc_s_crop = cx18_s_crop,
938 .vidioc_g_crop = cx18_g_crop,
939 .vidioc_g_input = cx18_g_input,
940 .vidioc_s_input = cx18_s_input,
941 .vidioc_g_frequency = cx18_g_frequency,
942 .vidioc_s_frequency = cx18_s_frequency,
943 .vidioc_s_tuner = cx18_s_tuner,
944 .vidioc_g_tuner = cx18_g_tuner,
945 .vidioc_g_enc_index = cx18_g_enc_index,
946 .vidioc_g_std = cx18_g_std,
947 .vidioc_s_std = cx18_s_std,
948 .vidioc_log_status = cx18_log_status,
949 .vidioc_enum_fmt_vid_cap = cx18_enum_fmt_vid_cap,
950 .vidioc_encoder_cmd = cx18_encoder_cmd,
951 .vidioc_try_encoder_cmd = cx18_try_encoder_cmd,
952 .vidioc_g_fmt_vid_cap = cx18_g_fmt_vid_cap,
953 .vidioc_g_fmt_vbi_cap = cx18_g_fmt_vbi_cap,
954 .vidioc_g_fmt_sliced_vbi_cap = cx18_g_fmt_sliced_vbi_cap,
955 .vidioc_s_fmt_vid_cap = cx18_s_fmt_vid_cap,
956 .vidioc_s_fmt_vbi_cap = cx18_s_fmt_vbi_cap,
957 .vidioc_s_fmt_sliced_vbi_cap = cx18_s_fmt_sliced_vbi_cap,
958 .vidioc_try_fmt_vid_cap = cx18_try_fmt_vid_cap,
959 .vidioc_try_fmt_vbi_cap = cx18_try_fmt_vbi_cap,
960 .vidioc_try_fmt_sliced_vbi_cap = cx18_try_fmt_sliced_vbi_cap,
961 .vidioc_g_sliced_vbi_cap = cx18_g_sliced_vbi_cap,
962 .vidioc_g_chip_ident = cx18_g_chip_ident,
963#ifdef CONFIG_VIDEO_ADV_DEBUG
964 .vidioc_g_register = cx18_g_register,
965 .vidioc_s_register = cx18_s_register,
966#endif
967 .vidioc_default = cx18_default,
968 .vidioc_queryctrl = cx18_queryctrl,
969 .vidioc_querymenu = cx18_querymenu,
970 .vidioc_g_ext_ctrls = cx18_g_ext_ctrls,
971 .vidioc_s_ext_ctrls = cx18_s_ext_ctrls,
972 .vidioc_try_ext_ctrls = cx18_try_ext_ctrls,
973};
974
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300975void cx18_set_funcs(struct video_device *vdev)
976{
Hans Verkuila3998102008-07-21 02:57:38 -0300977 vdev->ioctl_ops = &cx18_ioctl_ops;
Andy Walls3b6fe58f2008-06-21 08:36:31 -0300978}