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