28 #include <linux/i2c.h>
29 #include <linux/slab.h>
30 #include <linux/videodev2.h>
31 #include <linux/module.h>
45 #define TVP7002_MODULE_NAME "tvp7002"
48 #define I2C_RETRY_COUNT (5)
51 #define TVP7002_EOR 0x5c
54 #define TVP7002_READ 0
55 #define TVP7002_WRITE 1
56 #define TVP7002_RESERVED 2
59 #define TVP7002_IP_SHIFT 5
60 #define TVP7002_INPR_MASK (0x01 << TVP7002_IP_SHIFT)
63 #define TVP7002_CL_SHIFT 8
64 #define TVP7002_CL_MASK 0x0f
225 static const struct i2c_reg_value tvp7002_parms_1080I60[] = {
246 static const struct i2c_reg_value tvp7002_parms_1080P60[] = {
267 static const struct i2c_reg_value tvp7002_parms_1080I50[] = {
347 tvp7002_parms_720P60,
358 tvp7002_parms_1080I60,
369 tvp7002_parms_1080I50,
380 tvp7002_parms_720P50,
391 tvp7002_parms_1080P60,
423 #define NUM_PRESETS ARRAY_SIZE(tvp7002_presets)
477 v4l2_err(sd,
"TVP7002 read error %d\n", error);
495 *err = tvp7002_read(sd, reg, dst);
513 c = v4l2_get_subdevdata(sd);
521 v4l2_warn(sd,
"Write: retry ... %d\n", retry);
524 v4l2_err(sd,
"TVP7002 write error %d\n", error);
538 static inline void tvp7002_write_err(
struct v4l2_subdev *sd,
u8 reg,
542 *err = tvp7002_write(sd, reg, val);
553 static int tvp7002_g_chip_ident(
struct v4l2_subdev *sd,
576 static int tvp7002_write_inittab(
struct v4l2_subdev *sd,
584 tvp7002_write_err(sd, regs->
reg, regs->
value, &error);
599 static int tvp7002_s_dv_preset(
struct v4l2_subdev *sd,
607 preset = tvp7002_presets[
i].
preset;
608 if (preset == dv_preset->
preset) {
610 return tvp7002_write_inittab(sd, tvp7002_presets[i].p_settings);
617 static int tvp7002_s_dv_timings(
struct v4l2_subdev *sd,
620 struct tvp7002 *device = to_tvp7002(sd);
631 return tvp7002_write_inittab(sd, tvp7002_presets[i].p_settings);
637 static int tvp7002_g_dv_timings(
struct v4l2_subdev *sd,
640 struct tvp7002 *device = to_tvp7002(sd);
677 static int tvp7002_mbus_fmt(
struct v4l2_subdev *sd,
struct v4l2_mbus_framefmt *
f)
679 struct tvp7002 *device = to_tvp7002(sd);
688 f->width = e_preset.width;
689 f->height = e_preset.height;
695 f->width, f->height);
741 for (*index = 0; *index <
NUM_PRESETS; (*index)++, presets++)
744 if (presets->
cpl_min == 0xffff)
750 if (*index == NUM_PRESETS) {
751 v4l2_dbg(1,
debug, sd,
"detection failed: lpf = %x, cpl = %x\n",
761 static int tvp7002_query_dv_preset(
struct v4l2_subdev *sd,
765 int err = tvp7002_query_dv(sd, &index);
767 if (err || index == NUM_PRESETS) {
777 static int tvp7002_query_dv_timings(
struct v4l2_subdev *sd,
781 int err = tvp7002_query_dv(sd, &index);
789 #ifdef CONFIG_VIDEO_ADV_DEBUG
800 static int tvp7002_g_register(
struct v4l2_subdev *sd,
803 struct i2c_client *client = v4l2_get_subdevdata(sd);
812 ret = tvp7002_read(sd, reg->
reg & 0xff, &val);
826 static int tvp7002_s_register(
struct v4l2_subdev *sd,
829 struct i2c_client *client = v4l2_get_subdevdata(sd);
836 return tvp7002_write(sd, reg->
reg & 0xff, reg->
val & 0xff);
849 static int tvp7002_enum_mbus_fmt(
struct v4l2_subdev *sd,
unsigned index,
868 struct tvp7002 *device = to_tvp7002(sd);
897 static int tvp7002_log_status(
struct v4l2_subdev *sd)
900 struct tvp7002 *device = to_tvp7002(sd);
907 tvp7002_query_dv_preset(sd, &detected);
911 if (presets->
preset == detected.preset)
918 v4l2_info(sd,
" Pixels per line: %u\n", e_preset.width);
919 v4l2_info(sd,
" Lines per frame: %u\n\n", e_preset.height);
920 if (i == NUM_PRESETS) {
921 v4l2_info(sd,
"Detected DV Preset: None\n");
926 v4l2_info(sd,
" Pixels per line: %u\n", e_preset.width);
927 v4l2_info(sd,
" Lines per frame: %u\n\n", e_preset.height);
945 static int tvp7002_enum_dv_presets(
struct v4l2_subdev *sd,
949 if (preset->
index >= NUM_PRESETS)
955 static int tvp7002_enum_dv_timings(
struct v4l2_subdev *sd,
959 if (timings->
index >= NUM_PRESETS)
967 .s_ctrl = tvp7002_s_ctrl,
972 .g_chip_ident = tvp7002_g_chip_ident,
973 .log_status = tvp7002_log_status,
981 #ifdef CONFIG_VIDEO_ADV_DEBUG
982 .g_register = tvp7002_g_register,
983 .s_register = tvp7002_s_register,
989 .enum_dv_presets = tvp7002_enum_dv_presets,
990 .s_dv_preset = tvp7002_s_dv_preset,
991 .query_dv_preset = tvp7002_query_dv_preset,
992 .g_dv_timings = tvp7002_g_dv_timings,
993 .s_dv_timings = tvp7002_s_dv_timings,
994 .enum_dv_timings = tvp7002_enum_dv_timings,
995 .query_dv_timings = tvp7002_query_dv_timings,
996 .s_stream = tvp7002_s_stream,
997 .g_mbus_fmt = tvp7002_mbus_fmt,
998 .try_mbus_fmt = tvp7002_mbus_fmt,
999 .s_mbus_fmt = tvp7002_mbus_fmt,
1000 .enum_mbus_fmt = tvp7002_enum_mbus_fmt,
1005 .core = &tvp7002_core_ops,
1006 .video = &tvp7002_video_ops,
1030 if (!i2c_check_functionality(c->
adapter,
1034 if (!c->
dev.platform_data) {
1035 v4l_err(c,
"No platform data!!\n");
1045 device->
pdata = c->
dev.platform_data;
1050 v4l_info(c,
"tvp7002 found @ 0x%02x (%s)\n",
1058 v4l2_info(sd,
"Rev. %02x detected.\n", revision);
1059 if (revision != 0x02)
1060 v4l2_info(sd,
"Unknown revision detected.\n");
1063 error = tvp7002_write_inittab(sd, tvp7002_init_default);
1069 polarity_a = 0x20 | device->
pdata->hs_polarity << 5
1070 | device->
pdata->vs_polarity << 2;
1075 polarity_b = 0x01 | device->
pdata->fid_polarity << 2
1076 | device->
pdata->sog_polarity << 1
1077 | device->
pdata->clk_polarity;
1084 error = tvp7002_s_dv_preset(sd, &preset);
1090 if (device->
hdl.error) {
1091 int err = device->
hdl.error;
1113 static int tvp7002_remove(
struct i2c_client *c)
1116 struct tvp7002 *device = to_tvp7002(sd);
1119 "on address 0x%x\n", c->
addr);
1140 .probe = tvp7002_probe,
1141 .remove = tvp7002_remove,
1142 .id_table = tvp7002_id,