blob: f554809a51e75d5e0102e24a5a8db88ee52a83d3 [file] [log] [blame]
Mauro Carvalho Chehabd56410e2006-03-25 09:19:53 -03001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * adv7175 - adv7175a video encoder driver version 0.0.3
3 *
4 * Copyright (C) 1998 Dave Perks <dperks@ibm.net>
5 * Copyright (C) 1999 Wolfgang Scherr <scherr@net4you.net>
6 * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
7 * - some corrections for Pinnacle Systems Inc. DC10plus card.
8 *
9 * Changes by Ronald Bultje <rbultje@ronald.bitfreak.net>
10 * - moved over to linux>=2.4.x i2c protocol (9/9/2002)
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 */
26
27#include <linux/module.h>
Mauro Carvalho Chehab18f3fa12007-07-02 15:39:57 -030028#include <linux/types.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090029#include <linux/slab.h>
Hans Verkuilbba0d982008-09-07 07:58:46 -030030#include <linux/ioctl.h>
Mauro Carvalho Chehab18f3fa12007-07-02 15:39:57 -030031#include <asm/uaccess.h>
Hans Verkuilbba0d982008-09-07 07:58:46 -030032#include <linux/i2c.h>
Hans Verkuil35631dc2009-02-19 14:56:37 -030033#include <linux/videodev2.h>
34#include <media/v4l2-device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36MODULE_DESCRIPTION("Analog Devices ADV7175 video encoder driver");
37MODULE_AUTHOR("Dave Perks");
38MODULE_LICENSE("GPL");
39
Hans Verkuil35631dc2009-02-19 14:56:37 -030040#define I2C_ADV7175 0xd4
41#define I2C_ADV7176 0x54
42
Hans Verkuil35631dc2009-02-19 14:56:37 -030043
Douglas Schilling Landgrafff699e62008-04-22 14:41:48 -030044static int debug;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045module_param(debug, int, 0);
46MODULE_PARM_DESC(debug, "Debug level (0-1)");
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048/* ----------------------------------------------------------------------- */
49
50struct adv7175 {
Hans Verkuil35631dc2009-02-19 14:56:37 -030051 struct v4l2_subdev sd;
Hans Verkuil107063c2009-02-18 17:26:06 -030052 v4l2_std_id norm;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 int input;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054};
55
Hans Verkuil35631dc2009-02-19 14:56:37 -030056static inline struct adv7175 *to_adv7175(struct v4l2_subdev *sd)
57{
58 return container_of(sd, struct adv7175, sd);
59}
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Linus Torvalds1da177e2005-04-16 15:20:36 -070061static char *inputs[] = { "pass_through", "play_back", "color_bar" };
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Boris BREZILLONf5fe58f2014-11-10 14:28:29 -030063static u32 adv7175_codes[] = {
64 MEDIA_BUS_FMT_UYVY8_2X8,
65 MEDIA_BUS_FMT_UYVY8_1X16,
Christian Gmeinerf1a84c92011-10-05 17:48:43 -030066};
67
Linus Torvalds1da177e2005-04-16 15:20:36 -070068/* ----------------------------------------------------------------------- */
69
Hans Verkuil35631dc2009-02-19 14:56:37 -030070static inline int adv7175_write(struct v4l2_subdev *sd, u8 reg, u8 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071{
Hans Verkuil35631dc2009-02-19 14:56:37 -030072 struct i2c_client *client = v4l2_get_subdevdata(sd);
73
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 return i2c_smbus_write_byte_data(client, reg, value);
75}
76
Hans Verkuil35631dc2009-02-19 14:56:37 -030077static inline int adv7175_read(struct v4l2_subdev *sd, u8 reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078{
Hans Verkuil35631dc2009-02-19 14:56:37 -030079 struct i2c_client *client = v4l2_get_subdevdata(sd);
80
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 return i2c_smbus_read_byte_data(client, reg);
82}
83
Hans Verkuil35631dc2009-02-19 14:56:37 -030084static int adv7175_write_block(struct v4l2_subdev *sd,
Hans Verkuilbba0d982008-09-07 07:58:46 -030085 const u8 *data, unsigned int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086{
Hans Verkuil35631dc2009-02-19 14:56:37 -030087 struct i2c_client *client = v4l2_get_subdevdata(sd);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 int ret = -1;
89 u8 reg;
90
91 /* the adv7175 has an autoincrement function, use it if
92 * the adapter understands raw I2C */
93 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
94 /* do raw I2C, not smbus compatible */
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 u8 block_data[32];
Jean Delvare9aa45e32006-03-22 03:48:35 -030096 int block_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 while (len >= 2) {
Jean Delvare9aa45e32006-03-22 03:48:35 -030099 block_len = 0;
100 block_data[block_len++] = reg = data[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 do {
Jean Delvare9aa45e32006-03-22 03:48:35 -0300102 block_data[block_len++] = data[1];
Jean Delvare2467a672006-03-22 03:48:34 -0300103 reg++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 len -= 2;
105 data += 2;
Hans Verkuilbba0d982008-09-07 07:58:46 -0300106 } while (len >= 2 && data[0] == reg && block_len < 32);
107 ret = i2c_master_send(client, block_data, block_len);
108 if (ret < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 break;
110 }
111 } else {
112 /* do some slow I2C emulation kind of thing */
113 while (len >= 2) {
114 reg = *data++;
Hans Verkuil35631dc2009-02-19 14:56:37 -0300115 ret = adv7175_write(sd, reg, *data++);
Hans Verkuilbba0d982008-09-07 07:58:46 -0300116 if (ret < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 break;
118 len -= 2;
119 }
120 }
121
122 return ret;
123}
124
Hans Verkuil35631dc2009-02-19 14:56:37 -0300125static void set_subcarrier_freq(struct v4l2_subdev *sd, int pass_through)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126{
127 /* for some reason pass_through NTSC needs
128 * a different sub-carrier freq to remain stable. */
Hans Verkuilbba0d982008-09-07 07:58:46 -0300129 if (pass_through)
Hans Verkuil35631dc2009-02-19 14:56:37 -0300130 adv7175_write(sd, 0x02, 0x00);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 else
Hans Verkuil35631dc2009-02-19 14:56:37 -0300132 adv7175_write(sd, 0x02, 0x55);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Hans Verkuil35631dc2009-02-19 14:56:37 -0300134 adv7175_write(sd, 0x03, 0x55);
135 adv7175_write(sd, 0x04, 0x55);
136 adv7175_write(sd, 0x05, 0x25);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137}
138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139/* ----------------------------------------------------------------------- */
Hans Verkuilbba0d982008-09-07 07:58:46 -0300140/* Output filter: S-Video Composite */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
Hans Verkuilbba0d982008-09-07 07:58:46 -0300142#define MR050 0x11 /* 0x09 */
143#define MR060 0x14 /* 0x0c */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
Hans Verkuilbba0d982008-09-07 07:58:46 -0300145/* ----------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
147#define TR0MODE 0x46
148#define TR0RST 0x80
149
150#define TR1CAPT 0x80
151#define TR1PLAY 0x00
152
153static const unsigned char init_common[] = {
154
155 0x00, MR050, /* MR0, PAL enabled */
156 0x01, 0x00, /* MR1 */
157 0x02, 0x0c, /* subc. freq. */
158 0x03, 0x8c, /* subc. freq. */
159 0x04, 0x79, /* subc. freq. */
160 0x05, 0x26, /* subc. freq. */
161 0x06, 0x40, /* subc. phase */
162
163 0x07, TR0MODE, /* TR0, 16bit */
164 0x08, 0x21, /* */
165 0x09, 0x00, /* */
166 0x0a, 0x00, /* */
167 0x0b, 0x00, /* */
168 0x0c, TR1CAPT, /* TR1 */
169 0x0d, 0x4f, /* MR2 */
170 0x0e, 0x00, /* */
171 0x0f, 0x00, /* */
172 0x10, 0x00, /* */
173 0x11, 0x00, /* */
174};
175
176static const unsigned char init_pal[] = {
177 0x00, MR050, /* MR0, PAL enabled */
178 0x01, 0x00, /* MR1 */
179 0x02, 0x0c, /* subc. freq. */
180 0x03, 0x8c, /* subc. freq. */
181 0x04, 0x79, /* subc. freq. */
182 0x05, 0x26, /* subc. freq. */
183 0x06, 0x40, /* subc. phase */
184};
185
186static const unsigned char init_ntsc[] = {
187 0x00, MR060, /* MR0, NTSC enabled */
188 0x01, 0x00, /* MR1 */
189 0x02, 0x55, /* subc. freq. */
190 0x03, 0x55, /* subc. freq. */
191 0x04, 0x55, /* subc. freq. */
192 0x05, 0x25, /* subc. freq. */
193 0x06, 0x1a, /* subc. phase */
194};
195
Hans Verkuil35631dc2009-02-19 14:56:37 -0300196static int adv7175_init(struct v4l2_subdev *sd, u32 val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197{
Hans Verkuil35631dc2009-02-19 14:56:37 -0300198 /* This is just for testing!!! */
199 adv7175_write_block(sd, init_common, sizeof(init_common));
200 adv7175_write(sd, 0x07, TR0MODE | TR0RST);
201 adv7175_write(sd, 0x07, TR0MODE);
202 return 0;
203}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
Hans Verkuil35631dc2009-02-19 14:56:37 -0300205static int adv7175_s_std_output(struct v4l2_subdev *sd, v4l2_std_id std)
206{
207 struct adv7175 *encoder = to_adv7175(sd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
Hans Verkuil35631dc2009-02-19 14:56:37 -0300209 if (std & V4L2_STD_NTSC) {
210 adv7175_write_block(sd, init_ntsc, sizeof(init_ntsc));
211 if (encoder->input == 0)
212 adv7175_write(sd, 0x0d, 0x4f); /* Enable genlock */
213 adv7175_write(sd, 0x07, TR0MODE | TR0RST);
214 adv7175_write(sd, 0x07, TR0MODE);
215 } else if (std & V4L2_STD_PAL) {
216 adv7175_write_block(sd, init_pal, sizeof(init_pal));
217 if (encoder->input == 0)
218 adv7175_write(sd, 0x0d, 0x4f); /* Enable genlock */
219 adv7175_write(sd, 0x07, TR0MODE | TR0RST);
220 adv7175_write(sd, 0x07, TR0MODE);
221 } else if (std & V4L2_STD_SECAM) {
222 /* This is an attempt to convert
223 * SECAM->PAL (typically it does not work
224 * due to genlock: when decoder is in SECAM
225 * and encoder in in PAL the subcarrier can
226 * not be syncronized with horizontal
227 * quency) */
228 adv7175_write_block(sd, init_pal, sizeof(init_pal));
229 if (encoder->input == 0)
230 adv7175_write(sd, 0x0d, 0x49); /* Disable genlock */
231 adv7175_write(sd, 0x07, TR0MODE | TR0RST);
232 adv7175_write(sd, 0x07, TR0MODE);
233 } else {
Hans Verkuilcc5cef82009-03-06 10:15:01 -0300234 v4l2_dbg(1, debug, sd, "illegal norm: %llx\n",
235 (unsigned long long)std);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 return -EINVAL;
237 }
Hans Verkuilcc5cef82009-03-06 10:15:01 -0300238 v4l2_dbg(1, debug, sd, "switched to %llx\n", (unsigned long long)std);
Hans Verkuil35631dc2009-02-19 14:56:37 -0300239 encoder->norm = std;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 return 0;
241}
242
Hans Verkuil5325b422009-04-02 11:26:22 -0300243static int adv7175_s_routing(struct v4l2_subdev *sd,
244 u32 input, u32 output, u32 config)
Hans Verkuil35631dc2009-02-19 14:56:37 -0300245{
246 struct adv7175 *encoder = to_adv7175(sd);
247
Hans Verkuil5325b422009-04-02 11:26:22 -0300248 /* RJ: input = 0: input is from decoder
249 input = 1: input is from ZR36060
250 input = 2: color bar */
Hans Verkuil35631dc2009-02-19 14:56:37 -0300251
Hans Verkuil5325b422009-04-02 11:26:22 -0300252 switch (input) {
Hans Verkuil35631dc2009-02-19 14:56:37 -0300253 case 0:
254 adv7175_write(sd, 0x01, 0x00);
255
256 if (encoder->norm & V4L2_STD_NTSC)
257 set_subcarrier_freq(sd, 1);
258
259 adv7175_write(sd, 0x0c, TR1CAPT); /* TR1 */
260 if (encoder->norm & V4L2_STD_SECAM)
261 adv7175_write(sd, 0x0d, 0x49); /* Disable genlock */
262 else
263 adv7175_write(sd, 0x0d, 0x4f); /* Enable genlock */
264 adv7175_write(sd, 0x07, TR0MODE | TR0RST);
265 adv7175_write(sd, 0x07, TR0MODE);
266 /*udelay(10);*/
267 break;
268
269 case 1:
270 adv7175_write(sd, 0x01, 0x00);
271
272 if (encoder->norm & V4L2_STD_NTSC)
273 set_subcarrier_freq(sd, 0);
274
275 adv7175_write(sd, 0x0c, TR1PLAY); /* TR1 */
276 adv7175_write(sd, 0x0d, 0x49);
277 adv7175_write(sd, 0x07, TR0MODE | TR0RST);
278 adv7175_write(sd, 0x07, TR0MODE);
279 /* udelay(10); */
280 break;
281
282 case 2:
283 adv7175_write(sd, 0x01, 0x80);
284
285 if (encoder->norm & V4L2_STD_NTSC)
286 set_subcarrier_freq(sd, 0);
287
288 adv7175_write(sd, 0x0d, 0x49);
289 adv7175_write(sd, 0x07, TR0MODE | TR0RST);
290 adv7175_write(sd, 0x07, TR0MODE);
291 /* udelay(10); */
292 break;
293
294 default:
Hans Verkuil5325b422009-04-02 11:26:22 -0300295 v4l2_dbg(1, debug, sd, "illegal input: %d\n", input);
Hans Verkuil35631dc2009-02-19 14:56:37 -0300296 return -EINVAL;
297 }
Hans Verkuil5325b422009-04-02 11:26:22 -0300298 v4l2_dbg(1, debug, sd, "switched to %s\n", inputs[input]);
299 encoder->input = input;
Hans Verkuil35631dc2009-02-19 14:56:37 -0300300 return 0;
301}
302
Hans Verkuilebcff5f2015-04-09 04:01:33 -0300303static int adv7175_enum_mbus_code(struct v4l2_subdev *sd,
304 struct v4l2_subdev_pad_config *cfg,
305 struct v4l2_subdev_mbus_code_enum *code)
Christian Gmeinerf1a84c92011-10-05 17:48:43 -0300306{
Hans Verkuilebcff5f2015-04-09 04:01:33 -0300307 if (code->pad || code->index >= ARRAY_SIZE(adv7175_codes))
Christian Gmeinerf1a84c92011-10-05 17:48:43 -0300308 return -EINVAL;
309
Hans Verkuilebcff5f2015-04-09 04:01:33 -0300310 code->code = adv7175_codes[code->index];
Christian Gmeinerf1a84c92011-10-05 17:48:43 -0300311 return 0;
312}
313
Hans Verkuilda298c62015-04-09 04:02:34 -0300314static int adv7175_get_fmt(struct v4l2_subdev *sd,
315 struct v4l2_subdev_pad_config *cfg,
316 struct v4l2_subdev_format *format)
Christian Gmeinerf1a84c92011-10-05 17:48:43 -0300317{
Hans Verkuilda298c62015-04-09 04:02:34 -0300318 struct v4l2_mbus_framefmt *mf = &format->format;
Christian Gmeinerf1a84c92011-10-05 17:48:43 -0300319 u8 val = adv7175_read(sd, 0x7);
320
Hans Verkuilda298c62015-04-09 04:02:34 -0300321 if (format->pad)
322 return -EINVAL;
323
Christian Gmeinerf1a84c92011-10-05 17:48:43 -0300324 if ((val & 0x40) == (1 << 6))
Boris BREZILLONf5fe58f2014-11-10 14:28:29 -0300325 mf->code = MEDIA_BUS_FMT_UYVY8_1X16;
Christian Gmeinerf1a84c92011-10-05 17:48:43 -0300326 else
Boris BREZILLONf5fe58f2014-11-10 14:28:29 -0300327 mf->code = MEDIA_BUS_FMT_UYVY8_2X8;
Christian Gmeinerf1a84c92011-10-05 17:48:43 -0300328
329 mf->colorspace = V4L2_COLORSPACE_SMPTE170M;
330 mf->width = 0;
331 mf->height = 0;
332 mf->field = V4L2_FIELD_ANY;
333
334 return 0;
335}
336
Hans Verkuil6e80c472015-03-21 09:39:09 -0300337static int adv7175_set_fmt(struct v4l2_subdev *sd,
338 struct v4l2_subdev_pad_config *cfg,
339 struct v4l2_subdev_format *format)
Christian Gmeinerf1a84c92011-10-05 17:48:43 -0300340{
Hans Verkuil6e80c472015-03-21 09:39:09 -0300341 struct v4l2_mbus_framefmt *mf = &format->format;
Christian Gmeinerf1a84c92011-10-05 17:48:43 -0300342 u8 val = adv7175_read(sd, 0x7);
Hans Verkuil6e80c472015-03-21 09:39:09 -0300343 int ret = 0;
344
345 if (format->pad)
346 return -EINVAL;
Christian Gmeinerf1a84c92011-10-05 17:48:43 -0300347
348 switch (mf->code) {
Boris BREZILLONf5fe58f2014-11-10 14:28:29 -0300349 case MEDIA_BUS_FMT_UYVY8_2X8:
Christian Gmeinerf1a84c92011-10-05 17:48:43 -0300350 val &= ~0x40;
351 break;
352
Boris BREZILLONf5fe58f2014-11-10 14:28:29 -0300353 case MEDIA_BUS_FMT_UYVY8_1X16:
Christian Gmeinerf1a84c92011-10-05 17:48:43 -0300354 val |= 0x40;
355 break;
356
357 default:
358 v4l2_dbg(1, debug, sd,
359 "illegal v4l2_mbus_framefmt code: %d\n", mf->code);
360 return -EINVAL;
361 }
362
Hans Verkuil6e80c472015-03-21 09:39:09 -0300363 if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE)
364 ret = adv7175_write(sd, 0x7, val);
Christian Gmeinerf1a84c92011-10-05 17:48:43 -0300365
366 return ret;
367}
368
Christian Gmeinerb7eccc462011-01-08 18:45:35 -0300369static int adv7175_s_power(struct v4l2_subdev *sd, int on)
370{
371 if (on)
372 adv7175_write(sd, 0x01, 0x00);
373 else
374 adv7175_write(sd, 0x01, 0x78);
375
376 return 0;
377}
378
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379/* ----------------------------------------------------------------------- */
380
Hans Verkuil35631dc2009-02-19 14:56:37 -0300381static const struct v4l2_subdev_core_ops adv7175_core_ops = {
Hans Verkuil35631dc2009-02-19 14:56:37 -0300382 .init = adv7175_init,
Christian Gmeinerb7eccc462011-01-08 18:45:35 -0300383 .s_power = adv7175_s_power,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
Hans Verkuil35631dc2009-02-19 14:56:37 -0300386static const struct v4l2_subdev_video_ops adv7175_video_ops = {
387 .s_std_output = adv7175_s_std_output,
388 .s_routing = adv7175_s_routing,
Hans Verkuilebcff5f2015-04-09 04:01:33 -0300389};
390
391static const struct v4l2_subdev_pad_ops adv7175_pad_ops = {
392 .enum_mbus_code = adv7175_enum_mbus_code,
Hans Verkuilda298c62015-04-09 04:02:34 -0300393 .get_fmt = adv7175_get_fmt,
Hans Verkuil6e80c472015-03-21 09:39:09 -0300394 .set_fmt = adv7175_set_fmt,
Hans Verkuil35631dc2009-02-19 14:56:37 -0300395};
396
397static const struct v4l2_subdev_ops adv7175_ops = {
398 .core = &adv7175_core_ops,
399 .video = &adv7175_video_ops,
Hans Verkuilebcff5f2015-04-09 04:01:33 -0300400 .pad = &adv7175_pad_ops,
Hans Verkuil35631dc2009-02-19 14:56:37 -0300401};
402
403/* ----------------------------------------------------------------------- */
Mauro Carvalho Chehabd56410e2006-03-25 09:19:53 -0300404
Hans Verkuilbba0d982008-09-07 07:58:46 -0300405static int adv7175_probe(struct i2c_client *client,
406 const struct i2c_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407{
408 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 struct adv7175 *encoder;
Hans Verkuil35631dc2009-02-19 14:56:37 -0300410 struct v4l2_subdev *sd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
412 /* Check if the adapter supports the needed features */
Hans Verkuilbba0d982008-09-07 07:58:46 -0300413 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
414 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
Hans Verkuilbba0d982008-09-07 07:58:46 -0300416 v4l_info(client, "chip found @ 0x%x (%s)\n",
417 client->addr << 1, client->adapter->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
Laurent Pinchartc02b2112013-05-02 08:29:43 -0300419 encoder = devm_kzalloc(&client->dev, sizeof(*encoder), GFP_KERNEL);
Hans Verkuilbba0d982008-09-07 07:58:46 -0300420 if (encoder == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 return -ENOMEM;
Hans Verkuil35631dc2009-02-19 14:56:37 -0300422 sd = &encoder->sd;
423 v4l2_i2c_subdev_init(sd, client, &adv7175_ops);
Hans Verkuil107063c2009-02-18 17:26:06 -0300424 encoder->norm = V4L2_STD_NTSC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 encoder->input = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
Hans Verkuil35631dc2009-02-19 14:56:37 -0300427 i = adv7175_write_block(sd, init_common, sizeof(init_common));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 if (i >= 0) {
Hans Verkuil35631dc2009-02-19 14:56:37 -0300429 i = adv7175_write(sd, 0x07, TR0MODE | TR0RST);
430 i = adv7175_write(sd, 0x07, TR0MODE);
431 i = adv7175_read(sd, 0x12);
432 v4l2_dbg(1, debug, sd, "revision %d\n", i & 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 }
Hans Verkuilbba0d982008-09-07 07:58:46 -0300434 if (i < 0)
Hans Verkuil35631dc2009-02-19 14:56:37 -0300435 v4l2_dbg(1, debug, sd, "init error 0x%x\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 return 0;
437}
438
Hans Verkuilbba0d982008-09-07 07:58:46 -0300439static int adv7175_remove(struct i2c_client *client)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440{
Hans Verkuil35631dc2009-02-19 14:56:37 -0300441 struct v4l2_subdev *sd = i2c_get_clientdata(client);
442
443 v4l2_device_unregister_subdev(sd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 return 0;
445}
446
447/* ----------------------------------------------------------------------- */
448
Hans Verkuilbba0d982008-09-07 07:58:46 -0300449static const struct i2c_device_id adv7175_id[] = {
450 { "adv7175", 0 },
451 { "adv7176", 0 },
452 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453};
Hans Verkuilbba0d982008-09-07 07:58:46 -0300454MODULE_DEVICE_TABLE(i2c, adv7175_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455
Hans Verkuildc714432010-09-15 15:29:53 -0300456static struct i2c_driver adv7175_driver = {
457 .driver = {
Hans Verkuildc714432010-09-15 15:29:53 -0300458 .name = "adv7175",
459 },
460 .probe = adv7175_probe,
461 .remove = adv7175_remove,
462 .id_table = adv7175_id,
Hans Verkuilbba0d982008-09-07 07:58:46 -0300463};
Hans Verkuildc714432010-09-15 15:29:53 -0300464
Axel Linc6e8d862012-02-12 06:56:32 -0300465module_i2c_driver(adv7175_driver);