WIP FPC-III support
[linux/fpc-iii.git] / drivers / gpu / drm / amd / display / dc / bios / bios_parser_common.c
bloba8cb039d25721dea7152aeba85ab1be69bf3b550
1 /*
2 * Copyright 2012-15 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
22 * Authors: AMD
26 #include "bios_parser_common.h"
27 #include "include/grph_object_ctrl_defs.h"
29 static enum object_type object_type_from_bios_object_id(uint32_t bios_object_id)
31 uint32_t bios_object_type = (bios_object_id & OBJECT_TYPE_MASK)
32 >> OBJECT_TYPE_SHIFT;
33 enum object_type object_type;
35 switch (bios_object_type) {
36 case GRAPH_OBJECT_TYPE_GPU:
37 object_type = OBJECT_TYPE_GPU;
38 break;
39 case GRAPH_OBJECT_TYPE_ENCODER:
40 object_type = OBJECT_TYPE_ENCODER;
41 break;
42 case GRAPH_OBJECT_TYPE_CONNECTOR:
43 object_type = OBJECT_TYPE_CONNECTOR;
44 break;
45 case GRAPH_OBJECT_TYPE_ROUTER:
46 object_type = OBJECT_TYPE_ROUTER;
47 break;
48 case GRAPH_OBJECT_TYPE_GENERIC:
49 object_type = OBJECT_TYPE_GENERIC;
50 break;
51 default:
52 object_type = OBJECT_TYPE_UNKNOWN;
53 break;
56 return object_type;
59 static enum object_enum_id enum_id_from_bios_object_id(uint32_t bios_object_id)
61 uint32_t bios_enum_id =
62 (bios_object_id & ENUM_ID_MASK) >> ENUM_ID_SHIFT;
63 enum object_enum_id id;
65 switch (bios_enum_id) {
66 case GRAPH_OBJECT_ENUM_ID1:
67 id = ENUM_ID_1;
68 break;
69 case GRAPH_OBJECT_ENUM_ID2:
70 id = ENUM_ID_2;
71 break;
72 case GRAPH_OBJECT_ENUM_ID3:
73 id = ENUM_ID_3;
74 break;
75 case GRAPH_OBJECT_ENUM_ID4:
76 id = ENUM_ID_4;
77 break;
78 case GRAPH_OBJECT_ENUM_ID5:
79 id = ENUM_ID_5;
80 break;
81 case GRAPH_OBJECT_ENUM_ID6:
82 id = ENUM_ID_6;
83 break;
84 case GRAPH_OBJECT_ENUM_ID7:
85 id = ENUM_ID_7;
86 break;
87 default:
88 id = ENUM_ID_UNKNOWN;
89 break;
92 return id;
95 static uint32_t gpu_id_from_bios_object_id(uint32_t bios_object_id)
97 return (bios_object_id & OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
100 static enum encoder_id encoder_id_from_bios_object_id(uint32_t bios_object_id)
102 uint32_t bios_encoder_id = gpu_id_from_bios_object_id(bios_object_id);
103 enum encoder_id id;
105 switch (bios_encoder_id) {
106 case ENCODER_OBJECT_ID_INTERNAL_LVDS:
107 id = ENCODER_ID_INTERNAL_LVDS;
108 break;
109 case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
110 id = ENCODER_ID_INTERNAL_TMDS1;
111 break;
112 case ENCODER_OBJECT_ID_INTERNAL_TMDS2:
113 id = ENCODER_ID_INTERNAL_TMDS2;
114 break;
115 case ENCODER_OBJECT_ID_INTERNAL_DAC1:
116 id = ENCODER_ID_INTERNAL_DAC1;
117 break;
118 case ENCODER_OBJECT_ID_INTERNAL_DAC2:
119 id = ENCODER_ID_INTERNAL_DAC2;
120 break;
121 case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
122 id = ENCODER_ID_INTERNAL_LVTM1;
123 break;
124 case ENCODER_OBJECT_ID_HDMI_INTERNAL:
125 id = ENCODER_ID_INTERNAL_HDMI;
126 break;
127 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
128 id = ENCODER_ID_INTERNAL_KLDSCP_TMDS1;
129 break;
130 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
131 id = ENCODER_ID_INTERNAL_KLDSCP_DAC1;
132 break;
133 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
134 id = ENCODER_ID_INTERNAL_KLDSCP_DAC2;
135 break;
136 case ENCODER_OBJECT_ID_MVPU_FPGA:
137 id = ENCODER_ID_EXTERNAL_MVPU_FPGA;
138 break;
139 case ENCODER_OBJECT_ID_INTERNAL_DDI:
140 id = ENCODER_ID_INTERNAL_DDI;
141 break;
142 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
143 id = ENCODER_ID_INTERNAL_UNIPHY;
144 break;
145 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
146 id = ENCODER_ID_INTERNAL_KLDSCP_LVTMA;
147 break;
148 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
149 id = ENCODER_ID_INTERNAL_UNIPHY1;
150 break;
151 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
152 id = ENCODER_ID_INTERNAL_UNIPHY2;
153 break;
154 case ENCODER_OBJECT_ID_ALMOND: /* ENCODER_OBJECT_ID_NUTMEG */
155 id = ENCODER_ID_EXTERNAL_NUTMEG;
156 break;
157 case ENCODER_OBJECT_ID_TRAVIS:
158 id = ENCODER_ID_EXTERNAL_TRAVIS;
159 break;
160 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3:
161 id = ENCODER_ID_INTERNAL_UNIPHY3;
162 break;
163 default:
164 id = ENCODER_ID_UNKNOWN;
165 ASSERT(0);
166 break;
169 return id;
172 static enum connector_id connector_id_from_bios_object_id(
173 uint32_t bios_object_id)
175 uint32_t bios_connector_id = gpu_id_from_bios_object_id(bios_object_id);
177 enum connector_id id;
179 switch (bios_connector_id) {
180 case CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I:
181 id = CONNECTOR_ID_SINGLE_LINK_DVII;
182 break;
183 case CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I:
184 id = CONNECTOR_ID_DUAL_LINK_DVII;
185 break;
186 case CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D:
187 id = CONNECTOR_ID_SINGLE_LINK_DVID;
188 break;
189 case CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D:
190 id = CONNECTOR_ID_DUAL_LINK_DVID;
191 break;
192 case CONNECTOR_OBJECT_ID_VGA:
193 id = CONNECTOR_ID_VGA;
194 break;
195 case CONNECTOR_OBJECT_ID_HDMI_TYPE_A:
196 id = CONNECTOR_ID_HDMI_TYPE_A;
197 break;
198 case CONNECTOR_OBJECT_ID_LVDS:
199 id = CONNECTOR_ID_LVDS;
200 break;
201 case CONNECTOR_OBJECT_ID_PCIE_CONNECTOR:
202 id = CONNECTOR_ID_PCIE;
203 break;
204 case CONNECTOR_OBJECT_ID_HARDCODE_DVI:
205 id = CONNECTOR_ID_HARDCODE_DVI;
206 break;
207 case CONNECTOR_OBJECT_ID_DISPLAYPORT:
208 id = CONNECTOR_ID_DISPLAY_PORT;
209 break;
210 case CONNECTOR_OBJECT_ID_eDP:
211 id = CONNECTOR_ID_EDP;
212 break;
213 case CONNECTOR_OBJECT_ID_MXM:
214 id = CONNECTOR_ID_MXM;
215 break;
216 default:
217 id = CONNECTOR_ID_UNKNOWN;
218 break;
221 return id;
224 static enum generic_id generic_id_from_bios_object_id(uint32_t bios_object_id)
226 uint32_t bios_generic_id = gpu_id_from_bios_object_id(bios_object_id);
228 enum generic_id id;
230 switch (bios_generic_id) {
231 case GENERIC_OBJECT_ID_MXM_OPM:
232 id = GENERIC_ID_MXM_OPM;
233 break;
234 case GENERIC_OBJECT_ID_GLSYNC:
235 id = GENERIC_ID_GLSYNC;
236 break;
237 case GENERIC_OBJECT_ID_STEREO_PIN:
238 id = GENERIC_ID_STEREO;
239 break;
240 default:
241 id = GENERIC_ID_UNKNOWN;
242 break;
245 return id;
248 static uint32_t id_from_bios_object_id(enum object_type type,
249 uint32_t bios_object_id)
251 switch (type) {
252 case OBJECT_TYPE_GPU:
253 return gpu_id_from_bios_object_id(bios_object_id);
254 case OBJECT_TYPE_ENCODER:
255 return (uint32_t)encoder_id_from_bios_object_id(bios_object_id);
256 case OBJECT_TYPE_CONNECTOR:
257 return (uint32_t)connector_id_from_bios_object_id(
258 bios_object_id);
259 case OBJECT_TYPE_GENERIC:
260 return generic_id_from_bios_object_id(bios_object_id);
261 default:
262 return 0;
266 struct graphics_object_id object_id_from_bios_object_id(uint32_t bios_object_id)
268 enum object_type type;
269 enum object_enum_id enum_id;
270 struct graphics_object_id go_id = { 0 };
272 type = object_type_from_bios_object_id(bios_object_id);
274 if (OBJECT_TYPE_UNKNOWN == type)
275 return go_id;
277 enum_id = enum_id_from_bios_object_id(bios_object_id);
279 if (ENUM_ID_UNKNOWN == enum_id)
280 return go_id;
282 go_id = dal_graphics_object_id_init(
283 id_from_bios_object_id(type, bios_object_id), enum_id, type);
285 return go_id;