13 #include <linux/errno.h>
16 #include <linux/kernel.h>
18 #include <linux/module.h>
20 #include <linux/slab.h>
22 #include <linux/videodev2.h>
23 #include <linux/i2c.h>
29 #define SAA7191_MODULE_VERSION "0.0.5"
40 #define dprintk(x...) printk("SAA7191: " x);
45 #define SAA7191_SYNC_COUNT 30
46 #define SAA7191_SYNC_DELAY 100
64 static const u8 initseq[] = {
110 return to_saa7191(sd)->reg[
reg];
130 struct i2c_client *client = v4l2_get_subdevdata(sd);
137 static int saa7191_write_block(
struct v4l2_subdev *sd,
140 struct i2c_client *client = v4l2_get_subdevdata(sd);
141 struct saa7191 *decoder = to_saa7191(sd);
145 for (i = 0; i < (length - 1); i++) {
146 decoder->
reg[data[0] +
i] = data[i + 1];
161 static int saa7191_s_routing(
struct v4l2_subdev *sd,
164 struct saa7191 *decoder = to_saa7191(sd);
199 struct saa7191 *decoder = to_saa7191(sd);
234 dprintk(
"ctl3: %02x stdc: %02x chcv: %02x\n", ctl3,
245 dprintk(
"Checking for signal...\n");
248 if (saa7191_read_status(sd, status))
266 struct saa7191 *decoder = to_saa7191(sd);
273 dprintk(
"SAA7191 extended signal auto-detection...\n");
299 err = saa7191_wait_for_signal(sd, &status);
305 dprintk(
"60Hz signal: NTSC\n");
311 dprintk(
"50Hz signal: Trying PAL...\n");
314 err = saa7191_s_std(sd, V4L2_STD_PAL);
320 err = saa7191_wait_for_signal(sd, &status);
325 if (status & SAA7191_STATUS_FIDT) {
327 saa7191_s_std(sd, old_norm);
334 return saa7191_s_std(sd, old_norm);
337 dprintk(
"No color detected with PAL - Trying SECAM...\n");
340 err = saa7191_s_std(sd, V4L2_STD_SECAM);
346 err = saa7191_wait_for_signal(sd, &status);
351 if (status & SAA7191_STATUS_FIDT) {
357 if (status & SAA7191_STATUS_CODE) {
361 return saa7191_s_std(sd, old_norm);
364 dprintk(
"No color detected with SECAM - Going back to PAL.\n");
367 return saa7191_s_std(sd, old_norm);
370 static int saa7191_autodetect_norm(
struct v4l2_subdev *sd)
374 dprintk(
"SAA7191 signal auto-detection...\n");
376 dprintk(
"Reading status...\n");
378 if (saa7191_read_status(sd, &status))
381 dprintk(
"Checking for signal...\n");
391 if (status & SAA7191_STATUS_FIDT) {
394 return saa7191_s_std(sd, V4L2_STD_NTSC);
398 return saa7191_s_std(sd, V4L2_STD_PAL);
452 if (ctrl->
value >= 4)
503 reg &= ~SAA7191_GAIN_COLO;
505 reg &= ~SAA7191_GAIN_LFIS_MASK;
507 & SAA7191_GAIN_LFIS_MASK;
512 reg = ctrl->
value & 0xff;
554 static int saa7191_g_input_status(
struct v4l2_subdev *sd,
u32 *status)
559 if (saa7191_read_status(sd, &status_reg))
561 if ((status_reg & SAA7191_STATUS_HLCK) == 0)
563 if (!(status_reg & SAA7191_STATUS_CODE))
570 static int saa7191_g_chip_ident(
struct v4l2_subdev *sd,
573 struct i2c_client *client = v4l2_get_subdevdata(sd);
581 .g_chip_ident = saa7191_g_chip_ident,
582 .g_ctrl = saa7191_g_ctrl,
583 .s_ctrl = saa7191_s_ctrl,
584 .s_std = saa7191_s_std,
588 .s_routing = saa7191_s_routing,
589 .querystd = saa7191_querystd,
590 .g_input_status = saa7191_g_input_status,
594 .core = &saa7191_core_ops,
595 .video = &saa7191_video_ops,
598 static int saa7191_probe(
struct i2c_client *client,
605 v4l_info(client,
"chip found @ 0x%x (%s)\n",
608 decoder = kzalloc(
sizeof(*decoder),
GFP_KERNEL);
615 err = saa7191_write_block(sd,
sizeof(initseq), initseq);
627 err = saa7191_autodetect_norm(sd);
628 if (err && (err != -
EBUSY))
634 static int saa7191_remove(
struct i2c_client *client)
636 struct v4l2_subdev *sd = i2c_get_clientdata(client);
639 kfree(to_saa7191(sd));
654 .probe = saa7191_probe,
655 .remove = saa7191_remove,
656 .id_table = saa7191_id,