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 <media/v4l2-device.h>
12 #include <media/tvp5150.h>
13 #include <media/v4l2-i2c-drv-legacy.h>
14 #include <media/v4l2-chip-ident.h>
16 #include "tvp5150_reg.h"
18 MODULE_DESCRIPTION("Texas Instruments TVP5150A video decoder driver");
19 MODULE_AUTHOR("Mauro Carvalho Chehab");
20 MODULE_LICENSE("GPL");
22 /* standard i2c insmod options */
23 static unsigned short normal_i2c
[] = {
32 module_param(debug
, int, 0);
33 MODULE_PARM_DESC(debug
, "Debug level (0-2)");
35 /* supported controls */
36 static struct v4l2_queryctrl tvp5150_qctrl
[] = {
38 .id
= V4L2_CID_BRIGHTNESS
,
39 .type
= V4L2_CTRL_TYPE_INTEGER
,
47 .id
= V4L2_CID_CONTRAST
,
48 .type
= V4L2_CTRL_TYPE_INTEGER
,
56 .id
= V4L2_CID_SATURATION
,
57 .type
= V4L2_CTRL_TYPE_INTEGER
,
66 .type
= V4L2_CTRL_TYPE_INTEGER
,
77 struct v4l2_subdev sd
;
79 v4l2_std_id norm
; /* Current set standard */
80 struct v4l2_routing route
;
88 static inline struct tvp5150
*to_tvp5150(struct v4l2_subdev
*sd
)
90 return container_of(sd
, struct tvp5150
, sd
);
93 static int tvp5150_read(struct v4l2_subdev
*sd
, unsigned char addr
)
95 struct i2c_client
*c
= v4l2_get_subdevdata(sd
);
96 unsigned char buffer
[1];
100 if (1 != (rc
= i2c_master_send(c
, buffer
, 1)))
101 v4l2_dbg(0, debug
, sd
, "i2c i/o error: rc == %d (should be 1)\n", rc
);
105 if (1 != (rc
= i2c_master_recv(c
, buffer
, 1)))
106 v4l2_dbg(0, debug
, sd
, "i2c i/o error: rc == %d (should be 1)\n", rc
);
108 v4l2_dbg(2, debug
, sd
, "tvp5150: read 0x%02x = 0x%02x\n", addr
, buffer
[0]);
113 static inline void tvp5150_write(struct v4l2_subdev
*sd
, unsigned char addr
,
116 struct i2c_client
*c
= v4l2_get_subdevdata(sd
);
117 unsigned char buffer
[2];
122 v4l2_dbg(2, debug
, sd
, "tvp5150: writing 0x%02x 0x%02x\n", buffer
[0], buffer
[1]);
123 if (2 != (rc
= i2c_master_send(c
, buffer
, 2)))
124 v4l2_dbg(0, debug
, sd
, "i2c i/o error: rc == %d (should be 2)\n", rc
);
127 static void dump_reg_range(struct v4l2_subdev
*sd
, char *s
, u8 init
,
128 const u8 end
, int max_line
)
132 while (init
!= (u8
)(end
+ 1)) {
133 if ((i
% max_line
) == 0) {
136 printk("tvp5150: %s reg 0x%02x = ", s
, init
);
138 printk("%02x ", tvp5150_read(sd
, init
));
146 static int tvp5150_log_status(struct v4l2_subdev
*sd
)
148 printk("tvp5150: Video input source selection #1 = 0x%02x\n",
149 tvp5150_read(sd
, TVP5150_VD_IN_SRC_SEL_1
));
150 printk("tvp5150: Analog channel controls = 0x%02x\n",
151 tvp5150_read(sd
, TVP5150_ANAL_CHL_CTL
));
152 printk("tvp5150: Operation mode controls = 0x%02x\n",
153 tvp5150_read(sd
, TVP5150_OP_MODE_CTL
));
154 printk("tvp5150: Miscellaneous controls = 0x%02x\n",
155 tvp5150_read(sd
, TVP5150_MISC_CTL
));
156 printk("tvp5150: Autoswitch mask= 0x%02x\n",
157 tvp5150_read(sd
, TVP5150_AUTOSW_MSK
));
158 printk("tvp5150: Color killer threshold control = 0x%02x\n",
159 tvp5150_read(sd
, TVP5150_COLOR_KIL_THSH_CTL
));
160 printk("tvp5150: Luminance processing controls #1 #2 and #3 = %02x %02x %02x\n",
161 tvp5150_read(sd
, TVP5150_LUMA_PROC_CTL_1
),
162 tvp5150_read(sd
, TVP5150_LUMA_PROC_CTL_2
),
163 tvp5150_read(sd
, TVP5150_LUMA_PROC_CTL_3
));
164 printk("tvp5150: Brightness control = 0x%02x\n",
165 tvp5150_read(sd
, TVP5150_BRIGHT_CTL
));
166 printk("tvp5150: Color saturation control = 0x%02x\n",
167 tvp5150_read(sd
, TVP5150_SATURATION_CTL
));
168 printk("tvp5150: Hue control = 0x%02x\n",
169 tvp5150_read(sd
, TVP5150_HUE_CTL
));
170 printk("tvp5150: Contrast control = 0x%02x\n",
171 tvp5150_read(sd
, TVP5150_CONTRAST_CTL
));
172 printk("tvp5150: Outputs and data rates select = 0x%02x\n",
173 tvp5150_read(sd
, TVP5150_DATA_RATE_SEL
));
174 printk("tvp5150: Configuration shared pins = 0x%02x\n",
175 tvp5150_read(sd
, TVP5150_CONF_SHARED_PIN
));
176 printk("tvp5150: Active video cropping start = 0x%02x%02x\n",
177 tvp5150_read(sd
, TVP5150_ACT_VD_CROP_ST_MSB
),
178 tvp5150_read(sd
, TVP5150_ACT_VD_CROP_ST_LSB
));
179 printk("tvp5150: Active video cropping stop = 0x%02x%02x\n",
180 tvp5150_read(sd
, TVP5150_ACT_VD_CROP_STP_MSB
),
181 tvp5150_read(sd
, TVP5150_ACT_VD_CROP_STP_LSB
));
182 printk("tvp5150: Genlock/RTC = 0x%02x\n",
183 tvp5150_read(sd
, TVP5150_GENLOCK
));
184 printk("tvp5150: Horizontal sync start = 0x%02x\n",
185 tvp5150_read(sd
, TVP5150_HORIZ_SYNC_START
));
186 printk("tvp5150: Vertical blanking start = 0x%02x\n",
187 tvp5150_read(sd
, TVP5150_VERT_BLANKING_START
));
188 printk("tvp5150: Vertical blanking stop = 0x%02x\n",
189 tvp5150_read(sd
, TVP5150_VERT_BLANKING_STOP
));
190 printk("tvp5150: Chrominance processing control #1 and #2 = %02x %02x\n",
191 tvp5150_read(sd
, TVP5150_CHROMA_PROC_CTL_1
),
192 tvp5150_read(sd
, TVP5150_CHROMA_PROC_CTL_2
));
193 printk("tvp5150: Interrupt reset register B = 0x%02x\n",
194 tvp5150_read(sd
, TVP5150_INT_RESET_REG_B
));
195 printk("tvp5150: Interrupt enable register B = 0x%02x\n",
196 tvp5150_read(sd
, TVP5150_INT_ENABLE_REG_B
));
197 printk("tvp5150: Interrupt configuration register B = 0x%02x\n",
198 tvp5150_read(sd
, TVP5150_INTT_CONFIG_REG_B
));
199 printk("tvp5150: Video standard = 0x%02x\n",
200 tvp5150_read(sd
, TVP5150_VIDEO_STD
));
201 printk("tvp5150: Chroma gain factor: Cb=0x%02x Cr=0x%02x\n",
202 tvp5150_read(sd
, TVP5150_CB_GAIN_FACT
),
203 tvp5150_read(sd
, TVP5150_CR_GAIN_FACTOR
));
204 printk("tvp5150: Macrovision on counter = 0x%02x\n",
205 tvp5150_read(sd
, TVP5150_MACROVISION_ON_CTR
));
206 printk("tvp5150: Macrovision off counter = 0x%02x\n",
207 tvp5150_read(sd
, TVP5150_MACROVISION_OFF_CTR
));
208 printk("tvp5150: ITU-R BT.656.%d timing(TVP5150AM1 only)\n",
209 (tvp5150_read(sd
, TVP5150_REV_SELECT
) & 1) ? 3 : 4);
210 printk("tvp5150: Device ID = %02x%02x\n",
211 tvp5150_read(sd
, TVP5150_MSB_DEV_ID
),
212 tvp5150_read(sd
, TVP5150_LSB_DEV_ID
));
213 printk("tvp5150: ROM version = (hex) %02x.%02x\n",
214 tvp5150_read(sd
, TVP5150_ROM_MAJOR_VER
),
215 tvp5150_read(sd
, TVP5150_ROM_MINOR_VER
));
216 printk("tvp5150: Vertical line count = 0x%02x%02x\n",
217 tvp5150_read(sd
, TVP5150_VERT_LN_COUNT_MSB
),
218 tvp5150_read(sd
, TVP5150_VERT_LN_COUNT_LSB
));
219 printk("tvp5150: Interrupt status register B = 0x%02x\n",
220 tvp5150_read(sd
, TVP5150_INT_STATUS_REG_B
));
221 printk("tvp5150: Interrupt active register B = 0x%02x\n",
222 tvp5150_read(sd
, TVP5150_INT_ACTIVE_REG_B
));
223 printk("tvp5150: Status regs #1 to #5 = %02x %02x %02x %02x %02x\n",
224 tvp5150_read(sd
, TVP5150_STATUS_REG_1
),
225 tvp5150_read(sd
, TVP5150_STATUS_REG_2
),
226 tvp5150_read(sd
, TVP5150_STATUS_REG_3
),
227 tvp5150_read(sd
, TVP5150_STATUS_REG_4
),
228 tvp5150_read(sd
, TVP5150_STATUS_REG_5
));
230 dump_reg_range(sd
, "Teletext filter 1", TVP5150_TELETEXT_FIL1_INI
,
231 TVP5150_TELETEXT_FIL1_END
, 8);
232 dump_reg_range(sd
, "Teletext filter 2", TVP5150_TELETEXT_FIL2_INI
,
233 TVP5150_TELETEXT_FIL2_END
, 8);
235 printk("tvp5150: Teletext filter enable = 0x%02x\n",
236 tvp5150_read(sd
, TVP5150_TELETEXT_FIL_ENA
));
237 printk("tvp5150: Interrupt status register A = 0x%02x\n",
238 tvp5150_read(sd
, TVP5150_INT_STATUS_REG_A
));
239 printk("tvp5150: Interrupt enable register A = 0x%02x\n",
240 tvp5150_read(sd
, TVP5150_INT_ENABLE_REG_A
));
241 printk("tvp5150: Interrupt configuration = 0x%02x\n",
242 tvp5150_read(sd
, TVP5150_INT_CONF
));
243 printk("tvp5150: VDP status register = 0x%02x\n",
244 tvp5150_read(sd
, TVP5150_VDP_STATUS_REG
));
245 printk("tvp5150: FIFO word count = 0x%02x\n",
246 tvp5150_read(sd
, TVP5150_FIFO_WORD_COUNT
));
247 printk("tvp5150: FIFO interrupt threshold = 0x%02x\n",
248 tvp5150_read(sd
, TVP5150_FIFO_INT_THRESHOLD
));
249 printk("tvp5150: FIFO reset = 0x%02x\n",
250 tvp5150_read(sd
, TVP5150_FIFO_RESET
));
251 printk("tvp5150: Line number interrupt = 0x%02x\n",
252 tvp5150_read(sd
, TVP5150_LINE_NUMBER_INT
));
253 printk("tvp5150: Pixel alignment register = 0x%02x%02x\n",
254 tvp5150_read(sd
, TVP5150_PIX_ALIGN_REG_HIGH
),
255 tvp5150_read(sd
, TVP5150_PIX_ALIGN_REG_LOW
));
256 printk("tvp5150: FIFO output control = 0x%02x\n",
257 tvp5150_read(sd
, TVP5150_FIFO_OUT_CTRL
));
258 printk("tvp5150: Full field enable = 0x%02x\n",
259 tvp5150_read(sd
, TVP5150_FULL_FIELD_ENA
));
260 printk("tvp5150: Full field mode register = 0x%02x\n",
261 tvp5150_read(sd
, TVP5150_FULL_FIELD_MODE_REG
));
263 dump_reg_range(sd
, "CC data", TVP5150_CC_DATA_INI
,
264 TVP5150_CC_DATA_END
, 8);
266 dump_reg_range(sd
, "WSS data", TVP5150_WSS_DATA_INI
,
267 TVP5150_WSS_DATA_END
, 8);
269 dump_reg_range(sd
, "VPS data", TVP5150_VPS_DATA_INI
,
270 TVP5150_VPS_DATA_END
, 8);
272 dump_reg_range(sd
, "VITC data", TVP5150_VITC_DATA_INI
,
273 TVP5150_VITC_DATA_END
, 10);
275 dump_reg_range(sd
, "Line mode", TVP5150_LINE_MODE_INI
,
276 TVP5150_LINE_MODE_END
, 8);
280 /****************************************************************************
282 ****************************************************************************/
284 static inline void tvp5150_selmux(struct v4l2_subdev
*sd
)
287 struct tvp5150
*decoder
= to_tvp5150(sd
);
291 if ((decoder
->route
.output
& TVP5150_BLACK_SCREEN
) || !decoder
->enable
)
294 switch (decoder
->route
.input
) {
295 case TVP5150_COMPOSITE1
:
298 case TVP5150_COMPOSITE0
:
299 opmode
=0x30; /* TV Mode */
304 opmode
=0; /* Auto Mode */
308 v4l2_dbg(1, debug
, sd
, "Selecting video route: route input=%i, output=%i "
309 "=> tvp5150 input=%i, opmode=%i\n",
310 decoder
->route
.input
,decoder
->route
.output
,
313 tvp5150_write(sd
, TVP5150_OP_MODE_CTL
, opmode
);
314 tvp5150_write(sd
, TVP5150_VD_IN_SRC_SEL_1
, input
);
316 /* Svideo should enable YCrCb output and disable GPCL output
317 * For Composite and TV, it should be the reverse
319 val
= tvp5150_read(sd
, TVP5150_MISC_CTL
);
320 if (decoder
->route
.input
== TVP5150_SVIDEO
)
321 val
= (val
& ~0x40) | 0x10;
323 val
= (val
& ~0x10) | 0x40;
324 tvp5150_write(sd
, TVP5150_MISC_CTL
, val
);
327 struct i2c_reg_value
{
332 /* Default values as sugested at TVP5150AM1 datasheet */
333 static const struct i2c_reg_value tvp5150_init_default
[] = {
335 TVP5150_VD_IN_SRC_SEL_1
,0x00
338 TVP5150_ANAL_CHL_CTL
,0x15
341 TVP5150_OP_MODE_CTL
,0x00
344 TVP5150_MISC_CTL
,0x01
347 TVP5150_COLOR_KIL_THSH_CTL
,0x10
350 TVP5150_LUMA_PROC_CTL_1
,0x60
353 TVP5150_LUMA_PROC_CTL_2
,0x00
356 TVP5150_BRIGHT_CTL
,0x80
359 TVP5150_SATURATION_CTL
,0x80
365 TVP5150_CONTRAST_CTL
,0x80
368 TVP5150_DATA_RATE_SEL
,0x47
371 TVP5150_LUMA_PROC_CTL_3
,0x00
374 TVP5150_CONF_SHARED_PIN
,0x08
377 TVP5150_ACT_VD_CROP_ST_MSB
,0x00
380 TVP5150_ACT_VD_CROP_ST_LSB
,0x00
383 TVP5150_ACT_VD_CROP_STP_MSB
,0x00
386 TVP5150_ACT_VD_CROP_STP_LSB
,0x00
392 TVP5150_HORIZ_SYNC_START
,0x80
395 TVP5150_VERT_BLANKING_START
,0x00
398 TVP5150_VERT_BLANKING_STOP
,0x00
401 TVP5150_CHROMA_PROC_CTL_1
,0x0c
404 TVP5150_CHROMA_PROC_CTL_2
,0x14
407 TVP5150_INT_RESET_REG_B
,0x00
410 TVP5150_INT_ENABLE_REG_B
,0x00
413 TVP5150_INTT_CONFIG_REG_B
,0x00
416 TVP5150_VIDEO_STD
,0x00
419 TVP5150_MACROVISION_ON_CTR
,0x0f
422 TVP5150_MACROVISION_OFF_CTR
,0x01
425 TVP5150_TELETEXT_FIL_ENA
,0x00
428 TVP5150_INT_STATUS_REG_A
,0x00
431 TVP5150_INT_ENABLE_REG_A
,0x00
434 TVP5150_INT_CONF
,0x04
437 TVP5150_FIFO_INT_THRESHOLD
,0x80
440 TVP5150_FIFO_RESET
,0x00
443 TVP5150_LINE_NUMBER_INT
,0x00
446 TVP5150_PIX_ALIGN_REG_LOW
,0x4e
449 TVP5150_PIX_ALIGN_REG_HIGH
,0x00
452 TVP5150_FIFO_OUT_CTRL
,0x01
455 TVP5150_FULL_FIELD_ENA
,0x00
458 TVP5150_LINE_MODE_INI
,0x00
461 TVP5150_FULL_FIELD_MODE_REG
,0x7f
468 /* Default values as sugested at TVP5150AM1 datasheet */
469 static const struct i2c_reg_value tvp5150_init_enable
[] = {
471 TVP5150_CONF_SHARED_PIN
, 2
472 },{ /* Automatic offset and AGC enabled */
473 TVP5150_ANAL_CHL_CTL
, 0x15
474 },{ /* Activate YCrCb output 0x9 or 0xd ? */
475 TVP5150_MISC_CTL
, 0x6f
476 },{ /* Activates video std autodetection for all standards */
477 TVP5150_AUTOSW_MSK
, 0x0
478 },{ /* Default format: 0x47. For 4:2:2: 0x40 */
479 TVP5150_DATA_RATE_SEL
, 0x47
481 TVP5150_CHROMA_PROC_CTL_1
, 0x0c
483 TVP5150_CHROMA_PROC_CTL_2
, 0x54
484 },{ /* Non documented, but initialized on WinTV USB2 */
491 struct tvp5150_vbi_type
{
492 unsigned int vbi_type
;
493 unsigned int ini_line
;
494 unsigned int end_line
;
495 unsigned int by_field
:1;
498 struct i2c_vbi_ram_value
{
500 struct tvp5150_vbi_type type
;
501 unsigned char values
[16];
504 /* This struct have the values for each supported VBI Standard
506 tvp5150_vbi_types should follow the same order as vbi_ram_default
507 * value 0 means rom position 0x10, value 1 means rom position 0x30
508 * and so on. There are 16 possible locations from 0 to 15.
511 static struct i2c_vbi_ram_value vbi_ram_default
[] =
513 /* FIXME: Current api doesn't handle all VBI types, those not
514 yet supported are placed under #if 0 */
516 {0x010, /* Teletext, SECAM, WST System A */
517 {V4L2_SLICED_TELETEXT_SECAM
,6,23,1},
518 { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x26,
519 0xe6, 0xb4, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00 }
522 {0x030, /* Teletext, PAL, WST System B */
523 {V4L2_SLICED_TELETEXT_B
,6,22,1},
524 { 0xaa, 0xaa, 0xff, 0xff, 0x27, 0x2e, 0x20, 0x2b,
525 0xa6, 0x72, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00 }
528 {0x050, /* Teletext, PAL, WST System C */
529 {V4L2_SLICED_TELETEXT_PAL_C
,6,22,1},
530 { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x22,
531 0xa6, 0x98, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 }
533 {0x070, /* Teletext, NTSC, WST System B */
534 {V4L2_SLICED_TELETEXT_NTSC_B
,10,21,1},
535 { 0xaa, 0xaa, 0xff, 0xff, 0x27, 0x2e, 0x20, 0x23,
536 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 }
538 {0x090, /* Tetetext, NTSC NABTS System C */
539 {V4L2_SLICED_TELETEXT_NTSC_C
,10,21,1},
540 { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x22,
541 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x15, 0x00 }
543 {0x0b0, /* Teletext, NTSC-J, NABTS System D */
544 {V4L2_SLICED_TELETEXT_NTSC_D
,10,21,1},
545 { 0xaa, 0xaa, 0xff, 0xff, 0xa7, 0x2e, 0x20, 0x23,
546 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 }
548 {0x0d0, /* Closed Caption, PAL/SECAM */
549 {V4L2_SLICED_CAPTION_625
,22,22,1},
550 { 0xaa, 0x2a, 0xff, 0x3f, 0x04, 0x51, 0x6e, 0x02,
551 0xa6, 0x7b, 0x09, 0x00, 0x00, 0x00, 0x27, 0x00 }
554 {0x0f0, /* Closed Caption, NTSC */
555 {V4L2_SLICED_CAPTION_525
,21,21,1},
556 { 0xaa, 0x2a, 0xff, 0x3f, 0x04, 0x51, 0x6e, 0x02,
557 0x69, 0x8c, 0x09, 0x00, 0x00, 0x00, 0x27, 0x00 }
559 {0x110, /* Wide Screen Signal, PAL/SECAM */
560 {V4L2_SLICED_WSS_625
,23,23,1},
561 { 0x5b, 0x55, 0xc5, 0xff, 0x00, 0x71, 0x6e, 0x42,
562 0xa6, 0xcd, 0x0f, 0x00, 0x00, 0x00, 0x3a, 0x00 }
565 {0x130, /* Wide Screen Signal, NTSC C */
566 {V4L2_SLICED_WSS_525
,20,20,1},
567 { 0x38, 0x00, 0x3f, 0x00, 0x00, 0x71, 0x6e, 0x43,
568 0x69, 0x7c, 0x08, 0x00, 0x00, 0x00, 0x39, 0x00 }
570 {0x150, /* Vertical Interval Timecode (VITC), PAL/SECAM */
571 {V4l2_SLICED_VITC_625
,6,22,0},
572 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x6d, 0x49,
573 0xa6, 0x85, 0x08, 0x00, 0x00, 0x00, 0x4c, 0x00 }
575 {0x170, /* Vertical Interval Timecode (VITC), NTSC */
576 {V4l2_SLICED_VITC_525
,10,20,0},
577 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x6d, 0x49,
578 0x69, 0x94, 0x08, 0x00, 0x00, 0x00, 0x4c, 0x00 }
581 {0x190, /* Video Program System (VPS), PAL */
582 {V4L2_SLICED_VPS
,16,16,0},
583 { 0xaa, 0xaa, 0xff, 0xff, 0xba, 0xce, 0x2b, 0x0d,
584 0xa6, 0xda, 0x0b, 0x00, 0x00, 0x00, 0x60, 0x00 }
586 /* 0x1d0 User programmable */
592 static int tvp5150_write_inittab(struct v4l2_subdev
*sd
,
593 const struct i2c_reg_value
*regs
)
595 while (regs
->reg
!= 0xff) {
596 tvp5150_write(sd
, regs
->reg
, regs
->value
);
602 static int tvp5150_vdp_init(struct v4l2_subdev
*sd
,
603 const struct i2c_vbi_ram_value
*regs
)
607 /* Disable Full Field */
608 tvp5150_write(sd
, TVP5150_FULL_FIELD_ENA
, 0);
610 /* Before programming, Line mode should be at 0xff */
611 for (i
= TVP5150_LINE_MODE_INI
; i
<= TVP5150_LINE_MODE_END
; i
++)
612 tvp5150_write(sd
, i
, 0xff);
615 while (regs
->reg
!= (u16
)-1) {
616 tvp5150_write(sd
, TVP5150_CONF_RAM_ADDR_HIGH
, regs
->reg
>> 8);
617 tvp5150_write(sd
, TVP5150_CONF_RAM_ADDR_LOW
, regs
->reg
);
619 for (i
= 0; i
< 16; i
++)
620 tvp5150_write(sd
, TVP5150_VDP_CONF_RAM_DATA
, regs
->values
[i
]);
627 /* Fills VBI capabilities based on i2c_vbi_ram_value struct */
628 static int tvp5150_g_sliced_vbi_cap(struct v4l2_subdev
*sd
,
629 struct v4l2_sliced_vbi_cap
*cap
)
631 const struct i2c_vbi_ram_value
*regs
= vbi_ram_default
;
634 v4l2_dbg(1, debug
, sd
, "g_sliced_vbi_cap\n");
635 memset(cap
, 0, sizeof *cap
);
637 while (regs
->reg
!= (u16
)-1 ) {
638 for (line
=regs
->type
.ini_line
;line
<=regs
->type
.end_line
;line
++) {
639 cap
->service_lines
[0][line
] |= regs
->type
.vbi_type
;
641 cap
->service_set
|= regs
->type
.vbi_type
;
648 /* Set vbi processing
649 * type - one of tvp5150_vbi_types
650 * line - line to gather data
651 * fields: bit 0 field1, bit 1, field2
652 * flags (default=0xf0) is a bitmask, were set means:
653 * bit 7: enable filtering null bytes on CC
654 * bit 6: send data also to FIFO
655 * bit 5: don't allow data with errors on FIFO
656 * bit 4: enable ECC when possible
657 * pix_align = pix alignment:
661 static int tvp5150_set_vbi(struct v4l2_subdev
*sd
,
662 const struct i2c_vbi_ram_value
*regs
,
663 unsigned int type
,u8 flags
, int line
,
666 struct tvp5150
*decoder
= to_tvp5150(sd
);
667 v4l2_std_id std
= decoder
->norm
;
671 if (std
== V4L2_STD_ALL
) {
672 v4l2_err(sd
, "VBI can't be configured without knowing number of lines\n");
674 } else if (std
& V4L2_STD_625_50
) {
675 /* Don't follow NTSC Line number convension */
682 while (regs
->reg
!= (u16
)-1 ) {
683 if ((type
& regs
->type
.vbi_type
) &&
684 (line
>=regs
->type
.ini_line
) &&
685 (line
<=regs
->type
.end_line
)) {
686 type
=regs
->type
.vbi_type
;
693 if (regs
->reg
== (u16
)-1)
696 type
=pos
| (flags
& 0xf0);
697 reg
=((line
-6)<<1)+TVP5150_LINE_MODE_INI
;
700 tvp5150_write(sd
, reg
, type
);
704 tvp5150_write(sd
, reg
+1, type
);
710 static int tvp5150_get_vbi(struct v4l2_subdev
*sd
,
711 const struct i2c_vbi_ram_value
*regs
, int line
)
713 struct tvp5150
*decoder
= to_tvp5150(sd
);
714 v4l2_std_id std
= decoder
->norm
;
718 if (std
== V4L2_STD_ALL
) {
719 v4l2_err(sd
, "VBI can't be configured without knowing number of lines\n");
721 } else if (std
& V4L2_STD_625_50
) {
722 /* Don't follow NTSC Line number convension */
726 if (line
< 6 || line
> 27)
729 reg
= ((line
- 6) << 1) + TVP5150_LINE_MODE_INI
;
731 pos
= tvp5150_read(sd
, reg
) & 0x0f;
733 type
= regs
[pos
].type
.vbi_type
;
735 pos
= tvp5150_read(sd
, reg
+ 1) & 0x0f;
737 type
|= regs
[pos
].type
.vbi_type
;
742 static int tvp5150_set_std(struct v4l2_subdev
*sd
, v4l2_std_id std
)
744 struct tvp5150
*decoder
= to_tvp5150(sd
);
749 /* First tests should be against specific std */
751 if (std
== V4L2_STD_ALL
) {
752 fmt
= 0; /* Autodetect mode */
753 } else if (std
& V4L2_STD_NTSC_443
) {
755 } else if (std
& V4L2_STD_PAL_M
) {
757 } else if (std
& (V4L2_STD_PAL_N
| V4L2_STD_PAL_Nc
)) {
760 /* Then, test against generic ones */
761 if (std
& V4L2_STD_NTSC
)
763 else if (std
& V4L2_STD_PAL
)
765 else if (std
& V4L2_STD_SECAM
)
769 v4l2_dbg(1, debug
, sd
, "Set video std register to %d.\n", fmt
);
770 tvp5150_write(sd
, TVP5150_VIDEO_STD
, fmt
);
774 static int tvp5150_s_std(struct v4l2_subdev
*sd
, v4l2_std_id std
)
776 struct tvp5150
*decoder
= to_tvp5150(sd
);
778 if (decoder
->norm
== std
)
781 return tvp5150_set_std(sd
, std
);
784 static int tvp5150_reset(struct v4l2_subdev
*sd
, u32 val
)
786 struct tvp5150
*decoder
= to_tvp5150(sd
);
787 u8 msb_id
, lsb_id
, msb_rom
, lsb_rom
;
789 msb_id
= tvp5150_read(sd
, TVP5150_MSB_DEV_ID
);
790 lsb_id
= tvp5150_read(sd
, TVP5150_LSB_DEV_ID
);
791 msb_rom
= tvp5150_read(sd
, TVP5150_ROM_MAJOR_VER
);
792 lsb_rom
= tvp5150_read(sd
, TVP5150_ROM_MINOR_VER
);
794 if (msb_rom
== 4 && lsb_rom
== 0) { /* Is TVP5150AM1 */
795 v4l2_info(sd
, "tvp%02x%02xam1 detected.\n", msb_id
, lsb_id
);
797 /* ITU-T BT.656.4 timing */
798 tvp5150_write(sd
, TVP5150_REV_SELECT
, 0);
800 if (msb_rom
== 3 || lsb_rom
== 0x21) { /* Is TVP5150A */
801 v4l2_info(sd
, "tvp%02x%02xa detected.\n", msb_id
, lsb_id
);
803 v4l2_info(sd
, "*** unknown tvp%02x%02x chip detected.\n",
805 v4l2_info(sd
, "*** Rom ver is %d.%d\n", msb_rom
, lsb_rom
);
809 /* Initializes TVP5150 to its default values */
810 tvp5150_write_inittab(sd
, tvp5150_init_default
);
812 /* Initializes VDP registers */
813 tvp5150_vdp_init(sd
, vbi_ram_default
);
815 /* Selects decoder input */
818 /* Initializes TVP5150 to stream enabled values */
819 tvp5150_write_inittab(sd
, tvp5150_init_enable
);
821 /* Initialize image preferences */
822 tvp5150_write(sd
, TVP5150_BRIGHT_CTL
, decoder
->bright
);
823 tvp5150_write(sd
, TVP5150_CONTRAST_CTL
, decoder
->contrast
);
824 tvp5150_write(sd
, TVP5150_SATURATION_CTL
, decoder
->contrast
);
825 tvp5150_write(sd
, TVP5150_HUE_CTL
, decoder
->hue
);
827 tvp5150_set_std(sd
, decoder
->norm
);
831 static int tvp5150_g_ctrl(struct v4l2_subdev
*sd
, struct v4l2_control
*ctrl
)
833 v4l2_dbg(1, debug
, sd
, "g_ctrl called\n");
836 case V4L2_CID_BRIGHTNESS
:
837 ctrl
->value
= tvp5150_read(sd
, TVP5150_BRIGHT_CTL
);
839 case V4L2_CID_CONTRAST
:
840 ctrl
->value
= tvp5150_read(sd
, TVP5150_CONTRAST_CTL
);
842 case V4L2_CID_SATURATION
:
843 ctrl
->value
= tvp5150_read(sd
, TVP5150_SATURATION_CTL
);
846 ctrl
->value
= tvp5150_read(sd
, TVP5150_HUE_CTL
);
852 static int tvp5150_s_ctrl(struct v4l2_subdev
*sd
, struct v4l2_control
*ctrl
)
855 n
= ARRAY_SIZE(tvp5150_qctrl
);
857 for (i
= 0; i
< n
; i
++) {
858 if (ctrl
->id
!= tvp5150_qctrl
[i
].id
)
860 if (ctrl
->value
< tvp5150_qctrl
[i
].minimum
||
861 ctrl
->value
> tvp5150_qctrl
[i
].maximum
)
863 v4l2_dbg(1, debug
, sd
, "s_ctrl: id=%d, value=%d\n",
864 ctrl
->id
, ctrl
->value
);
869 case V4L2_CID_BRIGHTNESS
:
870 tvp5150_write(sd
, TVP5150_BRIGHT_CTL
, ctrl
->value
);
872 case V4L2_CID_CONTRAST
:
873 tvp5150_write(sd
, TVP5150_CONTRAST_CTL
, ctrl
->value
);
875 case V4L2_CID_SATURATION
:
876 tvp5150_write(sd
, TVP5150_SATURATION_CTL
, ctrl
->value
);
879 tvp5150_write(sd
, TVP5150_HUE_CTL
, ctrl
->value
);
885 /****************************************************************************
887 ****************************************************************************/
889 static int tvp5150_s_routing(struct v4l2_subdev
*sd
, const struct v4l2_routing
*route
)
891 struct tvp5150
*decoder
= to_tvp5150(sd
);
893 decoder
->route
= *route
;
898 static int tvp5150_s_fmt(struct v4l2_subdev
*sd
, struct v4l2_format
*fmt
)
900 struct v4l2_sliced_vbi_format
*svbi
;
904 if (fmt
->type
== V4L2_BUF_TYPE_VBI_CAPTURE
) {
905 /* this is for capturing 36 raw vbi lines
906 if there's a way to cut off the beginning 2 vbi lines
907 with the tvp5150 then the vbi line count could be lowered
908 to 17 lines/field again, although I couldn't find a register
909 which could do that cropping */
910 if (fmt
->fmt
.vbi
.sample_format
== V4L2_PIX_FMT_GREY
)
911 tvp5150_write(sd
, TVP5150_LUMA_PROC_CTL_1
, 0x70);
912 if (fmt
->fmt
.vbi
.count
[0] == 18 && fmt
->fmt
.vbi
.count
[1] == 18) {
913 tvp5150_write(sd
, TVP5150_VERT_BLANKING_START
, 0x00);
914 tvp5150_write(sd
, TVP5150_VERT_BLANKING_STOP
, 0x01);
918 if (fmt
->type
!= V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
)
920 svbi
= &fmt
->fmt
.sliced
;
921 if (svbi
->service_set
!= 0) {
922 for (i
= 0; i
<= 23; i
++) {
923 svbi
->service_lines
[1][i
] = 0;
924 svbi
->service_lines
[0][i
] =
925 tvp5150_set_vbi(sd
, vbi_ram_default
,
926 svbi
->service_lines
[0][i
], 0xf0, i
, 3);
929 tvp5150_write(sd
, TVP5150_FIFO_OUT_CTRL
, 1);
932 tvp5150_write(sd
, TVP5150_FIFO_OUT_CTRL
, 0);
934 /* Disable Full Field */
935 tvp5150_write(sd
, TVP5150_FULL_FIELD_ENA
, 0);
937 /* Disable Line modes */
938 for (i
= TVP5150_LINE_MODE_INI
; i
<= TVP5150_LINE_MODE_END
; i
++)
939 tvp5150_write(sd
, i
, 0xff);
944 static int tvp5150_g_fmt(struct v4l2_subdev
*sd
, struct v4l2_format
*fmt
)
946 struct v4l2_sliced_vbi_format
*svbi
;
949 if (fmt
->type
!= V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
)
951 svbi
= &fmt
->fmt
.sliced
;
952 memset(svbi
, 0, sizeof(*svbi
));
954 for (i
= 0; i
<= 23; i
++) {
955 svbi
->service_lines
[0][i
] =
956 tvp5150_get_vbi(sd
, vbi_ram_default
, i
);
957 mask
|= svbi
->service_lines
[0][i
];
959 svbi
->service_set
= mask
;
964 static int tvp5150_g_chip_ident(struct v4l2_subdev
*sd
,
965 struct v4l2_dbg_chip_ident
*chip
)
968 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
970 rev
= tvp5150_read(sd
, TVP5150_ROM_MAJOR_VER
) << 8 |
971 tvp5150_read(sd
, TVP5150_ROM_MINOR_VER
);
973 return v4l2_chip_ident_i2c_client(client
, chip
, V4L2_IDENT_TVP5150
,
978 #ifdef CONFIG_VIDEO_ADV_DEBUG
979 static int tvp5150_g_register(struct v4l2_subdev
*sd
, struct v4l2_dbg_register
*reg
)
981 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
983 if (!v4l2_chip_match_i2c_client(client
, ®
->match
))
985 if (!capable(CAP_SYS_ADMIN
))
987 reg
->val
= tvp5150_read(sd
, reg
->reg
& 0xff);
992 static int tvp5150_s_register(struct v4l2_subdev
*sd
, struct v4l2_dbg_register
*reg
)
994 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
996 if (!v4l2_chip_match_i2c_client(client
, ®
->match
))
998 if (!capable(CAP_SYS_ADMIN
))
1000 tvp5150_write(sd
, reg
->reg
& 0xff, reg
->val
& 0xff);
1005 static int tvp5150_g_tuner(struct v4l2_subdev
*sd
, struct v4l2_tuner
*vt
)
1007 int status
= tvp5150_read(sd
, 0x88);
1009 vt
->signal
= ((status
& 0x04) && (status
& 0x02)) ? 0xffff : 0x0;
1013 static int tvp5150_queryctrl(struct v4l2_subdev
*sd
, struct v4l2_queryctrl
*qc
)
1017 v4l2_dbg(1, debug
, sd
, "queryctrl called\n");
1019 for (i
= 0; i
< ARRAY_SIZE(tvp5150_qctrl
); i
++)
1020 if (qc
->id
&& qc
->id
== tvp5150_qctrl
[i
].id
) {
1021 memcpy(qc
, &(tvp5150_qctrl
[i
]),
1029 static int tvp5150_command(struct i2c_client
*client
, unsigned cmd
, void *arg
)
1031 return v4l2_subdev_command(i2c_get_clientdata(client
), cmd
, arg
);
1034 /* ----------------------------------------------------------------------- */
1036 static const struct v4l2_subdev_core_ops tvp5150_core_ops
= {
1037 .log_status
= tvp5150_log_status
,
1038 .g_ctrl
= tvp5150_g_ctrl
,
1039 .s_ctrl
= tvp5150_s_ctrl
,
1040 .queryctrl
= tvp5150_queryctrl
,
1041 .reset
= tvp5150_reset
,
1042 .g_chip_ident
= tvp5150_g_chip_ident
,
1043 #ifdef CONFIG_VIDEO_ADV_DEBUG
1044 .g_register
= tvp5150_g_register
,
1045 .s_register
= tvp5150_s_register
,
1049 static const struct v4l2_subdev_tuner_ops tvp5150_tuner_ops
= {
1050 .s_std
= tvp5150_s_std
,
1051 .g_tuner
= tvp5150_g_tuner
,
1054 static const struct v4l2_subdev_video_ops tvp5150_video_ops
= {
1055 .s_routing
= tvp5150_s_routing
,
1056 .g_fmt
= tvp5150_g_fmt
,
1057 .s_fmt
= tvp5150_s_fmt
,
1058 .g_sliced_vbi_cap
= tvp5150_g_sliced_vbi_cap
,
1061 static const struct v4l2_subdev_ops tvp5150_ops
= {
1062 .core
= &tvp5150_core_ops
,
1063 .tuner
= &tvp5150_tuner_ops
,
1064 .video
= &tvp5150_video_ops
,
1068 /****************************************************************************
1070 ****************************************************************************/
1072 static int tvp5150_probe(struct i2c_client
*c
,
1073 const struct i2c_device_id
*id
)
1075 struct tvp5150
*core
;
1076 struct v4l2_subdev
*sd
;
1078 /* Check if the adapter supports the needed features */
1079 if (!i2c_check_functionality(c
->adapter
,
1080 I2C_FUNC_SMBUS_READ_BYTE
| I2C_FUNC_SMBUS_WRITE_BYTE_DATA
))
1083 core
= kzalloc(sizeof(struct tvp5150
), GFP_KERNEL
);
1088 v4l2_i2c_subdev_init(sd
, c
, &tvp5150_ops
);
1089 v4l_info(c
, "chip found @ 0x%02x (%s)\n",
1090 c
->addr
<< 1, c
->adapter
->name
);
1092 core
->norm
= V4L2_STD_ALL
; /* Default is autodetect */
1093 core
->route
.input
= TVP5150_COMPOSITE1
;
1096 core
->contrast
= 128;
1101 tvp5150_log_status(sd
);
1105 static int tvp5150_remove(struct i2c_client
*c
)
1107 struct v4l2_subdev
*sd
= i2c_get_clientdata(c
);
1109 v4l2_dbg(1, debug
, sd
,
1110 "tvp5150.c: removing tvp5150 adapter on address 0x%x\n",
1113 v4l2_device_unregister_subdev(sd
);
1114 kfree(to_tvp5150(sd
));
1118 /* ----------------------------------------------------------------------- */
1120 static const struct i2c_device_id tvp5150_id
[] = {
1124 MODULE_DEVICE_TABLE(i2c
, tvp5150_id
);
1126 static struct v4l2_i2c_driver_data v4l2_i2c_data
= {
1128 .command
= tvp5150_command
,
1129 .probe
= tvp5150_probe
,
1130 .remove
= tvp5150_remove
,
1131 .legacy_class
= I2C_CLASS_TV_ANALOG
| I2C_CLASS_TV_DIGITAL
,
1132 .id_table
= tvp5150_id
,