Lines Matching full:sd

90 	struct v4l2_subdev sd;  member
247 static inline struct adv7842_state *to_state(struct v4l2_subdev *sd) in to_state() argument
249 return container_of(sd, struct adv7842_state, sd); in to_state()
254 return &container_of(ctrl->handler, struct adv7842_state, hdl)->sd; in to_sd()
362 static inline int io_read(struct v4l2_subdev *sd, u8 reg) in io_read() argument
364 struct i2c_client *client = v4l2_get_subdevdata(sd); in io_read()
369 static inline int io_write(struct v4l2_subdev *sd, u8 reg, u8 val) in io_write() argument
371 struct i2c_client *client = v4l2_get_subdevdata(sd); in io_write()
376 static inline int io_write_and_or(struct v4l2_subdev *sd, u8 reg, u8 mask, u8 val) in io_write_and_or() argument
378 return io_write(sd, reg, (io_read(sd, reg) & mask) | val); in io_write_and_or()
381 static inline int io_write_clr_set(struct v4l2_subdev *sd, in io_write_clr_set() argument
384 return io_write(sd, reg, (io_read(sd, reg) & ~mask) | val); in io_write_clr_set()
387 static inline int avlink_read(struct v4l2_subdev *sd, u8 reg) in avlink_read() argument
389 struct adv7842_state *state = to_state(sd); in avlink_read()
394 static inline int avlink_write(struct v4l2_subdev *sd, u8 reg, u8 val) in avlink_write() argument
396 struct adv7842_state *state = to_state(sd); in avlink_write()
401 static inline int cec_read(struct v4l2_subdev *sd, u8 reg) in cec_read() argument
403 struct adv7842_state *state = to_state(sd); in cec_read()
408 static inline int cec_write(struct v4l2_subdev *sd, u8 reg, u8 val) in cec_write() argument
410 struct adv7842_state *state = to_state(sd); in cec_write()
415 static inline int cec_write_clr_set(struct v4l2_subdev *sd, u8 reg, u8 mask, u8 val) in cec_write_clr_set() argument
417 return cec_write(sd, reg, (cec_read(sd, reg) & ~mask) | val); in cec_write_clr_set()
420 static inline int infoframe_read(struct v4l2_subdev *sd, u8 reg) in infoframe_read() argument
422 struct adv7842_state *state = to_state(sd); in infoframe_read()
427 static inline int infoframe_write(struct v4l2_subdev *sd, u8 reg, u8 val) in infoframe_write() argument
429 struct adv7842_state *state = to_state(sd); in infoframe_write()
434 static inline int sdp_io_read(struct v4l2_subdev *sd, u8 reg) in sdp_io_read() argument
436 struct adv7842_state *state = to_state(sd); in sdp_io_read()
441 static inline int sdp_io_write(struct v4l2_subdev *sd, u8 reg, u8 val) in sdp_io_write() argument
443 struct adv7842_state *state = to_state(sd); in sdp_io_write()
448 static inline int sdp_io_write_and_or(struct v4l2_subdev *sd, u8 reg, u8 mask, u8 val) in sdp_io_write_and_or() argument
450 return sdp_io_write(sd, reg, (sdp_io_read(sd, reg) & mask) | val); in sdp_io_write_and_or()
453 static inline int sdp_read(struct v4l2_subdev *sd, u8 reg) in sdp_read() argument
455 struct adv7842_state *state = to_state(sd); in sdp_read()
460 static inline int sdp_write(struct v4l2_subdev *sd, u8 reg, u8 val) in sdp_write() argument
462 struct adv7842_state *state = to_state(sd); in sdp_write()
467 static inline int sdp_write_and_or(struct v4l2_subdev *sd, u8 reg, u8 mask, u8 val) in sdp_write_and_or() argument
469 return sdp_write(sd, reg, (sdp_read(sd, reg) & mask) | val); in sdp_write_and_or()
472 static inline int afe_read(struct v4l2_subdev *sd, u8 reg) in afe_read() argument
474 struct adv7842_state *state = to_state(sd); in afe_read()
479 static inline int afe_write(struct v4l2_subdev *sd, u8 reg, u8 val) in afe_write() argument
481 struct adv7842_state *state = to_state(sd); in afe_write()
486 static inline int afe_write_and_or(struct v4l2_subdev *sd, u8 reg, u8 mask, u8 val) in afe_write_and_or() argument
488 return afe_write(sd, reg, (afe_read(sd, reg) & mask) | val); in afe_write_and_or()
491 static inline int rep_read(struct v4l2_subdev *sd, u8 reg) in rep_read() argument
493 struct adv7842_state *state = to_state(sd); in rep_read()
498 static inline int rep_write(struct v4l2_subdev *sd, u8 reg, u8 val) in rep_write() argument
500 struct adv7842_state *state = to_state(sd); in rep_write()
505 static inline int rep_write_and_or(struct v4l2_subdev *sd, u8 reg, u8 mask, u8 val) in rep_write_and_or() argument
507 return rep_write(sd, reg, (rep_read(sd, reg) & mask) | val); in rep_write_and_or()
510 static inline int edid_read(struct v4l2_subdev *sd, u8 reg) in edid_read() argument
512 struct adv7842_state *state = to_state(sd); in edid_read()
517 static inline int edid_write(struct v4l2_subdev *sd, u8 reg, u8 val) in edid_write() argument
519 struct adv7842_state *state = to_state(sd); in edid_write()
524 static inline int hdmi_read(struct v4l2_subdev *sd, u8 reg) in hdmi_read() argument
526 struct adv7842_state *state = to_state(sd); in hdmi_read()
531 static inline int hdmi_write(struct v4l2_subdev *sd, u8 reg, u8 val) in hdmi_write() argument
533 struct adv7842_state *state = to_state(sd); in hdmi_write()
538 static inline int hdmi_write_and_or(struct v4l2_subdev *sd, u8 reg, u8 mask, u8 val) in hdmi_write_and_or() argument
540 return hdmi_write(sd, reg, (hdmi_read(sd, reg) & mask) | val); in hdmi_write_and_or()
543 static inline int cp_read(struct v4l2_subdev *sd, u8 reg) in cp_read() argument
545 struct adv7842_state *state = to_state(sd); in cp_read()
550 static inline int cp_write(struct v4l2_subdev *sd, u8 reg, u8 val) in cp_write() argument
552 struct adv7842_state *state = to_state(sd); in cp_write()
557 static inline int cp_write_and_or(struct v4l2_subdev *sd, u8 reg, u8 mask, u8 val) in cp_write_and_or() argument
559 return cp_write(sd, reg, (cp_read(sd, reg) & mask) | val); in cp_write_and_or()
562 static inline int vdp_read(struct v4l2_subdev *sd, u8 reg) in vdp_read() argument
564 struct adv7842_state *state = to_state(sd); in vdp_read()
569 static inline int vdp_write(struct v4l2_subdev *sd, u8 reg, u8 val) in vdp_write() argument
571 struct adv7842_state *state = to_state(sd); in vdp_write()
576 static void main_reset(struct v4l2_subdev *sd) in main_reset() argument
578 struct i2c_client *client = v4l2_get_subdevdata(sd); in main_reset()
580 v4l2_dbg(1, debug, sd, "%s:\n", __func__); in main_reset()
647 static inline bool is_analog_input(struct v4l2_subdev *sd) in is_analog_input() argument
649 struct adv7842_state *state = to_state(sd); in is_analog_input()
655 static inline bool is_digital_input(struct v4l2_subdev *sd) in is_digital_input() argument
657 struct adv7842_state *state = to_state(sd); in is_digital_input()
685 adv7842_get_dv_timings_cap(struct v4l2_subdev *sd) in adv7842_get_dv_timings_cap() argument
687 return is_digital_input(sd) ? &adv7842_timings_cap_digital : in adv7842_get_dv_timings_cap()
693 static u16 adv7842_read_cable_det(struct v4l2_subdev *sd) in adv7842_read_cable_det() argument
695 u8 reg = io_read(sd, 0x6f); in adv7842_read_cable_det()
710 struct v4l2_subdev *sd = &state->sd; in adv7842_delayed_work_enable_hotplug() local
714 v4l2_dbg(2, debug, sd, "%s: enable hotplug on ports: 0x%x\n", in adv7842_delayed_work_enable_hotplug()
721 io_write_and_or(sd, 0x20, 0xcf, mask); in adv7842_delayed_work_enable_hotplug()
724 static int edid_write_vga_segment(struct v4l2_subdev *sd) in edid_write_vga_segment() argument
726 struct i2c_client *client = v4l2_get_subdevdata(sd); in edid_write_vga_segment()
727 struct adv7842_state *state = to_state(sd); in edid_write_vga_segment()
732 v4l2_dbg(2, debug, sd, "%s: write EDID on VGA port\n", __func__); in edid_write_vga_segment()
735 io_write_and_or(sd, 0x20, 0xcf, 0x00); in edid_write_vga_segment()
738 rep_write_and_or(sd, 0x7f, 0x7f, 0x00); in edid_write_vga_segment()
741 rep_write_and_or(sd, 0x77, 0xef, 0x10); in edid_write_vga_segment()
752 rep_write_and_or(sd, 0x7f, 0x7f, 0x80); in edid_write_vga_segment()
755 if (rep_read(sd, 0x79) & 0x20) in edid_write_vga_segment()
770 static int edid_write_hdmi_segment(struct v4l2_subdev *sd, u8 port) in edid_write_hdmi_segment() argument
772 struct i2c_client *client = v4l2_get_subdevdata(sd); in edid_write_hdmi_segment()
773 struct adv7842_state *state = to_state(sd); in edid_write_hdmi_segment()
780 v4l2_dbg(2, debug, sd, "%s: write EDID on port %c\n", in edid_write_hdmi_segment()
784 io_write_and_or(sd, 0x20, 0xcf, 0x00); in edid_write_hdmi_segment()
787 rep_write_and_or(sd, 0x77, 0xf3, 0x00); in edid_write_hdmi_segment()
807 rep_write_and_or(sd, 0x77, 0xef, 0x00); in edid_write_hdmi_segment()
816 rep_write(sd, 0x72, edid[spa_loc]); in edid_write_hdmi_segment()
817 rep_write(sd, 0x73, edid[spa_loc + 1]); in edid_write_hdmi_segment()
819 rep_write(sd, 0x74, edid[spa_loc]); in edid_write_hdmi_segment()
820 rep_write(sd, 0x75, edid[spa_loc + 1]); in edid_write_hdmi_segment()
822 rep_write(sd, 0x76, spa_loc & 0xff); in edid_write_hdmi_segment()
823 rep_write_and_or(sd, 0x77, 0xbf, (spa_loc >> 2) & 0x40); in edid_write_hdmi_segment()
828 rep_write_and_or(sd, 0x77, 0xf3, state->hdmi_edid.present); in edid_write_hdmi_segment()
831 if (rep_read(sd, 0x7d) & state->hdmi_edid.present) in edid_write_hdmi_segment()
851 static void adv7842_inv_register(struct v4l2_subdev *sd) in adv7842_inv_register() argument
853 v4l2_info(sd, "0x000-0x0ff: IO Map\n"); in adv7842_inv_register()
854 v4l2_info(sd, "0x100-0x1ff: AVLink Map\n"); in adv7842_inv_register()
855 v4l2_info(sd, "0x200-0x2ff: CEC Map\n"); in adv7842_inv_register()
856 v4l2_info(sd, "0x300-0x3ff: InfoFrame Map\n"); in adv7842_inv_register()
857 v4l2_info(sd, "0x400-0x4ff: SDP_IO Map\n"); in adv7842_inv_register()
858 v4l2_info(sd, "0x500-0x5ff: SDP Map\n"); in adv7842_inv_register()
859 v4l2_info(sd, "0x600-0x6ff: AFE Map\n"); in adv7842_inv_register()
860 v4l2_info(sd, "0x700-0x7ff: Repeater Map\n"); in adv7842_inv_register()
861 v4l2_info(sd, "0x800-0x8ff: EDID Map\n"); in adv7842_inv_register()
862 v4l2_info(sd, "0x900-0x9ff: HDMI Map\n"); in adv7842_inv_register()
863 v4l2_info(sd, "0xa00-0xaff: CP Map\n"); in adv7842_inv_register()
864 v4l2_info(sd, "0xb00-0xbff: VDP Map\n"); in adv7842_inv_register()
867 static int adv7842_g_register(struct v4l2_subdev *sd, in adv7842_g_register() argument
873 reg->val = io_read(sd, reg->reg & 0xff); in adv7842_g_register()
876 reg->val = avlink_read(sd, reg->reg & 0xff); in adv7842_g_register()
879 reg->val = cec_read(sd, reg->reg & 0xff); in adv7842_g_register()
882 reg->val = infoframe_read(sd, reg->reg & 0xff); in adv7842_g_register()
885 reg->val = sdp_io_read(sd, reg->reg & 0xff); in adv7842_g_register()
888 reg->val = sdp_read(sd, reg->reg & 0xff); in adv7842_g_register()
891 reg->val = afe_read(sd, reg->reg & 0xff); in adv7842_g_register()
894 reg->val = rep_read(sd, reg->reg & 0xff); in adv7842_g_register()
897 reg->val = edid_read(sd, reg->reg & 0xff); in adv7842_g_register()
900 reg->val = hdmi_read(sd, reg->reg & 0xff); in adv7842_g_register()
903 reg->val = cp_read(sd, reg->reg & 0xff); in adv7842_g_register()
906 reg->val = vdp_read(sd, reg->reg & 0xff); in adv7842_g_register()
909 v4l2_info(sd, "Register %03llx not supported\n", reg->reg); in adv7842_g_register()
910 adv7842_inv_register(sd); in adv7842_g_register()
916 static int adv7842_s_register(struct v4l2_subdev *sd, in adv7842_s_register() argument
923 io_write(sd, reg->reg & 0xff, val); in adv7842_s_register()
926 avlink_write(sd, reg->reg & 0xff, val); in adv7842_s_register()
929 cec_write(sd, reg->reg & 0xff, val); in adv7842_s_register()
932 infoframe_write(sd, reg->reg & 0xff, val); in adv7842_s_register()
935 sdp_io_write(sd, reg->reg & 0xff, val); in adv7842_s_register()
938 sdp_write(sd, reg->reg & 0xff, val); in adv7842_s_register()
941 afe_write(sd, reg->reg & 0xff, val); in adv7842_s_register()
944 rep_write(sd, reg->reg & 0xff, val); in adv7842_s_register()
947 edid_write(sd, reg->reg & 0xff, val); in adv7842_s_register()
950 hdmi_write(sd, reg->reg & 0xff, val); in adv7842_s_register()
953 cp_write(sd, reg->reg & 0xff, val); in adv7842_s_register()
956 vdp_write(sd, reg->reg & 0xff, val); in adv7842_s_register()
959 v4l2_info(sd, "Register %03llx not supported\n", reg->reg); in adv7842_s_register()
960 adv7842_inv_register(sd); in adv7842_s_register()
967 static int adv7842_s_detect_tx_5v_ctrl(struct v4l2_subdev *sd) in adv7842_s_detect_tx_5v_ctrl() argument
969 struct adv7842_state *state = to_state(sd); in adv7842_s_detect_tx_5v_ctrl()
970 u16 cable_det = adv7842_read_cable_det(sd); in adv7842_s_detect_tx_5v_ctrl()
972 v4l2_dbg(1, debug, sd, "%s: 0x%x\n", __func__, cable_det); in adv7842_s_detect_tx_5v_ctrl()
977 static int find_and_set_predefined_video_timings(struct v4l2_subdev *sd, in find_and_set_predefined_video_timings() argument
986 is_digital_input(sd) ? 250000 : 1000000, false)) in find_and_set_predefined_video_timings()
989 io_write(sd, 0x00, predef_vid_timings[i].vid_std); in find_and_set_predefined_video_timings()
991 io_write(sd, 0x01, (predef_vid_timings[i].v_freq << 4) + prim_mode); in find_and_set_predefined_video_timings()
998 static int configure_predefined_video_timings(struct v4l2_subdev *sd, in configure_predefined_video_timings() argument
1001 struct adv7842_state *state = to_state(sd); in configure_predefined_video_timings()
1004 v4l2_dbg(1, debug, sd, "%s\n", __func__); in configure_predefined_video_timings()
1007 io_write(sd, 0x16, 0x43); in configure_predefined_video_timings()
1008 io_write(sd, 0x17, 0x5a); in configure_predefined_video_timings()
1010 cp_write_and_or(sd, 0x81, 0xef, 0x00); in configure_predefined_video_timings()
1011 cp_write(sd, 0x26, 0x00); in configure_predefined_video_timings()
1012 cp_write(sd, 0x27, 0x00); in configure_predefined_video_timings()
1013 cp_write(sd, 0x28, 0x00); in configure_predefined_video_timings()
1014 cp_write(sd, 0x29, 0x00); in configure_predefined_video_timings()
1015 cp_write(sd, 0x8f, 0x40); in configure_predefined_video_timings()
1016 cp_write(sd, 0x90, 0x00); in configure_predefined_video_timings()
1017 cp_write(sd, 0xa5, 0x00); in configure_predefined_video_timings()
1018 cp_write(sd, 0xa6, 0x00); in configure_predefined_video_timings()
1019 cp_write(sd, 0xa7, 0x00); in configure_predefined_video_timings()
1020 cp_write(sd, 0xab, 0x00); in configure_predefined_video_timings()
1021 cp_write(sd, 0xac, 0x00); in configure_predefined_video_timings()
1026 err = find_and_set_predefined_video_timings(sd, in configure_predefined_video_timings()
1029 err = find_and_set_predefined_video_timings(sd, in configure_predefined_video_timings()
1033 err = find_and_set_predefined_video_timings(sd, in configure_predefined_video_timings()
1036 err = find_and_set_predefined_video_timings(sd, in configure_predefined_video_timings()
1040 v4l2_dbg(2, debug, sd, "%s: Unknown mode %d\n", in configure_predefined_video_timings()
1050 static void configure_custom_video_timings(struct v4l2_subdev *sd, in configure_custom_video_timings() argument
1053 struct adv7842_state *state = to_state(sd); in configure_custom_video_timings()
1054 struct i2c_client *client = v4l2_get_subdevdata(sd); in configure_custom_video_timings()
1068 v4l2_dbg(2, debug, sd, "%s\n", __func__); in configure_custom_video_timings()
1074 io_write(sd, 0x00, 0x07); /* video std */ in configure_custom_video_timings()
1075 io_write(sd, 0x01, 0x02); /* prim mode */ in configure_custom_video_timings()
1077 cp_write_and_or(sd, 0x81, 0xef, 0x10); in configure_custom_video_timings()
1083 v4l2_err(sd, "writing to reg 0x16 and 0x17 failed\n"); in configure_custom_video_timings()
1088 cp_write(sd, 0x26, (cp_start_sav >> 8) & 0xf); in configure_custom_video_timings()
1089 cp_write(sd, 0x27, (cp_start_sav & 0xff)); in configure_custom_video_timings()
1090 cp_write(sd, 0x28, (cp_start_eav >> 8) & 0xf); in configure_custom_video_timings()
1091 cp_write(sd, 0x29, (cp_start_eav & 0xff)); in configure_custom_video_timings()
1094 cp_write(sd, 0xa5, (cp_start_vbi >> 4) & 0xff); in configure_custom_video_timings()
1095 cp_write(sd, 0xa6, ((cp_start_vbi & 0xf) << 4) | in configure_custom_video_timings()
1097 cp_write(sd, 0xa7, cp_end_vbi & 0xff); in configure_custom_video_timings()
1102 io_write(sd, 0x00, 0x02); /* video std */ in configure_custom_video_timings()
1103 io_write(sd, 0x01, 0x06); /* prim mode */ in configure_custom_video_timings()
1106 v4l2_dbg(2, debug, sd, "%s: Unknown mode %d\n", in configure_custom_video_timings()
1111 cp_write(sd, 0x8f, (ch1_fr_ll >> 8) & 0x7); in configure_custom_video_timings()
1112 cp_write(sd, 0x90, ch1_fr_ll & 0xff); in configure_custom_video_timings()
1113 cp_write(sd, 0xab, (height >> 4) & 0xff); in configure_custom_video_timings()
1114 cp_write(sd, 0xac, (height & 0x0f) << 4); in configure_custom_video_timings()
1117 static void adv7842_set_offset(struct v4l2_subdev *sd, bool auto_offset, u16 offset_a, u16 offset_b… in adv7842_set_offset() argument
1119 struct adv7842_state *state = to_state(sd); in adv7842_set_offset()
1128 v4l2_dbg(2, debug, sd, "%s: %s offset: a = 0x%x, b = 0x%x, c = 0x%x\n", in adv7842_set_offset()
1132 offset_buf[0]= (cp_read(sd, 0x77) & 0xc0) | ((offset_a & 0x3f0) >> 4); in adv7842_set_offset()
1139 v4l2_err(sd, "%s: i2c error writing to CP reg 0x77, 0x78, 0x79, 0x7a\n", __func__); in adv7842_set_offset()
1142 static void adv7842_set_gain(struct v4l2_subdev *sd, bool auto_gain, u16 gain_a, u16 gain_b, u16 ga… in adv7842_set_gain() argument
1144 struct adv7842_state *state = to_state(sd); in adv7842_set_gain()
1157 v4l2_dbg(2, debug, sd, "%s: %s gain: a = 0x%x, b = 0x%x, c = 0x%x\n", in adv7842_set_gain()
1168 v4l2_err(sd, "%s: i2c error writing to CP reg 0x73, 0x74, 0x75, 0x76\n", __func__); in adv7842_set_gain()
1171 static void set_rgb_quantization_range(struct v4l2_subdev *sd) in set_rgb_quantization_range() argument
1173 struct adv7842_state *state = to_state(sd); in set_rgb_quantization_range()
1174 bool rgb_output = io_read(sd, 0x02) & 0x02; in set_rgb_quantization_range()
1175 bool hdmi_signal = hdmi_read(sd, 0x05) & 0x80; in set_rgb_quantization_range()
1178 if (hdmi_signal && (io_read(sd, 0x60) & 1)) in set_rgb_quantization_range()
1179 y = infoframe_read(sd, 0x01) >> 5; in set_rgb_quantization_range()
1181 v4l2_dbg(2, debug, sd, "%s: RGB quantization range: %d, RGB out: %d, HDMI: %d\n", in set_rgb_quantization_range()
1185 adv7842_set_gain(sd, true, 0x0, 0x0, 0x0); in set_rgb_quantization_range()
1186 adv7842_set_offset(sd, true, 0x0, 0x0, 0x0); in set_rgb_quantization_range()
1187 io_write_clr_set(sd, 0x02, 0x04, rgb_output ? 0 : 4); in set_rgb_quantization_range()
1194 io_write_and_or(sd, 0x02, 0x0f, 0x10); in set_rgb_quantization_range()
1201 io_write_and_or(sd, 0x02, 0x0f, 0xf0); in set_rgb_quantization_range()
1208 io_write_and_or(sd, 0x02, 0x0f, 0xf0); in set_rgb_quantization_range()
1217 io_write_and_or(sd, 0x02, 0x0f, 0x00); in set_rgb_quantization_range()
1220 io_write_and_or(sd, 0x02, 0x0f, 0x10); in set_rgb_quantization_range()
1222 if (is_digital_input(sd) && rgb_output) { in set_rgb_quantization_range()
1223 adv7842_set_offset(sd, false, 0x40, 0x40, 0x40); in set_rgb_quantization_range()
1225 adv7842_set_gain(sd, false, 0xe0, 0xe0, 0xe0); in set_rgb_quantization_range()
1226 adv7842_set_offset(sd, false, 0x70, 0x70, 0x70); in set_rgb_quantization_range()
1233 io_write_and_or(sd, 0x02, 0x0f, 0x20); in set_rgb_quantization_range()
1241 io_write_and_or(sd, 0x02, 0x0f, 0x00); in set_rgb_quantization_range()
1247 io_write_and_or(sd, 0x02, 0x0f, 0x60); in set_rgb_quantization_range()
1255 io_write_and_or(sd, 0x02, 0x0f, 0x10); in set_rgb_quantization_range()
1257 if (is_analog_input(sd) || hdmi_signal) in set_rgb_quantization_range()
1262 adv7842_set_offset(sd, false, 0x40, 0x40, 0x40); in set_rgb_quantization_range()
1264 adv7842_set_gain(sd, false, 0xe0, 0xe0, 0xe0); in set_rgb_quantization_range()
1265 adv7842_set_offset(sd, false, 0x70, 0x70, 0x70); in set_rgb_quantization_range()
1273 struct v4l2_subdev *sd = to_sd(ctrl); in adv7842_s_ctrl() local
1274 struct adv7842_state *state = to_state(sd); in adv7842_s_ctrl()
1283 cp_write(sd, 0x3c, ctrl->val); in adv7842_s_ctrl()
1284 sdp_write(sd, 0x14, ctrl->val); in adv7842_s_ctrl()
1288 cp_write(sd, 0x3a, ctrl->val); in adv7842_s_ctrl()
1289 sdp_write(sd, 0x13, ctrl->val); in adv7842_s_ctrl()
1293 cp_write(sd, 0x3b, ctrl->val); in adv7842_s_ctrl()
1294 sdp_write(sd, 0x15, ctrl->val); in adv7842_s_ctrl()
1298 cp_write(sd, 0x3d, ctrl->val); in adv7842_s_ctrl()
1299 sdp_write(sd, 0x16, ctrl->val); in adv7842_s_ctrl()
1304 afe_write(sd, 0xc8, ctrl->val); in adv7842_s_ctrl()
1307 cp_write_and_or(sd, 0xbf, ~0x04, (ctrl->val << 2)); in adv7842_s_ctrl()
1308 sdp_write_and_or(sd, 0xdd, ~0x04, (ctrl->val << 2)); in adv7842_s_ctrl()
1328 v4l2_dbg(1, debug, sd, "R %x, G %x, B %x\n", R, G, B); in adv7842_s_ctrl()
1329 v4l2_dbg(1, debug, sd, "Y %x, U %x, V %x\n", Y, U, V); in adv7842_s_ctrl()
1332 cp_write(sd, 0xc1, R); in adv7842_s_ctrl()
1333 cp_write(sd, 0xc0, G); in adv7842_s_ctrl()
1334 cp_write(sd, 0xc2, B); in adv7842_s_ctrl()
1336 sdp_write(sd, 0xde, Y); in adv7842_s_ctrl()
1337 sdp_write(sd, 0xdf, (V & 0xf0) | ((U >> 4) & 0x0f)); in adv7842_s_ctrl()
1342 set_rgb_quantization_range(sd); in adv7842_s_ctrl()
1350 struct v4l2_subdev *sd = to_sd(ctrl); in adv7842_g_volatile_ctrl() local
1354 if ((io_read(sd, 0x60) & 1) && (infoframe_read(sd, 0x03) & 0x80)) in adv7842_g_volatile_ctrl()
1355 ctrl->val = (infoframe_read(sd, 0x05) >> 4) & 3; in adv7842_g_volatile_ctrl()
1361 static inline bool no_power(struct v4l2_subdev *sd) in no_power() argument
1363 return io_read(sd, 0x0c) & 0x24; in no_power()
1366 static inline bool no_cp_signal(struct v4l2_subdev *sd) in no_cp_signal() argument
1368 return ((cp_read(sd, 0xb5) & 0xd0) != 0xd0) || !(cp_read(sd, 0xb1) & 0x80); in no_cp_signal()
1371 static inline bool is_hdmi(struct v4l2_subdev *sd) in is_hdmi() argument
1373 return hdmi_read(sd, 0x05) & 0x80; in is_hdmi()
1376 static int adv7842_g_input_status(struct v4l2_subdev *sd, u32 *status) in adv7842_g_input_status() argument
1378 struct adv7842_state *state = to_state(sd); in adv7842_g_input_status()
1382 if (io_read(sd, 0x0c) & 0x24) in adv7842_g_input_status()
1387 if (!(sdp_read(sd, 0x5A) & 0x01)) in adv7842_g_input_status()
1390 v4l2_dbg(1, debug, sd, "%s: SDP status = 0x%x\n", in adv7842_g_input_status()
1395 if ((cp_read(sd, 0xb5) & 0xd0) != 0xd0 || in adv7842_g_input_status()
1396 !(cp_read(sd, 0xb1) & 0x80)) in adv7842_g_input_status()
1400 if (is_digital_input(sd) && ((io_read(sd, 0x74) & 0x03) != 0x03)) in adv7842_g_input_status()
1403 v4l2_dbg(1, debug, sd, "%s: CP status = 0x%x\n", in adv7842_g_input_status()
1415 static int stdi2dv_timings(struct v4l2_subdev *sd, in stdi2dv_timings() argument
1419 struct adv7842_state *state = to_state(sd); in stdi2dv_timings()
1428 adv7842_get_dv_timings_cap(sd), in stdi2dv_timings()
1456 v4l2_dbg(2, debug, sd, in stdi2dv_timings()
1463 static int read_stdi(struct v4l2_subdev *sd, struct stdi_readback *stdi) in read_stdi() argument
1467 adv7842_g_input_status(sd, &status); in read_stdi()
1469 v4l2_dbg(2, debug, sd, "%s: no signal\n", __func__); in read_stdi()
1473 stdi->bl = ((cp_read(sd, 0xb1) & 0x3f) << 8) | cp_read(sd, 0xb2); in read_stdi()
1474 stdi->lcf = ((cp_read(sd, 0xb3) & 0x7) << 8) | cp_read(sd, 0xb4); in read_stdi()
1475 stdi->lcvs = cp_read(sd, 0xb3) >> 3; in read_stdi()
1477 if ((cp_read(sd, 0xb5) & 0x80) && ((cp_read(sd, 0xb5) & 0x03) == 0x01)) { in read_stdi()
1478 stdi->hs_pol = ((cp_read(sd, 0xb5) & 0x10) ? in read_stdi()
1479 ((cp_read(sd, 0xb5) & 0x08) ? '+' : '-') : 'x'); in read_stdi()
1480 stdi->vs_pol = ((cp_read(sd, 0xb5) & 0x40) ? in read_stdi()
1481 ((cp_read(sd, 0xb5) & 0x20) ? '+' : '-') : 'x'); in read_stdi()
1486 stdi->interlaced = (cp_read(sd, 0xb1) & 0x40) ? true : false; in read_stdi()
1489 v4l2_dbg(2, debug, sd, "%s: invalid signal\n", __func__); in read_stdi()
1493 v4l2_dbg(2, debug, sd, in read_stdi()
1502 static int adv7842_enum_dv_timings(struct v4l2_subdev *sd, in adv7842_enum_dv_timings() argument
1509 adv7842_get_dv_timings_cap(sd), adv7842_check_dv_timings, NULL); in adv7842_enum_dv_timings()
1512 static int adv7842_dv_timings_cap(struct v4l2_subdev *sd, in adv7842_dv_timings_cap() argument
1518 *cap = *adv7842_get_dv_timings_cap(sd); in adv7842_dv_timings_cap()
1524 static void adv7842_fill_optional_dv_timings_fields(struct v4l2_subdev *sd, in adv7842_fill_optional_dv_timings_fields() argument
1527 v4l2_find_dv_timings_cap(timings, adv7842_get_dv_timings_cap(sd), in adv7842_fill_optional_dv_timings_fields()
1528 is_digital_input(sd) ? 250000 : 1000000, in adv7842_fill_optional_dv_timings_fields()
1533 static int adv7842_query_dv_timings(struct v4l2_subdev *sd, in adv7842_query_dv_timings() argument
1536 struct adv7842_state *state = to_state(sd); in adv7842_query_dv_timings()
1540 v4l2_dbg(1, debug, sd, "%s:\n", __func__); in adv7842_query_dv_timings()
1549 if (read_stdi(sd, &stdi)) { in adv7842_query_dv_timings()
1551 v4l2_dbg(1, debug, sd, "%s: no valid signal\n", __func__); in adv7842_query_dv_timings()
1559 if (is_digital_input(sd)) { in adv7842_query_dv_timings()
1564 bt->width = (hdmi_read(sd, 0x07) & 0x0f) * 256 + hdmi_read(sd, 0x08); in adv7842_query_dv_timings()
1565 bt->height = (hdmi_read(sd, 0x09) & 0x0f) * 256 + hdmi_read(sd, 0x0a); in adv7842_query_dv_timings()
1566 freq = ((hdmi_read(sd, 0x51) << 1) + (hdmi_read(sd, 0x52) >> 7)) * 1000000; in adv7842_query_dv_timings()
1567 freq += ((hdmi_read(sd, 0x52) & 0x7f) * 7813); in adv7842_query_dv_timings()
1568 if (is_hdmi(sd)) { in adv7842_query_dv_timings()
1570 freq = freq * 8 / (((hdmi_read(sd, 0x0b) & 0xc0) >> 6) * 2 + 8); in adv7842_query_dv_timings()
1573 bt->hfrontporch = (hdmi_read(sd, 0x20) & 0x03) * 256 + in adv7842_query_dv_timings()
1574 hdmi_read(sd, 0x21); in adv7842_query_dv_timings()
1575 bt->hsync = (hdmi_read(sd, 0x22) & 0x03) * 256 + in adv7842_query_dv_timings()
1576 hdmi_read(sd, 0x23); in adv7842_query_dv_timings()
1577 bt->hbackporch = (hdmi_read(sd, 0x24) & 0x03) * 256 + in adv7842_query_dv_timings()
1578 hdmi_read(sd, 0x25); in adv7842_query_dv_timings()
1579 bt->vfrontporch = ((hdmi_read(sd, 0x2a) & 0x1f) * 256 + in adv7842_query_dv_timings()
1580 hdmi_read(sd, 0x2b)) / 2; in adv7842_query_dv_timings()
1581 bt->vsync = ((hdmi_read(sd, 0x2e) & 0x1f) * 256 + in adv7842_query_dv_timings()
1582 hdmi_read(sd, 0x2f)) / 2; in adv7842_query_dv_timings()
1583 bt->vbackporch = ((hdmi_read(sd, 0x32) & 0x1f) * 256 + in adv7842_query_dv_timings()
1584 hdmi_read(sd, 0x33)) / 2; in adv7842_query_dv_timings()
1585 bt->polarities = ((hdmi_read(sd, 0x05) & 0x10) ? V4L2_DV_VSYNC_POS_POL : 0) | in adv7842_query_dv_timings()
1586 ((hdmi_read(sd, 0x05) & 0x20) ? V4L2_DV_HSYNC_POS_POL : 0); in adv7842_query_dv_timings()
1588 bt->height += (hdmi_read(sd, 0x0b) & 0x0f) * 256 + in adv7842_query_dv_timings()
1589 hdmi_read(sd, 0x0c); in adv7842_query_dv_timings()
1590 bt->il_vfrontporch = ((hdmi_read(sd, 0x2c) & 0x1f) * 256 + in adv7842_query_dv_timings()
1591 hdmi_read(sd, 0x2d)) / 2; in adv7842_query_dv_timings()
1592 bt->il_vsync = ((hdmi_read(sd, 0x30) & 0x1f) * 256 + in adv7842_query_dv_timings()
1593 hdmi_read(sd, 0x31)) / 2; in adv7842_query_dv_timings()
1594 bt->il_vbackporch = ((hdmi_read(sd, 0x34) & 0x1f) * 256 + in adv7842_query_dv_timings()
1595 hdmi_read(sd, 0x35)) / 2; in adv7842_query_dv_timings()
1601 adv7842_fill_optional_dv_timings_fields(sd, timings); in adv7842_query_dv_timings()
1615 if (!stdi2dv_timings(sd, &stdi, timings)) in adv7842_query_dv_timings()
1618 v4l2_dbg(1, debug, sd, "%s: lcvs + 1 = %d\n", __func__, stdi.lcvs); in adv7842_query_dv_timings()
1619 if (!stdi2dv_timings(sd, &stdi, timings)) in adv7842_query_dv_timings()
1622 v4l2_dbg(1, debug, sd, "%s: lcvs - 1 = %d\n", __func__, stdi.lcvs); in adv7842_query_dv_timings()
1623 if (stdi2dv_timings(sd, &stdi, timings)) { in adv7842_query_dv_timings()
1634 v4l2_dbg(1, debug, sd, "%s: restart STDI\n", __func__); in adv7842_query_dv_timings()
1637 cp_write_and_or(sd, 0x86, 0xf9, 0x00); in adv7842_query_dv_timings()
1639 cp_write_and_or(sd, 0x86, 0xf9, 0x04); in adv7842_query_dv_timings()
1641 cp_write_and_or(sd, 0x86, 0xf9, 0x02); in adv7842_query_dv_timings()
1645 v4l2_dbg(1, debug, sd, "%s: format not supported\n", __func__); in adv7842_query_dv_timings()
1653 v4l2_print_dv_timings(sd->name, "adv7842_query_dv_timings:", in adv7842_query_dv_timings()
1658 static int adv7842_s_dv_timings(struct v4l2_subdev *sd, in adv7842_s_dv_timings() argument
1661 struct adv7842_state *state = to_state(sd); in adv7842_s_dv_timings()
1665 v4l2_dbg(1, debug, sd, "%s:\n", __func__); in adv7842_s_dv_timings()
1671 v4l2_dbg(1, debug, sd, "%s: no change\n", __func__); in adv7842_s_dv_timings()
1677 if (!v4l2_valid_dv_timings(timings, adv7842_get_dv_timings_cap(sd), in adv7842_s_dv_timings()
1681 adv7842_fill_optional_dv_timings_fields(sd, timings); in adv7842_s_dv_timings()
1685 cp_write(sd, 0x91, bt->interlaced ? 0x40 : 0x00); in adv7842_s_dv_timings()
1688 err = configure_predefined_video_timings(sd, timings); in adv7842_s_dv_timings()
1692 configure_custom_video_timings(sd, bt); in adv7842_s_dv_timings()
1695 set_rgb_quantization_range(sd); in adv7842_s_dv_timings()
1699 v4l2_print_dv_timings(sd->name, "adv7842_s_dv_timings: ", in adv7842_s_dv_timings()
1704 static int adv7842_g_dv_timings(struct v4l2_subdev *sd, in adv7842_g_dv_timings() argument
1707 struct adv7842_state *state = to_state(sd); in adv7842_g_dv_timings()
1715 static void enable_input(struct v4l2_subdev *sd) in enable_input() argument
1717 struct adv7842_state *state = to_state(sd); in enable_input()
1719 set_rgb_quantization_range(sd); in enable_input()
1724 io_write(sd, 0x15, 0xb0); /* Disable Tristate of Pins (no audio) */ in enable_input()
1727 hdmi_write(sd, 0x01, 0x00); /* Enable HDMI clock terminators */ in enable_input()
1728 io_write(sd, 0x15, 0xa0); /* Disable Tristate of Pins */ in enable_input()
1729 hdmi_write_and_or(sd, 0x1a, 0xef, 0x00); /* Unmute audio */ in enable_input()
1732 v4l2_dbg(2, debug, sd, "%s: Unknown mode %d\n", in enable_input()
1738 static void disable_input(struct v4l2_subdev *sd) in disable_input() argument
1740 hdmi_write_and_or(sd, 0x1a, 0xef, 0x10); /* Mute audio [REF_01, c. 2.2.2] */ in disable_input()
1742 io_write(sd, 0x15, 0xbe); /* Tristate all outputs from video core */ in disable_input()
1743 hdmi_write(sd, 0x01, 0x78); /* Disable HDMI clock terminators */ in disable_input()
1746 static void sdp_csc_coeff(struct v4l2_subdev *sd, in sdp_csc_coeff() argument
1750 sdp_io_write_and_or(sd, 0xe0, 0xbf, c->manual ? 0x00 : 0x40); in sdp_csc_coeff()
1756 sdp_io_write_and_or(sd, 0xe0, 0x7f, c->scaling == 2 ? 0x80 : 0x00); in sdp_csc_coeff()
1759 sdp_io_write_and_or(sd, 0xe0, 0xe0, c->A1 >> 8); in sdp_csc_coeff()
1760 sdp_io_write(sd, 0xe1, c->A1); in sdp_csc_coeff()
1761 sdp_io_write_and_or(sd, 0xe2, 0xe0, c->A2 >> 8); in sdp_csc_coeff()
1762 sdp_io_write(sd, 0xe3, c->A2); in sdp_csc_coeff()
1763 sdp_io_write_and_or(sd, 0xe4, 0xe0, c->A3 >> 8); in sdp_csc_coeff()
1764 sdp_io_write(sd, 0xe5, c->A3); in sdp_csc_coeff()
1767 sdp_io_write_and_or(sd, 0xe6, 0x80, c->A4 >> 8); in sdp_csc_coeff()
1768 sdp_io_write(sd, 0xe7, c->A4); in sdp_csc_coeff()
1771 sdp_io_write_and_or(sd, 0xe8, 0xe0, c->B1 >> 8); in sdp_csc_coeff()
1772 sdp_io_write(sd, 0xe9, c->B1); in sdp_csc_coeff()
1773 sdp_io_write_and_or(sd, 0xea, 0xe0, c->B2 >> 8); in sdp_csc_coeff()
1774 sdp_io_write(sd, 0xeb, c->B2); in sdp_csc_coeff()
1775 sdp_io_write_and_or(sd, 0xec, 0xe0, c->B3 >> 8); in sdp_csc_coeff()
1776 sdp_io_write(sd, 0xed, c->B3); in sdp_csc_coeff()
1779 sdp_io_write_and_or(sd, 0xee, 0x80, c->B4 >> 8); in sdp_csc_coeff()
1780 sdp_io_write(sd, 0xef, c->B4); in sdp_csc_coeff()
1783 sdp_io_write_and_or(sd, 0xf0, 0xe0, c->C1 >> 8); in sdp_csc_coeff()
1784 sdp_io_write(sd, 0xf1, c->C1); in sdp_csc_coeff()
1785 sdp_io_write_and_or(sd, 0xf2, 0xe0, c->C2 >> 8); in sdp_csc_coeff()
1786 sdp_io_write(sd, 0xf3, c->C2); in sdp_csc_coeff()
1787 sdp_io_write_and_or(sd, 0xf4, 0xe0, c->C3 >> 8); in sdp_csc_coeff()
1788 sdp_io_write(sd, 0xf5, c->C3); in sdp_csc_coeff()
1791 sdp_io_write_and_or(sd, 0xf6, 0x80, c->C4 >> 8); in sdp_csc_coeff()
1792 sdp_io_write(sd, 0xf7, c->C4); in sdp_csc_coeff()
1795 static void select_input(struct v4l2_subdev *sd, in select_input() argument
1798 struct adv7842_state *state = to_state(sd); in select_input()
1802 io_write(sd, 0x00, vid_std_select); /* video std: CVBS or YC mode */ in select_input()
1803 io_write(sd, 0x01, 0); /* prim mode */ in select_input()
1805 cp_write_and_or(sd, 0x81, 0xef, 0x10); in select_input()
1807 afe_write(sd, 0x00, 0x00); /* power up ADC */ in select_input()
1808 afe_write(sd, 0xc8, 0x00); /* phase control */ in select_input()
1810 io_write(sd, 0xdd, 0x90); /* Manual 2x output clock */ in select_input()
1814 afe_write_and_or(sd, 0x02, 0x7f, 0x80); in select_input()
1816 afe_write(sd, 0x03, 0xa0); /* ADC0 to AIN10 (CVBS), ADC1 N/C*/ in select_input()
1817 afe_write(sd, 0x04, 0x00); /* ADC2 N/C,ADC3 N/C*/ in select_input()
1819 afe_write(sd, 0x03, 0xa0); /* ADC0 to AIN10 (CVBS), ADC1 N/C*/ in select_input()
1820 afe_write(sd, 0x04, 0xc0); /* ADC2 to AIN12, ADC3 N/C*/ in select_input()
1822 afe_write(sd, 0x0c, 0x1f); /* ADI recommend write */ in select_input()
1823 afe_write(sd, 0x12, 0x63); /* ADI recommend write */ in select_input()
1825 sdp_io_write(sd, 0xb2, 0x60); /* Disable AV codes */ in select_input()
1826 sdp_io_write(sd, 0xc8, 0xe3); /* Disable Ancillary data */ in select_input()
1829 sdp_write(sd, 0x00, 0x3F); /* Autodetect PAL NTSC (not SECAM) */ in select_input()
1830 sdp_write(sd, 0x01, 0x00); /* Pedestal Off */ in select_input()
1832 sdp_write(sd, 0x03, 0xE4); /* Manual VCR Gain Luma 0x40B */ in select_input()
1833 sdp_write(sd, 0x04, 0x0B); /* Manual Luma setting */ in select_input()
1834 sdp_write(sd, 0x05, 0xC3); /* Manual Chroma setting 0x3FE */ in select_input()
1835 sdp_write(sd, 0x06, 0xFE); /* Manual Chroma setting */ in select_input()
1836 sdp_write(sd, 0x12, 0x0D); /* Frame TBC,I_P, 3D comb enabled */ in select_input()
1837 sdp_write(sd, 0xA7, 0x00); /* ADI Recommended Write */ in select_input()
1838 sdp_io_write(sd, 0xB0, 0x00); /* Disable H and v blanking */ in select_input()
1841 sdp_write_and_or(sd, 0x12, 0xf6, 0x09); in select_input()
1848 afe_write_and_or(sd, 0x02, 0x7f, 0x00); in select_input()
1850 io_write(sd, 0x00, vid_std_select); /* video std */ in select_input()
1851 io_write(sd, 0x01, 0x02); /* prim mode */ in select_input()
1852 cp_write_and_or(sd, 0x81, 0xef, 0x10); /* enable embedded syncs in select_input()
1855 afe_write(sd, 0x00, 0x00); /* power up ADC */ in select_input()
1856 afe_write(sd, 0xc8, 0x00); /* phase control */ in select_input()
1859 io_write_and_or(sd, 0x02, 0x0f, 0x60); in select_input()
1862 io_write_and_or(sd, 0x02, 0x0f, 0x10); in select_input()
1868 afe_write(sd, 0x0c, 0x1f); /* ADC Range improvement */ in select_input()
1869 afe_write(sd, 0x12, 0x63); /* ADC Range improvement */ in select_input()
1872 cp_write(sd, 0x73, 0x10); in select_input()
1873 cp_write(sd, 0x74, 0x04); in select_input()
1874 cp_write(sd, 0x75, 0x01); in select_input()
1875 cp_write(sd, 0x76, 0x00); in select_input()
1877 cp_write(sd, 0x3e, 0x04); /* CP core pre-gain control */ in select_input()
1878 cp_write(sd, 0xc3, 0x39); /* CP coast control. Graphics mode */ in select_input()
1879 cp_write(sd, 0x40, 0x5c); /* CP core pre-gain control. Graphics mode */ in select_input()
1884 afe_write_and_or(sd, 0x02, 0x7f, 0x00); in select_input()
1887 hdmi_write(sd, 0x00, 0x02); /* select port A */ in select_input()
1889 hdmi_write(sd, 0x00, 0x03); /* select port B */ in select_input()
1890 io_write(sd, 0x00, vid_std_select); /* video std */ in select_input()
1891 io_write(sd, 0x01, 5); /* prim mode */ in select_input()
1892 cp_write_and_or(sd, 0x81, 0xef, 0x00); /* disable embedded syncs in select_input()
1898 hdmi_write(sd, 0xc0, 0x00); in select_input()
1899 hdmi_write(sd, 0x0d, 0x34); /* ADI recommended write */ in select_input()
1900 hdmi_write(sd, 0x3d, 0x10); /* ADI recommended write */ in select_input()
1901 hdmi_write(sd, 0x44, 0x85); /* TMDS PLL optimization */ in select_input()
1902 hdmi_write(sd, 0x46, 0x1f); /* ADI recommended write */ in select_input()
1903 hdmi_write(sd, 0x57, 0xb6); /* TMDS PLL optimization */ in select_input()
1904 hdmi_write(sd, 0x58, 0x03); /* TMDS PLL optimization */ in select_input()
1905 hdmi_write(sd, 0x60, 0x88); /* TMDS PLL optimization */ in select_input()
1906 hdmi_write(sd, 0x61, 0x88); /* TMDS PLL optimization */ in select_input()
1907 hdmi_write(sd, 0x6c, 0x18); /* Disable ISRC clearing bit, in select_input()
1909 hdmi_write(sd, 0x75, 0x10); /* DDC drive strength */ in select_input()
1910 hdmi_write(sd, 0x85, 0x1f); /* equaliser */ in select_input()
1911 hdmi_write(sd, 0x87, 0x70); /* ADI recommended write */ in select_input()
1912 hdmi_write(sd, 0x89, 0x04); /* equaliser */ in select_input()
1913 hdmi_write(sd, 0x8a, 0x1e); /* equaliser */ in select_input()
1914 hdmi_write(sd, 0x93, 0x04); /* equaliser */ in select_input()
1915 hdmi_write(sd, 0x94, 0x1e); /* equaliser */ in select_input()
1916 hdmi_write(sd, 0x99, 0xa1); /* ADI recommended write */ in select_input()
1917 hdmi_write(sd, 0x9b, 0x09); /* ADI recommended write */ in select_input()
1918 hdmi_write(sd, 0x9d, 0x02); /* equaliser */ in select_input()
1920 afe_write(sd, 0x00, 0xff); /* power down ADC */ in select_input()
1921 afe_write(sd, 0xc8, 0x40); /* phase control */ in select_input()
1924 cp_write(sd, 0x73, 0x10); in select_input()
1925 cp_write(sd, 0x74, 0x04); in select_input()
1926 cp_write(sd, 0x75, 0x01); in select_input()
1927 cp_write(sd, 0x76, 0x00); in select_input()
1932 afe_write(sd, 0x12, 0xfb); /* ADC noise shaping filter controls */ in select_input()
1933 afe_write(sd, 0x0c, 0x0d); /* CP core gain controls */ in select_input()
1934 cp_write(sd, 0x3e, 0x00); /* CP core pre-gain control */ in select_input()
1937 cp_write(sd, 0xc3, 0x33); /* Component mode */ in select_input()
1940 io_write_and_or(sd, 0x02, 0x0f, 0xf0); in select_input()
1944 v4l2_dbg(2, debug, sd, "%s: Unknown mode %d\n", in select_input()
1950 static int adv7842_s_routing(struct v4l2_subdev *sd, in adv7842_s_routing() argument
1953 struct adv7842_state *state = to_state(sd); in adv7842_s_routing()
1955 v4l2_dbg(2, debug, sd, "%s: input %d\n", __func__, input); in adv7842_s_routing()
1988 disable_input(sd); in adv7842_s_routing()
1989 select_input(sd, state->vid_std_select); in adv7842_s_routing()
1990 enable_input(sd); in adv7842_s_routing()
1992 v4l2_subdev_notify_event(sd, &adv7842_ev_fmt); in adv7842_s_routing()
1997 static int adv7842_enum_mbus_code(struct v4l2_subdev *sd, in adv7842_enum_mbus_code() argument
2061 struct v4l2_subdev *sd = &state->sd; in adv7842_setup_format() local
2063 io_write_clr_set(sd, 0x02, 0x02, in adv7842_setup_format()
2065 io_write(sd, 0x03, state->format->op_format_sel | in adv7842_setup_format()
2067 io_write_clr_set(sd, 0x04, 0xe0, adv7842_op_ch_sel(state)); in adv7842_setup_format()
2068 io_write_clr_set(sd, 0x05, 0x01, in adv7842_setup_format()
2070 set_rgb_quantization_range(sd); in adv7842_setup_format()
2073 static int adv7842_get_format(struct v4l2_subdev *sd, in adv7842_get_format() argument
2077 struct adv7842_state *state = to_state(sd); in adv7842_get_format()
2084 if (!(sdp_read(sd, 0x5a) & 0x01)) in adv7842_get_format()
2102 fmt = v4l2_subdev_get_try_format(sd, cfg, format->pad); in adv7842_get_format()
2111 static int adv7842_set_format(struct v4l2_subdev *sd, in adv7842_set_format() argument
2115 struct adv7842_state *state = to_state(sd); in adv7842_set_format()
2122 return adv7842_get_format(sd, cfg, format); in adv7842_set_format()
2134 fmt = v4l2_subdev_get_try_format(sd, cfg, format->pad); in adv7842_set_format()
2144 static void adv7842_irq_enable(struct v4l2_subdev *sd, bool enable) in adv7842_irq_enable() argument
2148 io_write(sd, 0x46, 0x9c); in adv7842_irq_enable()
2150 io_write(sd, 0x5a, 0x10); in adv7842_irq_enable()
2152 io_write(sd, 0x73, 0x03); in adv7842_irq_enable()
2154 io_write(sd, 0x78, 0x03); in adv7842_irq_enable()
2156 io_write(sd, 0xa0, 0x09); in adv7842_irq_enable()
2158 io_write(sd, 0x69, 0x08); in adv7842_irq_enable()
2160 io_write(sd, 0x46, 0x0); in adv7842_irq_enable()
2161 io_write(sd, 0x5a, 0x0); in adv7842_irq_enable()
2162 io_write(sd, 0x73, 0x0); in adv7842_irq_enable()
2163 io_write(sd, 0x78, 0x0); in adv7842_irq_enable()
2164 io_write(sd, 0xa0, 0x0); in adv7842_irq_enable()
2165 io_write(sd, 0x69, 0x0); in adv7842_irq_enable()
2170 static void adv7842_cec_tx_raw_status(struct v4l2_subdev *sd, u8 tx_raw_status) in adv7842_cec_tx_raw_status() argument
2172 struct adv7842_state *state = to_state(sd); in adv7842_cec_tx_raw_status()
2174 if ((cec_read(sd, 0x11) & 0x01) == 0) { in adv7842_cec_tx_raw_status()
2175 v4l2_dbg(1, debug, sd, "%s: tx raw: tx disabled\n", __func__); in adv7842_cec_tx_raw_status()
2180 v4l2_dbg(1, debug, sd, "%s: tx raw: arbitration lost\n", in adv7842_cec_tx_raw_status()
2191 v4l2_dbg(1, debug, sd, "%s: tx raw: retry failed\n", __func__); in adv7842_cec_tx_raw_status()
2197 nack_cnt = cec_read(sd, 0x14) & 0xf; in adv7842_cec_tx_raw_status()
2200 low_drive_cnt = cec_read(sd, 0x14) >> 4; in adv7842_cec_tx_raw_status()
2208 v4l2_dbg(1, debug, sd, "%s: tx raw: ready ok\n", __func__); in adv7842_cec_tx_raw_status()
2214 static void adv7842_cec_isr(struct v4l2_subdev *sd, bool *handled) in adv7842_cec_isr() argument
2219 cec_irq = io_read(sd, 0x93) & 0x0f; in adv7842_cec_isr()
2223 v4l2_dbg(1, debug, sd, "%s: cec: irq 0x%x\n", __func__, cec_irq); in adv7842_cec_isr()
2224 adv7842_cec_tx_raw_status(sd, cec_irq); in adv7842_cec_isr()
2226 struct adv7842_state *state = to_state(sd); in adv7842_cec_isr()
2229 msg.len = cec_read(sd, 0x25) & 0x1f; in adv7842_cec_isr()
2237 msg.msg[i] = cec_read(sd, i + 0x15); in adv7842_cec_isr()
2238 cec_write(sd, 0x26, 0x01); /* re-enable rx */ in adv7842_cec_isr()
2243 io_write(sd, 0x94, cec_irq); in adv7842_cec_isr()
2252 struct v4l2_subdev *sd = &state->sd; in adv7842_cec_adap_enable() local
2255 cec_write_clr_set(sd, 0x2a, 0x01, 0x01); /* power up cec */ in adv7842_cec_adap_enable()
2256 cec_write(sd, 0x2c, 0x01); /* cec soft reset */ in adv7842_cec_adap_enable()
2257 cec_write_clr_set(sd, 0x11, 0x01, 0); /* initially disable tx */ in adv7842_cec_adap_enable()
2263 io_write_clr_set(sd, 0x96, 0x0f, 0x0f); in adv7842_cec_adap_enable()
2264 cec_write(sd, 0x26, 0x01); /* enable rx */ in adv7842_cec_adap_enable()
2267 io_write_clr_set(sd, 0x96, 0x0f, 0x00); in adv7842_cec_adap_enable()
2269 cec_write_clr_set(sd, 0x27, 0x70, 0x00); in adv7842_cec_adap_enable()
2271 cec_write_clr_set(sd, 0x2a, 0x01, 0x00); in adv7842_cec_adap_enable()
2281 struct v4l2_subdev *sd = &state->sd; in adv7842_cec_adap_log_addr() local
2288 cec_write_clr_set(sd, 0x27, 0x70, 0); in adv7842_cec_adap_log_addr()
2312 cec_write_clr_set(sd, 0x27, 0x10, 0x10); in adv7842_cec_adap_log_addr()
2314 cec_write_clr_set(sd, 0x28, 0x0f, addr); in adv7842_cec_adap_log_addr()
2318 cec_write_clr_set(sd, 0x27, 0x20, 0x20); in adv7842_cec_adap_log_addr()
2320 cec_write_clr_set(sd, 0x28, 0xf0, addr << 4); in adv7842_cec_adap_log_addr()
2324 cec_write_clr_set(sd, 0x27, 0x40, 0x40); in adv7842_cec_adap_log_addr()
2326 cec_write_clr_set(sd, 0x29, 0x0f, addr); in adv7842_cec_adap_log_addr()
2336 struct v4l2_subdev *sd = &state->sd; in adv7842_cec_adap_transmit() local
2345 cec_write_clr_set(sd, 0x12, 0x70, max(1, attempts - 1) << 4); in adv7842_cec_adap_transmit()
2348 v4l2_err(sd, "%s: len exceeded 16 (%d)\n", __func__, len); in adv7842_cec_adap_transmit()
2354 cec_write(sd, i, msg->msg[i]); in adv7842_cec_adap_transmit()
2357 cec_write(sd, 0x10, len); in adv7842_cec_adap_transmit()
2359 cec_write(sd, 0x11, 0x01); in adv7842_cec_adap_transmit()
2370 static int adv7842_isr(struct v4l2_subdev *sd, u32 status, bool *handled) in adv7842_isr() argument
2372 struct adv7842_state *state = to_state(sd); in adv7842_isr()
2376 adv7842_irq_enable(sd, false); in adv7842_isr()
2379 irq_status[0] = io_read(sd, 0x43); in adv7842_isr()
2380 irq_status[1] = io_read(sd, 0x57); in adv7842_isr()
2381 irq_status[2] = io_read(sd, 0x70); in adv7842_isr()
2382 irq_status[3] = io_read(sd, 0x75); in adv7842_isr()
2383 irq_status[4] = io_read(sd, 0x9d); in adv7842_isr()
2384 irq_status[5] = io_read(sd, 0x66); in adv7842_isr()
2388 io_write(sd, 0x44, irq_status[0]); in adv7842_isr()
2390 io_write(sd, 0x58, irq_status[1]); in adv7842_isr()
2392 io_write(sd, 0x71, irq_status[2]); in adv7842_isr()
2394 io_write(sd, 0x76, irq_status[3]); in adv7842_isr()
2396 io_write(sd, 0x9e, irq_status[4]); in adv7842_isr()
2398 io_write(sd, 0x67, irq_status[5]); in adv7842_isr()
2400 adv7842_irq_enable(sd, true); in adv7842_isr()
2402 v4l2_dbg(1, debug, sd, "%s: irq %x, %x, %x, %x, %x, %x\n", __func__, in adv7842_isr()
2416 if (is_digital_input(sd)) in adv7842_isr()
2423 v4l2_dbg(1, debug, sd, in adv7842_isr()
2427 v4l2_subdev_notify_event(sd, &adv7842_ev_fmt); in adv7842_isr()
2434 v4l2_dbg(1, debug, sd, "%s: irq %s mode\n", __func__, in adv7842_isr()
2435 (io_read(sd, 0x65) & 0x08) ? "HDMI" : "DVI"); in adv7842_isr()
2436 set_rgb_quantization_range(sd); in adv7842_isr()
2443 adv7842_cec_isr(sd, handled); in adv7842_isr()
2448 v4l2_dbg(1, debug, sd, "%s: irq tx_5v\n", __func__); in adv7842_isr()
2449 adv7842_s_detect_tx_5v_ctrl(sd); in adv7842_isr()
2456 static int adv7842_get_edid(struct v4l2_subdev *sd, struct v4l2_edid *edid) in adv7842_get_edid() argument
2458 struct adv7842_state *state = to_state(sd); in adv7842_get_edid()
2496 static int adv7842_set_edid(struct v4l2_subdev *sd, struct v4l2_edid *e) in adv7842_set_edid() argument
2498 struct adv7842_state *state = to_state(sd); in adv7842_set_edid()
2521 err = edid_write_vga_segment(sd); in adv7842_set_edid()
2530 adv7842_s_detect_tx_5v_ctrl(sd); in adv7842_set_edid()
2533 err = edid_write_hdmi_segment(sd, e->pad); in adv7842_set_edid()
2539 v4l2_err(sd, "error %d writing edid on port %d\n", err, e->pad); in adv7842_set_edid()
2550 static void log_infoframe(struct v4l2_subdev *sd, const struct adv7842_cfg_read_infoframe *cri) in log_infoframe() argument
2556 struct i2c_client *client = v4l2_get_subdevdata(sd); in log_infoframe()
2559 if (!(io_read(sd, 0x60) & cri->present_mask)) { in log_infoframe()
2560 v4l2_info(sd, "%s infoframe not received\n", cri->desc); in log_infoframe()
2565 buffer[i] = infoframe_read(sd, cri->head_addr + i); in log_infoframe()
2570 v4l2_err(sd, "%s: invalid %s infoframe length %d\n", __func__, cri->desc, len); in log_infoframe()
2575 buffer[i + 3] = infoframe_read(sd, cri->payload_addr + i); in log_infoframe()
2578 v4l2_err(sd, "%s: unpack of %s infoframe failed\n", __func__, cri->desc); in log_infoframe()
2585 static void adv7842_log_infoframes(struct v4l2_subdev *sd) in adv7842_log_infoframes() argument
2595 if (!(hdmi_read(sd, 0x05) & 0x80)) { in adv7842_log_infoframes()
2596 v4l2_info(sd, "receive DVI-D signal, no infoframes\n"); in adv7842_log_infoframes()
2601 log_infoframe(sd, &cri[i]); in adv7842_log_infoframes()
2626 static int adv7842_sdp_log_status(struct v4l2_subdev *sd) in adv7842_sdp_log_status() argument
2629 u8 sdp_signal_detected = sdp_read(sd, 0x5A) & 0x01; in adv7842_sdp_log_status()
2631 v4l2_info(sd, "Chip powered %s\n", no_power(sd) ? "off" : "on"); in adv7842_sdp_log_status()
2632 v4l2_info(sd, "Prim-mode = 0x%x, video std = 0x%x\n", in adv7842_sdp_log_status()
2633 io_read(sd, 0x01) & 0x0f, io_read(sd, 0x00) & 0x3f); in adv7842_sdp_log_status()
2635 v4l2_info(sd, "SDP: free run: %s\n", in adv7842_sdp_log_status()
2636 (sdp_read(sd, 0x56) & 0x01) ? "on" : "off"); in adv7842_sdp_log_status()
2637 v4l2_info(sd, "SDP: %s\n", sdp_signal_detected ? in adv7842_sdp_log_status()
2638 "valid SD/PR signal detected" : "invalid/no signal"); in adv7842_sdp_log_status()
2654 v4l2_info(sd, "SDP: standard %s\n", in adv7842_sdp_log_status()
2655 sdp_std_txt[sdp_read(sd, 0x52) & 0x0f]); in adv7842_sdp_log_status()
2656 v4l2_info(sd, "SDP: %s\n", in adv7842_sdp_log_status()
2657 (sdp_read(sd, 0x59) & 0x08) ? "50Hz" : "60Hz"); in adv7842_sdp_log_status()
2658 v4l2_info(sd, "SDP: %s\n", in adv7842_sdp_log_status()
2659 (sdp_read(sd, 0x57) & 0x08) ? "Interlaced" : "Progressive"); in adv7842_sdp_log_status()
2660 v4l2_info(sd, "SDP: deinterlacer %s\n", in adv7842_sdp_log_status()
2661 (sdp_read(sd, 0x12) & 0x08) ? "enabled" : "disabled"); in adv7842_sdp_log_status()
2662 v4l2_info(sd, "SDP: csc %s mode\n", in adv7842_sdp_log_status()
2663 (sdp_io_read(sd, 0xe0) & 0x40) ? "auto" : "manual"); in adv7842_sdp_log_status()
2668 static int adv7842_cp_log_status(struct v4l2_subdev *sd) in adv7842_cp_log_status() argument
2671 struct adv7842_state *state = to_state(sd); in adv7842_cp_log_status()
2673 u8 reg_io_0x02 = io_read(sd, 0x02); in adv7842_cp_log_status()
2674 u8 reg_io_0x21 = io_read(sd, 0x21); in adv7842_cp_log_status()
2675 u8 reg_rep_0x77 = rep_read(sd, 0x77); in adv7842_cp_log_status()
2676 u8 reg_rep_0x7d = rep_read(sd, 0x7d); in adv7842_cp_log_status()
2677 bool audio_pll_locked = hdmi_read(sd, 0x04) & 0x01; in adv7842_cp_log_status()
2678 bool audio_sample_packet_detect = hdmi_read(sd, 0x18) & 0x01; in adv7842_cp_log_status()
2679 bool audio_mute = io_read(sd, 0x65) & 0x40; in adv7842_cp_log_status()
2707 v4l2_info(sd, "-----Chip status-----\n"); in adv7842_cp_log_status()
2708 v4l2_info(sd, "Chip power: %s\n", no_power(sd) ? "off" : "on"); in adv7842_cp_log_status()
2709 v4l2_info(sd, "HDMI/DVI-D port selected: %s\n", in adv7842_cp_log_status()
2711 v4l2_info(sd, "EDID A %s, B %s\n", in adv7842_cp_log_status()
2716 v4l2_info(sd, "HPD A %s, B %s\n", in adv7842_cp_log_status()
2719 v4l2_info(sd, "CEC: %s\n", state->cec_enabled_adap ? in adv7842_cp_log_status()
2728 v4l2_info(sd, "CEC Logical Address: 0x%x\n", in adv7842_cp_log_status()
2733 v4l2_info(sd, "-----Signal status-----\n"); in adv7842_cp_log_status()
2735 v4l2_info(sd, "Cable detected (+5V power): %s\n", in adv7842_cp_log_status()
2736 io_read(sd, 0x6f) & 0x02 ? "true" : "false"); in adv7842_cp_log_status()
2737 v4l2_info(sd, "TMDS signal detected: %s\n", in adv7842_cp_log_status()
2738 (io_read(sd, 0x6a) & 0x02) ? "true" : "false"); in adv7842_cp_log_status()
2739 v4l2_info(sd, "TMDS signal locked: %s\n", in adv7842_cp_log_status()
2740 (io_read(sd, 0x6a) & 0x20) ? "true" : "false"); in adv7842_cp_log_status()
2742 v4l2_info(sd, "Cable detected (+5V power):%s\n", in adv7842_cp_log_status()
2743 io_read(sd, 0x6f) & 0x01 ? "true" : "false"); in adv7842_cp_log_status()
2744 v4l2_info(sd, "TMDS signal detected: %s\n", in adv7842_cp_log_status()
2745 (io_read(sd, 0x6a) & 0x01) ? "true" : "false"); in adv7842_cp_log_status()
2746 v4l2_info(sd, "TMDS signal locked: %s\n", in adv7842_cp_log_status()
2747 (io_read(sd, 0x6a) & 0x10) ? "true" : "false"); in adv7842_cp_log_status()
2749 v4l2_info(sd, "CP free run: %s\n", in adv7842_cp_log_status()
2750 (!!(cp_read(sd, 0xff) & 0x10) ? "on" : "off")); in adv7842_cp_log_status()
2751 v4l2_info(sd, "Prim-mode = 0x%x, video std = 0x%x, v_freq = 0x%x\n", in adv7842_cp_log_status()
2752 io_read(sd, 0x01) & 0x0f, io_read(sd, 0x00) & 0x3f, in adv7842_cp_log_status()
2753 (io_read(sd, 0x01) & 0x70) >> 4); in adv7842_cp_log_status()
2755 v4l2_info(sd, "-----Video Timings-----\n"); in adv7842_cp_log_status()
2756 if (no_cp_signal(sd)) { in adv7842_cp_log_status()
2757 v4l2_info(sd, "STDI: not locked\n"); in adv7842_cp_log_status()
2759 u32 bl = ((cp_read(sd, 0xb1) & 0x3f) << 8) | cp_read(sd, 0xb2); in adv7842_cp_log_status()
2760 u32 lcf = ((cp_read(sd, 0xb3) & 0x7) << 8) | cp_read(sd, 0xb4); in adv7842_cp_log_status()
2761 u32 lcvs = cp_read(sd, 0xb3) >> 3; in adv7842_cp_log_status()
2762 u32 fcl = ((cp_read(sd, 0xb8) & 0x1f) << 8) | cp_read(sd, 0xb9); in adv7842_cp_log_status()
2763 char hs_pol = ((cp_read(sd, 0xb5) & 0x10) ? in adv7842_cp_log_status()
2764 ((cp_read(sd, 0xb5) & 0x08) ? '+' : '-') : 'x'); in adv7842_cp_log_status()
2765 char vs_pol = ((cp_read(sd, 0xb5) & 0x40) ? in adv7842_cp_log_status()
2766 ((cp_read(sd, 0xb5) & 0x20) ? '+' : '-') : 'x'); in adv7842_cp_log_status()
2767 v4l2_info(sd, in adv7842_cp_log_status()
2770 (cp_read(sd, 0xb1) & 0x40) ? in adv7842_cp_log_status()
2774 if (adv7842_query_dv_timings(sd, &timings)) in adv7842_cp_log_status()
2775 v4l2_info(sd, "No video detected\n"); in adv7842_cp_log_status()
2777 v4l2_print_dv_timings(sd->name, "Detected format: ", in adv7842_cp_log_status()
2779 v4l2_print_dv_timings(sd->name, "Configured format: ", in adv7842_cp_log_status()
2782 if (no_cp_signal(sd)) in adv7842_cp_log_status()
2785 v4l2_info(sd, "-----Color space-----\n"); in adv7842_cp_log_status()
2786 v4l2_info(sd, "RGB quantization range ctrl: %s\n", in adv7842_cp_log_status()
2788 v4l2_info(sd, "Input color space: %s\n", in adv7842_cp_log_status()
2790 v4l2_info(sd, "Output color space: %s %s, alt-gamma %s\n", in adv7842_cp_log_status()
2795 v4l2_info(sd, "Color space conversion: %s\n", in adv7842_cp_log_status()
2796 csc_coeff_sel_rb[cp_read(sd, 0xf4) >> 4]); in adv7842_cp_log_status()
2798 if (!is_digital_input(sd)) in adv7842_cp_log_status()
2801 v4l2_info(sd, "-----%s status-----\n", is_hdmi(sd) ? "HDMI" : "DVI-D"); in adv7842_cp_log_status()
2802 v4l2_info(sd, "HDCP encrypted content: %s\n", in adv7842_cp_log_status()
2803 (hdmi_read(sd, 0x05) & 0x40) ? "true" : "false"); in adv7842_cp_log_status()
2804 v4l2_info(sd, "HDCP keys read: %s%s\n", in adv7842_cp_log_status()
2805 (hdmi_read(sd, 0x04) & 0x20) ? "yes" : "no", in adv7842_cp_log_status()
2806 (hdmi_read(sd, 0x04) & 0x10) ? "ERROR" : ""); in adv7842_cp_log_status()
2807 if (!is_hdmi(sd)) in adv7842_cp_log_status()
2810 v4l2_info(sd, "Audio: pll %s, samples %s, %s\n", in adv7842_cp_log_status()
2815 v4l2_info(sd, "Audio format: %s\n", in adv7842_cp_log_status()
2816 (hdmi_read(sd, 0x07) & 0x40) ? "multi-channel" : "stereo"); in adv7842_cp_log_status()
2818 v4l2_info(sd, "Audio CTS: %u\n", (hdmi_read(sd, 0x5b) << 12) + in adv7842_cp_log_status()
2819 (hdmi_read(sd, 0x5c) << 8) + in adv7842_cp_log_status()
2820 (hdmi_read(sd, 0x5d) & 0xf0)); in adv7842_cp_log_status()
2821 v4l2_info(sd, "Audio N: %u\n", ((hdmi_read(sd, 0x5d) & 0x0f) << 16) + in adv7842_cp_log_status()
2822 (hdmi_read(sd, 0x5e) << 8) + in adv7842_cp_log_status()
2823 hdmi_read(sd, 0x5f)); in adv7842_cp_log_status()
2824 v4l2_info(sd, "AV Mute: %s\n", in adv7842_cp_log_status()
2825 (hdmi_read(sd, 0x04) & 0x40) ? "on" : "off"); in adv7842_cp_log_status()
2826 v4l2_info(sd, "Deep color mode: %s\n", in adv7842_cp_log_status()
2827 deep_color_mode_txt[hdmi_read(sd, 0x0b) >> 6]); in adv7842_cp_log_status()
2829 adv7842_log_infoframes(sd); in adv7842_cp_log_status()
2834 static int adv7842_log_status(struct v4l2_subdev *sd) in adv7842_log_status() argument
2836 struct adv7842_state *state = to_state(sd); in adv7842_log_status()
2839 return adv7842_sdp_log_status(sd); in adv7842_log_status()
2840 return adv7842_cp_log_status(sd); in adv7842_log_status()
2843 static int adv7842_querystd(struct v4l2_subdev *sd, v4l2_std_id *std) in adv7842_querystd() argument
2845 struct adv7842_state *state = to_state(sd); in adv7842_querystd()
2847 v4l2_dbg(1, debug, sd, "%s:\n", __func__); in adv7842_querystd()
2852 if (!(sdp_read(sd, 0x5A) & 0x01)) { in adv7842_querystd()
2854 v4l2_dbg(1, debug, sd, "%s: no valid signal\n", __func__); in adv7842_querystd()
2858 switch (sdp_read(sd, 0x52) & 0x0f) { in adv7842_querystd()
2898 static void adv7842_s_sdp_io(struct v4l2_subdev *sd, struct adv7842_sdp_io_sync_adjustment *s) in adv7842_s_sdp_io() argument
2901 sdp_io_write(sd, 0x94, (s->hs_beg >> 8) & 0xf); in adv7842_s_sdp_io()
2902 sdp_io_write(sd, 0x95, s->hs_beg & 0xff); in adv7842_s_sdp_io()
2903 sdp_io_write(sd, 0x96, (s->hs_width >> 8) & 0xf); in adv7842_s_sdp_io()
2904 sdp_io_write(sd, 0x97, s->hs_width & 0xff); in adv7842_s_sdp_io()
2905 sdp_io_write(sd, 0x98, (s->de_beg >> 8) & 0xf); in adv7842_s_sdp_io()
2906 sdp_io_write(sd, 0x99, s->de_beg & 0xff); in adv7842_s_sdp_io()
2907 sdp_io_write(sd, 0x9a, (s->de_end >> 8) & 0xf); in adv7842_s_sdp_io()
2908 sdp_io_write(sd, 0x9b, s->de_end & 0xff); in adv7842_s_sdp_io()
2909 sdp_io_write(sd, 0xa8, s->vs_beg_o); in adv7842_s_sdp_io()
2910 sdp_io_write(sd, 0xa9, s->vs_beg_e); in adv7842_s_sdp_io()
2911 sdp_io_write(sd, 0xaa, s->vs_end_o); in adv7842_s_sdp_io()
2912 sdp_io_write(sd, 0xab, s->vs_end_e); in adv7842_s_sdp_io()
2913 sdp_io_write(sd, 0xac, s->de_v_beg_o); in adv7842_s_sdp_io()
2914 sdp_io_write(sd, 0xad, s->de_v_beg_e); in adv7842_s_sdp_io()
2915 sdp_io_write(sd, 0xae, s->de_v_end_o); in adv7842_s_sdp_io()
2916 sdp_io_write(sd, 0xaf, s->de_v_end_e); in adv7842_s_sdp_io()
2919 sdp_io_write(sd, 0x94, 0x00); in adv7842_s_sdp_io()
2920 sdp_io_write(sd, 0x95, 0x00); in adv7842_s_sdp_io()
2921 sdp_io_write(sd, 0x96, 0x00); in adv7842_s_sdp_io()
2922 sdp_io_write(sd, 0x97, 0x20); in adv7842_s_sdp_io()
2923 sdp_io_write(sd, 0x98, 0x00); in adv7842_s_sdp_io()
2924 sdp_io_write(sd, 0x99, 0x00); in adv7842_s_sdp_io()
2925 sdp_io_write(sd, 0x9a, 0x00); in adv7842_s_sdp_io()
2926 sdp_io_write(sd, 0x9b, 0x00); in adv7842_s_sdp_io()
2927 sdp_io_write(sd, 0xa8, 0x04); in adv7842_s_sdp_io()
2928 sdp_io_write(sd, 0xa9, 0x04); in adv7842_s_sdp_io()
2929 sdp_io_write(sd, 0xaa, 0x04); in adv7842_s_sdp_io()
2930 sdp_io_write(sd, 0xab, 0x04); in adv7842_s_sdp_io()
2931 sdp_io_write(sd, 0xac, 0x04); in adv7842_s_sdp_io()
2932 sdp_io_write(sd, 0xad, 0x04); in adv7842_s_sdp_io()
2933 sdp_io_write(sd, 0xae, 0x04); in adv7842_s_sdp_io()
2934 sdp_io_write(sd, 0xaf, 0x04); in adv7842_s_sdp_io()
2938 static int adv7842_s_std(struct v4l2_subdev *sd, v4l2_std_id norm) in adv7842_s_std() argument
2940 struct adv7842_state *state = to_state(sd); in adv7842_s_std()
2943 v4l2_dbg(1, debug, sd, "%s:\n", __func__); in adv7842_s_std()
2949 adv7842_s_sdp_io(sd, &pdata->sdp_io_sync_625); in adv7842_s_std()
2951 adv7842_s_sdp_io(sd, &pdata->sdp_io_sync_525); in adv7842_s_std()
2953 adv7842_s_sdp_io(sd, NULL); in adv7842_s_std()
2962 static int adv7842_g_std(struct v4l2_subdev *sd, v4l2_std_id *norm) in adv7842_g_std() argument
2964 struct adv7842_state *state = to_state(sd); in adv7842_g_std()
2966 v4l2_dbg(1, debug, sd, "%s:\n", __func__); in adv7842_g_std()
2977 static int adv7842_core_init(struct v4l2_subdev *sd) in adv7842_core_init() argument
2979 struct adv7842_state *state = to_state(sd); in adv7842_core_init()
2981 hdmi_write(sd, 0x48, in adv7842_core_init()
2985 disable_input(sd); in adv7842_core_init()
2991 rep_write_and_or(sd, 0x77, 0xd3, 0x20); in adv7842_core_init()
2994 io_write(sd, 0x0c, 0x42); /* Power up part and power down VDP */ in adv7842_core_init()
2995 io_write(sd, 0x15, 0x80); /* Power up pads */ in adv7842_core_init()
2998 io_write(sd, 0x02, 0xf0 | pdata->alt_gamma << 3); in adv7842_core_init()
2999 io_write_and_or(sd, 0x05, 0xf0, pdata->blank_data << 3 | in adv7842_core_init()
3005 hdmi_write_and_or(sd, 0x1a, 0xf1, 0x08); /* Wait 1 s before unmute */ in adv7842_core_init()
3008 io_write_and_or(sd, 0x14, 0xc0, in adv7842_core_init()
3014 cp_write_and_or(sd, 0xba, 0xfc, pdata->hdmi_free_run_enable | in adv7842_core_init()
3018 sdp_write_and_or(sd, 0xdd, 0xf0, pdata->sdp_free_run_force | in adv7842_core_init()
3024 cp_write(sd, 0x69, 0x14); /* Enable CP CSC */ in adv7842_core_init()
3025 io_write(sd, 0x06, 0xa6); /* positive VS and HS and DE */ in adv7842_core_init()
3026 cp_write(sd, 0xf3, 0xdc); /* Low threshold to enter/exit free run mode */ in adv7842_core_init()
3027 afe_write(sd, 0xb5, 0x01); /* Setting MCLK to 256Fs */ in adv7842_core_init()
3029 afe_write(sd, 0x02, pdata->ain_sel); /* Select analog input muxing mode */ in adv7842_core_init()
3030 io_write_and_or(sd, 0x30, ~(1 << 4), pdata->output_bus_lsb_to_msb << 4); in adv7842_core_init()
3032 sdp_csc_coeff(sd, &pdata->sdp_csc_coeff); in adv7842_core_init()
3036 sdp_write(sd, 0x12, 0x0d); /* Frame TBC,3D comb enabled */ in adv7842_core_init()
3039 sdp_io_write(sd, 0x6f, 0x00); /* DDR mode */ in adv7842_core_init()
3040 sdp_io_write(sd, 0x75, 0x0a); /* 128 MB memory size */ in adv7842_core_init()
3041 sdp_io_write(sd, 0x7a, 0xa5); /* Timing Adjustment */ in adv7842_core_init()
3042 sdp_io_write(sd, 0x7b, 0x8f); /* Timing Adjustment */ in adv7842_core_init()
3043 sdp_io_write(sd, 0x60, 0x01); /* SDRAM reset */ in adv7842_core_init()
3045 sdp_io_write(sd, 0x75, 0x0a); /* 64 MB memory size ?*/ in adv7842_core_init()
3046 sdp_io_write(sd, 0x74, 0x00); /* must be zero for sdr sdram */ in adv7842_core_init()
3047 sdp_io_write(sd, 0x79, 0x33); /* CAS latency to 3, in adv7842_core_init()
3049 sdp_io_write(sd, 0x6f, 0x01); /* SDR mode */ in adv7842_core_init()
3050 sdp_io_write(sd, 0x7a, 0xa5); /* Timing Adjustment */ in adv7842_core_init()
3051 sdp_io_write(sd, 0x7b, 0x8f); /* Timing Adjustment */ in adv7842_core_init()
3052 sdp_io_write(sd, 0x60, 0x01); /* SDRAM reset */ in adv7842_core_init()
3059 sdp_io_write(sd, 0x29, 0x10); /* Tristate memory interface */ in adv7842_core_init()
3062 select_input(sd, pdata->vid_std_select); in adv7842_core_init()
3064 enable_input(sd); in adv7842_core_init()
3068 hdmi_write(sd, 0x69, 0x5c); in adv7842_core_init()
3071 hdmi_write(sd, 0x69, 0xa3); in adv7842_core_init()
3073 io_write_and_or(sd, 0x20, 0xcf, 0x00); in adv7842_core_init()
3077 io_write(sd, 0x19, 0x80 | pdata->llc_dll_phase); in adv7842_core_init()
3078 io_write(sd, 0x33, 0x40); in adv7842_core_init()
3081 io_write(sd, 0x40, 0xf2); /* Configure INT1 */ in adv7842_core_init()
3083 adv7842_irq_enable(sd, true); in adv7842_core_init()
3085 return v4l2_ctrl_handler_setup(sd->ctrl_handler); in adv7842_core_init()
3090 static int adv7842_ddr_ram_test(struct v4l2_subdev *sd) in adv7842_ddr_ram_test() argument
3103 io_write(sd, 0x00, 0x01); /* Program SDP 4x1 */ in adv7842_ddr_ram_test()
3104 io_write(sd, 0x01, 0x00); /* Program SDP mode */ in adv7842_ddr_ram_test()
3105 afe_write(sd, 0x80, 0x92); /* SDP Recommended Write */ in adv7842_ddr_ram_test()
3106 afe_write(sd, 0x9B, 0x01); /* SDP Recommended Write ADV7844ES1 */ in adv7842_ddr_ram_test()
3107 afe_write(sd, 0x9C, 0x60); /* SDP Recommended Write ADV7844ES1 */ in adv7842_ddr_ram_test()
3108 afe_write(sd, 0x9E, 0x02); /* SDP Recommended Write ADV7844ES1 */ in adv7842_ddr_ram_test()
3109 afe_write(sd, 0xA0, 0x0B); /* SDP Recommended Write ADV7844ES1 */ in adv7842_ddr_ram_test()
3110 afe_write(sd, 0xC3, 0x02); /* Memory BIST Initialisation */ in adv7842_ddr_ram_test()
3111 io_write(sd, 0x0C, 0x40); /* Power up ADV7844 */ in adv7842_ddr_ram_test()
3112 io_write(sd, 0x15, 0xBA); /* Enable outputs */ in adv7842_ddr_ram_test()
3113 sdp_write(sd, 0x12, 0x00); /* Disable 3D comb, Frame TBC & 3DNR */ in adv7842_ddr_ram_test()
3114 io_write(sd, 0xFF, 0x04); /* Reset memory controller */ in adv7842_ddr_ram_test()
3118 sdp_write(sd, 0x12, 0x00); /* Disable 3D Comb, Frame TBC & 3DNR */ in adv7842_ddr_ram_test()
3119 sdp_io_write(sd, 0x2A, 0x01); /* Memory BIST Initialisation */ in adv7842_ddr_ram_test()
3120 sdp_io_write(sd, 0x7c, 0x19); /* Memory BIST Initialisation */ in adv7842_ddr_ram_test()
3121 sdp_io_write(sd, 0x80, 0x87); /* Memory BIST Initialisation */ in adv7842_ddr_ram_test()
3122 sdp_io_write(sd, 0x81, 0x4a); /* Memory BIST Initialisation */ in adv7842_ddr_ram_test()
3123 sdp_io_write(sd, 0x82, 0x2c); /* Memory BIST Initialisation */ in adv7842_ddr_ram_test()
3124 sdp_io_write(sd, 0x83, 0x0e); /* Memory BIST Initialisation */ in adv7842_ddr_ram_test()
3125 sdp_io_write(sd, 0x84, 0x94); /* Memory BIST Initialisation */ in adv7842_ddr_ram_test()
3126 sdp_io_write(sd, 0x85, 0x62); /* Memory BIST Initialisation */ in adv7842_ddr_ram_test()
3127 sdp_io_write(sd, 0x7d, 0x00); /* Memory BIST Initialisation */ in adv7842_ddr_ram_test()
3128 sdp_io_write(sd, 0x7e, 0x1a); /* Memory BIST Initialisation */ in adv7842_ddr_ram_test()
3132 sdp_io_write(sd, 0xd9, 0xd5); /* Enable BIST Test */ in adv7842_ddr_ram_test()
3133 sdp_write(sd, 0x12, 0x05); /* Enable FRAME TBC & 3D COMB */ in adv7842_ddr_ram_test()
3138 u8 result = sdp_io_read(sd, 0xdb); in adv7842_ddr_ram_test()
3149 v4l2_dbg(1, debug, sd, in adv7842_ddr_ram_test()
3158 static void adv7842_rewrite_i2c_addresses(struct v4l2_subdev *sd, in adv7842_rewrite_i2c_addresses() argument
3161 io_write(sd, 0xf1, pdata->i2c_sdp << 1); in adv7842_rewrite_i2c_addresses()
3162 io_write(sd, 0xf2, pdata->i2c_sdp_io << 1); in adv7842_rewrite_i2c_addresses()
3163 io_write(sd, 0xf3, pdata->i2c_avlink << 1); in adv7842_rewrite_i2c_addresses()
3164 io_write(sd, 0xf4, pdata->i2c_cec << 1); in adv7842_rewrite_i2c_addresses()
3165 io_write(sd, 0xf5, pdata->i2c_infoframe << 1); in adv7842_rewrite_i2c_addresses()
3167 io_write(sd, 0xf8, pdata->i2c_afe << 1); in adv7842_rewrite_i2c_addresses()
3168 io_write(sd, 0xf9, pdata->i2c_repeater << 1); in adv7842_rewrite_i2c_addresses()
3169 io_write(sd, 0xfa, pdata->i2c_edid << 1); in adv7842_rewrite_i2c_addresses()
3170 io_write(sd, 0xfb, pdata->i2c_hdmi << 1); in adv7842_rewrite_i2c_addresses()
3172 io_write(sd, 0xfd, pdata->i2c_cp << 1); in adv7842_rewrite_i2c_addresses()
3173 io_write(sd, 0xfe, pdata->i2c_vdp << 1); in adv7842_rewrite_i2c_addresses()
3176 static int adv7842_command_ram_test(struct v4l2_subdev *sd) in adv7842_command_ram_test() argument
3178 struct i2c_client *client = v4l2_get_subdevdata(sd); in adv7842_command_ram_test()
3179 struct adv7842_state *state = to_state(sd); in adv7842_command_ram_test()
3188 v4l2_info(sd, "no sdram or no ddr sdram\n"); in adv7842_command_ram_test()
3192 main_reset(sd); in adv7842_command_ram_test()
3194 adv7842_rewrite_i2c_addresses(sd, pdata); in adv7842_command_ram_test()
3197 ret = adv7842_ddr_ram_test(sd); in adv7842_command_ram_test()
3199 main_reset(sd); in adv7842_command_ram_test()
3201 adv7842_rewrite_i2c_addresses(sd, pdata); in adv7842_command_ram_test()
3204 adv7842_core_init(sd); in adv7842_command_ram_test()
3206 disable_input(sd); in adv7842_command_ram_test()
3208 select_input(sd, state->vid_std_select); in adv7842_command_ram_test()
3210 enable_input(sd); in adv7842_command_ram_test()
3212 edid_write_vga_segment(sd); in adv7842_command_ram_test()
3213 edid_write_hdmi_segment(sd, ADV7842_EDID_PORT_A); in adv7842_command_ram_test()
3214 edid_write_hdmi_segment(sd, ADV7842_EDID_PORT_B); in adv7842_command_ram_test()
3220 adv7842_s_dv_timings(sd, &timings); in adv7842_command_ram_test()
3225 static long adv7842_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg) in adv7842_ioctl() argument
3229 return adv7842_command_ram_test(sd); in adv7842_ioctl()
3234 static int adv7842_subscribe_event(struct v4l2_subdev *sd, in adv7842_subscribe_event() argument
3240 return v4l2_src_change_event_subdev_subscribe(sd, fh, sub); in adv7842_subscribe_event()
3242 return v4l2_ctrl_subdev_subscribe_event(sd, fh, sub); in adv7842_subscribe_event()
3248 static int adv7842_registered(struct v4l2_subdev *sd) in adv7842_registered() argument
3250 struct adv7842_state *state = to_state(sd); in adv7842_registered()
3251 struct i2c_client *client = v4l2_get_subdevdata(sd); in adv7842_registered()
3260 static void adv7842_unregistered(struct v4l2_subdev *sd) in adv7842_unregistered() argument
3262 struct adv7842_state *state = to_state(sd); in adv7842_unregistered()
3351 static void adv7842_unregister_clients(struct v4l2_subdev *sd) in adv7842_unregister_clients() argument
3353 struct adv7842_state *state = to_state(sd); in adv7842_unregister_clients()
3379 static struct i2c_client *adv7842_dummy_client(struct v4l2_subdev *sd, const char *desc, in adv7842_dummy_client() argument
3382 struct i2c_client *client = v4l2_get_subdevdata(sd); in adv7842_dummy_client()
3385 io_write(sd, io_reg, addr << 1); in adv7842_dummy_client()
3388 v4l2_err(sd, "no %s i2c addr configured\n", desc); in adv7842_dummy_client()
3392 cp = i2c_new_dummy_device(client->adapter, io_read(sd, io_reg) >> 1); in adv7842_dummy_client()
3394 v4l2_err(sd, "register %s on i2c addr 0x%x failed with %ld\n", in adv7842_dummy_client()
3402 static int adv7842_register_clients(struct v4l2_subdev *sd) in adv7842_register_clients() argument
3404 struct adv7842_state *state = to_state(sd); in adv7842_register_clients()
3407 state->i2c_avlink = adv7842_dummy_client(sd, "avlink", pdata->i2c_avlink, 0xf3); in adv7842_register_clients()
3408 state->i2c_cec = adv7842_dummy_client(sd, "cec", pdata->i2c_cec, 0xf4); in adv7842_register_clients()
3409 state->i2c_infoframe = adv7842_dummy_client(sd, "infoframe", pdata->i2c_infoframe, 0xf5); in adv7842_register_clients()
3410 state->i2c_sdp_io = adv7842_dummy_client(sd, "sdp_io", pdata->i2c_sdp_io, 0xf2); in adv7842_register_clients()
3411 state->i2c_sdp = adv7842_dummy_client(sd, "sdp", pdata->i2c_sdp, 0xf1); in adv7842_register_clients()
3412 state->i2c_afe = adv7842_dummy_client(sd, "afe", pdata->i2c_afe, 0xf8); in adv7842_register_clients()
3413 state->i2c_repeater = adv7842_dummy_client(sd, "repeater", pdata->i2c_repeater, 0xf9); in adv7842_register_clients()
3414 state->i2c_edid = adv7842_dummy_client(sd, "edid", pdata->i2c_edid, 0xfa); in adv7842_register_clients()
3415 state->i2c_hdmi = adv7842_dummy_client(sd, "hdmi", pdata->i2c_hdmi, 0xfb); in adv7842_register_clients()
3416 state->i2c_cp = adv7842_dummy_client(sd, "cp", pdata->i2c_cp, 0xfd); in adv7842_register_clients()
3417 state->i2c_vdp = adv7842_dummy_client(sd, "vdp", pdata->i2c_vdp, 0xfe); in adv7842_register_clients()
3444 struct v4l2_subdev *sd; in adv7842_probe() local
3469 sd = &state->sd; in adv7842_probe()
3470 v4l2_i2c_subdev_init(sd, client, &adv7842_ops); in adv7842_probe()
3471 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS; in adv7842_probe()
3472 sd->internal_ops = &adv7842_int_ops; in adv7842_probe()
3482 v4l2_info(sd, "got rev=0x%04x on first read attempt\n", rev); in adv7842_probe()
3487 v4l2_info(sd, "not an adv7842 on address 0x%x (rev=0x%04x)\n", in adv7842_probe()
3493 main_reset(sd); in adv7842_probe()
3527 sd->ctrl_handler = hdl; in adv7842_probe()
3532 if (adv7842_s_detect_tx_5v_ctrl(sd)) { in adv7842_probe()
3537 if (adv7842_register_clients(sd) < 0) { in adv7842_probe()
3539 v4l2_err(sd, "failed to create all i2c clients\n"); in adv7842_probe()
3547 sd->entity.function = MEDIA_ENT_F_DV_DECODER; in adv7842_probe()
3549 err = media_entity_pads_init(&sd->entity, 1, &state->pad); in adv7842_probe()
3553 err = adv7842_core_init(sd); in adv7842_probe()
3566 v4l2_info(sd, "%s found @ 0x%x (%s)\n", client->name, in adv7842_probe()
3571 media_entity_cleanup(&sd->entity); in adv7842_probe()
3575 adv7842_unregister_clients(sd); in adv7842_probe()
3585 struct v4l2_subdev *sd = i2c_get_clientdata(client); in adv7842_remove() local
3586 struct adv7842_state *state = to_state(sd); in adv7842_remove()
3588 adv7842_irq_enable(sd, false); in adv7842_remove()
3590 v4l2_device_unregister_subdev(sd); in adv7842_remove()
3591 media_entity_cleanup(&sd->entity); in adv7842_remove()
3592 adv7842_unregister_clients(sd); in adv7842_remove()
3593 v4l2_ctrl_handler_free(sd->ctrl_handler); in adv7842_remove()