2 * Copyright 2015 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
26 #include "dm_services.h"
28 #include "dc_bios_types.h"
29 #include "core_types.h"
30 #include "core_status.h"
32 #include "dm_helpers.h"
33 #include "dce110_timing_generator.h"
34 #include "dce/dce_hwseq.h"
35 #include "gpio_service_interface.h"
37 #include "dce110_compressor.h"
39 #include "bios/bios_parser_helper.h"
40 #include "timing_generator.h"
41 #include "mem_input.h"
44 #include "transform.h"
45 #include "stream_encoder.h"
46 #include "link_encoder.h"
47 #include "link_enc_cfg.h"
48 #include "link_hwss.h"
51 #include "clock_source.h"
55 #include "reg_helper.h"
56 #include "panel_cntl.h"
57 #include "dpcd_defs.h"
58 /* include DCE11 register header files */
59 #include "dce/dce_11_0_d.h"
60 #include "dce/dce_11_0_sh_mask.h"
61 #include "custom_float.h"
63 #include "atomfirmware.h"
65 #include "dcn10/dcn10_hw_sequencer.h"
67 #include "dce110_hw_sequencer.h"
69 #define GAMMA_HW_POINTS_NUM 256
72 * All values are in milliseconds;
73 * For eDP, after power-up/power/down,
74 * 300/500 msec max. delay from LCDVCC to black video generation
76 #define PANEL_POWER_UP_TIMEOUT 300
77 #define PANEL_POWER_DOWN_TIMEOUT 500
78 #define HPD_CHECK_INTERVAL 10
79 #define OLED_POST_T7_DELAY 100
80 #define OLED_PRE_T11_DELAY 150
85 #define DC_LOGGER_INIT()
91 #define FN(reg_name, field_name) \
92 hws->shifts->field_name, hws->masks->field_name
94 struct dce110_hw_seq_reg_offsets {
98 static const struct dce110_hw_seq_reg_offsets reg_offsets[] = {
100 .crtc = (mmCRTC0_CRTC_GSL_CONTROL - mmCRTC_GSL_CONTROL),
103 .crtc = (mmCRTC1_CRTC_GSL_CONTROL - mmCRTC_GSL_CONTROL),
106 .crtc = (mmCRTC2_CRTC_GSL_CONTROL - mmCRTC_GSL_CONTROL),
109 .crtc = (mmCRTCV_GSL_CONTROL - mmCRTC_GSL_CONTROL),
113 #define HW_REG_BLND(reg, id)\
114 (reg + reg_offsets[id].blnd)
116 #define HW_REG_CRTC(reg, id)\
117 (reg + reg_offsets[id].crtc)
119 #define MAX_WATERMARK 0xFFFF
120 #define SAFE_NBP_MARK 0x7FFF
122 /*******************************************************************************
123 * Private definitions
124 ******************************************************************************/
125 /***************************PIPE_CONTROL***********************************/
126 static void dce110_init_pte(struct dc_context *ctx)
130 uint32_t chunk_int = 0;
131 uint32_t chunk_mul = 0;
133 addr = mmUNP_DVMM_PTE_CONTROL;
134 value = dm_read_reg(ctx, addr);
140 DVMM_USE_SINGLE_PTE);
146 DVMM_PTE_BUFFER_MODE0);
152 DVMM_PTE_BUFFER_MODE1);
154 dm_write_reg(ctx, addr, value);
156 addr = mmDVMM_PTE_REQ;
157 value = dm_read_reg(ctx, addr);
159 chunk_int = get_reg_field_value(
162 HFLIP_PTEREQ_PER_CHUNK_INT);
164 chunk_mul = get_reg_field_value(
167 HFLIP_PTEREQ_PER_CHUNK_MULTIPLIER);
169 if (chunk_int != 0x4 || chunk_mul != 0x4) {
175 MAX_PTEREQ_TO_ISSUE);
181 HFLIP_PTEREQ_PER_CHUNK_INT);
187 HFLIP_PTEREQ_PER_CHUNK_MULTIPLIER);
189 dm_write_reg(ctx, addr, value);
192 /**************************************************************************/
194 static void enable_display_pipe_clock_gating(
195 struct dc_context *ctx,
201 static bool dce110_enable_display_power_gating(
203 uint8_t controller_id,
205 enum pipe_gating_control power_gating)
207 enum bp_result bp_result = BP_RESULT_OK;
208 enum bp_pipe_control_action cntl;
209 struct dc_context *ctx = dc->ctx;
210 unsigned int underlay_idx = dc->res_pool->underlay_pipe_index;
212 if (power_gating == PIPE_GATING_CONTROL_INIT)
213 cntl = ASIC_PIPE_INIT;
214 else if (power_gating == PIPE_GATING_CONTROL_ENABLE)
215 cntl = ASIC_PIPE_ENABLE;
217 cntl = ASIC_PIPE_DISABLE;
219 if (controller_id == underlay_idx)
220 controller_id = CONTROLLER_ID_UNDERLAY0 - 1;
222 if (power_gating != PIPE_GATING_CONTROL_INIT || controller_id == 0) {
224 bp_result = dcb->funcs->enable_disp_power_gating(
225 dcb, controller_id + 1, cntl);
227 /* Revert MASTER_UPDATE_MODE to 0 because bios sets it 2
228 * by default when command table is called
230 * Bios parser accepts controller_id = 6 as indicative of
231 * underlay pipe in dce110. But we do not support more
234 if (controller_id < CONTROLLER_ID_MAX - 1)
236 HW_REG_CRTC(mmCRTC_MASTER_UPDATE_MODE, controller_id),
240 if (power_gating != PIPE_GATING_CONTROL_ENABLE)
241 dce110_init_pte(ctx);
243 if (bp_result == BP_RESULT_OK)
249 static void build_prescale_params(struct ipp_prescale_params *prescale_params,
250 const struct dc_plane_state *plane_state)
252 prescale_params->mode = IPP_PRESCALE_MODE_FIXED_UNSIGNED;
254 switch (plane_state->format) {
255 case SURFACE_PIXEL_FORMAT_GRPH_RGB565:
256 prescale_params->scale = 0x2082;
258 case SURFACE_PIXEL_FORMAT_GRPH_ARGB8888:
259 case SURFACE_PIXEL_FORMAT_GRPH_ABGR8888:
260 prescale_params->scale = 0x2020;
262 case SURFACE_PIXEL_FORMAT_GRPH_ARGB2101010:
263 case SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010:
264 prescale_params->scale = 0x2008;
266 case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616:
267 case SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616:
268 case SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616F:
269 prescale_params->scale = 0x2000;
278 dce110_set_input_transfer_func(struct dc *dc, struct pipe_ctx *pipe_ctx,
279 const struct dc_plane_state *plane_state)
281 struct input_pixel_processor *ipp = pipe_ctx->plane_res.ipp;
282 const struct dc_transfer_func *tf = NULL;
283 struct ipp_prescale_params prescale_params = { 0 };
289 if (plane_state->in_transfer_func)
290 tf = plane_state->in_transfer_func;
292 build_prescale_params(&prescale_params, plane_state);
293 ipp->funcs->ipp_program_prescale(ipp, &prescale_params);
295 if (plane_state->gamma_correction &&
296 !plane_state->gamma_correction->is_identity &&
297 dce_use_lut(plane_state->format))
298 ipp->funcs->ipp_program_input_lut(ipp, plane_state->gamma_correction);
301 /* Default case if no input transfer function specified */
302 ipp->funcs->ipp_set_degamma(ipp, IPP_DEGAMMA_MODE_HW_sRGB);
303 } else if (tf->type == TF_TYPE_PREDEFINED) {
305 case TRANSFER_FUNCTION_SRGB:
306 ipp->funcs->ipp_set_degamma(ipp, IPP_DEGAMMA_MODE_HW_sRGB);
308 case TRANSFER_FUNCTION_BT709:
309 ipp->funcs->ipp_set_degamma(ipp, IPP_DEGAMMA_MODE_HW_xvYCC);
311 case TRANSFER_FUNCTION_LINEAR:
312 ipp->funcs->ipp_set_degamma(ipp, IPP_DEGAMMA_MODE_BYPASS);
314 case TRANSFER_FUNCTION_PQ:
319 } else if (tf->type == TF_TYPE_BYPASS) {
320 ipp->funcs->ipp_set_degamma(ipp, IPP_DEGAMMA_MODE_BYPASS);
322 /*TF_TYPE_DISTRIBUTED_POINTS - Not supported in DCE 11*/
329 static bool convert_to_custom_float(struct pwl_result_data *rgb_resulted,
330 struct curve_points *arr_points,
331 uint32_t hw_points_num)
333 struct custom_float_format fmt;
335 struct pwl_result_data *rgb = rgb_resulted;
339 fmt.exponenta_bits = 6;
340 fmt.mantissa_bits = 12;
343 if (!convert_to_custom_float_format(arr_points[0].x, &fmt,
344 &arr_points[0].custom_float_x)) {
349 if (!convert_to_custom_float_format(arr_points[0].offset, &fmt,
350 &arr_points[0].custom_float_offset)) {
355 if (!convert_to_custom_float_format(arr_points[0].slope, &fmt,
356 &arr_points[0].custom_float_slope)) {
361 fmt.mantissa_bits = 10;
364 if (!convert_to_custom_float_format(arr_points[1].x, &fmt,
365 &arr_points[1].custom_float_x)) {
370 if (!convert_to_custom_float_format(arr_points[1].y, &fmt,
371 &arr_points[1].custom_float_y)) {
376 if (!convert_to_custom_float_format(arr_points[1].slope, &fmt,
377 &arr_points[1].custom_float_slope)) {
382 fmt.mantissa_bits = 12;
385 while (i != hw_points_num) {
386 if (!convert_to_custom_float_format(rgb->red, &fmt,
392 if (!convert_to_custom_float_format(rgb->green, &fmt,
398 if (!convert_to_custom_float_format(rgb->blue, &fmt,
404 if (!convert_to_custom_float_format(rgb->delta_red, &fmt,
405 &rgb->delta_red_reg)) {
410 if (!convert_to_custom_float_format(rgb->delta_green, &fmt,
411 &rgb->delta_green_reg)) {
416 if (!convert_to_custom_float_format(rgb->delta_blue, &fmt,
417 &rgb->delta_blue_reg)) {
429 #define MAX_LOW_POINT 25
430 #define NUMBER_REGIONS 16
431 #define NUMBER_SW_SEGMENTS 16
434 dce110_translate_regamma_to_hw_format(const struct dc_transfer_func *output_tf,
435 struct pwl_params *regamma_params)
437 struct curve_points *arr_points;
438 struct pwl_result_data *rgb_resulted;
439 struct pwl_result_data *rgb;
440 struct pwl_result_data *rgb_plus_1;
441 struct fixed31_32 y_r;
442 struct fixed31_32 y_g;
443 struct fixed31_32 y_b;
444 struct fixed31_32 y1_min;
445 struct fixed31_32 y3_max;
447 int32_t region_start, region_end;
448 uint32_t i, j, k, seg_distr[NUMBER_REGIONS], increment, start_index, hw_points;
450 if (output_tf == NULL || regamma_params == NULL || output_tf->type == TF_TYPE_BYPASS)
453 arr_points = regamma_params->arr_points;
454 rgb_resulted = regamma_params->rgb_resulted;
457 memset(regamma_params, 0, sizeof(struct pwl_params));
459 if (output_tf->tf == TRANSFER_FUNCTION_PQ) {
461 * segments are from 2^-11 to 2^5
464 region_end = region_start + NUMBER_REGIONS;
466 for (i = 0; i < NUMBER_REGIONS; i++)
471 * segment is from 2^-10 to 2^1
472 * We include an extra segment for range [2^0, 2^1). This is to
473 * ensure that colors with normalized values of 1 don't miss the
497 for (k = 0; k < 16; k++) {
498 if (seg_distr[k] != -1)
499 hw_points += (1 << seg_distr[k]);
503 for (k = 0; k < (region_end - region_start); k++) {
504 increment = NUMBER_SW_SEGMENTS / (1 << seg_distr[k]);
505 start_index = (region_start + k + MAX_LOW_POINT) *
507 for (i = start_index; i < start_index + NUMBER_SW_SEGMENTS;
509 if (j == hw_points - 1)
511 rgb_resulted[j].red = output_tf->tf_pts.red[i];
512 rgb_resulted[j].green = output_tf->tf_pts.green[i];
513 rgb_resulted[j].blue = output_tf->tf_pts.blue[i];
519 start_index = (region_end + MAX_LOW_POINT) * NUMBER_SW_SEGMENTS;
520 rgb_resulted[hw_points - 1].red = output_tf->tf_pts.red[start_index];
521 rgb_resulted[hw_points - 1].green = output_tf->tf_pts.green[start_index];
522 rgb_resulted[hw_points - 1].blue = output_tf->tf_pts.blue[start_index];
524 arr_points[0].x = dc_fixpt_pow(dc_fixpt_from_int(2),
525 dc_fixpt_from_int(region_start));
526 arr_points[1].x = dc_fixpt_pow(dc_fixpt_from_int(2),
527 dc_fixpt_from_int(region_end));
529 y_r = rgb_resulted[0].red;
530 y_g = rgb_resulted[0].green;
531 y_b = rgb_resulted[0].blue;
533 y1_min = dc_fixpt_min(y_r, dc_fixpt_min(y_g, y_b));
535 arr_points[0].y = y1_min;
536 arr_points[0].slope = dc_fixpt_div(arr_points[0].y,
539 y_r = rgb_resulted[hw_points - 1].red;
540 y_g = rgb_resulted[hw_points - 1].green;
541 y_b = rgb_resulted[hw_points - 1].blue;
543 /* see comment above, m_arrPoints[1].y should be the Y value for the
544 * region end (m_numOfHwPoints), not last HW point(m_numOfHwPoints - 1)
546 y3_max = dc_fixpt_max(y_r, dc_fixpt_max(y_g, y_b));
548 arr_points[1].y = y3_max;
550 arr_points[1].slope = dc_fixpt_zero;
552 if (output_tf->tf == TRANSFER_FUNCTION_PQ) {
553 /* for PQ, we want to have a straight line from last HW X point,
554 * and the slope to be such that we hit 1.0 at 10000 nits.
556 const struct fixed31_32 end_value = dc_fixpt_from_int(125);
558 arr_points[1].slope = dc_fixpt_div(
559 dc_fixpt_sub(dc_fixpt_one, arr_points[1].y),
560 dc_fixpt_sub(end_value, arr_points[1].x));
563 regamma_params->hw_points_num = hw_points;
566 for (i = 1; i < 16; i++) {
567 if (seg_distr[k] != -1) {
568 regamma_params->arr_curve_points[k].segments_num = seg_distr[k];
569 regamma_params->arr_curve_points[i].offset =
570 regamma_params->arr_curve_points[k].offset + (1 << seg_distr[k]);
575 if (seg_distr[k] != -1)
576 regamma_params->arr_curve_points[k].segments_num = seg_distr[k];
579 rgb_plus_1 = rgb_resulted + 1;
583 while (i != hw_points + 1) {
584 if (dc_fixpt_lt(rgb_plus_1->red, rgb->red))
585 rgb_plus_1->red = rgb->red;
586 if (dc_fixpt_lt(rgb_plus_1->green, rgb->green))
587 rgb_plus_1->green = rgb->green;
588 if (dc_fixpt_lt(rgb_plus_1->blue, rgb->blue))
589 rgb_plus_1->blue = rgb->blue;
591 rgb->delta_red = dc_fixpt_sub(rgb_plus_1->red, rgb->red);
592 rgb->delta_green = dc_fixpt_sub(rgb_plus_1->green, rgb->green);
593 rgb->delta_blue = dc_fixpt_sub(rgb_plus_1->blue, rgb->blue);
600 convert_to_custom_float(rgb_resulted, arr_points, hw_points);
606 dce110_set_output_transfer_func(struct dc *dc, struct pipe_ctx *pipe_ctx,
607 const struct dc_stream_state *stream)
609 struct transform *xfm = pipe_ctx->plane_res.xfm;
611 xfm->funcs->opp_power_on_regamma_lut(xfm, true);
612 xfm->regamma_params.hw_points_num = GAMMA_HW_POINTS_NUM;
614 if (stream->out_transfer_func &&
615 stream->out_transfer_func->type == TF_TYPE_PREDEFINED &&
616 stream->out_transfer_func->tf == TRANSFER_FUNCTION_SRGB) {
617 xfm->funcs->opp_set_regamma_mode(xfm, OPP_REGAMMA_SRGB);
618 } else if (dce110_translate_regamma_to_hw_format(stream->out_transfer_func,
619 &xfm->regamma_params)) {
620 xfm->funcs->opp_program_regamma_pwl(xfm, &xfm->regamma_params);
621 xfm->funcs->opp_set_regamma_mode(xfm, OPP_REGAMMA_USER);
623 xfm->funcs->opp_set_regamma_mode(xfm, OPP_REGAMMA_BYPASS);
626 xfm->funcs->opp_power_on_regamma_lut(xfm, false);
631 void dce110_update_info_frame(struct pipe_ctx *pipe_ctx)
636 ASSERT(pipe_ctx->stream);
638 if (pipe_ctx->stream_res.stream_enc == NULL)
639 return; /* this is not root pipe */
641 is_hdmi_tmds = dc_is_hdmi_tmds_signal(pipe_ctx->stream->signal);
642 is_dp = dc_is_dp_signal(pipe_ctx->stream->signal);
644 if (!is_hdmi_tmds && !is_dp)
648 pipe_ctx->stream_res.stream_enc->funcs->update_hdmi_info_packets(
649 pipe_ctx->stream_res.stream_enc,
650 &pipe_ctx->stream_res.encoder_info_frame);
652 if (pipe_ctx->stream_res.stream_enc->funcs->update_dp_info_packets_sdp_line_num)
653 pipe_ctx->stream_res.stream_enc->funcs->update_dp_info_packets_sdp_line_num(
654 pipe_ctx->stream_res.stream_enc,
655 &pipe_ctx->stream_res.encoder_info_frame);
657 pipe_ctx->stream_res.stream_enc->funcs->update_dp_info_packets(
658 pipe_ctx->stream_res.stream_enc,
659 &pipe_ctx->stream_res.encoder_info_frame);
663 void dce110_enable_stream(struct pipe_ctx *pipe_ctx)
665 enum dc_lane_count lane_count =
666 pipe_ctx->stream->link->cur_link_settings.lane_count;
667 struct dc_crtc_timing *timing = &pipe_ctx->stream->timing;
668 struct dc_link *link = pipe_ctx->stream->link;
669 const struct dc *dc = link->dc;
670 const struct link_hwss *link_hwss = get_link_hwss(link, &pipe_ctx->link_res);
671 uint32_t active_total_with_borders;
672 uint32_t early_control = 0;
673 struct timing_generator *tg = pipe_ctx->stream_res.tg;
675 link_hwss->setup_stream_encoder(pipe_ctx);
677 dc->hwss.update_info_frame(pipe_ctx);
679 /* enable early control to avoid corruption on DP monitor*/
680 active_total_with_borders =
681 timing->h_addressable
682 + timing->h_border_left
683 + timing->h_border_right;
686 early_control = active_total_with_borders % lane_count;
688 if (early_control == 0)
689 early_control = lane_count;
691 tg->funcs->set_early_control(tg, early_control);
694 static enum bp_result link_transmitter_control(
695 struct dc_bios *bios,
696 struct bp_transmitter_control *cntl)
698 enum bp_result result;
700 result = bios->funcs->transmitter_control(bios, cntl);
709 void dce110_edp_wait_for_hpd_ready(
710 struct dc_link *link,
713 struct dc_context *ctx = link->ctx;
714 struct graphics_object_id connector = link->link_enc->connector;
716 bool edp_hpd_high = false;
717 uint32_t time_elapsed = 0;
718 uint32_t timeout = power_up ?
719 PANEL_POWER_UP_TIMEOUT : PANEL_POWER_DOWN_TIMEOUT;
721 if (dal_graphics_object_id_get_connector_id(connector)
722 != CONNECTOR_ID_EDP) {
729 * From KV, we will not HPD low after turning off VCC -
730 * instead, we will check the SW timer in power_up().
735 * When we power on/off the eDP panel,
736 * we need to wait until SENSE bit is high/low.
740 /* TODO what to do with this? */
741 hpd = ctx->dc->link_srv->get_hpd_gpio(ctx->dc_bios, connector, ctx->gpio_service);
749 if (link->panel_config.pps.extra_t3_ms > 0) {
750 int extra_t3_in_ms = link->panel_config.pps.extra_t3_ms;
752 msleep(extra_t3_in_ms);
756 dal_gpio_open(hpd, GPIO_MODE_INTERRUPT);
758 /* wait until timeout or panel detected */
761 uint32_t detected = 0;
763 dal_gpio_get_value(hpd, &detected);
765 if (!(detected ^ power_up)) {
770 msleep(HPD_CHECK_INTERVAL);
772 time_elapsed += HPD_CHECK_INTERVAL;
773 } while (time_elapsed < timeout);
777 dal_gpio_destroy_irq(&hpd);
779 /* ensure that the panel is detected */
781 DC_LOG_DC("%s: wait timed out!\n", __func__);
784 void dce110_edp_power_control(
785 struct dc_link *link,
788 struct dc_context *ctx = link->ctx;
789 struct bp_transmitter_control cntl = { 0 };
790 enum bp_result bp_result;
791 uint8_t panel_instance;
794 if (dal_graphics_object_id_get_connector_id(link->link_enc->connector)
795 != CONNECTOR_ID_EDP) {
800 if (!link->panel_cntl)
803 link->panel_cntl->funcs->is_panel_powered_on(link->panel_cntl)) {
805 unsigned long long current_ts = dm_get_timestamp(ctx);
806 unsigned long long time_since_edp_poweroff_ms =
807 div64_u64(dm_get_elapse_time_in_ns(
810 ctx->dc->link_srv->dp_trace_get_edp_poweroff_timestamp(link)), 1000000);
811 unsigned long long time_since_edp_poweron_ms =
812 div64_u64(dm_get_elapse_time_in_ns(
815 ctx->dc->link_srv->dp_trace_get_edp_poweron_timestamp(link)), 1000000);
817 "%s: transition: power_up=%d current_ts=%llu edp_poweroff=%llu edp_poweron=%llu time_since_edp_poweroff_ms=%llu time_since_edp_poweron_ms=%llu",
821 ctx->dc->link_srv->dp_trace_get_edp_poweroff_timestamp(link),
822 ctx->dc->link_srv->dp_trace_get_edp_poweron_timestamp(link),
823 time_since_edp_poweroff_ms,
824 time_since_edp_poweron_ms);
826 /* Send VBIOS command to prompt eDP panel power */
828 /* edp requires a min of 500ms from LCDVDD off to on */
829 unsigned long long remaining_min_edp_poweroff_time_ms = 500;
831 /* add time defined by a patch, if any (usually patch extra_t12_ms is 0) */
832 if (link->local_sink != NULL)
833 remaining_min_edp_poweroff_time_ms +=
834 link->panel_config.pps.extra_t12_ms;
836 /* Adjust remaining_min_edp_poweroff_time_ms if this is not the first time. */
837 if (ctx->dc->link_srv->dp_trace_get_edp_poweroff_timestamp(link) != 0) {
838 if (time_since_edp_poweroff_ms < remaining_min_edp_poweroff_time_ms)
839 remaining_min_edp_poweroff_time_ms =
840 remaining_min_edp_poweroff_time_ms - time_since_edp_poweroff_ms;
842 remaining_min_edp_poweroff_time_ms = 0;
845 if (remaining_min_edp_poweroff_time_ms) {
847 "%s: remaining_min_edp_poweroff_time_ms=%llu: begin wait.\n",
848 __func__, remaining_min_edp_poweroff_time_ms);
849 msleep(remaining_min_edp_poweroff_time_ms);
851 "%s: remaining_min_edp_poweroff_time_ms=%llu: end wait.\n",
852 __func__, remaining_min_edp_poweroff_time_ms);
853 dm_output_to_console("%s: wait %lld ms to power on eDP.\n",
854 __func__, remaining_min_edp_poweroff_time_ms);
857 "%s: remaining_min_edp_poweroff_time_ms=%llu: no wait required.\n",
858 __func__, remaining_min_edp_poweroff_time_ms);
863 "%s: BEGIN: Panel Power action: %s\n",
864 __func__, (power_up ? "On":"Off"));
866 cntl.action = power_up ?
867 TRANSMITTER_CONTROL_POWER_ON :
868 TRANSMITTER_CONTROL_POWER_OFF;
869 cntl.transmitter = link->link_enc->transmitter;
870 cntl.connector_obj_id = link->link_enc->connector;
871 cntl.coherent = false;
872 cntl.lanes_number = LANE_COUNT_FOUR;
873 cntl.hpd_sel = link->link_enc->hpd_source;
874 panel_instance = link->panel_cntl->inst;
876 if (ctx->dc->ctx->dmub_srv &&
877 ctx->dc->debug.dmub_command_table) {
879 if (cntl.action == TRANSMITTER_CONTROL_POWER_ON) {
880 bp_result = ctx->dc_bios->funcs->enable_lvtma_control(ctx->dc_bios,
881 LVTMA_CONTROL_POWER_ON,
882 panel_instance, link->link_powered_externally);
884 bp_result = ctx->dc_bios->funcs->enable_lvtma_control(ctx->dc_bios,
885 LVTMA_CONTROL_POWER_OFF,
886 panel_instance, link->link_powered_externally);
890 bp_result = link_transmitter_control(ctx->dc_bios, &cntl);
893 "%s: END: Panel Power action: %s bp_result=%u\n",
894 __func__, (power_up ? "On":"Off"),
897 ctx->dc->link_srv->dp_trace_set_edp_power_timestamp(link, power_up);
900 "%s: updated values: edp_poweroff=%llu edp_poweron=%llu\n",
902 ctx->dc->link_srv->dp_trace_get_edp_poweroff_timestamp(link),
903 ctx->dc->link_srv->dp_trace_get_edp_poweron_timestamp(link));
905 if (bp_result != BP_RESULT_OK)
907 "%s: Panel Power bp_result: %d\n",
908 __func__, bp_result);
911 "%s: Skipping Panel Power action: %s\n",
912 __func__, (power_up ? "On":"Off"));
916 void dce110_edp_wait_for_T12(
917 struct dc_link *link)
919 struct dc_context *ctx = link->ctx;
921 if (dal_graphics_object_id_get_connector_id(link->link_enc->connector)
922 != CONNECTOR_ID_EDP) {
927 if (!link->panel_cntl)
930 if (!link->panel_cntl->funcs->is_panel_powered_on(link->panel_cntl) &&
931 ctx->dc->link_srv->dp_trace_get_edp_poweroff_timestamp(link) != 0) {
932 unsigned int t12_duration = 500; // Default T12 as per spec
933 unsigned long long current_ts = dm_get_timestamp(ctx);
934 unsigned long long time_since_edp_poweroff_ms =
935 div64_u64(dm_get_elapse_time_in_ns(
938 ctx->dc->link_srv->dp_trace_get_edp_poweroff_timestamp(link)), 1000000);
940 t12_duration += link->panel_config.pps.extra_t12_ms; // Add extra T12
942 if (time_since_edp_poweroff_ms < t12_duration)
943 msleep(t12_duration - time_since_edp_poweroff_ms);
946 /*todo: cloned in stream enc, fix*/
949 * eDP only. Control the backlight of the eDP panel
951 void dce110_edp_backlight_control(
952 struct dc_link *link,
955 struct dc_context *ctx = link->ctx;
956 struct bp_transmitter_control cntl = { 0 };
957 uint8_t panel_instance;
958 unsigned int pre_T11_delay = OLED_PRE_T11_DELAY;
959 unsigned int post_T7_delay = OLED_POST_T7_DELAY;
961 if (dal_graphics_object_id_get_connector_id(link->link_enc->connector)
962 != CONNECTOR_ID_EDP) {
967 if (link->panel_cntl && !(link->dpcd_sink_ext_caps.bits.oled ||
968 link->dpcd_sink_ext_caps.bits.hdr_aux_backlight_control == 1 ||
969 link->dpcd_sink_ext_caps.bits.sdr_aux_backlight_control == 1)) {
970 bool is_backlight_on = link->panel_cntl->funcs->is_panel_backlight_on(link->panel_cntl);
972 if ((enable && is_backlight_on) || (!enable && !is_backlight_on)) {
974 "%s: panel already powered up/off. Do nothing.\n",
980 /* Send VBIOS command to control eDP panel backlight */
983 "%s: backlight action: %s\n",
984 __func__, (enable ? "On":"Off"));
986 cntl.action = enable ?
987 TRANSMITTER_CONTROL_BACKLIGHT_ON :
988 TRANSMITTER_CONTROL_BACKLIGHT_OFF;
990 /*cntl.engine_id = ctx->engine;*/
991 cntl.transmitter = link->link_enc->transmitter;
992 cntl.connector_obj_id = link->link_enc->connector;
994 cntl.lanes_number = LANE_COUNT_FOUR;
995 cntl.hpd_sel = link->link_enc->hpd_source;
996 cntl.signal = SIGNAL_TYPE_EDP;
998 /* For eDP, the following delays might need to be considered
999 * after link training completed:
1000 * idle period - min. accounts for required BS-Idle pattern,
1001 * max. allows for source frame synchronization);
1002 * 50 msec max. delay from valid video data from source
1003 * to video on dislpay or backlight enable.
1005 * Disable the delay for now.
1006 * Enable it in the future if necessary.
1008 /* dc_service_sleep_in_milliseconds(50); */
1010 panel_instance = link->panel_cntl->inst;
1012 if (cntl.action == TRANSMITTER_CONTROL_BACKLIGHT_ON) {
1013 if (!link->dc->config.edp_no_power_sequencing)
1015 * Sometimes, DP receiver chip power-controlled externally by an
1016 * Embedded Controller could be treated and used as eDP,
1017 * if it drives mobile display. In this case,
1018 * we shouldn't be doing power-sequencing, hence we can skip
1019 * waiting for T7-ready.
1021 ctx->dc->link_srv->edp_receiver_ready_T7(link);
1023 DC_LOG_DC("edp_receiver_ready_T7 skipped\n");
1026 /* Setting link_powered_externally will bypass delays in the backlight
1027 * as they are not required if the link is being powered by a different
1030 if (ctx->dc->ctx->dmub_srv &&
1031 ctx->dc->debug.dmub_command_table) {
1032 if (cntl.action == TRANSMITTER_CONTROL_BACKLIGHT_ON)
1033 ctx->dc_bios->funcs->enable_lvtma_control(ctx->dc_bios,
1034 LVTMA_CONTROL_LCD_BLON,
1035 panel_instance, link->link_powered_externally);
1037 ctx->dc_bios->funcs->enable_lvtma_control(ctx->dc_bios,
1038 LVTMA_CONTROL_LCD_BLOFF,
1039 panel_instance, link->link_powered_externally);
1042 link_transmitter_control(ctx->dc_bios, &cntl);
1044 if (enable && link->dpcd_sink_ext_caps.bits.oled) {
1045 post_T7_delay += link->panel_config.pps.extra_post_t7_ms;
1046 msleep(post_T7_delay);
1049 if (link->dpcd_sink_ext_caps.bits.oled ||
1050 link->dpcd_sink_ext_caps.bits.hdr_aux_backlight_control == 1 ||
1051 link->dpcd_sink_ext_caps.bits.sdr_aux_backlight_control == 1)
1052 ctx->dc->link_srv->edp_backlight_enable_aux(link, enable);
1055 if (cntl.action == TRANSMITTER_CONTROL_BACKLIGHT_OFF) {
1056 if (!link->dc->config.edp_no_power_sequencing)
1058 * Sometimes, DP receiver chip power-controlled externally by an
1059 * Embedded Controller could be treated and used as eDP,
1060 * if it drives mobile display. In this case,
1061 * we shouldn't be doing power-sequencing, hence we can skip
1062 * waiting for T9-ready.
1064 ctx->dc->link_srv->edp_add_delay_for_T9(link);
1066 DC_LOG_DC("edp_receiver_ready_T9 skipped\n");
1069 if (!enable && link->dpcd_sink_ext_caps.bits.oled) {
1070 pre_T11_delay += link->panel_config.pps.extra_pre_t11_ms;
1071 msleep(pre_T11_delay);
1075 void dce110_enable_audio_stream(struct pipe_ctx *pipe_ctx)
1077 /* notify audio driver for audio modes of monitor */
1079 struct clk_mgr *clk_mgr;
1080 unsigned int i, num_audio = 1;
1081 const struct link_hwss *link_hwss;
1083 if (!pipe_ctx->stream)
1086 dc = pipe_ctx->stream->ctx->dc;
1087 clk_mgr = dc->clk_mgr;
1088 link_hwss = get_link_hwss(pipe_ctx->stream->link, &pipe_ctx->link_res);
1090 if (pipe_ctx->stream_res.audio && pipe_ctx->stream_res.audio->enabled == true)
1093 if (pipe_ctx->stream_res.audio) {
1094 for (i = 0; i < MAX_PIPES; i++) {
1095 /*current_state not updated yet*/
1096 if (dc->current_state->res_ctx.pipe_ctx[i].stream_res.audio != NULL)
1100 pipe_ctx->stream_res.audio->funcs->az_enable(pipe_ctx->stream_res.audio);
1102 if (num_audio >= 1 && clk_mgr->funcs->enable_pme_wa)
1103 /*this is the first audio. apply the PME w/a in order to wake AZ from D3*/
1104 clk_mgr->funcs->enable_pme_wa(clk_mgr);
1106 link_hwss->enable_audio_packet(pipe_ctx);
1108 if (pipe_ctx->stream_res.audio)
1109 pipe_ctx->stream_res.audio->enabled = true;
1113 void dce110_disable_audio_stream(struct pipe_ctx *pipe_ctx)
1116 struct clk_mgr *clk_mgr;
1117 const struct link_hwss *link_hwss;
1119 if (!pipe_ctx || !pipe_ctx->stream)
1122 dc = pipe_ctx->stream->ctx->dc;
1123 clk_mgr = dc->clk_mgr;
1124 link_hwss = get_link_hwss(pipe_ctx->stream->link, &pipe_ctx->link_res);
1126 if (pipe_ctx->stream_res.audio && pipe_ctx->stream_res.audio->enabled == false)
1129 link_hwss->disable_audio_packet(pipe_ctx);
1131 if (pipe_ctx->stream_res.audio) {
1132 pipe_ctx->stream_res.audio->enabled = false;
1134 if (clk_mgr->funcs->enable_pme_wa)
1135 /*this is the first audio. apply the PME w/a in order to wake AZ from D3*/
1136 clk_mgr->funcs->enable_pme_wa(clk_mgr);
1138 /* TODO: notify audio driver for if audio modes list changed
1139 * add audio mode list change flag */
1140 /* dal_audio_disable_azalia_audio_jack_presence(stream->audio,
1141 * stream->stream_engine_id);
1146 void dce110_disable_stream(struct pipe_ctx *pipe_ctx)
1148 struct dc_stream_state *stream = pipe_ctx->stream;
1149 struct dc_link *link = stream->link;
1150 struct dc *dc = pipe_ctx->stream->ctx->dc;
1151 const struct link_hwss *link_hwss = get_link_hwss(link, &pipe_ctx->link_res);
1152 struct dccg *dccg = dc->res_pool->dccg;
1153 struct timing_generator *tg = pipe_ctx->stream_res.tg;
1154 struct dtbclk_dto_params dto_params = {0};
1156 struct link_encoder *link_enc = link_enc_cfg_get_link_enc(pipe_ctx->stream->link);
1157 struct stream_encoder *stream_enc = pipe_ctx->stream_res.stream_enc;
1159 if (dc_is_hdmi_tmds_signal(pipe_ctx->stream->signal)) {
1160 pipe_ctx->stream_res.stream_enc->funcs->stop_hdmi_info_packets(
1161 pipe_ctx->stream_res.stream_enc);
1162 pipe_ctx->stream_res.stream_enc->funcs->hdmi_reset_stream_attribute(
1163 pipe_ctx->stream_res.stream_enc);
1166 if (dc->link_srv->dp_is_128b_132b_signal(pipe_ctx)) {
1167 pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->stop_dp_info_packets(
1168 pipe_ctx->stream_res.hpo_dp_stream_enc);
1169 } else if (dc_is_dp_signal(pipe_ctx->stream->signal))
1170 pipe_ctx->stream_res.stream_enc->funcs->stop_dp_info_packets(
1171 pipe_ctx->stream_res.stream_enc);
1173 dc->hwss.disable_audio_stream(pipe_ctx);
1175 link_hwss->reset_stream_encoder(pipe_ctx);
1177 if (dc->link_srv->dp_is_128b_132b_signal(pipe_ctx)) {
1178 dto_params.otg_inst = tg->inst;
1179 dto_params.timing = &pipe_ctx->stream->timing;
1180 dp_hpo_inst = pipe_ctx->stream_res.hpo_dp_stream_enc->inst;
1181 dccg->funcs->set_dtbclk_dto(dccg, &dto_params);
1182 dccg->funcs->disable_symclk32_se(dccg, dp_hpo_inst);
1183 dccg->funcs->set_dpstreamclk(dccg, REFCLK, tg->inst, dp_hpo_inst);
1184 } else if (pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST && dccg->funcs->disable_symclk_se)
1185 dccg->funcs->disable_symclk_se(dccg, stream_enc->stream_enc_inst,
1186 link_enc->transmitter - TRANSMITTER_UNIPHY_A);
1188 if (dc->link_srv->dp_is_128b_132b_signal(pipe_ctx)) {
1189 /* TODO: This looks like a bug to me as we are disabling HPO IO when
1190 * we are just disabling a single HPO stream. Shouldn't we disable HPO
1191 * HW control only when HPOs for all streams are disabled?
1193 if (pipe_ctx->stream->ctx->dc->hwseq->funcs.setup_hpo_hw_control)
1194 pipe_ctx->stream->ctx->dc->hwseq->funcs.setup_hpo_hw_control(
1195 pipe_ctx->stream->ctx->dc->hwseq, false);
1199 void dce110_unblank_stream(struct pipe_ctx *pipe_ctx,
1200 struct dc_link_settings *link_settings)
1202 struct encoder_unblank_param params = { { 0 } };
1203 struct dc_stream_state *stream = pipe_ctx->stream;
1204 struct dc_link *link = stream->link;
1205 struct dce_hwseq *hws = link->dc->hwseq;
1207 /* only 3 items below are used by unblank */
1208 params.timing = pipe_ctx->stream->timing;
1209 params.link_settings.link_rate = link_settings->link_rate;
1211 if (dc_is_dp_signal(pipe_ctx->stream->signal))
1212 pipe_ctx->stream_res.stream_enc->funcs->dp_unblank(link, pipe_ctx->stream_res.stream_enc, ¶ms);
1214 if (link->local_sink && link->local_sink->sink_signal == SIGNAL_TYPE_EDP) {
1215 hws->funcs.edp_backlight_control(link, true);
1219 void dce110_blank_stream(struct pipe_ctx *pipe_ctx)
1221 struct dc_stream_state *stream = pipe_ctx->stream;
1222 struct dc_link *link = stream->link;
1223 struct dce_hwseq *hws = link->dc->hwseq;
1225 if (link->local_sink && link->local_sink->sink_signal == SIGNAL_TYPE_EDP) {
1226 if (!stream->skip_edp_power_down)
1227 hws->funcs.edp_backlight_control(link, false);
1228 link->dc->hwss.set_abm_immediate_disable(pipe_ctx);
1231 if (link->dc->link_srv->dp_is_128b_132b_signal(pipe_ctx)) {
1232 /* TODO - DP2.0 HW: Set ODM mode in dp hpo encoder here */
1233 pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->dp_blank(
1234 pipe_ctx->stream_res.hpo_dp_stream_enc);
1235 } else if (dc_is_dp_signal(pipe_ctx->stream->signal)) {
1236 pipe_ctx->stream_res.stream_enc->funcs->dp_blank(link, pipe_ctx->stream_res.stream_enc);
1238 if (!dc_is_embedded_signal(pipe_ctx->stream->signal)) {
1240 * After output is idle pattern some sinks need time to recognize the stream
1241 * has changed or they enter protection state and hang.
1244 } else if (pipe_ctx->stream->signal == SIGNAL_TYPE_EDP) {
1245 if (!link->dc->config.edp_no_power_sequencing) {
1247 * Sometimes, DP receiver chip power-controlled externally by an
1248 * Embedded Controller could be treated and used as eDP,
1249 * if it drives mobile display. In this case,
1250 * we shouldn't be doing power-sequencing, hence we can skip
1251 * waiting for T9-ready.
1253 link->dc->link_srv->edp_receiver_ready_T9(link);
1261 void dce110_set_avmute(struct pipe_ctx *pipe_ctx, bool enable)
1263 if (pipe_ctx != NULL && pipe_ctx->stream_res.stream_enc != NULL)
1264 pipe_ctx->stream_res.stream_enc->funcs->set_avmute(pipe_ctx->stream_res.stream_enc, enable);
1267 static enum audio_dto_source translate_to_dto_source(enum controller_id crtc_id)
1270 case CONTROLLER_ID_D0:
1271 return DTO_SOURCE_ID0;
1272 case CONTROLLER_ID_D1:
1273 return DTO_SOURCE_ID1;
1274 case CONTROLLER_ID_D2:
1275 return DTO_SOURCE_ID2;
1276 case CONTROLLER_ID_D3:
1277 return DTO_SOURCE_ID3;
1278 case CONTROLLER_ID_D4:
1279 return DTO_SOURCE_ID4;
1280 case CONTROLLER_ID_D5:
1281 return DTO_SOURCE_ID5;
1283 return DTO_SOURCE_UNKNOWN;
1287 static void build_audio_output(
1288 struct dc_state *state,
1289 const struct pipe_ctx *pipe_ctx,
1290 struct audio_output *audio_output)
1292 const struct dc_stream_state *stream = pipe_ctx->stream;
1293 audio_output->engine_id = pipe_ctx->stream_res.stream_enc->id;
1295 audio_output->signal = pipe_ctx->stream->signal;
1297 /* audio_crtc_info */
1299 audio_output->crtc_info.h_total =
1300 stream->timing.h_total;
1303 * Audio packets are sent during actual CRTC blank physical signal, we
1304 * need to specify actual active signal portion
1306 audio_output->crtc_info.h_active =
1307 stream->timing.h_addressable
1308 + stream->timing.h_border_left
1309 + stream->timing.h_border_right;
1311 audio_output->crtc_info.v_active =
1312 stream->timing.v_addressable
1313 + stream->timing.v_border_top
1314 + stream->timing.v_border_bottom;
1316 audio_output->crtc_info.pixel_repetition = 1;
1318 audio_output->crtc_info.interlaced =
1319 stream->timing.flags.INTERLACE;
1321 audio_output->crtc_info.refresh_rate =
1322 (stream->timing.pix_clk_100hz*100)/
1323 (stream->timing.h_total*stream->timing.v_total);
1325 audio_output->crtc_info.color_depth =
1326 stream->timing.display_color_depth;
1328 audio_output->crtc_info.requested_pixel_clock_100Hz =
1329 pipe_ctx->stream_res.pix_clk_params.requested_pix_clk_100hz;
1331 audio_output->crtc_info.calculated_pixel_clock_100Hz =
1332 pipe_ctx->stream_res.pix_clk_params.requested_pix_clk_100hz;
1334 /*for HDMI, audio ACR is with deep color ratio factor*/
1335 if (dc_is_hdmi_tmds_signal(pipe_ctx->stream->signal) &&
1336 audio_output->crtc_info.requested_pixel_clock_100Hz ==
1337 (stream->timing.pix_clk_100hz)) {
1338 if (pipe_ctx->stream_res.pix_clk_params.pixel_encoding == PIXEL_ENCODING_YCBCR420) {
1339 audio_output->crtc_info.requested_pixel_clock_100Hz =
1340 audio_output->crtc_info.requested_pixel_clock_100Hz/2;
1341 audio_output->crtc_info.calculated_pixel_clock_100Hz =
1342 pipe_ctx->stream_res.pix_clk_params.requested_pix_clk_100hz/2;
1347 if (state->clk_mgr &&
1348 (pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT ||
1349 pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST)) {
1350 audio_output->pll_info.dp_dto_source_clock_in_khz =
1351 state->clk_mgr->funcs->get_dp_ref_clk_frequency(
1355 audio_output->pll_info.feed_back_divider =
1356 pipe_ctx->pll_settings.feedback_divider;
1358 audio_output->pll_info.dto_source =
1359 translate_to_dto_source(
1360 pipe_ctx->stream_res.tg->inst + 1);
1362 /* TODO hard code to enable for now. Need get from stream */
1363 audio_output->pll_info.ss_enabled = true;
1365 audio_output->pll_info.ss_percentage =
1366 pipe_ctx->pll_settings.ss_percentage;
1369 static void program_scaler(const struct dc *dc,
1370 const struct pipe_ctx *pipe_ctx)
1372 struct tg_color color = {0};
1375 if (pipe_ctx->plane_res.xfm->funcs->transform_set_pixel_storage_depth == NULL)
1378 if (dc->debug.visual_confirm == VISUAL_CONFIRM_SURFACE)
1379 get_surface_visual_confirm_color(pipe_ctx, &color);
1381 color_space_to_black_color(dc,
1382 pipe_ctx->stream->output_color_space,
1385 pipe_ctx->plane_res.xfm->funcs->transform_set_pixel_storage_depth(
1386 pipe_ctx->plane_res.xfm,
1387 pipe_ctx->plane_res.scl_data.lb_params.depth,
1388 &pipe_ctx->stream->bit_depth_params);
1390 if (pipe_ctx->stream_res.tg->funcs->set_overscan_blank_color) {
1392 * The way 420 is packed, 2 channels carry Y component, 1 channel
1393 * alternate between Cb and Cr, so both channels need the pixel
1396 if (pipe_ctx->stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR420)
1397 color.color_r_cr = color.color_g_y;
1399 pipe_ctx->stream_res.tg->funcs->set_overscan_blank_color(
1400 pipe_ctx->stream_res.tg,
1404 pipe_ctx->plane_res.xfm->funcs->transform_set_scaler(pipe_ctx->plane_res.xfm,
1405 &pipe_ctx->plane_res.scl_data);
1408 static enum dc_status dce110_enable_stream_timing(
1409 struct pipe_ctx *pipe_ctx,
1410 struct dc_state *context,
1413 struct dc_stream_state *stream = pipe_ctx->stream;
1414 struct pipe_ctx *pipe_ctx_old = &dc->current_state->res_ctx.
1415 pipe_ctx[pipe_ctx->pipe_idx];
1416 struct tg_color black_color = {0};
1418 if (!pipe_ctx_old->stream) {
1420 /* program blank color */
1421 color_space_to_black_color(dc,
1422 stream->output_color_space, &black_color);
1423 pipe_ctx->stream_res.tg->funcs->set_blank_color(
1424 pipe_ctx->stream_res.tg,
1428 * Must blank CRTC after disabling power gating and before any
1429 * programming, otherwise CRTC will be hung in bad state
1431 pipe_ctx->stream_res.tg->funcs->set_blank(pipe_ctx->stream_res.tg, true);
1433 if (false == pipe_ctx->clock_source->funcs->program_pix_clk(
1434 pipe_ctx->clock_source,
1435 &pipe_ctx->stream_res.pix_clk_params,
1436 dc->link_srv->dp_get_encoding_format(&pipe_ctx->link_config.dp_link_settings),
1437 &pipe_ctx->pll_settings)) {
1438 BREAK_TO_DEBUGGER();
1439 return DC_ERROR_UNEXPECTED;
1442 if (dc_is_hdmi_tmds_signal(stream->signal)) {
1443 stream->link->phy_state.symclk_ref_cnts.otg = 1;
1444 if (stream->link->phy_state.symclk_state == SYMCLK_OFF_TX_OFF)
1445 stream->link->phy_state.symclk_state = SYMCLK_ON_TX_OFF;
1447 stream->link->phy_state.symclk_state = SYMCLK_ON_TX_ON;
1450 pipe_ctx->stream_res.tg->funcs->program_timing(
1451 pipe_ctx->stream_res.tg,
1457 pipe_ctx->stream->signal,
1461 if (!pipe_ctx_old->stream) {
1462 if (false == pipe_ctx->stream_res.tg->funcs->enable_crtc(
1463 pipe_ctx->stream_res.tg)) {
1464 BREAK_TO_DEBUGGER();
1465 return DC_ERROR_UNEXPECTED;
1472 static enum dc_status apply_single_controller_ctx_to_hw(
1473 struct pipe_ctx *pipe_ctx,
1474 struct dc_state *context,
1477 struct dc_stream_state *stream = pipe_ctx->stream;
1478 struct dc_link *link = stream->link;
1479 struct drr_params params = {0};
1480 unsigned int event_triggers = 0;
1481 struct pipe_ctx *odm_pipe = pipe_ctx->next_odm_pipe;
1482 struct dce_hwseq *hws = dc->hwseq;
1483 const struct link_hwss *link_hwss = get_link_hwss(
1484 link, &pipe_ctx->link_res);
1487 if (hws->funcs.disable_stream_gating) {
1488 hws->funcs.disable_stream_gating(dc, pipe_ctx);
1491 if (pipe_ctx->stream_res.audio != NULL) {
1492 struct audio_output audio_output;
1494 build_audio_output(context, pipe_ctx, &audio_output);
1496 link_hwss->setup_audio_output(pipe_ctx, &audio_output,
1497 pipe_ctx->stream_res.audio->inst);
1499 pipe_ctx->stream_res.audio->funcs->az_configure(
1500 pipe_ctx->stream_res.audio,
1501 pipe_ctx->stream->signal,
1502 &audio_output.crtc_info,
1503 &pipe_ctx->stream->audio_info);
1506 /* make sure no pipes syncd to the pipe being enabled */
1507 if (!pipe_ctx->stream->apply_seamless_boot_optimization && dc->config.use_pipe_ctx_sync_logic)
1508 check_syncd_pipes_for_disabled_master_pipe(dc, context, pipe_ctx->pipe_idx);
1510 pipe_ctx->stream_res.opp->funcs->opp_program_fmt(
1511 pipe_ctx->stream_res.opp,
1512 &stream->bit_depth_params,
1515 pipe_ctx->stream_res.opp->funcs->opp_set_dyn_expansion(
1516 pipe_ctx->stream_res.opp,
1517 COLOR_SPACE_YCBCR601,
1518 stream->timing.display_color_depth,
1522 odm_pipe->stream_res.opp->funcs->opp_set_dyn_expansion(
1523 odm_pipe->stream_res.opp,
1524 COLOR_SPACE_YCBCR601,
1525 stream->timing.display_color_depth,
1528 odm_pipe->stream_res.opp->funcs->opp_program_fmt(
1529 odm_pipe->stream_res.opp,
1530 &stream->bit_depth_params,
1532 odm_pipe = odm_pipe->next_odm_pipe;
1535 /* DCN3.1 FPGA Workaround
1536 * Need to enable HPO DP Stream Encoder before setting OTG master enable.
1537 * To do so, move calling function enable_stream_timing to only be done AFTER calling
1538 * function core_link_enable_stream
1540 if (!(hws->wa.dp_hpo_and_otg_sequence && dc->link_srv->dp_is_128b_132b_signal(pipe_ctx)))
1542 /* Do not touch stream timing on seamless boot optimization. */
1543 if (!pipe_ctx->stream->apply_seamless_boot_optimization)
1544 hws->funcs.enable_stream_timing(pipe_ctx, context, dc);
1546 if (hws->funcs.setup_vupdate_interrupt)
1547 hws->funcs.setup_vupdate_interrupt(dc, pipe_ctx);
1549 params.vertical_total_min = stream->adjust.v_total_min;
1550 params.vertical_total_max = stream->adjust.v_total_max;
1551 if (pipe_ctx->stream_res.tg->funcs->set_drr)
1552 pipe_ctx->stream_res.tg->funcs->set_drr(
1553 pipe_ctx->stream_res.tg, ¶ms);
1555 // DRR should set trigger event to monitor surface update event
1556 if (stream->adjust.v_total_min != 0 && stream->adjust.v_total_max != 0)
1557 event_triggers = 0x80;
1558 /* Event triggers and num frames initialized for DRR, but can be
1559 * later updated for PSR use. Note DRR trigger events are generated
1560 * regardless of whether num frames met.
1562 if (pipe_ctx->stream_res.tg->funcs->set_static_screen_control)
1563 pipe_ctx->stream_res.tg->funcs->set_static_screen_control(
1564 pipe_ctx->stream_res.tg, event_triggers, 2);
1566 if (!dc_is_virtual_signal(pipe_ctx->stream->signal))
1567 pipe_ctx->stream_res.stream_enc->funcs->dig_connect_to_otg(
1568 pipe_ctx->stream_res.stream_enc,
1569 pipe_ctx->stream_res.tg->inst);
1571 if (dc_is_dp_signal(pipe_ctx->stream->signal))
1572 dc->link_srv->dp_trace_source_sequence(link, DPCD_SOURCE_SEQ_AFTER_CONNECT_DIG_FE_OTG);
1574 if (!stream->dpms_off)
1575 dc->link_srv->set_dpms_on(context, pipe_ctx);
1577 /* DCN3.1 FPGA Workaround
1578 * Need to enable HPO DP Stream Encoder before setting OTG master enable.
1579 * To do so, move calling function enable_stream_timing to only be done AFTER calling
1580 * function core_link_enable_stream
1582 if (hws->wa.dp_hpo_and_otg_sequence && dc->link_srv->dp_is_128b_132b_signal(pipe_ctx)) {
1583 if (!pipe_ctx->stream->apply_seamless_boot_optimization)
1584 hws->funcs.enable_stream_timing(pipe_ctx, context, dc);
1587 pipe_ctx->plane_res.scl_data.lb_params.alpha_en = pipe_ctx->bottom_pipe != NULL;
1589 /* Phantom and main stream share the same link (because the stream
1590 * is constructed with the same sink). Make sure not to override
1591 * and link programming on the main.
1593 if (pipe_ctx->stream->mall_stream_config.type != SUBVP_PHANTOM) {
1594 pipe_ctx->stream->link->psr_settings.psr_feature_enabled = false;
1595 pipe_ctx->stream->link->replay_settings.replay_feature_enabled = false;
1600 /******************************************************************************/
1602 static void power_down_encoders(struct dc *dc)
1606 for (i = 0; i < dc->link_count; i++) {
1607 enum signal_type signal = dc->links[i]->connector_signal;
1609 dc->link_srv->blank_dp_stream(dc->links[i], false);
1611 if (signal != SIGNAL_TYPE_EDP)
1612 signal = SIGNAL_TYPE_NONE;
1614 if (dc->links[i]->ep_type == DISPLAY_ENDPOINT_PHY)
1615 dc->links[i]->link_enc->funcs->disable_output(
1616 dc->links[i]->link_enc, signal);
1618 dc->links[i]->link_status.link_active = false;
1619 memset(&dc->links[i]->cur_link_settings, 0,
1620 sizeof(dc->links[i]->cur_link_settings));
1624 static void power_down_controllers(struct dc *dc)
1628 for (i = 0; i < dc->res_pool->timing_generator_count; i++) {
1629 dc->res_pool->timing_generators[i]->funcs->disable_crtc(
1630 dc->res_pool->timing_generators[i]);
1634 static void power_down_clock_sources(struct dc *dc)
1638 if (dc->res_pool->dp_clock_source->funcs->cs_power_down(
1639 dc->res_pool->dp_clock_source) == false)
1640 dm_error("Failed to power down pll! (dp clk src)\n");
1642 for (i = 0; i < dc->res_pool->clk_src_count; i++) {
1643 if (dc->res_pool->clock_sources[i]->funcs->cs_power_down(
1644 dc->res_pool->clock_sources[i]) == false)
1645 dm_error("Failed to power down pll! (clk src index=%d)\n", i);
1649 static void power_down_all_hw_blocks(struct dc *dc)
1651 power_down_encoders(dc);
1653 power_down_controllers(dc);
1655 power_down_clock_sources(dc);
1657 if (dc->fbc_compressor)
1658 dc->fbc_compressor->funcs->disable_fbc(dc->fbc_compressor);
1661 static void disable_vga_and_power_gate_all_controllers(
1665 struct timing_generator *tg;
1666 struct dc_context *ctx = dc->ctx;
1668 for (i = 0; i < dc->res_pool->timing_generator_count; i++) {
1669 tg = dc->res_pool->timing_generators[i];
1671 if (tg->funcs->disable_vga)
1672 tg->funcs->disable_vga(tg);
1674 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1675 /* Enable CLOCK gating for each pipe BEFORE controller
1677 enable_display_pipe_clock_gating(ctx,
1680 dc->current_state->res_ctx.pipe_ctx[i].pipe_idx = i;
1681 dc->hwss.disable_plane(dc,
1682 &dc->current_state->res_ctx.pipe_ctx[i]);
1687 static void get_edp_streams(struct dc_state *context,
1688 struct dc_stream_state **edp_streams,
1689 int *edp_stream_num)
1693 *edp_stream_num = 0;
1694 for (i = 0; i < context->stream_count; i++) {
1695 if (context->streams[i]->signal == SIGNAL_TYPE_EDP) {
1696 edp_streams[*edp_stream_num] = context->streams[i];
1697 if (++(*edp_stream_num) == MAX_NUM_EDP)
1703 static void get_edp_links_with_sink(
1705 struct dc_link **edp_links_with_sink,
1706 int *edp_with_sink_num)
1710 /* check if there is an eDP panel not in use */
1711 *edp_with_sink_num = 0;
1712 for (i = 0; i < dc->link_count; i++) {
1713 if (dc->links[i]->local_sink &&
1714 dc->links[i]->local_sink->sink_signal == SIGNAL_TYPE_EDP) {
1715 edp_links_with_sink[*edp_with_sink_num] = dc->links[i];
1716 if (++(*edp_with_sink_num) == MAX_NUM_EDP)
1723 * When ASIC goes from VBIOS/VGA mode to driver/accelerated mode we need:
1724 * 1. Power down all DC HW blocks
1725 * 2. Disable VGA engine on all controllers
1726 * 3. Enable power gating for controller
1727 * 4. Set acc_mode_change bit (VBIOS will clear this bit when going to FSDOS)
1729 void dce110_enable_accelerated_mode(struct dc *dc, struct dc_state *context)
1731 struct dc_link *edp_links_with_sink[MAX_NUM_EDP];
1732 struct dc_link *edp_links[MAX_NUM_EDP];
1733 struct dc_stream_state *edp_streams[MAX_NUM_EDP];
1734 struct dc_link *edp_link_with_sink = NULL;
1735 struct dc_link *edp_link = NULL;
1736 struct dce_hwseq *hws = dc->hwseq;
1737 int edp_with_sink_num;
1741 bool can_apply_edp_fast_boot = false;
1742 bool can_apply_seamless_boot = false;
1743 bool keep_edp_vdd_on = false;
1747 get_edp_links_with_sink(dc, edp_links_with_sink, &edp_with_sink_num);
1748 dc_get_edp_links(dc, edp_links, &edp_num);
1750 if (hws->funcs.init_pipes)
1751 hws->funcs.init_pipes(dc, context);
1753 get_edp_streams(context, edp_streams, &edp_stream_num);
1755 // Check fastboot support, disable on DCE8 because of blank screens
1756 if (edp_num && edp_stream_num && dc->ctx->dce_version != DCE_VERSION_8_0 &&
1757 dc->ctx->dce_version != DCE_VERSION_8_1 &&
1758 dc->ctx->dce_version != DCE_VERSION_8_3) {
1759 for (i = 0; i < edp_num; i++) {
1760 edp_link = edp_links[i];
1761 if (edp_link != edp_streams[0]->link)
1763 // enable fastboot if backend is enabled on eDP
1764 if (edp_link->link_enc->funcs->is_dig_enabled &&
1765 edp_link->link_enc->funcs->is_dig_enabled(edp_link->link_enc) &&
1766 edp_link->link_status.link_active) {
1767 struct dc_stream_state *edp_stream = edp_streams[0];
1769 can_apply_edp_fast_boot = dc_validate_boot_timing(dc,
1770 edp_stream->sink, &edp_stream->timing);
1771 edp_stream->apply_edp_fast_boot_optimization = can_apply_edp_fast_boot;
1772 if (can_apply_edp_fast_boot)
1773 DC_LOG_EVENT_LINK_TRAINING("eDP fast boot disabled to optimize link rate\n");
1778 // We are trying to enable eDP, don't power down VDD
1779 if (can_apply_edp_fast_boot)
1780 keep_edp_vdd_on = true;
1783 // Check seamless boot support
1784 for (i = 0; i < context->stream_count; i++) {
1785 if (context->streams[i]->apply_seamless_boot_optimization) {
1786 can_apply_seamless_boot = true;
1791 /* eDP should not have stream in resume from S4 and so even with VBios post
1792 * it should get turned off
1794 if (edp_with_sink_num)
1795 edp_link_with_sink = edp_links_with_sink[0];
1797 if (!can_apply_edp_fast_boot && !can_apply_seamless_boot) {
1798 if (edp_link_with_sink && !keep_edp_vdd_on) {
1799 /*turn off backlight before DP_blank and encoder powered down*/
1800 hws->funcs.edp_backlight_control(edp_link_with_sink, false);
1802 /*resume from S3, no vbios posting, no need to power down again*/
1803 clk_mgr_exit_optimized_pwr_state(dc, dc->clk_mgr);
1805 power_down_all_hw_blocks(dc);
1806 disable_vga_and_power_gate_all_controllers(dc);
1807 if (edp_link_with_sink && !keep_edp_vdd_on)
1808 dc->hwss.edp_power_control(edp_link_with_sink, false);
1809 clk_mgr_optimize_pwr_state(dc, dc->clk_mgr);
1811 bios_set_scratch_acc_mode_change(dc->ctx->dc_bios, 1);
1814 static uint32_t compute_pstate_blackout_duration(
1815 struct bw_fixed blackout_duration,
1816 const struct dc_stream_state *stream)
1818 uint32_t total_dest_line_time_ns;
1819 uint32_t pstate_blackout_duration_ns;
1821 pstate_blackout_duration_ns = 1000 * blackout_duration.value >> 24;
1823 total_dest_line_time_ns = 1000000UL *
1824 (stream->timing.h_total * 10) /
1825 stream->timing.pix_clk_100hz +
1826 pstate_blackout_duration_ns;
1828 return total_dest_line_time_ns;
1831 static void dce110_set_displaymarks(
1832 const struct dc *dc,
1833 struct dc_state *context)
1835 uint8_t i, num_pipes;
1836 unsigned int underlay_idx = dc->res_pool->underlay_pipe_index;
1838 for (i = 0, num_pipes = 0; i < MAX_PIPES; i++) {
1839 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
1840 uint32_t total_dest_line_time_ns;
1842 if (pipe_ctx->stream == NULL)
1845 total_dest_line_time_ns = compute_pstate_blackout_duration(
1846 dc->bw_vbios->blackout_duration, pipe_ctx->stream);
1847 pipe_ctx->plane_res.mi->funcs->mem_input_program_display_marks(
1848 pipe_ctx->plane_res.mi,
1849 context->bw_ctx.bw.dce.nbp_state_change_wm_ns[num_pipes],
1850 context->bw_ctx.bw.dce.stutter_exit_wm_ns[num_pipes],
1851 context->bw_ctx.bw.dce.stutter_entry_wm_ns[num_pipes],
1852 context->bw_ctx.bw.dce.urgent_wm_ns[num_pipes],
1853 total_dest_line_time_ns);
1854 if (i == underlay_idx) {
1856 pipe_ctx->plane_res.mi->funcs->mem_input_program_chroma_display_marks(
1857 pipe_ctx->plane_res.mi,
1858 context->bw_ctx.bw.dce.nbp_state_change_wm_ns[num_pipes],
1859 context->bw_ctx.bw.dce.stutter_exit_wm_ns[num_pipes],
1860 context->bw_ctx.bw.dce.urgent_wm_ns[num_pipes],
1861 total_dest_line_time_ns);
1867 void dce110_set_safe_displaymarks(
1868 struct resource_context *res_ctx,
1869 const struct resource_pool *pool)
1872 int underlay_idx = pool->underlay_pipe_index;
1873 struct dce_watermarks max_marks = {
1874 MAX_WATERMARK, MAX_WATERMARK, MAX_WATERMARK, MAX_WATERMARK };
1875 struct dce_watermarks nbp_marks = {
1876 SAFE_NBP_MARK, SAFE_NBP_MARK, SAFE_NBP_MARK, SAFE_NBP_MARK };
1877 struct dce_watermarks min_marks = { 0, 0, 0, 0};
1879 for (i = 0; i < MAX_PIPES; i++) {
1880 if (res_ctx->pipe_ctx[i].stream == NULL || res_ctx->pipe_ctx[i].plane_res.mi == NULL)
1883 res_ctx->pipe_ctx[i].plane_res.mi->funcs->mem_input_program_display_marks(
1884 res_ctx->pipe_ctx[i].plane_res.mi,
1891 if (i == underlay_idx)
1892 res_ctx->pipe_ctx[i].plane_res.mi->funcs->mem_input_program_chroma_display_marks(
1893 res_ctx->pipe_ctx[i].plane_res.mi,
1902 /*******************************************************************************
1904 ******************************************************************************/
1906 static void set_drr(struct pipe_ctx **pipe_ctx,
1907 int num_pipes, struct dc_crtc_timing_adjust adjust)
1910 struct drr_params params = {0};
1911 // DRR should set trigger event to monitor surface update event
1912 unsigned int event_triggers = 0x80;
1913 // Note DRR trigger events are generated regardless of whether num frames met.
1914 unsigned int num_frames = 2;
1916 params.vertical_total_max = adjust.v_total_max;
1917 params.vertical_total_min = adjust.v_total_min;
1919 /* TODO: If multiple pipes are to be supported, you need
1920 * some GSL stuff. Static screen triggers may be programmed differently
1923 for (i = 0; i < num_pipes; i++) {
1924 pipe_ctx[i]->stream_res.tg->funcs->set_drr(
1925 pipe_ctx[i]->stream_res.tg, ¶ms);
1927 if (adjust.v_total_max != 0 && adjust.v_total_min != 0)
1928 pipe_ctx[i]->stream_res.tg->funcs->set_static_screen_control(
1929 pipe_ctx[i]->stream_res.tg,
1930 event_triggers, num_frames);
1934 static void get_position(struct pipe_ctx **pipe_ctx,
1936 struct crtc_position *position)
1940 /* TODO: handle pipes > 1
1942 for (i = 0; i < num_pipes; i++)
1943 pipe_ctx[i]->stream_res.tg->funcs->get_position(pipe_ctx[i]->stream_res.tg, position);
1946 static void set_static_screen_control(struct pipe_ctx **pipe_ctx,
1947 int num_pipes, const struct dc_static_screen_params *params)
1950 unsigned int triggers = 0;
1952 if (params->triggers.overlay_update)
1954 if (params->triggers.surface_update)
1956 if (params->triggers.cursor_update)
1958 if (params->triggers.force_trigger)
1962 struct dc *dc = pipe_ctx[0]->stream->ctx->dc;
1964 if (dc->fbc_compressor)
1968 for (i = 0; i < num_pipes; i++)
1969 pipe_ctx[i]->stream_res.tg->funcs->
1970 set_static_screen_control(pipe_ctx[i]->stream_res.tg,
1971 triggers, params->num_frames);
1975 * Check if FBC can be enabled
1977 static bool should_enable_fbc(struct dc *dc,
1978 struct dc_state *context,
1982 struct pipe_ctx *pipe_ctx = NULL;
1983 struct resource_context *res_ctx = &context->res_ctx;
1984 unsigned int underlay_idx = dc->res_pool->underlay_pipe_index;
1987 ASSERT(dc->fbc_compressor);
1989 /* FBC memory should be allocated */
1990 if (!dc->ctx->fbc_gpu_addr)
1993 /* Only supports single display */
1994 if (context->stream_count != 1)
1997 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1998 if (res_ctx->pipe_ctx[i].stream) {
2000 pipe_ctx = &res_ctx->pipe_ctx[i];
2005 /* fbc not applicable on underlay pipe */
2006 if (pipe_ctx->pipe_idx != underlay_idx) {
2013 if (i == dc->res_pool->pipe_count)
2016 if (!pipe_ctx->stream->link)
2019 /* Only supports eDP */
2020 if (pipe_ctx->stream->link->connector_signal != SIGNAL_TYPE_EDP)
2023 /* PSR should not be enabled */
2024 if (pipe_ctx->stream->link->psr_settings.psr_feature_enabled)
2027 /* Replay should not be enabled */
2028 if (pipe_ctx->stream->link->replay_settings.replay_feature_enabled)
2031 /* Nothing to compress */
2032 if (!pipe_ctx->plane_state)
2035 /* Only for non-linear tiling */
2036 if (pipe_ctx->plane_state->tiling_info.gfx8.array_mode == DC_ARRAY_LINEAR_GENERAL)
2045 static void enable_fbc(
2047 struct dc_state *context)
2049 uint32_t pipe_idx = 0;
2051 if (should_enable_fbc(dc, context, &pipe_idx)) {
2052 /* Program GRPH COMPRESSED ADDRESS and PITCH */
2053 struct compr_addr_and_pitch_params params = {0, 0, 0};
2054 struct compressor *compr = dc->fbc_compressor;
2055 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[pipe_idx];
2057 params.source_view_width = pipe_ctx->stream->timing.h_addressable;
2058 params.source_view_height = pipe_ctx->stream->timing.v_addressable;
2059 params.inst = pipe_ctx->stream_res.tg->inst;
2060 compr->compr_surface_address.quad_part = dc->ctx->fbc_gpu_addr;
2062 compr->funcs->surface_address_and_pitch(compr, ¶ms);
2063 compr->funcs->set_fbc_invalidation_triggers(compr, 1);
2065 compr->funcs->enable_fbc(compr, ¶ms);
2069 static void dce110_reset_hw_ctx_wrap(
2071 struct dc_state *context)
2075 /* Reset old context */
2076 /* look up the targets that have been removed since last commit */
2077 for (i = 0; i < MAX_PIPES; i++) {
2078 struct pipe_ctx *pipe_ctx_old =
2079 &dc->current_state->res_ctx.pipe_ctx[i];
2080 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2082 /* Note: We need to disable output if clock sources change,
2083 * since bios does optimization and doesn't apply if changing
2084 * PHY when not already disabled.
2087 /* Skip underlay pipe since it will be handled in commit surface*/
2088 if (!pipe_ctx_old->stream || pipe_ctx_old->top_pipe)
2091 if (!pipe_ctx->stream ||
2092 pipe_need_reprogram(pipe_ctx_old, pipe_ctx)) {
2093 struct clock_source *old_clk = pipe_ctx_old->clock_source;
2095 /* Disable if new stream is null. O/w, if stream is
2096 * disabled already, no need to disable again.
2098 if (!pipe_ctx->stream || !pipe_ctx->stream->dpms_off) {
2099 dc->link_srv->set_dpms_off(pipe_ctx_old);
2101 /* free acquired resources*/
2102 if (pipe_ctx_old->stream_res.audio) {
2103 /*disable az_endpoint*/
2104 pipe_ctx_old->stream_res.audio->funcs->
2105 az_disable(pipe_ctx_old->stream_res.audio);
2108 if (dc->caps.dynamic_audio == true) {
2109 /*we have to dynamic arbitrate the audio endpoints*/
2110 /*we free the resource, need reset is_audio_acquired*/
2111 update_audio_usage(&dc->current_state->res_ctx, dc->res_pool,
2112 pipe_ctx_old->stream_res.audio, false);
2113 pipe_ctx_old->stream_res.audio = NULL;
2118 pipe_ctx_old->stream_res.tg->funcs->set_blank(pipe_ctx_old->stream_res.tg, true);
2119 if (!hwss_wait_for_blank_complete(pipe_ctx_old->stream_res.tg)) {
2120 dm_error("DC: failed to blank crtc!\n");
2121 BREAK_TO_DEBUGGER();
2123 pipe_ctx_old->stream_res.tg->funcs->disable_crtc(pipe_ctx_old->stream_res.tg);
2124 pipe_ctx_old->stream->link->phy_state.symclk_ref_cnts.otg = 0;
2125 pipe_ctx_old->plane_res.mi->funcs->free_mem_input(
2126 pipe_ctx_old->plane_res.mi, dc->current_state->stream_count);
2128 if (old_clk && 0 == resource_get_clock_source_reference(&context->res_ctx,
2131 old_clk->funcs->cs_power_down(old_clk);
2133 dc->hwss.disable_plane(dc, pipe_ctx_old);
2135 pipe_ctx_old->stream = NULL;
2140 static void dce110_setup_audio_dto(
2142 struct dc_state *context)
2146 /* program audio wall clock. use HDMI as clock source if HDMI
2147 * audio active. Otherwise, use DP as clock source
2148 * first, loop to find any HDMI audio, if not, loop find DP audio
2150 /* Setup audio rate clock source */
2152 * Audio lag happened on DP monitor when unplug a HDMI monitor
2155 * In case of DP and HDMI connected or HDMI only, DCCG_AUDIO_DTO_SEL
2156 * is set to either dto0 or dto1, audio should work fine.
2157 * In case of DP connected only, DCCG_AUDIO_DTO_SEL should be dto1,
2158 * set to dto0 will cause audio lag.
2161 * Not optimized audio wall dto setup. When mode set, iterate pipe_ctx,
2162 * find first available pipe with audio, setup audio wall DTO per topology
2163 * instead of per pipe.
2165 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2166 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2168 if (pipe_ctx->stream == NULL)
2171 if (pipe_ctx->top_pipe)
2173 if (pipe_ctx->stream->signal != SIGNAL_TYPE_HDMI_TYPE_A)
2175 if (pipe_ctx->stream_res.audio != NULL) {
2176 struct audio_output audio_output;
2178 build_audio_output(context, pipe_ctx, &audio_output);
2180 if (dc->res_pool->dccg && dc->res_pool->dccg->funcs->set_audio_dtbclk_dto) {
2181 struct dtbclk_dto_params dto_params = {0};
2183 dc->res_pool->dccg->funcs->set_audio_dtbclk_dto(
2184 dc->res_pool->dccg, &dto_params);
2186 pipe_ctx->stream_res.audio->funcs->wall_dto_setup(
2187 pipe_ctx->stream_res.audio,
2188 pipe_ctx->stream->signal,
2189 &audio_output.crtc_info,
2190 &audio_output.pll_info);
2192 pipe_ctx->stream_res.audio->funcs->wall_dto_setup(
2193 pipe_ctx->stream_res.audio,
2194 pipe_ctx->stream->signal,
2195 &audio_output.crtc_info,
2196 &audio_output.pll_info);
2201 /* no HDMI audio is found, try DP audio */
2202 if (i == dc->res_pool->pipe_count) {
2203 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2204 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2206 if (pipe_ctx->stream == NULL)
2209 if (pipe_ctx->top_pipe)
2212 if (!dc_is_dp_signal(pipe_ctx->stream->signal))
2215 if (pipe_ctx->stream_res.audio != NULL) {
2216 struct audio_output audio_output;
2218 build_audio_output(context, pipe_ctx, &audio_output);
2220 pipe_ctx->stream_res.audio->funcs->wall_dto_setup(
2221 pipe_ctx->stream_res.audio,
2222 pipe_ctx->stream->signal,
2223 &audio_output.crtc_info,
2224 &audio_output.pll_info);
2231 enum dc_status dce110_apply_ctx_to_hw(
2233 struct dc_state *context)
2235 struct dce_hwseq *hws = dc->hwseq;
2236 struct dc_bios *dcb = dc->ctx->dc_bios;
2237 enum dc_status status;
2240 /* reset syncd pipes from disabled pipes */
2241 if (dc->config.use_pipe_ctx_sync_logic)
2242 reset_syncd_pipes_from_disabled_pipes(dc, context);
2244 /* Reset old context */
2245 /* look up the targets that have been removed since last commit */
2246 hws->funcs.reset_hw_ctx_wrap(dc, context);
2248 /* Skip applying if no targets */
2249 if (context->stream_count <= 0)
2252 /* Apply new context */
2253 dcb->funcs->set_scratch_critical_state(dcb, true);
2255 /* below is for real asic only */
2256 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2257 struct pipe_ctx *pipe_ctx_old =
2258 &dc->current_state->res_ctx.pipe_ctx[i];
2259 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2261 if (pipe_ctx->stream == NULL || pipe_ctx->top_pipe)
2264 if (pipe_ctx->stream == pipe_ctx_old->stream) {
2265 if (pipe_ctx_old->clock_source != pipe_ctx->clock_source)
2266 dce_crtc_switch_to_clk_src(dc->hwseq,
2267 pipe_ctx->clock_source, i);
2271 hws->funcs.enable_display_power_gating(
2272 dc, i, dc->ctx->dc_bios,
2273 PIPE_GATING_CONTROL_DISABLE);
2276 if (dc->fbc_compressor)
2277 dc->fbc_compressor->funcs->disable_fbc(dc->fbc_compressor);
2279 dce110_setup_audio_dto(dc, context);
2281 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2282 struct pipe_ctx *pipe_ctx_old =
2283 &dc->current_state->res_ctx.pipe_ctx[i];
2284 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2286 if (pipe_ctx->stream == NULL)
2289 if (pipe_ctx->stream == pipe_ctx_old->stream &&
2290 pipe_ctx->stream->link->link_state_valid) {
2294 if (pipe_ctx_old->stream && !pipe_need_reprogram(pipe_ctx_old, pipe_ctx))
2297 if (pipe_ctx->top_pipe || pipe_ctx->prev_odm_pipe)
2300 status = apply_single_controller_ctx_to_hw(
2305 if (DC_OK != status)
2308 #ifdef CONFIG_DRM_AMD_DC_FP
2309 if (hws->funcs.resync_fifo_dccg_dio)
2310 hws->funcs.resync_fifo_dccg_dio(hws, dc, context);
2314 if (dc->fbc_compressor)
2315 enable_fbc(dc, dc->current_state);
2317 dcb->funcs->set_scratch_critical_state(dcb, false);
2322 /*******************************************************************************
2323 * Front End programming
2324 ******************************************************************************/
2325 static void set_default_colors(struct pipe_ctx *pipe_ctx)
2327 struct default_adjustment default_adjust = { 0 };
2329 default_adjust.force_hw_default = false;
2330 default_adjust.in_color_space = pipe_ctx->plane_state->color_space;
2331 default_adjust.out_color_space = pipe_ctx->stream->output_color_space;
2332 default_adjust.csc_adjust_type = GRAPHICS_CSC_ADJUST_TYPE_SW;
2333 default_adjust.surface_pixel_format = pipe_ctx->plane_res.scl_data.format;
2335 /* display color depth */
2336 default_adjust.color_depth =
2337 pipe_ctx->stream->timing.display_color_depth;
2339 /* Lb color depth */
2340 default_adjust.lb_color_depth = pipe_ctx->plane_res.scl_data.lb_params.depth;
2342 pipe_ctx->plane_res.xfm->funcs->opp_set_csc_default(
2343 pipe_ctx->plane_res.xfm, &default_adjust);
2347 /*******************************************************************************
2348 * In order to turn on/off specific surface we will program
2351 * In case that we have two surfaces and they have a different visibility
2352 * we can't turn off the CRTC since it will turn off the entire display
2354 * |----------------------------------------------- |
2355 * |bottom pipe|curr pipe | | |
2356 * |Surface |Surface | Blender | CRCT |
2357 * |visibility |visibility | Configuration| |
2358 * |------------------------------------------------|
2359 * | off | off | CURRENT_PIPE | blank |
2360 * | off | on | CURRENT_PIPE | unblank |
2361 * | on | off | OTHER_PIPE | unblank |
2362 * | on | on | BLENDING | unblank |
2363 * -------------------------------------------------|
2365 ******************************************************************************/
2366 static void program_surface_visibility(const struct dc *dc,
2367 struct pipe_ctx *pipe_ctx)
2369 enum blnd_mode blender_mode = BLND_MODE_CURRENT_PIPE;
2370 bool blank_target = false;
2372 if (pipe_ctx->bottom_pipe) {
2374 /* For now we are supporting only two pipes */
2375 ASSERT(pipe_ctx->bottom_pipe->bottom_pipe == NULL);
2377 if (pipe_ctx->bottom_pipe->plane_state->visible) {
2378 if (pipe_ctx->plane_state->visible)
2379 blender_mode = BLND_MODE_BLENDING;
2381 blender_mode = BLND_MODE_OTHER_PIPE;
2383 } else if (!pipe_ctx->plane_state->visible)
2384 blank_target = true;
2386 } else if (!pipe_ctx->plane_state->visible)
2387 blank_target = true;
2389 dce_set_blender_mode(dc->hwseq, pipe_ctx->stream_res.tg->inst, blender_mode);
2390 pipe_ctx->stream_res.tg->funcs->set_blank(pipe_ctx->stream_res.tg, blank_target);
2394 static void program_gamut_remap(struct pipe_ctx *pipe_ctx)
2397 struct xfm_grph_csc_adjustment adjust;
2398 memset(&adjust, 0, sizeof(adjust));
2399 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS;
2402 if (pipe_ctx->stream->gamut_remap_matrix.enable_remap == true) {
2403 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_SW;
2405 for (i = 0; i < CSC_TEMPERATURE_MATRIX_SIZE; i++)
2406 adjust.temperature_matrix[i] =
2407 pipe_ctx->stream->gamut_remap_matrix.matrix[i];
2410 pipe_ctx->plane_res.xfm->funcs->transform_set_gamut_remap(pipe_ctx->plane_res.xfm, &adjust);
2412 static void update_plane_addr(const struct dc *dc,
2413 struct pipe_ctx *pipe_ctx)
2415 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
2417 if (plane_state == NULL)
2420 pipe_ctx->plane_res.mi->funcs->mem_input_program_surface_flip_and_addr(
2421 pipe_ctx->plane_res.mi,
2422 &plane_state->address,
2423 plane_state->flip_immediate);
2425 plane_state->status.requested_address = plane_state->address;
2428 static void dce110_update_pending_status(struct pipe_ctx *pipe_ctx)
2430 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
2432 if (plane_state == NULL)
2435 plane_state->status.is_flip_pending =
2436 pipe_ctx->plane_res.mi->funcs->mem_input_is_flip_pending(
2437 pipe_ctx->plane_res.mi);
2439 if (plane_state->status.is_flip_pending && !plane_state->visible)
2440 pipe_ctx->plane_res.mi->current_address = pipe_ctx->plane_res.mi->request_address;
2442 plane_state->status.current_address = pipe_ctx->plane_res.mi->current_address;
2443 if (pipe_ctx->plane_res.mi->current_address.type == PLN_ADDR_TYPE_GRPH_STEREO &&
2444 pipe_ctx->stream_res.tg->funcs->is_stereo_left_eye) {
2445 plane_state->status.is_right_eye =\
2446 !pipe_ctx->stream_res.tg->funcs->is_stereo_left_eye(pipe_ctx->stream_res.tg);
2450 void dce110_power_down(struct dc *dc)
2452 power_down_all_hw_blocks(dc);
2453 disable_vga_and_power_gate_all_controllers(dc);
2456 static bool wait_for_reset_trigger_to_occur(
2457 struct dc_context *dc_ctx,
2458 struct timing_generator *tg)
2462 /* To avoid endless loop we wait at most
2463 * frames_to_wait_on_triggered_reset frames for the reset to occur. */
2464 const uint32_t frames_to_wait_on_triggered_reset = 10;
2467 for (i = 0; i < frames_to_wait_on_triggered_reset; i++) {
2469 if (!tg->funcs->is_counter_moving(tg)) {
2470 DC_ERROR("TG counter is not moving!\n");
2474 if (tg->funcs->did_triggered_reset_occur(tg)) {
2476 /* usually occurs at i=1 */
2477 DC_SYNC_INFO("GSL: reset occurred at wait count: %d\n",
2482 /* Wait for one frame. */
2483 tg->funcs->wait_for_state(tg, CRTC_STATE_VACTIVE);
2484 tg->funcs->wait_for_state(tg, CRTC_STATE_VBLANK);
2488 DC_ERROR("GSL: Timeout on reset trigger!\n");
2493 /* Enable timing synchronization for a group of Timing Generators. */
2494 static void dce110_enable_timing_synchronization(
2498 struct pipe_ctx *grouped_pipes[])
2500 struct dc_context *dc_ctx = dc->ctx;
2501 struct dcp_gsl_params gsl_params = { 0 };
2504 DC_SYNC_INFO("GSL: Setting-up...\n");
2506 /* Designate a single TG in the group as a master.
2507 * Since HW doesn't care which one, we always assign
2508 * the 1st one in the group. */
2509 gsl_params.gsl_group = 0;
2510 gsl_params.gsl_master = grouped_pipes[0]->stream_res.tg->inst;
2512 for (i = 0; i < group_size; i++)
2513 grouped_pipes[i]->stream_res.tg->funcs->setup_global_swap_lock(
2514 grouped_pipes[i]->stream_res.tg, &gsl_params);
2516 /* Reset slave controllers on master VSync */
2517 DC_SYNC_INFO("GSL: enabling trigger-reset\n");
2519 for (i = 1 /* skip the master */; i < group_size; i++)
2520 grouped_pipes[i]->stream_res.tg->funcs->enable_reset_trigger(
2521 grouped_pipes[i]->stream_res.tg,
2522 gsl_params.gsl_group);
2524 for (i = 1 /* skip the master */; i < group_size; i++) {
2525 DC_SYNC_INFO("GSL: waiting for reset to occur.\n");
2526 wait_for_reset_trigger_to_occur(dc_ctx, grouped_pipes[i]->stream_res.tg);
2527 grouped_pipes[i]->stream_res.tg->funcs->disable_reset_trigger(
2528 grouped_pipes[i]->stream_res.tg);
2531 /* GSL Vblank synchronization is a one time sync mechanism, assumption
2532 * is that the sync'ed displays will not drift out of sync over time*/
2533 DC_SYNC_INFO("GSL: Restoring register states.\n");
2534 for (i = 0; i < group_size; i++)
2535 grouped_pipes[i]->stream_res.tg->funcs->tear_down_global_swap_lock(grouped_pipes[i]->stream_res.tg);
2537 DC_SYNC_INFO("GSL: Set-up complete.\n");
2540 static void dce110_enable_per_frame_crtc_position_reset(
2543 struct pipe_ctx *grouped_pipes[])
2545 struct dc_context *dc_ctx = dc->ctx;
2546 struct dcp_gsl_params gsl_params = { 0 };
2549 gsl_params.gsl_group = 0;
2550 gsl_params.gsl_master = 0;
2552 for (i = 0; i < group_size; i++)
2553 grouped_pipes[i]->stream_res.tg->funcs->setup_global_swap_lock(
2554 grouped_pipes[i]->stream_res.tg, &gsl_params);
2556 DC_SYNC_INFO("GSL: enabling trigger-reset\n");
2558 for (i = 1; i < group_size; i++)
2559 grouped_pipes[i]->stream_res.tg->funcs->enable_crtc_reset(
2560 grouped_pipes[i]->stream_res.tg,
2561 gsl_params.gsl_master,
2562 &grouped_pipes[i]->stream->triggered_crtc_reset);
2564 DC_SYNC_INFO("GSL: waiting for reset to occur.\n");
2565 for (i = 1; i < group_size; i++)
2566 wait_for_reset_trigger_to_occur(dc_ctx, grouped_pipes[i]->stream_res.tg);
2568 for (i = 0; i < group_size; i++)
2569 grouped_pipes[i]->stream_res.tg->funcs->tear_down_global_swap_lock(grouped_pipes[i]->stream_res.tg);
2573 static void init_pipes(struct dc *dc, struct dc_state *context)
2578 static void init_hw(struct dc *dc)
2582 struct transform *xfm;
2585 struct dce_hwseq *hws = dc->hwseq;
2586 uint32_t backlight = MAX_BACKLIGHT_LEVEL;
2588 bp = dc->ctx->dc_bios;
2589 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2590 xfm = dc->res_pool->transforms[i];
2591 xfm->funcs->transform_reset(xfm);
2593 hws->funcs.enable_display_power_gating(
2595 PIPE_GATING_CONTROL_INIT);
2596 hws->funcs.enable_display_power_gating(
2598 PIPE_GATING_CONTROL_DISABLE);
2599 hws->funcs.enable_display_pipe_clock_gating(
2604 dce_clock_gating_power_up(dc->hwseq, false);
2605 /***************************************/
2607 for (i = 0; i < dc->link_count; i++) {
2608 /****************************************/
2609 /* Power up AND update implementation according to the
2610 * required signal (which may be different from the
2611 * default signal on connector). */
2612 struct dc_link *link = dc->links[i];
2614 link->link_enc->funcs->hw_init(link->link_enc);
2617 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2618 struct timing_generator *tg = dc->res_pool->timing_generators[i];
2620 tg->funcs->disable_vga(tg);
2622 /* Blank controller using driver code instead of
2624 tg->funcs->set_blank(tg, true);
2625 hwss_wait_for_blank_complete(tg);
2628 for (i = 0; i < dc->res_pool->audio_count; i++) {
2629 struct audio *audio = dc->res_pool->audios[i];
2630 audio->funcs->hw_init(audio);
2633 for (i = 0; i < dc->link_count; i++) {
2634 struct dc_link *link = dc->links[i];
2636 if (link->panel_cntl)
2637 backlight = link->panel_cntl->funcs->hw_init(link->panel_cntl);
2640 abm = dc->res_pool->abm;
2642 abm->funcs->abm_init(abm, backlight);
2644 dmcu = dc->res_pool->dmcu;
2645 if (dmcu != NULL && abm != NULL)
2646 abm->dmcu_is_running = dmcu->funcs->is_dmcu_initialized(dmcu);
2648 if (dc->fbc_compressor)
2649 dc->fbc_compressor->funcs->power_up_fbc(dc->fbc_compressor);
2654 void dce110_prepare_bandwidth(
2656 struct dc_state *context)
2658 struct clk_mgr *dccg = dc->clk_mgr;
2660 dce110_set_safe_displaymarks(&context->res_ctx, dc->res_pool);
2662 dccg->funcs->update_clocks(
2668 void dce110_optimize_bandwidth(
2670 struct dc_state *context)
2672 struct clk_mgr *dccg = dc->clk_mgr;
2674 dce110_set_displaymarks(dc, context);
2676 dccg->funcs->update_clocks(
2682 static void dce110_program_front_end_for_pipe(
2683 struct dc *dc, struct pipe_ctx *pipe_ctx)
2685 struct mem_input *mi = pipe_ctx->plane_res.mi;
2686 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
2687 struct xfm_grph_csc_adjustment adjust;
2688 struct out_csc_color_matrix tbl_entry;
2690 struct dce_hwseq *hws = dc->hwseq;
2693 memset(&tbl_entry, 0, sizeof(tbl_entry));
2695 memset(&adjust, 0, sizeof(adjust));
2696 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS;
2698 dce_enable_fe_clock(dc->hwseq, mi->inst, true);
2700 set_default_colors(pipe_ctx);
2701 if (pipe_ctx->stream->csc_color_matrix.enable_adjustment
2703 tbl_entry.color_space =
2704 pipe_ctx->stream->output_color_space;
2706 for (i = 0; i < 12; i++)
2707 tbl_entry.regval[i] =
2708 pipe_ctx->stream->csc_color_matrix.matrix[i];
2710 pipe_ctx->plane_res.xfm->funcs->opp_set_csc_adjustment
2711 (pipe_ctx->plane_res.xfm, &tbl_entry);
2714 if (pipe_ctx->stream->gamut_remap_matrix.enable_remap == true) {
2715 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_SW;
2717 for (i = 0; i < CSC_TEMPERATURE_MATRIX_SIZE; i++)
2718 adjust.temperature_matrix[i] =
2719 pipe_ctx->stream->gamut_remap_matrix.matrix[i];
2722 pipe_ctx->plane_res.xfm->funcs->transform_set_gamut_remap(pipe_ctx->plane_res.xfm, &adjust);
2724 pipe_ctx->plane_res.scl_data.lb_params.alpha_en = pipe_ctx->bottom_pipe != NULL;
2726 program_scaler(dc, pipe_ctx);
2728 mi->funcs->mem_input_program_surface_config(
2730 plane_state->format,
2731 &plane_state->tiling_info,
2732 &plane_state->plane_size,
2733 plane_state->rotation,
2736 if (mi->funcs->set_blank)
2737 mi->funcs->set_blank(mi, pipe_ctx->plane_state->visible);
2739 if (dc->config.gpu_vm_support)
2740 mi->funcs->mem_input_program_pte_vm(
2741 pipe_ctx->plane_res.mi,
2742 plane_state->format,
2743 &plane_state->tiling_info,
2744 plane_state->rotation);
2746 /* Moved programming gamma from dc to hwss */
2747 if (pipe_ctx->plane_state->update_flags.bits.full_update ||
2748 pipe_ctx->plane_state->update_flags.bits.in_transfer_func_change ||
2749 pipe_ctx->plane_state->update_flags.bits.gamma_change)
2750 hws->funcs.set_input_transfer_func(dc, pipe_ctx, pipe_ctx->plane_state);
2752 if (pipe_ctx->plane_state->update_flags.bits.full_update)
2753 hws->funcs.set_output_transfer_func(dc, pipe_ctx, pipe_ctx->stream);
2756 "Pipe:%d %p: addr hi:0x%x, "
2759 " %d; dst: %d, %d, %d, %d;"
2760 "clip: %d, %d, %d, %d\n",
2762 (void *) pipe_ctx->plane_state,
2763 pipe_ctx->plane_state->address.grph.addr.high_part,
2764 pipe_ctx->plane_state->address.grph.addr.low_part,
2765 pipe_ctx->plane_state->src_rect.x,
2766 pipe_ctx->plane_state->src_rect.y,
2767 pipe_ctx->plane_state->src_rect.width,
2768 pipe_ctx->plane_state->src_rect.height,
2769 pipe_ctx->plane_state->dst_rect.x,
2770 pipe_ctx->plane_state->dst_rect.y,
2771 pipe_ctx->plane_state->dst_rect.width,
2772 pipe_ctx->plane_state->dst_rect.height,
2773 pipe_ctx->plane_state->clip_rect.x,
2774 pipe_ctx->plane_state->clip_rect.y,
2775 pipe_ctx->plane_state->clip_rect.width,
2776 pipe_ctx->plane_state->clip_rect.height);
2779 "Pipe %d: width, height, x, y\n"
2780 "viewport:%d, %d, %d, %d\n"
2781 "recout: %d, %d, %d, %d\n",
2783 pipe_ctx->plane_res.scl_data.viewport.width,
2784 pipe_ctx->plane_res.scl_data.viewport.height,
2785 pipe_ctx->plane_res.scl_data.viewport.x,
2786 pipe_ctx->plane_res.scl_data.viewport.y,
2787 pipe_ctx->plane_res.scl_data.recout.width,
2788 pipe_ctx->plane_res.scl_data.recout.height,
2789 pipe_ctx->plane_res.scl_data.recout.x,
2790 pipe_ctx->plane_res.scl_data.recout.y);
2793 static void dce110_apply_ctx_for_surface(
2795 const struct dc_stream_state *stream,
2797 struct dc_state *context)
2801 if (num_planes == 0)
2804 if (dc->fbc_compressor)
2805 dc->fbc_compressor->funcs->disable_fbc(dc->fbc_compressor);
2807 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2808 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2810 if (pipe_ctx->stream != stream)
2813 /* Need to allocate mem before program front end for Fiji */
2814 pipe_ctx->plane_res.mi->funcs->allocate_mem_input(
2815 pipe_ctx->plane_res.mi,
2816 pipe_ctx->stream->timing.h_total,
2817 pipe_ctx->stream->timing.v_total,
2818 pipe_ctx->stream->timing.pix_clk_100hz / 10,
2819 context->stream_count);
2821 dce110_program_front_end_for_pipe(dc, pipe_ctx);
2823 dc->hwss.update_plane_addr(dc, pipe_ctx);
2825 program_surface_visibility(dc, pipe_ctx);
2829 if (dc->fbc_compressor)
2830 enable_fbc(dc, context);
2833 static void dce110_post_unlock_program_front_end(
2835 struct dc_state *context)
2839 static void dce110_power_down_fe(struct dc *dc, struct pipe_ctx *pipe_ctx)
2841 struct dce_hwseq *hws = dc->hwseq;
2842 int fe_idx = pipe_ctx->plane_res.mi ?
2843 pipe_ctx->plane_res.mi->inst : pipe_ctx->pipe_idx;
2845 /* Do not power down fe when stream is active on dce*/
2846 if (dc->current_state->res_ctx.pipe_ctx[fe_idx].stream)
2849 hws->funcs.enable_display_power_gating(
2850 dc, fe_idx, dc->ctx->dc_bios, PIPE_GATING_CONTROL_ENABLE);
2852 dc->res_pool->transforms[fe_idx]->funcs->transform_reset(
2853 dc->res_pool->transforms[fe_idx]);
2856 static void dce110_wait_for_mpcc_disconnect(
2858 struct resource_pool *res_pool,
2859 struct pipe_ctx *pipe_ctx)
2864 static void program_output_csc(struct dc *dc,
2865 struct pipe_ctx *pipe_ctx,
2866 enum dc_color_space colorspace,
2871 struct out_csc_color_matrix tbl_entry;
2873 if (pipe_ctx->stream->csc_color_matrix.enable_adjustment == true) {
2874 enum dc_color_space color_space = pipe_ctx->stream->output_color_space;
2876 for (i = 0; i < 12; i++)
2877 tbl_entry.regval[i] = pipe_ctx->stream->csc_color_matrix.matrix[i];
2879 tbl_entry.color_space = color_space;
2881 pipe_ctx->plane_res.xfm->funcs->opp_set_csc_adjustment(
2882 pipe_ctx->plane_res.xfm, &tbl_entry);
2886 static void dce110_set_cursor_position(struct pipe_ctx *pipe_ctx)
2888 struct dc_cursor_position pos_cpy = pipe_ctx->stream->cursor_position;
2889 struct input_pixel_processor *ipp = pipe_ctx->plane_res.ipp;
2890 struct mem_input *mi = pipe_ctx->plane_res.mi;
2891 struct dc_cursor_mi_param param = {
2892 .pixel_clk_khz = pipe_ctx->stream->timing.pix_clk_100hz / 10,
2893 .ref_clk_khz = pipe_ctx->stream->ctx->dc->res_pool->ref_clocks.xtalin_clock_inKhz,
2894 .viewport = pipe_ctx->plane_res.scl_data.viewport,
2895 .h_scale_ratio = pipe_ctx->plane_res.scl_data.ratios.horz,
2896 .v_scale_ratio = pipe_ctx->plane_res.scl_data.ratios.vert,
2897 .rotation = pipe_ctx->plane_state->rotation,
2898 .mirror = pipe_ctx->plane_state->horizontal_mirror
2902 * If the cursor's source viewport is clipped then we need to
2903 * translate the cursor to appear in the correct position on
2906 * This translation isn't affected by scaling so it needs to be
2907 * done *after* we adjust the position for the scale factor.
2909 * This is only done by opt-in for now since there are still
2910 * some usecases like tiled display that might enable the
2911 * cursor on both streams while expecting dc to clip it.
2913 if (pos_cpy.translate_by_source) {
2914 pos_cpy.x += pipe_ctx->plane_state->src_rect.x;
2915 pos_cpy.y += pipe_ctx->plane_state->src_rect.y;
2918 if (pipe_ctx->plane_state->address.type
2919 == PLN_ADDR_TYPE_VIDEO_PROGRESSIVE)
2920 pos_cpy.enable = false;
2922 if (pipe_ctx->top_pipe && pipe_ctx->plane_state != pipe_ctx->top_pipe->plane_state)
2923 pos_cpy.enable = false;
2925 if (ipp->funcs->ipp_cursor_set_position)
2926 ipp->funcs->ipp_cursor_set_position(ipp, &pos_cpy, ¶m);
2927 if (mi->funcs->set_cursor_position)
2928 mi->funcs->set_cursor_position(mi, &pos_cpy, ¶m);
2931 static void dce110_set_cursor_attribute(struct pipe_ctx *pipe_ctx)
2933 struct dc_cursor_attributes *attributes = &pipe_ctx->stream->cursor_attributes;
2935 if (pipe_ctx->plane_res.ipp &&
2936 pipe_ctx->plane_res.ipp->funcs->ipp_cursor_set_attributes)
2937 pipe_ctx->plane_res.ipp->funcs->ipp_cursor_set_attributes(
2938 pipe_ctx->plane_res.ipp, attributes);
2940 if (pipe_ctx->plane_res.mi &&
2941 pipe_ctx->plane_res.mi->funcs->set_cursor_attributes)
2942 pipe_ctx->plane_res.mi->funcs->set_cursor_attributes(
2943 pipe_ctx->plane_res.mi, attributes);
2945 if (pipe_ctx->plane_res.xfm &&
2946 pipe_ctx->plane_res.xfm->funcs->set_cursor_attributes)
2947 pipe_ctx->plane_res.xfm->funcs->set_cursor_attributes(
2948 pipe_ctx->plane_res.xfm, attributes);
2951 bool dce110_set_backlight_level(struct pipe_ctx *pipe_ctx,
2952 uint32_t backlight_pwm_u16_16,
2953 uint32_t frame_ramp)
2955 struct dc_link *link = pipe_ctx->stream->link;
2956 struct dc *dc = link->ctx->dc;
2957 struct abm *abm = pipe_ctx->stream_res.abm;
2958 struct panel_cntl *panel_cntl = link->panel_cntl;
2959 struct dmcu *dmcu = dc->res_pool->dmcu;
2960 bool fw_set_brightness = true;
2961 /* DMCU -1 for all controller id values,
2964 uint32_t controller_id = pipe_ctx->stream_res.tg->inst + 1;
2966 if (abm == NULL || panel_cntl == NULL || (abm->funcs->set_backlight_level_pwm == NULL))
2970 fw_set_brightness = dmcu->funcs->is_dmcu_initialized(dmcu);
2972 if (!fw_set_brightness && panel_cntl->funcs->driver_set_backlight)
2973 panel_cntl->funcs->driver_set_backlight(panel_cntl, backlight_pwm_u16_16);
2975 abm->funcs->set_backlight_level_pwm(
2977 backlight_pwm_u16_16,
2980 link->panel_cntl->inst);
2985 void dce110_set_abm_immediate_disable(struct pipe_ctx *pipe_ctx)
2987 struct abm *abm = pipe_ctx->stream_res.abm;
2988 struct panel_cntl *panel_cntl = pipe_ctx->stream->link->panel_cntl;
2991 abm->funcs->set_abm_immediate_disable(abm,
2992 pipe_ctx->stream->link->panel_cntl->inst);
2995 panel_cntl->funcs->store_backlight_level(panel_cntl);
2998 void dce110_set_pipe(struct pipe_ctx *pipe_ctx)
3000 struct abm *abm = pipe_ctx->stream_res.abm;
3001 struct panel_cntl *panel_cntl = pipe_ctx->stream->link->panel_cntl;
3002 uint32_t otg_inst = pipe_ctx->stream_res.tg->inst + 1;
3004 if (abm && panel_cntl)
3005 abm->funcs->set_pipe(abm, otg_inst, panel_cntl->inst);
3008 void dce110_enable_lvds_link_output(struct dc_link *link,
3009 const struct link_resource *link_res,
3010 enum clock_source_id clock_source,
3011 uint32_t pixel_clock)
3013 link->link_enc->funcs->enable_lvds_output(
3017 link->phy_state.symclk_state = SYMCLK_ON_TX_ON;
3020 void dce110_enable_tmds_link_output(struct dc_link *link,
3021 const struct link_resource *link_res,
3022 enum signal_type signal,
3023 enum clock_source_id clock_source,
3024 enum dc_color_depth color_depth,
3025 uint32_t pixel_clock)
3027 link->link_enc->funcs->enable_tmds_output(
3033 link->phy_state.symclk_state = SYMCLK_ON_TX_ON;
3036 void dce110_enable_dp_link_output(
3037 struct dc_link *link,
3038 const struct link_resource *link_res,
3039 enum signal_type signal,
3040 enum clock_source_id clock_source,
3041 const struct dc_link_settings *link_settings)
3043 struct dc *dc = link->ctx->dc;
3044 struct dmcu *dmcu = dc->res_pool->dmcu;
3045 struct pipe_ctx *pipes =
3046 link->dc->current_state->res_ctx.pipe_ctx;
3047 struct clock_source *dp_cs =
3048 link->dc->res_pool->dp_clock_source;
3049 const struct link_hwss *link_hwss = get_link_hwss(link, link_res);
3053 * Add the logic to extract BOTH power up and power down sequences
3054 * from enable/disable link output and only call edp panel control
3055 * in enable_link_dp and disable_link_dp once.
3057 if (link->connector_signal == SIGNAL_TYPE_EDP) {
3058 link->dc->hwss.edp_wait_for_hpd_ready(link, true);
3061 /* If the current pixel clock source is not DTO(happens after
3062 * switching from HDMI passive dongle to DP on the same connector),
3063 * switch the pixel clock source to DTO.
3066 for (i = 0; i < MAX_PIPES; i++) {
3067 if (pipes[i].stream != NULL &&
3068 pipes[i].stream->link == link) {
3069 if (pipes[i].clock_source != NULL &&
3070 pipes[i].clock_source->id != CLOCK_SOURCE_ID_DP_DTO) {
3071 pipes[i].clock_source = dp_cs;
3072 pipes[i].stream_res.pix_clk_params.requested_pix_clk_100hz =
3073 pipes[i].stream->timing.pix_clk_100hz;
3074 pipes[i].clock_source->funcs->program_pix_clk(
3075 pipes[i].clock_source,
3076 &pipes[i].stream_res.pix_clk_params,
3077 dc->link_srv->dp_get_encoding_format(link_settings),
3078 &pipes[i].pll_settings);
3083 if (dc->link_srv->dp_get_encoding_format(link_settings) == DP_8b_10b_ENCODING) {
3084 if (dc->clk_mgr->funcs->notify_link_rate_change)
3085 dc->clk_mgr->funcs->notify_link_rate_change(dc->clk_mgr, link);
3088 if (dmcu != NULL && dmcu->funcs->lock_phy)
3089 dmcu->funcs->lock_phy(dmcu);
3091 if (link_hwss->ext.enable_dp_link_output)
3092 link_hwss->ext.enable_dp_link_output(link, link_res, signal,
3093 clock_source, link_settings);
3095 link->phy_state.symclk_state = SYMCLK_ON_TX_ON;
3097 if (dmcu != NULL && dmcu->funcs->unlock_phy)
3098 dmcu->funcs->unlock_phy(dmcu);
3100 dc->link_srv->dp_trace_source_sequence(link, DPCD_SOURCE_SEQ_AFTER_ENABLE_LINK_PHY);
3103 void dce110_disable_link_output(struct dc_link *link,
3104 const struct link_resource *link_res,
3105 enum signal_type signal)
3107 struct dc *dc = link->ctx->dc;
3108 const struct link_hwss *link_hwss = get_link_hwss(link, link_res);
3109 struct dmcu *dmcu = dc->res_pool->dmcu;
3111 if (signal == SIGNAL_TYPE_EDP &&
3112 link->dc->hwss.edp_backlight_control)
3113 link->dc->hwss.edp_backlight_control(link, false);
3114 else if (dmcu != NULL && dmcu->funcs->lock_phy)
3115 dmcu->funcs->lock_phy(dmcu);
3117 link_hwss->disable_link_output(link, link_res, signal);
3118 link->phy_state.symclk_state = SYMCLK_OFF_TX_OFF;
3120 * Add the logic to extract BOTH power up and power down sequences
3121 * from enable/disable link output and only call edp panel control
3122 * in enable_link_dp and disable_link_dp once.
3124 if (dmcu != NULL && dmcu->funcs->lock_phy)
3125 dmcu->funcs->unlock_phy(dmcu);
3126 dc->link_srv->dp_trace_source_sequence(link, DPCD_SOURCE_SEQ_AFTER_DISABLE_LINK_PHY);
3129 static const struct hw_sequencer_funcs dce110_funcs = {
3130 .program_gamut_remap = program_gamut_remap,
3131 .program_output_csc = program_output_csc,
3133 .apply_ctx_to_hw = dce110_apply_ctx_to_hw,
3134 .apply_ctx_for_surface = dce110_apply_ctx_for_surface,
3135 .post_unlock_program_front_end = dce110_post_unlock_program_front_end,
3136 .update_plane_addr = update_plane_addr,
3137 .update_pending_status = dce110_update_pending_status,
3138 .enable_accelerated_mode = dce110_enable_accelerated_mode,
3139 .enable_timing_synchronization = dce110_enable_timing_synchronization,
3140 .enable_per_frame_crtc_position_reset = dce110_enable_per_frame_crtc_position_reset,
3141 .update_info_frame = dce110_update_info_frame,
3142 .enable_stream = dce110_enable_stream,
3143 .disable_stream = dce110_disable_stream,
3144 .unblank_stream = dce110_unblank_stream,
3145 .blank_stream = dce110_blank_stream,
3146 .enable_audio_stream = dce110_enable_audio_stream,
3147 .disable_audio_stream = dce110_disable_audio_stream,
3148 .disable_plane = dce110_power_down_fe,
3149 .pipe_control_lock = dce_pipe_control_lock,
3150 .interdependent_update_lock = NULL,
3151 .cursor_lock = dce_pipe_control_lock,
3152 .prepare_bandwidth = dce110_prepare_bandwidth,
3153 .optimize_bandwidth = dce110_optimize_bandwidth,
3155 .get_position = get_position,
3156 .set_static_screen_control = set_static_screen_control,
3157 .setup_stereo = NULL,
3158 .set_avmute = dce110_set_avmute,
3159 .wait_for_mpcc_disconnect = dce110_wait_for_mpcc_disconnect,
3160 .edp_backlight_control = dce110_edp_backlight_control,
3161 .edp_power_control = dce110_edp_power_control,
3162 .edp_wait_for_hpd_ready = dce110_edp_wait_for_hpd_ready,
3163 .set_cursor_position = dce110_set_cursor_position,
3164 .set_cursor_attribute = dce110_set_cursor_attribute,
3165 .set_backlight_level = dce110_set_backlight_level,
3166 .set_abm_immediate_disable = dce110_set_abm_immediate_disable,
3167 .set_pipe = dce110_set_pipe,
3168 .enable_lvds_link_output = dce110_enable_lvds_link_output,
3169 .enable_tmds_link_output = dce110_enable_tmds_link_output,
3170 .enable_dp_link_output = dce110_enable_dp_link_output,
3171 .disable_link_output = dce110_disable_link_output,
3174 static const struct hwseq_private_funcs dce110_private_funcs = {
3175 .init_pipes = init_pipes,
3176 .update_plane_addr = update_plane_addr,
3177 .set_input_transfer_func = dce110_set_input_transfer_func,
3178 .set_output_transfer_func = dce110_set_output_transfer_func,
3179 .power_down = dce110_power_down,
3180 .enable_display_pipe_clock_gating = enable_display_pipe_clock_gating,
3181 .enable_display_power_gating = dce110_enable_display_power_gating,
3182 .reset_hw_ctx_wrap = dce110_reset_hw_ctx_wrap,
3183 .enable_stream_timing = dce110_enable_stream_timing,
3184 .disable_stream_gating = NULL,
3185 .enable_stream_gating = NULL,
3186 .edp_backlight_control = dce110_edp_backlight_control,
3189 void dce110_hw_sequencer_construct(struct dc *dc)
3191 dc->hwss = dce110_funcs;
3192 dc->hwseq->funcs = dce110_private_funcs;