14562236bSHarry Wentland /*
24562236bSHarry Wentland  * Copyright 2012-15 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 
264562236bSHarry Wentland #include "dm_services.h"
274562236bSHarry Wentland 
284562236bSHarry Wentland #include "atom.h"
294562236bSHarry Wentland 
304562236bSHarry Wentland #include "include/bios_parser_types.h"
314562236bSHarry Wentland 
324562236bSHarry Wentland #include "command_table_helper.h"
334562236bSHarry Wentland 
dal_bios_parser_init_cmd_tbl_helper(const struct command_table_helper ** h,enum dce_version dce)344562236bSHarry Wentland bool dal_bios_parser_init_cmd_tbl_helper(
354562236bSHarry Wentland 	const struct command_table_helper **h,
364562236bSHarry Wentland 	enum dce_version dce)
374562236bSHarry Wentland {
384562236bSHarry Wentland 	switch (dce) {
39c4a54f70SMauro Rossi #if defined(CONFIG_DRM_AMD_DC_SI)
40c4a54f70SMauro Rossi 	case DCE_VERSION_6_0:
41c4a54f70SMauro Rossi 	case DCE_VERSION_6_1:
42c4a54f70SMauro Rossi 	case DCE_VERSION_6_4:
43c4a54f70SMauro Rossi 		*h = dal_cmd_tbl_helper_dce60_get_table();
44c4a54f70SMauro Rossi 		return true;
45c4a54f70SMauro Rossi #endif
46c4a54f70SMauro Rossi 
474562236bSHarry Wentland 	case DCE_VERSION_8_0:
48ebfdf0d0SAlex Deucher 	case DCE_VERSION_8_1:
49ebfdf0d0SAlex Deucher 	case DCE_VERSION_8_3:
504562236bSHarry Wentland 		*h = dal_cmd_tbl_helper_dce80_get_table();
514562236bSHarry Wentland 		return true;
524562236bSHarry Wentland 
534562236bSHarry Wentland 	case DCE_VERSION_10_0:
544562236bSHarry Wentland 		*h = dal_cmd_tbl_helper_dce110_get_table();
554562236bSHarry Wentland 		return true;
564562236bSHarry Wentland 
574562236bSHarry Wentland 	case DCE_VERSION_11_0:
584562236bSHarry Wentland 		*h = dal_cmd_tbl_helper_dce110_get_table();
594562236bSHarry Wentland 		return true;
604562236bSHarry Wentland 
614562236bSHarry Wentland 	case DCE_VERSION_11_2:
620c75d5acSJerry (Fangzhi) Zuo 	case DCE_VERSION_11_22:
634562236bSHarry Wentland 		*h = dal_cmd_tbl_helper_dce112_get_table();
644562236bSHarry Wentland 		return true;
654562236bSHarry Wentland 
664562236bSHarry Wentland 	default:
674562236bSHarry Wentland 		/* Unsupported DCE */
684562236bSHarry Wentland 		BREAK_TO_DEBUGGER();
694562236bSHarry Wentland 		return false;
704562236bSHarry Wentland 	}
714562236bSHarry Wentland }
724562236bSHarry Wentland 
734562236bSHarry Wentland /* real implementations */
744562236bSHarry Wentland 
dal_cmd_table_helper_controller_id_to_atom(enum controller_id id,uint8_t * atom_id)754562236bSHarry Wentland bool dal_cmd_table_helper_controller_id_to_atom(
764562236bSHarry Wentland 	enum controller_id id,
774562236bSHarry Wentland 	uint8_t *atom_id)
784562236bSHarry Wentland {
794562236bSHarry Wentland 	if (atom_id == NULL) {
804562236bSHarry Wentland 		BREAK_TO_DEBUGGER();
814562236bSHarry Wentland 		return false;
824562236bSHarry Wentland 	}
834562236bSHarry Wentland 
844562236bSHarry Wentland 	switch (id) {
854562236bSHarry Wentland 	case CONTROLLER_ID_D0:
864562236bSHarry Wentland 		*atom_id = ATOM_CRTC1;
874562236bSHarry Wentland 		return true;
884562236bSHarry Wentland 	case CONTROLLER_ID_D1:
894562236bSHarry Wentland 		*atom_id = ATOM_CRTC2;
904562236bSHarry Wentland 		return true;
914562236bSHarry Wentland 	case CONTROLLER_ID_D2:
924562236bSHarry Wentland 		*atom_id = ATOM_CRTC3;
934562236bSHarry Wentland 		return true;
944562236bSHarry Wentland 	case CONTROLLER_ID_D3:
954562236bSHarry Wentland 		*atom_id = ATOM_CRTC4;
964562236bSHarry Wentland 		return true;
974562236bSHarry Wentland 	case CONTROLLER_ID_D4:
984562236bSHarry Wentland 		*atom_id = ATOM_CRTC5;
994562236bSHarry Wentland 		return true;
1004562236bSHarry Wentland 	case CONTROLLER_ID_D5:
1014562236bSHarry Wentland 		*atom_id = ATOM_CRTC6;
1024562236bSHarry Wentland 		return true;
1034562236bSHarry Wentland 	case CONTROLLER_ID_UNDERLAY0:
1044562236bSHarry Wentland 		*atom_id = ATOM_UNDERLAY_PIPE0;
1054562236bSHarry Wentland 		return true;
1064562236bSHarry Wentland 	case CONTROLLER_ID_UNDEFINED:
1074562236bSHarry Wentland 		*atom_id = ATOM_CRTC_INVALID;
1084562236bSHarry Wentland 		return true;
1094562236bSHarry Wentland 	default:
1104562236bSHarry Wentland 		/* Wrong controller id */
1114562236bSHarry Wentland 		BREAK_TO_DEBUGGER();
1124562236bSHarry Wentland 		return false;
1134562236bSHarry Wentland 	}
1144562236bSHarry Wentland }
1154562236bSHarry Wentland 
1164562236bSHarry Wentland /**
117*920e2f5aSLee Jones  * dal_cmd_table_helper_transmitter_bp_to_atom - Translate the Transmitter to the
1184646c42dSLee Jones  *                                    corresponding ATOM BIOS value
1194646c42dSLee Jones  * @t: transmitter
1204646c42dSLee Jones  * returns: output digitalTransmitter
1214562236bSHarry Wentland  *    // =00: Digital Transmitter1 ( UNIPHY linkAB )
1224562236bSHarry Wentland  *    // =01: Digital Transmitter2 ( UNIPHY linkCD )
1234562236bSHarry Wentland  *    // =02: Digital Transmitter3 ( UNIPHY linkEF )
1244562236bSHarry Wentland  */
dal_cmd_table_helper_transmitter_bp_to_atom(enum transmitter t)1254562236bSHarry Wentland uint8_t dal_cmd_table_helper_transmitter_bp_to_atom(
1264562236bSHarry Wentland 	enum transmitter t)
1274562236bSHarry Wentland {
1284562236bSHarry Wentland 	switch (t) {
1294562236bSHarry Wentland 	case TRANSMITTER_UNIPHY_A:
1304562236bSHarry Wentland 	case TRANSMITTER_UNIPHY_B:
1314562236bSHarry Wentland 	case TRANSMITTER_TRAVIS_LCD:
1324562236bSHarry Wentland 		return 0;
1334562236bSHarry Wentland 	case TRANSMITTER_UNIPHY_C:
1344562236bSHarry Wentland 	case TRANSMITTER_UNIPHY_D:
1354562236bSHarry Wentland 		return 1;
1364562236bSHarry Wentland 	case TRANSMITTER_UNIPHY_E:
1374562236bSHarry Wentland 	case TRANSMITTER_UNIPHY_F:
1384562236bSHarry Wentland 		return 2;
1394562236bSHarry Wentland 	default:
1404562236bSHarry Wentland 		/* Invalid Transmitter Type! */
1414562236bSHarry Wentland 		BREAK_TO_DEBUGGER();
1424562236bSHarry Wentland 		return 0;
1434562236bSHarry Wentland 	}
1444562236bSHarry Wentland }
1454562236bSHarry Wentland 
dal_cmd_table_helper_encoder_mode_bp_to_atom(enum signal_type s,bool enable_dp_audio)1464562236bSHarry Wentland uint32_t dal_cmd_table_helper_encoder_mode_bp_to_atom(
1474562236bSHarry Wentland 	enum signal_type s,
1484562236bSHarry Wentland 	bool enable_dp_audio)
1494562236bSHarry Wentland {
1504562236bSHarry Wentland 	switch (s) {
1514562236bSHarry Wentland 	case SIGNAL_TYPE_DVI_SINGLE_LINK:
1524562236bSHarry Wentland 	case SIGNAL_TYPE_DVI_DUAL_LINK:
1534562236bSHarry Wentland 		return ATOM_ENCODER_MODE_DVI;
1544562236bSHarry Wentland 	case SIGNAL_TYPE_HDMI_TYPE_A:
1554562236bSHarry Wentland 		return ATOM_ENCODER_MODE_HDMI;
1564562236bSHarry Wentland 	case SIGNAL_TYPE_LVDS:
1574562236bSHarry Wentland 		return ATOM_ENCODER_MODE_LVDS;
1584562236bSHarry Wentland 	case SIGNAL_TYPE_EDP:
1594562236bSHarry Wentland 	case SIGNAL_TYPE_DISPLAY_PORT_MST:
1604562236bSHarry Wentland 	case SIGNAL_TYPE_DISPLAY_PORT:
1614562236bSHarry Wentland 	case SIGNAL_TYPE_VIRTUAL:
1624562236bSHarry Wentland 		if (enable_dp_audio)
1634562236bSHarry Wentland 			return ATOM_ENCODER_MODE_DP_AUDIO;
1644562236bSHarry Wentland 		else
1654562236bSHarry Wentland 			return ATOM_ENCODER_MODE_DP;
1664562236bSHarry Wentland 	case SIGNAL_TYPE_RGB:
1674562236bSHarry Wentland 		return ATOM_ENCODER_MODE_CRT;
1684562236bSHarry Wentland 	default:
1694562236bSHarry Wentland 		return ATOM_ENCODER_MODE_CRT;
1704562236bSHarry Wentland 	}
1714562236bSHarry Wentland }
1724562236bSHarry Wentland 
dal_cmd_table_helper_assign_control_parameter(const struct command_table_helper * h,struct bp_encoder_control * control,DIG_ENCODER_CONTROL_PARAMETERS_V2 * ctrl_param)1734562236bSHarry Wentland void dal_cmd_table_helper_assign_control_parameter(
1744562236bSHarry Wentland 	const struct command_table_helper *h,
1754562236bSHarry Wentland 	struct bp_encoder_control *control,
1764562236bSHarry Wentland 	DIG_ENCODER_CONTROL_PARAMETERS_V2 *ctrl_param)
1774562236bSHarry Wentland {
1784562236bSHarry Wentland 	/* there are three transmitter blocks, each one has two links 4-lanes
1794562236bSHarry Wentland 	 * each, A+B, C+D, E+F, Uniphy A, C and E are enumerated as link 0 in
1804562236bSHarry Wentland 	 * each transmitter block B, D and F as link 1, third transmitter block
1814562236bSHarry Wentland 	 * has non splitable links (UniphyE and UniphyF can not be configured
1824562236bSHarry Wentland 	 * separately to drive two different streams)
1834562236bSHarry Wentland 	 */
1844562236bSHarry Wentland 	if ((control->transmitter == TRANSMITTER_UNIPHY_B) ||
1854562236bSHarry Wentland 		(control->transmitter == TRANSMITTER_UNIPHY_D) ||
1864562236bSHarry Wentland 		(control->transmitter == TRANSMITTER_UNIPHY_F)) {
1874562236bSHarry Wentland 		/* Bit2: Link Select
1884562236bSHarry Wentland 		 * =0: PHY linkA/C/E
1894562236bSHarry Wentland 		 * =1: PHY linkB/D/F
1904562236bSHarry Wentland 		 */
1914562236bSHarry Wentland 		ctrl_param->acConfig.ucLinkSel = 1;
1924562236bSHarry Wentland 	}
1934562236bSHarry Wentland 
1944562236bSHarry Wentland 	/* Bit[4:3]: Transmitter Selection
1954562236bSHarry Wentland 	 * =00: Digital Transmitter1 ( UNIPHY linkAB )
1964562236bSHarry Wentland 	 * =01: Digital Transmitter2 ( UNIPHY linkCD )
1974562236bSHarry Wentland 	 * =02: Digital Transmitter3 ( UNIPHY linkEF )
1984562236bSHarry Wentland 	 * =03: Reserved
1994562236bSHarry Wentland 	 */
2004562236bSHarry Wentland 	ctrl_param->acConfig.ucTransmitterSel =
2014562236bSHarry Wentland 		(uint8_t)(h->transmitter_bp_to_atom(control->transmitter));
2024562236bSHarry Wentland 
2034562236bSHarry Wentland 	/* We need to convert from KHz units into 10KHz units */
2044562236bSHarry Wentland 	ctrl_param->ucAction = h->encoder_action_to_atom(control->action);
2054562236bSHarry Wentland 	ctrl_param->usPixelClock = cpu_to_le16((uint16_t)(control->pixel_clock / 10));
2064562236bSHarry Wentland 	ctrl_param->ucEncoderMode =
2074562236bSHarry Wentland 		(uint8_t)(h->encoder_mode_bp_to_atom(
2084562236bSHarry Wentland 			control->signal, control->enable_dp_audio));
2094562236bSHarry Wentland 	ctrl_param->ucLaneNum = (uint8_t)(control->lanes_number);
2104562236bSHarry Wentland }
2114562236bSHarry Wentland 
dal_cmd_table_helper_clock_source_id_to_ref_clk_src(enum clock_source_id id,uint32_t * ref_clk_src_id)2124562236bSHarry Wentland bool dal_cmd_table_helper_clock_source_id_to_ref_clk_src(
2134562236bSHarry Wentland 	enum clock_source_id id,
2144562236bSHarry Wentland 	uint32_t *ref_clk_src_id)
2154562236bSHarry Wentland {
2164562236bSHarry Wentland 	if (ref_clk_src_id == NULL) {
2174562236bSHarry Wentland 		BREAK_TO_DEBUGGER();
2184562236bSHarry Wentland 		return false;
2194562236bSHarry Wentland 	}
2204562236bSHarry Wentland 
2214562236bSHarry Wentland 	switch (id) {
2224562236bSHarry Wentland 	case CLOCK_SOURCE_ID_PLL1:
2234562236bSHarry Wentland 		*ref_clk_src_id = ENCODER_REFCLK_SRC_P1PLL;
2244562236bSHarry Wentland 		return true;
2254562236bSHarry Wentland 	case CLOCK_SOURCE_ID_PLL2:
2264562236bSHarry Wentland 		*ref_clk_src_id = ENCODER_REFCLK_SRC_P2PLL;
2274562236bSHarry Wentland 		return true;
2284562236bSHarry Wentland 	case CLOCK_SOURCE_ID_DCPLL:
2294562236bSHarry Wentland 		*ref_clk_src_id = ENCODER_REFCLK_SRC_DCPLL;
2304562236bSHarry Wentland 		return true;
2314562236bSHarry Wentland 	case CLOCK_SOURCE_ID_EXTERNAL:
2324562236bSHarry Wentland 		*ref_clk_src_id = ENCODER_REFCLK_SRC_EXTCLK;
2334562236bSHarry Wentland 		return true;
2344562236bSHarry Wentland 	case CLOCK_SOURCE_ID_UNDEFINED:
2354562236bSHarry Wentland 		*ref_clk_src_id = ENCODER_REFCLK_SRC_INVALID;
2364562236bSHarry Wentland 		return true;
2374562236bSHarry Wentland 	default:
2384562236bSHarry Wentland 		/* Unsupported clock source id */
2394562236bSHarry Wentland 		BREAK_TO_DEBUGGER();
2404562236bSHarry Wentland 		return false;
2414562236bSHarry Wentland 	}
2424562236bSHarry Wentland }
2434562236bSHarry Wentland 
dal_cmd_table_helper_encoder_id_to_atom(enum encoder_id id)2444562236bSHarry Wentland uint8_t dal_cmd_table_helper_encoder_id_to_atom(
2454562236bSHarry Wentland 	enum encoder_id id)
2464562236bSHarry Wentland {
2474562236bSHarry Wentland 	switch (id) {
2484562236bSHarry Wentland 	case ENCODER_ID_INTERNAL_LVDS:
2494562236bSHarry Wentland 		return ENCODER_OBJECT_ID_INTERNAL_LVDS;
2504562236bSHarry Wentland 	case ENCODER_ID_INTERNAL_TMDS1:
2514562236bSHarry Wentland 		return ENCODER_OBJECT_ID_INTERNAL_TMDS1;
2524562236bSHarry Wentland 	case ENCODER_ID_INTERNAL_TMDS2:
2534562236bSHarry Wentland 		return ENCODER_OBJECT_ID_INTERNAL_TMDS2;
2544562236bSHarry Wentland 	case ENCODER_ID_INTERNAL_DAC1:
2554562236bSHarry Wentland 		return ENCODER_OBJECT_ID_INTERNAL_DAC1;
2564562236bSHarry Wentland 	case ENCODER_ID_INTERNAL_DAC2:
2574562236bSHarry Wentland 		return ENCODER_OBJECT_ID_INTERNAL_DAC2;
2584562236bSHarry Wentland 	case ENCODER_ID_INTERNAL_LVTM1:
2594562236bSHarry Wentland 		return ENCODER_OBJECT_ID_INTERNAL_LVTM1;
2604562236bSHarry Wentland 	case ENCODER_ID_INTERNAL_HDMI:
2614562236bSHarry Wentland 		return ENCODER_OBJECT_ID_HDMI_INTERNAL;
2624562236bSHarry Wentland 	case ENCODER_ID_EXTERNAL_TRAVIS:
2634562236bSHarry Wentland 		return ENCODER_OBJECT_ID_TRAVIS;
2644562236bSHarry Wentland 	case ENCODER_ID_EXTERNAL_NUTMEG:
2654562236bSHarry Wentland 		return ENCODER_OBJECT_ID_NUTMEG;
2664562236bSHarry Wentland 	case ENCODER_ID_INTERNAL_KLDSCP_TMDS1:
2674562236bSHarry Wentland 		return ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1;
2684562236bSHarry Wentland 	case ENCODER_ID_INTERNAL_KLDSCP_DAC1:
2694562236bSHarry Wentland 		return ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1;
2704562236bSHarry Wentland 	case ENCODER_ID_INTERNAL_KLDSCP_DAC2:
2714562236bSHarry Wentland 		return ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2;
2724562236bSHarry Wentland 	case ENCODER_ID_EXTERNAL_MVPU_FPGA:
2734562236bSHarry Wentland 		return ENCODER_OBJECT_ID_MVPU_FPGA;
2744562236bSHarry Wentland 	case ENCODER_ID_INTERNAL_DDI:
2754562236bSHarry Wentland 		return ENCODER_OBJECT_ID_INTERNAL_DDI;
2764562236bSHarry Wentland 	case ENCODER_ID_INTERNAL_UNIPHY:
2774562236bSHarry Wentland 		return ENCODER_OBJECT_ID_INTERNAL_UNIPHY;
2784562236bSHarry Wentland 	case ENCODER_ID_INTERNAL_KLDSCP_LVTMA:
2794562236bSHarry Wentland 		return ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA;
2804562236bSHarry Wentland 	case ENCODER_ID_INTERNAL_UNIPHY1:
2814562236bSHarry Wentland 		return ENCODER_OBJECT_ID_INTERNAL_UNIPHY1;
2824562236bSHarry Wentland 	case ENCODER_ID_INTERNAL_UNIPHY2:
2834562236bSHarry Wentland 		return ENCODER_OBJECT_ID_INTERNAL_UNIPHY2;
2844562236bSHarry Wentland 	case ENCODER_ID_INTERNAL_UNIPHY3:
2854562236bSHarry Wentland 		return ENCODER_OBJECT_ID_INTERNAL_UNIPHY3;
2864562236bSHarry Wentland 	case ENCODER_ID_INTERNAL_WIRELESS:
2874562236bSHarry Wentland 		return ENCODER_OBJECT_ID_INTERNAL_VCE;
2884562236bSHarry Wentland 	case ENCODER_ID_UNKNOWN:
2894562236bSHarry Wentland 		return ENCODER_OBJECT_ID_NONE;
2904562236bSHarry Wentland 	default:
2914562236bSHarry Wentland 		/* Invalid encoder id */
2924562236bSHarry Wentland 		BREAK_TO_DEBUGGER();
2934562236bSHarry Wentland 		return ENCODER_OBJECT_ID_NONE;
2944562236bSHarry Wentland 	}
2954562236bSHarry Wentland }
296