Lines Matching +full:hdmi +full:- +full:tx

1 // SPDX-License-Identifier: GPL-2.0+
3 * Driver for Analog Devices ADV748X HDMI receiver and Component Processor (CP)
11 #include <media/v4l2-ctrls.h>
12 #include <media/v4l2-device.h>
13 #include <media/v4l2-dv-timings.h>
14 #include <media/v4l2-ioctl.h>
16 #include <uapi/linux/v4l2-dv-timings.h>
20 /* -----------------------------------------------------------------------------
21 * HDMI and CP
29 /* V4L2_DV_BT_CEA_720X480I59_94 - 0.5 MHz */
90 static void adv748x_hdmi_fill_format(struct adv748x_hdmi *hdmi, in adv748x_hdmi_fill_format() argument
95 fmt->code = MEDIA_BUS_FMT_RGB888_1X24; in adv748x_hdmi_fill_format()
96 fmt->field = hdmi->timings.bt.interlaced ? in adv748x_hdmi_fill_format()
100 fmt->colorspace = V4L2_COLORSPACE_SRGB; in adv748x_hdmi_fill_format()
102 fmt->width = hdmi->timings.bt.width; in adv748x_hdmi_fill_format()
103 fmt->height = hdmi->timings.bt.height; in adv748x_hdmi_fill_format()
105 if (fmt->field == V4L2_FIELD_ALTERNATE) in adv748x_hdmi_fill_format()
106 fmt->height /= 2; in adv748x_hdmi_fill_format()
132 return -ENODATA; in adv748x_hdmi_read_pixelclock()
136 * The low 7 bits of TMDS_2 store the 7-bit TMDS fractional frequency in adv748x_hdmi_read_pixelclock()
145 * HDMI CP uses a Data Enable synchronisation timing reference
148 * core. Values are stored as signed-twos-complement in one-pixel-clock units
150 * The start and end are shifted equally by the 10-bit shift value.
185 return -EINVAL; in adv748x_hdmi_set_video_timings()
195 adv748x_hdmi_set_de_timings(state, -40); in adv748x_hdmi_set_video_timings()
199 adv748x_hdmi_set_de_timings(state, -44); in adv748x_hdmi_set_video_timings()
213 /* -----------------------------------------------------------------------------
220 struct adv748x_hdmi *hdmi = adv748x_sd_to_hdmi(sd); in adv748x_hdmi_s_dv_timings() local
221 struct adv748x_state *state = adv748x_hdmi_to_state(hdmi); in adv748x_hdmi_s_dv_timings()
225 return -EINVAL; in adv748x_hdmi_s_dv_timings()
227 if (v4l2_match_dv_timings(&hdmi->timings, timings, 0, false)) in adv748x_hdmi_s_dv_timings()
232 return -ERANGE; in adv748x_hdmi_s_dv_timings()
236 mutex_lock(&state->mutex); in adv748x_hdmi_s_dv_timings()
242 hdmi->timings = *timings; in adv748x_hdmi_s_dv_timings()
245 timings->bt.interlaced ? in adv748x_hdmi_s_dv_timings()
248 mutex_unlock(&state->mutex); in adv748x_hdmi_s_dv_timings()
253 mutex_unlock(&state->mutex); in adv748x_hdmi_s_dv_timings()
260 struct adv748x_hdmi *hdmi = adv748x_sd_to_hdmi(sd); in adv748x_hdmi_g_dv_timings() local
261 struct adv748x_state *state = adv748x_hdmi_to_state(hdmi); in adv748x_hdmi_g_dv_timings()
263 mutex_lock(&state->mutex); in adv748x_hdmi_g_dv_timings()
265 *timings = hdmi->timings; in adv748x_hdmi_g_dv_timings()
267 mutex_unlock(&state->mutex); in adv748x_hdmi_g_dv_timings()
275 struct adv748x_hdmi *hdmi = adv748x_sd_to_hdmi(sd); in adv748x_hdmi_query_dv_timings() local
276 struct adv748x_state *state = adv748x_hdmi_to_state(hdmi); in adv748x_hdmi_query_dv_timings()
277 struct v4l2_bt_timings *bt = &timings->bt; in adv748x_hdmi_query_dv_timings()
282 return -EINVAL; in adv748x_hdmi_query_dv_timings()
292 *timings = hdmi->timings; in adv748x_hdmi_query_dv_timings()
297 return -ENOLINK; in adv748x_hdmi_query_dv_timings()
301 return -ENODATA; in adv748x_hdmi_query_dv_timings()
303 timings->type = V4L2_DV_BT_656_1120; in adv748x_hdmi_query_dv_timings()
305 bt->pixelclock = pixelclock; in adv748x_hdmi_query_dv_timings()
306 bt->interlaced = hdmi_read(state, ADV748X_HDMI_F1H1) & in adv748x_hdmi_query_dv_timings()
309 bt->width = hdmi_read16(state, ADV748X_HDMI_LW1, in adv748x_hdmi_query_dv_timings()
311 bt->height = hdmi_read16(state, ADV748X_HDMI_F0H1, in adv748x_hdmi_query_dv_timings()
313 bt->hfrontporch = hdmi_read16(state, ADV748X_HDMI_HFRONT_PORCH, in adv748x_hdmi_query_dv_timings()
315 bt->hsync = hdmi_read16(state, ADV748X_HDMI_HSYNC_WIDTH, in adv748x_hdmi_query_dv_timings()
317 bt->hbackporch = hdmi_read16(state, ADV748X_HDMI_HBACK_PORCH, in adv748x_hdmi_query_dv_timings()
319 bt->vfrontporch = hdmi_read16(state, ADV748X_HDMI_VFRONT_PORCH, in adv748x_hdmi_query_dv_timings()
321 bt->vsync = hdmi_read16(state, ADV748X_HDMI_VSYNC_WIDTH, in adv748x_hdmi_query_dv_timings()
323 bt->vbackporch = hdmi_read16(state, ADV748X_HDMI_VBACK_PORCH, in adv748x_hdmi_query_dv_timings()
327 bt->polarities = (polarity & BIT(4) ? V4L2_DV_VSYNC_POS_POL : 0) | in adv748x_hdmi_query_dv_timings()
330 if (bt->interlaced == V4L2_DV_INTERLACED) { in adv748x_hdmi_query_dv_timings()
331 bt->height += hdmi_read16(state, 0x0b, 0x1fff); in adv748x_hdmi_query_dv_timings()
332 bt->il_vfrontporch = hdmi_read16(state, 0x2c, 0x3fff) / 2; in adv748x_hdmi_query_dv_timings()
333 bt->il_vsync = hdmi_read16(state, 0x30, 0x3fff) / 2; in adv748x_hdmi_query_dv_timings()
334 bt->il_vbackporch = hdmi_read16(state, 0x34, 0x3fff) / 2; in adv748x_hdmi_query_dv_timings()
344 hdmi->timings = *timings; in adv748x_hdmi_query_dv_timings()
351 struct adv748x_hdmi *hdmi = adv748x_sd_to_hdmi(sd); in adv748x_hdmi_g_input_status() local
352 struct adv748x_state *state = adv748x_hdmi_to_state(hdmi); in adv748x_hdmi_g_input_status()
354 mutex_lock(&state->mutex); in adv748x_hdmi_g_input_status()
358 mutex_unlock(&state->mutex); in adv748x_hdmi_g_input_status()
365 struct adv748x_hdmi *hdmi = adv748x_sd_to_hdmi(sd); in adv748x_hdmi_s_stream() local
366 struct adv748x_state *state = adv748x_hdmi_to_state(hdmi); in adv748x_hdmi_s_stream()
369 mutex_lock(&state->mutex); in adv748x_hdmi_s_stream()
371 ret = adv748x_tx_power(hdmi->tx, enable); in adv748x_hdmi_s_stream()
376 adv_dbg(state, "Detected HDMI signal\n"); in adv748x_hdmi_s_stream()
378 adv_dbg(state, "Couldn't detect HDMI video signal\n"); in adv748x_hdmi_s_stream()
381 mutex_unlock(&state->mutex); in adv748x_hdmi_s_stream()
388 aspect->numerator = 1; in adv748x_hdmi_g_pixelaspect()
389 aspect->denominator = 1; in adv748x_hdmi_g_pixelaspect()
400 /* -----------------------------------------------------------------------------
404 static int adv748x_hdmi_propagate_pixelrate(struct adv748x_hdmi *hdmi) in adv748x_hdmi_propagate_pixelrate() argument
406 struct v4l2_subdev *tx; in adv748x_hdmi_propagate_pixelrate() local
409 tx = adv748x_get_remote_sd(&hdmi->pads[ADV748X_HDMI_SOURCE]); in adv748x_hdmi_propagate_pixelrate()
410 if (!tx) in adv748x_hdmi_propagate_pixelrate()
411 return -ENOLINK; in adv748x_hdmi_propagate_pixelrate()
413 adv748x_hdmi_query_dv_timings(&hdmi->sd, 0, &timings); in adv748x_hdmi_propagate_pixelrate()
415 return adv748x_csi2_set_pixelrate(tx, timings.bt.pixelclock); in adv748x_hdmi_propagate_pixelrate()
422 if (code->index != 0) in adv748x_hdmi_enum_mbus_code()
423 return -EINVAL; in adv748x_hdmi_enum_mbus_code()
425 code->code = MEDIA_BUS_FMT_RGB888_1X24; in adv748x_hdmi_enum_mbus_code()
434 struct adv748x_hdmi *hdmi = adv748x_sd_to_hdmi(sd); in adv748x_hdmi_get_format() local
437 if (sdformat->pad != ADV748X_HDMI_SOURCE) in adv748x_hdmi_get_format()
438 return -EINVAL; in adv748x_hdmi_get_format()
440 if (sdformat->which == V4L2_SUBDEV_FORMAT_TRY) { in adv748x_hdmi_get_format()
442 sdformat->pad); in adv748x_hdmi_get_format()
443 sdformat->format = *mbusformat; in adv748x_hdmi_get_format()
445 adv748x_hdmi_fill_format(hdmi, &sdformat->format); in adv748x_hdmi_get_format()
446 adv748x_hdmi_propagate_pixelrate(hdmi); in adv748x_hdmi_get_format()
458 if (sdformat->pad != ADV748X_HDMI_SOURCE) in adv748x_hdmi_set_format()
459 return -EINVAL; in adv748x_hdmi_set_format()
461 if (sdformat->which == V4L2_SUBDEV_FORMAT_ACTIVE) in adv748x_hdmi_set_format()
464 mbusformat = v4l2_subdev_state_get_format(sd_state, sdformat->pad); in adv748x_hdmi_set_format()
465 *mbusformat = sdformat->format; in adv748x_hdmi_set_format()
472 struct adv748x_hdmi *hdmi = adv748x_sd_to_hdmi(sd); in adv748x_hdmi_get_edid() local
474 memset(edid->reserved, 0, sizeof(edid->reserved)); in adv748x_hdmi_get_edid()
476 if (!hdmi->edid.present) in adv748x_hdmi_get_edid()
477 return -ENODATA; in adv748x_hdmi_get_edid()
479 if (edid->start_block == 0 && edid->blocks == 0) { in adv748x_hdmi_get_edid()
480 edid->blocks = hdmi->edid.blocks; in adv748x_hdmi_get_edid()
484 if (edid->start_block >= hdmi->edid.blocks) in adv748x_hdmi_get_edid()
485 return -EINVAL; in adv748x_hdmi_get_edid()
487 if (edid->start_block + edid->blocks > hdmi->edid.blocks) in adv748x_hdmi_get_edid()
488 edid->blocks = hdmi->edid.blocks - edid->start_block; in adv748x_hdmi_get_edid()
490 memcpy(edid->edid, hdmi->edid.edid + edid->start_block * 128, in adv748x_hdmi_get_edid()
491 edid->blocks * 128); in adv748x_hdmi_get_edid()
496 static inline int adv748x_hdmi_edid_write_block(struct adv748x_hdmi *hdmi, in adv748x_hdmi_edid_write_block() argument
499 struct adv748x_state *state = adv748x_hdmi_to_state(hdmi); in adv748x_hdmi_edid_write_block()
508 len = (total_len - i) > I2C_SMBUS_BLOCK_MAX ? in adv748x_hdmi_edid_write_block()
510 (total_len - i); in adv748x_hdmi_edid_write_block()
522 struct adv748x_hdmi *hdmi = adv748x_sd_to_hdmi(sd); in adv748x_hdmi_set_edid() local
523 struct adv748x_state *state = adv748x_hdmi_to_state(hdmi); in adv748x_hdmi_set_edid()
526 memset(edid->reserved, 0, sizeof(edid->reserved)); in adv748x_hdmi_set_edid()
528 if (edid->start_block != 0) in adv748x_hdmi_set_edid()
529 return -EINVAL; in adv748x_hdmi_set_edid()
531 if (edid->blocks == 0) { in adv748x_hdmi_set_edid()
532 hdmi->edid.blocks = 0; in adv748x_hdmi_set_edid()
533 hdmi->edid.present = 0; in adv748x_hdmi_set_edid()
536 hdmi->aspect_ratio.numerator = 16; in adv748x_hdmi_set_edid()
537 hdmi->aspect_ratio.denominator = 9; in adv748x_hdmi_set_edid()
541 edid->blocks << ADV748X_REPEATER_EDID_SZ_SHIFT); in adv748x_hdmi_set_edid()
548 if (edid->blocks > 4) { in adv748x_hdmi_set_edid()
549 edid->blocks = 4; in adv748x_hdmi_set_edid()
550 return -E2BIG; in adv748x_hdmi_set_edid()
553 memcpy(hdmi->edid.edid, edid->edid, 128 * edid->blocks); in adv748x_hdmi_set_edid()
554 hdmi->edid.blocks = edid->blocks; in adv748x_hdmi_set_edid()
555 hdmi->edid.present = true; in adv748x_hdmi_set_edid()
557 hdmi->aspect_ratio = v4l2_calc_aspect_ratio(edid->edid[0x15], in adv748x_hdmi_set_edid()
558 edid->edid[0x16]); in adv748x_hdmi_set_edid()
560 err = adv748x_hdmi_edid_write_block(hdmi, 128 * edid->blocks, in adv748x_hdmi_set_edid()
561 hdmi->edid.edid); in adv748x_hdmi_set_edid()
563 v4l2_err(sd, "error %d writing edid pad %d\n", err, edid->pad); in adv748x_hdmi_set_edid()
568 edid->blocks << ADV748X_REPEATER_EDID_SZ_SHIFT); in adv748x_hdmi_set_edid()
617 /* -----------------------------------------------------------------------------
626 /* -----------------------------------------------------------------------------
642 struct adv748x_hdmi *hdmi = adv748x_ctrl_to_hdmi(ctrl); in adv748x_hdmi_s_ctrl() local
643 struct adv748x_state *state = adv748x_hdmi_to_state(hdmi); in adv748x_hdmi_s_ctrl()
654 switch (ctrl->id) { in adv748x_hdmi_s_ctrl()
656 ret = cp_write(state, ADV748X_CP_BRI, ctrl->val); in adv748x_hdmi_s_ctrl()
659 ret = cp_write(state, ADV748X_CP_HUE, ctrl->val); in adv748x_hdmi_s_ctrl()
662 ret = cp_write(state, ADV748X_CP_CON, ctrl->val); in adv748x_hdmi_s_ctrl()
665 ret = cp_write(state, ADV748X_CP_SAT, ctrl->val); in adv748x_hdmi_s_ctrl()
668 pattern = ctrl->val; in adv748x_hdmi_s_ctrl()
670 /* Pattern is 0-indexed. Ctrl Menu is 1-indexed */ in adv748x_hdmi_s_ctrl()
672 pattern--; in adv748x_hdmi_s_ctrl()
680 return -EINVAL; in adv748x_hdmi_s_ctrl()
690 static int adv748x_hdmi_init_controls(struct adv748x_hdmi *hdmi) in adv748x_hdmi_init_controls() argument
692 struct adv748x_state *state = adv748x_hdmi_to_state(hdmi); in adv748x_hdmi_init_controls()
694 v4l2_ctrl_handler_init(&hdmi->ctrl_hdl, 5); in adv748x_hdmi_init_controls()
697 hdmi->ctrl_hdl.lock = &state->mutex; in adv748x_hdmi_init_controls()
699 v4l2_ctrl_new_std(&hdmi->ctrl_hdl, &adv748x_hdmi_ctrl_ops, in adv748x_hdmi_init_controls()
702 v4l2_ctrl_new_std(&hdmi->ctrl_hdl, &adv748x_hdmi_ctrl_ops, in adv748x_hdmi_init_controls()
705 v4l2_ctrl_new_std(&hdmi->ctrl_hdl, &adv748x_hdmi_ctrl_ops, in adv748x_hdmi_init_controls()
708 v4l2_ctrl_new_std(&hdmi->ctrl_hdl, &adv748x_hdmi_ctrl_ops, in adv748x_hdmi_init_controls()
717 v4l2_ctrl_new_std_menu_items(&hdmi->ctrl_hdl, &adv748x_hdmi_ctrl_ops, in adv748x_hdmi_init_controls()
719 ARRAY_SIZE(hdmi_ctrl_patgen_menu) - 1, in adv748x_hdmi_init_controls()
722 hdmi->sd.ctrl_handler = &hdmi->ctrl_hdl; in adv748x_hdmi_init_controls()
723 if (hdmi->ctrl_hdl.error) { in adv748x_hdmi_init_controls()
724 v4l2_ctrl_handler_free(&hdmi->ctrl_hdl); in adv748x_hdmi_init_controls()
725 return hdmi->ctrl_hdl.error; in adv748x_hdmi_init_controls()
728 return v4l2_ctrl_handler_setup(&hdmi->ctrl_hdl); in adv748x_hdmi_init_controls()
731 int adv748x_hdmi_init(struct adv748x_hdmi *hdmi) in adv748x_hdmi_init() argument
733 struct adv748x_state *state = adv748x_hdmi_to_state(hdmi); in adv748x_hdmi_init()
737 adv748x_hdmi_s_dv_timings(&hdmi->sd, 0, &cea1280x720); in adv748x_hdmi_init()
740 hdmi->aspect_ratio.numerator = 16; in adv748x_hdmi_init()
741 hdmi->aspect_ratio.denominator = 9; in adv748x_hdmi_init()
743 adv748x_subdev_init(&hdmi->sd, state, &adv748x_ops_hdmi, in adv748x_hdmi_init()
744 MEDIA_ENT_F_IO_DTV, "hdmi"); in adv748x_hdmi_init()
746 hdmi->pads[ADV748X_HDMI_SINK].flags = MEDIA_PAD_FL_SINK; in adv748x_hdmi_init()
747 hdmi->pads[ADV748X_HDMI_SOURCE].flags = MEDIA_PAD_FL_SOURCE; in adv748x_hdmi_init()
749 ret = media_entity_pads_init(&hdmi->sd.entity, in adv748x_hdmi_init()
750 ADV748X_HDMI_NR_PADS, hdmi->pads); in adv748x_hdmi_init()
754 ret = adv748x_hdmi_init_controls(hdmi); in adv748x_hdmi_init()
761 media_entity_cleanup(&hdmi->sd.entity); in adv748x_hdmi_init()
766 void adv748x_hdmi_cleanup(struct adv748x_hdmi *hdmi) in adv748x_hdmi_cleanup() argument
768 v4l2_device_unregister_subdev(&hdmi->sd); in adv748x_hdmi_cleanup()
769 media_entity_cleanup(&hdmi->sd.entity); in adv748x_hdmi_cleanup()
770 v4l2_ctrl_handler_free(&hdmi->ctrl_hdl); in adv748x_hdmi_cleanup()