]>
Commit | Line | Data |
---|---|---|
07b1747c VH |
1 | /* |
2 | * drivers/media/video/tvp514x.c | |
3 | * | |
4 | * TI TVP5146/47 decoder driver | |
5 | * | |
6 | * Copyright (C) 2008 Texas Instruments Inc | |
7 | * Author: Vaibhav Hiremath <hvaibhav@ti.com> | |
8 | * | |
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> | |
15 | * | |
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. | |
19 | * | |
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. | |
24 | * | |
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. | |
28 | * | |
29 | */ | |
30 | ||
31 | #include <linux/i2c.h> | |
5a0e3ad6 | 32 | #include <linux/slab.h> |
07b1747c VH |
33 | #include <linux/delay.h> |
34 | #include <linux/videodev2.h> | |
62ef80a1 MK |
35 | |
36 | #include <media/v4l2-device.h> | |
37 | #include <media/v4l2-common.h> | |
38 | #include <media/v4l2-chip-ident.h> | |
07b1747c VH |
39 | #include <media/tvp514x.h> |
40 | ||
41 | #include "tvp514x_regs.h" | |
42 | ||
43 | /* Module Name */ | |
44 | #define TVP514X_MODULE_NAME "tvp514x" | |
45 | ||
46 | /* Private macros for TVP */ | |
47 | #define I2C_RETRY_COUNT (5) | |
48 | #define LOCK_RETRY_COUNT (5) | |
49 | #define LOCK_RETRY_DELAY (200) | |
50 | ||
51 | /* Debug functions */ | |
52 | static int debug; | |
53 | module_param(debug, bool, 0644); | |
54 | MODULE_PARM_DESC(debug, "Debug level (0-1)"); | |
55 | ||
62ef80a1 MK |
56 | MODULE_AUTHOR("Texas Instruments"); |
57 | MODULE_DESCRIPTION("TVP514X linux decoder driver"); | |
58 | MODULE_LICENSE("GPL"); | |
07b1747c | 59 | |
c1c9d09c | 60 | /* enum tvp514x_std - enum for supported standards */ |
07b1747c VH |
61 | enum tvp514x_std { |
62 | STD_NTSC_MJ = 0, | |
63 | STD_PAL_BDGHIN, | |
64 | STD_INVALID | |
65 | }; | |
66 | ||
c1c9d09c | 67 | /** |
07b1747c VH |
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 | |
73 | */ | |
74 | struct tvp514x_std_info { | |
75 | unsigned long width; | |
76 | unsigned long height; | |
77 | u8 video_std; | |
78 | struct v4l2_standard standard; | |
79 | }; | |
80 | ||
6722e0ef | 81 | static struct tvp514x_reg tvp514x_reg_list_default[0x40]; |
c1c9d09c | 82 | /** |
6722e0ef | 83 | * struct tvp514x_decoder - TVP5146/47 decoder object |
62ef80a1 | 84 | * @sd: Subdevice Slave handle |
6722e0ef | 85 | * @tvp514x_regs: copy of hw's regs with preset values. |
07b1747c | 86 | * @pdata: Board specific |
07b1747c | 87 | * @ver: Chip version |
62ef80a1 | 88 | * @streaming: TVP5146/47 decoder streaming - enabled or disabled. |
07b1747c VH |
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 | |
62ef80a1 MK |
95 | * @input: Input routing at chip level |
96 | * @output: Output routing at chip level | |
07b1747c VH |
97 | */ |
98 | struct tvp514x_decoder { | |
62ef80a1 | 99 | struct v4l2_subdev sd; |
6722e0ef | 100 | struct tvp514x_reg tvp514x_regs[ARRAY_SIZE(tvp514x_reg_list_default)]; |
07b1747c | 101 | const struct tvp514x_platform_data *pdata; |
07b1747c VH |
102 | |
103 | int ver; | |
62ef80a1 | 104 | int streaming; |
07b1747c VH |
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 | struct tvp514x_std_info *std_list; | |
c1c9d09c | 113 | /* Input and Output Routing parameters */ |
62ef80a1 MK |
114 | u32 input; |
115 | u32 output; | |
07b1747c VH |
116 | }; |
117 | ||
118 | /* TVP514x default register values */ | |
6722e0ef | 119 | static struct tvp514x_reg tvp514x_reg_list_default[] = { |
c1c9d09c MK |
120 | /* Composite selected */ |
121 | {TOK_WRITE, REG_INPUT_SEL, 0x05}, | |
07b1747c | 122 | {TOK_WRITE, REG_AFE_GAIN_CTRL, 0x0F}, |
c1c9d09c MK |
123 | /* Auto mode */ |
124 | {TOK_WRITE, REG_VIDEO_STD, 0x00}, | |
07b1747c VH |
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}, | |
c1c9d09c MK |
137 | /* Reserved */ |
138 | {TOK_SKIP, 0x0F, 0x00}, | |
07b1747c VH |
139 | {TOK_WRITE, REG_COMP_PR_SATURATION, 0x80}, |
140 | {TOK_WRITE, REG_COMP_Y_CONTRAST, 0x80}, | |
141 | {TOK_WRITE, REG_COMP_PB_SATURATION, 0x80}, | |
c1c9d09c MK |
142 | /* Reserved */ |
143 | {TOK_SKIP, 0x13, 0x00}, | |
07b1747c | 144 | {TOK_WRITE, REG_COMP_Y_BRIGHTNESS, 0x80}, |
c1c9d09c MK |
145 | /* Reserved */ |
146 | {TOK_SKIP, 0x15, 0x00}, | |
147 | /* NTSC timing */ | |
148 | {TOK_SKIP, REG_AVID_START_PIXEL_LSB, 0x55}, | |
07b1747c VH |
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}, | |
c1c9d09c MK |
152 | /* NTSC timing */ |
153 | {TOK_SKIP, REG_HSYNC_START_PIXEL_LSB, 0x00}, | |
07b1747c VH |
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}, | |
c1c9d09c MK |
157 | /* NTSC timing */ |
158 | {TOK_SKIP, REG_VSYNC_START_LINE_LSB, 0x04}, | |
07b1747c VH |
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}, | |
c1c9d09c MK |
162 | /* NTSC timing */ |
163 | {TOK_SKIP, REG_VBLK_START_LINE_LSB, 0x01}, | |
07b1747c VH |
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}, | |
c1c9d09c MK |
167 | /* Reserved */ |
168 | {TOK_SKIP, 0x26, 0x00}, | |
169 | /* Reserved */ | |
170 | {TOK_SKIP, 0x27, 0x00}, | |
07b1747c | 171 | {TOK_SKIP, REG_FAST_SWTICH_CONTROL, 0xCC}, |
c1c9d09c MK |
172 | /* Reserved */ |
173 | {TOK_SKIP, 0x29, 0x00}, | |
07b1747c | 174 | {TOK_SKIP, REG_FAST_SWTICH_SCART_DELAY, 0x00}, |
c1c9d09c MK |
175 | /* Reserved */ |
176 | {TOK_SKIP, 0x2B, 0x00}, | |
07b1747c VH |
177 | {TOK_SKIP, REG_SCART_DELAY, 0x00}, |
178 | {TOK_SKIP, REG_CTI_DELAY, 0x00}, | |
179 | {TOK_SKIP, REG_CTI_CONTROL, 0x00}, | |
c1c9d09c MK |
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}, | |
07b1747c VH |
196 | {TOK_WRITE, REG_OUTPUT_FORMATTER5, 0xFF}, |
197 | {TOK_WRITE, REG_OUTPUT_FORMATTER6, 0xFF}, | |
c1c9d09c MK |
198 | /* Clear status */ |
199 | {TOK_WRITE, REG_CLEAR_LOST_LOCK, 0x01}, | |
07b1747c VH |
200 | {TOK_TERM, 0, 0}, |
201 | }; | |
202 | ||
c1c9d09c | 203 | /** |
62ef80a1 | 204 | * List of image formats supported by TVP5146/47 decoder |
07b1747c VH |
205 | * Currently we are using 8 bit mode only, but can be |
206 | * extended to 10/20 bit mode. | |
207 | */ | |
208 | static const struct v4l2_fmtdesc tvp514x_fmt_list[] = { | |
209 | { | |
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, | |
215 | }, | |
216 | }; | |
217 | ||
c1c9d09c | 218 | /** |
07b1747c VH |
219 | * Supported standards - |
220 | * | |
221 | * Currently supports two standards only, need to add support for rest of the | |
222 | * modes, like SECAM, etc... | |
223 | */ | |
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 | |
236 | }, | |
237 | /* Standard: STD_PAL_BDGHIN */ | |
238 | }, | |
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 | |
249 | }, | |
250 | }, | |
251 | /* Standard: need to add for additional standard */ | |
252 | }; | |
62ef80a1 MK |
253 | |
254 | ||
255 | static inline struct tvp514x_decoder *to_decoder(struct v4l2_subdev *sd) | |
256 | { | |
257 | return container_of(sd, struct tvp514x_decoder, sd); | |
258 | } | |
259 | ||
07b1747c | 260 | |
c1c9d09c MK |
261 | /** |
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 | |
265 | * | |
07b1747c VH |
266 | * Returns value read if successful, or non-zero (-1) otherwise. |
267 | */ | |
62ef80a1 | 268 | static int tvp514x_read_reg(struct v4l2_subdev *sd, u8 reg) |
07b1747c | 269 | { |
62ef80a1 MK |
270 | int err, retry = 0; |
271 | struct i2c_client *client = v4l2_get_subdevdata(sd); | |
272 | ||
07b1747c VH |
273 | read_again: |
274 | ||
275 | err = i2c_smbus_read_byte_data(client, reg); | |
6f901a99 | 276 | if (err < 0) { |
07b1747c | 277 | if (retry <= I2C_RETRY_COUNT) { |
62ef80a1 | 278 | v4l2_warn(sd, "Read: retry ... %d\n", retry); |
07b1747c VH |
279 | retry++; |
280 | msleep_interruptible(10); | |
281 | goto read_again; | |
282 | } | |
283 | } | |
284 | ||
285 | return err; | |
286 | } | |
287 | ||
c1c9d09c MK |
288 | /** |
289 | * dump_reg() - dump the register content of TVP5146/47. | |
290 | * @sd: ptr to v4l2_subdev struct | |
291 | * @reg: TVP5146/47 register address | |
292 | */ | |
62ef80a1 MK |
293 | static void dump_reg(struct v4l2_subdev *sd, u8 reg) |
294 | { | |
295 | u32 val; | |
296 | ||
297 | val = tvp514x_read_reg(sd, reg); | |
298 | v4l2_info(sd, "Reg(0x%.2X): 0x%.2X\n", reg, val); | |
299 | } | |
300 | ||
c1c9d09c MK |
301 | /** |
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 | |
306 | * | |
07b1747c VH |
307 | * Write a value to a register in an TVP5146/47 decoder device. |
308 | * Returns zero if successful, or non-zero otherwise. | |
309 | */ | |
62ef80a1 | 310 | static int tvp514x_write_reg(struct v4l2_subdev *sd, u8 reg, u8 val) |
07b1747c | 311 | { |
62ef80a1 MK |
312 | int err, retry = 0; |
313 | struct i2c_client *client = v4l2_get_subdevdata(sd); | |
314 | ||
07b1747c VH |
315 | write_again: |
316 | ||
317 | err = i2c_smbus_write_byte_data(client, reg, val); | |
318 | if (err) { | |
319 | if (retry <= I2C_RETRY_COUNT) { | |
62ef80a1 | 320 | v4l2_warn(sd, "Write: retry ... %d\n", retry); |
07b1747c VH |
321 | retry++; |
322 | msleep_interruptible(10); | |
323 | goto write_again; | |
324 | } | |
325 | } | |
326 | ||
327 | return err; | |
328 | } | |
329 | ||
c1c9d09c MK |
330 | /** |
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 | |
334 | * | |
335 | * Initializes a list of TVP5146/47 registers:- | |
07b1747c VH |
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 | |
07b1747c VH |
340 | * Returns zero if successful, or non-zero otherwise. |
341 | */ | |
62ef80a1 | 342 | static int tvp514x_write_regs(struct v4l2_subdev *sd, |
07b1747c VH |
343 | const struct tvp514x_reg reglist[]) |
344 | { | |
345 | int err; | |
346 | const struct tvp514x_reg *next = reglist; | |
347 | ||
348 | for (; next->token != TOK_TERM; next++) { | |
349 | if (next->token == TOK_DELAY) { | |
350 | msleep(next->val); | |
351 | continue; | |
352 | } | |
353 | ||
354 | if (next->token == TOK_SKIP) | |
355 | continue; | |
356 | ||
62ef80a1 | 357 | err = tvp514x_write_reg(sd, next->reg, (u8) next->val); |
07b1747c | 358 | if (err) { |
62ef80a1 | 359 | v4l2_err(sd, "Write failed. Err[%d]\n", err); |
07b1747c VH |
360 | return err; |
361 | } | |
362 | } | |
363 | return 0; | |
364 | } | |
365 | ||
c1c9d09c MK |
366 | /** |
367 | * tvp514x_get_current_std() : Get the current standard detected by TVP5146/47 | |
368 | * @sd: ptr to v4l2_subdev struct | |
369 | * | |
370 | * Get current standard detected by TVP5146/47, STD_INVALID if there is no | |
371 | * standard detected. | |
07b1747c | 372 | */ |
62ef80a1 | 373 | static enum tvp514x_std tvp514x_get_current_std(struct v4l2_subdev *sd) |
07b1747c VH |
374 | { |
375 | u8 std, std_status; | |
376 | ||
62ef80a1 MK |
377 | std = tvp514x_read_reg(sd, REG_VIDEO_STD); |
378 | if ((std & VIDEO_STD_MASK) == VIDEO_STD_AUTO_SWITCH_BIT) | |
07b1747c | 379 | /* use the standard status register */ |
62ef80a1 MK |
380 | std_status = tvp514x_read_reg(sd, REG_VIDEO_STD_STATUS); |
381 | else | |
c1c9d09c MK |
382 | /* use the standard register itself */ |
383 | std_status = std; | |
07b1747c VH |
384 | |
385 | switch (std_status & VIDEO_STD_MASK) { | |
386 | case VIDEO_STD_NTSC_MJ_BIT: | |
387 | return STD_NTSC_MJ; | |
388 | ||
389 | case VIDEO_STD_PAL_BDGHIN_BIT: | |
390 | return STD_PAL_BDGHIN; | |
391 | ||
392 | default: | |
393 | return STD_INVALID; | |
394 | } | |
395 | ||
396 | return STD_INVALID; | |
397 | } | |
398 | ||
c1c9d09c | 399 | /* TVP5146/47 register dump function */ |
62ef80a1 | 400 | static void tvp514x_reg_dump(struct v4l2_subdev *sd) |
07b1747c | 401 | { |
62ef80a1 MK |
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); | |
07b1747c VH |
444 | } |
445 | ||
c1c9d09c MK |
446 | /** |
447 | * tvp514x_configure() - Configure the TVP5146/47 registers | |
448 | * @sd: ptr to v4l2_subdev struct | |
449 | * @decoder: ptr to tvp514x_decoder structure | |
450 | * | |
07b1747c VH |
451 | * Returns zero if successful, or non-zero otherwise. |
452 | */ | |
62ef80a1 MK |
453 | static int tvp514x_configure(struct v4l2_subdev *sd, |
454 | struct tvp514x_decoder *decoder) | |
07b1747c VH |
455 | { |
456 | int err; | |
457 | ||
458 | /* common register initialization */ | |
459 | err = | |
62ef80a1 | 460 | tvp514x_write_regs(sd, decoder->tvp514x_regs); |
07b1747c VH |
461 | if (err) |
462 | return err; | |
463 | ||
464 | if (debug) | |
62ef80a1 | 465 | tvp514x_reg_dump(sd); |
07b1747c VH |
466 | |
467 | return 0; | |
468 | } | |
469 | ||
c1c9d09c MK |
470 | /** |
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 | |
474 | * | |
07b1747c VH |
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. | |
480 | */ | |
62ef80a1 MK |
481 | static int tvp514x_detect(struct v4l2_subdev *sd, |
482 | struct tvp514x_decoder *decoder) | |
07b1747c VH |
483 | { |
484 | u8 chip_id_msb, chip_id_lsb, rom_ver; | |
62ef80a1 | 485 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
07b1747c | 486 | |
62ef80a1 MK |
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); | |
07b1747c | 490 | |
62ef80a1 | 491 | v4l2_dbg(1, debug, sd, |
07b1747c VH |
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. | |
499 | */ | |
62ef80a1 MK |
500 | v4l2_err(sd, "chip id mismatch msb:0x%x lsb:0x%x\n", |
501 | chip_id_msb, chip_id_lsb); | |
07b1747c VH |
502 | return -ENODEV; |
503 | } | |
504 | ||
505 | decoder->ver = rom_ver; | |
07b1747c | 506 | |
62ef80a1 MK |
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); | |
07b1747c VH |
510 | return 0; |
511 | } | |
512 | ||
c1c9d09c MK |
513 | /** |
514 | * tvp514x_querystd() - V4L2 decoder interface handler for querystd | |
62ef80a1 | 515 | * @sd: pointer to standard V4L2 sub-device structure |
07b1747c VH |
516 | * @std_id: standard V4L2 std_id ioctl enum |
517 | * | |
518 | * Returns the current standard detected by TVP5146/47. If no active input is | |
519 | * detected, returns -EINVAL | |
520 | */ | |
62ef80a1 | 521 | static int tvp514x_querystd(struct v4l2_subdev *sd, v4l2_std_id *std_id) |
07b1747c | 522 | { |
62ef80a1 | 523 | struct tvp514x_decoder *decoder = to_decoder(sd); |
07b1747c VH |
524 | enum tvp514x_std current_std; |
525 | enum tvp514x_input input_sel; | |
526 | u8 sync_lock_status, lock_mask; | |
527 | ||
528 | if (std_id == NULL) | |
529 | return -EINVAL; | |
530 | ||
531 | /* get the current standard */ | |
62ef80a1 | 532 | current_std = tvp514x_get_current_std(sd); |
07b1747c VH |
533 | if (current_std == STD_INVALID) |
534 | return -EINVAL; | |
535 | ||
62ef80a1 | 536 | input_sel = decoder->input; |
07b1747c VH |
537 | |
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; | |
553 | ||
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; | |
572 | } | |
573 | /* check whether signal is locked */ | |
62ef80a1 | 574 | sync_lock_status = tvp514x_read_reg(sd, REG_STATUS1); |
07b1747c VH |
575 | if (lock_mask != (sync_lock_status & lock_mask)) |
576 | return -EINVAL; /* No input detected */ | |
577 | ||
578 | decoder->current_std = current_std; | |
579 | *std_id = decoder->std_list[current_std].standard.id; | |
580 | ||
62ef80a1 | 581 | v4l2_dbg(1, debug, sd, "Current STD: %s", |
07b1747c VH |
582 | decoder->std_list[current_std].standard.name); |
583 | return 0; | |
584 | } | |
585 | ||
c1c9d09c MK |
586 | /** |
587 | * tvp514x_s_std() - V4L2 decoder interface handler for s_std | |
62ef80a1 | 588 | * @sd: pointer to standard V4L2 sub-device structure |
07b1747c VH |
589 | * @std_id: standard V4L2 v4l2_std_id ioctl enum |
590 | * | |
591 | * If std_id is supported, sets the requested standard. Otherwise, returns | |
592 | * -EINVAL | |
593 | */ | |
62ef80a1 | 594 | static int tvp514x_s_std(struct v4l2_subdev *sd, v4l2_std_id std_id) |
07b1747c | 595 | { |
62ef80a1 | 596 | struct tvp514x_decoder *decoder = to_decoder(sd); |
07b1747c VH |
597 | int err, i; |
598 | ||
07b1747c | 599 | for (i = 0; i < decoder->num_stds; i++) |
62ef80a1 | 600 | if (std_id & decoder->std_list[i].standard.id) |
07b1747c VH |
601 | break; |
602 | ||
603 | if ((i == decoder->num_stds) || (i == STD_INVALID)) | |
604 | return -EINVAL; | |
605 | ||
62ef80a1 | 606 | err = tvp514x_write_reg(sd, REG_VIDEO_STD, |
07b1747c VH |
607 | decoder->std_list[i].video_std); |
608 | if (err) | |
609 | return err; | |
610 | ||
611 | decoder->current_std = i; | |
6722e0ef SAS |
612 | decoder->tvp514x_regs[REG_VIDEO_STD].val = |
613 | decoder->std_list[i].video_std; | |
07b1747c | 614 | |
62ef80a1 | 615 | v4l2_dbg(1, debug, sd, "Standard set to: %s", |
07b1747c VH |
616 | decoder->std_list[i].standard.name); |
617 | return 0; | |
618 | } | |
619 | ||
c1c9d09c MK |
620 | /** |
621 | * tvp514x_s_routing() - V4L2 decoder interface handler for s_routing | |
62ef80a1 | 622 | * @sd: pointer to standard V4L2 sub-device structure |
c1c9d09c MK |
623 | * @input: input selector for routing the signal |
624 | * @output: output selector for routing the signal | |
625 | * @config: config value. Not used | |
07b1747c VH |
626 | * |
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. | |
630 | */ | |
62ef80a1 MK |
631 | static int tvp514x_s_routing(struct v4l2_subdev *sd, |
632 | u32 input, u32 output, u32 config) | |
07b1747c | 633 | { |
62ef80a1 | 634 | struct tvp514x_decoder *decoder = to_decoder(sd); |
07b1747c VH |
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; | |
641 | ||
62ef80a1 MK |
642 | if ((input >= INPUT_INVALID) || |
643 | (output >= OUTPUT_INVALID)) | |
c1c9d09c MK |
644 | /* Index out of bound */ |
645 | return -EINVAL; | |
07b1747c | 646 | |
62ef80a1 MK |
647 | input_sel = input; |
648 | output_sel = output; | |
07b1747c | 649 | |
62ef80a1 | 650 | err = tvp514x_write_reg(sd, REG_INPUT_SEL, input_sel); |
07b1747c VH |
651 | if (err) |
652 | return err; | |
653 | ||
62ef80a1 | 654 | output_sel |= tvp514x_read_reg(sd, |
07b1747c | 655 | REG_OUTPUT_FORMATTER1) & 0x7; |
62ef80a1 | 656 | err = tvp514x_write_reg(sd, REG_OUTPUT_FORMATTER1, |
07b1747c VH |
657 | output_sel); |
658 | if (err) | |
659 | return err; | |
660 | ||
6722e0ef SAS |
661 | decoder->tvp514x_regs[REG_INPUT_SEL].val = input_sel; |
662 | decoder->tvp514x_regs[REG_OUTPUT_FORMATTER1].val = output_sel; | |
07b1747c VH |
663 | |
664 | /* Clear status */ | |
665 | msleep(LOCK_RETRY_DELAY); | |
666 | err = | |
62ef80a1 | 667 | tvp514x_write_reg(sd, REG_CLEAR_LOST_LOCK, 0x01); |
07b1747c VH |
668 | if (err) |
669 | return err; | |
670 | ||
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; | |
686 | ||
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; | |
c1c9d09c | 702 | /* Need to add other interfaces*/ |
07b1747c VH |
703 | default: |
704 | return -EINVAL; | |
705 | } | |
706 | ||
707 | while (try_count-- > 0) { | |
708 | /* Allow decoder to sync up with new input */ | |
709 | msleep(LOCK_RETRY_DELAY); | |
710 | ||
711 | /* get the current standard for future reference */ | |
62ef80a1 | 712 | current_std = tvp514x_get_current_std(sd); |
07b1747c VH |
713 | if (current_std == STD_INVALID) |
714 | continue; | |
715 | ||
62ef80a1 | 716 | sync_lock_status = tvp514x_read_reg(sd, |
07b1747c VH |
717 | REG_STATUS1); |
718 | if (lock_mask == (sync_lock_status & lock_mask)) | |
c1c9d09c MK |
719 | /* Input detected */ |
720 | break; | |
07b1747c VH |
721 | } |
722 | ||
76b08116 | 723 | if ((current_std == STD_INVALID) || (try_count < 0)) |
07b1747c VH |
724 | return -EINVAL; |
725 | ||
726 | decoder->current_std = current_std; | |
62ef80a1 MK |
727 | decoder->input = input; |
728 | decoder->output = output; | |
07b1747c | 729 | |
62ef80a1 | 730 | v4l2_dbg(1, debug, sd, "Input set to: %d, std : %d", |
07b1747c VH |
731 | input_sel, current_std); |
732 | ||
733 | return 0; | |
734 | } | |
735 | ||
c1c9d09c MK |
736 | /** |
737 | * tvp514x_queryctrl() - V4L2 decoder interface handler for queryctrl | |
62ef80a1 | 738 | * @sd: pointer to standard V4L2 sub-device structure |
07b1747c VH |
739 | * @qctrl: standard V4L2 v4l2_queryctrl structure |
740 | * | |
741 | * If the requested control is supported, returns the control information. | |
742 | * Otherwise, returns -EINVAL if the control is not supported. | |
743 | */ | |
744 | static int | |
62ef80a1 | 745 | tvp514x_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qctrl) |
07b1747c | 746 | { |
07b1747c VH |
747 | int err = -EINVAL; |
748 | ||
749 | if (qctrl == NULL) | |
750 | return err; | |
751 | ||
752 | switch (qctrl->id) { | |
753 | case V4L2_CID_BRIGHTNESS: | |
c1c9d09c | 754 | /* Brightness supported is (0-255), */ |
10afbef1 | 755 | err = v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 128); |
07b1747c VH |
756 | break; |
757 | case V4L2_CID_CONTRAST: | |
758 | case V4L2_CID_SATURATION: | |
c1c9d09c MK |
759 | /** |
760 | * Saturation and Contrast supported is - | |
07b1747c VH |
761 | * Contrast: 0 - 255 (Default - 128) |
762 | * Saturation: 0 - 255 (Default - 128) | |
763 | */ | |
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) | |
769 | */ | |
770 | err = v4l2_ctrl_query_fill(qctrl, -180, 180, 180, 0); | |
771 | break; | |
772 | case V4L2_CID_AUTOGAIN: | |
c1c9d09c | 773 | /** |
62ef80a1 MK |
774 | * Auto Gain supported is - |
775 | * 0 - 1 (Default - 1) | |
776 | */ | |
777 | err = v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 1); | |
07b1747c VH |
778 | break; |
779 | default: | |
62ef80a1 | 780 | v4l2_err(sd, "invalid control id %d\n", qctrl->id); |
07b1747c VH |
781 | return err; |
782 | } | |
783 | ||
62ef80a1 MK |
784 | v4l2_dbg(1, debug, sd, "Query Control:%s: Min - %d, Max - %d, Def - %d", |
785 | qctrl->name, qctrl->minimum, qctrl->maximum, | |
07b1747c VH |
786 | qctrl->default_value); |
787 | ||
788 | return err; | |
789 | } | |
790 | ||
c1c9d09c MK |
791 | /** |
792 | * tvp514x_g_ctrl() - V4L2 decoder interface handler for g_ctrl | |
62ef80a1 | 793 | * @sd: pointer to standard V4L2 sub-device structure |
07b1747c VH |
794 | * @ctrl: pointer to v4l2_control structure |
795 | * | |
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. | |
799 | */ | |
800 | static int | |
62ef80a1 | 801 | tvp514x_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) |
07b1747c | 802 | { |
62ef80a1 | 803 | struct tvp514x_decoder *decoder = to_decoder(sd); |
07b1747c VH |
804 | |
805 | if (ctrl == NULL) | |
806 | return -EINVAL; | |
807 | ||
808 | switch (ctrl->id) { | |
809 | case V4L2_CID_BRIGHTNESS: | |
6722e0ef | 810 | ctrl->value = decoder->tvp514x_regs[REG_BRIGHTNESS].val; |
07b1747c VH |
811 | break; |
812 | case V4L2_CID_CONTRAST: | |
6722e0ef | 813 | ctrl->value = decoder->tvp514x_regs[REG_CONTRAST].val; |
07b1747c VH |
814 | break; |
815 | case V4L2_CID_SATURATION: | |
6722e0ef | 816 | ctrl->value = decoder->tvp514x_regs[REG_SATURATION].val; |
07b1747c VH |
817 | break; |
818 | case V4L2_CID_HUE: | |
6722e0ef | 819 | ctrl->value = decoder->tvp514x_regs[REG_HUE].val; |
07b1747c VH |
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; | |
826 | ||
827 | break; | |
828 | case V4L2_CID_AUTOGAIN: | |
6722e0ef | 829 | ctrl->value = decoder->tvp514x_regs[REG_AFE_GAIN_CTRL].val; |
07b1747c VH |
830 | if ((ctrl->value & 0x3) == 3) |
831 | ctrl->value = 1; | |
832 | else | |
833 | ctrl->value = 0; | |
834 | ||
835 | break; | |
836 | default: | |
62ef80a1 | 837 | v4l2_err(sd, "invalid control id %d\n", ctrl->id); |
07b1747c VH |
838 | return -EINVAL; |
839 | } | |
840 | ||
62ef80a1 | 841 | v4l2_dbg(1, debug, sd, "Get Control: ID - %d - %d", |
07b1747c VH |
842 | ctrl->id, ctrl->value); |
843 | return 0; | |
844 | } | |
845 | ||
c1c9d09c MK |
846 | /** |
847 | * tvp514x_s_ctrl() - V4L2 decoder interface handler for s_ctrl | |
62ef80a1 | 848 | * @sd: pointer to standard V4L2 sub-device structure |
07b1747c VH |
849 | * @ctrl: pointer to v4l2_control structure |
850 | * | |
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. | |
853 | */ | |
854 | static int | |
62ef80a1 | 855 | tvp514x_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) |
07b1747c | 856 | { |
62ef80a1 | 857 | struct tvp514x_decoder *decoder = to_decoder(sd); |
07b1747c VH |
858 | int err = -EINVAL, value; |
859 | ||
860 | if (ctrl == NULL) | |
861 | return err; | |
862 | ||
62ef80a1 | 863 | value = ctrl->value; |
07b1747c VH |
864 | |
865 | switch (ctrl->id) { | |
866 | case V4L2_CID_BRIGHTNESS: | |
867 | if (ctrl->value < 0 || ctrl->value > 255) { | |
62ef80a1 | 868 | v4l2_err(sd, "invalid brightness setting %d\n", |
07b1747c VH |
869 | ctrl->value); |
870 | return -ERANGE; | |
871 | } | |
62ef80a1 | 872 | err = tvp514x_write_reg(sd, REG_BRIGHTNESS, |
07b1747c VH |
873 | value); |
874 | if (err) | |
875 | return err; | |
62ef80a1 | 876 | |
6722e0ef | 877 | decoder->tvp514x_regs[REG_BRIGHTNESS].val = value; |
07b1747c VH |
878 | break; |
879 | case V4L2_CID_CONTRAST: | |
880 | if (ctrl->value < 0 || ctrl->value > 255) { | |
62ef80a1 | 881 | v4l2_err(sd, "invalid contrast setting %d\n", |
07b1747c VH |
882 | ctrl->value); |
883 | return -ERANGE; | |
884 | } | |
62ef80a1 | 885 | err = tvp514x_write_reg(sd, REG_CONTRAST, value); |
07b1747c VH |
886 | if (err) |
887 | return err; | |
62ef80a1 | 888 | |
6722e0ef | 889 | decoder->tvp514x_regs[REG_CONTRAST].val = value; |
07b1747c VH |
890 | break; |
891 | case V4L2_CID_SATURATION: | |
892 | if (ctrl->value < 0 || ctrl->value > 255) { | |
62ef80a1 | 893 | v4l2_err(sd, "invalid saturation setting %d\n", |
07b1747c VH |
894 | ctrl->value); |
895 | return -ERANGE; | |
896 | } | |
62ef80a1 | 897 | err = tvp514x_write_reg(sd, REG_SATURATION, value); |
07b1747c VH |
898 | if (err) |
899 | return err; | |
62ef80a1 | 900 | |
6722e0ef | 901 | decoder->tvp514x_regs[REG_SATURATION].val = value; |
07b1747c VH |
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 { | |
62ef80a1 | 911 | v4l2_err(sd, "invalid hue setting %d\n", ctrl->value); |
07b1747c VH |
912 | return -ERANGE; |
913 | } | |
62ef80a1 | 914 | err = tvp514x_write_reg(sd, REG_HUE, value); |
07b1747c VH |
915 | if (err) |
916 | return err; | |
62ef80a1 | 917 | |
6722e0ef | 918 | decoder->tvp514x_regs[REG_HUE].val = value; |
07b1747c VH |
919 | break; |
920 | case V4L2_CID_AUTOGAIN: | |
921 | if (value == 1) | |
922 | value = 0x0F; | |
923 | else if (value == 0) | |
924 | value = 0x0C; | |
925 | else { | |
62ef80a1 | 926 | v4l2_err(sd, "invalid auto gain setting %d\n", |
07b1747c VH |
927 | ctrl->value); |
928 | return -ERANGE; | |
929 | } | |
62ef80a1 | 930 | err = tvp514x_write_reg(sd, REG_AFE_GAIN_CTRL, value); |
07b1747c VH |
931 | if (err) |
932 | return err; | |
62ef80a1 | 933 | |
6722e0ef | 934 | decoder->tvp514x_regs[REG_AFE_GAIN_CTRL].val = value; |
07b1747c VH |
935 | break; |
936 | default: | |
62ef80a1 | 937 | v4l2_err(sd, "invalid control id %d\n", ctrl->id); |
07b1747c VH |
938 | return err; |
939 | } | |
940 | ||
62ef80a1 | 941 | v4l2_dbg(1, debug, sd, "Set Control: ID - %d - %d", |
07b1747c VH |
942 | ctrl->id, ctrl->value); |
943 | ||
944 | return err; | |
945 | } | |
946 | ||
c1c9d09c MK |
947 | /** |
948 | * tvp514x_enum_fmt_cap() - V4L2 decoder interface handler for enum_fmt | |
62ef80a1 | 949 | * @sd: pointer to standard V4L2 sub-device structure |
07b1747c VH |
950 | * @fmt: standard V4L2 VIDIOC_ENUM_FMT ioctl structure |
951 | * | |
952 | * Implement the VIDIOC_ENUM_FMT ioctl to enumerate supported formats | |
953 | */ | |
954 | static int | |
62ef80a1 | 955 | tvp514x_enum_fmt_cap(struct v4l2_subdev *sd, struct v4l2_fmtdesc *fmt) |
07b1747c | 956 | { |
62ef80a1 | 957 | struct tvp514x_decoder *decoder = to_decoder(sd); |
07b1747c VH |
958 | int index; |
959 | ||
960 | if (fmt == NULL) | |
961 | return -EINVAL; | |
962 | ||
963 | index = fmt->index; | |
964 | if ((index >= decoder->num_fmts) || (index < 0)) | |
c1c9d09c MK |
965 | /* Index out of bound */ |
966 | return -EINVAL; | |
07b1747c VH |
967 | |
968 | if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | |
c1c9d09c MK |
969 | /* only capture is supported */ |
970 | return -EINVAL; | |
07b1747c VH |
971 | |
972 | memcpy(fmt, &decoder->fmt_list[index], | |
973 | sizeof(struct v4l2_fmtdesc)); | |
974 | ||
62ef80a1 | 975 | v4l2_dbg(1, debug, sd, "Current FMT: index - %d (%s)", |
07b1747c VH |
976 | decoder->fmt_list[index].index, |
977 | decoder->fmt_list[index].description); | |
978 | return 0; | |
979 | } | |
980 | ||
c1c9d09c MK |
981 | /** |
982 | * tvp514x_try_fmt_cap() - V4L2 decoder interface handler for try_fmt | |
62ef80a1 | 983 | * @sd: pointer to standard V4L2 sub-device structure |
07b1747c VH |
984 | * @f: pointer to standard V4L2 VIDIOC_TRY_FMT ioctl structure |
985 | * | |
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. | |
989 | */ | |
990 | static int | |
62ef80a1 | 991 | tvp514x_try_fmt_cap(struct v4l2_subdev *sd, struct v4l2_format *f) |
07b1747c | 992 | { |
62ef80a1 | 993 | struct tvp514x_decoder *decoder = to_decoder(sd); |
07b1747c VH |
994 | int ifmt; |
995 | struct v4l2_pix_format *pix; | |
996 | enum tvp514x_std current_std; | |
997 | ||
998 | if (f == NULL) | |
999 | return -EINVAL; | |
1000 | ||
1001 | if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | |
c1c9d09c | 1002 | /* only capture is supported */ |
07b1747c VH |
1003 | f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
1004 | ||
1005 | pix = &f->fmt.pix; | |
1006 | ||
1007 | /* Calculate height and width based on current standard */ | |
62ef80a1 | 1008 | current_std = tvp514x_get_current_std(sd); |
07b1747c VH |
1009 | if (current_std == STD_INVALID) |
1010 | return -EINVAL; | |
1011 | ||
1012 | decoder->current_std = current_std; | |
1013 | pix->width = decoder->std_list[current_std].width; | |
1014 | pix->height = decoder->std_list[current_std].height; | |
1015 | ||
1016 | for (ifmt = 0; ifmt < decoder->num_fmts; ifmt++) { | |
1017 | if (pix->pixelformat == | |
1018 | decoder->fmt_list[ifmt].pixelformat) | |
1019 | break; | |
1020 | } | |
1021 | if (ifmt == decoder->num_fmts) | |
c1c9d09c MK |
1022 | /* None of the format matched, select default */ |
1023 | ifmt = 0; | |
07b1747c VH |
1024 | pix->pixelformat = decoder->fmt_list[ifmt].pixelformat; |
1025 | ||
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; | |
1031 | ||
62ef80a1 | 1032 | v4l2_dbg(1, debug, sd, "Try FMT: pixelformat - %s, bytesperline - %d" |
07b1747c VH |
1033 | "Width - %d, Height - %d", |
1034 | decoder->fmt_list[ifmt].description, pix->bytesperline, | |
1035 | pix->width, pix->height); | |
1036 | return 0; | |
1037 | } | |
1038 | ||
c1c9d09c MK |
1039 | /** |
1040 | * tvp514x_s_fmt_cap() - V4L2 decoder interface handler for s_fmt | |
62ef80a1 | 1041 | * @sd: pointer to standard V4L2 sub-device structure |
07b1747c VH |
1042 | * @f: pointer to standard V4L2 VIDIOC_S_FMT ioctl structure |
1043 | * | |
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. | |
1047 | */ | |
1048 | static int | |
62ef80a1 | 1049 | tvp514x_s_fmt_cap(struct v4l2_subdev *sd, struct v4l2_format *f) |
07b1747c | 1050 | { |
62ef80a1 | 1051 | struct tvp514x_decoder *decoder = to_decoder(sd); |
07b1747c VH |
1052 | struct v4l2_pix_format *pix; |
1053 | int rval; | |
1054 | ||
1055 | if (f == NULL) | |
1056 | return -EINVAL; | |
1057 | ||
1058 | if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | |
c1c9d09c MK |
1059 | /* only capture is supported */ |
1060 | return -EINVAL; | |
07b1747c VH |
1061 | |
1062 | pix = &f->fmt.pix; | |
62ef80a1 | 1063 | rval = tvp514x_try_fmt_cap(sd, f); |
07b1747c VH |
1064 | if (rval) |
1065 | return rval; | |
1066 | ||
1067 | decoder->pix = *pix; | |
1068 | ||
1069 | return rval; | |
1070 | } | |
1071 | ||
c1c9d09c MK |
1072 | /** |
1073 | * tvp514x_g_fmt_cap() - V4L2 decoder interface handler for tvp514x_g_fmt_cap | |
62ef80a1 | 1074 | * @sd: pointer to standard V4L2 sub-device structure |
07b1747c VH |
1075 | * @f: pointer to standard V4L2 v4l2_format structure |
1076 | * | |
1077 | * Returns the decoder's current pixel format in the v4l2_format | |
1078 | * parameter. | |
1079 | */ | |
1080 | static int | |
62ef80a1 | 1081 | tvp514x_g_fmt_cap(struct v4l2_subdev *sd, struct v4l2_format *f) |
07b1747c | 1082 | { |
62ef80a1 | 1083 | struct tvp514x_decoder *decoder = to_decoder(sd); |
07b1747c VH |
1084 | |
1085 | if (f == NULL) | |
1086 | return -EINVAL; | |
1087 | ||
1088 | if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | |
c1c9d09c MK |
1089 | /* only capture is supported */ |
1090 | return -EINVAL; | |
07b1747c VH |
1091 | |
1092 | f->fmt.pix = decoder->pix; | |
1093 | ||
62ef80a1 | 1094 | v4l2_dbg(1, debug, sd, "Current FMT: bytesperline - %d" |
07b1747c VH |
1095 | "Width - %d, Height - %d", |
1096 | decoder->pix.bytesperline, | |
1097 | decoder->pix.width, decoder->pix.height); | |
1098 | return 0; | |
1099 | } | |
1100 | ||
c1c9d09c MK |
1101 | /** |
1102 | * tvp514x_g_parm() - V4L2 decoder interface handler for g_parm | |
62ef80a1 | 1103 | * @sd: pointer to standard V4L2 sub-device structure |
07b1747c VH |
1104 | * @a: pointer to standard V4L2 VIDIOC_G_PARM ioctl structure |
1105 | * | |
1106 | * Returns the decoder's video CAPTURE parameters. | |
1107 | */ | |
1108 | static int | |
62ef80a1 | 1109 | tvp514x_g_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *a) |
07b1747c | 1110 | { |
62ef80a1 | 1111 | struct tvp514x_decoder *decoder = to_decoder(sd); |
07b1747c VH |
1112 | struct v4l2_captureparm *cparm; |
1113 | enum tvp514x_std current_std; | |
1114 | ||
1115 | if (a == NULL) | |
1116 | return -EINVAL; | |
1117 | ||
1118 | if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | |
c1c9d09c MK |
1119 | /* only capture is supported */ |
1120 | return -EINVAL; | |
07b1747c VH |
1121 | |
1122 | memset(a, 0, sizeof(*a)); | |
1123 | a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; | |
1124 | ||
1125 | /* get the current standard */ | |
62ef80a1 | 1126 | current_std = tvp514x_get_current_std(sd); |
07b1747c VH |
1127 | if (current_std == STD_INVALID) |
1128 | return -EINVAL; | |
1129 | ||
1130 | decoder->current_std = current_std; | |
1131 | ||
1132 | cparm = &a->parm.capture; | |
1133 | cparm->capability = V4L2_CAP_TIMEPERFRAME; | |
1134 | cparm->timeperframe = | |
1135 | decoder->std_list[current_std].standard.frameperiod; | |
1136 | ||
1137 | return 0; | |
1138 | } | |
1139 | ||
c1c9d09c MK |
1140 | /** |
1141 | * tvp514x_s_parm() - V4L2 decoder interface handler for s_parm | |
62ef80a1 | 1142 | * @sd: pointer to standard V4L2 sub-device structure |
07b1747c VH |
1143 | * @a: pointer to standard V4L2 VIDIOC_S_PARM ioctl structure |
1144 | * | |
1145 | * Configures the decoder to use the input parameters, if possible. If | |
1146 | * not possible, returns the appropriate error code. | |
1147 | */ | |
1148 | static int | |
62ef80a1 | 1149 | tvp514x_s_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *a) |
07b1747c | 1150 | { |
62ef80a1 | 1151 | struct tvp514x_decoder *decoder = to_decoder(sd); |
07b1747c VH |
1152 | struct v4l2_fract *timeperframe; |
1153 | enum tvp514x_std current_std; | |
1154 | ||
1155 | if (a == NULL) | |
1156 | return -EINVAL; | |
1157 | ||
1158 | if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | |
c1c9d09c MK |
1159 | /* only capture is supported */ |
1160 | return -EINVAL; | |
07b1747c VH |
1161 | |
1162 | timeperframe = &a->parm.capture.timeperframe; | |
1163 | ||
1164 | /* get the current standard */ | |
62ef80a1 | 1165 | current_std = tvp514x_get_current_std(sd); |
07b1747c VH |
1166 | if (current_std == STD_INVALID) |
1167 | return -EINVAL; | |
1168 | ||
1169 | decoder->current_std = current_std; | |
1170 | ||
1171 | *timeperframe = | |
1172 | decoder->std_list[current_std].standard.frameperiod; | |
1173 | ||
1174 | return 0; | |
1175 | } | |
1176 | ||
c1c9d09c MK |
1177 | /** |
1178 | * tvp514x_s_stream() - V4L2 decoder i/f handler for s_stream | |
62ef80a1 MK |
1179 | * @sd: pointer to standard V4L2 sub-device structure |
1180 | * @enable: streaming enable or disable | |
07b1747c | 1181 | * |
62ef80a1 | 1182 | * Sets streaming to enable or disable, if possible. |
07b1747c | 1183 | */ |
62ef80a1 | 1184 | static int tvp514x_s_stream(struct v4l2_subdev *sd, int enable) |
07b1747c | 1185 | { |
07b1747c | 1186 | int err = 0; |
62ef80a1 MK |
1187 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
1188 | struct tvp514x_decoder *decoder = to_decoder(sd); | |
07b1747c | 1189 | |
62ef80a1 MK |
1190 | if (decoder->streaming == enable) |
1191 | return 0; | |
07b1747c | 1192 | |
62ef80a1 MK |
1193 | switch (enable) { |
1194 | case 0: | |
1195 | { | |
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; | |
1201 | } | |
1202 | decoder->streaming = enable; | |
07b1747c | 1203 | break; |
62ef80a1 MK |
1204 | } |
1205 | case 1: | |
1206 | { | |
1207 | struct tvp514x_reg *int_seq = (struct tvp514x_reg *) | |
1208 | client->driver->id_table->driver_data; | |
07b1747c | 1209 | |
62ef80a1 MK |
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; | |
1215 | } | |
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; | |
07b1747c | 1221 | } |
62ef80a1 MK |
1222 | err = tvp514x_configure(sd, decoder); |
1223 | if (err) { | |
1224 | v4l2_err(sd, "Unable to configure decoder\n"); | |
1225 | return err; | |
1226 | } | |
1227 | decoder->streaming = enable; | |
07b1747c | 1228 | break; |
62ef80a1 | 1229 | } |
07b1747c VH |
1230 | default: |
1231 | err = -ENODEV; | |
1232 | break; | |
1233 | } | |
1234 | ||
1235 | return err; | |
1236 | } | |
1237 | ||
62ef80a1 MK |
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, | |
1243 | }; | |
07b1747c | 1244 | |
62ef80a1 MK |
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, | |
1255 | }; | |
07b1747c | 1256 | |
62ef80a1 MK |
1257 | static const struct v4l2_subdev_ops tvp514x_ops = { |
1258 | .core = &tvp514x_core_ops, | |
1259 | .video = &tvp514x_video_ops, | |
07b1747c VH |
1260 | }; |
1261 | ||
07b1747c | 1262 | static struct tvp514x_decoder tvp514x_dev = { |
62ef80a1 | 1263 | .streaming = 0, |
07b1747c VH |
1264 | |
1265 | .fmt_list = tvp514x_fmt_list, | |
1266 | .num_fmts = ARRAY_SIZE(tvp514x_fmt_list), | |
1267 | ||
c1c9d09c MK |
1268 | .pix = { |
1269 | /* Default to NTSC 8-bit YUV 422 */ | |
07b1747c VH |
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, | |
1278 | }, | |
1279 | ||
1280 | .current_std = STD_NTSC_MJ, | |
1281 | .std_list = tvp514x_std_list, | |
1282 | .num_stds = ARRAY_SIZE(tvp514x_std_list), | |
62ef80a1 | 1283 | |
07b1747c VH |
1284 | }; |
1285 | ||
c1c9d09c MK |
1286 | /** |
1287 | * tvp514x_probe() - decoder driver i2c probe handler | |
07b1747c | 1288 | * @client: i2c driver client device structure |
62ef80a1 | 1289 | * @id: i2c driver id table |
07b1747c VH |
1290 | * |
1291 | * Register decoder as an i2c client device and V4L2 | |
1292 | * device. | |
1293 | */ | |
1294 | static int | |
1295 | tvp514x_probe(struct i2c_client *client, const struct i2c_device_id *id) | |
1296 | { | |
6722e0ef | 1297 | struct tvp514x_decoder *decoder; |
62ef80a1 | 1298 | struct v4l2_subdev *sd; |
07b1747c VH |
1299 | |
1300 | /* Check if the adapter supports the needed features */ | |
1301 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | |
1302 | return -EIO; | |
1303 | ||
62ef80a1 MK |
1304 | if (!client->dev.platform_data) { |
1305 | v4l2_err(client, "No platform data!!\n"); | |
1306 | return -ENODEV; | |
1307 | } | |
1308 | ||
6722e0ef SAS |
1309 | decoder = kzalloc(sizeof(*decoder), GFP_KERNEL); |
1310 | if (!decoder) | |
1311 | return -ENOMEM; | |
1312 | ||
c1c9d09c | 1313 | /* Initialize the tvp514x_decoder with default configuration */ |
6722e0ef | 1314 | *decoder = tvp514x_dev; |
62ef80a1 | 1315 | /* Copy default register configuration */ |
6722e0ef SAS |
1316 | memcpy(decoder->tvp514x_regs, tvp514x_reg_list_default, |
1317 | sizeof(tvp514x_reg_list_default)); | |
62ef80a1 | 1318 | |
c1c9d09c | 1319 | /* Copy board specific information here */ |
62ef80a1 MK |
1320 | decoder->pdata = client->dev.platform_data; |
1321 | ||
c1c9d09c | 1322 | /** |
07b1747c VH |
1323 | * Fetch platform specific data, and configure the |
1324 | * tvp514x_reg_list[] accordingly. Since this is one | |
1325 | * time configuration, no need to preserve. | |
1326 | */ | |
6722e0ef | 1327 | decoder->tvp514x_regs[REG_OUTPUT_FORMATTER2].val |= |
62ef80a1 | 1328 | (decoder->pdata->clk_polarity << 1); |
6722e0ef | 1329 | decoder->tvp514x_regs[REG_SYNC_CONTROL].val |= |
62ef80a1 MK |
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; | |
07b1747c VH |
1335 | |
1336 | /* Register with V4L2 layer as slave device */ | |
62ef80a1 MK |
1337 | sd = &decoder->sd; |
1338 | v4l2_i2c_subdev_init(sd, client, &tvp514x_ops); | |
1339 | ||
1340 | v4l2_info(sd, "%s decoder driver registered !!\n", sd->name); | |
1341 | ||
07b1747c | 1342 | return 0; |
6722e0ef | 1343 | |
07b1747c VH |
1344 | } |
1345 | ||
c1c9d09c MK |
1346 | /** |
1347 | * tvp514x_remove() - decoder driver i2c remove handler | |
07b1747c VH |
1348 | * @client: i2c driver client device structure |
1349 | * | |
1350 | * Unregister decoder as an i2c client device and V4L2 | |
1351 | * device. Complement of tvp514x_probe(). | |
1352 | */ | |
62ef80a1 | 1353 | static int tvp514x_remove(struct i2c_client *client) |
07b1747c | 1354 | { |
62ef80a1 MK |
1355 | struct v4l2_subdev *sd = i2c_get_clientdata(client); |
1356 | struct tvp514x_decoder *decoder = to_decoder(sd); | |
07b1747c | 1357 | |
62ef80a1 | 1358 | v4l2_device_unregister_subdev(sd); |
6722e0ef | 1359 | kfree(decoder); |
07b1747c VH |
1360 | return 0; |
1361 | } | |
c1c9d09c | 1362 | /* TVP5146 Init/Power on Sequence */ |
07b1747c VH |
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}, | |
62ef80a1 | 1375 | {TOK_TERM, 0, 0}, |
07b1747c | 1376 | }; |
62ef80a1 | 1377 | |
c1c9d09c | 1378 | /* TVP5147 Init/Power on Sequence */ |
07b1747c VH |
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}, | |
62ef80a1 | 1398 | {TOK_TERM, 0, 0}, |
07b1747c | 1399 | }; |
62ef80a1 | 1400 | |
c1c9d09c | 1401 | /* TVP5146M2/TVP5147M1 Init/Power on Sequence */ |
07b1747c VH |
1402 | static const struct tvp514x_reg tvp514xm_init_reg_seq[] = { |
1403 | {TOK_WRITE, REG_OPERATION_MODE, 0x01}, | |
1404 | {TOK_WRITE, REG_OPERATION_MODE, 0x00}, | |
62ef80a1 | 1405 | {TOK_TERM, 0, 0}, |
07b1747c | 1406 | }; |
62ef80a1 | 1407 | |
c1c9d09c | 1408 | /** |
07b1747c VH |
1409 | * I2C Device Table - |
1410 | * | |
1411 | * name - Name of the actual device/chip. | |
1412 | * driver_data - Driver data | |
1413 | */ | |
1414 | static const struct i2c_device_id tvp514x_id[] = { | |
62ef80a1 MK |
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}, | |
07b1747c VH |
1419 | {}, |
1420 | }; | |
1421 | ||
1422 | MODULE_DEVICE_TABLE(i2c, tvp514x_id); | |
1423 | ||
62ef80a1 | 1424 | static struct i2c_driver tvp514x_driver = { |
07b1747c | 1425 | .driver = { |
62ef80a1 MK |
1426 | .owner = THIS_MODULE, |
1427 | .name = TVP514X_MODULE_NAME, | |
1428 | }, | |
07b1747c | 1429 | .probe = tvp514x_probe, |
62ef80a1 | 1430 | .remove = tvp514x_remove, |
07b1747c VH |
1431 | .id_table = tvp514x_id, |
1432 | }; | |
1433 | ||
07b1747c VH |
1434 | static int __init tvp514x_init(void) |
1435 | { | |
62ef80a1 | 1436 | return i2c_add_driver(&tvp514x_driver); |
07b1747c VH |
1437 | } |
1438 | ||
62ef80a1 | 1439 | static void __exit tvp514x_exit(void) |
07b1747c | 1440 | { |
62ef80a1 | 1441 | i2c_del_driver(&tvp514x_driver); |
07b1747c VH |
1442 | } |
1443 | ||
1444 | module_init(tvp514x_init); | |
62ef80a1 | 1445 | module_exit(tvp514x_exit); |