2 * drivers/media/video/tvp514x.c
4 * TI TVP5146/47 decoder driver
6 * Copyright (C) 2008 Texas Instruments Inc
7 * Author: Vaibhav Hiremath <hvaibhav@ti.com>
10 * Sivaraj R <sivaraj@ti.com>
11 * Brijesh R Jadav <brijesh.j@ti.com>
12 * Hardik Shah <hardik.shah@ti.com>
13 * Manjunath Hadli <mrh@ti.com>
14 * Karicheri Muralidharan <m-karicheri2@ti.com>
16 * This package is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License version 2 as
18 * published by the Free Software Foundation.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 #include <linux/i2c.h>
32 #include <linux/delay.h>
33 #include <linux/videodev2.h>
34 #include <media/v4l2-int-device.h>
35 #include <media/tvp514x.h>
37 #include "tvp514x_regs.h"
40 #define TVP514X_MODULE_NAME "tvp514x"
42 /* Private macros for TVP */
43 #define I2C_RETRY_COUNT (5)
44 #define LOCK_RETRY_COUNT (5)
45 #define LOCK_RETRY_DELAY (200)
49 module_param(debug, bool, 0644);
50 MODULE_PARM_DESC(debug, "Debug level (0-1)");
52 #define dump_reg(client, reg, val) \
54 val = tvp514x_read_reg(client, reg); \
55 v4l_info(client, "Reg(0x%.2X): 0x%.2X\n", reg, val); \
59 * enum tvp514x_std - enum for supported standards
68 * enum tvp514x_state - enum for different decoder states
76 * struct tvp514x_std_info - Structure to store standard informations
77 * @width: Line width in pixels
78 * @height:Number of active lines
79 * @video_std: Value to write in REG_VIDEO_STD register
80 * @standard: v4l2 standard structure information
82 struct tvp514x_std_info {
86 struct v4l2_standard standard;
90 * struct tvp514x_decoded - TVP5146/47 decoder object
91 * @v4l2_int_device: Slave handle
92 * @pdata: Board specific
93 * @client: I2C client data
94 * @id: Entry from I2C table
96 * @state: TVP5146/47 decoder state - detected or not-detected
97 * @pix: Current pixel format
98 * @num_fmts: Number of formats
99 * @fmt_list: Format list
100 * @current_std: Current standard
101 * @num_stds: Number of standards
102 * @std_list: Standards list
103 * @route: input and output routing at chip level
105 struct tvp514x_decoder {
106 struct v4l2_int_device *v4l2_int_device;
107 const struct tvp514x_platform_data *pdata;
108 struct i2c_client *client;
110 struct i2c_device_id *id;
113 enum tvp514x_state state;
115 struct v4l2_pix_format pix;
117 const struct v4l2_fmtdesc *fmt_list;
119 enum tvp514x_std current_std;
121 struct tvp514x_std_info *std_list;
123 struct v4l2_routing route;
126 /* TVP514x default register values */
127 static struct tvp514x_reg tvp514x_reg_list[] = {
128 {TOK_WRITE, REG_INPUT_SEL, 0x05}, /* Composite selected */
129 {TOK_WRITE, REG_AFE_GAIN_CTRL, 0x0F},
130 {TOK_WRITE, REG_VIDEO_STD, 0x00}, /* Auto mode */
131 {TOK_WRITE, REG_OPERATION_MODE, 0x00},
132 {TOK_SKIP, REG_AUTOSWITCH_MASK, 0x3F},
133 {TOK_WRITE, REG_COLOR_KILLER, 0x10},
134 {TOK_WRITE, REG_LUMA_CONTROL1, 0x00},
135 {TOK_WRITE, REG_LUMA_CONTROL2, 0x00},
136 {TOK_WRITE, REG_LUMA_CONTROL3, 0x02},
137 {TOK_WRITE, REG_BRIGHTNESS, 0x80},
138 {TOK_WRITE, REG_CONTRAST, 0x80},
139 {TOK_WRITE, REG_SATURATION, 0x80},
140 {TOK_WRITE, REG_HUE, 0x00},
141 {TOK_WRITE, REG_CHROMA_CONTROL1, 0x00},
142 {TOK_WRITE, REG_CHROMA_CONTROL2, 0x0E},
143 {TOK_SKIP, 0x0F, 0x00}, /* Reserved */
144 {TOK_WRITE, REG_COMP_PR_SATURATION, 0x80},
145 {TOK_WRITE, REG_COMP_Y_CONTRAST, 0x80},
146 {TOK_WRITE, REG_COMP_PB_SATURATION, 0x80},
147 {TOK_SKIP, 0x13, 0x00}, /* Reserved */
148 {TOK_WRITE, REG_COMP_Y_BRIGHTNESS, 0x80},
149 {TOK_SKIP, 0x15, 0x00}, /* Reserved */
150 {TOK_SKIP, REG_AVID_START_PIXEL_LSB, 0x55}, /* NTSC timing */
151 {TOK_SKIP, REG_AVID_START_PIXEL_MSB, 0x00},
152 {TOK_SKIP, REG_AVID_STOP_PIXEL_LSB, 0x25},
153 {TOK_SKIP, REG_AVID_STOP_PIXEL_MSB, 0x03},
154 {TOK_SKIP, REG_HSYNC_START_PIXEL_LSB, 0x00}, /* NTSC timing */
155 {TOK_SKIP, REG_HSYNC_START_PIXEL_MSB, 0x00},
156 {TOK_SKIP, REG_HSYNC_STOP_PIXEL_LSB, 0x40},
157 {TOK_SKIP, REG_HSYNC_STOP_PIXEL_MSB, 0x00},
158 {TOK_SKIP, REG_VSYNC_START_LINE_LSB, 0x04}, /* NTSC timing */
159 {TOK_SKIP, REG_VSYNC_START_LINE_MSB, 0x00},
160 {TOK_SKIP, REG_VSYNC_STOP_LINE_LSB, 0x07},
161 {TOK_SKIP, REG_VSYNC_STOP_LINE_MSB, 0x00},
162 {TOK_SKIP, REG_VBLK_START_LINE_LSB, 0x01}, /* NTSC timing */
163 {TOK_SKIP, REG_VBLK_START_LINE_MSB, 0x00},
164 {TOK_SKIP, REG_VBLK_STOP_LINE_LSB, 0x15},
165 {TOK_SKIP, REG_VBLK_STOP_LINE_MSB, 0x00},
166 {TOK_SKIP, 0x26, 0x00}, /* Reserved */
167 {TOK_SKIP, 0x27, 0x00}, /* Reserved */
168 {TOK_SKIP, REG_FAST_SWTICH_CONTROL, 0xCC},
169 {TOK_SKIP, 0x29, 0x00}, /* Reserved */
170 {TOK_SKIP, REG_FAST_SWTICH_SCART_DELAY, 0x00},
171 {TOK_SKIP, 0x2B, 0x00}, /* Reserved */
172 {TOK_SKIP, REG_SCART_DELAY, 0x00},
173 {TOK_SKIP, REG_CTI_DELAY, 0x00},
174 {TOK_SKIP, REG_CTI_CONTROL, 0x00},
175 {TOK_SKIP, 0x2F, 0x00}, /* Reserved */
176 {TOK_SKIP, 0x30, 0x00}, /* Reserved */
177 {TOK_SKIP, 0x31, 0x00}, /* Reserved */
178 {TOK_WRITE, REG_SYNC_CONTROL, 0x00}, /* HS, VS active high */
179 {TOK_WRITE, REG_OUTPUT_FORMATTER1, 0x00}, /* 10-bit BT.656 */
180 {TOK_WRITE, REG_OUTPUT_FORMATTER2, 0x11}, /* Enable clk & data */
181 {TOK_WRITE, REG_OUTPUT_FORMATTER3, 0xEE}, /* Enable AVID & FLD */
182 {TOK_WRITE, REG_OUTPUT_FORMATTER4, 0xAF}, /* Enable VS & HS */
183 {TOK_WRITE, REG_OUTPUT_FORMATTER5, 0xFF},
184 {TOK_WRITE, REG_OUTPUT_FORMATTER6, 0xFF},
185 {TOK_WRITE, REG_CLEAR_LOST_LOCK, 0x01}, /* Clear status */
189 /* List of image formats supported by TVP5146/47 decoder
190 * Currently we are using 8 bit mode only, but can be
191 * extended to 10/20 bit mode.
193 static const struct v4l2_fmtdesc tvp514x_fmt_list[] = {
196 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
198 .description = "8-bit UYVY 4:2:2 Format",
199 .pixelformat = V4L2_PIX_FMT_UYVY,
204 * Supported standards -
206 * Currently supports two standards only, need to add support for rest of the
207 * modes, like SECAM, etc...
209 static struct tvp514x_std_info tvp514x_std_list[] = {
210 /* Standard: STD_NTSC_MJ */
212 .width = NTSC_NUM_ACTIVE_PIXELS,
213 .height = NTSC_NUM_ACTIVE_LINES,
214 .video_std = VIDEO_STD_NTSC_MJ_BIT,
219 .frameperiod = {1001, 30000},
222 /* Standard: STD_PAL_BDGHIN */
225 .width = PAL_NUM_ACTIVE_PIXELS,
226 .height = PAL_NUM_ACTIVE_LINES,
227 .video_std = VIDEO_STD_PAL_BDGHIN_BIT,
232 .frameperiod = {1, 25},
236 /* Standard: need to add for additional standard */
239 * Control structure for Auto Gain
240 * This is temporary data, will get replaced once
241 * v4l2_ctrl_query_fill supports it.
243 static const struct v4l2_queryctrl tvp514x_autogain_ctrl = {
244 .id = V4L2_CID_AUTOGAIN,
245 .name = "Gain, Automatic",
246 .type = V4L2_CTRL_TYPE_BOOLEAN,
254 * Read a value from a register in an TVP5146/47 decoder device.
255 * Returns value read if successful, or non-zero (-1) otherwise.
257 static int tvp514x_read_reg(struct i2c_client *client, u8 reg)
263 err = i2c_smbus_read_byte_data(client, reg);
265 if (retry <= I2C_RETRY_COUNT) {
266 v4l_warn(client, "Read: retry ... %d\n", retry);
268 msleep_interruptible(10);
277 * Write a value to a register in an TVP5146/47 decoder device.
278 * Returns zero if successful, or non-zero otherwise.
280 static int tvp514x_write_reg(struct i2c_client *client, u8 reg, u8 val)
286 err = i2c_smbus_write_byte_data(client, reg, val);
288 if (retry <= I2C_RETRY_COUNT) {
289 v4l_warn(client, "Write: retry ... %d\n", retry);
291 msleep_interruptible(10);
300 * tvp514x_write_regs : Initializes a list of TVP5146/47 registers
301 * if token is TOK_TERM, then entire write operation terminates
302 * if token is TOK_DELAY, then a delay of 'val' msec is introduced
303 * if token is TOK_SKIP, then the register write is skipped
304 * if token is TOK_WRITE, then the register write is performed
306 * reglist - list of registers to be written
307 * Returns zero if successful, or non-zero otherwise.
309 static int tvp514x_write_regs(struct i2c_client *client,
310 const struct tvp514x_reg reglist[])
313 const struct tvp514x_reg *next = reglist;
315 for (; next->token != TOK_TERM; next++) {
316 if (next->token == TOK_DELAY) {
321 if (next->token == TOK_SKIP)
324 err = tvp514x_write_reg(client, next->reg, (u8) next->val);
326 v4l_err(client, "Write failed. Err[%d]\n", err);
334 * tvp514x_get_current_std:
335 * Returns the current standard detected by TVP5146/47
337 static enum tvp514x_std tvp514x_get_current_std(struct tvp514x_decoder
342 std = tvp514x_read_reg(decoder->client, REG_VIDEO_STD);
343 if ((std & VIDEO_STD_MASK) == VIDEO_STD_AUTO_SWITCH_BIT) {
344 /* use the standard status register */
345 std_status = tvp514x_read_reg(decoder->client,
346 REG_VIDEO_STD_STATUS);
348 std_status = std; /* use the standard register itself */
350 switch (std_status & VIDEO_STD_MASK) {
351 case VIDEO_STD_NTSC_MJ_BIT:
354 case VIDEO_STD_PAL_BDGHIN_BIT:
355 return STD_PAL_BDGHIN;
365 * TVP5146/47 register dump function
367 static void tvp514x_reg_dump(struct tvp514x_decoder *decoder)
371 dump_reg(decoder->client, REG_INPUT_SEL, value);
372 dump_reg(decoder->client, REG_AFE_GAIN_CTRL, value);
373 dump_reg(decoder->client, REG_VIDEO_STD, value);
374 dump_reg(decoder->client, REG_OPERATION_MODE, value);
375 dump_reg(decoder->client, REG_COLOR_KILLER, value);
376 dump_reg(decoder->client, REG_LUMA_CONTROL1, value);
377 dump_reg(decoder->client, REG_LUMA_CONTROL2, value);
378 dump_reg(decoder->client, REG_LUMA_CONTROL3, value);
379 dump_reg(decoder->client, REG_BRIGHTNESS, value);
380 dump_reg(decoder->client, REG_CONTRAST, value);
381 dump_reg(decoder->client, REG_SATURATION, value);
382 dump_reg(decoder->client, REG_HUE, value);
383 dump_reg(decoder->client, REG_CHROMA_CONTROL1, value);
384 dump_reg(decoder->client, REG_CHROMA_CONTROL2, value);
385 dump_reg(decoder->client, REG_COMP_PR_SATURATION, value);
386 dump_reg(decoder->client, REG_COMP_Y_CONTRAST, value);
387 dump_reg(decoder->client, REG_COMP_PB_SATURATION, value);
388 dump_reg(decoder->client, REG_COMP_Y_BRIGHTNESS, value);
389 dump_reg(decoder->client, REG_AVID_START_PIXEL_LSB, value);
390 dump_reg(decoder->client, REG_AVID_START_PIXEL_MSB, value);
391 dump_reg(decoder->client, REG_AVID_STOP_PIXEL_LSB, value);
392 dump_reg(decoder->client, REG_AVID_STOP_PIXEL_MSB, value);
393 dump_reg(decoder->client, REG_HSYNC_START_PIXEL_LSB, value);
394 dump_reg(decoder->client, REG_HSYNC_START_PIXEL_MSB, value);
395 dump_reg(decoder->client, REG_HSYNC_STOP_PIXEL_LSB, value);
396 dump_reg(decoder->client, REG_HSYNC_STOP_PIXEL_MSB, value);
397 dump_reg(decoder->client, REG_VSYNC_START_LINE_LSB, value);
398 dump_reg(decoder->client, REG_VSYNC_START_LINE_MSB, value);
399 dump_reg(decoder->client, REG_VSYNC_STOP_LINE_LSB, value);
400 dump_reg(decoder->client, REG_VSYNC_STOP_LINE_MSB, value);
401 dump_reg(decoder->client, REG_VBLK_START_LINE_LSB, value);
402 dump_reg(decoder->client, REG_VBLK_START_LINE_MSB, value);
403 dump_reg(decoder->client, REG_VBLK_STOP_LINE_LSB, value);
404 dump_reg(decoder->client, REG_VBLK_STOP_LINE_MSB, value);
405 dump_reg(decoder->client, REG_SYNC_CONTROL, value);
406 dump_reg(decoder->client, REG_OUTPUT_FORMATTER1, value);
407 dump_reg(decoder->client, REG_OUTPUT_FORMATTER2, value);
408 dump_reg(decoder->client, REG_OUTPUT_FORMATTER3, value);
409 dump_reg(decoder->client, REG_OUTPUT_FORMATTER4, value);
410 dump_reg(decoder->client, REG_OUTPUT_FORMATTER5, value);
411 dump_reg(decoder->client, REG_OUTPUT_FORMATTER6, value);
412 dump_reg(decoder->client, REG_CLEAR_LOST_LOCK, value);
416 * Configure the TVP5146/47 with the current register settings
417 * Returns zero if successful, or non-zero otherwise.
419 static int tvp514x_configure(struct tvp514x_decoder *decoder)
423 /* common register initialization */
425 tvp514x_write_regs(decoder->client, tvp514x_reg_list);
430 tvp514x_reg_dump(decoder);
436 * Detect if an tvp514x is present, and if so which revision.
437 * A device is considered to be detected if the chip ID (LSB and MSB)
438 * registers match the expected values.
439 * Any value of the rom version register is accepted.
440 * Returns ENODEV error number if no device is detected, or zero
441 * if a device is detected.
443 static int tvp514x_detect(struct tvp514x_decoder *decoder)
445 u8 chip_id_msb, chip_id_lsb, rom_ver;
447 chip_id_msb = tvp514x_read_reg(decoder->client, REG_CHIP_ID_MSB);
448 chip_id_lsb = tvp514x_read_reg(decoder->client, REG_CHIP_ID_LSB);
449 rom_ver = tvp514x_read_reg(decoder->client, REG_ROM_VERSION);
451 v4l_dbg(1, debug, decoder->client,
452 "chip id detected msb:0x%x lsb:0x%x rom version:0x%x\n",
453 chip_id_msb, chip_id_lsb, rom_ver);
454 if ((chip_id_msb != TVP514X_CHIP_ID_MSB)
455 || ((chip_id_lsb != TVP5146_CHIP_ID_LSB)
456 && (chip_id_lsb != TVP5147_CHIP_ID_LSB))) {
457 /* We didn't read the values we expected, so this must not be
460 v4l_err(decoder->client,
461 "chip id mismatch msb:0x%x lsb:0x%x\n",
462 chip_id_msb, chip_id_lsb);
466 decoder->ver = rom_ver;
467 decoder->state = STATE_DETECTED;
469 v4l_info(decoder->client,
470 "%s found at 0x%x (%s)\n", decoder->client->name,
471 decoder->client->addr << 1,
472 decoder->client->adapter->name);
477 * Following are decoder interface functions implemented by
478 * TVP5146/47 decoder driver.
482 * ioctl_querystd - V4L2 decoder interface handler for VIDIOC_QUERYSTD ioctl
483 * @s: pointer to standard V4L2 device structure
484 * @std_id: standard V4L2 std_id ioctl enum
486 * Returns the current standard detected by TVP5146/47. If no active input is
487 * detected, returns -EINVAL
489 static int ioctl_querystd(struct v4l2_int_device *s, v4l2_std_id *std_id)
491 struct tvp514x_decoder *decoder = s->priv;
492 enum tvp514x_std current_std;
493 enum tvp514x_input input_sel;
494 u8 sync_lock_status, lock_mask;
499 /* get the current standard */
500 current_std = tvp514x_get_current_std(decoder);
501 if (current_std == STD_INVALID)
504 input_sel = decoder->route.input;
507 case INPUT_CVBS_VI1A:
508 case INPUT_CVBS_VI1B:
509 case INPUT_CVBS_VI1C:
510 case INPUT_CVBS_VI2A:
511 case INPUT_CVBS_VI2B:
512 case INPUT_CVBS_VI2C:
513 case INPUT_CVBS_VI3A:
514 case INPUT_CVBS_VI3B:
515 case INPUT_CVBS_VI3C:
516 case INPUT_CVBS_VI4A:
517 lock_mask = STATUS_CLR_SUBCAR_LOCK_BIT |
518 STATUS_HORZ_SYNC_LOCK_BIT |
519 STATUS_VIRT_SYNC_LOCK_BIT;
522 case INPUT_SVIDEO_VI2A_VI1A:
523 case INPUT_SVIDEO_VI2B_VI1B:
524 case INPUT_SVIDEO_VI2C_VI1C:
525 case INPUT_SVIDEO_VI2A_VI3A:
526 case INPUT_SVIDEO_VI2B_VI3B:
527 case INPUT_SVIDEO_VI2C_VI3C:
528 case INPUT_SVIDEO_VI4A_VI1A:
529 case INPUT_SVIDEO_VI4A_VI1B:
530 case INPUT_SVIDEO_VI4A_VI1C:
531 case INPUT_SVIDEO_VI4A_VI3A:
532 case INPUT_SVIDEO_VI4A_VI3B:
533 case INPUT_SVIDEO_VI4A_VI3C:
534 lock_mask = STATUS_HORZ_SYNC_LOCK_BIT |
535 STATUS_VIRT_SYNC_LOCK_BIT;
537 /*Need to add other interfaces*/
541 /* check whether signal is locked */
542 sync_lock_status = tvp514x_read_reg(decoder->client, REG_STATUS1);
543 if (lock_mask != (sync_lock_status & lock_mask))
544 return -EINVAL; /* No input detected */
546 decoder->current_std = current_std;
547 *std_id = decoder->std_list[current_std].standard.id;
549 v4l_dbg(1, debug, decoder->client, "Current STD: %s",
550 decoder->std_list[current_std].standard.name);
555 * ioctl_s_std - V4L2 decoder interface handler for VIDIOC_S_STD ioctl
556 * @s: pointer to standard V4L2 device structure
557 * @std_id: standard V4L2 v4l2_std_id ioctl enum
559 * If std_id is supported, sets the requested standard. Otherwise, returns
562 static int ioctl_s_std(struct v4l2_int_device *s, v4l2_std_id *std_id)
564 struct tvp514x_decoder *decoder = s->priv;
570 for (i = 0; i < decoder->num_stds; i++)
571 if (*std_id & decoder->std_list[i].standard.id)
574 if ((i == decoder->num_stds) || (i == STD_INVALID))
577 err = tvp514x_write_reg(decoder->client, REG_VIDEO_STD,
578 decoder->std_list[i].video_std);
582 decoder->current_std = i;
583 tvp514x_reg_list[REG_VIDEO_STD].val = decoder->std_list[i].video_std;
585 v4l_dbg(1, debug, decoder->client, "Standard set to: %s",
586 decoder->std_list[i].standard.name);
591 * ioctl_s_routing - V4L2 decoder interface handler for VIDIOC_S_INPUT ioctl
592 * @s: pointer to standard V4L2 device structure
593 * @index: number of the input
595 * If index is valid, selects the requested input. Otherwise, returns -EINVAL if
596 * the input is not supported or there is no active signal present in the
599 static int ioctl_s_routing(struct v4l2_int_device *s,
600 struct v4l2_routing *route)
602 struct tvp514x_decoder *decoder = s->priv;
604 enum tvp514x_input input_sel;
605 enum tvp514x_output output_sel;
606 enum tvp514x_std current_std = STD_INVALID;
607 u8 sync_lock_status, lock_mask;
608 int try_count = LOCK_RETRY_COUNT;
610 if ((!route) || (route->input >= INPUT_INVALID) ||
611 (route->output >= OUTPUT_INVALID))
612 return -EINVAL; /* Index out of bound */
614 input_sel = route->input;
615 output_sel = route->output;
617 err = tvp514x_write_reg(decoder->client, REG_INPUT_SEL, input_sel);
621 output_sel |= tvp514x_read_reg(decoder->client,
622 REG_OUTPUT_FORMATTER1) & 0x7;
623 err = tvp514x_write_reg(decoder->client, REG_OUTPUT_FORMATTER1,
628 tvp514x_reg_list[REG_INPUT_SEL].val = input_sel;
629 tvp514x_reg_list[REG_OUTPUT_FORMATTER1].val = output_sel;
632 msleep(LOCK_RETRY_DELAY);
634 tvp514x_write_reg(decoder->client, REG_CLEAR_LOST_LOCK, 0x01);
639 case INPUT_CVBS_VI1A:
640 case INPUT_CVBS_VI1B:
641 case INPUT_CVBS_VI1C:
642 case INPUT_CVBS_VI2A:
643 case INPUT_CVBS_VI2B:
644 case INPUT_CVBS_VI2C:
645 case INPUT_CVBS_VI3A:
646 case INPUT_CVBS_VI3B:
647 case INPUT_CVBS_VI3C:
648 case INPUT_CVBS_VI4A:
649 lock_mask = STATUS_CLR_SUBCAR_LOCK_BIT |
650 STATUS_HORZ_SYNC_LOCK_BIT |
651 STATUS_VIRT_SYNC_LOCK_BIT;
654 case INPUT_SVIDEO_VI2A_VI1A:
655 case INPUT_SVIDEO_VI2B_VI1B:
656 case INPUT_SVIDEO_VI2C_VI1C:
657 case INPUT_SVIDEO_VI2A_VI3A:
658 case INPUT_SVIDEO_VI2B_VI3B:
659 case INPUT_SVIDEO_VI2C_VI3C:
660 case INPUT_SVIDEO_VI4A_VI1A:
661 case INPUT_SVIDEO_VI4A_VI1B:
662 case INPUT_SVIDEO_VI4A_VI1C:
663 case INPUT_SVIDEO_VI4A_VI3A:
664 case INPUT_SVIDEO_VI4A_VI3B:
665 case INPUT_SVIDEO_VI4A_VI3C:
666 lock_mask = STATUS_HORZ_SYNC_LOCK_BIT |
667 STATUS_VIRT_SYNC_LOCK_BIT;
669 /*Need to add other interfaces*/
674 while (try_count-- > 0) {
675 /* Allow decoder to sync up with new input */
676 msleep(LOCK_RETRY_DELAY);
678 /* get the current standard for future reference */
679 current_std = tvp514x_get_current_std(decoder);
680 if (current_std == STD_INVALID)
683 sync_lock_status = tvp514x_read_reg(decoder->client,
685 if (lock_mask == (sync_lock_status & lock_mask))
686 break; /* Input detected */
689 if ((current_std == STD_INVALID) || (try_count < 0))
692 decoder->current_std = current_std;
693 decoder->route.input = route->input;
694 decoder->route.output = route->output;
696 v4l_dbg(1, debug, decoder->client,
697 "Input set to: %d, std : %d",
698 input_sel, current_std);
704 * ioctl_queryctrl - V4L2 decoder interface handler for VIDIOC_QUERYCTRL ioctl
705 * @s: pointer to standard V4L2 device structure
706 * @qctrl: standard V4L2 v4l2_queryctrl structure
708 * If the requested control is supported, returns the control information.
709 * Otherwise, returns -EINVAL if the control is not supported.
712 ioctl_queryctrl(struct v4l2_int_device *s, struct v4l2_queryctrl *qctrl)
714 struct tvp514x_decoder *decoder = s->priv;
721 case V4L2_CID_BRIGHTNESS:
722 /* Brightness supported is same as standard one (0-255),
723 * so make use of standard API provided.
725 err = v4l2_ctrl_query_fill_std(qctrl);
727 case V4L2_CID_CONTRAST:
728 case V4L2_CID_SATURATION:
729 /* Saturation and Contrast supported is -
730 * Contrast: 0 - 255 (Default - 128)
731 * Saturation: 0 - 255 (Default - 128)
733 err = v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 128);
736 /* Hue Supported is -
737 * Hue - -180 - +180 (Default - 0, Step - +180)
739 err = v4l2_ctrl_query_fill(qctrl, -180, 180, 180, 0);
741 case V4L2_CID_AUTOGAIN:
742 /* Autogain is either 0 or 1*/
743 memcpy(qctrl, &tvp514x_autogain_ctrl,
744 sizeof(struct v4l2_queryctrl));
748 v4l_err(decoder->client,
749 "invalid control id %d\n", qctrl->id);
753 v4l_dbg(1, debug, decoder->client,
754 "Query Control: %s : Min - %d, Max - %d, Def - %d",
758 qctrl->default_value);
764 * ioctl_g_ctrl - V4L2 decoder interface handler for VIDIOC_G_CTRL ioctl
765 * @s: pointer to standard V4L2 device structure
766 * @ctrl: pointer to v4l2_control structure
768 * If the requested control is supported, returns the control's current
769 * value from the decoder. Otherwise, returns -EINVAL if the control is not
773 ioctl_g_ctrl(struct v4l2_int_device *s, struct v4l2_control *ctrl)
775 struct tvp514x_decoder *decoder = s->priv;
781 case V4L2_CID_BRIGHTNESS:
782 ctrl->value = tvp514x_reg_list[REG_BRIGHTNESS].val;
784 case V4L2_CID_CONTRAST:
785 ctrl->value = tvp514x_reg_list[REG_CONTRAST].val;
787 case V4L2_CID_SATURATION:
788 ctrl->value = tvp514x_reg_list[REG_SATURATION].val;
791 ctrl->value = tvp514x_reg_list[REG_HUE].val;
792 if (ctrl->value == 0x7F)
794 else if (ctrl->value == 0x80)
800 case V4L2_CID_AUTOGAIN:
801 ctrl->value = tvp514x_reg_list[REG_AFE_GAIN_CTRL].val;
802 if ((ctrl->value & 0x3) == 3)
809 v4l_err(decoder->client,
810 "invalid control id %d\n", ctrl->id);
814 v4l_dbg(1, debug, decoder->client,
815 "Get Control: ID - %d - %d",
816 ctrl->id, ctrl->value);
821 * ioctl_s_ctrl - V4L2 decoder interface handler for VIDIOC_S_CTRL ioctl
822 * @s: pointer to standard V4L2 device structure
823 * @ctrl: pointer to v4l2_control structure
825 * If the requested control is supported, sets the control's current
826 * value in HW. Otherwise, returns -EINVAL if the control is not supported.
829 ioctl_s_ctrl(struct v4l2_int_device *s, struct v4l2_control *ctrl)
831 struct tvp514x_decoder *decoder = s->priv;
832 int err = -EINVAL, value;
837 value = (__s32) ctrl->value;
840 case V4L2_CID_BRIGHTNESS:
841 if (ctrl->value < 0 || ctrl->value > 255) {
842 v4l_err(decoder->client,
843 "invalid brightness setting %d\n",
847 err = tvp514x_write_reg(decoder->client, REG_BRIGHTNESS,
851 tvp514x_reg_list[REG_BRIGHTNESS].val = value;
853 case V4L2_CID_CONTRAST:
854 if (ctrl->value < 0 || ctrl->value > 255) {
855 v4l_err(decoder->client,
856 "invalid contrast setting %d\n",
860 err = tvp514x_write_reg(decoder->client, REG_CONTRAST,
864 tvp514x_reg_list[REG_CONTRAST].val = value;
866 case V4L2_CID_SATURATION:
867 if (ctrl->value < 0 || ctrl->value > 255) {
868 v4l_err(decoder->client,
869 "invalid saturation setting %d\n",
873 err = tvp514x_write_reg(decoder->client, REG_SATURATION,
877 tvp514x_reg_list[REG_SATURATION].val = value;
882 else if (value == -180)
887 v4l_err(decoder->client,
888 "invalid hue setting %d\n",
892 err = tvp514x_write_reg(decoder->client, REG_HUE,
896 tvp514x_reg_list[REG_HUE].val = value;
898 case V4L2_CID_AUTOGAIN:
904 v4l_err(decoder->client,
905 "invalid auto gain setting %d\n",
909 err = tvp514x_write_reg(decoder->client, REG_AFE_GAIN_CTRL,
913 tvp514x_reg_list[REG_AFE_GAIN_CTRL].val = value;
916 v4l_err(decoder->client,
917 "invalid control id %d\n", ctrl->id);
921 v4l_dbg(1, debug, decoder->client,
922 "Set Control: ID - %d - %d",
923 ctrl->id, ctrl->value);
929 * ioctl_enum_fmt_cap - Implement the CAPTURE buffer VIDIOC_ENUM_FMT ioctl
930 * @s: pointer to standard V4L2 device structure
931 * @fmt: standard V4L2 VIDIOC_ENUM_FMT ioctl structure
933 * Implement the VIDIOC_ENUM_FMT ioctl to enumerate supported formats
936 ioctl_enum_fmt_cap(struct v4l2_int_device *s, struct v4l2_fmtdesc *fmt)
938 struct tvp514x_decoder *decoder = s->priv;
945 if ((index >= decoder->num_fmts) || (index < 0))
946 return -EINVAL; /* Index out of bound */
948 if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
949 return -EINVAL; /* only capture is supported */
951 memcpy(fmt, &decoder->fmt_list[index],
952 sizeof(struct v4l2_fmtdesc));
954 v4l_dbg(1, debug, decoder->client,
955 "Current FMT: index - %d (%s)",
956 decoder->fmt_list[index].index,
957 decoder->fmt_list[index].description);
962 * ioctl_try_fmt_cap - Implement the CAPTURE buffer VIDIOC_TRY_FMT ioctl
963 * @s: pointer to standard V4L2 device structure
964 * @f: pointer to standard V4L2 VIDIOC_TRY_FMT ioctl structure
966 * Implement the VIDIOC_TRY_FMT ioctl for the CAPTURE buffer type. This
967 * ioctl is used to negotiate the image capture size and pixel format
968 * without actually making it take effect.
971 ioctl_try_fmt_cap(struct v4l2_int_device *s, struct v4l2_format *f)
973 struct tvp514x_decoder *decoder = s->priv;
975 struct v4l2_pix_format *pix;
976 enum tvp514x_std current_std;
981 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
982 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
986 /* Calculate height and width based on current standard */
987 current_std = tvp514x_get_current_std(decoder);
988 if (current_std == STD_INVALID)
991 decoder->current_std = current_std;
992 pix->width = decoder->std_list[current_std].width;
993 pix->height = decoder->std_list[current_std].height;
995 for (ifmt = 0; ifmt < decoder->num_fmts; ifmt++) {
996 if (pix->pixelformat ==
997 decoder->fmt_list[ifmt].pixelformat)
1000 if (ifmt == decoder->num_fmts)
1001 ifmt = 0; /* None of the format matched, select default */
1002 pix->pixelformat = decoder->fmt_list[ifmt].pixelformat;
1004 pix->field = V4L2_FIELD_INTERLACED;
1005 pix->bytesperline = pix->width * 2;
1006 pix->sizeimage = pix->bytesperline * pix->height;
1007 pix->colorspace = V4L2_COLORSPACE_SMPTE170M;
1010 v4l_dbg(1, debug, decoder->client,
1011 "Try FMT: pixelformat - %s, bytesperline - %d"
1012 "Width - %d, Height - %d",
1013 decoder->fmt_list[ifmt].description, pix->bytesperline,
1014 pix->width, pix->height);
1019 * ioctl_s_fmt_cap - V4L2 decoder interface handler for VIDIOC_S_FMT ioctl
1020 * @s: pointer to standard V4L2 device structure
1021 * @f: pointer to standard V4L2 VIDIOC_S_FMT ioctl structure
1023 * If the requested format is supported, configures the HW to use that
1024 * format, returns error code if format not supported or HW can't be
1025 * correctly configured.
1028 ioctl_s_fmt_cap(struct v4l2_int_device *s, struct v4l2_format *f)
1030 struct tvp514x_decoder *decoder = s->priv;
1031 struct v4l2_pix_format *pix;
1037 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1038 return -EINVAL; /* only capture is supported */
1041 rval = ioctl_try_fmt_cap(s, f);
1045 decoder->pix = *pix;
1051 * ioctl_g_fmt_cap - V4L2 decoder interface handler for ioctl_g_fmt_cap
1052 * @s: pointer to standard V4L2 device structure
1053 * @f: pointer to standard V4L2 v4l2_format structure
1055 * Returns the decoder's current pixel format in the v4l2_format
1059 ioctl_g_fmt_cap(struct v4l2_int_device *s, struct v4l2_format *f)
1061 struct tvp514x_decoder *decoder = s->priv;
1066 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1067 return -EINVAL; /* only capture is supported */
1069 f->fmt.pix = decoder->pix;
1071 v4l_dbg(1, debug, decoder->client,
1072 "Current FMT: bytesperline - %d"
1073 "Width - %d, Height - %d",
1074 decoder->pix.bytesperline,
1075 decoder->pix.width, decoder->pix.height);
1080 * ioctl_g_parm - V4L2 decoder interface handler for VIDIOC_G_PARM ioctl
1081 * @s: pointer to standard V4L2 device structure
1082 * @a: pointer to standard V4L2 VIDIOC_G_PARM ioctl structure
1084 * Returns the decoder's video CAPTURE parameters.
1087 ioctl_g_parm(struct v4l2_int_device *s, struct v4l2_streamparm *a)
1089 struct tvp514x_decoder *decoder = s->priv;
1090 struct v4l2_captureparm *cparm;
1091 enum tvp514x_std current_std;
1096 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1097 return -EINVAL; /* only capture is supported */
1099 memset(a, 0, sizeof(*a));
1100 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1102 /* get the current standard */
1103 current_std = tvp514x_get_current_std(decoder);
1104 if (current_std == STD_INVALID)
1107 decoder->current_std = current_std;
1109 cparm = &a->parm.capture;
1110 cparm->capability = V4L2_CAP_TIMEPERFRAME;
1111 cparm->timeperframe =
1112 decoder->std_list[current_std].standard.frameperiod;
1118 * ioctl_s_parm - V4L2 decoder interface handler for VIDIOC_S_PARM ioctl
1119 * @s: pointer to standard V4L2 device structure
1120 * @a: pointer to standard V4L2 VIDIOC_S_PARM ioctl structure
1122 * Configures the decoder to use the input parameters, if possible. If
1123 * not possible, returns the appropriate error code.
1126 ioctl_s_parm(struct v4l2_int_device *s, struct v4l2_streamparm *a)
1128 struct tvp514x_decoder *decoder = s->priv;
1129 struct v4l2_fract *timeperframe;
1130 enum tvp514x_std current_std;
1135 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1136 return -EINVAL; /* only capture is supported */
1138 timeperframe = &a->parm.capture.timeperframe;
1140 /* get the current standard */
1141 current_std = tvp514x_get_current_std(decoder);
1142 if (current_std == STD_INVALID)
1145 decoder->current_std = current_std;
1148 decoder->std_list[current_std].standard.frameperiod;
1154 * ioctl_g_ifparm - V4L2 decoder interface handler for vidioc_int_g_ifparm_num
1155 * @s: pointer to standard V4L2 device structure
1156 * @p: pointer to standard V4L2 vidioc_int_g_ifparm_num ioctl structure
1158 * Gets slave interface parameters.
1159 * Calculates the required xclk value to support the requested
1160 * clock parameters in p. This value is returned in the p
1163 static int ioctl_g_ifparm(struct v4l2_int_device *s, struct v4l2_ifparm *p)
1165 struct tvp514x_decoder *decoder = s->priv;
1171 if (NULL == decoder->pdata->ifparm)
1174 rval = decoder->pdata->ifparm(p);
1176 v4l_err(decoder->client, "g_ifparm.Err[%d]\n", rval);
1180 p->u.bt656.clock_curr = TVP514X_XCLK_BT656;
1186 * ioctl_g_priv - V4L2 decoder interface handler for vidioc_int_g_priv_num
1187 * @s: pointer to standard V4L2 device structure
1188 * @p: void pointer to hold decoder's private data address
1190 * Returns device's (decoder's) private data area address in p parameter
1192 static int ioctl_g_priv(struct v4l2_int_device *s, void *p)
1194 struct tvp514x_decoder *decoder = s->priv;
1196 if (NULL == decoder->pdata->priv_data_set)
1199 return decoder->pdata->priv_data_set(p);
1203 * ioctl_s_power - V4L2 decoder interface handler for vidioc_int_s_power_num
1204 * @s: pointer to standard V4L2 device structure
1205 * @on: power state to which device is to be set
1207 * Sets devices power state to requrested state, if possible.
1209 static int ioctl_s_power(struct v4l2_int_device *s, enum v4l2_power on)
1211 struct tvp514x_decoder *decoder = s->priv;
1215 case V4L2_POWER_OFF:
1216 /* Power Down Sequence */
1218 tvp514x_write_reg(decoder->client, REG_OPERATION_MODE,
1220 /* Disable mux for TVP5146/47 decoder data path */
1221 if (decoder->pdata->power_set)
1222 err |= decoder->pdata->power_set(on);
1223 decoder->state = STATE_NOT_DETECTED;
1226 case V4L2_POWER_STANDBY:
1227 if (decoder->pdata->power_set)
1228 err = decoder->pdata->power_set(on);
1232 /* Enable mux for TVP5146/47 decoder data path */
1233 if ((decoder->pdata->power_set) &&
1234 (decoder->state == STATE_NOT_DETECTED)) {
1236 struct tvp514x_init_seq *int_seq =
1237 (struct tvp514x_init_seq *)
1238 decoder->id->driver_data;
1240 err = decoder->pdata->power_set(on);
1242 /* Power Up Sequence */
1243 for (i = 0; i < int_seq->no_regs; i++) {
1244 err |= tvp514x_write_reg(decoder->client,
1245 int_seq->init_reg_seq[i].reg,
1246 int_seq->init_reg_seq[i].val);
1248 /* Detect the sensor is not already detected */
1249 err |= tvp514x_detect(decoder);
1251 v4l_err(decoder->client,
1252 "Unable to detect decoder\n");
1256 err |= tvp514x_configure(decoder);
1268 * ioctl_init - V4L2 decoder interface handler for VIDIOC_INT_INIT
1269 * @s: pointer to standard V4L2 device structure
1271 * Initialize the decoder device (calls tvp514x_configure())
1273 static int ioctl_init(struct v4l2_int_device *s)
1275 struct tvp514x_decoder *decoder = s->priv;
1277 /* Set default standard to auto */
1278 tvp514x_reg_list[REG_VIDEO_STD].val =
1279 VIDEO_STD_AUTO_SWITCH_BIT;
1281 return tvp514x_configure(decoder);
1285 * ioctl_dev_exit - V4L2 decoder interface handler for vidioc_int_dev_exit_num
1286 * @s: pointer to standard V4L2 device structure
1288 * Delinitialise the dev. at slave detach. The complement of ioctl_dev_init.
1290 static int ioctl_dev_exit(struct v4l2_int_device *s)
1296 * ioctl_dev_init - V4L2 decoder interface handler for vidioc_int_dev_init_num
1297 * @s: pointer to standard V4L2 device structure
1299 * Initialise the device when slave attaches to the master. Returns 0 if
1300 * TVP5146/47 device could be found, otherwise returns appropriate error.
1302 static int ioctl_dev_init(struct v4l2_int_device *s)
1304 struct tvp514x_decoder *decoder = s->priv;
1307 err = tvp514x_detect(decoder);
1309 v4l_err(decoder->client,
1310 "Unable to detect decoder\n");
1314 v4l_info(decoder->client,
1315 "chip version 0x%.2x detected\n", decoder->ver);
1320 static struct v4l2_int_ioctl_desc tvp514x_ioctl_desc[] = {
1321 {vidioc_int_dev_init_num, (v4l2_int_ioctl_func*) ioctl_dev_init},
1322 {vidioc_int_dev_exit_num, (v4l2_int_ioctl_func*) ioctl_dev_exit},
1323 {vidioc_int_s_power_num, (v4l2_int_ioctl_func*) ioctl_s_power},
1324 {vidioc_int_g_priv_num, (v4l2_int_ioctl_func*) ioctl_g_priv},
1325 {vidioc_int_g_ifparm_num, (v4l2_int_ioctl_func*) ioctl_g_ifparm},
1326 {vidioc_int_init_num, (v4l2_int_ioctl_func*) ioctl_init},
1327 {vidioc_int_enum_fmt_cap_num,
1328 (v4l2_int_ioctl_func *) ioctl_enum_fmt_cap},
1329 {vidioc_int_try_fmt_cap_num,
1330 (v4l2_int_ioctl_func *) ioctl_try_fmt_cap},
1331 {vidioc_int_g_fmt_cap_num,
1332 (v4l2_int_ioctl_func *) ioctl_g_fmt_cap},
1333 {vidioc_int_s_fmt_cap_num,
1334 (v4l2_int_ioctl_func *) ioctl_s_fmt_cap},
1335 {vidioc_int_g_parm_num, (v4l2_int_ioctl_func *) ioctl_g_parm},
1336 {vidioc_int_s_parm_num, (v4l2_int_ioctl_func *) ioctl_s_parm},
1337 {vidioc_int_queryctrl_num,
1338 (v4l2_int_ioctl_func *) ioctl_queryctrl},
1339 {vidioc_int_g_ctrl_num, (v4l2_int_ioctl_func *) ioctl_g_ctrl},
1340 {vidioc_int_s_ctrl_num, (v4l2_int_ioctl_func *) ioctl_s_ctrl},
1341 {vidioc_int_querystd_num, (v4l2_int_ioctl_func *) ioctl_querystd},
1342 {vidioc_int_s_std_num, (v4l2_int_ioctl_func *) ioctl_s_std},
1343 {vidioc_int_s_video_routing_num,
1344 (v4l2_int_ioctl_func *) ioctl_s_routing},
1347 static struct v4l2_int_slave tvp514x_slave = {
1348 .ioctls = tvp514x_ioctl_desc,
1349 .num_ioctls = ARRAY_SIZE(tvp514x_ioctl_desc),
1352 static struct tvp514x_decoder tvp514x_dev = {
1353 .state = STATE_NOT_DETECTED,
1355 .fmt_list = tvp514x_fmt_list,
1356 .num_fmts = ARRAY_SIZE(tvp514x_fmt_list),
1358 .pix = { /* Default to NTSC 8-bit YUV 422 */
1359 .width = NTSC_NUM_ACTIVE_PIXELS,
1360 .height = NTSC_NUM_ACTIVE_LINES,
1361 .pixelformat = V4L2_PIX_FMT_UYVY,
1362 .field = V4L2_FIELD_INTERLACED,
1363 .bytesperline = NTSC_NUM_ACTIVE_PIXELS * 2,
1365 NTSC_NUM_ACTIVE_PIXELS * 2 * NTSC_NUM_ACTIVE_LINES,
1366 .colorspace = V4L2_COLORSPACE_SMPTE170M,
1369 .current_std = STD_NTSC_MJ,
1370 .std_list = tvp514x_std_list,
1371 .num_stds = ARRAY_SIZE(tvp514x_std_list),
1375 static struct v4l2_int_device tvp514x_int_device = {
1376 .module = THIS_MODULE,
1377 .name = TVP514X_MODULE_NAME,
1378 .priv = &tvp514x_dev,
1379 .type = v4l2_int_type_slave,
1381 .slave = &tvp514x_slave,
1386 * tvp514x_probe - decoder driver i2c probe handler
1387 * @client: i2c driver client device structure
1389 * Register decoder as an i2c client device and V4L2
1393 tvp514x_probe(struct i2c_client *client, const struct i2c_device_id *id)
1395 struct tvp514x_decoder *decoder = &tvp514x_dev;
1398 /* Check if the adapter supports the needed features */
1399 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
1402 decoder->pdata = client->dev.platform_data;
1403 if (!decoder->pdata) {
1404 v4l_err(client, "No platform data!!\n");
1408 * Fetch platform specific data, and configure the
1409 * tvp514x_reg_list[] accordingly. Since this is one
1410 * time configuration, no need to preserve.
1412 tvp514x_reg_list[REG_OUTPUT_FORMATTER2].val |=
1413 (decoder->pdata->clk_polarity << 1);
1414 tvp514x_reg_list[REG_SYNC_CONTROL].val |=
1415 ((decoder->pdata->hs_polarity << 2) |
1416 (decoder->pdata->vs_polarity << 3));
1418 * Save the id data, required for power up sequence
1420 decoder->id = (struct i2c_device_id *)id;
1421 /* Attach to Master */
1422 strcpy(tvp514x_int_device.u.slave->attach_to, decoder->pdata->master);
1423 decoder->v4l2_int_device = &tvp514x_int_device;
1424 decoder->client = client;
1425 i2c_set_clientdata(client, decoder);
1427 /* Register with V4L2 layer as slave device */
1428 err = v4l2_int_device_register(decoder->v4l2_int_device);
1430 i2c_set_clientdata(client, NULL);
1432 "Unable to register to v4l2. Err[%d]\n", err);
1435 v4l_info(client, "Registered to v4l2 master %s!!\n",
1436 decoder->pdata->master);
1442 * tvp514x_remove - decoder driver i2c remove handler
1443 * @client: i2c driver client device structure
1445 * Unregister decoder as an i2c client device and V4L2
1446 * device. Complement of tvp514x_probe().
1448 static int __exit tvp514x_remove(struct i2c_client *client)
1450 struct tvp514x_decoder *decoder = i2c_get_clientdata(client);
1452 if (!client->adapter)
1453 return -ENODEV; /* our client isn't attached */
1455 v4l2_int_device_unregister(decoder->v4l2_int_device);
1456 i2c_set_clientdata(client, NULL);
1461 * TVP5146 Init/Power on Sequence
1463 static const struct tvp514x_reg tvp5146_init_reg_seq[] = {
1464 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x02},
1465 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00},
1466 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0x80},
1467 {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x01},
1468 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x60},
1469 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00},
1470 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0xB0},
1471 {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x01},
1472 {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x00},
1473 {TOK_WRITE, REG_OPERATION_MODE, 0x01},
1474 {TOK_WRITE, REG_OPERATION_MODE, 0x00},
1476 static const struct tvp514x_init_seq tvp5146_init = {
1477 .no_regs = ARRAY_SIZE(tvp5146_init_reg_seq),
1478 .init_reg_seq = tvp5146_init_reg_seq,
1481 * TVP5147 Init/Power on Sequence
1483 static const struct tvp514x_reg tvp5147_init_reg_seq[] = {
1484 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x02},
1485 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00},
1486 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0x80},
1487 {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x01},
1488 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x60},
1489 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00},
1490 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0xB0},
1491 {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x01},
1492 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x16},
1493 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00},
1494 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0xA0},
1495 {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x16},
1496 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x60},
1497 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00},
1498 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0xB0},
1499 {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x00},
1500 {TOK_WRITE, REG_OPERATION_MODE, 0x01},
1501 {TOK_WRITE, REG_OPERATION_MODE, 0x00},
1503 static const struct tvp514x_init_seq tvp5147_init = {
1504 .no_regs = ARRAY_SIZE(tvp5147_init_reg_seq),
1505 .init_reg_seq = tvp5147_init_reg_seq,
1508 * TVP5146M2/TVP5147M1 Init/Power on Sequence
1510 static const struct tvp514x_reg tvp514xm_init_reg_seq[] = {
1511 {TOK_WRITE, REG_OPERATION_MODE, 0x01},
1512 {TOK_WRITE, REG_OPERATION_MODE, 0x00},
1514 static const struct tvp514x_init_seq tvp514xm_init = {
1515 .no_regs = ARRAY_SIZE(tvp514xm_init_reg_seq),
1516 .init_reg_seq = tvp514xm_init_reg_seq,
1519 * I2C Device Table -
1521 * name - Name of the actual device/chip.
1522 * driver_data - Driver data
1524 static const struct i2c_device_id tvp514x_id[] = {
1525 {"tvp5146", (unsigned long)&tvp5146_init},
1526 {"tvp5146m2", (unsigned long)&tvp514xm_init},
1527 {"tvp5147", (unsigned long)&tvp5147_init},
1528 {"tvp5147m1", (unsigned long)&tvp514xm_init},
1532 MODULE_DEVICE_TABLE(i2c, tvp514x_id);
1534 static struct i2c_driver tvp514x_i2c_driver = {
1536 .name = TVP514X_MODULE_NAME,
1537 .owner = THIS_MODULE,
1539 .probe = tvp514x_probe,
1540 .remove = __exit_p(tvp514x_remove),
1541 .id_table = tvp514x_id,
1547 * Module init function
1549 static int __init tvp514x_init(void)
1551 return i2c_add_driver(&tvp514x_i2c_driver);
1557 * Module exit function
1559 static void __exit tvp514x_cleanup(void)
1561 i2c_del_driver(&tvp514x_i2c_driver);
1564 module_init(tvp514x_init);
1565 module_exit(tvp514x_cleanup);
1567 MODULE_AUTHOR("Texas Instruments");
1568 MODULE_DESCRIPTION("TVP514X linux decoder driver");
1569 MODULE_LICENSE("GPL");