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 <linux/delay.h>
28 #include "dm_services.h"
30 #include "dc_bios_types.h"
31 #include "core_types.h"
32 #include "core_status.h"
34 #include "dm_helpers.h"
35 #include "dce110_timing_generator.h"
36 #include "dce/dce_hwseq.h"
37 #include "gpio_service_interface.h"
39 #include "dce110_compressor.h"
41 #include "bios/bios_parser_helper.h"
42 #include "timing_generator.h"
43 #include "mem_input.h"
46 #include "transform.h"
47 #include "stream_encoder.h"
48 #include "link_encoder.h"
49 #include "link_enc_cfg.h"
50 #include "link_hwss.h"
51 #include "dc_link_dp.h"
52 #if defined(CONFIG_DRM_AMD_DC_DCN)
55 #include "clock_source.h"
59 #include "reg_helper.h"
60 #include "panel_cntl.h"
61 #include "inc/link_dpcd.h"
62 #include "dpcd_defs.h"
63 /* include DCE11 register header files */
64 #include "dce/dce_11_0_d.h"
65 #include "dce/dce_11_0_sh_mask.h"
66 #include "custom_float.h"
68 #include "atomfirmware.h"
70 #include "dcn10/dcn10_hw_sequencer.h"
72 #include "dce110_hw_sequencer.h"
74 #define GAMMA_HW_POINTS_NUM 256
77 * All values are in milliseconds;
78 * For eDP, after power-up/power/down,
79 * 300/500 msec max. delay from LCDVCC to black video generation
81 #define PANEL_POWER_UP_TIMEOUT 300
82 #define PANEL_POWER_DOWN_TIMEOUT 500
83 #define HPD_CHECK_INTERVAL 10
84 #define OLED_POST_T7_DELAY 100
85 #define OLED_PRE_T11_DELAY 150
90 #define DC_LOGGER_INIT()
96 #define FN(reg_name, field_name) \
97 hws->shifts->field_name, hws->masks->field_name
99 struct dce110_hw_seq_reg_offsets {
103 static const struct dce110_hw_seq_reg_offsets reg_offsets[] = {
105 .crtc = (mmCRTC0_CRTC_GSL_CONTROL - mmCRTC_GSL_CONTROL),
108 .crtc = (mmCRTC1_CRTC_GSL_CONTROL - mmCRTC_GSL_CONTROL),
111 .crtc = (mmCRTC2_CRTC_GSL_CONTROL - mmCRTC_GSL_CONTROL),
114 .crtc = (mmCRTCV_GSL_CONTROL - mmCRTC_GSL_CONTROL),
118 #define HW_REG_BLND(reg, id)\
119 (reg + reg_offsets[id].blnd)
121 #define HW_REG_CRTC(reg, id)\
122 (reg + reg_offsets[id].crtc)
124 #define MAX_WATERMARK 0xFFFF
125 #define SAFE_NBP_MARK 0x7FFF
127 /*******************************************************************************
128 * Private definitions
129 ******************************************************************************/
130 /***************************PIPE_CONTROL***********************************/
131 static void dce110_init_pte(struct dc_context *ctx)
135 uint32_t chunk_int = 0;
136 uint32_t chunk_mul = 0;
138 addr = mmUNP_DVMM_PTE_CONTROL;
139 value = dm_read_reg(ctx, addr);
145 DVMM_USE_SINGLE_PTE);
151 DVMM_PTE_BUFFER_MODE0);
157 DVMM_PTE_BUFFER_MODE1);
159 dm_write_reg(ctx, addr, value);
161 addr = mmDVMM_PTE_REQ;
162 value = dm_read_reg(ctx, addr);
164 chunk_int = get_reg_field_value(
167 HFLIP_PTEREQ_PER_CHUNK_INT);
169 chunk_mul = get_reg_field_value(
172 HFLIP_PTEREQ_PER_CHUNK_MULTIPLIER);
174 if (chunk_int != 0x4 || chunk_mul != 0x4) {
180 MAX_PTEREQ_TO_ISSUE);
186 HFLIP_PTEREQ_PER_CHUNK_INT);
192 HFLIP_PTEREQ_PER_CHUNK_MULTIPLIER);
194 dm_write_reg(ctx, addr, value);
197 /**************************************************************************/
199 static void enable_display_pipe_clock_gating(
200 struct dc_context *ctx,
206 static bool dce110_enable_display_power_gating(
208 uint8_t controller_id,
210 enum pipe_gating_control power_gating)
212 enum bp_result bp_result = BP_RESULT_OK;
213 enum bp_pipe_control_action cntl;
214 struct dc_context *ctx = dc->ctx;
215 unsigned int underlay_idx = dc->res_pool->underlay_pipe_index;
217 if (IS_FPGA_MAXIMUS_DC(ctx->dce_environment))
220 if (power_gating == PIPE_GATING_CONTROL_INIT)
221 cntl = ASIC_PIPE_INIT;
222 else if (power_gating == PIPE_GATING_CONTROL_ENABLE)
223 cntl = ASIC_PIPE_ENABLE;
225 cntl = ASIC_PIPE_DISABLE;
227 if (controller_id == underlay_idx)
228 controller_id = CONTROLLER_ID_UNDERLAY0 - 1;
230 if (power_gating != PIPE_GATING_CONTROL_INIT || controller_id == 0){
232 bp_result = dcb->funcs->enable_disp_power_gating(
233 dcb, controller_id + 1, cntl);
235 /* Revert MASTER_UPDATE_MODE to 0 because bios sets it 2
236 * by default when command table is called
238 * Bios parser accepts controller_id = 6 as indicative of
239 * underlay pipe in dce110. But we do not support more
242 if (controller_id < CONTROLLER_ID_MAX - 1)
244 HW_REG_CRTC(mmCRTC_MASTER_UPDATE_MODE, controller_id),
248 if (power_gating != PIPE_GATING_CONTROL_ENABLE)
249 dce110_init_pte(ctx);
251 if (bp_result == BP_RESULT_OK)
257 static void build_prescale_params(struct ipp_prescale_params *prescale_params,
258 const struct dc_plane_state *plane_state)
260 prescale_params->mode = IPP_PRESCALE_MODE_FIXED_UNSIGNED;
262 switch (plane_state->format) {
263 case SURFACE_PIXEL_FORMAT_GRPH_RGB565:
264 prescale_params->scale = 0x2082;
266 case SURFACE_PIXEL_FORMAT_GRPH_ARGB8888:
267 case SURFACE_PIXEL_FORMAT_GRPH_ABGR8888:
268 prescale_params->scale = 0x2020;
270 case SURFACE_PIXEL_FORMAT_GRPH_ARGB2101010:
271 case SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010:
272 prescale_params->scale = 0x2008;
274 case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616:
275 case SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616:
276 case SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616F:
277 prescale_params->scale = 0x2000;
286 dce110_set_input_transfer_func(struct dc *dc, struct pipe_ctx *pipe_ctx,
287 const struct dc_plane_state *plane_state)
289 struct input_pixel_processor *ipp = pipe_ctx->plane_res.ipp;
290 const struct dc_transfer_func *tf = NULL;
291 struct ipp_prescale_params prescale_params = { 0 };
297 if (plane_state->in_transfer_func)
298 tf = plane_state->in_transfer_func;
300 build_prescale_params(&prescale_params, plane_state);
301 ipp->funcs->ipp_program_prescale(ipp, &prescale_params);
303 if (plane_state->gamma_correction &&
304 !plane_state->gamma_correction->is_identity &&
305 dce_use_lut(plane_state->format))
306 ipp->funcs->ipp_program_input_lut(ipp, plane_state->gamma_correction);
309 /* Default case if no input transfer function specified */
310 ipp->funcs->ipp_set_degamma(ipp, IPP_DEGAMMA_MODE_HW_sRGB);
311 } else if (tf->type == TF_TYPE_PREDEFINED) {
313 case TRANSFER_FUNCTION_SRGB:
314 ipp->funcs->ipp_set_degamma(ipp, IPP_DEGAMMA_MODE_HW_sRGB);
316 case TRANSFER_FUNCTION_BT709:
317 ipp->funcs->ipp_set_degamma(ipp, IPP_DEGAMMA_MODE_HW_xvYCC);
319 case TRANSFER_FUNCTION_LINEAR:
320 ipp->funcs->ipp_set_degamma(ipp, IPP_DEGAMMA_MODE_BYPASS);
322 case TRANSFER_FUNCTION_PQ:
327 } else if (tf->type == TF_TYPE_BYPASS) {
328 ipp->funcs->ipp_set_degamma(ipp, IPP_DEGAMMA_MODE_BYPASS);
330 /*TF_TYPE_DISTRIBUTED_POINTS - Not supported in DCE 11*/
337 static bool convert_to_custom_float(struct pwl_result_data *rgb_resulted,
338 struct curve_points *arr_points,
339 uint32_t hw_points_num)
341 struct custom_float_format fmt;
343 struct pwl_result_data *rgb = rgb_resulted;
347 fmt.exponenta_bits = 6;
348 fmt.mantissa_bits = 12;
351 if (!convert_to_custom_float_format(arr_points[0].x, &fmt,
352 &arr_points[0].custom_float_x)) {
357 if (!convert_to_custom_float_format(arr_points[0].offset, &fmt,
358 &arr_points[0].custom_float_offset)) {
363 if (!convert_to_custom_float_format(arr_points[0].slope, &fmt,
364 &arr_points[0].custom_float_slope)) {
369 fmt.mantissa_bits = 10;
372 if (!convert_to_custom_float_format(arr_points[1].x, &fmt,
373 &arr_points[1].custom_float_x)) {
378 if (!convert_to_custom_float_format(arr_points[1].y, &fmt,
379 &arr_points[1].custom_float_y)) {
384 if (!convert_to_custom_float_format(arr_points[1].slope, &fmt,
385 &arr_points[1].custom_float_slope)) {
390 fmt.mantissa_bits = 12;
393 while (i != hw_points_num) {
394 if (!convert_to_custom_float_format(rgb->red, &fmt,
400 if (!convert_to_custom_float_format(rgb->green, &fmt,
406 if (!convert_to_custom_float_format(rgb->blue, &fmt,
412 if (!convert_to_custom_float_format(rgb->delta_red, &fmt,
413 &rgb->delta_red_reg)) {
418 if (!convert_to_custom_float_format(rgb->delta_green, &fmt,
419 &rgb->delta_green_reg)) {
424 if (!convert_to_custom_float_format(rgb->delta_blue, &fmt,
425 &rgb->delta_blue_reg)) {
437 #define MAX_LOW_POINT 25
438 #define NUMBER_REGIONS 16
439 #define NUMBER_SW_SEGMENTS 16
442 dce110_translate_regamma_to_hw_format(const struct dc_transfer_func *output_tf,
443 struct pwl_params *regamma_params)
445 struct curve_points *arr_points;
446 struct pwl_result_data *rgb_resulted;
447 struct pwl_result_data *rgb;
448 struct pwl_result_data *rgb_plus_1;
449 struct fixed31_32 y_r;
450 struct fixed31_32 y_g;
451 struct fixed31_32 y_b;
452 struct fixed31_32 y1_min;
453 struct fixed31_32 y3_max;
455 int32_t region_start, region_end;
456 uint32_t i, j, k, seg_distr[NUMBER_REGIONS], increment, start_index, hw_points;
458 if (output_tf == NULL || regamma_params == NULL || output_tf->type == TF_TYPE_BYPASS)
461 arr_points = regamma_params->arr_points;
462 rgb_resulted = regamma_params->rgb_resulted;
465 memset(regamma_params, 0, sizeof(struct pwl_params));
467 if (output_tf->tf == TRANSFER_FUNCTION_PQ) {
469 * segments are from 2^-11 to 2^5
472 region_end = region_start + NUMBER_REGIONS;
474 for (i = 0; i < NUMBER_REGIONS; i++)
479 * segment is from 2^-10 to 2^1
480 * We include an extra segment for range [2^0, 2^1). This is to
481 * ensure that colors with normalized values of 1 don't miss the
505 for (k = 0; k < 16; k++) {
506 if (seg_distr[k] != -1)
507 hw_points += (1 << seg_distr[k]);
511 for (k = 0; k < (region_end - region_start); k++) {
512 increment = NUMBER_SW_SEGMENTS / (1 << seg_distr[k]);
513 start_index = (region_start + k + MAX_LOW_POINT) *
515 for (i = start_index; i < start_index + NUMBER_SW_SEGMENTS;
517 if (j == hw_points - 1)
519 rgb_resulted[j].red = output_tf->tf_pts.red[i];
520 rgb_resulted[j].green = output_tf->tf_pts.green[i];
521 rgb_resulted[j].blue = output_tf->tf_pts.blue[i];
527 start_index = (region_end + MAX_LOW_POINT) * NUMBER_SW_SEGMENTS;
528 rgb_resulted[hw_points - 1].red = output_tf->tf_pts.red[start_index];
529 rgb_resulted[hw_points - 1].green = output_tf->tf_pts.green[start_index];
530 rgb_resulted[hw_points - 1].blue = output_tf->tf_pts.blue[start_index];
532 arr_points[0].x = dc_fixpt_pow(dc_fixpt_from_int(2),
533 dc_fixpt_from_int(region_start));
534 arr_points[1].x = dc_fixpt_pow(dc_fixpt_from_int(2),
535 dc_fixpt_from_int(region_end));
537 y_r = rgb_resulted[0].red;
538 y_g = rgb_resulted[0].green;
539 y_b = rgb_resulted[0].blue;
541 y1_min = dc_fixpt_min(y_r, dc_fixpt_min(y_g, y_b));
543 arr_points[0].y = y1_min;
544 arr_points[0].slope = dc_fixpt_div(arr_points[0].y,
547 y_r = rgb_resulted[hw_points - 1].red;
548 y_g = rgb_resulted[hw_points - 1].green;
549 y_b = rgb_resulted[hw_points - 1].blue;
551 /* see comment above, m_arrPoints[1].y should be the Y value for the
552 * region end (m_numOfHwPoints), not last HW point(m_numOfHwPoints - 1)
554 y3_max = dc_fixpt_max(y_r, dc_fixpt_max(y_g, y_b));
556 arr_points[1].y = y3_max;
558 arr_points[1].slope = dc_fixpt_zero;
560 if (output_tf->tf == TRANSFER_FUNCTION_PQ) {
561 /* for PQ, we want to have a straight line from last HW X point,
562 * and the slope to be such that we hit 1.0 at 10000 nits.
564 const struct fixed31_32 end_value = dc_fixpt_from_int(125);
566 arr_points[1].slope = dc_fixpt_div(
567 dc_fixpt_sub(dc_fixpt_one, arr_points[1].y),
568 dc_fixpt_sub(end_value, arr_points[1].x));
571 regamma_params->hw_points_num = hw_points;
574 for (i = 1; i < 16; i++) {
575 if (seg_distr[k] != -1) {
576 regamma_params->arr_curve_points[k].segments_num = seg_distr[k];
577 regamma_params->arr_curve_points[i].offset =
578 regamma_params->arr_curve_points[k].offset + (1 << seg_distr[k]);
583 if (seg_distr[k] != -1)
584 regamma_params->arr_curve_points[k].segments_num = seg_distr[k];
587 rgb_plus_1 = rgb_resulted + 1;
591 while (i != hw_points + 1) {
592 if (dc_fixpt_lt(rgb_plus_1->red, rgb->red))
593 rgb_plus_1->red = rgb->red;
594 if (dc_fixpt_lt(rgb_plus_1->green, rgb->green))
595 rgb_plus_1->green = rgb->green;
596 if (dc_fixpt_lt(rgb_plus_1->blue, rgb->blue))
597 rgb_plus_1->blue = rgb->blue;
599 rgb->delta_red = dc_fixpt_sub(rgb_plus_1->red, rgb->red);
600 rgb->delta_green = dc_fixpt_sub(rgb_plus_1->green, rgb->green);
601 rgb->delta_blue = dc_fixpt_sub(rgb_plus_1->blue, rgb->blue);
608 convert_to_custom_float(rgb_resulted, arr_points, hw_points);
614 dce110_set_output_transfer_func(struct dc *dc, struct pipe_ctx *pipe_ctx,
615 const struct dc_stream_state *stream)
617 struct transform *xfm = pipe_ctx->plane_res.xfm;
619 xfm->funcs->opp_power_on_regamma_lut(xfm, true);
620 xfm->regamma_params.hw_points_num = GAMMA_HW_POINTS_NUM;
622 if (stream->out_transfer_func &&
623 stream->out_transfer_func->type == TF_TYPE_PREDEFINED &&
624 stream->out_transfer_func->tf == TRANSFER_FUNCTION_SRGB) {
625 xfm->funcs->opp_set_regamma_mode(xfm, OPP_REGAMMA_SRGB);
626 } else if (dce110_translate_regamma_to_hw_format(stream->out_transfer_func,
627 &xfm->regamma_params)) {
628 xfm->funcs->opp_program_regamma_pwl(xfm, &xfm->regamma_params);
629 xfm->funcs->opp_set_regamma_mode(xfm, OPP_REGAMMA_USER);
631 xfm->funcs->opp_set_regamma_mode(xfm, OPP_REGAMMA_BYPASS);
634 xfm->funcs->opp_power_on_regamma_lut(xfm, false);
639 void dce110_update_info_frame(struct pipe_ctx *pipe_ctx)
644 ASSERT(pipe_ctx->stream);
646 if (pipe_ctx->stream_res.stream_enc == NULL)
647 return; /* this is not root pipe */
649 is_hdmi_tmds = dc_is_hdmi_tmds_signal(pipe_ctx->stream->signal);
650 is_dp = dc_is_dp_signal(pipe_ctx->stream->signal);
652 if (!is_hdmi_tmds && !is_dp)
656 pipe_ctx->stream_res.stream_enc->funcs->update_hdmi_info_packets(
657 pipe_ctx->stream_res.stream_enc,
658 &pipe_ctx->stream_res.encoder_info_frame);
660 pipe_ctx->stream_res.stream_enc->funcs->update_dp_info_packets(
661 pipe_ctx->stream_res.stream_enc,
662 &pipe_ctx->stream_res.encoder_info_frame);
665 void dce110_enable_stream(struct pipe_ctx *pipe_ctx)
667 enum dc_lane_count lane_count =
668 pipe_ctx->stream->link->cur_link_settings.lane_count;
669 struct dc_crtc_timing *timing = &pipe_ctx->stream->timing;
670 struct dc_link *link = pipe_ctx->stream->link;
671 const struct dc *dc = link->dc;
673 uint32_t active_total_with_borders;
674 uint32_t early_control = 0;
675 struct timing_generator *tg = pipe_ctx->stream_res.tg;
677 /* For MST, there are multiply stream go to only one link.
678 * connect DIG back_end to front_end while enable_stream and
679 * disconnect them during disable_stream
680 * BY this, it is logic clean to separate stream and link */
681 link->link_enc->funcs->connect_dig_be_to_fe(link->link_enc,
682 pipe_ctx->stream_res.stream_enc->id, true);
684 dc->hwss.update_info_frame(pipe_ctx);
686 /* enable early control to avoid corruption on DP monitor*/
687 active_total_with_borders =
688 timing->h_addressable
689 + timing->h_border_left
690 + timing->h_border_right;
693 early_control = active_total_with_borders % lane_count;
695 if (early_control == 0)
696 early_control = lane_count;
698 tg->funcs->set_early_control(tg, early_control);
700 /* enable audio only within mode set */
701 if (pipe_ctx->stream_res.audio != NULL) {
702 if (dc_is_dp_signal(pipe_ctx->stream->signal))
703 pipe_ctx->stream_res.stream_enc->funcs->dp_audio_enable(pipe_ctx->stream_res.stream_enc);
711 static enum bp_result link_transmitter_control(
712 struct dc_bios *bios,
713 struct bp_transmitter_control *cntl)
715 enum bp_result result;
717 result = bios->funcs->transmitter_control(bios, cntl);
726 void dce110_edp_wait_for_hpd_ready(
727 struct dc_link *link,
730 struct dc_context *ctx = link->ctx;
731 struct graphics_object_id connector = link->link_enc->connector;
733 struct dc_sink *sink = link->local_sink;
734 bool edp_hpd_high = false;
735 uint32_t time_elapsed = 0;
736 uint32_t timeout = power_up ?
737 PANEL_POWER_UP_TIMEOUT : PANEL_POWER_DOWN_TIMEOUT;
739 if (dal_graphics_object_id_get_connector_id(connector)
740 != CONNECTOR_ID_EDP) {
747 * From KV, we will not HPD low after turning off VCC -
748 * instead, we will check the SW timer in power_up().
753 * When we power on/off the eDP panel,
754 * we need to wait until SENSE bit is high/low.
758 /* TODO what to do with this? */
759 hpd = get_hpd_gpio(ctx->dc_bios, connector, ctx->gpio_service);
767 if (sink->edid_caps.panel_patch.extra_t3_ms > 0) {
768 int extra_t3_in_ms = sink->edid_caps.panel_patch.extra_t3_ms;
770 msleep(extra_t3_in_ms);
774 dal_gpio_open(hpd, GPIO_MODE_INTERRUPT);
776 /* wait until timeout or panel detected */
779 uint32_t detected = 0;
781 dal_gpio_get_value(hpd, &detected);
783 if (!(detected ^ power_up)) {
788 msleep(HPD_CHECK_INTERVAL);
790 time_elapsed += HPD_CHECK_INTERVAL;
791 } while (time_elapsed < timeout);
795 dal_gpio_destroy_irq(&hpd);
797 if (false == edp_hpd_high) {
799 "%s: wait timed out!\n", __func__);
803 void dce110_edp_power_control(
804 struct dc_link *link,
807 struct dc_context *ctx = link->ctx;
808 struct bp_transmitter_control cntl = { 0 };
809 enum bp_result bp_result;
810 uint8_t panel_instance;
813 if (dal_graphics_object_id_get_connector_id(link->link_enc->connector)
814 != CONNECTOR_ID_EDP) {
819 if (!link->panel_cntl)
822 link->panel_cntl->funcs->is_panel_powered_on(link->panel_cntl)) {
824 unsigned long long current_ts = dm_get_timestamp(ctx);
825 unsigned long long time_since_edp_poweroff_ms =
826 div64_u64(dm_get_elapse_time_in_ns(
829 link->link_trace.time_stamp.edp_poweroff), 1000000);
830 unsigned long long time_since_edp_poweron_ms =
831 div64_u64(dm_get_elapse_time_in_ns(
834 link->link_trace.time_stamp.edp_poweron), 1000000);
836 "%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",
840 link->link_trace.time_stamp.edp_poweroff,
841 link->link_trace.time_stamp.edp_poweron,
842 time_since_edp_poweroff_ms,
843 time_since_edp_poweron_ms);
845 /* Send VBIOS command to prompt eDP panel power */
847 /* edp requires a min of 500ms from LCDVDD off to on */
848 unsigned long long remaining_min_edp_poweroff_time_ms = 500;
850 /* add time defined by a patch, if any (usually patch extra_t12_ms is 0) */
851 if (link->local_sink != NULL)
852 remaining_min_edp_poweroff_time_ms +=
853 link->local_sink->edid_caps.panel_patch.extra_t12_ms;
855 /* Adjust remaining_min_edp_poweroff_time_ms if this is not the first time. */
856 if (link->link_trace.time_stamp.edp_poweroff != 0) {
857 if (time_since_edp_poweroff_ms < remaining_min_edp_poweroff_time_ms)
858 remaining_min_edp_poweroff_time_ms =
859 remaining_min_edp_poweroff_time_ms - time_since_edp_poweroff_ms;
861 remaining_min_edp_poweroff_time_ms = 0;
864 if (remaining_min_edp_poweroff_time_ms) {
866 "%s: remaining_min_edp_poweroff_time_ms=%llu: begin wait.\n",
867 __func__, remaining_min_edp_poweroff_time_ms);
868 msleep(remaining_min_edp_poweroff_time_ms);
870 "%s: remaining_min_edp_poweroff_time_ms=%llu: end wait.\n",
871 __func__, remaining_min_edp_poweroff_time_ms);
872 dm_output_to_console("%s: wait %lld ms to power on eDP.\n",
873 __func__, remaining_min_edp_poweroff_time_ms);
876 "%s: remaining_min_edp_poweroff_time_ms=%llu: no wait required.\n",
877 __func__, remaining_min_edp_poweroff_time_ms);
882 "%s: BEGIN: Panel Power action: %s\n",
883 __func__, (power_up ? "On":"Off"));
885 cntl.action = power_up ?
886 TRANSMITTER_CONTROL_POWER_ON :
887 TRANSMITTER_CONTROL_POWER_OFF;
888 cntl.transmitter = link->link_enc->transmitter;
889 cntl.connector_obj_id = link->link_enc->connector;
890 cntl.coherent = false;
891 cntl.lanes_number = LANE_COUNT_FOUR;
892 cntl.hpd_sel = link->link_enc->hpd_source;
893 panel_instance = link->panel_cntl->inst;
895 if (ctx->dc->ctx->dmub_srv &&
896 ctx->dc->debug.dmub_command_table) {
897 if (cntl.action == TRANSMITTER_CONTROL_POWER_ON)
898 bp_result = ctx->dc_bios->funcs->enable_lvtma_control(ctx->dc_bios,
899 LVTMA_CONTROL_POWER_ON,
902 bp_result = ctx->dc_bios->funcs->enable_lvtma_control(ctx->dc_bios,
903 LVTMA_CONTROL_POWER_OFF,
907 bp_result = link_transmitter_control(ctx->dc_bios, &cntl);
910 "%s: END: Panel Power action: %s bp_result=%u\n",
911 __func__, (power_up ? "On":"Off"),
915 /*save driver power off time stamp*/
916 link->link_trace.time_stamp.edp_poweroff = dm_get_timestamp(ctx);
918 link->link_trace.time_stamp.edp_poweron = dm_get_timestamp(ctx);
921 "%s: updated values: edp_poweroff=%llu edp_poweron=%llu\n",
923 link->link_trace.time_stamp.edp_poweroff,
924 link->link_trace.time_stamp.edp_poweron);
926 if (bp_result != BP_RESULT_OK)
928 "%s: Panel Power bp_result: %d\n",
929 __func__, bp_result);
932 "%s: Skipping Panel Power action: %s\n",
933 __func__, (power_up ? "On":"Off"));
937 void dce110_edp_wait_for_T12(
938 struct dc_link *link)
940 struct dc_context *ctx = link->ctx;
942 if (dal_graphics_object_id_get_connector_id(link->link_enc->connector)
943 != CONNECTOR_ID_EDP) {
948 if (!link->panel_cntl)
951 if (!link->panel_cntl->funcs->is_panel_powered_on(link->panel_cntl) &&
952 link->link_trace.time_stamp.edp_poweroff != 0) {
953 unsigned int t12_duration = 500; // Default T12 as per spec
954 unsigned long long current_ts = dm_get_timestamp(ctx);
955 unsigned long long time_since_edp_poweroff_ms =
956 div64_u64(dm_get_elapse_time_in_ns(
959 link->link_trace.time_stamp.edp_poweroff), 1000000);
961 t12_duration += link->local_sink->edid_caps.panel_patch.extra_t12_ms; // Add extra T12
963 if (time_since_edp_poweroff_ms < t12_duration)
964 msleep(t12_duration - time_since_edp_poweroff_ms);
968 /*todo: cloned in stream enc, fix*/
971 * eDP only. Control the backlight of the eDP panel
973 void dce110_edp_backlight_control(
974 struct dc_link *link,
977 struct dc_context *ctx = link->ctx;
978 struct bp_transmitter_control cntl = { 0 };
979 uint8_t panel_instance;
981 if (dal_graphics_object_id_get_connector_id(link->link_enc->connector)
982 != CONNECTOR_ID_EDP) {
987 if (link->panel_cntl) {
988 bool is_backlight_on = link->panel_cntl->funcs->is_panel_backlight_on(link->panel_cntl);
990 if ((enable && is_backlight_on) || (!enable && !is_backlight_on)) {
992 "%s: panel already powered up/off. Do nothing.\n",
998 /* Send VBIOS command to control eDP panel backlight */
1000 DC_LOG_HW_RESUME_S3(
1001 "%s: backlight action: %s\n",
1002 __func__, (enable ? "On":"Off"));
1004 cntl.action = enable ?
1005 TRANSMITTER_CONTROL_BACKLIGHT_ON :
1006 TRANSMITTER_CONTROL_BACKLIGHT_OFF;
1008 /*cntl.engine_id = ctx->engine;*/
1009 cntl.transmitter = link->link_enc->transmitter;
1010 cntl.connector_obj_id = link->link_enc->connector;
1011 /*todo: unhardcode*/
1012 cntl.lanes_number = LANE_COUNT_FOUR;
1013 cntl.hpd_sel = link->link_enc->hpd_source;
1014 cntl.signal = SIGNAL_TYPE_EDP;
1016 /* For eDP, the following delays might need to be considered
1017 * after link training completed:
1018 * idle period - min. accounts for required BS-Idle pattern,
1019 * max. allows for source frame synchronization);
1020 * 50 msec max. delay from valid video data from source
1021 * to video on dislpay or backlight enable.
1023 * Disable the delay for now.
1024 * Enable it in the future if necessary.
1026 /* dc_service_sleep_in_milliseconds(50); */
1028 panel_instance = link->panel_cntl->inst;
1030 if (cntl.action == TRANSMITTER_CONTROL_BACKLIGHT_ON) {
1031 if (!link->dc->config.edp_no_power_sequencing)
1033 * Sometimes, DP receiver chip power-controlled externally by an
1034 * Embedded Controller could be treated and used as eDP,
1035 * if it drives mobile display. In this case,
1036 * we shouldn't be doing power-sequencing, hence we can skip
1037 * waiting for T7-ready.
1039 edp_receiver_ready_T7(link);
1041 DC_LOG_DC("edp_receiver_ready_T7 skipped\n");
1044 if (ctx->dc->ctx->dmub_srv &&
1045 ctx->dc->debug.dmub_command_table) {
1046 if (cntl.action == TRANSMITTER_CONTROL_BACKLIGHT_ON)
1047 ctx->dc_bios->funcs->enable_lvtma_control(ctx->dc_bios,
1048 LVTMA_CONTROL_LCD_BLON,
1051 ctx->dc_bios->funcs->enable_lvtma_control(ctx->dc_bios,
1052 LVTMA_CONTROL_LCD_BLOFF,
1056 link_transmitter_control(ctx->dc_bios, &cntl);
1058 if (enable && link->dpcd_sink_ext_caps.bits.oled)
1059 msleep(OLED_POST_T7_DELAY);
1061 if (link->dpcd_sink_ext_caps.bits.oled ||
1062 link->dpcd_sink_ext_caps.bits.hdr_aux_backlight_control == 1 ||
1063 link->dpcd_sink_ext_caps.bits.sdr_aux_backlight_control == 1)
1064 dc_link_backlight_enable_aux(link, enable);
1067 if (cntl.action == TRANSMITTER_CONTROL_BACKLIGHT_OFF) {
1068 if (!link->dc->config.edp_no_power_sequencing)
1070 * Sometimes, DP receiver chip power-controlled externally by an
1071 * Embedded Controller could be treated and used as eDP,
1072 * if it drives mobile display. In this case,
1073 * we shouldn't be doing power-sequencing, hence we can skip
1074 * waiting for T9-ready.
1076 edp_add_delay_for_T9(link);
1078 DC_LOG_DC("edp_receiver_ready_T9 skipped\n");
1081 if (!enable && link->dpcd_sink_ext_caps.bits.oled)
1082 msleep(OLED_PRE_T11_DELAY);
1085 void dce110_enable_audio_stream(struct pipe_ctx *pipe_ctx)
1087 /* notify audio driver for audio modes of monitor */
1089 struct clk_mgr *clk_mgr;
1090 unsigned int i, num_audio = 1;
1092 if (!pipe_ctx->stream)
1095 dc = pipe_ctx->stream->ctx->dc;
1096 clk_mgr = dc->clk_mgr;
1098 if (pipe_ctx->stream_res.audio && pipe_ctx->stream_res.audio->enabled == true)
1101 if (pipe_ctx->stream_res.audio) {
1102 for (i = 0; i < MAX_PIPES; i++) {
1103 /*current_state not updated yet*/
1104 if (dc->current_state->res_ctx.pipe_ctx[i].stream_res.audio != NULL)
1108 pipe_ctx->stream_res.audio->funcs->az_enable(pipe_ctx->stream_res.audio);
1110 if (num_audio >= 1 && clk_mgr->funcs->enable_pme_wa)
1111 /*this is the first audio. apply the PME w/a in order to wake AZ from D3*/
1112 clk_mgr->funcs->enable_pme_wa(clk_mgr);
1114 /* TODO: audio should be per stream rather than per link */
1115 #if defined(CONFIG_DRM_AMD_DC_DCN)
1116 if (is_dp_128b_132b_signal(pipe_ctx))
1117 pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->audio_mute_control(
1118 pipe_ctx->stream_res.hpo_dp_stream_enc, false);
1120 pipe_ctx->stream_res.stream_enc->funcs->audio_mute_control(
1121 pipe_ctx->stream_res.stream_enc, false);
1123 pipe_ctx->stream_res.stream_enc->funcs->audio_mute_control(
1124 pipe_ctx->stream_res.stream_enc, false);
1126 if (pipe_ctx->stream_res.audio)
1127 pipe_ctx->stream_res.audio->enabled = true;
1130 if (dc_is_dp_signal(pipe_ctx->stream->signal))
1131 dp_source_sequence_trace(pipe_ctx->stream->link, DPCD_SOURCE_SEQ_AFTER_ENABLE_AUDIO_STREAM);
1134 void dce110_disable_audio_stream(struct pipe_ctx *pipe_ctx)
1137 struct clk_mgr *clk_mgr;
1139 if (!pipe_ctx || !pipe_ctx->stream)
1142 dc = pipe_ctx->stream->ctx->dc;
1143 clk_mgr = dc->clk_mgr;
1145 if (pipe_ctx->stream_res.audio && pipe_ctx->stream_res.audio->enabled == false)
1148 #if defined(CONFIG_DRM_AMD_DC_DCN)
1149 if (is_dp_128b_132b_signal(pipe_ctx))
1150 pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->audio_mute_control(
1151 pipe_ctx->stream_res.hpo_dp_stream_enc, true);
1153 pipe_ctx->stream_res.stream_enc->funcs->audio_mute_control(
1154 pipe_ctx->stream_res.stream_enc, true);
1156 pipe_ctx->stream_res.stream_enc->funcs->audio_mute_control(
1157 pipe_ctx->stream_res.stream_enc, true);
1159 if (pipe_ctx->stream_res.audio) {
1160 pipe_ctx->stream_res.audio->enabled = false;
1162 if (dc_is_dp_signal(pipe_ctx->stream->signal))
1163 #if defined(CONFIG_DRM_AMD_DC_DCN)
1164 if (is_dp_128b_132b_signal(pipe_ctx))
1165 pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->dp_audio_disable(
1166 pipe_ctx->stream_res.hpo_dp_stream_enc);
1168 pipe_ctx->stream_res.stream_enc->funcs->dp_audio_disable(
1169 pipe_ctx->stream_res.stream_enc);
1171 pipe_ctx->stream_res.stream_enc->funcs->dp_audio_disable(
1172 pipe_ctx->stream_res.stream_enc);
1175 pipe_ctx->stream_res.stream_enc->funcs->hdmi_audio_disable(
1176 pipe_ctx->stream_res.stream_enc);
1178 if (clk_mgr->funcs->enable_pme_wa)
1179 /*this is the first audio. apply the PME w/a in order to wake AZ from D3*/
1180 clk_mgr->funcs->enable_pme_wa(clk_mgr);
1182 /* TODO: notify audio driver for if audio modes list changed
1183 * add audio mode list change flag */
1184 /* dal_audio_disable_azalia_audio_jack_presence(stream->audio,
1185 * stream->stream_engine_id);
1189 if (dc_is_dp_signal(pipe_ctx->stream->signal))
1190 dp_source_sequence_trace(pipe_ctx->stream->link, DPCD_SOURCE_SEQ_AFTER_DISABLE_AUDIO_STREAM);
1193 void dce110_disable_stream(struct pipe_ctx *pipe_ctx)
1195 struct dc_stream_state *stream = pipe_ctx->stream;
1196 struct dc_link *link = stream->link;
1197 struct dc *dc = pipe_ctx->stream->ctx->dc;
1198 struct link_encoder *link_enc = NULL;
1200 if (dc_is_hdmi_tmds_signal(pipe_ctx->stream->signal)) {
1201 pipe_ctx->stream_res.stream_enc->funcs->stop_hdmi_info_packets(
1202 pipe_ctx->stream_res.stream_enc);
1203 pipe_ctx->stream_res.stream_enc->funcs->hdmi_reset_stream_attribute(
1204 pipe_ctx->stream_res.stream_enc);
1207 #if defined(CONFIG_DRM_AMD_DC_DCN)
1208 if (is_dp_128b_132b_signal(pipe_ctx)) {
1209 pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->stop_dp_info_packets(
1210 pipe_ctx->stream_res.hpo_dp_stream_enc);
1211 } else if (dc_is_dp_signal(pipe_ctx->stream->signal))
1213 if (dc_is_dp_signal(pipe_ctx->stream->signal))
1215 pipe_ctx->stream_res.stream_enc->funcs->stop_dp_info_packets(
1216 pipe_ctx->stream_res.stream_enc);
1218 dc->hwss.disable_audio_stream(pipe_ctx);
1220 /* Link encoder may have been dynamically assigned to non-physical display endpoint. */
1221 if (link->ep_type == DISPLAY_ENDPOINT_PHY)
1222 link_enc = link->link_enc;
1223 else if (dc->res_pool->funcs->link_encs_assign)
1224 link_enc = link_enc_cfg_get_link_enc_used_by_link(link->ctx->dc, link);
1227 #if defined(CONFIG_DRM_AMD_DC_DCN)
1228 if (is_dp_128b_132b_signal(pipe_ctx)) {
1229 pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->disable(
1230 pipe_ctx->stream_res.hpo_dp_stream_enc);
1231 setup_dp_hpo_stream(pipe_ctx, false);
1232 /* TODO - DP2.0 HW: unmap stream from link encoder here */
1235 link_enc->funcs->connect_dig_be_to_fe(
1237 pipe_ctx->stream_res.stream_enc->id,
1242 link_enc->funcs->connect_dig_be_to_fe(
1244 pipe_ctx->stream_res.stream_enc->id,
1247 if (dc_is_dp_signal(pipe_ctx->stream->signal))
1248 dp_source_sequence_trace(link, DPCD_SOURCE_SEQ_AFTER_DISCONNECT_DIG_FE_BE);
1250 #if defined(CONFIG_DRM_AMD_DC_DCN)
1251 if (dc->hwseq->funcs.setup_hpo_hw_control && is_dp_128b_132b_signal(pipe_ctx))
1252 dc->hwseq->funcs.setup_hpo_hw_control(dc->hwseq, false);
1257 void dce110_unblank_stream(struct pipe_ctx *pipe_ctx,
1258 struct dc_link_settings *link_settings)
1260 struct encoder_unblank_param params = { { 0 } };
1261 struct dc_stream_state *stream = pipe_ctx->stream;
1262 struct dc_link *link = stream->link;
1263 struct dce_hwseq *hws = link->dc->hwseq;
1265 /* only 3 items below are used by unblank */
1266 params.timing = pipe_ctx->stream->timing;
1267 params.link_settings.link_rate = link_settings->link_rate;
1269 if (dc_is_dp_signal(pipe_ctx->stream->signal))
1270 pipe_ctx->stream_res.stream_enc->funcs->dp_unblank(link, pipe_ctx->stream_res.stream_enc, ¶ms);
1272 if (link->local_sink && link->local_sink->sink_signal == SIGNAL_TYPE_EDP) {
1273 hws->funcs.edp_backlight_control(link, true);
1277 void dce110_blank_stream(struct pipe_ctx *pipe_ctx)
1279 struct dc_stream_state *stream = pipe_ctx->stream;
1280 struct dc_link *link = stream->link;
1281 struct dce_hwseq *hws = link->dc->hwseq;
1283 if (link->local_sink && link->local_sink->sink_signal == SIGNAL_TYPE_EDP) {
1284 hws->funcs.edp_backlight_control(link, false);
1285 link->dc->hwss.set_abm_immediate_disable(pipe_ctx);
1288 #if defined(CONFIG_DRM_AMD_DC_DCN)
1289 if (is_dp_128b_132b_signal(pipe_ctx)) {
1290 /* TODO - DP2.0 HW: Set ODM mode in dp hpo encoder here */
1291 pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->dp_blank(
1292 pipe_ctx->stream_res.hpo_dp_stream_enc);
1293 } else if (dc_is_dp_signal(pipe_ctx->stream->signal)) {
1295 if (dc_is_dp_signal(pipe_ctx->stream->signal)) {
1297 pipe_ctx->stream_res.stream_enc->funcs->dp_blank(link, pipe_ctx->stream_res.stream_enc);
1299 if (!dc_is_embedded_signal(pipe_ctx->stream->signal)) {
1301 * After output is idle pattern some sinks need time to recognize the stream
1302 * has changed or they enter protection state and hang.
1305 } else if (pipe_ctx->stream->signal == SIGNAL_TYPE_EDP)
1306 edp_receiver_ready_T9(link);
1312 void dce110_set_avmute(struct pipe_ctx *pipe_ctx, bool enable)
1314 if (pipe_ctx != NULL && pipe_ctx->stream_res.stream_enc != NULL)
1315 pipe_ctx->stream_res.stream_enc->funcs->set_avmute(pipe_ctx->stream_res.stream_enc, enable);
1318 static enum audio_dto_source translate_to_dto_source(enum controller_id crtc_id)
1321 case CONTROLLER_ID_D0:
1322 return DTO_SOURCE_ID0;
1323 case CONTROLLER_ID_D1:
1324 return DTO_SOURCE_ID1;
1325 case CONTROLLER_ID_D2:
1326 return DTO_SOURCE_ID2;
1327 case CONTROLLER_ID_D3:
1328 return DTO_SOURCE_ID3;
1329 case CONTROLLER_ID_D4:
1330 return DTO_SOURCE_ID4;
1331 case CONTROLLER_ID_D5:
1332 return DTO_SOURCE_ID5;
1334 return DTO_SOURCE_UNKNOWN;
1338 static void build_audio_output(
1339 struct dc_state *state,
1340 const struct pipe_ctx *pipe_ctx,
1341 struct audio_output *audio_output)
1343 const struct dc_stream_state *stream = pipe_ctx->stream;
1344 audio_output->engine_id = pipe_ctx->stream_res.stream_enc->id;
1346 audio_output->signal = pipe_ctx->stream->signal;
1348 /* audio_crtc_info */
1350 audio_output->crtc_info.h_total =
1351 stream->timing.h_total;
1354 * Audio packets are sent during actual CRTC blank physical signal, we
1355 * need to specify actual active signal portion
1357 audio_output->crtc_info.h_active =
1358 stream->timing.h_addressable
1359 + stream->timing.h_border_left
1360 + stream->timing.h_border_right;
1362 audio_output->crtc_info.v_active =
1363 stream->timing.v_addressable
1364 + stream->timing.v_border_top
1365 + stream->timing.v_border_bottom;
1367 audio_output->crtc_info.pixel_repetition = 1;
1369 audio_output->crtc_info.interlaced =
1370 stream->timing.flags.INTERLACE;
1372 audio_output->crtc_info.refresh_rate =
1373 (stream->timing.pix_clk_100hz*100)/
1374 (stream->timing.h_total*stream->timing.v_total);
1376 audio_output->crtc_info.color_depth =
1377 stream->timing.display_color_depth;
1379 audio_output->crtc_info.requested_pixel_clock_100Hz =
1380 pipe_ctx->stream_res.pix_clk_params.requested_pix_clk_100hz;
1382 audio_output->crtc_info.calculated_pixel_clock_100Hz =
1383 pipe_ctx->stream_res.pix_clk_params.requested_pix_clk_100hz;
1385 /*for HDMI, audio ACR is with deep color ratio factor*/
1386 if (dc_is_hdmi_tmds_signal(pipe_ctx->stream->signal) &&
1387 audio_output->crtc_info.requested_pixel_clock_100Hz ==
1388 (stream->timing.pix_clk_100hz)) {
1389 if (pipe_ctx->stream_res.pix_clk_params.pixel_encoding == PIXEL_ENCODING_YCBCR420) {
1390 audio_output->crtc_info.requested_pixel_clock_100Hz =
1391 audio_output->crtc_info.requested_pixel_clock_100Hz/2;
1392 audio_output->crtc_info.calculated_pixel_clock_100Hz =
1393 pipe_ctx->stream_res.pix_clk_params.requested_pix_clk_100hz/2;
1398 if (state->clk_mgr &&
1399 (pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT ||
1400 pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST)) {
1401 audio_output->pll_info.dp_dto_source_clock_in_khz =
1402 state->clk_mgr->funcs->get_dp_ref_clk_frequency(
1406 audio_output->pll_info.feed_back_divider =
1407 pipe_ctx->pll_settings.feedback_divider;
1409 audio_output->pll_info.dto_source =
1410 translate_to_dto_source(
1411 pipe_ctx->stream_res.tg->inst + 1);
1413 /* TODO hard code to enable for now. Need get from stream */
1414 audio_output->pll_info.ss_enabled = true;
1416 audio_output->pll_info.ss_percentage =
1417 pipe_ctx->pll_settings.ss_percentage;
1420 static void program_scaler(const struct dc *dc,
1421 const struct pipe_ctx *pipe_ctx)
1423 struct tg_color color = {0};
1425 #if defined(CONFIG_DRM_AMD_DC_DCN)
1427 if (pipe_ctx->plane_res.xfm->funcs->transform_set_pixel_storage_depth == NULL)
1431 if (dc->debug.visual_confirm == VISUAL_CONFIRM_SURFACE)
1432 get_surface_visual_confirm_color(pipe_ctx, &color);
1434 color_space_to_black_color(dc,
1435 pipe_ctx->stream->output_color_space,
1438 pipe_ctx->plane_res.xfm->funcs->transform_set_pixel_storage_depth(
1439 pipe_ctx->plane_res.xfm,
1440 pipe_ctx->plane_res.scl_data.lb_params.depth,
1441 &pipe_ctx->stream->bit_depth_params);
1443 if (pipe_ctx->stream_res.tg->funcs->set_overscan_blank_color) {
1445 * The way 420 is packed, 2 channels carry Y component, 1 channel
1446 * alternate between Cb and Cr, so both channels need the pixel
1449 if (pipe_ctx->stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR420)
1450 color.color_r_cr = color.color_g_y;
1452 pipe_ctx->stream_res.tg->funcs->set_overscan_blank_color(
1453 pipe_ctx->stream_res.tg,
1457 pipe_ctx->plane_res.xfm->funcs->transform_set_scaler(pipe_ctx->plane_res.xfm,
1458 &pipe_ctx->plane_res.scl_data);
1461 static enum dc_status dce110_enable_stream_timing(
1462 struct pipe_ctx *pipe_ctx,
1463 struct dc_state *context,
1466 struct dc_stream_state *stream = pipe_ctx->stream;
1467 struct pipe_ctx *pipe_ctx_old = &dc->current_state->res_ctx.
1468 pipe_ctx[pipe_ctx->pipe_idx];
1469 struct tg_color black_color = {0};
1471 if (!pipe_ctx_old->stream) {
1473 /* program blank color */
1474 color_space_to_black_color(dc,
1475 stream->output_color_space, &black_color);
1476 pipe_ctx->stream_res.tg->funcs->set_blank_color(
1477 pipe_ctx->stream_res.tg,
1481 * Must blank CRTC after disabling power gating and before any
1482 * programming, otherwise CRTC will be hung in bad state
1484 pipe_ctx->stream_res.tg->funcs->set_blank(pipe_ctx->stream_res.tg, true);
1486 if (false == pipe_ctx->clock_source->funcs->program_pix_clk(
1487 pipe_ctx->clock_source,
1488 &pipe_ctx->stream_res.pix_clk_params,
1489 &pipe_ctx->pll_settings)) {
1490 BREAK_TO_DEBUGGER();
1491 return DC_ERROR_UNEXPECTED;
1494 pipe_ctx->stream_res.tg->funcs->program_timing(
1495 pipe_ctx->stream_res.tg,
1501 pipe_ctx->stream->signal,
1505 if (!pipe_ctx_old->stream) {
1506 if (false == pipe_ctx->stream_res.tg->funcs->enable_crtc(
1507 pipe_ctx->stream_res.tg)) {
1508 BREAK_TO_DEBUGGER();
1509 return DC_ERROR_UNEXPECTED;
1516 static enum dc_status apply_single_controller_ctx_to_hw(
1517 struct pipe_ctx *pipe_ctx,
1518 struct dc_state *context,
1521 struct dc_stream_state *stream = pipe_ctx->stream;
1522 struct dc_link *link = stream->link;
1523 struct drr_params params = {0};
1524 unsigned int event_triggers = 0;
1525 struct pipe_ctx *odm_pipe = pipe_ctx->next_odm_pipe;
1526 struct dce_hwseq *hws = dc->hwseq;
1528 if (hws->funcs.disable_stream_gating) {
1529 hws->funcs.disable_stream_gating(dc, pipe_ctx);
1532 if (pipe_ctx->stream_res.audio != NULL) {
1533 struct audio_output audio_output;
1535 build_audio_output(context, pipe_ctx, &audio_output);
1537 if (dc_is_dp_signal(pipe_ctx->stream->signal))
1538 #if defined(CONFIG_DRM_AMD_DC_DCN)
1539 if (is_dp_128b_132b_signal(pipe_ctx))
1540 pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->dp_audio_setup(
1541 pipe_ctx->stream_res.hpo_dp_stream_enc,
1542 pipe_ctx->stream_res.audio->inst,
1543 &pipe_ctx->stream->audio_info);
1545 pipe_ctx->stream_res.stream_enc->funcs->dp_audio_setup(
1546 pipe_ctx->stream_res.stream_enc,
1547 pipe_ctx->stream_res.audio->inst,
1548 &pipe_ctx->stream->audio_info);
1550 pipe_ctx->stream_res.stream_enc->funcs->dp_audio_setup(
1551 pipe_ctx->stream_res.stream_enc,
1552 pipe_ctx->stream_res.audio->inst,
1553 &pipe_ctx->stream->audio_info);
1556 pipe_ctx->stream_res.stream_enc->funcs->hdmi_audio_setup(
1557 pipe_ctx->stream_res.stream_enc,
1558 pipe_ctx->stream_res.audio->inst,
1559 &pipe_ctx->stream->audio_info,
1560 &audio_output.crtc_info);
1562 pipe_ctx->stream_res.audio->funcs->az_configure(
1563 pipe_ctx->stream_res.audio,
1564 pipe_ctx->stream->signal,
1565 &audio_output.crtc_info,
1566 &pipe_ctx->stream->audio_info);
1569 /* make sure no pipes syncd to the pipe being enabled */
1570 if (!pipe_ctx->stream->apply_seamless_boot_optimization && dc->config.use_pipe_ctx_sync_logic)
1571 check_syncd_pipes_for_disabled_master_pipe(dc, context, pipe_ctx->pipe_idx);
1573 #if defined(CONFIG_DRM_AMD_DC_DCN)
1574 /* DCN3.1 FPGA Workaround
1575 * Need to enable HPO DP Stream Encoder before setting OTG master enable.
1576 * To do so, move calling function enable_stream_timing to only be done AFTER calling
1577 * function core_link_enable_stream
1579 if (!(hws->wa.dp_hpo_and_otg_sequence && is_dp_128b_132b_signal(pipe_ctx)))
1582 /* Do not touch stream timing on seamless boot optimization. */
1583 if (!pipe_ctx->stream->apply_seamless_boot_optimization)
1584 hws->funcs.enable_stream_timing(pipe_ctx, context, dc);
1586 if (hws->funcs.setup_vupdate_interrupt)
1587 hws->funcs.setup_vupdate_interrupt(dc, pipe_ctx);
1589 params.vertical_total_min = stream->adjust.v_total_min;
1590 params.vertical_total_max = stream->adjust.v_total_max;
1591 if (pipe_ctx->stream_res.tg->funcs->set_drr)
1592 pipe_ctx->stream_res.tg->funcs->set_drr(
1593 pipe_ctx->stream_res.tg, ¶ms);
1595 // DRR should set trigger event to monitor surface update event
1596 if (stream->adjust.v_total_min != 0 && stream->adjust.v_total_max != 0)
1597 event_triggers = 0x80;
1598 /* Event triggers and num frames initialized for DRR, but can be
1599 * later updated for PSR use. Note DRR trigger events are generated
1600 * regardless of whether num frames met.
1602 if (pipe_ctx->stream_res.tg->funcs->set_static_screen_control)
1603 pipe_ctx->stream_res.tg->funcs->set_static_screen_control(
1604 pipe_ctx->stream_res.tg, event_triggers, 2);
1606 if (!dc_is_virtual_signal(pipe_ctx->stream->signal))
1607 pipe_ctx->stream_res.stream_enc->funcs->dig_connect_to_otg(
1608 pipe_ctx->stream_res.stream_enc,
1609 pipe_ctx->stream_res.tg->inst);
1611 if (dc_is_dp_signal(pipe_ctx->stream->signal) &&
1612 pipe_ctx->stream_res.stream_enc->funcs->reset_fifo)
1613 pipe_ctx->stream_res.stream_enc->funcs->reset_fifo(
1614 pipe_ctx->stream_res.stream_enc);
1616 if (dc_is_dp_signal(pipe_ctx->stream->signal))
1617 dp_source_sequence_trace(link, DPCD_SOURCE_SEQ_AFTER_CONNECT_DIG_FE_OTG);
1619 pipe_ctx->stream_res.opp->funcs->opp_set_dyn_expansion(
1620 pipe_ctx->stream_res.opp,
1621 COLOR_SPACE_YCBCR601,
1622 stream->timing.display_color_depth,
1625 pipe_ctx->stream_res.opp->funcs->opp_program_fmt(
1626 pipe_ctx->stream_res.opp,
1627 &stream->bit_depth_params,
1630 odm_pipe->stream_res.opp->funcs->opp_set_dyn_expansion(
1631 odm_pipe->stream_res.opp,
1632 COLOR_SPACE_YCBCR601,
1633 stream->timing.display_color_depth,
1636 odm_pipe->stream_res.opp->funcs->opp_program_fmt(
1637 odm_pipe->stream_res.opp,
1638 &stream->bit_depth_params,
1640 odm_pipe = odm_pipe->next_odm_pipe;
1643 if (!stream->dpms_off)
1644 core_link_enable_stream(context, pipe_ctx);
1646 #if defined(CONFIG_DRM_AMD_DC_DCN)
1647 /* DCN3.1 FPGA Workaround
1648 * Need to enable HPO DP Stream Encoder before setting OTG master enable.
1649 * To do so, move calling function enable_stream_timing to only be done AFTER calling
1650 * function core_link_enable_stream
1652 if (hws->wa.dp_hpo_and_otg_sequence && is_dp_128b_132b_signal(pipe_ctx)) {
1653 if (!pipe_ctx->stream->apply_seamless_boot_optimization)
1654 hws->funcs.enable_stream_timing(pipe_ctx, context, dc);
1658 pipe_ctx->plane_res.scl_data.lb_params.alpha_en = pipe_ctx->bottom_pipe != 0;
1660 pipe_ctx->stream->link->psr_settings.psr_feature_enabled = false;
1665 /******************************************************************************/
1667 static void power_down_encoders(struct dc *dc)
1671 for (i = 0; i < dc->link_count; i++) {
1672 enum signal_type signal = dc->links[i]->connector_signal;
1674 dc_link_blank_dp_stream(dc->links[i], false);
1676 if (signal != SIGNAL_TYPE_EDP)
1677 signal = SIGNAL_TYPE_NONE;
1679 if (dc->links[i]->ep_type == DISPLAY_ENDPOINT_PHY)
1680 dc->links[i]->link_enc->funcs->disable_output(
1681 dc->links[i]->link_enc, signal);
1683 dc->links[i]->link_status.link_active = false;
1684 memset(&dc->links[i]->cur_link_settings, 0,
1685 sizeof(dc->links[i]->cur_link_settings));
1689 static void power_down_controllers(struct dc *dc)
1693 for (i = 0; i < dc->res_pool->timing_generator_count; i++) {
1694 dc->res_pool->timing_generators[i]->funcs->disable_crtc(
1695 dc->res_pool->timing_generators[i]);
1699 static void power_down_clock_sources(struct dc *dc)
1703 if (dc->res_pool->dp_clock_source->funcs->cs_power_down(
1704 dc->res_pool->dp_clock_source) == false)
1705 dm_error("Failed to power down pll! (dp clk src)\n");
1707 for (i = 0; i < dc->res_pool->clk_src_count; i++) {
1708 if (dc->res_pool->clock_sources[i]->funcs->cs_power_down(
1709 dc->res_pool->clock_sources[i]) == false)
1710 dm_error("Failed to power down pll! (clk src index=%d)\n", i);
1714 static void power_down_all_hw_blocks(struct dc *dc)
1716 power_down_encoders(dc);
1718 power_down_controllers(dc);
1720 power_down_clock_sources(dc);
1722 if (dc->fbc_compressor)
1723 dc->fbc_compressor->funcs->disable_fbc(dc->fbc_compressor);
1726 static void disable_vga_and_power_gate_all_controllers(
1730 struct timing_generator *tg;
1731 struct dc_context *ctx = dc->ctx;
1733 for (i = 0; i < dc->res_pool->timing_generator_count; i++) {
1734 tg = dc->res_pool->timing_generators[i];
1736 if (tg->funcs->disable_vga)
1737 tg->funcs->disable_vga(tg);
1739 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1740 /* Enable CLOCK gating for each pipe BEFORE controller
1742 enable_display_pipe_clock_gating(ctx,
1745 dc->current_state->res_ctx.pipe_ctx[i].pipe_idx = i;
1746 dc->hwss.disable_plane(dc,
1747 &dc->current_state->res_ctx.pipe_ctx[i]);
1752 static void get_edp_streams(struct dc_state *context,
1753 struct dc_stream_state **edp_streams,
1754 int *edp_stream_num)
1758 *edp_stream_num = 0;
1759 for (i = 0; i < context->stream_count; i++) {
1760 if (context->streams[i]->signal == SIGNAL_TYPE_EDP) {
1761 edp_streams[*edp_stream_num] = context->streams[i];
1762 if (++(*edp_stream_num) == MAX_NUM_EDP)
1768 static void get_edp_links_with_sink(
1770 struct dc_link **edp_links_with_sink,
1771 int *edp_with_sink_num)
1775 /* check if there is an eDP panel not in use */
1776 *edp_with_sink_num = 0;
1777 for (i = 0; i < dc->link_count; i++) {
1778 if (dc->links[i]->local_sink &&
1779 dc->links[i]->local_sink->sink_signal == SIGNAL_TYPE_EDP) {
1780 edp_links_with_sink[*edp_with_sink_num] = dc->links[i];
1781 if (++(*edp_with_sink_num) == MAX_NUM_EDP)
1788 * When ASIC goes from VBIOS/VGA mode to driver/accelerated mode we need:
1789 * 1. Power down all DC HW blocks
1790 * 2. Disable VGA engine on all controllers
1791 * 3. Enable power gating for controller
1792 * 4. Set acc_mode_change bit (VBIOS will clear this bit when going to FSDOS)
1794 void dce110_enable_accelerated_mode(struct dc *dc, struct dc_state *context)
1796 struct dc_link *edp_links_with_sink[MAX_NUM_EDP];
1797 struct dc_link *edp_links[MAX_NUM_EDP];
1798 struct dc_stream_state *edp_streams[MAX_NUM_EDP];
1799 struct dc_link *edp_link_with_sink = NULL;
1800 struct dc_link *edp_link = NULL;
1801 struct dc_stream_state *edp_stream = NULL;
1802 struct dce_hwseq *hws = dc->hwseq;
1803 int edp_with_sink_num;
1807 bool can_apply_edp_fast_boot = false;
1808 bool can_apply_seamless_boot = false;
1809 bool keep_edp_vdd_on = false;
1813 get_edp_links_with_sink(dc, edp_links_with_sink, &edp_with_sink_num);
1814 get_edp_links(dc, edp_links, &edp_num);
1816 if (hws->funcs.init_pipes)
1817 hws->funcs.init_pipes(dc, context);
1819 get_edp_streams(context, edp_streams, &edp_stream_num);
1821 // Check fastboot support, disable on DCE8 because of blank screens
1822 if (edp_num && edp_stream_num && dc->ctx->dce_version != DCE_VERSION_8_0 &&
1823 dc->ctx->dce_version != DCE_VERSION_8_1 &&
1824 dc->ctx->dce_version != DCE_VERSION_8_3) {
1825 for (i = 0; i < edp_num; i++) {
1826 edp_link = edp_links[i];
1827 if (edp_link != edp_streams[0]->link)
1829 // enable fastboot if backend is enabled on eDP
1830 if (edp_link->link_enc->funcs->is_dig_enabled &&
1831 edp_link->link_enc->funcs->is_dig_enabled(edp_link->link_enc) &&
1832 edp_link->link_status.link_active) {
1833 edp_stream = edp_streams[0];
1834 can_apply_edp_fast_boot = !is_edp_ilr_optimization_required(edp_stream->link, &edp_stream->timing);
1835 edp_stream->apply_edp_fast_boot_optimization = can_apply_edp_fast_boot;
1836 if (can_apply_edp_fast_boot)
1837 DC_LOG_EVENT_LINK_TRAINING("eDP fast boot disabled to optimize link rate\n");
1842 // We are trying to enable eDP, don't power down VDD
1843 if (can_apply_edp_fast_boot)
1844 keep_edp_vdd_on = true;
1847 // Check seamless boot support
1848 for (i = 0; i < context->stream_count; i++) {
1849 if (context->streams[i]->apply_seamless_boot_optimization) {
1850 can_apply_seamless_boot = true;
1855 /* eDP should not have stream in resume from S4 and so even with VBios post
1856 * it should get turned off
1858 if (edp_with_sink_num)
1859 edp_link_with_sink = edp_links_with_sink[0];
1861 if (!can_apply_edp_fast_boot && !can_apply_seamless_boot) {
1862 if (edp_link_with_sink && !keep_edp_vdd_on) {
1863 /*turn off backlight before DP_blank and encoder powered down*/
1864 hws->funcs.edp_backlight_control(edp_link_with_sink, false);
1866 /*resume from S3, no vbios posting, no need to power down again*/
1867 power_down_all_hw_blocks(dc);
1868 disable_vga_and_power_gate_all_controllers(dc);
1869 if (edp_link_with_sink && !keep_edp_vdd_on)
1870 dc->hwss.edp_power_control(edp_link_with_sink, false);
1872 bios_set_scratch_acc_mode_change(dc->ctx->dc_bios, 1);
1875 static uint32_t compute_pstate_blackout_duration(
1876 struct bw_fixed blackout_duration,
1877 const struct dc_stream_state *stream)
1879 uint32_t total_dest_line_time_ns;
1880 uint32_t pstate_blackout_duration_ns;
1882 pstate_blackout_duration_ns = 1000 * blackout_duration.value >> 24;
1884 total_dest_line_time_ns = 1000000UL *
1885 (stream->timing.h_total * 10) /
1886 stream->timing.pix_clk_100hz +
1887 pstate_blackout_duration_ns;
1889 return total_dest_line_time_ns;
1892 static void dce110_set_displaymarks(
1893 const struct dc *dc,
1894 struct dc_state *context)
1896 uint8_t i, num_pipes;
1897 unsigned int underlay_idx = dc->res_pool->underlay_pipe_index;
1899 for (i = 0, num_pipes = 0; i < MAX_PIPES; i++) {
1900 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
1901 uint32_t total_dest_line_time_ns;
1903 if (pipe_ctx->stream == NULL)
1906 total_dest_line_time_ns = compute_pstate_blackout_duration(
1907 dc->bw_vbios->blackout_duration, pipe_ctx->stream);
1908 pipe_ctx->plane_res.mi->funcs->mem_input_program_display_marks(
1909 pipe_ctx->plane_res.mi,
1910 context->bw_ctx.bw.dce.nbp_state_change_wm_ns[num_pipes],
1911 context->bw_ctx.bw.dce.stutter_exit_wm_ns[num_pipes],
1912 context->bw_ctx.bw.dce.stutter_entry_wm_ns[num_pipes],
1913 context->bw_ctx.bw.dce.urgent_wm_ns[num_pipes],
1914 total_dest_line_time_ns);
1915 if (i == underlay_idx) {
1917 pipe_ctx->plane_res.mi->funcs->mem_input_program_chroma_display_marks(
1918 pipe_ctx->plane_res.mi,
1919 context->bw_ctx.bw.dce.nbp_state_change_wm_ns[num_pipes],
1920 context->bw_ctx.bw.dce.stutter_exit_wm_ns[num_pipes],
1921 context->bw_ctx.bw.dce.urgent_wm_ns[num_pipes],
1922 total_dest_line_time_ns);
1928 void dce110_set_safe_displaymarks(
1929 struct resource_context *res_ctx,
1930 const struct resource_pool *pool)
1933 int underlay_idx = pool->underlay_pipe_index;
1934 struct dce_watermarks max_marks = {
1935 MAX_WATERMARK, MAX_WATERMARK, MAX_WATERMARK, MAX_WATERMARK };
1936 struct dce_watermarks nbp_marks = {
1937 SAFE_NBP_MARK, SAFE_NBP_MARK, SAFE_NBP_MARK, SAFE_NBP_MARK };
1938 struct dce_watermarks min_marks = { 0, 0, 0, 0};
1940 for (i = 0; i < MAX_PIPES; i++) {
1941 if (res_ctx->pipe_ctx[i].stream == NULL || res_ctx->pipe_ctx[i].plane_res.mi == NULL)
1944 res_ctx->pipe_ctx[i].plane_res.mi->funcs->mem_input_program_display_marks(
1945 res_ctx->pipe_ctx[i].plane_res.mi,
1952 if (i == underlay_idx)
1953 res_ctx->pipe_ctx[i].plane_res.mi->funcs->mem_input_program_chroma_display_marks(
1954 res_ctx->pipe_ctx[i].plane_res.mi,
1963 /*******************************************************************************
1965 ******************************************************************************/
1967 static void set_drr(struct pipe_ctx **pipe_ctx,
1968 int num_pipes, struct dc_crtc_timing_adjust adjust)
1971 struct drr_params params = {0};
1972 // DRR should set trigger event to monitor surface update event
1973 unsigned int event_triggers = 0x80;
1974 // Note DRR trigger events are generated regardless of whether num frames met.
1975 unsigned int num_frames = 2;
1977 params.vertical_total_max = adjust.v_total_max;
1978 params.vertical_total_min = adjust.v_total_min;
1980 /* TODO: If multiple pipes are to be supported, you need
1981 * some GSL stuff. Static screen triggers may be programmed differently
1984 for (i = 0; i < num_pipes; i++) {
1985 pipe_ctx[i]->stream_res.tg->funcs->set_drr(
1986 pipe_ctx[i]->stream_res.tg, ¶ms);
1988 if (adjust.v_total_max != 0 && adjust.v_total_min != 0)
1989 pipe_ctx[i]->stream_res.tg->funcs->set_static_screen_control(
1990 pipe_ctx[i]->stream_res.tg,
1991 event_triggers, num_frames);
1995 static void get_position(struct pipe_ctx **pipe_ctx,
1997 struct crtc_position *position)
2001 /* TODO: handle pipes > 1
2003 for (i = 0; i < num_pipes; i++)
2004 pipe_ctx[i]->stream_res.tg->funcs->get_position(pipe_ctx[i]->stream_res.tg, position);
2007 static void set_static_screen_control(struct pipe_ctx **pipe_ctx,
2008 int num_pipes, const struct dc_static_screen_params *params)
2011 unsigned int triggers = 0;
2013 if (params->triggers.overlay_update)
2015 if (params->triggers.surface_update)
2017 if (params->triggers.cursor_update)
2019 if (params->triggers.force_trigger)
2023 struct dc *dc = pipe_ctx[0]->stream->ctx->dc;
2025 if (dc->fbc_compressor)
2029 for (i = 0; i < num_pipes; i++)
2030 pipe_ctx[i]->stream_res.tg->funcs->
2031 set_static_screen_control(pipe_ctx[i]->stream_res.tg,
2032 triggers, params->num_frames);
2036 * Check if FBC can be enabled
2038 static bool should_enable_fbc(struct dc *dc,
2039 struct dc_state *context,
2043 struct pipe_ctx *pipe_ctx = NULL;
2044 struct resource_context *res_ctx = &context->res_ctx;
2045 unsigned int underlay_idx = dc->res_pool->underlay_pipe_index;
2048 ASSERT(dc->fbc_compressor);
2050 /* FBC memory should be allocated */
2051 if (!dc->ctx->fbc_gpu_addr)
2054 /* Only supports single display */
2055 if (context->stream_count != 1)
2058 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2059 if (res_ctx->pipe_ctx[i].stream) {
2061 pipe_ctx = &res_ctx->pipe_ctx[i];
2066 /* fbc not applicable on underlay pipe */
2067 if (pipe_ctx->pipe_idx != underlay_idx) {
2074 if (i == dc->res_pool->pipe_count)
2077 if (!pipe_ctx->stream->link)
2080 /* Only supports eDP */
2081 if (pipe_ctx->stream->link->connector_signal != SIGNAL_TYPE_EDP)
2084 /* PSR should not be enabled */
2085 if (pipe_ctx->stream->link->psr_settings.psr_feature_enabled)
2088 /* Nothing to compress */
2089 if (!pipe_ctx->plane_state)
2092 /* Only for non-linear tiling */
2093 if (pipe_ctx->plane_state->tiling_info.gfx8.array_mode == DC_ARRAY_LINEAR_GENERAL)
2102 static void enable_fbc(
2104 struct dc_state *context)
2106 uint32_t pipe_idx = 0;
2108 if (should_enable_fbc(dc, context, &pipe_idx)) {
2109 /* Program GRPH COMPRESSED ADDRESS and PITCH */
2110 struct compr_addr_and_pitch_params params = {0, 0, 0};
2111 struct compressor *compr = dc->fbc_compressor;
2112 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[pipe_idx];
2114 params.source_view_width = pipe_ctx->stream->timing.h_addressable;
2115 params.source_view_height = pipe_ctx->stream->timing.v_addressable;
2116 params.inst = pipe_ctx->stream_res.tg->inst;
2117 compr->compr_surface_address.quad_part = dc->ctx->fbc_gpu_addr;
2119 compr->funcs->surface_address_and_pitch(compr, ¶ms);
2120 compr->funcs->set_fbc_invalidation_triggers(compr, 1);
2122 compr->funcs->enable_fbc(compr, ¶ms);
2126 static void dce110_reset_hw_ctx_wrap(
2128 struct dc_state *context)
2132 /* Reset old context */
2133 /* look up the targets that have been removed since last commit */
2134 for (i = 0; i < MAX_PIPES; i++) {
2135 struct pipe_ctx *pipe_ctx_old =
2136 &dc->current_state->res_ctx.pipe_ctx[i];
2137 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2139 /* Note: We need to disable output if clock sources change,
2140 * since bios does optimization and doesn't apply if changing
2141 * PHY when not already disabled.
2144 /* Skip underlay pipe since it will be handled in commit surface*/
2145 if (!pipe_ctx_old->stream || pipe_ctx_old->top_pipe)
2148 if (!pipe_ctx->stream ||
2149 pipe_need_reprogram(pipe_ctx_old, pipe_ctx)) {
2150 struct clock_source *old_clk = pipe_ctx_old->clock_source;
2152 /* Disable if new stream is null. O/w, if stream is
2153 * disabled already, no need to disable again.
2155 if (!pipe_ctx->stream || !pipe_ctx->stream->dpms_off) {
2156 core_link_disable_stream(pipe_ctx_old);
2158 /* free acquired resources*/
2159 if (pipe_ctx_old->stream_res.audio) {
2160 /*disable az_endpoint*/
2161 pipe_ctx_old->stream_res.audio->funcs->
2162 az_disable(pipe_ctx_old->stream_res.audio);
2165 if (dc->caps.dynamic_audio == true) {
2166 /*we have to dynamic arbitrate the audio endpoints*/
2167 /*we free the resource, need reset is_audio_acquired*/
2168 update_audio_usage(&dc->current_state->res_ctx, dc->res_pool,
2169 pipe_ctx_old->stream_res.audio, false);
2170 pipe_ctx_old->stream_res.audio = NULL;
2175 pipe_ctx_old->stream_res.tg->funcs->set_blank(pipe_ctx_old->stream_res.tg, true);
2176 if (!hwss_wait_for_blank_complete(pipe_ctx_old->stream_res.tg)) {
2177 dm_error("DC: failed to blank crtc!\n");
2178 BREAK_TO_DEBUGGER();
2180 pipe_ctx_old->stream_res.tg->funcs->disable_crtc(pipe_ctx_old->stream_res.tg);
2181 pipe_ctx_old->plane_res.mi->funcs->free_mem_input(
2182 pipe_ctx_old->plane_res.mi, dc->current_state->stream_count);
2184 if (old_clk && 0 == resource_get_clock_source_reference(&context->res_ctx,
2187 old_clk->funcs->cs_power_down(old_clk);
2189 dc->hwss.disable_plane(dc, pipe_ctx_old);
2191 pipe_ctx_old->stream = NULL;
2196 static void dce110_setup_audio_dto(
2198 struct dc_state *context)
2202 /* program audio wall clock. use HDMI as clock source if HDMI
2203 * audio active. Otherwise, use DP as clock source
2204 * first, loop to find any HDMI audio, if not, loop find DP audio
2206 /* Setup audio rate clock source */
2208 * Audio lag happened on DP monitor when unplug a HDMI monitor
2211 * In case of DP and HDMI connected or HDMI only, DCCG_AUDIO_DTO_SEL
2212 * is set to either dto0 or dto1, audio should work fine.
2213 * In case of DP connected only, DCCG_AUDIO_DTO_SEL should be dto1,
2214 * set to dto0 will cause audio lag.
2217 * Not optimized audio wall dto setup. When mode set, iterate pipe_ctx,
2218 * find first available pipe with audio, setup audio wall DTO per topology
2219 * instead of per pipe.
2221 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2222 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2224 if (pipe_ctx->stream == NULL)
2227 if (pipe_ctx->top_pipe)
2229 if (pipe_ctx->stream->signal != SIGNAL_TYPE_HDMI_TYPE_A)
2231 if (pipe_ctx->stream_res.audio != NULL) {
2232 struct audio_output audio_output;
2234 build_audio_output(context, pipe_ctx, &audio_output);
2236 #if defined(CONFIG_DRM_AMD_DC_DCN)
2237 /* For DCN3.1, audio to HPO FRL encoder is using audio DTBCLK DTO */
2238 if (dc->res_pool->dccg && dc->res_pool->dccg->funcs->set_audio_dtbclk_dto) {
2239 /* disable audio DTBCLK DTO */
2240 dc->res_pool->dccg->funcs->set_audio_dtbclk_dto(
2241 dc->res_pool->dccg, 0);
2243 pipe_ctx->stream_res.audio->funcs->wall_dto_setup(
2244 pipe_ctx->stream_res.audio,
2245 pipe_ctx->stream->signal,
2246 &audio_output.crtc_info,
2247 &audio_output.pll_info);
2249 pipe_ctx->stream_res.audio->funcs->wall_dto_setup(
2250 pipe_ctx->stream_res.audio,
2251 pipe_ctx->stream->signal,
2252 &audio_output.crtc_info,
2253 &audio_output.pll_info);
2255 pipe_ctx->stream_res.audio->funcs->wall_dto_setup(
2256 pipe_ctx->stream_res.audio,
2257 pipe_ctx->stream->signal,
2258 &audio_output.crtc_info,
2259 &audio_output.pll_info);
2265 /* no HDMI audio is found, try DP audio */
2266 if (i == dc->res_pool->pipe_count) {
2267 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2268 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2270 if (pipe_ctx->stream == NULL)
2273 if (pipe_ctx->top_pipe)
2276 if (!dc_is_dp_signal(pipe_ctx->stream->signal))
2279 if (pipe_ctx->stream_res.audio != NULL) {
2280 struct audio_output audio_output;
2282 build_audio_output(context, pipe_ctx, &audio_output);
2284 pipe_ctx->stream_res.audio->funcs->wall_dto_setup(
2285 pipe_ctx->stream_res.audio,
2286 pipe_ctx->stream->signal,
2287 &audio_output.crtc_info,
2288 &audio_output.pll_info);
2295 enum dc_status dce110_apply_ctx_to_hw(
2297 struct dc_state *context)
2299 struct dce_hwseq *hws = dc->hwseq;
2300 struct dc_bios *dcb = dc->ctx->dc_bios;
2301 enum dc_status status;
2304 /* reset syncd pipes from disabled pipes */
2305 if (dc->config.use_pipe_ctx_sync_logic)
2306 reset_syncd_pipes_from_disabled_pipes(dc, context);
2308 /* Reset old context */
2309 /* look up the targets that have been removed since last commit */
2310 hws->funcs.reset_hw_ctx_wrap(dc, context);
2312 /* Skip applying if no targets */
2313 if (context->stream_count <= 0)
2316 /* Apply new context */
2317 dcb->funcs->set_scratch_critical_state(dcb, true);
2319 /* below is for real asic only */
2320 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2321 struct pipe_ctx *pipe_ctx_old =
2322 &dc->current_state->res_ctx.pipe_ctx[i];
2323 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2325 if (pipe_ctx->stream == NULL || pipe_ctx->top_pipe)
2328 if (pipe_ctx->stream == pipe_ctx_old->stream) {
2329 if (pipe_ctx_old->clock_source != pipe_ctx->clock_source)
2330 dce_crtc_switch_to_clk_src(dc->hwseq,
2331 pipe_ctx->clock_source, i);
2335 hws->funcs.enable_display_power_gating(
2336 dc, i, dc->ctx->dc_bios,
2337 PIPE_GATING_CONTROL_DISABLE);
2340 if (dc->fbc_compressor)
2341 dc->fbc_compressor->funcs->disable_fbc(dc->fbc_compressor);
2343 dce110_setup_audio_dto(dc, context);
2345 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2346 struct pipe_ctx *pipe_ctx_old =
2347 &dc->current_state->res_ctx.pipe_ctx[i];
2348 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2350 if (pipe_ctx->stream == NULL)
2353 if (pipe_ctx->stream == pipe_ctx_old->stream &&
2354 pipe_ctx->stream->link->link_state_valid) {
2358 if (pipe_ctx_old->stream && !pipe_need_reprogram(pipe_ctx_old, pipe_ctx))
2361 if (pipe_ctx->top_pipe || pipe_ctx->prev_odm_pipe)
2364 status = apply_single_controller_ctx_to_hw(
2369 if (DC_OK != status)
2373 if (dc->fbc_compressor)
2374 enable_fbc(dc, dc->current_state);
2376 dcb->funcs->set_scratch_critical_state(dcb, false);
2381 /*******************************************************************************
2382 * Front End programming
2383 ******************************************************************************/
2384 static void set_default_colors(struct pipe_ctx *pipe_ctx)
2386 struct default_adjustment default_adjust = { 0 };
2388 default_adjust.force_hw_default = false;
2389 default_adjust.in_color_space = pipe_ctx->plane_state->color_space;
2390 default_adjust.out_color_space = pipe_ctx->stream->output_color_space;
2391 default_adjust.csc_adjust_type = GRAPHICS_CSC_ADJUST_TYPE_SW;
2392 default_adjust.surface_pixel_format = pipe_ctx->plane_res.scl_data.format;
2394 /* display color depth */
2395 default_adjust.color_depth =
2396 pipe_ctx->stream->timing.display_color_depth;
2398 /* Lb color depth */
2399 default_adjust.lb_color_depth = pipe_ctx->plane_res.scl_data.lb_params.depth;
2401 pipe_ctx->plane_res.xfm->funcs->opp_set_csc_default(
2402 pipe_ctx->plane_res.xfm, &default_adjust);
2406 /*******************************************************************************
2407 * In order to turn on/off specific surface we will program
2410 * In case that we have two surfaces and they have a different visibility
2411 * we can't turn off the CRTC since it will turn off the entire display
2413 * |----------------------------------------------- |
2414 * |bottom pipe|curr pipe | | |
2415 * |Surface |Surface | Blender | CRCT |
2416 * |visibility |visibility | Configuration| |
2417 * |------------------------------------------------|
2418 * | off | off | CURRENT_PIPE | blank |
2419 * | off | on | CURRENT_PIPE | unblank |
2420 * | on | off | OTHER_PIPE | unblank |
2421 * | on | on | BLENDING | unblank |
2422 * -------------------------------------------------|
2424 ******************************************************************************/
2425 static void program_surface_visibility(const struct dc *dc,
2426 struct pipe_ctx *pipe_ctx)
2428 enum blnd_mode blender_mode = BLND_MODE_CURRENT_PIPE;
2429 bool blank_target = false;
2431 if (pipe_ctx->bottom_pipe) {
2433 /* For now we are supporting only two pipes */
2434 ASSERT(pipe_ctx->bottom_pipe->bottom_pipe == NULL);
2436 if (pipe_ctx->bottom_pipe->plane_state->visible) {
2437 if (pipe_ctx->plane_state->visible)
2438 blender_mode = BLND_MODE_BLENDING;
2440 blender_mode = BLND_MODE_OTHER_PIPE;
2442 } else if (!pipe_ctx->plane_state->visible)
2443 blank_target = true;
2445 } else if (!pipe_ctx->plane_state->visible)
2446 blank_target = true;
2448 dce_set_blender_mode(dc->hwseq, pipe_ctx->stream_res.tg->inst, blender_mode);
2449 pipe_ctx->stream_res.tg->funcs->set_blank(pipe_ctx->stream_res.tg, blank_target);
2453 static void program_gamut_remap(struct pipe_ctx *pipe_ctx)
2456 struct xfm_grph_csc_adjustment adjust;
2457 memset(&adjust, 0, sizeof(adjust));
2458 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS;
2461 if (pipe_ctx->stream->gamut_remap_matrix.enable_remap == true) {
2462 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_SW;
2464 for (i = 0; i < CSC_TEMPERATURE_MATRIX_SIZE; i++)
2465 adjust.temperature_matrix[i] =
2466 pipe_ctx->stream->gamut_remap_matrix.matrix[i];
2469 pipe_ctx->plane_res.xfm->funcs->transform_set_gamut_remap(pipe_ctx->plane_res.xfm, &adjust);
2471 static void update_plane_addr(const struct dc *dc,
2472 struct pipe_ctx *pipe_ctx)
2474 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
2476 if (plane_state == NULL)
2479 pipe_ctx->plane_res.mi->funcs->mem_input_program_surface_flip_and_addr(
2480 pipe_ctx->plane_res.mi,
2481 &plane_state->address,
2482 plane_state->flip_immediate);
2484 plane_state->status.requested_address = plane_state->address;
2487 static void dce110_update_pending_status(struct pipe_ctx *pipe_ctx)
2489 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
2491 if (plane_state == NULL)
2494 plane_state->status.is_flip_pending =
2495 pipe_ctx->plane_res.mi->funcs->mem_input_is_flip_pending(
2496 pipe_ctx->plane_res.mi);
2498 if (plane_state->status.is_flip_pending && !plane_state->visible)
2499 pipe_ctx->plane_res.mi->current_address = pipe_ctx->plane_res.mi->request_address;
2501 plane_state->status.current_address = pipe_ctx->plane_res.mi->current_address;
2502 if (pipe_ctx->plane_res.mi->current_address.type == PLN_ADDR_TYPE_GRPH_STEREO &&
2503 pipe_ctx->stream_res.tg->funcs->is_stereo_left_eye) {
2504 plane_state->status.is_right_eye =\
2505 !pipe_ctx->stream_res.tg->funcs->is_stereo_left_eye(pipe_ctx->stream_res.tg);
2509 void dce110_power_down(struct dc *dc)
2511 power_down_all_hw_blocks(dc);
2512 disable_vga_and_power_gate_all_controllers(dc);
2515 static bool wait_for_reset_trigger_to_occur(
2516 struct dc_context *dc_ctx,
2517 struct timing_generator *tg)
2521 /* To avoid endless loop we wait at most
2522 * frames_to_wait_on_triggered_reset frames for the reset to occur. */
2523 const uint32_t frames_to_wait_on_triggered_reset = 10;
2526 for (i = 0; i < frames_to_wait_on_triggered_reset; i++) {
2528 if (!tg->funcs->is_counter_moving(tg)) {
2529 DC_ERROR("TG counter is not moving!\n");
2533 if (tg->funcs->did_triggered_reset_occur(tg)) {
2535 /* usually occurs at i=1 */
2536 DC_SYNC_INFO("GSL: reset occurred at wait count: %d\n",
2541 /* Wait for one frame. */
2542 tg->funcs->wait_for_state(tg, CRTC_STATE_VACTIVE);
2543 tg->funcs->wait_for_state(tg, CRTC_STATE_VBLANK);
2547 DC_ERROR("GSL: Timeout on reset trigger!\n");
2552 /* Enable timing synchronization for a group of Timing Generators. */
2553 static void dce110_enable_timing_synchronization(
2557 struct pipe_ctx *grouped_pipes[])
2559 struct dc_context *dc_ctx = dc->ctx;
2560 struct dcp_gsl_params gsl_params = { 0 };
2563 DC_SYNC_INFO("GSL: Setting-up...\n");
2565 /* Designate a single TG in the group as a master.
2566 * Since HW doesn't care which one, we always assign
2567 * the 1st one in the group. */
2568 gsl_params.gsl_group = 0;
2569 gsl_params.gsl_master = grouped_pipes[0]->stream_res.tg->inst;
2571 for (i = 0; i < group_size; i++)
2572 grouped_pipes[i]->stream_res.tg->funcs->setup_global_swap_lock(
2573 grouped_pipes[i]->stream_res.tg, &gsl_params);
2575 /* Reset slave controllers on master VSync */
2576 DC_SYNC_INFO("GSL: enabling trigger-reset\n");
2578 for (i = 1 /* skip the master */; i < group_size; i++)
2579 grouped_pipes[i]->stream_res.tg->funcs->enable_reset_trigger(
2580 grouped_pipes[i]->stream_res.tg,
2581 gsl_params.gsl_group);
2583 for (i = 1 /* skip the master */; i < group_size; i++) {
2584 DC_SYNC_INFO("GSL: waiting for reset to occur.\n");
2585 wait_for_reset_trigger_to_occur(dc_ctx, grouped_pipes[i]->stream_res.tg);
2586 grouped_pipes[i]->stream_res.tg->funcs->disable_reset_trigger(
2587 grouped_pipes[i]->stream_res.tg);
2590 /* GSL Vblank synchronization is a one time sync mechanism, assumption
2591 * is that the sync'ed displays will not drift out of sync over time*/
2592 DC_SYNC_INFO("GSL: Restoring register states.\n");
2593 for (i = 0; i < group_size; i++)
2594 grouped_pipes[i]->stream_res.tg->funcs->tear_down_global_swap_lock(grouped_pipes[i]->stream_res.tg);
2596 DC_SYNC_INFO("GSL: Set-up complete.\n");
2599 static void dce110_enable_per_frame_crtc_position_reset(
2602 struct pipe_ctx *grouped_pipes[])
2604 struct dc_context *dc_ctx = dc->ctx;
2605 struct dcp_gsl_params gsl_params = { 0 };
2608 gsl_params.gsl_group = 0;
2609 gsl_params.gsl_master = 0;
2611 for (i = 0; i < group_size; i++)
2612 grouped_pipes[i]->stream_res.tg->funcs->setup_global_swap_lock(
2613 grouped_pipes[i]->stream_res.tg, &gsl_params);
2615 DC_SYNC_INFO("GSL: enabling trigger-reset\n");
2617 for (i = 1; i < group_size; i++)
2618 grouped_pipes[i]->stream_res.tg->funcs->enable_crtc_reset(
2619 grouped_pipes[i]->stream_res.tg,
2620 gsl_params.gsl_master,
2621 &grouped_pipes[i]->stream->triggered_crtc_reset);
2623 DC_SYNC_INFO("GSL: waiting for reset to occur.\n");
2624 for (i = 1; i < group_size; i++)
2625 wait_for_reset_trigger_to_occur(dc_ctx, grouped_pipes[i]->stream_res.tg);
2627 for (i = 0; i < group_size; i++)
2628 grouped_pipes[i]->stream_res.tg->funcs->tear_down_global_swap_lock(grouped_pipes[i]->stream_res.tg);
2632 static void init_pipes(struct dc *dc, struct dc_state *context)
2637 static void init_hw(struct dc *dc)
2641 struct transform *xfm;
2644 struct dce_hwseq *hws = dc->hwseq;
2645 uint32_t backlight = MAX_BACKLIGHT_LEVEL;
2647 bp = dc->ctx->dc_bios;
2648 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2649 xfm = dc->res_pool->transforms[i];
2650 xfm->funcs->transform_reset(xfm);
2652 hws->funcs.enable_display_power_gating(
2654 PIPE_GATING_CONTROL_INIT);
2655 hws->funcs.enable_display_power_gating(
2657 PIPE_GATING_CONTROL_DISABLE);
2658 hws->funcs.enable_display_pipe_clock_gating(
2663 dce_clock_gating_power_up(dc->hwseq, false);
2664 /***************************************/
2666 for (i = 0; i < dc->link_count; i++) {
2667 /****************************************/
2668 /* Power up AND update implementation according to the
2669 * required signal (which may be different from the
2670 * default signal on connector). */
2671 struct dc_link *link = dc->links[i];
2673 link->link_enc->funcs->hw_init(link->link_enc);
2676 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2677 struct timing_generator *tg = dc->res_pool->timing_generators[i];
2679 tg->funcs->disable_vga(tg);
2681 /* Blank controller using driver code instead of
2683 tg->funcs->set_blank(tg, true);
2684 hwss_wait_for_blank_complete(tg);
2687 for (i = 0; i < dc->res_pool->audio_count; i++) {
2688 struct audio *audio = dc->res_pool->audios[i];
2689 audio->funcs->hw_init(audio);
2692 for (i = 0; i < dc->link_count; i++) {
2693 struct dc_link *link = dc->links[i];
2695 if (link->panel_cntl)
2696 backlight = link->panel_cntl->funcs->hw_init(link->panel_cntl);
2699 abm = dc->res_pool->abm;
2701 abm->funcs->abm_init(abm, backlight);
2703 dmcu = dc->res_pool->dmcu;
2704 if (dmcu != NULL && abm != NULL)
2705 abm->dmcu_is_running = dmcu->funcs->is_dmcu_initialized(dmcu);
2707 if (dc->fbc_compressor)
2708 dc->fbc_compressor->funcs->power_up_fbc(dc->fbc_compressor);
2713 void dce110_prepare_bandwidth(
2715 struct dc_state *context)
2717 struct clk_mgr *dccg = dc->clk_mgr;
2719 dce110_set_safe_displaymarks(&context->res_ctx, dc->res_pool);
2721 dccg->funcs->update_clocks(
2727 void dce110_optimize_bandwidth(
2729 struct dc_state *context)
2731 struct clk_mgr *dccg = dc->clk_mgr;
2733 dce110_set_displaymarks(dc, context);
2735 dccg->funcs->update_clocks(
2741 static void dce110_program_front_end_for_pipe(
2742 struct dc *dc, struct pipe_ctx *pipe_ctx)
2744 struct mem_input *mi = pipe_ctx->plane_res.mi;
2745 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
2746 struct xfm_grph_csc_adjustment adjust;
2747 struct out_csc_color_matrix tbl_entry;
2749 struct dce_hwseq *hws = dc->hwseq;
2752 memset(&tbl_entry, 0, sizeof(tbl_entry));
2754 memset(&adjust, 0, sizeof(adjust));
2755 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS;
2757 dce_enable_fe_clock(dc->hwseq, mi->inst, true);
2759 set_default_colors(pipe_ctx);
2760 if (pipe_ctx->stream->csc_color_matrix.enable_adjustment
2762 tbl_entry.color_space =
2763 pipe_ctx->stream->output_color_space;
2765 for (i = 0; i < 12; i++)
2766 tbl_entry.regval[i] =
2767 pipe_ctx->stream->csc_color_matrix.matrix[i];
2769 pipe_ctx->plane_res.xfm->funcs->opp_set_csc_adjustment
2770 (pipe_ctx->plane_res.xfm, &tbl_entry);
2773 if (pipe_ctx->stream->gamut_remap_matrix.enable_remap == true) {
2774 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_SW;
2776 for (i = 0; i < CSC_TEMPERATURE_MATRIX_SIZE; i++)
2777 adjust.temperature_matrix[i] =
2778 pipe_ctx->stream->gamut_remap_matrix.matrix[i];
2781 pipe_ctx->plane_res.xfm->funcs->transform_set_gamut_remap(pipe_ctx->plane_res.xfm, &adjust);
2783 pipe_ctx->plane_res.scl_data.lb_params.alpha_en = pipe_ctx->bottom_pipe != 0;
2785 program_scaler(dc, pipe_ctx);
2787 mi->funcs->mem_input_program_surface_config(
2789 plane_state->format,
2790 &plane_state->tiling_info,
2791 &plane_state->plane_size,
2792 plane_state->rotation,
2795 if (mi->funcs->set_blank)
2796 mi->funcs->set_blank(mi, pipe_ctx->plane_state->visible);
2798 if (dc->config.gpu_vm_support)
2799 mi->funcs->mem_input_program_pte_vm(
2800 pipe_ctx->plane_res.mi,
2801 plane_state->format,
2802 &plane_state->tiling_info,
2803 plane_state->rotation);
2805 /* Moved programming gamma from dc to hwss */
2806 if (pipe_ctx->plane_state->update_flags.bits.full_update ||
2807 pipe_ctx->plane_state->update_flags.bits.in_transfer_func_change ||
2808 pipe_ctx->plane_state->update_flags.bits.gamma_change)
2809 hws->funcs.set_input_transfer_func(dc, pipe_ctx, pipe_ctx->plane_state);
2811 if (pipe_ctx->plane_state->update_flags.bits.full_update)
2812 hws->funcs.set_output_transfer_func(dc, pipe_ctx, pipe_ctx->stream);
2815 "Pipe:%d %p: addr hi:0x%x, "
2818 " %d; dst: %d, %d, %d, %d;"
2819 "clip: %d, %d, %d, %d\n",
2821 (void *) pipe_ctx->plane_state,
2822 pipe_ctx->plane_state->address.grph.addr.high_part,
2823 pipe_ctx->plane_state->address.grph.addr.low_part,
2824 pipe_ctx->plane_state->src_rect.x,
2825 pipe_ctx->plane_state->src_rect.y,
2826 pipe_ctx->plane_state->src_rect.width,
2827 pipe_ctx->plane_state->src_rect.height,
2828 pipe_ctx->plane_state->dst_rect.x,
2829 pipe_ctx->plane_state->dst_rect.y,
2830 pipe_ctx->plane_state->dst_rect.width,
2831 pipe_ctx->plane_state->dst_rect.height,
2832 pipe_ctx->plane_state->clip_rect.x,
2833 pipe_ctx->plane_state->clip_rect.y,
2834 pipe_ctx->plane_state->clip_rect.width,
2835 pipe_ctx->plane_state->clip_rect.height);
2838 "Pipe %d: width, height, x, y\n"
2839 "viewport:%d, %d, %d, %d\n"
2840 "recout: %d, %d, %d, %d\n",
2842 pipe_ctx->plane_res.scl_data.viewport.width,
2843 pipe_ctx->plane_res.scl_data.viewport.height,
2844 pipe_ctx->plane_res.scl_data.viewport.x,
2845 pipe_ctx->plane_res.scl_data.viewport.y,
2846 pipe_ctx->plane_res.scl_data.recout.width,
2847 pipe_ctx->plane_res.scl_data.recout.height,
2848 pipe_ctx->plane_res.scl_data.recout.x,
2849 pipe_ctx->plane_res.scl_data.recout.y);
2852 static void dce110_apply_ctx_for_surface(
2854 const struct dc_stream_state *stream,
2856 struct dc_state *context)
2860 if (num_planes == 0)
2863 if (dc->fbc_compressor)
2864 dc->fbc_compressor->funcs->disable_fbc(dc->fbc_compressor);
2866 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2867 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2869 if (pipe_ctx->stream != stream)
2872 /* Need to allocate mem before program front end for Fiji */
2873 pipe_ctx->plane_res.mi->funcs->allocate_mem_input(
2874 pipe_ctx->plane_res.mi,
2875 pipe_ctx->stream->timing.h_total,
2876 pipe_ctx->stream->timing.v_total,
2877 pipe_ctx->stream->timing.pix_clk_100hz / 10,
2878 context->stream_count);
2880 dce110_program_front_end_for_pipe(dc, pipe_ctx);
2882 dc->hwss.update_plane_addr(dc, pipe_ctx);
2884 program_surface_visibility(dc, pipe_ctx);
2888 if (dc->fbc_compressor)
2889 enable_fbc(dc, context);
2892 static void dce110_post_unlock_program_front_end(
2894 struct dc_state *context)
2898 static void dce110_power_down_fe(struct dc *dc, struct pipe_ctx *pipe_ctx)
2900 struct dce_hwseq *hws = dc->hwseq;
2901 int fe_idx = pipe_ctx->plane_res.mi ?
2902 pipe_ctx->plane_res.mi->inst : pipe_ctx->pipe_idx;
2904 /* Do not power down fe when stream is active on dce*/
2905 if (dc->current_state->res_ctx.pipe_ctx[fe_idx].stream)
2908 hws->funcs.enable_display_power_gating(
2909 dc, fe_idx, dc->ctx->dc_bios, PIPE_GATING_CONTROL_ENABLE);
2911 dc->res_pool->transforms[fe_idx]->funcs->transform_reset(
2912 dc->res_pool->transforms[fe_idx]);
2915 static void dce110_wait_for_mpcc_disconnect(
2917 struct resource_pool *res_pool,
2918 struct pipe_ctx *pipe_ctx)
2923 static void program_output_csc(struct dc *dc,
2924 struct pipe_ctx *pipe_ctx,
2925 enum dc_color_space colorspace,
2930 struct out_csc_color_matrix tbl_entry;
2932 if (pipe_ctx->stream->csc_color_matrix.enable_adjustment == true) {
2933 enum dc_color_space color_space = pipe_ctx->stream->output_color_space;
2935 for (i = 0; i < 12; i++)
2936 tbl_entry.regval[i] = pipe_ctx->stream->csc_color_matrix.matrix[i];
2938 tbl_entry.color_space = color_space;
2940 pipe_ctx->plane_res.xfm->funcs->opp_set_csc_adjustment(
2941 pipe_ctx->plane_res.xfm, &tbl_entry);
2945 static void dce110_set_cursor_position(struct pipe_ctx *pipe_ctx)
2947 struct dc_cursor_position pos_cpy = pipe_ctx->stream->cursor_position;
2948 struct input_pixel_processor *ipp = pipe_ctx->plane_res.ipp;
2949 struct mem_input *mi = pipe_ctx->plane_res.mi;
2950 struct dc_cursor_mi_param param = {
2951 .pixel_clk_khz = pipe_ctx->stream->timing.pix_clk_100hz / 10,
2952 .ref_clk_khz = pipe_ctx->stream->ctx->dc->res_pool->ref_clocks.xtalin_clock_inKhz,
2953 .viewport = pipe_ctx->plane_res.scl_data.viewport,
2954 .h_scale_ratio = pipe_ctx->plane_res.scl_data.ratios.horz,
2955 .v_scale_ratio = pipe_ctx->plane_res.scl_data.ratios.vert,
2956 .rotation = pipe_ctx->plane_state->rotation,
2957 .mirror = pipe_ctx->plane_state->horizontal_mirror
2961 * If the cursor's source viewport is clipped then we need to
2962 * translate the cursor to appear in the correct position on
2965 * This translation isn't affected by scaling so it needs to be
2966 * done *after* we adjust the position for the scale factor.
2968 * This is only done by opt-in for now since there are still
2969 * some usecases like tiled display that might enable the
2970 * cursor on both streams while expecting dc to clip it.
2972 if (pos_cpy.translate_by_source) {
2973 pos_cpy.x += pipe_ctx->plane_state->src_rect.x;
2974 pos_cpy.y += pipe_ctx->plane_state->src_rect.y;
2977 if (pipe_ctx->plane_state->address.type
2978 == PLN_ADDR_TYPE_VIDEO_PROGRESSIVE)
2979 pos_cpy.enable = false;
2981 if (pipe_ctx->top_pipe && pipe_ctx->plane_state != pipe_ctx->top_pipe->plane_state)
2982 pos_cpy.enable = false;
2984 if (ipp->funcs->ipp_cursor_set_position)
2985 ipp->funcs->ipp_cursor_set_position(ipp, &pos_cpy, ¶m);
2986 if (mi->funcs->set_cursor_position)
2987 mi->funcs->set_cursor_position(mi, &pos_cpy, ¶m);
2990 static void dce110_set_cursor_attribute(struct pipe_ctx *pipe_ctx)
2992 struct dc_cursor_attributes *attributes = &pipe_ctx->stream->cursor_attributes;
2994 if (pipe_ctx->plane_res.ipp &&
2995 pipe_ctx->plane_res.ipp->funcs->ipp_cursor_set_attributes)
2996 pipe_ctx->plane_res.ipp->funcs->ipp_cursor_set_attributes(
2997 pipe_ctx->plane_res.ipp, attributes);
2999 if (pipe_ctx->plane_res.mi &&
3000 pipe_ctx->plane_res.mi->funcs->set_cursor_attributes)
3001 pipe_ctx->plane_res.mi->funcs->set_cursor_attributes(
3002 pipe_ctx->plane_res.mi, attributes);
3004 if (pipe_ctx->plane_res.xfm &&
3005 pipe_ctx->plane_res.xfm->funcs->set_cursor_attributes)
3006 pipe_ctx->plane_res.xfm->funcs->set_cursor_attributes(
3007 pipe_ctx->plane_res.xfm, attributes);
3010 bool dce110_set_backlight_level(struct pipe_ctx *pipe_ctx,
3011 uint32_t backlight_pwm_u16_16,
3012 uint32_t frame_ramp)
3014 struct dc_link *link = pipe_ctx->stream->link;
3015 struct dc *dc = link->ctx->dc;
3016 struct abm *abm = pipe_ctx->stream_res.abm;
3017 struct panel_cntl *panel_cntl = link->panel_cntl;
3018 struct dmcu *dmcu = dc->res_pool->dmcu;
3019 bool fw_set_brightness = true;
3020 /* DMCU -1 for all controller id values,
3023 uint32_t controller_id = pipe_ctx->stream_res.tg->inst + 1;
3025 if (abm == NULL || panel_cntl == NULL || (abm->funcs->set_backlight_level_pwm == NULL))
3029 fw_set_brightness = dmcu->funcs->is_dmcu_initialized(dmcu);
3031 if (!fw_set_brightness && panel_cntl->funcs->driver_set_backlight)
3032 panel_cntl->funcs->driver_set_backlight(panel_cntl, backlight_pwm_u16_16);
3034 abm->funcs->set_backlight_level_pwm(
3036 backlight_pwm_u16_16,
3039 link->panel_cntl->inst);
3044 void dce110_set_abm_immediate_disable(struct pipe_ctx *pipe_ctx)
3046 struct abm *abm = pipe_ctx->stream_res.abm;
3047 struct panel_cntl *panel_cntl = pipe_ctx->stream->link->panel_cntl;
3050 abm->funcs->set_abm_immediate_disable(abm,
3051 pipe_ctx->stream->link->panel_cntl->inst);
3054 panel_cntl->funcs->store_backlight_level(panel_cntl);
3057 void dce110_set_pipe(struct pipe_ctx *pipe_ctx)
3059 struct abm *abm = pipe_ctx->stream_res.abm;
3060 struct panel_cntl *panel_cntl = pipe_ctx->stream->link->panel_cntl;
3061 uint32_t otg_inst = pipe_ctx->stream_res.tg->inst + 1;
3063 if (abm && panel_cntl)
3064 abm->funcs->set_pipe(abm, otg_inst, panel_cntl->inst);
3067 static const struct hw_sequencer_funcs dce110_funcs = {
3068 .program_gamut_remap = program_gamut_remap,
3069 .program_output_csc = program_output_csc,
3071 .apply_ctx_to_hw = dce110_apply_ctx_to_hw,
3072 .apply_ctx_for_surface = dce110_apply_ctx_for_surface,
3073 .post_unlock_program_front_end = dce110_post_unlock_program_front_end,
3074 .update_plane_addr = update_plane_addr,
3075 .update_pending_status = dce110_update_pending_status,
3076 .enable_accelerated_mode = dce110_enable_accelerated_mode,
3077 .enable_timing_synchronization = dce110_enable_timing_synchronization,
3078 .enable_per_frame_crtc_position_reset = dce110_enable_per_frame_crtc_position_reset,
3079 .update_info_frame = dce110_update_info_frame,
3080 .enable_stream = dce110_enable_stream,
3081 .disable_stream = dce110_disable_stream,
3082 .unblank_stream = dce110_unblank_stream,
3083 .blank_stream = dce110_blank_stream,
3084 .enable_audio_stream = dce110_enable_audio_stream,
3085 .disable_audio_stream = dce110_disable_audio_stream,
3086 .disable_plane = dce110_power_down_fe,
3087 .pipe_control_lock = dce_pipe_control_lock,
3088 .interdependent_update_lock = NULL,
3089 .cursor_lock = dce_pipe_control_lock,
3090 .prepare_bandwidth = dce110_prepare_bandwidth,
3091 .optimize_bandwidth = dce110_optimize_bandwidth,
3093 .get_position = get_position,
3094 .set_static_screen_control = set_static_screen_control,
3095 .setup_stereo = NULL,
3096 .set_avmute = dce110_set_avmute,
3097 .wait_for_mpcc_disconnect = dce110_wait_for_mpcc_disconnect,
3098 .edp_backlight_control = dce110_edp_backlight_control,
3099 .edp_power_control = dce110_edp_power_control,
3100 .edp_wait_for_hpd_ready = dce110_edp_wait_for_hpd_ready,
3101 .set_cursor_position = dce110_set_cursor_position,
3102 .set_cursor_attribute = dce110_set_cursor_attribute,
3103 .set_backlight_level = dce110_set_backlight_level,
3104 .set_abm_immediate_disable = dce110_set_abm_immediate_disable,
3105 .set_pipe = dce110_set_pipe,
3108 static const struct hwseq_private_funcs dce110_private_funcs = {
3109 .init_pipes = init_pipes,
3110 .update_plane_addr = update_plane_addr,
3111 .set_input_transfer_func = dce110_set_input_transfer_func,
3112 .set_output_transfer_func = dce110_set_output_transfer_func,
3113 .power_down = dce110_power_down,
3114 .enable_display_pipe_clock_gating = enable_display_pipe_clock_gating,
3115 .enable_display_power_gating = dce110_enable_display_power_gating,
3116 .reset_hw_ctx_wrap = dce110_reset_hw_ctx_wrap,
3117 .enable_stream_timing = dce110_enable_stream_timing,
3118 .disable_stream_gating = NULL,
3119 .enable_stream_gating = NULL,
3120 .edp_backlight_control = dce110_edp_backlight_control,
3123 void dce110_hw_sequencer_construct(struct dc *dc)
3125 dc->hwss = dce110_funcs;
3126 dc->hwseq->funcs = dce110_private_funcs;