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 #if defined(CONFIG_DRM_AMD_DC_FBC)
38 #include "dce110_compressor.h"
41 #include "bios/bios_parser_helper.h"
42 #include "timing_generator.h"
43 #include "mem_input.h"
46 #include "transform.h"
47 #include "stream_encoder.h"
48 #include "link_encoder.h"
49 #include "link_hwss.h"
50 #include "clock_source.h"
53 #include "reg_helper.h"
55 /* include DCE11 register header files */
56 #include "dce/dce_11_0_d.h"
57 #include "dce/dce_11_0_sh_mask.h"
58 #include "custom_float.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
75 #define FN(reg_name, field_name) \
76 hws->shifts->field_name, hws->masks->field_name
78 struct dce110_hw_seq_reg_offsets
{
82 static const struct dce110_hw_seq_reg_offsets reg_offsets
[] = {
84 .crtc
= (mmCRTC0_CRTC_GSL_CONTROL
- mmCRTC_GSL_CONTROL
),
87 .crtc
= (mmCRTC1_CRTC_GSL_CONTROL
- mmCRTC_GSL_CONTROL
),
90 .crtc
= (mmCRTC2_CRTC_GSL_CONTROL
- mmCRTC_GSL_CONTROL
),
93 .crtc
= (mmCRTCV_GSL_CONTROL
- mmCRTC_GSL_CONTROL
),
97 #define HW_REG_BLND(reg, id)\
98 (reg + reg_offsets[id].blnd)
100 #define HW_REG_CRTC(reg, id)\
101 (reg + reg_offsets[id].crtc)
103 #define MAX_WATERMARK 0xFFFF
104 #define SAFE_NBP_MARK 0x7FFF
106 /*******************************************************************************
107 * Private definitions
108 ******************************************************************************/
109 /***************************PIPE_CONTROL***********************************/
110 static void dce110_init_pte(struct dc_context
*ctx
)
114 uint32_t chunk_int
= 0;
115 uint32_t chunk_mul
= 0;
117 addr
= mmUNP_DVMM_PTE_CONTROL
;
118 value
= dm_read_reg(ctx
, addr
);
124 DVMM_USE_SINGLE_PTE
);
130 DVMM_PTE_BUFFER_MODE0
);
136 DVMM_PTE_BUFFER_MODE1
);
138 dm_write_reg(ctx
, addr
, value
);
140 addr
= mmDVMM_PTE_REQ
;
141 value
= dm_read_reg(ctx
, addr
);
143 chunk_int
= get_reg_field_value(
146 HFLIP_PTEREQ_PER_CHUNK_INT
);
148 chunk_mul
= get_reg_field_value(
151 HFLIP_PTEREQ_PER_CHUNK_MULTIPLIER
);
153 if (chunk_int
!= 0x4 || chunk_mul
!= 0x4) {
159 MAX_PTEREQ_TO_ISSUE
);
165 HFLIP_PTEREQ_PER_CHUNK_INT
);
171 HFLIP_PTEREQ_PER_CHUNK_MULTIPLIER
);
173 dm_write_reg(ctx
, addr
, value
);
176 /**************************************************************************/
178 static void enable_display_pipe_clock_gating(
179 struct dc_context
*ctx
,
185 static bool dce110_enable_display_power_gating(
187 uint8_t controller_id
,
189 enum pipe_gating_control power_gating
)
191 enum bp_result bp_result
= BP_RESULT_OK
;
192 enum bp_pipe_control_action cntl
;
193 struct dc_context
*ctx
= dc
->ctx
;
194 unsigned int underlay_idx
= dc
->res_pool
->underlay_pipe_index
;
196 if (IS_FPGA_MAXIMUS_DC(ctx
->dce_environment
))
199 if (power_gating
== PIPE_GATING_CONTROL_INIT
)
200 cntl
= ASIC_PIPE_INIT
;
201 else if (power_gating
== PIPE_GATING_CONTROL_ENABLE
)
202 cntl
= ASIC_PIPE_ENABLE
;
204 cntl
= ASIC_PIPE_DISABLE
;
206 if (controller_id
== underlay_idx
)
207 controller_id
= CONTROLLER_ID_UNDERLAY0
- 1;
209 if (power_gating
!= PIPE_GATING_CONTROL_INIT
|| controller_id
== 0){
211 bp_result
= dcb
->funcs
->enable_disp_power_gating(
212 dcb
, controller_id
+ 1, cntl
);
214 /* Revert MASTER_UPDATE_MODE to 0 because bios sets it 2
215 * by default when command table is called
217 * Bios parser accepts controller_id = 6 as indicative of
218 * underlay pipe in dce110. But we do not support more
221 if (controller_id
< CONTROLLER_ID_MAX
- 1)
223 HW_REG_CRTC(mmCRTC_MASTER_UPDATE_MODE
, controller_id
),
227 if (power_gating
!= PIPE_GATING_CONTROL_ENABLE
)
228 dce110_init_pte(ctx
);
230 if (bp_result
== BP_RESULT_OK
)
236 static void build_prescale_params(struct ipp_prescale_params
*prescale_params
,
237 const struct dc_plane_state
*plane_state
)
239 prescale_params
->mode
= IPP_PRESCALE_MODE_FIXED_UNSIGNED
;
241 switch (plane_state
->format
) {
242 case SURFACE_PIXEL_FORMAT_GRPH_RGB565
:
243 prescale_params
->scale
= 0x2082;
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;
263 static bool dce110_set_input_transfer_func(
264 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
&& dce_use_lut(plane_state
))
282 ipp
->funcs
->ipp_program_input_lut(ipp
, plane_state
->gamma_correction
);
285 /* Default case if no input transfer function specified */
286 ipp
->funcs
->ipp_set_degamma(ipp
,
287 IPP_DEGAMMA_MODE_HW_sRGB
);
288 } else if (tf
->type
== TF_TYPE_PREDEFINED
) {
290 case TRANSFER_FUNCTION_SRGB
:
291 ipp
->funcs
->ipp_set_degamma(ipp
,
292 IPP_DEGAMMA_MODE_HW_sRGB
);
294 case TRANSFER_FUNCTION_BT709
:
295 ipp
->funcs
->ipp_set_degamma(ipp
,
296 IPP_DEGAMMA_MODE_HW_xvYCC
);
298 case TRANSFER_FUNCTION_LINEAR
:
299 ipp
->funcs
->ipp_set_degamma(ipp
,
300 IPP_DEGAMMA_MODE_BYPASS
);
302 case TRANSFER_FUNCTION_PQ
:
309 } else if (tf
->type
== TF_TYPE_BYPASS
) {
310 ipp
->funcs
->ipp_set_degamma(ipp
, IPP_DEGAMMA_MODE_BYPASS
);
312 /*TF_TYPE_DISTRIBUTED_POINTS - Not supported in DCE 11*/
319 static bool convert_to_custom_float(
320 struct pwl_result_data
*rgb_resulted
,
321 struct curve_points
*arr_points
,
322 uint32_t hw_points_num
)
324 struct custom_float_format fmt
;
326 struct pwl_result_data
*rgb
= rgb_resulted
;
330 fmt
.exponenta_bits
= 6;
331 fmt
.mantissa_bits
= 12;
334 if (!convert_to_custom_float_format(
337 &arr_points
[0].custom_float_x
)) {
342 if (!convert_to_custom_float_format(
343 arr_points
[0].offset
,
345 &arr_points
[0].custom_float_offset
)) {
350 if (!convert_to_custom_float_format(
353 &arr_points
[0].custom_float_slope
)) {
358 fmt
.mantissa_bits
= 10;
361 if (!convert_to_custom_float_format(
364 &arr_points
[1].custom_float_x
)) {
369 if (!convert_to_custom_float_format(
372 &arr_points
[1].custom_float_y
)) {
377 if (!convert_to_custom_float_format(
380 &arr_points
[2].custom_float_slope
)) {
385 fmt
.mantissa_bits
= 12;
388 while (i
!= hw_points_num
) {
389 if (!convert_to_custom_float_format(
397 if (!convert_to_custom_float_format(
405 if (!convert_to_custom_float_format(
413 if (!convert_to_custom_float_format(
416 &rgb
->delta_red_reg
)) {
421 if (!convert_to_custom_float_format(
424 &rgb
->delta_green_reg
)) {
429 if (!convert_to_custom_float_format(
432 &rgb
->delta_blue_reg
)) {
444 static bool dce110_translate_regamma_to_hw_format(const struct dc_transfer_func
445 *output_tf
, struct pwl_params
*regamma_params
)
447 struct curve_points
*arr_points
;
448 struct pwl_result_data
*rgb_resulted
;
449 struct pwl_result_data
*rgb
;
450 struct pwl_result_data
*rgb_plus_1
;
451 struct fixed31_32 y_r
;
452 struct fixed31_32 y_g
;
453 struct fixed31_32 y_b
;
454 struct fixed31_32 y1_min
;
455 struct fixed31_32 y3_max
;
457 int32_t segment_start
, segment_end
;
458 uint32_t i
, j
, k
, seg_distr
[16], increment
, start_index
, hw_points
;
460 if (output_tf
== NULL
|| regamma_params
== NULL
||
461 output_tf
->type
== TF_TYPE_BYPASS
)
464 arr_points
= regamma_params
->arr_points
;
465 rgb_resulted
= regamma_params
->rgb_resulted
;
468 memset(regamma_params
, 0, sizeof(struct pwl_params
));
470 if (output_tf
->tf
== TRANSFER_FUNCTION_PQ
) {
472 * segments are from 2^-11 to 2^5
496 * segment is from 2^-10 to 2^0
519 for (k
= 0; k
< 16; k
++) {
520 if (seg_distr
[k
] != -1)
521 hw_points
+= (1 << seg_distr
[k
]);
525 for (k
= 0; k
< (segment_end
- segment_start
); k
++) {
526 increment
= 32 / (1 << seg_distr
[k
]);
527 start_index
= (segment_start
+ k
+ 25) * 32;
528 for (i
= start_index
; i
< start_index
+ 32; i
+= increment
) {
529 if (j
== hw_points
- 1)
531 rgb_resulted
[j
].red
= output_tf
->tf_pts
.red
[i
];
532 rgb_resulted
[j
].green
= output_tf
->tf_pts
.green
[i
];
533 rgb_resulted
[j
].blue
= output_tf
->tf_pts
.blue
[i
];
539 start_index
= (segment_end
+ 25) * 32;
540 rgb_resulted
[hw_points
- 1].red
=
541 output_tf
->tf_pts
.red
[start_index
];
542 rgb_resulted
[hw_points
- 1].green
=
543 output_tf
->tf_pts
.green
[start_index
];
544 rgb_resulted
[hw_points
- 1].blue
=
545 output_tf
->tf_pts
.blue
[start_index
];
547 arr_points
[0].x
= dal_fixed31_32_pow(dal_fixed31_32_from_int(2),
548 dal_fixed31_32_from_int(segment_start
));
549 arr_points
[1].x
= dal_fixed31_32_pow(dal_fixed31_32_from_int(2),
550 dal_fixed31_32_from_int(segment_end
));
551 arr_points
[2].x
= dal_fixed31_32_pow(dal_fixed31_32_from_int(2),
552 dal_fixed31_32_from_int(segment_end
));
554 y_r
= rgb_resulted
[0].red
;
555 y_g
= rgb_resulted
[0].green
;
556 y_b
= rgb_resulted
[0].blue
;
558 y1_min
= dal_fixed31_32_min(y_r
, dal_fixed31_32_min(y_g
, y_b
));
560 arr_points
[0].y
= y1_min
;
561 arr_points
[0].slope
= dal_fixed31_32_div(
565 y_r
= rgb_resulted
[hw_points
- 1].red
;
566 y_g
= rgb_resulted
[hw_points
- 1].green
;
567 y_b
= rgb_resulted
[hw_points
- 1].blue
;
569 /* see comment above, m_arrPoints[1].y should be the Y value for the
570 * region end (m_numOfHwPoints), not last HW point(m_numOfHwPoints - 1)
572 y3_max
= dal_fixed31_32_max(y_r
, dal_fixed31_32_max(y_g
, y_b
));
574 arr_points
[1].y
= y3_max
;
575 arr_points
[2].y
= y3_max
;
577 arr_points
[1].slope
= dal_fixed31_32_zero
;
578 arr_points
[2].slope
= dal_fixed31_32_zero
;
580 if (output_tf
->tf
== TRANSFER_FUNCTION_PQ
) {
581 /* for PQ, we want to have a straight line from last HW X point,
582 * and the slope to be such that we hit 1.0 at 10000 nits.
584 const struct fixed31_32 end_value
=
585 dal_fixed31_32_from_int(125);
587 arr_points
[1].slope
= dal_fixed31_32_div(
588 dal_fixed31_32_sub(dal_fixed31_32_one
, arr_points
[1].y
),
589 dal_fixed31_32_sub(end_value
, arr_points
[1].x
));
590 arr_points
[2].slope
= dal_fixed31_32_div(
591 dal_fixed31_32_sub(dal_fixed31_32_one
, arr_points
[1].y
),
592 dal_fixed31_32_sub(end_value
, arr_points
[1].x
));
595 regamma_params
->hw_points_num
= hw_points
;
598 for (k
= 0; k
< 16 && i
< 16; k
++) {
599 if (seg_distr
[k
] != -1) {
600 regamma_params
->arr_curve_points
[k
].segments_num
=
602 regamma_params
->arr_curve_points
[i
].offset
=
603 regamma_params
->arr_curve_points
[k
].
604 offset
+ (1 << seg_distr
[k
]);
609 if (seg_distr
[k
] != -1)
610 regamma_params
->arr_curve_points
[k
].segments_num
=
614 rgb_plus_1
= rgb_resulted
+ 1;
618 while (i
!= hw_points
+ 1) {
619 if (dal_fixed31_32_lt(rgb_plus_1
->red
, rgb
->red
))
620 rgb_plus_1
->red
= rgb
->red
;
621 if (dal_fixed31_32_lt(rgb_plus_1
->green
, rgb
->green
))
622 rgb_plus_1
->green
= rgb
->green
;
623 if (dal_fixed31_32_lt(rgb_plus_1
->blue
, rgb
->blue
))
624 rgb_plus_1
->blue
= rgb
->blue
;
626 rgb
->delta_red
= dal_fixed31_32_sub(
629 rgb
->delta_green
= dal_fixed31_32_sub(
632 rgb
->delta_blue
= dal_fixed31_32_sub(
641 convert_to_custom_float(rgb_resulted
, arr_points
, hw_points
);
646 static bool dce110_set_output_transfer_func(
647 struct pipe_ctx
*pipe_ctx
,
648 const struct dc_stream_state
*stream
)
650 struct transform
*xfm
= pipe_ctx
->plane_res
.xfm
;
652 xfm
->funcs
->opp_power_on_regamma_lut(xfm
, true);
653 xfm
->regamma_params
.hw_points_num
= GAMMA_HW_POINTS_NUM
;
655 if (stream
->out_transfer_func
&&
656 stream
->out_transfer_func
->type
==
657 TF_TYPE_PREDEFINED
&&
658 stream
->out_transfer_func
->tf
==
659 TRANSFER_FUNCTION_SRGB
) {
660 xfm
->funcs
->opp_set_regamma_mode(xfm
, OPP_REGAMMA_SRGB
);
661 } else if (dce110_translate_regamma_to_hw_format(
662 stream
->out_transfer_func
, &xfm
->regamma_params
)) {
663 xfm
->funcs
->opp_program_regamma_pwl(xfm
, &xfm
->regamma_params
);
664 xfm
->funcs
->opp_set_regamma_mode(xfm
, OPP_REGAMMA_USER
);
666 xfm
->funcs
->opp_set_regamma_mode(xfm
, OPP_REGAMMA_BYPASS
);
669 xfm
->funcs
->opp_power_on_regamma_lut(xfm
, false);
674 static enum dc_status
bios_parser_crtc_source_select(
675 struct pipe_ctx
*pipe_ctx
)
678 /* call VBIOS table to set CRTC source for the HW
680 * note: video bios clears all FMT setting here. */
681 struct bp_crtc_source_select crtc_source_select
= {0};
682 const struct dc_sink
*sink
= pipe_ctx
->stream
->sink
;
684 crtc_source_select
.engine_id
= pipe_ctx
->stream_res
.stream_enc
->id
;
685 crtc_source_select
.controller_id
= pipe_ctx
->pipe_idx
+ 1;
686 /*TODO: Need to un-hardcode color depth, dp_audio and account for
687 * the case where signal and sink signal is different (translator
689 crtc_source_select
.signal
= pipe_ctx
->stream
->signal
;
690 crtc_source_select
.enable_dp_audio
= false;
691 crtc_source_select
.sink_signal
= pipe_ctx
->stream
->signal
;
693 switch (pipe_ctx
->stream
->timing
.display_color_depth
) {
694 case COLOR_DEPTH_666
:
695 crtc_source_select
.display_output_bit_depth
= PANEL_6BIT_COLOR
;
697 case COLOR_DEPTH_888
:
698 crtc_source_select
.display_output_bit_depth
= PANEL_8BIT_COLOR
;
700 case COLOR_DEPTH_101010
:
701 crtc_source_select
.display_output_bit_depth
= PANEL_10BIT_COLOR
;
703 case COLOR_DEPTH_121212
:
704 crtc_source_select
.display_output_bit_depth
= PANEL_12BIT_COLOR
;
708 crtc_source_select
.display_output_bit_depth
= PANEL_8BIT_COLOR
;
712 dcb
= sink
->ctx
->dc_bios
;
714 if (BP_RESULT_OK
!= dcb
->funcs
->crtc_source_select(
716 &crtc_source_select
)) {
717 return DC_ERROR_UNEXPECTED
;
723 void dce110_update_info_frame(struct pipe_ctx
*pipe_ctx
)
725 ASSERT(pipe_ctx
->stream
);
727 if (pipe_ctx
->stream_res
.stream_enc
== NULL
)
728 return; /* this is not root pipe */
730 if (dc_is_hdmi_signal(pipe_ctx
->stream
->signal
))
731 pipe_ctx
->stream_res
.stream_enc
->funcs
->update_hdmi_info_packets(
732 pipe_ctx
->stream_res
.stream_enc
,
733 &pipe_ctx
->stream_res
.encoder_info_frame
);
734 else if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
735 pipe_ctx
->stream_res
.stream_enc
->funcs
->update_dp_info_packets(
736 pipe_ctx
->stream_res
.stream_enc
,
737 &pipe_ctx
->stream_res
.encoder_info_frame
);
740 void dce110_enable_stream(struct pipe_ctx
*pipe_ctx
)
742 enum dc_lane_count lane_count
=
743 pipe_ctx
->stream
->sink
->link
->cur_link_settings
.lane_count
;
745 struct dc_crtc_timing
*timing
= &pipe_ctx
->stream
->timing
;
746 struct dc_link
*link
= pipe_ctx
->stream
->sink
->link
;
748 /* 1. update AVI info frame (HDMI, DP)
749 * we always need to update info frame
751 uint32_t active_total_with_borders
;
752 uint32_t early_control
= 0;
753 struct timing_generator
*tg
= pipe_ctx
->stream_res
.tg
;
755 /* TODOFPGA may change to hwss.update_info_frame */
756 dce110_update_info_frame(pipe_ctx
);
757 /* enable early control to avoid corruption on DP monitor*/
758 active_total_with_borders
=
759 timing
->h_addressable
760 + timing
->h_border_left
761 + timing
->h_border_right
;
764 early_control
= active_total_with_borders
% lane_count
;
766 if (early_control
== 0)
767 early_control
= lane_count
;
769 tg
->funcs
->set_early_control(tg
, early_control
);
771 /* enable audio only within mode set */
772 if (pipe_ctx
->stream_res
.audio
!= NULL
) {
773 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
774 pipe_ctx
->stream_res
.stream_enc
->funcs
->dp_audio_enable(pipe_ctx
->stream_res
.stream_enc
);
777 /* For MST, there are multiply stream go to only one link.
778 * connect DIG back_end to front_end while enable_stream and
779 * disconnect them during disable_stream
780 * BY this, it is logic clean to separate stream and link */
781 link
->link_enc
->funcs
->connect_dig_be_to_fe(link
->link_enc
,
782 pipe_ctx
->stream_res
.stream_enc
->id
, true);
786 /*todo: cloned in stream enc, fix*/
787 static bool is_panel_backlight_on(struct dce_hwseq
*hws
)
791 REG_GET(LVTMA_PWRSEQ_CNTL
, LVTMA_BLON
, &value
);
796 static bool is_panel_powered_on(struct dce_hwseq
*hws
)
800 REG_GET(LVTMA_PWRSEQ_STATE
, LVTMA_PWRSEQ_TARGET_STATE_R
, &value
);
804 static enum bp_result
link_transmitter_control(
805 struct dc_bios
*bios
,
806 struct bp_transmitter_control
*cntl
)
808 enum bp_result result
;
810 result
= bios
->funcs
->transmitter_control(bios
, cntl
);
819 void hwss_edp_wait_for_hpd_ready(
820 struct dc_link
*link
,
823 struct dc_context
*ctx
= link
->ctx
;
824 struct graphics_object_id connector
= link
->link_enc
->connector
;
826 bool edp_hpd_high
= false;
827 uint32_t time_elapsed
= 0;
828 uint32_t timeout
= power_up
?
829 PANEL_POWER_UP_TIMEOUT
: PANEL_POWER_DOWN_TIMEOUT
;
831 if (dal_graphics_object_id_get_connector_id(connector
)
832 != CONNECTOR_ID_EDP
) {
839 * From KV, we will not HPD low after turning off VCC -
840 * instead, we will check the SW timer in power_up().
845 * When we power on/off the eDP panel,
846 * we need to wait until SENSE bit is high/low.
850 /* TODO what to do with this? */
851 hpd
= get_hpd_gpio(ctx
->dc_bios
, connector
, ctx
->gpio_service
);
858 dal_gpio_open(hpd
, GPIO_MODE_INTERRUPT
);
860 /* wait until timeout or panel detected */
863 uint32_t detected
= 0;
865 dal_gpio_get_value(hpd
, &detected
);
867 if (!(detected
^ power_up
)) {
872 msleep(HPD_CHECK_INTERVAL
);
874 time_elapsed
+= HPD_CHECK_INTERVAL
;
875 } while (time_elapsed
< timeout
);
879 dal_gpio_destroy_irq(&hpd
);
881 if (false == edp_hpd_high
) {
882 dm_logger_write(ctx
->logger
, LOG_ERROR
,
883 "%s: wait timed out!\n", __func__
);
887 void hwss_edp_power_control(
888 struct dc_link
*link
,
891 struct dc_context
*ctx
= link
->ctx
;
892 struct dce_hwseq
*hwseq
= ctx
->dc
->hwseq
;
893 struct bp_transmitter_control cntl
= { 0 };
894 enum bp_result bp_result
;
897 if (dal_graphics_object_id_get_connector_id(link
->link_enc
->connector
)
898 != CONNECTOR_ID_EDP
) {
903 if (power_up
!= is_panel_powered_on(hwseq
)) {
904 /* Send VBIOS command to prompt eDP panel power */
906 dm_logger_write(ctx
->logger
, LOG_HW_RESUME_S3
,
907 "%s: Panel Power action: %s\n",
908 __func__
, (power_up
? "On":"Off"));
910 cntl
.action
= power_up
?
911 TRANSMITTER_CONTROL_POWER_ON
:
912 TRANSMITTER_CONTROL_POWER_OFF
;
913 cntl
.transmitter
= link
->link_enc
->transmitter
;
914 cntl
.connector_obj_id
= link
->link_enc
->connector
;
915 cntl
.coherent
= false;
916 cntl
.lanes_number
= LANE_COUNT_FOUR
;
917 cntl
.hpd_sel
= link
->link_enc
->hpd_source
;
919 bp_result
= link_transmitter_control(ctx
->dc_bios
, &cntl
);
921 if (bp_result
!= BP_RESULT_OK
)
922 dm_logger_write(ctx
->logger
, LOG_ERROR
,
923 "%s: Panel Power bp_result: %d\n",
924 __func__
, bp_result
);
926 dm_logger_write(ctx
->logger
, LOG_HW_RESUME_S3
,
927 "%s: Skipping Panel Power action: %s\n",
928 __func__
, (power_up
? "On":"Off"));
932 /*todo: cloned in stream enc, fix*/
935 * eDP only. Control the backlight of the eDP panel
937 void hwss_edp_backlight_control(
938 struct dc_link
*link
,
941 struct dc_context
*ctx
= link
->ctx
;
942 struct dce_hwseq
*hws
= ctx
->dc
->hwseq
;
943 struct bp_transmitter_control cntl
= { 0 };
945 if (dal_graphics_object_id_get_connector_id(link
->link_enc
->connector
)
946 != CONNECTOR_ID_EDP
) {
951 if (enable
&& is_panel_backlight_on(hws
)) {
952 dm_logger_write(ctx
->logger
, LOG_HW_RESUME_S3
,
953 "%s: panel already powered up. Do nothing.\n",
958 /* Send VBIOS command to control eDP panel backlight */
960 dm_logger_write(ctx
->logger
, LOG_HW_RESUME_S3
,
961 "%s: backlight action: %s\n",
962 __func__
, (enable
? "On":"Off"));
964 cntl
.action
= enable
?
965 TRANSMITTER_CONTROL_BACKLIGHT_ON
:
966 TRANSMITTER_CONTROL_BACKLIGHT_OFF
;
968 /*cntl.engine_id = ctx->engine;*/
969 cntl
.transmitter
= link
->link_enc
->transmitter
;
970 cntl
.connector_obj_id
= link
->link_enc
->connector
;
972 cntl
.lanes_number
= LANE_COUNT_FOUR
;
973 cntl
.hpd_sel
= link
->link_enc
->hpd_source
;
975 /* For eDP, the following delays might need to be considered
976 * after link training completed:
977 * idle period - min. accounts for required BS-Idle pattern,
978 * max. allows for source frame synchronization);
979 * 50 msec max. delay from valid video data from source
980 * to video on dislpay or backlight enable.
982 * Disable the delay for now.
983 * Enable it in the future if necessary.
985 /* dc_service_sleep_in_milliseconds(50); */
986 link_transmitter_control(ctx
->dc_bios
, &cntl
);
989 void dce110_disable_stream(struct pipe_ctx
*pipe_ctx
, int option
)
991 struct dc_stream_state
*stream
= pipe_ctx
->stream
;
992 struct dc_link
*link
= stream
->sink
->link
;
993 struct dc
*dc
= pipe_ctx
->stream
->ctx
->dc
;
995 if (dc_is_hdmi_signal(pipe_ctx
->stream
->signal
))
996 pipe_ctx
->stream_res
.stream_enc
->funcs
->stop_hdmi_info_packets(
997 pipe_ctx
->stream_res
.stream_enc
);
999 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
1000 pipe_ctx
->stream_res
.stream_enc
->funcs
->stop_dp_info_packets(
1001 pipe_ctx
->stream_res
.stream_enc
);
1003 pipe_ctx
->stream_res
.stream_enc
->funcs
->audio_mute_control(
1004 pipe_ctx
->stream_res
.stream_enc
, true);
1005 if (pipe_ctx
->stream_res
.audio
) {
1006 pipe_ctx
->stream_res
.audio
->funcs
->az_disable(pipe_ctx
->stream_res
.audio
);
1008 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
1009 pipe_ctx
->stream_res
.stream_enc
->funcs
->dp_audio_disable(
1010 pipe_ctx
->stream_res
.stream_enc
);
1012 pipe_ctx
->stream_res
.stream_enc
->funcs
->hdmi_audio_disable(
1013 pipe_ctx
->stream_res
.stream_enc
);
1014 /*don't free audio if it is from retrain or internal disable stream*/
1015 if (option
== FREE_ACQUIRED_RESOURCE
&& dc
->caps
.dynamic_audio
== true) {
1016 /*we have to dynamic arbitrate the audio endpoints*/
1017 pipe_ctx
->stream_res
.audio
= NULL
;
1018 /*we free the resource, need reset is_audio_acquired*/
1019 update_audio_usage(&dc
->current_state
->res_ctx
, dc
->res_pool
, pipe_ctx
->stream_res
.audio
, false);
1022 /* TODO: notify audio driver for if audio modes list changed
1023 * add audio mode list change flag */
1024 /* dal_audio_disable_azalia_audio_jack_presence(stream->audio,
1025 * stream->stream_engine_id);
1029 /* blank at encoder level */
1030 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
1031 pipe_ctx
->stream_res
.stream_enc
->funcs
->dp_blank(pipe_ctx
->stream_res
.stream_enc
);
1033 link
->link_enc
->funcs
->connect_dig_be_to_fe(
1035 pipe_ctx
->stream_res
.stream_enc
->id
,
1040 void dce110_unblank_stream(struct pipe_ctx
*pipe_ctx
,
1041 struct dc_link_settings
*link_settings
)
1043 struct encoder_unblank_param params
= { { 0 } };
1044 struct dc_stream_state
*stream
= pipe_ctx
->stream
;
1045 struct dc_link
*link
= stream
->sink
->link
;
1047 /* only 3 items below are used by unblank */
1048 params
.pixel_clk_khz
=
1049 pipe_ctx
->stream
->timing
.pix_clk_khz
;
1050 params
.link_settings
.link_rate
= link_settings
->link_rate
;
1052 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
1053 pipe_ctx
->stream_res
.stream_enc
->funcs
->dp_unblank(pipe_ctx
->stream_res
.stream_enc
, ¶ms
);
1055 if (link
->local_sink
&& link
->local_sink
->sink_signal
== SIGNAL_TYPE_EDP
)
1056 link
->dc
->hwss
.edp_backlight_control(link
, true);
1058 void dce110_blank_stream(struct pipe_ctx
*pipe_ctx
)
1060 struct dc_stream_state
*stream
= pipe_ctx
->stream
;
1061 struct dc_link
*link
= stream
->sink
->link
;
1063 if (link
->local_sink
&& link
->local_sink
->sink_signal
== SIGNAL_TYPE_EDP
)
1064 link
->dc
->hwss
.edp_backlight_control(link
, false);
1066 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
1067 pipe_ctx
->stream_res
.stream_enc
->funcs
->dp_blank(pipe_ctx
->stream_res
.stream_enc
);
1071 void dce110_set_avmute(struct pipe_ctx
*pipe_ctx
, bool enable
)
1073 if (pipe_ctx
!= NULL
&& pipe_ctx
->stream_res
.stream_enc
!= NULL
)
1074 pipe_ctx
->stream_res
.stream_enc
->funcs
->set_avmute(pipe_ctx
->stream_res
.stream_enc
, enable
);
1077 static enum audio_dto_source
translate_to_dto_source(enum controller_id crtc_id
)
1080 case CONTROLLER_ID_D0
:
1081 return DTO_SOURCE_ID0
;
1082 case CONTROLLER_ID_D1
:
1083 return DTO_SOURCE_ID1
;
1084 case CONTROLLER_ID_D2
:
1085 return DTO_SOURCE_ID2
;
1086 case CONTROLLER_ID_D3
:
1087 return DTO_SOURCE_ID3
;
1088 case CONTROLLER_ID_D4
:
1089 return DTO_SOURCE_ID4
;
1090 case CONTROLLER_ID_D5
:
1091 return DTO_SOURCE_ID5
;
1093 return DTO_SOURCE_UNKNOWN
;
1097 static void build_audio_output(
1098 struct dc_state
*state
,
1099 const struct pipe_ctx
*pipe_ctx
,
1100 struct audio_output
*audio_output
)
1102 const struct dc_stream_state
*stream
= pipe_ctx
->stream
;
1103 audio_output
->engine_id
= pipe_ctx
->stream_res
.stream_enc
->id
;
1105 audio_output
->signal
= pipe_ctx
->stream
->signal
;
1107 /* audio_crtc_info */
1109 audio_output
->crtc_info
.h_total
=
1110 stream
->timing
.h_total
;
1113 * Audio packets are sent during actual CRTC blank physical signal, we
1114 * need to specify actual active signal portion
1116 audio_output
->crtc_info
.h_active
=
1117 stream
->timing
.h_addressable
1118 + stream
->timing
.h_border_left
1119 + stream
->timing
.h_border_right
;
1121 audio_output
->crtc_info
.v_active
=
1122 stream
->timing
.v_addressable
1123 + stream
->timing
.v_border_top
1124 + stream
->timing
.v_border_bottom
;
1126 audio_output
->crtc_info
.pixel_repetition
= 1;
1128 audio_output
->crtc_info
.interlaced
=
1129 stream
->timing
.flags
.INTERLACE
;
1131 audio_output
->crtc_info
.refresh_rate
=
1132 (stream
->timing
.pix_clk_khz
*1000)/
1133 (stream
->timing
.h_total
*stream
->timing
.v_total
);
1135 audio_output
->crtc_info
.color_depth
=
1136 stream
->timing
.display_color_depth
;
1138 audio_output
->crtc_info
.requested_pixel_clock
=
1139 pipe_ctx
->stream_res
.pix_clk_params
.requested_pix_clk
;
1141 audio_output
->crtc_info
.calculated_pixel_clock
=
1142 pipe_ctx
->stream_res
.pix_clk_params
.requested_pix_clk
;
1144 /*for HDMI, audio ACR is with deep color ratio factor*/
1145 if (dc_is_hdmi_signal(pipe_ctx
->stream
->signal
) &&
1146 audio_output
->crtc_info
.requested_pixel_clock
==
1147 stream
->timing
.pix_clk_khz
) {
1148 if (pipe_ctx
->stream_res
.pix_clk_params
.pixel_encoding
== PIXEL_ENCODING_YCBCR420
) {
1149 audio_output
->crtc_info
.requested_pixel_clock
=
1150 audio_output
->crtc_info
.requested_pixel_clock
/2;
1151 audio_output
->crtc_info
.calculated_pixel_clock
=
1152 pipe_ctx
->stream_res
.pix_clk_params
.requested_pix_clk
/2;
1157 if (pipe_ctx
->stream
->signal
== SIGNAL_TYPE_DISPLAY_PORT
||
1158 pipe_ctx
->stream
->signal
== SIGNAL_TYPE_DISPLAY_PORT_MST
) {
1159 audio_output
->pll_info
.dp_dto_source_clock_in_khz
=
1160 state
->dis_clk
->funcs
->get_dp_ref_clk_frequency(
1164 audio_output
->pll_info
.feed_back_divider
=
1165 pipe_ctx
->pll_settings
.feedback_divider
;
1167 audio_output
->pll_info
.dto_source
=
1168 translate_to_dto_source(
1169 pipe_ctx
->pipe_idx
+ 1);
1171 /* TODO hard code to enable for now. Need get from stream */
1172 audio_output
->pll_info
.ss_enabled
= true;
1174 audio_output
->pll_info
.ss_percentage
=
1175 pipe_ctx
->pll_settings
.ss_percentage
;
1178 static void get_surface_visual_confirm_color(const struct pipe_ctx
*pipe_ctx
,
1179 struct tg_color
*color
)
1181 uint32_t color_value
= MAX_TG_COLOR_VALUE
* (4 - pipe_ctx
->pipe_idx
) / 4;
1183 switch (pipe_ctx
->plane_res
.scl_data
.format
) {
1184 case PIXEL_FORMAT_ARGB8888
:
1185 /* set boarder color to red */
1186 color
->color_r_cr
= color_value
;
1189 case PIXEL_FORMAT_ARGB2101010
:
1190 /* set boarder color to blue */
1191 color
->color_b_cb
= color_value
;
1193 case PIXEL_FORMAT_420BPP8
:
1194 /* set boarder color to green */
1195 color
->color_g_y
= color_value
;
1197 case PIXEL_FORMAT_420BPP10
:
1198 /* set boarder color to yellow */
1199 color
->color_g_y
= color_value
;
1200 color
->color_r_cr
= color_value
;
1202 case PIXEL_FORMAT_FP16
:
1203 /* set boarder color to white */
1204 color
->color_r_cr
= color_value
;
1205 color
->color_b_cb
= color_value
;
1206 color
->color_g_y
= color_value
;
1213 static void program_scaler(const struct dc
*dc
,
1214 const struct pipe_ctx
*pipe_ctx
)
1216 struct tg_color color
= {0};
1218 #if defined(CONFIG_DRM_AMD_DC_DCN1_0)
1220 if (pipe_ctx
->plane_res
.xfm
->funcs
->transform_set_pixel_storage_depth
== NULL
)
1224 if (dc
->debug
.surface_visual_confirm
)
1225 get_surface_visual_confirm_color(pipe_ctx
, &color
);
1227 color_space_to_black_color(dc
,
1228 pipe_ctx
->stream
->output_color_space
,
1231 pipe_ctx
->plane_res
.xfm
->funcs
->transform_set_pixel_storage_depth(
1232 pipe_ctx
->plane_res
.xfm
,
1233 pipe_ctx
->plane_res
.scl_data
.lb_params
.depth
,
1234 &pipe_ctx
->stream
->bit_depth_params
);
1236 if (pipe_ctx
->stream_res
.tg
->funcs
->set_overscan_blank_color
)
1237 pipe_ctx
->stream_res
.tg
->funcs
->set_overscan_blank_color(
1238 pipe_ctx
->stream_res
.tg
,
1241 pipe_ctx
->plane_res
.xfm
->funcs
->transform_set_scaler(pipe_ctx
->plane_res
.xfm
,
1242 &pipe_ctx
->plane_res
.scl_data
);
1245 static enum dc_status
dce110_prog_pixclk_crtc_otg(
1246 struct pipe_ctx
*pipe_ctx
,
1247 struct dc_state
*context
,
1250 struct dc_stream_state
*stream
= pipe_ctx
->stream
;
1251 struct pipe_ctx
*pipe_ctx_old
= &dc
->current_state
->res_ctx
.
1252 pipe_ctx
[pipe_ctx
->pipe_idx
];
1253 struct tg_color black_color
= {0};
1255 if (!pipe_ctx_old
->stream
) {
1257 /* program blank color */
1258 color_space_to_black_color(dc
,
1259 stream
->output_color_space
, &black_color
);
1260 pipe_ctx
->stream_res
.tg
->funcs
->set_blank_color(
1261 pipe_ctx
->stream_res
.tg
,
1265 * Must blank CRTC after disabling power gating and before any
1266 * programming, otherwise CRTC will be hung in bad state
1268 pipe_ctx
->stream_res
.tg
->funcs
->set_blank(pipe_ctx
->stream_res
.tg
, true);
1270 if (false == pipe_ctx
->clock_source
->funcs
->program_pix_clk(
1271 pipe_ctx
->clock_source
,
1272 &pipe_ctx
->stream_res
.pix_clk_params
,
1273 &pipe_ctx
->pll_settings
)) {
1274 BREAK_TO_DEBUGGER();
1275 return DC_ERROR_UNEXPECTED
;
1278 pipe_ctx
->stream_res
.tg
->funcs
->program_timing(
1279 pipe_ctx
->stream_res
.tg
,
1283 pipe_ctx
->stream_res
.tg
->funcs
->set_static_screen_control(
1284 pipe_ctx
->stream_res
.tg
,
1288 if (!pipe_ctx_old
->stream
) {
1289 if (false == pipe_ctx
->stream_res
.tg
->funcs
->enable_crtc(
1290 pipe_ctx
->stream_res
.tg
)) {
1291 BREAK_TO_DEBUGGER();
1292 return DC_ERROR_UNEXPECTED
;
1301 static enum dc_status
apply_single_controller_ctx_to_hw(
1302 struct pipe_ctx
*pipe_ctx
,
1303 struct dc_state
*context
,
1306 struct dc_stream_state
*stream
= pipe_ctx
->stream
;
1307 struct pipe_ctx
*pipe_ctx_old
= &dc
->current_state
->res_ctx
.
1308 pipe_ctx
[pipe_ctx
->pipe_idx
];
1311 dc
->hwss
.prog_pixclk_crtc_otg(pipe_ctx
, context
, dc
);
1313 /* FPGA does not program backend */
1314 if (IS_FPGA_MAXIMUS_DC(dc
->ctx
->dce_environment
)) {
1315 pipe_ctx
->stream_res
.opp
->funcs
->opp_set_dyn_expansion(
1316 pipe_ctx
->stream_res
.opp
,
1317 COLOR_SPACE_YCBCR601
,
1318 stream
->timing
.display_color_depth
,
1319 pipe_ctx
->stream
->signal
);
1321 pipe_ctx
->stream_res
.opp
->funcs
->opp_program_fmt(
1322 pipe_ctx
->stream_res
.opp
,
1323 &stream
->bit_depth_params
,
1327 /* TODO: move to stream encoder */
1328 if (pipe_ctx
->stream
->signal
!= SIGNAL_TYPE_VIRTUAL
)
1329 if (DC_OK
!= bios_parser_crtc_source_select(pipe_ctx
)) {
1330 BREAK_TO_DEBUGGER();
1331 return DC_ERROR_UNEXPECTED
;
1333 pipe_ctx
->stream_res
.opp
->funcs
->opp_set_dyn_expansion(
1334 pipe_ctx
->stream_res
.opp
,
1335 COLOR_SPACE_YCBCR601
,
1336 stream
->timing
.display_color_depth
,
1337 pipe_ctx
->stream
->signal
);
1339 if (pipe_ctx
->stream
->signal
!= SIGNAL_TYPE_VIRTUAL
)
1340 stream
->sink
->link
->link_enc
->funcs
->setup(
1341 stream
->sink
->link
->link_enc
,
1342 pipe_ctx
->stream
->signal
);
1344 if (pipe_ctx
->stream
->signal
!= SIGNAL_TYPE_VIRTUAL
)
1345 pipe_ctx
->stream_res
.stream_enc
->funcs
->setup_stereo_sync(
1346 pipe_ctx
->stream_res
.stream_enc
,
1347 pipe_ctx
->stream_res
.tg
->inst
,
1348 stream
->timing
.timing_3d_format
!= TIMING_3D_FORMAT_NONE
);
1351 pipe_ctx
->stream_res
.opp
->funcs
->opp_program_fmt(
1352 pipe_ctx
->stream_res
.opp
,
1353 &stream
->bit_depth_params
,
1356 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
1357 pipe_ctx
->stream_res
.stream_enc
->funcs
->dp_set_stream_attribute(
1358 pipe_ctx
->stream_res
.stream_enc
,
1360 stream
->output_color_space
);
1362 if (dc_is_hdmi_signal(pipe_ctx
->stream
->signal
))
1363 pipe_ctx
->stream_res
.stream_enc
->funcs
->hdmi_set_stream_attribute(
1364 pipe_ctx
->stream_res
.stream_enc
,
1366 stream
->phy_pix_clk
,
1367 pipe_ctx
->stream_res
.audio
!= NULL
);
1369 if (dc_is_dvi_signal(pipe_ctx
->stream
->signal
))
1370 pipe_ctx
->stream_res
.stream_enc
->funcs
->dvi_set_stream_attribute(
1371 pipe_ctx
->stream_res
.stream_enc
,
1373 (pipe_ctx
->stream
->signal
== SIGNAL_TYPE_DVI_DUAL_LINK
) ?
1376 resource_build_info_frame(pipe_ctx
);
1377 dce110_update_info_frame(pipe_ctx
);
1378 if (!pipe_ctx_old
->stream
) {
1379 if (!pipe_ctx
->stream
->dpms_off
)
1380 core_link_enable_stream(context
, pipe_ctx
);
1383 pipe_ctx
->plane_res
.scl_data
.lb_params
.alpha_en
= pipe_ctx
->bottom_pipe
!= 0;
1385 pipe_ctx
->stream
->sink
->link
->psr_enabled
= false;
1390 /******************************************************************************/
1392 static void power_down_encoders(struct dc
*dc
)
1395 enum connector_id connector_id
;
1396 enum signal_type signal
= SIGNAL_TYPE_NONE
;
1398 /* do not know BIOS back-front mapping, simply blank all. It will not
1401 for (i
= 0; i
< dc
->res_pool
->stream_enc_count
; i
++) {
1402 dc
->res_pool
->stream_enc
[i
]->funcs
->dp_blank(
1403 dc
->res_pool
->stream_enc
[i
]);
1406 for (i
= 0; i
< dc
->link_count
; i
++) {
1407 connector_id
= dal_graphics_object_id_get_connector_id(dc
->links
[i
]->link_id
);
1408 if ((connector_id
== CONNECTOR_ID_DISPLAY_PORT
) ||
1409 (connector_id
== CONNECTOR_ID_EDP
)) {
1411 if (!dc
->links
[i
]->wa_flags
.dp_keep_receiver_powered
)
1412 dp_receiver_power_ctrl(dc
->links
[i
], false);
1413 if (connector_id
== CONNECTOR_ID_EDP
)
1414 signal
= SIGNAL_TYPE_EDP
;
1417 dc
->links
[i
]->link_enc
->funcs
->disable_output(
1418 dc
->links
[i
]->link_enc
, signal
);
1422 static void power_down_controllers(struct dc
*dc
)
1426 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
1427 dc
->res_pool
->timing_generators
[i
]->funcs
->disable_crtc(
1428 dc
->res_pool
->timing_generators
[i
]);
1432 static void power_down_clock_sources(struct dc
*dc
)
1436 if (dc
->res_pool
->dp_clock_source
->funcs
->cs_power_down(
1437 dc
->res_pool
->dp_clock_source
) == false)
1438 dm_error("Failed to power down pll! (dp clk src)\n");
1440 for (i
= 0; i
< dc
->res_pool
->clk_src_count
; i
++) {
1441 if (dc
->res_pool
->clock_sources
[i
]->funcs
->cs_power_down(
1442 dc
->res_pool
->clock_sources
[i
]) == false)
1443 dm_error("Failed to power down pll! (clk src index=%d)\n", i
);
1447 static void power_down_all_hw_blocks(struct dc
*dc
)
1449 power_down_encoders(dc
);
1451 power_down_controllers(dc
);
1453 power_down_clock_sources(dc
);
1455 #if defined(CONFIG_DRM_AMD_DC_FBC)
1456 if (dc
->fbc_compressor
)
1457 dc
->fbc_compressor
->funcs
->disable_fbc(dc
->fbc_compressor
);
1461 static void disable_vga_and_power_gate_all_controllers(
1465 struct timing_generator
*tg
;
1466 struct dc_context
*ctx
= dc
->ctx
;
1468 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
1469 tg
= dc
->res_pool
->timing_generators
[i
];
1471 if (tg
->funcs
->disable_vga
)
1472 tg
->funcs
->disable_vga(tg
);
1474 /* Enable CLOCK gating for each pipe BEFORE controller
1476 enable_display_pipe_clock_gating(ctx
,
1479 dc
->hwss
.power_down_front_end(dc
, i
);
1484 * When ASIC goes from VBIOS/VGA mode to driver/accelerated mode we need:
1485 * 1. Power down all DC HW blocks
1486 * 2. Disable VGA engine on all controllers
1487 * 3. Enable power gating for controller
1488 * 4. Set acc_mode_change bit (VBIOS will clear this bit when going to FSDOS)
1490 void dce110_enable_accelerated_mode(struct dc
*dc
)
1492 power_down_all_hw_blocks(dc
);
1494 disable_vga_and_power_gate_all_controllers(dc
);
1495 bios_set_scratch_acc_mode_change(dc
->ctx
->dc_bios
);
1498 static uint32_t compute_pstate_blackout_duration(
1499 struct bw_fixed blackout_duration
,
1500 const struct dc_stream_state
*stream
)
1502 uint32_t total_dest_line_time_ns
;
1503 uint32_t pstate_blackout_duration_ns
;
1505 pstate_blackout_duration_ns
= 1000 * blackout_duration
.value
>> 24;
1507 total_dest_line_time_ns
= 1000000UL *
1508 stream
->timing
.h_total
/
1509 stream
->timing
.pix_clk_khz
+
1510 pstate_blackout_duration_ns
;
1512 return total_dest_line_time_ns
;
1515 void dce110_set_displaymarks(
1516 const struct dc
*dc
,
1517 struct dc_state
*context
)
1519 uint8_t i
, num_pipes
;
1520 unsigned int underlay_idx
= dc
->res_pool
->underlay_pipe_index
;
1522 for (i
= 0, num_pipes
= 0; i
< MAX_PIPES
; i
++) {
1523 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
1524 uint32_t total_dest_line_time_ns
;
1526 if (pipe_ctx
->stream
== NULL
)
1529 total_dest_line_time_ns
= compute_pstate_blackout_duration(
1530 dc
->bw_vbios
->blackout_duration
, pipe_ctx
->stream
);
1531 pipe_ctx
->plane_res
.mi
->funcs
->mem_input_program_display_marks(
1532 pipe_ctx
->plane_res
.mi
,
1533 context
->bw
.dce
.nbp_state_change_wm_ns
[num_pipes
],
1534 context
->bw
.dce
.stutter_exit_wm_ns
[num_pipes
],
1535 context
->bw
.dce
.urgent_wm_ns
[num_pipes
],
1536 total_dest_line_time_ns
);
1537 if (i
== underlay_idx
) {
1539 pipe_ctx
->plane_res
.mi
->funcs
->mem_input_program_chroma_display_marks(
1540 pipe_ctx
->plane_res
.mi
,
1541 context
->bw
.dce
.nbp_state_change_wm_ns
[num_pipes
],
1542 context
->bw
.dce
.stutter_exit_wm_ns
[num_pipes
],
1543 context
->bw
.dce
.urgent_wm_ns
[num_pipes
],
1544 total_dest_line_time_ns
);
1550 static void set_safe_displaymarks(
1551 struct resource_context
*res_ctx
,
1552 const struct resource_pool
*pool
)
1555 int underlay_idx
= pool
->underlay_pipe_index
;
1556 struct dce_watermarks max_marks
= {
1557 MAX_WATERMARK
, MAX_WATERMARK
, MAX_WATERMARK
, MAX_WATERMARK
};
1558 struct dce_watermarks nbp_marks
= {
1559 SAFE_NBP_MARK
, SAFE_NBP_MARK
, SAFE_NBP_MARK
, SAFE_NBP_MARK
};
1561 for (i
= 0; i
< MAX_PIPES
; i
++) {
1562 if (res_ctx
->pipe_ctx
[i
].stream
== NULL
|| res_ctx
->pipe_ctx
[i
].plane_res
.mi
== NULL
)
1565 res_ctx
->pipe_ctx
[i
].plane_res
.mi
->funcs
->mem_input_program_display_marks(
1566 res_ctx
->pipe_ctx
[i
].plane_res
.mi
,
1572 if (i
== underlay_idx
)
1573 res_ctx
->pipe_ctx
[i
].plane_res
.mi
->funcs
->mem_input_program_chroma_display_marks(
1574 res_ctx
->pipe_ctx
[i
].plane_res
.mi
,
1583 /*******************************************************************************
1585 ******************************************************************************/
1587 static void set_drr(struct pipe_ctx
**pipe_ctx
,
1588 int num_pipes
, int vmin
, int vmax
)
1591 struct drr_params params
= {0};
1593 params
.vertical_total_max
= vmax
;
1594 params
.vertical_total_min
= vmin
;
1596 /* TODO: If multiple pipes are to be supported, you need
1600 for (i
= 0; i
< num_pipes
; i
++) {
1601 pipe_ctx
[i
]->stream_res
.tg
->funcs
->set_drr(pipe_ctx
[i
]->stream_res
.tg
, ¶ms
);
1605 static void get_position(struct pipe_ctx
**pipe_ctx
,
1607 struct crtc_position
*position
)
1611 /* TODO: handle pipes > 1
1613 for (i
= 0; i
< num_pipes
; i
++)
1614 pipe_ctx
[i
]->stream_res
.tg
->funcs
->get_position(pipe_ctx
[i
]->stream_res
.tg
, position
);
1617 static void set_static_screen_control(struct pipe_ctx
**pipe_ctx
,
1618 int num_pipes
, const struct dc_static_screen_events
*events
)
1621 unsigned int value
= 0;
1623 if (events
->overlay_update
)
1625 if (events
->surface_update
)
1627 if (events
->cursor_update
)
1630 #if defined(CONFIG_DRM_AMD_DC_FBC)
1634 for (i
= 0; i
< num_pipes
; i
++)
1635 pipe_ctx
[i
]->stream_res
.tg
->funcs
->
1636 set_static_screen_control(pipe_ctx
[i
]->stream_res
.tg
, value
);
1639 /* unit: in_khz before mode set, get pixel clock from context. ASIC register
1640 * may not be programmed yet.
1641 * TODO: after mode set, pre_mode_set = false,
1642 * may read PLL register to get pixel clock
1644 static uint32_t get_max_pixel_clock_for_all_paths(
1646 struct dc_state
*context
,
1649 uint32_t max_pix_clk
= 0;
1652 if (!pre_mode_set
) {
1653 /* TODO: read ASIC register to get pixel clock */
1657 for (i
= 0; i
< MAX_PIPES
; i
++) {
1658 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
1660 if (pipe_ctx
->stream
== NULL
)
1663 /* do not check under lay */
1664 if (pipe_ctx
->top_pipe
)
1667 if (pipe_ctx
->stream_res
.pix_clk_params
.requested_pix_clk
> max_pix_clk
)
1669 pipe_ctx
->stream_res
.pix_clk_params
.requested_pix_clk
;
1672 if (max_pix_clk
== 0)
1679 * Find clock state based on clock requested. if clock value is 0, simply
1680 * set clock state as requested without finding clock state by clock value
1683 static void apply_min_clocks(
1685 struct dc_state
*context
,
1686 enum dm_pp_clocks_state
*clocks_state
,
1689 struct state_dependent_clocks req_clocks
= {0};
1691 if (!pre_mode_set
) {
1692 /* set clock_state without verification */
1693 if (context
->dis_clk
->funcs
->set_min_clocks_state
) {
1694 context
->dis_clk
->funcs
->set_min_clocks_state(
1695 context
->dis_clk
, *clocks_state
);
1699 /* TODO: This is incorrect. Figure out how to fix. */
1700 context
->dis_clk
->funcs
->apply_clock_voltage_request(
1702 DM_PP_CLOCK_TYPE_DISPLAY_CLK
,
1703 context
->dis_clk
->cur_clocks_value
.dispclk_in_khz
,
1707 context
->dis_clk
->funcs
->apply_clock_voltage_request(
1709 DM_PP_CLOCK_TYPE_PIXELCLK
,
1710 context
->dis_clk
->cur_clocks_value
.max_pixelclk_in_khz
,
1714 context
->dis_clk
->funcs
->apply_clock_voltage_request(
1716 DM_PP_CLOCK_TYPE_DISPLAYPHYCLK
,
1717 context
->dis_clk
->cur_clocks_value
.max_non_dp_phyclk_in_khz
,
1723 /* get the required state based on state dependent clocks:
1724 * display clock and pixel clock
1726 req_clocks
.display_clk_khz
= context
->bw
.dce
.dispclk_khz
;
1728 req_clocks
.pixel_clk_khz
= get_max_pixel_clock_for_all_paths(
1731 if (context
->dis_clk
->funcs
->get_required_clocks_state
) {
1732 *clocks_state
= context
->dis_clk
->funcs
->get_required_clocks_state(
1733 context
->dis_clk
, &req_clocks
);
1734 context
->dis_clk
->funcs
->set_min_clocks_state(
1735 context
->dis_clk
, *clocks_state
);
1737 context
->dis_clk
->funcs
->apply_clock_voltage_request(
1739 DM_PP_CLOCK_TYPE_DISPLAY_CLK
,
1740 req_clocks
.display_clk_khz
,
1744 context
->dis_clk
->funcs
->apply_clock_voltage_request(
1746 DM_PP_CLOCK_TYPE_PIXELCLK
,
1747 req_clocks
.pixel_clk_khz
,
1751 context
->dis_clk
->funcs
->apply_clock_voltage_request(
1753 DM_PP_CLOCK_TYPE_DISPLAYPHYCLK
,
1754 req_clocks
.pixel_clk_khz
,
1760 #if defined(CONFIG_DRM_AMD_DC_FBC)
1763 * Check if FBC can be enabled
1765 static enum dc_status
validate_fbc(struct dc
*dc
,
1766 struct dc_state
*context
)
1768 struct pipe_ctx
*pipe_ctx
=
1769 &context
->res_ctx
.pipe_ctx
[0];
1771 ASSERT(dc
->fbc_compressor
);
1773 /* FBC memory should be allocated */
1774 if (!dc
->ctx
->fbc_gpu_addr
)
1775 return DC_ERROR_UNEXPECTED
;
1777 /* Only supports single display */
1778 if (context
->stream_count
!= 1)
1779 return DC_ERROR_UNEXPECTED
;
1781 /* Only supports eDP */
1782 if (pipe_ctx
->stream
->sink
->link
->connector_signal
!= SIGNAL_TYPE_EDP
)
1783 return DC_ERROR_UNEXPECTED
;
1785 /* PSR should not be enabled */
1786 if (pipe_ctx
->stream
->sink
->link
->psr_enabled
)
1787 return DC_ERROR_UNEXPECTED
;
1789 /* Nothing to compress */
1790 if (!pipe_ctx
->plane_state
)
1791 return DC_ERROR_UNEXPECTED
;
1793 /* Only for non-linear tiling */
1794 if (pipe_ctx
->plane_state
->tiling_info
.gfx8
.array_mode
== DC_ARRAY_LINEAR_GENERAL
)
1795 return DC_ERROR_UNEXPECTED
;
1803 static enum dc_status
enable_fbc(struct dc
*dc
,
1804 struct dc_state
*context
)
1806 enum dc_status status
= validate_fbc(dc
, context
);
1808 if (status
== DC_OK
) {
1809 /* Program GRPH COMPRESSED ADDRESS and PITCH */
1810 struct compr_addr_and_pitch_params params
= {0, 0, 0};
1811 struct compressor
*compr
= dc
->fbc_compressor
;
1812 struct pipe_ctx
*pipe_ctx
=
1813 &context
->res_ctx
.pipe_ctx
[0];
1815 params
.source_view_width
=
1816 pipe_ctx
->stream
->timing
.h_addressable
;
1817 params
.source_view_height
=
1818 pipe_ctx
->stream
->timing
.v_addressable
;
1820 compr
->compr_surface_address
.quad_part
= dc
->ctx
->fbc_gpu_addr
;
1822 compr
->funcs
->surface_address_and_pitch(compr
, ¶ms
);
1823 compr
->funcs
->set_fbc_invalidation_triggers(compr
, 1);
1825 compr
->funcs
->enable_fbc(compr
, ¶ms
);
1831 static enum dc_status
apply_ctx_to_hw_fpga(
1833 struct dc_state
*context
)
1835 enum dc_status status
= DC_ERROR_UNEXPECTED
;
1838 for (i
= 0; i
< MAX_PIPES
; i
++) {
1839 struct pipe_ctx
*pipe_ctx_old
=
1840 &dc
->current_state
->res_ctx
.pipe_ctx
[i
];
1841 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
1843 if (pipe_ctx
->stream
== NULL
)
1846 if (pipe_ctx
->stream
== pipe_ctx_old
->stream
)
1849 status
= apply_single_controller_ctx_to_hw(
1854 if (status
!= DC_OK
)
1861 static void dce110_reset_hw_ctx_wrap(
1863 struct dc_state
*context
)
1867 /* Reset old context */
1868 /* look up the targets that have been removed since last commit */
1869 for (i
= 0; i
< MAX_PIPES
; i
++) {
1870 struct pipe_ctx
*pipe_ctx_old
=
1871 &dc
->current_state
->res_ctx
.pipe_ctx
[i
];
1872 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
1874 /* Note: We need to disable output if clock sources change,
1875 * since bios does optimization and doesn't apply if changing
1876 * PHY when not already disabled.
1879 /* Skip underlay pipe since it will be handled in commit surface*/
1880 if (!pipe_ctx_old
->stream
|| pipe_ctx_old
->top_pipe
)
1883 if (!pipe_ctx
->stream
||
1884 pipe_need_reprogram(pipe_ctx_old
, pipe_ctx
)) {
1885 struct clock_source
*old_clk
= pipe_ctx_old
->clock_source
;
1887 /* Disable if new stream is null. O/w, if stream is
1888 * disabled already, no need to disable again.
1890 if (!pipe_ctx
->stream
|| !pipe_ctx
->stream
->dpms_off
)
1891 core_link_disable_stream(pipe_ctx_old
, FREE_ACQUIRED_RESOURCE
);
1893 pipe_ctx_old
->stream_res
.tg
->funcs
->set_blank(pipe_ctx_old
->stream_res
.tg
, true);
1894 if (!hwss_wait_for_blank_complete(pipe_ctx_old
->stream_res
.tg
)) {
1895 dm_error("DC: failed to blank crtc!\n");
1896 BREAK_TO_DEBUGGER();
1898 pipe_ctx_old
->stream_res
.tg
->funcs
->disable_crtc(pipe_ctx_old
->stream_res
.tg
);
1899 pipe_ctx_old
->plane_res
.mi
->funcs
->free_mem_input(
1900 pipe_ctx_old
->plane_res
.mi
, dc
->current_state
->stream_count
);
1902 if (old_clk
&& 0 == resource_get_clock_source_reference(&context
->res_ctx
,
1905 old_clk
->funcs
->cs_power_down(old_clk
);
1907 dc
->hwss
.power_down_front_end(dc
, pipe_ctx_old
->pipe_idx
);
1909 pipe_ctx_old
->stream
= NULL
;
1915 enum dc_status
dce110_apply_ctx_to_hw(
1917 struct dc_state
*context
)
1919 struct dc_bios
*dcb
= dc
->ctx
->dc_bios
;
1920 enum dc_status status
;
1922 enum dm_pp_clocks_state clocks_state
= DM_PP_CLOCKS_STATE_INVALID
;
1924 /* Reset old context */
1925 /* look up the targets that have been removed since last commit */
1926 dc
->hwss
.reset_hw_ctx_wrap(dc
, context
);
1928 /* Skip applying if no targets */
1929 if (context
->stream_count
<= 0)
1932 if (IS_FPGA_MAXIMUS_DC(dc
->ctx
->dce_environment
)) {
1933 apply_ctx_to_hw_fpga(dc
, context
);
1937 /* Apply new context */
1938 dcb
->funcs
->set_scratch_critical_state(dcb
, true);
1940 /* below is for real asic only */
1941 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
1942 struct pipe_ctx
*pipe_ctx_old
=
1943 &dc
->current_state
->res_ctx
.pipe_ctx
[i
];
1944 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
1946 if (pipe_ctx
->stream
== NULL
|| pipe_ctx
->top_pipe
)
1949 if (pipe_ctx
->stream
== pipe_ctx_old
->stream
) {
1950 if (pipe_ctx_old
->clock_source
!= pipe_ctx
->clock_source
)
1951 dce_crtc_switch_to_clk_src(dc
->hwseq
,
1952 pipe_ctx
->clock_source
, i
);
1956 dc
->hwss
.enable_display_power_gating(
1957 dc
, i
, dc
->ctx
->dc_bios
,
1958 PIPE_GATING_CONTROL_DISABLE
);
1961 set_safe_displaymarks(&context
->res_ctx
, dc
->res_pool
);
1963 #if defined(CONFIG_DRM_AMD_DC_FBC)
1964 if (dc
->fbc_compressor
)
1965 dc
->fbc_compressor
->funcs
->disable_fbc(dc
->fbc_compressor
);
1967 /*TODO: when pplib works*/
1968 apply_min_clocks(dc
, context
, &clocks_state
, true);
1970 #if defined(CONFIG_DRM_AMD_DC_DCN1_0)
1971 if (dc
->ctx
->dce_version
>= DCN_VERSION_1_0
) {
1972 if (context
->bw
.dcn
.calc_clk
.fclk_khz
1973 > dc
->current_state
->bw
.dcn
.cur_clk
.fclk_khz
) {
1974 struct dm_pp_clock_for_voltage_req clock
;
1976 clock
.clk_type
= DM_PP_CLOCK_TYPE_FCLK
;
1977 clock
.clocks_in_khz
= context
->bw
.dcn
.calc_clk
.fclk_khz
;
1978 dm_pp_apply_clock_for_voltage_request(dc
->ctx
, &clock
);
1979 dc
->current_state
->bw
.dcn
.cur_clk
.fclk_khz
= clock
.clocks_in_khz
;
1980 context
->bw
.dcn
.cur_clk
.fclk_khz
= clock
.clocks_in_khz
;
1982 if (context
->bw
.dcn
.calc_clk
.dcfclk_khz
1983 > dc
->current_state
->bw
.dcn
.cur_clk
.dcfclk_khz
) {
1984 struct dm_pp_clock_for_voltage_req clock
;
1986 clock
.clk_type
= DM_PP_CLOCK_TYPE_DCFCLK
;
1987 clock
.clocks_in_khz
= context
->bw
.dcn
.calc_clk
.dcfclk_khz
;
1988 dm_pp_apply_clock_for_voltage_request(dc
->ctx
, &clock
);
1989 dc
->current_state
->bw
.dcn
.cur_clk
.dcfclk_khz
= clock
.clocks_in_khz
;
1990 context
->bw
.dcn
.cur_clk
.dcfclk_khz
= clock
.clocks_in_khz
;
1992 if (context
->bw
.dcn
.calc_clk
.dispclk_khz
1993 > dc
->current_state
->bw
.dcn
.cur_clk
.dispclk_khz
) {
1994 dc
->res_pool
->display_clock
->funcs
->set_clock(
1995 dc
->res_pool
->display_clock
,
1996 context
->bw
.dcn
.calc_clk
.dispclk_khz
);
1997 dc
->current_state
->bw
.dcn
.cur_clk
.dispclk_khz
=
1998 context
->bw
.dcn
.calc_clk
.dispclk_khz
;
1999 context
->bw
.dcn
.cur_clk
.dispclk_khz
=
2000 context
->bw
.dcn
.calc_clk
.dispclk_khz
;
2004 if (context
->bw
.dce
.dispclk_khz
2005 > dc
->current_state
->bw
.dce
.dispclk_khz
) {
2006 dc
->res_pool
->display_clock
->funcs
->set_clock(
2007 dc
->res_pool
->display_clock
,
2008 context
->bw
.dce
.dispclk_khz
* 115 / 100);
2010 /* program audio wall clock. use HDMI as clock source if HDMI
2011 * audio active. Otherwise, use DP as clock source
2012 * first, loop to find any HDMI audio, if not, loop find DP audio
2014 /* Setup audio rate clock source */
2016 * Audio lag happened on DP monitor when unplug a HDMI monitor
2019 * In case of DP and HDMI connected or HDMI only, DCCG_AUDIO_DTO_SEL
2020 * is set to either dto0 or dto1, audio should work fine.
2021 * In case of DP connected only, DCCG_AUDIO_DTO_SEL should be dto1,
2022 * set to dto0 will cause audio lag.
2025 * Not optimized audio wall dto setup. When mode set, iterate pipe_ctx,
2026 * find first available pipe with audio, setup audio wall DTO per topology
2027 * instead of per pipe.
2029 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
2030 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
2032 if (pipe_ctx
->stream
== NULL
)
2035 if (pipe_ctx
->top_pipe
)
2038 if (pipe_ctx
->stream
->signal
!= SIGNAL_TYPE_HDMI_TYPE_A
)
2041 if (pipe_ctx
->stream_res
.audio
!= NULL
) {
2042 struct audio_output audio_output
;
2044 build_audio_output(context
, pipe_ctx
, &audio_output
);
2046 pipe_ctx
->stream_res
.audio
->funcs
->wall_dto_setup(
2047 pipe_ctx
->stream_res
.audio
,
2048 pipe_ctx
->stream
->signal
,
2049 &audio_output
.crtc_info
,
2050 &audio_output
.pll_info
);
2055 /* no HDMI audio is found, try DP audio */
2056 if (i
== dc
->res_pool
->pipe_count
) {
2057 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
2058 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
2060 if (pipe_ctx
->stream
== NULL
)
2063 if (pipe_ctx
->top_pipe
)
2066 if (!dc_is_dp_signal(pipe_ctx
->stream
->signal
))
2069 if (pipe_ctx
->stream_res
.audio
!= NULL
) {
2070 struct audio_output audio_output
;
2072 build_audio_output(context
, pipe_ctx
, &audio_output
);
2074 pipe_ctx
->stream_res
.audio
->funcs
->wall_dto_setup(
2075 pipe_ctx
->stream_res
.audio
,
2076 pipe_ctx
->stream
->signal
,
2077 &audio_output
.crtc_info
,
2078 &audio_output
.pll_info
);
2084 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
2085 struct pipe_ctx
*pipe_ctx_old
=
2086 &dc
->current_state
->res_ctx
.pipe_ctx
[i
];
2087 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
2089 if (pipe_ctx
->stream
== NULL
)
2092 if (pipe_ctx
->stream
== pipe_ctx_old
->stream
)
2095 if (pipe_ctx
->stream
&& pipe_ctx_old
->stream
2096 && !pipe_need_reprogram(pipe_ctx_old
, pipe_ctx
))
2099 if (pipe_ctx
->top_pipe
)
2102 if (context
->res_ctx
.pipe_ctx
[i
].stream_res
.audio
!= NULL
) {
2104 struct audio_output audio_output
;
2106 build_audio_output(context
, pipe_ctx
, &audio_output
);
2108 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
2109 pipe_ctx
->stream_res
.stream_enc
->funcs
->dp_audio_setup(
2110 pipe_ctx
->stream_res
.stream_enc
,
2111 pipe_ctx
->stream_res
.audio
->inst
,
2112 &pipe_ctx
->stream
->audio_info
);
2114 pipe_ctx
->stream_res
.stream_enc
->funcs
->hdmi_audio_setup(
2115 pipe_ctx
->stream_res
.stream_enc
,
2116 pipe_ctx
->stream_res
.audio
->inst
,
2117 &pipe_ctx
->stream
->audio_info
,
2118 &audio_output
.crtc_info
);
2120 pipe_ctx
->stream_res
.audio
->funcs
->az_configure(
2121 pipe_ctx
->stream_res
.audio
,
2122 pipe_ctx
->stream
->signal
,
2123 &audio_output
.crtc_info
,
2124 &pipe_ctx
->stream
->audio_info
);
2127 status
= apply_single_controller_ctx_to_hw(
2132 if (dc
->hwss
.power_on_front_end
)
2133 dc
->hwss
.power_on_front_end(dc
, pipe_ctx
, context
);
2135 if (DC_OK
!= status
)
2139 /* pplib is notified if disp_num changed */
2140 dc
->hwss
.set_bandwidth(dc
, context
, true);
2143 apply_min_clocks(dc
, context
, &clocks_state
, false);
2145 dcb
->funcs
->set_scratch_critical_state(dcb
, false);
2147 #if defined(CONFIG_DRM_AMD_DC_FBC)
2148 if (dc
->fbc_compressor
)
2149 enable_fbc(dc
, context
);
2156 /*******************************************************************************
2157 * Front End programming
2158 ******************************************************************************/
2159 static void set_default_colors(struct pipe_ctx
*pipe_ctx
)
2161 struct default_adjustment default_adjust
= { 0 };
2163 default_adjust
.force_hw_default
= false;
2164 if (pipe_ctx
->plane_state
== NULL
)
2165 default_adjust
.in_color_space
= COLOR_SPACE_SRGB
;
2167 default_adjust
.in_color_space
=
2168 pipe_ctx
->plane_state
->color_space
;
2169 if (pipe_ctx
->stream
== NULL
)
2170 default_adjust
.out_color_space
= COLOR_SPACE_SRGB
;
2172 default_adjust
.out_color_space
=
2173 pipe_ctx
->stream
->output_color_space
;
2174 default_adjust
.csc_adjust_type
= GRAPHICS_CSC_ADJUST_TYPE_SW
;
2175 default_adjust
.surface_pixel_format
= pipe_ctx
->plane_res
.scl_data
.format
;
2177 /* display color depth */
2178 default_adjust
.color_depth
=
2179 pipe_ctx
->stream
->timing
.display_color_depth
;
2181 /* Lb color depth */
2182 default_adjust
.lb_color_depth
= pipe_ctx
->plane_res
.scl_data
.lb_params
.depth
;
2184 pipe_ctx
->plane_res
.xfm
->funcs
->opp_set_csc_default(
2185 pipe_ctx
->plane_res
.xfm
, &default_adjust
);
2189 /*******************************************************************************
2190 * In order to turn on/off specific surface we will program
2193 * In case that we have two surfaces and they have a different visibility
2194 * we can't turn off the CRTC since it will turn off the entire display
2196 * |----------------------------------------------- |
2197 * |bottom pipe|curr pipe | | |
2198 * |Surface |Surface | Blender | CRCT |
2199 * |visibility |visibility | Configuration| |
2200 * |------------------------------------------------|
2201 * | off | off | CURRENT_PIPE | blank |
2202 * | off | on | CURRENT_PIPE | unblank |
2203 * | on | off | OTHER_PIPE | unblank |
2204 * | on | on | BLENDING | unblank |
2205 * -------------------------------------------------|
2207 ******************************************************************************/
2208 static void program_surface_visibility(const struct dc
*dc
,
2209 struct pipe_ctx
*pipe_ctx
)
2211 enum blnd_mode blender_mode
= BLND_MODE_CURRENT_PIPE
;
2212 bool blank_target
= false;
2214 if (pipe_ctx
->bottom_pipe
) {
2216 /* For now we are supporting only two pipes */
2217 ASSERT(pipe_ctx
->bottom_pipe
->bottom_pipe
== NULL
);
2219 if (pipe_ctx
->bottom_pipe
->plane_state
->visible
) {
2220 if (pipe_ctx
->plane_state
->visible
)
2221 blender_mode
= BLND_MODE_BLENDING
;
2223 blender_mode
= BLND_MODE_OTHER_PIPE
;
2225 } else if (!pipe_ctx
->plane_state
->visible
)
2226 blank_target
= true;
2228 } else if (!pipe_ctx
->plane_state
->visible
)
2229 blank_target
= true;
2231 dce_set_blender_mode(dc
->hwseq
, pipe_ctx
->pipe_idx
, blender_mode
);
2232 pipe_ctx
->stream_res
.tg
->funcs
->set_blank(pipe_ctx
->stream_res
.tg
, blank_target
);
2236 static void program_gamut_remap(struct pipe_ctx
*pipe_ctx
)
2238 struct xfm_grph_csc_adjustment adjust
;
2239 memset(&adjust
, 0, sizeof(adjust
));
2240 adjust
.gamut_adjust_type
= GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS
;
2243 if (pipe_ctx
->stream
->gamut_remap_matrix
.enable_remap
== true) {
2244 adjust
.gamut_adjust_type
= GRAPHICS_GAMUT_ADJUST_TYPE_SW
;
2245 adjust
.temperature_matrix
[0] =
2247 gamut_remap_matrix
.matrix
[0];
2248 adjust
.temperature_matrix
[1] =
2250 gamut_remap_matrix
.matrix
[1];
2251 adjust
.temperature_matrix
[2] =
2253 gamut_remap_matrix
.matrix
[2];
2254 adjust
.temperature_matrix
[3] =
2256 gamut_remap_matrix
.matrix
[4];
2257 adjust
.temperature_matrix
[4] =
2259 gamut_remap_matrix
.matrix
[5];
2260 adjust
.temperature_matrix
[5] =
2262 gamut_remap_matrix
.matrix
[6];
2263 adjust
.temperature_matrix
[6] =
2265 gamut_remap_matrix
.matrix
[8];
2266 adjust
.temperature_matrix
[7] =
2268 gamut_remap_matrix
.matrix
[9];
2269 adjust
.temperature_matrix
[8] =
2271 gamut_remap_matrix
.matrix
[10];
2274 pipe_ctx
->plane_res
.xfm
->funcs
->transform_set_gamut_remap(pipe_ctx
->plane_res
.xfm
, &adjust
);
2278 * TODO REMOVE, USE UPDATE INSTEAD
2280 static void set_plane_config(
2281 const struct dc
*dc
,
2282 struct pipe_ctx
*pipe_ctx
,
2283 struct resource_context
*res_ctx
)
2285 struct mem_input
*mi
= pipe_ctx
->plane_res
.mi
;
2286 struct dc_plane_state
*plane_state
= pipe_ctx
->plane_state
;
2287 struct xfm_grph_csc_adjustment adjust
;
2288 struct out_csc_color_matrix tbl_entry
;
2291 memset(&adjust
, 0, sizeof(adjust
));
2292 memset(&tbl_entry
, 0, sizeof(tbl_entry
));
2293 adjust
.gamut_adjust_type
= GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS
;
2295 dce_enable_fe_clock(dc
->hwseq
, pipe_ctx
->pipe_idx
, true);
2297 set_default_colors(pipe_ctx
);
2298 if (pipe_ctx
->stream
->csc_color_matrix
.enable_adjustment
2300 tbl_entry
.color_space
=
2301 pipe_ctx
->stream
->output_color_space
;
2303 for (i
= 0; i
< 12; i
++)
2304 tbl_entry
.regval
[i
] =
2305 pipe_ctx
->stream
->csc_color_matrix
.matrix
[i
];
2307 pipe_ctx
->plane_res
.xfm
->funcs
->opp_set_csc_adjustment
2308 (pipe_ctx
->plane_res
.xfm
, &tbl_entry
);
2311 if (pipe_ctx
->stream
->gamut_remap_matrix
.enable_remap
== true) {
2312 adjust
.gamut_adjust_type
= GRAPHICS_GAMUT_ADJUST_TYPE_SW
;
2313 adjust
.temperature_matrix
[0] =
2315 gamut_remap_matrix
.matrix
[0];
2316 adjust
.temperature_matrix
[1] =
2318 gamut_remap_matrix
.matrix
[1];
2319 adjust
.temperature_matrix
[2] =
2321 gamut_remap_matrix
.matrix
[2];
2322 adjust
.temperature_matrix
[3] =
2324 gamut_remap_matrix
.matrix
[4];
2325 adjust
.temperature_matrix
[4] =
2327 gamut_remap_matrix
.matrix
[5];
2328 adjust
.temperature_matrix
[5] =
2330 gamut_remap_matrix
.matrix
[6];
2331 adjust
.temperature_matrix
[6] =
2333 gamut_remap_matrix
.matrix
[8];
2334 adjust
.temperature_matrix
[7] =
2336 gamut_remap_matrix
.matrix
[9];
2337 adjust
.temperature_matrix
[8] =
2339 gamut_remap_matrix
.matrix
[10];
2342 pipe_ctx
->plane_res
.xfm
->funcs
->transform_set_gamut_remap(pipe_ctx
->plane_res
.xfm
, &adjust
);
2344 pipe_ctx
->plane_res
.scl_data
.lb_params
.alpha_en
= pipe_ctx
->bottom_pipe
!= 0;
2345 program_scaler(dc
, pipe_ctx
);
2347 program_surface_visibility(dc
, pipe_ctx
);
2349 mi
->funcs
->mem_input_program_surface_config(
2351 plane_state
->format
,
2352 &plane_state
->tiling_info
,
2353 &plane_state
->plane_size
,
2354 plane_state
->rotation
,
2357 if (mi
->funcs
->set_blank
)
2358 mi
->funcs
->set_blank(mi
, pipe_ctx
->plane_state
->visible
);
2360 if (dc
->config
.gpu_vm_support
)
2361 mi
->funcs
->mem_input_program_pte_vm(
2362 pipe_ctx
->plane_res
.mi
,
2363 plane_state
->format
,
2364 &plane_state
->tiling_info
,
2365 plane_state
->rotation
);
2368 static void update_plane_addr(const struct dc
*dc
,
2369 struct pipe_ctx
*pipe_ctx
)
2371 struct dc_plane_state
*plane_state
= pipe_ctx
->plane_state
;
2373 if (plane_state
== NULL
)
2376 pipe_ctx
->plane_res
.mi
->funcs
->mem_input_program_surface_flip_and_addr(
2377 pipe_ctx
->plane_res
.mi
,
2378 &plane_state
->address
,
2379 plane_state
->flip_immediate
);
2381 plane_state
->status
.requested_address
= plane_state
->address
;
2384 void dce110_update_pending_status(struct pipe_ctx
*pipe_ctx
)
2386 struct dc_plane_state
*plane_state
= pipe_ctx
->plane_state
;
2388 if (plane_state
== NULL
)
2391 plane_state
->status
.is_flip_pending
=
2392 pipe_ctx
->plane_res
.mi
->funcs
->mem_input_is_flip_pending(
2393 pipe_ctx
->plane_res
.mi
);
2395 if (plane_state
->status
.is_flip_pending
&& !plane_state
->visible
)
2396 pipe_ctx
->plane_res
.mi
->current_address
= pipe_ctx
->plane_res
.mi
->request_address
;
2398 plane_state
->status
.current_address
= pipe_ctx
->plane_res
.mi
->current_address
;
2399 if (pipe_ctx
->plane_res
.mi
->current_address
.type
== PLN_ADDR_TYPE_GRPH_STEREO
&&
2400 pipe_ctx
->stream_res
.tg
->funcs
->is_stereo_left_eye
) {
2401 plane_state
->status
.is_right_eye
=\
2402 !pipe_ctx
->stream_res
.tg
->funcs
->is_stereo_left_eye(pipe_ctx
->stream_res
.tg
);
2406 void dce110_power_down(struct dc
*dc
)
2408 power_down_all_hw_blocks(dc
);
2409 disable_vga_and_power_gate_all_controllers(dc
);
2412 static bool wait_for_reset_trigger_to_occur(
2413 struct dc_context
*dc_ctx
,
2414 struct timing_generator
*tg
)
2418 /* To avoid endless loop we wait at most
2419 * frames_to_wait_on_triggered_reset frames for the reset to occur. */
2420 const uint32_t frames_to_wait_on_triggered_reset
= 10;
2423 for (i
= 0; i
< frames_to_wait_on_triggered_reset
; i
++) {
2425 if (!tg
->funcs
->is_counter_moving(tg
)) {
2426 DC_ERROR("TG counter is not moving!\n");
2430 if (tg
->funcs
->did_triggered_reset_occur(tg
)) {
2432 /* usually occurs at i=1 */
2433 DC_SYNC_INFO("GSL: reset occurred at wait count: %d\n",
2438 /* Wait for one frame. */
2439 tg
->funcs
->wait_for_state(tg
, CRTC_STATE_VACTIVE
);
2440 tg
->funcs
->wait_for_state(tg
, CRTC_STATE_VBLANK
);
2444 DC_ERROR("GSL: Timeout on reset trigger!\n");
2449 /* Enable timing synchronization for a group of Timing Generators. */
2450 static void dce110_enable_timing_synchronization(
2454 struct pipe_ctx
*grouped_pipes
[])
2456 struct dc_context
*dc_ctx
= dc
->ctx
;
2457 struct dcp_gsl_params gsl_params
= { 0 };
2460 DC_SYNC_INFO("GSL: Setting-up...\n");
2462 /* Designate a single TG in the group as a master.
2463 * Since HW doesn't care which one, we always assign
2464 * the 1st one in the group. */
2465 gsl_params
.gsl_group
= 0;
2466 gsl_params
.gsl_master
= grouped_pipes
[0]->stream_res
.tg
->inst
;
2468 for (i
= 0; i
< group_size
; i
++)
2469 grouped_pipes
[i
]->stream_res
.tg
->funcs
->setup_global_swap_lock(
2470 grouped_pipes
[i
]->stream_res
.tg
, &gsl_params
);
2472 /* Reset slave controllers on master VSync */
2473 DC_SYNC_INFO("GSL: enabling trigger-reset\n");
2475 for (i
= 1 /* skip the master */; i
< group_size
; i
++)
2476 grouped_pipes
[i
]->stream_res
.tg
->funcs
->enable_reset_trigger(
2477 grouped_pipes
[i
]->stream_res
.tg
, gsl_params
.gsl_group
);
2481 for (i
= 1 /* skip the master */; i
< group_size
; i
++) {
2482 DC_SYNC_INFO("GSL: waiting for reset to occur.\n");
2483 wait_for_reset_trigger_to_occur(dc_ctx
, grouped_pipes
[i
]->stream_res
.tg
);
2484 /* Regardless of success of the wait above, remove the reset or
2485 * the driver will start timing out on Display requests. */
2486 DC_SYNC_INFO("GSL: disabling trigger-reset.\n");
2487 grouped_pipes
[i
]->stream_res
.tg
->funcs
->disable_reset_trigger(grouped_pipes
[i
]->stream_res
.tg
);
2491 /* GSL Vblank synchronization is a one time sync mechanism, assumption
2492 * is that the sync'ed displays will not drift out of sync over time*/
2493 DC_SYNC_INFO("GSL: Restoring register states.\n");
2494 for (i
= 0; i
< group_size
; i
++)
2495 grouped_pipes
[i
]->stream_res
.tg
->funcs
->tear_down_global_swap_lock(grouped_pipes
[i
]->stream_res
.tg
);
2497 DC_SYNC_INFO("GSL: Set-up complete.\n");
2500 static void init_hw(struct dc
*dc
)
2504 struct transform
*xfm
;
2507 bp
= dc
->ctx
->dc_bios
;
2508 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
2509 xfm
= dc
->res_pool
->transforms
[i
];
2510 xfm
->funcs
->transform_reset(xfm
);
2512 dc
->hwss
.enable_display_power_gating(
2514 PIPE_GATING_CONTROL_INIT
);
2515 dc
->hwss
.enable_display_power_gating(
2517 PIPE_GATING_CONTROL_DISABLE
);
2518 dc
->hwss
.enable_display_pipe_clock_gating(
2523 dce_clock_gating_power_up(dc
->hwseq
, false);
2524 /***************************************/
2526 for (i
= 0; i
< dc
->link_count
; i
++) {
2527 /****************************************/
2528 /* Power up AND update implementation according to the
2529 * required signal (which may be different from the
2530 * default signal on connector). */
2531 struct dc_link
*link
= dc
->links
[i
];
2533 if (link
->link_enc
->connector
.id
== CONNECTOR_ID_EDP
)
2534 dc
->hwss
.edp_power_control(link
, true);
2536 link
->link_enc
->funcs
->hw_init(link
->link_enc
);
2539 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
2540 struct timing_generator
*tg
= dc
->res_pool
->timing_generators
[i
];
2542 tg
->funcs
->disable_vga(tg
);
2544 /* Blank controller using driver code instead of
2546 tg
->funcs
->set_blank(tg
, true);
2547 hwss_wait_for_blank_complete(tg
);
2550 for (i
= 0; i
< dc
->res_pool
->audio_count
; i
++) {
2551 struct audio
*audio
= dc
->res_pool
->audios
[i
];
2552 audio
->funcs
->hw_init(audio
);
2555 abm
= dc
->res_pool
->abm
;
2557 abm
->funcs
->init_backlight(abm
);
2558 abm
->funcs
->abm_init(abm
);
2560 #if defined(CONFIG_DRM_AMD_DC_FBC)
2561 if (dc
->fbc_compressor
)
2562 dc
->fbc_compressor
->funcs
->power_up_fbc(dc
->fbc_compressor
);
2567 void dce110_fill_display_configs(
2568 const struct dc_state
*context
,
2569 struct dm_pp_display_configuration
*pp_display_cfg
)
2574 for (j
= 0; j
< context
->stream_count
; j
++) {
2577 const struct dc_stream_state
*stream
= context
->streams
[j
];
2578 struct dm_pp_single_disp_config
*cfg
=
2579 &pp_display_cfg
->disp_configs
[num_cfgs
];
2580 const struct pipe_ctx
*pipe_ctx
= NULL
;
2582 for (k
= 0; k
< MAX_PIPES
; k
++)
2583 if (stream
== context
->res_ctx
.pipe_ctx
[k
].stream
) {
2584 pipe_ctx
= &context
->res_ctx
.pipe_ctx
[k
];
2588 ASSERT(pipe_ctx
!= NULL
);
2591 cfg
->signal
= pipe_ctx
->stream
->signal
;
2592 cfg
->pipe_idx
= pipe_ctx
->pipe_idx
;
2593 cfg
->src_height
= stream
->src
.height
;
2594 cfg
->src_width
= stream
->src
.width
;
2595 cfg
->ddi_channel_mapping
=
2596 stream
->sink
->link
->ddi_channel_mapping
.raw
;
2598 stream
->sink
->link
->link_enc
->transmitter
;
2599 cfg
->link_settings
.lane_count
=
2600 stream
->sink
->link
->cur_link_settings
.lane_count
;
2601 cfg
->link_settings
.link_rate
=
2602 stream
->sink
->link
->cur_link_settings
.link_rate
;
2603 cfg
->link_settings
.link_spread
=
2604 stream
->sink
->link
->cur_link_settings
.link_spread
;
2605 cfg
->sym_clock
= stream
->phy_pix_clk
;
2606 /* Round v_refresh*/
2607 cfg
->v_refresh
= stream
->timing
.pix_clk_khz
* 1000;
2608 cfg
->v_refresh
/= stream
->timing
.h_total
;
2609 cfg
->v_refresh
= (cfg
->v_refresh
+ stream
->timing
.v_total
/ 2)
2610 / stream
->timing
.v_total
;
2613 pp_display_cfg
->display_count
= num_cfgs
;
2616 uint32_t dce110_get_min_vblank_time_us(const struct dc_state
*context
)
2619 uint32_t min_vertical_blank_time
= -1;
2621 for (j
= 0; j
< context
->stream_count
; j
++) {
2622 struct dc_stream_state
*stream
= context
->streams
[j
];
2623 uint32_t vertical_blank_in_pixels
= 0;
2624 uint32_t vertical_blank_time
= 0;
2626 vertical_blank_in_pixels
= stream
->timing
.h_total
*
2627 (stream
->timing
.v_total
2628 - stream
->timing
.v_addressable
);
2630 vertical_blank_time
= vertical_blank_in_pixels
2631 * 1000 / stream
->timing
.pix_clk_khz
;
2633 if (min_vertical_blank_time
> vertical_blank_time
)
2634 min_vertical_blank_time
= vertical_blank_time
;
2637 return min_vertical_blank_time
;
2640 static int determine_sclk_from_bounding_box(
2641 const struct dc
*dc
,
2647 * Some asics do not give us sclk levels, so we just report the actual
2650 if (dc
->sclk_lvls
.num_levels
== 0)
2651 return required_sclk
;
2653 for (i
= 0; i
< dc
->sclk_lvls
.num_levels
; i
++) {
2654 if (dc
->sclk_lvls
.clocks_in_khz
[i
] >= required_sclk
)
2655 return dc
->sclk_lvls
.clocks_in_khz
[i
];
2658 * even maximum level could not satisfy requirement, this
2659 * is unexpected at this stage, should have been caught at
2663 return dc
->sclk_lvls
.clocks_in_khz
[dc
->sclk_lvls
.num_levels
- 1];
2666 static void pplib_apply_display_requirements(
2668 struct dc_state
*context
)
2670 struct dm_pp_display_configuration
*pp_display_cfg
= &context
->pp_display_cfg
;
2672 pp_display_cfg
->all_displays_in_sync
=
2673 context
->bw
.dce
.all_displays_in_sync
;
2674 pp_display_cfg
->nb_pstate_switch_disable
=
2675 context
->bw
.dce
.nbp_state_change_enable
== false;
2676 pp_display_cfg
->cpu_cc6_disable
=
2677 context
->bw
.dce
.cpuc_state_change_enable
== false;
2678 pp_display_cfg
->cpu_pstate_disable
=
2679 context
->bw
.dce
.cpup_state_change_enable
== false;
2680 pp_display_cfg
->cpu_pstate_separation_time
=
2681 context
->bw
.dce
.blackout_recovery_time_us
;
2683 pp_display_cfg
->min_memory_clock_khz
= context
->bw
.dce
.yclk_khz
2684 / MEMORY_TYPE_MULTIPLIER
;
2686 pp_display_cfg
->min_engine_clock_khz
= determine_sclk_from_bounding_box(
2688 context
->bw
.dce
.sclk_khz
);
2690 pp_display_cfg
->min_dcfclock_khz
= pp_display_cfg
->min_engine_clock_khz
;
2692 pp_display_cfg
->min_engine_clock_deep_sleep_khz
2693 = context
->bw
.dce
.sclk_deep_sleep_khz
;
2695 pp_display_cfg
->avail_mclk_switch_time_us
=
2696 dce110_get_min_vblank_time_us(context
);
2698 pp_display_cfg
->avail_mclk_switch_time_in_disp_active_us
= 0;
2700 pp_display_cfg
->disp_clk_khz
= context
->bw
.dce
.dispclk_khz
;
2702 dce110_fill_display_configs(context
, pp_display_cfg
);
2704 /* TODO: is this still applicable?*/
2705 if (pp_display_cfg
->display_count
== 1) {
2706 const struct dc_crtc_timing
*timing
=
2707 &context
->streams
[0]->timing
;
2709 pp_display_cfg
->crtc_index
=
2710 pp_display_cfg
->disp_configs
[0].pipe_idx
;
2711 pp_display_cfg
->line_time_in_us
= timing
->h_total
* 1000
2712 / timing
->pix_clk_khz
;
2715 if (memcmp(&dc
->prev_display_config
, pp_display_cfg
, sizeof(
2716 struct dm_pp_display_configuration
)) != 0)
2717 dm_pp_apply_display_requirements(dc
->ctx
, pp_display_cfg
);
2719 dc
->prev_display_config
= *pp_display_cfg
;
2722 static void dce110_set_bandwidth(
2724 struct dc_state
*context
,
2725 bool decrease_allowed
)
2727 dce110_set_displaymarks(dc
, context
);
2729 if (decrease_allowed
|| context
->bw
.dce
.dispclk_khz
> dc
->current_state
->bw
.dce
.dispclk_khz
) {
2730 dc
->res_pool
->display_clock
->funcs
->set_clock(
2731 dc
->res_pool
->display_clock
,
2732 context
->bw
.dce
.dispclk_khz
* 115 / 100);
2733 dc
->current_state
->bw
.dce
.dispclk_khz
= context
->bw
.dce
.dispclk_khz
;
2736 pplib_apply_display_requirements(dc
, context
);
2739 static void dce110_program_front_end_for_pipe(
2740 struct dc
*dc
, struct pipe_ctx
*pipe_ctx
)
2742 struct mem_input
*mi
= pipe_ctx
->plane_res
.mi
;
2743 struct pipe_ctx
*old_pipe
= NULL
;
2744 struct dc_plane_state
*plane_state
= pipe_ctx
->plane_state
;
2745 struct xfm_grph_csc_adjustment adjust
;
2746 struct out_csc_color_matrix tbl_entry
;
2747 struct pipe_ctx
*cur_pipe_ctx
=
2748 &dc
->current_state
->res_ctx
.pipe_ctx
[pipe_ctx
->pipe_idx
];
2751 memset(&tbl_entry
, 0, sizeof(tbl_entry
));
2753 if (dc
->current_state
)
2754 old_pipe
= &dc
->current_state
->res_ctx
.pipe_ctx
[pipe_ctx
->pipe_idx
];
2756 memset(&adjust
, 0, sizeof(adjust
));
2757 adjust
.gamut_adjust_type
= GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS
;
2759 dce_enable_fe_clock(dc
->hwseq
, pipe_ctx
->pipe_idx
, true);
2761 set_default_colors(pipe_ctx
);
2762 if (pipe_ctx
->stream
->csc_color_matrix
.enable_adjustment
2764 tbl_entry
.color_space
=
2765 pipe_ctx
->stream
->output_color_space
;
2767 for (i
= 0; i
< 12; i
++)
2768 tbl_entry
.regval
[i
] =
2769 pipe_ctx
->stream
->csc_color_matrix
.matrix
[i
];
2771 pipe_ctx
->plane_res
.xfm
->funcs
->opp_set_csc_adjustment
2772 (pipe_ctx
->plane_res
.xfm
, &tbl_entry
);
2775 if (pipe_ctx
->stream
->gamut_remap_matrix
.enable_remap
== true) {
2776 adjust
.gamut_adjust_type
= GRAPHICS_GAMUT_ADJUST_TYPE_SW
;
2777 adjust
.temperature_matrix
[0] =
2779 gamut_remap_matrix
.matrix
[0];
2780 adjust
.temperature_matrix
[1] =
2782 gamut_remap_matrix
.matrix
[1];
2783 adjust
.temperature_matrix
[2] =
2785 gamut_remap_matrix
.matrix
[2];
2786 adjust
.temperature_matrix
[3] =
2788 gamut_remap_matrix
.matrix
[4];
2789 adjust
.temperature_matrix
[4] =
2791 gamut_remap_matrix
.matrix
[5];
2792 adjust
.temperature_matrix
[5] =
2794 gamut_remap_matrix
.matrix
[6];
2795 adjust
.temperature_matrix
[6] =
2797 gamut_remap_matrix
.matrix
[8];
2798 adjust
.temperature_matrix
[7] =
2800 gamut_remap_matrix
.matrix
[9];
2801 adjust
.temperature_matrix
[8] =
2803 gamut_remap_matrix
.matrix
[10];
2806 pipe_ctx
->plane_res
.xfm
->funcs
->transform_set_gamut_remap(pipe_ctx
->plane_res
.xfm
, &adjust
);
2808 pipe_ctx
->plane_res
.scl_data
.lb_params
.alpha_en
= pipe_ctx
->bottom_pipe
!= 0;
2810 program_scaler(dc
, pipe_ctx
);
2812 #if defined(CONFIG_DRM_AMD_DC_FBC)
2813 if (dc
->fbc_compressor
&& old_pipe
->stream
) {
2814 if (plane_state
->tiling_info
.gfx8
.array_mode
== DC_ARRAY_LINEAR_GENERAL
)
2815 dc
->fbc_compressor
->funcs
->disable_fbc(dc
->fbc_compressor
);
2817 enable_fbc(dc
, dc
->current_state
);
2821 mi
->funcs
->mem_input_program_surface_config(
2823 plane_state
->format
,
2824 &plane_state
->tiling_info
,
2825 &plane_state
->plane_size
,
2826 plane_state
->rotation
,
2829 if (mi
->funcs
->set_blank
)
2830 mi
->funcs
->set_blank(mi
, pipe_ctx
->plane_state
->visible
);
2832 if (dc
->config
.gpu_vm_support
)
2833 mi
->funcs
->mem_input_program_pte_vm(
2834 pipe_ctx
->plane_res
.mi
,
2835 plane_state
->format
,
2836 &plane_state
->tiling_info
,
2837 plane_state
->rotation
);
2839 /* Moved programming gamma from dc to hwss */
2840 if (cur_pipe_ctx
->plane_state
!= pipe_ctx
->plane_state
) {
2841 dc
->hwss
.set_input_transfer_func(
2842 pipe_ctx
, pipe_ctx
->plane_state
);
2843 dc
->hwss
.set_output_transfer_func(
2844 pipe_ctx
, pipe_ctx
->stream
);
2847 dm_logger_write(dc
->ctx
->logger
, LOG_SURFACE
,
2848 "Pipe:%d 0x%x: addr hi:0x%x, "
2851 " %d; dst: %d, %d, %d, %d;"
2852 "clip: %d, %d, %d, %d\n",
2854 pipe_ctx
->plane_state
,
2855 pipe_ctx
->plane_state
->address
.grph
.addr
.high_part
,
2856 pipe_ctx
->plane_state
->address
.grph
.addr
.low_part
,
2857 pipe_ctx
->plane_state
->src_rect
.x
,
2858 pipe_ctx
->plane_state
->src_rect
.y
,
2859 pipe_ctx
->plane_state
->src_rect
.width
,
2860 pipe_ctx
->plane_state
->src_rect
.height
,
2861 pipe_ctx
->plane_state
->dst_rect
.x
,
2862 pipe_ctx
->plane_state
->dst_rect
.y
,
2863 pipe_ctx
->plane_state
->dst_rect
.width
,
2864 pipe_ctx
->plane_state
->dst_rect
.height
,
2865 pipe_ctx
->plane_state
->clip_rect
.x
,
2866 pipe_ctx
->plane_state
->clip_rect
.y
,
2867 pipe_ctx
->plane_state
->clip_rect
.width
,
2868 pipe_ctx
->plane_state
->clip_rect
.height
);
2870 dm_logger_write(dc
->ctx
->logger
, LOG_SURFACE
,
2871 "Pipe %d: width, height, x, y\n"
2872 "viewport:%d, %d, %d, %d\n"
2873 "recout: %d, %d, %d, %d\n",
2875 pipe_ctx
->plane_res
.scl_data
.viewport
.width
,
2876 pipe_ctx
->plane_res
.scl_data
.viewport
.height
,
2877 pipe_ctx
->plane_res
.scl_data
.viewport
.x
,
2878 pipe_ctx
->plane_res
.scl_data
.viewport
.y
,
2879 pipe_ctx
->plane_res
.scl_data
.recout
.width
,
2880 pipe_ctx
->plane_res
.scl_data
.recout
.height
,
2881 pipe_ctx
->plane_res
.scl_data
.recout
.x
,
2882 pipe_ctx
->plane_res
.scl_data
.recout
.y
);
2885 static void dce110_apply_ctx_for_surface(
2887 const struct dc_stream_state
*stream
,
2889 struct dc_state
*context
)
2893 if (num_planes
== 0)
2896 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
2897 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
2898 struct pipe_ctx
*old_pipe_ctx
= &dc
->current_state
->res_ctx
.pipe_ctx
[i
];
2900 if (stream
== pipe_ctx
->stream
) {
2901 if (!pipe_ctx
->top_pipe
&&
2902 (pipe_ctx
->plane_state
|| old_pipe_ctx
->plane_state
))
2903 dc
->hwss
.pipe_control_lock(dc
, pipe_ctx
, true);
2907 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
2908 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
2910 if (pipe_ctx
->stream
!= stream
)
2913 /* Need to allocate mem before program front end for Fiji */
2914 if (pipe_ctx
->plane_res
.mi
!= NULL
)
2915 pipe_ctx
->plane_res
.mi
->funcs
->allocate_mem_input(
2916 pipe_ctx
->plane_res
.mi
,
2917 pipe_ctx
->stream
->timing
.h_total
,
2918 pipe_ctx
->stream
->timing
.v_total
,
2919 pipe_ctx
->stream
->timing
.pix_clk_khz
,
2920 context
->stream_count
);
2922 dce110_program_front_end_for_pipe(dc
, pipe_ctx
);
2924 dc
->hwss
.update_plane_addr(dc
, pipe_ctx
);
2926 program_surface_visibility(dc
, pipe_ctx
);
2930 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
2931 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
2932 struct pipe_ctx
*old_pipe_ctx
= &dc
->current_state
->res_ctx
.pipe_ctx
[i
];
2934 if ((stream
== pipe_ctx
->stream
) &&
2935 (!pipe_ctx
->top_pipe
) &&
2936 (pipe_ctx
->plane_state
|| old_pipe_ctx
->plane_state
))
2937 dc
->hwss
.pipe_control_lock(dc
, pipe_ctx
, false);
2941 static void dce110_power_down_fe(struct dc
*dc
, int fe_idx
)
2943 /* Do not power down fe when stream is active on dce*/
2944 if (dc
->current_state
->res_ctx
.pipe_ctx
[fe_idx
].stream
)
2947 dc
->hwss
.enable_display_power_gating(
2948 dc
, fe_idx
, dc
->ctx
->dc_bios
, PIPE_GATING_CONTROL_ENABLE
);
2950 dc
->res_pool
->transforms
[fe_idx
]->funcs
->transform_reset(
2951 dc
->res_pool
->transforms
[fe_idx
]);
2954 static void dce110_wait_for_mpcc_disconnect(
2956 struct resource_pool
*res_pool
,
2957 struct pipe_ctx
*pipe_ctx
)
2962 static void program_csc_matrix(struct pipe_ctx
*pipe_ctx
,
2963 enum dc_color_space colorspace
,
2967 struct out_csc_color_matrix tbl_entry
;
2969 if (pipe_ctx
->stream
->csc_color_matrix
.enable_adjustment
2971 enum dc_color_space color_space
=
2972 pipe_ctx
->stream
->output_color_space
;
2974 //uint16_t matrix[12];
2975 for (i
= 0; i
< 12; i
++)
2976 tbl_entry
.regval
[i
] = pipe_ctx
->stream
->csc_color_matrix
.matrix
[i
];
2978 tbl_entry
.color_space
= color_space
;
2979 //tbl_entry.regval = matrix;
2980 pipe_ctx
->plane_res
.xfm
->funcs
->opp_set_csc_adjustment(pipe_ctx
->plane_res
.xfm
, &tbl_entry
);
2984 static void ready_shared_resources(struct dc
*dc
, struct dc_state
*context
) {}
2986 static void optimize_shared_resources(struct dc
*dc
) {}
2988 static const struct hw_sequencer_funcs dce110_funcs
= {
2989 .program_gamut_remap
= program_gamut_remap
,
2990 .program_csc_matrix
= program_csc_matrix
,
2992 .apply_ctx_to_hw
= dce110_apply_ctx_to_hw
,
2993 .apply_ctx_for_surface
= dce110_apply_ctx_for_surface
,
2994 .set_plane_config
= set_plane_config
,
2995 .update_plane_addr
= update_plane_addr
,
2996 .update_pending_status
= dce110_update_pending_status
,
2997 .set_input_transfer_func
= dce110_set_input_transfer_func
,
2998 .set_output_transfer_func
= dce110_set_output_transfer_func
,
2999 .power_down
= dce110_power_down
,
3000 .enable_accelerated_mode
= dce110_enable_accelerated_mode
,
3001 .enable_timing_synchronization
= dce110_enable_timing_synchronization
,
3002 .update_info_frame
= dce110_update_info_frame
,
3003 .enable_stream
= dce110_enable_stream
,
3004 .disable_stream
= dce110_disable_stream
,
3005 .unblank_stream
= dce110_unblank_stream
,
3006 .blank_stream
= dce110_blank_stream
,
3007 .enable_display_pipe_clock_gating
= enable_display_pipe_clock_gating
,
3008 .enable_display_power_gating
= dce110_enable_display_power_gating
,
3009 .power_down_front_end
= dce110_power_down_fe
,
3010 .pipe_control_lock
= dce_pipe_control_lock
,
3011 .set_bandwidth
= dce110_set_bandwidth
,
3013 .get_position
= get_position
,
3014 .set_static_screen_control
= set_static_screen_control
,
3015 .reset_hw_ctx_wrap
= dce110_reset_hw_ctx_wrap
,
3016 .prog_pixclk_crtc_otg
= dce110_prog_pixclk_crtc_otg
,
3017 .setup_stereo
= NULL
,
3018 .set_avmute
= dce110_set_avmute
,
3019 .wait_for_mpcc_disconnect
= dce110_wait_for_mpcc_disconnect
,
3020 .ready_shared_resources
= ready_shared_resources
,
3021 .optimize_shared_resources
= optimize_shared_resources
,
3022 .edp_backlight_control
= hwss_edp_backlight_control
,
3023 .edp_power_control
= hwss_edp_power_control
,
3024 .edp_wait_for_hpd_ready
= hwss_edp_wait_for_hpd_ready
,
3027 void dce110_hw_sequencer_construct(struct dc
*dc
)
3029 dc
->hwss
= dce110_funcs
;