31 #include <linux/module.h>
32 #include <linux/types.h>
35 #include <linux/i2c.h>
36 #include <linux/videodev2.h>
37 #include <linux/slab.h>
57 unsigned char reg[32];
85 static struct timing timing_data[] = {
86 {864 - 24, 20, 625 - 2, 1, 0x0504, 0x0000},
87 {858 - 24, 20, 525 - 2, 1, 0x00f8, 0x0000},
102 return bt819_write(decoder, reg,
103 (decoder->
reg[reg] & ~(1 << bit)) | (value ? (1 << bit) : 0));
106 static int bt819_write_block(
struct bt819 *decoder,
const u8 *
data,
unsigned int len)
121 block_data[block_len++] = reg = data[0];
123 block_data[block_len++] =
124 decoder->
reg[reg++] = data[1];
127 }
while (len >= 2 && data[0] == reg && block_len < 32);
136 ret = bt819_write(decoder, reg, *data++);
146 static inline int bt819_read(
struct bt819 *decoder,
u8 reg)
148 struct i2c_client *client = v4l2_get_subdevdata(&decoder->
sd);
155 static unsigned char init[] = {
189 struct bt819 *decoder = to_bt819(sd);
193 (((timing->
vdelay >> 8) & 0x03) << 6) |
194 (((timing->
vactive >> 8) & 0x03) << 4) |
195 (((timing->
hdelay >> 8) & 0x03) << 2) |
196 ((timing->
hactive >> 8) & 0x03);
197 init[0x04 * 2 - 1] = timing->
vdelay & 0xff;
198 init[0x05 * 2 - 1] = timing->
vactive & 0xff;
199 init[0x06 * 2 - 1] = timing->
hdelay & 0xff;
200 init[0x07 * 2 - 1] = timing->
hactive & 0xff;
201 init[0x08 * 2 - 1] = timing->
hscale >> 8;
202 init[0x09 * 2 - 1] = timing->
hscale & 0xff;
206 bt819_write(decoder, 0x1f, 0x00);
210 return bt819_write_block(decoder, init,
sizeof(init));
217 struct bt819 *decoder = to_bt819(sd);
218 int status = bt819_read(decoder, 0x00);
240 return bt819_status(sd,
NULL, std);
243 static int bt819_g_input_status(
struct v4l2_subdev *sd,
u32 *status)
245 return bt819_status(sd, status,
NULL);
250 struct bt819 *decoder = to_bt819(sd);
251 struct timing *timing =
NULL;
253 v4l2_dbg(1,
debug, sd,
"set norm %llx\n", (
unsigned long long)std);
260 bt819_setbit(decoder, 0x01, 0, 1);
261 bt819_setbit(decoder, 0x01, 1, 0);
262 bt819_setbit(decoder, 0x01, 5, 0);
263 bt819_write(decoder, 0x18, 0x68);
264 bt819_write(decoder, 0x19, 0x5d);
266 timing = &timing_data[1];
269 bt819_setbit(decoder, 0x01, 0, 1);
270 bt819_setbit(decoder, 0x01, 1, 1);
271 bt819_setbit(decoder, 0x01, 5, 1);
272 bt819_write(decoder, 0x18, 0x7f);
273 bt819_write(decoder, 0x19, 0x72);
275 timing = &timing_data[0];
278 (
unsigned long long)std);
281 bt819_write(decoder, 0x03,
282 (((timing->
vdelay >> 8) & 0x03) << 6) |
283 (((timing->
vactive >> 8) & 0x03) << 4) |
284 (((timing->
hdelay >> 8) & 0x03) << 2) |
285 ((timing->
hactive >> 8) & 0x03));
286 bt819_write(decoder, 0x04, timing->
vdelay & 0xff);
287 bt819_write(decoder, 0x05, timing->
vactive & 0xff);
288 bt819_write(decoder, 0x06, timing->
hdelay & 0xff);
289 bt819_write(decoder, 0x07, timing->
hactive & 0xff);
290 bt819_write(decoder, 0x08, (timing->
hscale >> 8) & 0xff);
291 bt819_write(decoder, 0x09, timing->
hscale & 0xff);
300 struct bt819 *decoder = to_bt819(sd);
310 if (decoder->
input != input) {
314 if (decoder->
input == 0) {
315 bt819_setbit(decoder, 0x0b, 6, 0);
316 bt819_setbit(decoder, 0x1a, 1, 1);
318 bt819_setbit(decoder, 0x0b, 6, 1);
319 bt819_setbit(decoder, 0x1a, 1, 0);
328 struct bt819 *decoder = to_bt819(sd);
332 if (decoder->
enable != enable) {
334 bt819_setbit(decoder, 0x16, 7, !enable);
342 struct bt819 *decoder = to_bt819(sd);
347 bt819_write(decoder, 0x0a, ctrl->
val);
351 bt819_write(decoder, 0x0c, ctrl->
val & 0xff);
352 bt819_setbit(decoder, 0x0b, 2, ((ctrl->
val >> 8) & 0x01));
356 bt819_write(decoder, 0x0d, (ctrl->
val >> 7) & 0xff);
357 bt819_setbit(decoder, 0x0b, 1, ((ctrl->
val >> 15) & 0x01));
361 temp = (ctrl->
val * 180) / 254;
362 bt819_write(decoder, 0x0e, (temp >> 7) & 0xff);
363 bt819_setbit(decoder, 0x0b, 0, (temp >> 15) & 0x01);
367 bt819_write(decoder, 0x0f, ctrl->
val);
378 struct bt819 *decoder = to_bt819(sd);
379 struct i2c_client *client = v4l2_get_subdevdata(sd);
387 .s_ctrl = bt819_s_ctrl,
391 .g_chip_ident = bt819_g_chip_ident,
399 .s_std = bt819_s_std,
403 .s_routing = bt819_s_routing,
404 .s_stream = bt819_s_stream,
405 .querystd = bt819_querystd,
406 .g_input_status = bt819_g_input_status,
410 .core = &bt819_core_ops,
411 .video = &bt819_video_ops,
416 static int bt819_probe(
struct i2c_client *client,
420 struct bt819 *decoder;
434 ver = bt819_read(decoder, 0x17);
435 switch (ver & 0xf0) {
450 "unknown chip version 0x%02x\n", ver);
454 v4l_info(client,
"%s found @ 0x%x (%s)\n", name,
475 if (decoder->
hdl.error) {
476 int err = decoder->
hdl.error;
486 static int bt819_remove(
struct i2c_client *client)
488 struct v4l2_subdev *sd = i2c_get_clientdata(client);
489 struct bt819 *decoder = to_bt819(sd);
512 .probe = bt819_probe,
513 .remove = bt819_remove,
514 .id_table = bt819_id,