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/slab.h>
10 #include <linux/videodev2.h>
11 #include <linux/delay.h>
12 #include <media/v4l2-device.h>
13 #include <media/tvp5150.h>
14 #include <media/v4l2-i2c-drv.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");
25 module_param(debug
, int, 0);
26 MODULE_PARM_DESC(debug
, "Debug level (0-2)");
28 /* supported controls */
29 static struct v4l2_queryctrl tvp5150_qctrl
[] = {
31 .id
= V4L2_CID_BRIGHTNESS
,
32 .type
= V4L2_CTRL_TYPE_INTEGER
,
40 .id
= V4L2_CID_CONTRAST
,
41 .type
= V4L2_CTRL_TYPE_INTEGER
,
49 .id
= V4L2_CID_SATURATION
,
50 .type
= V4L2_CTRL_TYPE_INTEGER
,
59 .type
= V4L2_CTRL_TYPE_INTEGER
,
70 struct v4l2_subdev sd
;
72 v4l2_std_id norm
; /* Current set standard */
82 static inline struct tvp5150
*to_tvp5150(struct v4l2_subdev
*sd
)
84 return container_of(sd
, struct tvp5150
, sd
);
87 static int tvp5150_read(struct v4l2_subdev
*sd
, unsigned char addr
)
89 struct i2c_client
*c
= v4l2_get_subdevdata(sd
);
90 unsigned char buffer
[1];
94 if (1 != (rc
= i2c_master_send(c
, buffer
, 1)))
95 v4l2_dbg(0, debug
, sd
, "i2c i/o error: rc == %d (should be 1)\n", rc
);
99 if (1 != (rc
= i2c_master_recv(c
, buffer
, 1)))
100 v4l2_dbg(0, debug
, sd
, "i2c i/o error: rc == %d (should be 1)\n", rc
);
102 v4l2_dbg(2, debug
, sd
, "tvp5150: read 0x%02x = 0x%02x\n", addr
, buffer
[0]);
107 static inline void tvp5150_write(struct v4l2_subdev
*sd
, unsigned char addr
,
110 struct i2c_client
*c
= v4l2_get_subdevdata(sd
);
111 unsigned char buffer
[2];
116 v4l2_dbg(2, debug
, sd
, "tvp5150: writing 0x%02x 0x%02x\n", buffer
[0], buffer
[1]);
117 if (2 != (rc
= i2c_master_send(c
, buffer
, 2)))
118 v4l2_dbg(0, debug
, sd
, "i2c i/o error: rc == %d (should be 2)\n", rc
);
121 static void dump_reg_range(struct v4l2_subdev
*sd
, char *s
, u8 init
,
122 const u8 end
, int max_line
)
126 while (init
!= (u8
)(end
+ 1)) {
127 if ((i
% max_line
) == 0) {
130 printk("tvp5150: %s reg 0x%02x = ", s
, init
);
132 printk("%02x ", tvp5150_read(sd
, init
));
140 static int tvp5150_log_status(struct v4l2_subdev
*sd
)
142 printk("tvp5150: Video input source selection #1 = 0x%02x\n",
143 tvp5150_read(sd
, TVP5150_VD_IN_SRC_SEL_1
));
144 printk("tvp5150: Analog channel controls = 0x%02x\n",
145 tvp5150_read(sd
, TVP5150_ANAL_CHL_CTL
));
146 printk("tvp5150: Operation mode controls = 0x%02x\n",
147 tvp5150_read(sd
, TVP5150_OP_MODE_CTL
));
148 printk("tvp5150: Miscellaneous controls = 0x%02x\n",
149 tvp5150_read(sd
, TVP5150_MISC_CTL
));
150 printk("tvp5150: Autoswitch mask= 0x%02x\n",
151 tvp5150_read(sd
, TVP5150_AUTOSW_MSK
));
152 printk("tvp5150: Color killer threshold control = 0x%02x\n",
153 tvp5150_read(sd
, TVP5150_COLOR_KIL_THSH_CTL
));
154 printk("tvp5150: Luminance processing controls #1 #2 and #3 = %02x %02x %02x\n",
155 tvp5150_read(sd
, TVP5150_LUMA_PROC_CTL_1
),
156 tvp5150_read(sd
, TVP5150_LUMA_PROC_CTL_2
),
157 tvp5150_read(sd
, TVP5150_LUMA_PROC_CTL_3
));
158 printk("tvp5150: Brightness control = 0x%02x\n",
159 tvp5150_read(sd
, TVP5150_BRIGHT_CTL
));
160 printk("tvp5150: Color saturation control = 0x%02x\n",
161 tvp5150_read(sd
, TVP5150_SATURATION_CTL
));
162 printk("tvp5150: Hue control = 0x%02x\n",
163 tvp5150_read(sd
, TVP5150_HUE_CTL
));
164 printk("tvp5150: Contrast control = 0x%02x\n",
165 tvp5150_read(sd
, TVP5150_CONTRAST_CTL
));
166 printk("tvp5150: Outputs and data rates select = 0x%02x\n",
167 tvp5150_read(sd
, TVP5150_DATA_RATE_SEL
));
168 printk("tvp5150: Configuration shared pins = 0x%02x\n",
169 tvp5150_read(sd
, TVP5150_CONF_SHARED_PIN
));
170 printk("tvp5150: Active video cropping start = 0x%02x%02x\n",
171 tvp5150_read(sd
, TVP5150_ACT_VD_CROP_ST_MSB
),
172 tvp5150_read(sd
, TVP5150_ACT_VD_CROP_ST_LSB
));
173 printk("tvp5150: Active video cropping stop = 0x%02x%02x\n",
174 tvp5150_read(sd
, TVP5150_ACT_VD_CROP_STP_MSB
),
175 tvp5150_read(sd
, TVP5150_ACT_VD_CROP_STP_LSB
));
176 printk("tvp5150: Genlock/RTC = 0x%02x\n",
177 tvp5150_read(sd
, TVP5150_GENLOCK
));
178 printk("tvp5150: Horizontal sync start = 0x%02x\n",
179 tvp5150_read(sd
, TVP5150_HORIZ_SYNC_START
));
180 printk("tvp5150: Vertical blanking start = 0x%02x\n",
181 tvp5150_read(sd
, TVP5150_VERT_BLANKING_START
));
182 printk("tvp5150: Vertical blanking stop = 0x%02x\n",
183 tvp5150_read(sd
, TVP5150_VERT_BLANKING_STOP
));
184 printk("tvp5150: Chrominance processing control #1 and #2 = %02x %02x\n",
185 tvp5150_read(sd
, TVP5150_CHROMA_PROC_CTL_1
),
186 tvp5150_read(sd
, TVP5150_CHROMA_PROC_CTL_2
));
187 printk("tvp5150: Interrupt reset register B = 0x%02x\n",
188 tvp5150_read(sd
, TVP5150_INT_RESET_REG_B
));
189 printk("tvp5150: Interrupt enable register B = 0x%02x\n",
190 tvp5150_read(sd
, TVP5150_INT_ENABLE_REG_B
));
191 printk("tvp5150: Interrupt configuration register B = 0x%02x\n",
192 tvp5150_read(sd
, TVP5150_INTT_CONFIG_REG_B
));
193 printk("tvp5150: Video standard = 0x%02x\n",
194 tvp5150_read(sd
, TVP5150_VIDEO_STD
));
195 printk("tvp5150: Chroma gain factor: Cb=0x%02x Cr=0x%02x\n",
196 tvp5150_read(sd
, TVP5150_CB_GAIN_FACT
),
197 tvp5150_read(sd
, TVP5150_CR_GAIN_FACTOR
));
198 printk("tvp5150: Macrovision on counter = 0x%02x\n",
199 tvp5150_read(sd
, TVP5150_MACROVISION_ON_CTR
));
200 printk("tvp5150: Macrovision off counter = 0x%02x\n",
201 tvp5150_read(sd
, TVP5150_MACROVISION_OFF_CTR
));
202 printk("tvp5150: ITU-R BT.656.%d timing(TVP5150AM1 only)\n",
203 (tvp5150_read(sd
, TVP5150_REV_SELECT
) & 1) ? 3 : 4);
204 printk("tvp5150: Device ID = %02x%02x\n",
205 tvp5150_read(sd
, TVP5150_MSB_DEV_ID
),
206 tvp5150_read(sd
, TVP5150_LSB_DEV_ID
));
207 printk("tvp5150: ROM version = (hex) %02x.%02x\n",
208 tvp5150_read(sd
, TVP5150_ROM_MAJOR_VER
),
209 tvp5150_read(sd
, TVP5150_ROM_MINOR_VER
));
210 printk("tvp5150: Vertical line count = 0x%02x%02x\n",
211 tvp5150_read(sd
, TVP5150_VERT_LN_COUNT_MSB
),
212 tvp5150_read(sd
, TVP5150_VERT_LN_COUNT_LSB
));
213 printk("tvp5150: Interrupt status register B = 0x%02x\n",
214 tvp5150_read(sd
, TVP5150_INT_STATUS_REG_B
));
215 printk("tvp5150: Interrupt active register B = 0x%02x\n",
216 tvp5150_read(sd
, TVP5150_INT_ACTIVE_REG_B
));
217 printk("tvp5150: Status regs #1 to #5 = %02x %02x %02x %02x %02x\n",
218 tvp5150_read(sd
, TVP5150_STATUS_REG_1
),
219 tvp5150_read(sd
, TVP5150_STATUS_REG_2
),
220 tvp5150_read(sd
, TVP5150_STATUS_REG_3
),
221 tvp5150_read(sd
, TVP5150_STATUS_REG_4
),
222 tvp5150_read(sd
, TVP5150_STATUS_REG_5
));
224 dump_reg_range(sd
, "Teletext filter 1", TVP5150_TELETEXT_FIL1_INI
,
225 TVP5150_TELETEXT_FIL1_END
, 8);
226 dump_reg_range(sd
, "Teletext filter 2", TVP5150_TELETEXT_FIL2_INI
,
227 TVP5150_TELETEXT_FIL2_END
, 8);
229 printk("tvp5150: Teletext filter enable = 0x%02x\n",
230 tvp5150_read(sd
, TVP5150_TELETEXT_FIL_ENA
));
231 printk("tvp5150: Interrupt status register A = 0x%02x\n",
232 tvp5150_read(sd
, TVP5150_INT_STATUS_REG_A
));
233 printk("tvp5150: Interrupt enable register A = 0x%02x\n",
234 tvp5150_read(sd
, TVP5150_INT_ENABLE_REG_A
));
235 printk("tvp5150: Interrupt configuration = 0x%02x\n",
236 tvp5150_read(sd
, TVP5150_INT_CONF
));
237 printk("tvp5150: VDP status register = 0x%02x\n",
238 tvp5150_read(sd
, TVP5150_VDP_STATUS_REG
));
239 printk("tvp5150: FIFO word count = 0x%02x\n",
240 tvp5150_read(sd
, TVP5150_FIFO_WORD_COUNT
));
241 printk("tvp5150: FIFO interrupt threshold = 0x%02x\n",
242 tvp5150_read(sd
, TVP5150_FIFO_INT_THRESHOLD
));
243 printk("tvp5150: FIFO reset = 0x%02x\n",
244 tvp5150_read(sd
, TVP5150_FIFO_RESET
));
245 printk("tvp5150: Line number interrupt = 0x%02x\n",
246 tvp5150_read(sd
, TVP5150_LINE_NUMBER_INT
));
247 printk("tvp5150: Pixel alignment register = 0x%02x%02x\n",
248 tvp5150_read(sd
, TVP5150_PIX_ALIGN_REG_HIGH
),
249 tvp5150_read(sd
, TVP5150_PIX_ALIGN_REG_LOW
));
250 printk("tvp5150: FIFO output control = 0x%02x\n",
251 tvp5150_read(sd
, TVP5150_FIFO_OUT_CTRL
));
252 printk("tvp5150: Full field enable = 0x%02x\n",
253 tvp5150_read(sd
, TVP5150_FULL_FIELD_ENA
));
254 printk("tvp5150: Full field mode register = 0x%02x\n",
255 tvp5150_read(sd
, TVP5150_FULL_FIELD_MODE_REG
));
257 dump_reg_range(sd
, "CC data", TVP5150_CC_DATA_INI
,
258 TVP5150_CC_DATA_END
, 8);
260 dump_reg_range(sd
, "WSS data", TVP5150_WSS_DATA_INI
,
261 TVP5150_WSS_DATA_END
, 8);
263 dump_reg_range(sd
, "VPS data", TVP5150_VPS_DATA_INI
,
264 TVP5150_VPS_DATA_END
, 8);
266 dump_reg_range(sd
, "VITC data", TVP5150_VITC_DATA_INI
,
267 TVP5150_VITC_DATA_END
, 10);
269 dump_reg_range(sd
, "Line mode", TVP5150_LINE_MODE_INI
,
270 TVP5150_LINE_MODE_END
, 8);
274 /****************************************************************************
276 ****************************************************************************/
278 static inline void tvp5150_selmux(struct v4l2_subdev
*sd
)
281 struct tvp5150
*decoder
= to_tvp5150(sd
);
285 if ((decoder
->output
& TVP5150_BLACK_SCREEN
) || !decoder
->enable
)
288 switch (decoder
->input
) {
289 case TVP5150_COMPOSITE1
:
292 case TVP5150_COMPOSITE0
:
293 opmode
=0x30; /* TV Mode */
298 opmode
=0; /* Auto Mode */
302 v4l2_dbg(1, debug
, sd
, "Selecting video route: route input=%i, output=%i "
303 "=> tvp5150 input=%i, opmode=%i\n",
304 decoder
->input
, decoder
->output
,
307 tvp5150_write(sd
, TVP5150_OP_MODE_CTL
, opmode
);
308 tvp5150_write(sd
, TVP5150_VD_IN_SRC_SEL_1
, input
);
310 /* Svideo should enable YCrCb output and disable GPCL output
311 * For Composite and TV, it should be the reverse
313 val
= tvp5150_read(sd
, TVP5150_MISC_CTL
);
314 if (decoder
->input
== TVP5150_SVIDEO
)
315 val
= (val
& ~0x40) | 0x10;
317 val
= (val
& ~0x10) | 0x40;
318 tvp5150_write(sd
, TVP5150_MISC_CTL
, val
);
321 struct i2c_reg_value
{
326 /* Default values as sugested at TVP5150AM1 datasheet */
327 static const struct i2c_reg_value tvp5150_init_default
[] = {
329 TVP5150_VD_IN_SRC_SEL_1
,0x00
332 TVP5150_ANAL_CHL_CTL
,0x15
335 TVP5150_OP_MODE_CTL
,0x00
338 TVP5150_MISC_CTL
,0x01
341 TVP5150_COLOR_KIL_THSH_CTL
,0x10
344 TVP5150_LUMA_PROC_CTL_1
,0x60
347 TVP5150_LUMA_PROC_CTL_2
,0x00
350 TVP5150_BRIGHT_CTL
,0x80
353 TVP5150_SATURATION_CTL
,0x80
359 TVP5150_CONTRAST_CTL
,0x80
362 TVP5150_DATA_RATE_SEL
,0x47
365 TVP5150_LUMA_PROC_CTL_3
,0x00
368 TVP5150_CONF_SHARED_PIN
,0x08
371 TVP5150_ACT_VD_CROP_ST_MSB
,0x00
374 TVP5150_ACT_VD_CROP_ST_LSB
,0x00
377 TVP5150_ACT_VD_CROP_STP_MSB
,0x00
380 TVP5150_ACT_VD_CROP_STP_LSB
,0x00
386 TVP5150_HORIZ_SYNC_START
,0x80
389 TVP5150_VERT_BLANKING_START
,0x00
392 TVP5150_VERT_BLANKING_STOP
,0x00
395 TVP5150_CHROMA_PROC_CTL_1
,0x0c
398 TVP5150_CHROMA_PROC_CTL_2
,0x14
401 TVP5150_INT_RESET_REG_B
,0x00
404 TVP5150_INT_ENABLE_REG_B
,0x00
407 TVP5150_INTT_CONFIG_REG_B
,0x00
410 TVP5150_VIDEO_STD
,0x00
413 TVP5150_MACROVISION_ON_CTR
,0x0f
416 TVP5150_MACROVISION_OFF_CTR
,0x01
419 TVP5150_TELETEXT_FIL_ENA
,0x00
422 TVP5150_INT_STATUS_REG_A
,0x00
425 TVP5150_INT_ENABLE_REG_A
,0x00
428 TVP5150_INT_CONF
,0x04
431 TVP5150_FIFO_INT_THRESHOLD
,0x80
434 TVP5150_FIFO_RESET
,0x00
437 TVP5150_LINE_NUMBER_INT
,0x00
440 TVP5150_PIX_ALIGN_REG_LOW
,0x4e
443 TVP5150_PIX_ALIGN_REG_HIGH
,0x00
446 TVP5150_FIFO_OUT_CTRL
,0x01
449 TVP5150_FULL_FIELD_ENA
,0x00
452 TVP5150_LINE_MODE_INI
,0x00
455 TVP5150_FULL_FIELD_MODE_REG
,0x7f
462 /* Default values as sugested at TVP5150AM1 datasheet */
463 static const struct i2c_reg_value tvp5150_init_enable
[] = {
465 TVP5150_CONF_SHARED_PIN
, 2
466 },{ /* Automatic offset and AGC enabled */
467 TVP5150_ANAL_CHL_CTL
, 0x15
468 },{ /* Activate YCrCb output 0x9 or 0xd ? */
469 TVP5150_MISC_CTL
, 0x6f
470 },{ /* Activates video std autodetection for all standards */
471 TVP5150_AUTOSW_MSK
, 0x0
472 },{ /* Default format: 0x47. For 4:2:2: 0x40 */
473 TVP5150_DATA_RATE_SEL
, 0x47
475 TVP5150_CHROMA_PROC_CTL_1
, 0x0c
477 TVP5150_CHROMA_PROC_CTL_2
, 0x54
478 },{ /* Non documented, but initialized on WinTV USB2 */
485 struct tvp5150_vbi_type
{
486 unsigned int vbi_type
;
487 unsigned int ini_line
;
488 unsigned int end_line
;
489 unsigned int by_field
:1;
492 struct i2c_vbi_ram_value
{
494 struct tvp5150_vbi_type type
;
495 unsigned char values
[16];
498 /* This struct have the values for each supported VBI Standard
500 tvp5150_vbi_types should follow the same order as vbi_ram_default
501 * value 0 means rom position 0x10, value 1 means rom position 0x30
502 * and so on. There are 16 possible locations from 0 to 15.
505 static struct i2c_vbi_ram_value vbi_ram_default
[] =
507 /* FIXME: Current api doesn't handle all VBI types, those not
508 yet supported are placed under #if 0 */
510 {0x010, /* Teletext, SECAM, WST System A */
511 {V4L2_SLICED_TELETEXT_SECAM
,6,23,1},
512 { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x26,
513 0xe6, 0xb4, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00 }
516 {0x030, /* Teletext, PAL, WST System B */
517 {V4L2_SLICED_TELETEXT_B
,6,22,1},
518 { 0xaa, 0xaa, 0xff, 0xff, 0x27, 0x2e, 0x20, 0x2b,
519 0xa6, 0x72, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00 }
522 {0x050, /* Teletext, PAL, WST System C */
523 {V4L2_SLICED_TELETEXT_PAL_C
,6,22,1},
524 { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x22,
525 0xa6, 0x98, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 }
527 {0x070, /* Teletext, NTSC, WST System B */
528 {V4L2_SLICED_TELETEXT_NTSC_B
,10,21,1},
529 { 0xaa, 0xaa, 0xff, 0xff, 0x27, 0x2e, 0x20, 0x23,
530 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 }
532 {0x090, /* Tetetext, NTSC NABTS System C */
533 {V4L2_SLICED_TELETEXT_NTSC_C
,10,21,1},
534 { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x22,
535 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x15, 0x00 }
537 {0x0b0, /* Teletext, NTSC-J, NABTS System D */
538 {V4L2_SLICED_TELETEXT_NTSC_D
,10,21,1},
539 { 0xaa, 0xaa, 0xff, 0xff, 0xa7, 0x2e, 0x20, 0x23,
540 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 }
542 {0x0d0, /* Closed Caption, PAL/SECAM */
543 {V4L2_SLICED_CAPTION_625
,22,22,1},
544 { 0xaa, 0x2a, 0xff, 0x3f, 0x04, 0x51, 0x6e, 0x02,
545 0xa6, 0x7b, 0x09, 0x00, 0x00, 0x00, 0x27, 0x00 }
548 {0x0f0, /* Closed Caption, NTSC */
549 {V4L2_SLICED_CAPTION_525
,21,21,1},
550 { 0xaa, 0x2a, 0xff, 0x3f, 0x04, 0x51, 0x6e, 0x02,
551 0x69, 0x8c, 0x09, 0x00, 0x00, 0x00, 0x27, 0x00 }
553 {0x110, /* Wide Screen Signal, PAL/SECAM */
554 {V4L2_SLICED_WSS_625
,23,23,1},
555 { 0x5b, 0x55, 0xc5, 0xff, 0x00, 0x71, 0x6e, 0x42,
556 0xa6, 0xcd, 0x0f, 0x00, 0x00, 0x00, 0x3a, 0x00 }
559 {0x130, /* Wide Screen Signal, NTSC C */
560 {V4L2_SLICED_WSS_525
,20,20,1},
561 { 0x38, 0x00, 0x3f, 0x00, 0x00, 0x71, 0x6e, 0x43,
562 0x69, 0x7c, 0x08, 0x00, 0x00, 0x00, 0x39, 0x00 }
564 {0x150, /* Vertical Interval Timecode (VITC), PAL/SECAM */
565 {V4l2_SLICED_VITC_625
,6,22,0},
566 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x6d, 0x49,
567 0xa6, 0x85, 0x08, 0x00, 0x00, 0x00, 0x4c, 0x00 }
569 {0x170, /* Vertical Interval Timecode (VITC), NTSC */
570 {V4l2_SLICED_VITC_525
,10,20,0},
571 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x6d, 0x49,
572 0x69, 0x94, 0x08, 0x00, 0x00, 0x00, 0x4c, 0x00 }
575 {0x190, /* Video Program System (VPS), PAL */
576 {V4L2_SLICED_VPS
,16,16,0},
577 { 0xaa, 0xaa, 0xff, 0xff, 0xba, 0xce, 0x2b, 0x0d,
578 0xa6, 0xda, 0x0b, 0x00, 0x00, 0x00, 0x60, 0x00 }
580 /* 0x1d0 User programmable */
586 static int tvp5150_write_inittab(struct v4l2_subdev
*sd
,
587 const struct i2c_reg_value
*regs
)
589 while (regs
->reg
!= 0xff) {
590 tvp5150_write(sd
, regs
->reg
, regs
->value
);
596 static int tvp5150_vdp_init(struct v4l2_subdev
*sd
,
597 const struct i2c_vbi_ram_value
*regs
)
601 /* Disable Full Field */
602 tvp5150_write(sd
, TVP5150_FULL_FIELD_ENA
, 0);
604 /* Before programming, Line mode should be at 0xff */
605 for (i
= TVP5150_LINE_MODE_INI
; i
<= TVP5150_LINE_MODE_END
; i
++)
606 tvp5150_write(sd
, i
, 0xff);
609 while (regs
->reg
!= (u16
)-1) {
610 tvp5150_write(sd
, TVP5150_CONF_RAM_ADDR_HIGH
, regs
->reg
>> 8);
611 tvp5150_write(sd
, TVP5150_CONF_RAM_ADDR_LOW
, regs
->reg
);
613 for (i
= 0; i
< 16; i
++)
614 tvp5150_write(sd
, TVP5150_VDP_CONF_RAM_DATA
, regs
->values
[i
]);
621 /* Fills VBI capabilities based on i2c_vbi_ram_value struct */
622 static int tvp5150_g_sliced_vbi_cap(struct v4l2_subdev
*sd
,
623 struct v4l2_sliced_vbi_cap
*cap
)
625 const struct i2c_vbi_ram_value
*regs
= vbi_ram_default
;
628 v4l2_dbg(1, debug
, sd
, "g_sliced_vbi_cap\n");
629 memset(cap
, 0, sizeof *cap
);
631 while (regs
->reg
!= (u16
)-1 ) {
632 for (line
=regs
->type
.ini_line
;line
<=regs
->type
.end_line
;line
++) {
633 cap
->service_lines
[0][line
] |= regs
->type
.vbi_type
;
635 cap
->service_set
|= regs
->type
.vbi_type
;
642 /* Set vbi processing
643 * type - one of tvp5150_vbi_types
644 * line - line to gather data
645 * fields: bit 0 field1, bit 1, field2
646 * flags (default=0xf0) is a bitmask, were set means:
647 * bit 7: enable filtering null bytes on CC
648 * bit 6: send data also to FIFO
649 * bit 5: don't allow data with errors on FIFO
650 * bit 4: enable ECC when possible
651 * pix_align = pix alignment:
655 static int tvp5150_set_vbi(struct v4l2_subdev
*sd
,
656 const struct i2c_vbi_ram_value
*regs
,
657 unsigned int type
,u8 flags
, int line
,
660 struct tvp5150
*decoder
= to_tvp5150(sd
);
661 v4l2_std_id std
= decoder
->norm
;
665 if (std
== V4L2_STD_ALL
) {
666 v4l2_err(sd
, "VBI can't be configured without knowing number of lines\n");
668 } else if (std
& V4L2_STD_625_50
) {
669 /* Don't follow NTSC Line number convension */
676 while (regs
->reg
!= (u16
)-1 ) {
677 if ((type
& regs
->type
.vbi_type
) &&
678 (line
>=regs
->type
.ini_line
) &&
679 (line
<=regs
->type
.end_line
)) {
680 type
=regs
->type
.vbi_type
;
687 if (regs
->reg
== (u16
)-1)
690 type
=pos
| (flags
& 0xf0);
691 reg
=((line
-6)<<1)+TVP5150_LINE_MODE_INI
;
694 tvp5150_write(sd
, reg
, type
);
698 tvp5150_write(sd
, reg
+1, type
);
704 static int tvp5150_get_vbi(struct v4l2_subdev
*sd
,
705 const struct i2c_vbi_ram_value
*regs
, int line
)
707 struct tvp5150
*decoder
= to_tvp5150(sd
);
708 v4l2_std_id std
= decoder
->norm
;
712 if (std
== V4L2_STD_ALL
) {
713 v4l2_err(sd
, "VBI can't be configured without knowing number of lines\n");
715 } else if (std
& V4L2_STD_625_50
) {
716 /* Don't follow NTSC Line number convension */
720 if (line
< 6 || line
> 27)
723 reg
= ((line
- 6) << 1) + TVP5150_LINE_MODE_INI
;
725 pos
= tvp5150_read(sd
, reg
) & 0x0f;
727 type
= regs
[pos
].type
.vbi_type
;
729 pos
= tvp5150_read(sd
, reg
+ 1) & 0x0f;
731 type
|= regs
[pos
].type
.vbi_type
;
736 static int tvp5150_set_std(struct v4l2_subdev
*sd
, v4l2_std_id std
)
738 struct tvp5150
*decoder
= to_tvp5150(sd
);
743 /* First tests should be against specific std */
745 if (std
== V4L2_STD_ALL
) {
746 fmt
= 0; /* Autodetect mode */
747 } else if (std
& V4L2_STD_NTSC_443
) {
749 } else if (std
& V4L2_STD_PAL_M
) {
751 } else if (std
& (V4L2_STD_PAL_N
| V4L2_STD_PAL_Nc
)) {
754 /* Then, test against generic ones */
755 if (std
& V4L2_STD_NTSC
)
757 else if (std
& V4L2_STD_PAL
)
759 else if (std
& V4L2_STD_SECAM
)
763 v4l2_dbg(1, debug
, sd
, "Set video std register to %d.\n", fmt
);
764 tvp5150_write(sd
, TVP5150_VIDEO_STD
, fmt
);
768 static int tvp5150_s_std(struct v4l2_subdev
*sd
, v4l2_std_id std
)
770 struct tvp5150
*decoder
= to_tvp5150(sd
);
772 if (decoder
->norm
== std
)
775 return tvp5150_set_std(sd
, std
);
778 static int tvp5150_reset(struct v4l2_subdev
*sd
, u32 val
)
780 struct tvp5150
*decoder
= to_tvp5150(sd
);
781 u8 msb_id
, lsb_id
, msb_rom
, lsb_rom
;
783 msb_id
= tvp5150_read(sd
, TVP5150_MSB_DEV_ID
);
784 lsb_id
= tvp5150_read(sd
, TVP5150_LSB_DEV_ID
);
785 msb_rom
= tvp5150_read(sd
, TVP5150_ROM_MAJOR_VER
);
786 lsb_rom
= tvp5150_read(sd
, TVP5150_ROM_MINOR_VER
);
788 if (msb_rom
== 4 && lsb_rom
== 0) { /* Is TVP5150AM1 */
789 v4l2_info(sd
, "tvp%02x%02xam1 detected.\n", msb_id
, lsb_id
);
791 /* ITU-T BT.656.4 timing */
792 tvp5150_write(sd
, TVP5150_REV_SELECT
, 0);
794 if (msb_rom
== 3 || lsb_rom
== 0x21) { /* Is TVP5150A */
795 v4l2_info(sd
, "tvp%02x%02xa detected.\n", msb_id
, lsb_id
);
797 v4l2_info(sd
, "*** unknown tvp%02x%02x chip detected.\n",
799 v4l2_info(sd
, "*** Rom ver is %d.%d\n", msb_rom
, lsb_rom
);
803 /* Initializes TVP5150 to its default values */
804 tvp5150_write_inittab(sd
, tvp5150_init_default
);
806 /* Initializes VDP registers */
807 tvp5150_vdp_init(sd
, vbi_ram_default
);
809 /* Selects decoder input */
812 /* Initializes TVP5150 to stream enabled values */
813 tvp5150_write_inittab(sd
, tvp5150_init_enable
);
815 /* Initialize image preferences */
816 tvp5150_write(sd
, TVP5150_BRIGHT_CTL
, decoder
->bright
);
817 tvp5150_write(sd
, TVP5150_CONTRAST_CTL
, decoder
->contrast
);
818 tvp5150_write(sd
, TVP5150_SATURATION_CTL
, decoder
->contrast
);
819 tvp5150_write(sd
, TVP5150_HUE_CTL
, decoder
->hue
);
821 tvp5150_set_std(sd
, decoder
->norm
);
825 static int tvp5150_g_ctrl(struct v4l2_subdev
*sd
, struct v4l2_control
*ctrl
)
827 v4l2_dbg(1, debug
, sd
, "g_ctrl called\n");
830 case V4L2_CID_BRIGHTNESS
:
831 ctrl
->value
= tvp5150_read(sd
, TVP5150_BRIGHT_CTL
);
833 case V4L2_CID_CONTRAST
:
834 ctrl
->value
= tvp5150_read(sd
, TVP5150_CONTRAST_CTL
);
836 case V4L2_CID_SATURATION
:
837 ctrl
->value
= tvp5150_read(sd
, TVP5150_SATURATION_CTL
);
840 ctrl
->value
= tvp5150_read(sd
, TVP5150_HUE_CTL
);
846 static int tvp5150_s_ctrl(struct v4l2_subdev
*sd
, struct v4l2_control
*ctrl
)
849 n
= ARRAY_SIZE(tvp5150_qctrl
);
851 for (i
= 0; i
< n
; i
++) {
852 if (ctrl
->id
!= tvp5150_qctrl
[i
].id
)
854 if (ctrl
->value
< tvp5150_qctrl
[i
].minimum
||
855 ctrl
->value
> tvp5150_qctrl
[i
].maximum
)
857 v4l2_dbg(1, debug
, sd
, "s_ctrl: id=%d, value=%d\n",
858 ctrl
->id
, ctrl
->value
);
863 case V4L2_CID_BRIGHTNESS
:
864 tvp5150_write(sd
, TVP5150_BRIGHT_CTL
, ctrl
->value
);
866 case V4L2_CID_CONTRAST
:
867 tvp5150_write(sd
, TVP5150_CONTRAST_CTL
, ctrl
->value
);
869 case V4L2_CID_SATURATION
:
870 tvp5150_write(sd
, TVP5150_SATURATION_CTL
, ctrl
->value
);
873 tvp5150_write(sd
, TVP5150_HUE_CTL
, ctrl
->value
);
879 /****************************************************************************
881 ****************************************************************************/
883 static int tvp5150_s_routing(struct v4l2_subdev
*sd
,
884 u32 input
, u32 output
, u32 config
)
886 struct tvp5150
*decoder
= to_tvp5150(sd
);
888 decoder
->input
= input
;
889 decoder
->output
= output
;
894 static int tvp5150_s_raw_fmt(struct v4l2_subdev
*sd
, struct v4l2_vbi_format
*fmt
)
896 /* this is for capturing 36 raw vbi lines
897 if there's a way to cut off the beginning 2 vbi lines
898 with the tvp5150 then the vbi line count could be lowered
899 to 17 lines/field again, although I couldn't find a register
900 which could do that cropping */
901 if (fmt
->sample_format
== V4L2_PIX_FMT_GREY
)
902 tvp5150_write(sd
, TVP5150_LUMA_PROC_CTL_1
, 0x70);
903 if (fmt
->count
[0] == 18 && fmt
->count
[1] == 18) {
904 tvp5150_write(sd
, TVP5150_VERT_BLANKING_START
, 0x00);
905 tvp5150_write(sd
, TVP5150_VERT_BLANKING_STOP
, 0x01);
910 static int tvp5150_s_sliced_fmt(struct v4l2_subdev
*sd
, struct v4l2_sliced_vbi_format
*svbi
)
914 if (svbi
->service_set
!= 0) {
915 for (i
= 0; i
<= 23; i
++) {
916 svbi
->service_lines
[1][i
] = 0;
917 svbi
->service_lines
[0][i
] =
918 tvp5150_set_vbi(sd
, vbi_ram_default
,
919 svbi
->service_lines
[0][i
], 0xf0, i
, 3);
922 tvp5150_write(sd
, TVP5150_FIFO_OUT_CTRL
, 1);
925 tvp5150_write(sd
, TVP5150_FIFO_OUT_CTRL
, 0);
927 /* Disable Full Field */
928 tvp5150_write(sd
, TVP5150_FULL_FIELD_ENA
, 0);
930 /* Disable Line modes */
931 for (i
= TVP5150_LINE_MODE_INI
; i
<= TVP5150_LINE_MODE_END
; i
++)
932 tvp5150_write(sd
, i
, 0xff);
937 static int tvp5150_g_sliced_fmt(struct v4l2_subdev
*sd
, struct v4l2_sliced_vbi_format
*svbi
)
941 memset(svbi
, 0, sizeof(*svbi
));
943 for (i
= 0; i
<= 23; i
++) {
944 svbi
->service_lines
[0][i
] =
945 tvp5150_get_vbi(sd
, vbi_ram_default
, i
);
946 mask
|= svbi
->service_lines
[0][i
];
948 svbi
->service_set
= mask
;
952 static int tvp5150_g_chip_ident(struct v4l2_subdev
*sd
,
953 struct v4l2_dbg_chip_ident
*chip
)
956 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
958 rev
= tvp5150_read(sd
, TVP5150_ROM_MAJOR_VER
) << 8 |
959 tvp5150_read(sd
, TVP5150_ROM_MINOR_VER
);
961 return v4l2_chip_ident_i2c_client(client
, chip
, V4L2_IDENT_TVP5150
,
966 #ifdef CONFIG_VIDEO_ADV_DEBUG
967 static int tvp5150_g_register(struct v4l2_subdev
*sd
, struct v4l2_dbg_register
*reg
)
969 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
971 if (!v4l2_chip_match_i2c_client(client
, ®
->match
))
973 if (!capable(CAP_SYS_ADMIN
))
975 reg
->val
= tvp5150_read(sd
, reg
->reg
& 0xff);
980 static int tvp5150_s_register(struct v4l2_subdev
*sd
, struct v4l2_dbg_register
*reg
)
982 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
984 if (!v4l2_chip_match_i2c_client(client
, ®
->match
))
986 if (!capable(CAP_SYS_ADMIN
))
988 tvp5150_write(sd
, reg
->reg
& 0xff, reg
->val
& 0xff);
993 static int tvp5150_g_tuner(struct v4l2_subdev
*sd
, struct v4l2_tuner
*vt
)
995 int status
= tvp5150_read(sd
, 0x88);
997 vt
->signal
= ((status
& 0x04) && (status
& 0x02)) ? 0xffff : 0x0;
1001 static int tvp5150_queryctrl(struct v4l2_subdev
*sd
, struct v4l2_queryctrl
*qc
)
1005 v4l2_dbg(1, debug
, sd
, "queryctrl called\n");
1007 for (i
= 0; i
< ARRAY_SIZE(tvp5150_qctrl
); i
++)
1008 if (qc
->id
&& qc
->id
== tvp5150_qctrl
[i
].id
) {
1009 memcpy(qc
, &(tvp5150_qctrl
[i
]),
1017 /* ----------------------------------------------------------------------- */
1019 static const struct v4l2_subdev_core_ops tvp5150_core_ops
= {
1020 .log_status
= tvp5150_log_status
,
1021 .g_ctrl
= tvp5150_g_ctrl
,
1022 .s_ctrl
= tvp5150_s_ctrl
,
1023 .queryctrl
= tvp5150_queryctrl
,
1024 .s_std
= tvp5150_s_std
,
1025 .reset
= tvp5150_reset
,
1026 .g_chip_ident
= tvp5150_g_chip_ident
,
1027 #ifdef CONFIG_VIDEO_ADV_DEBUG
1028 .g_register
= tvp5150_g_register
,
1029 .s_register
= tvp5150_s_register
,
1033 static const struct v4l2_subdev_tuner_ops tvp5150_tuner_ops
= {
1034 .g_tuner
= tvp5150_g_tuner
,
1037 static const struct v4l2_subdev_video_ops tvp5150_video_ops
= {
1038 .s_routing
= tvp5150_s_routing
,
1041 static const struct v4l2_subdev_vbi_ops tvp5150_vbi_ops
= {
1042 .g_sliced_vbi_cap
= tvp5150_g_sliced_vbi_cap
,
1043 .g_sliced_fmt
= tvp5150_g_sliced_fmt
,
1044 .s_sliced_fmt
= tvp5150_s_sliced_fmt
,
1045 .s_raw_fmt
= tvp5150_s_raw_fmt
,
1048 static const struct v4l2_subdev_ops tvp5150_ops
= {
1049 .core
= &tvp5150_core_ops
,
1050 .tuner
= &tvp5150_tuner_ops
,
1051 .video
= &tvp5150_video_ops
,
1052 .vbi
= &tvp5150_vbi_ops
,
1056 /****************************************************************************
1058 ****************************************************************************/
1060 static int tvp5150_probe(struct i2c_client
*c
,
1061 const struct i2c_device_id
*id
)
1063 struct tvp5150
*core
;
1064 struct v4l2_subdev
*sd
;
1066 /* Check if the adapter supports the needed features */
1067 if (!i2c_check_functionality(c
->adapter
,
1068 I2C_FUNC_SMBUS_READ_BYTE
| I2C_FUNC_SMBUS_WRITE_BYTE_DATA
))
1071 core
= kzalloc(sizeof(struct tvp5150
), GFP_KERNEL
);
1076 v4l2_i2c_subdev_init(sd
, c
, &tvp5150_ops
);
1077 v4l_info(c
, "chip found @ 0x%02x (%s)\n",
1078 c
->addr
<< 1, c
->adapter
->name
);
1080 core
->norm
= V4L2_STD_ALL
; /* Default is autodetect */
1081 core
->input
= TVP5150_COMPOSITE1
;
1084 core
->contrast
= 128;
1089 tvp5150_log_status(sd
);
1093 static int tvp5150_remove(struct i2c_client
*c
)
1095 struct v4l2_subdev
*sd
= i2c_get_clientdata(c
);
1097 v4l2_dbg(1, debug
, sd
,
1098 "tvp5150.c: removing tvp5150 adapter on address 0x%x\n",
1101 v4l2_device_unregister_subdev(sd
);
1102 kfree(to_tvp5150(sd
));
1106 /* ----------------------------------------------------------------------- */
1108 static const struct i2c_device_id tvp5150_id
[] = {
1112 MODULE_DEVICE_TABLE(i2c
, tvp5150_id
);
1114 static struct v4l2_i2c_driver_data v4l2_i2c_data
= {
1116 .probe
= tvp5150_probe
,
1117 .remove
= tvp5150_remove
,
1118 .id_table
= tvp5150_id
,