Staging: strip: delete the driver
[linux/fpc-iii.git] / drivers / media / video / tvp514x.c
blobe4815a1806e30e03482c55ca17390f6e4c95ba4c
1 /*
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>
9 * Contributors:
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/slab.h>
33 #include <linux/delay.h>
34 #include <linux/videodev2.h>
36 #include <media/v4l2-device.h>
37 #include <media/v4l2-common.h>
38 #include <media/v4l2-chip-ident.h>
39 #include <media/tvp514x.h>
41 #include "tvp514x_regs.h"
43 /* Module Name */
44 #define TVP514X_MODULE_NAME "tvp514x"
46 /* Private macros for TVP */
47 #define I2C_RETRY_COUNT (5)
48 #define LOCK_RETRY_COUNT (5)
49 #define LOCK_RETRY_DELAY (200)
51 /* Debug functions */
52 static int debug;
53 module_param(debug, bool, 0644);
54 MODULE_PARM_DESC(debug, "Debug level (0-1)");
56 MODULE_AUTHOR("Texas Instruments");
57 MODULE_DESCRIPTION("TVP514X linux decoder driver");
58 MODULE_LICENSE("GPL");
60 /* enum tvp514x_std - enum for supported standards */
61 enum tvp514x_std {
62 STD_NTSC_MJ = 0,
63 STD_PAL_BDGHIN,
64 STD_INVALID
67 /**
68 * struct tvp514x_std_info - Structure to store standard informations
69 * @width: Line width in pixels
70 * @height:Number of active lines
71 * @video_std: Value to write in REG_VIDEO_STD register
72 * @standard: v4l2 standard structure information
74 struct tvp514x_std_info {
75 unsigned long width;
76 unsigned long height;
77 u8 video_std;
78 struct v4l2_standard standard;
81 static struct tvp514x_reg tvp514x_reg_list_default[0x40];
82 /**
83 * struct tvp514x_decoder - TVP5146/47 decoder object
84 * @sd: Subdevice Slave handle
85 * @tvp514x_regs: copy of hw's regs with preset values.
86 * @pdata: Board specific
87 * @ver: Chip version
88 * @streaming: TVP5146/47 decoder streaming - enabled or disabled.
89 * @pix: Current pixel format
90 * @num_fmts: Number of formats
91 * @fmt_list: Format list
92 * @current_std: Current standard
93 * @num_stds: Number of standards
94 * @std_list: Standards list
95 * @input: Input routing at chip level
96 * @output: Output routing at chip level
98 struct tvp514x_decoder {
99 struct v4l2_subdev sd;
100 struct tvp514x_reg tvp514x_regs[ARRAY_SIZE(tvp514x_reg_list_default)];
101 const struct tvp514x_platform_data *pdata;
103 int ver;
104 int streaming;
106 struct v4l2_pix_format pix;
107 int num_fmts;
108 const struct v4l2_fmtdesc *fmt_list;
110 enum tvp514x_std current_std;
111 int num_stds;
112 struct tvp514x_std_info *std_list;
113 /* Input and Output Routing parameters */
114 u32 input;
115 u32 output;
118 /* TVP514x default register values */
119 static struct tvp514x_reg tvp514x_reg_list_default[] = {
120 /* Composite selected */
121 {TOK_WRITE, REG_INPUT_SEL, 0x05},
122 {TOK_WRITE, REG_AFE_GAIN_CTRL, 0x0F},
123 /* Auto mode */
124 {TOK_WRITE, REG_VIDEO_STD, 0x00},
125 {TOK_WRITE, REG_OPERATION_MODE, 0x00},
126 {TOK_SKIP, REG_AUTOSWITCH_MASK, 0x3F},
127 {TOK_WRITE, REG_COLOR_KILLER, 0x10},
128 {TOK_WRITE, REG_LUMA_CONTROL1, 0x00},
129 {TOK_WRITE, REG_LUMA_CONTROL2, 0x00},
130 {TOK_WRITE, REG_LUMA_CONTROL3, 0x02},
131 {TOK_WRITE, REG_BRIGHTNESS, 0x80},
132 {TOK_WRITE, REG_CONTRAST, 0x80},
133 {TOK_WRITE, REG_SATURATION, 0x80},
134 {TOK_WRITE, REG_HUE, 0x00},
135 {TOK_WRITE, REG_CHROMA_CONTROL1, 0x00},
136 {TOK_WRITE, REG_CHROMA_CONTROL2, 0x0E},
137 /* Reserved */
138 {TOK_SKIP, 0x0F, 0x00},
139 {TOK_WRITE, REG_COMP_PR_SATURATION, 0x80},
140 {TOK_WRITE, REG_COMP_Y_CONTRAST, 0x80},
141 {TOK_WRITE, REG_COMP_PB_SATURATION, 0x80},
142 /* Reserved */
143 {TOK_SKIP, 0x13, 0x00},
144 {TOK_WRITE, REG_COMP_Y_BRIGHTNESS, 0x80},
145 /* Reserved */
146 {TOK_SKIP, 0x15, 0x00},
147 /* NTSC timing */
148 {TOK_SKIP, REG_AVID_START_PIXEL_LSB, 0x55},
149 {TOK_SKIP, REG_AVID_START_PIXEL_MSB, 0x00},
150 {TOK_SKIP, REG_AVID_STOP_PIXEL_LSB, 0x25},
151 {TOK_SKIP, REG_AVID_STOP_PIXEL_MSB, 0x03},
152 /* NTSC timing */
153 {TOK_SKIP, REG_HSYNC_START_PIXEL_LSB, 0x00},
154 {TOK_SKIP, REG_HSYNC_START_PIXEL_MSB, 0x00},
155 {TOK_SKIP, REG_HSYNC_STOP_PIXEL_LSB, 0x40},
156 {TOK_SKIP, REG_HSYNC_STOP_PIXEL_MSB, 0x00},
157 /* NTSC timing */
158 {TOK_SKIP, REG_VSYNC_START_LINE_LSB, 0x04},
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 /* NTSC timing */
163 {TOK_SKIP, REG_VBLK_START_LINE_LSB, 0x01},
164 {TOK_SKIP, REG_VBLK_START_LINE_MSB, 0x00},
165 {TOK_SKIP, REG_VBLK_STOP_LINE_LSB, 0x15},
166 {TOK_SKIP, REG_VBLK_STOP_LINE_MSB, 0x00},
167 /* Reserved */
168 {TOK_SKIP, 0x26, 0x00},
169 /* Reserved */
170 {TOK_SKIP, 0x27, 0x00},
171 {TOK_SKIP, REG_FAST_SWTICH_CONTROL, 0xCC},
172 /* Reserved */
173 {TOK_SKIP, 0x29, 0x00},
174 {TOK_SKIP, REG_FAST_SWTICH_SCART_DELAY, 0x00},
175 /* Reserved */
176 {TOK_SKIP, 0x2B, 0x00},
177 {TOK_SKIP, REG_SCART_DELAY, 0x00},
178 {TOK_SKIP, REG_CTI_DELAY, 0x00},
179 {TOK_SKIP, REG_CTI_CONTROL, 0x00},
180 /* Reserved */
181 {TOK_SKIP, 0x2F, 0x00},
182 /* Reserved */
183 {TOK_SKIP, 0x30, 0x00},
184 /* Reserved */
185 {TOK_SKIP, 0x31, 0x00},
186 /* HS, VS active high */
187 {TOK_WRITE, REG_SYNC_CONTROL, 0x00},
188 /* 10-bit BT.656 */
189 {TOK_WRITE, REG_OUTPUT_FORMATTER1, 0x00},
190 /* Enable clk & data */
191 {TOK_WRITE, REG_OUTPUT_FORMATTER2, 0x11},
192 /* Enable AVID & FLD */
193 {TOK_WRITE, REG_OUTPUT_FORMATTER3, 0xEE},
194 /* Enable VS & HS */
195 {TOK_WRITE, REG_OUTPUT_FORMATTER4, 0xAF},
196 {TOK_WRITE, REG_OUTPUT_FORMATTER5, 0xFF},
197 {TOK_WRITE, REG_OUTPUT_FORMATTER6, 0xFF},
198 /* Clear status */
199 {TOK_WRITE, REG_CLEAR_LOST_LOCK, 0x01},
200 {TOK_TERM, 0, 0},
204 * List of image formats supported by TVP5146/47 decoder
205 * Currently we are using 8 bit mode only, but can be
206 * extended to 10/20 bit mode.
208 static const struct v4l2_fmtdesc tvp514x_fmt_list[] = {
210 .index = 0,
211 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
212 .flags = 0,
213 .description = "8-bit UYVY 4:2:2 Format",
214 .pixelformat = V4L2_PIX_FMT_UYVY,
219 * Supported standards -
221 * Currently supports two standards only, need to add support for rest of the
222 * modes, like SECAM, etc...
224 static struct tvp514x_std_info tvp514x_std_list[] = {
225 /* Standard: STD_NTSC_MJ */
226 [STD_NTSC_MJ] = {
227 .width = NTSC_NUM_ACTIVE_PIXELS,
228 .height = NTSC_NUM_ACTIVE_LINES,
229 .video_std = VIDEO_STD_NTSC_MJ_BIT,
230 .standard = {
231 .index = 0,
232 .id = V4L2_STD_NTSC,
233 .name = "NTSC",
234 .frameperiod = {1001, 30000},
235 .framelines = 525
237 /* Standard: STD_PAL_BDGHIN */
239 [STD_PAL_BDGHIN] = {
240 .width = PAL_NUM_ACTIVE_PIXELS,
241 .height = PAL_NUM_ACTIVE_LINES,
242 .video_std = VIDEO_STD_PAL_BDGHIN_BIT,
243 .standard = {
244 .index = 1,
245 .id = V4L2_STD_PAL,
246 .name = "PAL",
247 .frameperiod = {1, 25},
248 .framelines = 625
251 /* Standard: need to add for additional standard */
255 static inline struct tvp514x_decoder *to_decoder(struct v4l2_subdev *sd)
257 return container_of(sd, struct tvp514x_decoder, sd);
262 * tvp514x_read_reg() - Read a value from a register in an TVP5146/47.
263 * @sd: ptr to v4l2_subdev struct
264 * @reg: TVP5146/47 register address
266 * Returns value read if successful, or non-zero (-1) otherwise.
268 static int tvp514x_read_reg(struct v4l2_subdev *sd, u8 reg)
270 int err, retry = 0;
271 struct i2c_client *client = v4l2_get_subdevdata(sd);
273 read_again:
275 err = i2c_smbus_read_byte_data(client, reg);
276 if (err < 0) {
277 if (retry <= I2C_RETRY_COUNT) {
278 v4l2_warn(sd, "Read: retry ... %d\n", retry);
279 retry++;
280 msleep_interruptible(10);
281 goto read_again;
285 return err;
289 * dump_reg() - dump the register content of TVP5146/47.
290 * @sd: ptr to v4l2_subdev struct
291 * @reg: TVP5146/47 register address
293 static void dump_reg(struct v4l2_subdev *sd, u8 reg)
295 u32 val;
297 val = tvp514x_read_reg(sd, reg);
298 v4l2_info(sd, "Reg(0x%.2X): 0x%.2X\n", reg, val);
302 * tvp514x_write_reg() - Write a value to a register in TVP5146/47
303 * @sd: ptr to v4l2_subdev struct
304 * @reg: TVP5146/47 register address
305 * @val: value to be written to the register
307 * Write a value to a register in an TVP5146/47 decoder device.
308 * Returns zero if successful, or non-zero otherwise.
310 static int tvp514x_write_reg(struct v4l2_subdev *sd, u8 reg, u8 val)
312 int err, retry = 0;
313 struct i2c_client *client = v4l2_get_subdevdata(sd);
315 write_again:
317 err = i2c_smbus_write_byte_data(client, reg, val);
318 if (err) {
319 if (retry <= I2C_RETRY_COUNT) {
320 v4l2_warn(sd, "Write: retry ... %d\n", retry);
321 retry++;
322 msleep_interruptible(10);
323 goto write_again;
327 return err;
331 * tvp514x_write_regs() : Initializes a list of TVP5146/47 registers
332 * @sd: ptr to v4l2_subdev struct
333 * @reglist: list of TVP5146/47 registers and values
335 * Initializes a list of TVP5146/47 registers:-
336 * if token is TOK_TERM, then entire write operation terminates
337 * if token is TOK_DELAY, then a delay of 'val' msec is introduced
338 * if token is TOK_SKIP, then the register write is skipped
339 * if token is TOK_WRITE, then the register write is performed
340 * Returns zero if successful, or non-zero otherwise.
342 static int tvp514x_write_regs(struct v4l2_subdev *sd,
343 const struct tvp514x_reg reglist[])
345 int err;
346 const struct tvp514x_reg *next = reglist;
348 for (; next->token != TOK_TERM; next++) {
349 if (next->token == TOK_DELAY) {
350 msleep(next->val);
351 continue;
354 if (next->token == TOK_SKIP)
355 continue;
357 err = tvp514x_write_reg(sd, next->reg, (u8) next->val);
358 if (err) {
359 v4l2_err(sd, "Write failed. Err[%d]\n", err);
360 return err;
363 return 0;
367 * tvp514x_get_current_std() : Get the current standard detected by TVP5146/47
368 * @sd: ptr to v4l2_subdev struct
370 * Get current standard detected by TVP5146/47, STD_INVALID if there is no
371 * standard detected.
373 static enum tvp514x_std tvp514x_get_current_std(struct v4l2_subdev *sd)
375 u8 std, std_status;
377 std = tvp514x_read_reg(sd, REG_VIDEO_STD);
378 if ((std & VIDEO_STD_MASK) == VIDEO_STD_AUTO_SWITCH_BIT)
379 /* use the standard status register */
380 std_status = tvp514x_read_reg(sd, REG_VIDEO_STD_STATUS);
381 else
382 /* use the standard register itself */
383 std_status = std;
385 switch (std_status & VIDEO_STD_MASK) {
386 case VIDEO_STD_NTSC_MJ_BIT:
387 return STD_NTSC_MJ;
389 case VIDEO_STD_PAL_BDGHIN_BIT:
390 return STD_PAL_BDGHIN;
392 default:
393 return STD_INVALID;
396 return STD_INVALID;
399 /* TVP5146/47 register dump function */
400 static void tvp514x_reg_dump(struct v4l2_subdev *sd)
402 dump_reg(sd, REG_INPUT_SEL);
403 dump_reg(sd, REG_AFE_GAIN_CTRL);
404 dump_reg(sd, REG_VIDEO_STD);
405 dump_reg(sd, REG_OPERATION_MODE);
406 dump_reg(sd, REG_COLOR_KILLER);
407 dump_reg(sd, REG_LUMA_CONTROL1);
408 dump_reg(sd, REG_LUMA_CONTROL2);
409 dump_reg(sd, REG_LUMA_CONTROL3);
410 dump_reg(sd, REG_BRIGHTNESS);
411 dump_reg(sd, REG_CONTRAST);
412 dump_reg(sd, REG_SATURATION);
413 dump_reg(sd, REG_HUE);
414 dump_reg(sd, REG_CHROMA_CONTROL1);
415 dump_reg(sd, REG_CHROMA_CONTROL2);
416 dump_reg(sd, REG_COMP_PR_SATURATION);
417 dump_reg(sd, REG_COMP_Y_CONTRAST);
418 dump_reg(sd, REG_COMP_PB_SATURATION);
419 dump_reg(sd, REG_COMP_Y_BRIGHTNESS);
420 dump_reg(sd, REG_AVID_START_PIXEL_LSB);
421 dump_reg(sd, REG_AVID_START_PIXEL_MSB);
422 dump_reg(sd, REG_AVID_STOP_PIXEL_LSB);
423 dump_reg(sd, REG_AVID_STOP_PIXEL_MSB);
424 dump_reg(sd, REG_HSYNC_START_PIXEL_LSB);
425 dump_reg(sd, REG_HSYNC_START_PIXEL_MSB);
426 dump_reg(sd, REG_HSYNC_STOP_PIXEL_LSB);
427 dump_reg(sd, REG_HSYNC_STOP_PIXEL_MSB);
428 dump_reg(sd, REG_VSYNC_START_LINE_LSB);
429 dump_reg(sd, REG_VSYNC_START_LINE_MSB);
430 dump_reg(sd, REG_VSYNC_STOP_LINE_LSB);
431 dump_reg(sd, REG_VSYNC_STOP_LINE_MSB);
432 dump_reg(sd, REG_VBLK_START_LINE_LSB);
433 dump_reg(sd, REG_VBLK_START_LINE_MSB);
434 dump_reg(sd, REG_VBLK_STOP_LINE_LSB);
435 dump_reg(sd, REG_VBLK_STOP_LINE_MSB);
436 dump_reg(sd, REG_SYNC_CONTROL);
437 dump_reg(sd, REG_OUTPUT_FORMATTER1);
438 dump_reg(sd, REG_OUTPUT_FORMATTER2);
439 dump_reg(sd, REG_OUTPUT_FORMATTER3);
440 dump_reg(sd, REG_OUTPUT_FORMATTER4);
441 dump_reg(sd, REG_OUTPUT_FORMATTER5);
442 dump_reg(sd, REG_OUTPUT_FORMATTER6);
443 dump_reg(sd, REG_CLEAR_LOST_LOCK);
447 * tvp514x_configure() - Configure the TVP5146/47 registers
448 * @sd: ptr to v4l2_subdev struct
449 * @decoder: ptr to tvp514x_decoder structure
451 * Returns zero if successful, or non-zero otherwise.
453 static int tvp514x_configure(struct v4l2_subdev *sd,
454 struct tvp514x_decoder *decoder)
456 int err;
458 /* common register initialization */
459 err =
460 tvp514x_write_regs(sd, decoder->tvp514x_regs);
461 if (err)
462 return err;
464 if (debug)
465 tvp514x_reg_dump(sd);
467 return 0;
471 * tvp514x_detect() - Detect if an tvp514x is present, and if so which revision.
472 * @sd: pointer to standard V4L2 sub-device structure
473 * @decoder: pointer to tvp514x_decoder structure
475 * A device is considered to be detected if the chip ID (LSB and MSB)
476 * registers match the expected values.
477 * Any value of the rom version register is accepted.
478 * Returns ENODEV error number if no device is detected, or zero
479 * if a device is detected.
481 static int tvp514x_detect(struct v4l2_subdev *sd,
482 struct tvp514x_decoder *decoder)
484 u8 chip_id_msb, chip_id_lsb, rom_ver;
485 struct i2c_client *client = v4l2_get_subdevdata(sd);
487 chip_id_msb = tvp514x_read_reg(sd, REG_CHIP_ID_MSB);
488 chip_id_lsb = tvp514x_read_reg(sd, REG_CHIP_ID_LSB);
489 rom_ver = tvp514x_read_reg(sd, REG_ROM_VERSION);
491 v4l2_dbg(1, debug, sd,
492 "chip id detected msb:0x%x lsb:0x%x rom version:0x%x\n",
493 chip_id_msb, chip_id_lsb, rom_ver);
494 if ((chip_id_msb != TVP514X_CHIP_ID_MSB)
495 || ((chip_id_lsb != TVP5146_CHIP_ID_LSB)
496 && (chip_id_lsb != TVP5147_CHIP_ID_LSB))) {
497 /* We didn't read the values we expected, so this must not be
498 * an TVP5146/47.
500 v4l2_err(sd, "chip id mismatch msb:0x%x lsb:0x%x\n",
501 chip_id_msb, chip_id_lsb);
502 return -ENODEV;
505 decoder->ver = rom_ver;
507 v4l2_info(sd, "%s (Version - 0x%.2x) found at 0x%x (%s)\n",
508 client->name, decoder->ver,
509 client->addr << 1, client->adapter->name);
510 return 0;
514 * tvp514x_querystd() - V4L2 decoder interface handler for querystd
515 * @sd: pointer to standard V4L2 sub-device structure
516 * @std_id: standard V4L2 std_id ioctl enum
518 * Returns the current standard detected by TVP5146/47. If no active input is
519 * detected, returns -EINVAL
521 static int tvp514x_querystd(struct v4l2_subdev *sd, v4l2_std_id *std_id)
523 struct tvp514x_decoder *decoder = to_decoder(sd);
524 enum tvp514x_std current_std;
525 enum tvp514x_input input_sel;
526 u8 sync_lock_status, lock_mask;
528 if (std_id == NULL)
529 return -EINVAL;
531 /* get the current standard */
532 current_std = tvp514x_get_current_std(sd);
533 if (current_std == STD_INVALID)
534 return -EINVAL;
536 input_sel = decoder->input;
538 switch (input_sel) {
539 case INPUT_CVBS_VI1A:
540 case INPUT_CVBS_VI1B:
541 case INPUT_CVBS_VI1C:
542 case INPUT_CVBS_VI2A:
543 case INPUT_CVBS_VI2B:
544 case INPUT_CVBS_VI2C:
545 case INPUT_CVBS_VI3A:
546 case INPUT_CVBS_VI3B:
547 case INPUT_CVBS_VI3C:
548 case INPUT_CVBS_VI4A:
549 lock_mask = STATUS_CLR_SUBCAR_LOCK_BIT |
550 STATUS_HORZ_SYNC_LOCK_BIT |
551 STATUS_VIRT_SYNC_LOCK_BIT;
552 break;
554 case INPUT_SVIDEO_VI2A_VI1A:
555 case INPUT_SVIDEO_VI2B_VI1B:
556 case INPUT_SVIDEO_VI2C_VI1C:
557 case INPUT_SVIDEO_VI2A_VI3A:
558 case INPUT_SVIDEO_VI2B_VI3B:
559 case INPUT_SVIDEO_VI2C_VI3C:
560 case INPUT_SVIDEO_VI4A_VI1A:
561 case INPUT_SVIDEO_VI4A_VI1B:
562 case INPUT_SVIDEO_VI4A_VI1C:
563 case INPUT_SVIDEO_VI4A_VI3A:
564 case INPUT_SVIDEO_VI4A_VI3B:
565 case INPUT_SVIDEO_VI4A_VI3C:
566 lock_mask = STATUS_HORZ_SYNC_LOCK_BIT |
567 STATUS_VIRT_SYNC_LOCK_BIT;
568 break;
569 /*Need to add other interfaces*/
570 default:
571 return -EINVAL;
573 /* check whether signal is locked */
574 sync_lock_status = tvp514x_read_reg(sd, REG_STATUS1);
575 if (lock_mask != (sync_lock_status & lock_mask))
576 return -EINVAL; /* No input detected */
578 decoder->current_std = current_std;
579 *std_id = decoder->std_list[current_std].standard.id;
581 v4l2_dbg(1, debug, sd, "Current STD: %s",
582 decoder->std_list[current_std].standard.name);
583 return 0;
587 * tvp514x_s_std() - V4L2 decoder interface handler for s_std
588 * @sd: pointer to standard V4L2 sub-device structure
589 * @std_id: standard V4L2 v4l2_std_id ioctl enum
591 * If std_id is supported, sets the requested standard. Otherwise, returns
592 * -EINVAL
594 static int tvp514x_s_std(struct v4l2_subdev *sd, v4l2_std_id std_id)
596 struct tvp514x_decoder *decoder = to_decoder(sd);
597 int err, i;
599 for (i = 0; i < decoder->num_stds; i++)
600 if (std_id & decoder->std_list[i].standard.id)
601 break;
603 if ((i == decoder->num_stds) || (i == STD_INVALID))
604 return -EINVAL;
606 err = tvp514x_write_reg(sd, REG_VIDEO_STD,
607 decoder->std_list[i].video_std);
608 if (err)
609 return err;
611 decoder->current_std = i;
612 decoder->tvp514x_regs[REG_VIDEO_STD].val =
613 decoder->std_list[i].video_std;
615 v4l2_dbg(1, debug, sd, "Standard set to: %s",
616 decoder->std_list[i].standard.name);
617 return 0;
621 * tvp514x_s_routing() - V4L2 decoder interface handler for s_routing
622 * @sd: pointer to standard V4L2 sub-device structure
623 * @input: input selector for routing the signal
624 * @output: output selector for routing the signal
625 * @config: config value. Not used
627 * If index is valid, selects the requested input. Otherwise, returns -EINVAL if
628 * the input is not supported or there is no active signal present in the
629 * selected input.
631 static int tvp514x_s_routing(struct v4l2_subdev *sd,
632 u32 input, u32 output, u32 config)
634 struct tvp514x_decoder *decoder = to_decoder(sd);
635 int err;
636 enum tvp514x_input input_sel;
637 enum tvp514x_output output_sel;
638 enum tvp514x_std current_std = STD_INVALID;
639 u8 sync_lock_status, lock_mask;
640 int try_count = LOCK_RETRY_COUNT;
642 if ((input >= INPUT_INVALID) ||
643 (output >= OUTPUT_INVALID))
644 /* Index out of bound */
645 return -EINVAL;
647 input_sel = input;
648 output_sel = output;
650 err = tvp514x_write_reg(sd, REG_INPUT_SEL, input_sel);
651 if (err)
652 return err;
654 output_sel |= tvp514x_read_reg(sd,
655 REG_OUTPUT_FORMATTER1) & 0x7;
656 err = tvp514x_write_reg(sd, REG_OUTPUT_FORMATTER1,
657 output_sel);
658 if (err)
659 return err;
661 decoder->tvp514x_regs[REG_INPUT_SEL].val = input_sel;
662 decoder->tvp514x_regs[REG_OUTPUT_FORMATTER1].val = output_sel;
664 /* Clear status */
665 msleep(LOCK_RETRY_DELAY);
666 err =
667 tvp514x_write_reg(sd, REG_CLEAR_LOST_LOCK, 0x01);
668 if (err)
669 return err;
671 switch (input_sel) {
672 case INPUT_CVBS_VI1A:
673 case INPUT_CVBS_VI1B:
674 case INPUT_CVBS_VI1C:
675 case INPUT_CVBS_VI2A:
676 case INPUT_CVBS_VI2B:
677 case INPUT_CVBS_VI2C:
678 case INPUT_CVBS_VI3A:
679 case INPUT_CVBS_VI3B:
680 case INPUT_CVBS_VI3C:
681 case INPUT_CVBS_VI4A:
682 lock_mask = STATUS_CLR_SUBCAR_LOCK_BIT |
683 STATUS_HORZ_SYNC_LOCK_BIT |
684 STATUS_VIRT_SYNC_LOCK_BIT;
685 break;
687 case INPUT_SVIDEO_VI2A_VI1A:
688 case INPUT_SVIDEO_VI2B_VI1B:
689 case INPUT_SVIDEO_VI2C_VI1C:
690 case INPUT_SVIDEO_VI2A_VI3A:
691 case INPUT_SVIDEO_VI2B_VI3B:
692 case INPUT_SVIDEO_VI2C_VI3C:
693 case INPUT_SVIDEO_VI4A_VI1A:
694 case INPUT_SVIDEO_VI4A_VI1B:
695 case INPUT_SVIDEO_VI4A_VI1C:
696 case INPUT_SVIDEO_VI4A_VI3A:
697 case INPUT_SVIDEO_VI4A_VI3B:
698 case INPUT_SVIDEO_VI4A_VI3C:
699 lock_mask = STATUS_HORZ_SYNC_LOCK_BIT |
700 STATUS_VIRT_SYNC_LOCK_BIT;
701 break;
702 /* Need to add other interfaces*/
703 default:
704 return -EINVAL;
707 while (try_count-- > 0) {
708 /* Allow decoder to sync up with new input */
709 msleep(LOCK_RETRY_DELAY);
711 /* get the current standard for future reference */
712 current_std = tvp514x_get_current_std(sd);
713 if (current_std == STD_INVALID)
714 continue;
716 sync_lock_status = tvp514x_read_reg(sd,
717 REG_STATUS1);
718 if (lock_mask == (sync_lock_status & lock_mask))
719 /* Input detected */
720 break;
723 if ((current_std == STD_INVALID) || (try_count < 0))
724 return -EINVAL;
726 decoder->current_std = current_std;
727 decoder->input = input;
728 decoder->output = output;
730 v4l2_dbg(1, debug, sd, "Input set to: %d, std : %d",
731 input_sel, current_std);
733 return 0;
737 * tvp514x_queryctrl() - V4L2 decoder interface handler for queryctrl
738 * @sd: pointer to standard V4L2 sub-device structure
739 * @qctrl: standard V4L2 v4l2_queryctrl structure
741 * If the requested control is supported, returns the control information.
742 * Otherwise, returns -EINVAL if the control is not supported.
744 static int
745 tvp514x_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qctrl)
747 int err = -EINVAL;
749 if (qctrl == NULL)
750 return err;
752 switch (qctrl->id) {
753 case V4L2_CID_BRIGHTNESS:
754 /* Brightness supported is (0-255), */
755 err = v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 128);
756 break;
757 case V4L2_CID_CONTRAST:
758 case V4L2_CID_SATURATION:
760 * Saturation and Contrast supported is -
761 * Contrast: 0 - 255 (Default - 128)
762 * Saturation: 0 - 255 (Default - 128)
764 err = v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 128);
765 break;
766 case V4L2_CID_HUE:
767 /* Hue Supported is -
768 * Hue - -180 - +180 (Default - 0, Step - +180)
770 err = v4l2_ctrl_query_fill(qctrl, -180, 180, 180, 0);
771 break;
772 case V4L2_CID_AUTOGAIN:
774 * Auto Gain supported is -
775 * 0 - 1 (Default - 1)
777 err = v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 1);
778 break;
779 default:
780 v4l2_err(sd, "invalid control id %d\n", qctrl->id);
781 return err;
784 v4l2_dbg(1, debug, sd, "Query Control:%s: Min - %d, Max - %d, Def - %d",
785 qctrl->name, qctrl->minimum, qctrl->maximum,
786 qctrl->default_value);
788 return err;
792 * tvp514x_g_ctrl() - V4L2 decoder interface handler for g_ctrl
793 * @sd: pointer to standard V4L2 sub-device structure
794 * @ctrl: pointer to v4l2_control structure
796 * If the requested control is supported, returns the control's current
797 * value from the decoder. Otherwise, returns -EINVAL if the control is not
798 * supported.
800 static int
801 tvp514x_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
803 struct tvp514x_decoder *decoder = to_decoder(sd);
805 if (ctrl == NULL)
806 return -EINVAL;
808 switch (ctrl->id) {
809 case V4L2_CID_BRIGHTNESS:
810 ctrl->value = decoder->tvp514x_regs[REG_BRIGHTNESS].val;
811 break;
812 case V4L2_CID_CONTRAST:
813 ctrl->value = decoder->tvp514x_regs[REG_CONTRAST].val;
814 break;
815 case V4L2_CID_SATURATION:
816 ctrl->value = decoder->tvp514x_regs[REG_SATURATION].val;
817 break;
818 case V4L2_CID_HUE:
819 ctrl->value = decoder->tvp514x_regs[REG_HUE].val;
820 if (ctrl->value == 0x7F)
821 ctrl->value = 180;
822 else if (ctrl->value == 0x80)
823 ctrl->value = -180;
824 else
825 ctrl->value = 0;
827 break;
828 case V4L2_CID_AUTOGAIN:
829 ctrl->value = decoder->tvp514x_regs[REG_AFE_GAIN_CTRL].val;
830 if ((ctrl->value & 0x3) == 3)
831 ctrl->value = 1;
832 else
833 ctrl->value = 0;
835 break;
836 default:
837 v4l2_err(sd, "invalid control id %d\n", ctrl->id);
838 return -EINVAL;
841 v4l2_dbg(1, debug, sd, "Get Control: ID - %d - %d",
842 ctrl->id, ctrl->value);
843 return 0;
847 * tvp514x_s_ctrl() - V4L2 decoder interface handler for s_ctrl
848 * @sd: pointer to standard V4L2 sub-device structure
849 * @ctrl: pointer to v4l2_control structure
851 * If the requested control is supported, sets the control's current
852 * value in HW. Otherwise, returns -EINVAL if the control is not supported.
854 static int
855 tvp514x_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
857 struct tvp514x_decoder *decoder = to_decoder(sd);
858 int err = -EINVAL, value;
860 if (ctrl == NULL)
861 return err;
863 value = ctrl->value;
865 switch (ctrl->id) {
866 case V4L2_CID_BRIGHTNESS:
867 if (ctrl->value < 0 || ctrl->value > 255) {
868 v4l2_err(sd, "invalid brightness setting %d\n",
869 ctrl->value);
870 return -ERANGE;
872 err = tvp514x_write_reg(sd, REG_BRIGHTNESS,
873 value);
874 if (err)
875 return err;
877 decoder->tvp514x_regs[REG_BRIGHTNESS].val = value;
878 break;
879 case V4L2_CID_CONTRAST:
880 if (ctrl->value < 0 || ctrl->value > 255) {
881 v4l2_err(sd, "invalid contrast setting %d\n",
882 ctrl->value);
883 return -ERANGE;
885 err = tvp514x_write_reg(sd, REG_CONTRAST, value);
886 if (err)
887 return err;
889 decoder->tvp514x_regs[REG_CONTRAST].val = value;
890 break;
891 case V4L2_CID_SATURATION:
892 if (ctrl->value < 0 || ctrl->value > 255) {
893 v4l2_err(sd, "invalid saturation setting %d\n",
894 ctrl->value);
895 return -ERANGE;
897 err = tvp514x_write_reg(sd, REG_SATURATION, value);
898 if (err)
899 return err;
901 decoder->tvp514x_regs[REG_SATURATION].val = value;
902 break;
903 case V4L2_CID_HUE:
904 if (value == 180)
905 value = 0x7F;
906 else if (value == -180)
907 value = 0x80;
908 else if (value == 0)
909 value = 0;
910 else {
911 v4l2_err(sd, "invalid hue setting %d\n", ctrl->value);
912 return -ERANGE;
914 err = tvp514x_write_reg(sd, REG_HUE, value);
915 if (err)
916 return err;
918 decoder->tvp514x_regs[REG_HUE].val = value;
919 break;
920 case V4L2_CID_AUTOGAIN:
921 if (value == 1)
922 value = 0x0F;
923 else if (value == 0)
924 value = 0x0C;
925 else {
926 v4l2_err(sd, "invalid auto gain setting %d\n",
927 ctrl->value);
928 return -ERANGE;
930 err = tvp514x_write_reg(sd, REG_AFE_GAIN_CTRL, value);
931 if (err)
932 return err;
934 decoder->tvp514x_regs[REG_AFE_GAIN_CTRL].val = value;
935 break;
936 default:
937 v4l2_err(sd, "invalid control id %d\n", ctrl->id);
938 return err;
941 v4l2_dbg(1, debug, sd, "Set Control: ID - %d - %d",
942 ctrl->id, ctrl->value);
944 return err;
948 * tvp514x_enum_fmt_cap() - V4L2 decoder interface handler for enum_fmt
949 * @sd: pointer to standard V4L2 sub-device structure
950 * @fmt: standard V4L2 VIDIOC_ENUM_FMT ioctl structure
952 * Implement the VIDIOC_ENUM_FMT ioctl to enumerate supported formats
954 static int
955 tvp514x_enum_fmt_cap(struct v4l2_subdev *sd, struct v4l2_fmtdesc *fmt)
957 struct tvp514x_decoder *decoder = to_decoder(sd);
958 int index;
960 if (fmt == NULL)
961 return -EINVAL;
963 index = fmt->index;
964 if ((index >= decoder->num_fmts) || (index < 0))
965 /* Index out of bound */
966 return -EINVAL;
968 if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
969 /* only capture is supported */
970 return -EINVAL;
972 memcpy(fmt, &decoder->fmt_list[index],
973 sizeof(struct v4l2_fmtdesc));
975 v4l2_dbg(1, debug, sd, "Current FMT: index - %d (%s)",
976 decoder->fmt_list[index].index,
977 decoder->fmt_list[index].description);
978 return 0;
982 * tvp514x_try_fmt_cap() - V4L2 decoder interface handler for try_fmt
983 * @sd: pointer to standard V4L2 sub-device structure
984 * @f: pointer to standard V4L2 VIDIOC_TRY_FMT ioctl structure
986 * Implement the VIDIOC_TRY_FMT ioctl for the CAPTURE buffer type. This
987 * ioctl is used to negotiate the image capture size and pixel format
988 * without actually making it take effect.
990 static int
991 tvp514x_try_fmt_cap(struct v4l2_subdev *sd, struct v4l2_format *f)
993 struct tvp514x_decoder *decoder = to_decoder(sd);
994 int ifmt;
995 struct v4l2_pix_format *pix;
996 enum tvp514x_std current_std;
998 if (f == NULL)
999 return -EINVAL;
1001 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1002 /* only capture is supported */
1003 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1005 pix = &f->fmt.pix;
1007 /* Calculate height and width based on current standard */
1008 current_std = tvp514x_get_current_std(sd);
1009 if (current_std == STD_INVALID)
1010 return -EINVAL;
1012 decoder->current_std = current_std;
1013 pix->width = decoder->std_list[current_std].width;
1014 pix->height = decoder->std_list[current_std].height;
1016 for (ifmt = 0; ifmt < decoder->num_fmts; ifmt++) {
1017 if (pix->pixelformat ==
1018 decoder->fmt_list[ifmt].pixelformat)
1019 break;
1021 if (ifmt == decoder->num_fmts)
1022 /* None of the format matched, select default */
1023 ifmt = 0;
1024 pix->pixelformat = decoder->fmt_list[ifmt].pixelformat;
1026 pix->field = V4L2_FIELD_INTERLACED;
1027 pix->bytesperline = pix->width * 2;
1028 pix->sizeimage = pix->bytesperline * pix->height;
1029 pix->colorspace = V4L2_COLORSPACE_SMPTE170M;
1030 pix->priv = 0;
1032 v4l2_dbg(1, debug, sd, "Try FMT: pixelformat - %s, bytesperline - %d"
1033 "Width - %d, Height - %d",
1034 decoder->fmt_list[ifmt].description, pix->bytesperline,
1035 pix->width, pix->height);
1036 return 0;
1040 * tvp514x_s_fmt_cap() - V4L2 decoder interface handler for s_fmt
1041 * @sd: pointer to standard V4L2 sub-device structure
1042 * @f: pointer to standard V4L2 VIDIOC_S_FMT ioctl structure
1044 * If the requested format is supported, configures the HW to use that
1045 * format, returns error code if format not supported or HW can't be
1046 * correctly configured.
1048 static int
1049 tvp514x_s_fmt_cap(struct v4l2_subdev *sd, struct v4l2_format *f)
1051 struct tvp514x_decoder *decoder = to_decoder(sd);
1052 struct v4l2_pix_format *pix;
1053 int rval;
1055 if (f == NULL)
1056 return -EINVAL;
1058 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1059 /* only capture is supported */
1060 return -EINVAL;
1062 pix = &f->fmt.pix;
1063 rval = tvp514x_try_fmt_cap(sd, f);
1064 if (rval)
1065 return rval;
1067 decoder->pix = *pix;
1069 return rval;
1073 * tvp514x_g_fmt_cap() - V4L2 decoder interface handler for tvp514x_g_fmt_cap
1074 * @sd: pointer to standard V4L2 sub-device structure
1075 * @f: pointer to standard V4L2 v4l2_format structure
1077 * Returns the decoder's current pixel format in the v4l2_format
1078 * parameter.
1080 static int
1081 tvp514x_g_fmt_cap(struct v4l2_subdev *sd, struct v4l2_format *f)
1083 struct tvp514x_decoder *decoder = to_decoder(sd);
1085 if (f == NULL)
1086 return -EINVAL;
1088 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1089 /* only capture is supported */
1090 return -EINVAL;
1092 f->fmt.pix = decoder->pix;
1094 v4l2_dbg(1, debug, sd, "Current FMT: bytesperline - %d"
1095 "Width - %d, Height - %d",
1096 decoder->pix.bytesperline,
1097 decoder->pix.width, decoder->pix.height);
1098 return 0;
1102 * tvp514x_g_parm() - V4L2 decoder interface handler for g_parm
1103 * @sd: pointer to standard V4L2 sub-device structure
1104 * @a: pointer to standard V4L2 VIDIOC_G_PARM ioctl structure
1106 * Returns the decoder's video CAPTURE parameters.
1108 static int
1109 tvp514x_g_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *a)
1111 struct tvp514x_decoder *decoder = to_decoder(sd);
1112 struct v4l2_captureparm *cparm;
1113 enum tvp514x_std current_std;
1115 if (a == NULL)
1116 return -EINVAL;
1118 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1119 /* only capture is supported */
1120 return -EINVAL;
1122 memset(a, 0, sizeof(*a));
1123 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1125 /* get the current standard */
1126 current_std = tvp514x_get_current_std(sd);
1127 if (current_std == STD_INVALID)
1128 return -EINVAL;
1130 decoder->current_std = current_std;
1132 cparm = &a->parm.capture;
1133 cparm->capability = V4L2_CAP_TIMEPERFRAME;
1134 cparm->timeperframe =
1135 decoder->std_list[current_std].standard.frameperiod;
1137 return 0;
1141 * tvp514x_s_parm() - V4L2 decoder interface handler for s_parm
1142 * @sd: pointer to standard V4L2 sub-device structure
1143 * @a: pointer to standard V4L2 VIDIOC_S_PARM ioctl structure
1145 * Configures the decoder to use the input parameters, if possible. If
1146 * not possible, returns the appropriate error code.
1148 static int
1149 tvp514x_s_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *a)
1151 struct tvp514x_decoder *decoder = to_decoder(sd);
1152 struct v4l2_fract *timeperframe;
1153 enum tvp514x_std current_std;
1155 if (a == NULL)
1156 return -EINVAL;
1158 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1159 /* only capture is supported */
1160 return -EINVAL;
1162 timeperframe = &a->parm.capture.timeperframe;
1164 /* get the current standard */
1165 current_std = tvp514x_get_current_std(sd);
1166 if (current_std == STD_INVALID)
1167 return -EINVAL;
1169 decoder->current_std = current_std;
1171 *timeperframe =
1172 decoder->std_list[current_std].standard.frameperiod;
1174 return 0;
1178 * tvp514x_s_stream() - V4L2 decoder i/f handler for s_stream
1179 * @sd: pointer to standard V4L2 sub-device structure
1180 * @enable: streaming enable or disable
1182 * Sets streaming to enable or disable, if possible.
1184 static int tvp514x_s_stream(struct v4l2_subdev *sd, int enable)
1186 int err = 0;
1187 struct i2c_client *client = v4l2_get_subdevdata(sd);
1188 struct tvp514x_decoder *decoder = to_decoder(sd);
1190 if (decoder->streaming == enable)
1191 return 0;
1193 switch (enable) {
1194 case 0:
1196 /* Power Down Sequence */
1197 err = tvp514x_write_reg(sd, REG_OPERATION_MODE, 0x01);
1198 if (err) {
1199 v4l2_err(sd, "Unable to turn off decoder\n");
1200 return err;
1202 decoder->streaming = enable;
1203 break;
1205 case 1:
1207 struct tvp514x_reg *int_seq = (struct tvp514x_reg *)
1208 client->driver->id_table->driver_data;
1210 /* Power Up Sequence */
1211 err = tvp514x_write_regs(sd, int_seq);
1212 if (err) {
1213 v4l2_err(sd, "Unable to turn on decoder\n");
1214 return err;
1216 /* Detect if not already detected */
1217 err = tvp514x_detect(sd, decoder);
1218 if (err) {
1219 v4l2_err(sd, "Unable to detect decoder\n");
1220 return err;
1222 err = tvp514x_configure(sd, decoder);
1223 if (err) {
1224 v4l2_err(sd, "Unable to configure decoder\n");
1225 return err;
1227 decoder->streaming = enable;
1228 break;
1230 default:
1231 err = -ENODEV;
1232 break;
1235 return err;
1238 static const struct v4l2_subdev_core_ops tvp514x_core_ops = {
1239 .queryctrl = tvp514x_queryctrl,
1240 .g_ctrl = tvp514x_g_ctrl,
1241 .s_ctrl = tvp514x_s_ctrl,
1242 .s_std = tvp514x_s_std,
1245 static const struct v4l2_subdev_video_ops tvp514x_video_ops = {
1246 .s_routing = tvp514x_s_routing,
1247 .querystd = tvp514x_querystd,
1248 .enum_fmt = tvp514x_enum_fmt_cap,
1249 .g_fmt = tvp514x_g_fmt_cap,
1250 .try_fmt = tvp514x_try_fmt_cap,
1251 .s_fmt = tvp514x_s_fmt_cap,
1252 .g_parm = tvp514x_g_parm,
1253 .s_parm = tvp514x_s_parm,
1254 .s_stream = tvp514x_s_stream,
1257 static const struct v4l2_subdev_ops tvp514x_ops = {
1258 .core = &tvp514x_core_ops,
1259 .video = &tvp514x_video_ops,
1262 static struct tvp514x_decoder tvp514x_dev = {
1263 .streaming = 0,
1265 .fmt_list = tvp514x_fmt_list,
1266 .num_fmts = ARRAY_SIZE(tvp514x_fmt_list),
1268 .pix = {
1269 /* Default to NTSC 8-bit YUV 422 */
1270 .width = NTSC_NUM_ACTIVE_PIXELS,
1271 .height = NTSC_NUM_ACTIVE_LINES,
1272 .pixelformat = V4L2_PIX_FMT_UYVY,
1273 .field = V4L2_FIELD_INTERLACED,
1274 .bytesperline = NTSC_NUM_ACTIVE_PIXELS * 2,
1275 .sizeimage =
1276 NTSC_NUM_ACTIVE_PIXELS * 2 * NTSC_NUM_ACTIVE_LINES,
1277 .colorspace = V4L2_COLORSPACE_SMPTE170M,
1280 .current_std = STD_NTSC_MJ,
1281 .std_list = tvp514x_std_list,
1282 .num_stds = ARRAY_SIZE(tvp514x_std_list),
1287 * tvp514x_probe() - decoder driver i2c probe handler
1288 * @client: i2c driver client device structure
1289 * @id: i2c driver id table
1291 * Register decoder as an i2c client device and V4L2
1292 * device.
1294 static int
1295 tvp514x_probe(struct i2c_client *client, const struct i2c_device_id *id)
1297 struct tvp514x_decoder *decoder;
1298 struct v4l2_subdev *sd;
1300 /* Check if the adapter supports the needed features */
1301 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
1302 return -EIO;
1304 if (!client->dev.platform_data) {
1305 v4l2_err(client, "No platform data!!\n");
1306 return -ENODEV;
1309 decoder = kzalloc(sizeof(*decoder), GFP_KERNEL);
1310 if (!decoder)
1311 return -ENOMEM;
1313 /* Initialize the tvp514x_decoder with default configuration */
1314 *decoder = tvp514x_dev;
1315 /* Copy default register configuration */
1316 memcpy(decoder->tvp514x_regs, tvp514x_reg_list_default,
1317 sizeof(tvp514x_reg_list_default));
1319 /* Copy board specific information here */
1320 decoder->pdata = client->dev.platform_data;
1323 * Fetch platform specific data, and configure the
1324 * tvp514x_reg_list[] accordingly. Since this is one
1325 * time configuration, no need to preserve.
1327 decoder->tvp514x_regs[REG_OUTPUT_FORMATTER2].val |=
1328 (decoder->pdata->clk_polarity << 1);
1329 decoder->tvp514x_regs[REG_SYNC_CONTROL].val |=
1330 ((decoder->pdata->hs_polarity << 2) |
1331 (decoder->pdata->vs_polarity << 3));
1332 /* Set default standard to auto */
1333 decoder->tvp514x_regs[REG_VIDEO_STD].val =
1334 VIDEO_STD_AUTO_SWITCH_BIT;
1336 /* Register with V4L2 layer as slave device */
1337 sd = &decoder->sd;
1338 v4l2_i2c_subdev_init(sd, client, &tvp514x_ops);
1340 v4l2_info(sd, "%s decoder driver registered !!\n", sd->name);
1342 return 0;
1347 * tvp514x_remove() - decoder driver i2c remove handler
1348 * @client: i2c driver client device structure
1350 * Unregister decoder as an i2c client device and V4L2
1351 * device. Complement of tvp514x_probe().
1353 static int tvp514x_remove(struct i2c_client *client)
1355 struct v4l2_subdev *sd = i2c_get_clientdata(client);
1356 struct tvp514x_decoder *decoder = to_decoder(sd);
1358 v4l2_device_unregister_subdev(sd);
1359 kfree(decoder);
1360 return 0;
1362 /* TVP5146 Init/Power on Sequence */
1363 static const struct tvp514x_reg tvp5146_init_reg_seq[] = {
1364 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x02},
1365 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00},
1366 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0x80},
1367 {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x01},
1368 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x60},
1369 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00},
1370 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0xB0},
1371 {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x01},
1372 {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x00},
1373 {TOK_WRITE, REG_OPERATION_MODE, 0x01},
1374 {TOK_WRITE, REG_OPERATION_MODE, 0x00},
1375 {TOK_TERM, 0, 0},
1378 /* TVP5147 Init/Power on Sequence */
1379 static const struct tvp514x_reg tvp5147_init_reg_seq[] = {
1380 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x02},
1381 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00},
1382 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0x80},
1383 {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x01},
1384 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x60},
1385 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00},
1386 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0xB0},
1387 {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x01},
1388 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x16},
1389 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00},
1390 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0xA0},
1391 {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x16},
1392 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x60},
1393 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00},
1394 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0xB0},
1395 {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x00},
1396 {TOK_WRITE, REG_OPERATION_MODE, 0x01},
1397 {TOK_WRITE, REG_OPERATION_MODE, 0x00},
1398 {TOK_TERM, 0, 0},
1401 /* TVP5146M2/TVP5147M1 Init/Power on Sequence */
1402 static const struct tvp514x_reg tvp514xm_init_reg_seq[] = {
1403 {TOK_WRITE, REG_OPERATION_MODE, 0x01},
1404 {TOK_WRITE, REG_OPERATION_MODE, 0x00},
1405 {TOK_TERM, 0, 0},
1409 * I2C Device Table -
1411 * name - Name of the actual device/chip.
1412 * driver_data - Driver data
1414 static const struct i2c_device_id tvp514x_id[] = {
1415 {"tvp5146", (unsigned long)tvp5146_init_reg_seq},
1416 {"tvp5146m2", (unsigned long)tvp514xm_init_reg_seq},
1417 {"tvp5147", (unsigned long)tvp5147_init_reg_seq},
1418 {"tvp5147m1", (unsigned long)tvp514xm_init_reg_seq},
1422 MODULE_DEVICE_TABLE(i2c, tvp514x_id);
1424 static struct i2c_driver tvp514x_driver = {
1425 .driver = {
1426 .owner = THIS_MODULE,
1427 .name = TVP514X_MODULE_NAME,
1429 .probe = tvp514x_probe,
1430 .remove = tvp514x_remove,
1431 .id_table = tvp514x_id,
1434 static int __init tvp514x_init(void)
1436 return i2c_add_driver(&tvp514x_driver);
1439 static void __exit tvp514x_exit(void)
1441 i2c_del_driver(&tvp514x_driver);
1444 module_init(tvp514x_init);
1445 module_exit(tvp514x_exit);