31 #include <linux/kernel.h>
32 #include <linux/module.h>
33 #include <linux/slab.h>
34 #include <linux/i2c.h>
36 #include <linux/videodev2.h>
54 #define ADV7604_fsc (28636360)
56 #define DIGITAL_INPUT (state->mode == ADV7604_MODE_HDMI)
294 v4l_err(client,
"error reading %02x, %02x\n",
295 client->
addr, command);
299 static s32 adv_smbus_read_byte_data(
struct i2c_client *client,
u8 command)
301 return adv_smbus_read_byte_data_check(client, command,
true);
304 static s32 adv_smbus_write_byte_data(
struct i2c_client *client,
312 for (i = 0; i < 3; i++) {
321 v4l_err(client,
"error writing %02x, %02x, %02x\n",
322 client->
addr, command, value);
326 static s32 adv_smbus_write_i2c_block_data(
struct i2c_client *client,
344 struct i2c_client *client = v4l2_get_subdevdata(sd);
346 return adv_smbus_read_byte_data(client, reg);
351 struct i2c_client *client = v4l2_get_subdevdata(sd);
353 return adv_smbus_write_byte_data(client, reg, val);
358 return io_write(sd, reg, (io_read(sd, reg) & mask) | val);
361 static inline int avlink_read(
struct v4l2_subdev *sd,
u8 reg)
365 return adv_smbus_read_byte_data(state->
i2c_avlink, reg);
372 return adv_smbus_write_byte_data(state->
i2c_avlink, reg, val);
379 return adv_smbus_read_byte_data(state->
i2c_cec, reg);
386 return adv_smbus_write_byte_data(state->
i2c_cec, reg, val);
389 static inline int cec_write_and_or(
struct v4l2_subdev *sd,
u8 reg,
u8 mask,
u8 val)
391 return cec_write(sd, reg, (cec_read(sd, reg) & mask) | val);
394 static inline int infoframe_read(
struct v4l2_subdev *sd,
u8 reg)
401 static inline int infoframe_write(
struct v4l2_subdev *sd,
u8 reg,
u8 val)
405 return adv_smbus_write_byte_data(state->
i2c_infoframe, reg, val);
412 return adv_smbus_read_byte_data(state->
i2c_esdp, reg);
419 return adv_smbus_write_byte_data(state->
i2c_esdp, reg, val);
426 return adv_smbus_read_byte_data(state->
i2c_dpp, reg);
433 return adv_smbus_write_byte_data(state->
i2c_dpp, reg, val);
440 return adv_smbus_read_byte_data(state->
i2c_afe, reg);
447 return adv_smbus_write_byte_data(state->
i2c_afe, reg, val);
454 return adv_smbus_read_byte_data(state->
i2c_repeater, reg);
461 return adv_smbus_write_byte_data(state->
i2c_repeater, reg, val);
464 static inline int rep_write_and_or(
struct v4l2_subdev *sd,
u8 reg,
u8 mask,
u8 val)
466 return rep_write(sd, reg, (rep_read(sd, reg) & mask) | val);
473 return adv_smbus_read_byte_data(state->
i2c_edid, reg);
480 return adv_smbus_write_byte_data(state->
i2c_edid, reg, val);
483 static inline int edid_read_block(
struct v4l2_subdev *sd,
unsigned len,
u8 *val)
487 u8 msgbuf0[1] = { 0 };
495 memcpy(val, msgbuf1, len);
499 static void adv7604_delayed_work_enable_hotplug(
struct work_struct *
work)
511 static inline int edid_write_block(
struct v4l2_subdev *sd,
512 unsigned len,
const u8 *val)
514 struct i2c_client *client = v4l2_get_subdevdata(sd);
519 v4l2_dbg(2,
debug, sd,
"%s: write EDID block (%d byte)\n", __func__, len);
524 rep_write_and_or(sd, 0x77, 0xf0, 0x0);
527 err = adv_smbus_write_i2c_block_data(state->
i2c_edid, i,
534 rep_write_and_or(sd, 0x77, 0xf0, 0x1);
536 for (i = 0; i < 1000; i++) {
537 if (rep_read(sd, 0x7d) & 1)
542 v4l_err(client,
"error enabling edid\n");
556 return adv_smbus_read_byte_data(state->
i2c_hdmi, reg);
563 return adv_smbus_write_byte_data(state->
i2c_hdmi, reg, val);
570 return adv_smbus_read_byte_data(state->
i2c_test, reg);
577 return adv_smbus_write_byte_data(state->
i2c_test, reg, val);
584 return adv_smbus_read_byte_data(state->
i2c_cp, reg);
591 return adv_smbus_write_byte_data(state->
i2c_cp, reg, val);
594 static inline int cp_write_and_or(
struct v4l2_subdev *sd,
u8 reg,
u8 mask,
u8 val)
596 return cp_write(sd, reg, (cp_read(sd, reg) & mask) | val);
603 return adv_smbus_read_byte_data(state->
i2c_vdp, reg);
610 return adv_smbus_write_byte_data(state->
i2c_vdp, reg, val);
615 #ifdef CONFIG_VIDEO_ADV_DEBUG
616 static void adv7604_inv_register(
struct v4l2_subdev *sd)
619 v4l2_info(sd,
"0x100-0x1ff: AVLink Map\n");
621 v4l2_info(sd,
"0x300-0x3ff: InfoFrame Map\n");
622 v4l2_info(sd,
"0x400-0x4ff: ESDP Map\n");
625 v4l2_info(sd,
"0x700-0x7ff: Repeater Map\n");
626 v4l2_info(sd,
"0x800-0x8ff: EDID Map\n");
627 v4l2_info(sd,
"0x900-0x9ff: HDMI Map\n");
628 v4l2_info(sd,
"0xa00-0xaff: Test Map\n");
633 static int adv7604_g_register(
struct v4l2_subdev *sd,
636 struct i2c_client *client = v4l2_get_subdevdata(sd);
643 switch (reg->
reg >> 8) {
645 reg->
val = io_read(sd, reg->
reg & 0xff);
648 reg->
val = avlink_read(sd, reg->
reg & 0xff);
651 reg->
val = cec_read(sd, reg->
reg & 0xff);
654 reg->
val = infoframe_read(sd, reg->
reg & 0xff);
657 reg->
val = esdp_read(sd, reg->
reg & 0xff);
660 reg->
val = dpp_read(sd, reg->
reg & 0xff);
663 reg->
val = afe_read(sd, reg->
reg & 0xff);
666 reg->
val = rep_read(sd, reg->
reg & 0xff);
669 reg->
val = edid_read(sd, reg->
reg & 0xff);
672 reg->
val = hdmi_read(sd, reg->
reg & 0xff);
675 reg->
val = test_read(sd, reg->
reg & 0xff);
678 reg->
val = cp_read(sd, reg->
reg & 0xff);
681 reg->
val = vdp_read(sd, reg->
reg & 0xff);
684 v4l2_info(sd,
"Register %03llx not supported\n", reg->
reg);
685 adv7604_inv_register(sd);
691 static int adv7604_s_register(
struct v4l2_subdev *sd,
694 struct i2c_client *client = v4l2_get_subdevdata(sd);
700 switch (reg->
reg >> 8) {
702 io_write(sd, reg->
reg & 0xff, reg->
val & 0xff);
705 avlink_write(sd, reg->
reg & 0xff, reg->
val & 0xff);
708 cec_write(sd, reg->
reg & 0xff, reg->
val & 0xff);
711 infoframe_write(sd, reg->
reg & 0xff, reg->
val & 0xff);
714 esdp_write(sd, reg->
reg & 0xff, reg->
val & 0xff);
717 dpp_write(sd, reg->
reg & 0xff, reg->
val & 0xff);
720 afe_write(sd, reg->
reg & 0xff, reg->
val & 0xff);
723 rep_write(sd, reg->
reg & 0xff, reg->
val & 0xff);
726 edid_write(sd, reg->
reg & 0xff, reg->
val & 0xff);
729 hdmi_write(sd, reg->
reg & 0xff, reg->
val & 0xff);
732 test_write(sd, reg->
reg & 0xff, reg->
val & 0xff);
735 cp_write(sd, reg->
reg & 0xff, reg->
val & 0xff);
738 vdp_write(sd, reg->
reg & 0xff, reg->
val & 0xff);
741 v4l2_info(sd,
"Register %03llx not supported\n", reg->
reg);
742 adv7604_inv_register(sd);
749 static int adv7604_s_detect_tx_5v_ctrl(
struct v4l2_subdev *sd)
755 ((io_read(sd, 0x6f) & 0x10) >> 4));
758 static int find_and_set_predefined_video_timings(
struct v4l2_subdev *sd,
766 for (i = 0; predef_vid_timings[
i].
timings.bt.width; i++) {
770 io_write(sd, 0x00, predef_vid_timings[i].vid_std);
771 io_write(sd, 0x01, (predef_vid_timings[i].v_freq << 4) +
779 static int configure_predefined_video_timings(
struct v4l2_subdev *sd,
788 io_write(sd, 0x16, 0x43);
789 io_write(sd, 0x17, 0x5a);
791 cp_write_and_or(sd, 0x81, 0xef, 0x00);
792 cp_write(sd, 0x8f, 0x00);
793 cp_write(sd, 0x90, 0x00);
794 cp_write(sd, 0xa2, 0x00);
795 cp_write(sd, 0xa3, 0x00);
796 cp_write(sd, 0xa4, 0x00);
797 cp_write(sd, 0xa5, 0x00);
798 cp_write(sd, 0xa6, 0x00);
799 cp_write(sd, 0xa7, 0x00);
800 cp_write(sd, 0xab, 0x00);
801 cp_write(sd, 0xac, 0x00);
803 switch (state->
mode) {
806 err = find_and_set_predefined_video_timings(sd,
807 0x01, adv7604_prim_mode_comp, timings);
809 err = find_and_set_predefined_video_timings(sd,
810 0x02, adv7604_prim_mode_gr, timings);
813 err = find_and_set_predefined_video_timings(sd,
814 0x05, adv7604_prim_mode_hdmi_comp, timings);
816 err = find_and_set_predefined_video_timings(sd,
817 0x06, adv7604_prim_mode_hdmi_gr, timings);
821 __func__, state->
mode);
830 static void configure_custom_video_timings(
struct v4l2_subdev *sd,
834 struct i2c_client *client = v4l2_get_subdevdata(sd);
844 0xc0 | ((width >> 8) & 0x1f),
850 switch (state->
mode) {
854 io_write(sd, 0x00, 0x07);
855 io_write(sd, 0x01, 0x02);
857 cp_write_and_or(sd, 0x81, 0xef, 0x10);
862 if (adv_smbus_write_i2c_block_data(client, 0x16, 2, pll)) {
863 v4l2_err(sd,
"writing to reg 0x16 and 0x17 failed\n");
868 cp_write(sd, 0xa2, (cp_start_sav >> 4) & 0xff);
869 cp_write(sd, 0xa3, ((cp_start_sav & 0x0f) << 4) |
870 ((cp_start_eav >> 8) & 0x0f));
871 cp_write(sd, 0xa4, cp_start_eav & 0xff);
874 cp_write(sd, 0xa5, (cp_start_vbi >> 4) & 0xff);
875 cp_write(sd, 0xa6, ((cp_start_vbi & 0xf) << 4) |
876 ((cp_end_vbi >> 8) & 0xf));
877 cp_write(sd, 0xa7, cp_end_vbi & 0xff);
882 io_write(sd, 0x00, 0x02);
883 io_write(sd, 0x01, 0x06);
887 __func__, state->
mode);
891 cp_write(sd, 0x8f, (ch1_fr_ll >> 8) & 0x7);
892 cp_write(sd, 0x90, ch1_fr_ll & 0xff);
893 cp_write(sd, 0xab, (height >> 4) & 0xff);
894 cp_write(sd, 0xac, (height & 0x0f) << 4);
897 static void set_rgb_quantization_range(
struct v4l2_subdev *sd)
911 io_write_and_or(sd, 0x02, 0x0f, 0x00);
915 io_write_and_or(sd, 0x02, 0x0f, 0x10);
919 io_write_and_or(sd, 0x02, 0x0f, 0xf0);
924 io_write_and_or(sd, 0x02, 0x0f, 0x00);
928 io_write_and_or(sd, 0x02, 0x0f, 0x10);
941 cp_write(sd, 0x3c, ctrl->
val);
944 cp_write(sd, 0x3a, ctrl->
val);
947 cp_write(sd, 0x3b, ctrl->
val);
950 cp_write(sd, 0x3d, ctrl->
val);
954 set_rgb_quantization_range(sd);
961 afe_write(sd, 0xc8, ctrl->
val);
966 cp_write_and_or(sd, 0xbf, ~0x04, (ctrl->
val << 2));
969 cp_write(sd, 0xc0, (ctrl->
val & 0xff0000) >> 16);
970 cp_write(sd, 0xc1, (ctrl->
val & 0x00ff00) >> 8);
971 cp_write(sd, 0xc2, (
u8)(ctrl->
val & 0x0000ff));
977 static int adv7604_g_chip_ident(
struct v4l2_subdev *sd,
980 struct i2c_client *client = v4l2_get_subdevdata(sd);
987 static inline bool no_power(
struct v4l2_subdev *sd)
990 return io_read(sd, 0x0c) & 0x24;
993 static inline bool no_signal_tmds(
struct v4l2_subdev *sd)
996 return !(io_read(sd, 0x6a) & 0x10);
999 static inline bool no_lock_tmds(
struct v4l2_subdev *sd)
1001 return (io_read(sd, 0x6a) & 0xe0) != 0xe0;
1004 static inline bool no_lock_sspd(
struct v4l2_subdev *sd)
1007 return ((cp_read(sd, 0xb5) & 0xd0) != 0xd0);
1010 static inline bool no_lock_stdi(
struct v4l2_subdev *sd)
1013 return !(cp_read(sd, 0xb1) & 0x80);
1016 static inline bool no_signal(
struct v4l2_subdev *sd)
1023 ret |= no_lock_stdi(sd);
1024 ret |= no_lock_sspd(sd);
1027 ret |= no_lock_tmds(sd);
1028 ret |= no_signal_tmds(sd);
1034 static inline bool no_lock_cp(
struct v4l2_subdev *sd)
1038 return io_read(sd, 0x12) & 0x01;
1051 v4l2_dbg(1,
debug, sd,
"%s: status = 0x%x\n", __func__, *status);
1058 static void adv7604_print_timings(
struct v4l2_subdev *sd,
1077 v4l2_info(sd,
" horizontal: fp = %d, %ssync = %d, bp = %d\n",
1081 v4l2_info(sd,
" vertical: fp = %d, %ssync = %d, bp = %d\n",
1085 v4l2_info(sd,
" pixelclock: %lld, flags: 0x%x, standards: 0x%x\n",
1096 static int stdi2dv_timings(
struct v4l2_subdev *sd,
1105 for (i = 0; adv7604_timings[
i].
bt.height; i++) {
1106 if (vtotal(&adv7604_timings[i].bt) != stdi->
lcf + 1)
1108 if (adv7604_timings[i].bt.vsync != stdi->
lcvs)
1111 pix_clk = hfreq * htotal(&adv7604_timings[i].bt);
1113 if ((pix_clk < adv7604_timings[i].bt.pixelclock + 1000000) &&
1114 (pix_clk > adv7604_timings[i].
bt.pixelclock - 1000000)) {
1115 *timings = adv7604_timings[
i];
1132 "%s: No format candidate found for lcvs = %d, lcf=%d, bl = %d, %chsync, %cvsync\n",
1133 __func__, stdi->
lcvs, stdi->
lcf, stdi->
bl,
1140 if (no_lock_stdi(sd) || no_lock_sspd(sd)) {
1141 v4l2_dbg(2,
debug, sd,
"%s: STDI and/or SSPD not locked\n", __func__);
1146 stdi->
bl = ((cp_read(sd, 0xb1) & 0x3f) << 8) | cp_read(sd, 0xb2);
1147 stdi->
lcf = ((cp_read(sd, 0xb3) & 0x7) << 8) | cp_read(sd, 0xb4);
1148 stdi->
lcvs = cp_read(sd, 0xb3) >> 3;
1152 if ((cp_read(sd, 0xb5) & 0x03) == 0x01) {
1153 stdi->
hs_pol = ((cp_read(sd, 0xb5) & 0x10) ?
1154 ((cp_read(sd, 0xb5) & 0x08) ?
'+' :
'-') :
'x');
1155 stdi->
vs_pol = ((cp_read(sd, 0xb5) & 0x40) ?
1156 ((cp_read(sd, 0xb5) & 0x20) ?
'+' :
'-') :
'x');
1162 if (no_lock_stdi(sd) || no_lock_sspd(sd)) {
1164 "%s: signal lost during readout of STDI/SSPD\n", __func__);
1168 if (stdi->
lcf < 239 || stdi->
bl < 8 || stdi->
bl == 0x3fff) {
1175 "%s: lcf (frame height - 1) = %d, bl = %d, lcvs (vsync) = %d, %chsync, %cvsync, %s\n",
1176 __func__, stdi->
lcf, stdi->
bl, stdi->
lcvs,
1178 stdi->
interlaced ?
"interlaced" :
"progressive");
1183 static int adv7604_enum_dv_timings(
struct v4l2_subdev *sd,
1193 static int adv7604_dv_timings_cap(
struct v4l2_subdev *sd,
1199 cap->
bt.max_width = 1920;
1200 cap->
bt.max_height = 1200;
1201 cap->
bt.min_pixelclock = 27000000;
1203 cap->
bt.max_pixelclock = 225000000;
1205 cap->
bt.max_pixelclock = 170000000;
1215 static void adv7604_fill_optional_dv_timings_fields(
struct v4l2_subdev *sd,
1221 for (i = 0; adv7604_timings[
i].
bt.width; i++) {
1224 *timings = adv7604_timings[
i];
1230 static int adv7604_query_dv_timings(
struct v4l2_subdev *sd,
1242 if (no_signal(sd)) {
1248 if (read_stdi(sd, &stdi)) {
1249 v4l2_dbg(1,
debug, sd,
"%s: STDI/SSPD not locked\n", __func__);
1258 bt->
width = (hdmi_read(sd, 0x07) & 0x0f) * 256 + hdmi_read(sd, 0x08);
1259 bt->
height = (hdmi_read(sd, 0x09) & 0x0f) * 256 + hdmi_read(sd, 0x0a);
1260 bt->
pixelclock = (hdmi_read(sd, 0x06) * 1000000) +
1261 ((hdmi_read(sd, 0x3b) & 0x30) >> 4) * 250000;
1262 bt->
hfrontporch = (hdmi_read(sd, 0x20) & 0x03) * 256 +
1263 hdmi_read(sd, 0x21);
1264 bt->
hsync = (hdmi_read(sd, 0x22) & 0x03) * 256 +
1265 hdmi_read(sd, 0x23);
1266 bt->
hbackporch = (hdmi_read(sd, 0x24) & 0x03) * 256 +
1267 hdmi_read(sd, 0x25);
1268 bt->
vfrontporch = ((hdmi_read(sd, 0x2a) & 0x1f) * 256 +
1269 hdmi_read(sd, 0x2b)) / 2;
1270 bt->
vsync = ((hdmi_read(sd, 0x2e) & 0x1f) * 256 +
1271 hdmi_read(sd, 0x2f)) / 2;
1272 bt->
vbackporch = ((hdmi_read(sd, 0x32) & 0x1f) * 256 +
1273 hdmi_read(sd, 0x33)) / 2;
1277 bt->
height += (hdmi_read(sd, 0x0b) & 0x0f) * 256 +
1278 hdmi_read(sd, 0x0c);
1280 hdmi_read(sd, 0x2d)) / 2;
1281 bt->
il_vsync = ((hdmi_read(sd, 0x30) & 0x1f) * 256 +
1282 hdmi_read(sd, 0x31)) / 2;
1283 bt->
vbackporch = ((hdmi_read(sd, 0x34) & 0x1f) * 256 +
1284 hdmi_read(sd, 0x35)) / 2;
1286 adv7604_fill_optional_dv_timings_fields(sd, timings);
1292 if (!stdi2dv_timings(sd, &stdi, timings))
1296 if (!stdi2dv_timings(sd, &stdi, timings))
1300 if (stdi2dv_timings(sd, &stdi, timings)) {
1314 cp_write_and_or(sd, 0
x86, 0xf9, 0x00);
1316 cp_write_and_or(sd, 0
x86, 0xf9, 0x04);
1318 cp_write_and_or(sd, 0
x86, 0xf9, 0x02);
1322 v4l2_dbg(1,
debug, sd,
"%s: format not supported\n", __func__);
1329 if (no_signal(sd)) {
1330 v4l2_dbg(1,
debug, sd,
"%s: signal lost during readout\n", __func__);
1343 adv7604_print_timings(sd, timings,
1344 "adv7604_query_dv_timings:",
true);
1349 static int adv7604_s_dv_timings(
struct v4l2_subdev *sd,
1368 adv7604_fill_optional_dv_timings_fields(sd, timings);
1372 cp_write(sd, 0x91, bt->
interlaced ? 0x50 : 0x10);
1375 err = configure_predefined_video_timings(sd, timings);
1379 configure_custom_video_timings(sd, bt);
1382 set_rgb_quantization_range(sd);
1386 adv7604_print_timings(sd, timings,
1387 "adv7604_s_dv_timings:",
true);
1391 static int adv7604_g_dv_timings(
struct v4l2_subdev *sd,
1404 switch (state->
mode) {
1408 io_write(sd, 0x15, 0xb0);
1412 hdmi_write(sd, 0x1a, 0x0a);
1413 hdmi_write(sd, 0x01, 0x00);
1414 io_write(sd, 0x15, 0xa0);
1418 __func__, state->
mode);
1426 io_write(sd, 0x15, 0xbe);
1427 hdmi_write(sd, 0x1a, 0x1a);
1428 hdmi_write(sd, 0x01, 0x78);
1435 switch (state->
mode) {
1440 hdmi_write(sd, 0x0d, 0x04);
1441 hdmi_write(sd, 0x3d, 0x00);
1442 hdmi_write(sd, 0x3e, 0x74);
1443 hdmi_write(sd, 0x4e, 0x3b);
1444 hdmi_write(sd, 0x57, 0x74);
1445 hdmi_write(sd, 0x58, 0x63);
1446 hdmi_write(sd, 0x8d, 0x18);
1447 hdmi_write(sd, 0x8e, 0x34);
1448 hdmi_write(sd, 0x93, 0x88);
1449 hdmi_write(sd, 0x94, 0x2e);
1450 hdmi_write(sd, 0x96, 0x00);
1452 afe_write(sd, 0x00, 0x08);
1453 afe_write(sd, 0x01, 0x06);
1454 afe_write(sd, 0xc8, 0x00);
1458 afe_write(sd, 0x12, 0x7b);
1459 afe_write(sd, 0x0c, 0x1f);
1460 cp_write(sd, 0x3e, 0x04);
1461 cp_write(sd, 0xc3, 0x39);
1462 cp_write(sd, 0x40, 0x5c);
1468 hdmi_write(sd, 0x0d, 0x84);
1469 hdmi_write(sd, 0x3d, 0x10);
1470 hdmi_write(sd, 0x3e, 0x39);
1471 hdmi_write(sd, 0x4e, 0x3b);
1472 hdmi_write(sd, 0x57, 0xb6);
1473 hdmi_write(sd, 0x58, 0x03);
1474 hdmi_write(sd, 0x8d, 0x18);
1475 hdmi_write(sd, 0x8e, 0x34);
1476 hdmi_write(sd, 0x93, 0x8b);
1477 hdmi_write(sd, 0x94, 0x2d);
1478 hdmi_write(sd, 0x96, 0x01);
1480 afe_write(sd, 0x00, 0xff);
1481 afe_write(sd, 0x01, 0xfe);
1482 afe_write(sd, 0xc8, 0x40);
1486 afe_write(sd, 0x12, 0xfb);
1487 afe_write(sd, 0x0c, 0x0d);
1488 cp_write(sd, 0x3e, 0x00);
1489 cp_write(sd, 0xc3, 0x39);
1490 cp_write(sd, 0x40, 0x80);
1495 __func__, state->
mode);
1500 static int adv7604_s_routing(
struct v4l2_subdev *sd,
1518 static int adv7604_enum_mbus_fmt(
struct v4l2_subdev *sd,
unsigned int index,
1528 static int adv7604_g_mbus_fmt(
struct v4l2_subdev *sd,
1529 struct v4l2_mbus_framefmt *
fmt)
1533 fmt->width = state->
timings.bt.width;
1534 fmt->height = state->
timings.bt.height;
1538 fmt->colorspace = (state->
timings.bt.height <= 576) ?
1544 static int adv7604_isr(
struct v4l2_subdev *sd,
u32 status,
bool *handled)
1547 u8 fmt_change, fmt_change_digital, tx_5v;
1550 fmt_change = io_read(sd, 0x43) & 0x98;
1552 io_write(sd, 0x44, fmt_change);
1553 fmt_change_digital =
DIGITAL_INPUT ? (io_read(sd, 0x6b) & 0xc0) : 0;
1554 if (fmt_change_digital)
1555 io_write(sd, 0x6c, fmt_change_digital);
1556 if (fmt_change || fmt_change_digital) {
1558 "%s: ADV7604_FMT_CHANGE, fmt_change = 0x%x, fmt_change_digital = 0x%x\n",
1559 __func__, fmt_change, fmt_change_digital);
1565 tx_5v = io_read(sd, 0x70) & 0x10;
1567 v4l2_dbg(1,
debug, sd,
"%s: tx_5v: 0x%x\n", __func__, tx_5v);
1568 io_write(sd, 0x71, tx_5v);
1569 adv7604_s_detect_tx_5v_ctrl(sd);
1576 static int adv7604_get_edid(
struct v4l2_subdev *sd,
struct v4l2_subdev_edid *
edid)
1582 if (edid->blocks == 0)
1586 if (edid->start_block + edid->blocks > state->
edid_blocks)
1587 edid->blocks = state->
edid_blocks - edid->start_block;
1590 memcpy(edid->edid + edid->start_block * 128,
1591 state->
edid + edid->start_block * 128,
1592 edid->blocks * 128);
1596 static int adv7604_set_edid(
struct v4l2_subdev *sd,
struct v4l2_subdev_edid *edid)
1603 if (edid->start_block != 0)
1605 if (edid->blocks == 0) {
1609 rep_write_and_or(sd, 0x77, 0xf0, 0x0);
1616 if (edid->blocks > 2)
1620 memcpy(state->
edid, edid->edid, 128 * edid->blocks);
1624 err = edid_write_block(sd, 128 * edid->blocks, state->
edid);
1626 v4l2_err(sd,
"error %d writing edid\n", err);
1632 static void print_avi_infoframe(
struct v4l2_subdev *sd)
1639 if (!(hdmi_read(sd, 0x05) & 0x80)) {
1640 v4l2_info(sd,
"receive DVI-D signal (AVI infoframe not supported)\n");
1643 if (!(io_read(sd, 0x60) & 0x01)) {
1644 v4l2_info(sd,
"AVI infoframe not received\n");
1648 if (io_read(sd, 0x83) & 0x01) {
1649 v4l2_info(sd,
"AVI infoframe checksum error has occurred earlier\n");
1650 io_write(sd, 0x85, 0x01);
1651 if (io_read(sd, 0x83) & 0x01) {
1652 v4l2_info(sd,
"AVI infoframe checksum error still present\n");
1653 io_write(sd, 0x85, 0x01);
1657 avi_len = infoframe_read(sd, 0xe2);
1658 avi_ver = infoframe_read(sd, 0xe1);
1659 v4l2_info(sd,
"AVI infoframe version %d (%d byte)\n",
1662 if (avi_ver != 0x02)
1665 for (i = 0; i < 14; i++)
1666 buf[i] = infoframe_read(sd, i);
1669 "\t%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
1670 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7],
1671 buf[8], buf[9], buf[10], buf[11], buf[12], buf[13]);
1674 static int adv7604_log_status(
struct v4l2_subdev *sd)
1679 u8 reg_io_0x02 = io_read(sd, 0x02);
1681 char *csc_coeff_sel_rb[16] = {
1682 "bypassed",
"YPbPr601 -> RGB",
"reserved",
"YPbPr709 -> RGB",
1683 "reserved",
"RGB -> YPbPr601",
"reserved",
"RGB -> YPbPr709",
1684 "reserved",
"YPbPr709 -> YPbPr601",
"YPbPr601 -> YPbPr709",
1685 "reserved",
"reserved",
"reserved",
"reserved",
"manual"
1687 char *input_color_space_txt[16] = {
1688 "RGB limited range (16-235)",
"RGB full range (0-255)",
1689 "YCbCr Bt.601 (16-235)",
"YCbCr Bt.709 (16-235)",
1690 "XvYCC Bt.601",
"XvYCC Bt.709",
1691 "YCbCr Bt.601 (0-255)",
"YCbCr Bt.709 (0-255)",
1692 "invalid",
"invalid",
"invalid",
"invalid",
"invalid",
1693 "invalid",
"invalid",
"automatic"
1695 char *rgb_quantization_range_txt[] = {
1697 "RGB limited range (16-235)",
1698 "RGB full range (0-255)",
1701 v4l2_info(sd,
"-----Chip status-----\n");
1702 v4l2_info(sd,
"Chip power: %s\n", no_power(sd) ?
"off" :
"on");
1705 v4l2_info(sd,
"EDID: %s\n", ((rep_read(sd, 0x7d) & 0x01) &&
1706 (rep_read(sd, 0x77) & 0x01)) ?
"enabled" :
"disabled ");
1707 v4l2_info(sd,
"CEC: %s\n", !!(cec_read(sd, 0x2a) & 0x01) ?
1708 "enabled" :
"disabled");
1710 v4l2_info(sd,
"-----Signal status-----\n");
1711 v4l2_info(sd,
"Cable detected (+5V power): %s\n",
1712 (io_read(sd, 0x6f) & 0x10) ?
"true" :
"false");
1713 v4l2_info(sd,
"TMDS signal detected: %s\n",
1714 no_signal_tmds(sd) ?
"false" :
"true");
1715 v4l2_info(sd,
"TMDS signal locked: %s\n",
1716 no_lock_tmds(sd) ?
"false" :
"true");
1717 v4l2_info(sd,
"SSPD locked: %s\n", no_lock_sspd(sd) ?
"false" :
"true");
1718 v4l2_info(sd,
"STDI locked: %s\n", no_lock_stdi(sd) ?
"false" :
"true");
1719 v4l2_info(sd,
"CP locked: %s\n", no_lock_cp(sd) ?
"false" :
"true");
1721 (!!(cp_read(sd, 0xff) & 0x10) ?
"on" :
"off"));
1722 v4l2_info(sd,
"Prim-mode = 0x%x, video std = 0x%x, v_freq = 0x%x\n",
1723 io_read(sd, 0x01) & 0x0f, io_read(sd, 0x00) & 0x3f,
1724 (io_read(sd, 0x01) & 0x70) >> 4);
1726 v4l2_info(sd,
"-----Video Timings-----\n");
1727 if (read_stdi(sd, &stdi))
1730 v4l2_info(sd,
"STDI: lcf (frame height - 1) = %d, bl = %d, lcvs (vsync) = %d, %s, %chsync, %cvsync\n",
1732 stdi.
interlaced ?
"interlaced" :
"progressive",
1734 if (adv7604_query_dv_timings(sd, &timings))
1737 adv7604_print_timings(sd, &timings,
"Detected format:",
true);
1738 adv7604_print_timings(sd, &state->
timings,
"Configured format:",
true);
1740 v4l2_info(sd,
"-----Color space-----\n");
1741 v4l2_info(sd,
"RGB quantization range ctrl: %s\n",
1743 v4l2_info(sd,
"Input color space: %s\n",
1744 input_color_space_txt[reg_io_0x02 >> 4]);
1745 v4l2_info(sd,
"Output color space: %s %s, saturator %s\n",
1746 (reg_io_0x02 & 0x02) ?
"RGB" :
"YCbCr",
1747 (reg_io_0x02 & 0x04) ?
"(16-235)" :
"(0-255)",
1748 ((reg_io_0x02 & 0x04) ^ (reg_io_0x02 & 0x01)) ?
1749 "enabled" :
"disabled");
1750 v4l2_info(sd,
"Color space conversion: %s\n",
1751 csc_coeff_sel_rb[cp_read(sd, 0xfc) >> 4]);
1755 v4l2_info(sd,
"-----HDMI status-----\n");
1756 v4l2_info(sd,
"HDCP encrypted content: %s\n",
1757 hdmi_read(sd, 0x05) & 0x40 ?
"true" :
"false");
1759 print_avi_infoframe(sd);
1768 .s_ctrl = adv7604_s_ctrl,
1772 .log_status = adv7604_log_status,
1780 .g_chip_ident = adv7604_g_chip_ident,
1781 .interrupt_service_routine = adv7604_isr,
1782 #ifdef CONFIG_VIDEO_ADV_DEBUG
1783 .g_register = adv7604_g_register,
1784 .s_register = adv7604_s_register,
1789 .s_routing = adv7604_s_routing,
1790 .g_input_status = adv7604_g_input_status,
1791 .s_dv_timings = adv7604_s_dv_timings,
1792 .g_dv_timings = adv7604_g_dv_timings,
1793 .query_dv_timings = adv7604_query_dv_timings,
1794 .enum_dv_timings = adv7604_enum_dv_timings,
1795 .dv_timings_cap = adv7604_dv_timings_cap,
1796 .enum_mbus_fmt = adv7604_enum_mbus_fmt,
1797 .g_mbus_fmt = adv7604_g_mbus_fmt,
1798 .try_mbus_fmt = adv7604_g_mbus_fmt,
1799 .s_mbus_fmt = adv7604_g_mbus_fmt,
1803 .get_edid = adv7604_get_edid,
1804 .set_edid = adv7604_set_edid,
1808 .core = &adv7604_core_ops,
1809 .video = &adv7604_video_ops,
1810 .pad = &adv7604_pad_ops,
1815 static const struct v4l2_ctrl_config adv7604_ctrl_analog_sampling_phase = {
1816 .ops = &adv7604_ctrl_ops,
1818 .name =
"Analog Sampling Phase",
1826 static const struct v4l2_ctrl_config adv7604_ctrl_free_run_color_manual = {
1827 .ops = &adv7604_ctrl_ops,
1829 .name =
"Free Running Color, Manual",
1838 .ops = &adv7604_ctrl_ops,
1840 .name =
"Free Running Color",
1850 static int adv7604_core_init(
struct v4l2_subdev *sd)
1855 hdmi_write(sd, 0x48,
1862 io_write(sd, 0x0c, 0x42);
1863 io_write(sd, 0x0b, 0x44);
1864 cp_write(sd, 0xcf, 0x01);
1867 io_write_and_or(sd, 0x02, 0xf0,
1873 io_write_and_or(sd, 0x04, 0x1f, pdata->
op_ch_sel << 5);
1874 io_write_and_or(sd, 0x05, 0xf0, pdata->
blank_data << 3 |
1880 cp_write(sd, 0x69, 0x30);
1881 io_write(sd, 0x06, 0xa6);
1882 io_write(sd, 0x14, 0x7f);
1884 cp_write(sd, 0xf3, 0xdc);
1885 cp_write(sd, 0xf9, 0x23);
1887 cp_write(sd, 0x45, 0x23);
1889 cp_write(sd, 0xc9, 0x2d);
1893 afe_write(sd, 0xb5, 0x01);
1895 afe_write(sd, 0x02, pdata->
ain_sel);
1899 io_write(sd, 0x40, 0xc2);
1900 io_write(sd, 0x41, 0xd7);
1901 io_write(sd, 0x46, 0x98);
1902 io_write(sd, 0x6e, 0xc0);
1903 io_write(sd, 0x73, 0x10);
1908 static void adv7604_unregister_clients(
struct adv7604_state *state)
1939 struct i2c_client *client = v4l2_get_subdevdata(sd);
1942 io_write(sd, io_reg, addr << 1);
1946 static int adv7604_probe(
struct i2c_client *client,
1958 v4l_dbg(1,
debug, client,
"detecting adv7604 client on address 0x%x\n",
1963 v4l_err(client,
"Could not allocate adv7604_state memory!\n");
1969 v4l_err(client,
"No platform data!\n");
1981 if (adv_smbus_read_byte_data_check(client, 0xfb,
false) != 0x68) {
1982 v4l2_info(sd,
"not an adv7604 on address 0x%x\n",
2027 if (adv7604_s_detect_tx_5v_ctrl(sd)) {
2042 state->
i2c_cp = adv7604_dummy_client(sd, pdata->
i2c_cp, 0xfd);
2049 v4l2_err(sd,
"failed to create all i2c clients\n");
2057 v4l2_err(sd,
"Could not create work queue\n");
2063 adv7604_delayed_work_enable_hotplug);
2068 goto err_work_queues;
2070 err = adv7604_core_init(sd);
2083 adv7604_unregister_clients(state);
2093 static int adv7604_remove(
struct i2c_client *client)
2095 struct v4l2_subdev *sd = i2c_get_clientdata(client);
2102 adv7604_unregister_clients(to_state(sd));
2104 kfree(to_state(sd));
2121 .probe = adv7604_probe,
2122 .remove = adv7604_remove,
2123 .id_table = adv7604_id,