aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/media/video/Kconfig10
-rw-r--r--drivers/media/video/Makefile1
-rw-r--r--drivers/media/video/adv7183.c699
-rw-r--r--drivers/media/video/adv7183_regs.h107
-rw-r--r--include/media/adv7183.h47
-rw-r--r--include/media/v4l2-chip-ident.h3
6 files changed, 867 insertions, 0 deletions
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index 61580738de7a..cf0a1f656c64 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -273,6 +273,16 @@ config VIDEO_ADV7180
273 To compile this driver as a module, choose M here: the 273 To compile this driver as a module, choose M here: the
274 module will be called adv7180. 274 module will be called adv7180.
275 275
276config VIDEO_ADV7183
277 tristate "Analog Devices ADV7183 decoder"
278 depends on VIDEO_V4L2 && I2C
279 ---help---
280 V4l2 subdevice driver for the Analog Devices
281 ADV7183 video decoder.
282
283 To compile this driver as a module, choose M here: the
284 module will be called adv7183.
285
276config VIDEO_BT819 286config VIDEO_BT819
277 tristate "BT819A VideoStream decoder" 287 tristate "BT819A VideoStream decoder"
278 depends on VIDEO_V4L2 && I2C 288 depends on VIDEO_V4L2 && I2C
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
index d70dd0dc1f90..7ad4eebdc91b 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -39,6 +39,7 @@ obj-$(CONFIG_VIDEO_SAA7191) += saa7191.o
39obj-$(CONFIG_VIDEO_ADV7170) += adv7170.o 39obj-$(CONFIG_VIDEO_ADV7170) += adv7170.o
40obj-$(CONFIG_VIDEO_ADV7175) += adv7175.o 40obj-$(CONFIG_VIDEO_ADV7175) += adv7175.o
41obj-$(CONFIG_VIDEO_ADV7180) += adv7180.o 41obj-$(CONFIG_VIDEO_ADV7180) += adv7180.o
42obj-$(CONFIG_VIDEO_ADV7183) += adv7183.o
42obj-$(CONFIG_VIDEO_ADV7343) += adv7343.o 43obj-$(CONFIG_VIDEO_ADV7343) += adv7343.o
43obj-$(CONFIG_VIDEO_VPX3220) += vpx3220.o 44obj-$(CONFIG_VIDEO_VPX3220) += vpx3220.o
44obj-$(CONFIG_VIDEO_BT819) += bt819.o 45obj-$(CONFIG_VIDEO_BT819) += bt819.o
diff --git a/drivers/media/video/adv7183.c b/drivers/media/video/adv7183.c
new file mode 100644
index 000000000000..e1d4c89d7140
--- /dev/null
+++ b/drivers/media/video/adv7183.c
@@ -0,0 +1,699 @@
1/*
2 * adv7183.c Analog Devices ADV7183 video decoder driver
3 *
4 * Copyright (c) 2011 Analog Devices Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20#include <linux/delay.h>
21#include <linux/errno.h>
22#include <linux/gpio.h>
23#include <linux/i2c.h>
24#include <linux/init.h>
25#include <linux/module.h>
26#include <linux/slab.h>
27#include <linux/types.h>
28#include <linux/videodev2.h>
29
30#include <media/adv7183.h>
31#include <media/v4l2-chip-ident.h>
32#include <media/v4l2-ctrls.h>
33#include <media/v4l2-device.h>
34
35#include "adv7183_regs.h"
36
37struct adv7183 {
38 struct v4l2_subdev sd;
39 struct v4l2_ctrl_handler hdl;
40
41 v4l2_std_id std; /* Current set standard */
42 u32 input;
43 u32 output;
44 unsigned reset_pin;
45 unsigned oe_pin;
46 struct v4l2_mbus_framefmt fmt;
47};
48
49/* EXAMPLES USING 27 MHz CLOCK
50 * Mode 1 CVBS Input (Composite Video on AIN5)
51 * All standards are supported through autodetect, 8-bit, 4:2:2, ITU-R BT.656 output on P15 to P8.
52 */
53static const unsigned char adv7183_init_regs[] = {
54 ADV7183_IN_CTRL, 0x04, /* CVBS input on AIN5 */
55 ADV7183_DIGI_CLAMP_CTRL_1, 0x00, /* Slow down digital clamps */
56 ADV7183_SHAP_FILT_CTRL, 0x41, /* Set CSFM to SH1 */
57 ADV7183_ADC_CTRL, 0x16, /* Power down ADC 1 and ADC 2 */
58 ADV7183_CTI_DNR_CTRL_4, 0x04, /* Set DNR threshold to 4 for flat response */
59 /* ADI recommended programming sequence */
60 ADV7183_ADI_CTRL, 0x80,
61 ADV7183_CTI_DNR_CTRL_4, 0x20,
62 0x52, 0x18,
63 0x58, 0xED,
64 0x77, 0xC5,
65 0x7C, 0x93,
66 0x7D, 0x00,
67 0xD0, 0x48,
68 0xD5, 0xA0,
69 0xD7, 0xEA,
70 ADV7183_SD_SATURATION_CR, 0x3E,
71 ADV7183_PAL_V_END, 0x3E,
72 ADV7183_PAL_F_TOGGLE, 0x0F,
73 ADV7183_ADI_CTRL, 0x00,
74};
75
76static inline struct adv7183 *to_adv7183(struct v4l2_subdev *sd)
77{
78 return container_of(sd, struct adv7183, sd);
79}
80static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl)
81{
82 return &container_of(ctrl->handler, struct adv7183, hdl)->sd;
83}
84
85static inline int adv7183_read(struct v4l2_subdev *sd, unsigned char reg)
86{
87 struct i2c_client *client = v4l2_get_subdevdata(sd);
88
89 return i2c_smbus_read_byte_data(client, reg);
90}
91
92static inline int adv7183_write(struct v4l2_subdev *sd, unsigned char reg,
93 unsigned char value)
94{
95 struct i2c_client *client = v4l2_get_subdevdata(sd);
96
97 return i2c_smbus_write_byte_data(client, reg, value);
98}
99
100static int adv7183_writeregs(struct v4l2_subdev *sd,
101 const unsigned char *regs, unsigned int num)
102{
103 unsigned char reg, data;
104 unsigned int cnt = 0;
105
106 if (num & 0x1) {
107 v4l2_err(sd, "invalid regs array\n");
108 return -1;
109 }
110
111 while (cnt < num) {
112 reg = *regs++;
113 data = *regs++;
114 cnt += 2;
115
116 adv7183_write(sd, reg, data);
117 }
118 return 0;
119}
120
121static int adv7183_log_status(struct v4l2_subdev *sd)
122{
123 struct adv7183 *decoder = to_adv7183(sd);
124
125 v4l2_info(sd, "adv7183: Input control = 0x%02x\n",
126 adv7183_read(sd, ADV7183_IN_CTRL));
127 v4l2_info(sd, "adv7183: Video selection = 0x%02x\n",
128 adv7183_read(sd, ADV7183_VD_SEL));
129 v4l2_info(sd, "adv7183: Output control = 0x%02x\n",
130 adv7183_read(sd, ADV7183_OUT_CTRL));
131 v4l2_info(sd, "adv7183: Extended output control = 0x%02x\n",
132 adv7183_read(sd, ADV7183_EXT_OUT_CTRL));
133 v4l2_info(sd, "adv7183: Autodetect enable = 0x%02x\n",
134 adv7183_read(sd, ADV7183_AUTO_DET_EN));
135 v4l2_info(sd, "adv7183: Contrast = 0x%02x\n",
136 adv7183_read(sd, ADV7183_CONTRAST));
137 v4l2_info(sd, "adv7183: Brightness = 0x%02x\n",
138 adv7183_read(sd, ADV7183_BRIGHTNESS));
139 v4l2_info(sd, "adv7183: Hue = 0x%02x\n",
140 adv7183_read(sd, ADV7183_HUE));
141 v4l2_info(sd, "adv7183: Default value Y = 0x%02x\n",
142 adv7183_read(sd, ADV7183_DEF_Y));
143 v4l2_info(sd, "adv7183: Default value C = 0x%02x\n",
144 adv7183_read(sd, ADV7183_DEF_C));
145 v4l2_info(sd, "adv7183: ADI control = 0x%02x\n",
146 adv7183_read(sd, ADV7183_ADI_CTRL));
147 v4l2_info(sd, "adv7183: Power Management = 0x%02x\n",
148 adv7183_read(sd, ADV7183_POW_MANAGE));
149 v4l2_info(sd, "adv7183: Status 1 2 and 3 = 0x%02x 0x%02x 0x%02x\n",
150 adv7183_read(sd, ADV7183_STATUS_1),
151 adv7183_read(sd, ADV7183_STATUS_2),
152 adv7183_read(sd, ADV7183_STATUS_3));
153 v4l2_info(sd, "adv7183: Ident = 0x%02x\n",
154 adv7183_read(sd, ADV7183_IDENT));
155 v4l2_info(sd, "adv7183: Analog clamp control = 0x%02x\n",
156 adv7183_read(sd, ADV7183_ANAL_CLAMP_CTRL));
157 v4l2_info(sd, "adv7183: Digital clamp control 1 = 0x%02x\n",
158 adv7183_read(sd, ADV7183_DIGI_CLAMP_CTRL_1));
159 v4l2_info(sd, "adv7183: Shaping filter control 1 and 2 = 0x%02x 0x%02x\n",
160 adv7183_read(sd, ADV7183_SHAP_FILT_CTRL),
161 adv7183_read(sd, ADV7183_SHAP_FILT_CTRL_2));
162 v4l2_info(sd, "adv7183: Comb filter control = 0x%02x\n",
163 adv7183_read(sd, ADV7183_COMB_FILT_CTRL));
164 v4l2_info(sd, "adv7183: ADI control 2 = 0x%02x\n",
165 adv7183_read(sd, ADV7183_ADI_CTRL_2));
166 v4l2_info(sd, "adv7183: Pixel delay control = 0x%02x\n",
167 adv7183_read(sd, ADV7183_PIX_DELAY_CTRL));
168 v4l2_info(sd, "adv7183: Misc gain control = 0x%02x\n",
169 adv7183_read(sd, ADV7183_MISC_GAIN_CTRL));
170 v4l2_info(sd, "adv7183: AGC mode control = 0x%02x\n",
171 adv7183_read(sd, ADV7183_AGC_MODE_CTRL));
172 v4l2_info(sd, "adv7183: Chroma gain control 1 and 2 = 0x%02x 0x%02x\n",
173 adv7183_read(sd, ADV7183_CHRO_GAIN_CTRL_1),
174 adv7183_read(sd, ADV7183_CHRO_GAIN_CTRL_2));
175 v4l2_info(sd, "adv7183: Luma gain control 1 and 2 = 0x%02x 0x%02x\n",
176 adv7183_read(sd, ADV7183_LUMA_GAIN_CTRL_1),
177 adv7183_read(sd, ADV7183_LUMA_GAIN_CTRL_2));
178 v4l2_info(sd, "adv7183: Vsync field control 1 2 and 3 = 0x%02x 0x%02x 0x%02x\n",
179 adv7183_read(sd, ADV7183_VS_FIELD_CTRL_1),
180 adv7183_read(sd, ADV7183_VS_FIELD_CTRL_2),
181 adv7183_read(sd, ADV7183_VS_FIELD_CTRL_3));
182 v4l2_info(sd, "adv7183: Hsync positon control 1 2 and 3 = 0x%02x 0x%02x 0x%02x\n",
183 adv7183_read(sd, ADV7183_HS_POS_CTRL_1),
184 adv7183_read(sd, ADV7183_HS_POS_CTRL_2),
185 adv7183_read(sd, ADV7183_HS_POS_CTRL_3));
186 v4l2_info(sd, "adv7183: Polarity = 0x%02x\n",
187 adv7183_read(sd, ADV7183_POLARITY));
188 v4l2_info(sd, "adv7183: ADC control = 0x%02x\n",
189 adv7183_read(sd, ADV7183_ADC_CTRL));
190 v4l2_info(sd, "adv7183: SD offset Cb and Cr = 0x%02x 0x%02x\n",
191 adv7183_read(sd, ADV7183_SD_OFFSET_CB),
192 adv7183_read(sd, ADV7183_SD_OFFSET_CR));
193 v4l2_info(sd, "adv7183: SD saturation Cb and Cr = 0x%02x 0x%02x\n",
194 adv7183_read(sd, ADV7183_SD_SATURATION_CB),
195 adv7183_read(sd, ADV7183_SD_SATURATION_CR));
196 v4l2_info(sd, "adv7183: Drive strength = 0x%02x\n",
197 adv7183_read(sd, ADV7183_DRIVE_STR));
198 v4l2_ctrl_handler_log_status(&decoder->hdl, sd->name);
199 return 0;
200}
201
202static int adv7183_g_std(struct v4l2_subdev *sd, v4l2_std_id *std)
203{
204 struct adv7183 *decoder = to_adv7183(sd);
205
206 *std = decoder->std;
207 return 0;
208}
209
210static int adv7183_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
211{
212 struct adv7183 *decoder = to_adv7183(sd);
213 int reg;
214
215 reg = adv7183_read(sd, ADV7183_IN_CTRL) & 0xF;
216 if (std == V4L2_STD_PAL_60)
217 reg |= 0x60;
218 else if (std == V4L2_STD_NTSC_443)
219 reg |= 0x70;
220 else if (std == V4L2_STD_PAL_N)
221 reg |= 0x90;
222 else if (std == V4L2_STD_PAL_M)
223 reg |= 0xA0;
224 else if (std == V4L2_STD_PAL_Nc)
225 reg |= 0xC0;
226 else if (std & V4L2_STD_PAL)
227 reg |= 0x80;
228 else if (std & V4L2_STD_NTSC)
229 reg |= 0x50;
230 else if (std & V4L2_STD_SECAM)
231 reg |= 0xE0;
232 else
233 return -EINVAL;
234 adv7183_write(sd, ADV7183_IN_CTRL, reg);
235
236 decoder->std = std;
237
238 return 0;
239}
240
241static int adv7183_reset(struct v4l2_subdev *sd, u32 val)
242{
243 int reg;
244
245 reg = adv7183_read(sd, ADV7183_POW_MANAGE) | 0x80;
246 adv7183_write(sd, ADV7183_POW_MANAGE, reg);
247 /* wait 5ms before any further i2c writes are performed */
248 usleep_range(5000, 10000);
249 return 0;
250}
251
252static int adv7183_s_routing(struct v4l2_subdev *sd,
253 u32 input, u32 output, u32 config)
254{
255 struct adv7183 *decoder = to_adv7183(sd);
256 int reg;
257
258 if ((input > ADV7183_COMPONENT1) || (output > ADV7183_16BIT_OUT))
259 return -EINVAL;
260
261 if (input != decoder->input) {
262 decoder->input = input;
263 reg = adv7183_read(sd, ADV7183_IN_CTRL) & 0xF0;
264 switch (input) {
265 case ADV7183_COMPOSITE1:
266 reg |= 0x1;
267 break;
268 case ADV7183_COMPOSITE2:
269 reg |= 0x2;
270 break;
271 case ADV7183_COMPOSITE3:
272 reg |= 0x3;
273 break;
274 case ADV7183_COMPOSITE4:
275 reg |= 0x4;
276 break;
277 case ADV7183_COMPOSITE5:
278 reg |= 0x5;
279 break;
280 case ADV7183_COMPOSITE6:
281 reg |= 0xB;
282 break;
283 case ADV7183_COMPOSITE7:
284 reg |= 0xC;
285 break;
286 case ADV7183_COMPOSITE8:
287 reg |= 0xD;
288 break;
289 case ADV7183_COMPOSITE9:
290 reg |= 0xE;
291 break;
292 case ADV7183_COMPOSITE10:
293 reg |= 0xF;
294 break;
295 case ADV7183_SVIDEO0:
296 reg |= 0x6;
297 break;
298 case ADV7183_SVIDEO1:
299 reg |= 0x7;
300 break;
301 case ADV7183_SVIDEO2:
302 reg |= 0x8;
303 break;
304 case ADV7183_COMPONENT0:
305 reg |= 0x9;
306 break;
307 case ADV7183_COMPONENT1:
308 reg |= 0xA;
309 break;
310 default:
311 break;
312 }
313 adv7183_write(sd, ADV7183_IN_CTRL, reg);
314 }
315
316 if (output != decoder->output) {
317 decoder->output = output;
318 reg = adv7183_read(sd, ADV7183_OUT_CTRL) & 0xC0;
319 switch (output) {
320 case ADV7183_16BIT_OUT:
321 reg |= 0x9;
322 break;
323 default:
324 reg |= 0xC;
325 break;
326 }
327 adv7183_write(sd, ADV7183_OUT_CTRL, reg);
328 }
329
330 return 0;
331}
332
333static int adv7183_s_ctrl(struct v4l2_ctrl *ctrl)
334{
335 struct v4l2_subdev *sd = to_sd(ctrl);
336 int val = ctrl->val;
337
338 switch (ctrl->id) {
339 case V4L2_CID_BRIGHTNESS:
340 if (val < 0)
341 val = 127 - val;
342 adv7183_write(sd, ADV7183_BRIGHTNESS, val);
343 break;
344 case V4L2_CID_CONTRAST:
345 adv7183_write(sd, ADV7183_CONTRAST, val);
346 break;
347 case V4L2_CID_SATURATION:
348 adv7183_write(sd, ADV7183_SD_SATURATION_CB, val >> 8);
349 adv7183_write(sd, ADV7183_SD_SATURATION_CR, (val & 0xFF));
350 break;
351 case V4L2_CID_HUE:
352 adv7183_write(sd, ADV7183_SD_OFFSET_CB, val >> 8);
353 adv7183_write(sd, ADV7183_SD_OFFSET_CR, (val & 0xFF));
354 break;
355 default:
356 return -EINVAL;
357 }
358
359 return 0;
360}
361
362static int adv7183_querystd(struct v4l2_subdev *sd, v4l2_std_id *std)
363{
364 struct adv7183 *decoder = to_adv7183(sd);
365 int reg;
366
367 /* enable autodetection block */
368 reg = adv7183_read(sd, ADV7183_IN_CTRL) & 0xF;
369 adv7183_write(sd, ADV7183_IN_CTRL, reg);
370
371 /* wait autodetection switch */
372 mdelay(10);
373
374 /* get autodetection result */
375 reg = adv7183_read(sd, ADV7183_STATUS_1);
376 switch ((reg >> 0x4) & 0x7) {
377 case 0:
378 *std = V4L2_STD_NTSC;
379 break;
380 case 1:
381 *std = V4L2_STD_NTSC_443;
382 break;
383 case 2:
384 *std = V4L2_STD_PAL_M;
385 break;
386 case 3:
387 *std = V4L2_STD_PAL_60;
388 break;
389 case 4:
390 *std = V4L2_STD_PAL;
391 break;
392 case 5:
393 *std = V4L2_STD_SECAM;
394 break;
395 case 6:
396 *std = V4L2_STD_PAL_Nc;
397 break;
398 case 7:
399 *std = V4L2_STD_SECAM;
400 break;
401 default:
402 *std = V4L2_STD_UNKNOWN;
403 break;
404 }
405
406 /* after std detection, write back user set std */
407 adv7183_s_std(sd, decoder->std);
408 return 0;
409}
410
411static int adv7183_g_input_status(struct v4l2_subdev *sd, u32 *status)
412{
413 int reg;
414
415 *status = V4L2_IN_ST_NO_SIGNAL;
416 reg = adv7183_read(sd, ADV7183_STATUS_1);
417 if (reg < 0)
418 return reg;
419 if (reg & 0x1)
420 *status = 0;
421 return 0;
422}
423
424static int adv7183_enum_mbus_fmt(struct v4l2_subdev *sd, unsigned index,
425 enum v4l2_mbus_pixelcode *code)
426{
427 if (index > 0)
428 return -EINVAL;
429
430 *code = V4L2_MBUS_FMT_UYVY8_2X8;
431 return 0;
432}
433
434static int adv7183_try_mbus_fmt(struct v4l2_subdev *sd,
435 struct v4l2_mbus_framefmt *fmt)
436{
437 struct adv7183 *decoder = to_adv7183(sd);
438
439 fmt->code = V4L2_MBUS_FMT_UYVY8_2X8;
440 fmt->colorspace = V4L2_COLORSPACE_SMPTE170M;
441 if (decoder->std & V4L2_STD_525_60) {
442 fmt->field = V4L2_FIELD_SEQ_TB;
443 fmt->width = 720;
444 fmt->height = 480;
445 } else {
446 fmt->field = V4L2_FIELD_SEQ_BT;
447 fmt->width = 720;
448 fmt->height = 576;
449 }
450 return 0;
451}
452
453static int adv7183_s_mbus_fmt(struct v4l2_subdev *sd,
454 struct v4l2_mbus_framefmt *fmt)
455{
456 struct adv7183 *decoder = to_adv7183(sd);
457
458 adv7183_try_mbus_fmt(sd, fmt);
459 decoder->fmt = *fmt;
460 return 0;
461}
462
463static int adv7183_g_mbus_fmt(struct v4l2_subdev *sd,
464 struct v4l2_mbus_framefmt *fmt)
465{
466 struct adv7183 *decoder = to_adv7183(sd);
467
468 *fmt = decoder->fmt;
469 return 0;
470}
471
472static int adv7183_s_stream(struct v4l2_subdev *sd, int enable)
473{
474 struct adv7183 *decoder = to_adv7183(sd);
475
476 if (enable)
477 gpio_direction_output(decoder->oe_pin, 0);
478 else
479 gpio_direction_output(decoder->oe_pin, 1);
480 udelay(1);
481 return 0;
482}
483
484static int adv7183_g_chip_ident(struct v4l2_subdev *sd,
485 struct v4l2_dbg_chip_ident *chip)
486{
487 int rev;
488 struct i2c_client *client = v4l2_get_subdevdata(sd);
489
490 /* 0x11 for adv7183, 0x13 for adv7183b */
491 rev = adv7183_read(sd, ADV7183_IDENT);
492
493 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_ADV7183, rev);
494}
495
496#ifdef CONFIG_VIDEO_ADV_DEBUG
497static int adv7183_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
498{
499 struct i2c_client *client = v4l2_get_subdevdata(sd);
500
501 if (!v4l2_chip_match_i2c_client(client, &reg->match))
502 return -EINVAL;
503 if (!capable(CAP_SYS_ADMIN))
504 return -EPERM;
505 reg->val = adv7183_read(sd, reg->reg & 0xff);
506 reg->size = 1;
507 return 0;
508}
509
510static int adv7183_s_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
511{
512 struct i2c_client *client = v4l2_get_subdevdata(sd);
513
514 if (!v4l2_chip_match_i2c_client(client, &reg->match))
515 return -EINVAL;
516 if (!capable(CAP_SYS_ADMIN))
517 return -EPERM;
518 adv7183_write(sd, reg->reg & 0xff, reg->val & 0xff);
519 return 0;
520}
521#endif
522
523static const struct v4l2_ctrl_ops adv7183_ctrl_ops = {
524 .s_ctrl = adv7183_s_ctrl,
525};
526
527static const struct v4l2_subdev_core_ops adv7183_core_ops = {
528 .log_status = adv7183_log_status,
529 .g_std = adv7183_g_std,
530 .s_std = adv7183_s_std,
531 .reset = adv7183_reset,
532 .g_chip_ident = adv7183_g_chip_ident,
533#ifdef CONFIG_VIDEO_ADV_DEBUG
534 .g_register = adv7183_g_register,
535 .s_register = adv7183_s_register,
536#endif
537};
538
539static const struct v4l2_subdev_video_ops adv7183_video_ops = {
540 .s_routing = adv7183_s_routing,
541 .querystd = adv7183_querystd,
542 .g_input_status = adv7183_g_input_status,
543 .enum_mbus_fmt = adv7183_enum_mbus_fmt,
544 .try_mbus_fmt = adv7183_try_mbus_fmt,
545 .s_mbus_fmt = adv7183_s_mbus_fmt,
546 .g_mbus_fmt = adv7183_g_mbus_fmt,
547 .s_stream = adv7183_s_stream,
548};
549
550static const struct v4l2_subdev_ops adv7183_ops = {
551 .core = &adv7183_core_ops,
552 .video = &adv7183_video_ops,
553};
554
555static int adv7183_probe(struct i2c_client *client,
556 const struct i2c_device_id *id)
557{
558 struct adv7183 *decoder;
559 struct v4l2_subdev *sd;
560 struct v4l2_ctrl_handler *hdl;
561 int ret;
562 struct v4l2_mbus_framefmt fmt;
563 const unsigned *pin_array;
564
565 /* Check if the adapter supports the needed features */
566 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
567 return -EIO;
568
569 v4l_info(client, "chip found @ 0x%02x (%s)\n",
570 client->addr << 1, client->adapter->name);
571
572 pin_array = client->dev.platform_data;
573 if (pin_array == NULL)
574 return -EINVAL;
575
576 decoder = kzalloc(sizeof(struct adv7183), GFP_KERNEL);
577 if (decoder == NULL)
578 return -ENOMEM;
579
580 decoder->reset_pin = pin_array[0];
581 decoder->oe_pin = pin_array[1];
582
583 if (gpio_request(decoder->reset_pin, "ADV7183 Reset")) {
584 v4l_err(client, "failed to request GPIO %d\n", decoder->reset_pin);
585 ret = -EBUSY;
586 goto err_free_decoder;
587 }
588
589 if (gpio_request(decoder->oe_pin, "ADV7183 Output Enable")) {
590 v4l_err(client, "failed to request GPIO %d\n", decoder->oe_pin);
591 ret = -EBUSY;
592 goto err_free_reset;
593 }
594
595 sd = &decoder->sd;
596 v4l2_i2c_subdev_init(sd, client, &adv7183_ops);
597
598 hdl = &decoder->hdl;
599 v4l2_ctrl_handler_init(hdl, 4);
600 v4l2_ctrl_new_std(hdl, &adv7183_ctrl_ops,
601 V4L2_CID_BRIGHTNESS, -128, 127, 1, 0);
602 v4l2_ctrl_new_std(hdl, &adv7183_ctrl_ops,
603 V4L2_CID_CONTRAST, 0, 0xFF, 1, 0x80);
604 v4l2_ctrl_new_std(hdl, &adv7183_ctrl_ops,
605 V4L2_CID_SATURATION, 0, 0xFFFF, 1, 0x8080);
606 v4l2_ctrl_new_std(hdl, &adv7183_ctrl_ops,
607 V4L2_CID_HUE, 0, 0xFFFF, 1, 0x8080);
608 /* hook the control handler into the driver */
609 sd->ctrl_handler = hdl;
610 if (hdl->error) {
611 ret = hdl->error;
612
613 v4l2_ctrl_handler_free(hdl);
614 goto err_free_oe;
615 }
616
617 /* v4l2 doesn't support an autodetect standard, pick PAL as default */
618 decoder->std = V4L2_STD_PAL;
619 decoder->input = ADV7183_COMPOSITE4;
620 decoder->output = ADV7183_8BIT_OUT;
621
622 gpio_direction_output(decoder->oe_pin, 1);
623 /* reset chip */
624 gpio_direction_output(decoder->reset_pin, 0);
625 /* reset pulse width at least 5ms */
626 mdelay(10);
627 gpio_direction_output(decoder->reset_pin, 1);
628 /* wait 5ms before any further i2c writes are performed */
629 mdelay(5);
630
631 adv7183_writeregs(sd, adv7183_init_regs, ARRAY_SIZE(adv7183_init_regs));
632 adv7183_s_std(sd, decoder->std);
633 fmt.width = 720;
634 fmt.height = 576;
635 adv7183_s_mbus_fmt(sd, &fmt);
636
637 /* initialize the hardware to the default control values */
638 ret = v4l2_ctrl_handler_setup(hdl);
639 if (ret) {
640 v4l2_ctrl_handler_free(hdl);
641 goto err_free_oe;
642 }
643
644 return 0;
645err_free_oe:
646 gpio_free(decoder->oe_pin);
647err_free_reset:
648 gpio_free(decoder->reset_pin);
649err_free_decoder:
650 kfree(decoder);
651 return ret;
652}
653
654static int adv7183_remove(struct i2c_client *client)
655{
656 struct v4l2_subdev *sd = i2c_get_clientdata(client);
657 struct adv7183 *decoder = to_adv7183(sd);
658
659 v4l2_device_unregister_subdev(sd);
660 v4l2_ctrl_handler_free(sd->ctrl_handler);
661 gpio_free(decoder->oe_pin);
662 gpio_free(decoder->reset_pin);
663 kfree(decoder);
664 return 0;
665}
666
667static const struct i2c_device_id adv7183_id[] = {
668 {"adv7183", 0},
669 {},
670};
671
672MODULE_DEVICE_TABLE(i2c, adv7183_id);
673
674static struct i2c_driver adv7183_driver = {
675 .driver = {
676 .owner = THIS_MODULE,
677 .name = "adv7183",
678 },
679 .probe = adv7183_probe,
680 .remove = __devexit_p(adv7183_remove),
681 .id_table = adv7183_id,
682};
683
684static __init int adv7183_init(void)
685{
686 return i2c_add_driver(&adv7183_driver);
687}
688
689static __exit void adv7183_exit(void)
690{
691 i2c_del_driver(&adv7183_driver);
692}
693
694module_init(adv7183_init);
695module_exit(adv7183_exit);
696
697MODULE_DESCRIPTION("Analog Devices ADV7183 video decoder driver");
698MODULE_AUTHOR("Scott Jiang <Scott.Jiang.Linux@gmail.com>");
699MODULE_LICENSE("GPL v2");
diff --git a/drivers/media/video/adv7183_regs.h b/drivers/media/video/adv7183_regs.h
new file mode 100644
index 000000000000..4a5b7d211d2f
--- /dev/null
+++ b/drivers/media/video/adv7183_regs.h
@@ -0,0 +1,107 @@
1/*
2 * adv7183 - Analog Devices ADV7183 video decoder registers
3 *
4 * Copyright (c) 2011 Analog Devices Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20#ifndef _ADV7183_REGS_H_
21#define _ADV7183_REGS_H_
22
23#define ADV7183_IN_CTRL 0x00 /* Input control */
24#define ADV7183_VD_SEL 0x01 /* Video selection */
25#define ADV7183_OUT_CTRL 0x03 /* Output control */
26#define ADV7183_EXT_OUT_CTRL 0x04 /* Extended output control */
27#define ADV7183_AUTO_DET_EN 0x07 /* Autodetect enable */
28#define ADV7183_CONTRAST 0x08 /* Contrast */
29#define ADV7183_BRIGHTNESS 0x0A /* Brightness */
30#define ADV7183_HUE 0x0B /* Hue */
31#define ADV7183_DEF_Y 0x0C /* Default value Y */
32#define ADV7183_DEF_C 0x0D /* Default value C */
33#define ADV7183_ADI_CTRL 0x0E /* ADI control */
34#define ADV7183_POW_MANAGE 0x0F /* Power Management */
35#define ADV7183_STATUS_1 0x10 /* Status 1 */
36#define ADV7183_IDENT 0x11 /* Ident */
37#define ADV7183_STATUS_2 0x12 /* Status 2 */
38#define ADV7183_STATUS_3 0x13 /* Status 3 */
39#define ADV7183_ANAL_CLAMP_CTRL 0x14 /* Analog clamp control */
40#define ADV7183_DIGI_CLAMP_CTRL_1 0x15 /* Digital clamp control 1 */
41#define ADV7183_SHAP_FILT_CTRL 0x17 /* Shaping filter control */
42#define ADV7183_SHAP_FILT_CTRL_2 0x18 /* Shaping filter control 2 */
43#define ADV7183_COMB_FILT_CTRL 0x19 /* Comb filter control */
44#define ADV7183_ADI_CTRL_2 0x1D /* ADI control 2 */
45#define ADV7183_PIX_DELAY_CTRL 0x27 /* Pixel delay control */
46#define ADV7183_MISC_GAIN_CTRL 0x2B /* Misc gain control */
47#define ADV7183_AGC_MODE_CTRL 0x2C /* AGC mode control */
48#define ADV7183_CHRO_GAIN_CTRL_1 0x2D /* Chroma gain control 1 */
49#define ADV7183_CHRO_GAIN_CTRL_2 0x2E /* Chroma gain control 2 */
50#define ADV7183_LUMA_GAIN_CTRL_1 0x2F /* Luma gain control 1 */
51#define ADV7183_LUMA_GAIN_CTRL_2 0x30 /* Luma gain control 2 */
52#define ADV7183_VS_FIELD_CTRL_1 0x31 /* Vsync field control 1 */
53#define ADV7183_VS_FIELD_CTRL_2 0x32 /* Vsync field control 2 */
54#define ADV7183_VS_FIELD_CTRL_3 0x33 /* Vsync field control 3 */
55#define ADV7183_HS_POS_CTRL_1 0x34 /* Hsync positon control 1 */
56#define ADV7183_HS_POS_CTRL_2 0x35 /* Hsync positon control 2 */
57#define ADV7183_HS_POS_CTRL_3 0x36 /* Hsync positon control 3 */
58#define ADV7183_POLARITY 0x37 /* Polarity */
59#define ADV7183_NTSC_COMB_CTRL 0x38 /* NTSC comb control */
60#define ADV7183_PAL_COMB_CTRL 0x39 /* PAL comb control */
61#define ADV7183_ADC_CTRL 0x3A /* ADC control */
62#define ADV7183_MAN_WIN_CTRL 0x3D /* Manual window control */
63#define ADV7183_RESAMPLE_CTRL 0x41 /* Resample control */
64#define ADV7183_GEMSTAR_CTRL_1 0x48 /* Gemstar ctrl 1 */
65#define ADV7183_GEMSTAR_CTRL_2 0x49 /* Gemstar ctrl 2 */
66#define ADV7183_GEMSTAR_CTRL_3 0x4A /* Gemstar ctrl 3 */
67#define ADV7183_GEMSTAR_CTRL_4 0x4B /* Gemstar ctrl 4 */
68#define ADV7183_GEMSTAR_CTRL_5 0x4C /* Gemstar ctrl 5 */
69#define ADV7183_CTI_DNR_CTRL_1 0x4D /* CTI DNR ctrl 1 */
70#define ADV7183_CTI_DNR_CTRL_2 0x4E /* CTI DNR ctrl 2 */
71#define ADV7183_CTI_DNR_CTRL_4 0x50 /* CTI DNR ctrl 4 */
72#define ADV7183_LOCK_CNT 0x51 /* Lock count */
73#define ADV7183_FREE_LINE_LEN 0x8F /* Free-Run line length 1 */
74#define ADV7183_VBI_INFO 0x90 /* VBI info */
75#define ADV7183_WSS_1 0x91 /* WSS 1 */
76#define ADV7183_WSS_2 0x92 /* WSS 2 */
77#define ADV7183_EDTV_1 0x93 /* EDTV 1 */
78#define ADV7183_EDTV_2 0x94 /* EDTV 2 */
79#define ADV7183_EDTV_3 0x95 /* EDTV 3 */
80#define ADV7183_CGMS_1 0x96 /* CGMS 1 */
81#define ADV7183_CGMS_2 0x97 /* CGMS 2 */
82#define ADV7183_CGMS_3 0x98 /* CGMS 3 */
83#define ADV7183_CCAP_1 0x99 /* CCAP 1 */
84#define ADV7183_CCAP_2 0x9A /* CCAP 2 */
85#define ADV7183_LETTERBOX_1 0x9B /* Letterbox 1 */
86#define ADV7183_LETTERBOX_2 0x9C /* Letterbox 2 */
87#define ADV7183_LETTERBOX_3 0x9D /* Letterbox 3 */
88#define ADV7183_CRC_EN 0xB2 /* CRC enable */
89#define ADV7183_ADC_SWITCH_1 0xC3 /* ADC switch 1 */
90#define ADV7183_ADC_SWITCH_2 0xC4 /* ADC swithc 2 */
91#define ADV7183_LETTERBOX_CTRL_1 0xDC /* Letterbox control 1 */
92#define ADV7183_LETTERBOX_CTRL_2 0xDD /* Letterbox control 2 */
93#define ADV7183_SD_OFFSET_CB 0xE1 /* SD offset Cb */
94#define ADV7183_SD_OFFSET_CR 0xE2 /* SD offset Cr */
95#define ADV7183_SD_SATURATION_CB 0xE3 /* SD saturation Cb */
96#define ADV7183_SD_SATURATION_CR 0xE4 /* SD saturation Cr */
97#define ADV7183_NTSC_V_BEGIN 0xE5 /* NTSC V bit begin */
98#define ADV7183_NTSC_V_END 0xE6 /* NTSC V bit end */
99#define ADV7183_NTSC_F_TOGGLE 0xE7 /* NTSC F bit toggle */
100#define ADV7183_PAL_V_BEGIN 0xE8 /* PAL V bit begin */
101#define ADV7183_PAL_V_END 0xE9 /* PAL V bit end */
102#define ADV7183_PAL_F_TOGGLE 0xEA /* PAL F bit toggle */
103#define ADV7183_DRIVE_STR 0xF4 /* Drive strength */
104#define ADV7183_IF_COMP_CTRL 0xF8 /* IF comp control */
105#define ADV7183_VS_MODE_CTRL 0xF9 /* VS mode control */
106
107#endif
diff --git a/include/media/adv7183.h b/include/media/adv7183.h
new file mode 100644
index 000000000000..c5c2d377c0a6
--- /dev/null
+++ b/include/media/adv7183.h
@@ -0,0 +1,47 @@
1/*
2 * adv7183.h - definition for adv7183 inputs and outputs
3 *
4 * Copyright (c) 2011 Analog Devices Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20#ifndef _ADV7183_H_
21#define _ADV7183_H_
22
23/* ADV7183 HW inputs */
24#define ADV7183_COMPOSITE0 0 /* CVBS in on AIN1 */
25#define ADV7183_COMPOSITE1 1 /* CVBS in on AIN2 */
26#define ADV7183_COMPOSITE2 2 /* CVBS in on AIN3 */
27#define ADV7183_COMPOSITE3 3 /* CVBS in on AIN4 */
28#define ADV7183_COMPOSITE4 4 /* CVBS in on AIN5 */
29#define ADV7183_COMPOSITE5 5 /* CVBS in on AIN6 */
30#define ADV7183_COMPOSITE6 6 /* CVBS in on AIN7 */
31#define ADV7183_COMPOSITE7 7 /* CVBS in on AIN8 */
32#define ADV7183_COMPOSITE8 8 /* CVBS in on AIN9 */
33#define ADV7183_COMPOSITE9 9 /* CVBS in on AIN10 */
34#define ADV7183_COMPOSITE10 10 /* CVBS in on AIN11 */
35
36#define ADV7183_SVIDEO0 11 /* Y on AIN1, C on AIN4 */
37#define ADV7183_SVIDEO1 12 /* Y on AIN2, C on AIN5 */
38#define ADV7183_SVIDEO2 13 /* Y on AIN3, C on AIN6 */
39
40#define ADV7183_COMPONENT0 14 /* Y on AIN1, Pr on AIN4, Pb on AIN5 */
41#define ADV7183_COMPONENT1 15 /* Y on AIN2, Pr on AIN3, Pb on AIN6 */
42
43/* ADV7183 HW outputs */
44#define ADV7183_8BIT_OUT 0
45#define ADV7183_16BIT_OUT 1
46
47#endif
diff --git a/include/media/v4l2-chip-ident.h b/include/media/v4l2-chip-ident.h
index 810a20928a21..6da4ed0ca196 100644
--- a/include/media/v4l2-chip-ident.h
+++ b/include/media/v4l2-chip-ident.h
@@ -162,6 +162,9 @@ enum {
162 /* module adv7180: just ident 7180 */ 162 /* module adv7180: just ident 7180 */
163 V4L2_IDENT_ADV7180 = 7180, 163 V4L2_IDENT_ADV7180 = 7180,
164 164
165 /* module adv7183: just ident 7183 */
166 V4L2_IDENT_ADV7183 = 7183,
167
165 /* module saa7185: just ident 7185 */ 168 /* module saa7185: just ident 7185 */
166 V4L2_IDENT_SAA7185 = 7185, 169 V4L2_IDENT_SAA7185 = 7185,
167 170