aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media
diff options
context:
space:
mode:
authorHans Verkuil <hverkuil@xs4all.nl>2009-02-07 09:18:05 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2009-03-30 11:42:42 -0400
commit1b8dac150a01e2312d8e3fedd6462a0ec34c96d0 (patch)
treeba8fd678a4afb4bd72960e1737f857991fd00a19 /drivers/media
parentd30e21ddcdc948ecedfb46a0ed021d57f310a6f3 (diff)
V4L/DVB (10499): saa7146: convert saa7146 and mxb in particular to v4l2_subdev.
Modified mxb to load the i2c modules through v4l2_subdev. So no more probing. Modified tea6415c and tea6420 to use the standard routing ops to do the routing, rather than using private commands. Dropped the private commands from tda9840 (they were never used except during initialization of the module). Added saa7146 support for VIDIOC_DBG_G_CHIP_IDENT. Converted saa5246a and saa5249 to v4l2_subdev. 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/common/saa7146_video.c25
-rw-r--r--drivers/media/video/mxb.c274
-rw-r--r--drivers/media/video/saa5246a.c69
-rw-r--r--drivers/media/video/saa5249.c70
-rw-r--r--drivers/media/video/tda9840.c81
-rw-r--r--drivers/media/video/tda9840.h14
-rw-r--r--drivers/media/video/tea6415c.c52
-rw-r--r--drivers/media/video/tea6415c.h12
-rw-r--r--drivers/media/video/tea6420.c68
-rw-r--r--drivers/media/video/tea6420.h27
10 files changed, 297 insertions, 395 deletions
diff --git a/drivers/media/common/saa7146_video.c b/drivers/media/common/saa7146_video.c
index 91b7a4def46..a2a8847e678 100644
--- a/drivers/media/common/saa7146_video.c
+++ b/drivers/media/common/saa7146_video.c
@@ -1,4 +1,5 @@
1#include <media/saa7146_vv.h> 1#include <media/saa7146_vv.h>
2#include <media/v4l2-chip-ident.h>
2 3
3static int max_memory = 32; 4static int max_memory = 32;
4 5
@@ -209,6 +210,7 @@ static struct v4l2_queryctrl controls[] = {
209 .step = 1, 210 .step = 1,
210 .default_value = 128, 211 .default_value = 128,
211 .type = V4L2_CTRL_TYPE_INTEGER, 212 .type = V4L2_CTRL_TYPE_INTEGER,
213 .flags = V4L2_CTRL_FLAG_SLIDER,
212 },{ 214 },{
213 .id = V4L2_CID_CONTRAST, 215 .id = V4L2_CID_CONTRAST,
214 .name = "Contrast", 216 .name = "Contrast",
@@ -217,6 +219,7 @@ static struct v4l2_queryctrl controls[] = {
217 .step = 1, 219 .step = 1,
218 .default_value = 64, 220 .default_value = 64,
219 .type = V4L2_CTRL_TYPE_INTEGER, 221 .type = V4L2_CTRL_TYPE_INTEGER,
222 .flags = V4L2_CTRL_FLAG_SLIDER,
220 },{ 223 },{
221 .id = V4L2_CID_SATURATION, 224 .id = V4L2_CID_SATURATION,
222 .name = "Saturation", 225 .name = "Saturation",
@@ -225,15 +228,16 @@ static struct v4l2_queryctrl controls[] = {
225 .step = 1, 228 .step = 1,
226 .default_value = 64, 229 .default_value = 64,
227 .type = V4L2_CTRL_TYPE_INTEGER, 230 .type = V4L2_CTRL_TYPE_INTEGER,
231 .flags = V4L2_CTRL_FLAG_SLIDER,
228 },{ 232 },{
229 .id = V4L2_CID_VFLIP, 233 .id = V4L2_CID_VFLIP,
230 .name = "Vertical flip", 234 .name = "Vertical Flip",
231 .minimum = 0, 235 .minimum = 0,
232 .maximum = 1, 236 .maximum = 1,
233 .type = V4L2_CTRL_TYPE_BOOLEAN, 237 .type = V4L2_CTRL_TYPE_BOOLEAN,
234 },{ 238 },{
235 .id = V4L2_CID_HFLIP, 239 .id = V4L2_CID_HFLIP,
236 .name = "Horizontal flip", 240 .name = "Horizontal Flip",
237 .minimum = 0, 241 .minimum = 0,
238 .maximum = 1, 242 .maximum = 1,
239 .type = V4L2_CTRL_TYPE_BOOLEAN, 243 .type = V4L2_CTRL_TYPE_BOOLEAN,
@@ -1112,6 +1116,22 @@ static int vidioc_streamoff(struct file *file, void *__fh, enum v4l2_buf_type ty
1112 return err; 1116 return err;
1113} 1117}
1114 1118
1119static int vidioc_g_chip_ident(struct file *file, void *__fh,
1120 struct v4l2_dbg_chip_ident *chip)
1121{
1122 struct saa7146_fh *fh = __fh;
1123 struct saa7146_dev *dev = fh->dev;
1124
1125 chip->ident = V4L2_IDENT_NONE;
1126 chip->revision = 0;
1127 if (v4l2_chip_match_host(&chip->match)) {
1128 chip->ident = V4L2_IDENT_SAA7146;
1129 return 0;
1130 }
1131 return v4l2_device_call_until_err(&dev->v4l2_dev, 0,
1132 core, g_chip_ident, chip);
1133}
1134
1115#ifdef CONFIG_VIDEO_V4L1_COMPAT 1135#ifdef CONFIG_VIDEO_V4L1_COMPAT
1116static int vidiocgmbuf(struct file *file, void *__fh, struct video_mbuf *mbuf) 1136static int vidiocgmbuf(struct file *file, void *__fh, struct video_mbuf *mbuf)
1117{ 1137{
@@ -1152,6 +1172,7 @@ const struct v4l2_ioctl_ops saa7146_video_ioctl_ops = {
1152 .vidioc_try_fmt_vid_overlay = vidioc_try_fmt_vid_overlay, 1172 .vidioc_try_fmt_vid_overlay = vidioc_try_fmt_vid_overlay,
1153 .vidioc_s_fmt_vid_overlay = vidioc_s_fmt_vid_overlay, 1173 .vidioc_s_fmt_vid_overlay = vidioc_s_fmt_vid_overlay,
1154 .vidioc_g_fmt_vbi_cap = vidioc_g_fmt_vbi_cap, 1174 .vidioc_g_fmt_vbi_cap = vidioc_g_fmt_vbi_cap,
1175 .vidioc_g_chip_ident = vidioc_g_chip_ident,
1155 1176
1156 .vidioc_overlay = vidioc_overlay, 1177 .vidioc_overlay = vidioc_overlay,
1157 .vidioc_g_fbuf = vidioc_g_fbuf, 1178 .vidioc_g_fbuf = vidioc_g_fbuf,
diff --git a/drivers/media/video/mxb.c b/drivers/media/video/mxb.c
index 8ecda8dfbd0..996011f2aba 100644
--- a/drivers/media/video/mxb.c
+++ b/drivers/media/video/mxb.c
@@ -32,9 +32,14 @@
32#include "mxb.h" 32#include "mxb.h"
33#include "tea6415c.h" 33#include "tea6415c.h"
34#include "tea6420.h" 34#include "tea6420.h"
35#include "tda9840.h"
36 35
37#define I2C_SAA7111 0x24 36#define I2C_SAA5246A 0x11
37#define I2C_SAA7111A 0x24
38#define I2C_TDA9840 0x42
39#define I2C_TEA6415C 0x43
40#define I2C_TEA6420_1 0x4c
41#define I2C_TEA6420_2 0x4d
42#define I2C_TUNER 0x60
38 43
39#define MXB_BOARD_CAN_DO_VBI(dev) (dev->revision != 0) 44#define MXB_BOARD_CAN_DO_VBI(dev) (dev->revision != 0)
40 45
@@ -79,31 +84,29 @@ static struct {
79static int video_audio_connect[MXB_INPUTS] = 84static int video_audio_connect[MXB_INPUTS] =
80 { 0, 1, 3, 3 }; 85 { 0, 1, 3, 3 };
81 86
82/* these are the necessary input-output-pins for bringing one audio source 87/* These are the necessary input-output-pins for bringing one audio source
83(see above) to the CD-output */ 88 (see above) to the CD-output. Note that gain is set to 0 in this table. */
84static struct tea6420_multiplex TEA6420_cd[MXB_AUDIOS+1][2] = 89static struct v4l2_routing TEA6420_cd[MXB_AUDIOS + 1][2] = {
85 { 90 { { 1, 1 }, { 1, 1 } }, /* Tuner */
86 {{1,1,0},{1,1,0}}, /* Tuner */ 91 { { 5, 1 }, { 6, 1 } }, /* AUX 1 */
87 {{5,1,0},{6,1,0}}, /* AUX 1 */ 92 { { 4, 1 }, { 6, 1 } }, /* AUX 2 */
88 {{4,1,0},{6,1,0}}, /* AUX 2 */ 93 { { 3, 1 }, { 6, 1 } }, /* AUX 3 */
89 {{3,1,0},{6,1,0}}, /* AUX 3 */ 94 { { 1, 1 }, { 3, 1 } }, /* Radio */
90 {{1,1,0},{3,1,0}}, /* Radio */ 95 { { 1, 1 }, { 2, 1 } }, /* CD-Rom */
91 {{1,1,0},{2,1,0}}, /* CD-Rom */ 96 { { 6, 1 }, { 6, 1 } } /* Mute */
92 {{6,1,0},{6,1,0}} /* Mute */ 97};
93 }; 98
94 99/* These are the necessary input-output-pins for bringing one audio source
95/* these are the necessary input-output-pins for bringing one audio source 100 (see above) to the line-output. Note that gain is set to 0 in this table. */
96(see above) to the line-output */ 101static struct v4l2_routing TEA6420_line[MXB_AUDIOS + 1][2] = {
97static struct tea6420_multiplex TEA6420_line[MXB_AUDIOS+1][2] = 102 { { 2, 3 }, { 1, 2 } },
98 { 103 { { 5, 3 }, { 6, 2 } },
99 {{2,3,0},{1,2,0}}, 104 { { 4, 3 }, { 6, 2 } },
100 {{5,3,0},{6,2,0}}, 105 { { 3, 3 }, { 6, 2 } },
101 {{4,3,0},{6,2,0}}, 106 { { 2, 3 }, { 3, 2 } },
102 {{3,3,0},{6,2,0}}, 107 { { 2, 3 }, { 2, 2 } },
103 {{2,3,0},{3,2,0}}, 108 { { 6, 3 }, { 6, 2 } } /* Mute */
104 {{2,3,0},{2,2,0}}, 109};
105 {{6,3,0},{6,2,0}} /* Mute */
106 };
107 110
108#define MAXCONTROLS 1 111#define MAXCONTROLS 1
109static struct v4l2_queryctrl mxb_controls[] = { 112static struct v4l2_queryctrl mxb_controls[] = {
@@ -117,12 +120,12 @@ struct mxb
117 120
118 struct i2c_adapter i2c_adapter; 121 struct i2c_adapter i2c_adapter;
119 122
120 struct i2c_client *saa7111a; 123 struct v4l2_subdev *saa7111a;
121 struct i2c_client *tda9840; 124 struct v4l2_subdev *tda9840;
122 struct i2c_client *tea6415c; 125 struct v4l2_subdev *tea6415c;
123 struct i2c_client *tuner; 126 struct v4l2_subdev *tuner;
124 struct i2c_client *tea6420_1; 127 struct v4l2_subdev *tea6420_1;
125 struct i2c_client *tea6420_2; 128 struct v4l2_subdev *tea6420_2;
126 129
127 int cur_mode; /* current audio mode (mono, stereo, ...) */ 130 int cur_mode; /* current audio mode (mono, stereo, ...) */
128 int cur_input; /* current input */ 131 int cur_input; /* current input */
@@ -130,84 +133,51 @@ struct mxb
130 struct v4l2_frequency cur_freq; /* current frequency the tuner is tuned to */ 133 struct v4l2_frequency cur_freq; /* current frequency the tuner is tuned to */
131}; 134};
132 135
133static struct saa7146_extension extension; 136#define saa7111a_call(mxb, o, f, args...) \
134 137 v4l2_subdev_call(mxb->saa7111a, o, f, ##args)
135static int mxb_check_clients(struct device *dev, void *data) 138#define tea6420_1_call(mxb, o, f, args...) \
136{ 139 v4l2_subdev_call(mxb->tea6420_1, o, f, ##args)
137 struct mxb *mxb = data; 140#define tea6420_2_call(mxb, o, f, args...) \
138 struct i2c_client *client = i2c_verify_client(dev); 141 v4l2_subdev_call(mxb->tea6420_2, o, f, ##args)
139 142#define tda9840_call(mxb, o, f, args...) \
140 if (!client) 143 v4l2_subdev_call(mxb->tda9840, o, f, ##args)
141 return 0; 144#define tea6415c_call(mxb, o, f, args...) \
142 145 v4l2_subdev_call(mxb->tea6415c, o, f, ##args)
143 if (I2C_ADDR_TEA6420_1 == client->addr) 146#define tuner_call(mxb, o, f, args...) \
144 mxb->tea6420_1 = client; 147 v4l2_subdev_call(mxb->tuner, o, f, ##args)
145 if (I2C_ADDR_TEA6420_2 == client->addr) 148#define call_all(dev, o, f, args...) \
146 mxb->tea6420_2 = client; 149 v4l2_device_call_until_err(&dev->v4l2_dev, 0, o, f, ##args)
147 if (I2C_TEA6415C_2 == client->addr)
148 mxb->tea6415c = client;
149 if (I2C_ADDR_TDA9840 == client->addr)
150 mxb->tda9840 = client;
151 if (I2C_SAA7111 == client->addr)
152 mxb->saa7111a = client;
153 if (0x60 == client->addr)
154 mxb->tuner = client;
155 150
156 return 0; 151static struct saa7146_extension extension;
157}
158 152
159static int mxb_probe(struct saa7146_dev* dev) 153static int mxb_probe(struct saa7146_dev *dev)
160{ 154{
161 struct mxb* mxb = NULL; 155 struct mxb *mxb = NULL;
162 int result;
163
164 result = request_module("saa7115");
165 if (result < 0) {
166 printk("mxb: saa7111 i2c module not available.\n");
167 return -ENODEV;
168 }
169 result = request_module("tea6420");
170 if (result < 0) {
171 printk("mxb: tea6420 i2c module not available.\n");
172 return -ENODEV;
173 }
174 result = request_module("tea6415c");
175 if (result < 0) {
176 printk("mxb: tea6415c i2c module not available.\n");
177 return -ENODEV;
178 }
179 result = request_module("tda9840");
180 if (result < 0) {
181 printk("mxb: tda9840 i2c module not available.\n");
182 return -ENODEV;
183 }
184 result = request_module("tuner");
185 if (result < 0) {
186 printk("mxb: tuner i2c module not available.\n");
187 return -ENODEV;
188 }
189 156
190 mxb = kzalloc(sizeof(struct mxb), GFP_KERNEL); 157 mxb = kzalloc(sizeof(struct mxb), GFP_KERNEL);
191 if( NULL == mxb ) { 158 if (mxb == NULL) {
192 DEB_D(("not enough kernel memory.\n")); 159 DEB_D(("not enough kernel memory.\n"));
193 return -ENOMEM; 160 return -ENOMEM;
194 } 161 }
195 162
196 mxb->i2c_adapter = (struct i2c_adapter) {
197 .class = I2C_CLASS_TV_ANALOG,
198 };
199
200 snprintf(mxb->i2c_adapter.name, sizeof(mxb->i2c_adapter.name), "mxb%d", mxb_num); 163 snprintf(mxb->i2c_adapter.name, sizeof(mxb->i2c_adapter.name), "mxb%d", mxb_num);
201 164
202 saa7146_i2c_adapter_prepare(dev, &mxb->i2c_adapter, SAA7146_I2C_BUS_BIT_RATE_480); 165 saa7146_i2c_adapter_prepare(dev, &mxb->i2c_adapter, SAA7146_I2C_BUS_BIT_RATE_480);
203 if(i2c_add_adapter(&mxb->i2c_adapter) < 0) { 166 if (i2c_add_adapter(&mxb->i2c_adapter) < 0) {
204 DEB_S(("cannot register i2c-device. skipping.\n")); 167 DEB_S(("cannot register i2c-device. skipping.\n"));
205 kfree(mxb); 168 kfree(mxb);
206 return -EFAULT; 169 return -EFAULT;
207 } 170 }
208 171
209 /* loop through all i2c-devices on the bus and look who is there */ 172 mxb->saa7111a = v4l2_i2c_new_subdev(&mxb->i2c_adapter, "saa7115", "saa7111", I2C_SAA7111A);
210 device_for_each_child(&mxb->i2c_adapter.dev, mxb, mxb_check_clients); 173 mxb->tea6420_1 = v4l2_i2c_new_subdev(&mxb->i2c_adapter, "tea6420", "tea6420", I2C_TEA6420_1);
174 mxb->tea6420_2 = v4l2_i2c_new_subdev(&mxb->i2c_adapter, "tea6420", "tea6420", I2C_TEA6420_2);
175 mxb->tea6415c = v4l2_i2c_new_subdev(&mxb->i2c_adapter, "tea6415c", "tea6415c", I2C_TEA6415C);
176 mxb->tda9840 = v4l2_i2c_new_subdev(&mxb->i2c_adapter, "tda9840", "tda9840", I2C_TDA9840);
177 mxb->tuner = v4l2_i2c_new_subdev(&mxb->i2c_adapter, "tuner", "tuner", I2C_TUNER);
178 if (v4l2_i2c_new_subdev(&mxb->i2c_adapter, "saa5246a", "saa5246a", I2C_SAA5246A)) {
179 printk(KERN_INFO "mxb: found teletext decoder\n");
180 }
211 181
212 /* check if all devices are present */ 182 /* check if all devices are present */
213 if (!mxb->tea6420_1 || !mxb->tea6420_2 || !mxb->tea6415c || 183 if (!mxb->tea6420_1 || !mxb->tea6420_2 || !mxb->tea6415c ||
@@ -295,47 +265,45 @@ static int mxb_init_done(struct saa7146_dev* dev)
295 struct v4l2_routing route; 265 struct v4l2_routing route;
296 266
297 int i = 0, err = 0; 267 int i = 0, err = 0;
298 struct tea6415c_multiplex vm;
299 268
300 /* select video mode in saa7111a */ 269 /* select video mode in saa7111a */
301 mxb->saa7111a->driver->command(mxb->saa7111a, VIDIOC_S_STD, &std); 270 saa7111a_call(mxb, tuner, s_std, std);
302 271
303 /* select tuner-output on saa7111a */ 272 /* select tuner-output on saa7111a */
304 i = 0; 273 i = 0;
305 route.input = SAA7115_COMPOSITE0; 274 route.input = SAA7115_COMPOSITE0;
306 route.output = SAA7111_FMT_CCIR | SAA7111_VBI_BYPASS; 275 route.output = SAA7111_FMT_CCIR | SAA7111_VBI_BYPASS;
307 mxb->saa7111a->driver->command(mxb->saa7111a, VIDIOC_INT_S_VIDEO_ROUTING, &route); 276 saa7111a_call(mxb, video, s_routing, &route);
308 277
309 /* select a tuner type */ 278 /* select a tuner type */
310 tun_setup.mode_mask = T_ANALOG_TV; 279 tun_setup.mode_mask = T_ANALOG_TV;
311 tun_setup.addr = ADDR_UNSET; 280 tun_setup.addr = ADDR_UNSET;
312 tun_setup.type = TUNER_PHILIPS_PAL; 281 tun_setup.type = TUNER_PHILIPS_PAL;
313 mxb->tuner->driver->command(mxb->tuner, TUNER_SET_TYPE_ADDR, &tun_setup); 282 tuner_call(mxb, tuner, s_type_addr, &tun_setup);
314 /* tune in some frequency on tuner */ 283 /* tune in some frequency on tuner */
315 mxb->cur_freq.tuner = 0; 284 mxb->cur_freq.tuner = 0;
316 mxb->cur_freq.type = V4L2_TUNER_ANALOG_TV; 285 mxb->cur_freq.type = V4L2_TUNER_ANALOG_TV;
317 mxb->cur_freq.frequency = freq; 286 mxb->cur_freq.frequency = freq;
318 mxb->tuner->driver->command(mxb->tuner, VIDIOC_S_FREQUENCY, 287 tuner_call(mxb, tuner, s_frequency, &mxb->cur_freq);
319 &mxb->cur_freq);
320 288
321 /* set a default video standard */ 289 /* set a default video standard */
322 mxb->tuner->driver->command(mxb->tuner, VIDIOC_S_STD, &std); 290 tuner_call(mxb, tuner, s_std, std);
323 291
324 /* mute audio on tea6420s */ 292 /* mute audio on tea6420s */
325 mxb->tea6420_1->driver->command(mxb->tea6420_1, TEA6420_SWITCH, &TEA6420_line[6][0]); 293 tea6420_1_call(mxb, audio, s_routing, &TEA6420_line[6][0]);
326 mxb->tea6420_2->driver->command(mxb->tea6420_2, TEA6420_SWITCH, &TEA6420_line[6][1]); 294 tea6420_2_call(mxb, audio, s_routing, &TEA6420_line[6][1]);
327 mxb->tea6420_1->driver->command(mxb->tea6420_1, TEA6420_SWITCH, &TEA6420_cd[6][0]); 295 tea6420_1_call(mxb, audio, s_routing, &TEA6420_line[6][0]);
328 mxb->tea6420_2->driver->command(mxb->tea6420_2, TEA6420_SWITCH, &TEA6420_cd[6][1]); 296 tea6420_2_call(mxb, audio, s_routing, &TEA6420_line[6][1]);
329 297
330 /* switch to tuner-channel on tea6415c*/ 298 /* switch to tuner-channel on tea6415c */
331 vm.out = 17; 299 route.input = 3;
332 vm.in = 3; 300 route.output = 17;
333 mxb->tea6415c->driver->command(mxb->tea6415c, TEA6415C_SWITCH, &vm); 301 tea6415c_call(mxb, video, s_routing, &route);
334 302
335 /* select tuner-output on multicable on tea6415c*/ 303 /* select tuner-output on multicable on tea6415c */
336 vm.in = 3; 304 route.input = 3;
337 vm.out = 13; 305 route.output = 13;
338 mxb->tea6415c->driver->command(mxb->tea6415c, TEA6415C_SWITCH, &vm); 306 tea6415c_call(mxb, video, s_routing, &route);
339 307
340 /* the rest for mxb */ 308 /* the rest for mxb */
341 mxb->cur_input = 0; 309 mxb->cur_input = 0;
@@ -461,14 +429,14 @@ static int vidioc_s_ctrl(struct file *file, void *fh, struct v4l2_control *vc)
461 mxb->cur_mute = vc->value; 429 mxb->cur_mute = vc->value;
462 if (!vc->value) { 430 if (!vc->value) {
463 /* switch the audio-source */ 431 /* switch the audio-source */
464 mxb->tea6420_1->driver->command(mxb->tea6420_1, TEA6420_SWITCH, 432 tea6420_1_call(mxb, audio, s_routing,
465 &TEA6420_line[video_audio_connect[mxb->cur_input]][0]); 433 &TEA6420_line[video_audio_connect[mxb->cur_input]][0]);
466 mxb->tea6420_2->driver->command(mxb->tea6420_2, TEA6420_SWITCH, 434 tea6420_2_call(mxb, audio, s_routing,
467 &TEA6420_line[video_audio_connect[mxb->cur_input]][1]); 435 &TEA6420_line[video_audio_connect[mxb->cur_input]][1]);
468 } else { 436 } else {
469 mxb->tea6420_1->driver->command(mxb->tea6420_1, TEA6420_SWITCH, 437 tea6420_1_call(mxb, audio, s_routing,
470 &TEA6420_line[6][0]); 438 &TEA6420_line[6][0]);
471 mxb->tea6420_2->driver->command(mxb->tea6420_2, TEA6420_SWITCH, 439 tea6420_2_call(mxb, audio, s_routing,
472 &TEA6420_line[6][1]); 440 &TEA6420_line[6][1]);
473 } 441 }
474 DEB_EE(("VIDIOC_S_CTRL, V4L2_CID_AUDIO_MUTE: %d.\n", vc->value)); 442 DEB_EE(("VIDIOC_S_CTRL, V4L2_CID_AUDIO_MUTE: %d.\n", vc->value));
@@ -499,7 +467,6 @@ static int vidioc_s_input(struct file *file, void *fh, unsigned int input)
499{ 467{
500 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev; 468 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
501 struct mxb *mxb = (struct mxb *)dev->ext_priv; 469 struct mxb *mxb = (struct mxb *)dev->ext_priv;
502 struct tea6415c_multiplex vm;
503 struct v4l2_routing route; 470 struct v4l2_routing route;
504 int i = 0; 471 int i = 0;
505 472
@@ -518,16 +485,16 @@ static int vidioc_s_input(struct file *file, void *fh, unsigned int input)
518 switch (input) { 485 switch (input) {
519 case TUNER: 486 case TUNER:
520 i = SAA7115_COMPOSITE0; 487 i = SAA7115_COMPOSITE0;
521 vm.in = 3; 488 route.input = 3;
522 vm.out = 17; 489 route.output = 17;
523 490
524 if (mxb->tea6415c->driver->command(mxb->tea6415c, TEA6415C_SWITCH, &vm)) { 491 if (tea6415c_call(mxb, video, s_routing, &route)) {
525 printk(KERN_ERR "VIDIOC_S_INPUT: could not address tea6415c #1\n"); 492 printk(KERN_ERR "VIDIOC_S_INPUT: could not address tea6415c #1\n");
526 return -EFAULT; 493 return -EFAULT;
527 } 494 }
528 /* connect tuner-output always to multicable */ 495 /* connect tuner-output always to multicable */
529 vm.in = 3; 496 route.input = 3;
530 vm.out = 13; 497 route.output = 13;
531 break; 498 break;
532 case AUX3_YC: 499 case AUX3_YC:
533 /* nothing to be done here. aux3_yc is 500 /* nothing to be done here. aux3_yc is
@@ -541,8 +508,8 @@ static int vidioc_s_input(struct file *file, void *fh, unsigned int input)
541 break; 508 break;
542 case AUX1: 509 case AUX1:
543 i = SAA7115_COMPOSITE0; 510 i = SAA7115_COMPOSITE0;
544 vm.in = 1; 511 route.input = 1;
545 vm.out = 17; 512 route.output = 17;
546 break; 513 break;
547 } 514 }
548 515
@@ -550,7 +517,7 @@ static int vidioc_s_input(struct file *file, void *fh, unsigned int input)
550 switch (input) { 517 switch (input) {
551 case TUNER: 518 case TUNER:
552 case AUX1: 519 case AUX1:
553 if (mxb->tea6415c->driver->command(mxb->tea6415c, TEA6415C_SWITCH, &vm)) { 520 if (tea6415c_call(mxb, video, s_routing, &route)) {
554 printk(KERN_ERR "VIDIOC_S_INPUT: could not address tea6415c #3\n"); 521 printk(KERN_ERR "VIDIOC_S_INPUT: could not address tea6415c #3\n");
555 return -EFAULT; 522 return -EFAULT;
556 } 523 }
@@ -562,14 +529,14 @@ static int vidioc_s_input(struct file *file, void *fh, unsigned int input)
562 /* switch video in saa7111a */ 529 /* switch video in saa7111a */
563 route.input = i; 530 route.input = i;
564 route.output = 0; 531 route.output = 0;
565 if (mxb->saa7111a->driver->command(mxb->saa7111a, VIDIOC_INT_S_VIDEO_ROUTING, &route)) 532 if (saa7111a_call(mxb, video, s_routing, &route))
566 printk(KERN_ERR "VIDIOC_S_INPUT: could not address saa7111a #1.\n"); 533 printk(KERN_ERR "VIDIOC_S_INPUT: could not address saa7111a #1.\n");
567 534
568 /* switch the audio-source only if necessary */ 535 /* switch the audio-source only if necessary */
569 if (0 == mxb->cur_mute) { 536 if (0 == mxb->cur_mute) {
570 mxb->tea6420_1->driver->command(mxb->tea6420_1, TEA6420_SWITCH, 537 tea6420_1_call(mxb, audio, s_routing,
571 &TEA6420_line[video_audio_connect[input]][0]); 538 &TEA6420_line[video_audio_connect[input]][0]);
572 mxb->tea6420_2->driver->command(mxb->tea6420_2, TEA6420_SWITCH, 539 tea6420_2_call(mxb, audio, s_routing,
573 &TEA6420_line[video_audio_connect[input]][1]); 540 &TEA6420_line[video_audio_connect[input]][1]);
574 } 541 }
575 542
@@ -589,14 +556,12 @@ static int vidioc_g_tuner(struct file *file, void *fh, struct v4l2_tuner *t)
589 DEB_EE(("VIDIOC_G_TUNER: %d\n", t->index)); 556 DEB_EE(("VIDIOC_G_TUNER: %d\n", t->index));
590 557
591 memset(t, 0, sizeof(*t)); 558 memset(t, 0, sizeof(*t));
592 i2c_clients_command(&mxb->i2c_adapter, VIDIOC_G_TUNER, t);
593
594 strlcpy(t->name, "TV Tuner", sizeof(t->name)); 559 strlcpy(t->name, "TV Tuner", sizeof(t->name));
595 t->type = V4L2_TUNER_ANALOG_TV; 560 t->type = V4L2_TUNER_ANALOG_TV;
596 t->capability = V4L2_TUNER_CAP_NORM | V4L2_TUNER_CAP_STEREO | 561 t->capability = V4L2_TUNER_CAP_NORM | V4L2_TUNER_CAP_STEREO |
597 V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2 | V4L2_TUNER_CAP_SAP; 562 V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2 | V4L2_TUNER_CAP_SAP;
598 t->audmode = mxb->cur_mode; 563 t->audmode = mxb->cur_mode;
599 return 0; 564 return call_all(dev, tuner, g_tuner, t);
600} 565}
601 566
602static int vidioc_s_tuner(struct file *file, void *fh, struct v4l2_tuner *t) 567static int vidioc_s_tuner(struct file *file, void *fh, struct v4l2_tuner *t)
@@ -610,8 +575,7 @@ static int vidioc_s_tuner(struct file *file, void *fh, struct v4l2_tuner *t)
610 } 575 }
611 576
612 mxb->cur_mode = t->audmode; 577 mxb->cur_mode = t->audmode;
613 i2c_clients_command(&mxb->i2c_adapter, VIDIOC_S_TUNER, t); 578 return call_all(dev, tuner, s_tuner, t);
614 return 0;
615} 579}
616 580
617static int vidioc_g_frequency(struct file *file, void *fh, struct v4l2_frequency *f) 581static int vidioc_g_frequency(struct file *file, void *fh, struct v4l2_frequency *f)
@@ -652,7 +616,7 @@ static int vidioc_s_frequency(struct file *file, void *fh, struct v4l2_frequency
652 DEB_EE(("VIDIOC_S_FREQUENCY: freq:0x%08x.\n", mxb->cur_freq.frequency)); 616 DEB_EE(("VIDIOC_S_FREQUENCY: freq:0x%08x.\n", mxb->cur_freq.frequency));
653 617
654 /* tune in desired frequency */ 618 /* tune in desired frequency */
655 mxb->tuner->driver->command(mxb->tuner, VIDIOC_S_FREQUENCY, &mxb->cur_freq); 619 tuner_call(mxb, tuner, s_frequency, &mxb->cur_freq);
656 620
657 /* hack: changing the frequency should invalidate the vbi-counter (=> alevt) */ 621 /* hack: changing the frequency should invalidate the vbi-counter (=> alevt) */
658 spin_lock(&dev->slock); 622 spin_lock(&dev->slock);
@@ -687,19 +651,15 @@ static int vidioc_s_audio(struct file *file, void *fh, struct v4l2_audio *a)
687static int vidioc_g_register(struct file *file, void *fh, struct v4l2_dbg_register *reg) 651static int vidioc_g_register(struct file *file, void *fh, struct v4l2_dbg_register *reg)
688{ 652{
689 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev; 653 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
690 struct mxb *mxb = (struct mxb *)dev->ext_priv;
691 654
692 i2c_clients_command(&mxb->i2c_adapter, VIDIOC_DBG_G_REGISTER, reg); 655 return call_all(dev, core, g_register, reg);
693 return 0;
694} 656}
695 657
696static int vidioc_s_register(struct file *file, void *fh, struct v4l2_dbg_register *reg) 658static int vidioc_s_register(struct file *file, void *fh, struct v4l2_dbg_register *reg)
697{ 659{
698 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev; 660 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
699 struct mxb *mxb = (struct mxb *)dev->ext_priv;
700 661
701 i2c_clients_command(&mxb->i2c_adapter, VIDIOC_DBG_S_REGISTER, reg); 662 return call_all(dev, core, s_register, reg);
702 return 0;
703} 663}
704#endif 664#endif
705 665
@@ -720,8 +680,8 @@ static long vidioc_default(struct file *file, void *fh, int cmd, void *arg)
720 680
721 DEB_EE(("MXB_S_AUDIO_CD: i:%d.\n", i)); 681 DEB_EE(("MXB_S_AUDIO_CD: i:%d.\n", i));
722 682
723 mxb->tea6420_1->driver->command(mxb->tea6420_1, TEA6420_SWITCH, &TEA6420_cd[i][0]); 683 tea6420_1_call(mxb, audio, s_routing, &TEA6420_cd[i][0]);
724 mxb->tea6420_2->driver->command(mxb->tea6420_2, TEA6420_SWITCH, &TEA6420_cd[i][1]); 684 tea6420_2_call(mxb, audio, s_routing, &TEA6420_cd[i][1]);
725 685
726 return 0; 686 return 0;
727 } 687 }
@@ -735,8 +695,8 @@ static long vidioc_default(struct file *file, void *fh, int cmd, void *arg)
735 } 695 }
736 696
737 DEB_EE(("MXB_S_AUDIO_LINE: i:%d.\n", i)); 697 DEB_EE(("MXB_S_AUDIO_LINE: i:%d.\n", i));
738 mxb->tea6420_1->driver->command(mxb->tea6420_1, TEA6420_SWITCH, &TEA6420_line[i][0]); 698 tea6420_1_call(mxb, audio, s_routing, &TEA6420_line[i][0]);
739 mxb->tea6420_2->driver->command(mxb->tea6420_2, TEA6420_SWITCH, &TEA6420_line[i][1]); 699 tea6420_2_call(mxb, audio, s_routing, &TEA6420_line[i][1]);
740 700
741 return 0; 701 return 0;
742 } 702 }
@@ -791,13 +751,6 @@ static int mxb_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_data
791 } 751 }
792 } 752 }
793 753
794 i2c_use_client(mxb->tea6420_1);
795 i2c_use_client(mxb->tea6420_2);
796 i2c_use_client(mxb->tea6415c);
797 i2c_use_client(mxb->tda9840);
798 i2c_use_client(mxb->saa7111a);
799 i2c_use_client(mxb->tuner);
800
801 printk("mxb: found Multimedia eXtension Board #%d.\n", mxb_num); 754 printk("mxb: found Multimedia eXtension Board #%d.\n", mxb_num);
802 755
803 mxb_num++; 756 mxb_num++;
@@ -811,13 +764,6 @@ static int mxb_detach(struct saa7146_dev *dev)
811 764
812 DEB_EE(("dev:%p\n", dev)); 765 DEB_EE(("dev:%p\n", dev));
813 766
814 i2c_release_client(mxb->tea6420_1);
815 i2c_release_client(mxb->tea6420_2);
816 i2c_release_client(mxb->tea6415c);
817 i2c_release_client(mxb->tda9840);
818 i2c_release_client(mxb->saa7111a);
819 i2c_release_client(mxb->tuner);
820
821 saa7146_unregister_device(&mxb->video_dev,dev); 767 saa7146_unregister_device(&mxb->video_dev,dev);
822 if (MXB_BOARD_CAN_DO_VBI(dev)) 768 if (MXB_BOARD_CAN_DO_VBI(dev))
823 saa7146_unregister_device(&mxb->vbi_dev, dev); 769 saa7146_unregister_device(&mxb->vbi_dev, dev);
@@ -834,8 +780,6 @@ static int mxb_detach(struct saa7146_dev *dev)
834static int std_callback(struct saa7146_dev *dev, struct saa7146_standard *standard) 780static int std_callback(struct saa7146_dev *dev, struct saa7146_standard *standard)
835{ 781{
836 struct mxb *mxb = (struct mxb *)dev->ext_priv; 782 struct mxb *mxb = (struct mxb *)dev->ext_priv;
837 int zero = 0;
838 int one = 1;
839 783
840 if (V4L2_STD_PAL_I == standard->id) { 784 if (V4L2_STD_PAL_I == standard->id) {
841 v4l2_std_id std = V4L2_STD_PAL_I; 785 v4l2_std_id std = V4L2_STD_PAL_I;
@@ -844,8 +788,8 @@ static int std_callback(struct saa7146_dev *dev, struct saa7146_standard *standa
844 /* set the 7146 gpio register -- I don't know what this does exactly */ 788 /* set the 7146 gpio register -- I don't know what this does exactly */
845 saa7146_write(dev, GPIO_CTRL, 0x00404050); 789 saa7146_write(dev, GPIO_CTRL, 0x00404050);
846 /* unset the 7111 gpio register -- I don't know what this does exactly */ 790 /* unset the 7111 gpio register -- I don't know what this does exactly */
847 mxb->saa7111a->driver->command(mxb->saa7111a, VIDIOC_INT_S_GPIO, &zero); 791 saa7111a_call(mxb, core, s_gpio, 0);
848 mxb->tuner->driver->command(mxb->tuner, VIDIOC_S_STD, &std); 792 tuner_call(mxb, tuner, s_std, std);
849 } else { 793 } else {
850 v4l2_std_id std = V4L2_STD_PAL_BG; 794 v4l2_std_id std = V4L2_STD_PAL_BG;
851 795
@@ -853,8 +797,8 @@ static int std_callback(struct saa7146_dev *dev, struct saa7146_standard *standa
853 /* set the 7146 gpio register -- I don't know what this does exactly */ 797 /* set the 7146 gpio register -- I don't know what this does exactly */
854 saa7146_write(dev, GPIO_CTRL, 0x00404050); 798 saa7146_write(dev, GPIO_CTRL, 0x00404050);
855 /* set the 7111 gpio register -- I don't know what this does exactly */ 799 /* set the 7111 gpio register -- I don't know what this does exactly */
856 mxb->saa7111a->driver->command(mxb->saa7111a, VIDIOC_INT_S_GPIO, &one); 800 saa7111a_call(mxb, core, s_gpio, 1);
857 mxb->tuner->driver->command(mxb->tuner, VIDIOC_S_STD, &std); 801 tuner_call(mxb, tuner, s_std, std);
858 } 802 }
859 return 0; 803 return 0;
860} 804}
diff --git a/drivers/media/video/saa5246a.c b/drivers/media/video/saa5246a.c
index 8f117bd50b8..da47b2f0528 100644
--- a/drivers/media/video/saa5246a.c
+++ b/drivers/media/video/saa5246a.c
@@ -46,10 +46,11 @@
46#include <linux/smp_lock.h> 46#include <linux/smp_lock.h>
47#include <linux/mutex.h> 47#include <linux/mutex.h>
48#include <linux/videotext.h> 48#include <linux/videotext.h>
49#include <linux/videodev.h> 49#include <linux/videodev2.h>
50#include <media/v4l2-common.h> 50#include <media/v4l2-device.h>
51#include <media/v4l2-chip-ident.h>
51#include <media/v4l2-ioctl.h> 52#include <media/v4l2-ioctl.h>
52#include <media/v4l2-i2c-drv-legacy.h> 53#include <media/v4l2-i2c-drv.h>
53 54
54MODULE_AUTHOR("Michael Geng <linux@MichaelGeng.de>"); 55MODULE_AUTHOR("Michael Geng <linux@MichaelGeng.de>");
55MODULE_DESCRIPTION("Philips SAA5246A, SAA5281 Teletext decoder driver"); 56MODULE_DESCRIPTION("Philips SAA5246A, SAA5281 Teletext decoder driver");
@@ -388,13 +389,19 @@ MODULE_LICENSE("GPL");
388 389
389struct saa5246a_device 390struct saa5246a_device
390{ 391{
392 struct v4l2_subdev sd;
393 struct video_device *vdev;
391 u8 pgbuf[NUM_DAUS][VTX_VIRTUALSIZE]; 394 u8 pgbuf[NUM_DAUS][VTX_VIRTUALSIZE];
392 int is_searching[NUM_DAUS]; 395 int is_searching[NUM_DAUS];
393 struct i2c_client *client;
394 unsigned long in_use; 396 unsigned long in_use;
395 struct mutex lock; 397 struct mutex lock;
396}; 398};
397 399
400static inline struct saa5246a_device *to_dev(struct v4l2_subdev *sd)
401{
402 return container_of(sd, struct saa5246a_device, sd);
403}
404
398static struct video_device saa_template; /* Declared near bottom */ 405static struct video_device saa_template; /* Declared near bottom */
399 406
400/* 407/*
@@ -403,12 +410,13 @@ static struct video_device saa_template; /* Declared near bottom */
403 410
404static int i2c_sendbuf(struct saa5246a_device *t, int reg, int count, u8 *data) 411static int i2c_sendbuf(struct saa5246a_device *t, int reg, int count, u8 *data)
405{ 412{
413 struct i2c_client *client = v4l2_get_subdevdata(&t->sd);
406 char buf[64]; 414 char buf[64];
407 415
408 buf[0] = reg; 416 buf[0] = reg;
409 memcpy(buf+1, data, count); 417 memcpy(buf+1, data, count);
410 418
411 if(i2c_master_send(t->client, buf, count+1)==count+1) 419 if (i2c_master_send(client, buf, count + 1) == count + 1)
412 return 0; 420 return 0;
413 return -1; 421 return -1;
414} 422}
@@ -436,7 +444,9 @@ static int i2c_senddata(struct saa5246a_device *t, ...)
436 */ 444 */
437static int i2c_getdata(struct saa5246a_device *t, int count, u8 *buf) 445static int i2c_getdata(struct saa5246a_device *t, int count, u8 *buf)
438{ 446{
439 if(i2c_master_recv(t->client, buf, count)!=count) 447 struct i2c_client *client = v4l2_get_subdevdata(&t->sd);
448
449 if (i2c_master_recv(client, buf, count) != count)
440 return -1; 450 return -1;
441 return 0; 451 return 0;
442} 452}
@@ -961,9 +971,6 @@ static int saa5246a_open(struct file *file)
961{ 971{
962 struct saa5246a_device *t = video_drvdata(file); 972 struct saa5246a_device *t = video_drvdata(file);
963 973
964 if (t->client == NULL)
965 return -ENODEV;
966
967 if (test_and_set_bit(0, &t->in_use)) 974 if (test_and_set_bit(0, &t->in_use))
968 return -EBUSY; 975 return -EBUSY;
969 976
@@ -1033,18 +1040,29 @@ static struct video_device saa_template =
1033 .minor = -1, 1040 .minor = -1,
1034}; 1041};
1035 1042
1036/* Addresses to scan */ 1043static int saa5246a_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
1037static unsigned short normal_i2c[] = { 0x22 >> 1, I2C_CLIENT_END }; 1044{
1045 struct i2c_client *client = v4l2_get_subdevdata(sd);
1046
1047 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_SAA5246A, 0);
1048}
1049
1050static const struct v4l2_subdev_core_ops saa5246a_core_ops = {
1051 .g_chip_ident = saa5246a_g_chip_ident,
1052};
1053
1054static const struct v4l2_subdev_ops saa5246a_ops = {
1055 .core = &saa5246a_core_ops,
1056};
1038 1057
1039I2C_CLIENT_INSMOD;
1040 1058
1041static int saa5246a_probe(struct i2c_client *client, 1059static int saa5246a_probe(struct i2c_client *client,
1042 const struct i2c_device_id *id) 1060 const struct i2c_device_id *id)
1043{ 1061{
1044 int pgbuf; 1062 int pgbuf;
1045 int err; 1063 int err;
1046 struct video_device *vd;
1047 struct saa5246a_device *t; 1064 struct saa5246a_device *t;
1065 struct v4l2_subdev *sd;
1048 1066
1049 v4l_info(client, "chip found @ 0x%x (%s)\n", 1067 v4l_info(client, "chip found @ 0x%x (%s)\n",
1050 client->addr << 1, client->adapter->name); 1068 client->addr << 1, client->adapter->name);
@@ -1053,40 +1071,43 @@ static int saa5246a_probe(struct i2c_client *client,
1053 t = kzalloc(sizeof(*t), GFP_KERNEL); 1071 t = kzalloc(sizeof(*t), GFP_KERNEL);
1054 if (t == NULL) 1072 if (t == NULL)
1055 return -ENOMEM; 1073 return -ENOMEM;
1074 sd = &t->sd;
1075 v4l2_i2c_subdev_init(sd, client, &saa5246a_ops);
1056 mutex_init(&t->lock); 1076 mutex_init(&t->lock);
1057 1077
1058 /* Now create a video4linux device */ 1078 /* Now create a video4linux device */
1059 vd = video_device_alloc(); 1079 t->vdev = video_device_alloc();
1060 if (vd == NULL) { 1080 if (t->vdev == NULL) {
1061 kfree(t); 1081 kfree(t);
1062 return -ENOMEM; 1082 return -ENOMEM;
1063 } 1083 }
1064 i2c_set_clientdata(client, vd); 1084 memcpy(t->vdev, &saa_template, sizeof(*t->vdev));
1065 memcpy(vd, &saa_template, sizeof(*vd));
1066 1085
1067 for (pgbuf = 0; pgbuf < NUM_DAUS; pgbuf++) { 1086 for (pgbuf = 0; pgbuf < NUM_DAUS; pgbuf++) {
1068 memset(t->pgbuf[pgbuf], ' ', sizeof(t->pgbuf[0])); 1087 memset(t->pgbuf[pgbuf], ' ', sizeof(t->pgbuf[0]));
1069 t->is_searching[pgbuf] = false; 1088 t->is_searching[pgbuf] = false;
1070 } 1089 }
1071 video_set_drvdata(vd, t); 1090 video_set_drvdata(t->vdev, t);
1072 1091
1073 /* Register it */ 1092 /* Register it */
1074 err = video_register_device(vd, VFL_TYPE_VTX, -1); 1093 err = video_register_device(t->vdev, VFL_TYPE_VTX, -1);
1075 if (err < 0) { 1094 if (err < 0) {
1076 kfree(t); 1095 kfree(t);
1077 video_device_release(vd); 1096 video_device_release(t->vdev);
1097 t->vdev = NULL;
1078 return err; 1098 return err;
1079 } 1099 }
1080 t->client = client;
1081 return 0; 1100 return 0;
1082} 1101}
1083 1102
1084static int saa5246a_remove(struct i2c_client *client) 1103static int saa5246a_remove(struct i2c_client *client)
1085{ 1104{
1086 struct video_device *vd = i2c_get_clientdata(client); 1105 struct v4l2_subdev *sd = i2c_get_clientdata(client);
1106 struct saa5246a_device *t = to_dev(sd);
1087 1107
1088 video_unregister_device(vd); 1108 video_unregister_device(t->vdev);
1089 kfree(video_get_drvdata(vd)); 1109 v4l2_device_unregister_subdev(sd);
1110 kfree(t);
1090 return 0; 1111 return 0;
1091} 1112}
1092 1113
diff --git a/drivers/media/video/saa5249.c b/drivers/media/video/saa5249.c
index 81e666df0db..48b27fe4808 100644
--- a/drivers/media/video/saa5249.c
+++ b/drivers/media/video/saa5249.c
@@ -50,15 +50,17 @@
50#include <linux/mutex.h> 50#include <linux/mutex.h>
51#include <linux/delay.h> 51#include <linux/delay.h>
52#include <linux/videotext.h> 52#include <linux/videotext.h>
53#include <linux/videodev.h> 53#include <linux/videodev2.h>
54#include <media/v4l2-common.h> 54#include <media/v4l2-device.h>
55#include <media/v4l2-chip-ident.h>
55#include <media/v4l2-ioctl.h> 56#include <media/v4l2-ioctl.h>
56#include <media/v4l2-i2c-drv-legacy.h> 57#include <media/v4l2-i2c-drv.h>
57 58
58MODULE_AUTHOR("Michael Geng <linux@MichaelGeng.de>"); 59MODULE_AUTHOR("Michael Geng <linux@MichaelGeng.de>");
59MODULE_DESCRIPTION("Philips SAA5249 Teletext decoder driver"); 60MODULE_DESCRIPTION("Philips SAA5249 Teletext decoder driver");
60MODULE_LICENSE("GPL"); 61MODULE_LICENSE("GPL");
61 62
63
62#define VTX_VER_MAJ 1 64#define VTX_VER_MAJ 1
63#define VTX_VER_MIN 8 65#define VTX_VER_MIN 8
64 66
@@ -95,17 +97,23 @@ typedef struct {
95 97
96struct saa5249_device 98struct saa5249_device
97{ 99{
100 struct v4l2_subdev sd;
101 struct video_device *vdev;
98 vdau_t vdau[NUM_DAUS]; /* Data for virtual DAUs (the 5249 only has one */ 102 vdau_t vdau[NUM_DAUS]; /* Data for virtual DAUs (the 5249 only has one */
99 /* real DAU, so we have to simulate some more) */ 103 /* real DAU, so we have to simulate some more) */
100 int vtx_use_count; 104 int vtx_use_count;
101 int is_searching[NUM_DAUS]; 105 int is_searching[NUM_DAUS];
102 int disp_mode; 106 int disp_mode;
103 int virtual_mode; 107 int virtual_mode;
104 struct i2c_client *client;
105 unsigned long in_use; 108 unsigned long in_use;
106 struct mutex lock; 109 struct mutex lock;
107}; 110};
108 111
112static inline struct saa5249_device *to_dev(struct v4l2_subdev *sd)
113{
114 return container_of(sd, struct saa5249_device, sd);
115}
116
109 117
110#define CCTWR 34 /* I²C write/read-address of vtx-chip */ 118#define CCTWR 34 /* I²C write/read-address of vtx-chip */
111#define CCTRD 35 119#define CCTRD 35
@@ -147,12 +155,13 @@ static void jdelay(unsigned long delay)
147 155
148static int i2c_sendbuf(struct saa5249_device *t, int reg, int count, u8 *data) 156static int i2c_sendbuf(struct saa5249_device *t, int reg, int count, u8 *data)
149{ 157{
158 struct i2c_client *client = v4l2_get_subdevdata(&t->sd);
150 char buf[64]; 159 char buf[64];
151 160
152 buf[0] = reg; 161 buf[0] = reg;
153 memcpy(buf+1, data, count); 162 memcpy(buf+1, data, count);
154 163
155 if (i2c_master_send(t->client, buf, count + 1) == count + 1) 164 if (i2c_master_send(client, buf, count + 1) == count + 1)
156 return 0; 165 return 0;
157 return -1; 166 return -1;
158} 167}
@@ -180,7 +189,9 @@ static int i2c_senddata(struct saa5249_device *t, ...)
180 189
181static int i2c_getdata(struct saa5249_device *t, int count, u8 *buf) 190static int i2c_getdata(struct saa5249_device *t, int count, u8 *buf)
182{ 191{
183 if(i2c_master_recv(t->client, buf, count)!=count) 192 struct i2c_client *client = v4l2_get_subdevdata(&t->sd);
193
194 if (i2c_master_recv(client, buf, count) != count)
184 return -1; 195 return -1;
185 return 0; 196 return 0;
186} 197}
@@ -497,9 +508,6 @@ static int saa5249_open(struct file *file)
497 struct saa5249_device *t = video_drvdata(file); 508 struct saa5249_device *t = video_drvdata(file);
498 int pgbuf; 509 int pgbuf;
499 510
500 if (t->client == NULL)
501 return -ENODEV;
502
503 if (test_and_set_bit(0, &t->in_use)) 511 if (test_and_set_bit(0, &t->in_use))
504 return -EBUSY; 512 return -EBUSY;
505 513
@@ -553,18 +561,28 @@ static struct video_device saa_template =
553 .release = video_device_release, 561 .release = video_device_release,
554}; 562};
555 563
556/* Addresses to scan */ 564static int saa5249_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
557static unsigned short normal_i2c[] = { 0x22 >> 1, I2C_CLIENT_END }; 565{
566 struct i2c_client *client = v4l2_get_subdevdata(sd);
567
568 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_SAA5249, 0);
569}
558 570
559I2C_CLIENT_INSMOD; 571static const struct v4l2_subdev_core_ops saa5249_core_ops = {
572 .g_chip_ident = saa5249_g_chip_ident,
573};
574
575static const struct v4l2_subdev_ops saa5249_ops = {
576 .core = &saa5249_core_ops,
577};
560 578
561static int saa5249_probe(struct i2c_client *client, 579static int saa5249_probe(struct i2c_client *client,
562 const struct i2c_device_id *id) 580 const struct i2c_device_id *id)
563{ 581{
564 int pgbuf; 582 int pgbuf;
565 int err; 583 int err;
566 struct video_device *vd;
567 struct saa5249_device *t; 584 struct saa5249_device *t;
585 struct v4l2_subdev *sd;
568 586
569 v4l_info(client, "chip found @ 0x%x (%s)\n", 587 v4l_info(client, "chip found @ 0x%x (%s)\n",
570 client->addr << 1, client->adapter->name); 588 client->addr << 1, client->adapter->name);
@@ -573,16 +591,17 @@ static int saa5249_probe(struct i2c_client *client,
573 t = kzalloc(sizeof(*t), GFP_KERNEL); 591 t = kzalloc(sizeof(*t), GFP_KERNEL);
574 if (t == NULL) 592 if (t == NULL)
575 return -ENOMEM; 593 return -ENOMEM;
594 sd = &t->sd;
595 v4l2_i2c_subdev_init(sd, client, &saa5249_ops);
576 mutex_init(&t->lock); 596 mutex_init(&t->lock);
577 597
578 /* Now create a video4linux device */ 598 /* Now create a video4linux device */
579 vd = kmalloc(sizeof(struct video_device), GFP_KERNEL); 599 t->vdev = video_device_alloc();
580 if (vd == NULL) { 600 if (t->vdev == NULL) {
581 kfree(client); 601 kfree(client);
582 return -ENOMEM; 602 return -ENOMEM;
583 } 603 }
584 i2c_set_clientdata(client, vd); 604 memcpy(t->vdev, &saa_template, sizeof(*t->vdev));
585 memcpy(vd, &saa_template, sizeof(*vd));
586 605
587 for (pgbuf = 0; pgbuf < NUM_DAUS; pgbuf++) { 606 for (pgbuf = 0; pgbuf < NUM_DAUS; pgbuf++) {
588 memset(t->vdau[pgbuf].pgbuf, ' ', sizeof(t->vdau[0].pgbuf)); 607 memset(t->vdau[pgbuf].pgbuf, ' ', sizeof(t->vdau[0].pgbuf));
@@ -593,26 +612,27 @@ static int saa5249_probe(struct i2c_client *client,
593 t->vdau[pgbuf].stopped = true; 612 t->vdau[pgbuf].stopped = true;
594 t->is_searching[pgbuf] = false; 613 t->is_searching[pgbuf] = false;
595 } 614 }
596 video_set_drvdata(vd, t); 615 video_set_drvdata(t->vdev, t);
597 616
598 /* Register it */ 617 /* Register it */
599 err = video_register_device(vd, VFL_TYPE_VTX, -1); 618 err = video_register_device(t->vdev, VFL_TYPE_VTX, -1);
600 if (err < 0) { 619 if (err < 0) {
601 kfree(t); 620 kfree(t);
602 kfree(vd); 621 video_device_release(t->vdev);
622 t->vdev = NULL;
603 return err; 623 return err;
604 } 624 }
605 t->client = client;
606 return 0; 625 return 0;
607} 626}
608 627
609static int saa5249_remove(struct i2c_client *client) 628static int saa5249_remove(struct i2c_client *client)
610{ 629{
611 struct video_device *vd = i2c_get_clientdata(client); 630 struct v4l2_subdev *sd = i2c_get_clientdata(client);
631 struct saa5249_device *t = to_dev(sd);
612 632
613 video_unregister_device(vd); 633 video_unregister_device(t->vdev);
614 kfree(video_get_drvdata(vd)); 634 v4l2_device_unregister_subdev(sd);
615 kfree(vd); 635 kfree(t);
616 return 0; 636 return 0;
617} 637}
618 638
diff --git a/drivers/media/video/tda9840.c b/drivers/media/video/tda9840.c
index ae46a28dd05..fe1158094c2 100644
--- a/drivers/media/video/tda9840.c
+++ b/drivers/media/video/tda9840.c
@@ -30,8 +30,8 @@
30#include <linux/ioctl.h> 30#include <linux/ioctl.h>
31#include <linux/i2c.h> 31#include <linux/i2c.h>
32#include <media/v4l2-device.h> 32#include <media/v4l2-device.h>
33#include <media/v4l2-i2c-drv-legacy.h> 33#include <media/v4l2-chip-ident.h>
34#include "tda9840.h" 34#include <media/v4l2-i2c-drv.h>
35 35
36MODULE_AUTHOR("Michael Hunold <michael@mihu.de>"); 36MODULE_AUTHOR("Michael Hunold <michael@mihu.de>");
37MODULE_DESCRIPTION("tda9840 driver"); 37MODULE_DESCRIPTION("tda9840 driver");
@@ -56,11 +56,6 @@ MODULE_PARM_DESC(debug, "Debug level (0-1)");
56#define TDA9840_SET_BOTH_R 0x16 56#define TDA9840_SET_BOTH_R 0x16
57#define TDA9840_SET_EXTERNAL 0x7a 57#define TDA9840_SET_EXTERNAL 0x7a
58 58
59/* addresses to scan, found only at 0x42 (7-Bit) */
60static unsigned short normal_i2c[] = { I2C_ADDR_TDA9840, I2C_CLIENT_END };
61
62/* magic definition of all other variables and things */
63I2C_CLIENT_INSMOD;
64 59
65static void tda9840_write(struct v4l2_subdev *sd, u8 reg, u8 val) 60static void tda9840_write(struct v4l2_subdev *sd, u8 reg, u8 val)
66{ 61{
@@ -137,60 +132,17 @@ static int tda9840_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *t)
137 return 0; 132 return 0;
138} 133}
139 134
140static long tda9840_ioctl(struct v4l2_subdev *sd, unsigned cmd, void *arg) 135static int tda9840_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
141{ 136{
142 int byte; 137 struct i2c_client *client = v4l2_get_subdevdata(sd);
143
144 switch (cmd) {
145 case TDA9840_LEVEL_ADJUST:
146 byte = *(int *)arg;
147 v4l2_dbg(1, debug, sd, "TDA9840_LEVEL_ADJUST: %d\n", byte);
148
149 /* check for correct range */
150 if (byte > 25 || byte < -20)
151 return -EINVAL;
152
153 /* calculate actual value to set, see specs, page 18 */
154 byte /= 5;
155 if (0 < byte)
156 byte += 0x8;
157 else
158 byte = -byte;
159 tda9840_write(sd, LEVEL_ADJUST, byte);
160 break;
161
162 case TDA9840_STEREO_ADJUST:
163 byte = *(int *)arg;
164 v4l2_dbg(1, debug, sd, "TDA9840_STEREO_ADJUST: %d\n", byte);
165
166 /* check for correct range */
167 if (byte > 25 || byte < -24)
168 return -EINVAL;
169
170 /* calculate actual value to set */
171 byte /= 5;
172 if (0 < byte)
173 byte += 0x20;
174 else
175 byte = -byte;
176
177 tda9840_write(sd, STEREO_ADJUST, byte);
178 break;
179 default:
180 return -ENOIOCTLCMD;
181 }
182 return 0;
183}
184 138
185static int tda9840_command(struct i2c_client *client, unsigned cmd, void *arg) 139 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_TDA9840, 0);
186{
187 return v4l2_subdev_command(i2c_get_clientdata(client), cmd, arg);
188} 140}
189 141
190/* ----------------------------------------------------------------------- */ 142/* ----------------------------------------------------------------------- */
191 143
192static const struct v4l2_subdev_core_ops tda9840_core_ops = { 144static const struct v4l2_subdev_core_ops tda9840_core_ops = {
193 .ioctl = tda9840_ioctl, 145 .g_chip_ident = tda9840_g_chip_ident,
194}; 146};
195 147
196static const struct v4l2_subdev_tuner_ops tda9840_tuner_ops = { 148static const struct v4l2_subdev_tuner_ops tda9840_tuner_ops = {
@@ -209,8 +161,6 @@ static int tda9840_probe(struct i2c_client *client,
209 const struct i2c_device_id *id) 161 const struct i2c_device_id *id)
210{ 162{
211 struct v4l2_subdev *sd; 163 struct v4l2_subdev *sd;
212 int result;
213 int byte;
214 164
215 /* let's see whether this adapter can support what we need */ 165 /* let's see whether this adapter can support what we need */
216 if (!i2c_check_functionality(client->adapter, 166 if (!i2c_check_functionality(client->adapter,
@@ -227,15 +177,9 @@ static int tda9840_probe(struct i2c_client *client,
227 v4l2_i2c_subdev_init(sd, client, &tda9840_ops); 177 v4l2_i2c_subdev_init(sd, client, &tda9840_ops);
228 178
229 /* set initial values for level & stereo - adjustment, mode */ 179 /* set initial values for level & stereo - adjustment, mode */
230 byte = 0; 180 tda9840_write(sd, LEVEL_ADJUST, 0);
231 result = tda9840_ioctl(sd, TDA9840_LEVEL_ADJUST, &byte); 181 tda9840_write(sd, STEREO_ADJUST, 0);
232 result |= tda9840_ioctl(sd, TDA9840_STEREO_ADJUST, &byte);
233 tda9840_write(sd, SWITCH, TDA9840_SET_STEREO); 182 tda9840_write(sd, SWITCH, TDA9840_SET_STEREO);
234 if (result) {
235 v4l2_dbg(1, debug, sd, "could not initialize tda9840\n");
236 kfree(sd);
237 return -ENODEV;
238 }
239 return 0; 183 return 0;
240} 184}
241 185
@@ -248,12 +192,7 @@ static int tda9840_remove(struct i2c_client *client)
248 return 0; 192 return 0;
249} 193}
250 194
251static int tda9840_legacy_probe(struct i2c_adapter *adapter) 195
252{
253 /* Let's see whether this is a known adapter we can attach to.
254 Prevents conflicts with tvaudio.c. */
255 return adapter->id == I2C_HW_SAA7146;
256}
257static const struct i2c_device_id tda9840_id[] = { 196static const struct i2c_device_id tda9840_id[] = {
258 { "tda9840", 0 }, 197 { "tda9840", 0 },
259 { } 198 { }
@@ -262,9 +201,7 @@ MODULE_DEVICE_TABLE(i2c, tda9840_id);
262 201
263static struct v4l2_i2c_driver_data v4l2_i2c_data = { 202static struct v4l2_i2c_driver_data v4l2_i2c_data = {
264 .name = "tda9840", 203 .name = "tda9840",
265 .command = tda9840_command,
266 .probe = tda9840_probe, 204 .probe = tda9840_probe,
267 .remove = tda9840_remove, 205 .remove = tda9840_remove,
268 .legacy_probe = tda9840_legacy_probe,
269 .id_table = tda9840_id, 206 .id_table = tda9840_id,
270}; 207};
diff --git a/drivers/media/video/tda9840.h b/drivers/media/video/tda9840.h
deleted file mode 100644
index dc12ae7caf6..00000000000
--- a/drivers/media/video/tda9840.h
+++ /dev/null
@@ -1,14 +0,0 @@
1#ifndef __INCLUDED_TDA9840__
2#define __INCLUDED_TDA9840__
3
4#define I2C_ADDR_TDA9840 0x42
5
6/* values may range between +2.5 and -2.0;
7 the value has to be multiplied with 10 */
8#define TDA9840_LEVEL_ADJUST _IOW('v',3,int)
9
10/* values may range between +2.5 and -2.4;
11 the value has to be multiplied with 10 */
12#define TDA9840_STEREO_ADJUST _IOW('v',4,int)
13
14#endif
diff --git a/drivers/media/video/tea6415c.c b/drivers/media/video/tea6415c.c
index bb9b7780c49..d61c56f42bc 100644
--- a/drivers/media/video/tea6415c.c
+++ b/drivers/media/video/tea6415c.c
@@ -32,7 +32,8 @@
32#include <linux/ioctl.h> 32#include <linux/ioctl.h>
33#include <linux/i2c.h> 33#include <linux/i2c.h>
34#include <media/v4l2-device.h> 34#include <media/v4l2-device.h>
35#include <media/v4l2-i2c-drv-legacy.h> 35#include <media/v4l2-chip-ident.h>
36#include <media/v4l2-i2c-drv.h>
36#include "tea6415c.h" 37#include "tea6415c.h"
37 38
38MODULE_AUTHOR("Michael Hunold <michael@mihu.de>"); 39MODULE_AUTHOR("Michael Hunold <michael@mihu.de>");
@@ -44,25 +45,22 @@ module_param(debug, int, 0644);
44 45
45MODULE_PARM_DESC(debug, "Debug level (0-1)"); 46MODULE_PARM_DESC(debug, "Debug level (0-1)");
46 47
47/* addresses to scan, found only at 0x03 and/or 0x43 (7-bit) */
48static unsigned short normal_i2c[] = { I2C_TEA6415C_1, I2C_TEA6415C_2, I2C_CLIENT_END };
49 48
50/* magic definition of all other variables and things */ 49/* makes a connection between the input-pin 'i' and the output-pin 'o' */
51I2C_CLIENT_INSMOD; 50static int tea6415c_s_routing(struct v4l2_subdev *sd, const struct v4l2_routing *route)
52
53/* makes a connection between the input-pin 'i' and the output-pin 'o'
54 for the tea6415c-client 'client' */
55static int switch_matrix(struct i2c_client *client, int i, int o)
56{ 51{
52 struct i2c_client *client = v4l2_get_subdevdata(sd);
57 u8 byte = 0; 53 u8 byte = 0;
54 u32 i = route->input;
55 u32 o = route->output;
58 int ret; 56 int ret;
59 57
60 v4l_dbg(1, debug, client, "i=%d, o=%d\n", i, o); 58 v4l2_dbg(1, debug, sd, "i=%d, o=%d\n", i, o);
61 59
62 /* check if the pins are valid */ 60 /* check if the pins are valid */
63 if (0 == ((1 == i || 3 == i || 5 == i || 6 == i || 8 == i || 10 == i || 20 == i || 11 == i) 61 if (0 == ((1 == i || 3 == i || 5 == i || 6 == i || 8 == i || 10 == i || 20 == i || 11 == i)
64 && (18 == o || 17 == o || 16 == o || 15 == o || 14 == o || 13 == o))) 62 && (18 == o || 17 == o || 16 == o || 15 == o || 14 == o || 13 == o)))
65 return -1; 63 return -EINVAL;
66 64
67 /* to understand this, have a look at the tea6415c-specs (p.5) */ 65 /* to understand this, have a look at the tea6415c-specs (p.5) */
68 switch (o) { 66 switch (o) {
@@ -115,37 +113,33 @@ static int switch_matrix(struct i2c_client *client, int i, int o)
115 113
116 ret = i2c_smbus_write_byte(client, byte); 114 ret = i2c_smbus_write_byte(client, byte);
117 if (ret) { 115 if (ret) {
118 v4l_dbg(1, debug, client, 116 v4l2_dbg(1, debug, sd,
119 "i2c_smbus_write_byte() failed, ret:%d\n", ret); 117 "i2c_smbus_write_byte() failed, ret:%d\n", ret);
120 return -EIO; 118 return -EIO;
121 } 119 }
122 return ret; 120 return ret;
123} 121}
124 122
125static long tea6415c_ioctl(struct v4l2_subdev *sd, unsigned cmd, void *arg) 123static int tea6415c_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
126{ 124{
127 if (cmd == TEA6415C_SWITCH) { 125 struct i2c_client *client = v4l2_get_subdevdata(sd);
128 struct i2c_client *client = v4l2_get_subdevdata(sd);
129 struct tea6415c_multiplex *v = (struct tea6415c_multiplex *)arg;
130 126
131 return switch_matrix(client, v->in, v->out); 127 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_TEA6415C, 0);
132 }
133 return -ENOIOCTLCMD;
134}
135
136static int tea6415c_command(struct i2c_client *client, unsigned cmd, void *arg)
137{
138 return v4l2_subdev_command(i2c_get_clientdata(client), cmd, arg);
139} 128}
140 129
141/* ----------------------------------------------------------------------- */ 130/* ----------------------------------------------------------------------- */
142 131
143static const struct v4l2_subdev_core_ops tea6415c_core_ops = { 132static const struct v4l2_subdev_core_ops tea6415c_core_ops = {
144 .ioctl = tea6415c_ioctl, 133 .g_chip_ident = tea6415c_g_chip_ident,
134};
135
136static const struct v4l2_subdev_video_ops tea6415c_video_ops = {
137 .s_routing = tea6415c_s_routing,
145}; 138};
146 139
147static const struct v4l2_subdev_ops tea6415c_ops = { 140static const struct v4l2_subdev_ops tea6415c_ops = {
148 .core = &tea6415c_core_ops, 141 .core = &tea6415c_core_ops,
142 .video = &tea6415c_video_ops,
149}; 143};
150 144
151/* this function is called by i2c_probe */ 145/* this function is called by i2c_probe */
@@ -176,12 +170,6 @@ static int tea6415c_remove(struct i2c_client *client)
176 return 0; 170 return 0;
177} 171}
178 172
179static int tea6415c_legacy_probe(struct i2c_adapter *adapter)
180{
181 /* Let's see whether this is a known adapter we can attach to.
182 Prevents conflicts with tvaudio.c. */
183 return adapter->id == I2C_HW_SAA7146;
184}
185 173
186static const struct i2c_device_id tea6415c_id[] = { 174static const struct i2c_device_id tea6415c_id[] = {
187 { "tea6415c", 0 }, 175 { "tea6415c", 0 },
@@ -191,9 +179,7 @@ MODULE_DEVICE_TABLE(i2c, tea6415c_id);
191 179
192static struct v4l2_i2c_driver_data v4l2_i2c_data = { 180static struct v4l2_i2c_driver_data v4l2_i2c_data = {
193 .name = "tea6415c", 181 .name = "tea6415c",
194 .command = tea6415c_command,
195 .probe = tea6415c_probe, 182 .probe = tea6415c_probe,
196 .remove = tea6415c_remove, 183 .remove = tea6415c_remove,
197 .legacy_probe = tea6415c_legacy_probe,
198 .id_table = tea6415c_id, 184 .id_table = tea6415c_id,
199}; 185};
diff --git a/drivers/media/video/tea6415c.h b/drivers/media/video/tea6415c.h
index f84ed80050b..3a47d697536 100644
--- a/drivers/media/video/tea6415c.h
+++ b/drivers/media/video/tea6415c.h
@@ -1,10 +1,6 @@
1#ifndef __INCLUDED_TEA6415C__ 1#ifndef __INCLUDED_TEA6415C__
2#define __INCLUDED_TEA6415C__ 2#define __INCLUDED_TEA6415C__
3 3
4/* possible i2c-addresses */
5#define I2C_TEA6415C_1 0x03
6#define I2C_TEA6415C_2 0x43
7
8/* the tea6415c's design is quite brain-dead. although there are 4/* the tea6415c's design is quite brain-dead. although there are
9 8 inputs and 6 outputs, these aren't enumerated in any way. because 5 8 inputs and 6 outputs, these aren't enumerated in any way. because
10 I don't want to say "connect input pin 20 to output pin 17", I define 6 I don't want to say "connect input pin 20 to output pin 17", I define
@@ -28,12 +24,4 @@
28#define TEA6415C_INPUT7 1 24#define TEA6415C_INPUT7 1
29#define TEA6415C_INPUT8 11 25#define TEA6415C_INPUT8 11
30 26
31struct tea6415c_multiplex
32{
33 int in; /* input-pin */
34 int out; /* output-pin */
35};
36
37#define TEA6415C_SWITCH _IOW('v',1,struct tea6415c_multiplex)
38
39#endif 27#endif
diff --git a/drivers/media/video/tea6420.c b/drivers/media/video/tea6420.c
index 7546509c828..34922232402 100644
--- a/drivers/media/video/tea6420.c
+++ b/drivers/media/video/tea6420.c
@@ -32,7 +32,8 @@
32#include <linux/ioctl.h> 32#include <linux/ioctl.h>
33#include <linux/i2c.h> 33#include <linux/i2c.h>
34#include <media/v4l2-device.h> 34#include <media/v4l2-device.h>
35#include <media/v4l2-i2c-drv-legacy.h> 35#include <media/v4l2-chip-ident.h>
36#include <media/v4l2-i2c-drv.h>
36#include "tea6420.h" 37#include "tea6420.h"
37 38
38MODULE_AUTHOR("Michael Hunold <michael@mihu.de>"); 39MODULE_AUTHOR("Michael Hunold <michael@mihu.de>");
@@ -44,24 +45,23 @@ module_param(debug, int, 0644);
44 45
45MODULE_PARM_DESC(debug, "Debug level (0-1)"); 46MODULE_PARM_DESC(debug, "Debug level (0-1)");
46 47
47/* addresses to scan, found only at 0x4c and/or 0x4d (7-Bit) */
48static unsigned short normal_i2c[] = { I2C_ADDR_TEA6420_1, I2C_ADDR_TEA6420_2, I2C_CLIENT_END };
49
50/* magic definition of all other variables and things */
51I2C_CLIENT_INSMOD;
52 48
53/* make a connection between the input 'i' and the output 'o' 49/* make a connection between the input 'i' and the output 'o'
54 with gain 'g' for the tea6420-client 'client' (note: i = 6 means 'mute') */ 50 with gain 'g' (note: i = 6 means 'mute') */
55static int tea6420_switch(struct i2c_client *client, int i, int o, int g) 51static int tea6420_s_routing(struct v4l2_subdev *sd, const struct v4l2_routing *route)
56{ 52{
53 struct i2c_client *client = v4l2_get_subdevdata(sd);
54 int i = route->input;
55 int o = route->output & 0xf;
56 int g = (route->output >> 4) & 0xf;
57 u8 byte; 57 u8 byte;
58 int ret; 58 int ret;
59 59
60 v4l_dbg(1, debug, client, "i=%d, o=%d, g=%d\n", i, o, g); 60 v4l2_dbg(1, debug, sd, "i=%d, o=%d, g=%d\n", i, o, g);
61 61
62 /* check if the parameters are valid */ 62 /* check if the parameters are valid */
63 if (i < 1 || i > 6 || o < 1 || o > 4 || g < 0 || g > 6 || g % 2 != 0) 63 if (i < 1 || i > 6 || o < 1 || o > 4 || g < 0 || g > 6 || g % 2 != 0)
64 return -1; 64 return -EINVAL;
65 65
66 byte = ((o - 1) << 5); 66 byte = ((o - 1) << 5);
67 byte |= (i - 1); 67 byte |= (i - 1);
@@ -83,37 +83,33 @@ static int tea6420_switch(struct i2c_client *client, int i, int o, int g)
83 83
84 ret = i2c_smbus_write_byte(client, byte); 84 ret = i2c_smbus_write_byte(client, byte);
85 if (ret) { 85 if (ret) {
86 v4l_dbg(1, debug, client, 86 v4l2_dbg(1, debug, sd,
87 "i2c_smbus_write_byte() failed, ret:%d\n", ret); 87 "i2c_smbus_write_byte() failed, ret:%d\n", ret);
88 return -EIO; 88 return -EIO;
89 } 89 }
90 return 0; 90 return 0;
91} 91}
92 92
93static long tea6420_ioctl(struct v4l2_subdev *sd, unsigned cmd, void *arg) 93static int tea6420_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
94{ 94{
95 if (cmd == TEA6420_SWITCH) { 95 struct i2c_client *client = v4l2_get_subdevdata(sd);
96 struct i2c_client *client = v4l2_get_subdevdata(sd);
97 struct tea6420_multiplex *a = (struct tea6420_multiplex *)arg;
98 96
99 return tea6420_switch(client, a->in, a->out, a->gain); 97 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_TEA6420, 0);
100 }
101 return -ENOIOCTLCMD;
102}
103
104static int tea6420_command(struct i2c_client *client, unsigned cmd, void *arg)
105{
106 return v4l2_subdev_command(i2c_get_clientdata(client), cmd, arg);
107} 98}
108 99
109/* ----------------------------------------------------------------------- */ 100/* ----------------------------------------------------------------------- */
110 101
111static const struct v4l2_subdev_core_ops tea6420_core_ops = { 102static const struct v4l2_subdev_core_ops tea6420_core_ops = {
112 .ioctl = tea6420_ioctl, 103 .g_chip_ident = tea6420_g_chip_ident,
104};
105
106static const struct v4l2_subdev_audio_ops tea6420_audio_ops = {
107 .s_routing = tea6420_s_routing,
113}; 108};
114 109
115static const struct v4l2_subdev_ops tea6420_ops = { 110static const struct v4l2_subdev_ops tea6420_ops = {
116 .core = &tea6420_core_ops, 111 .core = &tea6420_core_ops,
112 .audio = &tea6420_audio_ops,
117}; 113};
118 114
119/* this function is called by i2c_probe */ 115/* this function is called by i2c_probe */
@@ -130,20 +126,24 @@ static int tea6420_probe(struct i2c_client *client,
130 v4l_info(client, "chip found @ 0x%x (%s)\n", 126 v4l_info(client, "chip found @ 0x%x (%s)\n",
131 client->addr << 1, client->adapter->name); 127 client->addr << 1, client->adapter->name);
132 128
129 sd = kmalloc(sizeof(struct v4l2_subdev), GFP_KERNEL);
130 if (sd == NULL)
131 return -ENOMEM;
132 v4l2_i2c_subdev_init(sd, client, &tea6420_ops);
133
133 /* set initial values: set "mute"-input to all outputs at gain 0 */ 134 /* set initial values: set "mute"-input to all outputs at gain 0 */
134 err = 0; 135 err = 0;
135 for (i = 1; i < 5; i++) { 136 for (i = 1; i < 5; i++) {
136 err += tea6420_switch(client, 6, i, 0); 137 struct v4l2_routing route;
138
139 route.input = 6;
140 route.output = i;
141 err += tea6420_s_routing(sd, &route);
137 } 142 }
138 if (err) { 143 if (err) {
139 v4l_dbg(1, debug, client, "could not initialize tea6420\n"); 144 v4l_dbg(1, debug, client, "could not initialize tea6420\n");
140 return -ENODEV; 145 return -ENODEV;
141 } 146 }
142
143 sd = kmalloc(sizeof(struct v4l2_subdev), GFP_KERNEL);
144 if (sd == NULL)
145 return -ENOMEM;
146 v4l2_i2c_subdev_init(sd, client, &tea6420_ops);
147 return 0; 147 return 0;
148} 148}
149 149
@@ -156,12 +156,6 @@ static int tea6420_remove(struct i2c_client *client)
156 return 0; 156 return 0;
157} 157}
158 158
159static int tea6420_legacy_probe(struct i2c_adapter *adapter)
160{
161 /* Let's see whether this is a known adapter we can attach to.
162 Prevents conflicts with tvaudio.c. */
163 return adapter->id == I2C_HW_SAA7146;
164}
165 159
166static const struct i2c_device_id tea6420_id[] = { 160static const struct i2c_device_id tea6420_id[] = {
167 { "tea6420", 0 }, 161 { "tea6420", 0 },
@@ -171,9 +165,7 @@ MODULE_DEVICE_TABLE(i2c, tea6420_id);
171 165
172static struct v4l2_i2c_driver_data v4l2_i2c_data = { 166static struct v4l2_i2c_driver_data v4l2_i2c_data = {
173 .name = "tea6420", 167 .name = "tea6420",
174 .command = tea6420_command,
175 .probe = tea6420_probe, 168 .probe = tea6420_probe,
176 .remove = tea6420_remove, 169 .remove = tea6420_remove,
177 .legacy_probe = tea6420_legacy_probe,
178 .id_table = tea6420_id, 170 .id_table = tea6420_id,
179}; 171};
diff --git a/drivers/media/video/tea6420.h b/drivers/media/video/tea6420.h
index 5ef7c18e0c5..4aa3edb3e19 100644
--- a/drivers/media/video/tea6420.h
+++ b/drivers/media/video/tea6420.h
@@ -1,17 +1,24 @@
1#ifndef __INCLUDED_TEA6420__ 1#ifndef __INCLUDED_TEA6420__
2#define __INCLUDED_TEA6420__ 2#define __INCLUDED_TEA6420__
3 3
4/* possible addresses */ 4/* input pins */
5#define I2C_ADDR_TEA6420_1 0x4c 5#define TEA6420_OUTPUT1 1
6#define I2C_ADDR_TEA6420_2 0x4d 6#define TEA6420_OUTPUT2 2
7#define TEA6420_OUTPUT3 3
8#define TEA6420_OUTPUT4 4
7 9
8struct tea6420_multiplex 10/* output pins */
9{ 11#define TEA6420_INPUT1 1
10 int in; /* input of audio switch */ 12#define TEA6420_INPUT2 2
11 int out; /* output of audio switch */ 13#define TEA6420_INPUT3 3
12 int gain; /* gain of connection */ 14#define TEA6420_INPUT4 4
13}; 15#define TEA6420_INPUT5 5
16#define TEA6420_INPUT6 6
14 17
15#define TEA6420_SWITCH _IOW('v',1,struct tea6420_multiplex) 18/* gain on the output pins, ORed with the output pin */
19#define TEA6420_GAIN0 0x00
20#define TEA6420_GAIN2 0x20
21#define TEA6420_GAIN4 0x40
22#define TEA6420_GAIN6 0x60
16 23
17#endif 24#endif