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
1122 pipe_ctx->stream_res.audio->funcs->az_enable(pipe_ctx->stream_res.audio);
1123
1124 if (num_audio >= 1 && clk_mgr->funcs->enable_pme_wa)
1125 /*this is the first audio. apply the PME w/a in order to wake AZ from D3*/
1126 clk_mgr->funcs->enable_pme_wa(clk_mgr);
1127
1128 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.feed_back_divider =
1488 pipe_ctx->pll_settings.feedback_divider;
1489
1490 audio_output->pll_info.dto_source =
1491 translate_to_dto_source(
1492 pipe_ctx->stream_res.tg->inst + 1);
1493
1494 /* TODO hard code to enable for now. Need get from stream */
1495 audio_output->pll_info.ss_enabled = true;
1496
1497 audio_output->pll_info.ss_percentage =
1498 pipe_ctx->pll_settings.ss_percentage;
1499
1500 if (dc_is_dp_signal(pipe_ctx->stream->signal)) {
1501 populate_audio_dp_link_info(pipe_ctx, &audio_output->dp_link_info);
1502 }
1503 }
1504
program_scaler(const struct dc * dc,const struct pipe_ctx * pipe_ctx)1505 static void program_scaler(const struct dc *dc,
1506 const struct pipe_ctx *pipe_ctx)
1507 {
1508 struct tg_color color = {0};
1509
1510 /* TOFPGA */
1511 if (pipe_ctx->plane_res.xfm->funcs->transform_set_pixel_storage_depth == NULL)
1512 return;
1513
1514 if (dc->debug.visual_confirm == VISUAL_CONFIRM_SURFACE)
1515 get_surface_visual_confirm_color(pipe_ctx, &color);
1516 else
1517 color_space_to_black_color(dc,
1518 pipe_ctx->stream->output_color_space,
1519 &color);
1520
1521 pipe_ctx->plane_res.xfm->funcs->transform_set_pixel_storage_depth(
1522 pipe_ctx->plane_res.xfm,
1523 pipe_ctx->plane_res.scl_data.lb_params.depth,
1524 &pipe_ctx->stream->bit_depth_params);
1525
1526 if (pipe_ctx->stream_res.tg->funcs->set_overscan_blank_color) {
1527 /*
1528 * The way 420 is packed, 2 channels carry Y component, 1 channel
1529 * alternate between Cb and Cr, so both channels need the pixel
1530 * value for Y
1531 */
1532 if (pipe_ctx->stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR420)
1533 color.color_r_cr = color.color_g_y;
1534
1535 pipe_ctx->stream_res.tg->funcs->set_overscan_blank_color(
1536 pipe_ctx->stream_res.tg,
1537 &color);
1538 }
1539
1540 pipe_ctx->plane_res.xfm->funcs->transform_set_scaler(pipe_ctx->plane_res.xfm,
1541 &pipe_ctx->plane_res.scl_data);
1542 }
1543
dce110_enable_stream_timing(struct pipe_ctx * pipe_ctx,struct dc_state * context,struct dc * dc)1544 static enum dc_status dce110_enable_stream_timing(
1545 struct pipe_ctx *pipe_ctx,
1546 struct dc_state *context,
1547 struct dc *dc)
1548 {
1549 struct dc_stream_state *stream = pipe_ctx->stream;
1550 struct pipe_ctx *pipe_ctx_old = &dc->current_state->res_ctx.
1551 pipe_ctx[pipe_ctx->pipe_idx];
1552 struct tg_color black_color = {0};
1553
1554 if (!pipe_ctx_old->stream) {
1555
1556 /* program blank color */
1557 color_space_to_black_color(dc,
1558 stream->output_color_space, &black_color);
1559 pipe_ctx->stream_res.tg->funcs->set_blank_color(
1560 pipe_ctx->stream_res.tg,
1561 &black_color);
1562
1563 /*
1564 * Must blank CRTC after disabling power gating and before any
1565 * programming, otherwise CRTC will be hung in bad state
1566 */
1567 pipe_ctx->stream_res.tg->funcs->set_blank(pipe_ctx->stream_res.tg, true);
1568
1569 if (false == pipe_ctx->clock_source->funcs->program_pix_clk(
1570 pipe_ctx->clock_source,
1571 &pipe_ctx->stream_res.pix_clk_params,
1572 dc->link_srv->dp_get_encoding_format(&pipe_ctx->link_config.dp_link_settings),
1573 &pipe_ctx->pll_settings)) {
1574 BREAK_TO_DEBUGGER();
1575 return DC_ERROR_UNEXPECTED;
1576 }
1577
1578 if (dc_is_hdmi_tmds_signal(stream->signal)) {
1579 stream->link->phy_state.symclk_ref_cnts.otg = 1;
1580 if (stream->link->phy_state.symclk_state == SYMCLK_OFF_TX_OFF)
1581 stream->link->phy_state.symclk_state = SYMCLK_ON_TX_OFF;
1582 else
1583 stream->link->phy_state.symclk_state = SYMCLK_ON_TX_ON;
1584 }
1585
1586 pipe_ctx->stream_res.tg->funcs->program_timing(
1587 pipe_ctx->stream_res.tg,
1588 &stream->timing,
1589 0,
1590 0,
1591 0,
1592 0,
1593 0,
1594 pipe_ctx->stream->signal,
1595 true);
1596 }
1597
1598 if (!pipe_ctx_old->stream) {
1599 if (false == pipe_ctx->stream_res.tg->funcs->enable_crtc(
1600 pipe_ctx->stream_res.tg)) {
1601 BREAK_TO_DEBUGGER();
1602 return DC_ERROR_UNEXPECTED;
1603 }
1604 }
1605
1606 return DC_OK;
1607 }
1608
1609 static void
dce110_select_crtc_source(struct pipe_ctx * pipe_ctx)1610 dce110_select_crtc_source(struct pipe_ctx *pipe_ctx)
1611 {
1612 struct dc_link *link = pipe_ctx->stream->link;
1613 struct dc_bios *bios = link->ctx->dc_bios;
1614 struct bp_crtc_source_select crtc_source_select = {0};
1615 enum engine_id engine_id = link->link_enc->preferred_engine;
1616 uint8_t bit_depth;
1617
1618 if (dc_is_rgb_signal(pipe_ctx->stream->signal))
1619 engine_id = link->link_enc->analog_engine;
1620
1621 switch (pipe_ctx->stream->timing.display_color_depth) {
1622 case COLOR_DEPTH_UNDEFINED:
1623 bit_depth = 0;
1624 break;
1625 case COLOR_DEPTH_666:
1626 bit_depth = 6;
1627 break;
1628 default:
1629 case COLOR_DEPTH_888:
1630 bit_depth = 8;
1631 break;
1632 case COLOR_DEPTH_101010:
1633 bit_depth = 10;
1634 break;
1635 case COLOR_DEPTH_121212:
1636 bit_depth = 12;
1637 break;
1638 case COLOR_DEPTH_141414:
1639 bit_depth = 14;
1640 break;
1641 case COLOR_DEPTH_161616:
1642 bit_depth = 16;
1643 break;
1644 }
1645
1646 crtc_source_select.controller_id = CONTROLLER_ID_D0 + pipe_ctx->stream_res.tg->inst;
1647 crtc_source_select.bit_depth = bit_depth;
1648 crtc_source_select.engine_id = engine_id;
1649 crtc_source_select.sink_signal = pipe_ctx->stream->signal;
1650
1651 bios->funcs->select_crtc_source(bios, &crtc_source_select);
1652 }
1653
dce110_apply_single_controller_ctx_to_hw(struct pipe_ctx * pipe_ctx,struct dc_state * context,struct dc * dc)1654 enum dc_status dce110_apply_single_controller_ctx_to_hw(
1655 struct pipe_ctx *pipe_ctx,
1656 struct dc_state *context,
1657 struct dc *dc)
1658 {
1659 struct dc_stream_state *stream = pipe_ctx->stream;
1660 struct dc_link *link = stream->link;
1661 struct drr_params params = {0};
1662 unsigned int event_triggers = 0;
1663 struct pipe_ctx *odm_pipe = pipe_ctx->next_odm_pipe;
1664 struct dce_hwseq *hws = dc->hwseq;
1665 const struct link_hwss *link_hwss = get_link_hwss(
1666 link, &pipe_ctx->link_res);
1667
1668
1669 if (hws->funcs.disable_stream_gating) {
1670 hws->funcs.disable_stream_gating(dc, pipe_ctx);
1671 }
1672
1673 if (pipe_ctx->stream->signal == SIGNAL_TYPE_RGB) {
1674 dce110_select_crtc_source(pipe_ctx);
1675 }
1676
1677 if (pipe_ctx->stream_res.audio != NULL) {
1678 struct audio_output audio_output = {0};
1679
1680 build_audio_output(context, pipe_ctx, &audio_output);
1681
1682 link_hwss->setup_audio_output(pipe_ctx, &audio_output,
1683 pipe_ctx->stream_res.audio->inst);
1684
1685 pipe_ctx->stream_res.audio->funcs->az_configure(
1686 pipe_ctx->stream_res.audio,
1687 pipe_ctx->stream->signal,
1688 &audio_output.crtc_info,
1689 &pipe_ctx->stream->audio_info,
1690 &audio_output.dp_link_info);
1691
1692 if (dc->config.disable_hbr_audio_dp2)
1693 if (pipe_ctx->stream_res.audio->funcs->az_disable_hbr_audio &&
1694 dc->link_srv->dp_is_128b_132b_signal(pipe_ctx))
1695 pipe_ctx->stream_res.audio->funcs->az_disable_hbr_audio(pipe_ctx->stream_res.audio);
1696 }
1697
1698 /* make sure no pipes syncd to the pipe being enabled */
1699 if (!pipe_ctx->stream->apply_seamless_boot_optimization && dc->config.use_pipe_ctx_sync_logic)
1700 check_syncd_pipes_for_disabled_master_pipe(dc, context, pipe_ctx->pipe_idx);
1701
1702 pipe_ctx->stream_res.opp->funcs->opp_program_fmt(
1703 pipe_ctx->stream_res.opp,
1704 &stream->bit_depth_params,
1705 &stream->clamping);
1706
1707 pipe_ctx->stream_res.opp->funcs->opp_set_dyn_expansion(
1708 pipe_ctx->stream_res.opp,
1709 COLOR_SPACE_YCBCR601,
1710 stream->timing.display_color_depth,
1711 stream->signal);
1712
1713 while (odm_pipe) {
1714 odm_pipe->stream_res.opp->funcs->opp_set_dyn_expansion(
1715 odm_pipe->stream_res.opp,
1716 COLOR_SPACE_YCBCR601,
1717 stream->timing.display_color_depth,
1718 stream->signal);
1719
1720 odm_pipe->stream_res.opp->funcs->opp_program_fmt(
1721 odm_pipe->stream_res.opp,
1722 &stream->bit_depth_params,
1723 &stream->clamping);
1724 odm_pipe = odm_pipe->next_odm_pipe;
1725 }
1726
1727 /* DCN3.1 FPGA Workaround
1728 * Need to enable HPO DP Stream Encoder before setting OTG master enable.
1729 * To do so, move calling function enable_stream_timing to only be done AFTER calling
1730 * function core_link_enable_stream
1731 */
1732 if (!(hws->wa.dp_hpo_and_otg_sequence && dc->link_srv->dp_is_128b_132b_signal(pipe_ctx)))
1733 /* */
1734 /* Do not touch stream timing on seamless boot optimization. */
1735 if (!pipe_ctx->stream->apply_seamless_boot_optimization)
1736 hws->funcs.enable_stream_timing(pipe_ctx, context, dc);
1737
1738 if (hws->funcs.setup_vupdate_interrupt)
1739 hws->funcs.setup_vupdate_interrupt(dc, pipe_ctx);
1740
1741 params.vertical_total_min = stream->adjust.v_total_min;
1742 params.vertical_total_max = stream->adjust.v_total_max;
1743 set_drr_and_clear_adjust_pending(pipe_ctx, stream, ¶ms);
1744
1745 // DRR should set trigger event to monitor surface update event
1746 if (stream->adjust.v_total_min != 0 && stream->adjust.v_total_max != 0)
1747 event_triggers = 0x80;
1748 /* Event triggers and num frames initialized for DRR, but can be
1749 * later updated for PSR use. Note DRR trigger events are generated
1750 * regardless of whether num frames met.
1751 */
1752 if (pipe_ctx->stream_res.tg->funcs->set_static_screen_control)
1753 pipe_ctx->stream_res.tg->funcs->set_static_screen_control(
1754 pipe_ctx->stream_res.tg, event_triggers, 2);
1755
1756 if (!dc_is_virtual_signal(pipe_ctx->stream->signal) &&
1757 !dc_is_rgb_signal(pipe_ctx->stream->signal))
1758 pipe_ctx->stream_res.stream_enc->funcs->dig_connect_to_otg(
1759 pipe_ctx->stream_res.stream_enc,
1760 pipe_ctx->stream_res.tg->inst);
1761
1762 if (dc_is_dp_signal(pipe_ctx->stream->signal))
1763 dc->link_srv->dp_trace_source_sequence(link, DPCD_SOURCE_SEQ_AFTER_CONNECT_DIG_FE_OTG);
1764
1765 /* Temporary workaround to perform DSC programming ahead of stream enablement
1766 * for smartmux/SPRS
1767 * TODO: Remove SmartMux/SPRS checks once movement of DSC programming is generalized
1768 */
1769 if (pipe_ctx->stream->timing.flags.DSC) {
1770 if ((pipe_ctx->stream->signal == SIGNAL_TYPE_EDP &&
1771 ((link->dc->config.smart_mux_version && link->dc->is_switch_in_progress_dest)
1772 || link->is_dds || link->skip_implict_edp_power_control)) &&
1773 (dc_is_dp_signal(pipe_ctx->stream->signal) ||
1774 dc_is_virtual_signal(pipe_ctx->stream->signal)))
1775 dc->link_srv->set_dsc_enable(pipe_ctx, true);
1776 }
1777
1778 if (!stream->dpms_off)
1779 dc->link_srv->set_dpms_on(context, pipe_ctx);
1780
1781 /* DCN3.1 FPGA Workaround
1782 * Need to enable HPO DP Stream Encoder before setting OTG master enable.
1783 * To do so, move calling function enable_stream_timing to only be done AFTER calling
1784 * function core_link_enable_stream
1785 */
1786 if (hws->wa.dp_hpo_and_otg_sequence && dc->link_srv->dp_is_128b_132b_signal(pipe_ctx)) {
1787 if (!pipe_ctx->stream->apply_seamless_boot_optimization)
1788 hws->funcs.enable_stream_timing(pipe_ctx, context, dc);
1789 }
1790
1791 pipe_ctx->plane_res.scl_data.lb_params.alpha_en = pipe_ctx->bottom_pipe != NULL;
1792
1793 /* Phantom and main stream share the same link (because the stream
1794 * is constructed with the same sink). Make sure not to override
1795 * and link programming on the main.
1796 */
1797 if (dc_state_get_pipe_subvp_type(context, pipe_ctx) != SUBVP_PHANTOM) {
1798 pipe_ctx->stream->link->psr_settings.psr_feature_enabled = false;
1799 pipe_ctx->stream->link->replay_settings.replay_feature_enabled = false;
1800 }
1801 return DC_OK;
1802 }
1803
1804 /******************************************************************************/
1805
power_down_encoders(struct dc * dc)1806 static void power_down_encoders(struct dc *dc)
1807 {
1808 int i;
1809
1810 for (i = 0; i < dc->link_count; i++) {
1811 enum signal_type signal = dc->links[i]->connector_signal;
1812
1813 dc->link_srv->blank_dp_stream(dc->links[i], false);
1814
1815 if (signal != SIGNAL_TYPE_EDP)
1816 signal = SIGNAL_TYPE_NONE;
1817
1818 if (dc->links[i]->ep_type == DISPLAY_ENDPOINT_PHY)
1819 dc->links[i]->link_enc->funcs->disable_output(
1820 dc->links[i]->link_enc, signal);
1821
1822 dc->links[i]->link_status.link_active = false;
1823 memset(&dc->links[i]->cur_link_settings, 0,
1824 sizeof(dc->links[i]->cur_link_settings));
1825 }
1826 }
1827
power_down_controllers(struct dc * dc)1828 static void power_down_controllers(struct dc *dc)
1829 {
1830 int i;
1831
1832 for (i = 0; i < dc->res_pool->timing_generator_count; i++) {
1833 dc->res_pool->timing_generators[i]->funcs->disable_crtc(
1834 dc->res_pool->timing_generators[i]);
1835 }
1836 }
1837
power_down_clock_sources(struct dc * dc)1838 static void power_down_clock_sources(struct dc *dc)
1839 {
1840 int i;
1841
1842 if (dc->res_pool->dp_clock_source->funcs->cs_power_down(
1843 dc->res_pool->dp_clock_source) == false)
1844 dm_error("Failed to power down pll! (dp clk src)\n");
1845
1846 for (i = 0; i < dc->res_pool->clk_src_count; i++) {
1847 if (dc->res_pool->clock_sources[i]->funcs->cs_power_down(
1848 dc->res_pool->clock_sources[i]) == false)
1849 dm_error("Failed to power down pll! (clk src index=%d)\n", i);
1850 }
1851 }
1852
power_down_all_hw_blocks(struct dc * dc)1853 static void power_down_all_hw_blocks(struct dc *dc)
1854 {
1855 power_down_encoders(dc);
1856
1857 power_down_controllers(dc);
1858
1859 power_down_clock_sources(dc);
1860
1861 if (dc->fbc_compressor)
1862 dc->fbc_compressor->funcs->disable_fbc(dc->fbc_compressor);
1863 }
1864
disable_vga_and_power_gate_all_controllers(struct dc * dc)1865 static void disable_vga_and_power_gate_all_controllers(
1866 struct dc *dc)
1867 {
1868 int i;
1869 struct timing_generator *tg;
1870 struct dc_context *ctx = dc->ctx;
1871
1872 for (i = 0; i < dc->res_pool->timing_generator_count; i++) {
1873 tg = dc->res_pool->timing_generators[i];
1874
1875 if (tg->funcs->disable_vga)
1876 tg->funcs->disable_vga(tg);
1877 }
1878 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1879 /* Enable CLOCK gating for each pipe BEFORE controller
1880 * powergating. */
1881 enable_display_pipe_clock_gating(ctx,
1882 true);
1883
1884 dc->current_state->res_ctx.pipe_ctx[i].pipe_idx = i;
1885 dc->hwss.disable_plane(dc, dc->current_state,
1886 &dc->current_state->res_ctx.pipe_ctx[i]);
1887 }
1888 }
1889
1890
get_edp_streams(struct dc_state * context,struct dc_stream_state ** edp_streams,int * edp_stream_num)1891 static void get_edp_streams(struct dc_state *context,
1892 struct dc_stream_state **edp_streams,
1893 int *edp_stream_num)
1894 {
1895 int i;
1896
1897 *edp_stream_num = 0;
1898 for (i = 0; i < context->stream_count; i++) {
1899 if (context->streams[i]->signal == SIGNAL_TYPE_EDP) {
1900 edp_streams[*edp_stream_num] = context->streams[i];
1901 if (++(*edp_stream_num) == MAX_NUM_EDP)
1902 return;
1903 }
1904 }
1905 }
1906
get_edp_links_with_sink(struct dc * dc,struct dc_link ** edp_links_with_sink,int * edp_with_sink_num)1907 static void get_edp_links_with_sink(
1908 struct dc *dc,
1909 struct dc_link **edp_links_with_sink,
1910 int *edp_with_sink_num)
1911 {
1912 int i;
1913
1914 /* check if there is an eDP panel not in use */
1915 *edp_with_sink_num = 0;
1916 for (i = 0; i < dc->link_count; i++) {
1917 if (dc->links[i]->local_sink &&
1918 dc->links[i]->local_sink->sink_signal == SIGNAL_TYPE_EDP) {
1919 edp_links_with_sink[*edp_with_sink_num] = dc->links[i];
1920 if (++(*edp_with_sink_num) == MAX_NUM_EDP)
1921 return;
1922 }
1923 }
1924 }
1925
clean_up_dsc_blocks(struct dc * dc)1926 static void clean_up_dsc_blocks(struct dc *dc)
1927 {
1928 struct display_stream_compressor *dsc = NULL;
1929 struct timing_generator *tg = NULL;
1930 struct stream_encoder *se = NULL;
1931 struct dccg *dccg = dc->res_pool->dccg;
1932 struct pg_cntl *pg_cntl = dc->res_pool->pg_cntl;
1933 int i;
1934
1935 if (!dc->caps.is_apu ||
1936 dc->ctx->dce_version < DCN_VERSION_3_15)
1937 return;
1938 /*VBIOS supports dsc starts from dcn315*/
1939 for (i = 0; i < dc->res_pool->res_cap->num_dsc; i++) {
1940 struct dcn_dsc_state s = {0};
1941
1942 dsc = dc->res_pool->dscs[i];
1943 dsc->funcs->dsc_read_state(dsc, &s);
1944 if (s.dsc_fw_en) {
1945 /* disable DSC in OPTC */
1946 if (i < dc->res_pool->timing_generator_count) {
1947 tg = dc->res_pool->timing_generators[i];
1948 tg->funcs->set_dsc_config(tg, OPTC_DSC_DISABLED, 0, 0);
1949 }
1950 /* disable DSC in stream encoder */
1951 if (i < dc->res_pool->stream_enc_count) {
1952 se = dc->res_pool->stream_enc[i];
1953 se->funcs->dp_set_dsc_config(se, OPTC_DSC_DISABLED, 0, 0);
1954 se->funcs->dp_set_dsc_pps_info_packet(se, false, NULL, true);
1955 }
1956 /* disable DSC block */
1957 if (dccg->funcs->set_ref_dscclk)
1958 dccg->funcs->set_ref_dscclk(dccg, dsc->inst);
1959 dsc->funcs->dsc_disable(dsc);
1960
1961 /* power down DSC */
1962 if (pg_cntl != NULL)
1963 pg_cntl->funcs->dsc_pg_control(pg_cntl, dsc->inst, false);
1964 }
1965 }
1966 }
1967
1968 /*
1969 * When ASIC goes from VBIOS/VGA mode to driver/accelerated mode we need:
1970 * 1. Power down all DC HW blocks
1971 * 2. Disable VGA engine on all controllers
1972 * 3. Enable power gating for controller
1973 * 4. Set acc_mode_change bit (VBIOS will clear this bit when going to FSDOS)
1974 */
dce110_enable_accelerated_mode(struct dc * dc,struct dc_state * context)1975 void dce110_enable_accelerated_mode(struct dc *dc, struct dc_state *context)
1976 {
1977 struct dc_link *edp_links_with_sink[MAX_NUM_EDP];
1978 struct dc_link *edp_links[MAX_NUM_EDP];
1979 struct dc_stream_state *edp_streams[MAX_NUM_EDP];
1980 struct dc_link *edp_link_with_sink = NULL;
1981 struct dc_link *edp_link = NULL;
1982 struct pipe_ctx *pipe_ctx = NULL;
1983 struct dce_hwseq *hws = dc->hwseq;
1984 int edp_with_sink_num;
1985 int edp_num;
1986 int edp_stream_num;
1987 int i;
1988 bool can_apply_edp_fast_boot = false;
1989 bool can_apply_seamless_boot = false;
1990 bool keep_edp_vdd_on = false;
1991 bool should_clean_dsc_block = true;
1992 struct dc_bios *dcb = dc->ctx->dc_bios;
1993 DC_LOGGER_INIT();
1994
1995
1996 get_edp_links_with_sink(dc, edp_links_with_sink, &edp_with_sink_num);
1997 dc_get_edp_links(dc, edp_links, &edp_num);
1998
1999 if (hws->funcs.init_pipes)
2000 hws->funcs.init_pipes(dc, context);
2001
2002 get_edp_streams(context, edp_streams, &edp_stream_num);
2003
2004 /* Check fastboot support, disable on DCE 6-8 because of blank screens */
2005 if (edp_num && edp_stream_num && dc->ctx->dce_version < DCE_VERSION_10_0) {
2006 for (i = 0; i < edp_num; i++) {
2007 edp_link = edp_links[i];
2008 if (edp_link != edp_streams[0]->link)
2009 continue;
2010 // enable fastboot if backend is enabled on eDP
2011 if (edp_link->link_enc->funcs->is_dig_enabled &&
2012 edp_link->link_enc->funcs->is_dig_enabled(edp_link->link_enc) &&
2013 edp_link->link_status.link_active) {
2014 struct dc_stream_state *edp_stream = edp_streams[0];
2015
2016 can_apply_edp_fast_boot = dc_validate_boot_timing(dc,
2017 edp_stream->sink, &edp_stream->timing);
2018
2019 // For Mux-platform, the default value is false.
2020 // Disable fast boot during mux switching.
2021 // The flag would be clean after switching done.
2022 if (dc->is_switch_in_progress_dest && edp_link->is_dds)
2023 can_apply_edp_fast_boot = false;
2024
2025 edp_stream->apply_edp_fast_boot_optimization = can_apply_edp_fast_boot;
2026 if (can_apply_edp_fast_boot) {
2027 DC_LOG_EVENT_LINK_TRAINING("eDP fast boot Enable\n");
2028
2029 // Vbios & Driver support different pixel rate div policy.
2030 pipe_ctx = resource_get_otg_master_for_stream(&context->res_ctx, edp_stream);
2031 if (pipe_ctx &&
2032 hws->funcs.is_dp_dig_pixel_rate_div_policy &&
2033 hws->funcs.is_dp_dig_pixel_rate_div_policy(pipe_ctx)) {
2034 // Get Vbios div factor from register
2035 dc->res_pool->dccg->funcs->get_pixel_rate_div(
2036 dc->res_pool->dccg,
2037 pipe_ctx->stream_res.tg->inst,
2038 &pipe_ctx->pixel_rate_divider.div_factor1,
2039 &pipe_ctx->pixel_rate_divider.div_factor2);
2040
2041 // VBios doesn't support pixel rate div, so force it.
2042 // If VBios supports it, we check it from reigster or other flags.
2043 pipe_ctx->stream_res.pix_clk_params.dio_se_pix_per_cycle = 1;
2044 }
2045 }
2046 break;
2047 }
2048 }
2049 // We are trying to enable eDP, don't power down VDD
2050 if (can_apply_edp_fast_boot)
2051 keep_edp_vdd_on = true;
2052 }
2053
2054 // Check seamless boot support
2055 for (i = 0; i < context->stream_count; i++) {
2056 if (context->streams[i]->apply_seamless_boot_optimization) {
2057 can_apply_seamless_boot = true;
2058 break;
2059 }
2060 }
2061
2062 /* eDP should not have stream in resume from S4 and so even with VBios post
2063 * it should get turned off
2064 */
2065 if (edp_with_sink_num)
2066 edp_link_with_sink = edp_links_with_sink[0];
2067
2068 // During a mux switch, powering down the HW blocks and then enabling
2069 // the link via a DPCD SET_POWER write causes a brief flash
2070 keep_edp_vdd_on |= dc->is_switch_in_progress_dest;
2071
2072 if (!can_apply_edp_fast_boot && !can_apply_seamless_boot) {
2073 if (edp_link_with_sink && !keep_edp_vdd_on) {
2074 /*turn off backlight before DP_blank and encoder powered down*/
2075 hws->funcs.edp_backlight_control(edp_link_with_sink, false);
2076 }
2077 /*resume from S3, no vbios posting, no need to power down again*/
2078 if (dcb && dcb->funcs && !dcb->funcs->is_accelerated_mode(dcb))
2079 clk_mgr_exit_optimized_pwr_state(dc, dc->clk_mgr);
2080
2081 power_down_all_hw_blocks(dc);
2082
2083 /* DSC could be enabled on eDP during VBIOS post.
2084 * To clean up dsc blocks if all eDP dpms_off is true.
2085 */
2086 for (i = 0; i < edp_stream_num; i++) {
2087 if (!edp_streams[i]->dpms_off) {
2088 should_clean_dsc_block = false;
2089 }
2090 }
2091
2092 if (should_clean_dsc_block)
2093 clean_up_dsc_blocks(dc);
2094
2095 disable_vga_and_power_gate_all_controllers(dc);
2096 if (edp_link_with_sink && !keep_edp_vdd_on)
2097 dc->hwss.edp_power_control(edp_link_with_sink, false);
2098 if (dcb && dcb->funcs && !dcb->funcs->is_accelerated_mode(dcb))
2099 clk_mgr_optimize_pwr_state(dc, dc->clk_mgr);
2100 }
2101 bios_set_scratch_acc_mode_change(dc->ctx->dc_bios, 1);
2102 }
2103
compute_pstate_blackout_duration(struct bw_fixed blackout_duration,const struct dc_stream_state * stream)2104 static uint32_t compute_pstate_blackout_duration(
2105 struct bw_fixed blackout_duration,
2106 const struct dc_stream_state *stream)
2107 {
2108 uint32_t total_dest_line_time_ns;
2109 uint32_t pstate_blackout_duration_ns;
2110
2111 pstate_blackout_duration_ns = 1000 * blackout_duration.value >> 24;
2112
2113 total_dest_line_time_ns = 1000000UL *
2114 (stream->timing.h_total * 10) /
2115 stream->timing.pix_clk_100hz +
2116 pstate_blackout_duration_ns;
2117
2118 return total_dest_line_time_ns;
2119 }
2120
dce110_set_displaymarks(const struct dc * dc,struct dc_state * context)2121 static void dce110_set_displaymarks(
2122 const struct dc *dc,
2123 struct dc_state *context)
2124 {
2125 uint8_t i, num_pipes;
2126 unsigned int underlay_idx = dc->res_pool->underlay_pipe_index;
2127
2128 for (i = 0, num_pipes = 0; i < MAX_PIPES; i++) {
2129 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2130 uint32_t total_dest_line_time_ns;
2131
2132 if (pipe_ctx->stream == NULL)
2133 continue;
2134
2135 total_dest_line_time_ns = compute_pstate_blackout_duration(
2136 dc->bw_vbios->blackout_duration, pipe_ctx->stream);
2137 pipe_ctx->plane_res.mi->funcs->mem_input_program_display_marks(
2138 pipe_ctx->plane_res.mi,
2139 context->bw_ctx.bw.dce.nbp_state_change_wm_ns[num_pipes],
2140 context->bw_ctx.bw.dce.stutter_exit_wm_ns[num_pipes],
2141 context->bw_ctx.bw.dce.stutter_entry_wm_ns[num_pipes],
2142 context->bw_ctx.bw.dce.urgent_wm_ns[num_pipes],
2143 total_dest_line_time_ns);
2144 if (i == underlay_idx) {
2145 num_pipes++;
2146 pipe_ctx->plane_res.mi->funcs->mem_input_program_chroma_display_marks(
2147 pipe_ctx->plane_res.mi,
2148 context->bw_ctx.bw.dce.nbp_state_change_wm_ns[num_pipes],
2149 context->bw_ctx.bw.dce.stutter_exit_wm_ns[num_pipes],
2150 context->bw_ctx.bw.dce.urgent_wm_ns[num_pipes],
2151 total_dest_line_time_ns);
2152 }
2153 num_pipes++;
2154 }
2155 }
2156
dce110_set_safe_displaymarks(struct resource_context * res_ctx,const struct resource_pool * pool)2157 void dce110_set_safe_displaymarks(
2158 struct resource_context *res_ctx,
2159 const struct resource_pool *pool)
2160 {
2161 int i;
2162 int underlay_idx = pool->underlay_pipe_index;
2163 struct dce_watermarks max_marks = {
2164 MAX_WATERMARK, MAX_WATERMARK, MAX_WATERMARK, MAX_WATERMARK };
2165 struct dce_watermarks nbp_marks = {
2166 SAFE_NBP_MARK, SAFE_NBP_MARK, SAFE_NBP_MARK, SAFE_NBP_MARK };
2167 struct dce_watermarks min_marks = { 0, 0, 0, 0};
2168
2169 for (i = 0; i < MAX_PIPES; i++) {
2170 if (res_ctx->pipe_ctx[i].stream == NULL || res_ctx->pipe_ctx[i].plane_res.mi == NULL)
2171 continue;
2172
2173 res_ctx->pipe_ctx[i].plane_res.mi->funcs->mem_input_program_display_marks(
2174 res_ctx->pipe_ctx[i].plane_res.mi,
2175 nbp_marks,
2176 max_marks,
2177 min_marks,
2178 max_marks,
2179 MAX_WATERMARK);
2180
2181 if (i == underlay_idx)
2182 res_ctx->pipe_ctx[i].plane_res.mi->funcs->mem_input_program_chroma_display_marks(
2183 res_ctx->pipe_ctx[i].plane_res.mi,
2184 nbp_marks,
2185 max_marks,
2186 max_marks,
2187 MAX_WATERMARK);
2188
2189 }
2190 }
2191
2192 /*******************************************************************************
2193 * Public functions
2194 ******************************************************************************/
2195
set_drr(struct pipe_ctx ** pipe_ctx,int num_pipes,struct dc_crtc_timing_adjust adjust)2196 static void set_drr(struct pipe_ctx **pipe_ctx,
2197 int num_pipes, struct dc_crtc_timing_adjust adjust)
2198 {
2199 int i = 0;
2200 struct drr_params params = {0};
2201 // DRR should set trigger event to monitor surface update event
2202 unsigned int event_triggers = 0x80;
2203 // Note DRR trigger events are generated regardless of whether num frames met.
2204 unsigned int num_frames = 2;
2205
2206 params.vertical_total_max = adjust.v_total_max;
2207 params.vertical_total_min = adjust.v_total_min;
2208
2209 /* TODO: If multiple pipes are to be supported, you need
2210 * some GSL stuff. Static screen triggers may be programmed differently
2211 * as well.
2212 */
2213 for (i = 0; i < num_pipes; i++) {
2214 /* dc_state_destruct() might null the stream resources, so fetch tg
2215 * here first to avoid a race condition. The lifetime of the pointee
2216 * itself (the timing_generator object) is not a problem here.
2217 */
2218 struct timing_generator *tg = pipe_ctx[i]->stream_res.tg;
2219
2220 if ((tg != NULL) && tg->funcs) {
2221 set_drr_and_clear_adjust_pending(pipe_ctx[i], pipe_ctx[i]->stream, ¶ms);
2222 if (adjust.v_total_max != 0 && adjust.v_total_min != 0)
2223 if (tg->funcs->set_static_screen_control)
2224 tg->funcs->set_static_screen_control(
2225 tg, event_triggers, num_frames);
2226 }
2227 }
2228 }
2229
get_position(struct pipe_ctx ** pipe_ctx,int num_pipes,struct crtc_position * position)2230 static void get_position(struct pipe_ctx **pipe_ctx,
2231 int num_pipes,
2232 struct crtc_position *position)
2233 {
2234 int i = 0;
2235
2236 /* TODO: handle pipes > 1
2237 */
2238 for (i = 0; i < num_pipes; i++)
2239 pipe_ctx[i]->stream_res.tg->funcs->get_position(pipe_ctx[i]->stream_res.tg, position);
2240 }
2241
set_static_screen_control(struct pipe_ctx ** pipe_ctx,int num_pipes,const struct dc_static_screen_params * params)2242 static void set_static_screen_control(struct pipe_ctx **pipe_ctx,
2243 int num_pipes, const struct dc_static_screen_params *params)
2244 {
2245 unsigned int i;
2246 unsigned int triggers = 0;
2247
2248 if (params->triggers.overlay_update)
2249 triggers |= 0x100;
2250 if (params->triggers.surface_update)
2251 triggers |= 0x80;
2252 if (params->triggers.cursor_update)
2253 triggers |= 0x2;
2254 if (params->triggers.force_trigger)
2255 triggers |= 0x1;
2256
2257 if (num_pipes) {
2258 struct dc *dc = pipe_ctx[0]->stream->ctx->dc;
2259
2260 if (dc->fbc_compressor)
2261 triggers |= 0x84;
2262 }
2263
2264 for (i = 0; i < num_pipes; i++)
2265 pipe_ctx[i]->stream_res.tg->funcs->
2266 set_static_screen_control(pipe_ctx[i]->stream_res.tg,
2267 triggers, params->num_frames);
2268 }
2269
2270 /*
2271 * Check if FBC can be enabled
2272 */
should_enable_fbc(struct dc * dc,struct dc_state * context,uint32_t * pipe_idx)2273 static bool should_enable_fbc(struct dc *dc,
2274 struct dc_state *context,
2275 uint32_t *pipe_idx)
2276 {
2277 uint32_t i;
2278 struct pipe_ctx *pipe_ctx = NULL;
2279 struct resource_context *res_ctx = &context->res_ctx;
2280 unsigned int underlay_idx = dc->res_pool->underlay_pipe_index;
2281
2282
2283 ASSERT(dc->fbc_compressor);
2284
2285 /* FBC memory should be allocated */
2286 if (!dc->ctx->fbc_gpu_addr)
2287 return false;
2288
2289 /* Only supports single display */
2290 if (context->stream_count != 1)
2291 return false;
2292
2293 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2294 if (res_ctx->pipe_ctx[i].stream) {
2295
2296 pipe_ctx = &res_ctx->pipe_ctx[i];
2297
2298 /* fbc not applicable on underlay pipe */
2299 if (pipe_ctx->pipe_idx != underlay_idx) {
2300 *pipe_idx = i;
2301 break;
2302 }
2303 }
2304 }
2305
2306 if (i == dc->res_pool->pipe_count)
2307 return false;
2308
2309 if (!pipe_ctx->stream->link)
2310 return false;
2311
2312 /* Only supports eDP */
2313 if (pipe_ctx->stream->link->connector_signal != SIGNAL_TYPE_EDP)
2314 return false;
2315
2316 /* PSR should not be enabled */
2317 if (pipe_ctx->stream->link->psr_settings.psr_feature_enabled)
2318 return false;
2319
2320 /* Replay should not be enabled */
2321 if (pipe_ctx->stream->link->replay_settings.replay_feature_enabled)
2322 return false;
2323
2324 /* Nothing to compress */
2325 if (!pipe_ctx->plane_state)
2326 return false;
2327
2328 /* Only for non-linear tiling */
2329 if (pipe_ctx->plane_state->tiling_info.gfx8.array_mode == DC_ARRAY_LINEAR_GENERAL)
2330 return false;
2331
2332 return true;
2333 }
2334
2335 /*
2336 * Enable FBC
2337 */
enable_fbc(struct dc * dc,struct dc_state * context)2338 void enable_fbc(
2339 struct dc *dc,
2340 struct dc_state *context)
2341 {
2342 uint32_t pipe_idx = 0;
2343
2344 if (should_enable_fbc(dc, context, &pipe_idx)) {
2345 /* Program GRPH COMPRESSED ADDRESS and PITCH */
2346 struct compr_addr_and_pitch_params params = {0, 0, 0};
2347 struct compressor *compr = dc->fbc_compressor;
2348 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[pipe_idx];
2349
2350 params.source_view_width = pipe_ctx->stream->timing.h_addressable;
2351 params.source_view_height = pipe_ctx->stream->timing.v_addressable;
2352 params.inst = pipe_ctx->stream_res.tg->inst;
2353 compr->compr_surface_address.quad_part = dc->ctx->fbc_gpu_addr;
2354
2355 compr->funcs->surface_address_and_pitch(compr, ¶ms);
2356 compr->funcs->set_fbc_invalidation_triggers(compr, 1);
2357
2358 compr->funcs->enable_fbc(compr, ¶ms);
2359 }
2360 }
2361
dce110_reset_hw_ctx_wrap(struct dc * dc,struct dc_state * context)2362 static void dce110_reset_hw_ctx_wrap(
2363 struct dc *dc,
2364 struct dc_state *context)
2365 {
2366 int i;
2367
2368 /* Reset old context */
2369 /* look up the targets that have been removed since last commit */
2370 for (i = 0; i < MAX_PIPES; i++) {
2371 struct pipe_ctx *pipe_ctx_old =
2372 &dc->current_state->res_ctx.pipe_ctx[i];
2373 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2374
2375 /* Note: We need to disable output if clock sources change,
2376 * since bios does optimization and doesn't apply if changing
2377 * PHY when not already disabled.
2378 */
2379
2380 /* Skip underlay pipe since it will be handled in commit surface*/
2381 if (!pipe_ctx_old->stream || pipe_ctx_old->top_pipe)
2382 continue;
2383
2384 if (!pipe_ctx->stream ||
2385 pipe_need_reprogram(pipe_ctx_old, pipe_ctx)) {
2386 struct clock_source *old_clk = pipe_ctx_old->clock_source;
2387
2388 /* Disable if new stream is null. O/w, if stream is
2389 * disabled already, no need to disable again.
2390 */
2391 if (!pipe_ctx->stream || !pipe_ctx->stream->dpms_off) {
2392 dc->link_srv->set_dpms_off(pipe_ctx_old);
2393
2394 /* free acquired resources*/
2395 if (pipe_ctx_old->stream_res.audio) {
2396 /*disable az_endpoint*/
2397 pipe_ctx_old->stream_res.audio->funcs->
2398 az_disable(pipe_ctx_old->stream_res.audio);
2399
2400 /*free audio*/
2401 if (dc->caps.dynamic_audio == true) {
2402 /*we have to dynamic arbitrate the audio endpoints*/
2403 /*we free the resource, need reset is_audio_acquired*/
2404 update_audio_usage(&dc->current_state->res_ctx, dc->res_pool,
2405 pipe_ctx_old->stream_res.audio, false);
2406 pipe_ctx_old->stream_res.audio = NULL;
2407 }
2408 }
2409 }
2410
2411 pipe_ctx_old->stream_res.tg->funcs->set_blank(pipe_ctx_old->stream_res.tg, true);
2412 if (!hwss_wait_for_blank_complete(pipe_ctx_old->stream_res.tg)) {
2413 dm_error("DC: failed to blank crtc!\n");
2414 BREAK_TO_DEBUGGER();
2415 }
2416 pipe_ctx_old->stream_res.tg->funcs->disable_crtc(pipe_ctx_old->stream_res.tg);
2417 if (dc_is_hdmi_tmds_signal(pipe_ctx_old->stream->signal))
2418 pipe_ctx_old->stream->link->phy_state.symclk_ref_cnts.otg = 0;
2419 pipe_ctx_old->plane_res.mi->funcs->free_mem_input(
2420 pipe_ctx_old->plane_res.mi, dc->current_state->stream_count);
2421
2422 if (old_clk && 0 == resource_get_clock_source_reference(&context->res_ctx,
2423 dc->res_pool,
2424 old_clk))
2425 old_clk->funcs->cs_power_down(old_clk);
2426
2427 dc->hwss.disable_plane(dc, dc->current_state, pipe_ctx_old);
2428
2429 pipe_ctx_old->stream = NULL;
2430 }
2431 }
2432 }
2433
dce110_setup_audio_dto(struct dc * dc,struct dc_state * context)2434 static void dce110_setup_audio_dto(
2435 struct dc *dc,
2436 struct dc_state *context)
2437 {
2438 unsigned int i;
2439
2440 /* program audio wall clock. use HDMI as clock source if HDMI
2441 * audio active. Otherwise, use DP as clock source
2442 * first, loop to find any HDMI audio, if not, loop find DP audio
2443 */
2444 /* Setup audio rate clock source */
2445 /* Issue:
2446 * Audio lag happened on DP monitor when unplug a HDMI monitor
2447 *
2448 * Cause:
2449 * In case of DP and HDMI connected or HDMI only, DCCG_AUDIO_DTO_SEL
2450 * is set to either dto0 or dto1, audio should work fine.
2451 * In case of DP connected only, DCCG_AUDIO_DTO_SEL should be dto1,
2452 * set to dto0 will cause audio lag.
2453 *
2454 * Solution:
2455 * Not optimized audio wall dto setup. When mode set, iterate pipe_ctx,
2456 * find first available pipe with audio, setup audio wall DTO per topology
2457 * instead of per pipe.
2458 */
2459 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2460 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2461
2462 if (pipe_ctx->stream == NULL)
2463 continue;
2464
2465 if (pipe_ctx->top_pipe)
2466 continue;
2467 if (pipe_ctx->stream->signal != SIGNAL_TYPE_HDMI_TYPE_A)
2468 continue;
2469 if (pipe_ctx->stream_res.audio != NULL) {
2470 struct audio_output audio_output;
2471
2472 build_audio_output(context, pipe_ctx, &audio_output);
2473
2474 if (dc->res_pool->dccg && dc->res_pool->dccg->funcs->set_audio_dtbclk_dto) {
2475 struct dtbclk_dto_params dto_params = {0};
2476
2477 dc->res_pool->dccg->funcs->set_audio_dtbclk_dto(
2478 dc->res_pool->dccg, &dto_params);
2479
2480 pipe_ctx->stream_res.audio->funcs->wall_dto_setup(
2481 pipe_ctx->stream_res.audio,
2482 pipe_ctx->stream->signal,
2483 &audio_output.crtc_info,
2484 &audio_output.pll_info);
2485 } else
2486 pipe_ctx->stream_res.audio->funcs->wall_dto_setup(
2487 pipe_ctx->stream_res.audio,
2488 pipe_ctx->stream->signal,
2489 &audio_output.crtc_info,
2490 &audio_output.pll_info);
2491 break;
2492 }
2493 }
2494
2495 /* no HDMI audio is found, try DP audio */
2496 if (i == dc->res_pool->pipe_count) {
2497 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2498 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2499
2500 if (pipe_ctx->stream == NULL)
2501 continue;
2502
2503 if (pipe_ctx->top_pipe)
2504 continue;
2505
2506 if (!dc_is_dp_signal(pipe_ctx->stream->signal))
2507 continue;
2508
2509 if (pipe_ctx->stream_res.audio != NULL) {
2510 struct audio_output audio_output = {0};
2511
2512 build_audio_output(context, pipe_ctx, &audio_output);
2513
2514 pipe_ctx->stream_res.audio->funcs->wall_dto_setup(
2515 pipe_ctx->stream_res.audio,
2516 pipe_ctx->stream->signal,
2517 &audio_output.crtc_info,
2518 &audio_output.pll_info);
2519 break;
2520 }
2521 }
2522 }
2523 }
2524
dce110_apply_ctx_to_hw(struct dc * dc,struct dc_state * context)2525 enum dc_status dce110_apply_ctx_to_hw(
2526 struct dc *dc,
2527 struct dc_state *context)
2528 {
2529 struct dce_hwseq *hws = dc->hwseq;
2530 struct dc_bios *dcb = dc->ctx->dc_bios;
2531 enum dc_status status;
2532 int i;
2533 bool was_hpo_acquired = resource_is_hpo_acquired(dc->current_state);
2534 bool is_hpo_acquired = resource_is_hpo_acquired(context);
2535
2536 /* reset syncd pipes from disabled pipes */
2537 if (dc->config.use_pipe_ctx_sync_logic)
2538 reset_syncd_pipes_from_disabled_pipes(dc, context);
2539
2540 /* Reset old context */
2541 /* look up the targets that have been removed since last commit */
2542 hws->funcs.reset_hw_ctx_wrap(dc, context);
2543
2544 /* Skip applying if no targets */
2545 if (context->stream_count <= 0)
2546 return DC_OK;
2547
2548 /* Apply new context */
2549 dcb->funcs->set_scratch_critical_state(dcb, true);
2550
2551 /* below is for real asic only */
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 || pipe_ctx->top_pipe)
2558 continue;
2559
2560 if (pipe_ctx->stream == pipe_ctx_old->stream) {
2561 if (pipe_ctx_old->clock_source != pipe_ctx->clock_source)
2562 dce_crtc_switch_to_clk_src(dc->hwseq,
2563 pipe_ctx->clock_source, i);
2564 continue;
2565 }
2566
2567 hws->funcs.enable_display_power_gating(
2568 dc, i, dc->ctx->dc_bios,
2569 PIPE_GATING_CONTROL_DISABLE);
2570 }
2571
2572 if (dc->fbc_compressor)
2573 dc->fbc_compressor->funcs->disable_fbc(dc->fbc_compressor);
2574
2575 dce110_setup_audio_dto(dc, context);
2576
2577 if (dc->hwseq->funcs.setup_hpo_hw_control && was_hpo_acquired != is_hpo_acquired) {
2578 dc->hwseq->funcs.setup_hpo_hw_control(dc->hwseq, is_hpo_acquired);
2579 }
2580
2581 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2582 struct pipe_ctx *pipe_ctx_old =
2583 &dc->current_state->res_ctx.pipe_ctx[i];
2584 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2585
2586 if (pipe_ctx->stream == NULL)
2587 continue;
2588
2589 if (pipe_ctx->stream == pipe_ctx_old->stream &&
2590 pipe_ctx->stream->link->link_state_valid) {
2591 continue;
2592 }
2593
2594 if (pipe_ctx_old->stream && !pipe_need_reprogram(pipe_ctx_old, pipe_ctx))
2595 continue;
2596
2597 if (pipe_ctx->top_pipe || pipe_ctx->prev_odm_pipe)
2598 continue;
2599
2600 status = dce110_apply_single_controller_ctx_to_hw(
2601 pipe_ctx,
2602 context,
2603 dc);
2604
2605 if (DC_OK != status)
2606 return status;
2607
2608 #ifdef CONFIG_DRM_AMD_DC_FP
2609 if (hws->funcs.resync_fifo_dccg_dio)
2610 hws->funcs.resync_fifo_dccg_dio(hws, dc, context, i);
2611 #endif
2612 }
2613
2614 if (dc->fbc_compressor)
2615 enable_fbc(dc, dc->current_state);
2616
2617 dcb->funcs->set_scratch_critical_state(dcb, false);
2618
2619 return DC_OK;
2620 }
2621
2622 /*******************************************************************************
2623 * Front End programming
2624 ******************************************************************************/
set_default_colors(struct pipe_ctx * pipe_ctx)2625 static void set_default_colors(struct pipe_ctx *pipe_ctx)
2626 {
2627 struct default_adjustment default_adjust = { 0 };
2628
2629 default_adjust.force_hw_default = false;
2630 default_adjust.in_color_space = pipe_ctx->plane_state->color_space;
2631 default_adjust.out_color_space = pipe_ctx->stream->output_color_space;
2632 default_adjust.csc_adjust_type = GRAPHICS_CSC_ADJUST_TYPE_SW;
2633 default_adjust.surface_pixel_format = pipe_ctx->plane_res.scl_data.format;
2634
2635 /* display color depth */
2636 default_adjust.color_depth =
2637 pipe_ctx->stream->timing.display_color_depth;
2638
2639 /* Lb color depth */
2640 default_adjust.lb_color_depth = pipe_ctx->plane_res.scl_data.lb_params.depth;
2641
2642 pipe_ctx->plane_res.xfm->funcs->opp_set_csc_default(
2643 pipe_ctx->plane_res.xfm, &default_adjust);
2644 }
2645
2646
2647 /*******************************************************************************
2648 * In order to turn on/off specific surface we will program
2649 * Blender + CRTC
2650 *
2651 * In case that we have two surfaces and they have a different visibility
2652 * we can't turn off the CRTC since it will turn off the entire display
2653 *
2654 * |----------------------------------------------- |
2655 * |bottom pipe|curr pipe | | |
2656 * |Surface |Surface | Blender | CRCT |
2657 * |visibility |visibility | Configuration| |
2658 * |------------------------------------------------|
2659 * | off | off | CURRENT_PIPE | blank |
2660 * | off | on | CURRENT_PIPE | unblank |
2661 * | on | off | OTHER_PIPE | unblank |
2662 * | on | on | BLENDING | unblank |
2663 * -------------------------------------------------|
2664 *
2665 ******************************************************************************/
program_surface_visibility(const struct dc * dc,struct pipe_ctx * pipe_ctx)2666 static void program_surface_visibility(const struct dc *dc,
2667 struct pipe_ctx *pipe_ctx)
2668 {
2669 enum blnd_mode blender_mode = BLND_MODE_CURRENT_PIPE;
2670 bool blank_target = false;
2671
2672 if (pipe_ctx->bottom_pipe) {
2673
2674 /* For now we are supporting only two pipes */
2675 ASSERT(pipe_ctx->bottom_pipe->bottom_pipe == NULL);
2676
2677 if (pipe_ctx->bottom_pipe->plane_state->visible) {
2678 if (pipe_ctx->plane_state->visible)
2679 blender_mode = BLND_MODE_BLENDING;
2680 else
2681 blender_mode = BLND_MODE_OTHER_PIPE;
2682
2683 } else if (!pipe_ctx->plane_state->visible)
2684 blank_target = true;
2685
2686 } else if (!pipe_ctx->plane_state->visible)
2687 blank_target = true;
2688
2689 dce_set_blender_mode(dc->hwseq, pipe_ctx->stream_res.tg->inst, blender_mode);
2690 pipe_ctx->stream_res.tg->funcs->set_blank(pipe_ctx->stream_res.tg, blank_target);
2691
2692 }
2693
program_gamut_remap(struct pipe_ctx * pipe_ctx)2694 static void program_gamut_remap(struct pipe_ctx *pipe_ctx)
2695 {
2696 int i = 0;
2697 struct xfm_grph_csc_adjustment adjust;
2698 memset(&adjust, 0, sizeof(adjust));
2699 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS;
2700
2701
2702 if (pipe_ctx->stream->gamut_remap_matrix.enable_remap == true) {
2703 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_SW;
2704
2705 for (i = 0; i < CSC_TEMPERATURE_MATRIX_SIZE; i++)
2706 adjust.temperature_matrix[i] =
2707 pipe_ctx->stream->gamut_remap_matrix.matrix[i];
2708 }
2709
2710 pipe_ctx->plane_res.xfm->funcs->transform_set_gamut_remap(pipe_ctx->plane_res.xfm, &adjust);
2711 }
update_plane_addr(const struct dc * dc,struct pipe_ctx * pipe_ctx)2712 static void update_plane_addr(const struct dc *dc,
2713 struct pipe_ctx *pipe_ctx)
2714 {
2715 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
2716
2717 if (plane_state == NULL)
2718 return;
2719
2720 pipe_ctx->plane_res.mi->funcs->mem_input_program_surface_flip_and_addr(
2721 pipe_ctx->plane_res.mi,
2722 &plane_state->address,
2723 plane_state->flip_immediate);
2724
2725 plane_state->status.requested_address = plane_state->address;
2726 }
2727
dce110_update_pending_status(struct pipe_ctx * pipe_ctx)2728 static void dce110_update_pending_status(struct pipe_ctx *pipe_ctx)
2729 {
2730 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
2731
2732 if (plane_state == NULL)
2733 return;
2734
2735 plane_state->status.is_flip_pending =
2736 pipe_ctx->plane_res.mi->funcs->mem_input_is_flip_pending(
2737 pipe_ctx->plane_res.mi);
2738
2739 if (plane_state->status.is_flip_pending && !plane_state->visible)
2740 pipe_ctx->plane_res.mi->current_address = pipe_ctx->plane_res.mi->request_address;
2741
2742 plane_state->status.current_address = pipe_ctx->plane_res.mi->current_address;
2743 if (pipe_ctx->plane_res.mi->current_address.type == PLN_ADDR_TYPE_GRPH_STEREO &&
2744 pipe_ctx->stream_res.tg->funcs->is_stereo_left_eye) {
2745 plane_state->status.is_right_eye =\
2746 !pipe_ctx->stream_res.tg->funcs->is_stereo_left_eye(pipe_ctx->stream_res.tg);
2747 }
2748 }
2749
dce110_power_down(struct dc * dc)2750 void dce110_power_down(struct dc *dc)
2751 {
2752 power_down_all_hw_blocks(dc);
2753 disable_vga_and_power_gate_all_controllers(dc);
2754 }
2755
wait_for_reset_trigger_to_occur(struct dc_context * dc_ctx,struct timing_generator * tg)2756 static bool wait_for_reset_trigger_to_occur(
2757 struct dc_context *dc_ctx,
2758 struct timing_generator *tg)
2759 {
2760 struct dc_context *ctx = dc_ctx;
2761 bool rc = false;
2762
2763 /* To avoid endless loop we wait at most
2764 * frames_to_wait_on_triggered_reset frames for the reset to occur. */
2765 const uint32_t frames_to_wait_on_triggered_reset = 10;
2766 uint32_t i;
2767
2768 for (i = 0; i < frames_to_wait_on_triggered_reset; i++) {
2769
2770 if (!tg->funcs->is_counter_moving(tg)) {
2771 DC_ERROR("TG counter is not moving!\n");
2772 break;
2773 }
2774
2775 if (tg->funcs->did_triggered_reset_occur(tg)) {
2776 rc = true;
2777 /* usually occurs at i=1 */
2778 DC_SYNC_INFO("GSL: reset occurred at wait count: %d\n",
2779 i);
2780 break;
2781 }
2782
2783 /* Wait for one frame. */
2784 tg->funcs->wait_for_state(tg, CRTC_STATE_VACTIVE);
2785 tg->funcs->wait_for_state(tg, CRTC_STATE_VBLANK);
2786 }
2787
2788 if (false == rc)
2789 DC_ERROR("GSL: Timeout on reset trigger!\n");
2790
2791 return rc;
2792 }
2793
2794 /* 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[])2795 static void dce110_enable_timing_synchronization(
2796 struct dc *dc,
2797 struct dc_state *state,
2798 int group_index,
2799 int group_size,
2800 struct pipe_ctx *grouped_pipes[])
2801 {
2802 struct dc_context *dc_ctx = dc->ctx;
2803 struct dcp_gsl_params gsl_params = { 0 };
2804 int i;
2805 DC_LOGGER_INIT();
2806
2807 DC_SYNC_INFO("GSL: Setting-up...\n");
2808
2809 /* Designate a single TG in the group as a master.
2810 * Since HW doesn't care which one, we always assign
2811 * the 1st one in the group. */
2812 gsl_params.gsl_group = 0;
2813 gsl_params.gsl_master = grouped_pipes[0]->stream_res.tg->inst;
2814
2815 for (i = 0; i < group_size; i++)
2816 grouped_pipes[i]->stream_res.tg->funcs->setup_global_swap_lock(
2817 grouped_pipes[i]->stream_res.tg, &gsl_params);
2818
2819 /* Reset slave controllers on master VSync */
2820 DC_SYNC_INFO("GSL: enabling trigger-reset\n");
2821
2822 for (i = 1 /* skip the master */; i < group_size; i++)
2823 grouped_pipes[i]->stream_res.tg->funcs->enable_reset_trigger(
2824 grouped_pipes[i]->stream_res.tg,
2825 gsl_params.gsl_group);
2826
2827 for (i = 1 /* skip the master */; i < group_size; i++) {
2828 DC_SYNC_INFO("GSL: waiting for reset to occur.\n");
2829 wait_for_reset_trigger_to_occur(dc_ctx, grouped_pipes[i]->stream_res.tg);
2830 grouped_pipes[i]->stream_res.tg->funcs->disable_reset_trigger(
2831 grouped_pipes[i]->stream_res.tg);
2832 }
2833
2834 /* GSL Vblank synchronization is a one time sync mechanism, assumption
2835 * is that the sync'ed displays will not drift out of sync over time*/
2836 DC_SYNC_INFO("GSL: Restoring register states.\n");
2837 for (i = 0; i < group_size; i++)
2838 grouped_pipes[i]->stream_res.tg->funcs->tear_down_global_swap_lock(grouped_pipes[i]->stream_res.tg);
2839
2840 DC_SYNC_INFO("GSL: Set-up complete.\n");
2841 }
2842
dce110_enable_per_frame_crtc_position_reset(struct dc * dc,int group_size,struct pipe_ctx * grouped_pipes[])2843 static void dce110_enable_per_frame_crtc_position_reset(
2844 struct dc *dc,
2845 int group_size,
2846 struct pipe_ctx *grouped_pipes[])
2847 {
2848 struct dc_context *dc_ctx = dc->ctx;
2849 struct dcp_gsl_params gsl_params = { 0 };
2850 int i;
2851 DC_LOGGER_INIT();
2852
2853 gsl_params.gsl_group = 0;
2854 gsl_params.gsl_master = 0;
2855
2856 for (i = 0; i < group_size; i++)
2857 grouped_pipes[i]->stream_res.tg->funcs->setup_global_swap_lock(
2858 grouped_pipes[i]->stream_res.tg, &gsl_params);
2859
2860 DC_SYNC_INFO("GSL: enabling trigger-reset\n");
2861
2862 for (i = 1; i < group_size; i++)
2863 grouped_pipes[i]->stream_res.tg->funcs->enable_crtc_reset(
2864 grouped_pipes[i]->stream_res.tg,
2865 gsl_params.gsl_master,
2866 &grouped_pipes[i]->stream->triggered_crtc_reset);
2867
2868 DC_SYNC_INFO("GSL: waiting for reset to occur.\n");
2869 for (i = 1; i < group_size; i++)
2870 wait_for_reset_trigger_to_occur(dc_ctx, grouped_pipes[i]->stream_res.tg);
2871
2872 for (i = 0; i < group_size; i++)
2873 grouped_pipes[i]->stream_res.tg->funcs->tear_down_global_swap_lock(grouped_pipes[i]->stream_res.tg);
2874
2875 }
2876
dce110_init_pipes(struct dc * dc,struct dc_state * context)2877 static void dce110_init_pipes(struct dc *dc, struct dc_state *context)
2878 {
2879 // Do nothing
2880 }
2881
dce110_init_hw(struct dc * dc)2882 static void dce110_init_hw(struct dc *dc)
2883 {
2884 int i;
2885 struct dc_bios *bp;
2886 struct transform *xfm;
2887 struct abm *abm;
2888 struct dmcu *dmcu;
2889 struct dce_hwseq *hws = dc->hwseq;
2890 uint32_t backlight = MAX_BACKLIGHT_LEVEL;
2891 uint32_t user_level = MAX_BACKLIGHT_LEVEL;
2892
2893 bp = dc->ctx->dc_bios;
2894 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2895 xfm = dc->res_pool->transforms[i];
2896 xfm->funcs->transform_reset(xfm);
2897
2898 hws->funcs.enable_display_power_gating(
2899 dc, i, bp,
2900 PIPE_GATING_CONTROL_INIT);
2901 hws->funcs.enable_display_power_gating(
2902 dc, i, bp,
2903 PIPE_GATING_CONTROL_DISABLE);
2904 hws->funcs.enable_display_pipe_clock_gating(
2905 dc->ctx,
2906 true);
2907 }
2908
2909 dce_clock_gating_power_up(dc->hwseq, false);
2910 /***************************************/
2911
2912 for (i = 0; i < dc->link_count; i++) {
2913 /****************************************/
2914 /* Power up AND update implementation according to the
2915 * required signal (which may be different from the
2916 * default signal on connector). */
2917 struct dc_link *link = dc->links[i];
2918
2919 link->link_enc->funcs->hw_init(link->link_enc);
2920 }
2921
2922 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2923 struct timing_generator *tg = dc->res_pool->timing_generators[i];
2924
2925 tg->funcs->disable_vga(tg);
2926
2927 /* Blank controller using driver code instead of
2928 * command table. */
2929 tg->funcs->set_blank(tg, true);
2930 hwss_wait_for_blank_complete(tg);
2931 }
2932
2933 for (i = 0; i < dc->res_pool->audio_count; i++) {
2934 struct audio *audio = dc->res_pool->audios[i];
2935 audio->funcs->hw_init(audio);
2936 }
2937
2938 for (i = 0; i < dc->link_count; i++) {
2939 struct dc_link *link = dc->links[i];
2940
2941 if (link->panel_cntl) {
2942 backlight = link->panel_cntl->funcs->hw_init(link->panel_cntl);
2943 user_level = link->panel_cntl->stored_backlight_registers.USER_LEVEL;
2944 }
2945 }
2946
2947 abm = dc->res_pool->abm;
2948 if (abm != NULL)
2949 abm->funcs->abm_init(abm, backlight, user_level);
2950
2951 dmcu = dc->res_pool->dmcu;
2952 if (dmcu != NULL && abm != NULL)
2953 abm->dmcu_is_running = dmcu->funcs->is_dmcu_initialized(dmcu);
2954
2955 if (dc->fbc_compressor)
2956 dc->fbc_compressor->funcs->power_up_fbc(dc->fbc_compressor);
2957
2958 }
2959
2960
dce110_prepare_bandwidth(struct dc * dc,struct dc_state * context)2961 void dce110_prepare_bandwidth(
2962 struct dc *dc,
2963 struct dc_state *context)
2964 {
2965 struct clk_mgr *dccg = dc->clk_mgr;
2966
2967 dce110_set_safe_displaymarks(&context->res_ctx, dc->res_pool);
2968 if (dccg)
2969 dccg->funcs->update_clocks(
2970 dccg,
2971 context,
2972 false);
2973 }
2974
dce110_optimize_bandwidth(struct dc * dc,struct dc_state * context)2975 void dce110_optimize_bandwidth(
2976 struct dc *dc,
2977 struct dc_state *context)
2978 {
2979 struct clk_mgr *dccg = dc->clk_mgr;
2980
2981 dce110_set_displaymarks(dc, context);
2982
2983 if (dccg)
2984 dccg->funcs->update_clocks(
2985 dccg,
2986 context,
2987 true);
2988 }
2989
dce110_program_front_end_for_pipe(struct dc * dc,struct pipe_ctx * pipe_ctx)2990 static void dce110_program_front_end_for_pipe(
2991 struct dc *dc, struct pipe_ctx *pipe_ctx)
2992 {
2993 struct mem_input *mi = pipe_ctx->plane_res.mi;
2994 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
2995 struct xfm_grph_csc_adjustment adjust;
2996 struct out_csc_color_matrix tbl_entry;
2997 unsigned int i;
2998 struct dce_hwseq *hws = dc->hwseq;
2999
3000 memset(&tbl_entry, 0, sizeof(tbl_entry));
3001
3002 memset(&adjust, 0, sizeof(adjust));
3003 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS;
3004
3005 dce_enable_fe_clock(dc->hwseq, mi->inst, true);
3006
3007 set_default_colors(pipe_ctx);
3008 if (pipe_ctx->stream->csc_color_matrix.enable_adjustment
3009 == true) {
3010 tbl_entry.color_space =
3011 pipe_ctx->stream->output_color_space;
3012
3013 for (i = 0; i < 12; i++)
3014 tbl_entry.regval[i] =
3015 pipe_ctx->stream->csc_color_matrix.matrix[i];
3016
3017 pipe_ctx->plane_res.xfm->funcs->opp_set_csc_adjustment
3018 (pipe_ctx->plane_res.xfm, &tbl_entry);
3019 }
3020
3021 if (pipe_ctx->stream->gamut_remap_matrix.enable_remap == true) {
3022 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_SW;
3023
3024 for (i = 0; i < CSC_TEMPERATURE_MATRIX_SIZE; i++)
3025 adjust.temperature_matrix[i] =
3026 pipe_ctx->stream->gamut_remap_matrix.matrix[i];
3027 }
3028
3029 pipe_ctx->plane_res.xfm->funcs->transform_set_gamut_remap(pipe_ctx->plane_res.xfm, &adjust);
3030
3031 pipe_ctx->plane_res.scl_data.lb_params.alpha_en = pipe_ctx->bottom_pipe != NULL;
3032
3033 program_scaler(dc, pipe_ctx);
3034
3035 mi->funcs->mem_input_program_surface_config(
3036 mi,
3037 plane_state->format,
3038 &plane_state->tiling_info,
3039 &plane_state->plane_size,
3040 plane_state->rotation,
3041 NULL,
3042 false);
3043 if (mi->funcs->set_blank)
3044 mi->funcs->set_blank(mi, pipe_ctx->plane_state->visible);
3045
3046 if (dc->config.gpu_vm_support)
3047 mi->funcs->mem_input_program_pte_vm(
3048 pipe_ctx->plane_res.mi,
3049 plane_state->format,
3050 &plane_state->tiling_info,
3051 plane_state->rotation);
3052
3053 /* Moved programming gamma from dc to hwss */
3054 if (pipe_ctx->plane_state->update_flags.bits.full_update ||
3055 pipe_ctx->plane_state->update_flags.bits.in_transfer_func_change ||
3056 pipe_ctx->plane_state->update_flags.bits.gamma_change)
3057 hws->funcs.set_input_transfer_func(dc, pipe_ctx, pipe_ctx->plane_state);
3058
3059 if (pipe_ctx->plane_state->update_flags.bits.full_update)
3060 hws->funcs.set_output_transfer_func(dc, pipe_ctx, pipe_ctx->stream);
3061
3062 DC_LOG_SURFACE(
3063 "Pipe:%d %p: addr hi:0x%x, "
3064 "addr low:0x%x, "
3065 "src: %d, %d, %d,"
3066 " %d; dst: %d, %d, %d, %d;"
3067 "clip: %d, %d, %d, %d\n",
3068 pipe_ctx->pipe_idx,
3069 (void *) pipe_ctx->plane_state,
3070 pipe_ctx->plane_state->address.grph.addr.high_part,
3071 pipe_ctx->plane_state->address.grph.addr.low_part,
3072 pipe_ctx->plane_state->src_rect.x,
3073 pipe_ctx->plane_state->src_rect.y,
3074 pipe_ctx->plane_state->src_rect.width,
3075 pipe_ctx->plane_state->src_rect.height,
3076 pipe_ctx->plane_state->dst_rect.x,
3077 pipe_ctx->plane_state->dst_rect.y,
3078 pipe_ctx->plane_state->dst_rect.width,
3079 pipe_ctx->plane_state->dst_rect.height,
3080 pipe_ctx->plane_state->clip_rect.x,
3081 pipe_ctx->plane_state->clip_rect.y,
3082 pipe_ctx->plane_state->clip_rect.width,
3083 pipe_ctx->plane_state->clip_rect.height);
3084
3085 DC_LOG_SURFACE(
3086 "Pipe %d: width, height, x, y\n"
3087 "viewport:%d, %d, %d, %d\n"
3088 "recout: %d, %d, %d, %d\n",
3089 pipe_ctx->pipe_idx,
3090 pipe_ctx->plane_res.scl_data.viewport.width,
3091 pipe_ctx->plane_res.scl_data.viewport.height,
3092 pipe_ctx->plane_res.scl_data.viewport.x,
3093 pipe_ctx->plane_res.scl_data.viewport.y,
3094 pipe_ctx->plane_res.scl_data.recout.width,
3095 pipe_ctx->plane_res.scl_data.recout.height,
3096 pipe_ctx->plane_res.scl_data.recout.x,
3097 pipe_ctx->plane_res.scl_data.recout.y);
3098 }
3099
dce110_apply_ctx_for_surface(struct dc * dc,const struct dc_stream_state * stream,int num_planes,struct dc_state * context)3100 static void dce110_apply_ctx_for_surface(
3101 struct dc *dc,
3102 const struct dc_stream_state *stream,
3103 int num_planes,
3104 struct dc_state *context)
3105 {
3106 int i;
3107
3108 if (num_planes == 0)
3109 return;
3110
3111 if (dc->fbc_compressor)
3112 dc->fbc_compressor->funcs->disable_fbc(dc->fbc_compressor);
3113
3114 for (i = 0; i < dc->res_pool->pipe_count; i++) {
3115 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
3116
3117 if (pipe_ctx->stream != stream)
3118 continue;
3119
3120 /* Need to allocate mem before program front end for Fiji */
3121 pipe_ctx->plane_res.mi->funcs->allocate_mem_input(
3122 pipe_ctx->plane_res.mi,
3123 pipe_ctx->stream->timing.h_total,
3124 pipe_ctx->stream->timing.v_total,
3125 pipe_ctx->stream->timing.pix_clk_100hz / 10,
3126 context->stream_count);
3127
3128 dce110_program_front_end_for_pipe(dc, pipe_ctx);
3129
3130 dc->hwss.update_plane_addr(dc, pipe_ctx);
3131
3132 program_surface_visibility(dc, pipe_ctx);
3133
3134 }
3135
3136 if (dc->fbc_compressor)
3137 enable_fbc(dc, context);
3138 }
3139
dce110_post_unlock_program_front_end(struct dc * dc,struct dc_state * context)3140 static void dce110_post_unlock_program_front_end(
3141 struct dc *dc,
3142 struct dc_state *context)
3143 {
3144 }
3145
dce110_power_down_fe(struct dc * dc,struct dc_state * state,struct pipe_ctx * pipe_ctx)3146 static void dce110_power_down_fe(struct dc *dc, struct dc_state *state, struct pipe_ctx *pipe_ctx)
3147 {
3148 struct dce_hwseq *hws = dc->hwseq;
3149 int fe_idx = pipe_ctx->plane_res.mi ?
3150 pipe_ctx->plane_res.mi->inst : pipe_ctx->pipe_idx;
3151
3152 /* Do not power down fe when stream is active on dce*/
3153 if (dc->current_state->res_ctx.pipe_ctx[fe_idx].stream)
3154 return;
3155
3156 hws->funcs.enable_display_power_gating(
3157 dc, fe_idx, dc->ctx->dc_bios, PIPE_GATING_CONTROL_ENABLE);
3158
3159 dc->res_pool->transforms[fe_idx]->funcs->transform_reset(
3160 dc->res_pool->transforms[fe_idx]);
3161 }
3162
dce110_wait_for_mpcc_disconnect(struct dc * dc,struct resource_pool * res_pool,struct pipe_ctx * pipe_ctx)3163 static void dce110_wait_for_mpcc_disconnect(
3164 struct dc *dc,
3165 struct resource_pool *res_pool,
3166 struct pipe_ctx *pipe_ctx)
3167 {
3168 /* do nothing*/
3169 }
3170
program_output_csc(struct dc * dc,struct pipe_ctx * pipe_ctx,enum dc_color_space colorspace,uint16_t * matrix,int opp_id)3171 static void program_output_csc(struct dc *dc,
3172 struct pipe_ctx *pipe_ctx,
3173 enum dc_color_space colorspace,
3174 uint16_t *matrix,
3175 int opp_id)
3176 {
3177 int i;
3178 struct out_csc_color_matrix tbl_entry;
3179
3180 if (pipe_ctx->stream->csc_color_matrix.enable_adjustment == true) {
3181 enum dc_color_space color_space = pipe_ctx->stream->output_color_space;
3182
3183 for (i = 0; i < 12; i++)
3184 tbl_entry.regval[i] = pipe_ctx->stream->csc_color_matrix.matrix[i];
3185
3186 tbl_entry.color_space = color_space;
3187
3188 pipe_ctx->plane_res.xfm->funcs->opp_set_csc_adjustment(
3189 pipe_ctx->plane_res.xfm, &tbl_entry);
3190 }
3191 }
3192
dce110_set_cursor_position(struct pipe_ctx * pipe_ctx)3193 static void dce110_set_cursor_position(struct pipe_ctx *pipe_ctx)
3194 {
3195 struct dc_cursor_position pos_cpy = pipe_ctx->stream->cursor_position;
3196 struct input_pixel_processor *ipp = pipe_ctx->plane_res.ipp;
3197 struct mem_input *mi = pipe_ctx->plane_res.mi;
3198 struct dc_cursor_mi_param param = {
3199 .pixel_clk_khz = pipe_ctx->stream->timing.pix_clk_100hz / 10,
3200 .ref_clk_khz = pipe_ctx->stream->ctx->dc->res_pool->ref_clocks.xtalin_clock_inKhz,
3201 .viewport = pipe_ctx->plane_res.scl_data.viewport,
3202 .h_scale_ratio = pipe_ctx->plane_res.scl_data.ratios.horz,
3203 .v_scale_ratio = pipe_ctx->plane_res.scl_data.ratios.vert,
3204 .rotation = pipe_ctx->plane_state->rotation,
3205 .mirror = pipe_ctx->plane_state->horizontal_mirror
3206 };
3207
3208 /**
3209 * If the cursor's source viewport is clipped then we need to
3210 * translate the cursor to appear in the correct position on
3211 * the screen.
3212 *
3213 * This translation isn't affected by scaling so it needs to be
3214 * done *after* we adjust the position for the scale factor.
3215 *
3216 * This is only done by opt-in for now since there are still
3217 * some usecases like tiled display that might enable the
3218 * cursor on both streams while expecting dc to clip it.
3219 */
3220 if (pos_cpy.translate_by_source) {
3221 pos_cpy.x += pipe_ctx->plane_state->src_rect.x;
3222 pos_cpy.y += pipe_ctx->plane_state->src_rect.y;
3223 }
3224
3225 if (pipe_ctx->plane_state->address.type
3226 == PLN_ADDR_TYPE_VIDEO_PROGRESSIVE)
3227 pos_cpy.enable = false;
3228
3229 if (pipe_ctx->top_pipe && pipe_ctx->plane_state != pipe_ctx->top_pipe->plane_state)
3230 pos_cpy.enable = false;
3231
3232 if (ipp->funcs->ipp_cursor_set_position)
3233 ipp->funcs->ipp_cursor_set_position(ipp, &pos_cpy, ¶m);
3234 if (mi->funcs->set_cursor_position)
3235 mi->funcs->set_cursor_position(mi, &pos_cpy, ¶m);
3236 }
3237
dce110_set_cursor_attribute(struct pipe_ctx * pipe_ctx)3238 static void dce110_set_cursor_attribute(struct pipe_ctx *pipe_ctx)
3239 {
3240 struct dc_cursor_attributes *attributes = &pipe_ctx->stream->cursor_attributes;
3241
3242 if (pipe_ctx->plane_res.ipp &&
3243 pipe_ctx->plane_res.ipp->funcs->ipp_cursor_set_attributes)
3244 pipe_ctx->plane_res.ipp->funcs->ipp_cursor_set_attributes(
3245 pipe_ctx->plane_res.ipp, attributes);
3246
3247 if (pipe_ctx->plane_res.mi &&
3248 pipe_ctx->plane_res.mi->funcs->set_cursor_attributes)
3249 pipe_ctx->plane_res.mi->funcs->set_cursor_attributes(
3250 pipe_ctx->plane_res.mi, attributes);
3251
3252 if (pipe_ctx->plane_res.xfm &&
3253 pipe_ctx->plane_res.xfm->funcs->set_cursor_attributes)
3254 pipe_ctx->plane_res.xfm->funcs->set_cursor_attributes(
3255 pipe_ctx->plane_res.xfm, attributes);
3256 }
3257
dce110_set_backlight_level(struct pipe_ctx * pipe_ctx,struct set_backlight_level_params * backlight_level_params)3258 bool dce110_set_backlight_level(struct pipe_ctx *pipe_ctx,
3259 struct set_backlight_level_params *backlight_level_params)
3260 {
3261 uint32_t backlight_pwm_u16_16 = backlight_level_params->backlight_pwm_u16_16;
3262 uint32_t frame_ramp = backlight_level_params->frame_ramp;
3263 struct dc_link *link = pipe_ctx->stream->link;
3264 struct dc *dc = link->ctx->dc;
3265 struct abm *abm = pipe_ctx->stream_res.abm;
3266 struct panel_cntl *panel_cntl = link->panel_cntl;
3267 struct dmcu *dmcu = dc->res_pool->dmcu;
3268 bool fw_set_brightness = true;
3269 /* DMCU -1 for all controller id values,
3270 * therefore +1 here
3271 */
3272 uint32_t controller_id = pipe_ctx->stream_res.tg->inst + 1;
3273
3274 if (abm == NULL || panel_cntl == NULL || (abm->funcs->set_backlight_level_pwm == NULL))
3275 return false;
3276
3277 if (dmcu)
3278 fw_set_brightness = dmcu->funcs->is_dmcu_initialized(dmcu);
3279
3280 if (!fw_set_brightness && panel_cntl->funcs->driver_set_backlight)
3281 panel_cntl->funcs->driver_set_backlight(panel_cntl, backlight_pwm_u16_16);
3282 else
3283 abm->funcs->set_backlight_level_pwm(
3284 abm,
3285 backlight_pwm_u16_16,
3286 frame_ramp,
3287 controller_id,
3288 link->panel_cntl->inst);
3289
3290 return true;
3291 }
3292
dce110_set_abm_immediate_disable(struct pipe_ctx * pipe_ctx)3293 void dce110_set_abm_immediate_disable(struct pipe_ctx *pipe_ctx)
3294 {
3295 struct abm *abm = pipe_ctx->stream_res.abm;
3296 struct panel_cntl *panel_cntl = pipe_ctx->stream->link->panel_cntl;
3297
3298 if (abm)
3299 abm->funcs->set_abm_immediate_disable(abm,
3300 pipe_ctx->stream->link->panel_cntl->inst);
3301
3302 if (panel_cntl)
3303 panel_cntl->funcs->store_backlight_level(panel_cntl);
3304 }
3305
dce110_set_pipe(struct pipe_ctx * pipe_ctx)3306 void dce110_set_pipe(struct pipe_ctx *pipe_ctx)
3307 {
3308 struct abm *abm = pipe_ctx->stream_res.abm;
3309 struct panel_cntl *panel_cntl = pipe_ctx->stream->link->panel_cntl;
3310 uint32_t otg_inst = pipe_ctx->stream_res.tg->inst + 1;
3311
3312 if (abm && panel_cntl)
3313 abm->funcs->set_pipe(abm, otg_inst, panel_cntl->inst);
3314 }
3315
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)3316 void dce110_enable_lvds_link_output(struct dc_link *link,
3317 const struct link_resource *link_res,
3318 enum clock_source_id clock_source,
3319 uint32_t pixel_clock)
3320 {
3321 link->link_enc->funcs->enable_lvds_output(
3322 link->link_enc,
3323 clock_source,
3324 pixel_clock);
3325 link->phy_state.symclk_state = SYMCLK_ON_TX_ON;
3326 }
3327
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)3328 void dce110_enable_tmds_link_output(struct dc_link *link,
3329 const struct link_resource *link_res,
3330 enum signal_type signal,
3331 enum clock_source_id clock_source,
3332 enum dc_color_depth color_depth,
3333 uint32_t pixel_clock)
3334 {
3335 link->link_enc->funcs->enable_tmds_output(
3336 link->link_enc,
3337 clock_source,
3338 color_depth,
3339 signal,
3340 pixel_clock);
3341 link->phy_state.symclk_state = SYMCLK_ON_TX_ON;
3342 }
3343
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)3344 void dce110_enable_dp_link_output(
3345 struct dc_link *link,
3346 const struct link_resource *link_res,
3347 enum signal_type signal,
3348 enum clock_source_id clock_source,
3349 const struct dc_link_settings *link_settings)
3350 {
3351 struct dc *dc = link->ctx->dc;
3352 struct dmcu *dmcu = dc->res_pool->dmcu;
3353 struct pipe_ctx *pipes =
3354 link->dc->current_state->res_ctx.pipe_ctx;
3355 struct clock_source *dp_cs =
3356 link->dc->res_pool->dp_clock_source;
3357 const struct link_hwss *link_hwss = get_link_hwss(link, link_res);
3358 unsigned int i;
3359
3360 /*
3361 * Add the logic to extract BOTH power up and power down sequences
3362 * from enable/disable link output and only call edp panel control
3363 * in enable_link_dp and disable_link_dp once.
3364 */
3365 if (link->connector_signal == SIGNAL_TYPE_EDP) {
3366 link->dc->hwss.edp_wait_for_hpd_ready(link, true);
3367 }
3368
3369 /* If the current pixel clock source is not DTO(happens after
3370 * switching from HDMI passive dongle to DP on the same connector),
3371 * switch the pixel clock source to DTO.
3372 */
3373
3374 for (i = 0; i < MAX_PIPES; i++) {
3375 if (pipes[i].stream != NULL &&
3376 pipes[i].stream->link == link) {
3377 if (pipes[i].clock_source != NULL &&
3378 pipes[i].clock_source->id != CLOCK_SOURCE_ID_DP_DTO) {
3379 pipes[i].clock_source = dp_cs;
3380 pipes[i].stream_res.pix_clk_params.requested_pix_clk_100hz =
3381 pipes[i].stream->timing.pix_clk_100hz;
3382 pipes[i].clock_source->funcs->program_pix_clk(
3383 pipes[i].clock_source,
3384 &pipes[i].stream_res.pix_clk_params,
3385 dc->link_srv->dp_get_encoding_format(link_settings),
3386 &pipes[i].pll_settings);
3387 }
3388 }
3389 }
3390
3391 if (dc->link_srv->dp_get_encoding_format(link_settings) == DP_8b_10b_ENCODING) {
3392 if (dc->clk_mgr->funcs->notify_link_rate_change)
3393 dc->clk_mgr->funcs->notify_link_rate_change(dc->clk_mgr, link);
3394 }
3395
3396 if (dmcu != NULL && dmcu->funcs->lock_phy)
3397 dmcu->funcs->lock_phy(dmcu);
3398
3399 if (link_hwss->ext.enable_dp_link_output)
3400 link_hwss->ext.enable_dp_link_output(link, link_res, signal,
3401 clock_source, link_settings);
3402
3403 link->phy_state.symclk_state = SYMCLK_ON_TX_ON;
3404
3405 if (dmcu != NULL && dmcu->funcs->unlock_phy)
3406 dmcu->funcs->unlock_phy(dmcu);
3407
3408 dc->link_srv->dp_trace_source_sequence(link, DPCD_SOURCE_SEQ_AFTER_ENABLE_LINK_PHY);
3409 }
3410
dce110_disable_link_output(struct dc_link * link,const struct link_resource * link_res,enum signal_type signal)3411 void dce110_disable_link_output(struct dc_link *link,
3412 const struct link_resource *link_res,
3413 enum signal_type signal)
3414 {
3415 struct dc *dc = link->ctx->dc;
3416 const struct link_hwss *link_hwss = get_link_hwss(link, link_res);
3417 struct dmcu *dmcu = dc->res_pool->dmcu;
3418
3419 if (signal == SIGNAL_TYPE_EDP &&
3420 link->dc->hwss.edp_backlight_control &&
3421 !link->skip_implict_edp_power_control)
3422 link->dc->hwss.edp_backlight_control(link, false);
3423 else if (dmcu != NULL && dmcu->funcs->lock_phy)
3424 dmcu->funcs->lock_phy(dmcu);
3425
3426 link_hwss->disable_link_output(link, link_res, signal);
3427 link->phy_state.symclk_state = SYMCLK_OFF_TX_OFF;
3428 /*
3429 * Add the logic to extract BOTH power up and power down sequences
3430 * from enable/disable link output and only call edp panel control
3431 * in enable_link_dp and disable_link_dp once.
3432 */
3433 if (dmcu != NULL && dmcu->funcs->unlock_phy)
3434 dmcu->funcs->unlock_phy(dmcu);
3435 dc->link_srv->dp_trace_source_sequence(link, DPCD_SOURCE_SEQ_AFTER_DISABLE_LINK_PHY);
3436 }
3437
3438 static const struct hw_sequencer_funcs dce110_funcs = {
3439 .program_gamut_remap = program_gamut_remap,
3440 .program_output_csc = program_output_csc,
3441 .init_hw = dce110_init_hw,
3442 .apply_ctx_to_hw = dce110_apply_ctx_to_hw,
3443 .apply_ctx_for_surface = dce110_apply_ctx_for_surface,
3444 .post_unlock_program_front_end = dce110_post_unlock_program_front_end,
3445 .update_plane_addr = update_plane_addr,
3446 .update_pending_status = dce110_update_pending_status,
3447 .clear_surface_dcc_and_tiling = dce100_reset_surface_dcc_and_tiling,
3448 .enable_accelerated_mode = dce110_enable_accelerated_mode,
3449 .enable_timing_synchronization = dce110_enable_timing_synchronization,
3450 .enable_per_frame_crtc_position_reset = dce110_enable_per_frame_crtc_position_reset,
3451 .update_info_frame = dce110_update_info_frame,
3452 .enable_stream = dce110_enable_stream,
3453 .disable_stream = dce110_disable_stream,
3454 .unblank_stream = dce110_unblank_stream,
3455 .blank_stream = dce110_blank_stream,
3456 .enable_audio_stream = dce110_enable_audio_stream,
3457 .disable_audio_stream = dce110_disable_audio_stream,
3458 .disable_plane = dce110_power_down_fe,
3459 .pipe_control_lock = dce_pipe_control_lock,
3460 .interdependent_update_lock = NULL,
3461 .cursor_lock = dce_pipe_control_lock,
3462 .prepare_bandwidth = dce110_prepare_bandwidth,
3463 .optimize_bandwidth = dce110_optimize_bandwidth,
3464 .set_drr = set_drr,
3465 .get_position = get_position,
3466 .set_static_screen_control = set_static_screen_control,
3467 .setup_stereo = NULL,
3468 .set_avmute = dce110_set_avmute,
3469 .wait_for_mpcc_disconnect = dce110_wait_for_mpcc_disconnect,
3470 .edp_backlight_control = dce110_edp_backlight_control,
3471 .edp_power_control = dce110_edp_power_control,
3472 .edp_wait_for_hpd_ready = dce110_edp_wait_for_hpd_ready,
3473 .set_cursor_position = dce110_set_cursor_position,
3474 .set_cursor_attribute = dce110_set_cursor_attribute,
3475 .set_backlight_level = dce110_set_backlight_level,
3476 .set_abm_immediate_disable = dce110_set_abm_immediate_disable,
3477 .set_pipe = dce110_set_pipe,
3478 .enable_lvds_link_output = dce110_enable_lvds_link_output,
3479 .enable_tmds_link_output = dce110_enable_tmds_link_output,
3480 .enable_dp_link_output = dce110_enable_dp_link_output,
3481 .disable_link_output = dce110_disable_link_output,
3482 };
3483
3484 static const struct hwseq_private_funcs dce110_private_funcs = {
3485 .init_pipes = dce110_init_pipes,
3486 .set_input_transfer_func = dce110_set_input_transfer_func,
3487 .set_output_transfer_func = dce110_set_output_transfer_func,
3488 .power_down = dce110_power_down,
3489 .enable_display_pipe_clock_gating = enable_display_pipe_clock_gating,
3490 .enable_display_power_gating = dce110_enable_display_power_gating,
3491 .reset_hw_ctx_wrap = dce110_reset_hw_ctx_wrap,
3492 .enable_stream_timing = dce110_enable_stream_timing,
3493 .disable_stream_gating = NULL,
3494 .enable_stream_gating = NULL,
3495 .edp_backlight_control = dce110_edp_backlight_control,
3496 };
3497
dce110_hw_sequencer_construct(struct dc * dc)3498 void dce110_hw_sequencer_construct(struct dc *dc)
3499 {
3500 dc->hwss = dce110_funcs;
3501 dc->hwseq->funcs = dce110_private_funcs;
3502 }
3503
3504