diff options
author | Vaibhav Hiremath <hvaibhav@ti.com> | 2008-12-05 08:19:36 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2008-12-30 06:38:36 -0500 |
commit | 07b1747c8d0bb463311f9dd05d4c013765abe2eb (patch) | |
tree | ee9c2484ae5ac534c41a5bbd0c290611cac580fb | |
parent | 67bc04dd04bfe6a6337a9c6773e4c36645360332 (diff) |
V4L/DVB (9817): v4l: add new tvp514x I2C video decoder driver
Signed-off-by: Brijesh Jadav <brijesh.j@ti.com>
Signed-off-by: Hardik Shah <hardik.shah@ti.com>
Signed-off-by: Manjunath Hadli <mrh@ti.com>
Signed-off-by: R Sivaraj <sivaraj@ti.com>
Signed-off-by: Vaibhav Hiremath <hvaibhav@ti.com>
Signed-off-by: Karicheri Muralidharan <m-karicheri2@ti.com>
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Reviewed-by: Hans Verkuil <hverkuil@xs4all.nl>
Reviewed-by: David Brownell <david-b@pacbell.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r-- | drivers/media/video/Kconfig | 11 | ||||
-rw-r--r-- | drivers/media/video/Makefile | 1 | ||||
-rw-r--r-- | drivers/media/video/tvp514x.c | 1569 | ||||
-rw-r--r-- | drivers/media/video/tvp514x_regs.h | 297 | ||||
-rw-r--r-- | include/media/tvp514x.h | 118 |
5 files changed, 1996 insertions, 0 deletions
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig index c487d2a1285f..eb9ff7e107d6 100644 --- a/drivers/media/video/Kconfig +++ b/drivers/media/video/Kconfig | |||
@@ -361,6 +361,17 @@ config VIDEO_SAA7191 | |||
361 | To compile this driver as a module, choose M here: the | 361 | To compile this driver as a module, choose M here: the |
362 | module will be called saa7191. | 362 | module will be called saa7191. |
363 | 363 | ||
364 | config VIDEO_TVP514X | ||
365 | tristate "Texas Instruments TVP514x video decoder" | ||
366 | depends on VIDEO_V4L2 && I2C | ||
367 | ---help--- | ||
368 | This is a Video4Linux2 sensor-level driver for the TI TVP5146/47 | ||
369 | decoder. It is currently working with the TI OMAP3 camera | ||
370 | controller. | ||
371 | |||
372 | To compile this driver as a module, choose M here: the | ||
373 | module will be called tvp514x. | ||
374 | |||
364 | config VIDEO_TVP5150 | 375 | config VIDEO_TVP5150 |
365 | tristate "Texas Instruments TVP5150 video decoder" | 376 | tristate "Texas Instruments TVP5150 video decoder" |
366 | depends on VIDEO_V4L2 && I2C | 377 | depends on VIDEO_V4L2 && I2C |
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile index ac147b1aea36..492ab3dce71b 100644 --- a/drivers/media/video/Makefile +++ b/drivers/media/video/Makefile | |||
@@ -69,6 +69,7 @@ obj-$(CONFIG_VIDEO_CX88) += cx88/ | |||
69 | obj-$(CONFIG_VIDEO_EM28XX) += em28xx/ | 69 | obj-$(CONFIG_VIDEO_EM28XX) += em28xx/ |
70 | obj-$(CONFIG_VIDEO_USBVISION) += usbvision/ | 70 | obj-$(CONFIG_VIDEO_USBVISION) += usbvision/ |
71 | obj-$(CONFIG_VIDEO_TVP5150) += tvp5150.o | 71 | obj-$(CONFIG_VIDEO_TVP5150) += tvp5150.o |
72 | obj-$(CONFIG_VIDEO_TVP514X) += tvp514x.o | ||
72 | obj-$(CONFIG_VIDEO_PVRUSB2) += pvrusb2/ | 73 | obj-$(CONFIG_VIDEO_PVRUSB2) += pvrusb2/ |
73 | obj-$(CONFIG_VIDEO_MSP3400) += msp3400.o | 74 | obj-$(CONFIG_VIDEO_MSP3400) += msp3400.o |
74 | obj-$(CONFIG_VIDEO_CS5345) += cs5345.o | 75 | obj-$(CONFIG_VIDEO_CS5345) += cs5345.o |
diff --git a/drivers/media/video/tvp514x.c b/drivers/media/video/tvp514x.c new file mode 100644 index 000000000000..ac9aa40d09f6 --- /dev/null +++ b/drivers/media/video/tvp514x.c | |||
@@ -0,0 +1,1569 @@ | |||
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> | ||
32 | #include <linux/delay.h> | ||
33 | #include <linux/videodev2.h> | ||
34 | #include <media/v4l2-int-device.h> | ||
35 | #include <media/tvp514x.h> | ||
36 | |||
37 | #include "tvp514x_regs.h" | ||
38 | |||
39 | /* Module Name */ | ||
40 | #define TVP514X_MODULE_NAME "tvp514x" | ||
41 | |||
42 | /* Private macros for TVP */ | ||
43 | #define I2C_RETRY_COUNT (5) | ||
44 | #define LOCK_RETRY_COUNT (5) | ||
45 | #define LOCK_RETRY_DELAY (200) | ||
46 | |||
47 | /* Debug functions */ | ||
48 | static int debug; | ||
49 | module_param(debug, bool, 0644); | ||
50 | MODULE_PARM_DESC(debug, "Debug level (0-1)"); | ||
51 | |||
52 | #define dump_reg(client, reg, val) \ | ||
53 | do { \ | ||
54 | val = tvp514x_read_reg(client, reg); \ | ||
55 | v4l_info(client, "Reg(0x%.2X): 0x%.2X\n", reg, val); \ | ||
56 | } while (0) | ||
57 | |||
58 | /** | ||
59 | * enum tvp514x_std - enum for supported standards | ||
60 | */ | ||
61 | enum tvp514x_std { | ||
62 | STD_NTSC_MJ = 0, | ||
63 | STD_PAL_BDGHIN, | ||
64 | STD_INVALID | ||
65 | }; | ||
66 | |||
67 | /** | ||
68 | * enum tvp514x_state - enum for different decoder states | ||
69 | */ | ||
70 | enum tvp514x_state { | ||
71 | STATE_NOT_DETECTED, | ||
72 | STATE_DETECTED | ||
73 | }; | ||
74 | |||
75 | /** | ||
76 | * struct tvp514x_std_info - Structure to store standard informations | ||
77 | * @width: Line width in pixels | ||
78 | * @height:Number of active lines | ||
79 | * @video_std: Value to write in REG_VIDEO_STD register | ||
80 | * @standard: v4l2 standard structure information | ||
81 | */ | ||
82 | struct tvp514x_std_info { | ||
83 | unsigned long width; | ||
84 | unsigned long height; | ||
85 | u8 video_std; | ||
86 | struct v4l2_standard standard; | ||
87 | }; | ||
88 | |||
89 | /** | ||
90 | * struct tvp514x_decoded - TVP5146/47 decoder object | ||
91 | * @v4l2_int_device: Slave handle | ||
92 | * @pdata: Board specific | ||
93 | * @client: I2C client data | ||
94 | * @id: Entry from I2C table | ||
95 | * @ver: Chip version | ||
96 | * @state: TVP5146/47 decoder state - detected or not-detected | ||
97 | * @pix: Current pixel format | ||
98 | * @num_fmts: Number of formats | ||
99 | * @fmt_list: Format list | ||
100 | * @current_std: Current standard | ||
101 | * @num_stds: Number of standards | ||
102 | * @std_list: Standards list | ||
103 | * @route: input and output routing at chip level | ||
104 | */ | ||
105 | struct tvp514x_decoder { | ||
106 | struct v4l2_int_device *v4l2_int_device; | ||
107 | const struct tvp514x_platform_data *pdata; | ||
108 | struct i2c_client *client; | ||
109 | |||
110 | struct i2c_device_id *id; | ||
111 | |||
112 | int ver; | ||
113 | enum tvp514x_state state; | ||
114 | |||
115 | struct v4l2_pix_format pix; | ||
116 | int num_fmts; | ||
117 | const struct v4l2_fmtdesc *fmt_list; | ||
118 | |||
119 | enum tvp514x_std current_std; | ||
120 | int num_stds; | ||
121 | struct tvp514x_std_info *std_list; | ||
122 | |||
123 | struct v4l2_routing route; | ||
124 | }; | ||
125 | |||
126 | /* TVP514x default register values */ | ||
127 | static struct tvp514x_reg tvp514x_reg_list[] = { | ||
128 | {TOK_WRITE, REG_INPUT_SEL, 0x05}, /* Composite selected */ | ||
129 | {TOK_WRITE, REG_AFE_GAIN_CTRL, 0x0F}, | ||
130 | {TOK_WRITE, REG_VIDEO_STD, 0x00}, /* Auto mode */ | ||
131 | {TOK_WRITE, REG_OPERATION_MODE, 0x00}, | ||
132 | {TOK_SKIP, REG_AUTOSWITCH_MASK, 0x3F}, | ||
133 | {TOK_WRITE, REG_COLOR_KILLER, 0x10}, | ||
134 | {TOK_WRITE, REG_LUMA_CONTROL1, 0x00}, | ||
135 | {TOK_WRITE, REG_LUMA_CONTROL2, 0x00}, | ||
136 | {TOK_WRITE, REG_LUMA_CONTROL3, 0x02}, | ||
137 | {TOK_WRITE, REG_BRIGHTNESS, 0x80}, | ||
138 | {TOK_WRITE, REG_CONTRAST, 0x80}, | ||
139 | {TOK_WRITE, REG_SATURATION, 0x80}, | ||
140 | {TOK_WRITE, REG_HUE, 0x00}, | ||
141 | {TOK_WRITE, REG_CHROMA_CONTROL1, 0x00}, | ||
142 | {TOK_WRITE, REG_CHROMA_CONTROL2, 0x0E}, | ||
143 | {TOK_SKIP, 0x0F, 0x00}, /* Reserved */ | ||
144 | {TOK_WRITE, REG_COMP_PR_SATURATION, 0x80}, | ||
145 | {TOK_WRITE, REG_COMP_Y_CONTRAST, 0x80}, | ||
146 | {TOK_WRITE, REG_COMP_PB_SATURATION, 0x80}, | ||
147 | {TOK_SKIP, 0x13, 0x00}, /* Reserved */ | ||
148 | {TOK_WRITE, REG_COMP_Y_BRIGHTNESS, 0x80}, | ||
149 | {TOK_SKIP, 0x15, 0x00}, /* Reserved */ | ||
150 | {TOK_SKIP, REG_AVID_START_PIXEL_LSB, 0x55}, /* NTSC timing */ | ||
151 | {TOK_SKIP, REG_AVID_START_PIXEL_MSB, 0x00}, | ||
152 | {TOK_SKIP, REG_AVID_STOP_PIXEL_LSB, 0x25}, | ||
153 | {TOK_SKIP, REG_AVID_STOP_PIXEL_MSB, 0x03}, | ||
154 | {TOK_SKIP, REG_HSYNC_START_PIXEL_LSB, 0x00}, /* NTSC timing */ | ||
155 | {TOK_SKIP, REG_HSYNC_START_PIXEL_MSB, 0x00}, | ||
156 | {TOK_SKIP, REG_HSYNC_STOP_PIXEL_LSB, 0x40}, | ||
157 | {TOK_SKIP, REG_HSYNC_STOP_PIXEL_MSB, 0x00}, | ||
158 | {TOK_SKIP, REG_VSYNC_START_LINE_LSB, 0x04}, /* NTSC timing */ | ||
159 | {TOK_SKIP, REG_VSYNC_START_LINE_MSB, 0x00}, | ||
160 | {TOK_SKIP, REG_VSYNC_STOP_LINE_LSB, 0x07}, | ||
161 | {TOK_SKIP, REG_VSYNC_STOP_LINE_MSB, 0x00}, | ||
162 | {TOK_SKIP, REG_VBLK_START_LINE_LSB, 0x01}, /* NTSC timing */ | ||
163 | {TOK_SKIP, REG_VBLK_START_LINE_MSB, 0x00}, | ||
164 | {TOK_SKIP, REG_VBLK_STOP_LINE_LSB, 0x15}, | ||
165 | {TOK_SKIP, REG_VBLK_STOP_LINE_MSB, 0x00}, | ||
166 | {TOK_SKIP, 0x26, 0x00}, /* Reserved */ | ||
167 | {TOK_SKIP, 0x27, 0x00}, /* Reserved */ | ||
168 | {TOK_SKIP, REG_FAST_SWTICH_CONTROL, 0xCC}, | ||
169 | {TOK_SKIP, 0x29, 0x00}, /* Reserved */ | ||
170 | {TOK_SKIP, REG_FAST_SWTICH_SCART_DELAY, 0x00}, | ||
171 | {TOK_SKIP, 0x2B, 0x00}, /* Reserved */ | ||
172 | {TOK_SKIP, REG_SCART_DELAY, 0x00}, | ||
173 | {TOK_SKIP, REG_CTI_DELAY, 0x00}, | ||
174 | {TOK_SKIP, REG_CTI_CONTROL, 0x00}, | ||
175 | {TOK_SKIP, 0x2F, 0x00}, /* Reserved */ | ||
176 | {TOK_SKIP, 0x30, 0x00}, /* Reserved */ | ||
177 | {TOK_SKIP, 0x31, 0x00}, /* Reserved */ | ||
178 | {TOK_WRITE, REG_SYNC_CONTROL, 0x00}, /* HS, VS active high */ | ||
179 | {TOK_WRITE, REG_OUTPUT_FORMATTER1, 0x00}, /* 10-bit BT.656 */ | ||
180 | {TOK_WRITE, REG_OUTPUT_FORMATTER2, 0x11}, /* Enable clk & data */ | ||
181 | {TOK_WRITE, REG_OUTPUT_FORMATTER3, 0xEE}, /* Enable AVID & FLD */ | ||
182 | {TOK_WRITE, REG_OUTPUT_FORMATTER4, 0xAF}, /* Enable VS & HS */ | ||
183 | {TOK_WRITE, REG_OUTPUT_FORMATTER5, 0xFF}, | ||
184 | {TOK_WRITE, REG_OUTPUT_FORMATTER6, 0xFF}, | ||
185 | {TOK_WRITE, REG_CLEAR_LOST_LOCK, 0x01}, /* Clear status */ | ||
186 | {TOK_TERM, 0, 0}, | ||
187 | }; | ||
188 | |||
189 | /* List of image formats supported by TVP5146/47 decoder | ||
190 | * Currently we are using 8 bit mode only, but can be | ||
191 | * extended to 10/20 bit mode. | ||
192 | */ | ||
193 | static const struct v4l2_fmtdesc tvp514x_fmt_list[] = { | ||
194 | { | ||
195 | .index = 0, | ||
196 | .type = V4L2_BUF_TYPE_VIDEO_CAPTURE, | ||
197 | .flags = 0, | ||
198 | .description = "8-bit UYVY 4:2:2 Format", | ||
199 | .pixelformat = V4L2_PIX_FMT_UYVY, | ||
200 | }, | ||
201 | }; | ||
202 | |||
203 | /* | ||
204 | * Supported standards - | ||
205 | * | ||
206 | * Currently supports two standards only, need to add support for rest of the | ||
207 | * modes, like SECAM, etc... | ||
208 | */ | ||
209 | static struct tvp514x_std_info tvp514x_std_list[] = { | ||
210 | /* Standard: STD_NTSC_MJ */ | ||
211 | [STD_NTSC_MJ] = { | ||
212 | .width = NTSC_NUM_ACTIVE_PIXELS, | ||
213 | .height = NTSC_NUM_ACTIVE_LINES, | ||
214 | .video_std = VIDEO_STD_NTSC_MJ_BIT, | ||
215 | .standard = { | ||
216 | .index = 0, | ||
217 | .id = V4L2_STD_NTSC, | ||
218 | .name = "NTSC", | ||
219 | .frameperiod = {1001, 30000}, | ||
220 | .framelines = 525 | ||
221 | }, | ||
222 | /* Standard: STD_PAL_BDGHIN */ | ||
223 | }, | ||
224 | [STD_PAL_BDGHIN] = { | ||
225 | .width = PAL_NUM_ACTIVE_PIXELS, | ||
226 | .height = PAL_NUM_ACTIVE_LINES, | ||
227 | .video_std = VIDEO_STD_PAL_BDGHIN_BIT, | ||
228 | .standard = { | ||
229 | .index = 1, | ||
230 | .id = V4L2_STD_PAL, | ||
231 | .name = "PAL", | ||
232 | .frameperiod = {1, 25}, | ||
233 | .framelines = 625 | ||
234 | }, | ||
235 | }, | ||
236 | /* Standard: need to add for additional standard */ | ||
237 | }; | ||
238 | /* | ||
239 | * Control structure for Auto Gain | ||
240 | * This is temporary data, will get replaced once | ||
241 | * v4l2_ctrl_query_fill supports it. | ||
242 | */ | ||
243 | static const struct v4l2_queryctrl tvp514x_autogain_ctrl = { | ||
244 | .id = V4L2_CID_AUTOGAIN, | ||
245 | .name = "Gain, Automatic", | ||
246 | .type = V4L2_CTRL_TYPE_BOOLEAN, | ||
247 | .minimum = 0, | ||
248 | .maximum = 1, | ||
249 | .step = 1, | ||
250 | .default_value = 1, | ||
251 | }; | ||
252 | |||
253 | /* | ||
254 | * Read a value from a register in an TVP5146/47 decoder device. | ||
255 | * Returns value read if successful, or non-zero (-1) otherwise. | ||
256 | */ | ||
257 | static int tvp514x_read_reg(struct i2c_client *client, u8 reg) | ||
258 | { | ||
259 | int err; | ||
260 | int retry = 0; | ||
261 | read_again: | ||
262 | |||
263 | err = i2c_smbus_read_byte_data(client, reg); | ||
264 | if (err == -1) { | ||
265 | if (retry <= I2C_RETRY_COUNT) { | ||
266 | v4l_warn(client, "Read: retry ... %d\n", retry); | ||
267 | retry++; | ||
268 | msleep_interruptible(10); | ||
269 | goto read_again; | ||
270 | } | ||
271 | } | ||
272 | |||
273 | return err; | ||
274 | } | ||
275 | |||
276 | /* | ||
277 | * Write a value to a register in an TVP5146/47 decoder device. | ||
278 | * Returns zero if successful, or non-zero otherwise. | ||
279 | */ | ||
280 | static int tvp514x_write_reg(struct i2c_client *client, u8 reg, u8 val) | ||
281 | { | ||
282 | int err; | ||
283 | int retry = 0; | ||
284 | write_again: | ||
285 | |||
286 | err = i2c_smbus_write_byte_data(client, reg, val); | ||
287 | if (err) { | ||
288 | if (retry <= I2C_RETRY_COUNT) { | ||
289 | v4l_warn(client, "Write: retry ... %d\n", retry); | ||
290 | retry++; | ||
291 | msleep_interruptible(10); | ||
292 | goto write_again; | ||
293 | } | ||
294 | } | ||
295 | |||
296 | return err; | ||
297 | } | ||
298 | |||
299 | /* | ||
300 | * tvp514x_write_regs : Initializes a list of TVP5146/47 registers | ||
301 | * if token is TOK_TERM, then entire write operation terminates | ||
302 | * if token is TOK_DELAY, then a delay of 'val' msec is introduced | ||
303 | * if token is TOK_SKIP, then the register write is skipped | ||
304 | * if token is TOK_WRITE, then the register write is performed | ||
305 | * | ||
306 | * reglist - list of registers to be written | ||
307 | * Returns zero if successful, or non-zero otherwise. | ||
308 | */ | ||
309 | static int tvp514x_write_regs(struct i2c_client *client, | ||
310 | const struct tvp514x_reg reglist[]) | ||
311 | { | ||
312 | int err; | ||
313 | const struct tvp514x_reg *next = reglist; | ||
314 | |||
315 | for (; next->token != TOK_TERM; next++) { | ||
316 | if (next->token == TOK_DELAY) { | ||
317 | msleep(next->val); | ||
318 | continue; | ||
319 | } | ||
320 | |||
321 | if (next->token == TOK_SKIP) | ||
322 | continue; | ||
323 | |||
324 | err = tvp514x_write_reg(client, next->reg, (u8) next->val); | ||
325 | if (err) { | ||
326 | v4l_err(client, "Write failed. Err[%d]\n", err); | ||
327 | return err; | ||
328 | } | ||
329 | } | ||
330 | return 0; | ||
331 | } | ||
332 | |||
333 | /* | ||
334 | * tvp514x_get_current_std: | ||
335 | * Returns the current standard detected by TVP5146/47 | ||
336 | */ | ||
337 | static enum tvp514x_std tvp514x_get_current_std(struct tvp514x_decoder | ||
338 | *decoder) | ||
339 | { | ||
340 | u8 std, std_status; | ||
341 | |||
342 | std = tvp514x_read_reg(decoder->client, REG_VIDEO_STD); | ||
343 | if ((std & VIDEO_STD_MASK) == VIDEO_STD_AUTO_SWITCH_BIT) { | ||
344 | /* use the standard status register */ | ||
345 | std_status = tvp514x_read_reg(decoder->client, | ||
346 | REG_VIDEO_STD_STATUS); | ||
347 | } else | ||
348 | std_status = std; /* use the standard register itself */ | ||
349 | |||
350 | switch (std_status & VIDEO_STD_MASK) { | ||
351 | case VIDEO_STD_NTSC_MJ_BIT: | ||
352 | return STD_NTSC_MJ; | ||
353 | |||
354 | case VIDEO_STD_PAL_BDGHIN_BIT: | ||
355 | return STD_PAL_BDGHIN; | ||
356 | |||
357 | default: | ||
358 | return STD_INVALID; | ||
359 | } | ||
360 | |||
361 | return STD_INVALID; | ||
362 | } | ||
363 | |||
364 | /* | ||
365 | * TVP5146/47 register dump function | ||
366 | */ | ||
367 | static void tvp514x_reg_dump(struct tvp514x_decoder *decoder) | ||
368 | { | ||
369 | u8 value; | ||
370 | |||
371 | dump_reg(decoder->client, REG_INPUT_SEL, value); | ||
372 | dump_reg(decoder->client, REG_AFE_GAIN_CTRL, value); | ||
373 | dump_reg(decoder->client, REG_VIDEO_STD, value); | ||
374 | dump_reg(decoder->client, REG_OPERATION_MODE, value); | ||
375 | dump_reg(decoder->client, REG_COLOR_KILLER, value); | ||
376 | dump_reg(decoder->client, REG_LUMA_CONTROL1, value); | ||
377 | dump_reg(decoder->client, REG_LUMA_CONTROL2, value); | ||
378 | dump_reg(decoder->client, REG_LUMA_CONTROL3, value); | ||
379 | dump_reg(decoder->client, REG_BRIGHTNESS, value); | ||
380 | dump_reg(decoder->client, REG_CONTRAST, value); | ||
381 | dump_reg(decoder->client, REG_SATURATION, value); | ||
382 | dump_reg(decoder->client, REG_HUE, value); | ||
383 | dump_reg(decoder->client, REG_CHROMA_CONTROL1, value); | ||
384 | dump_reg(decoder->client, REG_CHROMA_CONTROL2, value); | ||
385 | dump_reg(decoder->client, REG_COMP_PR_SATURATION, value); | ||
386 | dump_reg(decoder->client, REG_COMP_Y_CONTRAST, value); | ||
387 | dump_reg(decoder->client, REG_COMP_PB_SATURATION, value); | ||
388 | dump_reg(decoder->client, REG_COMP_Y_BRIGHTNESS, value); | ||
389 | dump_reg(decoder->client, REG_AVID_START_PIXEL_LSB, value); | ||
390 | dump_reg(decoder->client, REG_AVID_START_PIXEL_MSB, value); | ||
391 | dump_reg(decoder->client, REG_AVID_STOP_PIXEL_LSB, value); | ||
392 | dump_reg(decoder->client, REG_AVID_STOP_PIXEL_MSB, value); | ||
393 | dump_reg(decoder->client, REG_HSYNC_START_PIXEL_LSB, value); | ||
394 | dump_reg(decoder->client, REG_HSYNC_START_PIXEL_MSB, value); | ||
395 | dump_reg(decoder->client, REG_HSYNC_STOP_PIXEL_LSB, value); | ||
396 | dump_reg(decoder->client, REG_HSYNC_STOP_PIXEL_MSB, value); | ||
397 | dump_reg(decoder->client, REG_VSYNC_START_LINE_LSB, value); | ||
398 | dump_reg(decoder->client, REG_VSYNC_START_LINE_MSB, value); | ||
399 | dump_reg(decoder->client, REG_VSYNC_STOP_LINE_LSB, value); | ||
400 | dump_reg(decoder->client, REG_VSYNC_STOP_LINE_MSB, value); | ||
401 | dump_reg(decoder->client, REG_VBLK_START_LINE_LSB, value); | ||
402 | dump_reg(decoder->client, REG_VBLK_START_LINE_MSB, value); | ||
403 | dump_reg(decoder->client, REG_VBLK_STOP_LINE_LSB, value); | ||
404 | dump_reg(decoder->client, REG_VBLK_STOP_LINE_MSB, value); | ||
405 | dump_reg(decoder->client, REG_SYNC_CONTROL, value); | ||
406 | dump_reg(decoder->client, REG_OUTPUT_FORMATTER1, value); | ||
407 | dump_reg(decoder->client, REG_OUTPUT_FORMATTER2, value); | ||
408 | dump_reg(decoder->client, REG_OUTPUT_FORMATTER3, value); | ||
409 | dump_reg(decoder->client, REG_OUTPUT_FORMATTER4, value); | ||
410 | dump_reg(decoder->client, REG_OUTPUT_FORMATTER5, value); | ||
411 | dump_reg(decoder->client, REG_OUTPUT_FORMATTER6, value); | ||
412 | dump_reg(decoder->client, REG_CLEAR_LOST_LOCK, value); | ||
413 | } | ||
414 | |||
415 | /* | ||
416 | * Configure the TVP5146/47 with the current register settings | ||
417 | * Returns zero if successful, or non-zero otherwise. | ||
418 | */ | ||
419 | static int tvp514x_configure(struct tvp514x_decoder *decoder) | ||
420 | { | ||
421 | int err; | ||
422 | |||
423 | /* common register initialization */ | ||
424 | err = | ||
425 | tvp514x_write_regs(decoder->client, tvp514x_reg_list); | ||
426 | if (err) | ||
427 | return err; | ||
428 | |||
429 | if (debug) | ||
430 | tvp514x_reg_dump(decoder); | ||
431 | |||
432 | return 0; | ||
433 | } | ||
434 | |||
435 | /* | ||
436 | * Detect if an tvp514x is present, and if so which revision. | ||
437 | * A device is considered to be detected if the chip ID (LSB and MSB) | ||
438 | * registers match the expected values. | ||
439 | * Any value of the rom version register is accepted. | ||
440 | * Returns ENODEV error number if no device is detected, or zero | ||
441 | * if a device is detected. | ||
442 | */ | ||
443 | static int tvp514x_detect(struct tvp514x_decoder *decoder) | ||
444 | { | ||
445 | u8 chip_id_msb, chip_id_lsb, rom_ver; | ||
446 | |||
447 | chip_id_msb = tvp514x_read_reg(decoder->client, REG_CHIP_ID_MSB); | ||
448 | chip_id_lsb = tvp514x_read_reg(decoder->client, REG_CHIP_ID_LSB); | ||
449 | rom_ver = tvp514x_read_reg(decoder->client, REG_ROM_VERSION); | ||
450 | |||
451 | v4l_dbg(1, debug, decoder->client, | ||
452 | "chip id detected msb:0x%x lsb:0x%x rom version:0x%x\n", | ||
453 | chip_id_msb, chip_id_lsb, rom_ver); | ||
454 | if ((chip_id_msb != TVP514X_CHIP_ID_MSB) | ||
455 | || ((chip_id_lsb != TVP5146_CHIP_ID_LSB) | ||
456 | && (chip_id_lsb != TVP5147_CHIP_ID_LSB))) { | ||
457 | /* We didn't read the values we expected, so this must not be | ||
458 | * an TVP5146/47. | ||
459 | */ | ||
460 | v4l_err(decoder->client, | ||
461 | "chip id mismatch msb:0x%x lsb:0x%x\n", | ||
462 | chip_id_msb, chip_id_lsb); | ||
463 | return -ENODEV; | ||
464 | } | ||
465 | |||
466 | decoder->ver = rom_ver; | ||
467 | decoder->state = STATE_DETECTED; | ||
468 | |||
469 | v4l_info(decoder->client, | ||
470 | "%s found at 0x%x (%s)\n", decoder->client->name, | ||
471 | decoder->client->addr << 1, | ||
472 | decoder->client->adapter->name); | ||
473 | return 0; | ||
474 | } | ||
475 | |||
476 | /* | ||
477 | * Following are decoder interface functions implemented by | ||
478 | * TVP5146/47 decoder driver. | ||
479 | */ | ||
480 | |||
481 | /** | ||
482 | * ioctl_querystd - V4L2 decoder interface handler for VIDIOC_QUERYSTD ioctl | ||
483 | * @s: pointer to standard V4L2 device structure | ||
484 | * @std_id: standard V4L2 std_id ioctl enum | ||
485 | * | ||
486 | * Returns the current standard detected by TVP5146/47. If no active input is | ||
487 | * detected, returns -EINVAL | ||
488 | */ | ||
489 | static int ioctl_querystd(struct v4l2_int_device *s, v4l2_std_id *std_id) | ||
490 | { | ||
491 | struct tvp514x_decoder *decoder = s->priv; | ||
492 | enum tvp514x_std current_std; | ||
493 | enum tvp514x_input input_sel; | ||
494 | u8 sync_lock_status, lock_mask; | ||
495 | |||
496 | if (std_id == NULL) | ||
497 | return -EINVAL; | ||
498 | |||
499 | /* get the current standard */ | ||
500 | current_std = tvp514x_get_current_std(decoder); | ||
501 | if (current_std == STD_INVALID) | ||
502 | return -EINVAL; | ||
503 | |||
504 | input_sel = decoder->route.input; | ||
505 | |||
506 | switch (input_sel) { | ||
507 | case INPUT_CVBS_VI1A: | ||
508 | case INPUT_CVBS_VI1B: | ||
509 | case INPUT_CVBS_VI1C: | ||
510 | case INPUT_CVBS_VI2A: | ||
511 | case INPUT_CVBS_VI2B: | ||
512 | case INPUT_CVBS_VI2C: | ||
513 | case INPUT_CVBS_VI3A: | ||
514 | case INPUT_CVBS_VI3B: | ||
515 | case INPUT_CVBS_VI3C: | ||
516 | case INPUT_CVBS_VI4A: | ||
517 | lock_mask = STATUS_CLR_SUBCAR_LOCK_BIT | | ||
518 | STATUS_HORZ_SYNC_LOCK_BIT | | ||
519 | STATUS_VIRT_SYNC_LOCK_BIT; | ||
520 | break; | ||
521 | |||
522 | case INPUT_SVIDEO_VI2A_VI1A: | ||
523 | case INPUT_SVIDEO_VI2B_VI1B: | ||
524 | case INPUT_SVIDEO_VI2C_VI1C: | ||
525 | case INPUT_SVIDEO_VI2A_VI3A: | ||
526 | case INPUT_SVIDEO_VI2B_VI3B: | ||
527 | case INPUT_SVIDEO_VI2C_VI3C: | ||
528 | case INPUT_SVIDEO_VI4A_VI1A: | ||
529 | case INPUT_SVIDEO_VI4A_VI1B: | ||
530 | case INPUT_SVIDEO_VI4A_VI1C: | ||
531 | case INPUT_SVIDEO_VI4A_VI3A: | ||
532 | case INPUT_SVIDEO_VI4A_VI3B: | ||
533 | case INPUT_SVIDEO_VI4A_VI3C: | ||
534 | lock_mask = STATUS_HORZ_SYNC_LOCK_BIT | | ||
535 | STATUS_VIRT_SYNC_LOCK_BIT; | ||
536 | break; | ||
537 | /*Need to add other interfaces*/ | ||
538 | default: | ||
539 | return -EINVAL; | ||
540 | } | ||
541 | /* check whether signal is locked */ | ||
542 | sync_lock_status = tvp514x_read_reg(decoder->client, REG_STATUS1); | ||
543 | if (lock_mask != (sync_lock_status & lock_mask)) | ||
544 | return -EINVAL; /* No input detected */ | ||
545 | |||
546 | decoder->current_std = current_std; | ||
547 | *std_id = decoder->std_list[current_std].standard.id; | ||
548 | |||
549 | v4l_dbg(1, debug, decoder->client, "Current STD: %s", | ||
550 | decoder->std_list[current_std].standard.name); | ||
551 | return 0; | ||
552 | } | ||
553 | |||
554 | /** | ||
555 | * ioctl_s_std - V4L2 decoder interface handler for VIDIOC_S_STD ioctl | ||
556 | * @s: pointer to standard V4L2 device structure | ||
557 | * @std_id: standard V4L2 v4l2_std_id ioctl enum | ||
558 | * | ||
559 | * If std_id is supported, sets the requested standard. Otherwise, returns | ||
560 | * -EINVAL | ||
561 | */ | ||
562 | static int ioctl_s_std(struct v4l2_int_device *s, v4l2_std_id *std_id) | ||
563 | { | ||
564 | struct tvp514x_decoder *decoder = s->priv; | ||
565 | int err, i; | ||
566 | |||
567 | if (std_id == NULL) | ||
568 | return -EINVAL; | ||
569 | |||
570 | for (i = 0; i < decoder->num_stds; i++) | ||
571 | if (*std_id & decoder->std_list[i].standard.id) | ||
572 | break; | ||
573 | |||
574 | if ((i == decoder->num_stds) || (i == STD_INVALID)) | ||
575 | return -EINVAL; | ||
576 | |||
577 | err = tvp514x_write_reg(decoder->client, REG_VIDEO_STD, | ||
578 | decoder->std_list[i].video_std); | ||
579 | if (err) | ||
580 | return err; | ||
581 | |||
582 | decoder->current_std = i; | ||
583 | tvp514x_reg_list[REG_VIDEO_STD].val = decoder->std_list[i].video_std; | ||
584 | |||
585 | v4l_dbg(1, debug, decoder->client, "Standard set to: %s", | ||
586 | decoder->std_list[i].standard.name); | ||
587 | return 0; | ||
588 | } | ||
589 | |||
590 | /** | ||
591 | * ioctl_s_routing - V4L2 decoder interface handler for VIDIOC_S_INPUT ioctl | ||
592 | * @s: pointer to standard V4L2 device structure | ||
593 | * @index: number of the input | ||
594 | * | ||
595 | * If index is valid, selects the requested input. Otherwise, returns -EINVAL if | ||
596 | * the input is not supported or there is no active signal present in the | ||
597 | * selected input. | ||
598 | */ | ||
599 | static int ioctl_s_routing(struct v4l2_int_device *s, | ||
600 | struct v4l2_routing *route) | ||
601 | { | ||
602 | struct tvp514x_decoder *decoder = s->priv; | ||
603 | int err; | ||
604 | enum tvp514x_input input_sel; | ||
605 | enum tvp514x_output output_sel; | ||
606 | enum tvp514x_std current_std = STD_INVALID; | ||
607 | u8 sync_lock_status, lock_mask; | ||
608 | int try_count = LOCK_RETRY_COUNT; | ||
609 | |||
610 | if ((!route) || (route->input >= INPUT_INVALID) || | ||
611 | (route->output >= OUTPUT_INVALID)) | ||
612 | return -EINVAL; /* Index out of bound */ | ||
613 | |||
614 | input_sel = route->input; | ||
615 | output_sel = route->output; | ||
616 | |||
617 | err = tvp514x_write_reg(decoder->client, REG_INPUT_SEL, input_sel); | ||
618 | if (err) | ||
619 | return err; | ||
620 | |||
621 | output_sel |= tvp514x_read_reg(decoder->client, | ||
622 | REG_OUTPUT_FORMATTER1) & 0x7; | ||
623 | err = tvp514x_write_reg(decoder->client, REG_OUTPUT_FORMATTER1, | ||
624 | output_sel); | ||
625 | if (err) | ||
626 | return err; | ||
627 | |||
628 | tvp514x_reg_list[REG_INPUT_SEL].val = input_sel; | ||
629 | tvp514x_reg_list[REG_OUTPUT_FORMATTER1].val = output_sel; | ||
630 | |||
631 | /* Clear status */ | ||
632 | msleep(LOCK_RETRY_DELAY); | ||
633 | err = | ||
634 | tvp514x_write_reg(decoder->client, REG_CLEAR_LOST_LOCK, 0x01); | ||
635 | if (err) | ||
636 | return err; | ||
637 | |||
638 | switch (input_sel) { | ||
639 | case INPUT_CVBS_VI1A: | ||
640 | case INPUT_CVBS_VI1B: | ||
641 | case INPUT_CVBS_VI1C: | ||
642 | case INPUT_CVBS_VI2A: | ||
643 | case INPUT_CVBS_VI2B: | ||
644 | case INPUT_CVBS_VI2C: | ||
645 | case INPUT_CVBS_VI3A: | ||
646 | case INPUT_CVBS_VI3B: | ||
647 | case INPUT_CVBS_VI3C: | ||
648 | case INPUT_CVBS_VI4A: | ||
649 | lock_mask = STATUS_CLR_SUBCAR_LOCK_BIT | | ||
650 | STATUS_HORZ_SYNC_LOCK_BIT | | ||
651 | STATUS_VIRT_SYNC_LOCK_BIT; | ||
652 | break; | ||
653 | |||
654 | case INPUT_SVIDEO_VI2A_VI1A: | ||
655 | case INPUT_SVIDEO_VI2B_VI1B: | ||
656 | case INPUT_SVIDEO_VI2C_VI1C: | ||
657 | case INPUT_SVIDEO_VI2A_VI3A: | ||
658 | case INPUT_SVIDEO_VI2B_VI3B: | ||
659 | case INPUT_SVIDEO_VI2C_VI3C: | ||
660 | case INPUT_SVIDEO_VI4A_VI1A: | ||
661 | case INPUT_SVIDEO_VI4A_VI1B: | ||
662 | case INPUT_SVIDEO_VI4A_VI1C: | ||
663 | case INPUT_SVIDEO_VI4A_VI3A: | ||
664 | case INPUT_SVIDEO_VI4A_VI3B: | ||
665 | case INPUT_SVIDEO_VI4A_VI3C: | ||
666 | lock_mask = STATUS_HORZ_SYNC_LOCK_BIT | | ||
667 | STATUS_VIRT_SYNC_LOCK_BIT; | ||
668 | break; | ||
669 | /*Need to add other interfaces*/ | ||
670 | default: | ||
671 | return -EINVAL; | ||
672 | } | ||
673 | |||
674 | while (try_count-- > 0) { | ||
675 | /* Allow decoder to sync up with new input */ | ||
676 | msleep(LOCK_RETRY_DELAY); | ||
677 | |||
678 | /* get the current standard for future reference */ | ||
679 | current_std = tvp514x_get_current_std(decoder); | ||
680 | if (current_std == STD_INVALID) | ||
681 | continue; | ||
682 | |||
683 | sync_lock_status = tvp514x_read_reg(decoder->client, | ||
684 | REG_STATUS1); | ||
685 | if (lock_mask == (sync_lock_status & lock_mask)) | ||
686 | break; /* Input detected */ | ||
687 | } | ||
688 | |||
689 | if ((current_std == STD_INVALID) || (try_count < 0)) | ||
690 | return -EINVAL; | ||
691 | |||
692 | decoder->current_std = current_std; | ||
693 | decoder->route.input = route->input; | ||
694 | decoder->route.output = route->output; | ||
695 | |||
696 | v4l_dbg(1, debug, decoder->client, | ||
697 | "Input set to: %d, std : %d", | ||
698 | input_sel, current_std); | ||
699 | |||
700 | return 0; | ||
701 | } | ||
702 | |||
703 | /** | ||
704 | * ioctl_queryctrl - V4L2 decoder interface handler for VIDIOC_QUERYCTRL ioctl | ||
705 | * @s: pointer to standard V4L2 device structure | ||
706 | * @qctrl: standard V4L2 v4l2_queryctrl structure | ||
707 | * | ||
708 | * If the requested control is supported, returns the control information. | ||
709 | * Otherwise, returns -EINVAL if the control is not supported. | ||
710 | */ | ||
711 | static int | ||
712 | ioctl_queryctrl(struct v4l2_int_device *s, struct v4l2_queryctrl *qctrl) | ||
713 | { | ||
714 | struct tvp514x_decoder *decoder = s->priv; | ||
715 | int err = -EINVAL; | ||
716 | |||
717 | if (qctrl == NULL) | ||
718 | return err; | ||
719 | |||
720 | switch (qctrl->id) { | ||
721 | case V4L2_CID_BRIGHTNESS: | ||
722 | /* Brightness supported is same as standard one (0-255), | ||
723 | * so make use of standard API provided. | ||
724 | */ | ||
725 | err = v4l2_ctrl_query_fill_std(qctrl); | ||
726 | break; | ||
727 | case V4L2_CID_CONTRAST: | ||
728 | case V4L2_CID_SATURATION: | ||
729 | /* Saturation and Contrast supported is - | ||
730 | * Contrast: 0 - 255 (Default - 128) | ||
731 | * Saturation: 0 - 255 (Default - 128) | ||
732 | */ | ||
733 | err = v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 128); | ||
734 | break; | ||
735 | case V4L2_CID_HUE: | ||
736 | /* Hue Supported is - | ||
737 | * Hue - -180 - +180 (Default - 0, Step - +180) | ||
738 | */ | ||
739 | err = v4l2_ctrl_query_fill(qctrl, -180, 180, 180, 0); | ||
740 | break; | ||
741 | case V4L2_CID_AUTOGAIN: | ||
742 | /* Autogain is either 0 or 1*/ | ||
743 | memcpy(qctrl, &tvp514x_autogain_ctrl, | ||
744 | sizeof(struct v4l2_queryctrl)); | ||
745 | err = 0; | ||
746 | break; | ||
747 | default: | ||
748 | v4l_err(decoder->client, | ||
749 | "invalid control id %d\n", qctrl->id); | ||
750 | return err; | ||
751 | } | ||
752 | |||
753 | v4l_dbg(1, debug, decoder->client, | ||
754 | "Query Control: %s : Min - %d, Max - %d, Def - %d", | ||
755 | qctrl->name, | ||
756 | qctrl->minimum, | ||
757 | qctrl->maximum, | ||
758 | qctrl->default_value); | ||
759 | |||
760 | return err; | ||
761 | } | ||
762 | |||
763 | /** | ||
764 | * ioctl_g_ctrl - V4L2 decoder interface handler for VIDIOC_G_CTRL ioctl | ||
765 | * @s: pointer to standard V4L2 device structure | ||
766 | * @ctrl: pointer to v4l2_control structure | ||
767 | * | ||
768 | * If the requested control is supported, returns the control's current | ||
769 | * value from the decoder. Otherwise, returns -EINVAL if the control is not | ||
770 | * supported. | ||
771 | */ | ||
772 | static int | ||
773 | ioctl_g_ctrl(struct v4l2_int_device *s, struct v4l2_control *ctrl) | ||
774 | { | ||
775 | struct tvp514x_decoder *decoder = s->priv; | ||
776 | |||
777 | if (ctrl == NULL) | ||
778 | return -EINVAL; | ||
779 | |||
780 | switch (ctrl->id) { | ||
781 | case V4L2_CID_BRIGHTNESS: | ||
782 | ctrl->value = tvp514x_reg_list[REG_BRIGHTNESS].val; | ||
783 | break; | ||
784 | case V4L2_CID_CONTRAST: | ||
785 | ctrl->value = tvp514x_reg_list[REG_CONTRAST].val; | ||
786 | break; | ||
787 | case V4L2_CID_SATURATION: | ||
788 | ctrl->value = tvp514x_reg_list[REG_SATURATION].val; | ||
789 | break; | ||
790 | case V4L2_CID_HUE: | ||
791 | ctrl->value = tvp514x_reg_list[REG_HUE].val; | ||
792 | if (ctrl->value == 0x7F) | ||
793 | ctrl->value = 180; | ||
794 | else if (ctrl->value == 0x80) | ||
795 | ctrl->value = -180; | ||
796 | else | ||
797 | ctrl->value = 0; | ||
798 | |||
799 | break; | ||
800 | case V4L2_CID_AUTOGAIN: | ||
801 | ctrl->value = tvp514x_reg_list[REG_AFE_GAIN_CTRL].val; | ||
802 | if ((ctrl->value & 0x3) == 3) | ||
803 | ctrl->value = 1; | ||
804 | else | ||
805 | ctrl->value = 0; | ||
806 | |||
807 | break; | ||
808 | default: | ||
809 | v4l_err(decoder->client, | ||
810 | "invalid control id %d\n", ctrl->id); | ||
811 | return -EINVAL; | ||
812 | } | ||
813 | |||
814 | v4l_dbg(1, debug, decoder->client, | ||
815 | "Get Control: ID - %d - %d", | ||
816 | ctrl->id, ctrl->value); | ||
817 | return 0; | ||
818 | } | ||
819 | |||
820 | /** | ||
821 | * ioctl_s_ctrl - V4L2 decoder interface handler for VIDIOC_S_CTRL ioctl | ||
822 | * @s: pointer to standard V4L2 device structure | ||
823 | * @ctrl: pointer to v4l2_control structure | ||
824 | * | ||
825 | * If the requested control is supported, sets the control's current | ||
826 | * value in HW. Otherwise, returns -EINVAL if the control is not supported. | ||
827 | */ | ||
828 | static int | ||
829 | ioctl_s_ctrl(struct v4l2_int_device *s, struct v4l2_control *ctrl) | ||
830 | { | ||
831 | struct tvp514x_decoder *decoder = s->priv; | ||
832 | int err = -EINVAL, value; | ||
833 | |||
834 | if (ctrl == NULL) | ||
835 | return err; | ||
836 | |||
837 | value = (__s32) ctrl->value; | ||
838 | |||
839 | switch (ctrl->id) { | ||
840 | case V4L2_CID_BRIGHTNESS: | ||
841 | if (ctrl->value < 0 || ctrl->value > 255) { | ||
842 | v4l_err(decoder->client, | ||
843 | "invalid brightness setting %d\n", | ||
844 | ctrl->value); | ||
845 | return -ERANGE; | ||
846 | } | ||
847 | err = tvp514x_write_reg(decoder->client, REG_BRIGHTNESS, | ||
848 | value); | ||
849 | if (err) | ||
850 | return err; | ||
851 | tvp514x_reg_list[REG_BRIGHTNESS].val = value; | ||
852 | break; | ||
853 | case V4L2_CID_CONTRAST: | ||
854 | if (ctrl->value < 0 || ctrl->value > 255) { | ||
855 | v4l_err(decoder->client, | ||
856 | "invalid contrast setting %d\n", | ||
857 | ctrl->value); | ||
858 | return -ERANGE; | ||
859 | } | ||
860 | err = tvp514x_write_reg(decoder->client, REG_CONTRAST, | ||
861 | value); | ||
862 | if (err) | ||
863 | return err; | ||
864 | tvp514x_reg_list[REG_CONTRAST].val = value; | ||
865 | break; | ||
866 | case V4L2_CID_SATURATION: | ||
867 | if (ctrl->value < 0 || ctrl->value > 255) { | ||
868 | v4l_err(decoder->client, | ||
869 | "invalid saturation setting %d\n", | ||
870 | ctrl->value); | ||
871 | return -ERANGE; | ||
872 | } | ||
873 | err = tvp514x_write_reg(decoder->client, REG_SATURATION, | ||
874 | value); | ||
875 | if (err) | ||
876 | return err; | ||
877 | tvp514x_reg_list[REG_SATURATION].val = value; | ||
878 | break; | ||
879 | case V4L2_CID_HUE: | ||
880 | if (value == 180) | ||
881 | value = 0x7F; | ||
882 | else if (value == -180) | ||
883 | value = 0x80; | ||
884 | else if (value == 0) | ||
885 | value = 0; | ||
886 | else { | ||
887 | v4l_err(decoder->client, | ||
888 | "invalid hue setting %d\n", | ||
889 | ctrl->value); | ||
890 | return -ERANGE; | ||
891 | } | ||
892 | err = tvp514x_write_reg(decoder->client, REG_HUE, | ||
893 | value); | ||
894 | if (err) | ||
895 | return err; | ||
896 | tvp514x_reg_list[REG_HUE].val = value; | ||
897 | break; | ||
898 | case V4L2_CID_AUTOGAIN: | ||
899 | if (value == 1) | ||
900 | value = 0x0F; | ||
901 | else if (value == 0) | ||
902 | value = 0x0C; | ||
903 | else { | ||
904 | v4l_err(decoder->client, | ||
905 | "invalid auto gain setting %d\n", | ||
906 | ctrl->value); | ||
907 | return -ERANGE; | ||
908 | } | ||
909 | err = tvp514x_write_reg(decoder->client, REG_AFE_GAIN_CTRL, | ||
910 | value); | ||
911 | if (err) | ||
912 | return err; | ||
913 | tvp514x_reg_list[REG_AFE_GAIN_CTRL].val = value; | ||
914 | break; | ||
915 | default: | ||
916 | v4l_err(decoder->client, | ||
917 | "invalid control id %d\n", ctrl->id); | ||
918 | return err; | ||
919 | } | ||
920 | |||
921 | v4l_dbg(1, debug, decoder->client, | ||
922 | "Set Control: ID - %d - %d", | ||
923 | ctrl->id, ctrl->value); | ||
924 | |||
925 | return err; | ||
926 | } | ||
927 | |||
928 | /** | ||
929 | * ioctl_enum_fmt_cap - Implement the CAPTURE buffer VIDIOC_ENUM_FMT ioctl | ||
930 | * @s: pointer to standard V4L2 device structure | ||
931 | * @fmt: standard V4L2 VIDIOC_ENUM_FMT ioctl structure | ||
932 | * | ||
933 | * Implement the VIDIOC_ENUM_FMT ioctl to enumerate supported formats | ||
934 | */ | ||
935 | static int | ||
936 | ioctl_enum_fmt_cap(struct v4l2_int_device *s, struct v4l2_fmtdesc *fmt) | ||
937 | { | ||
938 | struct tvp514x_decoder *decoder = s->priv; | ||
939 | int index; | ||
940 | |||
941 | if (fmt == NULL) | ||
942 | return -EINVAL; | ||
943 | |||
944 | index = fmt->index; | ||
945 | if ((index >= decoder->num_fmts) || (index < 0)) | ||
946 | return -EINVAL; /* Index out of bound */ | ||
947 | |||
948 | if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | ||
949 | return -EINVAL; /* only capture is supported */ | ||
950 | |||
951 | memcpy(fmt, &decoder->fmt_list[index], | ||
952 | sizeof(struct v4l2_fmtdesc)); | ||
953 | |||
954 | v4l_dbg(1, debug, decoder->client, | ||
955 | "Current FMT: index - %d (%s)", | ||
956 | decoder->fmt_list[index].index, | ||
957 | decoder->fmt_list[index].description); | ||
958 | return 0; | ||
959 | } | ||
960 | |||
961 | /** | ||
962 | * ioctl_try_fmt_cap - Implement the CAPTURE buffer VIDIOC_TRY_FMT ioctl | ||
963 | * @s: pointer to standard V4L2 device structure | ||
964 | * @f: pointer to standard V4L2 VIDIOC_TRY_FMT ioctl structure | ||
965 | * | ||
966 | * Implement the VIDIOC_TRY_FMT ioctl for the CAPTURE buffer type. This | ||
967 | * ioctl is used to negotiate the image capture size and pixel format | ||
968 | * without actually making it take effect. | ||
969 | */ | ||
970 | static int | ||
971 | ioctl_try_fmt_cap(struct v4l2_int_device *s, struct v4l2_format *f) | ||
972 | { | ||
973 | struct tvp514x_decoder *decoder = s->priv; | ||
974 | int ifmt; | ||
975 | struct v4l2_pix_format *pix; | ||
976 | enum tvp514x_std current_std; | ||
977 | |||
978 | if (f == NULL) | ||
979 | return -EINVAL; | ||
980 | |||
981 | if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | ||
982 | f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; | ||
983 | |||
984 | pix = &f->fmt.pix; | ||
985 | |||
986 | /* Calculate height and width based on current standard */ | ||
987 | current_std = tvp514x_get_current_std(decoder); | ||
988 | if (current_std == STD_INVALID) | ||
989 | return -EINVAL; | ||
990 | |||
991 | decoder->current_std = current_std; | ||
992 | pix->width = decoder->std_list[current_std].width; | ||
993 | pix->height = decoder->std_list[current_std].height; | ||
994 | |||
995 | for (ifmt = 0; ifmt < decoder->num_fmts; ifmt++) { | ||
996 | if (pix->pixelformat == | ||
997 | decoder->fmt_list[ifmt].pixelformat) | ||
998 | break; | ||
999 | } | ||
1000 | if (ifmt == decoder->num_fmts) | ||
1001 | ifmt = 0; /* None of the format matched, select default */ | ||
1002 | pix->pixelformat = decoder->fmt_list[ifmt].pixelformat; | ||
1003 | |||
1004 | pix->field = V4L2_FIELD_INTERLACED; | ||
1005 | pix->bytesperline = pix->width * 2; | ||
1006 | pix->sizeimage = pix->bytesperline * pix->height; | ||
1007 | pix->colorspace = V4L2_COLORSPACE_SMPTE170M; | ||
1008 | pix->priv = 0; | ||
1009 | |||
1010 | v4l_dbg(1, debug, decoder->client, | ||
1011 | "Try FMT: pixelformat - %s, bytesperline - %d" | ||
1012 | "Width - %d, Height - %d", | ||
1013 | decoder->fmt_list[ifmt].description, pix->bytesperline, | ||
1014 | pix->width, pix->height); | ||
1015 | return 0; | ||
1016 | } | ||
1017 | |||
1018 | /** | ||
1019 | * ioctl_s_fmt_cap - V4L2 decoder interface handler for VIDIOC_S_FMT ioctl | ||
1020 | * @s: pointer to standard V4L2 device structure | ||
1021 | * @f: pointer to standard V4L2 VIDIOC_S_FMT ioctl structure | ||
1022 | * | ||
1023 | * If the requested format is supported, configures the HW to use that | ||
1024 | * format, returns error code if format not supported or HW can't be | ||
1025 | * correctly configured. | ||
1026 | */ | ||
1027 | static int | ||
1028 | ioctl_s_fmt_cap(struct v4l2_int_device *s, struct v4l2_format *f) | ||
1029 | { | ||
1030 | struct tvp514x_decoder *decoder = s->priv; | ||
1031 | struct v4l2_pix_format *pix; | ||
1032 | int rval; | ||
1033 | |||
1034 | if (f == NULL) | ||
1035 | return -EINVAL; | ||
1036 | |||
1037 | if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | ||
1038 | return -EINVAL; /* only capture is supported */ | ||
1039 | |||
1040 | pix = &f->fmt.pix; | ||
1041 | rval = ioctl_try_fmt_cap(s, f); | ||
1042 | if (rval) | ||
1043 | return rval; | ||
1044 | |||
1045 | decoder->pix = *pix; | ||
1046 | |||
1047 | return rval; | ||
1048 | } | ||
1049 | |||
1050 | /** | ||
1051 | * ioctl_g_fmt_cap - V4L2 decoder interface handler for ioctl_g_fmt_cap | ||
1052 | * @s: pointer to standard V4L2 device structure | ||
1053 | * @f: pointer to standard V4L2 v4l2_format structure | ||
1054 | * | ||
1055 | * Returns the decoder's current pixel format in the v4l2_format | ||
1056 | * parameter. | ||
1057 | */ | ||
1058 | static int | ||
1059 | ioctl_g_fmt_cap(struct v4l2_int_device *s, struct v4l2_format *f) | ||
1060 | { | ||
1061 | struct tvp514x_decoder *decoder = s->priv; | ||
1062 | |||
1063 | if (f == NULL) | ||
1064 | return -EINVAL; | ||
1065 | |||
1066 | if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | ||
1067 | return -EINVAL; /* only capture is supported */ | ||
1068 | |||
1069 | f->fmt.pix = decoder->pix; | ||
1070 | |||
1071 | v4l_dbg(1, debug, decoder->client, | ||
1072 | "Current FMT: bytesperline - %d" | ||
1073 | "Width - %d, Height - %d", | ||
1074 | decoder->pix.bytesperline, | ||
1075 | decoder->pix.width, decoder->pix.height); | ||
1076 | return 0; | ||
1077 | } | ||
1078 | |||
1079 | /** | ||
1080 | * ioctl_g_parm - V4L2 decoder interface handler for VIDIOC_G_PARM ioctl | ||
1081 | * @s: pointer to standard V4L2 device structure | ||
1082 | * @a: pointer to standard V4L2 VIDIOC_G_PARM ioctl structure | ||
1083 | * | ||
1084 | * Returns the decoder's video CAPTURE parameters. | ||
1085 | */ | ||
1086 | static int | ||
1087 | ioctl_g_parm(struct v4l2_int_device *s, struct v4l2_streamparm *a) | ||
1088 | { | ||
1089 | struct tvp514x_decoder *decoder = s->priv; | ||
1090 | struct v4l2_captureparm *cparm; | ||
1091 | enum tvp514x_std current_std; | ||
1092 | |||
1093 | if (a == NULL) | ||
1094 | return -EINVAL; | ||
1095 | |||
1096 | if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | ||
1097 | return -EINVAL; /* only capture is supported */ | ||
1098 | |||
1099 | memset(a, 0, sizeof(*a)); | ||
1100 | a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; | ||
1101 | |||
1102 | /* get the current standard */ | ||
1103 | current_std = tvp514x_get_current_std(decoder); | ||
1104 | if (current_std == STD_INVALID) | ||
1105 | return -EINVAL; | ||
1106 | |||
1107 | decoder->current_std = current_std; | ||
1108 | |||
1109 | cparm = &a->parm.capture; | ||
1110 | cparm->capability = V4L2_CAP_TIMEPERFRAME; | ||
1111 | cparm->timeperframe = | ||
1112 | decoder->std_list[current_std].standard.frameperiod; | ||
1113 | |||
1114 | return 0; | ||
1115 | } | ||
1116 | |||
1117 | /** | ||
1118 | * ioctl_s_parm - V4L2 decoder interface handler for VIDIOC_S_PARM ioctl | ||
1119 | * @s: pointer to standard V4L2 device structure | ||
1120 | * @a: pointer to standard V4L2 VIDIOC_S_PARM ioctl structure | ||
1121 | * | ||
1122 | * Configures the decoder to use the input parameters, if possible. If | ||
1123 | * not possible, returns the appropriate error code. | ||
1124 | */ | ||
1125 | static int | ||
1126 | ioctl_s_parm(struct v4l2_int_device *s, struct v4l2_streamparm *a) | ||
1127 | { | ||
1128 | struct tvp514x_decoder *decoder = s->priv; | ||
1129 | struct v4l2_fract *timeperframe; | ||
1130 | enum tvp514x_std current_std; | ||
1131 | |||
1132 | if (a == NULL) | ||
1133 | return -EINVAL; | ||
1134 | |||
1135 | if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | ||
1136 | return -EINVAL; /* only capture is supported */ | ||
1137 | |||
1138 | timeperframe = &a->parm.capture.timeperframe; | ||
1139 | |||
1140 | /* get the current standard */ | ||
1141 | current_std = tvp514x_get_current_std(decoder); | ||
1142 | if (current_std == STD_INVALID) | ||
1143 | return -EINVAL; | ||
1144 | |||
1145 | decoder->current_std = current_std; | ||
1146 | |||
1147 | *timeperframe = | ||
1148 | decoder->std_list[current_std].standard.frameperiod; | ||
1149 | |||
1150 | return 0; | ||
1151 | } | ||
1152 | |||
1153 | /** | ||
1154 | * ioctl_g_ifparm - V4L2 decoder interface handler for vidioc_int_g_ifparm_num | ||
1155 | * @s: pointer to standard V4L2 device structure | ||
1156 | * @p: pointer to standard V4L2 vidioc_int_g_ifparm_num ioctl structure | ||
1157 | * | ||
1158 | * Gets slave interface parameters. | ||
1159 | * Calculates the required xclk value to support the requested | ||
1160 | * clock parameters in p. This value is returned in the p | ||
1161 | * parameter. | ||
1162 | */ | ||
1163 | static int ioctl_g_ifparm(struct v4l2_int_device *s, struct v4l2_ifparm *p) | ||
1164 | { | ||
1165 | struct tvp514x_decoder *decoder = s->priv; | ||
1166 | int rval; | ||
1167 | |||
1168 | if (p == NULL) | ||
1169 | return -EINVAL; | ||
1170 | |||
1171 | if (NULL == decoder->pdata->ifparm) | ||
1172 | return -EINVAL; | ||
1173 | |||
1174 | rval = decoder->pdata->ifparm(p); | ||
1175 | if (rval) { | ||
1176 | v4l_err(decoder->client, "g_ifparm.Err[%d]\n", rval); | ||
1177 | return rval; | ||
1178 | } | ||
1179 | |||
1180 | p->u.bt656.clock_curr = TVP514X_XCLK_BT656; | ||
1181 | |||
1182 | return 0; | ||
1183 | } | ||
1184 | |||
1185 | /** | ||
1186 | * ioctl_g_priv - V4L2 decoder interface handler for vidioc_int_g_priv_num | ||
1187 | * @s: pointer to standard V4L2 device structure | ||
1188 | * @p: void pointer to hold decoder's private data address | ||
1189 | * | ||
1190 | * Returns device's (decoder's) private data area address in p parameter | ||
1191 | */ | ||
1192 | static int ioctl_g_priv(struct v4l2_int_device *s, void *p) | ||
1193 | { | ||
1194 | struct tvp514x_decoder *decoder = s->priv; | ||
1195 | |||
1196 | if (NULL == decoder->pdata->priv_data_set) | ||
1197 | return -EINVAL; | ||
1198 | |||
1199 | return decoder->pdata->priv_data_set(p); | ||
1200 | } | ||
1201 | |||
1202 | /** | ||
1203 | * ioctl_s_power - V4L2 decoder interface handler for vidioc_int_s_power_num | ||
1204 | * @s: pointer to standard V4L2 device structure | ||
1205 | * @on: power state to which device is to be set | ||
1206 | * | ||
1207 | * Sets devices power state to requrested state, if possible. | ||
1208 | */ | ||
1209 | static int ioctl_s_power(struct v4l2_int_device *s, enum v4l2_power on) | ||
1210 | { | ||
1211 | struct tvp514x_decoder *decoder = s->priv; | ||
1212 | int err = 0; | ||
1213 | |||
1214 | switch (on) { | ||
1215 | case V4L2_POWER_OFF: | ||
1216 | /* Power Down Sequence */ | ||
1217 | err = | ||
1218 | tvp514x_write_reg(decoder->client, REG_OPERATION_MODE, | ||
1219 | 0x01); | ||
1220 | /* Disable mux for TVP5146/47 decoder data path */ | ||
1221 | if (decoder->pdata->power_set) | ||
1222 | err |= decoder->pdata->power_set(on); | ||
1223 | decoder->state = STATE_NOT_DETECTED; | ||
1224 | break; | ||
1225 | |||
1226 | case V4L2_POWER_STANDBY: | ||
1227 | if (decoder->pdata->power_set) | ||
1228 | err = decoder->pdata->power_set(on); | ||
1229 | break; | ||
1230 | |||
1231 | case V4L2_POWER_ON: | ||
1232 | /* Enable mux for TVP5146/47 decoder data path */ | ||
1233 | if ((decoder->pdata->power_set) && | ||
1234 | (decoder->state == STATE_NOT_DETECTED)) { | ||
1235 | int i; | ||
1236 | struct tvp514x_init_seq *int_seq = | ||
1237 | (struct tvp514x_init_seq *) | ||
1238 | decoder->id->driver_data; | ||
1239 | |||
1240 | err = decoder->pdata->power_set(on); | ||
1241 | |||
1242 | /* Power Up Sequence */ | ||
1243 | for (i = 0; i < int_seq->no_regs; i++) { | ||
1244 | err |= tvp514x_write_reg(decoder->client, | ||
1245 | int_seq->init_reg_seq[i].reg, | ||
1246 | int_seq->init_reg_seq[i].val); | ||
1247 | } | ||
1248 | /* Detect the sensor is not already detected */ | ||
1249 | err |= tvp514x_detect(decoder); | ||
1250 | if (err) { | ||
1251 | v4l_err(decoder->client, | ||
1252 | "Unable to detect decoder\n"); | ||
1253 | return err; | ||
1254 | } | ||
1255 | } | ||
1256 | err |= tvp514x_configure(decoder); | ||
1257 | break; | ||
1258 | |||
1259 | default: | ||
1260 | err = -ENODEV; | ||
1261 | break; | ||
1262 | } | ||
1263 | |||
1264 | return err; | ||
1265 | } | ||
1266 | |||
1267 | /** | ||
1268 | * ioctl_init - V4L2 decoder interface handler for VIDIOC_INT_INIT | ||
1269 | * @s: pointer to standard V4L2 device structure | ||
1270 | * | ||
1271 | * Initialize the decoder device (calls tvp514x_configure()) | ||
1272 | */ | ||
1273 | static int ioctl_init(struct v4l2_int_device *s) | ||
1274 | { | ||
1275 | struct tvp514x_decoder *decoder = s->priv; | ||
1276 | |||
1277 | /* Set default standard to auto */ | ||
1278 | tvp514x_reg_list[REG_VIDEO_STD].val = | ||
1279 | VIDEO_STD_AUTO_SWITCH_BIT; | ||
1280 | |||
1281 | return tvp514x_configure(decoder); | ||
1282 | } | ||
1283 | |||
1284 | /** | ||
1285 | * ioctl_dev_exit - V4L2 decoder interface handler for vidioc_int_dev_exit_num | ||
1286 | * @s: pointer to standard V4L2 device structure | ||
1287 | * | ||
1288 | * Delinitialise the dev. at slave detach. The complement of ioctl_dev_init. | ||
1289 | */ | ||
1290 | static int ioctl_dev_exit(struct v4l2_int_device *s) | ||
1291 | { | ||
1292 | return 0; | ||
1293 | } | ||
1294 | |||
1295 | /** | ||
1296 | * ioctl_dev_init - V4L2 decoder interface handler for vidioc_int_dev_init_num | ||
1297 | * @s: pointer to standard V4L2 device structure | ||
1298 | * | ||
1299 | * Initialise the device when slave attaches to the master. Returns 0 if | ||
1300 | * TVP5146/47 device could be found, otherwise returns appropriate error. | ||
1301 | */ | ||
1302 | static int ioctl_dev_init(struct v4l2_int_device *s) | ||
1303 | { | ||
1304 | struct tvp514x_decoder *decoder = s->priv; | ||
1305 | int err; | ||
1306 | |||
1307 | err = tvp514x_detect(decoder); | ||
1308 | if (err < 0) { | ||
1309 | v4l_err(decoder->client, | ||
1310 | "Unable to detect decoder\n"); | ||
1311 | return err; | ||
1312 | } | ||
1313 | |||
1314 | v4l_info(decoder->client, | ||
1315 | "chip version 0x%.2x detected\n", decoder->ver); | ||
1316 | |||
1317 | return 0; | ||
1318 | } | ||
1319 | |||
1320 | static struct v4l2_int_ioctl_desc tvp514x_ioctl_desc[] = { | ||
1321 | {vidioc_int_dev_init_num, (v4l2_int_ioctl_func*) ioctl_dev_init}, | ||
1322 | {vidioc_int_dev_exit_num, (v4l2_int_ioctl_func*) ioctl_dev_exit}, | ||
1323 | {vidioc_int_s_power_num, (v4l2_int_ioctl_func*) ioctl_s_power}, | ||
1324 | {vidioc_int_g_priv_num, (v4l2_int_ioctl_func*) ioctl_g_priv}, | ||
1325 | {vidioc_int_g_ifparm_num, (v4l2_int_ioctl_func*) ioctl_g_ifparm}, | ||
1326 | {vidioc_int_init_num, (v4l2_int_ioctl_func*) ioctl_init}, | ||
1327 | {vidioc_int_enum_fmt_cap_num, | ||
1328 | (v4l2_int_ioctl_func *) ioctl_enum_fmt_cap}, | ||
1329 | {vidioc_int_try_fmt_cap_num, | ||
1330 | (v4l2_int_ioctl_func *) ioctl_try_fmt_cap}, | ||
1331 | {vidioc_int_g_fmt_cap_num, | ||
1332 | (v4l2_int_ioctl_func *) ioctl_g_fmt_cap}, | ||
1333 | {vidioc_int_s_fmt_cap_num, | ||
1334 | (v4l2_int_ioctl_func *) ioctl_s_fmt_cap}, | ||
1335 | {vidioc_int_g_parm_num, (v4l2_int_ioctl_func *) ioctl_g_parm}, | ||
1336 | {vidioc_int_s_parm_num, (v4l2_int_ioctl_func *) ioctl_s_parm}, | ||
1337 | {vidioc_int_queryctrl_num, | ||
1338 | (v4l2_int_ioctl_func *) ioctl_queryctrl}, | ||
1339 | {vidioc_int_g_ctrl_num, (v4l2_int_ioctl_func *) ioctl_g_ctrl}, | ||
1340 | {vidioc_int_s_ctrl_num, (v4l2_int_ioctl_func *) ioctl_s_ctrl}, | ||
1341 | {vidioc_int_querystd_num, (v4l2_int_ioctl_func *) ioctl_querystd}, | ||
1342 | {vidioc_int_s_std_num, (v4l2_int_ioctl_func *) ioctl_s_std}, | ||
1343 | {vidioc_int_s_video_routing_num, | ||
1344 | (v4l2_int_ioctl_func *) ioctl_s_routing}, | ||
1345 | }; | ||
1346 | |||
1347 | static struct v4l2_int_slave tvp514x_slave = { | ||
1348 | .ioctls = tvp514x_ioctl_desc, | ||
1349 | .num_ioctls = ARRAY_SIZE(tvp514x_ioctl_desc), | ||
1350 | }; | ||
1351 | |||
1352 | static struct tvp514x_decoder tvp514x_dev = { | ||
1353 | .state = STATE_NOT_DETECTED, | ||
1354 | |||
1355 | .fmt_list = tvp514x_fmt_list, | ||
1356 | .num_fmts = ARRAY_SIZE(tvp514x_fmt_list), | ||
1357 | |||
1358 | .pix = { /* Default to NTSC 8-bit YUV 422 */ | ||
1359 | .width = NTSC_NUM_ACTIVE_PIXELS, | ||
1360 | .height = NTSC_NUM_ACTIVE_LINES, | ||
1361 | .pixelformat = V4L2_PIX_FMT_UYVY, | ||
1362 | .field = V4L2_FIELD_INTERLACED, | ||
1363 | .bytesperline = NTSC_NUM_ACTIVE_PIXELS * 2, | ||
1364 | .sizeimage = | ||
1365 | NTSC_NUM_ACTIVE_PIXELS * 2 * NTSC_NUM_ACTIVE_LINES, | ||
1366 | .colorspace = V4L2_COLORSPACE_SMPTE170M, | ||
1367 | }, | ||
1368 | |||
1369 | .current_std = STD_NTSC_MJ, | ||
1370 | .std_list = tvp514x_std_list, | ||
1371 | .num_stds = ARRAY_SIZE(tvp514x_std_list), | ||
1372 | |||
1373 | }; | ||
1374 | |||
1375 | static struct v4l2_int_device tvp514x_int_device = { | ||
1376 | .module = THIS_MODULE, | ||
1377 | .name = TVP514X_MODULE_NAME, | ||
1378 | .priv = &tvp514x_dev, | ||
1379 | .type = v4l2_int_type_slave, | ||
1380 | .u = { | ||
1381 | .slave = &tvp514x_slave, | ||
1382 | }, | ||
1383 | }; | ||
1384 | |||
1385 | /** | ||
1386 | * tvp514x_probe - decoder driver i2c probe handler | ||
1387 | * @client: i2c driver client device structure | ||
1388 | * | ||
1389 | * Register decoder as an i2c client device and V4L2 | ||
1390 | * device. | ||
1391 | */ | ||
1392 | static int | ||
1393 | tvp514x_probe(struct i2c_client *client, const struct i2c_device_id *id) | ||
1394 | { | ||
1395 | struct tvp514x_decoder *decoder = &tvp514x_dev; | ||
1396 | int err; | ||
1397 | |||
1398 | /* Check if the adapter supports the needed features */ | ||
1399 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | ||
1400 | return -EIO; | ||
1401 | |||
1402 | decoder->pdata = client->dev.platform_data; | ||
1403 | if (!decoder->pdata) { | ||
1404 | v4l_err(client, "No platform data\n!!"); | ||
1405 | return -ENODEV; | ||
1406 | } | ||
1407 | /* | ||
1408 | * Fetch platform specific data, and configure the | ||
1409 | * tvp514x_reg_list[] accordingly. Since this is one | ||
1410 | * time configuration, no need to preserve. | ||
1411 | */ | ||
1412 | tvp514x_reg_list[REG_OUTPUT_FORMATTER2].val |= | ||
1413 | (decoder->pdata->clk_polarity << 1); | ||
1414 | tvp514x_reg_list[REG_SYNC_CONTROL].val |= | ||
1415 | ((decoder->pdata->hs_polarity << 2) | | ||
1416 | (decoder->pdata->vs_polarity << 3)); | ||
1417 | /* | ||
1418 | * Save the id data, required for power up sequence | ||
1419 | */ | ||
1420 | decoder->id = (struct i2c_device_id *)id; | ||
1421 | /* Attach to Master */ | ||
1422 | strcpy(tvp514x_int_device.u.slave->attach_to, decoder->pdata->master); | ||
1423 | decoder->v4l2_int_device = &tvp514x_int_device; | ||
1424 | decoder->client = client; | ||
1425 | i2c_set_clientdata(client, decoder); | ||
1426 | |||
1427 | /* Register with V4L2 layer as slave device */ | ||
1428 | err = v4l2_int_device_register(decoder->v4l2_int_device); | ||
1429 | if (err) { | ||
1430 | i2c_set_clientdata(client, NULL); | ||
1431 | v4l_err(client, | ||
1432 | "Unable to register to v4l2. Err[%d]\n", err); | ||
1433 | |||
1434 | } else | ||
1435 | v4l_info(client, "Registered to v4l2 master %s!!\n", | ||
1436 | decoder->pdata->master); | ||
1437 | |||
1438 | return 0; | ||
1439 | } | ||
1440 | |||
1441 | /** | ||
1442 | * tvp514x_remove - decoder driver i2c remove handler | ||
1443 | * @client: i2c driver client device structure | ||
1444 | * | ||
1445 | * Unregister decoder as an i2c client device and V4L2 | ||
1446 | * device. Complement of tvp514x_probe(). | ||
1447 | */ | ||
1448 | static int __exit tvp514x_remove(struct i2c_client *client) | ||
1449 | { | ||
1450 | struct tvp514x_decoder *decoder = i2c_get_clientdata(client); | ||
1451 | |||
1452 | if (!client->adapter) | ||
1453 | return -ENODEV; /* our client isn't attached */ | ||
1454 | |||
1455 | v4l2_int_device_unregister(decoder->v4l2_int_device); | ||
1456 | i2c_set_clientdata(client, NULL); | ||
1457 | |||
1458 | return 0; | ||
1459 | } | ||
1460 | /* | ||
1461 | * TVP5146 Init/Power on Sequence | ||
1462 | */ | ||
1463 | static const struct tvp514x_reg tvp5146_init_reg_seq[] = { | ||
1464 | {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x02}, | ||
1465 | {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00}, | ||
1466 | {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0x80}, | ||
1467 | {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x01}, | ||
1468 | {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x60}, | ||
1469 | {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00}, | ||
1470 | {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0xB0}, | ||
1471 | {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x01}, | ||
1472 | {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x00}, | ||
1473 | {TOK_WRITE, REG_OPERATION_MODE, 0x01}, | ||
1474 | {TOK_WRITE, REG_OPERATION_MODE, 0x00}, | ||
1475 | }; | ||
1476 | static const struct tvp514x_init_seq tvp5146_init = { | ||
1477 | .no_regs = ARRAY_SIZE(tvp5146_init_reg_seq), | ||
1478 | .init_reg_seq = tvp5146_init_reg_seq, | ||
1479 | }; | ||
1480 | /* | ||
1481 | * TVP5147 Init/Power on Sequence | ||
1482 | */ | ||
1483 | static const struct tvp514x_reg tvp5147_init_reg_seq[] = { | ||
1484 | {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x02}, | ||
1485 | {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00}, | ||
1486 | {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0x80}, | ||
1487 | {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x01}, | ||
1488 | {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x60}, | ||
1489 | {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00}, | ||
1490 | {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0xB0}, | ||
1491 | {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x01}, | ||
1492 | {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x16}, | ||
1493 | {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00}, | ||
1494 | {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0xA0}, | ||
1495 | {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x16}, | ||
1496 | {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x60}, | ||
1497 | {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00}, | ||
1498 | {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0xB0}, | ||
1499 | {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x00}, | ||
1500 | {TOK_WRITE, REG_OPERATION_MODE, 0x01}, | ||
1501 | {TOK_WRITE, REG_OPERATION_MODE, 0x00}, | ||
1502 | }; | ||
1503 | static const struct tvp514x_init_seq tvp5147_init = { | ||
1504 | .no_regs = ARRAY_SIZE(tvp5147_init_reg_seq), | ||
1505 | .init_reg_seq = tvp5147_init_reg_seq, | ||
1506 | }; | ||
1507 | /* | ||
1508 | * TVP5146M2/TVP5147M1 Init/Power on Sequence | ||
1509 | */ | ||
1510 | static const struct tvp514x_reg tvp514xm_init_reg_seq[] = { | ||
1511 | {TOK_WRITE, REG_OPERATION_MODE, 0x01}, | ||
1512 | {TOK_WRITE, REG_OPERATION_MODE, 0x00}, | ||
1513 | }; | ||
1514 | static const struct tvp514x_init_seq tvp514xm_init = { | ||
1515 | .no_regs = ARRAY_SIZE(tvp514xm_init_reg_seq), | ||
1516 | .init_reg_seq = tvp514xm_init_reg_seq, | ||
1517 | }; | ||
1518 | /* | ||
1519 | * I2C Device Table - | ||
1520 | * | ||
1521 | * name - Name of the actual device/chip. | ||
1522 | * driver_data - Driver data | ||
1523 | */ | ||
1524 | static const struct i2c_device_id tvp514x_id[] = { | ||
1525 | {"tvp5146", (unsigned long)&tvp5146_init}, | ||
1526 | {"tvp5146m2", (unsigned long)&tvp514xm_init}, | ||
1527 | {"tvp5147", (unsigned long)&tvp5147_init}, | ||
1528 | {"tvp5147m1", (unsigned long)&tvp514xm_init}, | ||
1529 | {}, | ||
1530 | }; | ||
1531 | |||
1532 | MODULE_DEVICE_TABLE(i2c, tvp514x_id); | ||
1533 | |||
1534 | static struct i2c_driver tvp514x_i2c_driver = { | ||
1535 | .driver = { | ||
1536 | .name = TVP514X_MODULE_NAME, | ||
1537 | .owner = THIS_MODULE, | ||
1538 | }, | ||
1539 | .probe = tvp514x_probe, | ||
1540 | .remove = __exit_p(tvp514x_remove), | ||
1541 | .id_table = tvp514x_id, | ||
1542 | }; | ||
1543 | |||
1544 | /** | ||
1545 | * tvp514x_init | ||
1546 | * | ||
1547 | * Module init function | ||
1548 | */ | ||
1549 | static int __init tvp514x_init(void) | ||
1550 | { | ||
1551 | return i2c_add_driver(&tvp514x_i2c_driver); | ||
1552 | } | ||
1553 | |||
1554 | /** | ||
1555 | * tvp514x_cleanup | ||
1556 | * | ||
1557 | * Module exit function | ||
1558 | */ | ||
1559 | static void __exit tvp514x_cleanup(void) | ||
1560 | { | ||
1561 | i2c_del_driver(&tvp514x_i2c_driver); | ||
1562 | } | ||
1563 | |||
1564 | module_init(tvp514x_init); | ||
1565 | module_exit(tvp514x_cleanup); | ||
1566 | |||
1567 | MODULE_AUTHOR("Texas Instruments"); | ||
1568 | MODULE_DESCRIPTION("TVP514X linux decoder driver"); | ||
1569 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/media/video/tvp514x_regs.h b/drivers/media/video/tvp514x_regs.h new file mode 100644 index 000000000000..351620aeecc2 --- /dev/null +++ b/drivers/media/video/tvp514x_regs.h | |||
@@ -0,0 +1,297 @@ | |||
1 | /* | ||
2 | * drivers/media/video/tvp514x_regs.h | ||
3 | * | ||
4 | * Copyright (C) 2008 Texas Instruments Inc | ||
5 | * Author: Vaibhav Hiremath <hvaibhav@ti.com> | ||
6 | * | ||
7 | * Contributors: | ||
8 | * Sivaraj R <sivaraj@ti.com> | ||
9 | * Brijesh R Jadav <brijesh.j@ti.com> | ||
10 | * Hardik Shah <hardik.shah@ti.com> | ||
11 | * Manjunath Hadli <mrh@ti.com> | ||
12 | * Karicheri Muralidharan <m-karicheri2@ti.com> | ||
13 | * | ||
14 | * This package is free software; you can redistribute it and/or modify | ||
15 | * it under the terms of the GNU General Public License version 2 as | ||
16 | * published by the Free Software Foundation. | ||
17 | * | ||
18 | * This program is distributed in the hope that it will be useful, | ||
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
21 | * GNU General Public License for more details. | ||
22 | * | ||
23 | * You should have received a copy of the GNU General Public License | ||
24 | * along with this program; if not, write to the Free Software | ||
25 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
26 | * | ||
27 | */ | ||
28 | |||
29 | #ifndef _TVP514X_REGS_H | ||
30 | #define _TVP514X_REGS_H | ||
31 | |||
32 | /* | ||
33 | * TVP5146/47 registers | ||
34 | */ | ||
35 | #define REG_INPUT_SEL (0x00) | ||
36 | #define REG_AFE_GAIN_CTRL (0x01) | ||
37 | #define REG_VIDEO_STD (0x02) | ||
38 | #define REG_OPERATION_MODE (0x03) | ||
39 | #define REG_AUTOSWITCH_MASK (0x04) | ||
40 | |||
41 | #define REG_COLOR_KILLER (0x05) | ||
42 | #define REG_LUMA_CONTROL1 (0x06) | ||
43 | #define REG_LUMA_CONTROL2 (0x07) | ||
44 | #define REG_LUMA_CONTROL3 (0x08) | ||
45 | |||
46 | #define REG_BRIGHTNESS (0x09) | ||
47 | #define REG_CONTRAST (0x0A) | ||
48 | #define REG_SATURATION (0x0B) | ||
49 | #define REG_HUE (0x0C) | ||
50 | |||
51 | #define REG_CHROMA_CONTROL1 (0x0D) | ||
52 | #define REG_CHROMA_CONTROL2 (0x0E) | ||
53 | |||
54 | /* 0x0F Reserved */ | ||
55 | |||
56 | #define REG_COMP_PR_SATURATION (0x10) | ||
57 | #define REG_COMP_Y_CONTRAST (0x11) | ||
58 | #define REG_COMP_PB_SATURATION (0x12) | ||
59 | |||
60 | /* 0x13 Reserved */ | ||
61 | |||
62 | #define REG_COMP_Y_BRIGHTNESS (0x14) | ||
63 | |||
64 | /* 0x15 Reserved */ | ||
65 | |||
66 | #define REG_AVID_START_PIXEL_LSB (0x16) | ||
67 | #define REG_AVID_START_PIXEL_MSB (0x17) | ||
68 | #define REG_AVID_STOP_PIXEL_LSB (0x18) | ||
69 | #define REG_AVID_STOP_PIXEL_MSB (0x19) | ||
70 | |||
71 | #define REG_HSYNC_START_PIXEL_LSB (0x1A) | ||
72 | #define REG_HSYNC_START_PIXEL_MSB (0x1B) | ||
73 | #define REG_HSYNC_STOP_PIXEL_LSB (0x1C) | ||
74 | #define REG_HSYNC_STOP_PIXEL_MSB (0x1D) | ||
75 | |||
76 | #define REG_VSYNC_START_LINE_LSB (0x1E) | ||
77 | #define REG_VSYNC_START_LINE_MSB (0x1F) | ||
78 | #define REG_VSYNC_STOP_LINE_LSB (0x20) | ||
79 | #define REG_VSYNC_STOP_LINE_MSB (0x21) | ||
80 | |||
81 | #define REG_VBLK_START_LINE_LSB (0x22) | ||
82 | #define REG_VBLK_START_LINE_MSB (0x23) | ||
83 | #define REG_VBLK_STOP_LINE_LSB (0x24) | ||
84 | #define REG_VBLK_STOP_LINE_MSB (0x25) | ||
85 | |||
86 | /* 0x26 - 0x27 Reserved */ | ||
87 | |||
88 | #define REG_FAST_SWTICH_CONTROL (0x28) | ||
89 | |||
90 | /* 0x29 Reserved */ | ||
91 | |||
92 | #define REG_FAST_SWTICH_SCART_DELAY (0x2A) | ||
93 | |||
94 | /* 0x2B Reserved */ | ||
95 | |||
96 | #define REG_SCART_DELAY (0x2C) | ||
97 | #define REG_CTI_DELAY (0x2D) | ||
98 | #define REG_CTI_CONTROL (0x2E) | ||
99 | |||
100 | /* 0x2F - 0x31 Reserved */ | ||
101 | |||
102 | #define REG_SYNC_CONTROL (0x32) | ||
103 | #define REG_OUTPUT_FORMATTER1 (0x33) | ||
104 | #define REG_OUTPUT_FORMATTER2 (0x34) | ||
105 | #define REG_OUTPUT_FORMATTER3 (0x35) | ||
106 | #define REG_OUTPUT_FORMATTER4 (0x36) | ||
107 | #define REG_OUTPUT_FORMATTER5 (0x37) | ||
108 | #define REG_OUTPUT_FORMATTER6 (0x38) | ||
109 | #define REG_CLEAR_LOST_LOCK (0x39) | ||
110 | |||
111 | #define REG_STATUS1 (0x3A) | ||
112 | #define REG_STATUS2 (0x3B) | ||
113 | |||
114 | #define REG_AGC_GAIN_STATUS_LSB (0x3C) | ||
115 | #define REG_AGC_GAIN_STATUS_MSB (0x3D) | ||
116 | |||
117 | /* 0x3E Reserved */ | ||
118 | |||
119 | #define REG_VIDEO_STD_STATUS (0x3F) | ||
120 | #define REG_GPIO_INPUT1 (0x40) | ||
121 | #define REG_GPIO_INPUT2 (0x41) | ||
122 | |||
123 | /* 0x42 - 0x45 Reserved */ | ||
124 | |||
125 | #define REG_AFE_COARSE_GAIN_CH1 (0x46) | ||
126 | #define REG_AFE_COARSE_GAIN_CH2 (0x47) | ||
127 | #define REG_AFE_COARSE_GAIN_CH3 (0x48) | ||
128 | #define REG_AFE_COARSE_GAIN_CH4 (0x49) | ||
129 | |||
130 | #define REG_AFE_FINE_GAIN_PB_B_LSB (0x4A) | ||
131 | #define REG_AFE_FINE_GAIN_PB_B_MSB (0x4B) | ||
132 | #define REG_AFE_FINE_GAIN_Y_G_CHROMA_LSB (0x4C) | ||
133 | #define REG_AFE_FINE_GAIN_Y_G_CHROMA_MSB (0x4D) | ||
134 | #define REG_AFE_FINE_GAIN_PR_R_LSB (0x4E) | ||
135 | #define REG_AFE_FINE_GAIN_PR_R_MSB (0x4F) | ||
136 | #define REG_AFE_FINE_GAIN_CVBS_LUMA_LSB (0x50) | ||
137 | #define REG_AFE_FINE_GAIN_CVBS_LUMA_MSB (0x51) | ||
138 | |||
139 | /* 0x52 - 0x68 Reserved */ | ||
140 | |||
141 | #define REG_FBIT_VBIT_CONTROL1 (0x69) | ||
142 | |||
143 | /* 0x6A - 0x6B Reserved */ | ||
144 | |||
145 | #define REG_BACKEND_AGC_CONTROL (0x6C) | ||
146 | |||
147 | /* 0x6D - 0x6E Reserved */ | ||
148 | |||
149 | #define REG_AGC_DECREMENT_SPEED_CONTROL (0x6F) | ||
150 | #define REG_ROM_VERSION (0x70) | ||
151 | |||
152 | /* 0x71 - 0x73 Reserved */ | ||
153 | |||
154 | #define REG_AGC_WHITE_PEAK_PROCESSING (0x74) | ||
155 | #define REG_FBIT_VBIT_CONTROL2 (0x75) | ||
156 | #define REG_VCR_TRICK_MODE_CONTROL (0x76) | ||
157 | #define REG_HORIZONTAL_SHAKE_INCREMENT (0x77) | ||
158 | #define REG_AGC_INCREMENT_SPEED (0x78) | ||
159 | #define REG_AGC_INCREMENT_DELAY (0x79) | ||
160 | |||
161 | /* 0x7A - 0x7F Reserved */ | ||
162 | |||
163 | #define REG_CHIP_ID_MSB (0x80) | ||
164 | #define REG_CHIP_ID_LSB (0x81) | ||
165 | |||
166 | /* 0x82 Reserved */ | ||
167 | |||
168 | #define REG_CPLL_SPEED_CONTROL (0x83) | ||
169 | |||
170 | /* 0x84 - 0x96 Reserved */ | ||
171 | |||
172 | #define REG_STATUS_REQUEST (0x97) | ||
173 | |||
174 | /* 0x98 - 0x99 Reserved */ | ||
175 | |||
176 | #define REG_VERTICAL_LINE_COUNT_LSB (0x9A) | ||
177 | #define REG_VERTICAL_LINE_COUNT_MSB (0x9B) | ||
178 | |||
179 | /* 0x9C - 0x9D Reserved */ | ||
180 | |||
181 | #define REG_AGC_DECREMENT_DELAY (0x9E) | ||
182 | |||
183 | /* 0x9F - 0xB0 Reserved */ | ||
184 | |||
185 | #define REG_VDP_TTX_FILTER_1_MASK1 (0xB1) | ||
186 | #define REG_VDP_TTX_FILTER_1_MASK2 (0xB2) | ||
187 | #define REG_VDP_TTX_FILTER_1_MASK3 (0xB3) | ||
188 | #define REG_VDP_TTX_FILTER_1_MASK4 (0xB4) | ||
189 | #define REG_VDP_TTX_FILTER_1_MASK5 (0xB5) | ||
190 | #define REG_VDP_TTX_FILTER_2_MASK1 (0xB6) | ||
191 | #define REG_VDP_TTX_FILTER_2_MASK2 (0xB7) | ||
192 | #define REG_VDP_TTX_FILTER_2_MASK3 (0xB8) | ||
193 | #define REG_VDP_TTX_FILTER_2_MASK4 (0xB9) | ||
194 | #define REG_VDP_TTX_FILTER_2_MASK5 (0xBA) | ||
195 | #define REG_VDP_TTX_FILTER_CONTROL (0xBB) | ||
196 | #define REG_VDP_FIFO_WORD_COUNT (0xBC) | ||
197 | #define REG_VDP_FIFO_INTERRUPT_THRLD (0xBD) | ||
198 | |||
199 | /* 0xBE Reserved */ | ||
200 | |||
201 | #define REG_VDP_FIFO_RESET (0xBF) | ||
202 | #define REG_VDP_FIFO_OUTPUT_CONTROL (0xC0) | ||
203 | #define REG_VDP_LINE_NUMBER_INTERRUPT (0xC1) | ||
204 | #define REG_VDP_PIXEL_ALIGNMENT_LSB (0xC2) | ||
205 | #define REG_VDP_PIXEL_ALIGNMENT_MSB (0xC3) | ||
206 | |||
207 | /* 0xC4 - 0xD5 Reserved */ | ||
208 | |||
209 | #define REG_VDP_LINE_START (0xD6) | ||
210 | #define REG_VDP_LINE_STOP (0xD7) | ||
211 | #define REG_VDP_GLOBAL_LINE_MODE (0xD8) | ||
212 | #define REG_VDP_FULL_FIELD_ENABLE (0xD9) | ||
213 | #define REG_VDP_FULL_FIELD_MODE (0xDA) | ||
214 | |||
215 | /* 0xDB - 0xDF Reserved */ | ||
216 | |||
217 | #define REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR (0xE0) | ||
218 | #define REG_VBUS_DATA_ACCESS_VBUS_ADDR_INCR (0xE1) | ||
219 | #define REG_FIFO_READ_DATA (0xE2) | ||
220 | |||
221 | /* 0xE3 - 0xE7 Reserved */ | ||
222 | |||
223 | #define REG_VBUS_ADDRESS_ACCESS1 (0xE8) | ||
224 | #define REG_VBUS_ADDRESS_ACCESS2 (0xE9) | ||
225 | #define REG_VBUS_ADDRESS_ACCESS3 (0xEA) | ||
226 | |||
227 | /* 0xEB - 0xEF Reserved */ | ||
228 | |||
229 | #define REG_INTERRUPT_RAW_STATUS0 (0xF0) | ||
230 | #define REG_INTERRUPT_RAW_STATUS1 (0xF1) | ||
231 | #define REG_INTERRUPT_STATUS0 (0xF2) | ||
232 | #define REG_INTERRUPT_STATUS1 (0xF3) | ||
233 | #define REG_INTERRUPT_MASK0 (0xF4) | ||
234 | #define REG_INTERRUPT_MASK1 (0xF5) | ||
235 | #define REG_INTERRUPT_CLEAR0 (0xF6) | ||
236 | #define REG_INTERRUPT_CLEAR1 (0xF7) | ||
237 | |||
238 | /* 0xF8 - 0xFF Reserved */ | ||
239 | |||
240 | /* | ||
241 | * Mask and bit definitions of TVP5146/47 registers | ||
242 | */ | ||
243 | /* The ID values we are looking for */ | ||
244 | #define TVP514X_CHIP_ID_MSB (0x51) | ||
245 | #define TVP5146_CHIP_ID_LSB (0x46) | ||
246 | #define TVP5147_CHIP_ID_LSB (0x47) | ||
247 | |||
248 | #define VIDEO_STD_MASK (0x07) | ||
249 | #define VIDEO_STD_AUTO_SWITCH_BIT (0x00) | ||
250 | #define VIDEO_STD_NTSC_MJ_BIT (0x01) | ||
251 | #define VIDEO_STD_PAL_BDGHIN_BIT (0x02) | ||
252 | #define VIDEO_STD_PAL_M_BIT (0x03) | ||
253 | #define VIDEO_STD_PAL_COMBINATION_N_BIT (0x04) | ||
254 | #define VIDEO_STD_NTSC_4_43_BIT (0x05) | ||
255 | #define VIDEO_STD_SECAM_BIT (0x06) | ||
256 | #define VIDEO_STD_PAL_60_BIT (0x07) | ||
257 | |||
258 | /* | ||
259 | * Status bit | ||
260 | */ | ||
261 | #define STATUS_TV_VCR_BIT (1<<0) | ||
262 | #define STATUS_HORZ_SYNC_LOCK_BIT (1<<1) | ||
263 | #define STATUS_VIRT_SYNC_LOCK_BIT (1<<2) | ||
264 | #define STATUS_CLR_SUBCAR_LOCK_BIT (1<<3) | ||
265 | #define STATUS_LOST_LOCK_DETECT_BIT (1<<4) | ||
266 | #define STATUS_FEILD_RATE_BIT (1<<5) | ||
267 | #define STATUS_LINE_ALTERNATING_BIT (1<<6) | ||
268 | #define STATUS_PEAK_WHITE_DETECT_BIT (1<<7) | ||
269 | |||
270 | /* Tokens for register write */ | ||
271 | #define TOK_WRITE (0) /* token for write operation */ | ||
272 | #define TOK_TERM (1) /* terminating token */ | ||
273 | #define TOK_DELAY (2) /* delay token for reg list */ | ||
274 | #define TOK_SKIP (3) /* token to skip a register */ | ||
275 | /** | ||
276 | * struct tvp514x_reg - Structure for TVP5146/47 register initialization values | ||
277 | * @token - Token: TOK_WRITE, TOK_TERM etc.. | ||
278 | * @reg - Register offset | ||
279 | * @val - Register Value for TOK_WRITE or delay in ms for TOK_DELAY | ||
280 | */ | ||
281 | struct tvp514x_reg { | ||
282 | u8 token; | ||
283 | u8 reg; | ||
284 | u32 val; | ||
285 | }; | ||
286 | |||
287 | /** | ||
288 | * struct tvp514x_init_seq - Structure for TVP5146/47/46M2/47M1 power up | ||
289 | * Sequence. | ||
290 | * @ no_regs - Number of registers to write for power up sequence. | ||
291 | * @ init_reg_seq - Array of registers and respective value to write. | ||
292 | */ | ||
293 | struct tvp514x_init_seq { | ||
294 | unsigned int no_regs; | ||
295 | const struct tvp514x_reg *init_reg_seq; | ||
296 | }; | ||
297 | #endif /* ifndef _TVP514X_REGS_H */ | ||
diff --git a/include/media/tvp514x.h b/include/media/tvp514x.h new file mode 100644 index 000000000000..5e7ee968c6dc --- /dev/null +++ b/include/media/tvp514x.h | |||
@@ -0,0 +1,118 @@ | |||
1 | /* | ||
2 | * drivers/media/video/tvp514x.h | ||
3 | * | ||
4 | * Copyright (C) 2008 Texas Instruments Inc | ||
5 | * Author: Vaibhav Hiremath <hvaibhav@ti.com> | ||
6 | * | ||
7 | * Contributors: | ||
8 | * Sivaraj R <sivaraj@ti.com> | ||
9 | * Brijesh R Jadav <brijesh.j@ti.com> | ||
10 | * Hardik Shah <hardik.shah@ti.com> | ||
11 | * Manjunath Hadli <mrh@ti.com> | ||
12 | * Karicheri Muralidharan <m-karicheri2@ti.com> | ||
13 | * | ||
14 | * This package is free software; you can redistribute it and/or modify | ||
15 | * it under the terms of the GNU General Public License version 2 as | ||
16 | * published by the Free Software Foundation. | ||
17 | * | ||
18 | * This program is distributed in the hope that it will be useful, | ||
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
21 | * GNU General Public License for more details. | ||
22 | * | ||
23 | * You should have received a copy of the GNU General Public License | ||
24 | * along with this program; if not, write to the Free Software | ||
25 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
26 | * | ||
27 | */ | ||
28 | |||
29 | #ifndef _TVP514X_H | ||
30 | #define _TVP514X_H | ||
31 | |||
32 | /* | ||
33 | * Other macros | ||
34 | */ | ||
35 | #define TVP514X_MODULE_NAME "tvp514x" | ||
36 | |||
37 | #define TVP514X_XCLK_BT656 (27000000) | ||
38 | |||
39 | /* Number of pixels and number of lines per frame for different standards */ | ||
40 | #define NTSC_NUM_ACTIVE_PIXELS (720) | ||
41 | #define NTSC_NUM_ACTIVE_LINES (480) | ||
42 | #define PAL_NUM_ACTIVE_PIXELS (720) | ||
43 | #define PAL_NUM_ACTIVE_LINES (576) | ||
44 | |||
45 | /** | ||
46 | * enum tvp514x_input - enum for different decoder input pin | ||
47 | * configuration. | ||
48 | */ | ||
49 | enum tvp514x_input { | ||
50 | /* | ||
51 | * CVBS input selection | ||
52 | */ | ||
53 | INPUT_CVBS_VI1A = 0x0, | ||
54 | INPUT_CVBS_VI1B, | ||
55 | INPUT_CVBS_VI1C, | ||
56 | INPUT_CVBS_VI2A = 0x04, | ||
57 | INPUT_CVBS_VI2B, | ||
58 | INPUT_CVBS_VI2C, | ||
59 | INPUT_CVBS_VI3A = 0x08, | ||
60 | INPUT_CVBS_VI3B, | ||
61 | INPUT_CVBS_VI3C, | ||
62 | INPUT_CVBS_VI4A = 0x0C, | ||
63 | /* | ||
64 | * S-Video input selection | ||
65 | */ | ||
66 | INPUT_SVIDEO_VI2A_VI1A = 0x44, | ||
67 | INPUT_SVIDEO_VI2B_VI1B, | ||
68 | INPUT_SVIDEO_VI2C_VI1C, | ||
69 | INPUT_SVIDEO_VI2A_VI3A = 0x54, | ||
70 | INPUT_SVIDEO_VI2B_VI3B, | ||
71 | INPUT_SVIDEO_VI2C_VI3C, | ||
72 | INPUT_SVIDEO_VI4A_VI1A = 0x4C, | ||
73 | INPUT_SVIDEO_VI4A_VI1B, | ||
74 | INPUT_SVIDEO_VI4A_VI1C, | ||
75 | INPUT_SVIDEO_VI4A_VI3A = 0x5C, | ||
76 | INPUT_SVIDEO_VI4A_VI3B, | ||
77 | INPUT_SVIDEO_VI4A_VI3C, | ||
78 | |||
79 | /* Need to add entries for | ||
80 | * RGB, YPbPr and SCART. | ||
81 | */ | ||
82 | INPUT_INVALID | ||
83 | }; | ||
84 | |||
85 | /** | ||
86 | * enum tvp514x_output - enum for output format | ||
87 | * supported. | ||
88 | * | ||
89 | */ | ||
90 | enum tvp514x_output { | ||
91 | OUTPUT_10BIT_422_EMBEDDED_SYNC = 0, | ||
92 | OUTPUT_20BIT_422_SEPERATE_SYNC, | ||
93 | OUTPUT_10BIT_422_SEPERATE_SYNC = 3, | ||
94 | OUTPUT_INVALID | ||
95 | }; | ||
96 | |||
97 | /** | ||
98 | * struct tvp514x_platform_data - Platform data values and access functions. | ||
99 | * @power_set: Power state access function, zero is off, non-zero is on. | ||
100 | * @ifparm: Interface parameters access function. | ||
101 | * @priv_data_set: Device private data (pointer) access function. | ||
102 | * @clk_polarity: Clock polarity of the current interface. | ||
103 | * @ hs_polarity: HSYNC Polarity configuration for current interface. | ||
104 | * @ vs_polarity: VSYNC Polarity configuration for current interface. | ||
105 | */ | ||
106 | struct tvp514x_platform_data { | ||
107 | char *master; | ||
108 | int (*power_set) (enum v4l2_power on); | ||
109 | int (*ifparm) (struct v4l2_ifparm *p); | ||
110 | int (*priv_data_set) (void *); | ||
111 | /* Interface control params */ | ||
112 | bool clk_polarity; | ||
113 | bool hs_polarity; | ||
114 | bool vs_polarity; | ||
115 | }; | ||
116 | |||
117 | |||
118 | #endif /* ifndef _TVP514X_H */ | ||