aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/ivtv/ivtv-controls.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/ivtv/ivtv-controls.c')
-rw-r--r--drivers/media/video/ivtv/ivtv-controls.c225
1 files changed, 112 insertions, 113 deletions
diff --git a/drivers/media/video/ivtv/ivtv-controls.c b/drivers/media/video/ivtv/ivtv-controls.c
index c7e449f6397b..48e103be7183 100644
--- a/drivers/media/video/ivtv/ivtv-controls.c
+++ b/drivers/media/video/ivtv/ivtv-controls.c
@@ -47,12 +47,12 @@ static const u32 *ctrl_classes[] = {
47 NULL 47 NULL
48}; 48};
49 49
50static int ivtv_queryctrl(struct ivtv *itv, struct v4l2_queryctrl *qctrl) 50
51int ivtv_queryctrl(struct file *file, void *fh, struct v4l2_queryctrl *qctrl)
51{ 52{
53 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
52 const char *name; 54 const char *name;
53 55
54 IVTV_DEBUG_IOCTL("VIDIOC_QUERYCTRL(%08x)\n", qctrl->id);
55
56 qctrl->id = v4l2_ctrl_next(ctrl_classes, qctrl->id); 56 qctrl->id = v4l2_ctrl_next(ctrl_classes, qctrl->id);
57 if (qctrl->id == 0) 57 if (qctrl->id == 0)
58 return -EINVAL; 58 return -EINVAL;
@@ -87,21 +87,35 @@ static int ivtv_queryctrl(struct ivtv *itv, struct v4l2_queryctrl *qctrl)
87 return 0; 87 return 0;
88} 88}
89 89
90static int ivtv_querymenu(struct ivtv *itv, struct v4l2_querymenu *qmenu) 90int ivtv_querymenu(struct file *file, void *fh, struct v4l2_querymenu *qmenu)
91{ 91{
92 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
92 struct v4l2_queryctrl qctrl; 93 struct v4l2_queryctrl qctrl;
93 94
94 qctrl.id = qmenu->id; 95 qctrl.id = qmenu->id;
95 ivtv_queryctrl(itv, &qctrl); 96 ivtv_queryctrl(file, fh, &qctrl);
96 return v4l2_ctrl_query_menu(qmenu, &qctrl, cx2341x_ctrl_get_menu(qmenu->id)); 97 return v4l2_ctrl_query_menu(qmenu, &qctrl,
98 cx2341x_ctrl_get_menu(&itv->params, qmenu->id));
97} 99}
98 100
99static int ivtv_s_ctrl(struct ivtv *itv, struct v4l2_control *vctrl) 101static int ivtv_try_ctrl(struct file *file, void *fh,
102 struct v4l2_ext_control *vctrl)
100{ 103{
101 s32 v = vctrl->value; 104 struct v4l2_queryctrl qctrl;
102 105 const char **menu_items = NULL;
103 IVTV_DEBUG_IOCTL("VIDIOC_S_CTRL(%08x, %x)\n", vctrl->id, v); 106 int err;
107
108 qctrl.id = vctrl->id;
109 err = ivtv_queryctrl(file, fh, &qctrl);
110 if (err)
111 return err;
112 if (qctrl.type == V4L2_CTRL_TYPE_MENU)
113 menu_items = v4l2_ctrl_get_menu(qctrl.id);
114 return v4l2_ctrl_check(vctrl, &qctrl, menu_items);
115}
104 116
117static int ivtv_s_ctrl(struct ivtv *itv, struct v4l2_control *vctrl)
118{
105 switch (vctrl->id) { 119 switch (vctrl->id) {
106 /* Standard V4L2 controls */ 120 /* Standard V4L2 controls */
107 case V4L2_CID_BRIGHTNESS: 121 case V4L2_CID_BRIGHTNESS:
@@ -119,7 +133,7 @@ static int ivtv_s_ctrl(struct ivtv *itv, struct v4l2_control *vctrl)
119 return ivtv_i2c_hw(itv, itv->card->hw_audio_ctrl, VIDIOC_S_CTRL, vctrl); 133 return ivtv_i2c_hw(itv, itv->card->hw_audio_ctrl, VIDIOC_S_CTRL, vctrl);
120 134
121 default: 135 default:
122 IVTV_DEBUG_IOCTL("invalid control %x\n", vctrl->id); 136 IVTV_DEBUG_IOCTL("invalid control 0x%x\n", vctrl->id);
123 return -EINVAL; 137 return -EINVAL;
124 } 138 }
125 return 0; 139 return 0;
@@ -127,8 +141,6 @@ static int ivtv_s_ctrl(struct ivtv *itv, struct v4l2_control *vctrl)
127 141
128static int ivtv_g_ctrl(struct ivtv *itv, struct v4l2_control *vctrl) 142static int ivtv_g_ctrl(struct ivtv *itv, struct v4l2_control *vctrl)
129{ 143{
130 IVTV_DEBUG_IOCTL("VIDIOC_G_CTRL(%08x)\n", vctrl->id);
131
132 switch (vctrl->id) { 144 switch (vctrl->id) {
133 /* Standard V4L2 controls */ 145 /* Standard V4L2 controls */
134 case V4L2_CID_BRIGHTNESS: 146 case V4L2_CID_BRIGHTNESS:
@@ -145,7 +157,7 @@ static int ivtv_g_ctrl(struct ivtv *itv, struct v4l2_control *vctrl)
145 case V4L2_CID_AUDIO_LOUDNESS: 157 case V4L2_CID_AUDIO_LOUDNESS:
146 return ivtv_i2c_hw(itv, itv->card->hw_audio_ctrl, VIDIOC_G_CTRL, vctrl); 158 return ivtv_i2c_hw(itv, itv->card->hw_audio_ctrl, VIDIOC_G_CTRL, vctrl);
147 default: 159 default:
148 IVTV_DEBUG_IOCTL("invalid control %x\n", vctrl->id); 160 IVTV_DEBUG_IOCTL("invalid control 0x%x\n", vctrl->id);
149 return -EINVAL; 161 return -EINVAL;
150 } 162 }
151 return 0; 163 return 0;
@@ -191,119 +203,106 @@ static int ivtv_setup_vbi_fmt(struct ivtv *itv, enum v4l2_mpeg_stream_vbi_fmt fm
191 return 0; 203 return 0;
192} 204}
193 205
194int ivtv_control_ioctls(struct ivtv *itv, unsigned int cmd, void *arg) 206int ivtv_g_ext_ctrls(struct file *file, void *fh, struct v4l2_ext_controls *c)
195{ 207{
208 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
196 struct v4l2_control ctrl; 209 struct v4l2_control ctrl;
197 210
198 switch (cmd) { 211 if (c->ctrl_class == V4L2_CTRL_CLASS_USER) {
199 case VIDIOC_QUERYMENU: 212 int i;
200 IVTV_DEBUG_IOCTL("VIDIOC_QUERYMENU\n"); 213 int err = 0;
201 return ivtv_querymenu(itv, arg); 214
202 215 for (i = 0; i < c->count; i++) {
203 case VIDIOC_QUERYCTRL: 216 ctrl.id = c->controls[i].id;
204 return ivtv_queryctrl(itv, arg); 217 ctrl.value = c->controls[i].value;
205 218 err = ivtv_g_ctrl(itv, &ctrl);
206 case VIDIOC_S_CTRL: 219 c->controls[i].value = ctrl.value;
207 return ivtv_s_ctrl(itv, arg); 220 if (err) {
208 221 c->error_idx = i;
209 case VIDIOC_G_CTRL: 222 break;
210 return ivtv_g_ctrl(itv, arg);
211
212 case VIDIOC_S_EXT_CTRLS:
213 {
214 struct v4l2_ext_controls *c = arg;
215
216 if (c->ctrl_class == V4L2_CTRL_CLASS_USER) {
217 int i;
218 int err = 0;
219
220 for (i = 0; i < c->count; i++) {
221 ctrl.id = c->controls[i].id;
222 ctrl.value = c->controls[i].value;
223 err = ivtv_s_ctrl(itv, &ctrl);
224 c->controls[i].value = ctrl.value;
225 if (err) {
226 c->error_idx = i;
227 break;
228 }
229 } 223 }
230 return err;
231 } 224 }
232 IVTV_DEBUG_IOCTL("VIDIOC_S_EXT_CTRLS\n"); 225 return err;
233 if (c->ctrl_class == V4L2_CTRL_CLASS_MPEG) { 226 }
234 static u32 freqs[3] = { 44100, 48000, 32000 }; 227 if (c->ctrl_class == V4L2_CTRL_CLASS_MPEG)
235 struct cx2341x_mpeg_params p = itv->params; 228 return cx2341x_ext_ctrls(&itv->params, 0, c, VIDIOC_G_EXT_CTRLS);
236 int err = cx2341x_ext_ctrls(&p, atomic_read(&itv->capturing), arg, cmd); 229 return -EINVAL;
237 unsigned idx; 230}
238 231
239 if (err) 232int ivtv_s_ext_ctrls(struct file *file, void *fh, struct v4l2_ext_controls *c)
240 return err; 233{
241 234 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
242 if (p.video_encoding != itv->params.video_encoding) { 235 struct v4l2_control ctrl;
243 int is_mpeg1 = p.video_encoding == 236
244 V4L2_MPEG_VIDEO_ENCODING_MPEG_1; 237 if (c->ctrl_class == V4L2_CTRL_CLASS_USER) {
245 struct v4l2_format fmt; 238 int i;
246 239 int err = 0;
247 /* fix videodecoder resolution */ 240
248 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 241 for (i = 0; i < c->count; i++) {
249 fmt.fmt.pix.width = itv->params.width / (is_mpeg1 ? 2 : 1); 242 ctrl.id = c->controls[i].id;
250 fmt.fmt.pix.height = itv->params.height; 243 ctrl.value = c->controls[i].value;
251 itv->video_dec_func(itv, VIDIOC_S_FMT, &fmt); 244 err = ivtv_s_ctrl(itv, &ctrl);
252 } 245 c->controls[i].value = ctrl.value;
253 err = cx2341x_update(itv, ivtv_api_func, &itv->params, &p); 246 if (err) {
254 if (!err && itv->params.stream_vbi_fmt != p.stream_vbi_fmt) { 247 c->error_idx = i;
255 err = ivtv_setup_vbi_fmt(itv, p.stream_vbi_fmt); 248 break;
256 } 249 }
257 itv->params = p;
258 itv->dualwatch_stereo_mode = p.audio_properties & 0x0300;
259 idx = p.audio_properties & 0x03;
260 /* The audio clock of the digitizer must match the codec sample
261 rate otherwise you get some very strange effects. */
262 if (idx < sizeof(freqs))
263 ivtv_call_i2c_clients(itv, VIDIOC_INT_AUDIO_CLOCK_FREQ, &freqs[idx]);
264 return err;
265 } 250 }
266 return -EINVAL; 251 return err;
267 } 252 }
253 if (c->ctrl_class == V4L2_CTRL_CLASS_MPEG) {
254 static u32 freqs[3] = { 44100, 48000, 32000 };
255 struct cx2341x_mpeg_params p = itv->params;
256 int err = cx2341x_ext_ctrls(&p, atomic_read(&itv->capturing), c, VIDIOC_S_EXT_CTRLS);
257 unsigned idx;
268 258
269 case VIDIOC_G_EXT_CTRLS: 259 if (err)
270 {
271 struct v4l2_ext_controls *c = arg;
272
273 if (c->ctrl_class == V4L2_CTRL_CLASS_USER) {
274 int i;
275 int err = 0;
276
277 for (i = 0; i < c->count; i++) {
278 ctrl.id = c->controls[i].id;
279 ctrl.value = c->controls[i].value;
280 err = ivtv_g_ctrl(itv, &ctrl);
281 c->controls[i].value = ctrl.value;
282 if (err) {
283 c->error_idx = i;
284 break;
285 }
286 }
287 return err; 260 return err;
261
262 if (p.video_encoding != itv->params.video_encoding) {
263 int is_mpeg1 = p.video_encoding ==
264 V4L2_MPEG_VIDEO_ENCODING_MPEG_1;
265 struct v4l2_format fmt;
266
267 /* fix videodecoder resolution */
268 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
269 fmt.fmt.pix.width = itv->params.width / (is_mpeg1 ? 2 : 1);
270 fmt.fmt.pix.height = itv->params.height;
271 itv->video_dec_func(itv, VIDIOC_S_FMT, &fmt);
288 } 272 }
289 IVTV_DEBUG_IOCTL("VIDIOC_G_EXT_CTRLS\n"); 273 err = cx2341x_update(itv, ivtv_api_func, &itv->params, &p);
290 if (c->ctrl_class == V4L2_CTRL_CLASS_MPEG) 274 if (!err && itv->params.stream_vbi_fmt != p.stream_vbi_fmt)
291 return cx2341x_ext_ctrls(&itv->params, 0, arg, cmd); 275 err = ivtv_setup_vbi_fmt(itv, p.stream_vbi_fmt);
292 return -EINVAL; 276 itv->params = p;
277 itv->dualwatch_stereo_mode = p.audio_properties & 0x0300;
278 idx = p.audio_properties & 0x03;
279 /* The audio clock of the digitizer must match the codec sample
280 rate otherwise you get some very strange effects. */
281 if (idx < sizeof(freqs))
282 ivtv_call_i2c_clients(itv, VIDIOC_INT_AUDIO_CLOCK_FREQ, &freqs[idx]);
283 return err;
293 } 284 }
285 return -EINVAL;
286}
294 287
295 case VIDIOC_TRY_EXT_CTRLS: 288int ivtv_try_ext_ctrls(struct file *file, void *fh, struct v4l2_ext_controls *c)
296 { 289{
297 struct v4l2_ext_controls *c = arg; 290 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
298 291
299 IVTV_DEBUG_IOCTL("VIDIOC_TRY_EXT_CTRLS\n"); 292 if (c->ctrl_class == V4L2_CTRL_CLASS_USER) {
300 if (c->ctrl_class == V4L2_CTRL_CLASS_MPEG) 293 int i;
301 return cx2341x_ext_ctrls(&itv->params, atomic_read(&itv->capturing), arg, cmd); 294 int err = 0;
302 return -EINVAL;
303 }
304 295
305 default: 296 for (i = 0; i < c->count; i++) {
306 return -EINVAL; 297 err = ivtv_try_ctrl(file, fh, &c->controls[i]);
298 if (err) {
299 c->error_idx = i;
300 break;
301 }
302 }
303 return err;
307 } 304 }
308 return 0; 305 if (c->ctrl_class == V4L2_CTRL_CLASS_MPEG)
306 return cx2341x_ext_ctrls(&itv->params, atomic_read(&itv->capturing), c, VIDIOC_TRY_EXT_CTRLS);
307 return -EINVAL;
309} 308}