📄 tvp5150_ti.c
字号:
571 {0x190, /* Video Program System (VPS), PAL */
572 {V4L2_SLICED_VPS,16,16,0},
573 { 0xaa, 0xaa, 0xff, 0xff, 0xba, 0xce, 0x2b, 0x0d,
574 0xa6, 0xda, 0x0b, 0x00, 0x00, 0x00, 0x60, 0x00 }
575 },
576 /* 0x1d0 User programmable */
577
578 /* End of struct */
579 { (u16)-1 }
580 };
581
582 static int tvp5150_write_inittab(struct i2c_client *c,
583 const struct i2c_reg_value *regs)
584 {
585 while (regs->reg != 0xff) {
586 tvp5150_write(c, regs->reg, regs->value);
587 regs++;
588 }
589 return 0;
590 }
591
592 static int tvp5150_vdp_init(struct i2c_client *c,
593 const struct i2c_vbi_ram_value *regs)
594 {
595 unsigned int i;
596
597 /* Disable Full Field */
598 tvp5150_write(c, TVP5150_FULL_FIELD_ENA, 0);
599
600 /* Before programming, Line mode should be at 0xff */
601 for (i=TVP5150_LINE_MODE_INI; i<=TVP5150_LINE_MODE_END; i++)
602 tvp5150_write(c, i, 0xff);
603
604 /* Load Ram Table */
605 while (regs->reg != (u16)-1 ) {
606 tvp5150_write(c, TVP5150_CONF_RAM_ADDR_HIGH,regs->reg>>8);
607 tvp5150_write(c, TVP5150_CONF_RAM_ADDR_LOW,regs->reg);
608
609 for (i=0;i<16;i++)
610 tvp5150_write(c, TVP5150_VDP_CONF_RAM_DATA,regs->values[i]);
611
612 regs++;
613 }
614 return 0;
615 }
616
617 /* Fills VBI capabilities based on i2c_vbi_ram_value struct */
618 static void tvp5150_vbi_get_cap(const struct i2c_vbi_ram_value *regs,
619 struct v4l2_sliced_vbi_cap *cap)
620 {
621 int line;
622
623 memset(cap, 0, sizeof *cap);
624
625 while (regs->reg != (u16)-1 ) {
626 for (line=regs->type.ini_line;line<=regs->type.end_line;line++) {
627 cap->service_lines[0][line] |= regs->type.vbi_type;
628 }
629 cap->service_set |= regs->type.vbi_type;
630
631 regs++;
632 }
633 }
634
635 /* Set vbi processing
636 * type - one of tvp5150_vbi_types
637 * line - line to gather data
638 * fields: bit 0 field1, bit 1, field2
639 * flags (default=0xf0) is a bitmask, were set means:
640 * bit 7: enable filtering null bytes on CC
641 * bit 6: send data also to FIFO
642 * bit 5: don't allow data with errors on FIFO
643 * bit 4: enable ECC when possible
644 * pix_align = pix alignment:
645 * LSB = field1
646 * MSB = field2
647 */
648 static int tvp5150_set_vbi(struct i2c_client *c,
649 const struct i2c_vbi_ram_value *regs,
650 unsigned int type,u8 flags, int line,
651 const int fields)
652 {
653 struct tvp5150 *decoder = i2c_get_clientdata(c);
654 v4l2_std_id std=decoder->norm;
655 u8 reg;
656 int pos=0;
657
658 if (std == V4L2_STD_ALL) {
659 tvp5150_err("VBI can't be configured without knowing number of lines\n");
660 return 0;
661 } else if (std && V4L2_STD_625_50) {
662 /* Don't follow NTSC Line number convension */
663 line += 3;
664 }
665
666 if (line<6||line>27)
667 return 0;
668
669 while (regs->reg != (u16)-1 ) {
670 if ((type & regs->type.vbi_type) &&
671 (line>=regs->type.ini_line) &&
672 (line<=regs->type.end_line)) {
673 type=regs->type.vbi_type;
674 break;
675 }
676
677 regs++;
678 pos++;
679 }
680 if (regs->reg == (u16)-1)
681 return 0;
682
683 type=pos | (flags & 0xf0);
684 reg=((line-6)<<1)+TVP5150_LINE_MODE_INI;
685
686 if (fields&1) {
687 tvp5150_write(c, reg, type);
688 }
689
690 if (fields&2) {
691 tvp5150_write(c, reg+1, type);
692 }
693
694 return type;
695 }
696
697 static int tvp5150_get_vbi(struct i2c_client *c,
698 const struct i2c_vbi_ram_value *regs, int line)
699 {
700 struct tvp5150 *decoder = i2c_get_clientdata(c);
701 v4l2_std_id std=decoder->norm;
702 u8 reg;
703 int pos, type=0;
704
705 if (std == V4L2_STD_ALL) {
706 tvp5150_err("VBI can't be configured without knowing number of lines\n");
707 return 0;
708 } else if (std && V4L2_STD_625_50) {
709 /* Don't follow NTSC Line number convension */
710 line += 3;
711 }
712
713 if (line<6||line>27)
714 return 0;
715
716 reg=((line-6)<<1)+TVP5150_LINE_MODE_INI;
717
718 pos=tvp5150_read(c, reg)&0x0f;
719 if (pos<0x0f)
720 type=regs[pos].type.vbi_type;
721
722 pos=tvp5150_read(c, reg+1)&0x0f;
723 if (pos<0x0f)
724 type|=regs[pos].type.vbi_type;
725
726 return type;
727 }
728 static int tvp5150_set_std(struct i2c_client *c, v4l2_std_id std)
729 {
730 struct tvp5150 *decoder = i2c_get_clientdata(c);
731 int fmt=0;
732
733 decoder->norm=std;
734
735 /* First tests should be against specific std */
736
737 if (std == V4L2_STD_ALL) {
738 fmt=0; /* Autodetect mode */
739 } else if (std & V4L2_STD_NTSC_443) {
740 fmt=0xa;
741 } else if (std & V4L2_STD_PAL_M) {
742 fmt=0x6;
743 } else if (std & (V4L2_STD_PAL_N| V4L2_STD_PAL_Nc)) {
744 fmt=0x8;
745 } else {
746 /* Then, test against generic ones */
747 if (std & V4L2_STD_NTSC) {
748 fmt=0x2;
749 } else if (std & V4L2_STD_PAL) {
750 fmt=0x4;
751 } else if (std & V4L2_STD_SECAM) {
752 fmt=0xc;
753 }
754 }
755
756 tvp5150_dbg(1,"Set video std register to %d.\n",fmt);
757 tvp5150_write(c, TVP5150_VIDEO_STD, fmt);
758
759 return 0;
760 }
761
762 static inline void tvp5150_reset(struct i2c_client *c)
763 {
764 u8 msb_id, lsb_id, msb_rom, lsb_rom;
765 struct tvp5150 *decoder = i2c_get_clientdata(c);
766
767 msb_id=tvp5150_read(c,TVP5150_MSB_DEV_ID);
768 lsb_id=tvp5150_read(c,TVP5150_LSB_DEV_ID);
769 msb_rom=tvp5150_read(c,TVP5150_ROM_MAJOR_VER);
770 lsb_rom=tvp5150_read(c,TVP5150_ROM_MINOR_VER);
771
772 if ((msb_rom==4)&&(lsb_rom==0)) { /* Is TVP5150AM1 */
773 tvp5150_info("tvp%02x%02xam1 detected.\n",msb_id, lsb_id);
774
775 /* ITU-T BT.656.4 timing */
776 tvp5150_write(c,TVP5150_REV_SELECT,0);
777 } else {
778 if ((msb_rom==3)||(lsb_rom==0x21)) { /* Is TVP5150A */
779 tvp5150_info("tvp%02x%02xa detected.\n",msb_id, lsb_id);
780 } else {
781 tvp5150_info("*** unknown tvp%02x%02x chip detected.\n",msb_id,lsb_id);
782 tvp5150_info("*** Rom ver is %d.%d\n",msb_rom,lsb_rom);
783 }
784 }
785
786 /* Initializes TVP5150 to its default values */
787 tvp5150_write_inittab(c, tvp5150_init_default);
788
789 /* Initializes VDP registers */
790 tvp5150_vdp_init(c, vbi_ram_default);
791
792 /* Selects decoder input */
793 tvp5150_selmux(c, decoder->input);
794
795 /* Initializes TVP5150 to stream enabled values */
796 tvp5150_write_inittab(c, tvp5150_init_enable);
797
798 /* Initialize image preferences */
799 tvp5150_write(c, TVP5150_BRIGHT_CTL, decoder->bright >> 8);
800 tvp5150_write(c, TVP5150_CONTRAST_CTL, decoder->contrast >> 8);
801 tvp5150_write(c, TVP5150_SATURATION_CTL, decoder->contrast >> 8);
802 tvp5150_write(c, TVP5150_HUE_CTL, (decoder->hue - 32768) >> 8);
803
804 tvp5150_set_std(c, decoder->norm);
805 };
806
807 static int tvp5150_get_ctrl(struct i2c_client *c, struct v4l2_control *ctrl)
808 {
809 /* struct tvp5150 *decoder = i2c_get_clientdata(c); */
810
811 switch (ctrl->id) {
812 case V4L2_CID_BRIGHTNESS:
813 ctrl->value = tvp5150_read(c, TVP5150_BRIGHT_CTL);
814 return 0;
815 case V4L2_CID_CONTRAST:
816 ctrl->value = tvp5150_read(c, TVP5150_CONTRAST_CTL);
817 return 0;
818 case V4L2_CID_SATURATION:
819 ctrl->value = tvp5150_read(c, TVP5150_SATURATION_CTL);
820 return 0;
821 case V4L2_CID_HUE:
822 ctrl->value = tvp5150_read(c, TVP5150_HUE_CTL);
823 return 0;
824 }
825 return -EINVAL;
826 }
827
828 static int tvp5150_set_ctrl(struct i2c_client *c, struct v4l2_control *ctrl)
829 {
830 /* struct tvp5150 *decoder = i2c_get_clientdata(c); */
831
832 switch (ctrl->id) {
833 case V4L2_CID_BRIGHTNESS:
834 tvp5150_write(c, TVP5150_BRIGHT_CTL, ctrl->value);
835 return 0;
836 case V4L2_CID_CONTRAST:
837 tvp5150_write(c, TVP5150_CONTRAST_CTL, ctrl->value);
838 return 0;
839 case V4L2_CID_SATURATION:
840 tvp5150_write(c, TVP5150_SATURATION_CTL, ctrl->value);
841 return 0;
842 case V4L2_CID_HUE:
843 tvp5150_write(c, TVP5150_HUE_CTL, ctrl->value);
844 return 0;
845 }
846 return -EINVAL;
847 }
848
849 /****************************************************************************
850 I2C Command
851 ****************************************************************************/
852 static int tvp5150_command(struct i2c_client *c,
853 unsigned int cmd, void *arg)
854 {
855 struct tvp5150 *decoder = i2c_get_clientdata(c);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -