blob: e31e8d909bb9958c765077369370376c96935486 [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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070021 */
22
23#include <linux/module.h>
Mauro Carvalho Chehab18f3fa12007-07-02 15:39:57 -030024#include <linux/types.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090025#include <linux/slab.h>
Hans Verkuilbba0d982008-09-07 07:58:46 -030026#include <linux/ioctl.h>
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080027#include <linux/uaccess.h>
Hans Verkuilbba0d982008-09-07 07:58:46 -030028#include <linux/i2c.h>
Hans Verkuil35631dc2009-02-19 14:56:37 -030029#include <linux/videodev2.h>
30#include <media/v4l2-device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32MODULE_DESCRIPTION("Analog Devices ADV7175 video encoder driver");
33MODULE_AUTHOR("Dave Perks");
34MODULE_LICENSE("GPL");
35
Hans Verkuil35631dc2009-02-19 14:56:37 -030036#define I2C_ADV7175 0xd4
37#define I2C_ADV7176 0x54
38
Hans Verkuil35631dc2009-02-19 14:56:37 -030039
Douglas Schilling Landgrafff699e62008-04-22 14:41:48 -030040static int debug;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041module_param(debug, int, 0);
42MODULE_PARM_DESC(debug, "Debug level (0-1)");
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044/* ----------------------------------------------------------------------- */
45
46struct adv7175 {
Hans Verkuil35631dc2009-02-19 14:56:37 -030047 struct v4l2_subdev sd;
Hans Verkuil107063c2009-02-18 17:26:06 -030048 v4l2_std_id norm;
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 int input;
Linus Torvalds1da177e2005-04-16 15:20:36 -070050};
51
Hans Verkuil35631dc2009-02-19 14:56:37 -030052static inline struct adv7175 *to_adv7175(struct v4l2_subdev *sd)
53{
54 return container_of(sd, struct adv7175, sd);
55}
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Linus Torvalds1da177e2005-04-16 15:20:36 -070057static char *inputs[] = { "pass_through", "play_back", "color_bar" };
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Boris BREZILLONf5fe58f2014-11-10 14:28:29 -030059static u32 adv7175_codes[] = {
60 MEDIA_BUS_FMT_UYVY8_2X8,
61 MEDIA_BUS_FMT_UYVY8_1X16,
Christian Gmeinerf1a84c92011-10-05 17:48:43 -030062};
63
Linus Torvalds1da177e2005-04-16 15:20:36 -070064/* ----------------------------------------------------------------------- */
65
Hans Verkuil35631dc2009-02-19 14:56:37 -030066static inline int adv7175_write(struct v4l2_subdev *sd, u8 reg, u8 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067{
Hans Verkuil35631dc2009-02-19 14:56:37 -030068 struct i2c_client *client = v4l2_get_subdevdata(sd);
69
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 return i2c_smbus_write_byte_data(client, reg, value);
71}
72
Hans Verkuil35631dc2009-02-19 14:56:37 -030073static inline int adv7175_read(struct v4l2_subdev *sd, u8 reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
Hans Verkuil35631dc2009-02-19 14:56:37 -030075 struct i2c_client *client = v4l2_get_subdevdata(sd);
76
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 return i2c_smbus_read_byte_data(client, reg);
78}
79
Hans Verkuil35631dc2009-02-19 14:56:37 -030080static int adv7175_write_block(struct v4l2_subdev *sd,
Hans Verkuilbba0d982008-09-07 07:58:46 -030081 const u8 *data, unsigned int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082{
Hans Verkuil35631dc2009-02-19 14:56:37 -030083 struct i2c_client *client = v4l2_get_subdevdata(sd);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 int ret = -1;
85 u8 reg;
86
87 /* the adv7175 has an autoincrement function, use it if
88 * the adapter understands raw I2C */
89 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
90 /* do raw I2C, not smbus compatible */
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 u8 block_data[32];
Jean Delvare9aa45e32006-03-22 03:48:35 -030092 int block_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 while (len >= 2) {
Jean Delvare9aa45e32006-03-22 03:48:35 -030095 block_len = 0;
96 block_data[block_len++] = reg = data[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 do {
Jean Delvare9aa45e32006-03-22 03:48:35 -030098 block_data[block_len++] = data[1];
Jean Delvare2467a672006-03-22 03:48:34 -030099 reg++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 len -= 2;
101 data += 2;
Hans Verkuilbba0d982008-09-07 07:58:46 -0300102 } while (len >= 2 && data[0] == reg && block_len < 32);
103 ret = i2c_master_send(client, block_data, block_len);
104 if (ret < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 break;
106 }
107 } else {
108 /* do some slow I2C emulation kind of thing */
109 while (len >= 2) {
110 reg = *data++;
Hans Verkuil35631dc2009-02-19 14:56:37 -0300111 ret = adv7175_write(sd, reg, *data++);
Hans Verkuilbba0d982008-09-07 07:58:46 -0300112 if (ret < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 break;
114 len -= 2;
115 }
116 }
117
118 return ret;
119}
120
Hans Verkuil35631dc2009-02-19 14:56:37 -0300121static void set_subcarrier_freq(struct v4l2_subdev *sd, int pass_through)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122{
123 /* for some reason pass_through NTSC needs
124 * a different sub-carrier freq to remain stable. */
Hans Verkuilbba0d982008-09-07 07:58:46 -0300125 if (pass_through)
Hans Verkuil35631dc2009-02-19 14:56:37 -0300126 adv7175_write(sd, 0x02, 0x00);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 else
Hans Verkuil35631dc2009-02-19 14:56:37 -0300128 adv7175_write(sd, 0x02, 0x55);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
Hans Verkuil35631dc2009-02-19 14:56:37 -0300130 adv7175_write(sd, 0x03, 0x55);
131 adv7175_write(sd, 0x04, 0x55);
132 adv7175_write(sd, 0x05, 0x25);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133}
134
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135/* ----------------------------------------------------------------------- */
Hans Verkuilbba0d982008-09-07 07:58:46 -0300136/* Output filter: S-Video Composite */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
Hans Verkuilbba0d982008-09-07 07:58:46 -0300138#define MR050 0x11 /* 0x09 */
139#define MR060 0x14 /* 0x0c */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
Hans Verkuilbba0d982008-09-07 07:58:46 -0300141/* ----------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
143#define TR0MODE 0x46
144#define TR0RST 0x80
145
146#define TR1CAPT 0x80
147#define TR1PLAY 0x00
148
149static const unsigned char init_common[] = {
150
151 0x00, MR050, /* MR0, PAL enabled */
152 0x01, 0x00, /* MR1 */
153 0x02, 0x0c, /* subc. freq. */
154 0x03, 0x8c, /* subc. freq. */
155 0x04, 0x79, /* subc. freq. */
156 0x05, 0x26, /* subc. freq. */
157 0x06, 0x40, /* subc. phase */
158
159 0x07, TR0MODE, /* TR0, 16bit */
160 0x08, 0x21, /* */
161 0x09, 0x00, /* */
162 0x0a, 0x00, /* */
163 0x0b, 0x00, /* */
164 0x0c, TR1CAPT, /* TR1 */
165 0x0d, 0x4f, /* MR2 */
166 0x0e, 0x00, /* */
167 0x0f, 0x00, /* */
168 0x10, 0x00, /* */
169 0x11, 0x00, /* */
170};
171
172static const unsigned char init_pal[] = {
173 0x00, MR050, /* MR0, PAL enabled */
174 0x01, 0x00, /* MR1 */
175 0x02, 0x0c, /* subc. freq. */
176 0x03, 0x8c, /* subc. freq. */
177 0x04, 0x79, /* subc. freq. */
178 0x05, 0x26, /* subc. freq. */
179 0x06, 0x40, /* subc. phase */
180};
181
182static const unsigned char init_ntsc[] = {
183 0x00, MR060, /* MR0, NTSC enabled */
184 0x01, 0x00, /* MR1 */
185 0x02, 0x55, /* subc. freq. */
186 0x03, 0x55, /* subc. freq. */
187 0x04, 0x55, /* subc. freq. */
188 0x05, 0x25, /* subc. freq. */
189 0x06, 0x1a, /* subc. phase */
190};
191
Hans Verkuil35631dc2009-02-19 14:56:37 -0300192static int adv7175_init(struct v4l2_subdev *sd, u32 val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193{
Hans Verkuil35631dc2009-02-19 14:56:37 -0300194 /* This is just for testing!!! */
195 adv7175_write_block(sd, init_common, sizeof(init_common));
196 adv7175_write(sd, 0x07, TR0MODE | TR0RST);
197 adv7175_write(sd, 0x07, TR0MODE);
198 return 0;
199}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
Hans Verkuil35631dc2009-02-19 14:56:37 -0300201static int adv7175_s_std_output(struct v4l2_subdev *sd, v4l2_std_id std)
202{
203 struct adv7175 *encoder = to_adv7175(sd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
Hans Verkuil35631dc2009-02-19 14:56:37 -0300205 if (std & V4L2_STD_NTSC) {
206 adv7175_write_block(sd, init_ntsc, sizeof(init_ntsc));
207 if (encoder->input == 0)
208 adv7175_write(sd, 0x0d, 0x4f); /* Enable genlock */
209 adv7175_write(sd, 0x07, TR0MODE | TR0RST);
210 adv7175_write(sd, 0x07, TR0MODE);
211 } else if (std & V4L2_STD_PAL) {
212 adv7175_write_block(sd, init_pal, sizeof(init_pal));
213 if (encoder->input == 0)
214 adv7175_write(sd, 0x0d, 0x4f); /* Enable genlock */
215 adv7175_write(sd, 0x07, TR0MODE | TR0RST);
216 adv7175_write(sd, 0x07, TR0MODE);
217 } else if (std & V4L2_STD_SECAM) {
218 /* This is an attempt to convert
219 * SECAM->PAL (typically it does not work
220 * due to genlock: when decoder is in SECAM
221 * and encoder in in PAL the subcarrier can
222 * not be syncronized with horizontal
223 * quency) */
224 adv7175_write_block(sd, init_pal, sizeof(init_pal));
225 if (encoder->input == 0)
226 adv7175_write(sd, 0x0d, 0x49); /* Disable genlock */
227 adv7175_write(sd, 0x07, TR0MODE | TR0RST);
228 adv7175_write(sd, 0x07, TR0MODE);
229 } else {
Hans Verkuilcc5cef82009-03-06 10:15:01 -0300230 v4l2_dbg(1, debug, sd, "illegal norm: %llx\n",
231 (unsigned long long)std);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 return -EINVAL;
233 }
Hans Verkuilcc5cef82009-03-06 10:15:01 -0300234 v4l2_dbg(1, debug, sd, "switched to %llx\n", (unsigned long long)std);
Hans Verkuil35631dc2009-02-19 14:56:37 -0300235 encoder->norm = std;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 return 0;
237}
238
Hans Verkuil5325b422009-04-02 11:26:22 -0300239static int adv7175_s_routing(struct v4l2_subdev *sd,
240 u32 input, u32 output, u32 config)
Hans Verkuil35631dc2009-02-19 14:56:37 -0300241{
242 struct adv7175 *encoder = to_adv7175(sd);
243
Hans Verkuil5325b422009-04-02 11:26:22 -0300244 /* RJ: input = 0: input is from decoder
245 input = 1: input is from ZR36060
246 input = 2: color bar */
Hans Verkuil35631dc2009-02-19 14:56:37 -0300247
Hans Verkuil5325b422009-04-02 11:26:22 -0300248 switch (input) {
Hans Verkuil35631dc2009-02-19 14:56:37 -0300249 case 0:
250 adv7175_write(sd, 0x01, 0x00);
251
252 if (encoder->norm & V4L2_STD_NTSC)
253 set_subcarrier_freq(sd, 1);
254
255 adv7175_write(sd, 0x0c, TR1CAPT); /* TR1 */
256 if (encoder->norm & V4L2_STD_SECAM)
257 adv7175_write(sd, 0x0d, 0x49); /* Disable genlock */
258 else
259 adv7175_write(sd, 0x0d, 0x4f); /* Enable genlock */
260 adv7175_write(sd, 0x07, TR0MODE | TR0RST);
261 adv7175_write(sd, 0x07, TR0MODE);
262 /*udelay(10);*/
263 break;
264
265 case 1:
266 adv7175_write(sd, 0x01, 0x00);
267
268 if (encoder->norm & V4L2_STD_NTSC)
269 set_subcarrier_freq(sd, 0);
270
271 adv7175_write(sd, 0x0c, TR1PLAY); /* TR1 */
272 adv7175_write(sd, 0x0d, 0x49);
273 adv7175_write(sd, 0x07, TR0MODE | TR0RST);
274 adv7175_write(sd, 0x07, TR0MODE);
275 /* udelay(10); */
276 break;
277
278 case 2:
279 adv7175_write(sd, 0x01, 0x80);
280
281 if (encoder->norm & V4L2_STD_NTSC)
282 set_subcarrier_freq(sd, 0);
283
284 adv7175_write(sd, 0x0d, 0x49);
285 adv7175_write(sd, 0x07, TR0MODE | TR0RST);
286 adv7175_write(sd, 0x07, TR0MODE);
287 /* udelay(10); */
288 break;
289
290 default:
Hans Verkuil5325b422009-04-02 11:26:22 -0300291 v4l2_dbg(1, debug, sd, "illegal input: %d\n", input);
Hans Verkuil35631dc2009-02-19 14:56:37 -0300292 return -EINVAL;
293 }
Hans Verkuil5325b422009-04-02 11:26:22 -0300294 v4l2_dbg(1, debug, sd, "switched to %s\n", inputs[input]);
295 encoder->input = input;
Hans Verkuil35631dc2009-02-19 14:56:37 -0300296 return 0;
297}
298
Hans Verkuilebcff5f2015-04-09 04:01:33 -0300299static int adv7175_enum_mbus_code(struct v4l2_subdev *sd,
300 struct v4l2_subdev_pad_config *cfg,
301 struct v4l2_subdev_mbus_code_enum *code)
Christian Gmeinerf1a84c92011-10-05 17:48:43 -0300302{
Hans Verkuilebcff5f2015-04-09 04:01:33 -0300303 if (code->pad || code->index >= ARRAY_SIZE(adv7175_codes))
Christian Gmeinerf1a84c92011-10-05 17:48:43 -0300304 return -EINVAL;
305
Hans Verkuilebcff5f2015-04-09 04:01:33 -0300306 code->code = adv7175_codes[code->index];
Christian Gmeinerf1a84c92011-10-05 17:48:43 -0300307 return 0;
308}
309
Hans Verkuilda298c62015-04-09 04:02:34 -0300310static int adv7175_get_fmt(struct v4l2_subdev *sd,
311 struct v4l2_subdev_pad_config *cfg,
312 struct v4l2_subdev_format *format)
Christian Gmeinerf1a84c92011-10-05 17:48:43 -0300313{
Hans Verkuilda298c62015-04-09 04:02:34 -0300314 struct v4l2_mbus_framefmt *mf = &format->format;
Christian Gmeinerf1a84c92011-10-05 17:48:43 -0300315 u8 val = adv7175_read(sd, 0x7);
316
Hans Verkuilda298c62015-04-09 04:02:34 -0300317 if (format->pad)
318 return -EINVAL;
319
Christian Gmeinerf1a84c92011-10-05 17:48:43 -0300320 if ((val & 0x40) == (1 << 6))
Boris BREZILLONf5fe58f2014-11-10 14:28:29 -0300321 mf->code = MEDIA_BUS_FMT_UYVY8_1X16;
Christian Gmeinerf1a84c92011-10-05 17:48:43 -0300322 else
Boris BREZILLONf5fe58f2014-11-10 14:28:29 -0300323 mf->code = MEDIA_BUS_FMT_UYVY8_2X8;
Christian Gmeinerf1a84c92011-10-05 17:48:43 -0300324
325 mf->colorspace = V4L2_COLORSPACE_SMPTE170M;
326 mf->width = 0;
327 mf->height = 0;
328 mf->field = V4L2_FIELD_ANY;
329
330 return 0;
331}
332
Hans Verkuil6e80c472015-03-21 09:39:09 -0300333static int adv7175_set_fmt(struct v4l2_subdev *sd,
334 struct v4l2_subdev_pad_config *cfg,
335 struct v4l2_subdev_format *format)
Christian Gmeinerf1a84c92011-10-05 17:48:43 -0300336{
Hans Verkuil6e80c472015-03-21 09:39:09 -0300337 struct v4l2_mbus_framefmt *mf = &format->format;
Christian Gmeinerf1a84c92011-10-05 17:48:43 -0300338 u8 val = adv7175_read(sd, 0x7);
Hans Verkuil6e80c472015-03-21 09:39:09 -0300339 int ret = 0;
340
341 if (format->pad)
342 return -EINVAL;
Christian Gmeinerf1a84c92011-10-05 17:48:43 -0300343
344 switch (mf->code) {
Boris BREZILLONf5fe58f2014-11-10 14:28:29 -0300345 case MEDIA_BUS_FMT_UYVY8_2X8:
Christian Gmeinerf1a84c92011-10-05 17:48:43 -0300346 val &= ~0x40;
347 break;
348
Boris BREZILLONf5fe58f2014-11-10 14:28:29 -0300349 case MEDIA_BUS_FMT_UYVY8_1X16:
Christian Gmeinerf1a84c92011-10-05 17:48:43 -0300350 val |= 0x40;
351 break;
352
353 default:
354 v4l2_dbg(1, debug, sd,
355 "illegal v4l2_mbus_framefmt code: %d\n", mf->code);
356 return -EINVAL;
357 }
358
Hans Verkuil6e80c472015-03-21 09:39:09 -0300359 if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE)
360 ret = adv7175_write(sd, 0x7, val);
Christian Gmeinerf1a84c92011-10-05 17:48:43 -0300361
362 return ret;
363}
364
Christian Gmeinerb7eccc462011-01-08 18:45:35 -0300365static int adv7175_s_power(struct v4l2_subdev *sd, int on)
366{
367 if (on)
368 adv7175_write(sd, 0x01, 0x00);
369 else
370 adv7175_write(sd, 0x01, 0x78);
371
372 return 0;
373}
374
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375/* ----------------------------------------------------------------------- */
376
Hans Verkuil35631dc2009-02-19 14:56:37 -0300377static const struct v4l2_subdev_core_ops adv7175_core_ops = {
Hans Verkuil35631dc2009-02-19 14:56:37 -0300378 .init = adv7175_init,
Christian Gmeinerb7eccc462011-01-08 18:45:35 -0300379 .s_power = adv7175_s_power,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
Hans Verkuil35631dc2009-02-19 14:56:37 -0300382static const struct v4l2_subdev_video_ops adv7175_video_ops = {
383 .s_std_output = adv7175_s_std_output,
384 .s_routing = adv7175_s_routing,
Hans Verkuilebcff5f2015-04-09 04:01:33 -0300385};
386
387static const struct v4l2_subdev_pad_ops adv7175_pad_ops = {
388 .enum_mbus_code = adv7175_enum_mbus_code,
Hans Verkuilda298c62015-04-09 04:02:34 -0300389 .get_fmt = adv7175_get_fmt,
Hans Verkuil6e80c472015-03-21 09:39:09 -0300390 .set_fmt = adv7175_set_fmt,
Hans Verkuil35631dc2009-02-19 14:56:37 -0300391};
392
393static const struct v4l2_subdev_ops adv7175_ops = {
394 .core = &adv7175_core_ops,
395 .video = &adv7175_video_ops,
Hans Verkuilebcff5f2015-04-09 04:01:33 -0300396 .pad = &adv7175_pad_ops,
Hans Verkuil35631dc2009-02-19 14:56:37 -0300397};
398
399/* ----------------------------------------------------------------------- */
Mauro Carvalho Chehabd56410e2006-03-25 09:19:53 -0300400
Hans Verkuilbba0d982008-09-07 07:58:46 -0300401static int adv7175_probe(struct i2c_client *client,
402 const struct i2c_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403{
404 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 struct adv7175 *encoder;
Hans Verkuil35631dc2009-02-19 14:56:37 -0300406 struct v4l2_subdev *sd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
408 /* Check if the adapter supports the needed features */
Hans Verkuilbba0d982008-09-07 07:58:46 -0300409 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
410 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
Hans Verkuilbba0d982008-09-07 07:58:46 -0300412 v4l_info(client, "chip found @ 0x%x (%s)\n",
413 client->addr << 1, client->adapter->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
Laurent Pinchartc02b2112013-05-02 08:29:43 -0300415 encoder = devm_kzalloc(&client->dev, sizeof(*encoder), GFP_KERNEL);
Hans Verkuilbba0d982008-09-07 07:58:46 -0300416 if (encoder == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 return -ENOMEM;
Hans Verkuil35631dc2009-02-19 14:56:37 -0300418 sd = &encoder->sd;
419 v4l2_i2c_subdev_init(sd, client, &adv7175_ops);
Hans Verkuil107063c2009-02-18 17:26:06 -0300420 encoder->norm = V4L2_STD_NTSC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 encoder->input = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
Hans Verkuil35631dc2009-02-19 14:56:37 -0300423 i = adv7175_write_block(sd, init_common, sizeof(init_common));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 if (i >= 0) {
Hans Verkuil35631dc2009-02-19 14:56:37 -0300425 i = adv7175_write(sd, 0x07, TR0MODE | TR0RST);
426 i = adv7175_write(sd, 0x07, TR0MODE);
427 i = adv7175_read(sd, 0x12);
428 v4l2_dbg(1, debug, sd, "revision %d\n", i & 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 }
Hans Verkuilbba0d982008-09-07 07:58:46 -0300430 if (i < 0)
Hans Verkuil35631dc2009-02-19 14:56:37 -0300431 v4l2_dbg(1, debug, sd, "init error 0x%x\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 return 0;
433}
434
Hans Verkuilbba0d982008-09-07 07:58:46 -0300435static int adv7175_remove(struct i2c_client *client)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436{
Hans Verkuil35631dc2009-02-19 14:56:37 -0300437 struct v4l2_subdev *sd = i2c_get_clientdata(client);
438
439 v4l2_device_unregister_subdev(sd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 return 0;
441}
442
443/* ----------------------------------------------------------------------- */
444
Hans Verkuilbba0d982008-09-07 07:58:46 -0300445static const struct i2c_device_id adv7175_id[] = {
446 { "adv7175", 0 },
447 { "adv7176", 0 },
448 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449};
Hans Verkuilbba0d982008-09-07 07:58:46 -0300450MODULE_DEVICE_TABLE(i2c, adv7175_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
Hans Verkuildc714432010-09-15 15:29:53 -0300452static struct i2c_driver adv7175_driver = {
453 .driver = {
Hans Verkuildc714432010-09-15 15:29:53 -0300454 .name = "adv7175",
455 },
456 .probe = adv7175_probe,
457 .remove = adv7175_remove,
458 .id_table = adv7175_id,
Hans Verkuilbba0d982008-09-07 07:58:46 -0300459};
Hans Verkuildc714432010-09-15 15:29:53 -0300460
Axel Linc6e8d862012-02-12 06:56:32 -0300461module_i2c_driver(adv7175_driver);