blob: b31ee1bceef82c71bf3b13845bc55a5f481945ba [file] [log] [blame]
Hans Verkuil1a0adaf2007-04-27 12:31:25 -03001/*
2 ioctl control functions
3 Copyright (C) 2003-2004 Kevin Thayer <nufan_wfk at yahoo.com>
4 Copyright (C) 2005-2007 Hans Verkuil <hverkuil@xs4all.nl>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include "ivtv-driver.h"
Hans Verkuil1a0adaf2007-04-27 12:31:25 -030022#include "ivtv-ioctl.h"
Hans Verkuil1a0adaf2007-04-27 12:31:25 -030023#include "ivtv-controls.h"
24
Hans Verkuilf7b80e62010-06-27 06:07:26 -030025static int ivtv_s_stream_vbi_fmt(struct cx2341x_handler *cxhdl, u32 fmt)
Hans Verkuil1a0adaf2007-04-27 12:31:25 -030026{
Hans Verkuilf7b80e62010-06-27 06:07:26 -030027 struct ivtv *itv = container_of(cxhdl, struct ivtv, cxhdl);
Hans Verkuil1a0adaf2007-04-27 12:31:25 -030028
29 /* First try to allocate sliced VBI buffers if needed. */
30 if (fmt && itv->vbi.sliced_mpeg_data[0] == NULL) {
31 int i;
32
33 for (i = 0; i < IVTV_VBI_FRAMES; i++) {
34 /* Yuck, hardcoded. Needs to be a define */
35 itv->vbi.sliced_mpeg_data[i] = kmalloc(2049, GFP_KERNEL);
36 if (itv->vbi.sliced_mpeg_data[i] == NULL) {
37 while (--i >= 0) {
38 kfree(itv->vbi.sliced_mpeg_data[i]);
39 itv->vbi.sliced_mpeg_data[i] = NULL;
40 }
41 return -ENOMEM;
42 }
43 }
44 }
45
46 itv->vbi.insert_mpeg = fmt;
47
48 if (itv->vbi.insert_mpeg == 0) {
49 return 0;
50 }
51 /* Need sliced data for mpeg insertion */
Hans Verkuilfeb5bce2008-05-01 09:22:13 -030052 if (ivtv_get_service_set(itv->vbi.sliced_in) == 0) {
Hans Verkuil1a0adaf2007-04-27 12:31:25 -030053 if (itv->is_60hz)
54 itv->vbi.sliced_in->service_set = V4L2_SLICED_CAPTION_525;
55 else
56 itv->vbi.sliced_in->service_set = V4L2_SLICED_WSS_625;
Hans Verkuilfeb5bce2008-05-01 09:22:13 -030057 ivtv_expand_service_set(itv->vbi.sliced_in, itv->is_50hz);
Hans Verkuil1a0adaf2007-04-27 12:31:25 -030058 }
59 return 0;
60}
61
Hans Verkuilf7b80e62010-06-27 06:07:26 -030062static int ivtv_s_video_encoding(struct cx2341x_handler *cxhdl, u32 val)
Hans Verkuil1a0adaf2007-04-27 12:31:25 -030063{
Hans Verkuilf7b80e62010-06-27 06:07:26 -030064 struct ivtv *itv = container_of(cxhdl, struct ivtv, cxhdl);
65 int is_mpeg1 = val == V4L2_MPEG_VIDEO_ENCODING_MPEG_1;
66 struct v4l2_mbus_framefmt fmt;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -030067
Hans Verkuilf7b80e62010-06-27 06:07:26 -030068 /* fix videodecoder resolution */
69 fmt.width = cxhdl->width / (is_mpeg1 ? 2 : 1);
70 fmt.height = cxhdl->height;
71 fmt.code = V4L2_MBUS_FMT_FIXED;
72 v4l2_subdev_call(itv->sd_video, video, s_mbus_fmt, &fmt);
73 return 0;
Hans Verkuil3f038d82008-05-29 16:43:54 -030074}
Hans Verkuil1a0adaf2007-04-27 12:31:25 -030075
Hans Verkuilf7b80e62010-06-27 06:07:26 -030076static int ivtv_s_audio_sampling_freq(struct cx2341x_handler *cxhdl, u32 idx)
Hans Verkuil3f038d82008-05-29 16:43:54 -030077{
Hans Verkuilf7b80e62010-06-27 06:07:26 -030078 static const u32 freqs[3] = { 44100, 48000, 32000 };
79 struct ivtv *itv = container_of(cxhdl, struct ivtv, cxhdl);
Hans Verkuil1a0adaf2007-04-27 12:31:25 -030080
Hans Verkuilf7b80e62010-06-27 06:07:26 -030081 /* The audio clock of the digitizer must match the codec sample
82 rate otherwise you get some very strange effects. */
83 if (idx < ARRAY_SIZE(freqs))
84 ivtv_call_all(itv, audio, s_clock_freq, freqs[idx]);
85 return 0;
Hans Verkuil3f038d82008-05-29 16:43:54 -030086}
Hans Verkuil1a0adaf2007-04-27 12:31:25 -030087
Hans Verkuilf7b80e62010-06-27 06:07:26 -030088static int ivtv_s_audio_mode(struct cx2341x_handler *cxhdl, u32 val)
Hans Verkuil3f038d82008-05-29 16:43:54 -030089{
Hans Verkuilf7b80e62010-06-27 06:07:26 -030090 struct ivtv *itv = container_of(cxhdl, struct ivtv, cxhdl);
Hans Verkuil1a0adaf2007-04-27 12:31:25 -030091
Hans Verkuilf7b80e62010-06-27 06:07:26 -030092 itv->dualwatch_stereo_mode = val;
93 return 0;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -030094}
Hans Verkuilf7b80e62010-06-27 06:07:26 -030095
96struct cx2341x_handler_ops ivtv_cxhdl_ops = {
97 .s_audio_mode = ivtv_s_audio_mode,
98 .s_audio_sampling_freq = ivtv_s_audio_sampling_freq,
99 .s_video_encoding = ivtv_s_video_encoding,
100 .s_stream_vbi_fmt = ivtv_s_stream_vbi_fmt,
101};