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 #if defined(CONFIG_DRM_AMD_DC_DCN)
1570 /* DCN3.1 FPGA Workaround
1571 * Need to enable HPO DP Stream Encoder before setting OTG master enable.
1572 * To do so, move calling function enable_stream_timing to only be done AFTER calling
1573 * function core_link_enable_stream
1575 if (!(hws->wa.dp_hpo_and_otg_sequence && is_dp_128b_132b_signal(pipe_ctx)))
1578 /* Do not touch stream timing on seamless boot optimization. */
1579 if (!pipe_ctx->stream->apply_seamless_boot_optimization)
1580 hws->funcs.enable_stream_timing(pipe_ctx, context, dc);
1582 if (hws->funcs.setup_vupdate_interrupt)
1583 hws->funcs.setup_vupdate_interrupt(dc, pipe_ctx);
1585 params.vertical_total_min = stream->adjust.v_total_min;
1586 params.vertical_total_max = stream->adjust.v_total_max;
1587 if (pipe_ctx->stream_res.tg->funcs->set_drr)
1588 pipe_ctx->stream_res.tg->funcs->set_drr(
1589 pipe_ctx->stream_res.tg, ¶ms);
1591 // DRR should set trigger event to monitor surface update event
1592 if (stream->adjust.v_total_min != 0 && stream->adjust.v_total_max != 0)
1593 event_triggers = 0x80;
1594 /* Event triggers and num frames initialized for DRR, but can be
1595 * later updated for PSR use. Note DRR trigger events are generated
1596 * regardless of whether num frames met.
1598 if (pipe_ctx->stream_res.tg->funcs->set_static_screen_control)
1599 pipe_ctx->stream_res.tg->funcs->set_static_screen_control(
1600 pipe_ctx->stream_res.tg, event_triggers, 2);
1602 if (!dc_is_virtual_signal(pipe_ctx->stream->signal))
1603 pipe_ctx->stream_res.stream_enc->funcs->dig_connect_to_otg(
1604 pipe_ctx->stream_res.stream_enc,
1605 pipe_ctx->stream_res.tg->inst);
1607 if (dc_is_dp_signal(pipe_ctx->stream->signal) &&
1608 pipe_ctx->stream_res.stream_enc->funcs->reset_fifo)
1609 pipe_ctx->stream_res.stream_enc->funcs->reset_fifo(
1610 pipe_ctx->stream_res.stream_enc);
1612 if (dc_is_dp_signal(pipe_ctx->stream->signal))
1613 dp_source_sequence_trace(link, DPCD_SOURCE_SEQ_AFTER_CONNECT_DIG_FE_OTG);
1615 pipe_ctx->stream_res.opp->funcs->opp_set_dyn_expansion(
1616 pipe_ctx->stream_res.opp,
1617 COLOR_SPACE_YCBCR601,
1618 stream->timing.display_color_depth,
1621 pipe_ctx->stream_res.opp->funcs->opp_program_fmt(
1622 pipe_ctx->stream_res.opp,
1623 &stream->bit_depth_params,
1626 odm_pipe->stream_res.opp->funcs->opp_set_dyn_expansion(
1627 odm_pipe->stream_res.opp,
1628 COLOR_SPACE_YCBCR601,
1629 stream->timing.display_color_depth,
1632 odm_pipe->stream_res.opp->funcs->opp_program_fmt(
1633 odm_pipe->stream_res.opp,
1634 &stream->bit_depth_params,
1636 odm_pipe = odm_pipe->next_odm_pipe;
1639 if (!stream->dpms_off)
1640 core_link_enable_stream(context, pipe_ctx);
1642 #if defined(CONFIG_DRM_AMD_DC_DCN)
1643 /* DCN3.1 FPGA Workaround
1644 * Need to enable HPO DP Stream Encoder before setting OTG master enable.
1645 * To do so, move calling function enable_stream_timing to only be done AFTER calling
1646 * function core_link_enable_stream
1648 if (hws->wa.dp_hpo_and_otg_sequence && is_dp_128b_132b_signal(pipe_ctx)) {
1649 if (!pipe_ctx->stream->apply_seamless_boot_optimization)
1650 hws->funcs.enable_stream_timing(pipe_ctx, context, dc);
1654 pipe_ctx->plane_res.scl_data.lb_params.alpha_en = pipe_ctx->bottom_pipe != 0;
1656 pipe_ctx->stream->link->psr_settings.psr_feature_enabled = false;
1661 /******************************************************************************/
1663 static void power_down_encoders(struct dc *dc)
1667 for (i = 0; i < dc->link_count; i++) {
1668 enum signal_type signal = dc->links[i]->connector_signal;
1670 dc_link_blank_dp_stream(dc->links[i], false);
1672 if (signal != SIGNAL_TYPE_EDP)
1673 signal = SIGNAL_TYPE_NONE;
1675 if (dc->links[i]->ep_type == DISPLAY_ENDPOINT_PHY)
1676 dc->links[i]->link_enc->funcs->disable_output(
1677 dc->links[i]->link_enc, signal);
1679 dc->links[i]->link_status.link_active = false;
1680 memset(&dc->links[i]->cur_link_settings, 0,
1681 sizeof(dc->links[i]->cur_link_settings));
1685 static void power_down_controllers(struct dc *dc)
1689 for (i = 0; i < dc->res_pool->timing_generator_count; i++) {
1690 dc->res_pool->timing_generators[i]->funcs->disable_crtc(
1691 dc->res_pool->timing_generators[i]);
1695 static void power_down_clock_sources(struct dc *dc)
1699 if (dc->res_pool->dp_clock_source->funcs->cs_power_down(
1700 dc->res_pool->dp_clock_source) == false)
1701 dm_error("Failed to power down pll! (dp clk src)\n");
1703 for (i = 0; i < dc->res_pool->clk_src_count; i++) {
1704 if (dc->res_pool->clock_sources[i]->funcs->cs_power_down(
1705 dc->res_pool->clock_sources[i]) == false)
1706 dm_error("Failed to power down pll! (clk src index=%d)\n", i);
1710 static void power_down_all_hw_blocks(struct dc *dc)
1712 power_down_encoders(dc);
1714 power_down_controllers(dc);
1716 power_down_clock_sources(dc);
1718 if (dc->fbc_compressor)
1719 dc->fbc_compressor->funcs->disable_fbc(dc->fbc_compressor);
1722 static void disable_vga_and_power_gate_all_controllers(
1726 struct timing_generator *tg;
1727 struct dc_context *ctx = dc->ctx;
1729 for (i = 0; i < dc->res_pool->timing_generator_count; i++) {
1730 tg = dc->res_pool->timing_generators[i];
1732 if (tg->funcs->disable_vga)
1733 tg->funcs->disable_vga(tg);
1735 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1736 /* Enable CLOCK gating for each pipe BEFORE controller
1738 enable_display_pipe_clock_gating(ctx,
1741 dc->current_state->res_ctx.pipe_ctx[i].pipe_idx = i;
1742 dc->hwss.disable_plane(dc,
1743 &dc->current_state->res_ctx.pipe_ctx[i]);
1748 static void get_edp_streams(struct dc_state *context,
1749 struct dc_stream_state **edp_streams,
1750 int *edp_stream_num)
1754 *edp_stream_num = 0;
1755 for (i = 0; i < context->stream_count; i++) {
1756 if (context->streams[i]->signal == SIGNAL_TYPE_EDP) {
1757 edp_streams[*edp_stream_num] = context->streams[i];
1758 if (++(*edp_stream_num) == MAX_NUM_EDP)
1764 static void get_edp_links_with_sink(
1766 struct dc_link **edp_links_with_sink,
1767 int *edp_with_sink_num)
1771 /* check if there is an eDP panel not in use */
1772 *edp_with_sink_num = 0;
1773 for (i = 0; i < dc->link_count; i++) {
1774 if (dc->links[i]->local_sink &&
1775 dc->links[i]->local_sink->sink_signal == SIGNAL_TYPE_EDP) {
1776 edp_links_with_sink[*edp_with_sink_num] = dc->links[i];
1777 if (++(*edp_with_sink_num) == MAX_NUM_EDP)
1784 * When ASIC goes from VBIOS/VGA mode to driver/accelerated mode we need:
1785 * 1. Power down all DC HW blocks
1786 * 2. Disable VGA engine on all controllers
1787 * 3. Enable power gating for controller
1788 * 4. Set acc_mode_change bit (VBIOS will clear this bit when going to FSDOS)
1790 void dce110_enable_accelerated_mode(struct dc *dc, struct dc_state *context)
1792 struct dc_link *edp_links_with_sink[MAX_NUM_EDP];
1793 struct dc_link *edp_links[MAX_NUM_EDP];
1794 struct dc_stream_state *edp_streams[MAX_NUM_EDP];
1795 struct dc_link *edp_link_with_sink = NULL;
1796 struct dc_link *edp_link = NULL;
1797 struct dce_hwseq *hws = dc->hwseq;
1798 int edp_with_sink_num;
1802 bool can_apply_edp_fast_boot = false;
1803 bool can_apply_seamless_boot = false;
1804 bool keep_edp_vdd_on = false;
1808 get_edp_links_with_sink(dc, edp_links_with_sink, &edp_with_sink_num);
1809 get_edp_links(dc, edp_links, &edp_num);
1811 if (hws->funcs.init_pipes)
1812 hws->funcs.init_pipes(dc, context);
1814 get_edp_streams(context, edp_streams, &edp_stream_num);
1816 // Check fastboot support, disable on DCE8 because of blank screens
1817 if (edp_num && edp_stream_num && dc->ctx->dce_version != DCE_VERSION_8_0 &&
1818 dc->ctx->dce_version != DCE_VERSION_8_1 &&
1819 dc->ctx->dce_version != DCE_VERSION_8_3) {
1820 for (i = 0; i < edp_num; i++) {
1821 edp_link = edp_links[i];
1822 if (edp_link != edp_streams[0]->link)
1824 // enable fastboot if backend is enabled on eDP
1825 if (edp_link->link_enc->funcs->is_dig_enabled &&
1826 edp_link->link_enc->funcs->is_dig_enabled(edp_link->link_enc) &&
1827 edp_link->link_status.link_active) {
1828 struct dc_stream_state *edp_stream = edp_streams[0];
1830 can_apply_edp_fast_boot = !is_edp_ilr_optimization_required(edp_stream->link, &edp_stream->timing);
1831 edp_stream->apply_edp_fast_boot_optimization = can_apply_edp_fast_boot;
1832 if (can_apply_edp_fast_boot)
1833 DC_LOG_EVENT_LINK_TRAINING("eDP fast boot disabled to optimize link rate\n");
1838 // We are trying to enable eDP, don't power down VDD
1839 if (can_apply_edp_fast_boot)
1840 keep_edp_vdd_on = true;
1843 // Check seamless boot support
1844 for (i = 0; i < context->stream_count; i++) {
1845 if (context->streams[i]->apply_seamless_boot_optimization) {
1846 can_apply_seamless_boot = true;
1851 /* eDP should not have stream in resume from S4 and so even with VBios post
1852 * it should get turned off
1854 if (edp_with_sink_num)
1855 edp_link_with_sink = edp_links_with_sink[0];
1857 if (!can_apply_edp_fast_boot && !can_apply_seamless_boot) {
1858 if (edp_link_with_sink && !keep_edp_vdd_on) {
1859 /*turn off backlight before DP_blank and encoder powered down*/
1860 hws->funcs.edp_backlight_control(edp_link_with_sink, false);
1862 /*resume from S3, no vbios posting, no need to power down again*/
1863 power_down_all_hw_blocks(dc);
1864 disable_vga_and_power_gate_all_controllers(dc);
1865 if (edp_link_with_sink && !keep_edp_vdd_on)
1866 dc->hwss.edp_power_control(edp_link_with_sink, false);
1868 bios_set_scratch_acc_mode_change(dc->ctx->dc_bios, 1);
1871 static uint32_t compute_pstate_blackout_duration(
1872 struct bw_fixed blackout_duration,
1873 const struct dc_stream_state *stream)
1875 uint32_t total_dest_line_time_ns;
1876 uint32_t pstate_blackout_duration_ns;
1878 pstate_blackout_duration_ns = 1000 * blackout_duration.value >> 24;
1880 total_dest_line_time_ns = 1000000UL *
1881 (stream->timing.h_total * 10) /
1882 stream->timing.pix_clk_100hz +
1883 pstate_blackout_duration_ns;
1885 return total_dest_line_time_ns;
1888 static void dce110_set_displaymarks(
1889 const struct dc *dc,
1890 struct dc_state *context)
1892 uint8_t i, num_pipes;
1893 unsigned int underlay_idx = dc->res_pool->underlay_pipe_index;
1895 for (i = 0, num_pipes = 0; i < MAX_PIPES; i++) {
1896 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
1897 uint32_t total_dest_line_time_ns;
1899 if (pipe_ctx->stream == NULL)
1902 total_dest_line_time_ns = compute_pstate_blackout_duration(
1903 dc->bw_vbios->blackout_duration, pipe_ctx->stream);
1904 pipe_ctx->plane_res.mi->funcs->mem_input_program_display_marks(
1905 pipe_ctx->plane_res.mi,
1906 context->bw_ctx.bw.dce.nbp_state_change_wm_ns[num_pipes],
1907 context->bw_ctx.bw.dce.stutter_exit_wm_ns[num_pipes],
1908 context->bw_ctx.bw.dce.stutter_entry_wm_ns[num_pipes],
1909 context->bw_ctx.bw.dce.urgent_wm_ns[num_pipes],
1910 total_dest_line_time_ns);
1911 if (i == underlay_idx) {
1913 pipe_ctx->plane_res.mi->funcs->mem_input_program_chroma_display_marks(
1914 pipe_ctx->plane_res.mi,
1915 context->bw_ctx.bw.dce.nbp_state_change_wm_ns[num_pipes],
1916 context->bw_ctx.bw.dce.stutter_exit_wm_ns[num_pipes],
1917 context->bw_ctx.bw.dce.urgent_wm_ns[num_pipes],
1918 total_dest_line_time_ns);
1924 void dce110_set_safe_displaymarks(
1925 struct resource_context *res_ctx,
1926 const struct resource_pool *pool)
1929 int underlay_idx = pool->underlay_pipe_index;
1930 struct dce_watermarks max_marks = {
1931 MAX_WATERMARK, MAX_WATERMARK, MAX_WATERMARK, MAX_WATERMARK };
1932 struct dce_watermarks nbp_marks = {
1933 SAFE_NBP_MARK, SAFE_NBP_MARK, SAFE_NBP_MARK, SAFE_NBP_MARK };
1934 struct dce_watermarks min_marks = { 0, 0, 0, 0};
1936 for (i = 0; i < MAX_PIPES; i++) {
1937 if (res_ctx->pipe_ctx[i].stream == NULL || res_ctx->pipe_ctx[i].plane_res.mi == NULL)
1940 res_ctx->pipe_ctx[i].plane_res.mi->funcs->mem_input_program_display_marks(
1941 res_ctx->pipe_ctx[i].plane_res.mi,
1948 if (i == underlay_idx)
1949 res_ctx->pipe_ctx[i].plane_res.mi->funcs->mem_input_program_chroma_display_marks(
1950 res_ctx->pipe_ctx[i].plane_res.mi,
1959 /*******************************************************************************
1961 ******************************************************************************/
1963 static void set_drr(struct pipe_ctx **pipe_ctx,
1964 int num_pipes, struct dc_crtc_timing_adjust adjust)
1967 struct drr_params params = {0};
1968 // DRR should set trigger event to monitor surface update event
1969 unsigned int event_triggers = 0x80;
1970 // Note DRR trigger events are generated regardless of whether num frames met.
1971 unsigned int num_frames = 2;
1973 params.vertical_total_max = adjust.v_total_max;
1974 params.vertical_total_min = adjust.v_total_min;
1976 /* TODO: If multiple pipes are to be supported, you need
1977 * some GSL stuff. Static screen triggers may be programmed differently
1980 for (i = 0; i < num_pipes; i++) {
1981 pipe_ctx[i]->stream_res.tg->funcs->set_drr(
1982 pipe_ctx[i]->stream_res.tg, ¶ms);
1984 if (adjust.v_total_max != 0 && adjust.v_total_min != 0)
1985 pipe_ctx[i]->stream_res.tg->funcs->set_static_screen_control(
1986 pipe_ctx[i]->stream_res.tg,
1987 event_triggers, num_frames);
1991 static void get_position(struct pipe_ctx **pipe_ctx,
1993 struct crtc_position *position)
1997 /* TODO: handle pipes > 1
1999 for (i = 0; i < num_pipes; i++)
2000 pipe_ctx[i]->stream_res.tg->funcs->get_position(pipe_ctx[i]->stream_res.tg, position);
2003 static void set_static_screen_control(struct pipe_ctx **pipe_ctx,
2004 int num_pipes, const struct dc_static_screen_params *params)
2007 unsigned int triggers = 0;
2009 if (params->triggers.overlay_update)
2011 if (params->triggers.surface_update)
2013 if (params->triggers.cursor_update)
2015 if (params->triggers.force_trigger)
2019 struct dc *dc = pipe_ctx[0]->stream->ctx->dc;
2021 if (dc->fbc_compressor)
2025 for (i = 0; i < num_pipes; i++)
2026 pipe_ctx[i]->stream_res.tg->funcs->
2027 set_static_screen_control(pipe_ctx[i]->stream_res.tg,
2028 triggers, params->num_frames);
2032 * Check if FBC can be enabled
2034 static bool should_enable_fbc(struct dc *dc,
2035 struct dc_state *context,
2039 struct pipe_ctx *pipe_ctx = NULL;
2040 struct resource_context *res_ctx = &context->res_ctx;
2041 unsigned int underlay_idx = dc->res_pool->underlay_pipe_index;
2044 ASSERT(dc->fbc_compressor);
2046 /* FBC memory should be allocated */
2047 if (!dc->ctx->fbc_gpu_addr)
2050 /* Only supports single display */
2051 if (context->stream_count != 1)
2054 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2055 if (res_ctx->pipe_ctx[i].stream) {
2057 pipe_ctx = &res_ctx->pipe_ctx[i];
2062 /* fbc not applicable on underlay pipe */
2063 if (pipe_ctx->pipe_idx != underlay_idx) {
2070 if (i == dc->res_pool->pipe_count)
2073 if (!pipe_ctx->stream->link)
2076 /* Only supports eDP */
2077 if (pipe_ctx->stream->link->connector_signal != SIGNAL_TYPE_EDP)
2080 /* PSR should not be enabled */
2081 if (pipe_ctx->stream->link->psr_settings.psr_feature_enabled)
2084 /* Nothing to compress */
2085 if (!pipe_ctx->plane_state)
2088 /* Only for non-linear tiling */
2089 if (pipe_ctx->plane_state->tiling_info.gfx8.array_mode == DC_ARRAY_LINEAR_GENERAL)
2098 static void enable_fbc(
2100 struct dc_state *context)
2102 uint32_t pipe_idx = 0;
2104 if (should_enable_fbc(dc, context, &pipe_idx)) {
2105 /* Program GRPH COMPRESSED ADDRESS and PITCH */
2106 struct compr_addr_and_pitch_params params = {0, 0, 0};
2107 struct compressor *compr = dc->fbc_compressor;
2108 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[pipe_idx];
2110 params.source_view_width = pipe_ctx->stream->timing.h_addressable;
2111 params.source_view_height = pipe_ctx->stream->timing.v_addressable;
2112 params.inst = pipe_ctx->stream_res.tg->inst;
2113 compr->compr_surface_address.quad_part = dc->ctx->fbc_gpu_addr;
2115 compr->funcs->surface_address_and_pitch(compr, ¶ms);
2116 compr->funcs->set_fbc_invalidation_triggers(compr, 1);
2118 compr->funcs->enable_fbc(compr, ¶ms);
2122 static void dce110_reset_hw_ctx_wrap(
2124 struct dc_state *context)
2128 /* Reset old context */
2129 /* look up the targets that have been removed since last commit */
2130 for (i = 0; i < MAX_PIPES; i++) {
2131 struct pipe_ctx *pipe_ctx_old =
2132 &dc->current_state->res_ctx.pipe_ctx[i];
2133 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2135 /* Note: We need to disable output if clock sources change,
2136 * since bios does optimization and doesn't apply if changing
2137 * PHY when not already disabled.
2140 /* Skip underlay pipe since it will be handled in commit surface*/
2141 if (!pipe_ctx_old->stream || pipe_ctx_old->top_pipe)
2144 if (!pipe_ctx->stream ||
2145 pipe_need_reprogram(pipe_ctx_old, pipe_ctx)) {
2146 struct clock_source *old_clk = pipe_ctx_old->clock_source;
2148 /* Disable if new stream is null. O/w, if stream is
2149 * disabled already, no need to disable again.
2151 if (!pipe_ctx->stream || !pipe_ctx->stream->dpms_off) {
2152 core_link_disable_stream(pipe_ctx_old);
2154 /* free acquired resources*/
2155 if (pipe_ctx_old->stream_res.audio) {
2156 /*disable az_endpoint*/
2157 pipe_ctx_old->stream_res.audio->funcs->
2158 az_disable(pipe_ctx_old->stream_res.audio);
2161 if (dc->caps.dynamic_audio == true) {
2162 /*we have to dynamic arbitrate the audio endpoints*/
2163 /*we free the resource, need reset is_audio_acquired*/
2164 update_audio_usage(&dc->current_state->res_ctx, dc->res_pool,
2165 pipe_ctx_old->stream_res.audio, false);
2166 pipe_ctx_old->stream_res.audio = NULL;
2171 pipe_ctx_old->stream_res.tg->funcs->set_blank(pipe_ctx_old->stream_res.tg, true);
2172 if (!hwss_wait_for_blank_complete(pipe_ctx_old->stream_res.tg)) {
2173 dm_error("DC: failed to blank crtc!\n");
2174 BREAK_TO_DEBUGGER();
2176 pipe_ctx_old->stream_res.tg->funcs->disable_crtc(pipe_ctx_old->stream_res.tg);
2177 pipe_ctx_old->plane_res.mi->funcs->free_mem_input(
2178 pipe_ctx_old->plane_res.mi, dc->current_state->stream_count);
2180 if (old_clk && 0 == resource_get_clock_source_reference(&context->res_ctx,
2183 old_clk->funcs->cs_power_down(old_clk);
2185 dc->hwss.disable_plane(dc, pipe_ctx_old);
2187 pipe_ctx_old->stream = NULL;
2192 static void dce110_setup_audio_dto(
2194 struct dc_state *context)
2198 /* program audio wall clock. use HDMI as clock source if HDMI
2199 * audio active. Otherwise, use DP as clock source
2200 * first, loop to find any HDMI audio, if not, loop find DP audio
2202 /* Setup audio rate clock source */
2204 * Audio lag happened on DP monitor when unplug a HDMI monitor
2207 * In case of DP and HDMI connected or HDMI only, DCCG_AUDIO_DTO_SEL
2208 * is set to either dto0 or dto1, audio should work fine.
2209 * In case of DP connected only, DCCG_AUDIO_DTO_SEL should be dto1,
2210 * set to dto0 will cause audio lag.
2213 * Not optimized audio wall dto setup. When mode set, iterate pipe_ctx,
2214 * find first available pipe with audio, setup audio wall DTO per topology
2215 * instead of per pipe.
2217 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2218 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2220 if (pipe_ctx->stream == NULL)
2223 if (pipe_ctx->top_pipe)
2225 if (pipe_ctx->stream->signal != SIGNAL_TYPE_HDMI_TYPE_A)
2227 if (pipe_ctx->stream_res.audio != NULL) {
2228 struct audio_output audio_output;
2230 build_audio_output(context, pipe_ctx, &audio_output);
2232 #if defined(CONFIG_DRM_AMD_DC_DCN)
2233 /* For DCN3.1, audio to HPO FRL encoder is using audio DTBCLK DTO */
2234 if (dc->res_pool->dccg && dc->res_pool->dccg->funcs->set_audio_dtbclk_dto) {
2235 /* disable audio DTBCLK DTO */
2236 dc->res_pool->dccg->funcs->set_audio_dtbclk_dto(
2237 dc->res_pool->dccg, 0);
2239 pipe_ctx->stream_res.audio->funcs->wall_dto_setup(
2240 pipe_ctx->stream_res.audio,
2241 pipe_ctx->stream->signal,
2242 &audio_output.crtc_info,
2243 &audio_output.pll_info);
2245 pipe_ctx->stream_res.audio->funcs->wall_dto_setup(
2246 pipe_ctx->stream_res.audio,
2247 pipe_ctx->stream->signal,
2248 &audio_output.crtc_info,
2249 &audio_output.pll_info);
2251 pipe_ctx->stream_res.audio->funcs->wall_dto_setup(
2252 pipe_ctx->stream_res.audio,
2253 pipe_ctx->stream->signal,
2254 &audio_output.crtc_info,
2255 &audio_output.pll_info);
2261 /* no HDMI audio is found, try DP audio */
2262 if (i == dc->res_pool->pipe_count) {
2263 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2264 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2266 if (pipe_ctx->stream == NULL)
2269 if (pipe_ctx->top_pipe)
2272 if (!dc_is_dp_signal(pipe_ctx->stream->signal))
2275 if (pipe_ctx->stream_res.audio != NULL) {
2276 struct audio_output audio_output;
2278 build_audio_output(context, pipe_ctx, &audio_output);
2280 pipe_ctx->stream_res.audio->funcs->wall_dto_setup(
2281 pipe_ctx->stream_res.audio,
2282 pipe_ctx->stream->signal,
2283 &audio_output.crtc_info,
2284 &audio_output.pll_info);
2291 enum dc_status dce110_apply_ctx_to_hw(
2293 struct dc_state *context)
2295 struct dce_hwseq *hws = dc->hwseq;
2296 struct dc_bios *dcb = dc->ctx->dc_bios;
2297 enum dc_status status;
2300 /* Reset old context */
2301 /* look up the targets that have been removed since last commit */
2302 hws->funcs.reset_hw_ctx_wrap(dc, context);
2304 /* Skip applying if no targets */
2305 if (context->stream_count <= 0)
2308 /* Apply new context */
2309 dcb->funcs->set_scratch_critical_state(dcb, true);
2311 /* below is for real asic only */
2312 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2313 struct pipe_ctx *pipe_ctx_old =
2314 &dc->current_state->res_ctx.pipe_ctx[i];
2315 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2317 if (pipe_ctx->stream == NULL || pipe_ctx->top_pipe)
2320 if (pipe_ctx->stream == pipe_ctx_old->stream) {
2321 if (pipe_ctx_old->clock_source != pipe_ctx->clock_source)
2322 dce_crtc_switch_to_clk_src(dc->hwseq,
2323 pipe_ctx->clock_source, i);
2327 hws->funcs.enable_display_power_gating(
2328 dc, i, dc->ctx->dc_bios,
2329 PIPE_GATING_CONTROL_DISABLE);
2332 if (dc->fbc_compressor)
2333 dc->fbc_compressor->funcs->disable_fbc(dc->fbc_compressor);
2335 dce110_setup_audio_dto(dc, context);
2337 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2338 struct pipe_ctx *pipe_ctx_old =
2339 &dc->current_state->res_ctx.pipe_ctx[i];
2340 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2342 if (pipe_ctx->stream == NULL)
2345 if (pipe_ctx->stream == pipe_ctx_old->stream &&
2346 pipe_ctx->stream->link->link_state_valid) {
2350 if (pipe_ctx_old->stream && !pipe_need_reprogram(pipe_ctx_old, pipe_ctx))
2353 if (pipe_ctx->top_pipe || pipe_ctx->prev_odm_pipe)
2356 status = apply_single_controller_ctx_to_hw(
2361 if (DC_OK != status)
2365 if (dc->fbc_compressor)
2366 enable_fbc(dc, dc->current_state);
2368 dcb->funcs->set_scratch_critical_state(dcb, false);
2373 /*******************************************************************************
2374 * Front End programming
2375 ******************************************************************************/
2376 static void set_default_colors(struct pipe_ctx *pipe_ctx)
2378 struct default_adjustment default_adjust = { 0 };
2380 default_adjust.force_hw_default = false;
2381 default_adjust.in_color_space = pipe_ctx->plane_state->color_space;
2382 default_adjust.out_color_space = pipe_ctx->stream->output_color_space;
2383 default_adjust.csc_adjust_type = GRAPHICS_CSC_ADJUST_TYPE_SW;
2384 default_adjust.surface_pixel_format = pipe_ctx->plane_res.scl_data.format;
2386 /* display color depth */
2387 default_adjust.color_depth =
2388 pipe_ctx->stream->timing.display_color_depth;
2390 /* Lb color depth */
2391 default_adjust.lb_color_depth = pipe_ctx->plane_res.scl_data.lb_params.depth;
2393 pipe_ctx->plane_res.xfm->funcs->opp_set_csc_default(
2394 pipe_ctx->plane_res.xfm, &default_adjust);
2398 /*******************************************************************************
2399 * In order to turn on/off specific surface we will program
2402 * In case that we have two surfaces and they have a different visibility
2403 * we can't turn off the CRTC since it will turn off the entire display
2405 * |----------------------------------------------- |
2406 * |bottom pipe|curr pipe | | |
2407 * |Surface |Surface | Blender | CRCT |
2408 * |visibility |visibility | Configuration| |
2409 * |------------------------------------------------|
2410 * | off | off | CURRENT_PIPE | blank |
2411 * | off | on | CURRENT_PIPE | unblank |
2412 * | on | off | OTHER_PIPE | unblank |
2413 * | on | on | BLENDING | unblank |
2414 * -------------------------------------------------|
2416 ******************************************************************************/
2417 static void program_surface_visibility(const struct dc *dc,
2418 struct pipe_ctx *pipe_ctx)
2420 enum blnd_mode blender_mode = BLND_MODE_CURRENT_PIPE;
2421 bool blank_target = false;
2423 if (pipe_ctx->bottom_pipe) {
2425 /* For now we are supporting only two pipes */
2426 ASSERT(pipe_ctx->bottom_pipe->bottom_pipe == NULL);
2428 if (pipe_ctx->bottom_pipe->plane_state->visible) {
2429 if (pipe_ctx->plane_state->visible)
2430 blender_mode = BLND_MODE_BLENDING;
2432 blender_mode = BLND_MODE_OTHER_PIPE;
2434 } else if (!pipe_ctx->plane_state->visible)
2435 blank_target = true;
2437 } else if (!pipe_ctx->plane_state->visible)
2438 blank_target = true;
2440 dce_set_blender_mode(dc->hwseq, pipe_ctx->stream_res.tg->inst, blender_mode);
2441 pipe_ctx->stream_res.tg->funcs->set_blank(pipe_ctx->stream_res.tg, blank_target);
2445 static void program_gamut_remap(struct pipe_ctx *pipe_ctx)
2448 struct xfm_grph_csc_adjustment adjust;
2449 memset(&adjust, 0, sizeof(adjust));
2450 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS;
2453 if (pipe_ctx->stream->gamut_remap_matrix.enable_remap == true) {
2454 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_SW;
2456 for (i = 0; i < CSC_TEMPERATURE_MATRIX_SIZE; i++)
2457 adjust.temperature_matrix[i] =
2458 pipe_ctx->stream->gamut_remap_matrix.matrix[i];
2461 pipe_ctx->plane_res.xfm->funcs->transform_set_gamut_remap(pipe_ctx->plane_res.xfm, &adjust);
2463 static void update_plane_addr(const struct dc *dc,
2464 struct pipe_ctx *pipe_ctx)
2466 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
2468 if (plane_state == NULL)
2471 pipe_ctx->plane_res.mi->funcs->mem_input_program_surface_flip_and_addr(
2472 pipe_ctx->plane_res.mi,
2473 &plane_state->address,
2474 plane_state->flip_immediate);
2476 plane_state->status.requested_address = plane_state->address;
2479 static void dce110_update_pending_status(struct pipe_ctx *pipe_ctx)
2481 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
2483 if (plane_state == NULL)
2486 plane_state->status.is_flip_pending =
2487 pipe_ctx->plane_res.mi->funcs->mem_input_is_flip_pending(
2488 pipe_ctx->plane_res.mi);
2490 if (plane_state->status.is_flip_pending && !plane_state->visible)
2491 pipe_ctx->plane_res.mi->current_address = pipe_ctx->plane_res.mi->request_address;
2493 plane_state->status.current_address = pipe_ctx->plane_res.mi->current_address;
2494 if (pipe_ctx->plane_res.mi->current_address.type == PLN_ADDR_TYPE_GRPH_STEREO &&
2495 pipe_ctx->stream_res.tg->funcs->is_stereo_left_eye) {
2496 plane_state->status.is_right_eye =\
2497 !pipe_ctx->stream_res.tg->funcs->is_stereo_left_eye(pipe_ctx->stream_res.tg);
2501 void dce110_power_down(struct dc *dc)
2503 power_down_all_hw_blocks(dc);
2504 disable_vga_and_power_gate_all_controllers(dc);
2507 static bool wait_for_reset_trigger_to_occur(
2508 struct dc_context *dc_ctx,
2509 struct timing_generator *tg)
2513 /* To avoid endless loop we wait at most
2514 * frames_to_wait_on_triggered_reset frames for the reset to occur. */
2515 const uint32_t frames_to_wait_on_triggered_reset = 10;
2518 for (i = 0; i < frames_to_wait_on_triggered_reset; i++) {
2520 if (!tg->funcs->is_counter_moving(tg)) {
2521 DC_ERROR("TG counter is not moving!\n");
2525 if (tg->funcs->did_triggered_reset_occur(tg)) {
2527 /* usually occurs at i=1 */
2528 DC_SYNC_INFO("GSL: reset occurred at wait count: %d\n",
2533 /* Wait for one frame. */
2534 tg->funcs->wait_for_state(tg, CRTC_STATE_VACTIVE);
2535 tg->funcs->wait_for_state(tg, CRTC_STATE_VBLANK);
2539 DC_ERROR("GSL: Timeout on reset trigger!\n");
2544 /* Enable timing synchronization for a group of Timing Generators. */
2545 static void dce110_enable_timing_synchronization(
2549 struct pipe_ctx *grouped_pipes[])
2551 struct dc_context *dc_ctx = dc->ctx;
2552 struct dcp_gsl_params gsl_params = { 0 };
2555 DC_SYNC_INFO("GSL: Setting-up...\n");
2557 /* Designate a single TG in the group as a master.
2558 * Since HW doesn't care which one, we always assign
2559 * the 1st one in the group. */
2560 gsl_params.gsl_group = 0;
2561 gsl_params.gsl_master = grouped_pipes[0]->stream_res.tg->inst;
2563 for (i = 0; i < group_size; i++)
2564 grouped_pipes[i]->stream_res.tg->funcs->setup_global_swap_lock(
2565 grouped_pipes[i]->stream_res.tg, &gsl_params);
2567 /* Reset slave controllers on master VSync */
2568 DC_SYNC_INFO("GSL: enabling trigger-reset\n");
2570 for (i = 1 /* skip the master */; i < group_size; i++)
2571 grouped_pipes[i]->stream_res.tg->funcs->enable_reset_trigger(
2572 grouped_pipes[i]->stream_res.tg,
2573 gsl_params.gsl_group);
2575 for (i = 1 /* skip the master */; i < group_size; i++) {
2576 DC_SYNC_INFO("GSL: waiting for reset to occur.\n");
2577 wait_for_reset_trigger_to_occur(dc_ctx, grouped_pipes[i]->stream_res.tg);
2578 grouped_pipes[i]->stream_res.tg->funcs->disable_reset_trigger(
2579 grouped_pipes[i]->stream_res.tg);
2582 /* GSL Vblank synchronization is a one time sync mechanism, assumption
2583 * is that the sync'ed displays will not drift out of sync over time*/
2584 DC_SYNC_INFO("GSL: Restoring register states.\n");
2585 for (i = 0; i < group_size; i++)
2586 grouped_pipes[i]->stream_res.tg->funcs->tear_down_global_swap_lock(grouped_pipes[i]->stream_res.tg);
2588 DC_SYNC_INFO("GSL: Set-up complete.\n");
2591 static void dce110_enable_per_frame_crtc_position_reset(
2594 struct pipe_ctx *grouped_pipes[])
2596 struct dc_context *dc_ctx = dc->ctx;
2597 struct dcp_gsl_params gsl_params = { 0 };
2600 gsl_params.gsl_group = 0;
2601 gsl_params.gsl_master = 0;
2603 for (i = 0; i < group_size; i++)
2604 grouped_pipes[i]->stream_res.tg->funcs->setup_global_swap_lock(
2605 grouped_pipes[i]->stream_res.tg, &gsl_params);
2607 DC_SYNC_INFO("GSL: enabling trigger-reset\n");
2609 for (i = 1; i < group_size; i++)
2610 grouped_pipes[i]->stream_res.tg->funcs->enable_crtc_reset(
2611 grouped_pipes[i]->stream_res.tg,
2612 gsl_params.gsl_master,
2613 &grouped_pipes[i]->stream->triggered_crtc_reset);
2615 DC_SYNC_INFO("GSL: waiting for reset to occur.\n");
2616 for (i = 1; i < group_size; i++)
2617 wait_for_reset_trigger_to_occur(dc_ctx, grouped_pipes[i]->stream_res.tg);
2619 for (i = 0; i < group_size; i++)
2620 grouped_pipes[i]->stream_res.tg->funcs->tear_down_global_swap_lock(grouped_pipes[i]->stream_res.tg);
2624 static void init_pipes(struct dc *dc, struct dc_state *context)
2629 static void init_hw(struct dc *dc)
2633 struct transform *xfm;
2636 struct dce_hwseq *hws = dc->hwseq;
2637 uint32_t backlight = MAX_BACKLIGHT_LEVEL;
2639 bp = dc->ctx->dc_bios;
2640 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2641 xfm = dc->res_pool->transforms[i];
2642 xfm->funcs->transform_reset(xfm);
2644 hws->funcs.enable_display_power_gating(
2646 PIPE_GATING_CONTROL_INIT);
2647 hws->funcs.enable_display_power_gating(
2649 PIPE_GATING_CONTROL_DISABLE);
2650 hws->funcs.enable_display_pipe_clock_gating(
2655 dce_clock_gating_power_up(dc->hwseq, false);
2656 /***************************************/
2658 for (i = 0; i < dc->link_count; i++) {
2659 /****************************************/
2660 /* Power up AND update implementation according to the
2661 * required signal (which may be different from the
2662 * default signal on connector). */
2663 struct dc_link *link = dc->links[i];
2665 link->link_enc->funcs->hw_init(link->link_enc);
2668 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2669 struct timing_generator *tg = dc->res_pool->timing_generators[i];
2671 tg->funcs->disable_vga(tg);
2673 /* Blank controller using driver code instead of
2675 tg->funcs->set_blank(tg, true);
2676 hwss_wait_for_blank_complete(tg);
2679 for (i = 0; i < dc->res_pool->audio_count; i++) {
2680 struct audio *audio = dc->res_pool->audios[i];
2681 audio->funcs->hw_init(audio);
2684 for (i = 0; i < dc->link_count; i++) {
2685 struct dc_link *link = dc->links[i];
2687 if (link->panel_cntl)
2688 backlight = link->panel_cntl->funcs->hw_init(link->panel_cntl);
2691 abm = dc->res_pool->abm;
2693 abm->funcs->abm_init(abm, backlight);
2695 dmcu = dc->res_pool->dmcu;
2696 if (dmcu != NULL && abm != NULL)
2697 abm->dmcu_is_running = dmcu->funcs->is_dmcu_initialized(dmcu);
2699 if (dc->fbc_compressor)
2700 dc->fbc_compressor->funcs->power_up_fbc(dc->fbc_compressor);
2705 void dce110_prepare_bandwidth(
2707 struct dc_state *context)
2709 struct clk_mgr *dccg = dc->clk_mgr;
2711 dce110_set_safe_displaymarks(&context->res_ctx, dc->res_pool);
2713 dccg->funcs->update_clocks(
2719 void dce110_optimize_bandwidth(
2721 struct dc_state *context)
2723 struct clk_mgr *dccg = dc->clk_mgr;
2725 dce110_set_displaymarks(dc, context);
2727 dccg->funcs->update_clocks(
2733 static void dce110_program_front_end_for_pipe(
2734 struct dc *dc, struct pipe_ctx *pipe_ctx)
2736 struct mem_input *mi = pipe_ctx->plane_res.mi;
2737 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
2738 struct xfm_grph_csc_adjustment adjust;
2739 struct out_csc_color_matrix tbl_entry;
2741 struct dce_hwseq *hws = dc->hwseq;
2744 memset(&tbl_entry, 0, sizeof(tbl_entry));
2746 memset(&adjust, 0, sizeof(adjust));
2747 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS;
2749 dce_enable_fe_clock(dc->hwseq, mi->inst, true);
2751 set_default_colors(pipe_ctx);
2752 if (pipe_ctx->stream->csc_color_matrix.enable_adjustment
2754 tbl_entry.color_space =
2755 pipe_ctx->stream->output_color_space;
2757 for (i = 0; i < 12; i++)
2758 tbl_entry.regval[i] =
2759 pipe_ctx->stream->csc_color_matrix.matrix[i];
2761 pipe_ctx->plane_res.xfm->funcs->opp_set_csc_adjustment
2762 (pipe_ctx->plane_res.xfm, &tbl_entry);
2765 if (pipe_ctx->stream->gamut_remap_matrix.enable_remap == true) {
2766 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_SW;
2768 for (i = 0; i < CSC_TEMPERATURE_MATRIX_SIZE; i++)
2769 adjust.temperature_matrix[i] =
2770 pipe_ctx->stream->gamut_remap_matrix.matrix[i];
2773 pipe_ctx->plane_res.xfm->funcs->transform_set_gamut_remap(pipe_ctx->plane_res.xfm, &adjust);
2775 pipe_ctx->plane_res.scl_data.lb_params.alpha_en = pipe_ctx->bottom_pipe != 0;
2777 program_scaler(dc, pipe_ctx);
2779 mi->funcs->mem_input_program_surface_config(
2781 plane_state->format,
2782 &plane_state->tiling_info,
2783 &plane_state->plane_size,
2784 plane_state->rotation,
2787 if (mi->funcs->set_blank)
2788 mi->funcs->set_blank(mi, pipe_ctx->plane_state->visible);
2790 if (dc->config.gpu_vm_support)
2791 mi->funcs->mem_input_program_pte_vm(
2792 pipe_ctx->plane_res.mi,
2793 plane_state->format,
2794 &plane_state->tiling_info,
2795 plane_state->rotation);
2797 /* Moved programming gamma from dc to hwss */
2798 if (pipe_ctx->plane_state->update_flags.bits.full_update ||
2799 pipe_ctx->plane_state->update_flags.bits.in_transfer_func_change ||
2800 pipe_ctx->plane_state->update_flags.bits.gamma_change)
2801 hws->funcs.set_input_transfer_func(dc, pipe_ctx, pipe_ctx->plane_state);
2803 if (pipe_ctx->plane_state->update_flags.bits.full_update)
2804 hws->funcs.set_output_transfer_func(dc, pipe_ctx, pipe_ctx->stream);
2807 "Pipe:%d %p: addr hi:0x%x, "
2810 " %d; dst: %d, %d, %d, %d;"
2811 "clip: %d, %d, %d, %d\n",
2813 (void *) pipe_ctx->plane_state,
2814 pipe_ctx->plane_state->address.grph.addr.high_part,
2815 pipe_ctx->plane_state->address.grph.addr.low_part,
2816 pipe_ctx->plane_state->src_rect.x,
2817 pipe_ctx->plane_state->src_rect.y,
2818 pipe_ctx->plane_state->src_rect.width,
2819 pipe_ctx->plane_state->src_rect.height,
2820 pipe_ctx->plane_state->dst_rect.x,
2821 pipe_ctx->plane_state->dst_rect.y,
2822 pipe_ctx->plane_state->dst_rect.width,
2823 pipe_ctx->plane_state->dst_rect.height,
2824 pipe_ctx->plane_state->clip_rect.x,
2825 pipe_ctx->plane_state->clip_rect.y,
2826 pipe_ctx->plane_state->clip_rect.width,
2827 pipe_ctx->plane_state->clip_rect.height);
2830 "Pipe %d: width, height, x, y\n"
2831 "viewport:%d, %d, %d, %d\n"
2832 "recout: %d, %d, %d, %d\n",
2834 pipe_ctx->plane_res.scl_data.viewport.width,
2835 pipe_ctx->plane_res.scl_data.viewport.height,
2836 pipe_ctx->plane_res.scl_data.viewport.x,
2837 pipe_ctx->plane_res.scl_data.viewport.y,
2838 pipe_ctx->plane_res.scl_data.recout.width,
2839 pipe_ctx->plane_res.scl_data.recout.height,
2840 pipe_ctx->plane_res.scl_data.recout.x,
2841 pipe_ctx->plane_res.scl_data.recout.y);
2844 static void dce110_apply_ctx_for_surface(
2846 const struct dc_stream_state *stream,
2848 struct dc_state *context)
2852 if (num_planes == 0)
2855 if (dc->fbc_compressor)
2856 dc->fbc_compressor->funcs->disable_fbc(dc->fbc_compressor);
2858 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2859 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2861 if (pipe_ctx->stream != stream)
2864 /* Need to allocate mem before program front end for Fiji */
2865 pipe_ctx->plane_res.mi->funcs->allocate_mem_input(
2866 pipe_ctx->plane_res.mi,
2867 pipe_ctx->stream->timing.h_total,
2868 pipe_ctx->stream->timing.v_total,
2869 pipe_ctx->stream->timing.pix_clk_100hz / 10,
2870 context->stream_count);
2872 dce110_program_front_end_for_pipe(dc, pipe_ctx);
2874 dc->hwss.update_plane_addr(dc, pipe_ctx);
2876 program_surface_visibility(dc, pipe_ctx);
2880 if (dc->fbc_compressor)
2881 enable_fbc(dc, context);
2884 static void dce110_post_unlock_program_front_end(
2886 struct dc_state *context)
2890 static void dce110_power_down_fe(struct dc *dc, struct pipe_ctx *pipe_ctx)
2892 struct dce_hwseq *hws = dc->hwseq;
2893 int fe_idx = pipe_ctx->plane_res.mi ?
2894 pipe_ctx->plane_res.mi->inst : pipe_ctx->pipe_idx;
2896 /* Do not power down fe when stream is active on dce*/
2897 if (dc->current_state->res_ctx.pipe_ctx[fe_idx].stream)
2900 hws->funcs.enable_display_power_gating(
2901 dc, fe_idx, dc->ctx->dc_bios, PIPE_GATING_CONTROL_ENABLE);
2903 dc->res_pool->transforms[fe_idx]->funcs->transform_reset(
2904 dc->res_pool->transforms[fe_idx]);
2907 static void dce110_wait_for_mpcc_disconnect(
2909 struct resource_pool *res_pool,
2910 struct pipe_ctx *pipe_ctx)
2915 static void program_output_csc(struct dc *dc,
2916 struct pipe_ctx *pipe_ctx,
2917 enum dc_color_space colorspace,
2922 struct out_csc_color_matrix tbl_entry;
2924 if (pipe_ctx->stream->csc_color_matrix.enable_adjustment == true) {
2925 enum dc_color_space color_space = pipe_ctx->stream->output_color_space;
2927 for (i = 0; i < 12; i++)
2928 tbl_entry.regval[i] = pipe_ctx->stream->csc_color_matrix.matrix[i];
2930 tbl_entry.color_space = color_space;
2932 pipe_ctx->plane_res.xfm->funcs->opp_set_csc_adjustment(
2933 pipe_ctx->plane_res.xfm, &tbl_entry);
2937 static void dce110_set_cursor_position(struct pipe_ctx *pipe_ctx)
2939 struct dc_cursor_position pos_cpy = pipe_ctx->stream->cursor_position;
2940 struct input_pixel_processor *ipp = pipe_ctx->plane_res.ipp;
2941 struct mem_input *mi = pipe_ctx->plane_res.mi;
2942 struct dc_cursor_mi_param param = {
2943 .pixel_clk_khz = pipe_ctx->stream->timing.pix_clk_100hz / 10,
2944 .ref_clk_khz = pipe_ctx->stream->ctx->dc->res_pool->ref_clocks.xtalin_clock_inKhz,
2945 .viewport = pipe_ctx->plane_res.scl_data.viewport,
2946 .h_scale_ratio = pipe_ctx->plane_res.scl_data.ratios.horz,
2947 .v_scale_ratio = pipe_ctx->plane_res.scl_data.ratios.vert,
2948 .rotation = pipe_ctx->plane_state->rotation,
2949 .mirror = pipe_ctx->plane_state->horizontal_mirror
2953 * If the cursor's source viewport is clipped then we need to
2954 * translate the cursor to appear in the correct position on
2957 * This translation isn't affected by scaling so it needs to be
2958 * done *after* we adjust the position for the scale factor.
2960 * This is only done by opt-in for now since there are still
2961 * some usecases like tiled display that might enable the
2962 * cursor on both streams while expecting dc to clip it.
2964 if (pos_cpy.translate_by_source) {
2965 pos_cpy.x += pipe_ctx->plane_state->src_rect.x;
2966 pos_cpy.y += pipe_ctx->plane_state->src_rect.y;
2969 if (pipe_ctx->plane_state->address.type
2970 == PLN_ADDR_TYPE_VIDEO_PROGRESSIVE)
2971 pos_cpy.enable = false;
2973 if (pipe_ctx->top_pipe && pipe_ctx->plane_state != pipe_ctx->top_pipe->plane_state)
2974 pos_cpy.enable = false;
2976 if (ipp->funcs->ipp_cursor_set_position)
2977 ipp->funcs->ipp_cursor_set_position(ipp, &pos_cpy, ¶m);
2978 if (mi->funcs->set_cursor_position)
2979 mi->funcs->set_cursor_position(mi, &pos_cpy, ¶m);
2982 static void dce110_set_cursor_attribute(struct pipe_ctx *pipe_ctx)
2984 struct dc_cursor_attributes *attributes = &pipe_ctx->stream->cursor_attributes;
2986 if (pipe_ctx->plane_res.ipp &&
2987 pipe_ctx->plane_res.ipp->funcs->ipp_cursor_set_attributes)
2988 pipe_ctx->plane_res.ipp->funcs->ipp_cursor_set_attributes(
2989 pipe_ctx->plane_res.ipp, attributes);
2991 if (pipe_ctx->plane_res.mi &&
2992 pipe_ctx->plane_res.mi->funcs->set_cursor_attributes)
2993 pipe_ctx->plane_res.mi->funcs->set_cursor_attributes(
2994 pipe_ctx->plane_res.mi, attributes);
2996 if (pipe_ctx->plane_res.xfm &&
2997 pipe_ctx->plane_res.xfm->funcs->set_cursor_attributes)
2998 pipe_ctx->plane_res.xfm->funcs->set_cursor_attributes(
2999 pipe_ctx->plane_res.xfm, attributes);
3002 bool dce110_set_backlight_level(struct pipe_ctx *pipe_ctx,
3003 uint32_t backlight_pwm_u16_16,
3004 uint32_t frame_ramp)
3006 struct dc_link *link = pipe_ctx->stream->link;
3007 struct dc *dc = link->ctx->dc;
3008 struct abm *abm = pipe_ctx->stream_res.abm;
3009 struct panel_cntl *panel_cntl = link->panel_cntl;
3010 struct dmcu *dmcu = dc->res_pool->dmcu;
3011 bool fw_set_brightness = true;
3012 /* DMCU -1 for all controller id values,
3015 uint32_t controller_id = pipe_ctx->stream_res.tg->inst + 1;
3017 if (abm == NULL || panel_cntl == NULL || (abm->funcs->set_backlight_level_pwm == NULL))
3021 fw_set_brightness = dmcu->funcs->is_dmcu_initialized(dmcu);
3023 if (!fw_set_brightness && panel_cntl->funcs->driver_set_backlight)
3024 panel_cntl->funcs->driver_set_backlight(panel_cntl, backlight_pwm_u16_16);
3026 abm->funcs->set_backlight_level_pwm(
3028 backlight_pwm_u16_16,
3031 link->panel_cntl->inst);
3036 void dce110_set_abm_immediate_disable(struct pipe_ctx *pipe_ctx)
3038 struct abm *abm = pipe_ctx->stream_res.abm;
3039 struct panel_cntl *panel_cntl = pipe_ctx->stream->link->panel_cntl;
3042 abm->funcs->set_abm_immediate_disable(abm,
3043 pipe_ctx->stream->link->panel_cntl->inst);
3046 panel_cntl->funcs->store_backlight_level(panel_cntl);
3049 void dce110_set_pipe(struct pipe_ctx *pipe_ctx)
3051 struct abm *abm = pipe_ctx->stream_res.abm;
3052 struct panel_cntl *panel_cntl = pipe_ctx->stream->link->panel_cntl;
3053 uint32_t otg_inst = pipe_ctx->stream_res.tg->inst + 1;
3055 if (abm && panel_cntl)
3056 abm->funcs->set_pipe(abm, otg_inst, panel_cntl->inst);
3059 static const struct hw_sequencer_funcs dce110_funcs = {
3060 .program_gamut_remap = program_gamut_remap,
3061 .program_output_csc = program_output_csc,
3063 .apply_ctx_to_hw = dce110_apply_ctx_to_hw,
3064 .apply_ctx_for_surface = dce110_apply_ctx_for_surface,
3065 .post_unlock_program_front_end = dce110_post_unlock_program_front_end,
3066 .update_plane_addr = update_plane_addr,
3067 .update_pending_status = dce110_update_pending_status,
3068 .enable_accelerated_mode = dce110_enable_accelerated_mode,
3069 .enable_timing_synchronization = dce110_enable_timing_synchronization,
3070 .enable_per_frame_crtc_position_reset = dce110_enable_per_frame_crtc_position_reset,
3071 .update_info_frame = dce110_update_info_frame,
3072 .enable_stream = dce110_enable_stream,
3073 .disable_stream = dce110_disable_stream,
3074 .unblank_stream = dce110_unblank_stream,
3075 .blank_stream = dce110_blank_stream,
3076 .enable_audio_stream = dce110_enable_audio_stream,
3077 .disable_audio_stream = dce110_disable_audio_stream,
3078 .disable_plane = dce110_power_down_fe,
3079 .pipe_control_lock = dce_pipe_control_lock,
3080 .interdependent_update_lock = NULL,
3081 .cursor_lock = dce_pipe_control_lock,
3082 .prepare_bandwidth = dce110_prepare_bandwidth,
3083 .optimize_bandwidth = dce110_optimize_bandwidth,
3085 .get_position = get_position,
3086 .set_static_screen_control = set_static_screen_control,
3087 .setup_stereo = NULL,
3088 .set_avmute = dce110_set_avmute,
3089 .wait_for_mpcc_disconnect = dce110_wait_for_mpcc_disconnect,
3090 .edp_backlight_control = dce110_edp_backlight_control,
3091 .edp_power_control = dce110_edp_power_control,
3092 .edp_wait_for_hpd_ready = dce110_edp_wait_for_hpd_ready,
3093 .set_cursor_position = dce110_set_cursor_position,
3094 .set_cursor_attribute = dce110_set_cursor_attribute,
3095 .set_backlight_level = dce110_set_backlight_level,
3096 .set_abm_immediate_disable = dce110_set_abm_immediate_disable,
3097 .set_pipe = dce110_set_pipe,
3100 static const struct hwseq_private_funcs dce110_private_funcs = {
3101 .init_pipes = init_pipes,
3102 .update_plane_addr = update_plane_addr,
3103 .set_input_transfer_func = dce110_set_input_transfer_func,
3104 .set_output_transfer_func = dce110_set_output_transfer_func,
3105 .power_down = dce110_power_down,
3106 .enable_display_pipe_clock_gating = enable_display_pipe_clock_gating,
3107 .enable_display_power_gating = dce110_enable_display_power_gating,
3108 .reset_hw_ctx_wrap = dce110_reset_hw_ctx_wrap,
3109 .enable_stream_timing = dce110_enable_stream_timing,
3110 .disable_stream_gating = NULL,
3111 .enable_stream_gating = NULL,
3112 .edp_backlight_control = dce110_edp_backlight_control,
3115 void dce110_hw_sequencer_construct(struct dc *dc)
3117 dc->hwss = dce110_funcs;
3118 dc->hwseq->funcs = dce110_private_funcs;