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()
434 mbusformat = v4l2_subdev_get_try_format(sd, cfg, sdformat->pad); in adv748x_hdmi_get_format()
435 sdformat->format = *mbusformat; in adv748x_hdmi_get_format()
437 adv748x_hdmi_fill_format(hdmi, &sdformat->format); in adv748x_hdmi_get_format()
450 if (sdformat->pad != ADV748X_HDMI_SOURCE) in adv748x_hdmi_set_format()
451 return -EINVAL; in adv748x_hdmi_set_format()
453 if (sdformat->which == V4L2_SUBDEV_FORMAT_ACTIVE) in adv748x_hdmi_set_format()
456 mbusformat = v4l2_subdev_get_try_format(sd, cfg, sdformat->pad); in adv748x_hdmi_set_format()
457 *mbusformat = sdformat->format; in adv748x_hdmi_set_format()
466 memset(edid->reserved, 0, sizeof(edid->reserved)); in adv748x_hdmi_get_edid()
468 if (!hdmi->edid.present) in adv748x_hdmi_get_edid()
469 return -ENODATA; in adv748x_hdmi_get_edid()
471 if (edid->start_block == 0 && edid->blocks == 0) { in adv748x_hdmi_get_edid()
472 edid->blocks = hdmi->edid.blocks; in adv748x_hdmi_get_edid()
476 if (edid->start_block >= hdmi->edid.blocks) in adv748x_hdmi_get_edid()
477 return -EINVAL; in adv748x_hdmi_get_edid()
479 if (edid->start_block + edid->blocks > hdmi->edid.blocks) in adv748x_hdmi_get_edid()
480 edid->blocks = hdmi->edid.blocks - edid->start_block; in adv748x_hdmi_get_edid()
482 memcpy(edid->edid, hdmi->edid.edid + edid->start_block * 128, in adv748x_hdmi_get_edid()
483 edid->blocks * 128); in adv748x_hdmi_get_edid()
500 len = (total_len - i) > I2C_SMBUS_BLOCK_MAX ? in adv748x_hdmi_edid_write_block()
502 (total_len - i); in adv748x_hdmi_edid_write_block()
518 memset(edid->reserved, 0, sizeof(edid->reserved)); in adv748x_hdmi_set_edid()
520 if (edid->start_block != 0) in adv748x_hdmi_set_edid()
521 return -EINVAL; in adv748x_hdmi_set_edid()
523 if (edid->blocks == 0) { in adv748x_hdmi_set_edid()
524 hdmi->edid.blocks = 0; in adv748x_hdmi_set_edid()
525 hdmi->edid.present = 0; in adv748x_hdmi_set_edid()
528 hdmi->aspect_ratio.numerator = 16; in adv748x_hdmi_set_edid()
529 hdmi->aspect_ratio.denominator = 9; in adv748x_hdmi_set_edid()
533 edid->blocks << ADV748X_REPEATER_EDID_SZ_SHIFT); in adv748x_hdmi_set_edid()
540 if (edid->blocks > 4) { in adv748x_hdmi_set_edid()
541 edid->blocks = 4; in adv748x_hdmi_set_edid()
542 return -E2BIG; in adv748x_hdmi_set_edid()
545 memcpy(hdmi->edid.edid, edid->edid, 128 * edid->blocks); in adv748x_hdmi_set_edid()
546 hdmi->edid.blocks = edid->blocks; in adv748x_hdmi_set_edid()
547 hdmi->edid.present = true; in adv748x_hdmi_set_edid()
549 hdmi->aspect_ratio = v4l2_calc_aspect_ratio(edid->edid[0x15], in adv748x_hdmi_set_edid()
550 edid->edid[0x16]); in adv748x_hdmi_set_edid()
552 err = adv748x_hdmi_edid_write_block(hdmi, 128 * edid->blocks, in adv748x_hdmi_set_edid()
553 hdmi->edid.edid); in adv748x_hdmi_set_edid()
555 v4l2_err(sd, "error %d writing edid pad %d\n", err, edid->pad); in adv748x_hdmi_set_edid()
560 edid->blocks << ADV748X_REPEATER_EDID_SZ_SHIFT); in adv748x_hdmi_set_edid()
606 /* -----------------------------------------------------------------------------
615 /* -----------------------------------------------------------------------------
643 switch (ctrl->id) { in adv748x_hdmi_s_ctrl()
645 ret = cp_write(state, ADV748X_CP_BRI, ctrl->val); in adv748x_hdmi_s_ctrl()
648 ret = cp_write(state, ADV748X_CP_HUE, ctrl->val); in adv748x_hdmi_s_ctrl()
651 ret = cp_write(state, ADV748X_CP_CON, ctrl->val); in adv748x_hdmi_s_ctrl()
654 ret = cp_write(state, ADV748X_CP_SAT, ctrl->val); in adv748x_hdmi_s_ctrl()
657 pattern = ctrl->val; in adv748x_hdmi_s_ctrl()
659 /* Pattern is 0-indexed. Ctrl Menu is 1-indexed */ in adv748x_hdmi_s_ctrl()
661 pattern--; in adv748x_hdmi_s_ctrl()
669 return -EINVAL; in adv748x_hdmi_s_ctrl()
683 v4l2_ctrl_handler_init(&hdmi->ctrl_hdl, 5); in adv748x_hdmi_init_controls()
686 hdmi->ctrl_hdl.lock = &state->mutex; in adv748x_hdmi_init_controls()
688 v4l2_ctrl_new_std(&hdmi->ctrl_hdl, &adv748x_hdmi_ctrl_ops, in adv748x_hdmi_init_controls()
691 v4l2_ctrl_new_std(&hdmi->ctrl_hdl, &adv748x_hdmi_ctrl_ops, in adv748x_hdmi_init_controls()
694 v4l2_ctrl_new_std(&hdmi->ctrl_hdl, &adv748x_hdmi_ctrl_ops, in adv748x_hdmi_init_controls()
697 v4l2_ctrl_new_std(&hdmi->ctrl_hdl, &adv748x_hdmi_ctrl_ops, in adv748x_hdmi_init_controls()
706 v4l2_ctrl_new_std_menu_items(&hdmi->ctrl_hdl, &adv748x_hdmi_ctrl_ops, in adv748x_hdmi_init_controls()
708 ARRAY_SIZE(hdmi_ctrl_patgen_menu) - 1, in adv748x_hdmi_init_controls()
711 hdmi->sd.ctrl_handler = &hdmi->ctrl_hdl; in adv748x_hdmi_init_controls()
712 if (hdmi->ctrl_hdl.error) { in adv748x_hdmi_init_controls()
713 v4l2_ctrl_handler_free(&hdmi->ctrl_hdl); in adv748x_hdmi_init_controls()
714 return hdmi->ctrl_hdl.error; in adv748x_hdmi_init_controls()
717 return v4l2_ctrl_handler_setup(&hdmi->ctrl_hdl); in adv748x_hdmi_init_controls()
727 hdmi->timings = cea1280x720; in adv748x_hdmi_init()
730 hdmi->aspect_ratio.numerator = 16; in adv748x_hdmi_init()
731 hdmi->aspect_ratio.denominator = 9; in adv748x_hdmi_init()
733 adv748x_subdev_init(&hdmi->sd, state, &adv748x_ops_hdmi, in adv748x_hdmi_init()
736 hdmi->pads[ADV748X_HDMI_SINK].flags = MEDIA_PAD_FL_SINK; in adv748x_hdmi_init()
737 hdmi->pads[ADV748X_HDMI_SOURCE].flags = MEDIA_PAD_FL_SOURCE; in adv748x_hdmi_init()
739 ret = media_entity_pads_init(&hdmi->sd.entity, in adv748x_hdmi_init()
740 ADV748X_HDMI_NR_PADS, hdmi->pads); in adv748x_hdmi_init()
751 media_entity_cleanup(&hdmi->sd.entity); in adv748x_hdmi_init()
758 v4l2_device_unregister_subdev(&hdmi->sd); in adv748x_hdmi_cleanup()
759 media_entity_cleanup(&hdmi->sd.entity); in adv748x_hdmi_cleanup()
760 v4l2_ctrl_handler_free(&hdmi->ctrl_hdl); in adv748x_hdmi_cleanup()