1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * drivers/media/i2c/tvp514x.c
4 *
5 * TI TVP5146/47 decoder driver
6 *
7 * Copyright (C) 2008 Texas Instruments Inc
8 * Author: Vaibhav Hiremath <hvaibhav@ti.com>
9 *
10 * Contributors:
11 * Sivaraj R <sivaraj@ti.com>
12 * Brijesh R Jadav <brijesh.j@ti.com>
13 * Hardik Shah <hardik.shah@ti.com>
14 * Manjunath Hadli <mrh@ti.com>
15 * Karicheri Muralidharan <m-karicheri2@ti.com>
16 * Prabhakar Lad <prabhakar.lad@ti.com>
17 */
18
19 #include <linux/delay.h>
20 #include <linux/i2c.h>
21 #include <linux/module.h>
22 #include <linux/of.h>
23 #include <linux/of_graph.h>
24 #include <linux/slab.h>
25 #include <linux/v4l2-mediabus.h>
26 #include <linux/videodev2.h>
27
28 #include <media/i2c/tvp514x.h>
29 #include <media/media-entity.h>
30 #include <media/v4l2-async.h>
31 #include <media/v4l2-common.h>
32 #include <media/v4l2-ctrls.h>
33 #include <media/v4l2-device.h>
34 #include <media/v4l2-fwnode.h>
35 #include <media/v4l2-mediabus.h>
36
37 #include "tvp514x_regs.h"
38
39 /* Private macros for TVP */
40 #define I2C_RETRY_COUNT (5)
41 #define LOCK_RETRY_COUNT (5)
42 #define LOCK_RETRY_DELAY (200)
43
44 /* Debug functions */
45 static bool debug;
46 module_param(debug, bool, 0644);
47 MODULE_PARM_DESC(debug, "Debug level (0-1)");
48
49 MODULE_AUTHOR("Texas Instruments");
50 MODULE_DESCRIPTION("TVP514X linux decoder driver");
51 MODULE_LICENSE("GPL");
52
53 /* enum tvp514x_std - enum for supported standards */
54 enum tvp514x_std {
55 STD_NTSC_MJ = 0,
56 STD_PAL_BDGHIN,
57 STD_INVALID
58 };
59
60 /**
61 * struct tvp514x_std_info - Structure to store standard information
62 * @width: Line width in pixels
63 * @height:Number of active lines
64 * @video_std: Value to write in REG_VIDEO_STD register
65 * @standard: v4l2 standard structure information
66 */
67 struct tvp514x_std_info {
68 unsigned long width;
69 unsigned long height;
70 u8 video_std;
71 struct v4l2_standard standard;
72 };
73
74 static struct tvp514x_reg tvp514x_reg_list_default[0x40];
75
76 static int tvp514x_s_stream(struct v4l2_subdev *sd, int enable);
77 /**
78 * struct tvp514x_decoder - TVP5146/47 decoder object
79 * @sd: Subdevice Slave handle
80 * @hdl: embedded &struct v4l2_ctrl_handler
81 * @tvp514x_regs: copy of hw's regs with preset values.
82 * @pdata: Board specific
83 * @ver: Chip version
84 * @streaming: TVP5146/47 decoder streaming - enabled or disabled.
85 * @pix: Current pixel format
86 * @num_fmts: Number of formats
87 * @fmt_list: Format list
88 * @current_std: Current standard
89 * @num_stds: Number of standards
90 * @std_list: Standards list
91 * @input: Input routing at chip level
92 * @output: Output routing at chip level
93 * @pad: subdev media pad associated with the decoder
94 * @format: media bus frame format
95 * @int_seq: driver's register init sequence
96 */
97 struct tvp514x_decoder {
98 struct v4l2_subdev sd;
99 struct v4l2_ctrl_handler hdl;
100 struct tvp514x_reg tvp514x_regs[ARRAY_SIZE(tvp514x_reg_list_default)];
101 const struct tvp514x_platform_data *pdata;
102
103 int ver;
104 int streaming;
105
106 struct v4l2_pix_format pix;
107 int num_fmts;
108 const struct v4l2_fmtdesc *fmt_list;
109
110 enum tvp514x_std current_std;
111 int num_stds;
112 const struct tvp514x_std_info *std_list;
113 /* Input and Output Routing parameters */
114 u32 input;
115 u32 output;
116
117 /* mc related members */
118 struct media_pad pad;
119 struct v4l2_mbus_framefmt format;
120
121 const struct tvp514x_reg *int_seq;
122 };
123
124 /* TVP514x default register values */
125 static struct tvp514x_reg tvp514x_reg_list_default[] = {
126 /* Composite selected */
127 {TOK_WRITE, REG_INPUT_SEL, 0x05},
128 {TOK_WRITE, REG_AFE_GAIN_CTRL, 0x0F},
129 /* Auto mode */
130 {TOK_WRITE, REG_VIDEO_STD, 0x00},
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 /* Reserved */
144 {TOK_SKIP, 0x0F, 0x00},
145 {TOK_WRITE, REG_COMP_PR_SATURATION, 0x80},
146 {TOK_WRITE, REG_COMP_Y_CONTRAST, 0x80},
147 {TOK_WRITE, REG_COMP_PB_SATURATION, 0x80},
148 /* Reserved */
149 {TOK_SKIP, 0x13, 0x00},
150 {TOK_WRITE, REG_COMP_Y_BRIGHTNESS, 0x80},
151 /* Reserved */
152 {TOK_SKIP, 0x15, 0x00},
153 /* NTSC timing */
154 {TOK_SKIP, REG_AVID_START_PIXEL_LSB, 0x55},
155 {TOK_SKIP, REG_AVID_START_PIXEL_MSB, 0x00},
156 {TOK_SKIP, REG_AVID_STOP_PIXEL_LSB, 0x25},
157 {TOK_SKIP, REG_AVID_STOP_PIXEL_MSB, 0x03},
158 /* NTSC timing */
159 {TOK_SKIP, REG_HSYNC_START_PIXEL_LSB, 0x00},
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 /* NTSC timing */
164 {TOK_SKIP, REG_VSYNC_START_LINE_LSB, 0x04},
165 {TOK_SKIP, REG_VSYNC_START_LINE_MSB, 0x00},
166 {TOK_SKIP, REG_VSYNC_STOP_LINE_LSB, 0x07},
167 {TOK_SKIP, REG_VSYNC_STOP_LINE_MSB, 0x00},
168 /* NTSC timing */
169 {TOK_SKIP, REG_VBLK_START_LINE_LSB, 0x01},
170 {TOK_SKIP, REG_VBLK_START_LINE_MSB, 0x00},
171 {TOK_SKIP, REG_VBLK_STOP_LINE_LSB, 0x15},
172 {TOK_SKIP, REG_VBLK_STOP_LINE_MSB, 0x00},
173 /* Reserved */
174 {TOK_SKIP, 0x26, 0x00},
175 /* Reserved */
176 {TOK_SKIP, 0x27, 0x00},
177 {TOK_SKIP, REG_FAST_SWTICH_CONTROL, 0xCC},
178 /* Reserved */
179 {TOK_SKIP, 0x29, 0x00},
180 {TOK_SKIP, REG_FAST_SWTICH_SCART_DELAY, 0x00},
181 /* Reserved */
182 {TOK_SKIP, 0x2B, 0x00},
183 {TOK_SKIP, REG_SCART_DELAY, 0x00},
184 {TOK_SKIP, REG_CTI_DELAY, 0x00},
185 {TOK_SKIP, REG_CTI_CONTROL, 0x00},
186 /* Reserved */
187 {TOK_SKIP, 0x2F, 0x00},
188 /* Reserved */
189 {TOK_SKIP, 0x30, 0x00},
190 /* Reserved */
191 {TOK_SKIP, 0x31, 0x00},
192 /* HS, VS active high */
193 {TOK_WRITE, REG_SYNC_CONTROL, 0x00},
194 /* 10-bit BT.656 */
195 {TOK_WRITE, REG_OUTPUT_FORMATTER1, 0x00},
196 /* Enable clk & data */
197 {TOK_WRITE, REG_OUTPUT_FORMATTER2, 0x11},
198 /* Enable AVID & FLD */
199 {TOK_WRITE, REG_OUTPUT_FORMATTER3, 0xEE},
200 /* Enable VS & HS */
201 {TOK_WRITE, REG_OUTPUT_FORMATTER4, 0xAF},
202 {TOK_WRITE, REG_OUTPUT_FORMATTER5, 0xFF},
203 {TOK_WRITE, REG_OUTPUT_FORMATTER6, 0xFF},
204 /* Clear status */
205 {TOK_WRITE, REG_CLEAR_LOST_LOCK, 0x01},
206 {TOK_TERM, 0, 0},
207 };
208
209 /*
210 * List of image formats supported by TVP5146/47 decoder
211 * Currently we are using 8 bit mode only, but can be
212 * extended to 10/20 bit mode.
213 */
214 static const struct v4l2_fmtdesc tvp514x_fmt_list[] = {
215 {
216 .index = 0,
217 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
218 .flags = 0,
219 .description = "8-bit UYVY 4:2:2 Format",
220 .pixelformat = V4L2_PIX_FMT_UYVY,
221 },
222 };
223
224 /*
225 * Supported standards -
226 *
227 * Currently supports two standards only, need to add support for rest of the
228 * modes, like SECAM, etc...
229 */
230 static const struct tvp514x_std_info tvp514x_std_list[] = {
231 /* Standard: STD_NTSC_MJ */
232 [STD_NTSC_MJ] = {
233 .width = NTSC_NUM_ACTIVE_PIXELS,
234 .height = NTSC_NUM_ACTIVE_LINES,
235 .video_std = VIDEO_STD_NTSC_MJ_BIT,
236 .standard = {
237 .index = 0,
238 .id = V4L2_STD_NTSC,
239 .name = "NTSC",
240 .frameperiod = {1001, 30000},
241 .framelines = 525
242 },
243 /* Standard: STD_PAL_BDGHIN */
244 },
245 [STD_PAL_BDGHIN] = {
246 .width = PAL_NUM_ACTIVE_PIXELS,
247 .height = PAL_NUM_ACTIVE_LINES,
248 .video_std = VIDEO_STD_PAL_BDGHIN_BIT,
249 .standard = {
250 .index = 1,
251 .id = V4L2_STD_PAL,
252 .name = "PAL",
253 .frameperiod = {1, 25},
254 .framelines = 625
255 },
256 },
257 /* Standard: need to add for additional standard */
258 };
259
260
to_decoder(struct v4l2_subdev * sd)261 static inline struct tvp514x_decoder *to_decoder(struct v4l2_subdev *sd)
262 {
263 return container_of(sd, struct tvp514x_decoder, sd);
264 }
265
to_sd(struct v4l2_ctrl * ctrl)266 static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl)
267 {
268 return &container_of(ctrl->handler, struct tvp514x_decoder, hdl)->sd;
269 }
270
271
272 /**
273 * tvp514x_read_reg() - Read a value from a register in an TVP5146/47.
274 * @sd: ptr to v4l2_subdev struct
275 * @reg: TVP5146/47 register address
276 *
277 * Returns value read if successful, or non-zero (-1) otherwise.
278 */
tvp514x_read_reg(struct v4l2_subdev * sd,u8 reg)279 static int tvp514x_read_reg(struct v4l2_subdev *sd, u8 reg)
280 {
281 int err, retry = 0;
282 struct i2c_client *client = v4l2_get_subdevdata(sd);
283
284 read_again:
285
286 err = i2c_smbus_read_byte_data(client, reg);
287 if (err < 0) {
288 if (retry <= I2C_RETRY_COUNT) {
289 v4l2_warn(sd, "Read: retry ... %d\n", retry);
290 retry++;
291 msleep_interruptible(10);
292 goto read_again;
293 }
294 }
295
296 return err;
297 }
298
299 /**
300 * dump_reg() - dump the register content of TVP5146/47.
301 * @sd: ptr to v4l2_subdev struct
302 * @reg: TVP5146/47 register address
303 */
dump_reg(struct v4l2_subdev * sd,u8 reg)304 static void dump_reg(struct v4l2_subdev *sd, u8 reg)
305 {
306 u32 val;
307
308 val = tvp514x_read_reg(sd, reg);
309 v4l2_info(sd, "Reg(0x%.2X): 0x%.2X\n", reg, val);
310 }
311
312 /**
313 * tvp514x_write_reg() - Write a value to a register in TVP5146/47
314 * @sd: ptr to v4l2_subdev struct
315 * @reg: TVP5146/47 register address
316 * @val: value to be written to the register
317 *
318 * Write a value to a register in an TVP5146/47 decoder device.
319 * Returns zero if successful, or non-zero otherwise.
320 */
tvp514x_write_reg(struct v4l2_subdev * sd,u8 reg,u8 val)321 static int tvp514x_write_reg(struct v4l2_subdev *sd, u8 reg, u8 val)
322 {
323 int err, retry = 0;
324 struct i2c_client *client = v4l2_get_subdevdata(sd);
325
326 write_again:
327
328 err = i2c_smbus_write_byte_data(client, reg, val);
329 if (err) {
330 if (retry <= I2C_RETRY_COUNT) {
331 v4l2_warn(sd, "Write: retry ... %d\n", retry);
332 retry++;
333 msleep_interruptible(10);
334 goto write_again;
335 }
336 }
337
338 return err;
339 }
340
341 /**
342 * tvp514x_write_regs() : Initializes a list of TVP5146/47 registers
343 * @sd: ptr to v4l2_subdev struct
344 * @reglist: list of TVP5146/47 registers and values
345 *
346 * Initializes a list of TVP5146/47 registers:-
347 * if token is TOK_TERM, then entire write operation terminates
348 * if token is TOK_DELAY, then a delay of 'val' msec is introduced
349 * if token is TOK_SKIP, then the register write is skipped
350 * if token is TOK_WRITE, then the register write is performed
351 * Returns zero if successful, or non-zero otherwise.
352 */
tvp514x_write_regs(struct v4l2_subdev * sd,const struct tvp514x_reg reglist[])353 static int tvp514x_write_regs(struct v4l2_subdev *sd,
354 const struct tvp514x_reg reglist[])
355 {
356 int err;
357 const struct tvp514x_reg *next = reglist;
358
359 for (; next->token != TOK_TERM; next++) {
360 if (next->token == TOK_DELAY) {
361 msleep(next->val);
362 continue;
363 }
364
365 if (next->token == TOK_SKIP)
366 continue;
367
368 err = tvp514x_write_reg(sd, next->reg, (u8) next->val);
369 if (err) {
370 v4l2_err(sd, "Write failed. Err[%d]\n", err);
371 return err;
372 }
373 }
374 return 0;
375 }
376
377 /**
378 * tvp514x_query_current_std() : Query the current standard detected by TVP5146/47
379 * @sd: ptr to v4l2_subdev struct
380 *
381 * Returns the current standard detected by TVP5146/47, STD_INVALID if there is no
382 * standard detected.
383 */
tvp514x_query_current_std(struct v4l2_subdev * sd)384 static enum tvp514x_std tvp514x_query_current_std(struct v4l2_subdev *sd)
385 {
386 u8 std, std_status;
387
388 std = tvp514x_read_reg(sd, REG_VIDEO_STD);
389 if ((std & VIDEO_STD_MASK) == VIDEO_STD_AUTO_SWITCH_BIT)
390 /* use the standard status register */
391 std_status = tvp514x_read_reg(sd, REG_VIDEO_STD_STATUS);
392 else
393 /* use the standard register itself */
394 std_status = std;
395
396 switch (std_status & VIDEO_STD_MASK) {
397 case VIDEO_STD_NTSC_MJ_BIT:
398 return STD_NTSC_MJ;
399
400 case VIDEO_STD_PAL_BDGHIN_BIT:
401 return STD_PAL_BDGHIN;
402
403 default:
404 return STD_INVALID;
405 }
406
407 return STD_INVALID;
408 }
409
410 /* TVP5146/47 register dump function */
tvp514x_reg_dump(struct v4l2_subdev * sd)411 static void tvp514x_reg_dump(struct v4l2_subdev *sd)
412 {
413 dump_reg(sd, REG_INPUT_SEL);
414 dump_reg(sd, REG_AFE_GAIN_CTRL);
415 dump_reg(sd, REG_VIDEO_STD);
416 dump_reg(sd, REG_OPERATION_MODE);
417 dump_reg(sd, REG_COLOR_KILLER);
418 dump_reg(sd, REG_LUMA_CONTROL1);
419 dump_reg(sd, REG_LUMA_CONTROL2);
420 dump_reg(sd, REG_LUMA_CONTROL3);
421 dump_reg(sd, REG_BRIGHTNESS);
422 dump_reg(sd, REG_CONTRAST);
423 dump_reg(sd, REG_SATURATION);
424 dump_reg(sd, REG_HUE);
425 dump_reg(sd, REG_CHROMA_CONTROL1);
426 dump_reg(sd, REG_CHROMA_CONTROL2);
427 dump_reg(sd, REG_COMP_PR_SATURATION);
428 dump_reg(sd, REG_COMP_Y_CONTRAST);
429 dump_reg(sd, REG_COMP_PB_SATURATION);
430 dump_reg(sd, REG_COMP_Y_BRIGHTNESS);
431 dump_reg(sd, REG_AVID_START_PIXEL_LSB);
432 dump_reg(sd, REG_AVID_START_PIXEL_MSB);
433 dump_reg(sd, REG_AVID_STOP_PIXEL_LSB);
434 dump_reg(sd, REG_AVID_STOP_PIXEL_MSB);
435 dump_reg(sd, REG_HSYNC_START_PIXEL_LSB);
436 dump_reg(sd, REG_HSYNC_START_PIXEL_MSB);
437 dump_reg(sd, REG_HSYNC_STOP_PIXEL_LSB);
438 dump_reg(sd, REG_HSYNC_STOP_PIXEL_MSB);
439 dump_reg(sd, REG_VSYNC_START_LINE_LSB);
440 dump_reg(sd, REG_VSYNC_START_LINE_MSB);
441 dump_reg(sd, REG_VSYNC_STOP_LINE_LSB);
442 dump_reg(sd, REG_VSYNC_STOP_LINE_MSB);
443 dump_reg(sd, REG_VBLK_START_LINE_LSB);
444 dump_reg(sd, REG_VBLK_START_LINE_MSB);
445 dump_reg(sd, REG_VBLK_STOP_LINE_LSB);
446 dump_reg(sd, REG_VBLK_STOP_LINE_MSB);
447 dump_reg(sd, REG_SYNC_CONTROL);
448 dump_reg(sd, REG_OUTPUT_FORMATTER1);
449 dump_reg(sd, REG_OUTPUT_FORMATTER2);
450 dump_reg(sd, REG_OUTPUT_FORMATTER3);
451 dump_reg(sd, REG_OUTPUT_FORMATTER4);
452 dump_reg(sd, REG_OUTPUT_FORMATTER5);
453 dump_reg(sd, REG_OUTPUT_FORMATTER6);
454 dump_reg(sd, REG_CLEAR_LOST_LOCK);
455 }
456
457 /**
458 * tvp514x_configure() - Configure the TVP5146/47 registers
459 * @sd: ptr to v4l2_subdev struct
460 * @decoder: ptr to tvp514x_decoder structure
461 *
462 * Returns zero if successful, or non-zero otherwise.
463 */
tvp514x_configure(struct v4l2_subdev * sd,struct tvp514x_decoder * decoder)464 static int tvp514x_configure(struct v4l2_subdev *sd,
465 struct tvp514x_decoder *decoder)
466 {
467 int err;
468
469 /* common register initialization */
470 err =
471 tvp514x_write_regs(sd, decoder->tvp514x_regs);
472 if (err)
473 return err;
474
475 if (debug)
476 tvp514x_reg_dump(sd);
477
478 return 0;
479 }
480
481 /**
482 * tvp514x_detect() - Detect if an tvp514x is present, and if so which revision.
483 * @sd: pointer to standard V4L2 sub-device structure
484 * @decoder: pointer to tvp514x_decoder structure
485 *
486 * A device is considered to be detected if the chip ID (LSB and MSB)
487 * registers match the expected values.
488 * Any value of the rom version register is accepted.
489 * Returns ENODEV error number if no device is detected, or zero
490 * if a device is detected.
491 */
tvp514x_detect(struct v4l2_subdev * sd,struct tvp514x_decoder * decoder)492 static int tvp514x_detect(struct v4l2_subdev *sd,
493 struct tvp514x_decoder *decoder)
494 {
495 u8 chip_id_msb, chip_id_lsb, rom_ver;
496 struct i2c_client *client = v4l2_get_subdevdata(sd);
497
498 chip_id_msb = tvp514x_read_reg(sd, REG_CHIP_ID_MSB);
499 chip_id_lsb = tvp514x_read_reg(sd, REG_CHIP_ID_LSB);
500 rom_ver = tvp514x_read_reg(sd, REG_ROM_VERSION);
501
502 v4l2_dbg(1, debug, sd,
503 "chip id detected msb:0x%x lsb:0x%x rom version:0x%x\n",
504 chip_id_msb, chip_id_lsb, rom_ver);
505 if ((chip_id_msb != TVP514X_CHIP_ID_MSB)
506 || ((chip_id_lsb != TVP5146_CHIP_ID_LSB)
507 && (chip_id_lsb != TVP5147_CHIP_ID_LSB))) {
508 /* We didn't read the values we expected, so this must not be
509 * an TVP5146/47.
510 */
511 v4l2_err(sd, "chip id mismatch msb:0x%x lsb:0x%x\n",
512 chip_id_msb, chip_id_lsb);
513 return -ENODEV;
514 }
515
516 decoder->ver = rom_ver;
517
518 v4l2_info(sd, "%s (Version - 0x%.2x) found at 0x%x (%s)\n",
519 client->name, decoder->ver,
520 client->addr << 1, client->adapter->name);
521 return 0;
522 }
523
524 /**
525 * tvp514x_querystd() - V4L2 decoder interface handler for querystd
526 * @sd: pointer to standard V4L2 sub-device structure
527 * @std_id: standard V4L2 std_id ioctl enum
528 *
529 * Returns the current standard detected by TVP5146/47. If no active input is
530 * detected then *std_id is set to 0 and the function returns 0.
531 */
tvp514x_querystd(struct v4l2_subdev * sd,v4l2_std_id * std_id)532 static int tvp514x_querystd(struct v4l2_subdev *sd, v4l2_std_id *std_id)
533 {
534 struct tvp514x_decoder *decoder = to_decoder(sd);
535 enum tvp514x_std current_std;
536 enum tvp514x_input input_sel;
537 u8 sync_lock_status, lock_mask;
538
539 if (std_id == NULL)
540 return -EINVAL;
541
542 /* To query the standard the TVP514x must power on the ADCs. */
543 if (!decoder->streaming) {
544 tvp514x_s_stream(sd, 1);
545 msleep(LOCK_RETRY_DELAY);
546 }
547
548 /* query the current standard */
549 current_std = tvp514x_query_current_std(sd);
550 if (current_std == STD_INVALID) {
551 *std_id = V4L2_STD_UNKNOWN;
552 return 0;
553 }
554
555 input_sel = decoder->input;
556
557 switch (input_sel) {
558 case INPUT_CVBS_VI1A:
559 case INPUT_CVBS_VI1B:
560 case INPUT_CVBS_VI1C:
561 case INPUT_CVBS_VI2A:
562 case INPUT_CVBS_VI2B:
563 case INPUT_CVBS_VI2C:
564 case INPUT_CVBS_VI3A:
565 case INPUT_CVBS_VI3B:
566 case INPUT_CVBS_VI3C:
567 case INPUT_CVBS_VI4A:
568 lock_mask = STATUS_CLR_SUBCAR_LOCK_BIT |
569 STATUS_HORZ_SYNC_LOCK_BIT |
570 STATUS_VIRT_SYNC_LOCK_BIT;
571 break;
572
573 case INPUT_SVIDEO_VI2A_VI1A:
574 case INPUT_SVIDEO_VI2B_VI1B:
575 case INPUT_SVIDEO_VI2C_VI1C:
576 case INPUT_SVIDEO_VI2A_VI3A:
577 case INPUT_SVIDEO_VI2B_VI3B:
578 case INPUT_SVIDEO_VI2C_VI3C:
579 case INPUT_SVIDEO_VI4A_VI1A:
580 case INPUT_SVIDEO_VI4A_VI1B:
581 case INPUT_SVIDEO_VI4A_VI1C:
582 case INPUT_SVIDEO_VI4A_VI3A:
583 case INPUT_SVIDEO_VI4A_VI3B:
584 case INPUT_SVIDEO_VI4A_VI3C:
585 lock_mask = STATUS_HORZ_SYNC_LOCK_BIT |
586 STATUS_VIRT_SYNC_LOCK_BIT;
587 break;
588 /*Need to add other interfaces*/
589 default:
590 return -EINVAL;
591 }
592 /* check whether signal is locked */
593 sync_lock_status = tvp514x_read_reg(sd, REG_STATUS1);
594 if (lock_mask != (sync_lock_status & lock_mask)) {
595 *std_id = V4L2_STD_UNKNOWN;
596 return 0; /* No input detected */
597 }
598
599 *std_id &= decoder->std_list[current_std].standard.id;
600
601 v4l2_dbg(1, debug, sd, "Current STD: %s\n",
602 decoder->std_list[current_std].standard.name);
603 return 0;
604 }
605
606 /**
607 * tvp514x_s_std() - V4L2 decoder interface handler for s_std
608 * @sd: pointer to standard V4L2 sub-device structure
609 * @std_id: standard V4L2 v4l2_std_id ioctl enum
610 *
611 * If std_id is supported, sets the requested standard. Otherwise, returns
612 * -EINVAL
613 */
tvp514x_s_std(struct v4l2_subdev * sd,v4l2_std_id std_id)614 static int tvp514x_s_std(struct v4l2_subdev *sd, v4l2_std_id std_id)
615 {
616 struct tvp514x_decoder *decoder = to_decoder(sd);
617 int err, i;
618
619 for (i = 0; i < decoder->num_stds; i++)
620 if (std_id & decoder->std_list[i].standard.id)
621 break;
622
623 if ((i == decoder->num_stds) || (i == STD_INVALID))
624 return -EINVAL;
625
626 err = tvp514x_write_reg(sd, REG_VIDEO_STD,
627 decoder->std_list[i].video_std);
628 if (err)
629 return err;
630
631 decoder->current_std = i;
632 decoder->tvp514x_regs[REG_VIDEO_STD].val =
633 decoder->std_list[i].video_std;
634
635 v4l2_dbg(1, debug, sd, "Standard set to: %s\n",
636 decoder->std_list[i].standard.name);
637 return 0;
638 }
639
640 /**
641 * tvp514x_s_routing() - V4L2 decoder interface handler for s_routing
642 * @sd: pointer to standard V4L2 sub-device structure
643 * @input: input selector for routing the signal
644 * @output: output selector for routing the signal
645 * @config: config value. Not used
646 *
647 * If index is valid, selects the requested input. Otherwise, returns -EINVAL if
648 * the input is not supported or there is no active signal present in the
649 * selected input.
650 */
tvp514x_s_routing(struct v4l2_subdev * sd,u32 input,u32 output,u32 config)651 static int tvp514x_s_routing(struct v4l2_subdev *sd,
652 u32 input, u32 output, u32 config)
653 {
654 struct tvp514x_decoder *decoder = to_decoder(sd);
655 int err;
656 enum tvp514x_input input_sel;
657 enum tvp514x_output output_sel;
658
659 if ((input >= INPUT_INVALID) ||
660 (output >= OUTPUT_INVALID))
661 /* Index out of bound */
662 return -EINVAL;
663
664 input_sel = input;
665 output_sel = output;
666
667 err = tvp514x_write_reg(sd, REG_INPUT_SEL, input_sel);
668 if (err)
669 return err;
670
671 output_sel |= tvp514x_read_reg(sd,
672 REG_OUTPUT_FORMATTER1) & 0x7;
673 err = tvp514x_write_reg(sd, REG_OUTPUT_FORMATTER1,
674 output_sel);
675 if (err)
676 return err;
677
678 decoder->tvp514x_regs[REG_INPUT_SEL].val = input_sel;
679 decoder->tvp514x_regs[REG_OUTPUT_FORMATTER1].val = output_sel;
680 decoder->input = input;
681 decoder->output = output;
682
683 v4l2_dbg(1, debug, sd, "Input set to: %d\n", input_sel);
684
685 return 0;
686 }
687
tvp514x_s_ctrl(struct v4l2_ctrl * ctrl)688 static int tvp514x_s_ctrl(struct v4l2_ctrl *ctrl)
689 {
690 struct v4l2_subdev *sd = to_sd(ctrl);
691 struct tvp514x_decoder *decoder = to_decoder(sd);
692 int err = -EINVAL, value;
693
694 value = ctrl->val;
695
696 switch (ctrl->id) {
697 case V4L2_CID_BRIGHTNESS:
698 err = tvp514x_write_reg(sd, REG_BRIGHTNESS, value);
699 if (!err)
700 decoder->tvp514x_regs[REG_BRIGHTNESS].val = value;
701 break;
702 case V4L2_CID_CONTRAST:
703 err = tvp514x_write_reg(sd, REG_CONTRAST, value);
704 if (!err)
705 decoder->tvp514x_regs[REG_CONTRAST].val = value;
706 break;
707 case V4L2_CID_SATURATION:
708 err = tvp514x_write_reg(sd, REG_SATURATION, value);
709 if (!err)
710 decoder->tvp514x_regs[REG_SATURATION].val = value;
711 break;
712 case V4L2_CID_HUE:
713 if (value == 180)
714 value = 0x7F;
715 else if (value == -180)
716 value = 0x80;
717 err = tvp514x_write_reg(sd, REG_HUE, value);
718 if (!err)
719 decoder->tvp514x_regs[REG_HUE].val = value;
720 break;
721 case V4L2_CID_AUTOGAIN:
722 err = tvp514x_write_reg(sd, REG_AFE_GAIN_CTRL, value ? 0x0f : 0x0c);
723 if (!err)
724 decoder->tvp514x_regs[REG_AFE_GAIN_CTRL].val = value;
725 break;
726 }
727
728 v4l2_dbg(1, debug, sd, "Set Control: ID - %d - %d\n",
729 ctrl->id, ctrl->val);
730 return err;
731 }
732
733 static int
tvp514x_get_frame_interval(struct v4l2_subdev * sd,struct v4l2_subdev_state * sd_state,struct v4l2_subdev_frame_interval * ival)734 tvp514x_get_frame_interval(struct v4l2_subdev *sd,
735 struct v4l2_subdev_state *sd_state,
736 struct v4l2_subdev_frame_interval *ival)
737 {
738 struct tvp514x_decoder *decoder = to_decoder(sd);
739 enum tvp514x_std current_std;
740
741 /*
742 * FIXME: Implement support for V4L2_SUBDEV_FORMAT_TRY, using the V4L2
743 * subdev active state API.
744 */
745 if (ival->which != V4L2_SUBDEV_FORMAT_ACTIVE)
746 return -EINVAL;
747
748 /* get the current standard */
749 current_std = decoder->current_std;
750
751 ival->interval =
752 decoder->std_list[current_std].standard.frameperiod;
753
754 return 0;
755 }
756
757 static int
tvp514x_set_frame_interval(struct v4l2_subdev * sd,struct v4l2_subdev_state * sd_state,struct v4l2_subdev_frame_interval * ival)758 tvp514x_set_frame_interval(struct v4l2_subdev *sd,
759 struct v4l2_subdev_state *sd_state,
760 struct v4l2_subdev_frame_interval *ival)
761 {
762 struct tvp514x_decoder *decoder = to_decoder(sd);
763 struct v4l2_fract *timeperframe;
764 enum tvp514x_std current_std;
765
766 /*
767 * FIXME: Implement support for V4L2_SUBDEV_FORMAT_TRY, using the V4L2
768 * subdev active state API.
769 */
770 if (ival->which != V4L2_SUBDEV_FORMAT_ACTIVE)
771 return -EINVAL;
772
773 timeperframe = &ival->interval;
774
775 /* get the current standard */
776 current_std = decoder->current_std;
777
778 *timeperframe =
779 decoder->std_list[current_std].standard.frameperiod;
780
781 return 0;
782 }
783
tvp514x_s_stream(struct v4l2_subdev * sd,int enable)784 static int tvp514x_s_stream(struct v4l2_subdev *sd, int enable)
785 {
786 int err = 0;
787 struct tvp514x_decoder *decoder = to_decoder(sd);
788
789 if (decoder->streaming == enable)
790 return 0;
791
792 switch (enable) {
793 case 0:
794 {
795 /* Power Down Sequence */
796 err = tvp514x_write_reg(sd, REG_OPERATION_MODE, 0x01);
797 if (err) {
798 v4l2_err(sd, "Unable to turn off decoder\n");
799 return err;
800 }
801 decoder->streaming = enable;
802 break;
803 }
804 case 1:
805 {
806 /* Power Up Sequence */
807 err = tvp514x_write_regs(sd, decoder->int_seq);
808 if (err) {
809 v4l2_err(sd, "Unable to turn on decoder\n");
810 return err;
811 }
812 /* Detect if not already detected */
813 err = tvp514x_detect(sd, decoder);
814 if (err) {
815 v4l2_err(sd, "Unable to detect decoder\n");
816 return err;
817 }
818 err = tvp514x_configure(sd, decoder);
819 if (err) {
820 v4l2_err(sd, "Unable to configure decoder\n");
821 return err;
822 }
823 decoder->streaming = enable;
824 break;
825 }
826 default:
827 err = -ENODEV;
828 break;
829 }
830
831 return err;
832 }
833
834 static const struct v4l2_ctrl_ops tvp514x_ctrl_ops = {
835 .s_ctrl = tvp514x_s_ctrl,
836 };
837
tvp514x_enum_mbus_code(struct v4l2_subdev * sd,struct v4l2_subdev_state * sd_state,struct v4l2_subdev_mbus_code_enum * code)838 static int tvp514x_enum_mbus_code(struct v4l2_subdev *sd,
839 struct v4l2_subdev_state *sd_state,
840 struct v4l2_subdev_mbus_code_enum *code)
841 {
842 u32 pad = code->pad;
843 u32 index = code->index;
844
845 memset(code, 0, sizeof(*code));
846 code->index = index;
847 code->pad = pad;
848
849 if (index != 0)
850 return -EINVAL;
851
852 code->code = MEDIA_BUS_FMT_UYVY8_2X8;
853
854 return 0;
855 }
856
tvp514x_get_pad_format(struct v4l2_subdev * sd,struct v4l2_subdev_state * sd_state,struct v4l2_subdev_format * format)857 static int tvp514x_get_pad_format(struct v4l2_subdev *sd,
858 struct v4l2_subdev_state *sd_state,
859 struct v4l2_subdev_format *format)
860 {
861 struct tvp514x_decoder *decoder = to_decoder(sd);
862 __u32 which = format->which;
863
864 if (format->pad)
865 return -EINVAL;
866
867 if (which == V4L2_SUBDEV_FORMAT_ACTIVE) {
868 format->format = decoder->format;
869 return 0;
870 }
871
872 format->format.code = MEDIA_BUS_FMT_UYVY8_2X8;
873 format->format.width = tvp514x_std_list[decoder->current_std].width;
874 format->format.height = tvp514x_std_list[decoder->current_std].height;
875 format->format.colorspace = V4L2_COLORSPACE_SMPTE170M;
876 format->format.field = V4L2_FIELD_INTERLACED;
877
878 return 0;
879 }
880
tvp514x_set_pad_format(struct v4l2_subdev * sd,struct v4l2_subdev_state * sd_state,struct v4l2_subdev_format * fmt)881 static int tvp514x_set_pad_format(struct v4l2_subdev *sd,
882 struct v4l2_subdev_state *sd_state,
883 struct v4l2_subdev_format *fmt)
884 {
885 struct tvp514x_decoder *decoder = to_decoder(sd);
886
887 if (fmt->format.field != V4L2_FIELD_INTERLACED ||
888 fmt->format.code != MEDIA_BUS_FMT_UYVY8_2X8 ||
889 fmt->format.colorspace != V4L2_COLORSPACE_SMPTE170M ||
890 fmt->format.width != tvp514x_std_list[decoder->current_std].width ||
891 fmt->format.height != tvp514x_std_list[decoder->current_std].height)
892 return -EINVAL;
893
894 decoder->format = fmt->format;
895
896 return 0;
897 }
898
899 static const struct v4l2_subdev_video_ops tvp514x_video_ops = {
900 .s_std = tvp514x_s_std,
901 .s_routing = tvp514x_s_routing,
902 .querystd = tvp514x_querystd,
903 .s_stream = tvp514x_s_stream,
904 };
905
906 static const struct v4l2_subdev_pad_ops tvp514x_pad_ops = {
907 .enum_mbus_code = tvp514x_enum_mbus_code,
908 .get_fmt = tvp514x_get_pad_format,
909 .set_fmt = tvp514x_set_pad_format,
910 .get_frame_interval = tvp514x_get_frame_interval,
911 .set_frame_interval = tvp514x_set_frame_interval,
912 };
913
914 static const struct v4l2_subdev_ops tvp514x_ops = {
915 .video = &tvp514x_video_ops,
916 .pad = &tvp514x_pad_ops,
917 };
918
919 static const struct tvp514x_decoder tvp514x_dev = {
920 .streaming = 0,
921 .fmt_list = tvp514x_fmt_list,
922 .num_fmts = ARRAY_SIZE(tvp514x_fmt_list),
923 .pix = {
924 /* Default to NTSC 8-bit YUV 422 */
925 .width = NTSC_NUM_ACTIVE_PIXELS,
926 .height = NTSC_NUM_ACTIVE_LINES,
927 .pixelformat = V4L2_PIX_FMT_UYVY,
928 .field = V4L2_FIELD_INTERLACED,
929 .bytesperline = NTSC_NUM_ACTIVE_PIXELS * 2,
930 .sizeimage = NTSC_NUM_ACTIVE_PIXELS * 2 *
931 NTSC_NUM_ACTIVE_LINES,
932 .colorspace = V4L2_COLORSPACE_SMPTE170M,
933 },
934 .current_std = STD_NTSC_MJ,
935 .std_list = tvp514x_std_list,
936 .num_stds = ARRAY_SIZE(tvp514x_std_list),
937
938 };
939
940 static struct tvp514x_platform_data *
tvp514x_get_pdata(struct i2c_client * client)941 tvp514x_get_pdata(struct i2c_client *client)
942 {
943 struct tvp514x_platform_data *pdata = NULL;
944 struct v4l2_fwnode_endpoint bus_cfg = { .bus_type = 0 };
945 struct device_node *endpoint;
946 unsigned int flags;
947
948 if (!IS_ENABLED(CONFIG_OF) || !client->dev.of_node)
949 return client->dev.platform_data;
950
951 endpoint = of_graph_get_endpoint_by_regs(client->dev.of_node, 0, -1);
952 if (!endpoint)
953 return NULL;
954
955 if (v4l2_fwnode_endpoint_parse(of_fwnode_handle(endpoint), &bus_cfg))
956 goto done;
957
958 pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL);
959 if (!pdata)
960 goto done;
961
962 flags = bus_cfg.bus.parallel.flags;
963
964 if (flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH)
965 pdata->hs_polarity = 1;
966
967 if (flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH)
968 pdata->vs_polarity = 1;
969
970 if (flags & V4L2_MBUS_PCLK_SAMPLE_RISING)
971 pdata->clk_polarity = 1;
972
973 done:
974 of_node_put(endpoint);
975 return pdata;
976 }
977
tvp514x_probe(struct i2c_client * client)978 static int tvp514x_probe(struct i2c_client *client)
979 {
980 struct tvp514x_platform_data *pdata = tvp514x_get_pdata(client);
981 struct tvp514x_decoder *decoder;
982 struct v4l2_subdev *sd;
983 int ret;
984
985 if (pdata == NULL) {
986 dev_err(&client->dev, "No platform data\n");
987 return -EINVAL;
988 }
989
990 /* Check if the adapter supports the needed features */
991 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
992 return -EIO;
993
994 decoder = devm_kzalloc(&client->dev, sizeof(*decoder), GFP_KERNEL);
995 if (!decoder)
996 return -ENOMEM;
997
998 /* Initialize the tvp514x_decoder with default configuration */
999 *decoder = tvp514x_dev;
1000 /* Copy default register configuration */
1001 memcpy(decoder->tvp514x_regs, tvp514x_reg_list_default,
1002 sizeof(tvp514x_reg_list_default));
1003
1004 decoder->int_seq = i2c_get_match_data(client);
1005
1006 /* Copy board specific information here */
1007 decoder->pdata = pdata;
1008
1009 /**
1010 * Fetch platform specific data, and configure the
1011 * tvp514x_reg_list[] accordingly. Since this is one
1012 * time configuration, no need to preserve.
1013 */
1014 decoder->tvp514x_regs[REG_OUTPUT_FORMATTER2].val |=
1015 (decoder->pdata->clk_polarity << 1);
1016 decoder->tvp514x_regs[REG_SYNC_CONTROL].val |=
1017 ((decoder->pdata->hs_polarity << 2) |
1018 (decoder->pdata->vs_polarity << 3));
1019 /* Set default standard to auto */
1020 decoder->tvp514x_regs[REG_VIDEO_STD].val =
1021 VIDEO_STD_AUTO_SWITCH_BIT;
1022
1023 /* Register with V4L2 layer as slave device */
1024 sd = &decoder->sd;
1025 v4l2_i2c_subdev_init(sd, client, &tvp514x_ops);
1026
1027 #if defined(CONFIG_MEDIA_CONTROLLER)
1028 decoder->pad.flags = MEDIA_PAD_FL_SOURCE;
1029 decoder->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
1030 decoder->sd.entity.function = MEDIA_ENT_F_ATV_DECODER;
1031
1032 ret = media_entity_pads_init(&decoder->sd.entity, 1, &decoder->pad);
1033 if (ret < 0) {
1034 v4l2_err(sd, "%s decoder driver failed to register !!\n",
1035 sd->name);
1036 return ret;
1037 }
1038 #endif
1039 v4l2_ctrl_handler_init(&decoder->hdl, 5);
1040 v4l2_ctrl_new_std(&decoder->hdl, &tvp514x_ctrl_ops,
1041 V4L2_CID_BRIGHTNESS, 0, 255, 1, 128);
1042 v4l2_ctrl_new_std(&decoder->hdl, &tvp514x_ctrl_ops,
1043 V4L2_CID_CONTRAST, 0, 255, 1, 128);
1044 v4l2_ctrl_new_std(&decoder->hdl, &tvp514x_ctrl_ops,
1045 V4L2_CID_SATURATION, 0, 255, 1, 128);
1046 v4l2_ctrl_new_std(&decoder->hdl, &tvp514x_ctrl_ops,
1047 V4L2_CID_HUE, -180, 180, 180, 0);
1048 v4l2_ctrl_new_std(&decoder->hdl, &tvp514x_ctrl_ops,
1049 V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
1050 sd->ctrl_handler = &decoder->hdl;
1051 if (decoder->hdl.error) {
1052 ret = decoder->hdl.error;
1053 goto done;
1054 }
1055 v4l2_ctrl_handler_setup(&decoder->hdl);
1056
1057 ret = v4l2_async_register_subdev(&decoder->sd);
1058 if (!ret)
1059 v4l2_info(sd, "%s decoder driver registered !!\n", sd->name);
1060
1061 done:
1062 if (ret < 0) {
1063 v4l2_ctrl_handler_free(&decoder->hdl);
1064 media_entity_cleanup(&decoder->sd.entity);
1065 }
1066 return ret;
1067 }
1068
tvp514x_remove(struct i2c_client * client)1069 static void tvp514x_remove(struct i2c_client *client)
1070 {
1071 struct v4l2_subdev *sd = i2c_get_clientdata(client);
1072 struct tvp514x_decoder *decoder = to_decoder(sd);
1073
1074 v4l2_async_unregister_subdev(&decoder->sd);
1075 media_entity_cleanup(&decoder->sd.entity);
1076 v4l2_ctrl_handler_free(&decoder->hdl);
1077 }
1078 /* TVP5146 Init/Power on Sequence */
1079 static const struct tvp514x_reg tvp5146_init_reg_seq[] = {
1080 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x02},
1081 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00},
1082 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0x80},
1083 {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x01},
1084 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x60},
1085 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00},
1086 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0xB0},
1087 {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x01},
1088 {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x00},
1089 {TOK_WRITE, REG_OPERATION_MODE, 0x01},
1090 {TOK_WRITE, REG_OPERATION_MODE, 0x00},
1091 {TOK_TERM, 0, 0},
1092 };
1093
1094 /* TVP5147 Init/Power on Sequence */
1095 static const struct tvp514x_reg tvp5147_init_reg_seq[] = {
1096 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x02},
1097 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00},
1098 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0x80},
1099 {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x01},
1100 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x60},
1101 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00},
1102 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0xB0},
1103 {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x01},
1104 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x16},
1105 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00},
1106 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0xA0},
1107 {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x16},
1108 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x60},
1109 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00},
1110 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0xB0},
1111 {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x00},
1112 {TOK_WRITE, REG_OPERATION_MODE, 0x01},
1113 {TOK_WRITE, REG_OPERATION_MODE, 0x00},
1114 {TOK_TERM, 0, 0},
1115 };
1116
1117 /* TVP5146M2/TVP5147M1 Init/Power on Sequence */
1118 static const struct tvp514x_reg tvp514xm_init_reg_seq[] = {
1119 {TOK_WRITE, REG_OPERATION_MODE, 0x01},
1120 {TOK_WRITE, REG_OPERATION_MODE, 0x00},
1121 {TOK_TERM, 0, 0},
1122 };
1123
1124 /*
1125 * I2C Device Table -
1126 *
1127 * name - Name of the actual device/chip.
1128 * driver_data - Driver data
1129 */
1130 static const struct i2c_device_id tvp514x_id[] = {
1131 { .name = "tvp5146", .driver_data = (kernel_ulong_t)tvp5146_init_reg_seq },
1132 { .name = "tvp5146m2", .driver_data = (kernel_ulong_t)tvp514xm_init_reg_seq },
1133 { .name = "tvp5147", .driver_data = (kernel_ulong_t)tvp5147_init_reg_seq },
1134 { .name = "tvp5147m1", .driver_data = (kernel_ulong_t)tvp514xm_init_reg_seq },
1135 { /* sentinel */ }
1136 };
1137 MODULE_DEVICE_TABLE(i2c, tvp514x_id);
1138
1139 static const struct of_device_id tvp514x_of_match[] = {
1140 { .compatible = "ti,tvp5146", .data = tvp5146_init_reg_seq },
1141 { .compatible = "ti,tvp5146m2", .data = tvp514xm_init_reg_seq },
1142 { .compatible = "ti,tvp5147", .data = tvp5147_init_reg_seq },
1143 { .compatible = "ti,tvp5147m1", .data = tvp514xm_init_reg_seq },
1144 { /* sentinel */ }
1145 };
1146 MODULE_DEVICE_TABLE(of, tvp514x_of_match);
1147
1148 static struct i2c_driver tvp514x_driver = {
1149 .driver = {
1150 .of_match_table = tvp514x_of_match,
1151 .name = TVP514X_MODULE_NAME,
1152 },
1153 .probe = tvp514x_probe,
1154 .remove = tvp514x_remove,
1155 .id_table = tvp514x_id,
1156 };
1157
1158 module_i2c_driver(tvp514x_driver);
1159