Lines Matching +full:vsync +full:- +full:polarity +full:- +full:high

1 // SPDX-License-Identifier: GPL-2.0+
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 /* -----------------------------------------------------------------------------
29 /* V4L2_DV_BT_CEA_720X480I59_94 - 0.5 MHz */
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()
135 * The high 9 bits store TMDS frequency measurement in MHz 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()
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.
154 u8 high, low; in adv748x_hdmi_set_de_timings() local
157 high = ADV748X_CP_DE_POS_HIGH_SET; in adv748x_hdmi_set_de_timings()
158 high |= (shift & 0x300) >> 8; in adv748x_hdmi_set_de_timings()
162 cp_write(state, ADV748X_CP_DE_POS_HIGH, high); in adv748x_hdmi_set_de_timings()
165 high |= (shift & 0x300) >> 6; in adv748x_hdmi_set_de_timings()
167 cp_write(state, ADV748X_CP_DE_POS_HIGH, high); in adv748x_hdmi_set_de_timings()
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 /* -----------------------------------------------------------------------------
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()
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()
277 struct v4l2_bt_timings *bt = &timings->bt; in adv748x_hdmi_query_dv_timings()
279 int polarity; in adv748x_hdmi_query_dv_timings() local
282 return -EINVAL; in adv748x_hdmi_query_dv_timings()
287 return -ENOLINK; in adv748x_hdmi_query_dv_timings()
291 return -ENODATA; in adv748x_hdmi_query_dv_timings()
293 timings->type = V4L2_DV_BT_656_1120; in adv748x_hdmi_query_dv_timings()
295 bt->pixelclock = pixelclock; in adv748x_hdmi_query_dv_timings()
296 bt->interlaced = hdmi_read(state, ADV748X_HDMI_F1H1) & in adv748x_hdmi_query_dv_timings()
299 bt->width = hdmi_read16(state, ADV748X_HDMI_LW1, in adv748x_hdmi_query_dv_timings()
301 bt->height = hdmi_read16(state, ADV748X_HDMI_F0H1, in adv748x_hdmi_query_dv_timings()
303 bt->hfrontporch = hdmi_read16(state, ADV748X_HDMI_HFRONT_PORCH, in adv748x_hdmi_query_dv_timings()
305 bt->hsync = hdmi_read16(state, ADV748X_HDMI_HSYNC_WIDTH, in adv748x_hdmi_query_dv_timings()
307 bt->hbackporch = hdmi_read16(state, ADV748X_HDMI_HBACK_PORCH, in adv748x_hdmi_query_dv_timings()
309 bt->vfrontporch = hdmi_read16(state, ADV748X_HDMI_VFRONT_PORCH, in adv748x_hdmi_query_dv_timings()
311 bt->vsync = hdmi_read16(state, ADV748X_HDMI_VSYNC_WIDTH, in adv748x_hdmi_query_dv_timings()
313 bt->vbackporch = hdmi_read16(state, ADV748X_HDMI_VBACK_PORCH, in adv748x_hdmi_query_dv_timings()
316 polarity = hdmi_read(state, 0x05); in adv748x_hdmi_query_dv_timings()
317 bt->polarities = (polarity & BIT(4) ? V4L2_DV_VSYNC_POS_POL : 0) | in adv748x_hdmi_query_dv_timings()
318 (polarity & BIT(5) ? V4L2_DV_HSYNC_POS_POL : 0); in adv748x_hdmi_query_dv_timings()
320 if (bt->interlaced == V4L2_DV_INTERLACED) { in adv748x_hdmi_query_dv_timings()
321 bt->height += hdmi_read16(state, 0x0b, 0x1fff); in adv748x_hdmi_query_dv_timings()
322 bt->il_vfrontporch = hdmi_read16(state, 0x2c, 0x3fff) / 2; in adv748x_hdmi_query_dv_timings()
323 bt->il_vsync = hdmi_read16(state, 0x30, 0x3fff) / 2; in adv748x_hdmi_query_dv_timings()
324 bt->il_vbackporch = hdmi_read16(state, 0x34, 0x3fff) / 2; in adv748x_hdmi_query_dv_timings()
334 hdmi->timings = *timings; in adv748x_hdmi_query_dv_timings()
344 mutex_lock(&state->mutex); in adv748x_hdmi_g_input_status()
348 mutex_unlock(&state->mutex); in adv748x_hdmi_g_input_status()
359 mutex_lock(&state->mutex); in adv748x_hdmi_s_stream()
361 ret = adv748x_tx_power(hdmi->tx, enable); in adv748x_hdmi_s_stream()
371 mutex_unlock(&state->mutex); in adv748x_hdmi_s_stream()
378 aspect->numerator = 1; in adv748x_hdmi_g_pixelaspect()
379 aspect->denominator = 1; in adv748x_hdmi_g_pixelaspect()
393 /* -----------------------------------------------------------------------------
402 tx = adv748x_get_remote_sd(&hdmi->pads[ADV748X_HDMI_SOURCE]); in adv748x_hdmi_propagate_pixelrate()
404 return -ENOLINK; in adv748x_hdmi_propagate_pixelrate()
406 adv748x_hdmi_query_dv_timings(&hdmi->sd, &timings); in adv748x_hdmi_propagate_pixelrate()
415 if (code->index != 0) in adv748x_hdmi_enum_mbus_code()
416 return -EINVAL; in adv748x_hdmi_enum_mbus_code()
418 code->code = MEDIA_BUS_FMT_RGB888_1X24; in adv748x_hdmi_enum_mbus_code()
430 if (sdformat->pad != ADV748X_HDMI_SOURCE) in adv748x_hdmi_get_format()
431 return -EINVAL; in adv748x_hdmi_get_format()
433 if (sdformat->which == V4L2_SUBDEV_FORMAT_TRY) { in adv748x_hdmi_get_format()
435 sdformat->pad); in adv748x_hdmi_get_format()
436 sdformat->format = *mbusformat; in adv748x_hdmi_get_format()
438 adv748x_hdmi_fill_format(hdmi, &sdformat->format); in adv748x_hdmi_get_format()
451 if (sdformat->pad != ADV748X_HDMI_SOURCE) in adv748x_hdmi_set_format()
452 return -EINVAL; in adv748x_hdmi_set_format()
454 if (sdformat->which == V4L2_SUBDEV_FORMAT_ACTIVE) in adv748x_hdmi_set_format()
457 mbusformat = v4l2_subdev_get_try_format(sd, sd_state, sdformat->pad); in adv748x_hdmi_set_format()
458 *mbusformat = sdformat->format; in adv748x_hdmi_set_format()
467 memset(edid->reserved, 0, sizeof(edid->reserved)); in adv748x_hdmi_get_edid()
469 if (!hdmi->edid.present) in adv748x_hdmi_get_edid()
470 return -ENODATA; in adv748x_hdmi_get_edid()
472 if (edid->start_block == 0 && edid->blocks == 0) { in adv748x_hdmi_get_edid()
473 edid->blocks = hdmi->edid.blocks; in adv748x_hdmi_get_edid()
477 if (edid->start_block >= hdmi->edid.blocks) in adv748x_hdmi_get_edid()
478 return -EINVAL; in adv748x_hdmi_get_edid()
480 if (edid->start_block + edid->blocks > hdmi->edid.blocks) in adv748x_hdmi_get_edid()
481 edid->blocks = hdmi->edid.blocks - edid->start_block; in adv748x_hdmi_get_edid()
483 memcpy(edid->edid, hdmi->edid.edid + edid->start_block * 128, in adv748x_hdmi_get_edid()
484 edid->blocks * 128); in adv748x_hdmi_get_edid()
501 len = (total_len - i) > I2C_SMBUS_BLOCK_MAX ? in adv748x_hdmi_edid_write_block()
503 (total_len - i); in adv748x_hdmi_edid_write_block()
519 memset(edid->reserved, 0, sizeof(edid->reserved)); in adv748x_hdmi_set_edid()
521 if (edid->start_block != 0) in adv748x_hdmi_set_edid()
522 return -EINVAL; in adv748x_hdmi_set_edid()
524 if (edid->blocks == 0) { in adv748x_hdmi_set_edid()
525 hdmi->edid.blocks = 0; in adv748x_hdmi_set_edid()
526 hdmi->edid.present = 0; in adv748x_hdmi_set_edid()
529 hdmi->aspect_ratio.numerator = 16; in adv748x_hdmi_set_edid()
530 hdmi->aspect_ratio.denominator = 9; in adv748x_hdmi_set_edid()
534 edid->blocks << ADV748X_REPEATER_EDID_SZ_SHIFT); in adv748x_hdmi_set_edid()
541 if (edid->blocks > 4) { in adv748x_hdmi_set_edid()
542 edid->blocks = 4; in adv748x_hdmi_set_edid()
543 return -E2BIG; in adv748x_hdmi_set_edid()
546 memcpy(hdmi->edid.edid, edid->edid, 128 * edid->blocks); in adv748x_hdmi_set_edid()
547 hdmi->edid.blocks = edid->blocks; in adv748x_hdmi_set_edid()
548 hdmi->edid.present = true; in adv748x_hdmi_set_edid()
550 hdmi->aspect_ratio = v4l2_calc_aspect_ratio(edid->edid[0x15], in adv748x_hdmi_set_edid()
551 edid->edid[0x16]); in adv748x_hdmi_set_edid()
553 err = adv748x_hdmi_edid_write_block(hdmi, 128 * edid->blocks, in adv748x_hdmi_set_edid()
554 hdmi->edid.edid); in adv748x_hdmi_set_edid()
556 v4l2_err(sd, "error %d writing edid pad %d\n", err, edid->pad); in adv748x_hdmi_set_edid()
561 edid->blocks << ADV748X_REPEATER_EDID_SZ_SHIFT); in adv748x_hdmi_set_edid()
607 /* -----------------------------------------------------------------------------
616 /* -----------------------------------------------------------------------------
644 switch (ctrl->id) { in adv748x_hdmi_s_ctrl()
646 ret = cp_write(state, ADV748X_CP_BRI, ctrl->val); in adv748x_hdmi_s_ctrl()
649 ret = cp_write(state, ADV748X_CP_HUE, ctrl->val); in adv748x_hdmi_s_ctrl()
652 ret = cp_write(state, ADV748X_CP_CON, ctrl->val); in adv748x_hdmi_s_ctrl()
655 ret = cp_write(state, ADV748X_CP_SAT, ctrl->val); in adv748x_hdmi_s_ctrl()
658 pattern = ctrl->val; in adv748x_hdmi_s_ctrl()
660 /* Pattern is 0-indexed. Ctrl Menu is 1-indexed */ in adv748x_hdmi_s_ctrl()
662 pattern--; in adv748x_hdmi_s_ctrl()
670 return -EINVAL; in adv748x_hdmi_s_ctrl()
684 v4l2_ctrl_handler_init(&hdmi->ctrl_hdl, 5); in adv748x_hdmi_init_controls()
687 hdmi->ctrl_hdl.lock = &state->mutex; in adv748x_hdmi_init_controls()
689 v4l2_ctrl_new_std(&hdmi->ctrl_hdl, &adv748x_hdmi_ctrl_ops, in adv748x_hdmi_init_controls()
692 v4l2_ctrl_new_std(&hdmi->ctrl_hdl, &adv748x_hdmi_ctrl_ops, in adv748x_hdmi_init_controls()
695 v4l2_ctrl_new_std(&hdmi->ctrl_hdl, &adv748x_hdmi_ctrl_ops, in adv748x_hdmi_init_controls()
698 v4l2_ctrl_new_std(&hdmi->ctrl_hdl, &adv748x_hdmi_ctrl_ops, in adv748x_hdmi_init_controls()
707 v4l2_ctrl_new_std_menu_items(&hdmi->ctrl_hdl, &adv748x_hdmi_ctrl_ops, in adv748x_hdmi_init_controls()
709 ARRAY_SIZE(hdmi_ctrl_patgen_menu) - 1, in adv748x_hdmi_init_controls()
712 hdmi->sd.ctrl_handler = &hdmi->ctrl_hdl; in adv748x_hdmi_init_controls()
713 if (hdmi->ctrl_hdl.error) { in adv748x_hdmi_init_controls()
714 v4l2_ctrl_handler_free(&hdmi->ctrl_hdl); in adv748x_hdmi_init_controls()
715 return hdmi->ctrl_hdl.error; in adv748x_hdmi_init_controls()
718 return v4l2_ctrl_handler_setup(&hdmi->ctrl_hdl); in adv748x_hdmi_init_controls()
728 hdmi->timings = cea1280x720; in adv748x_hdmi_init()
731 hdmi->aspect_ratio.numerator = 16; in adv748x_hdmi_init()
732 hdmi->aspect_ratio.denominator = 9; in adv748x_hdmi_init()
734 adv748x_subdev_init(&hdmi->sd, state, &adv748x_ops_hdmi, in adv748x_hdmi_init()
737 hdmi->pads[ADV748X_HDMI_SINK].flags = MEDIA_PAD_FL_SINK; in adv748x_hdmi_init()
738 hdmi->pads[ADV748X_HDMI_SOURCE].flags = MEDIA_PAD_FL_SOURCE; in adv748x_hdmi_init()
740 ret = media_entity_pads_init(&hdmi->sd.entity, in adv748x_hdmi_init()
741 ADV748X_HDMI_NR_PADS, hdmi->pads); in adv748x_hdmi_init()
752 media_entity_cleanup(&hdmi->sd.entity); in adv748x_hdmi_init()
759 v4l2_device_unregister_subdev(&hdmi->sd); in adv748x_hdmi_cleanup()
760 media_entity_cleanup(&hdmi->sd.entity); in adv748x_hdmi_cleanup()
761 v4l2_ctrl_handler_free(&hdmi->ctrl_hdl); in adv748x_hdmi_cleanup()