1 /*
2 * Copyright 2012-15 Advanced Micro Devices, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Authors: AMD
23 *
24 */
25
26 #include "dm_services.h"
27
28 #include "atom.h"
29
30 #include "include/grph_object_id.h"
31 #include "include/grph_object_defs.h"
32 #include "include/bios_parser_types.h"
33
34 #include "../command_table_helper.h"
35
encoder_action_to_atom(enum bp_encoder_control_action action)36 static uint8_t encoder_action_to_atom(enum bp_encoder_control_action action)
37 {
38 uint8_t atom_action = 0;
39
40 switch (action) {
41 case ENCODER_CONTROL_ENABLE:
42 atom_action = ATOM_ENABLE;
43 break;
44 case ENCODER_CONTROL_DISABLE:
45 atom_action = ATOM_DISABLE;
46 break;
47 case ENCODER_CONTROL_SETUP:
48 atom_action = ATOM_ENCODER_CMD_SETUP;
49 break;
50 case ENCODER_CONTROL_INIT:
51 atom_action = ATOM_ENCODER_INIT;
52 break;
53 default:
54 BREAK_TO_DEBUGGER(); /* Unhandle action in driver.!! */
55 break;
56 }
57
58 return atom_action;
59 }
60
clock_source_id_to_atom(enum clock_source_id id,uint32_t * atom_pll_id)61 static bool clock_source_id_to_atom(
62 enum clock_source_id id,
63 uint32_t *atom_pll_id)
64 {
65 bool result = true;
66
67 if (atom_pll_id != NULL)
68 switch (id) {
69 case CLOCK_SOURCE_ID_PLL0:
70 *atom_pll_id = ATOM_PPLL0;
71 break;
72 case CLOCK_SOURCE_ID_PLL1:
73 *atom_pll_id = ATOM_PPLL1;
74 break;
75 case CLOCK_SOURCE_ID_PLL2:
76 *atom_pll_id = ATOM_PPLL2;
77 break;
78 case CLOCK_SOURCE_ID_EXTERNAL:
79 *atom_pll_id = ATOM_PPLL_INVALID;
80 break;
81 case CLOCK_SOURCE_ID_DFS:
82 *atom_pll_id = ATOM_EXT_PLL1;
83 break;
84 case CLOCK_SOURCE_ID_VCE:
85 /* for VCE encoding,
86 * we need to pass in ATOM_PPLL_INVALID
87 */
88 *atom_pll_id = ATOM_PPLL_INVALID;
89 break;
90 case CLOCK_SOURCE_ID_DP_DTO:
91 /* When programming DP DTO PLL ID should be invalid */
92 *atom_pll_id = ATOM_PPLL_INVALID;
93 break;
94 case CLOCK_SOURCE_ID_UNDEFINED:
95 BREAK_TO_DEBUGGER(); /* check when this will happen! */
96 *atom_pll_id = ATOM_PPLL_INVALID;
97 result = false;
98 break;
99 default:
100 result = false;
101 break;
102 }
103
104 return result;
105 }
106
signal_type_to_atom_dig_mode(enum signal_type s)107 static uint8_t signal_type_to_atom_dig_mode(enum signal_type s)
108 {
109 uint8_t atom_dig_mode = ATOM_TRANSMITTER_DIGMODE_V5_DP;
110
111 switch (s) {
112 case SIGNAL_TYPE_DISPLAY_PORT:
113 case SIGNAL_TYPE_EDP:
114 atom_dig_mode = ATOM_TRANSMITTER_DIGMODE_V5_DP;
115 break;
116 case SIGNAL_TYPE_LVDS:
117 atom_dig_mode = ATOM_TRANSMITTER_DIGMODE_V5_LVDS;
118 break;
119 case SIGNAL_TYPE_DVI_SINGLE_LINK:
120 case SIGNAL_TYPE_DVI_DUAL_LINK:
121 atom_dig_mode = ATOM_TRANSMITTER_DIGMODE_V5_DVI;
122 break;
123 case SIGNAL_TYPE_HDMI_TYPE_A:
124 atom_dig_mode = ATOM_TRANSMITTER_DIGMODE_V5_HDMI;
125 break;
126 case SIGNAL_TYPE_DISPLAY_PORT_MST:
127 atom_dig_mode = ATOM_TRANSMITTER_DIGMODE_V5_DP_MST;
128 break;
129 default:
130 atom_dig_mode = ATOM_TRANSMITTER_DIGMODE_V5_DVI;
131 break;
132 }
133
134 return atom_dig_mode;
135 }
136
hpd_sel_to_atom(enum hpd_source_id id)137 static uint8_t hpd_sel_to_atom(enum hpd_source_id id)
138 {
139 uint8_t atom_hpd_sel = 0;
140
141 switch (id) {
142 case HPD_SOURCEID1:
143 atom_hpd_sel = ATOM_TRANSMITTER_CONFIG_V5_HPD1_SEL;
144 break;
145 case HPD_SOURCEID2:
146 atom_hpd_sel = ATOM_TRANSMITTER_CONFIG_V5_HPD2_SEL;
147 break;
148 case HPD_SOURCEID3:
149 atom_hpd_sel = ATOM_TRANSMITTER_CONFIG_V5_HPD3_SEL;
150 break;
151 case HPD_SOURCEID4:
152 atom_hpd_sel = ATOM_TRANSMITTER_CONFIG_V5_HPD4_SEL;
153 break;
154 case HPD_SOURCEID5:
155 atom_hpd_sel = ATOM_TRANSMITTER_CONFIG_V5_HPD5_SEL;
156 break;
157 case HPD_SOURCEID6:
158 atom_hpd_sel = ATOM_TRANSMITTER_CONFIG_V5_HPD6_SEL;
159 break;
160 case HPD_SOURCEID_UNKNOWN:
161 default:
162 atom_hpd_sel = 0;
163 break;
164 }
165 return atom_hpd_sel >> 4;
166 }
167
dig_encoder_sel_to_atom(enum engine_id id)168 static uint8_t dig_encoder_sel_to_atom(enum engine_id id)
169 {
170 uint8_t atom_dig_encoder_sel = 0;
171
172 switch (id) {
173 case ENGINE_ID_DIGA:
174 atom_dig_encoder_sel = ATOM_TRANMSITTER_V5__DIGA_SEL;
175 break;
176 case ENGINE_ID_DIGB:
177 atom_dig_encoder_sel = ATOM_TRANMSITTER_V5__DIGB_SEL;
178 break;
179 case ENGINE_ID_DIGC:
180 atom_dig_encoder_sel = ATOM_TRANMSITTER_V5__DIGC_SEL;
181 break;
182 case ENGINE_ID_DIGD:
183 atom_dig_encoder_sel = ATOM_TRANMSITTER_V5__DIGD_SEL;
184 break;
185 case ENGINE_ID_DIGE:
186 atom_dig_encoder_sel = ATOM_TRANMSITTER_V5__DIGE_SEL;
187 break;
188 case ENGINE_ID_DIGF:
189 atom_dig_encoder_sel = ATOM_TRANMSITTER_V5__DIGF_SEL;
190 break;
191 case ENGINE_ID_DIGG:
192 atom_dig_encoder_sel = ATOM_TRANMSITTER_V5__DIGG_SEL;
193 break;
194 default:
195 atom_dig_encoder_sel = ATOM_TRANMSITTER_V5__DIGA_SEL;
196 break;
197 }
198
199 return atom_dig_encoder_sel;
200 }
201
disp_power_gating_action_to_atom(enum bp_pipe_control_action action)202 static uint8_t disp_power_gating_action_to_atom(
203 enum bp_pipe_control_action action)
204 {
205 uint8_t atom_pipe_action = 0;
206
207 switch (action) {
208 case ASIC_PIPE_DISABLE:
209 atom_pipe_action = ATOM_DISABLE;
210 break;
211 case ASIC_PIPE_ENABLE:
212 atom_pipe_action = ATOM_ENABLE;
213 break;
214 case ASIC_PIPE_INIT:
215 atom_pipe_action = ATOM_INIT;
216 break;
217 default:
218 BREAK_TO_DEBUGGER(); /* Unhandle action in driver! */
219 break;
220 }
221
222 return atom_pipe_action;
223 }
224
225 static const struct command_table_helper command_table_helper_funcs = {
226 .controller_id_to_atom = dal_cmd_table_helper_controller_id_to_atom,
227 .encoder_action_to_atom = encoder_action_to_atom,
228 .engine_bp_to_atom = engine_bp_to_atom,
229 .clock_source_id_to_atom = clock_source_id_to_atom,
230 .clock_source_id_to_atom_phy_clk_src_id =
231 clock_source_id_to_atom_phy_clk_src_id,
232 .signal_type_to_atom_dig_mode = signal_type_to_atom_dig_mode,
233 .hpd_sel_to_atom = hpd_sel_to_atom,
234 .dig_encoder_sel_to_atom = dig_encoder_sel_to_atom,
235 .phy_id_to_atom = phy_id_to_atom,
236 .disp_power_gating_action_to_atom = disp_power_gating_action_to_atom,
237 .assign_control_parameter =
238 dal_cmd_table_helper_assign_control_parameter,
239 .clock_source_id_to_ref_clk_src =
240 dal_cmd_table_helper_clock_source_id_to_ref_clk_src,
241 .transmitter_bp_to_atom = dal_cmd_table_helper_transmitter_bp_to_atom,
242 .encoder_id_to_atom = dal_cmd_table_helper_encoder_id_to_atom,
243 .encoder_mode_bp_to_atom =
244 dal_cmd_table_helper_encoder_mode_bp_to_atom,
245 };
246
dal_cmd_tbl_helper_dce80_get_table(void)247 const struct command_table_helper *dal_cmd_tbl_helper_dce80_get_table(void)
248 {
249 return &command_table_helper_funcs;
250 }
251