xref: /dflybsd-src/sys/dev/drm/amd/display/dc/bios/command_table_helper2.c (revision b843c749addef9340ee7d4e250b09fdd492602a1)
1*b843c749SSergey Zigachev /*
2*b843c749SSergey Zigachev  * Copyright 2012-15 Advanced Micro Devices, Inc.
3*b843c749SSergey Zigachev  *
4*b843c749SSergey Zigachev  * Permission is hereby granted, free of charge, to any person obtaining a
5*b843c749SSergey Zigachev  * copy of this software and associated documentation files (the "Software"),
6*b843c749SSergey Zigachev  * to deal in the Software without restriction, including without limitation
7*b843c749SSergey Zigachev  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*b843c749SSergey Zigachev  * and/or sell copies of the Software, and to permit persons to whom the
9*b843c749SSergey Zigachev  * Software is furnished to do so, subject to the following conditions:
10*b843c749SSergey Zigachev  *
11*b843c749SSergey Zigachev  * The above copyright notice and this permission notice shall be included in
12*b843c749SSergey Zigachev  * all copies or substantial portions of the Software.
13*b843c749SSergey Zigachev  *
14*b843c749SSergey Zigachev  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15*b843c749SSergey Zigachev  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16*b843c749SSergey Zigachev  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17*b843c749SSergey Zigachev  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18*b843c749SSergey Zigachev  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19*b843c749SSergey Zigachev  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20*b843c749SSergey Zigachev  * OTHER DEALINGS IN THE SOFTWARE.
21*b843c749SSergey Zigachev  *
22*b843c749SSergey Zigachev  * Authors: AMD
23*b843c749SSergey Zigachev  *
24*b843c749SSergey Zigachev  */
25*b843c749SSergey Zigachev 
26*b843c749SSergey Zigachev #include "dm_services.h"
27*b843c749SSergey Zigachev 
28*b843c749SSergey Zigachev #include "ObjectID.h"
29*b843c749SSergey Zigachev #include "atomfirmware.h"
30*b843c749SSergey Zigachev 
31*b843c749SSergey Zigachev #include "include/bios_parser_types.h"
32*b843c749SSergey Zigachev 
33*b843c749SSergey Zigachev #include "command_table_helper2.h"
34*b843c749SSergey Zigachev 
dal_bios_parser_init_cmd_tbl_helper2(const struct command_table_helper ** h,enum dce_version dce)35*b843c749SSergey Zigachev bool dal_bios_parser_init_cmd_tbl_helper2(
36*b843c749SSergey Zigachev 	const struct command_table_helper **h,
37*b843c749SSergey Zigachev 	enum dce_version dce)
38*b843c749SSergey Zigachev {
39*b843c749SSergey Zigachev 	switch (dce) {
40*b843c749SSergey Zigachev 	case DCE_VERSION_8_0:
41*b843c749SSergey Zigachev 	case DCE_VERSION_8_1:
42*b843c749SSergey Zigachev 	case DCE_VERSION_8_3:
43*b843c749SSergey Zigachev 		*h = dal_cmd_tbl_helper_dce80_get_table();
44*b843c749SSergey Zigachev 		return true;
45*b843c749SSergey Zigachev 
46*b843c749SSergey Zigachev 	case DCE_VERSION_10_0:
47*b843c749SSergey Zigachev 		*h = dal_cmd_tbl_helper_dce110_get_table();
48*b843c749SSergey Zigachev 		return true;
49*b843c749SSergey Zigachev 
50*b843c749SSergey Zigachev 	case DCE_VERSION_11_0:
51*b843c749SSergey Zigachev 		*h = dal_cmd_tbl_helper_dce110_get_table();
52*b843c749SSergey Zigachev 		return true;
53*b843c749SSergey Zigachev 
54*b843c749SSergey Zigachev 	case DCE_VERSION_11_2:
55*b843c749SSergey Zigachev 	case DCE_VERSION_11_22:
56*b843c749SSergey Zigachev 		*h = dal_cmd_tbl_helper_dce112_get_table2();
57*b843c749SSergey Zigachev 		return true;
58*b843c749SSergey Zigachev #if defined(CONFIG_DRM_AMD_DC_DCN1_0)
59*b843c749SSergey Zigachev 	case DCN_VERSION_1_0:
60*b843c749SSergey Zigachev 		*h = dal_cmd_tbl_helper_dce112_get_table2();
61*b843c749SSergey Zigachev 		return true;
62*b843c749SSergey Zigachev #endif
63*b843c749SSergey Zigachev 
64*b843c749SSergey Zigachev 	case DCE_VERSION_12_0:
65*b843c749SSergey Zigachev 		*h = dal_cmd_tbl_helper_dce112_get_table2();
66*b843c749SSergey Zigachev 		return true;
67*b843c749SSergey Zigachev 
68*b843c749SSergey Zigachev 	default:
69*b843c749SSergey Zigachev 		/* Unsupported DCE */
70*b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER();
71*b843c749SSergey Zigachev 		return false;
72*b843c749SSergey Zigachev 	}
73*b843c749SSergey Zigachev }
74*b843c749SSergey Zigachev 
75*b843c749SSergey Zigachev /* real implementations */
76*b843c749SSergey Zigachev 
dal_cmd_table_helper_controller_id_to_atom2(enum controller_id id,uint8_t * atom_id)77*b843c749SSergey Zigachev bool dal_cmd_table_helper_controller_id_to_atom2(
78*b843c749SSergey Zigachev 	enum controller_id id,
79*b843c749SSergey Zigachev 	uint8_t *atom_id)
80*b843c749SSergey Zigachev {
81*b843c749SSergey Zigachev 	if (atom_id == NULL) {
82*b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER();
83*b843c749SSergey Zigachev 		return false;
84*b843c749SSergey Zigachev 	}
85*b843c749SSergey Zigachev 
86*b843c749SSergey Zigachev 	switch (id) {
87*b843c749SSergey Zigachev 	case CONTROLLER_ID_D0:
88*b843c749SSergey Zigachev 		*atom_id = ATOM_CRTC1;
89*b843c749SSergey Zigachev 		return true;
90*b843c749SSergey Zigachev 	case CONTROLLER_ID_D1:
91*b843c749SSergey Zigachev 		*atom_id = ATOM_CRTC2;
92*b843c749SSergey Zigachev 		return true;
93*b843c749SSergey Zigachev 	case CONTROLLER_ID_D2:
94*b843c749SSergey Zigachev 		*atom_id = ATOM_CRTC3;
95*b843c749SSergey Zigachev 		return true;
96*b843c749SSergey Zigachev 	case CONTROLLER_ID_D3:
97*b843c749SSergey Zigachev 		*atom_id = ATOM_CRTC4;
98*b843c749SSergey Zigachev 		return true;
99*b843c749SSergey Zigachev 	case CONTROLLER_ID_D4:
100*b843c749SSergey Zigachev 		*atom_id = ATOM_CRTC5;
101*b843c749SSergey Zigachev 		return true;
102*b843c749SSergey Zigachev 	case CONTROLLER_ID_D5:
103*b843c749SSergey Zigachev 		*atom_id = ATOM_CRTC6;
104*b843c749SSergey Zigachev 		return true;
105*b843c749SSergey Zigachev 	/* TODO :case CONTROLLER_ID_UNDERLAY0:
106*b843c749SSergey Zigachev 		*atom_id = ATOM_UNDERLAY_PIPE0;
107*b843c749SSergey Zigachev 		return true;
108*b843c749SSergey Zigachev 	*/
109*b843c749SSergey Zigachev 	case CONTROLLER_ID_UNDEFINED:
110*b843c749SSergey Zigachev 		*atom_id = ATOM_CRTC_INVALID;
111*b843c749SSergey Zigachev 		return true;
112*b843c749SSergey Zigachev 	default:
113*b843c749SSergey Zigachev 		/* Wrong controller id */
114*b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER();
115*b843c749SSergey Zigachev 		return false;
116*b843c749SSergey Zigachev 	}
117*b843c749SSergey Zigachev }
118*b843c749SSergey Zigachev 
119*b843c749SSergey Zigachev /**
120*b843c749SSergey Zigachev * translate_transmitter_bp_to_atom
121*b843c749SSergey Zigachev *
122*b843c749SSergey Zigachev * @brief
123*b843c749SSergey Zigachev *  Translate the Transmitter to the corresponding ATOM BIOS value
124*b843c749SSergey Zigachev *
125*b843c749SSergey Zigachev * @param
126*b843c749SSergey Zigachev *   input transmitter
127*b843c749SSergey Zigachev *   output digitalTransmitter
128*b843c749SSergey Zigachev *    // =00: Digital Transmitter1 ( UNIPHY linkAB )
129*b843c749SSergey Zigachev *    // =01: Digital Transmitter2 ( UNIPHY linkCD )
130*b843c749SSergey Zigachev *    // =02: Digital Transmitter3 ( UNIPHY linkEF )
131*b843c749SSergey Zigachev */
dal_cmd_table_helper_transmitter_bp_to_atom2(enum transmitter t)132*b843c749SSergey Zigachev uint8_t dal_cmd_table_helper_transmitter_bp_to_atom2(
133*b843c749SSergey Zigachev 	enum transmitter t)
134*b843c749SSergey Zigachev {
135*b843c749SSergey Zigachev 	switch (t) {
136*b843c749SSergey Zigachev 	case TRANSMITTER_UNIPHY_A:
137*b843c749SSergey Zigachev 	case TRANSMITTER_UNIPHY_B:
138*b843c749SSergey Zigachev 	case TRANSMITTER_TRAVIS_LCD:
139*b843c749SSergey Zigachev 		return 0;
140*b843c749SSergey Zigachev 	case TRANSMITTER_UNIPHY_C:
141*b843c749SSergey Zigachev 	case TRANSMITTER_UNIPHY_D:
142*b843c749SSergey Zigachev 		return 1;
143*b843c749SSergey Zigachev 	case TRANSMITTER_UNIPHY_E:
144*b843c749SSergey Zigachev 	case TRANSMITTER_UNIPHY_F:
145*b843c749SSergey Zigachev 		return 2;
146*b843c749SSergey Zigachev 	default:
147*b843c749SSergey Zigachev 		/* Invalid Transmitter Type! */
148*b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER();
149*b843c749SSergey Zigachev 		return 0;
150*b843c749SSergey Zigachev 	}
151*b843c749SSergey Zigachev }
152*b843c749SSergey Zigachev 
dal_cmd_table_helper_encoder_mode_bp_to_atom2(enum signal_type s,bool enable_dp_audio)153*b843c749SSergey Zigachev uint32_t dal_cmd_table_helper_encoder_mode_bp_to_atom2(
154*b843c749SSergey Zigachev 	enum signal_type s,
155*b843c749SSergey Zigachev 	bool enable_dp_audio)
156*b843c749SSergey Zigachev {
157*b843c749SSergey Zigachev 	switch (s) {
158*b843c749SSergey Zigachev 	case SIGNAL_TYPE_DVI_SINGLE_LINK:
159*b843c749SSergey Zigachev 	case SIGNAL_TYPE_DVI_DUAL_LINK:
160*b843c749SSergey Zigachev 		return ATOM_ENCODER_MODE_DVI;
161*b843c749SSergey Zigachev 	case SIGNAL_TYPE_HDMI_TYPE_A:
162*b843c749SSergey Zigachev 		return ATOM_ENCODER_MODE_HDMI;
163*b843c749SSergey Zigachev 	case SIGNAL_TYPE_LVDS:
164*b843c749SSergey Zigachev 		return ATOM_ENCODER_MODE_LVDS;
165*b843c749SSergey Zigachev 	case SIGNAL_TYPE_EDP:
166*b843c749SSergey Zigachev 	case SIGNAL_TYPE_DISPLAY_PORT_MST:
167*b843c749SSergey Zigachev 	case SIGNAL_TYPE_DISPLAY_PORT:
168*b843c749SSergey Zigachev 	case SIGNAL_TYPE_VIRTUAL:
169*b843c749SSergey Zigachev 		if (enable_dp_audio)
170*b843c749SSergey Zigachev 			return ATOM_ENCODER_MODE_DP_AUDIO;
171*b843c749SSergey Zigachev 		else
172*b843c749SSergey Zigachev 			return ATOM_ENCODER_MODE_DP;
173*b843c749SSergey Zigachev 	case SIGNAL_TYPE_RGB:
174*b843c749SSergey Zigachev 		return ATOM_ENCODER_MODE_CRT;
175*b843c749SSergey Zigachev 	default:
176*b843c749SSergey Zigachev 		return ATOM_ENCODER_MODE_CRT;
177*b843c749SSergey Zigachev 	}
178*b843c749SSergey Zigachev }
179*b843c749SSergey Zigachev 
dal_cmd_table_helper_clock_source_id_to_ref_clk_src2(enum clock_source_id id,uint32_t * ref_clk_src_id)180*b843c749SSergey Zigachev bool dal_cmd_table_helper_clock_source_id_to_ref_clk_src2(
181*b843c749SSergey Zigachev 	enum clock_source_id id,
182*b843c749SSergey Zigachev 	uint32_t *ref_clk_src_id)
183*b843c749SSergey Zigachev {
184*b843c749SSergey Zigachev 	if (ref_clk_src_id == NULL) {
185*b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER();
186*b843c749SSergey Zigachev 		return false;
187*b843c749SSergey Zigachev 	}
188*b843c749SSergey Zigachev 
189*b843c749SSergey Zigachev 	switch (id) {
190*b843c749SSergey Zigachev 	case CLOCK_SOURCE_ID_PLL1:
191*b843c749SSergey Zigachev 		*ref_clk_src_id = ENCODER_REFCLK_SRC_P1PLL;
192*b843c749SSergey Zigachev 		return true;
193*b843c749SSergey Zigachev 	case CLOCK_SOURCE_ID_PLL2:
194*b843c749SSergey Zigachev 		*ref_clk_src_id = ENCODER_REFCLK_SRC_P2PLL;
195*b843c749SSergey Zigachev 		return true;
196*b843c749SSergey Zigachev 	/*TODO:case CLOCK_SOURCE_ID_DCPLL:
197*b843c749SSergey Zigachev 		*ref_clk_src_id = ENCODER_REFCLK_SRC_DCPLL;
198*b843c749SSergey Zigachev 		return true;
199*b843c749SSergey Zigachev 	*/
200*b843c749SSergey Zigachev 	case CLOCK_SOURCE_ID_EXTERNAL:
201*b843c749SSergey Zigachev 		*ref_clk_src_id = ENCODER_REFCLK_SRC_EXTCLK;
202*b843c749SSergey Zigachev 		return true;
203*b843c749SSergey Zigachev 	case CLOCK_SOURCE_ID_UNDEFINED:
204*b843c749SSergey Zigachev 		*ref_clk_src_id = ENCODER_REFCLK_SRC_INVALID;
205*b843c749SSergey Zigachev 		return true;
206*b843c749SSergey Zigachev 	default:
207*b843c749SSergey Zigachev 		/* Unsupported clock source id */
208*b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER();
209*b843c749SSergey Zigachev 		return false;
210*b843c749SSergey Zigachev 	}
211*b843c749SSergey Zigachev }
212*b843c749SSergey Zigachev 
dal_cmd_table_helper_encoder_id_to_atom2(enum encoder_id id)213*b843c749SSergey Zigachev uint8_t dal_cmd_table_helper_encoder_id_to_atom2(
214*b843c749SSergey Zigachev 	enum encoder_id id)
215*b843c749SSergey Zigachev {
216*b843c749SSergey Zigachev 	switch (id) {
217*b843c749SSergey Zigachev 	case ENCODER_ID_INTERNAL_LVDS:
218*b843c749SSergey Zigachev 		return ENCODER_OBJECT_ID_INTERNAL_LVDS;
219*b843c749SSergey Zigachev 	case ENCODER_ID_INTERNAL_TMDS1:
220*b843c749SSergey Zigachev 		return ENCODER_OBJECT_ID_INTERNAL_TMDS1;
221*b843c749SSergey Zigachev 	case ENCODER_ID_INTERNAL_TMDS2:
222*b843c749SSergey Zigachev 		return ENCODER_OBJECT_ID_INTERNAL_TMDS2;
223*b843c749SSergey Zigachev 	case ENCODER_ID_INTERNAL_DAC1:
224*b843c749SSergey Zigachev 		return ENCODER_OBJECT_ID_INTERNAL_DAC1;
225*b843c749SSergey Zigachev 	case ENCODER_ID_INTERNAL_DAC2:
226*b843c749SSergey Zigachev 		return ENCODER_OBJECT_ID_INTERNAL_DAC2;
227*b843c749SSergey Zigachev 	case ENCODER_ID_INTERNAL_LVTM1:
228*b843c749SSergey Zigachev 		return ENCODER_OBJECT_ID_INTERNAL_LVTM1;
229*b843c749SSergey Zigachev 	case ENCODER_ID_INTERNAL_HDMI:
230*b843c749SSergey Zigachev 		return ENCODER_OBJECT_ID_HDMI_INTERNAL;
231*b843c749SSergey Zigachev 	case ENCODER_ID_EXTERNAL_TRAVIS:
232*b843c749SSergey Zigachev 		return ENCODER_OBJECT_ID_TRAVIS;
233*b843c749SSergey Zigachev 	case ENCODER_ID_EXTERNAL_NUTMEG:
234*b843c749SSergey Zigachev 		return ENCODER_OBJECT_ID_NUTMEG;
235*b843c749SSergey Zigachev 	case ENCODER_ID_INTERNAL_KLDSCP_TMDS1:
236*b843c749SSergey Zigachev 		return ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1;
237*b843c749SSergey Zigachev 	case ENCODER_ID_INTERNAL_KLDSCP_DAC1:
238*b843c749SSergey Zigachev 		return ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1;
239*b843c749SSergey Zigachev 	case ENCODER_ID_INTERNAL_KLDSCP_DAC2:
240*b843c749SSergey Zigachev 		return ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2;
241*b843c749SSergey Zigachev 	case ENCODER_ID_EXTERNAL_MVPU_FPGA:
242*b843c749SSergey Zigachev 		return ENCODER_OBJECT_ID_MVPU_FPGA;
243*b843c749SSergey Zigachev 	case ENCODER_ID_INTERNAL_DDI:
244*b843c749SSergey Zigachev 		return ENCODER_OBJECT_ID_INTERNAL_DDI;
245*b843c749SSergey Zigachev 	case ENCODER_ID_INTERNAL_UNIPHY:
246*b843c749SSergey Zigachev 		return ENCODER_OBJECT_ID_INTERNAL_UNIPHY;
247*b843c749SSergey Zigachev 	case ENCODER_ID_INTERNAL_KLDSCP_LVTMA:
248*b843c749SSergey Zigachev 		return ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA;
249*b843c749SSergey Zigachev 	case ENCODER_ID_INTERNAL_UNIPHY1:
250*b843c749SSergey Zigachev 		return ENCODER_OBJECT_ID_INTERNAL_UNIPHY1;
251*b843c749SSergey Zigachev 	case ENCODER_ID_INTERNAL_UNIPHY2:
252*b843c749SSergey Zigachev 		return ENCODER_OBJECT_ID_INTERNAL_UNIPHY2;
253*b843c749SSergey Zigachev 	case ENCODER_ID_INTERNAL_UNIPHY3:
254*b843c749SSergey Zigachev 		return ENCODER_OBJECT_ID_INTERNAL_UNIPHY3;
255*b843c749SSergey Zigachev 	case ENCODER_ID_INTERNAL_WIRELESS:
256*b843c749SSergey Zigachev 		return ENCODER_OBJECT_ID_INTERNAL_VCE;
257*b843c749SSergey Zigachev 	case ENCODER_ID_INTERNAL_VIRTUAL:
258*b843c749SSergey Zigachev 		return ENCODER_OBJECT_ID_NONE;
259*b843c749SSergey Zigachev 	case ENCODER_ID_UNKNOWN:
260*b843c749SSergey Zigachev 		return ENCODER_OBJECT_ID_NONE;
261*b843c749SSergey Zigachev 	default:
262*b843c749SSergey Zigachev 		/* Invalid encoder id */
263*b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER();
264*b843c749SSergey Zigachev 		return ENCODER_OBJECT_ID_NONE;
265*b843c749SSergey Zigachev 	}
266*b843c749SSergey Zigachev }
267