blob: f2ebf8441aa0ddde9a065d4c9bfc19d1afd4362f [file] [log] [blame]
Mauro Carvalho Chehabd56410e2006-03-25 09:19:53 -03001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * bt819 - BT819A VideoStream Decoder (Rockwell Part)
3 *
4 * Copyright (C) 1999 Mike Bernson <mike@mlb.org>
5 * Copyright (C) 1998 Dave Perks <dperks@ibm.net>
6 *
7 * Modifications for LML33/DC10plus unified driver
8 * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
Mauro Carvalho Chehabd56410e2006-03-25 09:19:53 -03009 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 * Changes by Ronald Bultje <rbultje@ronald.bitfreak.net>
11 * - moved over to linux>=2.4.x i2c protocol (9/9/2002)
12 *
13 * This code was modify/ported from the saa7111 driver written
14 * by Dave Perks.
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 */
30
31#include <linux/module.h>
Mauro Carvalho Chehab18f3fa12007-07-02 15:39:57 -030032#include <linux/types.h>
Hans Verkuil7fd011f2008-10-13 07:30:15 -030033#include <linux/ioctl.h>
Hans Verkuil28839132009-02-19 08:08:07 -030034#include <linux/delay.h>
Mauro Carvalho Chehab18f3fa12007-07-02 15:39:57 -030035#include <asm/uaccess.h>
Hans Verkuil7fd011f2008-10-13 07:30:15 -030036#include <linux/i2c.h>
37#include <linux/i2c-id.h>
Hans Verkuilc2179ad2009-02-19 06:36:36 -030038#include <linux/videodev2.h>
39#include <media/v4l2-device.h>
40#include <media/v4l2-chip-ident.h>
Hans Verkuil2d266982009-02-19 17:41:19 -030041#include <media/v4l2-i2c-drv.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43MODULE_DESCRIPTION("Brooktree-819 video decoder driver");
44MODULE_AUTHOR("Mike Bernson & Dave Perks");
45MODULE_LICENSE("GPL");
46
Douglas Schilling Landgrafff699e62008-04-22 14:41:48 -030047static int debug;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048module_param(debug, int, 0);
49MODULE_PARM_DESC(debug, "Debug level (0-1)");
50
Hans Verkuilc2179ad2009-02-19 06:36:36 -030051
Linus Torvalds1da177e2005-04-16 15:20:36 -070052/* ----------------------------------------------------------------------- */
53
54struct bt819 {
Hans Verkuilc2179ad2009-02-19 06:36:36 -030055 struct v4l2_subdev sd;
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 unsigned char reg[32];
57
Hans Verkuil107063c2009-02-18 17:26:06 -030058 v4l2_std_id norm;
Hans Verkuilc2179ad2009-02-19 06:36:36 -030059 int ident;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 int input;
61 int enable;
62 int bright;
63 int contrast;
64 int hue;
65 int sat;
66};
67
Hans Verkuilc2179ad2009-02-19 06:36:36 -030068static inline struct bt819 *to_bt819(struct v4l2_subdev *sd)
69{
70 return container_of(sd, struct bt819, sd);
71}
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073struct timing {
74 int hactive;
75 int hdelay;
76 int vactive;
77 int vdelay;
78 int hscale;
79 int vscale;
80};
81
82/* for values, see the bt819 datasheet */
83static struct timing timing_data[] = {
84 {864 - 24, 20, 625 - 2, 1, 0x0504, 0x0000},
85 {858 - 24, 20, 525 - 2, 1, 0x00f8, 0x0000},
86};
87
Linus Torvalds1da177e2005-04-16 15:20:36 -070088/* ----------------------------------------------------------------------- */
89
Hans Verkuilc2179ad2009-02-19 06:36:36 -030090static inline int bt819_write(struct bt819 *decoder, u8 reg, u8 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091{
Hans Verkuilc2179ad2009-02-19 06:36:36 -030092 struct i2c_client *client = v4l2_get_subdevdata(&decoder->sd);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
94 decoder->reg[reg] = value;
95 return i2c_smbus_write_byte_data(client, reg, value);
96}
97
Hans Verkuilc2179ad2009-02-19 06:36:36 -030098static inline int bt819_setbit(struct bt819 *decoder, u8 reg, u8 bit, u8 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -070099{
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300100 return bt819_write(decoder, reg,
Hans Verkuil7fd011f2008-10-13 07:30:15 -0300101 (decoder->reg[reg] & ~(1 << bit)) | (value ? (1 << bit) : 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102}
103
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300104static int bt819_write_block(struct bt819 *decoder, const u8 *data, unsigned int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105{
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300106 struct i2c_client *client = v4l2_get_subdevdata(&decoder->sd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 int ret = -1;
108 u8 reg;
109
110 /* the bt819 has an autoincrement function, use it if
111 * the adapter understands raw I2C */
112 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
113 /* do raw I2C, not smbus compatible */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 u8 block_data[32];
Jean Delvare9aa45e32006-03-22 03:48:35 -0300115 int block_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 while (len >= 2) {
Jean Delvare9aa45e32006-03-22 03:48:35 -0300118 block_len = 0;
119 block_data[block_len++] = reg = data[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 do {
Jean Delvare9aa45e32006-03-22 03:48:35 -0300121 block_data[block_len++] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 decoder->reg[reg++] = data[1];
123 len -= 2;
124 data += 2;
Hans Verkuil7fd011f2008-10-13 07:30:15 -0300125 } while (len >= 2 && data[0] == reg && block_len < 32);
126 ret = i2c_master_send(client, block_data, block_len);
127 if (ret < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 break;
129 }
130 } else {
131 /* do some slow I2C emulation kind of thing */
132 while (len >= 2) {
133 reg = *data++;
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300134 ret = bt819_write(decoder, reg, *data++);
135 if (ret < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 break;
137 len -= 2;
138 }
139 }
140
141 return ret;
142}
143
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300144static inline int bt819_read(struct bt819 *decoder, u8 reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145{
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300146 struct i2c_client *client = v4l2_get_subdevdata(&decoder->sd);
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 return i2c_smbus_read_byte_data(client, reg);
149}
150
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300151static int bt819_init(struct v4l2_subdev *sd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 static unsigned char init[] = {
Hans Verkuil7fd011f2008-10-13 07:30:15 -0300154 /*0x1f, 0x00,*/ /* Reset */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 0x01, 0x59, /* 0x01 input format */
156 0x02, 0x00, /* 0x02 temporal decimation */
157 0x03, 0x12, /* 0x03 Cropping msb */
158 0x04, 0x16, /* 0x04 Vertical Delay, lsb */
159 0x05, 0xe0, /* 0x05 Vertical Active lsb */
160 0x06, 0x80, /* 0x06 Horizontal Delay lsb */
161 0x07, 0xd0, /* 0x07 Horizontal Active lsb */
162 0x08, 0x00, /* 0x08 Horizontal Scaling msb */
163 0x09, 0xf8, /* 0x09 Horizontal Scaling lsb */
164 0x0a, 0x00, /* 0x0a Brightness control */
165 0x0b, 0x30, /* 0x0b Miscellaneous control */
166 0x0c, 0xd8, /* 0x0c Luma Gain lsb */
167 0x0d, 0xfe, /* 0x0d Chroma Gain (U) lsb */
168 0x0e, 0xb4, /* 0x0e Chroma Gain (V) msb */
169 0x0f, 0x00, /* 0x0f Hue control */
170 0x12, 0x04, /* 0x12 Output Format */
171 0x13, 0x20, /* 0x13 Vertial Scaling msb 0x00
172 chroma comb OFF, line drop scaling, interlace scaling
173 BUG? Why does turning the chroma comb on fuck up color?
174 Bug in the bt819 stepping on my board?
175 */
176 0x14, 0x00, /* 0x14 Vertial Scaling lsb */
Mauro Carvalho Chehabd56410e2006-03-25 09:19:53 -0300177 0x16, 0x07, /* 0x16 Video Timing Polarity
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 ACTIVE=active low
Mauro Carvalho Chehabd56410e2006-03-25 09:19:53 -0300179 FIELD: high=odd,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 vreset=active high,
181 hreset=active high */
182 0x18, 0x68, /* 0x18 AGC Delay */
183 0x19, 0x5d, /* 0x19 Burst Gate Delay */
184 0x1a, 0x80, /* 0x1a ADC Interface */
185 };
186
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300187 struct bt819 *decoder = to_bt819(sd);
Hans Verkuil107063c2009-02-18 17:26:06 -0300188 struct timing *timing = &timing_data[(decoder->norm & V4L2_STD_525_60) ? 1 : 0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
190 init[0x03 * 2 - 1] =
Hans Verkuil7fd011f2008-10-13 07:30:15 -0300191 (((timing->vdelay >> 8) & 0x03) << 6) |
192 (((timing->vactive >> 8) & 0x03) << 4) |
193 (((timing->hdelay >> 8) & 0x03) << 2) |
194 ((timing->hactive >> 8) & 0x03);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 init[0x04 * 2 - 1] = timing->vdelay & 0xff;
196 init[0x05 * 2 - 1] = timing->vactive & 0xff;
197 init[0x06 * 2 - 1] = timing->hdelay & 0xff;
198 init[0x07 * 2 - 1] = timing->hactive & 0xff;
199 init[0x08 * 2 - 1] = timing->hscale >> 8;
200 init[0x09 * 2 - 1] = timing->hscale & 0xff;
201 /* 0x15 in array is address 0x19 */
Hans Verkuil107063c2009-02-18 17:26:06 -0300202 init[0x15 * 2 - 1] = (decoder->norm & V4L2_STD_625_50) ? 115 : 93; /* Chroma burst delay */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 /* reset */
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300204 bt819_write(decoder, 0x1f, 0x00);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 mdelay(1);
206
207 /* init */
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300208 return bt819_write_block(decoder, init, sizeof(init));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209}
210
211/* ----------------------------------------------------------------------- */
212
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300213static int bt819_status(struct v4l2_subdev *sd, u32 *pstatus, v4l2_std_id *pstd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214{
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300215 struct bt819 *decoder = to_bt819(sd);
216 int status = bt819_read(decoder, 0x00);
217 int res = V4L2_IN_ST_NO_SIGNAL;
218 v4l2_std_id std;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300220 if ((status & 0x80))
221 res = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300223 if ((status & 0x10))
224 std = V4L2_STD_PAL;
225 else
226 std = V4L2_STD_NTSC;
227 if (pstd)
228 *pstd = std;
229 if (pstatus)
230 *pstatus = status;
231
232 v4l2_dbg(1, debug, sd, "get status %x\n", status);
233 return 0;
234}
235
236static int bt819_querystd(struct v4l2_subdev *sd, v4l2_std_id *std)
237{
238 return bt819_status(sd, NULL, std);
239}
240
241static int bt819_g_input_status(struct v4l2_subdev *sd, u32 *status)
242{
243 return bt819_status(sd, status, NULL);
244}
245
246static int bt819_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
247{
248 struct bt819 *decoder = to_bt819(sd);
249 struct timing *timing = NULL;
250
251 v4l2_dbg(1, debug, sd, "set norm %llx\n", std);
252
253 if (std & V4L2_STD_NTSC) {
254 bt819_setbit(decoder, 0x01, 0, 1);
255 bt819_setbit(decoder, 0x01, 1, 0);
256 bt819_setbit(decoder, 0x01, 5, 0);
257 bt819_write(decoder, 0x18, 0x68);
258 bt819_write(decoder, 0x19, 0x5d);
259 /* bt819_setbit(decoder, 0x1a, 5, 1); */
260 timing = &timing_data[1];
261 } else if (std & V4L2_STD_PAL) {
262 bt819_setbit(decoder, 0x01, 0, 1);
263 bt819_setbit(decoder, 0x01, 1, 1);
264 bt819_setbit(decoder, 0x01, 5, 1);
265 bt819_write(decoder, 0x18, 0x7f);
266 bt819_write(decoder, 0x19, 0x72);
267 /* bt819_setbit(decoder, 0x1a, 5, 0); */
268 timing = &timing_data[0];
269 } else {
270 v4l2_dbg(1, debug, sd, "unsupported norm %llx\n", std);
271 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 }
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300273 bt819_write(decoder, 0x03,
274 (((timing->vdelay >> 8) & 0x03) << 6) |
275 (((timing->vactive >> 8) & 0x03) << 4) |
276 (((timing->hdelay >> 8) & 0x03) << 2) |
277 ((timing->hactive >> 8) & 0x03));
278 bt819_write(decoder, 0x04, timing->vdelay & 0xff);
279 bt819_write(decoder, 0x05, timing->vactive & 0xff);
280 bt819_write(decoder, 0x06, timing->hdelay & 0xff);
281 bt819_write(decoder, 0x07, timing->hactive & 0xff);
282 bt819_write(decoder, 0x08, (timing->hscale >> 8) & 0xff);
283 bt819_write(decoder, 0x09, timing->hscale & 0xff);
284 decoder->norm = std;
285 return 0;
286}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300288static int bt819_s_routing(struct v4l2_subdev *sd, const struct v4l2_routing *route)
289{
290 struct bt819 *decoder = to_bt819(sd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300292 v4l2_dbg(1, debug, sd, "set input %x\n", route->input);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300294 if (route->input < 0 || route->input > 7)
295 return -EINVAL;
Hans Verkuil7fd011f2008-10-13 07:30:15 -0300296
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300297 if (decoder->input != route->input) {
298 decoder->input = route->input;
299 /* select mode */
300 if (decoder->input == 0) {
301 bt819_setbit(decoder, 0x0b, 6, 0);
302 bt819_setbit(decoder, 0x1a, 1, 1);
Hans Verkuil107063c2009-02-18 17:26:06 -0300303 } else {
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300304 bt819_setbit(decoder, 0x0b, 6, 1);
305 bt819_setbit(decoder, 0x1a, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 }
Hans Verkuil7fd011f2008-10-13 07:30:15 -0300307 }
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300308 return 0;
309}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300311static int bt819_s_stream(struct v4l2_subdev *sd, int enable)
312{
313 struct bt819 *decoder = to_bt819(sd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300315 v4l2_dbg(1, debug, sd, "enable output %x\n", enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300317 if (decoder->enable != enable) {
318 decoder->enable = enable;
319 bt819_setbit(decoder, 0x16, 7, !enable);
Hans Verkuil7fd011f2008-10-13 07:30:15 -0300320 }
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300321 return 0;
322}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300324static int bt819_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc)
325{
326 switch (qc->id) {
327 case V4L2_CID_BRIGHTNESS:
328 v4l2_ctrl_query_fill(qc, -128, 127, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 break;
330
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300331 case V4L2_CID_CONTRAST:
332 v4l2_ctrl_query_fill(qc, 0, 511, 1, 256);
Hans Verkuil107063c2009-02-18 17:26:06 -0300333 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300335 case V4L2_CID_SATURATION:
336 v4l2_ctrl_query_fill(qc, 0, 511, 1, 256);
Hans Verkuil107063c2009-02-18 17:26:06 -0300337 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300339 case V4L2_CID_HUE:
340 v4l2_ctrl_query_fill(qc, -128, 127, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 break;
342
343 default:
344 return -EINVAL;
345 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 return 0;
347}
348
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300349static int bt819_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
350{
351 struct bt819 *decoder = to_bt819(sd);
352 int temp;
353
354 switch (ctrl->id) {
355 case V4L2_CID_BRIGHTNESS:
356 if (decoder->bright == ctrl->value)
357 break;
358 decoder->bright = ctrl->value;
359 bt819_write(decoder, 0x0a, decoder->bright);
360 break;
361
362 case V4L2_CID_CONTRAST:
363 if (decoder->contrast == ctrl->value)
364 break;
365 decoder->contrast = ctrl->value;
366 bt819_write(decoder, 0x0c, decoder->contrast & 0xff);
367 bt819_setbit(decoder, 0x0b, 2, ((decoder->contrast >> 8) & 0x01));
368 break;
369
370 case V4L2_CID_SATURATION:
371 if (decoder->sat == ctrl->value)
372 break;
373 decoder->sat = ctrl->value;
374 bt819_write(decoder, 0x0d, (decoder->sat >> 7) & 0xff);
375 bt819_setbit(decoder, 0x0b, 1, ((decoder->sat >> 15) & 0x01));
376
377 /* Ratio between U gain and V gain must stay the same as
378 the ratio between the default U and V gain values. */
379 temp = (decoder->sat * 180) / 254;
380 bt819_write(decoder, 0x0e, (temp >> 7) & 0xff);
381 bt819_setbit(decoder, 0x0b, 0, (temp >> 15) & 0x01);
382 break;
383
384 case V4L2_CID_HUE:
385 if (decoder->hue == ctrl->value)
386 break;
387 decoder->hue = ctrl->value;
388 bt819_write(decoder, 0x0f, decoder->hue);
389 break;
390
391 default:
392 return -EINVAL;
393 }
394 return 0;
395}
396
397static int bt819_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
398{
399 struct bt819 *decoder = to_bt819(sd);
400
401 switch (ctrl->id) {
402 case V4L2_CID_BRIGHTNESS:
403 ctrl->value = decoder->bright;
404 break;
405 case V4L2_CID_CONTRAST:
406 ctrl->value = decoder->contrast;
407 break;
408 case V4L2_CID_SATURATION:
409 ctrl->value = decoder->sat;
410 break;
411 case V4L2_CID_HUE:
412 ctrl->value = decoder->hue;
413 break;
414 default:
415 return -EINVAL;
416 }
417 return 0;
418}
419
420static int bt819_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
421{
422 struct bt819 *decoder = to_bt819(sd);
423 struct i2c_client *client = v4l2_get_subdevdata(sd);
424
425 return v4l2_chip_ident_i2c_client(client, chip, decoder->ident, 0);
426}
427
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428/* ----------------------------------------------------------------------- */
429
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300430static const struct v4l2_subdev_core_ops bt819_core_ops = {
431 .g_chip_ident = bt819_g_chip_ident,
432 .g_ctrl = bt819_g_ctrl,
433 .s_ctrl = bt819_s_ctrl,
434 .queryctrl = bt819_queryctrl,
435};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300437static const struct v4l2_subdev_tuner_ops bt819_tuner_ops = {
438 .s_std = bt819_s_std,
439};
440
441static const struct v4l2_subdev_video_ops bt819_video_ops = {
442 .s_routing = bt819_s_routing,
443 .s_stream = bt819_s_stream,
444 .querystd = bt819_querystd,
445 .g_input_status = bt819_g_input_status,
446};
447
448static const struct v4l2_subdev_ops bt819_ops = {
449 .core = &bt819_core_ops,
450 .tuner = &bt819_tuner_ops,
451 .video = &bt819_video_ops,
452};
453
454/* ----------------------------------------------------------------------- */
Mauro Carvalho Chehabd56410e2006-03-25 09:19:53 -0300455
Hans Verkuil7fd011f2008-10-13 07:30:15 -0300456static int bt819_probe(struct i2c_client *client,
457 const struct i2c_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458{
Hans Verkuil7fd011f2008-10-13 07:30:15 -0300459 int i, ver;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 struct bt819 *decoder;
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300461 struct v4l2_subdev *sd;
Hans Verkuil7fd011f2008-10-13 07:30:15 -0300462 const char *name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
464 /* Check if the adapter supports the needed features */
Hans Verkuil7fd011f2008-10-13 07:30:15 -0300465 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
466 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300468 decoder = kzalloc(sizeof(struct bt819), GFP_KERNEL);
469 if (decoder == NULL)
470 return -ENOMEM;
471 sd = &decoder->sd;
472 v4l2_i2c_subdev_init(sd, client, &bt819_ops);
473
474 ver = bt819_read(decoder, 0x17);
Hans Verkuil7fd011f2008-10-13 07:30:15 -0300475 switch (ver & 0xf0) {
476 case 0x70:
477 name = "bt819a";
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300478 decoder->ident = V4L2_IDENT_BT819A;
Hans Verkuil7fd011f2008-10-13 07:30:15 -0300479 break;
480 case 0x60:
481 name = "bt817a";
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300482 decoder->ident = V4L2_IDENT_BT817A;
Hans Verkuil7fd011f2008-10-13 07:30:15 -0300483 break;
484 case 0x20:
485 name = "bt815a";
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300486 decoder->ident = V4L2_IDENT_BT815A;
Hans Verkuil7fd011f2008-10-13 07:30:15 -0300487 break;
488 default:
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300489 v4l2_dbg(1, debug, sd,
Hans Verkuil7fd011f2008-10-13 07:30:15 -0300490 "unknown chip version 0x%02x\n", ver);
491 return -ENODEV;
492 }
493
494 v4l_info(client, "%s found @ 0x%x (%s)\n", name,
495 client->addr << 1, client->adapter->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496
Hans Verkuil107063c2009-02-18 17:26:06 -0300497 decoder->norm = V4L2_STD_NTSC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 decoder->input = 0;
499 decoder->enable = 1;
Hans Verkuil107063c2009-02-18 17:26:06 -0300500 decoder->bright = 0;
501 decoder->contrast = 0xd8; /* 100% of original signal */
502 decoder->hue = 0;
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300503 decoder->sat = 0xfe; /* 100% of original signal */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300505 i = bt819_init(sd);
Hans Verkuil7fd011f2008-10-13 07:30:15 -0300506 if (i < 0)
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300507 v4l2_dbg(1, debug, sd, "init status %d\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 return 0;
509}
510
Hans Verkuil7fd011f2008-10-13 07:30:15 -0300511static int bt819_remove(struct i2c_client *client)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512{
Hans Verkuilc2179ad2009-02-19 06:36:36 -0300513 struct v4l2_subdev *sd = i2c_get_clientdata(client);
514
515 v4l2_device_unregister_subdev(sd);
516 kfree(to_bt819(sd));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 return 0;
518}
519
520/* ----------------------------------------------------------------------- */
521
Hans Verkuil7fd011f2008-10-13 07:30:15 -0300522static const struct i2c_device_id bt819_id[] = {
523 { "bt819a", 0 },
524 { "bt817a", 0 },
525 { "bt815a", 0 },
526 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527};
Hans Verkuil7fd011f2008-10-13 07:30:15 -0300528MODULE_DEVICE_TABLE(i2c, bt819_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529
Hans Verkuil7fd011f2008-10-13 07:30:15 -0300530static struct v4l2_i2c_driver_data v4l2_i2c_data = {
531 .name = "bt819",
Hans Verkuil7fd011f2008-10-13 07:30:15 -0300532 .probe = bt819_probe,
533 .remove = bt819_remove,
534 .id_table = bt819_id,
535};