Lines Matching refs:sd

84 	struct v4l2_subdev sd;
127 static void adv7511_check_monitor_present_status(struct v4l2_subdev *sd);
128 static bool adv7511_check_edid_status(struct v4l2_subdev *sd);
129 static void adv7511_setup(struct v4l2_subdev *sd);
130 static int adv7511_s_i2s_clock_freq(struct v4l2_subdev *sd, u32 freq);
131 static int adv7511_s_clock_freq(struct v4l2_subdev *sd, u32 freq);
146 static inline struct adv7511_state *get_adv7511_state(struct v4l2_subdev *sd)
148 return container_of(sd, struct adv7511_state, sd);
153 return &container_of(ctrl->handler, struct adv7511_state, hdl)->sd;
188 static int adv7511_rd(struct v4l2_subdev *sd, u8 reg)
190 struct i2c_client *client = v4l2_get_subdevdata(sd);
195 static int adv7511_wr(struct v4l2_subdev *sd, u8 reg, u8 val)
197 struct i2c_client *client = v4l2_get_subdevdata(sd);
206 v4l2_err(sd, "%s: i2c write error\n", __func__);
212 static inline void adv7511_wr_and_or(struct v4l2_subdev *sd, u8 reg, u8 clr_mask, u8 val_mask)
214 adv7511_wr(sd, reg, (adv7511_rd(sd, reg) & clr_mask) | val_mask);
234 static void adv7511_edid_rd(struct v4l2_subdev *sd, uint16_t len, uint8_t *buf)
236 struct adv7511_state *state = get_adv7511_state(sd);
240 v4l2_dbg(1, debug, sd, "%s:\n", __func__);
246 v4l2_err(sd, "%s: i2c read error\n", __func__);
249 static inline int adv7511_cec_read(struct v4l2_subdev *sd, u8 reg)
251 struct adv7511_state *state = get_adv7511_state(sd);
256 static int adv7511_cec_write(struct v4l2_subdev *sd, u8 reg, u8 val)
258 struct adv7511_state *state = get_adv7511_state(sd);
267 v4l2_err(sd, "%s: I2C Write Problem\n", __func__);
271 static inline int adv7511_cec_write_and_or(struct v4l2_subdev *sd, u8 reg, u8 mask,
274 return adv7511_cec_write(sd, reg, (adv7511_cec_read(sd, reg) & mask) | val);
277 static int adv7511_pktmem_rd(struct v4l2_subdev *sd, u8 reg)
279 struct adv7511_state *state = get_adv7511_state(sd);
284 static int adv7511_pktmem_wr(struct v4l2_subdev *sd, u8 reg, u8 val)
286 struct adv7511_state *state = get_adv7511_state(sd);
295 v4l2_err(sd, "%s: i2c write error\n", __func__);
301 static inline void adv7511_pktmem_wr_and_or(struct v4l2_subdev *sd, u8 reg, u8 clr_mask, u8 val_mask)
303 adv7511_pktmem_wr(sd, reg, (adv7511_pktmem_rd(sd, reg) & clr_mask) | val_mask);
306 static inline bool adv7511_have_hotplug(struct v4l2_subdev *sd)
308 return adv7511_rd(sd, 0x42) & MASK_ADV7511_HPD_DETECT;
311 static inline bool adv7511_have_rx_sense(struct v4l2_subdev *sd)
313 return adv7511_rd(sd, 0x42) & MASK_ADV7511_MSEN_DETECT;
316 static void adv7511_csc_conversion_mode(struct v4l2_subdev *sd, u8 mode)
318 adv7511_wr_and_or(sd, 0x18, 0x9f, (mode & 0x3)<<5);
321 static void adv7511_csc_coeff(struct v4l2_subdev *sd,
327 adv7511_wr_and_or(sd, 0x18, 0xe0, A1>>8);
328 adv7511_wr(sd, 0x19, A1);
329 adv7511_wr_and_or(sd, 0x1A, 0xe0, A2>>8);
330 adv7511_wr(sd, 0x1B, A2);
331 adv7511_wr_and_or(sd, 0x1c, 0xe0, A3>>8);
332 adv7511_wr(sd, 0x1d, A3);
333 adv7511_wr_and_or(sd, 0x1e, 0xe0, A4>>8);
334 adv7511_wr(sd, 0x1f, A4);
337 adv7511_wr_and_or(sd, 0x20, 0xe0, B1>>8);
338 adv7511_wr(sd, 0x21, B1);
339 adv7511_wr_and_or(sd, 0x22, 0xe0, B2>>8);
340 adv7511_wr(sd, 0x23, B2);
341 adv7511_wr_and_or(sd, 0x24, 0xe0, B3>>8);
342 adv7511_wr(sd, 0x25, B3);
343 adv7511_wr_and_or(sd, 0x26, 0xe0, B4>>8);
344 adv7511_wr(sd, 0x27, B4);
347 adv7511_wr_and_or(sd, 0x28, 0xe0, C1>>8);
348 adv7511_wr(sd, 0x29, C1);
349 adv7511_wr_and_or(sd, 0x2A, 0xe0, C2>>8);
350 adv7511_wr(sd, 0x2B, C2);
351 adv7511_wr_and_or(sd, 0x2C, 0xe0, C3>>8);
352 adv7511_wr(sd, 0x2D, C3);
353 adv7511_wr_and_or(sd, 0x2E, 0xe0, C4>>8);
354 adv7511_wr(sd, 0x2F, C4);
357 static void adv7511_csc_rgb_full2limit(struct v4l2_subdev *sd, bool enable)
361 adv7511_csc_conversion_mode(sd, csc_mode);
362 adv7511_csc_coeff(sd,
367 adv7511_wr_and_or(sd, 0x18, 0x7f, 0x80);
369 adv7511_wr_and_or(sd, 0x57, 0xf3, 0x04);
372 adv7511_wr_and_or(sd, 0x18, 0x7f, 0x0);
374 adv7511_wr_and_or(sd, 0x57, 0xf3, 0x08);
378 static void adv7511_set_rgb_quantization_mode(struct v4l2_subdev *sd, struct v4l2_ctrl *ctrl)
380 struct adv7511_state *state = get_adv7511_state(sd);
385 adv7511_csc_rgb_full2limit(sd, false);
394 adv7511_csc_rgb_full2limit(sd, true);
397 adv7511_csc_rgb_full2limit(sd, false);
402 adv7511_csc_rgb_full2limit(sd, true);
406 adv7511_csc_rgb_full2limit(sd, false);
415 struct v4l2_subdev *sd = to_sd(ctrl);
416 struct adv7511_state *state = get_adv7511_state(sd);
418 v4l2_dbg(1, debug, sd, "%s: ctrl id: %d, ctrl->val %d\n", __func__, ctrl->id, ctrl->val);
422 adv7511_wr_and_or(sd, 0xaf, 0xfd, ctrl->val == V4L2_DV_TX_MODE_HDMI ? 0x02 : 0x00);
426 adv7511_set_rgb_quantization_mode(sd, ctrl);
435 adv7511_wr_and_or(sd, 0x57, 0x7f, itc << 7);
436 adv7511_wr_and_or(sd, 0x59, 0xcf, cn << 4);
450 static void adv7511_inv_register(struct v4l2_subdev *sd)
452 struct adv7511_state *state = get_adv7511_state(sd);
454 v4l2_info(sd, "0x000-0x0ff: Main Map\n");
456 v4l2_info(sd, "0x100-0x1ff: CEC Map\n");
459 static int adv7511_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
461 struct adv7511_state *state = get_adv7511_state(sd);
466 reg->val = adv7511_rd(sd, reg->reg & 0xff);
470 reg->val = adv7511_cec_read(sd, reg->reg & 0xff);
475 v4l2_info(sd, "Register %03llx not supported\n", reg->reg);
476 adv7511_inv_register(sd);
482 static int adv7511_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
484 struct adv7511_state *state = get_adv7511_state(sd);
488 adv7511_wr(sd, reg->reg & 0xff, reg->val & 0xff);
492 adv7511_cec_write(sd, reg->reg & 0xff, reg->val & 0xff);
497 v4l2_info(sd, "Register %03llx not supported\n", reg->reg);
498 adv7511_inv_register(sd);
525 static void log_infoframe(struct v4l2_subdev *sd, const struct adv7511_cfg_read_infoframe *cri)
527 struct i2c_client *client = v4l2_get_subdevdata(sd);
534 if (!(adv7511_rd(sd, cri->present_reg) & cri->present_mask)) {
535 v4l2_info(sd, "%s infoframe not transmitted\n", cri->desc);
544 v4l2_err(sd, "%s: invalid %s infoframe length %d\n", __func__, cri->desc, len);
550 buffer[i + 4] = adv7511_pktmem_rd(sd, cri->payload_addr + i - 0x100);
553 buffer[i + 4] = adv7511_rd(sd, cri->payload_addr + i);
559 v4l2_err(sd, "%s: unpack of %s infoframe failed\n", __func__, cri->desc);
566 static void adv7511_log_infoframes(struct v4l2_subdev *sd)
576 log_infoframe(sd, &cri[i]);
579 static int adv7511_log_status(struct v4l2_subdev *sd)
581 struct adv7511_state *state = get_adv7511_state(sd);
607 v4l2_info(sd, "power %s\n", state->power_on ? "on" : "off");
608 v4l2_info(sd, "%s hotplug, %s Rx Sense, %s EDID (%d block(s))\n",
609 (adv7511_rd(sd, 0x42) & MASK_ADV7511_HPD_DETECT) ? "detected" : "no",
610 (adv7511_rd(sd, 0x42) & MASK_ADV7511_MSEN_DETECT) ? "detected" : "no",
613 v4l2_info(sd, "%s output %s\n",
614 (adv7511_rd(sd, 0xaf) & 0x02) ?
616 (adv7511_rd(sd, 0xa1) & 0x3c) ?
618 v4l2_info(sd, "state: %s, error: %s, detect count: %u, msk/irq: %02x/%02x\n",
619 states[adv7511_rd(sd, 0xc8) & 0xf],
620 errors[adv7511_rd(sd, 0xc8) >> 4], state->edid_detect_counter,
621 adv7511_rd(sd, 0x94), adv7511_rd(sd, 0x96));
622 v4l2_info(sd, "RGB quantization: %s range\n", adv7511_rd(sd, 0x18) & 0x80 ? "limited" : "full");
623 if (adv7511_rd(sd, 0xaf) & 0x02) {
625 u8 manual_cts = adv7511_rd(sd, 0x0a) & 0x80;
626 u32 N = (adv7511_rd(sd, 0x01) & 0xf) << 16 |
627 adv7511_rd(sd, 0x02) << 8 |
628 adv7511_rd(sd, 0x03);
629 u8 vic_detect = adv7511_rd(sd, 0x3e) >> 2;
630 u8 vic_sent = adv7511_rd(sd, 0x3d) & 0x3f;
634 CTS = (adv7511_rd(sd, 0x07) & 0xf) << 16 |
635 adv7511_rd(sd, 0x08) << 8 |
636 adv7511_rd(sd, 0x09);
638 CTS = (adv7511_rd(sd, 0x04) & 0xf) << 16 |
639 adv7511_rd(sd, 0x05) << 8 |
640 adv7511_rd(sd, 0x06);
641 v4l2_info(sd, "CTS %s mode: N %d, CTS %d\n",
643 v4l2_info(sd, "VIC: detected %d, sent %d\n",
645 adv7511_log_infoframes(sd);
648 v4l2_print_dv_timings(sd->name, "timings: ",
651 v4l2_info(sd, "no timings set\n");
652 v4l2_info(sd, "i2c edid addr: 0x%x\n", state->i2c_edid_addr);
657 v4l2_info(sd, "i2c cec addr: 0x%x\n", state->i2c_cec_addr);
659 v4l2_info(sd, "CEC: %s\n", state->cec_enabled_adap ?
666 v4l2_info(sd, "CEC Logical Address: 0x%x\n",
670 v4l2_info(sd, "i2c pktmem addr: 0x%x\n", state->i2c_pktmem_addr);
675 static int adv7511_s_power(struct v4l2_subdev *sd, int on)
677 struct adv7511_state *state = get_adv7511_state(sd);
681 v4l2_dbg(1, debug, sd, "%s: power %s\n", __func__, on ? "on" : "off");
687 adv7511_wr_and_or(sd, 0x41, 0xbf, 0x40);
695 adv7511_wr_and_or(sd, 0x41, 0xbf, 0x0);
696 if ((adv7511_rd(sd, 0x41) & 0x40) == 0)
698 adv7511_wr_and_or(sd, 0x41, 0xbf, 0x40);
702 v4l2_dbg(1, debug, sd, "%s: failed to powerup the adv7511!\n", __func__);
703 adv7511_s_power(sd, 0);
707 v4l2_dbg(1, debug, sd, "%s: needed %d retries to powerup the adv7511\n", __func__, i);
710 adv7511_wr(sd, 0x98, 0x03);
711 adv7511_wr_and_or(sd, 0x9a, 0xfe, 0x70);
712 adv7511_wr(sd, 0x9c, 0x30);
713 adv7511_wr_and_or(sd, 0x9d, 0xfc, 0x01);
714 adv7511_wr(sd, 0xa2, 0xa4);
715 adv7511_wr(sd, 0xa3, 0xa4);
716 adv7511_wr(sd, 0xe0, 0xd0);
717 adv7511_wr(sd, 0xf9, 0x00);
719 adv7511_wr(sd, 0x43, state->i2c_edid_addr);
720 adv7511_wr(sd, 0x45, state->i2c_pktmem_addr);
723 adv7511_wr(sd, 0xc9, 0xf);
731 struct v4l2_subdev *sd = &state->sd;
738 adv7511_cec_write_and_or(sd, 0x4e, 0xfc, 0x01);
740 adv7511_cec_write(sd, 0x4a, 0x00);
741 adv7511_cec_write(sd, 0x4a, 0x07);
742 adv7511_cec_write_and_or(sd, 0x11, 0xfe, 0); /* initially disable tx */
749 adv7511_wr_and_or(sd, 0x95, 0xc0, 0x39);
752 adv7511_wr_and_or(sd, 0x95, 0xc0, 0x00);
754 adv7511_cec_write_and_or(sd, 0x4b, 0x8f, 0x00);
756 adv7511_cec_write_and_or(sd, 0x4e, 0xfc, 0x00);
766 struct v4l2_subdev *sd = &state->sd;
773 adv7511_cec_write_and_or(sd, 0x4b, 0x8f, 0);
797 adv7511_cec_write_and_or(sd, 0x4b, 0xef, 0x10);
799 adv7511_cec_write_and_or(sd, 0x4c, 0xf0, addr);
803 adv7511_cec_write_and_or(sd, 0x4b, 0xdf, 0x20);
805 adv7511_cec_write_and_or(sd, 0x4c, 0x0f, addr << 4);
809 adv7511_cec_write_and_or(sd, 0x4b, 0xbf, 0x40);
811 adv7511_cec_write_and_or(sd, 0x4d, 0xf0, addr);
821 struct v4l2_subdev *sd = &state->sd;
825 v4l2_dbg(1, debug, sd, "%s: len %d\n", __func__, len);
828 v4l2_err(sd, "%s: len exceeded 16 (%d)\n", __func__, len);
837 adv7511_cec_write_and_or(sd, 0x12, ~0x70, max(1, attempts - 1) << 4);
840 adv7511_wr(sd, 0x97, 0x38);
844 adv7511_cec_write(sd, i, msg->msg[i]);
847 adv7511_cec_write(sd, 0x10, len);
849 adv7511_cec_write(sd, 0x11, 0x01);
853 static void adv_cec_tx_raw_status(struct v4l2_subdev *sd, u8 tx_raw_status)
855 struct adv7511_state *state = get_adv7511_state(sd);
857 if ((adv7511_cec_read(sd, 0x11) & 0x01) == 0) {
858 v4l2_dbg(1, debug, sd, "%s: tx raw: tx disabled\n", __func__);
863 v4l2_dbg(1, debug, sd,
874 v4l2_dbg(1, debug, sd, "%s: tx raw: retry failed\n", __func__);
880 nack_cnt = adv7511_cec_read(sd, 0x14) & 0xf;
883 low_drive_cnt = adv7511_cec_read(sd, 0x14) >> 4;
891 v4l2_dbg(1, debug, sd, "%s: tx raw: ready ok\n", __func__);
905 static void adv7511_set_isr(struct v4l2_subdev *sd, bool enable)
907 struct adv7511_state *state = get_adv7511_state(sd);
912 v4l2_dbg(2, debug, sd, "%s: %s\n", __func__, enable ? "enable" : "disable");
922 else if (adv7511_have_hotplug(sd))
934 adv7511_wr(sd, 0x94, irqs);
935 irqs_rd = adv7511_rd(sd, 0x94);
939 v4l2_err(sd, "Could not set interrupts: hw failure?\n");
941 adv7511_wr_and_or(sd, 0x95, 0xc0,
946 static int adv7511_isr(struct v4l2_subdev *sd, u32 status, bool *handled)
952 adv7511_set_isr(sd, false);
953 irq_status = adv7511_rd(sd, 0x96);
954 cec_irq = adv7511_rd(sd, 0x97);
956 adv7511_wr(sd, 0x96, irq_status);
957 adv7511_wr(sd, 0x97, cec_irq);
959 v4l2_dbg(1, debug, sd, "%s: irq 0x%x, cec-irq 0x%x\n", __func__,
963 adv7511_check_monitor_present_status(sd);
965 adv7511_check_edid_status(sd);
969 adv_cec_tx_raw_status(sd, cec_irq);
972 struct adv7511_state *state = get_adv7511_state(sd);
975 msg.len = adv7511_cec_read(sd, 0x25) & 0x1f;
977 v4l2_dbg(1, debug, sd, "%s: cec msg len %d\n", __func__,
987 msg.msg[i] = adv7511_cec_read(sd, i + 0x15);
989 adv7511_cec_write(sd, 0x4a, 0); /* toggle to re-enable rx 1 */
990 adv7511_cec_write(sd, 0x4a, 1);
997 adv7511_set_isr(sd, true);
1017 static int adv7511_s_stream(struct v4l2_subdev *sd, int enable)
1019 struct adv7511_state *state = get_adv7511_state(sd);
1021 v4l2_dbg(1, debug, sd, "%s: %sable\n", __func__, (enable ? "en" : "dis"));
1022 adv7511_wr_and_or(sd, 0xa1, ~0x3c, (enable ? 0 : 0x3c));
1024 adv7511_check_monitor_present_status(sd);
1026 adv7511_s_power(sd, 0);
1032 static int adv7511_s_dv_timings(struct v4l2_subdev *sd,
1035 struct adv7511_state *state = get_adv7511_state(sd);
1039 v4l2_dbg(1, debug, sd, "%s:\n", __func__);
1053 adv7511_wr_and_or(sd, 0x17, 0x9f,
1060 adv7511_wr_and_or(sd, 0xfb, 0xf9, 1 << 1);
1063 adv7511_wr_and_or(sd, 0xfb, 0xf9, 2 << 1);
1066 adv7511_wr_and_or(sd, 0xfb, 0xf9, 3 << 1);
1069 adv7511_wr_and_or(sd, 0xfb, 0xf9, 0);
1074 adv7511_set_rgb_quantization_mode(sd, state->rgb_quantization_range_ctrl);
1079 static int adv7511_g_dv_timings(struct v4l2_subdev *sd,
1082 struct adv7511_state *state = get_adv7511_state(sd);
1084 v4l2_dbg(1, debug, sd, "%s:\n", __func__);
1094 static int adv7511_enum_dv_timings(struct v4l2_subdev *sd,
1103 static int adv7511_dv_timings_cap(struct v4l2_subdev *sd,
1120 static int adv7511_s_audio_stream(struct v4l2_subdev *sd, int enable)
1122 v4l2_dbg(1, debug, sd, "%s: %sable\n", __func__, (enable ? "en" : "dis"));
1125 adv7511_wr_and_or(sd, 0x4b, 0x3f, 0x80);
1127 adv7511_wr_and_or(sd, 0x4b, 0x3f, 0x40);
1132 static int adv7511_s_clock_freq(struct v4l2_subdev *sd, u32 freq)
1149 adv7511_wr(sd, 0x01, (N >> 16) & 0xf);
1150 adv7511_wr(sd, 0x02, (N >> 8) & 0xff);
1151 adv7511_wr(sd, 0x03, N & 0xff);
1156 static int adv7511_s_i2s_clock_freq(struct v4l2_subdev *sd, u32 freq)
1173 adv7511_wr_and_or(sd, 0x15, 0xf, i2s_sf);
1178 static int adv7511_s_routing(struct v4l2_subdev *sd, u32 input, u32 output, u32 config)
1181 adv7511_wr_and_or(sd, 0x73, 0xf8, 0x1);
1183 adv7511_wr(sd, 0x76, 0x00);
1186 adv7511_wr_and_or(sd, 0x14, 0xf0, 0x02);
1200 static int adv7511_get_edid(struct v4l2_subdev *sd, struct v4l2_edid *edid)
1202 struct adv7511_state *state = get_adv7511_state(sd);
1229 static int adv7511_enum_mbus_code(struct v4l2_subdev *sd,
1260 static int adv7511_get_fmt(struct v4l2_subdev *sd,
1264 struct adv7511_state *state = get_adv7511_state(sd);
1275 fmt = v4l2_subdev_get_try_format(sd, cfg, format->pad);
1292 static int adv7511_set_fmt(struct v4l2_subdev *sd,
1296 struct adv7511_state *state = get_adv7511_state(sd);
1330 fmt = v4l2_subdev_get_try_format(sd, cfg, format->pad);
1341 adv7511_wr_and_or(sd, 0x15, 0xf0, 0x01);
1342 adv7511_wr_and_or(sd, 0x16, 0x03, 0xb8);
1346 adv7511_wr_and_or(sd, 0x15, 0xf0, 0x01);
1347 adv7511_wr_and_or(sd, 0x16, 0x03, 0xbc);
1352 adv7511_wr_and_or(sd, 0x15, 0xf0, 0x00);
1353 adv7511_wr_and_or(sd, 0x16, 0x03, 0x00);
1424 adv7511_wr_and_or(sd, 0x4a, 0xbf, 0);
1425 adv7511_wr_and_or(sd, 0x55, 0x9f, y << 5);
1426 adv7511_wr_and_or(sd, 0x56, 0x3f, c << 6);
1427 adv7511_wr_and_or(sd, 0x57, 0x83, (ec << 4) | (q << 2) | (itc << 7));
1428 adv7511_wr_and_or(sd, 0x59, 0x0f, (yq << 6) | (cn << 4));
1429 adv7511_wr_and_or(sd, 0x4a, 0xff, 1);
1430 adv7511_set_rgb_quantization_mode(sd, state->rgb_quantization_range_ctrl);
1454 static void adv7511_dbg_dump_edid(int lvl, int debug, struct v4l2_subdev *sd, int segment, u8 *buf)
1458 v4l2_dbg(lvl, debug, sd, "edid segment %d\n", segment);
1463 v4l2_dbg(lvl, debug, sd, "\n");
1469 v4l2_dbg(lvl, debug, sd, "%s\n", b);
1474 static void adv7511_notify_no_edid(struct v4l2_subdev *sd)
1476 struct adv7511_state *state = get_adv7511_state(sd);
1481 ed.segment = adv7511_rd(sd, 0xc4);
1484 v4l2_subdev_notify(sd, ADV7511_EDID_DETECT, (void *)&ed);
1492 struct v4l2_subdev *sd = &state->sd;
1494 v4l2_dbg(1, debug, sd, "%s:\n", __func__);
1496 if (adv7511_check_edid_status(sd)) {
1501 if (adv7511_have_hotplug(sd)) {
1507 v4l2_dbg(1, debug, sd, "%s: edid read failed\n", __func__);
1509 adv7511_s_power(sd, false);
1510 adv7511_s_power(sd, true);
1517 adv7511_notify_no_edid(sd);
1518 v4l2_dbg(1, debug, sd, "%s: no edid found\n", __func__);
1521 static void adv7511_audio_setup(struct v4l2_subdev *sd)
1523 v4l2_dbg(1, debug, sd, "%s\n", __func__);
1525 adv7511_s_i2s_clock_freq(sd, 48000);
1526 adv7511_s_clock_freq(sd, 48000);
1527 adv7511_s_routing(sd, 0, 0, 0);
1531 static void adv7511_setup(struct v4l2_subdev *sd)
1533 struct adv7511_state *state = get_adv7511_state(sd);
1534 v4l2_dbg(1, debug, sd, "%s\n", __func__);
1537 adv7511_wr_and_or(sd, 0x15, 0xf0, 0x0);
1539 adv7511_wr_and_or(sd, 0x16, 0x7f, 0x0);
1541 adv7511_wr_and_or(sd, 0x17, 0xf9, 0x06);
1543 adv7511_wr_and_or(sd, 0x3b, 0x9f, 0x0);
1545 adv7511_wr_and_or(sd, 0x18, 0x7f, 0x0);
1548 adv7511_wr_and_or(sd, 0x55, 0x9c, 0x12);
1550 adv7511_wr_and_or(sd, 0x44, 0xe7, 0x10);
1552 adv7511_wr(sd, 0x56, 0xa8);
1554 adv7511_wr_and_or(sd, 0xaf, 0xed, 0x0);
1557 adv7511_wr_and_or(sd, 0xba, 0x1f, 0x60);
1559 adv7511_audio_setup(sd);
1564 static void adv7511_notify_monitor_detect(struct v4l2_subdev *sd)
1567 struct adv7511_state *state = get_adv7511_state(sd);
1570 v4l2_subdev_notify(sd, ADV7511_MONITOR_DETECT, (void *)&mdt);
1573 static void adv7511_check_monitor_present_status(struct v4l2_subdev *sd)
1575 struct adv7511_state *state = get_adv7511_state(sd);
1577 u8 status = adv7511_rd(sd, 0x42);
1579 v4l2_dbg(1, debug, sd, "%s: status: 0x%x%s%s\n",
1586 v4l2_ctrl_s_ctrl(state->hotplug_ctrl, adv7511_have_hotplug(sd) ? 0x1 : 0x0);
1587 v4l2_ctrl_s_ctrl(state->rx_sense_ctrl, adv7511_have_rx_sense(sd) ? 0x1 : 0x0);
1590 v4l2_dbg(1, debug, sd, "%s: hotplug and (rx-sense or edid)\n", __func__);
1592 v4l2_dbg(1, debug, sd, "%s: monitor detected\n", __func__);
1594 adv7511_set_isr(sd, true);
1595 if (!adv7511_s_power(sd, true)) {
1596 v4l2_dbg(1, debug, sd, "%s: monitor detected, powerup failed\n", __func__);
1599 adv7511_setup(sd);
1600 adv7511_notify_monitor_detect(sd);
1605 v4l2_dbg(1, debug, sd, "%s: hotplug detected\n", __func__);
1609 v4l2_dbg(1, debug, sd, "%s: hotplug not detected\n", __func__);
1611 v4l2_dbg(1, debug, sd, "%s: monitor not detected\n", __func__);
1613 adv7511_notify_monitor_detect(sd);
1615 adv7511_s_power(sd, false);
1617 adv7511_notify_no_edid(sd);
1631 static bool edid_verify_crc(struct v4l2_subdev *sd, u32 segment)
1633 struct adv7511_state *state = get_adv7511_state(sd);
1644 static bool edid_verify_header(struct v4l2_subdev *sd, u32 segment)
1649 struct adv7511_state *state = get_adv7511_state(sd);
1657 static bool adv7511_check_edid_status(struct v4l2_subdev *sd)
1659 struct adv7511_state *state = get_adv7511_state(sd);
1660 u8 edidRdy = adv7511_rd(sd, 0xc5);
1662 v4l2_dbg(1, debug, sd, "%s: edid ready (retries: %d)\n",
1669 int segment = adv7511_rd(sd, 0xc4);
1673 v4l2_err(sd, "edid segment number too big\n");
1676 v4l2_dbg(1, debug, sd, "%s: got segment %d\n", __func__, segment);
1677 adv7511_edid_rd(sd, 256, &state->edid.data[segment * 256]);
1678 adv7511_dbg_dump_edid(2, debug, sd, segment, &state->edid.data[segment * 256]);
1681 v4l2_dbg(1, debug, sd, "%s: %d blocks in total\n", __func__, state->edid.blocks);
1683 if (!edid_verify_crc(sd, segment) ||
1684 !edid_verify_header(sd, segment)) {
1686 v4l2_err(sd, "%s: edid crc or header error\n", __func__);
1688 adv7511_s_power(sd, false);
1689 adv7511_s_power(sd, true);
1697 v4l2_dbg(1, debug, sd, "%s: request segment %d\n", __func__, state->edid.segments);
1698 adv7511_wr(sd, 0xc9, 0xf);
1699 adv7511_wr(sd, 0xc4, state->edid.segments);
1705 v4l2_dbg(1, debug, sd, "%s: edid complete with %d segment(s)\n", __func__, state->edid.segments);
1717 v4l2_subdev_notify(sd, ADV7511_EDID_DETECT, (void *)&ed);
1724 static int adv7511_registered(struct v4l2_subdev *sd)
1726 struct adv7511_state *state = get_adv7511_state(sd);
1727 struct i2c_client *client = v4l2_get_subdevdata(sd);
1736 static void adv7511_unregistered(struct v4l2_subdev *sd)
1738 struct adv7511_state *state = get_adv7511_state(sd);
1750 static void adv7511_init_setup(struct v4l2_subdev *sd)
1752 struct adv7511_state *state = get_adv7511_state(sd);
1757 v4l2_dbg(1, debug, sd, "%s\n", __func__);
1760 adv7511_wr(sd, 0x96, 0xff);
1761 adv7511_wr(sd, 0x97, 0xff);
1767 adv7511_wr_and_or(sd, 0xd6, 0x3f, 0xc0);
1770 adv7511_set_isr(sd, false);
1771 adv7511_s_stream(sd, false);
1772 adv7511_s_audio_stream(sd, false);
1777 v4l2_dbg(1, debug, sd, "%s: cec_clk %d\n", __func__, cec_clk);
1780 adv7511_cec_write(sd, 0x50, 0x01);
1781 adv7511_cec_write(sd, 0x50, 0x00);
1784 adv7511_cec_write(sd, 0x4a, 0x00);
1785 adv7511_cec_write(sd, 0x4a, 0x07);
1788 v4l2_err(sd, "%s: cec_clk %d, not multiple of 750 Khz\n",
1792 adv7511_cec_write(sd, 0x4e, ratio << 2);
1800 struct v4l2_subdev *sd;
1821 sd = &state->sd;
1823 v4l2_dbg(1, debug, sd, "detecting adv7511 client on address 0x%x\n",
1826 v4l2_i2c_subdev_init(sd, client, &adv7511_ops);
1827 sd->internal_ops = &adv7511_int_ops;
1849 sd->ctrl_handler = hdl;
1855 sd->entity.function = MEDIA_ENT_F_DV_ENCODER;
1856 err = media_entity_pads_init(&sd->entity, 1, &state->pad);
1865 state->chip_revision = adv7511_rd(sd, 0x0);
1866 chip_id[0] = adv7511_rd(sd, 0xf5);
1867 chip_id[1] = adv7511_rd(sd, 0xf6);
1869 v4l2_err(sd, "chip_id != 0x7511, read 0x%02x%02x\n", chip_id[0],
1878 v4l2_err(sd, "failed to register edid i2c client\n");
1883 adv7511_wr(sd, 0xe1, state->i2c_cec_addr);
1886 v4l2_err(sd, "%s: cec_clk %u outside range, disabling cec\n",
1895 v4l2_err(sd, "failed to register cec i2c client\n");
1899 adv7511_wr(sd, 0xe2, 0x00); /* power up cec section */
1901 adv7511_wr(sd, 0xe2, 0x01); /* power down cec section */
1906 v4l2_err(sd, "failed to register pktmem i2c client\n");
1911 state->work_queue = create_singlethread_workqueue(sd->name);
1913 v4l2_err(sd, "could not create workqueue\n");
1920 adv7511_init_setup(sd);
1933 adv7511_set_isr(sd, true);
1934 adv7511_check_monitor_present_status(sd);
1936 v4l2_info(sd, "%s found @ 0x%x (%s)\n", client->name,
1947 media_entity_cleanup(&sd->entity);
1957 struct v4l2_subdev *sd = i2c_get_clientdata(client);
1958 struct adv7511_state *state = get_adv7511_state(sd);
1962 v4l2_dbg(1, debug, sd, "%s removed @ 0x%x (%s)\n", client->name,
1965 adv7511_set_isr(sd, false);
1966 adv7511_init_setup(sd);
1972 v4l2_device_unregister_subdev(sd);
1973 media_entity_cleanup(&sd->entity);
1974 v4l2_ctrl_handler_free(sd->ctrl_handler);