0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 #include "dm_services.h"
0027 #include "dc.h"
0028 #include "dc_bios_types.h"
0029 #include "core_types.h"
0030 #include "core_status.h"
0031 #include "resource.h"
0032 #include "dm_helpers.h"
0033 #include "dce110_timing_generator.h"
0034 #include "dce/dce_hwseq.h"
0035 #include "gpio_service_interface.h"
0036
0037 #include "dce110_compressor.h"
0038
0039 #include "bios/bios_parser_helper.h"
0040 #include "timing_generator.h"
0041 #include "mem_input.h"
0042 #include "opp.h"
0043 #include "ipp.h"
0044 #include "transform.h"
0045 #include "stream_encoder.h"
0046 #include "link_encoder.h"
0047 #include "link_enc_cfg.h"
0048 #include "link_hwss.h"
0049 #include "dc_link_dp.h"
0050 #include "dccg.h"
0051 #include "clock_source.h"
0052 #include "clk_mgr.h"
0053 #include "abm.h"
0054 #include "audio.h"
0055 #include "reg_helper.h"
0056 #include "panel_cntl.h"
0057 #include "inc/link_dpcd.h"
0058 #include "dpcd_defs.h"
0059
0060 #include "dce/dce_11_0_d.h"
0061 #include "dce/dce_11_0_sh_mask.h"
0062 #include "custom_float.h"
0063
0064 #include "atomfirmware.h"
0065
0066 #include "dcn10/dcn10_hw_sequencer.h"
0067
0068 #include "link/link_dp_trace.h"
0069 #include "dce110_hw_sequencer.h"
0070
0071 #define GAMMA_HW_POINTS_NUM 256
0072
0073
0074
0075
0076
0077
0078 #define PANEL_POWER_UP_TIMEOUT 300
0079 #define PANEL_POWER_DOWN_TIMEOUT 500
0080 #define HPD_CHECK_INTERVAL 10
0081 #define OLED_POST_T7_DELAY 100
0082 #define OLED_PRE_T11_DELAY 150
0083
0084 #define CTX \
0085 hws->ctx
0086
0087 #define DC_LOGGER_INIT()
0088
0089 #define REG(reg)\
0090 hws->regs->reg
0091
0092 #undef FN
0093 #define FN(reg_name, field_name) \
0094 hws->shifts->field_name, hws->masks->field_name
0095
0096 struct dce110_hw_seq_reg_offsets {
0097 uint32_t crtc;
0098 };
0099
0100 static const struct dce110_hw_seq_reg_offsets reg_offsets[] = {
0101 {
0102 .crtc = (mmCRTC0_CRTC_GSL_CONTROL - mmCRTC_GSL_CONTROL),
0103 },
0104 {
0105 .crtc = (mmCRTC1_CRTC_GSL_CONTROL - mmCRTC_GSL_CONTROL),
0106 },
0107 {
0108 .crtc = (mmCRTC2_CRTC_GSL_CONTROL - mmCRTC_GSL_CONTROL),
0109 },
0110 {
0111 .crtc = (mmCRTCV_GSL_CONTROL - mmCRTC_GSL_CONTROL),
0112 }
0113 };
0114
0115 #define HW_REG_BLND(reg, id)\
0116 (reg + reg_offsets[id].blnd)
0117
0118 #define HW_REG_CRTC(reg, id)\
0119 (reg + reg_offsets[id].crtc)
0120
0121 #define MAX_WATERMARK 0xFFFF
0122 #define SAFE_NBP_MARK 0x7FFF
0123
0124
0125
0126
0127
0128 static void dce110_init_pte(struct dc_context *ctx)
0129 {
0130 uint32_t addr;
0131 uint32_t value = 0;
0132 uint32_t chunk_int = 0;
0133 uint32_t chunk_mul = 0;
0134
0135 addr = mmUNP_DVMM_PTE_CONTROL;
0136 value = dm_read_reg(ctx, addr);
0137
0138 set_reg_field_value(
0139 value,
0140 0,
0141 DVMM_PTE_CONTROL,
0142 DVMM_USE_SINGLE_PTE);
0143
0144 set_reg_field_value(
0145 value,
0146 1,
0147 DVMM_PTE_CONTROL,
0148 DVMM_PTE_BUFFER_MODE0);
0149
0150 set_reg_field_value(
0151 value,
0152 1,
0153 DVMM_PTE_CONTROL,
0154 DVMM_PTE_BUFFER_MODE1);
0155
0156 dm_write_reg(ctx, addr, value);
0157
0158 addr = mmDVMM_PTE_REQ;
0159 value = dm_read_reg(ctx, addr);
0160
0161 chunk_int = get_reg_field_value(
0162 value,
0163 DVMM_PTE_REQ,
0164 HFLIP_PTEREQ_PER_CHUNK_INT);
0165
0166 chunk_mul = get_reg_field_value(
0167 value,
0168 DVMM_PTE_REQ,
0169 HFLIP_PTEREQ_PER_CHUNK_MULTIPLIER);
0170
0171 if (chunk_int != 0x4 || chunk_mul != 0x4) {
0172
0173 set_reg_field_value(
0174 value,
0175 255,
0176 DVMM_PTE_REQ,
0177 MAX_PTEREQ_TO_ISSUE);
0178
0179 set_reg_field_value(
0180 value,
0181 4,
0182 DVMM_PTE_REQ,
0183 HFLIP_PTEREQ_PER_CHUNK_INT);
0184
0185 set_reg_field_value(
0186 value,
0187 4,
0188 DVMM_PTE_REQ,
0189 HFLIP_PTEREQ_PER_CHUNK_MULTIPLIER);
0190
0191 dm_write_reg(ctx, addr, value);
0192 }
0193 }
0194
0195
0196 static void enable_display_pipe_clock_gating(
0197 struct dc_context *ctx,
0198 bool clock_gating)
0199 {
0200
0201 }
0202
0203 static bool dce110_enable_display_power_gating(
0204 struct dc *dc,
0205 uint8_t controller_id,
0206 struct dc_bios *dcb,
0207 enum pipe_gating_control power_gating)
0208 {
0209 enum bp_result bp_result = BP_RESULT_OK;
0210 enum bp_pipe_control_action cntl;
0211 struct dc_context *ctx = dc->ctx;
0212 unsigned int underlay_idx = dc->res_pool->underlay_pipe_index;
0213
0214 if (IS_FPGA_MAXIMUS_DC(ctx->dce_environment))
0215 return true;
0216
0217 if (power_gating == PIPE_GATING_CONTROL_INIT)
0218 cntl = ASIC_PIPE_INIT;
0219 else if (power_gating == PIPE_GATING_CONTROL_ENABLE)
0220 cntl = ASIC_PIPE_ENABLE;
0221 else
0222 cntl = ASIC_PIPE_DISABLE;
0223
0224 if (controller_id == underlay_idx)
0225 controller_id = CONTROLLER_ID_UNDERLAY0 - 1;
0226
0227 if (power_gating != PIPE_GATING_CONTROL_INIT || controller_id == 0){
0228
0229 bp_result = dcb->funcs->enable_disp_power_gating(
0230 dcb, controller_id + 1, cntl);
0231
0232
0233
0234
0235
0236
0237
0238
0239 if (controller_id < CONTROLLER_ID_MAX - 1)
0240 dm_write_reg(ctx,
0241 HW_REG_CRTC(mmCRTC_MASTER_UPDATE_MODE, controller_id),
0242 0);
0243 }
0244
0245 if (power_gating != PIPE_GATING_CONTROL_ENABLE)
0246 dce110_init_pte(ctx);
0247
0248 if (bp_result == BP_RESULT_OK)
0249 return true;
0250 else
0251 return false;
0252 }
0253
0254 static void build_prescale_params(struct ipp_prescale_params *prescale_params,
0255 const struct dc_plane_state *plane_state)
0256 {
0257 prescale_params->mode = IPP_PRESCALE_MODE_FIXED_UNSIGNED;
0258
0259 switch (plane_state->format) {
0260 case SURFACE_PIXEL_FORMAT_GRPH_RGB565:
0261 prescale_params->scale = 0x2082;
0262 break;
0263 case SURFACE_PIXEL_FORMAT_GRPH_ARGB8888:
0264 case SURFACE_PIXEL_FORMAT_GRPH_ABGR8888:
0265 prescale_params->scale = 0x2020;
0266 break;
0267 case SURFACE_PIXEL_FORMAT_GRPH_ARGB2101010:
0268 case SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010:
0269 prescale_params->scale = 0x2008;
0270 break;
0271 case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616:
0272 case SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616:
0273 case SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616F:
0274 prescale_params->scale = 0x2000;
0275 break;
0276 default:
0277 ASSERT(false);
0278 break;
0279 }
0280 }
0281
0282 static bool
0283 dce110_set_input_transfer_func(struct dc *dc, struct pipe_ctx *pipe_ctx,
0284 const struct dc_plane_state *plane_state)
0285 {
0286 struct input_pixel_processor *ipp = pipe_ctx->plane_res.ipp;
0287 const struct dc_transfer_func *tf = NULL;
0288 struct ipp_prescale_params prescale_params = { 0 };
0289 bool result = true;
0290
0291 if (ipp == NULL)
0292 return false;
0293
0294 if (plane_state->in_transfer_func)
0295 tf = plane_state->in_transfer_func;
0296
0297 build_prescale_params(&prescale_params, plane_state);
0298 ipp->funcs->ipp_program_prescale(ipp, &prescale_params);
0299
0300 if (plane_state->gamma_correction &&
0301 !plane_state->gamma_correction->is_identity &&
0302 dce_use_lut(plane_state->format))
0303 ipp->funcs->ipp_program_input_lut(ipp, plane_state->gamma_correction);
0304
0305 if (tf == NULL) {
0306
0307 ipp->funcs->ipp_set_degamma(ipp, IPP_DEGAMMA_MODE_HW_sRGB);
0308 } else if (tf->type == TF_TYPE_PREDEFINED) {
0309 switch (tf->tf) {
0310 case TRANSFER_FUNCTION_SRGB:
0311 ipp->funcs->ipp_set_degamma(ipp, IPP_DEGAMMA_MODE_HW_sRGB);
0312 break;
0313 case TRANSFER_FUNCTION_BT709:
0314 ipp->funcs->ipp_set_degamma(ipp, IPP_DEGAMMA_MODE_HW_xvYCC);
0315 break;
0316 case TRANSFER_FUNCTION_LINEAR:
0317 ipp->funcs->ipp_set_degamma(ipp, IPP_DEGAMMA_MODE_BYPASS);
0318 break;
0319 case TRANSFER_FUNCTION_PQ:
0320 default:
0321 result = false;
0322 break;
0323 }
0324 } else if (tf->type == TF_TYPE_BYPASS) {
0325 ipp->funcs->ipp_set_degamma(ipp, IPP_DEGAMMA_MODE_BYPASS);
0326 } else {
0327
0328 result = false;
0329 }
0330
0331 return result;
0332 }
0333
0334 static bool convert_to_custom_float(struct pwl_result_data *rgb_resulted,
0335 struct curve_points *arr_points,
0336 uint32_t hw_points_num)
0337 {
0338 struct custom_float_format fmt;
0339
0340 struct pwl_result_data *rgb = rgb_resulted;
0341
0342 uint32_t i = 0;
0343
0344 fmt.exponenta_bits = 6;
0345 fmt.mantissa_bits = 12;
0346 fmt.sign = true;
0347
0348 if (!convert_to_custom_float_format(arr_points[0].x, &fmt,
0349 &arr_points[0].custom_float_x)) {
0350 BREAK_TO_DEBUGGER();
0351 return false;
0352 }
0353
0354 if (!convert_to_custom_float_format(arr_points[0].offset, &fmt,
0355 &arr_points[0].custom_float_offset)) {
0356 BREAK_TO_DEBUGGER();
0357 return false;
0358 }
0359
0360 if (!convert_to_custom_float_format(arr_points[0].slope, &fmt,
0361 &arr_points[0].custom_float_slope)) {
0362 BREAK_TO_DEBUGGER();
0363 return false;
0364 }
0365
0366 fmt.mantissa_bits = 10;
0367 fmt.sign = false;
0368
0369 if (!convert_to_custom_float_format(arr_points[1].x, &fmt,
0370 &arr_points[1].custom_float_x)) {
0371 BREAK_TO_DEBUGGER();
0372 return false;
0373 }
0374
0375 if (!convert_to_custom_float_format(arr_points[1].y, &fmt,
0376 &arr_points[1].custom_float_y)) {
0377 BREAK_TO_DEBUGGER();
0378 return false;
0379 }
0380
0381 if (!convert_to_custom_float_format(arr_points[1].slope, &fmt,
0382 &arr_points[1].custom_float_slope)) {
0383 BREAK_TO_DEBUGGER();
0384 return false;
0385 }
0386
0387 fmt.mantissa_bits = 12;
0388 fmt.sign = true;
0389
0390 while (i != hw_points_num) {
0391 if (!convert_to_custom_float_format(rgb->red, &fmt,
0392 &rgb->red_reg)) {
0393 BREAK_TO_DEBUGGER();
0394 return false;
0395 }
0396
0397 if (!convert_to_custom_float_format(rgb->green, &fmt,
0398 &rgb->green_reg)) {
0399 BREAK_TO_DEBUGGER();
0400 return false;
0401 }
0402
0403 if (!convert_to_custom_float_format(rgb->blue, &fmt,
0404 &rgb->blue_reg)) {
0405 BREAK_TO_DEBUGGER();
0406 return false;
0407 }
0408
0409 if (!convert_to_custom_float_format(rgb->delta_red, &fmt,
0410 &rgb->delta_red_reg)) {
0411 BREAK_TO_DEBUGGER();
0412 return false;
0413 }
0414
0415 if (!convert_to_custom_float_format(rgb->delta_green, &fmt,
0416 &rgb->delta_green_reg)) {
0417 BREAK_TO_DEBUGGER();
0418 return false;
0419 }
0420
0421 if (!convert_to_custom_float_format(rgb->delta_blue, &fmt,
0422 &rgb->delta_blue_reg)) {
0423 BREAK_TO_DEBUGGER();
0424 return false;
0425 }
0426
0427 ++rgb;
0428 ++i;
0429 }
0430
0431 return true;
0432 }
0433
0434 #define MAX_LOW_POINT 25
0435 #define NUMBER_REGIONS 16
0436 #define NUMBER_SW_SEGMENTS 16
0437
0438 static bool
0439 dce110_translate_regamma_to_hw_format(const struct dc_transfer_func *output_tf,
0440 struct pwl_params *regamma_params)
0441 {
0442 struct curve_points *arr_points;
0443 struct pwl_result_data *rgb_resulted;
0444 struct pwl_result_data *rgb;
0445 struct pwl_result_data *rgb_plus_1;
0446 struct fixed31_32 y_r;
0447 struct fixed31_32 y_g;
0448 struct fixed31_32 y_b;
0449 struct fixed31_32 y1_min;
0450 struct fixed31_32 y3_max;
0451
0452 int32_t region_start, region_end;
0453 uint32_t i, j, k, seg_distr[NUMBER_REGIONS], increment, start_index, hw_points;
0454
0455 if (output_tf == NULL || regamma_params == NULL || output_tf->type == TF_TYPE_BYPASS)
0456 return false;
0457
0458 arr_points = regamma_params->arr_points;
0459 rgb_resulted = regamma_params->rgb_resulted;
0460 hw_points = 0;
0461
0462 memset(regamma_params, 0, sizeof(struct pwl_params));
0463
0464 if (output_tf->tf == TRANSFER_FUNCTION_PQ) {
0465
0466
0467
0468 region_start = -11;
0469 region_end = region_start + NUMBER_REGIONS;
0470
0471 for (i = 0; i < NUMBER_REGIONS; i++)
0472 seg_distr[i] = 4;
0473
0474 } else {
0475
0476
0477
0478
0479
0480
0481 region_start = -10;
0482 region_end = 1;
0483
0484 seg_distr[0] = 4;
0485 seg_distr[1] = 4;
0486 seg_distr[2] = 4;
0487 seg_distr[3] = 4;
0488 seg_distr[4] = 4;
0489 seg_distr[5] = 4;
0490 seg_distr[6] = 4;
0491 seg_distr[7] = 4;
0492 seg_distr[8] = 4;
0493 seg_distr[9] = 4;
0494 seg_distr[10] = 0;
0495 seg_distr[11] = -1;
0496 seg_distr[12] = -1;
0497 seg_distr[13] = -1;
0498 seg_distr[14] = -1;
0499 seg_distr[15] = -1;
0500 }
0501
0502 for (k = 0; k < 16; k++) {
0503 if (seg_distr[k] != -1)
0504 hw_points += (1 << seg_distr[k]);
0505 }
0506
0507 j = 0;
0508 for (k = 0; k < (region_end - region_start); k++) {
0509 increment = NUMBER_SW_SEGMENTS / (1 << seg_distr[k]);
0510 start_index = (region_start + k + MAX_LOW_POINT) *
0511 NUMBER_SW_SEGMENTS;
0512 for (i = start_index; i < start_index + NUMBER_SW_SEGMENTS;
0513 i += increment) {
0514 if (j == hw_points - 1)
0515 break;
0516 rgb_resulted[j].red = output_tf->tf_pts.red[i];
0517 rgb_resulted[j].green = output_tf->tf_pts.green[i];
0518 rgb_resulted[j].blue = output_tf->tf_pts.blue[i];
0519 j++;
0520 }
0521 }
0522
0523
0524 start_index = (region_end + MAX_LOW_POINT) * NUMBER_SW_SEGMENTS;
0525 rgb_resulted[hw_points - 1].red = output_tf->tf_pts.red[start_index];
0526 rgb_resulted[hw_points - 1].green = output_tf->tf_pts.green[start_index];
0527 rgb_resulted[hw_points - 1].blue = output_tf->tf_pts.blue[start_index];
0528
0529 arr_points[0].x = dc_fixpt_pow(dc_fixpt_from_int(2),
0530 dc_fixpt_from_int(region_start));
0531 arr_points[1].x = dc_fixpt_pow(dc_fixpt_from_int(2),
0532 dc_fixpt_from_int(region_end));
0533
0534 y_r = rgb_resulted[0].red;
0535 y_g = rgb_resulted[0].green;
0536 y_b = rgb_resulted[0].blue;
0537
0538 y1_min = dc_fixpt_min(y_r, dc_fixpt_min(y_g, y_b));
0539
0540 arr_points[0].y = y1_min;
0541 arr_points[0].slope = dc_fixpt_div(arr_points[0].y,
0542 arr_points[0].x);
0543
0544 y_r = rgb_resulted[hw_points - 1].red;
0545 y_g = rgb_resulted[hw_points - 1].green;
0546 y_b = rgb_resulted[hw_points - 1].blue;
0547
0548
0549
0550
0551 y3_max = dc_fixpt_max(y_r, dc_fixpt_max(y_g, y_b));
0552
0553 arr_points[1].y = y3_max;
0554
0555 arr_points[1].slope = dc_fixpt_zero;
0556
0557 if (output_tf->tf == TRANSFER_FUNCTION_PQ) {
0558
0559
0560
0561 const struct fixed31_32 end_value = dc_fixpt_from_int(125);
0562
0563 arr_points[1].slope = dc_fixpt_div(
0564 dc_fixpt_sub(dc_fixpt_one, arr_points[1].y),
0565 dc_fixpt_sub(end_value, arr_points[1].x));
0566 }
0567
0568 regamma_params->hw_points_num = hw_points;
0569
0570 k = 0;
0571 for (i = 1; i < 16; i++) {
0572 if (seg_distr[k] != -1) {
0573 regamma_params->arr_curve_points[k].segments_num = seg_distr[k];
0574 regamma_params->arr_curve_points[i].offset =
0575 regamma_params->arr_curve_points[k].offset + (1 << seg_distr[k]);
0576 }
0577 k++;
0578 }
0579
0580 if (seg_distr[k] != -1)
0581 regamma_params->arr_curve_points[k].segments_num = seg_distr[k];
0582
0583 rgb = rgb_resulted;
0584 rgb_plus_1 = rgb_resulted + 1;
0585
0586 i = 1;
0587
0588 while (i != hw_points + 1) {
0589 if (dc_fixpt_lt(rgb_plus_1->red, rgb->red))
0590 rgb_plus_1->red = rgb->red;
0591 if (dc_fixpt_lt(rgb_plus_1->green, rgb->green))
0592 rgb_plus_1->green = rgb->green;
0593 if (dc_fixpt_lt(rgb_plus_1->blue, rgb->blue))
0594 rgb_plus_1->blue = rgb->blue;
0595
0596 rgb->delta_red = dc_fixpt_sub(rgb_plus_1->red, rgb->red);
0597 rgb->delta_green = dc_fixpt_sub(rgb_plus_1->green, rgb->green);
0598 rgb->delta_blue = dc_fixpt_sub(rgb_plus_1->blue, rgb->blue);
0599
0600 ++rgb_plus_1;
0601 ++rgb;
0602 ++i;
0603 }
0604
0605 convert_to_custom_float(rgb_resulted, arr_points, hw_points);
0606
0607 return true;
0608 }
0609
0610 static bool
0611 dce110_set_output_transfer_func(struct dc *dc, struct pipe_ctx *pipe_ctx,
0612 const struct dc_stream_state *stream)
0613 {
0614 struct transform *xfm = pipe_ctx->plane_res.xfm;
0615
0616 xfm->funcs->opp_power_on_regamma_lut(xfm, true);
0617 xfm->regamma_params.hw_points_num = GAMMA_HW_POINTS_NUM;
0618
0619 if (stream->out_transfer_func &&
0620 stream->out_transfer_func->type == TF_TYPE_PREDEFINED &&
0621 stream->out_transfer_func->tf == TRANSFER_FUNCTION_SRGB) {
0622 xfm->funcs->opp_set_regamma_mode(xfm, OPP_REGAMMA_SRGB);
0623 } else if (dce110_translate_regamma_to_hw_format(stream->out_transfer_func,
0624 &xfm->regamma_params)) {
0625 xfm->funcs->opp_program_regamma_pwl(xfm, &xfm->regamma_params);
0626 xfm->funcs->opp_set_regamma_mode(xfm, OPP_REGAMMA_USER);
0627 } else {
0628 xfm->funcs->opp_set_regamma_mode(xfm, OPP_REGAMMA_BYPASS);
0629 }
0630
0631 xfm->funcs->opp_power_on_regamma_lut(xfm, false);
0632
0633 return true;
0634 }
0635
0636 void dce110_update_info_frame(struct pipe_ctx *pipe_ctx)
0637 {
0638 bool is_hdmi_tmds;
0639 bool is_dp;
0640
0641 ASSERT(pipe_ctx->stream);
0642
0643 if (pipe_ctx->stream_res.stream_enc == NULL)
0644 return;
0645
0646 is_hdmi_tmds = dc_is_hdmi_tmds_signal(pipe_ctx->stream->signal);
0647 is_dp = dc_is_dp_signal(pipe_ctx->stream->signal);
0648
0649 if (!is_hdmi_tmds && !is_dp)
0650 return;
0651
0652 if (is_hdmi_tmds)
0653 pipe_ctx->stream_res.stream_enc->funcs->update_hdmi_info_packets(
0654 pipe_ctx->stream_res.stream_enc,
0655 &pipe_ctx->stream_res.encoder_info_frame);
0656 else
0657 pipe_ctx->stream_res.stream_enc->funcs->update_dp_info_packets(
0658 pipe_ctx->stream_res.stream_enc,
0659 &pipe_ctx->stream_res.encoder_info_frame);
0660 }
0661
0662 void dce110_enable_stream(struct pipe_ctx *pipe_ctx)
0663 {
0664 enum dc_lane_count lane_count =
0665 pipe_ctx->stream->link->cur_link_settings.lane_count;
0666 struct dc_crtc_timing *timing = &pipe_ctx->stream->timing;
0667 struct dc_link *link = pipe_ctx->stream->link;
0668 const struct dc *dc = link->dc;
0669 const struct link_hwss *link_hwss = get_link_hwss(link, &pipe_ctx->link_res);
0670 uint32_t active_total_with_borders;
0671 uint32_t early_control = 0;
0672 struct timing_generator *tg = pipe_ctx->stream_res.tg;
0673
0674 link_hwss->setup_stream_encoder(pipe_ctx);
0675
0676 dc->hwss.update_info_frame(pipe_ctx);
0677
0678
0679 active_total_with_borders =
0680 timing->h_addressable
0681 + timing->h_border_left
0682 + timing->h_border_right;
0683
0684 if (lane_count != 0)
0685 early_control = active_total_with_borders % lane_count;
0686
0687 if (early_control == 0)
0688 early_control = lane_count;
0689
0690 tg->funcs->set_early_control(tg, early_control);
0691
0692
0693 if (pipe_ctx->stream_res.audio != NULL) {
0694 if (dc_is_dp_signal(pipe_ctx->stream->signal))
0695 pipe_ctx->stream_res.stream_enc->funcs->dp_audio_enable(pipe_ctx->stream_res.stream_enc);
0696 }
0697
0698
0699
0700
0701 }
0702
0703 static enum bp_result link_transmitter_control(
0704 struct dc_bios *bios,
0705 struct bp_transmitter_control *cntl)
0706 {
0707 enum bp_result result;
0708
0709 result = bios->funcs->transmitter_control(bios, cntl);
0710
0711 return result;
0712 }
0713
0714
0715
0716
0717
0718 void dce110_edp_wait_for_hpd_ready(
0719 struct dc_link *link,
0720 bool power_up)
0721 {
0722 struct dc_context *ctx = link->ctx;
0723 struct graphics_object_id connector = link->link_enc->connector;
0724 struct gpio *hpd;
0725 struct dc_sink *sink = link->local_sink;
0726 bool edp_hpd_high = false;
0727 uint32_t time_elapsed = 0;
0728 uint32_t timeout = power_up ?
0729 PANEL_POWER_UP_TIMEOUT : PANEL_POWER_DOWN_TIMEOUT;
0730
0731 if (dal_graphics_object_id_get_connector_id(connector)
0732 != CONNECTOR_ID_EDP) {
0733 BREAK_TO_DEBUGGER();
0734 return;
0735 }
0736
0737 if (!power_up)
0738
0739
0740
0741
0742 return;
0743
0744
0745
0746
0747
0748
0749
0750
0751 hpd = get_hpd_gpio(ctx->dc_bios, connector, ctx->gpio_service);
0752
0753 if (!hpd) {
0754 BREAK_TO_DEBUGGER();
0755 return;
0756 }
0757
0758 if (sink != NULL) {
0759 if (sink->edid_caps.panel_patch.extra_t3_ms > 0) {
0760 int extra_t3_in_ms = sink->edid_caps.panel_patch.extra_t3_ms;
0761
0762 msleep(extra_t3_in_ms);
0763 }
0764 }
0765
0766 dal_gpio_open(hpd, GPIO_MODE_INTERRUPT);
0767
0768
0769
0770 do {
0771 uint32_t detected = 0;
0772
0773 dal_gpio_get_value(hpd, &detected);
0774
0775 if (!(detected ^ power_up)) {
0776 edp_hpd_high = true;
0777 break;
0778 }
0779
0780 msleep(HPD_CHECK_INTERVAL);
0781
0782 time_elapsed += HPD_CHECK_INTERVAL;
0783 } while (time_elapsed < timeout);
0784
0785 dal_gpio_close(hpd);
0786
0787 dal_gpio_destroy_irq(&hpd);
0788
0789 if (false == edp_hpd_high) {
0790 DC_LOG_WARNING(
0791 "%s: wait timed out!\n", __func__);
0792 }
0793 }
0794
0795 void dce110_edp_power_control(
0796 struct dc_link *link,
0797 bool power_up)
0798 {
0799 struct dc_context *ctx = link->ctx;
0800 struct bp_transmitter_control cntl = { 0 };
0801 enum bp_result bp_result;
0802 uint8_t panel_instance;
0803
0804
0805 if (dal_graphics_object_id_get_connector_id(link->link_enc->connector)
0806 != CONNECTOR_ID_EDP) {
0807 BREAK_TO_DEBUGGER();
0808 return;
0809 }
0810
0811 if (!link->panel_cntl)
0812 return;
0813 if (power_up !=
0814 link->panel_cntl->funcs->is_panel_powered_on(link->panel_cntl)) {
0815
0816 unsigned long long current_ts = dm_get_timestamp(ctx);
0817 unsigned long long time_since_edp_poweroff_ms =
0818 div64_u64(dm_get_elapse_time_in_ns(
0819 ctx,
0820 current_ts,
0821 dp_trace_get_edp_poweroff_timestamp(link)), 1000000);
0822 unsigned long long time_since_edp_poweron_ms =
0823 div64_u64(dm_get_elapse_time_in_ns(
0824 ctx,
0825 current_ts,
0826 dp_trace_get_edp_poweron_timestamp(link)), 1000000);
0827 DC_LOG_HW_RESUME_S3(
0828 "%s: transition: power_up=%d current_ts=%llu edp_poweroff=%llu edp_poweron=%llu time_since_edp_poweroff_ms=%llu time_since_edp_poweron_ms=%llu",
0829 __func__,
0830 power_up,
0831 current_ts,
0832 dp_trace_get_edp_poweroff_timestamp(link),
0833 dp_trace_get_edp_poweron_timestamp(link),
0834 time_since_edp_poweroff_ms,
0835 time_since_edp_poweron_ms);
0836
0837
0838 if (power_up) {
0839
0840 unsigned long long remaining_min_edp_poweroff_time_ms = 500;
0841
0842
0843 if (link->local_sink != NULL)
0844 remaining_min_edp_poweroff_time_ms +=
0845 link->local_sink->edid_caps.panel_patch.extra_t12_ms;
0846
0847
0848 if (dp_trace_get_edp_poweroff_timestamp(link) != 0) {
0849 if (time_since_edp_poweroff_ms < remaining_min_edp_poweroff_time_ms)
0850 remaining_min_edp_poweroff_time_ms =
0851 remaining_min_edp_poweroff_time_ms - time_since_edp_poweroff_ms;
0852 else
0853 remaining_min_edp_poweroff_time_ms = 0;
0854 }
0855
0856 if (remaining_min_edp_poweroff_time_ms) {
0857 DC_LOG_HW_RESUME_S3(
0858 "%s: remaining_min_edp_poweroff_time_ms=%llu: begin wait.\n",
0859 __func__, remaining_min_edp_poweroff_time_ms);
0860 msleep(remaining_min_edp_poweroff_time_ms);
0861 DC_LOG_HW_RESUME_S3(
0862 "%s: remaining_min_edp_poweroff_time_ms=%llu: end wait.\n",
0863 __func__, remaining_min_edp_poweroff_time_ms);
0864 dm_output_to_console("%s: wait %lld ms to power on eDP.\n",
0865 __func__, remaining_min_edp_poweroff_time_ms);
0866 } else {
0867 DC_LOG_HW_RESUME_S3(
0868 "%s: remaining_min_edp_poweroff_time_ms=%llu: no wait required.\n",
0869 __func__, remaining_min_edp_poweroff_time_ms);
0870 }
0871 }
0872
0873 DC_LOG_HW_RESUME_S3(
0874 "%s: BEGIN: Panel Power action: %s\n",
0875 __func__, (power_up ? "On":"Off"));
0876
0877 cntl.action = power_up ?
0878 TRANSMITTER_CONTROL_POWER_ON :
0879 TRANSMITTER_CONTROL_POWER_OFF;
0880 cntl.transmitter = link->link_enc->transmitter;
0881 cntl.connector_obj_id = link->link_enc->connector;
0882 cntl.coherent = false;
0883 cntl.lanes_number = LANE_COUNT_FOUR;
0884 cntl.hpd_sel = link->link_enc->hpd_source;
0885 panel_instance = link->panel_cntl->inst;
0886
0887 if (ctx->dc->ctx->dmub_srv &&
0888 ctx->dc->debug.dmub_command_table) {
0889 if (cntl.action == TRANSMITTER_CONTROL_POWER_ON)
0890 bp_result = ctx->dc_bios->funcs->enable_lvtma_control(ctx->dc_bios,
0891 LVTMA_CONTROL_POWER_ON,
0892 panel_instance);
0893 else
0894 bp_result = ctx->dc_bios->funcs->enable_lvtma_control(ctx->dc_bios,
0895 LVTMA_CONTROL_POWER_OFF,
0896 panel_instance);
0897 }
0898
0899 bp_result = link_transmitter_control(ctx->dc_bios, &cntl);
0900
0901 DC_LOG_HW_RESUME_S3(
0902 "%s: END: Panel Power action: %s bp_result=%u\n",
0903 __func__, (power_up ? "On":"Off"),
0904 bp_result);
0905
0906 dp_trace_set_edp_power_timestamp(link, power_up);
0907
0908 DC_LOG_HW_RESUME_S3(
0909 "%s: updated values: edp_poweroff=%llu edp_poweron=%llu\n",
0910 __func__,
0911 dp_trace_get_edp_poweroff_timestamp(link),
0912 dp_trace_get_edp_poweron_timestamp(link));
0913
0914 if (bp_result != BP_RESULT_OK)
0915 DC_LOG_ERROR(
0916 "%s: Panel Power bp_result: %d\n",
0917 __func__, bp_result);
0918 } else {
0919 DC_LOG_HW_RESUME_S3(
0920 "%s: Skipping Panel Power action: %s\n",
0921 __func__, (power_up ? "On":"Off"));
0922 }
0923 }
0924
0925 void dce110_edp_wait_for_T12(
0926 struct dc_link *link)
0927 {
0928 struct dc_context *ctx = link->ctx;
0929
0930 if (dal_graphics_object_id_get_connector_id(link->link_enc->connector)
0931 != CONNECTOR_ID_EDP) {
0932 BREAK_TO_DEBUGGER();
0933 return;
0934 }
0935
0936 if (!link->panel_cntl)
0937 return;
0938
0939 if (!link->panel_cntl->funcs->is_panel_powered_on(link->panel_cntl) &&
0940 dp_trace_get_edp_poweroff_timestamp(link) != 0) {
0941 unsigned int t12_duration = 500;
0942 unsigned long long current_ts = dm_get_timestamp(ctx);
0943 unsigned long long time_since_edp_poweroff_ms =
0944 div64_u64(dm_get_elapse_time_in_ns(
0945 ctx,
0946 current_ts,
0947 dp_trace_get_edp_poweroff_timestamp(link)), 1000000);
0948
0949 t12_duration += link->local_sink->edid_caps.panel_patch.extra_t12_ms;
0950
0951 if (time_since_edp_poweroff_ms < t12_duration)
0952 msleep(t12_duration - time_since_edp_poweroff_ms);
0953 }
0954 }
0955
0956
0957
0958
0959
0960
0961 void dce110_edp_backlight_control(
0962 struct dc_link *link,
0963 bool enable)
0964 {
0965 struct dc_context *ctx = link->ctx;
0966 struct bp_transmitter_control cntl = { 0 };
0967 uint8_t panel_instance;
0968
0969 if (dal_graphics_object_id_get_connector_id(link->link_enc->connector)
0970 != CONNECTOR_ID_EDP) {
0971 BREAK_TO_DEBUGGER();
0972 return;
0973 }
0974
0975 if (link->panel_cntl) {
0976 bool is_backlight_on = link->panel_cntl->funcs->is_panel_backlight_on(link->panel_cntl);
0977
0978 if ((enable && is_backlight_on) || (!enable && !is_backlight_on)) {
0979 DC_LOG_HW_RESUME_S3(
0980 "%s: panel already powered up/off. Do nothing.\n",
0981 __func__);
0982 return;
0983 }
0984 }
0985
0986
0987
0988 DC_LOG_HW_RESUME_S3(
0989 "%s: backlight action: %s\n",
0990 __func__, (enable ? "On":"Off"));
0991
0992 cntl.action = enable ?
0993 TRANSMITTER_CONTROL_BACKLIGHT_ON :
0994 TRANSMITTER_CONTROL_BACKLIGHT_OFF;
0995
0996
0997 cntl.transmitter = link->link_enc->transmitter;
0998 cntl.connector_obj_id = link->link_enc->connector;
0999
1000 cntl.lanes_number = LANE_COUNT_FOUR;
1001 cntl.hpd_sel = link->link_enc->hpd_source;
1002 cntl.signal = SIGNAL_TYPE_EDP;
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016 panel_instance = link->panel_cntl->inst;
1017
1018 if (cntl.action == TRANSMITTER_CONTROL_BACKLIGHT_ON) {
1019 if (!link->dc->config.edp_no_power_sequencing)
1020
1021
1022
1023
1024
1025
1026
1027 edp_receiver_ready_T7(link);
1028 else
1029 DC_LOG_DC("edp_receiver_ready_T7 skipped\n");
1030 }
1031
1032 if (ctx->dc->ctx->dmub_srv &&
1033 ctx->dc->debug.dmub_command_table) {
1034 if (cntl.action == TRANSMITTER_CONTROL_BACKLIGHT_ON)
1035 ctx->dc_bios->funcs->enable_lvtma_control(ctx->dc_bios,
1036 LVTMA_CONTROL_LCD_BLON,
1037 panel_instance);
1038 else
1039 ctx->dc_bios->funcs->enable_lvtma_control(ctx->dc_bios,
1040 LVTMA_CONTROL_LCD_BLOFF,
1041 panel_instance);
1042 }
1043
1044 link_transmitter_control(ctx->dc_bios, &cntl);
1045
1046 if (enable && link->dpcd_sink_ext_caps.bits.oled)
1047 msleep(OLED_POST_T7_DELAY);
1048
1049 if (link->dpcd_sink_ext_caps.bits.oled ||
1050 link->dpcd_sink_ext_caps.bits.hdr_aux_backlight_control == 1 ||
1051 link->dpcd_sink_ext_caps.bits.sdr_aux_backlight_control == 1)
1052 dc_link_backlight_enable_aux(link, enable);
1053
1054
1055 if (cntl.action == TRANSMITTER_CONTROL_BACKLIGHT_OFF) {
1056 if (!link->dc->config.edp_no_power_sequencing)
1057
1058
1059
1060
1061
1062
1063
1064 edp_add_delay_for_T9(link);
1065 else
1066 DC_LOG_DC("edp_receiver_ready_T9 skipped\n");
1067 }
1068
1069 if (!enable && link->dpcd_sink_ext_caps.bits.oled)
1070 msleep(OLED_PRE_T11_DELAY);
1071 }
1072
1073 void dce110_enable_audio_stream(struct pipe_ctx *pipe_ctx)
1074 {
1075
1076 struct dc *dc;
1077 struct clk_mgr *clk_mgr;
1078 unsigned int i, num_audio = 1;
1079
1080 if (!pipe_ctx->stream)
1081 return;
1082
1083 dc = pipe_ctx->stream->ctx->dc;
1084 clk_mgr = dc->clk_mgr;
1085
1086 if (pipe_ctx->stream_res.audio && pipe_ctx->stream_res.audio->enabled == true)
1087 return;
1088
1089 if (pipe_ctx->stream_res.audio) {
1090 for (i = 0; i < MAX_PIPES; i++) {
1091
1092 if (dc->current_state->res_ctx.pipe_ctx[i].stream_res.audio != NULL)
1093 num_audio++;
1094 }
1095
1096 pipe_ctx->stream_res.audio->funcs->az_enable(pipe_ctx->stream_res.audio);
1097
1098 if (num_audio >= 1 && clk_mgr->funcs->enable_pme_wa)
1099
1100 clk_mgr->funcs->enable_pme_wa(clk_mgr);
1101
1102
1103 if (is_dp_128b_132b_signal(pipe_ctx))
1104 pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->audio_mute_control(
1105 pipe_ctx->stream_res.hpo_dp_stream_enc, false);
1106 else
1107 pipe_ctx->stream_res.stream_enc->funcs->audio_mute_control(
1108 pipe_ctx->stream_res.stream_enc, false);
1109 if (pipe_ctx->stream_res.audio)
1110 pipe_ctx->stream_res.audio->enabled = true;
1111 }
1112
1113 if (dc_is_dp_signal(pipe_ctx->stream->signal))
1114 dp_source_sequence_trace(pipe_ctx->stream->link, DPCD_SOURCE_SEQ_AFTER_ENABLE_AUDIO_STREAM);
1115 }
1116
1117 void dce110_disable_audio_stream(struct pipe_ctx *pipe_ctx)
1118 {
1119 struct dc *dc;
1120 struct clk_mgr *clk_mgr;
1121
1122 if (!pipe_ctx || !pipe_ctx->stream)
1123 return;
1124
1125 dc = pipe_ctx->stream->ctx->dc;
1126 clk_mgr = dc->clk_mgr;
1127
1128 if (pipe_ctx->stream_res.audio && pipe_ctx->stream_res.audio->enabled == false)
1129 return;
1130
1131 if (is_dp_128b_132b_signal(pipe_ctx))
1132 pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->audio_mute_control(
1133 pipe_ctx->stream_res.hpo_dp_stream_enc, true);
1134 else
1135 pipe_ctx->stream_res.stream_enc->funcs->audio_mute_control(
1136 pipe_ctx->stream_res.stream_enc, true);
1137 if (pipe_ctx->stream_res.audio) {
1138 pipe_ctx->stream_res.audio->enabled = false;
1139
1140 if (dc_is_dp_signal(pipe_ctx->stream->signal))
1141 if (is_dp_128b_132b_signal(pipe_ctx))
1142 pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->dp_audio_disable(
1143 pipe_ctx->stream_res.hpo_dp_stream_enc);
1144 else
1145 pipe_ctx->stream_res.stream_enc->funcs->dp_audio_disable(
1146 pipe_ctx->stream_res.stream_enc);
1147 else
1148 pipe_ctx->stream_res.stream_enc->funcs->hdmi_audio_disable(
1149 pipe_ctx->stream_res.stream_enc);
1150
1151 if (clk_mgr->funcs->enable_pme_wa)
1152
1153 clk_mgr->funcs->enable_pme_wa(clk_mgr);
1154
1155
1156
1157
1158
1159
1160 }
1161
1162 if (dc_is_dp_signal(pipe_ctx->stream->signal))
1163 dp_source_sequence_trace(pipe_ctx->stream->link, DPCD_SOURCE_SEQ_AFTER_DISABLE_AUDIO_STREAM);
1164 }
1165
1166 void dce110_disable_stream(struct pipe_ctx *pipe_ctx)
1167 {
1168 struct dc_stream_state *stream = pipe_ctx->stream;
1169 struct dc_link *link = stream->link;
1170 struct dc *dc = pipe_ctx->stream->ctx->dc;
1171 const struct link_hwss *link_hwss = get_link_hwss(link, &pipe_ctx->link_res);
1172
1173 if (dc_is_hdmi_tmds_signal(pipe_ctx->stream->signal)) {
1174 pipe_ctx->stream_res.stream_enc->funcs->stop_hdmi_info_packets(
1175 pipe_ctx->stream_res.stream_enc);
1176 pipe_ctx->stream_res.stream_enc->funcs->hdmi_reset_stream_attribute(
1177 pipe_ctx->stream_res.stream_enc);
1178 }
1179
1180 if (is_dp_128b_132b_signal(pipe_ctx)) {
1181 pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->stop_dp_info_packets(
1182 pipe_ctx->stream_res.hpo_dp_stream_enc);
1183 } else if (dc_is_dp_signal(pipe_ctx->stream->signal))
1184 pipe_ctx->stream_res.stream_enc->funcs->stop_dp_info_packets(
1185 pipe_ctx->stream_res.stream_enc);
1186
1187 dc->hwss.disable_audio_stream(pipe_ctx);
1188
1189 link_hwss->reset_stream_encoder(pipe_ctx);
1190
1191 if (is_dp_128b_132b_signal(pipe_ctx)) {
1192
1193
1194
1195
1196 if (pipe_ctx->stream->ctx->dc->hwseq->funcs.setup_hpo_hw_control)
1197 pipe_ctx->stream->ctx->dc->hwseq->funcs.setup_hpo_hw_control(
1198 pipe_ctx->stream->ctx->dc->hwseq, false);
1199 }
1200 }
1201
1202 void dce110_unblank_stream(struct pipe_ctx *pipe_ctx,
1203 struct dc_link_settings *link_settings)
1204 {
1205 struct encoder_unblank_param params = { { 0 } };
1206 struct dc_stream_state *stream = pipe_ctx->stream;
1207 struct dc_link *link = stream->link;
1208 struct dce_hwseq *hws = link->dc->hwseq;
1209
1210
1211 params.timing = pipe_ctx->stream->timing;
1212 params.link_settings.link_rate = link_settings->link_rate;
1213
1214 if (dc_is_dp_signal(pipe_ctx->stream->signal))
1215 pipe_ctx->stream_res.stream_enc->funcs->dp_unblank(link, pipe_ctx->stream_res.stream_enc, ¶ms);
1216
1217 if (link->local_sink && link->local_sink->sink_signal == SIGNAL_TYPE_EDP) {
1218 hws->funcs.edp_backlight_control(link, true);
1219 }
1220 }
1221
1222 void dce110_blank_stream(struct pipe_ctx *pipe_ctx)
1223 {
1224 struct dc_stream_state *stream = pipe_ctx->stream;
1225 struct dc_link *link = stream->link;
1226 struct dce_hwseq *hws = link->dc->hwseq;
1227
1228 if (link->local_sink && link->local_sink->sink_signal == SIGNAL_TYPE_EDP) {
1229 hws->funcs.edp_backlight_control(link, false);
1230 link->dc->hwss.set_abm_immediate_disable(pipe_ctx);
1231 }
1232
1233 if (is_dp_128b_132b_signal(pipe_ctx)) {
1234
1235 pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->dp_blank(
1236 pipe_ctx->stream_res.hpo_dp_stream_enc);
1237 } else if (dc_is_dp_signal(pipe_ctx->stream->signal)) {
1238 pipe_ctx->stream_res.stream_enc->funcs->dp_blank(link, pipe_ctx->stream_res.stream_enc);
1239
1240 if (!dc_is_embedded_signal(pipe_ctx->stream->signal)) {
1241
1242
1243
1244
1245 msleep(60);
1246 } else if (pipe_ctx->stream->signal == SIGNAL_TYPE_EDP) {
1247 if (!link->dc->config.edp_no_power_sequencing) {
1248
1249
1250
1251
1252
1253
1254
1255 edp_receiver_ready_T9(link);
1256 }
1257 }
1258 }
1259
1260 }
1261
1262
1263 void dce110_set_avmute(struct pipe_ctx *pipe_ctx, bool enable)
1264 {
1265 if (pipe_ctx != NULL && pipe_ctx->stream_res.stream_enc != NULL)
1266 pipe_ctx->stream_res.stream_enc->funcs->set_avmute(pipe_ctx->stream_res.stream_enc, enable);
1267 }
1268
1269 static enum audio_dto_source translate_to_dto_source(enum controller_id crtc_id)
1270 {
1271 switch (crtc_id) {
1272 case CONTROLLER_ID_D0:
1273 return DTO_SOURCE_ID0;
1274 case CONTROLLER_ID_D1:
1275 return DTO_SOURCE_ID1;
1276 case CONTROLLER_ID_D2:
1277 return DTO_SOURCE_ID2;
1278 case CONTROLLER_ID_D3:
1279 return DTO_SOURCE_ID3;
1280 case CONTROLLER_ID_D4:
1281 return DTO_SOURCE_ID4;
1282 case CONTROLLER_ID_D5:
1283 return DTO_SOURCE_ID5;
1284 default:
1285 return DTO_SOURCE_UNKNOWN;
1286 }
1287 }
1288
1289 static void build_audio_output(
1290 struct dc_state *state,
1291 const struct pipe_ctx *pipe_ctx,
1292 struct audio_output *audio_output)
1293 {
1294 const struct dc_stream_state *stream = pipe_ctx->stream;
1295 audio_output->engine_id = pipe_ctx->stream_res.stream_enc->id;
1296
1297 audio_output->signal = pipe_ctx->stream->signal;
1298
1299
1300
1301 audio_output->crtc_info.h_total =
1302 stream->timing.h_total;
1303
1304
1305
1306
1307
1308 audio_output->crtc_info.h_active =
1309 stream->timing.h_addressable
1310 + stream->timing.h_border_left
1311 + stream->timing.h_border_right;
1312
1313 audio_output->crtc_info.v_active =
1314 stream->timing.v_addressable
1315 + stream->timing.v_border_top
1316 + stream->timing.v_border_bottom;
1317
1318 audio_output->crtc_info.pixel_repetition = 1;
1319
1320 audio_output->crtc_info.interlaced =
1321 stream->timing.flags.INTERLACE;
1322
1323 audio_output->crtc_info.refresh_rate =
1324 (stream->timing.pix_clk_100hz*100)/
1325 (stream->timing.h_total*stream->timing.v_total);
1326
1327 audio_output->crtc_info.color_depth =
1328 stream->timing.display_color_depth;
1329
1330 audio_output->crtc_info.requested_pixel_clock_100Hz =
1331 pipe_ctx->stream_res.pix_clk_params.requested_pix_clk_100hz;
1332
1333 audio_output->crtc_info.calculated_pixel_clock_100Hz =
1334 pipe_ctx->stream_res.pix_clk_params.requested_pix_clk_100hz;
1335
1336
1337 if (dc_is_hdmi_tmds_signal(pipe_ctx->stream->signal) &&
1338 audio_output->crtc_info.requested_pixel_clock_100Hz ==
1339 (stream->timing.pix_clk_100hz)) {
1340 if (pipe_ctx->stream_res.pix_clk_params.pixel_encoding == PIXEL_ENCODING_YCBCR420) {
1341 audio_output->crtc_info.requested_pixel_clock_100Hz =
1342 audio_output->crtc_info.requested_pixel_clock_100Hz/2;
1343 audio_output->crtc_info.calculated_pixel_clock_100Hz =
1344 pipe_ctx->stream_res.pix_clk_params.requested_pix_clk_100hz/2;
1345
1346 }
1347 }
1348
1349 if (state->clk_mgr &&
1350 (pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT ||
1351 pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST)) {
1352 audio_output->pll_info.dp_dto_source_clock_in_khz =
1353 state->clk_mgr->funcs->get_dp_ref_clk_frequency(
1354 state->clk_mgr);
1355 }
1356
1357 audio_output->pll_info.feed_back_divider =
1358 pipe_ctx->pll_settings.feedback_divider;
1359
1360 audio_output->pll_info.dto_source =
1361 translate_to_dto_source(
1362 pipe_ctx->stream_res.tg->inst + 1);
1363
1364
1365 audio_output->pll_info.ss_enabled = true;
1366
1367 audio_output->pll_info.ss_percentage =
1368 pipe_ctx->pll_settings.ss_percentage;
1369 }
1370
1371 static void program_scaler(const struct dc *dc,
1372 const struct pipe_ctx *pipe_ctx)
1373 {
1374 struct tg_color color = {0};
1375
1376
1377 if (pipe_ctx->plane_res.xfm->funcs->transform_set_pixel_storage_depth == NULL)
1378 return;
1379
1380 if (dc->debug.visual_confirm == VISUAL_CONFIRM_SURFACE)
1381 get_surface_visual_confirm_color(pipe_ctx, &color);
1382 else
1383 color_space_to_black_color(dc,
1384 pipe_ctx->stream->output_color_space,
1385 &color);
1386
1387 pipe_ctx->plane_res.xfm->funcs->transform_set_pixel_storage_depth(
1388 pipe_ctx->plane_res.xfm,
1389 pipe_ctx->plane_res.scl_data.lb_params.depth,
1390 &pipe_ctx->stream->bit_depth_params);
1391
1392 if (pipe_ctx->stream_res.tg->funcs->set_overscan_blank_color) {
1393
1394
1395
1396
1397
1398 if (pipe_ctx->stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR420)
1399 color.color_r_cr = color.color_g_y;
1400
1401 pipe_ctx->stream_res.tg->funcs->set_overscan_blank_color(
1402 pipe_ctx->stream_res.tg,
1403 &color);
1404 }
1405
1406 pipe_ctx->plane_res.xfm->funcs->transform_set_scaler(pipe_ctx->plane_res.xfm,
1407 &pipe_ctx->plane_res.scl_data);
1408 }
1409
1410 static enum dc_status dce110_enable_stream_timing(
1411 struct pipe_ctx *pipe_ctx,
1412 struct dc_state *context,
1413 struct dc *dc)
1414 {
1415 struct dc_stream_state *stream = pipe_ctx->stream;
1416 struct pipe_ctx *pipe_ctx_old = &dc->current_state->res_ctx.
1417 pipe_ctx[pipe_ctx->pipe_idx];
1418 struct tg_color black_color = {0};
1419
1420 if (!pipe_ctx_old->stream) {
1421
1422
1423 color_space_to_black_color(dc,
1424 stream->output_color_space, &black_color);
1425 pipe_ctx->stream_res.tg->funcs->set_blank_color(
1426 pipe_ctx->stream_res.tg,
1427 &black_color);
1428
1429
1430
1431
1432
1433 pipe_ctx->stream_res.tg->funcs->set_blank(pipe_ctx->stream_res.tg, true);
1434
1435 if (false == pipe_ctx->clock_source->funcs->program_pix_clk(
1436 pipe_ctx->clock_source,
1437 &pipe_ctx->stream_res.pix_clk_params,
1438 dp_get_link_encoding_format(&pipe_ctx->link_config.dp_link_settings),
1439 &pipe_ctx->pll_settings)) {
1440 BREAK_TO_DEBUGGER();
1441 return DC_ERROR_UNEXPECTED;
1442 }
1443
1444 pipe_ctx->stream_res.tg->funcs->program_timing(
1445 pipe_ctx->stream_res.tg,
1446 &stream->timing,
1447 0,
1448 0,
1449 0,
1450 0,
1451 pipe_ctx->stream->signal,
1452 true);
1453 }
1454
1455 if (!pipe_ctx_old->stream) {
1456 if (false == pipe_ctx->stream_res.tg->funcs->enable_crtc(
1457 pipe_ctx->stream_res.tg)) {
1458 BREAK_TO_DEBUGGER();
1459 return DC_ERROR_UNEXPECTED;
1460 }
1461 }
1462
1463 return DC_OK;
1464 }
1465
1466 static enum dc_status apply_single_controller_ctx_to_hw(
1467 struct pipe_ctx *pipe_ctx,
1468 struct dc_state *context,
1469 struct dc *dc)
1470 {
1471 struct dc_stream_state *stream = pipe_ctx->stream;
1472 struct dc_link *link = stream->link;
1473 struct drr_params params = {0};
1474 unsigned int event_triggers = 0;
1475 struct pipe_ctx *odm_pipe = pipe_ctx->next_odm_pipe;
1476 struct dce_hwseq *hws = dc->hwseq;
1477
1478 if (hws->funcs.disable_stream_gating) {
1479 hws->funcs.disable_stream_gating(dc, pipe_ctx);
1480 }
1481
1482 if (pipe_ctx->stream_res.audio != NULL) {
1483 struct audio_output audio_output;
1484
1485 build_audio_output(context, pipe_ctx, &audio_output);
1486
1487 if (dc_is_dp_signal(pipe_ctx->stream->signal))
1488 if (is_dp_128b_132b_signal(pipe_ctx))
1489 pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->dp_audio_setup(
1490 pipe_ctx->stream_res.hpo_dp_stream_enc,
1491 pipe_ctx->stream_res.audio->inst,
1492 &pipe_ctx->stream->audio_info);
1493 else
1494 pipe_ctx->stream_res.stream_enc->funcs->dp_audio_setup(
1495 pipe_ctx->stream_res.stream_enc,
1496 pipe_ctx->stream_res.audio->inst,
1497 &pipe_ctx->stream->audio_info);
1498 else
1499 pipe_ctx->stream_res.stream_enc->funcs->hdmi_audio_setup(
1500 pipe_ctx->stream_res.stream_enc,
1501 pipe_ctx->stream_res.audio->inst,
1502 &pipe_ctx->stream->audio_info,
1503 &audio_output.crtc_info);
1504
1505 pipe_ctx->stream_res.audio->funcs->az_configure(
1506 pipe_ctx->stream_res.audio,
1507 pipe_ctx->stream->signal,
1508 &audio_output.crtc_info,
1509 &pipe_ctx->stream->audio_info);
1510 }
1511
1512
1513 if (!pipe_ctx->stream->apply_seamless_boot_optimization && dc->config.use_pipe_ctx_sync_logic)
1514 check_syncd_pipes_for_disabled_master_pipe(dc, context, pipe_ctx->pipe_idx);
1515
1516 pipe_ctx->stream_res.opp->funcs->opp_program_fmt(
1517 pipe_ctx->stream_res.opp,
1518 &stream->bit_depth_params,
1519 &stream->clamping);
1520
1521 pipe_ctx->stream_res.opp->funcs->opp_set_dyn_expansion(
1522 pipe_ctx->stream_res.opp,
1523 COLOR_SPACE_YCBCR601,
1524 stream->timing.display_color_depth,
1525 stream->signal);
1526
1527 while (odm_pipe) {
1528 odm_pipe->stream_res.opp->funcs->opp_set_dyn_expansion(
1529 odm_pipe->stream_res.opp,
1530 COLOR_SPACE_YCBCR601,
1531 stream->timing.display_color_depth,
1532 stream->signal);
1533
1534 odm_pipe->stream_res.opp->funcs->opp_program_fmt(
1535 odm_pipe->stream_res.opp,
1536 &stream->bit_depth_params,
1537 &stream->clamping);
1538 odm_pipe = odm_pipe->next_odm_pipe;
1539 }
1540
1541
1542
1543
1544
1545
1546 if (!(hws->wa.dp_hpo_and_otg_sequence && is_dp_128b_132b_signal(pipe_ctx)))
1547
1548
1549 if (!pipe_ctx->stream->apply_seamless_boot_optimization)
1550 hws->funcs.enable_stream_timing(pipe_ctx, context, dc);
1551
1552 if (hws->funcs.setup_vupdate_interrupt)
1553 hws->funcs.setup_vupdate_interrupt(dc, pipe_ctx);
1554
1555 params.vertical_total_min = stream->adjust.v_total_min;
1556 params.vertical_total_max = stream->adjust.v_total_max;
1557 if (pipe_ctx->stream_res.tg->funcs->set_drr)
1558 pipe_ctx->stream_res.tg->funcs->set_drr(
1559 pipe_ctx->stream_res.tg, ¶ms);
1560
1561
1562 if (stream->adjust.v_total_min != 0 && stream->adjust.v_total_max != 0)
1563 event_triggers = 0x80;
1564
1565
1566
1567
1568 if (pipe_ctx->stream_res.tg->funcs->set_static_screen_control)
1569 pipe_ctx->stream_res.tg->funcs->set_static_screen_control(
1570 pipe_ctx->stream_res.tg, event_triggers, 2);
1571
1572 if (!dc_is_virtual_signal(pipe_ctx->stream->signal))
1573 pipe_ctx->stream_res.stream_enc->funcs->dig_connect_to_otg(
1574 pipe_ctx->stream_res.stream_enc,
1575 pipe_ctx->stream_res.tg->inst);
1576
1577 if (dc_is_dp_signal(pipe_ctx->stream->signal))
1578 dp_source_sequence_trace(link, DPCD_SOURCE_SEQ_AFTER_CONNECT_DIG_FE_OTG);
1579
1580 if (!stream->dpms_off)
1581 core_link_enable_stream(context, pipe_ctx);
1582
1583
1584
1585
1586
1587
1588 if (hws->wa.dp_hpo_and_otg_sequence && is_dp_128b_132b_signal(pipe_ctx)) {
1589 if (!pipe_ctx->stream->apply_seamless_boot_optimization)
1590 hws->funcs.enable_stream_timing(pipe_ctx, context, dc);
1591 }
1592
1593 pipe_ctx->plane_res.scl_data.lb_params.alpha_en = pipe_ctx->bottom_pipe != NULL;
1594
1595 pipe_ctx->stream->link->psr_settings.psr_feature_enabled = false;
1596
1597 return DC_OK;
1598 }
1599
1600
1601
1602 static void power_down_encoders(struct dc *dc)
1603 {
1604 int i;
1605
1606 for (i = 0; i < dc->link_count; i++) {
1607 enum signal_type signal = dc->links[i]->connector_signal;
1608
1609 dc_link_blank_dp_stream(dc->links[i], false);
1610
1611 if (signal != SIGNAL_TYPE_EDP)
1612 signal = SIGNAL_TYPE_NONE;
1613
1614 if (dc->links[i]->ep_type == DISPLAY_ENDPOINT_PHY)
1615 dc->links[i]->link_enc->funcs->disable_output(
1616 dc->links[i]->link_enc, signal);
1617
1618 dc->links[i]->link_status.link_active = false;
1619 memset(&dc->links[i]->cur_link_settings, 0,
1620 sizeof(dc->links[i]->cur_link_settings));
1621 }
1622 }
1623
1624 static void power_down_controllers(struct dc *dc)
1625 {
1626 int i;
1627
1628 for (i = 0; i < dc->res_pool->timing_generator_count; i++) {
1629 dc->res_pool->timing_generators[i]->funcs->disable_crtc(
1630 dc->res_pool->timing_generators[i]);
1631 }
1632 }
1633
1634 static void power_down_clock_sources(struct dc *dc)
1635 {
1636 int i;
1637
1638 if (dc->res_pool->dp_clock_source->funcs->cs_power_down(
1639 dc->res_pool->dp_clock_source) == false)
1640 dm_error("Failed to power down pll! (dp clk src)\n");
1641
1642 for (i = 0; i < dc->res_pool->clk_src_count; i++) {
1643 if (dc->res_pool->clock_sources[i]->funcs->cs_power_down(
1644 dc->res_pool->clock_sources[i]) == false)
1645 dm_error("Failed to power down pll! (clk src index=%d)\n", i);
1646 }
1647 }
1648
1649 static void power_down_all_hw_blocks(struct dc *dc)
1650 {
1651 power_down_encoders(dc);
1652
1653 power_down_controllers(dc);
1654
1655 power_down_clock_sources(dc);
1656
1657 if (dc->fbc_compressor)
1658 dc->fbc_compressor->funcs->disable_fbc(dc->fbc_compressor);
1659 }
1660
1661 static void disable_vga_and_power_gate_all_controllers(
1662 struct dc *dc)
1663 {
1664 int i;
1665 struct timing_generator *tg;
1666 struct dc_context *ctx = dc->ctx;
1667
1668 for (i = 0; i < dc->res_pool->timing_generator_count; i++) {
1669 tg = dc->res_pool->timing_generators[i];
1670
1671 if (tg->funcs->disable_vga)
1672 tg->funcs->disable_vga(tg);
1673 }
1674 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1675
1676
1677 enable_display_pipe_clock_gating(ctx,
1678 true);
1679
1680 dc->current_state->res_ctx.pipe_ctx[i].pipe_idx = i;
1681 dc->hwss.disable_plane(dc,
1682 &dc->current_state->res_ctx.pipe_ctx[i]);
1683 }
1684 }
1685
1686
1687 static void get_edp_streams(struct dc_state *context,
1688 struct dc_stream_state **edp_streams,
1689 int *edp_stream_num)
1690 {
1691 int i;
1692
1693 *edp_stream_num = 0;
1694 for (i = 0; i < context->stream_count; i++) {
1695 if (context->streams[i]->signal == SIGNAL_TYPE_EDP) {
1696 edp_streams[*edp_stream_num] = context->streams[i];
1697 if (++(*edp_stream_num) == MAX_NUM_EDP)
1698 return;
1699 }
1700 }
1701 }
1702
1703 static void get_edp_links_with_sink(
1704 struct dc *dc,
1705 struct dc_link **edp_links_with_sink,
1706 int *edp_with_sink_num)
1707 {
1708 int i;
1709
1710
1711 *edp_with_sink_num = 0;
1712 for (i = 0; i < dc->link_count; i++) {
1713 if (dc->links[i]->local_sink &&
1714 dc->links[i]->local_sink->sink_signal == SIGNAL_TYPE_EDP) {
1715 edp_links_with_sink[*edp_with_sink_num] = dc->links[i];
1716 if (++(*edp_with_sink_num) == MAX_NUM_EDP)
1717 return;
1718 }
1719 }
1720 }
1721
1722
1723
1724
1725
1726
1727
1728
1729 void dce110_enable_accelerated_mode(struct dc *dc, struct dc_state *context)
1730 {
1731 struct dc_link *edp_links_with_sink[MAX_NUM_EDP];
1732 struct dc_link *edp_links[MAX_NUM_EDP];
1733 struct dc_stream_state *edp_streams[MAX_NUM_EDP];
1734 struct dc_link *edp_link_with_sink = NULL;
1735 struct dc_link *edp_link = NULL;
1736 struct dce_hwseq *hws = dc->hwseq;
1737 int edp_with_sink_num;
1738 int edp_num;
1739 int edp_stream_num;
1740 int i;
1741 bool can_apply_edp_fast_boot = false;
1742 bool can_apply_seamless_boot = false;
1743 bool keep_edp_vdd_on = false;
1744 DC_LOGGER_INIT();
1745
1746
1747 get_edp_links_with_sink(dc, edp_links_with_sink, &edp_with_sink_num);
1748 get_edp_links(dc, edp_links, &edp_num);
1749
1750 if (hws->funcs.init_pipes)
1751 hws->funcs.init_pipes(dc, context);
1752
1753 get_edp_streams(context, edp_streams, &edp_stream_num);
1754
1755
1756 if (edp_num && edp_stream_num && dc->ctx->dce_version != DCE_VERSION_8_0 &&
1757 dc->ctx->dce_version != DCE_VERSION_8_1 &&
1758 dc->ctx->dce_version != DCE_VERSION_8_3) {
1759 for (i = 0; i < edp_num; i++) {
1760 edp_link = edp_links[i];
1761 if (edp_link != edp_streams[0]->link)
1762 continue;
1763
1764 if (edp_link->link_enc->funcs->is_dig_enabled &&
1765 edp_link->link_enc->funcs->is_dig_enabled(edp_link->link_enc) &&
1766 edp_link->link_status.link_active) {
1767 struct dc_stream_state *edp_stream = edp_streams[0];
1768
1769 can_apply_edp_fast_boot = dc_validate_boot_timing(dc,
1770 edp_stream->sink, &edp_stream->timing);
1771 edp_stream->apply_edp_fast_boot_optimization = can_apply_edp_fast_boot;
1772 if (can_apply_edp_fast_boot)
1773 DC_LOG_EVENT_LINK_TRAINING("eDP fast boot disabled to optimize link rate\n");
1774
1775 break;
1776 }
1777 }
1778
1779 if (can_apply_edp_fast_boot)
1780 keep_edp_vdd_on = true;
1781 }
1782
1783
1784 for (i = 0; i < context->stream_count; i++) {
1785 if (context->streams[i]->apply_seamless_boot_optimization) {
1786 can_apply_seamless_boot = true;
1787 break;
1788 }
1789 }
1790
1791
1792
1793
1794 if (edp_with_sink_num)
1795 edp_link_with_sink = edp_links_with_sink[0];
1796
1797 if (!can_apply_edp_fast_boot && !can_apply_seamless_boot) {
1798 if (edp_link_with_sink && !keep_edp_vdd_on) {
1799
1800 hws->funcs.edp_backlight_control(edp_link_with_sink, false);
1801 }
1802
1803 power_down_all_hw_blocks(dc);
1804 disable_vga_and_power_gate_all_controllers(dc);
1805 if (edp_link_with_sink && !keep_edp_vdd_on)
1806 dc->hwss.edp_power_control(edp_link_with_sink, false);
1807 }
1808 bios_set_scratch_acc_mode_change(dc->ctx->dc_bios, 1);
1809 }
1810
1811 static uint32_t compute_pstate_blackout_duration(
1812 struct bw_fixed blackout_duration,
1813 const struct dc_stream_state *stream)
1814 {
1815 uint32_t total_dest_line_time_ns;
1816 uint32_t pstate_blackout_duration_ns;
1817
1818 pstate_blackout_duration_ns = 1000 * blackout_duration.value >> 24;
1819
1820 total_dest_line_time_ns = 1000000UL *
1821 (stream->timing.h_total * 10) /
1822 stream->timing.pix_clk_100hz +
1823 pstate_blackout_duration_ns;
1824
1825 return total_dest_line_time_ns;
1826 }
1827
1828 static void dce110_set_displaymarks(
1829 const struct dc *dc,
1830 struct dc_state *context)
1831 {
1832 uint8_t i, num_pipes;
1833 unsigned int underlay_idx = dc->res_pool->underlay_pipe_index;
1834
1835 for (i = 0, num_pipes = 0; i < MAX_PIPES; i++) {
1836 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
1837 uint32_t total_dest_line_time_ns;
1838
1839 if (pipe_ctx->stream == NULL)
1840 continue;
1841
1842 total_dest_line_time_ns = compute_pstate_blackout_duration(
1843 dc->bw_vbios->blackout_duration, pipe_ctx->stream);
1844 pipe_ctx->plane_res.mi->funcs->mem_input_program_display_marks(
1845 pipe_ctx->plane_res.mi,
1846 context->bw_ctx.bw.dce.nbp_state_change_wm_ns[num_pipes],
1847 context->bw_ctx.bw.dce.stutter_exit_wm_ns[num_pipes],
1848 context->bw_ctx.bw.dce.stutter_entry_wm_ns[num_pipes],
1849 context->bw_ctx.bw.dce.urgent_wm_ns[num_pipes],
1850 total_dest_line_time_ns);
1851 if (i == underlay_idx) {
1852 num_pipes++;
1853 pipe_ctx->plane_res.mi->funcs->mem_input_program_chroma_display_marks(
1854 pipe_ctx->plane_res.mi,
1855 context->bw_ctx.bw.dce.nbp_state_change_wm_ns[num_pipes],
1856 context->bw_ctx.bw.dce.stutter_exit_wm_ns[num_pipes],
1857 context->bw_ctx.bw.dce.urgent_wm_ns[num_pipes],
1858 total_dest_line_time_ns);
1859 }
1860 num_pipes++;
1861 }
1862 }
1863
1864 void dce110_set_safe_displaymarks(
1865 struct resource_context *res_ctx,
1866 const struct resource_pool *pool)
1867 {
1868 int i;
1869 int underlay_idx = pool->underlay_pipe_index;
1870 struct dce_watermarks max_marks = {
1871 MAX_WATERMARK, MAX_WATERMARK, MAX_WATERMARK, MAX_WATERMARK };
1872 struct dce_watermarks nbp_marks = {
1873 SAFE_NBP_MARK, SAFE_NBP_MARK, SAFE_NBP_MARK, SAFE_NBP_MARK };
1874 struct dce_watermarks min_marks = { 0, 0, 0, 0};
1875
1876 for (i = 0; i < MAX_PIPES; i++) {
1877 if (res_ctx->pipe_ctx[i].stream == NULL || res_ctx->pipe_ctx[i].plane_res.mi == NULL)
1878 continue;
1879
1880 res_ctx->pipe_ctx[i].plane_res.mi->funcs->mem_input_program_display_marks(
1881 res_ctx->pipe_ctx[i].plane_res.mi,
1882 nbp_marks,
1883 max_marks,
1884 min_marks,
1885 max_marks,
1886 MAX_WATERMARK);
1887
1888 if (i == underlay_idx)
1889 res_ctx->pipe_ctx[i].plane_res.mi->funcs->mem_input_program_chroma_display_marks(
1890 res_ctx->pipe_ctx[i].plane_res.mi,
1891 nbp_marks,
1892 max_marks,
1893 max_marks,
1894 MAX_WATERMARK);
1895
1896 }
1897 }
1898
1899
1900
1901
1902
1903 static void set_drr(struct pipe_ctx **pipe_ctx,
1904 int num_pipes, struct dc_crtc_timing_adjust adjust)
1905 {
1906 int i = 0;
1907 struct drr_params params = {0};
1908
1909 unsigned int event_triggers = 0x80;
1910
1911 unsigned int num_frames = 2;
1912
1913 params.vertical_total_max = adjust.v_total_max;
1914 params.vertical_total_min = adjust.v_total_min;
1915
1916
1917
1918
1919
1920 for (i = 0; i < num_pipes; i++) {
1921 pipe_ctx[i]->stream_res.tg->funcs->set_drr(
1922 pipe_ctx[i]->stream_res.tg, ¶ms);
1923
1924 if (adjust.v_total_max != 0 && adjust.v_total_min != 0)
1925 pipe_ctx[i]->stream_res.tg->funcs->set_static_screen_control(
1926 pipe_ctx[i]->stream_res.tg,
1927 event_triggers, num_frames);
1928 }
1929 }
1930
1931 static void get_position(struct pipe_ctx **pipe_ctx,
1932 int num_pipes,
1933 struct crtc_position *position)
1934 {
1935 int i = 0;
1936
1937
1938
1939 for (i = 0; i < num_pipes; i++)
1940 pipe_ctx[i]->stream_res.tg->funcs->get_position(pipe_ctx[i]->stream_res.tg, position);
1941 }
1942
1943 static void set_static_screen_control(struct pipe_ctx **pipe_ctx,
1944 int num_pipes, const struct dc_static_screen_params *params)
1945 {
1946 unsigned int i;
1947 unsigned int triggers = 0;
1948
1949 if (params->triggers.overlay_update)
1950 triggers |= 0x100;
1951 if (params->triggers.surface_update)
1952 triggers |= 0x80;
1953 if (params->triggers.cursor_update)
1954 triggers |= 0x2;
1955 if (params->triggers.force_trigger)
1956 triggers |= 0x1;
1957
1958 if (num_pipes) {
1959 struct dc *dc = pipe_ctx[0]->stream->ctx->dc;
1960
1961 if (dc->fbc_compressor)
1962 triggers |= 0x84;
1963 }
1964
1965 for (i = 0; i < num_pipes; i++)
1966 pipe_ctx[i]->stream_res.tg->funcs->
1967 set_static_screen_control(pipe_ctx[i]->stream_res.tg,
1968 triggers, params->num_frames);
1969 }
1970
1971
1972
1973
1974 static bool should_enable_fbc(struct dc *dc,
1975 struct dc_state *context,
1976 uint32_t *pipe_idx)
1977 {
1978 uint32_t i;
1979 struct pipe_ctx *pipe_ctx = NULL;
1980 struct resource_context *res_ctx = &context->res_ctx;
1981 unsigned int underlay_idx = dc->res_pool->underlay_pipe_index;
1982
1983
1984 ASSERT(dc->fbc_compressor);
1985
1986
1987 if (!dc->ctx->fbc_gpu_addr)
1988 return false;
1989
1990
1991 if (context->stream_count != 1)
1992 return false;
1993
1994 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1995 if (res_ctx->pipe_ctx[i].stream) {
1996
1997 pipe_ctx = &res_ctx->pipe_ctx[i];
1998
1999 if (!pipe_ctx)
2000 continue;
2001
2002
2003 if (pipe_ctx->pipe_idx != underlay_idx) {
2004 *pipe_idx = i;
2005 break;
2006 }
2007 }
2008 }
2009
2010 if (i == dc->res_pool->pipe_count)
2011 return false;
2012
2013 if (!pipe_ctx->stream->link)
2014 return false;
2015
2016
2017 if (pipe_ctx->stream->link->connector_signal != SIGNAL_TYPE_EDP)
2018 return false;
2019
2020
2021 if (pipe_ctx->stream->link->psr_settings.psr_feature_enabled)
2022 return false;
2023
2024
2025 if (!pipe_ctx->plane_state)
2026 return false;
2027
2028
2029 if (pipe_ctx->plane_state->tiling_info.gfx8.array_mode == DC_ARRAY_LINEAR_GENERAL)
2030 return false;
2031
2032 return true;
2033 }
2034
2035
2036
2037
2038 static void enable_fbc(
2039 struct dc *dc,
2040 struct dc_state *context)
2041 {
2042 uint32_t pipe_idx = 0;
2043
2044 if (should_enable_fbc(dc, context, &pipe_idx)) {
2045
2046 struct compr_addr_and_pitch_params params = {0, 0, 0};
2047 struct compressor *compr = dc->fbc_compressor;
2048 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[pipe_idx];
2049
2050 params.source_view_width = pipe_ctx->stream->timing.h_addressable;
2051 params.source_view_height = pipe_ctx->stream->timing.v_addressable;
2052 params.inst = pipe_ctx->stream_res.tg->inst;
2053 compr->compr_surface_address.quad_part = dc->ctx->fbc_gpu_addr;
2054
2055 compr->funcs->surface_address_and_pitch(compr, ¶ms);
2056 compr->funcs->set_fbc_invalidation_triggers(compr, 1);
2057
2058 compr->funcs->enable_fbc(compr, ¶ms);
2059 }
2060 }
2061
2062 static void dce110_reset_hw_ctx_wrap(
2063 struct dc *dc,
2064 struct dc_state *context)
2065 {
2066 int i;
2067
2068
2069
2070 for (i = 0; i < MAX_PIPES; i++) {
2071 struct pipe_ctx *pipe_ctx_old =
2072 &dc->current_state->res_ctx.pipe_ctx[i];
2073 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2074
2075
2076
2077
2078
2079
2080
2081 if (!pipe_ctx_old->stream || pipe_ctx_old->top_pipe)
2082 continue;
2083
2084 if (!pipe_ctx->stream ||
2085 pipe_need_reprogram(pipe_ctx_old, pipe_ctx)) {
2086 struct clock_source *old_clk = pipe_ctx_old->clock_source;
2087
2088
2089
2090
2091 if (!pipe_ctx->stream || !pipe_ctx->stream->dpms_off) {
2092 core_link_disable_stream(pipe_ctx_old);
2093
2094
2095 if (pipe_ctx_old->stream_res.audio) {
2096
2097 pipe_ctx_old->stream_res.audio->funcs->
2098 az_disable(pipe_ctx_old->stream_res.audio);
2099
2100
2101 if (dc->caps.dynamic_audio == true) {
2102
2103
2104 update_audio_usage(&dc->current_state->res_ctx, dc->res_pool,
2105 pipe_ctx_old->stream_res.audio, false);
2106 pipe_ctx_old->stream_res.audio = NULL;
2107 }
2108 }
2109 }
2110
2111 pipe_ctx_old->stream_res.tg->funcs->set_blank(pipe_ctx_old->stream_res.tg, true);
2112 if (!hwss_wait_for_blank_complete(pipe_ctx_old->stream_res.tg)) {
2113 dm_error("DC: failed to blank crtc!\n");
2114 BREAK_TO_DEBUGGER();
2115 }
2116 pipe_ctx_old->stream_res.tg->funcs->disable_crtc(pipe_ctx_old->stream_res.tg);
2117 pipe_ctx_old->plane_res.mi->funcs->free_mem_input(
2118 pipe_ctx_old->plane_res.mi, dc->current_state->stream_count);
2119
2120 if (old_clk && 0 == resource_get_clock_source_reference(&context->res_ctx,
2121 dc->res_pool,
2122 old_clk))
2123 old_clk->funcs->cs_power_down(old_clk);
2124
2125 dc->hwss.disable_plane(dc, pipe_ctx_old);
2126
2127 pipe_ctx_old->stream = NULL;
2128 }
2129 }
2130 }
2131
2132 static void dce110_setup_audio_dto(
2133 struct dc *dc,
2134 struct dc_state *context)
2135 {
2136 int i;
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2158 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2159
2160 if (pipe_ctx->stream == NULL)
2161 continue;
2162
2163 if (pipe_ctx->top_pipe)
2164 continue;
2165 if (pipe_ctx->stream->signal != SIGNAL_TYPE_HDMI_TYPE_A)
2166 continue;
2167 if (pipe_ctx->stream_res.audio != NULL) {
2168 struct audio_output audio_output;
2169
2170 build_audio_output(context, pipe_ctx, &audio_output);
2171
2172 if (dc->res_pool->dccg && dc->res_pool->dccg->funcs->set_audio_dtbclk_dto) {
2173 struct dtbclk_dto_params dto_params = {0};
2174
2175 dc->res_pool->dccg->funcs->set_audio_dtbclk_dto(
2176 dc->res_pool->dccg, &dto_params);
2177
2178 pipe_ctx->stream_res.audio->funcs->wall_dto_setup(
2179 pipe_ctx->stream_res.audio,
2180 pipe_ctx->stream->signal,
2181 &audio_output.crtc_info,
2182 &audio_output.pll_info);
2183 } else
2184 pipe_ctx->stream_res.audio->funcs->wall_dto_setup(
2185 pipe_ctx->stream_res.audio,
2186 pipe_ctx->stream->signal,
2187 &audio_output.crtc_info,
2188 &audio_output.pll_info);
2189 break;
2190 }
2191 }
2192
2193
2194 if (i == dc->res_pool->pipe_count) {
2195 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2196 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2197
2198 if (pipe_ctx->stream == NULL)
2199 continue;
2200
2201 if (pipe_ctx->top_pipe)
2202 continue;
2203
2204 if (!dc_is_dp_signal(pipe_ctx->stream->signal))
2205 continue;
2206
2207 if (pipe_ctx->stream_res.audio != NULL) {
2208 struct audio_output audio_output;
2209
2210 build_audio_output(context, pipe_ctx, &audio_output);
2211
2212 pipe_ctx->stream_res.audio->funcs->wall_dto_setup(
2213 pipe_ctx->stream_res.audio,
2214 pipe_ctx->stream->signal,
2215 &audio_output.crtc_info,
2216 &audio_output.pll_info);
2217 break;
2218 }
2219 }
2220 }
2221 }
2222
2223 enum dc_status dce110_apply_ctx_to_hw(
2224 struct dc *dc,
2225 struct dc_state *context)
2226 {
2227 struct dce_hwseq *hws = dc->hwseq;
2228 struct dc_bios *dcb = dc->ctx->dc_bios;
2229 enum dc_status status;
2230 int i;
2231
2232
2233 if (dc->config.use_pipe_ctx_sync_logic)
2234 reset_syncd_pipes_from_disabled_pipes(dc, context);
2235
2236
2237
2238 hws->funcs.reset_hw_ctx_wrap(dc, context);
2239
2240
2241 if (context->stream_count <= 0)
2242 return DC_OK;
2243
2244
2245 dcb->funcs->set_scratch_critical_state(dcb, true);
2246
2247
2248 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2249 struct pipe_ctx *pipe_ctx_old =
2250 &dc->current_state->res_ctx.pipe_ctx[i];
2251 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2252
2253 if (pipe_ctx->stream == NULL || pipe_ctx->top_pipe)
2254 continue;
2255
2256 if (pipe_ctx->stream == pipe_ctx_old->stream) {
2257 if (pipe_ctx_old->clock_source != pipe_ctx->clock_source)
2258 dce_crtc_switch_to_clk_src(dc->hwseq,
2259 pipe_ctx->clock_source, i);
2260 continue;
2261 }
2262
2263 hws->funcs.enable_display_power_gating(
2264 dc, i, dc->ctx->dc_bios,
2265 PIPE_GATING_CONTROL_DISABLE);
2266 }
2267
2268 if (dc->fbc_compressor)
2269 dc->fbc_compressor->funcs->disable_fbc(dc->fbc_compressor);
2270
2271 dce110_setup_audio_dto(dc, context);
2272
2273 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2274 struct pipe_ctx *pipe_ctx_old =
2275 &dc->current_state->res_ctx.pipe_ctx[i];
2276 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2277
2278 if (pipe_ctx->stream == NULL)
2279 continue;
2280
2281 if (pipe_ctx->stream == pipe_ctx_old->stream &&
2282 pipe_ctx->stream->link->link_state_valid) {
2283 continue;
2284 }
2285
2286 if (pipe_ctx_old->stream && !pipe_need_reprogram(pipe_ctx_old, pipe_ctx))
2287 continue;
2288
2289 if (pipe_ctx->top_pipe || pipe_ctx->prev_odm_pipe)
2290 continue;
2291
2292 status = apply_single_controller_ctx_to_hw(
2293 pipe_ctx,
2294 context,
2295 dc);
2296
2297 if (DC_OK != status)
2298 return status;
2299 }
2300
2301 if (dc->fbc_compressor)
2302 enable_fbc(dc, dc->current_state);
2303
2304 dcb->funcs->set_scratch_critical_state(dcb, false);
2305
2306 return DC_OK;
2307 }
2308
2309
2310
2311
2312 static void set_default_colors(struct pipe_ctx *pipe_ctx)
2313 {
2314 struct default_adjustment default_adjust = { 0 };
2315
2316 default_adjust.force_hw_default = false;
2317 default_adjust.in_color_space = pipe_ctx->plane_state->color_space;
2318 default_adjust.out_color_space = pipe_ctx->stream->output_color_space;
2319 default_adjust.csc_adjust_type = GRAPHICS_CSC_ADJUST_TYPE_SW;
2320 default_adjust.surface_pixel_format = pipe_ctx->plane_res.scl_data.format;
2321
2322
2323 default_adjust.color_depth =
2324 pipe_ctx->stream->timing.display_color_depth;
2325
2326
2327 default_adjust.lb_color_depth = pipe_ctx->plane_res.scl_data.lb_params.depth;
2328
2329 pipe_ctx->plane_res.xfm->funcs->opp_set_csc_default(
2330 pipe_ctx->plane_res.xfm, &default_adjust);
2331 }
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353 static void program_surface_visibility(const struct dc *dc,
2354 struct pipe_ctx *pipe_ctx)
2355 {
2356 enum blnd_mode blender_mode = BLND_MODE_CURRENT_PIPE;
2357 bool blank_target = false;
2358
2359 if (pipe_ctx->bottom_pipe) {
2360
2361
2362 ASSERT(pipe_ctx->bottom_pipe->bottom_pipe == NULL);
2363
2364 if (pipe_ctx->bottom_pipe->plane_state->visible) {
2365 if (pipe_ctx->plane_state->visible)
2366 blender_mode = BLND_MODE_BLENDING;
2367 else
2368 blender_mode = BLND_MODE_OTHER_PIPE;
2369
2370 } else if (!pipe_ctx->plane_state->visible)
2371 blank_target = true;
2372
2373 } else if (!pipe_ctx->plane_state->visible)
2374 blank_target = true;
2375
2376 dce_set_blender_mode(dc->hwseq, pipe_ctx->stream_res.tg->inst, blender_mode);
2377 pipe_ctx->stream_res.tg->funcs->set_blank(pipe_ctx->stream_res.tg, blank_target);
2378
2379 }
2380
2381 static void program_gamut_remap(struct pipe_ctx *pipe_ctx)
2382 {
2383 int i = 0;
2384 struct xfm_grph_csc_adjustment adjust;
2385 memset(&adjust, 0, sizeof(adjust));
2386 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS;
2387
2388
2389 if (pipe_ctx->stream->gamut_remap_matrix.enable_remap == true) {
2390 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_SW;
2391
2392 for (i = 0; i < CSC_TEMPERATURE_MATRIX_SIZE; i++)
2393 adjust.temperature_matrix[i] =
2394 pipe_ctx->stream->gamut_remap_matrix.matrix[i];
2395 }
2396
2397 pipe_ctx->plane_res.xfm->funcs->transform_set_gamut_remap(pipe_ctx->plane_res.xfm, &adjust);
2398 }
2399 static void update_plane_addr(const struct dc *dc,
2400 struct pipe_ctx *pipe_ctx)
2401 {
2402 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
2403
2404 if (plane_state == NULL)
2405 return;
2406
2407 pipe_ctx->plane_res.mi->funcs->mem_input_program_surface_flip_and_addr(
2408 pipe_ctx->plane_res.mi,
2409 &plane_state->address,
2410 plane_state->flip_immediate);
2411
2412 plane_state->status.requested_address = plane_state->address;
2413 }
2414
2415 static void dce110_update_pending_status(struct pipe_ctx *pipe_ctx)
2416 {
2417 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
2418
2419 if (plane_state == NULL)
2420 return;
2421
2422 plane_state->status.is_flip_pending =
2423 pipe_ctx->plane_res.mi->funcs->mem_input_is_flip_pending(
2424 pipe_ctx->plane_res.mi);
2425
2426 if (plane_state->status.is_flip_pending && !plane_state->visible)
2427 pipe_ctx->plane_res.mi->current_address = pipe_ctx->plane_res.mi->request_address;
2428
2429 plane_state->status.current_address = pipe_ctx->plane_res.mi->current_address;
2430 if (pipe_ctx->plane_res.mi->current_address.type == PLN_ADDR_TYPE_GRPH_STEREO &&
2431 pipe_ctx->stream_res.tg->funcs->is_stereo_left_eye) {
2432 plane_state->status.is_right_eye =\
2433 !pipe_ctx->stream_res.tg->funcs->is_stereo_left_eye(pipe_ctx->stream_res.tg);
2434 }
2435 }
2436
2437 void dce110_power_down(struct dc *dc)
2438 {
2439 power_down_all_hw_blocks(dc);
2440 disable_vga_and_power_gate_all_controllers(dc);
2441 }
2442
2443 static bool wait_for_reset_trigger_to_occur(
2444 struct dc_context *dc_ctx,
2445 struct timing_generator *tg)
2446 {
2447 bool rc = false;
2448
2449
2450
2451 const uint32_t frames_to_wait_on_triggered_reset = 10;
2452 uint32_t i;
2453
2454 for (i = 0; i < frames_to_wait_on_triggered_reset; i++) {
2455
2456 if (!tg->funcs->is_counter_moving(tg)) {
2457 DC_ERROR("TG counter is not moving!\n");
2458 break;
2459 }
2460
2461 if (tg->funcs->did_triggered_reset_occur(tg)) {
2462 rc = true;
2463
2464 DC_SYNC_INFO("GSL: reset occurred at wait count: %d\n",
2465 i);
2466 break;
2467 }
2468
2469
2470 tg->funcs->wait_for_state(tg, CRTC_STATE_VACTIVE);
2471 tg->funcs->wait_for_state(tg, CRTC_STATE_VBLANK);
2472 }
2473
2474 if (false == rc)
2475 DC_ERROR("GSL: Timeout on reset trigger!\n");
2476
2477 return rc;
2478 }
2479
2480
2481 static void dce110_enable_timing_synchronization(
2482 struct dc *dc,
2483 int group_index,
2484 int group_size,
2485 struct pipe_ctx *grouped_pipes[])
2486 {
2487 struct dc_context *dc_ctx = dc->ctx;
2488 struct dcp_gsl_params gsl_params = { 0 };
2489 int i;
2490
2491 DC_SYNC_INFO("GSL: Setting-up...\n");
2492
2493
2494
2495
2496 gsl_params.gsl_group = 0;
2497 gsl_params.gsl_master = grouped_pipes[0]->stream_res.tg->inst;
2498
2499 for (i = 0; i < group_size; i++)
2500 grouped_pipes[i]->stream_res.tg->funcs->setup_global_swap_lock(
2501 grouped_pipes[i]->stream_res.tg, &gsl_params);
2502
2503
2504 DC_SYNC_INFO("GSL: enabling trigger-reset\n");
2505
2506 for (i = 1 ; i < group_size; i++)
2507 grouped_pipes[i]->stream_res.tg->funcs->enable_reset_trigger(
2508 grouped_pipes[i]->stream_res.tg,
2509 gsl_params.gsl_group);
2510
2511 for (i = 1 ; i < group_size; i++) {
2512 DC_SYNC_INFO("GSL: waiting for reset to occur.\n");
2513 wait_for_reset_trigger_to_occur(dc_ctx, grouped_pipes[i]->stream_res.tg);
2514 grouped_pipes[i]->stream_res.tg->funcs->disable_reset_trigger(
2515 grouped_pipes[i]->stream_res.tg);
2516 }
2517
2518
2519
2520 DC_SYNC_INFO("GSL: Restoring register states.\n");
2521 for (i = 0; i < group_size; i++)
2522 grouped_pipes[i]->stream_res.tg->funcs->tear_down_global_swap_lock(grouped_pipes[i]->stream_res.tg);
2523
2524 DC_SYNC_INFO("GSL: Set-up complete.\n");
2525 }
2526
2527 static void dce110_enable_per_frame_crtc_position_reset(
2528 struct dc *dc,
2529 int group_size,
2530 struct pipe_ctx *grouped_pipes[])
2531 {
2532 struct dc_context *dc_ctx = dc->ctx;
2533 struct dcp_gsl_params gsl_params = { 0 };
2534 int i;
2535
2536 gsl_params.gsl_group = 0;
2537 gsl_params.gsl_master = 0;
2538
2539 for (i = 0; i < group_size; i++)
2540 grouped_pipes[i]->stream_res.tg->funcs->setup_global_swap_lock(
2541 grouped_pipes[i]->stream_res.tg, &gsl_params);
2542
2543 DC_SYNC_INFO("GSL: enabling trigger-reset\n");
2544
2545 for (i = 1; i < group_size; i++)
2546 grouped_pipes[i]->stream_res.tg->funcs->enable_crtc_reset(
2547 grouped_pipes[i]->stream_res.tg,
2548 gsl_params.gsl_master,
2549 &grouped_pipes[i]->stream->triggered_crtc_reset);
2550
2551 DC_SYNC_INFO("GSL: waiting for reset to occur.\n");
2552 for (i = 1; i < group_size; i++)
2553 wait_for_reset_trigger_to_occur(dc_ctx, grouped_pipes[i]->stream_res.tg);
2554
2555 for (i = 0; i < group_size; i++)
2556 grouped_pipes[i]->stream_res.tg->funcs->tear_down_global_swap_lock(grouped_pipes[i]->stream_res.tg);
2557
2558 }
2559
2560 static void init_pipes(struct dc *dc, struct dc_state *context)
2561 {
2562
2563 }
2564
2565 static void init_hw(struct dc *dc)
2566 {
2567 int i;
2568 struct dc_bios *bp;
2569 struct transform *xfm;
2570 struct abm *abm;
2571 struct dmcu *dmcu;
2572 struct dce_hwseq *hws = dc->hwseq;
2573 uint32_t backlight = MAX_BACKLIGHT_LEVEL;
2574
2575 bp = dc->ctx->dc_bios;
2576 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2577 xfm = dc->res_pool->transforms[i];
2578 xfm->funcs->transform_reset(xfm);
2579
2580 hws->funcs.enable_display_power_gating(
2581 dc, i, bp,
2582 PIPE_GATING_CONTROL_INIT);
2583 hws->funcs.enable_display_power_gating(
2584 dc, i, bp,
2585 PIPE_GATING_CONTROL_DISABLE);
2586 hws->funcs.enable_display_pipe_clock_gating(
2587 dc->ctx,
2588 true);
2589 }
2590
2591 dce_clock_gating_power_up(dc->hwseq, false);
2592
2593
2594 for (i = 0; i < dc->link_count; i++) {
2595
2596
2597
2598
2599 struct dc_link *link = dc->links[i];
2600
2601 link->link_enc->funcs->hw_init(link->link_enc);
2602 }
2603
2604 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2605 struct timing_generator *tg = dc->res_pool->timing_generators[i];
2606
2607 tg->funcs->disable_vga(tg);
2608
2609
2610
2611 tg->funcs->set_blank(tg, true);
2612 hwss_wait_for_blank_complete(tg);
2613 }
2614
2615 for (i = 0; i < dc->res_pool->audio_count; i++) {
2616 struct audio *audio = dc->res_pool->audios[i];
2617 audio->funcs->hw_init(audio);
2618 }
2619
2620 for (i = 0; i < dc->link_count; i++) {
2621 struct dc_link *link = dc->links[i];
2622
2623 if (link->panel_cntl)
2624 backlight = link->panel_cntl->funcs->hw_init(link->panel_cntl);
2625 }
2626
2627 abm = dc->res_pool->abm;
2628 if (abm != NULL)
2629 abm->funcs->abm_init(abm, backlight);
2630
2631 dmcu = dc->res_pool->dmcu;
2632 if (dmcu != NULL && abm != NULL)
2633 abm->dmcu_is_running = dmcu->funcs->is_dmcu_initialized(dmcu);
2634
2635 if (dc->fbc_compressor)
2636 dc->fbc_compressor->funcs->power_up_fbc(dc->fbc_compressor);
2637
2638 }
2639
2640
2641 void dce110_prepare_bandwidth(
2642 struct dc *dc,
2643 struct dc_state *context)
2644 {
2645 struct clk_mgr *dccg = dc->clk_mgr;
2646
2647 dce110_set_safe_displaymarks(&context->res_ctx, dc->res_pool);
2648
2649 dccg->funcs->update_clocks(
2650 dccg,
2651 context,
2652 false);
2653 }
2654
2655 void dce110_optimize_bandwidth(
2656 struct dc *dc,
2657 struct dc_state *context)
2658 {
2659 struct clk_mgr *dccg = dc->clk_mgr;
2660
2661 dce110_set_displaymarks(dc, context);
2662
2663 dccg->funcs->update_clocks(
2664 dccg,
2665 context,
2666 true);
2667 }
2668
2669 static void dce110_program_front_end_for_pipe(
2670 struct dc *dc, struct pipe_ctx *pipe_ctx)
2671 {
2672 struct mem_input *mi = pipe_ctx->plane_res.mi;
2673 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
2674 struct xfm_grph_csc_adjustment adjust;
2675 struct out_csc_color_matrix tbl_entry;
2676 unsigned int i;
2677 struct dce_hwseq *hws = dc->hwseq;
2678
2679 DC_LOGGER_INIT();
2680 memset(&tbl_entry, 0, sizeof(tbl_entry));
2681
2682 memset(&adjust, 0, sizeof(adjust));
2683 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS;
2684
2685 dce_enable_fe_clock(dc->hwseq, mi->inst, true);
2686
2687 set_default_colors(pipe_ctx);
2688 if (pipe_ctx->stream->csc_color_matrix.enable_adjustment
2689 == true) {
2690 tbl_entry.color_space =
2691 pipe_ctx->stream->output_color_space;
2692
2693 for (i = 0; i < 12; i++)
2694 tbl_entry.regval[i] =
2695 pipe_ctx->stream->csc_color_matrix.matrix[i];
2696
2697 pipe_ctx->plane_res.xfm->funcs->opp_set_csc_adjustment
2698 (pipe_ctx->plane_res.xfm, &tbl_entry);
2699 }
2700
2701 if (pipe_ctx->stream->gamut_remap_matrix.enable_remap == true) {
2702 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_SW;
2703
2704 for (i = 0; i < CSC_TEMPERATURE_MATRIX_SIZE; i++)
2705 adjust.temperature_matrix[i] =
2706 pipe_ctx->stream->gamut_remap_matrix.matrix[i];
2707 }
2708
2709 pipe_ctx->plane_res.xfm->funcs->transform_set_gamut_remap(pipe_ctx->plane_res.xfm, &adjust);
2710
2711 pipe_ctx->plane_res.scl_data.lb_params.alpha_en = pipe_ctx->bottom_pipe != NULL;
2712
2713 program_scaler(dc, pipe_ctx);
2714
2715 mi->funcs->mem_input_program_surface_config(
2716 mi,
2717 plane_state->format,
2718 &plane_state->tiling_info,
2719 &plane_state->plane_size,
2720 plane_state->rotation,
2721 NULL,
2722 false);
2723 if (mi->funcs->set_blank)
2724 mi->funcs->set_blank(mi, pipe_ctx->plane_state->visible);
2725
2726 if (dc->config.gpu_vm_support)
2727 mi->funcs->mem_input_program_pte_vm(
2728 pipe_ctx->plane_res.mi,
2729 plane_state->format,
2730 &plane_state->tiling_info,
2731 plane_state->rotation);
2732
2733
2734 if (pipe_ctx->plane_state->update_flags.bits.full_update ||
2735 pipe_ctx->plane_state->update_flags.bits.in_transfer_func_change ||
2736 pipe_ctx->plane_state->update_flags.bits.gamma_change)
2737 hws->funcs.set_input_transfer_func(dc, pipe_ctx, pipe_ctx->plane_state);
2738
2739 if (pipe_ctx->plane_state->update_flags.bits.full_update)
2740 hws->funcs.set_output_transfer_func(dc, pipe_ctx, pipe_ctx->stream);
2741
2742 DC_LOG_SURFACE(
2743 "Pipe:%d %p: addr hi:0x%x, "
2744 "addr low:0x%x, "
2745 "src: %d, %d, %d,"
2746 " %d; dst: %d, %d, %d, %d;"
2747 "clip: %d, %d, %d, %d\n",
2748 pipe_ctx->pipe_idx,
2749 (void *) pipe_ctx->plane_state,
2750 pipe_ctx->plane_state->address.grph.addr.high_part,
2751 pipe_ctx->plane_state->address.grph.addr.low_part,
2752 pipe_ctx->plane_state->src_rect.x,
2753 pipe_ctx->plane_state->src_rect.y,
2754 pipe_ctx->plane_state->src_rect.width,
2755 pipe_ctx->plane_state->src_rect.height,
2756 pipe_ctx->plane_state->dst_rect.x,
2757 pipe_ctx->plane_state->dst_rect.y,
2758 pipe_ctx->plane_state->dst_rect.width,
2759 pipe_ctx->plane_state->dst_rect.height,
2760 pipe_ctx->plane_state->clip_rect.x,
2761 pipe_ctx->plane_state->clip_rect.y,
2762 pipe_ctx->plane_state->clip_rect.width,
2763 pipe_ctx->plane_state->clip_rect.height);
2764
2765 DC_LOG_SURFACE(
2766 "Pipe %d: width, height, x, y\n"
2767 "viewport:%d, %d, %d, %d\n"
2768 "recout: %d, %d, %d, %d\n",
2769 pipe_ctx->pipe_idx,
2770 pipe_ctx->plane_res.scl_data.viewport.width,
2771 pipe_ctx->plane_res.scl_data.viewport.height,
2772 pipe_ctx->plane_res.scl_data.viewport.x,
2773 pipe_ctx->plane_res.scl_data.viewport.y,
2774 pipe_ctx->plane_res.scl_data.recout.width,
2775 pipe_ctx->plane_res.scl_data.recout.height,
2776 pipe_ctx->plane_res.scl_data.recout.x,
2777 pipe_ctx->plane_res.scl_data.recout.y);
2778 }
2779
2780 static void dce110_apply_ctx_for_surface(
2781 struct dc *dc,
2782 const struct dc_stream_state *stream,
2783 int num_planes,
2784 struct dc_state *context)
2785 {
2786 int i;
2787
2788 if (num_planes == 0)
2789 return;
2790
2791 if (dc->fbc_compressor)
2792 dc->fbc_compressor->funcs->disable_fbc(dc->fbc_compressor);
2793
2794 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2795 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2796
2797 if (pipe_ctx->stream != stream)
2798 continue;
2799
2800
2801 pipe_ctx->plane_res.mi->funcs->allocate_mem_input(
2802 pipe_ctx->plane_res.mi,
2803 pipe_ctx->stream->timing.h_total,
2804 pipe_ctx->stream->timing.v_total,
2805 pipe_ctx->stream->timing.pix_clk_100hz / 10,
2806 context->stream_count);
2807
2808 dce110_program_front_end_for_pipe(dc, pipe_ctx);
2809
2810 dc->hwss.update_plane_addr(dc, pipe_ctx);
2811
2812 program_surface_visibility(dc, pipe_ctx);
2813
2814 }
2815
2816 if (dc->fbc_compressor)
2817 enable_fbc(dc, context);
2818 }
2819
2820 static void dce110_post_unlock_program_front_end(
2821 struct dc *dc,
2822 struct dc_state *context)
2823 {
2824 }
2825
2826 static void dce110_power_down_fe(struct dc *dc, struct pipe_ctx *pipe_ctx)
2827 {
2828 struct dce_hwseq *hws = dc->hwseq;
2829 int fe_idx = pipe_ctx->plane_res.mi ?
2830 pipe_ctx->plane_res.mi->inst : pipe_ctx->pipe_idx;
2831
2832
2833 if (dc->current_state->res_ctx.pipe_ctx[fe_idx].stream)
2834 return;
2835
2836 hws->funcs.enable_display_power_gating(
2837 dc, fe_idx, dc->ctx->dc_bios, PIPE_GATING_CONTROL_ENABLE);
2838
2839 dc->res_pool->transforms[fe_idx]->funcs->transform_reset(
2840 dc->res_pool->transforms[fe_idx]);
2841 }
2842
2843 static void dce110_wait_for_mpcc_disconnect(
2844 struct dc *dc,
2845 struct resource_pool *res_pool,
2846 struct pipe_ctx *pipe_ctx)
2847 {
2848
2849 }
2850
2851 static void program_output_csc(struct dc *dc,
2852 struct pipe_ctx *pipe_ctx,
2853 enum dc_color_space colorspace,
2854 uint16_t *matrix,
2855 int opp_id)
2856 {
2857 int i;
2858 struct out_csc_color_matrix tbl_entry;
2859
2860 if (pipe_ctx->stream->csc_color_matrix.enable_adjustment == true) {
2861 enum dc_color_space color_space = pipe_ctx->stream->output_color_space;
2862
2863 for (i = 0; i < 12; i++)
2864 tbl_entry.regval[i] = pipe_ctx->stream->csc_color_matrix.matrix[i];
2865
2866 tbl_entry.color_space = color_space;
2867
2868 pipe_ctx->plane_res.xfm->funcs->opp_set_csc_adjustment(
2869 pipe_ctx->plane_res.xfm, &tbl_entry);
2870 }
2871 }
2872
2873 static void dce110_set_cursor_position(struct pipe_ctx *pipe_ctx)
2874 {
2875 struct dc_cursor_position pos_cpy = pipe_ctx->stream->cursor_position;
2876 struct input_pixel_processor *ipp = pipe_ctx->plane_res.ipp;
2877 struct mem_input *mi = pipe_ctx->plane_res.mi;
2878 struct dc_cursor_mi_param param = {
2879 .pixel_clk_khz = pipe_ctx->stream->timing.pix_clk_100hz / 10,
2880 .ref_clk_khz = pipe_ctx->stream->ctx->dc->res_pool->ref_clocks.xtalin_clock_inKhz,
2881 .viewport = pipe_ctx->plane_res.scl_data.viewport,
2882 .h_scale_ratio = pipe_ctx->plane_res.scl_data.ratios.horz,
2883 .v_scale_ratio = pipe_ctx->plane_res.scl_data.ratios.vert,
2884 .rotation = pipe_ctx->plane_state->rotation,
2885 .mirror = pipe_ctx->plane_state->horizontal_mirror
2886 };
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900 if (pos_cpy.translate_by_source) {
2901 pos_cpy.x += pipe_ctx->plane_state->src_rect.x;
2902 pos_cpy.y += pipe_ctx->plane_state->src_rect.y;
2903 }
2904
2905 if (pipe_ctx->plane_state->address.type
2906 == PLN_ADDR_TYPE_VIDEO_PROGRESSIVE)
2907 pos_cpy.enable = false;
2908
2909 if (pipe_ctx->top_pipe && pipe_ctx->plane_state != pipe_ctx->top_pipe->plane_state)
2910 pos_cpy.enable = false;
2911
2912 if (ipp->funcs->ipp_cursor_set_position)
2913 ipp->funcs->ipp_cursor_set_position(ipp, &pos_cpy, ¶m);
2914 if (mi->funcs->set_cursor_position)
2915 mi->funcs->set_cursor_position(mi, &pos_cpy, ¶m);
2916 }
2917
2918 static void dce110_set_cursor_attribute(struct pipe_ctx *pipe_ctx)
2919 {
2920 struct dc_cursor_attributes *attributes = &pipe_ctx->stream->cursor_attributes;
2921
2922 if (pipe_ctx->plane_res.ipp &&
2923 pipe_ctx->plane_res.ipp->funcs->ipp_cursor_set_attributes)
2924 pipe_ctx->plane_res.ipp->funcs->ipp_cursor_set_attributes(
2925 pipe_ctx->plane_res.ipp, attributes);
2926
2927 if (pipe_ctx->plane_res.mi &&
2928 pipe_ctx->plane_res.mi->funcs->set_cursor_attributes)
2929 pipe_ctx->plane_res.mi->funcs->set_cursor_attributes(
2930 pipe_ctx->plane_res.mi, attributes);
2931
2932 if (pipe_ctx->plane_res.xfm &&
2933 pipe_ctx->plane_res.xfm->funcs->set_cursor_attributes)
2934 pipe_ctx->plane_res.xfm->funcs->set_cursor_attributes(
2935 pipe_ctx->plane_res.xfm, attributes);
2936 }
2937
2938 bool dce110_set_backlight_level(struct pipe_ctx *pipe_ctx,
2939 uint32_t backlight_pwm_u16_16,
2940 uint32_t frame_ramp)
2941 {
2942 struct dc_link *link = pipe_ctx->stream->link;
2943 struct dc *dc = link->ctx->dc;
2944 struct abm *abm = pipe_ctx->stream_res.abm;
2945 struct panel_cntl *panel_cntl = link->panel_cntl;
2946 struct dmcu *dmcu = dc->res_pool->dmcu;
2947 bool fw_set_brightness = true;
2948
2949
2950
2951 uint32_t controller_id = pipe_ctx->stream_res.tg->inst + 1;
2952
2953 if (abm == NULL || panel_cntl == NULL || (abm->funcs->set_backlight_level_pwm == NULL))
2954 return false;
2955
2956 if (dmcu)
2957 fw_set_brightness = dmcu->funcs->is_dmcu_initialized(dmcu);
2958
2959 if (!fw_set_brightness && panel_cntl->funcs->driver_set_backlight)
2960 panel_cntl->funcs->driver_set_backlight(panel_cntl, backlight_pwm_u16_16);
2961 else
2962 abm->funcs->set_backlight_level_pwm(
2963 abm,
2964 backlight_pwm_u16_16,
2965 frame_ramp,
2966 controller_id,
2967 link->panel_cntl->inst);
2968
2969 return true;
2970 }
2971
2972 void dce110_set_abm_immediate_disable(struct pipe_ctx *pipe_ctx)
2973 {
2974 struct abm *abm = pipe_ctx->stream_res.abm;
2975 struct panel_cntl *panel_cntl = pipe_ctx->stream->link->panel_cntl;
2976
2977 if (abm)
2978 abm->funcs->set_abm_immediate_disable(abm,
2979 pipe_ctx->stream->link->panel_cntl->inst);
2980
2981 if (panel_cntl)
2982 panel_cntl->funcs->store_backlight_level(panel_cntl);
2983 }
2984
2985 void dce110_set_pipe(struct pipe_ctx *pipe_ctx)
2986 {
2987 struct abm *abm = pipe_ctx->stream_res.abm;
2988 struct panel_cntl *panel_cntl = pipe_ctx->stream->link->panel_cntl;
2989 uint32_t otg_inst = pipe_ctx->stream_res.tg->inst + 1;
2990
2991 if (abm && panel_cntl)
2992 abm->funcs->set_pipe(abm, otg_inst, panel_cntl->inst);
2993 }
2994
2995 static const struct hw_sequencer_funcs dce110_funcs = {
2996 .program_gamut_remap = program_gamut_remap,
2997 .program_output_csc = program_output_csc,
2998 .init_hw = init_hw,
2999 .apply_ctx_to_hw = dce110_apply_ctx_to_hw,
3000 .apply_ctx_for_surface = dce110_apply_ctx_for_surface,
3001 .post_unlock_program_front_end = dce110_post_unlock_program_front_end,
3002 .update_plane_addr = update_plane_addr,
3003 .update_pending_status = dce110_update_pending_status,
3004 .enable_accelerated_mode = dce110_enable_accelerated_mode,
3005 .enable_timing_synchronization = dce110_enable_timing_synchronization,
3006 .enable_per_frame_crtc_position_reset = dce110_enable_per_frame_crtc_position_reset,
3007 .update_info_frame = dce110_update_info_frame,
3008 .enable_stream = dce110_enable_stream,
3009 .disable_stream = dce110_disable_stream,
3010 .unblank_stream = dce110_unblank_stream,
3011 .blank_stream = dce110_blank_stream,
3012 .enable_audio_stream = dce110_enable_audio_stream,
3013 .disable_audio_stream = dce110_disable_audio_stream,
3014 .disable_plane = dce110_power_down_fe,
3015 .pipe_control_lock = dce_pipe_control_lock,
3016 .interdependent_update_lock = NULL,
3017 .cursor_lock = dce_pipe_control_lock,
3018 .prepare_bandwidth = dce110_prepare_bandwidth,
3019 .optimize_bandwidth = dce110_optimize_bandwidth,
3020 .set_drr = set_drr,
3021 .get_position = get_position,
3022 .set_static_screen_control = set_static_screen_control,
3023 .setup_stereo = NULL,
3024 .set_avmute = dce110_set_avmute,
3025 .wait_for_mpcc_disconnect = dce110_wait_for_mpcc_disconnect,
3026 .edp_backlight_control = dce110_edp_backlight_control,
3027 .edp_power_control = dce110_edp_power_control,
3028 .edp_wait_for_hpd_ready = dce110_edp_wait_for_hpd_ready,
3029 .set_cursor_position = dce110_set_cursor_position,
3030 .set_cursor_attribute = dce110_set_cursor_attribute,
3031 .set_backlight_level = dce110_set_backlight_level,
3032 .set_abm_immediate_disable = dce110_set_abm_immediate_disable,
3033 .set_pipe = dce110_set_pipe,
3034 };
3035
3036 static const struct hwseq_private_funcs dce110_private_funcs = {
3037 .init_pipes = init_pipes,
3038 .update_plane_addr = update_plane_addr,
3039 .set_input_transfer_func = dce110_set_input_transfer_func,
3040 .set_output_transfer_func = dce110_set_output_transfer_func,
3041 .power_down = dce110_power_down,
3042 .enable_display_pipe_clock_gating = enable_display_pipe_clock_gating,
3043 .enable_display_power_gating = dce110_enable_display_power_gating,
3044 .reset_hw_ctx_wrap = dce110_reset_hw_ctx_wrap,
3045 .enable_stream_timing = dce110_enable_stream_timing,
3046 .disable_stream_gating = NULL,
3047 .enable_stream_gating = NULL,
3048 .edp_backlight_control = dce110_edp_backlight_control,
3049 };
3050
3051 void dce110_hw_sequencer_construct(struct dc *dc)
3052 {
3053 dc->hwss = dce110_funcs;
3054 dc->hwseq->funcs = dce110_private_funcs;
3055 }
3056