aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@brturbo.com.br>2006-01-09 12:25:36 -0500
committerMauro Carvalho Chehab <mchehab@brturbo.com.br>2006-01-09 12:25:36 -0500
commite1bc80adaf801bf75ca176b9c1b60b3cceee1e03 (patch)
treeec51175069a1c8a17081ab9cd2829d08bf57706d
parentfc40b261db15d010455ad0a4e2ac59da2ced730f (diff)
V4L/DVB (3232): Several improvements at tvp5150 driver
- Now reset do init tvp5150 registers to its default. - Debug messages improved. - Implemented video standard selection function. Signed-off-by: Mauro Carvalho Chehab <mchehab@brturbo.com.br>
-rw-r--r--drivers/media/video/tvp5150.c423
1 files changed, 362 insertions, 61 deletions
diff --git a/drivers/media/video/tvp5150.c b/drivers/media/video/tvp5150.c
index d62b2302af49..9ed839d688eb 100644
--- a/drivers/media/video/tvp5150.c
+++ b/drivers/media/video/tvp5150.c
@@ -9,6 +9,7 @@
9#include <linux/videodev.h> 9#include <linux/videodev.h>
10#include <linux/delay.h> 10#include <linux/delay.h>
11#include <linux/video_decoder.h> 11#include <linux/video_decoder.h>
12#include <media/v4l2-common.h>
12 13
13#include "tvp5150_reg.h" 14#include "tvp5150_reg.h"
14 15
@@ -28,10 +29,14 @@ static int debug = 0;
28module_param(debug, int, 0); 29module_param(debug, int, 0);
29MODULE_PARM_DESC(debug, "Debug level (0-1)"); 30MODULE_PARM_DESC(debug, "Debug level (0-1)");
30 31
31#define dprintk(num, format, args...) \ 32#define tvp5150_info(fmt, arg...) do { \
33 printk(KERN_INFO "%s %d-%04x: " fmt, c->driver->name, \
34 i2c_adapter_id(c->adapter), c->addr , ## arg); } while (0)
35#define tvp5150_dbg(num, fmt, arg...) \
32 do { \ 36 do { \
33 if (debug >= num) \ 37 if (debug >= num) \
34 printk(format, ##args); \ 38 printk(KERN_DEBUG "%s debug %d-%04x: " fmt, c->driver->name, \
39 i2c_adapter_id(c->adapter), c->addr , ## arg); \
35 } while (0) 40 } while (0)
36 41
37/* supported controls */ 42/* supported controls */
@@ -94,12 +99,14 @@ static inline int tvp5150_read(struct i2c_client *c, unsigned char addr)
94 99
95 buffer[0] = addr; 100 buffer[0] = addr;
96 if (1 != (rc = i2c_master_send(c, buffer, 1))) 101 if (1 != (rc = i2c_master_send(c, buffer, 1)))
97 dprintk(0, "i2c i/o error: rc == %d (should be 1)\n", rc); 102 tvp5150_dbg(0, "i2c i/o error: rc == %d (should be 1)\n", rc);
98 103
99 msleep(10); 104 msleep(10);
100 105
101 if (1 != (rc = i2c_master_recv(c, buffer, 1))) 106 if (1 != (rc = i2c_master_recv(c, buffer, 1)))
102 dprintk(0, "i2c i/o error: rc == %d (should be 1)\n", rc); 107 tvp5150_dbg(0, "i2c i/o error: rc == %d (should be 1)\n", rc);
108
109 tvp5150_dbg(2, "tvp5150: read 0x%02x = 0x%02x\n", addr, buffer[0]);
103 110
104 return (buffer[0]); 111 return (buffer[0]);
105} 112}
@@ -109,13 +116,12 @@ static inline void tvp5150_write(struct i2c_client *c, unsigned char addr,
109{ 116{
110 unsigned char buffer[2]; 117 unsigned char buffer[2];
111 int rc; 118 int rc;
112/* struct tvp5150 *core = i2c_get_clientdata(c); */
113 119
114 buffer[0] = addr; 120 buffer[0] = addr;
115 buffer[1] = value; 121 buffer[1] = value;
116 dprintk(1, "tvp5150: writing 0x%02x 0x%02x\n", buffer[0], buffer[1]); 122 tvp5150_dbg(2, "tvp5150: writing 0x%02x 0x%02x\n", buffer[0], buffer[1]);
117 if (2 != (rc = i2c_master_send(c, buffer, 2))) 123 if (2 != (rc = i2c_master_send(c, buffer, 2)))
118 dprintk(0, "i2c i/o error: rc == %d (should be 2)\n", rc); 124 tvp5150_dbg(0, "i2c i/o error: rc == %d (should be 2)\n", rc);
119} 125}
120 126
121static void dump_reg(struct i2c_client *c) 127static void dump_reg(struct i2c_client *c)
@@ -458,40 +464,325 @@ static inline void tvp5150_selmux(struct i2c_client *c,
458 tvp5150_write(c, TVP5150_VD_IN_SRC_SEL_1, input); 464 tvp5150_write(c, TVP5150_VD_IN_SRC_SEL_1, input);
459}; 465};
460 466
461static inline void tvp5150_reset(struct i2c_client *c) 467struct i2c_reg_value {
468 unsigned char reg;
469 unsigned char value;
470};
471
472/* Default values as sugested at TVP5150AM1 datasheet */
473static const struct i2c_reg_value tvp5150_init_default[] = {
474 { /* 0x00 */
475 TVP5150_VD_IN_SRC_SEL_1,0x00
476 },
477 { /* 0x01 */
478 TVP5150_ANAL_CHL_CTL,0x15
479 },
480 { /* 0x02 */
481 TVP5150_OP_MODE_CTL,0x00
482 },
483 { /* 0x03 */
484 TVP5150_MISC_CTL,0x01
485 },
486 { /* 0x06 */
487 TVP5150_COLOR_KIL_THSH_CTL,0x10
488 },
489 { /* 0x07 */
490 TVP5150_LUMA_PROC_CTL_1,0x60
491 },
492 { /* 0x08 */
493 TVP5150_LUMA_PROC_CTL_2,0x00
494 },
495 { /* 0x09 */
496 TVP5150_BRIGHT_CTL,0x80
497 },
498 { /* 0x0a */
499 TVP5150_SATURATION_CTL,0x80
500 },
501 { /* 0x0b */
502 TVP5150_HUE_CTL,0x00
503 },
504 { /* 0x0c */
505 TVP5150_CONTRAST_CTL,0x80
506 },
507 { /* 0x0d */
508 TVP5150_DATA_RATE_SEL,0x47
509 },
510 { /* 0x0e */
511 TVP5150_LUMA_PROC_CTL_3,0x00
512 },
513 { /* 0x0f */
514 TVP5150_CONF_SHARED_PIN,0x08
515 },
516 { /* 0x11 */
517 TVP5150_ACT_VD_CROP_ST_MSB,0x00
518 },
519 { /* 0x12 */
520 TVP5150_ACT_VD_CROP_ST_LSB,0x00
521 },
522 { /* 0x13 */
523 TVP5150_ACT_VD_CROP_STP_MSB,0x00
524 },
525 { /* 0x14 */
526 TVP5150_ACT_VD_CROP_STP_LSB,0x00
527 },
528 { /* 0x15 */
529 TVP5150_GENLOCK,0x01
530 },
531 { /* 0x16 */
532 TVP5150_HORIZ_SYNC_START,0x80
533 },
534 { /* 0x18 */
535 TVP5150_VERT_BLANKING_START,0x00
536 },
537 { /* 0x19 */
538 TVP5150_VERT_BLANKING_STOP,0x00
539 },
540 { /* 0x1a */
541 TVP5150_CHROMA_PROC_CTL_1,0x0c
542 },
543 { /* 0x1b */
544 TVP5150_CHROMA_PROC_CTL_2,0x14
545 },
546 { /* 0x1c */
547 TVP5150_INT_RESET_REG_B,0x00
548 },
549 { /* 0x1d */
550 TVP5150_INT_ENABLE_REG_B,0x00
551 },
552 { /* 0x1e */
553 TVP5150_INTT_CONFIG_REG_B,0x00
554 },
555 { /* 0x28 */
556 TVP5150_VIDEO_STD,0x00
557 },
558 { /* 0x2e */
559 TVP5150_MACROVISION_ON_CTR,0x0f
560 },
561 { /* 0x2f */
562 TVP5150_MACROVISION_OFF_CTR,0x01
563 },
564 { /* 0xbb */
565 TVP5150_TELETEXT_FIL_ENA,0x00
566 },
567 { /* 0xc0 */
568 TVP5150_INT_STATUS_REG_A,0x00
569 },
570 { /* 0xc1 */
571 TVP5150_INT_ENABLE_REG_A,0x00
572 },
573 { /* 0xc2 */
574 TVP5150_INT_CONF,0x04
575 },
576 { /* 0xc8 */
577 TVP5150_FIFO_INT_THRESHOLD,0x80
578 },
579 { /* 0xc9 */
580 TVP5150_FIFO_RESET,0x00
581 },
582 { /* 0xca */
583 TVP5150_LINE_NUMBER_INT,0x00
584 },
585 { /* 0xcb */
586 TVP5150_PIX_ALIGN_REG_LOW,0x4e
587 },
588 { /* 0xcc */
589 TVP5150_PIX_ALIGN_REG_HIGH,0x00
590 },
591 { /* 0xcd */
592 TVP5150_FIFO_OUT_CTRL,0x01
593 },
594 { /* 0xcf */
595 TVP5150_FULL_FIELD_ENA_1,0x00
596 },
597 { /* 0xd0 */
598 TVP5150_FULL_FIELD_ENA_2,0x00
599 },
600 { /* 0xfc */
601 TVP5150_FULL_FIELD_MODE_REG,0x7f
602 },
603 { /* end of data */
604 0xff,0xff
605 }
606};
607
608/* Default values as sugested at TVP5150AM1 datasheet */
609static const struct i2c_reg_value tvp5150_init_enable[] = {
610 {
611 TVP5150_CONF_SHARED_PIN, 2
612 },{ /* Automatic offset and AGC enabled */
613 TVP5150_ANAL_CHL_CTL, 0x15
614 },{ /* Activate YCrCb output 0x9 or 0xd ? */
615 TVP5150_MISC_CTL, 0x6f
616 },{ /* Activates video std autodetection for all standards */
617 TVP5150_AUTOSW_MSK, 0x0
618 },{ /* Default format: 0x47. For 4:2:2: 0x40 */
619 TVP5150_DATA_RATE_SEL, 0x47
620 },{
621 TVP5150_CHROMA_PROC_CTL_1, 0x0c
622 },{
623 TVP5150_CHROMA_PROC_CTL_2, 0x54
624 },{ /* Non documented, but initialized on WinTV USB2 */
625 0x27, 0x20
626 },{
627 0xff,0xff
628 }
629};
630
631struct i2c_vbi_ram_value {
632 u16 reg;
633 unsigned char values[26];
634};
635
636struct i2c_vbi_ram_value vbi_ram_default[] =
462{ 637{
463 struct tvp5150 *decoder = i2c_get_clientdata(c); 638 {0x010, /* WST SECAM 6 */
639 { 0xaa, 0xaa, 0xff, 0xff , 0xe7, 0x2e, 0x20, 0x26, 0xe6, 0xb4, 0x0e, 0x0, 0x0, 0x0, 0x10, 0x0 }
640 },
641 {0x030, /* WST PAL B 6 */
642 { 0xaa, 0xaa, 0xff, 0xff , 0x27, 0x2e, 0x20, 0x2b, 0xa6, 0x72, 0x10, 0x0, 0x0, 0x0, 0x10, 0x0 }
643 },
644 {0x050, /* WST PAL C 6 */
645 { 0xaa, 0xaa, 0xff, 0xff , 0xe7, 0x2e, 0x20, 0x22, 0xa6, 0x98, 0x0d, 0x0, 0x0, 0x0, 0x10, 0x0 }
646 },
647 {0x070, /* WST NTSC 6 */
648 { 0xaa, 0xaa, 0xff, 0xff , 0x27, 0x2e, 0x20, 0x23, 0x69, 0x93, 0x0d, 0x0, 0x0, 0x0, 0x10, 0x0 }
649 },
650 {0x090, /* NABTS, NTSC 6 */
651 { 0xaa, 0xaa, 0xff, 0xff , 0xe7, 0x2e, 0x20, 0x22, 0x69, 0x93, 0x0d, 0x0, 0x0, 0x0, 0x15, 0x0 }
652 },
653 {0x0b0, /* NABTS, NTSC-J 6 */
654 { 0xaa, 0xaa, 0xff, 0xff , 0xa7, 0x2e, 0x20, 0x23, 0x69, 0x93, 0x0d, 0x0, 0x0, 0x0, 0x10, 0x0 }
655 },
656 {0x0d0, /* CC, PAL/SECAM 6 */
657 { 0xaa, 0x2a, 0xff, 0x3f , 0x04, 0x51, 0x6e, 0x02, 0xa6, 0x7b, 0x09, 0x0, 0x0, 0x0, 0x27, 0x0 }
658 },
659 {0x0f0, /* CC, NTSC 6 */
660 { 0xaa, 0x2a, 0xff, 0x3f , 0x04, 0x51, 0x6e, 0x02, 0x69, 0x8c, 0x09, 0x0, 0x0, 0x0, 0x27, 0x0 }
661 },
662 {0x110, /* WSS, PAL/SECAM 6 */
663 { 0x5b, 0x55, 0xc5, 0xff , 0x0, 0x71, 0x6e, 0x42, 0xa6, 0xcd, 0x0f, 0x0, 0x0, 0x0, 0x3a, 0x0 }
664 },
665 {0x130, /* WSS, NTSC C */
666 { 0x38, 0x00, 0x3f, 0x00 , 0x0, 0x71, 0x6e, 0x43, 0x69, 0x7c, 0x08, 0x0, 0x0, 0x0, 0x39, 0x0 }
667 },
668 {0x150, /* VITC, PAL/SECAM 6 */
669 { 0x0, 0x0, 0x0, 0x0 , 0x0, 0x8f, 0x6d, 0x49, 0xa6, 0x85, 0x08, 0x0, 0x0, 0x0, 0x4c, 0x0 }
670 },
671 {0x170, /* VITC, NTSC 6 */
672 { 0x0, 0x0, 0x0, 0x0 , 0x0, 0x8f, 0x6d, 0x49, 0x69, 0x94, 0x08, 0x0, 0x0, 0x0, 0x4c, 0x0 }
673 },
674 { (u16)-1 }
675};
464 676
465 tvp5150_write(c, TVP5150_CONF_SHARED_PIN, 2); 677static int tvp5150_write_inittab(struct i2c_client *c,
678 const struct i2c_reg_value *regs)
679{
680 while (regs->reg != 0xff) {
681 tvp5150_write(c, regs->reg, regs->value);
682 regs++;
683 }
684 return 0;
685}
466 686
467 /* Automatic offset and AGC enabled */ 687static int tvp5150_vdp_init(struct i2c_client *c,
468 tvp5150_write(c, TVP5150_ANAL_CHL_CTL, 0x15); 688 const struct i2c_vbi_ram_value *regs)
689{
690 unsigned int i;
469 691
470 /* Normal Operation */ 692 /* Disable Full Field */
471// tvp5150_write(c, TVP5150_OP_MODE_CTL, 0x00); 693 tvp5150_write(c, TVP5150_FULL_FIELD_ENA_1, 0);
472 694
473 /* Activate YCrCb output 0x9 or 0xd ? */ 695 /* Before programming, Line mode should be at 0xff */
474 tvp5150_write(c, TVP5150_MISC_CTL, 0x6f); 696 for (i=TVP5150_FULL_FIELD_ENA_2; i<=TVP5150_LINE_MODE_REG_44; i++)
697 tvp5150_write(c, i, 0xff);
475 698
476 /* Activates video std autodetection for all standards */ 699 /* Load Ram Table */
477 tvp5150_write(c, TVP5150_AUTOSW_MSK, 0x0); 700 while (regs->reg != (u16)-1 ) {
701 tvp5150_write(c, TVP5150_CONF_RAM_ADDR_HIGH,regs->reg>>8);
702 tvp5150_write(c, TVP5150_CONF_RAM_ADDR_LOW,regs->reg);
478 703
479 /* Default format: 0x47, 4:2:2: 0x40 */ 704 for (i=0;i<16;i++)
480 tvp5150_write(c, TVP5150_DATA_RATE_SEL, 0x47); 705 tvp5150_write(c, TVP5150_VDP_CONF_RAM_DATA,regs->values[i]);
481 706
482 tvp5150_selmux(c, decoder->input); 707 regs++;
708 }
709 return 0;
710}
483 711
484 tvp5150_write(c, TVP5150_CHROMA_PROC_CTL_1, 0x0c); 712static int tvp5150_set_std(struct i2c_client *c, v4l2_std_id std)
485 tvp5150_write(c, TVP5150_CHROMA_PROC_CTL_2, 0x54); 713{
714 struct tvp5150 *decoder = i2c_get_clientdata(c);
715 int fmt=0;
716
717 decoder->norm=std;
718
719 /* First tests should be against specific std */
720
721 if (std == V4L2_STD_ALL) {
722 fmt=0; /* Autodetect mode */
723 } else if (std & V4L2_STD_NTSC_443) {
724 fmt=0xa;
725 } else if (std & V4L2_STD_PAL_M) {
726 fmt=0x6;
727 } else if (std & (V4L2_STD_PAL_N| V4L2_STD_PAL_Nc)) {
728 fmt=0x8;
729 } else {
730 /* Then, test against generic ones */
731 if (std & V4L2_STD_NTSC) {
732 fmt=0x2;
733 } else if (std & V4L2_STD_PAL) {
734 fmt=0x4;
735 } else if (std & V4L2_STD_SECAM) {
736 fmt=0xc;
737 }
738 }
486 739
487 tvp5150_write(c, 0x27, 0x20); /* ?????????? */ 740 tvp5150_dbg(1,"Set video std register to %d.\n",fmt);
741 tvp5150_write(c, TVP5150_VIDEO_STD, fmt);
488 742
489 tvp5150_write(c, TVP5150_VIDEO_STD, 0x0); /* Auto switch */ 743 return 0;
744}
745
746static inline void tvp5150_reset(struct i2c_client *c)
747{
748 u8 type, ver_656, msb_id, lsb_id, msb_rom, lsb_rom;
749 struct tvp5150 *decoder = i2c_get_clientdata(c);
750
751 type=tvp5150_read(c,TVP5150_AUTOSW_MSK);
752 msb_id=tvp5150_read(c,TVP5150_MSB_DEV_ID);
753 lsb_id=tvp5150_read(c,TVP5150_LSB_DEV_ID);
754 msb_rom=tvp5150_read(c,TVP5150_ROM_MAJOR_VER);
755 lsb_rom=tvp5150_read(c,TVP5150_ROM_MINOR_VER);
756
757 if (type==0xdc) {
758 ver_656=tvp5150_read(c,TVP5150_REV_SELECT);
759 tvp5150_info("tvp%02x%02xam1 detected 656 version is %d.\n",msb_id, lsb_id,ver_656);
760 } else if (type==0xfc) {
761 tvp5150_info("tvp%02x%02xa detected.\n",msb_id, lsb_id);
762 } else {
763 tvp5150_info("unknown tvp%02x%02x chip detected(%d).\n",msb_id,lsb_id,type);
764 }
765 tvp5150_info("Rom ver is %d.%d\n",msb_rom,lsb_rom);
490 766
767 /* Initializes TVP5150 to its default values */
768 tvp5150_write_inittab(c, tvp5150_init_default);
769
770 /* Initializes VDP registers */
771 tvp5150_vdp_init(c, vbi_ram_default);
772
773 /* Selects decoder input */
774 tvp5150_selmux(c, decoder->input);
775
776 /* Initializes TVP5150 to stream enabled values */
777 tvp5150_write_inittab(c, tvp5150_init_enable);
778
779 /* Initialize image preferences */
491 tvp5150_write(c, TVP5150_BRIGHT_CTL, decoder->bright >> 8); 780 tvp5150_write(c, TVP5150_BRIGHT_CTL, decoder->bright >> 8);
492 tvp5150_write(c, TVP5150_CONTRAST_CTL, decoder->contrast >> 8); 781 tvp5150_write(c, TVP5150_CONTRAST_CTL, decoder->contrast >> 8);
493 tvp5150_write(c, TVP5150_SATURATION_CTL, decoder->contrast >> 8); 782 tvp5150_write(c, TVP5150_SATURATION_CTL, decoder->contrast >> 8);
494 tvp5150_write(c, TVP5150_HUE_CTL, (decoder->hue - 32768) >> 8); 783 tvp5150_write(c, TVP5150_HUE_CTL, (decoder->hue - 32768) >> 8);
784
785 tvp5150_set_std(c, decoder->norm);
495}; 786};
496 787
497static int tvp5150_get_ctrl(struct i2c_client *c, struct v4l2_control *ctrl) 788static int tvp5150_get_ctrl(struct i2c_client *c, struct v4l2_control *ctrl)
@@ -539,20 +830,28 @@ static int tvp5150_set_ctrl(struct i2c_client *c, struct v4l2_control *ctrl)
539/**************************************************************************** 830/****************************************************************************
540 I2C Command 831 I2C Command
541 ****************************************************************************/ 832 ****************************************************************************/
542static int tvp5150_command(struct i2c_client *client, 833static int tvp5150_command(struct i2c_client *c,
543 unsigned int cmd, void *arg) 834 unsigned int cmd, void *arg)
544{ 835{
545 struct tvp5150 *decoder = i2c_get_clientdata(client); 836 struct tvp5150 *decoder = i2c_get_clientdata(c);
546 837
547 switch (cmd) { 838 switch (cmd) {
548 839
549 case 0: 840 case 0:
841 case VIDIOC_INT_RESET:
550 case DECODER_INIT: 842 case DECODER_INIT:
551 tvp5150_reset(client); 843 tvp5150_reset(c);
844 break;
845 case VIDIOC_S_STD:
846 if (decoder->norm == *(v4l2_std_id *)arg)
847 break;
848 return tvp5150_set_std(c, *(v4l2_std_id *)arg);
849 case VIDIOC_G_STD:
850 *(v4l2_std_id *)arg = decoder->norm;
552 break; 851 break;
553 852
554 case DECODER_DUMP: 853 case DECODER_DUMP:
555 dump_reg(client); 854 dump_reg(c);
556 break; 855 break;
557 856
558 case DECODER_GET_CAPABILITIES: 857 case DECODER_GET_CAPABILITIES:
@@ -611,7 +910,7 @@ static int tvp5150_command(struct i2c_client *client,
611 } 910 }
612 911
613 decoder->input = *iarg; 912 decoder->input = *iarg;
614 tvp5150_selmux(client, decoder->input); 913 tvp5150_selmux(c, decoder->input);
615 914
616 break; 915 break;
617 } 916 }
@@ -631,7 +930,7 @@ static int tvp5150_command(struct i2c_client *client,
631 930
632 decoder->enable = (*iarg != 0); 931 decoder->enable = (*iarg != 0);
633 932
634 tvp5150_selmux(client, decoder->input); 933 tvp5150_selmux(c, decoder->input);
635 934
636 break; 935 break;
637 } 936 }
@@ -640,7 +939,7 @@ static int tvp5150_command(struct i2c_client *client,
640 struct v4l2_queryctrl *qc = arg; 939 struct v4l2_queryctrl *qc = arg;
641 int i; 940 int i;
642 941
643 dprintk(1, KERN_DEBUG "VIDIOC_QUERYCTRL"); 942 tvp5150_dbg(1, "VIDIOC_QUERYCTRL called\n");
644 943
645 for (i = 0; i < ARRAY_SIZE(tvp5150_qctrl); i++) 944 for (i = 0; i < ARRAY_SIZE(tvp5150_qctrl); i++)
646 if (qc->id && qc->id == tvp5150_qctrl[i].id) { 945 if (qc->id && qc->id == tvp5150_qctrl[i].id) {
@@ -654,15 +953,14 @@ static int tvp5150_command(struct i2c_client *client,
654 case VIDIOC_G_CTRL: 953 case VIDIOC_G_CTRL:
655 { 954 {
656 struct v4l2_control *ctrl = arg; 955 struct v4l2_control *ctrl = arg;
657 dprintk(1, KERN_DEBUG "VIDIOC_G_CTRL"); 956 tvp5150_dbg(1, "VIDIOC_G_CTRL called\n");
658 957
659 return tvp5150_get_ctrl(client, ctrl); 958 return tvp5150_get_ctrl(c, ctrl);
660 } 959 }
661 case VIDIOC_S_CTRL: 960 case VIDIOC_S_CTRL:
662 { 961 {
663 struct v4l2_control *ctrl = arg; 962 struct v4l2_control *ctrl = arg;
664 u8 i, n; 963 u8 i, n;
665 dprintk(1, KERN_DEBUG "VIDIOC_S_CTRL");
666 n = sizeof(tvp5150_qctrl) / sizeof(tvp5150_qctrl[0]); 964 n = sizeof(tvp5150_qctrl) / sizeof(tvp5150_qctrl[0]);
667 for (i = 0; i < n; i++) 965 for (i = 0; i < n; i++)
668 if (ctrl->id == tvp5150_qctrl[i].id) { 966 if (ctrl->id == tvp5150_qctrl[i].id) {
@@ -671,11 +969,10 @@ static int tvp5150_command(struct i2c_client *client,
671 || ctrl->value > 969 || ctrl->value >
672 tvp5150_qctrl[i].maximum) 970 tvp5150_qctrl[i].maximum)
673 return -ERANGE; 971 return -ERANGE;
674 dprintk(1, 972 tvp5150_dbg(1,
675 KERN_DEBUG 973 "VIDIOC_S_CTRL: id=%d, value=%d\n",
676 "VIDIOC_S_CTRL: id=%d, value=%d",
677 ctrl->id, ctrl->value); 974 ctrl->id, ctrl->value);
678 return tvp5150_set_ctrl(client, ctrl); 975 return tvp5150_set_ctrl(c, ctrl);
679 } 976 }
680 return -EINVAL; 977 return -EINVAL;
681 } 978 }
@@ -686,25 +983,25 @@ static int tvp5150_command(struct i2c_client *client,
686 if (decoder->bright != pic->brightness) { 983 if (decoder->bright != pic->brightness) {
687 /* We want 0 to 255 we get 0-65535 */ 984 /* We want 0 to 255 we get 0-65535 */
688 decoder->bright = pic->brightness; 985 decoder->bright = pic->brightness;
689 tvp5150_write(client, TVP5150_BRIGHT_CTL, 986 tvp5150_write(c, TVP5150_BRIGHT_CTL,
690 decoder->bright >> 8); 987 decoder->bright >> 8);
691 } 988 }
692 if (decoder->contrast != pic->contrast) { 989 if (decoder->contrast != pic->contrast) {
693 /* We want 0 to 255 we get 0-65535 */ 990 /* We want 0 to 255 we get 0-65535 */
694 decoder->contrast = pic->contrast; 991 decoder->contrast = pic->contrast;
695 tvp5150_write(client, TVP5150_CONTRAST_CTL, 992 tvp5150_write(c, TVP5150_CONTRAST_CTL,
696 decoder->contrast >> 8); 993 decoder->contrast >> 8);
697 } 994 }
698 if (decoder->sat != pic->colour) { 995 if (decoder->sat != pic->colour) {
699 /* We want 0 to 255 we get 0-65535 */ 996 /* We want 0 to 255 we get 0-65535 */
700 decoder->sat = pic->colour; 997 decoder->sat = pic->colour;
701 tvp5150_write(client, TVP5150_SATURATION_CTL, 998 tvp5150_write(c, TVP5150_SATURATION_CTL,
702 decoder->contrast >> 8); 999 decoder->contrast >> 8);
703 } 1000 }
704 if (decoder->hue != pic->hue) { 1001 if (decoder->hue != pic->hue) {
705 /* We want -128 to 127 we get 0-65535 */ 1002 /* We want -128 to 127 we get 0-65535 */
706 decoder->hue = pic->hue; 1003 decoder->hue = pic->hue;
707 tvp5150_write(client, TVP5150_HUE_CTL, 1004 tvp5150_write(c, TVP5150_HUE_CTL,
708 (decoder->hue - 32768) >> 8); 1005 (decoder->hue - 32768) >> 8);
709 } 1006 }
710 break; 1007 break;
@@ -729,12 +1026,12 @@ static struct i2c_client client_template = {
729static int tvp5150_detect_client(struct i2c_adapter *adapter, 1026static int tvp5150_detect_client(struct i2c_adapter *adapter,
730 int address, int kind) 1027 int address, int kind)
731{ 1028{
732 struct i2c_client *client; 1029 struct i2c_client *c;
733 struct tvp5150 *core; 1030 struct tvp5150 *core;
734 int rv; 1031 int rv;
735 1032
736 dprintk(1, 1033 if (debug)
737 KERN_INFO 1034 printk( KERN_INFO
738 "tvp5150.c: detecting tvp5150 client on address 0x%x\n", 1035 "tvp5150.c: detecting tvp5150 client on address 0x%x\n",
739 address << 1); 1036 address << 1);
740 1037
@@ -747,22 +1044,22 @@ static int tvp5150_detect_client(struct i2c_adapter *adapter,
747 I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) 1044 I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
748 return 0; 1045 return 0;
749 1046
750 client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL); 1047 c = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
751 if (client == 0) 1048 if (c == 0)
752 return -ENOMEM; 1049 return -ENOMEM;
753 memcpy(client, &client_template, sizeof(struct i2c_client)); 1050 memcpy(c, &client_template, sizeof(struct i2c_client));
754 1051
755 core = kmalloc(sizeof(struct tvp5150), GFP_KERNEL); 1052 core = kmalloc(sizeof(struct tvp5150), GFP_KERNEL);
756 if (core == 0) { 1053 if (core == 0) {
757 kfree(client); 1054 kfree(c);
758 return -ENOMEM; 1055 return -ENOMEM;
759 } 1056 }
760 memset(core, 0, sizeof(struct tvp5150)); 1057 memset(core, 0, sizeof(struct tvp5150));
761 i2c_set_clientdata(client, core); 1058 i2c_set_clientdata(c, core);
762 1059
763 rv = i2c_attach_client(client); 1060 rv = i2c_attach_client(c);
764 1061
765 core->norm = VIDEO_MODE_AUTO; 1062 core->norm = V4L2_STD_ALL;
766 core->input = 2; 1063 core->input = 2;
767 core->enable = 1; 1064 core->enable = 1;
768 core->bright = 32768; 1065 core->bright = 32768;
@@ -771,37 +1068,41 @@ static int tvp5150_detect_client(struct i2c_adapter *adapter,
771 core->sat = 32768; 1068 core->sat = 32768;
772 1069
773 if (rv) { 1070 if (rv) {
774 kfree(client); 1071 kfree(c);
775 kfree(core); 1072 kfree(core);
776 return rv; 1073 return rv;
777 } 1074 }
778 1075
779 if (debug > 1) 1076 if (debug > 1)
780 dump_reg(client); 1077 dump_reg(c);
781 return 0; 1078 return 0;
782} 1079}
783 1080
784static int tvp5150_attach_adapter(struct i2c_adapter *adapter) 1081static int tvp5150_attach_adapter(struct i2c_adapter *adapter)
785{ 1082{
786 dprintk(1, 1083 if (debug)
787 KERN_INFO 1084 printk( KERN_INFO
788 "tvp5150.c: starting probe for adapter %s (0x%x)\n", 1085 "tvp5150.c: starting probe for adapter %s (0x%x)\n",
789 adapter->name, adapter->id); 1086 adapter->name, adapter->id);
790 return i2c_probe(adapter, &addr_data, &tvp5150_detect_client); 1087 return i2c_probe(adapter, &addr_data, &tvp5150_detect_client);
791} 1088}
792 1089
793static int tvp5150_detach_client(struct i2c_client *client) 1090static int tvp5150_detach_client(struct i2c_client *c)
794{ 1091{
795 struct tvp5150 *decoder = i2c_get_clientdata(client); 1092 struct tvp5150 *decoder = i2c_get_clientdata(c);
796 int err; 1093 int err;
797 1094
798 err = i2c_detach_client(client); 1095 tvp5150_dbg(1,
1096 "tvp5150.c: removing tvp5150 adapter on address 0x%x\n",
1097 c->addr << 1);
1098
1099 err = i2c_detach_client(c);
799 if (err) { 1100 if (err) {
800 return err; 1101 return err;
801 } 1102 }
802 1103
803 kfree(decoder); 1104 kfree(decoder);
804 kfree(client); 1105 kfree(c);
805 1106
806 return 0; 1107 return 0;
807} 1108}