31 #include <linux/i2c.h>
32 #include <linux/slab.h>
34 #include <linux/videodev2.h>
35 #include <linux/module.h>
47 #define TVP514X_MODULE_NAME "tvp514x"
50 #define I2C_RETRY_COUNT (5)
51 #define LOCK_RETRY_COUNT (5)
52 #define LOCK_RETRY_DELAY (200)
84 static struct tvp514x_reg tvp514x_reg_list_default[0x40];
118 static struct tvp514x_reg tvp514x_reg_list_default[] = {
218 .frameperiod = {1001, 30000},
231 .frameperiod = {1, 25},
267 v4l2_warn(sd,
"Read: retry ... %d\n", retry);
286 val = tvp514x_read_reg(sd, reg);
287 v4l2_info(sd,
"Reg(0x%.2X): 0x%.2X\n", reg, val);
302 struct i2c_client *client = v4l2_get_subdevdata(sd);
309 v4l2_warn(sd,
"Write: retry ... %d\n", retry);
331 static int tvp514x_write_regs(
struct v4l2_subdev *sd,
346 err = tvp514x_write_reg(sd, next->
reg, (
u8) next->
val);
348 v4l2_err(sd,
"Write failed. Err[%d]\n", err);
374 switch (std_status & VIDEO_STD_MASK) {
389 static void tvp514x_reg_dump(
struct v4l2_subdev *sd)
442 static int tvp514x_configure(
struct v4l2_subdev *sd,
454 tvp514x_reg_dump(sd);
473 u8 chip_id_msb, chip_id_lsb, rom_ver;
474 struct i2c_client *client = v4l2_get_subdevdata(sd);
481 "chip id detected msb:0x%x lsb:0x%x rom version:0x%x\n",
482 chip_id_msb, chip_id_lsb, rom_ver);
489 v4l2_err(sd,
"chip id mismatch msb:0x%x lsb:0x%x\n",
490 chip_id_msb, chip_id_lsb);
494 decoder->
ver = rom_ver;
496 v4l2_info(sd,
"%s (Version - 0x%.2x) found at 0x%x (%s)\n",
515 u8 sync_lock_status, lock_mask;
524 tvp514x_s_stream(sd, 1);
529 current_std = tvp514x_query_current_std(sd);
533 input_sel = decoder->
input;
571 sync_lock_status = tvp514x_read_reg(sd,
REG_STATUS1);
572 if (lock_mask != (sync_lock_status & lock_mask))
578 decoder->
std_list[current_std].standard.name);
595 for (i = 0; i < decoder->
num_stds; i++)
596 if (std_id & decoder->
std_list[i].standard.id)
612 decoder->
std_list[i].standard.name);
627 static int tvp514x_s_routing(
struct v4l2_subdev *sd,
647 output_sel |= tvp514x_read_reg(sd,
698 else if (value == -180)
700 err = tvp514x_write_reg(sd,
REG_HUE, value);
712 ctrl->
id, ctrl->
val);
743 tvp514x_mbus_fmt(
struct v4l2_subdev *sd,
struct v4l2_mbus_framefmt *
f)
760 v4l2_dbg(1,
debug, sd,
"MBUS_FMT: Width - %d, Height - %d\n",
761 f->width, f->height);
792 decoder->
std_list[current_std].standard.frameperiod;
825 decoder->
std_list[current_std].standard.frameperiod;
840 struct i2c_client *client = v4l2_get_subdevdata(sd);
852 v4l2_err(sd,
"Unable to turn off decoder\n");
861 client->
driver->id_table->driver_data;
864 err = tvp514x_write_regs(sd, int_seq);
866 v4l2_err(sd,
"Unable to turn on decoder\n");
870 err = tvp514x_detect(sd, decoder);
872 v4l2_err(sd,
"Unable to detect decoder\n");
875 err = tvp514x_configure(sd, decoder);
877 v4l2_err(sd,
"Unable to configure decoder\n");
903 .s_std = tvp514x_s_std,
908 .querystd = tvp514x_querystd,
909 .enum_mbus_fmt = tvp514x_enum_mbus_fmt,
910 .g_mbus_fmt = tvp514x_mbus_fmt,
911 .try_mbus_fmt = tvp514x_mbus_fmt,
912 .s_mbus_fmt = tvp514x_mbus_fmt,
913 .g_parm = tvp514x_g_parm,
914 .s_parm = tvp514x_s_parm,
915 .s_stream = tvp514x_s_stream,
919 .
core = &tvp514x_core_ops,
920 .video = &tvp514x_video_ops,
926 .std_list = tvp514x_std_list,
949 if (!client->
dev.platform_data) {
950 v4l2_err(client,
"No platform data!!\n");
954 decoder = kzalloc(
sizeof(*decoder),
GFP_KERNEL);
959 *decoder = tvp514x_dev;
962 sizeof(tvp514x_reg_list_default));
965 decoder->
pdata = client->
dev.platform_data;
973 (decoder->
pdata->clk_polarity << 1);
975 ((decoder->
pdata->hs_polarity << 2) |
976 (decoder->
pdata->vs_polarity << 3));
997 if (decoder->
hdl.error) {
998 int err = decoder->
hdl.error;
1006 v4l2_info(sd,
"%s decoder driver registered !!\n", sd->
name);
1019 static int tvp514x_remove(
struct i2c_client *client)
1021 struct v4l2_subdev *sd = i2c_get_clientdata(client);
1030 static const struct tvp514x_reg tvp5146_init_reg_seq[] = {
1046 static const struct tvp514x_reg tvp5147_init_reg_seq[] = {
1069 static const struct tvp514x_reg tvp514xm_init_reg_seq[] = {
1082 {
"tvp5146", (
unsigned long)tvp5146_init_reg_seq},
1083 {
"tvp5146m2", (
unsigned long)tvp514xm_init_reg_seq},
1084 {
"tvp5147", (
unsigned long)tvp5147_init_reg_seq},
1085 {
"tvp5147m1", (
unsigned long)tvp514xm_init_reg_seq},
1096 .probe = tvp514x_probe,
1097 .remove = tvp514x_remove,
1098 .id_table = tvp514x_id,