2 * tvp5150 - Texas Instruments TVP5150A(M) video decoder driver
4 * Copyright (c) 2005 Mauro Carvalho Chehab (mchehab@brturbo.com.br)
5 * This code is placed under the terms of the GNU General Public License
9 #include <linux/videodev.h>
10 #include <linux/delay.h>
11 #include <linux/video_decoder.h>
12 #include <media/v4l2-common.h>
14 #include "tvp5150_reg.h"
16 MODULE_DESCRIPTION("Texas Instruments TVP5150A video decoder driver"); /* standard i2c insmod options */
17 MODULE_AUTHOR("Mauro Carvalho Chehab");
18 MODULE_LICENSE("GPL");
20 static unsigned short normal_i2c[] = {
29 module_param(debug, int, 0);
30 MODULE_PARM_DESC(debug, "Debug level (0-1)");
32 #define tvp5150_err(fmt, arg...) do { \
33 printk(KERN_ERR "%s %d-%04x: " fmt, c->driver->driver.name, \
34 i2c_adapter_id(c->adapter), c->addr , ## arg); } while (0)
35 #define tvp5150_info(fmt, arg...) do { \
36 printk(KERN_INFO "%s %d-%04x: " fmt, c->driver->driver.name, \
37 i2c_adapter_id(c->adapter), c->addr , ## arg); } while (0)
38 #define tvp5150_dbg(num, fmt, arg...) \
41 printk(KERN_DEBUG "%s debug %d-%04x: " fmt,\
42 c->driver->driver.name, \
43 i2c_adapter_id(c->adapter), \
44 c->addr , ## arg); } while (0)
46 /* supported controls */
47 static struct v4l2_queryctrl tvp5150_qctrl[] = {
49 .id = V4L2_CID_BRIGHTNESS,
50 .type = V4L2_CTRL_TYPE_INTEGER,
58 .id = V4L2_CID_CONTRAST,
59 .type = V4L2_CTRL_TYPE_INTEGER,
64 .default_value = 0x10,
67 .id = V4L2_CID_SATURATION,
68 .type = V4L2_CTRL_TYPE_INTEGER,
73 .default_value = 0x10,
77 .type = V4L2_CTRL_TYPE_INTEGER,
82 .default_value = 0x10,
88 struct i2c_client *client;
90 v4l2_std_id norm; /* Current set standard */
99 static int tvp5150_read(struct i2c_client *c, unsigned char addr)
101 unsigned char buffer[1];
105 if (1 != (rc = i2c_master_send(c, buffer, 1)))
106 tvp5150_dbg(0, "i2c i/o error: rc == %d (should be 1)\n", rc);
110 if (1 != (rc = i2c_master_recv(c, buffer, 1)))
111 tvp5150_dbg(0, "i2c i/o error: rc == %d (should be 1)\n", rc);
113 tvp5150_dbg(2, "tvp5150: read 0x%02x = 0x%02x\n", addr, buffer[0]);
118 static inline void tvp5150_write(struct i2c_client *c, unsigned char addr,
121 unsigned char buffer[2];
126 tvp5150_dbg(2, "tvp5150: writing 0x%02x 0x%02x\n", buffer[0], buffer[1]);
127 if (2 != (rc = i2c_master_send(c, buffer, 2)))
128 tvp5150_dbg(0, "i2c i/o error: rc == %d (should be 2)\n", rc);
131 static void dump_reg_range(struct i2c_client *c, char *s, u8 init, const u8 end,int max_line)
135 while (init!=(u8)(end+1)) {
136 if ((i%max_line) == 0) {
139 printk("tvp5150: %s reg 0x%02x = ",s,init);
141 printk("%02x ",tvp5150_read(c, init));
149 static void dump_reg(struct i2c_client *c)
151 printk("tvp5150: Video input source selection #1 = 0x%02x\n",
152 tvp5150_read(c, TVP5150_VD_IN_SRC_SEL_1));
153 printk("tvp5150: Analog channel controls = 0x%02x\n",
154 tvp5150_read(c, TVP5150_ANAL_CHL_CTL));
155 printk("tvp5150: Operation mode controls = 0x%02x\n",
156 tvp5150_read(c, TVP5150_OP_MODE_CTL));
157 printk("tvp5150: Miscellaneous controls = 0x%02x\n",
158 tvp5150_read(c, TVP5150_MISC_CTL));
159 printk("tvp5150: Autoswitch mask= 0x%02x\n",
160 tvp5150_read(c, TVP5150_AUTOSW_MSK));
161 printk("tvp5150: Color killer threshold control = 0x%02x\n",
162 tvp5150_read(c, TVP5150_COLOR_KIL_THSH_CTL));
163 printk("tvp5150: Luminance processing controls #1 #2 and #3 = %02x %02x %02x\n",
164 tvp5150_read(c, TVP5150_LUMA_PROC_CTL_1),
165 tvp5150_read(c, TVP5150_LUMA_PROC_CTL_2),
166 tvp5150_read(c, TVP5150_LUMA_PROC_CTL_3));
167 printk("tvp5150: Brightness control = 0x%02x\n",
168 tvp5150_read(c, TVP5150_BRIGHT_CTL));
169 printk("tvp5150: Color saturation control = 0x%02x\n",
170 tvp5150_read(c, TVP5150_SATURATION_CTL));
171 printk("tvp5150: Hue control = 0x%02x\n",
172 tvp5150_read(c, TVP5150_HUE_CTL));
173 printk("tvp5150: Contrast control = 0x%02x\n",
174 tvp5150_read(c, TVP5150_CONTRAST_CTL));
175 printk("tvp5150: Outputs and data rates select = 0x%02x\n",
176 tvp5150_read(c, TVP5150_DATA_RATE_SEL));
177 printk("tvp5150: Configuration shared pins = 0x%02x\n",
178 tvp5150_read(c, TVP5150_CONF_SHARED_PIN));
179 printk("tvp5150: Active video cropping start = 0x%02x%02x\n",
180 tvp5150_read(c, TVP5150_ACT_VD_CROP_ST_MSB),
181 tvp5150_read(c, TVP5150_ACT_VD_CROP_ST_LSB));
182 printk("tvp5150: Active video cropping stop = 0x%02x%02x\n",
183 tvp5150_read(c, TVP5150_ACT_VD_CROP_STP_MSB),
184 tvp5150_read(c, TVP5150_ACT_VD_CROP_STP_LSB));
185 printk("tvp5150: Genlock/RTC = 0x%02x\n",
186 tvp5150_read(c, TVP5150_GENLOCK));
187 printk("tvp5150: Horizontal sync start = 0x%02x\n",
188 tvp5150_read(c, TVP5150_HORIZ_SYNC_START));
189 printk("tvp5150: Vertical blanking start = 0x%02x\n",
190 tvp5150_read(c, TVP5150_VERT_BLANKING_START));
191 printk("tvp5150: Vertical blanking stop = 0x%02x\n",
192 tvp5150_read(c, TVP5150_VERT_BLANKING_STOP));
193 printk("tvp5150: Chrominance processing control #1 and #2 = %02x %02x\n",
194 tvp5150_read(c, TVP5150_CHROMA_PROC_CTL_1),
195 tvp5150_read(c, TVP5150_CHROMA_PROC_CTL_2));
196 printk("tvp5150: Interrupt reset register B = 0x%02x\n",
197 tvp5150_read(c, TVP5150_INT_RESET_REG_B));
198 printk("tvp5150: Interrupt enable register B = 0x%02x\n",
199 tvp5150_read(c, TVP5150_INT_ENABLE_REG_B));
200 printk("tvp5150: Interrupt configuration register B = 0x%02x\n",
201 tvp5150_read(c, TVP5150_INTT_CONFIG_REG_B));
202 printk("tvp5150: Video standard = 0x%02x\n",
203 tvp5150_read(c, TVP5150_VIDEO_STD));
204 printk("tvp5150: Chroma gain factor: Cb=0x%02x Cr=0x%02x\n",
205 tvp5150_read(c, TVP5150_CB_GAIN_FACT),
206 tvp5150_read(c, TVP5150_CR_GAIN_FACTOR));
207 printk("tvp5150: Macrovision on counter = 0x%02x\n",
208 tvp5150_read(c, TVP5150_MACROVISION_ON_CTR));
209 printk("tvp5150: Macrovision off counter = 0x%02x\n",
210 tvp5150_read(c, TVP5150_MACROVISION_OFF_CTR));
211 printk("tvp5150: ITU-R BT.656.%d timing(TVP5150AM1 only)\n",
212 (tvp5150_read(c, TVP5150_REV_SELECT)&1)?3:4);
213 printk("tvp5150: Device ID = %02x%02x\n",
214 tvp5150_read(c, TVP5150_MSB_DEV_ID),
215 tvp5150_read(c, TVP5150_LSB_DEV_ID));
216 printk("tvp5150: ROM version = (hex) %02x.%02x\n",
217 tvp5150_read(c, TVP5150_ROM_MAJOR_VER),
218 tvp5150_read(c, TVP5150_ROM_MINOR_VER));
219 printk("tvp5150: Vertical line count = 0x%02x%02x\n",
220 tvp5150_read(c, TVP5150_VERT_LN_COUNT_MSB),
221 tvp5150_read(c, TVP5150_VERT_LN_COUNT_LSB));
222 printk("tvp5150: Interrupt status register B = 0x%02x\n",
223 tvp5150_read(c, TVP5150_INT_STATUS_REG_B));
224 printk("tvp5150: Interrupt active register B = 0x%02x\n",
225 tvp5150_read(c, TVP5150_INT_ACTIVE_REG_B));
226 printk("tvp5150: Status regs #1 to #5 = %02x %02x %02x %02x %02x\n",
227 tvp5150_read(c, TVP5150_STATUS_REG_1),
228 tvp5150_read(c, TVP5150_STATUS_REG_2),
229 tvp5150_read(c, TVP5150_STATUS_REG_3),
230 tvp5150_read(c, TVP5150_STATUS_REG_4),
231 tvp5150_read(c, TVP5150_STATUS_REG_5));
233 dump_reg_range(c,"Teletext filter 1", TVP5150_TELETEXT_FIL1_INI,
234 TVP5150_TELETEXT_FIL1_END,8);
235 dump_reg_range(c,"Teletext filter 2", TVP5150_TELETEXT_FIL2_INI,
236 TVP5150_TELETEXT_FIL2_END,8);
238 printk("tvp5150: Teletext filter enable = 0x%02x\n",
239 tvp5150_read(c, TVP5150_TELETEXT_FIL_ENA));
240 printk("tvp5150: Interrupt status register A = 0x%02x\n",
241 tvp5150_read(c, TVP5150_INT_STATUS_REG_A));
242 printk("tvp5150: Interrupt enable register A = 0x%02x\n",
243 tvp5150_read(c, TVP5150_INT_ENABLE_REG_A));
244 printk("tvp5150: Interrupt configuration = 0x%02x\n",
245 tvp5150_read(c, TVP5150_INT_CONF));
246 printk("tvp5150: VDP status register = 0x%02x\n",
247 tvp5150_read(c, TVP5150_VDP_STATUS_REG));
248 printk("tvp5150: FIFO word count = 0x%02x\n",
249 tvp5150_read(c, TVP5150_FIFO_WORD_COUNT));
250 printk("tvp5150: FIFO interrupt threshold = 0x%02x\n",
251 tvp5150_read(c, TVP5150_FIFO_INT_THRESHOLD));
252 printk("tvp5150: FIFO reset = 0x%02x\n",
253 tvp5150_read(c, TVP5150_FIFO_RESET));
254 printk("tvp5150: Line number interrupt = 0x%02x\n",
255 tvp5150_read(c, TVP5150_LINE_NUMBER_INT));
256 printk("tvp5150: Pixel alignment register = 0x%02x%02x\n",
257 tvp5150_read(c, TVP5150_PIX_ALIGN_REG_HIGH),
258 tvp5150_read(c, TVP5150_PIX_ALIGN_REG_LOW));
259 printk("tvp5150: FIFO output control = 0x%02x\n",
260 tvp5150_read(c, TVP5150_FIFO_OUT_CTRL));
261 printk("tvp5150: Full field enable = 0x%02x\n",
262 tvp5150_read(c, TVP5150_FULL_FIELD_ENA));
263 printk("tvp5150: Full field mode register = 0x%02x\n",
264 tvp5150_read(c, TVP5150_FULL_FIELD_MODE_REG));
266 dump_reg_range(c,"CC data", TVP5150_CC_DATA_INI,
267 TVP5150_CC_DATA_END,8);
269 dump_reg_range(c,"WSS data", TVP5150_WSS_DATA_INI,
270 TVP5150_WSS_DATA_END,8);
272 dump_reg_range(c,"VPS data", TVP5150_VPS_DATA_INI,
273 TVP5150_VPS_DATA_END,8);
275 dump_reg_range(c,"VITC data", TVP5150_VITC_DATA_INI,
276 TVP5150_VITC_DATA_END,10);
278 dump_reg_range(c,"Line mode", TVP5150_LINE_MODE_INI,
279 TVP5150_LINE_MODE_END,8);
282 /****************************************************************************
284 ****************************************************************************/
286 TVP5150_ANALOG_CH0 = 0,
288 TVP5150_ANALOG_CH1 = 2,
289 TVP5150_BLACK_SCREEN = 8
292 static inline void tvp5150_selmux(struct i2c_client *c,
293 enum tvp5150_input input)
297 struct tvp5150 *decoder = i2c_get_clientdata(c);
299 if (!decoder->enable)
300 input |= TVP5150_BLACK_SCREEN;
303 case TVP5150_ANALOG_CH0:
304 case TVP5150_ANALOG_CH1:
305 opmode=0x30; /* TV Mode */
308 opmode=0; /* Auto Mode */
312 tvp5150_write(c, TVP5150_OP_MODE_CTL, opmode);
313 tvp5150_write(c, TVP5150_VD_IN_SRC_SEL_1, input);
316 struct i2c_reg_value {
321 /* Default values as sugested at TVP5150AM1 datasheet */
322 static const struct i2c_reg_value tvp5150_init_default[] = {
324 TVP5150_VD_IN_SRC_SEL_1,0x00
327 TVP5150_ANAL_CHL_CTL,0x15
330 TVP5150_OP_MODE_CTL,0x00
333 TVP5150_MISC_CTL,0x01
336 TVP5150_COLOR_KIL_THSH_CTL,0x10
339 TVP5150_LUMA_PROC_CTL_1,0x60
342 TVP5150_LUMA_PROC_CTL_2,0x00
345 TVP5150_BRIGHT_CTL,0x80
348 TVP5150_SATURATION_CTL,0x80
354 TVP5150_CONTRAST_CTL,0x80
357 TVP5150_DATA_RATE_SEL,0x47
360 TVP5150_LUMA_PROC_CTL_3,0x00
363 TVP5150_CONF_SHARED_PIN,0x08
366 TVP5150_ACT_VD_CROP_ST_MSB,0x00
369 TVP5150_ACT_VD_CROP_ST_LSB,0x00
372 TVP5150_ACT_VD_CROP_STP_MSB,0x00
375 TVP5150_ACT_VD_CROP_STP_LSB,0x00
381 TVP5150_HORIZ_SYNC_START,0x80
384 TVP5150_VERT_BLANKING_START,0x00
387 TVP5150_VERT_BLANKING_STOP,0x00
390 TVP5150_CHROMA_PROC_CTL_1,0x0c
393 TVP5150_CHROMA_PROC_CTL_2,0x14
396 TVP5150_INT_RESET_REG_B,0x00
399 TVP5150_INT_ENABLE_REG_B,0x00
402 TVP5150_INTT_CONFIG_REG_B,0x00
405 TVP5150_VIDEO_STD,0x00
408 TVP5150_MACROVISION_ON_CTR,0x0f
411 TVP5150_MACROVISION_OFF_CTR,0x01
414 TVP5150_TELETEXT_FIL_ENA,0x00
417 TVP5150_INT_STATUS_REG_A,0x00
420 TVP5150_INT_ENABLE_REG_A,0x00
423 TVP5150_INT_CONF,0x04
426 TVP5150_FIFO_INT_THRESHOLD,0x80
429 TVP5150_FIFO_RESET,0x00
432 TVP5150_LINE_NUMBER_INT,0x00
435 TVP5150_PIX_ALIGN_REG_LOW,0x4e
438 TVP5150_PIX_ALIGN_REG_HIGH,0x00
441 TVP5150_FIFO_OUT_CTRL,0x01
444 TVP5150_FULL_FIELD_ENA,0x00
447 TVP5150_LINE_MODE_INI,0x00
450 TVP5150_FULL_FIELD_MODE_REG,0x7f
457 /* Default values as sugested at TVP5150AM1 datasheet */
458 static const struct i2c_reg_value tvp5150_init_enable[] = {
460 TVP5150_CONF_SHARED_PIN, 2
461 },{ /* Automatic offset and AGC enabled */
462 TVP5150_ANAL_CHL_CTL, 0x15
463 },{ /* Activate YCrCb output 0x9 or 0xd ? */
464 TVP5150_MISC_CTL, 0x6f
465 },{ /* Activates video std autodetection for all standards */
466 TVP5150_AUTOSW_MSK, 0x0
467 },{ /* Default format: 0x47. For 4:2:2: 0x40 */
468 TVP5150_DATA_RATE_SEL, 0x47
470 TVP5150_CHROMA_PROC_CTL_1, 0x0c
472 TVP5150_CHROMA_PROC_CTL_2, 0x54
473 },{ /* Non documented, but initialized on WinTV USB2 */
480 struct i2c_vbi_ram_value {
482 unsigned char values[26];
485 /* tvp5150_vbi_types should follow the same order as vbi_ram_default
486 * value 0 means rom position 0x10, value 1 means rom position 0x30
487 * and so on. There are 16 possible locations from 0 to 15.
489 enum tvp5150_vbi_types { /* Video line number Description */
490 VBI_WST_SECAM, /* 6-23 (field 1,2) Teletext, SECAM */
491 VBI_WST_PAL_B, /* 6-22 (field 1,2) Teletext, PAL, System B */
492 VBI_WST_PAL_C, /* 6-22 (field 1,2) Teletext, PAL, System C */
493 VBI_WST_NTSC_B, /* 10-21 (field 1,2) Teletext, NTSC, System B */
494 VBI_NABTS_NTSC_C, /* 10-21 (field 1,2) Teletext, NTSC, System C */
495 VBI_NABTS_NTSC_D, /* 10-21 (field 1,2) Teletext, NTSC, System D */
496 VBI_CC_PAL_SECAM, /* 22 (field 1,2) Closed Caption PAL/SECAM */
497 VBI_CC_NTSC, /* 21 (field 1,2) Closed Caption NTSC */
498 VBI_WSS_PAL_SECAM, /* 23 (field 1,2) Wide Screen Signal PAL/SECAM */
499 VBI_WSS_NTSC, /* 20 (field 1,2) Wide Screen Signal NTSC */
500 VBI_VITC_PAL_SECAM, /* 6-22 Vertical Interval Timecode PAL/SECAM */
501 VBI_VITC_NTSC, /* 10-20 Vertical Interval Timecode NTSC */
502 VBI_VPS_PAL, /* 16 Video Program System PAL */
503 VBI_EPG_GEMSTAR, /* EPG/Gemstar Electronic program guide */
504 VBI_RESERVED, /* not in use on vbi_ram_default table */
505 VBI_FULL_FIELD /* Active video/Full Field */
508 static struct i2c_vbi_ram_value vbi_ram_default[] =
510 {0x010, /* WST SECAM */
511 { 0xaa, 0xaa, 0xff, 0xff , 0xe7, 0x2e, 0x20, 0x26, 0xe6, 0xb4, 0x0e, 0x0, 0x0, 0x0, 0x10, 0x0 }
513 {0x030, /* WST PAL B */
514 { 0xaa, 0xaa, 0xff, 0xff , 0x27, 0x2e, 0x20, 0x2b, 0xa6, 0x72, 0x10, 0x0, 0x0, 0x0, 0x10, 0x0 }
516 {0x050, /* WST PAL C */
517 { 0xaa, 0xaa, 0xff, 0xff , 0xe7, 0x2e, 0x20, 0x22, 0xa6, 0x98, 0x0d, 0x0, 0x0, 0x0, 0x10, 0x0 }
519 {0x070, /* WST NTSC B */
520 { 0xaa, 0xaa, 0xff, 0xff , 0x27, 0x2e, 0x20, 0x23, 0x69, 0x93, 0x0d, 0x0, 0x0, 0x0, 0x10, 0x0 }
522 {0x090, /* NABTS, NTSC */
523 { 0xaa, 0xaa, 0xff, 0xff , 0xe7, 0x2e, 0x20, 0x22, 0x69, 0x93, 0x0d, 0x0, 0x0, 0x0, 0x15, 0x0 }
525 {0x0b0, /* NABTS, NTSC-J */
526 { 0xaa, 0xaa, 0xff, 0xff , 0xa7, 0x2e, 0x20, 0x23, 0x69, 0x93, 0x0d, 0x0, 0x0, 0x0, 0x10, 0x0 }
528 {0x0d0, /* CC, PAL/SECAM */
529 { 0xaa, 0x2a, 0xff, 0x3f , 0x04, 0x51, 0x6e, 0x02, 0xa6, 0x7b, 0x09, 0x0, 0x0, 0x0, 0x27, 0x0 }
531 {0x0f0, /* CC, NTSC */
532 { 0xaa, 0x2a, 0xff, 0x3f , 0x04, 0x51, 0x6e, 0x02, 0x69, 0x8c, 0x09, 0x0, 0x0, 0x0, 0x27, 0x0 }
534 {0x110, /* WSS, PAL/SECAM */
535 { 0x5b, 0x55, 0xc5, 0xff , 0x0, 0x71, 0x6e, 0x42, 0xa6, 0xcd, 0x0f, 0x0, 0x0, 0x0, 0x3a, 0x0 }
537 {0x130, /* WSS, NTSC C */
538 { 0x38, 0x00, 0x3f, 0x00 , 0x0, 0x71, 0x6e, 0x43, 0x69, 0x7c, 0x08, 0x0, 0x0, 0x0, 0x39, 0x0 }
540 {0x150, /* VITC, PAL/SECAM */
541 { 0x0, 0x0, 0x0, 0x0 , 0x0, 0x8f, 0x6d, 0x49, 0xa6, 0x85, 0x08, 0x0, 0x0, 0x0, 0x4c, 0x0 }
543 {0x170, /* VITC, NTSC */
544 { 0x0, 0x0, 0x0, 0x0 , 0x0, 0x8f, 0x6d, 0x49, 0x69, 0x94, 0x08, 0x0, 0x0, 0x0, 0x4c, 0x0 }
546 {0x190, /* VPS, PAL */
547 { 0xaa, 0xaa, 0xff, 0xff, 0xba, 0xce, 0x2b, 0x0d, 0xa6, 0xda, 0x0b, 0x0, 0x0, 0x0, 0x60, 0x0 }
549 {0x1b0, /* Gemstar Custom 1 */
550 { 0xcc, 0xcc, 0xff, 0xff, 0x05, 0x51, 0x6e, 0x05, 0x69, 0x19, 0x13, 0x0, 0x0, 0x0, 0x60, 0x0 }
554 static int tvp5150_write_inittab(struct i2c_client *c,
555 const struct i2c_reg_value *regs)
557 while (regs->reg != 0xff) {
558 tvp5150_write(c, regs->reg, regs->value);
564 static int tvp5150_vdp_init(struct i2c_client *c,
565 const struct i2c_vbi_ram_value *regs)
569 /* Disable Full Field */
570 tvp5150_write(c, TVP5150_FULL_FIELD_ENA, 0);
572 /* Before programming, Line mode should be at 0xff */
573 for (i=TVP5150_LINE_MODE_INI; i<=TVP5150_LINE_MODE_END; i++)
574 tvp5150_write(c, i, 0xff);
577 while (regs->reg != (u16)-1 ) {
578 tvp5150_write(c, TVP5150_CONF_RAM_ADDR_HIGH,regs->reg>>8);
579 tvp5150_write(c, TVP5150_CONF_RAM_ADDR_LOW,regs->reg);
582 tvp5150_write(c, TVP5150_VDP_CONF_RAM_DATA,regs->values[i]);
589 /* Set vbi processing
590 * type - one of tvp5150_vbi_types
591 * line - line to gather data
592 * fields: bit 0 field1, bit 1, field2
593 * flags (default=0xf0) is a bitmask, were set means:
594 * bit 7: enable filtering null bytes on CC
595 * bit 6: send data also to FIFO
596 * bit 5: don't allow data with errors on FIFO
597 * bit 4: enable ECC when possible
598 * pix_align = pix alignment:
602 static int tvp5150_set_vbi(struct i2c_client *c, enum tvp5150_vbi_types type,
603 u8 flags, int line, const int fields)
605 struct tvp5150 *decoder = i2c_get_clientdata(c);
606 v4l2_std_id std=decoder->norm;
609 if (std == V4L2_STD_ALL) {
610 tvp5150_err("VBI can't be configured without knowing number of lines\n");
612 } else if (std && V4L2_STD_625_50) {
613 /* Don't follow NTSC Line number convension */
620 type=type | (flags & 0xf0);
621 reg=((line-6)<<1)+TVP5150_LINE_MODE_INI;
624 tvp5150_write(c, reg, type);
628 tvp5150_write(c, reg+1, type);
634 static int tvp5150_set_std(struct i2c_client *c, v4l2_std_id std)
636 struct tvp5150 *decoder = i2c_get_clientdata(c);
641 /* First tests should be against specific std */
643 if (std == V4L2_STD_ALL) {
644 fmt=0; /* Autodetect mode */
645 } else if (std & V4L2_STD_NTSC_443) {
647 } else if (std & V4L2_STD_PAL_M) {
649 } else if (std & (V4L2_STD_PAL_N| V4L2_STD_PAL_Nc)) {
652 /* Then, test against generic ones */
653 if (std & V4L2_STD_NTSC) {
655 } else if (std & V4L2_STD_PAL) {
657 } else if (std & V4L2_STD_SECAM) {
662 tvp5150_dbg(1,"Set video std register to %d.\n",fmt);
663 tvp5150_write(c, TVP5150_VIDEO_STD, fmt);
668 static inline void tvp5150_reset(struct i2c_client *c)
670 u8 msb_id, lsb_id, msb_rom, lsb_rom;
671 struct tvp5150 *decoder = i2c_get_clientdata(c);
673 msb_id=tvp5150_read(c,TVP5150_MSB_DEV_ID);
674 lsb_id=tvp5150_read(c,TVP5150_LSB_DEV_ID);
675 msb_rom=tvp5150_read(c,TVP5150_ROM_MAJOR_VER);
676 lsb_rom=tvp5150_read(c,TVP5150_ROM_MINOR_VER);
678 if ((msb_rom==4)&&(lsb_rom==0)) { /* Is TVP5150AM1 */
679 tvp5150_info("tvp%02x%02xam1 detected.\n",msb_id, lsb_id);
681 /* ITU-T BT.656.4 timing */
682 tvp5150_write(c,TVP5150_REV_SELECT,0);
684 if ((msb_rom==3)||(lsb_rom==0x21)) { /* Is TVP5150A */
685 tvp5150_info("tvp%02x%02xa detected.\n",msb_id, lsb_id);
687 tvp5150_info("*** unknown tvp%02x%02x chip detected.\n",msb_id,lsb_id);
688 tvp5150_info("*** Rom ver is %d.%d\n",msb_rom,lsb_rom);
692 /* Initializes TVP5150 to its default values */
693 tvp5150_write_inittab(c, tvp5150_init_default);
695 /* Initializes VDP registers */
696 tvp5150_vdp_init(c, vbi_ram_default);
698 /* Selects decoder input */
699 tvp5150_selmux(c, decoder->input);
701 /* Initializes TVP5150 to stream enabled values */
702 tvp5150_write_inittab(c, tvp5150_init_enable);
704 /* Initialize image preferences */
705 tvp5150_write(c, TVP5150_BRIGHT_CTL, decoder->bright >> 8);
706 tvp5150_write(c, TVP5150_CONTRAST_CTL, decoder->contrast >> 8);
707 tvp5150_write(c, TVP5150_SATURATION_CTL, decoder->contrast >> 8);
708 tvp5150_write(c, TVP5150_HUE_CTL, (decoder->hue - 32768) >> 8);
710 tvp5150_set_std(c, decoder->norm);
713 static int tvp5150_get_ctrl(struct i2c_client *c, struct v4l2_control *ctrl)
715 /* struct tvp5150 *decoder = i2c_get_clientdata(c); */
718 case V4L2_CID_BRIGHTNESS:
719 ctrl->value = tvp5150_read(c, TVP5150_BRIGHT_CTL);
721 case V4L2_CID_CONTRAST:
722 ctrl->value = tvp5150_read(c, TVP5150_CONTRAST_CTL);
724 case V4L2_CID_SATURATION:
725 ctrl->value = tvp5150_read(c, TVP5150_SATURATION_CTL);
728 ctrl->value = tvp5150_read(c, TVP5150_HUE_CTL);
734 static int tvp5150_set_ctrl(struct i2c_client *c, struct v4l2_control *ctrl)
736 /* struct tvp5150 *decoder = i2c_get_clientdata(c); */
739 case V4L2_CID_BRIGHTNESS:
740 tvp5150_write(c, TVP5150_BRIGHT_CTL, ctrl->value);
742 case V4L2_CID_CONTRAST:
743 tvp5150_write(c, TVP5150_CONTRAST_CTL, ctrl->value);
745 case V4L2_CID_SATURATION:
746 tvp5150_write(c, TVP5150_SATURATION_CTL, ctrl->value);
749 tvp5150_write(c, TVP5150_HUE_CTL, ctrl->value);
755 /****************************************************************************
757 ****************************************************************************/
758 static int tvp5150_command(struct i2c_client *c,
759 unsigned int cmd, void *arg)
761 struct tvp5150 *decoder = i2c_get_clientdata(c);
766 case VIDIOC_INT_RESET:
771 if (decoder->norm == *(v4l2_std_id *)arg)
773 return tvp5150_set_std(c, *(v4l2_std_id *)arg);
775 *(v4l2_std_id *)arg = decoder->norm;
778 #ifdef CONFIG_VIDEO_ADV_DEBUG
779 case VIDIOC_INT_G_REGISTER:
781 struct v4l2_register *reg = arg;
783 if (reg->i2c_id != I2C_DRIVERID_TVP5150)
785 reg->val = tvp5150_read(c, reg->reg & 0xff);
789 case VIDIOC_INT_S_REGISTER:
791 struct v4l2_register *reg = arg;
793 if (reg->i2c_id != I2C_DRIVERID_TVP5150)
795 if (!capable(CAP_SYS_ADMIN))
797 tvp5150_write(c, reg->reg & 0xff, reg->val & 0xff);
806 case DECODER_GET_CAPABILITIES:
808 struct video_decoder_capability *cap = arg;
810 cap->flags = VIDEO_DECODER_PAL |
812 VIDEO_DECODER_SECAM |
813 VIDEO_DECODER_AUTO | VIDEO_DECODER_CCIR;
818 case DECODER_GET_STATUS:
823 case DECODER_SET_GPIO:
826 case DECODER_SET_VBI_BYPASS:
829 case DECODER_SET_NORM:
835 case VIDEO_MODE_NTSC:
841 case VIDEO_MODE_SECAM:
844 case VIDEO_MODE_AUTO:
851 decoder->norm = *iarg;
854 case DECODER_SET_INPUT:
857 if (*iarg < 0 || *iarg > 3) {
861 decoder->input = *iarg;
862 tvp5150_selmux(c, decoder->input);
866 case DECODER_SET_OUTPUT:
870 /* not much choice of outputs */
876 case DECODER_ENABLE_OUTPUT:
880 decoder->enable = (*iarg != 0);
882 tvp5150_selmux(c, decoder->input);
886 case VIDIOC_QUERYCTRL:
888 struct v4l2_queryctrl *qc = arg;
891 tvp5150_dbg(1, "VIDIOC_QUERYCTRL called\n");
893 for (i = 0; i < ARRAY_SIZE(tvp5150_qctrl); i++)
894 if (qc->id && qc->id == tvp5150_qctrl[i].id) {
895 memcpy(qc, &(tvp5150_qctrl[i]),
904 struct v4l2_control *ctrl = arg;
905 tvp5150_dbg(1, "VIDIOC_G_CTRL called\n");
907 return tvp5150_get_ctrl(c, ctrl);
911 struct v4l2_control *ctrl = arg;
913 n = sizeof(tvp5150_qctrl) / sizeof(tvp5150_qctrl[0]);
914 for (i = 0; i < n; i++)
915 if (ctrl->id == tvp5150_qctrl[i].id) {
917 tvp5150_qctrl[i].minimum
919 tvp5150_qctrl[i].maximum)
922 "VIDIOC_S_CTRL: id=%d, value=%d\n",
923 ctrl->id, ctrl->value);
924 return tvp5150_set_ctrl(c, ctrl);
929 case DECODER_SET_PICTURE:
931 struct video_picture *pic = arg;
932 if (decoder->bright != pic->brightness) {
933 /* We want 0 to 255 we get 0-65535 */
934 decoder->bright = pic->brightness;
935 tvp5150_write(c, TVP5150_BRIGHT_CTL,
936 decoder->bright >> 8);
938 if (decoder->contrast != pic->contrast) {
939 /* We want 0 to 255 we get 0-65535 */
940 decoder->contrast = pic->contrast;
941 tvp5150_write(c, TVP5150_CONTRAST_CTL,
942 decoder->contrast >> 8);
944 if (decoder->sat != pic->colour) {
945 /* We want 0 to 255 we get 0-65535 */
946 decoder->sat = pic->colour;
947 tvp5150_write(c, TVP5150_SATURATION_CTL,
948 decoder->contrast >> 8);
950 if (decoder->hue != pic->hue) {
951 /* We want -128 to 127 we get 0-65535 */
952 decoder->hue = pic->hue;
953 tvp5150_write(c, TVP5150_HUE_CTL,
954 (decoder->hue - 32768) >> 8);
965 /****************************************************************************
967 ****************************************************************************/
968 static struct i2c_driver driver;
970 static struct i2c_client client_template = {
975 static int tvp5150_detect_client(struct i2c_adapter *adapter,
976 int address, int kind)
978 struct i2c_client *c;
979 struct tvp5150 *core;
984 "tvp5150.c: detecting tvp5150 client on address 0x%x\n",
987 client_template.adapter = adapter;
988 client_template.addr = address;
990 /* Check if the adapter supports the needed features */
991 if (!i2c_check_functionality
993 I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
996 c = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
999 memcpy(c, &client_template, sizeof(struct i2c_client));
1001 core = kzalloc(sizeof(struct tvp5150), GFP_KERNEL);
1006 i2c_set_clientdata(c, core);
1008 rv = i2c_attach_client(c);
1010 core->norm = V4L2_STD_ALL; /* Default is autodetect */
1013 core->bright = 32768;
1014 core->contrast = 32768;
1029 static int tvp5150_attach_adapter(struct i2c_adapter *adapter)
1033 "tvp5150.c: starting probe for adapter %s (0x%x)\n",
1034 adapter->name, adapter->id);
1035 return i2c_probe(adapter, &addr_data, &tvp5150_detect_client);
1038 static int tvp5150_detach_client(struct i2c_client *c)
1040 struct tvp5150 *decoder = i2c_get_clientdata(c);
1044 "tvp5150.c: removing tvp5150 adapter on address 0x%x\n",
1047 err = i2c_detach_client(c);
1058 /* ----------------------------------------------------------------------- */
1060 static struct i2c_driver driver = {
1064 .id = I2C_DRIVERID_TVP5150,
1066 .attach_adapter = tvp5150_attach_adapter,
1067 .detach_client = tvp5150_detach_client,
1069 .command = tvp5150_command,
1072 static int __init tvp5150_init(void)
1074 return i2c_add_driver(&driver);
1077 static void __exit tvp5150_exit(void)
1079 i2c_del_driver(&driver);
1082 module_init(tvp5150_init);
1083 module_exit(tvp5150_exit);