21 #include <linux/module.h>
24 #include <linux/types.h>
25 #include <linux/slab.h>
26 #include <asm/uaccess.h>
27 #include <linux/i2c.h>
28 #include <linux/videodev2.h>
42 #define VPX_TIMEOUT_COUNT 10
49 unsigned char reg[255];
67 static char *inputs[] = {
"internal",
"composite",
"svideo" };
74 struct vpx3220 *decoder = i2c_get_clientdata(client);
93 status = vpx3220_read(sd, 0x29);
117 if (vpx3220_fp_status(sd) < 0)
131 struct i2c_client *client = v4l2_get_subdevdata(sd);
140 if (vpx3220_fp_status(sd) < 0)
153 static int vpx3220_write_block(
struct v4l2_subdev *sd,
const u8 *data,
unsigned int len)
160 ret = vpx3220_write(sd, reg, *data++);
169 static int vpx3220_write_fp_block(
struct v4l2_subdev *sd,
170 const u16 *data,
unsigned int len)
177 ret |= vpx3220_fp_write(sd, reg, *data++);
186 static const unsigned short init_ntsc[] = {
202 static const unsigned short init_pal[] = {
219 static const unsigned short init_secam[] = {
236 static const unsigned char init_common[] = {
266 static const unsigned short init_fp[] = {
282 struct vpx3220 *decoder = to_vpx3220(sd);
284 vpx3220_write_block(sd, init_common,
sizeof(init_common));
285 vpx3220_write_fp_block(sd, init_fp,
sizeof(init_fp) >> 1);
287 vpx3220_write_fp_block(sd, init_ntsc,
sizeof(init_ntsc) >> 1);
289 vpx3220_write_fp_block(sd, init_pal,
sizeof(init_pal) >> 1);
291 vpx3220_write_fp_block(sd, init_secam,
sizeof(init_secam) >> 1);
293 vpx3220_write_fp_block(sd, init_pal,
sizeof(init_pal) >> 1);
302 status = vpx3220_fp_read(sd, 0x0f3);
309 if ((status & 0x20) == 0) {
312 switch (status & 0x18) {
341 return vpx3220_status(sd,
NULL, std);
344 static int vpx3220_g_input_status(
struct v4l2_subdev *sd,
u32 *status)
347 return vpx3220_status(sd, status,
NULL);
352 struct vpx3220 *decoder = to_vpx3220(sd);
358 temp_input = vpx3220_fp_read(sd, 0xf2);
360 v4l2_dbg(1,
debug, sd,
"s_std %llx\n", (
unsigned long long)std);
362 vpx3220_write_fp_block(sd, init_ntsc,
sizeof(init_ntsc) >> 1);
365 vpx3220_write_fp_block(sd, init_pal,
sizeof(init_pal) >> 1);
368 vpx3220_write_fp_block(sd, init_secam,
sizeof(init_secam) >> 1);
377 vpx3220_fp_write(sd, 0xf2, temp_input | 0x0010);
382 static int vpx3220_s_routing(
struct v4l2_subdev *sd,
391 const int input_vals[3][2] = {
400 v4l2_dbg(1,
debug, sd,
"input switched to %s\n", inputs[input]);
402 vpx3220_write(sd, 0x33, input_vals[input][0]);
404 data = vpx3220_fp_read(sd, 0xf2) & ~(0x0020);
408 vpx3220_fp_write(sd, 0xf2,
409 data | (input_vals[input][1] << 5) | 0x0010);
417 v4l2_dbg(1,
debug, sd,
"s_stream %s\n", enable ?
"on" :
"off");
419 vpx3220_write(sd, 0xf2, (enable ? 0x1b : 0x00));
429 vpx3220_write(sd, 0xe6, ctrl->
val);
433 vpx3220_write(sd, 0xe7, ctrl->
val + 192);
436 vpx3220_fp_write(sd, 0xa0, ctrl->
val);
439 vpx3220_fp_write(sd, 0x1c, ctrl->
val);
447 struct vpx3220 *decoder = to_vpx3220(sd);
448 struct i2c_client *client = v4l2_get_subdevdata(sd);
456 .s_ctrl = vpx3220_s_ctrl,
460 .g_chip_ident = vpx3220_g_chip_ident,
461 .init = vpx3220_init,
469 .s_std = vpx3220_s_std,
473 .s_routing = vpx3220_s_routing,
474 .s_stream = vpx3220_s_stream,
475 .querystd = vpx3220_querystd,
476 .g_input_status = vpx3220_g_input_status,
480 .core = &vpx3220_core_ops,
481 .video = &vpx3220_video_ops,
488 static int vpx3220_probe(
struct i2c_client *client,
498 if (!i2c_check_functionality(client->
adapter,
520 if (decoder->
hdl.error) {
521 int err = decoder->
hdl.error;
549 v4l2_info(sd,
"%s found @ 0x%x (%s)\n", name,
552 v4l2_info(sd,
"chip (%02x:%04x) found @ 0x%x (%s)\n",
553 ver, pn, client->
addr << 1, client->
adapter->name);
555 vpx3220_write_block(sd, init_common,
sizeof(init_common));
556 vpx3220_write_fp_block(sd, init_fp,
sizeof(init_fp) >> 1);
558 vpx3220_write_fp_block(sd, init_pal,
sizeof(init_pal) >> 1);
562 static int vpx3220_remove(
struct i2c_client *client)
564 struct v4l2_subdev *sd = i2c_get_clientdata(client);
565 struct vpx3220 *decoder = to_vpx3220(sd);
586 .probe = vpx3220_probe,
587 .remove = vpx3220_remove,
588 .id_table = vpx3220_id,