2 * cx18 ioctl system call
4 * Derived from ivtv-ioctl.c
6 * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
24 #include "cx18-driver.h"
25 #include "cx18-version.h"
26 #include "cx18-mailbox.h"
28 #include "cx18-queue.h"
29 #include "cx18-fileops.h"
31 #include "cx18-audio.h"
32 #include "cx18-video.h"
33 #include "cx18-streams.h"
34 #include "cx18-ioctl.h"
35 #include "cx18-gpio.h"
36 #include "cx18-controls.h"
37 #include "cx18-cards.h"
38 #include "cx18-av-core.h"
39 #include <media/tveeprom.h>
40 #include <media/v4l2-chip-ident.h>
41 #include <linux/i2c-id.h>
43 u16 cx18_service2vbi(int 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;
53 return CX18_SLICED_TYPE_VPS;
59 static int valid_service_line(int field, int line, int is_pal)
61 return (is_pal && line >= 6 && (line != 23 || field == 0)) ||
62 (!is_pal && line >= 10 && line < 22);
65 static u16 select_service_from_set(int field, int line, u16 set, int is_pal)
67 u16 valid_set = (is_pal ? V4L2_SLICED_VBI_625 : V4L2_SLICED_VBI_525);
70 set = set & valid_set;
71 if (set == 0 || !valid_service_line(field, line, is_pal))
74 if (line == 21 && (set & V4L2_SLICED_CAPTION_525))
75 return V4L2_SLICED_CAPTION_525;
77 if (line == 16 && field == 0 && (set & V4L2_SLICED_VPS))
78 return V4L2_SLICED_VPS;
79 if (line == 23 && field == 0 && (set & V4L2_SLICED_WSS_625))
80 return V4L2_SLICED_WSS_625;
84 for (i = 0; i < 32; i++) {
91 void cx18_expand_service_set(struct v4l2_sliced_vbi_format *fmt, int is_pal)
93 u16 set = fmt->service_set;
97 for (f = 0; f < 2; f++) {
98 for (l = 0; l < 24; l++)
99 fmt->service_lines[f][l] = select_service_from_set(f, l, set, is_pal);
104 u16 cx18_get_service_set(struct v4l2_sliced_vbi_format *fmt)
109 for (f = 0; f < 2; f++) {
110 for (l = 0; l < 24; l++)
111 set |= fmt->service_lines[f][l];
116 static int cx18_cxc(struct cx18 *cx, unsigned int cmd, void *arg)
118 struct v4l2_register *regs = arg;
121 if (!capable(CAP_SYS_ADMIN))
123 if (regs->reg >= CX18_MEM_OFFSET + CX18_MEM_SIZE)
126 spin_lock_irqsave(&cx18_cards_lock, flags);
127 if (cmd == VIDIOC_DBG_G_REGISTER)
128 regs->val = read_enc(regs->reg);
130 write_enc(regs->val, regs->reg);
131 spin_unlock_irqrestore(&cx18_cards_lock, flags);
135 static int cx18_g_fmt_vid_cap(struct file *file, void *fh,
136 struct v4l2_format *fmt)
138 struct cx18_open_id *id = fh;
139 struct cx18 *cx = id->cx;
141 CX18_DEBUG_IOCTL("VIDIOC_G_FMT: V4L2_BUF_TYPE_VIDEO_CAPTURE\n");
143 fmt->fmt.pix.width = cx->params.width;
144 fmt->fmt.pix.height = cx->params.height;
145 fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
146 fmt->fmt.pix.field = V4L2_FIELD_INTERLACED;
147 if (id->type == CX18_ENC_STREAM_TYPE_YUV) {
148 fmt->fmt.pix.pixelformat = V4L2_PIX_FMT_HM12;
149 /* YUV size is (Y=(h*w) + UV=(h*(w/2))) */
150 fmt->fmt.pix.sizeimage =
151 fmt->fmt.pix.height * fmt->fmt.pix.width +
152 fmt->fmt.pix.height * (fmt->fmt.pix.width / 2);
154 fmt->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
155 fmt->fmt.pix.sizeimage = 128 * 1024;
160 static int cx18_g_fmt_vbi_cap(struct file *file, void *fh,
161 struct v4l2_format *fmt)
163 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
165 CX18_DEBUG_IOCTL("VIDIOC_G_FMT: V4L2_BUF_TYPE_VBI_CAPTURE\n");
167 fmt->fmt.vbi.sampling_rate = 27000000;
168 fmt->fmt.vbi.offset = 248;
169 fmt->fmt.vbi.samples_per_line = cx->vbi.raw_decoder_line_size - 4;
170 fmt->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
171 fmt->fmt.vbi.start[0] = cx->vbi.start[0];
172 fmt->fmt.vbi.start[1] = cx->vbi.start[1];
173 fmt->fmt.vbi.count[0] = fmt->fmt.vbi.count[1] = cx->vbi.count;
177 static int cx18_g_fmt_sliced_vbi_cap(struct file *file, void *fh,
178 struct v4l2_format *fmt)
183 static int cx18_try_fmt_vid_cap(struct file *file, void *fh,
184 struct v4l2_format *fmt)
186 struct cx18_open_id *id = fh;
187 struct cx18 *cx = id->cx;
189 int w = fmt->fmt.pix.width;
190 int h = fmt->fmt.pix.height;
192 CX18_DEBUG_IOCTL("VIDIOC_TRY_FMT: V4L2_BUF_TYPE_VIDEO_CAPTURE\n");
196 h = min(h, cx->is_50hz ? 576 : 480);
198 cx18_g_fmt_vid_cap(file, fh, fmt);
199 fmt->fmt.pix.width = w;
200 fmt->fmt.pix.height = h;
204 static int cx18_try_fmt_vbi_cap(struct file *file, void *fh,
205 struct v4l2_format *fmt)
207 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
209 CX18_DEBUG_IOCTL("VIDIOC_TRY_FMT: V4L2_BUF_TYPE_VBI_CAPTURE\n");
211 return cx18_g_fmt_vbi_cap(file, fh, fmt);
214 static int cx18_try_fmt_sliced_vbi_cap(struct file *file, void *fh,
215 struct v4l2_format *fmt)
220 static int cx18_s_fmt_vid_cap(struct file *file, void *fh,
221 struct v4l2_format *fmt)
223 struct cx18_open_id *id = fh;
224 struct cx18 *cx = id->cx;
226 int w = fmt->fmt.pix.width;
227 int h = fmt->fmt.pix.height;
229 ret = v4l2_prio_check(&cx->prio, &id->prio);
233 CX18_DEBUG_IOCTL("VIDIOC_S_FMT: V4L2_BUF_TYPE_VIDEO_CAPTURE\n");
235 ret = cx18_try_fmt_vid_cap(file, fh, fmt);
239 if (cx->params.width == w && cx->params.height == h)
242 if (atomic_read(&cx->ana_capturing) > 0)
245 cx->params.width = w;
246 cx->params.height = h;
247 cx18_av_cmd(cx, VIDIOC_S_FMT, fmt);
248 return cx18_g_fmt_vid_cap(file, fh, fmt);
251 static int cx18_s_fmt_vbi_cap(struct file *file, void *fh,
252 struct v4l2_format *fmt)
254 struct cx18_open_id *id = fh;
255 struct cx18 *cx = id->cx;
258 ret = v4l2_prio_check(&cx->prio, &id->prio);
262 CX18_DEBUG_IOCTL("VIDIOC_S_FMT: V4L2_BUF_TYPE_VBI_CAPTURE\n");
264 if (id->type == CX18_ENC_STREAM_TYPE_VBI &&
265 cx->vbi.sliced_in->service_set &&
266 atomic_read(&cx->ana_capturing) > 0)
269 cx->vbi.sliced_in->service_set = 0;
270 cx18_av_cmd(cx, VIDIOC_S_FMT, &cx->vbi.in);
271 return cx18_g_fmt_vbi_cap(file, fh, fmt);
274 static int cx18_s_fmt_sliced_vbi_cap(struct file *file, void *fh,
275 struct v4l2_format *fmt)
280 static int cx18_g_chip_ident(struct file *file, void *fh,
281 struct v4l2_chip_ident *chip)
283 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
285 CX18_DEBUG_IOCTL("VIDIOC_G_CHIP_IDENT\n");
287 chip->ident = V4L2_IDENT_NONE;
289 if (chip->match_type == V4L2_CHIP_MATCH_HOST) {
290 if (v4l2_chip_match_host(chip->match_type, chip->match_chip))
291 chip->ident = V4L2_IDENT_CX23418;
294 if (chip->match_type == V4L2_CHIP_MATCH_I2C_DRIVER)
295 return cx18_i2c_id(cx, chip->match_chip, VIDIOC_G_CHIP_IDENT,
297 if (chip->match_type == V4L2_CHIP_MATCH_I2C_ADDR)
298 return cx18_call_i2c_client(cx, chip->match_chip,
299 VIDIOC_G_CHIP_IDENT, chip);
303 static int cx18_g_register(struct file *file, void *fh,
304 struct v4l2_register *reg)
306 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
308 CX18_DEBUG_IOCTL("VIDIOC_DBG_G_REGISTER\n");
310 if (v4l2_chip_match_host(reg->match_type, reg->match_chip))
311 return cx18_cxc(cx, VIDIOC_DBG_G_REGISTER, reg);
312 if (reg->match_type == V4L2_CHIP_MATCH_I2C_DRIVER)
313 return cx18_i2c_id(cx, reg->match_chip, VIDIOC_DBG_G_REGISTER,
315 return cx18_call_i2c_client(cx, reg->match_chip, VIDIOC_DBG_G_REGISTER,
319 static int cx18_s_register(struct file *file, void *fh,
320 struct v4l2_register *reg)
322 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
324 CX18_DEBUG_IOCTL("VIDIOC_DBG_S_REGISTER\n");
326 if (v4l2_chip_match_host(reg->match_type, reg->match_chip))
327 return cx18_cxc(cx, VIDIOC_DBG_S_REGISTER, reg);
328 if (reg->match_type == V4L2_CHIP_MATCH_I2C_DRIVER)
329 return cx18_i2c_id(cx, reg->match_chip, VIDIOC_DBG_S_REGISTER,
331 return cx18_call_i2c_client(cx, reg->match_chip, VIDIOC_DBG_S_REGISTER,
335 static int cx18_g_priority(struct file *file, void *fh, enum v4l2_priority *p)
337 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
339 CX18_DEBUG_IOCTL("VIDIOC_G_PRIORITY\n");
341 *p = v4l2_prio_max(&cx->prio);
345 static int cx18_s_priority(struct file *file, void *fh, enum v4l2_priority prio)
347 struct cx18_open_id *id = fh;
348 struct cx18 *cx = id->cx;
350 CX18_DEBUG_IOCTL("VIDIOC_S_PRIORITY\n");
352 return v4l2_prio_change(&cx->prio, &id->prio, prio);
355 static int cx18_querycap(struct file *file, void *fh,
356 struct v4l2_capability *vcap)
358 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
360 CX18_DEBUG_IOCTL("VIDIOC_QUERYCAP\n");
362 strlcpy(vcap->driver, CX18_DRIVER_NAME, sizeof(vcap->driver));
363 strlcpy(vcap->card, cx->card_name, sizeof(vcap->card));
364 strlcpy(vcap->bus_info, pci_name(cx->dev), sizeof(vcap->bus_info));
365 vcap->version = CX18_DRIVER_VERSION; /* version */
366 vcap->capabilities = cx->v4l2_cap; /* capabilities */
370 static int cx18_enumaudio(struct file *file, void *fh, struct v4l2_audio *vin)
372 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
374 CX18_DEBUG_IOCTL("VIDIOC_ENUMAUDIO\n");
376 return cx18_get_audio_input(cx, vin->index, vin);
379 static int cx18_g_audio(struct file *file, void *fh, struct v4l2_audio *vin)
381 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
383 CX18_DEBUG_IOCTL("VIDIOC_G_AUDIO\n");
385 vin->index = cx->audio_input;
386 return cx18_get_audio_input(cx, vin->index, vin);
389 static int cx18_s_audio(struct file *file, void *fh, struct v4l2_audio *vout)
391 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
393 CX18_DEBUG_IOCTL("VIDIOC_S_AUDIO\n");
395 if (vout->index >= cx->nof_audio_inputs)
397 cx->audio_input = vout->index;
398 cx18_audio_set_io(cx);
402 static int cx18_enum_input(struct file *file, void *fh, struct v4l2_input *vin)
404 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
406 CX18_DEBUG_IOCTL("VIDIOC_ENUMINPUT\n");
408 /* set it to defaults from our table */
409 return cx18_get_input(cx, vin->index, vin);
412 static int cx18_cropcap(struct file *file, void *fh,
413 struct v4l2_cropcap *cropcap)
415 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
417 CX18_DEBUG_IOCTL("VIDIOC_CROPCAP\n");
419 if (cropcap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
421 cropcap->bounds.top = cropcap->bounds.left = 0;
422 cropcap->bounds.width = 720;
423 cropcap->bounds.height = cx->is_50hz ? 576 : 480;
424 cropcap->pixelaspect.numerator = cx->is_50hz ? 59 : 10;
425 cropcap->pixelaspect.denominator = cx->is_50hz ? 54 : 11;
426 cropcap->defrect = cropcap->bounds;
430 static int cx18_s_crop(struct file *file, void *fh, struct v4l2_crop *crop)
432 struct cx18_open_id *id = fh;
433 struct cx18 *cx = id->cx;
436 ret = v4l2_prio_check(&cx->prio, &id->prio);
440 CX18_DEBUG_IOCTL("VIDIOC_S_CROP\n");
442 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
444 return cx18_av_cmd(cx, VIDIOC_S_CROP, crop);
447 static int cx18_g_crop(struct file *file, void *fh, struct v4l2_crop *crop)
449 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
451 CX18_DEBUG_IOCTL("VIDIOC_G_CROP\n");
453 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
455 return cx18_av_cmd(cx, VIDIOC_G_CROP, crop);
458 static int cx18_enum_fmt_vid_cap(struct file *file, void *fh,
459 struct v4l2_fmtdesc *fmt)
461 static struct v4l2_fmtdesc formats[] = {
462 { 0, V4L2_BUF_TYPE_VIDEO_CAPTURE, 0,
463 "HM12 (YUV 4:1:1)", V4L2_PIX_FMT_HM12, { 0, 0, 0, 0 }
465 { 1, V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FMT_FLAG_COMPRESSED,
466 "MPEG", V4L2_PIX_FMT_MPEG, { 0, 0, 0, 0 }
470 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
472 CX18_DEBUG_IOCTL("VIDIOC_ENUM_FMT: V4L2_BUF_TYPE_VIDEO_CAPTURE\n");
476 *fmt = formats[fmt->index];
480 static int cx18_g_input(struct file *file, void *fh, unsigned int *i)
482 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
484 CX18_DEBUG_IOCTL("VIDIOC_G_INPUT\n");
486 *i = cx->active_input;
490 int cx18_s_input(struct file *file, void *fh, unsigned int inp)
492 struct cx18_open_id *id = fh;
493 struct cx18 *cx = id->cx;
496 ret = v4l2_prio_check(&cx->prio, &id->prio);
500 CX18_DEBUG_IOCTL("VIDIOC_S_INPUT\n");
502 if (inp < 0 || inp >= cx->nof_inputs)
505 if (inp == cx->active_input) {
506 CX18_DEBUG_INFO("Input unchanged\n");
510 CX18_DEBUG_INFO("Changing input from %d to %d\n",
511 cx->active_input, inp);
513 cx->active_input = inp;
514 /* Set the audio input to whatever is appropriate for the input type. */
515 cx->audio_input = cx->card->video_inputs[inp].audio_index;
517 /* prevent others from messing with the streams until
518 we're finished changing inputs. */
520 cx18_video_set_io(cx);
521 cx18_audio_set_io(cx);
526 static int cx18_g_frequency(struct file *file, void *fh,
527 struct v4l2_frequency *vf)
529 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
531 CX18_DEBUG_IOCTL("VIDIOC_G_FREQUENCY\n");
536 cx18_call_i2c_clients(cx, VIDIOC_G_FREQUENCY, vf);
540 int cx18_s_frequency(struct file *file, void *fh, struct v4l2_frequency *vf)
542 struct cx18_open_id *id = fh;
543 struct cx18 *cx = id->cx;
546 ret = v4l2_prio_check(&cx->prio, &id->prio);
550 CX18_DEBUG_IOCTL("VIDIOC_S_FREQUENCY\n");
556 CX18_DEBUG_INFO("v4l2 ioctl: set frequency %d\n", vf->frequency);
557 cx18_call_i2c_clients(cx, VIDIOC_S_FREQUENCY, vf);
562 static int cx18_g_std(struct file *file, void *fh, v4l2_std_id *std)
564 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
566 CX18_DEBUG_IOCTL("VIDIOC_G_STD\n");
572 int cx18_s_std(struct file *file, void *fh, v4l2_std_id *std)
574 struct cx18_open_id *id = fh;
575 struct cx18 *cx = id->cx;
578 ret = v4l2_prio_check(&cx->prio, &id->prio);
582 CX18_DEBUG_IOCTL("VIDIOC_S_STD\n");
584 if ((*std & V4L2_STD_ALL) == 0)
590 if (test_bit(CX18_F_I_RADIO_USER, &cx->i_flags) ||
591 atomic_read(&cx->ana_capturing) > 0) {
592 /* Switching standard would turn off the radio or mess
593 with already running streams, prevent that by
599 cx->is_60hz = (*std & V4L2_STD_525_60) ? 1 : 0;
600 cx->params.is_50hz = cx->is_50hz = !cx->is_60hz;
601 cx->params.width = 720;
602 cx->params.height = cx->is_50hz ? 576 : 480;
603 cx->vbi.count = cx->is_50hz ? 18 : 12;
604 cx->vbi.start[0] = cx->is_50hz ? 6 : 10;
605 cx->vbi.start[1] = cx->is_50hz ? 318 : 273;
606 cx->vbi.sliced_decoder_line_size = cx->is_60hz ? 272 : 284;
607 CX18_DEBUG_INFO("Switching standard to %llx.\n",
608 (unsigned long long) cx->std);
611 cx18_call_i2c_clients(cx, VIDIOC_S_STD, &cx->std);
615 static int cx18_s_tuner(struct file *file, void *fh, struct v4l2_tuner *vt)
617 struct cx18_open_id *id = fh;
618 struct cx18 *cx = id->cx;
621 ret = v4l2_prio_check(&cx->prio, &id->prio);
625 CX18_DEBUG_IOCTL("VIDIOC_S_TUNER\n");
630 /* Setting tuner can only set audio mode */
631 cx18_call_i2c_clients(cx, VIDIOC_S_TUNER, vt);
636 static int cx18_g_tuner(struct file *file, void *fh, struct v4l2_tuner *vt)
638 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
640 CX18_DEBUG_IOCTL("VIDIOC_G_TUNER\n");
645 cx18_call_i2c_clients(cx, VIDIOC_G_TUNER, vt);
647 if (test_bit(CX18_F_I_RADIO_USER, &cx->i_flags)) {
648 strlcpy(vt->name, "cx18 Radio Tuner", sizeof(vt->name));
649 vt->type = V4L2_TUNER_RADIO;
651 strlcpy(vt->name, "cx18 TV Tuner", sizeof(vt->name));
652 vt->type = V4L2_TUNER_ANALOG_TV;
658 static int cx18_g_sliced_vbi_cap(struct file *file, void *fh,
659 struct v4l2_sliced_vbi_cap *cap)
664 static int cx18_g_enc_index(struct file *file, void *fh,
665 struct v4l2_enc_idx *idx)
670 static int cx18_encoder_cmd(struct file *file, void *fh,
671 struct v4l2_encoder_cmd *enc)
673 struct cx18_open_id *id = fh;
674 struct cx18 *cx = id->cx;
676 CX18_DEBUG_IOCTL("VIDIOC_ENCODER_CMD:\n");
679 case V4L2_ENC_CMD_START:
680 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_START\n");
682 return cx18_start_capture(id);
684 case V4L2_ENC_CMD_STOP:
685 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_STOP\n");
686 enc->flags &= V4L2_ENC_CMD_STOP_AT_GOP_END;
687 cx18_stop_capture(id,
688 enc->flags & V4L2_ENC_CMD_STOP_AT_GOP_END);
691 case V4L2_ENC_CMD_PAUSE:
692 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_PAUSE\n");
694 if (!atomic_read(&cx->ana_capturing))
696 if (test_and_set_bit(CX18_F_I_ENC_PAUSED, &cx->i_flags))
699 cx18_vapi(cx, CX18_CPU_CAPTURE_PAUSE, 1, cx18_find_handle(cx));
702 case V4L2_ENC_CMD_RESUME:
703 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_RESUME\n");
705 if (!atomic_read(&cx->ana_capturing))
707 if (!test_and_clear_bit(CX18_F_I_ENC_PAUSED, &cx->i_flags))
709 cx18_vapi(cx, CX18_CPU_CAPTURE_RESUME, 1, cx18_find_handle(cx));
714 CX18_DEBUG_IOCTL("Unknown cmd %d\n", enc->cmd);
720 static int cx18_try_encoder_cmd(struct file *file, void *fh,
721 struct v4l2_encoder_cmd *enc)
723 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
725 CX18_DEBUG_IOCTL("VIDIOC_TRY_ENCDOER_CMD:\n");
728 case V4L2_ENC_CMD_START:
729 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_START\n");
733 case V4L2_ENC_CMD_STOP:
734 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_STOP\n");
735 enc->flags &= V4L2_ENC_CMD_STOP_AT_GOP_END;
738 case V4L2_ENC_CMD_PAUSE:
739 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_PAUSE\n");
743 case V4L2_ENC_CMD_RESUME:
744 CX18_DEBUG_IOCTL("V4L2_ENC_CMD_RESUME\n");
749 CX18_DEBUG_IOCTL("Unknown cmd %d\n", enc->cmd);
755 static int cx18_log_status(struct file *file, void *fh)
757 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
758 struct v4l2_input vidin;
759 struct v4l2_audio audin;
762 CX18_DEBUG_IOCTL("VIDIOC_LOG_STATUS\n");
763 CX18_INFO("================= START STATUS CARD #%d =================\n", cx->num);
764 if (cx->hw_flags & CX18_HW_TVEEPROM) {
767 cx18_read_eeprom(cx, &tv);
769 cx18_call_i2c_clients(cx, VIDIOC_LOG_STATUS, NULL);
770 cx18_get_input(cx, cx->active_input, &vidin);
771 cx18_get_audio_input(cx, cx->audio_input, &audin);
772 CX18_INFO("Video Input: %s\n", vidin.name);
773 CX18_INFO("Audio Input: %s\n", audin.name);
774 CX18_INFO("Tuner: %s\n",
775 test_bit(CX18_F_I_RADIO_USER, &cx->i_flags) ? "Radio" : "TV");
776 cx2341x_log_status(&cx->params, cx->name);
777 CX18_INFO("Status flags: 0x%08lx\n", cx->i_flags);
778 for (i = 0; i < CX18_MAX_STREAMS; i++) {
779 struct cx18_stream *s = &cx->streams[i];
781 if (s->v4l2dev == NULL || s->buffers == 0)
783 CX18_INFO("Stream %s: status 0x%04lx, %d%% of %d KiB (%d buffers) in use\n",
785 (s->buffers - s->q_free.buffers) * 100 / s->buffers,
786 (s->buffers * s->buf_size) / 1024, s->buffers);
788 CX18_INFO("Read MPEG/VBI: %lld/%lld bytes\n",
789 (long long)cx->mpg_data_received,
790 (long long)cx->vbi_data_inserted);
791 CX18_INFO("================== END STATUS CARD #%d ==================\n", cx->num);
795 static int cx18_default(struct file *file, void *fh, int cmd, void *arg)
797 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
800 case VIDIOC_INT_S_AUDIO_ROUTING: {
801 struct v4l2_routing *route = arg;
802 CX18_DEBUG_IOCTL("VIDIOC_INT_S_AUDIO_ROUTING (%d, %d)\n",
803 route->input, route->output);
804 cx18_audio_set_route(cx, route);
807 case VIDIOC_INT_RESET: {
808 u32 val = *(u32 *)arg;
809 CX18_DEBUG_IOCTL("VIDIOC_INT_RESET (%#10x)\n", val);
810 /* No op right now */
811 /* cx18_av_cmd(cx, cmd, arg) */
812 /* cx18_call_i2c_clients(cx, cmd, arg) */
816 if (cx18_debug & CX18_DBGFLG_IOCTL) {
817 printk(KERN_INFO "cx18%d ioctl: unsupported cmd: ",
819 v4l_printk_ioctl(cmd);
827 int cx18_v4l2_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
830 struct cx18_open_id *id = (struct cx18_open_id *)filp->private_data;
831 struct cx18 *cx = id->cx;
834 mutex_lock(&cx->serialize_lock);
835 res = video_ioctl2(inode, filp, cmd, arg);
836 mutex_unlock(&cx->serialize_lock);
840 void cx18_set_funcs(struct video_device *vdev)
842 vdev->vidioc_querycap = cx18_querycap;
843 vdev->vidioc_g_priority = cx18_g_priority;
844 vdev->vidioc_s_priority = cx18_s_priority;
845 vdev->vidioc_s_audio = cx18_s_audio;
846 vdev->vidioc_g_audio = cx18_g_audio;
847 vdev->vidioc_enumaudio = cx18_enumaudio;
848 vdev->vidioc_enum_input = cx18_enum_input;
849 vdev->vidioc_cropcap = cx18_cropcap;
850 vdev->vidioc_s_crop = cx18_s_crop;
851 vdev->vidioc_g_crop = cx18_g_crop;
852 vdev->vidioc_g_input = cx18_g_input;
853 vdev->vidioc_s_input = cx18_s_input;
854 vdev->vidioc_g_frequency = cx18_g_frequency;
855 vdev->vidioc_s_frequency = cx18_s_frequency;
856 vdev->vidioc_s_tuner = cx18_s_tuner;
857 vdev->vidioc_g_tuner = cx18_g_tuner;
858 vdev->vidioc_g_enc_index = cx18_g_enc_index;
859 vdev->vidioc_g_std = cx18_g_std;
860 vdev->vidioc_s_std = cx18_s_std;
861 vdev->vidioc_log_status = cx18_log_status;
862 vdev->vidioc_enum_fmt_vid_cap = cx18_enum_fmt_vid_cap;
863 vdev->vidioc_encoder_cmd = cx18_encoder_cmd;
864 vdev->vidioc_try_encoder_cmd = cx18_try_encoder_cmd;
865 vdev->vidioc_g_fmt_vid_cap = cx18_g_fmt_vid_cap;
866 vdev->vidioc_g_fmt_vbi_cap = cx18_g_fmt_vbi_cap;
867 vdev->vidioc_g_fmt_sliced_vbi_cap = cx18_g_fmt_sliced_vbi_cap;
868 vdev->vidioc_s_fmt_vid_cap = cx18_s_fmt_vid_cap;
869 vdev->vidioc_s_fmt_vbi_cap = cx18_s_fmt_vbi_cap;
870 vdev->vidioc_s_fmt_sliced_vbi_cap = cx18_s_fmt_sliced_vbi_cap;
871 vdev->vidioc_try_fmt_vid_cap = cx18_try_fmt_vid_cap;
872 vdev->vidioc_try_fmt_vbi_cap = cx18_try_fmt_vbi_cap;
873 vdev->vidioc_try_fmt_sliced_vbi_cap = cx18_try_fmt_sliced_vbi_cap;
874 vdev->vidioc_g_sliced_vbi_cap = cx18_g_sliced_vbi_cap;
875 vdev->vidioc_g_chip_ident = cx18_g_chip_ident;
876 vdev->vidioc_g_register = cx18_g_register;
877 vdev->vidioc_s_register = cx18_s_register;
878 vdev->vidioc_default = cx18_default;
879 vdev->vidioc_queryctrl = cx18_queryctrl;
880 vdev->vidioc_querymenu = cx18_querymenu;
881 vdev->vidioc_g_ctrl = cx18_g_ctrl;
882 vdev->vidioc_s_ctrl = cx18_s_ctrl;
883 vdev->vidioc_g_ext_ctrls = cx18_g_ext_ctrls;
884 vdev->vidioc_s_ext_ctrls = cx18_s_ext_ctrls;
885 vdev->vidioc_try_ext_ctrls = cx18_try_ext_ctrls;