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