aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/saa7191.c
diff options
context:
space:
mode:
authorHans Verkuil <hverkuil@xs4all.nl>2009-02-27 07:05:10 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2009-03-30 11:43:10 -0400
commitcf4e9484f402c799fa25c9ffb7e9a3b620a3702d (patch)
tree5f7839009c8a66f4c1b5eaaf2c3c7365b515564d /drivers/media/video/saa7191.c
parentbabb7dc7776dd6ded4e1e6cb7acc34c25c0eb521 (diff)
V4L/DVB (10861): vino/indycam/saa7191: convert to i2c modules to V4L2.
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/saa7191.c')
-rw-r--r--drivers/media/video/saa7191.c228
1 files changed, 57 insertions, 171 deletions
diff --git a/drivers/media/video/saa7191.c b/drivers/media/video/saa7191.c
index 9943e5c35e15..4c7bddf4b7ee 100644
--- a/drivers/media/video/saa7191.c
+++ b/drivers/media/video/saa7191.c
@@ -19,8 +19,7 @@
19#include <linux/mm.h> 19#include <linux/mm.h>
20#include <linux/slab.h> 20#include <linux/slab.h>
21 21
22#include <linux/videodev.h> 22#include <linux/videodev2.h>
23#include <linux/video_decoder.h>
24#include <linux/i2c.h> 23#include <linux/i2c.h>
25#include <media/v4l2-common.h> 24#include <media/v4l2-common.h>
26#include <media/v4l2-i2c-drv-legacy.h> 25#include <media/v4l2-i2c-drv-legacy.h>
@@ -57,7 +56,7 @@ struct saa7191 {
57 u8 reg[25]; 56 u8 reg[25];
58 57
59 int input; 58 int input;
60 int norm; 59 v4l2_std_id norm;
61}; 60};
62 61
63static const u8 initseq[] = { 62static const u8 initseq[] = {
@@ -191,7 +190,7 @@ static int saa7191_set_input(struct i2c_client *client, int input)
191 return 0; 190 return 0;
192} 191}
193 192
194static int saa7191_set_norm(struct i2c_client *client, int norm) 193static int saa7191_set_norm(struct i2c_client *client, v4l2_std_id norm)
195{ 194{
196 struct saa7191 *decoder = i2c_get_clientdata(client); 195 struct saa7191 *decoder = i2c_get_clientdata(client);
197 u8 stdc = saa7191_read_reg(client, SAA7191_REG_STDC); 196 u8 stdc = saa7191_read_reg(client, SAA7191_REG_STDC);
@@ -199,24 +198,20 @@ static int saa7191_set_norm(struct i2c_client *client, int norm)
199 u8 chcv = saa7191_read_reg(client, SAA7191_REG_CHCV); 198 u8 chcv = saa7191_read_reg(client, SAA7191_REG_CHCV);
200 int err; 199 int err;
201 200
202 switch(norm) { 201 if (norm & V4L2_STD_PAL) {
203 case SAA7191_NORM_PAL:
204 stdc &= ~SAA7191_STDC_SECS; 202 stdc &= ~SAA7191_STDC_SECS;
205 ctl3 &= ~(SAA7191_CTL3_AUFD | SAA7191_CTL3_FSEL); 203 ctl3 &= ~(SAA7191_CTL3_AUFD | SAA7191_CTL3_FSEL);
206 chcv = SAA7191_CHCV_PAL; 204 chcv = SAA7191_CHCV_PAL;
207 break; 205 } else if (norm & V4L2_STD_NTSC) {
208 case SAA7191_NORM_NTSC:
209 stdc &= ~SAA7191_STDC_SECS; 206 stdc &= ~SAA7191_STDC_SECS;
210 ctl3 &= ~SAA7191_CTL3_AUFD; 207 ctl3 &= ~SAA7191_CTL3_AUFD;
211 ctl3 |= SAA7191_CTL3_FSEL; 208 ctl3 |= SAA7191_CTL3_FSEL;
212 chcv = SAA7191_CHCV_NTSC; 209 chcv = SAA7191_CHCV_NTSC;
213 break; 210 } else if (norm & V4L2_STD_SECAM) {
214 case SAA7191_NORM_SECAM:
215 stdc |= SAA7191_STDC_SECS; 211 stdc |= SAA7191_STDC_SECS;
216 ctl3 &= ~(SAA7191_CTL3_AUFD | SAA7191_CTL3_FSEL); 212 ctl3 &= ~(SAA7191_CTL3_AUFD | SAA7191_CTL3_FSEL);
217 chcv = SAA7191_CHCV_PAL; 213 chcv = SAA7191_CHCV_PAL;
218 break; 214 } else {
219 default:
220 return -EINVAL; 215 return -EINVAL;
221 } 216 }
222 217
@@ -234,7 +229,7 @@ static int saa7191_set_norm(struct i2c_client *client, int norm)
234 229
235 dprintk("ctl3: %02x stdc: %02x chcv: %02x\n", ctl3, 230 dprintk("ctl3: %02x stdc: %02x chcv: %02x\n", ctl3,
236 stdc, chcv); 231 stdc, chcv);
237 dprintk("norm: %d\n", norm); 232 dprintk("norm: %llx\n", norm);
238 233
239 return 0; 234 return 0;
240} 235}
@@ -262,15 +257,19 @@ static int saa7191_wait_for_signal(struct i2c_client *client, u8 *status)
262 return -EBUSY; 257 return -EBUSY;
263} 258}
264 259
265static int saa7191_autodetect_norm_extended(struct i2c_client *client) 260static int saa7191_autodetect_norm_extended(struct i2c_client *client,
261 v4l2_std_id *norm)
266{ 262{
263 struct saa7191 *decoder = i2c_get_clientdata(client);
267 u8 stdc = saa7191_read_reg(client, SAA7191_REG_STDC); 264 u8 stdc = saa7191_read_reg(client, SAA7191_REG_STDC);
268 u8 ctl3 = saa7191_read_reg(client, SAA7191_REG_CTL3); 265 u8 ctl3 = saa7191_read_reg(client, SAA7191_REG_CTL3);
269 u8 status; 266 u8 status;
267 v4l2_std_id old_norm = decoder->norm;
270 int err = 0; 268 int err = 0;
271 269
272 dprintk("SAA7191 extended signal auto-detection...\n"); 270 dprintk("SAA7191 extended signal auto-detection...\n");
273 271
272 *norm = V4L2_STD_NTSC | V4L2_STD_PAL | V4L2_STD_SECAM;
274 stdc &= ~SAA7191_STDC_SECS; 273 stdc &= ~SAA7191_STDC_SECS;
275 ctl3 &= ~(SAA7191_CTL3_FSEL); 274 ctl3 &= ~(SAA7191_CTL3_FSEL);
276 275
@@ -301,14 +300,15 @@ static int saa7191_autodetect_norm_extended(struct i2c_client *client)
301 if (status & SAA7191_STATUS_FIDT) { 300 if (status & SAA7191_STATUS_FIDT) {
302 /* 60Hz signal -> NTSC */ 301 /* 60Hz signal -> NTSC */
303 dprintk("60Hz signal: NTSC\n"); 302 dprintk("60Hz signal: NTSC\n");
304 return saa7191_set_norm(client, SAA7191_NORM_NTSC); 303 *norm = V4L2_STD_NTSC;
304 return 0;
305 } 305 }
306 306
307 /* 50Hz signal */ 307 /* 50Hz signal */
308 dprintk("50Hz signal: Trying PAL...\n"); 308 dprintk("50Hz signal: Trying PAL...\n");
309 309
310 /* try PAL first */ 310 /* try PAL first */
311 err = saa7191_set_norm(client, SAA7191_NORM_PAL); 311 err = saa7191_set_norm(client, V4L2_STD_PAL);
312 if (err) 312 if (err)
313 goto out; 313 goto out;
314 314
@@ -321,20 +321,20 @@ static int saa7191_autodetect_norm_extended(struct i2c_client *client)
321 /* not 50Hz ? */ 321 /* not 50Hz ? */
322 if (status & SAA7191_STATUS_FIDT) { 322 if (status & SAA7191_STATUS_FIDT) {
323 dprintk("No 50Hz signal\n"); 323 dprintk("No 50Hz signal\n");
324 err = -EAGAIN; 324 saa7191_set_norm(client, old_norm);
325 goto out; 325 return -EAGAIN;
326 } 326 }
327 327
328 if (status & SAA7191_STATUS_CODE) { 328 if (status & SAA7191_STATUS_CODE) {
329 dprintk("PAL\n"); 329 dprintk("PAL\n");
330 return 0; 330 *norm = V4L2_STD_PAL;
331 return saa7191_set_norm(client, old_norm);
331 } 332 }
332 333
333 dprintk("No color detected with PAL - Trying SECAM...\n"); 334 dprintk("No color detected with PAL - Trying SECAM...\n");
334 335
335 /* no color detected ? -> try SECAM */ 336 /* no color detected ? -> try SECAM */
336 err = saa7191_set_norm(client, 337 err = saa7191_set_norm(client, V4L2_STD_SECAM);
337 SAA7191_NORM_SECAM);
338 if (err) 338 if (err)
339 goto out; 339 goto out;
340 340
@@ -354,29 +354,14 @@ static int saa7191_autodetect_norm_extended(struct i2c_client *client)
354 if (status & SAA7191_STATUS_CODE) { 354 if (status & SAA7191_STATUS_CODE) {
355 /* Color detected -> SECAM */ 355 /* Color detected -> SECAM */
356 dprintk("SECAM\n"); 356 dprintk("SECAM\n");
357 return 0; 357 *norm = V4L2_STD_SECAM;
358 return saa7191_set_norm(client, old_norm);
358 } 359 }
359 360
360 dprintk("No color detected with SECAM - Going back to PAL.\n"); 361 dprintk("No color detected with SECAM - Going back to PAL.\n");
361 362
362 /* still no color detected ?
363 * -> set norm back to PAL */
364 err = saa7191_set_norm(client,
365 SAA7191_NORM_PAL);
366 if (err)
367 goto out;
368
369out: 363out:
370 ctl3 = saa7191_read_reg(client, SAA7191_REG_CTL3); 364 return saa7191_set_norm(client, old_norm);
371 if (ctl3 & SAA7191_CTL3_AUFD) {
372 ctl3 &= ~(SAA7191_CTL3_AUFD);
373 err = saa7191_write_reg(client, SAA7191_REG_CTL3, ctl3);
374 if (err) {
375 err = -EIO;
376 }
377 }
378
379 return err;
380} 365}
381 366
382static int saa7191_autodetect_norm(struct i2c_client *client) 367static int saa7191_autodetect_norm(struct i2c_client *client)
@@ -403,26 +388,26 @@ static int saa7191_autodetect_norm(struct i2c_client *client)
403 if (status & SAA7191_STATUS_FIDT) { 388 if (status & SAA7191_STATUS_FIDT) {
404 /* 60hz signal -> NTSC */ 389 /* 60hz signal -> NTSC */
405 dprintk("NTSC\n"); 390 dprintk("NTSC\n");
406 return saa7191_set_norm(client, SAA7191_NORM_NTSC); 391 return saa7191_set_norm(client, V4L2_STD_NTSC);
407 } else { 392 } else {
408 /* 50hz signal -> PAL */ 393 /* 50hz signal -> PAL */
409 dprintk("PAL\n"); 394 dprintk("PAL\n");
410 return saa7191_set_norm(client, SAA7191_NORM_PAL); 395 return saa7191_set_norm(client, V4L2_STD_PAL);
411 } 396 }
412} 397}
413 398
414static int saa7191_get_control(struct i2c_client *client, 399static int saa7191_get_control(struct i2c_client *client,
415 struct saa7191_control *ctrl) 400 struct v4l2_control *ctrl)
416{ 401{
417 u8 reg; 402 u8 reg;
418 int ret = 0; 403 int ret = 0;
419 404
420 switch (ctrl->type) { 405 switch (ctrl->id) {
421 case SAA7191_CONTROL_BANDPASS: 406 case SAA7191_CONTROL_BANDPASS:
422 case SAA7191_CONTROL_BANDPASS_WEIGHT: 407 case SAA7191_CONTROL_BANDPASS_WEIGHT:
423 case SAA7191_CONTROL_CORING: 408 case SAA7191_CONTROL_CORING:
424 reg = saa7191_read_reg(client, SAA7191_REG_LUMA); 409 reg = saa7191_read_reg(client, SAA7191_REG_LUMA);
425 switch (ctrl->type) { 410 switch (ctrl->id) {
426 case SAA7191_CONTROL_BANDPASS: 411 case SAA7191_CONTROL_BANDPASS:
427 ctrl->value = ((s32)reg & SAA7191_LUMA_BPSS_MASK) 412 ctrl->value = ((s32)reg & SAA7191_LUMA_BPSS_MASK)
428 >> SAA7191_LUMA_BPSS_SHIFT; 413 >> SAA7191_LUMA_BPSS_SHIFT;
@@ -440,13 +425,13 @@ static int saa7191_get_control(struct i2c_client *client,
440 case SAA7191_CONTROL_FORCE_COLOUR: 425 case SAA7191_CONTROL_FORCE_COLOUR:
441 case SAA7191_CONTROL_CHROMA_GAIN: 426 case SAA7191_CONTROL_CHROMA_GAIN:
442 reg = saa7191_read_reg(client, SAA7191_REG_GAIN); 427 reg = saa7191_read_reg(client, SAA7191_REG_GAIN);
443 if (ctrl->type == SAA7191_CONTROL_FORCE_COLOUR) 428 if (ctrl->id == SAA7191_CONTROL_FORCE_COLOUR)
444 ctrl->value = ((s32)reg & SAA7191_GAIN_COLO) ? 1 : 0; 429 ctrl->value = ((s32)reg & SAA7191_GAIN_COLO) ? 1 : 0;
445 else 430 else
446 ctrl->value = ((s32)reg & SAA7191_GAIN_LFIS_MASK) 431 ctrl->value = ((s32)reg & SAA7191_GAIN_LFIS_MASK)
447 >> SAA7191_GAIN_LFIS_SHIFT; 432 >> SAA7191_GAIN_LFIS_SHIFT;
448 break; 433 break;
449 case SAA7191_CONTROL_HUE: 434 case V4L2_CID_HUE:
450 reg = saa7191_read_reg(client, SAA7191_REG_HUEC); 435 reg = saa7191_read_reg(client, SAA7191_REG_HUEC);
451 if (reg < 0x80) 436 if (reg < 0x80)
452 reg += 0x80; 437 reg += 0x80;
@@ -478,17 +463,17 @@ static int saa7191_get_control(struct i2c_client *client,
478} 463}
479 464
480static int saa7191_set_control(struct i2c_client *client, 465static int saa7191_set_control(struct i2c_client *client,
481 struct saa7191_control *ctrl) 466 struct v4l2_control *ctrl)
482{ 467{
483 u8 reg; 468 u8 reg;
484 int ret = 0; 469 int ret = 0;
485 470
486 switch (ctrl->type) { 471 switch (ctrl->id) {
487 case SAA7191_CONTROL_BANDPASS: 472 case SAA7191_CONTROL_BANDPASS:
488 case SAA7191_CONTROL_BANDPASS_WEIGHT: 473 case SAA7191_CONTROL_BANDPASS_WEIGHT:
489 case SAA7191_CONTROL_CORING: 474 case SAA7191_CONTROL_CORING:
490 reg = saa7191_read_reg(client, SAA7191_REG_LUMA); 475 reg = saa7191_read_reg(client, SAA7191_REG_LUMA);
491 switch (ctrl->type) { 476 switch (ctrl->id) {
492 case SAA7191_CONTROL_BANDPASS: 477 case SAA7191_CONTROL_BANDPASS:
493 reg &= ~SAA7191_LUMA_BPSS_MASK; 478 reg &= ~SAA7191_LUMA_BPSS_MASK;
494 reg |= (ctrl->value << SAA7191_LUMA_BPSS_SHIFT) 479 reg |= (ctrl->value << SAA7191_LUMA_BPSS_SHIFT)
@@ -510,7 +495,7 @@ static int saa7191_set_control(struct i2c_client *client,
510 case SAA7191_CONTROL_FORCE_COLOUR: 495 case SAA7191_CONTROL_FORCE_COLOUR:
511 case SAA7191_CONTROL_CHROMA_GAIN: 496 case SAA7191_CONTROL_CHROMA_GAIN:
512 reg = saa7191_read_reg(client, SAA7191_REG_GAIN); 497 reg = saa7191_read_reg(client, SAA7191_REG_GAIN);
513 if (ctrl->type == SAA7191_CONTROL_FORCE_COLOUR) { 498 if (ctrl->id == SAA7191_CONTROL_FORCE_COLOUR) {
514 if (ctrl->value) 499 if (ctrl->value)
515 reg |= SAA7191_GAIN_COLO; 500 reg |= SAA7191_GAIN_COLO;
516 else 501 else
@@ -522,7 +507,7 @@ static int saa7191_set_control(struct i2c_client *client,
522 } 507 }
523 ret = saa7191_write_reg(client, SAA7191_REG_GAIN, reg); 508 ret = saa7191_write_reg(client, SAA7191_REG_GAIN, reg);
524 break; 509 break;
525 case SAA7191_CONTROL_HUE: 510 case V4L2_CID_HUE:
526 reg = ctrl->value & 0xff; 511 reg = ctrl->value & 0xff;
527 if (reg < 0x80) 512 if (reg < 0x80)
528 reg += 0x80; 513 reg += 0x80;
@@ -568,141 +553,42 @@ static int saa7191_set_control(struct i2c_client *client,
568static int saa7191_command(struct i2c_client *client, unsigned int cmd, 553static int saa7191_command(struct i2c_client *client, unsigned int cmd,
569 void *arg) 554 void *arg)
570{ 555{
571 struct saa7191 *decoder = i2c_get_clientdata(client);
572
573 switch (cmd) { 556 switch (cmd) {
574 case DECODER_GET_CAPABILITIES: { 557 case VIDIOC_INT_G_INPUT_STATUS: {
575 struct video_decoder_capability *cap = arg; 558 u32 *iarg = arg;
576
577 cap->flags = VIDEO_DECODER_PAL | VIDEO_DECODER_NTSC |
578 VIDEO_DECODER_SECAM | VIDEO_DECODER_AUTO;
579 cap->inputs = (client->adapter->id == I2C_HW_SGI_VINO) ? 2 : 1;
580 cap->outputs = 1;
581 break;
582 }
583 case DECODER_GET_STATUS: {
584 int *iarg = arg;
585 u8 status; 559 u8 status;
586 int res = 0; 560 int res = V4L2_IN_ST_NO_SIGNAL;
587 561
588 if (saa7191_read_status(client, &status)) { 562 if (saa7191_read_status(client, &status))
589 return -EIO; 563 return -EIO;
590 }
591 if ((status & SAA7191_STATUS_HLCK) == 0) 564 if ((status & SAA7191_STATUS_HLCK) == 0)
592 res |= DECODER_STATUS_GOOD; 565 res = 0;
593 if (status & SAA7191_STATUS_CODE) 566 if (!(status & SAA7191_STATUS_CODE))
594 res |= DECODER_STATUS_COLOR; 567 res |= V4L2_IN_ST_NO_COLOR;
595 switch (decoder->norm) {
596 case SAA7191_NORM_NTSC:
597 res |= DECODER_STATUS_NTSC;
598 break;
599 case SAA7191_NORM_PAL:
600 res |= DECODER_STATUS_PAL;
601 break;
602 case SAA7191_NORM_SECAM:
603 res |= DECODER_STATUS_SECAM;
604 break;
605 case SAA7191_NORM_AUTO:
606 default:
607 if (status & SAA7191_STATUS_FIDT)
608 res |= DECODER_STATUS_NTSC;
609 else
610 res |= DECODER_STATUS_PAL;
611 break;
612 }
613 *iarg = res; 568 *iarg = res;
614 break; 569 break;
615 } 570 }
616 case DECODER_SET_NORM: {
617 int *iarg = arg;
618
619 switch (*iarg) {
620 case VIDEO_MODE_AUTO:
621 return saa7191_autodetect_norm(client);
622 case VIDEO_MODE_PAL:
623 return saa7191_set_norm(client, SAA7191_NORM_PAL);
624 case VIDEO_MODE_NTSC:
625 return saa7191_set_norm(client, SAA7191_NORM_NTSC);
626 case VIDEO_MODE_SECAM:
627 return saa7191_set_norm(client, SAA7191_NORM_SECAM);
628 default:
629 return -EINVAL;
630 }
631 break;
632 }
633 case DECODER_SET_INPUT: {
634 int *iarg = arg;
635
636 switch (client->adapter->id) {
637 case I2C_HW_SGI_VINO:
638 return saa7191_set_input(client, *iarg);
639 default:
640 if (*iarg != 0)
641 return -EINVAL;
642 }
643 break;
644 }
645 case DECODER_SET_OUTPUT: {
646 int *iarg = arg;
647 571
648 /* not much choice of outputs */ 572 case VIDIOC_QUERYSTD:
649 if (*iarg != 0) 573 return saa7191_autodetect_norm_extended(client, arg);
650 return -EINVAL;
651 break;
652 }
653 case DECODER_ENABLE_OUTPUT: {
654 /* Always enabled */
655 break;
656 }
657 case DECODER_SET_PICTURE: {
658 struct video_picture *pic = arg;
659 unsigned val;
660 int err;
661
662 val = (pic->hue >> 8) - 0x80;
663 574
664 err = saa7191_write_reg(client, SAA7191_REG_HUEC, val); 575 case VIDIOC_S_STD: {
665 if (err) 576 v4l2_std_id *istd = arg;
666 return -EIO;
667 577
668 break; 578 return saa7191_set_norm(client, *istd);
669 } 579 }
670 case DECODER_SAA7191_GET_STATUS: { 580 case VIDIOC_INT_S_VIDEO_ROUTING: {
671 struct saa7191_status *status = arg; 581 struct v4l2_routing *route = arg;
672 u8 status_reg;
673
674 if (saa7191_read_status(client, &status_reg))
675 return -EIO;
676
677 status->signal = ((status_reg & SAA7191_STATUS_HLCK) == 0)
678 ? 1 : 0;
679 status->signal_60hz = (status_reg & SAA7191_STATUS_FIDT)
680 ? 1 : 0;
681 status->color = (status_reg & SAA7191_STATUS_CODE) ? 1 : 0;
682 582
683 status->input = decoder->input; 583 return saa7191_set_input(client, route->input);
684 status->norm = decoder->norm;
685
686 break;
687 } 584 }
688 case DECODER_SAA7191_SET_NORM: { 585
689 int *norm = arg; 586 case VIDIOC_G_CTRL:
690
691 switch (*norm) {
692 case SAA7191_NORM_AUTO:
693 return saa7191_autodetect_norm(client);
694 case SAA7191_NORM_AUTO_EXT:
695 return saa7191_autodetect_norm_extended(client);
696 default:
697 return saa7191_set_norm(client, *norm);
698 }
699 }
700 case DECODER_SAA7191_GET_CONTROL: {
701 return saa7191_get_control(client, arg); 587 return saa7191_get_control(client, arg);
702 } 588
703 case DECODER_SAA7191_SET_CONTROL: { 589 case VIDIOC_S_CTRL:
704 return saa7191_set_control(client, arg); 590 return saa7191_set_control(client, arg);
705 } 591
706 default: 592 default:
707 return -EINVAL; 593 return -EINVAL;
708 } 594 }
@@ -737,7 +623,7 @@ static int saa7191_probe(struct i2c_client *client,
737 printk(KERN_INFO "SAA7191 initialized\n"); 623 printk(KERN_INFO "SAA7191 initialized\n");
738 624
739 decoder->input = SAA7191_INPUT_COMPOSITE; 625 decoder->input = SAA7191_INPUT_COMPOSITE;
740 decoder->norm = SAA7191_NORM_PAL; 626 decoder->norm = V4L2_STD_PAL;
741 627
742 err = saa7191_autodetect_norm(client); 628 err = saa7191_autodetect_norm(client);
743 if (err && (err != -EBUSY)) 629 if (err && (err != -EBUSY))