Lines Matching full:sd

84 	struct v4l2_subdev sd;  member
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) in get_adv7511_state() argument
148 return container_of(sd, struct adv7511_state, sd); in get_adv7511_state()
153 return &container_of(ctrl->handler, struct adv7511_state, hdl)->sd; in to_sd()
188 static int adv7511_rd(struct v4l2_subdev *sd, u8 reg) in adv7511_rd() argument
190 struct i2c_client *client = v4l2_get_subdevdata(sd); in adv7511_rd()
195 static int adv7511_wr(struct v4l2_subdev *sd, u8 reg, u8 val) in adv7511_wr() argument
197 struct i2c_client *client = v4l2_get_subdevdata(sd); in adv7511_wr()
206 v4l2_err(sd, "%s: i2c write error\n", __func__); in adv7511_wr()
212 static inline void adv7511_wr_and_or(struct v4l2_subdev *sd, u8 reg, u8 clr_mask, u8 val_mask) in adv7511_wr_and_or() argument
214 adv7511_wr(sd, reg, (adv7511_rd(sd, reg) & clr_mask) | val_mask); in adv7511_wr_and_or()
217 static int adv7511_edid_rd(struct v4l2_subdev *sd, uint16_t len, uint8_t *buf) in adv7511_edid_rd() argument
219 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_edid_rd()
222 v4l2_dbg(1, debug, sd, "%s:\n", __func__); in adv7511_edid_rd()
230 v4l2_err(sd, "%s: i2c read error\n", __func__); in adv7511_edid_rd()
238 static inline int adv7511_cec_read(struct v4l2_subdev *sd, u8 reg) in adv7511_cec_read() argument
240 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_cec_read()
245 static int adv7511_cec_write(struct v4l2_subdev *sd, u8 reg, u8 val) in adv7511_cec_write() argument
247 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_cec_write()
256 v4l2_err(sd, "%s: I2C Write Problem\n", __func__); in adv7511_cec_write()
260 static inline int adv7511_cec_write_and_or(struct v4l2_subdev *sd, u8 reg, u8 mask, in adv7511_cec_write_and_or() argument
263 return adv7511_cec_write(sd, reg, (adv7511_cec_read(sd, reg) & mask) | val); in adv7511_cec_write_and_or()
266 static int adv7511_pktmem_rd(struct v4l2_subdev *sd, u8 reg) in adv7511_pktmem_rd() argument
268 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_pktmem_rd()
273 static int adv7511_pktmem_wr(struct v4l2_subdev *sd, u8 reg, u8 val) in adv7511_pktmem_wr() argument
275 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_pktmem_wr()
284 v4l2_err(sd, "%s: i2c write error\n", __func__); in adv7511_pktmem_wr()
290 static inline void adv7511_pktmem_wr_and_or(struct v4l2_subdev *sd, u8 reg, u8 clr_mask, u8 val_mas… in adv7511_pktmem_wr_and_or() argument
292 adv7511_pktmem_wr(sd, reg, (adv7511_pktmem_rd(sd, reg) & clr_mask) | val_mask); in adv7511_pktmem_wr_and_or()
295 static inline bool adv7511_have_hotplug(struct v4l2_subdev *sd) in adv7511_have_hotplug() argument
297 return adv7511_rd(sd, 0x42) & MASK_ADV7511_HPD_DETECT; in adv7511_have_hotplug()
300 static inline bool adv7511_have_rx_sense(struct v4l2_subdev *sd) in adv7511_have_rx_sense() argument
302 return adv7511_rd(sd, 0x42) & MASK_ADV7511_MSEN_DETECT; in adv7511_have_rx_sense()
305 static void adv7511_csc_conversion_mode(struct v4l2_subdev *sd, u8 mode) in adv7511_csc_conversion_mode() argument
307 adv7511_wr_and_or(sd, 0x18, 0x9f, (mode & 0x3)<<5); in adv7511_csc_conversion_mode()
310 static void adv7511_csc_coeff(struct v4l2_subdev *sd, in adv7511_csc_coeff() argument
316 adv7511_wr_and_or(sd, 0x18, 0xe0, A1>>8); in adv7511_csc_coeff()
317 adv7511_wr(sd, 0x19, A1); in adv7511_csc_coeff()
318 adv7511_wr_and_or(sd, 0x1A, 0xe0, A2>>8); in adv7511_csc_coeff()
319 adv7511_wr(sd, 0x1B, A2); in adv7511_csc_coeff()
320 adv7511_wr_and_or(sd, 0x1c, 0xe0, A3>>8); in adv7511_csc_coeff()
321 adv7511_wr(sd, 0x1d, A3); in adv7511_csc_coeff()
322 adv7511_wr_and_or(sd, 0x1e, 0xe0, A4>>8); in adv7511_csc_coeff()
323 adv7511_wr(sd, 0x1f, A4); in adv7511_csc_coeff()
326 adv7511_wr_and_or(sd, 0x20, 0xe0, B1>>8); in adv7511_csc_coeff()
327 adv7511_wr(sd, 0x21, B1); in adv7511_csc_coeff()
328 adv7511_wr_and_or(sd, 0x22, 0xe0, B2>>8); in adv7511_csc_coeff()
329 adv7511_wr(sd, 0x23, B2); in adv7511_csc_coeff()
330 adv7511_wr_and_or(sd, 0x24, 0xe0, B3>>8); in adv7511_csc_coeff()
331 adv7511_wr(sd, 0x25, B3); in adv7511_csc_coeff()
332 adv7511_wr_and_or(sd, 0x26, 0xe0, B4>>8); in adv7511_csc_coeff()
333 adv7511_wr(sd, 0x27, B4); in adv7511_csc_coeff()
336 adv7511_wr_and_or(sd, 0x28, 0xe0, C1>>8); in adv7511_csc_coeff()
337 adv7511_wr(sd, 0x29, C1); in adv7511_csc_coeff()
338 adv7511_wr_and_or(sd, 0x2A, 0xe0, C2>>8); in adv7511_csc_coeff()
339 adv7511_wr(sd, 0x2B, C2); in adv7511_csc_coeff()
340 adv7511_wr_and_or(sd, 0x2C, 0xe0, C3>>8); in adv7511_csc_coeff()
341 adv7511_wr(sd, 0x2D, C3); in adv7511_csc_coeff()
342 adv7511_wr_and_or(sd, 0x2E, 0xe0, C4>>8); in adv7511_csc_coeff()
343 adv7511_wr(sd, 0x2F, C4); in adv7511_csc_coeff()
346 static void adv7511_csc_rgb_full2limit(struct v4l2_subdev *sd, bool enable) in adv7511_csc_rgb_full2limit() argument
350 adv7511_csc_conversion_mode(sd, csc_mode); in adv7511_csc_rgb_full2limit()
351 adv7511_csc_coeff(sd, in adv7511_csc_rgb_full2limit()
356 adv7511_wr_and_or(sd, 0x18, 0x7f, 0x80); in adv7511_csc_rgb_full2limit()
358 adv7511_wr_and_or(sd, 0x57, 0xf3, 0x04); in adv7511_csc_rgb_full2limit()
361 adv7511_wr_and_or(sd, 0x18, 0x7f, 0x0); in adv7511_csc_rgb_full2limit()
363 adv7511_wr_and_or(sd, 0x57, 0xf3, 0x08); in adv7511_csc_rgb_full2limit()
367 static void adv7511_set_rgb_quantization_mode(struct v4l2_subdev *sd, struct v4l2_ctrl *ctrl) in adv7511_set_rgb_quantization_mode() argument
369 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_set_rgb_quantization_mode()
374 adv7511_csc_rgb_full2limit(sd, false); in adv7511_set_rgb_quantization_mode()
383 adv7511_csc_rgb_full2limit(sd, true); in adv7511_set_rgb_quantization_mode()
386 adv7511_csc_rgb_full2limit(sd, false); in adv7511_set_rgb_quantization_mode()
391 adv7511_csc_rgb_full2limit(sd, true); in adv7511_set_rgb_quantization_mode()
395 adv7511_csc_rgb_full2limit(sd, false); in adv7511_set_rgb_quantization_mode()
404 struct v4l2_subdev *sd = to_sd(ctrl); in adv7511_s_ctrl() local
405 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_s_ctrl()
407 v4l2_dbg(1, debug, sd, "%s: ctrl id: %d, ctrl->val %d\n", __func__, ctrl->id, ctrl->val); in adv7511_s_ctrl()
411 adv7511_wr_and_or(sd, 0xaf, 0xfd, ctrl->val == V4L2_DV_TX_MODE_HDMI ? 0x02 : 0x00); in adv7511_s_ctrl()
415 adv7511_set_rgb_quantization_mode(sd, ctrl); in adv7511_s_ctrl()
424 adv7511_wr_and_or(sd, 0x57, 0x7f, itc << 7); in adv7511_s_ctrl()
425 adv7511_wr_and_or(sd, 0x59, 0xcf, cn << 4); in adv7511_s_ctrl()
439 static void adv7511_inv_register(struct v4l2_subdev *sd) in adv7511_inv_register() argument
441 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_inv_register()
443 v4l2_info(sd, "0x000-0x0ff: Main Map\n"); in adv7511_inv_register()
445 v4l2_info(sd, "0x100-0x1ff: CEC Map\n"); in adv7511_inv_register()
448 static int adv7511_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) in adv7511_g_register() argument
450 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_g_register()
455 reg->val = adv7511_rd(sd, reg->reg & 0xff); in adv7511_g_register()
459 reg->val = adv7511_cec_read(sd, reg->reg & 0xff); in adv7511_g_register()
464 v4l2_info(sd, "Register %03llx not supported\n", reg->reg); in adv7511_g_register()
465 adv7511_inv_register(sd); in adv7511_g_register()
471 static int adv7511_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg) in adv7511_s_register() argument
473 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_s_register()
477 adv7511_wr(sd, reg->reg & 0xff, reg->val & 0xff); in adv7511_s_register()
481 adv7511_cec_write(sd, reg->reg & 0xff, reg->val & 0xff); in adv7511_s_register()
486 v4l2_info(sd, "Register %03llx not supported\n", reg->reg); in adv7511_s_register()
487 adv7511_inv_register(sd); in adv7511_s_register()
514 static void log_infoframe(struct v4l2_subdev *sd, const struct adv7511_cfg_read_infoframe *cri) in log_infoframe() argument
516 struct i2c_client *client = v4l2_get_subdevdata(sd); in log_infoframe()
523 if (!(adv7511_rd(sd, cri->present_reg) & cri->present_mask)) { in log_infoframe()
524 v4l2_info(sd, "%s infoframe not transmitted\n", cri->desc); in log_infoframe()
533 v4l2_err(sd, "%s: invalid %s infoframe length %d\n", __func__, cri->desc, len); in log_infoframe()
539 buffer[i + 4] = adv7511_pktmem_rd(sd, cri->payload_addr + i - 0x100); in log_infoframe()
542 buffer[i + 4] = adv7511_rd(sd, cri->payload_addr + i); in log_infoframe()
548 v4l2_err(sd, "%s: unpack of %s infoframe failed\n", __func__, cri->desc); in log_infoframe()
555 static void adv7511_log_infoframes(struct v4l2_subdev *sd) in adv7511_log_infoframes() argument
565 log_infoframe(sd, &cri[i]); in adv7511_log_infoframes()
568 static int adv7511_log_status(struct v4l2_subdev *sd) in adv7511_log_status() argument
570 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_log_status()
596 v4l2_info(sd, "power %s\n", state->power_on ? "on" : "off"); in adv7511_log_status()
597 v4l2_info(sd, "%s hotplug, %s Rx Sense, %s EDID (%d block(s))\n", in adv7511_log_status()
598 (adv7511_rd(sd, 0x42) & MASK_ADV7511_HPD_DETECT) ? "detected" : "no", in adv7511_log_status()
599 (adv7511_rd(sd, 0x42) & MASK_ADV7511_MSEN_DETECT) ? "detected" : "no", in adv7511_log_status()
602 v4l2_info(sd, "%s output %s\n", in adv7511_log_status()
603 (adv7511_rd(sd, 0xaf) & 0x02) ? in adv7511_log_status()
605 (adv7511_rd(sd, 0xa1) & 0x3c) ? in adv7511_log_status()
607 v4l2_info(sd, "state: %s, error: %s, detect count: %u, msk/irq: %02x/%02x\n", in adv7511_log_status()
608 states[adv7511_rd(sd, 0xc8) & 0xf], in adv7511_log_status()
609 errors[adv7511_rd(sd, 0xc8) >> 4], state->edid_detect_counter, in adv7511_log_status()
610 adv7511_rd(sd, 0x94), adv7511_rd(sd, 0x96)); in adv7511_log_status()
611 v4l2_info(sd, "RGB quantization: %s range\n", adv7511_rd(sd, 0x18) & 0x80 ? "limited" : "full"); in adv7511_log_status()
612 if (adv7511_rd(sd, 0xaf) & 0x02) { in adv7511_log_status()
614 u8 manual_cts = adv7511_rd(sd, 0x0a) & 0x80; in adv7511_log_status()
615 u32 N = (adv7511_rd(sd, 0x01) & 0xf) << 16 | in adv7511_log_status()
616 adv7511_rd(sd, 0x02) << 8 | in adv7511_log_status()
617 adv7511_rd(sd, 0x03); in adv7511_log_status()
618 u8 vic_detect = adv7511_rd(sd, 0x3e) >> 2; in adv7511_log_status()
619 u8 vic_sent = adv7511_rd(sd, 0x3d) & 0x3f; in adv7511_log_status()
623 CTS = (adv7511_rd(sd, 0x07) & 0xf) << 16 | in adv7511_log_status()
624 adv7511_rd(sd, 0x08) << 8 | in adv7511_log_status()
625 adv7511_rd(sd, 0x09); in adv7511_log_status()
627 CTS = (adv7511_rd(sd, 0x04) & 0xf) << 16 | in adv7511_log_status()
628 adv7511_rd(sd, 0x05) << 8 | in adv7511_log_status()
629 adv7511_rd(sd, 0x06); in adv7511_log_status()
630 v4l2_info(sd, "CTS %s mode: N %d, CTS %d\n", in adv7511_log_status()
632 v4l2_info(sd, "VIC: detected %d, sent %d\n", in adv7511_log_status()
634 adv7511_log_infoframes(sd); in adv7511_log_status()
637 v4l2_print_dv_timings(sd->name, "timings: ", in adv7511_log_status()
640 v4l2_info(sd, "no timings set\n"); in adv7511_log_status()
641 v4l2_info(sd, "i2c edid addr: 0x%x\n", state->i2c_edid_addr); in adv7511_log_status()
646 v4l2_info(sd, "i2c cec addr: 0x%x\n", state->i2c_cec_addr); in adv7511_log_status()
648 v4l2_info(sd, "CEC: %s\n", state->cec_enabled_adap ? in adv7511_log_status()
655 v4l2_info(sd, "CEC Logical Address: 0x%x\n", in adv7511_log_status()
659 v4l2_info(sd, "i2c pktmem addr: 0x%x\n", state->i2c_pktmem_addr); in adv7511_log_status()
664 static int adv7511_s_power(struct v4l2_subdev *sd, int on) in adv7511_s_power() argument
666 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_s_power()
670 v4l2_dbg(1, debug, sd, "%s: power %s\n", __func__, on ? "on" : "off"); in adv7511_s_power()
676 adv7511_wr_and_or(sd, 0x41, 0xbf, 0x40); in adv7511_s_power()
684 adv7511_wr_and_or(sd, 0x41, 0xbf, 0x0); in adv7511_s_power()
685 if ((adv7511_rd(sd, 0x41) & 0x40) == 0) in adv7511_s_power()
687 adv7511_wr_and_or(sd, 0x41, 0xbf, 0x40); in adv7511_s_power()
691 v4l2_dbg(1, debug, sd, "%s: failed to powerup the adv7511!\n", __func__); in adv7511_s_power()
692 adv7511_s_power(sd, 0); in adv7511_s_power()
696 v4l2_dbg(1, debug, sd, "%s: needed %d retries to powerup the adv7511\n", __func__, i); in adv7511_s_power()
699 adv7511_wr(sd, 0x98, 0x03); in adv7511_s_power()
700 adv7511_wr_and_or(sd, 0x9a, 0xfe, 0x70); in adv7511_s_power()
701 adv7511_wr(sd, 0x9c, 0x30); in adv7511_s_power()
702 adv7511_wr_and_or(sd, 0x9d, 0xfc, 0x01); in adv7511_s_power()
703 adv7511_wr(sd, 0xa2, 0xa4); in adv7511_s_power()
704 adv7511_wr(sd, 0xa3, 0xa4); in adv7511_s_power()
705 adv7511_wr(sd, 0xe0, 0xd0); in adv7511_s_power()
706 adv7511_wr(sd, 0xf9, 0x00); in adv7511_s_power()
708 adv7511_wr(sd, 0x43, state->i2c_edid_addr); in adv7511_s_power()
709 adv7511_wr(sd, 0x45, state->i2c_pktmem_addr); in adv7511_s_power()
712 adv7511_wr(sd, 0xc9, 0xf); in adv7511_s_power()
720 struct v4l2_subdev *sd = &state->sd; in adv7511_cec_adap_enable() local
727 adv7511_cec_write_and_or(sd, 0x4e, 0xfc, 0x01); in adv7511_cec_adap_enable()
729 adv7511_cec_write(sd, 0x4a, 0x00); in adv7511_cec_adap_enable()
730 adv7511_cec_write(sd, 0x4a, 0x07); in adv7511_cec_adap_enable()
731 adv7511_cec_write_and_or(sd, 0x11, 0xfe, 0); /* initially disable tx */ in adv7511_cec_adap_enable()
738 adv7511_wr_and_or(sd, 0x95, 0xc0, 0x39); in adv7511_cec_adap_enable()
741 adv7511_wr_and_or(sd, 0x95, 0xc0, 0x00); in adv7511_cec_adap_enable()
743 adv7511_cec_write_and_or(sd, 0x4b, 0x8f, 0x00); in adv7511_cec_adap_enable()
745 adv7511_cec_write_and_or(sd, 0x4e, 0xfc, 0x00); in adv7511_cec_adap_enable()
755 struct v4l2_subdev *sd = &state->sd; in adv7511_cec_adap_log_addr() local
762 adv7511_cec_write_and_or(sd, 0x4b, 0x8f, 0); in adv7511_cec_adap_log_addr()
786 adv7511_cec_write_and_or(sd, 0x4b, 0xef, 0x10); in adv7511_cec_adap_log_addr()
788 adv7511_cec_write_and_or(sd, 0x4c, 0xf0, addr); in adv7511_cec_adap_log_addr()
792 adv7511_cec_write_and_or(sd, 0x4b, 0xdf, 0x20); in adv7511_cec_adap_log_addr()
794 adv7511_cec_write_and_or(sd, 0x4c, 0x0f, addr << 4); in adv7511_cec_adap_log_addr()
798 adv7511_cec_write_and_or(sd, 0x4b, 0xbf, 0x40); in adv7511_cec_adap_log_addr()
800 adv7511_cec_write_and_or(sd, 0x4d, 0xf0, addr); in adv7511_cec_adap_log_addr()
810 struct v4l2_subdev *sd = &state->sd; in adv7511_cec_adap_transmit() local
814 v4l2_dbg(1, debug, sd, "%s: len %d\n", __func__, len); in adv7511_cec_adap_transmit()
817 v4l2_err(sd, "%s: len exceeded 16 (%d)\n", __func__, len); in adv7511_cec_adap_transmit()
826 adv7511_cec_write_and_or(sd, 0x12, ~0x70, max(1, attempts - 1) << 4); in adv7511_cec_adap_transmit()
829 adv7511_wr(sd, 0x97, 0x38); in adv7511_cec_adap_transmit()
833 adv7511_cec_write(sd, i, msg->msg[i]); in adv7511_cec_adap_transmit()
836 adv7511_cec_write(sd, 0x10, len); in adv7511_cec_adap_transmit()
838 adv7511_cec_write(sd, 0x11, 0x01); in adv7511_cec_adap_transmit()
842 static void adv_cec_tx_raw_status(struct v4l2_subdev *sd, u8 tx_raw_status) in adv_cec_tx_raw_status() argument
844 struct adv7511_state *state = get_adv7511_state(sd); in adv_cec_tx_raw_status()
846 if ((adv7511_cec_read(sd, 0x11) & 0x01) == 0) { in adv_cec_tx_raw_status()
847 v4l2_dbg(1, debug, sd, "%s: tx raw: tx disabled\n", __func__); in adv_cec_tx_raw_status()
852 v4l2_dbg(1, debug, sd, in adv_cec_tx_raw_status()
863 v4l2_dbg(1, debug, sd, "%s: tx raw: retry failed\n", __func__); in adv_cec_tx_raw_status()
869 nack_cnt = adv7511_cec_read(sd, 0x14) & 0xf; in adv_cec_tx_raw_status()
872 low_drive_cnt = adv7511_cec_read(sd, 0x14) >> 4; in adv_cec_tx_raw_status()
880 v4l2_dbg(1, debug, sd, "%s: tx raw: ready ok\n", __func__); in adv_cec_tx_raw_status()
894 static void adv7511_set_isr(struct v4l2_subdev *sd, bool enable) in adv7511_set_isr() argument
896 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_set_isr()
901 v4l2_dbg(2, debug, sd, "%s: %s\n", __func__, enable ? "enable" : "disable"); in adv7511_set_isr()
911 else if (adv7511_have_hotplug(sd)) in adv7511_set_isr()
923 adv7511_wr(sd, 0x94, irqs); in adv7511_set_isr()
924 irqs_rd = adv7511_rd(sd, 0x94); in adv7511_set_isr()
928 v4l2_err(sd, "Could not set interrupts: hw failure?\n"); in adv7511_set_isr()
930 adv7511_wr_and_or(sd, 0x95, 0xc0, in adv7511_set_isr()
935 static int adv7511_isr(struct v4l2_subdev *sd, u32 status, bool *handled) in adv7511_isr() argument
941 adv7511_set_isr(sd, false); in adv7511_isr()
942 irq_status = adv7511_rd(sd, 0x96); in adv7511_isr()
943 cec_irq = adv7511_rd(sd, 0x97); in adv7511_isr()
945 adv7511_wr(sd, 0x96, irq_status); in adv7511_isr()
946 adv7511_wr(sd, 0x97, cec_irq); in adv7511_isr()
948 v4l2_dbg(1, debug, sd, "%s: irq 0x%x, cec-irq 0x%x\n", __func__, in adv7511_isr()
952 adv7511_check_monitor_present_status(sd); in adv7511_isr()
954 adv7511_check_edid_status(sd); in adv7511_isr()
958 adv_cec_tx_raw_status(sd, cec_irq); in adv7511_isr()
961 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_isr()
964 msg.len = adv7511_cec_read(sd, 0x25) & 0x1f; in adv7511_isr()
966 v4l2_dbg(1, debug, sd, "%s: cec msg len %d\n", __func__, in adv7511_isr()
976 msg.msg[i] = adv7511_cec_read(sd, i + 0x15); in adv7511_isr()
978 adv7511_cec_write(sd, 0x4a, 0); /* toggle to re-enable rx 1 */ in adv7511_isr()
979 adv7511_cec_write(sd, 0x4a, 1); in adv7511_isr()
986 adv7511_set_isr(sd, true); in adv7511_isr()
1006 static int adv7511_s_stream(struct v4l2_subdev *sd, int enable) in adv7511_s_stream() argument
1008 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_s_stream()
1010 v4l2_dbg(1, debug, sd, "%s: %sable\n", __func__, (enable ? "en" : "dis")); in adv7511_s_stream()
1011 adv7511_wr_and_or(sd, 0xa1, ~0x3c, (enable ? 0 : 0x3c)); in adv7511_s_stream()
1013 adv7511_check_monitor_present_status(sd); in adv7511_s_stream()
1015 adv7511_s_power(sd, 0); in adv7511_s_stream()
1021 static int adv7511_s_dv_timings(struct v4l2_subdev *sd, in adv7511_s_dv_timings() argument
1024 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_s_dv_timings()
1028 v4l2_dbg(1, debug, sd, "%s:\n", __func__); in adv7511_s_dv_timings()
1042 adv7511_wr_and_or(sd, 0x17, 0x9f, in adv7511_s_dv_timings()
1049 adv7511_wr_and_or(sd, 0xfb, 0xf9, 1 << 1); in adv7511_s_dv_timings()
1052 adv7511_wr_and_or(sd, 0xfb, 0xf9, 2 << 1); in adv7511_s_dv_timings()
1055 adv7511_wr_and_or(sd, 0xfb, 0xf9, 3 << 1); in adv7511_s_dv_timings()
1058 adv7511_wr_and_or(sd, 0xfb, 0xf9, 0); in adv7511_s_dv_timings()
1063 adv7511_set_rgb_quantization_mode(sd, state->rgb_quantization_range_ctrl); in adv7511_s_dv_timings()
1068 static int adv7511_g_dv_timings(struct v4l2_subdev *sd, in adv7511_g_dv_timings() argument
1071 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_g_dv_timings()
1073 v4l2_dbg(1, debug, sd, "%s:\n", __func__); in adv7511_g_dv_timings()
1083 static int adv7511_enum_dv_timings(struct v4l2_subdev *sd, in adv7511_enum_dv_timings() argument
1092 static int adv7511_dv_timings_cap(struct v4l2_subdev *sd, in adv7511_dv_timings_cap() argument
1109 static int adv7511_s_audio_stream(struct v4l2_subdev *sd, int enable) in adv7511_s_audio_stream() argument
1111 v4l2_dbg(1, debug, sd, "%s: %sable\n", __func__, (enable ? "en" : "dis")); in adv7511_s_audio_stream()
1114 adv7511_wr_and_or(sd, 0x4b, 0x3f, 0x80); in adv7511_s_audio_stream()
1116 adv7511_wr_and_or(sd, 0x4b, 0x3f, 0x40); in adv7511_s_audio_stream()
1121 static int adv7511_s_clock_freq(struct v4l2_subdev *sd, u32 freq) in adv7511_s_clock_freq() argument
1138 adv7511_wr(sd, 0x01, (N >> 16) & 0xf); in adv7511_s_clock_freq()
1139 adv7511_wr(sd, 0x02, (N >> 8) & 0xff); in adv7511_s_clock_freq()
1140 adv7511_wr(sd, 0x03, N & 0xff); in adv7511_s_clock_freq()
1145 static int adv7511_s_i2s_clock_freq(struct v4l2_subdev *sd, u32 freq) in adv7511_s_i2s_clock_freq() argument
1162 adv7511_wr_and_or(sd, 0x15, 0xf, i2s_sf); in adv7511_s_i2s_clock_freq()
1167 static int adv7511_s_routing(struct v4l2_subdev *sd, u32 input, u32 output, u32 config) in adv7511_s_routing() argument
1170 adv7511_wr_and_or(sd, 0x73, 0xf8, 0x1); in adv7511_s_routing()
1172 adv7511_wr(sd, 0x76, 0x00); in adv7511_s_routing()
1175 adv7511_wr_and_or(sd, 0x14, 0xf0, 0x02); in adv7511_s_routing()
1189 static int adv7511_get_edid(struct v4l2_subdev *sd, struct v4l2_edid *edid) in adv7511_get_edid() argument
1191 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_get_edid()
1218 static int adv7511_enum_mbus_code(struct v4l2_subdev *sd, in adv7511_enum_mbus_code() argument
1249 static int adv7511_get_fmt(struct v4l2_subdev *sd, in adv7511_get_fmt() argument
1253 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_get_fmt()
1264 fmt = v4l2_subdev_get_try_format(sd, sd_state, format->pad); in adv7511_get_fmt()
1281 static int adv7511_set_fmt(struct v4l2_subdev *sd, in adv7511_set_fmt() argument
1285 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_set_fmt()
1319 fmt = v4l2_subdev_get_try_format(sd, sd_state, format->pad); in adv7511_set_fmt()
1330 adv7511_wr_and_or(sd, 0x15, 0xf0, 0x01); in adv7511_set_fmt()
1331 adv7511_wr_and_or(sd, 0x16, 0x03, 0xb8); in adv7511_set_fmt()
1335 adv7511_wr_and_or(sd, 0x15, 0xf0, 0x01); in adv7511_set_fmt()
1336 adv7511_wr_and_or(sd, 0x16, 0x03, 0xbc); in adv7511_set_fmt()
1341 adv7511_wr_and_or(sd, 0x15, 0xf0, 0x00); in adv7511_set_fmt()
1342 adv7511_wr_and_or(sd, 0x16, 0x03, 0x00); in adv7511_set_fmt()
1413 adv7511_wr_and_or(sd, 0x4a, 0xbf, 0); in adv7511_set_fmt()
1414 adv7511_wr_and_or(sd, 0x55, 0x9f, y << 5); in adv7511_set_fmt()
1415 adv7511_wr_and_or(sd, 0x56, 0x3f, c << 6); in adv7511_set_fmt()
1416 adv7511_wr_and_or(sd, 0x57, 0x83, (ec << 4) | (q << 2) | (itc << 7)); in adv7511_set_fmt()
1417 adv7511_wr_and_or(sd, 0x59, 0x0f, (yq << 6) | (cn << 4)); in adv7511_set_fmt()
1418 adv7511_wr_and_or(sd, 0x4a, 0xff, 1); in adv7511_set_fmt()
1419 adv7511_set_rgb_quantization_mode(sd, state->rgb_quantization_range_ctrl); in adv7511_set_fmt()
1443 static void adv7511_dbg_dump_edid(int lvl, int debug, struct v4l2_subdev *sd, int segment, u8 *buf) in adv7511_dbg_dump_edid() argument
1447 v4l2_dbg(lvl, debug, sd, "edid segment %d\n", segment); in adv7511_dbg_dump_edid()
1452 v4l2_dbg(lvl, debug, sd, "\n"); in adv7511_dbg_dump_edid()
1458 v4l2_dbg(lvl, debug, sd, "%s\n", b); in adv7511_dbg_dump_edid()
1463 static void adv7511_notify_no_edid(struct v4l2_subdev *sd) in adv7511_notify_no_edid() argument
1465 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_notify_no_edid()
1470 ed.segment = adv7511_rd(sd, 0xc4); in adv7511_notify_no_edid()
1473 v4l2_subdev_notify(sd, ADV7511_EDID_DETECT, (void *)&ed); in adv7511_notify_no_edid()
1481 struct v4l2_subdev *sd = &state->sd; in adv7511_edid_handler() local
1483 v4l2_dbg(1, debug, sd, "%s:\n", __func__); in adv7511_edid_handler()
1485 if (adv7511_check_edid_status(sd)) { in adv7511_edid_handler()
1490 if (adv7511_have_hotplug(sd)) { in adv7511_edid_handler()
1496 v4l2_dbg(1, debug, sd, "%s: edid read failed\n", __func__); in adv7511_edid_handler()
1498 adv7511_s_power(sd, false); in adv7511_edid_handler()
1499 adv7511_s_power(sd, true); in adv7511_edid_handler()
1506 adv7511_notify_no_edid(sd); in adv7511_edid_handler()
1507 v4l2_dbg(1, debug, sd, "%s: no edid found\n", __func__); in adv7511_edid_handler()
1510 static void adv7511_audio_setup(struct v4l2_subdev *sd) in adv7511_audio_setup() argument
1512 v4l2_dbg(1, debug, sd, "%s\n", __func__); in adv7511_audio_setup()
1514 adv7511_s_i2s_clock_freq(sd, 48000); in adv7511_audio_setup()
1515 adv7511_s_clock_freq(sd, 48000); in adv7511_audio_setup()
1516 adv7511_s_routing(sd, 0, 0, 0); in adv7511_audio_setup()
1520 static void adv7511_setup(struct v4l2_subdev *sd) in adv7511_setup() argument
1522 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_setup()
1523 v4l2_dbg(1, debug, sd, "%s\n", __func__); in adv7511_setup()
1526 adv7511_wr_and_or(sd, 0x15, 0xf0, 0x0); in adv7511_setup()
1528 adv7511_wr_and_or(sd, 0x16, 0x7f, 0x0); in adv7511_setup()
1530 adv7511_wr_and_or(sd, 0x17, 0xf9, 0x06); in adv7511_setup()
1532 adv7511_wr_and_or(sd, 0x3b, 0x9f, 0x0); in adv7511_setup()
1534 adv7511_wr_and_or(sd, 0x18, 0x7f, 0x0); in adv7511_setup()
1537 adv7511_wr_and_or(sd, 0x55, 0x9c, 0x12); in adv7511_setup()
1539 adv7511_wr_and_or(sd, 0x44, 0xe7, 0x10); in adv7511_setup()
1541 adv7511_wr(sd, 0x56, 0xa8); in adv7511_setup()
1543 adv7511_wr_and_or(sd, 0xaf, 0xed, 0x0); in adv7511_setup()
1546 adv7511_wr_and_or(sd, 0xba, 0x1f, 0x60); in adv7511_setup()
1548 adv7511_audio_setup(sd); in adv7511_setup()
1553 static void adv7511_notify_monitor_detect(struct v4l2_subdev *sd) in adv7511_notify_monitor_detect() argument
1556 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_notify_monitor_detect()
1559 v4l2_subdev_notify(sd, ADV7511_MONITOR_DETECT, (void *)&mdt); in adv7511_notify_monitor_detect()
1562 static void adv7511_check_monitor_present_status(struct v4l2_subdev *sd) in adv7511_check_monitor_present_status() argument
1564 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_check_monitor_present_status()
1566 u8 status = adv7511_rd(sd, 0x42); in adv7511_check_monitor_present_status()
1568 v4l2_dbg(1, debug, sd, "%s: status: 0x%x%s%s\n", in adv7511_check_monitor_present_status()
1575 v4l2_ctrl_s_ctrl(state->hotplug_ctrl, adv7511_have_hotplug(sd) ? 0x1 : 0x0); in adv7511_check_monitor_present_status()
1576 v4l2_ctrl_s_ctrl(state->rx_sense_ctrl, adv7511_have_rx_sense(sd) ? 0x1 : 0x0); in adv7511_check_monitor_present_status()
1579 v4l2_dbg(1, debug, sd, "%s: hotplug and (rx-sense or edid)\n", __func__); in adv7511_check_monitor_present_status()
1581 v4l2_dbg(1, debug, sd, "%s: monitor detected\n", __func__); in adv7511_check_monitor_present_status()
1583 adv7511_set_isr(sd, true); in adv7511_check_monitor_present_status()
1584 if (!adv7511_s_power(sd, true)) { in adv7511_check_monitor_present_status()
1585 v4l2_dbg(1, debug, sd, "%s: monitor detected, powerup failed\n", __func__); in adv7511_check_monitor_present_status()
1588 adv7511_setup(sd); in adv7511_check_monitor_present_status()
1589 adv7511_notify_monitor_detect(sd); in adv7511_check_monitor_present_status()
1594 v4l2_dbg(1, debug, sd, "%s: hotplug detected\n", __func__); in adv7511_check_monitor_present_status()
1598 v4l2_dbg(1, debug, sd, "%s: hotplug not detected\n", __func__); in adv7511_check_monitor_present_status()
1600 v4l2_dbg(1, debug, sd, "%s: monitor not detected\n", __func__); in adv7511_check_monitor_present_status()
1602 adv7511_notify_monitor_detect(sd); in adv7511_check_monitor_present_status()
1604 adv7511_s_power(sd, false); in adv7511_check_monitor_present_status()
1606 adv7511_notify_no_edid(sd); in adv7511_check_monitor_present_status()
1620 static bool edid_verify_crc(struct v4l2_subdev *sd, u32 segment) in edid_verify_crc() argument
1622 struct adv7511_state *state = get_adv7511_state(sd); in edid_verify_crc()
1633 static bool edid_verify_header(struct v4l2_subdev *sd, u32 segment) in edid_verify_header() argument
1638 struct adv7511_state *state = get_adv7511_state(sd); in edid_verify_header()
1646 static bool adv7511_check_edid_status(struct v4l2_subdev *sd) in adv7511_check_edid_status() argument
1648 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_check_edid_status()
1649 u8 edidRdy = adv7511_rd(sd, 0xc5); in adv7511_check_edid_status()
1651 v4l2_dbg(1, debug, sd, "%s: edid ready (retries: %d)\n", in adv7511_check_edid_status()
1658 int segment = adv7511_rd(sd, 0xc4); in adv7511_check_edid_status()
1663 v4l2_err(sd, "edid segment number too big\n"); in adv7511_check_edid_status()
1666 v4l2_dbg(1, debug, sd, "%s: got segment %d\n", __func__, segment); in adv7511_check_edid_status()
1667 err = adv7511_edid_rd(sd, 256, &state->edid.data[segment * 256]); in adv7511_check_edid_status()
1669 adv7511_dbg_dump_edid(2, debug, sd, segment, &state->edid.data[segment * 256]); in adv7511_check_edid_status()
1672 v4l2_dbg(1, debug, sd, "%s: %d blocks in total\n", in adv7511_check_edid_status()
1677 if (err || !edid_verify_crc(sd, segment) || !edid_verify_header(sd, segment)) { in adv7511_check_edid_status()
1680 v4l2_err(sd, "%s: edid crc or header error\n", __func__); in adv7511_check_edid_status()
1682 adv7511_s_power(sd, false); in adv7511_check_edid_status()
1683 adv7511_s_power(sd, true); in adv7511_check_edid_status()
1691 v4l2_dbg(1, debug, sd, "%s: request segment %d\n", __func__, state->edid.segments); in adv7511_check_edid_status()
1692 adv7511_wr(sd, 0xc9, 0xf); in adv7511_check_edid_status()
1693 adv7511_wr(sd, 0xc4, state->edid.segments); in adv7511_check_edid_status()
1699 v4l2_dbg(1, debug, sd, "%s: edid complete with %d segment(s)\n", __func__, state->edid.segments); in adv7511_check_edid_status()
1711 v4l2_subdev_notify(sd, ADV7511_EDID_DETECT, (void *)&ed); in adv7511_check_edid_status()
1718 static int adv7511_registered(struct v4l2_subdev *sd) in adv7511_registered() argument
1720 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_registered()
1721 struct i2c_client *client = v4l2_get_subdevdata(sd); in adv7511_registered()
1730 static void adv7511_unregistered(struct v4l2_subdev *sd) in adv7511_unregistered() argument
1732 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_unregistered()
1744 static void adv7511_init_setup(struct v4l2_subdev *sd) in adv7511_init_setup() argument
1746 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_init_setup()
1751 v4l2_dbg(1, debug, sd, "%s\n", __func__); in adv7511_init_setup()
1754 adv7511_wr(sd, 0x96, 0xff); in adv7511_init_setup()
1755 adv7511_wr(sd, 0x97, 0xff); in adv7511_init_setup()
1761 adv7511_wr_and_or(sd, 0xd6, 0x3f, 0xc0); in adv7511_init_setup()
1764 adv7511_set_isr(sd, false); in adv7511_init_setup()
1765 adv7511_s_stream(sd, false); in adv7511_init_setup()
1766 adv7511_s_audio_stream(sd, false); in adv7511_init_setup()
1771 v4l2_dbg(1, debug, sd, "%s: cec_clk %d\n", __func__, cec_clk); in adv7511_init_setup()
1774 adv7511_cec_write(sd, 0x50, 0x01); in adv7511_init_setup()
1775 adv7511_cec_write(sd, 0x50, 0x00); in adv7511_init_setup()
1778 adv7511_cec_write(sd, 0x4a, 0x00); in adv7511_init_setup()
1779 adv7511_cec_write(sd, 0x4a, 0x07); in adv7511_init_setup()
1782 v4l2_err(sd, "%s: cec_clk %d, not multiple of 750 Khz\n", in adv7511_init_setup()
1786 adv7511_cec_write(sd, 0x4e, ratio << 2); in adv7511_init_setup()
1794 struct v4l2_subdev *sd; in adv7511_probe() local
1815 sd = &state->sd; in adv7511_probe()
1817 v4l2_dbg(1, debug, sd, "detecting adv7511 client on address 0x%x\n", in adv7511_probe()
1820 v4l2_i2c_subdev_init(sd, client, &adv7511_ops); in adv7511_probe()
1821 sd->internal_ops = &adv7511_int_ops; in adv7511_probe()
1843 sd->ctrl_handler = hdl; in adv7511_probe()
1849 sd->entity.function = MEDIA_ENT_F_DV_ENCODER; in adv7511_probe()
1850 err = media_entity_pads_init(&sd->entity, 1, &state->pad); in adv7511_probe()
1859 state->chip_revision = adv7511_rd(sd, 0x0); in adv7511_probe()
1860 chip_id[0] = adv7511_rd(sd, 0xf5); in adv7511_probe()
1861 chip_id[1] = adv7511_rd(sd, 0xf6); in adv7511_probe()
1863 v4l2_err(sd, "chip_id != 0x7511, read 0x%02x%02x\n", chip_id[0], in adv7511_probe()
1872 v4l2_err(sd, "failed to register edid i2c client\n"); in adv7511_probe()
1877 adv7511_wr(sd, 0xe1, state->i2c_cec_addr); in adv7511_probe()
1880 v4l2_err(sd, "%s: cec_clk %u outside range, disabling cec\n", in adv7511_probe()
1889 v4l2_err(sd, "failed to register cec i2c client\n"); in adv7511_probe()
1893 adv7511_wr(sd, 0xe2, 0x00); /* power up cec section */ in adv7511_probe()
1895 adv7511_wr(sd, 0xe2, 0x01); /* power down cec section */ in adv7511_probe()
1900 v4l2_err(sd, "failed to register pktmem i2c client\n"); in adv7511_probe()
1905 state->work_queue = create_singlethread_workqueue(sd->name); in adv7511_probe()
1907 v4l2_err(sd, "could not create workqueue\n"); in adv7511_probe()
1914 adv7511_init_setup(sd); in adv7511_probe()
1927 adv7511_set_isr(sd, true); in adv7511_probe()
1928 adv7511_check_monitor_present_status(sd); in adv7511_probe()
1930 v4l2_info(sd, "%s found @ 0x%x (%s)\n", client->name, in adv7511_probe()
1941 media_entity_cleanup(&sd->entity); in adv7511_probe()
1951 struct v4l2_subdev *sd = i2c_get_clientdata(client); in adv7511_remove() local
1952 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_remove()
1956 v4l2_dbg(1, debug, sd, "%s removed @ 0x%x (%s)\n", client->name, in adv7511_remove()
1959 adv7511_set_isr(sd, false); in adv7511_remove()
1960 adv7511_init_setup(sd); in adv7511_remove()
1966 v4l2_device_unregister_subdev(sd); in adv7511_remove()
1967 media_entity_cleanup(&sd->entity); in adv7511_remove()
1968 v4l2_ctrl_handler_free(sd->ctrl_handler); in adv7511_remove()