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;
89 static struct tvp514x_reg tvp514x_reg_list_default[0x40];
91 * struct tvp514x_decoder - TVP5146/47 decoder object
92 * @v4l2_int_device: Slave handle
93 * @tvp514x_slave: Slave pointer which is used by @v4l2_int_device
94 * @tvp514x_regs: copy of hw's regs with preset values.
95 * @pdata: Board specific
96 * @client: I2C client data
97 * @id: Entry from I2C table
99 * @state: TVP5146/47 decoder state - detected or not-detected
100 * @pix: Current pixel format
101 * @num_fmts: Number of formats
102 * @fmt_list: Format list
103 * @current_std: Current standard
104 * @num_stds: Number of standards
105 * @std_list: Standards list
106 * @route: input and output routing at chip level
108 struct tvp514x_decoder {
109 struct v4l2_int_device v4l2_int_device;
110 struct v4l2_int_slave tvp514x_slave;
111 struct tvp514x_reg tvp514x_regs[ARRAY_SIZE(tvp514x_reg_list_default)];
112 const struct tvp514x_platform_data *pdata;
113 struct i2c_client *client;
115 struct i2c_device_id *id;
118 enum tvp514x_state state;
120 struct v4l2_pix_format pix;
122 const struct v4l2_fmtdesc *fmt_list;
124 enum tvp514x_std current_std;
126 struct tvp514x_std_info *std_list;
128 struct v4l2_routing route;
131 /* TVP514x default register values */
132 static struct tvp514x_reg tvp514x_reg_list_default[] = {
133 {TOK_WRITE, REG_INPUT_SEL, 0x05}, /* Composite selected */
134 {TOK_WRITE, REG_AFE_GAIN_CTRL, 0x0F},
135 {TOK_WRITE, REG_VIDEO_STD, 0x00}, /* Auto mode */
136 {TOK_WRITE, REG_OPERATION_MODE, 0x00},
137 {TOK_SKIP, REG_AUTOSWITCH_MASK, 0x3F},
138 {TOK_WRITE, REG_COLOR_KILLER, 0x10},
139 {TOK_WRITE, REG_LUMA_CONTROL1, 0x00},
140 {TOK_WRITE, REG_LUMA_CONTROL2, 0x00},
141 {TOK_WRITE, REG_LUMA_CONTROL3, 0x02},
142 {TOK_WRITE, REG_BRIGHTNESS, 0x80},
143 {TOK_WRITE, REG_CONTRAST, 0x80},
144 {TOK_WRITE, REG_SATURATION, 0x80},
145 {TOK_WRITE, REG_HUE, 0x00},
146 {TOK_WRITE, REG_CHROMA_CONTROL1, 0x00},
147 {TOK_WRITE, REG_CHROMA_CONTROL2, 0x0E},
148 {TOK_SKIP, 0x0F, 0x00}, /* Reserved */
149 {TOK_WRITE, REG_COMP_PR_SATURATION, 0x80},
150 {TOK_WRITE, REG_COMP_Y_CONTRAST, 0x80},
151 {TOK_WRITE, REG_COMP_PB_SATURATION, 0x80},
152 {TOK_SKIP, 0x13, 0x00}, /* Reserved */
153 {TOK_WRITE, REG_COMP_Y_BRIGHTNESS, 0x80},
154 {TOK_SKIP, 0x15, 0x00}, /* Reserved */
155 {TOK_SKIP, REG_AVID_START_PIXEL_LSB, 0x55}, /* NTSC timing */
156 {TOK_SKIP, REG_AVID_START_PIXEL_MSB, 0x00},
157 {TOK_SKIP, REG_AVID_STOP_PIXEL_LSB, 0x25},
158 {TOK_SKIP, REG_AVID_STOP_PIXEL_MSB, 0x03},
159 {TOK_SKIP, REG_HSYNC_START_PIXEL_LSB, 0x00}, /* NTSC timing */
160 {TOK_SKIP, REG_HSYNC_START_PIXEL_MSB, 0x00},
161 {TOK_SKIP, REG_HSYNC_STOP_PIXEL_LSB, 0x40},
162 {TOK_SKIP, REG_HSYNC_STOP_PIXEL_MSB, 0x00},
163 {TOK_SKIP, REG_VSYNC_START_LINE_LSB, 0x04}, /* NTSC timing */
164 {TOK_SKIP, REG_VSYNC_START_LINE_MSB, 0x00},
165 {TOK_SKIP, REG_VSYNC_STOP_LINE_LSB, 0x07},
166 {TOK_SKIP, REG_VSYNC_STOP_LINE_MSB, 0x00},
167 {TOK_SKIP, REG_VBLK_START_LINE_LSB, 0x01}, /* NTSC timing */
168 {TOK_SKIP, REG_VBLK_START_LINE_MSB, 0x00},
169 {TOK_SKIP, REG_VBLK_STOP_LINE_LSB, 0x15},
170 {TOK_SKIP, REG_VBLK_STOP_LINE_MSB, 0x00},
171 {TOK_SKIP, 0x26, 0x00}, /* Reserved */
172 {TOK_SKIP, 0x27, 0x00}, /* Reserved */
173 {TOK_SKIP, REG_FAST_SWTICH_CONTROL, 0xCC},
174 {TOK_SKIP, 0x29, 0x00}, /* Reserved */
175 {TOK_SKIP, REG_FAST_SWTICH_SCART_DELAY, 0x00},
176 {TOK_SKIP, 0x2B, 0x00}, /* Reserved */
177 {TOK_SKIP, REG_SCART_DELAY, 0x00},
178 {TOK_SKIP, REG_CTI_DELAY, 0x00},
179 {TOK_SKIP, REG_CTI_CONTROL, 0x00},
180 {TOK_SKIP, 0x2F, 0x00}, /* Reserved */
181 {TOK_SKIP, 0x30, 0x00}, /* Reserved */
182 {TOK_SKIP, 0x31, 0x00}, /* Reserved */
183 {TOK_WRITE, REG_SYNC_CONTROL, 0x00}, /* HS, VS active high */
184 {TOK_WRITE, REG_OUTPUT_FORMATTER1, 0x00}, /* 10-bit BT.656 */
185 {TOK_WRITE, REG_OUTPUT_FORMATTER2, 0x11}, /* Enable clk & data */
186 {TOK_WRITE, REG_OUTPUT_FORMATTER3, 0xEE}, /* Enable AVID & FLD */
187 {TOK_WRITE, REG_OUTPUT_FORMATTER4, 0xAF}, /* Enable VS & HS */
188 {TOK_WRITE, REG_OUTPUT_FORMATTER5, 0xFF},
189 {TOK_WRITE, REG_OUTPUT_FORMATTER6, 0xFF},
190 {TOK_WRITE, REG_CLEAR_LOST_LOCK, 0x01}, /* Clear status */
194 /* List of image formats supported by TVP5146/47 decoder
195 * Currently we are using 8 bit mode only, but can be
196 * extended to 10/20 bit mode.
198 static const struct v4l2_fmtdesc tvp514x_fmt_list[] = {
201 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
203 .description = "8-bit UYVY 4:2:2 Format",
204 .pixelformat = V4L2_PIX_FMT_UYVY,
209 * Supported standards -
211 * Currently supports two standards only, need to add support for rest of the
212 * modes, like SECAM, etc...
214 static struct tvp514x_std_info tvp514x_std_list[] = {
215 /* Standard: STD_NTSC_MJ */
217 .width = NTSC_NUM_ACTIVE_PIXELS,
218 .height = NTSC_NUM_ACTIVE_LINES,
219 .video_std = VIDEO_STD_NTSC_MJ_BIT,
224 .frameperiod = {1001, 30000},
227 /* Standard: STD_PAL_BDGHIN */
230 .width = PAL_NUM_ACTIVE_PIXELS,
231 .height = PAL_NUM_ACTIVE_LINES,
232 .video_std = VIDEO_STD_PAL_BDGHIN_BIT,
237 .frameperiod = {1, 25},
241 /* Standard: need to add for additional standard */
244 * Control structure for Auto Gain
245 * This is temporary data, will get replaced once
246 * v4l2_ctrl_query_fill supports it.
248 static const struct v4l2_queryctrl tvp514x_autogain_ctrl = {
249 .id = V4L2_CID_AUTOGAIN,
250 .name = "Gain, Automatic",
251 .type = V4L2_CTRL_TYPE_BOOLEAN,
259 * Read a value from a register in an TVP5146/47 decoder device.
260 * Returns value read if successful, or non-zero (-1) otherwise.
262 static int tvp514x_read_reg(struct i2c_client *client, u8 reg)
268 err = i2c_smbus_read_byte_data(client, reg);
270 if (retry <= I2C_RETRY_COUNT) {
271 v4l_warn(client, "Read: retry ... %d\n", retry);
273 msleep_interruptible(10);
282 * Write a value to a register in an TVP5146/47 decoder device.
283 * Returns zero if successful, or non-zero otherwise.
285 static int tvp514x_write_reg(struct i2c_client *client, u8 reg, u8 val)
291 err = i2c_smbus_write_byte_data(client, reg, val);
293 if (retry <= I2C_RETRY_COUNT) {
294 v4l_warn(client, "Write: retry ... %d\n", retry);
296 msleep_interruptible(10);
305 * tvp514x_write_regs : Initializes a list of TVP5146/47 registers
306 * if token is TOK_TERM, then entire write operation terminates
307 * if token is TOK_DELAY, then a delay of 'val' msec is introduced
308 * if token is TOK_SKIP, then the register write is skipped
309 * if token is TOK_WRITE, then the register write is performed
311 * reglist - list of registers to be written
312 * Returns zero if successful, or non-zero otherwise.
314 static int tvp514x_write_regs(struct i2c_client *client,
315 const struct tvp514x_reg reglist[])
318 const struct tvp514x_reg *next = reglist;
320 for (; next->token != TOK_TERM; next++) {
321 if (next->token == TOK_DELAY) {
326 if (next->token == TOK_SKIP)
329 err = tvp514x_write_reg(client, next->reg, (u8) next->val);
331 v4l_err(client, "Write failed. Err[%d]\n", err);
339 * tvp514x_get_current_std:
340 * Returns the current standard detected by TVP5146/47
342 static enum tvp514x_std tvp514x_get_current_std(struct tvp514x_decoder
347 std = tvp514x_read_reg(decoder->client, REG_VIDEO_STD);
348 if ((std & VIDEO_STD_MASK) == VIDEO_STD_AUTO_SWITCH_BIT) {
349 /* use the standard status register */
350 std_status = tvp514x_read_reg(decoder->client,
351 REG_VIDEO_STD_STATUS);
353 std_status = std; /* use the standard register itself */
355 switch (std_status & VIDEO_STD_MASK) {
356 case VIDEO_STD_NTSC_MJ_BIT:
359 case VIDEO_STD_PAL_BDGHIN_BIT:
360 return STD_PAL_BDGHIN;
370 * TVP5146/47 register dump function
372 static void tvp514x_reg_dump(struct tvp514x_decoder *decoder)
376 dump_reg(decoder->client, REG_INPUT_SEL, value);
377 dump_reg(decoder->client, REG_AFE_GAIN_CTRL, value);
378 dump_reg(decoder->client, REG_VIDEO_STD, value);
379 dump_reg(decoder->client, REG_OPERATION_MODE, value);
380 dump_reg(decoder->client, REG_COLOR_KILLER, value);
381 dump_reg(decoder->client, REG_LUMA_CONTROL1, value);
382 dump_reg(decoder->client, REG_LUMA_CONTROL2, value);
383 dump_reg(decoder->client, REG_LUMA_CONTROL3, value);
384 dump_reg(decoder->client, REG_BRIGHTNESS, value);
385 dump_reg(decoder->client, REG_CONTRAST, value);
386 dump_reg(decoder->client, REG_SATURATION, value);
387 dump_reg(decoder->client, REG_HUE, value);
388 dump_reg(decoder->client, REG_CHROMA_CONTROL1, value);
389 dump_reg(decoder->client, REG_CHROMA_CONTROL2, value);
390 dump_reg(decoder->client, REG_COMP_PR_SATURATION, value);
391 dump_reg(decoder->client, REG_COMP_Y_CONTRAST, value);
392 dump_reg(decoder->client, REG_COMP_PB_SATURATION, value);
393 dump_reg(decoder->client, REG_COMP_Y_BRIGHTNESS, value);
394 dump_reg(decoder->client, REG_AVID_START_PIXEL_LSB, value);
395 dump_reg(decoder->client, REG_AVID_START_PIXEL_MSB, value);
396 dump_reg(decoder->client, REG_AVID_STOP_PIXEL_LSB, value);
397 dump_reg(decoder->client, REG_AVID_STOP_PIXEL_MSB, value);
398 dump_reg(decoder->client, REG_HSYNC_START_PIXEL_LSB, value);
399 dump_reg(decoder->client, REG_HSYNC_START_PIXEL_MSB, value);
400 dump_reg(decoder->client, REG_HSYNC_STOP_PIXEL_LSB, value);
401 dump_reg(decoder->client, REG_HSYNC_STOP_PIXEL_MSB, value);
402 dump_reg(decoder->client, REG_VSYNC_START_LINE_LSB, value);
403 dump_reg(decoder->client, REG_VSYNC_START_LINE_MSB, value);
404 dump_reg(decoder->client, REG_VSYNC_STOP_LINE_LSB, value);
405 dump_reg(decoder->client, REG_VSYNC_STOP_LINE_MSB, value);
406 dump_reg(decoder->client, REG_VBLK_START_LINE_LSB, value);
407 dump_reg(decoder->client, REG_VBLK_START_LINE_MSB, value);
408 dump_reg(decoder->client, REG_VBLK_STOP_LINE_LSB, value);
409 dump_reg(decoder->client, REG_VBLK_STOP_LINE_MSB, value);
410 dump_reg(decoder->client, REG_SYNC_CONTROL, value);
411 dump_reg(decoder->client, REG_OUTPUT_FORMATTER1, value);
412 dump_reg(decoder->client, REG_OUTPUT_FORMATTER2, value);
413 dump_reg(decoder->client, REG_OUTPUT_FORMATTER3, value);
414 dump_reg(decoder->client, REG_OUTPUT_FORMATTER4, value);
415 dump_reg(decoder->client, REG_OUTPUT_FORMATTER5, value);
416 dump_reg(decoder->client, REG_OUTPUT_FORMATTER6, value);
417 dump_reg(decoder->client, REG_CLEAR_LOST_LOCK, value);
421 * Configure the TVP5146/47 with the current register settings
422 * Returns zero if successful, or non-zero otherwise.
424 static int tvp514x_configure(struct tvp514x_decoder *decoder)
428 /* common register initialization */
430 tvp514x_write_regs(decoder->client, decoder->tvp514x_regs);
435 tvp514x_reg_dump(decoder);
441 * Detect if an tvp514x is present, and if so which revision.
442 * A device is considered to be detected if the chip ID (LSB and MSB)
443 * registers match the expected values.
444 * Any value of the rom version register is accepted.
445 * Returns ENODEV error number if no device is detected, or zero
446 * if a device is detected.
448 static int tvp514x_detect(struct tvp514x_decoder *decoder)
450 u8 chip_id_msb, chip_id_lsb, rom_ver;
452 chip_id_msb = tvp514x_read_reg(decoder->client, REG_CHIP_ID_MSB);
453 chip_id_lsb = tvp514x_read_reg(decoder->client, REG_CHIP_ID_LSB);
454 rom_ver = tvp514x_read_reg(decoder->client, REG_ROM_VERSION);
456 v4l_dbg(1, debug, decoder->client,
457 "chip id detected msb:0x%x lsb:0x%x rom version:0x%x\n",
458 chip_id_msb, chip_id_lsb, rom_ver);
459 if ((chip_id_msb != TVP514X_CHIP_ID_MSB)
460 || ((chip_id_lsb != TVP5146_CHIP_ID_LSB)
461 && (chip_id_lsb != TVP5147_CHIP_ID_LSB))) {
462 /* We didn't read the values we expected, so this must not be
465 v4l_err(decoder->client,
466 "chip id mismatch msb:0x%x lsb:0x%x\n",
467 chip_id_msb, chip_id_lsb);
471 decoder->ver = rom_ver;
472 decoder->state = STATE_DETECTED;
474 v4l_info(decoder->client,
475 "%s found at 0x%x (%s)\n", decoder->client->name,
476 decoder->client->addr << 1,
477 decoder->client->adapter->name);
482 * Following are decoder interface functions implemented by
483 * TVP5146/47 decoder driver.
487 * ioctl_querystd - V4L2 decoder interface handler for VIDIOC_QUERYSTD ioctl
488 * @s: pointer to standard V4L2 device structure
489 * @std_id: standard V4L2 std_id ioctl enum
491 * Returns the current standard detected by TVP5146/47. If no active input is
492 * detected, returns -EINVAL
494 static int ioctl_querystd(struct v4l2_int_device *s, v4l2_std_id *std_id)
496 struct tvp514x_decoder *decoder = s->priv;
497 enum tvp514x_std current_std;
498 enum tvp514x_input input_sel;
499 u8 sync_lock_status, lock_mask;
504 /* get the current standard */
505 current_std = tvp514x_get_current_std(decoder);
506 if (current_std == STD_INVALID)
509 input_sel = decoder->route.input;
512 case INPUT_CVBS_VI1A:
513 case INPUT_CVBS_VI1B:
514 case INPUT_CVBS_VI1C:
515 case INPUT_CVBS_VI2A:
516 case INPUT_CVBS_VI2B:
517 case INPUT_CVBS_VI2C:
518 case INPUT_CVBS_VI3A:
519 case INPUT_CVBS_VI3B:
520 case INPUT_CVBS_VI3C:
521 case INPUT_CVBS_VI4A:
522 lock_mask = STATUS_CLR_SUBCAR_LOCK_BIT |
523 STATUS_HORZ_SYNC_LOCK_BIT |
524 STATUS_VIRT_SYNC_LOCK_BIT;
527 case INPUT_SVIDEO_VI2A_VI1A:
528 case INPUT_SVIDEO_VI2B_VI1B:
529 case INPUT_SVIDEO_VI2C_VI1C:
530 case INPUT_SVIDEO_VI2A_VI3A:
531 case INPUT_SVIDEO_VI2B_VI3B:
532 case INPUT_SVIDEO_VI2C_VI3C:
533 case INPUT_SVIDEO_VI4A_VI1A:
534 case INPUT_SVIDEO_VI4A_VI1B:
535 case INPUT_SVIDEO_VI4A_VI1C:
536 case INPUT_SVIDEO_VI4A_VI3A:
537 case INPUT_SVIDEO_VI4A_VI3B:
538 case INPUT_SVIDEO_VI4A_VI3C:
539 lock_mask = STATUS_HORZ_SYNC_LOCK_BIT |
540 STATUS_VIRT_SYNC_LOCK_BIT;
542 /*Need to add other interfaces*/
546 /* check whether signal is locked */
547 sync_lock_status = tvp514x_read_reg(decoder->client, REG_STATUS1);
548 if (lock_mask != (sync_lock_status & lock_mask))
549 return -EINVAL; /* No input detected */
551 decoder->current_std = current_std;
552 *std_id = decoder->std_list[current_std].standard.id;
554 v4l_dbg(1, debug, decoder->client, "Current STD: %s",
555 decoder->std_list[current_std].standard.name);
560 * ioctl_s_std - V4L2 decoder interface handler for VIDIOC_S_STD ioctl
561 * @s: pointer to standard V4L2 device structure
562 * @std_id: standard V4L2 v4l2_std_id ioctl enum
564 * If std_id is supported, sets the requested standard. Otherwise, returns
567 static int ioctl_s_std(struct v4l2_int_device *s, v4l2_std_id *std_id)
569 struct tvp514x_decoder *decoder = s->priv;
575 for (i = 0; i < decoder->num_stds; i++)
576 if (*std_id & decoder->std_list[i].standard.id)
579 if ((i == decoder->num_stds) || (i == STD_INVALID))
582 err = tvp514x_write_reg(decoder->client, REG_VIDEO_STD,
583 decoder->std_list[i].video_std);
587 decoder->current_std = i;
588 decoder->tvp514x_regs[REG_VIDEO_STD].val =
589 decoder->std_list[i].video_std;
591 v4l_dbg(1, debug, decoder->client, "Standard set to: %s",
592 decoder->std_list[i].standard.name);
597 * ioctl_s_routing - V4L2 decoder interface handler for VIDIOC_S_INPUT ioctl
598 * @s: pointer to standard V4L2 device structure
599 * @index: number of the input
601 * If index is valid, selects the requested input. Otherwise, returns -EINVAL if
602 * the input is not supported or there is no active signal present in the
605 static int ioctl_s_routing(struct v4l2_int_device *s,
606 struct v4l2_routing *route)
608 struct tvp514x_decoder *decoder = s->priv;
610 enum tvp514x_input input_sel;
611 enum tvp514x_output output_sel;
612 enum tvp514x_std current_std = STD_INVALID;
613 u8 sync_lock_status, lock_mask;
614 int try_count = LOCK_RETRY_COUNT;
616 if ((!route) || (route->input >= INPUT_INVALID) ||
617 (route->output >= OUTPUT_INVALID))
618 return -EINVAL; /* Index out of bound */
620 input_sel = route->input;
621 output_sel = route->output;
623 err = tvp514x_write_reg(decoder->client, REG_INPUT_SEL, input_sel);
627 output_sel |= tvp514x_read_reg(decoder->client,
628 REG_OUTPUT_FORMATTER1) & 0x7;
629 err = tvp514x_write_reg(decoder->client, REG_OUTPUT_FORMATTER1,
634 decoder->tvp514x_regs[REG_INPUT_SEL].val = input_sel;
635 decoder->tvp514x_regs[REG_OUTPUT_FORMATTER1].val = output_sel;
638 msleep(LOCK_RETRY_DELAY);
640 tvp514x_write_reg(decoder->client, REG_CLEAR_LOST_LOCK, 0x01);
645 case INPUT_CVBS_VI1A:
646 case INPUT_CVBS_VI1B:
647 case INPUT_CVBS_VI1C:
648 case INPUT_CVBS_VI2A:
649 case INPUT_CVBS_VI2B:
650 case INPUT_CVBS_VI2C:
651 case INPUT_CVBS_VI3A:
652 case INPUT_CVBS_VI3B:
653 case INPUT_CVBS_VI3C:
654 case INPUT_CVBS_VI4A:
655 lock_mask = STATUS_CLR_SUBCAR_LOCK_BIT |
656 STATUS_HORZ_SYNC_LOCK_BIT |
657 STATUS_VIRT_SYNC_LOCK_BIT;
660 case INPUT_SVIDEO_VI2A_VI1A:
661 case INPUT_SVIDEO_VI2B_VI1B:
662 case INPUT_SVIDEO_VI2C_VI1C:
663 case INPUT_SVIDEO_VI2A_VI3A:
664 case INPUT_SVIDEO_VI2B_VI3B:
665 case INPUT_SVIDEO_VI2C_VI3C:
666 case INPUT_SVIDEO_VI4A_VI1A:
667 case INPUT_SVIDEO_VI4A_VI1B:
668 case INPUT_SVIDEO_VI4A_VI1C:
669 case INPUT_SVIDEO_VI4A_VI3A:
670 case INPUT_SVIDEO_VI4A_VI3B:
671 case INPUT_SVIDEO_VI4A_VI3C:
672 lock_mask = STATUS_HORZ_SYNC_LOCK_BIT |
673 STATUS_VIRT_SYNC_LOCK_BIT;
675 /*Need to add other interfaces*/
680 while (try_count-- > 0) {
681 /* Allow decoder to sync up with new input */
682 msleep(LOCK_RETRY_DELAY);
684 /* get the current standard for future reference */
685 current_std = tvp514x_get_current_std(decoder);
686 if (current_std == STD_INVALID)
689 sync_lock_status = tvp514x_read_reg(decoder->client,
691 if (lock_mask == (sync_lock_status & lock_mask))
692 break; /* Input detected */
695 if ((current_std == STD_INVALID) || (try_count <= 0))
698 decoder->current_std = current_std;
699 decoder->route.input = route->input;
700 decoder->route.output = route->output;
702 v4l_dbg(1, debug, decoder->client,
703 "Input set to: %d, std : %d",
704 input_sel, current_std);
710 * ioctl_queryctrl - V4L2 decoder interface handler for VIDIOC_QUERYCTRL ioctl
711 * @s: pointer to standard V4L2 device structure
712 * @qctrl: standard V4L2 v4l2_queryctrl structure
714 * If the requested control is supported, returns the control information.
715 * Otherwise, returns -EINVAL if the control is not supported.
718 ioctl_queryctrl(struct v4l2_int_device *s, struct v4l2_queryctrl *qctrl)
720 struct tvp514x_decoder *decoder = s->priv;
727 case V4L2_CID_BRIGHTNESS:
728 /* Brightness supported is (0-255),
730 err = v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 128);
732 case V4L2_CID_CONTRAST:
733 case V4L2_CID_SATURATION:
734 /* Saturation and Contrast supported is -
735 * Contrast: 0 - 255 (Default - 128)
736 * Saturation: 0 - 255 (Default - 128)
738 err = v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 128);
741 /* Hue Supported is -
742 * Hue - -180 - +180 (Default - 0, Step - +180)
744 err = v4l2_ctrl_query_fill(qctrl, -180, 180, 180, 0);
746 case V4L2_CID_AUTOGAIN:
747 /* Autogain is either 0 or 1*/
748 memcpy(qctrl, &tvp514x_autogain_ctrl,
749 sizeof(struct v4l2_queryctrl));
753 v4l_err(decoder->client,
754 "invalid control id %d\n", qctrl->id);
758 v4l_dbg(1, debug, decoder->client,
759 "Query Control: %s : Min - %d, Max - %d, Def - %d",
763 qctrl->default_value);
769 * ioctl_g_ctrl - V4L2 decoder interface handler for VIDIOC_G_CTRL ioctl
770 * @s: pointer to standard V4L2 device structure
771 * @ctrl: pointer to v4l2_control structure
773 * If the requested control is supported, returns the control's current
774 * value from the decoder. Otherwise, returns -EINVAL if the control is not
778 ioctl_g_ctrl(struct v4l2_int_device *s, struct v4l2_control *ctrl)
780 struct tvp514x_decoder *decoder = s->priv;
786 case V4L2_CID_BRIGHTNESS:
787 ctrl->value = decoder->tvp514x_regs[REG_BRIGHTNESS].val;
789 case V4L2_CID_CONTRAST:
790 ctrl->value = decoder->tvp514x_regs[REG_CONTRAST].val;
792 case V4L2_CID_SATURATION:
793 ctrl->value = decoder->tvp514x_regs[REG_SATURATION].val;
796 ctrl->value = decoder->tvp514x_regs[REG_HUE].val;
797 if (ctrl->value == 0x7F)
799 else if (ctrl->value == 0x80)
805 case V4L2_CID_AUTOGAIN:
806 ctrl->value = decoder->tvp514x_regs[REG_AFE_GAIN_CTRL].val;
807 if ((ctrl->value & 0x3) == 3)
814 v4l_err(decoder->client,
815 "invalid control id %d\n", ctrl->id);
819 v4l_dbg(1, debug, decoder->client,
820 "Get Control: ID - %d - %d",
821 ctrl->id, ctrl->value);
826 * ioctl_s_ctrl - V4L2 decoder interface handler for VIDIOC_S_CTRL ioctl
827 * @s: pointer to standard V4L2 device structure
828 * @ctrl: pointer to v4l2_control structure
830 * If the requested control is supported, sets the control's current
831 * value in HW. Otherwise, returns -EINVAL if the control is not supported.
834 ioctl_s_ctrl(struct v4l2_int_device *s, struct v4l2_control *ctrl)
836 struct tvp514x_decoder *decoder = s->priv;
837 int err = -EINVAL, value;
842 value = (__s32) ctrl->value;
845 case V4L2_CID_BRIGHTNESS:
846 if (ctrl->value < 0 || ctrl->value > 255) {
847 v4l_err(decoder->client,
848 "invalid brightness setting %d\n",
852 err = tvp514x_write_reg(decoder->client, REG_BRIGHTNESS,
856 decoder->tvp514x_regs[REG_BRIGHTNESS].val = value;
858 case V4L2_CID_CONTRAST:
859 if (ctrl->value < 0 || ctrl->value > 255) {
860 v4l_err(decoder->client,
861 "invalid contrast setting %d\n",
865 err = tvp514x_write_reg(decoder->client, REG_CONTRAST,
869 decoder->tvp514x_regs[REG_CONTRAST].val = value;
871 case V4L2_CID_SATURATION:
872 if (ctrl->value < 0 || ctrl->value > 255) {
873 v4l_err(decoder->client,
874 "invalid saturation setting %d\n",
878 err = tvp514x_write_reg(decoder->client, REG_SATURATION,
882 decoder->tvp514x_regs[REG_SATURATION].val = value;
887 else if (value == -180)
892 v4l_err(decoder->client,
893 "invalid hue setting %d\n",
897 err = tvp514x_write_reg(decoder->client, REG_HUE,
901 decoder->tvp514x_regs[REG_HUE].val = value;
903 case V4L2_CID_AUTOGAIN:
909 v4l_err(decoder->client,
910 "invalid auto gain setting %d\n",
914 err = tvp514x_write_reg(decoder->client, REG_AFE_GAIN_CTRL,
918 decoder->tvp514x_regs[REG_AFE_GAIN_CTRL].val = value;
921 v4l_err(decoder->client,
922 "invalid control id %d\n", ctrl->id);
926 v4l_dbg(1, debug, decoder->client,
927 "Set Control: ID - %d - %d",
928 ctrl->id, ctrl->value);
934 * ioctl_enum_fmt_cap - Implement the CAPTURE buffer VIDIOC_ENUM_FMT ioctl
935 * @s: pointer to standard V4L2 device structure
936 * @fmt: standard V4L2 VIDIOC_ENUM_FMT ioctl structure
938 * Implement the VIDIOC_ENUM_FMT ioctl to enumerate supported formats
941 ioctl_enum_fmt_cap(struct v4l2_int_device *s, struct v4l2_fmtdesc *fmt)
943 struct tvp514x_decoder *decoder = s->priv;
950 if ((index >= decoder->num_fmts) || (index < 0))
951 return -EINVAL; /* Index out of bound */
953 if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
954 return -EINVAL; /* only capture is supported */
956 memcpy(fmt, &decoder->fmt_list[index],
957 sizeof(struct v4l2_fmtdesc));
959 v4l_dbg(1, debug, decoder->client,
960 "Current FMT: index - %d (%s)",
961 decoder->fmt_list[index].index,
962 decoder->fmt_list[index].description);
967 * ioctl_try_fmt_cap - Implement the CAPTURE buffer VIDIOC_TRY_FMT ioctl
968 * @s: pointer to standard V4L2 device structure
969 * @f: pointer to standard V4L2 VIDIOC_TRY_FMT ioctl structure
971 * Implement the VIDIOC_TRY_FMT ioctl for the CAPTURE buffer type. This
972 * ioctl is used to negotiate the image capture size and pixel format
973 * without actually making it take effect.
976 ioctl_try_fmt_cap(struct v4l2_int_device *s, struct v4l2_format *f)
978 struct tvp514x_decoder *decoder = s->priv;
980 struct v4l2_pix_format *pix;
981 enum tvp514x_std current_std;
986 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
987 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
991 /* Calculate height and width based on current standard */
992 current_std = tvp514x_get_current_std(decoder);
993 if (current_std == STD_INVALID)
996 decoder->current_std = current_std;
997 pix->width = decoder->std_list[current_std].width;
998 pix->height = decoder->std_list[current_std].height;
1000 for (ifmt = 0; ifmt < decoder->num_fmts; ifmt++) {
1001 if (pix->pixelformat ==
1002 decoder->fmt_list[ifmt].pixelformat)
1005 if (ifmt == decoder->num_fmts)
1006 ifmt = 0; /* None of the format matched, select default */
1007 pix->pixelformat = decoder->fmt_list[ifmt].pixelformat;
1009 pix->field = V4L2_FIELD_INTERLACED;
1010 pix->bytesperline = pix->width * 2;
1011 pix->sizeimage = pix->bytesperline * pix->height;
1012 pix->colorspace = V4L2_COLORSPACE_SMPTE170M;
1015 v4l_dbg(1, debug, decoder->client,
1016 "Try FMT: pixelformat - %s, bytesperline - %d"
1017 "Width - %d, Height - %d",
1018 decoder->fmt_list[ifmt].description, pix->bytesperline,
1019 pix->width, pix->height);
1024 * ioctl_s_fmt_cap - V4L2 decoder interface handler for VIDIOC_S_FMT ioctl
1025 * @s: pointer to standard V4L2 device structure
1026 * @f: pointer to standard V4L2 VIDIOC_S_FMT ioctl structure
1028 * If the requested format is supported, configures the HW to use that
1029 * format, returns error code if format not supported or HW can't be
1030 * correctly configured.
1033 ioctl_s_fmt_cap(struct v4l2_int_device *s, struct v4l2_format *f)
1035 struct tvp514x_decoder *decoder = s->priv;
1036 struct v4l2_pix_format *pix;
1042 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1043 return -EINVAL; /* only capture is supported */
1046 rval = ioctl_try_fmt_cap(s, f);
1050 decoder->pix = *pix;
1056 * ioctl_g_fmt_cap - V4L2 decoder interface handler for ioctl_g_fmt_cap
1057 * @s: pointer to standard V4L2 device structure
1058 * @f: pointer to standard V4L2 v4l2_format structure
1060 * Returns the decoder's current pixel format in the v4l2_format
1064 ioctl_g_fmt_cap(struct v4l2_int_device *s, struct v4l2_format *f)
1066 struct tvp514x_decoder *decoder = s->priv;
1071 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1072 return -EINVAL; /* only capture is supported */
1074 f->fmt.pix = decoder->pix;
1076 v4l_dbg(1, debug, decoder->client,
1077 "Current FMT: bytesperline - %d"
1078 "Width - %d, Height - %d",
1079 decoder->pix.bytesperline,
1080 decoder->pix.width, decoder->pix.height);
1085 * ioctl_g_parm - V4L2 decoder interface handler for VIDIOC_G_PARM ioctl
1086 * @s: pointer to standard V4L2 device structure
1087 * @a: pointer to standard V4L2 VIDIOC_G_PARM ioctl structure
1089 * Returns the decoder's video CAPTURE parameters.
1092 ioctl_g_parm(struct v4l2_int_device *s, struct v4l2_streamparm *a)
1094 struct tvp514x_decoder *decoder = s->priv;
1095 struct v4l2_captureparm *cparm;
1096 enum tvp514x_std current_std;
1101 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1102 return -EINVAL; /* only capture is supported */
1104 memset(a, 0, sizeof(*a));
1105 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1107 /* get the current standard */
1108 current_std = tvp514x_get_current_std(decoder);
1109 if (current_std == STD_INVALID)
1112 decoder->current_std = current_std;
1114 cparm = &a->parm.capture;
1115 cparm->capability = V4L2_CAP_TIMEPERFRAME;
1116 cparm->timeperframe =
1117 decoder->std_list[current_std].standard.frameperiod;
1123 * ioctl_s_parm - V4L2 decoder interface handler for VIDIOC_S_PARM ioctl
1124 * @s: pointer to standard V4L2 device structure
1125 * @a: pointer to standard V4L2 VIDIOC_S_PARM ioctl structure
1127 * Configures the decoder to use the input parameters, if possible. If
1128 * not possible, returns the appropriate error code.
1131 ioctl_s_parm(struct v4l2_int_device *s, struct v4l2_streamparm *a)
1133 struct tvp514x_decoder *decoder = s->priv;
1134 struct v4l2_fract *timeperframe;
1135 enum tvp514x_std current_std;
1140 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1141 return -EINVAL; /* only capture is supported */
1143 timeperframe = &a->parm.capture.timeperframe;
1145 /* get the current standard */
1146 current_std = tvp514x_get_current_std(decoder);
1147 if (current_std == STD_INVALID)
1150 decoder->current_std = current_std;
1153 decoder->std_list[current_std].standard.frameperiod;
1159 * ioctl_g_ifparm - V4L2 decoder interface handler for vidioc_int_g_ifparm_num
1160 * @s: pointer to standard V4L2 device structure
1161 * @p: pointer to standard V4L2 vidioc_int_g_ifparm_num ioctl structure
1163 * Gets slave interface parameters.
1164 * Calculates the required xclk value to support the requested
1165 * clock parameters in p. This value is returned in the p
1168 static int ioctl_g_ifparm(struct v4l2_int_device *s, struct v4l2_ifparm *p)
1170 struct tvp514x_decoder *decoder = s->priv;
1176 if (NULL == decoder->pdata->ifparm)
1179 rval = decoder->pdata->ifparm(p);
1181 v4l_err(decoder->client, "g_ifparm.Err[%d]\n", rval);
1185 p->u.bt656.clock_curr = TVP514X_XCLK_BT656;
1191 * ioctl_g_priv - V4L2 decoder interface handler for vidioc_int_g_priv_num
1192 * @s: pointer to standard V4L2 device structure
1193 * @p: void pointer to hold decoder's private data address
1195 * Returns device's (decoder's) private data area address in p parameter
1197 static int ioctl_g_priv(struct v4l2_int_device *s, void *p)
1199 struct tvp514x_decoder *decoder = s->priv;
1201 if (NULL == decoder->pdata->priv_data_set)
1204 return decoder->pdata->priv_data_set(p);
1208 * ioctl_s_power - V4L2 decoder interface handler for vidioc_int_s_power_num
1209 * @s: pointer to standard V4L2 device structure
1210 * @on: power state to which device is to be set
1212 * Sets devices power state to requrested state, if possible.
1214 static int ioctl_s_power(struct v4l2_int_device *s, enum v4l2_power on)
1216 struct tvp514x_decoder *decoder = s->priv;
1220 case V4L2_POWER_OFF:
1221 /* Power Down Sequence */
1223 tvp514x_write_reg(decoder->client, REG_OPERATION_MODE,
1225 /* Disable mux for TVP5146/47 decoder data path */
1226 if (decoder->pdata->power_set)
1227 err |= decoder->pdata->power_set(on);
1228 decoder->state = STATE_NOT_DETECTED;
1231 case V4L2_POWER_STANDBY:
1232 if (decoder->pdata->power_set)
1233 err = decoder->pdata->power_set(on);
1237 /* Enable mux for TVP5146/47 decoder data path */
1238 if ((decoder->pdata->power_set) &&
1239 (decoder->state == STATE_NOT_DETECTED)) {
1241 struct tvp514x_init_seq *int_seq =
1242 (struct tvp514x_init_seq *)
1243 decoder->id->driver_data;
1245 err = decoder->pdata->power_set(on);
1247 /* Power Up Sequence */
1248 for (i = 0; i < int_seq->no_regs; i++) {
1249 err |= tvp514x_write_reg(decoder->client,
1250 int_seq->init_reg_seq[i].reg,
1251 int_seq->init_reg_seq[i].val);
1253 /* Detect the sensor is not already detected */
1254 err |= tvp514x_detect(decoder);
1256 v4l_err(decoder->client,
1257 "Unable to detect decoder\n");
1261 err |= tvp514x_configure(decoder);
1273 * ioctl_init - V4L2 decoder interface handler for VIDIOC_INT_INIT
1274 * @s: pointer to standard V4L2 device structure
1276 * Initialize the decoder device (calls tvp514x_configure())
1278 static int ioctl_init(struct v4l2_int_device *s)
1280 struct tvp514x_decoder *decoder = s->priv;
1282 /* Set default standard to auto */
1283 decoder->tvp514x_regs[REG_VIDEO_STD].val =
1284 VIDEO_STD_AUTO_SWITCH_BIT;
1286 return tvp514x_configure(decoder);
1290 * ioctl_dev_exit - V4L2 decoder interface handler for vidioc_int_dev_exit_num
1291 * @s: pointer to standard V4L2 device structure
1293 * Delinitialise the dev. at slave detach. The complement of ioctl_dev_init.
1295 static int ioctl_dev_exit(struct v4l2_int_device *s)
1301 * ioctl_dev_init - V4L2 decoder interface handler for vidioc_int_dev_init_num
1302 * @s: pointer to standard V4L2 device structure
1304 * Initialise the device when slave attaches to the master. Returns 0 if
1305 * TVP5146/47 device could be found, otherwise returns appropriate error.
1307 static int ioctl_dev_init(struct v4l2_int_device *s)
1309 struct tvp514x_decoder *decoder = s->priv;
1312 err = tvp514x_detect(decoder);
1314 v4l_err(decoder->client,
1315 "Unable to detect decoder\n");
1319 v4l_info(decoder->client,
1320 "chip version 0x%.2x detected\n", decoder->ver);
1325 static struct v4l2_int_ioctl_desc tvp514x_ioctl_desc[] = {
1326 {vidioc_int_dev_init_num, (v4l2_int_ioctl_func*) ioctl_dev_init},
1327 {vidioc_int_dev_exit_num, (v4l2_int_ioctl_func*) ioctl_dev_exit},
1328 {vidioc_int_s_power_num, (v4l2_int_ioctl_func*) ioctl_s_power},
1329 {vidioc_int_g_priv_num, (v4l2_int_ioctl_func*) ioctl_g_priv},
1330 {vidioc_int_g_ifparm_num, (v4l2_int_ioctl_func*) ioctl_g_ifparm},
1331 {vidioc_int_init_num, (v4l2_int_ioctl_func*) ioctl_init},
1332 {vidioc_int_enum_fmt_cap_num,
1333 (v4l2_int_ioctl_func *) ioctl_enum_fmt_cap},
1334 {vidioc_int_try_fmt_cap_num,
1335 (v4l2_int_ioctl_func *) ioctl_try_fmt_cap},
1336 {vidioc_int_g_fmt_cap_num,
1337 (v4l2_int_ioctl_func *) ioctl_g_fmt_cap},
1338 {vidioc_int_s_fmt_cap_num,
1339 (v4l2_int_ioctl_func *) ioctl_s_fmt_cap},
1340 {vidioc_int_g_parm_num, (v4l2_int_ioctl_func *) ioctl_g_parm},
1341 {vidioc_int_s_parm_num, (v4l2_int_ioctl_func *) ioctl_s_parm},
1342 {vidioc_int_queryctrl_num,
1343 (v4l2_int_ioctl_func *) ioctl_queryctrl},
1344 {vidioc_int_g_ctrl_num, (v4l2_int_ioctl_func *) ioctl_g_ctrl},
1345 {vidioc_int_s_ctrl_num, (v4l2_int_ioctl_func *) ioctl_s_ctrl},
1346 {vidioc_int_querystd_num, (v4l2_int_ioctl_func *) ioctl_querystd},
1347 {vidioc_int_s_std_num, (v4l2_int_ioctl_func *) ioctl_s_std},
1348 {vidioc_int_s_video_routing_num,
1349 (v4l2_int_ioctl_func *) ioctl_s_routing},
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),
1372 .v4l2_int_device = {
1373 .module = THIS_MODULE,
1374 .name = TVP514X_MODULE_NAME,
1375 .type = v4l2_int_type_slave,
1378 .ioctls = tvp514x_ioctl_desc,
1379 .num_ioctls = ARRAY_SIZE(tvp514x_ioctl_desc),
1384 * tvp514x_probe - decoder driver i2c probe handler
1385 * @client: i2c driver client device structure
1387 * Register decoder as an i2c client device and V4L2
1391 tvp514x_probe(struct i2c_client *client, const struct i2c_device_id *id)
1393 struct tvp514x_decoder *decoder;
1396 /* Check if the adapter supports the needed features */
1397 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
1400 decoder = kzalloc(sizeof(*decoder), GFP_KERNEL);
1404 if (!client->dev.platform_data) {
1405 v4l_err(client, "No platform data!!\n");
1410 *decoder = tvp514x_dev;
1411 decoder->v4l2_int_device.priv = decoder;
1412 decoder->pdata = client->dev.platform_data;
1413 decoder->v4l2_int_device.u.slave = &decoder->tvp514x_slave;
1414 memcpy(decoder->tvp514x_regs, tvp514x_reg_list_default,
1415 sizeof(tvp514x_reg_list_default));
1417 * Fetch platform specific data, and configure the
1418 * tvp514x_reg_list[] accordingly. Since this is one
1419 * time configuration, no need to preserve.
1421 decoder->tvp514x_regs[REG_OUTPUT_FORMATTER2].val |=
1422 (decoder->pdata->clk_polarity << 1);
1423 decoder->tvp514x_regs[REG_SYNC_CONTROL].val |=
1424 ((decoder->pdata->hs_polarity << 2) |
1425 (decoder->pdata->vs_polarity << 3));
1427 * Save the id data, required for power up sequence
1429 decoder->id = (struct i2c_device_id *)id;
1430 /* Attach to Master */
1431 strcpy(decoder->v4l2_int_device.u.slave->attach_to,
1432 decoder->pdata->master);
1433 decoder->client = client;
1434 i2c_set_clientdata(client, decoder);
1436 /* Register with V4L2 layer as slave device */
1437 err = v4l2_int_device_register(&decoder->v4l2_int_device);
1439 i2c_set_clientdata(client, NULL);
1441 "Unable to register to v4l2. Err[%d]\n", err);
1445 v4l_info(client, "Registered to v4l2 master %s!!\n",
1446 decoder->pdata->master);
1455 * tvp514x_remove - decoder driver i2c remove handler
1456 * @client: i2c driver client device structure
1458 * Unregister decoder as an i2c client device and V4L2
1459 * device. Complement of tvp514x_probe().
1461 static int __exit tvp514x_remove(struct i2c_client *client)
1463 struct tvp514x_decoder *decoder = i2c_get_clientdata(client);
1465 if (!client->adapter)
1466 return -ENODEV; /* our client isn't attached */
1468 v4l2_int_device_unregister(&decoder->v4l2_int_device);
1469 i2c_set_clientdata(client, NULL);
1474 * TVP5146 Init/Power on Sequence
1476 static const struct tvp514x_reg tvp5146_init_reg_seq[] = {
1477 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x02},
1478 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00},
1479 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0x80},
1480 {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x01},
1481 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x60},
1482 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00},
1483 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0xB0},
1484 {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x01},
1485 {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x00},
1486 {TOK_WRITE, REG_OPERATION_MODE, 0x01},
1487 {TOK_WRITE, REG_OPERATION_MODE, 0x00},
1489 static const struct tvp514x_init_seq tvp5146_init = {
1490 .no_regs = ARRAY_SIZE(tvp5146_init_reg_seq),
1491 .init_reg_seq = tvp5146_init_reg_seq,
1494 * TVP5147 Init/Power on Sequence
1496 static const struct tvp514x_reg tvp5147_init_reg_seq[] = {
1497 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x02},
1498 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00},
1499 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0x80},
1500 {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x01},
1501 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x60},
1502 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00},
1503 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0xB0},
1504 {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x01},
1505 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x16},
1506 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00},
1507 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0xA0},
1508 {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x16},
1509 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x60},
1510 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00},
1511 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0xB0},
1512 {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x00},
1513 {TOK_WRITE, REG_OPERATION_MODE, 0x01},
1514 {TOK_WRITE, REG_OPERATION_MODE, 0x00},
1516 static const struct tvp514x_init_seq tvp5147_init = {
1517 .no_regs = ARRAY_SIZE(tvp5147_init_reg_seq),
1518 .init_reg_seq = tvp5147_init_reg_seq,
1521 * TVP5146M2/TVP5147M1 Init/Power on Sequence
1523 static const struct tvp514x_reg tvp514xm_init_reg_seq[] = {
1524 {TOK_WRITE, REG_OPERATION_MODE, 0x01},
1525 {TOK_WRITE, REG_OPERATION_MODE, 0x00},
1527 static const struct tvp514x_init_seq tvp514xm_init = {
1528 .no_regs = ARRAY_SIZE(tvp514xm_init_reg_seq),
1529 .init_reg_seq = tvp514xm_init_reg_seq,
1532 * I2C Device Table -
1534 * name - Name of the actual device/chip.
1535 * driver_data - Driver data
1537 static const struct i2c_device_id tvp514x_id[] = {
1538 {"tvp5146", (unsigned long)&tvp5146_init},
1539 {"tvp5146m2", (unsigned long)&tvp514xm_init},
1540 {"tvp5147", (unsigned long)&tvp5147_init},
1541 {"tvp5147m1", (unsigned long)&tvp514xm_init},
1545 MODULE_DEVICE_TABLE(i2c, tvp514x_id);
1547 static struct i2c_driver tvp514x_i2c_driver = {
1549 .name = TVP514X_MODULE_NAME,
1550 .owner = THIS_MODULE,
1552 .probe = tvp514x_probe,
1553 .remove = __exit_p(tvp514x_remove),
1554 .id_table = tvp514x_id,
1560 * Module init function
1562 static int __init tvp514x_init(void)
1564 return i2c_add_driver(&tvp514x_i2c_driver);
1570 * Module exit function
1572 static void __exit tvp514x_cleanup(void)
1574 i2c_del_driver(&tvp514x_i2c_driver);
1577 module_init(tvp514x_init);
1578 module_exit(tvp514x_cleanup);
1580 MODULE_AUTHOR("Texas Instruments");
1581 MODULE_DESCRIPTION("TVP514X linux decoder driver");
1582 MODULE_LICENSE("GPL");