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" |
Hans Verkuil | debf800 | 2011-12-15 10:32:53 -0300 | [diff] [blame] | 24 | #include "ivtv-mailbox.h" |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 25 | |
Hans Verkuil | f7b80e6 | 2010-06-27 06:07:26 -0300 | [diff] [blame] | 26 | 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] | 27 | { |
Hans Verkuil | f7b80e6 | 2010-06-27 06:07:26 -0300 | [diff] [blame] | 28 | struct ivtv *itv = container_of(cxhdl, struct ivtv, cxhdl); |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 29 | |
| 30 | /* First try to allocate sliced VBI buffers if needed. */ |
| 31 | if (fmt && itv->vbi.sliced_mpeg_data[0] == NULL) { |
| 32 | int i; |
| 33 | |
| 34 | for (i = 0; i < IVTV_VBI_FRAMES; i++) { |
| 35 | /* Yuck, hardcoded. Needs to be a define */ |
| 36 | itv->vbi.sliced_mpeg_data[i] = kmalloc(2049, GFP_KERNEL); |
| 37 | if (itv->vbi.sliced_mpeg_data[i] == NULL) { |
| 38 | while (--i >= 0) { |
| 39 | kfree(itv->vbi.sliced_mpeg_data[i]); |
| 40 | itv->vbi.sliced_mpeg_data[i] = NULL; |
| 41 | } |
| 42 | return -ENOMEM; |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | itv->vbi.insert_mpeg = fmt; |
| 48 | |
| 49 | if (itv->vbi.insert_mpeg == 0) { |
| 50 | return 0; |
| 51 | } |
| 52 | /* Need sliced data for mpeg insertion */ |
Hans Verkuil | feb5bce | 2008-05-01 09:22:13 -0300 | [diff] [blame] | 53 | if (ivtv_get_service_set(itv->vbi.sliced_in) == 0) { |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 54 | if (itv->is_60hz) |
| 55 | itv->vbi.sliced_in->service_set = V4L2_SLICED_CAPTION_525; |
| 56 | else |
| 57 | itv->vbi.sliced_in->service_set = V4L2_SLICED_WSS_625; |
Hans Verkuil | feb5bce | 2008-05-01 09:22:13 -0300 | [diff] [blame] | 58 | ivtv_expand_service_set(itv->vbi.sliced_in, itv->is_50hz); |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 59 | } |
| 60 | return 0; |
| 61 | } |
| 62 | |
Hans Verkuil | f7b80e6 | 2010-06-27 06:07:26 -0300 | [diff] [blame] | 63 | static int ivtv_s_video_encoding(struct cx2341x_handler *cxhdl, u32 val) |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 64 | { |
Hans Verkuil | f7b80e6 | 2010-06-27 06:07:26 -0300 | [diff] [blame] | 65 | struct ivtv *itv = container_of(cxhdl, struct ivtv, cxhdl); |
| 66 | int is_mpeg1 = val == V4L2_MPEG_VIDEO_ENCODING_MPEG_1; |
Hans Verkuil | ebf984b | 2015-04-09 04:05:59 -0300 | [diff] [blame] | 67 | struct v4l2_subdev_format format = { |
| 68 | .which = V4L2_SUBDEV_FORMAT_ACTIVE, |
| 69 | }; |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 70 | |
Hans Verkuil | f7b80e6 | 2010-06-27 06:07:26 -0300 | [diff] [blame] | 71 | /* fix videodecoder resolution */ |
Hans Verkuil | ebf984b | 2015-04-09 04:05:59 -0300 | [diff] [blame] | 72 | format.format.width = cxhdl->width / (is_mpeg1 ? 2 : 1); |
| 73 | format.format.height = cxhdl->height; |
| 74 | format.format.code = MEDIA_BUS_FMT_FIXED; |
| 75 | v4l2_subdev_call(itv->sd_video, pad, set_fmt, NULL, &format); |
Hans Verkuil | f7b80e6 | 2010-06-27 06:07:26 -0300 | [diff] [blame] | 76 | return 0; |
Hans Verkuil | 3f038d8 | 2008-05-29 16:43:54 -0300 | [diff] [blame] | 77 | } |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 78 | |
Hans Verkuil | f7b80e6 | 2010-06-27 06:07:26 -0300 | [diff] [blame] | 79 | 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] | 80 | { |
Hans Verkuil | f7b80e6 | 2010-06-27 06:07:26 -0300 | [diff] [blame] | 81 | static const u32 freqs[3] = { 44100, 48000, 32000 }; |
| 82 | struct ivtv *itv = container_of(cxhdl, struct ivtv, cxhdl); |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 83 | |
Hans Verkuil | f7b80e6 | 2010-06-27 06:07:26 -0300 | [diff] [blame] | 84 | /* The audio clock of the digitizer must match the codec sample |
| 85 | rate otherwise you get some very strange effects. */ |
| 86 | if (idx < ARRAY_SIZE(freqs)) |
| 87 | ivtv_call_all(itv, audio, s_clock_freq, freqs[idx]); |
| 88 | return 0; |
Hans Verkuil | 3f038d8 | 2008-05-29 16:43:54 -0300 | [diff] [blame] | 89 | } |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 90 | |
Hans Verkuil | f7b80e6 | 2010-06-27 06:07:26 -0300 | [diff] [blame] | 91 | static int ivtv_s_audio_mode(struct cx2341x_handler *cxhdl, u32 val) |
Hans Verkuil | 3f038d8 | 2008-05-29 16:43:54 -0300 | [diff] [blame] | 92 | { |
Hans Verkuil | f7b80e6 | 2010-06-27 06:07:26 -0300 | [diff] [blame] | 93 | struct ivtv *itv = container_of(cxhdl, struct ivtv, cxhdl); |
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 | itv->dualwatch_stereo_mode = val; |
| 96 | return 0; |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 97 | } |
Hans Verkuil | f7b80e6 | 2010-06-27 06:07:26 -0300 | [diff] [blame] | 98 | |
| 99 | struct cx2341x_handler_ops ivtv_cxhdl_ops = { |
| 100 | .s_audio_mode = ivtv_s_audio_mode, |
| 101 | .s_audio_sampling_freq = ivtv_s_audio_sampling_freq, |
| 102 | .s_video_encoding = ivtv_s_video_encoding, |
| 103 | .s_stream_vbi_fmt = ivtv_s_stream_vbi_fmt, |
| 104 | }; |
Hans Verkuil | debf800 | 2011-12-15 10:32:53 -0300 | [diff] [blame] | 105 | |
| 106 | int ivtv_g_pts_frame(struct ivtv *itv, s64 *pts, s64 *frame) |
| 107 | { |
| 108 | u32 data[CX2341X_MBOX_MAX_DATA]; |
| 109 | |
| 110 | if (test_bit(IVTV_F_I_VALID_DEC_TIMINGS, &itv->i_flags)) { |
| 111 | *pts = (s64)((u64)itv->last_dec_timing[2] << 32) | |
| 112 | (u64)itv->last_dec_timing[1]; |
| 113 | *frame = itv->last_dec_timing[0]; |
| 114 | return 0; |
| 115 | } |
| 116 | *pts = 0; |
| 117 | *frame = 0; |
| 118 | if (atomic_read(&itv->decoding)) { |
| 119 | if (ivtv_api(itv, CX2341X_DEC_GET_TIMING_INFO, 5, data)) { |
| 120 | IVTV_DEBUG_WARN("GET_TIMING: couldn't read clock\n"); |
| 121 | return -EIO; |
| 122 | } |
| 123 | memcpy(itv->last_dec_timing, data, sizeof(itv->last_dec_timing)); |
| 124 | set_bit(IVTV_F_I_VALID_DEC_TIMINGS, &itv->i_flags); |
| 125 | *pts = (s64)((u64) data[2] << 32) | (u64) data[1]; |
| 126 | *frame = data[0]; |
| 127 | /*timing->scr = (u64) (((u64) data[4] << 32) | (u64) (data[3]));*/ |
| 128 | } |
| 129 | return 0; |
| 130 | } |
| 131 | |
| 132 | static int ivtv_g_volatile_ctrl(struct v4l2_ctrl *ctrl) |
| 133 | { |
Hans Verkuil | eb2ba85 | 2012-03-02 13:02:11 -0300 | [diff] [blame] | 134 | struct ivtv *itv = container_of(ctrl->handler, struct ivtv, cxhdl.hdl); |
Hans Verkuil | debf800 | 2011-12-15 10:32:53 -0300 | [diff] [blame] | 135 | |
| 136 | switch (ctrl->id) { |
| 137 | /* V4L2_CID_MPEG_VIDEO_DEC_PTS and V4L2_CID_MPEG_VIDEO_DEC_FRAME |
| 138 | control cluster */ |
| 139 | case V4L2_CID_MPEG_VIDEO_DEC_PTS: |
Hans Verkuil | 2a9ec37 | 2014-04-27 03:38:13 -0300 | [diff] [blame] | 140 | return ivtv_g_pts_frame(itv, itv->ctrl_pts->p_new.p_s64, |
| 141 | itv->ctrl_frame->p_new.p_s64); |
Hans Verkuil | debf800 | 2011-12-15 10:32:53 -0300 | [diff] [blame] | 142 | } |
| 143 | return 0; |
| 144 | } |
| 145 | |
| 146 | static int ivtv_s_ctrl(struct v4l2_ctrl *ctrl) |
| 147 | { |
Hans Verkuil | eb2ba85 | 2012-03-02 13:02:11 -0300 | [diff] [blame] | 148 | struct ivtv *itv = container_of(ctrl->handler, struct ivtv, cxhdl.hdl); |
Hans Verkuil | debf800 | 2011-12-15 10:32:53 -0300 | [diff] [blame] | 149 | |
| 150 | switch (ctrl->id) { |
| 151 | /* V4L2_CID_MPEG_AUDIO_DEC_PLAYBACK and MULTILINGUAL_PLAYBACK |
| 152 | control cluster */ |
| 153 | case V4L2_CID_MPEG_AUDIO_DEC_PLAYBACK: |
| 154 | itv->audio_stereo_mode = itv->ctrl_audio_playback->val - 1; |
| 155 | itv->audio_bilingual_mode = itv->ctrl_audio_multilingual_playback->val - 1; |
| 156 | ivtv_vapi(itv, CX2341X_DEC_SET_AUDIO_MODE, 2, itv->audio_bilingual_mode, itv->audio_stereo_mode); |
| 157 | break; |
| 158 | } |
| 159 | return 0; |
| 160 | } |
| 161 | |
| 162 | const struct v4l2_ctrl_ops ivtv_hdl_out_ops = { |
| 163 | .s_ctrl = ivtv_s_ctrl, |
| 164 | .g_volatile_ctrl = ivtv_g_volatile_ctrl, |
| 165 | }; |