28 #include <linux/module.h>
30 #include <linux/types.h>
32 #include <linux/slab.h>
33 #include <linux/wait.h>
34 #include <asm/uaccess.h>
35 #include <linux/i2c.h>
36 #include <linux/videodev2.h>
50 #define SAA7110_MAX_INPUT 9
51 #define SAA7110_MAX_OUTPUT 1
53 #define SAA7110_NR_REG 0x35
84 struct saa7110 *decoder = to_saa7110(sd);
93 struct saa7110 *decoder = to_saa7110(sd);
107 memcpy(decoder->
reg + reg, data + 1, len - 1);
109 for (++data, --len; len; len--) {
110 ret = saa7110_write(sd, reg++, *data++);
119 static inline int saa7110_read(
struct v4l2_subdev *sd)
121 struct i2c_client *client = v4l2_get_subdevdata(sd);
130 #define FRESP_06H_COMPST 0x03
131 #define FRESP_06H_SVIDEO 0x83
136 static const unsigned char modes[9][8] = {
165 struct saa7110 *decoder = to_saa7110(sd);
166 const unsigned char *
ptr = modes[chan];
168 saa7110_write(sd, 0x06, ptr[0]);
169 saa7110_write(sd, 0x20, ptr[1]);
170 saa7110_write(sd, 0x21, ptr[2]);
171 saa7110_write(sd, 0x22, ptr[3]);
172 saa7110_write(sd, 0x2C, ptr[4]);
173 saa7110_write(sd, 0x30, ptr[5]);
174 saa7110_write(sd, 0x31, ptr[6]);
175 saa7110_write(sd, 0x21, ptr[7]);
176 decoder->
input = chan;
182 0, 0x4C, 0x3C, 0x0D, 0xEF, 0xBD, 0xF2, 0x03, 0x00,
183 0xF8, 0xF8, 0x60, 0x60, 0x00, 0x86, 0x18, 0x90,
184 0x00, 0x59, 0x40, 0x46, 0x42, 0x1A, 0xFF, 0xDA,
185 0xF2, 0x8B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
186 0xD9, 0x16, 0x40, 0x41, 0x80, 0x41, 0x80, 0x4F,
187 0xFE, 0x01, 0xCF, 0x0F, 0x03, 0x01, 0x03, 0x0C,
188 0x44, 0x71, 0x02, 0x8C, 0x02
194 struct saa7110 *decoder = to_saa7110(sd);
198 saa7110_write_block(sd, initseq,
sizeof(initseq));
199 saa7110_selmux(sd, decoder->
input);
203 status = saa7110_read(sd);
205 v4l2_dbg(1,
debug, sd,
"status=0x%02x (no signal)\n", status);
206 return decoder->
norm;
208 if ((status & 3) == 0) {
209 saa7110_write(sd, 0x06, 0x83);
211 v4l2_dbg(1,
debug, sd,
"status=0x%02x (NTSC/no color)\n", status);
215 v4l2_dbg(1,
debug, sd,
"status=0x%02x (PAL/no color)\n", status);
222 saa7110_write(sd, 0x0D, 0
x86);
223 saa7110_write(sd, 0x0F, 0x50);
224 saa7110_write(sd, 0x11, 0x2C);
230 saa7110_write(sd, 0x0D, 0
x86);
231 saa7110_write(sd, 0x0F, 0x10);
232 saa7110_write(sd, 0x11, 0x59);
239 status = saa7110_read(sd);
240 if ((status & 0x03) == 0x01) {
242 saa7110_write(sd, 0x0D, 0x87);
249 static int saa7110_g_input_status(
struct v4l2_subdev *sd,
u32 *pstatus)
251 struct saa7110 *decoder = to_saa7110(sd);
253 int status = saa7110_read(sd);
256 status, (
unsigned long long)decoder->
norm);
257 if (!(status & 0x40))
259 if (!(status & 0x03))
274 struct saa7110 *decoder = to_saa7110(sd);
276 if (decoder->
norm != std) {
280 saa7110_write(sd, 0x0D, 0
x86);
281 saa7110_write(sd, 0x0F, 0x50);
282 saa7110_write(sd, 0x11, 0x2C);
286 saa7110_write(sd, 0x0D, 0
x86);
287 saa7110_write(sd, 0x0F, 0x10);
288 saa7110_write(sd, 0x11, 0x59);
292 saa7110_write(sd, 0x0D, 0x87);
293 saa7110_write(sd, 0x0F, 0x10);
294 saa7110_write(sd, 0x11, 0x59);
304 static int saa7110_s_routing(
struct v4l2_subdev *sd,
307 struct saa7110 *decoder = to_saa7110(sd);
313 if (decoder->
input != input) {
314 saa7110_selmux(sd, input);
322 struct saa7110 *decoder = to_saa7110(sd);
324 if (decoder->
enable != enable) {
326 saa7110_write(sd, 0x0E, enable ? 0x18 : 0x80);
338 saa7110_write(sd, 0x19, ctrl->
val);
341 saa7110_write(sd, 0x13, ctrl->
val);
344 saa7110_write(sd, 0x12, ctrl->
val);
347 saa7110_write(sd, 0x07, ctrl->
val);
357 struct i2c_client *client = v4l2_get_subdevdata(sd);
365 .s_ctrl = saa7110_s_ctrl,
369 .g_chip_ident = saa7110_g_chip_ident,
377 .s_std = saa7110_s_std,
381 .s_routing = saa7110_s_routing,
382 .s_stream = saa7110_s_stream,
383 .querystd = saa7110_querystd,
384 .g_input_status = saa7110_g_input_status,
388 .core = &saa7110_core_ops,
389 .video = &saa7110_video_ops,
394 static int saa7110_probe(
struct i2c_client *client,
402 if (!i2c_check_functionality(client->
adapter,
406 v4l_info(client,
"chip found @ 0x%x (%s)\n",
427 if (decoder->
hdl.error) {
428 int err = decoder->
hdl.error;
438 rv = saa7110_write_block(sd, initseq,
sizeof(initseq));
443 saa7110_write(sd, 0x21, 0x10);
444 saa7110_write(sd, 0x0e, 0x18);
445 saa7110_write(sd, 0x0D, 0x04);
446 ver = saa7110_read(sd);
447 saa7110_write(sd, 0x0D, 0x06);
449 status = saa7110_read(sd);
452 saa7110_write(sd, 0x0D, 0
x86);
453 saa7110_write(sd, 0x0F, 0x10);
454 saa7110_write(sd, 0x11, 0x59);
465 static int saa7110_remove(
struct i2c_client *client)
467 struct v4l2_subdev *sd = i2c_get_clientdata(client);
468 struct saa7110 *decoder = to_saa7110(sd);
489 .probe = saa7110_probe,
490 .remove = saa7110_remove,
491 .id_table = saa7110_id,