1 /*
2 * Copyright 2015 Advanced Micro Devices, Inc.
3 *
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:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
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.
21 *
22 * Authors: AMD
23 *
24 */
25
26 #include "dm_services.h"
27 #include "dc.h"
28 #include "dc_bios_types.h"
29 #include "core_types.h"
30 #include "core_status.h"
31 #include "resource.h"
32 #include "dm_helpers.h"
33 #include "dce110_hwseq.h"
34 #include "dce110/dce110_timing_generator.h"
35 #include "dce/dce_hwseq.h"
36 #include "dce100/dce100_hwseq.h"
37 #include "gpio_service_interface.h"
38
39 #include "dce110/dce110_compressor.h"
40
41 #include "bios/bios_parser_helper.h"
42 #include "timing_generator.h"
43 #include "mem_input.h"
44 #include "opp.h"
45 #include "ipp.h"
46 #include "transform.h"
47 #include "stream_encoder.h"
48 #include "link_encoder.h"
49 #include "link_enc_cfg.h"
50 #include "link_hwss.h"
51 #include "link_service.h"
52 #include "dccg.h"
53 #include "clock_source.h"
54 #include "clk_mgr.h"
55 #include "abm.h"
56 #include "audio.h"
57 #include "reg_helper.h"
58 #include "panel_cntl.h"
59 #include "dc_state_priv.h"
60 #include "dpcd_defs.h"
61 #include "dsc.h"
62 #include "dc_dp_types.h"
63 /* include DCE11 register header files */
64 #include "dce/dce_11_0_d.h"
65 #include "dce/dce_11_0_sh_mask.h"
66 #include "custom_float.h"
67
68 #include "atomfirmware.h"
69
70 #include "dcn10/dcn10_hwseq.h"
71
72 #define GAMMA_HW_POINTS_NUM 256
73
74 /*
75 * All values are in milliseconds;
76 * For eDP, after power-up/power/down,
77 * 300/500 msec max. delay from LCDVCC to black video generation
78 */
79 #define PANEL_POWER_UP_TIMEOUT 300
80 #define PANEL_POWER_DOWN_TIMEOUT 500
81 #define HPD_CHECK_INTERVAL 10
82 #define OLED_POST_T7_DELAY 100
83 #define OLED_PRE_T11_DELAY 150
84
85 #define CTX \
86 hws->ctx
87
88 #define DC_LOGGER \
89 dc_ctx->logger
90 #define DC_LOGGER_INIT(ctx) \
91 struct dc_context *dc_ctx = ctx
92
93 #define REG(reg)\
94 hws->regs->reg
95
96 #undef FN
97 #define FN(reg_name, field_name) \
98 hws->shifts->field_name, hws->masks->field_name
99
100 struct dce110_hw_seq_reg_offsets {
101 uint32_t crtc;
102 };
103
104 static const struct dce110_hw_seq_reg_offsets reg_offsets[] = {
105 {
106 .crtc = (mmCRTC0_CRTC_GSL_CONTROL - mmCRTC_GSL_CONTROL),
107 },
108 {
109 .crtc = (mmCRTC1_CRTC_GSL_CONTROL - mmCRTC_GSL_CONTROL),
110 },
111 {
112 .crtc = (mmCRTC2_CRTC_GSL_CONTROL - mmCRTC_GSL_CONTROL),
113 },
114 {
115 .crtc = (mmCRTCV_GSL_CONTROL - mmCRTC_GSL_CONTROL),
116 }
117 };
118
119 #define HW_REG_BLND(reg, id)\
120 (reg + reg_offsets[id].blnd)
121
122 #define HW_REG_CRTC(reg, id)\
123 (reg + reg_offsets[id].crtc)
124
125 #define MAX_WATERMARK 0xFFFF
126 #define SAFE_NBP_MARK 0x7FFF
127
128 /*******************************************************************************
129 * Private definitions
130 ******************************************************************************/
131 /***************************PIPE_CONTROL***********************************/
dce110_init_pte(struct dc_context * ctx)132 static void dce110_init_pte(struct dc_context *ctx)
133 {
134 uint32_t addr;
135 uint32_t value = 0;
136 uint32_t chunk_int = 0;
137 uint32_t chunk_mul = 0;
138
139 addr = mmUNP_DVMM_PTE_CONTROL;
140 value = dm_read_reg(ctx, addr);
141
142 set_reg_field_value(
143 value,
144 0,
145 DVMM_PTE_CONTROL,
146 DVMM_USE_SINGLE_PTE);
147
148 set_reg_field_value(
149 value,
150 1,
151 DVMM_PTE_CONTROL,
152 DVMM_PTE_BUFFER_MODE0);
153
154 set_reg_field_value(
155 value,
156 1,
157 DVMM_PTE_CONTROL,
158 DVMM_PTE_BUFFER_MODE1);
159
160 dm_write_reg(ctx, addr, value);
161
162 addr = mmDVMM_PTE_REQ;
163 value = dm_read_reg(ctx, addr);
164
165 chunk_int = get_reg_field_value(
166 value,
167 DVMM_PTE_REQ,
168 HFLIP_PTEREQ_PER_CHUNK_INT);
169
170 chunk_mul = get_reg_field_value(
171 value,
172 DVMM_PTE_REQ,
173 HFLIP_PTEREQ_PER_CHUNK_MULTIPLIER);
174
175 if (chunk_int != 0x4 || chunk_mul != 0x4) {
176
177 set_reg_field_value(
178 value,
179 255,
180 DVMM_PTE_REQ,
181 MAX_PTEREQ_TO_ISSUE);
182
183 set_reg_field_value(
184 value,
185 4,
186 DVMM_PTE_REQ,
187 HFLIP_PTEREQ_PER_CHUNK_INT);
188
189 set_reg_field_value(
190 value,
191 4,
192 DVMM_PTE_REQ,
193 HFLIP_PTEREQ_PER_CHUNK_MULTIPLIER);
194
195 dm_write_reg(ctx, addr, value);
196 }
197 }
198 /**************************************************************************/
199
enable_display_pipe_clock_gating(struct dc_context * ctx,bool clock_gating)200 static void enable_display_pipe_clock_gating(
201 struct dc_context *ctx,
202 bool clock_gating)
203 {
204 (void)ctx;
205 (void)clock_gating;
206 /*TODO*/
207 }
208
dce110_enable_display_power_gating(struct dc * dc,uint8_t controller_id,struct dc_bios * dcb,enum pipe_gating_control power_gating)209 static bool dce110_enable_display_power_gating(
210 struct dc *dc,
211 uint8_t controller_id,
212 struct dc_bios *dcb,
213 enum pipe_gating_control power_gating)
214 {
215 enum bp_result bp_result = BP_RESULT_OK;
216 enum bp_pipe_control_action cntl;
217 struct dc_context *ctx = dc->ctx;
218 unsigned int underlay_idx = dc->res_pool->underlay_pipe_index;
219
220 if (power_gating == PIPE_GATING_CONTROL_INIT)
221 cntl = ASIC_PIPE_INIT;
222 else if (power_gating == PIPE_GATING_CONTROL_ENABLE)
223 cntl = ASIC_PIPE_ENABLE;
224 else
225 cntl = ASIC_PIPE_DISABLE;
226
227 if (controller_id == underlay_idx)
228 controller_id = CONTROLLER_ID_UNDERLAY0 - 1;
229
230 if (power_gating != PIPE_GATING_CONTROL_INIT || controller_id == 0) {
231
232 bp_result = dcb->funcs->enable_disp_power_gating(
233 dcb, controller_id + 1, cntl);
234
235 /* Revert MASTER_UPDATE_MODE to 0 because bios sets it 2
236 * by default when command table is called
237 *
238 * Bios parser accepts controller_id = 6 as indicative of
239 * underlay pipe in dce110. But we do not support more
240 * than 3.
241 */
242 if (controller_id < CONTROLLER_ID_MAX - 1)
243 dm_write_reg(ctx,
244 HW_REG_CRTC(mmCRTC_MASTER_UPDATE_MODE, controller_id),
245 0);
246 }
247
248 if (power_gating != PIPE_GATING_CONTROL_ENABLE)
249 dce110_init_pte(ctx);
250
251 if (bp_result == BP_RESULT_OK)
252 return true;
253 else
254 return false;
255 }
256
dce110_prescale_params(struct ipp_prescale_params * prescale_params,const struct dc_plane_state * plane_state)257 static void dce110_prescale_params(struct ipp_prescale_params *prescale_params,
258 const struct dc_plane_state *plane_state)
259 {
260 prescale_params->mode = IPP_PRESCALE_MODE_FIXED_UNSIGNED;
261
262 switch (plane_state->format) {
263 case SURFACE_PIXEL_FORMAT_GRPH_RGB565:
264 prescale_params->scale = 0x2082;
265 break;
266 case SURFACE_PIXEL_FORMAT_GRPH_ARGB8888:
267 case SURFACE_PIXEL_FORMAT_GRPH_ABGR8888:
268 prescale_params->scale = 0x2020;
269 break;
270 case SURFACE_PIXEL_FORMAT_GRPH_ARGB2101010:
271 case SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010:
272 prescale_params->scale = 0x2008;
273 break;
274 case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616:
275 case SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616:
276 case SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616F:
277 prescale_params->scale = 0x2000;
278 break;
279 default:
280 ASSERT(false);
281 break;
282 }
283 }
284
285 static bool
dce110_set_input_transfer_func(struct dc * dc,struct pipe_ctx * pipe_ctx,const struct dc_plane_state * plane_state)286 dce110_set_input_transfer_func(struct dc *dc, struct pipe_ctx *pipe_ctx,
287 const struct dc_plane_state *plane_state)
288 {
289 (void)dc;
290 struct input_pixel_processor *ipp = pipe_ctx->plane_res.ipp;
291 const struct dc_transfer_func *tf = NULL;
292 struct ipp_prescale_params prescale_params = { 0 };
293 bool result = true;
294
295 if (ipp == NULL)
296 return false;
297
298 tf = &plane_state->in_transfer_func;
299
300 dce110_prescale_params(&prescale_params, plane_state);
301 ipp->funcs->ipp_program_prescale(ipp, &prescale_params);
302
303 if (!plane_state->gamma_correction.is_identity &&
304 dce_use_lut(plane_state->format))
305 ipp->funcs->ipp_program_input_lut(ipp, &plane_state->gamma_correction);
306
307 if (tf->type == TF_TYPE_PREDEFINED) {
308 switch (tf->tf) {
309 case TRANSFER_FUNCTION_SRGB:
310 ipp->funcs->ipp_set_degamma(ipp, IPP_DEGAMMA_MODE_HW_sRGB);
311 break;
312 case TRANSFER_FUNCTION_BT709:
313 ipp->funcs->ipp_set_degamma(ipp, IPP_DEGAMMA_MODE_HW_xvYCC);
314 break;
315 case TRANSFER_FUNCTION_LINEAR:
316 ipp->funcs->ipp_set_degamma(ipp, IPP_DEGAMMA_MODE_BYPASS);
317 break;
318 case TRANSFER_FUNCTION_PQ:
319 default:
320 result = false;
321 break;
322 }
323 } else if (tf->type == TF_TYPE_BYPASS) {
324 ipp->funcs->ipp_set_degamma(ipp, IPP_DEGAMMA_MODE_BYPASS);
325 } else {
326 /*TF_TYPE_DISTRIBUTED_POINTS - Not supported in DCE 11*/
327 result = false;
328 }
329
330 return result;
331 }
332
convert_to_custom_float(struct pwl_result_data * rgb_resulted,struct curve_points * arr_points,uint32_t hw_points_num)333 static bool convert_to_custom_float(struct pwl_result_data *rgb_resulted,
334 struct curve_points *arr_points,
335 uint32_t hw_points_num)
336 {
337 struct custom_float_format fmt;
338
339 struct pwl_result_data *rgb = rgb_resulted;
340
341 uint32_t i = 0;
342
343 fmt.exponenta_bits = 6;
344 fmt.mantissa_bits = 12;
345 fmt.sign = true;
346
347 if (!convert_to_custom_float_format(arr_points[0].x, &fmt,
348 &arr_points[0].custom_float_x)) {
349 BREAK_TO_DEBUGGER();
350 return false;
351 }
352
353 if (!convert_to_custom_float_format(arr_points[0].offset, &fmt,
354 &arr_points[0].custom_float_offset)) {
355 BREAK_TO_DEBUGGER();
356 return false;
357 }
358
359 if (!convert_to_custom_float_format(arr_points[0].slope, &fmt,
360 &arr_points[0].custom_float_slope)) {
361 BREAK_TO_DEBUGGER();
362 return false;
363 }
364
365 fmt.mantissa_bits = 10;
366 fmt.sign = false;
367
368 if (!convert_to_custom_float_format(arr_points[1].x, &fmt,
369 &arr_points[1].custom_float_x)) {
370 BREAK_TO_DEBUGGER();
371 return false;
372 }
373
374 if (!convert_to_custom_float_format(arr_points[1].y, &fmt,
375 &arr_points[1].custom_float_y)) {
376 BREAK_TO_DEBUGGER();
377 return false;
378 }
379
380 if (!convert_to_custom_float_format(arr_points[1].slope, &fmt,
381 &arr_points[1].custom_float_slope)) {
382 BREAK_TO_DEBUGGER();
383 return false;
384 }
385
386 fmt.mantissa_bits = 12;
387 fmt.sign = true;
388
389 while (i != hw_points_num) {
390 if (!convert_to_custom_float_format(rgb->red, &fmt,
391 &rgb->red_reg)) {
392 BREAK_TO_DEBUGGER();
393 return false;
394 }
395
396 if (!convert_to_custom_float_format(rgb->green, &fmt,
397 &rgb->green_reg)) {
398 BREAK_TO_DEBUGGER();
399 return false;
400 }
401
402 if (!convert_to_custom_float_format(rgb->blue, &fmt,
403 &rgb->blue_reg)) {
404 BREAK_TO_DEBUGGER();
405 return false;
406 }
407
408 if (!convert_to_custom_float_format(rgb->delta_red, &fmt,
409 &rgb->delta_red_reg)) {
410 BREAK_TO_DEBUGGER();
411 return false;
412 }
413
414 if (!convert_to_custom_float_format(rgb->delta_green, &fmt,
415 &rgb->delta_green_reg)) {
416 BREAK_TO_DEBUGGER();
417 return false;
418 }
419
420 if (!convert_to_custom_float_format(rgb->delta_blue, &fmt,
421 &rgb->delta_blue_reg)) {
422 BREAK_TO_DEBUGGER();
423 return false;
424 }
425
426 ++rgb;
427 ++i;
428 }
429
430 return true;
431 }
432
433 #define MAX_LOW_POINT 25
434 #define NUMBER_REGIONS 16
435 #define NUMBER_SW_SEGMENTS 16
436
437 static bool
dce110_translate_regamma_to_hw_format(const struct dc_transfer_func * output_tf,struct pwl_params * regamma_params)438 dce110_translate_regamma_to_hw_format(const struct dc_transfer_func *output_tf,
439 struct pwl_params *regamma_params)
440 {
441 struct curve_points *arr_points;
442 struct pwl_result_data *rgb_resulted;
443 struct pwl_result_data *rgb;
444 struct pwl_result_data *rgb_plus_1;
445 struct fixed31_32 y_r;
446 struct fixed31_32 y_g;
447 struct fixed31_32 y_b;
448 struct fixed31_32 y1_min;
449 struct fixed31_32 y3_max;
450
451 int32_t region_start, region_end;
452 uint32_t i, j, k, seg_distr[NUMBER_REGIONS], increment, start_index, hw_points;
453
454 if (output_tf == NULL || regamma_params == NULL || output_tf->type == TF_TYPE_BYPASS)
455 return false;
456
457 arr_points = regamma_params->arr_points;
458 rgb_resulted = regamma_params->rgb_resulted;
459 hw_points = 0;
460
461 memset(regamma_params, 0, sizeof(struct pwl_params));
462
463 if (output_tf->tf == TRANSFER_FUNCTION_PQ) {
464 /* 16 segments
465 * segments are from 2^-11 to 2^5
466 */
467 region_start = -11;
468 region_end = region_start + NUMBER_REGIONS;
469
470 for (i = 0; i < NUMBER_REGIONS; i++)
471 seg_distr[i] = 4;
472
473 } else {
474 /* 10 segments
475 * segment is from 2^-10 to 2^1
476 * We include an extra segment for range [2^0, 2^1). This is to
477 * ensure that colors with normalized values of 1 don't miss the
478 * LUT.
479 */
480 region_start = -10;
481 region_end = 1;
482
483 seg_distr[0] = 4;
484 seg_distr[1] = 4;
485 seg_distr[2] = 4;
486 seg_distr[3] = 4;
487 seg_distr[4] = 4;
488 seg_distr[5] = 4;
489 seg_distr[6] = 4;
490 seg_distr[7] = 4;
491 seg_distr[8] = 4;
492 seg_distr[9] = 4;
493 seg_distr[10] = 0;
494 seg_distr[11] = (uint32_t)-1;
495 seg_distr[12] = (uint32_t)-1;
496 seg_distr[13] = (uint32_t)-1;
497 seg_distr[14] = (uint32_t)-1;
498 seg_distr[15] = (uint32_t)-1;
499 }
500
501 for (k = 0; k < 16; k++) {
502 if (seg_distr[k] != (uint32_t)-1)
503 hw_points += (1 << seg_distr[k]);
504 }
505
506 j = 0;
507 for (k = 0; k < (region_end - region_start); k++) {
508 increment = NUMBER_SW_SEGMENTS / (1 << seg_distr[k]);
509 start_index = (region_start + k + MAX_LOW_POINT) *
510 NUMBER_SW_SEGMENTS;
511 for (i = start_index; i < start_index + NUMBER_SW_SEGMENTS;
512 i += increment) {
513 if (j == hw_points - 1)
514 break;
515 rgb_resulted[j].red = output_tf->tf_pts.red[i];
516 rgb_resulted[j].green = output_tf->tf_pts.green[i];
517 rgb_resulted[j].blue = output_tf->tf_pts.blue[i];
518 j++;
519 }
520 }
521
522 /* last point */
523 start_index = (region_end + MAX_LOW_POINT) * NUMBER_SW_SEGMENTS;
524 rgb_resulted[hw_points - 1].red = output_tf->tf_pts.red[start_index];
525 rgb_resulted[hw_points - 1].green = output_tf->tf_pts.green[start_index];
526 rgb_resulted[hw_points - 1].blue = output_tf->tf_pts.blue[start_index];
527
528 arr_points[0].x = dc_fixpt_pow(dc_fixpt_from_int(2),
529 dc_fixpt_from_int(region_start));
530 arr_points[1].x = dc_fixpt_pow(dc_fixpt_from_int(2),
531 dc_fixpt_from_int(region_end));
532
533 y_r = rgb_resulted[0].red;
534 y_g = rgb_resulted[0].green;
535 y_b = rgb_resulted[0].blue;
536
537 y1_min = dc_fixpt_min(y_r, dc_fixpt_min(y_g, y_b));
538
539 arr_points[0].y = y1_min;
540 arr_points[0].slope = dc_fixpt_div(arr_points[0].y,
541 arr_points[0].x);
542
543 y_r = rgb_resulted[hw_points - 1].red;
544 y_g = rgb_resulted[hw_points - 1].green;
545 y_b = rgb_resulted[hw_points - 1].blue;
546
547 /* see comment above, m_arrPoints[1].y should be the Y value for the
548 * region end (m_numOfHwPoints), not last HW point(m_numOfHwPoints - 1)
549 */
550 y3_max = dc_fixpt_max(y_r, dc_fixpt_max(y_g, y_b));
551
552 arr_points[1].y = y3_max;
553
554 arr_points[1].slope = dc_fixpt_zero;
555
556 if (output_tf->tf == TRANSFER_FUNCTION_PQ) {
557 /* for PQ, we want to have a straight line from last HW X point,
558 * and the slope to be such that we hit 1.0 at 10000 nits.
559 */
560 const struct fixed31_32 end_value = dc_fixpt_from_int(125);
561
562 arr_points[1].slope = dc_fixpt_div(
563 dc_fixpt_sub(dc_fixpt_one, arr_points[1].y),
564 dc_fixpt_sub(end_value, arr_points[1].x));
565 }
566
567 regamma_params->hw_points_num = hw_points;
568
569 k = 0;
570 for (i = 1; i < 16; i++) {
571 if (seg_distr[k] != -1) {
572 regamma_params->arr_curve_points[k].segments_num = seg_distr[k];
573 regamma_params->arr_curve_points[i].offset =
574 regamma_params->arr_curve_points[k].offset + (1 << seg_distr[k]);
575 }
576 k++;
577 }
578
579 if (seg_distr[k] != -1)
580 regamma_params->arr_curve_points[k].segments_num = seg_distr[k];
581
582 rgb = rgb_resulted;
583 rgb_plus_1 = rgb_resulted + 1;
584
585 i = 1;
586
587 while (i != hw_points + 1) {
588 if (dc_fixpt_lt(rgb_plus_1->red, rgb->red))
589 rgb_plus_1->red = rgb->red;
590 if (dc_fixpt_lt(rgb_plus_1->green, rgb->green))
591 rgb_plus_1->green = rgb->green;
592 if (dc_fixpt_lt(rgb_plus_1->blue, rgb->blue))
593 rgb_plus_1->blue = rgb->blue;
594
595 rgb->delta_red = dc_fixpt_sub(rgb_plus_1->red, rgb->red);
596 rgb->delta_green = dc_fixpt_sub(rgb_plus_1->green, rgb->green);
597 rgb->delta_blue = dc_fixpt_sub(rgb_plus_1->blue, rgb->blue);
598
599 ++rgb_plus_1;
600 ++rgb;
601 ++i;
602 }
603
604 convert_to_custom_float(rgb_resulted, arr_points, hw_points);
605
606 return true;
607 }
608
609 static bool
dce110_set_output_transfer_func(struct dc * dc,struct pipe_ctx * pipe_ctx,const struct dc_stream_state * stream)610 dce110_set_output_transfer_func(struct dc *dc, struct pipe_ctx *pipe_ctx,
611 const struct dc_stream_state *stream)
612 {
613 (void)dc;
614 struct transform *xfm = pipe_ctx->plane_res.xfm;
615
616 xfm->funcs->opp_power_on_regamma_lut(xfm, true);
617 xfm->regamma_params.hw_points_num = GAMMA_HW_POINTS_NUM;
618
619 if (stream->out_transfer_func.type == TF_TYPE_PREDEFINED &&
620 stream->out_transfer_func.tf == TRANSFER_FUNCTION_SRGB) {
621 xfm->funcs->opp_set_regamma_mode(xfm, OPP_REGAMMA_SRGB);
622 } else if (dce110_translate_regamma_to_hw_format(&stream->out_transfer_func,
623 &xfm->regamma_params)) {
624 xfm->funcs->opp_program_regamma_pwl(xfm, &xfm->regamma_params);
625 xfm->funcs->opp_set_regamma_mode(xfm, OPP_REGAMMA_USER);
626 } else {
627 xfm->funcs->opp_set_regamma_mode(xfm, OPP_REGAMMA_BYPASS);
628 }
629
630 xfm->funcs->opp_power_on_regamma_lut(xfm, false);
631
632 return true;
633 }
634
dce110_update_info_frame(struct pipe_ctx * pipe_ctx)635 void dce110_update_info_frame(struct pipe_ctx *pipe_ctx)
636 {
637 bool is_hdmi_tmds;
638 bool is_dp;
639
640 ASSERT(pipe_ctx->stream);
641
642 if (pipe_ctx->stream_res.stream_enc == NULL)
643 return; /* this is not root pipe */
644
645 is_hdmi_tmds = dc_is_hdmi_tmds_signal(pipe_ctx->stream->signal);
646 is_dp = dc_is_dp_signal(pipe_ctx->stream->signal);
647
648 if (!is_hdmi_tmds && !is_dp)
649 return;
650
651 if (is_hdmi_tmds)
652 pipe_ctx->stream_res.stream_enc->funcs->update_hdmi_info_packets(
653 pipe_ctx->stream_res.stream_enc,
654 &pipe_ctx->stream_res.encoder_info_frame);
655 else {
656 if (pipe_ctx->stream_res.stream_enc->funcs->update_dp_info_packets_sdp_line_num)
657 pipe_ctx->stream_res.stream_enc->funcs->update_dp_info_packets_sdp_line_num(
658 pipe_ctx->stream_res.stream_enc,
659 &pipe_ctx->stream_res.encoder_info_frame);
660
661 pipe_ctx->stream_res.stream_enc->funcs->update_dp_info_packets(
662 pipe_ctx->stream_res.stream_enc,
663 &pipe_ctx->stream_res.encoder_info_frame);
664 }
665 }
666
667 static void
dce110_external_encoder_control(enum bp_external_encoder_control_action action,struct dc_link * link,struct dc_crtc_timing * timing)668 dce110_external_encoder_control(enum bp_external_encoder_control_action action,
669 struct dc_link *link,
670 struct dc_crtc_timing *timing)
671 {
672 struct dc *dc = link->ctx->dc;
673 struct dc_bios *bios = link->ctx->dc_bios;
674 const struct dc_link_settings *link_settings = &link->cur_link_settings;
675 enum bp_result bp_result = BP_RESULT_OK;
676 struct bp_external_encoder_control ext_cntl = {
677 .action = action,
678 .connector_obj_id = link->link_enc->connector,
679 .encoder_id = link->ext_enc_id,
680 .lanes_number = link_settings->lane_count,
681 .link_rate = link_settings->link_rate,
682
683 /* Use signal type of the real link encoder, ie. DP */
684 .signal = link->connector_signal,
685
686 /* We don't know the timing yet when executing the SETUP action,
687 * so use a reasonably high default value. It seems that ENABLE
688 * can change the actual pixel clock but doesn't work with higher
689 * pixel clocks than what SETUP was called with.
690 */
691 .pixel_clock = timing ? timing->pix_clk_100hz / 10 : 300000,
692 .color_depth = timing ? timing->display_color_depth : COLOR_DEPTH_888,
693 };
694 DC_LOGGER_INIT(dc->ctx);
695
696 bp_result = bios->funcs->external_encoder_control(bios, &ext_cntl);
697
698 if (bp_result != BP_RESULT_OK)
699 DC_LOG_ERROR("Failed to execute external encoder action: 0x%x\n", action);
700 }
701
702 static void
dce110_prepare_ddc(struct dc_link * link)703 dce110_prepare_ddc(struct dc_link *link)
704 {
705 if (link->ext_enc_id.id)
706 dce110_external_encoder_control(EXTERNAL_ENCODER_CONTROL_DDC_SETUP, link, NULL);
707 }
708
709 static bool
dce110_dac_load_detect(struct dc_link * link)710 dce110_dac_load_detect(struct dc_link *link)
711 {
712 struct dc_bios *bios = link->ctx->dc_bios;
713 struct link_encoder *link_enc = link->link_enc;
714 enum bp_result bp_result;
715
716 bp_result = bios->funcs->dac_load_detection(
717 bios, link_enc->analog_engine, link->ext_enc_id);
718 return bp_result == BP_RESULT_OK;
719 }
720
dce110_enable_stream(struct pipe_ctx * pipe_ctx)721 void dce110_enable_stream(struct pipe_ctx *pipe_ctx)
722 {
723 enum dc_lane_count lane_count =
724 pipe_ctx->stream->link->cur_link_settings.lane_count;
725 struct dc_crtc_timing *timing = &pipe_ctx->stream->timing;
726 struct dc_link *link = pipe_ctx->stream->link;
727 const struct dc *dc = link->dc;
728 const struct link_hwss *link_hwss = get_link_hwss(link, &pipe_ctx->link_res);
729 uint32_t active_total_with_borders;
730 uint32_t early_control = 0;
731 struct timing_generator *tg = pipe_ctx->stream_res.tg;
732
733 link_hwss->setup_stream_encoder(pipe_ctx);
734
735 dc->hwss.update_info_frame(pipe_ctx);
736
737 /* enable early control to avoid corruption on DP monitor*/
738 active_total_with_borders =
739 timing->h_addressable
740 + timing->h_border_left
741 + timing->h_border_right;
742
743 if (lane_count != 0)
744 early_control = active_total_with_borders % lane_count;
745
746 if (early_control == 0)
747 early_control = lane_count;
748
749 tg->funcs->set_early_control(tg, early_control);
750
751 if (link->ext_enc_id.id)
752 dce110_external_encoder_control(EXTERNAL_ENCODER_CONTROL_ENABLE, link, timing);
753 }
754
link_transmitter_control(struct dc_bios * bios,struct bp_transmitter_control * cntl)755 static enum bp_result link_transmitter_control(
756 struct dc_bios *bios,
757 struct bp_transmitter_control *cntl)
758 {
759 enum bp_result result;
760
761 result = bios->funcs->transmitter_control(bios, cntl);
762
763 return result;
764 }
765
766 /*
767 * @brief
768 * eDP only.
769 */
dce110_edp_wait_for_hpd_ready(struct dc_link * link,bool power_up)770 void dce110_edp_wait_for_hpd_ready(
771 struct dc_link *link,
772 bool power_up)
773 {
774 struct graphics_object_id connector = link->link_enc->connector;
775 bool edp_hpd_high = false;
776 uint32_t time_elapsed = 0;
777 uint32_t timeout = power_up ?
778 PANEL_POWER_UP_TIMEOUT : PANEL_POWER_DOWN_TIMEOUT;
779
780 DC_LOGGER_INIT(link->ctx);
781
782 if (dal_graphics_object_id_get_connector_id(connector)
783 != CONNECTOR_ID_EDP) {
784 BREAK_TO_DEBUGGER();
785 return;
786 }
787
788 if (!power_up)
789 /*
790 * From KV, we will not HPD low after turning off VCC -
791 * instead, we will check the SW timer in power_up().
792 */
793 return;
794
795 /*
796 * When we power on/off the eDP panel,
797 * we need to wait until SENSE bit is high/low.
798 */
799
800 if (link->panel_config.pps.extra_t3_ms > 0) {
801 int extra_t3_in_ms = link->panel_config.pps.extra_t3_ms;
802
803 msleep(extra_t3_in_ms);
804 }
805
806 /* wait until timeout or panel detected */
807
808 do {
809 if (!(link->dc->link_srv->get_hpd_state(link) ^ power_up)) {
810 edp_hpd_high = true;
811 break;
812 }
813
814 msleep(HPD_CHECK_INTERVAL);
815
816 time_elapsed += HPD_CHECK_INTERVAL;
817 } while (time_elapsed < timeout);
818
819 /* ensure that the panel is detected */
820 if (!edp_hpd_high)
821 DC_LOG_DC("%s: wait timed out!\n", __func__);
822 }
823
dce110_edp_power_control(struct dc_link * link,bool power_up)824 void dce110_edp_power_control(
825 struct dc_link *link,
826 bool power_up)
827 {
828 struct dc_context *ctx = link->ctx;
829 struct bp_transmitter_control cntl = { 0 };
830 enum bp_result bp_result;
831 uint8_t pwrseq_instance;
832
833 DC_LOGGER_INIT(ctx);
834
835 if (dal_graphics_object_id_get_connector_id(link->link_enc->connector)
836 != CONNECTOR_ID_EDP) {
837 BREAK_TO_DEBUGGER();
838 return;
839 }
840
841 if (!link->panel_cntl)
842 return;
843 if (power_up !=
844 link->panel_cntl->funcs->is_panel_powered_on(link->panel_cntl)) {
845
846 unsigned long long current_ts = dm_get_timestamp(ctx);
847 unsigned long long time_since_edp_poweroff_ms =
848 div64_u64(dm_get_elapse_time_in_ns(
849 ctx,
850 current_ts,
851 ctx->dc->link_srv->dp_trace_get_edp_poweroff_timestamp(link)), 1000000);
852 unsigned long long time_since_edp_poweron_ms =
853 div64_u64(dm_get_elapse_time_in_ns(
854 ctx,
855 current_ts,
856 ctx->dc->link_srv->dp_trace_get_edp_poweron_timestamp(link)), 1000000);
857 DC_LOG_HW_RESUME_S3(
858 "%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",
859 __func__,
860 power_up,
861 current_ts,
862 ctx->dc->link_srv->dp_trace_get_edp_poweroff_timestamp(link),
863 ctx->dc->link_srv->dp_trace_get_edp_poweron_timestamp(link),
864 time_since_edp_poweroff_ms,
865 time_since_edp_poweron_ms);
866
867 /* Send VBIOS command to prompt eDP panel power */
868 if (power_up) {
869 /* edp requires a min of 500ms from LCDVDD off to on */
870 unsigned long long remaining_min_edp_poweroff_time_ms = 500;
871
872 /* add time defined by a patch, if any (usually patch extra_t12_ms is 0) */
873 if (link->local_sink != NULL)
874 remaining_min_edp_poweroff_time_ms +=
875 link->panel_config.pps.extra_t12_ms;
876
877 /* Adjust remaining_min_edp_poweroff_time_ms if this is not the first time. */
878 if (ctx->dc->link_srv->dp_trace_get_edp_poweroff_timestamp(link) != 0) {
879 if (time_since_edp_poweroff_ms < remaining_min_edp_poweroff_time_ms)
880 remaining_min_edp_poweroff_time_ms =
881 remaining_min_edp_poweroff_time_ms - time_since_edp_poweroff_ms;
882 else
883 remaining_min_edp_poweroff_time_ms = 0;
884 }
885
886 if (remaining_min_edp_poweroff_time_ms) {
887 DC_LOG_HW_RESUME_S3(
888 "%s: remaining_min_edp_poweroff_time_ms=%llu: begin wait.\n",
889 __func__, remaining_min_edp_poweroff_time_ms);
890 msleep(remaining_min_edp_poweroff_time_ms);
891 DC_LOG_HW_RESUME_S3(
892 "%s: remaining_min_edp_poweroff_time_ms=%llu: end wait.\n",
893 __func__, remaining_min_edp_poweroff_time_ms);
894 dm_output_to_console("%s: wait %lld ms to power on eDP.\n",
895 __func__, remaining_min_edp_poweroff_time_ms);
896 } else {
897 DC_LOG_HW_RESUME_S3(
898 "%s: remaining_min_edp_poweroff_time_ms=%llu: no wait required.\n",
899 __func__, remaining_min_edp_poweroff_time_ms);
900 }
901 }
902
903 DC_LOG_HW_RESUME_S3(
904 "%s: BEGIN: Panel Power action: %s\n",
905 __func__, (power_up ? "On":"Off"));
906
907 cntl.action = power_up ?
908 TRANSMITTER_CONTROL_POWER_ON :
909 TRANSMITTER_CONTROL_POWER_OFF;
910 cntl.transmitter = link->link_enc->transmitter;
911 cntl.connector_obj_id = link->link_enc->connector;
912 cntl.coherent = false;
913 cntl.lanes_number = LANE_COUNT_FOUR;
914 cntl.hpd_sel = link->link_enc->hpd_source;
915 pwrseq_instance = link->panel_cntl->pwrseq_inst;
916
917 if (ctx->dc->ctx->dmub_srv &&
918 ctx->dc->debug.dmub_command_table) {
919
920 if (cntl.action == TRANSMITTER_CONTROL_POWER_ON) {
921 bp_result = ctx->dc_bios->funcs->enable_lvtma_control(ctx->dc_bios,
922 LVTMA_CONTROL_POWER_ON,
923 pwrseq_instance, link->link_powered_externally);
924 } else {
925 bp_result = ctx->dc_bios->funcs->enable_lvtma_control(ctx->dc_bios,
926 LVTMA_CONTROL_POWER_OFF,
927 pwrseq_instance, link->link_powered_externally);
928 }
929 }
930
931 bp_result = link_transmitter_control(ctx->dc_bios, &cntl);
932
933 DC_LOG_HW_RESUME_S3(
934 "%s: END: Panel Power action: %s bp_result=%u\n",
935 __func__, (power_up ? "On":"Off"),
936 bp_result);
937
938 ctx->dc->link_srv->dp_trace_set_edp_power_timestamp(link, power_up);
939
940 DC_LOG_HW_RESUME_S3(
941 "%s: updated values: edp_poweroff=%llu edp_poweron=%llu\n",
942 __func__,
943 ctx->dc->link_srv->dp_trace_get_edp_poweroff_timestamp(link),
944 ctx->dc->link_srv->dp_trace_get_edp_poweron_timestamp(link));
945
946 if (bp_result != BP_RESULT_OK)
947 DC_LOG_ERROR(
948 "%s: Panel Power bp_result: %d\n",
949 __func__, bp_result);
950 } else {
951 DC_LOG_HW_RESUME_S3(
952 "%s: Skipping Panel Power action: %s\n",
953 __func__, (power_up ? "On":"Off"));
954 }
955 }
956
dce110_edp_wait_for_T12(struct dc_link * link)957 void dce110_edp_wait_for_T12(
958 struct dc_link *link)
959 {
960 struct dc_context *ctx = link->ctx;
961
962 if (dal_graphics_object_id_get_connector_id(link->link_enc->connector)
963 != CONNECTOR_ID_EDP) {
964 BREAK_TO_DEBUGGER();
965 return;
966 }
967
968 if (!link->panel_cntl)
969 return;
970
971 if (!link->panel_cntl->funcs->is_panel_powered_on(link->panel_cntl) &&
972 ctx->dc->link_srv->dp_trace_get_edp_poweroff_timestamp(link) != 0) {
973 unsigned int t12_duration = 500; // Default T12 as per spec
974 unsigned long long current_ts = dm_get_timestamp(ctx);
975 unsigned long long time_since_edp_poweroff_ms =
976 div64_u64(dm_get_elapse_time_in_ns(
977 ctx,
978 current_ts,
979 ctx->dc->link_srv->dp_trace_get_edp_poweroff_timestamp(link)), 1000000);
980
981 t12_duration += link->panel_config.pps.extra_t12_ms; // Add extra T12
982
983 if (time_since_edp_poweroff_ms < t12_duration)
984 msleep(t12_duration - time_since_edp_poweroff_ms);
985 }
986 }
987 /*todo: cloned in stream enc, fix*/
988 /*
989 * @brief
990 * eDP only. Control the backlight of the eDP panel
991 */
dce110_edp_backlight_control(struct dc_link * link,bool enable)992 void dce110_edp_backlight_control(
993 struct dc_link *link,
994 bool enable)
995 {
996 struct dc_context *ctx = link->ctx;
997 struct bp_transmitter_control cntl = { 0 };
998 uint8_t pwrseq_instance = 0;
999 unsigned int pre_T11_delay = (link->dpcd_sink_ext_caps.bits.oled ? OLED_PRE_T11_DELAY : 0);
1000 unsigned int post_T7_delay = (link->dpcd_sink_ext_caps.bits.oled ? OLED_POST_T7_DELAY : 0);
1001
1002 DC_LOGGER_INIT(ctx);
1003
1004 if (dal_graphics_object_id_get_connector_id(link->link_enc->connector)
1005 != CONNECTOR_ID_EDP) {
1006 BREAK_TO_DEBUGGER();
1007 return;
1008 }
1009
1010 if (link->panel_cntl && !(link->dpcd_sink_ext_caps.bits.oled ||
1011 link->dpcd_sink_ext_caps.bits.hdr_aux_backlight_control == 1 ||
1012 link->dpcd_sink_ext_caps.bits.sdr_aux_backlight_control == 1)) {
1013 bool is_backlight_on = link->panel_cntl->funcs->is_panel_backlight_on(link->panel_cntl);
1014
1015 if ((enable && is_backlight_on) || (!enable && !is_backlight_on)) {
1016 DC_LOG_HW_RESUME_S3(
1017 "%s: panel already powered up/off. Do nothing.\n",
1018 __func__);
1019 return;
1020 }
1021 }
1022
1023 /* Send VBIOS command to control eDP panel backlight */
1024
1025 DC_LOG_HW_RESUME_S3(
1026 "%s: backlight action: %s\n",
1027 __func__, (enable ? "On":"Off"));
1028
1029 cntl.action = enable ?
1030 TRANSMITTER_CONTROL_BACKLIGHT_ON :
1031 TRANSMITTER_CONTROL_BACKLIGHT_OFF;
1032
1033 /*cntl.engine_id = ctx->engine;*/
1034 cntl.transmitter = link->link_enc->transmitter;
1035 cntl.connector_obj_id = link->link_enc->connector;
1036 /*todo: unhardcode*/
1037 cntl.lanes_number = LANE_COUNT_FOUR;
1038 cntl.hpd_sel = link->link_enc->hpd_source;
1039 cntl.signal = SIGNAL_TYPE_EDP;
1040
1041 /* For eDP, the following delays might need to be considered
1042 * after link training completed:
1043 * idle period - min. accounts for required BS-Idle pattern,
1044 * max. allows for source frame synchronization);
1045 * 50 msec max. delay from valid video data from source
1046 * to video on dislpay or backlight enable.
1047 *
1048 * Disable the delay for now.
1049 * Enable it in the future if necessary.
1050 */
1051 /* dc_service_sleep_in_milliseconds(50); */
1052 /*edp 1.2*/
1053 if (link->panel_cntl)
1054 pwrseq_instance = link->panel_cntl->pwrseq_inst;
1055
1056 if (cntl.action == TRANSMITTER_CONTROL_BACKLIGHT_ON) {
1057 if (!link->dc->config.edp_no_power_sequencing)
1058 /*
1059 * Sometimes, DP receiver chip power-controlled externally by an
1060 * Embedded Controller could be treated and used as eDP,
1061 * if it drives mobile display. In this case,
1062 * we shouldn't be doing power-sequencing, hence we can skip
1063 * waiting for T7-ready.
1064 */
1065 ctx->dc->link_srv->edp_receiver_ready_T7(link);
1066 else
1067 DC_LOG_DC("edp_receiver_ready_T7 skipped\n");
1068 }
1069
1070 /* Setting link_powered_externally will bypass delays in the backlight
1071 * as they are not required if the link is being powered by a different
1072 * source.
1073 */
1074 if (ctx->dc->ctx->dmub_srv &&
1075 ctx->dc->debug.dmub_command_table) {
1076 if (cntl.action == TRANSMITTER_CONTROL_BACKLIGHT_ON)
1077 ctx->dc_bios->funcs->enable_lvtma_control(ctx->dc_bios,
1078 LVTMA_CONTROL_LCD_BLON,
1079 pwrseq_instance, link->link_powered_externally);
1080 else
1081 ctx->dc_bios->funcs->enable_lvtma_control(ctx->dc_bios,
1082 LVTMA_CONTROL_LCD_BLOFF,
1083 pwrseq_instance, link->link_powered_externally);
1084 }
1085
1086 link_transmitter_control(ctx->dc_bios, &cntl);
1087
1088 if (enable && link->dpcd_sink_ext_caps.bits.oled &&
1089 !link->dc->config.edp_no_power_sequencing &&
1090 !link->local_sink->edid_caps.panel_patch.oled_optimize_display_on) {
1091 post_T7_delay += link->panel_config.pps.extra_post_t7_ms;
1092 msleep(post_T7_delay);
1093 }
1094
1095 if (link->dpcd_sink_ext_caps.bits.oled ||
1096 link->dpcd_sink_ext_caps.bits.hdr_aux_backlight_control == 1 ||
1097 link->dpcd_sink_ext_caps.bits.sdr_aux_backlight_control == 1)
1098 ctx->dc->link_srv->edp_backlight_enable_aux(link, enable);
1099
1100 /*edp 1.2*/
1101 if (cntl.action == TRANSMITTER_CONTROL_BACKLIGHT_OFF) {
1102 if (!link->dc->config.edp_no_power_sequencing)
1103 /*
1104 * Sometimes, DP receiver chip power-controlled externally by an
1105 * Embedded Controller could be treated and used as eDP,
1106 * if it drives mobile display. In this case,
1107 * we shouldn't be doing power-sequencing, hence we can skip
1108 * waiting for T9-ready.
1109 */
1110 ctx->dc->link_srv->edp_add_delay_for_T9(link);
1111 else
1112 DC_LOG_DC("edp_receiver_ready_T9 skipped\n");
1113 }
1114
1115 if (!enable) {
1116 /*follow oem panel config's requirement*/
1117 pre_T11_delay += link->panel_config.pps.extra_pre_t11_ms;
1118 if (pre_T11_delay)
1119 msleep(pre_T11_delay);
1120 }
1121 }
1122
dce110_enable_audio_stream(struct pipe_ctx * pipe_ctx)1123 void dce110_enable_audio_stream(struct pipe_ctx *pipe_ctx)
1124 {
1125 /* notify audio driver for audio modes of monitor */
1126 struct dc *dc;
1127 struct clk_mgr *clk_mgr;
1128 unsigned int i, num_audio = 1;
1129 const struct link_hwss *link_hwss;
1130
1131 if (!pipe_ctx->stream)
1132 return;
1133
1134 if (dc_is_rgb_signal(pipe_ctx->stream->signal))
1135 return;
1136
1137 dc = pipe_ctx->stream->ctx->dc;
1138 clk_mgr = dc->clk_mgr;
1139 link_hwss = get_link_hwss(pipe_ctx->stream->link, &pipe_ctx->link_res);
1140
1141 if (pipe_ctx->stream_res.audio && pipe_ctx->stream_res.audio->enabled == true)
1142 return;
1143
1144 if (pipe_ctx->stream_res.audio) {
1145 for (i = 0; i < MAX_PIPES; i++) {
1146 /*current_state not updated yet*/
1147 if (dc->current_state->res_ctx.pipe_ctx[i].stream_res.audio != NULL)
1148 num_audio++;
1149 }
1150 if (num_audio >= 1 && clk_mgr->funcs->enable_pme_wa) {
1151 /*wake AZ from D3 first before access az endpoint*/
1152 clk_mgr->funcs->enable_pme_wa(clk_mgr);
1153 }
1154
1155 pipe_ctx->stream_res.audio->funcs->az_enable(pipe_ctx->stream_res.audio);
1156
1157 link_hwss->enable_audio_packet(pipe_ctx);
1158
1159 if (pipe_ctx->stream_res.audio)
1160 pipe_ctx->stream_res.audio->enabled = true;
1161 }
1162 }
1163
dce110_disable_audio_stream(struct pipe_ctx * pipe_ctx)1164 void dce110_disable_audio_stream(struct pipe_ctx *pipe_ctx)
1165 {
1166 struct dc *dc;
1167 struct clk_mgr *clk_mgr;
1168 const struct link_hwss *link_hwss;
1169
1170 if (!pipe_ctx || !pipe_ctx->stream)
1171 return;
1172
1173 if (dc_is_rgb_signal(pipe_ctx->stream->signal))
1174 return;
1175
1176 dc = pipe_ctx->stream->ctx->dc;
1177 clk_mgr = dc->clk_mgr;
1178 link_hwss = get_link_hwss(pipe_ctx->stream->link, &pipe_ctx->link_res);
1179
1180 if (pipe_ctx->stream_res.audio && pipe_ctx->stream_res.audio->enabled == false)
1181 return;
1182
1183 link_hwss->disable_audio_packet(pipe_ctx);
1184
1185 if (pipe_ctx->stream_res.audio) {
1186 pipe_ctx->stream_res.audio->enabled = false;
1187
1188 if (clk_mgr->funcs->enable_pme_wa)
1189 /*this is the first audio. apply the PME w/a in order to wake AZ from D3*/
1190 clk_mgr->funcs->enable_pme_wa(clk_mgr);
1191
1192 /* TODO: notify audio driver for if audio modes list changed
1193 * add audio mode list change flag */
1194 /* dal_audio_disable_azalia_audio_jack_presence(stream->audio,
1195 * stream->stream_engine_id);
1196 */
1197 }
1198 }
1199
dce110_disable_stream(struct pipe_ctx * pipe_ctx)1200 void dce110_disable_stream(struct pipe_ctx *pipe_ctx)
1201 {
1202 struct dc_stream_state *stream = pipe_ctx->stream;
1203 struct dc_link *link = stream->link;
1204 struct dc *dc = pipe_ctx->stream->ctx->dc;
1205 const struct link_hwss *link_hwss = get_link_hwss(link, &pipe_ctx->link_res);
1206 struct dccg *dccg = dc->res_pool->dccg;
1207 struct timing_generator *tg = pipe_ctx->stream_res.tg;
1208 struct dtbclk_dto_params dto_params = {0};
1209 int dp_hpo_inst;
1210 struct link_encoder *link_enc = pipe_ctx->link_res.dio_link_enc;
1211 struct stream_encoder *stream_enc = pipe_ctx->stream_res.stream_enc;
1212
1213 if (!dc->config.unify_link_enc_assignment)
1214 link_enc = link_enc_cfg_get_link_enc(link);
1215
1216 if (dc_is_hdmi_tmds_signal(pipe_ctx->stream->signal)) {
1217 pipe_ctx->stream_res.stream_enc->funcs->stop_hdmi_info_packets(
1218 pipe_ctx->stream_res.stream_enc);
1219 pipe_ctx->stream_res.stream_enc->funcs->hdmi_reset_stream_attribute(
1220 pipe_ctx->stream_res.stream_enc);
1221 }
1222
1223 if (dc->link_srv->dp_is_128b_132b_signal(pipe_ctx)) {
1224 pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->stop_dp_info_packets(
1225 pipe_ctx->stream_res.hpo_dp_stream_enc);
1226 } else if (dc_is_dp_signal(pipe_ctx->stream->signal))
1227 pipe_ctx->stream_res.stream_enc->funcs->stop_dp_info_packets(
1228 pipe_ctx->stream_res.stream_enc);
1229
1230 dc->hwss.disable_audio_stream(pipe_ctx);
1231
1232 link_hwss->reset_stream_encoder(pipe_ctx);
1233
1234 if (dc->link_srv->dp_is_128b_132b_signal(pipe_ctx) && dccg) {
1235 dto_params.otg_inst = tg->inst;
1236 dto_params.timing = &pipe_ctx->stream->timing;
1237 dp_hpo_inst = pipe_ctx->stream_res.hpo_dp_stream_enc->inst;
1238 if (dccg) {
1239 dccg->funcs->disable_symclk32_se(dccg, dp_hpo_inst);
1240 dccg->funcs->set_dpstreamclk(dccg, REFCLK, tg->inst, dp_hpo_inst);
1241 if (!(dc->ctx->dce_version >= DCN_VERSION_3_5)) {
1242 if (dccg && dccg->funcs->set_dtbclk_dto)
1243 dccg->funcs->set_dtbclk_dto(dccg, &dto_params);
1244 }
1245 }
1246 } else if (dccg && dccg->funcs->disable_symclk_se) {
1247 dccg->funcs->disable_symclk_se(dccg, stream_enc->stream_enc_inst,
1248 link_enc->transmitter - TRANSMITTER_UNIPHY_A);
1249 }
1250
1251 if (link->ext_enc_id.id)
1252 dce110_external_encoder_control(EXTERNAL_ENCODER_CONTROL_DISABLE, link, NULL);
1253 }
1254
dce110_unblank_stream(struct pipe_ctx * pipe_ctx,struct dc_link_settings * link_settings)1255 void dce110_unblank_stream(struct pipe_ctx *pipe_ctx,
1256 struct dc_link_settings *link_settings)
1257 {
1258 struct encoder_unblank_param params = { { 0 } };
1259 struct dc_stream_state *stream = pipe_ctx->stream;
1260 struct dc_link *link = stream->link;
1261 struct dce_hwseq *hws = link->dc->hwseq;
1262
1263 /* only 3 items below are used by unblank */
1264 params.timing = pipe_ctx->stream->timing;
1265 params.link_settings.link_rate = link_settings->link_rate;
1266
1267 if (dc_is_dp_signal(pipe_ctx->stream->signal))
1268 pipe_ctx->stream_res.stream_enc->funcs->dp_unblank(link, pipe_ctx->stream_res.stream_enc, ¶ms);
1269
1270 if (link->local_sink && link->local_sink->sink_signal == SIGNAL_TYPE_EDP) {
1271 hws->funcs.edp_backlight_control(link, true);
1272 }
1273 }
1274
dce110_blank_stream(struct pipe_ctx * pipe_ctx)1275 void dce110_blank_stream(struct pipe_ctx *pipe_ctx)
1276 {
1277 struct dc_stream_state *stream = pipe_ctx->stream;
1278 struct dc_link *link = stream->link;
1279 struct dce_hwseq *hws = link->dc->hwseq;
1280
1281 if (hws && hws->wa_state.skip_blank_stream)
1282 return;
1283
1284 if (link->local_sink && link->local_sink->sink_signal == SIGNAL_TYPE_EDP) {
1285 if (!link->skip_implict_edp_power_control && hws)
1286 hws->funcs.edp_backlight_control(link, false);
1287 link->dc->hwss.set_abm_immediate_disable(pipe_ctx);
1288 }
1289
1290 if (link->dc->link_srv->dp_is_128b_132b_signal(pipe_ctx)) {
1291 /* TODO - DP2.0 HW: Set ODM mode in dp hpo encoder here */
1292 pipe_ctx->stream_res.hpo_dp_stream_enc->funcs->dp_blank(
1293 pipe_ctx->stream_res.hpo_dp_stream_enc);
1294 } else if (dc_is_dp_signal(pipe_ctx->stream->signal)) {
1295 pipe_ctx->stream_res.stream_enc->funcs->dp_blank(link, pipe_ctx->stream_res.stream_enc);
1296
1297 if (!dc_is_embedded_signal(pipe_ctx->stream->signal)) {
1298 /*
1299 * After output is idle pattern some sinks need time to recognize the stream
1300 * has changed or they enter protection state and hang.
1301 */
1302 msleep(60);
1303 }
1304 }
1305
1306 if (pipe_ctx->stream->signal == SIGNAL_TYPE_EDP &&
1307 !link->dc->config.edp_no_power_sequencing) {
1308 /*
1309 * Sometimes, DP receiver chip power-controlled externally by an
1310 * Embedded Controller could be treated and used as eDP,
1311 * if it drives mobile display. In this case,
1312 * we shouldn't be doing power-sequencing, hence we can skip
1313 * waiting for T9-ready.
1314 */
1315 link->dc->link_srv->edp_receiver_ready_T9(link);
1316 }
1317
1318 }
1319
1320
dce110_set_avmute(struct pipe_ctx * pipe_ctx,bool enable)1321 void dce110_set_avmute(struct pipe_ctx *pipe_ctx, bool enable)
1322 {
1323 if (pipe_ctx != NULL && pipe_ctx->stream_res.stream_enc != NULL)
1324 pipe_ctx->stream_res.stream_enc->funcs->set_avmute(pipe_ctx->stream_res.stream_enc, enable);
1325 }
1326
translate_to_dto_source(enum controller_id crtc_id)1327 enum audio_dto_source translate_to_dto_source(enum controller_id crtc_id)
1328 {
1329 switch (crtc_id) {
1330 case CONTROLLER_ID_D0:
1331 return DTO_SOURCE_ID0;
1332 case CONTROLLER_ID_D1:
1333 return DTO_SOURCE_ID1;
1334 case CONTROLLER_ID_D2:
1335 return DTO_SOURCE_ID2;
1336 case CONTROLLER_ID_D3:
1337 return DTO_SOURCE_ID3;
1338 case CONTROLLER_ID_D4:
1339 return DTO_SOURCE_ID4;
1340 case CONTROLLER_ID_D5:
1341 return DTO_SOURCE_ID5;
1342 default:
1343 return DTO_SOURCE_UNKNOWN;
1344 }
1345 }
1346
populate_audio_dp_link_info(const struct pipe_ctx * pipe_ctx,struct audio_dp_link_info * dp_link_info)1347 void populate_audio_dp_link_info(
1348 const struct pipe_ctx *pipe_ctx,
1349 struct audio_dp_link_info *dp_link_info)
1350 {
1351 const struct dc_stream_state *stream = pipe_ctx->stream;
1352 const struct dc_link *link = stream->link;
1353 struct fixed31_32 link_bw_kbps;
1354
1355 dp_link_info->encoding = link->dc->link_srv->dp_get_encoding_format(
1356 &pipe_ctx->link_config.dp_link_settings);
1357 dp_link_info->is_mst = (stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST);
1358 dp_link_info->lane_count = pipe_ctx->link_config.dp_link_settings.lane_count;
1359 dp_link_info->link_rate = pipe_ctx->link_config.dp_link_settings.link_rate;
1360
1361 link_bw_kbps = dc_fixpt_from_int(dc_link_bandwidth_kbps(link,
1362 &pipe_ctx->link_config.dp_link_settings));
1363
1364 /* For audio stream calculations, the video stream should not include FEC or SSC
1365 * in order to get the most pessimistic values.
1366 */
1367 if (dp_link_info->encoding == DP_8b_10b_ENCODING &&
1368 link->dc->link_srv->dp_is_fec_supported(link)) {
1369 link_bw_kbps = dc_fixpt_mul(link_bw_kbps,
1370 dc_fixpt_from_fraction(100, DATA_EFFICIENCY_8b_10b_FEC_EFFICIENCY_x100));
1371 } else if (dp_link_info->encoding == DP_128b_132b_ENCODING) {
1372 link_bw_kbps = dc_fixpt_mul(link_bw_kbps,
1373 dc_fixpt_from_fraction(10000, 9975)); /* 99.75% SSC overhead*/
1374 }
1375
1376 dp_link_info->link_bandwidth_kbps = dc_fixpt_floor(link_bw_kbps);
1377
1378 /* Calculates hblank_min_symbol_width for 128b/132b
1379 * Corresponding HBLANK_MIN_SYMBOL_WIDTH register is calculated as:
1380 * floor(h_blank * bits_per_pixel / 128)
1381 */
1382 if (dp_link_info->encoding == DP_128b_132b_ENCODING) {
1383 struct dc_crtc_timing *crtc_timing = &pipe_ctx->stream->timing;
1384
1385 uint32_t h_active = crtc_timing->h_addressable + crtc_timing->h_border_left
1386 + crtc_timing->h_border_right;
1387 uint32_t h_blank = crtc_timing->h_total - h_active;
1388
1389 uint32_t bpp;
1390
1391 if (crtc_timing->flags.DSC) {
1392 bpp = crtc_timing->dsc_cfg.bits_per_pixel;
1393 } else {
1394 /* When the timing is using DSC, dsc_cfg.bits_per_pixel is in 16th bits.
1395 * The bpp in this path is scaled to 16th bits so the final calculation
1396 * is correct for both cases.
1397 */
1398 bpp = 16;
1399 switch (crtc_timing->display_color_depth) {
1400 case COLOR_DEPTH_666:
1401 bpp *= 18;
1402 break;
1403 case COLOR_DEPTH_888:
1404 bpp *= 24;
1405 break;
1406 case COLOR_DEPTH_101010:
1407 bpp *= 30;
1408 break;
1409 case COLOR_DEPTH_121212:
1410 bpp *= 36;
1411 break;
1412 default:
1413 bpp = 0;
1414 break;
1415 }
1416
1417 switch (crtc_timing->pixel_encoding) {
1418 case PIXEL_ENCODING_YCBCR422:
1419 bpp = bpp * 2 / 3;
1420 break;
1421 case PIXEL_ENCODING_YCBCR420:
1422 bpp /= 2;
1423 break;
1424 default:
1425 break;
1426 }
1427 }
1428
1429 /* Min symbol width = floor(h_blank * (bpp/16) / 128) */
1430 dp_link_info->hblank_min_symbol_width = dc_fixpt_floor(
1431 dc_fixpt_div(dc_fixpt_from_int(h_blank * bpp),
1432 dc_fixpt_from_int(128 / 16)));
1433
1434 } else {
1435 dp_link_info->hblank_min_symbol_width = 0;
1436 }
1437 }
1438
build_audio_output(struct dc_state * state,const struct pipe_ctx * pipe_ctx,struct audio_output * audio_output)1439 void build_audio_output(
1440 struct dc_state *state,
1441 const struct pipe_ctx *pipe_ctx,
1442 struct audio_output *audio_output)
1443 {
1444 const struct dc_stream_state *stream = pipe_ctx->stream;
1445 audio_output->engine_id = pipe_ctx->stream_res.stream_enc->id;
1446
1447 audio_output->signal = pipe_ctx->stream->signal;
1448
1449 /* audio_crtc_info */
1450
1451 audio_output->crtc_info.h_total =
1452 stream->timing.h_total;
1453
1454 /*
1455 * Audio packets are sent during actual CRTC blank physical signal, we
1456 * need to specify actual active signal portion
1457 */
1458 audio_output->crtc_info.h_active =
1459 stream->timing.h_addressable
1460 + stream->timing.h_border_left
1461 + stream->timing.h_border_right;
1462
1463 audio_output->crtc_info.v_active =
1464 stream->timing.v_addressable
1465 + stream->timing.v_border_top
1466 + stream->timing.v_border_bottom;
1467
1468 audio_output->crtc_info.pixel_repetition = 1;
1469
1470 audio_output->crtc_info.interlaced =
1471 stream->timing.flags.INTERLACE;
1472
1473 audio_output->crtc_info.refresh_rate =
1474 (stream->timing.pix_clk_100hz*100)/
1475 (stream->timing.h_total*stream->timing.v_total);
1476
1477 audio_output->crtc_info.color_depth =
1478 stream->timing.display_color_depth;
1479
1480 audio_output->crtc_info.requested_pixel_clock_100Hz =
1481 pipe_ctx->stream_res.pix_clk_params.requested_pix_clk_100hz;
1482
1483 audio_output->crtc_info.calculated_pixel_clock_100Hz =
1484 pipe_ctx->stream_res.pix_clk_params.requested_pix_clk_100hz;
1485
1486 audio_output->crtc_info.pixel_encoding =
1487 stream->timing.pixel_encoding;
1488
1489 audio_output->crtc_info.dsc_bits_per_pixel =
1490 stream->timing.dsc_cfg.bits_per_pixel;
1491
1492 audio_output->crtc_info.dsc_num_slices =
1493 stream->timing.dsc_cfg.num_slices_h;
1494
1495 /*for HDMI, audio ACR is with deep color ratio factor*/
1496 if (dc_is_hdmi_tmds_signal(pipe_ctx->stream->signal) &&
1497 audio_output->crtc_info.requested_pixel_clock_100Hz ==
1498 (stream->timing.pix_clk_100hz)) {
1499 if (pipe_ctx->stream_res.pix_clk_params.pixel_encoding == PIXEL_ENCODING_YCBCR420) {
1500 audio_output->crtc_info.requested_pixel_clock_100Hz =
1501 audio_output->crtc_info.requested_pixel_clock_100Hz/2;
1502 audio_output->crtc_info.calculated_pixel_clock_100Hz =
1503 pipe_ctx->stream_res.pix_clk_params.requested_pix_clk_100hz/2;
1504
1505 }
1506 }
1507
1508 if (state->clk_mgr &&
1509 (pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT ||
1510 pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST)) {
1511 audio_output->pll_info.audio_dto_source_clock_in_khz =
1512 state->clk_mgr->funcs->get_dp_ref_clk_frequency(
1513 state->clk_mgr);
1514 }
1515
1516 audio_output->pll_info.dto_source =
1517 translate_to_dto_source(
1518 pipe_ctx->stream_res.tg->inst + 1);
1519
1520 /* TODO hard code to enable for now. Need get from stream */
1521 audio_output->pll_info.ss_enabled = true;
1522
1523 audio_output->pll_info.ss_percentage =
1524 pipe_ctx->pll_settings.ss_percentage;
1525
1526 if (dc_is_dp_signal(pipe_ctx->stream->signal)) {
1527 populate_audio_dp_link_info(pipe_ctx, &audio_output->dp_link_info);
1528 }
1529 }
1530
program_scaler(const struct dc * dc,const struct pipe_ctx * pipe_ctx)1531 static void program_scaler(const struct dc *dc,
1532 const struct pipe_ctx *pipe_ctx)
1533 {
1534 struct tg_color color = {0};
1535
1536 /* TOFPGA */
1537 if (pipe_ctx->plane_res.xfm->funcs->transform_set_pixel_storage_depth == NULL)
1538 return;
1539
1540 if (dc->debug.visual_confirm == VISUAL_CONFIRM_SURFACE)
1541 get_surface_visual_confirm_color(pipe_ctx, &color);
1542 else
1543 color_space_to_black_color(dc,
1544 pipe_ctx->stream->output_color_space,
1545 &color);
1546
1547 pipe_ctx->plane_res.xfm->funcs->transform_set_pixel_storage_depth(
1548 pipe_ctx->plane_res.xfm,
1549 pipe_ctx->plane_res.scl_data.lb_params.depth,
1550 &pipe_ctx->stream->bit_depth_params);
1551
1552 if (pipe_ctx->stream_res.tg->funcs->set_overscan_blank_color) {
1553 /*
1554 * The way 420 is packed, 2 channels carry Y component, 1 channel
1555 * alternate between Cb and Cr, so both channels need the pixel
1556 * value for Y
1557 */
1558 if (pipe_ctx->stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR420)
1559 color.color_r_cr = color.color_g_y;
1560
1561 pipe_ctx->stream_res.tg->funcs->set_overscan_blank_color(
1562 pipe_ctx->stream_res.tg,
1563 &color);
1564 }
1565
1566 pipe_ctx->plane_res.xfm->funcs->transform_set_scaler(pipe_ctx->plane_res.xfm,
1567 &pipe_ctx->plane_res.scl_data);
1568 }
1569
dce110_enable_stream_timing(struct pipe_ctx * pipe_ctx,struct dc_state * context,struct dc * dc)1570 static enum dc_status dce110_enable_stream_timing(
1571 struct pipe_ctx *pipe_ctx,
1572 struct dc_state *context,
1573 struct dc *dc)
1574 {
1575 (void)context;
1576 struct dc_stream_state *stream = pipe_ctx->stream;
1577 struct pipe_ctx *pipe_ctx_old = &dc->current_state->res_ctx.
1578 pipe_ctx[pipe_ctx->pipe_idx];
1579 struct tg_color black_color = {0};
1580
1581 if (!pipe_ctx_old->stream) {
1582
1583 /* program blank color */
1584 color_space_to_black_color(dc,
1585 stream->output_color_space, &black_color);
1586 pipe_ctx->stream_res.tg->funcs->set_blank_color(
1587 pipe_ctx->stream_res.tg,
1588 &black_color);
1589
1590 /*
1591 * Must blank CRTC after disabling power gating and before any
1592 * programming, otherwise CRTC will be hung in bad state
1593 */
1594 pipe_ctx->stream_res.tg->funcs->set_blank(pipe_ctx->stream_res.tg, true);
1595
1596 if (false == pipe_ctx->clock_source->funcs->program_pix_clk(
1597 pipe_ctx->clock_source,
1598 &pipe_ctx->stream_res.pix_clk_params,
1599 dc->link_srv->dp_get_encoding_format(&pipe_ctx->link_config.dp_link_settings),
1600 &pipe_ctx->pll_settings)) {
1601 BREAK_TO_DEBUGGER();
1602 return DC_ERROR_UNEXPECTED;
1603 }
1604
1605 if (dc_is_tmds_signal(stream->signal)) {
1606 stream->link->phy_state.symclk_ref_cnts.otg = 1;
1607 if (stream->link->phy_state.symclk_state == SYMCLK_OFF_TX_OFF)
1608 stream->link->phy_state.symclk_state = SYMCLK_ON_TX_OFF;
1609 else
1610 stream->link->phy_state.symclk_state = SYMCLK_ON_TX_ON;
1611 }
1612
1613 pipe_ctx->stream_res.tg->funcs->program_timing(
1614 pipe_ctx->stream_res.tg,
1615 &stream->timing,
1616 0,
1617 0,
1618 0,
1619 0,
1620 0,
1621 pipe_ctx->stream->signal,
1622 true);
1623 }
1624
1625 if (!pipe_ctx_old->stream) {
1626 if (false == pipe_ctx->stream_res.tg->funcs->enable_crtc(
1627 pipe_ctx->stream_res.tg)) {
1628 BREAK_TO_DEBUGGER();
1629 return DC_ERROR_UNEXPECTED;
1630 }
1631 }
1632
1633 return DC_OK;
1634 }
1635
dce110_apply_single_controller_ctx_to_hw(struct pipe_ctx * pipe_ctx,struct dc_state * context,struct dc * dc)1636 enum dc_status dce110_apply_single_controller_ctx_to_hw(
1637 struct pipe_ctx *pipe_ctx,
1638 struct dc_state *context,
1639 struct dc *dc)
1640 {
1641 struct dc_stream_state *stream = pipe_ctx->stream;
1642 struct dc_link *link = stream->link;
1643 struct drr_params params = {0};
1644 unsigned int event_triggers = 0;
1645 struct pipe_ctx *odm_pipe = pipe_ctx->next_odm_pipe;
1646 struct dce_hwseq *hws = dc->hwseq;
1647 const struct link_hwss *link_hwss = get_link_hwss(
1648 link, &pipe_ctx->link_res);
1649
1650
1651 if (hws->funcs.disable_stream_gating) {
1652 hws->funcs.disable_stream_gating(dc, pipe_ctx);
1653 }
1654
1655 if (pipe_ctx->stream_res.audio != NULL) {
1656 struct audio_output audio_output = {0};
1657
1658 build_audio_output(context, pipe_ctx, &audio_output);
1659
1660 link_hwss->setup_audio_output(pipe_ctx, &audio_output,
1661 pipe_ctx->stream_res.audio->inst);
1662
1663 pipe_ctx->stream_res.audio->funcs->az_configure(
1664 pipe_ctx->stream_res.audio,
1665 pipe_ctx->stream->signal,
1666 &audio_output.crtc_info,
1667 &pipe_ctx->stream->audio_info,
1668 &audio_output.dp_link_info);
1669
1670 if (dc->config.disable_hbr_audio_dp2)
1671 if (pipe_ctx->stream_res.audio->funcs->az_disable_hbr_audio &&
1672 dc->link_srv->dp_is_128b_132b_signal(pipe_ctx))
1673 pipe_ctx->stream_res.audio->funcs->az_disable_hbr_audio(pipe_ctx->stream_res.audio);
1674 }
1675
1676 /* make sure no pipes syncd to the pipe being enabled */
1677 if (!pipe_ctx->stream->apply_seamless_boot_optimization && dc->config.use_pipe_ctx_sync_logic)
1678 check_syncd_pipes_for_disabled_master_pipe(dc, context, pipe_ctx->pipe_idx);
1679
1680 pipe_ctx->stream_res.opp->funcs->opp_program_fmt(
1681 pipe_ctx->stream_res.opp,
1682 &stream->bit_depth_params,
1683 &stream->clamping);
1684
1685 pipe_ctx->stream_res.opp->funcs->opp_set_dyn_expansion(
1686 pipe_ctx->stream_res.opp,
1687 COLOR_SPACE_YCBCR601,
1688 stream->timing.display_color_depth,
1689 stream->signal);
1690
1691 while (odm_pipe) {
1692 odm_pipe->stream_res.opp->funcs->opp_set_dyn_expansion(
1693 odm_pipe->stream_res.opp,
1694 COLOR_SPACE_YCBCR601,
1695 stream->timing.display_color_depth,
1696 stream->signal);
1697
1698 odm_pipe->stream_res.opp->funcs->opp_program_fmt(
1699 odm_pipe->stream_res.opp,
1700 &stream->bit_depth_params,
1701 &stream->clamping);
1702 odm_pipe = odm_pipe->next_odm_pipe;
1703 }
1704
1705 /* DCN3.1 FPGA Workaround
1706 * Need to enable HPO DP Stream Encoder before setting OTG master enable.
1707 * To do so, move calling function enable_stream_timing to only be done AFTER calling
1708 * function core_link_enable_stream
1709 */
1710 if (!(hws->wa.dp_hpo_and_otg_sequence && dc->link_srv->dp_is_128b_132b_signal(pipe_ctx)))
1711 /* */
1712 /* Do not touch stream timing on seamless boot optimization. */
1713 if (!pipe_ctx->stream->apply_seamless_boot_optimization)
1714 hws->funcs.enable_stream_timing(pipe_ctx, context, dc);
1715
1716 if (hws->funcs.setup_vupdate_interrupt)
1717 hws->funcs.setup_vupdate_interrupt(dc, pipe_ctx);
1718
1719 params.vertical_total_min = stream->adjust.v_total_min;
1720 params.vertical_total_max = stream->adjust.v_total_max;
1721 set_drr_and_clear_adjust_pending(pipe_ctx, stream, ¶ms);
1722
1723 // DRR should set trigger event to monitor surface update event
1724 if (stream->adjust.v_total_min != 0 && stream->adjust.v_total_max != 0)
1725 event_triggers = 0x80;
1726 /* Event triggers and num frames initialized for DRR, but can be
1727 * later updated for PSR use. Note DRR trigger events are generated
1728 * regardless of whether num frames met.
1729 */
1730 if (pipe_ctx->stream_res.tg->funcs->set_static_screen_control)
1731 pipe_ctx->stream_res.tg->funcs->set_static_screen_control(
1732 pipe_ctx->stream_res.tg, event_triggers, 2);
1733
1734 if (!dc_is_virtual_signal(pipe_ctx->stream->signal))
1735 pipe_ctx->stream_res.stream_enc->funcs->dig_connect_to_otg(
1736 pipe_ctx->stream_res.stream_enc,
1737 pipe_ctx->stream_res.tg->inst);
1738
1739 if (dc_is_dp_signal(pipe_ctx->stream->signal))
1740 dc->link_srv->dp_trace_source_sequence(link, DPCD_SOURCE_SEQ_AFTER_CONNECT_DIG_FE_OTG);
1741
1742 /* Temporary workaround to perform DSC programming ahead of stream enablement
1743 * for smartmux/SPRS
1744 * TODO: Remove SmartMux/SPRS checks once movement of DSC programming is generalized
1745 */
1746 if (pipe_ctx->stream->timing.flags.DSC) {
1747 if ((pipe_ctx->stream->signal == SIGNAL_TYPE_EDP &&
1748 ((link->dc->config.smart_mux_version && link->dc->is_switch_in_progress_dest)
1749 || link->is_dds || link->skip_implict_edp_power_control)) &&
1750 (dc_is_dp_signal(pipe_ctx->stream->signal) ||
1751 dc_is_virtual_signal(pipe_ctx->stream->signal)))
1752 dc->link_srv->set_dsc_enable(pipe_ctx, true);
1753 }
1754
1755 if (!stream->dpms_off)
1756 dc->link_srv->set_dpms_on(context, pipe_ctx);
1757
1758 /* DCN3.1 FPGA Workaround
1759 * Need to enable HPO DP Stream Encoder before setting OTG master enable.
1760 * To do so, move calling function enable_stream_timing to only be done AFTER calling
1761 * function core_link_enable_stream
1762 */
1763 if (hws->wa.dp_hpo_and_otg_sequence && dc->link_srv->dp_is_128b_132b_signal(pipe_ctx)) {
1764 if (!pipe_ctx->stream->apply_seamless_boot_optimization)
1765 hws->funcs.enable_stream_timing(pipe_ctx, context, dc);
1766 }
1767
1768 pipe_ctx->plane_res.scl_data.lb_params.alpha_en = pipe_ctx->bottom_pipe != NULL;
1769
1770 /* Phantom and main stream share the same link (because the stream
1771 * is constructed with the same sink). Make sure not to override
1772 * and link programming on the main.
1773 */
1774 if (dc_state_get_pipe_subvp_type(context, pipe_ctx) != SUBVP_PHANTOM) {
1775 pipe_ctx->stream->link->psr_settings.psr_feature_enabled = false;
1776 pipe_ctx->stream->link->replay_settings.replay_feature_enabled = false;
1777 }
1778 return DC_OK;
1779 }
1780
1781 /******************************************************************************/
1782
power_down_encoders(struct dc * dc)1783 static void power_down_encoders(struct dc *dc)
1784 {
1785 int i;
1786
1787 for (i = 0; i < dc->link_count; i++) {
1788 struct dc_link *link = dc->links[i];
1789 struct link_encoder *link_enc = link->link_enc;
1790 enum signal_type signal = link->connector_signal;
1791
1792 dc->link_srv->blank_dp_stream(link, false);
1793 if (signal != SIGNAL_TYPE_EDP)
1794 signal = SIGNAL_TYPE_NONE;
1795
1796 if (link->ep_type == DISPLAY_ENDPOINT_PHY)
1797 link_enc->funcs->disable_output(link_enc, signal);
1798
1799 if (link->fec_state == dc_link_fec_enabled) {
1800 link_enc->funcs->fec_set_enable(link_enc, false);
1801 link_enc->funcs->fec_set_ready(link_enc, false);
1802 link->fec_state = dc_link_fec_not_ready;
1803 }
1804
1805 link->link_status.link_active = false;
1806 memset(&link->cur_link_settings, 0, sizeof(link->cur_link_settings));
1807 }
1808 }
1809
power_down_controllers(struct dc * dc)1810 static void power_down_controllers(struct dc *dc)
1811 {
1812 int i;
1813
1814 for (i = 0; i < dc->res_pool->timing_generator_count; i++) {
1815 dc->res_pool->timing_generators[i]->funcs->disable_crtc(
1816 dc->res_pool->timing_generators[i]);
1817 }
1818 }
1819
power_down_clock_sources(struct dc * dc)1820 static void power_down_clock_sources(struct dc *dc)
1821 {
1822 int i;
1823
1824 if (dc->res_pool->dp_clock_source->funcs->cs_power_down(
1825 dc->res_pool->dp_clock_source) == false)
1826 dm_error("Failed to power down pll! (dp clk src)\n");
1827
1828 for (i = 0; i < dc->res_pool->clk_src_count; i++) {
1829 if (dc->res_pool->clock_sources[i]->funcs->cs_power_down(
1830 dc->res_pool->clock_sources[i]) == false)
1831 dm_error("Failed to power down pll! (clk src index=%d)\n", i);
1832 }
1833 }
1834
power_down_all_hw_blocks(struct dc * dc)1835 static void power_down_all_hw_blocks(struct dc *dc)
1836 {
1837 power_down_encoders(dc);
1838
1839 power_down_controllers(dc);
1840
1841 power_down_clock_sources(dc);
1842
1843 if (dc->fbc_compressor)
1844 dc->fbc_compressor->funcs->disable_fbc(dc->fbc_compressor);
1845 }
1846
disable_vga_and_power_gate_all_controllers(struct dc * dc)1847 static void disable_vga_and_power_gate_all_controllers(
1848 struct dc *dc)
1849 {
1850 int i;
1851 struct timing_generator *tg;
1852 struct dc_context *ctx = dc->ctx;
1853
1854 if (dc->caps.ips_support)
1855 return;
1856
1857 for (i = 0; i < dc->res_pool->timing_generator_count; i++) {
1858 tg = dc->res_pool->timing_generators[i];
1859
1860 if (tg->funcs->disable_vga)
1861 tg->funcs->disable_vga(tg);
1862 }
1863 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1864 /* Enable CLOCK gating for each pipe BEFORE controller
1865 * powergating. */
1866 enable_display_pipe_clock_gating(ctx,
1867 true);
1868
1869 dc->current_state->res_ctx.pipe_ctx[i].pipe_idx = i;
1870 dc->hwss.disable_plane(dc, dc->current_state,
1871 &dc->current_state->res_ctx.pipe_ctx[i]);
1872 }
1873 }
1874
1875
get_edp_streams(struct dc_state * context,struct dc_stream_state ** edp_streams,int * edp_stream_num)1876 static void get_edp_streams(struct dc_state *context,
1877 struct dc_stream_state **edp_streams,
1878 int *edp_stream_num)
1879 {
1880 int i;
1881
1882 *edp_stream_num = 0;
1883 for (i = 0; i < context->stream_count; i++) {
1884 if (context->streams[i]->signal == SIGNAL_TYPE_EDP) {
1885 edp_streams[*edp_stream_num] = context->streams[i];
1886 if (++(*edp_stream_num) == MAX_NUM_EDP)
1887 return;
1888 }
1889 }
1890 }
1891
get_edp_links_with_sink(struct dc * dc,struct dc_link ** edp_links_with_sink,int * edp_with_sink_num)1892 static void get_edp_links_with_sink(
1893 struct dc *dc,
1894 struct dc_link **edp_links_with_sink,
1895 int *edp_with_sink_num)
1896 {
1897 int i;
1898
1899 /* check if there is an eDP panel not in use */
1900 *edp_with_sink_num = 0;
1901 for (i = 0; i < dc->link_count; i++) {
1902 if (dc->links[i]->local_sink &&
1903 dc->links[i]->local_sink->sink_signal == SIGNAL_TYPE_EDP) {
1904 edp_links_with_sink[*edp_with_sink_num] = dc->links[i];
1905 if (++(*edp_with_sink_num) == MAX_NUM_EDP)
1906 return;
1907 }
1908 }
1909 }
1910
clean_up_dsc_blocks(struct dc * dc)1911 static void clean_up_dsc_blocks(struct dc *dc)
1912 {
1913 struct display_stream_compressor *dsc = NULL;
1914 struct timing_generator *tg = NULL;
1915 struct stream_encoder *se = NULL;
1916 struct dccg *dccg = dc->res_pool->dccg;
1917 struct pg_cntl *pg_cntl = dc->res_pool->pg_cntl;
1918 int i;
1919
1920 if (!dc->caps.is_apu ||
1921 dc->ctx->dce_version < DCN_VERSION_3_15)
1922 return;
1923 /*VBIOS supports dsc starts from dcn315*/
1924 for (i = 0; i < dc->res_pool->res_cap->num_dsc; i++) {
1925 struct dcn_dsc_state s = {0};
1926
1927 dsc = dc->res_pool->dscs[i];
1928 dsc->funcs->dsc_read_state(dsc, &s);
1929 if (s.dsc_fw_en) {
1930 /* disable DSC in OPTC */
1931 if (i < dc->res_pool->timing_generator_count) {
1932 tg = dc->res_pool->timing_generators[i];
1933 if (tg->funcs->set_dsc_config)
1934 tg->funcs->set_dsc_config(tg, OPTC_DSC_DISABLED, 0, 0);
1935 }
1936 /* disable DSC in stream encoder */
1937 if (i < dc->res_pool->stream_enc_count) {
1938 se = dc->res_pool->stream_enc[i];
1939 if (se->funcs->dp_set_dsc_config)
1940 se->funcs->dp_set_dsc_config(se, OPTC_DSC_DISABLED, 0, 0);
1941 if (se->funcs->dp_set_dsc_pps_info_packet)
1942 se->funcs->dp_set_dsc_pps_info_packet(se, false, NULL, true);
1943 }
1944 /* disable DSC block */
1945 if (dccg->funcs->set_ref_dscclk)
1946 dccg->funcs->set_ref_dscclk(dccg, dsc->inst);
1947 dsc->funcs->dsc_disable(dsc);
1948
1949 /* power down DSC */
1950 if (pg_cntl != NULL)
1951 pg_cntl->funcs->dsc_pg_control(pg_cntl, dsc->inst, false);
1952 }
1953 }
1954 }
1955
dc_hwss_enable_otg_pwa(struct dc * dc,struct pipe_ctx * pipe_ctx)1956 static void dc_hwss_enable_otg_pwa(
1957 struct dc *dc,
1958 struct pipe_ctx *pipe_ctx)
1959 {
1960 struct timing_generator *tg = NULL;
1961
1962 if (dc->debug.enable_otg_frame_sync_pwa == 0)
1963 return;
1964
1965 if (pipe_ctx == NULL || pipe_ctx->stream_res.tg == NULL)
1966 return;
1967 tg = pipe_ctx->stream_res.tg;
1968
1969 /*only enable this if one active*/
1970 if (tg->funcs->enable_otg_pwa) {
1971 struct otc_pwa_frame_sync pwa_param = {0};
1972
1973 DC_LOGGER_INIT(dc->ctx);
1974 /* mode 1 to choose generate pwa sync signal on line 0 counting
1975 * from vstartup at very beginning of the frame
1976 */
1977 pwa_param.pwa_frame_sync_line_offset = 0;
1978 pwa_param.pwa_sync_mode = DC_OTG_PWA_FRAME_SYNC_MODE_VSTARTUP;
1979 /*frame sync line for generating high frame sync*/
1980 tg->funcs->enable_otg_pwa(tg, &pwa_param);
1981 DC_LOG_DC("Enable OTG PWA frame sync on TG %d\n", tg->inst);
1982 }
1983 }
1984
1985 /*
1986 * When ASIC goes from VBIOS/VGA mode to driver/accelerated mode we need:
1987 * 1. Power down all DC HW blocks
1988 * 2. Disable VGA engine on all controllers
1989 * 3. Enable power gating for controller
1990 * 4. Set acc_mode_change bit (VBIOS will clear this bit when going to FSDOS)
1991 */
dce110_enable_accelerated_mode(struct dc * dc,struct dc_state * context)1992 void dce110_enable_accelerated_mode(struct dc *dc, struct dc_state *context)
1993 {
1994 struct dc_link *edp_links_with_sink[MAX_NUM_EDP];
1995 struct dc_link *edp_links[MAX_NUM_EDP];
1996 struct dc_stream_state *edp_streams[MAX_NUM_EDP];
1997 struct dc_link *edp_link_with_sink = NULL;
1998 struct dc_link *edp_link = NULL;
1999 struct pipe_ctx *pipe_ctx = NULL;
2000 struct dce_hwseq *hws = dc->hwseq;
2001 int edp_with_sink_num;
2002 unsigned int edp_num;
2003 int edp_stream_num;
2004 int i;
2005 bool can_apply_edp_fast_boot = false;
2006 bool can_apply_seamless_boot = false;
2007 bool keep_edp_vdd_on = false;
2008 bool should_clean_dsc_block = true;
2009 struct dc_bios *dcb = dc->ctx->dc_bios;
2010 DC_LOGGER_INIT(dc->ctx);
2011
2012 get_edp_links_with_sink(dc, edp_links_with_sink, &edp_with_sink_num);
2013 dc_get_edp_links(dc, edp_links, &edp_num);
2014
2015 if (hws->funcs.init_pipes)
2016 hws->funcs.init_pipes(dc, context);
2017
2018 get_edp_streams(context, edp_streams, &edp_stream_num);
2019
2020 /* Check fastboot support, disable on DCE 6-8-10 because of blank screens */
2021 if (edp_num && edp_stream_num && dc->ctx->dce_version > DCE_VERSION_10_0) {
2022 for (i = 0; i < edp_num; i++) {
2023 edp_link = edp_links[i];
2024 if (edp_link != edp_streams[0]->link)
2025 continue;
2026 // enable fastboot if backend is enabled on eDP
2027 if (edp_link->link_enc->funcs->is_dig_enabled &&
2028 edp_link->link_enc->funcs->is_dig_enabled(edp_link->link_enc) &&
2029 edp_link->link_status.link_active) {
2030 struct dc_stream_state *edp_stream = edp_streams[0];
2031
2032 can_apply_edp_fast_boot = dc_validate_boot_timing(dc,
2033 edp_stream->sink, &edp_stream->timing);
2034
2035 // For Mux-platform, the default value is false.
2036 // Disable fast boot during mux switching.
2037 // The flag would be clean after switching done.
2038 if (dc->is_switch_in_progress_dest && edp_link->is_dds)
2039 can_apply_edp_fast_boot = false;
2040
2041 edp_stream->apply_edp_fast_boot_optimization = can_apply_edp_fast_boot;
2042 if (can_apply_edp_fast_boot) {
2043 DC_LOG_EVENT_LINK_TRAINING("eDP fast boot Enable\n");
2044
2045 // Vbios & Driver support different pixel rate div policy.
2046 pipe_ctx = resource_get_otg_master_for_stream(&context->res_ctx, edp_stream);
2047 if (pipe_ctx &&
2048 hws->funcs.is_dp_dig_pixel_rate_div_policy &&
2049 hws->funcs.is_dp_dig_pixel_rate_div_policy(pipe_ctx)) {
2050 // Get Vbios div factor from register
2051 dc->res_pool->dccg->funcs->get_pixel_rate_div(
2052 dc->res_pool->dccg,
2053 pipe_ctx->stream_res.tg->inst,
2054 &pipe_ctx->pixel_rate_divider.div_factor1,
2055 &pipe_ctx->pixel_rate_divider.div_factor2);
2056
2057 // VBios doesn't support pixel rate div, so force it.
2058 // If VBios supports it, we check it from reigster or other flags.
2059 pipe_ctx->stream_res.pix_clk_params.dio_se_pix_per_cycle = 1;
2060 }
2061 dc_hwss_enable_otg_pwa(dc, pipe_ctx);
2062 }
2063 break;
2064 }
2065 }
2066 // We are trying to enable eDP, don't power down VDD
2067 if (can_apply_edp_fast_boot)
2068 keep_edp_vdd_on = true;
2069 }
2070
2071 // Check seamless boot support
2072 for (i = 0; i < context->stream_count; i++) {
2073 if (context->streams[i]->apply_seamless_boot_optimization) {
2074 can_apply_seamless_boot = true;
2075 break;
2076 }
2077 }
2078
2079 /* eDP should not have stream in resume from S4 and so even with VBios post
2080 * it should get turned off
2081 */
2082 if (edp_with_sink_num)
2083 edp_link_with_sink = edp_links_with_sink[0];
2084
2085 // During a mux switch, powering down the HW blocks and then enabling
2086 // the link via a DPCD SET_POWER write causes a brief flash
2087 keep_edp_vdd_on |= dc->is_switch_in_progress_dest;
2088
2089 if (!can_apply_edp_fast_boot && !can_apply_seamless_boot) {
2090 if (edp_link_with_sink && !keep_edp_vdd_on) {
2091 /*turn off backlight before DP_blank and encoder powered down*/
2092 hws->funcs.edp_backlight_control(edp_link_with_sink, false);
2093 }
2094 /*resume from S3, no vbios posting, no need to power down again*/
2095 if (dcb && dcb->funcs && !dcb->funcs->is_accelerated_mode(dcb))
2096 clk_mgr_exit_optimized_pwr_state(dc, dc->clk_mgr);
2097
2098 power_down_all_hw_blocks(dc);
2099
2100 /* DSC could be enabled on eDP during VBIOS post.
2101 * To clean up dsc blocks if all eDP dpms_off is true.
2102 */
2103 for (i = 0; i < edp_stream_num; i++) {
2104 if (!edp_streams[i]->dpms_off) {
2105 should_clean_dsc_block = false;
2106 }
2107 }
2108
2109 if (should_clean_dsc_block)
2110 clean_up_dsc_blocks(dc);
2111
2112 disable_vga_and_power_gate_all_controllers(dc);
2113 if (edp_link_with_sink && !keep_edp_vdd_on)
2114 dc->hwss.edp_power_control(edp_link_with_sink, false);
2115 if (dcb && dcb->funcs && !dcb->funcs->is_accelerated_mode(dcb))
2116 clk_mgr_optimize_pwr_state(dc, dc->clk_mgr);
2117 }
2118 bios_set_scratch_acc_mode_change(dc->ctx->dc_bios, 1);
2119 }
2120
compute_pstate_blackout_duration(struct bw_fixed blackout_duration,const struct dc_stream_state * stream)2121 static uint32_t compute_pstate_blackout_duration(
2122 struct bw_fixed blackout_duration,
2123 const struct dc_stream_state *stream)
2124 {
2125 uint32_t total_dest_line_time_ns;
2126 uint32_t pstate_blackout_duration_ns;
2127
2128 pstate_blackout_duration_ns = 1000 * blackout_duration.value >> 24;
2129
2130 total_dest_line_time_ns = 1000000UL *
2131 (stream->timing.h_total * 10) /
2132 stream->timing.pix_clk_100hz +
2133 pstate_blackout_duration_ns;
2134
2135 return total_dest_line_time_ns;
2136 }
2137
dce110_set_displaymarks(const struct dc * dc,struct dc_state * context)2138 static void dce110_set_displaymarks(
2139 const struct dc *dc,
2140 struct dc_state *context)
2141 {
2142 uint8_t i, num_pipes;
2143 unsigned int underlay_idx = dc->res_pool->underlay_pipe_index;
2144
2145 for (i = 0, num_pipes = 0; i < MAX_PIPES; i++) {
2146 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2147 uint32_t total_dest_line_time_ns;
2148
2149 if (pipe_ctx->stream == NULL)
2150 continue;
2151
2152 total_dest_line_time_ns = compute_pstate_blackout_duration(
2153 dc->bw_vbios->blackout_duration, pipe_ctx->stream);
2154 pipe_ctx->plane_res.mi->funcs->mem_input_program_display_marks(
2155 pipe_ctx->plane_res.mi,
2156 context->bw_ctx.bw.dce.nbp_state_change_wm_ns[num_pipes],
2157 context->bw_ctx.bw.dce.stutter_exit_wm_ns[num_pipes],
2158 context->bw_ctx.bw.dce.stutter_entry_wm_ns[num_pipes],
2159 context->bw_ctx.bw.dce.urgent_wm_ns[num_pipes],
2160 total_dest_line_time_ns);
2161 if (i == underlay_idx) {
2162 num_pipes++;
2163 pipe_ctx->plane_res.mi->funcs->mem_input_program_chroma_display_marks(
2164 pipe_ctx->plane_res.mi,
2165 context->bw_ctx.bw.dce.nbp_state_change_wm_ns[num_pipes],
2166 context->bw_ctx.bw.dce.stutter_exit_wm_ns[num_pipes],
2167 context->bw_ctx.bw.dce.urgent_wm_ns[num_pipes],
2168 total_dest_line_time_ns);
2169 }
2170 num_pipes++;
2171 }
2172 }
2173
dce110_set_safe_displaymarks(struct resource_context * res_ctx,const struct resource_pool * pool)2174 void dce110_set_safe_displaymarks(
2175 struct resource_context *res_ctx,
2176 const struct resource_pool *pool)
2177 {
2178 int i;
2179 int underlay_idx = pool->underlay_pipe_index;
2180 struct dce_watermarks max_marks = {
2181 MAX_WATERMARK, MAX_WATERMARK, MAX_WATERMARK, MAX_WATERMARK };
2182 struct dce_watermarks nbp_marks = {
2183 SAFE_NBP_MARK, SAFE_NBP_MARK, SAFE_NBP_MARK, SAFE_NBP_MARK };
2184 struct dce_watermarks min_marks = { 0, 0, 0, 0};
2185
2186 for (i = 0; i < MAX_PIPES; i++) {
2187 if (res_ctx->pipe_ctx[i].stream == NULL || res_ctx->pipe_ctx[i].plane_res.mi == NULL)
2188 continue;
2189
2190 res_ctx->pipe_ctx[i].plane_res.mi->funcs->mem_input_program_display_marks(
2191 res_ctx->pipe_ctx[i].plane_res.mi,
2192 nbp_marks,
2193 max_marks,
2194 min_marks,
2195 max_marks,
2196 MAX_WATERMARK);
2197
2198 if (i == underlay_idx)
2199 res_ctx->pipe_ctx[i].plane_res.mi->funcs->mem_input_program_chroma_display_marks(
2200 res_ctx->pipe_ctx[i].plane_res.mi,
2201 nbp_marks,
2202 max_marks,
2203 max_marks,
2204 MAX_WATERMARK);
2205
2206 }
2207 }
2208
2209 /*******************************************************************************
2210 * Public functions
2211 ******************************************************************************/
2212
set_drr(struct pipe_ctx ** pipe_ctx,int num_pipes,struct dc_crtc_timing_adjust adjust)2213 static void set_drr(struct pipe_ctx **pipe_ctx,
2214 int num_pipes, struct dc_crtc_timing_adjust adjust)
2215 {
2216 int i = 0;
2217 struct drr_params params = {0};
2218 // DRR should set trigger event to monitor surface update event
2219 unsigned int event_triggers = 0x80;
2220 // Note DRR trigger events are generated regardless of whether num frames met.
2221 unsigned int num_frames = 2;
2222
2223 params.vertical_total_max = adjust.v_total_max;
2224 params.vertical_total_min = adjust.v_total_min;
2225
2226 /* TODO: If multiple pipes are to be supported, you need
2227 * some GSL stuff. Static screen triggers may be programmed differently
2228 * as well.
2229 */
2230 for (i = 0; i < num_pipes; i++) {
2231 /* dc_state_destruct() might null the stream resources, so fetch tg
2232 * here first to avoid a race condition. The lifetime of the pointee
2233 * itself (the timing_generator object) is not a problem here.
2234 */
2235 struct timing_generator *tg = pipe_ctx[i]->stream_res.tg;
2236
2237 if ((tg != NULL) && tg->funcs) {
2238 set_drr_and_clear_adjust_pending(pipe_ctx[i], pipe_ctx[i]->stream, ¶ms);
2239 if (adjust.v_total_max != 0 && adjust.v_total_min != 0)
2240 if (tg->funcs->set_static_screen_control)
2241 tg->funcs->set_static_screen_control(
2242 tg, event_triggers, num_frames);
2243 }
2244 }
2245 }
2246
get_position(struct pipe_ctx ** pipe_ctx,int num_pipes,struct crtc_position * position)2247 static void get_position(struct pipe_ctx **pipe_ctx,
2248 int num_pipes,
2249 struct crtc_position *position)
2250 {
2251 int i = 0;
2252
2253 /* TODO: handle pipes > 1
2254 */
2255 for (i = 0; i < num_pipes; i++)
2256 pipe_ctx[i]->stream_res.tg->funcs->get_position(pipe_ctx[i]->stream_res.tg, position);
2257 }
2258
set_static_screen_control(struct pipe_ctx ** pipe_ctx,int num_pipes,const struct dc_static_screen_params * params)2259 static void set_static_screen_control(struct pipe_ctx **pipe_ctx,
2260 int num_pipes, const struct dc_static_screen_params *params)
2261 {
2262 unsigned int i;
2263 unsigned int triggers = 0;
2264
2265 if (params->triggers.overlay_update)
2266 triggers |= 0x100;
2267 if (params->triggers.surface_update)
2268 triggers |= 0x80;
2269 if (params->triggers.cursor_update)
2270 triggers |= 0x2;
2271 if (params->triggers.force_trigger)
2272 triggers |= 0x1;
2273
2274 if (num_pipes) {
2275 struct dc *dc = pipe_ctx[0]->stream->ctx->dc;
2276
2277 if (dc->fbc_compressor)
2278 triggers |= 0x84;
2279 }
2280
2281 for (i = 0; i < num_pipes; i++)
2282 pipe_ctx[i]->stream_res.tg->funcs->
2283 set_static_screen_control(pipe_ctx[i]->stream_res.tg,
2284 triggers, params->num_frames);
2285 }
2286
2287 /*
2288 * Check if FBC can be enabled
2289 */
should_enable_fbc(struct dc * dc,struct dc_state * context,uint32_t * pipe_idx)2290 static bool should_enable_fbc(struct dc *dc,
2291 struct dc_state *context,
2292 uint32_t *pipe_idx)
2293 {
2294 uint32_t i;
2295 struct pipe_ctx *pipe_ctx = NULL;
2296 struct resource_context *res_ctx = &context->res_ctx;
2297 unsigned int underlay_idx = dc->res_pool->underlay_pipe_index;
2298
2299
2300 ASSERT(dc->fbc_compressor);
2301
2302 /* FBC memory should be allocated */
2303 if (!dc->ctx->fbc_gpu_addr)
2304 return false;
2305
2306 /* Only supports single display */
2307 if (context->stream_count != 1)
2308 return false;
2309
2310 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2311 if (res_ctx->pipe_ctx[i].stream) {
2312
2313 pipe_ctx = &res_ctx->pipe_ctx[i];
2314
2315 /* fbc not applicable on underlay pipe */
2316 if (pipe_ctx->pipe_idx != underlay_idx) {
2317 *pipe_idx = i;
2318 break;
2319 }
2320 }
2321 }
2322
2323 if (i == dc->res_pool->pipe_count)
2324 return false;
2325
2326 if (!pipe_ctx->stream->link)
2327 return false;
2328
2329 /* Only supports eDP */
2330 if (pipe_ctx->stream->link->connector_signal != SIGNAL_TYPE_EDP)
2331 return false;
2332
2333 /* PSR should not be enabled */
2334 if (pipe_ctx->stream->link->psr_settings.psr_feature_enabled)
2335 return false;
2336
2337 /* Replay should not be enabled */
2338 if (pipe_ctx->stream->link->replay_settings.replay_feature_enabled)
2339 return false;
2340
2341 /* Nothing to compress */
2342 if (!pipe_ctx->plane_state)
2343 return false;
2344
2345 /* Only for non-linear tiling */
2346 if (pipe_ctx->plane_state->tiling_info.gfx8.array_mode == DC_ARRAY_LINEAR_GENERAL)
2347 return false;
2348
2349 return true;
2350 }
2351
2352 /*
2353 * Enable FBC
2354 */
enable_fbc(struct dc * dc,struct dc_state * context)2355 void enable_fbc(
2356 struct dc *dc,
2357 struct dc_state *context)
2358 {
2359 uint32_t pipe_idx = 0;
2360
2361 if (should_enable_fbc(dc, context, &pipe_idx)) {
2362 /* Program GRPH COMPRESSED ADDRESS and PITCH */
2363 struct compr_addr_and_pitch_params params = {0, 0, 0};
2364 struct compressor *compr = dc->fbc_compressor;
2365 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[pipe_idx];
2366
2367 params.source_view_width = pipe_ctx->stream->timing.h_addressable;
2368 params.source_view_height = pipe_ctx->stream->timing.v_addressable;
2369 params.inst = pipe_ctx->stream_res.tg->inst;
2370 compr->compr_surface_address.quad_part = dc->ctx->fbc_gpu_addr;
2371
2372 compr->funcs->surface_address_and_pitch(compr, ¶ms);
2373 compr->funcs->set_fbc_invalidation_triggers(compr, 1);
2374
2375 compr->funcs->enable_fbc(compr, ¶ms);
2376 }
2377 }
2378
dce110_reset_hw_ctx_wrap(struct dc * dc,struct dc_state * context)2379 static void dce110_reset_hw_ctx_wrap(
2380 struct dc *dc,
2381 struct dc_state *context)
2382 {
2383 int i;
2384
2385 /* Reset old context */
2386 /* look up the targets that have been removed since last commit */
2387 for (i = 0; i < MAX_PIPES; i++) {
2388 struct pipe_ctx *pipe_ctx_old =
2389 &dc->current_state->res_ctx.pipe_ctx[i];
2390 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2391
2392 /* Note: We need to disable output if clock sources change,
2393 * since bios does optimization and doesn't apply if changing
2394 * PHY when not already disabled.
2395 */
2396
2397 /* Skip underlay pipe since it will be handled in commit surface*/
2398 if (!pipe_ctx_old->stream || pipe_ctx_old->top_pipe)
2399 continue;
2400
2401 if (!pipe_ctx->stream ||
2402 pipe_need_reprogram(pipe_ctx_old, pipe_ctx)) {
2403 struct clock_source *old_clk = pipe_ctx_old->clock_source;
2404
2405 /* Disable if new stream is null. O/w, if stream is
2406 * disabled already, no need to disable again.
2407 */
2408 if (!pipe_ctx->stream || !pipe_ctx->stream->dpms_off) {
2409 dc->link_srv->set_dpms_off(pipe_ctx_old);
2410
2411 /* free acquired resources*/
2412 if (pipe_ctx_old->stream_res.audio) {
2413 /*disable az_endpoint*/
2414 pipe_ctx_old->stream_res.audio->funcs->
2415 az_disable(pipe_ctx_old->stream_res.audio);
2416
2417 /*free audio*/
2418 if (dc->caps.dynamic_audio == true) {
2419 /*we have to dynamic arbitrate the audio endpoints*/
2420 /*we free the resource, need reset is_audio_acquired*/
2421 update_audio_usage(&dc->current_state->res_ctx, dc->res_pool,
2422 pipe_ctx_old->stream_res.audio, false);
2423 pipe_ctx_old->stream_res.audio = NULL;
2424 }
2425 }
2426 }
2427
2428 pipe_ctx_old->stream_res.tg->funcs->set_blank(pipe_ctx_old->stream_res.tg, true);
2429 if (!hwss_wait_for_blank_complete(pipe_ctx_old->stream_res.tg)) {
2430 dm_error("DC: failed to blank crtc!\n");
2431 BREAK_TO_DEBUGGER();
2432 }
2433 pipe_ctx_old->stream_res.tg->funcs->disable_crtc(pipe_ctx_old->stream_res.tg);
2434 if (dc_is_tmds_signal(pipe_ctx_old->stream->signal))
2435 pipe_ctx_old->stream->link->phy_state.symclk_ref_cnts.otg = 0;
2436 pipe_ctx_old->plane_res.mi->funcs->free_mem_input(
2437 pipe_ctx_old->plane_res.mi, dc->current_state->stream_count);
2438
2439 if (old_clk && 0 == resource_get_clock_source_reference(&context->res_ctx,
2440 dc->res_pool,
2441 old_clk))
2442 old_clk->funcs->cs_power_down(old_clk);
2443
2444 dc->hwss.disable_plane(dc, dc->current_state, pipe_ctx_old);
2445
2446 pipe_ctx_old->stream = NULL;
2447 }
2448 }
2449 }
2450
dce110_setup_audio_dto(struct dc * dc,struct dc_state * context)2451 static void dce110_setup_audio_dto(
2452 struct dc *dc,
2453 struct dc_state *context)
2454 {
2455 unsigned int i;
2456
2457 /* program audio wall clock. use HDMI as clock source if HDMI
2458 * audio active. Otherwise, use DP as clock source
2459 * first, loop to find any HDMI audio, if not, loop find DP audio
2460 */
2461 /* Setup audio rate clock source */
2462 /* Issue:
2463 * Audio lag happened on DP monitor when unplug a HDMI monitor
2464 *
2465 * Cause:
2466 * In case of DP and HDMI connected or HDMI only, DCCG_AUDIO_DTO_SEL
2467 * is set to either dto0 or dto1, audio should work fine.
2468 * In case of DP connected only, DCCG_AUDIO_DTO_SEL should be dto1,
2469 * set to dto0 will cause audio lag.
2470 *
2471 * Solution:
2472 * Not optimized audio wall dto setup. When mode set, iterate pipe_ctx,
2473 * find first available pipe with audio, setup audio wall DTO per topology
2474 * instead of per pipe.
2475 */
2476 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2477 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2478
2479 if (pipe_ctx->stream == NULL)
2480 continue;
2481
2482 if (pipe_ctx->top_pipe)
2483 continue;
2484 if (pipe_ctx->stream->signal != SIGNAL_TYPE_HDMI_TYPE_A)
2485 continue;
2486 if (pipe_ctx->stream_res.audio != NULL) {
2487 struct audio_output audio_output;
2488
2489 build_audio_output(context, pipe_ctx, &audio_output);
2490
2491 if (dc->res_pool->dccg && dc->res_pool->dccg->funcs->set_audio_dtbclk_dto) {
2492 struct dtbclk_dto_params dto_params = {0};
2493
2494 dc->res_pool->dccg->funcs->set_audio_dtbclk_dto(
2495 dc->res_pool->dccg, &dto_params);
2496
2497 pipe_ctx->stream_res.audio->funcs->wall_dto_setup(
2498 pipe_ctx->stream_res.audio,
2499 pipe_ctx->stream->signal,
2500 &audio_output.crtc_info,
2501 &audio_output.pll_info);
2502 } else
2503 pipe_ctx->stream_res.audio->funcs->wall_dto_setup(
2504 pipe_ctx->stream_res.audio,
2505 pipe_ctx->stream->signal,
2506 &audio_output.crtc_info,
2507 &audio_output.pll_info);
2508 break;
2509 }
2510 }
2511
2512 /* no HDMI audio is found, try DP audio */
2513 if (i == dc->res_pool->pipe_count) {
2514 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2515 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2516
2517 if (pipe_ctx->stream == NULL)
2518 continue;
2519
2520 if (pipe_ctx->top_pipe)
2521 continue;
2522
2523 if (!dc_is_dp_signal(pipe_ctx->stream->signal))
2524 continue;
2525
2526 if (pipe_ctx->stream_res.audio != NULL) {
2527 struct audio_output audio_output = {0};
2528
2529 build_audio_output(context, pipe_ctx, &audio_output);
2530
2531 pipe_ctx->stream_res.audio->funcs->wall_dto_setup(
2532 pipe_ctx->stream_res.audio,
2533 pipe_ctx->stream->signal,
2534 &audio_output.crtc_info,
2535 &audio_output.pll_info);
2536 break;
2537 }
2538 }
2539 }
2540 }
2541
dce110_apply_ctx_to_hw(struct dc * dc,struct dc_state * context)2542 enum dc_status dce110_apply_ctx_to_hw(
2543 struct dc *dc,
2544 struct dc_state *context)
2545 {
2546 struct dce_hwseq *hws = dc->hwseq;
2547 struct dc_bios *dcb = dc->ctx->dc_bios;
2548 enum dc_status status;
2549 int i;
2550 bool was_hpo_acquired = resource_is_hpo_acquired(dc->current_state);
2551 bool is_hpo_acquired = resource_is_hpo_acquired(context);
2552
2553 /* reset syncd pipes from disabled pipes */
2554 if (dc->config.use_pipe_ctx_sync_logic)
2555 reset_syncd_pipes_from_disabled_pipes(dc, context);
2556
2557 /* Reset old context */
2558 /* look up the targets that have been removed since last commit */
2559 hws->funcs.reset_hw_ctx_wrap(dc, context);
2560
2561 /* Skip applying if no targets */
2562 if (context->stream_count <= 0)
2563 return DC_OK;
2564
2565 /* Apply new context */
2566 dcb->funcs->set_scratch_critical_state(dcb, true);
2567
2568 /* below is for real asic only */
2569 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2570 struct pipe_ctx *pipe_ctx_old =
2571 &dc->current_state->res_ctx.pipe_ctx[i];
2572 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2573
2574 if (pipe_ctx->stream == NULL || pipe_ctx->top_pipe)
2575 continue;
2576
2577 if (pipe_ctx->stream == pipe_ctx_old->stream) {
2578 if (pipe_ctx_old->clock_source != pipe_ctx->clock_source)
2579 dce_crtc_switch_to_clk_src(dc->hwseq,
2580 pipe_ctx->clock_source, i);
2581 continue;
2582 }
2583
2584 hws->funcs.enable_display_power_gating(
2585 dc, i, dc->ctx->dc_bios,
2586 PIPE_GATING_CONTROL_DISABLE);
2587 }
2588
2589 if (dc->fbc_compressor)
2590 dc->fbc_compressor->funcs->disable_fbc(dc->fbc_compressor);
2591
2592 dce110_setup_audio_dto(dc, context);
2593
2594 if (dc->hwseq->funcs.setup_hpo_hw_control && was_hpo_acquired != is_hpo_acquired) {
2595 dc->hwseq->funcs.setup_hpo_hw_control(dc->hwseq, is_hpo_acquired);
2596 }
2597
2598 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2599 struct pipe_ctx *pipe_ctx_old =
2600 &dc->current_state->res_ctx.pipe_ctx[i];
2601 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2602
2603 if (pipe_ctx->stream == NULL)
2604 continue;
2605
2606 if (pipe_ctx->stream == pipe_ctx_old->stream &&
2607 pipe_ctx->stream->link->link_state_valid) {
2608 continue;
2609 }
2610
2611 if (pipe_ctx_old->stream && !pipe_need_reprogram(pipe_ctx_old, pipe_ctx))
2612 continue;
2613
2614 if (pipe_ctx->top_pipe || pipe_ctx->prev_odm_pipe)
2615 continue;
2616
2617 status = dce110_apply_single_controller_ctx_to_hw(
2618 pipe_ctx,
2619 context,
2620 dc);
2621
2622 if (DC_OK != status)
2623 return status;
2624
2625 #ifdef CONFIG_DRM_AMD_DC_FP
2626 if (hws->funcs.resync_fifo_dccg_dio)
2627 hws->funcs.resync_fifo_dccg_dio(hws, dc, context, i);
2628 #endif
2629 }
2630
2631
2632 if (dc->debug.enable_otg_frame_sync_pwa && context->stream_count == 1) {
2633 /* only enable this on one OTG*/
2634 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2635 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2636
2637 if (pipe_ctx && pipe_ctx->stream != NULL) {
2638 dc_hwss_enable_otg_pwa(dc, pipe_ctx);
2639 break;
2640 }
2641 }
2642 }
2643 if (dc->fbc_compressor)
2644 enable_fbc(dc, dc->current_state);
2645
2646 dcb->funcs->set_scratch_critical_state(dcb, false);
2647
2648 return DC_OK;
2649 }
2650
2651 /*******************************************************************************
2652 * Front End programming
2653 ******************************************************************************/
set_default_colors(struct pipe_ctx * pipe_ctx)2654 static void set_default_colors(struct pipe_ctx *pipe_ctx)
2655 {
2656 struct default_adjustment default_adjust = { 0 };
2657
2658 default_adjust.force_hw_default = false;
2659 default_adjust.in_color_space = pipe_ctx->plane_state->color_space;
2660 default_adjust.out_color_space = pipe_ctx->stream->output_color_space;
2661 default_adjust.csc_adjust_type = GRAPHICS_CSC_ADJUST_TYPE_SW;
2662 default_adjust.surface_pixel_format = pipe_ctx->plane_res.scl_data.format;
2663
2664 /* display color depth */
2665 default_adjust.color_depth =
2666 pipe_ctx->stream->timing.display_color_depth;
2667
2668 /* Lb color depth */
2669 default_adjust.lb_color_depth = pipe_ctx->plane_res.scl_data.lb_params.depth;
2670
2671 pipe_ctx->plane_res.xfm->funcs->opp_set_csc_default(
2672 pipe_ctx->plane_res.xfm, &default_adjust);
2673 }
2674
2675
2676 /*******************************************************************************
2677 * In order to turn on/off specific surface we will program
2678 * Blender + CRTC
2679 *
2680 * In case that we have two surfaces and they have a different visibility
2681 * we can't turn off the CRTC since it will turn off the entire display
2682 *
2683 * |----------------------------------------------- |
2684 * |bottom pipe|curr pipe | | |
2685 * |Surface |Surface | Blender | CRCT |
2686 * |visibility |visibility | Configuration| |
2687 * |------------------------------------------------|
2688 * | off | off | CURRENT_PIPE | blank |
2689 * | off | on | CURRENT_PIPE | unblank |
2690 * | on | off | OTHER_PIPE | unblank |
2691 * | on | on | BLENDING | unblank |
2692 * -------------------------------------------------|
2693 *
2694 ******************************************************************************/
program_surface_visibility(const struct dc * dc,struct pipe_ctx * pipe_ctx)2695 static void program_surface_visibility(const struct dc *dc,
2696 struct pipe_ctx *pipe_ctx)
2697 {
2698 enum blnd_mode blender_mode = BLND_MODE_CURRENT_PIPE;
2699 bool blank_target = false;
2700
2701 if (pipe_ctx->bottom_pipe) {
2702
2703 /* For now we are supporting only two pipes */
2704 ASSERT(pipe_ctx->bottom_pipe->bottom_pipe == NULL);
2705
2706 if (pipe_ctx->bottom_pipe->plane_state->visible) {
2707 if (pipe_ctx->plane_state->visible)
2708 blender_mode = BLND_MODE_BLENDING;
2709 else
2710 blender_mode = BLND_MODE_OTHER_PIPE;
2711
2712 } else if (!pipe_ctx->plane_state->visible)
2713 blank_target = true;
2714
2715 } else if (!pipe_ctx->plane_state->visible)
2716 blank_target = true;
2717
2718 dce_set_blender_mode(dc->hwseq, pipe_ctx->stream_res.tg->inst, blender_mode);
2719 pipe_ctx->stream_res.tg->funcs->set_blank(pipe_ctx->stream_res.tg, blank_target);
2720
2721 }
2722
program_gamut_remap(struct pipe_ctx * pipe_ctx)2723 static void program_gamut_remap(struct pipe_ctx *pipe_ctx)
2724 {
2725 int i = 0;
2726 struct xfm_grph_csc_adjustment adjust;
2727 memset(&adjust, 0, sizeof(adjust));
2728 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS;
2729
2730
2731 if (pipe_ctx->stream->gamut_remap_matrix.enable_remap == true) {
2732 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_SW;
2733
2734 for (i = 0; i < CSC_TEMPERATURE_MATRIX_SIZE; i++)
2735 adjust.temperature_matrix[i] =
2736 pipe_ctx->stream->gamut_remap_matrix.matrix[i];
2737 }
2738
2739 pipe_ctx->plane_res.xfm->funcs->transform_set_gamut_remap(pipe_ctx->plane_res.xfm, &adjust);
2740 }
update_plane_addr(const struct dc * dc,struct pipe_ctx * pipe_ctx)2741 static void update_plane_addr(const struct dc *dc,
2742 struct pipe_ctx *pipe_ctx)
2743 {
2744 (void)dc;
2745 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
2746
2747 if (plane_state == NULL)
2748 return;
2749
2750 pipe_ctx->plane_res.mi->funcs->mem_input_program_surface_flip_and_addr(
2751 pipe_ctx->plane_res.mi,
2752 &plane_state->address,
2753 plane_state->flip_immediate);
2754
2755 plane_state->status.requested_address = plane_state->address;
2756 }
2757
dce110_update_pending_status(struct pipe_ctx * pipe_ctx)2758 static void dce110_update_pending_status(struct pipe_ctx *pipe_ctx)
2759 {
2760 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
2761
2762 if (plane_state == NULL)
2763 return;
2764
2765 plane_state->status.is_flip_pending =
2766 pipe_ctx->plane_res.mi->funcs->mem_input_is_flip_pending(
2767 pipe_ctx->plane_res.mi);
2768
2769 if (plane_state->status.is_flip_pending && !plane_state->visible)
2770 pipe_ctx->plane_res.mi->current_address = pipe_ctx->plane_res.mi->request_address;
2771
2772 plane_state->status.current_address = pipe_ctx->plane_res.mi->current_address;
2773 if (pipe_ctx->plane_res.mi->current_address.type == PLN_ADDR_TYPE_GRPH_STEREO &&
2774 pipe_ctx->stream_res.tg->funcs->is_stereo_left_eye) {
2775 plane_state->status.is_right_eye =\
2776 !pipe_ctx->stream_res.tg->funcs->is_stereo_left_eye(pipe_ctx->stream_res.tg);
2777 }
2778 }
2779
dce110_power_down(struct dc * dc)2780 void dce110_power_down(struct dc *dc)
2781 {
2782 power_down_all_hw_blocks(dc);
2783 disable_vga_and_power_gate_all_controllers(dc);
2784 }
2785
wait_for_reset_trigger_to_occur(struct dc_context * dc_ctx,struct timing_generator * tg)2786 static bool wait_for_reset_trigger_to_occur(
2787 struct dc_context *dc_ctx,
2788 struct timing_generator *tg)
2789 {
2790 bool rc = false;
2791
2792 /* To avoid endless loop we wait at most
2793 * frames_to_wait_on_triggered_reset frames for the reset to occur. */
2794 const uint32_t frames_to_wait_on_triggered_reset = 10;
2795 uint32_t i;
2796
2797 for (i = 0; i < frames_to_wait_on_triggered_reset; i++) {
2798
2799 if (!tg->funcs->is_counter_moving(tg)) {
2800 DC_ERROR("TG counter is not moving!\n");
2801 break;
2802 }
2803
2804 if (tg->funcs->did_triggered_reset_occur(tg)) {
2805 rc = true;
2806 /* usually occurs at i=1 */
2807 DC_SYNC_INFO("GSL: reset occurred at wait count: %d\n",
2808 i);
2809 break;
2810 }
2811
2812 /* Wait for one frame. */
2813 tg->funcs->wait_for_state(tg, CRTC_STATE_VACTIVE);
2814 tg->funcs->wait_for_state(tg, CRTC_STATE_VBLANK);
2815 }
2816
2817 if (false == rc)
2818 DC_ERROR("GSL: Timeout on reset trigger!\n");
2819
2820 return rc;
2821 }
2822
2823 /* Enable timing synchronization for a group of Timing Generators. */
dce110_enable_timing_synchronization(struct dc * dc,struct dc_state * state,int group_index,int group_size,struct pipe_ctx * grouped_pipes[])2824 static void dce110_enable_timing_synchronization(
2825 struct dc *dc,
2826 struct dc_state *state,
2827 int group_index,
2828 int group_size,
2829 struct pipe_ctx *grouped_pipes[])
2830 {
2831 (void)state;
2832 (void)group_index;
2833 struct dcp_gsl_params gsl_params = { 0 };
2834 int i;
2835 DC_LOGGER_INIT(dc->ctx);
2836
2837 DC_SYNC_INFO("GSL: Setting-up...\n");
2838
2839 /* Designate a single TG in the group as a master.
2840 * Since HW doesn't care which one, we always assign
2841 * the 1st one in the group. */
2842 gsl_params.gsl_group = 0;
2843 gsl_params.gsl_master = grouped_pipes[0]->stream_res.tg->inst;
2844
2845 for (i = 0; i < group_size; i++)
2846 grouped_pipes[i]->stream_res.tg->funcs->setup_global_swap_lock(
2847 grouped_pipes[i]->stream_res.tg, &gsl_params);
2848
2849 /* Reset slave controllers on master VSync */
2850 DC_SYNC_INFO("GSL: enabling trigger-reset\n");
2851
2852 for (i = 1 /* skip the master */; i < group_size; i++)
2853 grouped_pipes[i]->stream_res.tg->funcs->enable_reset_trigger(
2854 grouped_pipes[i]->stream_res.tg,
2855 gsl_params.gsl_group);
2856
2857 for (i = 1 /* skip the master */; i < group_size; i++) {
2858 DC_SYNC_INFO("GSL: waiting for reset to occur.\n");
2859 wait_for_reset_trigger_to_occur(dc_ctx, grouped_pipes[i]->stream_res.tg);
2860 grouped_pipes[i]->stream_res.tg->funcs->disable_reset_trigger(
2861 grouped_pipes[i]->stream_res.tg);
2862 }
2863
2864 /* GSL Vblank synchronization is a one time sync mechanism, assumption
2865 * is that the sync'ed displays will not drift out of sync over time*/
2866 DC_SYNC_INFO("GSL: Restoring register states.\n");
2867 for (i = 0; i < group_size; i++)
2868 grouped_pipes[i]->stream_res.tg->funcs->tear_down_global_swap_lock(grouped_pipes[i]->stream_res.tg);
2869
2870 DC_SYNC_INFO("GSL: Set-up complete.\n");
2871 }
2872
dce110_enable_per_frame_crtc_position_reset(struct dc * dc,int group_size,struct pipe_ctx * grouped_pipes[])2873 static void dce110_enable_per_frame_crtc_position_reset(
2874 struct dc *dc,
2875 int group_size,
2876 struct pipe_ctx *grouped_pipes[])
2877 {
2878 struct dcp_gsl_params gsl_params = { 0 };
2879 int i;
2880 DC_LOGGER_INIT(dc->ctx);
2881
2882 gsl_params.gsl_group = 0;
2883 gsl_params.gsl_master = 0;
2884
2885 for (i = 0; i < group_size; i++)
2886 grouped_pipes[i]->stream_res.tg->funcs->setup_global_swap_lock(
2887 grouped_pipes[i]->stream_res.tg, &gsl_params);
2888
2889 DC_SYNC_INFO("GSL: enabling trigger-reset\n");
2890
2891 for (i = 1; i < group_size; i++)
2892 grouped_pipes[i]->stream_res.tg->funcs->enable_crtc_reset(
2893 grouped_pipes[i]->stream_res.tg,
2894 gsl_params.gsl_master,
2895 &grouped_pipes[i]->stream->triggered_crtc_reset);
2896
2897 DC_SYNC_INFO("GSL: waiting for reset to occur.\n");
2898 for (i = 1; i < group_size; i++)
2899 wait_for_reset_trigger_to_occur(dc_ctx, grouped_pipes[i]->stream_res.tg);
2900
2901 for (i = 0; i < group_size; i++)
2902 grouped_pipes[i]->stream_res.tg->funcs->tear_down_global_swap_lock(grouped_pipes[i]->stream_res.tg);
2903
2904 }
2905
dce110_init_pipes(struct dc * dc,struct dc_state * context)2906 static void dce110_init_pipes(struct dc *dc, struct dc_state *context)
2907 {
2908 (void)context;
2909 (void)dc;
2910 // Do nothing
2911 }
2912
dce110_init_hw(struct dc * dc)2913 static void dce110_init_hw(struct dc *dc)
2914 {
2915 int i;
2916 struct dc_bios *bp;
2917 struct transform *xfm;
2918 struct abm *abm;
2919 struct dmcu *dmcu;
2920 struct dce_hwseq *hws = dc->hwseq;
2921 uint32_t backlight = MAX_BACKLIGHT_LEVEL;
2922 uint32_t user_level = MAX_BACKLIGHT_LEVEL;
2923
2924 bp = dc->ctx->dc_bios;
2925 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2926 xfm = dc->res_pool->transforms[i];
2927 xfm->funcs->transform_reset(xfm);
2928
2929 hws->funcs.enable_display_power_gating(
2930 dc, i, bp,
2931 PIPE_GATING_CONTROL_INIT);
2932 hws->funcs.enable_display_power_gating(
2933 dc, i, bp,
2934 PIPE_GATING_CONTROL_DISABLE);
2935 hws->funcs.enable_display_pipe_clock_gating(
2936 dc->ctx,
2937 true);
2938 }
2939
2940 dce_clock_gating_power_up(dc->hwseq, false);
2941 /***************************************/
2942
2943 for (i = 0; i < dc->link_count; i++) {
2944 /****************************************/
2945 /* Power up AND update implementation according to the
2946 * required signal (which may be different from the
2947 * default signal on connector). */
2948 struct dc_link *link = dc->links[i];
2949
2950 link->link_enc->funcs->hw_init(link->link_enc);
2951 }
2952
2953 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2954 struct timing_generator *tg = dc->res_pool->timing_generators[i];
2955
2956 tg->funcs->disable_vga(tg);
2957
2958 /* Blank controller using driver code instead of
2959 * command table. */
2960 tg->funcs->set_blank(tg, true);
2961 hwss_wait_for_blank_complete(tg);
2962 }
2963
2964 for (i = 0; i < dc->res_pool->audio_count; i++) {
2965 struct audio *audio = dc->res_pool->audios[i];
2966 audio->funcs->hw_init(audio);
2967 }
2968
2969 for (i = 0; i < dc->link_count; i++) {
2970 struct dc_link *link = dc->links[i];
2971
2972 if (link->panel_cntl) {
2973 backlight = link->panel_cntl->funcs->hw_init(link->panel_cntl);
2974 user_level = link->panel_cntl->stored_backlight_registers.USER_LEVEL;
2975 }
2976 }
2977
2978 abm = dc->res_pool->abm;
2979 if (abm != NULL)
2980 abm->funcs->abm_init(abm, backlight, user_level);
2981
2982 dmcu = dc->res_pool->dmcu;
2983 if (dmcu != NULL && abm != NULL)
2984 abm->dmcu_is_running = dmcu->funcs->is_dmcu_initialized(dmcu);
2985
2986 if (dc->fbc_compressor)
2987 dc->fbc_compressor->funcs->power_up_fbc(dc->fbc_compressor);
2988
2989 }
2990
2991
dce110_prepare_bandwidth(struct dc * dc,struct dc_state * context)2992 void dce110_prepare_bandwidth(
2993 struct dc *dc,
2994 struct dc_state *context)
2995 {
2996 struct clk_mgr *dccg = dc->clk_mgr;
2997
2998 dce110_set_safe_displaymarks(&context->res_ctx, dc->res_pool);
2999 if (dccg)
3000 dccg->funcs->update_clocks(
3001 dccg,
3002 context,
3003 false);
3004 }
3005
dce110_optimize_bandwidth(struct dc * dc,struct dc_state * context)3006 void dce110_optimize_bandwidth(
3007 struct dc *dc,
3008 struct dc_state *context)
3009 {
3010 struct clk_mgr *dccg = dc->clk_mgr;
3011
3012 dce110_set_displaymarks(dc, context);
3013
3014 if (dccg)
3015 dccg->funcs->update_clocks(
3016 dccg,
3017 context,
3018 true);
3019 }
3020
dce110_program_front_end_for_pipe(struct dc * dc,struct pipe_ctx * pipe_ctx)3021 static void dce110_program_front_end_for_pipe(
3022 struct dc *dc, struct pipe_ctx *pipe_ctx)
3023 {
3024 struct mem_input *mi = pipe_ctx->plane_res.mi;
3025 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
3026 struct xfm_grph_csc_adjustment adjust;
3027 struct out_csc_color_matrix tbl_entry;
3028 unsigned int i;
3029 struct dce_hwseq *hws = dc->hwseq;
3030
3031 memset(&tbl_entry, 0, sizeof(tbl_entry));
3032
3033 memset(&adjust, 0, sizeof(adjust));
3034 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS;
3035
3036 dce_enable_fe_clock(dc->hwseq, mi->inst, true);
3037
3038 set_default_colors(pipe_ctx);
3039 if (pipe_ctx->stream->csc_color_matrix.enable_adjustment
3040 == true) {
3041 tbl_entry.color_space =
3042 pipe_ctx->stream->output_color_space;
3043
3044 for (i = 0; i < 12; i++)
3045 tbl_entry.regval[i] =
3046 pipe_ctx->stream->csc_color_matrix.matrix[i];
3047
3048 pipe_ctx->plane_res.xfm->funcs->opp_set_csc_adjustment
3049 (pipe_ctx->plane_res.xfm, &tbl_entry);
3050 }
3051
3052 if (pipe_ctx->stream->gamut_remap_matrix.enable_remap == true) {
3053 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_SW;
3054
3055 for (i = 0; i < CSC_TEMPERATURE_MATRIX_SIZE; i++)
3056 adjust.temperature_matrix[i] =
3057 pipe_ctx->stream->gamut_remap_matrix.matrix[i];
3058 }
3059
3060 pipe_ctx->plane_res.xfm->funcs->transform_set_gamut_remap(pipe_ctx->plane_res.xfm, &adjust);
3061
3062 pipe_ctx->plane_res.scl_data.lb_params.alpha_en = pipe_ctx->bottom_pipe != NULL;
3063
3064 program_scaler(dc, pipe_ctx);
3065
3066 mi->funcs->mem_input_program_surface_config(
3067 mi,
3068 plane_state->format,
3069 &plane_state->tiling_info,
3070 &plane_state->plane_size,
3071 plane_state->rotation,
3072 NULL,
3073 false);
3074 if (mi->funcs->set_blank)
3075 mi->funcs->set_blank(mi, pipe_ctx->plane_state->visible);
3076
3077 if (dc->config.gpu_vm_support)
3078 mi->funcs->mem_input_program_pte_vm(
3079 pipe_ctx->plane_res.mi,
3080 plane_state->format,
3081 &plane_state->tiling_info,
3082 plane_state->rotation);
3083
3084 /* Moved programming gamma from dc to hwss */
3085 if (pipe_ctx->plane_state->update_flags.bits.full_update ||
3086 pipe_ctx->plane_state->update_flags.bits.in_transfer_func_change ||
3087 pipe_ctx->plane_state->update_flags.bits.gamma_change)
3088 hws->funcs.set_input_transfer_func(dc, pipe_ctx, pipe_ctx->plane_state);
3089
3090 if (pipe_ctx->plane_state->update_flags.bits.full_update)
3091 hws->funcs.set_output_transfer_func(dc, pipe_ctx, pipe_ctx->stream);
3092
3093 DC_LOG_SURFACE(
3094 "Pipe:%d %p: addr hi:0x%x, "
3095 "addr low:0x%x, "
3096 "src: %d, %d, %d,"
3097 " %d; dst: %d, %d, %d, %d;"
3098 "clip: %d, %d, %d, %d\n",
3099 pipe_ctx->pipe_idx,
3100 (void *) pipe_ctx->plane_state,
3101 pipe_ctx->plane_state->address.grph.addr.high_part,
3102 pipe_ctx->plane_state->address.grph.addr.low_part,
3103 pipe_ctx->plane_state->src_rect.x,
3104 pipe_ctx->plane_state->src_rect.y,
3105 pipe_ctx->plane_state->src_rect.width,
3106 pipe_ctx->plane_state->src_rect.height,
3107 pipe_ctx->plane_state->dst_rect.x,
3108 pipe_ctx->plane_state->dst_rect.y,
3109 pipe_ctx->plane_state->dst_rect.width,
3110 pipe_ctx->plane_state->dst_rect.height,
3111 pipe_ctx->plane_state->clip_rect.x,
3112 pipe_ctx->plane_state->clip_rect.y,
3113 pipe_ctx->plane_state->clip_rect.width,
3114 pipe_ctx->plane_state->clip_rect.height);
3115
3116 DC_LOG_SURFACE(
3117 "Pipe %d: width, height, x, y\n"
3118 "viewport:%d, %d, %d, %d\n"
3119 "recout: %d, %d, %d, %d\n",
3120 pipe_ctx->pipe_idx,
3121 pipe_ctx->plane_res.scl_data.viewport.width,
3122 pipe_ctx->plane_res.scl_data.viewport.height,
3123 pipe_ctx->plane_res.scl_data.viewport.x,
3124 pipe_ctx->plane_res.scl_data.viewport.y,
3125 pipe_ctx->plane_res.scl_data.recout.width,
3126 pipe_ctx->plane_res.scl_data.recout.height,
3127 pipe_ctx->plane_res.scl_data.recout.x,
3128 pipe_ctx->plane_res.scl_data.recout.y);
3129 }
3130
dce110_apply_ctx_for_surface(struct dc * dc,const struct dc_stream_state * stream,int num_planes,struct dc_state * context)3131 static void dce110_apply_ctx_for_surface(
3132 struct dc *dc,
3133 const struct dc_stream_state *stream,
3134 int num_planes,
3135 struct dc_state *context)
3136 {
3137 int i;
3138
3139 if (num_planes == 0)
3140 return;
3141
3142 if (dc->fbc_compressor)
3143 dc->fbc_compressor->funcs->disable_fbc(dc->fbc_compressor);
3144
3145 for (i = 0; i < dc->res_pool->pipe_count; i++) {
3146 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
3147
3148 if (pipe_ctx->stream != stream)
3149 continue;
3150
3151 /* Need to allocate mem before program front end for Fiji */
3152 pipe_ctx->plane_res.mi->funcs->allocate_mem_input(
3153 pipe_ctx->plane_res.mi,
3154 pipe_ctx->stream->timing.h_total,
3155 pipe_ctx->stream->timing.v_total,
3156 pipe_ctx->stream->timing.pix_clk_100hz / 10,
3157 context->stream_count);
3158
3159 dce110_program_front_end_for_pipe(dc, pipe_ctx);
3160
3161 dc->hwss.update_plane_addr(dc, pipe_ctx);
3162
3163 program_surface_visibility(dc, pipe_ctx);
3164
3165 }
3166
3167 if (dc->fbc_compressor)
3168 enable_fbc(dc, context);
3169 }
3170
dce110_post_unlock_program_front_end(struct dc * dc,struct dc_state * context)3171 static void dce110_post_unlock_program_front_end(
3172 struct dc *dc,
3173 struct dc_state *context)
3174 {
3175 (void)dc;
3176 (void)context;
3177 }
3178
dce110_power_down_fe(struct dc * dc,struct dc_state * state,struct pipe_ctx * pipe_ctx)3179 static void dce110_power_down_fe(struct dc *dc, struct dc_state *state, struct pipe_ctx *pipe_ctx)
3180 {
3181 (void)state;
3182 struct dce_hwseq *hws = dc->hwseq;
3183 int fe_idx = pipe_ctx->plane_res.mi ?
3184 pipe_ctx->plane_res.mi->inst : pipe_ctx->pipe_idx;
3185
3186 /* Do not power down fe when stream is active on dce*/
3187 if (dc->current_state->res_ctx.pipe_ctx[fe_idx].stream)
3188 return;
3189
3190 hws->funcs.enable_display_power_gating(
3191 dc, fe_idx, dc->ctx->dc_bios, PIPE_GATING_CONTROL_ENABLE);
3192
3193 dc->res_pool->transforms[fe_idx]->funcs->transform_reset(
3194 dc->res_pool->transforms[fe_idx]);
3195 }
3196
dce110_wait_for_mpcc_disconnect(struct dc * dc,struct resource_pool * res_pool,struct pipe_ctx * pipe_ctx)3197 static void dce110_wait_for_mpcc_disconnect(
3198 struct dc *dc,
3199 struct resource_pool *res_pool,
3200 struct pipe_ctx *pipe_ctx)
3201 {
3202 (void)dc;
3203 (void)res_pool;
3204 (void)pipe_ctx;
3205 /* do nothing*/
3206 }
3207
program_output_csc(struct dc * dc,struct pipe_ctx * pipe_ctx,enum dc_color_space colorspace,uint16_t * matrix,int opp_id)3208 static void program_output_csc(struct dc *dc,
3209 struct pipe_ctx *pipe_ctx,
3210 enum dc_color_space colorspace,
3211 uint16_t *matrix,
3212 int opp_id)
3213 {
3214 (void)dc;
3215 (void)colorspace;
3216 (void)matrix;
3217 (void)opp_id;
3218 int i;
3219 struct out_csc_color_matrix tbl_entry;
3220
3221 if (pipe_ctx->stream->csc_color_matrix.enable_adjustment == true) {
3222 enum dc_color_space color_space = pipe_ctx->stream->output_color_space;
3223
3224 for (i = 0; i < 12; i++)
3225 tbl_entry.regval[i] = pipe_ctx->stream->csc_color_matrix.matrix[i];
3226
3227 tbl_entry.color_space = color_space;
3228
3229 pipe_ctx->plane_res.xfm->funcs->opp_set_csc_adjustment(
3230 pipe_ctx->plane_res.xfm, &tbl_entry);
3231 }
3232 }
3233
dce110_set_cursor_position(struct pipe_ctx * pipe_ctx)3234 static void dce110_set_cursor_position(struct pipe_ctx *pipe_ctx)
3235 {
3236 struct dc_cursor_position pos_cpy = pipe_ctx->stream->cursor_position;
3237 struct input_pixel_processor *ipp = pipe_ctx->plane_res.ipp;
3238 struct mem_input *mi = pipe_ctx->plane_res.mi;
3239 struct dc_cursor_mi_param param = {
3240 .pixel_clk_khz = pipe_ctx->stream->timing.pix_clk_100hz / 10,
3241 .ref_clk_khz = pipe_ctx->stream->ctx->dc->res_pool->ref_clocks.xtalin_clock_inKhz,
3242 .viewport = pipe_ctx->plane_res.scl_data.viewport,
3243 .h_scale_ratio = pipe_ctx->plane_res.scl_data.ratios.horz,
3244 .v_scale_ratio = pipe_ctx->plane_res.scl_data.ratios.vert,
3245 .rotation = pipe_ctx->plane_state->rotation,
3246 .mirror = pipe_ctx->plane_state->horizontal_mirror
3247 };
3248
3249 /**
3250 * If the cursor's source viewport is clipped then we need to
3251 * translate the cursor to appear in the correct position on
3252 * the screen.
3253 *
3254 * This translation isn't affected by scaling so it needs to be
3255 * done *after* we adjust the position for the scale factor.
3256 *
3257 * This is only done by opt-in for now since there are still
3258 * some usecases like tiled display that might enable the
3259 * cursor on both streams while expecting dc to clip it.
3260 */
3261 if (pos_cpy.translate_by_source) {
3262 pos_cpy.x += pipe_ctx->plane_state->src_rect.x;
3263 pos_cpy.y += pipe_ctx->plane_state->src_rect.y;
3264 }
3265
3266 if (pipe_ctx->plane_state->address.type
3267 == PLN_ADDR_TYPE_VIDEO_PROGRESSIVE)
3268 pos_cpy.enable = false;
3269
3270 if (pipe_ctx->top_pipe && pipe_ctx->plane_state != pipe_ctx->top_pipe->plane_state)
3271 pos_cpy.enable = false;
3272
3273 if (ipp->funcs->ipp_cursor_set_position)
3274 ipp->funcs->ipp_cursor_set_position(ipp, &pos_cpy, ¶m);
3275 if (mi->funcs->set_cursor_position)
3276 mi->funcs->set_cursor_position(mi, &pos_cpy, ¶m);
3277 }
3278
dce110_set_cursor_attribute(struct pipe_ctx * pipe_ctx)3279 static void dce110_set_cursor_attribute(struct pipe_ctx *pipe_ctx)
3280 {
3281 struct dc_cursor_attributes *attributes = &pipe_ctx->stream->cursor_attributes;
3282
3283 if (pipe_ctx->plane_res.ipp &&
3284 pipe_ctx->plane_res.ipp->funcs->ipp_cursor_set_attributes)
3285 pipe_ctx->plane_res.ipp->funcs->ipp_cursor_set_attributes(
3286 pipe_ctx->plane_res.ipp, attributes);
3287
3288 if (pipe_ctx->plane_res.mi &&
3289 pipe_ctx->plane_res.mi->funcs->set_cursor_attributes)
3290 pipe_ctx->plane_res.mi->funcs->set_cursor_attributes(
3291 pipe_ctx->plane_res.mi, attributes);
3292
3293 if (pipe_ctx->plane_res.xfm &&
3294 pipe_ctx->plane_res.xfm->funcs->set_cursor_attributes)
3295 pipe_ctx->plane_res.xfm->funcs->set_cursor_attributes(
3296 pipe_ctx->plane_res.xfm, attributes);
3297 }
3298
dce110_set_backlight_level(struct pipe_ctx * pipe_ctx,struct set_backlight_level_params * backlight_level_params)3299 bool dce110_set_backlight_level(struct pipe_ctx *pipe_ctx,
3300 struct set_backlight_level_params *backlight_level_params)
3301 {
3302 uint32_t backlight_pwm_u16_16 = backlight_level_params->backlight_pwm_u16_16;
3303 uint32_t frame_ramp = backlight_level_params->frame_ramp;
3304 struct dc_link *link = pipe_ctx->stream->link;
3305 struct dc *dc = link->ctx->dc;
3306 struct abm *abm = pipe_ctx->stream_res.abm;
3307 struct panel_cntl *panel_cntl = link->panel_cntl;
3308 struct dmcu *dmcu = dc->res_pool->dmcu;
3309 bool fw_set_brightness = true;
3310 /* DMCU -1 for all controller id values,
3311 * therefore +1 here
3312 */
3313 uint32_t controller_id = pipe_ctx->stream_res.tg->inst + 1;
3314
3315 if (abm == NULL || panel_cntl == NULL || (abm->funcs->set_backlight_level_pwm == NULL))
3316 return false;
3317
3318 if (dmcu)
3319 fw_set_brightness = dmcu->funcs->is_dmcu_initialized(dmcu);
3320
3321 if (!fw_set_brightness && panel_cntl->funcs->driver_set_backlight)
3322 panel_cntl->funcs->driver_set_backlight(panel_cntl, backlight_pwm_u16_16);
3323 else
3324 abm->funcs->set_backlight_level_pwm(
3325 abm,
3326 backlight_pwm_u16_16,
3327 frame_ramp,
3328 controller_id,
3329 link->panel_cntl->inst);
3330
3331 return true;
3332 }
3333
dce110_set_abm_immediate_disable(struct pipe_ctx * pipe_ctx)3334 void dce110_set_abm_immediate_disable(struct pipe_ctx *pipe_ctx)
3335 {
3336 struct abm *abm = pipe_ctx->stream_res.abm;
3337 struct panel_cntl *panel_cntl = pipe_ctx->stream->link->panel_cntl;
3338
3339 if (abm)
3340 abm->funcs->set_abm_immediate_disable(abm,
3341 pipe_ctx->stream->link->panel_cntl->inst);
3342
3343 if (panel_cntl)
3344 panel_cntl->funcs->store_backlight_level(panel_cntl);
3345 }
3346
dce110_set_pipe(struct pipe_ctx * pipe_ctx)3347 void dce110_set_pipe(struct pipe_ctx *pipe_ctx)
3348 {
3349 struct abm *abm = pipe_ctx->stream_res.abm;
3350 struct panel_cntl *panel_cntl = pipe_ctx->stream->link->panel_cntl;
3351 uint32_t otg_inst = pipe_ctx->stream_res.tg->inst + 1;
3352
3353 if (abm && panel_cntl)
3354 abm->funcs->set_pipe(abm, otg_inst, panel_cntl->inst);
3355 }
3356
dce110_enable_lvds_link_output(struct dc_link * link,const struct link_resource * link_res,enum clock_source_id clock_source,uint32_t pixel_clock)3357 void dce110_enable_lvds_link_output(struct dc_link *link,
3358 const struct link_resource *link_res,
3359 enum clock_source_id clock_source,
3360 uint32_t pixel_clock)
3361 {
3362 (void)link_res;
3363 link->link_enc->funcs->enable_lvds_output(
3364 link->link_enc,
3365 clock_source,
3366 pixel_clock);
3367 link->phy_state.symclk_state = SYMCLK_ON_TX_ON;
3368 }
3369
dce110_enable_tmds_link_output(struct dc_link * link,const struct link_resource * link_res,enum signal_type signal,enum clock_source_id clock_source,enum dc_color_depth color_depth,uint32_t pixel_clock)3370 void dce110_enable_tmds_link_output(struct dc_link *link,
3371 const struct link_resource *link_res,
3372 enum signal_type signal,
3373 enum clock_source_id clock_source,
3374 enum dc_color_depth color_depth,
3375 uint32_t pixel_clock)
3376 {
3377 (void)link_res;
3378 link->link_enc->funcs->enable_tmds_output(
3379 link->link_enc,
3380 clock_source,
3381 color_depth,
3382 signal,
3383 pixel_clock);
3384 link->phy_state.symclk_state = SYMCLK_ON_TX_ON;
3385 }
3386
dce110_enable_analog_link_output(struct dc_link * link,uint32_t pix_clk_100hz)3387 static void dce110_enable_analog_link_output(
3388 struct dc_link *link,
3389 uint32_t pix_clk_100hz)
3390 {
3391 link->link_enc->funcs->enable_analog_output(
3392 link->link_enc,
3393 pix_clk_100hz);
3394 }
3395
dce110_enable_dp_link_output(struct dc_link * link,const struct link_resource * link_res,enum signal_type signal,enum clock_source_id clock_source,const struct dc_link_settings * link_settings)3396 void dce110_enable_dp_link_output(
3397 struct dc_link *link,
3398 const struct link_resource *link_res,
3399 enum signal_type signal,
3400 enum clock_source_id clock_source,
3401 const struct dc_link_settings *link_settings)
3402 {
3403 struct dc *dc = link->ctx->dc;
3404 struct dmcu *dmcu = dc->res_pool->dmcu;
3405 struct pipe_ctx *pipes =
3406 link->dc->current_state->res_ctx.pipe_ctx;
3407 struct clock_source *dp_cs =
3408 link->dc->res_pool->dp_clock_source;
3409 const struct link_hwss *link_hwss = get_link_hwss(link, link_res);
3410 unsigned int i;
3411
3412 /*
3413 * Add the logic to extract BOTH power up and power down sequences
3414 * from enable/disable link output and only call edp panel control
3415 * in enable_link_dp and disable_link_dp once.
3416 */
3417 if (link->connector_signal == SIGNAL_TYPE_EDP) {
3418 link->dc->hwss.edp_wait_for_hpd_ready(link, true);
3419 }
3420
3421 /* If the current pixel clock source is not DTO(happens after
3422 * switching from HDMI passive dongle to DP on the same connector),
3423 * switch the pixel clock source to DTO.
3424 */
3425
3426 for (i = 0; i < MAX_PIPES; i++) {
3427 if (pipes[i].stream != NULL &&
3428 pipes[i].stream->link == link) {
3429 if (pipes[i].clock_source != NULL &&
3430 pipes[i].clock_source->id != CLOCK_SOURCE_ID_DP_DTO) {
3431 pipes[i].clock_source = dp_cs;
3432 pipes[i].stream_res.pix_clk_params.requested_pix_clk_100hz =
3433 pipes[i].stream->timing.pix_clk_100hz;
3434 pipes[i].clock_source->funcs->program_pix_clk(
3435 pipes[i].clock_source,
3436 &pipes[i].stream_res.pix_clk_params,
3437 dc->link_srv->dp_get_encoding_format(link_settings),
3438 &pipes[i].pll_settings);
3439 }
3440 }
3441 }
3442
3443 if (link->ext_enc_id.id) {
3444 dce110_external_encoder_control(EXTERNAL_ENCODER_CONTROL_INIT, link, NULL);
3445 dce110_external_encoder_control(EXTERNAL_ENCODER_CONTROL_SETUP, link, NULL);
3446 }
3447
3448 if (dc->link_srv->dp_get_encoding_format(link_settings) == DP_8b_10b_ENCODING) {
3449 if (dc->clk_mgr->funcs->notify_link_rate_change)
3450 dc->clk_mgr->funcs->notify_link_rate_change(dc->clk_mgr, link);
3451 }
3452
3453 if (dmcu != NULL && dmcu->funcs->lock_phy)
3454 dmcu->funcs->lock_phy(dmcu);
3455
3456 if (link_hwss->ext.enable_dp_link_output)
3457 link_hwss->ext.enable_dp_link_output(link, link_res, signal,
3458 clock_source, link_settings);
3459
3460 link->phy_state.symclk_state = SYMCLK_ON_TX_ON;
3461
3462 if (dmcu != NULL && dmcu->funcs->unlock_phy)
3463 dmcu->funcs->unlock_phy(dmcu);
3464
3465 dc->link_srv->dp_trace_source_sequence(link, DPCD_SOURCE_SEQ_AFTER_ENABLE_LINK_PHY);
3466 }
3467
dce110_disable_link_output(struct dc_link * link,const struct link_resource * link_res,enum signal_type signal)3468 void dce110_disable_link_output(struct dc_link *link,
3469 const struct link_resource *link_res,
3470 enum signal_type signal)
3471 {
3472 struct dc *dc = link->ctx->dc;
3473 const struct link_hwss *link_hwss = get_link_hwss(link, link_res);
3474 struct dmcu *dmcu = dc->res_pool->dmcu;
3475
3476 if (signal == SIGNAL_TYPE_EDP &&
3477 link->dc->hwss.edp_backlight_control &&
3478 !link->skip_implict_edp_power_control)
3479 link->dc->hwss.edp_backlight_control(link, false);
3480 else if (dmcu != NULL && dmcu->funcs->lock_phy)
3481 dmcu->funcs->lock_phy(dmcu);
3482
3483 link_hwss->disable_link_output(link, link_res, signal);
3484 link->phy_state.symclk_state = SYMCLK_OFF_TX_OFF;
3485 /*
3486 * Add the logic to extract BOTH power up and power down sequences
3487 * from enable/disable link output and only call edp panel control
3488 * in enable_link_dp and disable_link_dp once.
3489 */
3490 if (dmcu != NULL && dmcu->funcs->unlock_phy)
3491 dmcu->funcs->unlock_phy(dmcu);
3492 dc->link_srv->dp_trace_source_sequence(link, DPCD_SOURCE_SEQ_AFTER_DISABLE_LINK_PHY);
3493 }
3494
3495 static const struct hw_sequencer_funcs dce110_funcs = {
3496 .program_gamut_remap = program_gamut_remap,
3497 .program_output_csc = program_output_csc,
3498 .init_hw = dce110_init_hw,
3499 .apply_ctx_to_hw = dce110_apply_ctx_to_hw,
3500 .apply_ctx_for_surface = dce110_apply_ctx_for_surface,
3501 .post_unlock_program_front_end = dce110_post_unlock_program_front_end,
3502 .update_plane_addr = update_plane_addr,
3503 .update_pending_status = dce110_update_pending_status,
3504 .clear_surface_dcc_and_tiling = dce100_reset_surface_dcc_and_tiling,
3505 .enable_accelerated_mode = dce110_enable_accelerated_mode,
3506 .enable_timing_synchronization = dce110_enable_timing_synchronization,
3507 .enable_per_frame_crtc_position_reset = dce110_enable_per_frame_crtc_position_reset,
3508 .update_info_frame = dce110_update_info_frame,
3509 .enable_stream = dce110_enable_stream,
3510 .disable_stream = dce110_disable_stream,
3511 .unblank_stream = dce110_unblank_stream,
3512 .blank_stream = dce110_blank_stream,
3513 .enable_audio_stream = dce110_enable_audio_stream,
3514 .disable_audio_stream = dce110_disable_audio_stream,
3515 .disable_plane = dce110_power_down_fe,
3516 .pipe_control_lock = dce_pipe_control_lock,
3517 .interdependent_update_lock = NULL,
3518 .cursor_lock = dce_pipe_control_lock,
3519 .prepare_bandwidth = dce110_prepare_bandwidth,
3520 .optimize_bandwidth = dce110_optimize_bandwidth,
3521 .set_drr = set_drr,
3522 .get_position = get_position,
3523 .set_static_screen_control = set_static_screen_control,
3524 .setup_stereo = NULL,
3525 .set_avmute = dce110_set_avmute,
3526 .wait_for_mpcc_disconnect = dce110_wait_for_mpcc_disconnect,
3527 .edp_backlight_control = dce110_edp_backlight_control,
3528 .edp_power_control = dce110_edp_power_control,
3529 .edp_wait_for_hpd_ready = dce110_edp_wait_for_hpd_ready,
3530 .set_cursor_position = dce110_set_cursor_position,
3531 .set_cursor_attribute = dce110_set_cursor_attribute,
3532 .set_backlight_level = dce110_set_backlight_level,
3533 .set_abm_immediate_disable = dce110_set_abm_immediate_disable,
3534 .set_pipe = dce110_set_pipe,
3535 .enable_lvds_link_output = dce110_enable_lvds_link_output,
3536 .enable_tmds_link_output = dce110_enable_tmds_link_output,
3537 .enable_dp_link_output = dce110_enable_dp_link_output,
3538 .enable_analog_link_output = dce110_enable_analog_link_output,
3539 .disable_link_output = dce110_disable_link_output,
3540 .dac_load_detect = dce110_dac_load_detect,
3541 .prepare_ddc = dce110_prepare_ddc,
3542 };
3543
3544 static const struct hwseq_private_funcs dce110_private_funcs = {
3545 .init_pipes = dce110_init_pipes,
3546 .set_input_transfer_func = dce110_set_input_transfer_func,
3547 .set_output_transfer_func = dce110_set_output_transfer_func,
3548 .power_down = dce110_power_down,
3549 .enable_display_pipe_clock_gating = enable_display_pipe_clock_gating,
3550 .enable_display_power_gating = dce110_enable_display_power_gating,
3551 .reset_hw_ctx_wrap = dce110_reset_hw_ctx_wrap,
3552 .enable_stream_timing = dce110_enable_stream_timing,
3553 .disable_stream_gating = NULL,
3554 .enable_stream_gating = NULL,
3555 .edp_backlight_control = dce110_edp_backlight_control,
3556 };
3557
dce110_hw_sequencer_construct(struct dc * dc)3558 void dce110_hw_sequencer_construct(struct dc *dc)
3559 {
3560 dc->hwss = dce110_funcs;
3561 dc->hwseq->funcs = dce110_private_funcs;
3562 }
3563
3564