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-chip-ident.h>
15 #include <media/v4l2-ctrls.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)");
29 struct v4l2_subdev sd
;
30 struct v4l2_ctrl_handler hdl
;
32 v4l2_std_id norm
; /* Current set standard */
38 static inline struct tvp5150
*to_tvp5150(struct v4l2_subdev
*sd
)
40 return container_of(sd
, struct tvp5150
, sd
);
43 static inline struct v4l2_subdev
*to_sd(struct v4l2_ctrl
*ctrl
)
45 return &container_of(ctrl
->handler
, struct tvp5150
, hdl
)->sd
;
48 static int tvp5150_read(struct v4l2_subdev
*sd
, unsigned char addr
)
50 struct i2c_client
*c
= v4l2_get_subdevdata(sd
);
51 unsigned char buffer
[1];
55 if (1 != (rc
= i2c_master_send(c
, buffer
, 1)))
56 v4l2_dbg(0, debug
, sd
, "i2c i/o error: rc == %d (should be 1)\n", rc
);
60 if (1 != (rc
= i2c_master_recv(c
, buffer
, 1)))
61 v4l2_dbg(0, debug
, sd
, "i2c i/o error: rc == %d (should be 1)\n", rc
);
63 v4l2_dbg(2, debug
, sd
, "tvp5150: read 0x%02x = 0x%02x\n", addr
, buffer
[0]);
68 static inline void tvp5150_write(struct v4l2_subdev
*sd
, unsigned char addr
,
71 struct i2c_client
*c
= v4l2_get_subdevdata(sd
);
72 unsigned char buffer
[2];
77 v4l2_dbg(2, debug
, sd
, "tvp5150: writing 0x%02x 0x%02x\n", buffer
[0], buffer
[1]);
78 if (2 != (rc
= i2c_master_send(c
, buffer
, 2)))
79 v4l2_dbg(0, debug
, sd
, "i2c i/o error: rc == %d (should be 2)\n", rc
);
82 static void dump_reg_range(struct v4l2_subdev
*sd
, char *s
, u8 init
,
83 const u8 end
, int max_line
)
87 while (init
!= (u8
)(end
+ 1)) {
88 if ((i
% max_line
) == 0) {
91 printk("tvp5150: %s reg 0x%02x = ", s
, init
);
93 printk("%02x ", tvp5150_read(sd
, init
));
101 static int tvp5150_log_status(struct v4l2_subdev
*sd
)
103 printk("tvp5150: Video input source selection #1 = 0x%02x\n",
104 tvp5150_read(sd
, TVP5150_VD_IN_SRC_SEL_1
));
105 printk("tvp5150: Analog channel controls = 0x%02x\n",
106 tvp5150_read(sd
, TVP5150_ANAL_CHL_CTL
));
107 printk("tvp5150: Operation mode controls = 0x%02x\n",
108 tvp5150_read(sd
, TVP5150_OP_MODE_CTL
));
109 printk("tvp5150: Miscellaneous controls = 0x%02x\n",
110 tvp5150_read(sd
, TVP5150_MISC_CTL
));
111 printk("tvp5150: Autoswitch mask= 0x%02x\n",
112 tvp5150_read(sd
, TVP5150_AUTOSW_MSK
));
113 printk("tvp5150: Color killer threshold control = 0x%02x\n",
114 tvp5150_read(sd
, TVP5150_COLOR_KIL_THSH_CTL
));
115 printk("tvp5150: Luminance processing controls #1 #2 and #3 = %02x %02x %02x\n",
116 tvp5150_read(sd
, TVP5150_LUMA_PROC_CTL_1
),
117 tvp5150_read(sd
, TVP5150_LUMA_PROC_CTL_2
),
118 tvp5150_read(sd
, TVP5150_LUMA_PROC_CTL_3
));
119 printk("tvp5150: Brightness control = 0x%02x\n",
120 tvp5150_read(sd
, TVP5150_BRIGHT_CTL
));
121 printk("tvp5150: Color saturation control = 0x%02x\n",
122 tvp5150_read(sd
, TVP5150_SATURATION_CTL
));
123 printk("tvp5150: Hue control = 0x%02x\n",
124 tvp5150_read(sd
, TVP5150_HUE_CTL
));
125 printk("tvp5150: Contrast control = 0x%02x\n",
126 tvp5150_read(sd
, TVP5150_CONTRAST_CTL
));
127 printk("tvp5150: Outputs and data rates select = 0x%02x\n",
128 tvp5150_read(sd
, TVP5150_DATA_RATE_SEL
));
129 printk("tvp5150: Configuration shared pins = 0x%02x\n",
130 tvp5150_read(sd
, TVP5150_CONF_SHARED_PIN
));
131 printk("tvp5150: Active video cropping start = 0x%02x%02x\n",
132 tvp5150_read(sd
, TVP5150_ACT_VD_CROP_ST_MSB
),
133 tvp5150_read(sd
, TVP5150_ACT_VD_CROP_ST_LSB
));
134 printk("tvp5150: Active video cropping stop = 0x%02x%02x\n",
135 tvp5150_read(sd
, TVP5150_ACT_VD_CROP_STP_MSB
),
136 tvp5150_read(sd
, TVP5150_ACT_VD_CROP_STP_LSB
));
137 printk("tvp5150: Genlock/RTC = 0x%02x\n",
138 tvp5150_read(sd
, TVP5150_GENLOCK
));
139 printk("tvp5150: Horizontal sync start = 0x%02x\n",
140 tvp5150_read(sd
, TVP5150_HORIZ_SYNC_START
));
141 printk("tvp5150: Vertical blanking start = 0x%02x\n",
142 tvp5150_read(sd
, TVP5150_VERT_BLANKING_START
));
143 printk("tvp5150: Vertical blanking stop = 0x%02x\n",
144 tvp5150_read(sd
, TVP5150_VERT_BLANKING_STOP
));
145 printk("tvp5150: Chrominance processing control #1 and #2 = %02x %02x\n",
146 tvp5150_read(sd
, TVP5150_CHROMA_PROC_CTL_1
),
147 tvp5150_read(sd
, TVP5150_CHROMA_PROC_CTL_2
));
148 printk("tvp5150: Interrupt reset register B = 0x%02x\n",
149 tvp5150_read(sd
, TVP5150_INT_RESET_REG_B
));
150 printk("tvp5150: Interrupt enable register B = 0x%02x\n",
151 tvp5150_read(sd
, TVP5150_INT_ENABLE_REG_B
));
152 printk("tvp5150: Interrupt configuration register B = 0x%02x\n",
153 tvp5150_read(sd
, TVP5150_INTT_CONFIG_REG_B
));
154 printk("tvp5150: Video standard = 0x%02x\n",
155 tvp5150_read(sd
, TVP5150_VIDEO_STD
));
156 printk("tvp5150: Chroma gain factor: Cb=0x%02x Cr=0x%02x\n",
157 tvp5150_read(sd
, TVP5150_CB_GAIN_FACT
),
158 tvp5150_read(sd
, TVP5150_CR_GAIN_FACTOR
));
159 printk("tvp5150: Macrovision on counter = 0x%02x\n",
160 tvp5150_read(sd
, TVP5150_MACROVISION_ON_CTR
));
161 printk("tvp5150: Macrovision off counter = 0x%02x\n",
162 tvp5150_read(sd
, TVP5150_MACROVISION_OFF_CTR
));
163 printk("tvp5150: ITU-R BT.656.%d timing(TVP5150AM1 only)\n",
164 (tvp5150_read(sd
, TVP5150_REV_SELECT
) & 1) ? 3 : 4);
165 printk("tvp5150: Device ID = %02x%02x\n",
166 tvp5150_read(sd
, TVP5150_MSB_DEV_ID
),
167 tvp5150_read(sd
, TVP5150_LSB_DEV_ID
));
168 printk("tvp5150: ROM version = (hex) %02x.%02x\n",
169 tvp5150_read(sd
, TVP5150_ROM_MAJOR_VER
),
170 tvp5150_read(sd
, TVP5150_ROM_MINOR_VER
));
171 printk("tvp5150: Vertical line count = 0x%02x%02x\n",
172 tvp5150_read(sd
, TVP5150_VERT_LN_COUNT_MSB
),
173 tvp5150_read(sd
, TVP5150_VERT_LN_COUNT_LSB
));
174 printk("tvp5150: Interrupt status register B = 0x%02x\n",
175 tvp5150_read(sd
, TVP5150_INT_STATUS_REG_B
));
176 printk("tvp5150: Interrupt active register B = 0x%02x\n",
177 tvp5150_read(sd
, TVP5150_INT_ACTIVE_REG_B
));
178 printk("tvp5150: Status regs #1 to #5 = %02x %02x %02x %02x %02x\n",
179 tvp5150_read(sd
, TVP5150_STATUS_REG_1
),
180 tvp5150_read(sd
, TVP5150_STATUS_REG_2
),
181 tvp5150_read(sd
, TVP5150_STATUS_REG_3
),
182 tvp5150_read(sd
, TVP5150_STATUS_REG_4
),
183 tvp5150_read(sd
, TVP5150_STATUS_REG_5
));
185 dump_reg_range(sd
, "Teletext filter 1", TVP5150_TELETEXT_FIL1_INI
,
186 TVP5150_TELETEXT_FIL1_END
, 8);
187 dump_reg_range(sd
, "Teletext filter 2", TVP5150_TELETEXT_FIL2_INI
,
188 TVP5150_TELETEXT_FIL2_END
, 8);
190 printk("tvp5150: Teletext filter enable = 0x%02x\n",
191 tvp5150_read(sd
, TVP5150_TELETEXT_FIL_ENA
));
192 printk("tvp5150: Interrupt status register A = 0x%02x\n",
193 tvp5150_read(sd
, TVP5150_INT_STATUS_REG_A
));
194 printk("tvp5150: Interrupt enable register A = 0x%02x\n",
195 tvp5150_read(sd
, TVP5150_INT_ENABLE_REG_A
));
196 printk("tvp5150: Interrupt configuration = 0x%02x\n",
197 tvp5150_read(sd
, TVP5150_INT_CONF
));
198 printk("tvp5150: VDP status register = 0x%02x\n",
199 tvp5150_read(sd
, TVP5150_VDP_STATUS_REG
));
200 printk("tvp5150: FIFO word count = 0x%02x\n",
201 tvp5150_read(sd
, TVP5150_FIFO_WORD_COUNT
));
202 printk("tvp5150: FIFO interrupt threshold = 0x%02x\n",
203 tvp5150_read(sd
, TVP5150_FIFO_INT_THRESHOLD
));
204 printk("tvp5150: FIFO reset = 0x%02x\n",
205 tvp5150_read(sd
, TVP5150_FIFO_RESET
));
206 printk("tvp5150: Line number interrupt = 0x%02x\n",
207 tvp5150_read(sd
, TVP5150_LINE_NUMBER_INT
));
208 printk("tvp5150: Pixel alignment register = 0x%02x%02x\n",
209 tvp5150_read(sd
, TVP5150_PIX_ALIGN_REG_HIGH
),
210 tvp5150_read(sd
, TVP5150_PIX_ALIGN_REG_LOW
));
211 printk("tvp5150: FIFO output control = 0x%02x\n",
212 tvp5150_read(sd
, TVP5150_FIFO_OUT_CTRL
));
213 printk("tvp5150: Full field enable = 0x%02x\n",
214 tvp5150_read(sd
, TVP5150_FULL_FIELD_ENA
));
215 printk("tvp5150: Full field mode register = 0x%02x\n",
216 tvp5150_read(sd
, TVP5150_FULL_FIELD_MODE_REG
));
218 dump_reg_range(sd
, "CC data", TVP5150_CC_DATA_INI
,
219 TVP5150_CC_DATA_END
, 8);
221 dump_reg_range(sd
, "WSS data", TVP5150_WSS_DATA_INI
,
222 TVP5150_WSS_DATA_END
, 8);
224 dump_reg_range(sd
, "VPS data", TVP5150_VPS_DATA_INI
,
225 TVP5150_VPS_DATA_END
, 8);
227 dump_reg_range(sd
, "VITC data", TVP5150_VITC_DATA_INI
,
228 TVP5150_VITC_DATA_END
, 10);
230 dump_reg_range(sd
, "Line mode", TVP5150_LINE_MODE_INI
,
231 TVP5150_LINE_MODE_END
, 8);
235 /****************************************************************************
237 ****************************************************************************/
239 static inline void tvp5150_selmux(struct v4l2_subdev
*sd
)
242 struct tvp5150
*decoder
= to_tvp5150(sd
);
246 if ((decoder
->output
& TVP5150_BLACK_SCREEN
) || !decoder
->enable
)
249 switch (decoder
->input
) {
250 case TVP5150_COMPOSITE1
:
253 case TVP5150_COMPOSITE0
:
261 v4l2_dbg(1, debug
, sd
, "Selecting video route: route input=%i, output=%i "
262 "=> tvp5150 input=%i, opmode=%i\n",
263 decoder
->input
, decoder
->output
,
266 tvp5150_write(sd
, TVP5150_OP_MODE_CTL
, opmode
);
267 tvp5150_write(sd
, TVP5150_VD_IN_SRC_SEL_1
, input
);
269 /* Svideo should enable YCrCb output and disable GPCL output
270 * For Composite and TV, it should be the reverse
272 val
= tvp5150_read(sd
, TVP5150_MISC_CTL
);
273 if (decoder
->input
== TVP5150_SVIDEO
)
274 val
= (val
& ~0x40) | 0x10;
276 val
= (val
& ~0x10) | 0x40;
277 tvp5150_write(sd
, TVP5150_MISC_CTL
, val
);
280 struct i2c_reg_value
{
285 /* Default values as sugested at TVP5150AM1 datasheet */
286 static const struct i2c_reg_value tvp5150_init_default
[] = {
288 TVP5150_VD_IN_SRC_SEL_1
,0x00
291 TVP5150_ANAL_CHL_CTL
,0x15
294 TVP5150_OP_MODE_CTL
,0x00
297 TVP5150_MISC_CTL
,0x01
300 TVP5150_COLOR_KIL_THSH_CTL
,0x10
303 TVP5150_LUMA_PROC_CTL_1
,0x60
306 TVP5150_LUMA_PROC_CTL_2
,0x00
309 TVP5150_BRIGHT_CTL
,0x80
312 TVP5150_SATURATION_CTL
,0x80
318 TVP5150_CONTRAST_CTL
,0x80
321 TVP5150_DATA_RATE_SEL
,0x47
324 TVP5150_LUMA_PROC_CTL_3
,0x00
327 TVP5150_CONF_SHARED_PIN
,0x08
330 TVP5150_ACT_VD_CROP_ST_MSB
,0x00
333 TVP5150_ACT_VD_CROP_ST_LSB
,0x00
336 TVP5150_ACT_VD_CROP_STP_MSB
,0x00
339 TVP5150_ACT_VD_CROP_STP_LSB
,0x00
345 TVP5150_HORIZ_SYNC_START
,0x80
348 TVP5150_VERT_BLANKING_START
,0x00
351 TVP5150_VERT_BLANKING_STOP
,0x00
354 TVP5150_CHROMA_PROC_CTL_1
,0x0c
357 TVP5150_CHROMA_PROC_CTL_2
,0x14
360 TVP5150_INT_RESET_REG_B
,0x00
363 TVP5150_INT_ENABLE_REG_B
,0x00
366 TVP5150_INTT_CONFIG_REG_B
,0x00
369 TVP5150_VIDEO_STD
,0x00
372 TVP5150_MACROVISION_ON_CTR
,0x0f
375 TVP5150_MACROVISION_OFF_CTR
,0x01
378 TVP5150_TELETEXT_FIL_ENA
,0x00
381 TVP5150_INT_STATUS_REG_A
,0x00
384 TVP5150_INT_ENABLE_REG_A
,0x00
387 TVP5150_INT_CONF
,0x04
390 TVP5150_FIFO_INT_THRESHOLD
,0x80
393 TVP5150_FIFO_RESET
,0x00
396 TVP5150_LINE_NUMBER_INT
,0x00
399 TVP5150_PIX_ALIGN_REG_LOW
,0x4e
402 TVP5150_PIX_ALIGN_REG_HIGH
,0x00
405 TVP5150_FIFO_OUT_CTRL
,0x01
408 TVP5150_FULL_FIELD_ENA
,0x00
411 TVP5150_LINE_MODE_INI
,0x00
414 TVP5150_FULL_FIELD_MODE_REG
,0x7f
421 /* Default values as sugested at TVP5150AM1 datasheet */
422 static const struct i2c_reg_value tvp5150_init_enable
[] = {
424 TVP5150_CONF_SHARED_PIN
, 2
425 },{ /* Automatic offset and AGC enabled */
426 TVP5150_ANAL_CHL_CTL
, 0x15
427 },{ /* Activate YCrCb output 0x9 or 0xd ? */
428 TVP5150_MISC_CTL
, 0x6f
429 },{ /* Activates video std autodetection for all standards */
430 TVP5150_AUTOSW_MSK
, 0x0
431 },{ /* Default format: 0x47. For 4:2:2: 0x40 */
432 TVP5150_DATA_RATE_SEL
, 0x47
434 TVP5150_CHROMA_PROC_CTL_1
, 0x0c
436 TVP5150_CHROMA_PROC_CTL_2
, 0x54
437 },{ /* Non documented, but initialized on WinTV USB2 */
444 struct tvp5150_vbi_type
{
445 unsigned int vbi_type
;
446 unsigned int ini_line
;
447 unsigned int end_line
;
448 unsigned int by_field
:1;
451 struct i2c_vbi_ram_value
{
453 struct tvp5150_vbi_type type
;
454 unsigned char values
[16];
457 /* This struct have the values for each supported VBI Standard
459 tvp5150_vbi_types should follow the same order as vbi_ram_default
460 * value 0 means rom position 0x10, value 1 means rom position 0x30
461 * and so on. There are 16 possible locations from 0 to 15.
464 static struct i2c_vbi_ram_value vbi_ram_default
[] =
466 /* FIXME: Current api doesn't handle all VBI types, those not
467 yet supported are placed under #if 0 */
469 {0x010, /* Teletext, SECAM, WST System A */
470 {V4L2_SLICED_TELETEXT_SECAM
,6,23,1},
471 { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x26,
472 0xe6, 0xb4, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00 }
475 {0x030, /* Teletext, PAL, WST System B */
476 {V4L2_SLICED_TELETEXT_B
,6,22,1},
477 { 0xaa, 0xaa, 0xff, 0xff, 0x27, 0x2e, 0x20, 0x2b,
478 0xa6, 0x72, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00 }
481 {0x050, /* Teletext, PAL, WST System C */
482 {V4L2_SLICED_TELETEXT_PAL_C
,6,22,1},
483 { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x22,
484 0xa6, 0x98, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 }
486 {0x070, /* Teletext, NTSC, WST System B */
487 {V4L2_SLICED_TELETEXT_NTSC_B
,10,21,1},
488 { 0xaa, 0xaa, 0xff, 0xff, 0x27, 0x2e, 0x20, 0x23,
489 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 }
491 {0x090, /* Tetetext, NTSC NABTS System C */
492 {V4L2_SLICED_TELETEXT_NTSC_C
,10,21,1},
493 { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x22,
494 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x15, 0x00 }
496 {0x0b0, /* Teletext, NTSC-J, NABTS System D */
497 {V4L2_SLICED_TELETEXT_NTSC_D
,10,21,1},
498 { 0xaa, 0xaa, 0xff, 0xff, 0xa7, 0x2e, 0x20, 0x23,
499 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 }
501 {0x0d0, /* Closed Caption, PAL/SECAM */
502 {V4L2_SLICED_CAPTION_625
,22,22,1},
503 { 0xaa, 0x2a, 0xff, 0x3f, 0x04, 0x51, 0x6e, 0x02,
504 0xa6, 0x7b, 0x09, 0x00, 0x00, 0x00, 0x27, 0x00 }
507 {0x0f0, /* Closed Caption, NTSC */
508 {V4L2_SLICED_CAPTION_525
,21,21,1},
509 { 0xaa, 0x2a, 0xff, 0x3f, 0x04, 0x51, 0x6e, 0x02,
510 0x69, 0x8c, 0x09, 0x00, 0x00, 0x00, 0x27, 0x00 }
512 {0x110, /* Wide Screen Signal, PAL/SECAM */
513 {V4L2_SLICED_WSS_625
,23,23,1},
514 { 0x5b, 0x55, 0xc5, 0xff, 0x00, 0x71, 0x6e, 0x42,
515 0xa6, 0xcd, 0x0f, 0x00, 0x00, 0x00, 0x3a, 0x00 }
518 {0x130, /* Wide Screen Signal, NTSC C */
519 {V4L2_SLICED_WSS_525
,20,20,1},
520 { 0x38, 0x00, 0x3f, 0x00, 0x00, 0x71, 0x6e, 0x43,
521 0x69, 0x7c, 0x08, 0x00, 0x00, 0x00, 0x39, 0x00 }
523 {0x150, /* Vertical Interval Timecode (VITC), PAL/SECAM */
524 {V4l2_SLICED_VITC_625
,6,22,0},
525 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x6d, 0x49,
526 0xa6, 0x85, 0x08, 0x00, 0x00, 0x00, 0x4c, 0x00 }
528 {0x170, /* Vertical Interval Timecode (VITC), NTSC */
529 {V4l2_SLICED_VITC_525
,10,20,0},
530 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x6d, 0x49,
531 0x69, 0x94, 0x08, 0x00, 0x00, 0x00, 0x4c, 0x00 }
534 {0x190, /* Video Program System (VPS), PAL */
535 {V4L2_SLICED_VPS
,16,16,0},
536 { 0xaa, 0xaa, 0xff, 0xff, 0xba, 0xce, 0x2b, 0x0d,
537 0xa6, 0xda, 0x0b, 0x00, 0x00, 0x00, 0x60, 0x00 }
539 /* 0x1d0 User programmable */
545 static int tvp5150_write_inittab(struct v4l2_subdev
*sd
,
546 const struct i2c_reg_value
*regs
)
548 while (regs
->reg
!= 0xff) {
549 tvp5150_write(sd
, regs
->reg
, regs
->value
);
555 static int tvp5150_vdp_init(struct v4l2_subdev
*sd
,
556 const struct i2c_vbi_ram_value
*regs
)
560 /* Disable Full Field */
561 tvp5150_write(sd
, TVP5150_FULL_FIELD_ENA
, 0);
563 /* Before programming, Line mode should be at 0xff */
564 for (i
= TVP5150_LINE_MODE_INI
; i
<= TVP5150_LINE_MODE_END
; i
++)
565 tvp5150_write(sd
, i
, 0xff);
568 while (regs
->reg
!= (u16
)-1) {
569 tvp5150_write(sd
, TVP5150_CONF_RAM_ADDR_HIGH
, regs
->reg
>> 8);
570 tvp5150_write(sd
, TVP5150_CONF_RAM_ADDR_LOW
, regs
->reg
);
572 for (i
= 0; i
< 16; i
++)
573 tvp5150_write(sd
, TVP5150_VDP_CONF_RAM_DATA
, regs
->values
[i
]);
580 /* Fills VBI capabilities based on i2c_vbi_ram_value struct */
581 static int tvp5150_g_sliced_vbi_cap(struct v4l2_subdev
*sd
,
582 struct v4l2_sliced_vbi_cap
*cap
)
584 const struct i2c_vbi_ram_value
*regs
= vbi_ram_default
;
587 v4l2_dbg(1, debug
, sd
, "g_sliced_vbi_cap\n");
588 memset(cap
, 0, sizeof *cap
);
590 while (regs
->reg
!= (u16
)-1 ) {
591 for (line
=regs
->type
.ini_line
;line
<=regs
->type
.end_line
;line
++) {
592 cap
->service_lines
[0][line
] |= regs
->type
.vbi_type
;
594 cap
->service_set
|= regs
->type
.vbi_type
;
601 /* Set vbi processing
602 * type - one of tvp5150_vbi_types
603 * line - line to gather data
604 * fields: bit 0 field1, bit 1, field2
605 * flags (default=0xf0) is a bitmask, were set means:
606 * bit 7: enable filtering null bytes on CC
607 * bit 6: send data also to FIFO
608 * bit 5: don't allow data with errors on FIFO
609 * bit 4: enable ECC when possible
610 * pix_align = pix alignment:
614 static int tvp5150_set_vbi(struct v4l2_subdev
*sd
,
615 const struct i2c_vbi_ram_value
*regs
,
616 unsigned int type
,u8 flags
, int line
,
619 struct tvp5150
*decoder
= to_tvp5150(sd
);
620 v4l2_std_id std
= decoder
->norm
;
624 if (std
== V4L2_STD_ALL
) {
625 v4l2_err(sd
, "VBI can't be configured without knowing number of lines\n");
627 } else if (std
& V4L2_STD_625_50
) {
628 /* Don't follow NTSC Line number convension */
635 while (regs
->reg
!= (u16
)-1 ) {
636 if ((type
& regs
->type
.vbi_type
) &&
637 (line
>=regs
->type
.ini_line
) &&
638 (line
<=regs
->type
.end_line
)) {
639 type
=regs
->type
.vbi_type
;
646 if (regs
->reg
== (u16
)-1)
649 type
=pos
| (flags
& 0xf0);
650 reg
=((line
-6)<<1)+TVP5150_LINE_MODE_INI
;
653 tvp5150_write(sd
, reg
, type
);
657 tvp5150_write(sd
, reg
+1, type
);
663 static int tvp5150_get_vbi(struct v4l2_subdev
*sd
,
664 const struct i2c_vbi_ram_value
*regs
, 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 */
679 if (line
< 6 || line
> 27)
682 reg
= ((line
- 6) << 1) + TVP5150_LINE_MODE_INI
;
684 pos
= tvp5150_read(sd
, reg
) & 0x0f;
686 type
= regs
[pos
].type
.vbi_type
;
688 pos
= tvp5150_read(sd
, reg
+ 1) & 0x0f;
690 type
|= regs
[pos
].type
.vbi_type
;
695 static int tvp5150_set_std(struct v4l2_subdev
*sd
, v4l2_std_id std
)
697 struct tvp5150
*decoder
= to_tvp5150(sd
);
702 /* First tests should be against specific std */
704 if (std
== V4L2_STD_ALL
) {
705 fmt
= 0; /* Autodetect mode */
706 } else if (std
& V4L2_STD_NTSC_443
) {
708 } else if (std
& V4L2_STD_PAL_M
) {
710 } else if (std
& (V4L2_STD_PAL_N
| V4L2_STD_PAL_Nc
)) {
713 /* Then, test against generic ones */
714 if (std
& V4L2_STD_NTSC
)
716 else if (std
& V4L2_STD_PAL
)
718 else if (std
& V4L2_STD_SECAM
)
722 v4l2_dbg(1, debug
, sd
, "Set video std register to %d.\n", fmt
);
723 tvp5150_write(sd
, TVP5150_VIDEO_STD
, fmt
);
727 static int tvp5150_s_std(struct v4l2_subdev
*sd
, v4l2_std_id std
)
729 struct tvp5150
*decoder
= to_tvp5150(sd
);
731 if (decoder
->norm
== std
)
734 return tvp5150_set_std(sd
, std
);
737 static int tvp5150_reset(struct v4l2_subdev
*sd
, u32 val
)
739 struct tvp5150
*decoder
= to_tvp5150(sd
);
741 /* Initializes TVP5150 to its default values */
742 tvp5150_write_inittab(sd
, tvp5150_init_default
);
744 /* Initializes VDP registers */
745 tvp5150_vdp_init(sd
, vbi_ram_default
);
747 /* Selects decoder input */
750 /* Initializes TVP5150 to stream enabled values */
751 tvp5150_write_inittab(sd
, tvp5150_init_enable
);
753 /* Initialize image preferences */
754 v4l2_ctrl_handler_setup(&decoder
->hdl
);
756 tvp5150_set_std(sd
, decoder
->norm
);
760 static int tvp5150_s_ctrl(struct v4l2_ctrl
*ctrl
)
762 struct v4l2_subdev
*sd
= to_sd(ctrl
);
765 case V4L2_CID_BRIGHTNESS
:
766 tvp5150_write(sd
, TVP5150_BRIGHT_CTL
, ctrl
->val
);
768 case V4L2_CID_CONTRAST
:
769 tvp5150_write(sd
, TVP5150_CONTRAST_CTL
, ctrl
->val
);
771 case V4L2_CID_SATURATION
:
772 tvp5150_write(sd
, TVP5150_SATURATION_CTL
, ctrl
->val
);
775 tvp5150_write(sd
, TVP5150_HUE_CTL
, ctrl
->val
);
781 /****************************************************************************
783 ****************************************************************************/
785 static int tvp5150_s_routing(struct v4l2_subdev
*sd
,
786 u32 input
, u32 output
, u32 config
)
788 struct tvp5150
*decoder
= to_tvp5150(sd
);
790 decoder
->input
= input
;
791 decoder
->output
= output
;
796 static int tvp5150_s_raw_fmt(struct v4l2_subdev
*sd
, struct v4l2_vbi_format
*fmt
)
798 /* this is for capturing 36 raw vbi lines
799 if there's a way to cut off the beginning 2 vbi lines
800 with the tvp5150 then the vbi line count could be lowered
801 to 17 lines/field again, although I couldn't find a register
802 which could do that cropping */
803 if (fmt
->sample_format
== V4L2_PIX_FMT_GREY
)
804 tvp5150_write(sd
, TVP5150_LUMA_PROC_CTL_1
, 0x70);
805 if (fmt
->count
[0] == 18 && fmt
->count
[1] == 18) {
806 tvp5150_write(sd
, TVP5150_VERT_BLANKING_START
, 0x00);
807 tvp5150_write(sd
, TVP5150_VERT_BLANKING_STOP
, 0x01);
812 static int tvp5150_s_sliced_fmt(struct v4l2_subdev
*sd
, struct v4l2_sliced_vbi_format
*svbi
)
816 if (svbi
->service_set
!= 0) {
817 for (i
= 0; i
<= 23; i
++) {
818 svbi
->service_lines
[1][i
] = 0;
819 svbi
->service_lines
[0][i
] =
820 tvp5150_set_vbi(sd
, vbi_ram_default
,
821 svbi
->service_lines
[0][i
], 0xf0, i
, 3);
824 tvp5150_write(sd
, TVP5150_FIFO_OUT_CTRL
, 1);
827 tvp5150_write(sd
, TVP5150_FIFO_OUT_CTRL
, 0);
829 /* Disable Full Field */
830 tvp5150_write(sd
, TVP5150_FULL_FIELD_ENA
, 0);
832 /* Disable Line modes */
833 for (i
= TVP5150_LINE_MODE_INI
; i
<= TVP5150_LINE_MODE_END
; i
++)
834 tvp5150_write(sd
, i
, 0xff);
839 static int tvp5150_g_sliced_fmt(struct v4l2_subdev
*sd
, struct v4l2_sliced_vbi_format
*svbi
)
843 memset(svbi
, 0, sizeof(*svbi
));
845 for (i
= 0; i
<= 23; i
++) {
846 svbi
->service_lines
[0][i
] =
847 tvp5150_get_vbi(sd
, vbi_ram_default
, i
);
848 mask
|= svbi
->service_lines
[0][i
];
850 svbi
->service_set
= mask
;
854 static int tvp5150_g_chip_ident(struct v4l2_subdev
*sd
,
855 struct v4l2_dbg_chip_ident
*chip
)
858 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
860 rev
= tvp5150_read(sd
, TVP5150_ROM_MAJOR_VER
) << 8 |
861 tvp5150_read(sd
, TVP5150_ROM_MINOR_VER
);
863 return v4l2_chip_ident_i2c_client(client
, chip
, V4L2_IDENT_TVP5150
,
868 #ifdef CONFIG_VIDEO_ADV_DEBUG
869 static int tvp5150_g_register(struct v4l2_subdev
*sd
, struct v4l2_dbg_register
*reg
)
871 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
873 if (!v4l2_chip_match_i2c_client(client
, ®
->match
))
875 if (!capable(CAP_SYS_ADMIN
))
877 reg
->val
= tvp5150_read(sd
, reg
->reg
& 0xff);
882 static int tvp5150_s_register(struct v4l2_subdev
*sd
, struct v4l2_dbg_register
*reg
)
884 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
886 if (!v4l2_chip_match_i2c_client(client
, ®
->match
))
888 if (!capable(CAP_SYS_ADMIN
))
890 tvp5150_write(sd
, reg
->reg
& 0xff, reg
->val
& 0xff);
895 static int tvp5150_g_tuner(struct v4l2_subdev
*sd
, struct v4l2_tuner
*vt
)
897 int status
= tvp5150_read(sd
, 0x88);
899 vt
->signal
= ((status
& 0x04) && (status
& 0x02)) ? 0xffff : 0x0;
903 /* ----------------------------------------------------------------------- */
905 static const struct v4l2_ctrl_ops tvp5150_ctrl_ops
= {
906 .s_ctrl
= tvp5150_s_ctrl
,
909 static const struct v4l2_subdev_core_ops tvp5150_core_ops
= {
910 .log_status
= tvp5150_log_status
,
911 .g_ext_ctrls
= v4l2_subdev_g_ext_ctrls
,
912 .try_ext_ctrls
= v4l2_subdev_try_ext_ctrls
,
913 .s_ext_ctrls
= v4l2_subdev_s_ext_ctrls
,
914 .g_ctrl
= v4l2_subdev_g_ctrl
,
915 .s_ctrl
= v4l2_subdev_s_ctrl
,
916 .queryctrl
= v4l2_subdev_queryctrl
,
917 .querymenu
= v4l2_subdev_querymenu
,
918 .s_std
= tvp5150_s_std
,
919 .reset
= tvp5150_reset
,
920 .g_chip_ident
= tvp5150_g_chip_ident
,
921 #ifdef CONFIG_VIDEO_ADV_DEBUG
922 .g_register
= tvp5150_g_register
,
923 .s_register
= tvp5150_s_register
,
927 static const struct v4l2_subdev_tuner_ops tvp5150_tuner_ops
= {
928 .g_tuner
= tvp5150_g_tuner
,
931 static const struct v4l2_subdev_video_ops tvp5150_video_ops
= {
932 .s_routing
= tvp5150_s_routing
,
935 static const struct v4l2_subdev_vbi_ops tvp5150_vbi_ops
= {
936 .g_sliced_vbi_cap
= tvp5150_g_sliced_vbi_cap
,
937 .g_sliced_fmt
= tvp5150_g_sliced_fmt
,
938 .s_sliced_fmt
= tvp5150_s_sliced_fmt
,
939 .s_raw_fmt
= tvp5150_s_raw_fmt
,
942 static const struct v4l2_subdev_ops tvp5150_ops
= {
943 .core
= &tvp5150_core_ops
,
944 .tuner
= &tvp5150_tuner_ops
,
945 .video
= &tvp5150_video_ops
,
946 .vbi
= &tvp5150_vbi_ops
,
950 /****************************************************************************
952 ****************************************************************************/
954 static int tvp5150_probe(struct i2c_client
*c
,
955 const struct i2c_device_id
*id
)
957 struct tvp5150
*core
;
958 struct v4l2_subdev
*sd
;
959 u8 msb_id
, lsb_id
, msb_rom
, lsb_rom
;
961 /* Check if the adapter supports the needed features */
962 if (!i2c_check_functionality(c
->adapter
,
963 I2C_FUNC_SMBUS_READ_BYTE
| I2C_FUNC_SMBUS_WRITE_BYTE_DATA
))
966 core
= kzalloc(sizeof(struct tvp5150
), GFP_KERNEL
);
971 v4l2_i2c_subdev_init(sd
, c
, &tvp5150_ops
);
972 v4l_info(c
, "chip found @ 0x%02x (%s)\n",
973 c
->addr
<< 1, c
->adapter
->name
);
975 msb_id
= tvp5150_read(sd
, TVP5150_MSB_DEV_ID
);
976 lsb_id
= tvp5150_read(sd
, TVP5150_LSB_DEV_ID
);
977 msb_rom
= tvp5150_read(sd
, TVP5150_ROM_MAJOR_VER
);
978 lsb_rom
= tvp5150_read(sd
, TVP5150_ROM_MINOR_VER
);
980 if (msb_rom
== 4 && lsb_rom
== 0) { /* Is TVP5150AM1 */
981 v4l2_info(sd
, "tvp%02x%02xam1 detected.\n", msb_id
, lsb_id
);
983 /* ITU-T BT.656.4 timing */
984 tvp5150_write(sd
, TVP5150_REV_SELECT
, 0);
986 if (msb_rom
== 3 || lsb_rom
== 0x21) { /* Is TVP5150A */
987 v4l2_info(sd
, "tvp%02x%02xa detected.\n", msb_id
, lsb_id
);
989 v4l2_info(sd
, "*** unknown tvp%02x%02x chip detected.\n",
991 v4l2_info(sd
, "*** Rom ver is %d.%d\n", msb_rom
, lsb_rom
);
995 core
->norm
= V4L2_STD_ALL
; /* Default is autodetect */
996 core
->input
= TVP5150_COMPOSITE1
;
999 v4l2_ctrl_handler_init(&core
->hdl
, 4);
1000 v4l2_ctrl_new_std(&core
->hdl
, &tvp5150_ctrl_ops
,
1001 V4L2_CID_BRIGHTNESS
, 0, 255, 1, 128);
1002 v4l2_ctrl_new_std(&core
->hdl
, &tvp5150_ctrl_ops
,
1003 V4L2_CID_CONTRAST
, 0, 255, 1, 128);
1004 v4l2_ctrl_new_std(&core
->hdl
, &tvp5150_ctrl_ops
,
1005 V4L2_CID_SATURATION
, 0, 255, 1, 128);
1006 v4l2_ctrl_new_std(&core
->hdl
, &tvp5150_ctrl_ops
,
1007 V4L2_CID_HUE
, -128, 127, 1, 0);
1008 sd
->ctrl_handler
= &core
->hdl
;
1009 if (core
->hdl
.error
) {
1010 int err
= core
->hdl
.error
;
1012 v4l2_ctrl_handler_free(&core
->hdl
);
1016 v4l2_ctrl_handler_setup(&core
->hdl
);
1019 tvp5150_log_status(sd
);
1023 static int tvp5150_remove(struct i2c_client
*c
)
1025 struct v4l2_subdev
*sd
= i2c_get_clientdata(c
);
1026 struct tvp5150
*decoder
= to_tvp5150(sd
);
1028 v4l2_dbg(1, debug
, sd
,
1029 "tvp5150.c: removing tvp5150 adapter on address 0x%x\n",
1032 v4l2_device_unregister_subdev(sd
);
1033 v4l2_ctrl_handler_free(&decoder
->hdl
);
1034 kfree(to_tvp5150(sd
));
1038 /* ----------------------------------------------------------------------- */
1040 static const struct i2c_device_id tvp5150_id
[] = {
1044 MODULE_DEVICE_TABLE(i2c
, tvp5150_id
);
1046 static struct i2c_driver tvp5150_driver
= {
1048 .owner
= THIS_MODULE
,
1051 .probe
= tvp5150_probe
,
1052 .remove
= tvp5150_remove
,
1053 .id_table
= tvp5150_id
,
1056 static __init
int init_tvp5150(void)
1058 return i2c_add_driver(&tvp5150_driver
);
1061 static __exit
void exit_tvp5150(void)
1063 i2c_del_driver(&tvp5150_driver
);
1066 module_init(init_tvp5150
);
1067 module_exit(exit_tvp5150
);