Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1 | /* |
| 2 | * cx18 ioctl control functions |
| 3 | * |
| 4 | * Derived from ivtv-controls.c |
| 5 | * |
| 6 | * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl> |
| 7 | * |
| 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. |
| 12 | * |
| 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. |
| 17 | * |
| 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 |
| 21 | * 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include "cx18-driver.h" |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 25 | #include "cx18-cards.h" |
| 26 | #include "cx18-ioctl.h" |
| 27 | #include "cx18-audio.h" |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 28 | #include "cx18-mailbox.h" |
| 29 | #include "cx18-controls.h" |
| 30 | |
Hans Verkuil | 2ba5889 | 2009-02-13 10:57:48 -0300 | [diff] [blame] | 31 | /* Must be sorted from low to high control ID! */ |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 32 | static const u32 user_ctrls[] = { |
| 33 | V4L2_CID_USER_CLASS, |
| 34 | V4L2_CID_BRIGHTNESS, |
| 35 | V4L2_CID_CONTRAST, |
| 36 | V4L2_CID_SATURATION, |
| 37 | V4L2_CID_HUE, |
| 38 | V4L2_CID_AUDIO_VOLUME, |
| 39 | V4L2_CID_AUDIO_BALANCE, |
| 40 | V4L2_CID_AUDIO_BASS, |
| 41 | V4L2_CID_AUDIO_TREBLE, |
| 42 | V4L2_CID_AUDIO_MUTE, |
| 43 | V4L2_CID_AUDIO_LOUDNESS, |
| 44 | 0 |
| 45 | }; |
| 46 | |
| 47 | static const u32 *ctrl_classes[] = { |
| 48 | user_ctrls, |
| 49 | cx2341x_mpeg_ctrls, |
| 50 | NULL |
| 51 | }; |
| 52 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 53 | int cx18_queryctrl(struct file *file, void *fh, struct v4l2_queryctrl *qctrl) |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 54 | { |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 55 | struct cx18 *cx = ((struct cx18_open_id *)fh)->cx; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 56 | const char *name; |
| 57 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 58 | qctrl->id = v4l2_ctrl_next(ctrl_classes, qctrl->id); |
| 59 | if (qctrl->id == 0) |
| 60 | return -EINVAL; |
| 61 | |
| 62 | switch (qctrl->id) { |
| 63 | /* Standard V4L2 controls */ |
| 64 | case V4L2_CID_BRIGHTNESS: |
| 65 | case V4L2_CID_HUE: |
| 66 | case V4L2_CID_SATURATION: |
| 67 | case V4L2_CID_CONTRAST: |
Andy Walls | fa3e703 | 2009-02-16 02:23:25 -0300 | [diff] [blame] | 68 | if (v4l2_subdev_call(cx->sd_av, core, queryctrl, qctrl)) |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 69 | qctrl->flags |= V4L2_CTRL_FLAG_DISABLED; |
| 70 | return 0; |
| 71 | |
| 72 | case V4L2_CID_AUDIO_VOLUME: |
| 73 | case V4L2_CID_AUDIO_MUTE: |
| 74 | case V4L2_CID_AUDIO_BALANCE: |
| 75 | case V4L2_CID_AUDIO_BASS: |
| 76 | case V4L2_CID_AUDIO_TREBLE: |
| 77 | case V4L2_CID_AUDIO_LOUDNESS: |
Andy Walls | ff2a200 | 2009-02-20 23:52:13 -0300 | [diff] [blame] | 78 | if (v4l2_subdev_call(cx->sd_av, core, queryctrl, qctrl)) |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 79 | qctrl->flags |= V4L2_CTRL_FLAG_DISABLED; |
| 80 | return 0; |
| 81 | |
| 82 | default: |
| 83 | if (cx2341x_ctrl_query(&cx->params, qctrl)) |
| 84 | qctrl->flags |= V4L2_CTRL_FLAG_DISABLED; |
| 85 | return 0; |
| 86 | } |
| 87 | strncpy(qctrl->name, name, sizeof(qctrl->name) - 1); |
| 88 | qctrl->name[sizeof(qctrl->name) - 1] = 0; |
| 89 | return 0; |
| 90 | } |
| 91 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 92 | int cx18_querymenu(struct file *file, void *fh, struct v4l2_querymenu *qmenu) |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 93 | { |
Hans Verkuil | e0e31cd | 2008-06-22 12:03:28 -0300 | [diff] [blame] | 94 | struct cx18 *cx = ((struct cx18_open_id *)fh)->cx; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 95 | struct v4l2_queryctrl qctrl; |
| 96 | |
| 97 | qctrl.id = qmenu->id; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 98 | cx18_queryctrl(file, fh, &qctrl); |
Hans Verkuil | e0e31cd | 2008-06-22 12:03:28 -0300 | [diff] [blame] | 99 | return v4l2_ctrl_query_menu(qmenu, &qctrl, |
| 100 | cx2341x_ctrl_get_menu(&cx->params, qmenu->id)); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 101 | } |
| 102 | |
Hans Verkuil | adb65bc | 2008-06-25 06:32:44 -0300 | [diff] [blame] | 103 | static int cx18_try_ctrl(struct file *file, void *fh, |
| 104 | struct v4l2_ext_control *vctrl) |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 105 | { |
Hans Verkuil | adb65bc | 2008-06-25 06:32:44 -0300 | [diff] [blame] | 106 | struct v4l2_queryctrl qctrl; |
| 107 | const char **menu_items = NULL; |
| 108 | int err; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 109 | |
Hans Verkuil | adb65bc | 2008-06-25 06:32:44 -0300 | [diff] [blame] | 110 | qctrl.id = vctrl->id; |
| 111 | err = cx18_queryctrl(file, fh, &qctrl); |
| 112 | if (err) |
| 113 | return err; |
| 114 | if (qctrl.type == V4L2_CTRL_TYPE_MENU) |
| 115 | menu_items = v4l2_ctrl_get_menu(qctrl.id); |
| 116 | return v4l2_ctrl_check(vctrl, &qctrl, menu_items); |
| 117 | } |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 118 | |
Hans Verkuil | adb65bc | 2008-06-25 06:32:44 -0300 | [diff] [blame] | 119 | static int cx18_s_ctrl(struct cx18 *cx, struct v4l2_control *vctrl) |
| 120 | { |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 121 | switch (vctrl->id) { |
| 122 | /* Standard V4L2 controls */ |
| 123 | case V4L2_CID_BRIGHTNESS: |
| 124 | case V4L2_CID_HUE: |
| 125 | case V4L2_CID_SATURATION: |
| 126 | case V4L2_CID_CONTRAST: |
Andy Walls | fa3e703 | 2009-02-16 02:23:25 -0300 | [diff] [blame] | 127 | return v4l2_subdev_call(cx->sd_av, core, s_ctrl, vctrl); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 128 | |
| 129 | case V4L2_CID_AUDIO_VOLUME: |
| 130 | case V4L2_CID_AUDIO_MUTE: |
| 131 | case V4L2_CID_AUDIO_BALANCE: |
| 132 | case V4L2_CID_AUDIO_BASS: |
| 133 | case V4L2_CID_AUDIO_TREBLE: |
| 134 | case V4L2_CID_AUDIO_LOUDNESS: |
Andy Walls | ff2a200 | 2009-02-20 23:52:13 -0300 | [diff] [blame] | 135 | return v4l2_subdev_call(cx->sd_av, core, s_ctrl, vctrl); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 136 | |
| 137 | default: |
Hans Verkuil | 37f89f9 | 2008-06-22 11:57:31 -0300 | [diff] [blame] | 138 | CX18_DEBUG_IOCTL("invalid control 0x%x\n", vctrl->id); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 139 | return -EINVAL; |
| 140 | } |
| 141 | return 0; |
| 142 | } |
| 143 | |
Hans Verkuil | adb65bc | 2008-06-25 06:32:44 -0300 | [diff] [blame] | 144 | static int cx18_g_ctrl(struct cx18 *cx, struct v4l2_control *vctrl) |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 145 | { |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 146 | switch (vctrl->id) { |
| 147 | /* Standard V4L2 controls */ |
| 148 | case V4L2_CID_BRIGHTNESS: |
| 149 | case V4L2_CID_HUE: |
| 150 | case V4L2_CID_SATURATION: |
| 151 | case V4L2_CID_CONTRAST: |
Andy Walls | fa3e703 | 2009-02-16 02:23:25 -0300 | [diff] [blame] | 152 | return v4l2_subdev_call(cx->sd_av, core, g_ctrl, vctrl); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 153 | |
| 154 | case V4L2_CID_AUDIO_VOLUME: |
| 155 | case V4L2_CID_AUDIO_MUTE: |
| 156 | case V4L2_CID_AUDIO_BALANCE: |
| 157 | case V4L2_CID_AUDIO_BASS: |
| 158 | case V4L2_CID_AUDIO_TREBLE: |
| 159 | case V4L2_CID_AUDIO_LOUDNESS: |
Andy Walls | ff2a200 | 2009-02-20 23:52:13 -0300 | [diff] [blame] | 160 | return v4l2_subdev_call(cx->sd_av, core, g_ctrl, vctrl); |
| 161 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 162 | default: |
Hans Verkuil | 37f89f9 | 2008-06-22 11:57:31 -0300 | [diff] [blame] | 163 | CX18_DEBUG_IOCTL("invalid control 0x%x\n", vctrl->id); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 164 | return -EINVAL; |
| 165 | } |
| 166 | return 0; |
| 167 | } |
| 168 | |
Andy Walls | 49a5375 | 2009-03-01 23:10:07 -0300 | [diff] [blame] | 169 | static int cx18_setup_vbi_fmt(struct cx18 *cx, |
| 170 | enum v4l2_mpeg_stream_vbi_fmt fmt, |
| 171 | enum v4l2_mpeg_stream_type type) |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 172 | { |
| 173 | if (!(cx->v4l2_cap & V4L2_CAP_SLICED_VBI_CAPTURE)) |
| 174 | return -EINVAL; |
Hans Verkuil | 31554ae | 2008-05-25 11:21:27 -0300 | [diff] [blame] | 175 | if (atomic_read(&cx->ana_capturing) > 0) |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 176 | return -EBUSY; |
| 177 | |
Andy Walls | 49a5375 | 2009-03-01 23:10:07 -0300 | [diff] [blame] | 178 | if (fmt != V4L2_MPEG_STREAM_VBI_FMT_IVTV || |
Andy Walls | 0c62925 | 2009-04-26 16:34:36 -0300 | [diff] [blame^] | 179 | !(type == V4L2_MPEG_STREAM_TYPE_MPEG2_PS || |
| 180 | type == V4L2_MPEG_STREAM_TYPE_MPEG2_DVD || |
| 181 | type == V4L2_MPEG_STREAM_TYPE_MPEG2_SVCD)) { |
| 182 | /* Only IVTV fmt VBI insertion & only MPEG-2 PS type streams */ |
Andy Walls | 49a5375 | 2009-03-01 23:10:07 -0300 | [diff] [blame] | 183 | cx->vbi.insert_mpeg = V4L2_MPEG_STREAM_VBI_FMT_NONE; |
| 184 | CX18_DEBUG_INFO("disabled insertion of sliced VBI data into " |
| 185 | "the MPEG stream\n"); |
| 186 | return 0; |
| 187 | } |
| 188 | |
| 189 | /* Allocate sliced VBI buffers if needed. */ |
| 190 | if (cx->vbi.sliced_mpeg_data[0] == NULL) { |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 191 | int i; |
| 192 | |
| 193 | for (i = 0; i < CX18_VBI_FRAMES; i++) { |
Andy Walls | 302df97 | 2009-01-31 00:33:02 -0300 | [diff] [blame] | 194 | cx->vbi.sliced_mpeg_data[i] = |
| 195 | kmalloc(CX18_SLICED_MPEG_DATA_BUFSZ, GFP_KERNEL); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 196 | if (cx->vbi.sliced_mpeg_data[i] == NULL) { |
| 197 | while (--i >= 0) { |
| 198 | kfree(cx->vbi.sliced_mpeg_data[i]); |
| 199 | cx->vbi.sliced_mpeg_data[i] = NULL; |
| 200 | } |
Andy Walls | 49a5375 | 2009-03-01 23:10:07 -0300 | [diff] [blame] | 201 | cx->vbi.insert_mpeg = |
| 202 | V4L2_MPEG_STREAM_VBI_FMT_NONE; |
| 203 | CX18_WARN("Unable to allocate buffers for " |
| 204 | "sliced VBI data insertion\n"); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 205 | return -ENOMEM; |
| 206 | } |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | cx->vbi.insert_mpeg = fmt; |
Andy Walls | 49a5375 | 2009-03-01 23:10:07 -0300 | [diff] [blame] | 211 | CX18_DEBUG_INFO("enabled insertion of sliced VBI data into the MPEG PS," |
| 212 | "when sliced VBI is enabled\n"); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 213 | |
Andy Walls | 49a5375 | 2009-03-01 23:10:07 -0300 | [diff] [blame] | 214 | /* |
| 215 | * If our current settings have no lines set for capture, store a valid, |
| 216 | * default set of service lines to capture, in our current settings. |
| 217 | */ |
Mauro Carvalho Chehab | aed6abd | 2008-04-29 21:38:51 -0300 | [diff] [blame] | 218 | if (cx18_get_service_set(cx->vbi.sliced_in) == 0) { |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 219 | if (cx->is_60hz) |
Andy Walls | 49a5375 | 2009-03-01 23:10:07 -0300 | [diff] [blame] | 220 | cx->vbi.sliced_in->service_set = |
| 221 | V4L2_SLICED_CAPTION_525; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 222 | else |
| 223 | cx->vbi.sliced_in->service_set = V4L2_SLICED_WSS_625; |
Mauro Carvalho Chehab | aed6abd | 2008-04-29 21:38:51 -0300 | [diff] [blame] | 224 | cx18_expand_service_set(cx->vbi.sliced_in, cx->is_50hz); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 225 | } |
| 226 | return 0; |
| 227 | } |
| 228 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 229 | int cx18_g_ext_ctrls(struct file *file, void *fh, struct v4l2_ext_controls *c) |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 230 | { |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 231 | struct cx18 *cx = ((struct cx18_open_id *)fh)->cx; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 232 | struct v4l2_control ctrl; |
| 233 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 234 | if (c->ctrl_class == V4L2_CTRL_CLASS_USER) { |
| 235 | int i; |
| 236 | int err = 0; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 237 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 238 | for (i = 0; i < c->count; i++) { |
| 239 | ctrl.id = c->controls[i].id; |
| 240 | ctrl.value = c->controls[i].value; |
Hans Verkuil | adb65bc | 2008-06-25 06:32:44 -0300 | [diff] [blame] | 241 | err = cx18_g_ctrl(cx, &ctrl); |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 242 | c->controls[i].value = ctrl.value; |
| 243 | if (err) { |
| 244 | c->error_idx = i; |
| 245 | break; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 246 | } |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 247 | } |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 248 | return err; |
| 249 | } |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 250 | if (c->ctrl_class == V4L2_CTRL_CLASS_MPEG) |
| 251 | return cx2341x_ext_ctrls(&cx->params, 0, c, VIDIOC_G_EXT_CTRLS); |
| 252 | return -EINVAL; |
| 253 | } |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 254 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 255 | int cx18_s_ext_ctrls(struct file *file, void *fh, struct v4l2_ext_controls *c) |
| 256 | { |
| 257 | struct cx18_open_id *id = fh; |
| 258 | struct cx18 *cx = id->cx; |
| 259 | int ret; |
| 260 | struct v4l2_control ctrl; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 261 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 262 | ret = v4l2_prio_check(&cx->prio, &id->prio); |
| 263 | if (ret) |
| 264 | return ret; |
| 265 | |
| 266 | if (c->ctrl_class == V4L2_CTRL_CLASS_USER) { |
| 267 | int i; |
| 268 | int err = 0; |
| 269 | |
| 270 | for (i = 0; i < c->count; i++) { |
| 271 | ctrl.id = c->controls[i].id; |
| 272 | ctrl.value = c->controls[i].value; |
Hans Verkuil | adb65bc | 2008-06-25 06:32:44 -0300 | [diff] [blame] | 273 | err = cx18_s_ctrl(cx, &ctrl); |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 274 | c->controls[i].value = ctrl.value; |
| 275 | if (err) { |
| 276 | c->error_idx = i; |
| 277 | break; |
| 278 | } |
| 279 | } |
| 280 | return err; |
| 281 | } |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 282 | if (c->ctrl_class == V4L2_CTRL_CLASS_MPEG) { |
Andy Walls | ff2a200 | 2009-02-20 23:52:13 -0300 | [diff] [blame] | 283 | static u32 freqs[3] = { 44100, 48000, 32000 }; |
Andy Walls | 50b86ba | 2008-11-23 19:16:44 -0300 | [diff] [blame] | 284 | struct cx18_api_func_private priv; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 285 | struct cx2341x_mpeg_params p = cx->params; |
| 286 | int err = cx2341x_ext_ctrls(&p, atomic_read(&cx->ana_capturing), |
| 287 | c, VIDIOC_S_EXT_CTRLS); |
Andy Walls | ff2a200 | 2009-02-20 23:52:13 -0300 | [diff] [blame] | 288 | unsigned int idx; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 289 | |
| 290 | if (err) |
| 291 | return err; |
| 292 | |
| 293 | if (p.video_encoding != cx->params.video_encoding) { |
| 294 | int is_mpeg1 = p.video_encoding == |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 295 | V4L2_MPEG_VIDEO_ENCODING_MPEG_1; |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 296 | struct v4l2_format fmt; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 297 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 298 | /* fix videodecoder resolution */ |
| 299 | fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 300 | fmt.fmt.pix.width = cx->params.width |
| 301 | / (is_mpeg1 ? 2 : 1); |
| 302 | fmt.fmt.pix.height = cx->params.height; |
Andy Walls | fa3e703 | 2009-02-16 02:23:25 -0300 | [diff] [blame] | 303 | v4l2_subdev_call(cx->sd_av, video, s_fmt, &fmt); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 304 | } |
Andy Walls | 50b86ba | 2008-11-23 19:16:44 -0300 | [diff] [blame] | 305 | priv.cx = cx; |
| 306 | priv.s = &cx->streams[id->type]; |
| 307 | err = cx2341x_update(&priv, cx18_api_func, &cx->params, &p); |
Andy Walls | 49a5375 | 2009-03-01 23:10:07 -0300 | [diff] [blame] | 308 | if (!err && |
| 309 | (cx->params.stream_vbi_fmt != p.stream_vbi_fmt || |
| 310 | cx->params.stream_type != p.stream_type)) |
| 311 | err = cx18_setup_vbi_fmt(cx, p.stream_vbi_fmt, |
| 312 | p.stream_type); |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 313 | cx->params = p; |
| 314 | cx->dualwatch_stereo_mode = p.audio_properties & 0x0300; |
Andy Walls | ff2a200 | 2009-02-20 23:52:13 -0300 | [diff] [blame] | 315 | idx = p.audio_properties & 0x03; |
| 316 | /* The audio clock of the digitizer must match the codec sample |
| 317 | rate otherwise you get some very strange effects. */ |
| 318 | if (idx < sizeof(freqs)) |
| 319 | cx18_call_all(cx, audio, s_clock_freq, freqs[idx]); |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 320 | return err; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 321 | } |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 322 | return -EINVAL; |
| 323 | } |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 324 | |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 325 | int cx18_try_ext_ctrls(struct file *file, void *fh, struct v4l2_ext_controls *c) |
| 326 | { |
| 327 | struct cx18 *cx = ((struct cx18_open_id *)fh)->cx; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 328 | |
Hans Verkuil | adb65bc | 2008-06-25 06:32:44 -0300 | [diff] [blame] | 329 | if (c->ctrl_class == V4L2_CTRL_CLASS_USER) { |
| 330 | int i; |
| 331 | int err = 0; |
| 332 | |
| 333 | for (i = 0; i < c->count; i++) { |
| 334 | err = cx18_try_ctrl(file, fh, &c->controls[i]); |
| 335 | if (err) { |
| 336 | c->error_idx = i; |
| 337 | break; |
| 338 | } |
| 339 | } |
| 340 | return err; |
| 341 | } |
Andy Walls | 3b6fe58 | 2008-06-21 08:36:31 -0300 | [diff] [blame] | 342 | if (c->ctrl_class == V4L2_CTRL_CLASS_MPEG) |
| 343 | return cx2341x_ext_ctrls(&cx->params, |
| 344 | atomic_read(&cx->ana_capturing), |
| 345 | c, VIDIOC_TRY_EXT_CTRLS); |
| 346 | return -EINVAL; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 347 | } |