1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26#include <linux/delay.h>
27
28#include "dm_services.h"
29#include "dc.h"
30#include "dc_bios_types.h"
31#include "core_types.h"
32#include "core_status.h"
33#include "resource.h"
34#include "dm_helpers.h"
35#include "dce110_timing_generator.h"
36#include "dce/dce_hwseq.h"
37#include "gpio_service_interface.h"
38
39#include "dce110_compressor.h"
40
41#include "bios/bios_parser_helper.h"
42#include "timing_generator.h"
43#include "mem_input.h"
44#include "opp.h"
45#include "ipp.h"
46#include "transform.h"
47#include "stream_encoder.h"
48#include "link_encoder.h"
49#include "link_hwss.h"
50#include "dc_link_dp.h"
51#if defined(CONFIG_DRM_AMD_DC_DCN)
52#include "dccg.h"
53#endif
54#include "clock_source.h"
55#include "clk_mgr.h"
56#include "abm.h"
57#include "audio.h"
58#include "reg_helper.h"
59#include "panel_cntl.h"
60
61
62#include "dce/dce_11_0_d.h"
63#include "dce/dce_11_0_sh_mask.h"
64#include "custom_float.h"
65
66#include "atomfirmware.h"
67
68#include "dcn10/dcn10_hw_sequencer.h"
69
70#define GAMMA_HW_POINTS_NUM 256
71
72
73
74
75
76
77#define PANEL_POWER_UP_TIMEOUT 300
78#define PANEL_POWER_DOWN_TIMEOUT 500
79#define HPD_CHECK_INTERVAL 10
80#define OLED_POST_T7_DELAY 100
81#define OLED_PRE_T11_DELAY 150
82
83#define CTX \
84 hws->ctx
85
86#define DC_LOGGER_INIT()
87
88#define REG(reg)\
89 hws->regs->reg
90
91#undef FN
92#define FN(reg_name, field_name) \
93 hws->shifts->field_name, hws->masks->field_name
94
95struct dce110_hw_seq_reg_offsets {
96 uint32_t crtc;
97};
98
99static const struct dce110_hw_seq_reg_offsets reg_offsets[] = {
100{
101 .crtc = (mmCRTC0_CRTC_GSL_CONTROL - mmCRTC_GSL_CONTROL),
102},
103{
104 .crtc = (mmCRTC1_CRTC_GSL_CONTROL - mmCRTC_GSL_CONTROL),
105},
106{
107 .crtc = (mmCRTC2_CRTC_GSL_CONTROL - mmCRTC_GSL_CONTROL),
108},
109{
110 .crtc = (mmCRTCV_GSL_CONTROL - mmCRTC_GSL_CONTROL),
111}
112};
113
114#define HW_REG_BLND(reg, id)\
115 (reg + reg_offsets[id].blnd)
116
117#define HW_REG_CRTC(reg, id)\
118 (reg + reg_offsets[id].crtc)
119
120#define MAX_WATERMARK 0xFFFF
121#define SAFE_NBP_MARK 0x7FFF
122
123
124
125
126
127static void dce110_init_pte(struct dc_context *ctx)
128{
129 uint32_t addr;
130 uint32_t value = 0;
131 uint32_t chunk_int = 0;
132 uint32_t chunk_mul = 0;
133
134 addr = mmUNP_DVMM_PTE_CONTROL;
135 value = dm_read_reg(ctx, addr);
136
137 set_reg_field_value(
138 value,
139 0,
140 DVMM_PTE_CONTROL,
141 DVMM_USE_SINGLE_PTE);
142
143 set_reg_field_value(
144 value,
145 1,
146 DVMM_PTE_CONTROL,
147 DVMM_PTE_BUFFER_MODE0);
148
149 set_reg_field_value(
150 value,
151 1,
152 DVMM_PTE_CONTROL,
153 DVMM_PTE_BUFFER_MODE1);
154
155 dm_write_reg(ctx, addr, value);
156
157 addr = mmDVMM_PTE_REQ;
158 value = dm_read_reg(ctx, addr);
159
160 chunk_int = get_reg_field_value(
161 value,
162 DVMM_PTE_REQ,
163 HFLIP_PTEREQ_PER_CHUNK_INT);
164
165 chunk_mul = get_reg_field_value(
166 value,
167 DVMM_PTE_REQ,
168 HFLIP_PTEREQ_PER_CHUNK_MULTIPLIER);
169
170 if (chunk_int != 0x4 || chunk_mul != 0x4) {
171
172 set_reg_field_value(
173 value,
174 255,
175 DVMM_PTE_REQ,
176 MAX_PTEREQ_TO_ISSUE);
177
178 set_reg_field_value(
179 value,
180 4,
181 DVMM_PTE_REQ,
182 HFLIP_PTEREQ_PER_CHUNK_INT);
183
184 set_reg_field_value(
185 value,
186 4,
187 DVMM_PTE_REQ,
188 HFLIP_PTEREQ_PER_CHUNK_MULTIPLIER);
189
190 dm_write_reg(ctx, addr, value);
191 }
192}
193
194
195static void enable_display_pipe_clock_gating(
196 struct dc_context *ctx,
197 bool clock_gating)
198{
199
200}
201
202static bool dce110_enable_display_power_gating(
203 struct dc *dc,
204 uint8_t controller_id,
205 struct dc_bios *dcb,
206 enum pipe_gating_control power_gating)
207{
208 enum bp_result bp_result = BP_RESULT_OK;
209 enum bp_pipe_control_action cntl;
210 struct dc_context *ctx = dc->ctx;
211 unsigned int underlay_idx = dc->res_pool->underlay_pipe_index;
212
213 if (IS_FPGA_MAXIMUS_DC(ctx->dce_environment))
214 return true;
215
216 if (power_gating == PIPE_GATING_CONTROL_INIT)
217 cntl = ASIC_PIPE_INIT;
218 else if (power_gating == PIPE_GATING_CONTROL_ENABLE)
219 cntl = ASIC_PIPE_ENABLE;
220 else
221 cntl = ASIC_PIPE_DISABLE;
222
223 if (controller_id == underlay_idx)
224 controller_id = CONTROLLER_ID_UNDERLAY0 - 1;
225
226 if (power_gating != PIPE_GATING_CONTROL_INIT || controller_id == 0){
227
228 bp_result = dcb->funcs->enable_disp_power_gating(
229 dcb, controller_id + 1, cntl);
230
231
232
233
234
235
236
237
238 if (controller_id < CONTROLLER_ID_MAX - 1)
239 dm_write_reg(ctx,
240 HW_REG_CRTC(mmCRTC_MASTER_UPDATE_MODE, controller_id),
241 0);
242 }
243
244 if (power_gating != PIPE_GATING_CONTROL_ENABLE)
245 dce110_init_pte(ctx);
246
247 if (bp_result == BP_RESULT_OK)
248 return true;
249 else
250 return false;
251}
252
253static void build_prescale_params(struct ipp_prescale_params *prescale_params,
254 const struct dc_plane_state *plane_state)
255{
256 prescale_params->mode = IPP_PRESCALE_MODE_FIXED_UNSIGNED;
257
258 switch (plane_state->format) {
259 case SURFACE_PIXEL_FORMAT_GRPH_RGB565:
260 prescale_params->scale = 0x2082;
261 break;
262 case SURFACE_PIXEL_FORMAT_GRPH_ARGB8888:
263 case SURFACE_PIXEL_FORMAT_GRPH_ABGR8888:
264 prescale_params->scale = 0x2020;
265 break;
266 case SURFACE_PIXEL_FORMAT_GRPH_ARGB2101010:
267 case SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010:
268 prescale_params->scale = 0x2008;
269 break;
270 case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616:
271 case SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616:
272 case SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616F:
273 prescale_params->scale = 0x2000;
274 break;
275 default:
276 ASSERT(false);
277 break;
278 }
279}
280
281static bool
282dce110_set_input_transfer_func(struct dc *dc, struct pipe_ctx *pipe_ctx,
283 const struct dc_plane_state *plane_state)
284{
285 struct input_pixel_processor *ipp = pipe_ctx->plane_res.ipp;
286 const struct dc_transfer_func *tf = NULL;
287 struct ipp_prescale_params prescale_params = { 0 };
288 bool result = true;
289
290 if (ipp == NULL)
291 return false;
292
293 if (plane_state->in_transfer_func)
294 tf = plane_state->in_transfer_func;
295
296 build_prescale_params(&prescale_params, plane_state);
297 ipp->funcs->ipp_program_prescale(ipp, &prescale_params);
298
299 if (plane_state->gamma_correction &&
300 !plane_state->gamma_correction->is_identity &&
301 dce_use_lut(plane_state->format))
302 ipp->funcs->ipp_program_input_lut(ipp, plane_state->gamma_correction);
303
304 if (tf == NULL) {
305
306 ipp->funcs->ipp_set_degamma(ipp, IPP_DEGAMMA_MODE_HW_sRGB);
307 } else if (tf->type == TF_TYPE_PREDEFINED) {
308 switch (tf->tf) {
309 case TRANSFER_FUNCTION_SRGB:
310 ipp->funcs->ipp_set_degamma(ipp, IPP_DEGAMMA_MODE_HW_sRGB);
311 break;
312 case TRANSFER_FUNCTION_BT709:
313 ipp->funcs->ipp_set_degamma(ipp, IPP_DEGAMMA_MODE_HW_xvYCC);
314 break;
315 case TRANSFER_FUNCTION_LINEAR:
316 ipp->funcs->ipp_set_degamma(ipp, IPP_DEGAMMA_MODE_BYPASS);
317 break;
318 case TRANSFER_FUNCTION_PQ:
319 default:
320 result = false;
321 break;
322 }
323 } else if (tf->type == TF_TYPE_BYPASS) {
324 ipp->funcs->ipp_set_degamma(ipp, IPP_DEGAMMA_MODE_BYPASS);
325 } else {
326
327 result = false;
328 }
329
330 return result;
331}
332
333static bool convert_to_custom_float(struct pwl_result_data *rgb_resulted,
334 struct curve_points *arr_points,
335 uint32_t hw_points_num)
336{
337 struct custom_float_format fmt;
338
339 struct pwl_result_data *rgb = rgb_resulted;
340
341 uint32_t i = 0;
342
343 fmt.exponenta_bits = 6;
344 fmt.mantissa_bits = 12;
345 fmt.sign = true;
346
347 if (!convert_to_custom_float_format(arr_points[0].x, &fmt,
348 &arr_points[0].custom_float_x)) {
349 BREAK_TO_DEBUGGER();
350 return false;
351 }
352
353 if (!convert_to_custom_float_format(arr_points[0].offset, &fmt,
354 &arr_points[0].custom_float_offset)) {
355 BREAK_TO_DEBUGGER();
356 return false;
357 }
358
359 if (!convert_to_custom_float_format(arr_points[0].slope, &fmt,
360 &arr_points[0].custom_float_slope)) {
361 BREAK_TO_DEBUGGER();
362 return false;
363 }
364
365 fmt.mantissa_bits = 10;
366 fmt.sign = false;
367
368 if (!convert_to_custom_float_format(arr_points[1].x, &fmt,
369 &arr_points[1].custom_float_x)) {
370 BREAK_TO_DEBUGGER();
371 return false;
372 }
373
374 if (!convert_to_custom_float_format(arr_points[1].y, &fmt,
375 &arr_points[1].custom_float_y)) {
376 BREAK_TO_DEBUGGER();
377 return false;
378 }
379
380 if (!convert_to_custom_float_format(arr_points[1].slope, &fmt,
381 &arr_points[1].custom_float_slope)) {
382 BREAK_TO_DEBUGGER();
383 return false;
384 }
385
386 fmt.mantissa_bits = 12;
387 fmt.sign = true;
388
389 while (i != hw_points_num) {
390 if (!convert_to_custom_float_format(rgb->red, &fmt,
391 &rgb->red_reg)) {
392 BREAK_TO_DEBUGGER();
393 return false;
394 }
395
396 if (!convert_to_custom_float_format(rgb->green, &fmt,
397 &rgb->green_reg)) {
398 BREAK_TO_DEBUGGER();
399 return false;
400 }
401
402 if (!convert_to_custom_float_format(rgb->blue, &fmt,
403 &rgb->blue_reg)) {
404 BREAK_TO_DEBUGGER();
405 return false;
406 }
407
408 if (!convert_to_custom_float_format(rgb->delta_red, &fmt,
409 &rgb->delta_red_reg)) {
410 BREAK_TO_DEBUGGER();
411 return false;
412 }
413
414 if (!convert_to_custom_float_format(rgb->delta_green, &fmt,
415 &rgb->delta_green_reg)) {
416 BREAK_TO_DEBUGGER();
417 return false;
418 }
419
420 if (!convert_to_custom_float_format(rgb->delta_blue, &fmt,
421 &rgb->delta_blue_reg)) {
422 BREAK_TO_DEBUGGER();
423 return false;
424 }
425
426 ++rgb;
427 ++i;
428 }
429
430 return true;
431}
432
433#define MAX_LOW_POINT 25
434#define NUMBER_REGIONS 16
435#define NUMBER_SW_SEGMENTS 16
436
437static bool
438dce110_translate_regamma_to_hw_format(const struct dc_transfer_func *output_tf,
439 struct pwl_params *regamma_params)
440{
441 struct curve_points *arr_points;
442 struct pwl_result_data *rgb_resulted;
443 struct pwl_result_data *rgb;
444 struct pwl_result_data *rgb_plus_1;
445 struct fixed31_32 y_r;
446 struct fixed31_32 y_g;
447 struct fixed31_32 y_b;
448 struct fixed31_32 y1_min;
449 struct fixed31_32 y3_max;
450
451 int32_t region_start, region_end;
452 uint32_t i, j, k, seg_distr[NUMBER_REGIONS], increment, start_index, hw_points;
453
454 if (output_tf == NULL || regamma_params == NULL || output_tf->type == TF_TYPE_BYPASS)
455 return false;
456
457 arr_points = regamma_params->arr_points;
458 rgb_resulted = regamma_params->rgb_resulted;
459 hw_points = 0;
460
461 memset(regamma_params, 0, sizeof(struct pwl_params));
462
463 if (output_tf->tf == TRANSFER_FUNCTION_PQ) {
464
465
466
467 region_start = -11;
468 region_end = region_start + NUMBER_REGIONS;
469
470 for (i = 0; i < NUMBER_REGIONS; i++)
471 seg_distr[i] = 4;
472
473 } else {
474
475
476
477
478
479
480 region_start = -10;
481 region_end = 1;
482
483 seg_distr[0] = 4;
484 seg_distr[1] = 4;
485 seg_distr[2] = 4;
486 seg_distr[3] = 4;
487 seg_distr[4] = 4;
488 seg_distr[5] = 4;
489 seg_distr[6] = 4;
490 seg_distr[7] = 4;
491 seg_distr[8] = 4;
492 seg_distr[9] = 4;
493 seg_distr[10] = 0;
494 seg_distr[11] = -1;
495 seg_distr[12] = -1;
496 seg_distr[13] = -1;
497 seg_distr[14] = -1;
498 seg_distr[15] = -1;
499 }
500
501 for (k = 0; k < 16; k++) {
502 if (seg_distr[k] != -1)
503 hw_points += (1 << seg_distr[k]);
504 }
505
506 j = 0;
507 for (k = 0; k < (region_end - region_start); k++) {
508 increment = NUMBER_SW_SEGMENTS / (1 << seg_distr[k]);
509 start_index = (region_start + k + MAX_LOW_POINT) *
510 NUMBER_SW_SEGMENTS;
511 for (i = start_index; i < start_index + NUMBER_SW_SEGMENTS;
512 i += increment) {
513 if (j == hw_points - 1)
514 break;
515 rgb_resulted[j].red = output_tf->tf_pts.red[i];
516 rgb_resulted[j].green = output_tf->tf_pts.green[i];
517 rgb_resulted[j].blue = output_tf->tf_pts.blue[i];
518 j++;
519 }
520 }
521
522
523 start_index = (region_end + MAX_LOW_POINT) * NUMBER_SW_SEGMENTS;
524 rgb_resulted[hw_points - 1].red = output_tf->tf_pts.red[start_index];
525 rgb_resulted[hw_points - 1].green = output_tf->tf_pts.green[start_index];
526 rgb_resulted[hw_points - 1].blue = output_tf->tf_pts.blue[start_index];
527
528 arr_points[0].x = dc_fixpt_pow(dc_fixpt_from_int(2),
529 dc_fixpt_from_int(region_start));
530 arr_points[1].x = dc_fixpt_pow(dc_fixpt_from_int(2),
531 dc_fixpt_from_int(region_end));
532
533 y_r = rgb_resulted[0].red;
534 y_g = rgb_resulted[0].green;
535 y_b = rgb_resulted[0].blue;
536
537 y1_min = dc_fixpt_min(y_r, dc_fixpt_min(y_g, y_b));
538
539 arr_points[0].y = y1_min;
540 arr_points[0].slope = dc_fixpt_div(arr_points[0].y,
541 arr_points[0].x);
542
543 y_r = rgb_resulted[hw_points - 1].red;
544 y_g = rgb_resulted[hw_points - 1].green;
545 y_b = rgb_resulted[hw_points - 1].blue;
546
547
548
549
550 y3_max = dc_fixpt_max(y_r, dc_fixpt_max(y_g, y_b));
551
552 arr_points[1].y = y3_max;
553
554 arr_points[1].slope = dc_fixpt_zero;
555
556 if (output_tf->tf == TRANSFER_FUNCTION_PQ) {
557
558
559
560 const struct fixed31_32 end_value = dc_fixpt_from_int(125);
561
562 arr_points[1].slope = dc_fixpt_div(
563 dc_fixpt_sub(dc_fixpt_one, arr_points[1].y),
564 dc_fixpt_sub(end_value, arr_points[1].x));
565 }
566
567 regamma_params->hw_points_num = hw_points;
568
569 k = 0;
570 for (i = 1; i < 16; i++) {
571 if (seg_distr[k] != -1) {
572 regamma_params->arr_curve_points[k].segments_num = seg_distr[k];
573 regamma_params->arr_curve_points[i].offset =
574 regamma_params->arr_curve_points[k].offset + (1 << seg_distr[k]);
575 }
576 k++;
577 }
578
579 if (seg_distr[k] != -1)
580 regamma_params->arr_curve_points[k].segments_num = seg_distr[k];
581
582 rgb = rgb_resulted;
583 rgb_plus_1 = rgb_resulted + 1;
584
585 i = 1;
586
587 while (i != hw_points + 1) {
588 if (dc_fixpt_lt(rgb_plus_1->red, rgb->red))
589 rgb_plus_1->red = rgb->red;
590 if (dc_fixpt_lt(rgb_plus_1->green, rgb->green))
591 rgb_plus_1->green = rgb->green;
592 if (dc_fixpt_lt(rgb_plus_1->blue, rgb->blue))
593 rgb_plus_1->blue = rgb->blue;
594
595 rgb->delta_red = dc_fixpt_sub(rgb_plus_1->red, rgb->red);
596 rgb->delta_green = dc_fixpt_sub(rgb_plus_1->green, rgb->green);
597 rgb->delta_blue = dc_fixpt_sub(rgb_plus_1->blue, rgb->blue);
598
599 ++rgb_plus_1;
600 ++rgb;
601 ++i;
602 }
603
604 convert_to_custom_float(rgb_resulted, arr_points, hw_points);
605
606 return true;
607}
608
609static bool
610dce110_set_output_transfer_func(struct dc *dc, struct pipe_ctx *pipe_ctx,
611 const struct dc_stream_state *stream)
612{
613 struct transform *xfm = pipe_ctx->plane_res.xfm;
614
615 xfm->funcs->opp_power_on_regamma_lut(xfm, true);
616 xfm->regamma_params.hw_points_num = GAMMA_HW_POINTS_NUM;
617
618 if (stream->out_transfer_func &&
619 stream->out_transfer_func->type == TF_TYPE_PREDEFINED &&
620 stream->out_transfer_func->tf == TRANSFER_FUNCTION_SRGB) {
621 xfm->funcs->opp_set_regamma_mode(xfm, OPP_REGAMMA_SRGB);
622 } else if (dce110_translate_regamma_to_hw_format(stream->out_transfer_func,
623 &xfm->regamma_params)) {
624 xfm->funcs->opp_program_regamma_pwl(xfm, &xfm->regamma_params);
625 xfm->funcs->opp_set_regamma_mode(xfm, OPP_REGAMMA_USER);
626 } else {
627 xfm->funcs->opp_set_regamma_mode(xfm, OPP_REGAMMA_BYPASS);
628 }
629
630 xfm->funcs->opp_power_on_regamma_lut(xfm, false);
631
632 return true;
633}
634
635void dce110_update_info_frame(struct pipe_ctx *pipe_ctx)
636{
637 bool is_hdmi_tmds;
638 bool is_dp;
639
640 ASSERT(pipe_ctx->stream);
641
642 if (pipe_ctx->stream_res.stream_enc == NULL)
643 return;
644
645 is_hdmi_tmds = dc_is_hdmi_tmds_signal(pipe_ctx->stream->signal);
646 is_dp = dc_is_dp_signal(pipe_ctx->stream->signal);
647
648 if (!is_hdmi_tmds && !is_dp)
649 return;
650
651 if (is_hdmi_tmds)
652 pipe_ctx->stream_res.stream_enc->funcs->update_hdmi_info_packets(
653 pipe_ctx->stream_res.stream_enc,
654 &pipe_ctx->stream_res.encoder_info_frame);
655 else
656 pipe_ctx->stream_res.stream_enc->funcs->update_dp_info_packets(
657 pipe_ctx->stream_res.stream_enc,
658 &pipe_ctx->stream_res.encoder_info_frame);
659}
660
661void dce110_enable_stream(struct pipe_ctx *pipe_ctx)
662{
663 enum dc_lane_count lane_count =
664 pipe_ctx->stream->link->cur_link_settings.lane_count;
665 struct dc_crtc_timing *timing = &pipe_ctx->stream->timing;
666 struct dc_link *link = pipe_ctx->stream->link;
667 const struct dc *dc = link->dc;
668
669 uint32_t active_total_with_borders;
670 uint32_t early_control = 0;
671 struct timing_generator *tg = pipe_ctx->stream_res.tg;
672
673
674
675
676
677 link->link_enc->funcs->connect_dig_be_to_fe(link->link_enc,
678 pipe_ctx->stream_res.stream_enc->id, true);
679
680 dc->hwss.update_info_frame(pipe_ctx);
681
682
683 active_total_with_borders =
684 timing->h_addressable
685 + timing->h_border_left
686 + timing->h_border_right;
687
688 if (lane_count != 0)
689 early_control = active_total_with_borders % lane_count;
690
691 if (early_control == 0)
692 early_control = lane_count;
693
694 tg->funcs->set_early_control(tg, early_control);
695
696
697 if (pipe_ctx->stream_res.audio != NULL) {
698 if (dc_is_dp_signal(pipe_ctx->stream->signal))
699 pipe_ctx->stream_res.stream_enc->funcs->dp_audio_enable(pipe_ctx->stream_res.stream_enc);
700 }
701
702
703
704
705}
706
707static enum bp_result link_transmitter_control(
708 struct dc_bios *bios,
709 struct bp_transmitter_control *cntl)
710{
711 enum bp_result result;
712
713 result = bios->funcs->transmitter_control(bios, cntl);
714
715 return result;
716}
717
718
719
720
721
722void dce110_edp_wait_for_hpd_ready(
723 struct dc_link *link,
724 bool power_up)
725{
726 struct dc_context *ctx = link->ctx;
727 struct graphics_object_id connector = link->link_enc->connector;
728 struct gpio *hpd;
729 struct dc_sink *sink = link->local_sink;
730 bool edp_hpd_high = false;
731 uint32_t time_elapsed = 0;
732 uint32_t timeout = power_up ?
733 PANEL_POWER_UP_TIMEOUT : PANEL_POWER_DOWN_TIMEOUT;
734
735 if (dal_graphics_object_id_get_connector_id(connector)
736 != CONNECTOR_ID_EDP) {
737 BREAK_TO_DEBUGGER();
738 return;
739 }
740
741 if (!power_up)
742
743
744
745
746 return;
747
748
749
750
751
752
753
754
755 hpd = get_hpd_gpio(ctx->dc_bios, connector, ctx->gpio_service);
756
757 if (!hpd) {
758 BREAK_TO_DEBUGGER();
759 return;
760 }
761
762 if (sink != NULL) {
763 if (sink->edid_caps.panel_patch.extra_t3_ms > 0) {
764 int extra_t3_in_ms = sink->edid_caps.panel_patch.extra_t3_ms;
765
766 msleep(extra_t3_in_ms);
767 }
768 }
769
770 dal_gpio_open(hpd, GPIO_MODE_INTERRUPT);
771
772
773
774 do {
775 uint32_t detected = 0;
776
777 dal_gpio_get_value(hpd, &detected);
778
779 if (!(detected ^ power_up)) {
780 edp_hpd_high = true;
781 break;
782 }
783
784 msleep(HPD_CHECK_INTERVAL);
785
786 time_elapsed += HPD_CHECK_INTERVAL;
787 } while (time_elapsed < timeout);
788
789 dal_gpio_close(hpd);
790
791 dal_gpio_destroy_irq(&hpd);
792
793 if (false == edp_hpd_high) {
794 DC_LOG_ERROR(
795 "%s: wait timed out!\n", __func__);
796 }
797}
798
799void dce110_edp_power_control(
800 struct dc_link *link,
801 bool power_up)
802{
803 struct dc_context *ctx = link->ctx;
804 struct bp_transmitter_control cntl = { 0 };
805 enum bp_result bp_result;
806 uint8_t panel_instance;
807
808
809 if (dal_graphics_object_id_get_connector_id(link->link_enc->connector)
810 != CONNECTOR_ID_EDP) {
811 BREAK_TO_DEBUGGER();
812 return;
813 }
814
815 if (!link->panel_cntl)
816 return;
817 if (power_up !=
818 link->panel_cntl->funcs->is_panel_powered_on(link->panel_cntl)) {
819
820 unsigned long long current_ts = dm_get_timestamp(ctx);
821 unsigned long long time_since_edp_poweroff_ms =
822 div64_u64(dm_get_elapse_time_in_ns(
823 ctx,
824 current_ts,
825 link->link_trace.time_stamp.edp_poweroff), 1000000);
826 unsigned long long time_since_edp_poweron_ms =
827 div64_u64(dm_get_elapse_time_in_ns(
828 ctx,
829 current_ts,
830 link->link_trace.time_stamp.edp_poweron), 1000000);
831 DC_LOG_HW_RESUME_S3(
832 "%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",
833 __func__,
834 power_up,
835 current_ts,
836 link->link_trace.time_stamp.edp_poweroff,
837 link->link_trace.time_stamp.edp_poweron,
838 time_since_edp_poweroff_ms,
839 time_since_edp_poweron_ms);
840
841
842 if (power_up) {
843
844 unsigned long long remaining_min_edp_poweroff_time_ms = 500;
845
846
847 if (link->local_sink != NULL)
848 remaining_min_edp_poweroff_time_ms +=
849 link->local_sink->edid_caps.panel_patch.extra_t12_ms;
850
851
852 if (link->link_trace.time_stamp.edp_poweroff != 0) {
853 if (time_since_edp_poweroff_ms < remaining_min_edp_poweroff_time_ms)
854 remaining_min_edp_poweroff_time_ms =
855 remaining_min_edp_poweroff_time_ms - time_since_edp_poweroff_ms;
856 else
857 remaining_min_edp_poweroff_time_ms = 0;
858 }
859
860 if (remaining_min_edp_poweroff_time_ms) {
861 DC_LOG_HW_RESUME_S3(
862 "%s: remaining_min_edp_poweroff_time_ms=%llu: begin wait.\n",
863 __func__, remaining_min_edp_poweroff_time_ms);
864 msleep(remaining_min_edp_poweroff_time_ms);
865 DC_LOG_HW_RESUME_S3(
866 "%s: remaining_min_edp_poweroff_time_ms=%llu: end wait.\n",
867 __func__, remaining_min_edp_poweroff_time_ms);
868 dm_output_to_console("%s: wait %lld ms to power on eDP.\n",
869 __func__, remaining_min_edp_poweroff_time_ms);
870 } else {
871 DC_LOG_HW_RESUME_S3(
872 "%s: remaining_min_edp_poweroff_time_ms=%llu: no wait required.\n",
873 __func__, remaining_min_edp_poweroff_time_ms);
874 }
875 }
876
877 DC_LOG_HW_RESUME_S3(
878 "%s: BEGIN: Panel Power action: %s\n",
879 __func__, (power_up ? "On":"Off"));
880
881 cntl.action = power_up ?
882 TRANSMITTER_CONTROL_POWER_ON :
883 TRANSMITTER_CONTROL_POWER_OFF;
884 cntl.transmitter = link->link_enc->transmitter;
885 cntl.connector_obj_id = link->link_enc->connector;
886 cntl.coherent = false;
887 cntl.lanes_number = LANE_COUNT_FOUR;
888 cntl.hpd_sel = link->link_enc->hpd_source;
889 panel_instance = link->panel_cntl->inst;
890
891 if (ctx->dc->ctx->dmub_srv &&
892 ctx->dc->debug.dmub_command_table) {
893 if (cntl.action == TRANSMITTER_CONTROL_POWER_ON)
894 bp_result = ctx->dc_bios->funcs->enable_lvtma_control(ctx->dc_bios,
895 LVTMA_CONTROL_POWER_ON,
896 panel_instance);
897 else
898 bp_result = ctx->dc_bios->funcs->enable_lvtma_control(ctx->dc_bios,
899 LVTMA_CONTROL_POWER_OFF,
900 panel_instance);
901 }
902
903 bp_result = link_transmitter_control(ctx->dc_bios, &cntl);
904
905 DC_LOG_HW_RESUME_S3(
906 "%s: END: Panel Power action: %s bp_result=%u\n",
907 __func__, (power_up ? "On":"Off"),
908 bp_result);
909
910 if (!power_up)
911
912 link->link_trace.time_stamp.edp_poweroff = dm_get_timestamp(ctx);
913 else
914 link->link_trace.time_stamp.edp_poweron = dm_get_timestamp(ctx);
915
916 DC_LOG_HW_RESUME_S3(
917 "%s: updated values: edp_poweroff=%llu edp_poweron=%llu\n",
918 __func__,
919 link->link_trace.time_stamp.edp_poweroff,
920 link->link_trace.time_stamp.edp_poweron);
921
922 if (bp_result != BP_RESULT_OK)
923 DC_LOG_ERROR(
924 "%s: Panel Power bp_result: %d\n",
925 __func__, bp_result);
926 } else {
927 DC_LOG_HW_RESUME_S3(
928 "%s: Skipping Panel Power action: %s\n",
929 __func__, (power_up ? "On":"Off"));
930 }
931}
932
933void dce110_edp_wait_for_T12(
934 struct dc_link *link)
935{
936 struct dc_context *ctx = link->ctx;
937
938 if (dal_graphics_object_id_get_connector_id(link->link_enc->connector)
939 != CONNECTOR_ID_EDP) {
940 BREAK_TO_DEBUGGER();
941 return;
942 }
943
944 if (!link->panel_cntl)
945 return;
946
947 if (!link->panel_cntl->funcs->is_panel_powered_on(link->panel_cntl) &&
948 link->link_trace.time_stamp.edp_poweroff != 0) {
949 unsigned int t12_duration = 500;
950 unsigned long long current_ts = dm_get_timestamp(ctx);
951 unsigned long long time_since_edp_poweroff_ms =
952 div64_u64(dm_get_elapse_time_in_ns(
953 ctx,
954 current_ts,
955 link->link_trace.time_stamp.edp_poweroff), 1000000);
956
957 t12_duration += link->local_sink->edid_caps.panel_patch.extra_t12_ms;
958
959 if (time_since_edp_poweroff_ms < t12_duration)
960 msleep(t12_duration - time_since_edp_poweroff_ms);
961 }
962}
963
964
965
966
967
968
969void dce110_edp_backlight_control(
970 struct dc_link *link,
971 bool enable)
972{
973 struct dc_context *ctx = link->ctx;
974 struct bp_transmitter_control cntl = { 0 };
975 uint8_t panel_instance;
976
977 if (dal_graphics_object_id_get_connector_id(link->link_enc->connector)
978 != CONNECTOR_ID_EDP) {
979 BREAK_TO_DEBUGGER();
980 return;
981 }
982
983 if (link->panel_cntl) {
984 bool is_backlight_on = link->panel_cntl->funcs->is_panel_backlight_on(link->panel_cntl);
985
986 if ((enable && is_backlight_on) || (!enable && !is_backlight_on)) {
987 DC_LOG_HW_RESUME_S3(
988 "%s: panel already powered up/off. Do nothing.\n",
989 __func__);
990 return;
991 }
992 }
993
994
995
996 DC_LOG_HW_RESUME_S3(
997 "%s: backlight action: %s\n",
998 __func__, (enable ? "On":"Off"));
999
1000 cntl.action = enable ?
1001 TRANSMITTER_CONTROL_BACKLIGHT_ON :
1002 TRANSMITTER_CONTROL_BACKLIGHT_OFF;
1003
1004
1005 cntl.transmitter = link->link_enc->transmitter;
1006 cntl.connector_obj_id = link->link_enc->connector;
1007
1008 cntl.lanes_number = LANE_COUNT_FOUR;
1009 cntl.hpd_sel = link->link_enc->hpd_source;
1010 cntl.signal = SIGNAL_TYPE_EDP;
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024 panel_instance = link->panel_cntl->inst;
1025
1026 if (cntl.action == TRANSMITTER_CONTROL_BACKLIGHT_ON) {
1027 if (!link->dc->config.edp_no_power_sequencing)
1028
1029
1030
1031
1032
1033
1034
1035 edp_receiver_ready_T7(link);
1036 else
1037 DC_LOG_DC("edp_receiver_ready_T7 skipped\n");
1038 }
1039
1040 if (ctx->dc->ctx->dmub_srv &&
1041 ctx->dc->debug.dmub_command_table) {
1042 if (cntl.action == TRANSMITTER_CONTROL_BACKLIGHT_ON)
1043 ctx->dc_bios->funcs->enable_lvtma_control(ctx->dc_bios,
1044 LVTMA_CONTROL_LCD_BLON,
1045 panel_instance);
1046 else
1047 ctx->dc_bios->funcs->enable_lvtma_control(ctx->dc_bios,
1048 LVTMA_CONTROL_LCD_BLOFF,
1049 panel_instance);
1050 }
1051
1052 link_transmitter_control(ctx->dc_bios, &cntl);
1053
1054 if (enable && link->dpcd_sink_ext_caps.bits.oled)
1055 msleep(OLED_POST_T7_DELAY);
1056
1057 if (link->dpcd_sink_ext_caps.bits.oled ||
1058 link->dpcd_sink_ext_caps.bits.hdr_aux_backlight_control == 1 ||
1059 link->dpcd_sink_ext_caps.bits.sdr_aux_backlight_control == 1)
1060 dc_link_backlight_enable_aux(link, enable);
1061
1062
1063 if (cntl.action == TRANSMITTER_CONTROL_BACKLIGHT_OFF) {
1064 if (!link->dc->config.edp_no_power_sequencing)
1065
1066
1067
1068
1069
1070
1071
1072 edp_add_delay_for_T9(link);
1073 else
1074 DC_LOG_DC("edp_receiver_ready_T9 skipped\n");
1075 }
1076
1077 if (!enable && link->dpcd_sink_ext_caps.bits.oled)
1078 msleep(OLED_PRE_T11_DELAY);
1079}
1080
1081void dce110_enable_audio_stream(struct pipe_ctx *pipe_ctx)
1082{
1083
1084 struct dc *dc;
1085 struct clk_mgr *clk_mgr;
1086 unsigned int i, num_audio = 1;
1087
1088 if (!pipe_ctx->stream)
1089 return;
1090
1091 dc = pipe_ctx->stream->ctx->dc;
1092 clk_mgr = dc->clk_mgr;
1093
1094 if (pipe_ctx->stream_res.audio && pipe_ctx->stream_res.audio->enabled == true)
1095 return;
1096
1097 if (pipe_ctx->stream_res.audio) {
1098 for (i = 0; i < MAX_PIPES; i++) {
1099
1100 if (dc->current_state->res_ctx.pipe_ctx[i].stream_res.audio != NULL)
1101 num_audio++;
1102 }
1103
1104 pipe_ctx->stream_res.audio->funcs->az_enable(pipe_ctx->stream_res.audio);
1105
1106 if (num_audio >= 1 && clk_mgr->funcs->enable_pme_wa)
1107
1108 clk_mgr->funcs->enable_pme_wa(clk_mgr);
1109
1110
1111 pipe_ctx->stream_res.stream_enc->funcs->audio_mute_control(
1112 pipe_ctx->stream_res.stream_enc, false);
1113 if (pipe_ctx->stream_res.audio)
1114 pipe_ctx->stream_res.audio->enabled = true;
1115 }
1116}
1117
1118void dce110_disable_audio_stream(struct pipe_ctx *pipe_ctx)
1119{
1120 struct dc *dc;
1121 struct clk_mgr *clk_mgr;
1122
1123 if (!pipe_ctx || !pipe_ctx->stream)
1124 return;
1125
1126 dc = pipe_ctx->stream->ctx->dc;
1127 clk_mgr = dc->clk_mgr;
1128
1129 if (pipe_ctx->stream_res.audio && pipe_ctx->stream_res.audio->enabled == false)
1130 return;
1131
1132 pipe_ctx->stream_res.stream_enc->funcs->audio_mute_control(
1133 pipe_ctx->stream_res.stream_enc, true);
1134 if (pipe_ctx->stream_res.audio) {
1135 pipe_ctx->stream_res.audio->enabled = false;
1136
1137 if (dc_is_dp_signal(pipe_ctx->stream->signal))
1138 pipe_ctx->stream_res.stream_enc->funcs->dp_audio_disable(
1139 pipe_ctx->stream_res.stream_enc);
1140 else
1141 pipe_ctx->stream_res.stream_enc->funcs->hdmi_audio_disable(
1142 pipe_ctx->stream_res.stream_enc);
1143
1144 if (clk_mgr->funcs->enable_pme_wa)
1145
1146 clk_mgr->funcs->enable_pme_wa(clk_mgr);
1147
1148
1149
1150
1151
1152
1153 }
1154}
1155
1156void dce110_disable_stream(struct pipe_ctx *pipe_ctx)
1157{
1158 struct dc_stream_state *stream = pipe_ctx->stream;
1159 struct dc_link *link = stream->link;
1160 struct dc *dc = pipe_ctx->stream->ctx->dc;
1161
1162 if (dc_is_hdmi_tmds_signal(pipe_ctx->stream->signal)) {
1163 pipe_ctx->stream_res.stream_enc->funcs->stop_hdmi_info_packets(
1164 pipe_ctx->stream_res.stream_enc);
1165 pipe_ctx->stream_res.stream_enc->funcs->hdmi_reset_stream_attribute(
1166 pipe_ctx->stream_res.stream_enc);
1167 }
1168
1169 if (dc_is_dp_signal(pipe_ctx->stream->signal))
1170 pipe_ctx->stream_res.stream_enc->funcs->stop_dp_info_packets(
1171 pipe_ctx->stream_res.stream_enc);
1172
1173 dc->hwss.disable_audio_stream(pipe_ctx);
1174
1175 link->link_enc->funcs->connect_dig_be_to_fe(
1176 link->link_enc,
1177 pipe_ctx->stream_res.stream_enc->id,
1178 false);
1179
1180}
1181
1182void dce110_unblank_stream(struct pipe_ctx *pipe_ctx,
1183 struct dc_link_settings *link_settings)
1184{
1185 struct encoder_unblank_param params = { { 0 } };
1186 struct dc_stream_state *stream = pipe_ctx->stream;
1187 struct dc_link *link = stream->link;
1188 struct dce_hwseq *hws = link->dc->hwseq;
1189
1190
1191 params.timing = pipe_ctx->stream->timing;
1192 params.link_settings.link_rate = link_settings->link_rate;
1193
1194 if (dc_is_dp_signal(pipe_ctx->stream->signal))
1195 pipe_ctx->stream_res.stream_enc->funcs->dp_unblank(pipe_ctx->stream_res.stream_enc, ¶ms);
1196
1197 if (link->local_sink && link->local_sink->sink_signal == SIGNAL_TYPE_EDP) {
1198 hws->funcs.edp_backlight_control(link, true);
1199 }
1200}
1201
1202void dce110_blank_stream(struct pipe_ctx *pipe_ctx)
1203{
1204 struct dc_stream_state *stream = pipe_ctx->stream;
1205 struct dc_link *link = stream->link;
1206 struct dce_hwseq *hws = link->dc->hwseq;
1207
1208 if (link->local_sink && link->local_sink->sink_signal == SIGNAL_TYPE_EDP) {
1209 hws->funcs.edp_backlight_control(link, false);
1210 link->dc->hwss.set_abm_immediate_disable(pipe_ctx);
1211 }
1212
1213 if (dc_is_dp_signal(pipe_ctx->stream->signal)) {
1214 pipe_ctx->stream_res.stream_enc->funcs->dp_blank(pipe_ctx->stream_res.stream_enc);
1215
1216 if (!dc_is_embedded_signal(pipe_ctx->stream->signal)) {
1217
1218
1219
1220
1221 msleep(60);
1222 } else if (pipe_ctx->stream->signal == SIGNAL_TYPE_EDP)
1223 edp_receiver_ready_T9(link);
1224 }
1225
1226}
1227
1228
1229void dce110_set_avmute(struct pipe_ctx *pipe_ctx, bool enable)
1230{
1231 if (pipe_ctx != NULL && pipe_ctx->stream_res.stream_enc != NULL)
1232 pipe_ctx->stream_res.stream_enc->funcs->set_avmute(pipe_ctx->stream_res.stream_enc, enable);
1233}
1234
1235static enum audio_dto_source translate_to_dto_source(enum controller_id crtc_id)
1236{
1237 switch (crtc_id) {
1238 case CONTROLLER_ID_D0:
1239 return DTO_SOURCE_ID0;
1240 case CONTROLLER_ID_D1:
1241 return DTO_SOURCE_ID1;
1242 case CONTROLLER_ID_D2:
1243 return DTO_SOURCE_ID2;
1244 case CONTROLLER_ID_D3:
1245 return DTO_SOURCE_ID3;
1246 case CONTROLLER_ID_D4:
1247 return DTO_SOURCE_ID4;
1248 case CONTROLLER_ID_D5:
1249 return DTO_SOURCE_ID5;
1250 default:
1251 return DTO_SOURCE_UNKNOWN;
1252 }
1253}
1254
1255static void build_audio_output(
1256 struct dc_state *state,
1257 const struct pipe_ctx *pipe_ctx,
1258 struct audio_output *audio_output)
1259{
1260 const struct dc_stream_state *stream = pipe_ctx->stream;
1261 audio_output->engine_id = pipe_ctx->stream_res.stream_enc->id;
1262
1263 audio_output->signal = pipe_ctx->stream->signal;
1264
1265
1266
1267 audio_output->crtc_info.h_total =
1268 stream->timing.h_total;
1269
1270
1271
1272
1273
1274 audio_output->crtc_info.h_active =
1275 stream->timing.h_addressable
1276 + stream->timing.h_border_left
1277 + stream->timing.h_border_right;
1278
1279 audio_output->crtc_info.v_active =
1280 stream->timing.v_addressable
1281 + stream->timing.v_border_top
1282 + stream->timing.v_border_bottom;
1283
1284 audio_output->crtc_info.pixel_repetition = 1;
1285
1286 audio_output->crtc_info.interlaced =
1287 stream->timing.flags.INTERLACE;
1288
1289 audio_output->crtc_info.refresh_rate =
1290 (stream->timing.pix_clk_100hz*100)/
1291 (stream->timing.h_total*stream->timing.v_total);
1292
1293 audio_output->crtc_info.color_depth =
1294 stream->timing.display_color_depth;
1295
1296 audio_output->crtc_info.requested_pixel_clock_100Hz =
1297 pipe_ctx->stream_res.pix_clk_params.requested_pix_clk_100hz;
1298
1299 audio_output->crtc_info.calculated_pixel_clock_100Hz =
1300 pipe_ctx->stream_res.pix_clk_params.requested_pix_clk_100hz;
1301
1302
1303 if (dc_is_hdmi_tmds_signal(pipe_ctx->stream->signal) &&
1304 audio_output->crtc_info.requested_pixel_clock_100Hz ==
1305 (stream->timing.pix_clk_100hz)) {
1306 if (pipe_ctx->stream_res.pix_clk_params.pixel_encoding == PIXEL_ENCODING_YCBCR420) {
1307 audio_output->crtc_info.requested_pixel_clock_100Hz =
1308 audio_output->crtc_info.requested_pixel_clock_100Hz/2;
1309 audio_output->crtc_info.calculated_pixel_clock_100Hz =
1310 pipe_ctx->stream_res.pix_clk_params.requested_pix_clk_100hz/2;
1311
1312 }
1313 }
1314
1315 if (state->clk_mgr &&
1316 (pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT ||
1317 pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST)) {
1318 audio_output->pll_info.dp_dto_source_clock_in_khz =
1319 state->clk_mgr->funcs->get_dp_ref_clk_frequency(
1320 state->clk_mgr);
1321 }
1322
1323 audio_output->pll_info.feed_back_divider =
1324 pipe_ctx->pll_settings.feedback_divider;
1325
1326 audio_output->pll_info.dto_source =
1327 translate_to_dto_source(
1328 pipe_ctx->stream_res.tg->inst + 1);
1329
1330
1331 audio_output->pll_info.ss_enabled = true;
1332
1333 audio_output->pll_info.ss_percentage =
1334 pipe_ctx->pll_settings.ss_percentage;
1335}
1336
1337static void program_scaler(const struct dc *dc,
1338 const struct pipe_ctx *pipe_ctx)
1339{
1340 struct tg_color color = {0};
1341
1342#if defined(CONFIG_DRM_AMD_DC_DCN)
1343
1344 if (pipe_ctx->plane_res.xfm->funcs->transform_set_pixel_storage_depth == NULL)
1345 return;
1346#endif
1347
1348 if (dc->debug.visual_confirm == VISUAL_CONFIRM_SURFACE)
1349 get_surface_visual_confirm_color(pipe_ctx, &color);
1350 else
1351 color_space_to_black_color(dc,
1352 pipe_ctx->stream->output_color_space,
1353 &color);
1354
1355 pipe_ctx->plane_res.xfm->funcs->transform_set_pixel_storage_depth(
1356 pipe_ctx->plane_res.xfm,
1357 pipe_ctx->plane_res.scl_data.lb_params.depth,
1358 &pipe_ctx->stream->bit_depth_params);
1359
1360 if (pipe_ctx->stream_res.tg->funcs->set_overscan_blank_color) {
1361
1362
1363
1364
1365
1366 if (pipe_ctx->stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR420)
1367 color.color_r_cr = color.color_g_y;
1368
1369 pipe_ctx->stream_res.tg->funcs->set_overscan_blank_color(
1370 pipe_ctx->stream_res.tg,
1371 &color);
1372 }
1373
1374 pipe_ctx->plane_res.xfm->funcs->transform_set_scaler(pipe_ctx->plane_res.xfm,
1375 &pipe_ctx->plane_res.scl_data);
1376}
1377
1378static enum dc_status dce110_enable_stream_timing(
1379 struct pipe_ctx *pipe_ctx,
1380 struct dc_state *context,
1381 struct dc *dc)
1382{
1383 struct dc_stream_state *stream = pipe_ctx->stream;
1384 struct pipe_ctx *pipe_ctx_old = &dc->current_state->res_ctx.
1385 pipe_ctx[pipe_ctx->pipe_idx];
1386 struct tg_color black_color = {0};
1387
1388 if (!pipe_ctx_old->stream) {
1389
1390
1391 color_space_to_black_color(dc,
1392 stream->output_color_space, &black_color);
1393 pipe_ctx->stream_res.tg->funcs->set_blank_color(
1394 pipe_ctx->stream_res.tg,
1395 &black_color);
1396
1397
1398
1399
1400
1401 pipe_ctx->stream_res.tg->funcs->set_blank(pipe_ctx->stream_res.tg, true);
1402
1403 if (false == pipe_ctx->clock_source->funcs->program_pix_clk(
1404 pipe_ctx->clock_source,
1405 &pipe_ctx->stream_res.pix_clk_params,
1406 &pipe_ctx->pll_settings)) {
1407 BREAK_TO_DEBUGGER();
1408 return DC_ERROR_UNEXPECTED;
1409 }
1410
1411 pipe_ctx->stream_res.tg->funcs->program_timing(
1412 pipe_ctx->stream_res.tg,
1413 &stream->timing,
1414 0,
1415 0,
1416 0,
1417 0,
1418 pipe_ctx->stream->signal,
1419 true);
1420 }
1421
1422 if (!pipe_ctx_old->stream) {
1423 if (false == pipe_ctx->stream_res.tg->funcs->enable_crtc(
1424 pipe_ctx->stream_res.tg)) {
1425 BREAK_TO_DEBUGGER();
1426 return DC_ERROR_UNEXPECTED;
1427 }
1428 }
1429
1430 return DC_OK;
1431}
1432
1433static enum dc_status apply_single_controller_ctx_to_hw(
1434 struct pipe_ctx *pipe_ctx,
1435 struct dc_state *context,
1436 struct dc *dc)
1437{
1438 struct dc_stream_state *stream = pipe_ctx->stream;
1439 struct drr_params params = {0};
1440 unsigned int event_triggers = 0;
1441 struct pipe_ctx *odm_pipe = pipe_ctx->next_odm_pipe;
1442 struct dce_hwseq *hws = dc->hwseq;
1443
1444 if (hws->funcs.disable_stream_gating) {
1445 hws->funcs.disable_stream_gating(dc, pipe_ctx);
1446 }
1447
1448 if (pipe_ctx->stream_res.audio != NULL) {
1449 struct audio_output audio_output;
1450
1451 build_audio_output(context, pipe_ctx, &audio_output);
1452
1453 if (dc_is_dp_signal(pipe_ctx->stream->signal))
1454 pipe_ctx->stream_res.stream_enc->funcs->dp_audio_setup(
1455 pipe_ctx->stream_res.stream_enc,
1456 pipe_ctx->stream_res.audio->inst,
1457 &pipe_ctx->stream->audio_info);
1458 else
1459 pipe_ctx->stream_res.stream_enc->funcs->hdmi_audio_setup(
1460 pipe_ctx->stream_res.stream_enc,
1461 pipe_ctx->stream_res.audio->inst,
1462 &pipe_ctx->stream->audio_info,
1463 &audio_output.crtc_info);
1464
1465 pipe_ctx->stream_res.audio->funcs->az_configure(
1466 pipe_ctx->stream_res.audio,
1467 pipe_ctx->stream->signal,
1468 &audio_output.crtc_info,
1469 &pipe_ctx->stream->audio_info);
1470 }
1471
1472
1473
1474 if (!pipe_ctx->stream->apply_seamless_boot_optimization)
1475 hws->funcs.enable_stream_timing(pipe_ctx, context, dc);
1476
1477 if (hws->funcs.setup_vupdate_interrupt)
1478 hws->funcs.setup_vupdate_interrupt(dc, pipe_ctx);
1479
1480 params.vertical_total_min = stream->adjust.v_total_min;
1481 params.vertical_total_max = stream->adjust.v_total_max;
1482 if (pipe_ctx->stream_res.tg->funcs->set_drr)
1483 pipe_ctx->stream_res.tg->funcs->set_drr(
1484 pipe_ctx->stream_res.tg, ¶ms);
1485
1486
1487 if (stream->adjust.v_total_min != 0 && stream->adjust.v_total_max != 0)
1488 event_triggers = 0x80;
1489
1490
1491
1492
1493 if (pipe_ctx->stream_res.tg->funcs->set_static_screen_control)
1494 pipe_ctx->stream_res.tg->funcs->set_static_screen_control(
1495 pipe_ctx->stream_res.tg, event_triggers, 2);
1496
1497 if (!dc_is_virtual_signal(pipe_ctx->stream->signal))
1498 pipe_ctx->stream_res.stream_enc->funcs->dig_connect_to_otg(
1499 pipe_ctx->stream_res.stream_enc,
1500 pipe_ctx->stream_res.tg->inst);
1501
1502 pipe_ctx->stream_res.opp->funcs->opp_set_dyn_expansion(
1503 pipe_ctx->stream_res.opp,
1504 COLOR_SPACE_YCBCR601,
1505 stream->timing.display_color_depth,
1506 stream->signal);
1507
1508 pipe_ctx->stream_res.opp->funcs->opp_program_fmt(
1509 pipe_ctx->stream_res.opp,
1510 &stream->bit_depth_params,
1511 &stream->clamping);
1512 while (odm_pipe) {
1513 odm_pipe->stream_res.opp->funcs->opp_set_dyn_expansion(
1514 odm_pipe->stream_res.opp,
1515 COLOR_SPACE_YCBCR601,
1516 stream->timing.display_color_depth,
1517 stream->signal);
1518
1519 odm_pipe->stream_res.opp->funcs->opp_program_fmt(
1520 odm_pipe->stream_res.opp,
1521 &stream->bit_depth_params,
1522 &stream->clamping);
1523 odm_pipe = odm_pipe->next_odm_pipe;
1524 }
1525
1526 if (!stream->dpms_off)
1527 core_link_enable_stream(context, pipe_ctx);
1528
1529 pipe_ctx->plane_res.scl_data.lb_params.alpha_en = pipe_ctx->bottom_pipe != 0;
1530
1531 pipe_ctx->stream->link->psr_settings.psr_feature_enabled = false;
1532
1533 return DC_OK;
1534}
1535
1536
1537
1538static void power_down_encoders(struct dc *dc)
1539{
1540 int i;
1541
1542
1543
1544
1545 for (i = 0; i < dc->res_pool->stream_enc_count; i++) {
1546 dc->res_pool->stream_enc[i]->funcs->dp_blank(
1547 dc->res_pool->stream_enc[i]);
1548 }
1549
1550 for (i = 0; i < dc->link_count; i++) {
1551 enum signal_type signal = dc->links[i]->connector_signal;
1552
1553 if ((signal == SIGNAL_TYPE_EDP) ||
1554 (signal == SIGNAL_TYPE_DISPLAY_PORT))
1555 if (!dc->links[i]->wa_flags.dp_keep_receiver_powered)
1556 dp_receiver_power_ctrl(dc->links[i], false);
1557
1558 if (signal != SIGNAL_TYPE_EDP)
1559 signal = SIGNAL_TYPE_NONE;
1560
1561 dc->links[i]->link_enc->funcs->disable_output(
1562 dc->links[i]->link_enc, signal);
1563
1564 dc->links[i]->link_status.link_active = false;
1565 memset(&dc->links[i]->cur_link_settings, 0,
1566 sizeof(dc->links[i]->cur_link_settings));
1567 }
1568}
1569
1570static void power_down_controllers(struct dc *dc)
1571{
1572 int i;
1573
1574 for (i = 0; i < dc->res_pool->timing_generator_count; i++) {
1575 dc->res_pool->timing_generators[i]->funcs->disable_crtc(
1576 dc->res_pool->timing_generators[i]);
1577 }
1578}
1579
1580static void power_down_clock_sources(struct dc *dc)
1581{
1582 int i;
1583
1584 if (dc->res_pool->dp_clock_source->funcs->cs_power_down(
1585 dc->res_pool->dp_clock_source) == false)
1586 dm_error("Failed to power down pll! (dp clk src)\n");
1587
1588 for (i = 0; i < dc->res_pool->clk_src_count; i++) {
1589 if (dc->res_pool->clock_sources[i]->funcs->cs_power_down(
1590 dc->res_pool->clock_sources[i]) == false)
1591 dm_error("Failed to power down pll! (clk src index=%d)\n", i);
1592 }
1593}
1594
1595static void power_down_all_hw_blocks(struct dc *dc)
1596{
1597 power_down_encoders(dc);
1598
1599 power_down_controllers(dc);
1600
1601 power_down_clock_sources(dc);
1602
1603 if (dc->fbc_compressor)
1604 dc->fbc_compressor->funcs->disable_fbc(dc->fbc_compressor);
1605}
1606
1607static void disable_vga_and_power_gate_all_controllers(
1608 struct dc *dc)
1609{
1610 int i;
1611 struct timing_generator *tg;
1612 struct dc_context *ctx = dc->ctx;
1613
1614 for (i = 0; i < dc->res_pool->timing_generator_count; i++) {
1615 tg = dc->res_pool->timing_generators[i];
1616
1617 if (tg->funcs->disable_vga)
1618 tg->funcs->disable_vga(tg);
1619 }
1620 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1621
1622
1623 enable_display_pipe_clock_gating(ctx,
1624 true);
1625
1626 dc->current_state->res_ctx.pipe_ctx[i].pipe_idx = i;
1627 dc->hwss.disable_plane(dc,
1628 &dc->current_state->res_ctx.pipe_ctx[i]);
1629 }
1630}
1631
1632
1633static void get_edp_streams(struct dc_state *context,
1634 struct dc_stream_state **edp_streams,
1635 int *edp_stream_num)
1636{
1637 int i;
1638
1639 *edp_stream_num = 0;
1640 for (i = 0; i < context->stream_count; i++) {
1641 if (context->streams[i]->signal == SIGNAL_TYPE_EDP) {
1642 edp_streams[*edp_stream_num] = context->streams[i];
1643 if (++(*edp_stream_num) == MAX_NUM_EDP)
1644 return;
1645 }
1646 }
1647}
1648
1649static void get_edp_links_with_sink(
1650 struct dc *dc,
1651 struct dc_link **edp_links_with_sink,
1652 int *edp_with_sink_num)
1653{
1654 int i;
1655
1656
1657 *edp_with_sink_num = 0;
1658 for (i = 0; i < dc->link_count; i++) {
1659 if (dc->links[i]->local_sink &&
1660 dc->links[i]->local_sink->sink_signal == SIGNAL_TYPE_EDP) {
1661 edp_links_with_sink[*edp_with_sink_num] = dc->links[i];
1662 if (++(*edp_with_sink_num) == MAX_NUM_EDP)
1663 return;
1664 }
1665 }
1666}
1667
1668
1669
1670
1671
1672
1673
1674
1675void dce110_enable_accelerated_mode(struct dc *dc, struct dc_state *context)
1676{
1677 struct dc_link *edp_links_with_sink[MAX_NUM_EDP];
1678 struct dc_link *edp_links[MAX_NUM_EDP];
1679 struct dc_stream_state *edp_streams[MAX_NUM_EDP];
1680 struct dc_link *edp_link_with_sink = NULL;
1681 struct dc_link *edp_link = NULL;
1682 struct dc_stream_state *edp_stream = NULL;
1683 struct dce_hwseq *hws = dc->hwseq;
1684 int edp_with_sink_num;
1685 int edp_num;
1686 int edp_stream_num;
1687 int i;
1688 bool can_apply_edp_fast_boot = false;
1689 bool can_apply_seamless_boot = false;
1690 bool keep_edp_vdd_on = false;
1691 DC_LOGGER_INIT();
1692
1693
1694 get_edp_links_with_sink(dc, edp_links_with_sink, &edp_with_sink_num);
1695 get_edp_links(dc, edp_links, &edp_num);
1696
1697 if (hws->funcs.init_pipes)
1698 hws->funcs.init_pipes(dc, context);
1699
1700 get_edp_streams(context, edp_streams, &edp_stream_num);
1701
1702
1703 if (edp_num && dc->ctx->dce_version != DCE_VERSION_8_0 &&
1704 dc->ctx->dce_version != DCE_VERSION_8_1 &&
1705 dc->ctx->dce_version != DCE_VERSION_8_3) {
1706 for (i = 0; i < edp_num; i++) {
1707 edp_link = edp_links[i];
1708
1709 if (edp_link->link_enc->funcs->is_dig_enabled(edp_link->link_enc)) {
1710
1711 if (edp_stream_num && edp_link->link_status.link_active) {
1712 edp_stream = edp_streams[0];
1713 can_apply_edp_fast_boot = !is_edp_ilr_optimization_required(edp_stream->link, &edp_stream->timing);
1714 edp_stream->apply_edp_fast_boot_optimization = can_apply_edp_fast_boot;
1715 if (can_apply_edp_fast_boot)
1716 DC_LOG_EVENT_LINK_TRAINING("eDP fast boot disabled to optimize link rate\n");
1717
1718 break;
1719 }
1720 }
1721 }
1722
1723 if (edp_stream_num)
1724 keep_edp_vdd_on = true;
1725 }
1726
1727
1728 for (i = 0; i < context->stream_count; i++) {
1729 if (context->streams[i]->apply_seamless_boot_optimization) {
1730 can_apply_seamless_boot = true;
1731 break;
1732 }
1733 }
1734
1735
1736
1737
1738 if (edp_with_sink_num)
1739 edp_link_with_sink = edp_links_with_sink[0];
1740
1741 if (!can_apply_edp_fast_boot && !can_apply_seamless_boot) {
1742 if (edp_link_with_sink && !keep_edp_vdd_on) {
1743
1744 hws->funcs.edp_backlight_control(edp_link_with_sink, false);
1745 }
1746
1747 power_down_all_hw_blocks(dc);
1748 disable_vga_and_power_gate_all_controllers(dc);
1749 if (edp_link_with_sink && !keep_edp_vdd_on)
1750 dc->hwss.edp_power_control(edp_link_with_sink, false);
1751 }
1752 bios_set_scratch_acc_mode_change(dc->ctx->dc_bios, 1);
1753}
1754
1755static uint32_t compute_pstate_blackout_duration(
1756 struct bw_fixed blackout_duration,
1757 const struct dc_stream_state *stream)
1758{
1759 uint32_t total_dest_line_time_ns;
1760 uint32_t pstate_blackout_duration_ns;
1761
1762 pstate_blackout_duration_ns = 1000 * blackout_duration.value >> 24;
1763
1764 total_dest_line_time_ns = 1000000UL *
1765 (stream->timing.h_total * 10) /
1766 stream->timing.pix_clk_100hz +
1767 pstate_blackout_duration_ns;
1768
1769 return total_dest_line_time_ns;
1770}
1771
1772static void dce110_set_displaymarks(
1773 const struct dc *dc,
1774 struct dc_state *context)
1775{
1776 uint8_t i, num_pipes;
1777 unsigned int underlay_idx = dc->res_pool->underlay_pipe_index;
1778
1779 for (i = 0, num_pipes = 0; i < MAX_PIPES; i++) {
1780 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
1781 uint32_t total_dest_line_time_ns;
1782
1783 if (pipe_ctx->stream == NULL)
1784 continue;
1785
1786 total_dest_line_time_ns = compute_pstate_blackout_duration(
1787 dc->bw_vbios->blackout_duration, pipe_ctx->stream);
1788 pipe_ctx->plane_res.mi->funcs->mem_input_program_display_marks(
1789 pipe_ctx->plane_res.mi,
1790 context->bw_ctx.bw.dce.nbp_state_change_wm_ns[num_pipes],
1791 context->bw_ctx.bw.dce.stutter_exit_wm_ns[num_pipes],
1792 context->bw_ctx.bw.dce.stutter_entry_wm_ns[num_pipes],
1793 context->bw_ctx.bw.dce.urgent_wm_ns[num_pipes],
1794 total_dest_line_time_ns);
1795 if (i == underlay_idx) {
1796 num_pipes++;
1797 pipe_ctx->plane_res.mi->funcs->mem_input_program_chroma_display_marks(
1798 pipe_ctx->plane_res.mi,
1799 context->bw_ctx.bw.dce.nbp_state_change_wm_ns[num_pipes],
1800 context->bw_ctx.bw.dce.stutter_exit_wm_ns[num_pipes],
1801 context->bw_ctx.bw.dce.urgent_wm_ns[num_pipes],
1802 total_dest_line_time_ns);
1803 }
1804 num_pipes++;
1805 }
1806}
1807
1808void dce110_set_safe_displaymarks(
1809 struct resource_context *res_ctx,
1810 const struct resource_pool *pool)
1811{
1812 int i;
1813 int underlay_idx = pool->underlay_pipe_index;
1814 struct dce_watermarks max_marks = {
1815 MAX_WATERMARK, MAX_WATERMARK, MAX_WATERMARK, MAX_WATERMARK };
1816 struct dce_watermarks nbp_marks = {
1817 SAFE_NBP_MARK, SAFE_NBP_MARK, SAFE_NBP_MARK, SAFE_NBP_MARK };
1818 struct dce_watermarks min_marks = { 0, 0, 0, 0};
1819
1820 for (i = 0; i < MAX_PIPES; i++) {
1821 if (res_ctx->pipe_ctx[i].stream == NULL || res_ctx->pipe_ctx[i].plane_res.mi == NULL)
1822 continue;
1823
1824 res_ctx->pipe_ctx[i].plane_res.mi->funcs->mem_input_program_display_marks(
1825 res_ctx->pipe_ctx[i].plane_res.mi,
1826 nbp_marks,
1827 max_marks,
1828 min_marks,
1829 max_marks,
1830 MAX_WATERMARK);
1831
1832 if (i == underlay_idx)
1833 res_ctx->pipe_ctx[i].plane_res.mi->funcs->mem_input_program_chroma_display_marks(
1834 res_ctx->pipe_ctx[i].plane_res.mi,
1835 nbp_marks,
1836 max_marks,
1837 max_marks,
1838 MAX_WATERMARK);
1839
1840 }
1841}
1842
1843
1844
1845
1846
1847static void set_drr(struct pipe_ctx **pipe_ctx,
1848 int num_pipes, struct dc_crtc_timing_adjust adjust)
1849{
1850 int i = 0;
1851 struct drr_params params = {0};
1852
1853 unsigned int event_triggers = 0x80;
1854
1855 unsigned int num_frames = 2;
1856
1857 params.vertical_total_max = adjust.v_total_max;
1858 params.vertical_total_min = adjust.v_total_min;
1859
1860
1861
1862
1863
1864 for (i = 0; i < num_pipes; i++) {
1865 pipe_ctx[i]->stream_res.tg->funcs->set_drr(
1866 pipe_ctx[i]->stream_res.tg, ¶ms);
1867
1868 if (adjust.v_total_max != 0 && adjust.v_total_min != 0)
1869 pipe_ctx[i]->stream_res.tg->funcs->set_static_screen_control(
1870 pipe_ctx[i]->stream_res.tg,
1871 event_triggers, num_frames);
1872 }
1873}
1874
1875static void get_position(struct pipe_ctx **pipe_ctx,
1876 int num_pipes,
1877 struct crtc_position *position)
1878{
1879 int i = 0;
1880
1881
1882
1883 for (i = 0; i < num_pipes; i++)
1884 pipe_ctx[i]->stream_res.tg->funcs->get_position(pipe_ctx[i]->stream_res.tg, position);
1885}
1886
1887static void set_static_screen_control(struct pipe_ctx **pipe_ctx,
1888 int num_pipes, const struct dc_static_screen_params *params)
1889{
1890 unsigned int i;
1891 unsigned int triggers = 0;
1892
1893 if (params->triggers.overlay_update)
1894 triggers |= 0x100;
1895 if (params->triggers.surface_update)
1896 triggers |= 0x80;
1897 if (params->triggers.cursor_update)
1898 triggers |= 0x2;
1899 if (params->triggers.force_trigger)
1900 triggers |= 0x1;
1901
1902 if (num_pipes) {
1903 struct dc *dc = pipe_ctx[0]->stream->ctx->dc;
1904
1905 if (dc->fbc_compressor)
1906 triggers |= 0x84;
1907 }
1908
1909 for (i = 0; i < num_pipes; i++)
1910 pipe_ctx[i]->stream_res.tg->funcs->
1911 set_static_screen_control(pipe_ctx[i]->stream_res.tg,
1912 triggers, params->num_frames);
1913}
1914
1915
1916
1917
1918static bool should_enable_fbc(struct dc *dc,
1919 struct dc_state *context,
1920 uint32_t *pipe_idx)
1921{
1922 uint32_t i;
1923 struct pipe_ctx *pipe_ctx = NULL;
1924 struct resource_context *res_ctx = &context->res_ctx;
1925 unsigned int underlay_idx = dc->res_pool->underlay_pipe_index;
1926
1927
1928 ASSERT(dc->fbc_compressor);
1929
1930
1931 if (!dc->ctx->fbc_gpu_addr)
1932 return false;
1933
1934
1935 if (context->stream_count != 1)
1936 return false;
1937
1938 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1939 if (res_ctx->pipe_ctx[i].stream) {
1940
1941 pipe_ctx = &res_ctx->pipe_ctx[i];
1942
1943 if (!pipe_ctx)
1944 continue;
1945
1946
1947 if (pipe_ctx->pipe_idx != underlay_idx) {
1948 *pipe_idx = i;
1949 break;
1950 }
1951 }
1952 }
1953
1954 if (i == dc->res_pool->pipe_count)
1955 return false;
1956
1957 if (!pipe_ctx->stream->link)
1958 return false;
1959
1960
1961 if (pipe_ctx->stream->link->connector_signal != SIGNAL_TYPE_EDP)
1962 return false;
1963
1964
1965 if (pipe_ctx->stream->link->psr_settings.psr_feature_enabled)
1966 return false;
1967
1968
1969 if (!pipe_ctx->plane_state)
1970 return false;
1971
1972
1973 if (pipe_ctx->plane_state->tiling_info.gfx8.array_mode == DC_ARRAY_LINEAR_GENERAL)
1974 return false;
1975
1976 return true;
1977}
1978
1979
1980
1981
1982static void enable_fbc(
1983 struct dc *dc,
1984 struct dc_state *context)
1985{
1986 uint32_t pipe_idx = 0;
1987
1988 if (should_enable_fbc(dc, context, &pipe_idx)) {
1989
1990 struct compr_addr_and_pitch_params params = {0, 0, 0};
1991 struct compressor *compr = dc->fbc_compressor;
1992 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[pipe_idx];
1993
1994 params.source_view_width = pipe_ctx->stream->timing.h_addressable;
1995 params.source_view_height = pipe_ctx->stream->timing.v_addressable;
1996 params.inst = pipe_ctx->stream_res.tg->inst;
1997 compr->compr_surface_address.quad_part = dc->ctx->fbc_gpu_addr;
1998
1999 compr->funcs->surface_address_and_pitch(compr, ¶ms);
2000 compr->funcs->set_fbc_invalidation_triggers(compr, 1);
2001
2002 compr->funcs->enable_fbc(compr, ¶ms);
2003 }
2004}
2005
2006static void dce110_reset_hw_ctx_wrap(
2007 struct dc *dc,
2008 struct dc_state *context)
2009{
2010 int i;
2011
2012
2013
2014 for (i = 0; i < MAX_PIPES; i++) {
2015 struct pipe_ctx *pipe_ctx_old =
2016 &dc->current_state->res_ctx.pipe_ctx[i];
2017 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2018
2019
2020
2021
2022
2023
2024
2025 if (!pipe_ctx_old->stream || pipe_ctx_old->top_pipe)
2026 continue;
2027
2028 if (!pipe_ctx->stream ||
2029 pipe_need_reprogram(pipe_ctx_old, pipe_ctx)) {
2030 struct clock_source *old_clk = pipe_ctx_old->clock_source;
2031
2032
2033
2034
2035 if (!pipe_ctx->stream || !pipe_ctx->stream->dpms_off) {
2036 core_link_disable_stream(pipe_ctx_old);
2037
2038
2039 if (pipe_ctx_old->stream_res.audio) {
2040
2041 pipe_ctx_old->stream_res.audio->funcs->
2042 az_disable(pipe_ctx_old->stream_res.audio);
2043
2044
2045 if (dc->caps.dynamic_audio == true) {
2046
2047
2048 update_audio_usage(&dc->current_state->res_ctx, dc->res_pool,
2049 pipe_ctx_old->stream_res.audio, false);
2050 pipe_ctx_old->stream_res.audio = NULL;
2051 }
2052 }
2053 }
2054
2055 pipe_ctx_old->stream_res.tg->funcs->set_blank(pipe_ctx_old->stream_res.tg, true);
2056 if (!hwss_wait_for_blank_complete(pipe_ctx_old->stream_res.tg)) {
2057 dm_error("DC: failed to blank crtc!\n");
2058 BREAK_TO_DEBUGGER();
2059 }
2060 pipe_ctx_old->stream_res.tg->funcs->disable_crtc(pipe_ctx_old->stream_res.tg);
2061 pipe_ctx_old->plane_res.mi->funcs->free_mem_input(
2062 pipe_ctx_old->plane_res.mi, dc->current_state->stream_count);
2063
2064 if (old_clk && 0 == resource_get_clock_source_reference(&context->res_ctx,
2065 dc->res_pool,
2066 old_clk))
2067 old_clk->funcs->cs_power_down(old_clk);
2068
2069 dc->hwss.disable_plane(dc, pipe_ctx_old);
2070
2071 pipe_ctx_old->stream = NULL;
2072 }
2073 }
2074}
2075
2076static void dce110_setup_audio_dto(
2077 struct dc *dc,
2078 struct dc_state *context)
2079{
2080 int i;
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2102 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2103
2104 if (pipe_ctx->stream == NULL)
2105 continue;
2106
2107 if (pipe_ctx->top_pipe)
2108 continue;
2109 if (pipe_ctx->stream->signal != SIGNAL_TYPE_HDMI_TYPE_A)
2110 continue;
2111 if (pipe_ctx->stream_res.audio != NULL) {
2112 struct audio_output audio_output;
2113
2114 build_audio_output(context, pipe_ctx, &audio_output);
2115
2116#if defined(CONFIG_DRM_AMD_DC_DCN)
2117
2118 if (dc->res_pool->dccg && dc->res_pool->dccg->funcs->set_audio_dtbclk_dto) {
2119
2120 dc->res_pool->dccg->funcs->set_audio_dtbclk_dto(
2121 dc->res_pool->dccg, 0);
2122
2123 pipe_ctx->stream_res.audio->funcs->wall_dto_setup(
2124 pipe_ctx->stream_res.audio,
2125 pipe_ctx->stream->signal,
2126 &audio_output.crtc_info,
2127 &audio_output.pll_info);
2128 } else
2129 pipe_ctx->stream_res.audio->funcs->wall_dto_setup(
2130 pipe_ctx->stream_res.audio,
2131 pipe_ctx->stream->signal,
2132 &audio_output.crtc_info,
2133 &audio_output.pll_info);
2134#else
2135 pipe_ctx->stream_res.audio->funcs->wall_dto_setup(
2136 pipe_ctx->stream_res.audio,
2137 pipe_ctx->stream->signal,
2138 &audio_output.crtc_info,
2139 &audio_output.pll_info);
2140#endif
2141 break;
2142 }
2143 }
2144
2145
2146 if (i == dc->res_pool->pipe_count) {
2147 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2148 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2149
2150 if (pipe_ctx->stream == NULL)
2151 continue;
2152
2153 if (pipe_ctx->top_pipe)
2154 continue;
2155
2156 if (!dc_is_dp_signal(pipe_ctx->stream->signal))
2157 continue;
2158
2159 if (pipe_ctx->stream_res.audio != NULL) {
2160 struct audio_output audio_output;
2161
2162 build_audio_output(context, pipe_ctx, &audio_output);
2163
2164 pipe_ctx->stream_res.audio->funcs->wall_dto_setup(
2165 pipe_ctx->stream_res.audio,
2166 pipe_ctx->stream->signal,
2167 &audio_output.crtc_info,
2168 &audio_output.pll_info);
2169 break;
2170 }
2171 }
2172 }
2173}
2174
2175enum dc_status dce110_apply_ctx_to_hw(
2176 struct dc *dc,
2177 struct dc_state *context)
2178{
2179 struct dce_hwseq *hws = dc->hwseq;
2180 struct dc_bios *dcb = dc->ctx->dc_bios;
2181 enum dc_status status;
2182 int i;
2183
2184
2185
2186 hws->funcs.reset_hw_ctx_wrap(dc, context);
2187
2188
2189 if (context->stream_count <= 0)
2190 return DC_OK;
2191
2192
2193 dcb->funcs->set_scratch_critical_state(dcb, true);
2194
2195
2196 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2197 struct pipe_ctx *pipe_ctx_old =
2198 &dc->current_state->res_ctx.pipe_ctx[i];
2199 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2200
2201 if (pipe_ctx->stream == NULL || pipe_ctx->top_pipe)
2202 continue;
2203
2204 if (pipe_ctx->stream == pipe_ctx_old->stream) {
2205 if (pipe_ctx_old->clock_source != pipe_ctx->clock_source)
2206 dce_crtc_switch_to_clk_src(dc->hwseq,
2207 pipe_ctx->clock_source, i);
2208 continue;
2209 }
2210
2211 hws->funcs.enable_display_power_gating(
2212 dc, i, dc->ctx->dc_bios,
2213 PIPE_GATING_CONTROL_DISABLE);
2214 }
2215
2216 if (dc->fbc_compressor)
2217 dc->fbc_compressor->funcs->disable_fbc(dc->fbc_compressor);
2218
2219 dce110_setup_audio_dto(dc, context);
2220
2221 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2222 struct pipe_ctx *pipe_ctx_old =
2223 &dc->current_state->res_ctx.pipe_ctx[i];
2224 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2225
2226 if (pipe_ctx->stream == NULL)
2227 continue;
2228
2229 if (pipe_ctx->stream == pipe_ctx_old->stream &&
2230 pipe_ctx->stream->link->link_state_valid) {
2231 continue;
2232 }
2233
2234 if (pipe_ctx_old->stream && !pipe_need_reprogram(pipe_ctx_old, pipe_ctx))
2235 continue;
2236
2237 if (pipe_ctx->top_pipe || pipe_ctx->prev_odm_pipe)
2238 continue;
2239
2240 status = apply_single_controller_ctx_to_hw(
2241 pipe_ctx,
2242 context,
2243 dc);
2244
2245 if (DC_OK != status)
2246 return status;
2247 }
2248
2249 if (dc->fbc_compressor)
2250 enable_fbc(dc, dc->current_state);
2251
2252 dcb->funcs->set_scratch_critical_state(dcb, false);
2253
2254 return DC_OK;
2255}
2256
2257
2258
2259
2260static void set_default_colors(struct pipe_ctx *pipe_ctx)
2261{
2262 struct default_adjustment default_adjust = { 0 };
2263
2264 default_adjust.force_hw_default = false;
2265 default_adjust.in_color_space = pipe_ctx->plane_state->color_space;
2266 default_adjust.out_color_space = pipe_ctx->stream->output_color_space;
2267 default_adjust.csc_adjust_type = GRAPHICS_CSC_ADJUST_TYPE_SW;
2268 default_adjust.surface_pixel_format = pipe_ctx->plane_res.scl_data.format;
2269
2270
2271 default_adjust.color_depth =
2272 pipe_ctx->stream->timing.display_color_depth;
2273
2274
2275 default_adjust.lb_color_depth = pipe_ctx->plane_res.scl_data.lb_params.depth;
2276
2277 pipe_ctx->plane_res.xfm->funcs->opp_set_csc_default(
2278 pipe_ctx->plane_res.xfm, &default_adjust);
2279}
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301static void program_surface_visibility(const struct dc *dc,
2302 struct pipe_ctx *pipe_ctx)
2303{
2304 enum blnd_mode blender_mode = BLND_MODE_CURRENT_PIPE;
2305 bool blank_target = false;
2306
2307 if (pipe_ctx->bottom_pipe) {
2308
2309
2310 ASSERT(pipe_ctx->bottom_pipe->bottom_pipe == NULL);
2311
2312 if (pipe_ctx->bottom_pipe->plane_state->visible) {
2313 if (pipe_ctx->plane_state->visible)
2314 blender_mode = BLND_MODE_BLENDING;
2315 else
2316 blender_mode = BLND_MODE_OTHER_PIPE;
2317
2318 } else if (!pipe_ctx->plane_state->visible)
2319 blank_target = true;
2320
2321 } else if (!pipe_ctx->plane_state->visible)
2322 blank_target = true;
2323
2324 dce_set_blender_mode(dc->hwseq, pipe_ctx->stream_res.tg->inst, blender_mode);
2325 pipe_ctx->stream_res.tg->funcs->set_blank(pipe_ctx->stream_res.tg, blank_target);
2326
2327}
2328
2329static void program_gamut_remap(struct pipe_ctx *pipe_ctx)
2330{
2331 int i = 0;
2332 struct xfm_grph_csc_adjustment adjust;
2333 memset(&adjust, 0, sizeof(adjust));
2334 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS;
2335
2336
2337 if (pipe_ctx->stream->gamut_remap_matrix.enable_remap == true) {
2338 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_SW;
2339
2340 for (i = 0; i < CSC_TEMPERATURE_MATRIX_SIZE; i++)
2341 adjust.temperature_matrix[i] =
2342 pipe_ctx->stream->gamut_remap_matrix.matrix[i];
2343 }
2344
2345 pipe_ctx->plane_res.xfm->funcs->transform_set_gamut_remap(pipe_ctx->plane_res.xfm, &adjust);
2346}
2347static void update_plane_addr(const struct dc *dc,
2348 struct pipe_ctx *pipe_ctx)
2349{
2350 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
2351
2352 if (plane_state == NULL)
2353 return;
2354
2355 pipe_ctx->plane_res.mi->funcs->mem_input_program_surface_flip_and_addr(
2356 pipe_ctx->plane_res.mi,
2357 &plane_state->address,
2358 plane_state->flip_immediate);
2359
2360 plane_state->status.requested_address = plane_state->address;
2361}
2362
2363static void dce110_update_pending_status(struct pipe_ctx *pipe_ctx)
2364{
2365 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
2366
2367 if (plane_state == NULL)
2368 return;
2369
2370 plane_state->status.is_flip_pending =
2371 pipe_ctx->plane_res.mi->funcs->mem_input_is_flip_pending(
2372 pipe_ctx->plane_res.mi);
2373
2374 if (plane_state->status.is_flip_pending && !plane_state->visible)
2375 pipe_ctx->plane_res.mi->current_address = pipe_ctx->plane_res.mi->request_address;
2376
2377 plane_state->status.current_address = pipe_ctx->plane_res.mi->current_address;
2378 if (pipe_ctx->plane_res.mi->current_address.type == PLN_ADDR_TYPE_GRPH_STEREO &&
2379 pipe_ctx->stream_res.tg->funcs->is_stereo_left_eye) {
2380 plane_state->status.is_right_eye =\
2381 !pipe_ctx->stream_res.tg->funcs->is_stereo_left_eye(pipe_ctx->stream_res.tg);
2382 }
2383}
2384
2385void dce110_power_down(struct dc *dc)
2386{
2387 power_down_all_hw_blocks(dc);
2388 disable_vga_and_power_gate_all_controllers(dc);
2389}
2390
2391static bool wait_for_reset_trigger_to_occur(
2392 struct dc_context *dc_ctx,
2393 struct timing_generator *tg)
2394{
2395 bool rc = false;
2396
2397
2398
2399 const uint32_t frames_to_wait_on_triggered_reset = 10;
2400 uint32_t i;
2401
2402 for (i = 0; i < frames_to_wait_on_triggered_reset; i++) {
2403
2404 if (!tg->funcs->is_counter_moving(tg)) {
2405 DC_ERROR("TG counter is not moving!\n");
2406 break;
2407 }
2408
2409 if (tg->funcs->did_triggered_reset_occur(tg)) {
2410 rc = true;
2411
2412 DC_SYNC_INFO("GSL: reset occurred at wait count: %d\n",
2413 i);
2414 break;
2415 }
2416
2417
2418 tg->funcs->wait_for_state(tg, CRTC_STATE_VACTIVE);
2419 tg->funcs->wait_for_state(tg, CRTC_STATE_VBLANK);
2420 }
2421
2422 if (false == rc)
2423 DC_ERROR("GSL: Timeout on reset trigger!\n");
2424
2425 return rc;
2426}
2427
2428
2429static void dce110_enable_timing_synchronization(
2430 struct dc *dc,
2431 int group_index,
2432 int group_size,
2433 struct pipe_ctx *grouped_pipes[])
2434{
2435 struct dc_context *dc_ctx = dc->ctx;
2436 struct dcp_gsl_params gsl_params = { 0 };
2437 int i;
2438
2439 DC_SYNC_INFO("GSL: Setting-up...\n");
2440
2441
2442
2443
2444 gsl_params.gsl_group = 0;
2445 gsl_params.gsl_master = grouped_pipes[0]->stream_res.tg->inst;
2446
2447 for (i = 0; i < group_size; i++)
2448 grouped_pipes[i]->stream_res.tg->funcs->setup_global_swap_lock(
2449 grouped_pipes[i]->stream_res.tg, &gsl_params);
2450
2451
2452 DC_SYNC_INFO("GSL: enabling trigger-reset\n");
2453
2454 for (i = 1 ; i < group_size; i++)
2455 grouped_pipes[i]->stream_res.tg->funcs->enable_reset_trigger(
2456 grouped_pipes[i]->stream_res.tg,
2457 gsl_params.gsl_group);
2458
2459 for (i = 1 ; i < group_size; i++) {
2460 DC_SYNC_INFO("GSL: waiting for reset to occur.\n");
2461 wait_for_reset_trigger_to_occur(dc_ctx, grouped_pipes[i]->stream_res.tg);
2462 grouped_pipes[i]->stream_res.tg->funcs->disable_reset_trigger(
2463 grouped_pipes[i]->stream_res.tg);
2464 }
2465
2466
2467
2468 DC_SYNC_INFO("GSL: Restoring register states.\n");
2469 for (i = 0; i < group_size; i++)
2470 grouped_pipes[i]->stream_res.tg->funcs->tear_down_global_swap_lock(grouped_pipes[i]->stream_res.tg);
2471
2472 DC_SYNC_INFO("GSL: Set-up complete.\n");
2473}
2474
2475static void dce110_enable_per_frame_crtc_position_reset(
2476 struct dc *dc,
2477 int group_size,
2478 struct pipe_ctx *grouped_pipes[])
2479{
2480 struct dc_context *dc_ctx = dc->ctx;
2481 struct dcp_gsl_params gsl_params = { 0 };
2482 int i;
2483
2484 gsl_params.gsl_group = 0;
2485 gsl_params.gsl_master = 0;
2486
2487 for (i = 0; i < group_size; i++)
2488 grouped_pipes[i]->stream_res.tg->funcs->setup_global_swap_lock(
2489 grouped_pipes[i]->stream_res.tg, &gsl_params);
2490
2491 DC_SYNC_INFO("GSL: enabling trigger-reset\n");
2492
2493 for (i = 1; i < group_size; i++)
2494 grouped_pipes[i]->stream_res.tg->funcs->enable_crtc_reset(
2495 grouped_pipes[i]->stream_res.tg,
2496 gsl_params.gsl_master,
2497 &grouped_pipes[i]->stream->triggered_crtc_reset);
2498
2499 DC_SYNC_INFO("GSL: waiting for reset to occur.\n");
2500 for (i = 1; i < group_size; i++)
2501 wait_for_reset_trigger_to_occur(dc_ctx, grouped_pipes[i]->stream_res.tg);
2502
2503 for (i = 0; i < group_size; i++)
2504 grouped_pipes[i]->stream_res.tg->funcs->tear_down_global_swap_lock(grouped_pipes[i]->stream_res.tg);
2505
2506}
2507
2508static void init_pipes(struct dc *dc, struct dc_state *context)
2509{
2510
2511}
2512
2513static void init_hw(struct dc *dc)
2514{
2515 int i;
2516 struct dc_bios *bp;
2517 struct transform *xfm;
2518 struct abm *abm;
2519 struct dmcu *dmcu;
2520 struct dce_hwseq *hws = dc->hwseq;
2521 uint32_t backlight = MAX_BACKLIGHT_LEVEL;
2522
2523 bp = dc->ctx->dc_bios;
2524 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2525 xfm = dc->res_pool->transforms[i];
2526 xfm->funcs->transform_reset(xfm);
2527
2528 hws->funcs.enable_display_power_gating(
2529 dc, i, bp,
2530 PIPE_GATING_CONTROL_INIT);
2531 hws->funcs.enable_display_power_gating(
2532 dc, i, bp,
2533 PIPE_GATING_CONTROL_DISABLE);
2534 hws->funcs.enable_display_pipe_clock_gating(
2535 dc->ctx,
2536 true);
2537 }
2538
2539 dce_clock_gating_power_up(dc->hwseq, false);
2540
2541
2542 for (i = 0; i < dc->link_count; i++) {
2543
2544
2545
2546
2547 struct dc_link *link = dc->links[i];
2548
2549 link->link_enc->funcs->hw_init(link->link_enc);
2550 }
2551
2552 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2553 struct timing_generator *tg = dc->res_pool->timing_generators[i];
2554
2555 tg->funcs->disable_vga(tg);
2556
2557
2558
2559 tg->funcs->set_blank(tg, true);
2560 hwss_wait_for_blank_complete(tg);
2561 }
2562
2563 for (i = 0; i < dc->res_pool->audio_count; i++) {
2564 struct audio *audio = dc->res_pool->audios[i];
2565 audio->funcs->hw_init(audio);
2566 }
2567
2568 for (i = 0; i < dc->link_count; i++) {
2569 struct dc_link *link = dc->links[i];
2570
2571 if (link->panel_cntl)
2572 backlight = link->panel_cntl->funcs->hw_init(link->panel_cntl);
2573 }
2574
2575 abm = dc->res_pool->abm;
2576 if (abm != NULL)
2577 abm->funcs->abm_init(abm, backlight);
2578
2579 dmcu = dc->res_pool->dmcu;
2580 if (dmcu != NULL && abm != NULL)
2581 abm->dmcu_is_running = dmcu->funcs->is_dmcu_initialized(dmcu);
2582
2583 if (dc->fbc_compressor)
2584 dc->fbc_compressor->funcs->power_up_fbc(dc->fbc_compressor);
2585
2586}
2587
2588
2589void dce110_prepare_bandwidth(
2590 struct dc *dc,
2591 struct dc_state *context)
2592{
2593 struct clk_mgr *dccg = dc->clk_mgr;
2594
2595 dce110_set_safe_displaymarks(&context->res_ctx, dc->res_pool);
2596
2597 dccg->funcs->update_clocks(
2598 dccg,
2599 context,
2600 false);
2601}
2602
2603void dce110_optimize_bandwidth(
2604 struct dc *dc,
2605 struct dc_state *context)
2606{
2607 struct clk_mgr *dccg = dc->clk_mgr;
2608
2609 dce110_set_displaymarks(dc, context);
2610
2611 dccg->funcs->update_clocks(
2612 dccg,
2613 context,
2614 true);
2615}
2616
2617static void dce110_program_front_end_for_pipe(
2618 struct dc *dc, struct pipe_ctx *pipe_ctx)
2619{
2620 struct mem_input *mi = pipe_ctx->plane_res.mi;
2621 struct dc_plane_state *plane_state = pipe_ctx->plane_state;
2622 struct xfm_grph_csc_adjustment adjust;
2623 struct out_csc_color_matrix tbl_entry;
2624 unsigned int i;
2625 struct dce_hwseq *hws = dc->hwseq;
2626
2627 DC_LOGGER_INIT();
2628 memset(&tbl_entry, 0, sizeof(tbl_entry));
2629
2630 memset(&adjust, 0, sizeof(adjust));
2631 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS;
2632
2633 dce_enable_fe_clock(dc->hwseq, mi->inst, true);
2634
2635 set_default_colors(pipe_ctx);
2636 if (pipe_ctx->stream->csc_color_matrix.enable_adjustment
2637 == true) {
2638 tbl_entry.color_space =
2639 pipe_ctx->stream->output_color_space;
2640
2641 for (i = 0; i < 12; i++)
2642 tbl_entry.regval[i] =
2643 pipe_ctx->stream->csc_color_matrix.matrix[i];
2644
2645 pipe_ctx->plane_res.xfm->funcs->opp_set_csc_adjustment
2646 (pipe_ctx->plane_res.xfm, &tbl_entry);
2647 }
2648
2649 if (pipe_ctx->stream->gamut_remap_matrix.enable_remap == true) {
2650 adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_SW;
2651
2652 for (i = 0; i < CSC_TEMPERATURE_MATRIX_SIZE; i++)
2653 adjust.temperature_matrix[i] =
2654 pipe_ctx->stream->gamut_remap_matrix.matrix[i];
2655 }
2656
2657 pipe_ctx->plane_res.xfm->funcs->transform_set_gamut_remap(pipe_ctx->plane_res.xfm, &adjust);
2658
2659 pipe_ctx->plane_res.scl_data.lb_params.alpha_en = pipe_ctx->bottom_pipe != 0;
2660
2661 program_scaler(dc, pipe_ctx);
2662
2663 mi->funcs->mem_input_program_surface_config(
2664 mi,
2665 plane_state->format,
2666 &plane_state->tiling_info,
2667 &plane_state->plane_size,
2668 plane_state->rotation,
2669 NULL,
2670 false);
2671 if (mi->funcs->set_blank)
2672 mi->funcs->set_blank(mi, pipe_ctx->plane_state->visible);
2673
2674 if (dc->config.gpu_vm_support)
2675 mi->funcs->mem_input_program_pte_vm(
2676 pipe_ctx->plane_res.mi,
2677 plane_state->format,
2678 &plane_state->tiling_info,
2679 plane_state->rotation);
2680
2681
2682 if (pipe_ctx->plane_state->update_flags.bits.full_update ||
2683 pipe_ctx->plane_state->update_flags.bits.in_transfer_func_change ||
2684 pipe_ctx->plane_state->update_flags.bits.gamma_change)
2685 hws->funcs.set_input_transfer_func(dc, pipe_ctx, pipe_ctx->plane_state);
2686
2687 if (pipe_ctx->plane_state->update_flags.bits.full_update)
2688 hws->funcs.set_output_transfer_func(dc, pipe_ctx, pipe_ctx->stream);
2689
2690 DC_LOG_SURFACE(
2691 "Pipe:%d %p: addr hi:0x%x, "
2692 "addr low:0x%x, "
2693 "src: %d, %d, %d,"
2694 " %d; dst: %d, %d, %d, %d;"
2695 "clip: %d, %d, %d, %d\n",
2696 pipe_ctx->pipe_idx,
2697 (void *) pipe_ctx->plane_state,
2698 pipe_ctx->plane_state->address.grph.addr.high_part,
2699 pipe_ctx->plane_state->address.grph.addr.low_part,
2700 pipe_ctx->plane_state->src_rect.x,
2701 pipe_ctx->plane_state->src_rect.y,
2702 pipe_ctx->plane_state->src_rect.width,
2703 pipe_ctx->plane_state->src_rect.height,
2704 pipe_ctx->plane_state->dst_rect.x,
2705 pipe_ctx->plane_state->dst_rect.y,
2706 pipe_ctx->plane_state->dst_rect.width,
2707 pipe_ctx->plane_state->dst_rect.height,
2708 pipe_ctx->plane_state->clip_rect.x,
2709 pipe_ctx->plane_state->clip_rect.y,
2710 pipe_ctx->plane_state->clip_rect.width,
2711 pipe_ctx->plane_state->clip_rect.height);
2712
2713 DC_LOG_SURFACE(
2714 "Pipe %d: width, height, x, y\n"
2715 "viewport:%d, %d, %d, %d\n"
2716 "recout: %d, %d, %d, %d\n",
2717 pipe_ctx->pipe_idx,
2718 pipe_ctx->plane_res.scl_data.viewport.width,
2719 pipe_ctx->plane_res.scl_data.viewport.height,
2720 pipe_ctx->plane_res.scl_data.viewport.x,
2721 pipe_ctx->plane_res.scl_data.viewport.y,
2722 pipe_ctx->plane_res.scl_data.recout.width,
2723 pipe_ctx->plane_res.scl_data.recout.height,
2724 pipe_ctx->plane_res.scl_data.recout.x,
2725 pipe_ctx->plane_res.scl_data.recout.y);
2726}
2727
2728static void dce110_apply_ctx_for_surface(
2729 struct dc *dc,
2730 const struct dc_stream_state *stream,
2731 int num_planes,
2732 struct dc_state *context)
2733{
2734 int i;
2735
2736 if (num_planes == 0)
2737 return;
2738
2739 if (dc->fbc_compressor)
2740 dc->fbc_compressor->funcs->disable_fbc(dc->fbc_compressor);
2741
2742 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2743 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2744
2745 if (pipe_ctx->stream != stream)
2746 continue;
2747
2748
2749 pipe_ctx->plane_res.mi->funcs->allocate_mem_input(
2750 pipe_ctx->plane_res.mi,
2751 pipe_ctx->stream->timing.h_total,
2752 pipe_ctx->stream->timing.v_total,
2753 pipe_ctx->stream->timing.pix_clk_100hz / 10,
2754 context->stream_count);
2755
2756 dce110_program_front_end_for_pipe(dc, pipe_ctx);
2757
2758 dc->hwss.update_plane_addr(dc, pipe_ctx);
2759
2760 program_surface_visibility(dc, pipe_ctx);
2761
2762 }
2763
2764 if (dc->fbc_compressor)
2765 enable_fbc(dc, context);
2766}
2767
2768static void dce110_post_unlock_program_front_end(
2769 struct dc *dc,
2770 struct dc_state *context)
2771{
2772}
2773
2774static void dce110_power_down_fe(struct dc *dc, struct pipe_ctx *pipe_ctx)
2775{
2776 struct dce_hwseq *hws = dc->hwseq;
2777 int fe_idx = pipe_ctx->plane_res.mi ?
2778 pipe_ctx->plane_res.mi->inst : pipe_ctx->pipe_idx;
2779
2780
2781 if (dc->current_state->res_ctx.pipe_ctx[fe_idx].stream)
2782 return;
2783
2784 hws->funcs.enable_display_power_gating(
2785 dc, fe_idx, dc->ctx->dc_bios, PIPE_GATING_CONTROL_ENABLE);
2786
2787 dc->res_pool->transforms[fe_idx]->funcs->transform_reset(
2788 dc->res_pool->transforms[fe_idx]);
2789}
2790
2791static void dce110_wait_for_mpcc_disconnect(
2792 struct dc *dc,
2793 struct resource_pool *res_pool,
2794 struct pipe_ctx *pipe_ctx)
2795{
2796
2797}
2798
2799static void program_output_csc(struct dc *dc,
2800 struct pipe_ctx *pipe_ctx,
2801 enum dc_color_space colorspace,
2802 uint16_t *matrix,
2803 int opp_id)
2804{
2805 int i;
2806 struct out_csc_color_matrix tbl_entry;
2807
2808 if (pipe_ctx->stream->csc_color_matrix.enable_adjustment == true) {
2809 enum dc_color_space color_space = pipe_ctx->stream->output_color_space;
2810
2811 for (i = 0; i < 12; i++)
2812 tbl_entry.regval[i] = pipe_ctx->stream->csc_color_matrix.matrix[i];
2813
2814 tbl_entry.color_space = color_space;
2815
2816 pipe_ctx->plane_res.xfm->funcs->opp_set_csc_adjustment(
2817 pipe_ctx->plane_res.xfm, &tbl_entry);
2818 }
2819}
2820
2821static void dce110_set_cursor_position(struct pipe_ctx *pipe_ctx)
2822{
2823 struct dc_cursor_position pos_cpy = pipe_ctx->stream->cursor_position;
2824 struct input_pixel_processor *ipp = pipe_ctx->plane_res.ipp;
2825 struct mem_input *mi = pipe_ctx->plane_res.mi;
2826 struct dc_cursor_mi_param param = {
2827 .pixel_clk_khz = pipe_ctx->stream->timing.pix_clk_100hz / 10,
2828 .ref_clk_khz = pipe_ctx->stream->ctx->dc->res_pool->ref_clocks.xtalin_clock_inKhz,
2829 .viewport = pipe_ctx->plane_res.scl_data.viewport,
2830 .h_scale_ratio = pipe_ctx->plane_res.scl_data.ratios.horz,
2831 .v_scale_ratio = pipe_ctx->plane_res.scl_data.ratios.vert,
2832 .rotation = pipe_ctx->plane_state->rotation,
2833 .mirror = pipe_ctx->plane_state->horizontal_mirror
2834 };
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848 if (pos_cpy.translate_by_source) {
2849 pos_cpy.x += pipe_ctx->plane_state->src_rect.x;
2850 pos_cpy.y += pipe_ctx->plane_state->src_rect.y;
2851 }
2852
2853 if (pipe_ctx->plane_state->address.type
2854 == PLN_ADDR_TYPE_VIDEO_PROGRESSIVE)
2855 pos_cpy.enable = false;
2856
2857 if (pipe_ctx->top_pipe && pipe_ctx->plane_state != pipe_ctx->top_pipe->plane_state)
2858 pos_cpy.enable = false;
2859
2860 if (ipp->funcs->ipp_cursor_set_position)
2861 ipp->funcs->ipp_cursor_set_position(ipp, &pos_cpy, ¶m);
2862 if (mi->funcs->set_cursor_position)
2863 mi->funcs->set_cursor_position(mi, &pos_cpy, ¶m);
2864}
2865
2866static void dce110_set_cursor_attribute(struct pipe_ctx *pipe_ctx)
2867{
2868 struct dc_cursor_attributes *attributes = &pipe_ctx->stream->cursor_attributes;
2869
2870 if (pipe_ctx->plane_res.ipp &&
2871 pipe_ctx->plane_res.ipp->funcs->ipp_cursor_set_attributes)
2872 pipe_ctx->plane_res.ipp->funcs->ipp_cursor_set_attributes(
2873 pipe_ctx->plane_res.ipp, attributes);
2874
2875 if (pipe_ctx->plane_res.mi &&
2876 pipe_ctx->plane_res.mi->funcs->set_cursor_attributes)
2877 pipe_ctx->plane_res.mi->funcs->set_cursor_attributes(
2878 pipe_ctx->plane_res.mi, attributes);
2879
2880 if (pipe_ctx->plane_res.xfm &&
2881 pipe_ctx->plane_res.xfm->funcs->set_cursor_attributes)
2882 pipe_ctx->plane_res.xfm->funcs->set_cursor_attributes(
2883 pipe_ctx->plane_res.xfm, attributes);
2884}
2885
2886bool dce110_set_backlight_level(struct pipe_ctx *pipe_ctx,
2887 uint32_t backlight_pwm_u16_16,
2888 uint32_t frame_ramp)
2889{
2890 struct dc_link *link = pipe_ctx->stream->link;
2891 struct dc *dc = link->ctx->dc;
2892 struct abm *abm = pipe_ctx->stream_res.abm;
2893 struct panel_cntl *panel_cntl = link->panel_cntl;
2894 struct dmcu *dmcu = dc->res_pool->dmcu;
2895 bool fw_set_brightness = true;
2896
2897
2898
2899 uint32_t controller_id = pipe_ctx->stream_res.tg->inst + 1;
2900
2901 if (abm == NULL || panel_cntl == NULL || (abm->funcs->set_backlight_level_pwm == NULL))
2902 return false;
2903
2904 if (dmcu)
2905 fw_set_brightness = dmcu->funcs->is_dmcu_initialized(dmcu);
2906
2907 if (!fw_set_brightness && panel_cntl->funcs->driver_set_backlight)
2908 panel_cntl->funcs->driver_set_backlight(panel_cntl, backlight_pwm_u16_16);
2909 else
2910 abm->funcs->set_backlight_level_pwm(
2911 abm,
2912 backlight_pwm_u16_16,
2913 frame_ramp,
2914 controller_id,
2915 link->panel_cntl->inst);
2916
2917 return true;
2918}
2919
2920void dce110_set_abm_immediate_disable(struct pipe_ctx *pipe_ctx)
2921{
2922 struct abm *abm = pipe_ctx->stream_res.abm;
2923 struct panel_cntl *panel_cntl = pipe_ctx->stream->link->panel_cntl;
2924
2925 if (abm)
2926 abm->funcs->set_abm_immediate_disable(abm,
2927 pipe_ctx->stream->link->panel_cntl->inst);
2928
2929 if (panel_cntl)
2930 panel_cntl->funcs->store_backlight_level(panel_cntl);
2931}
2932
2933void dce110_set_pipe(struct pipe_ctx *pipe_ctx)
2934{
2935 struct abm *abm = pipe_ctx->stream_res.abm;
2936 struct panel_cntl *panel_cntl = pipe_ctx->stream->link->panel_cntl;
2937 uint32_t otg_inst = pipe_ctx->stream_res.tg->inst + 1;
2938
2939 if (abm && panel_cntl)
2940 abm->funcs->set_pipe(abm, otg_inst, panel_cntl->inst);
2941}
2942
2943static const struct hw_sequencer_funcs dce110_funcs = {
2944 .program_gamut_remap = program_gamut_remap,
2945 .program_output_csc = program_output_csc,
2946 .init_hw = init_hw,
2947 .apply_ctx_to_hw = dce110_apply_ctx_to_hw,
2948 .apply_ctx_for_surface = dce110_apply_ctx_for_surface,
2949 .post_unlock_program_front_end = dce110_post_unlock_program_front_end,
2950 .update_plane_addr = update_plane_addr,
2951 .update_pending_status = dce110_update_pending_status,
2952 .enable_accelerated_mode = dce110_enable_accelerated_mode,
2953 .enable_timing_synchronization = dce110_enable_timing_synchronization,
2954 .enable_per_frame_crtc_position_reset = dce110_enable_per_frame_crtc_position_reset,
2955 .update_info_frame = dce110_update_info_frame,
2956 .enable_stream = dce110_enable_stream,
2957 .disable_stream = dce110_disable_stream,
2958 .unblank_stream = dce110_unblank_stream,
2959 .blank_stream = dce110_blank_stream,
2960 .enable_audio_stream = dce110_enable_audio_stream,
2961 .disable_audio_stream = dce110_disable_audio_stream,
2962 .disable_plane = dce110_power_down_fe,
2963 .pipe_control_lock = dce_pipe_control_lock,
2964 .interdependent_update_lock = NULL,
2965 .cursor_lock = dce_pipe_control_lock,
2966 .prepare_bandwidth = dce110_prepare_bandwidth,
2967 .optimize_bandwidth = dce110_optimize_bandwidth,
2968 .set_drr = set_drr,
2969 .get_position = get_position,
2970 .set_static_screen_control = set_static_screen_control,
2971 .setup_stereo = NULL,
2972 .set_avmute = dce110_set_avmute,
2973 .wait_for_mpcc_disconnect = dce110_wait_for_mpcc_disconnect,
2974 .edp_backlight_control = dce110_edp_backlight_control,
2975 .edp_power_control = dce110_edp_power_control,
2976 .edp_wait_for_hpd_ready = dce110_edp_wait_for_hpd_ready,
2977 .set_cursor_position = dce110_set_cursor_position,
2978 .set_cursor_attribute = dce110_set_cursor_attribute,
2979 .set_backlight_level = dce110_set_backlight_level,
2980 .set_abm_immediate_disable = dce110_set_abm_immediate_disable,
2981 .set_pipe = dce110_set_pipe,
2982};
2983
2984static const struct hwseq_private_funcs dce110_private_funcs = {
2985 .init_pipes = init_pipes,
2986 .update_plane_addr = update_plane_addr,
2987 .set_input_transfer_func = dce110_set_input_transfer_func,
2988 .set_output_transfer_func = dce110_set_output_transfer_func,
2989 .power_down = dce110_power_down,
2990 .enable_display_pipe_clock_gating = enable_display_pipe_clock_gating,
2991 .enable_display_power_gating = dce110_enable_display_power_gating,
2992 .reset_hw_ctx_wrap = dce110_reset_hw_ctx_wrap,
2993 .enable_stream_timing = dce110_enable_stream_timing,
2994 .disable_stream_gating = NULL,
2995 .enable_stream_gating = NULL,
2996 .edp_backlight_control = dce110_edp_backlight_control,
2997};
2998
2999void dce110_hw_sequencer_construct(struct dc *dc)
3000{
3001 dc->hwss = dce110_funcs;
3002 dc->hwseq->funcs = dce110_private_funcs;
3003}
3004
3005