Commit | Line | Data |
---|---|---|
d56410e0 | 1 | /* |
1da177e4 LT |
2 | * 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> | |
d56410e0 | 9 | * |
1da177e4 LT |
10 | * 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> | |
18f3fa1e | 32 | #include <linux/types.h> |
7fd011fb | 33 | #include <linux/ioctl.h> |
2883913c | 34 | #include <linux/delay.h> |
18f3fa1e | 35 | #include <asm/uaccess.h> |
7fd011fb HV |
36 | #include <linux/i2c.h> |
37 | #include <linux/i2c-id.h> | |
c2179ad8 HV |
38 | #include <linux/videodev2.h> |
39 | #include <media/v4l2-device.h> | |
40 | #include <media/v4l2-chip-ident.h> | |
2d26698e | 41 | #include <media/v4l2-i2c-drv.h> |
1da177e4 LT |
42 | |
43 | MODULE_DESCRIPTION("Brooktree-819 video decoder driver"); | |
44 | MODULE_AUTHOR("Mike Bernson & Dave Perks"); | |
45 | MODULE_LICENSE("GPL"); | |
46 | ||
ff699e6b | 47 | static int debug; |
1da177e4 LT |
48 | module_param(debug, int, 0); |
49 | MODULE_PARM_DESC(debug, "Debug level (0-1)"); | |
50 | ||
c2179ad8 | 51 | |
1da177e4 LT |
52 | /* ----------------------------------------------------------------------- */ |
53 | ||
54 | struct bt819 { | |
c2179ad8 | 55 | struct v4l2_subdev sd; |
1da177e4 LT |
56 | unsigned char reg[32]; |
57 | ||
107063c6 | 58 | v4l2_std_id norm; |
c2179ad8 | 59 | int ident; |
1da177e4 LT |
60 | int input; |
61 | int enable; | |
62 | int bright; | |
63 | int contrast; | |
64 | int hue; | |
65 | int sat; | |
66 | }; | |
67 | ||
c2179ad8 HV |
68 | static inline struct bt819 *to_bt819(struct v4l2_subdev *sd) |
69 | { | |
70 | return container_of(sd, struct bt819, sd); | |
71 | } | |
72 | ||
1da177e4 LT |
73 | struct 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 */ | |
83 | static struct timing timing_data[] = { | |
84 | {864 - 24, 20, 625 - 2, 1, 0x0504, 0x0000}, | |
85 | {858 - 24, 20, 525 - 2, 1, 0x00f8, 0x0000}, | |
86 | }; | |
87 | ||
1da177e4 LT |
88 | /* ----------------------------------------------------------------------- */ |
89 | ||
c2179ad8 | 90 | static inline int bt819_write(struct bt819 *decoder, u8 reg, u8 value) |
1da177e4 | 91 | { |
c2179ad8 | 92 | struct i2c_client *client = v4l2_get_subdevdata(&decoder->sd); |
1da177e4 LT |
93 | |
94 | decoder->reg[reg] = value; | |
95 | return i2c_smbus_write_byte_data(client, reg, value); | |
96 | } | |
97 | ||
c2179ad8 | 98 | static inline int bt819_setbit(struct bt819 *decoder, u8 reg, u8 bit, u8 value) |
1da177e4 | 99 | { |
c2179ad8 | 100 | return bt819_write(decoder, reg, |
7fd011fb | 101 | (decoder->reg[reg] & ~(1 << bit)) | (value ? (1 << bit) : 0)); |
1da177e4 LT |
102 | } |
103 | ||
c2179ad8 | 104 | static int bt819_write_block(struct bt819 *decoder, const u8 *data, unsigned int len) |
1da177e4 | 105 | { |
c2179ad8 | 106 | struct i2c_client *client = v4l2_get_subdevdata(&decoder->sd); |
1da177e4 LT |
107 | 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 */ | |
1da177e4 | 114 | u8 block_data[32]; |
9aa45e34 | 115 | int block_len; |
1da177e4 | 116 | |
1da177e4 | 117 | while (len >= 2) { |
9aa45e34 JD |
118 | block_len = 0; |
119 | block_data[block_len++] = reg = data[0]; | |
1da177e4 | 120 | do { |
9aa45e34 | 121 | block_data[block_len++] = |
1da177e4 LT |
122 | decoder->reg[reg++] = data[1]; |
123 | len -= 2; | |
124 | data += 2; | |
7fd011fb HV |
125 | } while (len >= 2 && data[0] == reg && block_len < 32); |
126 | ret = i2c_master_send(client, block_data, block_len); | |
127 | if (ret < 0) | |
1da177e4 LT |
128 | break; |
129 | } | |
130 | } else { | |
131 | /* do some slow I2C emulation kind of thing */ | |
132 | while (len >= 2) { | |
133 | reg = *data++; | |
c2179ad8 HV |
134 | ret = bt819_write(decoder, reg, *data++); |
135 | if (ret < 0) | |
1da177e4 LT |
136 | break; |
137 | len -= 2; | |
138 | } | |
139 | } | |
140 | ||
141 | return ret; | |
142 | } | |
143 | ||
c2179ad8 | 144 | static inline int bt819_read(struct bt819 *decoder, u8 reg) |
1da177e4 | 145 | { |
c2179ad8 HV |
146 | struct i2c_client *client = v4l2_get_subdevdata(&decoder->sd); |
147 | ||
1da177e4 LT |
148 | return i2c_smbus_read_byte_data(client, reg); |
149 | } | |
150 | ||
c2179ad8 | 151 | static int bt819_init(struct v4l2_subdev *sd) |
1da177e4 | 152 | { |
1da177e4 | 153 | static unsigned char init[] = { |
7fd011fb | 154 | /*0x1f, 0x00,*/ /* Reset */ |
1da177e4 LT |
155 | 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 */ | |
d56410e0 | 177 | 0x16, 0x07, /* 0x16 Video Timing Polarity |
1da177e4 | 178 | ACTIVE=active low |
d56410e0 | 179 | FIELD: high=odd, |
1da177e4 LT |
180 | 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 | ||
c2179ad8 | 187 | struct bt819 *decoder = to_bt819(sd); |
107063c6 | 188 | struct timing *timing = &timing_data[(decoder->norm & V4L2_STD_525_60) ? 1 : 0]; |
1da177e4 LT |
189 | |
190 | init[0x03 * 2 - 1] = | |
7fd011fb HV |
191 | (((timing->vdelay >> 8) & 0x03) << 6) | |
192 | (((timing->vactive >> 8) & 0x03) << 4) | | |
193 | (((timing->hdelay >> 8) & 0x03) << 2) | | |
194 | ((timing->hactive >> 8) & 0x03); | |
1da177e4 LT |
195 | 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 */ | |
107063c6 | 202 | init[0x15 * 2 - 1] = (decoder->norm & V4L2_STD_625_50) ? 115 : 93; /* Chroma burst delay */ |
1da177e4 | 203 | /* reset */ |
c2179ad8 | 204 | bt819_write(decoder, 0x1f, 0x00); |
1da177e4 LT |
205 | mdelay(1); |
206 | ||
207 | /* init */ | |
c2179ad8 | 208 | return bt819_write_block(decoder, init, sizeof(init)); |
1da177e4 LT |
209 | } |
210 | ||
211 | /* ----------------------------------------------------------------------- */ | |
212 | ||
c2179ad8 | 213 | static int bt819_status(struct v4l2_subdev *sd, u32 *pstatus, v4l2_std_id *pstd) |
1da177e4 | 214 | { |
c2179ad8 HV |
215 | 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; | |
219 | ||
220 | if ((status & 0x80)) | |
221 | res = 0; | |
222 | ||
223 | 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 | } | |
1da177e4 | 235 | |
c2179ad8 HV |
236 | static int bt819_querystd(struct v4l2_subdev *sd, v4l2_std_id *std) |
237 | { | |
238 | return bt819_status(sd, NULL, std); | |
239 | } | |
1da177e4 | 240 | |
c2179ad8 HV |
241 | static int bt819_g_input_status(struct v4l2_subdev *sd, u32 *status) |
242 | { | |
243 | return bt819_status(sd, status, NULL); | |
244 | } | |
245 | ||
246 | static 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 | ||
cc5cef8e | 251 | v4l2_dbg(1, debug, sd, "set norm %llx\n", (unsigned long long)std); |
c2179ad8 HV |
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 { | |
cc5cef8e HV |
270 | v4l2_dbg(1, debug, sd, "unsupported norm %llx\n", |
271 | (unsigned long long)std); | |
c2179ad8 | 272 | return -EINVAL; |
1da177e4 | 273 | } |
c2179ad8 HV |
274 | bt819_write(decoder, 0x03, |
275 | (((timing->vdelay >> 8) & 0x03) << 6) | | |
276 | (((timing->vactive >> 8) & 0x03) << 4) | | |
277 | (((timing->hdelay >> 8) & 0x03) << 2) | | |
278 | ((timing->hactive >> 8) & 0x03)); | |
279 | bt819_write(decoder, 0x04, timing->vdelay & 0xff); | |
280 | bt819_write(decoder, 0x05, timing->vactive & 0xff); | |
281 | bt819_write(decoder, 0x06, timing->hdelay & 0xff); | |
282 | bt819_write(decoder, 0x07, timing->hactive & 0xff); | |
283 | bt819_write(decoder, 0x08, (timing->hscale >> 8) & 0xff); | |
284 | bt819_write(decoder, 0x09, timing->hscale & 0xff); | |
285 | decoder->norm = std; | |
286 | return 0; | |
287 | } | |
1da177e4 | 288 | |
c2179ad8 HV |
289 | static int bt819_s_routing(struct v4l2_subdev *sd, const struct v4l2_routing *route) |
290 | { | |
291 | struct bt819 *decoder = to_bt819(sd); | |
1da177e4 | 292 | |
c2179ad8 | 293 | v4l2_dbg(1, debug, sd, "set input %x\n", route->input); |
1da177e4 | 294 | |
c2179ad8 HV |
295 | if (route->input < 0 || route->input > 7) |
296 | return -EINVAL; | |
1da177e4 | 297 | |
c2179ad8 HV |
298 | if (decoder->input != route->input) { |
299 | decoder->input = route->input; | |
300 | /* select mode */ | |
301 | if (decoder->input == 0) { | |
302 | bt819_setbit(decoder, 0x0b, 6, 0); | |
303 | bt819_setbit(decoder, 0x1a, 1, 1); | |
304 | } else { | |
305 | bt819_setbit(decoder, 0x0b, 6, 1); | |
306 | bt819_setbit(decoder, 0x1a, 1, 0); | |
1da177e4 | 307 | } |
7fd011fb | 308 | } |
c2179ad8 HV |
309 | return 0; |
310 | } | |
1da177e4 | 311 | |
c2179ad8 HV |
312 | static int bt819_s_stream(struct v4l2_subdev *sd, int enable) |
313 | { | |
314 | struct bt819 *decoder = to_bt819(sd); | |
1da177e4 | 315 | |
c2179ad8 | 316 | v4l2_dbg(1, debug, sd, "enable output %x\n", enable); |
1da177e4 | 317 | |
c2179ad8 HV |
318 | if (decoder->enable != enable) { |
319 | decoder->enable = enable; | |
320 | bt819_setbit(decoder, 0x16, 7, !enable); | |
7fd011fb | 321 | } |
c2179ad8 HV |
322 | return 0; |
323 | } | |
1da177e4 | 324 | |
c2179ad8 HV |
325 | static int bt819_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc) |
326 | { | |
327 | switch (qc->id) { | |
328 | case V4L2_CID_BRIGHTNESS: | |
329 | v4l2_ctrl_query_fill(qc, -128, 127, 1, 0); | |
330 | break; | |
107063c6 | 331 | |
c2179ad8 HV |
332 | case V4L2_CID_CONTRAST: |
333 | v4l2_ctrl_query_fill(qc, 0, 511, 1, 256); | |
334 | break; | |
107063c6 | 335 | |
c2179ad8 HV |
336 | case V4L2_CID_SATURATION: |
337 | v4l2_ctrl_query_fill(qc, 0, 511, 1, 256); | |
338 | break; | |
107063c6 | 339 | |
c2179ad8 HV |
340 | case V4L2_CID_HUE: |
341 | v4l2_ctrl_query_fill(qc, -128, 127, 1, 0); | |
1da177e4 | 342 | break; |
c2179ad8 HV |
343 | |
344 | default: | |
345 | return -EINVAL; | |
7fd011fb | 346 | } |
c2179ad8 HV |
347 | return 0; |
348 | } | |
1da177e4 | 349 | |
c2179ad8 HV |
350 | static int bt819_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) |
351 | { | |
352 | struct bt819 *decoder = to_bt819(sd); | |
353 | int temp; | |
1da177e4 | 354 | |
c2179ad8 HV |
355 | switch (ctrl->id) { |
356 | case V4L2_CID_BRIGHTNESS: | |
357 | if (decoder->bright == ctrl->value) | |
107063c6 | 358 | break; |
c2179ad8 HV |
359 | decoder->bright = ctrl->value; |
360 | bt819_write(decoder, 0x0a, decoder->bright); | |
361 | break; | |
1da177e4 | 362 | |
c2179ad8 HV |
363 | case V4L2_CID_CONTRAST: |
364 | if (decoder->contrast == ctrl->value) | |
107063c6 | 365 | break; |
c2179ad8 HV |
366 | decoder->contrast = ctrl->value; |
367 | bt819_write(decoder, 0x0c, decoder->contrast & 0xff); | |
368 | bt819_setbit(decoder, 0x0b, 2, ((decoder->contrast >> 8) & 0x01)); | |
369 | break; | |
1da177e4 | 370 | |
c2179ad8 HV |
371 | case V4L2_CID_SATURATION: |
372 | if (decoder->sat == ctrl->value) | |
107063c6 | 373 | break; |
c2179ad8 HV |
374 | decoder->sat = ctrl->value; |
375 | bt819_write(decoder, 0x0d, (decoder->sat >> 7) & 0xff); | |
376 | bt819_setbit(decoder, 0x0b, 1, ((decoder->sat >> 15) & 0x01)); | |
377 | ||
378 | /* Ratio between U gain and V gain must stay the same as | |
379 | the ratio between the default U and V gain values. */ | |
380 | temp = (decoder->sat * 180) / 254; | |
381 | bt819_write(decoder, 0x0e, (temp >> 7) & 0xff); | |
382 | bt819_setbit(decoder, 0x0b, 0, (temp >> 15) & 0x01); | |
383 | break; | |
1da177e4 | 384 | |
c2179ad8 HV |
385 | case V4L2_CID_HUE: |
386 | if (decoder->hue == ctrl->value) | |
107063c6 | 387 | break; |
c2179ad8 HV |
388 | decoder->hue = ctrl->value; |
389 | bt819_write(decoder, 0x0f, decoder->hue); | |
107063c6 | 390 | break; |
c2179ad8 HV |
391 | |
392 | default: | |
393 | return -EINVAL; | |
107063c6 | 394 | } |
c2179ad8 HV |
395 | return 0; |
396 | } | |
1da177e4 | 397 | |
c2179ad8 HV |
398 | static int bt819_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) |
399 | { | |
400 | struct bt819 *decoder = to_bt819(sd); | |
1da177e4 | 401 | |
c2179ad8 HV |
402 | switch (ctrl->id) { |
403 | case V4L2_CID_BRIGHTNESS: | |
404 | ctrl->value = decoder->bright; | |
405 | break; | |
406 | case V4L2_CID_CONTRAST: | |
407 | ctrl->value = decoder->contrast; | |
408 | break; | |
409 | case V4L2_CID_SATURATION: | |
410 | ctrl->value = decoder->sat; | |
411 | break; | |
412 | case V4L2_CID_HUE: | |
413 | ctrl->value = decoder->hue; | |
1da177e4 | 414 | break; |
1da177e4 LT |
415 | default: |
416 | return -EINVAL; | |
417 | } | |
1da177e4 LT |
418 | return 0; |
419 | } | |
420 | ||
c2179ad8 HV |
421 | static int bt819_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip) |
422 | { | |
423 | struct bt819 *decoder = to_bt819(sd); | |
424 | struct i2c_client *client = v4l2_get_subdevdata(sd); | |
425 | ||
426 | return v4l2_chip_ident_i2c_client(client, chip, decoder->ident, 0); | |
427 | } | |
428 | ||
1da177e4 LT |
429 | /* ----------------------------------------------------------------------- */ |
430 | ||
c2179ad8 HV |
431 | static const struct v4l2_subdev_core_ops bt819_core_ops = { |
432 | .g_chip_ident = bt819_g_chip_ident, | |
433 | .g_ctrl = bt819_g_ctrl, | |
434 | .s_ctrl = bt819_s_ctrl, | |
435 | .queryctrl = bt819_queryctrl, | |
436 | }; | |
1da177e4 | 437 | |
c2179ad8 HV |
438 | static const struct v4l2_subdev_tuner_ops bt819_tuner_ops = { |
439 | .s_std = bt819_s_std, | |
440 | }; | |
441 | ||
442 | static const struct v4l2_subdev_video_ops bt819_video_ops = { | |
443 | .s_routing = bt819_s_routing, | |
444 | .s_stream = bt819_s_stream, | |
445 | .querystd = bt819_querystd, | |
446 | .g_input_status = bt819_g_input_status, | |
447 | }; | |
448 | ||
449 | static const struct v4l2_subdev_ops bt819_ops = { | |
450 | .core = &bt819_core_ops, | |
451 | .tuner = &bt819_tuner_ops, | |
452 | .video = &bt819_video_ops, | |
453 | }; | |
454 | ||
455 | /* ----------------------------------------------------------------------- */ | |
1da177e4 | 456 | |
7fd011fb HV |
457 | static int bt819_probe(struct i2c_client *client, |
458 | const struct i2c_device_id *id) | |
1da177e4 | 459 | { |
7fd011fb | 460 | int i, ver; |
1da177e4 | 461 | struct bt819 *decoder; |
c2179ad8 | 462 | struct v4l2_subdev *sd; |
7fd011fb | 463 | const char *name; |
1da177e4 LT |
464 | |
465 | /* Check if the adapter supports the needed features */ | |
7fd011fb HV |
466 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
467 | return -ENODEV; | |
1da177e4 | 468 | |
c2179ad8 HV |
469 | decoder = kzalloc(sizeof(struct bt819), GFP_KERNEL); |
470 | if (decoder == NULL) | |
471 | return -ENOMEM; | |
472 | sd = &decoder->sd; | |
473 | v4l2_i2c_subdev_init(sd, client, &bt819_ops); | |
474 | ||
475 | ver = bt819_read(decoder, 0x17); | |
7fd011fb HV |
476 | switch (ver & 0xf0) { |
477 | case 0x70: | |
478 | name = "bt819a"; | |
c2179ad8 | 479 | decoder->ident = V4L2_IDENT_BT819A; |
7fd011fb HV |
480 | break; |
481 | case 0x60: | |
482 | name = "bt817a"; | |
c2179ad8 | 483 | decoder->ident = V4L2_IDENT_BT817A; |
7fd011fb HV |
484 | break; |
485 | case 0x20: | |
486 | name = "bt815a"; | |
c2179ad8 | 487 | decoder->ident = V4L2_IDENT_BT815A; |
7fd011fb HV |
488 | break; |
489 | default: | |
c2179ad8 | 490 | v4l2_dbg(1, debug, sd, |
7fd011fb HV |
491 | "unknown chip version 0x%02x\n", ver); |
492 | return -ENODEV; | |
493 | } | |
494 | ||
495 | v4l_info(client, "%s found @ 0x%x (%s)\n", name, | |
496 | client->addr << 1, client->adapter->name); | |
1da177e4 | 497 | |
107063c6 | 498 | decoder->norm = V4L2_STD_NTSC; |
1da177e4 LT |
499 | decoder->input = 0; |
500 | decoder->enable = 1; | |
107063c6 HV |
501 | decoder->bright = 0; |
502 | decoder->contrast = 0xd8; /* 100% of original signal */ | |
503 | decoder->hue = 0; | |
c2179ad8 | 504 | decoder->sat = 0xfe; /* 100% of original signal */ |
1da177e4 | 505 | |
c2179ad8 | 506 | i = bt819_init(sd); |
7fd011fb | 507 | if (i < 0) |
c2179ad8 | 508 | v4l2_dbg(1, debug, sd, "init status %d\n", i); |
1da177e4 LT |
509 | return 0; |
510 | } | |
511 | ||
7fd011fb | 512 | static int bt819_remove(struct i2c_client *client) |
1da177e4 | 513 | { |
c2179ad8 HV |
514 | struct v4l2_subdev *sd = i2c_get_clientdata(client); |
515 | ||
516 | v4l2_device_unregister_subdev(sd); | |
517 | kfree(to_bt819(sd)); | |
1da177e4 LT |
518 | return 0; |
519 | } | |
520 | ||
521 | /* ----------------------------------------------------------------------- */ | |
522 | ||
7fd011fb HV |
523 | static const struct i2c_device_id bt819_id[] = { |
524 | { "bt819a", 0 }, | |
525 | { "bt817a", 0 }, | |
526 | { "bt815a", 0 }, | |
527 | { } | |
528 | }; | |
529 | MODULE_DEVICE_TABLE(i2c, bt819_id); | |
1da177e4 | 530 | |
7fd011fb HV |
531 | static struct v4l2_i2c_driver_data v4l2_i2c_data = { |
532 | .name = "bt819", | |
7fd011fb HV |
533 | .probe = bt819_probe, |
534 | .remove = bt819_remove, | |
535 | .id_table = bt819_id, | |
1da177e4 | 536 | }; |