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 link_encoder
*enc
,
820 struct dc_context
*ctx
= enc
->ctx
;
821 struct graphics_object_id connector
= 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 link_encoder
*enc
,
888 struct dc_context
*ctx
= enc
->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(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
= enc
->transmitter
;
911 cntl
.connector_obj_id
= enc
->connector
;
912 cntl
.coherent
= false;
913 cntl
.lanes_number
= LANE_COUNT_FOUR
;
914 cntl
.hpd_sel
= 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"));
928 hwss_edp_wait_for_hpd_ready(enc
, true);
931 /*todo: cloned in stream enc, fix*/
934 * eDP only. Control the backlight of the eDP panel
936 void hwss_edp_backlight_control(
937 struct dc_link
*link
,
940 struct dce_hwseq
*hws
= link
->dc
->hwseq
;
941 struct dc_context
*ctx
= link
->dc
->ctx
;
942 struct bp_transmitter_control cntl
= { 0 };
944 if (dal_graphics_object_id_get_connector_id(link
->link_id
)
945 != CONNECTOR_ID_EDP
) {
950 if (enable
&& is_panel_backlight_on(hws
)) {
951 dm_logger_write(ctx
->logger
, LOG_HW_RESUME_S3
,
952 "%s: panel already powered up. Do nothing.\n",
957 /* Send VBIOS command to control eDP panel backlight */
959 dm_logger_write(ctx
->logger
, LOG_HW_RESUME_S3
,
960 "%s: backlight action: %s\n",
961 __func__
, (enable
? "On":"Off"));
963 cntl
.action
= enable
?
964 TRANSMITTER_CONTROL_BACKLIGHT_ON
:
965 TRANSMITTER_CONTROL_BACKLIGHT_OFF
;
967 /*cntl.engine_id = ctx->engine;*/
968 cntl
.transmitter
= link
->link_enc
->transmitter
;
969 cntl
.connector_obj_id
= link
->link_enc
->connector
;
971 cntl
.lanes_number
= LANE_COUNT_FOUR
;
972 cntl
.hpd_sel
= link
->link_enc
->hpd_source
;
974 /* For eDP, the following delays might need to be considered
975 * after link training completed:
976 * idle period - min. accounts for required BS-Idle pattern,
977 * max. allows for source frame synchronization);
978 * 50 msec max. delay from valid video data from source
979 * to video on dislpay or backlight enable.
981 * Disable the delay for now.
982 * Enable it in the future if necessary.
984 /* dc_service_sleep_in_milliseconds(50); */
985 link_transmitter_control(link
->dc
->ctx
->dc_bios
, &cntl
);
988 void dce110_disable_stream(struct pipe_ctx
*pipe_ctx
, int option
)
990 struct dc_stream_state
*stream
= pipe_ctx
->stream
;
991 struct dc_link
*link
= stream
->sink
->link
;
992 struct dc
*dc
= pipe_ctx
->stream
->ctx
->dc
;
994 if (pipe_ctx
->stream_res
.audio
) {
995 pipe_ctx
->stream_res
.audio
->funcs
->az_disable(pipe_ctx
->stream_res
.audio
);
997 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
998 pipe_ctx
->stream_res
.stream_enc
->funcs
->dp_audio_disable(
999 pipe_ctx
->stream_res
.stream_enc
);
1001 pipe_ctx
->stream_res
.stream_enc
->funcs
->hdmi_audio_disable(
1002 pipe_ctx
->stream_res
.stream_enc
);
1003 /*don't free audio if it is from retrain or internal disable stream*/
1004 if (option
== FREE_ACQUIRED_RESOURCE
&& dc
->caps
.dynamic_audio
== true) {
1005 /*we have to dynamic arbitrate the audio endpoints*/
1006 pipe_ctx
->stream_res
.audio
= NULL
;
1007 /*we free the resource, need reset is_audio_acquired*/
1008 update_audio_usage(&dc
->current_state
->res_ctx
, dc
->res_pool
, pipe_ctx
->stream_res
.audio
, false);
1011 /* TODO: notify audio driver for if audio modes list changed
1012 * add audio mode list change flag */
1013 /* dal_audio_disable_azalia_audio_jack_presence(stream->audio,
1014 * stream->stream_engine_id);
1018 if (dc_is_hdmi_signal(pipe_ctx
->stream
->signal
))
1019 pipe_ctx
->stream_res
.stream_enc
->funcs
->stop_hdmi_info_packets(
1020 pipe_ctx
->stream_res
.stream_enc
);
1022 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
1023 pipe_ctx
->stream_res
.stream_enc
->funcs
->stop_dp_info_packets(
1024 pipe_ctx
->stream_res
.stream_enc
);
1026 pipe_ctx
->stream_res
.stream_enc
->funcs
->audio_mute_control(
1027 pipe_ctx
->stream_res
.stream_enc
, true);
1030 /* blank at encoder level */
1031 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
)) {
1032 if (pipe_ctx
->stream
->sink
->link
->connector_signal
== SIGNAL_TYPE_EDP
)
1033 hwss_edp_backlight_control(link
, false);
1034 pipe_ctx
->stream_res
.stream_enc
->funcs
->dp_blank(pipe_ctx
->stream_res
.stream_enc
);
1036 link
->link_enc
->funcs
->connect_dig_be_to_fe(
1038 pipe_ctx
->stream_res
.stream_enc
->id
,
1043 void dce110_unblank_stream(struct pipe_ctx
*pipe_ctx
,
1044 struct dc_link_settings
*link_settings
)
1046 struct encoder_unblank_param params
= { { 0 } };
1047 struct dc_link
*link
= pipe_ctx
->stream
->sink
->link
;
1049 /* only 3 items below are used by unblank */
1050 params
.pixel_clk_khz
=
1051 pipe_ctx
->stream
->timing
.pix_clk_khz
;
1052 params
.link_settings
.link_rate
= link_settings
->link_rate
;
1053 pipe_ctx
->stream_res
.stream_enc
->funcs
->dp_unblank(pipe_ctx
->stream_res
.stream_enc
, ¶ms
);
1054 if (link
->connector_signal
== SIGNAL_TYPE_EDP
)
1055 hwss_edp_backlight_control(link
, true);
1059 void dce110_set_avmute(struct pipe_ctx
*pipe_ctx
, bool enable
)
1061 if (pipe_ctx
!= NULL
&& pipe_ctx
->stream_res
.stream_enc
!= NULL
)
1062 pipe_ctx
->stream_res
.stream_enc
->funcs
->set_avmute(pipe_ctx
->stream_res
.stream_enc
, enable
);
1065 static enum audio_dto_source
translate_to_dto_source(enum controller_id crtc_id
)
1068 case CONTROLLER_ID_D0
:
1069 return DTO_SOURCE_ID0
;
1070 case CONTROLLER_ID_D1
:
1071 return DTO_SOURCE_ID1
;
1072 case CONTROLLER_ID_D2
:
1073 return DTO_SOURCE_ID2
;
1074 case CONTROLLER_ID_D3
:
1075 return DTO_SOURCE_ID3
;
1076 case CONTROLLER_ID_D4
:
1077 return DTO_SOURCE_ID4
;
1078 case CONTROLLER_ID_D5
:
1079 return DTO_SOURCE_ID5
;
1081 return DTO_SOURCE_UNKNOWN
;
1085 static void build_audio_output(
1086 struct dc_state
*state
,
1087 const struct pipe_ctx
*pipe_ctx
,
1088 struct audio_output
*audio_output
)
1090 const struct dc_stream_state
*stream
= pipe_ctx
->stream
;
1091 audio_output
->engine_id
= pipe_ctx
->stream_res
.stream_enc
->id
;
1093 audio_output
->signal
= pipe_ctx
->stream
->signal
;
1095 /* audio_crtc_info */
1097 audio_output
->crtc_info
.h_total
=
1098 stream
->timing
.h_total
;
1101 * Audio packets are sent during actual CRTC blank physical signal, we
1102 * need to specify actual active signal portion
1104 audio_output
->crtc_info
.h_active
=
1105 stream
->timing
.h_addressable
1106 + stream
->timing
.h_border_left
1107 + stream
->timing
.h_border_right
;
1109 audio_output
->crtc_info
.v_active
=
1110 stream
->timing
.v_addressable
1111 + stream
->timing
.v_border_top
1112 + stream
->timing
.v_border_bottom
;
1114 audio_output
->crtc_info
.pixel_repetition
= 1;
1116 audio_output
->crtc_info
.interlaced
=
1117 stream
->timing
.flags
.INTERLACE
;
1119 audio_output
->crtc_info
.refresh_rate
=
1120 (stream
->timing
.pix_clk_khz
*1000)/
1121 (stream
->timing
.h_total
*stream
->timing
.v_total
);
1123 audio_output
->crtc_info
.color_depth
=
1124 stream
->timing
.display_color_depth
;
1126 audio_output
->crtc_info
.requested_pixel_clock
=
1127 pipe_ctx
->stream_res
.pix_clk_params
.requested_pix_clk
;
1129 audio_output
->crtc_info
.calculated_pixel_clock
=
1130 pipe_ctx
->stream_res
.pix_clk_params
.requested_pix_clk
;
1132 /*for HDMI, audio ACR is with deep color ratio factor*/
1133 if (dc_is_hdmi_signal(pipe_ctx
->stream
->signal
) &&
1134 audio_output
->crtc_info
.requested_pixel_clock
==
1135 stream
->timing
.pix_clk_khz
) {
1136 if (pipe_ctx
->stream_res
.pix_clk_params
.pixel_encoding
== PIXEL_ENCODING_YCBCR420
) {
1137 audio_output
->crtc_info
.requested_pixel_clock
=
1138 audio_output
->crtc_info
.requested_pixel_clock
/2;
1139 audio_output
->crtc_info
.calculated_pixel_clock
=
1140 pipe_ctx
->stream_res
.pix_clk_params
.requested_pix_clk
/2;
1145 if (pipe_ctx
->stream
->signal
== SIGNAL_TYPE_DISPLAY_PORT
||
1146 pipe_ctx
->stream
->signal
== SIGNAL_TYPE_DISPLAY_PORT_MST
) {
1147 audio_output
->pll_info
.dp_dto_source_clock_in_khz
=
1148 state
->dis_clk
->funcs
->get_dp_ref_clk_frequency(
1152 audio_output
->pll_info
.feed_back_divider
=
1153 pipe_ctx
->pll_settings
.feedback_divider
;
1155 audio_output
->pll_info
.dto_source
=
1156 translate_to_dto_source(
1157 pipe_ctx
->pipe_idx
+ 1);
1159 /* TODO hard code to enable for now. Need get from stream */
1160 audio_output
->pll_info
.ss_enabled
= true;
1162 audio_output
->pll_info
.ss_percentage
=
1163 pipe_ctx
->pll_settings
.ss_percentage
;
1166 static void get_surface_visual_confirm_color(const struct pipe_ctx
*pipe_ctx
,
1167 struct tg_color
*color
)
1169 uint32_t color_value
= MAX_TG_COLOR_VALUE
* (4 - pipe_ctx
->pipe_idx
) / 4;
1171 switch (pipe_ctx
->plane_res
.scl_data
.format
) {
1172 case PIXEL_FORMAT_ARGB8888
:
1173 /* set boarder color to red */
1174 color
->color_r_cr
= color_value
;
1177 case PIXEL_FORMAT_ARGB2101010
:
1178 /* set boarder color to blue */
1179 color
->color_b_cb
= color_value
;
1181 case PIXEL_FORMAT_420BPP8
:
1182 /* set boarder color to green */
1183 color
->color_g_y
= color_value
;
1185 case PIXEL_FORMAT_420BPP10
:
1186 /* set boarder color to yellow */
1187 color
->color_g_y
= color_value
;
1188 color
->color_r_cr
= color_value
;
1190 case PIXEL_FORMAT_FP16
:
1191 /* set boarder color to white */
1192 color
->color_r_cr
= color_value
;
1193 color
->color_b_cb
= color_value
;
1194 color
->color_g_y
= color_value
;
1201 static void program_scaler(const struct dc
*dc
,
1202 const struct pipe_ctx
*pipe_ctx
)
1204 struct tg_color color
= {0};
1206 #if defined(CONFIG_DRM_AMD_DC_DCN1_0)
1208 if (pipe_ctx
->plane_res
.xfm
->funcs
->transform_set_pixel_storage_depth
== NULL
)
1212 if (dc
->debug
.surface_visual_confirm
)
1213 get_surface_visual_confirm_color(pipe_ctx
, &color
);
1215 color_space_to_black_color(dc
,
1216 pipe_ctx
->stream
->output_color_space
,
1219 pipe_ctx
->plane_res
.xfm
->funcs
->transform_set_pixel_storage_depth(
1220 pipe_ctx
->plane_res
.xfm
,
1221 pipe_ctx
->plane_res
.scl_data
.lb_params
.depth
,
1222 &pipe_ctx
->stream
->bit_depth_params
);
1224 if (pipe_ctx
->stream_res
.tg
->funcs
->set_overscan_blank_color
)
1225 pipe_ctx
->stream_res
.tg
->funcs
->set_overscan_blank_color(
1226 pipe_ctx
->stream_res
.tg
,
1229 pipe_ctx
->plane_res
.xfm
->funcs
->transform_set_scaler(pipe_ctx
->plane_res
.xfm
,
1230 &pipe_ctx
->plane_res
.scl_data
);
1233 static enum dc_status
dce110_prog_pixclk_crtc_otg(
1234 struct pipe_ctx
*pipe_ctx
,
1235 struct dc_state
*context
,
1238 struct dc_stream_state
*stream
= pipe_ctx
->stream
;
1239 struct pipe_ctx
*pipe_ctx_old
= &dc
->current_state
->res_ctx
.
1240 pipe_ctx
[pipe_ctx
->pipe_idx
];
1241 struct tg_color black_color
= {0};
1243 if (!pipe_ctx_old
->stream
) {
1245 /* program blank color */
1246 color_space_to_black_color(dc
,
1247 stream
->output_color_space
, &black_color
);
1248 pipe_ctx
->stream_res
.tg
->funcs
->set_blank_color(
1249 pipe_ctx
->stream_res
.tg
,
1253 * Must blank CRTC after disabling power gating and before any
1254 * programming, otherwise CRTC will be hung in bad state
1256 pipe_ctx
->stream_res
.tg
->funcs
->set_blank(pipe_ctx
->stream_res
.tg
, true);
1258 if (false == pipe_ctx
->clock_source
->funcs
->program_pix_clk(
1259 pipe_ctx
->clock_source
,
1260 &pipe_ctx
->stream_res
.pix_clk_params
,
1261 &pipe_ctx
->pll_settings
)) {
1262 BREAK_TO_DEBUGGER();
1263 return DC_ERROR_UNEXPECTED
;
1266 pipe_ctx
->stream_res
.tg
->funcs
->program_timing(
1267 pipe_ctx
->stream_res
.tg
,
1271 pipe_ctx
->stream_res
.tg
->funcs
->set_static_screen_control(
1272 pipe_ctx
->stream_res
.tg
,
1276 if (!pipe_ctx_old
->stream
) {
1277 if (false == pipe_ctx
->stream_res
.tg
->funcs
->enable_crtc(
1278 pipe_ctx
->stream_res
.tg
)) {
1279 BREAK_TO_DEBUGGER();
1280 return DC_ERROR_UNEXPECTED
;
1289 static enum dc_status
apply_single_controller_ctx_to_hw(
1290 struct pipe_ctx
*pipe_ctx
,
1291 struct dc_state
*context
,
1294 struct dc_stream_state
*stream
= pipe_ctx
->stream
;
1295 struct pipe_ctx
*pipe_ctx_old
= &dc
->current_state
->res_ctx
.
1296 pipe_ctx
[pipe_ctx
->pipe_idx
];
1299 dc
->hwss
.prog_pixclk_crtc_otg(pipe_ctx
, context
, dc
);
1301 /* FPGA does not program backend */
1302 if (IS_FPGA_MAXIMUS_DC(dc
->ctx
->dce_environment
)) {
1303 pipe_ctx
->stream_res
.opp
->funcs
->opp_set_dyn_expansion(
1304 pipe_ctx
->stream_res
.opp
,
1305 COLOR_SPACE_YCBCR601
,
1306 stream
->timing
.display_color_depth
,
1307 pipe_ctx
->stream
->signal
);
1309 pipe_ctx
->stream_res
.opp
->funcs
->opp_program_fmt(
1310 pipe_ctx
->stream_res
.opp
,
1311 &stream
->bit_depth_params
,
1315 /* TODO: move to stream encoder */
1316 if (pipe_ctx
->stream
->signal
!= SIGNAL_TYPE_VIRTUAL
)
1317 if (DC_OK
!= bios_parser_crtc_source_select(pipe_ctx
)) {
1318 BREAK_TO_DEBUGGER();
1319 return DC_ERROR_UNEXPECTED
;
1321 pipe_ctx
->stream_res
.opp
->funcs
->opp_set_dyn_expansion(
1322 pipe_ctx
->stream_res
.opp
,
1323 COLOR_SPACE_YCBCR601
,
1324 stream
->timing
.display_color_depth
,
1325 pipe_ctx
->stream
->signal
);
1327 if (pipe_ctx
->stream
->signal
!= SIGNAL_TYPE_VIRTUAL
)
1328 stream
->sink
->link
->link_enc
->funcs
->setup(
1329 stream
->sink
->link
->link_enc
,
1330 pipe_ctx
->stream
->signal
);
1332 if (pipe_ctx
->stream
->signal
!= SIGNAL_TYPE_VIRTUAL
)
1333 pipe_ctx
->stream_res
.stream_enc
->funcs
->setup_stereo_sync(
1334 pipe_ctx
->stream_res
.stream_enc
,
1335 pipe_ctx
->stream_res
.tg
->inst
,
1336 stream
->timing
.timing_3d_format
!= TIMING_3D_FORMAT_NONE
);
1339 pipe_ctx
->stream_res
.opp
->funcs
->opp_program_fmt(
1340 pipe_ctx
->stream_res
.opp
,
1341 &stream
->bit_depth_params
,
1344 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
1345 pipe_ctx
->stream_res
.stream_enc
->funcs
->dp_set_stream_attribute(
1346 pipe_ctx
->stream_res
.stream_enc
,
1348 stream
->output_color_space
);
1350 if (dc_is_hdmi_signal(pipe_ctx
->stream
->signal
))
1351 pipe_ctx
->stream_res
.stream_enc
->funcs
->hdmi_set_stream_attribute(
1352 pipe_ctx
->stream_res
.stream_enc
,
1354 stream
->phy_pix_clk
,
1355 pipe_ctx
->stream_res
.audio
!= NULL
);
1357 if (dc_is_dvi_signal(pipe_ctx
->stream
->signal
))
1358 pipe_ctx
->stream_res
.stream_enc
->funcs
->dvi_set_stream_attribute(
1359 pipe_ctx
->stream_res
.stream_enc
,
1361 (pipe_ctx
->stream
->signal
== SIGNAL_TYPE_DVI_DUAL_LINK
) ?
1364 resource_build_info_frame(pipe_ctx
);
1365 dce110_update_info_frame(pipe_ctx
);
1366 if (!pipe_ctx_old
->stream
) {
1367 if (!pipe_ctx
->stream
->dpms_off
)
1368 core_link_enable_stream(context
, pipe_ctx
);
1371 pipe_ctx
->plane_res
.scl_data
.lb_params
.alpha_en
= pipe_ctx
->bottom_pipe
!= 0;
1373 /* mst support - use total stream count */
1374 if (pipe_ctx
->plane_res
.mi
!= NULL
) {
1375 pipe_ctx
->plane_res
.mi
->funcs
->allocate_mem_input(
1376 pipe_ctx
->plane_res
.mi
,
1377 stream
->timing
.h_total
,
1378 stream
->timing
.v_total
,
1379 stream
->timing
.pix_clk_khz
,
1380 context
->stream_count
);
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
, dc
->links
[i
]);
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 /* Only for non-linear tiling */
1788 if (pipe_ctx
->plane_state
->tiling_info
.gfx8
.array_mode
== DC_ARRAY_LINEAR_GENERAL
)
1789 return DC_ERROR_UNEXPECTED
;
1797 static enum dc_status
enable_fbc(struct dc
*dc
,
1798 struct dc_state
*context
)
1800 enum dc_status status
= validate_fbc(dc
, context
);
1802 if (status
== DC_OK
) {
1803 /* Program GRPH COMPRESSED ADDRESS and PITCH */
1804 struct compr_addr_and_pitch_params params
= {0, 0, 0};
1805 struct compressor
*compr
= dc
->fbc_compressor
;
1806 struct pipe_ctx
*pipe_ctx
=
1807 &context
->res_ctx
.pipe_ctx
[0];
1809 params
.source_view_width
=
1810 pipe_ctx
->stream
->timing
.h_addressable
;
1811 params
.source_view_height
=
1812 pipe_ctx
->stream
->timing
.v_addressable
;
1814 compr
->compr_surface_address
.quad_part
= dc
->ctx
->fbc_gpu_addr
;
1816 compr
->funcs
->surface_address_and_pitch(compr
, ¶ms
);
1817 compr
->funcs
->set_fbc_invalidation_triggers(compr
, 1);
1819 compr
->funcs
->enable_fbc(compr
, ¶ms
);
1825 static enum dc_status
apply_ctx_to_hw_fpga(
1827 struct dc_state
*context
)
1829 enum dc_status status
= DC_ERROR_UNEXPECTED
;
1832 for (i
= 0; i
< MAX_PIPES
; i
++) {
1833 struct pipe_ctx
*pipe_ctx_old
=
1834 &dc
->current_state
->res_ctx
.pipe_ctx
[i
];
1835 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
1837 if (pipe_ctx
->stream
== NULL
)
1840 if (pipe_ctx
->stream
== pipe_ctx_old
->stream
)
1843 status
= apply_single_controller_ctx_to_hw(
1848 if (status
!= DC_OK
)
1855 static void dce110_reset_hw_ctx_wrap(
1857 struct dc_state
*context
)
1861 /* Reset old context */
1862 /* look up the targets that have been removed since last commit */
1863 for (i
= 0; i
< MAX_PIPES
; i
++) {
1864 struct pipe_ctx
*pipe_ctx_old
=
1865 &dc
->current_state
->res_ctx
.pipe_ctx
[i
];
1866 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
1868 /* Note: We need to disable output if clock sources change,
1869 * since bios does optimization and doesn't apply if changing
1870 * PHY when not already disabled.
1873 /* Skip underlay pipe since it will be handled in commit surface*/
1874 if (!pipe_ctx_old
->stream
|| pipe_ctx_old
->top_pipe
)
1877 if (!pipe_ctx
->stream
||
1878 pipe_need_reprogram(pipe_ctx_old
, pipe_ctx
)) {
1879 struct clock_source
*old_clk
= pipe_ctx_old
->clock_source
;
1881 /* disable already, no need to disable again */
1882 if (pipe_ctx
->stream
&& !pipe_ctx
->stream
->dpms_off
)
1883 core_link_disable_stream(pipe_ctx_old
, FREE_ACQUIRED_RESOURCE
);
1885 pipe_ctx_old
->stream_res
.tg
->funcs
->set_blank(pipe_ctx_old
->stream_res
.tg
, true);
1886 if (!hwss_wait_for_blank_complete(pipe_ctx_old
->stream_res
.tg
)) {
1887 dm_error("DC: failed to blank crtc!\n");
1888 BREAK_TO_DEBUGGER();
1890 pipe_ctx_old
->stream_res
.tg
->funcs
->disable_crtc(pipe_ctx_old
->stream_res
.tg
);
1891 pipe_ctx_old
->plane_res
.mi
->funcs
->free_mem_input(
1892 pipe_ctx_old
->plane_res
.mi
, dc
->current_state
->stream_count
);
1895 old_clk
->funcs
->cs_power_down(old_clk
);
1897 dc
->hwss
.power_down_front_end(dc
, pipe_ctx_old
->pipe_idx
);
1899 pipe_ctx_old
->stream
= NULL
;
1905 enum dc_status
dce110_apply_ctx_to_hw(
1907 struct dc_state
*context
)
1909 struct dc_bios
*dcb
= dc
->ctx
->dc_bios
;
1910 enum dc_status status
;
1912 enum dm_pp_clocks_state clocks_state
= DM_PP_CLOCKS_STATE_INVALID
;
1914 /* Reset old context */
1915 /* look up the targets that have been removed since last commit */
1916 dc
->hwss
.reset_hw_ctx_wrap(dc
, context
);
1918 /* Skip applying if no targets */
1919 if (context
->stream_count
<= 0)
1922 if (IS_FPGA_MAXIMUS_DC(dc
->ctx
->dce_environment
)) {
1923 apply_ctx_to_hw_fpga(dc
, context
);
1927 /* Apply new context */
1928 dcb
->funcs
->set_scratch_critical_state(dcb
, true);
1930 /* below is for real asic only */
1931 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
1932 struct pipe_ctx
*pipe_ctx_old
=
1933 &dc
->current_state
->res_ctx
.pipe_ctx
[i
];
1934 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
1936 if (pipe_ctx
->stream
== NULL
|| pipe_ctx
->top_pipe
)
1939 if (pipe_ctx
->stream
== pipe_ctx_old
->stream
) {
1940 if (pipe_ctx_old
->clock_source
!= pipe_ctx
->clock_source
)
1941 dce_crtc_switch_to_clk_src(dc
->hwseq
,
1942 pipe_ctx
->clock_source
, i
);
1946 dc
->hwss
.enable_display_power_gating(
1947 dc
, i
, dc
->ctx
->dc_bios
,
1948 PIPE_GATING_CONTROL_DISABLE
);
1951 set_safe_displaymarks(&context
->res_ctx
, dc
->res_pool
);
1953 #if defined(CONFIG_DRM_AMD_DC_FBC)
1954 if (dc
->fbc_compressor
)
1955 dc
->fbc_compressor
->funcs
->disable_fbc(dc
->fbc_compressor
);
1957 /*TODO: when pplib works*/
1958 apply_min_clocks(dc
, context
, &clocks_state
, true);
1960 #if defined(CONFIG_DRM_AMD_DC_DCN1_0)
1961 if (dc
->ctx
->dce_version
>= DCN_VERSION_1_0
) {
1962 if (context
->bw
.dcn
.calc_clk
.fclk_khz
1963 > dc
->current_state
->bw
.dcn
.cur_clk
.fclk_khz
) {
1964 struct dm_pp_clock_for_voltage_req clock
;
1966 clock
.clk_type
= DM_PP_CLOCK_TYPE_FCLK
;
1967 clock
.clocks_in_khz
= context
->bw
.dcn
.calc_clk
.fclk_khz
;
1968 dm_pp_apply_clock_for_voltage_request(dc
->ctx
, &clock
);
1969 dc
->current_state
->bw
.dcn
.cur_clk
.fclk_khz
= clock
.clocks_in_khz
;
1970 context
->bw
.dcn
.cur_clk
.fclk_khz
= clock
.clocks_in_khz
;
1972 if (context
->bw
.dcn
.calc_clk
.dcfclk_khz
1973 > dc
->current_state
->bw
.dcn
.cur_clk
.dcfclk_khz
) {
1974 struct dm_pp_clock_for_voltage_req clock
;
1976 clock
.clk_type
= DM_PP_CLOCK_TYPE_DCFCLK
;
1977 clock
.clocks_in_khz
= context
->bw
.dcn
.calc_clk
.dcfclk_khz
;
1978 dm_pp_apply_clock_for_voltage_request(dc
->ctx
, &clock
);
1979 dc
->current_state
->bw
.dcn
.cur_clk
.dcfclk_khz
= clock
.clocks_in_khz
;
1980 context
->bw
.dcn
.cur_clk
.dcfclk_khz
= clock
.clocks_in_khz
;
1982 if (context
->bw
.dcn
.calc_clk
.dispclk_khz
1983 > dc
->current_state
->bw
.dcn
.cur_clk
.dispclk_khz
) {
1984 dc
->res_pool
->display_clock
->funcs
->set_clock(
1985 dc
->res_pool
->display_clock
,
1986 context
->bw
.dcn
.calc_clk
.dispclk_khz
);
1987 dc
->current_state
->bw
.dcn
.cur_clk
.dispclk_khz
=
1988 context
->bw
.dcn
.calc_clk
.dispclk_khz
;
1989 context
->bw
.dcn
.cur_clk
.dispclk_khz
=
1990 context
->bw
.dcn
.calc_clk
.dispclk_khz
;
1994 if (context
->bw
.dce
.dispclk_khz
1995 > dc
->current_state
->bw
.dce
.dispclk_khz
) {
1996 dc
->res_pool
->display_clock
->funcs
->set_clock(
1997 dc
->res_pool
->display_clock
,
1998 context
->bw
.dce
.dispclk_khz
* 115 / 100);
2000 /* program audio wall clock. use HDMI as clock source if HDMI
2001 * audio active. Otherwise, use DP as clock source
2002 * first, loop to find any HDMI audio, if not, loop find DP audio
2004 /* Setup audio rate clock source */
2006 * Audio lag happened on DP monitor when unplug a HDMI monitor
2009 * In case of DP and HDMI connected or HDMI only, DCCG_AUDIO_DTO_SEL
2010 * is set to either dto0 or dto1, audio should work fine.
2011 * In case of DP connected only, DCCG_AUDIO_DTO_SEL should be dto1,
2012 * set to dto0 will cause audio lag.
2015 * Not optimized audio wall dto setup. When mode set, iterate pipe_ctx,
2016 * find first available pipe with audio, setup audio wall DTO per topology
2017 * instead of per pipe.
2019 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
2020 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
2022 if (pipe_ctx
->stream
== NULL
)
2025 if (pipe_ctx
->top_pipe
)
2028 if (pipe_ctx
->stream
->signal
!= SIGNAL_TYPE_HDMI_TYPE_A
)
2031 if (pipe_ctx
->stream_res
.audio
!= NULL
) {
2032 struct audio_output audio_output
;
2034 build_audio_output(context
, pipe_ctx
, &audio_output
);
2036 pipe_ctx
->stream_res
.audio
->funcs
->wall_dto_setup(
2037 pipe_ctx
->stream_res
.audio
,
2038 pipe_ctx
->stream
->signal
,
2039 &audio_output
.crtc_info
,
2040 &audio_output
.pll_info
);
2045 /* no HDMI audio is found, try DP audio */
2046 if (i
== dc
->res_pool
->pipe_count
) {
2047 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
2048 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
2050 if (pipe_ctx
->stream
== NULL
)
2053 if (pipe_ctx
->top_pipe
)
2056 if (!dc_is_dp_signal(pipe_ctx
->stream
->signal
))
2059 if (pipe_ctx
->stream_res
.audio
!= NULL
) {
2060 struct audio_output audio_output
;
2062 build_audio_output(context
, pipe_ctx
, &audio_output
);
2064 pipe_ctx
->stream_res
.audio
->funcs
->wall_dto_setup(
2065 pipe_ctx
->stream_res
.audio
,
2066 pipe_ctx
->stream
->signal
,
2067 &audio_output
.crtc_info
,
2068 &audio_output
.pll_info
);
2074 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
2075 struct pipe_ctx
*pipe_ctx_old
=
2076 &dc
->current_state
->res_ctx
.pipe_ctx
[i
];
2077 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
2079 if (pipe_ctx
->stream
== NULL
)
2082 if (pipe_ctx
->stream
== pipe_ctx_old
->stream
)
2085 if (pipe_ctx
->stream
&& pipe_ctx_old
->stream
2086 && !pipe_need_reprogram(pipe_ctx_old
, pipe_ctx
))
2089 if (pipe_ctx
->top_pipe
)
2092 if (context
->res_ctx
.pipe_ctx
[i
].stream_res
.audio
!= NULL
) {
2094 struct audio_output audio_output
;
2096 build_audio_output(context
, pipe_ctx
, &audio_output
);
2098 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
2099 pipe_ctx
->stream_res
.stream_enc
->funcs
->dp_audio_setup(
2100 pipe_ctx
->stream_res
.stream_enc
,
2101 pipe_ctx
->stream_res
.audio
->inst
,
2102 &pipe_ctx
->stream
->audio_info
);
2104 pipe_ctx
->stream_res
.stream_enc
->funcs
->hdmi_audio_setup(
2105 pipe_ctx
->stream_res
.stream_enc
,
2106 pipe_ctx
->stream_res
.audio
->inst
,
2107 &pipe_ctx
->stream
->audio_info
,
2108 &audio_output
.crtc_info
);
2110 pipe_ctx
->stream_res
.audio
->funcs
->az_configure(
2111 pipe_ctx
->stream_res
.audio
,
2112 pipe_ctx
->stream
->signal
,
2113 &audio_output
.crtc_info
,
2114 &pipe_ctx
->stream
->audio_info
);
2117 status
= apply_single_controller_ctx_to_hw(
2122 if (dc
->hwss
.power_on_front_end
)
2123 dc
->hwss
.power_on_front_end(dc
, pipe_ctx
, context
);
2125 if (DC_OK
!= status
)
2129 /* pplib is notified if disp_num changed */
2130 dc
->hwss
.set_bandwidth(dc
, context
, true);
2133 apply_min_clocks(dc
, context
, &clocks_state
, false);
2135 dcb
->funcs
->set_scratch_critical_state(dcb
, false);
2137 #if defined(CONFIG_DRM_AMD_DC_FBC)
2138 if (dc
->fbc_compressor
)
2139 enable_fbc(dc
, context
);
2146 /*******************************************************************************
2147 * Front End programming
2148 ******************************************************************************/
2149 static void set_default_colors(struct pipe_ctx
*pipe_ctx
)
2151 struct default_adjustment default_adjust
= { 0 };
2153 default_adjust
.force_hw_default
= false;
2154 if (pipe_ctx
->plane_state
== NULL
)
2155 default_adjust
.in_color_space
= COLOR_SPACE_SRGB
;
2157 default_adjust
.in_color_space
=
2158 pipe_ctx
->plane_state
->color_space
;
2159 if (pipe_ctx
->stream
== NULL
)
2160 default_adjust
.out_color_space
= COLOR_SPACE_SRGB
;
2162 default_adjust
.out_color_space
=
2163 pipe_ctx
->stream
->output_color_space
;
2164 default_adjust
.csc_adjust_type
= GRAPHICS_CSC_ADJUST_TYPE_SW
;
2165 default_adjust
.surface_pixel_format
= pipe_ctx
->plane_res
.scl_data
.format
;
2167 /* display color depth */
2168 default_adjust
.color_depth
=
2169 pipe_ctx
->stream
->timing
.display_color_depth
;
2171 /* Lb color depth */
2172 default_adjust
.lb_color_depth
= pipe_ctx
->plane_res
.scl_data
.lb_params
.depth
;
2174 pipe_ctx
->plane_res
.xfm
->funcs
->opp_set_csc_default(
2175 pipe_ctx
->plane_res
.xfm
, &default_adjust
);
2179 /*******************************************************************************
2180 * In order to turn on/off specific surface we will program
2183 * In case that we have two surfaces and they have a different visibility
2184 * we can't turn off the CRTC since it will turn off the entire display
2186 * |----------------------------------------------- |
2187 * |bottom pipe|curr pipe | | |
2188 * |Surface |Surface | Blender | CRCT |
2189 * |visibility |visibility | Configuration| |
2190 * |------------------------------------------------|
2191 * | off | off | CURRENT_PIPE | blank |
2192 * | off | on | CURRENT_PIPE | unblank |
2193 * | on | off | OTHER_PIPE | unblank |
2194 * | on | on | BLENDING | unblank |
2195 * -------------------------------------------------|
2197 ******************************************************************************/
2198 static void program_surface_visibility(const struct dc
*dc
,
2199 struct pipe_ctx
*pipe_ctx
)
2201 enum blnd_mode blender_mode
= BLND_MODE_CURRENT_PIPE
;
2202 bool blank_target
= false;
2204 if (pipe_ctx
->bottom_pipe
) {
2206 /* For now we are supporting only two pipes */
2207 ASSERT(pipe_ctx
->bottom_pipe
->bottom_pipe
== NULL
);
2209 if (pipe_ctx
->bottom_pipe
->plane_state
->visible
) {
2210 if (pipe_ctx
->plane_state
->visible
)
2211 blender_mode
= BLND_MODE_BLENDING
;
2213 blender_mode
= BLND_MODE_OTHER_PIPE
;
2215 } else if (!pipe_ctx
->plane_state
->visible
)
2216 blank_target
= true;
2218 } else if (!pipe_ctx
->plane_state
->visible
)
2219 blank_target
= true;
2221 dce_set_blender_mode(dc
->hwseq
, pipe_ctx
->pipe_idx
, blender_mode
);
2222 pipe_ctx
->stream_res
.tg
->funcs
->set_blank(pipe_ctx
->stream_res
.tg
, blank_target
);
2226 static void program_gamut_remap(struct pipe_ctx
*pipe_ctx
)
2228 struct xfm_grph_csc_adjustment adjust
;
2229 memset(&adjust
, 0, sizeof(adjust
));
2230 adjust
.gamut_adjust_type
= GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS
;
2233 if (pipe_ctx
->stream
->gamut_remap_matrix
.enable_remap
== true) {
2234 adjust
.gamut_adjust_type
= GRAPHICS_GAMUT_ADJUST_TYPE_SW
;
2235 adjust
.temperature_matrix
[0] =
2237 gamut_remap_matrix
.matrix
[0];
2238 adjust
.temperature_matrix
[1] =
2240 gamut_remap_matrix
.matrix
[1];
2241 adjust
.temperature_matrix
[2] =
2243 gamut_remap_matrix
.matrix
[2];
2244 adjust
.temperature_matrix
[3] =
2246 gamut_remap_matrix
.matrix
[4];
2247 adjust
.temperature_matrix
[4] =
2249 gamut_remap_matrix
.matrix
[5];
2250 adjust
.temperature_matrix
[5] =
2252 gamut_remap_matrix
.matrix
[6];
2253 adjust
.temperature_matrix
[6] =
2255 gamut_remap_matrix
.matrix
[8];
2256 adjust
.temperature_matrix
[7] =
2258 gamut_remap_matrix
.matrix
[9];
2259 adjust
.temperature_matrix
[8] =
2261 gamut_remap_matrix
.matrix
[10];
2264 pipe_ctx
->plane_res
.xfm
->funcs
->transform_set_gamut_remap(pipe_ctx
->plane_res
.xfm
, &adjust
);
2268 * TODO REMOVE, USE UPDATE INSTEAD
2270 static void set_plane_config(
2271 const struct dc
*dc
,
2272 struct pipe_ctx
*pipe_ctx
,
2273 struct resource_context
*res_ctx
)
2275 struct mem_input
*mi
= pipe_ctx
->plane_res
.mi
;
2276 struct dc_plane_state
*plane_state
= pipe_ctx
->plane_state
;
2277 struct xfm_grph_csc_adjustment adjust
;
2278 struct out_csc_color_matrix tbl_entry
;
2281 memset(&adjust
, 0, sizeof(adjust
));
2282 memset(&tbl_entry
, 0, sizeof(tbl_entry
));
2283 adjust
.gamut_adjust_type
= GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS
;
2285 dce_enable_fe_clock(dc
->hwseq
, pipe_ctx
->pipe_idx
, true);
2287 set_default_colors(pipe_ctx
);
2288 if (pipe_ctx
->stream
->csc_color_matrix
.enable_adjustment
2290 tbl_entry
.color_space
=
2291 pipe_ctx
->stream
->output_color_space
;
2293 for (i
= 0; i
< 12; i
++)
2294 tbl_entry
.regval
[i
] =
2295 pipe_ctx
->stream
->csc_color_matrix
.matrix
[i
];
2297 pipe_ctx
->plane_res
.xfm
->funcs
->opp_set_csc_adjustment
2298 (pipe_ctx
->plane_res
.xfm
, &tbl_entry
);
2301 if (pipe_ctx
->stream
->gamut_remap_matrix
.enable_remap
== true) {
2302 adjust
.gamut_adjust_type
= GRAPHICS_GAMUT_ADJUST_TYPE_SW
;
2303 adjust
.temperature_matrix
[0] =
2305 gamut_remap_matrix
.matrix
[0];
2306 adjust
.temperature_matrix
[1] =
2308 gamut_remap_matrix
.matrix
[1];
2309 adjust
.temperature_matrix
[2] =
2311 gamut_remap_matrix
.matrix
[2];
2312 adjust
.temperature_matrix
[3] =
2314 gamut_remap_matrix
.matrix
[4];
2315 adjust
.temperature_matrix
[4] =
2317 gamut_remap_matrix
.matrix
[5];
2318 adjust
.temperature_matrix
[5] =
2320 gamut_remap_matrix
.matrix
[6];
2321 adjust
.temperature_matrix
[6] =
2323 gamut_remap_matrix
.matrix
[8];
2324 adjust
.temperature_matrix
[7] =
2326 gamut_remap_matrix
.matrix
[9];
2327 adjust
.temperature_matrix
[8] =
2329 gamut_remap_matrix
.matrix
[10];
2332 pipe_ctx
->plane_res
.xfm
->funcs
->transform_set_gamut_remap(pipe_ctx
->plane_res
.xfm
, &adjust
);
2334 pipe_ctx
->plane_res
.scl_data
.lb_params
.alpha_en
= pipe_ctx
->bottom_pipe
!= 0;
2335 program_scaler(dc
, pipe_ctx
);
2337 program_surface_visibility(dc
, pipe_ctx
);
2339 mi
->funcs
->mem_input_program_surface_config(
2341 plane_state
->format
,
2342 &plane_state
->tiling_info
,
2343 &plane_state
->plane_size
,
2344 plane_state
->rotation
,
2347 if (mi
->funcs
->set_blank
)
2348 mi
->funcs
->set_blank(mi
, pipe_ctx
->plane_state
->visible
);
2350 if (dc
->config
.gpu_vm_support
)
2351 mi
->funcs
->mem_input_program_pte_vm(
2352 pipe_ctx
->plane_res
.mi
,
2353 plane_state
->format
,
2354 &plane_state
->tiling_info
,
2355 plane_state
->rotation
);
2358 static void update_plane_addr(const struct dc
*dc
,
2359 struct pipe_ctx
*pipe_ctx
)
2361 struct dc_plane_state
*plane_state
= pipe_ctx
->plane_state
;
2363 if (plane_state
== NULL
)
2366 pipe_ctx
->plane_res
.mi
->funcs
->mem_input_program_surface_flip_and_addr(
2367 pipe_ctx
->plane_res
.mi
,
2368 &plane_state
->address
,
2369 plane_state
->flip_immediate
);
2371 plane_state
->status
.requested_address
= plane_state
->address
;
2374 void dce110_update_pending_status(struct pipe_ctx
*pipe_ctx
)
2376 struct dc_plane_state
*plane_state
= pipe_ctx
->plane_state
;
2378 if (plane_state
== NULL
)
2381 plane_state
->status
.is_flip_pending
=
2382 pipe_ctx
->plane_res
.mi
->funcs
->mem_input_is_flip_pending(
2383 pipe_ctx
->plane_res
.mi
);
2385 if (plane_state
->status
.is_flip_pending
&& !plane_state
->visible
)
2386 pipe_ctx
->plane_res
.mi
->current_address
= pipe_ctx
->plane_res
.mi
->request_address
;
2388 plane_state
->status
.current_address
= pipe_ctx
->plane_res
.mi
->current_address
;
2389 if (pipe_ctx
->plane_res
.mi
->current_address
.type
== PLN_ADDR_TYPE_GRPH_STEREO
&&
2390 pipe_ctx
->stream_res
.tg
->funcs
->is_stereo_left_eye
) {
2391 plane_state
->status
.is_right_eye
=\
2392 !pipe_ctx
->stream_res
.tg
->funcs
->is_stereo_left_eye(pipe_ctx
->stream_res
.tg
);
2396 void dce110_power_down(struct dc
*dc
)
2398 power_down_all_hw_blocks(dc
);
2399 disable_vga_and_power_gate_all_controllers(dc
);
2402 static bool wait_for_reset_trigger_to_occur(
2403 struct dc_context
*dc_ctx
,
2404 struct timing_generator
*tg
)
2408 /* To avoid endless loop we wait at most
2409 * frames_to_wait_on_triggered_reset frames for the reset to occur. */
2410 const uint32_t frames_to_wait_on_triggered_reset
= 10;
2413 for (i
= 0; i
< frames_to_wait_on_triggered_reset
; i
++) {
2415 if (!tg
->funcs
->is_counter_moving(tg
)) {
2416 DC_ERROR("TG counter is not moving!\n");
2420 if (tg
->funcs
->did_triggered_reset_occur(tg
)) {
2422 /* usually occurs at i=1 */
2423 DC_SYNC_INFO("GSL: reset occurred at wait count: %d\n",
2428 /* Wait for one frame. */
2429 tg
->funcs
->wait_for_state(tg
, CRTC_STATE_VACTIVE
);
2430 tg
->funcs
->wait_for_state(tg
, CRTC_STATE_VBLANK
);
2434 DC_ERROR("GSL: Timeout on reset trigger!\n");
2439 /* Enable timing synchronization for a group of Timing Generators. */
2440 static void dce110_enable_timing_synchronization(
2444 struct pipe_ctx
*grouped_pipes
[])
2446 struct dc_context
*dc_ctx
= dc
->ctx
;
2447 struct dcp_gsl_params gsl_params
= { 0 };
2450 DC_SYNC_INFO("GSL: Setting-up...\n");
2452 /* Designate a single TG in the group as a master.
2453 * Since HW doesn't care which one, we always assign
2454 * the 1st one in the group. */
2455 gsl_params
.gsl_group
= 0;
2456 gsl_params
.gsl_master
= grouped_pipes
[0]->stream_res
.tg
->inst
;
2458 for (i
= 0; i
< group_size
; i
++)
2459 grouped_pipes
[i
]->stream_res
.tg
->funcs
->setup_global_swap_lock(
2460 grouped_pipes
[i
]->stream_res
.tg
, &gsl_params
);
2462 /* Reset slave controllers on master VSync */
2463 DC_SYNC_INFO("GSL: enabling trigger-reset\n");
2465 for (i
= 1 /* skip the master */; i
< group_size
; i
++)
2466 grouped_pipes
[i
]->stream_res
.tg
->funcs
->enable_reset_trigger(
2467 grouped_pipes
[i
]->stream_res
.tg
, gsl_params
.gsl_group
);
2471 for (i
= 1 /* skip the master */; i
< group_size
; i
++) {
2472 DC_SYNC_INFO("GSL: waiting for reset to occur.\n");
2473 wait_for_reset_trigger_to_occur(dc_ctx
, grouped_pipes
[i
]->stream_res
.tg
);
2474 /* Regardless of success of the wait above, remove the reset or
2475 * the driver will start timing out on Display requests. */
2476 DC_SYNC_INFO("GSL: disabling trigger-reset.\n");
2477 grouped_pipes
[i
]->stream_res
.tg
->funcs
->disable_reset_trigger(grouped_pipes
[i
]->stream_res
.tg
);
2481 /* GSL Vblank synchronization is a one time sync mechanism, assumption
2482 * is that the sync'ed displays will not drift out of sync over time*/
2483 DC_SYNC_INFO("GSL: Restoring register states.\n");
2484 for (i
= 0; i
< group_size
; i
++)
2485 grouped_pipes
[i
]->stream_res
.tg
->funcs
->tear_down_global_swap_lock(grouped_pipes
[i
]->stream_res
.tg
);
2487 DC_SYNC_INFO("GSL: Set-up complete.\n");
2490 static void init_hw(struct dc
*dc
)
2494 struct transform
*xfm
;
2497 bp
= dc
->ctx
->dc_bios
;
2498 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
2499 xfm
= dc
->res_pool
->transforms
[i
];
2500 xfm
->funcs
->transform_reset(xfm
);
2502 dc
->hwss
.enable_display_power_gating(
2504 PIPE_GATING_CONTROL_INIT
);
2505 dc
->hwss
.enable_display_power_gating(
2507 PIPE_GATING_CONTROL_DISABLE
);
2508 dc
->hwss
.enable_display_pipe_clock_gating(
2513 dce_clock_gating_power_up(dc
->hwseq
, false);
2514 /***************************************/
2516 for (i
= 0; i
< dc
->link_count
; i
++) {
2517 /****************************************/
2518 /* Power up AND update implementation according to the
2519 * required signal (which may be different from the
2520 * default signal on connector). */
2521 struct dc_link
*link
= dc
->links
[i
];
2522 link
->link_enc
->funcs
->hw_init(link
->link_enc
);
2525 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
2526 struct timing_generator
*tg
= dc
->res_pool
->timing_generators
[i
];
2528 tg
->funcs
->disable_vga(tg
);
2530 /* Blank controller using driver code instead of
2532 tg
->funcs
->set_blank(tg
, true);
2533 hwss_wait_for_blank_complete(tg
);
2536 for (i
= 0; i
< dc
->res_pool
->audio_count
; i
++) {
2537 struct audio
*audio
= dc
->res_pool
->audios
[i
];
2538 audio
->funcs
->hw_init(audio
);
2541 abm
= dc
->res_pool
->abm
;
2543 abm
->funcs
->init_backlight(abm
);
2544 abm
->funcs
->abm_init(abm
);
2546 #if defined(CONFIG_DRM_AMD_DC_FBC)
2547 if (dc
->fbc_compressor
)
2548 dc
->fbc_compressor
->funcs
->power_up_fbc(dc
->fbc_compressor
);
2553 void dce110_fill_display_configs(
2554 const struct dc_state
*context
,
2555 struct dm_pp_display_configuration
*pp_display_cfg
)
2560 for (j
= 0; j
< context
->stream_count
; j
++) {
2563 const struct dc_stream_state
*stream
= context
->streams
[j
];
2564 struct dm_pp_single_disp_config
*cfg
=
2565 &pp_display_cfg
->disp_configs
[num_cfgs
];
2566 const struct pipe_ctx
*pipe_ctx
= NULL
;
2568 for (k
= 0; k
< MAX_PIPES
; k
++)
2569 if (stream
== context
->res_ctx
.pipe_ctx
[k
].stream
) {
2570 pipe_ctx
= &context
->res_ctx
.pipe_ctx
[k
];
2574 ASSERT(pipe_ctx
!= NULL
);
2577 cfg
->signal
= pipe_ctx
->stream
->signal
;
2578 cfg
->pipe_idx
= pipe_ctx
->pipe_idx
;
2579 cfg
->src_height
= stream
->src
.height
;
2580 cfg
->src_width
= stream
->src
.width
;
2581 cfg
->ddi_channel_mapping
=
2582 stream
->sink
->link
->ddi_channel_mapping
.raw
;
2584 stream
->sink
->link
->link_enc
->transmitter
;
2585 cfg
->link_settings
.lane_count
=
2586 stream
->sink
->link
->cur_link_settings
.lane_count
;
2587 cfg
->link_settings
.link_rate
=
2588 stream
->sink
->link
->cur_link_settings
.link_rate
;
2589 cfg
->link_settings
.link_spread
=
2590 stream
->sink
->link
->cur_link_settings
.link_spread
;
2591 cfg
->sym_clock
= stream
->phy_pix_clk
;
2592 /* Round v_refresh*/
2593 cfg
->v_refresh
= stream
->timing
.pix_clk_khz
* 1000;
2594 cfg
->v_refresh
/= stream
->timing
.h_total
;
2595 cfg
->v_refresh
= (cfg
->v_refresh
+ stream
->timing
.v_total
/ 2)
2596 / stream
->timing
.v_total
;
2599 pp_display_cfg
->display_count
= num_cfgs
;
2602 uint32_t dce110_get_min_vblank_time_us(const struct dc_state
*context
)
2605 uint32_t min_vertical_blank_time
= -1;
2607 for (j
= 0; j
< context
->stream_count
; j
++) {
2608 struct dc_stream_state
*stream
= context
->streams
[j
];
2609 uint32_t vertical_blank_in_pixels
= 0;
2610 uint32_t vertical_blank_time
= 0;
2612 vertical_blank_in_pixels
= stream
->timing
.h_total
*
2613 (stream
->timing
.v_total
2614 - stream
->timing
.v_addressable
);
2616 vertical_blank_time
= vertical_blank_in_pixels
2617 * 1000 / stream
->timing
.pix_clk_khz
;
2619 if (min_vertical_blank_time
> vertical_blank_time
)
2620 min_vertical_blank_time
= vertical_blank_time
;
2623 return min_vertical_blank_time
;
2626 static int determine_sclk_from_bounding_box(
2627 const struct dc
*dc
,
2633 * Some asics do not give us sclk levels, so we just report the actual
2636 if (dc
->sclk_lvls
.num_levels
== 0)
2637 return required_sclk
;
2639 for (i
= 0; i
< dc
->sclk_lvls
.num_levels
; i
++) {
2640 if (dc
->sclk_lvls
.clocks_in_khz
[i
] >= required_sclk
)
2641 return dc
->sclk_lvls
.clocks_in_khz
[i
];
2644 * even maximum level could not satisfy requirement, this
2645 * is unexpected at this stage, should have been caught at
2649 return dc
->sclk_lvls
.clocks_in_khz
[dc
->sclk_lvls
.num_levels
- 1];
2652 static void pplib_apply_display_requirements(
2654 struct dc_state
*context
)
2656 struct dm_pp_display_configuration
*pp_display_cfg
= &context
->pp_display_cfg
;
2658 pp_display_cfg
->all_displays_in_sync
=
2659 context
->bw
.dce
.all_displays_in_sync
;
2660 pp_display_cfg
->nb_pstate_switch_disable
=
2661 context
->bw
.dce
.nbp_state_change_enable
== false;
2662 pp_display_cfg
->cpu_cc6_disable
=
2663 context
->bw
.dce
.cpuc_state_change_enable
== false;
2664 pp_display_cfg
->cpu_pstate_disable
=
2665 context
->bw
.dce
.cpup_state_change_enable
== false;
2666 pp_display_cfg
->cpu_pstate_separation_time
=
2667 context
->bw
.dce
.blackout_recovery_time_us
;
2669 pp_display_cfg
->min_memory_clock_khz
= context
->bw
.dce
.yclk_khz
2670 / MEMORY_TYPE_MULTIPLIER
;
2672 pp_display_cfg
->min_engine_clock_khz
= determine_sclk_from_bounding_box(
2674 context
->bw
.dce
.sclk_khz
);
2676 pp_display_cfg
->min_engine_clock_deep_sleep_khz
2677 = context
->bw
.dce
.sclk_deep_sleep_khz
;
2679 pp_display_cfg
->avail_mclk_switch_time_us
=
2680 dce110_get_min_vblank_time_us(context
);
2682 pp_display_cfg
->avail_mclk_switch_time_in_disp_active_us
= 0;
2684 pp_display_cfg
->disp_clk_khz
= context
->bw
.dce
.dispclk_khz
;
2686 dce110_fill_display_configs(context
, pp_display_cfg
);
2688 /* TODO: is this still applicable?*/
2689 if (pp_display_cfg
->display_count
== 1) {
2690 const struct dc_crtc_timing
*timing
=
2691 &context
->streams
[0]->timing
;
2693 pp_display_cfg
->crtc_index
=
2694 pp_display_cfg
->disp_configs
[0].pipe_idx
;
2695 pp_display_cfg
->line_time_in_us
= timing
->h_total
* 1000
2696 / timing
->pix_clk_khz
;
2699 if (memcmp(&dc
->prev_display_config
, pp_display_cfg
, sizeof(
2700 struct dm_pp_display_configuration
)) != 0)
2701 dm_pp_apply_display_requirements(dc
->ctx
, pp_display_cfg
);
2703 dc
->prev_display_config
= *pp_display_cfg
;
2706 static void dce110_set_bandwidth(
2708 struct dc_state
*context
,
2709 bool decrease_allowed
)
2711 dce110_set_displaymarks(dc
, context
);
2713 if (decrease_allowed
|| context
->bw
.dce
.dispclk_khz
> dc
->current_state
->bw
.dce
.dispclk_khz
) {
2714 dc
->res_pool
->display_clock
->funcs
->set_clock(
2715 dc
->res_pool
->display_clock
,
2716 context
->bw
.dce
.dispclk_khz
* 115 / 100);
2717 dc
->current_state
->bw
.dce
.dispclk_khz
= context
->bw
.dce
.dispclk_khz
;
2720 pplib_apply_display_requirements(dc
, context
);
2723 static void dce110_program_front_end_for_pipe(
2724 struct dc
*dc
, struct pipe_ctx
*pipe_ctx
)
2726 struct mem_input
*mi
= pipe_ctx
->plane_res
.mi
;
2727 struct pipe_ctx
*old_pipe
= NULL
;
2728 struct dc_plane_state
*plane_state
= pipe_ctx
->plane_state
;
2729 struct xfm_grph_csc_adjustment adjust
;
2730 struct out_csc_color_matrix tbl_entry
;
2731 struct pipe_ctx
*cur_pipe_ctx
=
2732 &dc
->current_state
->res_ctx
.pipe_ctx
[pipe_ctx
->pipe_idx
];
2735 memset(&tbl_entry
, 0, sizeof(tbl_entry
));
2737 if (dc
->current_state
)
2738 old_pipe
= &dc
->current_state
->res_ctx
.pipe_ctx
[pipe_ctx
->pipe_idx
];
2740 memset(&adjust
, 0, sizeof(adjust
));
2741 adjust
.gamut_adjust_type
= GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS
;
2743 dce_enable_fe_clock(dc
->hwseq
, pipe_ctx
->pipe_idx
, true);
2745 set_default_colors(pipe_ctx
);
2746 if (pipe_ctx
->stream
->csc_color_matrix
.enable_adjustment
2748 tbl_entry
.color_space
=
2749 pipe_ctx
->stream
->output_color_space
;
2751 for (i
= 0; i
< 12; i
++)
2752 tbl_entry
.regval
[i
] =
2753 pipe_ctx
->stream
->csc_color_matrix
.matrix
[i
];
2755 pipe_ctx
->plane_res
.xfm
->funcs
->opp_set_csc_adjustment
2756 (pipe_ctx
->plane_res
.xfm
, &tbl_entry
);
2759 if (pipe_ctx
->stream
->gamut_remap_matrix
.enable_remap
== true) {
2760 adjust
.gamut_adjust_type
= GRAPHICS_GAMUT_ADJUST_TYPE_SW
;
2761 adjust
.temperature_matrix
[0] =
2763 gamut_remap_matrix
.matrix
[0];
2764 adjust
.temperature_matrix
[1] =
2766 gamut_remap_matrix
.matrix
[1];
2767 adjust
.temperature_matrix
[2] =
2769 gamut_remap_matrix
.matrix
[2];
2770 adjust
.temperature_matrix
[3] =
2772 gamut_remap_matrix
.matrix
[4];
2773 adjust
.temperature_matrix
[4] =
2775 gamut_remap_matrix
.matrix
[5];
2776 adjust
.temperature_matrix
[5] =
2778 gamut_remap_matrix
.matrix
[6];
2779 adjust
.temperature_matrix
[6] =
2781 gamut_remap_matrix
.matrix
[8];
2782 adjust
.temperature_matrix
[7] =
2784 gamut_remap_matrix
.matrix
[9];
2785 adjust
.temperature_matrix
[8] =
2787 gamut_remap_matrix
.matrix
[10];
2790 pipe_ctx
->plane_res
.xfm
->funcs
->transform_set_gamut_remap(pipe_ctx
->plane_res
.xfm
, &adjust
);
2792 pipe_ctx
->plane_res
.scl_data
.lb_params
.alpha_en
= pipe_ctx
->bottom_pipe
!= 0;
2794 program_scaler(dc
, pipe_ctx
);
2796 #if defined(CONFIG_DRM_AMD_DC_FBC)
2797 if (dc
->fbc_compressor
&& old_pipe
->stream
) {
2798 if (plane_state
->tiling_info
.gfx8
.array_mode
== DC_ARRAY_LINEAR_GENERAL
)
2799 dc
->fbc_compressor
->funcs
->disable_fbc(dc
->fbc_compressor
);
2801 enable_fbc(dc
, dc
->current_state
);
2805 mi
->funcs
->mem_input_program_surface_config(
2807 plane_state
->format
,
2808 &plane_state
->tiling_info
,
2809 &plane_state
->plane_size
,
2810 plane_state
->rotation
,
2813 if (mi
->funcs
->set_blank
)
2814 mi
->funcs
->set_blank(mi
, pipe_ctx
->plane_state
->visible
);
2816 if (dc
->config
.gpu_vm_support
)
2817 mi
->funcs
->mem_input_program_pte_vm(
2818 pipe_ctx
->plane_res
.mi
,
2819 plane_state
->format
,
2820 &plane_state
->tiling_info
,
2821 plane_state
->rotation
);
2823 /* Moved programming gamma from dc to hwss */
2824 if (cur_pipe_ctx
->plane_state
!= pipe_ctx
->plane_state
) {
2825 dc
->hwss
.set_input_transfer_func(
2826 pipe_ctx
, pipe_ctx
->plane_state
);
2827 dc
->hwss
.set_output_transfer_func(
2828 pipe_ctx
, pipe_ctx
->stream
);
2831 dm_logger_write(dc
->ctx
->logger
, LOG_SURFACE
,
2832 "Pipe:%d 0x%x: addr hi:0x%x, "
2835 " %d; dst: %d, %d, %d, %d;"
2836 "clip: %d, %d, %d, %d\n",
2838 pipe_ctx
->plane_state
,
2839 pipe_ctx
->plane_state
->address
.grph
.addr
.high_part
,
2840 pipe_ctx
->plane_state
->address
.grph
.addr
.low_part
,
2841 pipe_ctx
->plane_state
->src_rect
.x
,
2842 pipe_ctx
->plane_state
->src_rect
.y
,
2843 pipe_ctx
->plane_state
->src_rect
.width
,
2844 pipe_ctx
->plane_state
->src_rect
.height
,
2845 pipe_ctx
->plane_state
->dst_rect
.x
,
2846 pipe_ctx
->plane_state
->dst_rect
.y
,
2847 pipe_ctx
->plane_state
->dst_rect
.width
,
2848 pipe_ctx
->plane_state
->dst_rect
.height
,
2849 pipe_ctx
->plane_state
->clip_rect
.x
,
2850 pipe_ctx
->plane_state
->clip_rect
.y
,
2851 pipe_ctx
->plane_state
->clip_rect
.width
,
2852 pipe_ctx
->plane_state
->clip_rect
.height
);
2854 dm_logger_write(dc
->ctx
->logger
, LOG_SURFACE
,
2855 "Pipe %d: width, height, x, y\n"
2856 "viewport:%d, %d, %d, %d\n"
2857 "recout: %d, %d, %d, %d\n",
2859 pipe_ctx
->plane_res
.scl_data
.viewport
.width
,
2860 pipe_ctx
->plane_res
.scl_data
.viewport
.height
,
2861 pipe_ctx
->plane_res
.scl_data
.viewport
.x
,
2862 pipe_ctx
->plane_res
.scl_data
.viewport
.y
,
2863 pipe_ctx
->plane_res
.scl_data
.recout
.width
,
2864 pipe_ctx
->plane_res
.scl_data
.recout
.height
,
2865 pipe_ctx
->plane_res
.scl_data
.recout
.x
,
2866 pipe_ctx
->plane_res
.scl_data
.recout
.y
);
2869 static void dce110_apply_ctx_for_surface(
2871 const struct dc_stream_state
*stream
,
2873 struct dc_state
*context
)
2877 if (num_planes
== 0)
2881 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
2882 if (stream
== context
->res_ctx
.pipe_ctx
[i
].stream
) {
2883 be_idx
= context
->res_ctx
.pipe_ctx
[i
].stream_res
.tg
->inst
;
2888 for (i
= 0; i
< dc
->res_pool
->pipe_count
; i
++) {
2889 struct pipe_ctx
*pipe_ctx
= &context
->res_ctx
.pipe_ctx
[i
];
2891 if (pipe_ctx
->stream
!= stream
)
2894 dce110_program_front_end_for_pipe(dc
, pipe_ctx
);
2895 program_surface_visibility(dc
, pipe_ctx
);
2900 static void dce110_power_down_fe(struct dc
*dc
, int fe_idx
)
2902 /* Do not power down fe when stream is active on dce*/
2903 if (dc
->current_state
->res_ctx
.pipe_ctx
[fe_idx
].stream
)
2906 dc
->hwss
.enable_display_power_gating(
2907 dc
, fe_idx
, dc
->ctx
->dc_bios
, PIPE_GATING_CONTROL_ENABLE
);
2909 dc
->res_pool
->transforms
[fe_idx
]->funcs
->transform_reset(
2910 dc
->res_pool
->transforms
[fe_idx
]);
2913 static void dce110_wait_for_mpcc_disconnect(
2915 struct resource_pool
*res_pool
,
2916 struct pipe_ctx
*pipe_ctx
)
2921 static void program_csc_matrix(struct pipe_ctx
*pipe_ctx
,
2922 enum dc_color_space colorspace
,
2926 struct out_csc_color_matrix tbl_entry
;
2928 if (pipe_ctx
->stream
->csc_color_matrix
.enable_adjustment
2930 enum dc_color_space color_space
=
2931 pipe_ctx
->stream
->output_color_space
;
2933 //uint16_t matrix[12];
2934 for (i
= 0; i
< 12; i
++)
2935 tbl_entry
.regval
[i
] = pipe_ctx
->stream
->csc_color_matrix
.matrix
[i
];
2937 tbl_entry
.color_space
= color_space
;
2938 //tbl_entry.regval = matrix;
2939 pipe_ctx
->plane_res
.xfm
->funcs
->opp_set_csc_adjustment(pipe_ctx
->plane_res
.xfm
, &tbl_entry
);
2943 static void ready_shared_resources(struct dc
*dc
, struct dc_state
*context
) {}
2945 static void optimize_shared_resources(struct dc
*dc
) {}
2947 static const struct hw_sequencer_funcs dce110_funcs
= {
2948 .program_gamut_remap
= program_gamut_remap
,
2949 .program_csc_matrix
= program_csc_matrix
,
2951 .apply_ctx_to_hw
= dce110_apply_ctx_to_hw
,
2952 .apply_ctx_for_surface
= dce110_apply_ctx_for_surface
,
2953 .set_plane_config
= set_plane_config
,
2954 .update_plane_addr
= update_plane_addr
,
2955 .update_pending_status
= dce110_update_pending_status
,
2956 .set_input_transfer_func
= dce110_set_input_transfer_func
,
2957 .set_output_transfer_func
= dce110_set_output_transfer_func
,
2958 .power_down
= dce110_power_down
,
2959 .enable_accelerated_mode
= dce110_enable_accelerated_mode
,
2960 .enable_timing_synchronization
= dce110_enable_timing_synchronization
,
2961 .update_info_frame
= dce110_update_info_frame
,
2962 .enable_stream
= dce110_enable_stream
,
2963 .disable_stream
= dce110_disable_stream
,
2964 .unblank_stream
= dce110_unblank_stream
,
2965 .enable_display_pipe_clock_gating
= enable_display_pipe_clock_gating
,
2966 .enable_display_power_gating
= dce110_enable_display_power_gating
,
2967 .power_down_front_end
= dce110_power_down_fe
,
2968 .pipe_control_lock
= dce_pipe_control_lock
,
2969 .set_bandwidth
= dce110_set_bandwidth
,
2971 .get_position
= get_position
,
2972 .set_static_screen_control
= set_static_screen_control
,
2973 .reset_hw_ctx_wrap
= dce110_reset_hw_ctx_wrap
,
2974 .prog_pixclk_crtc_otg
= dce110_prog_pixclk_crtc_otg
,
2975 .setup_stereo
= NULL
,
2976 .set_avmute
= dce110_set_avmute
,
2977 .wait_for_mpcc_disconnect
= dce110_wait_for_mpcc_disconnect
,
2978 .ready_shared_resources
= ready_shared_resources
,
2979 .optimize_shared_resources
= optimize_shared_resources
,
2980 .edp_backlight_control
= hwss_edp_backlight_control
,
2981 .edp_power_control
= hwss_edp_power_control
,
2984 void dce110_hw_sequencer_construct(struct dc
*dc
)
2986 dc
->hwss
= dce110_funcs
;