aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media
diff options
context:
space:
mode:
authorHans Verkuil <hverkuil@xs4all.nl>2009-02-13 17:58:12 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2009-03-30 11:43:10 -0400
commit8340ff43c49fe8e0cd049b65fbd2156bd651697e (patch)
treecf5a21e2d9a48c2057b61f5f2c93984dbb57fcd7 /drivers/media
parent2b80a19181af3bb15ef1c022f4a56deabcc5bd5e (diff)
V4L/DVB (10863): saa7191: convert 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/video/saa7191.c240
1 files changed, 126 insertions, 114 deletions
diff --git a/drivers/media/video/saa7191.c b/drivers/media/video/saa7191.c
index 4c7bddf4b7ee..40ae2787326f 100644
--- a/drivers/media/video/saa7191.c
+++ b/drivers/media/video/saa7191.c
@@ -21,7 +21,8 @@
21 21
22#include <linux/videodev2.h> 22#include <linux/videodev2.h>
23#include <linux/i2c.h> 23#include <linux/i2c.h>
24#include <media/v4l2-common.h> 24#include <media/v4l2-device.h>
25#include <media/v4l2-chip-ident.h>
25#include <media/v4l2-i2c-drv-legacy.h> 26#include <media/v4l2-i2c-drv-legacy.h>
26 27
27#include "saa7191.h" 28#include "saa7191.h"
@@ -49,7 +50,7 @@ I2C_CLIENT_INSMOD;
49#define SAA7191_SYNC_DELAY 100 /* milliseconds */ 50#define SAA7191_SYNC_DELAY 100 /* milliseconds */
50 51
51struct saa7191 { 52struct saa7191 {
52 struct i2c_client *client; 53 struct v4l2_subdev sd;
53 54
54 /* the register values are stored here as the actual 55 /* the register values are stored here as the actual
55 * I2C-registers are write-only */ 56 * I2C-registers are write-only */
@@ -59,6 +60,11 @@ struct saa7191 {
59 v4l2_std_id norm; 60 v4l2_std_id norm;
60}; 61};
61 62
63static inline struct saa7191 *to_saa7191(struct v4l2_subdev *sd)
64{
65 return container_of(sd, struct saa7191, sd);
66}
67
62static const u8 initseq[] = { 68static const u8 initseq[] = {
63 0, /* Subaddress */ 69 0, /* Subaddress */
64 70
@@ -103,15 +109,14 @@ static const u8 initseq[] = {
103 109
104/* SAA7191 register handling */ 110/* SAA7191 register handling */
105 111
106static u8 saa7191_read_reg(struct i2c_client *client, 112static u8 saa7191_read_reg(struct v4l2_subdev *sd, u8 reg)
107 u8 reg)
108{ 113{
109 return ((struct saa7191 *)i2c_get_clientdata(client))->reg[reg]; 114 return to_saa7191(sd)->reg[reg];
110} 115}
111 116
112static int saa7191_read_status(struct i2c_client *client, 117static int saa7191_read_status(struct v4l2_subdev *sd, u8 *value)
113 u8 *value)
114{ 118{
119 struct i2c_client *client = v4l2_get_subdevdata(sd);
115 int ret; 120 int ret;
116 121
117 ret = i2c_master_recv(client, value, 1); 122 ret = i2c_master_recv(client, value, 1);
@@ -124,21 +129,23 @@ static int saa7191_read_status(struct i2c_client *client,
124} 129}
125 130
126 131
127static int saa7191_write_reg(struct i2c_client *client, u8 reg, 132static int saa7191_write_reg(struct v4l2_subdev *sd, u8 reg, u8 value)
128 u8 value)
129{ 133{
130 ((struct saa7191 *)i2c_get_clientdata(client))->reg[reg] = value; 134 struct i2c_client *client = v4l2_get_subdevdata(sd);
135
136 to_saa7191(sd)->reg[reg] = value;
131 return i2c_smbus_write_byte_data(client, reg, value); 137 return i2c_smbus_write_byte_data(client, reg, value);
132} 138}
133 139
134/* the first byte of data must be the first subaddress number (register) */ 140/* the first byte of data must be the first subaddress number (register) */
135static int saa7191_write_block(struct i2c_client *client, 141static int saa7191_write_block(struct v4l2_subdev *sd,
136 u8 length, const u8 *data) 142 u8 length, const u8 *data)
137{ 143{
144 struct i2c_client *client = v4l2_get_subdevdata(sd);
145 struct saa7191 *decoder = to_saa7191(sd);
138 int i; 146 int i;
139 int ret; 147 int ret;
140 148
141 struct saa7191 *decoder = (struct saa7191 *)i2c_get_clientdata(client);
142 for (i = 0; i < (length - 1); i++) { 149 for (i = 0; i < (length - 1); i++) {
143 decoder->reg[data[0] + i] = data[i + 1]; 150 decoder->reg[data[0] + i] = data[i + 1];
144 } 151 }
@@ -155,14 +162,15 @@ static int saa7191_write_block(struct i2c_client *client,
155 162
156/* Helper functions */ 163/* Helper functions */
157 164
158static int saa7191_set_input(struct i2c_client *client, int input) 165static int saa7191_s_routing(struct v4l2_subdev *sd,
166 const struct v4l2_routing *route)
159{ 167{
160 struct saa7191 *decoder = i2c_get_clientdata(client); 168 struct saa7191 *decoder = to_saa7191(sd);
161 u8 luma = saa7191_read_reg(client, SAA7191_REG_LUMA); 169 u8 luma = saa7191_read_reg(sd, SAA7191_REG_LUMA);
162 u8 iock = saa7191_read_reg(client, SAA7191_REG_IOCK); 170 u8 iock = saa7191_read_reg(sd, SAA7191_REG_IOCK);
163 int err; 171 int err;
164 172
165 switch (input) { 173 switch (route->input) {
166 case SAA7191_INPUT_COMPOSITE: /* Set Composite input */ 174 case SAA7191_INPUT_COMPOSITE: /* Set Composite input */
167 iock &= ~(SAA7191_IOCK_CHRS | SAA7191_IOCK_GPSW1 175 iock &= ~(SAA7191_IOCK_CHRS | SAA7191_IOCK_GPSW1
168 | SAA7191_IOCK_GPSW2); 176 | SAA7191_IOCK_GPSW2);
@@ -178,24 +186,24 @@ static int saa7191_set_input(struct i2c_client *client, int input)
178 return -EINVAL; 186 return -EINVAL;
179 } 187 }
180 188
181 err = saa7191_write_reg(client, SAA7191_REG_LUMA, luma); 189 err = saa7191_write_reg(sd, SAA7191_REG_LUMA, luma);
182 if (err) 190 if (err)
183 return -EIO; 191 return -EIO;
184 err = saa7191_write_reg(client, SAA7191_REG_IOCK, iock); 192 err = saa7191_write_reg(sd, SAA7191_REG_IOCK, iock);
185 if (err) 193 if (err)
186 return -EIO; 194 return -EIO;
187 195
188 decoder->input = input; 196 decoder->input = route->input;
189 197
190 return 0; 198 return 0;
191} 199}
192 200
193static int saa7191_set_norm(struct i2c_client *client, v4l2_std_id norm) 201static int saa7191_s_std(struct v4l2_subdev *sd, v4l2_std_id norm)
194{ 202{
195 struct saa7191 *decoder = i2c_get_clientdata(client); 203 struct saa7191 *decoder = to_saa7191(sd);
196 u8 stdc = saa7191_read_reg(client, SAA7191_REG_STDC); 204 u8 stdc = saa7191_read_reg(sd, SAA7191_REG_STDC);
197 u8 ctl3 = saa7191_read_reg(client, SAA7191_REG_CTL3); 205 u8 ctl3 = saa7191_read_reg(sd, SAA7191_REG_CTL3);
198 u8 chcv = saa7191_read_reg(client, SAA7191_REG_CHCV); 206 u8 chcv = saa7191_read_reg(sd, SAA7191_REG_CHCV);
199 int err; 207 int err;
200 208
201 if (norm & V4L2_STD_PAL) { 209 if (norm & V4L2_STD_PAL) {
@@ -215,13 +223,13 @@ static int saa7191_set_norm(struct i2c_client *client, v4l2_std_id norm)
215 return -EINVAL; 223 return -EINVAL;
216 } 224 }
217 225
218 err = saa7191_write_reg(client, SAA7191_REG_CTL3, ctl3); 226 err = saa7191_write_reg(sd, SAA7191_REG_CTL3, ctl3);
219 if (err) 227 if (err)
220 return -EIO; 228 return -EIO;
221 err = saa7191_write_reg(client, SAA7191_REG_STDC, stdc); 229 err = saa7191_write_reg(sd, SAA7191_REG_STDC, stdc);
222 if (err) 230 if (err)
223 return -EIO; 231 return -EIO;
224 err = saa7191_write_reg(client, SAA7191_REG_CHCV, chcv); 232 err = saa7191_write_reg(sd, SAA7191_REG_CHCV, chcv);
225 if (err) 233 if (err)
226 return -EIO; 234 return -EIO;
227 235
@@ -234,14 +242,14 @@ static int saa7191_set_norm(struct i2c_client *client, v4l2_std_id norm)
234 return 0; 242 return 0;
235} 243}
236 244
237static int saa7191_wait_for_signal(struct i2c_client *client, u8 *status) 245static int saa7191_wait_for_signal(struct v4l2_subdev *sd, u8 *status)
238{ 246{
239 int i = 0; 247 int i = 0;
240 248
241 dprintk("Checking for signal...\n"); 249 dprintk("Checking for signal...\n");
242 250
243 for (i = 0; i < SAA7191_SYNC_COUNT; i++) { 251 for (i = 0; i < SAA7191_SYNC_COUNT; i++) {
244 if (saa7191_read_status(client, status)) 252 if (saa7191_read_status(sd, status))
245 return -EIO; 253 return -EIO;
246 254
247 if (((*status) & SAA7191_STATUS_HLCK) == 0) { 255 if (((*status) & SAA7191_STATUS_HLCK) == 0) {
@@ -257,12 +265,11 @@ static int saa7191_wait_for_signal(struct i2c_client *client, u8 *status)
257 return -EBUSY; 265 return -EBUSY;
258} 266}
259 267
260static int saa7191_autodetect_norm_extended(struct i2c_client *client, 268static int saa7191_querystd(struct v4l2_subdev *sd, v4l2_std_id *norm)
261 v4l2_std_id *norm)
262{ 269{
263 struct saa7191 *decoder = i2c_get_clientdata(client); 270 struct saa7191 *decoder = to_saa7191(sd);
264 u8 stdc = saa7191_read_reg(client, SAA7191_REG_STDC); 271 u8 stdc = saa7191_read_reg(sd, SAA7191_REG_STDC);
265 u8 ctl3 = saa7191_read_reg(client, SAA7191_REG_CTL3); 272 u8 ctl3 = saa7191_read_reg(sd, SAA7191_REG_CTL3);
266 u8 status; 273 u8 status;
267 v4l2_std_id old_norm = decoder->norm; 274 v4l2_std_id old_norm = decoder->norm;
268 int err = 0; 275 int err = 0;
@@ -273,19 +280,19 @@ static int saa7191_autodetect_norm_extended(struct i2c_client *client,
273 stdc &= ~SAA7191_STDC_SECS; 280 stdc &= ~SAA7191_STDC_SECS;
274 ctl3 &= ~(SAA7191_CTL3_FSEL); 281 ctl3 &= ~(SAA7191_CTL3_FSEL);
275 282
276 err = saa7191_write_reg(client, SAA7191_REG_STDC, stdc); 283 err = saa7191_write_reg(sd, SAA7191_REG_STDC, stdc);
277 if (err) { 284 if (err) {
278 err = -EIO; 285 err = -EIO;
279 goto out; 286 goto out;
280 } 287 }
281 err = saa7191_write_reg(client, SAA7191_REG_CTL3, ctl3); 288 err = saa7191_write_reg(sd, SAA7191_REG_CTL3, ctl3);
282 if (err) { 289 if (err) {
283 err = -EIO; 290 err = -EIO;
284 goto out; 291 goto out;
285 } 292 }
286 293
287 ctl3 |= SAA7191_CTL3_AUFD; 294 ctl3 |= SAA7191_CTL3_AUFD;
288 err = saa7191_write_reg(client, SAA7191_REG_CTL3, ctl3); 295 err = saa7191_write_reg(sd, SAA7191_REG_CTL3, ctl3);
289 if (err) { 296 if (err) {
290 err = -EIO; 297 err = -EIO;
291 goto out; 298 goto out;
@@ -293,7 +300,7 @@ static int saa7191_autodetect_norm_extended(struct i2c_client *client,
293 300
294 msleep(SAA7191_SYNC_DELAY); 301 msleep(SAA7191_SYNC_DELAY);
295 302
296 err = saa7191_wait_for_signal(client, &status); 303 err = saa7191_wait_for_signal(sd, &status);
297 if (err) 304 if (err)
298 goto out; 305 goto out;
299 306
@@ -308,39 +315,39 @@ static int saa7191_autodetect_norm_extended(struct i2c_client *client,
308 dprintk("50Hz signal: Trying PAL...\n"); 315 dprintk("50Hz signal: Trying PAL...\n");
309 316
310 /* try PAL first */ 317 /* try PAL first */
311 err = saa7191_set_norm(client, V4L2_STD_PAL); 318 err = saa7191_s_std(sd, V4L2_STD_PAL);
312 if (err) 319 if (err)
313 goto out; 320 goto out;
314 321
315 msleep(SAA7191_SYNC_DELAY); 322 msleep(SAA7191_SYNC_DELAY);
316 323
317 err = saa7191_wait_for_signal(client, &status); 324 err = saa7191_wait_for_signal(sd, &status);
318 if (err) 325 if (err)
319 goto out; 326 goto out;
320 327
321 /* not 50Hz ? */ 328 /* not 50Hz ? */
322 if (status & SAA7191_STATUS_FIDT) { 329 if (status & SAA7191_STATUS_FIDT) {
323 dprintk("No 50Hz signal\n"); 330 dprintk("No 50Hz signal\n");
324 saa7191_set_norm(client, old_norm); 331 saa7191_s_std(sd, old_norm);
325 return -EAGAIN; 332 return -EAGAIN;
326 } 333 }
327 334
328 if (status & SAA7191_STATUS_CODE) { 335 if (status & SAA7191_STATUS_CODE) {
329 dprintk("PAL\n"); 336 dprintk("PAL\n");
330 *norm = V4L2_STD_PAL; 337 *norm = V4L2_STD_PAL;
331 return saa7191_set_norm(client, old_norm); 338 return saa7191_s_std(sd, old_norm);
332 } 339 }
333 340
334 dprintk("No color detected with PAL - Trying SECAM...\n"); 341 dprintk("No color detected with PAL - Trying SECAM...\n");
335 342
336 /* no color detected ? -> try SECAM */ 343 /* no color detected ? -> try SECAM */
337 err = saa7191_set_norm(client, V4L2_STD_SECAM); 344 err = saa7191_s_std(sd, V4L2_STD_SECAM);
338 if (err) 345 if (err)
339 goto out; 346 goto out;
340 347
341 msleep(SAA7191_SYNC_DELAY); 348 msleep(SAA7191_SYNC_DELAY);
342 349
343 err = saa7191_wait_for_signal(client, &status); 350 err = saa7191_wait_for_signal(sd, &status);
344 if (err) 351 if (err)
345 goto out; 352 goto out;
346 353
@@ -355,16 +362,16 @@ static int saa7191_autodetect_norm_extended(struct i2c_client *client,
355 /* Color detected -> SECAM */ 362 /* Color detected -> SECAM */
356 dprintk("SECAM\n"); 363 dprintk("SECAM\n");
357 *norm = V4L2_STD_SECAM; 364 *norm = V4L2_STD_SECAM;
358 return saa7191_set_norm(client, old_norm); 365 return saa7191_s_std(sd, old_norm);
359 } 366 }
360 367
361 dprintk("No color detected with SECAM - Going back to PAL.\n"); 368 dprintk("No color detected with SECAM - Going back to PAL.\n");
362 369
363out: 370out:
364 return saa7191_set_norm(client, old_norm); 371 return saa7191_s_std(sd, old_norm);
365} 372}
366 373
367static int saa7191_autodetect_norm(struct i2c_client *client) 374static int saa7191_autodetect_norm(struct v4l2_subdev *sd)
368{ 375{
369 u8 status; 376 u8 status;
370 377
@@ -372,7 +379,7 @@ static int saa7191_autodetect_norm(struct i2c_client *client)
372 379
373 dprintk("Reading status...\n"); 380 dprintk("Reading status...\n");
374 381
375 if (saa7191_read_status(client, &status)) 382 if (saa7191_read_status(sd, &status))
376 return -EIO; 383 return -EIO;
377 384
378 dprintk("Checking for signal...\n"); 385 dprintk("Checking for signal...\n");
@@ -388,16 +395,15 @@ static int saa7191_autodetect_norm(struct i2c_client *client)
388 if (status & SAA7191_STATUS_FIDT) { 395 if (status & SAA7191_STATUS_FIDT) {
389 /* 60hz signal -> NTSC */ 396 /* 60hz signal -> NTSC */
390 dprintk("NTSC\n"); 397 dprintk("NTSC\n");
391 return saa7191_set_norm(client, V4L2_STD_NTSC); 398 return saa7191_s_std(sd, V4L2_STD_NTSC);
392 } else { 399 } else {
393 /* 50hz signal -> PAL */ 400 /* 50hz signal -> PAL */
394 dprintk("PAL\n"); 401 dprintk("PAL\n");
395 return saa7191_set_norm(client, V4L2_STD_PAL); 402 return saa7191_s_std(sd, V4L2_STD_PAL);
396 } 403 }
397} 404}
398 405
399static int saa7191_get_control(struct i2c_client *client, 406static int saa7191_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
400 struct v4l2_control *ctrl)
401{ 407{
402 u8 reg; 408 u8 reg;
403 int ret = 0; 409 int ret = 0;
@@ -406,7 +412,7 @@ static int saa7191_get_control(struct i2c_client *client,
406 case SAA7191_CONTROL_BANDPASS: 412 case SAA7191_CONTROL_BANDPASS:
407 case SAA7191_CONTROL_BANDPASS_WEIGHT: 413 case SAA7191_CONTROL_BANDPASS_WEIGHT:
408 case SAA7191_CONTROL_CORING: 414 case SAA7191_CONTROL_CORING:
409 reg = saa7191_read_reg(client, SAA7191_REG_LUMA); 415 reg = saa7191_read_reg(sd, SAA7191_REG_LUMA);
410 switch (ctrl->id) { 416 switch (ctrl->id) {
411 case SAA7191_CONTROL_BANDPASS: 417 case SAA7191_CONTROL_BANDPASS:
412 ctrl->value = ((s32)reg & SAA7191_LUMA_BPSS_MASK) 418 ctrl->value = ((s32)reg & SAA7191_LUMA_BPSS_MASK)
@@ -424,7 +430,7 @@ static int saa7191_get_control(struct i2c_client *client,
424 break; 430 break;
425 case SAA7191_CONTROL_FORCE_COLOUR: 431 case SAA7191_CONTROL_FORCE_COLOUR:
426 case SAA7191_CONTROL_CHROMA_GAIN: 432 case SAA7191_CONTROL_CHROMA_GAIN:
427 reg = saa7191_read_reg(client, SAA7191_REG_GAIN); 433 reg = saa7191_read_reg(sd, SAA7191_REG_GAIN);
428 if (ctrl->id == SAA7191_CONTROL_FORCE_COLOUR) 434 if (ctrl->id == SAA7191_CONTROL_FORCE_COLOUR)
429 ctrl->value = ((s32)reg & SAA7191_GAIN_COLO) ? 1 : 0; 435 ctrl->value = ((s32)reg & SAA7191_GAIN_COLO) ? 1 : 0;
430 else 436 else
@@ -432,7 +438,7 @@ static int saa7191_get_control(struct i2c_client *client,
432 >> SAA7191_GAIN_LFIS_SHIFT; 438 >> SAA7191_GAIN_LFIS_SHIFT;
433 break; 439 break;
434 case V4L2_CID_HUE: 440 case V4L2_CID_HUE:
435 reg = saa7191_read_reg(client, SAA7191_REG_HUEC); 441 reg = saa7191_read_reg(sd, SAA7191_REG_HUEC);
436 if (reg < 0x80) 442 if (reg < 0x80)
437 reg += 0x80; 443 reg += 0x80;
438 else 444 else
@@ -440,18 +446,18 @@ static int saa7191_get_control(struct i2c_client *client,
440 ctrl->value = (s32)reg; 446 ctrl->value = (s32)reg;
441 break; 447 break;
442 case SAA7191_CONTROL_VTRC: 448 case SAA7191_CONTROL_VTRC:
443 reg = saa7191_read_reg(client, SAA7191_REG_STDC); 449 reg = saa7191_read_reg(sd, SAA7191_REG_STDC);
444 ctrl->value = ((s32)reg & SAA7191_STDC_VTRC) ? 1 : 0; 450 ctrl->value = ((s32)reg & SAA7191_STDC_VTRC) ? 1 : 0;
445 break; 451 break;
446 case SAA7191_CONTROL_LUMA_DELAY: 452 case SAA7191_CONTROL_LUMA_DELAY:
447 reg = saa7191_read_reg(client, SAA7191_REG_CTL3); 453 reg = saa7191_read_reg(sd, SAA7191_REG_CTL3);
448 ctrl->value = ((s32)reg & SAA7191_CTL3_YDEL_MASK) 454 ctrl->value = ((s32)reg & SAA7191_CTL3_YDEL_MASK)
449 >> SAA7191_CTL3_YDEL_SHIFT; 455 >> SAA7191_CTL3_YDEL_SHIFT;
450 if (ctrl->value >= 4) 456 if (ctrl->value >= 4)
451 ctrl->value -= 8; 457 ctrl->value -= 8;
452 break; 458 break;
453 case SAA7191_CONTROL_VNR: 459 case SAA7191_CONTROL_VNR:
454 reg = saa7191_read_reg(client, SAA7191_REG_CTL4); 460 reg = saa7191_read_reg(sd, SAA7191_REG_CTL4);
455 ctrl->value = ((s32)reg & SAA7191_CTL4_VNOI_MASK) 461 ctrl->value = ((s32)reg & SAA7191_CTL4_VNOI_MASK)
456 >> SAA7191_CTL4_VNOI_SHIFT; 462 >> SAA7191_CTL4_VNOI_SHIFT;
457 break; 463 break;
@@ -462,8 +468,7 @@ static int saa7191_get_control(struct i2c_client *client,
462 return ret; 468 return ret;
463} 469}
464 470
465static int saa7191_set_control(struct i2c_client *client, 471static int saa7191_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
466 struct v4l2_control *ctrl)
467{ 472{
468 u8 reg; 473 u8 reg;
469 int ret = 0; 474 int ret = 0;
@@ -472,7 +477,7 @@ static int saa7191_set_control(struct i2c_client *client,
472 case SAA7191_CONTROL_BANDPASS: 477 case SAA7191_CONTROL_BANDPASS:
473 case SAA7191_CONTROL_BANDPASS_WEIGHT: 478 case SAA7191_CONTROL_BANDPASS_WEIGHT:
474 case SAA7191_CONTROL_CORING: 479 case SAA7191_CONTROL_CORING:
475 reg = saa7191_read_reg(client, SAA7191_REG_LUMA); 480 reg = saa7191_read_reg(sd, SAA7191_REG_LUMA);
476 switch (ctrl->id) { 481 switch (ctrl->id) {
477 case SAA7191_CONTROL_BANDPASS: 482 case SAA7191_CONTROL_BANDPASS:
478 reg &= ~SAA7191_LUMA_BPSS_MASK; 483 reg &= ~SAA7191_LUMA_BPSS_MASK;
@@ -490,11 +495,11 @@ static int saa7191_set_control(struct i2c_client *client,
490 & SAA7191_LUMA_CORI_MASK; 495 & SAA7191_LUMA_CORI_MASK;
491 break; 496 break;
492 } 497 }
493 ret = saa7191_write_reg(client, SAA7191_REG_LUMA, reg); 498 ret = saa7191_write_reg(sd, SAA7191_REG_LUMA, reg);
494 break; 499 break;
495 case SAA7191_CONTROL_FORCE_COLOUR: 500 case SAA7191_CONTROL_FORCE_COLOUR:
496 case SAA7191_CONTROL_CHROMA_GAIN: 501 case SAA7191_CONTROL_CHROMA_GAIN:
497 reg = saa7191_read_reg(client, SAA7191_REG_GAIN); 502 reg = saa7191_read_reg(sd, SAA7191_REG_GAIN);
498 if (ctrl->id == SAA7191_CONTROL_FORCE_COLOUR) { 503 if (ctrl->id == SAA7191_CONTROL_FORCE_COLOUR) {
499 if (ctrl->value) 504 if (ctrl->value)
500 reg |= SAA7191_GAIN_COLO; 505 reg |= SAA7191_GAIN_COLO;
@@ -505,7 +510,7 @@ static int saa7191_set_control(struct i2c_client *client,
505 reg |= (ctrl->value << SAA7191_GAIN_LFIS_SHIFT) 510 reg |= (ctrl->value << SAA7191_GAIN_LFIS_SHIFT)
506 & SAA7191_GAIN_LFIS_MASK; 511 & SAA7191_GAIN_LFIS_MASK;
507 } 512 }
508 ret = saa7191_write_reg(client, SAA7191_REG_GAIN, reg); 513 ret = saa7191_write_reg(sd, SAA7191_REG_GAIN, reg);
509 break; 514 break;
510 case V4L2_CID_HUE: 515 case V4L2_CID_HUE:
511 reg = ctrl->value & 0xff; 516 reg = ctrl->value & 0xff;
@@ -513,33 +518,33 @@ static int saa7191_set_control(struct i2c_client *client,
513 reg += 0x80; 518 reg += 0x80;
514 else 519 else
515 reg -= 0x80; 520 reg -= 0x80;
516 ret = saa7191_write_reg(client, SAA7191_REG_HUEC, reg); 521 ret = saa7191_write_reg(sd, SAA7191_REG_HUEC, reg);
517 break; 522 break;
518 case SAA7191_CONTROL_VTRC: 523 case SAA7191_CONTROL_VTRC:
519 reg = saa7191_read_reg(client, SAA7191_REG_STDC); 524 reg = saa7191_read_reg(sd, SAA7191_REG_STDC);
520 if (ctrl->value) 525 if (ctrl->value)
521 reg |= SAA7191_STDC_VTRC; 526 reg |= SAA7191_STDC_VTRC;
522 else 527 else
523 reg &= ~SAA7191_STDC_VTRC; 528 reg &= ~SAA7191_STDC_VTRC;
524 ret = saa7191_write_reg(client, SAA7191_REG_STDC, reg); 529 ret = saa7191_write_reg(sd, SAA7191_REG_STDC, reg);
525 break; 530 break;
526 case SAA7191_CONTROL_LUMA_DELAY: { 531 case SAA7191_CONTROL_LUMA_DELAY: {
527 s32 value = ctrl->value; 532 s32 value = ctrl->value;
528 if (value < 0) 533 if (value < 0)
529 value += 8; 534 value += 8;
530 reg = saa7191_read_reg(client, SAA7191_REG_CTL3); 535 reg = saa7191_read_reg(sd, SAA7191_REG_CTL3);
531 reg &= ~SAA7191_CTL3_YDEL_MASK; 536 reg &= ~SAA7191_CTL3_YDEL_MASK;
532 reg |= (value << SAA7191_CTL3_YDEL_SHIFT) 537 reg |= (value << SAA7191_CTL3_YDEL_SHIFT)
533 & SAA7191_CTL3_YDEL_MASK; 538 & SAA7191_CTL3_YDEL_MASK;
534 ret = saa7191_write_reg(client, SAA7191_REG_CTL3, reg); 539 ret = saa7191_write_reg(sd, SAA7191_REG_CTL3, reg);
535 break; 540 break;
536 } 541 }
537 case SAA7191_CONTROL_VNR: 542 case SAA7191_CONTROL_VNR:
538 reg = saa7191_read_reg(client, SAA7191_REG_CTL4); 543 reg = saa7191_read_reg(sd, SAA7191_REG_CTL4);
539 reg &= ~SAA7191_CTL4_VNOI_MASK; 544 reg &= ~SAA7191_CTL4_VNOI_MASK;
540 reg |= (ctrl->value << SAA7191_CTL4_VNOI_SHIFT) 545 reg |= (ctrl->value << SAA7191_CTL4_VNOI_SHIFT)
541 & SAA7191_CTL4_VNOI_MASK; 546 & SAA7191_CTL4_VNOI_MASK;
542 ret = saa7191_write_reg(client, SAA7191_REG_CTL4, reg); 547 ret = saa7191_write_reg(sd, SAA7191_REG_CTL4, reg);
543 break; 548 break;
544 default: 549 default:
545 ret = -EINVAL; 550 ret = -EINVAL;
@@ -550,57 +555,64 @@ static int saa7191_set_control(struct i2c_client *client,
550 555
551/* I2C-interface */ 556/* I2C-interface */
552 557
553static int saa7191_command(struct i2c_client *client, unsigned int cmd, 558static int saa7191_g_input_status(struct v4l2_subdev *sd, u32 *status)
554 void *arg)
555{ 559{
556 switch (cmd) { 560 u8 status_reg;
557 case VIDIOC_INT_G_INPUT_STATUS: { 561 int res = V4L2_IN_ST_NO_SIGNAL;
558 u32 *iarg = arg;
559 u8 status;
560 int res = V4L2_IN_ST_NO_SIGNAL;
561 562
562 if (saa7191_read_status(client, &status)) 563 if (saa7191_read_status(sd, &status_reg))
563 return -EIO; 564 return -EIO;
564 if ((status & SAA7191_STATUS_HLCK) == 0) 565 if ((status_reg & SAA7191_STATUS_HLCK) == 0)
565 res = 0; 566 res = 0;
566 if (!(status & SAA7191_STATUS_CODE)) 567 if (!(status_reg & SAA7191_STATUS_CODE))
567 res |= V4L2_IN_ST_NO_COLOR; 568 res |= V4L2_IN_ST_NO_COLOR;
568 *iarg = res; 569 *status = res;
569 break; 570 return 0;
570 } 571}
571 572
572 case VIDIOC_QUERYSTD:
573 return saa7191_autodetect_norm_extended(client, arg);
574 573
575 case VIDIOC_S_STD: { 574static int saa7191_g_chip_ident(struct v4l2_subdev *sd,
576 v4l2_std_id *istd = arg; 575 struct v4l2_dbg_chip_ident *chip)
576{
577 struct i2c_client *client = v4l2_get_subdevdata(sd);
577 578
578 return saa7191_set_norm(client, *istd); 579 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_SAA7191, 0);
579 } 580}
580 case VIDIOC_INT_S_VIDEO_ROUTING: {
581 struct v4l2_routing *route = arg;
582 581
583 return saa7191_set_input(client, route->input); 582static int saa7191_command(struct i2c_client *client, unsigned cmd, void *arg)
584 } 583{
584 return v4l2_subdev_command(i2c_get_clientdata(client), cmd, arg);
585}
585 586
586 case VIDIOC_G_CTRL: 587/* ----------------------------------------------------------------------- */
587 return saa7191_get_control(client, arg);
588 588
589 case VIDIOC_S_CTRL: 589static const struct v4l2_subdev_core_ops saa7191_core_ops = {
590 return saa7191_set_control(client, arg); 590 .g_chip_ident = saa7191_g_chip_ident,
591 .g_ctrl = saa7191_g_ctrl,
592 .s_ctrl = saa7191_s_ctrl,
593};
591 594
592 default: 595static const struct v4l2_subdev_tuner_ops saa7191_tuner_ops = {
593 return -EINVAL; 596 .s_std = saa7191_s_std,
594 } 597};
595 598
596 return 0; 599static const struct v4l2_subdev_video_ops saa7191_video_ops = {
597} 600 .s_routing = saa7191_s_routing,
601 .querystd = saa7191_querystd,
602 .g_input_status = saa7191_g_input_status,
603};
604
605static const struct v4l2_subdev_ops saa7191_ops = {
606 .core = &saa7191_core_ops,
607 .video = &saa7191_video_ops,
608};
598 609
599static int saa7191_probe(struct i2c_client *client, 610static int saa7191_probe(struct i2c_client *client,
600 const struct i2c_device_id *id) 611 const struct i2c_device_id *id)
601{ 612{
602 int err = 0; 613 int err = 0;
603 struct saa7191 *decoder; 614 struct saa7191 *decoder;
615 struct v4l2_subdev *sd;
604 616
605 v4l_info(client, "chip found @ 0x%x (%s)\n", 617 v4l_info(client, "chip found @ 0x%x (%s)\n",
606 client->addr << 1, client->adapter->name); 618 client->addr << 1, client->adapter->name);
@@ -609,11 +621,10 @@ static int saa7191_probe(struct i2c_client *client,
609 if (!decoder) 621 if (!decoder)
610 return -ENOMEM; 622 return -ENOMEM;
611 623
612 i2c_set_clientdata(client, decoder); 624 sd = &decoder->sd;
613 625 v4l2_i2c_subdev_init(sd, client, &saa7191_ops);
614 decoder->client = client;
615 626
616 err = saa7191_write_block(client, sizeof(initseq), initseq); 627 err = saa7191_write_block(sd, sizeof(initseq), initseq);
617 if (err) { 628 if (err) {
618 printk(KERN_ERR "SAA7191 initialization failed\n"); 629 printk(KERN_ERR "SAA7191 initialization failed\n");
619 kfree(decoder); 630 kfree(decoder);
@@ -625,7 +636,7 @@ static int saa7191_probe(struct i2c_client *client,
625 decoder->input = SAA7191_INPUT_COMPOSITE; 636 decoder->input = SAA7191_INPUT_COMPOSITE;
626 decoder->norm = V4L2_STD_PAL; 637 decoder->norm = V4L2_STD_PAL;
627 638
628 err = saa7191_autodetect_norm(client); 639 err = saa7191_autodetect_norm(sd);
629 if (err && (err != -EBUSY)) 640 if (err && (err != -EBUSY))
630 printk(KERN_ERR "SAA7191: Signal auto-detection failed\n"); 641 printk(KERN_ERR "SAA7191: Signal auto-detection failed\n");
631 642
@@ -634,9 +645,10 @@ static int saa7191_probe(struct i2c_client *client,
634 645
635static int saa7191_remove(struct i2c_client *client) 646static int saa7191_remove(struct i2c_client *client)
636{ 647{
637 struct saa7191 *decoder = i2c_get_clientdata(client); 648 struct v4l2_subdev *sd = i2c_get_clientdata(client);
638 649
639 kfree(decoder); 650 v4l2_device_unregister_subdev(sd);
651 kfree(to_saa7191(sd));
640 return 0; 652 return 0;
641} 653}
642 654