2 * tvp5150 - Texas Instruments TVP5150A/AM1 video decoder driver
4 * Copyright (c) 2005,2006 Mauro Carvalho Chehab (mchehab@infradead.org)
5 * This code is placed under the terms of the GNU General Public License v2
9 #include <linux/videodev2.h>
10 #include <linux/delay.h>
11 #include <linux/video_decoder.h>
12 #include <media/v4l2-device.h>
13 #include <media/tvp5150.h>
14 #include <media/v4l2-i2c-drv-legacy.h>
15 #include <media/v4l2-chip-ident.h>
17 #include "tvp5150_reg.h"
19 MODULE_DESCRIPTION("Texas Instruments TVP5150A video decoder driver");
20 MODULE_AUTHOR("Mauro Carvalho Chehab");
21 MODULE_LICENSE("GPL");
23 /* standard i2c insmod options */
24 static unsigned short normal_i2c[] = {
33 module_param(debug, int, 0);
34 MODULE_PARM_DESC(debug, "Debug level (0-2)");
36 /* supported controls */
37 static struct v4l2_queryctrl tvp5150_qctrl[] = {
39 .id = V4L2_CID_BRIGHTNESS,
40 .type = V4L2_CTRL_TYPE_INTEGER,
48 .id = V4L2_CID_CONTRAST,
49 .type = V4L2_CTRL_TYPE_INTEGER,
57 .id = V4L2_CID_SATURATION,
58 .type = V4L2_CTRL_TYPE_INTEGER,
67 .type = V4L2_CTRL_TYPE_INTEGER,
78 struct v4l2_subdev sd;
80 v4l2_std_id norm; /* Current set standard */
81 struct v4l2_routing route;
89 static inline struct tvp5150 *to_tvp5150(struct v4l2_subdev *sd)
91 return container_of(sd, struct tvp5150, sd);
94 static int tvp5150_read(struct v4l2_subdev *sd, unsigned char addr)
96 struct i2c_client *c = v4l2_get_subdevdata(sd);
97 unsigned char buffer[1];
101 if (1 != (rc = i2c_master_send(c, buffer, 1)))
102 v4l2_dbg(0, debug, sd, "i2c i/o error: rc == %d (should be 1)\n", rc);
106 if (1 != (rc = i2c_master_recv(c, buffer, 1)))
107 v4l2_dbg(0, debug, sd, "i2c i/o error: rc == %d (should be 1)\n", rc);
109 v4l2_dbg(2, debug, sd, "tvp5150: read 0x%02x = 0x%02x\n", addr, buffer[0]);
114 static inline void tvp5150_write(struct v4l2_subdev *sd, unsigned char addr,
117 struct i2c_client *c = v4l2_get_subdevdata(sd);
118 unsigned char buffer[2];
123 v4l2_dbg(2, debug, sd, "tvp5150: writing 0x%02x 0x%02x\n", buffer[0], buffer[1]);
124 if (2 != (rc = i2c_master_send(c, buffer, 2)))
125 v4l2_dbg(0, debug, sd, "i2c i/o error: rc == %d (should be 2)\n", rc);
128 static void dump_reg_range(struct v4l2_subdev *sd, char *s, u8 init,
129 const u8 end, int max_line)
133 while (init != (u8)(end + 1)) {
134 if ((i % max_line) == 0) {
137 printk("tvp5150: %s reg 0x%02x = ", s, init);
139 printk("%02x ", tvp5150_read(sd, init));
147 static int tvp5150_log_status(struct v4l2_subdev *sd)
149 printk("tvp5150: Video input source selection #1 = 0x%02x\n",
150 tvp5150_read(sd, TVP5150_VD_IN_SRC_SEL_1));
151 printk("tvp5150: Analog channel controls = 0x%02x\n",
152 tvp5150_read(sd, TVP5150_ANAL_CHL_CTL));
153 printk("tvp5150: Operation mode controls = 0x%02x\n",
154 tvp5150_read(sd, TVP5150_OP_MODE_CTL));
155 printk("tvp5150: Miscellaneous controls = 0x%02x\n",
156 tvp5150_read(sd, TVP5150_MISC_CTL));
157 printk("tvp5150: Autoswitch mask= 0x%02x\n",
158 tvp5150_read(sd, TVP5150_AUTOSW_MSK));
159 printk("tvp5150: Color killer threshold control = 0x%02x\n",
160 tvp5150_read(sd, TVP5150_COLOR_KIL_THSH_CTL));
161 printk("tvp5150: Luminance processing controls #1 #2 and #3 = %02x %02x %02x\n",
162 tvp5150_read(sd, TVP5150_LUMA_PROC_CTL_1),
163 tvp5150_read(sd, TVP5150_LUMA_PROC_CTL_2),
164 tvp5150_read(sd, TVP5150_LUMA_PROC_CTL_3));
165 printk("tvp5150: Brightness control = 0x%02x\n",
166 tvp5150_read(sd, TVP5150_BRIGHT_CTL));
167 printk("tvp5150: Color saturation control = 0x%02x\n",
168 tvp5150_read(sd, TVP5150_SATURATION_CTL));
169 printk("tvp5150: Hue control = 0x%02x\n",
170 tvp5150_read(sd, TVP5150_HUE_CTL));
171 printk("tvp5150: Contrast control = 0x%02x\n",
172 tvp5150_read(sd, TVP5150_CONTRAST_CTL));
173 printk("tvp5150: Outputs and data rates select = 0x%02x\n",
174 tvp5150_read(sd, TVP5150_DATA_RATE_SEL));
175 printk("tvp5150: Configuration shared pins = 0x%02x\n",
176 tvp5150_read(sd, TVP5150_CONF_SHARED_PIN));
177 printk("tvp5150: Active video cropping start = 0x%02x%02x\n",
178 tvp5150_read(sd, TVP5150_ACT_VD_CROP_ST_MSB),
179 tvp5150_read(sd, TVP5150_ACT_VD_CROP_ST_LSB));
180 printk("tvp5150: Active video cropping stop = 0x%02x%02x\n",
181 tvp5150_read(sd, TVP5150_ACT_VD_CROP_STP_MSB),
182 tvp5150_read(sd, TVP5150_ACT_VD_CROP_STP_LSB));
183 printk("tvp5150: Genlock/RTC = 0x%02x\n",
184 tvp5150_read(sd, TVP5150_GENLOCK));
185 printk("tvp5150: Horizontal sync start = 0x%02x\n",
186 tvp5150_read(sd, TVP5150_HORIZ_SYNC_START));
187 printk("tvp5150: Vertical blanking start = 0x%02x\n",
188 tvp5150_read(sd, TVP5150_VERT_BLANKING_START));
189 printk("tvp5150: Vertical blanking stop = 0x%02x\n",
190 tvp5150_read(sd, TVP5150_VERT_BLANKING_STOP));
191 printk("tvp5150: Chrominance processing control #1 and #2 = %02x %02x\n",
192 tvp5150_read(sd, TVP5150_CHROMA_PROC_CTL_1),
193 tvp5150_read(sd, TVP5150_CHROMA_PROC_CTL_2));
194 printk("tvp5150: Interrupt reset register B = 0x%02x\n",
195 tvp5150_read(sd, TVP5150_INT_RESET_REG_B));
196 printk("tvp5150: Interrupt enable register B = 0x%02x\n",
197 tvp5150_read(sd, TVP5150_INT_ENABLE_REG_B));
198 printk("tvp5150: Interrupt configuration register B = 0x%02x\n",
199 tvp5150_read(sd, TVP5150_INTT_CONFIG_REG_B));
200 printk("tvp5150: Video standard = 0x%02x\n",
201 tvp5150_read(sd, TVP5150_VIDEO_STD));
202 printk("tvp5150: Chroma gain factor: Cb=0x%02x Cr=0x%02x\n",
203 tvp5150_read(sd, TVP5150_CB_GAIN_FACT),
204 tvp5150_read(sd, TVP5150_CR_GAIN_FACTOR));
205 printk("tvp5150: Macrovision on counter = 0x%02x\n",
206 tvp5150_read(sd, TVP5150_MACROVISION_ON_CTR));
207 printk("tvp5150: Macrovision off counter = 0x%02x\n",
208 tvp5150_read(sd, TVP5150_MACROVISION_OFF_CTR));
209 printk("tvp5150: ITU-R BT.656.%d timing(TVP5150AM1 only)\n",
210 (tvp5150_read(sd, TVP5150_REV_SELECT) & 1) ? 3 : 4);
211 printk("tvp5150: Device ID = %02x%02x\n",
212 tvp5150_read(sd, TVP5150_MSB_DEV_ID),
213 tvp5150_read(sd, TVP5150_LSB_DEV_ID));
214 printk("tvp5150: ROM version = (hex) %02x.%02x\n",
215 tvp5150_read(sd, TVP5150_ROM_MAJOR_VER),
216 tvp5150_read(sd, TVP5150_ROM_MINOR_VER));
217 printk("tvp5150: Vertical line count = 0x%02x%02x\n",
218 tvp5150_read(sd, TVP5150_VERT_LN_COUNT_MSB),
219 tvp5150_read(sd, TVP5150_VERT_LN_COUNT_LSB));
220 printk("tvp5150: Interrupt status register B = 0x%02x\n",
221 tvp5150_read(sd, TVP5150_INT_STATUS_REG_B));
222 printk("tvp5150: Interrupt active register B = 0x%02x\n",
223 tvp5150_read(sd, TVP5150_INT_ACTIVE_REG_B));
224 printk("tvp5150: Status regs #1 to #5 = %02x %02x %02x %02x %02x\n",
225 tvp5150_read(sd, TVP5150_STATUS_REG_1),
226 tvp5150_read(sd, TVP5150_STATUS_REG_2),
227 tvp5150_read(sd, TVP5150_STATUS_REG_3),
228 tvp5150_read(sd, TVP5150_STATUS_REG_4),
229 tvp5150_read(sd, TVP5150_STATUS_REG_5));
231 dump_reg_range(sd, "Teletext filter 1", TVP5150_TELETEXT_FIL1_INI,
232 TVP5150_TELETEXT_FIL1_END, 8);
233 dump_reg_range(sd, "Teletext filter 2", TVP5150_TELETEXT_FIL2_INI,
234 TVP5150_TELETEXT_FIL2_END, 8);
236 printk("tvp5150: Teletext filter enable = 0x%02x\n",
237 tvp5150_read(sd, TVP5150_TELETEXT_FIL_ENA));
238 printk("tvp5150: Interrupt status register A = 0x%02x\n",
239 tvp5150_read(sd, TVP5150_INT_STATUS_REG_A));
240 printk("tvp5150: Interrupt enable register A = 0x%02x\n",
241 tvp5150_read(sd, TVP5150_INT_ENABLE_REG_A));
242 printk("tvp5150: Interrupt configuration = 0x%02x\n",
243 tvp5150_read(sd, TVP5150_INT_CONF));
244 printk("tvp5150: VDP status register = 0x%02x\n",
245 tvp5150_read(sd, TVP5150_VDP_STATUS_REG));
246 printk("tvp5150: FIFO word count = 0x%02x\n",
247 tvp5150_read(sd, TVP5150_FIFO_WORD_COUNT));
248 printk("tvp5150: FIFO interrupt threshold = 0x%02x\n",
249 tvp5150_read(sd, TVP5150_FIFO_INT_THRESHOLD));
250 printk("tvp5150: FIFO reset = 0x%02x\n",
251 tvp5150_read(sd, TVP5150_FIFO_RESET));
252 printk("tvp5150: Line number interrupt = 0x%02x\n",
253 tvp5150_read(sd, TVP5150_LINE_NUMBER_INT));
254 printk("tvp5150: Pixel alignment register = 0x%02x%02x\n",
255 tvp5150_read(sd, TVP5150_PIX_ALIGN_REG_HIGH),
256 tvp5150_read(sd, TVP5150_PIX_ALIGN_REG_LOW));
257 printk("tvp5150: FIFO output control = 0x%02x\n",
258 tvp5150_read(sd, TVP5150_FIFO_OUT_CTRL));
259 printk("tvp5150: Full field enable = 0x%02x\n",
260 tvp5150_read(sd, TVP5150_FULL_FIELD_ENA));
261 printk("tvp5150: Full field mode register = 0x%02x\n",
262 tvp5150_read(sd, TVP5150_FULL_FIELD_MODE_REG));
264 dump_reg_range(sd, "CC data", TVP5150_CC_DATA_INI,
265 TVP5150_CC_DATA_END, 8);
267 dump_reg_range(sd, "WSS data", TVP5150_WSS_DATA_INI,
268 TVP5150_WSS_DATA_END, 8);
270 dump_reg_range(sd, "VPS data", TVP5150_VPS_DATA_INI,
271 TVP5150_VPS_DATA_END, 8);
273 dump_reg_range(sd, "VITC data", TVP5150_VITC_DATA_INI,
274 TVP5150_VITC_DATA_END, 10);
276 dump_reg_range(sd, "Line mode", TVP5150_LINE_MODE_INI,
277 TVP5150_LINE_MODE_END, 8);
281 /****************************************************************************
283 ****************************************************************************/
285 static inline void tvp5150_selmux(struct v4l2_subdev *sd)
288 struct tvp5150 *decoder = to_tvp5150(sd);
292 if ((decoder->route.output & TVP5150_BLACK_SCREEN) || !decoder->enable)
295 switch (decoder->route.input) {
296 case TVP5150_COMPOSITE1:
299 case TVP5150_COMPOSITE0:
300 opmode=0x30; /* TV Mode */
305 opmode=0; /* Auto Mode */
309 v4l2_dbg(1, debug, sd, "Selecting video route: route input=%i, output=%i "
310 "=> tvp5150 input=%i, opmode=%i\n",
311 decoder->route.input,decoder->route.output,
314 tvp5150_write(sd, TVP5150_OP_MODE_CTL, opmode);
315 tvp5150_write(sd, TVP5150_VD_IN_SRC_SEL_1, input);
317 /* Svideo should enable YCrCb output and disable GPCL output
318 * For Composite and TV, it should be the reverse
320 val = tvp5150_read(sd, TVP5150_MISC_CTL);
321 if (decoder->route.input == TVP5150_SVIDEO)
322 val = (val & ~0x40) | 0x10;
324 val = (val & ~0x10) | 0x40;
325 tvp5150_write(sd, TVP5150_MISC_CTL, val);
328 struct i2c_reg_value {
333 /* Default values as sugested at TVP5150AM1 datasheet */
334 static const struct i2c_reg_value tvp5150_init_default[] = {
336 TVP5150_VD_IN_SRC_SEL_1,0x00
339 TVP5150_ANAL_CHL_CTL,0x15
342 TVP5150_OP_MODE_CTL,0x00
345 TVP5150_MISC_CTL,0x01
348 TVP5150_COLOR_KIL_THSH_CTL,0x10
351 TVP5150_LUMA_PROC_CTL_1,0x60
354 TVP5150_LUMA_PROC_CTL_2,0x00
357 TVP5150_BRIGHT_CTL,0x80
360 TVP5150_SATURATION_CTL,0x80
366 TVP5150_CONTRAST_CTL,0x80
369 TVP5150_DATA_RATE_SEL,0x47
372 TVP5150_LUMA_PROC_CTL_3,0x00
375 TVP5150_CONF_SHARED_PIN,0x08
378 TVP5150_ACT_VD_CROP_ST_MSB,0x00
381 TVP5150_ACT_VD_CROP_ST_LSB,0x00
384 TVP5150_ACT_VD_CROP_STP_MSB,0x00
387 TVP5150_ACT_VD_CROP_STP_LSB,0x00
393 TVP5150_HORIZ_SYNC_START,0x80
396 TVP5150_VERT_BLANKING_START,0x00
399 TVP5150_VERT_BLANKING_STOP,0x00
402 TVP5150_CHROMA_PROC_CTL_1,0x0c
405 TVP5150_CHROMA_PROC_CTL_2,0x14
408 TVP5150_INT_RESET_REG_B,0x00
411 TVP5150_INT_ENABLE_REG_B,0x00
414 TVP5150_INTT_CONFIG_REG_B,0x00
417 TVP5150_VIDEO_STD,0x00
420 TVP5150_MACROVISION_ON_CTR,0x0f
423 TVP5150_MACROVISION_OFF_CTR,0x01
426 TVP5150_TELETEXT_FIL_ENA,0x00
429 TVP5150_INT_STATUS_REG_A,0x00
432 TVP5150_INT_ENABLE_REG_A,0x00
435 TVP5150_INT_CONF,0x04
438 TVP5150_FIFO_INT_THRESHOLD,0x80
441 TVP5150_FIFO_RESET,0x00
444 TVP5150_LINE_NUMBER_INT,0x00
447 TVP5150_PIX_ALIGN_REG_LOW,0x4e
450 TVP5150_PIX_ALIGN_REG_HIGH,0x00
453 TVP5150_FIFO_OUT_CTRL,0x01
456 TVP5150_FULL_FIELD_ENA,0x00
459 TVP5150_LINE_MODE_INI,0x00
462 TVP5150_FULL_FIELD_MODE_REG,0x7f
469 /* Default values as sugested at TVP5150AM1 datasheet */
470 static const struct i2c_reg_value tvp5150_init_enable[] = {
472 TVP5150_CONF_SHARED_PIN, 2
473 },{ /* Automatic offset and AGC enabled */
474 TVP5150_ANAL_CHL_CTL, 0x15
475 },{ /* Activate YCrCb output 0x9 or 0xd ? */
476 TVP5150_MISC_CTL, 0x6f
477 },{ /* Activates video std autodetection for all standards */
478 TVP5150_AUTOSW_MSK, 0x0
479 },{ /* Default format: 0x47. For 4:2:2: 0x40 */
480 TVP5150_DATA_RATE_SEL, 0x47
482 TVP5150_CHROMA_PROC_CTL_1, 0x0c
484 TVP5150_CHROMA_PROC_CTL_2, 0x54
485 },{ /* Non documented, but initialized on WinTV USB2 */
492 struct tvp5150_vbi_type {
493 unsigned int vbi_type;
494 unsigned int ini_line;
495 unsigned int end_line;
496 unsigned int by_field :1;
499 struct i2c_vbi_ram_value {
501 struct tvp5150_vbi_type type;
502 unsigned char values[16];
505 /* This struct have the values for each supported VBI Standard
507 tvp5150_vbi_types should follow the same order as vbi_ram_default
508 * value 0 means rom position 0x10, value 1 means rom position 0x30
509 * and so on. There are 16 possible locations from 0 to 15.
512 static struct i2c_vbi_ram_value vbi_ram_default[] =
514 /* FIXME: Current api doesn't handle all VBI types, those not
515 yet supported are placed under #if 0 */
517 {0x010, /* Teletext, SECAM, WST System A */
518 {V4L2_SLICED_TELETEXT_SECAM,6,23,1},
519 { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x26,
520 0xe6, 0xb4, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00 }
523 {0x030, /* Teletext, PAL, WST System B */
524 {V4L2_SLICED_TELETEXT_B,6,22,1},
525 { 0xaa, 0xaa, 0xff, 0xff, 0x27, 0x2e, 0x20, 0x2b,
526 0xa6, 0x72, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00 }
529 {0x050, /* Teletext, PAL, WST System C */
530 {V4L2_SLICED_TELETEXT_PAL_C,6,22,1},
531 { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x22,
532 0xa6, 0x98, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 }
534 {0x070, /* Teletext, NTSC, WST System B */
535 {V4L2_SLICED_TELETEXT_NTSC_B,10,21,1},
536 { 0xaa, 0xaa, 0xff, 0xff, 0x27, 0x2e, 0x20, 0x23,
537 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 }
539 {0x090, /* Tetetext, NTSC NABTS System C */
540 {V4L2_SLICED_TELETEXT_NTSC_C,10,21,1},
541 { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x22,
542 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x15, 0x00 }
544 {0x0b0, /* Teletext, NTSC-J, NABTS System D */
545 {V4L2_SLICED_TELETEXT_NTSC_D,10,21,1},
546 { 0xaa, 0xaa, 0xff, 0xff, 0xa7, 0x2e, 0x20, 0x23,
547 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 }
549 {0x0d0, /* Closed Caption, PAL/SECAM */
550 {V4L2_SLICED_CAPTION_625,22,22,1},
551 { 0xaa, 0x2a, 0xff, 0x3f, 0x04, 0x51, 0x6e, 0x02,
552 0xa6, 0x7b, 0x09, 0x00, 0x00, 0x00, 0x27, 0x00 }
555 {0x0f0, /* Closed Caption, NTSC */
556 {V4L2_SLICED_CAPTION_525,21,21,1},
557 { 0xaa, 0x2a, 0xff, 0x3f, 0x04, 0x51, 0x6e, 0x02,
558 0x69, 0x8c, 0x09, 0x00, 0x00, 0x00, 0x27, 0x00 }
560 {0x110, /* Wide Screen Signal, PAL/SECAM */
561 {V4L2_SLICED_WSS_625,23,23,1},
562 { 0x5b, 0x55, 0xc5, 0xff, 0x00, 0x71, 0x6e, 0x42,
563 0xa6, 0xcd, 0x0f, 0x00, 0x00, 0x00, 0x3a, 0x00 }
566 {0x130, /* Wide Screen Signal, NTSC C */
567 {V4L2_SLICED_WSS_525,20,20,1},
568 { 0x38, 0x00, 0x3f, 0x00, 0x00, 0x71, 0x6e, 0x43,
569 0x69, 0x7c, 0x08, 0x00, 0x00, 0x00, 0x39, 0x00 }
571 {0x150, /* Vertical Interval Timecode (VITC), PAL/SECAM */
572 {V4l2_SLICED_VITC_625,6,22,0},
573 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x6d, 0x49,
574 0xa6, 0x85, 0x08, 0x00, 0x00, 0x00, 0x4c, 0x00 }
576 {0x170, /* Vertical Interval Timecode (VITC), NTSC */
577 {V4l2_SLICED_VITC_525,10,20,0},
578 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x6d, 0x49,
579 0x69, 0x94, 0x08, 0x00, 0x00, 0x00, 0x4c, 0x00 }
582 {0x190, /* Video Program System (VPS), PAL */
583 {V4L2_SLICED_VPS,16,16,0},
584 { 0xaa, 0xaa, 0xff, 0xff, 0xba, 0xce, 0x2b, 0x0d,
585 0xa6, 0xda, 0x0b, 0x00, 0x00, 0x00, 0x60, 0x00 }
587 /* 0x1d0 User programmable */
593 static int tvp5150_write_inittab(struct v4l2_subdev *sd,
594 const struct i2c_reg_value *regs)
596 while (regs->reg != 0xff) {
597 tvp5150_write(sd, regs->reg, regs->value);
603 static int tvp5150_vdp_init(struct v4l2_subdev *sd,
604 const struct i2c_vbi_ram_value *regs)
608 /* Disable Full Field */
609 tvp5150_write(sd, TVP5150_FULL_FIELD_ENA, 0);
611 /* Before programming, Line mode should be at 0xff */
612 for (i = TVP5150_LINE_MODE_INI; i <= TVP5150_LINE_MODE_END; i++)
613 tvp5150_write(sd, i, 0xff);
616 while (regs->reg != (u16)-1) {
617 tvp5150_write(sd, TVP5150_CONF_RAM_ADDR_HIGH, regs->reg >> 8);
618 tvp5150_write(sd, TVP5150_CONF_RAM_ADDR_LOW, regs->reg);
620 for (i = 0; i < 16; i++)
621 tvp5150_write(sd, TVP5150_VDP_CONF_RAM_DATA, regs->values[i]);
628 /* Fills VBI capabilities based on i2c_vbi_ram_value struct */
629 static int tvp5150_g_sliced_vbi_cap(struct v4l2_subdev *sd,
630 struct v4l2_sliced_vbi_cap *cap)
632 const struct i2c_vbi_ram_value *regs = vbi_ram_default;
635 v4l2_dbg(1, debug, sd, "VIDIOC_G_SLICED_VBI_CAP\n");
636 memset(cap, 0, sizeof *cap);
638 while (regs->reg != (u16)-1 ) {
639 for (line=regs->type.ini_line;line<=regs->type.end_line;line++) {
640 cap->service_lines[0][line] |= regs->type.vbi_type;
642 cap->service_set |= regs->type.vbi_type;
649 /* Set vbi processing
650 * type - one of tvp5150_vbi_types
651 * line - line to gather data
652 * fields: bit 0 field1, bit 1, field2
653 * flags (default=0xf0) is a bitmask, were set means:
654 * bit 7: enable filtering null bytes on CC
655 * bit 6: send data also to FIFO
656 * bit 5: don't allow data with errors on FIFO
657 * bit 4: enable ECC when possible
658 * pix_align = pix alignment:
662 static int tvp5150_set_vbi(struct v4l2_subdev *sd,
663 const struct i2c_vbi_ram_value *regs,
664 unsigned int type,u8 flags, int line,
667 struct tvp5150 *decoder = to_tvp5150(sd);
668 v4l2_std_id std = decoder->norm;
672 if (std == V4L2_STD_ALL) {
673 v4l2_err(sd, "VBI can't be configured without knowing number of lines\n");
675 } else if (std & V4L2_STD_625_50) {
676 /* Don't follow NTSC Line number convension */
683 while (regs->reg != (u16)-1 ) {
684 if ((type & regs->type.vbi_type) &&
685 (line>=regs->type.ini_line) &&
686 (line<=regs->type.end_line)) {
687 type=regs->type.vbi_type;
694 if (regs->reg == (u16)-1)
697 type=pos | (flags & 0xf0);
698 reg=((line-6)<<1)+TVP5150_LINE_MODE_INI;
701 tvp5150_write(sd, reg, type);
705 tvp5150_write(sd, reg+1, type);
711 static int tvp5150_get_vbi(struct v4l2_subdev *sd,
712 const struct i2c_vbi_ram_value *regs, int line)
714 struct tvp5150 *decoder = to_tvp5150(sd);
715 v4l2_std_id std = decoder->norm;
719 if (std == V4L2_STD_ALL) {
720 v4l2_err(sd, "VBI can't be configured without knowing number of lines\n");
722 } else if (std & V4L2_STD_625_50) {
723 /* Don't follow NTSC Line number convension */
727 if (line < 6 || line > 27)
730 reg = ((line - 6) << 1) + TVP5150_LINE_MODE_INI;
732 pos = tvp5150_read(sd, reg) & 0x0f;
734 type = regs[pos].type.vbi_type;
736 pos = tvp5150_read(sd, reg + 1) & 0x0f;
738 type |= regs[pos].type.vbi_type;
743 static int tvp5150_set_std(struct v4l2_subdev *sd, v4l2_std_id std)
745 struct tvp5150 *decoder = to_tvp5150(sd);
750 /* First tests should be against specific std */
752 if (std == V4L2_STD_ALL) {
753 fmt = 0; /* Autodetect mode */
754 } else if (std & V4L2_STD_NTSC_443) {
756 } else if (std & V4L2_STD_PAL_M) {
758 } else if (std & (V4L2_STD_PAL_N | V4L2_STD_PAL_Nc)) {
761 /* Then, test against generic ones */
762 if (std & V4L2_STD_NTSC)
764 else if (std & V4L2_STD_PAL)
766 else if (std & V4L2_STD_SECAM)
770 v4l2_dbg(1, debug, sd, "Set video std register to %d.\n", fmt);
771 tvp5150_write(sd, TVP5150_VIDEO_STD, fmt);
775 static int tvp5150_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
777 struct tvp5150 *decoder = to_tvp5150(sd);
779 if (decoder->norm == std)
782 return tvp5150_set_std(sd, std);
785 static int tvp5150_reset(struct v4l2_subdev *sd, u32 val)
787 struct tvp5150 *decoder = to_tvp5150(sd);
788 u8 msb_id, lsb_id, msb_rom, lsb_rom;
790 msb_id = tvp5150_read(sd, TVP5150_MSB_DEV_ID);
791 lsb_id = tvp5150_read(sd, TVP5150_LSB_DEV_ID);
792 msb_rom = tvp5150_read(sd, TVP5150_ROM_MAJOR_VER);
793 lsb_rom = tvp5150_read(sd, TVP5150_ROM_MINOR_VER);
795 if (msb_rom == 4 && lsb_rom == 0) { /* Is TVP5150AM1 */
796 v4l2_info(sd, "tvp%02x%02xam1 detected.\n", msb_id, lsb_id);
798 /* ITU-T BT.656.4 timing */
799 tvp5150_write(sd, TVP5150_REV_SELECT, 0);
801 if (msb_rom == 3 || lsb_rom == 0x21) { /* Is TVP5150A */
802 v4l2_info(sd, "tvp%02x%02xa detected.\n", msb_id, lsb_id);
804 v4l2_info(sd, "*** unknown tvp%02x%02x chip detected.\n",
806 v4l2_info(sd, "*** Rom ver is %d.%d\n", msb_rom, lsb_rom);
810 /* Initializes TVP5150 to its default values */
811 tvp5150_write_inittab(sd, tvp5150_init_default);
813 /* Initializes VDP registers */
814 tvp5150_vdp_init(sd, vbi_ram_default);
816 /* Selects decoder input */
819 /* Initializes TVP5150 to stream enabled values */
820 tvp5150_write_inittab(sd, tvp5150_init_enable);
822 /* Initialize image preferences */
823 tvp5150_write(sd, TVP5150_BRIGHT_CTL, decoder->bright);
824 tvp5150_write(sd, TVP5150_CONTRAST_CTL, decoder->contrast);
825 tvp5150_write(sd, TVP5150_SATURATION_CTL, decoder->contrast);
826 tvp5150_write(sd, TVP5150_HUE_CTL, decoder->hue);
828 tvp5150_set_std(sd, decoder->norm);
832 static int tvp5150_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
834 v4l2_dbg(1, debug, sd, "VIDIOC_G_CTRL called\n");
837 case V4L2_CID_BRIGHTNESS:
838 ctrl->value = tvp5150_read(sd, TVP5150_BRIGHT_CTL);
840 case V4L2_CID_CONTRAST:
841 ctrl->value = tvp5150_read(sd, TVP5150_CONTRAST_CTL);
843 case V4L2_CID_SATURATION:
844 ctrl->value = tvp5150_read(sd, TVP5150_SATURATION_CTL);
847 ctrl->value = tvp5150_read(sd, TVP5150_HUE_CTL);
853 static int tvp5150_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
856 n = ARRAY_SIZE(tvp5150_qctrl);
858 for (i = 0; i < n; i++) {
859 if (ctrl->id != tvp5150_qctrl[i].id)
861 if (ctrl->value < tvp5150_qctrl[i].minimum ||
862 ctrl->value > tvp5150_qctrl[i].maximum)
864 v4l2_dbg(1, debug, sd, "VIDIOC_S_CTRL: id=%d, value=%d\n",
865 ctrl->id, ctrl->value);
870 case V4L2_CID_BRIGHTNESS:
871 tvp5150_write(sd, TVP5150_BRIGHT_CTL, ctrl->value);
873 case V4L2_CID_CONTRAST:
874 tvp5150_write(sd, TVP5150_CONTRAST_CTL, ctrl->value);
876 case V4L2_CID_SATURATION:
877 tvp5150_write(sd, TVP5150_SATURATION_CTL, ctrl->value);
880 tvp5150_write(sd, TVP5150_HUE_CTL, ctrl->value);
886 /****************************************************************************
888 ****************************************************************************/
890 static int tvp5150_s_routing(struct v4l2_subdev *sd, const struct v4l2_routing *route)
892 struct tvp5150 *decoder = to_tvp5150(sd);
894 decoder->route = *route;
899 static int tvp5150_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
901 struct v4l2_sliced_vbi_format *svbi;
905 if (fmt->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
906 /* this is for capturing 36 raw vbi lines
907 if there's a way to cut off the beginning 2 vbi lines
908 with the tvp5150 then the vbi line count could be lowered
909 to 17 lines/field again, although I couldn't find a register
910 which could do that cropping */
911 if (fmt->fmt.vbi.sample_format == V4L2_PIX_FMT_GREY)
912 tvp5150_write(sd, TVP5150_LUMA_PROC_CTL_1, 0x70);
913 if (fmt->fmt.vbi.count[0] == 18 && fmt->fmt.vbi.count[1] == 18) {
914 tvp5150_write(sd, TVP5150_VERT_BLANKING_START, 0x00);
915 tvp5150_write(sd, TVP5150_VERT_BLANKING_STOP, 0x01);
919 if (fmt->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE)
921 svbi = &fmt->fmt.sliced;
922 if (svbi->service_set != 0) {
923 for (i = 0; i <= 23; i++) {
924 svbi->service_lines[1][i] = 0;
925 svbi->service_lines[0][i] =
926 tvp5150_set_vbi(sd, vbi_ram_default,
927 svbi->service_lines[0][i], 0xf0, i, 3);
930 tvp5150_write(sd, TVP5150_FIFO_OUT_CTRL, 1);
933 tvp5150_write(sd, TVP5150_FIFO_OUT_CTRL, 0);
935 /* Disable Full Field */
936 tvp5150_write(sd, TVP5150_FULL_FIELD_ENA, 0);
938 /* Disable Line modes */
939 for (i = TVP5150_LINE_MODE_INI; i <= TVP5150_LINE_MODE_END; i++)
940 tvp5150_write(sd, i, 0xff);
945 static int tvp5150_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
947 struct v4l2_sliced_vbi_format *svbi;
950 if (fmt->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE)
952 svbi = &fmt->fmt.sliced;
953 memset(svbi, 0, sizeof(*svbi));
955 for (i = 0; i <= 23; i++) {
956 svbi->service_lines[0][i] =
957 tvp5150_get_vbi(sd, vbi_ram_default, i);
958 mask |= svbi->service_lines[0][i];
960 svbi->service_set = mask;
965 static int tvp5150_g_chip_ident(struct v4l2_subdev *sd,
966 struct v4l2_chip_ident *chip)
969 struct i2c_client *client = v4l2_get_subdevdata(sd);
971 rev = tvp5150_read(sd, TVP5150_ROM_MAJOR_VER) << 8 |
972 tvp5150_read(sd, TVP5150_ROM_MINOR_VER);
974 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_TVP5150,
979 #ifdef CONFIG_VIDEO_ADV_DEBUG
980 static int tvp5150_g_register(struct v4l2_subdev *sd, struct v4l2_register *reg)
982 struct i2c_client *client = v4l2_get_subdevdata(sd);
984 if (!v4l2_chip_match_i2c_client(client,
985 reg->match_type, reg->match_chip))
987 if (!capable(CAP_SYS_ADMIN))
989 reg->val = tvp5150_read(sd, reg->reg & 0xff);
993 static int tvp5150_s_register(struct v4l2_subdev *sd, struct v4l2_register *reg)
995 struct i2c_client *client = v4l2_get_subdevdata(sd);
997 if (!v4l2_chip_match_i2c_client(client,
998 reg->match_type, reg->match_chip))
1000 if (!capable(CAP_SYS_ADMIN))
1002 tvp5150_write(sd, reg->reg & 0xff, reg->val & 0xff);
1007 static int tvp5150_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
1009 int status = tvp5150_read(sd, 0x88);
1011 vt->signal = ((status & 0x04) && (status & 0x02)) ? 0xffff : 0x0;
1015 static int tvp5150_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc)
1019 v4l2_dbg(1, debug, sd, "VIDIOC_QUERYCTRL called\n");
1021 for (i = 0; i < ARRAY_SIZE(tvp5150_qctrl); i++)
1022 if (qc->id && qc->id == tvp5150_qctrl[i].id) {
1023 memcpy(qc, &(tvp5150_qctrl[i]),
1031 static int tvp5150_command(struct i2c_client *client, unsigned cmd, void *arg)
1033 return v4l2_subdev_command(i2c_get_clientdata(client), cmd, arg);
1036 /* ----------------------------------------------------------------------- */
1038 static const struct v4l2_subdev_core_ops tvp5150_core_ops = {
1039 .log_status = tvp5150_log_status,
1040 .g_ctrl = tvp5150_g_ctrl,
1041 .s_ctrl = tvp5150_s_ctrl,
1042 .queryctrl = tvp5150_queryctrl,
1043 .reset = tvp5150_reset,
1044 .g_chip_ident = tvp5150_g_chip_ident,
1045 #ifdef CONFIG_VIDEO_ADV_DEBUG
1046 .g_register = tvp5150_g_register,
1047 .s_register = tvp5150_s_register,
1051 static const struct v4l2_subdev_tuner_ops tvp5150_tuner_ops = {
1052 .s_std = tvp5150_s_std,
1053 .g_tuner = tvp5150_g_tuner,
1056 static const struct v4l2_subdev_video_ops tvp5150_video_ops = {
1057 .s_routing = tvp5150_s_routing,
1058 .g_fmt = tvp5150_g_fmt,
1059 .s_fmt = tvp5150_s_fmt,
1060 .g_sliced_vbi_cap = tvp5150_g_sliced_vbi_cap,
1063 static const struct v4l2_subdev_ops tvp5150_ops = {
1064 .core = &tvp5150_core_ops,
1065 .tuner = &tvp5150_tuner_ops,
1066 .video = &tvp5150_video_ops,
1070 /****************************************************************************
1072 ****************************************************************************/
1074 static int tvp5150_probe(struct i2c_client *c,
1075 const struct i2c_device_id *id)
1077 struct tvp5150 *core;
1078 struct v4l2_subdev *sd;
1080 /* Check if the adapter supports the needed features */
1081 if (!i2c_check_functionality(c->adapter,
1082 I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
1085 core = kzalloc(sizeof(struct tvp5150), GFP_KERNEL);
1090 v4l2_i2c_subdev_init(sd, c, &tvp5150_ops);
1091 v4l_info(c, "chip found @ 0x%02x (%s)\n",
1092 c->addr << 1, c->adapter->name);
1094 core->norm = V4L2_STD_ALL; /* Default is autodetect */
1095 core->route.input = TVP5150_COMPOSITE1;
1098 core->contrast = 128;
1103 tvp5150_log_status(sd);
1107 static int tvp5150_remove(struct i2c_client *c)
1109 struct v4l2_subdev *sd = i2c_get_clientdata(c);
1111 v4l2_dbg(1, debug, sd,
1112 "tvp5150.c: removing tvp5150 adapter on address 0x%x\n",
1115 v4l2_device_unregister_subdev(sd);
1116 kfree(to_tvp5150(sd));
1120 /* ----------------------------------------------------------------------- */
1122 static const struct i2c_device_id tvp5150_id[] = {
1126 MODULE_DEVICE_TABLE(i2c, tvp5150_id);
1128 static struct v4l2_i2c_driver_data v4l2_i2c_data = {
1130 .driverid = I2C_DRIVERID_TVP5150,
1131 .command = tvp5150_command,
1132 .probe = tvp5150_probe,
1133 .remove = tvp5150_remove,
1134 .legacy_class = I2C_CLASS_TV_ANALOG | I2C_CLASS_TV_DIGITAL,
1135 .id_table = tvp5150_id,