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_hw_sequencer.h"
36 #include "dce110_timing_generator.h"
37 #include "dce/dce_hwseq.h"
38 #include "gpio_service_interface.h"
40 #include "dce110_compressor.h"
42 #include "bios/bios_parser_helper.h"
43 #include "timing_generator.h"
44 #include "mem_input.h"
47 #include "transform.h"
48 #include "stream_encoder.h"
49 #include "link_encoder.h"
50 #include "link_hwss.h"
51 #include "clock_source.h"
55 #include "reg_helper.h"
57 /* include DCE11 register header files */
58 #include "dce/dce_11_0_d.h"
59 #include "dce/dce_11_0_sh_mask.h"
60 #include "custom_float.h"
62 #include "atomfirmware.h"
65 * All values are in milliseconds;
66 * For eDP, after power-up/power/down,
67 * 300/500 msec max. delay from LCDVCC to black video generation
69 #define PANEL_POWER_UP_TIMEOUT 300
70 #define PANEL_POWER_DOWN_TIMEOUT 500
71 #define HPD_CHECK_INTERVAL 10
76 #define DC_LOGGER_INIT()
82 #define FN(reg_name, field_name) \
83 hws->shifts->field_name, hws->masks->field_name
85 struct dce110_hw_seq_reg_offsets {
89 static const struct dce110_hw_seq_reg_offsets reg_offsets[] = {
91 .crtc = (mmCRTC0_CRTC_GSL_CONTROL - mmCRTC_GSL_CONTROL),
94 .crtc = (mmCRTC1_CRTC_GSL_CONTROL - mmCRTC_GSL_CONTROL),
97 .crtc = (mmCRTC2_CRTC_GSL_CONTROL - mmCRTC_GSL_CONTROL),
100 .crtc = (mmCRTCV_GSL_CONTROL - mmCRTC_GSL_CONTROL),
104 #define HW_REG_BLND(reg, id)\
105 (reg + reg_offsets[id].blnd)
107 #define HW_REG_CRTC(reg, id)\
108 (reg + reg_offsets[id].crtc)
110 #define MAX_WATERMARK 0xFFFF
111 #define SAFE_NBP_MARK 0x7FFF
113 /*******************************************************************************
114 * Private definitions
115 ******************************************************************************/
116 /***************************PIPE_CONTROL***********************************/
117 static void dce110_init_pte(struct dc_context *ctx)
121 uint32_t chunk_int = 0;
122 uint32_t chunk_mul = 0;
124 addr = mmUNP_DVMM_PTE_CONTROL;
125 value = dm_read_reg(ctx, addr);
131 DVMM_USE_SINGLE_PTE);
137 DVMM_PTE_BUFFER_MODE0);
143 DVMM_PTE_BUFFER_MODE1);
145 dm_write_reg(ctx, addr, value);
147 addr = mmDVMM_PTE_REQ;
148 value = dm_read_reg(ctx, addr);
150 chunk_int = get_reg_field_value(
153 HFLIP_PTEREQ_PER_CHUNK_INT);
155 chunk_mul = get_reg_field_value(
158 HFLIP_PTEREQ_PER_CHUNK_MULTIPLIER);
160 if (chunk_int != 0x4 || chunk_mul != 0x4) {
166 MAX_PTEREQ_TO_ISSUE);
172 HFLIP_PTEREQ_PER_CHUNK_INT);
178 HFLIP_PTEREQ_PER_CHUNK_MULTIPLIER);
180 dm_write_reg(ctx, addr, value);
183 /**************************************************************************/
185 static void enable_display_pipe_clock_gating(
186 struct dc_context *ctx,
192 static bool dce110_enable_display_power_gating(
194 uint8_t controller_id,
196 enum pipe_gating_control power_gating)
198 enum bp_result bp_result = BP_RESULT_OK;
199 enum bp_pipe_control_action cntl;
200 struct dc_context *ctx = dc->ctx;
201 unsigned int underlay_idx = dc->res_pool->underlay_pipe_index;
203 if (IS_FPGA_MAXIMUS_DC(ctx->dce_environment))
206 if (power_gating == PIPE_GATING_CONTROL_INIT)
207 cntl = ASIC_PIPE_INIT;
208 else if (power_gating == PIPE_GATING_CONTROL_ENABLE)
209 cntl = ASIC_PIPE_ENABLE;
211 cntl = ASIC_PIPE_DISABLE;
213 if (controller_id == underlay_idx)
214 controller_id = CONTROLLER_ID_UNDERLAY0 - 1;
216 if (power_gating != PIPE_GATING_CONTROL_INIT || controller_id == 0){
218 bp_result = dcb->funcs->enable_disp_power_gating(
219 dcb, controller_id + 1, cntl);
221 /* Revert MASTER_UPDATE_MODE to 0 because bios sets it 2
222 * by default when command table is called
224 * Bios parser accepts controller_id = 6 as indicative of
225 * underlay pipe in dce110. But we do not support more
228 if (controller_id < CONTROLLER_ID_MAX - 1)
230 HW_REG_CRTC(mmCRTC_MASTER_UPDATE_MODE, controller_id),
234 if (power_gating != PIPE_GATING_CONTROL_ENABLE)
235 dce110_init_pte(ctx);
237 if (bp_result == BP_RESULT_OK)
243 static void build_prescale_params(struct ipp_prescale_params *prescale_params,
244 const struct dc_plane_state *plane_state)
246 prescale_params->mode = IPP_PRESCALE_MODE_FIXED_UNSIGNED;
248 switch (plane_state->format) {
249 case SURFACE_PIXEL_FORMAT_GRPH_RGB565:
250 prescale_params->scale = 0x2082;
252 case SURFACE_PIXEL_FORMAT_GRPH_ARGB8888:
253 case SURFACE_PIXEL_FORMAT_GRPH_ABGR8888:
254 prescale_params->scale = 0x2020;
256 case SURFACE_PIXEL_FORMAT_GRPH_ARGB2101010:
257 case SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010:
258 prescale_params->scale = 0x2008;
260 case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616:
261 case SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616F:
262 prescale_params->scale = 0x2000;
271 dce110_set_input_transfer_func(struct pipe_ctx *pipe_ctx,
272 const struct dc_plane_state *plane_state)
274 struct input_pixel_processor *ipp = pipe_ctx->plane_res.ipp;
275 const struct dc_transfer_func *tf = NULL;
276 struct ipp_prescale_params prescale_params = { 0 };
282 if (plane_state->in_transfer_func)
283 tf = plane_state->in_transfer_func;
285 build_prescale_params(&prescale_params, plane_state);
286 ipp->funcs->ipp_program_prescale(ipp, &prescale_params);
288 if (plane_state->gamma_correction &&
289 !plane_state->gamma_correction->is_identity &&
290 dce_use_lut(plane_state->format))
291 ipp->funcs->ipp_program_input_lut(ipp, plane_state->gamma_correction);
294 /* Default case if no input transfer function specified */
295 ipp->funcs->ipp_set_degamma(ipp, IPP_DEGAMMA_MODE_HW_sRGB);
296 } else if (tf->type == TF_TYPE_PREDEFINED) {
298 case TRANSFER_FUNCTION_SRGB:
299 ipp->funcs->ipp_set_degamma(ipp, IPP_DEGAMMA_MODE_HW_sRGB);
301 case TRANSFER_FUNCTION_BT709:
302 ipp->funcs->ipp_set_degamma(ipp, IPP_DEGAMMA_MODE_HW_xvYCC);
304 case TRANSFER_FUNCTION_LINEAR:
305 ipp->funcs->ipp_set_degamma(ipp, IPP_DEGAMMA_MODE_BYPASS);
307 case TRANSFER_FUNCTION_PQ:
312 } else if (tf->type == TF_TYPE_BYPASS) {
313 ipp->funcs->ipp_set_degamma(ipp, IPP_DEGAMMA_MODE_BYPASS);
315 /*TF_TYPE_DISTRIBUTED_POINTS - Not supported in DCE 11*/
322 static bool convert_to_custom_float(struct pwl_result_data *rgb_resulted,
323 struct curve_points *arr_points,
324 uint32_t hw_points_num)
326 struct custom_float_format fmt;
328 struct pwl_result_data *rgb = rgb_resulted;
332 fmt.exponenta_bits = 6;
333 fmt.mantissa_bits = 12;
336 if (!convert_to_custom_float_format(arr_points[0].x, &fmt,
337 &arr_points[0].custom_float_x)) {
342 if (!convert_to_custom_float_format(arr_points[0].offset, &fmt,
343 &arr_points[0].custom_float_offset)) {
348 if (!convert_to_custom_float_format(arr_points[0].slope, &fmt,
349 &arr_points[0].custom_float_slope)) {
354 fmt.mantissa_bits = 10;
357 if (!convert_to_custom_float_format(arr_points[1].x, &fmt,
358 &arr_points[1].custom_float_x)) {
363 if (!convert_to_custom_float_format(arr_points[1].y, &fmt,
364 &arr_points[1].custom_float_y)) {
369 if (!convert_to_custom_float_format(arr_points[1].slope, &fmt,
370 &arr_points[1].custom_float_slope)) {
375 fmt.mantissa_bits = 12;
378 while (i != hw_points_num) {
379 if (!convert_to_custom_float_format(rgb->red, &fmt,
385 if (!convert_to_custom_float_format(rgb->green, &fmt,
391 if (!convert_to_custom_float_format(rgb->blue, &fmt,
397 if (!convert_to_custom_float_format(rgb->delta_red, &fmt,
398 &rgb->delta_red_reg)) {
403 if (!convert_to_custom_float_format(rgb->delta_green, &fmt,
404 &rgb->delta_green_reg)) {
409 if (!convert_to_custom_float_format(rgb->delta_blue, &fmt,
410 &rgb->delta_blue_reg)) {
422 #define MAX_LOW_POINT 25
423 #define NUMBER_REGIONS 16
424 #define NUMBER_SW_SEGMENTS 16
427 dce110_translate_regamma_to_hw_format(const struct dc_transfer_func *output_tf,
428 struct pwl_params *regamma_params)
430 struct curve_points *arr_points;
431 struct pwl_result_data *rgb_resulted;
432 struct pwl_result_data *rgb;
433 struct pwl_result_data *rgb_plus_1;
434 struct fixed31_32 y_r;
435 struct fixed31_32 y_g;
436 struct fixed31_32 y_b;
437 struct fixed31_32 y1_min;
438 struct fixed31_32 y3_max;
440 int32_t region_start, region_end;
441 uint32_t i, j, k, seg_distr[NUMBER_REGIONS], increment, start_index, hw_points;
443 if (output_tf == NULL || regamma_params == NULL || output_tf->type == TF_TYPE_BYPASS)
446 arr_points = regamma_params->arr_points;
447 rgb_resulted = regamma_params->rgb_resulted;
450 memset(regamma_params, 0, sizeof(struct pwl_params));
452 if (output_tf->tf == TRANSFER_FUNCTION_PQ) {
454 * segments are from 2^-11 to 2^5
457 region_end = region_start + NUMBER_REGIONS;
459 for (i = 0; i < NUMBER_REGIONS; i++)
464 * segment is from 2^-10 to 2^1
465 * We include an extra segment for range [2^0, 2^1). This is to
466 * ensure that colors with normalized values of 1 don't miss the
490 for (k = 0; k < 16; k++) {
491 if (seg_distr[k] != -1)
492 hw_points += (1 << seg_distr[k]);
496 for (k = 0; k < (region_end - region_start); k++) {
497 increment = NUMBER_SW_SEGMENTS / (1 << seg_distr[k]);
498 start_index = (region_start + k + MAX_LOW_POINT) *
500 for (i = start_index; i < start_index + NUMBER_SW_SEGMENTS;
502 if (j == hw_points - 1)
504 rgb_resulted[j].red = output_tf->tf_pts.red[i];
505 rgb_resulted[j].green = output_tf->tf_pts.green[i];
506 rgb_resulted[j].blue = output_tf->tf_pts.blue[i];
512 start_index = (region_end + MAX_LOW_POINT) * NUMBER_SW_SEGMENTS;
513 rgb_resulted[hw_points - 1].red = output_tf->tf_pts.red[start_index];
514 rgb_resulted[hw_points - 1].green = output_tf->tf_pts.green[start_index];
515 rgb_resulted[hw_points - 1].blue = output_tf->tf_pts.blue[start_index];
517 arr_points[0].x = dc_fixpt_pow(dc_fixpt_from_int(2),
518 dc_fixpt_from_int(region_start));
519 arr_points[1].x = dc_fixpt_pow(dc_fixpt_from_int(2),
520 dc_fixpt_from_int(region_end));
522 y_r = rgb_resulted[0].red;
523 y_g = rgb_resulted[0].green;
524 y_b = rgb_resulted[0].blue;
526 y1_min = dc_fixpt_min(y_r, dc_fixpt_min(y_g, y_b));
528 arr_points[0].y = y1_min;
529 arr_points[0].slope = dc_fixpt_div(arr_points[0].y,
532 y_r = rgb_resulted[hw_points - 1].red;
533 y_g = rgb_resulted[hw_points - 1].green;
534 y_b = rgb_resulted[hw_points - 1].blue;
536 /* see comment above, m_arrPoints[1].y should be the Y value for the
537 * region end (m_numOfHwPoints), not last HW point(m_numOfHwPoints - 1)
539 y3_max = dc_fixpt_max(y_r, dc_fixpt_max(y_g, y_b));
541 arr_points[1].y = y3_max;
543 arr_points[1].slope = dc_fixpt_zero;
545 if (output_tf->tf == TRANSFER_FUNCTION_PQ) {
546 /* for PQ, we want to have a straight line from last HW X point,
547 * and the slope to be such that we hit 1.0 at 10000 nits.
549 const struct fixed31_32 end_value = dc_fixpt_from_int(125);
551 arr_points[1].slope = dc_fixpt_div(
552 dc_fixpt_sub(dc_fixpt_one, arr_points[1].y),
553 dc_fixpt_sub(end_value, arr_points[1].x));
556 regamma_params->hw_points_num = hw_points;
559 for (i = 1; i < 16; i++) {
560 if (seg_distr[k] != -1) {
561 regamma_params->arr_curve_points[k].segments_num = seg_distr[k];
562 regamma_params->arr_curve_points[i].offset =
563 regamma_params->arr_curve_points[k].offset + (1 << seg_distr[k]);
568 if (seg_distr[k] != -1)
569 regamma_params->arr_curve_points[k].segments_num = seg_distr[k];
572 rgb_plus_1 = rgb_resulted + 1;
576 while (i != hw_points + 1) {
577 if (dc_fixpt_lt(rgb_plus_1->red, rgb->red))
578 rgb_plus_1->red = rgb->red;
579 if (dc_fixpt_lt(rgb_plus_1->green, rgb->green))
580 rgb_plus_1->green = rgb->green;
581 if (dc_fixpt_lt(rgb_plus_1->blue, rgb->blue))
582 rgb_plus_1->blue = rgb->blue;
584 rgb->delta_red = dc_fixpt_sub(rgb_plus_1->red, rgb->red);
585 rgb->delta_green = dc_fixpt_sub(rgb_plus_1->green, rgb->green);
586 rgb->delta_blue = dc_fixpt_sub(rgb_plus_1->blue, rgb->blue);
593 convert_to_custom_float(rgb_resulted, arr_points, hw_points);
599 dce110_set_output_transfer_func(struct pipe_ctx *pipe_ctx,
600 const struct dc_stream_state *stream)
602 struct transform *xfm = pipe_ctx->plane_res.xfm;
604 xfm->funcs->opp_power_on_regamma_lut(xfm, true);
605 xfm->regamma_params.hw_points_num = GAMMA_HW_POINTS_NUM;
607 if (stream->out_transfer_func &&
608 stream->out_transfer_func->type == TF_TYPE_PREDEFINED &&
609 stream->out_transfer_func->tf == TRANSFER_FUNCTION_SRGB) {
610 xfm->funcs->opp_set_regamma_mode(xfm, OPP_REGAMMA_SRGB);
611 } else if (dce110_translate_regamma_to_hw_format(stream->out_transfer_func,
612 &xfm->regamma_params)) {
613 xfm->funcs->opp_program_regamma_pwl(xfm, &xfm->regamma_params);
614 xfm->funcs->opp_set_regamma_mode(xfm, OPP_REGAMMA_USER);
616 xfm->funcs->opp_set_regamma_mode(xfm, OPP_REGAMMA_BYPASS);
619 xfm->funcs->opp_power_on_regamma_lut(xfm, false);
624 void dce110_update_info_frame(struct pipe_ctx *pipe_ctx)
629 ASSERT(pipe_ctx->stream);
631 if (pipe_ctx->stream_res.stream_enc == NULL)
632 return; /* this is not root pipe */
634 is_hdmi_tmds = dc_is_hdmi_tmds_signal(pipe_ctx->stream->signal);
635 is_dp = dc_is_dp_signal(pipe_ctx->stream->signal);
637 if (!is_hdmi_tmds && !is_dp)
641 pipe_ctx->stream_res.stream_enc->funcs->update_hdmi_info_packets(
642 pipe_ctx->stream_res.stream_enc,
643 &pipe_ctx->stream_res.encoder_info_frame);
645 pipe_ctx->stream_res.stream_enc->funcs->update_dp_info_packets(
646 pipe_ctx->stream_res.stream_enc,
647 &pipe_ctx->stream_res.encoder_info_frame);
650 void dce110_enable_stream(struct pipe_ctx *pipe_ctx)
652 enum dc_lane_count lane_count =
653 pipe_ctx->stream->link->cur_link_settings.lane_count;
655 struct dc_crtc_timing *timing = &pipe_ctx->stream->timing;
656 struct dc_link *link = pipe_ctx->stream->link;
659 uint32_t active_total_with_borders;
660 uint32_t early_control = 0;
661 struct timing_generator *tg = pipe_ctx->stream_res.tg;
663 /* For MST, there are multiply stream go to only one link.
664 * connect DIG back_end to front_end while enable_stream and
665 * disconnect them during disable_stream
666 * BY this, it is logic clean to separate stream and link */
667 link->link_enc->funcs->connect_dig_be_to_fe(link->link_enc,
668 pipe_ctx->stream_res.stream_enc->id, true);
670 link->dc->hwss.update_info_frame(pipe_ctx);
672 /* enable early control to avoid corruption on DP monitor*/
673 active_total_with_borders =
674 timing->h_addressable
675 + timing->h_border_left
676 + timing->h_border_right;
679 early_control = active_total_with_borders % lane_count;
681 if (early_control == 0)
682 early_control = lane_count;
684 tg->funcs->set_early_control(tg, early_control);
686 /* enable audio only within mode set */
687 if (pipe_ctx->stream_res.audio != NULL) {
688 if (dc_is_dp_signal(pipe_ctx->stream->signal))
689 pipe_ctx->stream_res.stream_enc->funcs->dp_audio_enable(pipe_ctx->stream_res.stream_enc);
697 /*todo: cloned in stream enc, fix*/
698 static bool is_panel_backlight_on(struct dce_hwseq *hws)
702 REG_GET(LVTMA_PWRSEQ_CNTL, LVTMA_BLON, &value);
707 static bool is_panel_powered_on(struct dce_hwseq *hws)
709 uint32_t pwr_seq_state, dig_on, dig_on_ovrd;
712 REG_GET(LVTMA_PWRSEQ_STATE, LVTMA_PWRSEQ_TARGET_STATE_R, &pwr_seq_state);
714 REG_GET_2(LVTMA_PWRSEQ_CNTL, LVTMA_DIGON, &dig_on, LVTMA_DIGON_OVRD, &dig_on_ovrd);
716 return (pwr_seq_state == 1) || (dig_on == 1 && dig_on_ovrd == 1);
719 static enum bp_result link_transmitter_control(
720 struct dc_bios *bios,
721 struct bp_transmitter_control *cntl)
723 enum bp_result result;
725 result = bios->funcs->transmitter_control(bios, cntl);
734 void dce110_edp_wait_for_hpd_ready(
735 struct dc_link *link,
738 struct dc_context *ctx = link->ctx;
739 struct graphics_object_id connector = link->link_enc->connector;
741 bool edp_hpd_high = false;
742 uint32_t time_elapsed = 0;
743 uint32_t timeout = power_up ?
744 PANEL_POWER_UP_TIMEOUT : PANEL_POWER_DOWN_TIMEOUT;
746 if (dal_graphics_object_id_get_connector_id(connector)
747 != CONNECTOR_ID_EDP) {
754 * From KV, we will not HPD low after turning off VCC -
755 * instead, we will check the SW timer in power_up().
760 * When we power on/off the eDP panel,
761 * we need to wait until SENSE bit is high/low.
765 /* TODO what to do with this? */
766 hpd = get_hpd_gpio(ctx->dc_bios, connector, ctx->gpio_service);
773 dal_gpio_open(hpd, GPIO_MODE_INTERRUPT);
775 /* wait until timeout or panel detected */
778 uint32_t detected = 0;
780 dal_gpio_get_value(hpd, &detected);
782 if (!(detected ^ power_up)) {
787 msleep(HPD_CHECK_INTERVAL);
789 time_elapsed += HPD_CHECK_INTERVAL;
790 } while (time_elapsed < timeout);
794 dal_gpio_destroy_irq(&hpd);
796 if (false == edp_hpd_high) {
798 "%s: wait timed out!\n", __func__);
802 void dce110_edp_power_control(
803 struct dc_link *link,
806 struct dc_context *ctx = link->ctx;
807 struct dce_hwseq *hwseq = ctx->dc->hwseq;
808 struct bp_transmitter_control cntl = { 0 };
809 enum bp_result bp_result;
812 if (dal_graphics_object_id_get_connector_id(link->link_enc->connector)
813 != CONNECTOR_ID_EDP) {
818 if (power_up != is_panel_powered_on(hwseq)) {
819 /* Send VBIOS command to prompt eDP panel power */
821 unsigned long long current_ts = dm_get_timestamp(ctx);
822 unsigned long long duration_in_ms =
823 div64_u64(dm_get_elapse_time_in_ns(
826 link->link_trace.time_stamp.edp_poweroff), 1000000);
827 unsigned long long wait_time_ms = 0;
829 /* max 500ms from LCDVDD off to on */
830 unsigned long long edp_poweroff_time_ms = 500;
832 if (link->local_sink != NULL)
833 edp_poweroff_time_ms =
834 500 + link->local_sink->edid_caps.panel_patch.extra_t12_ms;
835 if (link->link_trace.time_stamp.edp_poweroff == 0)
836 wait_time_ms = edp_poweroff_time_ms;
837 else if (duration_in_ms < edp_poweroff_time_ms)
838 wait_time_ms = edp_poweroff_time_ms - duration_in_ms;
841 msleep(wait_time_ms);
842 dm_output_to_console("%s: wait %lld ms to power on eDP.\n",
843 __func__, wait_time_ms);
849 "%s: Panel Power action: %s\n",
850 __func__, (power_up ? "On":"Off"));
852 cntl.action = power_up ?
853 TRANSMITTER_CONTROL_POWER_ON :
854 TRANSMITTER_CONTROL_POWER_OFF;
855 cntl.transmitter = link->link_enc->transmitter;
856 cntl.connector_obj_id = link->link_enc->connector;
857 cntl.coherent = false;
858 cntl.lanes_number = LANE_COUNT_FOUR;
859 cntl.hpd_sel = link->link_enc->hpd_source;
860 bp_result = link_transmitter_control(ctx->dc_bios, &cntl);
863 /*save driver power off time stamp*/
864 link->link_trace.time_stamp.edp_poweroff = dm_get_timestamp(ctx);
866 link->link_trace.time_stamp.edp_poweron = dm_get_timestamp(ctx);
868 if (bp_result != BP_RESULT_OK)
870 "%s: Panel Power bp_result: %d\n",
871 __func__, bp_result);
874 "%s: Skipping Panel Power action: %s\n",
875 __func__, (power_up ? "On":"Off"));
879 /*todo: cloned in stream enc, fix*/
882 * eDP only. Control the backlight of the eDP panel
884 void dce110_edp_backlight_control(
885 struct dc_link *link,
888 struct dc_context *ctx = link->ctx;
889 struct dce_hwseq *hws = ctx->dc->hwseq;
890 struct bp_transmitter_control cntl = { 0 };
892 if (dal_graphics_object_id_get_connector_id(link->link_enc->connector)
893 != CONNECTOR_ID_EDP) {
898 if (enable && is_panel_backlight_on(hws)) {
900 "%s: panel already powered up. Do nothing.\n",
905 /* Send VBIOS command to control eDP panel backlight */
908 "%s: backlight action: %s\n",
909 __func__, (enable ? "On":"Off"));
911 cntl.action = enable ?
912 TRANSMITTER_CONTROL_BACKLIGHT_ON :
913 TRANSMITTER_CONTROL_BACKLIGHT_OFF;
915 /*cntl.engine_id = ctx->engine;*/
916 cntl.transmitter = link->link_enc->transmitter;
917 cntl.connector_obj_id = link->link_enc->connector;
919 cntl.lanes_number = LANE_COUNT_FOUR;
920 cntl.hpd_sel = link->link_enc->hpd_source;
921 cntl.signal = SIGNAL_TYPE_EDP;
923 /* For eDP, the following delays might need to be considered
924 * after link training completed:
925 * idle period - min. accounts for required BS-Idle pattern,
926 * max. allows for source frame synchronization);
927 * 50 msec max. delay from valid video data from source
928 * to video on dislpay or backlight enable.
930 * Disable the delay for now.
931 * Enable it in the future if necessary.
933 /* dc_service_sleep_in_milliseconds(50); */
935 if (cntl.action == TRANSMITTER_CONTROL_BACKLIGHT_ON)
936 edp_receiver_ready_T7(link);
937 link_transmitter_control(ctx->dc_bios, &cntl);
939 if (cntl.action == TRANSMITTER_CONTROL_BACKLIGHT_OFF)
940 edp_receiver_ready_T9(link);
943 void dce110_enable_audio_stream(struct pipe_ctx *pipe_ctx)
945 /* notify audio driver for audio modes of monitor */
947 struct clk_mgr *clk_mgr;
948 unsigned int i, num_audio = 1;
950 if (!pipe_ctx->stream)
953 core_dc = pipe_ctx->stream->ctx->dc;
954 clk_mgr = core_dc->clk_mgr;
956 if (pipe_ctx->stream_res.audio && pipe_ctx->stream_res.audio->enabled == true)
959 if (pipe_ctx->stream_res.audio) {
960 for (i = 0; i < MAX_PIPES; i++) {
961 /*current_state not updated yet*/
962 if (core_dc->current_state->res_ctx.pipe_ctx[i].stream_res.audio != NULL)
966 pipe_ctx->stream_res.audio->funcs->az_enable(pipe_ctx->stream_res.audio);
968 if (num_audio >= 1 && clk_mgr->funcs->enable_pme_wa)
969 /*this is the first audio. apply the PME w/a in order to wake AZ from D3*/
970 clk_mgr->funcs->enable_pme_wa(clk_mgr);
972 /* TODO: audio should be per stream rather than per link */
973 pipe_ctx->stream_res.stream_enc->funcs->audio_mute_control(
974 pipe_ctx->stream_res.stream_enc, false);
975 if (pipe_ctx->stream_res.audio)
976 pipe_ctx->stream_res.audio->enabled = true;
980 void dce110_disable_audio_stream(struct pipe_ctx *pipe_ctx)
983 struct clk_mgr *clk_mgr;
985 if (!pipe_ctx || !pipe_ctx->stream)
988 dc = pipe_ctx->stream->ctx->dc;
989 clk_mgr = dc->clk_mgr;
991 if (pipe_ctx->stream_res.audio && pipe_ctx->stream_res.audio->enabled == false)
994 pipe_ctx->stream_res.stream_enc->funcs->audio_mute_control(
995 pipe_ctx->stream_res.stream_enc, true);
996 if (pipe_ctx->stream_res.audio) {
997 pipe_ctx->stream_res.audio->enabled = false;
999 if (dc_is_dp_signal(pipe_ctx->stream->signal))
1000 pipe_ctx->stream_res.stream_enc->funcs->dp_audio_disable(
1001 pipe_ctx->stream_res.stream_enc);
1003 pipe_ctx->stream_res.stream_enc->funcs->hdmi_audio_disable(
1004 pipe_ctx->stream_res.stream_enc);
1006 if (clk_mgr->funcs->enable_pme_wa)
1007 /*this is the first audio. apply the PME w/a in order to wake AZ from D3*/
1008 clk_mgr->funcs->enable_pme_wa(clk_mgr);
1010 /* TODO: notify audio driver for if audio modes list changed
1011 * add audio mode list change flag */
1012 /* dal_audio_disable_azalia_audio_jack_presence(stream->audio,
1013 * stream->stream_engine_id);
1018 void dce110_disable_stream(struct pipe_ctx *pipe_ctx)
1020 struct dc_stream_state *stream = pipe_ctx->stream;
1021 struct dc_link *link = stream->link;
1022 struct dc *dc = pipe_ctx->stream->ctx->dc;
1024 if (dc_is_hdmi_tmds_signal(pipe_ctx->stream->signal)) {
1025 pipe_ctx->stream_res.stream_enc->funcs->stop_hdmi_info_packets(
1026 pipe_ctx->stream_res.stream_enc);
1027 pipe_ctx->stream_res.stream_enc->funcs->hdmi_reset_stream_attribute(
1028 pipe_ctx->stream_res.stream_enc);
1031 if (dc_is_dp_signal(pipe_ctx->stream->signal))
1032 pipe_ctx->stream_res.stream_enc->funcs->stop_dp_info_packets(
1033 pipe_ctx->stream_res.stream_enc);
1035 dc->hwss.disable_audio_stream(pipe_ctx);
1037 link->link_enc->funcs->connect_dig_be_to_fe(
1039 pipe_ctx->stream_res.stream_enc->id,
1044 void dce110_unblank_stream(struct pipe_ctx *pipe_ctx,
1045 struct dc_link_settings *link_settings)
1047 struct encoder_unblank_param params = { { 0 } };
1048 struct dc_stream_state *stream = pipe_ctx->stream;
1049 struct dc_link *link = stream->link;
1051 /* only 3 items below are used by unblank */
1052 params.timing = pipe_ctx->stream->timing;
1053 params.link_settings.link_rate = link_settings->link_rate;
1055 if (dc_is_dp_signal(pipe_ctx->stream->signal))
1056 pipe_ctx->stream_res.stream_enc->funcs->dp_unblank(pipe_ctx->stream_res.stream_enc, ¶ms);
1058 if (link->local_sink && link->local_sink->sink_signal == SIGNAL_TYPE_EDP) {
1059 link->dc->hwss.edp_backlight_control(link, true);
1063 void dce110_blank_stream(struct pipe_ctx *pipe_ctx)
1065 struct dc_stream_state *stream = pipe_ctx->stream;
1066 struct dc_link *link = stream->link;
1068 if (link->local_sink && link->local_sink->sink_signal == SIGNAL_TYPE_EDP) {
1069 link->dc->hwss.edp_backlight_control(link, false);
1070 dc_link_set_abm_disable(link);
1073 if (dc_is_dp_signal(pipe_ctx->stream->signal))
1074 pipe_ctx->stream_res.stream_enc->funcs->dp_blank(pipe_ctx->stream_res.stream_enc);
1078 void dce110_set_avmute(struct pipe_ctx *pipe_ctx, bool enable)
1080 if (pipe_ctx != NULL && pipe_ctx->stream_res.stream_enc != NULL)
1081 pipe_ctx->stream_res.stream_enc->funcs->set_avmute(pipe_ctx->stream_res.stream_enc, enable);
1084 static enum audio_dto_source translate_to_dto_source(enum controller_id crtc_id)
1087 case CONTROLLER_ID_D0:
1088 return DTO_SOURCE_ID0;
1089 case CONTROLLER_ID_D1:
1090 return DTO_SOURCE_ID1;
1091 case CONTROLLER_ID_D2:
1092 return DTO_SOURCE_ID2;
1093 case CONTROLLER_ID_D3:
1094 return DTO_SOURCE_ID3;
1095 case CONTROLLER_ID_D4:
1096 return DTO_SOURCE_ID4;
1097 case CONTROLLER_ID_D5:
1098 return DTO_SOURCE_ID5;
1100 return DTO_SOURCE_UNKNOWN;
1104 static void build_audio_output(
1105 struct dc_state *state,
1106 const struct pipe_ctx *pipe_ctx,
1107 struct audio_output *audio_output)
1109 const struct dc_stream_state *stream = pipe_ctx->stream;
1110 audio_output->engine_id = pipe_ctx->stream_res.stream_enc->id;
1112 audio_output->signal = pipe_ctx->stream->signal;
1114 /* audio_crtc_info */
1116 audio_output->crtc_info.h_total =
1117 stream->timing.h_total;
1120 * Audio packets are sent during actual CRTC blank physical signal, we
1121 * need to specify actual active signal portion
1123 audio_output->crtc_info.h_active =
1124 stream->timing.h_addressable
1125 + stream->timing.h_border_left
1126 + stream->timing.h_border_right;
1128 audio_output->crtc_info.v_active =
1129 stream->timing.v_addressable
1130 + stream->timing.v_border_top
1131 + stream->timing.v_border_bottom;
1133 audio_output->crtc_info.pixel_repetition = 1;
1135 audio_output->crtc_info.interlaced =
1136 stream->timing.flags.INTERLACE;
1138 audio_output->crtc_info.refresh_rate =
1139 (stream->timing.pix_clk_100hz*100)/
1140 (stream->timing.h_total*stream->timing.v_total);
1142 audio_output->crtc_info.color_depth =
1143 stream->timing.display_color_depth;
1145 audio_output->crtc_info.requested_pixel_clock_100Hz =
1146 pipe_ctx->stream_res.pix_clk_params.requested_pix_clk_100hz;
1148 audio_output->crtc_info.calculated_pixel_clock_100Hz =
1149 pipe_ctx->stream_res.pix_clk_params.requested_pix_clk_100hz;
1151 /*for HDMI, audio ACR is with deep color ratio factor*/
1152 if (dc_is_hdmi_signal(pipe_ctx->stream->signal) &&
1153 audio_output->crtc_info.requested_pixel_clock_100Hz ==
1154 (stream->timing.pix_clk_100hz)) {
1155 if (pipe_ctx->stream_res.pix_clk_params.pixel_encoding == PIXEL_ENCODING_YCBCR420) {
1156 audio_output->crtc_info.requested_pixel_clock_100Hz =
1157 audio_output->crtc_info.requested_pixel_clock_100Hz/2;
1158 audio_output->crtc_info.calculated_pixel_clock_100Hz =
1159 pipe_ctx->stream_res.pix_clk_params.requested_pix_clk_100hz/2;
1164 if (state->clk_mgr &&
1165 (pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT ||
1166 pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST)) {
1167 audio_output->pll_info.dp_dto_source_clock_in_khz =
1168 state->clk_mgr->funcs->get_dp_ref_clk_frequency(
1172 audio_output->pll_info.feed_back_divider =
1173 pipe_ctx->pll_settings.feedback_divider;
1175 audio_output->pll_info.dto_source =
1176 translate_to_dto_source(
1177 pipe_ctx->stream_res.tg->inst + 1);
1179 /* TODO hard code to enable for now. Need get from stream */
1180 audio_output->pll_info.ss_enabled = true;
1182 audio_output->pll_info.ss_percentage =
1183 pipe_ctx->pll_settings.ss_percentage;
1186 static void get_surface_visual_confirm_color(const struct pipe_ctx *pipe_ctx,
1187 struct tg_color *color)
1189 uint32_t color_value = MAX_TG_COLOR_VALUE * (4 - pipe_ctx->stream_res.tg->inst) / 4;
1191 switch (pipe_ctx->plane_res.scl_data.format) {
1192 case PIXEL_FORMAT_ARGB8888:
1193 /* set boarder color to red */
1194 color->color_r_cr = color_value;
1197 case PIXEL_FORMAT_ARGB2101010:
1198 /* set boarder color to blue */
1199 color->color_b_cb = color_value;
1201 case PIXEL_FORMAT_420BPP8:
1202 /* set boarder color to green */
1203 color->color_g_y = color_value;
1205 case PIXEL_FORMAT_420BPP10:
1206 /* set boarder color to yellow */
1207 color->color_g_y = color_value;
1208 color->color_r_cr = color_value;
1210 case PIXEL_FORMAT_FP16:
1211 /* set boarder color to white */
1212 color->color_r_cr = color_value;
1213 color->color_b_cb = color_value;
1214 color->color_g_y = color_value;
1221 static void program_scaler(const struct dc *dc,
1222 const struct pipe_ctx *pipe_ctx)
1224 struct tg_color color = {0};
1226 #if defined(CONFIG_DRM_AMD_DC_DCN1_0)
1228 if (pipe_ctx->plane_res.xfm->funcs->transform_set_pixel_storage_depth == NULL)
1232 if (dc->debug.visual_confirm == VISUAL_CONFIRM_SURFACE)
1233 get_surface_visual_confirm_color(pipe_ctx, &color);
1235 color_space_to_black_color(dc,
1236 pipe_ctx->stream->output_color_space,
1239 pipe_ctx->plane_res.xfm->funcs->transform_set_pixel_storage_depth(
1240 pipe_ctx->plane_res.xfm,
1241 pipe_ctx->plane_res.scl_data.lb_params.depth,
1242 &pipe_ctx->stream->bit_depth_params);
1244 if (pipe_ctx->stream_res.tg->funcs->set_overscan_blank_color) {
1246 * The way 420 is packed, 2 channels carry Y component, 1 channel
1247 * alternate between Cb and Cr, so both channels need the pixel
1250 if (pipe_ctx->stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR420)
1251 color.color_r_cr = color.color_g_y;
1253 pipe_ctx->stream_res.tg->funcs->set_overscan_blank_color(
1254 pipe_ctx->stream_res.tg,
1258 pipe_ctx->plane_res.xfm->funcs->transform_set_scaler(pipe_ctx->plane_res.xfm,
1259 &pipe_ctx->plane_res.scl_data);
1262 static enum dc_status dce110_enable_stream_timing(
1263 struct pipe_ctx *pipe_ctx,
1264 struct dc_state *context,
1267 struct dc_stream_state *stream = pipe_ctx->stream;
1268 struct pipe_ctx *pipe_ctx_old = &dc->current_state->res_ctx.
1269 pipe_ctx[pipe_ctx->pipe_idx];
1270 struct tg_color black_color = {0};
1272 if (!pipe_ctx_old->stream) {
1274 /* program blank color */
1275 color_space_to_black_color(dc,
1276 stream->output_color_space, &black_color);
1277 pipe_ctx->stream_res.tg->funcs->set_blank_color(
1278 pipe_ctx->stream_res.tg,
1282 * Must blank CRTC after disabling power gating and before any
1283 * programming, otherwise CRTC will be hung in bad state
1285 pipe_ctx->stream_res.tg->funcs->set_blank(pipe_ctx->stream_res.tg, true);
1287 if (false == pipe_ctx->clock_source->funcs->program_pix_clk(
1288 pipe_ctx->clock_source,
1289 &pipe_ctx->stream_res.pix_clk_params,
1290 &pipe_ctx->pll_settings)) {
1291 BREAK_TO_DEBUGGER();
1292 return DC_ERROR_UNEXPECTED;
1295 pipe_ctx->stream_res.tg->funcs->program_timing(
1296 pipe_ctx->stream_res.tg,
1302 pipe_ctx->stream->signal,
1306 if (!pipe_ctx_old->stream) {
1307 if (false == pipe_ctx->stream_res.tg->funcs->enable_crtc(
1308 pipe_ctx->stream_res.tg)) {
1309 BREAK_TO_DEBUGGER();
1310 return DC_ERROR_UNEXPECTED;
1317 static enum dc_status apply_single_controller_ctx_to_hw(
1318 struct pipe_ctx *pipe_ctx,
1319 struct dc_state *context,
1322 struct dc_stream_state *stream = pipe_ctx->stream;
1323 struct drr_params params = {0};
1324 unsigned int event_triggers = 0;
1325 struct pipe_ctx *odm_pipe = pipe_ctx->next_odm_pipe;
1327 if (dc->hwss.disable_stream_gating) {
1328 dc->hwss.disable_stream_gating(dc, pipe_ctx);
1331 if (pipe_ctx->stream_res.audio != NULL) {
1332 struct audio_output audio_output;
1334 build_audio_output(context, pipe_ctx, &audio_output);
1336 if (dc_is_dp_signal(pipe_ctx->stream->signal))
1337 pipe_ctx->stream_res.stream_enc->funcs->dp_audio_setup(
1338 pipe_ctx->stream_res.stream_enc,
1339 pipe_ctx->stream_res.audio->inst,
1340 &pipe_ctx->stream->audio_info);
1342 pipe_ctx->stream_res.stream_enc->funcs->hdmi_audio_setup(
1343 pipe_ctx->stream_res.stream_enc,
1344 pipe_ctx->stream_res.audio->inst,
1345 &pipe_ctx->stream->audio_info,
1346 &audio_output.crtc_info);
1348 pipe_ctx->stream_res.audio->funcs->az_configure(
1349 pipe_ctx->stream_res.audio,
1350 pipe_ctx->stream->signal,
1351 &audio_output.crtc_info,
1352 &pipe_ctx->stream->audio_info);
1356 /* Do not touch stream timing on seamless boot optimization. */
1357 if (!pipe_ctx->stream->apply_seamless_boot_optimization)
1358 dc->hwss.enable_stream_timing(pipe_ctx, context, dc);
1360 if (dc->hwss.setup_vupdate_interrupt)
1361 dc->hwss.setup_vupdate_interrupt(pipe_ctx);
1363 params.vertical_total_min = stream->adjust.v_total_min;
1364 params.vertical_total_max = stream->adjust.v_total_max;
1365 if (pipe_ctx->stream_res.tg->funcs->set_drr)
1366 pipe_ctx->stream_res.tg->funcs->set_drr(
1367 pipe_ctx->stream_res.tg, ¶ms);
1369 // DRR should set trigger event to monitor surface update event
1370 if (stream->adjust.v_total_min != 0 && stream->adjust.v_total_max != 0)
1371 event_triggers = 0x80;
1372 if (pipe_ctx->stream_res.tg->funcs->set_static_screen_control)
1373 pipe_ctx->stream_res.tg->funcs->set_static_screen_control(
1374 pipe_ctx->stream_res.tg, event_triggers);
1376 if (!dc_is_virtual_signal(pipe_ctx->stream->signal))
1377 pipe_ctx->stream_res.stream_enc->funcs->dig_connect_to_otg(
1378 pipe_ctx->stream_res.stream_enc,
1379 pipe_ctx->stream_res.tg->inst);
1381 pipe_ctx->stream_res.opp->funcs->opp_set_dyn_expansion(
1382 pipe_ctx->stream_res.opp,
1383 COLOR_SPACE_YCBCR601,
1384 stream->timing.display_color_depth,
1387 pipe_ctx->stream_res.opp->funcs->opp_program_fmt(
1388 pipe_ctx->stream_res.opp,
1389 &stream->bit_depth_params,
1392 odm_pipe->stream_res.opp->funcs->opp_set_dyn_expansion(
1393 odm_pipe->stream_res.opp,
1394 COLOR_SPACE_YCBCR601,
1395 stream->timing.display_color_depth,
1398 odm_pipe->stream_res.opp->funcs->opp_program_fmt(
1399 odm_pipe->stream_res.opp,
1400 &stream->bit_depth_params,
1402 odm_pipe = odm_pipe->next_odm_pipe;
1405 if (!stream->dpms_off)
1406 core_link_enable_stream(context, pipe_ctx);
1408 pipe_ctx->plane_res.scl_data.lb_params.alpha_en = pipe_ctx->bottom_pipe != 0;
1410 pipe_ctx->stream->link->psr_feature_enabled = false;
1415 /******************************************************************************/
1417 static void power_down_encoders(struct dc *dc)
1421 /* do not know BIOS back-front mapping, simply blank all. It will not
1424 for (i = 0; i < dc->res_pool->stream_enc_count; i++) {
1425 dc->res_pool->stream_enc[i]->funcs->dp_blank(
1426 dc->res_pool->stream_enc[i]);
1429 for (i = 0; i < dc->link_count; i++) {
1430 enum signal_type signal = dc->links[i]->connector_signal;
1432 if ((signal == SIGNAL_TYPE_EDP) ||
1433 (signal == SIGNAL_TYPE_DISPLAY_PORT))
1434 if (!dc->links[i]->wa_flags.dp_keep_receiver_powered)
1435 dp_receiver_power_ctrl(dc->links[i], false);
1437 if (signal != SIGNAL_TYPE_EDP)
1438 signal = SIGNAL_TYPE_NONE;
1440 dc->links[i]->link_enc->funcs->disable_output(
1441 dc->links[i]->link_enc, signal);
1445 static void power_down_controllers(struct dc *dc)
1449 for (i = 0; i < dc->res_pool->timing_generator_count; i++) {
1450 dc->res_pool->timing_generators[i]->funcs->disable_crtc(
1451 dc->res_pool->timing_generators[i]);
1455 static void power_down_clock_sources(struct dc *dc)
1459 if (dc->res_pool->dp_clock_source->funcs->cs_power_down(
1460 dc->res_pool->dp_clock_source) == false)
1461 dm_error("Failed to power down pll! (dp clk src)\n");
1463 for (i = 0; i < dc->res_pool->clk_src_count; i++) {
1464 if (dc->res_pool->clock_sources[i]->funcs->cs_power_down(
1465 dc->res_pool->clock_sources[i]) == false)
1466 dm_error("Failed to power down pll! (clk src index=%d)\n", i);
1470 static void power_down_all_hw_blocks(struct dc *dc)
1472 power_down_encoders(dc);
1474 power_down_controllers(dc);
1476 power_down_clock_sources(dc);
1478 if (dc->fbc_compressor)
1479 dc->fbc_compressor->funcs->disable_fbc(dc->fbc_compressor);
1482 static void disable_vga_and_power_gate_all_controllers(
1486 struct timing_generator *tg;
1487 struct dc_context *ctx = dc->ctx;
1489 for (i = 0; i < dc->res_pool->timing_generator_count; i++) {
1490 tg = dc->res_pool->timing_generators[i];
1492 if (tg->funcs->disable_vga)
1493 tg->funcs->disable_vga(tg);
1495 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1496 /* Enable CLOCK gating for each pipe BEFORE controller
1498 enable_display_pipe_clock_gating(ctx,
1501 dc->current_state->res_ctx.pipe_ctx[i].pipe_idx = i;
1502 dc->hwss.disable_plane(dc,
1503 &dc->current_state->res_ctx.pipe_ctx[i]);
1508 static struct dc_stream_state *get_edp_stream(struct dc_state *context)
1512 for (i = 0; i < context->stream_count; i++) {
1513 if (context->streams[i]->signal == SIGNAL_TYPE_EDP)
1514 return context->streams[i];
1519 static struct dc_link *get_edp_link_with_sink(
1521 struct dc_state *context)
1524 struct dc_link *link = NULL;
1526 /* check if there is an eDP panel not in use */
1527 for (i = 0; i < dc->link_count; i++) {
1528 if (dc->links[i]->local_sink &&
1529 dc->links[i]->local_sink->sink_signal == SIGNAL_TYPE_EDP) {
1530 link = dc->links[i];
1539 * When ASIC goes from VBIOS/VGA mode to driver/accelerated mode we need:
1540 * 1. Power down all DC HW blocks
1541 * 2. Disable VGA engine on all controllers
1542 * 3. Enable power gating for controller
1543 * 4. Set acc_mode_change bit (VBIOS will clear this bit when going to FSDOS)
1545 void dce110_enable_accelerated_mode(struct dc *dc, struct dc_state *context)
1548 struct dc_link *edp_link_with_sink = get_edp_link_with_sink(dc, context);
1549 struct dc_link *edp_link = get_edp_link(dc);
1550 struct dc_stream_state *edp_stream = NULL;
1551 bool can_apply_edp_fast_boot = false;
1552 bool can_apply_seamless_boot = false;
1553 bool keep_edp_vdd_on = false;
1555 if (dc->hwss.init_pipes)
1556 dc->hwss.init_pipes(dc, context);
1558 edp_stream = get_edp_stream(context);
1560 // Check fastboot support, disable on DCE8 because of blank screens
1561 if (edp_link && dc->ctx->dce_version != DCE_VERSION_8_0 &&
1562 dc->ctx->dce_version != DCE_VERSION_8_1 &&
1563 dc->ctx->dce_version != DCE_VERSION_8_3) {
1565 // enable fastboot if backend is enabled on eDP
1566 if (edp_link->link_enc->funcs->is_dig_enabled(edp_link->link_enc)) {
1567 /* Set optimization flag on eDP stream*/
1569 edp_stream->apply_edp_fast_boot_optimization = true;
1570 can_apply_edp_fast_boot = true;
1574 // We are trying to enable eDP, don't power down VDD
1576 keep_edp_vdd_on = true;
1579 // Check seamless boot support
1580 for (i = 0; i < context->stream_count; i++) {
1581 if (context->streams[i]->apply_seamless_boot_optimization) {
1582 can_apply_seamless_boot = true;
1587 /* eDP should not have stream in resume from S4 and so even with VBios post
1588 * it should get turned off
1590 if (!can_apply_edp_fast_boot && !can_apply_seamless_boot) {
1591 if (edp_link_with_sink && !keep_edp_vdd_on) {
1592 /*turn off backlight before DP_blank and encoder powered down*/
1593 dc->hwss.edp_backlight_control(edp_link_with_sink, false);
1595 /*resume from S3, no vbios posting, no need to power down again*/
1596 power_down_all_hw_blocks(dc);
1597 disable_vga_and_power_gate_all_controllers(dc);
1598 if (edp_link_with_sink && !keep_edp_vdd_on)
1599 dc->hwss.edp_power_control(edp_link_with_sink, false);
1601 bios_set_scratch_acc_mode_change(dc->ctx->dc_bios);
1604 static uint32_t compute_pstate_blackout_duration(
1605 struct bw_fixed blackout_duration,
1606 const struct dc_stream_state *stream)
1608 uint32_t total_dest_line_time_ns;
1609 uint32_t pstate_blackout_duration_ns;
1611 pstate_blackout_duration_ns = 1000 * blackout_duration.value >> 24;
1613 total_dest_line_time_ns = 1000000UL *
1614 (stream->timing.h_total * 10) /
1615 stream->timing.pix_clk_100hz +
1616 pstate_blackout_duration_ns;
1618 return total_dest_line_time_ns;
1621 static void dce110_set_displaymarks(
1622 const struct dc *dc,
1623 struct dc_state *context)
1625 uint8_t i, num_pipes;
1626 unsigned int underlay_idx = dc->res_pool->underlay_pipe_index;
1628 for (i = 0, num_pipes = 0; i < MAX_PIPES; i++) {
1629 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
1630 uint32_t total_dest_line_time_ns;
1632 if (pipe_ctx->stream == NULL)
1635 total_dest_line_time_ns = compute_pstate_blackout_duration(
1636 dc->bw_vbios->blackout_duration, pipe_ctx->stream);
1637 pipe_ctx->plane_res.mi->funcs->mem_input_program_display_marks(
1638 pipe_ctx->plane_res.mi,
1639 context->bw_ctx.bw.dce.nbp_state_change_wm_ns[num_pipes],
1640 context->bw_ctx.bw.dce.stutter_exit_wm_ns[num_pipes],
1641 context->bw_ctx.bw.dce.stutter_entry_wm_ns[num_pipes],
1642 context->bw_ctx.bw.dce.urgent_wm_ns[num_pipes],
1643 total_dest_line_time_ns);
1644 if (i == underlay_idx) {
1646 pipe_ctx->plane_res.mi->funcs->mem_input_program_chroma_display_marks(
1647 pipe_ctx->plane_res.mi,
1648 context->bw_ctx.bw.dce.nbp_state_change_wm_ns[num_pipes],
1649 context->bw_ctx.bw.dce.stutter_exit_wm_ns[num_pipes],
1650 context->bw_ctx.bw.dce.urgent_wm_ns[num_pipes],
1651 total_dest_line_time_ns);
1657 void dce110_set_safe_displaymarks(
1658 struct resource_context *res_ctx,
1659 const struct resource_pool *pool)
1662 int underlay_idx = pool->underlay_pipe_index;
1663 struct dce_watermarks max_marks = {
1664 MAX_WATERMARK, MAX_WATERMARK, MAX_WATERMARK, MAX_WATERMARK };
1665 struct dce_watermarks nbp_marks = {
1666 SAFE_NBP_MARK, SAFE_NBP_MARK, SAFE_NBP_MARK, SAFE_NBP_MARK };
1667 struct dce_watermarks min_marks = { 0, 0, 0, 0};
1669 for (i = 0; i < MAX_PIPES; i++) {
1670 if (res_ctx->pipe_ctx[i].stream == NULL || res_ctx->pipe_ctx[i].plane_res.mi == NULL)
1673 res_ctx->pipe_ctx[i].plane_res.mi->funcs->mem_input_program_display_marks(
1674 res_ctx->pipe_ctx[i].plane_res.mi,
1681 if (i == underlay_idx)
1682 res_ctx->pipe_ctx[i].plane_res.mi->funcs->mem_input_program_chroma_display_marks(
1683 res_ctx->pipe_ctx[i].plane_res.mi,
1692 /*******************************************************************************
1694 ******************************************************************************/
1696 static void set_drr(struct pipe_ctx **pipe_ctx,
1697 int num_pipes, unsigned int vmin, unsigned int vmax,
1698 unsigned int vmid, unsigned int vmid_frame_number)
1701 struct drr_params params = {0};
1702 // DRR should set trigger event to monitor surface update event
1703 unsigned int event_triggers = 0x80;
1705 params.vertical_total_max = vmax;
1706 params.vertical_total_min = vmin;
1708 /* TODO: If multiple pipes are to be supported, you need
1709 * some GSL stuff. Static screen triggers may be programmed differently
1712 for (i = 0; i < num_pipes; i++) {
1713 pipe_ctx[i]->stream_res.tg->funcs->set_drr(
1714 pipe_ctx[i]->stream_res.tg, ¶ms);
1716 if (vmax != 0 && vmin != 0)
1717 pipe_ctx[i]->stream_res.tg->funcs->set_static_screen_control(
1718 pipe_ctx[i]->stream_res.tg,
1723 static void get_position(struct pipe_ctx **pipe_ctx,
1725 struct crtc_position *position)
1729 /* TODO: handle pipes > 1
1731 for (i = 0; i < num_pipes; i++)
1732 pipe_ctx[i]->stream_res.tg->funcs->get_position(pipe_ctx[i]->stream_res.tg, position);
1735 static void set_static_screen_control(struct pipe_ctx **pipe_ctx,
1736 int num_pipes, const struct dc_static_screen_events *events)
1739 unsigned int value = 0;
1741 if (events->overlay_update)
1743 if (events->surface_update)
1745 if (events->cursor_update)
1747 if (events->force_trigger)
1751 struct dc *dc = pipe_ctx[0]->stream->ctx->dc;
1753 if (dc->fbc_compressor)
1757 for (i = 0; i < num_pipes; i++)
1758 pipe_ctx[i]->stream_res.tg->funcs->
1759 set_static_screen_control(pipe_ctx[i]->stream_res.tg, value);
1763 * Check if FBC can be enabled
1765 static bool should_enable_fbc(struct dc *dc,
1766 struct dc_state *context,
1770 struct pipe_ctx *pipe_ctx = NULL;
1771 struct resource_context *res_ctx = &context->res_ctx;
1772 unsigned int underlay_idx = dc->res_pool->underlay_pipe_index;
1775 ASSERT(dc->fbc_compressor);
1777 /* FBC memory should be allocated */
1778 if (!dc->ctx->fbc_gpu_addr)
1781 /* Only supports single display */
1782 if (context->stream_count != 1)
1785 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1786 if (res_ctx->pipe_ctx[i].stream) {
1788 pipe_ctx = &res_ctx->pipe_ctx[i];
1793 /* fbc not applicable on underlay pipe */
1794 if (pipe_ctx->pipe_idx != underlay_idx) {
1801 if (i == dc->res_pool->pipe_count)
1804 if (!pipe_ctx->stream->link)
1807 /* Only supports eDP */
1808 if (pipe_ctx->stream->link->connector_signal != SIGNAL_TYPE_EDP)
1811 /* PSR should not be enabled */
1812 if (pipe_ctx->stream->link->psr_feature_enabled)
1815 /* Nothing to compress */
1816 if (!pipe_ctx->plane_state)
1819 /* Only for non-linear tiling */
1820 if (pipe_ctx->plane_state->tiling_info.gfx8.array_mode == DC_ARRAY_LINEAR_GENERAL)
1829 static void enable_fbc(
1831 struct dc_state *context)
1833 uint32_t pipe_idx = 0;
1835 if (should_enable_fbc(dc, context, &pipe_idx)) {
1836 /* Program GRPH COMPRESSED ADDRESS and PITCH */
1837 struct compr_addr_and_pitch_params params = {0, 0, 0};
1838 struct compressor *compr = dc->fbc_compressor;
1839 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[pipe_idx];
1841 params.source_view_width = pipe_ctx->stream->timing.h_addressable;
1842 params.source_view_height = pipe_ctx->stream->timing.v_addressable;
1843 params.inst = pipe_ctx->stream_res.tg->inst;
1844 compr->compr_surface_address.quad_part = dc->ctx->fbc_gpu_addr;
1846 compr->funcs->surface_address_and_pitch(compr, ¶ms);
1847 compr->funcs->set_fbc_invalidation_triggers(compr, 1);
1849 compr->funcs->enable_fbc(compr, ¶ms);
1853 static void dce110_reset_hw_ctx_wrap(
1855 struct dc_state *context)
1859 /* Reset old context */
1860 /* look up the targets that have been removed since last commit */
1861 for (i = 0; i < MAX_PIPES; i++) {
1862 struct pipe_ctx *pipe_ctx_old =
1863 &dc->current_state->res_ctx.pipe_ctx[i];
1864 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
1866 /* Note: We need to disable output if clock sources change,
1867 * since bios does optimization and doesn't apply if changing
1868 * PHY when not already disabled.
1871 /* Skip underlay pipe since it will be handled in commit surface*/
1872 if (!pipe_ctx_old->stream || pipe_ctx_old->top_pipe)
1875 if (!pipe_ctx->stream ||
1876 pipe_need_reprogram(pipe_ctx_old, pipe_ctx)) {
1877 struct clock_source *old_clk = pipe_ctx_old->clock_source;
1879 /* Disable if new stream is null. O/w, if stream is
1880 * disabled already, no need to disable again.
1882 if (!pipe_ctx->stream || !pipe_ctx->stream->dpms_off) {
1883 core_link_disable_stream(pipe_ctx_old);
1885 /* free acquired resources*/
1886 if (pipe_ctx_old->stream_res.audio) {
1887 /*disable az_endpoint*/
1888 pipe_ctx_old->stream_res.audio->funcs->
1889 az_disable(pipe_ctx_old->stream_res.audio);
1892 if (dc->caps.dynamic_audio == true) {
1893 /*we have to dynamic arbitrate the audio endpoints*/
1894 /*we free the resource, need reset is_audio_acquired*/
1895 update_audio_usage(&dc->current_state->res_ctx, dc->res_pool,
1896 pipe_ctx_old->stream_res.audio, false);
1897 pipe_ctx_old->stream_res.audio = NULL;
1902 pipe_ctx_old->stream_res.tg->funcs->set_blank(pipe_ctx_old->stream_res.tg, true);
1903 if (!hwss_wait_for_blank_complete(pipe_ctx_old->stream_res.tg)) {
1904 dm_error("DC: failed to blank crtc!\n");
1905 BREAK_TO_DEBUGGER();
1907 pipe_ctx_old->stream_res.tg->funcs->disable_crtc(pipe_ctx_old->stream_res.tg);
1908 pipe_ctx_old->plane_res.mi->funcs->free_mem_input(
1909 pipe_ctx_old->plane_res.mi, dc->current_state->stream_count);
1911 if (old_clk && 0 == resource_get_clock_source_reference(&context->res_ctx,
1914 old_clk->funcs->cs_power_down(old_clk);
1916 dc->hwss.disable_plane(dc, pipe_ctx_old);
1918 pipe_ctx_old->stream = NULL;
1923 static void dce110_setup_audio_dto(
1925 struct dc_state *context)
1929 /* program audio wall clock. use HDMI as clock source if HDMI
1930 * audio active. Otherwise, use DP as clock source
1931 * first, loop to find any HDMI audio, if not, loop find DP audio
1933 /* Setup audio rate clock source */
1935 * Audio lag happened on DP monitor when unplug a HDMI monitor
1938 * In case of DP and HDMI connected or HDMI only, DCCG_AUDIO_DTO_SEL
1939 * is set to either dto0 or dto1, audio should work fine.
1940 * In case of DP connected only, DCCG_AUDIO_DTO_SEL should be dto1,
1941 * set to dto0 will cause audio lag.
1944 * Not optimized audio wall dto setup. When mode set, iterate pipe_ctx,
1945 * find first available pipe with audio, setup audio wall DTO per topology
1946 * instead of per pipe.
1948 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1949 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
1951 if (pipe_ctx->stream == NULL)
1954 if (pipe_ctx->top_pipe)
1957 if (pipe_ctx->stream->signal != SIGNAL_TYPE_HDMI_TYPE_A)
1960 if (pipe_ctx->stream_res.audio != NULL) {
1961 struct audio_output audio_output;
1963 build_audio_output(context, pipe_ctx, &audio_output);
1965 pipe_ctx->stream_res.audio->funcs->wall_dto_setup(
1966 pipe_ctx->stream_res.audio,
1967 pipe_ctx->stream->signal,
1968 &audio_output.crtc_info,
1969 &audio_output.pll_info);
1974 /* no HDMI audio is found, try DP audio */
1975 if (i == dc->res_pool->pipe_count) {
1976 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1977 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
1979 if (pipe_ctx->stream == NULL)
1982 if (pipe_ctx->top_pipe)
1985 if (!dc_is_dp_signal(pipe_ctx->stream->signal))
1988 if (pipe_ctx->stream_res.audio != NULL) {
1989 struct audio_output audio_output;
1991 build_audio_output(context, pipe_ctx, &audio_output);
1993 pipe_ctx->stream_res.audio->funcs->wall_dto_setup(
1994 pipe_ctx->stream_res.audio,
1995 pipe_ctx->stream->signal,
1996 &audio_output.crtc_info,
1997 &audio_output.pll_info);
2004 enum dc_status dce110_apply_ctx_to_hw(
2006 struct dc_state *context)
2008 struct dc_bios *dcb = dc->ctx->dc_bios;
2009 enum dc_status status;
2012 /* Reset old context */
2013 /* look up the targets that have been removed since last commit */
2014 dc->hwss.reset_hw_ctx_wrap(dc, context);
2016 /* Skip applying if no targets */
2017 if (context->stream_count <= 0)
2020 /* Apply new context */
2021 dcb->funcs->set_scratch_critical_state(dcb, true);
2023 /* below is for real asic only */
2024 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2025 struct pipe_ctx *pipe_ctx_old =
2026 &dc->current_state->res_ctx.pipe_ctx[i];
2027 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2029 if (pipe_ctx->stream == NULL || pipe_ctx->top_pipe)
2032 if (pipe_ctx->stream == pipe_ctx_old->stream) {
2033 if (pipe_ctx_old->clock_source != pipe_ctx->clock_source)
2034 dce_crtc_switch_to_clk_src(dc->hwseq,
2035 pipe_ctx->clock_source, i);
2039 dc->hwss.enable_display_power_gating(
2040 dc, i, dc->ctx->dc_bios,
2041 PIPE_GATING_CONTROL_DISABLE);
2044 if (dc->fbc_compressor)
2045 dc->fbc_compressor->funcs->disable_fbc(dc->fbc_compressor);
2047 dce110_setup_audio_dto(dc, context);
2049 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2050 struct pipe_ctx *pipe_ctx_old =
2051 &dc->current_state->res_ctx.pipe_ctx[i];
2052 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2054 if (pipe_ctx->stream == NULL)
2057 if (pipe_ctx->stream == pipe_ctx_old->stream &&
2058 pipe_ctx->stream->link->link_state_valid) {
2062 if (pipe_ctx_old->stream && !pipe_need_reprogram(pipe_ctx_old, pipe_ctx))
2065 if (pipe_ctx->top_pipe || pipe_ctx->prev_odm_pipe)
2068 status = apply_single_controller_ctx_to_hw(
2073 if (DC_OK != status)
2077 if (dc->fbc_compressor)
2078 enable_fbc(dc, dc->current_state);
2080 dcb->funcs->set_scratch_critical_state(dcb, false);
2085 /*******************************************************************************
2086 * Front End programming
2087 ******************************************************************************/
2088 static void set_default_colors(struct pipe_ctx *pipe_ctx)
2090 struct default_adjustment default_adjust = { 0 };
2092 default_adjust.force_hw_default = false;
2093 default_adjust.in_color_space = pipe_ctx->plane_state->color_space;
2094 default_adjust.out_color_space = pipe_ctx->stream->output_color_space;
2095 default_adjust.csc_adjust_type = GRAPHICS_CSC_ADJUST_TYPE_SW;
2096 default_adjust.surface_pixel_format = pipe_ctx->plane_res.scl_data.format;
2098 /* display color depth */
2099 default_adjust.color_depth =
2100 pipe_ctx->stream->timing.display_color_depth;
2102 /* Lb color depth */
2103 default_adjust.lb_color_depth = pipe_ctx->plane_res.scl_data.lb_params.depth;
2105 pipe_ctx->plane_res.xfm->funcs->opp_set_csc_default(
2106 pipe_ctx->plane_res.xfm, &default_adjust);
2110 /*******************************************************************************
2111 * In order to turn on/off specific surface we will program
2114 * In case that we have two surfaces and they have a different visibility
2115 * we can't turn off the CRTC since it will turn off the entire display
2117 * |----------------------------------------------- |
2118 * |bottom pipe|curr pipe | | |
2119 * |Surface |Surface | Blender | CRCT |
2120 * |visibility |visibility | Configuration| |
2121 * |------------------------------------------------|
2122 * | off | off | CURRENT_PIPE | blank |
2123 * | off | on | CURRENT_PIPE | unblank |
2124 * | on | off | OTHER_PIPE | unblank |
2125 * | on | on | BLENDING | unblank |
2126 * -------------------------------------------------|
2128 ******************************************************************************/
2129 static void program_surface_visibility(const struct dc *dc,
2130 struct pipe_ctx *pipe_ctx)
2132 enum blnd_mode blender_mode = BLND_MODE_CURRENT_PIPE;
2133 bool blank_target = false;
2135 if (pipe_ctx->bottom_pipe) {
2137 /* For now we are supporting only two pipes */
2138 ASSERT(pipe_ctx->bottom_pipe->bottom_pipe == NULL);
2140 if (pipe_ctx->bottom_pipe->plane_state->visible) {
2141 if (pipe_ctx->plane_state->visible)
2142 blender_mode = BLND_MODE_BLENDING;
2144 blender_mode = BLND_MODE_OTHER_PIPE;
2146 } else if (!pipe_ctx->plane_state->visible)
2147 blank_target = true;
2149 } else if (!pipe_ctx->plane_state->visible)
2150 blank_target = true;
2152 dce_set_blender_mode(dc->hwseq, pipe_ctx->stream_res.tg->inst, blender_mode);
2153 pipe_ctx->stream_res.tg->funcs->set_blank(pipe_ctx->stream_res.tg, blank_target);
2157 static void program_gamut_remap(struct pipe_ctx *pipe_ctx)
2160 struct xfm_grph_csc_adjustment adjust;
2161 memset(&adjust, 0, sizeof(adjust));
2162 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS;
2165 if (pipe_ctx->stream->gamut_remap_matrix.enable_remap == true) {
2166 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_SW;
2168 for (i = 0; i < CSC_TEMPERATURE_MATRIX_SIZE; i++)
2169 adjust.temperature_matrix[i] =
2170 pipe_ctx->stream->gamut_remap_matrix.matrix[i];
2173 pipe_ctx->plane_res.xfm->funcs->transform_set_gamut_remap(pipe_ctx->plane_res.xfm, &adjust);
2175 static void update_plane_addr(const struct dc *dc,
2176 struct pipe_ctx *pipe_ctx)
2178 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
2180 if (plane_state == NULL)
2183 pipe_ctx->plane_res.mi->funcs->mem_input_program_surface_flip_and_addr(
2184 pipe_ctx->plane_res.mi,
2185 &plane_state->address,
2186 plane_state->flip_immediate);
2188 plane_state->status.requested_address = plane_state->address;
2191 static void dce110_update_pending_status(struct pipe_ctx *pipe_ctx)
2193 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
2195 if (plane_state == NULL)
2198 plane_state->status.is_flip_pending =
2199 pipe_ctx->plane_res.mi->funcs->mem_input_is_flip_pending(
2200 pipe_ctx->plane_res.mi);
2202 if (plane_state->status.is_flip_pending && !plane_state->visible)
2203 pipe_ctx->plane_res.mi->current_address = pipe_ctx->plane_res.mi->request_address;
2205 plane_state->status.current_address = pipe_ctx->plane_res.mi->current_address;
2206 if (pipe_ctx->plane_res.mi->current_address.type == PLN_ADDR_TYPE_GRPH_STEREO &&
2207 pipe_ctx->stream_res.tg->funcs->is_stereo_left_eye) {
2208 plane_state->status.is_right_eye =\
2209 !pipe_ctx->stream_res.tg->funcs->is_stereo_left_eye(pipe_ctx->stream_res.tg);
2213 void dce110_power_down(struct dc *dc)
2215 power_down_all_hw_blocks(dc);
2216 disable_vga_and_power_gate_all_controllers(dc);
2219 static bool wait_for_reset_trigger_to_occur(
2220 struct dc_context *dc_ctx,
2221 struct timing_generator *tg)
2225 /* To avoid endless loop we wait at most
2226 * frames_to_wait_on_triggered_reset frames for the reset to occur. */
2227 const uint32_t frames_to_wait_on_triggered_reset = 10;
2230 for (i = 0; i < frames_to_wait_on_triggered_reset; i++) {
2232 if (!tg->funcs->is_counter_moving(tg)) {
2233 DC_ERROR("TG counter is not moving!\n");
2237 if (tg->funcs->did_triggered_reset_occur(tg)) {
2239 /* usually occurs at i=1 */
2240 DC_SYNC_INFO("GSL: reset occurred at wait count: %d\n",
2245 /* Wait for one frame. */
2246 tg->funcs->wait_for_state(tg, CRTC_STATE_VACTIVE);
2247 tg->funcs->wait_for_state(tg, CRTC_STATE_VBLANK);
2251 DC_ERROR("GSL: Timeout on reset trigger!\n");
2256 /* Enable timing synchronization for a group of Timing Generators. */
2257 static void dce110_enable_timing_synchronization(
2261 struct pipe_ctx *grouped_pipes[])
2263 struct dc_context *dc_ctx = dc->ctx;
2264 struct dcp_gsl_params gsl_params = { 0 };
2267 DC_SYNC_INFO("GSL: Setting-up...\n");
2269 /* Designate a single TG in the group as a master.
2270 * Since HW doesn't care which one, we always assign
2271 * the 1st one in the group. */
2272 gsl_params.gsl_group = 0;
2273 gsl_params.gsl_master = grouped_pipes[0]->stream_res.tg->inst;
2275 for (i = 0; i < group_size; i++)
2276 grouped_pipes[i]->stream_res.tg->funcs->setup_global_swap_lock(
2277 grouped_pipes[i]->stream_res.tg, &gsl_params);
2279 /* Reset slave controllers on master VSync */
2280 DC_SYNC_INFO("GSL: enabling trigger-reset\n");
2282 for (i = 1 /* skip the master */; i < group_size; i++)
2283 grouped_pipes[i]->stream_res.tg->funcs->enable_reset_trigger(
2284 grouped_pipes[i]->stream_res.tg,
2285 gsl_params.gsl_group);
2287 for (i = 1 /* skip the master */; i < group_size; i++) {
2288 DC_SYNC_INFO("GSL: waiting for reset to occur.\n");
2289 wait_for_reset_trigger_to_occur(dc_ctx, grouped_pipes[i]->stream_res.tg);
2290 grouped_pipes[i]->stream_res.tg->funcs->disable_reset_trigger(
2291 grouped_pipes[i]->stream_res.tg);
2294 /* GSL Vblank synchronization is a one time sync mechanism, assumption
2295 * is that the sync'ed displays will not drift out of sync over time*/
2296 DC_SYNC_INFO("GSL: Restoring register states.\n");
2297 for (i = 0; i < group_size; i++)
2298 grouped_pipes[i]->stream_res.tg->funcs->tear_down_global_swap_lock(grouped_pipes[i]->stream_res.tg);
2300 DC_SYNC_INFO("GSL: Set-up complete.\n");
2303 static void dce110_enable_per_frame_crtc_position_reset(
2306 struct pipe_ctx *grouped_pipes[])
2308 struct dc_context *dc_ctx = dc->ctx;
2309 struct dcp_gsl_params gsl_params = { 0 };
2312 gsl_params.gsl_group = 0;
2313 gsl_params.gsl_master = 0;
2315 for (i = 0; i < group_size; i++)
2316 grouped_pipes[i]->stream_res.tg->funcs->setup_global_swap_lock(
2317 grouped_pipes[i]->stream_res.tg, &gsl_params);
2319 DC_SYNC_INFO("GSL: enabling trigger-reset\n");
2321 for (i = 1; i < group_size; i++)
2322 grouped_pipes[i]->stream_res.tg->funcs->enable_crtc_reset(
2323 grouped_pipes[i]->stream_res.tg,
2324 gsl_params.gsl_master,
2325 &grouped_pipes[i]->stream->triggered_crtc_reset);
2327 DC_SYNC_INFO("GSL: waiting for reset to occur.\n");
2328 for (i = 1; i < group_size; i++)
2329 wait_for_reset_trigger_to_occur(dc_ctx, grouped_pipes[i]->stream_res.tg);
2331 for (i = 0; i < group_size; i++)
2332 grouped_pipes[i]->stream_res.tg->funcs->tear_down_global_swap_lock(grouped_pipes[i]->stream_res.tg);
2336 static void init_pipes(struct dc *dc, struct dc_state *context)
2341 static void init_hw(struct dc *dc)
2345 struct transform *xfm;
2349 bp = dc->ctx->dc_bios;
2350 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2351 xfm = dc->res_pool->transforms[i];
2352 xfm->funcs->transform_reset(xfm);
2354 dc->hwss.enable_display_power_gating(
2356 PIPE_GATING_CONTROL_INIT);
2357 dc->hwss.enable_display_power_gating(
2359 PIPE_GATING_CONTROL_DISABLE);
2360 dc->hwss.enable_display_pipe_clock_gating(
2365 dce_clock_gating_power_up(dc->hwseq, false);
2366 /***************************************/
2368 for (i = 0; i < dc->link_count; i++) {
2369 /****************************************/
2370 /* Power up AND update implementation according to the
2371 * required signal (which may be different from the
2372 * default signal on connector). */
2373 struct dc_link *link = dc->links[i];
2375 link->link_enc->funcs->hw_init(link->link_enc);
2378 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2379 struct timing_generator *tg = dc->res_pool->timing_generators[i];
2381 tg->funcs->disable_vga(tg);
2383 /* Blank controller using driver code instead of
2385 tg->funcs->set_blank(tg, true);
2386 hwss_wait_for_blank_complete(tg);
2389 for (i = 0; i < dc->res_pool->audio_count; i++) {
2390 struct audio *audio = dc->res_pool->audios[i];
2391 audio->funcs->hw_init(audio);
2394 abm = dc->res_pool->abm;
2396 abm->funcs->init_backlight(abm);
2397 abm->funcs->abm_init(abm);
2400 dmcu = dc->res_pool->dmcu;
2401 if (dmcu != NULL && abm != NULL)
2402 abm->dmcu_is_running = dmcu->funcs->is_dmcu_initialized(dmcu);
2404 if (dc->fbc_compressor)
2405 dc->fbc_compressor->funcs->power_up_fbc(dc->fbc_compressor);
2410 void dce110_prepare_bandwidth(
2412 struct dc_state *context)
2414 struct clk_mgr *dccg = dc->clk_mgr;
2416 dce110_set_safe_displaymarks(&context->res_ctx, dc->res_pool);
2418 dccg->funcs->update_clocks(
2424 void dce110_optimize_bandwidth(
2426 struct dc_state *context)
2428 struct clk_mgr *dccg = dc->clk_mgr;
2430 dce110_set_displaymarks(dc, context);
2432 dccg->funcs->update_clocks(
2438 static void dce110_program_front_end_for_pipe(
2439 struct dc *dc, struct pipe_ctx *pipe_ctx)
2441 struct mem_input *mi = pipe_ctx->plane_res.mi;
2442 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
2443 struct xfm_grph_csc_adjustment adjust;
2444 struct out_csc_color_matrix tbl_entry;
2447 memset(&tbl_entry, 0, sizeof(tbl_entry));
2449 memset(&adjust, 0, sizeof(adjust));
2450 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS;
2452 dce_enable_fe_clock(dc->hwseq, mi->inst, true);
2454 set_default_colors(pipe_ctx);
2455 if (pipe_ctx->stream->csc_color_matrix.enable_adjustment
2457 tbl_entry.color_space =
2458 pipe_ctx->stream->output_color_space;
2460 for (i = 0; i < 12; i++)
2461 tbl_entry.regval[i] =
2462 pipe_ctx->stream->csc_color_matrix.matrix[i];
2464 pipe_ctx->plane_res.xfm->funcs->opp_set_csc_adjustment
2465 (pipe_ctx->plane_res.xfm, &tbl_entry);
2468 if (pipe_ctx->stream->gamut_remap_matrix.enable_remap == true) {
2469 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_SW;
2471 for (i = 0; i < CSC_TEMPERATURE_MATRIX_SIZE; i++)
2472 adjust.temperature_matrix[i] =
2473 pipe_ctx->stream->gamut_remap_matrix.matrix[i];
2476 pipe_ctx->plane_res.xfm->funcs->transform_set_gamut_remap(pipe_ctx->plane_res.xfm, &adjust);
2478 pipe_ctx->plane_res.scl_data.lb_params.alpha_en = pipe_ctx->bottom_pipe != 0;
2480 program_scaler(dc, pipe_ctx);
2482 mi->funcs->mem_input_program_surface_config(
2484 plane_state->format,
2485 &plane_state->tiling_info,
2486 &plane_state->plane_size,
2487 plane_state->rotation,
2490 if (mi->funcs->set_blank)
2491 mi->funcs->set_blank(mi, pipe_ctx->plane_state->visible);
2493 if (dc->config.gpu_vm_support)
2494 mi->funcs->mem_input_program_pte_vm(
2495 pipe_ctx->plane_res.mi,
2496 plane_state->format,
2497 &plane_state->tiling_info,
2498 plane_state->rotation);
2500 /* Moved programming gamma from dc to hwss */
2501 if (pipe_ctx->plane_state->update_flags.bits.full_update ||
2502 pipe_ctx->plane_state->update_flags.bits.in_transfer_func_change ||
2503 pipe_ctx->plane_state->update_flags.bits.gamma_change)
2504 dc->hwss.set_input_transfer_func(pipe_ctx, pipe_ctx->plane_state);
2506 if (pipe_ctx->plane_state->update_flags.bits.full_update)
2507 dc->hwss.set_output_transfer_func(pipe_ctx, pipe_ctx->stream);
2510 "Pipe:%d %p: addr hi:0x%x, "
2513 " %d; dst: %d, %d, %d, %d;"
2514 "clip: %d, %d, %d, %d\n",
2516 (void *) pipe_ctx->plane_state,
2517 pipe_ctx->plane_state->address.grph.addr.high_part,
2518 pipe_ctx->plane_state->address.grph.addr.low_part,
2519 pipe_ctx->plane_state->src_rect.x,
2520 pipe_ctx->plane_state->src_rect.y,
2521 pipe_ctx->plane_state->src_rect.width,
2522 pipe_ctx->plane_state->src_rect.height,
2523 pipe_ctx->plane_state->dst_rect.x,
2524 pipe_ctx->plane_state->dst_rect.y,
2525 pipe_ctx->plane_state->dst_rect.width,
2526 pipe_ctx->plane_state->dst_rect.height,
2527 pipe_ctx->plane_state->clip_rect.x,
2528 pipe_ctx->plane_state->clip_rect.y,
2529 pipe_ctx->plane_state->clip_rect.width,
2530 pipe_ctx->plane_state->clip_rect.height);
2533 "Pipe %d: width, height, x, y\n"
2534 "viewport:%d, %d, %d, %d\n"
2535 "recout: %d, %d, %d, %d\n",
2537 pipe_ctx->plane_res.scl_data.viewport.width,
2538 pipe_ctx->plane_res.scl_data.viewport.height,
2539 pipe_ctx->plane_res.scl_data.viewport.x,
2540 pipe_ctx->plane_res.scl_data.viewport.y,
2541 pipe_ctx->plane_res.scl_data.recout.width,
2542 pipe_ctx->plane_res.scl_data.recout.height,
2543 pipe_ctx->plane_res.scl_data.recout.x,
2544 pipe_ctx->plane_res.scl_data.recout.y);
2547 static void dce110_apply_ctx_for_surface(
2549 const struct dc_stream_state *stream,
2551 struct dc_state *context)
2555 if (num_planes == 0)
2558 if (dc->fbc_compressor)
2559 dc->fbc_compressor->funcs->disable_fbc(dc->fbc_compressor);
2561 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2562 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2563 struct pipe_ctx *old_pipe_ctx = &dc->current_state->res_ctx.pipe_ctx[i];
2565 if (stream == pipe_ctx->stream) {
2566 if (!pipe_ctx->top_pipe &&
2567 (pipe_ctx->plane_state || old_pipe_ctx->plane_state))
2568 dc->hwss.pipe_control_lock(dc, pipe_ctx, true);
2572 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2573 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2575 if (pipe_ctx->stream != stream)
2578 /* Need to allocate mem before program front end for Fiji */
2579 pipe_ctx->plane_res.mi->funcs->allocate_mem_input(
2580 pipe_ctx->plane_res.mi,
2581 pipe_ctx->stream->timing.h_total,
2582 pipe_ctx->stream->timing.v_total,
2583 pipe_ctx->stream->timing.pix_clk_100hz / 10,
2584 context->stream_count);
2586 dce110_program_front_end_for_pipe(dc, pipe_ctx);
2588 dc->hwss.update_plane_addr(dc, pipe_ctx);
2590 program_surface_visibility(dc, pipe_ctx);
2594 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2595 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2596 struct pipe_ctx *old_pipe_ctx = &dc->current_state->res_ctx.pipe_ctx[i];
2598 if ((stream == pipe_ctx->stream) &&
2599 (!pipe_ctx->top_pipe) &&
2600 (pipe_ctx->plane_state || old_pipe_ctx->plane_state))
2601 dc->hwss.pipe_control_lock(dc, pipe_ctx, false);
2604 if (dc->fbc_compressor)
2605 enable_fbc(dc, context);
2608 static void dce110_power_down_fe(struct dc *dc, struct pipe_ctx *pipe_ctx)
2610 int fe_idx = pipe_ctx->plane_res.mi ?
2611 pipe_ctx->plane_res.mi->inst : pipe_ctx->pipe_idx;
2613 /* Do not power down fe when stream is active on dce*/
2614 if (dc->current_state->res_ctx.pipe_ctx[fe_idx].stream)
2617 dc->hwss.enable_display_power_gating(
2618 dc, fe_idx, dc->ctx->dc_bios, PIPE_GATING_CONTROL_ENABLE);
2620 dc->res_pool->transforms[fe_idx]->funcs->transform_reset(
2621 dc->res_pool->transforms[fe_idx]);
2624 static void dce110_wait_for_mpcc_disconnect(
2626 struct resource_pool *res_pool,
2627 struct pipe_ctx *pipe_ctx)
2632 static void program_output_csc(struct dc *dc,
2633 struct pipe_ctx *pipe_ctx,
2634 enum dc_color_space colorspace,
2639 struct out_csc_color_matrix tbl_entry;
2641 if (pipe_ctx->stream->csc_color_matrix.enable_adjustment == true) {
2642 enum dc_color_space color_space = pipe_ctx->stream->output_color_space;
2644 for (i = 0; i < 12; i++)
2645 tbl_entry.regval[i] = pipe_ctx->stream->csc_color_matrix.matrix[i];
2647 tbl_entry.color_space = color_space;
2649 pipe_ctx->plane_res.xfm->funcs->opp_set_csc_adjustment(
2650 pipe_ctx->plane_res.xfm, &tbl_entry);
2654 void dce110_set_cursor_position(struct pipe_ctx *pipe_ctx)
2656 struct dc_cursor_position pos_cpy = pipe_ctx->stream->cursor_position;
2657 struct input_pixel_processor *ipp = pipe_ctx->plane_res.ipp;
2658 struct mem_input *mi = pipe_ctx->plane_res.mi;
2659 struct dc_cursor_mi_param param = {
2660 .pixel_clk_khz = pipe_ctx->stream->timing.pix_clk_100hz / 10,
2661 .ref_clk_khz = pipe_ctx->stream->ctx->dc->res_pool->ref_clocks.xtalin_clock_inKhz,
2662 .viewport = pipe_ctx->plane_res.scl_data.viewport,
2663 .h_scale_ratio = pipe_ctx->plane_res.scl_data.ratios.horz,
2664 .v_scale_ratio = pipe_ctx->plane_res.scl_data.ratios.vert,
2665 .rotation = pipe_ctx->plane_state->rotation,
2666 .mirror = pipe_ctx->plane_state->horizontal_mirror
2669 if (pipe_ctx->plane_state->address.type
2670 == PLN_ADDR_TYPE_VIDEO_PROGRESSIVE)
2671 pos_cpy.enable = false;
2673 if (pipe_ctx->top_pipe && pipe_ctx->plane_state != pipe_ctx->top_pipe->plane_state)
2674 pos_cpy.enable = false;
2676 if (ipp->funcs->ipp_cursor_set_position)
2677 ipp->funcs->ipp_cursor_set_position(ipp, &pos_cpy, ¶m);
2678 if (mi->funcs->set_cursor_position)
2679 mi->funcs->set_cursor_position(mi, &pos_cpy, ¶m);
2682 void dce110_set_cursor_attribute(struct pipe_ctx *pipe_ctx)
2684 struct dc_cursor_attributes *attributes = &pipe_ctx->stream->cursor_attributes;
2686 if (pipe_ctx->plane_res.ipp &&
2687 pipe_ctx->plane_res.ipp->funcs->ipp_cursor_set_attributes)
2688 pipe_ctx->plane_res.ipp->funcs->ipp_cursor_set_attributes(
2689 pipe_ctx->plane_res.ipp, attributes);
2691 if (pipe_ctx->plane_res.mi &&
2692 pipe_ctx->plane_res.mi->funcs->set_cursor_attributes)
2693 pipe_ctx->plane_res.mi->funcs->set_cursor_attributes(
2694 pipe_ctx->plane_res.mi, attributes);
2696 if (pipe_ctx->plane_res.xfm &&
2697 pipe_ctx->plane_res.xfm->funcs->set_cursor_attributes)
2698 pipe_ctx->plane_res.xfm->funcs->set_cursor_attributes(
2699 pipe_ctx->plane_res.xfm, attributes);
2702 static const struct hw_sequencer_funcs dce110_funcs = {
2703 .program_gamut_remap = program_gamut_remap,
2704 .program_output_csc = program_output_csc,
2706 .init_pipes = init_pipes,
2707 .apply_ctx_to_hw = dce110_apply_ctx_to_hw,
2708 .apply_ctx_for_surface = dce110_apply_ctx_for_surface,
2709 .update_plane_addr = update_plane_addr,
2710 .update_pending_status = dce110_update_pending_status,
2711 .set_input_transfer_func = dce110_set_input_transfer_func,
2712 .set_output_transfer_func = dce110_set_output_transfer_func,
2713 .power_down = dce110_power_down,
2714 .enable_accelerated_mode = dce110_enable_accelerated_mode,
2715 .enable_timing_synchronization = dce110_enable_timing_synchronization,
2716 .enable_per_frame_crtc_position_reset = dce110_enable_per_frame_crtc_position_reset,
2717 .update_info_frame = dce110_update_info_frame,
2718 .enable_stream = dce110_enable_stream,
2719 .disable_stream = dce110_disable_stream,
2720 .unblank_stream = dce110_unblank_stream,
2721 .blank_stream = dce110_blank_stream,
2722 .enable_audio_stream = dce110_enable_audio_stream,
2723 .disable_audio_stream = dce110_disable_audio_stream,
2724 .enable_display_pipe_clock_gating = enable_display_pipe_clock_gating,
2725 .enable_display_power_gating = dce110_enable_display_power_gating,
2726 .disable_plane = dce110_power_down_fe,
2727 .pipe_control_lock = dce_pipe_control_lock,
2728 .prepare_bandwidth = dce110_prepare_bandwidth,
2729 .optimize_bandwidth = dce110_optimize_bandwidth,
2731 .get_position = get_position,
2732 .set_static_screen_control = set_static_screen_control,
2733 .reset_hw_ctx_wrap = dce110_reset_hw_ctx_wrap,
2734 .enable_stream_timing = dce110_enable_stream_timing,
2735 .disable_stream_gating = NULL,
2736 .enable_stream_gating = NULL,
2737 .setup_stereo = NULL,
2738 .set_avmute = dce110_set_avmute,
2739 .wait_for_mpcc_disconnect = dce110_wait_for_mpcc_disconnect,
2740 .edp_backlight_control = dce110_edp_backlight_control,
2741 .edp_power_control = dce110_edp_power_control,
2742 .edp_wait_for_hpd_ready = dce110_edp_wait_for_hpd_ready,
2743 .set_cursor_position = dce110_set_cursor_position,
2744 .set_cursor_attribute = dce110_set_cursor_attribute
2747 void dce110_hw_sequencer_construct(struct dc *dc)
2749 dc->hwss = dce110_funcs;