Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 1 | /* |
| 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 Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 22 | #include "ivtv-ioctl.h" |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 23 | #include "ivtv-controls.h" |
| 24 | |
Hans Verkuil | f7b80e6 | 2010-06-27 06:07:26 -0300 | [diff] [blame^] | 25 | static int ivtv_s_stream_vbi_fmt(struct cx2341x_handler *cxhdl, u32 fmt) |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 26 | { |
Hans Verkuil | f7b80e6 | 2010-06-27 06:07:26 -0300 | [diff] [blame^] | 27 | struct ivtv *itv = container_of(cxhdl, struct ivtv, cxhdl); |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 28 | |
| 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 Verkuil | feb5bce | 2008-05-01 09:22:13 -0300 | [diff] [blame] | 52 | if (ivtv_get_service_set(itv->vbi.sliced_in) == 0) { |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 53 | 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 Verkuil | feb5bce | 2008-05-01 09:22:13 -0300 | [diff] [blame] | 57 | ivtv_expand_service_set(itv->vbi.sliced_in, itv->is_50hz); |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 58 | } |
| 59 | return 0; |
| 60 | } |
| 61 | |
Hans Verkuil | f7b80e6 | 2010-06-27 06:07:26 -0300 | [diff] [blame^] | 62 | static int ivtv_s_video_encoding(struct cx2341x_handler *cxhdl, u32 val) |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 63 | { |
Hans Verkuil | f7b80e6 | 2010-06-27 06:07:26 -0300 | [diff] [blame^] | 64 | 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 Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 67 | |
Hans Verkuil | f7b80e6 | 2010-06-27 06:07:26 -0300 | [diff] [blame^] | 68 | /* 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 Verkuil | 3f038d8 | 2008-05-29 16:43:54 -0300 | [diff] [blame] | 74 | } |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 75 | |
Hans Verkuil | f7b80e6 | 2010-06-27 06:07:26 -0300 | [diff] [blame^] | 76 | static int ivtv_s_audio_sampling_freq(struct cx2341x_handler *cxhdl, u32 idx) |
Hans Verkuil | 3f038d8 | 2008-05-29 16:43:54 -0300 | [diff] [blame] | 77 | { |
Hans Verkuil | f7b80e6 | 2010-06-27 06:07:26 -0300 | [diff] [blame^] | 78 | static const u32 freqs[3] = { 44100, 48000, 32000 }; |
| 79 | struct ivtv *itv = container_of(cxhdl, struct ivtv, cxhdl); |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 80 | |
Hans Verkuil | f7b80e6 | 2010-06-27 06:07:26 -0300 | [diff] [blame^] | 81 | /* 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 Verkuil | 3f038d8 | 2008-05-29 16:43:54 -0300 | [diff] [blame] | 86 | } |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 87 | |
Hans Verkuil | f7b80e6 | 2010-06-27 06:07:26 -0300 | [diff] [blame^] | 88 | static int ivtv_s_audio_mode(struct cx2341x_handler *cxhdl, u32 val) |
Hans Verkuil | 3f038d8 | 2008-05-29 16:43:54 -0300 | [diff] [blame] | 89 | { |
Hans Verkuil | f7b80e6 | 2010-06-27 06:07:26 -0300 | [diff] [blame^] | 90 | struct ivtv *itv = container_of(cxhdl, struct ivtv, cxhdl); |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 91 | |
Hans Verkuil | f7b80e6 | 2010-06-27 06:07:26 -0300 | [diff] [blame^] | 92 | itv->dualwatch_stereo_mode = val; |
| 93 | return 0; |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 94 | } |
Hans Verkuil | f7b80e6 | 2010-06-27 06:07:26 -0300 | [diff] [blame^] | 95 | |
| 96 | struct 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 | }; |