2 * cx18 ioctl system call
4 * Derived from ivtv-ioctl.c
6 * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl>
7 * Copyright (C) 2008 Andy Walls <awalls@radix.net>
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.
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.
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
25 #include "cx18-driver.h"
27 #include "cx18-version.h"
28 #include "cx18-mailbox.h"
30 #include "cx18-queue.h"
31 #include "cx18-fileops.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>
45 u16 cx18_service2vbi(int 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;
55 return CX18_SLICED_TYPE_VPS;
61 static int valid_service_line(int field, int line, int is_pal)
63 return (is_pal && line >= 6 && (line != 23 || field == 0)) ||
64 (!is_pal && line >= 10 && line < 22);
67 static u16 select_service_from_set(int field, int line, u16 set, int is_pal)
69 u16 valid_set = (is_pal ? V4L2_SLICED_VBI_625 : V4L2_SLICED_VBI_525);
72 set = set & valid_set;
73 if (set == 0 || !valid_service_line(field, line, is_pal))
76 if (line == 21 && (set & V4L2_SLICED_CAPTION_525))
77 return V4L2_SLICED_CAPTION_525;
79 if (line == 16 && field == 0 && (set & V4L2_SLICED_VPS))
80 return V4L2_SLICED_VPS;
81 if (line == 23 && field == 0 && (set & V4L2_SLICED_WSS_625))
82 return V4L2_SLICED_WSS_625;
86 for (i = 0; i < 32; i++) {
93 void cx18_expand_service_set(struct v4l2_sliced_vbi_format *fmt, int is_pal)
95 u16 set = fmt->service_set;
99 for (f = 0; f < 2; f++) {
100 for (l = 0; l < 24; l++)
101 fmt->service_lines[f][l] = select_service_from_set(f, l, set, is_pal);
106 u16 cx18_get_service_set(struct v4l2_sliced_vbi_format *fmt)
111 for (f = 0; f < 2; f++) {
112 for (l = 0; l < 24; l++)
113 set |= fmt->service_lines[f][l];
118 static int cx18_g_fmt_vid_cap(struct file *file, void *fh,
119 struct v4l2_format *fmt)
121 struct cx18_open_id *id = fh;
122 struct cx18 *cx = id->cx;
123 struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
125 pixfmt->width = cx->params.width;
126 pixfmt->height = cx->params.height;
127 pixfmt->colorspace = V4L2_COLORSPACE_SMPTE170M;
128 pixfmt->field = V4L2_FIELD_INTERLACED;
130 if (id->type == CX18_ENC_STREAM_TYPE_YUV) {
131 pixfmt->pixelformat = V4L2_PIX_FMT_HM12;
132 /* YUV size is (Y=(h*w) + UV=(h*(w/2))) */
134 pixfmt->height * pixfmt->width +
135 pixfmt->height * (pixfmt->width / 2);
136 pixfmt->bytesperline = 720;
138 pixfmt->pixelformat = V4L2_PIX_FMT_MPEG;
139 pixfmt->sizeimage = 128 * 1024;
140 pixfmt->bytesperline = 0;
145 static int cx18_g_fmt_vbi_cap(struct file *file, void *fh,
146 struct v4l2_format *fmt)
148 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
149 struct v4l2_vbi_format *vbifmt = &fmt->fmt.vbi;
151 vbifmt->sampling_rate = 27000000;
152 vbifmt->offset = 248;
153 vbifmt->samples_per_line = cx->vbi.raw_decoder_line_size - 4;
154 vbifmt->sample_format = V4L2_PIX_FMT_GREY;
155 vbifmt->start[0] = cx->vbi.start[0];
156 vbifmt->start[1] = cx->vbi.start[1];
157 vbifmt->count[0] = vbifmt->count[1] = cx->vbi.count;
159 vbifmt->reserved[0] = 0;
160 vbifmt->reserved[1] = 0;
164 static int cx18_g_fmt_sliced_vbi_cap(struct file *file, void *fh,
165 struct v4l2_format *fmt)
170 static int cx18_try_fmt_vid_cap(struct file *file, void *fh,
171 struct v4l2_format *fmt)
173 struct cx18_open_id *id = fh;
174 struct cx18 *cx = id->cx;
175 int w = fmt->fmt.pix.width;
176 int h = fmt->fmt.pix.height;
180 h = min(h, cx->is_50hz ? 576 : 480);
182 cx18_g_fmt_vid_cap(file, fh, fmt);
183 fmt->fmt.pix.width = w;
184 fmt->fmt.pix.height = h;
188 static int cx18_try_fmt_vbi_cap(struct file *file, void *fh,
189 struct v4l2_format *fmt)
191 return cx18_g_fmt_vbi_cap(file, fh, fmt);
194 static int cx18_try_fmt_sliced_vbi_cap(struct file *file, void *fh,
195 struct v4l2_format *fmt)
200 static int cx18_s_fmt_vid_cap(struct file *file, void *fh,
201 struct v4l2_format *fmt)
203 struct cx18_open_id *id = fh;
204 struct cx18 *cx = id->cx;
208 ret = v4l2_prio_check(&cx->prio, &id->prio);
212 ret = cx18_try_fmt_vid_cap(file, fh, fmt);
215 w = fmt->fmt.pix.width;
216 h = fmt->fmt.pix.height;
218 if (cx->params.width == w && cx->params.height == h)
221 if (atomic_read(&cx->ana_capturing) > 0)
224 cx->params.width = w;
225 cx->params.height = h;
226 cx18_av_cmd(cx, VIDIOC_S_FMT, fmt);
227 return cx18_g_fmt_vid_cap(file, fh, fmt);
230 static int cx18_s_fmt_vbi_cap(struct file *file, void *fh,
231 struct v4l2_format *fmt)
233 struct cx18_open_id *id = fh;
234 struct cx18 *cx = id->cx;
237 ret = v4l2_prio_check(&cx->prio, &id->prio);
241 if (id->type == CX18_ENC_STREAM_TYPE_VBI &&
242 cx->vbi.sliced_in->service_set &&
243 atomic_read(&cx->ana_capturing) > 0)
246 cx->vbi.sliced_in->service_set = 0;
247 cx18_av_cmd(cx, VIDIOC_S_FMT, &cx->vbi.in);
248 return cx18_g_fmt_vbi_cap(file, fh, fmt);
251 static int cx18_s_fmt_sliced_vbi_cap(struct file *file, void *fh,
252 struct v4l2_format *fmt)
257 static int cx18_g_chip_ident(struct file *file, void *fh,
258 struct v4l2_chip_ident *chip)
260 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
262 chip->ident = V4L2_IDENT_NONE;
264 if (chip->match_type == V4L2_CHIP_MATCH_HOST) {
265 if (v4l2_chip_match_host(chip->match_type, chip->match_chip))
266 chip->ident = V4L2_IDENT_CX23418;
269 if (chip->match_type == V4L2_CHIP_MATCH_I2C_DRIVER)
270 return cx18_i2c_id(cx, chip->match_chip, VIDIOC_G_CHIP_IDENT,
272 if (chip->match_type == V4L2_CHIP_MATCH_I2C_ADDR)
273 return cx18_call_i2c_client(cx, chip->match_chip,
274 VIDIOC_G_CHIP_IDENT, chip);
278 #ifdef CONFIG_VIDEO_ADV_DEBUG
279 static int cx18_cxc(struct cx18 *cx, unsigned int cmd, void *arg)
281 struct v4l2_register *regs = arg;
284 if (!capable(CAP_SYS_ADMIN))
286 if (regs->reg >= CX18_MEM_OFFSET + CX18_MEM_SIZE)
289 spin_lock_irqsave(&cx18_cards_lock, flags);
290 if (cmd == VIDIOC_DBG_G_REGISTER)
291 regs->val = cx18_read_enc(cx, regs->reg);
293 cx18_write_enc(cx, regs->val, regs->reg);
294 spin_unlock_irqrestore(&cx18_cards_lock, flags);
298 static int cx18_g_register(struct file *file, void *fh,
299 struct v4l2_register *reg)
301 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
303 if (v4l2_chip_match_host(reg->match_type, reg->match_chip))
304 return cx18_cxc(cx, VIDIOC_DBG_G_REGISTER, reg);
305 if (reg->match_type == V4L2_CHIP_MATCH_I2C_DRIVER)
306 return cx18_i2c_id(cx, reg->match_chip, VIDIOC_DBG_G_REGISTER,
308 return cx18_call_i2c_client(cx, reg->match_chip, VIDIOC_DBG_G_REGISTER,
312 static int cx18_s_register(struct file *file, void *fh,
313 struct v4l2_register *reg)
315 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
317 if (v4l2_chip_match_host(reg->match_type, reg->match_chip))
318 return cx18_cxc(cx, VIDIOC_DBG_S_REGISTER, reg);
319 if (reg->match_type == V4L2_CHIP_MATCH_I2C_DRIVER)
320 return cx18_i2c_id(cx, reg->match_chip, VIDIOC_DBG_S_REGISTER,
322 return cx18_call_i2c_client(cx, reg->match_chip, VIDIOC_DBG_S_REGISTER,
327 static int cx18_g_priority(struct file *file, void *fh, enum v4l2_priority *p)
329 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
331 *p = v4l2_prio_max(&cx->prio);
335 static int cx18_s_priority(struct file *file, void *fh, enum v4l2_priority prio)
337 struct cx18_open_id *id = fh;
338 struct cx18 *cx = id->cx;
340 return v4l2_prio_change(&cx->prio, &id->prio, prio);
343 static int cx18_querycap(struct file *file, void *fh,
344 struct v4l2_capability *vcap)
346 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
348 strlcpy(vcap->driver, CX18_DRIVER_NAME, sizeof(vcap->driver));
349 strlcpy(vcap->card, cx->card_name, sizeof(vcap->card));
350 snprintf(vcap->bus_info, sizeof(vcap->bus_info), "PCI:%s", pci_name(cx->dev));
351 vcap->version = CX18_DRIVER_VERSION; /* version */
352 vcap->capabilities = cx->v4l2_cap; /* capabilities */
356 static int cx18_enumaudio(struct file *file, void *fh, struct v4l2_audio *vin)
358 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
360 return cx18_get_audio_input(cx, vin->index, vin);
363 static int cx18_g_audio(struct file *file, void *fh, struct v4l2_audio *vin)
365 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
367 vin->index = cx->audio_input;
368 return cx18_get_audio_input(cx, vin->index, vin);
371 static int cx18_s_audio(struct file *file, void *fh, struct v4l2_audio *vout)
373 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
375 if (vout->index >= cx->nof_audio_inputs)
377 cx->audio_input = vout->index;
378 cx18_audio_set_io(cx);
382 static int cx18_enum_input(struct file *file, void *fh, struct v4l2_input *vin)
384 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
386 /* set it to defaults from our table */
387 return cx18_get_input(cx, vin->index, vin);
390 static int cx18_cropcap(struct file *file, void *fh,
391 struct v4l2_cropcap *cropcap)
393 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
395 if (cropcap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
397 cropcap->bounds.top = cropcap->bounds.left = 0;
398 cropcap->bounds.width = 720;
399 cropcap->bounds.height = cx->is_50hz ? 576 : 480;
400 cropcap->pixelaspect.numerator = cx->is_50hz ? 59 : 10;
401 cropcap->pixelaspect.denominator = cx->is_50hz ? 54 : 11;
402 cropcap->defrect = cropcap->bounds;
406 static int cx18_s_crop(struct file *file, void *fh, struct v4l2_crop *crop)
408 struct cx18_open_id *id = fh;
409 struct cx18 *cx = id->cx;
412 ret = v4l2_prio_check(&cx->prio, &id->prio);
416 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
418 return cx18_av_cmd(cx, VIDIOC_S_CROP, crop);
421 static int cx18_g_crop(struct file *file, void *fh, struct v4l2_crop *crop)
423 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
425 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
427 return cx18_av_cmd(cx, VIDIOC_G_CROP, crop);
430 static int cx18_enum_fmt_vid_cap(struct file *file, void *fh,
431 struct v4l2_fmtdesc *fmt)
433 static struct v4l2_fmtdesc formats[] = {
434 { 0, V4L2_BUF_TYPE_VIDEO_CAPTURE, 0,
435 "HM12 (YUV 4:1:1)", V4L2_PIX_FMT_HM12, { 0, 0, 0, 0 }
437 { 1, V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FMT_FLAG_COMPRESSED,
438 "MPEG", V4L2_PIX_FMT_MPEG, { 0, 0, 0, 0 }
444 *fmt = formats[fmt->index];
448 static int cx18_g_input(struct file *file, void *fh, unsigned int *i)
450 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
452 *i = cx->active_input;
456 int cx18_s_input(struct file *file, void *fh, unsigned int inp)
458 struct cx18_open_id *id = fh;
459 struct cx18 *cx = id->cx;
462 ret = v4l2_prio_check(&cx->prio, &id->prio);
466 if (inp < 0 || inp >= cx->nof_inputs)
469 if (inp == cx->active_input) {
470 CX18_DEBUG_INFO("Input unchanged\n");
474 CX18_DEBUG_INFO("Changing input from %d to %d\n",
475 cx->active_input, inp);
477 cx->active_input = inp;
478 /* Set the audio input to whatever is appropriate for the input type. */
479 cx->audio_input = cx->card->video_inputs[inp].audio_index;
481 /* prevent others from messing with the streams until
482 we're finished changing inputs. */
484 cx18_video_set_io(cx);
485 cx18_audio_set_io(cx);
490 static int cx18_g_frequency(struct file *file, void *fh,
491 struct v4l2_frequency *vf)
493 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
498 cx18_call_i2c_clients(cx, VIDIOC_G_FREQUENCY, vf);
502 int cx18_s_frequency(struct file *file, void *fh, struct v4l2_frequency *vf)
504 struct cx18_open_id *id = fh;
505 struct cx18 *cx = id->cx;
508 ret = v4l2_prio_check(&cx->prio, &id->prio);
516 CX18_DEBUG_INFO("v4l2 ioctl: set frequency %d\n", vf->frequency);
517 cx18_call_i2c_clients(cx, VIDIOC_S_FREQUENCY, vf);
522 static int cx18_g_std(struct file *file, void *fh, v4l2_std_id *std)
524 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
530 int cx18_s_std(struct file *file, void *fh, v4l2_std_id *std)
532 struct cx18_open_id *id = fh;
533 struct cx18 *cx = id->cx;
536 ret = v4l2_prio_check(&cx->prio, &id->prio);
540 if ((*std & V4L2_STD_ALL) == 0)
546 if (test_bit(CX18_F_I_RADIO_USER, &cx->i_flags) ||
547 atomic_read(&cx->ana_capturing) > 0) {
548 /* Switching standard would turn off the radio or mess
549 with already running streams, prevent that by
555 cx->is_60hz = (*std & V4L2_STD_525_60) ? 1 : 0;
556 cx->params.is_50hz = cx->is_50hz = !cx->is_60hz;
557 cx->params.width = 720;
558 cx->params.height = cx->is_50hz ? 576 : 480;
559 cx->vbi.count = cx->is_50hz ? 18 : 12;
560 cx->vbi.start[0] = cx->is_50hz ? 6 : 10;
561 cx->vbi.start[1] = cx->is_50hz ? 318 : 273;
562 cx->vbi.sliced_decoder_line_size = cx->is_60hz ? 272 : 284;
563 CX18_DEBUG_INFO("Switching standard to %llx.\n",
564 (unsigned long long) cx->std);
567 cx18_call_i2c_clients(cx, VIDIOC_S_STD, &cx->std);
571 static int cx18_s_tuner(struct file *file, void *fh, struct v4l2_tuner *vt)
573 struct cx18_open_id *id = fh;
574 struct cx18 *cx = id->cx;
577 ret = v4l2_prio_check(&cx->prio, &id->prio);
584 /* Setting tuner can only set audio mode */
585 cx18_call_i2c_clients(cx, VIDIOC_S_TUNER, vt);
590 static int cx18_g_tuner(struct file *file, void *fh, struct v4l2_tuner *vt)
592 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
597 cx18_call_i2c_clients(cx, VIDIOC_G_TUNER, vt);
599 if (test_bit(CX18_F_I_RADIO_USER, &cx->i_flags)) {
600 strlcpy(vt->name, "cx18 Radio Tuner", sizeof(vt->name));
601 vt->type = V4L2_TUNER_RADIO;
603 strlcpy(vt->name, "cx18 TV Tuner", sizeof(vt->name));
604 vt->type = V4L2_TUNER_ANALOG_TV;
610 static int cx18_g_sliced_vbi_cap(struct file *file, void *fh,
611 struct v4l2_sliced_vbi_cap *cap)
616 static int cx18_g_enc_index(struct file *file, void *fh,
617 struct v4l2_enc_idx *idx)
622 static int cx18_encoder_cmd(struct file *file, void *fh,
623 struct v4l2_encoder_cmd *enc)
625 struct cx18_open_id *id = fh;
626 struct cx18 *cx = id->cx;
630 case V4L2_ENC_CMD_START:
631 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_START\n");
633 return cx18_start_capture(id);
635 case V4L2_ENC_CMD_STOP:
636 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_STOP\n");
637 enc->flags &= V4L2_ENC_CMD_STOP_AT_GOP_END;
638 cx18_stop_capture(id,
639 enc->flags & V4L2_ENC_CMD_STOP_AT_GOP_END);
642 case V4L2_ENC_CMD_PAUSE:
643 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_PAUSE\n");
645 if (!atomic_read(&cx->ana_capturing))
647 if (test_and_set_bit(CX18_F_I_ENC_PAUSED, &cx->i_flags))
649 h = cx18_find_handle(cx);
650 if (h == CX18_INVALID_TASK_HANDLE) {
651 CX18_ERR("Can't find valid task handle for "
652 "V4L2_ENC_CMD_PAUSE\n");
656 cx18_vapi(cx, CX18_CPU_CAPTURE_PAUSE, 1, h);
659 case V4L2_ENC_CMD_RESUME:
660 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_RESUME\n");
662 if (!atomic_read(&cx->ana_capturing))
664 if (!test_and_clear_bit(CX18_F_I_ENC_PAUSED, &cx->i_flags))
666 h = cx18_find_handle(cx);
667 if (h == CX18_INVALID_TASK_HANDLE) {
668 CX18_ERR("Can't find valid task handle for "
669 "V4L2_ENC_CMD_RESUME\n");
672 cx18_vapi(cx, CX18_CPU_CAPTURE_RESUME, 1, h);
677 CX18_DEBUG_IOCTL("Unknown cmd %d\n", enc->cmd);
683 static int cx18_try_encoder_cmd(struct file *file, void *fh,
684 struct v4l2_encoder_cmd *enc)
686 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
689 case V4L2_ENC_CMD_START:
690 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_START\n");
694 case V4L2_ENC_CMD_STOP:
695 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_STOP\n");
696 enc->flags &= V4L2_ENC_CMD_STOP_AT_GOP_END;
699 case V4L2_ENC_CMD_PAUSE:
700 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_PAUSE\n");
704 case V4L2_ENC_CMD_RESUME:
705 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_RESUME\n");
710 CX18_DEBUG_IOCTL("Unknown cmd %d\n", enc->cmd);
716 static int cx18_log_status(struct file *file, void *fh)
718 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
719 struct v4l2_input vidin;
720 struct v4l2_audio audin;
723 CX18_INFO("================= START STATUS CARD #%d =================\n", cx->num);
724 if (cx->hw_flags & CX18_HW_TVEEPROM) {
727 cx18_read_eeprom(cx, &tv);
729 cx18_call_i2c_clients(cx, VIDIOC_LOG_STATUS, NULL);
730 cx18_get_input(cx, cx->active_input, &vidin);
731 cx18_get_audio_input(cx, cx->audio_input, &audin);
732 CX18_INFO("Video Input: %s\n", vidin.name);
733 CX18_INFO("Audio Input: %s\n", audin.name);
734 mutex_lock(&cx->gpio_lock);
735 CX18_INFO("GPIO: direction 0x%08x, value 0x%08x\n",
736 cx->gpio_dir, cx->gpio_val);
737 mutex_unlock(&cx->gpio_lock);
738 CX18_INFO("Tuner: %s\n",
739 test_bit(CX18_F_I_RADIO_USER, &cx->i_flags) ? "Radio" : "TV");
740 cx2341x_log_status(&cx->params, cx->name);
741 CX18_INFO("Status flags: 0x%08lx\n", cx->i_flags);
742 for (i = 0; i < CX18_MAX_STREAMS; i++) {
743 struct cx18_stream *s = &cx->streams[i];
745 if (s->v4l2dev == NULL || s->buffers == 0)
747 CX18_INFO("Stream %s: status 0x%04lx, %d%% of %d KiB (%d buffers) in use\n",
749 (s->buffers - atomic_read(&s->q_free.buffers))
751 (s->buffers * s->buf_size) / 1024, s->buffers);
753 CX18_INFO("Read MPEG/VBI: %lld/%lld bytes\n",
754 (long long)cx->mpg_data_received,
755 (long long)cx->vbi_data_inserted);
756 CX18_INFO("================== END STATUS CARD #%d ==================\n", cx->num);
760 static int cx18_default(struct file *file, void *fh, int cmd, void *arg)
762 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
765 case VIDIOC_INT_S_AUDIO_ROUTING: {
766 struct v4l2_routing *route = arg;
768 CX18_DEBUG_IOCTL("VIDIOC_INT_S_AUDIO_ROUTING(%d, %d)\n",
769 route->input, route->output);
770 cx18_audio_set_route(cx, route);
774 case VIDIOC_INT_RESET: {
775 u32 val = *(u32 *)arg;
777 if ((val == 0) || (val & 0x01))
778 cx18_reset_ir_gpio(&cx->i2c_algo_cb_data[0]);
788 int cx18_v4l2_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
791 struct video_device *vfd = video_devdata(filp);
792 struct cx18_open_id *id = (struct cx18_open_id *)filp->private_data;
793 struct cx18 *cx = id->cx;
796 mutex_lock(&cx->serialize_lock);
798 if (cx18_debug & CX18_DBGFLG_IOCTL)
799 vfd->debug = V4L2_DEBUG_IOCTL | V4L2_DEBUG_IOCTL_ARG;
800 res = video_ioctl2(inode, filp, cmd, arg);
802 mutex_unlock(&cx->serialize_lock);
806 static const struct v4l2_ioctl_ops cx18_ioctl_ops = {
807 .vidioc_querycap = cx18_querycap,
808 .vidioc_g_priority = cx18_g_priority,
809 .vidioc_s_priority = cx18_s_priority,
810 .vidioc_s_audio = cx18_s_audio,
811 .vidioc_g_audio = cx18_g_audio,
812 .vidioc_enumaudio = cx18_enumaudio,
813 .vidioc_enum_input = cx18_enum_input,
814 .vidioc_cropcap = cx18_cropcap,
815 .vidioc_s_crop = cx18_s_crop,
816 .vidioc_g_crop = cx18_g_crop,
817 .vidioc_g_input = cx18_g_input,
818 .vidioc_s_input = cx18_s_input,
819 .vidioc_g_frequency = cx18_g_frequency,
820 .vidioc_s_frequency = cx18_s_frequency,
821 .vidioc_s_tuner = cx18_s_tuner,
822 .vidioc_g_tuner = cx18_g_tuner,
823 .vidioc_g_enc_index = cx18_g_enc_index,
824 .vidioc_g_std = cx18_g_std,
825 .vidioc_s_std = cx18_s_std,
826 .vidioc_log_status = cx18_log_status,
827 .vidioc_enum_fmt_vid_cap = cx18_enum_fmt_vid_cap,
828 .vidioc_encoder_cmd = cx18_encoder_cmd,
829 .vidioc_try_encoder_cmd = cx18_try_encoder_cmd,
830 .vidioc_g_fmt_vid_cap = cx18_g_fmt_vid_cap,
831 .vidioc_g_fmt_vbi_cap = cx18_g_fmt_vbi_cap,
832 .vidioc_g_fmt_sliced_vbi_cap = cx18_g_fmt_sliced_vbi_cap,
833 .vidioc_s_fmt_vid_cap = cx18_s_fmt_vid_cap,
834 .vidioc_s_fmt_vbi_cap = cx18_s_fmt_vbi_cap,
835 .vidioc_s_fmt_sliced_vbi_cap = cx18_s_fmt_sliced_vbi_cap,
836 .vidioc_try_fmt_vid_cap = cx18_try_fmt_vid_cap,
837 .vidioc_try_fmt_vbi_cap = cx18_try_fmt_vbi_cap,
838 .vidioc_try_fmt_sliced_vbi_cap = cx18_try_fmt_sliced_vbi_cap,
839 .vidioc_g_sliced_vbi_cap = cx18_g_sliced_vbi_cap,
840 .vidioc_g_chip_ident = cx18_g_chip_ident,
841 #ifdef CONFIG_VIDEO_ADV_DEBUG
842 .vidioc_g_register = cx18_g_register,
843 .vidioc_s_register = cx18_s_register,
845 .vidioc_default = cx18_default,
846 .vidioc_queryctrl = cx18_queryctrl,
847 .vidioc_querymenu = cx18_querymenu,
848 .vidioc_g_ext_ctrls = cx18_g_ext_ctrls,
849 .vidioc_s_ext_ctrls = cx18_s_ext_ctrls,
850 .vidioc_try_ext_ctrls = cx18_try_ext_ctrls,
853 void cx18_set_funcs(struct video_device *vdev)
855 vdev->ioctl_ops = &cx18_ioctl_ops;