Lines Matching +full:1 +full:- +full:sd
1 // SPDX-License-Identifier: GPL-2.0-only
9 * This file is named adv7511-v4l2.c so it doesn't conflict with the Analog
22 #include <linux/v4l2-dv-timings.h>
23 #include <media/v4l2-device.h>
24 #include <media/v4l2-common.h>
25 #include <media/v4l2-ctrls.h>
26 #include <media/v4l2-dv-timings.h>
32 MODULE_PARM_DESC(debug, "debug level (0-2)");
78 struct v4l2_subdev sd; member
94 /* Did we receive hotplug and rx-sense signals? */
121 static void adv7511_check_monitor_present_status(struct v4l2_subdev *sd);
122 static bool adv7511_check_edid_status(struct v4l2_subdev *sd);
123 static void adv7511_setup(struct v4l2_subdev *sd);
124 static int adv7511_s_i2s_clock_freq(struct v4l2_subdev *sd, u32 freq);
125 static int adv7511_s_clock_freq(struct v4l2_subdev *sd, u32 freq);
140 static inline struct adv7511_state *get_adv7511_state(struct v4l2_subdev *sd) in get_adv7511_state() argument
142 return container_of(sd, struct adv7511_state, sd); in get_adv7511_state()
147 return &container_of(ctrl->handler, struct adv7511_state, hdl)->sd; in to_sd()
150 /* ------------------------ I2C ----------------------------------------------- */
157 if (!i2c_smbus_xfer(client->adapter, client->addr, client->flags, in adv_smbus_read_byte_data_check()
163 client->addr, command); in adv_smbus_read_byte_data_check()
164 return -1; in adv_smbus_read_byte_data_check()
179 return -1; in adv_smbus_read_byte_data()
182 static int adv7511_rd(struct v4l2_subdev *sd, u8 reg) in adv7511_rd() argument
184 struct i2c_client *client = v4l2_get_subdevdata(sd); in adv7511_rd()
189 static int adv7511_wr(struct v4l2_subdev *sd, u8 reg, u8 val) in adv7511_wr() argument
191 struct i2c_client *client = v4l2_get_subdevdata(sd); in adv7511_wr()
200 v4l2_err(sd, "%s: i2c write error\n", __func__); in adv7511_wr()
204 /* To set specific bits in the register, a clear-mask is given (to be AND-ed),
205 and then the value-mask (to be OR-ed). */
206 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
208 adv7511_wr(sd, reg, (adv7511_rd(sd, reg) & clr_mask) | val_mask); in adv7511_wr_and_or()
211 static int adv7511_edid_rd(struct v4l2_subdev *sd, uint16_t len, uint8_t *buf) in adv7511_edid_rd() argument
213 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_edid_rd()
216 v4l2_dbg(1, debug, sd, "%s:\n", __func__); in adv7511_edid_rd()
221 ret = i2c_smbus_read_i2c_block_data(state->i2c_edid, i, in adv7511_edid_rd()
224 v4l2_err(sd, "%s: i2c read error\n", __func__); in adv7511_edid_rd()
232 static inline int adv7511_cec_read(struct v4l2_subdev *sd, u8 reg) in adv7511_cec_read() argument
234 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_cec_read()
236 return i2c_smbus_read_byte_data(state->i2c_cec, reg); in adv7511_cec_read()
239 static int adv7511_cec_write(struct v4l2_subdev *sd, u8 reg, u8 val) in adv7511_cec_write() argument
241 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_cec_write()
246 ret = i2c_smbus_write_byte_data(state->i2c_cec, reg, val); in adv7511_cec_write()
250 v4l2_err(sd, "%s: I2C Write Problem\n", __func__); in adv7511_cec_write()
254 static inline int adv7511_cec_write_and_or(struct v4l2_subdev *sd, u8 reg, u8 mask, in adv7511_cec_write_and_or() argument
257 return adv7511_cec_write(sd, reg, (adv7511_cec_read(sd, reg) & mask) | val); in adv7511_cec_write_and_or()
260 static int adv7511_pktmem_rd(struct v4l2_subdev *sd, u8 reg) in adv7511_pktmem_rd() argument
262 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_pktmem_rd()
264 return adv_smbus_read_byte_data(state->i2c_pktmem, reg); in adv7511_pktmem_rd()
267 static inline bool adv7511_have_hotplug(struct v4l2_subdev *sd) in adv7511_have_hotplug() argument
269 return adv7511_rd(sd, 0x42) & MASK_ADV7511_HPD_DETECT; in adv7511_have_hotplug()
272 static inline bool adv7511_have_rx_sense(struct v4l2_subdev *sd) in adv7511_have_rx_sense() argument
274 return adv7511_rd(sd, 0x42) & MASK_ADV7511_MSEN_DETECT; in adv7511_have_rx_sense()
277 static void adv7511_csc_conversion_mode(struct v4l2_subdev *sd, u8 mode) in adv7511_csc_conversion_mode() argument
279 adv7511_wr_and_or(sd, 0x18, 0x9f, (mode & 0x3)<<5); in adv7511_csc_conversion_mode()
282 static void adv7511_csc_coeff(struct v4l2_subdev *sd, in adv7511_csc_coeff() argument
288 adv7511_wr_and_or(sd, 0x18, 0xe0, A1>>8); in adv7511_csc_coeff()
289 adv7511_wr(sd, 0x19, A1); in adv7511_csc_coeff()
290 adv7511_wr_and_or(sd, 0x1A, 0xe0, A2>>8); in adv7511_csc_coeff()
291 adv7511_wr(sd, 0x1B, A2); in adv7511_csc_coeff()
292 adv7511_wr_and_or(sd, 0x1c, 0xe0, A3>>8); in adv7511_csc_coeff()
293 adv7511_wr(sd, 0x1d, A3); in adv7511_csc_coeff()
294 adv7511_wr_and_or(sd, 0x1e, 0xe0, A4>>8); in adv7511_csc_coeff()
295 adv7511_wr(sd, 0x1f, A4); in adv7511_csc_coeff()
298 adv7511_wr_and_or(sd, 0x20, 0xe0, B1>>8); in adv7511_csc_coeff()
299 adv7511_wr(sd, 0x21, B1); in adv7511_csc_coeff()
300 adv7511_wr_and_or(sd, 0x22, 0xe0, B2>>8); in adv7511_csc_coeff()
301 adv7511_wr(sd, 0x23, B2); in adv7511_csc_coeff()
302 adv7511_wr_and_or(sd, 0x24, 0xe0, B3>>8); in adv7511_csc_coeff()
303 adv7511_wr(sd, 0x25, B3); in adv7511_csc_coeff()
304 adv7511_wr_and_or(sd, 0x26, 0xe0, B4>>8); in adv7511_csc_coeff()
305 adv7511_wr(sd, 0x27, B4); in adv7511_csc_coeff()
308 adv7511_wr_and_or(sd, 0x28, 0xe0, C1>>8); in adv7511_csc_coeff()
309 adv7511_wr(sd, 0x29, C1); in adv7511_csc_coeff()
310 adv7511_wr_and_or(sd, 0x2A, 0xe0, C2>>8); in adv7511_csc_coeff()
311 adv7511_wr(sd, 0x2B, C2); in adv7511_csc_coeff()
312 adv7511_wr_and_or(sd, 0x2C, 0xe0, C3>>8); in adv7511_csc_coeff()
313 adv7511_wr(sd, 0x2D, C3); in adv7511_csc_coeff()
314 adv7511_wr_and_or(sd, 0x2E, 0xe0, C4>>8); in adv7511_csc_coeff()
315 adv7511_wr(sd, 0x2F, C4); in adv7511_csc_coeff()
318 static void adv7511_csc_rgb_full2limit(struct v4l2_subdev *sd, bool enable) in adv7511_csc_rgb_full2limit() argument
322 adv7511_csc_conversion_mode(sd, csc_mode); in adv7511_csc_rgb_full2limit()
323 adv7511_csc_coeff(sd, in adv7511_csc_rgb_full2limit()
324 4096-564, 0, 0, 256, in adv7511_csc_rgb_full2limit()
325 0, 4096-564, 0, 256, in adv7511_csc_rgb_full2limit()
326 0, 0, 4096-564, 256); in adv7511_csc_rgb_full2limit()
328 adv7511_wr_and_or(sd, 0x18, 0x7f, 0x80); in adv7511_csc_rgb_full2limit()
329 /* AVI infoframe: Limited range RGB (16-235) */ in adv7511_csc_rgb_full2limit()
330 adv7511_wr_and_or(sd, 0x57, 0xf3, 0x04); in adv7511_csc_rgb_full2limit()
333 adv7511_wr_and_or(sd, 0x18, 0x7f, 0x0); in adv7511_csc_rgb_full2limit()
334 /* AVI infoframe: Full range RGB (0-255) */ in adv7511_csc_rgb_full2limit()
335 adv7511_wr_and_or(sd, 0x57, 0xf3, 0x08); in adv7511_csc_rgb_full2limit()
339 static void adv7511_set_rgb_quantization_mode(struct v4l2_subdev *sd, struct v4l2_ctrl *ctrl) in adv7511_set_rgb_quantization_mode() argument
341 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_set_rgb_quantization_mode()
344 if (state->fmt_code != MEDIA_BUS_FMT_RGB888_1X24) { in adv7511_set_rgb_quantization_mode()
346 adv7511_csc_rgb_full2limit(sd, false); in adv7511_set_rgb_quantization_mode()
350 switch (ctrl->val) { in adv7511_set_rgb_quantization_mode()
353 if (state->dv_timings.bt.flags & V4L2_DV_FL_IS_CE_VIDEO) { in adv7511_set_rgb_quantization_mode()
354 /* CE format, RGB limited range (16-235) */ in adv7511_set_rgb_quantization_mode()
355 adv7511_csc_rgb_full2limit(sd, true); in adv7511_set_rgb_quantization_mode()
357 /* not CE format, RGB full range (0-255) */ in adv7511_set_rgb_quantization_mode()
358 adv7511_csc_rgb_full2limit(sd, false); in adv7511_set_rgb_quantization_mode()
362 /* RGB limited range (16-235) */ in adv7511_set_rgb_quantization_mode()
363 adv7511_csc_rgb_full2limit(sd, true); in adv7511_set_rgb_quantization_mode()
366 /* RGB full range (0-255) */ in adv7511_set_rgb_quantization_mode()
367 adv7511_csc_rgb_full2limit(sd, false); in adv7511_set_rgb_quantization_mode()
372 /* ------------------------------ CTRL OPS ------------------------------ */
376 struct v4l2_subdev *sd = to_sd(ctrl); in adv7511_s_ctrl() local
377 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_s_ctrl()
379 v4l2_dbg(1, debug, sd, "%s: ctrl id: %d, ctrl->val %d\n", __func__, ctrl->id, ctrl->val); in adv7511_s_ctrl()
381 if (state->hdmi_mode_ctrl == ctrl) { in adv7511_s_ctrl()
382 /* Set HDMI or DVI-D */ in adv7511_s_ctrl()
383 adv7511_wr_and_or(sd, 0xaf, 0xfd, ctrl->val == V4L2_DV_TX_MODE_HDMI ? 0x02 : 0x00); in adv7511_s_ctrl()
386 if (state->rgb_quantization_range_ctrl == ctrl) { in adv7511_s_ctrl()
387 adv7511_set_rgb_quantization_mode(sd, ctrl); in adv7511_s_ctrl()
390 if (state->content_type_ctrl == ctrl) { in adv7511_s_ctrl()
393 state->content_type = ctrl->val; in adv7511_s_ctrl()
394 itc = state->content_type != V4L2_DV_IT_CONTENT_TYPE_NO_ITC; in adv7511_s_ctrl()
395 cn = itc ? state->content_type : V4L2_DV_IT_CONTENT_TYPE_GRAPHICS; in adv7511_s_ctrl()
396 adv7511_wr_and_or(sd, 0x57, 0x7f, itc << 7); in adv7511_s_ctrl()
397 adv7511_wr_and_or(sd, 0x59, 0xcf, cn << 4); in adv7511_s_ctrl()
401 return -EINVAL; in adv7511_s_ctrl()
408 /* ---------------------------- CORE OPS ------------------------------------------- */
411 static void adv7511_inv_register(struct v4l2_subdev *sd) in adv7511_inv_register() argument
413 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_inv_register()
415 v4l2_info(sd, "0x000-0x0ff: Main Map\n"); in adv7511_inv_register()
416 if (state->i2c_cec) in adv7511_inv_register()
417 v4l2_info(sd, "0x100-0x1ff: CEC Map\n"); in adv7511_inv_register()
420 static int adv7511_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) in adv7511_g_register() argument
422 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_g_register()
424 reg->size = 1; in adv7511_g_register()
425 switch (reg->reg >> 8) { in adv7511_g_register()
427 reg->val = adv7511_rd(sd, reg->reg & 0xff); in adv7511_g_register()
429 case 1: in adv7511_g_register()
430 if (state->i2c_cec) { in adv7511_g_register()
431 reg->val = adv7511_cec_read(sd, reg->reg & 0xff); in adv7511_g_register()
436 v4l2_info(sd, "Register %03llx not supported\n", reg->reg); in adv7511_g_register()
437 adv7511_inv_register(sd); in adv7511_g_register()
443 static int adv7511_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg) in adv7511_s_register() argument
445 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_s_register()
447 switch (reg->reg >> 8) { in adv7511_s_register()
449 adv7511_wr(sd, reg->reg & 0xff, reg->val & 0xff); in adv7511_s_register()
451 case 1: in adv7511_s_register()
452 if (state->i2c_cec) { in adv7511_s_register()
453 adv7511_cec_write(sd, reg->reg & 0xff, reg->val & 0xff); in adv7511_s_register()
458 v4l2_info(sd, "Register %03llx not supported\n", reg->reg); in adv7511_s_register()
459 adv7511_inv_register(sd); in adv7511_s_register()
483 return 256 - csum; in hdmi_infoframe_checksum()
486 static void log_infoframe(struct v4l2_subdev *sd, const struct adv7511_cfg_read_infoframe *cri) in log_infoframe() argument
488 struct i2c_client *client = v4l2_get_subdevdata(sd); in log_infoframe()
489 struct device *dev = &client->dev; in log_infoframe()
495 if (!(adv7511_rd(sd, cri->present_reg) & cri->present_mask)) { in log_infoframe()
496 v4l2_info(sd, "%s infoframe not transmitted\n", cri->desc); in log_infoframe()
500 memcpy(buffer, cri->header, sizeof(cri->header)); in log_infoframe()
505 v4l2_err(sd, "%s: invalid %s infoframe length %d\n", __func__, cri->desc, len); in log_infoframe()
509 if (cri->payload_addr >= 0x100) { in log_infoframe()
511 buffer[i + 4] = adv7511_pktmem_rd(sd, cri->payload_addr + i - 0x100); in log_infoframe()
514 buffer[i + 4] = adv7511_rd(sd, cri->payload_addr + i); in log_infoframe()
520 v4l2_err(sd, "%s: unpack of %s infoframe failed\n", __func__, cri->desc); in log_infoframe()
527 static void adv7511_log_infoframes(struct v4l2_subdev *sd) in adv7511_log_infoframes() argument
531 { "Audio", 0x44, 0x08, { 0x84, 1, 10 }, 0x73 }, in adv7511_log_infoframes()
532 { "SDP", 0x40, 0x40, { 0x83, 1, 25 }, 0x103 }, in adv7511_log_infoframes()
537 log_infoframe(sd, &cri[i]); in adv7511_log_infoframes()
540 static int adv7511_log_status(struct v4l2_subdev *sd) in adv7511_log_status() argument
542 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_log_status()
543 struct adv7511_state_edid *edid = &state->edid; in adv7511_log_status()
568 v4l2_info(sd, "power %s\n", state->power_on ? "on" : "off"); in adv7511_log_status()
569 v4l2_info(sd, "%s hotplug, %s Rx Sense, %s EDID (%d block(s))\n", in adv7511_log_status()
570 (adv7511_rd(sd, 0x42) & MASK_ADV7511_HPD_DETECT) ? "detected" : "no", in adv7511_log_status()
571 (adv7511_rd(sd, 0x42) & MASK_ADV7511_MSEN_DETECT) ? "detected" : "no", in adv7511_log_status()
572 edid->segments ? "found" : "no", in adv7511_log_status()
573 edid->blocks); in adv7511_log_status()
574 v4l2_info(sd, "%s output %s\n", in adv7511_log_status()
575 (adv7511_rd(sd, 0xaf) & 0x02) ? in adv7511_log_status()
576 "HDMI" : "DVI-D", in adv7511_log_status()
577 (adv7511_rd(sd, 0xa1) & 0x3c) ? in adv7511_log_status()
579 v4l2_info(sd, "state: %s, error: %s, detect count: %u, msk/irq: %02x/%02x\n", in adv7511_log_status()
580 states[adv7511_rd(sd, 0xc8) & 0xf], in adv7511_log_status()
581 errors[adv7511_rd(sd, 0xc8) >> 4], state->edid_detect_counter, in adv7511_log_status()
582 adv7511_rd(sd, 0x94), adv7511_rd(sd, 0x96)); in adv7511_log_status()
583 v4l2_info(sd, "RGB quantization: %s range\n", adv7511_rd(sd, 0x18) & 0x80 ? "limited" : "full"); in adv7511_log_status()
584 if (adv7511_rd(sd, 0xaf) & 0x02) { in adv7511_log_status()
586 u8 manual_cts = adv7511_rd(sd, 0x0a) & 0x80; in adv7511_log_status()
587 u32 N = (adv7511_rd(sd, 0x01) & 0xf) << 16 | in adv7511_log_status()
588 adv7511_rd(sd, 0x02) << 8 | in adv7511_log_status()
589 adv7511_rd(sd, 0x03); in adv7511_log_status()
590 u8 vic_detect = adv7511_rd(sd, 0x3e) >> 2; in adv7511_log_status()
591 u8 vic_sent = adv7511_rd(sd, 0x3d) & 0x3f; in adv7511_log_status()
595 CTS = (adv7511_rd(sd, 0x07) & 0xf) << 16 | in adv7511_log_status()
596 adv7511_rd(sd, 0x08) << 8 | in adv7511_log_status()
597 adv7511_rd(sd, 0x09); in adv7511_log_status()
599 CTS = (adv7511_rd(sd, 0x04) & 0xf) << 16 | in adv7511_log_status()
600 adv7511_rd(sd, 0x05) << 8 | in adv7511_log_status()
601 adv7511_rd(sd, 0x06); in adv7511_log_status()
602 v4l2_info(sd, "CTS %s mode: N %d, CTS %d\n", in adv7511_log_status()
604 v4l2_info(sd, "VIC: detected %d, sent %d\n", in adv7511_log_status()
606 adv7511_log_infoframes(sd); in adv7511_log_status()
608 if (state->dv_timings.type == V4L2_DV_BT_656_1120) in adv7511_log_status()
609 v4l2_print_dv_timings(sd->name, "timings: ", in adv7511_log_status()
610 &state->dv_timings, false); in adv7511_log_status()
612 v4l2_info(sd, "no timings set\n"); in adv7511_log_status()
613 v4l2_info(sd, "i2c edid addr: 0x%x\n", state->i2c_edid_addr); in adv7511_log_status()
615 if (state->i2c_cec == NULL) in adv7511_log_status()
618 v4l2_info(sd, "i2c cec addr: 0x%x\n", state->i2c_cec_addr); in adv7511_log_status()
620 v4l2_info(sd, "CEC: %s\n", state->cec_enabled_adap ? in adv7511_log_status()
622 if (state->cec_enabled_adap) { in adv7511_log_status()
624 bool is_valid = state->cec_valid_addrs & (1 << i); in adv7511_log_status()
627 v4l2_info(sd, "CEC Logical Address: 0x%x\n", in adv7511_log_status()
628 state->cec_addr[i]); in adv7511_log_status()
631 v4l2_info(sd, "i2c pktmem addr: 0x%x\n", state->i2c_pktmem_addr); in adv7511_log_status()
636 static int adv7511_s_power(struct v4l2_subdev *sd, int on) in adv7511_s_power() argument
638 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_s_power()
642 v4l2_dbg(1, debug, sd, "%s: power %s\n", __func__, on ? "on" : "off"); in adv7511_s_power()
644 state->power_on = on; in adv7511_s_power()
648 adv7511_wr_and_or(sd, 0x41, 0xbf, 0x40); in adv7511_s_power()
656 adv7511_wr_and_or(sd, 0x41, 0xbf, 0x0); in adv7511_s_power()
657 if ((adv7511_rd(sd, 0x41) & 0x40) == 0) in adv7511_s_power()
659 adv7511_wr_and_or(sd, 0x41, 0xbf, 0x40); in adv7511_s_power()
663 v4l2_dbg(1, debug, sd, "%s: failed to powerup the adv7511!\n", __func__); in adv7511_s_power()
664 adv7511_s_power(sd, 0); in adv7511_s_power()
667 if (i > 1) in adv7511_s_power()
668 v4l2_dbg(1, debug, sd, "%s: needed %d retries to powerup the adv7511\n", __func__, i); in adv7511_s_power()
671 adv7511_wr(sd, 0x98, 0x03); in adv7511_s_power()
672 adv7511_wr_and_or(sd, 0x9a, 0xfe, 0x70); in adv7511_s_power()
673 adv7511_wr(sd, 0x9c, 0x30); in adv7511_s_power()
674 adv7511_wr_and_or(sd, 0x9d, 0xfc, 0x01); in adv7511_s_power()
675 adv7511_wr(sd, 0xa2, 0xa4); in adv7511_s_power()
676 adv7511_wr(sd, 0xa3, 0xa4); in adv7511_s_power()
677 adv7511_wr(sd, 0xe0, 0xd0); in adv7511_s_power()
678 adv7511_wr(sd, 0xf9, 0x00); in adv7511_s_power()
680 adv7511_wr(sd, 0x43, state->i2c_edid_addr); in adv7511_s_power()
681 adv7511_wr(sd, 0x45, state->i2c_pktmem_addr); in adv7511_s_power()
684 adv7511_wr(sd, 0xc9, 0xf); in adv7511_s_power()
692 struct v4l2_subdev *sd = &state->sd; in adv7511_cec_adap_enable() local
694 if (state->i2c_cec == NULL) in adv7511_cec_adap_enable()
695 return -EIO; in adv7511_cec_adap_enable()
697 if (!state->cec_enabled_adap && enable) { in adv7511_cec_adap_enable()
699 adv7511_cec_write_and_or(sd, 0x4e, 0xfc, 0x01); in adv7511_cec_adap_enable()
701 adv7511_cec_write(sd, 0x4a, 0x00); in adv7511_cec_adap_enable()
702 adv7511_cec_write(sd, 0x4a, 0x07); in adv7511_cec_adap_enable()
703 adv7511_cec_write_and_or(sd, 0x11, 0xfe, 0); /* initially disable tx */ in adv7511_cec_adap_enable()
708 /* rx: ready 1 */ in adv7511_cec_adap_enable()
709 if (state->enabled_irq) in adv7511_cec_adap_enable()
710 adv7511_wr_and_or(sd, 0x95, 0xc0, 0x39); in adv7511_cec_adap_enable()
711 } else if (state->cec_enabled_adap && !enable) { in adv7511_cec_adap_enable()
712 if (state->enabled_irq) in adv7511_cec_adap_enable()
713 adv7511_wr_and_or(sd, 0x95, 0xc0, 0x00); in adv7511_cec_adap_enable()
714 /* disable address mask 1-3 */ in adv7511_cec_adap_enable()
715 adv7511_cec_write_and_or(sd, 0x4b, 0x8f, 0x00); in adv7511_cec_adap_enable()
717 adv7511_cec_write_and_or(sd, 0x4e, 0xfc, 0x00); in adv7511_cec_adap_enable()
718 state->cec_valid_addrs = 0; in adv7511_cec_adap_enable()
720 state->cec_enabled_adap = enable; in adv7511_cec_adap_enable()
727 struct v4l2_subdev *sd = &state->sd; in adv7511_cec_adap_log_addr() local
730 if (!state->cec_enabled_adap) in adv7511_cec_adap_log_addr()
731 return addr == CEC_LOG_ADDR_INVALID ? 0 : -EIO; in adv7511_cec_adap_log_addr()
734 adv7511_cec_write_and_or(sd, 0x4b, 0x8f, 0); in adv7511_cec_adap_log_addr()
735 state->cec_valid_addrs = 0; in adv7511_cec_adap_log_addr()
740 bool is_valid = state->cec_valid_addrs & (1 << i); in adv7511_cec_adap_log_addr()
744 if (is_valid && state->cec_addr[i] == addr) in adv7511_cec_adap_log_addr()
750 return -ENXIO; in adv7511_cec_adap_log_addr()
752 state->cec_addr[i] = addr; in adv7511_cec_adap_log_addr()
753 state->cec_valid_addrs |= 1 << i; in adv7511_cec_adap_log_addr()
758 adv7511_cec_write_and_or(sd, 0x4b, 0xef, 0x10); in adv7511_cec_adap_log_addr()
760 adv7511_cec_write_and_or(sd, 0x4c, 0xf0, addr); in adv7511_cec_adap_log_addr()
762 case 1: in adv7511_cec_adap_log_addr()
763 /* enable address mask 1 */ in adv7511_cec_adap_log_addr()
764 adv7511_cec_write_and_or(sd, 0x4b, 0xdf, 0x20); in adv7511_cec_adap_log_addr()
765 /* set address for mask 1 */ in adv7511_cec_adap_log_addr()
766 adv7511_cec_write_and_or(sd, 0x4c, 0x0f, addr << 4); in adv7511_cec_adap_log_addr()
770 adv7511_cec_write_and_or(sd, 0x4b, 0xbf, 0x40); in adv7511_cec_adap_log_addr()
771 /* set address for mask 1 */ in adv7511_cec_adap_log_addr()
772 adv7511_cec_write_and_or(sd, 0x4d, 0xf0, addr); in adv7511_cec_adap_log_addr()
782 struct v4l2_subdev *sd = &state->sd; in adv7511_cec_adap_transmit() local
783 u8 len = msg->len; in adv7511_cec_adap_transmit()
786 v4l2_dbg(1, debug, sd, "%s: len %d\n", __func__, len); in adv7511_cec_adap_transmit()
789 v4l2_err(sd, "%s: len exceeded 16 (%d)\n", __func__, len); in adv7511_cec_adap_transmit()
790 return -EINVAL; in adv7511_cec_adap_transmit()
794 * The number of retries is the number of attempts - 1, but retry in adv7511_cec_adap_transmit()
798 adv7511_cec_write_and_or(sd, 0x12, ~0x70, max(1, attempts - 1) << 4); in adv7511_cec_adap_transmit()
801 adv7511_wr(sd, 0x97, 0x38); in adv7511_cec_adap_transmit()
805 adv7511_cec_write(sd, i, msg->msg[i]); in adv7511_cec_adap_transmit()
808 adv7511_cec_write(sd, 0x10, len); in adv7511_cec_adap_transmit()
810 adv7511_cec_write(sd, 0x11, 0x01); in adv7511_cec_adap_transmit()
814 static void adv_cec_tx_raw_status(struct v4l2_subdev *sd, u8 tx_raw_status) in adv_cec_tx_raw_status() argument
816 struct adv7511_state *state = get_adv7511_state(sd); in adv_cec_tx_raw_status()
818 if ((adv7511_cec_read(sd, 0x11) & 0x01) == 0) { in adv_cec_tx_raw_status()
819 v4l2_dbg(1, debug, sd, "%s: tx raw: tx disabled\n", __func__); in adv_cec_tx_raw_status()
824 v4l2_dbg(1, debug, sd, in adv_cec_tx_raw_status()
826 cec_transmit_done(state->cec_adap, CEC_TX_STATUS_ARB_LOST, in adv_cec_tx_raw_status()
827 1, 0, 0, 0); in adv_cec_tx_raw_status()
835 v4l2_dbg(1, debug, sd, "%s: tx raw: retry failed\n", __func__); in adv_cec_tx_raw_status()
841 nack_cnt = adv7511_cec_read(sd, 0x14) & 0xf; in adv_cec_tx_raw_status()
844 low_drive_cnt = adv7511_cec_read(sd, 0x14) >> 4; in adv_cec_tx_raw_status()
847 cec_transmit_done(state->cec_adap, status, in adv_cec_tx_raw_status()
852 v4l2_dbg(1, debug, sd, "%s: tx raw: ready ok\n", __func__); in adv_cec_tx_raw_status()
853 cec_transmit_done(state->cec_adap, CEC_TX_STATUS_OK, 0, 0, 0, 0); in adv_cec_tx_raw_status()
866 static void adv7511_set_isr(struct v4l2_subdev *sd, bool enable) in adv7511_set_isr() argument
868 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_set_isr()
873 v4l2_dbg(2, debug, sd, "%s: %s\n", __func__, enable ? "enable" : "disable"); in adv7511_set_isr()
875 if (state->enabled_irq == enable) in adv7511_set_isr()
877 state->enabled_irq = enable; in adv7511_set_isr()
883 else if (adv7511_have_hotplug(sd)) in adv7511_set_isr()
887 * This i2c write can fail (approx. 1 in 1000 writes). But it in adv7511_set_isr()
895 adv7511_wr(sd, 0x94, irqs); in adv7511_set_isr()
896 irqs_rd = adv7511_rd(sd, 0x94); in adv7511_set_isr()
897 } while (retries-- && irqs_rd != irqs); in adv7511_set_isr()
900 v4l2_err(sd, "Could not set interrupts: hw failure?\n"); in adv7511_set_isr()
902 adv7511_wr_and_or(sd, 0x95, 0xc0, in adv7511_set_isr()
903 (state->cec_enabled_adap && enable) ? 0x39 : 0x00); in adv7511_set_isr()
907 static int adv7511_isr(struct v4l2_subdev *sd, u32 status, bool *handled) in adv7511_isr() argument
913 adv7511_set_isr(sd, false); in adv7511_isr()
914 irq_status = adv7511_rd(sd, 0x96); in adv7511_isr()
915 cec_irq = adv7511_rd(sd, 0x97); in adv7511_isr()
917 adv7511_wr(sd, 0x96, irq_status); in adv7511_isr()
918 adv7511_wr(sd, 0x97, cec_irq); in adv7511_isr()
920 v4l2_dbg(1, debug, sd, "%s: irq 0x%x, cec-irq 0x%x\n", __func__, in adv7511_isr()
924 adv7511_check_monitor_present_status(sd); in adv7511_isr()
926 adv7511_check_edid_status(sd); in adv7511_isr()
930 adv_cec_tx_raw_status(sd, cec_irq); in adv7511_isr()
932 if (cec_irq & 1) { in adv7511_isr()
933 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_isr()
936 msg.len = adv7511_cec_read(sd, 0x25) & 0x1f; in adv7511_isr()
938 v4l2_dbg(1, debug, sd, "%s: cec msg len %d\n", __func__, in adv7511_isr()
948 msg.msg[i] = adv7511_cec_read(sd, i + 0x15); in adv7511_isr()
950 adv7511_cec_write(sd, 0x4a, 0); /* toggle to re-enable rx 1 */ in adv7511_isr()
951 adv7511_cec_write(sd, 0x4a, 1); in adv7511_isr()
952 cec_received_msg(state->cec_adap, &msg); in adv7511_isr()
958 adv7511_set_isr(sd, true); in adv7511_isr()
975 /* ------------------------------ VIDEO OPS ------------------------------ */
978 static int adv7511_s_stream(struct v4l2_subdev *sd, int enable) in adv7511_s_stream() argument
980 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_s_stream()
982 v4l2_dbg(1, debug, sd, "%s: %sable\n", __func__, (enable ? "en" : "dis")); in adv7511_s_stream()
983 adv7511_wr_and_or(sd, 0xa1, ~0x3c, (enable ? 0 : 0x3c)); in adv7511_s_stream()
985 adv7511_check_monitor_present_status(sd); in adv7511_s_stream()
987 adv7511_s_power(sd, 0); in adv7511_s_stream()
988 state->have_monitor = false; in adv7511_s_stream()
993 static int adv7511_s_dv_timings(struct v4l2_subdev *sd, unsigned int pad, in adv7511_s_dv_timings() argument
996 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_s_dv_timings()
997 struct v4l2_bt_timings *bt = &timings->bt; in adv7511_s_dv_timings()
1000 v4l2_dbg(1, debug, sd, "%s:\n", __func__); in adv7511_s_dv_timings()
1003 return -EINVAL; in adv7511_s_dv_timings()
1007 return -EINVAL; in adv7511_s_dv_timings()
1014 state->dv_timings = *timings; in adv7511_s_dv_timings()
1017 adv7511_wr_and_or(sd, 0x17, 0x9f, in adv7511_s_dv_timings()
1018 ((bt->polarities & V4L2_DV_VSYNC_POS_POL) ? 0 : 0x40) | in adv7511_s_dv_timings()
1019 ((bt->polarities & V4L2_DV_HSYNC_POS_POL) ? 0 : 0x20)); in adv7511_s_dv_timings()
1021 fps = (u32)bt->pixelclock / (V4L2_DV_BT_FRAME_WIDTH(bt) * V4L2_DV_BT_FRAME_HEIGHT(bt)); in adv7511_s_dv_timings()
1024 adv7511_wr_and_or(sd, 0xfb, 0xf9, 1 << 1); in adv7511_s_dv_timings()
1027 adv7511_wr_and_or(sd, 0xfb, 0xf9, 2 << 1); in adv7511_s_dv_timings()
1030 adv7511_wr_and_or(sd, 0xfb, 0xf9, 3 << 1); in adv7511_s_dv_timings()
1033 adv7511_wr_and_or(sd, 0xfb, 0xf9, 0); in adv7511_s_dv_timings()
1038 adv7511_set_rgb_quantization_mode(sd, state->rgb_quantization_range_ctrl); in adv7511_s_dv_timings()
1043 static int adv7511_g_dv_timings(struct v4l2_subdev *sd, unsigned int pad, in adv7511_g_dv_timings() argument
1046 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_g_dv_timings()
1048 v4l2_dbg(1, debug, sd, "%s:\n", __func__); in adv7511_g_dv_timings()
1051 return -EINVAL; in adv7511_g_dv_timings()
1054 return -EINVAL; in adv7511_g_dv_timings()
1056 *timings = state->dv_timings; in adv7511_g_dv_timings()
1061 static int adv7511_enum_dv_timings(struct v4l2_subdev *sd, in adv7511_enum_dv_timings() argument
1064 if (timings->pad != 0) in adv7511_enum_dv_timings()
1065 return -EINVAL; in adv7511_enum_dv_timings()
1070 static int adv7511_dv_timings_cap(struct v4l2_subdev *sd, in adv7511_dv_timings_cap() argument
1073 if (cap->pad != 0) in adv7511_dv_timings_cap()
1074 return -EINVAL; in adv7511_dv_timings_cap()
1084 /* ------------------------------ AUDIO OPS ------------------------------ */
1085 static int adv7511_s_audio_stream(struct v4l2_subdev *sd, int enable) in adv7511_s_audio_stream() argument
1087 v4l2_dbg(1, debug, sd, "%s: %sable\n", __func__, (enable ? "en" : "dis")); in adv7511_s_audio_stream()
1090 adv7511_wr_and_or(sd, 0x4b, 0x3f, 0x80); in adv7511_s_audio_stream()
1092 adv7511_wr_and_or(sd, 0x4b, 0x3f, 0x40); in adv7511_s_audio_stream()
1097 static int adv7511_s_clock_freq(struct v4l2_subdev *sd, u32 freq) in adv7511_s_clock_freq() argument
1110 return -EINVAL; in adv7511_s_clock_freq()
1114 adv7511_wr(sd, 0x01, (N >> 16) & 0xf); in adv7511_s_clock_freq()
1115 adv7511_wr(sd, 0x02, (N >> 8) & 0xff); in adv7511_s_clock_freq()
1116 adv7511_wr(sd, 0x03, N & 0xff); in adv7511_s_clock_freq()
1121 static int adv7511_s_i2s_clock_freq(struct v4l2_subdev *sd, u32 freq) in adv7511_s_i2s_clock_freq() argument
1134 return -EINVAL; in adv7511_s_i2s_clock_freq()
1138 adv7511_wr_and_or(sd, 0x15, 0xf, i2s_sf); in adv7511_s_i2s_clock_freq()
1143 static int adv7511_s_routing(struct v4l2_subdev *sd, u32 input, u32 output, u32 config) in adv7511_s_routing() argument
1146 adv7511_wr_and_or(sd, 0x73, 0xf8, 0x1); in adv7511_s_routing()
1148 adv7511_wr(sd, 0x76, 0x00); in adv7511_s_routing()
1151 adv7511_wr_and_or(sd, 0x14, 0xf0, 0x02); in adv7511_s_routing()
1163 /* ---------------------------- PAD OPS ------------------------------------- */
1165 static int adv7511_get_edid(struct v4l2_subdev *sd, struct v4l2_edid *edid) in adv7511_get_edid() argument
1167 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_get_edid()
1169 memset(edid->reserved, 0, sizeof(edid->reserved)); in adv7511_get_edid()
1171 if (edid->pad != 0) in adv7511_get_edid()
1172 return -EINVAL; in adv7511_get_edid()
1174 if (edid->start_block == 0 && edid->blocks == 0) { in adv7511_get_edid()
1175 edid->blocks = state->edid.blocks; in adv7511_get_edid()
1179 if (state->edid.blocks == 0) in adv7511_get_edid()
1180 return -ENODATA; in adv7511_get_edid()
1182 if (edid->start_block >= state->edid.blocks) in adv7511_get_edid()
1183 return -EINVAL; in adv7511_get_edid()
1185 if (edid->start_block + edid->blocks > state->edid.blocks) in adv7511_get_edid()
1186 edid->blocks = state->edid.blocks - edid->start_block; in adv7511_get_edid()
1188 memcpy(edid->edid, &state->edid.data[edid->start_block * 128], in adv7511_get_edid()
1189 128 * edid->blocks); in adv7511_get_edid()
1194 static int adv7511_enum_mbus_code(struct v4l2_subdev *sd, in adv7511_enum_mbus_code() argument
1198 if (code->pad != 0) in adv7511_enum_mbus_code()
1199 return -EINVAL; in adv7511_enum_mbus_code()
1201 switch (code->index) { in adv7511_enum_mbus_code()
1203 code->code = MEDIA_BUS_FMT_RGB888_1X24; in adv7511_enum_mbus_code()
1205 case 1: in adv7511_enum_mbus_code()
1206 code->code = MEDIA_BUS_FMT_YUYV8_1X16; in adv7511_enum_mbus_code()
1209 code->code = MEDIA_BUS_FMT_UYVY8_1X16; in adv7511_enum_mbus_code()
1212 return -EINVAL; in adv7511_enum_mbus_code()
1220 format->width = state->dv_timings.bt.width; in adv7511_fill_format()
1221 format->height = state->dv_timings.bt.height; in adv7511_fill_format()
1222 format->field = V4L2_FIELD_NONE; in adv7511_fill_format()
1225 static int adv7511_get_fmt(struct v4l2_subdev *sd, in adv7511_get_fmt() argument
1229 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_get_fmt()
1231 if (format->pad != 0) in adv7511_get_fmt()
1232 return -EINVAL; in adv7511_get_fmt()
1234 memset(&format->format, 0, sizeof(format->format)); in adv7511_get_fmt()
1235 adv7511_fill_format(state, &format->format); in adv7511_get_fmt()
1237 if (format->which == V4L2_SUBDEV_FORMAT_TRY) { in adv7511_get_fmt()
1240 fmt = v4l2_subdev_state_get_format(sd_state, format->pad); in adv7511_get_fmt()
1241 format->format.code = fmt->code; in adv7511_get_fmt()
1242 format->format.colorspace = fmt->colorspace; in adv7511_get_fmt()
1243 format->format.ycbcr_enc = fmt->ycbcr_enc; in adv7511_get_fmt()
1244 format->format.quantization = fmt->quantization; in adv7511_get_fmt()
1245 format->format.xfer_func = fmt->xfer_func; in adv7511_get_fmt()
1247 format->format.code = state->fmt_code; in adv7511_get_fmt()
1248 format->format.colorspace = state->colorspace; in adv7511_get_fmt()
1249 format->format.ycbcr_enc = state->ycbcr_enc; in adv7511_get_fmt()
1250 format->format.quantization = state->quantization; in adv7511_get_fmt()
1251 format->format.xfer_func = state->xfer_func; in adv7511_get_fmt()
1257 static int adv7511_set_fmt(struct v4l2_subdev *sd, in adv7511_set_fmt() argument
1261 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_set_fmt()
1263 * Bitfield namings come the CEA-861-F standard, table 8 "Auxiliary in adv7511_set_fmt()
1277 u8 itc = state->content_type != V4L2_DV_IT_CONTENT_TYPE_NO_ITC; in adv7511_set_fmt()
1278 u8 cn = itc ? state->content_type : V4L2_DV_IT_CONTENT_TYPE_GRAPHICS; in adv7511_set_fmt()
1280 if (format->pad != 0) in adv7511_set_fmt()
1281 return -EINVAL; in adv7511_set_fmt()
1282 switch (format->format.code) { in adv7511_set_fmt()
1288 return -EINVAL; in adv7511_set_fmt()
1291 adv7511_fill_format(state, &format->format); in adv7511_set_fmt()
1292 if (format->which == V4L2_SUBDEV_FORMAT_TRY) { in adv7511_set_fmt()
1295 fmt = v4l2_subdev_state_get_format(sd_state, format->pad); in adv7511_set_fmt()
1296 fmt->code = format->format.code; in adv7511_set_fmt()
1297 fmt->colorspace = format->format.colorspace; in adv7511_set_fmt()
1298 fmt->ycbcr_enc = format->format.ycbcr_enc; in adv7511_set_fmt()
1299 fmt->quantization = format->format.quantization; in adv7511_set_fmt()
1300 fmt->xfer_func = format->format.xfer_func; in adv7511_set_fmt()
1304 switch (format->format.code) { in adv7511_set_fmt()
1306 adv7511_wr_and_or(sd, 0x15, 0xf0, 0x01); in adv7511_set_fmt()
1307 adv7511_wr_and_or(sd, 0x16, 0x03, 0xb8); in adv7511_set_fmt()
1311 adv7511_wr_and_or(sd, 0x15, 0xf0, 0x01); in adv7511_set_fmt()
1312 adv7511_wr_and_or(sd, 0x16, 0x03, 0xbc); in adv7511_set_fmt()
1317 adv7511_wr_and_or(sd, 0x15, 0xf0, 0x00); in adv7511_set_fmt()
1318 adv7511_wr_and_or(sd, 0x16, 0x03, 0x00); in adv7511_set_fmt()
1321 state->fmt_code = format->format.code; in adv7511_set_fmt()
1322 state->colorspace = format->format.colorspace; in adv7511_set_fmt()
1323 state->ycbcr_enc = format->format.ycbcr_enc; in adv7511_set_fmt()
1324 state->quantization = format->format.quantization; in adv7511_set_fmt()
1325 state->xfer_func = format->format.xfer_func; in adv7511_set_fmt()
1327 switch (format->format.colorspace) { in adv7511_set_fmt()
1335 if (y && format->format.ycbcr_enc == V4L2_YCBCR_ENC_XV601) { in adv7511_set_fmt()
1342 if (y && format->format.ycbcr_enc == V4L2_YCBCR_ENC_XV709) { in adv7511_set_fmt()
1354 if (y && format->format.ycbcr_enc == V4L2_YCBCR_ENC_BT2020_CONST_LUM) in adv7511_set_fmt()
1364 * CEA-861-F says that for RGB formats the YCC range must match the in adv7511_set_fmt()
1367 * The RGB quantization range shouldn't be non-zero if the EDID doesn't in adv7511_set_fmt()
1372 * The same is true for the YCC quantization range: non-standard YCC in adv7511_set_fmt()
1376 switch (format->format.quantization) { in adv7511_set_fmt()
1380 yq = q ? q - 1 : HDMI_YCC_QUANTIZATION_RANGE_FULL; in adv7511_set_fmt()
1385 yq = q ? q - 1 : HDMI_YCC_QUANTIZATION_RANGE_LIMITED; in adv7511_set_fmt()
1389 adv7511_wr_and_or(sd, 0x4a, 0xbf, 0); in adv7511_set_fmt()
1390 adv7511_wr_and_or(sd, 0x55, 0x9f, y << 5); in adv7511_set_fmt()
1391 adv7511_wr_and_or(sd, 0x56, 0x3f, c << 6); in adv7511_set_fmt()
1392 adv7511_wr_and_or(sd, 0x57, 0x83, (ec << 4) | (q << 2) | (itc << 7)); in adv7511_set_fmt()
1393 adv7511_wr_and_or(sd, 0x59, 0x0f, (yq << 6) | (cn << 4)); in adv7511_set_fmt()
1394 adv7511_wr_and_or(sd, 0x4a, 0xff, 1); in adv7511_set_fmt()
1395 adv7511_set_rgb_quantization_mode(sd, state->rgb_quantization_range_ctrl); in adv7511_set_fmt()
1411 /* --------------------- SUBDEV OPS --------------------------------------- */
1420 /* ----------------------------------------------------------------------- */
1421 static void adv7511_dbg_dump_edid(int lvl, int debug, struct v4l2_subdev *sd, int segment, u8 *buf) in adv7511_dbg_dump_edid() argument
1425 v4l2_dbg(lvl, debug, sd, "edid segment %d\n", segment); in adv7511_dbg_dump_edid()
1430 v4l2_dbg(lvl, debug, sd, "\n"); in adv7511_dbg_dump_edid()
1436 v4l2_dbg(lvl, debug, sd, "%s\n", b); in adv7511_dbg_dump_edid()
1441 static void adv7511_notify_no_edid(struct v4l2_subdev *sd) in adv7511_notify_no_edid() argument
1443 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_notify_no_edid()
1448 ed.segment = adv7511_rd(sd, 0xc4); in adv7511_notify_no_edid()
1450 cec_s_phys_addr(state->cec_adap, ed.phys_addr, false); in adv7511_notify_no_edid()
1451 v4l2_subdev_notify(sd, ADV7511_EDID_DETECT, (void *)&ed); in adv7511_notify_no_edid()
1452 v4l2_ctrl_s_ctrl(state->have_edid0_ctrl, 0x0); in adv7511_notify_no_edid()
1459 struct v4l2_subdev *sd = &state->sd; in adv7511_edid_handler() local
1461 v4l2_dbg(1, debug, sd, "%s:\n", __func__); in adv7511_edid_handler()
1463 if (adv7511_check_edid_status(sd)) { in adv7511_edid_handler()
1468 if (adv7511_have_hotplug(sd)) { in adv7511_edid_handler()
1472 if (state->edid.read_retries) { in adv7511_edid_handler()
1473 state->edid.read_retries--; in adv7511_edid_handler()
1474 v4l2_dbg(1, debug, sd, "%s: edid read failed\n", __func__); in adv7511_edid_handler()
1475 state->have_monitor = false; in adv7511_edid_handler()
1476 adv7511_s_power(sd, false); in adv7511_edid_handler()
1477 adv7511_s_power(sd, true); in adv7511_edid_handler()
1478 queue_delayed_work(state->work_queue, &state->edid_handler, EDID_DELAY); in adv7511_edid_handler()
1484 adv7511_notify_no_edid(sd); in adv7511_edid_handler()
1485 v4l2_dbg(1, debug, sd, "%s: no edid found\n", __func__); in adv7511_edid_handler()
1488 static void adv7511_audio_setup(struct v4l2_subdev *sd) in adv7511_audio_setup() argument
1490 v4l2_dbg(1, debug, sd, "%s\n", __func__); in adv7511_audio_setup()
1492 adv7511_s_i2s_clock_freq(sd, 48000); in adv7511_audio_setup()
1493 adv7511_s_clock_freq(sd, 48000); in adv7511_audio_setup()
1494 adv7511_s_routing(sd, 0, 0, 0); in adv7511_audio_setup()
1498 static void adv7511_setup(struct v4l2_subdev *sd) in adv7511_setup() argument
1500 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_setup()
1501 v4l2_dbg(1, debug, sd, "%s\n", __func__); in adv7511_setup()
1504 adv7511_wr_and_or(sd, 0x15, 0xf0, 0x0); in adv7511_setup()
1506 adv7511_wr_and_or(sd, 0x16, 0x7f, 0x0); in adv7511_setup()
1507 /* 1st order interpolation 4:2:2 -> 4:4:4 up conversion, Aspect ratio: 16:9 */ in adv7511_setup()
1508 adv7511_wr_and_or(sd, 0x17, 0xf9, 0x06); in adv7511_setup()
1510 adv7511_wr_and_or(sd, 0x3b, 0x9f, 0x0); in adv7511_setup()
1512 adv7511_wr_and_or(sd, 0x18, 0x7f, 0x0); in adv7511_setup()
1515 adv7511_wr_and_or(sd, 0x55, 0x9c, 0x12); in adv7511_setup()
1517 adv7511_wr_and_or(sd, 0x44, 0xe7, 0x10); in adv7511_setup()
1519 adv7511_wr(sd, 0x56, 0xa8); in adv7511_setup()
1521 adv7511_wr_and_or(sd, 0xaf, 0xed, 0x0); in adv7511_setup()
1524 adv7511_wr_and_or(sd, 0xba, 0x1f, 0x60); in adv7511_setup()
1526 adv7511_audio_setup(sd); in adv7511_setup()
1528 v4l2_ctrl_handler_setup(&state->hdl); in adv7511_setup()
1531 static void adv7511_notify_monitor_detect(struct v4l2_subdev *sd) in adv7511_notify_monitor_detect() argument
1534 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_notify_monitor_detect()
1536 mdt.present = state->have_monitor; in adv7511_notify_monitor_detect()
1537 v4l2_subdev_notify(sd, ADV7511_MONITOR_DETECT, (void *)&mdt); in adv7511_notify_monitor_detect()
1540 static void adv7511_check_monitor_present_status(struct v4l2_subdev *sd) in adv7511_check_monitor_present_status() argument
1542 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_check_monitor_present_status()
1543 /* read hotplug and rx-sense state */ in adv7511_check_monitor_present_status()
1544 u8 status = adv7511_rd(sd, 0x42); in adv7511_check_monitor_present_status()
1546 v4l2_dbg(1, debug, sd, "%s: status: 0x%x%s%s\n", in adv7511_check_monitor_present_status()
1550 status & MASK_ADV7511_MSEN_DETECT ? ", rx-sense" : ""); in adv7511_check_monitor_present_status()
1553 v4l2_ctrl_s_ctrl(state->hotplug_ctrl, adv7511_have_hotplug(sd) ? 0x1 : 0x0); in adv7511_check_monitor_present_status()
1554 v4l2_ctrl_s_ctrl(state->rx_sense_ctrl, adv7511_have_rx_sense(sd) ? 0x1 : 0x0); in adv7511_check_monitor_present_status()
1556 …if ((status & MASK_ADV7511_HPD_DETECT) && ((status & MASK_ADV7511_MSEN_DETECT) || state->edid.segm… in adv7511_check_monitor_present_status()
1557 v4l2_dbg(1, debug, sd, "%s: hotplug and (rx-sense or edid)\n", __func__); in adv7511_check_monitor_present_status()
1558 if (!state->have_monitor) { in adv7511_check_monitor_present_status()
1559 v4l2_dbg(1, debug, sd, "%s: monitor detected\n", __func__); in adv7511_check_monitor_present_status()
1560 state->have_monitor = true; in adv7511_check_monitor_present_status()
1561 adv7511_set_isr(sd, true); in adv7511_check_monitor_present_status()
1562 if (!adv7511_s_power(sd, true)) { in adv7511_check_monitor_present_status()
1563 v4l2_dbg(1, debug, sd, "%s: monitor detected, powerup failed\n", __func__); in adv7511_check_monitor_present_status()
1566 adv7511_setup(sd); in adv7511_check_monitor_present_status()
1567 adv7511_notify_monitor_detect(sd); in adv7511_check_monitor_present_status()
1568 state->edid.read_retries = EDID_MAX_RETRIES; in adv7511_check_monitor_present_status()
1569 queue_delayed_work(state->work_queue, &state->edid_handler, EDID_DELAY); in adv7511_check_monitor_present_status()
1572 v4l2_dbg(1, debug, sd, "%s: hotplug detected\n", __func__); in adv7511_check_monitor_present_status()
1573 state->edid.read_retries = EDID_MAX_RETRIES; in adv7511_check_monitor_present_status()
1574 queue_delayed_work(state->work_queue, &state->edid_handler, EDID_DELAY); in adv7511_check_monitor_present_status()
1576 v4l2_dbg(1, debug, sd, "%s: hotplug not detected\n", __func__); in adv7511_check_monitor_present_status()
1577 if (state->have_monitor) { in adv7511_check_monitor_present_status()
1578 v4l2_dbg(1, debug, sd, "%s: monitor not detected\n", __func__); in adv7511_check_monitor_present_status()
1579 state->have_monitor = false; in adv7511_check_monitor_present_status()
1580 adv7511_notify_monitor_detect(sd); in adv7511_check_monitor_present_status()
1582 adv7511_s_power(sd, false); in adv7511_check_monitor_present_status()
1583 memset(&state->edid, 0, sizeof(struct adv7511_state_edid)); in adv7511_check_monitor_present_status()
1584 adv7511_notify_no_edid(sd); in adv7511_check_monitor_present_status()
1598 static bool edid_verify_crc(struct v4l2_subdev *sd, u32 segment) in edid_verify_crc() argument
1600 struct adv7511_state *state = get_adv7511_state(sd); in edid_verify_crc()
1601 u32 blocks = state->edid.blocks; in edid_verify_crc()
1602 u8 *data = state->edid.data; in edid_verify_crc()
1606 if ((segment + 1) * 2 <= blocks) in edid_verify_crc()
1611 static bool edid_verify_header(struct v4l2_subdev *sd, u32 segment) in edid_verify_header() argument
1616 struct adv7511_state *state = get_adv7511_state(sd); in edid_verify_header()
1617 u8 *data = state->edid.data; in edid_verify_header()
1624 static bool adv7511_check_edid_status(struct v4l2_subdev *sd) in adv7511_check_edid_status() argument
1626 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_check_edid_status()
1627 u8 edidRdy = adv7511_rd(sd, 0xc5); in adv7511_check_edid_status()
1629 v4l2_dbg(1, debug, sd, "%s: edid ready (retries: %d)\n", in adv7511_check_edid_status()
1630 __func__, EDID_MAX_RETRIES - state->edid.read_retries); in adv7511_check_edid_status()
1632 if (state->edid.complete) in adv7511_check_edid_status()
1636 int segment = adv7511_rd(sd, 0xc4); in adv7511_check_edid_status()
1641 v4l2_err(sd, "edid segment number too big\n"); in adv7511_check_edid_status()
1644 v4l2_dbg(1, debug, sd, "%s: got segment %d\n", __func__, segment); in adv7511_check_edid_status()
1645 err = adv7511_edid_rd(sd, 256, &state->edid.data[segment * 256]); in adv7511_check_edid_status()
1647 adv7511_dbg_dump_edid(2, debug, sd, segment, &state->edid.data[segment * 256]); in adv7511_check_edid_status()
1649 state->edid.blocks = state->edid.data[0x7e] + 1; in adv7511_check_edid_status()
1650 v4l2_dbg(1, debug, sd, "%s: %d blocks in total\n", in adv7511_check_edid_status()
1651 __func__, state->edid.blocks); in adv7511_check_edid_status()
1655 if (err || !edid_verify_crc(sd, segment) || !edid_verify_header(sd, segment)) { in adv7511_check_edid_status()
1658 v4l2_err(sd, "%s: edid crc or header error\n", __func__); in adv7511_check_edid_status()
1659 state->have_monitor = false; in adv7511_check_edid_status()
1660 adv7511_s_power(sd, false); in adv7511_check_edid_status()
1661 adv7511_s_power(sd, true); in adv7511_check_edid_status()
1665 state->edid.segments = segment + 1; in adv7511_check_edid_status()
1666 v4l2_ctrl_s_ctrl(state->have_edid0_ctrl, 0x1); in adv7511_check_edid_status()
1667 if (((state->edid.data[0x7e] >> 1) + 1) > state->edid.segments) { in adv7511_check_edid_status()
1669 v4l2_dbg(1, debug, sd, "%s: request segment %d\n", __func__, state->edid.segments); in adv7511_check_edid_status()
1670 adv7511_wr(sd, 0xc9, 0xf); in adv7511_check_edid_status()
1671 adv7511_wr(sd, 0xc4, state->edid.segments); in adv7511_check_edid_status()
1672 state->edid.read_retries = EDID_MAX_RETRIES; in adv7511_check_edid_status()
1673 queue_delayed_work(state->work_queue, &state->edid_handler, EDID_DELAY); in adv7511_check_edid_status()
1677 v4l2_dbg(1, debug, sd, "%s: edid complete with %d segment(s)\n", __func__, state->edid.segments); in adv7511_check_edid_status()
1678 state->edid.complete = true; in adv7511_check_edid_status()
1679 ed.phys_addr = cec_get_edid_phys_addr(state->edid.data, in adv7511_check_edid_status()
1680 state->edid.segments * 256, in adv7511_check_edid_status()
1687 state->edid_detect_counter++; in adv7511_check_edid_status()
1688 cec_s_phys_addr(state->cec_adap, ed.phys_addr, false); in adv7511_check_edid_status()
1689 v4l2_subdev_notify(sd, ADV7511_EDID_DETECT, (void *)&ed); in adv7511_check_edid_status()
1696 static int adv7511_registered(struct v4l2_subdev *sd) in adv7511_registered() argument
1698 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_registered()
1699 struct i2c_client *client = v4l2_get_subdevdata(sd); in adv7511_registered()
1702 err = cec_register_adapter(state->cec_adap, &client->dev); in adv7511_registered()
1704 cec_delete_adapter(state->cec_adap); in adv7511_registered()
1708 static void adv7511_unregistered(struct v4l2_subdev *sd) in adv7511_unregistered() argument
1710 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_unregistered()
1712 cec_unregister_adapter(state->cec_adap); in adv7511_unregistered()
1720 /* ----------------------------------------------------------------------- */
1722 static void adv7511_init_setup(struct v4l2_subdev *sd) in adv7511_init_setup() argument
1724 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_init_setup()
1725 struct adv7511_state_edid *edid = &state->edid; in adv7511_init_setup()
1726 u32 cec_clk = state->pdata.cec_clk; in adv7511_init_setup()
1729 v4l2_dbg(1, debug, sd, "%s\n", __func__); in adv7511_init_setup()
1732 adv7511_wr(sd, 0x96, 0xff); in adv7511_init_setup()
1733 adv7511_wr(sd, 0x97, 0xff); in adv7511_init_setup()
1736 * It might leave the chip in a partly un-initialized state, in adv7511_init_setup()
1739 adv7511_wr_and_or(sd, 0xd6, 0x3f, 0xc0); in adv7511_init_setup()
1741 state->have_monitor = false; in adv7511_init_setup()
1742 adv7511_set_isr(sd, false); in adv7511_init_setup()
1743 adv7511_s_stream(sd, false); in adv7511_init_setup()
1744 adv7511_s_audio_stream(sd, false); in adv7511_init_setup()
1746 if (state->i2c_cec == NULL) in adv7511_init_setup()
1749 v4l2_dbg(1, debug, sd, "%s: cec_clk %d\n", __func__, cec_clk); in adv7511_init_setup()
1752 adv7511_cec_write(sd, 0x50, 0x01); in adv7511_init_setup()
1753 adv7511_cec_write(sd, 0x50, 0x00); in adv7511_init_setup()
1756 adv7511_cec_write(sd, 0x4a, 0x00); in adv7511_init_setup()
1757 adv7511_cec_write(sd, 0x4a, 0x07); in adv7511_init_setup()
1760 v4l2_err(sd, "%s: cec_clk %d, not multiple of 750 Khz\n", in adv7511_init_setup()
1763 ratio = (cec_clk / 750000) - 1; in adv7511_init_setup()
1764 adv7511_cec_write(sd, 0x4e, ratio << 2); in adv7511_init_setup()
1770 struct adv7511_platform_data *pdata = client->dev.platform_data; in adv7511_probe()
1772 struct v4l2_subdev *sd; in adv7511_probe() local
1774 int err = -EIO; in adv7511_probe()
1777 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) in adv7511_probe()
1778 return -EIO; in adv7511_probe()
1780 state = devm_kzalloc(&client->dev, sizeof(struct adv7511_state), GFP_KERNEL); in adv7511_probe()
1782 return -ENOMEM; in adv7511_probe()
1787 return -ENODEV; in adv7511_probe()
1789 memcpy(&state->pdata, pdata, sizeof(state->pdata)); in adv7511_probe()
1790 state->fmt_code = MEDIA_BUS_FMT_RGB888_1X24; in adv7511_probe()
1791 state->colorspace = V4L2_COLORSPACE_SRGB; in adv7511_probe()
1793 sd = &state->sd; in adv7511_probe()
1795 v4l2_dbg(1, debug, sd, "detecting adv7511 client on address 0x%x\n", in adv7511_probe()
1796 client->addr << 1); in adv7511_probe()
1798 v4l2_i2c_subdev_init(sd, client, &adv7511_ops); in adv7511_probe()
1799 sd->internal_ops = &adv7511_int_ops; in adv7511_probe()
1801 hdl = &state->hdl; in adv7511_probe()
1804 state->hdmi_mode_ctrl = v4l2_ctrl_new_std_menu(hdl, &adv7511_ctrl_ops, in adv7511_probe()
1807 state->hotplug_ctrl = v4l2_ctrl_new_std(hdl, NULL, in adv7511_probe()
1808 V4L2_CID_DV_TX_HOTPLUG, 0, 1, 0, 0); in adv7511_probe()
1809 state->rx_sense_ctrl = v4l2_ctrl_new_std(hdl, NULL, in adv7511_probe()
1810 V4L2_CID_DV_TX_RXSENSE, 0, 1, 0, 0); in adv7511_probe()
1811 state->have_edid0_ctrl = v4l2_ctrl_new_std(hdl, NULL, in adv7511_probe()
1812 V4L2_CID_DV_TX_EDID_PRESENT, 0, 1, 0, 0); in adv7511_probe()
1813 state->rgb_quantization_range_ctrl = in adv7511_probe()
1817 state->content_type_ctrl = in adv7511_probe()
1821 sd->ctrl_handler = hdl; in adv7511_probe()
1822 if (hdl->error) { in adv7511_probe()
1823 err = hdl->error; in adv7511_probe()
1826 state->pad.flags = MEDIA_PAD_FL_SINK; in adv7511_probe()
1827 sd->entity.function = MEDIA_ENT_F_DV_ENCODER; in adv7511_probe()
1828 err = media_entity_pads_init(&sd->entity, 1, &state->pad); in adv7511_probe()
1833 state->i2c_edid_addr = state->pdata.i2c_edid << 1; in adv7511_probe()
1834 state->i2c_cec_addr = state->pdata.i2c_cec << 1; in adv7511_probe()
1835 state->i2c_pktmem_addr = state->pdata.i2c_pktmem << 1; in adv7511_probe()
1837 state->chip_revision = adv7511_rd(sd, 0x0); in adv7511_probe()
1838 chip_id[0] = adv7511_rd(sd, 0xf5); in adv7511_probe()
1839 chip_id[1] = adv7511_rd(sd, 0xf6); in adv7511_probe()
1840 if (chip_id[0] != 0x75 || chip_id[1] != 0x11) { in adv7511_probe()
1841 v4l2_err(sd, "chip_id != 0x7511, read 0x%02x%02x\n", chip_id[0], in adv7511_probe()
1842 chip_id[1]); in adv7511_probe()
1843 err = -EIO; in adv7511_probe()
1847 state->i2c_edid = i2c_new_dummy_device(client->adapter, in adv7511_probe()
1848 state->i2c_edid_addr >> 1); in adv7511_probe()
1849 if (IS_ERR(state->i2c_edid)) { in adv7511_probe()
1850 v4l2_err(sd, "failed to register edid i2c client\n"); in adv7511_probe()
1851 err = PTR_ERR(state->i2c_edid); in adv7511_probe()
1855 adv7511_wr(sd, 0xe1, state->i2c_cec_addr); in adv7511_probe()
1856 if (state->pdata.cec_clk < 3000000 || in adv7511_probe()
1857 state->pdata.cec_clk > 100000000) { in adv7511_probe()
1858 v4l2_err(sd, "%s: cec_clk %u outside range, disabling cec\n", in adv7511_probe()
1859 __func__, state->pdata.cec_clk); in adv7511_probe()
1860 state->pdata.cec_clk = 0; in adv7511_probe()
1863 if (state->pdata.cec_clk) { in adv7511_probe()
1864 state->i2c_cec = i2c_new_dummy_device(client->adapter, in adv7511_probe()
1865 state->i2c_cec_addr >> 1); in adv7511_probe()
1866 if (IS_ERR(state->i2c_cec)) { in adv7511_probe()
1867 v4l2_err(sd, "failed to register cec i2c client\n"); in adv7511_probe()
1868 err = PTR_ERR(state->i2c_cec); in adv7511_probe()
1871 adv7511_wr(sd, 0xe2, 0x00); /* power up cec section */ in adv7511_probe()
1873 adv7511_wr(sd, 0xe2, 0x01); /* power down cec section */ in adv7511_probe()
1876 state->i2c_pktmem = i2c_new_dummy_device(client->adapter, state->i2c_pktmem_addr >> 1); in adv7511_probe()
1877 if (IS_ERR(state->i2c_pktmem)) { in adv7511_probe()
1878 v4l2_err(sd, "failed to register pktmem i2c client\n"); in adv7511_probe()
1879 err = PTR_ERR(state->i2c_pktmem); in adv7511_probe()
1883 state->work_queue = create_singlethread_workqueue(sd->name); in adv7511_probe()
1884 if (state->work_queue == NULL) { in adv7511_probe()
1885 v4l2_err(sd, "could not create workqueue\n"); in adv7511_probe()
1886 err = -ENOMEM; in adv7511_probe()
1890 INIT_DELAYED_WORK(&state->edid_handler, adv7511_edid_handler); in adv7511_probe()
1892 adv7511_init_setup(sd); in adv7511_probe()
1895 state->cec_adap = cec_allocate_adapter(&adv7511_cec_adap_ops, in adv7511_probe()
1896 state, dev_name(&client->dev), CEC_CAP_DEFAULTS, in adv7511_probe()
1898 err = PTR_ERR_OR_ZERO(state->cec_adap); in adv7511_probe()
1900 destroy_workqueue(state->work_queue); in adv7511_probe()
1905 adv7511_set_isr(sd, true); in adv7511_probe()
1906 adv7511_check_monitor_present_status(sd); in adv7511_probe()
1908 v4l2_info(sd, "%s found @ 0x%x (%s)\n", client->name, in adv7511_probe()
1909 client->addr << 1, client->adapter->name); in adv7511_probe()
1913 i2c_unregister_device(state->i2c_pktmem); in adv7511_probe()
1915 i2c_unregister_device(state->i2c_cec); in adv7511_probe()
1917 i2c_unregister_device(state->i2c_edid); in adv7511_probe()
1919 media_entity_cleanup(&sd->entity); in adv7511_probe()
1921 v4l2_ctrl_handler_free(&state->hdl); in adv7511_probe()
1925 /* ----------------------------------------------------------------------- */
1929 struct v4l2_subdev *sd = i2c_get_clientdata(client); in adv7511_remove() local
1930 struct adv7511_state *state = get_adv7511_state(sd); in adv7511_remove()
1932 state->chip_revision = -1; in adv7511_remove()
1934 v4l2_dbg(1, debug, sd, "%s removed @ 0x%x (%s)\n", client->name, in adv7511_remove()
1935 client->addr << 1, client->adapter->name); in adv7511_remove()
1937 adv7511_set_isr(sd, false); in adv7511_remove()
1938 adv7511_init_setup(sd); in adv7511_remove()
1939 cancel_delayed_work_sync(&state->edid_handler); in adv7511_remove()
1940 i2c_unregister_device(state->i2c_edid); in adv7511_remove()
1941 i2c_unregister_device(state->i2c_cec); in adv7511_remove()
1942 i2c_unregister_device(state->i2c_pktmem); in adv7511_remove()
1943 destroy_workqueue(state->work_queue); in adv7511_remove()
1944 v4l2_device_unregister_subdev(sd); in adv7511_remove()
1945 media_entity_cleanup(&sd->entity); in adv7511_remove()
1946 v4l2_ctrl_handler_free(sd->ctrl_handler); in adv7511_remove()
1949 /* ----------------------------------------------------------------------- */
1952 { "adv7511-v4l2" },
1959 .name = "adv7511-v4l2",