9 #include <linux/slab.h>
10 #include <linux/videodev2.h>
12 #include <linux/module.h>
20 #define TVP5150_H_MAX 720
21 #define TVP5150_V_MAX_525_60 480
22 #define TVP5150_V_MAX_OTHERS 576
23 #define TVP5150_MAX_CROP_LEFT 511
24 #define TVP5150_MAX_CROP_TOP 127
25 #define TVP5150_CROP_SHIFT 2
67 v4l2_err(sd,
"i2c i/o error: rc == %d (should be 1)\n", rc);
75 v4l2_err(sd,
"i2c i/o error: rc == %d (should be 1)\n", rc);
79 v4l2_dbg(2,
debug, sd,
"tvp5150: read 0x%02x = 0x%02x\n", addr, buffer[0]);
84 static inline void tvp5150_write(
struct v4l2_subdev *sd,
unsigned char addr,
87 struct i2c_client *c = v4l2_get_subdevdata(sd);
88 unsigned char buffer[2];
93 v4l2_dbg(2,
debug, sd,
"tvp5150: writing 0x%02x 0x%02x\n", buffer[0], buffer[1]);
95 v4l2_dbg(0,
debug, sd,
"i2c i/o error: rc == %d (should be 2)\n", rc);
99 const u8 end,
int max_line)
103 while (init != (
u8)(end + 1)) {
104 if ((i % max_line) == 0) {
107 printk(
"tvp5150: %s reg 0x%02x = ", s, init);
109 printk(
"%02x ", tvp5150_read(sd, init));
117 static int tvp5150_log_status(
struct v4l2_subdev *sd)
119 printk(
"tvp5150: Video input source selection #1 = 0x%02x\n",
121 printk(
"tvp5150: Analog channel controls = 0x%02x\n",
123 printk(
"tvp5150: Operation mode controls = 0x%02x\n",
125 printk(
"tvp5150: Miscellaneous controls = 0x%02x\n",
127 printk(
"tvp5150: Autoswitch mask= 0x%02x\n",
129 printk(
"tvp5150: Color killer threshold control = 0x%02x\n",
131 printk(
"tvp5150: Luminance processing controls #1 #2 and #3 = %02x %02x %02x\n",
135 printk(
"tvp5150: Brightness control = 0x%02x\n",
137 printk(
"tvp5150: Color saturation control = 0x%02x\n",
139 printk(
"tvp5150: Hue control = 0x%02x\n",
141 printk(
"tvp5150: Contrast control = 0x%02x\n",
143 printk(
"tvp5150: Outputs and data rates select = 0x%02x\n",
145 printk(
"tvp5150: Configuration shared pins = 0x%02x\n",
147 printk(
"tvp5150: Active video cropping start = 0x%02x%02x\n",
150 printk(
"tvp5150: Active video cropping stop = 0x%02x%02x\n",
153 printk(
"tvp5150: Genlock/RTC = 0x%02x\n",
155 printk(
"tvp5150: Horizontal sync start = 0x%02x\n",
157 printk(
"tvp5150: Vertical blanking start = 0x%02x\n",
159 printk(
"tvp5150: Vertical blanking stop = 0x%02x\n",
161 printk(
"tvp5150: Chrominance processing control #1 and #2 = %02x %02x\n",
164 printk(
"tvp5150: Interrupt reset register B = 0x%02x\n",
166 printk(
"tvp5150: Interrupt enable register B = 0x%02x\n",
168 printk(
"tvp5150: Interrupt configuration register B = 0x%02x\n",
170 printk(
"tvp5150: Video standard = 0x%02x\n",
172 printk(
"tvp5150: Chroma gain factor: Cb=0x%02x Cr=0x%02x\n",
175 printk(
"tvp5150: Macrovision on counter = 0x%02x\n",
177 printk(
"tvp5150: Macrovision off counter = 0x%02x\n",
179 printk(
"tvp5150: ITU-R BT.656.%d timing(TVP5150AM1 only)\n",
181 printk(
"tvp5150: Device ID = %02x%02x\n",
184 printk(
"tvp5150: ROM version = (hex) %02x.%02x\n",
187 printk(
"tvp5150: Vertical line count = 0x%02x%02x\n",
190 printk(
"tvp5150: Interrupt status register B = 0x%02x\n",
192 printk(
"tvp5150: Interrupt active register B = 0x%02x\n",
194 printk(
"tvp5150: Status regs #1 to #5 = %02x %02x %02x %02x %02x\n",
206 printk(
"tvp5150: Teletext filter enable = 0x%02x\n",
208 printk(
"tvp5150: Interrupt status register A = 0x%02x\n",
210 printk(
"tvp5150: Interrupt enable register A = 0x%02x\n",
212 printk(
"tvp5150: Interrupt configuration = 0x%02x\n",
214 printk(
"tvp5150: VDP status register = 0x%02x\n",
216 printk(
"tvp5150: FIFO word count = 0x%02x\n",
218 printk(
"tvp5150: FIFO interrupt threshold = 0x%02x\n",
220 printk(
"tvp5150: FIFO reset = 0x%02x\n",
222 printk(
"tvp5150: Line number interrupt = 0x%02x\n",
224 printk(
"tvp5150: Pixel alignment register = 0x%02x%02x\n",
227 printk(
"tvp5150: FIFO output control = 0x%02x\n",
229 printk(
"tvp5150: Full field enable = 0x%02x\n",
231 printk(
"tvp5150: Full field mode register = 0x%02x\n",
255 static inline void tvp5150_selmux(
struct v4l2_subdev *sd)
258 struct tvp5150 *decoder = to_tvp5150(sd);
265 switch (decoder->
input) {
277 v4l2_dbg(1,
debug, sd,
"Selecting video route: route input=%i, output=%i "
278 "=> tvp5150 input=%i, opmode=%i\n",
290 v4l2_err(sd,
"%s: failed with error = %d\n", __func__, val);
295 val = (val & ~0x40) | 0x10;
297 val = (val & ~0x10) | 0x40;
491 {V4L2_SLICED_TELETEXT_SECAM,6,23,1},
492 { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x26,
493 0xe6, 0xb4, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00 }
498 { 0xaa, 0xaa, 0xff, 0xff, 0x27, 0x2e, 0x20, 0x2b,
499 0xa6, 0x72, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00 }
503 {V4L2_SLICED_TELETEXT_PAL_C,6,22,1},
504 { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x22,
505 0xa6, 0x98, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 }
508 {V4L2_SLICED_TELETEXT_NTSC_B,10,21,1},
509 { 0xaa, 0xaa, 0xff, 0xff, 0x27, 0x2e, 0x20, 0x23,
510 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 }
513 {V4L2_SLICED_TELETEXT_NTSC_C,10,21,1},
514 { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x22,
515 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x15, 0x00 }
518 {V4L2_SLICED_TELETEXT_NTSC_D,10,21,1},
519 { 0xaa, 0xaa, 0xff, 0xff, 0xa7, 0x2e, 0x20, 0x23,
520 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 }
523 {V4L2_SLICED_CAPTION_625,22,22,1},
524 { 0xaa, 0x2a, 0xff, 0x3f, 0x04, 0x51, 0x6e, 0x02,
525 0xa6, 0x7b, 0x09, 0x00, 0x00, 0x00, 0x27, 0x00 }
530 { 0xaa, 0x2a, 0xff, 0x3f, 0x04, 0x51, 0x6e, 0x02,
531 0x69, 0x8c, 0x09, 0x00, 0x00, 0x00, 0x27, 0x00 }
535 { 0x5b, 0x55, 0xc5, 0xff, 0x00, 0x71, 0x6e, 0x42,
536 0xa6, 0xcd, 0x0f, 0x00, 0x00, 0x00, 0x3a, 0x00 }
540 {V4L2_SLICED_WSS_525,20,20,1},
541 { 0x38, 0x00, 0x3f, 0x00, 0x00, 0x71, 0x6e, 0x43,
542 0x69, 0x7c, 0x08, 0x00, 0x00, 0x00, 0x39, 0x00 }
545 {V4l2_SLICED_VITC_625,6,22,0},
546 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x6d, 0x49,
547 0xa6, 0x85, 0x08, 0x00, 0x00, 0x00, 0x4c, 0x00 }
550 {V4l2_SLICED_VITC_525,10,20,0},
551 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x6d, 0x49,
552 0x69, 0x94, 0x08, 0x00, 0x00, 0x00, 0x4c, 0x00 }
557 { 0xaa, 0xaa, 0xff, 0xff, 0xba, 0xce, 0x2b, 0x0d,
558 0xa6, 0xda, 0x0b, 0x00, 0x00, 0x00, 0x60, 0x00 }
566 static int tvp5150_write_inittab(
struct v4l2_subdev *sd,
569 while (regs->
reg != 0xff) {
570 tvp5150_write(sd, regs->
reg, regs->
value);
576 static int tvp5150_vdp_init(
struct v4l2_subdev *sd,
586 tvp5150_write(sd, i, 0xff);
589 while (regs->
reg != (
u16)-1) {
593 for (i = 0; i < 16; i++)
602 static int tvp5150_g_sliced_vbi_cap(
struct v4l2_subdev *sd,
609 memset(cap, 0,
sizeof *cap);
611 while (regs->
reg != (
u16)-1 ) {
640 struct tvp5150 *decoder = to_tvp5150(sd);
646 v4l2_err(sd,
"VBI can't be configured without knowing number of lines\n");
656 while (regs->
reg != (
u16)-1 ) {
657 if ((type & regs->
type.vbi_type) &&
658 (line>=regs->
type.ini_line) &&
660 type=regs->
type.vbi_type;
670 type=pos | (flags & 0xf0);
674 tvp5150_write(sd, reg, type);
678 tvp5150_write(sd, reg+1, type);
687 struct tvp5150 *decoder = to_tvp5150(sd);
694 v4l2_err(sd,
"VBI can't be configured without knowing number of lines\n");
696 }
else if (std & V4L2_STD_625_50) {
706 for (i = 0; i <= 1; i++) {
707 ret = tvp5150_read(sd, reg + i);
709 v4l2_err(sd,
"%s: failed with error = %d\n",
715 type |= regs[
pos].
type.vbi_type;
723 struct tvp5150 *decoder = to_tvp5150(sd);
748 v4l2_dbg(1,
debug, sd,
"Set video std register to %d.\n", fmt);
755 struct tvp5150 *decoder = to_tvp5150(sd);
757 if (decoder->
norm == std)
767 return tvp5150_set_std(sd, std);
772 struct tvp5150 *decoder = to_tvp5150(sd);
775 tvp5150_write_inittab(sd, tvp5150_init_default);
778 tvp5150_vdp_init(sd, vbi_ram_default);
784 tvp5150_write_inittab(sd, tvp5150_init_enable);
789 tvp5150_set_std(sd, decoder->
norm);
818 switch (val & 0x0F) {
846 static int tvp5150_mbus_fmt(
struct v4l2_subdev *sd,
847 struct v4l2_mbus_framefmt *
f)
849 struct tvp5150 *decoder = to_tvp5150(sd);
854 tvp5150_reset(sd, 0);
856 f->width = decoder->
rect.width;
857 f->height = decoder->
rect.height;
863 v4l2_dbg(1,
debug, sd,
"width = %d, height = %d\n", f->width,
871 struct tvp5150 *decoder = to_tvp5150(sd);
875 v4l2_dbg(1,
debug, sd,
"%s left=%d, top=%d, width=%d, height=%d\n",
890 std = tvp5150_read_std(sd);
925 a->
c = decoder->
rect;
945 std = tvp5150_read_std(sd);
949 if (std & V4L2_STD_525_60)
965 static int tvp5150_s_routing(
struct v4l2_subdev *sd,
968 struct tvp5150 *decoder = to_tvp5150(sd);
985 if (fmt->
count[0] == 18 && fmt->
count[1] == 18) {
997 for (i = 0; i <= 23; i++) {
1000 tvp5150_set_vbi(sd, vbi_ram_default,
1014 tvp5150_write(sd, i, 0xff);
1025 for (i = 0; i <= 23; i++) {
1027 tvp5150_get_vbi(sd, vbi_ram_default, i);
1034 static int tvp5150_g_chip_ident(
struct v4l2_subdev *sd,
1048 #ifdef CONFIG_VIDEO_ADV_DEBUG
1059 res = tvp5150_read(sd, reg->
reg & 0xff);
1061 v4l2_err(sd,
"%s: failed with error = %d\n", __func__, res);
1072 struct i2c_client *client = v4l2_get_subdevdata(sd);
1078 tvp5150_write(sd, reg->
reg & 0xff, reg->
val & 0xff);
1085 int status = tvp5150_read(sd, 0x88);
1087 vt->
signal = ((status & 0x04) && (status & 0x02)) ? 0xffff : 0x0;
1094 .s_ctrl = tvp5150_s_ctrl,
1098 .log_status = tvp5150_log_status,
1106 .s_std = tvp5150_s_std,
1107 .reset = tvp5150_reset,
1108 .g_chip_ident = tvp5150_g_chip_ident,
1109 #ifdef CONFIG_VIDEO_ADV_DEBUG
1110 .g_register = tvp5150_g_register,
1111 .s_register = tvp5150_s_register,
1116 .g_tuner = tvp5150_g_tuner,
1120 .s_routing = tvp5150_s_routing,
1121 .enum_mbus_fmt = tvp5150_enum_mbus_fmt,
1122 .s_mbus_fmt = tvp5150_mbus_fmt,
1123 .try_mbus_fmt = tvp5150_mbus_fmt,
1124 .g_mbus_fmt = tvp5150_mbus_fmt,
1125 .s_crop = tvp5150_s_crop,
1126 .g_crop = tvp5150_g_crop,
1127 .cropcap = tvp5150_cropcap,
1131 .g_sliced_vbi_cap = tvp5150_g_sliced_vbi_cap,
1132 .g_sliced_fmt = tvp5150_g_sliced_fmt,
1133 .s_sliced_fmt = tvp5150_s_sliced_fmt,
1134 .s_raw_fmt = tvp5150_s_raw_fmt,
1138 .core = &tvp5150_core_ops,
1139 .tuner = &tvp5150_tuner_ops,
1140 .video = &tvp5150_video_ops,
1141 .vbi = &tvp5150_vbi_ops,
1149 static int tvp5150_probe(
struct i2c_client *c,
1158 if (!i2c_check_functionality(c->
adapter,
1173 for (i = 0; i < 4; i++) {
1177 tvp5150_id[
i] =
res;
1180 v4l_info(c,
"chip found @ 0x%02x (%s)\n",
1183 if (tvp5150_id[2] == 4 && tvp5150_id[3] == 0) {
1184 v4l2_info(sd,
"tvp%02x%02xam1 detected.\n",
1185 tvp5150_id[0], tvp5150_id[1]);
1191 if (tvp5150_id[2] == 3 || tvp5150_id[3] == 0x21) {
1192 v4l2_info(sd,
"tvp%02x%02xa detected.\n",
1193 tvp5150_id[2], tvp5150_id[3]);
1195 v4l2_info(sd,
"*** unknown tvp%02x%02x chip detected.\n",
1196 tvp5150_id[2], tvp5150_id[3]);
1198 tvp5150_id[2], tvp5150_id[3]);
1216 if (core->
hdl.error) {
1217 res = core->
hdl.error;
1225 if (tvp5150_read_std(sd) & V4L2_STD_525_60)
1229 core->
rect.left = 0;
1233 tvp5150_log_status(sd);
1241 static int tvp5150_remove(
struct i2c_client *c)
1244 struct tvp5150 *decoder = to_tvp5150(sd);
1247 "tvp5150.c: removing tvp5150 adapter on address 0x%x\n",
1252 kfree(to_tvp5150(sd));
1269 .probe = tvp5150_probe,
1270 .remove = tvp5150_remove,
1271 .id_table = tvp5150_id,