aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media
diff options
context:
space:
mode:
authorHans Verkuil <hverkuil@xs4all.nl>2010-06-27 05:07:26 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2010-08-08 22:43:06 -0400
commitf7b80e6919df812b4bed99a927325312a904111b (patch)
tree6828bb6bfeea81a8345b148dbca8b2fdcadec7eb /drivers/media
parent2fd781448acd6cbc3ca9d2f48b0e16f67a77bf51 (diff)
V4L/DVB: ivtv: convert to the new control framework
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media')
-rw-r--r--drivers/media/video/ivtv/ivtv-controls.c276
-rw-r--r--drivers/media/video/ivtv/ivtv-controls.h6
-rw-r--r--drivers/media/video/ivtv/ivtv-driver.c18
-rw-r--r--drivers/media/video/ivtv/ivtv-driver.h5
-rw-r--r--drivers/media/video/ivtv/ivtv-fileops.c23
-rw-r--r--drivers/media/video/ivtv/ivtv-firmware.c6
-rw-r--r--drivers/media/video/ivtv/ivtv-ioctl.c31
-rw-r--r--drivers/media/video/ivtv/ivtv-streams.c24
8 files changed, 88 insertions, 301 deletions
diff --git a/drivers/media/video/ivtv/ivtv-controls.c b/drivers/media/video/ivtv/ivtv-controls.c
index b588e30cbcf0..b31ee1bceef8 100644
--- a/drivers/media/video/ivtv/ivtv-controls.c
+++ b/drivers/media/video/ivtv/ivtv-controls.c
@@ -17,163 +17,14 @@
17 along with this program; if not, write to the Free Software 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 18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */ 19 */
20#include <linux/kernel.h>
21#include <linux/slab.h>
22 20
23#include "ivtv-driver.h" 21#include "ivtv-driver.h"
24#include "ivtv-cards.h"
25#include "ivtv-ioctl.h" 22#include "ivtv-ioctl.h"
26#include "ivtv-routing.h"
27#include "ivtv-i2c.h"
28#include "ivtv-mailbox.h"
29#include "ivtv-controls.h" 23#include "ivtv-controls.h"
30 24
31/* Must be sorted from low to high control ID! */ 25static int ivtv_s_stream_vbi_fmt(struct cx2341x_handler *cxhdl, u32 fmt)
32static 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
47static const u32 *ctrl_classes[] = {
48 user_ctrls,
49 cx2341x_mpeg_ctrls,
50 NULL
51};
52
53
54int ivtv_queryctrl(struct file *file, void *fh, struct v4l2_queryctrl *qctrl)
55{
56 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
57 const char *name;
58
59 qctrl->id = v4l2_ctrl_next(ctrl_classes, qctrl->id);
60 if (qctrl->id == 0)
61 return -EINVAL;
62
63 switch (qctrl->id) {
64 /* Standard V4L2 controls */
65 case V4L2_CID_USER_CLASS:
66 return v4l2_ctrl_query_fill(qctrl, 0, 0, 0, 0);
67 case V4L2_CID_BRIGHTNESS:
68 case V4L2_CID_HUE:
69 case V4L2_CID_SATURATION:
70 case V4L2_CID_CONTRAST:
71 if (v4l2_subdev_call(itv->sd_video, core, queryctrl, qctrl))
72 qctrl->flags |= V4L2_CTRL_FLAG_DISABLED;
73 return 0;
74
75 case V4L2_CID_AUDIO_VOLUME:
76 case V4L2_CID_AUDIO_MUTE:
77 case V4L2_CID_AUDIO_BALANCE:
78 case V4L2_CID_AUDIO_BASS:
79 case V4L2_CID_AUDIO_TREBLE:
80 case V4L2_CID_AUDIO_LOUDNESS:
81 if (v4l2_subdev_call(itv->sd_audio, core, queryctrl, qctrl))
82 qctrl->flags |= V4L2_CTRL_FLAG_DISABLED;
83 return 0;
84
85 default:
86 if (cx2341x_ctrl_query(&itv->params, qctrl))
87 qctrl->flags |= V4L2_CTRL_FLAG_DISABLED;
88 return 0;
89 }
90 strncpy(qctrl->name, name, sizeof(qctrl->name) - 1);
91 qctrl->name[sizeof(qctrl->name) - 1] = 0;
92 return 0;
93}
94
95int ivtv_querymenu(struct file *file, void *fh, struct v4l2_querymenu *qmenu)
96{
97 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
98 struct v4l2_queryctrl qctrl;
99
100 qctrl.id = qmenu->id;
101 ivtv_queryctrl(file, fh, &qctrl);
102 return v4l2_ctrl_query_menu(qmenu, &qctrl,
103 cx2341x_ctrl_get_menu(&itv->params, qmenu->id));
104}
105
106static int ivtv_try_ctrl(struct file *file, void *fh,
107 struct v4l2_ext_control *vctrl)
108{
109 struct v4l2_queryctrl qctrl;
110 const char **menu_items = NULL;
111 int err;
112
113 qctrl.id = vctrl->id;
114 err = ivtv_queryctrl(file, fh, &qctrl);
115 if (err)
116 return err;
117 if (qctrl.type == V4L2_CTRL_TYPE_MENU)
118 menu_items = v4l2_ctrl_get_menu(qctrl.id);
119 return v4l2_ctrl_check(vctrl, &qctrl, menu_items);
120}
121
122static int ivtv_s_ctrl(struct ivtv *itv, struct v4l2_control *vctrl)
123{
124 switch (vctrl->id) {
125 /* Standard V4L2 controls */
126 case V4L2_CID_BRIGHTNESS:
127 case V4L2_CID_HUE:
128 case V4L2_CID_SATURATION:
129 case V4L2_CID_CONTRAST:
130 return v4l2_subdev_call(itv->sd_video, core, s_ctrl, vctrl);
131
132 case V4L2_CID_AUDIO_VOLUME:
133 case V4L2_CID_AUDIO_MUTE:
134 case V4L2_CID_AUDIO_BALANCE:
135 case V4L2_CID_AUDIO_BASS:
136 case V4L2_CID_AUDIO_TREBLE:
137 case V4L2_CID_AUDIO_LOUDNESS:
138 return v4l2_subdev_call(itv->sd_audio, core, s_ctrl, vctrl);
139
140 default:
141 IVTV_DEBUG_IOCTL("invalid control 0x%x\n", vctrl->id);
142 return -EINVAL;
143 }
144 return 0;
145}
146
147static int ivtv_g_ctrl(struct ivtv *itv, struct v4l2_control *vctrl)
148{ 26{
149 switch (vctrl->id) { 27 struct ivtv *itv = container_of(cxhdl, struct ivtv, cxhdl);
150 /* Standard V4L2 controls */
151 case V4L2_CID_BRIGHTNESS:
152 case V4L2_CID_HUE:
153 case V4L2_CID_SATURATION:
154 case V4L2_CID_CONTRAST:
155 return v4l2_subdev_call(itv->sd_video, core, g_ctrl, vctrl);
156
157 case V4L2_CID_AUDIO_VOLUME:
158 case V4L2_CID_AUDIO_MUTE:
159 case V4L2_CID_AUDIO_BALANCE:
160 case V4L2_CID_AUDIO_BASS:
161 case V4L2_CID_AUDIO_TREBLE:
162 case V4L2_CID_AUDIO_LOUDNESS:
163 return v4l2_subdev_call(itv->sd_audio, core, g_ctrl, vctrl);
164 default:
165 IVTV_DEBUG_IOCTL("invalid control 0x%x\n", vctrl->id);
166 return -EINVAL;
167 }
168 return 0;
169}
170
171static int ivtv_setup_vbi_fmt(struct ivtv *itv, enum v4l2_mpeg_stream_vbi_fmt fmt)
172{
173 if (!(itv->v4l2_cap & V4L2_CAP_SLICED_VBI_CAPTURE))
174 return -EINVAL;
175 if (atomic_read(&itv->capturing) > 0)
176 return -EBUSY;
177 28
178 /* First try to allocate sliced VBI buffers if needed. */ 29 /* First try to allocate sliced VBI buffers if needed. */
179 if (fmt && itv->vbi.sliced_mpeg_data[0] == NULL) { 30 if (fmt && itv->vbi.sliced_mpeg_data[0] == NULL) {
@@ -208,106 +59,43 @@ static int ivtv_setup_vbi_fmt(struct ivtv *itv, enum v4l2_mpeg_stream_vbi_fmt fm
208 return 0; 59 return 0;
209} 60}
210 61
211int ivtv_g_ext_ctrls(struct file *file, void *fh, struct v4l2_ext_controls *c) 62static int ivtv_s_video_encoding(struct cx2341x_handler *cxhdl, u32 val)
212{ 63{
213 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; 64 struct ivtv *itv = container_of(cxhdl, struct ivtv, cxhdl);
214 struct v4l2_control ctrl; 65 int is_mpeg1 = val == V4L2_MPEG_VIDEO_ENCODING_MPEG_1;
215 66 struct v4l2_mbus_framefmt fmt;
216 if (c->ctrl_class == V4L2_CTRL_CLASS_USER) { 67
217 int i; 68 /* fix videodecoder resolution */
218 int err = 0; 69 fmt.width = cxhdl->width / (is_mpeg1 ? 2 : 1);
219 70 fmt.height = cxhdl->height;
220 for (i = 0; i < c->count; i++) { 71 fmt.code = V4L2_MBUS_FMT_FIXED;
221 ctrl.id = c->controls[i].id; 72 v4l2_subdev_call(itv->sd_video, video, s_mbus_fmt, &fmt);
222 ctrl.value = c->controls[i].value; 73 return 0;
223 err = ivtv_g_ctrl(itv, &ctrl);
224 c->controls[i].value = ctrl.value;
225 if (err) {
226 c->error_idx = i;
227 break;
228 }
229 }
230 return err;
231 }
232 if (c->ctrl_class == V4L2_CTRL_CLASS_MPEG)
233 return cx2341x_ext_ctrls(&itv->params, 0, c, VIDIOC_G_EXT_CTRLS);
234 return -EINVAL;
235} 74}
236 75
237int ivtv_s_ext_ctrls(struct file *file, void *fh, struct v4l2_ext_controls *c) 76static int ivtv_s_audio_sampling_freq(struct cx2341x_handler *cxhdl, u32 idx)
238{ 77{
239 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; 78 static const u32 freqs[3] = { 44100, 48000, 32000 };
240 struct v4l2_control ctrl; 79 struct ivtv *itv = container_of(cxhdl, struct ivtv, cxhdl);
241
242 if (c->ctrl_class == V4L2_CTRL_CLASS_USER) {
243 int i;
244 int err = 0;
245
246 for (i = 0; i < c->count; i++) {
247 ctrl.id = c->controls[i].id;
248 ctrl.value = c->controls[i].value;
249 err = ivtv_s_ctrl(itv, &ctrl);
250 c->controls[i].value = ctrl.value;
251 if (err) {
252 c->error_idx = i;
253 break;
254 }
255 }
256 return err;
257 }
258 if (c->ctrl_class == V4L2_CTRL_CLASS_MPEG) {
259 static u32 freqs[3] = { 44100, 48000, 32000 };
260 struct cx2341x_mpeg_params p = itv->params;
261 int err = cx2341x_ext_ctrls(&p, atomic_read(&itv->capturing), c, VIDIOC_S_EXT_CTRLS);
262 unsigned idx;
263
264 if (err)
265 return err;
266 80
267 if (p.video_encoding != itv->params.video_encoding) { 81 /* The audio clock of the digitizer must match the codec sample
268 int is_mpeg1 = p.video_encoding == 82 rate otherwise you get some very strange effects. */
269 V4L2_MPEG_VIDEO_ENCODING_MPEG_1; 83 if (idx < ARRAY_SIZE(freqs))
270 struct v4l2_mbus_framefmt fmt; 84 ivtv_call_all(itv, audio, s_clock_freq, freqs[idx]);
271 85 return 0;
272 /* fix videodecoder resolution */
273 fmt.width = itv->params.width / (is_mpeg1 ? 2 : 1);
274 fmt.height = itv->params.height;
275 fmt.code = V4L2_MBUS_FMT_FIXED;
276 v4l2_subdev_call(itv->sd_video, video, s_mbus_fmt, &fmt);
277 }
278 err = cx2341x_update(itv, ivtv_api_func, &itv->params, &p);
279 if (!err && itv->params.stream_vbi_fmt != p.stream_vbi_fmt)
280 err = ivtv_setup_vbi_fmt(itv, p.stream_vbi_fmt);
281 itv->params = p;
282 itv->dualwatch_stereo_mode = p.audio_properties & 0x0300;
283 idx = p.audio_properties & 0x03;
284 /* The audio clock of the digitizer must match the codec sample
285 rate otherwise you get some very strange effects. */
286 if (idx < ARRAY_SIZE(freqs))
287 ivtv_call_all(itv, audio, s_clock_freq, freqs[idx]);
288 return err;
289 }
290 return -EINVAL;
291} 86}
292 87
293int ivtv_try_ext_ctrls(struct file *file, void *fh, struct v4l2_ext_controls *c) 88static int ivtv_s_audio_mode(struct cx2341x_handler *cxhdl, u32 val)
294{ 89{
295 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; 90 struct ivtv *itv = container_of(cxhdl, struct ivtv, cxhdl);
296 91
297 if (c->ctrl_class == V4L2_CTRL_CLASS_USER) { 92 itv->dualwatch_stereo_mode = val;
298 int i; 93 return 0;
299 int err = 0;
300
301 for (i = 0; i < c->count; i++) {
302 err = ivtv_try_ctrl(file, fh, &c->controls[i]);
303 if (err) {
304 c->error_idx = i;
305 break;
306 }
307 }
308 return err;
309 }
310 if (c->ctrl_class == V4L2_CTRL_CLASS_MPEG)
311 return cx2341x_ext_ctrls(&itv->params, atomic_read(&itv->capturing), c, VIDIOC_TRY_EXT_CTRLS);
312 return -EINVAL;
313} 94}
95
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};
diff --git a/drivers/media/video/ivtv/ivtv-controls.h b/drivers/media/video/ivtv/ivtv-controls.h
index 1c7721e23c9b..d12893dd0183 100644
--- a/drivers/media/video/ivtv/ivtv-controls.h
+++ b/drivers/media/video/ivtv/ivtv-controls.h
@@ -21,10 +21,6 @@
21#ifndef IVTV_CONTROLS_H 21#ifndef IVTV_CONTROLS_H
22#define IVTV_CONTROLS_H 22#define IVTV_CONTROLS_H
23 23
24int ivtv_queryctrl(struct file *file, void *fh, struct v4l2_queryctrl *a); 24extern struct cx2341x_handler_ops ivtv_cxhdl_ops;
25int ivtv_g_ext_ctrls(struct file *file, void *fh, struct v4l2_ext_controls *a);
26int ivtv_s_ext_ctrls(struct file *file, void *fh, struct v4l2_ext_controls *a);
27int ivtv_try_ext_ctrls(struct file *file, void *fh, struct v4l2_ext_controls *a);
28int ivtv_querymenu(struct file *file, void *fh, struct v4l2_querymenu *a);
29 25
30#endif 26#endif
diff --git a/drivers/media/video/ivtv/ivtv-driver.c b/drivers/media/video/ivtv/ivtv-driver.c
index 53ea31aab155..e421d15b0f5c 100644
--- a/drivers/media/video/ivtv/ivtv-driver.c
+++ b/drivers/media/video/ivtv/ivtv-driver.c
@@ -53,6 +53,7 @@
53#include "ivtv-cards.h" 53#include "ivtv-cards.h"
54#include "ivtv-vbi.h" 54#include "ivtv-vbi.h"
55#include "ivtv-routing.h" 55#include "ivtv-routing.h"
56#include "ivtv-controls.h"
56#include "ivtv-gpio.h" 57#include "ivtv-gpio.h"
57 58
58#include <media/tveeprom.h> 59#include <media/tveeprom.h>
@@ -734,9 +735,8 @@ static int __devinit ivtv_init_struct1(struct ivtv *itv)
734 itv->open_id = 1; 735 itv->open_id = 1;
735 736
736 /* Initial settings */ 737 /* Initial settings */
737 cx2341x_fill_defaults(&itv->params); 738 itv->cxhdl.port = CX2341X_PORT_MEMORY;
738 itv->params.port = CX2341X_PORT_MEMORY; 739 itv->cxhdl.capabilities = CX2341X_CAP_HAS_SLICED_VBI;
739 itv->params.capabilities = CX2341X_CAP_HAS_SLICED_VBI;
740 init_waitqueue_head(&itv->eos_waitq); 740 init_waitqueue_head(&itv->eos_waitq);
741 init_waitqueue_head(&itv->event_waitq); 741 init_waitqueue_head(&itv->event_waitq);
742 init_waitqueue_head(&itv->vsync_waitq); 742 init_waitqueue_head(&itv->vsync_waitq);
@@ -1006,6 +1006,13 @@ static int __devinit ivtv_probe(struct pci_dev *pdev,
1006 retval = -ENOMEM; 1006 retval = -ENOMEM;
1007 goto err; 1007 goto err;
1008 } 1008 }
1009 retval = cx2341x_handler_init(&itv->cxhdl, 50);
1010 if (retval)
1011 goto err;
1012 itv->v4l2_dev.ctrl_handler = &itv->cxhdl.hdl;
1013 itv->cxhdl.ops = &ivtv_cxhdl_ops;
1014 itv->cxhdl.priv = itv;
1015 itv->cxhdl.func = ivtv_api_func;
1009 1016
1010 IVTV_DEBUG_INFO("base addr: 0x%08x\n", itv->base_addr); 1017 IVTV_DEBUG_INFO("base addr: 0x%08x\n", itv->base_addr);
1011 1018
@@ -1127,7 +1134,7 @@ static int __devinit ivtv_probe(struct pci_dev *pdev,
1127 itv->yuv_info.v4l2_src_w = itv->yuv_info.osd_full_w; 1134 itv->yuv_info.v4l2_src_w = itv->yuv_info.osd_full_w;
1128 itv->yuv_info.v4l2_src_h = itv->yuv_info.osd_full_h; 1135 itv->yuv_info.v4l2_src_h = itv->yuv_info.osd_full_h;
1129 1136
1130 itv->params.video_gop_size = itv->is_60hz ? 15 : 12; 1137 cx2341x_handler_set_50hz(&itv->cxhdl, itv->is_50hz);
1131 1138
1132 itv->stream_buf_size[IVTV_ENC_STREAM_TYPE_MPG] = 0x08000; 1139 itv->stream_buf_size[IVTV_ENC_STREAM_TYPE_MPG] = 0x08000;
1133 itv->stream_buf_size[IVTV_ENC_STREAM_TYPE_PCM] = 0x01200; 1140 itv->stream_buf_size[IVTV_ENC_STREAM_TYPE_PCM] = 0x01200;
@@ -1322,6 +1329,8 @@ int ivtv_init_on_first_open(struct ivtv *itv)
1322 /* For cards with video out, this call needs interrupts enabled */ 1329 /* For cards with video out, this call needs interrupts enabled */
1323 ivtv_s_std(NULL, &fh, &itv->tuner_std); 1330 ivtv_s_std(NULL, &fh, &itv->tuner_std);
1324 1331
1332 /* Setup initial controls */
1333 cx2341x_handler_setup(&itv->cxhdl);
1325 return 0; 1334 return 0;
1326} 1335}
1327 1336
@@ -1386,7 +1395,6 @@ static void ivtv_remove(struct pci_dev *pdev)
1386 printk(KERN_INFO "ivtv: Removed %s\n", itv->card_name); 1395 printk(KERN_INFO "ivtv: Removed %s\n", itv->card_name);
1387 1396
1388 v4l2_device_unregister(&itv->v4l2_dev); 1397 v4l2_device_unregister(&itv->v4l2_dev);
1389 v4l2_ctrl_handler_free(&itv->hdl_gpio);
1390 kfree(itv); 1398 kfree(itv);
1391} 1399}
1392 1400
diff --git a/drivers/media/video/ivtv/ivtv-driver.h b/drivers/media/video/ivtv/ivtv-driver.h
index d2260de4c812..75803141481e 100644
--- a/drivers/media/video/ivtv/ivtv-driver.h
+++ b/drivers/media/video/ivtv/ivtv-driver.h
@@ -62,6 +62,7 @@
62#include <linux/dvb/audio.h> 62#include <linux/dvb/audio.h>
63#include <media/v4l2-common.h> 63#include <media/v4l2-common.h>
64#include <media/v4l2-ioctl.h> 64#include <media/v4l2-ioctl.h>
65#include <media/v4l2-ctrls.h>
65#include <media/v4l2-device.h> 66#include <media/v4l2-device.h>
66#include <media/v4l2-fh.h> 67#include <media/v4l2-fh.h>
67#include <media/tuner.h> 68#include <media/tuner.h>
@@ -631,8 +632,9 @@ struct ivtv {
631 struct ivtv_options options; /* user options */ 632 struct ivtv_options options; /* user options */
632 633
633 struct v4l2_device v4l2_dev; 634 struct v4l2_device v4l2_dev;
634 struct v4l2_subdev sd_gpio; /* GPIO sub-device */ 635 struct cx2341x_handler cxhdl;
635 struct v4l2_ctrl_handler hdl_gpio; 636 struct v4l2_ctrl_handler hdl_gpio;
637 struct v4l2_subdev sd_gpio; /* GPIO sub-device */
636 u16 instance; 638 u16 instance;
637 639
638 /* High-level state info */ 640 /* High-level state info */
@@ -649,7 +651,6 @@ struct ivtv {
649 v4l2_std_id std_out; /* current TV output standard */ 651 v4l2_std_id std_out; /* current TV output standard */
650 u8 audio_stereo_mode; /* decoder setting how to handle stereo MPEG audio */ 652 u8 audio_stereo_mode; /* decoder setting how to handle stereo MPEG audio */
651 u8 audio_bilingual_mode; /* decoder setting how to handle bilingual MPEG audio */ 653 u8 audio_bilingual_mode; /* decoder setting how to handle bilingual MPEG audio */
652 struct cx2341x_mpeg_params params; /* current encoder parameters */
653 654
654 655
655 /* Locking */ 656 /* Locking */
diff --git a/drivers/media/video/ivtv/ivtv-fileops.c b/drivers/media/video/ivtv/ivtv-fileops.c
index a6a2cdb81566..d727485da886 100644
--- a/drivers/media/video/ivtv/ivtv-fileops.c
+++ b/drivers/media/video/ivtv/ivtv-fileops.c
@@ -150,12 +150,10 @@ void ivtv_release_stream(struct ivtv_stream *s)
150static void ivtv_dualwatch(struct ivtv *itv) 150static void ivtv_dualwatch(struct ivtv *itv)
151{ 151{
152 struct v4l2_tuner vt; 152 struct v4l2_tuner vt;
153 u32 new_bitmap;
154 u32 new_stereo_mode; 153 u32 new_stereo_mode;
155 const u32 stereo_mask = 0x0300; 154 const u32 dual = 0x02;
156 const u32 dual = 0x0200;
157 155
158 new_stereo_mode = itv->params.audio_properties & stereo_mask; 156 new_stereo_mode = v4l2_ctrl_g_ctrl(itv->cxhdl.audio_mode);
159 memset(&vt, 0, sizeof(vt)); 157 memset(&vt, 0, sizeof(vt));
160 ivtv_call_all(itv, tuner, g_tuner, &vt); 158 ivtv_call_all(itv, tuner, g_tuner, &vt);
161 if (vt.audmode == V4L2_TUNER_MODE_LANG1_LANG2 && (vt.rxsubchans & V4L2_TUNER_SUB_LANG2)) 159 if (vt.audmode == V4L2_TUNER_MODE_LANG1_LANG2 && (vt.rxsubchans & V4L2_TUNER_SUB_LANG2))
@@ -164,16 +162,10 @@ static void ivtv_dualwatch(struct ivtv *itv)
164 if (new_stereo_mode == itv->dualwatch_stereo_mode) 162 if (new_stereo_mode == itv->dualwatch_stereo_mode)
165 return; 163 return;
166 164
167 new_bitmap = new_stereo_mode | (itv->params.audio_properties & ~stereo_mask); 165 IVTV_DEBUG_INFO("dualwatch: change stereo flag from 0x%x to 0x%x.\n",
168 166 itv->dualwatch_stereo_mode, new_stereo_mode);
169 IVTV_DEBUG_INFO("dualwatch: change stereo flag from 0x%x to 0x%x. new audio_bitmask=0x%ux\n", 167 if (v4l2_ctrl_s_ctrl(itv->cxhdl.audio_mode, new_stereo_mode))
170 itv->dualwatch_stereo_mode, new_stereo_mode, new_bitmap); 168 IVTV_DEBUG_INFO("dualwatch: changing stereo flag failed\n");
171
172 if (ivtv_vapi(itv, CX2341X_ENC_SET_AUDIO_PROPERTIES, 1, new_bitmap) == 0) {
173 itv->dualwatch_stereo_mode = new_stereo_mode;
174 return;
175 }
176 IVTV_DEBUG_INFO("dualwatch: changing stereo flag failed\n");
177} 169}
178 170
179static void ivtv_update_pgm_info(struct ivtv *itv) 171static void ivtv_update_pgm_info(struct ivtv *itv)
@@ -894,7 +886,8 @@ int ivtv_v4l2_close(struct file *filp)
894 if (atomic_read(&itv->capturing) > 0) { 886 if (atomic_read(&itv->capturing) > 0) {
895 /* Undo video mute */ 887 /* Undo video mute */
896 ivtv_vapi(itv, CX2341X_ENC_MUTE_VIDEO, 1, 888 ivtv_vapi(itv, CX2341X_ENC_MUTE_VIDEO, 1,
897 itv->params.video_mute | (itv->params.video_mute_yuv << 8)); 889 v4l2_ctrl_g_ctrl(itv->cxhdl.video_mute) |
890 (v4l2_ctrl_g_ctrl(itv->cxhdl.video_mute_yuv) << 8));
898 } 891 }
899 /* Done! Unmute and continue. */ 892 /* Done! Unmute and continue. */
900 ivtv_unmute(itv); 893 ivtv_unmute(itv);
diff --git a/drivers/media/video/ivtv/ivtv-firmware.c b/drivers/media/video/ivtv/ivtv-firmware.c
index d8bf2b01729d..4df01947a7df 100644
--- a/drivers/media/video/ivtv/ivtv-firmware.c
+++ b/drivers/media/video/ivtv/ivtv-firmware.c
@@ -248,9 +248,9 @@ void ivtv_init_mpeg_decoder(struct ivtv *itv)
248 volatile u8 __iomem *mem_offset; 248 volatile u8 __iomem *mem_offset;
249 249
250 data[0] = 0; 250 data[0] = 0;
251 data[1] = itv->params.width; /* YUV source width */ 251 data[1] = itv->cxhdl.width; /* YUV source width */
252 data[2] = itv->params.height; 252 data[2] = itv->cxhdl.height;
253 data[3] = itv->params.audio_properties; /* Audio settings to use, 253 data[3] = itv->cxhdl.audio_properties; /* Audio settings to use,
254 bitmap. see docs. */ 254 bitmap. see docs. */
255 if (ivtv_api(itv, CX2341X_DEC_SET_DECODER_SOURCE, 4, data)) { 255 if (ivtv_api(itv, CX2341X_DEC_SET_DECODER_SOURCE, 4, data)) {
256 IVTV_ERR("ivtv_init_mpeg_decoder failed to set decoder source\n"); 256 IVTV_ERR("ivtv_init_mpeg_decoder failed to set decoder source\n");
diff --git a/drivers/media/video/ivtv/ivtv-ioctl.c b/drivers/media/video/ivtv/ivtv-ioctl.c
index 11ac2fa33ef7..4eed9123683e 100644
--- a/drivers/media/video/ivtv/ivtv-ioctl.c
+++ b/drivers/media/video/ivtv/ivtv-ioctl.c
@@ -162,7 +162,7 @@ int ivtv_set_speed(struct ivtv *itv, int speed)
162 data[0] |= (speed > 1000 || speed < -1500) ? 0x40000000 : 0; 162 data[0] |= (speed > 1000 || speed < -1500) ? 0x40000000 : 0;
163 data[1] = (speed < 0); 163 data[1] = (speed < 0);
164 data[2] = speed < 0 ? 3 : 7; 164 data[2] = speed < 0 ? 3 : 7;
165 data[3] = itv->params.video_b_frames; 165 data[3] = v4l2_ctrl_g_ctrl(itv->cxhdl.video_b_frames);
166 data[4] = (speed == 1500 || speed == 500) ? itv->speed_mute_audio : 0; 166 data[4] = (speed == 1500 || speed == 500) ? itv->speed_mute_audio : 0;
167 data[5] = 0; 167 data[5] = 0;
168 data[6] = 0; 168 data[6] = 0;
@@ -339,8 +339,8 @@ static int ivtv_g_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *f
339 struct ivtv *itv = id->itv; 339 struct ivtv *itv = id->itv;
340 struct v4l2_pix_format *pixfmt = &fmt->fmt.pix; 340 struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
341 341
342 pixfmt->width = itv->params.width; 342 pixfmt->width = itv->cxhdl.width;
343 pixfmt->height = itv->params.height; 343 pixfmt->height = itv->cxhdl.height;
344 pixfmt->colorspace = V4L2_COLORSPACE_SMPTE170M; 344 pixfmt->colorspace = V4L2_COLORSPACE_SMPTE170M;
345 pixfmt->field = V4L2_FIELD_INTERLACED; 345 pixfmt->field = V4L2_FIELD_INTERLACED;
346 pixfmt->priv = 0; 346 pixfmt->priv = 0;
@@ -568,7 +568,6 @@ static int ivtv_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *f
568{ 568{
569 struct ivtv_open_id *id = fh; 569 struct ivtv_open_id *id = fh;
570 struct ivtv *itv = id->itv; 570 struct ivtv *itv = id->itv;
571 struct cx2341x_mpeg_params *p = &itv->params;
572 struct v4l2_mbus_framefmt mbus_fmt; 571 struct v4l2_mbus_framefmt mbus_fmt;
573 int ret = ivtv_try_fmt_vid_cap(file, fh, fmt); 572 int ret = ivtv_try_fmt_vid_cap(file, fh, fmt);
574 int w = fmt->fmt.pix.width; 573 int w = fmt->fmt.pix.width;
@@ -577,15 +576,15 @@ static int ivtv_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *f
577 if (ret) 576 if (ret)
578 return ret; 577 return ret;
579 578
580 if (p->width == w && p->height == h) 579 if (itv->cxhdl.width == w && itv->cxhdl.height == h)
581 return 0; 580 return 0;
582 581
583 if (atomic_read(&itv->capturing) > 0) 582 if (atomic_read(&itv->capturing) > 0)
584 return -EBUSY; 583 return -EBUSY;
585 584
586 p->width = w; 585 itv->cxhdl.width = w;
587 p->height = h; 586 itv->cxhdl.height = h;
588 if (p->video_encoding == V4L2_MPEG_VIDEO_ENCODING_MPEG_1) 587 if (v4l2_ctrl_g_ctrl(itv->cxhdl.video_encoding) == V4L2_MPEG_VIDEO_ENCODING_MPEG_1)
589 fmt->fmt.pix.width /= 2; 588 fmt->fmt.pix.width /= 2;
590 mbus_fmt.width = fmt->fmt.pix.width; 589 mbus_fmt.width = fmt->fmt.pix.width;
591 mbus_fmt.height = h; 590 mbus_fmt.height = h;
@@ -1114,9 +1113,10 @@ int ivtv_s_std(struct file *file, void *fh, v4l2_std_id *std)
1114 1113
1115 itv->std = *std; 1114 itv->std = *std;
1116 itv->is_60hz = (*std & V4L2_STD_525_60) ? 1 : 0; 1115 itv->is_60hz = (*std & V4L2_STD_525_60) ? 1 : 0;
1117 itv->params.is_50hz = itv->is_50hz = !itv->is_60hz; 1116 itv->is_50hz = !itv->is_60hz;
1118 itv->params.width = 720; 1117 cx2341x_handler_set_50hz(&itv->cxhdl, itv->is_50hz);
1119 itv->params.height = itv->is_50hz ? 576 : 480; 1118 itv->cxhdl.width = 720;
1119 itv->cxhdl.height = itv->is_50hz ? 576 : 480;
1120 itv->vbi.count = itv->is_50hz ? 18 : 12; 1120 itv->vbi.count = itv->is_50hz ? 18 : 12;
1121 itv->vbi.start[0] = itv->is_50hz ? 6 : 10; 1121 itv->vbi.start[0] = itv->is_50hz ? 6 : 10;
1122 itv->vbi.start[1] = itv->is_50hz ? 318 : 273; 1122 itv->vbi.start[1] = itv->is_50hz ? 318 : 273;
@@ -1157,7 +1157,7 @@ int ivtv_s_std(struct file *file, void *fh, v4l2_std_id *std)
1157 ivtv_vapi(itv, CX2341X_DEC_SET_STANDARD, 1, itv->is_out_50hz); 1157 ivtv_vapi(itv, CX2341X_DEC_SET_STANDARD, 1, itv->is_out_50hz);
1158 itv->main_rect.left = itv->main_rect.top = 0; 1158 itv->main_rect.left = itv->main_rect.top = 0;
1159 itv->main_rect.width = 720; 1159 itv->main_rect.width = 720;
1160 itv->main_rect.height = itv->params.height; 1160 itv->main_rect.height = itv->cxhdl.height;
1161 ivtv_vapi(itv, CX2341X_OSD_SET_FRAMEBUFFER_WINDOW, 4, 1161 ivtv_vapi(itv, CX2341X_OSD_SET_FRAMEBUFFER_WINDOW, 4,
1162 720, itv->main_rect.height, 0, 0); 1162 720, itv->main_rect.height, 0, 0);
1163 yi->main_rect = itv->main_rect; 1163 yi->main_rect = itv->main_rect;
@@ -1554,7 +1554,7 @@ static int ivtv_log_status(struct file *file, void *fh)
1554 } 1554 }
1555 IVTV_INFO("Tuner: %s\n", 1555 IVTV_INFO("Tuner: %s\n",
1556 test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags) ? "Radio" : "TV"); 1556 test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags) ? "Radio" : "TV");
1557 cx2341x_log_status(&itv->params, itv->v4l2_dev.name); 1557 v4l2_ctrl_handler_log_status(&itv->cxhdl.hdl, itv->v4l2_dev.name);
1558 IVTV_INFO("Status flags: 0x%08lx\n", itv->i_flags); 1558 IVTV_INFO("Status flags: 0x%08lx\n", itv->i_flags);
1559 for (i = 0; i < IVTV_MAX_STREAMS; i++) { 1559 for (i = 0; i < IVTV_MAX_STREAMS; i++) {
1560 struct ivtv_stream *s = &itv->streams[i]; 1560 struct ivtv_stream *s = &itv->streams[i];
@@ -1942,11 +1942,6 @@ static const struct v4l2_ioctl_ops ivtv_ioctl_ops = {
1942 .vidioc_s_register = ivtv_s_register, 1942 .vidioc_s_register = ivtv_s_register,
1943#endif 1943#endif
1944 .vidioc_default = ivtv_default, 1944 .vidioc_default = ivtv_default,
1945 .vidioc_queryctrl = ivtv_queryctrl,
1946 .vidioc_querymenu = ivtv_querymenu,
1947 .vidioc_g_ext_ctrls = ivtv_g_ext_ctrls,
1948 .vidioc_s_ext_ctrls = ivtv_s_ext_ctrls,
1949 .vidioc_try_ext_ctrls = ivtv_try_ext_ctrls,
1950 .vidioc_subscribe_event = ivtv_subscribe_event, 1945 .vidioc_subscribe_event = ivtv_subscribe_event,
1951 .vidioc_unsubscribe_event = v4l2_event_unsubscribe, 1946 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1952}; 1947};
diff --git a/drivers/media/video/ivtv/ivtv-streams.c b/drivers/media/video/ivtv/ivtv-streams.c
index 55df4190c28d..512607e0cda3 100644
--- a/drivers/media/video/ivtv/ivtv-streams.c
+++ b/drivers/media/video/ivtv/ivtv-streams.c
@@ -210,6 +210,7 @@ static int ivtv_prep_dev(struct ivtv *itv, int type)
210 210
211 s->vdev->num = num; 211 s->vdev->num = num;
212 s->vdev->v4l2_dev = &itv->v4l2_dev; 212 s->vdev->v4l2_dev = &itv->v4l2_dev;
213 s->vdev->ctrl_handler = itv->v4l2_dev.ctrl_handler;
213 s->vdev->fops = ivtv_stream_info[type].fops; 214 s->vdev->fops = ivtv_stream_info[type].fops;
214 s->vdev->release = video_device_release; 215 s->vdev->release = video_device_release;
215 s->vdev->tvnorms = V4L2_STD_ALL; 216 s->vdev->tvnorms = V4L2_STD_ALL;
@@ -451,7 +452,6 @@ int ivtv_start_v4l2_encode_stream(struct ivtv_stream *s)
451{ 452{
452 u32 data[CX2341X_MBOX_MAX_DATA]; 453 u32 data[CX2341X_MBOX_MAX_DATA];
453 struct ivtv *itv = s->itv; 454 struct ivtv *itv = s->itv;
454 struct cx2341x_mpeg_params *p = &itv->params;
455 int captype = 0, subtype = 0; 455 int captype = 0, subtype = 0;
456 int enable_passthrough = 0; 456 int enable_passthrough = 0;
457 457
@@ -472,7 +472,7 @@ int ivtv_start_v4l2_encode_stream(struct ivtv_stream *s)
472 } 472 }
473 itv->mpg_data_received = itv->vbi_data_inserted = 0; 473 itv->mpg_data_received = itv->vbi_data_inserted = 0;
474 itv->dualwatch_jiffies = jiffies; 474 itv->dualwatch_jiffies = jiffies;
475 itv->dualwatch_stereo_mode = p->audio_properties & 0x0300; 475 itv->dualwatch_stereo_mode = v4l2_ctrl_g_ctrl(itv->cxhdl.audio_mode);
476 itv->search_pack_header = 0; 476 itv->search_pack_header = 0;
477 break; 477 break;
478 478
@@ -560,12 +560,12 @@ int ivtv_start_v4l2_encode_stream(struct ivtv_stream *s)
560 itv->pgm_info_offset, itv->pgm_info_num); 560 itv->pgm_info_offset, itv->pgm_info_num);
561 561
562 /* Setup API for Stream */ 562 /* Setup API for Stream */
563 cx2341x_update(itv, ivtv_api_func, NULL, p); 563 cx2341x_handler_setup(&itv->cxhdl);
564 564
565 /* mute if capturing radio */ 565 /* mute if capturing radio */
566 if (test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags)) 566 if (test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags))
567 ivtv_vapi(itv, CX2341X_ENC_MUTE_VIDEO, 1, 567 ivtv_vapi(itv, CX2341X_ENC_MUTE_VIDEO, 1,
568 1 | (p->video_mute_yuv << 8)); 568 1 | (v4l2_ctrl_g_ctrl(itv->cxhdl.video_mute_yuv) << 8));
569 } 569 }
570 570
571 /* Vsync Setup */ 571 /* Vsync Setup */
@@ -581,6 +581,8 @@ int ivtv_start_v4l2_encode_stream(struct ivtv_stream *s)
581 581
582 clear_bit(IVTV_F_I_EOS, &itv->i_flags); 582 clear_bit(IVTV_F_I_EOS, &itv->i_flags);
583 583
584 cx2341x_handler_set_busy(&itv->cxhdl, 1);
585
584 /* Initialize Digitizer for Capture */ 586 /* Initialize Digitizer for Capture */
585 /* Avoid tinny audio problem - ensure audio clocks are going */ 587 /* Avoid tinny audio problem - ensure audio clocks are going */
586 v4l2_subdev_call(itv->sd_audio, audio, s_stream, 1); 588 v4l2_subdev_call(itv->sd_audio, audio, s_stream, 1);
@@ -617,7 +619,6 @@ static int ivtv_setup_v4l2_decode_stream(struct ivtv_stream *s)
617{ 619{
618 u32 data[CX2341X_MBOX_MAX_DATA]; 620 u32 data[CX2341X_MBOX_MAX_DATA];
619 struct ivtv *itv = s->itv; 621 struct ivtv *itv = s->itv;
620 struct cx2341x_mpeg_params *p = &itv->params;
621 int datatype; 622 int datatype;
622 u16 width; 623 u16 width;
623 u16 height; 624 u16 height;
@@ -627,8 +628,8 @@ static int ivtv_setup_v4l2_decode_stream(struct ivtv_stream *s)
627 628
628 IVTV_DEBUG_INFO("Setting some initial decoder settings\n"); 629 IVTV_DEBUG_INFO("Setting some initial decoder settings\n");
629 630
630 width = p->width; 631 width = itv->cxhdl.width;
631 height = p->height; 632 height = itv->cxhdl.height;
632 633
633 /* set audio mode to left/stereo for dual/stereo mode. */ 634 /* set audio mode to left/stereo for dual/stereo mode. */
634 ivtv_vapi(itv, CX2341X_DEC_SET_AUDIO_MODE, 2, itv->audio_bilingual_mode, itv->audio_stereo_mode); 635 ivtv_vapi(itv, CX2341X_DEC_SET_AUDIO_MODE, 2, itv->audio_bilingual_mode, itv->audio_stereo_mode);
@@ -668,7 +669,7 @@ static int ivtv_setup_v4l2_decode_stream(struct ivtv_stream *s)
668 break; 669 break;
669 } 670 }
670 if (ivtv_vapi(itv, CX2341X_DEC_SET_DECODER_SOURCE, 4, datatype, 671 if (ivtv_vapi(itv, CX2341X_DEC_SET_DECODER_SOURCE, 4, datatype,
671 width, height, p->audio_properties)) { 672 width, height, itv->cxhdl.audio_properties)) {
672 IVTV_DEBUG_WARN("Couldn't initialize decoder source\n"); 673 IVTV_DEBUG_WARN("Couldn't initialize decoder source\n");
673 } 674 }
674 675
@@ -847,6 +848,8 @@ int ivtv_stop_v4l2_encode_stream(struct ivtv_stream *s, int gop_end)
847 return 0; 848 return 0;
848 } 849 }
849 850
851 cx2341x_handler_set_busy(&itv->cxhdl, 0);
852
850 /* Set the following Interrupt mask bits for capture */ 853 /* Set the following Interrupt mask bits for capture */
851 ivtv_set_irq_mask(itv, IVTV_IRQ_MASK_CAPTURE); 854 ivtv_set_irq_mask(itv, IVTV_IRQ_MASK_CAPTURE);
852 del_timer(&itv->dma_timer); 855 del_timer(&itv->dma_timer);
@@ -967,7 +970,8 @@ int ivtv_passthrough_mode(struct ivtv *itv, int enable)
967 970
968 /* Setup capture if not already done */ 971 /* Setup capture if not already done */
969 if (atomic_read(&itv->capturing) == 0) { 972 if (atomic_read(&itv->capturing) == 0) {
970 cx2341x_update(itv, ivtv_api_func, NULL, &itv->params); 973 cx2341x_handler_setup(&itv->cxhdl);
974 cx2341x_handler_set_busy(&itv->cxhdl, 1);
971 } 975 }
972 976
973 /* Start Passthrough Mode */ 977 /* Start Passthrough Mode */
@@ -988,6 +992,8 @@ int ivtv_passthrough_mode(struct ivtv *itv, int enable)
988 clear_bit(IVTV_F_S_PASSTHROUGH, &dec_stream->s_flags); 992 clear_bit(IVTV_F_S_PASSTHROUGH, &dec_stream->s_flags);
989 clear_bit(IVTV_F_S_STREAMING, &dec_stream->s_flags); 993 clear_bit(IVTV_F_S_STREAMING, &dec_stream->s_flags);
990 itv->output_mode = OUT_NONE; 994 itv->output_mode = OUT_NONE;
995 if (atomic_read(&itv->capturing) == 0)
996 cx2341x_handler_set_busy(&itv->cxhdl, 0);
991 997
992 return 0; 998 return 0;
993} 999}