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.
25 #include "dm_services.h"
27 #include "dc_bios_types.h"
28 #include "core_types.h"
29 #include "core_status.h"
31 #include "dm_helpers.h"
32 #include "dce110_hw_sequencer.h"
33 #include "dce110_timing_generator.h"
34 #include "dce/dce_hwseq.h"
35 #include "gpio_service_interface.h"
37 #include "dce110_compressor.h"
39 #include "bios/bios_parser_helper.h"
40 #include "timing_generator.h"
41 #include "mem_input.h"
44 #include "transform.h"
45 #include "stream_encoder.h"
46 #include "link_encoder.h"
47 #include "link_hwss.h"
48 #include "clock_source.h"
51 #include "reg_helper.h"
53 /* include DCE11 register header files */
54 #include "dce/dce_11_0_d.h"
55 #include "dce/dce_11_0_sh_mask.h"
56 #include "custom_float.h"
58 #include "atomfirmware.h"
61 * All values are in milliseconds;
62 * For eDP, after power-up/power/down,
63 * 300/500 msec max. delay from LCDVCC to black video generation
65 #define PANEL_POWER_UP_TIMEOUT 300
66 #define PANEL_POWER_DOWN_TIMEOUT 500
67 #define HPD_CHECK_INTERVAL 10
72 #define DC_LOGGER_INIT()
78 #define FN(reg_name, field_name) \
79 hws->shifts->field_name, hws->masks->field_name
81 struct dce110_hw_seq_reg_offsets {
85 static const struct dce110_hw_seq_reg_offsets reg_offsets[] = {
87 .crtc = (mmCRTC0_CRTC_GSL_CONTROL - mmCRTC_GSL_CONTROL),
90 .crtc = (mmCRTC1_CRTC_GSL_CONTROL - mmCRTC_GSL_CONTROL),
93 .crtc = (mmCRTC2_CRTC_GSL_CONTROL - mmCRTC_GSL_CONTROL),
96 .crtc = (mmCRTCV_GSL_CONTROL - mmCRTC_GSL_CONTROL),
100 #define HW_REG_BLND(reg, id)\
101 (reg + reg_offsets[id].blnd)
103 #define HW_REG_CRTC(reg, id)\
104 (reg + reg_offsets[id].crtc)
106 #define MAX_WATERMARK 0xFFFF
107 #define SAFE_NBP_MARK 0x7FFF
109 /*******************************************************************************
110 * Private definitions
111 ******************************************************************************/
112 /***************************PIPE_CONTROL***********************************/
113 static void dce110_init_pte(struct dc_context *ctx)
117 uint32_t chunk_int = 0;
118 uint32_t chunk_mul = 0;
120 addr = mmUNP_DVMM_PTE_CONTROL;
121 value = dm_read_reg(ctx, addr);
127 DVMM_USE_SINGLE_PTE);
133 DVMM_PTE_BUFFER_MODE0);
139 DVMM_PTE_BUFFER_MODE1);
141 dm_write_reg(ctx, addr, value);
143 addr = mmDVMM_PTE_REQ;
144 value = dm_read_reg(ctx, addr);
146 chunk_int = get_reg_field_value(
149 HFLIP_PTEREQ_PER_CHUNK_INT);
151 chunk_mul = get_reg_field_value(
154 HFLIP_PTEREQ_PER_CHUNK_MULTIPLIER);
156 if (chunk_int != 0x4 || chunk_mul != 0x4) {
162 MAX_PTEREQ_TO_ISSUE);
168 HFLIP_PTEREQ_PER_CHUNK_INT);
174 HFLIP_PTEREQ_PER_CHUNK_MULTIPLIER);
176 dm_write_reg(ctx, addr, value);
179 /**************************************************************************/
181 static void enable_display_pipe_clock_gating(
182 struct dc_context *ctx,
188 static bool dce110_enable_display_power_gating(
190 uint8_t controller_id,
192 enum pipe_gating_control power_gating)
194 enum bp_result bp_result = BP_RESULT_OK;
195 enum bp_pipe_control_action cntl;
196 struct dc_context *ctx = dc->ctx;
197 unsigned int underlay_idx = dc->res_pool->underlay_pipe_index;
199 if (IS_FPGA_MAXIMUS_DC(ctx->dce_environment))
202 if (power_gating == PIPE_GATING_CONTROL_INIT)
203 cntl = ASIC_PIPE_INIT;
204 else if (power_gating == PIPE_GATING_CONTROL_ENABLE)
205 cntl = ASIC_PIPE_ENABLE;
207 cntl = ASIC_PIPE_DISABLE;
209 if (controller_id == underlay_idx)
210 controller_id = CONTROLLER_ID_UNDERLAY0 - 1;
212 if (power_gating != PIPE_GATING_CONTROL_INIT || controller_id == 0){
214 bp_result = dcb->funcs->enable_disp_power_gating(
215 dcb, controller_id + 1, cntl);
217 /* Revert MASTER_UPDATE_MODE to 0 because bios sets it 2
218 * by default when command table is called
220 * Bios parser accepts controller_id = 6 as indicative of
221 * underlay pipe in dce110. But we do not support more
224 if (controller_id < CONTROLLER_ID_MAX - 1)
226 HW_REG_CRTC(mmCRTC_MASTER_UPDATE_MODE, controller_id),
230 if (power_gating != PIPE_GATING_CONTROL_ENABLE)
231 dce110_init_pte(ctx);
233 if (bp_result == BP_RESULT_OK)
239 static void build_prescale_params(struct ipp_prescale_params *prescale_params,
240 const struct dc_plane_state *plane_state)
242 prescale_params->mode = IPP_PRESCALE_MODE_FIXED_UNSIGNED;
244 switch (plane_state->format) {
245 case SURFACE_PIXEL_FORMAT_GRPH_ARGB8888:
246 case SURFACE_PIXEL_FORMAT_GRPH_ABGR8888:
247 prescale_params->scale = 0x2020;
249 case SURFACE_PIXEL_FORMAT_GRPH_ARGB2101010:
250 case SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010:
251 prescale_params->scale = 0x2008;
253 case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616:
254 case SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616F:
255 prescale_params->scale = 0x2000;
264 dce110_set_input_transfer_func(struct pipe_ctx *pipe_ctx,
265 const struct dc_plane_state *plane_state)
267 struct input_pixel_processor *ipp = pipe_ctx->plane_res.ipp;
268 const struct dc_transfer_func *tf = NULL;
269 struct ipp_prescale_params prescale_params = { 0 };
275 if (plane_state->in_transfer_func)
276 tf = plane_state->in_transfer_func;
278 build_prescale_params(&prescale_params, plane_state);
279 ipp->funcs->ipp_program_prescale(ipp, &prescale_params);
281 if (plane_state->gamma_correction &&
282 !plane_state->gamma_correction->is_identity &&
283 dce_use_lut(plane_state->format))
284 ipp->funcs->ipp_program_input_lut(ipp, plane_state->gamma_correction);
287 /* Default case if no input transfer function specified */
288 ipp->funcs->ipp_set_degamma(ipp, IPP_DEGAMMA_MODE_HW_sRGB);
289 } else if (tf->type == TF_TYPE_PREDEFINED) {
291 case TRANSFER_FUNCTION_SRGB:
292 ipp->funcs->ipp_set_degamma(ipp, IPP_DEGAMMA_MODE_HW_sRGB);
294 case TRANSFER_FUNCTION_BT709:
295 ipp->funcs->ipp_set_degamma(ipp, IPP_DEGAMMA_MODE_HW_xvYCC);
297 case TRANSFER_FUNCTION_LINEAR:
298 ipp->funcs->ipp_set_degamma(ipp, IPP_DEGAMMA_MODE_BYPASS);
300 case TRANSFER_FUNCTION_PQ:
305 } else if (tf->type == TF_TYPE_BYPASS) {
306 ipp->funcs->ipp_set_degamma(ipp, IPP_DEGAMMA_MODE_BYPASS);
308 /*TF_TYPE_DISTRIBUTED_POINTS - Not supported in DCE 11*/
315 static bool convert_to_custom_float(struct pwl_result_data *rgb_resulted,
316 struct curve_points *arr_points,
317 uint32_t hw_points_num)
319 struct custom_float_format fmt;
321 struct pwl_result_data *rgb = rgb_resulted;
325 fmt.exponenta_bits = 6;
326 fmt.mantissa_bits = 12;
329 if (!convert_to_custom_float_format(arr_points[0].x, &fmt,
330 &arr_points[0].custom_float_x)) {
335 if (!convert_to_custom_float_format(arr_points[0].offset, &fmt,
336 &arr_points[0].custom_float_offset)) {
341 if (!convert_to_custom_float_format(arr_points[0].slope, &fmt,
342 &arr_points[0].custom_float_slope)) {
347 fmt.mantissa_bits = 10;
350 if (!convert_to_custom_float_format(arr_points[1].x, &fmt,
351 &arr_points[1].custom_float_x)) {
356 if (!convert_to_custom_float_format(arr_points[1].y, &fmt,
357 &arr_points[1].custom_float_y)) {
362 if (!convert_to_custom_float_format(arr_points[1].slope, &fmt,
363 &arr_points[1].custom_float_slope)) {
368 fmt.mantissa_bits = 12;
371 while (i != hw_points_num) {
372 if (!convert_to_custom_float_format(rgb->red, &fmt,
378 if (!convert_to_custom_float_format(rgb->green, &fmt,
384 if (!convert_to_custom_float_format(rgb->blue, &fmt,
390 if (!convert_to_custom_float_format(rgb->delta_red, &fmt,
391 &rgb->delta_red_reg)) {
396 if (!convert_to_custom_float_format(rgb->delta_green, &fmt,
397 &rgb->delta_green_reg)) {
402 if (!convert_to_custom_float_format(rgb->delta_blue, &fmt,
403 &rgb->delta_blue_reg)) {
415 #define MAX_LOW_POINT 25
416 #define NUMBER_REGIONS 16
417 #define NUMBER_SW_SEGMENTS 16
420 dce110_translate_regamma_to_hw_format(const struct dc_transfer_func *output_tf,
421 struct pwl_params *regamma_params)
423 struct curve_points *arr_points;
424 struct pwl_result_data *rgb_resulted;
425 struct pwl_result_data *rgb;
426 struct pwl_result_data *rgb_plus_1;
427 struct fixed31_32 y_r;
428 struct fixed31_32 y_g;
429 struct fixed31_32 y_b;
430 struct fixed31_32 y1_min;
431 struct fixed31_32 y3_max;
433 int32_t region_start, region_end;
434 uint32_t i, j, k, seg_distr[NUMBER_REGIONS], increment, start_index, hw_points;
436 if (output_tf == NULL || regamma_params == NULL || output_tf->type == TF_TYPE_BYPASS)
439 arr_points = regamma_params->arr_points;
440 rgb_resulted = regamma_params->rgb_resulted;
443 memset(regamma_params, 0, sizeof(struct pwl_params));
445 if (output_tf->tf == TRANSFER_FUNCTION_PQ) {
447 * segments are from 2^-11 to 2^5
450 region_end = region_start + NUMBER_REGIONS;
452 for (i = 0; i < NUMBER_REGIONS; i++)
457 * segment is from 2^-10 to 2^1
458 * We include an extra segment for range [2^0, 2^1). This is to
459 * ensure that colors with normalized values of 1 don't miss the
483 for (k = 0; k < 16; k++) {
484 if (seg_distr[k] != -1)
485 hw_points += (1 << seg_distr[k]);
489 for (k = 0; k < (region_end - region_start); k++) {
490 increment = NUMBER_SW_SEGMENTS / (1 << seg_distr[k]);
491 start_index = (region_start + k + MAX_LOW_POINT) *
493 for (i = start_index; i < start_index + NUMBER_SW_SEGMENTS;
495 if (j == hw_points - 1)
497 rgb_resulted[j].red = output_tf->tf_pts.red[i];
498 rgb_resulted[j].green = output_tf->tf_pts.green[i];
499 rgb_resulted[j].blue = output_tf->tf_pts.blue[i];
505 start_index = (region_end + MAX_LOW_POINT) * NUMBER_SW_SEGMENTS;
506 rgb_resulted[hw_points - 1].red = output_tf->tf_pts.red[start_index];
507 rgb_resulted[hw_points - 1].green = output_tf->tf_pts.green[start_index];
508 rgb_resulted[hw_points - 1].blue = output_tf->tf_pts.blue[start_index];
510 arr_points[0].x = dc_fixpt_pow(dc_fixpt_from_int(2),
511 dc_fixpt_from_int(region_start));
512 arr_points[1].x = dc_fixpt_pow(dc_fixpt_from_int(2),
513 dc_fixpt_from_int(region_end));
515 y_r = rgb_resulted[0].red;
516 y_g = rgb_resulted[0].green;
517 y_b = rgb_resulted[0].blue;
519 y1_min = dc_fixpt_min(y_r, dc_fixpt_min(y_g, y_b));
521 arr_points[0].y = y1_min;
522 arr_points[0].slope = dc_fixpt_div(arr_points[0].y,
525 y_r = rgb_resulted[hw_points - 1].red;
526 y_g = rgb_resulted[hw_points - 1].green;
527 y_b = rgb_resulted[hw_points - 1].blue;
529 /* see comment above, m_arrPoints[1].y should be the Y value for the
530 * region end (m_numOfHwPoints), not last HW point(m_numOfHwPoints - 1)
532 y3_max = dc_fixpt_max(y_r, dc_fixpt_max(y_g, y_b));
534 arr_points[1].y = y3_max;
536 arr_points[1].slope = dc_fixpt_zero;
538 if (output_tf->tf == TRANSFER_FUNCTION_PQ) {
539 /* for PQ, we want to have a straight line from last HW X point,
540 * and the slope to be such that we hit 1.0 at 10000 nits.
542 const struct fixed31_32 end_value = dc_fixpt_from_int(125);
544 arr_points[1].slope = dc_fixpt_div(
545 dc_fixpt_sub(dc_fixpt_one, arr_points[1].y),
546 dc_fixpt_sub(end_value, arr_points[1].x));
549 regamma_params->hw_points_num = hw_points;
552 for (i = 1; i < 16; i++) {
553 if (seg_distr[k] != -1) {
554 regamma_params->arr_curve_points[k].segments_num = seg_distr[k];
555 regamma_params->arr_curve_points[i].offset =
556 regamma_params->arr_curve_points[k].offset + (1 << seg_distr[k]);
561 if (seg_distr[k] != -1)
562 regamma_params->arr_curve_points[k].segments_num = seg_distr[k];
565 rgb_plus_1 = rgb_resulted + 1;
569 while (i != hw_points + 1) {
570 if (dc_fixpt_lt(rgb_plus_1->red, rgb->red))
571 rgb_plus_1->red = rgb->red;
572 if (dc_fixpt_lt(rgb_plus_1->green, rgb->green))
573 rgb_plus_1->green = rgb->green;
574 if (dc_fixpt_lt(rgb_plus_1->blue, rgb->blue))
575 rgb_plus_1->blue = rgb->blue;
577 rgb->delta_red = dc_fixpt_sub(rgb_plus_1->red, rgb->red);
578 rgb->delta_green = dc_fixpt_sub(rgb_plus_1->green, rgb->green);
579 rgb->delta_blue = dc_fixpt_sub(rgb_plus_1->blue, rgb->blue);
586 convert_to_custom_float(rgb_resulted, arr_points, hw_points);
592 dce110_set_output_transfer_func(struct pipe_ctx *pipe_ctx,
593 const struct dc_stream_state *stream)
595 struct transform *xfm = pipe_ctx->plane_res.xfm;
597 xfm->funcs->opp_power_on_regamma_lut(xfm, true);
598 xfm->regamma_params.hw_points_num = GAMMA_HW_POINTS_NUM;
600 if (stream->out_transfer_func &&
601 stream->out_transfer_func->type == TF_TYPE_PREDEFINED &&
602 stream->out_transfer_func->tf == TRANSFER_FUNCTION_SRGB) {
603 xfm->funcs->opp_set_regamma_mode(xfm, OPP_REGAMMA_SRGB);
604 } else if (dce110_translate_regamma_to_hw_format(stream->out_transfer_func,
605 &xfm->regamma_params)) {
606 xfm->funcs->opp_program_regamma_pwl(xfm, &xfm->regamma_params);
607 xfm->funcs->opp_set_regamma_mode(xfm, OPP_REGAMMA_USER);
609 xfm->funcs->opp_set_regamma_mode(xfm, OPP_REGAMMA_BYPASS);
612 xfm->funcs->opp_power_on_regamma_lut(xfm, false);
617 static enum dc_status bios_parser_crtc_source_select(
618 struct pipe_ctx *pipe_ctx)
621 /* call VBIOS table to set CRTC source for the HW
623 * note: video bios clears all FMT setting here. */
624 struct bp_crtc_source_select crtc_source_select = {0};
625 const struct dc_sink *sink = pipe_ctx->stream->sink;
627 crtc_source_select.engine_id = pipe_ctx->stream_res.stream_enc->id;
628 crtc_source_select.controller_id = pipe_ctx->stream_res.tg->inst + 1;
629 /*TODO: Need to un-hardcode color depth, dp_audio and account for
630 * the case where signal and sink signal is different (translator
632 crtc_source_select.signal = pipe_ctx->stream->signal;
633 crtc_source_select.enable_dp_audio = false;
634 crtc_source_select.sink_signal = pipe_ctx->stream->signal;
636 switch (pipe_ctx->stream->timing.display_color_depth) {
637 case COLOR_DEPTH_666:
638 crtc_source_select.display_output_bit_depth = PANEL_6BIT_COLOR;
640 case COLOR_DEPTH_888:
641 crtc_source_select.display_output_bit_depth = PANEL_8BIT_COLOR;
643 case COLOR_DEPTH_101010:
644 crtc_source_select.display_output_bit_depth = PANEL_10BIT_COLOR;
646 case COLOR_DEPTH_121212:
647 crtc_source_select.display_output_bit_depth = PANEL_12BIT_COLOR;
651 crtc_source_select.display_output_bit_depth = PANEL_8BIT_COLOR;
655 dcb = sink->ctx->dc_bios;
657 if (BP_RESULT_OK != dcb->funcs->crtc_source_select(
659 &crtc_source_select)) {
660 return DC_ERROR_UNEXPECTED;
666 void dce110_update_info_frame(struct pipe_ctx *pipe_ctx)
671 ASSERT(pipe_ctx->stream);
673 if (pipe_ctx->stream_res.stream_enc == NULL)
674 return; /* this is not root pipe */
676 is_hdmi = dc_is_hdmi_signal(pipe_ctx->stream->signal);
677 is_dp = dc_is_dp_signal(pipe_ctx->stream->signal);
679 if (!is_hdmi && !is_dp)
683 pipe_ctx->stream_res.stream_enc->funcs->update_hdmi_info_packets(
684 pipe_ctx->stream_res.stream_enc,
685 &pipe_ctx->stream_res.encoder_info_frame);
687 pipe_ctx->stream_res.stream_enc->funcs->update_dp_info_packets(
688 pipe_ctx->stream_res.stream_enc,
689 &pipe_ctx->stream_res.encoder_info_frame);
692 void dce110_enable_stream(struct pipe_ctx *pipe_ctx)
694 enum dc_lane_count lane_count =
695 pipe_ctx->stream->sink->link->cur_link_settings.lane_count;
697 struct dc_crtc_timing *timing = &pipe_ctx->stream->timing;
698 struct dc_link *link = pipe_ctx->stream->sink->link;
701 uint32_t active_total_with_borders;
702 uint32_t early_control = 0;
703 struct timing_generator *tg = pipe_ctx->stream_res.tg;
705 /* For MST, there are multiply stream go to only one link.
706 * connect DIG back_end to front_end while enable_stream and
707 * disconnect them during disable_stream
708 * BY this, it is logic clean to separate stream and link */
709 link->link_enc->funcs->connect_dig_be_to_fe(link->link_enc,
710 pipe_ctx->stream_res.stream_enc->id, true);
712 /* update AVI info frame (HDMI, DP)*/
713 /* TODO: FPGA may change to hwss.update_info_frame */
714 dce110_update_info_frame(pipe_ctx);
716 /* enable early control to avoid corruption on DP monitor*/
717 active_total_with_borders =
718 timing->h_addressable
719 + timing->h_border_left
720 + timing->h_border_right;
723 early_control = active_total_with_borders % lane_count;
725 if (early_control == 0)
726 early_control = lane_count;
728 tg->funcs->set_early_control(tg, early_control);
730 /* enable audio only within mode set */
731 if (pipe_ctx->stream_res.audio != NULL) {
732 if (dc_is_dp_signal(pipe_ctx->stream->signal))
733 pipe_ctx->stream_res.stream_enc->funcs->dp_audio_enable(pipe_ctx->stream_res.stream_enc);
741 /*todo: cloned in stream enc, fix*/
742 static bool is_panel_backlight_on(struct dce_hwseq *hws)
746 REG_GET(LVTMA_PWRSEQ_CNTL, LVTMA_BLON, &value);
751 static bool is_panel_powered_on(struct dce_hwseq *hws)
753 uint32_t pwr_seq_state, dig_on, dig_on_ovrd;
756 REG_GET(LVTMA_PWRSEQ_STATE, LVTMA_PWRSEQ_TARGET_STATE_R, &pwr_seq_state);
758 REG_GET_2(LVTMA_PWRSEQ_CNTL, LVTMA_DIGON, &dig_on, LVTMA_DIGON_OVRD, &dig_on_ovrd);
760 return (pwr_seq_state == 1) || (dig_on == 1 && dig_on_ovrd == 1);
763 static enum bp_result link_transmitter_control(
764 struct dc_bios *bios,
765 struct bp_transmitter_control *cntl)
767 enum bp_result result;
769 result = bios->funcs->transmitter_control(bios, cntl);
778 void hwss_edp_wait_for_hpd_ready(
779 struct dc_link *link,
782 struct dc_context *ctx = link->ctx;
783 struct graphics_object_id connector = link->link_enc->connector;
785 bool edp_hpd_high = false;
786 uint32_t time_elapsed = 0;
787 uint32_t timeout = power_up ?
788 PANEL_POWER_UP_TIMEOUT : PANEL_POWER_DOWN_TIMEOUT;
790 if (dal_graphics_object_id_get_connector_id(connector)
791 != CONNECTOR_ID_EDP) {
798 * From KV, we will not HPD low after turning off VCC -
799 * instead, we will check the SW timer in power_up().
804 * When we power on/off the eDP panel,
805 * we need to wait until SENSE bit is high/low.
809 /* TODO what to do with this? */
810 hpd = get_hpd_gpio(ctx->dc_bios, connector, ctx->gpio_service);
817 dal_gpio_open(hpd, GPIO_MODE_INTERRUPT);
819 /* wait until timeout or panel detected */
822 uint32_t detected = 0;
824 dal_gpio_get_value(hpd, &detected);
826 if (!(detected ^ power_up)) {
831 msleep(HPD_CHECK_INTERVAL);
833 time_elapsed += HPD_CHECK_INTERVAL;
834 } while (time_elapsed < timeout);
838 dal_gpio_destroy_irq(&hpd);
840 if (false == edp_hpd_high) {
842 "%s: wait timed out!\n", __func__);
846 void hwss_edp_power_control(
847 struct dc_link *link,
850 struct dc_context *ctx = link->ctx;
851 struct dce_hwseq *hwseq = ctx->dc->hwseq;
852 struct bp_transmitter_control cntl = { 0 };
853 enum bp_result bp_result;
856 if (dal_graphics_object_id_get_connector_id(link->link_enc->connector)
857 != CONNECTOR_ID_EDP) {
862 if (power_up != is_panel_powered_on(hwseq)) {
863 /* Send VBIOS command to prompt eDP panel power */
865 unsigned long long current_ts = dm_get_timestamp(ctx);
866 unsigned long long duration_in_ms =
867 div64_u64(dm_get_elapse_time_in_ns(
870 link->link_trace.time_stamp.edp_poweroff), 1000000);
871 unsigned long long wait_time_ms = 0;
873 /* max 500ms from LCDVDD off to on */
874 unsigned long long edp_poweroff_time_ms = 500;
876 if (link->local_sink != NULL)
877 edp_poweroff_time_ms =
878 500 + link->local_sink->edid_caps.panel_patch.extra_t12_ms;
879 if (link->link_trace.time_stamp.edp_poweroff == 0)
880 wait_time_ms = edp_poweroff_time_ms;
881 else if (duration_in_ms < edp_poweroff_time_ms)
882 wait_time_ms = edp_poweroff_time_ms - duration_in_ms;
885 msleep(wait_time_ms);
886 dm_output_to_console("%s: wait %lld ms to power on eDP.\n",
887 __func__, wait_time_ms);
893 "%s: Panel Power action: %s\n",
894 __func__, (power_up ? "On":"Off"));
896 cntl.action = power_up ?
897 TRANSMITTER_CONTROL_POWER_ON :
898 TRANSMITTER_CONTROL_POWER_OFF;
899 cntl.transmitter = link->link_enc->transmitter;
900 cntl.connector_obj_id = link->link_enc->connector;
901 cntl.coherent = false;
902 cntl.lanes_number = LANE_COUNT_FOUR;
903 cntl.hpd_sel = link->link_enc->hpd_source;
904 bp_result = link_transmitter_control(ctx->dc_bios, &cntl);
907 /*save driver power off time stamp*/
908 link->link_trace.time_stamp.edp_poweroff = dm_get_timestamp(ctx);
910 link->link_trace.time_stamp.edp_poweron = dm_get_timestamp(ctx);
912 if (bp_result != BP_RESULT_OK)
914 "%s: Panel Power bp_result: %d\n",
915 __func__, bp_result);
918 "%s: Skipping Panel Power action: %s\n",
919 __func__, (power_up ? "On":"Off"));
923 /*todo: cloned in stream enc, fix*/
926 * eDP only. Control the backlight of the eDP panel
928 void hwss_edp_backlight_control(
929 struct dc_link *link,
932 struct dc_context *ctx = link->ctx;
933 struct dce_hwseq *hws = ctx->dc->hwseq;
934 struct bp_transmitter_control cntl = { 0 };
936 if (dal_graphics_object_id_get_connector_id(link->link_enc->connector)
937 != CONNECTOR_ID_EDP) {
942 if (enable && is_panel_backlight_on(hws)) {
944 "%s: panel already powered up. Do nothing.\n",
949 /* Send VBIOS command to control eDP panel backlight */
952 "%s: backlight action: %s\n",
953 __func__, (enable ? "On":"Off"));
955 cntl.action = enable ?
956 TRANSMITTER_CONTROL_BACKLIGHT_ON :
957 TRANSMITTER_CONTROL_BACKLIGHT_OFF;
959 /*cntl.engine_id = ctx->engine;*/
960 cntl.transmitter = link->link_enc->transmitter;
961 cntl.connector_obj_id = link->link_enc->connector;
963 cntl.lanes_number = LANE_COUNT_FOUR;
964 cntl.hpd_sel = link->link_enc->hpd_source;
965 cntl.signal = SIGNAL_TYPE_EDP;
967 /* For eDP, the following delays might need to be considered
968 * after link training completed:
969 * idle period - min. accounts for required BS-Idle pattern,
970 * max. allows for source frame synchronization);
971 * 50 msec max. delay from valid video data from source
972 * to video on dislpay or backlight enable.
974 * Disable the delay for now.
975 * Enable it in the future if necessary.
977 /* dc_service_sleep_in_milliseconds(50); */
979 if (cntl.action == TRANSMITTER_CONTROL_BACKLIGHT_ON)
980 edp_receiver_ready_T7(link);
981 link_transmitter_control(ctx->dc_bios, &cntl);
983 if (cntl.action == TRANSMITTER_CONTROL_BACKLIGHT_OFF)
984 edp_receiver_ready_T9(link);
987 void dce110_enable_audio_stream(struct pipe_ctx *pipe_ctx)
989 struct dc *core_dc = pipe_ctx->stream->ctx->dc;
990 /* notify audio driver for audio modes of monitor */
991 struct pp_smu_funcs_rv *pp_smu = core_dc->res_pool->pp_smu;
992 unsigned int i, num_audio = 1;
994 if (pipe_ctx->stream_res.audio) {
995 for (i = 0; i < MAX_PIPES; i++) {
996 /*current_state not updated yet*/
997 if (core_dc->current_state->res_ctx.pipe_ctx[i].stream_res.audio != NULL)
1001 pipe_ctx->stream_res.audio->funcs->az_enable(pipe_ctx->stream_res.audio);
1003 if (num_audio == 1 && pp_smu != NULL && pp_smu->set_pme_wa_enable != NULL)
1004 /*this is the first audio. apply the PME w/a in order to wake AZ from D3*/
1005 pp_smu->set_pme_wa_enable(&pp_smu->pp_smu);
1007 /* TODO: audio should be per stream rather than per link */
1008 pipe_ctx->stream_res.stream_enc->funcs->audio_mute_control(
1009 pipe_ctx->stream_res.stream_enc, false);
1013 void dce110_disable_audio_stream(struct pipe_ctx *pipe_ctx, int option)
1015 struct dc *dc = pipe_ctx->stream->ctx->dc;
1017 pipe_ctx->stream_res.stream_enc->funcs->audio_mute_control(
1018 pipe_ctx->stream_res.stream_enc, true);
1019 if (pipe_ctx->stream_res.audio) {
1020 if (option != KEEP_ACQUIRED_RESOURCE ||
1021 !dc->debug.az_endpoint_mute_only) {
1022 /*only disalbe az_endpoint if power down or free*/
1023 pipe_ctx->stream_res.audio->funcs->az_disable(pipe_ctx->stream_res.audio);
1026 if (dc_is_dp_signal(pipe_ctx->stream->signal))
1027 pipe_ctx->stream_res.stream_enc->funcs->dp_audio_disable(
1028 pipe_ctx->stream_res.stream_enc);
1030 pipe_ctx->stream_res.stream_enc->funcs->hdmi_audio_disable(
1031 pipe_ctx->stream_res.stream_enc);
1032 /*don't free audio if it is from retrain or internal disable stream*/
1033 if (option == FREE_ACQUIRED_RESOURCE && dc->caps.dynamic_audio == true) {
1034 /*we have to dynamic arbitrate the audio endpoints*/
1035 /*we free the resource, need reset is_audio_acquired*/
1036 update_audio_usage(&dc->current_state->res_ctx, dc->res_pool, pipe_ctx->stream_res.audio, false);
1037 pipe_ctx->stream_res.audio = NULL;
1040 /* TODO: notify audio driver for if audio modes list changed
1041 * add audio mode list change flag */
1042 /* dal_audio_disable_azalia_audio_jack_presence(stream->audio,
1043 * stream->stream_engine_id);
1048 void dce110_disable_stream(struct pipe_ctx *pipe_ctx, int option)
1050 struct dc_stream_state *stream = pipe_ctx->stream;
1051 struct dc_link *link = stream->sink->link;
1052 struct dc *dc = pipe_ctx->stream->ctx->dc;
1054 if (dc_is_hdmi_signal(pipe_ctx->stream->signal))
1055 pipe_ctx->stream_res.stream_enc->funcs->stop_hdmi_info_packets(
1056 pipe_ctx->stream_res.stream_enc);
1058 if (dc_is_dp_signal(pipe_ctx->stream->signal))
1059 pipe_ctx->stream_res.stream_enc->funcs->stop_dp_info_packets(
1060 pipe_ctx->stream_res.stream_enc);
1062 dc->hwss.disable_audio_stream(pipe_ctx, option);
1064 link->link_enc->funcs->connect_dig_be_to_fe(
1066 pipe_ctx->stream_res.stream_enc->id,
1071 void dce110_unblank_stream(struct pipe_ctx *pipe_ctx,
1072 struct dc_link_settings *link_settings)
1074 struct encoder_unblank_param params = { { 0 } };
1075 struct dc_stream_state *stream = pipe_ctx->stream;
1076 struct dc_link *link = stream->sink->link;
1078 /* only 3 items below are used by unblank */
1079 params.pixel_clk_khz =
1080 pipe_ctx->stream->timing.pix_clk_khz;
1081 params.link_settings.link_rate = link_settings->link_rate;
1083 if (dc_is_dp_signal(pipe_ctx->stream->signal))
1084 pipe_ctx->stream_res.stream_enc->funcs->dp_unblank(pipe_ctx->stream_res.stream_enc, ¶ms);
1086 if (link->local_sink && link->local_sink->sink_signal == SIGNAL_TYPE_EDP) {
1087 link->dc->hwss.edp_backlight_control(link, true);
1090 void dce110_blank_stream(struct pipe_ctx *pipe_ctx)
1092 struct dc_stream_state *stream = pipe_ctx->stream;
1093 struct dc_link *link = stream->sink->link;
1095 if (link->local_sink && link->local_sink->sink_signal == SIGNAL_TYPE_EDP) {
1096 link->dc->hwss.edp_backlight_control(link, false);
1097 dc_link_set_abm_disable(link);
1100 if (dc_is_dp_signal(pipe_ctx->stream->signal))
1101 pipe_ctx->stream_res.stream_enc->funcs->dp_blank(pipe_ctx->stream_res.stream_enc);
1105 void dce110_set_avmute(struct pipe_ctx *pipe_ctx, bool enable)
1107 if (pipe_ctx != NULL && pipe_ctx->stream_res.stream_enc != NULL)
1108 pipe_ctx->stream_res.stream_enc->funcs->set_avmute(pipe_ctx->stream_res.stream_enc, enable);
1111 static enum audio_dto_source translate_to_dto_source(enum controller_id crtc_id)
1114 case CONTROLLER_ID_D0:
1115 return DTO_SOURCE_ID0;
1116 case CONTROLLER_ID_D1:
1117 return DTO_SOURCE_ID1;
1118 case CONTROLLER_ID_D2:
1119 return DTO_SOURCE_ID2;
1120 case CONTROLLER_ID_D3:
1121 return DTO_SOURCE_ID3;
1122 case CONTROLLER_ID_D4:
1123 return DTO_SOURCE_ID4;
1124 case CONTROLLER_ID_D5:
1125 return DTO_SOURCE_ID5;
1127 return DTO_SOURCE_UNKNOWN;
1131 static void build_audio_output(
1132 struct dc_state *state,
1133 const struct pipe_ctx *pipe_ctx,
1134 struct audio_output *audio_output)
1136 const struct dc_stream_state *stream = pipe_ctx->stream;
1137 audio_output->engine_id = pipe_ctx->stream_res.stream_enc->id;
1139 audio_output->signal = pipe_ctx->stream->signal;
1141 /* audio_crtc_info */
1143 audio_output->crtc_info.h_total =
1144 stream->timing.h_total;
1147 * Audio packets are sent during actual CRTC blank physical signal, we
1148 * need to specify actual active signal portion
1150 audio_output->crtc_info.h_active =
1151 stream->timing.h_addressable
1152 + stream->timing.h_border_left
1153 + stream->timing.h_border_right;
1155 audio_output->crtc_info.v_active =
1156 stream->timing.v_addressable
1157 + stream->timing.v_border_top
1158 + stream->timing.v_border_bottom;
1160 audio_output->crtc_info.pixel_repetition = 1;
1162 audio_output->crtc_info.interlaced =
1163 stream->timing.flags.INTERLACE;
1165 audio_output->crtc_info.refresh_rate =
1166 (stream->timing.pix_clk_khz*1000)/
1167 (stream->timing.h_total*stream->timing.v_total);
1169 audio_output->crtc_info.color_depth =
1170 stream->timing.display_color_depth;
1172 audio_output->crtc_info.requested_pixel_clock =
1173 pipe_ctx->stream_res.pix_clk_params.requested_pix_clk;
1175 audio_output->crtc_info.calculated_pixel_clock =
1176 pipe_ctx->stream_res.pix_clk_params.requested_pix_clk;
1178 /*for HDMI, audio ACR is with deep color ratio factor*/
1179 if (dc_is_hdmi_signal(pipe_ctx->stream->signal) &&
1180 audio_output->crtc_info.requested_pixel_clock ==
1181 stream->timing.pix_clk_khz) {
1182 if (pipe_ctx->stream_res.pix_clk_params.pixel_encoding == PIXEL_ENCODING_YCBCR420) {
1183 audio_output->crtc_info.requested_pixel_clock =
1184 audio_output->crtc_info.requested_pixel_clock/2;
1185 audio_output->crtc_info.calculated_pixel_clock =
1186 pipe_ctx->stream_res.pix_clk_params.requested_pix_clk/2;
1191 if (pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT ||
1192 pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST) {
1193 audio_output->pll_info.dp_dto_source_clock_in_khz =
1194 state->dccg->funcs->get_dp_ref_clk_frequency(
1198 audio_output->pll_info.feed_back_divider =
1199 pipe_ctx->pll_settings.feedback_divider;
1201 audio_output->pll_info.dto_source =
1202 translate_to_dto_source(
1203 pipe_ctx->stream_res.tg->inst + 1);
1205 /* TODO hard code to enable for now. Need get from stream */
1206 audio_output->pll_info.ss_enabled = true;
1208 audio_output->pll_info.ss_percentage =
1209 pipe_ctx->pll_settings.ss_percentage;
1212 static void get_surface_visual_confirm_color(const struct pipe_ctx *pipe_ctx,
1213 struct tg_color *color)
1215 uint32_t color_value = MAX_TG_COLOR_VALUE * (4 - pipe_ctx->stream_res.tg->inst) / 4;
1217 switch (pipe_ctx->plane_res.scl_data.format) {
1218 case PIXEL_FORMAT_ARGB8888:
1219 /* set boarder color to red */
1220 color->color_r_cr = color_value;
1223 case PIXEL_FORMAT_ARGB2101010:
1224 /* set boarder color to blue */
1225 color->color_b_cb = color_value;
1227 case PIXEL_FORMAT_420BPP8:
1228 /* set boarder color to green */
1229 color->color_g_y = color_value;
1231 case PIXEL_FORMAT_420BPP10:
1232 /* set boarder color to yellow */
1233 color->color_g_y = color_value;
1234 color->color_r_cr = color_value;
1236 case PIXEL_FORMAT_FP16:
1237 /* set boarder color to white */
1238 color->color_r_cr = color_value;
1239 color->color_b_cb = color_value;
1240 color->color_g_y = color_value;
1247 static void program_scaler(const struct dc *dc,
1248 const struct pipe_ctx *pipe_ctx)
1250 struct tg_color color = {0};
1252 #if defined(CONFIG_DRM_AMD_DC_DCN1_0)
1254 if (pipe_ctx->plane_res.xfm->funcs->transform_set_pixel_storage_depth == NULL)
1258 if (dc->debug.visual_confirm == VISUAL_CONFIRM_SURFACE)
1259 get_surface_visual_confirm_color(pipe_ctx, &color);
1261 color_space_to_black_color(dc,
1262 pipe_ctx->stream->output_color_space,
1265 pipe_ctx->plane_res.xfm->funcs->transform_set_pixel_storage_depth(
1266 pipe_ctx->plane_res.xfm,
1267 pipe_ctx->plane_res.scl_data.lb_params.depth,
1268 &pipe_ctx->stream->bit_depth_params);
1270 if (pipe_ctx->stream_res.tg->funcs->set_overscan_blank_color)
1271 pipe_ctx->stream_res.tg->funcs->set_overscan_blank_color(
1272 pipe_ctx->stream_res.tg,
1275 pipe_ctx->plane_res.xfm->funcs->transform_set_scaler(pipe_ctx->plane_res.xfm,
1276 &pipe_ctx->plane_res.scl_data);
1279 static enum dc_status dce110_enable_stream_timing(
1280 struct pipe_ctx *pipe_ctx,
1281 struct dc_state *context,
1284 struct dc_stream_state *stream = pipe_ctx->stream;
1285 struct pipe_ctx *pipe_ctx_old = &dc->current_state->res_ctx.
1286 pipe_ctx[pipe_ctx->pipe_idx];
1287 struct tg_color black_color = {0};
1288 struct drr_params params = {0};
1289 unsigned int event_triggers = 0;
1291 if (!pipe_ctx_old->stream) {
1293 /* program blank color */
1294 color_space_to_black_color(dc,
1295 stream->output_color_space, &black_color);
1296 pipe_ctx->stream_res.tg->funcs->set_blank_color(
1297 pipe_ctx->stream_res.tg,
1301 * Must blank CRTC after disabling power gating and before any
1302 * programming, otherwise CRTC will be hung in bad state
1304 pipe_ctx->stream_res.tg->funcs->set_blank(pipe_ctx->stream_res.tg, true);
1306 if (false == pipe_ctx->clock_source->funcs->program_pix_clk(
1307 pipe_ctx->clock_source,
1308 &pipe_ctx->stream_res.pix_clk_params,
1309 &pipe_ctx->pll_settings)) {
1310 BREAK_TO_DEBUGGER();
1311 return DC_ERROR_UNEXPECTED;
1314 pipe_ctx->stream_res.tg->funcs->program_timing(
1315 pipe_ctx->stream_res.tg,
1319 params.vertical_total_min = stream->adjust.v_total_min;
1320 params.vertical_total_max = stream->adjust.v_total_max;
1321 if (pipe_ctx->stream_res.tg->funcs->set_drr)
1322 pipe_ctx->stream_res.tg->funcs->set_drr(
1323 pipe_ctx->stream_res.tg, ¶ms);
1325 // DRR should set trigger event to monitor surface update event
1326 if (stream->adjust.v_total_min != 0 &&
1327 stream->adjust.v_total_max != 0)
1328 event_triggers = 0x80;
1329 if (pipe_ctx->stream_res.tg->funcs->set_static_screen_control)
1330 pipe_ctx->stream_res.tg->funcs->set_static_screen_control(
1331 pipe_ctx->stream_res.tg, event_triggers);
1334 if (!pipe_ctx_old->stream) {
1335 if (false == pipe_ctx->stream_res.tg->funcs->enable_crtc(
1336 pipe_ctx->stream_res.tg)) {
1337 BREAK_TO_DEBUGGER();
1338 return DC_ERROR_UNEXPECTED;
1345 static enum dc_status apply_single_controller_ctx_to_hw(
1346 struct pipe_ctx *pipe_ctx,
1347 struct dc_state *context,
1350 struct dc_stream_state *stream = pipe_ctx->stream;
1352 if (pipe_ctx->stream_res.audio != NULL) {
1353 struct audio_output audio_output;
1355 build_audio_output(context, pipe_ctx, &audio_output);
1357 if (dc_is_dp_signal(pipe_ctx->stream->signal))
1358 pipe_ctx->stream_res.stream_enc->funcs->dp_audio_setup(
1359 pipe_ctx->stream_res.stream_enc,
1360 pipe_ctx->stream_res.audio->inst,
1361 &pipe_ctx->stream->audio_info);
1363 pipe_ctx->stream_res.stream_enc->funcs->hdmi_audio_setup(
1364 pipe_ctx->stream_res.stream_enc,
1365 pipe_ctx->stream_res.audio->inst,
1366 &pipe_ctx->stream->audio_info,
1367 &audio_output.crtc_info);
1369 pipe_ctx->stream_res.audio->funcs->az_configure(
1370 pipe_ctx->stream_res.audio,
1371 pipe_ctx->stream->signal,
1372 &audio_output.crtc_info,
1373 &pipe_ctx->stream->audio_info);
1377 dc->hwss.enable_stream_timing(pipe_ctx, context, dc);
1379 /* TODO: move to stream encoder */
1380 if (pipe_ctx->stream->signal != SIGNAL_TYPE_VIRTUAL)
1381 if (DC_OK != bios_parser_crtc_source_select(pipe_ctx)) {
1382 BREAK_TO_DEBUGGER();
1383 return DC_ERROR_UNEXPECTED;
1386 pipe_ctx->stream_res.opp->funcs->opp_set_dyn_expansion(
1387 pipe_ctx->stream_res.opp,
1388 COLOR_SPACE_YCBCR601,
1389 stream->timing.display_color_depth,
1390 pipe_ctx->stream->signal);
1392 pipe_ctx->stream_res.opp->funcs->opp_program_fmt(
1393 pipe_ctx->stream_res.opp,
1394 &stream->bit_depth_params,
1397 if (!stream->dpms_off)
1398 core_link_enable_stream(context, pipe_ctx);
1400 pipe_ctx->plane_res.scl_data.lb_params.alpha_en = pipe_ctx->bottom_pipe != 0;
1402 pipe_ctx->stream->sink->link->psr_enabled = false;
1407 /******************************************************************************/
1409 static void power_down_encoders(struct dc *dc)
1412 enum connector_id connector_id;
1413 enum signal_type signal = SIGNAL_TYPE_NONE;
1415 /* do not know BIOS back-front mapping, simply blank all. It will not
1418 for (i = 0; i < dc->res_pool->stream_enc_count; i++) {
1419 dc->res_pool->stream_enc[i]->funcs->dp_blank(
1420 dc->res_pool->stream_enc[i]);
1423 for (i = 0; i < dc->link_count; i++) {
1424 connector_id = dal_graphics_object_id_get_connector_id(dc->links[i]->link_id);
1425 if ((connector_id == CONNECTOR_ID_DISPLAY_PORT) ||
1426 (connector_id == CONNECTOR_ID_EDP)) {
1428 if (!dc->links[i]->wa_flags.dp_keep_receiver_powered)
1429 dp_receiver_power_ctrl(dc->links[i], false);
1430 if (connector_id == CONNECTOR_ID_EDP)
1431 signal = SIGNAL_TYPE_EDP;
1434 dc->links[i]->link_enc->funcs->disable_output(
1435 dc->links[i]->link_enc, signal);
1439 static void power_down_controllers(struct dc *dc)
1443 for (i = 0; i < dc->res_pool->timing_generator_count; i++) {
1444 dc->res_pool->timing_generators[i]->funcs->disable_crtc(
1445 dc->res_pool->timing_generators[i]);
1449 static void power_down_clock_sources(struct dc *dc)
1453 if (dc->res_pool->dp_clock_source->funcs->cs_power_down(
1454 dc->res_pool->dp_clock_source) == false)
1455 dm_error("Failed to power down pll! (dp clk src)\n");
1457 for (i = 0; i < dc->res_pool->clk_src_count; i++) {
1458 if (dc->res_pool->clock_sources[i]->funcs->cs_power_down(
1459 dc->res_pool->clock_sources[i]) == false)
1460 dm_error("Failed to power down pll! (clk src index=%d)\n", i);
1464 static void power_down_all_hw_blocks(struct dc *dc)
1466 power_down_encoders(dc);
1468 power_down_controllers(dc);
1470 power_down_clock_sources(dc);
1472 if (dc->fbc_compressor)
1473 dc->fbc_compressor->funcs->disable_fbc(dc->fbc_compressor);
1476 static void disable_vga_and_power_gate_all_controllers(
1480 struct timing_generator *tg;
1481 struct dc_context *ctx = dc->ctx;
1483 for (i = 0; i < dc->res_pool->timing_generator_count; i++) {
1484 tg = dc->res_pool->timing_generators[i];
1486 if (tg->funcs->disable_vga)
1487 tg->funcs->disable_vga(tg);
1489 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1490 /* Enable CLOCK gating for each pipe BEFORE controller
1492 enable_display_pipe_clock_gating(ctx,
1495 dc->current_state->res_ctx.pipe_ctx[i].pipe_idx = i;
1496 dc->hwss.disable_plane(dc,
1497 &dc->current_state->res_ctx.pipe_ctx[i]);
1501 static struct dc_link *get_link_for_edp(struct dc *dc)
1505 for (i = 0; i < dc->link_count; i++) {
1506 if (dc->links[i]->connector_signal == SIGNAL_TYPE_EDP)
1507 return dc->links[i];
1512 static struct dc_link *get_link_for_edp_not_in_use(
1514 struct dc_state *context)
1517 struct dc_link *link = NULL;
1519 /* check if eDP panel is suppose to be set mode, if yes, no need to disable */
1520 for (i = 0; i < context->stream_count; i++) {
1521 if (context->streams[i]->signal == SIGNAL_TYPE_EDP)
1525 /* check if there is an eDP panel not in use */
1526 for (i = 0; i < dc->link_count; i++) {
1527 if (dc->links[i]->local_sink &&
1528 dc->links[i]->local_sink->sink_signal == SIGNAL_TYPE_EDP) {
1529 link = dc->links[i];
1538 * When ASIC goes from VBIOS/VGA mode to driver/accelerated mode we need:
1539 * 1. Power down all DC HW blocks
1540 * 2. Disable VGA engine on all controllers
1541 * 3. Enable power gating for controller
1542 * 4. Set acc_mode_change bit (VBIOS will clear this bit when going to FSDOS)
1544 void dce110_enable_accelerated_mode(struct dc *dc, struct dc_state *context)
1547 struct dc_link *edp_link_to_turnoff = NULL;
1548 struct dc_link *edp_link = get_link_for_edp(dc);
1549 struct dc_bios *bios = dc->ctx->dc_bios;
1550 bool can_edp_fast_boot_optimize = false;
1551 bool apply_edp_fast_boot_optimization = false;
1554 /* this seems to cause blank screens on DCE8 */
1555 if ((dc->ctx->dce_version == DCE_VERSION_8_0) ||
1556 (dc->ctx->dce_version == DCE_VERSION_8_1) ||
1557 (dc->ctx->dce_version == DCE_VERSION_8_3))
1558 can_edp_fast_boot_optimize = false;
1560 can_edp_fast_boot_optimize =
1561 edp_link->link_enc->funcs->is_dig_enabled(edp_link->link_enc);
1564 if (can_edp_fast_boot_optimize)
1565 edp_link_to_turnoff = get_link_for_edp_not_in_use(dc, context);
1567 /* if OS doesn't light up eDP and eDP link is available, we want to disable
1568 * If resume from S4/S5, should optimization.
1570 if (can_edp_fast_boot_optimize && !edp_link_to_turnoff) {
1571 /* Find eDP stream and set optimization flag */
1572 for (i = 0; i < context->stream_count; i++) {
1573 if (context->streams[i]->signal == SIGNAL_TYPE_EDP) {
1574 context->streams[i]->apply_edp_fast_boot_optimization = true;
1575 apply_edp_fast_boot_optimization = true;
1577 /* When after S4 and S5, vbios may post edp and previous dpms_off
1578 * doesn't make sense.
1579 * Update dpms_off state to align hw and sw state via check
1580 * vBios scratch register.
1582 if (bios->funcs->is_active_display) {
1583 const struct connector_device_tag_info *device_tag = &(edp_link->device_tag);
1585 if (bios->funcs->is_active_display(bios,
1586 context->streams[i]->signal,
1588 context->streams[i]->dpms_off = false;
1594 if (!apply_edp_fast_boot_optimization) {
1595 if (edp_link_to_turnoff) {
1596 /*turn off backlight before DP_blank and encoder powered down*/
1597 dc->hwss.edp_backlight_control(edp_link_to_turnoff, false);
1599 /*resume from S3, no vbios posting, no need to power down again*/
1600 power_down_all_hw_blocks(dc);
1601 disable_vga_and_power_gate_all_controllers(dc);
1602 if (edp_link_to_turnoff)
1603 dc->hwss.edp_power_control(edp_link_to_turnoff, false);
1605 bios_set_scratch_acc_mode_change(dc->ctx->dc_bios);
1608 static uint32_t compute_pstate_blackout_duration(
1609 struct bw_fixed blackout_duration,
1610 const struct dc_stream_state *stream)
1612 uint32_t total_dest_line_time_ns;
1613 uint32_t pstate_blackout_duration_ns;
1615 pstate_blackout_duration_ns = 1000 * blackout_duration.value >> 24;
1617 total_dest_line_time_ns = 1000000UL *
1618 stream->timing.h_total /
1619 stream->timing.pix_clk_khz +
1620 pstate_blackout_duration_ns;
1622 return total_dest_line_time_ns;
1625 static void dce110_set_displaymarks(
1626 const struct dc *dc,
1627 struct dc_state *context)
1629 uint8_t i, num_pipes;
1630 unsigned int underlay_idx = dc->res_pool->underlay_pipe_index;
1632 for (i = 0, num_pipes = 0; i < MAX_PIPES; i++) {
1633 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
1634 uint32_t total_dest_line_time_ns;
1636 if (pipe_ctx->stream == NULL)
1639 total_dest_line_time_ns = compute_pstate_blackout_duration(
1640 dc->bw_vbios->blackout_duration, pipe_ctx->stream);
1641 pipe_ctx->plane_res.mi->funcs->mem_input_program_display_marks(
1642 pipe_ctx->plane_res.mi,
1643 context->bw.dce.nbp_state_change_wm_ns[num_pipes],
1644 context->bw.dce.stutter_exit_wm_ns[num_pipes],
1645 context->bw.dce.stutter_entry_wm_ns[num_pipes],
1646 context->bw.dce.urgent_wm_ns[num_pipes],
1647 total_dest_line_time_ns);
1648 if (i == underlay_idx) {
1650 pipe_ctx->plane_res.mi->funcs->mem_input_program_chroma_display_marks(
1651 pipe_ctx->plane_res.mi,
1652 context->bw.dce.nbp_state_change_wm_ns[num_pipes],
1653 context->bw.dce.stutter_exit_wm_ns[num_pipes],
1654 context->bw.dce.urgent_wm_ns[num_pipes],
1655 total_dest_line_time_ns);
1661 void dce110_set_safe_displaymarks(
1662 struct resource_context *res_ctx,
1663 const struct resource_pool *pool)
1666 int underlay_idx = pool->underlay_pipe_index;
1667 struct dce_watermarks max_marks = {
1668 MAX_WATERMARK, MAX_WATERMARK, MAX_WATERMARK, MAX_WATERMARK };
1669 struct dce_watermarks nbp_marks = {
1670 SAFE_NBP_MARK, SAFE_NBP_MARK, SAFE_NBP_MARK, SAFE_NBP_MARK };
1671 struct dce_watermarks min_marks = { 0, 0, 0, 0};
1673 for (i = 0; i < MAX_PIPES; i++) {
1674 if (res_ctx->pipe_ctx[i].stream == NULL || res_ctx->pipe_ctx[i].plane_res.mi == NULL)
1677 res_ctx->pipe_ctx[i].plane_res.mi->funcs->mem_input_program_display_marks(
1678 res_ctx->pipe_ctx[i].plane_res.mi,
1685 if (i == underlay_idx)
1686 res_ctx->pipe_ctx[i].plane_res.mi->funcs->mem_input_program_chroma_display_marks(
1687 res_ctx->pipe_ctx[i].plane_res.mi,
1696 /*******************************************************************************
1698 ******************************************************************************/
1700 static void set_drr(struct pipe_ctx **pipe_ctx,
1701 int num_pipes, int vmin, int vmax)
1704 struct drr_params params = {0};
1705 // DRR should set trigger event to monitor surface update event
1706 unsigned int event_triggers = 0x80;
1708 params.vertical_total_max = vmax;
1709 params.vertical_total_min = vmin;
1711 /* TODO: If multiple pipes are to be supported, you need
1712 * some GSL stuff. Static screen triggers may be programmed differently
1715 for (i = 0; i < num_pipes; i++) {
1716 pipe_ctx[i]->stream_res.tg->funcs->set_drr(
1717 pipe_ctx[i]->stream_res.tg, ¶ms);
1719 if (vmax != 0 && vmin != 0)
1720 pipe_ctx[i]->stream_res.tg->funcs->set_static_screen_control(
1721 pipe_ctx[i]->stream_res.tg,
1726 static void get_position(struct pipe_ctx **pipe_ctx,
1728 struct crtc_position *position)
1732 /* TODO: handle pipes > 1
1734 for (i = 0; i < num_pipes; i++)
1735 pipe_ctx[i]->stream_res.tg->funcs->get_position(pipe_ctx[i]->stream_res.tg, position);
1738 static void set_static_screen_control(struct pipe_ctx **pipe_ctx,
1739 int num_pipes, const struct dc_static_screen_events *events)
1742 unsigned int value = 0;
1744 if (events->overlay_update)
1746 if (events->surface_update)
1748 if (events->cursor_update)
1750 if (events->force_trigger)
1754 struct dc *dc = pipe_ctx[0]->stream->ctx->dc;
1756 if (dc->fbc_compressor)
1760 for (i = 0; i < num_pipes; i++)
1761 pipe_ctx[i]->stream_res.tg->funcs->
1762 set_static_screen_control(pipe_ctx[i]->stream_res.tg, value);
1766 * Check if FBC can be enabled
1768 static bool should_enable_fbc(struct dc *dc,
1769 struct dc_state *context,
1773 struct pipe_ctx *pipe_ctx = NULL;
1774 struct resource_context *res_ctx = &context->res_ctx;
1775 unsigned int underlay_idx = dc->res_pool->underlay_pipe_index;
1778 ASSERT(dc->fbc_compressor);
1780 /* FBC memory should be allocated */
1781 if (!dc->ctx->fbc_gpu_addr)
1784 /* Only supports single display */
1785 if (context->stream_count != 1)
1788 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1789 if (res_ctx->pipe_ctx[i].stream) {
1791 pipe_ctx = &res_ctx->pipe_ctx[i];
1796 /* fbc not applicable on underlay pipe */
1797 if (pipe_ctx->pipe_idx != underlay_idx) {
1804 if (i == dc->res_pool->pipe_count)
1807 if (!pipe_ctx->stream->sink)
1810 if (!pipe_ctx->stream->sink->link)
1813 /* Only supports eDP */
1814 if (pipe_ctx->stream->sink->link->connector_signal != SIGNAL_TYPE_EDP)
1817 /* PSR should not be enabled */
1818 if (pipe_ctx->stream->sink->link->psr_enabled)
1821 /* Nothing to compress */
1822 if (!pipe_ctx->plane_state)
1825 /* Only for non-linear tiling */
1826 if (pipe_ctx->plane_state->tiling_info.gfx8.array_mode == DC_ARRAY_LINEAR_GENERAL)
1835 static void enable_fbc(
1837 struct dc_state *context)
1839 uint32_t pipe_idx = 0;
1841 if (should_enable_fbc(dc, context, &pipe_idx)) {
1842 /* Program GRPH COMPRESSED ADDRESS and PITCH */
1843 struct compr_addr_and_pitch_params params = {0, 0, 0};
1844 struct compressor *compr = dc->fbc_compressor;
1845 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[pipe_idx];
1847 params.source_view_width = pipe_ctx->stream->timing.h_addressable;
1848 params.source_view_height = pipe_ctx->stream->timing.v_addressable;
1849 params.inst = pipe_ctx->stream_res.tg->inst;
1850 compr->compr_surface_address.quad_part = dc->ctx->fbc_gpu_addr;
1852 compr->funcs->surface_address_and_pitch(compr, ¶ms);
1853 compr->funcs->set_fbc_invalidation_triggers(compr, 1);
1855 compr->funcs->enable_fbc(compr, ¶ms);
1859 static void dce110_reset_hw_ctx_wrap(
1861 struct dc_state *context)
1865 /* Reset old context */
1866 /* look up the targets that have been removed since last commit */
1867 for (i = 0; i < MAX_PIPES; i++) {
1868 struct pipe_ctx *pipe_ctx_old =
1869 &dc->current_state->res_ctx.pipe_ctx[i];
1870 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
1872 /* Note: We need to disable output if clock sources change,
1873 * since bios does optimization and doesn't apply if changing
1874 * PHY when not already disabled.
1877 /* Skip underlay pipe since it will be handled in commit surface*/
1878 if (!pipe_ctx_old->stream || pipe_ctx_old->top_pipe)
1881 if (!pipe_ctx->stream ||
1882 pipe_need_reprogram(pipe_ctx_old, pipe_ctx)) {
1883 struct clock_source *old_clk = pipe_ctx_old->clock_source;
1885 /* Disable if new stream is null. O/w, if stream is
1886 * disabled already, no need to disable again.
1888 if (!pipe_ctx->stream || !pipe_ctx->stream->dpms_off)
1889 core_link_disable_stream(pipe_ctx_old, FREE_ACQUIRED_RESOURCE);
1891 pipe_ctx_old->stream_res.tg->funcs->set_blank(pipe_ctx_old->stream_res.tg, true);
1892 if (!hwss_wait_for_blank_complete(pipe_ctx_old->stream_res.tg)) {
1893 dm_error("DC: failed to blank crtc!\n");
1894 BREAK_TO_DEBUGGER();
1896 pipe_ctx_old->stream_res.tg->funcs->disable_crtc(pipe_ctx_old->stream_res.tg);
1897 pipe_ctx_old->plane_res.mi->funcs->free_mem_input(
1898 pipe_ctx_old->plane_res.mi, dc->current_state->stream_count);
1900 if (old_clk && 0 == resource_get_clock_source_reference(&context->res_ctx,
1903 old_clk->funcs->cs_power_down(old_clk);
1905 dc->hwss.disable_plane(dc, pipe_ctx_old);
1907 pipe_ctx_old->stream = NULL;
1912 static void dce110_setup_audio_dto(
1914 struct dc_state *context)
1918 /* program audio wall clock. use HDMI as clock source if HDMI
1919 * audio active. Otherwise, use DP as clock source
1920 * first, loop to find any HDMI audio, if not, loop find DP audio
1922 /* Setup audio rate clock source */
1924 * Audio lag happened on DP monitor when unplug a HDMI monitor
1927 * In case of DP and HDMI connected or HDMI only, DCCG_AUDIO_DTO_SEL
1928 * is set to either dto0 or dto1, audio should work fine.
1929 * In case of DP connected only, DCCG_AUDIO_DTO_SEL should be dto1,
1930 * set to dto0 will cause audio lag.
1933 * Not optimized audio wall dto setup. When mode set, iterate pipe_ctx,
1934 * find first available pipe with audio, setup audio wall DTO per topology
1935 * instead of per pipe.
1937 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1938 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
1940 if (pipe_ctx->stream == NULL)
1943 if (pipe_ctx->top_pipe)
1946 if (pipe_ctx->stream->signal != SIGNAL_TYPE_HDMI_TYPE_A)
1949 if (pipe_ctx->stream_res.audio != NULL) {
1950 struct audio_output audio_output;
1952 build_audio_output(context, pipe_ctx, &audio_output);
1954 pipe_ctx->stream_res.audio->funcs->wall_dto_setup(
1955 pipe_ctx->stream_res.audio,
1956 pipe_ctx->stream->signal,
1957 &audio_output.crtc_info,
1958 &audio_output.pll_info);
1963 /* no HDMI audio is found, try DP audio */
1964 if (i == dc->res_pool->pipe_count) {
1965 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1966 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
1968 if (pipe_ctx->stream == NULL)
1971 if (pipe_ctx->top_pipe)
1974 if (!dc_is_dp_signal(pipe_ctx->stream->signal))
1977 if (pipe_ctx->stream_res.audio != NULL) {
1978 struct audio_output audio_output;
1980 build_audio_output(context, pipe_ctx, &audio_output);
1982 pipe_ctx->stream_res.audio->funcs->wall_dto_setup(
1983 pipe_ctx->stream_res.audio,
1984 pipe_ctx->stream->signal,
1985 &audio_output.crtc_info,
1986 &audio_output.pll_info);
1993 enum dc_status dce110_apply_ctx_to_hw(
1995 struct dc_state *context)
1997 struct dc_bios *dcb = dc->ctx->dc_bios;
1998 enum dc_status status;
2001 /* Reset old context */
2002 /* look up the targets that have been removed since last commit */
2003 dc->hwss.reset_hw_ctx_wrap(dc, context);
2005 /* Skip applying if no targets */
2006 if (context->stream_count <= 0)
2009 /* Apply new context */
2010 dcb->funcs->set_scratch_critical_state(dcb, true);
2012 /* below is for real asic only */
2013 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2014 struct pipe_ctx *pipe_ctx_old =
2015 &dc->current_state->res_ctx.pipe_ctx[i];
2016 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2018 if (pipe_ctx->stream == NULL || pipe_ctx->top_pipe)
2021 if (pipe_ctx->stream == pipe_ctx_old->stream) {
2022 if (pipe_ctx_old->clock_source != pipe_ctx->clock_source)
2023 dce_crtc_switch_to_clk_src(dc->hwseq,
2024 pipe_ctx->clock_source, i);
2028 dc->hwss.enable_display_power_gating(
2029 dc, i, dc->ctx->dc_bios,
2030 PIPE_GATING_CONTROL_DISABLE);
2033 if (dc->fbc_compressor)
2034 dc->fbc_compressor->funcs->disable_fbc(dc->fbc_compressor);
2036 dce110_setup_audio_dto(dc, context);
2038 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2039 struct pipe_ctx *pipe_ctx_old =
2040 &dc->current_state->res_ctx.pipe_ctx[i];
2041 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2043 if (pipe_ctx->stream == NULL)
2046 if (pipe_ctx->stream == pipe_ctx_old->stream)
2049 if (pipe_ctx_old->stream && !pipe_need_reprogram(pipe_ctx_old, pipe_ctx))
2052 if (pipe_ctx->top_pipe)
2055 status = apply_single_controller_ctx_to_hw(
2060 if (DC_OK != status)
2064 if (dc->fbc_compressor)
2065 enable_fbc(dc, dc->current_state);
2067 dcb->funcs->set_scratch_critical_state(dcb, false);
2072 /*******************************************************************************
2073 * Front End programming
2074 ******************************************************************************/
2075 static void set_default_colors(struct pipe_ctx *pipe_ctx)
2077 struct default_adjustment default_adjust = { 0 };
2079 default_adjust.force_hw_default = false;
2080 default_adjust.in_color_space = pipe_ctx->plane_state->color_space;
2081 default_adjust.out_color_space = pipe_ctx->stream->output_color_space;
2082 default_adjust.csc_adjust_type = GRAPHICS_CSC_ADJUST_TYPE_SW;
2083 default_adjust.surface_pixel_format = pipe_ctx->plane_res.scl_data.format;
2085 /* display color depth */
2086 default_adjust.color_depth =
2087 pipe_ctx->stream->timing.display_color_depth;
2089 /* Lb color depth */
2090 default_adjust.lb_color_depth = pipe_ctx->plane_res.scl_data.lb_params.depth;
2092 pipe_ctx->plane_res.xfm->funcs->opp_set_csc_default(
2093 pipe_ctx->plane_res.xfm, &default_adjust);
2097 /*******************************************************************************
2098 * In order to turn on/off specific surface we will program
2101 * In case that we have two surfaces and they have a different visibility
2102 * we can't turn off the CRTC since it will turn off the entire display
2104 * |----------------------------------------------- |
2105 * |bottom pipe|curr pipe | | |
2106 * |Surface |Surface | Blender | CRCT |
2107 * |visibility |visibility | Configuration| |
2108 * |------------------------------------------------|
2109 * | off | off | CURRENT_PIPE | blank |
2110 * | off | on | CURRENT_PIPE | unblank |
2111 * | on | off | OTHER_PIPE | unblank |
2112 * | on | on | BLENDING | unblank |
2113 * -------------------------------------------------|
2115 ******************************************************************************/
2116 static void program_surface_visibility(const struct dc *dc,
2117 struct pipe_ctx *pipe_ctx)
2119 enum blnd_mode blender_mode = BLND_MODE_CURRENT_PIPE;
2120 bool blank_target = false;
2122 if (pipe_ctx->bottom_pipe) {
2124 /* For now we are supporting only two pipes */
2125 ASSERT(pipe_ctx->bottom_pipe->bottom_pipe == NULL);
2127 if (pipe_ctx->bottom_pipe->plane_state->visible) {
2128 if (pipe_ctx->plane_state->visible)
2129 blender_mode = BLND_MODE_BLENDING;
2131 blender_mode = BLND_MODE_OTHER_PIPE;
2133 } else if (!pipe_ctx->plane_state->visible)
2134 blank_target = true;
2136 } else if (!pipe_ctx->plane_state->visible)
2137 blank_target = true;
2139 dce_set_blender_mode(dc->hwseq, pipe_ctx->stream_res.tg->inst, blender_mode);
2140 pipe_ctx->stream_res.tg->funcs->set_blank(pipe_ctx->stream_res.tg, blank_target);
2144 static void program_gamut_remap(struct pipe_ctx *pipe_ctx)
2147 struct xfm_grph_csc_adjustment adjust;
2148 memset(&adjust, 0, sizeof(adjust));
2149 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS;
2152 if (pipe_ctx->stream->gamut_remap_matrix.enable_remap == true) {
2153 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_SW;
2155 for (i = 0; i < CSC_TEMPERATURE_MATRIX_SIZE; i++)
2156 adjust.temperature_matrix[i] =
2157 pipe_ctx->stream->gamut_remap_matrix.matrix[i];
2160 pipe_ctx->plane_res.xfm->funcs->transform_set_gamut_remap(pipe_ctx->plane_res.xfm, &adjust);
2162 static void update_plane_addr(const struct dc *dc,
2163 struct pipe_ctx *pipe_ctx)
2165 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
2167 if (plane_state == NULL)
2170 pipe_ctx->plane_res.mi->funcs->mem_input_program_surface_flip_and_addr(
2171 pipe_ctx->plane_res.mi,
2172 &plane_state->address,
2173 plane_state->flip_immediate);
2175 plane_state->status.requested_address = plane_state->address;
2178 static void dce110_update_pending_status(struct pipe_ctx *pipe_ctx)
2180 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
2182 if (plane_state == NULL)
2185 plane_state->status.is_flip_pending =
2186 pipe_ctx->plane_res.mi->funcs->mem_input_is_flip_pending(
2187 pipe_ctx->plane_res.mi);
2189 if (plane_state->status.is_flip_pending && !plane_state->visible)
2190 pipe_ctx->plane_res.mi->current_address = pipe_ctx->plane_res.mi->request_address;
2192 plane_state->status.current_address = pipe_ctx->plane_res.mi->current_address;
2193 if (pipe_ctx->plane_res.mi->current_address.type == PLN_ADDR_TYPE_GRPH_STEREO &&
2194 pipe_ctx->stream_res.tg->funcs->is_stereo_left_eye) {
2195 plane_state->status.is_right_eye =\
2196 !pipe_ctx->stream_res.tg->funcs->is_stereo_left_eye(pipe_ctx->stream_res.tg);
2200 void dce110_power_down(struct dc *dc)
2202 power_down_all_hw_blocks(dc);
2203 disable_vga_and_power_gate_all_controllers(dc);
2206 static bool wait_for_reset_trigger_to_occur(
2207 struct dc_context *dc_ctx,
2208 struct timing_generator *tg)
2212 /* To avoid endless loop we wait at most
2213 * frames_to_wait_on_triggered_reset frames for the reset to occur. */
2214 const uint32_t frames_to_wait_on_triggered_reset = 10;
2217 for (i = 0; i < frames_to_wait_on_triggered_reset; i++) {
2219 if (!tg->funcs->is_counter_moving(tg)) {
2220 DC_ERROR("TG counter is not moving!\n");
2224 if (tg->funcs->did_triggered_reset_occur(tg)) {
2226 /* usually occurs at i=1 */
2227 DC_SYNC_INFO("GSL: reset occurred at wait count: %d\n",
2232 /* Wait for one frame. */
2233 tg->funcs->wait_for_state(tg, CRTC_STATE_VACTIVE);
2234 tg->funcs->wait_for_state(tg, CRTC_STATE_VBLANK);
2238 DC_ERROR("GSL: Timeout on reset trigger!\n");
2243 /* Enable timing synchronization for a group of Timing Generators. */
2244 static void dce110_enable_timing_synchronization(
2248 struct pipe_ctx *grouped_pipes[])
2250 struct dc_context *dc_ctx = dc->ctx;
2251 struct dcp_gsl_params gsl_params = { 0 };
2254 DC_SYNC_INFO("GSL: Setting-up...\n");
2256 /* Designate a single TG in the group as a master.
2257 * Since HW doesn't care which one, we always assign
2258 * the 1st one in the group. */
2259 gsl_params.gsl_group = 0;
2260 gsl_params.gsl_master = grouped_pipes[0]->stream_res.tg->inst;
2262 for (i = 0; i < group_size; i++)
2263 grouped_pipes[i]->stream_res.tg->funcs->setup_global_swap_lock(
2264 grouped_pipes[i]->stream_res.tg, &gsl_params);
2266 /* Reset slave controllers on master VSync */
2267 DC_SYNC_INFO("GSL: enabling trigger-reset\n");
2269 for (i = 1 /* skip the master */; i < group_size; i++)
2270 grouped_pipes[i]->stream_res.tg->funcs->enable_reset_trigger(
2271 grouped_pipes[i]->stream_res.tg,
2272 gsl_params.gsl_group);
2274 for (i = 1 /* skip the master */; i < group_size; i++) {
2275 DC_SYNC_INFO("GSL: waiting for reset to occur.\n");
2276 wait_for_reset_trigger_to_occur(dc_ctx, grouped_pipes[i]->stream_res.tg);
2277 grouped_pipes[i]->stream_res.tg->funcs->disable_reset_trigger(
2278 grouped_pipes[i]->stream_res.tg);
2281 /* GSL Vblank synchronization is a one time sync mechanism, assumption
2282 * is that the sync'ed displays will not drift out of sync over time*/
2283 DC_SYNC_INFO("GSL: Restoring register states.\n");
2284 for (i = 0; i < group_size; i++)
2285 grouped_pipes[i]->stream_res.tg->funcs->tear_down_global_swap_lock(grouped_pipes[i]->stream_res.tg);
2287 DC_SYNC_INFO("GSL: Set-up complete.\n");
2290 static void dce110_enable_per_frame_crtc_position_reset(
2293 struct pipe_ctx *grouped_pipes[])
2295 struct dc_context *dc_ctx = dc->ctx;
2296 struct dcp_gsl_params gsl_params = { 0 };
2299 gsl_params.gsl_group = 0;
2300 gsl_params.gsl_master = 0;
2302 for (i = 0; i < group_size; i++)
2303 grouped_pipes[i]->stream_res.tg->funcs->setup_global_swap_lock(
2304 grouped_pipes[i]->stream_res.tg, &gsl_params);
2306 DC_SYNC_INFO("GSL: enabling trigger-reset\n");
2308 for (i = 1; i < group_size; i++)
2309 grouped_pipes[i]->stream_res.tg->funcs->enable_crtc_reset(
2310 grouped_pipes[i]->stream_res.tg,
2311 gsl_params.gsl_master,
2312 &grouped_pipes[i]->stream->triggered_crtc_reset);
2314 DC_SYNC_INFO("GSL: waiting for reset to occur.\n");
2315 for (i = 1; i < group_size; i++)
2316 wait_for_reset_trigger_to_occur(dc_ctx, grouped_pipes[i]->stream_res.tg);
2318 for (i = 0; i < group_size; i++)
2319 grouped_pipes[i]->stream_res.tg->funcs->tear_down_global_swap_lock(grouped_pipes[i]->stream_res.tg);
2323 static void init_hw(struct dc *dc)
2327 struct transform *xfm;
2330 bp = dc->ctx->dc_bios;
2331 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2332 xfm = dc->res_pool->transforms[i];
2333 xfm->funcs->transform_reset(xfm);
2335 dc->hwss.enable_display_power_gating(
2337 PIPE_GATING_CONTROL_INIT);
2338 dc->hwss.enable_display_power_gating(
2340 PIPE_GATING_CONTROL_DISABLE);
2341 dc->hwss.enable_display_pipe_clock_gating(
2346 dce_clock_gating_power_up(dc->hwseq, false);
2347 /***************************************/
2349 for (i = 0; i < dc->link_count; i++) {
2350 /****************************************/
2351 /* Power up AND update implementation according to the
2352 * required signal (which may be different from the
2353 * default signal on connector). */
2354 struct dc_link *link = dc->links[i];
2356 if (link->link_enc->connector.id == CONNECTOR_ID_EDP)
2357 dc->hwss.edp_power_control(link, true);
2359 link->link_enc->funcs->hw_init(link->link_enc);
2362 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2363 struct timing_generator *tg = dc->res_pool->timing_generators[i];
2365 tg->funcs->disable_vga(tg);
2367 /* Blank controller using driver code instead of
2369 tg->funcs->set_blank(tg, true);
2370 hwss_wait_for_blank_complete(tg);
2373 for (i = 0; i < dc->res_pool->audio_count; i++) {
2374 struct audio *audio = dc->res_pool->audios[i];
2375 audio->funcs->hw_init(audio);
2378 abm = dc->res_pool->abm;
2380 abm->funcs->init_backlight(abm);
2381 abm->funcs->abm_init(abm);
2384 if (dc->fbc_compressor)
2385 dc->fbc_compressor->funcs->power_up_fbc(dc->fbc_compressor);
2390 void dce110_prepare_bandwidth(
2392 struct dc_state *context)
2394 struct clk_mgr *dccg = dc->res_pool->clk_mgr;
2396 dce110_set_safe_displaymarks(&context->res_ctx, dc->res_pool);
2398 dccg->funcs->update_clocks(
2404 void dce110_optimize_bandwidth(
2406 struct dc_state *context)
2408 struct clk_mgr *dccg = dc->res_pool->clk_mgr;
2410 dce110_set_displaymarks(dc, context);
2412 dccg->funcs->update_clocks(
2418 static void dce110_program_front_end_for_pipe(
2419 struct dc *dc, struct pipe_ctx *pipe_ctx)
2421 struct mem_input *mi = pipe_ctx->plane_res.mi;
2422 struct pipe_ctx *old_pipe = NULL;
2423 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
2424 struct xfm_grph_csc_adjustment adjust;
2425 struct out_csc_color_matrix tbl_entry;
2428 memset(&tbl_entry, 0, sizeof(tbl_entry));
2430 if (dc->current_state)
2431 old_pipe = &dc->current_state->res_ctx.pipe_ctx[pipe_ctx->pipe_idx];
2433 memset(&adjust, 0, sizeof(adjust));
2434 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS;
2436 dce_enable_fe_clock(dc->hwseq, mi->inst, true);
2438 set_default_colors(pipe_ctx);
2439 if (pipe_ctx->stream->csc_color_matrix.enable_adjustment
2441 tbl_entry.color_space =
2442 pipe_ctx->stream->output_color_space;
2444 for (i = 0; i < 12; i++)
2445 tbl_entry.regval[i] =
2446 pipe_ctx->stream->csc_color_matrix.matrix[i];
2448 pipe_ctx->plane_res.xfm->funcs->opp_set_csc_adjustment
2449 (pipe_ctx->plane_res.xfm, &tbl_entry);
2452 if (pipe_ctx->stream->gamut_remap_matrix.enable_remap == true) {
2453 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_SW;
2455 for (i = 0; i < CSC_TEMPERATURE_MATRIX_SIZE; i++)
2456 adjust.temperature_matrix[i] =
2457 pipe_ctx->stream->gamut_remap_matrix.matrix[i];
2460 pipe_ctx->plane_res.xfm->funcs->transform_set_gamut_remap(pipe_ctx->plane_res.xfm, &adjust);
2462 pipe_ctx->plane_res.scl_data.lb_params.alpha_en = pipe_ctx->bottom_pipe != 0;
2464 program_scaler(dc, pipe_ctx);
2466 mi->funcs->mem_input_program_surface_config(
2468 plane_state->format,
2469 &plane_state->tiling_info,
2470 &plane_state->plane_size,
2471 plane_state->rotation,
2474 if (mi->funcs->set_blank)
2475 mi->funcs->set_blank(mi, pipe_ctx->plane_state->visible);
2477 if (dc->config.gpu_vm_support)
2478 mi->funcs->mem_input_program_pte_vm(
2479 pipe_ctx->plane_res.mi,
2480 plane_state->format,
2481 &plane_state->tiling_info,
2482 plane_state->rotation);
2484 /* Moved programming gamma from dc to hwss */
2485 if (pipe_ctx->plane_state->update_flags.bits.full_update ||
2486 pipe_ctx->plane_state->update_flags.bits.in_transfer_func_change ||
2487 pipe_ctx->plane_state->update_flags.bits.gamma_change)
2488 dc->hwss.set_input_transfer_func(pipe_ctx, pipe_ctx->plane_state);
2490 if (pipe_ctx->plane_state->update_flags.bits.full_update)
2491 dc->hwss.set_output_transfer_func(pipe_ctx, pipe_ctx->stream);
2494 "Pipe:%d %p: addr hi:0x%x, "
2497 " %d; dst: %d, %d, %d, %d;"
2498 "clip: %d, %d, %d, %d\n",
2500 (void *) pipe_ctx->plane_state,
2501 pipe_ctx->plane_state->address.grph.addr.high_part,
2502 pipe_ctx->plane_state->address.grph.addr.low_part,
2503 pipe_ctx->plane_state->src_rect.x,
2504 pipe_ctx->plane_state->src_rect.y,
2505 pipe_ctx->plane_state->src_rect.width,
2506 pipe_ctx->plane_state->src_rect.height,
2507 pipe_ctx->plane_state->dst_rect.x,
2508 pipe_ctx->plane_state->dst_rect.y,
2509 pipe_ctx->plane_state->dst_rect.width,
2510 pipe_ctx->plane_state->dst_rect.height,
2511 pipe_ctx->plane_state->clip_rect.x,
2512 pipe_ctx->plane_state->clip_rect.y,
2513 pipe_ctx->plane_state->clip_rect.width,
2514 pipe_ctx->plane_state->clip_rect.height);
2517 "Pipe %d: width, height, x, y\n"
2518 "viewport:%d, %d, %d, %d\n"
2519 "recout: %d, %d, %d, %d\n",
2521 pipe_ctx->plane_res.scl_data.viewport.width,
2522 pipe_ctx->plane_res.scl_data.viewport.height,
2523 pipe_ctx->plane_res.scl_data.viewport.x,
2524 pipe_ctx->plane_res.scl_data.viewport.y,
2525 pipe_ctx->plane_res.scl_data.recout.width,
2526 pipe_ctx->plane_res.scl_data.recout.height,
2527 pipe_ctx->plane_res.scl_data.recout.x,
2528 pipe_ctx->plane_res.scl_data.recout.y);
2531 static void dce110_apply_ctx_for_surface(
2533 const struct dc_stream_state *stream,
2535 struct dc_state *context)
2539 if (num_planes == 0)
2542 if (dc->fbc_compressor)
2543 dc->fbc_compressor->funcs->disable_fbc(dc->fbc_compressor);
2545 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2546 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2547 struct pipe_ctx *old_pipe_ctx = &dc->current_state->res_ctx.pipe_ctx[i];
2549 if (stream == pipe_ctx->stream) {
2550 if (!pipe_ctx->top_pipe &&
2551 (pipe_ctx->plane_state || old_pipe_ctx->plane_state))
2552 dc->hwss.pipe_control_lock(dc, pipe_ctx, true);
2556 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2557 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2559 if (pipe_ctx->stream != stream)
2562 /* Need to allocate mem before program front end for Fiji */
2563 pipe_ctx->plane_res.mi->funcs->allocate_mem_input(
2564 pipe_ctx->plane_res.mi,
2565 pipe_ctx->stream->timing.h_total,
2566 pipe_ctx->stream->timing.v_total,
2567 pipe_ctx->stream->timing.pix_clk_khz,
2568 context->stream_count);
2570 dce110_program_front_end_for_pipe(dc, pipe_ctx);
2572 dc->hwss.update_plane_addr(dc, pipe_ctx);
2574 program_surface_visibility(dc, pipe_ctx);
2578 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2579 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2580 struct pipe_ctx *old_pipe_ctx = &dc->current_state->res_ctx.pipe_ctx[i];
2582 if ((stream == pipe_ctx->stream) &&
2583 (!pipe_ctx->top_pipe) &&
2584 (pipe_ctx->plane_state || old_pipe_ctx->plane_state))
2585 dc->hwss.pipe_control_lock(dc, pipe_ctx, false);
2588 if (dc->fbc_compressor)
2589 enable_fbc(dc, dc->current_state);
2592 static void dce110_power_down_fe(struct dc *dc, struct pipe_ctx *pipe_ctx)
2594 int fe_idx = pipe_ctx->plane_res.mi ?
2595 pipe_ctx->plane_res.mi->inst : pipe_ctx->pipe_idx;
2597 /* Do not power down fe when stream is active on dce*/
2598 if (dc->current_state->res_ctx.pipe_ctx[fe_idx].stream)
2601 dc->hwss.enable_display_power_gating(
2602 dc, fe_idx, dc->ctx->dc_bios, PIPE_GATING_CONTROL_ENABLE);
2604 dc->res_pool->transforms[fe_idx]->funcs->transform_reset(
2605 dc->res_pool->transforms[fe_idx]);
2608 static void dce110_wait_for_mpcc_disconnect(
2610 struct resource_pool *res_pool,
2611 struct pipe_ctx *pipe_ctx)
2616 void dce110_set_cursor_position(struct pipe_ctx *pipe_ctx)
2618 struct dc_cursor_position pos_cpy = pipe_ctx->stream->cursor_position;
2619 struct input_pixel_processor *ipp = pipe_ctx->plane_res.ipp;
2620 struct mem_input *mi = pipe_ctx->plane_res.mi;
2621 struct dc_cursor_mi_param param = {
2622 .pixel_clk_khz = pipe_ctx->stream->timing.pix_clk_khz,
2623 .ref_clk_khz = pipe_ctx->stream->ctx->dc->res_pool->ref_clock_inKhz,
2624 .viewport = pipe_ctx->plane_res.scl_data.viewport,
2625 .h_scale_ratio = pipe_ctx->plane_res.scl_data.ratios.horz,
2626 .v_scale_ratio = pipe_ctx->plane_res.scl_data.ratios.vert,
2627 .rotation = pipe_ctx->plane_state->rotation,
2628 .mirror = pipe_ctx->plane_state->horizontal_mirror
2631 if (pipe_ctx->plane_state->address.type
2632 == PLN_ADDR_TYPE_VIDEO_PROGRESSIVE)
2633 pos_cpy.enable = false;
2635 if (pipe_ctx->top_pipe && pipe_ctx->plane_state != pipe_ctx->top_pipe->plane_state)
2636 pos_cpy.enable = false;
2638 if (ipp->funcs->ipp_cursor_set_position)
2639 ipp->funcs->ipp_cursor_set_position(ipp, &pos_cpy, ¶m);
2640 if (mi->funcs->set_cursor_position)
2641 mi->funcs->set_cursor_position(mi, &pos_cpy, ¶m);
2644 void dce110_set_cursor_attribute(struct pipe_ctx *pipe_ctx)
2646 struct dc_cursor_attributes *attributes = &pipe_ctx->stream->cursor_attributes;
2648 if (pipe_ctx->plane_res.ipp &&
2649 pipe_ctx->plane_res.ipp->funcs->ipp_cursor_set_attributes)
2650 pipe_ctx->plane_res.ipp->funcs->ipp_cursor_set_attributes(
2651 pipe_ctx->plane_res.ipp, attributes);
2653 if (pipe_ctx->plane_res.mi &&
2654 pipe_ctx->plane_res.mi->funcs->set_cursor_attributes)
2655 pipe_ctx->plane_res.mi->funcs->set_cursor_attributes(
2656 pipe_ctx->plane_res.mi, attributes);
2658 if (pipe_ctx->plane_res.xfm &&
2659 pipe_ctx->plane_res.xfm->funcs->set_cursor_attributes)
2660 pipe_ctx->plane_res.xfm->funcs->set_cursor_attributes(
2661 pipe_ctx->plane_res.xfm, attributes);
2664 static const struct hw_sequencer_funcs dce110_funcs = {
2665 .program_gamut_remap = program_gamut_remap,
2667 .apply_ctx_to_hw = dce110_apply_ctx_to_hw,
2668 .apply_ctx_for_surface = dce110_apply_ctx_for_surface,
2669 .update_plane_addr = update_plane_addr,
2670 .update_pending_status = dce110_update_pending_status,
2671 .set_input_transfer_func = dce110_set_input_transfer_func,
2672 .set_output_transfer_func = dce110_set_output_transfer_func,
2673 .power_down = dce110_power_down,
2674 .enable_accelerated_mode = dce110_enable_accelerated_mode,
2675 .enable_timing_synchronization = dce110_enable_timing_synchronization,
2676 .enable_per_frame_crtc_position_reset = dce110_enable_per_frame_crtc_position_reset,
2677 .update_info_frame = dce110_update_info_frame,
2678 .enable_stream = dce110_enable_stream,
2679 .disable_stream = dce110_disable_stream,
2680 .unblank_stream = dce110_unblank_stream,
2681 .blank_stream = dce110_blank_stream,
2682 .enable_audio_stream = dce110_enable_audio_stream,
2683 .disable_audio_stream = dce110_disable_audio_stream,
2684 .enable_display_pipe_clock_gating = enable_display_pipe_clock_gating,
2685 .enable_display_power_gating = dce110_enable_display_power_gating,
2686 .disable_plane = dce110_power_down_fe,
2687 .pipe_control_lock = dce_pipe_control_lock,
2688 .prepare_bandwidth = dce110_prepare_bandwidth,
2689 .optimize_bandwidth = dce110_optimize_bandwidth,
2691 .get_position = get_position,
2692 .set_static_screen_control = set_static_screen_control,
2693 .reset_hw_ctx_wrap = dce110_reset_hw_ctx_wrap,
2694 .enable_stream_timing = dce110_enable_stream_timing,
2695 .setup_stereo = NULL,
2696 .set_avmute = dce110_set_avmute,
2697 .wait_for_mpcc_disconnect = dce110_wait_for_mpcc_disconnect,
2698 .edp_backlight_control = hwss_edp_backlight_control,
2699 .edp_power_control = hwss_edp_power_control,
2700 .edp_wait_for_hpd_ready = hwss_edp_wait_for_hpd_ready,
2701 .set_cursor_position = dce110_set_cursor_position,
2702 .set_cursor_attribute = dce110_set_cursor_attribute
2705 void dce110_hw_sequencer_construct(struct dc *dc)
2707 dc->hwss = dce110_funcs;