14562236bSHarry Wentland /*
24562236bSHarry Wentland  * Copyright 2015 Advanced Micro Devices, Inc.
34562236bSHarry Wentland  *
44562236bSHarry Wentland  * Permission is hereby granted, free of charge, to any person obtaining a
54562236bSHarry Wentland  * copy of this software and associated documentation files (the "Software"),
64562236bSHarry Wentland  * to deal in the Software without restriction, including without limitation
74562236bSHarry Wentland  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
84562236bSHarry Wentland  * and/or sell copies of the Software, and to permit persons to whom the
94562236bSHarry Wentland  * Software is furnished to do so, subject to the following conditions:
104562236bSHarry Wentland  *
114562236bSHarry Wentland  * The above copyright notice and this permission notice shall be included in
124562236bSHarry Wentland  * all copies or substantial portions of the Software.
134562236bSHarry Wentland  *
144562236bSHarry Wentland  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
154562236bSHarry Wentland  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
164562236bSHarry Wentland  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
174562236bSHarry Wentland  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
184562236bSHarry Wentland  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
194562236bSHarry Wentland  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
204562236bSHarry Wentland  * OTHER DEALINGS IN THE SOFTWARE.
214562236bSHarry Wentland  *
224562236bSHarry Wentland  * Authors: AMD
234562236bSHarry Wentland  *
244562236bSHarry Wentland  */
254562236bSHarry Wentland #include "dm_services.h"
264562236bSHarry Wentland #include "dc.h"
274562236bSHarry Wentland #include "dc_bios_types.h"
284562236bSHarry Wentland #include "core_types.h"
294562236bSHarry Wentland #include "core_status.h"
304562236bSHarry Wentland #include "resource.h"
314562236bSHarry Wentland #include "hw_sequencer.h"
324562236bSHarry Wentland #include "dm_helpers.h"
334562236bSHarry Wentland #include "dce110_hw_sequencer.h"
344562236bSHarry Wentland #include "dce110_timing_generator.h"
354562236bSHarry Wentland 
364562236bSHarry Wentland #include "bios/bios_parser_helper.h"
374562236bSHarry Wentland #include "timing_generator.h"
384562236bSHarry Wentland #include "mem_input.h"
394562236bSHarry Wentland #include "opp.h"
404562236bSHarry Wentland #include "ipp.h"
414562236bSHarry Wentland #include "transform.h"
424562236bSHarry Wentland #include "stream_encoder.h"
434562236bSHarry Wentland #include "link_encoder.h"
444562236bSHarry Wentland #include "clock_source.h"
454562236bSHarry Wentland #include "audio.h"
464562236bSHarry Wentland #include "dce/dce_hwseq.h"
474562236bSHarry Wentland 
484562236bSHarry Wentland /* include DCE11 register header files */
494562236bSHarry Wentland #include "dce/dce_11_0_d.h"
504562236bSHarry Wentland #include "dce/dce_11_0_sh_mask.h"
514562236bSHarry Wentland 
524562236bSHarry Wentland struct dce110_hw_seq_reg_offsets {
534562236bSHarry Wentland 	uint32_t crtc;
544562236bSHarry Wentland };
554562236bSHarry Wentland 
564562236bSHarry Wentland static const struct dce110_hw_seq_reg_offsets reg_offsets[] = {
574562236bSHarry Wentland {
584562236bSHarry Wentland 	.crtc = (mmCRTC0_CRTC_GSL_CONTROL - mmCRTC_GSL_CONTROL),
594562236bSHarry Wentland },
604562236bSHarry Wentland {
614562236bSHarry Wentland 	.crtc = (mmCRTC1_CRTC_GSL_CONTROL - mmCRTC_GSL_CONTROL),
624562236bSHarry Wentland },
634562236bSHarry Wentland {
644562236bSHarry Wentland 	.crtc = (mmCRTC2_CRTC_GSL_CONTROL - mmCRTC_GSL_CONTROL),
654562236bSHarry Wentland },
664562236bSHarry Wentland {
674562236bSHarry Wentland 	.crtc = (mmCRTCV_GSL_CONTROL - mmCRTC_GSL_CONTROL),
684562236bSHarry Wentland }
694562236bSHarry Wentland };
704562236bSHarry Wentland 
714562236bSHarry Wentland #define HW_REG_BLND(reg, id)\
724562236bSHarry Wentland 	(reg + reg_offsets[id].blnd)
734562236bSHarry Wentland 
744562236bSHarry Wentland #define HW_REG_CRTC(reg, id)\
754562236bSHarry Wentland 	(reg + reg_offsets[id].crtc)
764562236bSHarry Wentland 
774562236bSHarry Wentland #define MAX_WATERMARK 0xFFFF
784562236bSHarry Wentland #define SAFE_NBP_MARK 0x7FFF
794562236bSHarry Wentland 
804562236bSHarry Wentland /*******************************************************************************
814562236bSHarry Wentland  * Private definitions
824562236bSHarry Wentland  ******************************************************************************/
834562236bSHarry Wentland /***************************PIPE_CONTROL***********************************/
844562236bSHarry Wentland static void dce110_init_pte(struct dc_context *ctx)
854562236bSHarry Wentland {
864562236bSHarry Wentland 	uint32_t addr;
874562236bSHarry Wentland 	uint32_t value = 0;
884562236bSHarry Wentland 	uint32_t chunk_int = 0;
894562236bSHarry Wentland 	uint32_t chunk_mul = 0;
904562236bSHarry Wentland 
914562236bSHarry Wentland 	addr = mmUNP_DVMM_PTE_CONTROL;
924562236bSHarry Wentland 	value = dm_read_reg(ctx, addr);
934562236bSHarry Wentland 
944562236bSHarry Wentland 	set_reg_field_value(
954562236bSHarry Wentland 		value,
964562236bSHarry Wentland 		0,
974562236bSHarry Wentland 		DVMM_PTE_CONTROL,
984562236bSHarry Wentland 		DVMM_USE_SINGLE_PTE);
994562236bSHarry Wentland 
1004562236bSHarry Wentland 	set_reg_field_value(
1014562236bSHarry Wentland 		value,
1024562236bSHarry Wentland 		1,
1034562236bSHarry Wentland 		DVMM_PTE_CONTROL,
1044562236bSHarry Wentland 		DVMM_PTE_BUFFER_MODE0);
1054562236bSHarry Wentland 
1064562236bSHarry Wentland 	set_reg_field_value(
1074562236bSHarry Wentland 		value,
1084562236bSHarry Wentland 		1,
1094562236bSHarry Wentland 		DVMM_PTE_CONTROL,
1104562236bSHarry Wentland 		DVMM_PTE_BUFFER_MODE1);
1114562236bSHarry Wentland 
1124562236bSHarry Wentland 	dm_write_reg(ctx, addr, value);
1134562236bSHarry Wentland 
1144562236bSHarry Wentland 	addr = mmDVMM_PTE_REQ;
1154562236bSHarry Wentland 	value = dm_read_reg(ctx, addr);
1164562236bSHarry Wentland 
1174562236bSHarry Wentland 	chunk_int = get_reg_field_value(
1184562236bSHarry Wentland 		value,
1194562236bSHarry Wentland 		DVMM_PTE_REQ,
1204562236bSHarry Wentland 		HFLIP_PTEREQ_PER_CHUNK_INT);
1214562236bSHarry Wentland 
1224562236bSHarry Wentland 	chunk_mul = get_reg_field_value(
1234562236bSHarry Wentland 		value,
1244562236bSHarry Wentland 		DVMM_PTE_REQ,
1254562236bSHarry Wentland 		HFLIP_PTEREQ_PER_CHUNK_MULTIPLIER);
1264562236bSHarry Wentland 
1274562236bSHarry Wentland 	if (chunk_int != 0x4 || chunk_mul != 0x4) {
1284562236bSHarry Wentland 
1294562236bSHarry Wentland 		set_reg_field_value(
1304562236bSHarry Wentland 			value,
1314562236bSHarry Wentland 			255,
1324562236bSHarry Wentland 			DVMM_PTE_REQ,
1334562236bSHarry Wentland 			MAX_PTEREQ_TO_ISSUE);
1344562236bSHarry Wentland 
1354562236bSHarry Wentland 		set_reg_field_value(
1364562236bSHarry Wentland 			value,
1374562236bSHarry Wentland 			4,
1384562236bSHarry Wentland 			DVMM_PTE_REQ,
1394562236bSHarry Wentland 			HFLIP_PTEREQ_PER_CHUNK_INT);
1404562236bSHarry Wentland 
1414562236bSHarry Wentland 		set_reg_field_value(
1424562236bSHarry Wentland 			value,
1434562236bSHarry Wentland 			4,
1444562236bSHarry Wentland 			DVMM_PTE_REQ,
1454562236bSHarry Wentland 			HFLIP_PTEREQ_PER_CHUNK_MULTIPLIER);
1464562236bSHarry Wentland 
1474562236bSHarry Wentland 		dm_write_reg(ctx, addr, value);
1484562236bSHarry Wentland 	}
1494562236bSHarry Wentland }
1504562236bSHarry Wentland /**************************************************************************/
1514562236bSHarry Wentland 
1524562236bSHarry Wentland static void enable_display_pipe_clock_gating(
1534562236bSHarry Wentland 	struct dc_context *ctx,
1544562236bSHarry Wentland 	bool clock_gating)
1554562236bSHarry Wentland {
1564562236bSHarry Wentland 	/*TODO*/
1574562236bSHarry Wentland }
1584562236bSHarry Wentland 
1594562236bSHarry Wentland static bool dce110_enable_display_power_gating(
1604562236bSHarry Wentland 	struct core_dc *dc,
1614562236bSHarry Wentland 	uint8_t controller_id,
1624562236bSHarry Wentland 	struct dc_bios *dcb,
1634562236bSHarry Wentland 	enum pipe_gating_control power_gating)
1644562236bSHarry Wentland {
1654562236bSHarry Wentland 	enum bp_result bp_result = BP_RESULT_OK;
1664562236bSHarry Wentland 	enum bp_pipe_control_action cntl;
1674562236bSHarry Wentland 	struct dc_context *ctx = dc->ctx;
1684562236bSHarry Wentland 	unsigned int underlay_idx = dc->res_pool->underlay_pipe_index;
1694562236bSHarry Wentland 
1704562236bSHarry Wentland 	if (IS_FPGA_MAXIMUS_DC(ctx->dce_environment))
1714562236bSHarry Wentland 		return true;
1724562236bSHarry Wentland 
1734562236bSHarry Wentland 	if (power_gating == PIPE_GATING_CONTROL_INIT)
1744562236bSHarry Wentland 		cntl = ASIC_PIPE_INIT;
1754562236bSHarry Wentland 	else if (power_gating == PIPE_GATING_CONTROL_ENABLE)
1764562236bSHarry Wentland 		cntl = ASIC_PIPE_ENABLE;
1774562236bSHarry Wentland 	else
1784562236bSHarry Wentland 		cntl = ASIC_PIPE_DISABLE;
1794562236bSHarry Wentland 
1804562236bSHarry Wentland 	if (controller_id == underlay_idx)
1814562236bSHarry Wentland 		controller_id = CONTROLLER_ID_UNDERLAY0 - 1;
1824562236bSHarry Wentland 
1834562236bSHarry Wentland 	if (power_gating != PIPE_GATING_CONTROL_INIT || controller_id == 0){
1844562236bSHarry Wentland 
1854562236bSHarry Wentland 		bp_result = dcb->funcs->enable_disp_power_gating(
1864562236bSHarry Wentland 						dcb, controller_id + 1, cntl);
1874562236bSHarry Wentland 
1884562236bSHarry Wentland 		/* Revert MASTER_UPDATE_MODE to 0 because bios sets it 2
1894562236bSHarry Wentland 		 * by default when command table is called
1904562236bSHarry Wentland 		 *
1914562236bSHarry Wentland 		 * Bios parser accepts controller_id = 6 as indicative of
1924562236bSHarry Wentland 		 * underlay pipe in dce110. But we do not support more
1934562236bSHarry Wentland 		 * than 3.
1944562236bSHarry Wentland 		 */
1954562236bSHarry Wentland 		if (controller_id < CONTROLLER_ID_MAX - 1)
1964562236bSHarry Wentland 			dm_write_reg(ctx,
1974562236bSHarry Wentland 				HW_REG_CRTC(mmCRTC_MASTER_UPDATE_MODE, controller_id),
1984562236bSHarry Wentland 				0);
1994562236bSHarry Wentland 	}
2004562236bSHarry Wentland 
2014562236bSHarry Wentland 	if (power_gating != PIPE_GATING_CONTROL_ENABLE)
2024562236bSHarry Wentland 		dce110_init_pte(ctx);
2034562236bSHarry Wentland 
2044562236bSHarry Wentland 	if (bp_result == BP_RESULT_OK)
2054562236bSHarry Wentland 		return true;
2064562236bSHarry Wentland 	else
2074562236bSHarry Wentland 		return false;
2084562236bSHarry Wentland }
2094562236bSHarry Wentland 
2104562236bSHarry Wentland static void build_prescale_params(struct ipp_prescale_params *prescale_params,
2114562236bSHarry Wentland 		const struct core_surface *surface)
2124562236bSHarry Wentland {
2134562236bSHarry Wentland 	prescale_params->mode = IPP_PRESCALE_MODE_FIXED_UNSIGNED;
2144562236bSHarry Wentland 
2154562236bSHarry Wentland 	switch (surface->public.format) {
2164562236bSHarry Wentland 	case SURFACE_PIXEL_FORMAT_GRPH_ARGB8888:
2178693049aSTony Cheng 	case SURFACE_PIXEL_FORMAT_GRPH_ABGR8888:
2184562236bSHarry Wentland 		prescale_params->scale = 0x2020;
2194562236bSHarry Wentland 		break;
2204562236bSHarry Wentland 	case SURFACE_PIXEL_FORMAT_GRPH_ARGB2101010:
2214562236bSHarry Wentland 	case SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010:
2224562236bSHarry Wentland 		prescale_params->scale = 0x2008;
2234562236bSHarry Wentland 		break;
2244562236bSHarry Wentland 	case SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616:
2254562236bSHarry Wentland 	case SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616F:
2264562236bSHarry Wentland 		prescale_params->scale = 0x2000;
2274562236bSHarry Wentland 		break;
2284562236bSHarry Wentland 	default:
2294562236bSHarry Wentland 		ASSERT(false);
230d7194cf6SAric Cyr 		break;
2314562236bSHarry Wentland 	}
2324562236bSHarry Wentland }
2334562236bSHarry Wentland 
234d7194cf6SAric Cyr static bool dce110_set_input_transfer_func(
235fb735a9fSAnthony Koo 	struct pipe_ctx *pipe_ctx,
2364562236bSHarry Wentland 	const struct core_surface *surface)
2374562236bSHarry Wentland {
238fb735a9fSAnthony Koo 	struct input_pixel_processor *ipp = pipe_ctx->ipp;
23990e508baSAnthony Koo 	const struct core_transfer_func *tf = NULL;
24090e508baSAnthony Koo 	struct ipp_prescale_params prescale_params = { 0 };
24190e508baSAnthony Koo 	bool result = true;
24290e508baSAnthony Koo 
24390e508baSAnthony Koo 	if (ipp == NULL)
24490e508baSAnthony Koo 		return false;
24590e508baSAnthony Koo 
24690e508baSAnthony Koo 	if (surface->public.in_transfer_func)
24790e508baSAnthony Koo 		tf = DC_TRANSFER_FUNC_TO_CORE(surface->public.in_transfer_func);
24890e508baSAnthony Koo 
24990e508baSAnthony Koo 	build_prescale_params(&prescale_params, surface);
25090e508baSAnthony Koo 	ipp->funcs->ipp_program_prescale(ipp, &prescale_params);
25190e508baSAnthony Koo 
252d7194cf6SAric Cyr 	if (surface->public.gamma_correction)
253d7194cf6SAric Cyr 	    ipp->funcs->ipp_program_input_lut(ipp, surface->public.gamma_correction);
254d7194cf6SAric Cyr 
25590e508baSAnthony Koo 	if (tf == NULL) {
25690e508baSAnthony Koo 		/* Default case if no input transfer function specified */
25790e508baSAnthony Koo 		ipp->funcs->ipp_set_degamma(ipp,
258306dadf0SAmy Zhang 				IPP_DEGAMMA_MODE_HW_sRGB);
25990e508baSAnthony Koo 	} else if (tf->public.type == TF_TYPE_PREDEFINED) {
26090e508baSAnthony Koo 		switch (tf->public.tf) {
26190e508baSAnthony Koo 		case TRANSFER_FUNCTION_SRGB:
26290e508baSAnthony Koo 			ipp->funcs->ipp_set_degamma(ipp,
26390e508baSAnthony Koo 					IPP_DEGAMMA_MODE_HW_sRGB);
26490e508baSAnthony Koo 			break;
26590e508baSAnthony Koo 		case TRANSFER_FUNCTION_BT709:
26690e508baSAnthony Koo 			ipp->funcs->ipp_set_degamma(ipp,
26790e508baSAnthony Koo 					IPP_DEGAMMA_MODE_HW_xvYCC);
26890e508baSAnthony Koo 			break;
26990e508baSAnthony Koo 		case TRANSFER_FUNCTION_LINEAR:
27090e508baSAnthony Koo 			ipp->funcs->ipp_set_degamma(ipp,
27190e508baSAnthony Koo 					IPP_DEGAMMA_MODE_BYPASS);
27290e508baSAnthony Koo 			break;
27390e508baSAnthony Koo 		case TRANSFER_FUNCTION_PQ:
27490e508baSAnthony Koo 			result = false;
27590e508baSAnthony Koo 			break;
27690e508baSAnthony Koo 		default:
27790e508baSAnthony Koo 			result = false;
278d7194cf6SAric Cyr 			break;
27990e508baSAnthony Koo 		}
28090e508baSAnthony Koo 	} else {
28190e508baSAnthony Koo 		/*TF_TYPE_DISTRIBUTED_POINTS - Not supported in DCE 11*/
28290e508baSAnthony Koo 		result = false;
28390e508baSAnthony Koo 	}
28490e508baSAnthony Koo 
28590e508baSAnthony Koo 	return result;
28690e508baSAnthony Koo }
28790e508baSAnthony Koo 
288fcd2f4bfSAmy Zhang static bool build_custom_float(
289fcd2f4bfSAmy Zhang 	struct fixed31_32 value,
290fcd2f4bfSAmy Zhang 	const struct custom_float_format *format,
291fcd2f4bfSAmy Zhang 	bool *negative,
292fcd2f4bfSAmy Zhang 	uint32_t *mantissa,
293fcd2f4bfSAmy Zhang 	uint32_t *exponenta)
294fcd2f4bfSAmy Zhang {
295fcd2f4bfSAmy Zhang 	uint32_t exp_offset = (1 << (format->exponenta_bits - 1)) - 1;
296fcd2f4bfSAmy Zhang 
297fcd2f4bfSAmy Zhang 	const struct fixed31_32 mantissa_constant_plus_max_fraction =
298fcd2f4bfSAmy Zhang 		dal_fixed31_32_from_fraction(
299fcd2f4bfSAmy Zhang 			(1LL << (format->mantissa_bits + 1)) - 1,
300fcd2f4bfSAmy Zhang 			1LL << format->mantissa_bits);
301fcd2f4bfSAmy Zhang 
302fcd2f4bfSAmy Zhang 	struct fixed31_32 mantiss;
303fcd2f4bfSAmy Zhang 
304fcd2f4bfSAmy Zhang 	if (dal_fixed31_32_eq(
305fcd2f4bfSAmy Zhang 		value,
306fcd2f4bfSAmy Zhang 		dal_fixed31_32_zero)) {
307fcd2f4bfSAmy Zhang 		*negative = false;
308fcd2f4bfSAmy Zhang 		*mantissa = 0;
309fcd2f4bfSAmy Zhang 		*exponenta = 0;
310fcd2f4bfSAmy Zhang 		return true;
311fcd2f4bfSAmy Zhang 	}
312fcd2f4bfSAmy Zhang 
313fcd2f4bfSAmy Zhang 	if (dal_fixed31_32_lt(
314fcd2f4bfSAmy Zhang 		value,
315fcd2f4bfSAmy Zhang 		dal_fixed31_32_zero)) {
316fcd2f4bfSAmy Zhang 		*negative = format->sign;
317fcd2f4bfSAmy Zhang 		value = dal_fixed31_32_neg(value);
318fcd2f4bfSAmy Zhang 	} else {
319fcd2f4bfSAmy Zhang 		*negative = false;
320fcd2f4bfSAmy Zhang 	}
321fcd2f4bfSAmy Zhang 
322fcd2f4bfSAmy Zhang 	if (dal_fixed31_32_lt(
323fcd2f4bfSAmy Zhang 		value,
324fcd2f4bfSAmy Zhang 		dal_fixed31_32_one)) {
325fcd2f4bfSAmy Zhang 		uint32_t i = 1;
326fcd2f4bfSAmy Zhang 
327fcd2f4bfSAmy Zhang 		do {
328fcd2f4bfSAmy Zhang 			value = dal_fixed31_32_shl(value, 1);
329fcd2f4bfSAmy Zhang 			++i;
330fcd2f4bfSAmy Zhang 		} while (dal_fixed31_32_lt(
331fcd2f4bfSAmy Zhang 			value,
332fcd2f4bfSAmy Zhang 			dal_fixed31_32_one));
333fcd2f4bfSAmy Zhang 
334fcd2f4bfSAmy Zhang 		--i;
335fcd2f4bfSAmy Zhang 
336fcd2f4bfSAmy Zhang 		if (exp_offset <= i) {
337fcd2f4bfSAmy Zhang 			*mantissa = 0;
338fcd2f4bfSAmy Zhang 			*exponenta = 0;
339fcd2f4bfSAmy Zhang 			return true;
340fcd2f4bfSAmy Zhang 		}
341fcd2f4bfSAmy Zhang 
342fcd2f4bfSAmy Zhang 		*exponenta = exp_offset - i;
343fcd2f4bfSAmy Zhang 	} else if (dal_fixed31_32_le(
344fcd2f4bfSAmy Zhang 		mantissa_constant_plus_max_fraction,
345fcd2f4bfSAmy Zhang 		value)) {
346fcd2f4bfSAmy Zhang 		uint32_t i = 1;
347fcd2f4bfSAmy Zhang 
348fcd2f4bfSAmy Zhang 		do {
349fcd2f4bfSAmy Zhang 			value = dal_fixed31_32_shr(value, 1);
350fcd2f4bfSAmy Zhang 			++i;
351fcd2f4bfSAmy Zhang 		} while (dal_fixed31_32_lt(
352fcd2f4bfSAmy Zhang 			mantissa_constant_plus_max_fraction,
353fcd2f4bfSAmy Zhang 			value));
354fcd2f4bfSAmy Zhang 
355fcd2f4bfSAmy Zhang 		*exponenta = exp_offset + i - 1;
356fcd2f4bfSAmy Zhang 	} else {
357fcd2f4bfSAmy Zhang 		*exponenta = exp_offset;
358fcd2f4bfSAmy Zhang 	}
359fcd2f4bfSAmy Zhang 
360fcd2f4bfSAmy Zhang 	mantiss = dal_fixed31_32_sub(
361fcd2f4bfSAmy Zhang 		value,
362fcd2f4bfSAmy Zhang 		dal_fixed31_32_one);
363fcd2f4bfSAmy Zhang 
364fcd2f4bfSAmy Zhang 	if (dal_fixed31_32_lt(
365fcd2f4bfSAmy Zhang 			mantiss,
366fcd2f4bfSAmy Zhang 			dal_fixed31_32_zero) ||
367fcd2f4bfSAmy Zhang 		dal_fixed31_32_lt(
368fcd2f4bfSAmy Zhang 			dal_fixed31_32_one,
369fcd2f4bfSAmy Zhang 			mantiss))
370fcd2f4bfSAmy Zhang 		mantiss = dal_fixed31_32_zero;
371fcd2f4bfSAmy Zhang 	else
372fcd2f4bfSAmy Zhang 		mantiss = dal_fixed31_32_shl(
373fcd2f4bfSAmy Zhang 			mantiss,
374fcd2f4bfSAmy Zhang 			format->mantissa_bits);
375fcd2f4bfSAmy Zhang 
376fcd2f4bfSAmy Zhang 	*mantissa = dal_fixed31_32_floor(mantiss);
377fcd2f4bfSAmy Zhang 
378fcd2f4bfSAmy Zhang 	return true;
379fcd2f4bfSAmy Zhang }
380fcd2f4bfSAmy Zhang 
381fcd2f4bfSAmy Zhang static bool setup_custom_float(
382fcd2f4bfSAmy Zhang 	const struct custom_float_format *format,
383fcd2f4bfSAmy Zhang 	bool negative,
384fcd2f4bfSAmy Zhang 	uint32_t mantissa,
385fcd2f4bfSAmy Zhang 	uint32_t exponenta,
386fcd2f4bfSAmy Zhang 	uint32_t *result)
387fcd2f4bfSAmy Zhang {
388fcd2f4bfSAmy Zhang 	uint32_t i = 0;
389fcd2f4bfSAmy Zhang 	uint32_t j = 0;
390fcd2f4bfSAmy Zhang 
391fcd2f4bfSAmy Zhang 	uint32_t value = 0;
392fcd2f4bfSAmy Zhang 
393fcd2f4bfSAmy Zhang 	/* verification code:
394fcd2f4bfSAmy Zhang 	 * once calculation is ok we can remove it
395fcd2f4bfSAmy Zhang 	 */
396fcd2f4bfSAmy Zhang 
397fcd2f4bfSAmy Zhang 	const uint32_t mantissa_mask =
398fcd2f4bfSAmy Zhang 		(1 << (format->mantissa_bits + 1)) - 1;
399fcd2f4bfSAmy Zhang 
400fcd2f4bfSAmy Zhang 	const uint32_t exponenta_mask =
401fcd2f4bfSAmy Zhang 		(1 << (format->exponenta_bits + 1)) - 1;
402fcd2f4bfSAmy Zhang 
403fcd2f4bfSAmy Zhang 	if (mantissa & ~mantissa_mask) {
404fcd2f4bfSAmy Zhang 		BREAK_TO_DEBUGGER();
405fcd2f4bfSAmy Zhang 		mantissa = mantissa_mask;
406fcd2f4bfSAmy Zhang 	}
407fcd2f4bfSAmy Zhang 
408fcd2f4bfSAmy Zhang 	if (exponenta & ~exponenta_mask) {
409fcd2f4bfSAmy Zhang 		BREAK_TO_DEBUGGER();
410fcd2f4bfSAmy Zhang 		exponenta = exponenta_mask;
411fcd2f4bfSAmy Zhang 	}
412fcd2f4bfSAmy Zhang 
413fcd2f4bfSAmy Zhang 	/* end of verification code */
414fcd2f4bfSAmy Zhang 
415fcd2f4bfSAmy Zhang 	while (i < format->mantissa_bits) {
416fcd2f4bfSAmy Zhang 		uint32_t mask = 1 << i;
417fcd2f4bfSAmy Zhang 
418fcd2f4bfSAmy Zhang 		if (mantissa & mask)
419fcd2f4bfSAmy Zhang 			value |= mask;
420fcd2f4bfSAmy Zhang 
421fcd2f4bfSAmy Zhang 		++i;
422fcd2f4bfSAmy Zhang 	}
423fcd2f4bfSAmy Zhang 
424fcd2f4bfSAmy Zhang 	while (j < format->exponenta_bits) {
425fcd2f4bfSAmy Zhang 		uint32_t mask = 1 << j;
426fcd2f4bfSAmy Zhang 
427fcd2f4bfSAmy Zhang 		if (exponenta & mask)
428fcd2f4bfSAmy Zhang 			value |= mask << i;
429fcd2f4bfSAmy Zhang 
430fcd2f4bfSAmy Zhang 		++j;
431fcd2f4bfSAmy Zhang 	}
432fcd2f4bfSAmy Zhang 
433fcd2f4bfSAmy Zhang 	if (negative && format->sign)
434fcd2f4bfSAmy Zhang 		value |= 1 << (i + j);
435fcd2f4bfSAmy Zhang 
436fcd2f4bfSAmy Zhang 	*result = value;
437fcd2f4bfSAmy Zhang 
438fcd2f4bfSAmy Zhang 	return true;
439fcd2f4bfSAmy Zhang }
440fcd2f4bfSAmy Zhang 
441fcd2f4bfSAmy Zhang static bool convert_to_custom_float_format(
442fcd2f4bfSAmy Zhang 	struct fixed31_32 value,
443fcd2f4bfSAmy Zhang 	const struct custom_float_format *format,
444fcd2f4bfSAmy Zhang 	uint32_t *result)
445fcd2f4bfSAmy Zhang {
446fcd2f4bfSAmy Zhang 	uint32_t mantissa;
447fcd2f4bfSAmy Zhang 	uint32_t exponenta;
448fcd2f4bfSAmy Zhang 	bool negative;
449fcd2f4bfSAmy Zhang 
450fcd2f4bfSAmy Zhang 	return build_custom_float(
451fcd2f4bfSAmy Zhang 		value, format, &negative, &mantissa, &exponenta) &&
452fcd2f4bfSAmy Zhang 	setup_custom_float(
453fcd2f4bfSAmy Zhang 		format, negative, mantissa, exponenta, result);
454fcd2f4bfSAmy Zhang }
455fcd2f4bfSAmy Zhang 
456fcd2f4bfSAmy Zhang static bool convert_to_custom_float(
457fcd2f4bfSAmy Zhang 		struct pwl_result_data *rgb_resulted,
458fcd2f4bfSAmy Zhang 		struct curve_points *arr_points,
459fcd2f4bfSAmy Zhang 		uint32_t hw_points_num)
460fcd2f4bfSAmy Zhang {
461fcd2f4bfSAmy Zhang 	struct custom_float_format fmt;
462fcd2f4bfSAmy Zhang 
463fcd2f4bfSAmy Zhang 	struct pwl_result_data *rgb = rgb_resulted;
464fcd2f4bfSAmy Zhang 
465fcd2f4bfSAmy Zhang 	uint32_t i = 0;
466fcd2f4bfSAmy Zhang 
467fcd2f4bfSAmy Zhang 	fmt.exponenta_bits = 6;
468fcd2f4bfSAmy Zhang 	fmt.mantissa_bits = 12;
469fcd2f4bfSAmy Zhang 	fmt.sign = true;
470fcd2f4bfSAmy Zhang 
471fcd2f4bfSAmy Zhang 	if (!convert_to_custom_float_format(
472fcd2f4bfSAmy Zhang 		arr_points[0].x,
473fcd2f4bfSAmy Zhang 		&fmt,
474fcd2f4bfSAmy Zhang 		&arr_points[0].custom_float_x)) {
475fcd2f4bfSAmy Zhang 		BREAK_TO_DEBUGGER();
476fcd2f4bfSAmy Zhang 		return false;
477fcd2f4bfSAmy Zhang 	}
478fcd2f4bfSAmy Zhang 
479fcd2f4bfSAmy Zhang 	if (!convert_to_custom_float_format(
480fcd2f4bfSAmy Zhang 		arr_points[0].offset,
481fcd2f4bfSAmy Zhang 		&fmt,
482fcd2f4bfSAmy Zhang 		&arr_points[0].custom_float_offset)) {
483fcd2f4bfSAmy Zhang 		BREAK_TO_DEBUGGER();
484fcd2f4bfSAmy Zhang 		return false;
485fcd2f4bfSAmy Zhang 	}
486fcd2f4bfSAmy Zhang 
487fcd2f4bfSAmy Zhang 	if (!convert_to_custom_float_format(
488fcd2f4bfSAmy Zhang 		arr_points[0].slope,
489fcd2f4bfSAmy Zhang 		&fmt,
490fcd2f4bfSAmy Zhang 		&arr_points[0].custom_float_slope)) {
491fcd2f4bfSAmy Zhang 		BREAK_TO_DEBUGGER();
492fcd2f4bfSAmy Zhang 		return false;
493fcd2f4bfSAmy Zhang 	}
494fcd2f4bfSAmy Zhang 
495fcd2f4bfSAmy Zhang 	fmt.mantissa_bits = 10;
496fcd2f4bfSAmy Zhang 	fmt.sign = false;
497fcd2f4bfSAmy Zhang 
498fcd2f4bfSAmy Zhang 	if (!convert_to_custom_float_format(
499fcd2f4bfSAmy Zhang 		arr_points[1].x,
500fcd2f4bfSAmy Zhang 		&fmt,
501fcd2f4bfSAmy Zhang 		&arr_points[1].custom_float_x)) {
502fcd2f4bfSAmy Zhang 		BREAK_TO_DEBUGGER();
503fcd2f4bfSAmy Zhang 		return false;
504fcd2f4bfSAmy Zhang 	}
505fcd2f4bfSAmy Zhang 
506fcd2f4bfSAmy Zhang 	if (!convert_to_custom_float_format(
507fcd2f4bfSAmy Zhang 		arr_points[1].y,
508fcd2f4bfSAmy Zhang 		&fmt,
509fcd2f4bfSAmy Zhang 		&arr_points[1].custom_float_y)) {
510fcd2f4bfSAmy Zhang 		BREAK_TO_DEBUGGER();
511fcd2f4bfSAmy Zhang 		return false;
512fcd2f4bfSAmy Zhang 	}
513fcd2f4bfSAmy Zhang 
514fcd2f4bfSAmy Zhang 	if (!convert_to_custom_float_format(
515fcd2f4bfSAmy Zhang 		arr_points[2].slope,
516fcd2f4bfSAmy Zhang 		&fmt,
517fcd2f4bfSAmy Zhang 		&arr_points[2].custom_float_slope)) {
518fcd2f4bfSAmy Zhang 		BREAK_TO_DEBUGGER();
519fcd2f4bfSAmy Zhang 		return false;
520fcd2f4bfSAmy Zhang 	}
521fcd2f4bfSAmy Zhang 
522fcd2f4bfSAmy Zhang 	fmt.mantissa_bits = 12;
523fcd2f4bfSAmy Zhang 	fmt.sign = true;
524fcd2f4bfSAmy Zhang 
525fcd2f4bfSAmy Zhang 	while (i != hw_points_num) {
526fcd2f4bfSAmy Zhang 		if (!convert_to_custom_float_format(
527fcd2f4bfSAmy Zhang 			rgb->red,
528fcd2f4bfSAmy Zhang 			&fmt,
529fcd2f4bfSAmy Zhang 			&rgb->red_reg)) {
530fcd2f4bfSAmy Zhang 			BREAK_TO_DEBUGGER();
531fcd2f4bfSAmy Zhang 			return false;
532fcd2f4bfSAmy Zhang 		}
533fcd2f4bfSAmy Zhang 
534fcd2f4bfSAmy Zhang 		if (!convert_to_custom_float_format(
535fcd2f4bfSAmy Zhang 			rgb->green,
536fcd2f4bfSAmy Zhang 			&fmt,
537fcd2f4bfSAmy Zhang 			&rgb->green_reg)) {
538fcd2f4bfSAmy Zhang 			BREAK_TO_DEBUGGER();
539fcd2f4bfSAmy Zhang 			return false;
540fcd2f4bfSAmy Zhang 		}
541fcd2f4bfSAmy Zhang 
542fcd2f4bfSAmy Zhang 		if (!convert_to_custom_float_format(
543fcd2f4bfSAmy Zhang 			rgb->blue,
544fcd2f4bfSAmy Zhang 			&fmt,
545fcd2f4bfSAmy Zhang 			&rgb->blue_reg)) {
546fcd2f4bfSAmy Zhang 			BREAK_TO_DEBUGGER();
547fcd2f4bfSAmy Zhang 			return false;
548fcd2f4bfSAmy Zhang 		}
549fcd2f4bfSAmy Zhang 
550fcd2f4bfSAmy Zhang 		if (!convert_to_custom_float_format(
551fcd2f4bfSAmy Zhang 			rgb->delta_red,
552fcd2f4bfSAmy Zhang 			&fmt,
553fcd2f4bfSAmy Zhang 			&rgb->delta_red_reg)) {
554fcd2f4bfSAmy Zhang 			BREAK_TO_DEBUGGER();
555fcd2f4bfSAmy Zhang 			return false;
556fcd2f4bfSAmy Zhang 		}
557fcd2f4bfSAmy Zhang 
558fcd2f4bfSAmy Zhang 		if (!convert_to_custom_float_format(
559fcd2f4bfSAmy Zhang 			rgb->delta_green,
560fcd2f4bfSAmy Zhang 			&fmt,
561fcd2f4bfSAmy Zhang 			&rgb->delta_green_reg)) {
562fcd2f4bfSAmy Zhang 			BREAK_TO_DEBUGGER();
563fcd2f4bfSAmy Zhang 			return false;
564fcd2f4bfSAmy Zhang 		}
565fcd2f4bfSAmy Zhang 
566fcd2f4bfSAmy Zhang 		if (!convert_to_custom_float_format(
567fcd2f4bfSAmy Zhang 			rgb->delta_blue,
568fcd2f4bfSAmy Zhang 			&fmt,
569fcd2f4bfSAmy Zhang 			&rgb->delta_blue_reg)) {
570fcd2f4bfSAmy Zhang 			BREAK_TO_DEBUGGER();
571fcd2f4bfSAmy Zhang 			return false;
572fcd2f4bfSAmy Zhang 		}
573fcd2f4bfSAmy Zhang 
574fcd2f4bfSAmy Zhang 		++rgb;
575fcd2f4bfSAmy Zhang 		++i;
576fcd2f4bfSAmy Zhang 	}
577fcd2f4bfSAmy Zhang 
578fcd2f4bfSAmy Zhang 	return true;
579fcd2f4bfSAmy Zhang }
580fcd2f4bfSAmy Zhang 
581fcd2f4bfSAmy Zhang static bool dce110_translate_regamma_to_hw_format(const struct dc_transfer_func
582fcd2f4bfSAmy Zhang 		*output_tf, struct pwl_params *regamma_params)
583fcd2f4bfSAmy Zhang {
58423ae4f8eSAmy Zhang 	struct curve_points *arr_points;
58523ae4f8eSAmy Zhang 	struct pwl_result_data *rgb_resulted;
58623ae4f8eSAmy Zhang 	struct pwl_result_data *rgb;
58723ae4f8eSAmy Zhang 	struct pwl_result_data *rgb_plus_1;
588fcd2f4bfSAmy Zhang 	struct fixed31_32 y_r;
589fcd2f4bfSAmy Zhang 	struct fixed31_32 y_g;
590fcd2f4bfSAmy Zhang 	struct fixed31_32 y_b;
591fcd2f4bfSAmy Zhang 	struct fixed31_32 y1_min;
592fcd2f4bfSAmy Zhang 	struct fixed31_32 y3_max;
593fcd2f4bfSAmy Zhang 
594fcd2f4bfSAmy Zhang 	int32_t segment_start, segment_end;
59523ae4f8eSAmy Zhang 	uint32_t i, j, k, seg_distr[16], increment, start_index, hw_points;
59623ae4f8eSAmy Zhang 
59723ae4f8eSAmy Zhang 	if (output_tf == NULL || regamma_params == NULL)
59823ae4f8eSAmy Zhang 		return false;
59923ae4f8eSAmy Zhang 
60023ae4f8eSAmy Zhang 	arr_points = regamma_params->arr_points;
60123ae4f8eSAmy Zhang 	rgb_resulted = regamma_params->rgb_resulted;
60223ae4f8eSAmy Zhang 	hw_points = 0;
603fcd2f4bfSAmy Zhang 
604fcd2f4bfSAmy Zhang 	memset(regamma_params, 0, sizeof(struct pwl_params));
605fcd2f4bfSAmy Zhang 
606fcd2f4bfSAmy Zhang 	if (output_tf->tf == TRANSFER_FUNCTION_PQ) {
607534db198SAmy Zhang 		/* 16 segments
608fcd2f4bfSAmy Zhang 		 * segments are from 2^-11 to 2^5
609fcd2f4bfSAmy Zhang 		 */
610fcd2f4bfSAmy Zhang 		segment_start = -11;
611fcd2f4bfSAmy Zhang 		segment_end = 5;
612fcd2f4bfSAmy Zhang 
613534db198SAmy Zhang 		seg_distr[0] = 2;
614534db198SAmy Zhang 		seg_distr[1] = 2;
615534db198SAmy Zhang 		seg_distr[2] = 2;
616534db198SAmy Zhang 		seg_distr[3] = 2;
617534db198SAmy Zhang 		seg_distr[4] = 2;
618534db198SAmy Zhang 		seg_distr[5] = 2;
619534db198SAmy Zhang 		seg_distr[6] = 3;
620534db198SAmy Zhang 		seg_distr[7] = 4;
621534db198SAmy Zhang 		seg_distr[8] = 4;
622534db198SAmy Zhang 		seg_distr[9] = 4;
623534db198SAmy Zhang 		seg_distr[10] = 4;
624534db198SAmy Zhang 		seg_distr[11] = 5;
625534db198SAmy Zhang 		seg_distr[12] = 5;
626534db198SAmy Zhang 		seg_distr[13] = 5;
627534db198SAmy Zhang 		seg_distr[14] = 5;
628534db198SAmy Zhang 		seg_distr[15] = 5;
629534db198SAmy Zhang 
630fcd2f4bfSAmy Zhang 	} else {
631534db198SAmy Zhang 		/* 10 segments
632fcd2f4bfSAmy Zhang 		 * segment is from 2^-10 to 2^0
633fcd2f4bfSAmy Zhang 		 */
634fcd2f4bfSAmy Zhang 		segment_start = -10;
635fcd2f4bfSAmy Zhang 		segment_end = 0;
636534db198SAmy Zhang 
637534db198SAmy Zhang 		seg_distr[0] = 3;
638534db198SAmy Zhang 		seg_distr[1] = 4;
639534db198SAmy Zhang 		seg_distr[2] = 4;
640534db198SAmy Zhang 		seg_distr[3] = 4;
641534db198SAmy Zhang 		seg_distr[4] = 4;
642534db198SAmy Zhang 		seg_distr[5] = 4;
643534db198SAmy Zhang 		seg_distr[6] = 4;
644534db198SAmy Zhang 		seg_distr[7] = 4;
645534db198SAmy Zhang 		seg_distr[8] = 5;
646534db198SAmy Zhang 		seg_distr[9] = 5;
647534db198SAmy Zhang 		seg_distr[10] = -1;
648534db198SAmy Zhang 		seg_distr[11] = -1;
649534db198SAmy Zhang 		seg_distr[12] = -1;
650534db198SAmy Zhang 		seg_distr[13] = -1;
651534db198SAmy Zhang 		seg_distr[14] = -1;
652534db198SAmy Zhang 		seg_distr[15] = -1;
653fcd2f4bfSAmy Zhang 	}
654fcd2f4bfSAmy Zhang 
655534db198SAmy Zhang 	for (k = 0; k < 16; k++) {
656534db198SAmy Zhang 		if (seg_distr[k] != -1)
657534db198SAmy Zhang 			hw_points += (1 << seg_distr[k]);
658534db198SAmy Zhang 	}
659534db198SAmy Zhang 
660fcd2f4bfSAmy Zhang 	j = 0;
661534db198SAmy Zhang 	for (k = 0; k < (segment_end - segment_start); k++) {
662534db198SAmy Zhang 		increment = 32 / (1 << seg_distr[k]);
663534db198SAmy Zhang 		start_index = (segment_start + k + 25) * 32;
664534db198SAmy Zhang 		for (i = start_index; i < start_index + 32; i += increment) {
665534db198SAmy Zhang 			if (j == hw_points - 1)
666fcd2f4bfSAmy Zhang 				break;
667fcd2f4bfSAmy Zhang 			rgb_resulted[j].red = output_tf->tf_pts.red[i];
668fcd2f4bfSAmy Zhang 			rgb_resulted[j].green = output_tf->tf_pts.green[i];
669fcd2f4bfSAmy Zhang 			rgb_resulted[j].blue = output_tf->tf_pts.blue[i];
670fcd2f4bfSAmy Zhang 			j++;
671fcd2f4bfSAmy Zhang 		}
672534db198SAmy Zhang 	}
673534db198SAmy Zhang 
674534db198SAmy Zhang 	/* last point */
675534db198SAmy Zhang 	start_index = (segment_end + 25) * 32;
676534db198SAmy Zhang 	rgb_resulted[hw_points - 1].red =
677534db198SAmy Zhang 			output_tf->tf_pts.red[start_index];
678534db198SAmy Zhang 	rgb_resulted[hw_points - 1].green =
679534db198SAmy Zhang 			output_tf->tf_pts.green[start_index];
680534db198SAmy Zhang 	rgb_resulted[hw_points - 1].blue =
681534db198SAmy Zhang 			output_tf->tf_pts.blue[start_index];
682fcd2f4bfSAmy Zhang 
683fcd2f4bfSAmy Zhang 	arr_points[0].x = dal_fixed31_32_pow(dal_fixed31_32_from_int(2),
684fcd2f4bfSAmy Zhang 			dal_fixed31_32_from_int(segment_start));
685fcd2f4bfSAmy Zhang 	arr_points[1].x = dal_fixed31_32_pow(dal_fixed31_32_from_int(2),
686fcd2f4bfSAmy Zhang 			dal_fixed31_32_from_int(segment_end));
687fcd2f4bfSAmy Zhang 	arr_points[2].x = dal_fixed31_32_pow(dal_fixed31_32_from_int(2),
688fcd2f4bfSAmy Zhang 			dal_fixed31_32_from_int(segment_end));
689fcd2f4bfSAmy Zhang 
690fcd2f4bfSAmy Zhang 	y_r = rgb_resulted[0].red;
691fcd2f4bfSAmy Zhang 	y_g = rgb_resulted[0].green;
692fcd2f4bfSAmy Zhang 	y_b = rgb_resulted[0].blue;
693fcd2f4bfSAmy Zhang 
694fcd2f4bfSAmy Zhang 	y1_min = dal_fixed31_32_min(y_r, dal_fixed31_32_min(y_g, y_b));
695fcd2f4bfSAmy Zhang 
696fcd2f4bfSAmy Zhang 	arr_points[0].y = y1_min;
697fcd2f4bfSAmy Zhang 	arr_points[0].slope = dal_fixed31_32_div(
698fcd2f4bfSAmy Zhang 					arr_points[0].y,
699fcd2f4bfSAmy Zhang 					arr_points[0].x);
700fcd2f4bfSAmy Zhang 
701fcd2f4bfSAmy Zhang 	y_r = rgb_resulted[hw_points - 1].red;
702fcd2f4bfSAmy Zhang 	y_g = rgb_resulted[hw_points - 1].green;
703fcd2f4bfSAmy Zhang 	y_b = rgb_resulted[hw_points - 1].blue;
704fcd2f4bfSAmy Zhang 
705fcd2f4bfSAmy Zhang 	/* see comment above, m_arrPoints[1].y should be the Y value for the
706fcd2f4bfSAmy Zhang 	 * region end (m_numOfHwPoints), not last HW point(m_numOfHwPoints - 1)
707fcd2f4bfSAmy Zhang 	 */
708fcd2f4bfSAmy Zhang 	y3_max = dal_fixed31_32_max(y_r, dal_fixed31_32_max(y_g, y_b));
709fcd2f4bfSAmy Zhang 
710fcd2f4bfSAmy Zhang 	arr_points[1].y = y3_max;
711fcd2f4bfSAmy Zhang 	arr_points[2].y = y3_max;
712fcd2f4bfSAmy Zhang 
713fcd2f4bfSAmy Zhang 	arr_points[1].slope = dal_fixed31_32_zero;
714fcd2f4bfSAmy Zhang 	arr_points[2].slope = dal_fixed31_32_zero;
715fcd2f4bfSAmy Zhang 
716fcd2f4bfSAmy Zhang 	if (output_tf->tf == TRANSFER_FUNCTION_PQ) {
717fcd2f4bfSAmy Zhang 		/* for PQ, we want to have a straight line from last HW X point,
718fcd2f4bfSAmy Zhang 		 * and the slope to be such that we hit 1.0 at 10000 nits.
719fcd2f4bfSAmy Zhang 		 */
720fcd2f4bfSAmy Zhang 		const struct fixed31_32 end_value =
721fcd2f4bfSAmy Zhang 				dal_fixed31_32_from_int(125);
722fcd2f4bfSAmy Zhang 
723fcd2f4bfSAmy Zhang 		arr_points[1].slope = dal_fixed31_32_div(
724fcd2f4bfSAmy Zhang 			dal_fixed31_32_sub(dal_fixed31_32_one, arr_points[1].y),
725fcd2f4bfSAmy Zhang 			dal_fixed31_32_sub(end_value, arr_points[1].x));
726fcd2f4bfSAmy Zhang 		arr_points[2].slope = dal_fixed31_32_div(
727fcd2f4bfSAmy Zhang 			dal_fixed31_32_sub(dal_fixed31_32_one, arr_points[1].y),
728fcd2f4bfSAmy Zhang 			dal_fixed31_32_sub(end_value, arr_points[1].x));
729fcd2f4bfSAmy Zhang 	}
730fcd2f4bfSAmy Zhang 
731fcd2f4bfSAmy Zhang 	regamma_params->hw_points_num = hw_points;
732fcd2f4bfSAmy Zhang 
733534db198SAmy Zhang 	i = 1;
734534db198SAmy Zhang 	for (k = 0; k < 16 && i < 16; k++) {
735534db198SAmy Zhang 		if (seg_distr[k] != -1) {
736534db198SAmy Zhang 			regamma_params->arr_curve_points[k].segments_num =
737534db198SAmy Zhang 					seg_distr[k];
738534db198SAmy Zhang 			regamma_params->arr_curve_points[i].offset =
739534db198SAmy Zhang 					regamma_params->arr_curve_points[k].
740534db198SAmy Zhang 					offset + (1 << seg_distr[k]);
741fcd2f4bfSAmy Zhang 		}
742534db198SAmy Zhang 		i++;
743534db198SAmy Zhang 	}
744534db198SAmy Zhang 
745534db198SAmy Zhang 	if (seg_distr[k] != -1)
746534db198SAmy Zhang 		regamma_params->arr_curve_points[k].segments_num =
747534db198SAmy Zhang 				seg_distr[k];
748fcd2f4bfSAmy Zhang 
74923ae4f8eSAmy Zhang 	rgb = rgb_resulted;
75023ae4f8eSAmy Zhang 	rgb_plus_1 = rgb_resulted + 1;
751fcd2f4bfSAmy Zhang 
752fcd2f4bfSAmy Zhang 	i = 1;
753fcd2f4bfSAmy Zhang 
754fcd2f4bfSAmy Zhang 	while (i != hw_points + 1) {
755fcd2f4bfSAmy Zhang 		if (dal_fixed31_32_lt(rgb_plus_1->red, rgb->red))
756fcd2f4bfSAmy Zhang 			rgb_plus_1->red = rgb->red;
757fcd2f4bfSAmy Zhang 		if (dal_fixed31_32_lt(rgb_plus_1->green, rgb->green))
758fcd2f4bfSAmy Zhang 			rgb_plus_1->green = rgb->green;
759fcd2f4bfSAmy Zhang 		if (dal_fixed31_32_lt(rgb_plus_1->blue, rgb->blue))
760fcd2f4bfSAmy Zhang 			rgb_plus_1->blue = rgb->blue;
761fcd2f4bfSAmy Zhang 
762fcd2f4bfSAmy Zhang 		rgb->delta_red = dal_fixed31_32_sub(
763fcd2f4bfSAmy Zhang 			rgb_plus_1->red,
764fcd2f4bfSAmy Zhang 			rgb->red);
765fcd2f4bfSAmy Zhang 		rgb->delta_green = dal_fixed31_32_sub(
766fcd2f4bfSAmy Zhang 			rgb_plus_1->green,
767fcd2f4bfSAmy Zhang 			rgb->green);
768fcd2f4bfSAmy Zhang 		rgb->delta_blue = dal_fixed31_32_sub(
769fcd2f4bfSAmy Zhang 			rgb_plus_1->blue,
770fcd2f4bfSAmy Zhang 			rgb->blue);
771fcd2f4bfSAmy Zhang 
772fcd2f4bfSAmy Zhang 		++rgb_plus_1;
773fcd2f4bfSAmy Zhang 		++rgb;
774fcd2f4bfSAmy Zhang 		++i;
775fcd2f4bfSAmy Zhang 	}
776fcd2f4bfSAmy Zhang 
777fcd2f4bfSAmy Zhang 	convert_to_custom_float(rgb_resulted, arr_points, hw_points);
778fcd2f4bfSAmy Zhang 
779fcd2f4bfSAmy Zhang 	return true;
780fcd2f4bfSAmy Zhang }
781fcd2f4bfSAmy Zhang 
78290e508baSAnthony Koo static bool dce110_set_output_transfer_func(
78390e508baSAnthony Koo 	struct pipe_ctx *pipe_ctx,
78490e508baSAnthony Koo 	const struct core_surface *surface, /* Surface - To be removed */
78590e508baSAnthony Koo 	const struct core_stream *stream)
78690e508baSAnthony Koo {
787fb735a9fSAnthony Koo 	struct output_pixel_processor *opp = pipe_ctx->opp;
7884562236bSHarry Wentland 
7894562236bSHarry Wentland 	opp->funcs->opp_power_on_regamma_lut(opp, true);
790cc0cb445SLeon Elazar 	opp->regamma_params->hw_points_num = GAMMA_HW_POINTS_NUM;
7914562236bSHarry Wentland 
792d7194cf6SAric Cyr 	if (stream->public.out_transfer_func &&
793fcd2f4bfSAmy Zhang 		stream->public.out_transfer_func->type ==
794fcd2f4bfSAmy Zhang 			TF_TYPE_PREDEFINED &&
795fcd2f4bfSAmy Zhang 		stream->public.out_transfer_func->tf ==
796fcd2f4bfSAmy Zhang 			TRANSFER_FUNCTION_SRGB) {
797d7194cf6SAric Cyr 		opp->funcs->opp_set_regamma_mode(opp, OPP_REGAMMA_SRGB);
798fcd2f4bfSAmy Zhang 	} else if (dce110_translate_regamma_to_hw_format(
799cc0cb445SLeon Elazar 				stream->public.out_transfer_func, opp->regamma_params)) {
800cc0cb445SLeon Elazar 			opp->funcs->opp_program_regamma_pwl(opp, opp->regamma_params);
8014562236bSHarry Wentland 			opp->funcs->opp_set_regamma_mode(opp, OPP_REGAMMA_USER);
8024562236bSHarry Wentland 	} else {
8034562236bSHarry Wentland 		opp->funcs->opp_set_regamma_mode(opp, OPP_REGAMMA_BYPASS);
8044562236bSHarry Wentland 	}
8054562236bSHarry Wentland 
8064562236bSHarry Wentland 	opp->funcs->opp_power_on_regamma_lut(opp, false);
8074562236bSHarry Wentland 
808cc0cb445SLeon Elazar 	return true;
8094562236bSHarry Wentland }
8104562236bSHarry Wentland 
8114562236bSHarry Wentland static enum dc_status bios_parser_crtc_source_select(
8124562236bSHarry Wentland 		struct pipe_ctx *pipe_ctx)
8134562236bSHarry Wentland {
8144562236bSHarry Wentland 	struct dc_bios *dcb;
8154562236bSHarry Wentland 	/* call VBIOS table to set CRTC source for the HW
8164562236bSHarry Wentland 	 * encoder block
8174562236bSHarry Wentland 	 * note: video bios clears all FMT setting here. */
8184562236bSHarry Wentland 	struct bp_crtc_source_select crtc_source_select = {0};
8194562236bSHarry Wentland 	const struct core_sink *sink = pipe_ctx->stream->sink;
8204562236bSHarry Wentland 
8214562236bSHarry Wentland 	crtc_source_select.engine_id = pipe_ctx->stream_enc->id;
8224562236bSHarry Wentland 	crtc_source_select.controller_id = pipe_ctx->pipe_idx + 1;
8234562236bSHarry Wentland 	/*TODO: Need to un-hardcode color depth, dp_audio and account for
8244562236bSHarry Wentland 	 * the case where signal and sink signal is different (translator
8254562236bSHarry Wentland 	 * encoder)*/
8264562236bSHarry Wentland 	crtc_source_select.signal = pipe_ctx->stream->signal;
8274562236bSHarry Wentland 	crtc_source_select.enable_dp_audio = false;
8284562236bSHarry Wentland 	crtc_source_select.sink_signal = pipe_ctx->stream->signal;
8294562236bSHarry Wentland 	crtc_source_select.display_output_bit_depth = PANEL_8BIT_COLOR;
8304562236bSHarry Wentland 
8314562236bSHarry Wentland 	dcb = sink->ctx->dc_bios;
8324562236bSHarry Wentland 
8334562236bSHarry Wentland 	if (BP_RESULT_OK != dcb->funcs->crtc_source_select(
8344562236bSHarry Wentland 		dcb,
8354562236bSHarry Wentland 		&crtc_source_select)) {
8364562236bSHarry Wentland 		return DC_ERROR_UNEXPECTED;
8374562236bSHarry Wentland 	}
8384562236bSHarry Wentland 
8394562236bSHarry Wentland 	return DC_OK;
8404562236bSHarry Wentland }
8414562236bSHarry Wentland 
8424562236bSHarry Wentland void dce110_update_info_frame(struct pipe_ctx *pipe_ctx)
8434562236bSHarry Wentland {
84486e2e1beSHersen Wu 	ASSERT(pipe_ctx->stream);
84586e2e1beSHersen Wu 
84686e2e1beSHersen Wu 	if (pipe_ctx->stream_enc == NULL)
84786e2e1beSHersen Wu 		return;  /* this is not root pipe */
84886e2e1beSHersen Wu 
8494562236bSHarry Wentland 	if (dc_is_hdmi_signal(pipe_ctx->stream->signal))
8504562236bSHarry Wentland 		pipe_ctx->stream_enc->funcs->update_hdmi_info_packets(
8514562236bSHarry Wentland 			pipe_ctx->stream_enc,
8524562236bSHarry Wentland 			&pipe_ctx->encoder_info_frame);
8534562236bSHarry Wentland 	else if (dc_is_dp_signal(pipe_ctx->stream->signal))
8544562236bSHarry Wentland 		pipe_ctx->stream_enc->funcs->update_dp_info_packets(
8554562236bSHarry Wentland 			pipe_ctx->stream_enc,
8564562236bSHarry Wentland 			&pipe_ctx->encoder_info_frame);
8574562236bSHarry Wentland }
8584562236bSHarry Wentland 
8594562236bSHarry Wentland void dce110_enable_stream(struct pipe_ctx *pipe_ctx)
8604562236bSHarry Wentland {
8614562236bSHarry Wentland 	enum dc_lane_count lane_count =
8624562236bSHarry Wentland 		pipe_ctx->stream->sink->link->public.cur_link_settings.lane_count;
8634562236bSHarry Wentland 
8644562236bSHarry Wentland 	struct dc_crtc_timing *timing = &pipe_ctx->stream->public.timing;
8654562236bSHarry Wentland 	struct core_link *link = pipe_ctx->stream->sink->link;
8664562236bSHarry Wentland 
8674562236bSHarry Wentland 	/* 1. update AVI info frame (HDMI, DP)
8684562236bSHarry Wentland 	 * we always need to update info frame
8694562236bSHarry Wentland 	*/
8704562236bSHarry Wentland 	uint32_t active_total_with_borders;
8714562236bSHarry Wentland 	uint32_t early_control = 0;
8724562236bSHarry Wentland 	struct timing_generator *tg = pipe_ctx->tg;
8734562236bSHarry Wentland 
8744562236bSHarry Wentland 	/* TODOFPGA may change to hwss.update_info_frame */
8754562236bSHarry Wentland 	dce110_update_info_frame(pipe_ctx);
8764562236bSHarry Wentland 	/* enable early control to avoid corruption on DP monitor*/
8774562236bSHarry Wentland 	active_total_with_borders =
8784562236bSHarry Wentland 			timing->h_addressable
8794562236bSHarry Wentland 				+ timing->h_border_left
8804562236bSHarry Wentland 				+ timing->h_border_right;
8814562236bSHarry Wentland 
8824562236bSHarry Wentland 	if (lane_count != 0)
8834562236bSHarry Wentland 		early_control = active_total_with_borders % lane_count;
8844562236bSHarry Wentland 
8854562236bSHarry Wentland 	if (early_control == 0)
8864562236bSHarry Wentland 		early_control = lane_count;
8874562236bSHarry Wentland 
8884562236bSHarry Wentland 	tg->funcs->set_early_control(tg, early_control);
8894562236bSHarry Wentland 
8904562236bSHarry Wentland 	/* enable audio only within mode set */
8914562236bSHarry Wentland 	if (pipe_ctx->audio != NULL) {
8924562236bSHarry Wentland 		if (dc_is_dp_signal(pipe_ctx->stream->signal))
8934562236bSHarry Wentland 			pipe_ctx->stream_enc->funcs->dp_audio_enable(pipe_ctx->stream_enc);
8944562236bSHarry Wentland 	}
8954562236bSHarry Wentland 
8964562236bSHarry Wentland 	/* For MST, there are multiply stream go to only one link.
8974562236bSHarry Wentland 	 * connect DIG back_end to front_end while enable_stream and
8984562236bSHarry Wentland 	 * disconnect them during disable_stream
8994562236bSHarry Wentland 	 * BY this, it is logic clean to separate stream and link */
9004562236bSHarry Wentland 	 link->link_enc->funcs->connect_dig_be_to_fe(link->link_enc,
9014562236bSHarry Wentland 			pipe_ctx->stream_enc->id, true);
9024562236bSHarry Wentland 
9034562236bSHarry Wentland }
9044562236bSHarry Wentland 
9054562236bSHarry Wentland void dce110_disable_stream(struct pipe_ctx *pipe_ctx)
9064562236bSHarry Wentland {
9074562236bSHarry Wentland 	struct core_stream *stream = pipe_ctx->stream;
9084562236bSHarry Wentland 	struct core_link *link = stream->sink->link;
9094562236bSHarry Wentland 
9104562236bSHarry Wentland 	if (pipe_ctx->audio) {
9114562236bSHarry Wentland 		pipe_ctx->audio->funcs->az_disable(pipe_ctx->audio);
9124562236bSHarry Wentland 
9134562236bSHarry Wentland 		if (dc_is_dp_signal(pipe_ctx->stream->signal))
9144562236bSHarry Wentland 			pipe_ctx->stream_enc->funcs->dp_audio_disable(
9154562236bSHarry Wentland 					pipe_ctx->stream_enc);
9164562236bSHarry Wentland 		else
9174562236bSHarry Wentland 			pipe_ctx->stream_enc->funcs->hdmi_audio_disable(
9184562236bSHarry Wentland 					pipe_ctx->stream_enc);
9194562236bSHarry Wentland 
9204562236bSHarry Wentland 		pipe_ctx->audio = NULL;
9214562236bSHarry Wentland 
9224562236bSHarry Wentland 		/* TODO: notify audio driver for if audio modes list changed
9234562236bSHarry Wentland 		 * add audio mode list change flag */
9244562236bSHarry Wentland 		/* dal_audio_disable_azalia_audio_jack_presence(stream->audio,
9254562236bSHarry Wentland 		 * stream->stream_engine_id);
9264562236bSHarry Wentland 		 */
9274562236bSHarry Wentland 	}
9284562236bSHarry Wentland 
9294562236bSHarry Wentland 	if (dc_is_hdmi_signal(pipe_ctx->stream->signal))
9304562236bSHarry Wentland 		pipe_ctx->stream_enc->funcs->stop_hdmi_info_packets(
9314562236bSHarry Wentland 			pipe_ctx->stream_enc);
9324562236bSHarry Wentland 
9334562236bSHarry Wentland 	if (dc_is_dp_signal(pipe_ctx->stream->signal))
9344562236bSHarry Wentland 		pipe_ctx->stream_enc->funcs->stop_dp_info_packets(
9354562236bSHarry Wentland 			pipe_ctx->stream_enc);
9364562236bSHarry Wentland 
9374562236bSHarry Wentland 	pipe_ctx->stream_enc->funcs->audio_mute_control(
9384562236bSHarry Wentland 			pipe_ctx->stream_enc, true);
9394562236bSHarry Wentland 
9404562236bSHarry Wentland 
9414562236bSHarry Wentland 	/* blank at encoder level */
9424562236bSHarry Wentland 	if (dc_is_dp_signal(pipe_ctx->stream->signal))
9434562236bSHarry Wentland 		pipe_ctx->stream_enc->funcs->dp_blank(pipe_ctx->stream_enc);
9444562236bSHarry Wentland 
9454562236bSHarry Wentland 	link->link_enc->funcs->connect_dig_be_to_fe(
9464562236bSHarry Wentland 			link->link_enc,
9474562236bSHarry Wentland 			pipe_ctx->stream_enc->id,
9484562236bSHarry Wentland 			false);
9494562236bSHarry Wentland 
9504562236bSHarry Wentland }
9514562236bSHarry Wentland 
9524562236bSHarry Wentland void dce110_unblank_stream(struct pipe_ctx *pipe_ctx,
9534562236bSHarry Wentland 		struct dc_link_settings *link_settings)
9544562236bSHarry Wentland {
9554562236bSHarry Wentland 	struct encoder_unblank_param params = { { 0 } };
9564562236bSHarry Wentland 
9574562236bSHarry Wentland 	/* only 3 items below are used by unblank */
9586235b23cSTony Cheng 	params.pixel_clk_khz =
9594562236bSHarry Wentland 		pipe_ctx->stream->public.timing.pix_clk_khz;
9604562236bSHarry Wentland 	params.link_settings.link_rate = link_settings->link_rate;
9614562236bSHarry Wentland 	pipe_ctx->stream_enc->funcs->dp_unblank(pipe_ctx->stream_enc, &params);
9624562236bSHarry Wentland }
9634562236bSHarry Wentland 
9644562236bSHarry Wentland static enum audio_dto_source translate_to_dto_source(enum controller_id crtc_id)
9654562236bSHarry Wentland {
9664562236bSHarry Wentland 	switch (crtc_id) {
9674562236bSHarry Wentland 	case CONTROLLER_ID_D0:
9684562236bSHarry Wentland 		return DTO_SOURCE_ID0;
9694562236bSHarry Wentland 	case CONTROLLER_ID_D1:
9704562236bSHarry Wentland 		return DTO_SOURCE_ID1;
9714562236bSHarry Wentland 	case CONTROLLER_ID_D2:
9724562236bSHarry Wentland 		return DTO_SOURCE_ID2;
9734562236bSHarry Wentland 	case CONTROLLER_ID_D3:
9744562236bSHarry Wentland 		return DTO_SOURCE_ID3;
9754562236bSHarry Wentland 	case CONTROLLER_ID_D4:
9764562236bSHarry Wentland 		return DTO_SOURCE_ID4;
9774562236bSHarry Wentland 	case CONTROLLER_ID_D5:
9784562236bSHarry Wentland 		return DTO_SOURCE_ID5;
9794562236bSHarry Wentland 	default:
9804562236bSHarry Wentland 		return DTO_SOURCE_UNKNOWN;
9814562236bSHarry Wentland 	}
9824562236bSHarry Wentland }
9834562236bSHarry Wentland 
9844562236bSHarry Wentland static void build_audio_output(
9854562236bSHarry Wentland 	const struct pipe_ctx *pipe_ctx,
9864562236bSHarry Wentland 	struct audio_output *audio_output)
9874562236bSHarry Wentland {
9884562236bSHarry Wentland 	const struct core_stream *stream = pipe_ctx->stream;
9894562236bSHarry Wentland 	audio_output->engine_id = pipe_ctx->stream_enc->id;
9904562236bSHarry Wentland 
9914562236bSHarry Wentland 	audio_output->signal = pipe_ctx->stream->signal;
9924562236bSHarry Wentland 
9934562236bSHarry Wentland 	/* audio_crtc_info  */
9944562236bSHarry Wentland 
9954562236bSHarry Wentland 	audio_output->crtc_info.h_total =
9964562236bSHarry Wentland 		stream->public.timing.h_total;
9974562236bSHarry Wentland 
9984562236bSHarry Wentland 	/*
9994562236bSHarry Wentland 	 * Audio packets are sent during actual CRTC blank physical signal, we
10004562236bSHarry Wentland 	 * need to specify actual active signal portion
10014562236bSHarry Wentland 	 */
10024562236bSHarry Wentland 	audio_output->crtc_info.h_active =
10034562236bSHarry Wentland 			stream->public.timing.h_addressable
10044562236bSHarry Wentland 			+ stream->public.timing.h_border_left
10054562236bSHarry Wentland 			+ stream->public.timing.h_border_right;
10064562236bSHarry Wentland 
10074562236bSHarry Wentland 	audio_output->crtc_info.v_active =
10084562236bSHarry Wentland 			stream->public.timing.v_addressable
10094562236bSHarry Wentland 			+ stream->public.timing.v_border_top
10104562236bSHarry Wentland 			+ stream->public.timing.v_border_bottom;
10114562236bSHarry Wentland 
10124562236bSHarry Wentland 	audio_output->crtc_info.pixel_repetition = 1;
10134562236bSHarry Wentland 
10144562236bSHarry Wentland 	audio_output->crtc_info.interlaced =
10154562236bSHarry Wentland 			stream->public.timing.flags.INTERLACE;
10164562236bSHarry Wentland 
10174562236bSHarry Wentland 	audio_output->crtc_info.refresh_rate =
10184562236bSHarry Wentland 		(stream->public.timing.pix_clk_khz*1000)/
10194562236bSHarry Wentland 		(stream->public.timing.h_total*stream->public.timing.v_total);
10204562236bSHarry Wentland 
10214562236bSHarry Wentland 	audio_output->crtc_info.color_depth =
10224562236bSHarry Wentland 		stream->public.timing.display_color_depth;
10234562236bSHarry Wentland 
10244562236bSHarry Wentland 	audio_output->crtc_info.requested_pixel_clock =
10254562236bSHarry Wentland 			pipe_ctx->pix_clk_params.requested_pix_clk;
10264562236bSHarry Wentland 
10274562236bSHarry Wentland 	/*
10284562236bSHarry Wentland 	 * TODO - Investigate why calculated pixel clk has to be
10294562236bSHarry Wentland 	 * requested pixel clk
10304562236bSHarry Wentland 	 */
10314562236bSHarry Wentland 	audio_output->crtc_info.calculated_pixel_clock =
10324562236bSHarry Wentland 			pipe_ctx->pix_clk_params.requested_pix_clk;
10334562236bSHarry Wentland 
10344562236bSHarry Wentland 	if (pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT ||
10354562236bSHarry Wentland 			pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST) {
10364562236bSHarry Wentland 		audio_output->pll_info.dp_dto_source_clock_in_khz =
10371a687574SDmytro Laktyushkin 				pipe_ctx->dis_clk->funcs->get_dp_ref_clk_frequency(
10384562236bSHarry Wentland 						pipe_ctx->dis_clk);
10394562236bSHarry Wentland 	}
10404562236bSHarry Wentland 
10414562236bSHarry Wentland 	audio_output->pll_info.feed_back_divider =
10424562236bSHarry Wentland 			pipe_ctx->pll_settings.feedback_divider;
10434562236bSHarry Wentland 
10444562236bSHarry Wentland 	audio_output->pll_info.dto_source =
10454562236bSHarry Wentland 		translate_to_dto_source(
10464562236bSHarry Wentland 			pipe_ctx->pipe_idx + 1);
10474562236bSHarry Wentland 
10484562236bSHarry Wentland 	/* TODO hard code to enable for now. Need get from stream */
10494562236bSHarry Wentland 	audio_output->pll_info.ss_enabled = true;
10504562236bSHarry Wentland 
10514562236bSHarry Wentland 	audio_output->pll_info.ss_percentage =
10524562236bSHarry Wentland 			pipe_ctx->pll_settings.ss_percentage;
10534562236bSHarry Wentland }
10544562236bSHarry Wentland 
10554562236bSHarry Wentland static void get_surface_visual_confirm_color(const struct pipe_ctx *pipe_ctx,
10564562236bSHarry Wentland 		struct tg_color *color)
10574562236bSHarry Wentland {
10584562236bSHarry Wentland 	uint32_t color_value = MAX_TG_COLOR_VALUE * (4 - pipe_ctx->pipe_idx) / 4;
10594562236bSHarry Wentland 
10604562236bSHarry Wentland 	switch (pipe_ctx->scl_data.format) {
10614562236bSHarry Wentland 	case PIXEL_FORMAT_ARGB8888:
10624562236bSHarry Wentland 		/* set boarder color to red */
10634562236bSHarry Wentland 		color->color_r_cr = color_value;
10644562236bSHarry Wentland 		break;
10654562236bSHarry Wentland 
10664562236bSHarry Wentland 	case PIXEL_FORMAT_ARGB2101010:
10674562236bSHarry Wentland 		/* set boarder color to blue */
10684562236bSHarry Wentland 		color->color_b_cb = color_value;
10694562236bSHarry Wentland 		break;
10704562236bSHarry Wentland 	case PIXEL_FORMAT_420BPP12:
10714562236bSHarry Wentland 		/* set boarder color to green */
10724562236bSHarry Wentland 		color->color_g_y = color_value;
10734562236bSHarry Wentland 		break;
10744562236bSHarry Wentland 	case PIXEL_FORMAT_FP16:
10754562236bSHarry Wentland 		/* set boarder color to white */
10764562236bSHarry Wentland 		color->color_r_cr = color_value;
10774562236bSHarry Wentland 		color->color_b_cb = color_value;
10784562236bSHarry Wentland 		color->color_g_y = color_value;
10794562236bSHarry Wentland 		break;
10804562236bSHarry Wentland 	default:
10814562236bSHarry Wentland 		break;
10824562236bSHarry Wentland 	}
10834562236bSHarry Wentland }
10844562236bSHarry Wentland 
10854562236bSHarry Wentland static void program_scaler(const struct core_dc *dc,
10864562236bSHarry Wentland 		const struct pipe_ctx *pipe_ctx)
10874562236bSHarry Wentland {
10884562236bSHarry Wentland 	struct tg_color color = {0};
10894562236bSHarry Wentland 
10904562236bSHarry Wentland 	if (dc->public.debug.surface_visual_confirm)
10914562236bSHarry Wentland 		get_surface_visual_confirm_color(pipe_ctx, &color);
10924562236bSHarry Wentland 	else
10934562236bSHarry Wentland 		color_space_to_black_color(dc,
10944562236bSHarry Wentland 				pipe_ctx->stream->public.output_color_space,
10954562236bSHarry Wentland 				&color);
10964562236bSHarry Wentland 
10974562236bSHarry Wentland 	pipe_ctx->xfm->funcs->transform_set_pixel_storage_depth(
10984562236bSHarry Wentland 		pipe_ctx->xfm,
10994562236bSHarry Wentland 		pipe_ctx->scl_data.lb_params.depth,
11004562236bSHarry Wentland 		&pipe_ctx->stream->bit_depth_params);
11014562236bSHarry Wentland 
11024562236bSHarry Wentland 	if (pipe_ctx->tg->funcs->set_overscan_blank_color)
11034562236bSHarry Wentland 		pipe_ctx->tg->funcs->set_overscan_blank_color(
11044562236bSHarry Wentland 				pipe_ctx->tg,
11054562236bSHarry Wentland 				&color);
11064562236bSHarry Wentland 
11074562236bSHarry Wentland 	pipe_ctx->xfm->funcs->transform_set_scaler(pipe_ctx->xfm,
11084562236bSHarry Wentland 		&pipe_ctx->scl_data);
11094562236bSHarry Wentland }
11104562236bSHarry Wentland 
11114b5e7d62SHersen Wu static enum dc_status dce110_prog_pixclk_crtc_otg(
11124562236bSHarry Wentland 		struct pipe_ctx *pipe_ctx,
11134562236bSHarry Wentland 		struct validate_context *context,
11144562236bSHarry Wentland 		struct core_dc *dc)
11154562236bSHarry Wentland {
11164562236bSHarry Wentland 	struct core_stream *stream = pipe_ctx->stream;
11174562236bSHarry Wentland 	struct pipe_ctx *pipe_ctx_old = &dc->current_context->res_ctx.
11184562236bSHarry Wentland 			pipe_ctx[pipe_ctx->pipe_idx];
11194562236bSHarry Wentland 	struct tg_color black_color = {0};
11204562236bSHarry Wentland 
11214562236bSHarry Wentland 	if (!pipe_ctx_old->stream) {
11224562236bSHarry Wentland 
11234562236bSHarry Wentland 		/* program blank color */
11244562236bSHarry Wentland 		color_space_to_black_color(dc,
11254562236bSHarry Wentland 				stream->public.output_color_space, &black_color);
11264562236bSHarry Wentland 		pipe_ctx->tg->funcs->set_blank_color(
11274562236bSHarry Wentland 				pipe_ctx->tg,
11284562236bSHarry Wentland 				&black_color);
11294b5e7d62SHersen Wu 
11304562236bSHarry Wentland 		/*
11314562236bSHarry Wentland 		 * Must blank CRTC after disabling power gating and before any
11324562236bSHarry Wentland 		 * programming, otherwise CRTC will be hung in bad state
11334562236bSHarry Wentland 		 */
11344562236bSHarry Wentland 		pipe_ctx->tg->funcs->set_blank(pipe_ctx->tg, true);
11354562236bSHarry Wentland 
11364562236bSHarry Wentland 		if (false == pipe_ctx->clock_source->funcs->program_pix_clk(
11374562236bSHarry Wentland 				pipe_ctx->clock_source,
11384562236bSHarry Wentland 				&pipe_ctx->pix_clk_params,
11394562236bSHarry Wentland 				&pipe_ctx->pll_settings)) {
11404562236bSHarry Wentland 			BREAK_TO_DEBUGGER();
11414562236bSHarry Wentland 			return DC_ERROR_UNEXPECTED;
11424562236bSHarry Wentland 		}
11434562236bSHarry Wentland 
11444562236bSHarry Wentland 		pipe_ctx->tg->funcs->program_timing(
11454562236bSHarry Wentland 				pipe_ctx->tg,
11464562236bSHarry Wentland 				&stream->public.timing,
11474562236bSHarry Wentland 				true);
11484562236bSHarry Wentland 	}
11494562236bSHarry Wentland 
11504562236bSHarry Wentland 	if (!pipe_ctx_old->stream) {
11514562236bSHarry Wentland 		if (false == pipe_ctx->tg->funcs->enable_crtc(
11524562236bSHarry Wentland 				pipe_ctx->tg)) {
11534562236bSHarry Wentland 			BREAK_TO_DEBUGGER();
11544562236bSHarry Wentland 			return DC_ERROR_UNEXPECTED;
11554562236bSHarry Wentland 		}
11564562236bSHarry Wentland 	}
11574562236bSHarry Wentland 
11584562236bSHarry Wentland 	return DC_OK;
11594562236bSHarry Wentland }
11604562236bSHarry Wentland 
11614562236bSHarry Wentland static enum dc_status apply_single_controller_ctx_to_hw(
11624562236bSHarry Wentland 		struct pipe_ctx *pipe_ctx,
11634562236bSHarry Wentland 		struct validate_context *context,
11644562236bSHarry Wentland 		struct core_dc *dc)
11654562236bSHarry Wentland {
11664562236bSHarry Wentland 	struct core_stream *stream = pipe_ctx->stream;
11674562236bSHarry Wentland 	struct pipe_ctx *pipe_ctx_old = &dc->current_context->res_ctx.
11684562236bSHarry Wentland 			pipe_ctx[pipe_ctx->pipe_idx];
11694562236bSHarry Wentland 
11704562236bSHarry Wentland 	/*  */
11714562236bSHarry Wentland 	dc->hwss.prog_pixclk_crtc_otg(pipe_ctx, context, dc);
11724562236bSHarry Wentland 
11734562236bSHarry Wentland 	pipe_ctx->opp->funcs->opp_set_dyn_expansion(
11744562236bSHarry Wentland 			pipe_ctx->opp,
11754562236bSHarry Wentland 			COLOR_SPACE_YCBCR601,
11764562236bSHarry Wentland 			stream->public.timing.display_color_depth,
11774562236bSHarry Wentland 			pipe_ctx->stream->signal);
11784562236bSHarry Wentland 
11794562236bSHarry Wentland 	pipe_ctx->opp->funcs->opp_program_fmt(
11804562236bSHarry Wentland 			pipe_ctx->opp,
11814562236bSHarry Wentland 			&stream->bit_depth_params,
11824562236bSHarry Wentland 			&stream->clamping);
11834562236bSHarry Wentland 
11844562236bSHarry Wentland 	/* FPGA does not program backend */
11854562236bSHarry Wentland 	if (IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment))
11864562236bSHarry Wentland 		return DC_OK;
11874562236bSHarry Wentland 
11884562236bSHarry Wentland 	/* TODO: move to stream encoder */
11894562236bSHarry Wentland 	if (pipe_ctx->stream->signal != SIGNAL_TYPE_VIRTUAL)
11904562236bSHarry Wentland 		if (DC_OK != bios_parser_crtc_source_select(pipe_ctx)) {
11914562236bSHarry Wentland 			BREAK_TO_DEBUGGER();
11924562236bSHarry Wentland 			return DC_ERROR_UNEXPECTED;
11934562236bSHarry Wentland 		}
11944562236bSHarry Wentland 
11954562236bSHarry Wentland 	if (pipe_ctx->stream->signal != SIGNAL_TYPE_VIRTUAL)
11964562236bSHarry Wentland 		stream->sink->link->link_enc->funcs->setup(
11974562236bSHarry Wentland 			stream->sink->link->link_enc,
11984562236bSHarry Wentland 			pipe_ctx->stream->signal);
11994562236bSHarry Wentland 
12004562236bSHarry Wentland 	if (dc_is_dp_signal(pipe_ctx->stream->signal))
12014562236bSHarry Wentland 		pipe_ctx->stream_enc->funcs->dp_set_stream_attribute(
12024562236bSHarry Wentland 			pipe_ctx->stream_enc,
12034562236bSHarry Wentland 			&stream->public.timing,
12044562236bSHarry Wentland 			stream->public.output_color_space);
12054562236bSHarry Wentland 
12064562236bSHarry Wentland 	if (dc_is_hdmi_signal(pipe_ctx->stream->signal))
12074562236bSHarry Wentland 		pipe_ctx->stream_enc->funcs->hdmi_set_stream_attribute(
12084562236bSHarry Wentland 			pipe_ctx->stream_enc,
12094562236bSHarry Wentland 			&stream->public.timing,
12104562236bSHarry Wentland 			stream->phy_pix_clk,
12114562236bSHarry Wentland 			pipe_ctx->audio != NULL);
12124562236bSHarry Wentland 
12134562236bSHarry Wentland 	if (dc_is_dvi_signal(pipe_ctx->stream->signal))
12144562236bSHarry Wentland 		pipe_ctx->stream_enc->funcs->dvi_set_stream_attribute(
12154562236bSHarry Wentland 			pipe_ctx->stream_enc,
12164562236bSHarry Wentland 			&stream->public.timing,
12174562236bSHarry Wentland 			(pipe_ctx->stream->signal == SIGNAL_TYPE_DVI_DUAL_LINK) ?
12184562236bSHarry Wentland 			true : false);
12194562236bSHarry Wentland 
12204562236bSHarry Wentland 	if (!pipe_ctx_old->stream) {
12214562236bSHarry Wentland 		core_link_enable_stream(pipe_ctx);
12224562236bSHarry Wentland 
12234562236bSHarry Wentland 		if (dc_is_dp_signal(pipe_ctx->stream->signal))
12244562236bSHarry Wentland 			dce110_unblank_stream(pipe_ctx,
12254562236bSHarry Wentland 				&stream->sink->link->public.cur_link_settings);
12264562236bSHarry Wentland 	}
12274562236bSHarry Wentland 
12284562236bSHarry Wentland 	pipe_ctx->scl_data.lb_params.alpha_en = pipe_ctx->bottom_pipe != 0;
12294562236bSHarry Wentland 	/* program_scaler and allocate_mem_input are not new asic */
12304562236bSHarry Wentland 	if (!pipe_ctx_old || memcmp(&pipe_ctx_old->scl_data,
12314562236bSHarry Wentland 				&pipe_ctx->scl_data,
12324562236bSHarry Wentland 				sizeof(struct scaler_data)) != 0)
12334562236bSHarry Wentland 		program_scaler(dc, pipe_ctx);
12344562236bSHarry Wentland 
12354562236bSHarry Wentland 	/* mst support - use total stream count */
12364562236bSHarry Wentland 		pipe_ctx->mi->funcs->allocate_mem_input(
12374562236bSHarry Wentland 					pipe_ctx->mi,
12384562236bSHarry Wentland 					stream->public.timing.h_total,
12394562236bSHarry Wentland 					stream->public.timing.v_total,
12404562236bSHarry Wentland 					stream->public.timing.pix_clk_khz,
1241ab2541b6SAric Cyr 					context->stream_count);
12424562236bSHarry Wentland 
12434562236bSHarry Wentland 	return DC_OK;
12444562236bSHarry Wentland }
12454562236bSHarry Wentland 
12464562236bSHarry Wentland /******************************************************************************/
12474562236bSHarry Wentland 
12484562236bSHarry Wentland static void power_down_encoders(struct core_dc *dc)
12494562236bSHarry Wentland {
12504562236bSHarry Wentland 	int i;
12514562236bSHarry Wentland 
12524562236bSHarry Wentland 	for (i = 0; i < dc->link_count; i++) {
12534562236bSHarry Wentland 		dc->links[i]->link_enc->funcs->disable_output(
12544562236bSHarry Wentland 				dc->links[i]->link_enc, SIGNAL_TYPE_NONE);
12554562236bSHarry Wentland 	}
12564562236bSHarry Wentland }
12574562236bSHarry Wentland 
12584562236bSHarry Wentland static void power_down_controllers(struct core_dc *dc)
12594562236bSHarry Wentland {
12604562236bSHarry Wentland 	int i;
12614562236bSHarry Wentland 
12624562236bSHarry Wentland 	for (i = 0; i < dc->res_pool->pipe_count; i++) {
12634562236bSHarry Wentland 		dc->res_pool->timing_generators[i]->funcs->disable_crtc(
12644562236bSHarry Wentland 				dc->res_pool->timing_generators[i]);
12654562236bSHarry Wentland 	}
12664562236bSHarry Wentland }
12674562236bSHarry Wentland 
12684562236bSHarry Wentland static void power_down_clock_sources(struct core_dc *dc)
12694562236bSHarry Wentland {
12704562236bSHarry Wentland 	int i;
12714562236bSHarry Wentland 
12724562236bSHarry Wentland 	if (dc->res_pool->dp_clock_source->funcs->cs_power_down(
12734562236bSHarry Wentland 		dc->res_pool->dp_clock_source) == false)
12744562236bSHarry Wentland 		dm_error("Failed to power down pll! (dp clk src)\n");
12754562236bSHarry Wentland 
12764562236bSHarry Wentland 	for (i = 0; i < dc->res_pool->clk_src_count; i++) {
12774562236bSHarry Wentland 		if (dc->res_pool->clock_sources[i]->funcs->cs_power_down(
12784562236bSHarry Wentland 				dc->res_pool->clock_sources[i]) == false)
12794562236bSHarry Wentland 			dm_error("Failed to power down pll! (clk src index=%d)\n", i);
12804562236bSHarry Wentland 	}
12814562236bSHarry Wentland }
12824562236bSHarry Wentland 
12834562236bSHarry Wentland static void power_down_all_hw_blocks(struct core_dc *dc)
12844562236bSHarry Wentland {
12854562236bSHarry Wentland 	power_down_encoders(dc);
12864562236bSHarry Wentland 
12874562236bSHarry Wentland 	power_down_controllers(dc);
12884562236bSHarry Wentland 
12894562236bSHarry Wentland 	power_down_clock_sources(dc);
12904562236bSHarry Wentland }
12914562236bSHarry Wentland 
12924562236bSHarry Wentland static void disable_vga_and_power_gate_all_controllers(
12934562236bSHarry Wentland 		struct core_dc *dc)
12944562236bSHarry Wentland {
12954562236bSHarry Wentland 	int i;
12964562236bSHarry Wentland 	struct timing_generator *tg;
12974562236bSHarry Wentland 	struct dc_context *ctx = dc->ctx;
12984562236bSHarry Wentland 
12994562236bSHarry Wentland 	for (i = 0; i < dc->res_pool->pipe_count; i++) {
13004562236bSHarry Wentland 		tg = dc->res_pool->timing_generators[i];
13014562236bSHarry Wentland 
13024562236bSHarry Wentland 		tg->funcs->disable_vga(tg);
13034562236bSHarry Wentland 
13044562236bSHarry Wentland 		/* Enable CLOCK gating for each pipe BEFORE controller
13054562236bSHarry Wentland 		 * powergating. */
13064562236bSHarry Wentland 		enable_display_pipe_clock_gating(ctx,
13074562236bSHarry Wentland 				true);
13084562236bSHarry Wentland 
13094562236bSHarry Wentland 		dc->hwss.power_down_front_end(
13104562236bSHarry Wentland 			dc, &dc->current_context->res_ctx.pipe_ctx[i]);
13114562236bSHarry Wentland 	}
13124562236bSHarry Wentland }
13134562236bSHarry Wentland 
13144562236bSHarry Wentland /**
13154562236bSHarry Wentland  * When ASIC goes from VBIOS/VGA mode to driver/accelerated mode we need:
13164562236bSHarry Wentland  *  1. Power down all DC HW blocks
13174562236bSHarry Wentland  *  2. Disable VGA engine on all controllers
13184562236bSHarry Wentland  *  3. Enable power gating for controller
13194562236bSHarry Wentland  *  4. Set acc_mode_change bit (VBIOS will clear this bit when going to FSDOS)
13204562236bSHarry Wentland  */
13214562236bSHarry Wentland void dce110_enable_accelerated_mode(struct core_dc *dc)
13224562236bSHarry Wentland {
13234562236bSHarry Wentland 	power_down_all_hw_blocks(dc);
13244562236bSHarry Wentland 
13254562236bSHarry Wentland 	disable_vga_and_power_gate_all_controllers(dc);
13264562236bSHarry Wentland 	bios_set_scratch_acc_mode_change(dc->ctx->dc_bios);
13274562236bSHarry Wentland }
13284562236bSHarry Wentland 
13294562236bSHarry Wentland static uint32_t compute_pstate_blackout_duration(
13304562236bSHarry Wentland 	struct bw_fixed blackout_duration,
13314562236bSHarry Wentland 	const struct core_stream *stream)
13324562236bSHarry Wentland {
13334562236bSHarry Wentland 	uint32_t total_dest_line_time_ns;
13344562236bSHarry Wentland 	uint32_t pstate_blackout_duration_ns;
13354562236bSHarry Wentland 
13364562236bSHarry Wentland 	pstate_blackout_duration_ns = 1000 * blackout_duration.value >> 24;
13374562236bSHarry Wentland 
13384562236bSHarry Wentland 	total_dest_line_time_ns = 1000000UL *
13394562236bSHarry Wentland 		stream->public.timing.h_total /
13404562236bSHarry Wentland 		stream->public.timing.pix_clk_khz +
13414562236bSHarry Wentland 		pstate_blackout_duration_ns;
13424562236bSHarry Wentland 
13434562236bSHarry Wentland 	return total_dest_line_time_ns;
13444562236bSHarry Wentland }
13454562236bSHarry Wentland 
13464562236bSHarry Wentland /* get the index of the pipe_ctx if there were no gaps in the pipe_ctx array*/
13474562236bSHarry Wentland int get_bw_result_idx(
13484562236bSHarry Wentland 		struct resource_context *res_ctx,
13494562236bSHarry Wentland 		int pipe_idx)
13504562236bSHarry Wentland {
13514562236bSHarry Wentland 	int i, collapsed_idx;
13524562236bSHarry Wentland 
13534562236bSHarry Wentland 	if (res_ctx->pipe_ctx[pipe_idx].top_pipe)
13544562236bSHarry Wentland 		return 3;
13554562236bSHarry Wentland 
13564562236bSHarry Wentland 	collapsed_idx = 0;
13574562236bSHarry Wentland 	for (i = 0; i < pipe_idx; i++) {
13584562236bSHarry Wentland 		if (res_ctx->pipe_ctx[i].stream)
13594562236bSHarry Wentland 			collapsed_idx++;
13604562236bSHarry Wentland 	}
13614562236bSHarry Wentland 
13624562236bSHarry Wentland 	return collapsed_idx;
13634562236bSHarry Wentland }
13644562236bSHarry Wentland 
13654562236bSHarry Wentland static bool is_watermark_set_a_greater(
13664562236bSHarry Wentland 		const struct bw_watermarks *set_a,
13674562236bSHarry Wentland 		const struct bw_watermarks *set_b)
13684562236bSHarry Wentland {
13694562236bSHarry Wentland 	if (set_a->a_mark > set_b->a_mark
13704562236bSHarry Wentland 			|| set_a->b_mark > set_b->b_mark
13714562236bSHarry Wentland 			|| set_a->c_mark > set_b->c_mark
13724562236bSHarry Wentland 			|| set_a->d_mark > set_b->d_mark)
13734562236bSHarry Wentland 		return true;
13744562236bSHarry Wentland 	return false;
13754562236bSHarry Wentland }
13764562236bSHarry Wentland 
13774562236bSHarry Wentland static bool did_watermarks_increase(
13784562236bSHarry Wentland 		struct pipe_ctx *pipe_ctx,
13794562236bSHarry Wentland 		struct validate_context *context,
13804562236bSHarry Wentland 		struct validate_context *old_context)
13814562236bSHarry Wentland {
13824562236bSHarry Wentland 	int collapsed_pipe_idx = get_bw_result_idx(&context->res_ctx,
13834562236bSHarry Wentland 			pipe_ctx->pipe_idx);
13844562236bSHarry Wentland 	int old_collapsed_pipe_idx = get_bw_result_idx(&old_context->res_ctx,
13854562236bSHarry Wentland 			pipe_ctx->pipe_idx);
13864562236bSHarry Wentland 	struct pipe_ctx *old_pipe_ctx =  &old_context->res_ctx.pipe_ctx[pipe_ctx->pipe_idx];
13874562236bSHarry Wentland 
13884562236bSHarry Wentland 	if (!old_pipe_ctx->stream)
13894562236bSHarry Wentland 		return true;
13904562236bSHarry Wentland 
13914562236bSHarry Wentland 	if (is_watermark_set_a_greater(
13924562236bSHarry Wentland 			&context->bw_results.nbp_state_change_wm_ns[collapsed_pipe_idx],
13934562236bSHarry Wentland 			&old_context->bw_results.nbp_state_change_wm_ns[old_collapsed_pipe_idx]))
13944562236bSHarry Wentland 		return true;
13954562236bSHarry Wentland 	if (is_watermark_set_a_greater(
13964562236bSHarry Wentland 			&context->bw_results.stutter_exit_wm_ns[collapsed_pipe_idx],
13974562236bSHarry Wentland 			&old_context->bw_results.stutter_exit_wm_ns[old_collapsed_pipe_idx]))
13984562236bSHarry Wentland 		return true;
13994562236bSHarry Wentland 	if (is_watermark_set_a_greater(
14004562236bSHarry Wentland 			&context->bw_results.urgent_wm_ns[collapsed_pipe_idx],
14014562236bSHarry Wentland 			&old_context->bw_results.urgent_wm_ns[old_collapsed_pipe_idx]))
14024562236bSHarry Wentland 		return true;
14034562236bSHarry Wentland 
14044562236bSHarry Wentland 	return false;
14054562236bSHarry Wentland }
14064562236bSHarry Wentland 
14074562236bSHarry Wentland static void program_wm_for_pipe(struct core_dc *dc,
14084562236bSHarry Wentland 		struct pipe_ctx *pipe_ctx,
14094562236bSHarry Wentland 		struct validate_context *context)
14104562236bSHarry Wentland {
14114562236bSHarry Wentland 	int total_dest_line_time_ns = compute_pstate_blackout_duration(
14124562236bSHarry Wentland 			dc->bw_vbios.blackout_duration,
14134562236bSHarry Wentland 			pipe_ctx->stream);
14144562236bSHarry Wentland 	int bw_result_idx = get_bw_result_idx(&context->res_ctx,
14154562236bSHarry Wentland 				pipe_ctx->pipe_idx);
14164562236bSHarry Wentland 
14174562236bSHarry Wentland 	pipe_ctx->mi->funcs->mem_input_program_display_marks(
14184562236bSHarry Wentland 		pipe_ctx->mi,
14194562236bSHarry Wentland 		context->bw_results.nbp_state_change_wm_ns[bw_result_idx],
14204562236bSHarry Wentland 		context->bw_results.stutter_exit_wm_ns[bw_result_idx],
14214562236bSHarry Wentland 		context->bw_results.urgent_wm_ns[bw_result_idx],
14224562236bSHarry Wentland 		total_dest_line_time_ns);
14234562236bSHarry Wentland 
14244562236bSHarry Wentland 	if (pipe_ctx->top_pipe)
14254562236bSHarry Wentland 		pipe_ctx->mi->funcs->mem_input_program_chroma_display_marks(
14264562236bSHarry Wentland 				pipe_ctx->mi,
14274562236bSHarry Wentland 				context->bw_results.nbp_state_change_wm_ns[bw_result_idx + 1],
14284562236bSHarry Wentland 				context->bw_results.stutter_exit_wm_ns[bw_result_idx + 1],
14294562236bSHarry Wentland 				context->bw_results.urgent_wm_ns[bw_result_idx + 1],
14304562236bSHarry Wentland 				total_dest_line_time_ns);
14314562236bSHarry Wentland }
14324562236bSHarry Wentland 
14334562236bSHarry Wentland void dce110_set_displaymarks(
14344562236bSHarry Wentland 	const struct core_dc *dc,
14354562236bSHarry Wentland 	struct validate_context *context)
14364562236bSHarry Wentland {
14374562236bSHarry Wentland 	uint8_t i, num_pipes;
14384562236bSHarry Wentland 	unsigned int underlay_idx = dc->res_pool->underlay_pipe_index;
14394562236bSHarry Wentland 
14404562236bSHarry Wentland 	for (i = 0, num_pipes = 0; i < MAX_PIPES; i++) {
14414562236bSHarry Wentland 		struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
14424562236bSHarry Wentland 		uint32_t total_dest_line_time_ns;
14434562236bSHarry Wentland 
14444562236bSHarry Wentland 		if (pipe_ctx->stream == NULL)
14454562236bSHarry Wentland 			continue;
14464562236bSHarry Wentland 
14474562236bSHarry Wentland 		total_dest_line_time_ns = compute_pstate_blackout_duration(
14484562236bSHarry Wentland 			dc->bw_vbios.blackout_duration, pipe_ctx->stream);
14494562236bSHarry Wentland 		pipe_ctx->mi->funcs->mem_input_program_display_marks(
14504562236bSHarry Wentland 			pipe_ctx->mi,
14514562236bSHarry Wentland 			context->bw_results.nbp_state_change_wm_ns[num_pipes],
14524562236bSHarry Wentland 			context->bw_results.stutter_exit_wm_ns[num_pipes],
14534562236bSHarry Wentland 			context->bw_results.urgent_wm_ns[num_pipes],
14544562236bSHarry Wentland 			total_dest_line_time_ns);
14554562236bSHarry Wentland 		if (i == underlay_idx) {
14564562236bSHarry Wentland 			num_pipes++;
14574562236bSHarry Wentland 			pipe_ctx->mi->funcs->mem_input_program_chroma_display_marks(
14584562236bSHarry Wentland 				pipe_ctx->mi,
14594562236bSHarry Wentland 				context->bw_results.nbp_state_change_wm_ns[num_pipes],
14604562236bSHarry Wentland 				context->bw_results.stutter_exit_wm_ns[num_pipes],
14614562236bSHarry Wentland 				context->bw_results.urgent_wm_ns[num_pipes],
14624562236bSHarry Wentland 				total_dest_line_time_ns);
14634562236bSHarry Wentland 		}
14644562236bSHarry Wentland 		num_pipes++;
14654562236bSHarry Wentland 	}
14664562236bSHarry Wentland }
14674562236bSHarry Wentland 
14684562236bSHarry Wentland static void set_safe_displaymarks(struct resource_context *res_ctx)
14694562236bSHarry Wentland {
14704562236bSHarry Wentland 	int i;
14714562236bSHarry Wentland 	int underlay_idx = res_ctx->pool->underlay_pipe_index;
14724562236bSHarry Wentland 	struct bw_watermarks max_marks = {
14734562236bSHarry Wentland 		MAX_WATERMARK, MAX_WATERMARK, MAX_WATERMARK, MAX_WATERMARK };
14744562236bSHarry Wentland 	struct bw_watermarks nbp_marks = {
14754562236bSHarry Wentland 		SAFE_NBP_MARK, SAFE_NBP_MARK, SAFE_NBP_MARK, SAFE_NBP_MARK };
14764562236bSHarry Wentland 
14774562236bSHarry Wentland 	for (i = 0; i < MAX_PIPES; i++) {
14784562236bSHarry Wentland 		if (res_ctx->pipe_ctx[i].stream == NULL)
14794562236bSHarry Wentland 			continue;
14804562236bSHarry Wentland 
14814562236bSHarry Wentland 		res_ctx->pipe_ctx[i].mi->funcs->mem_input_program_display_marks(
14824562236bSHarry Wentland 				res_ctx->pipe_ctx[i].mi,
14834562236bSHarry Wentland 				nbp_marks,
14844562236bSHarry Wentland 				max_marks,
14854562236bSHarry Wentland 				max_marks,
14864562236bSHarry Wentland 				MAX_WATERMARK);
14874562236bSHarry Wentland 		if (i == underlay_idx)
14884562236bSHarry Wentland 			res_ctx->pipe_ctx[i].mi->funcs->mem_input_program_chroma_display_marks(
14894562236bSHarry Wentland 				res_ctx->pipe_ctx[i].mi,
14904562236bSHarry Wentland 				nbp_marks,
14914562236bSHarry Wentland 				max_marks,
14924562236bSHarry Wentland 				max_marks,
14934562236bSHarry Wentland 				MAX_WATERMARK);
14944562236bSHarry Wentland 	}
14954562236bSHarry Wentland }
14964562236bSHarry Wentland 
14974562236bSHarry Wentland static void switch_dp_clock_sources(
14984562236bSHarry Wentland 	const struct core_dc *dc,
14994562236bSHarry Wentland 	struct resource_context *res_ctx)
15004562236bSHarry Wentland {
15014562236bSHarry Wentland 	uint8_t i;
15024562236bSHarry Wentland 	for (i = 0; i < MAX_PIPES; i++) {
15034562236bSHarry Wentland 		struct pipe_ctx *pipe_ctx = &res_ctx->pipe_ctx[i];
15044562236bSHarry Wentland 
15054562236bSHarry Wentland 		if (pipe_ctx->stream == NULL || pipe_ctx->top_pipe)
15064562236bSHarry Wentland 			continue;
15074562236bSHarry Wentland 
15084562236bSHarry Wentland 		if (dc_is_dp_signal(pipe_ctx->stream->signal)) {
15094562236bSHarry Wentland 			struct clock_source *clk_src =
15104562236bSHarry Wentland 				resource_find_used_clk_src_for_sharing(
15114562236bSHarry Wentland 						res_ctx, pipe_ctx);
15124562236bSHarry Wentland 
15134562236bSHarry Wentland 			if (clk_src &&
15144562236bSHarry Wentland 				clk_src != pipe_ctx->clock_source) {
15154562236bSHarry Wentland 				resource_unreference_clock_source(
15168c737fccSYongqiang Sun 					res_ctx, &pipe_ctx->clock_source);
15174562236bSHarry Wentland 				pipe_ctx->clock_source = clk_src;
15184562236bSHarry Wentland 				resource_reference_clock_source(res_ctx, clk_src);
15194562236bSHarry Wentland 
15204562236bSHarry Wentland 				dce_crtc_switch_to_clk_src(dc->hwseq, clk_src, i);
15214562236bSHarry Wentland 			}
15224562236bSHarry Wentland 		}
15234562236bSHarry Wentland 	}
15244562236bSHarry Wentland }
15254562236bSHarry Wentland 
15264562236bSHarry Wentland /*******************************************************************************
15274562236bSHarry Wentland  * Public functions
15284562236bSHarry Wentland  ******************************************************************************/
15294562236bSHarry Wentland 
15304562236bSHarry Wentland static void reset_single_pipe_hw_ctx(
15314562236bSHarry Wentland 		const struct core_dc *dc,
15324562236bSHarry Wentland 		struct pipe_ctx *pipe_ctx,
15334562236bSHarry Wentland 		struct validate_context *context)
15344562236bSHarry Wentland {
15354562236bSHarry Wentland 	core_link_disable_stream(pipe_ctx);
15364b5e7d62SHersen Wu 	pipe_ctx->tg->funcs->set_blank(pipe_ctx->tg, true);
15374b5e7d62SHersen Wu 	if (!hwss_wait_for_blank_complete(pipe_ctx->tg)) {
15384562236bSHarry Wentland 		dm_error("DC: failed to blank crtc!\n");
15394562236bSHarry Wentland 		BREAK_TO_DEBUGGER();
15404562236bSHarry Wentland 	}
15414562236bSHarry Wentland 	pipe_ctx->tg->funcs->disable_crtc(pipe_ctx->tg);
15424562236bSHarry Wentland 	pipe_ctx->mi->funcs->free_mem_input(
1543ab2541b6SAric Cyr 				pipe_ctx->mi, context->stream_count);
15444562236bSHarry Wentland 	resource_unreference_clock_source(
15458c737fccSYongqiang Sun 			&context->res_ctx, &pipe_ctx->clock_source);
15464562236bSHarry Wentland 
15474562236bSHarry Wentland 	dc->hwss.power_down_front_end((struct core_dc *)dc, pipe_ctx);
15484562236bSHarry Wentland 
15494562236bSHarry Wentland 	pipe_ctx->stream = NULL;
15504562236bSHarry Wentland }
15514562236bSHarry Wentland 
15524562236bSHarry Wentland static void set_drr(struct pipe_ctx **pipe_ctx,
15534562236bSHarry Wentland 		int num_pipes, int vmin, int vmax)
15544562236bSHarry Wentland {
15554562236bSHarry Wentland 	int i = 0;
15564562236bSHarry Wentland 	struct drr_params params = {0};
15574562236bSHarry Wentland 
15584562236bSHarry Wentland 	params.vertical_total_max = vmax;
15594562236bSHarry Wentland 	params.vertical_total_min = vmin;
15604562236bSHarry Wentland 
15614562236bSHarry Wentland 	/* TODO: If multiple pipes are to be supported, you need
15624562236bSHarry Wentland 	 * some GSL stuff
15634562236bSHarry Wentland 	 */
15644562236bSHarry Wentland 
15654562236bSHarry Wentland 	for (i = 0; i < num_pipes; i++) {
15664562236bSHarry Wentland 		pipe_ctx[i]->tg->funcs->set_drr(pipe_ctx[i]->tg, &params);
15674562236bSHarry Wentland 	}
15684562236bSHarry Wentland }
15694562236bSHarry Wentland 
15704562236bSHarry Wentland static void set_static_screen_control(struct pipe_ctx **pipe_ctx,
15714562236bSHarry Wentland 		int num_pipes, int value)
15724562236bSHarry Wentland {
15734562236bSHarry Wentland 	unsigned int i;
15744562236bSHarry Wentland 
15754562236bSHarry Wentland 	for (i = 0; i < num_pipes; i++)
15764562236bSHarry Wentland 		pipe_ctx[i]->tg->funcs->
15774562236bSHarry Wentland 			set_static_screen_control(pipe_ctx[i]->tg, value);
15784562236bSHarry Wentland }
15794562236bSHarry Wentland 
15804562236bSHarry Wentland /* unit: in_khz before mode set, get pixel clock from context. ASIC register
15814562236bSHarry Wentland  * may not be programmed yet.
15824562236bSHarry Wentland  * TODO: after mode set, pre_mode_set = false,
15834562236bSHarry Wentland  * may read PLL register to get pixel clock
15844562236bSHarry Wentland  */
15854562236bSHarry Wentland static uint32_t get_max_pixel_clock_for_all_paths(
15864562236bSHarry Wentland 	struct core_dc *dc,
15874562236bSHarry Wentland 	struct validate_context *context,
15884562236bSHarry Wentland 	bool pre_mode_set)
15894562236bSHarry Wentland {
15904562236bSHarry Wentland 	uint32_t max_pix_clk = 0;
15914562236bSHarry Wentland 	int i;
15924562236bSHarry Wentland 
15934562236bSHarry Wentland 	if (!pre_mode_set) {
15944562236bSHarry Wentland 		/* TODO: read ASIC register to get pixel clock */
15954562236bSHarry Wentland 		ASSERT(0);
15964562236bSHarry Wentland 	}
15974562236bSHarry Wentland 
15984562236bSHarry Wentland 	for (i = 0; i < MAX_PIPES; i++) {
15994562236bSHarry Wentland 		struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
16004562236bSHarry Wentland 
16014562236bSHarry Wentland 		if (pipe_ctx->stream == NULL)
16024562236bSHarry Wentland 			continue;
16034562236bSHarry Wentland 
16044562236bSHarry Wentland 		/* do not check under lay */
16054562236bSHarry Wentland 		if (pipe_ctx->top_pipe)
16064562236bSHarry Wentland 			continue;
16074562236bSHarry Wentland 
16084562236bSHarry Wentland 		if (pipe_ctx->pix_clk_params.requested_pix_clk > max_pix_clk)
16094562236bSHarry Wentland 			max_pix_clk =
16104562236bSHarry Wentland 				pipe_ctx->pix_clk_params.requested_pix_clk;
16114562236bSHarry Wentland 	}
16124562236bSHarry Wentland 
16134562236bSHarry Wentland 	if (max_pix_clk == 0)
16144562236bSHarry Wentland 		ASSERT(0);
16154562236bSHarry Wentland 
16164562236bSHarry Wentland 	return max_pix_clk;
16174562236bSHarry Wentland }
16184562236bSHarry Wentland 
16194562236bSHarry Wentland /*
16204562236bSHarry Wentland  * Find clock state based on clock requested. if clock value is 0, simply
16214562236bSHarry Wentland  * set clock state as requested without finding clock state by clock value
16224562236bSHarry Wentland  */
16234562236bSHarry Wentland static void apply_min_clocks(
16244562236bSHarry Wentland 	struct core_dc *dc,
16254562236bSHarry Wentland 	struct validate_context *context,
1626e9c58bb4SDmytro Laktyushkin 	enum dm_pp_clocks_state *clocks_state,
16274562236bSHarry Wentland 	bool pre_mode_set)
16284562236bSHarry Wentland {
16294562236bSHarry Wentland 	struct state_dependent_clocks req_clocks = {0};
16304562236bSHarry Wentland 	struct pipe_ctx *pipe_ctx;
16314562236bSHarry Wentland 	int i;
16324562236bSHarry Wentland 
16334562236bSHarry Wentland 	for (i = 0; i < MAX_PIPES; i++) {
16344562236bSHarry Wentland 		pipe_ctx = &context->res_ctx.pipe_ctx[i];
16354562236bSHarry Wentland 		if (pipe_ctx->dis_clk != NULL)
16364562236bSHarry Wentland 			break;
16374562236bSHarry Wentland 	}
16384562236bSHarry Wentland 
16394562236bSHarry Wentland 	if (!pre_mode_set) {
16404562236bSHarry Wentland 		/* set clock_state without verification */
16415d6d185fSDmytro Laktyushkin 		if (pipe_ctx->dis_clk->funcs->set_min_clocks_state) {
16425d6d185fSDmytro Laktyushkin 			pipe_ctx->dis_clk->funcs->set_min_clocks_state(
16435d6d185fSDmytro Laktyushkin 						pipe_ctx->dis_clk, *clocks_state);
16444562236bSHarry Wentland 			return;
16455d6d185fSDmytro Laktyushkin 		}
16464562236bSHarry Wentland 
16474562236bSHarry Wentland 		/* TODOFPGA */
16484562236bSHarry Wentland 	}
16494562236bSHarry Wentland 
16504562236bSHarry Wentland 	/* get the required state based on state dependent clocks:
16514562236bSHarry Wentland 	 * display clock and pixel clock
16524562236bSHarry Wentland 	 */
16534562236bSHarry Wentland 	req_clocks.display_clk_khz = context->bw_results.dispclk_khz;
16544562236bSHarry Wentland 
16554562236bSHarry Wentland 	req_clocks.pixel_clk_khz = get_max_pixel_clock_for_all_paths(
16564562236bSHarry Wentland 			dc, context, true);
16574562236bSHarry Wentland 
16585d6d185fSDmytro Laktyushkin 	if (pipe_ctx->dis_clk->funcs->get_required_clocks_state) {
16595d6d185fSDmytro Laktyushkin 		*clocks_state = pipe_ctx->dis_clk->funcs->get_required_clocks_state(
16605d6d185fSDmytro Laktyushkin 				pipe_ctx->dis_clk, &req_clocks);
16615d6d185fSDmytro Laktyushkin 		pipe_ctx->dis_clk->funcs->set_min_clocks_state(
16624562236bSHarry Wentland 			pipe_ctx->dis_clk, *clocks_state);
16634562236bSHarry Wentland 	} else {
16644562236bSHarry Wentland 	}
16654562236bSHarry Wentland }
16664562236bSHarry Wentland 
16674562236bSHarry Wentland static enum dc_status apply_ctx_to_hw_fpga(
16684562236bSHarry Wentland 		struct core_dc *dc,
16694562236bSHarry Wentland 		struct validate_context *context)
16704562236bSHarry Wentland {
16714562236bSHarry Wentland 	enum dc_status status = DC_ERROR_UNEXPECTED;
16724562236bSHarry Wentland 	int i;
16734562236bSHarry Wentland 
16744562236bSHarry Wentland 	for (i = 0; i < context->res_ctx.pool->pipe_count; i++) {
16754562236bSHarry Wentland 		struct pipe_ctx *pipe_ctx_old =
16764562236bSHarry Wentland 				&dc->current_context->res_ctx.pipe_ctx[i];
16774562236bSHarry Wentland 		struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
16784562236bSHarry Wentland 
16794562236bSHarry Wentland 		if (pipe_ctx->stream == NULL)
16804562236bSHarry Wentland 			continue;
16814562236bSHarry Wentland 
16824562236bSHarry Wentland 		if (pipe_ctx->stream == pipe_ctx_old->stream)
16834562236bSHarry Wentland 			continue;
16844562236bSHarry Wentland 
16854562236bSHarry Wentland 		status = apply_single_controller_ctx_to_hw(
16864562236bSHarry Wentland 				pipe_ctx,
16874562236bSHarry Wentland 				context,
16884562236bSHarry Wentland 				dc);
16894562236bSHarry Wentland 
16904562236bSHarry Wentland 		if (status != DC_OK)
16914562236bSHarry Wentland 			return status;
16924562236bSHarry Wentland 	}
16934562236bSHarry Wentland 
16944562236bSHarry Wentland 	return DC_OK;
16954562236bSHarry Wentland }
16964562236bSHarry Wentland 
16974562236bSHarry Wentland static void reset_hw_ctx_wrap(
16984562236bSHarry Wentland 		struct core_dc *dc,
16994562236bSHarry Wentland 		struct validate_context *context)
17004562236bSHarry Wentland {
17014562236bSHarry Wentland 	int i;
17024562236bSHarry Wentland 
17034562236bSHarry Wentland 	/* Reset old context */
17044562236bSHarry Wentland 	/* look up the targets that have been removed since last commit */
17054562236bSHarry Wentland 	for (i = 0; i < context->res_ctx.pool->pipe_count; i++) {
17064562236bSHarry Wentland 		struct pipe_ctx *pipe_ctx_old =
17074562236bSHarry Wentland 			&dc->current_context->res_ctx.pipe_ctx[i];
17084562236bSHarry Wentland 		struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
17094562236bSHarry Wentland 
17104562236bSHarry Wentland 		/* Note: We need to disable output if clock sources change,
17114562236bSHarry Wentland 		 * since bios does optimization and doesn't apply if changing
17124562236bSHarry Wentland 		 * PHY when not already disabled.
17134562236bSHarry Wentland 		 */
17144562236bSHarry Wentland 
17154562236bSHarry Wentland 		/* Skip underlay pipe since it will be handled in commit surface*/
17164562236bSHarry Wentland 		if (!pipe_ctx_old->stream || pipe_ctx_old->top_pipe)
17174562236bSHarry Wentland 			continue;
17184562236bSHarry Wentland 
17194562236bSHarry Wentland 		if (!pipe_ctx->stream ||
17204562236bSHarry Wentland 				pipe_need_reprogram(pipe_ctx_old, pipe_ctx))
17214562236bSHarry Wentland 			reset_single_pipe_hw_ctx(
17224562236bSHarry Wentland 				dc, pipe_ctx_old, dc->current_context);
17234562236bSHarry Wentland 	}
17244562236bSHarry Wentland }
17254562236bSHarry Wentland 
17264562236bSHarry Wentland /*TODO: const validate_context*/
17274562236bSHarry Wentland enum dc_status dce110_apply_ctx_to_hw(
17284562236bSHarry Wentland 		struct core_dc *dc,
17294562236bSHarry Wentland 		struct validate_context *context)
17304562236bSHarry Wentland {
17314562236bSHarry Wentland 	struct dc_bios *dcb = dc->ctx->dc_bios;
17324562236bSHarry Wentland 	enum dc_status status;
17334562236bSHarry Wentland 	int i;
17344562236bSHarry Wentland 	bool programmed_audio_dto = false;
1735e9c58bb4SDmytro Laktyushkin 	enum dm_pp_clocks_state clocks_state = DM_PP_CLOCKS_STATE_INVALID;
17364562236bSHarry Wentland 
17374562236bSHarry Wentland 	/* Reset old context */
17384562236bSHarry Wentland 	/* look up the targets that have been removed since last commit */
17394562236bSHarry Wentland 	dc->hwss.reset_hw_ctx_wrap(dc, context);
17404562236bSHarry Wentland 
17414562236bSHarry Wentland 	/* Skip applying if no targets */
1742ab2541b6SAric Cyr 	if (context->stream_count <= 0)
17434562236bSHarry Wentland 		return DC_OK;
17444562236bSHarry Wentland 
17454562236bSHarry Wentland 	if (IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment)) {
17464562236bSHarry Wentland 		apply_ctx_to_hw_fpga(dc, context);
17474562236bSHarry Wentland 		return DC_OK;
17484562236bSHarry Wentland 	}
17494562236bSHarry Wentland 
17504562236bSHarry Wentland 	/* Apply new context */
17514562236bSHarry Wentland 	dcb->funcs->set_scratch_critical_state(dcb, true);
17524562236bSHarry Wentland 
17534562236bSHarry Wentland 	/* below is for real asic only */
17544562236bSHarry Wentland 	for (i = 0; i < context->res_ctx.pool->pipe_count; i++) {
17554562236bSHarry Wentland 		struct pipe_ctx *pipe_ctx_old =
17564562236bSHarry Wentland 					&dc->current_context->res_ctx.pipe_ctx[i];
17574562236bSHarry Wentland 		struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
17584562236bSHarry Wentland 
17594562236bSHarry Wentland 		if (pipe_ctx->stream == NULL || pipe_ctx->top_pipe)
17604562236bSHarry Wentland 			continue;
17614562236bSHarry Wentland 
17624562236bSHarry Wentland 		if (pipe_ctx->stream == pipe_ctx_old->stream) {
17634562236bSHarry Wentland 			if (pipe_ctx_old->clock_source != pipe_ctx->clock_source)
17644562236bSHarry Wentland 				dce_crtc_switch_to_clk_src(dc->hwseq,
17654562236bSHarry Wentland 						pipe_ctx->clock_source, i);
17664562236bSHarry Wentland 			continue;
17674562236bSHarry Wentland 		}
17684562236bSHarry Wentland 
17694562236bSHarry Wentland 		dc->hwss.enable_display_power_gating(
17704562236bSHarry Wentland 				dc, i, dc->ctx->dc_bios,
17714562236bSHarry Wentland 				PIPE_GATING_CONTROL_DISABLE);
17724562236bSHarry Wentland 	}
17734562236bSHarry Wentland 
17744562236bSHarry Wentland 	set_safe_displaymarks(&context->res_ctx);
17754562236bSHarry Wentland 	/*TODO: when pplib works*/
17764562236bSHarry Wentland 	apply_min_clocks(dc, context, &clocks_state, true);
17774562236bSHarry Wentland 
17784562236bSHarry Wentland 	if (context->bw_results.dispclk_khz
17794562236bSHarry Wentland 			> dc->current_context->bw_results.dispclk_khz)
17801a687574SDmytro Laktyushkin 		context->res_ctx.pool->display_clock->funcs->set_clock(
17811a687574SDmytro Laktyushkin 				context->res_ctx.pool->display_clock,
17821a687574SDmytro Laktyushkin 				context->bw_results.dispclk_khz * 115 / 100);
17834562236bSHarry Wentland 
17844562236bSHarry Wentland 	for (i = 0; i < context->res_ctx.pool->pipe_count; i++) {
17854562236bSHarry Wentland 		struct pipe_ctx *pipe_ctx_old =
17864562236bSHarry Wentland 					&dc->current_context->res_ctx.pipe_ctx[i];
17874562236bSHarry Wentland 		struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
17884562236bSHarry Wentland 
17894562236bSHarry Wentland 		if (pipe_ctx->stream == NULL)
17904562236bSHarry Wentland 			continue;
17914562236bSHarry Wentland 
17924562236bSHarry Wentland 		if (pipe_ctx->stream == pipe_ctx_old->stream)
17934562236bSHarry Wentland 			continue;
17944562236bSHarry Wentland 
17954562236bSHarry Wentland 		if (pipe_ctx->top_pipe)
17964562236bSHarry Wentland 			continue;
17974562236bSHarry Wentland 
17984562236bSHarry Wentland 		if (context->res_ctx.pipe_ctx[i].audio != NULL) {
17994562236bSHarry Wentland 			/* Setup audio rate clock source */
18004562236bSHarry Wentland 			/* Issue:
18014562236bSHarry Wentland 			* Audio lag happened on DP monitor when unplug a HDMI monitor
18024562236bSHarry Wentland 			*
18034562236bSHarry Wentland 			* Cause:
18044562236bSHarry Wentland 			* In case of DP and HDMI connected or HDMI only, DCCG_AUDIO_DTO_SEL
18054562236bSHarry Wentland 			* is set to either dto0 or dto1, audio should work fine.
18064562236bSHarry Wentland 			* In case of DP connected only, DCCG_AUDIO_DTO_SEL should be dto1,
18074562236bSHarry Wentland 			* set to dto0 will cause audio lag.
18084562236bSHarry Wentland 			*
18094562236bSHarry Wentland 			* Solution:
18104562236bSHarry Wentland 			* Not optimized audio wall dto setup. When mode set, iterate pipe_ctx,
18114562236bSHarry Wentland 			* find first available pipe with audio, setup audio wall DTO per topology
18124562236bSHarry Wentland 			* instead of per pipe.
18134562236bSHarry Wentland 			*/
18144562236bSHarry Wentland 			struct audio_output audio_output;
18154562236bSHarry Wentland 
18164562236bSHarry Wentland 			build_audio_output(pipe_ctx, &audio_output);
18174562236bSHarry Wentland 
18184562236bSHarry Wentland 			if (dc_is_dp_signal(pipe_ctx->stream->signal))
18194562236bSHarry Wentland 				pipe_ctx->stream_enc->funcs->dp_audio_setup(
18204562236bSHarry Wentland 						pipe_ctx->stream_enc,
18214562236bSHarry Wentland 						pipe_ctx->audio->inst,
18224562236bSHarry Wentland 						&pipe_ctx->stream->public.audio_info);
18234562236bSHarry Wentland 			else
18244562236bSHarry Wentland 				pipe_ctx->stream_enc->funcs->hdmi_audio_setup(
18254562236bSHarry Wentland 						pipe_ctx->stream_enc,
18264562236bSHarry Wentland 						pipe_ctx->audio->inst,
18274562236bSHarry Wentland 						&pipe_ctx->stream->public.audio_info,
18284562236bSHarry Wentland 						&audio_output.crtc_info);
18294562236bSHarry Wentland 
18304562236bSHarry Wentland 			pipe_ctx->audio->funcs->az_configure(
18314562236bSHarry Wentland 					pipe_ctx->audio,
18324562236bSHarry Wentland 					pipe_ctx->stream->signal,
18334562236bSHarry Wentland 					&audio_output.crtc_info,
18344562236bSHarry Wentland 					&pipe_ctx->stream->public.audio_info);
18354562236bSHarry Wentland 
18364562236bSHarry Wentland 			if (!programmed_audio_dto) {
18374562236bSHarry Wentland 				pipe_ctx->audio->funcs->wall_dto_setup(
18384562236bSHarry Wentland 					pipe_ctx->audio,
18394562236bSHarry Wentland 					pipe_ctx->stream->signal,
18404562236bSHarry Wentland 					&audio_output.crtc_info,
18414562236bSHarry Wentland 					&audio_output.pll_info);
18424562236bSHarry Wentland 				programmed_audio_dto = true;
18434562236bSHarry Wentland 			}
18444562236bSHarry Wentland 		}
18454562236bSHarry Wentland 
18464562236bSHarry Wentland 		status = apply_single_controller_ctx_to_hw(
18474562236bSHarry Wentland 				pipe_ctx,
18484562236bSHarry Wentland 				context,
18494562236bSHarry Wentland 				dc);
18504562236bSHarry Wentland 
18514562236bSHarry Wentland 		if (DC_OK != status)
18524562236bSHarry Wentland 			return status;
18534562236bSHarry Wentland 	}
18544562236bSHarry Wentland 
18554562236bSHarry Wentland 	dc->hwss.set_displaymarks(dc, context);
18564562236bSHarry Wentland 
18574562236bSHarry Wentland 	/* to save power */
18584562236bSHarry Wentland 	apply_min_clocks(dc, context, &clocks_state, false);
18594562236bSHarry Wentland 
18604562236bSHarry Wentland 	dcb->funcs->set_scratch_critical_state(dcb, false);
18614562236bSHarry Wentland 
18624562236bSHarry Wentland 	switch_dp_clock_sources(dc, &context->res_ctx);
18634562236bSHarry Wentland 
18644562236bSHarry Wentland 	return DC_OK;
18654562236bSHarry Wentland }
18664562236bSHarry Wentland 
18674562236bSHarry Wentland /*******************************************************************************
18684562236bSHarry Wentland  * Front End programming
18694562236bSHarry Wentland  ******************************************************************************/
18704562236bSHarry Wentland static void set_default_colors(struct pipe_ctx *pipe_ctx)
18714562236bSHarry Wentland {
18724562236bSHarry Wentland 	struct default_adjustment default_adjust = { 0 };
18734562236bSHarry Wentland 
18744562236bSHarry Wentland 	default_adjust.force_hw_default = false;
18754562236bSHarry Wentland 	if (pipe_ctx->surface == NULL)
18764562236bSHarry Wentland 		default_adjust.in_color_space = COLOR_SPACE_SRGB;
18774562236bSHarry Wentland 	else
18784562236bSHarry Wentland 		default_adjust.in_color_space =
18794562236bSHarry Wentland 				pipe_ctx->surface->public.color_space;
18804562236bSHarry Wentland 	if (pipe_ctx->stream == NULL)
18814562236bSHarry Wentland 		default_adjust.out_color_space = COLOR_SPACE_SRGB;
18824562236bSHarry Wentland 	else
18834562236bSHarry Wentland 		default_adjust.out_color_space =
18844562236bSHarry Wentland 				pipe_ctx->stream->public.output_color_space;
18854562236bSHarry Wentland 	default_adjust.csc_adjust_type = GRAPHICS_CSC_ADJUST_TYPE_SW;
18864562236bSHarry Wentland 	default_adjust.surface_pixel_format = pipe_ctx->scl_data.format;
18874562236bSHarry Wentland 
18884562236bSHarry Wentland 	/* display color depth */
18894562236bSHarry Wentland 	default_adjust.color_depth =
18904562236bSHarry Wentland 		pipe_ctx->stream->public.timing.display_color_depth;
18914562236bSHarry Wentland 
18924562236bSHarry Wentland 	/* Lb color depth */
18934562236bSHarry Wentland 	default_adjust.lb_color_depth = pipe_ctx->scl_data.lb_params.depth;
18944562236bSHarry Wentland 
18954562236bSHarry Wentland 	pipe_ctx->opp->funcs->opp_set_csc_default(
18964562236bSHarry Wentland 					pipe_ctx->opp, &default_adjust);
18974562236bSHarry Wentland }
18984562236bSHarry Wentland 
1899b06b7680SLeon Elazar 
1900b06b7680SLeon Elazar /*******************************************************************************
1901b06b7680SLeon Elazar  * In order to turn on/off specific surface we will program
1902b06b7680SLeon Elazar  * Blender + CRTC
1903b06b7680SLeon Elazar  *
1904b06b7680SLeon Elazar  * In case that we have two surfaces and they have a different visibility
1905b06b7680SLeon Elazar  * we can't turn off the CRTC since it will turn off the entire display
1906b06b7680SLeon Elazar  *
1907b06b7680SLeon Elazar  * |----------------------------------------------- |
1908b06b7680SLeon Elazar  * |bottom pipe|curr pipe  |              |         |
1909b06b7680SLeon Elazar  * |Surface    |Surface    | Blender      |  CRCT   |
1910b06b7680SLeon Elazar  * |visibility |visibility | Configuration|         |
1911b06b7680SLeon Elazar  * |------------------------------------------------|
1912b06b7680SLeon Elazar  * |   off     |    off    | CURRENT_PIPE | blank   |
1913b06b7680SLeon Elazar  * |   off     |    on     | CURRENT_PIPE | unblank |
1914b06b7680SLeon Elazar  * |   on      |    off    | OTHER_PIPE   | unblank |
1915b06b7680SLeon Elazar  * |   on      |    on     | BLENDING     | unblank |
1916b06b7680SLeon Elazar  * -------------------------------------------------|
1917b06b7680SLeon Elazar  *
1918b06b7680SLeon Elazar  ******************************************************************************/
1919b06b7680SLeon Elazar static void program_surface_visibility(const struct core_dc *dc,
19204562236bSHarry Wentland 		struct pipe_ctx *pipe_ctx)
19214562236bSHarry Wentland {
19224562236bSHarry Wentland 	enum blnd_mode blender_mode = BLND_MODE_CURRENT_PIPE;
1923b06b7680SLeon Elazar 	bool blank_target = false;
19244562236bSHarry Wentland 
19254562236bSHarry Wentland 	if (pipe_ctx->bottom_pipe) {
1926b06b7680SLeon Elazar 
1927b06b7680SLeon Elazar 		/* For now we are supporting only two pipes */
1928b06b7680SLeon Elazar 		ASSERT(pipe_ctx->bottom_pipe->bottom_pipe == NULL);
1929b06b7680SLeon Elazar 
19304562236bSHarry Wentland 		if (pipe_ctx->bottom_pipe->surface->public.visible) {
19314562236bSHarry Wentland 			if (pipe_ctx->surface->public.visible)
19324562236bSHarry Wentland 				blender_mode = BLND_MODE_BLENDING;
19334562236bSHarry Wentland 			else
19344562236bSHarry Wentland 				blender_mode = BLND_MODE_OTHER_PIPE;
1935b06b7680SLeon Elazar 
1936b06b7680SLeon Elazar 		} else if (!pipe_ctx->surface->public.visible)
1937b06b7680SLeon Elazar 			blank_target = true;
1938b06b7680SLeon Elazar 
1939b06b7680SLeon Elazar 	} else if (!pipe_ctx->surface->public.visible)
1940b06b7680SLeon Elazar 		blank_target = true;
1941b06b7680SLeon Elazar 
19424562236bSHarry Wentland 	dce_set_blender_mode(dc->hwseq, pipe_ctx->pipe_idx, blender_mode);
1943b06b7680SLeon Elazar 	pipe_ctx->tg->funcs->set_blank(pipe_ctx->tg, blank_target);
1944b06b7680SLeon Elazar 
19454562236bSHarry Wentland }
19464562236bSHarry Wentland 
19474562236bSHarry Wentland /**
19484562236bSHarry Wentland  * TODO REMOVE, USE UPDATE INSTEAD
19494562236bSHarry Wentland  */
19504562236bSHarry Wentland static void set_plane_config(
19514562236bSHarry Wentland 	const struct core_dc *dc,
19524562236bSHarry Wentland 	struct pipe_ctx *pipe_ctx,
19534562236bSHarry Wentland 	struct resource_context *res_ctx)
19544562236bSHarry Wentland {
19554562236bSHarry Wentland 	struct mem_input *mi = pipe_ctx->mi;
19564562236bSHarry Wentland 	struct core_surface *surface = pipe_ctx->surface;
19574562236bSHarry Wentland 	struct xfm_grph_csc_adjustment adjust;
19584562236bSHarry Wentland 	struct out_csc_color_matrix tbl_entry;
19594562236bSHarry Wentland 	unsigned int i;
19604562236bSHarry Wentland 
19614562236bSHarry Wentland 	memset(&adjust, 0, sizeof(adjust));
19624562236bSHarry Wentland 	memset(&tbl_entry, 0, sizeof(tbl_entry));
19634562236bSHarry Wentland 	adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS;
19644562236bSHarry Wentland 
19654562236bSHarry Wentland 	dce_enable_fe_clock(dc->hwseq, pipe_ctx->pipe_idx, true);
19664562236bSHarry Wentland 
19674562236bSHarry Wentland 	set_default_colors(pipe_ctx);
19684562236bSHarry Wentland 	if (pipe_ctx->stream->public.csc_color_matrix.enable_adjustment
19694562236bSHarry Wentland 			== true) {
19704562236bSHarry Wentland 		tbl_entry.color_space =
19714562236bSHarry Wentland 			pipe_ctx->stream->public.output_color_space;
19724562236bSHarry Wentland 
19734562236bSHarry Wentland 		for (i = 0; i < 12; i++)
19744562236bSHarry Wentland 			tbl_entry.regval[i] =
19754562236bSHarry Wentland 			pipe_ctx->stream->public.csc_color_matrix.matrix[i];
19764562236bSHarry Wentland 
19774562236bSHarry Wentland 		pipe_ctx->opp->funcs->opp_set_csc_adjustment
19784562236bSHarry Wentland 				(pipe_ctx->opp, &tbl_entry);
19794562236bSHarry Wentland 	}
19804562236bSHarry Wentland 
19814562236bSHarry Wentland 	if (pipe_ctx->stream->public.gamut_remap_matrix.enable_remap == true) {
19824562236bSHarry Wentland 		adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_SW;
19834562236bSHarry Wentland 		adjust.temperature_matrix[0] =
19844562236bSHarry Wentland 				pipe_ctx->stream->
19854562236bSHarry Wentland 				public.gamut_remap_matrix.matrix[0];
19864562236bSHarry Wentland 		adjust.temperature_matrix[1] =
19874562236bSHarry Wentland 				pipe_ctx->stream->
19884562236bSHarry Wentland 				public.gamut_remap_matrix.matrix[1];
19894562236bSHarry Wentland 		adjust.temperature_matrix[2] =
19904562236bSHarry Wentland 				pipe_ctx->stream->
19914562236bSHarry Wentland 				public.gamut_remap_matrix.matrix[2];
19924562236bSHarry Wentland 		adjust.temperature_matrix[3] =
19934562236bSHarry Wentland 				pipe_ctx->stream->
19944562236bSHarry Wentland 				public.gamut_remap_matrix.matrix[4];
19954562236bSHarry Wentland 		adjust.temperature_matrix[4] =
19964562236bSHarry Wentland 				pipe_ctx->stream->
19974562236bSHarry Wentland 				public.gamut_remap_matrix.matrix[5];
19984562236bSHarry Wentland 		adjust.temperature_matrix[5] =
19994562236bSHarry Wentland 				pipe_ctx->stream->
20004562236bSHarry Wentland 				public.gamut_remap_matrix.matrix[6];
20014562236bSHarry Wentland 		adjust.temperature_matrix[6] =
20024562236bSHarry Wentland 				pipe_ctx->stream->
20034562236bSHarry Wentland 				public.gamut_remap_matrix.matrix[8];
20044562236bSHarry Wentland 		adjust.temperature_matrix[7] =
20054562236bSHarry Wentland 				pipe_ctx->stream->
20064562236bSHarry Wentland 				public.gamut_remap_matrix.matrix[9];
20074562236bSHarry Wentland 		adjust.temperature_matrix[8] =
20084562236bSHarry Wentland 				pipe_ctx->stream->
20094562236bSHarry Wentland 				public.gamut_remap_matrix.matrix[10];
20104562236bSHarry Wentland 	}
20114562236bSHarry Wentland 
20124562236bSHarry Wentland 	pipe_ctx->xfm->funcs->transform_set_gamut_remap(pipe_ctx->xfm, &adjust);
20134562236bSHarry Wentland 
20144562236bSHarry Wentland 	pipe_ctx->scl_data.lb_params.alpha_en = pipe_ctx->bottom_pipe != 0;
20154562236bSHarry Wentland 	program_scaler(dc, pipe_ctx);
20164562236bSHarry Wentland 
2017b06b7680SLeon Elazar 	program_surface_visibility(dc, pipe_ctx);
20184562236bSHarry Wentland 
20194562236bSHarry Wentland 	mi->funcs->mem_input_program_surface_config(
20204562236bSHarry Wentland 			mi,
20214562236bSHarry Wentland 			surface->public.format,
20224562236bSHarry Wentland 			&surface->public.tiling_info,
20234562236bSHarry Wentland 			&surface->public.plane_size,
20244562236bSHarry Wentland 			surface->public.rotation,
20254562236bSHarry Wentland 			NULL,
2026624d7c47SYongqiang Sun 			false,
2027624d7c47SYongqiang Sun 			pipe_ctx->surface->public.visible);
20284562236bSHarry Wentland 
20294562236bSHarry Wentland 	if (dc->public.config.gpu_vm_support)
20304562236bSHarry Wentland 		mi->funcs->mem_input_program_pte_vm(
20314562236bSHarry Wentland 				pipe_ctx->mi,
20324562236bSHarry Wentland 				surface->public.format,
20334562236bSHarry Wentland 				&surface->public.tiling_info,
20344562236bSHarry Wentland 				surface->public.rotation);
20354562236bSHarry Wentland }
20364562236bSHarry Wentland 
20374562236bSHarry Wentland static void update_plane_addr(const struct core_dc *dc,
20384562236bSHarry Wentland 		struct pipe_ctx *pipe_ctx)
20394562236bSHarry Wentland {
20404562236bSHarry Wentland 	struct core_surface *surface = pipe_ctx->surface;
20414562236bSHarry Wentland 
20424562236bSHarry Wentland 	if (surface == NULL)
20434562236bSHarry Wentland 		return;
20444562236bSHarry Wentland 
20454562236bSHarry Wentland 	pipe_ctx->mi->funcs->mem_input_program_surface_flip_and_addr(
20464562236bSHarry Wentland 			pipe_ctx->mi,
20474562236bSHarry Wentland 			&surface->public.address,
20484562236bSHarry Wentland 			surface->public.flip_immediate);
20494562236bSHarry Wentland 
20504562236bSHarry Wentland 	surface->status.requested_address = surface->public.address;
20514562236bSHarry Wentland }
20524562236bSHarry Wentland 
20534562236bSHarry Wentland void dce110_update_pending_status(struct pipe_ctx *pipe_ctx)
20544562236bSHarry Wentland {
20554562236bSHarry Wentland 	struct core_surface *surface = pipe_ctx->surface;
20564562236bSHarry Wentland 
20574562236bSHarry Wentland 	if (surface == NULL)
20584562236bSHarry Wentland 		return;
20594562236bSHarry Wentland 
20604562236bSHarry Wentland 	surface->status.is_flip_pending =
20614562236bSHarry Wentland 			pipe_ctx->mi->funcs->mem_input_is_flip_pending(
20624562236bSHarry Wentland 					pipe_ctx->mi);
20634562236bSHarry Wentland 
20644562236bSHarry Wentland 	if (surface->status.is_flip_pending && !surface->public.visible)
20654562236bSHarry Wentland 		pipe_ctx->mi->current_address = pipe_ctx->mi->request_address;
20664562236bSHarry Wentland 
20674562236bSHarry Wentland 	surface->status.current_address = pipe_ctx->mi->current_address;
20684562236bSHarry Wentland }
20694562236bSHarry Wentland 
20704562236bSHarry Wentland void dce110_power_down(struct core_dc *dc)
20714562236bSHarry Wentland {
20724562236bSHarry Wentland 	power_down_all_hw_blocks(dc);
20734562236bSHarry Wentland 	disable_vga_and_power_gate_all_controllers(dc);
20744562236bSHarry Wentland }
20754562236bSHarry Wentland 
20764562236bSHarry Wentland static bool wait_for_reset_trigger_to_occur(
20774562236bSHarry Wentland 	struct dc_context *dc_ctx,
20784562236bSHarry Wentland 	struct timing_generator *tg)
20794562236bSHarry Wentland {
20804562236bSHarry Wentland 	bool rc = false;
20814562236bSHarry Wentland 
20824562236bSHarry Wentland 	/* To avoid endless loop we wait at most
20834562236bSHarry Wentland 	 * frames_to_wait_on_triggered_reset frames for the reset to occur. */
20844562236bSHarry Wentland 	const uint32_t frames_to_wait_on_triggered_reset = 10;
20854562236bSHarry Wentland 	uint32_t i;
20864562236bSHarry Wentland 
20874562236bSHarry Wentland 	for (i = 0; i < frames_to_wait_on_triggered_reset; i++) {
20884562236bSHarry Wentland 
20894562236bSHarry Wentland 		if (!tg->funcs->is_counter_moving(tg)) {
20904562236bSHarry Wentland 			DC_ERROR("TG counter is not moving!\n");
20914562236bSHarry Wentland 			break;
20924562236bSHarry Wentland 		}
20934562236bSHarry Wentland 
20944562236bSHarry Wentland 		if (tg->funcs->did_triggered_reset_occur(tg)) {
20954562236bSHarry Wentland 			rc = true;
20964562236bSHarry Wentland 			/* usually occurs at i=1 */
20974562236bSHarry Wentland 			DC_SYNC_INFO("GSL: reset occurred at wait count: %d\n",
20984562236bSHarry Wentland 					i);
20994562236bSHarry Wentland 			break;
21004562236bSHarry Wentland 		}
21014562236bSHarry Wentland 
21024562236bSHarry Wentland 		/* Wait for one frame. */
21034562236bSHarry Wentland 		tg->funcs->wait_for_state(tg, CRTC_STATE_VACTIVE);
21044562236bSHarry Wentland 		tg->funcs->wait_for_state(tg, CRTC_STATE_VBLANK);
21054562236bSHarry Wentland 	}
21064562236bSHarry Wentland 
21074562236bSHarry Wentland 	if (false == rc)
21084562236bSHarry Wentland 		DC_ERROR("GSL: Timeout on reset trigger!\n");
21094562236bSHarry Wentland 
21104562236bSHarry Wentland 	return rc;
21114562236bSHarry Wentland }
21124562236bSHarry Wentland 
21134562236bSHarry Wentland /* Enable timing synchronization for a group of Timing Generators. */
21144562236bSHarry Wentland static void dce110_enable_timing_synchronization(
21154562236bSHarry Wentland 		struct core_dc *dc,
21164562236bSHarry Wentland 		int group_index,
21174562236bSHarry Wentland 		int group_size,
21184562236bSHarry Wentland 		struct pipe_ctx *grouped_pipes[])
21194562236bSHarry Wentland {
21204562236bSHarry Wentland 	struct dc_context *dc_ctx = dc->ctx;
21214562236bSHarry Wentland 	struct dcp_gsl_params gsl_params = { 0 };
21224562236bSHarry Wentland 	int i;
21234562236bSHarry Wentland 
21244562236bSHarry Wentland 	DC_SYNC_INFO("GSL: Setting-up...\n");
21254562236bSHarry Wentland 
21264562236bSHarry Wentland 	/* Designate a single TG in the group as a master.
21274562236bSHarry Wentland 	 * Since HW doesn't care which one, we always assign
21284562236bSHarry Wentland 	 * the 1st one in the group. */
21294562236bSHarry Wentland 	gsl_params.gsl_group = 0;
21304562236bSHarry Wentland 	gsl_params.gsl_master = grouped_pipes[0]->tg->inst;
21314562236bSHarry Wentland 
21324562236bSHarry Wentland 	for (i = 0; i < group_size; i++)
21334562236bSHarry Wentland 		grouped_pipes[i]->tg->funcs->setup_global_swap_lock(
21344562236bSHarry Wentland 					grouped_pipes[i]->tg, &gsl_params);
21354562236bSHarry Wentland 
21364562236bSHarry Wentland 	/* Reset slave controllers on master VSync */
21374562236bSHarry Wentland 	DC_SYNC_INFO("GSL: enabling trigger-reset\n");
21384562236bSHarry Wentland 
21394562236bSHarry Wentland 	for (i = 1 /* skip the master */; i < group_size; i++)
21404562236bSHarry Wentland 		grouped_pipes[i]->tg->funcs->enable_reset_trigger(
21414562236bSHarry Wentland 					grouped_pipes[i]->tg, gsl_params.gsl_group);
21424562236bSHarry Wentland 
21434562236bSHarry Wentland 
21444562236bSHarry Wentland 
21454562236bSHarry Wentland 	for (i = 1 /* skip the master */; i < group_size; i++) {
21464562236bSHarry Wentland 		DC_SYNC_INFO("GSL: waiting for reset to occur.\n");
21474562236bSHarry Wentland 		wait_for_reset_trigger_to_occur(dc_ctx, grouped_pipes[i]->tg);
21484562236bSHarry Wentland 		/* Regardless of success of the wait above, remove the reset or
21494562236bSHarry Wentland 		 * the driver will start timing out on Display requests. */
21504562236bSHarry Wentland 		DC_SYNC_INFO("GSL: disabling trigger-reset.\n");
21514562236bSHarry Wentland 		grouped_pipes[i]->tg->funcs->disable_reset_trigger(grouped_pipes[i]->tg);
21524562236bSHarry Wentland 	}
21534562236bSHarry Wentland 
21544562236bSHarry Wentland 
21554562236bSHarry Wentland 	/* GSL Vblank synchronization is a one time sync mechanism, assumption
21564562236bSHarry Wentland 	 * is that the sync'ed displays will not drift out of sync over time*/
21574562236bSHarry Wentland 	DC_SYNC_INFO("GSL: Restoring register states.\n");
21584562236bSHarry Wentland 	for (i = 0; i < group_size; i++)
21594562236bSHarry Wentland 		grouped_pipes[i]->tg->funcs->tear_down_global_swap_lock(grouped_pipes[i]->tg);
21604562236bSHarry Wentland 
21614562236bSHarry Wentland 	DC_SYNC_INFO("GSL: Set-up complete.\n");
21624562236bSHarry Wentland }
21634562236bSHarry Wentland 
21644562236bSHarry Wentland static void init_hw(struct core_dc *dc)
21654562236bSHarry Wentland {
21664562236bSHarry Wentland 	int i;
21674562236bSHarry Wentland 	struct dc_bios *bp;
21684562236bSHarry Wentland 	struct transform *xfm;
21694562236bSHarry Wentland 
21704562236bSHarry Wentland 	bp = dc->ctx->dc_bios;
21714562236bSHarry Wentland 	for (i = 0; i < dc->res_pool->pipe_count; i++) {
21724562236bSHarry Wentland 		xfm = dc->res_pool->transforms[i];
21734562236bSHarry Wentland 		xfm->funcs->transform_reset(xfm);
21744562236bSHarry Wentland 
21754562236bSHarry Wentland 		dc->hwss.enable_display_power_gating(
21764562236bSHarry Wentland 				dc, i, bp,
21774562236bSHarry Wentland 				PIPE_GATING_CONTROL_INIT);
21784562236bSHarry Wentland 		dc->hwss.enable_display_power_gating(
21794562236bSHarry Wentland 				dc, i, bp,
21804562236bSHarry Wentland 				PIPE_GATING_CONTROL_DISABLE);
21814562236bSHarry Wentland 		dc->hwss.enable_display_pipe_clock_gating(
21824562236bSHarry Wentland 			dc->ctx,
21834562236bSHarry Wentland 			true);
21844562236bSHarry Wentland 	}
21854562236bSHarry Wentland 
21864562236bSHarry Wentland 	dce_clock_gating_power_up(dc->hwseq, false);;
21874562236bSHarry Wentland 	/***************************************/
21884562236bSHarry Wentland 
21894562236bSHarry Wentland 	for (i = 0; i < dc->link_count; i++) {
21904562236bSHarry Wentland 		/****************************************/
21914562236bSHarry Wentland 		/* Power up AND update implementation according to the
21924562236bSHarry Wentland 		 * required signal (which may be different from the
21934562236bSHarry Wentland 		 * default signal on connector). */
21944562236bSHarry Wentland 		struct core_link *link = dc->links[i];
21954562236bSHarry Wentland 		link->link_enc->funcs->hw_init(link->link_enc);
21964562236bSHarry Wentland 	}
21974562236bSHarry Wentland 
21984562236bSHarry Wentland 	for (i = 0; i < dc->res_pool->pipe_count; i++) {
21994562236bSHarry Wentland 		struct timing_generator *tg = dc->res_pool->timing_generators[i];
22004562236bSHarry Wentland 
22014562236bSHarry Wentland 		tg->funcs->disable_vga(tg);
22024562236bSHarry Wentland 
22034562236bSHarry Wentland 		/* Blank controller using driver code instead of
22044562236bSHarry Wentland 		 * command table. */
22054562236bSHarry Wentland 		tg->funcs->set_blank(tg, true);
22064b5e7d62SHersen Wu 		hwss_wait_for_blank_complete(tg);
22074562236bSHarry Wentland 	}
22084562236bSHarry Wentland 
22094562236bSHarry Wentland 	for (i = 0; i < dc->res_pool->audio_count; i++) {
22104562236bSHarry Wentland 		struct audio *audio = dc->res_pool->audios[i];
22114562236bSHarry Wentland 		audio->funcs->hw_init(audio);
22124562236bSHarry Wentland 	}
22134562236bSHarry Wentland }
22144562236bSHarry Wentland 
22154562236bSHarry Wentland /* TODO: move this to apply_ctx_tohw some how?*/
22164562236bSHarry Wentland static void dce110_power_on_pipe_if_needed(
22174562236bSHarry Wentland 		struct core_dc *dc,
22184562236bSHarry Wentland 		struct pipe_ctx *pipe_ctx,
22194562236bSHarry Wentland 		struct validate_context *context)
22204562236bSHarry Wentland {
22214562236bSHarry Wentland 	struct pipe_ctx *old_pipe_ctx = &dc->current_context->res_ctx.pipe_ctx[pipe_ctx->pipe_idx];
22224562236bSHarry Wentland 	struct dc_bios *dcb = dc->ctx->dc_bios;
22234562236bSHarry Wentland 	struct tg_color black_color = {0};
22244562236bSHarry Wentland 
22254562236bSHarry Wentland 	if (!old_pipe_ctx->stream && pipe_ctx->stream) {
22264562236bSHarry Wentland 		dc->hwss.enable_display_power_gating(
22274562236bSHarry Wentland 				dc,
22284562236bSHarry Wentland 				pipe_ctx->pipe_idx,
22294562236bSHarry Wentland 				dcb, PIPE_GATING_CONTROL_DISABLE);
22304562236bSHarry Wentland 
22314562236bSHarry Wentland 		/*
22324562236bSHarry Wentland 		 * This is for powering on underlay, so crtc does not
22334562236bSHarry Wentland 		 * need to be enabled
22344562236bSHarry Wentland 		 */
22354562236bSHarry Wentland 
22364562236bSHarry Wentland 		pipe_ctx->tg->funcs->program_timing(pipe_ctx->tg,
22374562236bSHarry Wentland 				&pipe_ctx->stream->public.timing,
22384562236bSHarry Wentland 				false);
22394562236bSHarry Wentland 
22404562236bSHarry Wentland 		pipe_ctx->tg->funcs->enable_advanced_request(
22414562236bSHarry Wentland 				pipe_ctx->tg,
22424562236bSHarry Wentland 				true,
22434562236bSHarry Wentland 				&pipe_ctx->stream->public.timing);
22444562236bSHarry Wentland 
22454562236bSHarry Wentland 		pipe_ctx->mi->funcs->allocate_mem_input(pipe_ctx->mi,
22464562236bSHarry Wentland 				pipe_ctx->stream->public.timing.h_total,
22474562236bSHarry Wentland 				pipe_ctx->stream->public.timing.v_total,
22484562236bSHarry Wentland 				pipe_ctx->stream->public.timing.pix_clk_khz,
2249ab2541b6SAric Cyr 				context->stream_count);
22504562236bSHarry Wentland 
22514562236bSHarry Wentland 		/* TODO unhardcode*/
22524562236bSHarry Wentland 		color_space_to_black_color(dc,
22534562236bSHarry Wentland 				COLOR_SPACE_YCBCR601, &black_color);
22544562236bSHarry Wentland 		pipe_ctx->tg->funcs->set_blank_color(
22554562236bSHarry Wentland 				pipe_ctx->tg,
22564562236bSHarry Wentland 				&black_color);
22574562236bSHarry Wentland 	}
22584562236bSHarry Wentland }
22594562236bSHarry Wentland 
22604562236bSHarry Wentland static void dce110_increase_watermarks_for_pipe(
22614562236bSHarry Wentland 		struct core_dc *dc,
22624562236bSHarry Wentland 		struct pipe_ctx *pipe_ctx,
22634562236bSHarry Wentland 		struct validate_context *context)
22644562236bSHarry Wentland {
22654562236bSHarry Wentland 	if (did_watermarks_increase(pipe_ctx, context, dc->current_context))
22664562236bSHarry Wentland 		program_wm_for_pipe(dc, pipe_ctx, context);
22674562236bSHarry Wentland }
22684562236bSHarry Wentland 
22694562236bSHarry Wentland static void dce110_set_bandwidth(struct core_dc *dc)
22704562236bSHarry Wentland {
22714562236bSHarry Wentland 	int i;
22724562236bSHarry Wentland 
22734562236bSHarry Wentland 	for (i = 0; i < dc->current_context->res_ctx.pool->pipe_count; i++) {
22744562236bSHarry Wentland 		struct pipe_ctx *pipe_ctx = &dc->current_context->res_ctx.pipe_ctx[i];
22754562236bSHarry Wentland 
22764562236bSHarry Wentland 		if (!pipe_ctx->stream)
22774562236bSHarry Wentland 			continue;
22784562236bSHarry Wentland 
22794562236bSHarry Wentland 		program_wm_for_pipe(dc, pipe_ctx, dc->current_context);
22804562236bSHarry Wentland 	}
22814562236bSHarry Wentland 
22821a687574SDmytro Laktyushkin 	dc->current_context->res_ctx.pool->display_clock->funcs->set_clock(
22831a687574SDmytro Laktyushkin 			dc->current_context->res_ctx.pool->display_clock,
22841a687574SDmytro Laktyushkin 			dc->current_context->bw_results.dispclk_khz * 115 / 100);
22854562236bSHarry Wentland }
22864562236bSHarry Wentland 
22874562236bSHarry Wentland static void dce110_program_front_end_for_pipe(
22884562236bSHarry Wentland 		struct core_dc *dc, struct pipe_ctx *pipe_ctx)
22894562236bSHarry Wentland {
22904562236bSHarry Wentland 	struct mem_input *mi = pipe_ctx->mi;
22914562236bSHarry Wentland 	struct pipe_ctx *old_pipe = NULL;
22924562236bSHarry Wentland 	struct core_surface *surface = pipe_ctx->surface;
22934562236bSHarry Wentland 	struct xfm_grph_csc_adjustment adjust;
22944562236bSHarry Wentland 	struct out_csc_color_matrix tbl_entry;
22954562236bSHarry Wentland 	unsigned int i;
22964562236bSHarry Wentland 
22974562236bSHarry Wentland 	memset(&tbl_entry, 0, sizeof(tbl_entry));
22984562236bSHarry Wentland 
22994562236bSHarry Wentland 	if (dc->current_context)
23004562236bSHarry Wentland 		old_pipe = &dc->current_context->res_ctx.pipe_ctx[pipe_ctx->pipe_idx];
23014562236bSHarry Wentland 
23024562236bSHarry Wentland 	memset(&adjust, 0, sizeof(adjust));
23034562236bSHarry Wentland 	adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_BYPASS;
23044562236bSHarry Wentland 
23054562236bSHarry Wentland 	dce_enable_fe_clock(dc->hwseq, pipe_ctx->pipe_idx, true);
23064562236bSHarry Wentland 
23074562236bSHarry Wentland 	set_default_colors(pipe_ctx);
23084562236bSHarry Wentland 	if (pipe_ctx->stream->public.csc_color_matrix.enable_adjustment
23094562236bSHarry Wentland 			== true) {
23104562236bSHarry Wentland 		tbl_entry.color_space =
23114562236bSHarry Wentland 			pipe_ctx->stream->public.output_color_space;
23124562236bSHarry Wentland 
23134562236bSHarry Wentland 		for (i = 0; i < 12; i++)
23144562236bSHarry Wentland 			tbl_entry.regval[i] =
23154562236bSHarry Wentland 			pipe_ctx->stream->public.csc_color_matrix.matrix[i];
23164562236bSHarry Wentland 
23174562236bSHarry Wentland 		pipe_ctx->opp->funcs->opp_set_csc_adjustment
23184562236bSHarry Wentland 				(pipe_ctx->opp, &tbl_entry);
23194562236bSHarry Wentland 	}
23204562236bSHarry Wentland 
23214562236bSHarry Wentland 	if (pipe_ctx->stream->public.gamut_remap_matrix.enable_remap == true) {
23224562236bSHarry Wentland 		adjust.gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_SW;
23234562236bSHarry Wentland 		adjust.temperature_matrix[0] =
23244562236bSHarry Wentland 				pipe_ctx->stream->
23254562236bSHarry Wentland 				public.gamut_remap_matrix.matrix[0];
23264562236bSHarry Wentland 		adjust.temperature_matrix[1] =
23274562236bSHarry Wentland 				pipe_ctx->stream->
23284562236bSHarry Wentland 				public.gamut_remap_matrix.matrix[1];
23294562236bSHarry Wentland 		adjust.temperature_matrix[2] =
23304562236bSHarry Wentland 				pipe_ctx->stream->
23314562236bSHarry Wentland 				public.gamut_remap_matrix.matrix[2];
23324562236bSHarry Wentland 		adjust.temperature_matrix[3] =
23334562236bSHarry Wentland 				pipe_ctx->stream->
23344562236bSHarry Wentland 				public.gamut_remap_matrix.matrix[4];
23354562236bSHarry Wentland 		adjust.temperature_matrix[4] =
23364562236bSHarry Wentland 				pipe_ctx->stream->
23374562236bSHarry Wentland 				public.gamut_remap_matrix.matrix[5];
23384562236bSHarry Wentland 		adjust.temperature_matrix[5] =
23394562236bSHarry Wentland 				pipe_ctx->stream->
23404562236bSHarry Wentland 				public.gamut_remap_matrix.matrix[6];
23414562236bSHarry Wentland 		adjust.temperature_matrix[6] =
23424562236bSHarry Wentland 				pipe_ctx->stream->
23434562236bSHarry Wentland 				public.gamut_remap_matrix.matrix[8];
23444562236bSHarry Wentland 		adjust.temperature_matrix[7] =
23454562236bSHarry Wentland 				pipe_ctx->stream->
23464562236bSHarry Wentland 				public.gamut_remap_matrix.matrix[9];
23474562236bSHarry Wentland 		adjust.temperature_matrix[8] =
23484562236bSHarry Wentland 				pipe_ctx->stream->
23494562236bSHarry Wentland 				public.gamut_remap_matrix.matrix[10];
23504562236bSHarry Wentland 	}
23514562236bSHarry Wentland 
23524562236bSHarry Wentland 	pipe_ctx->xfm->funcs->transform_set_gamut_remap(pipe_ctx->xfm, &adjust);
23534562236bSHarry Wentland 
23544562236bSHarry Wentland 	pipe_ctx->scl_data.lb_params.alpha_en = pipe_ctx->bottom_pipe != 0;
23554562236bSHarry Wentland 	if (old_pipe && memcmp(&old_pipe->scl_data,
23564562236bSHarry Wentland 				&pipe_ctx->scl_data,
23574562236bSHarry Wentland 				sizeof(struct scaler_data)) != 0)
23584562236bSHarry Wentland 		program_scaler(dc, pipe_ctx);
23594562236bSHarry Wentland 
23604562236bSHarry Wentland 	mi->funcs->mem_input_program_surface_config(
23614562236bSHarry Wentland 			mi,
23624562236bSHarry Wentland 			surface->public.format,
23634562236bSHarry Wentland 			&surface->public.tiling_info,
23644562236bSHarry Wentland 			&surface->public.plane_size,
23654562236bSHarry Wentland 			surface->public.rotation,
2366624d7c47SYongqiang Sun 			NULL,
23674562236bSHarry Wentland 			false,
2368624d7c47SYongqiang Sun 			pipe_ctx->surface->public.visible);
23694562236bSHarry Wentland 
23704562236bSHarry Wentland 	if (dc->public.config.gpu_vm_support)
23714562236bSHarry Wentland 		mi->funcs->mem_input_program_pte_vm(
23724562236bSHarry Wentland 				pipe_ctx->mi,
23734562236bSHarry Wentland 				surface->public.format,
23744562236bSHarry Wentland 				&surface->public.tiling_info,
23754562236bSHarry Wentland 				surface->public.rotation);
23764562236bSHarry Wentland 
23774562236bSHarry Wentland 	dm_logger_write(dc->ctx->logger, LOG_SURFACE,
23784562236bSHarry Wentland 			"Pipe:%d 0x%x: addr hi:0x%x, "
23794562236bSHarry Wentland 			"addr low:0x%x, "
23804562236bSHarry Wentland 			"src: %d, %d, %d,"
23814562236bSHarry Wentland 			" %d; dst: %d, %d, %d, %d;"
23824562236bSHarry Wentland 			"clip: %d, %d, %d, %d\n",
23834562236bSHarry Wentland 			pipe_ctx->pipe_idx,
23844562236bSHarry Wentland 			pipe_ctx->surface,
23854562236bSHarry Wentland 			pipe_ctx->surface->public.address.grph.addr.high_part,
23864562236bSHarry Wentland 			pipe_ctx->surface->public.address.grph.addr.low_part,
23874562236bSHarry Wentland 			pipe_ctx->surface->public.src_rect.x,
23884562236bSHarry Wentland 			pipe_ctx->surface->public.src_rect.y,
23894562236bSHarry Wentland 			pipe_ctx->surface->public.src_rect.width,
23904562236bSHarry Wentland 			pipe_ctx->surface->public.src_rect.height,
23914562236bSHarry Wentland 			pipe_ctx->surface->public.dst_rect.x,
23924562236bSHarry Wentland 			pipe_ctx->surface->public.dst_rect.y,
23934562236bSHarry Wentland 			pipe_ctx->surface->public.dst_rect.width,
23944562236bSHarry Wentland 			pipe_ctx->surface->public.dst_rect.height,
23954562236bSHarry Wentland 			pipe_ctx->surface->public.clip_rect.x,
23964562236bSHarry Wentland 			pipe_ctx->surface->public.clip_rect.y,
23974562236bSHarry Wentland 			pipe_ctx->surface->public.clip_rect.width,
23984562236bSHarry Wentland 			pipe_ctx->surface->public.clip_rect.height);
23994562236bSHarry Wentland 
24004562236bSHarry Wentland 	dm_logger_write(dc->ctx->logger, LOG_SURFACE,
24014562236bSHarry Wentland 			"Pipe %d: width, height, x, y\n"
24024562236bSHarry Wentland 			"viewport:%d, %d, %d, %d\n"
24034562236bSHarry Wentland 			"recout:  %d, %d, %d, %d\n",
24044562236bSHarry Wentland 			pipe_ctx->pipe_idx,
24054562236bSHarry Wentland 			pipe_ctx->scl_data.viewport.width,
24064562236bSHarry Wentland 			pipe_ctx->scl_data.viewport.height,
24074562236bSHarry Wentland 			pipe_ctx->scl_data.viewport.x,
24084562236bSHarry Wentland 			pipe_ctx->scl_data.viewport.y,
24094562236bSHarry Wentland 			pipe_ctx->scl_data.recout.width,
24104562236bSHarry Wentland 			pipe_ctx->scl_data.recout.height,
24114562236bSHarry Wentland 			pipe_ctx->scl_data.recout.x,
24124562236bSHarry Wentland 			pipe_ctx->scl_data.recout.y);
24134562236bSHarry Wentland }
24144562236bSHarry Wentland 
24154562236bSHarry Wentland static void dce110_prepare_pipe_for_context(
24164562236bSHarry Wentland 		struct core_dc *dc,
24174562236bSHarry Wentland 		struct pipe_ctx *pipe_ctx,
24184562236bSHarry Wentland 		struct validate_context *context)
24194562236bSHarry Wentland {
24204562236bSHarry Wentland 	dce110_power_on_pipe_if_needed(dc, pipe_ctx, context);
2421fb735a9fSAnthony Koo 	dc->hwss.increase_watermarks_for_pipe(dc, pipe_ctx, context);
24224562236bSHarry Wentland }
24234562236bSHarry Wentland 
24244562236bSHarry Wentland static void dce110_apply_ctx_for_surface(
24254562236bSHarry Wentland 		struct core_dc *dc,
24264562236bSHarry Wentland 		struct core_surface *surface,
24274562236bSHarry Wentland 		struct validate_context *context)
24284562236bSHarry Wentland {
24294562236bSHarry Wentland 	int i;
24304562236bSHarry Wentland 
24314562236bSHarry Wentland 	/* TODO remove when removing the surface reset workaroud*/
24324562236bSHarry Wentland 	if (!surface)
24334562236bSHarry Wentland 		return;
24344562236bSHarry Wentland 
24354562236bSHarry Wentland 	for (i = 0; i < context->res_ctx.pool->pipe_count; i++) {
24364562236bSHarry Wentland 		struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
24374562236bSHarry Wentland 
24384562236bSHarry Wentland 		if (pipe_ctx->surface != surface)
24394562236bSHarry Wentland 			continue;
24404562236bSHarry Wentland 
24414562236bSHarry Wentland 		dce110_program_front_end_for_pipe(dc, pipe_ctx);
2442b06b7680SLeon Elazar 		program_surface_visibility(dc, pipe_ctx);
24434562236bSHarry Wentland 
24444562236bSHarry Wentland 	}
24454562236bSHarry Wentland }
24464562236bSHarry Wentland 
24474562236bSHarry Wentland static void dce110_power_down_fe(struct core_dc *dc, struct pipe_ctx *pipe)
24484562236bSHarry Wentland {
24494562236bSHarry Wentland 	int i;
24504562236bSHarry Wentland 
24514562236bSHarry Wentland 	for (i = 0; i < dc->res_pool->pipe_count; i++)
24524562236bSHarry Wentland 		if (&dc->current_context->res_ctx.pipe_ctx[i] == pipe)
24534562236bSHarry Wentland 			break;
24544562236bSHarry Wentland 
24554562236bSHarry Wentland 	if (i == dc->res_pool->pipe_count)
24564562236bSHarry Wentland 		return;
24574562236bSHarry Wentland 
24584562236bSHarry Wentland 	dc->hwss.enable_display_power_gating(
24594562236bSHarry Wentland 		dc, i, dc->ctx->dc_bios, PIPE_GATING_CONTROL_ENABLE);
24604562236bSHarry Wentland 	if (pipe->xfm)
24614562236bSHarry Wentland 		pipe->xfm->funcs->transform_reset(pipe->xfm);
24624562236bSHarry Wentland 	memset(&pipe->scl_data, 0, sizeof(struct scaler_data));
24634562236bSHarry Wentland }
24644562236bSHarry Wentland 
24654562236bSHarry Wentland static const struct hw_sequencer_funcs dce110_funcs = {
24664562236bSHarry Wentland 	.init_hw = init_hw,
24674562236bSHarry Wentland 	.apply_ctx_to_hw = dce110_apply_ctx_to_hw,
24684562236bSHarry Wentland 	.prepare_pipe_for_context = dce110_prepare_pipe_for_context,
24694562236bSHarry Wentland 	.apply_ctx_for_surface = dce110_apply_ctx_for_surface,
24704562236bSHarry Wentland 	.set_plane_config = set_plane_config,
24714562236bSHarry Wentland 	.update_plane_addr = update_plane_addr,
24724562236bSHarry Wentland 	.update_pending_status = dce110_update_pending_status,
2473d7194cf6SAric Cyr 	.set_input_transfer_func = dce110_set_input_transfer_func,
247490e508baSAnthony Koo 	.set_output_transfer_func = dce110_set_output_transfer_func,
24754562236bSHarry Wentland 	.power_down = dce110_power_down,
24764562236bSHarry Wentland 	.enable_accelerated_mode = dce110_enable_accelerated_mode,
24774562236bSHarry Wentland 	.enable_timing_synchronization = dce110_enable_timing_synchronization,
24784562236bSHarry Wentland 	.update_info_frame = dce110_update_info_frame,
24794562236bSHarry Wentland 	.enable_stream = dce110_enable_stream,
24804562236bSHarry Wentland 	.disable_stream = dce110_disable_stream,
24814562236bSHarry Wentland 	.unblank_stream = dce110_unblank_stream,
24824562236bSHarry Wentland 	.enable_display_pipe_clock_gating = enable_display_pipe_clock_gating,
24834562236bSHarry Wentland 	.enable_display_power_gating = dce110_enable_display_power_gating,
24844562236bSHarry Wentland 	.power_down_front_end = dce110_power_down_fe,
24854562236bSHarry Wentland 	.pipe_control_lock = dce_pipe_control_lock,
24864562236bSHarry Wentland 	.set_displaymarks = dce110_set_displaymarks,
24874562236bSHarry Wentland 	.increase_watermarks_for_pipe = dce110_increase_watermarks_for_pipe,
24884562236bSHarry Wentland 	.set_bandwidth = dce110_set_bandwidth,
24894562236bSHarry Wentland 	.set_drr = set_drr,
24904562236bSHarry Wentland 	.set_static_screen_control = set_static_screen_control,
24914562236bSHarry Wentland 	.reset_hw_ctx_wrap = reset_hw_ctx_wrap,
24924b5e7d62SHersen Wu 	.prog_pixclk_crtc_otg = dce110_prog_pixclk_crtc_otg,
24934562236bSHarry Wentland };
24944562236bSHarry Wentland 
24954562236bSHarry Wentland bool dce110_hw_sequencer_construct(struct core_dc *dc)
24964562236bSHarry Wentland {
24974562236bSHarry Wentland 	dc->hwss = dce110_funcs;
24984562236bSHarry Wentland 
24994562236bSHarry Wentland 	return true;
25004562236bSHarry Wentland }
25014562236bSHarry Wentland 
2502