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