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