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_ARGB8888
:
243 case SURFACE_PIXEL_FORMAT_GRPH_ABGR8888
:
244 prescale_params
->scale
= 0x2020;
246 case SURFACE_PIXEL_FORMAT_GRPH_ARGB2101010
:
247 case SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010
:
248 prescale_params
->scale
= 0x2008;
250 case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616
:
251 case SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616F
:
252 prescale_params
->scale
= 0x2000;
260 static bool dce110_set_input_transfer_func(
261 struct pipe_ctx
*pipe_ctx
,
262 const struct dc_plane_state
*plane_state
)
264 struct input_pixel_processor
*ipp
= pipe_ctx
->plane_res
.ipp
;
265 const struct dc_transfer_func
*tf
= NULL
;
266 struct ipp_prescale_params prescale_params
= { 0 };
272 if (plane_state
->in_transfer_func
)
273 tf
= plane_state
->in_transfer_func
;
275 build_prescale_params(&prescale_params
, plane_state
);
276 ipp
->funcs
->ipp_program_prescale(ipp
, &prescale_params
);
278 if (plane_state
->gamma_correction
&& dce_use_lut(plane_state
))
279 ipp
->funcs
->ipp_program_input_lut(ipp
, plane_state
->gamma_correction
);
282 /* Default case if no input transfer function specified */
283 ipp
->funcs
->ipp_set_degamma(ipp
,
284 IPP_DEGAMMA_MODE_HW_sRGB
);
285 } else if (tf
->type
== TF_TYPE_PREDEFINED
) {
287 case TRANSFER_FUNCTION_SRGB
:
288 ipp
->funcs
->ipp_set_degamma(ipp
,
289 IPP_DEGAMMA_MODE_HW_sRGB
);
291 case TRANSFER_FUNCTION_BT709
:
292 ipp
->funcs
->ipp_set_degamma(ipp
,
293 IPP_DEGAMMA_MODE_HW_xvYCC
);
295 case TRANSFER_FUNCTION_LINEAR
:
296 ipp
->funcs
->ipp_set_degamma(ipp
,
297 IPP_DEGAMMA_MODE_BYPASS
);
299 case TRANSFER_FUNCTION_PQ
:
306 } else if (tf
->type
== TF_TYPE_BYPASS
) {
307 ipp
->funcs
->ipp_set_degamma(ipp
, IPP_DEGAMMA_MODE_BYPASS
);
309 /*TF_TYPE_DISTRIBUTED_POINTS - Not supported in DCE 11*/
316 static bool convert_to_custom_float(
317 struct pwl_result_data
*rgb_resulted
,
318 struct curve_points
*arr_points
,
319 uint32_t hw_points_num
)
321 struct custom_float_format fmt
;
323 struct pwl_result_data
*rgb
= rgb_resulted
;
327 fmt
.exponenta_bits
= 6;
328 fmt
.mantissa_bits
= 12;
331 if (!convert_to_custom_float_format(
334 &arr_points
[0].custom_float_x
)) {
339 if (!convert_to_custom_float_format(
340 arr_points
[0].offset
,
342 &arr_points
[0].custom_float_offset
)) {
347 if (!convert_to_custom_float_format(
350 &arr_points
[0].custom_float_slope
)) {
355 fmt
.mantissa_bits
= 10;
358 if (!convert_to_custom_float_format(
361 &arr_points
[1].custom_float_x
)) {
366 if (!convert_to_custom_float_format(
369 &arr_points
[1].custom_float_y
)) {
374 if (!convert_to_custom_float_format(
377 &arr_points
[2].custom_float_slope
)) {
382 fmt
.mantissa_bits
= 12;
385 while (i
!= hw_points_num
) {
386 if (!convert_to_custom_float_format(
394 if (!convert_to_custom_float_format(
402 if (!convert_to_custom_float_format(
410 if (!convert_to_custom_float_format(
413 &rgb
->delta_red_reg
)) {
418 if (!convert_to_custom_float_format(
421 &rgb
->delta_green_reg
)) {
426 if (!convert_to_custom_float_format(
429 &rgb
->delta_blue_reg
)) {
441 static bool dce110_translate_regamma_to_hw_format(const struct dc_transfer_func
442 *output_tf
, struct pwl_params
*regamma_params
)
444 struct curve_points
*arr_points
;
445 struct pwl_result_data
*rgb_resulted
;
446 struct pwl_result_data
*rgb
;
447 struct pwl_result_data
*rgb_plus_1
;
448 struct fixed31_32 y_r
;
449 struct fixed31_32 y_g
;
450 struct fixed31_32 y_b
;
451 struct fixed31_32 y1_min
;
452 struct fixed31_32 y3_max
;
454 int32_t segment_start
, segment_end
;
455 uint32_t i
, j
, k
, seg_distr
[16], increment
, start_index
, hw_points
;
457 if (output_tf
== NULL
|| regamma_params
== NULL
||
458 output_tf
->type
== TF_TYPE_BYPASS
)
461 arr_points
= regamma_params
->arr_points
;
462 rgb_resulted
= regamma_params
->rgb_resulted
;
465 memset(regamma_params
, 0, sizeof(struct pwl_params
));
467 if (output_tf
->tf
== TRANSFER_FUNCTION_PQ
) {
469 * segments are from 2^-11 to 2^5
493 * segment is from 2^-10 to 2^0
516 for (k
= 0; k
< 16; k
++) {
517 if (seg_distr
[k
] != -1)
518 hw_points
+= (1 << seg_distr
[k
]);
522 for (k
= 0; k
< (segment_end
- segment_start
); k
++) {
523 increment
= 32 / (1 << seg_distr
[k
]);
524 start_index
= (segment_start
+ k
+ 25) * 32;
525 for (i
= start_index
; i
< start_index
+ 32; i
+= increment
) {
526 if (j
== hw_points
- 1)
528 rgb_resulted
[j
].red
= output_tf
->tf_pts
.red
[i
];
529 rgb_resulted
[j
].green
= output_tf
->tf_pts
.green
[i
];
530 rgb_resulted
[j
].blue
= output_tf
->tf_pts
.blue
[i
];
536 start_index
= (segment_end
+ 25) * 32;
537 rgb_resulted
[hw_points
- 1].red
=
538 output_tf
->tf_pts
.red
[start_index
];
539 rgb_resulted
[hw_points
- 1].green
=
540 output_tf
->tf_pts
.green
[start_index
];
541 rgb_resulted
[hw_points
- 1].blue
=
542 output_tf
->tf_pts
.blue
[start_index
];
544 arr_points
[0].x
= dal_fixed31_32_pow(dal_fixed31_32_from_int(2),
545 dal_fixed31_32_from_int(segment_start
));
546 arr_points
[1].x
= dal_fixed31_32_pow(dal_fixed31_32_from_int(2),
547 dal_fixed31_32_from_int(segment_end
));
548 arr_points
[2].x
= dal_fixed31_32_pow(dal_fixed31_32_from_int(2),
549 dal_fixed31_32_from_int(segment_end
));
551 y_r
= rgb_resulted
[0].red
;
552 y_g
= rgb_resulted
[0].green
;
553 y_b
= rgb_resulted
[0].blue
;
555 y1_min
= dal_fixed31_32_min(y_r
, dal_fixed31_32_min(y_g
, y_b
));
557 arr_points
[0].y
= y1_min
;
558 arr_points
[0].slope
= dal_fixed31_32_div(
562 y_r
= rgb_resulted
[hw_points
- 1].red
;
563 y_g
= rgb_resulted
[hw_points
- 1].green
;
564 y_b
= rgb_resulted
[hw_points
- 1].blue
;
566 /* see comment above, m_arrPoints[1].y should be the Y value for the
567 * region end (m_numOfHwPoints), not last HW point(m_numOfHwPoints - 1)
569 y3_max
= dal_fixed31_32_max(y_r
, dal_fixed31_32_max(y_g
, y_b
));
571 arr_points
[1].y
= y3_max
;
572 arr_points
[2].y
= y3_max
;
574 arr_points
[1].slope
= dal_fixed31_32_zero
;
575 arr_points
[2].slope
= dal_fixed31_32_zero
;
577 if (output_tf
->tf
== TRANSFER_FUNCTION_PQ
) {
578 /* for PQ, we want to have a straight line from last HW X point,
579 * and the slope to be such that we hit 1.0 at 10000 nits.
581 const struct fixed31_32 end_value
=
582 dal_fixed31_32_from_int(125);
584 arr_points
[1].slope
= dal_fixed31_32_div(
585 dal_fixed31_32_sub(dal_fixed31_32_one
, arr_points
[1].y
),
586 dal_fixed31_32_sub(end_value
, arr_points
[1].x
));
587 arr_points
[2].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
));
592 regamma_params
->hw_points_num
= hw_points
;
595 for (k
= 0; k
< 16 && i
< 16; k
++) {
596 if (seg_distr
[k
] != -1) {
597 regamma_params
->arr_curve_points
[k
].segments_num
=
599 regamma_params
->arr_curve_points
[i
].offset
=
600 regamma_params
->arr_curve_points
[k
].
601 offset
+ (1 << seg_distr
[k
]);
606 if (seg_distr
[k
] != -1)
607 regamma_params
->arr_curve_points
[k
].segments_num
=
611 rgb_plus_1
= rgb_resulted
+ 1;
615 while (i
!= hw_points
+ 1) {
616 if (dal_fixed31_32_lt(rgb_plus_1
->red
, rgb
->red
))
617 rgb_plus_1
->red
= rgb
->red
;
618 if (dal_fixed31_32_lt(rgb_plus_1
->green
, rgb
->green
))
619 rgb_plus_1
->green
= rgb
->green
;
620 if (dal_fixed31_32_lt(rgb_plus_1
->blue
, rgb
->blue
))
621 rgb_plus_1
->blue
= rgb
->blue
;
623 rgb
->delta_red
= dal_fixed31_32_sub(
626 rgb
->delta_green
= dal_fixed31_32_sub(
629 rgb
->delta_blue
= dal_fixed31_32_sub(
638 convert_to_custom_float(rgb_resulted
, arr_points
, hw_points
);
643 static bool dce110_set_output_transfer_func(
644 struct pipe_ctx
*pipe_ctx
,
645 const struct dc_stream_state
*stream
)
647 struct transform
*xfm
= pipe_ctx
->plane_res
.xfm
;
649 xfm
->funcs
->opp_power_on_regamma_lut(xfm
, true);
650 xfm
->regamma_params
.hw_points_num
= GAMMA_HW_POINTS_NUM
;
652 if (stream
->out_transfer_func
&&
653 stream
->out_transfer_func
->type
==
654 TF_TYPE_PREDEFINED
&&
655 stream
->out_transfer_func
->tf
==
656 TRANSFER_FUNCTION_SRGB
) {
657 xfm
->funcs
->opp_set_regamma_mode(xfm
, OPP_REGAMMA_SRGB
);
658 } else if (dce110_translate_regamma_to_hw_format(
659 stream
->out_transfer_func
, &xfm
->regamma_params
)) {
660 xfm
->funcs
->opp_program_regamma_pwl(xfm
, &xfm
->regamma_params
);
661 xfm
->funcs
->opp_set_regamma_mode(xfm
, OPP_REGAMMA_USER
);
663 xfm
->funcs
->opp_set_regamma_mode(xfm
, OPP_REGAMMA_BYPASS
);
666 xfm
->funcs
->opp_power_on_regamma_lut(xfm
, false);
671 static enum dc_status
bios_parser_crtc_source_select(
672 struct pipe_ctx
*pipe_ctx
)
675 /* call VBIOS table to set CRTC source for the HW
677 * note: video bios clears all FMT setting here. */
678 struct bp_crtc_source_select crtc_source_select
= {0};
679 const struct dc_sink
*sink
= pipe_ctx
->stream
->sink
;
681 crtc_source_select
.engine_id
= pipe_ctx
->stream_res
.stream_enc
->id
;
682 crtc_source_select
.controller_id
= pipe_ctx
->pipe_idx
+ 1;
683 /*TODO: Need to un-hardcode color depth, dp_audio and account for
684 * the case where signal and sink signal is different (translator
686 crtc_source_select
.signal
= pipe_ctx
->stream
->signal
;
687 crtc_source_select
.enable_dp_audio
= false;
688 crtc_source_select
.sink_signal
= pipe_ctx
->stream
->signal
;
690 switch (pipe_ctx
->stream
->timing
.display_color_depth
) {
691 case COLOR_DEPTH_666
:
692 crtc_source_select
.display_output_bit_depth
= PANEL_6BIT_COLOR
;
694 case COLOR_DEPTH_888
:
695 crtc_source_select
.display_output_bit_depth
= PANEL_8BIT_COLOR
;
697 case COLOR_DEPTH_101010
:
698 crtc_source_select
.display_output_bit_depth
= PANEL_10BIT_COLOR
;
700 case COLOR_DEPTH_121212
:
701 crtc_source_select
.display_output_bit_depth
= PANEL_12BIT_COLOR
;
705 crtc_source_select
.display_output_bit_depth
= PANEL_8BIT_COLOR
;
709 dcb
= sink
->ctx
->dc_bios
;
711 if (BP_RESULT_OK
!= dcb
->funcs
->crtc_source_select(
713 &crtc_source_select
)) {
714 return DC_ERROR_UNEXPECTED
;
720 void dce110_update_info_frame(struct pipe_ctx
*pipe_ctx
)
722 ASSERT(pipe_ctx
->stream
);
724 if (pipe_ctx
->stream_res
.stream_enc
== NULL
)
725 return; /* this is not root pipe */
727 if (dc_is_hdmi_signal(pipe_ctx
->stream
->signal
))
728 pipe_ctx
->stream_res
.stream_enc
->funcs
->update_hdmi_info_packets(
729 pipe_ctx
->stream_res
.stream_enc
,
730 &pipe_ctx
->stream_res
.encoder_info_frame
);
731 else if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
732 pipe_ctx
->stream_res
.stream_enc
->funcs
->update_dp_info_packets(
733 pipe_ctx
->stream_res
.stream_enc
,
734 &pipe_ctx
->stream_res
.encoder_info_frame
);
737 void dce110_enable_stream(struct pipe_ctx
*pipe_ctx
)
739 enum dc_lane_count lane_count
=
740 pipe_ctx
->stream
->sink
->link
->cur_link_settings
.lane_count
;
742 struct dc_crtc_timing
*timing
= &pipe_ctx
->stream
->timing
;
743 struct dc_link
*link
= pipe_ctx
->stream
->sink
->link
;
745 /* 1. update AVI info frame (HDMI, DP)
746 * we always need to update info frame
748 uint32_t active_total_with_borders
;
749 uint32_t early_control
= 0;
750 struct timing_generator
*tg
= pipe_ctx
->stream_res
.tg
;
752 /* TODOFPGA may change to hwss.update_info_frame */
753 dce110_update_info_frame(pipe_ctx
);
754 /* enable early control to avoid corruption on DP monitor*/
755 active_total_with_borders
=
756 timing
->h_addressable
757 + timing
->h_border_left
758 + timing
->h_border_right
;
761 early_control
= active_total_with_borders
% lane_count
;
763 if (early_control
== 0)
764 early_control
= lane_count
;
766 tg
->funcs
->set_early_control(tg
, early_control
);
768 /* enable audio only within mode set */
769 if (pipe_ctx
->stream_res
.audio
!= NULL
) {
770 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
771 pipe_ctx
->stream_res
.stream_enc
->funcs
->dp_audio_enable(pipe_ctx
->stream_res
.stream_enc
);
774 /* For MST, there are multiply stream go to only one link.
775 * connect DIG back_end to front_end while enable_stream and
776 * disconnect them during disable_stream
777 * BY this, it is logic clean to separate stream and link */
778 link
->link_enc
->funcs
->connect_dig_be_to_fe(link
->link_enc
,
779 pipe_ctx
->stream_res
.stream_enc
->id
, true);
783 /*todo: cloned in stream enc, fix*/
784 static bool is_panel_backlight_on(struct dce_hwseq
*hws
)
788 REG_GET(LVTMA_PWRSEQ_CNTL
, LVTMA_BLON
, &value
);
793 static bool is_panel_powered_on(struct dce_hwseq
*hws
)
797 REG_GET(LVTMA_PWRSEQ_STATE
, LVTMA_PWRSEQ_TARGET_STATE_R
, &value
);
801 static enum bp_result
link_transmitter_control(
802 struct dc_bios
*bios
,
803 struct bp_transmitter_control
*cntl
)
805 enum bp_result result
;
807 result
= bios
->funcs
->transmitter_control(bios
, cntl
);
816 void hwss_edp_wait_for_hpd_ready(
817 struct dc_link
*link
,
820 struct dc_context
*ctx
= link
->ctx
;
821 struct graphics_object_id connector
= link
->link_enc
->connector
;
823 bool edp_hpd_high
= false;
824 uint32_t time_elapsed
= 0;
825 uint32_t timeout
= power_up
?
826 PANEL_POWER_UP_TIMEOUT
: PANEL_POWER_DOWN_TIMEOUT
;
828 if (dal_graphics_object_id_get_connector_id(connector
)
829 != CONNECTOR_ID_EDP
) {
836 * From KV, we will not HPD low after turning off VCC -
837 * instead, we will check the SW timer in power_up().
842 * When we power on/off the eDP panel,
843 * we need to wait until SENSE bit is high/low.
847 /* TODO what to do with this? */
848 hpd
= get_hpd_gpio(ctx
->dc_bios
, connector
, ctx
->gpio_service
);
855 dal_gpio_open(hpd
, GPIO_MODE_INTERRUPT
);
857 /* wait until timeout or panel detected */
860 uint32_t detected
= 0;
862 dal_gpio_get_value(hpd
, &detected
);
864 if (!(detected
^ power_up
)) {
869 msleep(HPD_CHECK_INTERVAL
);
871 time_elapsed
+= HPD_CHECK_INTERVAL
;
872 } while (time_elapsed
< timeout
);
876 dal_gpio_destroy_irq(&hpd
);
878 if (false == edp_hpd_high
) {
879 dm_logger_write(ctx
->logger
, LOG_ERROR
,
880 "%s: wait timed out!\n", __func__
);
884 void hwss_edp_power_control(
885 struct dc_link
*link
,
888 struct dc_context
*ctx
= link
->ctx
;
889 struct dce_hwseq
*hwseq
= ctx
->dc
->hwseq
;
890 struct bp_transmitter_control cntl
= { 0 };
891 enum bp_result bp_result
;
894 if (dal_graphics_object_id_get_connector_id(link
->link_enc
->connector
)
895 != CONNECTOR_ID_EDP
) {
900 if (power_up
!= is_panel_powered_on(hwseq
)) {
901 /* Send VBIOS command to prompt eDP panel power */
903 dm_logger_write(ctx
->logger
, LOG_HW_RESUME_S3
,
904 "%s: Panel Power action: %s\n",
905 __func__
, (power_up
? "On":"Off"));
907 cntl
.action
= power_up
?
908 TRANSMITTER_CONTROL_POWER_ON
:
909 TRANSMITTER_CONTROL_POWER_OFF
;
910 cntl
.transmitter
= link
->link_enc
->transmitter
;
911 cntl
.connector_obj_id
= link
->link_enc
->connector
;
912 cntl
.coherent
= false;
913 cntl
.lanes_number
= LANE_COUNT_FOUR
;
914 cntl
.hpd_sel
= link
->link_enc
->hpd_source
;
916 bp_result
= link_transmitter_control(ctx
->dc_bios
, &cntl
);
918 if (bp_result
!= BP_RESULT_OK
)
919 dm_logger_write(ctx
->logger
, LOG_ERROR
,
920 "%s: Panel Power bp_result: %d\n",
921 __func__
, bp_result
);
923 dm_logger_write(ctx
->logger
, LOG_HW_RESUME_S3
,
924 "%s: Skipping Panel Power action: %s\n",
925 __func__
, (power_up
? "On":"Off"));
929 /*todo: cloned in stream enc, fix*/
932 * eDP only. Control the backlight of the eDP panel
934 void hwss_edp_backlight_control(
935 struct dc_link
*link
,
938 struct dc_context
*ctx
= link
->ctx
;
939 struct dce_hwseq
*hws
= ctx
->dc
->hwseq
;
940 struct bp_transmitter_control cntl
= { 0 };
942 if (dal_graphics_object_id_get_connector_id(link
->link_enc
->connector
)
943 != CONNECTOR_ID_EDP
) {
948 if (enable
&& is_panel_backlight_on(hws
)) {
949 dm_logger_write(ctx
->logger
, LOG_HW_RESUME_S3
,
950 "%s: panel already powered up. Do nothing.\n",
955 /* Send VBIOS command to control eDP panel backlight */
957 dm_logger_write(ctx
->logger
, LOG_HW_RESUME_S3
,
958 "%s: backlight action: %s\n",
959 __func__
, (enable
? "On":"Off"));
961 cntl
.action
= enable
?
962 TRANSMITTER_CONTROL_BACKLIGHT_ON
:
963 TRANSMITTER_CONTROL_BACKLIGHT_OFF
;
965 /*cntl.engine_id = ctx->engine;*/
966 cntl
.transmitter
= link
->link_enc
->transmitter
;
967 cntl
.connector_obj_id
= link
->link_enc
->connector
;
969 cntl
.lanes_number
= LANE_COUNT_FOUR
;
970 cntl
.hpd_sel
= link
->link_enc
->hpd_source
;
972 /* For eDP, the following delays might need to be considered
973 * after link training completed:
974 * idle period - min. accounts for required BS-Idle pattern,
975 * max. allows for source frame synchronization);
976 * 50 msec max. delay from valid video data from source
977 * to video on dislpay or backlight enable.
979 * Disable the delay for now.
980 * Enable it in the future if necessary.
982 /* dc_service_sleep_in_milliseconds(50); */
983 link_transmitter_control(ctx
->dc_bios
, &cntl
);
986 void dce110_disable_stream(struct pipe_ctx
*pipe_ctx
, int option
)
988 struct dc_stream_state
*stream
= pipe_ctx
->stream
;
989 struct dc_link
*link
= stream
->sink
->link
;
990 struct dc
*dc
= pipe_ctx
->stream
->ctx
->dc
;
992 if (dc_is_hdmi_signal(pipe_ctx
->stream
->signal
))
993 pipe_ctx
->stream_res
.stream_enc
->funcs
->stop_hdmi_info_packets(
994 pipe_ctx
->stream_res
.stream_enc
);
996 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
997 pipe_ctx
->stream_res
.stream_enc
->funcs
->stop_dp_info_packets(
998 pipe_ctx
->stream_res
.stream_enc
);
1000 pipe_ctx
->stream_res
.stream_enc
->funcs
->audio_mute_control(
1001 pipe_ctx
->stream_res
.stream_enc
, true);
1002 if (pipe_ctx
->stream_res
.audio
) {
1003 pipe_ctx
->stream_res
.audio
->funcs
->az_disable(pipe_ctx
->stream_res
.audio
);
1005 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
1006 pipe_ctx
->stream_res
.stream_enc
->funcs
->dp_audio_disable(
1007 pipe_ctx
->stream_res
.stream_enc
);
1009 pipe_ctx
->stream_res
.stream_enc
->funcs
->hdmi_audio_disable(
1010 pipe_ctx
->stream_res
.stream_enc
);
1011 /*don't free audio if it is from retrain or internal disable stream*/
1012 if (option
== FREE_ACQUIRED_RESOURCE
&& dc
->caps
.dynamic_audio
== true) {
1013 /*we have to dynamic arbitrate the audio endpoints*/
1014 pipe_ctx
->stream_res
.audio
= NULL
;
1015 /*we free the resource, need reset is_audio_acquired*/
1016 update_audio_usage(&dc
->current_state
->res_ctx
, dc
->res_pool
, pipe_ctx
->stream_res
.audio
, false);
1019 /* TODO: notify audio driver for if audio modes list changed
1020 * add audio mode list change flag */
1021 /* dal_audio_disable_azalia_audio_jack_presence(stream->audio,
1022 * stream->stream_engine_id);
1026 /* blank at encoder level */
1027 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
1028 pipe_ctx
->stream_res
.stream_enc
->funcs
->dp_blank(pipe_ctx
->stream_res
.stream_enc
);
1030 link
->link_enc
->funcs
->connect_dig_be_to_fe(
1032 pipe_ctx
->stream_res
.stream_enc
->id
,
1037 void dce110_unblank_stream(struct pipe_ctx
*pipe_ctx
,
1038 struct dc_link_settings
*link_settings
)
1040 struct encoder_unblank_param params
= { { 0 } };
1041 struct dc_stream_state
*stream
= pipe_ctx
->stream
;
1042 struct dc_link
*link
= stream
->sink
->link
;
1044 /* only 3 items below are used by unblank */
1045 params
.pixel_clk_khz
=
1046 pipe_ctx
->stream
->timing
.pix_clk_khz
;
1047 params
.link_settings
.link_rate
= link_settings
->link_rate
;
1049 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
1050 pipe_ctx
->stream_res
.stream_enc
->funcs
->dp_unblank(pipe_ctx
->stream_res
.stream_enc
, ¶ms
);
1052 if (link
->local_sink
&& link
->local_sink
->sink_signal
== SIGNAL_TYPE_EDP
)
1053 link
->dc
->hwss
.edp_backlight_control(link
, true);
1055 void dce110_blank_stream(struct pipe_ctx
*pipe_ctx
)
1057 struct encoder_unblank_param params
= { { 0 } };
1058 struct dc_stream_state
*stream
= pipe_ctx
->stream
;
1059 struct dc_link
*link
= stream
->sink
->link
;
1061 if (link
->local_sink
&& link
->local_sink
->sink_signal
== SIGNAL_TYPE_EDP
)
1062 link
->dc
->hwss
.edp_backlight_control(link
, false);
1064 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
1065 pipe_ctx
->stream_res
.stream_enc
->funcs
->dp_blank(pipe_ctx
->stream_res
.stream_enc
);
1069 void dce110_set_avmute(struct pipe_ctx
*pipe_ctx
, bool enable
)
1071 if (pipe_ctx
!= NULL
&& pipe_ctx
->stream_res
.stream_enc
!= NULL
)
1072 pipe_ctx
->stream_res
.stream_enc
->funcs
->set_avmute(pipe_ctx
->stream_res
.stream_enc
, enable
);
1075 static enum audio_dto_source
translate_to_dto_source(enum controller_id crtc_id
)
1078 case CONTROLLER_ID_D0
:
1079 return DTO_SOURCE_ID0
;
1080 case CONTROLLER_ID_D1
:
1081 return DTO_SOURCE_ID1
;
1082 case CONTROLLER_ID_D2
:
1083 return DTO_SOURCE_ID2
;
1084 case CONTROLLER_ID_D3
:
1085 return DTO_SOURCE_ID3
;
1086 case CONTROLLER_ID_D4
:
1087 return DTO_SOURCE_ID4
;
1088 case CONTROLLER_ID_D5
:
1089 return DTO_SOURCE_ID5
;
1091 return DTO_SOURCE_UNKNOWN
;
1095 static void build_audio_output(
1096 struct dc_state
*state
,
1097 const struct pipe_ctx
*pipe_ctx
,
1098 struct audio_output
*audio_output
)
1100 const struct dc_stream_state
*stream
= pipe_ctx
->stream
;
1101 audio_output
->engine_id
= pipe_ctx
->stream_res
.stream_enc
->id
;
1103 audio_output
->signal
= pipe_ctx
->stream
->signal
;
1105 /* audio_crtc_info */
1107 audio_output
->crtc_info
.h_total
=
1108 stream
->timing
.h_total
;
1111 * Audio packets are sent during actual CRTC blank physical signal, we
1112 * need to specify actual active signal portion
1114 audio_output
->crtc_info
.h_active
=
1115 stream
->timing
.h_addressable
1116 + stream
->timing
.h_border_left
1117 + stream
->timing
.h_border_right
;
1119 audio_output
->crtc_info
.v_active
=
1120 stream
->timing
.v_addressable
1121 + stream
->timing
.v_border_top
1122 + stream
->timing
.v_border_bottom
;
1124 audio_output
->crtc_info
.pixel_repetition
= 1;
1126 audio_output
->crtc_info
.interlaced
=
1127 stream
->timing
.flags
.INTERLACE
;
1129 audio_output
->crtc_info
.refresh_rate
=
1130 (stream
->timing
.pix_clk_khz
*1000)/
1131 (stream
->timing
.h_total
*stream
->timing
.v_total
);
1133 audio_output
->crtc_info
.color_depth
=
1134 stream
->timing
.display_color_depth
;
1136 audio_output
->crtc_info
.requested_pixel_clock
=
1137 pipe_ctx
->stream_res
.pix_clk_params
.requested_pix_clk
;
1139 audio_output
->crtc_info
.calculated_pixel_clock
=
1140 pipe_ctx
->stream_res
.pix_clk_params
.requested_pix_clk
;
1142 /*for HDMI, audio ACR is with deep color ratio factor*/
1143 if (dc_is_hdmi_signal(pipe_ctx
->stream
->signal
) &&
1144 audio_output
->crtc_info
.requested_pixel_clock
==
1145 stream
->timing
.pix_clk_khz
) {
1146 if (pipe_ctx
->stream_res
.pix_clk_params
.pixel_encoding
== PIXEL_ENCODING_YCBCR420
) {
1147 audio_output
->crtc_info
.requested_pixel_clock
=
1148 audio_output
->crtc_info
.requested_pixel_clock
/2;
1149 audio_output
->crtc_info
.calculated_pixel_clock
=
1150 pipe_ctx
->stream_res
.pix_clk_params
.requested_pix_clk
/2;
1155 if (pipe_ctx
->stream
->signal
== SIGNAL_TYPE_DISPLAY_PORT
||
1156 pipe_ctx
->stream
->signal
== SIGNAL_TYPE_DISPLAY_PORT_MST
) {
1157 audio_output
->pll_info
.dp_dto_source_clock_in_khz
=
1158 state
->dis_clk
->funcs
->get_dp_ref_clk_frequency(
1162 audio_output
->pll_info
.feed_back_divider
=
1163 pipe_ctx
->pll_settings
.feedback_divider
;
1165 audio_output
->pll_info
.dto_source
=
1166 translate_to_dto_source(
1167 pipe_ctx
->pipe_idx
+ 1);
1169 /* TODO hard code to enable for now. Need get from stream */
1170 audio_output
->pll_info
.ss_enabled
= true;
1172 audio_output
->pll_info
.ss_percentage
=
1173 pipe_ctx
->pll_settings
.ss_percentage
;
1176 static void get_surface_visual_confirm_color(const struct pipe_ctx
*pipe_ctx
,
1177 struct tg_color
*color
)
1179 uint32_t color_value
= MAX_TG_COLOR_VALUE
* (4 - pipe_ctx
->pipe_idx
) / 4;
1181 switch (pipe_ctx
->plane_res
.scl_data
.format
) {
1182 case PIXEL_FORMAT_ARGB8888
:
1183 /* set boarder color to red */
1184 color
->color_r_cr
= color_value
;
1187 case PIXEL_FORMAT_ARGB2101010
:
1188 /* set boarder color to blue */
1189 color
->color_b_cb
= color_value
;
1191 case PIXEL_FORMAT_420BPP8
:
1192 /* set boarder color to green */
1193 color
->color_g_y
= color_value
;
1195 case PIXEL_FORMAT_420BPP10
:
1196 /* set boarder color to yellow */
1197 color
->color_g_y
= color_value
;
1198 color
->color_r_cr
= color_value
;
1200 case PIXEL_FORMAT_FP16
:
1201 /* set boarder color to white */
1202 color
->color_r_cr
= color_value
;
1203 color
->color_b_cb
= color_value
;
1204 color
->color_g_y
= color_value
;
1211 static void program_scaler(const struct dc
*dc
,
1212 const struct pipe_ctx
*pipe_ctx
)
1214 struct tg_color color
= {0};
1216 #if defined(CONFIG_DRM_AMD_DC_DCN1_0)
1218 if (pipe_ctx
->plane_res
.xfm
->funcs
->transform_set_pixel_storage_depth
== NULL
)
1222 if (dc
->debug
.surface_visual_confirm
)
1223 get_surface_visual_confirm_color(pipe_ctx
, &color
);
1225 color_space_to_black_color(dc
,
1226 pipe_ctx
->stream
->output_color_space
,
1229 pipe_ctx
->plane_res
.xfm
->funcs
->transform_set_pixel_storage_depth(
1230 pipe_ctx
->plane_res
.xfm
,
1231 pipe_ctx
->plane_res
.scl_data
.lb_params
.depth
,
1232 &pipe_ctx
->stream
->bit_depth_params
);
1234 if (pipe_ctx
->stream_res
.tg
->funcs
->set_overscan_blank_color
)
1235 pipe_ctx
->stream_res
.tg
->funcs
->set_overscan_blank_color(
1236 pipe_ctx
->stream_res
.tg
,
1239 pipe_ctx
->plane_res
.xfm
->funcs
->transform_set_scaler(pipe_ctx
->plane_res
.xfm
,
1240 &pipe_ctx
->plane_res
.scl_data
);
1243 static enum dc_status
dce110_prog_pixclk_crtc_otg(
1244 struct pipe_ctx
*pipe_ctx
,
1245 struct dc_state
*context
,
1248 struct dc_stream_state
*stream
= pipe_ctx
->stream
;
1249 struct pipe_ctx
*pipe_ctx_old
= &dc
->current_state
->res_ctx
.
1250 pipe_ctx
[pipe_ctx
->pipe_idx
];
1251 struct tg_color black_color
= {0};
1253 if (!pipe_ctx_old
->stream
) {
1255 /* program blank color */
1256 color_space_to_black_color(dc
,
1257 stream
->output_color_space
, &black_color
);
1258 pipe_ctx
->stream_res
.tg
->funcs
->set_blank_color(
1259 pipe_ctx
->stream_res
.tg
,
1263 * Must blank CRTC after disabling power gating and before any
1264 * programming, otherwise CRTC will be hung in bad state
1266 pipe_ctx
->stream_res
.tg
->funcs
->set_blank(pipe_ctx
->stream_res
.tg
, true);
1268 if (false == pipe_ctx
->clock_source
->funcs
->program_pix_clk(
1269 pipe_ctx
->clock_source
,
1270 &pipe_ctx
->stream_res
.pix_clk_params
,
1271 &pipe_ctx
->pll_settings
)) {
1272 BREAK_TO_DEBUGGER();
1273 return DC_ERROR_UNEXPECTED
;
1276 pipe_ctx
->stream_res
.tg
->funcs
->program_timing(
1277 pipe_ctx
->stream_res
.tg
,
1281 pipe_ctx
->stream_res
.tg
->funcs
->set_static_screen_control(
1282 pipe_ctx
->stream_res
.tg
,
1286 if (!pipe_ctx_old
->stream
) {
1287 if (false == pipe_ctx
->stream_res
.tg
->funcs
->enable_crtc(
1288 pipe_ctx
->stream_res
.tg
)) {
1289 BREAK_TO_DEBUGGER();
1290 return DC_ERROR_UNEXPECTED
;
1299 static enum dc_status
apply_single_controller_ctx_to_hw(
1300 struct pipe_ctx
*pipe_ctx
,
1301 struct dc_state
*context
,
1304 struct dc_stream_state
*stream
= pipe_ctx
->stream
;
1305 struct pipe_ctx
*pipe_ctx_old
= &dc
->current_state
->res_ctx
.
1306 pipe_ctx
[pipe_ctx
->pipe_idx
];
1309 dc
->hwss
.prog_pixclk_crtc_otg(pipe_ctx
, context
, dc
);
1311 /* FPGA does not program backend */
1312 if (IS_FPGA_MAXIMUS_DC(dc
->ctx
->dce_environment
)) {
1313 pipe_ctx
->stream_res
.opp
->funcs
->opp_set_dyn_expansion(
1314 pipe_ctx
->stream_res
.opp
,
1315 COLOR_SPACE_YCBCR601
,
1316 stream
->timing
.display_color_depth
,
1317 pipe_ctx
->stream
->signal
);
1319 pipe_ctx
->stream_res
.opp
->funcs
->opp_program_fmt(
1320 pipe_ctx
->stream_res
.opp
,
1321 &stream
->bit_depth_params
,
1325 /* TODO: move to stream encoder */
1326 if (pipe_ctx
->stream
->signal
!= SIGNAL_TYPE_VIRTUAL
)
1327 if (DC_OK
!= bios_parser_crtc_source_select(pipe_ctx
)) {
1328 BREAK_TO_DEBUGGER();
1329 return DC_ERROR_UNEXPECTED
;
1331 pipe_ctx
->stream_res
.opp
->funcs
->opp_set_dyn_expansion(
1332 pipe_ctx
->stream_res
.opp
,
1333 COLOR_SPACE_YCBCR601
,
1334 stream
->timing
.display_color_depth
,
1335 pipe_ctx
->stream
->signal
);
1337 if (pipe_ctx
->stream
->signal
!= SIGNAL_TYPE_VIRTUAL
)
1338 stream
->sink
->link
->link_enc
->funcs
->setup(
1339 stream
->sink
->link
->link_enc
,
1340 pipe_ctx
->stream
->signal
);
1342 if (pipe_ctx
->stream
->signal
!= SIGNAL_TYPE_VIRTUAL
)
1343 pipe_ctx
->stream_res
.stream_enc
->funcs
->setup_stereo_sync(
1344 pipe_ctx
->stream_res
.stream_enc
,
1345 pipe_ctx
->stream_res
.tg
->inst
,
1346 stream
->timing
.timing_3d_format
!= TIMING_3D_FORMAT_NONE
);
1349 pipe_ctx
->stream_res
.opp
->funcs
->opp_program_fmt(
1350 pipe_ctx
->stream_res
.opp
,
1351 &stream
->bit_depth_params
,
1354 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
1355 pipe_ctx
->stream_res
.stream_enc
->funcs
->dp_set_stream_attribute(
1356 pipe_ctx
->stream_res
.stream_enc
,
1358 stream
->output_color_space
);
1360 if (dc_is_hdmi_signal(pipe_ctx
->stream
->signal
))
1361 pipe_ctx
->stream_res
.stream_enc
->funcs
->hdmi_set_stream_attribute(
1362 pipe_ctx
->stream_res
.stream_enc
,
1364 stream
->phy_pix_clk
,
1365 pipe_ctx
->stream_res
.audio
!= NULL
);
1367 if (dc_is_dvi_signal(pipe_ctx
->stream
->signal
))
1368 pipe_ctx
->stream_res
.stream_enc
->funcs
->dvi_set_stream_attribute(
1369 pipe_ctx
->stream_res
.stream_enc
,
1371 (pipe_ctx
->stream
->signal
== SIGNAL_TYPE_DVI_DUAL_LINK
) ?
1374 resource_build_info_frame(pipe_ctx
);
1375 dce110_update_info_frame(pipe_ctx
);
1376 if (!pipe_ctx_old
->stream
) {
1377 if (!pipe_ctx
->stream
->dpms_off
)
1378 core_link_enable_stream(context
, pipe_ctx
);
1381 pipe_ctx
->plane_res
.scl_data
.lb_params
.alpha_en
= pipe_ctx
->bottom_pipe
!= 0;
1383 pipe_ctx
->stream
->sink
->link
->psr_enabled
= false;
1388 /******************************************************************************/
1390 static void power_down_encoders(struct dc
*dc
)
1393 enum connector_id connector_id
;
1394 enum signal_type signal
= SIGNAL_TYPE_NONE
;
1396 /* do not know BIOS back-front mapping, simply blank all. It will not
1399 for (i
= 0; i
< dc
->res_pool
->stream_enc_count
; i
++) {
1400 dc
->res_pool
->stream_enc
[i
]->funcs
->dp_blank(
1401 dc
->res_pool
->stream_enc
[i
]);
1404 for (i
= 0; i
< dc
->link_count
; i
++) {
1405 connector_id
= dal_graphics_object_id_get_connector_id(dc
->links
[i
]->link_id
);
1406 if ((connector_id
== CONNECTOR_ID_DISPLAY_PORT
) ||
1407 (connector_id
== CONNECTOR_ID_EDP
)) {
1409 if (!dc
->links
[i
]->wa_flags
.dp_keep_receiver_powered
)
1410 dp_receiver_power_ctrl(dc
->links
[i
], false);
1411 if (connector_id
== CONNECTOR_ID_EDP
)
1412 signal
= SIGNAL_TYPE_EDP
;
1415 dc
->links
[i
]->link_enc
->funcs
->disable_output(
1416 dc
->links
[i
]->link_enc
, signal
);
1420 static void power_down_controllers(struct dc
*dc
)
1424 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
1425 dc
->res_pool
->timing_generators
[i
]->funcs
->disable_crtc(
1426 dc
->res_pool
->timing_generators
[i
]);
1430 static void power_down_clock_sources(struct dc
*dc
)
1434 if (dc
->res_pool
->dp_clock_source
->funcs
->cs_power_down(
1435 dc
->res_pool
->dp_clock_source
) == false)
1436 dm_error("Failed to power down pll! (dp clk src)\n");
1438 for (i
= 0; i
< dc
->res_pool
->clk_src_count
; i
++) {
1439 if (dc
->res_pool
->clock_sources
[i
]->funcs
->cs_power_down(
1440 dc
->res_pool
->clock_sources
[i
]) == false)
1441 dm_error("Failed to power down pll! (clk src index=%d)\n", i
);
1445 static void power_down_all_hw_blocks(struct dc
*dc
)
1447 power_down_encoders(dc
);
1449 power_down_controllers(dc
);
1451 power_down_clock_sources(dc
);
1453 #if defined(CONFIG_DRM_AMD_DC_FBC)
1454 if (dc
->fbc_compressor
)
1455 dc
->fbc_compressor
->funcs
->disable_fbc(dc
->fbc_compressor
);
1459 static void disable_vga_and_power_gate_all_controllers(
1463 struct timing_generator
*tg
;
1464 struct dc_context
*ctx
= dc
->ctx
;
1466 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
1467 tg
= dc
->res_pool
->timing_generators
[i
];
1469 if (tg
->funcs
->disable_vga
)
1470 tg
->funcs
->disable_vga(tg
);
1472 /* Enable CLOCK gating for each pipe BEFORE controller
1474 enable_display_pipe_clock_gating(ctx
,
1477 dc
->hwss
.power_down_front_end(dc
, i
);
1482 * When ASIC goes from VBIOS/VGA mode to driver/accelerated mode we need:
1483 * 1. Power down all DC HW blocks
1484 * 2. Disable VGA engine on all controllers
1485 * 3. Enable power gating for controller
1486 * 4. Set acc_mode_change bit (VBIOS will clear this bit when going to FSDOS)
1488 void dce110_enable_accelerated_mode(struct dc
*dc
)
1490 power_down_all_hw_blocks(dc
);
1492 disable_vga_and_power_gate_all_controllers(dc
);
1493 bios_set_scratch_acc_mode_change(dc
->ctx
->dc_bios
);
1496 static uint32_t compute_pstate_blackout_duration(
1497 struct bw_fixed blackout_duration
,
1498 const struct dc_stream_state
*stream
)
1500 uint32_t total_dest_line_time_ns
;
1501 uint32_t pstate_blackout_duration_ns
;
1503 pstate_blackout_duration_ns
= 1000 * blackout_duration
.value
>> 24;
1505 total_dest_line_time_ns
= 1000000UL *
1506 stream
->timing
.h_total
/
1507 stream
->timing
.pix_clk_khz
+
1508 pstate_blackout_duration_ns
;
1510 return total_dest_line_time_ns
;
1513 void dce110_set_displaymarks(
1514 const struct dc
*dc
,
1515 struct dc_state
*context
)
1517 uint8_t i
, num_pipes
;
1518 unsigned int underlay_idx
= dc
->res_pool
->underlay_pipe_index
;
1520 for (i
= 0, num_pipes
= 0; i
< MAX_PIPES
; i
++) {
1521 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
1522 uint32_t total_dest_line_time_ns
;
1524 if (pipe_ctx
->stream
== NULL
)
1527 total_dest_line_time_ns
= compute_pstate_blackout_duration(
1528 dc
->bw_vbios
->blackout_duration
, pipe_ctx
->stream
);
1529 pipe_ctx
->plane_res
.mi
->funcs
->mem_input_program_display_marks(
1530 pipe_ctx
->plane_res
.mi
,
1531 context
->bw
.dce
.nbp_state_change_wm_ns
[num_pipes
],
1532 context
->bw
.dce
.stutter_exit_wm_ns
[num_pipes
],
1533 context
->bw
.dce
.urgent_wm_ns
[num_pipes
],
1534 total_dest_line_time_ns
);
1535 if (i
== underlay_idx
) {
1537 pipe_ctx
->plane_res
.mi
->funcs
->mem_input_program_chroma_display_marks(
1538 pipe_ctx
->plane_res
.mi
,
1539 context
->bw
.dce
.nbp_state_change_wm_ns
[num_pipes
],
1540 context
->bw
.dce
.stutter_exit_wm_ns
[num_pipes
],
1541 context
->bw
.dce
.urgent_wm_ns
[num_pipes
],
1542 total_dest_line_time_ns
);
1548 static void set_safe_displaymarks(
1549 struct resource_context
*res_ctx
,
1550 const struct resource_pool
*pool
)
1553 int underlay_idx
= pool
->underlay_pipe_index
;
1554 struct dce_watermarks max_marks
= {
1555 MAX_WATERMARK
, MAX_WATERMARK
, MAX_WATERMARK
, MAX_WATERMARK
};
1556 struct dce_watermarks nbp_marks
= {
1557 SAFE_NBP_MARK
, SAFE_NBP_MARK
, SAFE_NBP_MARK
, SAFE_NBP_MARK
};
1559 for (i
= 0; i
< MAX_PIPES
; i
++) {
1560 if (res_ctx
->pipe_ctx
[i
].stream
== NULL
|| res_ctx
->pipe_ctx
[i
].plane_res
.mi
== NULL
)
1563 res_ctx
->pipe_ctx
[i
].plane_res
.mi
->funcs
->mem_input_program_display_marks(
1564 res_ctx
->pipe_ctx
[i
].plane_res
.mi
,
1570 if (i
== underlay_idx
)
1571 res_ctx
->pipe_ctx
[i
].plane_res
.mi
->funcs
->mem_input_program_chroma_display_marks(
1572 res_ctx
->pipe_ctx
[i
].plane_res
.mi
,
1581 /*******************************************************************************
1583 ******************************************************************************/
1585 static void set_drr(struct pipe_ctx
**pipe_ctx
,
1586 int num_pipes
, int vmin
, int vmax
)
1589 struct drr_params params
= {0};
1591 params
.vertical_total_max
= vmax
;
1592 params
.vertical_total_min
= vmin
;
1594 /* TODO: If multiple pipes are to be supported, you need
1598 for (i
= 0; i
< num_pipes
; i
++) {
1599 pipe_ctx
[i
]->stream_res
.tg
->funcs
->set_drr(pipe_ctx
[i
]->stream_res
.tg
, ¶ms
);
1603 static void get_position(struct pipe_ctx
**pipe_ctx
,
1605 struct crtc_position
*position
)
1609 /* TODO: handle pipes > 1
1611 for (i
= 0; i
< num_pipes
; i
++)
1612 pipe_ctx
[i
]->stream_res
.tg
->funcs
->get_position(pipe_ctx
[i
]->stream_res
.tg
, position
);
1615 static void set_static_screen_control(struct pipe_ctx
**pipe_ctx
,
1616 int num_pipes
, const struct dc_static_screen_events
*events
)
1619 unsigned int value
= 0;
1621 if (events
->overlay_update
)
1623 if (events
->surface_update
)
1625 if (events
->cursor_update
)
1628 #if defined(CONFIG_DRM_AMD_DC_FBC)
1632 for (i
= 0; i
< num_pipes
; i
++)
1633 pipe_ctx
[i
]->stream_res
.tg
->funcs
->
1634 set_static_screen_control(pipe_ctx
[i
]->stream_res
.tg
, value
);
1637 /* unit: in_khz before mode set, get pixel clock from context. ASIC register
1638 * may not be programmed yet.
1639 * TODO: after mode set, pre_mode_set = false,
1640 * may read PLL register to get pixel clock
1642 static uint32_t get_max_pixel_clock_for_all_paths(
1644 struct dc_state
*context
,
1647 uint32_t max_pix_clk
= 0;
1650 if (!pre_mode_set
) {
1651 /* TODO: read ASIC register to get pixel clock */
1655 for (i
= 0; i
< MAX_PIPES
; i
++) {
1656 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
1658 if (pipe_ctx
->stream
== NULL
)
1661 /* do not check under lay */
1662 if (pipe_ctx
->top_pipe
)
1665 if (pipe_ctx
->stream_res
.pix_clk_params
.requested_pix_clk
> max_pix_clk
)
1667 pipe_ctx
->stream_res
.pix_clk_params
.requested_pix_clk
;
1670 if (max_pix_clk
== 0)
1677 * Find clock state based on clock requested. if clock value is 0, simply
1678 * set clock state as requested without finding clock state by clock value
1681 static void apply_min_clocks(
1683 struct dc_state
*context
,
1684 enum dm_pp_clocks_state
*clocks_state
,
1687 struct state_dependent_clocks req_clocks
= {0};
1689 if (!pre_mode_set
) {
1690 /* set clock_state without verification */
1691 if (context
->dis_clk
->funcs
->set_min_clocks_state
) {
1692 context
->dis_clk
->funcs
->set_min_clocks_state(
1693 context
->dis_clk
, *clocks_state
);
1697 /* TODO: This is incorrect. Figure out how to fix. */
1698 context
->dis_clk
->funcs
->apply_clock_voltage_request(
1700 DM_PP_CLOCK_TYPE_DISPLAY_CLK
,
1701 context
->dis_clk
->cur_clocks_value
.dispclk_in_khz
,
1705 context
->dis_clk
->funcs
->apply_clock_voltage_request(
1707 DM_PP_CLOCK_TYPE_PIXELCLK
,
1708 context
->dis_clk
->cur_clocks_value
.max_pixelclk_in_khz
,
1712 context
->dis_clk
->funcs
->apply_clock_voltage_request(
1714 DM_PP_CLOCK_TYPE_DISPLAYPHYCLK
,
1715 context
->dis_clk
->cur_clocks_value
.max_non_dp_phyclk_in_khz
,
1721 /* get the required state based on state dependent clocks:
1722 * display clock and pixel clock
1724 req_clocks
.display_clk_khz
= context
->bw
.dce
.dispclk_khz
;
1726 req_clocks
.pixel_clk_khz
= get_max_pixel_clock_for_all_paths(
1729 if (context
->dis_clk
->funcs
->get_required_clocks_state
) {
1730 *clocks_state
= context
->dis_clk
->funcs
->get_required_clocks_state(
1731 context
->dis_clk
, &req_clocks
);
1732 context
->dis_clk
->funcs
->set_min_clocks_state(
1733 context
->dis_clk
, *clocks_state
);
1735 context
->dis_clk
->funcs
->apply_clock_voltage_request(
1737 DM_PP_CLOCK_TYPE_DISPLAY_CLK
,
1738 req_clocks
.display_clk_khz
,
1742 context
->dis_clk
->funcs
->apply_clock_voltage_request(
1744 DM_PP_CLOCK_TYPE_PIXELCLK
,
1745 req_clocks
.pixel_clk_khz
,
1749 context
->dis_clk
->funcs
->apply_clock_voltage_request(
1751 DM_PP_CLOCK_TYPE_DISPLAYPHYCLK
,
1752 req_clocks
.pixel_clk_khz
,
1758 #if defined(CONFIG_DRM_AMD_DC_FBC)
1761 * Check if FBC can be enabled
1763 static enum dc_status
validate_fbc(struct dc
*dc
,
1764 struct dc_state
*context
)
1766 struct pipe_ctx
*pipe_ctx
=
1767 &context
->res_ctx
.pipe_ctx
[0];
1769 ASSERT(dc
->fbc_compressor
);
1771 /* FBC memory should be allocated */
1772 if (!dc
->ctx
->fbc_gpu_addr
)
1773 return DC_ERROR_UNEXPECTED
;
1775 /* Only supports single display */
1776 if (context
->stream_count
!= 1)
1777 return DC_ERROR_UNEXPECTED
;
1779 /* Only supports eDP */
1780 if (pipe_ctx
->stream
->sink
->link
->connector_signal
!= SIGNAL_TYPE_EDP
)
1781 return DC_ERROR_UNEXPECTED
;
1783 /* PSR should not be enabled */
1784 if (pipe_ctx
->stream
->sink
->link
->psr_enabled
)
1785 return DC_ERROR_UNEXPECTED
;
1787 /* Nothing to compress */
1788 if (!pipe_ctx
->plane_state
)
1789 return DC_ERROR_UNEXPECTED
;
1791 /* Only for non-linear tiling */
1792 if (pipe_ctx
->plane_state
->tiling_info
.gfx8
.array_mode
== DC_ARRAY_LINEAR_GENERAL
)
1793 return DC_ERROR_UNEXPECTED
;
1801 static enum dc_status
enable_fbc(struct dc
*dc
,
1802 struct dc_state
*context
)
1804 enum dc_status status
= validate_fbc(dc
, context
);
1806 if (status
== DC_OK
) {
1807 /* Program GRPH COMPRESSED ADDRESS and PITCH */
1808 struct compr_addr_and_pitch_params params
= {0, 0, 0};
1809 struct compressor
*compr
= dc
->fbc_compressor
;
1810 struct pipe_ctx
*pipe_ctx
=
1811 &context
->res_ctx
.pipe_ctx
[0];
1813 params
.source_view_width
=
1814 pipe_ctx
->stream
->timing
.h_addressable
;
1815 params
.source_view_height
=
1816 pipe_ctx
->stream
->timing
.v_addressable
;
1818 compr
->compr_surface_address
.quad_part
= dc
->ctx
->fbc_gpu_addr
;
1820 compr
->funcs
->surface_address_and_pitch(compr
, ¶ms
);
1821 compr
->funcs
->set_fbc_invalidation_triggers(compr
, 1);
1823 compr
->funcs
->enable_fbc(compr
, ¶ms
);
1829 static enum dc_status
apply_ctx_to_hw_fpga(
1831 struct dc_state
*context
)
1833 enum dc_status status
= DC_ERROR_UNEXPECTED
;
1836 for (i
= 0; i
< MAX_PIPES
; i
++) {
1837 struct pipe_ctx
*pipe_ctx_old
=
1838 &dc
->current_state
->res_ctx
.pipe_ctx
[i
];
1839 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
1841 if (pipe_ctx
->stream
== NULL
)
1844 if (pipe_ctx
->stream
== pipe_ctx_old
->stream
)
1847 status
= apply_single_controller_ctx_to_hw(
1852 if (status
!= DC_OK
)
1859 static void dce110_reset_hw_ctx_wrap(
1861 struct dc_state
*context
)
1865 /* Reset old context */
1866 /* look up the targets that have been removed since last commit */
1867 for (i
= 0; i
< MAX_PIPES
; i
++) {
1868 struct pipe_ctx
*pipe_ctx_old
=
1869 &dc
->current_state
->res_ctx
.pipe_ctx
[i
];
1870 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
1872 /* Note: We need to disable output if clock sources change,
1873 * since bios does optimization and doesn't apply if changing
1874 * PHY when not already disabled.
1877 /* Skip underlay pipe since it will be handled in commit surface*/
1878 if (!pipe_ctx_old
->stream
|| pipe_ctx_old
->top_pipe
)
1881 if (!pipe_ctx
->stream
||
1882 pipe_need_reprogram(pipe_ctx_old
, pipe_ctx
)) {
1883 struct clock_source
*old_clk
= pipe_ctx_old
->clock_source
;
1885 /* Disable if new stream is null. O/w, if stream is
1886 * disabled already, no need to disable again.
1888 if (!pipe_ctx
->stream
|| !pipe_ctx
->stream
->dpms_off
)
1889 core_link_disable_stream(pipe_ctx_old
, FREE_ACQUIRED_RESOURCE
);
1891 pipe_ctx_old
->stream_res
.tg
->funcs
->set_blank(pipe_ctx_old
->stream_res
.tg
, true);
1892 if (!hwss_wait_for_blank_complete(pipe_ctx_old
->stream_res
.tg
)) {
1893 dm_error("DC: failed to blank crtc!\n");
1894 BREAK_TO_DEBUGGER();
1896 pipe_ctx_old
->stream_res
.tg
->funcs
->disable_crtc(pipe_ctx_old
->stream_res
.tg
);
1897 pipe_ctx_old
->plane_res
.mi
->funcs
->free_mem_input(
1898 pipe_ctx_old
->plane_res
.mi
, dc
->current_state
->stream_count
);
1901 old_clk
->funcs
->cs_power_down(old_clk
);
1903 dc
->hwss
.power_down_front_end(dc
, pipe_ctx_old
->pipe_idx
);
1905 pipe_ctx_old
->stream
= NULL
;
1911 enum dc_status
dce110_apply_ctx_to_hw(
1913 struct dc_state
*context
)
1915 struct dc_bios
*dcb
= dc
->ctx
->dc_bios
;
1916 enum dc_status status
;
1918 enum dm_pp_clocks_state clocks_state
= DM_PP_CLOCKS_STATE_INVALID
;
1920 /* Reset old context */
1921 /* look up the targets that have been removed since last commit */
1922 dc
->hwss
.reset_hw_ctx_wrap(dc
, context
);
1924 /* Skip applying if no targets */
1925 if (context
->stream_count
<= 0)
1928 if (IS_FPGA_MAXIMUS_DC(dc
->ctx
->dce_environment
)) {
1929 apply_ctx_to_hw_fpga(dc
, context
);
1933 /* Apply new context */
1934 dcb
->funcs
->set_scratch_critical_state(dcb
, true);
1936 /* below is for real asic only */
1937 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
1938 struct pipe_ctx
*pipe_ctx_old
=
1939 &dc
->current_state
->res_ctx
.pipe_ctx
[i
];
1940 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
1942 if (pipe_ctx
->stream
== NULL
|| pipe_ctx
->top_pipe
)
1945 if (pipe_ctx
->stream
== pipe_ctx_old
->stream
) {
1946 if (pipe_ctx_old
->clock_source
!= pipe_ctx
->clock_source
)
1947 dce_crtc_switch_to_clk_src(dc
->hwseq
,
1948 pipe_ctx
->clock_source
, i
);
1952 dc
->hwss
.enable_display_power_gating(
1953 dc
, i
, dc
->ctx
->dc_bios
,
1954 PIPE_GATING_CONTROL_DISABLE
);
1957 set_safe_displaymarks(&context
->res_ctx
, dc
->res_pool
);
1959 #if defined(CONFIG_DRM_AMD_DC_FBC)
1960 if (dc
->fbc_compressor
)
1961 dc
->fbc_compressor
->funcs
->disable_fbc(dc
->fbc_compressor
);
1963 /*TODO: when pplib works*/
1964 apply_min_clocks(dc
, context
, &clocks_state
, true);
1966 #if defined(CONFIG_DRM_AMD_DC_DCN1_0)
1967 if (dc
->ctx
->dce_version
>= DCN_VERSION_1_0
) {
1968 if (context
->bw
.dcn
.calc_clk
.fclk_khz
1969 > dc
->current_state
->bw
.dcn
.cur_clk
.fclk_khz
) {
1970 struct dm_pp_clock_for_voltage_req clock
;
1972 clock
.clk_type
= DM_PP_CLOCK_TYPE_FCLK
;
1973 clock
.clocks_in_khz
= context
->bw
.dcn
.calc_clk
.fclk_khz
;
1974 dm_pp_apply_clock_for_voltage_request(dc
->ctx
, &clock
);
1975 dc
->current_state
->bw
.dcn
.cur_clk
.fclk_khz
= clock
.clocks_in_khz
;
1976 context
->bw
.dcn
.cur_clk
.fclk_khz
= clock
.clocks_in_khz
;
1978 if (context
->bw
.dcn
.calc_clk
.dcfclk_khz
1979 > dc
->current_state
->bw
.dcn
.cur_clk
.dcfclk_khz
) {
1980 struct dm_pp_clock_for_voltage_req clock
;
1982 clock
.clk_type
= DM_PP_CLOCK_TYPE_DCFCLK
;
1983 clock
.clocks_in_khz
= context
->bw
.dcn
.calc_clk
.dcfclk_khz
;
1984 dm_pp_apply_clock_for_voltage_request(dc
->ctx
, &clock
);
1985 dc
->current_state
->bw
.dcn
.cur_clk
.dcfclk_khz
= clock
.clocks_in_khz
;
1986 context
->bw
.dcn
.cur_clk
.dcfclk_khz
= clock
.clocks_in_khz
;
1988 if (context
->bw
.dcn
.calc_clk
.dispclk_khz
1989 > dc
->current_state
->bw
.dcn
.cur_clk
.dispclk_khz
) {
1990 dc
->res_pool
->display_clock
->funcs
->set_clock(
1991 dc
->res_pool
->display_clock
,
1992 context
->bw
.dcn
.calc_clk
.dispclk_khz
);
1993 dc
->current_state
->bw
.dcn
.cur_clk
.dispclk_khz
=
1994 context
->bw
.dcn
.calc_clk
.dispclk_khz
;
1995 context
->bw
.dcn
.cur_clk
.dispclk_khz
=
1996 context
->bw
.dcn
.calc_clk
.dispclk_khz
;
2000 if (context
->bw
.dce
.dispclk_khz
2001 > dc
->current_state
->bw
.dce
.dispclk_khz
) {
2002 dc
->res_pool
->display_clock
->funcs
->set_clock(
2003 dc
->res_pool
->display_clock
,
2004 context
->bw
.dce
.dispclk_khz
* 115 / 100);
2006 /* program audio wall clock. use HDMI as clock source if HDMI
2007 * audio active. Otherwise, use DP as clock source
2008 * first, loop to find any HDMI audio, if not, loop find DP audio
2010 /* Setup audio rate clock source */
2012 * Audio lag happened on DP monitor when unplug a HDMI monitor
2015 * In case of DP and HDMI connected or HDMI only, DCCG_AUDIO_DTO_SEL
2016 * is set to either dto0 or dto1, audio should work fine.
2017 * In case of DP connected only, DCCG_AUDIO_DTO_SEL should be dto1,
2018 * set to dto0 will cause audio lag.
2021 * Not optimized audio wall dto setup. When mode set, iterate pipe_ctx,
2022 * find first available pipe with audio, setup audio wall DTO per topology
2023 * instead of per pipe.
2025 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
2026 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
2028 if (pipe_ctx
->stream
== NULL
)
2031 if (pipe_ctx
->top_pipe
)
2034 if (pipe_ctx
->stream
->signal
!= SIGNAL_TYPE_HDMI_TYPE_A
)
2037 if (pipe_ctx
->stream_res
.audio
!= NULL
) {
2038 struct audio_output audio_output
;
2040 build_audio_output(context
, pipe_ctx
, &audio_output
);
2042 pipe_ctx
->stream_res
.audio
->funcs
->wall_dto_setup(
2043 pipe_ctx
->stream_res
.audio
,
2044 pipe_ctx
->stream
->signal
,
2045 &audio_output
.crtc_info
,
2046 &audio_output
.pll_info
);
2051 /* no HDMI audio is found, try DP audio */
2052 if (i
== dc
->res_pool
->pipe_count
) {
2053 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
2054 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
2056 if (pipe_ctx
->stream
== NULL
)
2059 if (pipe_ctx
->top_pipe
)
2062 if (!dc_is_dp_signal(pipe_ctx
->stream
->signal
))
2065 if (pipe_ctx
->stream_res
.audio
!= NULL
) {
2066 struct audio_output audio_output
;
2068 build_audio_output(context
, pipe_ctx
, &audio_output
);
2070 pipe_ctx
->stream_res
.audio
->funcs
->wall_dto_setup(
2071 pipe_ctx
->stream_res
.audio
,
2072 pipe_ctx
->stream
->signal
,
2073 &audio_output
.crtc_info
,
2074 &audio_output
.pll_info
);
2080 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
2081 struct pipe_ctx
*pipe_ctx_old
=
2082 &dc
->current_state
->res_ctx
.pipe_ctx
[i
];
2083 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
2085 if (pipe_ctx
->stream
== NULL
)
2088 if (pipe_ctx
->stream
== pipe_ctx_old
->stream
)
2091 if (pipe_ctx
->stream
&& pipe_ctx_old
->stream
2092 && !pipe_need_reprogram(pipe_ctx_old
, pipe_ctx
))
2095 if (pipe_ctx
->top_pipe
)
2098 if (context
->res_ctx
.pipe_ctx
[i
].stream_res
.audio
!= NULL
) {
2100 struct audio_output audio_output
;
2102 build_audio_output(context
, pipe_ctx
, &audio_output
);
2104 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
2105 pipe_ctx
->stream_res
.stream_enc
->funcs
->dp_audio_setup(
2106 pipe_ctx
->stream_res
.stream_enc
,
2107 pipe_ctx
->stream_res
.audio
->inst
,
2108 &pipe_ctx
->stream
->audio_info
);
2110 pipe_ctx
->stream_res
.stream_enc
->funcs
->hdmi_audio_setup(
2111 pipe_ctx
->stream_res
.stream_enc
,
2112 pipe_ctx
->stream_res
.audio
->inst
,
2113 &pipe_ctx
->stream
->audio_info
,
2114 &audio_output
.crtc_info
);
2116 pipe_ctx
->stream_res
.audio
->funcs
->az_configure(
2117 pipe_ctx
->stream_res
.audio
,
2118 pipe_ctx
->stream
->signal
,
2119 &audio_output
.crtc_info
,
2120 &pipe_ctx
->stream
->audio_info
);
2123 status
= apply_single_controller_ctx_to_hw(
2128 if (dc
->hwss
.power_on_front_end
)
2129 dc
->hwss
.power_on_front_end(dc
, pipe_ctx
, context
);
2131 if (DC_OK
!= status
)
2135 /* pplib is notified if disp_num changed */
2136 dc
->hwss
.set_bandwidth(dc
, context
, true);
2139 apply_min_clocks(dc
, context
, &clocks_state
, false);
2141 dcb
->funcs
->set_scratch_critical_state(dcb
, false);
2143 #if defined(CONFIG_DRM_AMD_DC_FBC)
2144 if (dc
->fbc_compressor
)
2145 enable_fbc(dc
, context
);
2152 /*******************************************************************************
2153 * Front End programming
2154 ******************************************************************************/
2155 static void set_default_colors(struct pipe_ctx
*pipe_ctx
)
2157 struct default_adjustment default_adjust
= { 0 };
2159 default_adjust
.force_hw_default
= false;
2160 if (pipe_ctx
->plane_state
== NULL
)
2161 default_adjust
.in_color_space
= COLOR_SPACE_SRGB
;
2163 default_adjust
.in_color_space
=
2164 pipe_ctx
->plane_state
->color_space
;
2165 if (pipe_ctx
->stream
== NULL
)
2166 default_adjust
.out_color_space
= COLOR_SPACE_SRGB
;
2168 default_adjust
.out_color_space
=
2169 pipe_ctx
->stream
->output_color_space
;
2170 default_adjust
.csc_adjust_type
= GRAPHICS_CSC_ADJUST_TYPE_SW
;
2171 default_adjust
.surface_pixel_format
= pipe_ctx
->plane_res
.scl_data
.format
;
2173 /* display color depth */
2174 default_adjust
.color_depth
=
2175 pipe_ctx
->stream
->timing
.display_color_depth
;
2177 /* Lb color depth */
2178 default_adjust
.lb_color_depth
= pipe_ctx
->plane_res
.scl_data
.lb_params
.depth
;
2180 pipe_ctx
->plane_res
.xfm
->funcs
->opp_set_csc_default(
2181 pipe_ctx
->plane_res
.xfm
, &default_adjust
);
2185 /*******************************************************************************
2186 * In order to turn on/off specific surface we will program
2189 * In case that we have two surfaces and they have a different visibility
2190 * we can't turn off the CRTC since it will turn off the entire display
2192 * |----------------------------------------------- |
2193 * |bottom pipe|curr pipe | | |
2194 * |Surface |Surface | Blender | CRCT |
2195 * |visibility |visibility | Configuration| |
2196 * |------------------------------------------------|
2197 * | off | off | CURRENT_PIPE | blank |
2198 * | off | on | CURRENT_PIPE | unblank |
2199 * | on | off | OTHER_PIPE | unblank |
2200 * | on | on | BLENDING | unblank |
2201 * -------------------------------------------------|
2203 ******************************************************************************/
2204 static void program_surface_visibility(const struct dc
*dc
,
2205 struct pipe_ctx
*pipe_ctx
)
2207 enum blnd_mode blender_mode
= BLND_MODE_CURRENT_PIPE
;
2208 bool blank_target
= false;
2210 if (pipe_ctx
->bottom_pipe
) {
2212 /* For now we are supporting only two pipes */
2213 ASSERT(pipe_ctx
->bottom_pipe
->bottom_pipe
== NULL
);
2215 if (pipe_ctx
->bottom_pipe
->plane_state
->visible
) {
2216 if (pipe_ctx
->plane_state
->visible
)
2217 blender_mode
= BLND_MODE_BLENDING
;
2219 blender_mode
= BLND_MODE_OTHER_PIPE
;
2221 } else if (!pipe_ctx
->plane_state
->visible
)
2222 blank_target
= true;
2224 } else if (!pipe_ctx
->plane_state
->visible
)
2225 blank_target
= true;
2227 dce_set_blender_mode(dc
->hwseq
, pipe_ctx
->pipe_idx
, blender_mode
);
2228 pipe_ctx
->stream_res
.tg
->funcs
->set_blank(pipe_ctx
->stream_res
.tg
, blank_target
);
2232 static void program_gamut_remap(struct pipe_ctx
*pipe_ctx
)
2234 struct xfm_grph_csc_adjustment adjust
;
2235 memset(&adjust
, 0, sizeof(adjust
));
2236 adjust
.gamut_adjust_type
= GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS
;
2239 if (pipe_ctx
->stream
->gamut_remap_matrix
.enable_remap
== true) {
2240 adjust
.gamut_adjust_type
= GRAPHICS_GAMUT_ADJUST_TYPE_SW
;
2241 adjust
.temperature_matrix
[0] =
2243 gamut_remap_matrix
.matrix
[0];
2244 adjust
.temperature_matrix
[1] =
2246 gamut_remap_matrix
.matrix
[1];
2247 adjust
.temperature_matrix
[2] =
2249 gamut_remap_matrix
.matrix
[2];
2250 adjust
.temperature_matrix
[3] =
2252 gamut_remap_matrix
.matrix
[4];
2253 adjust
.temperature_matrix
[4] =
2255 gamut_remap_matrix
.matrix
[5];
2256 adjust
.temperature_matrix
[5] =
2258 gamut_remap_matrix
.matrix
[6];
2259 adjust
.temperature_matrix
[6] =
2261 gamut_remap_matrix
.matrix
[8];
2262 adjust
.temperature_matrix
[7] =
2264 gamut_remap_matrix
.matrix
[9];
2265 adjust
.temperature_matrix
[8] =
2267 gamut_remap_matrix
.matrix
[10];
2270 pipe_ctx
->plane_res
.xfm
->funcs
->transform_set_gamut_remap(pipe_ctx
->plane_res
.xfm
, &adjust
);
2274 * TODO REMOVE, USE UPDATE INSTEAD
2276 static void set_plane_config(
2277 const struct dc
*dc
,
2278 struct pipe_ctx
*pipe_ctx
,
2279 struct resource_context
*res_ctx
)
2281 struct mem_input
*mi
= pipe_ctx
->plane_res
.mi
;
2282 struct dc_plane_state
*plane_state
= pipe_ctx
->plane_state
;
2283 struct xfm_grph_csc_adjustment adjust
;
2284 struct out_csc_color_matrix tbl_entry
;
2287 memset(&adjust
, 0, sizeof(adjust
));
2288 memset(&tbl_entry
, 0, sizeof(tbl_entry
));
2289 adjust
.gamut_adjust_type
= GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS
;
2291 dce_enable_fe_clock(dc
->hwseq
, pipe_ctx
->pipe_idx
, true);
2293 set_default_colors(pipe_ctx
);
2294 if (pipe_ctx
->stream
->csc_color_matrix
.enable_adjustment
2296 tbl_entry
.color_space
=
2297 pipe_ctx
->stream
->output_color_space
;
2299 for (i
= 0; i
< 12; i
++)
2300 tbl_entry
.regval
[i
] =
2301 pipe_ctx
->stream
->csc_color_matrix
.matrix
[i
];
2303 pipe_ctx
->plane_res
.xfm
->funcs
->opp_set_csc_adjustment
2304 (pipe_ctx
->plane_res
.xfm
, &tbl_entry
);
2307 if (pipe_ctx
->stream
->gamut_remap_matrix
.enable_remap
== true) {
2308 adjust
.gamut_adjust_type
= GRAPHICS_GAMUT_ADJUST_TYPE_SW
;
2309 adjust
.temperature_matrix
[0] =
2311 gamut_remap_matrix
.matrix
[0];
2312 adjust
.temperature_matrix
[1] =
2314 gamut_remap_matrix
.matrix
[1];
2315 adjust
.temperature_matrix
[2] =
2317 gamut_remap_matrix
.matrix
[2];
2318 adjust
.temperature_matrix
[3] =
2320 gamut_remap_matrix
.matrix
[4];
2321 adjust
.temperature_matrix
[4] =
2323 gamut_remap_matrix
.matrix
[5];
2324 adjust
.temperature_matrix
[5] =
2326 gamut_remap_matrix
.matrix
[6];
2327 adjust
.temperature_matrix
[6] =
2329 gamut_remap_matrix
.matrix
[8];
2330 adjust
.temperature_matrix
[7] =
2332 gamut_remap_matrix
.matrix
[9];
2333 adjust
.temperature_matrix
[8] =
2335 gamut_remap_matrix
.matrix
[10];
2338 pipe_ctx
->plane_res
.xfm
->funcs
->transform_set_gamut_remap(pipe_ctx
->plane_res
.xfm
, &adjust
);
2340 pipe_ctx
->plane_res
.scl_data
.lb_params
.alpha_en
= pipe_ctx
->bottom_pipe
!= 0;
2341 program_scaler(dc
, pipe_ctx
);
2343 program_surface_visibility(dc
, pipe_ctx
);
2345 mi
->funcs
->mem_input_program_surface_config(
2347 plane_state
->format
,
2348 &plane_state
->tiling_info
,
2349 &plane_state
->plane_size
,
2350 plane_state
->rotation
,
2353 if (mi
->funcs
->set_blank
)
2354 mi
->funcs
->set_blank(mi
, pipe_ctx
->plane_state
->visible
);
2356 if (dc
->config
.gpu_vm_support
)
2357 mi
->funcs
->mem_input_program_pte_vm(
2358 pipe_ctx
->plane_res
.mi
,
2359 plane_state
->format
,
2360 &plane_state
->tiling_info
,
2361 plane_state
->rotation
);
2364 static void update_plane_addr(const struct dc
*dc
,
2365 struct pipe_ctx
*pipe_ctx
)
2367 struct dc_plane_state
*plane_state
= pipe_ctx
->plane_state
;
2369 if (plane_state
== NULL
)
2372 pipe_ctx
->plane_res
.mi
->funcs
->mem_input_program_surface_flip_and_addr(
2373 pipe_ctx
->plane_res
.mi
,
2374 &plane_state
->address
,
2375 plane_state
->flip_immediate
);
2377 plane_state
->status
.requested_address
= plane_state
->address
;
2380 void dce110_update_pending_status(struct pipe_ctx
*pipe_ctx
)
2382 struct dc_plane_state
*plane_state
= pipe_ctx
->plane_state
;
2384 if (plane_state
== NULL
)
2387 plane_state
->status
.is_flip_pending
=
2388 pipe_ctx
->plane_res
.mi
->funcs
->mem_input_is_flip_pending(
2389 pipe_ctx
->plane_res
.mi
);
2391 if (plane_state
->status
.is_flip_pending
&& !plane_state
->visible
)
2392 pipe_ctx
->plane_res
.mi
->current_address
= pipe_ctx
->plane_res
.mi
->request_address
;
2394 plane_state
->status
.current_address
= pipe_ctx
->plane_res
.mi
->current_address
;
2395 if (pipe_ctx
->plane_res
.mi
->current_address
.type
== PLN_ADDR_TYPE_GRPH_STEREO
&&
2396 pipe_ctx
->stream_res
.tg
->funcs
->is_stereo_left_eye
) {
2397 plane_state
->status
.is_right_eye
=\
2398 !pipe_ctx
->stream_res
.tg
->funcs
->is_stereo_left_eye(pipe_ctx
->stream_res
.tg
);
2402 void dce110_power_down(struct dc
*dc
)
2404 power_down_all_hw_blocks(dc
);
2405 disable_vga_and_power_gate_all_controllers(dc
);
2408 static bool wait_for_reset_trigger_to_occur(
2409 struct dc_context
*dc_ctx
,
2410 struct timing_generator
*tg
)
2414 /* To avoid endless loop we wait at most
2415 * frames_to_wait_on_triggered_reset frames for the reset to occur. */
2416 const uint32_t frames_to_wait_on_triggered_reset
= 10;
2419 for (i
= 0; i
< frames_to_wait_on_triggered_reset
; i
++) {
2421 if (!tg
->funcs
->is_counter_moving(tg
)) {
2422 DC_ERROR("TG counter is not moving!\n");
2426 if (tg
->funcs
->did_triggered_reset_occur(tg
)) {
2428 /* usually occurs at i=1 */
2429 DC_SYNC_INFO("GSL: reset occurred at wait count: %d\n",
2434 /* Wait for one frame. */
2435 tg
->funcs
->wait_for_state(tg
, CRTC_STATE_VACTIVE
);
2436 tg
->funcs
->wait_for_state(tg
, CRTC_STATE_VBLANK
);
2440 DC_ERROR("GSL: Timeout on reset trigger!\n");
2445 /* Enable timing synchronization for a group of Timing Generators. */
2446 static void dce110_enable_timing_synchronization(
2450 struct pipe_ctx
*grouped_pipes
[])
2452 struct dc_context
*dc_ctx
= dc
->ctx
;
2453 struct dcp_gsl_params gsl_params
= { 0 };
2456 DC_SYNC_INFO("GSL: Setting-up...\n");
2458 /* Designate a single TG in the group as a master.
2459 * Since HW doesn't care which one, we always assign
2460 * the 1st one in the group. */
2461 gsl_params
.gsl_group
= 0;
2462 gsl_params
.gsl_master
= grouped_pipes
[0]->stream_res
.tg
->inst
;
2464 for (i
= 0; i
< group_size
; i
++)
2465 grouped_pipes
[i
]->stream_res
.tg
->funcs
->setup_global_swap_lock(
2466 grouped_pipes
[i
]->stream_res
.tg
, &gsl_params
);
2468 /* Reset slave controllers on master VSync */
2469 DC_SYNC_INFO("GSL: enabling trigger-reset\n");
2471 for (i
= 1 /* skip the master */; i
< group_size
; i
++)
2472 grouped_pipes
[i
]->stream_res
.tg
->funcs
->enable_reset_trigger(
2473 grouped_pipes
[i
]->stream_res
.tg
, gsl_params
.gsl_group
);
2477 for (i
= 1 /* skip the master */; i
< group_size
; i
++) {
2478 DC_SYNC_INFO("GSL: waiting for reset to occur.\n");
2479 wait_for_reset_trigger_to_occur(dc_ctx
, grouped_pipes
[i
]->stream_res
.tg
);
2480 /* Regardless of success of the wait above, remove the reset or
2481 * the driver will start timing out on Display requests. */
2482 DC_SYNC_INFO("GSL: disabling trigger-reset.\n");
2483 grouped_pipes
[i
]->stream_res
.tg
->funcs
->disable_reset_trigger(grouped_pipes
[i
]->stream_res
.tg
);
2487 /* GSL Vblank synchronization is a one time sync mechanism, assumption
2488 * is that the sync'ed displays will not drift out of sync over time*/
2489 DC_SYNC_INFO("GSL: Restoring register states.\n");
2490 for (i
= 0; i
< group_size
; i
++)
2491 grouped_pipes
[i
]->stream_res
.tg
->funcs
->tear_down_global_swap_lock(grouped_pipes
[i
]->stream_res
.tg
);
2493 DC_SYNC_INFO("GSL: Set-up complete.\n");
2496 static void init_hw(struct dc
*dc
)
2500 struct transform
*xfm
;
2503 bp
= dc
->ctx
->dc_bios
;
2504 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
2505 xfm
= dc
->res_pool
->transforms
[i
];
2506 xfm
->funcs
->transform_reset(xfm
);
2508 dc
->hwss
.enable_display_power_gating(
2510 PIPE_GATING_CONTROL_INIT
);
2511 dc
->hwss
.enable_display_power_gating(
2513 PIPE_GATING_CONTROL_DISABLE
);
2514 dc
->hwss
.enable_display_pipe_clock_gating(
2519 dce_clock_gating_power_up(dc
->hwseq
, false);
2520 /***************************************/
2522 for (i
= 0; i
< dc
->link_count
; i
++) {
2523 /****************************************/
2524 /* Power up AND update implementation according to the
2525 * required signal (which may be different from the
2526 * default signal on connector). */
2527 struct dc_link
*link
= dc
->links
[i
];
2529 if (link
->link_enc
->connector
.id
== CONNECTOR_ID_EDP
)
2530 dc
->hwss
.edp_power_control(link
, true);
2532 link
->link_enc
->funcs
->hw_init(link
->link_enc
);
2535 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
2536 struct timing_generator
*tg
= dc
->res_pool
->timing_generators
[i
];
2538 tg
->funcs
->disable_vga(tg
);
2540 /* Blank controller using driver code instead of
2542 tg
->funcs
->set_blank(tg
, true);
2543 hwss_wait_for_blank_complete(tg
);
2546 for (i
= 0; i
< dc
->res_pool
->audio_count
; i
++) {
2547 struct audio
*audio
= dc
->res_pool
->audios
[i
];
2548 audio
->funcs
->hw_init(audio
);
2551 abm
= dc
->res_pool
->abm
;
2553 abm
->funcs
->init_backlight(abm
);
2554 abm
->funcs
->abm_init(abm
);
2556 #if defined(CONFIG_DRM_AMD_DC_FBC)
2557 if (dc
->fbc_compressor
)
2558 dc
->fbc_compressor
->funcs
->power_up_fbc(dc
->fbc_compressor
);
2563 void dce110_fill_display_configs(
2564 const struct dc_state
*context
,
2565 struct dm_pp_display_configuration
*pp_display_cfg
)
2570 for (j
= 0; j
< context
->stream_count
; j
++) {
2573 const struct dc_stream_state
*stream
= context
->streams
[j
];
2574 struct dm_pp_single_disp_config
*cfg
=
2575 &pp_display_cfg
->disp_configs
[num_cfgs
];
2576 const struct pipe_ctx
*pipe_ctx
= NULL
;
2578 for (k
= 0; k
< MAX_PIPES
; k
++)
2579 if (stream
== context
->res_ctx
.pipe_ctx
[k
].stream
) {
2580 pipe_ctx
= &context
->res_ctx
.pipe_ctx
[k
];
2584 ASSERT(pipe_ctx
!= NULL
);
2587 cfg
->signal
= pipe_ctx
->stream
->signal
;
2588 cfg
->pipe_idx
= pipe_ctx
->pipe_idx
;
2589 cfg
->src_height
= stream
->src
.height
;
2590 cfg
->src_width
= stream
->src
.width
;
2591 cfg
->ddi_channel_mapping
=
2592 stream
->sink
->link
->ddi_channel_mapping
.raw
;
2594 stream
->sink
->link
->link_enc
->transmitter
;
2595 cfg
->link_settings
.lane_count
=
2596 stream
->sink
->link
->cur_link_settings
.lane_count
;
2597 cfg
->link_settings
.link_rate
=
2598 stream
->sink
->link
->cur_link_settings
.link_rate
;
2599 cfg
->link_settings
.link_spread
=
2600 stream
->sink
->link
->cur_link_settings
.link_spread
;
2601 cfg
->sym_clock
= stream
->phy_pix_clk
;
2602 /* Round v_refresh*/
2603 cfg
->v_refresh
= stream
->timing
.pix_clk_khz
* 1000;
2604 cfg
->v_refresh
/= stream
->timing
.h_total
;
2605 cfg
->v_refresh
= (cfg
->v_refresh
+ stream
->timing
.v_total
/ 2)
2606 / stream
->timing
.v_total
;
2609 pp_display_cfg
->display_count
= num_cfgs
;
2612 uint32_t dce110_get_min_vblank_time_us(const struct dc_state
*context
)
2615 uint32_t min_vertical_blank_time
= -1;
2617 for (j
= 0; j
< context
->stream_count
; j
++) {
2618 struct dc_stream_state
*stream
= context
->streams
[j
];
2619 uint32_t vertical_blank_in_pixels
= 0;
2620 uint32_t vertical_blank_time
= 0;
2622 vertical_blank_in_pixels
= stream
->timing
.h_total
*
2623 (stream
->timing
.v_total
2624 - stream
->timing
.v_addressable
);
2626 vertical_blank_time
= vertical_blank_in_pixels
2627 * 1000 / stream
->timing
.pix_clk_khz
;
2629 if (min_vertical_blank_time
> vertical_blank_time
)
2630 min_vertical_blank_time
= vertical_blank_time
;
2633 return min_vertical_blank_time
;
2636 static int determine_sclk_from_bounding_box(
2637 const struct dc
*dc
,
2643 * Some asics do not give us sclk levels, so we just report the actual
2646 if (dc
->sclk_lvls
.num_levels
== 0)
2647 return required_sclk
;
2649 for (i
= 0; i
< dc
->sclk_lvls
.num_levels
; i
++) {
2650 if (dc
->sclk_lvls
.clocks_in_khz
[i
] >= required_sclk
)
2651 return dc
->sclk_lvls
.clocks_in_khz
[i
];
2654 * even maximum level could not satisfy requirement, this
2655 * is unexpected at this stage, should have been caught at
2659 return dc
->sclk_lvls
.clocks_in_khz
[dc
->sclk_lvls
.num_levels
- 1];
2662 static void pplib_apply_display_requirements(
2664 struct dc_state
*context
)
2666 struct dm_pp_display_configuration
*pp_display_cfg
= &context
->pp_display_cfg
;
2668 pp_display_cfg
->all_displays_in_sync
=
2669 context
->bw
.dce
.all_displays_in_sync
;
2670 pp_display_cfg
->nb_pstate_switch_disable
=
2671 context
->bw
.dce
.nbp_state_change_enable
== false;
2672 pp_display_cfg
->cpu_cc6_disable
=
2673 context
->bw
.dce
.cpuc_state_change_enable
== false;
2674 pp_display_cfg
->cpu_pstate_disable
=
2675 context
->bw
.dce
.cpup_state_change_enable
== false;
2676 pp_display_cfg
->cpu_pstate_separation_time
=
2677 context
->bw
.dce
.blackout_recovery_time_us
;
2679 pp_display_cfg
->min_memory_clock_khz
= context
->bw
.dce
.yclk_khz
2680 / MEMORY_TYPE_MULTIPLIER
;
2682 pp_display_cfg
->min_engine_clock_khz
= determine_sclk_from_bounding_box(
2684 context
->bw
.dce
.sclk_khz
);
2686 pp_display_cfg
->min_engine_clock_deep_sleep_khz
2687 = context
->bw
.dce
.sclk_deep_sleep_khz
;
2689 pp_display_cfg
->avail_mclk_switch_time_us
=
2690 dce110_get_min_vblank_time_us(context
);
2692 pp_display_cfg
->avail_mclk_switch_time_in_disp_active_us
= 0;
2694 pp_display_cfg
->disp_clk_khz
= context
->bw
.dce
.dispclk_khz
;
2696 dce110_fill_display_configs(context
, pp_display_cfg
);
2698 /* TODO: is this still applicable?*/
2699 if (pp_display_cfg
->display_count
== 1) {
2700 const struct dc_crtc_timing
*timing
=
2701 &context
->streams
[0]->timing
;
2703 pp_display_cfg
->crtc_index
=
2704 pp_display_cfg
->disp_configs
[0].pipe_idx
;
2705 pp_display_cfg
->line_time_in_us
= timing
->h_total
* 1000
2706 / timing
->pix_clk_khz
;
2709 if (memcmp(&dc
->prev_display_config
, pp_display_cfg
, sizeof(
2710 struct dm_pp_display_configuration
)) != 0)
2711 dm_pp_apply_display_requirements(dc
->ctx
, pp_display_cfg
);
2713 dc
->prev_display_config
= *pp_display_cfg
;
2716 static void dce110_set_bandwidth(
2718 struct dc_state
*context
,
2719 bool decrease_allowed
)
2721 dce110_set_displaymarks(dc
, context
);
2723 if (decrease_allowed
|| context
->bw
.dce
.dispclk_khz
> dc
->current_state
->bw
.dce
.dispclk_khz
) {
2724 dc
->res_pool
->display_clock
->funcs
->set_clock(
2725 dc
->res_pool
->display_clock
,
2726 context
->bw
.dce
.dispclk_khz
* 115 / 100);
2727 dc
->current_state
->bw
.dce
.dispclk_khz
= context
->bw
.dce
.dispclk_khz
;
2730 pplib_apply_display_requirements(dc
, context
);
2733 static void dce110_program_front_end_for_pipe(
2734 struct dc
*dc
, struct pipe_ctx
*pipe_ctx
)
2736 struct mem_input
*mi
= pipe_ctx
->plane_res
.mi
;
2737 struct pipe_ctx
*old_pipe
= NULL
;
2738 struct dc_plane_state
*plane_state
= pipe_ctx
->plane_state
;
2739 struct xfm_grph_csc_adjustment adjust
;
2740 struct out_csc_color_matrix tbl_entry
;
2741 struct pipe_ctx
*cur_pipe_ctx
=
2742 &dc
->current_state
->res_ctx
.pipe_ctx
[pipe_ctx
->pipe_idx
];
2745 memset(&tbl_entry
, 0, sizeof(tbl_entry
));
2747 if (dc
->current_state
)
2748 old_pipe
= &dc
->current_state
->res_ctx
.pipe_ctx
[pipe_ctx
->pipe_idx
];
2750 memset(&adjust
, 0, sizeof(adjust
));
2751 adjust
.gamut_adjust_type
= GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS
;
2753 dce_enable_fe_clock(dc
->hwseq
, pipe_ctx
->pipe_idx
, true);
2755 set_default_colors(pipe_ctx
);
2756 if (pipe_ctx
->stream
->csc_color_matrix
.enable_adjustment
2758 tbl_entry
.color_space
=
2759 pipe_ctx
->stream
->output_color_space
;
2761 for (i
= 0; i
< 12; i
++)
2762 tbl_entry
.regval
[i
] =
2763 pipe_ctx
->stream
->csc_color_matrix
.matrix
[i
];
2765 pipe_ctx
->plane_res
.xfm
->funcs
->opp_set_csc_adjustment
2766 (pipe_ctx
->plane_res
.xfm
, &tbl_entry
);
2769 if (pipe_ctx
->stream
->gamut_remap_matrix
.enable_remap
== true) {
2770 adjust
.gamut_adjust_type
= GRAPHICS_GAMUT_ADJUST_TYPE_SW
;
2771 adjust
.temperature_matrix
[0] =
2773 gamut_remap_matrix
.matrix
[0];
2774 adjust
.temperature_matrix
[1] =
2776 gamut_remap_matrix
.matrix
[1];
2777 adjust
.temperature_matrix
[2] =
2779 gamut_remap_matrix
.matrix
[2];
2780 adjust
.temperature_matrix
[3] =
2782 gamut_remap_matrix
.matrix
[4];
2783 adjust
.temperature_matrix
[4] =
2785 gamut_remap_matrix
.matrix
[5];
2786 adjust
.temperature_matrix
[5] =
2788 gamut_remap_matrix
.matrix
[6];
2789 adjust
.temperature_matrix
[6] =
2791 gamut_remap_matrix
.matrix
[8];
2792 adjust
.temperature_matrix
[7] =
2794 gamut_remap_matrix
.matrix
[9];
2795 adjust
.temperature_matrix
[8] =
2797 gamut_remap_matrix
.matrix
[10];
2800 pipe_ctx
->plane_res
.xfm
->funcs
->transform_set_gamut_remap(pipe_ctx
->plane_res
.xfm
, &adjust
);
2802 pipe_ctx
->plane_res
.scl_data
.lb_params
.alpha_en
= pipe_ctx
->bottom_pipe
!= 0;
2804 program_scaler(dc
, pipe_ctx
);
2806 #if defined(CONFIG_DRM_AMD_DC_FBC)
2807 if (dc
->fbc_compressor
&& old_pipe
->stream
) {
2808 if (plane_state
->tiling_info
.gfx8
.array_mode
== DC_ARRAY_LINEAR_GENERAL
)
2809 dc
->fbc_compressor
->funcs
->disable_fbc(dc
->fbc_compressor
);
2811 enable_fbc(dc
, dc
->current_state
);
2815 mi
->funcs
->mem_input_program_surface_config(
2817 plane_state
->format
,
2818 &plane_state
->tiling_info
,
2819 &plane_state
->plane_size
,
2820 plane_state
->rotation
,
2823 if (mi
->funcs
->set_blank
)
2824 mi
->funcs
->set_blank(mi
, pipe_ctx
->plane_state
->visible
);
2826 if (dc
->config
.gpu_vm_support
)
2827 mi
->funcs
->mem_input_program_pte_vm(
2828 pipe_ctx
->plane_res
.mi
,
2829 plane_state
->format
,
2830 &plane_state
->tiling_info
,
2831 plane_state
->rotation
);
2833 /* Moved programming gamma from dc to hwss */
2834 if (cur_pipe_ctx
->plane_state
!= pipe_ctx
->plane_state
) {
2835 dc
->hwss
.set_input_transfer_func(
2836 pipe_ctx
, pipe_ctx
->plane_state
);
2837 dc
->hwss
.set_output_transfer_func(
2838 pipe_ctx
, pipe_ctx
->stream
);
2841 dm_logger_write(dc
->ctx
->logger
, LOG_SURFACE
,
2842 "Pipe:%d 0x%x: addr hi:0x%x, "
2845 " %d; dst: %d, %d, %d, %d;"
2846 "clip: %d, %d, %d, %d\n",
2848 pipe_ctx
->plane_state
,
2849 pipe_ctx
->plane_state
->address
.grph
.addr
.high_part
,
2850 pipe_ctx
->plane_state
->address
.grph
.addr
.low_part
,
2851 pipe_ctx
->plane_state
->src_rect
.x
,
2852 pipe_ctx
->plane_state
->src_rect
.y
,
2853 pipe_ctx
->plane_state
->src_rect
.width
,
2854 pipe_ctx
->plane_state
->src_rect
.height
,
2855 pipe_ctx
->plane_state
->dst_rect
.x
,
2856 pipe_ctx
->plane_state
->dst_rect
.y
,
2857 pipe_ctx
->plane_state
->dst_rect
.width
,
2858 pipe_ctx
->plane_state
->dst_rect
.height
,
2859 pipe_ctx
->plane_state
->clip_rect
.x
,
2860 pipe_ctx
->plane_state
->clip_rect
.y
,
2861 pipe_ctx
->plane_state
->clip_rect
.width
,
2862 pipe_ctx
->plane_state
->clip_rect
.height
);
2864 dm_logger_write(dc
->ctx
->logger
, LOG_SURFACE
,
2865 "Pipe %d: width, height, x, y\n"
2866 "viewport:%d, %d, %d, %d\n"
2867 "recout: %d, %d, %d, %d\n",
2869 pipe_ctx
->plane_res
.scl_data
.viewport
.width
,
2870 pipe_ctx
->plane_res
.scl_data
.viewport
.height
,
2871 pipe_ctx
->plane_res
.scl_data
.viewport
.x
,
2872 pipe_ctx
->plane_res
.scl_data
.viewport
.y
,
2873 pipe_ctx
->plane_res
.scl_data
.recout
.width
,
2874 pipe_ctx
->plane_res
.scl_data
.recout
.height
,
2875 pipe_ctx
->plane_res
.scl_data
.recout
.x
,
2876 pipe_ctx
->plane_res
.scl_data
.recout
.y
);
2879 static void dce110_apply_ctx_for_surface(
2881 const struct dc_stream_state
*stream
,
2883 struct dc_state
*context
)
2887 if (num_planes
== 0)
2890 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
2891 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
2892 struct pipe_ctx
*old_pipe_ctx
= &dc
->current_state
->res_ctx
.pipe_ctx
[i
];
2894 if (stream
== pipe_ctx
->stream
) {
2895 if (!pipe_ctx
->top_pipe
&&
2896 (pipe_ctx
->plane_state
|| old_pipe_ctx
->plane_state
))
2897 dc
->hwss
.pipe_control_lock(dc
, pipe_ctx
, true);
2901 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
2902 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
2904 if (pipe_ctx
->stream
!= stream
)
2907 /* Need to allocate mem before program front end for Fiji */
2908 if (pipe_ctx
->plane_res
.mi
!= NULL
)
2909 pipe_ctx
->plane_res
.mi
->funcs
->allocate_mem_input(
2910 pipe_ctx
->plane_res
.mi
,
2911 pipe_ctx
->stream
->timing
.h_total
,
2912 pipe_ctx
->stream
->timing
.v_total
,
2913 pipe_ctx
->stream
->timing
.pix_clk_khz
,
2914 context
->stream_count
);
2916 dce110_program_front_end_for_pipe(dc
, pipe_ctx
);
2918 dc
->hwss
.update_plane_addr(dc
, pipe_ctx
);
2920 program_surface_visibility(dc
, pipe_ctx
);
2924 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
2925 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
2926 struct pipe_ctx
*old_pipe_ctx
= &dc
->current_state
->res_ctx
.pipe_ctx
[i
];
2928 if ((stream
== pipe_ctx
->stream
) &&
2929 (!pipe_ctx
->top_pipe
) &&
2930 (pipe_ctx
->plane_state
|| old_pipe_ctx
->plane_state
))
2931 dc
->hwss
.pipe_control_lock(dc
, pipe_ctx
, false);
2935 static void dce110_power_down_fe(struct dc
*dc
, int fe_idx
)
2937 /* Do not power down fe when stream is active on dce*/
2938 if (dc
->current_state
->res_ctx
.pipe_ctx
[fe_idx
].stream
)
2941 dc
->hwss
.enable_display_power_gating(
2942 dc
, fe_idx
, dc
->ctx
->dc_bios
, PIPE_GATING_CONTROL_ENABLE
);
2944 dc
->res_pool
->transforms
[fe_idx
]->funcs
->transform_reset(
2945 dc
->res_pool
->transforms
[fe_idx
]);
2948 static void dce110_wait_for_mpcc_disconnect(
2950 struct resource_pool
*res_pool
,
2951 struct pipe_ctx
*pipe_ctx
)
2956 static void program_csc_matrix(struct pipe_ctx
*pipe_ctx
,
2957 enum dc_color_space colorspace
,
2961 struct out_csc_color_matrix tbl_entry
;
2963 if (pipe_ctx
->stream
->csc_color_matrix
.enable_adjustment
2965 enum dc_color_space color_space
=
2966 pipe_ctx
->stream
->output_color_space
;
2968 //uint16_t matrix[12];
2969 for (i
= 0; i
< 12; i
++)
2970 tbl_entry
.regval
[i
] = pipe_ctx
->stream
->csc_color_matrix
.matrix
[i
];
2972 tbl_entry
.color_space
= color_space
;
2973 //tbl_entry.regval = matrix;
2974 pipe_ctx
->plane_res
.xfm
->funcs
->opp_set_csc_adjustment(pipe_ctx
->plane_res
.xfm
, &tbl_entry
);
2978 static void ready_shared_resources(struct dc
*dc
, struct dc_state
*context
) {}
2980 static void optimize_shared_resources(struct dc
*dc
) {}
2982 static const struct hw_sequencer_funcs dce110_funcs
= {
2983 .program_gamut_remap
= program_gamut_remap
,
2984 .program_csc_matrix
= program_csc_matrix
,
2986 .apply_ctx_to_hw
= dce110_apply_ctx_to_hw
,
2987 .apply_ctx_for_surface
= dce110_apply_ctx_for_surface
,
2988 .set_plane_config
= set_plane_config
,
2989 .update_plane_addr
= update_plane_addr
,
2990 .update_pending_status
= dce110_update_pending_status
,
2991 .set_input_transfer_func
= dce110_set_input_transfer_func
,
2992 .set_output_transfer_func
= dce110_set_output_transfer_func
,
2993 .power_down
= dce110_power_down
,
2994 .enable_accelerated_mode
= dce110_enable_accelerated_mode
,
2995 .enable_timing_synchronization
= dce110_enable_timing_synchronization
,
2996 .update_info_frame
= dce110_update_info_frame
,
2997 .enable_stream
= dce110_enable_stream
,
2998 .disable_stream
= dce110_disable_stream
,
2999 .unblank_stream
= dce110_unblank_stream
,
3000 .blank_stream
= dce110_blank_stream
,
3001 .enable_display_pipe_clock_gating
= enable_display_pipe_clock_gating
,
3002 .enable_display_power_gating
= dce110_enable_display_power_gating
,
3003 .power_down_front_end
= dce110_power_down_fe
,
3004 .pipe_control_lock
= dce_pipe_control_lock
,
3005 .set_bandwidth
= dce110_set_bandwidth
,
3007 .get_position
= get_position
,
3008 .set_static_screen_control
= set_static_screen_control
,
3009 .reset_hw_ctx_wrap
= dce110_reset_hw_ctx_wrap
,
3010 .prog_pixclk_crtc_otg
= dce110_prog_pixclk_crtc_otg
,
3011 .setup_stereo
= NULL
,
3012 .set_avmute
= dce110_set_avmute
,
3013 .wait_for_mpcc_disconnect
= dce110_wait_for_mpcc_disconnect
,
3014 .ready_shared_resources
= ready_shared_resources
,
3015 .optimize_shared_resources
= optimize_shared_resources
,
3016 .edp_backlight_control
= hwss_edp_backlight_control
,
3017 .edp_power_control
= hwss_edp_power_control
,
3018 .edp_wait_for_hpd_ready
= hwss_edp_wait_for_hpd_ready
,
3021 void dce110_hw_sequencer_construct(struct dc
*dc
)
3023 dc
->hwss
= dce110_funcs
;