1 /*
2  * Copyright 2013 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  */
23 
24 #include <linux/module.h>
25 #include <linux/pci.h>
26 
27 #include "amdgpu.h"
28 #include "amdgpu_pm.h"
29 #include "amdgpu_dpm.h"
30 #include "amdgpu_atombios.h"
31 #include "amdgpu_dpm_internal.h"
32 #include "amd_pcie.h"
33 #include "sid.h"
34 #include "r600_dpm.h"
35 #include "si_dpm.h"
36 #include "atom.h"
37 #include "../include/pptable.h"
38 #include <linux/math64.h>
39 #include <linux/seq_file.h>
40 #include <linux/firmware.h>
41 #include <legacy_dpm.h>
42 
43 #define MC_CG_ARB_FREQ_F0           0x0a
44 #define MC_CG_ARB_FREQ_F1           0x0b
45 #define MC_CG_ARB_FREQ_F2           0x0c
46 #define MC_CG_ARB_FREQ_F3           0x0d
47 
48 #define SMC_RAM_END                 0x20000
49 
50 #define SCLK_MIN_DEEPSLEEP_FREQ     1350
51 
52 
53 /* sizeof(ATOM_PPLIB_EXTENDEDHEADER) */
54 #define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V2 12
55 #define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V3 14
56 #define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V4 16
57 #define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V5 18
58 #define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V6 20
59 #define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V7 22
60 
61 #define BIOS_SCRATCH_4                                    0x5cd
62 
63 MODULE_FIRMWARE("amdgpu/tahiti_smc.bin");
64 MODULE_FIRMWARE("amdgpu/pitcairn_smc.bin");
65 MODULE_FIRMWARE("amdgpu/pitcairn_k_smc.bin");
66 MODULE_FIRMWARE("amdgpu/verde_smc.bin");
67 MODULE_FIRMWARE("amdgpu/verde_k_smc.bin");
68 MODULE_FIRMWARE("amdgpu/oland_smc.bin");
69 MODULE_FIRMWARE("amdgpu/oland_k_smc.bin");
70 MODULE_FIRMWARE("amdgpu/hainan_smc.bin");
71 MODULE_FIRMWARE("amdgpu/hainan_k_smc.bin");
72 MODULE_FIRMWARE("amdgpu/banks_k_2_smc.bin");
73 
74 static const struct amd_pm_funcs si_dpm_funcs;
75 
76 union power_info {
77 	struct _ATOM_POWERPLAY_INFO info;
78 	struct _ATOM_POWERPLAY_INFO_V2 info_2;
79 	struct _ATOM_POWERPLAY_INFO_V3 info_3;
80 	struct _ATOM_PPLIB_POWERPLAYTABLE pplib;
81 	struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2;
82 	struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3;
83 	struct _ATOM_PPLIB_POWERPLAYTABLE4 pplib4;
84 	struct _ATOM_PPLIB_POWERPLAYTABLE5 pplib5;
85 };
86 
87 union fan_info {
88 	struct _ATOM_PPLIB_FANTABLE fan;
89 	struct _ATOM_PPLIB_FANTABLE2 fan2;
90 	struct _ATOM_PPLIB_FANTABLE3 fan3;
91 };
92 
93 union pplib_clock_info {
94 	struct _ATOM_PPLIB_R600_CLOCK_INFO r600;
95 	struct _ATOM_PPLIB_RS780_CLOCK_INFO rs780;
96 	struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO evergreen;
97 	struct _ATOM_PPLIB_SUMO_CLOCK_INFO sumo;
98 	struct _ATOM_PPLIB_SI_CLOCK_INFO si;
99 };
100 
101 enum si_dpm_auto_throttle_src {
102 	SI_DPM_AUTO_THROTTLE_SRC_THERMAL,
103 	SI_DPM_AUTO_THROTTLE_SRC_EXTERNAL
104 };
105 
106 enum si_dpm_event_src {
107 	SI_DPM_EVENT_SRC_ANALOG = 0,
108 	SI_DPM_EVENT_SRC_EXTERNAL = 1,
109 	SI_DPM_EVENT_SRC_DIGITAL = 2,
110 	SI_DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
111 	SI_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL = 4
112 };
113 
114 static const u32 r600_utc[R600_PM_NUMBER_OF_TC] =
115 {
116 	R600_UTC_DFLT_00,
117 	R600_UTC_DFLT_01,
118 	R600_UTC_DFLT_02,
119 	R600_UTC_DFLT_03,
120 	R600_UTC_DFLT_04,
121 	R600_UTC_DFLT_05,
122 	R600_UTC_DFLT_06,
123 	R600_UTC_DFLT_07,
124 	R600_UTC_DFLT_08,
125 	R600_UTC_DFLT_09,
126 	R600_UTC_DFLT_10,
127 	R600_UTC_DFLT_11,
128 	R600_UTC_DFLT_12,
129 	R600_UTC_DFLT_13,
130 	R600_UTC_DFLT_14,
131 };
132 
133 static const u32 r600_dtc[R600_PM_NUMBER_OF_TC] =
134 {
135 	R600_DTC_DFLT_00,
136 	R600_DTC_DFLT_01,
137 	R600_DTC_DFLT_02,
138 	R600_DTC_DFLT_03,
139 	R600_DTC_DFLT_04,
140 	R600_DTC_DFLT_05,
141 	R600_DTC_DFLT_06,
142 	R600_DTC_DFLT_07,
143 	R600_DTC_DFLT_08,
144 	R600_DTC_DFLT_09,
145 	R600_DTC_DFLT_10,
146 	R600_DTC_DFLT_11,
147 	R600_DTC_DFLT_12,
148 	R600_DTC_DFLT_13,
149 	R600_DTC_DFLT_14,
150 };
151 
152 static const struct si_cac_config_reg cac_weights_tahiti[] =
153 {
154 	{ 0x0, 0x0000ffff, 0, 0xc, SISLANDS_CACCONFIG_CGIND },
155 	{ 0x0, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
156 	{ 0x1, 0x0000ffff, 0, 0x101, SISLANDS_CACCONFIG_CGIND },
157 	{ 0x1, 0xffff0000, 16, 0xc, SISLANDS_CACCONFIG_CGIND },
158 	{ 0x2, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
159 	{ 0x3, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
160 	{ 0x3, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
161 	{ 0x4, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
162 	{ 0x4, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
163 	{ 0x5, 0x0000ffff, 0, 0x8fc, SISLANDS_CACCONFIG_CGIND },
164 	{ 0x5, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
165 	{ 0x6, 0x0000ffff, 0, 0x95, SISLANDS_CACCONFIG_CGIND },
166 	{ 0x6, 0xffff0000, 16, 0x34e, SISLANDS_CACCONFIG_CGIND },
167 	{ 0x18f, 0x0000ffff, 0, 0x1a1, SISLANDS_CACCONFIG_CGIND },
168 	{ 0x7, 0x0000ffff, 0, 0xda, SISLANDS_CACCONFIG_CGIND },
169 	{ 0x7, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
170 	{ 0x8, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
171 	{ 0x8, 0xffff0000, 16, 0x46, SISLANDS_CACCONFIG_CGIND },
172 	{ 0x9, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
173 	{ 0xa, 0x0000ffff, 0, 0x208, SISLANDS_CACCONFIG_CGIND },
174 	{ 0xb, 0x0000ffff, 0, 0xe7, SISLANDS_CACCONFIG_CGIND },
175 	{ 0xb, 0xffff0000, 16, 0x948, SISLANDS_CACCONFIG_CGIND },
176 	{ 0xc, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
177 	{ 0xd, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
178 	{ 0xd, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
179 	{ 0xe, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
180 	{ 0xf, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
181 	{ 0xf, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
182 	{ 0x10, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
183 	{ 0x10, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
184 	{ 0x11, 0x0000ffff, 0, 0x167, SISLANDS_CACCONFIG_CGIND },
185 	{ 0x11, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
186 	{ 0x12, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
187 	{ 0x13, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
188 	{ 0x13, 0xffff0000, 16, 0x35, SISLANDS_CACCONFIG_CGIND },
189 	{ 0x14, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
190 	{ 0x15, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
191 	{ 0x15, 0xffff0000, 16, 0x2, SISLANDS_CACCONFIG_CGIND },
192 	{ 0x4e, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
193 	{ 0x16, 0x0000ffff, 0, 0x31, SISLANDS_CACCONFIG_CGIND },
194 	{ 0x16, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
195 	{ 0x17, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
196 	{ 0x18, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
197 	{ 0x18, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
198 	{ 0x19, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
199 	{ 0x19, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
200 	{ 0x1a, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
201 	{ 0x1a, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
202 	{ 0x1b, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
203 	{ 0x1b, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
204 	{ 0x1c, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
205 	{ 0x1c, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
206 	{ 0x1d, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
207 	{ 0x1d, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
208 	{ 0x1e, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
209 	{ 0x1e, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
210 	{ 0x1f, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
211 	{ 0x1f, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
212 	{ 0x20, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
213 	{ 0x6d, 0x0000ffff, 0, 0x18e, SISLANDS_CACCONFIG_CGIND },
214 	{ 0xFFFFFFFF }
215 };
216 
217 static const struct si_cac_config_reg lcac_tahiti[] =
218 {
219 	{ 0x143, 0x0001fffe, 1, 0x3, SISLANDS_CACCONFIG_CGIND },
220 	{ 0x143, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
221 	{ 0x146, 0x0001fffe, 1, 0x3, SISLANDS_CACCONFIG_CGIND },
222 	{ 0x146, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
223 	{ 0x149, 0x0001fffe, 1, 0x3, SISLANDS_CACCONFIG_CGIND },
224 	{ 0x149, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
225 	{ 0x14c, 0x0001fffe, 1, 0x3, SISLANDS_CACCONFIG_CGIND },
226 	{ 0x14c, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
227 	{ 0x98, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
228 	{ 0x98, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
229 	{ 0x9b, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
230 	{ 0x9b, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
231 	{ 0x9e, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
232 	{ 0x9e, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
233 	{ 0x101, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
234 	{ 0x101, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
235 	{ 0x104, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
236 	{ 0x104, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
237 	{ 0x107, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
238 	{ 0x107, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
239 	{ 0x10a, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
240 	{ 0x10a, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
241 	{ 0x10d, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
242 	{ 0x10d, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
243 	{ 0x8c, 0x0001fffe, 1, 0x8, SISLANDS_CACCONFIG_CGIND },
244 	{ 0x8c, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
245 	{ 0x8f, 0x0001fffe, 1, 0x8, SISLANDS_CACCONFIG_CGIND },
246 	{ 0x8f, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
247 	{ 0x92, 0x0001fffe, 1, 0x8, SISLANDS_CACCONFIG_CGIND },
248 	{ 0x92, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
249 	{ 0x95, 0x0001fffe, 1, 0x8, SISLANDS_CACCONFIG_CGIND },
250 	{ 0x95, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
251 	{ 0x14f, 0x0001fffe, 1, 0x8, SISLANDS_CACCONFIG_CGIND },
252 	{ 0x14f, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
253 	{ 0x152, 0x0001fffe, 1, 0x8, SISLANDS_CACCONFIG_CGIND },
254 	{ 0x152, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
255 	{ 0x155, 0x0001fffe, 1, 0x8, SISLANDS_CACCONFIG_CGIND },
256 	{ 0x155, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
257 	{ 0x158, 0x0001fffe, 1, 0x8, SISLANDS_CACCONFIG_CGIND },
258 	{ 0x158, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
259 	{ 0x110, 0x0001fffe, 1, 0x8, SISLANDS_CACCONFIG_CGIND },
260 	{ 0x110, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
261 	{ 0x113, 0x0001fffe, 1, 0x8, SISLANDS_CACCONFIG_CGIND },
262 	{ 0x113, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
263 	{ 0x116, 0x0001fffe, 1, 0x8, SISLANDS_CACCONFIG_CGIND },
264 	{ 0x116, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
265 	{ 0x119, 0x0001fffe, 1, 0x8, SISLANDS_CACCONFIG_CGIND },
266 	{ 0x119, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
267 	{ 0x11c, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
268 	{ 0x11c, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
269 	{ 0x11f, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
270 	{ 0x11f, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
271 	{ 0x122, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
272 	{ 0x122, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
273 	{ 0x125, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
274 	{ 0x125, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
275 	{ 0x128, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
276 	{ 0x128, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
277 	{ 0x12b, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
278 	{ 0x12b, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
279 	{ 0x15b, 0x0001fffe, 1, 0x4, SISLANDS_CACCONFIG_CGIND },
280 	{ 0x15b, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
281 	{ 0x15e, 0x0001fffe, 1, 0x4, SISLANDS_CACCONFIG_CGIND },
282 	{ 0x15e, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
283 	{ 0x161, 0x0001fffe, 1, 0x4, SISLANDS_CACCONFIG_CGIND },
284 	{ 0x161, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
285 	{ 0x164, 0x0001fffe, 1, 0x4, SISLANDS_CACCONFIG_CGIND },
286 	{ 0x164, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
287 	{ 0x167, 0x0001fffe, 1, 0x4, SISLANDS_CACCONFIG_CGIND },
288 	{ 0x167, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
289 	{ 0x16a, 0x0001fffe, 1, 0x4, SISLANDS_CACCONFIG_CGIND },
290 	{ 0x16a, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
291 	{ 0x16d, 0x0001fffe, 1, 0x6, SISLANDS_CACCONFIG_CGIND },
292 	{ 0x16d, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
293 	{ 0x170, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
294 	{ 0x170, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
295 	{ 0x173, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
296 	{ 0x173, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
297 	{ 0x176, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
298 	{ 0x176, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
299 	{ 0x179, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
300 	{ 0x179, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
301 	{ 0x17c, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
302 	{ 0x17c, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
303 	{ 0x17f, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
304 	{ 0x17f, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
305 	{ 0xFFFFFFFF }
306 
307 };
308 
309 static const struct si_cac_config_reg cac_override_tahiti[] =
310 {
311 	{ 0xFFFFFFFF }
312 };
313 
314 static const struct si_powertune_data powertune_data_tahiti =
315 {
316 	((1 << 16) | 27027),
317 	6,
318 	0,
319 	4,
320 	95,
321 	{
322 		0UL,
323 		0UL,
324 		4521550UL,
325 		309631529UL,
326 		-1270850L,
327 		4513710L,
328 		40
329 	},
330 	595000000UL,
331 	12,
332 	{
333 		0,
334 		0,
335 		0,
336 		0,
337 		0,
338 		0,
339 		0,
340 		0
341 	},
342 	true
343 };
344 
345 static const struct si_dte_data dte_data_tahiti =
346 {
347 	{ 1159409, 0, 0, 0, 0 },
348 	{ 777, 0, 0, 0, 0 },
349 	2,
350 	54000,
351 	127000,
352 	25,
353 	2,
354 	10,
355 	13,
356 	{ 27, 31, 35, 39, 43, 47, 54, 61, 67, 74, 81, 88, 95, 0, 0, 0 },
357 	{ 240888759, 221057860, 235370597, 162287531, 158510299, 131423027, 116673180, 103067515, 87941937, 76209048, 68209175, 64090048, 58301890, 0, 0, 0 },
358 	{ 12024, 11189, 11451, 8411, 7939, 6666, 5681, 4905, 4241, 3720, 3354, 3122, 2890, 0, 0, 0 },
359 	85,
360 	false
361 };
362 
363 static const struct si_dte_data dte_data_tahiti_pro =
364 {
365 	{ 0x1E8480, 0x3D0900, 0x989680, 0x2625A00, 0x0 },
366 	{ 0x0, 0x0, 0x0, 0x0, 0x0 },
367 	5,
368 	45000,
369 	100,
370 	0xA,
371 	1,
372 	0,
373 	0x10,
374 	{ 0x96, 0xB4, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
375 	{ 0x895440, 0x3D0900, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680 },
376 	{ 0x7D0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 },
377 	90,
378 	true
379 };
380 
381 static const struct si_dte_data dte_data_new_zealand =
382 {
383 	{ 0x1E8480, 0x3D0900, 0x989680, 0x2625A00, 0 },
384 	{ 0x29B, 0x3E9, 0x537, 0x7D2, 0 },
385 	0x5,
386 	0xAFC8,
387 	0x69,
388 	0x32,
389 	1,
390 	0,
391 	0x10,
392 	{ 0x82, 0xA0, 0xB4, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE },
393 	{ 0x895440, 0x3D0900, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680 },
394 	{ 0xDAC, 0x1388, 0x685, 0x685, 0x685, 0x685, 0x685, 0x685, 0x685, 0x685, 0x685, 0x685, 0x685, 0x685, 0x685, 0x685 },
395 	85,
396 	true
397 };
398 
399 static const struct si_dte_data dte_data_aruba_pro =
400 {
401 	{ 0x1E8480, 0x3D0900, 0x989680, 0x2625A00, 0x0 },
402 	{ 0x0, 0x0, 0x0, 0x0, 0x0 },
403 	5,
404 	45000,
405 	100,
406 	0xA,
407 	1,
408 	0,
409 	0x10,
410 	{ 0x96, 0xB4, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
411 	{ 0x895440, 0x3D0900, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680 },
412 	{ 0x1000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 },
413 	90,
414 	true
415 };
416 
417 static const struct si_dte_data dte_data_malta =
418 {
419 	{ 0x1E8480, 0x3D0900, 0x989680, 0x2625A00, 0x0 },
420 	{ 0x0, 0x0, 0x0, 0x0, 0x0 },
421 	5,
422 	45000,
423 	100,
424 	0xA,
425 	1,
426 	0,
427 	0x10,
428 	{ 0x96, 0xB4, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
429 	{ 0x895440, 0x3D0900, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680 },
430 	{ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 },
431 	90,
432 	true
433 };
434 
435 static const struct si_cac_config_reg cac_weights_pitcairn[] =
436 {
437 	{ 0x0, 0x0000ffff, 0, 0x8a, SISLANDS_CACCONFIG_CGIND },
438 	{ 0x0, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
439 	{ 0x1, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
440 	{ 0x1, 0xffff0000, 16, 0x24d, SISLANDS_CACCONFIG_CGIND },
441 	{ 0x2, 0x0000ffff, 0, 0x19, SISLANDS_CACCONFIG_CGIND },
442 	{ 0x3, 0x0000ffff, 0, 0x118, SISLANDS_CACCONFIG_CGIND },
443 	{ 0x3, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
444 	{ 0x4, 0x0000ffff, 0, 0x76, SISLANDS_CACCONFIG_CGIND },
445 	{ 0x4, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
446 	{ 0x5, 0x0000ffff, 0, 0xc11, SISLANDS_CACCONFIG_CGIND },
447 	{ 0x5, 0xffff0000, 16, 0x7f3, SISLANDS_CACCONFIG_CGIND },
448 	{ 0x6, 0x0000ffff, 0, 0x403, SISLANDS_CACCONFIG_CGIND },
449 	{ 0x6, 0xffff0000, 16, 0x367, SISLANDS_CACCONFIG_CGIND },
450 	{ 0x18f, 0x0000ffff, 0, 0x4c9, SISLANDS_CACCONFIG_CGIND },
451 	{ 0x7, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
452 	{ 0x7, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
453 	{ 0x8, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
454 	{ 0x8, 0xffff0000, 16, 0x45d, SISLANDS_CACCONFIG_CGIND },
455 	{ 0x9, 0x0000ffff, 0, 0x36d, SISLANDS_CACCONFIG_CGIND },
456 	{ 0xa, 0x0000ffff, 0, 0x534, SISLANDS_CACCONFIG_CGIND },
457 	{ 0xb, 0x0000ffff, 0, 0x5da, SISLANDS_CACCONFIG_CGIND },
458 	{ 0xb, 0xffff0000, 16, 0x880, SISLANDS_CACCONFIG_CGIND },
459 	{ 0xc, 0x0000ffff, 0, 0x201, SISLANDS_CACCONFIG_CGIND },
460 	{ 0xd, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
461 	{ 0xd, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
462 	{ 0xe, 0x0000ffff, 0, 0x9f, SISLANDS_CACCONFIG_CGIND },
463 	{ 0xf, 0x0000ffff, 0, 0x1f, SISLANDS_CACCONFIG_CGIND },
464 	{ 0xf, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
465 	{ 0x10, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
466 	{ 0x10, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
467 	{ 0x11, 0x0000ffff, 0, 0x5de, SISLANDS_CACCONFIG_CGIND },
468 	{ 0x11, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
469 	{ 0x12, 0x0000ffff, 0, 0x7b, SISLANDS_CACCONFIG_CGIND },
470 	{ 0x13, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
471 	{ 0x13, 0xffff0000, 16, 0x13, SISLANDS_CACCONFIG_CGIND },
472 	{ 0x14, 0x0000ffff, 0, 0xf9, SISLANDS_CACCONFIG_CGIND },
473 	{ 0x15, 0x0000ffff, 0, 0x66, SISLANDS_CACCONFIG_CGIND },
474 	{ 0x15, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
475 	{ 0x4e, 0x0000ffff, 0, 0x13, SISLANDS_CACCONFIG_CGIND },
476 	{ 0x16, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
477 	{ 0x16, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
478 	{ 0x17, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
479 	{ 0x18, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
480 	{ 0x18, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
481 	{ 0x19, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
482 	{ 0x19, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
483 	{ 0x1a, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
484 	{ 0x1a, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
485 	{ 0x1b, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
486 	{ 0x1b, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
487 	{ 0x1c, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
488 	{ 0x1c, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
489 	{ 0x1d, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
490 	{ 0x1d, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
491 	{ 0x1e, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
492 	{ 0x1e, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
493 	{ 0x1f, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
494 	{ 0x1f, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
495 	{ 0x20, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
496 	{ 0x6d, 0x0000ffff, 0, 0x186, SISLANDS_CACCONFIG_CGIND },
497 	{ 0xFFFFFFFF }
498 };
499 
500 static const struct si_cac_config_reg lcac_pitcairn[] =
501 {
502 	{ 0x98, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
503 	{ 0x98, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
504 	{ 0x104, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
505 	{ 0x104, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
506 	{ 0x110, 0x0001fffe, 1, 0x5, SISLANDS_CACCONFIG_CGIND },
507 	{ 0x110, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
508 	{ 0x14f, 0x0001fffe, 1, 0x5, SISLANDS_CACCONFIG_CGIND },
509 	{ 0x14f, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
510 	{ 0x8c, 0x0001fffe, 1, 0x5, SISLANDS_CACCONFIG_CGIND },
511 	{ 0x8c, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
512 	{ 0x143, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
513 	{ 0x143, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
514 	{ 0x9b, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
515 	{ 0x9b, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
516 	{ 0x107, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
517 	{ 0x107, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
518 	{ 0x113, 0x0001fffe, 1, 0x5, SISLANDS_CACCONFIG_CGIND },
519 	{ 0x113, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
520 	{ 0x152, 0x0001fffe, 1, 0x5, SISLANDS_CACCONFIG_CGIND },
521 	{ 0x152, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
522 	{ 0x8f, 0x0001fffe, 1, 0x5, SISLANDS_CACCONFIG_CGIND },
523 	{ 0x8f, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
524 	{ 0x146, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
525 	{ 0x146, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
526 	{ 0x9e, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
527 	{ 0x9e, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
528 	{ 0x10a, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
529 	{ 0x10a, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
530 	{ 0x116, 0x0001fffe, 1, 0x5, SISLANDS_CACCONFIG_CGIND },
531 	{ 0x116, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
532 	{ 0x155, 0x0001fffe, 1, 0x5, SISLANDS_CACCONFIG_CGIND },
533 	{ 0x155, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
534 	{ 0x92, 0x0001fffe, 1, 0x5, SISLANDS_CACCONFIG_CGIND },
535 	{ 0x92, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
536 	{ 0x149, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
537 	{ 0x149, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
538 	{ 0x101, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
539 	{ 0x101, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
540 	{ 0x10d, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
541 	{ 0x10d, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
542 	{ 0x119, 0x0001fffe, 1, 0x5, SISLANDS_CACCONFIG_CGIND },
543 	{ 0x119, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
544 	{ 0x158, 0x0001fffe, 1, 0x5, SISLANDS_CACCONFIG_CGIND },
545 	{ 0x158, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
546 	{ 0x95, 0x0001fffe, 1, 0x5, SISLANDS_CACCONFIG_CGIND },
547 	{ 0x95, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
548 	{ 0x14c, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
549 	{ 0x14c, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
550 	{ 0x11c, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
551 	{ 0x11c, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
552 	{ 0x11f, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
553 	{ 0x11f, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
554 	{ 0x122, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
555 	{ 0x122, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
556 	{ 0x125, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
557 	{ 0x125, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
558 	{ 0x128, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
559 	{ 0x128, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
560 	{ 0x12b, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
561 	{ 0x12b, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
562 	{ 0x164, 0x0001fffe, 1, 0x4, SISLANDS_CACCONFIG_CGIND },
563 	{ 0x164, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
564 	{ 0x167, 0x0001fffe, 1, 0x4, SISLANDS_CACCONFIG_CGIND },
565 	{ 0x167, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
566 	{ 0x16a, 0x0001fffe, 1, 0x4, SISLANDS_CACCONFIG_CGIND },
567 	{ 0x16a, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
568 	{ 0x15e, 0x0001fffe, 1, 0x4, SISLANDS_CACCONFIG_CGIND },
569 	{ 0x15e, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
570 	{ 0x161, 0x0001fffe, 1, 0x4, SISLANDS_CACCONFIG_CGIND },
571 	{ 0x161, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
572 	{ 0x15b, 0x0001fffe, 1, 0x4, SISLANDS_CACCONFIG_CGIND },
573 	{ 0x15b, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
574 	{ 0x16d, 0x0001fffe, 1, 0x4, SISLANDS_CACCONFIG_CGIND },
575 	{ 0x16d, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
576 	{ 0x170, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
577 	{ 0x170, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
578 	{ 0x173, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
579 	{ 0x173, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
580 	{ 0x176, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
581 	{ 0x176, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
582 	{ 0x179, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
583 	{ 0x179, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
584 	{ 0x17c, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
585 	{ 0x17c, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
586 	{ 0x17f, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
587 	{ 0x17f, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
588 	{ 0xFFFFFFFF }
589 };
590 
591 static const struct si_cac_config_reg cac_override_pitcairn[] =
592 {
593     { 0xFFFFFFFF }
594 };
595 
596 static const struct si_powertune_data powertune_data_pitcairn =
597 {
598 	((1 << 16) | 27027),
599 	5,
600 	0,
601 	6,
602 	100,
603 	{
604 		51600000UL,
605 		1800000UL,
606 		7194395UL,
607 		309631529UL,
608 		-1270850L,
609 		4513710L,
610 		100
611 	},
612 	117830498UL,
613 	12,
614 	{
615 		0,
616 		0,
617 		0,
618 		0,
619 		0,
620 		0,
621 		0,
622 		0
623 	},
624 	true
625 };
626 
627 static const struct si_dte_data dte_data_pitcairn =
628 {
629 	{ 0, 0, 0, 0, 0 },
630 	{ 0, 0, 0, 0, 0 },
631 	0,
632 	0,
633 	0,
634 	0,
635 	0,
636 	0,
637 	0,
638 	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
639 	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
640 	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
641 	0,
642 	false
643 };
644 
645 static const struct si_dte_data dte_data_curacao_xt =
646 {
647 	{ 0x1E8480, 0x3D0900, 0x989680, 0x2625A00, 0x0 },
648 	{ 0x0, 0x0, 0x0, 0x0, 0x0 },
649 	5,
650 	45000,
651 	100,
652 	0xA,
653 	1,
654 	0,
655 	0x10,
656 	{ 0x96, 0xB4, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
657 	{ 0x895440, 0x3D0900, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680 },
658 	{ 0x1D17, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 },
659 	90,
660 	true
661 };
662 
663 static const struct si_dte_data dte_data_curacao_pro =
664 {
665 	{ 0x1E8480, 0x3D0900, 0x989680, 0x2625A00, 0x0 },
666 	{ 0x0, 0x0, 0x0, 0x0, 0x0 },
667 	5,
668 	45000,
669 	100,
670 	0xA,
671 	1,
672 	0,
673 	0x10,
674 	{ 0x96, 0xB4, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
675 	{ 0x895440, 0x3D0900, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680 },
676 	{ 0x1D17, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 },
677 	90,
678 	true
679 };
680 
681 static const struct si_dte_data dte_data_neptune_xt =
682 {
683 	{ 0x1E8480, 0x3D0900, 0x989680, 0x2625A00, 0x0 },
684 	{ 0x0, 0x0, 0x0, 0x0, 0x0 },
685 	5,
686 	45000,
687 	100,
688 	0xA,
689 	1,
690 	0,
691 	0x10,
692 	{ 0x96, 0xB4, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
693 	{ 0x895440, 0x3D0900, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680 },
694 	{ 0x3A2F, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 },
695 	90,
696 	true
697 };
698 
699 static const struct si_cac_config_reg cac_weights_chelsea_pro[] =
700 {
701 	{ 0x0, 0x0000ffff, 0, 0x82, SISLANDS_CACCONFIG_CGIND },
702 	{ 0x0, 0xffff0000, 16, 0x4F, SISLANDS_CACCONFIG_CGIND },
703 	{ 0x1, 0x0000ffff, 0, 0x153, SISLANDS_CACCONFIG_CGIND },
704 	{ 0x1, 0xffff0000, 16, 0x52, SISLANDS_CACCONFIG_CGIND },
705 	{ 0x2, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
706 	{ 0x3, 0x0000ffff, 0, 0x135, SISLANDS_CACCONFIG_CGIND },
707 	{ 0x3, 0xffff0000, 16, 0x4F, SISLANDS_CACCONFIG_CGIND },
708 	{ 0x4, 0x0000ffff, 0, 0x135, SISLANDS_CACCONFIG_CGIND },
709 	{ 0x4, 0xffff0000, 16, 0xAC, SISLANDS_CACCONFIG_CGIND },
710 	{ 0x5, 0x0000ffff, 0, 0x118, SISLANDS_CACCONFIG_CGIND },
711 	{ 0x5, 0xffff0000, 16, 0xBE, SISLANDS_CACCONFIG_CGIND },
712 	{ 0x6, 0x0000ffff, 0, 0x110, SISLANDS_CACCONFIG_CGIND },
713 	{ 0x6, 0xffff0000, 16, 0x4CD, SISLANDS_CACCONFIG_CGIND },
714 	{ 0x18f, 0x0000ffff, 0, 0x30, SISLANDS_CACCONFIG_CGIND },
715 	{ 0x7, 0x0000ffff, 0, 0x37, SISLANDS_CACCONFIG_CGIND },
716 	{ 0x7, 0xffff0000, 16, 0x27, SISLANDS_CACCONFIG_CGIND },
717 	{ 0x8, 0x0000ffff, 0, 0xC3, SISLANDS_CACCONFIG_CGIND },
718 	{ 0x8, 0xffff0000, 16, 0x35, SISLANDS_CACCONFIG_CGIND },
719 	{ 0x9, 0x0000ffff, 0, 0x28, SISLANDS_CACCONFIG_CGIND },
720 	{ 0xa, 0x0000ffff, 0, 0x26C, SISLANDS_CACCONFIG_CGIND },
721 	{ 0xb, 0x0000ffff, 0, 0x3B2, SISLANDS_CACCONFIG_CGIND },
722 	{ 0xb, 0xffff0000, 16, 0x99D, SISLANDS_CACCONFIG_CGIND },
723 	{ 0xc, 0x0000ffff, 0, 0xA3F, SISLANDS_CACCONFIG_CGIND },
724 	{ 0xd, 0x0000ffff, 0, 0xA, SISLANDS_CACCONFIG_CGIND },
725 	{ 0xd, 0xffff0000, 16, 0xA, SISLANDS_CACCONFIG_CGIND },
726 	{ 0xe, 0x0000ffff, 0, 0x5, SISLANDS_CACCONFIG_CGIND },
727 	{ 0xf, 0x0000ffff, 0, 0x3, SISLANDS_CACCONFIG_CGIND },
728 	{ 0xf, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
729 	{ 0x10, 0x0000ffff, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
730 	{ 0x10, 0xffff0000, 16, 0x1, SISLANDS_CACCONFIG_CGIND },
731 	{ 0x11, 0x0000ffff, 0, 0x5, SISLANDS_CACCONFIG_CGIND },
732 	{ 0x11, 0xffff0000, 16, 0x15, SISLANDS_CACCONFIG_CGIND },
733 	{ 0x12, 0x0000ffff, 0, 0x34, SISLANDS_CACCONFIG_CGIND },
734 	{ 0x13, 0x0000ffff, 0, 0x4, SISLANDS_CACCONFIG_CGIND },
735 	{ 0x13, 0xffff0000, 16, 0x4, SISLANDS_CACCONFIG_CGIND },
736 	{ 0x14, 0x0000ffff, 0, 0x2BD, SISLANDS_CACCONFIG_CGIND },
737 	{ 0x15, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
738 	{ 0x15, 0xffff0000, 16, 0x6, SISLANDS_CACCONFIG_CGIND },
739 	{ 0x4e, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
740 	{ 0x16, 0x0000ffff, 0, 0x30, SISLANDS_CACCONFIG_CGIND },
741 	{ 0x16, 0xffff0000, 16, 0x7A, SISLANDS_CACCONFIG_CGIND },
742 	{ 0x17, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
743 	{ 0x18, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
744 	{ 0x18, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
745 	{ 0x19, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
746 	{ 0x19, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
747 	{ 0x1a, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
748 	{ 0x1a, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
749 	{ 0x1b, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
750 	{ 0x1b, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
751 	{ 0x1c, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
752 	{ 0x1c, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
753 	{ 0x1d, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
754 	{ 0x1d, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
755 	{ 0x1e, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
756 	{ 0x1e, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
757 	{ 0x1f, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
758 	{ 0x1f, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
759 	{ 0x20, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
760 	{ 0x6d, 0x0000ffff, 0, 0x100, SISLANDS_CACCONFIG_CGIND },
761 	{ 0xFFFFFFFF }
762 };
763 
764 static const struct si_cac_config_reg cac_weights_chelsea_xt[] =
765 {
766 	{ 0x0, 0x0000ffff, 0, 0x82, SISLANDS_CACCONFIG_CGIND },
767 	{ 0x0, 0xffff0000, 16, 0x4F, SISLANDS_CACCONFIG_CGIND },
768 	{ 0x1, 0x0000ffff, 0, 0x153, SISLANDS_CACCONFIG_CGIND },
769 	{ 0x1, 0xffff0000, 16, 0x52, SISLANDS_CACCONFIG_CGIND },
770 	{ 0x2, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
771 	{ 0x3, 0x0000ffff, 0, 0x135, SISLANDS_CACCONFIG_CGIND },
772 	{ 0x3, 0xffff0000, 16, 0x4F, SISLANDS_CACCONFIG_CGIND },
773 	{ 0x4, 0x0000ffff, 0, 0x135, SISLANDS_CACCONFIG_CGIND },
774 	{ 0x4, 0xffff0000, 16, 0xAC, SISLANDS_CACCONFIG_CGIND },
775 	{ 0x5, 0x0000ffff, 0, 0x118, SISLANDS_CACCONFIG_CGIND },
776 	{ 0x5, 0xffff0000, 16, 0xBE, SISLANDS_CACCONFIG_CGIND },
777 	{ 0x6, 0x0000ffff, 0, 0x110, SISLANDS_CACCONFIG_CGIND },
778 	{ 0x6, 0xffff0000, 16, 0x4CD, SISLANDS_CACCONFIG_CGIND },
779 	{ 0x18f, 0x0000ffff, 0, 0x30, SISLANDS_CACCONFIG_CGIND },
780 	{ 0x7, 0x0000ffff, 0, 0x37, SISLANDS_CACCONFIG_CGIND },
781 	{ 0x7, 0xffff0000, 16, 0x27, SISLANDS_CACCONFIG_CGIND },
782 	{ 0x8, 0x0000ffff, 0, 0xC3, SISLANDS_CACCONFIG_CGIND },
783 	{ 0x8, 0xffff0000, 16, 0x35, SISLANDS_CACCONFIG_CGIND },
784 	{ 0x9, 0x0000ffff, 0, 0x28, SISLANDS_CACCONFIG_CGIND },
785 	{ 0xa, 0x0000ffff, 0, 0x26C, SISLANDS_CACCONFIG_CGIND },
786 	{ 0xb, 0x0000ffff, 0, 0x3B2, SISLANDS_CACCONFIG_CGIND },
787 	{ 0xb, 0xffff0000, 16, 0x99D, SISLANDS_CACCONFIG_CGIND },
788 	{ 0xc, 0x0000ffff, 0, 0xA3F, SISLANDS_CACCONFIG_CGIND },
789 	{ 0xd, 0x0000ffff, 0, 0xA, SISLANDS_CACCONFIG_CGIND },
790 	{ 0xd, 0xffff0000, 16, 0xA, SISLANDS_CACCONFIG_CGIND },
791 	{ 0xe, 0x0000ffff, 0, 0x5, SISLANDS_CACCONFIG_CGIND },
792 	{ 0xf, 0x0000ffff, 0, 0x3, SISLANDS_CACCONFIG_CGIND },
793 	{ 0xf, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
794 	{ 0x10, 0x0000ffff, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
795 	{ 0x10, 0xffff0000, 16, 0x1, SISLANDS_CACCONFIG_CGIND },
796 	{ 0x11, 0x0000ffff, 0, 0x5, SISLANDS_CACCONFIG_CGIND },
797 	{ 0x11, 0xffff0000, 16, 0x15, SISLANDS_CACCONFIG_CGIND },
798 	{ 0x12, 0x0000ffff, 0, 0x34, SISLANDS_CACCONFIG_CGIND },
799 	{ 0x13, 0x0000ffff, 0, 0x4, SISLANDS_CACCONFIG_CGIND },
800 	{ 0x13, 0xffff0000, 16, 0x4, SISLANDS_CACCONFIG_CGIND },
801 	{ 0x14, 0x0000ffff, 0, 0x30A, SISLANDS_CACCONFIG_CGIND },
802 	{ 0x15, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
803 	{ 0x15, 0xffff0000, 16, 0x6, SISLANDS_CACCONFIG_CGIND },
804 	{ 0x4e, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
805 	{ 0x16, 0x0000ffff, 0, 0x30, SISLANDS_CACCONFIG_CGIND },
806 	{ 0x16, 0xffff0000, 16, 0x7A, SISLANDS_CACCONFIG_CGIND },
807 	{ 0x17, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
808 	{ 0x18, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
809 	{ 0x18, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
810 	{ 0x19, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
811 	{ 0x19, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
812 	{ 0x1a, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
813 	{ 0x1a, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
814 	{ 0x1b, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
815 	{ 0x1b, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
816 	{ 0x1c, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
817 	{ 0x1c, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
818 	{ 0x1d, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
819 	{ 0x1d, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
820 	{ 0x1e, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
821 	{ 0x1e, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
822 	{ 0x1f, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
823 	{ 0x1f, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
824 	{ 0x20, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
825 	{ 0x6d, 0x0000ffff, 0, 0x100, SISLANDS_CACCONFIG_CGIND },
826 	{ 0xFFFFFFFF }
827 };
828 
829 static const struct si_cac_config_reg cac_weights_heathrow[] =
830 {
831 	{ 0x0, 0x0000ffff, 0, 0x82, SISLANDS_CACCONFIG_CGIND },
832 	{ 0x0, 0xffff0000, 16, 0x4F, SISLANDS_CACCONFIG_CGIND },
833 	{ 0x1, 0x0000ffff, 0, 0x153, SISLANDS_CACCONFIG_CGIND },
834 	{ 0x1, 0xffff0000, 16, 0x52, SISLANDS_CACCONFIG_CGIND },
835 	{ 0x2, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
836 	{ 0x3, 0x0000ffff, 0, 0x135, SISLANDS_CACCONFIG_CGIND },
837 	{ 0x3, 0xffff0000, 16, 0x4F, SISLANDS_CACCONFIG_CGIND },
838 	{ 0x4, 0x0000ffff, 0, 0x135, SISLANDS_CACCONFIG_CGIND },
839 	{ 0x4, 0xffff0000, 16, 0xAC, SISLANDS_CACCONFIG_CGIND },
840 	{ 0x5, 0x0000ffff, 0, 0x118, SISLANDS_CACCONFIG_CGIND },
841 	{ 0x5, 0xffff0000, 16, 0xBE, SISLANDS_CACCONFIG_CGIND },
842 	{ 0x6, 0x0000ffff, 0, 0x110, SISLANDS_CACCONFIG_CGIND },
843 	{ 0x6, 0xffff0000, 16, 0x4CD, SISLANDS_CACCONFIG_CGIND },
844 	{ 0x18f, 0x0000ffff, 0, 0x30, SISLANDS_CACCONFIG_CGIND },
845 	{ 0x7, 0x0000ffff, 0, 0x37, SISLANDS_CACCONFIG_CGIND },
846 	{ 0x7, 0xffff0000, 16, 0x27, SISLANDS_CACCONFIG_CGIND },
847 	{ 0x8, 0x0000ffff, 0, 0xC3, SISLANDS_CACCONFIG_CGIND },
848 	{ 0x8, 0xffff0000, 16, 0x35, SISLANDS_CACCONFIG_CGIND },
849 	{ 0x9, 0x0000ffff, 0, 0x28, SISLANDS_CACCONFIG_CGIND },
850 	{ 0xa, 0x0000ffff, 0, 0x26C, SISLANDS_CACCONFIG_CGIND },
851 	{ 0xb, 0x0000ffff, 0, 0x3B2, SISLANDS_CACCONFIG_CGIND },
852 	{ 0xb, 0xffff0000, 16, 0x99D, SISLANDS_CACCONFIG_CGIND },
853 	{ 0xc, 0x0000ffff, 0, 0xA3F, SISLANDS_CACCONFIG_CGIND },
854 	{ 0xd, 0x0000ffff, 0, 0xA, SISLANDS_CACCONFIG_CGIND },
855 	{ 0xd, 0xffff0000, 16, 0xA, SISLANDS_CACCONFIG_CGIND },
856 	{ 0xe, 0x0000ffff, 0, 0x5, SISLANDS_CACCONFIG_CGIND },
857 	{ 0xf, 0x0000ffff, 0, 0x3, SISLANDS_CACCONFIG_CGIND },
858 	{ 0xf, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
859 	{ 0x10, 0x0000ffff, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
860 	{ 0x10, 0xffff0000, 16, 0x1, SISLANDS_CACCONFIG_CGIND },
861 	{ 0x11, 0x0000ffff, 0, 0x5, SISLANDS_CACCONFIG_CGIND },
862 	{ 0x11, 0xffff0000, 16, 0x15, SISLANDS_CACCONFIG_CGIND },
863 	{ 0x12, 0x0000ffff, 0, 0x34, SISLANDS_CACCONFIG_CGIND },
864 	{ 0x13, 0x0000ffff, 0, 0x4, SISLANDS_CACCONFIG_CGIND },
865 	{ 0x13, 0xffff0000, 16, 0x4, SISLANDS_CACCONFIG_CGIND },
866 	{ 0x14, 0x0000ffff, 0, 0x362, SISLANDS_CACCONFIG_CGIND },
867 	{ 0x15, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
868 	{ 0x15, 0xffff0000, 16, 0x6, SISLANDS_CACCONFIG_CGIND },
869 	{ 0x4e, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
870 	{ 0x16, 0x0000ffff, 0, 0x30, SISLANDS_CACCONFIG_CGIND },
871 	{ 0x16, 0xffff0000, 16, 0x7A, SISLANDS_CACCONFIG_CGIND },
872 	{ 0x17, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
873 	{ 0x18, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
874 	{ 0x18, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
875 	{ 0x19, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
876 	{ 0x19, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
877 	{ 0x1a, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
878 	{ 0x1a, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
879 	{ 0x1b, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
880 	{ 0x1b, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
881 	{ 0x1c, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
882 	{ 0x1c, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
883 	{ 0x1d, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
884 	{ 0x1d, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
885 	{ 0x1e, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
886 	{ 0x1e, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
887 	{ 0x1f, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
888 	{ 0x1f, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
889 	{ 0x20, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
890 	{ 0x6d, 0x0000ffff, 0, 0x100, SISLANDS_CACCONFIG_CGIND },
891 	{ 0xFFFFFFFF }
892 };
893 
894 static const struct si_cac_config_reg cac_weights_cape_verde_pro[] =
895 {
896 	{ 0x0, 0x0000ffff, 0, 0x82, SISLANDS_CACCONFIG_CGIND },
897 	{ 0x0, 0xffff0000, 16, 0x4F, SISLANDS_CACCONFIG_CGIND },
898 	{ 0x1, 0x0000ffff, 0, 0x153, SISLANDS_CACCONFIG_CGIND },
899 	{ 0x1, 0xffff0000, 16, 0x52, SISLANDS_CACCONFIG_CGIND },
900 	{ 0x2, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
901 	{ 0x3, 0x0000ffff, 0, 0x135, SISLANDS_CACCONFIG_CGIND },
902 	{ 0x3, 0xffff0000, 16, 0x4F, SISLANDS_CACCONFIG_CGIND },
903 	{ 0x4, 0x0000ffff, 0, 0x135, SISLANDS_CACCONFIG_CGIND },
904 	{ 0x4, 0xffff0000, 16, 0xAC, SISLANDS_CACCONFIG_CGIND },
905 	{ 0x5, 0x0000ffff, 0, 0x118, SISLANDS_CACCONFIG_CGIND },
906 	{ 0x5, 0xffff0000, 16, 0xBE, SISLANDS_CACCONFIG_CGIND },
907 	{ 0x6, 0x0000ffff, 0, 0x110, SISLANDS_CACCONFIG_CGIND },
908 	{ 0x6, 0xffff0000, 16, 0x4CD, SISLANDS_CACCONFIG_CGIND },
909 	{ 0x18f, 0x0000ffff, 0, 0x30, SISLANDS_CACCONFIG_CGIND },
910 	{ 0x7, 0x0000ffff, 0, 0x37, SISLANDS_CACCONFIG_CGIND },
911 	{ 0x7, 0xffff0000, 16, 0x27, SISLANDS_CACCONFIG_CGIND },
912 	{ 0x8, 0x0000ffff, 0, 0xC3, SISLANDS_CACCONFIG_CGIND },
913 	{ 0x8, 0xffff0000, 16, 0x35, SISLANDS_CACCONFIG_CGIND },
914 	{ 0x9, 0x0000ffff, 0, 0x28, SISLANDS_CACCONFIG_CGIND },
915 	{ 0xa, 0x0000ffff, 0, 0x26C, SISLANDS_CACCONFIG_CGIND },
916 	{ 0xb, 0x0000ffff, 0, 0x3B2, SISLANDS_CACCONFIG_CGIND },
917 	{ 0xb, 0xffff0000, 16, 0x99D, SISLANDS_CACCONFIG_CGIND },
918 	{ 0xc, 0x0000ffff, 0, 0xA3F, SISLANDS_CACCONFIG_CGIND },
919 	{ 0xd, 0x0000ffff, 0, 0xA, SISLANDS_CACCONFIG_CGIND },
920 	{ 0xd, 0xffff0000, 16, 0xA, SISLANDS_CACCONFIG_CGIND },
921 	{ 0xe, 0x0000ffff, 0, 0x5, SISLANDS_CACCONFIG_CGIND },
922 	{ 0xf, 0x0000ffff, 0, 0x3, SISLANDS_CACCONFIG_CGIND },
923 	{ 0xf, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
924 	{ 0x10, 0x0000ffff, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
925 	{ 0x10, 0xffff0000, 16, 0x1, SISLANDS_CACCONFIG_CGIND },
926 	{ 0x11, 0x0000ffff, 0, 0x5, SISLANDS_CACCONFIG_CGIND },
927 	{ 0x11, 0xffff0000, 16, 0x15, SISLANDS_CACCONFIG_CGIND },
928 	{ 0x12, 0x0000ffff, 0, 0x34, SISLANDS_CACCONFIG_CGIND },
929 	{ 0x13, 0x0000ffff, 0, 0x4, SISLANDS_CACCONFIG_CGIND },
930 	{ 0x13, 0xffff0000, 16, 0x4, SISLANDS_CACCONFIG_CGIND },
931 	{ 0x14, 0x0000ffff, 0, 0x315, SISLANDS_CACCONFIG_CGIND },
932 	{ 0x15, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
933 	{ 0x15, 0xffff0000, 16, 0x6, SISLANDS_CACCONFIG_CGIND },
934 	{ 0x4e, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
935 	{ 0x16, 0x0000ffff, 0, 0x30, SISLANDS_CACCONFIG_CGIND },
936 	{ 0x16, 0xffff0000, 16, 0x7A, SISLANDS_CACCONFIG_CGIND },
937 	{ 0x17, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
938 	{ 0x18, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
939 	{ 0x18, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
940 	{ 0x19, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
941 	{ 0x19, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
942 	{ 0x1a, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
943 	{ 0x1a, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
944 	{ 0x1b, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
945 	{ 0x1b, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
946 	{ 0x1c, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
947 	{ 0x1c, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
948 	{ 0x1d, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
949 	{ 0x1d, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
950 	{ 0x1e, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
951 	{ 0x1e, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
952 	{ 0x1f, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
953 	{ 0x1f, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
954 	{ 0x20, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
955 	{ 0x6d, 0x0000ffff, 0, 0x100, SISLANDS_CACCONFIG_CGIND },
956 	{ 0xFFFFFFFF }
957 };
958 
959 static const struct si_cac_config_reg cac_weights_cape_verde[] =
960 {
961 	{ 0x0, 0x0000ffff, 0, 0x82, SISLANDS_CACCONFIG_CGIND },
962 	{ 0x0, 0xffff0000, 16, 0x4F, SISLANDS_CACCONFIG_CGIND },
963 	{ 0x1, 0x0000ffff, 0, 0x153, SISLANDS_CACCONFIG_CGIND },
964 	{ 0x1, 0xffff0000, 16, 0x52, SISLANDS_CACCONFIG_CGIND },
965 	{ 0x2, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
966 	{ 0x3, 0x0000ffff, 0, 0x135, SISLANDS_CACCONFIG_CGIND },
967 	{ 0x3, 0xffff0000, 16, 0x4F, SISLANDS_CACCONFIG_CGIND },
968 	{ 0x4, 0x0000ffff, 0, 0x135, SISLANDS_CACCONFIG_CGIND },
969 	{ 0x4, 0xffff0000, 16, 0xAC, SISLANDS_CACCONFIG_CGIND },
970 	{ 0x5, 0x0000ffff, 0, 0x118, SISLANDS_CACCONFIG_CGIND },
971 	{ 0x5, 0xffff0000, 16, 0xBE, SISLANDS_CACCONFIG_CGIND },
972 	{ 0x6, 0x0000ffff, 0, 0x110, SISLANDS_CACCONFIG_CGIND },
973 	{ 0x6, 0xffff0000, 16, 0x4CD, SISLANDS_CACCONFIG_CGIND },
974 	{ 0x18f, 0x0000ffff, 0, 0x30, SISLANDS_CACCONFIG_CGIND },
975 	{ 0x7, 0x0000ffff, 0, 0x37, SISLANDS_CACCONFIG_CGIND },
976 	{ 0x7, 0xffff0000, 16, 0x27, SISLANDS_CACCONFIG_CGIND },
977 	{ 0x8, 0x0000ffff, 0, 0xC3, SISLANDS_CACCONFIG_CGIND },
978 	{ 0x8, 0xffff0000, 16, 0x35, SISLANDS_CACCONFIG_CGIND },
979 	{ 0x9, 0x0000ffff, 0, 0x28, SISLANDS_CACCONFIG_CGIND },
980 	{ 0xa, 0x0000ffff, 0, 0x26C, SISLANDS_CACCONFIG_CGIND },
981 	{ 0xb, 0x0000ffff, 0, 0x3B2, SISLANDS_CACCONFIG_CGIND },
982 	{ 0xb, 0xffff0000, 16, 0x99D, SISLANDS_CACCONFIG_CGIND },
983 	{ 0xc, 0x0000ffff, 0, 0xA3F, SISLANDS_CACCONFIG_CGIND },
984 	{ 0xd, 0x0000ffff, 0, 0xA, SISLANDS_CACCONFIG_CGIND },
985 	{ 0xd, 0xffff0000, 16, 0xA, SISLANDS_CACCONFIG_CGIND },
986 	{ 0xe, 0x0000ffff, 0, 0x5, SISLANDS_CACCONFIG_CGIND },
987 	{ 0xf, 0x0000ffff, 0, 0x3, SISLANDS_CACCONFIG_CGIND },
988 	{ 0xf, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
989 	{ 0x10, 0x0000ffff, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
990 	{ 0x10, 0xffff0000, 16, 0x1, SISLANDS_CACCONFIG_CGIND },
991 	{ 0x11, 0x0000ffff, 0, 0x5, SISLANDS_CACCONFIG_CGIND },
992 	{ 0x11, 0xffff0000, 16, 0x15, SISLANDS_CACCONFIG_CGIND },
993 	{ 0x12, 0x0000ffff, 0, 0x34, SISLANDS_CACCONFIG_CGIND },
994 	{ 0x13, 0x0000ffff, 0, 0x4, SISLANDS_CACCONFIG_CGIND },
995 	{ 0x13, 0xffff0000, 16, 0x4, SISLANDS_CACCONFIG_CGIND },
996 	{ 0x14, 0x0000ffff, 0, 0x3BA, SISLANDS_CACCONFIG_CGIND },
997 	{ 0x15, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
998 	{ 0x15, 0xffff0000, 16, 0x6, SISLANDS_CACCONFIG_CGIND },
999 	{ 0x4e, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1000 	{ 0x16, 0x0000ffff, 0, 0x30, SISLANDS_CACCONFIG_CGIND },
1001 	{ 0x16, 0xffff0000, 16, 0x7A, SISLANDS_CACCONFIG_CGIND },
1002 	{ 0x17, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1003 	{ 0x18, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1004 	{ 0x18, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
1005 	{ 0x19, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1006 	{ 0x19, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
1007 	{ 0x1a, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
1008 	{ 0x1a, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
1009 	{ 0x1b, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
1010 	{ 0x1b, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
1011 	{ 0x1c, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
1012 	{ 0x1c, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
1013 	{ 0x1d, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
1014 	{ 0x1d, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
1015 	{ 0x1e, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
1016 	{ 0x1e, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
1017 	{ 0x1f, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
1018 	{ 0x1f, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
1019 	{ 0x20, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
1020 	{ 0x6d, 0x0000ffff, 0, 0x100, SISLANDS_CACCONFIG_CGIND },
1021 	{ 0xFFFFFFFF }
1022 };
1023 
1024 static const struct si_cac_config_reg lcac_cape_verde[] =
1025 {
1026 	{ 0x98, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
1027 	{ 0x98, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1028 	{ 0x104, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
1029 	{ 0x104, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1030 	{ 0x110, 0x0001fffe, 1, 0x5, SISLANDS_CACCONFIG_CGIND },
1031 	{ 0x110, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1032 	{ 0x14f, 0x0001fffe, 1, 0x5, SISLANDS_CACCONFIG_CGIND },
1033 	{ 0x14f, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1034 	{ 0x8c, 0x0001fffe, 1, 0x5, SISLANDS_CACCONFIG_CGIND },
1035 	{ 0x8c, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1036 	{ 0x143, 0x0001fffe, 1, 0x1, SISLANDS_CACCONFIG_CGIND },
1037 	{ 0x143, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1038 	{ 0x9b, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
1039 	{ 0x9b, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1040 	{ 0x107, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
1041 	{ 0x107, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1042 	{ 0x113, 0x0001fffe, 1, 0x5, SISLANDS_CACCONFIG_CGIND },
1043 	{ 0x113, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1044 	{ 0x152, 0x0001fffe, 1, 0x5, SISLANDS_CACCONFIG_CGIND },
1045 	{ 0x152, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1046 	{ 0x8f, 0x0001fffe, 1, 0x1, SISLANDS_CACCONFIG_CGIND },
1047 	{ 0x8f, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1048 	{ 0x146, 0x0001fffe, 1, 0x1, SISLANDS_CACCONFIG_CGIND },
1049 	{ 0x146, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1050 	{ 0x11c, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
1051 	{ 0x11c, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1052 	{ 0x11f, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
1053 	{ 0x11f, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1054 	{ 0x164, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
1055 	{ 0x164, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1056 	{ 0x167, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
1057 	{ 0x167, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1058 	{ 0x16a, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
1059 	{ 0x16a, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1060 	{ 0x15e, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
1061 	{ 0x15e, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1062 	{ 0x161, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
1063 	{ 0x161, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1064 	{ 0x15b, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
1065 	{ 0x15b, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1066 	{ 0x16d, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
1067 	{ 0x16d, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1068 	{ 0x170, 0x0001fffe, 1, 0x1, SISLANDS_CACCONFIG_CGIND },
1069 	{ 0x170, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1070 	{ 0x173, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
1071 	{ 0x173, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1072 	{ 0x176, 0x0001fffe, 1, 0x1, SISLANDS_CACCONFIG_CGIND },
1073 	{ 0x176, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1074 	{ 0x179, 0x0001fffe, 1, 0x1, SISLANDS_CACCONFIG_CGIND },
1075 	{ 0x179, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1076 	{ 0x17c, 0x0001fffe, 1, 0x1, SISLANDS_CACCONFIG_CGIND },
1077 	{ 0x17c, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1078 	{ 0x17f, 0x0001fffe, 1, 0x1, SISLANDS_CACCONFIG_CGIND },
1079 	{ 0x17f, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1080 	{ 0xFFFFFFFF }
1081 };
1082 
1083 static const struct si_cac_config_reg cac_override_cape_verde[] =
1084 {
1085     { 0xFFFFFFFF }
1086 };
1087 
1088 static const struct si_powertune_data powertune_data_cape_verde =
1089 {
1090 	((1 << 16) | 0x6993),
1091 	5,
1092 	0,
1093 	7,
1094 	105,
1095 	{
1096 		0UL,
1097 		0UL,
1098 		7194395UL,
1099 		309631529UL,
1100 		-1270850L,
1101 		4513710L,
1102 		100
1103 	},
1104 	117830498UL,
1105 	12,
1106 	{
1107 		0,
1108 		0,
1109 		0,
1110 		0,
1111 		0,
1112 		0,
1113 		0,
1114 		0
1115 	},
1116 	true
1117 };
1118 
1119 static const struct si_dte_data dte_data_cape_verde =
1120 {
1121 	{ 0, 0, 0, 0, 0 },
1122 	{ 0, 0, 0, 0, 0 },
1123 	0,
1124 	0,
1125 	0,
1126 	0,
1127 	0,
1128 	0,
1129 	0,
1130 	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
1131 	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
1132 	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
1133 	0,
1134 	false
1135 };
1136 
1137 static const struct si_dte_data dte_data_venus_xtx =
1138 {
1139 	{ 0x1E8480, 0x3D0900, 0x989680, 0x2625A00, 0x0 },
1140 	{ 0x71C, 0xAAB, 0xE39, 0x11C7, 0x0 },
1141 	5,
1142 	55000,
1143 	0x69,
1144 	0xA,
1145 	1,
1146 	0,
1147 	0x3,
1148 	{ 0x96, 0xB4, 0xFF, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 },
1149 	{ 0x895440, 0x3D0900, 0x989680, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 },
1150 	{ 0xD6D8, 0x88B8, 0x1555, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 },
1151 	90,
1152 	true
1153 };
1154 
1155 static const struct si_dte_data dte_data_venus_xt =
1156 {
1157 	{ 0x1E8480, 0x3D0900, 0x989680, 0x2625A00, 0x0 },
1158 	{ 0xBDA, 0x11C7, 0x17B4, 0x1DA1, 0x0 },
1159 	5,
1160 	55000,
1161 	0x69,
1162 	0xA,
1163 	1,
1164 	0,
1165 	0x3,
1166 	{ 0x96, 0xB4, 0xFF, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 },
1167 	{ 0x895440, 0x3D0900, 0x989680, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 },
1168 	{ 0xAFC8, 0x88B8, 0x238E, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 },
1169 	90,
1170 	true
1171 };
1172 
1173 static const struct si_dte_data dte_data_venus_pro =
1174 {
1175 	{  0x1E8480, 0x3D0900, 0x989680, 0x2625A00, 0x0 },
1176 	{ 0x11C7, 0x1AAB, 0x238E, 0x2C72, 0x0 },
1177 	5,
1178 	55000,
1179 	0x69,
1180 	0xA,
1181 	1,
1182 	0,
1183 	0x3,
1184 	{ 0x96, 0xB4, 0xFF, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 },
1185 	{ 0x895440, 0x3D0900, 0x989680, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 },
1186 	{ 0x88B8, 0x88B8, 0x3555, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 },
1187 	90,
1188 	true
1189 };
1190 
1191 static const struct si_cac_config_reg cac_weights_oland[] =
1192 {
1193 	{ 0x0, 0x0000ffff, 0, 0x82, SISLANDS_CACCONFIG_CGIND },
1194 	{ 0x0, 0xffff0000, 16, 0x4F, SISLANDS_CACCONFIG_CGIND },
1195 	{ 0x1, 0x0000ffff, 0, 0x153, SISLANDS_CACCONFIG_CGIND },
1196 	{ 0x1, 0xffff0000, 16, 0x52, SISLANDS_CACCONFIG_CGIND },
1197 	{ 0x2, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1198 	{ 0x3, 0x0000ffff, 0, 0x135, SISLANDS_CACCONFIG_CGIND },
1199 	{ 0x3, 0xffff0000, 16, 0x4F, SISLANDS_CACCONFIG_CGIND },
1200 	{ 0x4, 0x0000ffff, 0, 0x135, SISLANDS_CACCONFIG_CGIND },
1201 	{ 0x4, 0xffff0000, 16, 0xAC, SISLANDS_CACCONFIG_CGIND },
1202 	{ 0x5, 0x0000ffff, 0, 0x118, SISLANDS_CACCONFIG_CGIND },
1203 	{ 0x5, 0xffff0000, 16, 0xBE, SISLANDS_CACCONFIG_CGIND },
1204 	{ 0x6, 0x0000ffff, 0, 0x110, SISLANDS_CACCONFIG_CGIND },
1205 	{ 0x6, 0xffff0000, 16, 0x4CD, SISLANDS_CACCONFIG_CGIND },
1206 	{ 0x18f, 0x0000ffff, 0, 0x30, SISLANDS_CACCONFIG_CGIND },
1207 	{ 0x7, 0x0000ffff, 0, 0x37, SISLANDS_CACCONFIG_CGIND },
1208 	{ 0x7, 0xffff0000, 16, 0x27, SISLANDS_CACCONFIG_CGIND },
1209 	{ 0x8, 0x0000ffff, 0, 0xC3, SISLANDS_CACCONFIG_CGIND },
1210 	{ 0x8, 0xffff0000, 16, 0x35, SISLANDS_CACCONFIG_CGIND },
1211 	{ 0x9, 0x0000ffff, 0, 0x28, SISLANDS_CACCONFIG_CGIND },
1212 	{ 0xa, 0x0000ffff, 0, 0x26C, SISLANDS_CACCONFIG_CGIND },
1213 	{ 0xb, 0x0000ffff, 0, 0x3B2, SISLANDS_CACCONFIG_CGIND },
1214 	{ 0xb, 0xffff0000, 16, 0x99D, SISLANDS_CACCONFIG_CGIND },
1215 	{ 0xc, 0x0000ffff, 0, 0xA3F, SISLANDS_CACCONFIG_CGIND },
1216 	{ 0xd, 0x0000ffff, 0, 0xA, SISLANDS_CACCONFIG_CGIND },
1217 	{ 0xd, 0xffff0000, 16, 0xA, SISLANDS_CACCONFIG_CGIND },
1218 	{ 0xe, 0x0000ffff, 0, 0x5, SISLANDS_CACCONFIG_CGIND },
1219 	{ 0xf, 0x0000ffff, 0, 0x3, SISLANDS_CACCONFIG_CGIND },
1220 	{ 0xf, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
1221 	{ 0x10, 0x0000ffff, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1222 	{ 0x10, 0xffff0000, 16, 0x1, SISLANDS_CACCONFIG_CGIND },
1223 	{ 0x11, 0x0000ffff, 0, 0x5, SISLANDS_CACCONFIG_CGIND },
1224 	{ 0x11, 0xffff0000, 16, 0x15, SISLANDS_CACCONFIG_CGIND },
1225 	{ 0x12, 0x0000ffff, 0, 0x34, SISLANDS_CACCONFIG_CGIND },
1226 	{ 0x13, 0x0000ffff, 0, 0x4, SISLANDS_CACCONFIG_CGIND },
1227 	{ 0x13, 0xffff0000, 16, 0x4, SISLANDS_CACCONFIG_CGIND },
1228 	{ 0x14, 0x0000ffff, 0, 0x3BA, SISLANDS_CACCONFIG_CGIND },
1229 	{ 0x15, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1230 	{ 0x15, 0xffff0000, 16, 0x6, SISLANDS_CACCONFIG_CGIND },
1231 	{ 0x4e, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1232 	{ 0x16, 0x0000ffff, 0, 0x30, SISLANDS_CACCONFIG_CGIND },
1233 	{ 0x16, 0xffff0000, 16, 0x7A, SISLANDS_CACCONFIG_CGIND },
1234 	{ 0x17, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1235 	{ 0x18, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1236 	{ 0x18, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
1237 	{ 0x19, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1238 	{ 0x19, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
1239 	{ 0x1a, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
1240 	{ 0x1a, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
1241 	{ 0x1b, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
1242 	{ 0x1b, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
1243 	{ 0x1c, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
1244 	{ 0x1c, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
1245 	{ 0x1d, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
1246 	{ 0x1d, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
1247 	{ 0x1e, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
1248 	{ 0x1e, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
1249 	{ 0x1f, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
1250 	{ 0x1f, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
1251 	{ 0x20, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
1252 	{ 0x6d, 0x0000ffff, 0, 0x100, SISLANDS_CACCONFIG_CGIND },
1253 	{ 0xFFFFFFFF }
1254 };
1255 
1256 static const struct si_cac_config_reg cac_weights_mars_pro[] =
1257 {
1258 	{ 0x0, 0x0000ffff, 0, 0x43, SISLANDS_CACCONFIG_CGIND },
1259 	{ 0x0, 0xffff0000, 16, 0x29, SISLANDS_CACCONFIG_CGIND },
1260 	{ 0x1, 0x0000ffff, 0, 0xAF, SISLANDS_CACCONFIG_CGIND },
1261 	{ 0x1, 0xffff0000, 16, 0x2A, SISLANDS_CACCONFIG_CGIND },
1262 	{ 0x2, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1263 	{ 0x3, 0x0000ffff, 0, 0xA0, SISLANDS_CACCONFIG_CGIND },
1264 	{ 0x3, 0xffff0000, 16, 0x29, SISLANDS_CACCONFIG_CGIND },
1265 	{ 0x4, 0x0000ffff, 0, 0xA0, SISLANDS_CACCONFIG_CGIND },
1266 	{ 0x4, 0xffff0000, 16, 0x59, SISLANDS_CACCONFIG_CGIND },
1267 	{ 0x5, 0x0000ffff, 0, 0x1A5, SISLANDS_CACCONFIG_CGIND },
1268 	{ 0x5, 0xffff0000, 16, 0x1D6, SISLANDS_CACCONFIG_CGIND },
1269 	{ 0x6, 0x0000ffff, 0, 0x2A3, SISLANDS_CACCONFIG_CGIND },
1270 	{ 0x6, 0xffff0000, 16, 0x8FD, SISLANDS_CACCONFIG_CGIND },
1271 	{ 0x18f, 0x0000ffff, 0, 0x76, SISLANDS_CACCONFIG_CGIND },
1272 	{ 0x7, 0x0000ffff, 0, 0x8A, SISLANDS_CACCONFIG_CGIND },
1273 	{ 0x7, 0xffff0000, 16, 0xA3, SISLANDS_CACCONFIG_CGIND },
1274 	{ 0x8, 0x0000ffff, 0, 0x71, SISLANDS_CACCONFIG_CGIND },
1275 	{ 0x8, 0xffff0000, 16, 0x36, SISLANDS_CACCONFIG_CGIND },
1276 	{ 0x9, 0x0000ffff, 0, 0xA6, SISLANDS_CACCONFIG_CGIND },
1277 	{ 0xa, 0x0000ffff, 0, 0x81, SISLANDS_CACCONFIG_CGIND },
1278 	{ 0xb, 0x0000ffff, 0, 0x3D2, SISLANDS_CACCONFIG_CGIND },
1279 	{ 0xb, 0xffff0000, 16, 0x27C, SISLANDS_CACCONFIG_CGIND },
1280 	{ 0xc, 0x0000ffff, 0, 0xA96, SISLANDS_CACCONFIG_CGIND },
1281 	{ 0xd, 0x0000ffff, 0, 0x5, SISLANDS_CACCONFIG_CGIND },
1282 	{ 0xd, 0xffff0000, 16, 0x5, SISLANDS_CACCONFIG_CGIND },
1283 	{ 0xe, 0x0000ffff, 0, 0xB, SISLANDS_CACCONFIG_CGIND },
1284 	{ 0xf, 0x0000ffff, 0, 0x3, SISLANDS_CACCONFIG_CGIND },
1285 	{ 0xf, 0xffff0000, 16, 0x2, SISLANDS_CACCONFIG_CGIND },
1286 	{ 0x10, 0x0000ffff, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1287 	{ 0x10, 0xffff0000, 16, 0x4, SISLANDS_CACCONFIG_CGIND },
1288 	{ 0x11, 0x0000ffff, 0, 0x15, SISLANDS_CACCONFIG_CGIND },
1289 	{ 0x11, 0xffff0000, 16, 0x7, SISLANDS_CACCONFIG_CGIND },
1290 	{ 0x12, 0x0000ffff, 0, 0x36, SISLANDS_CACCONFIG_CGIND },
1291 	{ 0x13, 0x0000ffff, 0, 0x10, SISLANDS_CACCONFIG_CGIND },
1292 	{ 0x13, 0xffff0000, 16, 0x10, SISLANDS_CACCONFIG_CGIND },
1293 	{ 0x14, 0x0000ffff, 0, 0x2, SISLANDS_CACCONFIG_CGIND },
1294 	{ 0x15, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1295 	{ 0x15, 0xffff0000, 16, 0x6, SISLANDS_CACCONFIG_CGIND },
1296 	{ 0x4e, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1297 	{ 0x16, 0x0000ffff, 0, 0x32, SISLANDS_CACCONFIG_CGIND },
1298 	{ 0x16, 0xffff0000, 16, 0x7E, SISLANDS_CACCONFIG_CGIND },
1299 	{ 0x17, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1300 	{ 0x18, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1301 	{ 0x18, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
1302 	{ 0x19, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1303 	{ 0x19, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
1304 	{ 0x1a, 0x0000ffff, 0, 0x280, SISLANDS_CACCONFIG_CGIND },
1305 	{ 0x1a, 0xffff0000, 16, 0x7, SISLANDS_CACCONFIG_CGIND },
1306 	{ 0x1b, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1307 	{ 0x1b, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
1308 	{ 0x1c, 0x0000ffff, 0, 0x3C, SISLANDS_CACCONFIG_CGIND },
1309 	{ 0x1c, 0xffff0000, 16, 0x203, SISLANDS_CACCONFIG_CGIND },
1310 	{ 0x1d, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1311 	{ 0x1d, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
1312 	{ 0x1e, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
1313 	{ 0x1e, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
1314 	{ 0x1f, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
1315 	{ 0x1f, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
1316 	{ 0x20, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
1317 	{ 0x6d, 0x0000ffff, 0, 0xB4, SISLANDS_CACCONFIG_CGIND },
1318 	{ 0xFFFFFFFF }
1319 };
1320 
1321 static const struct si_cac_config_reg cac_weights_mars_xt[] =
1322 {
1323 	{ 0x0, 0x0000ffff, 0, 0x43, SISLANDS_CACCONFIG_CGIND },
1324 	{ 0x0, 0xffff0000, 16, 0x29, SISLANDS_CACCONFIG_CGIND },
1325 	{ 0x1, 0x0000ffff, 0, 0xAF, SISLANDS_CACCONFIG_CGIND },
1326 	{ 0x1, 0xffff0000, 16, 0x2A, SISLANDS_CACCONFIG_CGIND },
1327 	{ 0x2, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1328 	{ 0x3, 0x0000ffff, 0, 0xA0, SISLANDS_CACCONFIG_CGIND },
1329 	{ 0x3, 0xffff0000, 16, 0x29, SISLANDS_CACCONFIG_CGIND },
1330 	{ 0x4, 0x0000ffff, 0, 0xA0, SISLANDS_CACCONFIG_CGIND },
1331 	{ 0x4, 0xffff0000, 16, 0x59, SISLANDS_CACCONFIG_CGIND },
1332 	{ 0x5, 0x0000ffff, 0, 0x1A5, SISLANDS_CACCONFIG_CGIND },
1333 	{ 0x5, 0xffff0000, 16, 0x1D6, SISLANDS_CACCONFIG_CGIND },
1334 	{ 0x6, 0x0000ffff, 0, 0x2A3, SISLANDS_CACCONFIG_CGIND },
1335 	{ 0x6, 0xffff0000, 16, 0x8FD, SISLANDS_CACCONFIG_CGIND },
1336 	{ 0x18f, 0x0000ffff, 0, 0x76, SISLANDS_CACCONFIG_CGIND },
1337 	{ 0x7, 0x0000ffff, 0, 0x8A, SISLANDS_CACCONFIG_CGIND },
1338 	{ 0x7, 0xffff0000, 16, 0xA3, SISLANDS_CACCONFIG_CGIND },
1339 	{ 0x8, 0x0000ffff, 0, 0x71, SISLANDS_CACCONFIG_CGIND },
1340 	{ 0x8, 0xffff0000, 16, 0x36, SISLANDS_CACCONFIG_CGIND },
1341 	{ 0x9, 0x0000ffff, 0, 0xA6, SISLANDS_CACCONFIG_CGIND },
1342 	{ 0xa, 0x0000ffff, 0, 0x81, SISLANDS_CACCONFIG_CGIND },
1343 	{ 0xb, 0x0000ffff, 0, 0x3D2, SISLANDS_CACCONFIG_CGIND },
1344 	{ 0xb, 0xffff0000, 16, 0x27C, SISLANDS_CACCONFIG_CGIND },
1345 	{ 0xc, 0x0000ffff, 0, 0xA96, SISLANDS_CACCONFIG_CGIND },
1346 	{ 0xd, 0x0000ffff, 0, 0x5, SISLANDS_CACCONFIG_CGIND },
1347 	{ 0xd, 0xffff0000, 16, 0x5, SISLANDS_CACCONFIG_CGIND },
1348 	{ 0xe, 0x0000ffff, 0, 0xB, SISLANDS_CACCONFIG_CGIND },
1349 	{ 0xf, 0x0000ffff, 0, 0x3, SISLANDS_CACCONFIG_CGIND },
1350 	{ 0xf, 0xffff0000, 16, 0x2, SISLANDS_CACCONFIG_CGIND },
1351 	{ 0x10, 0x0000ffff, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1352 	{ 0x10, 0xffff0000, 16, 0x4, SISLANDS_CACCONFIG_CGIND },
1353 	{ 0x11, 0x0000ffff, 0, 0x15, SISLANDS_CACCONFIG_CGIND },
1354 	{ 0x11, 0xffff0000, 16, 0x7, SISLANDS_CACCONFIG_CGIND },
1355 	{ 0x12, 0x0000ffff, 0, 0x36, SISLANDS_CACCONFIG_CGIND },
1356 	{ 0x13, 0x0000ffff, 0, 0x10, SISLANDS_CACCONFIG_CGIND },
1357 	{ 0x13, 0xffff0000, 16, 0x10, SISLANDS_CACCONFIG_CGIND },
1358 	{ 0x14, 0x0000ffff, 0, 0x60, SISLANDS_CACCONFIG_CGIND },
1359 	{ 0x15, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1360 	{ 0x15, 0xffff0000, 16, 0x6, SISLANDS_CACCONFIG_CGIND },
1361 	{ 0x4e, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1362 	{ 0x16, 0x0000ffff, 0, 0x32, SISLANDS_CACCONFIG_CGIND },
1363 	{ 0x16, 0xffff0000, 16, 0x7E, SISLANDS_CACCONFIG_CGIND },
1364 	{ 0x17, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1365 	{ 0x18, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1366 	{ 0x18, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
1367 	{ 0x19, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1368 	{ 0x19, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
1369 	{ 0x1a, 0x0000ffff, 0, 0x280, SISLANDS_CACCONFIG_CGIND },
1370 	{ 0x1a, 0xffff0000, 16, 0x7, SISLANDS_CACCONFIG_CGIND },
1371 	{ 0x1b, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1372 	{ 0x1b, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
1373 	{ 0x1c, 0x0000ffff, 0, 0x3C, SISLANDS_CACCONFIG_CGIND },
1374 	{ 0x1c, 0xffff0000, 16, 0x203, SISLANDS_CACCONFIG_CGIND },
1375 	{ 0x1d, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1376 	{ 0x1d, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
1377 	{ 0x1e, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
1378 	{ 0x1e, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
1379 	{ 0x1f, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
1380 	{ 0x1f, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
1381 	{ 0x20, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
1382 	{ 0x6d, 0x0000ffff, 0, 0xB4, SISLANDS_CACCONFIG_CGIND },
1383 	{ 0xFFFFFFFF }
1384 };
1385 
1386 static const struct si_cac_config_reg cac_weights_oland_pro[] =
1387 {
1388 	{ 0x0, 0x0000ffff, 0, 0x43, SISLANDS_CACCONFIG_CGIND },
1389 	{ 0x0, 0xffff0000, 16, 0x29, SISLANDS_CACCONFIG_CGIND },
1390 	{ 0x1, 0x0000ffff, 0, 0xAF, SISLANDS_CACCONFIG_CGIND },
1391 	{ 0x1, 0xffff0000, 16, 0x2A, SISLANDS_CACCONFIG_CGIND },
1392 	{ 0x2, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1393 	{ 0x3, 0x0000ffff, 0, 0xA0, SISLANDS_CACCONFIG_CGIND },
1394 	{ 0x3, 0xffff0000, 16, 0x29, SISLANDS_CACCONFIG_CGIND },
1395 	{ 0x4, 0x0000ffff, 0, 0xA0, SISLANDS_CACCONFIG_CGIND },
1396 	{ 0x4, 0xffff0000, 16, 0x59, SISLANDS_CACCONFIG_CGIND },
1397 	{ 0x5, 0x0000ffff, 0, 0x1A5, SISLANDS_CACCONFIG_CGIND },
1398 	{ 0x5, 0xffff0000, 16, 0x1D6, SISLANDS_CACCONFIG_CGIND },
1399 	{ 0x6, 0x0000ffff, 0, 0x2A3, SISLANDS_CACCONFIG_CGIND },
1400 	{ 0x6, 0xffff0000, 16, 0x8FD, SISLANDS_CACCONFIG_CGIND },
1401 	{ 0x18f, 0x0000ffff, 0, 0x76, SISLANDS_CACCONFIG_CGIND },
1402 	{ 0x7, 0x0000ffff, 0, 0x8A, SISLANDS_CACCONFIG_CGIND },
1403 	{ 0x7, 0xffff0000, 16, 0xA3, SISLANDS_CACCONFIG_CGIND },
1404 	{ 0x8, 0x0000ffff, 0, 0x71, SISLANDS_CACCONFIG_CGIND },
1405 	{ 0x8, 0xffff0000, 16, 0x36, SISLANDS_CACCONFIG_CGIND },
1406 	{ 0x9, 0x0000ffff, 0, 0xA6, SISLANDS_CACCONFIG_CGIND },
1407 	{ 0xa, 0x0000ffff, 0, 0x81, SISLANDS_CACCONFIG_CGIND },
1408 	{ 0xb, 0x0000ffff, 0, 0x3D2, SISLANDS_CACCONFIG_CGIND },
1409 	{ 0xb, 0xffff0000, 16, 0x27C, SISLANDS_CACCONFIG_CGIND },
1410 	{ 0xc, 0x0000ffff, 0, 0xA96, SISLANDS_CACCONFIG_CGIND },
1411 	{ 0xd, 0x0000ffff, 0, 0x5, SISLANDS_CACCONFIG_CGIND },
1412 	{ 0xd, 0xffff0000, 16, 0x5, SISLANDS_CACCONFIG_CGIND },
1413 	{ 0xe, 0x0000ffff, 0, 0xB, SISLANDS_CACCONFIG_CGIND },
1414 	{ 0xf, 0x0000ffff, 0, 0x3, SISLANDS_CACCONFIG_CGIND },
1415 	{ 0xf, 0xffff0000, 16, 0x2, SISLANDS_CACCONFIG_CGIND },
1416 	{ 0x10, 0x0000ffff, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1417 	{ 0x10, 0xffff0000, 16, 0x4, SISLANDS_CACCONFIG_CGIND },
1418 	{ 0x11, 0x0000ffff, 0, 0x15, SISLANDS_CACCONFIG_CGIND },
1419 	{ 0x11, 0xffff0000, 16, 0x7, SISLANDS_CACCONFIG_CGIND },
1420 	{ 0x12, 0x0000ffff, 0, 0x36, SISLANDS_CACCONFIG_CGIND },
1421 	{ 0x13, 0x0000ffff, 0, 0x10, SISLANDS_CACCONFIG_CGIND },
1422 	{ 0x13, 0xffff0000, 16, 0x10, SISLANDS_CACCONFIG_CGIND },
1423 	{ 0x14, 0x0000ffff, 0, 0x90, SISLANDS_CACCONFIG_CGIND },
1424 	{ 0x15, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1425 	{ 0x15, 0xffff0000, 16, 0x6, SISLANDS_CACCONFIG_CGIND },
1426 	{ 0x4e, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1427 	{ 0x16, 0x0000ffff, 0, 0x32, SISLANDS_CACCONFIG_CGIND },
1428 	{ 0x16, 0xffff0000, 16, 0x7E, SISLANDS_CACCONFIG_CGIND },
1429 	{ 0x17, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1430 	{ 0x18, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1431 	{ 0x18, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
1432 	{ 0x19, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1433 	{ 0x19, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
1434 	{ 0x1a, 0x0000ffff, 0, 0x280, SISLANDS_CACCONFIG_CGIND },
1435 	{ 0x1a, 0xffff0000, 16, 0x7, SISLANDS_CACCONFIG_CGIND },
1436 	{ 0x1b, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1437 	{ 0x1b, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
1438 	{ 0x1c, 0x0000ffff, 0, 0x3C, SISLANDS_CACCONFIG_CGIND },
1439 	{ 0x1c, 0xffff0000, 16, 0x203, SISLANDS_CACCONFIG_CGIND },
1440 	{ 0x1d, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1441 	{ 0x1d, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
1442 	{ 0x1e, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
1443 	{ 0x1e, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
1444 	{ 0x1f, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
1445 	{ 0x1f, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
1446 	{ 0x20, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
1447 	{ 0x6d, 0x0000ffff, 0, 0xB4, SISLANDS_CACCONFIG_CGIND },
1448 	{ 0xFFFFFFFF }
1449 };
1450 
1451 static const struct si_cac_config_reg cac_weights_oland_xt[] =
1452 {
1453 	{ 0x0, 0x0000ffff, 0, 0x43, SISLANDS_CACCONFIG_CGIND },
1454 	{ 0x0, 0xffff0000, 16, 0x29, SISLANDS_CACCONFIG_CGIND },
1455 	{ 0x1, 0x0000ffff, 0, 0xAF, SISLANDS_CACCONFIG_CGIND },
1456 	{ 0x1, 0xffff0000, 16, 0x2A, SISLANDS_CACCONFIG_CGIND },
1457 	{ 0x2, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1458 	{ 0x3, 0x0000ffff, 0, 0xA0, SISLANDS_CACCONFIG_CGIND },
1459 	{ 0x3, 0xffff0000, 16, 0x29, SISLANDS_CACCONFIG_CGIND },
1460 	{ 0x4, 0x0000ffff, 0, 0xA0, SISLANDS_CACCONFIG_CGIND },
1461 	{ 0x4, 0xffff0000, 16, 0x59, SISLANDS_CACCONFIG_CGIND },
1462 	{ 0x5, 0x0000ffff, 0, 0x1A5, SISLANDS_CACCONFIG_CGIND },
1463 	{ 0x5, 0xffff0000, 16, 0x1D6, SISLANDS_CACCONFIG_CGIND },
1464 	{ 0x6, 0x0000ffff, 0, 0x2A3, SISLANDS_CACCONFIG_CGIND },
1465 	{ 0x6, 0xffff0000, 16, 0x8FD, SISLANDS_CACCONFIG_CGIND },
1466 	{ 0x18f, 0x0000ffff, 0, 0x76, SISLANDS_CACCONFIG_CGIND },
1467 	{ 0x7, 0x0000ffff, 0, 0x8A, SISLANDS_CACCONFIG_CGIND },
1468 	{ 0x7, 0xffff0000, 16, 0xA3, SISLANDS_CACCONFIG_CGIND },
1469 	{ 0x8, 0x0000ffff, 0, 0x71, SISLANDS_CACCONFIG_CGIND },
1470 	{ 0x8, 0xffff0000, 16, 0x36, SISLANDS_CACCONFIG_CGIND },
1471 	{ 0x9, 0x0000ffff, 0, 0xA6, SISLANDS_CACCONFIG_CGIND },
1472 	{ 0xa, 0x0000ffff, 0, 0x81, SISLANDS_CACCONFIG_CGIND },
1473 	{ 0xb, 0x0000ffff, 0, 0x3D2, SISLANDS_CACCONFIG_CGIND },
1474 	{ 0xb, 0xffff0000, 16, 0x27C, SISLANDS_CACCONFIG_CGIND },
1475 	{ 0xc, 0x0000ffff, 0, 0xA96, SISLANDS_CACCONFIG_CGIND },
1476 	{ 0xd, 0x0000ffff, 0, 0x5, SISLANDS_CACCONFIG_CGIND },
1477 	{ 0xd, 0xffff0000, 16, 0x5, SISLANDS_CACCONFIG_CGIND },
1478 	{ 0xe, 0x0000ffff, 0, 0xB, SISLANDS_CACCONFIG_CGIND },
1479 	{ 0xf, 0x0000ffff, 0, 0x3, SISLANDS_CACCONFIG_CGIND },
1480 	{ 0xf, 0xffff0000, 16, 0x2, SISLANDS_CACCONFIG_CGIND },
1481 	{ 0x10, 0x0000ffff, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1482 	{ 0x10, 0xffff0000, 16, 0x4, SISLANDS_CACCONFIG_CGIND },
1483 	{ 0x11, 0x0000ffff, 0, 0x15, SISLANDS_CACCONFIG_CGIND },
1484 	{ 0x11, 0xffff0000, 16, 0x7, SISLANDS_CACCONFIG_CGIND },
1485 	{ 0x12, 0x0000ffff, 0, 0x36, SISLANDS_CACCONFIG_CGIND },
1486 	{ 0x13, 0x0000ffff, 0, 0x10, SISLANDS_CACCONFIG_CGIND },
1487 	{ 0x13, 0xffff0000, 16, 0x10, SISLANDS_CACCONFIG_CGIND },
1488 	{ 0x14, 0x0000ffff, 0, 0x120, SISLANDS_CACCONFIG_CGIND },
1489 	{ 0x15, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1490 	{ 0x15, 0xffff0000, 16, 0x6, SISLANDS_CACCONFIG_CGIND },
1491 	{ 0x4e, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1492 	{ 0x16, 0x0000ffff, 0, 0x32, SISLANDS_CACCONFIG_CGIND },
1493 	{ 0x16, 0xffff0000, 16, 0x7E, SISLANDS_CACCONFIG_CGIND },
1494 	{ 0x17, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1495 	{ 0x18, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1496 	{ 0x18, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
1497 	{ 0x19, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1498 	{ 0x19, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
1499 	{ 0x1a, 0x0000ffff, 0, 0x280, SISLANDS_CACCONFIG_CGIND },
1500 	{ 0x1a, 0xffff0000, 16, 0x7, SISLANDS_CACCONFIG_CGIND },
1501 	{ 0x1b, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1502 	{ 0x1b, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
1503 	{ 0x1c, 0x0000ffff, 0, 0x3C, SISLANDS_CACCONFIG_CGIND },
1504 	{ 0x1c, 0xffff0000, 16, 0x203, SISLANDS_CACCONFIG_CGIND },
1505 	{ 0x1d, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1506 	{ 0x1d, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
1507 	{ 0x1e, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
1508 	{ 0x1e, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
1509 	{ 0x1f, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
1510 	{ 0x1f, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
1511 	{ 0x20, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
1512 	{ 0x6d, 0x0000ffff, 0, 0xB4, SISLANDS_CACCONFIG_CGIND },
1513 	{ 0xFFFFFFFF }
1514 };
1515 
1516 static const struct si_cac_config_reg lcac_oland[] =
1517 {
1518 	{ 0x98, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
1519 	{ 0x98, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1520 	{ 0x104, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
1521 	{ 0x104, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1522 	{ 0x110, 0x0001fffe, 1, 0x6, SISLANDS_CACCONFIG_CGIND },
1523 	{ 0x110, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1524 	{ 0x14f, 0x0001fffe, 1, 0x6, SISLANDS_CACCONFIG_CGIND },
1525 	{ 0x14f, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1526 	{ 0x8c, 0x0001fffe, 1, 0x6, SISLANDS_CACCONFIG_CGIND },
1527 	{ 0x8c, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1528 	{ 0x143, 0x0001fffe, 1, 0x4, SISLANDS_CACCONFIG_CGIND },
1529 	{ 0x143, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1530 	{ 0x11c, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
1531 	{ 0x11c, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1532 	{ 0x11f, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
1533 	{ 0x11f, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1534 	{ 0x164, 0x0001fffe, 1, 0x1, SISLANDS_CACCONFIG_CGIND },
1535 	{ 0x164, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1536 	{ 0x167, 0x0001fffe, 1, 0x1, SISLANDS_CACCONFIG_CGIND },
1537 	{ 0x167, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1538 	{ 0x16a, 0x0001fffe, 1, 0x1, SISLANDS_CACCONFIG_CGIND },
1539 	{ 0x16a, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1540 	{ 0x15e, 0x0001fffe, 1, 0x1, SISLANDS_CACCONFIG_CGIND },
1541 	{ 0x15e, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1542 	{ 0x161, 0x0001fffe, 1, 0x1, SISLANDS_CACCONFIG_CGIND },
1543 	{ 0x161, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1544 	{ 0x15b, 0x0001fffe, 1, 0x1, SISLANDS_CACCONFIG_CGIND },
1545 	{ 0x15b, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1546 	{ 0x16d, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
1547 	{ 0x16d, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1548 	{ 0x170, 0x0001fffe, 1, 0x1, SISLANDS_CACCONFIG_CGIND },
1549 	{ 0x170, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1550 	{ 0x173, 0x0001fffe, 1, 0x1, SISLANDS_CACCONFIG_CGIND },
1551 	{ 0x173, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1552 	{ 0x176, 0x0001fffe, 1, 0x1, SISLANDS_CACCONFIG_CGIND },
1553 	{ 0x176, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1554 	{ 0x179, 0x0001fffe, 1, 0x1, SISLANDS_CACCONFIG_CGIND },
1555 	{ 0x179, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1556 	{ 0x17c, 0x0001fffe, 1, 0x1, SISLANDS_CACCONFIG_CGIND },
1557 	{ 0x17c, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1558 	{ 0x17f, 0x0001fffe, 1, 0x1, SISLANDS_CACCONFIG_CGIND },
1559 	{ 0x17f, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1560 	{ 0xFFFFFFFF }
1561 };
1562 
1563 static const struct si_cac_config_reg lcac_mars_pro[] =
1564 {
1565 	{ 0x98, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
1566 	{ 0x98, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1567 	{ 0x104, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
1568 	{ 0x104, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1569 	{ 0x110, 0x0001fffe, 1, 0x6, SISLANDS_CACCONFIG_CGIND },
1570 	{ 0x110, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1571 	{ 0x14f, 0x0001fffe, 1, 0x6, SISLANDS_CACCONFIG_CGIND },
1572 	{ 0x14f, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1573 	{ 0x8c, 0x0001fffe, 1, 0x6, SISLANDS_CACCONFIG_CGIND },
1574 	{ 0x8c, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1575 	{ 0x143, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
1576 	{ 0x143, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1577 	{ 0x11c, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
1578 	{ 0x11c, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1579 	{ 0x11f, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
1580 	{ 0x11f, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1581 	{ 0x164, 0x0001fffe, 1, 0x1, SISLANDS_CACCONFIG_CGIND },
1582 	{ 0x164, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1583 	{ 0x167, 0x0001fffe, 1, 0x1, SISLANDS_CACCONFIG_CGIND },
1584 	{ 0x167, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1585 	{ 0x16a, 0x0001fffe, 1, 0x1, SISLANDS_CACCONFIG_CGIND },
1586 	{ 0x16a, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1587 	{ 0x15e, 0x0001fffe, 1, 0x1, SISLANDS_CACCONFIG_CGIND },
1588 	{ 0x15e, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1589 	{ 0x161, 0x0001fffe, 1, 0x1, SISLANDS_CACCONFIG_CGIND },
1590 	{ 0x161, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1591 	{ 0x15b, 0x0001fffe, 1, 0x1, SISLANDS_CACCONFIG_CGIND },
1592 	{ 0x15b, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1593 	{ 0x16d, 0x0001fffe, 1, 0x2, SISLANDS_CACCONFIG_CGIND },
1594 	{ 0x16d, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1595 	{ 0x170, 0x0001fffe, 1, 0x1, SISLANDS_CACCONFIG_CGIND },
1596 	{ 0x170, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1597 	{ 0x173, 0x0001fffe, 1, 0x1, SISLANDS_CACCONFIG_CGIND },
1598 	{ 0x173, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1599 	{ 0x176, 0x0001fffe, 1, 0x1, SISLANDS_CACCONFIG_CGIND },
1600 	{ 0x176, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1601 	{ 0x179, 0x0001fffe, 1, 0x1, SISLANDS_CACCONFIG_CGIND },
1602 	{ 0x179, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1603 	{ 0x17c, 0x0001fffe, 1, 0x1, SISLANDS_CACCONFIG_CGIND },
1604 	{ 0x17c, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1605 	{ 0x17f, 0x0001fffe, 1, 0x1, SISLANDS_CACCONFIG_CGIND },
1606 	{ 0x17f, 0x00000001, 0, 0x1, SISLANDS_CACCONFIG_CGIND },
1607 	{ 0xFFFFFFFF }
1608 };
1609 
1610 static const struct si_cac_config_reg cac_override_oland[] =
1611 {
1612 	{ 0xFFFFFFFF }
1613 };
1614 
1615 static const struct si_powertune_data powertune_data_oland =
1616 {
1617 	((1 << 16) | 0x6993),
1618 	5,
1619 	0,
1620 	7,
1621 	105,
1622 	{
1623 		0UL,
1624 		0UL,
1625 		7194395UL,
1626 		309631529UL,
1627 		-1270850L,
1628 		4513710L,
1629 		100
1630 	},
1631 	117830498UL,
1632 	12,
1633 	{
1634 		0,
1635 		0,
1636 		0,
1637 		0,
1638 		0,
1639 		0,
1640 		0,
1641 		0
1642 	},
1643 	true
1644 };
1645 
1646 static const struct si_powertune_data powertune_data_mars_pro =
1647 {
1648 	((1 << 16) | 0x6993),
1649 	5,
1650 	0,
1651 	7,
1652 	105,
1653 	{
1654 		0UL,
1655 		0UL,
1656 		7194395UL,
1657 		309631529UL,
1658 		-1270850L,
1659 		4513710L,
1660 		100
1661 	},
1662 	117830498UL,
1663 	12,
1664 	{
1665 		0,
1666 		0,
1667 		0,
1668 		0,
1669 		0,
1670 		0,
1671 		0,
1672 		0
1673 	},
1674 	true
1675 };
1676 
1677 static const struct si_dte_data dte_data_oland =
1678 {
1679 	{ 0, 0, 0, 0, 0 },
1680 	{ 0, 0, 0, 0, 0 },
1681 	0,
1682 	0,
1683 	0,
1684 	0,
1685 	0,
1686 	0,
1687 	0,
1688 	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
1689 	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
1690 	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
1691 	0,
1692 	false
1693 };
1694 
1695 static const struct si_dte_data dte_data_mars_pro =
1696 {
1697 	{ 0x1E8480, 0x3D0900, 0x989680, 0x2625A00, 0x0 },
1698 	{ 0x0, 0x0, 0x0, 0x0, 0x0 },
1699 	5,
1700 	55000,
1701 	105,
1702 	0xA,
1703 	1,
1704 	0,
1705 	0x10,
1706 	{ 0x96, 0xB4, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
1707 	{ 0x895440, 0x3D0900, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680 },
1708 	{ 0xF627, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 },
1709 	90,
1710 	true
1711 };
1712 
1713 static const struct si_dte_data dte_data_sun_xt =
1714 {
1715 	{ 0x1E8480, 0x3D0900, 0x989680, 0x2625A00, 0x0 },
1716 	{ 0x0, 0x0, 0x0, 0x0, 0x0 },
1717 	5,
1718 	55000,
1719 	105,
1720 	0xA,
1721 	1,
1722 	0,
1723 	0x10,
1724 	{ 0x96, 0xB4, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
1725 	{ 0x895440, 0x3D0900, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680, 0x989680 },
1726 	{ 0xD555, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 },
1727 	90,
1728 	true
1729 };
1730 
1731 
1732 static const struct si_cac_config_reg cac_weights_hainan[] =
1733 {
1734 	{ 0x0, 0x0000ffff, 0, 0x2d9, SISLANDS_CACCONFIG_CGIND },
1735 	{ 0x0, 0xffff0000, 16, 0x22b, SISLANDS_CACCONFIG_CGIND },
1736 	{ 0x1, 0x0000ffff, 0, 0x21c, SISLANDS_CACCONFIG_CGIND },
1737 	{ 0x1, 0xffff0000, 16, 0x1dc, SISLANDS_CACCONFIG_CGIND },
1738 	{ 0x2, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1739 	{ 0x3, 0x0000ffff, 0, 0x24e, SISLANDS_CACCONFIG_CGIND },
1740 	{ 0x3, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
1741 	{ 0x4, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1742 	{ 0x4, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
1743 	{ 0x5, 0x0000ffff, 0, 0x35e, SISLANDS_CACCONFIG_CGIND },
1744 	{ 0x5, 0xffff0000, 16, 0x1143, SISLANDS_CACCONFIG_CGIND },
1745 	{ 0x6, 0x0000ffff, 0, 0xe17, SISLANDS_CACCONFIG_CGIND },
1746 	{ 0x6, 0xffff0000, 16, 0x441, SISLANDS_CACCONFIG_CGIND },
1747 	{ 0x18f, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1748 	{ 0x7, 0x0000ffff, 0, 0x28b, SISLANDS_CACCONFIG_CGIND },
1749 	{ 0x7, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
1750 	{ 0x8, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1751 	{ 0x8, 0xffff0000, 16, 0xabe, SISLANDS_CACCONFIG_CGIND },
1752 	{ 0x9, 0x0000ffff, 0, 0xf11, SISLANDS_CACCONFIG_CGIND },
1753 	{ 0xa, 0x0000ffff, 0, 0x907, SISLANDS_CACCONFIG_CGIND },
1754 	{ 0xb, 0x0000ffff, 0, 0xb45, SISLANDS_CACCONFIG_CGIND },
1755 	{ 0xb, 0xffff0000, 16, 0xd1e, SISLANDS_CACCONFIG_CGIND },
1756 	{ 0xc, 0x0000ffff, 0, 0xa2c, SISLANDS_CACCONFIG_CGIND },
1757 	{ 0xd, 0x0000ffff, 0, 0x62, SISLANDS_CACCONFIG_CGIND },
1758 	{ 0xd, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
1759 	{ 0xe, 0x0000ffff, 0, 0x1f3, SISLANDS_CACCONFIG_CGIND },
1760 	{ 0xf, 0x0000ffff, 0, 0x42, SISLANDS_CACCONFIG_CGIND },
1761 	{ 0xf, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
1762 	{ 0x10, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1763 	{ 0x10, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
1764 	{ 0x11, 0x0000ffff, 0, 0x709, SISLANDS_CACCONFIG_CGIND },
1765 	{ 0x11, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
1766 	{ 0x12, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1767 	{ 0x13, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1768 	{ 0x13, 0xffff0000, 16, 0x3a, SISLANDS_CACCONFIG_CGIND },
1769 	{ 0x14, 0x0000ffff, 0, 0x357, SISLANDS_CACCONFIG_CGIND },
1770 	{ 0x15, 0x0000ffff, 0, 0x9f, SISLANDS_CACCONFIG_CGIND },
1771 	{ 0x15, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
1772 	{ 0x4e, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1773 	{ 0x16, 0x0000ffff, 0, 0x314, SISLANDS_CACCONFIG_CGIND },
1774 	{ 0x16, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
1775 	{ 0x17, 0x0000ffff, 0, 0x6d, SISLANDS_CACCONFIG_CGIND },
1776 	{ 0x18, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1777 	{ 0x18, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
1778 	{ 0x19, 0x0000ffff, 0, 0x0, SISLANDS_CACCONFIG_CGIND },
1779 	{ 0x19, 0xffff0000, 16, 0x0, SISLANDS_CACCONFIG_CGIND },
1780 	{ 0x1a, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
1781 	{ 0x1a, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
1782 	{ 0x1b, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
1783 	{ 0x1b, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
1784 	{ 0x1c, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
1785 	{ 0x1c, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
1786 	{ 0x1d, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
1787 	{ 0x1d, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
1788 	{ 0x1e, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
1789 	{ 0x1e, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
1790 	{ 0x1f, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
1791 	{ 0x1f, 0xffff0000, 16, 0, SISLANDS_CACCONFIG_CGIND },
1792 	{ 0x20, 0x0000ffff, 0, 0, SISLANDS_CACCONFIG_CGIND },
1793 	{ 0x6d, 0x0000ffff, 0, 0x1b9, SISLANDS_CACCONFIG_CGIND },
1794 	{ 0xFFFFFFFF }
1795 };
1796 
1797 static const struct si_powertune_data powertune_data_hainan =
1798 {
1799 	((1 << 16) | 0x6993),
1800 	5,
1801 	0,
1802 	9,
1803 	105,
1804 	{
1805 		0UL,
1806 		0UL,
1807 		7194395UL,
1808 		309631529UL,
1809 		-1270850L,
1810 		4513710L,
1811 		100
1812 	},
1813 	117830498UL,
1814 	12,
1815 	{
1816 		0,
1817 		0,
1818 		0,
1819 		0,
1820 		0,
1821 		0,
1822 		0,
1823 		0
1824 	},
1825 	true
1826 };
1827 
1828 static struct rv7xx_power_info *rv770_get_pi(struct amdgpu_device *adev);
1829 static struct evergreen_power_info *evergreen_get_pi(struct amdgpu_device *adev);
1830 static struct ni_power_info *ni_get_pi(struct amdgpu_device *adev);
1831 static struct  si_ps *si_get_ps(struct amdgpu_ps *rps);
1832 
1833 static int si_populate_voltage_value(struct amdgpu_device *adev,
1834 				     const struct atom_voltage_table *table,
1835 				     u16 value, SISLANDS_SMC_VOLTAGE_VALUE *voltage);
1836 static int si_get_std_voltage_value(struct amdgpu_device *adev,
1837 				    SISLANDS_SMC_VOLTAGE_VALUE *voltage,
1838 				    u16 *std_voltage);
1839 static int si_write_smc_soft_register(struct amdgpu_device *adev,
1840 				      u16 reg_offset, u32 value);
1841 static int si_convert_power_level_to_smc(struct amdgpu_device *adev,
1842 					 struct rv7xx_pl *pl,
1843 					 SISLANDS_SMC_HW_PERFORMANCE_LEVEL *level);
1844 static int si_calculate_sclk_params(struct amdgpu_device *adev,
1845 				    u32 engine_clock,
1846 				    SISLANDS_SMC_SCLK_VALUE *sclk);
1847 
1848 static void si_thermal_start_smc_fan_control(struct amdgpu_device *adev);
1849 static void si_fan_ctrl_set_default_mode(struct amdgpu_device *adev);
1850 static void si_dpm_set_irq_funcs(struct amdgpu_device *adev);
1851 
1852 static struct si_power_info *si_get_pi(struct amdgpu_device *adev)
1853 {
1854 	struct si_power_info *pi = adev->pm.dpm.priv;
1855 	return pi;
1856 }
1857 
1858 static void si_calculate_leakage_for_v_and_t_formula(const struct ni_leakage_coeffients *coeff,
1859 						     u16 v, s32 t, u32 ileakage, u32 *leakage)
1860 {
1861 	s64 kt, kv, leakage_w, i_leakage, vddc;
1862 	s64 temperature, t_slope, t_intercept, av, bv, t_ref;
1863 	s64 tmp;
1864 
1865 	i_leakage = div64_s64(drm_int2fixp(ileakage), 100);
1866 	vddc = div64_s64(drm_int2fixp(v), 1000);
1867 	temperature = div64_s64(drm_int2fixp(t), 1000);
1868 
1869 	t_slope = div64_s64(drm_int2fixp(coeff->t_slope), 100000000);
1870 	t_intercept = div64_s64(drm_int2fixp(coeff->t_intercept), 100000000);
1871 	av = div64_s64(drm_int2fixp(coeff->av), 100000000);
1872 	bv = div64_s64(drm_int2fixp(coeff->bv), 100000000);
1873 	t_ref = drm_int2fixp(coeff->t_ref);
1874 
1875 	tmp = drm_fixp_mul(t_slope, vddc) + t_intercept;
1876 	kt = drm_fixp_exp(drm_fixp_mul(tmp, temperature));
1877 	kt = drm_fixp_div(kt, drm_fixp_exp(drm_fixp_mul(tmp, t_ref)));
1878 	kv = drm_fixp_mul(av, drm_fixp_exp(drm_fixp_mul(bv, vddc)));
1879 
1880 	leakage_w = drm_fixp_mul(drm_fixp_mul(drm_fixp_mul(i_leakage, kt), kv), vddc);
1881 
1882 	*leakage = drm_fixp2int(leakage_w * 1000);
1883 }
1884 
1885 static void si_calculate_leakage_for_v_and_t(struct amdgpu_device *adev,
1886 					     const struct ni_leakage_coeffients *coeff,
1887 					     u16 v,
1888 					     s32 t,
1889 					     u32 i_leakage,
1890 					     u32 *leakage)
1891 {
1892 	si_calculate_leakage_for_v_and_t_formula(coeff, v, t, i_leakage, leakage);
1893 }
1894 
1895 static void si_calculate_leakage_for_v_formula(const struct ni_leakage_coeffients *coeff,
1896 					       const u32 fixed_kt, u16 v,
1897 					       u32 ileakage, u32 *leakage)
1898 {
1899 	s64 kt, kv, leakage_w, i_leakage, vddc;
1900 
1901 	i_leakage = div64_s64(drm_int2fixp(ileakage), 100);
1902 	vddc = div64_s64(drm_int2fixp(v), 1000);
1903 
1904 	kt = div64_s64(drm_int2fixp(fixed_kt), 100000000);
1905 	kv = drm_fixp_mul(div64_s64(drm_int2fixp(coeff->av), 100000000),
1906 			  drm_fixp_exp(drm_fixp_mul(div64_s64(drm_int2fixp(coeff->bv), 100000000), vddc)));
1907 
1908 	leakage_w = drm_fixp_mul(drm_fixp_mul(drm_fixp_mul(i_leakage, kt), kv), vddc);
1909 
1910 	*leakage = drm_fixp2int(leakage_w * 1000);
1911 }
1912 
1913 static void si_calculate_leakage_for_v(struct amdgpu_device *adev,
1914 				       const struct ni_leakage_coeffients *coeff,
1915 				       const u32 fixed_kt,
1916 				       u16 v,
1917 				       u32 i_leakage,
1918 				       u32 *leakage)
1919 {
1920 	si_calculate_leakage_for_v_formula(coeff, fixed_kt, v, i_leakage, leakage);
1921 }
1922 
1923 
1924 static void si_update_dte_from_pl2(struct amdgpu_device *adev,
1925 				   struct si_dte_data *dte_data)
1926 {
1927 	u32 p_limit1 = adev->pm.dpm.tdp_limit;
1928 	u32 p_limit2 = adev->pm.dpm.near_tdp_limit;
1929 	u32 k = dte_data->k;
1930 	u32 t_max = dte_data->max_t;
1931 	u32 t_split[5] = { 10, 15, 20, 25, 30 };
1932 	u32 t_0 = dte_data->t0;
1933 	u32 i;
1934 
1935 	if (p_limit2 != 0 && p_limit2 <= p_limit1) {
1936 		dte_data->tdep_count = 3;
1937 
1938 		for (i = 0; i < k; i++) {
1939 			dte_data->r[i] =
1940 				(t_split[i] * (t_max - t_0/(u32)1000) * (1 << 14)) /
1941 				(p_limit2  * (u32)100);
1942 		}
1943 
1944 		dte_data->tdep_r[1] = dte_data->r[4] * 2;
1945 
1946 		for (i = 2; i < SMC_SISLANDS_DTE_MAX_TEMPERATURE_DEPENDENT_ARRAY_SIZE; i++) {
1947 			dte_data->tdep_r[i] = dte_data->r[4];
1948 		}
1949 	} else {
1950 		DRM_ERROR("Invalid PL2! DTE will not be updated.\n");
1951 	}
1952 }
1953 
1954 static struct rv7xx_power_info *rv770_get_pi(struct amdgpu_device *adev)
1955 {
1956 	struct rv7xx_power_info *pi = adev->pm.dpm.priv;
1957 
1958 	return pi;
1959 }
1960 
1961 static struct ni_power_info *ni_get_pi(struct amdgpu_device *adev)
1962 {
1963 	struct ni_power_info *pi = adev->pm.dpm.priv;
1964 
1965 	return pi;
1966 }
1967 
1968 static struct si_ps *si_get_ps(struct amdgpu_ps *aps)
1969 {
1970 	struct  si_ps *ps = aps->ps_priv;
1971 
1972 	return ps;
1973 }
1974 
1975 static void si_initialize_powertune_defaults(struct amdgpu_device *adev)
1976 {
1977 	struct ni_power_info *ni_pi = ni_get_pi(adev);
1978 	struct si_power_info *si_pi = si_get_pi(adev);
1979 	bool update_dte_from_pl2 = false;
1980 
1981 	if (adev->asic_type == CHIP_TAHITI) {
1982 		si_pi->cac_weights = cac_weights_tahiti;
1983 		si_pi->lcac_config = lcac_tahiti;
1984 		si_pi->cac_override = cac_override_tahiti;
1985 		si_pi->powertune_data = &powertune_data_tahiti;
1986 		si_pi->dte_data = dte_data_tahiti;
1987 
1988 		switch (adev->pdev->device) {
1989 		case 0x6798:
1990 			si_pi->dte_data.enable_dte_by_default = true;
1991 			break;
1992 		case 0x6799:
1993 			si_pi->dte_data = dte_data_new_zealand;
1994 			break;
1995 		case 0x6790:
1996 		case 0x6791:
1997 		case 0x6792:
1998 		case 0x679E:
1999 			si_pi->dte_data = dte_data_aruba_pro;
2000 			update_dte_from_pl2 = true;
2001 			break;
2002 		case 0x679B:
2003 			si_pi->dte_data = dte_data_malta;
2004 			update_dte_from_pl2 = true;
2005 			break;
2006 		case 0x679A:
2007 			si_pi->dte_data = dte_data_tahiti_pro;
2008 			update_dte_from_pl2 = true;
2009 			break;
2010 		default:
2011 			if (si_pi->dte_data.enable_dte_by_default == true)
2012 				DRM_ERROR("DTE is not enabled!\n");
2013 			break;
2014 		}
2015 	} else if (adev->asic_type == CHIP_PITCAIRN) {
2016 		si_pi->cac_weights = cac_weights_pitcairn;
2017 		si_pi->lcac_config = lcac_pitcairn;
2018 		si_pi->cac_override = cac_override_pitcairn;
2019 		si_pi->powertune_data = &powertune_data_pitcairn;
2020 
2021 		switch (adev->pdev->device) {
2022 		case 0x6810:
2023 		case 0x6818:
2024 			si_pi->dte_data = dte_data_curacao_xt;
2025 			update_dte_from_pl2 = true;
2026 			break;
2027 		case 0x6819:
2028 		case 0x6811:
2029 			si_pi->dte_data = dte_data_curacao_pro;
2030 			update_dte_from_pl2 = true;
2031 			break;
2032 		case 0x6800:
2033 		case 0x6806:
2034 			si_pi->dte_data = dte_data_neptune_xt;
2035 			update_dte_from_pl2 = true;
2036 			break;
2037 		default:
2038 			si_pi->dte_data = dte_data_pitcairn;
2039 			break;
2040 		}
2041 	} else if (adev->asic_type == CHIP_VERDE) {
2042 		si_pi->lcac_config = lcac_cape_verde;
2043 		si_pi->cac_override = cac_override_cape_verde;
2044 		si_pi->powertune_data = &powertune_data_cape_verde;
2045 
2046 		switch (adev->pdev->device) {
2047 		case 0x683B:
2048 		case 0x683F:
2049 		case 0x6829:
2050 		case 0x6835:
2051 			si_pi->cac_weights = cac_weights_cape_verde_pro;
2052 			si_pi->dte_data = dte_data_cape_verde;
2053 			break;
2054 		case 0x682C:
2055 			si_pi->cac_weights = cac_weights_cape_verde_pro;
2056 			si_pi->dte_data = dte_data_sun_xt;
2057 			update_dte_from_pl2 = true;
2058 			break;
2059 		case 0x6825:
2060 		case 0x6827:
2061 			si_pi->cac_weights = cac_weights_heathrow;
2062 			si_pi->dte_data = dte_data_cape_verde;
2063 			break;
2064 		case 0x6824:
2065 		case 0x682D:
2066 			si_pi->cac_weights = cac_weights_chelsea_xt;
2067 			si_pi->dte_data = dte_data_cape_verde;
2068 			break;
2069 		case 0x682F:
2070 			si_pi->cac_weights = cac_weights_chelsea_pro;
2071 			si_pi->dte_data = dte_data_cape_verde;
2072 			break;
2073 		case 0x6820:
2074 			si_pi->cac_weights = cac_weights_heathrow;
2075 			si_pi->dte_data = dte_data_venus_xtx;
2076 			break;
2077 		case 0x6821:
2078 			si_pi->cac_weights = cac_weights_heathrow;
2079 			si_pi->dte_data = dte_data_venus_xt;
2080 			break;
2081 		case 0x6823:
2082 		case 0x682B:
2083 		case 0x6822:
2084 		case 0x682A:
2085 			si_pi->cac_weights = cac_weights_chelsea_pro;
2086 			si_pi->dte_data = dte_data_venus_pro;
2087 			break;
2088 		default:
2089 			si_pi->cac_weights = cac_weights_cape_verde;
2090 			si_pi->dte_data = dte_data_cape_verde;
2091 			break;
2092 		}
2093 	} else if (adev->asic_type == CHIP_OLAND) {
2094 		si_pi->lcac_config = lcac_mars_pro;
2095 		si_pi->cac_override = cac_override_oland;
2096 		si_pi->powertune_data = &powertune_data_mars_pro;
2097 		si_pi->dte_data = dte_data_mars_pro;
2098 
2099 		switch (adev->pdev->device) {
2100 		case 0x6601:
2101 		case 0x6621:
2102 		case 0x6603:
2103 		case 0x6605:
2104 			si_pi->cac_weights = cac_weights_mars_pro;
2105 			update_dte_from_pl2 = true;
2106 			break;
2107 		case 0x6600:
2108 		case 0x6606:
2109 		case 0x6620:
2110 		case 0x6604:
2111 			si_pi->cac_weights = cac_weights_mars_xt;
2112 			update_dte_from_pl2 = true;
2113 			break;
2114 		case 0x6611:
2115 		case 0x6613:
2116 		case 0x6608:
2117 			si_pi->cac_weights = cac_weights_oland_pro;
2118 			update_dte_from_pl2 = true;
2119 			break;
2120 		case 0x6610:
2121 			si_pi->cac_weights = cac_weights_oland_xt;
2122 			update_dte_from_pl2 = true;
2123 			break;
2124 		default:
2125 			si_pi->cac_weights = cac_weights_oland;
2126 			si_pi->lcac_config = lcac_oland;
2127 			si_pi->cac_override = cac_override_oland;
2128 			si_pi->powertune_data = &powertune_data_oland;
2129 			si_pi->dte_data = dte_data_oland;
2130 			break;
2131 		}
2132 	} else if (adev->asic_type == CHIP_HAINAN) {
2133 		si_pi->cac_weights = cac_weights_hainan;
2134 		si_pi->lcac_config = lcac_oland;
2135 		si_pi->cac_override = cac_override_oland;
2136 		si_pi->powertune_data = &powertune_data_hainan;
2137 		si_pi->dte_data = dte_data_sun_xt;
2138 		update_dte_from_pl2 = true;
2139 	} else {
2140 		DRM_ERROR("Unknown SI asic revision, failed to initialize PowerTune!\n");
2141 		return;
2142 	}
2143 
2144 	ni_pi->enable_power_containment = false;
2145 	ni_pi->enable_cac = false;
2146 	ni_pi->enable_sq_ramping = false;
2147 	si_pi->enable_dte = false;
2148 
2149 	if (si_pi->powertune_data->enable_powertune_by_default) {
2150 		ni_pi->enable_power_containment = true;
2151 		ni_pi->enable_cac = true;
2152 		if (si_pi->dte_data.enable_dte_by_default) {
2153 			si_pi->enable_dte = true;
2154 			if (update_dte_from_pl2)
2155 				si_update_dte_from_pl2(adev, &si_pi->dte_data);
2156 
2157 		}
2158 		ni_pi->enable_sq_ramping = true;
2159 	}
2160 
2161 	ni_pi->driver_calculate_cac_leakage = true;
2162 	ni_pi->cac_configuration_required = true;
2163 
2164 	if (ni_pi->cac_configuration_required) {
2165 		ni_pi->support_cac_long_term_average = true;
2166 		si_pi->dyn_powertune_data.l2_lta_window_size =
2167 			si_pi->powertune_data->l2_lta_window_size_default;
2168 		si_pi->dyn_powertune_data.lts_truncate =
2169 			si_pi->powertune_data->lts_truncate_default;
2170 	} else {
2171 		ni_pi->support_cac_long_term_average = false;
2172 		si_pi->dyn_powertune_data.l2_lta_window_size = 0;
2173 		si_pi->dyn_powertune_data.lts_truncate = 0;
2174 	}
2175 
2176 	si_pi->dyn_powertune_data.disable_uvd_powertune = false;
2177 }
2178 
2179 static u32 si_get_smc_power_scaling_factor(struct amdgpu_device *adev)
2180 {
2181 	return 1;
2182 }
2183 
2184 static u32 si_calculate_cac_wintime(struct amdgpu_device *adev)
2185 {
2186 	u32 xclk;
2187 	u32 wintime;
2188 	u32 cac_window;
2189 	u32 cac_window_size;
2190 
2191 	xclk = amdgpu_asic_get_xclk(adev);
2192 
2193 	if (xclk == 0)
2194 		return 0;
2195 
2196 	cac_window = RREG32(CG_CAC_CTRL) & CAC_WINDOW_MASK;
2197 	cac_window_size = ((cac_window & 0xFFFF0000) >> 16) * (cac_window & 0x0000FFFF);
2198 
2199 	wintime = (cac_window_size * 100) / xclk;
2200 
2201 	return wintime;
2202 }
2203 
2204 static u32 si_scale_power_for_smc(u32 power_in_watts, u32 scaling_factor)
2205 {
2206 	return power_in_watts;
2207 }
2208 
2209 static int si_calculate_adjusted_tdp_limits(struct amdgpu_device *adev,
2210 					    bool adjust_polarity,
2211 					    u32 tdp_adjustment,
2212 					    u32 *tdp_limit,
2213 					    u32 *near_tdp_limit)
2214 {
2215 	u32 adjustment_delta, max_tdp_limit;
2216 
2217 	if (tdp_adjustment > (u32)adev->pm.dpm.tdp_od_limit)
2218 		return -EINVAL;
2219 
2220 	max_tdp_limit = ((100 + 100) * adev->pm.dpm.tdp_limit) / 100;
2221 
2222 	if (adjust_polarity) {
2223 		*tdp_limit = ((100 + tdp_adjustment) * adev->pm.dpm.tdp_limit) / 100;
2224 		*near_tdp_limit = adev->pm.dpm.near_tdp_limit_adjusted + (*tdp_limit - adev->pm.dpm.tdp_limit);
2225 	} else {
2226 		*tdp_limit = ((100 - tdp_adjustment) * adev->pm.dpm.tdp_limit) / 100;
2227 		adjustment_delta  = adev->pm.dpm.tdp_limit - *tdp_limit;
2228 		if (adjustment_delta < adev->pm.dpm.near_tdp_limit_adjusted)
2229 			*near_tdp_limit = adev->pm.dpm.near_tdp_limit_adjusted - adjustment_delta;
2230 		else
2231 			*near_tdp_limit = 0;
2232 	}
2233 
2234 	if ((*tdp_limit <= 0) || (*tdp_limit > max_tdp_limit))
2235 		return -EINVAL;
2236 	if ((*near_tdp_limit <= 0) || (*near_tdp_limit > *tdp_limit))
2237 		return -EINVAL;
2238 
2239 	return 0;
2240 }
2241 
2242 static int si_populate_smc_tdp_limits(struct amdgpu_device *adev,
2243 				      struct amdgpu_ps *amdgpu_state)
2244 {
2245 	struct ni_power_info *ni_pi = ni_get_pi(adev);
2246 	struct si_power_info *si_pi = si_get_pi(adev);
2247 
2248 	if (ni_pi->enable_power_containment) {
2249 		SISLANDS_SMC_STATETABLE *smc_table = &si_pi->smc_statetable;
2250 		PP_SIslands_PAPMParameters *papm_parm;
2251 		struct amdgpu_ppm_table *ppm = adev->pm.dpm.dyn_state.ppm_table;
2252 		u32 scaling_factor = si_get_smc_power_scaling_factor(adev);
2253 		u32 tdp_limit;
2254 		u32 near_tdp_limit;
2255 		int ret;
2256 
2257 		if (scaling_factor == 0)
2258 			return -EINVAL;
2259 
2260 		memset(smc_table, 0, sizeof(SISLANDS_SMC_STATETABLE));
2261 
2262 		ret = si_calculate_adjusted_tdp_limits(adev,
2263 						       false, /* ??? */
2264 						       adev->pm.dpm.tdp_adjustment,
2265 						       &tdp_limit,
2266 						       &near_tdp_limit);
2267 		if (ret)
2268 			return ret;
2269 
2270 		smc_table->dpm2Params.TDPLimit =
2271 			cpu_to_be32(si_scale_power_for_smc(tdp_limit, scaling_factor) * 1000);
2272 		smc_table->dpm2Params.NearTDPLimit =
2273 			cpu_to_be32(si_scale_power_for_smc(near_tdp_limit, scaling_factor) * 1000);
2274 		smc_table->dpm2Params.SafePowerLimit =
2275 			cpu_to_be32(si_scale_power_for_smc((near_tdp_limit * SISLANDS_DPM2_TDP_SAFE_LIMIT_PERCENT) / 100, scaling_factor) * 1000);
2276 
2277 		ret = amdgpu_si_copy_bytes_to_smc(adev,
2278 						  (si_pi->state_table_start + offsetof(SISLANDS_SMC_STATETABLE, dpm2Params) +
2279 						   offsetof(PP_SIslands_DPM2Parameters, TDPLimit)),
2280 						  (u8 *)(&(smc_table->dpm2Params.TDPLimit)),
2281 						  sizeof(u32) * 3,
2282 						  si_pi->sram_end);
2283 		if (ret)
2284 			return ret;
2285 
2286 		if (si_pi->enable_ppm) {
2287 			papm_parm = &si_pi->papm_parm;
2288 			memset(papm_parm, 0, sizeof(PP_SIslands_PAPMParameters));
2289 			papm_parm->NearTDPLimitTherm = cpu_to_be32(ppm->dgpu_tdp);
2290 			papm_parm->dGPU_T_Limit = cpu_to_be32(ppm->tj_max);
2291 			papm_parm->dGPU_T_Warning = cpu_to_be32(95);
2292 			papm_parm->dGPU_T_Hysteresis = cpu_to_be32(5);
2293 			papm_parm->PlatformPowerLimit = 0xffffffff;
2294 			papm_parm->NearTDPLimitPAPM = 0xffffffff;
2295 
2296 			ret = amdgpu_si_copy_bytes_to_smc(adev, si_pi->papm_cfg_table_start,
2297 							  (u8 *)papm_parm,
2298 							  sizeof(PP_SIslands_PAPMParameters),
2299 							  si_pi->sram_end);
2300 			if (ret)
2301 				return ret;
2302 		}
2303 	}
2304 	return 0;
2305 }
2306 
2307 static int si_populate_smc_tdp_limits_2(struct amdgpu_device *adev,
2308 					struct amdgpu_ps *amdgpu_state)
2309 {
2310 	struct ni_power_info *ni_pi = ni_get_pi(adev);
2311 	struct si_power_info *si_pi = si_get_pi(adev);
2312 
2313 	if (ni_pi->enable_power_containment) {
2314 		SISLANDS_SMC_STATETABLE *smc_table = &si_pi->smc_statetable;
2315 		u32 scaling_factor = si_get_smc_power_scaling_factor(adev);
2316 		int ret;
2317 
2318 		memset(smc_table, 0, sizeof(SISLANDS_SMC_STATETABLE));
2319 
2320 		smc_table->dpm2Params.NearTDPLimit =
2321 			cpu_to_be32(si_scale_power_for_smc(adev->pm.dpm.near_tdp_limit_adjusted, scaling_factor) * 1000);
2322 		smc_table->dpm2Params.SafePowerLimit =
2323 			cpu_to_be32(si_scale_power_for_smc((adev->pm.dpm.near_tdp_limit_adjusted * SISLANDS_DPM2_TDP_SAFE_LIMIT_PERCENT) / 100, scaling_factor) * 1000);
2324 
2325 		ret = amdgpu_si_copy_bytes_to_smc(adev,
2326 						  (si_pi->state_table_start +
2327 						   offsetof(SISLANDS_SMC_STATETABLE, dpm2Params) +
2328 						   offsetof(PP_SIslands_DPM2Parameters, NearTDPLimit)),
2329 						  (u8 *)(&(smc_table->dpm2Params.NearTDPLimit)),
2330 						  sizeof(u32) * 2,
2331 						  si_pi->sram_end);
2332 		if (ret)
2333 			return ret;
2334 	}
2335 
2336 	return 0;
2337 }
2338 
2339 static u16 si_calculate_power_efficiency_ratio(struct amdgpu_device *adev,
2340 					       const u16 prev_std_vddc,
2341 					       const u16 curr_std_vddc)
2342 {
2343 	u64 margin = (u64)SISLANDS_DPM2_PWREFFICIENCYRATIO_MARGIN;
2344 	u64 prev_vddc = (u64)prev_std_vddc;
2345 	u64 curr_vddc = (u64)curr_std_vddc;
2346 	u64 pwr_efficiency_ratio, n, d;
2347 
2348 	if ((prev_vddc == 0) || (curr_vddc == 0))
2349 		return 0;
2350 
2351 	n = div64_u64((u64)1024 * curr_vddc * curr_vddc * ((u64)1000 + margin), (u64)1000);
2352 	d = prev_vddc * prev_vddc;
2353 	pwr_efficiency_ratio = div64_u64(n, d);
2354 
2355 	if (pwr_efficiency_ratio > (u64)0xFFFF)
2356 		return 0;
2357 
2358 	return (u16)pwr_efficiency_ratio;
2359 }
2360 
2361 static bool si_should_disable_uvd_powertune(struct amdgpu_device *adev,
2362 					    struct amdgpu_ps *amdgpu_state)
2363 {
2364 	struct si_power_info *si_pi = si_get_pi(adev);
2365 
2366 	if (si_pi->dyn_powertune_data.disable_uvd_powertune &&
2367 	    amdgpu_state->vclk && amdgpu_state->dclk)
2368 		return true;
2369 
2370 	return false;
2371 }
2372 
2373 struct evergreen_power_info *evergreen_get_pi(struct amdgpu_device *adev)
2374 {
2375 	struct evergreen_power_info *pi = adev->pm.dpm.priv;
2376 
2377 	return pi;
2378 }
2379 
2380 static int si_populate_power_containment_values(struct amdgpu_device *adev,
2381 						struct amdgpu_ps *amdgpu_state,
2382 						SISLANDS_SMC_SWSTATE *smc_state)
2383 {
2384 	struct evergreen_power_info *eg_pi = evergreen_get_pi(adev);
2385 	struct ni_power_info *ni_pi = ni_get_pi(adev);
2386 	struct  si_ps *state = si_get_ps(amdgpu_state);
2387 	SISLANDS_SMC_VOLTAGE_VALUE vddc;
2388 	u32 prev_sclk;
2389 	u32 max_sclk;
2390 	u32 min_sclk;
2391 	u16 prev_std_vddc;
2392 	u16 curr_std_vddc;
2393 	int i;
2394 	u16 pwr_efficiency_ratio;
2395 	u8 max_ps_percent;
2396 	bool disable_uvd_power_tune;
2397 	int ret;
2398 
2399 	if (ni_pi->enable_power_containment == false)
2400 		return 0;
2401 
2402 	if (state->performance_level_count == 0)
2403 		return -EINVAL;
2404 
2405 	if (smc_state->levelCount != state->performance_level_count)
2406 		return -EINVAL;
2407 
2408 	disable_uvd_power_tune = si_should_disable_uvd_powertune(adev, amdgpu_state);
2409 
2410 	smc_state->levels[0].dpm2.MaxPS = 0;
2411 	smc_state->levels[0].dpm2.NearTDPDec = 0;
2412 	smc_state->levels[0].dpm2.AboveSafeInc = 0;
2413 	smc_state->levels[0].dpm2.BelowSafeInc = 0;
2414 	smc_state->levels[0].dpm2.PwrEfficiencyRatio = 0;
2415 
2416 	for (i = 1; i < state->performance_level_count; i++) {
2417 		prev_sclk = state->performance_levels[i-1].sclk;
2418 		max_sclk  = state->performance_levels[i].sclk;
2419 		if (i == 1)
2420 			max_ps_percent = SISLANDS_DPM2_MAXPS_PERCENT_M;
2421 		else
2422 			max_ps_percent = SISLANDS_DPM2_MAXPS_PERCENT_H;
2423 
2424 		if (prev_sclk > max_sclk)
2425 			return -EINVAL;
2426 
2427 		if ((max_ps_percent == 0) ||
2428 		    (prev_sclk == max_sclk) ||
2429 		    disable_uvd_power_tune)
2430 			min_sclk = max_sclk;
2431 		else if (i == 1)
2432 			min_sclk = prev_sclk;
2433 		else
2434 			min_sclk = (prev_sclk * (u32)max_ps_percent) / 100;
2435 
2436 		if (min_sclk < state->performance_levels[0].sclk)
2437 			min_sclk = state->performance_levels[0].sclk;
2438 
2439 		if (min_sclk == 0)
2440 			return -EINVAL;
2441 
2442 		ret = si_populate_voltage_value(adev, &eg_pi->vddc_voltage_table,
2443 						state->performance_levels[i-1].vddc, &vddc);
2444 		if (ret)
2445 			return ret;
2446 
2447 		ret = si_get_std_voltage_value(adev, &vddc, &prev_std_vddc);
2448 		if (ret)
2449 			return ret;
2450 
2451 		ret = si_populate_voltage_value(adev, &eg_pi->vddc_voltage_table,
2452 						state->performance_levels[i].vddc, &vddc);
2453 		if (ret)
2454 			return ret;
2455 
2456 		ret = si_get_std_voltage_value(adev, &vddc, &curr_std_vddc);
2457 		if (ret)
2458 			return ret;
2459 
2460 		pwr_efficiency_ratio = si_calculate_power_efficiency_ratio(adev,
2461 									   prev_std_vddc, curr_std_vddc);
2462 
2463 		smc_state->levels[i].dpm2.MaxPS = (u8)((SISLANDS_DPM2_MAX_PULSE_SKIP * (max_sclk - min_sclk)) / max_sclk);
2464 		smc_state->levels[i].dpm2.NearTDPDec = SISLANDS_DPM2_NEAR_TDP_DEC;
2465 		smc_state->levels[i].dpm2.AboveSafeInc = SISLANDS_DPM2_ABOVE_SAFE_INC;
2466 		smc_state->levels[i].dpm2.BelowSafeInc = SISLANDS_DPM2_BELOW_SAFE_INC;
2467 		smc_state->levels[i].dpm2.PwrEfficiencyRatio = cpu_to_be16(pwr_efficiency_ratio);
2468 	}
2469 
2470 	return 0;
2471 }
2472 
2473 static int si_populate_sq_ramping_values(struct amdgpu_device *adev,
2474 					 struct amdgpu_ps *amdgpu_state,
2475 					 SISLANDS_SMC_SWSTATE *smc_state)
2476 {
2477 	struct ni_power_info *ni_pi = ni_get_pi(adev);
2478 	struct  si_ps *state = si_get_ps(amdgpu_state);
2479 	u32 sq_power_throttle, sq_power_throttle2;
2480 	bool enable_sq_ramping = ni_pi->enable_sq_ramping;
2481 	int i;
2482 
2483 	if (state->performance_level_count == 0)
2484 		return -EINVAL;
2485 
2486 	if (smc_state->levelCount != state->performance_level_count)
2487 		return -EINVAL;
2488 
2489 	if (adev->pm.dpm.sq_ramping_threshold == 0)
2490 		return -EINVAL;
2491 
2492 	if (SISLANDS_DPM2_SQ_RAMP_MAX_POWER > (MAX_POWER_MASK >> MAX_POWER_SHIFT))
2493 		enable_sq_ramping = false;
2494 
2495 	if (SISLANDS_DPM2_SQ_RAMP_MIN_POWER > (MIN_POWER_MASK >> MIN_POWER_SHIFT))
2496 		enable_sq_ramping = false;
2497 
2498 	if (SISLANDS_DPM2_SQ_RAMP_MAX_POWER_DELTA > (MAX_POWER_DELTA_MASK >> MAX_POWER_DELTA_SHIFT))
2499 		enable_sq_ramping = false;
2500 
2501 	if (SISLANDS_DPM2_SQ_RAMP_STI_SIZE > (STI_SIZE_MASK >> STI_SIZE_SHIFT))
2502 		enable_sq_ramping = false;
2503 
2504 	if (SISLANDS_DPM2_SQ_RAMP_LTI_RATIO > (LTI_RATIO_MASK >> LTI_RATIO_SHIFT))
2505 		enable_sq_ramping = false;
2506 
2507 	for (i = 0; i < state->performance_level_count; i++) {
2508 		sq_power_throttle = 0;
2509 		sq_power_throttle2 = 0;
2510 
2511 		if ((state->performance_levels[i].sclk >= adev->pm.dpm.sq_ramping_threshold) &&
2512 		    enable_sq_ramping) {
2513 			sq_power_throttle |= MAX_POWER(SISLANDS_DPM2_SQ_RAMP_MAX_POWER);
2514 			sq_power_throttle |= MIN_POWER(SISLANDS_DPM2_SQ_RAMP_MIN_POWER);
2515 			sq_power_throttle2 |= MAX_POWER_DELTA(SISLANDS_DPM2_SQ_RAMP_MAX_POWER_DELTA);
2516 			sq_power_throttle2 |= STI_SIZE(SISLANDS_DPM2_SQ_RAMP_STI_SIZE);
2517 			sq_power_throttle2 |= LTI_RATIO(SISLANDS_DPM2_SQ_RAMP_LTI_RATIO);
2518 		} else {
2519 			sq_power_throttle |= MAX_POWER_MASK | MIN_POWER_MASK;
2520 			sq_power_throttle2 |= MAX_POWER_DELTA_MASK | STI_SIZE_MASK | LTI_RATIO_MASK;
2521 		}
2522 
2523 		smc_state->levels[i].SQPowerThrottle = cpu_to_be32(sq_power_throttle);
2524 		smc_state->levels[i].SQPowerThrottle_2 = cpu_to_be32(sq_power_throttle2);
2525 	}
2526 
2527 	return 0;
2528 }
2529 
2530 static int si_enable_power_containment(struct amdgpu_device *adev,
2531 				       struct amdgpu_ps *amdgpu_new_state,
2532 				       bool enable)
2533 {
2534 	struct ni_power_info *ni_pi = ni_get_pi(adev);
2535 	PPSMC_Result smc_result;
2536 	int ret = 0;
2537 
2538 	if (ni_pi->enable_power_containment) {
2539 		if (enable) {
2540 			if (!si_should_disable_uvd_powertune(adev, amdgpu_new_state)) {
2541 				smc_result = amdgpu_si_send_msg_to_smc(adev, PPSMC_TDPClampingActive);
2542 				if (smc_result != PPSMC_Result_OK) {
2543 					ret = -EINVAL;
2544 					ni_pi->pc_enabled = false;
2545 				} else {
2546 					ni_pi->pc_enabled = true;
2547 				}
2548 			}
2549 		} else {
2550 			smc_result = amdgpu_si_send_msg_to_smc(adev, PPSMC_TDPClampingInactive);
2551 			if (smc_result != PPSMC_Result_OK)
2552 				ret = -EINVAL;
2553 			ni_pi->pc_enabled = false;
2554 		}
2555 	}
2556 
2557 	return ret;
2558 }
2559 
2560 static int si_initialize_smc_dte_tables(struct amdgpu_device *adev)
2561 {
2562 	struct si_power_info *si_pi = si_get_pi(adev);
2563 	int ret = 0;
2564 	struct si_dte_data *dte_data = &si_pi->dte_data;
2565 	Smc_SIslands_DTE_Configuration *dte_tables = NULL;
2566 	u32 table_size;
2567 	u8 tdep_count;
2568 	u32 i;
2569 
2570 	if (dte_data == NULL)
2571 		si_pi->enable_dte = false;
2572 
2573 	if (si_pi->enable_dte == false)
2574 		return 0;
2575 
2576 	if (dte_data->k <= 0)
2577 		return -EINVAL;
2578 
2579 	dte_tables = kzalloc(sizeof(Smc_SIslands_DTE_Configuration), GFP_KERNEL);
2580 	if (dte_tables == NULL) {
2581 		si_pi->enable_dte = false;
2582 		return -ENOMEM;
2583 	}
2584 
2585 	table_size = dte_data->k;
2586 
2587 	if (table_size > SMC_SISLANDS_DTE_MAX_FILTER_STAGES)
2588 		table_size = SMC_SISLANDS_DTE_MAX_FILTER_STAGES;
2589 
2590 	tdep_count = dte_data->tdep_count;
2591 	if (tdep_count > SMC_SISLANDS_DTE_MAX_TEMPERATURE_DEPENDENT_ARRAY_SIZE)
2592 		tdep_count = SMC_SISLANDS_DTE_MAX_TEMPERATURE_DEPENDENT_ARRAY_SIZE;
2593 
2594 	dte_tables->K = cpu_to_be32(table_size);
2595 	dte_tables->T0 = cpu_to_be32(dte_data->t0);
2596 	dte_tables->MaxT = cpu_to_be32(dte_data->max_t);
2597 	dte_tables->WindowSize = dte_data->window_size;
2598 	dte_tables->temp_select = dte_data->temp_select;
2599 	dte_tables->DTE_mode = dte_data->dte_mode;
2600 	dte_tables->Tthreshold = cpu_to_be32(dte_data->t_threshold);
2601 
2602 	if (tdep_count > 0)
2603 		table_size--;
2604 
2605 	for (i = 0; i < table_size; i++) {
2606 		dte_tables->tau[i] = cpu_to_be32(dte_data->tau[i]);
2607 		dte_tables->R[i]   = cpu_to_be32(dte_data->r[i]);
2608 	}
2609 
2610 	dte_tables->Tdep_count = tdep_count;
2611 
2612 	for (i = 0; i < (u32)tdep_count; i++) {
2613 		dte_tables->T_limits[i] = dte_data->t_limits[i];
2614 		dte_tables->Tdep_tau[i] = cpu_to_be32(dte_data->tdep_tau[i]);
2615 		dte_tables->Tdep_R[i] = cpu_to_be32(dte_data->tdep_r[i]);
2616 	}
2617 
2618 	ret = amdgpu_si_copy_bytes_to_smc(adev, si_pi->dte_table_start,
2619 					  (u8 *)dte_tables,
2620 					  sizeof(Smc_SIslands_DTE_Configuration),
2621 					  si_pi->sram_end);
2622 	kfree(dte_tables);
2623 
2624 	return ret;
2625 }
2626 
2627 static int si_get_cac_std_voltage_max_min(struct amdgpu_device *adev,
2628 					  u16 *max, u16 *min)
2629 {
2630 	struct si_power_info *si_pi = si_get_pi(adev);
2631 	struct amdgpu_cac_leakage_table *table =
2632 		&adev->pm.dpm.dyn_state.cac_leakage_table;
2633 	u32 i;
2634 	u32 v0_loadline;
2635 
2636 	if (table == NULL)
2637 		return -EINVAL;
2638 
2639 	*max = 0;
2640 	*min = 0xFFFF;
2641 
2642 	for (i = 0; i < table->count; i++) {
2643 		if (table->entries[i].vddc > *max)
2644 			*max = table->entries[i].vddc;
2645 		if (table->entries[i].vddc < *min)
2646 			*min = table->entries[i].vddc;
2647 	}
2648 
2649 	if (si_pi->powertune_data->lkge_lut_v0_percent > 100)
2650 		return -EINVAL;
2651 
2652 	v0_loadline = (*min) * (100 - si_pi->powertune_data->lkge_lut_v0_percent) / 100;
2653 
2654 	if (v0_loadline > 0xFFFFUL)
2655 		return -EINVAL;
2656 
2657 	*min = (u16)v0_loadline;
2658 
2659 	if ((*min > *max) || (*max == 0) || (*min == 0))
2660 		return -EINVAL;
2661 
2662 	return 0;
2663 }
2664 
2665 static u16 si_get_cac_std_voltage_step(u16 max, u16 min)
2666 {
2667 	return ((max - min) + (SMC_SISLANDS_LKGE_LUT_NUM_OF_VOLT_ENTRIES - 1)) /
2668 		SMC_SISLANDS_LKGE_LUT_NUM_OF_VOLT_ENTRIES;
2669 }
2670 
2671 static int si_init_dte_leakage_table(struct amdgpu_device *adev,
2672 				     PP_SIslands_CacConfig *cac_tables,
2673 				     u16 vddc_max, u16 vddc_min, u16 vddc_step,
2674 				     u16 t0, u16 t_step)
2675 {
2676 	struct si_power_info *si_pi = si_get_pi(adev);
2677 	u32 leakage;
2678 	unsigned int i, j;
2679 	s32 t;
2680 	u32 smc_leakage;
2681 	u32 scaling_factor;
2682 	u16 voltage;
2683 
2684 	scaling_factor = si_get_smc_power_scaling_factor(adev);
2685 
2686 	for (i = 0; i < SMC_SISLANDS_LKGE_LUT_NUM_OF_TEMP_ENTRIES ; i++) {
2687 		t = (1000 * (i * t_step + t0));
2688 
2689 		for (j = 0; j < SMC_SISLANDS_LKGE_LUT_NUM_OF_VOLT_ENTRIES; j++) {
2690 			voltage = vddc_max - (vddc_step * j);
2691 
2692 			si_calculate_leakage_for_v_and_t(adev,
2693 							 &si_pi->powertune_data->leakage_coefficients,
2694 							 voltage,
2695 							 t,
2696 							 si_pi->dyn_powertune_data.cac_leakage,
2697 							 &leakage);
2698 
2699 			smc_leakage = si_scale_power_for_smc(leakage, scaling_factor) / 4;
2700 
2701 			if (smc_leakage > 0xFFFF)
2702 				smc_leakage = 0xFFFF;
2703 
2704 			cac_tables->cac_lkge_lut[i][SMC_SISLANDS_LKGE_LUT_NUM_OF_VOLT_ENTRIES-1-j] =
2705 				cpu_to_be16((u16)smc_leakage);
2706 		}
2707 	}
2708 	return 0;
2709 }
2710 
2711 static int si_init_simplified_leakage_table(struct amdgpu_device *adev,
2712 					    PP_SIslands_CacConfig *cac_tables,
2713 					    u16 vddc_max, u16 vddc_min, u16 vddc_step)
2714 {
2715 	struct si_power_info *si_pi = si_get_pi(adev);
2716 	u32 leakage;
2717 	unsigned int i, j;
2718 	u32 smc_leakage;
2719 	u32 scaling_factor;
2720 	u16 voltage;
2721 
2722 	scaling_factor = si_get_smc_power_scaling_factor(adev);
2723 
2724 	for (j = 0; j < SMC_SISLANDS_LKGE_LUT_NUM_OF_VOLT_ENTRIES; j++) {
2725 		voltage = vddc_max - (vddc_step * j);
2726 
2727 		si_calculate_leakage_for_v(adev,
2728 					   &si_pi->powertune_data->leakage_coefficients,
2729 					   si_pi->powertune_data->fixed_kt,
2730 					   voltage,
2731 					   si_pi->dyn_powertune_data.cac_leakage,
2732 					   &leakage);
2733 
2734 		smc_leakage = si_scale_power_for_smc(leakage, scaling_factor) / 4;
2735 
2736 		if (smc_leakage > 0xFFFF)
2737 			smc_leakage = 0xFFFF;
2738 
2739 		for (i = 0; i < SMC_SISLANDS_LKGE_LUT_NUM_OF_TEMP_ENTRIES ; i++)
2740 			cac_tables->cac_lkge_lut[i][SMC_SISLANDS_LKGE_LUT_NUM_OF_VOLT_ENTRIES-1-j] =
2741 				cpu_to_be16((u16)smc_leakage);
2742 	}
2743 	return 0;
2744 }
2745 
2746 static int si_initialize_smc_cac_tables(struct amdgpu_device *adev)
2747 {
2748 	struct ni_power_info *ni_pi = ni_get_pi(adev);
2749 	struct si_power_info *si_pi = si_get_pi(adev);
2750 	PP_SIslands_CacConfig *cac_tables = NULL;
2751 	u16 vddc_max, vddc_min, vddc_step;
2752 	u16 t0, t_step;
2753 	u32 load_line_slope, reg;
2754 	int ret = 0;
2755 	u32 ticks_per_us = amdgpu_asic_get_xclk(adev) / 100;
2756 
2757 	if (ni_pi->enable_cac == false)
2758 		return 0;
2759 
2760 	cac_tables = kzalloc(sizeof(PP_SIslands_CacConfig), GFP_KERNEL);
2761 	if (!cac_tables)
2762 		return -ENOMEM;
2763 
2764 	reg = RREG32(CG_CAC_CTRL) & ~CAC_WINDOW_MASK;
2765 	reg |= CAC_WINDOW(si_pi->powertune_data->cac_window);
2766 	WREG32(CG_CAC_CTRL, reg);
2767 
2768 	si_pi->dyn_powertune_data.cac_leakage = adev->pm.dpm.cac_leakage;
2769 	si_pi->dyn_powertune_data.dc_pwr_value =
2770 		si_pi->powertune_data->dc_cac[NISLANDS_DCCAC_LEVEL_0];
2771 	si_pi->dyn_powertune_data.wintime = si_calculate_cac_wintime(adev);
2772 	si_pi->dyn_powertune_data.shift_n = si_pi->powertune_data->shift_n_default;
2773 
2774 	si_pi->dyn_powertune_data.leakage_minimum_temperature = 80 * 1000;
2775 
2776 	ret = si_get_cac_std_voltage_max_min(adev, &vddc_max, &vddc_min);
2777 	if (ret)
2778 		goto done_free;
2779 
2780 	vddc_step = si_get_cac_std_voltage_step(vddc_max, vddc_min);
2781 	vddc_min = vddc_max - (vddc_step * (SMC_SISLANDS_LKGE_LUT_NUM_OF_VOLT_ENTRIES - 1));
2782 	t_step = 4;
2783 	t0 = 60;
2784 
2785 	if (si_pi->enable_dte || ni_pi->driver_calculate_cac_leakage)
2786 		ret = si_init_dte_leakage_table(adev, cac_tables,
2787 						vddc_max, vddc_min, vddc_step,
2788 						t0, t_step);
2789 	else
2790 		ret = si_init_simplified_leakage_table(adev, cac_tables,
2791 						       vddc_max, vddc_min, vddc_step);
2792 	if (ret)
2793 		goto done_free;
2794 
2795 	load_line_slope = ((u32)adev->pm.dpm.load_line_slope << SMC_SISLANDS_SCALE_R) / 100;
2796 
2797 	cac_tables->l2numWin_TDP = cpu_to_be32(si_pi->dyn_powertune_data.l2_lta_window_size);
2798 	cac_tables->lts_truncate_n = si_pi->dyn_powertune_data.lts_truncate;
2799 	cac_tables->SHIFT_N = si_pi->dyn_powertune_data.shift_n;
2800 	cac_tables->lkge_lut_V0 = cpu_to_be32((u32)vddc_min);
2801 	cac_tables->lkge_lut_Vstep = cpu_to_be32((u32)vddc_step);
2802 	cac_tables->R_LL = cpu_to_be32(load_line_slope);
2803 	cac_tables->WinTime = cpu_to_be32(si_pi->dyn_powertune_data.wintime);
2804 	cac_tables->calculation_repeats = cpu_to_be32(2);
2805 	cac_tables->dc_cac = cpu_to_be32(0);
2806 	cac_tables->log2_PG_LKG_SCALE = 12;
2807 	cac_tables->cac_temp = si_pi->powertune_data->operating_temp;
2808 	cac_tables->lkge_lut_T0 = cpu_to_be32((u32)t0);
2809 	cac_tables->lkge_lut_Tstep = cpu_to_be32((u32)t_step);
2810 
2811 	ret = amdgpu_si_copy_bytes_to_smc(adev, si_pi->cac_table_start,
2812 					  (u8 *)cac_tables,
2813 					  sizeof(PP_SIslands_CacConfig),
2814 					  si_pi->sram_end);
2815 
2816 	if (ret)
2817 		goto done_free;
2818 
2819 	ret = si_write_smc_soft_register(adev, SI_SMC_SOFT_REGISTER_ticks_per_us, ticks_per_us);
2820 
2821 done_free:
2822 	if (ret) {
2823 		ni_pi->enable_cac = false;
2824 		ni_pi->enable_power_containment = false;
2825 	}
2826 
2827 	kfree(cac_tables);
2828 
2829 	return ret;
2830 }
2831 
2832 static int si_program_cac_config_registers(struct amdgpu_device *adev,
2833 					   const struct si_cac_config_reg *cac_config_regs)
2834 {
2835 	const struct si_cac_config_reg *config_regs = cac_config_regs;
2836 	u32 data = 0, offset;
2837 
2838 	if (!config_regs)
2839 		return -EINVAL;
2840 
2841 	while (config_regs->offset != 0xFFFFFFFF) {
2842 		switch (config_regs->type) {
2843 		case SISLANDS_CACCONFIG_CGIND:
2844 			offset = SMC_CG_IND_START + config_regs->offset;
2845 			if (offset < SMC_CG_IND_END)
2846 				data = RREG32_SMC(offset);
2847 			break;
2848 		default:
2849 			data = RREG32(config_regs->offset);
2850 			break;
2851 		}
2852 
2853 		data &= ~config_regs->mask;
2854 		data |= ((config_regs->value << config_regs->shift) & config_regs->mask);
2855 
2856 		switch (config_regs->type) {
2857 		case SISLANDS_CACCONFIG_CGIND:
2858 			offset = SMC_CG_IND_START + config_regs->offset;
2859 			if (offset < SMC_CG_IND_END)
2860 				WREG32_SMC(offset, data);
2861 			break;
2862 		default:
2863 			WREG32(config_regs->offset, data);
2864 			break;
2865 		}
2866 		config_regs++;
2867 	}
2868 	return 0;
2869 }
2870 
2871 static int si_initialize_hardware_cac_manager(struct amdgpu_device *adev)
2872 {
2873 	struct ni_power_info *ni_pi = ni_get_pi(adev);
2874 	struct si_power_info *si_pi = si_get_pi(adev);
2875 	int ret;
2876 
2877 	if ((ni_pi->enable_cac == false) ||
2878 	    (ni_pi->cac_configuration_required == false))
2879 		return 0;
2880 
2881 	ret = si_program_cac_config_registers(adev, si_pi->lcac_config);
2882 	if (ret)
2883 		return ret;
2884 	ret = si_program_cac_config_registers(adev, si_pi->cac_override);
2885 	if (ret)
2886 		return ret;
2887 	ret = si_program_cac_config_registers(adev, si_pi->cac_weights);
2888 	if (ret)
2889 		return ret;
2890 
2891 	return 0;
2892 }
2893 
2894 static int si_enable_smc_cac(struct amdgpu_device *adev,
2895 			     struct amdgpu_ps *amdgpu_new_state,
2896 			     bool enable)
2897 {
2898 	struct ni_power_info *ni_pi = ni_get_pi(adev);
2899 	struct si_power_info *si_pi = si_get_pi(adev);
2900 	PPSMC_Result smc_result;
2901 	int ret = 0;
2902 
2903 	if (ni_pi->enable_cac) {
2904 		if (enable) {
2905 			if (!si_should_disable_uvd_powertune(adev, amdgpu_new_state)) {
2906 				if (ni_pi->support_cac_long_term_average) {
2907 					smc_result = amdgpu_si_send_msg_to_smc(adev, PPSMC_CACLongTermAvgEnable);
2908 					if (smc_result != PPSMC_Result_OK)
2909 						ni_pi->support_cac_long_term_average = false;
2910 				}
2911 
2912 				smc_result = amdgpu_si_send_msg_to_smc(adev, PPSMC_MSG_EnableCac);
2913 				if (smc_result != PPSMC_Result_OK) {
2914 					ret = -EINVAL;
2915 					ni_pi->cac_enabled = false;
2916 				} else {
2917 					ni_pi->cac_enabled = true;
2918 				}
2919 
2920 				if (si_pi->enable_dte) {
2921 					smc_result = amdgpu_si_send_msg_to_smc(adev, PPSMC_MSG_EnableDTE);
2922 					if (smc_result != PPSMC_Result_OK)
2923 						ret = -EINVAL;
2924 				}
2925 			}
2926 		} else if (ni_pi->cac_enabled) {
2927 			if (si_pi->enable_dte)
2928 				smc_result = amdgpu_si_send_msg_to_smc(adev, PPSMC_MSG_DisableDTE);
2929 
2930 			smc_result = amdgpu_si_send_msg_to_smc(adev, PPSMC_MSG_DisableCac);
2931 
2932 			ni_pi->cac_enabled = false;
2933 
2934 			if (ni_pi->support_cac_long_term_average)
2935 				smc_result = amdgpu_si_send_msg_to_smc(adev, PPSMC_CACLongTermAvgDisable);
2936 		}
2937 	}
2938 	return ret;
2939 }
2940 
2941 static int si_init_smc_spll_table(struct amdgpu_device *adev)
2942 {
2943 	struct ni_power_info *ni_pi = ni_get_pi(adev);
2944 	struct si_power_info *si_pi = si_get_pi(adev);
2945 	SMC_SISLANDS_SPLL_DIV_TABLE *spll_table;
2946 	SISLANDS_SMC_SCLK_VALUE sclk_params;
2947 	u32 fb_div, p_div;
2948 	u32 clk_s, clk_v;
2949 	u32 sclk = 0;
2950 	int ret = 0;
2951 	u32 tmp;
2952 	int i;
2953 
2954 	if (si_pi->spll_table_start == 0)
2955 		return -EINVAL;
2956 
2957 	spll_table = kzalloc(sizeof(SMC_SISLANDS_SPLL_DIV_TABLE), GFP_KERNEL);
2958 	if (spll_table == NULL)
2959 		return -ENOMEM;
2960 
2961 	for (i = 0; i < 256; i++) {
2962 		ret = si_calculate_sclk_params(adev, sclk, &sclk_params);
2963 		if (ret)
2964 			break;
2965 		p_div = (sclk_params.vCG_SPLL_FUNC_CNTL & SPLL_PDIV_A_MASK) >> SPLL_PDIV_A_SHIFT;
2966 		fb_div = (sclk_params.vCG_SPLL_FUNC_CNTL_3 & SPLL_FB_DIV_MASK) >> SPLL_FB_DIV_SHIFT;
2967 		clk_s = (sclk_params.vCG_SPLL_SPREAD_SPECTRUM & CLK_S_MASK) >> CLK_S_SHIFT;
2968 		clk_v = (sclk_params.vCG_SPLL_SPREAD_SPECTRUM_2 & CLK_V_MASK) >> CLK_V_SHIFT;
2969 
2970 		fb_div &= ~0x00001FFF;
2971 		fb_div >>= 1;
2972 		clk_v >>= 6;
2973 
2974 		if (p_div & ~(SMC_SISLANDS_SPLL_DIV_TABLE_PDIV_MASK >> SMC_SISLANDS_SPLL_DIV_TABLE_PDIV_SHIFT))
2975 			ret = -EINVAL;
2976 		if (fb_div & ~(SMC_SISLANDS_SPLL_DIV_TABLE_FBDIV_MASK >> SMC_SISLANDS_SPLL_DIV_TABLE_FBDIV_SHIFT))
2977 			ret = -EINVAL;
2978 		if (clk_s & ~(SMC_SISLANDS_SPLL_DIV_TABLE_CLKS_MASK >> SMC_SISLANDS_SPLL_DIV_TABLE_CLKS_SHIFT))
2979 			ret = -EINVAL;
2980 		if (clk_v & ~(SMC_SISLANDS_SPLL_DIV_TABLE_CLKV_MASK >> SMC_SISLANDS_SPLL_DIV_TABLE_CLKV_SHIFT))
2981 			ret = -EINVAL;
2982 
2983 		if (ret)
2984 			break;
2985 
2986 		tmp = ((fb_div << SMC_SISLANDS_SPLL_DIV_TABLE_FBDIV_SHIFT) & SMC_SISLANDS_SPLL_DIV_TABLE_FBDIV_MASK) |
2987 			((p_div << SMC_SISLANDS_SPLL_DIV_TABLE_PDIV_SHIFT) & SMC_SISLANDS_SPLL_DIV_TABLE_PDIV_MASK);
2988 		spll_table->freq[i] = cpu_to_be32(tmp);
2989 
2990 		tmp = ((clk_v << SMC_SISLANDS_SPLL_DIV_TABLE_CLKV_SHIFT) & SMC_SISLANDS_SPLL_DIV_TABLE_CLKV_MASK) |
2991 			((clk_s << SMC_SISLANDS_SPLL_DIV_TABLE_CLKS_SHIFT) & SMC_SISLANDS_SPLL_DIV_TABLE_CLKS_MASK);
2992 		spll_table->ss[i] = cpu_to_be32(tmp);
2993 
2994 		sclk += 512;
2995 	}
2996 
2997 
2998 	if (!ret)
2999 		ret = amdgpu_si_copy_bytes_to_smc(adev, si_pi->spll_table_start,
3000 						  (u8 *)spll_table,
3001 						  sizeof(SMC_SISLANDS_SPLL_DIV_TABLE),
3002 						  si_pi->sram_end);
3003 
3004 	if (ret)
3005 		ni_pi->enable_power_containment = false;
3006 
3007 	kfree(spll_table);
3008 
3009 	return ret;
3010 }
3011 
3012 static u16 si_get_lower_of_leakage_and_vce_voltage(struct amdgpu_device *adev,
3013 						   u16 vce_voltage)
3014 {
3015 	u16 highest_leakage = 0;
3016 	struct si_power_info *si_pi = si_get_pi(adev);
3017 	int i;
3018 
3019 	for (i = 0; i < si_pi->leakage_voltage.count; i++){
3020 		if (highest_leakage < si_pi->leakage_voltage.entries[i].voltage)
3021 			highest_leakage = si_pi->leakage_voltage.entries[i].voltage;
3022 	}
3023 
3024 	if (si_pi->leakage_voltage.count && (highest_leakage < vce_voltage))
3025 		return highest_leakage;
3026 
3027 	return vce_voltage;
3028 }
3029 
3030 static int si_get_vce_clock_voltage(struct amdgpu_device *adev,
3031 				    u32 evclk, u32 ecclk, u16 *voltage)
3032 {
3033 	u32 i;
3034 	int ret = -EINVAL;
3035 	struct amdgpu_vce_clock_voltage_dependency_table *table =
3036 		&adev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table;
3037 
3038 	if (((evclk == 0) && (ecclk == 0)) ||
3039 	    (table && (table->count == 0))) {
3040 		*voltage = 0;
3041 		return 0;
3042 	}
3043 
3044 	for (i = 0; i < table->count; i++) {
3045 		if ((evclk <= table->entries[i].evclk) &&
3046 		    (ecclk <= table->entries[i].ecclk)) {
3047 			*voltage = table->entries[i].v;
3048 			ret = 0;
3049 			break;
3050 		}
3051 	}
3052 
3053 	/* if no match return the highest voltage */
3054 	if (ret)
3055 		*voltage = table->entries[table->count - 1].v;
3056 
3057 	*voltage = si_get_lower_of_leakage_and_vce_voltage(adev, *voltage);
3058 
3059 	return ret;
3060 }
3061 
3062 static bool si_dpm_vblank_too_short(void *handle)
3063 {
3064 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
3065 	u32 vblank_time = amdgpu_dpm_get_vblank_time(adev);
3066 	/* we never hit the non-gddr5 limit so disable it */
3067 	u32 switch_limit = adev->gmc.vram_type == AMDGPU_VRAM_TYPE_GDDR5 ? 450 : 0;
3068 
3069 	if (vblank_time < switch_limit)
3070 		return true;
3071 	else
3072 		return false;
3073 
3074 }
3075 
3076 static int ni_copy_and_switch_arb_sets(struct amdgpu_device *adev,
3077 				u32 arb_freq_src, u32 arb_freq_dest)
3078 {
3079 	u32 mc_arb_dram_timing;
3080 	u32 mc_arb_dram_timing2;
3081 	u32 burst_time;
3082 	u32 mc_cg_config;
3083 
3084 	switch (arb_freq_src) {
3085 	case MC_CG_ARB_FREQ_F0:
3086 		mc_arb_dram_timing  = RREG32(MC_ARB_DRAM_TIMING);
3087 		mc_arb_dram_timing2 = RREG32(MC_ARB_DRAM_TIMING2);
3088 		burst_time = (RREG32(MC_ARB_BURST_TIME) & STATE0_MASK) >> STATE0_SHIFT;
3089 		break;
3090 	case MC_CG_ARB_FREQ_F1:
3091 		mc_arb_dram_timing  = RREG32(MC_ARB_DRAM_TIMING_1);
3092 		mc_arb_dram_timing2 = RREG32(MC_ARB_DRAM_TIMING2_1);
3093 		burst_time = (RREG32(MC_ARB_BURST_TIME) & STATE1_MASK) >> STATE1_SHIFT;
3094 		break;
3095 	case MC_CG_ARB_FREQ_F2:
3096 		mc_arb_dram_timing  = RREG32(MC_ARB_DRAM_TIMING_2);
3097 		mc_arb_dram_timing2 = RREG32(MC_ARB_DRAM_TIMING2_2);
3098 		burst_time = (RREG32(MC_ARB_BURST_TIME) & STATE2_MASK) >> STATE2_SHIFT;
3099 		break;
3100 	case MC_CG_ARB_FREQ_F3:
3101 		mc_arb_dram_timing  = RREG32(MC_ARB_DRAM_TIMING_3);
3102 		mc_arb_dram_timing2 = RREG32(MC_ARB_DRAM_TIMING2_3);
3103 		burst_time = (RREG32(MC_ARB_BURST_TIME) & STATE3_MASK) >> STATE3_SHIFT;
3104 		break;
3105 	default:
3106 		return -EINVAL;
3107 	}
3108 
3109 	switch (arb_freq_dest) {
3110 	case MC_CG_ARB_FREQ_F0:
3111 		WREG32(MC_ARB_DRAM_TIMING, mc_arb_dram_timing);
3112 		WREG32(MC_ARB_DRAM_TIMING2, mc_arb_dram_timing2);
3113 		WREG32_P(MC_ARB_BURST_TIME, STATE0(burst_time), ~STATE0_MASK);
3114 		break;
3115 	case MC_CG_ARB_FREQ_F1:
3116 		WREG32(MC_ARB_DRAM_TIMING_1, mc_arb_dram_timing);
3117 		WREG32(MC_ARB_DRAM_TIMING2_1, mc_arb_dram_timing2);
3118 		WREG32_P(MC_ARB_BURST_TIME, STATE1(burst_time), ~STATE1_MASK);
3119 		break;
3120 	case MC_CG_ARB_FREQ_F2:
3121 		WREG32(MC_ARB_DRAM_TIMING_2, mc_arb_dram_timing);
3122 		WREG32(MC_ARB_DRAM_TIMING2_2, mc_arb_dram_timing2);
3123 		WREG32_P(MC_ARB_BURST_TIME, STATE2(burst_time), ~STATE2_MASK);
3124 		break;
3125 	case MC_CG_ARB_FREQ_F3:
3126 		WREG32(MC_ARB_DRAM_TIMING_3, mc_arb_dram_timing);
3127 		WREG32(MC_ARB_DRAM_TIMING2_3, mc_arb_dram_timing2);
3128 		WREG32_P(MC_ARB_BURST_TIME, STATE3(burst_time), ~STATE3_MASK);
3129 		break;
3130 	default:
3131 		return -EINVAL;
3132 	}
3133 
3134 	mc_cg_config = RREG32(MC_CG_CONFIG) | 0x0000000F;
3135 	WREG32(MC_CG_CONFIG, mc_cg_config);
3136 	WREG32_P(MC_ARB_CG, CG_ARB_REQ(arb_freq_dest), ~CG_ARB_REQ_MASK);
3137 
3138 	return 0;
3139 }
3140 
3141 static void ni_update_current_ps(struct amdgpu_device *adev,
3142 			  struct amdgpu_ps *rps)
3143 {
3144 	struct si_ps *new_ps = si_get_ps(rps);
3145 	struct evergreen_power_info *eg_pi = evergreen_get_pi(adev);
3146 	struct ni_power_info *ni_pi = ni_get_pi(adev);
3147 
3148 	eg_pi->current_rps = *rps;
3149 	ni_pi->current_ps = *new_ps;
3150 	eg_pi->current_rps.ps_priv = &ni_pi->current_ps;
3151 	adev->pm.dpm.current_ps = &eg_pi->current_rps;
3152 }
3153 
3154 static void ni_update_requested_ps(struct amdgpu_device *adev,
3155 			    struct amdgpu_ps *rps)
3156 {
3157 	struct si_ps *new_ps = si_get_ps(rps);
3158 	struct evergreen_power_info *eg_pi = evergreen_get_pi(adev);
3159 	struct ni_power_info *ni_pi = ni_get_pi(adev);
3160 
3161 	eg_pi->requested_rps = *rps;
3162 	ni_pi->requested_ps = *new_ps;
3163 	eg_pi->requested_rps.ps_priv = &ni_pi->requested_ps;
3164 	adev->pm.dpm.requested_ps = &eg_pi->requested_rps;
3165 }
3166 
3167 static void ni_set_uvd_clock_before_set_eng_clock(struct amdgpu_device *adev,
3168 					   struct amdgpu_ps *new_ps,
3169 					   struct amdgpu_ps *old_ps)
3170 {
3171 	struct si_ps *new_state = si_get_ps(new_ps);
3172 	struct si_ps *current_state = si_get_ps(old_ps);
3173 
3174 	if ((new_ps->vclk == old_ps->vclk) &&
3175 	    (new_ps->dclk == old_ps->dclk))
3176 		return;
3177 
3178 	if (new_state->performance_levels[new_state->performance_level_count - 1].sclk >=
3179 	    current_state->performance_levels[current_state->performance_level_count - 1].sclk)
3180 		return;
3181 
3182 	amdgpu_asic_set_uvd_clocks(adev, new_ps->vclk, new_ps->dclk);
3183 }
3184 
3185 static void ni_set_uvd_clock_after_set_eng_clock(struct amdgpu_device *adev,
3186 					  struct amdgpu_ps *new_ps,
3187 					  struct amdgpu_ps *old_ps)
3188 {
3189 	struct si_ps *new_state = si_get_ps(new_ps);
3190 	struct si_ps *current_state = si_get_ps(old_ps);
3191 
3192 	if ((new_ps->vclk == old_ps->vclk) &&
3193 	    (new_ps->dclk == old_ps->dclk))
3194 		return;
3195 
3196 	if (new_state->performance_levels[new_state->performance_level_count - 1].sclk <
3197 	    current_state->performance_levels[current_state->performance_level_count - 1].sclk)
3198 		return;
3199 
3200 	amdgpu_asic_set_uvd_clocks(adev, new_ps->vclk, new_ps->dclk);
3201 }
3202 
3203 static u16 btc_find_voltage(struct atom_voltage_table *table, u16 voltage)
3204 {
3205 	unsigned int i;
3206 
3207 	for (i = 0; i < table->count; i++)
3208 		if (voltage <= table->entries[i].value)
3209 			return table->entries[i].value;
3210 
3211 	return table->entries[table->count - 1].value;
3212 }
3213 
3214 static u32 btc_find_valid_clock(struct amdgpu_clock_array *clocks,
3215 		                u32 max_clock, u32 requested_clock)
3216 {
3217 	unsigned int i;
3218 
3219 	if ((clocks == NULL) || (clocks->count == 0))
3220 		return (requested_clock < max_clock) ? requested_clock : max_clock;
3221 
3222 	for (i = 0; i < clocks->count; i++) {
3223 		if (clocks->values[i] >= requested_clock)
3224 			return (clocks->values[i] < max_clock) ? clocks->values[i] : max_clock;
3225 	}
3226 
3227 	return (clocks->values[clocks->count - 1] < max_clock) ?
3228 		clocks->values[clocks->count - 1] : max_clock;
3229 }
3230 
3231 static u32 btc_get_valid_mclk(struct amdgpu_device *adev,
3232 			      u32 max_mclk, u32 requested_mclk)
3233 {
3234 	return btc_find_valid_clock(&adev->pm.dpm.dyn_state.valid_mclk_values,
3235 				    max_mclk, requested_mclk);
3236 }
3237 
3238 static u32 btc_get_valid_sclk(struct amdgpu_device *adev,
3239 		              u32 max_sclk, u32 requested_sclk)
3240 {
3241 	return btc_find_valid_clock(&adev->pm.dpm.dyn_state.valid_sclk_values,
3242 				    max_sclk, requested_sclk);
3243 }
3244 
3245 static void btc_get_max_clock_from_voltage_dependency_table(struct amdgpu_clock_voltage_dependency_table *table,
3246 							    u32 *max_clock)
3247 {
3248 	u32 i, clock = 0;
3249 
3250 	if ((table == NULL) || (table->count == 0)) {
3251 		*max_clock = clock;
3252 		return;
3253 	}
3254 
3255 	for (i = 0; i < table->count; i++) {
3256 		if (clock < table->entries[i].clk)
3257 			clock = table->entries[i].clk;
3258 	}
3259 	*max_clock = clock;
3260 }
3261 
3262 static void btc_apply_voltage_dependency_rules(struct amdgpu_clock_voltage_dependency_table *table,
3263 					       u32 clock, u16 max_voltage, u16 *voltage)
3264 {
3265 	u32 i;
3266 
3267 	if ((table == NULL) || (table->count == 0))
3268 		return;
3269 
3270 	for (i= 0; i < table->count; i++) {
3271 		if (clock <= table->entries[i].clk) {
3272 			if (*voltage < table->entries[i].v)
3273 				*voltage = (u16)((table->entries[i].v < max_voltage) ?
3274 					   table->entries[i].v : max_voltage);
3275 			return;
3276 		}
3277 	}
3278 
3279 	*voltage = (*voltage > max_voltage) ? *voltage : max_voltage;
3280 }
3281 
3282 static void btc_adjust_clock_combinations(struct amdgpu_device *adev,
3283 					  const struct amdgpu_clock_and_voltage_limits *max_limits,
3284 					  struct rv7xx_pl *pl)
3285 {
3286 
3287 	if ((pl->mclk == 0) || (pl->sclk == 0))
3288 		return;
3289 
3290 	if (pl->mclk == pl->sclk)
3291 		return;
3292 
3293 	if (pl->mclk > pl->sclk) {
3294 		if (((pl->mclk + (pl->sclk - 1)) / pl->sclk) > adev->pm.dpm.dyn_state.mclk_sclk_ratio)
3295 			pl->sclk = btc_get_valid_sclk(adev,
3296 						      max_limits->sclk,
3297 						      (pl->mclk +
3298 						      (adev->pm.dpm.dyn_state.mclk_sclk_ratio - 1)) /
3299 						      adev->pm.dpm.dyn_state.mclk_sclk_ratio);
3300 	} else {
3301 		if ((pl->sclk - pl->mclk) > adev->pm.dpm.dyn_state.sclk_mclk_delta)
3302 			pl->mclk = btc_get_valid_mclk(adev,
3303 						      max_limits->mclk,
3304 						      pl->sclk -
3305 						      adev->pm.dpm.dyn_state.sclk_mclk_delta);
3306 	}
3307 }
3308 
3309 static void btc_apply_voltage_delta_rules(struct amdgpu_device *adev,
3310 					  u16 max_vddc, u16 max_vddci,
3311 					  u16 *vddc, u16 *vddci)
3312 {
3313 	struct evergreen_power_info *eg_pi = evergreen_get_pi(adev);
3314 	u16 new_voltage;
3315 
3316 	if ((0 == *vddc) || (0 == *vddci))
3317 		return;
3318 
3319 	if (*vddc > *vddci) {
3320 		if ((*vddc - *vddci) > adev->pm.dpm.dyn_state.vddc_vddci_delta) {
3321 			new_voltage = btc_find_voltage(&eg_pi->vddci_voltage_table,
3322 						       (*vddc - adev->pm.dpm.dyn_state.vddc_vddci_delta));
3323 			*vddci = (new_voltage < max_vddci) ? new_voltage : max_vddci;
3324 		}
3325 	} else {
3326 		if ((*vddci - *vddc) > adev->pm.dpm.dyn_state.vddc_vddci_delta) {
3327 			new_voltage = btc_find_voltage(&eg_pi->vddc_voltage_table,
3328 						       (*vddci - adev->pm.dpm.dyn_state.vddc_vddci_delta));
3329 			*vddc = (new_voltage < max_vddc) ? new_voltage : max_vddc;
3330 		}
3331 	}
3332 }
3333 
3334 static void r600_calculate_u_and_p(u32 i, u32 r_c, u32 p_b,
3335 			    u32 *p, u32 *u)
3336 {
3337 	u32 b_c = 0;
3338 	u32 i_c;
3339 	u32 tmp;
3340 
3341 	i_c = (i * r_c) / 100;
3342 	tmp = i_c >> p_b;
3343 
3344 	while (tmp) {
3345 		b_c++;
3346 		tmp >>= 1;
3347 	}
3348 
3349 	*u = (b_c + 1) / 2;
3350 	*p = i_c / (1 << (2 * (*u)));
3351 }
3352 
3353 static int r600_calculate_at(u32 t, u32 h, u32 fh, u32 fl, u32 *tl, u32 *th)
3354 {
3355 	u32 k, a, ah, al;
3356 	u32 t1;
3357 
3358 	if ((fl == 0) || (fh == 0) || (fl > fh))
3359 		return -EINVAL;
3360 
3361 	k = (100 * fh) / fl;
3362 	t1 = (t * (k - 100));
3363 	a = (1000 * (100 * h + t1)) / (10000 + (t1 / 100));
3364 	a = (a + 5) / 10;
3365 	ah = ((a * t) + 5000) / 10000;
3366 	al = a - ah;
3367 
3368 	*th = t - ah;
3369 	*tl = t + al;
3370 
3371 	return 0;
3372 }
3373 
3374 static bool r600_is_uvd_state(u32 class, u32 class2)
3375 {
3376 	if (class & ATOM_PPLIB_CLASSIFICATION_UVDSTATE)
3377 		return true;
3378 	if (class & ATOM_PPLIB_CLASSIFICATION_HD2STATE)
3379 		return true;
3380 	if (class & ATOM_PPLIB_CLASSIFICATION_HDSTATE)
3381 		return true;
3382 	if (class & ATOM_PPLIB_CLASSIFICATION_SDSTATE)
3383 		return true;
3384 	if (class2 & ATOM_PPLIB_CLASSIFICATION2_MVC)
3385 		return true;
3386 	return false;
3387 }
3388 
3389 static u8 rv770_get_memory_module_index(struct amdgpu_device *adev)
3390 {
3391 	return (u8) ((RREG32(BIOS_SCRATCH_4) >> 16) & 0xff);
3392 }
3393 
3394 static void rv770_get_max_vddc(struct amdgpu_device *adev)
3395 {
3396 	struct rv7xx_power_info *pi = rv770_get_pi(adev);
3397 	u16 vddc;
3398 
3399 	if (amdgpu_atombios_get_max_vddc(adev, 0, 0, &vddc))
3400 		pi->max_vddc = 0;
3401 	else
3402 		pi->max_vddc = vddc;
3403 }
3404 
3405 static void rv770_get_engine_memory_ss(struct amdgpu_device *adev)
3406 {
3407 	struct rv7xx_power_info *pi = rv770_get_pi(adev);
3408 	struct amdgpu_atom_ss ss;
3409 
3410 	pi->sclk_ss = amdgpu_atombios_get_asic_ss_info(adev, &ss,
3411 						       ASIC_INTERNAL_ENGINE_SS, 0);
3412 	pi->mclk_ss = amdgpu_atombios_get_asic_ss_info(adev, &ss,
3413 						       ASIC_INTERNAL_MEMORY_SS, 0);
3414 
3415 	if (pi->sclk_ss || pi->mclk_ss)
3416 		pi->dynamic_ss = true;
3417 	else
3418 		pi->dynamic_ss = false;
3419 }
3420 
3421 
3422 static void si_apply_state_adjust_rules(struct amdgpu_device *adev,
3423 					struct amdgpu_ps *rps)
3424 {
3425 	struct  si_ps *ps = si_get_ps(rps);
3426 	struct amdgpu_clock_and_voltage_limits *max_limits;
3427 	bool disable_mclk_switching = false;
3428 	bool disable_sclk_switching = false;
3429 	u32 mclk, sclk;
3430 	u16 vddc, vddci, min_vce_voltage = 0;
3431 	u32 max_sclk_vddc, max_mclk_vddci, max_mclk_vddc;
3432 	u32 max_sclk = 0, max_mclk = 0;
3433 	int i;
3434 
3435 	if (adev->asic_type == CHIP_HAINAN) {
3436 		if ((adev->pdev->revision == 0x81) ||
3437 		    (adev->pdev->revision == 0xC3) ||
3438 		    (adev->pdev->device == 0x6664) ||
3439 		    (adev->pdev->device == 0x6665) ||
3440 		    (adev->pdev->device == 0x6667)) {
3441 			max_sclk = 75000;
3442 		}
3443 		if ((adev->pdev->revision == 0xC3) ||
3444 		    (adev->pdev->device == 0x6665)) {
3445 			max_sclk = 60000;
3446 			max_mclk = 80000;
3447 		}
3448 	} else if (adev->asic_type == CHIP_OLAND) {
3449 		if ((adev->pdev->revision == 0xC7) ||
3450 		    (adev->pdev->revision == 0x80) ||
3451 		    (adev->pdev->revision == 0x81) ||
3452 		    (adev->pdev->revision == 0x83) ||
3453 		    (adev->pdev->revision == 0x87) ||
3454 		    (adev->pdev->device == 0x6604) ||
3455 		    (adev->pdev->device == 0x6605)) {
3456 			max_sclk = 75000;
3457 		}
3458 	}
3459 
3460 	if (rps->vce_active) {
3461 		rps->evclk = adev->pm.dpm.vce_states[adev->pm.dpm.vce_level].evclk;
3462 		rps->ecclk = adev->pm.dpm.vce_states[adev->pm.dpm.vce_level].ecclk;
3463 		si_get_vce_clock_voltage(adev, rps->evclk, rps->ecclk,
3464 					 &min_vce_voltage);
3465 	} else {
3466 		rps->evclk = 0;
3467 		rps->ecclk = 0;
3468 	}
3469 
3470 	if ((adev->pm.dpm.new_active_crtc_count > 1) ||
3471 	    si_dpm_vblank_too_short(adev))
3472 		disable_mclk_switching = true;
3473 
3474 	if (rps->vclk || rps->dclk) {
3475 		disable_mclk_switching = true;
3476 		disable_sclk_switching = true;
3477 	}
3478 
3479 	if (adev->pm.ac_power)
3480 		max_limits = &adev->pm.dpm.dyn_state.max_clock_voltage_on_ac;
3481 	else
3482 		max_limits = &adev->pm.dpm.dyn_state.max_clock_voltage_on_dc;
3483 
3484 	for (i = ps->performance_level_count - 2; i >= 0; i--) {
3485 		if (ps->performance_levels[i].vddc > ps->performance_levels[i+1].vddc)
3486 			ps->performance_levels[i].vddc = ps->performance_levels[i+1].vddc;
3487 	}
3488 	if (adev->pm.ac_power == false) {
3489 		for (i = 0; i < ps->performance_level_count; i++) {
3490 			if (ps->performance_levels[i].mclk > max_limits->mclk)
3491 				ps->performance_levels[i].mclk = max_limits->mclk;
3492 			if (ps->performance_levels[i].sclk > max_limits->sclk)
3493 				ps->performance_levels[i].sclk = max_limits->sclk;
3494 			if (ps->performance_levels[i].vddc > max_limits->vddc)
3495 				ps->performance_levels[i].vddc = max_limits->vddc;
3496 			if (ps->performance_levels[i].vddci > max_limits->vddci)
3497 				ps->performance_levels[i].vddci = max_limits->vddci;
3498 		}
3499 	}
3500 
3501 	/* limit clocks to max supported clocks based on voltage dependency tables */
3502 	btc_get_max_clock_from_voltage_dependency_table(&adev->pm.dpm.dyn_state.vddc_dependency_on_sclk,
3503 							&max_sclk_vddc);
3504 	btc_get_max_clock_from_voltage_dependency_table(&adev->pm.dpm.dyn_state.vddci_dependency_on_mclk,
3505 							&max_mclk_vddci);
3506 	btc_get_max_clock_from_voltage_dependency_table(&adev->pm.dpm.dyn_state.vddc_dependency_on_mclk,
3507 							&max_mclk_vddc);
3508 
3509 	for (i = 0; i < ps->performance_level_count; i++) {
3510 		if (max_sclk_vddc) {
3511 			if (ps->performance_levels[i].sclk > max_sclk_vddc)
3512 				ps->performance_levels[i].sclk = max_sclk_vddc;
3513 		}
3514 		if (max_mclk_vddci) {
3515 			if (ps->performance_levels[i].mclk > max_mclk_vddci)
3516 				ps->performance_levels[i].mclk = max_mclk_vddci;
3517 		}
3518 		if (max_mclk_vddc) {
3519 			if (ps->performance_levels[i].mclk > max_mclk_vddc)
3520 				ps->performance_levels[i].mclk = max_mclk_vddc;
3521 		}
3522 		if (max_mclk) {
3523 			if (ps->performance_levels[i].mclk > max_mclk)
3524 				ps->performance_levels[i].mclk = max_mclk;
3525 		}
3526 		if (max_sclk) {
3527 			if (ps->performance_levels[i].sclk > max_sclk)
3528 				ps->performance_levels[i].sclk = max_sclk;
3529 		}
3530 	}
3531 
3532 	/* XXX validate the min clocks required for display */
3533 
3534 	if (disable_mclk_switching) {
3535 		mclk  = ps->performance_levels[ps->performance_level_count - 1].mclk;
3536 		vddci = ps->performance_levels[ps->performance_level_count - 1].vddci;
3537 	} else {
3538 		mclk = ps->performance_levels[0].mclk;
3539 		vddci = ps->performance_levels[0].vddci;
3540 	}
3541 
3542 	if (disable_sclk_switching) {
3543 		sclk = ps->performance_levels[ps->performance_level_count - 1].sclk;
3544 		vddc = ps->performance_levels[ps->performance_level_count - 1].vddc;
3545 	} else {
3546 		sclk = ps->performance_levels[0].sclk;
3547 		vddc = ps->performance_levels[0].vddc;
3548 	}
3549 
3550 	if (rps->vce_active) {
3551 		if (sclk < adev->pm.dpm.vce_states[adev->pm.dpm.vce_level].sclk)
3552 			sclk = adev->pm.dpm.vce_states[adev->pm.dpm.vce_level].sclk;
3553 		if (mclk < adev->pm.dpm.vce_states[adev->pm.dpm.vce_level].mclk)
3554 			mclk = adev->pm.dpm.vce_states[adev->pm.dpm.vce_level].mclk;
3555 	}
3556 
3557 	/* adjusted low state */
3558 	ps->performance_levels[0].sclk = sclk;
3559 	ps->performance_levels[0].mclk = mclk;
3560 	ps->performance_levels[0].vddc = vddc;
3561 	ps->performance_levels[0].vddci = vddci;
3562 
3563 	if (disable_sclk_switching) {
3564 		sclk = ps->performance_levels[0].sclk;
3565 		for (i = 1; i < ps->performance_level_count; i++) {
3566 			if (sclk < ps->performance_levels[i].sclk)
3567 				sclk = ps->performance_levels[i].sclk;
3568 		}
3569 		for (i = 0; i < ps->performance_level_count; i++) {
3570 			ps->performance_levels[i].sclk = sclk;
3571 			ps->performance_levels[i].vddc = vddc;
3572 		}
3573 	} else {
3574 		for (i = 1; i < ps->performance_level_count; i++) {
3575 			if (ps->performance_levels[i].sclk < ps->performance_levels[i - 1].sclk)
3576 				ps->performance_levels[i].sclk = ps->performance_levels[i - 1].sclk;
3577 			if (ps->performance_levels[i].vddc < ps->performance_levels[i - 1].vddc)
3578 				ps->performance_levels[i].vddc = ps->performance_levels[i - 1].vddc;
3579 		}
3580 	}
3581 
3582 	if (disable_mclk_switching) {
3583 		mclk = ps->performance_levels[0].mclk;
3584 		for (i = 1; i < ps->performance_level_count; i++) {
3585 			if (mclk < ps->performance_levels[i].mclk)
3586 				mclk = ps->performance_levels[i].mclk;
3587 		}
3588 		for (i = 0; i < ps->performance_level_count; i++) {
3589 			ps->performance_levels[i].mclk = mclk;
3590 			ps->performance_levels[i].vddci = vddci;
3591 		}
3592 	} else {
3593 		for (i = 1; i < ps->performance_level_count; i++) {
3594 			if (ps->performance_levels[i].mclk < ps->performance_levels[i - 1].mclk)
3595 				ps->performance_levels[i].mclk = ps->performance_levels[i - 1].mclk;
3596 			if (ps->performance_levels[i].vddci < ps->performance_levels[i - 1].vddci)
3597 				ps->performance_levels[i].vddci = ps->performance_levels[i - 1].vddci;
3598 		}
3599 	}
3600 
3601 	for (i = 0; i < ps->performance_level_count; i++)
3602 		btc_adjust_clock_combinations(adev, max_limits,
3603 					      &ps->performance_levels[i]);
3604 
3605 	for (i = 0; i < ps->performance_level_count; i++) {
3606 		if (ps->performance_levels[i].vddc < min_vce_voltage)
3607 			ps->performance_levels[i].vddc = min_vce_voltage;
3608 		btc_apply_voltage_dependency_rules(&adev->pm.dpm.dyn_state.vddc_dependency_on_sclk,
3609 						   ps->performance_levels[i].sclk,
3610 						   max_limits->vddc,  &ps->performance_levels[i].vddc);
3611 		btc_apply_voltage_dependency_rules(&adev->pm.dpm.dyn_state.vddci_dependency_on_mclk,
3612 						   ps->performance_levels[i].mclk,
3613 						   max_limits->vddci, &ps->performance_levels[i].vddci);
3614 		btc_apply_voltage_dependency_rules(&adev->pm.dpm.dyn_state.vddc_dependency_on_mclk,
3615 						   ps->performance_levels[i].mclk,
3616 						   max_limits->vddc,  &ps->performance_levels[i].vddc);
3617 		btc_apply_voltage_dependency_rules(&adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk,
3618 						   adev->clock.current_dispclk,
3619 						   max_limits->vddc,  &ps->performance_levels[i].vddc);
3620 	}
3621 
3622 	for (i = 0; i < ps->performance_level_count; i++) {
3623 		btc_apply_voltage_delta_rules(adev,
3624 					      max_limits->vddc, max_limits->vddci,
3625 					      &ps->performance_levels[i].vddc,
3626 					      &ps->performance_levels[i].vddci);
3627 	}
3628 
3629 	ps->dc_compatible = true;
3630 	for (i = 0; i < ps->performance_level_count; i++) {
3631 		if (ps->performance_levels[i].vddc > adev->pm.dpm.dyn_state.max_clock_voltage_on_dc.vddc)
3632 			ps->dc_compatible = false;
3633 	}
3634 }
3635 
3636 #if 0
3637 static int si_read_smc_soft_register(struct amdgpu_device *adev,
3638 				     u16 reg_offset, u32 *value)
3639 {
3640 	struct si_power_info *si_pi = si_get_pi(adev);
3641 
3642 	return amdgpu_si_read_smc_sram_dword(adev,
3643 					     si_pi->soft_regs_start + reg_offset, value,
3644 					     si_pi->sram_end);
3645 }
3646 #endif
3647 
3648 static int si_write_smc_soft_register(struct amdgpu_device *adev,
3649 				      u16 reg_offset, u32 value)
3650 {
3651 	struct si_power_info *si_pi = si_get_pi(adev);
3652 
3653 	return amdgpu_si_write_smc_sram_dword(adev,
3654 					      si_pi->soft_regs_start + reg_offset,
3655 					      value, si_pi->sram_end);
3656 }
3657 
3658 static bool si_is_special_1gb_platform(struct amdgpu_device *adev)
3659 {
3660 	bool ret = false;
3661 	u32 tmp, width, row, column, bank, density;
3662 	bool is_memory_gddr5, is_special;
3663 
3664 	tmp = RREG32(MC_SEQ_MISC0);
3665 	is_memory_gddr5 = (MC_SEQ_MISC0_GDDR5_VALUE == ((tmp & MC_SEQ_MISC0_GDDR5_MASK) >> MC_SEQ_MISC0_GDDR5_SHIFT));
3666 	is_special = (MC_SEQ_MISC0_REV_ID_VALUE == ((tmp & MC_SEQ_MISC0_REV_ID_MASK) >> MC_SEQ_MISC0_REV_ID_SHIFT))
3667 		& (MC_SEQ_MISC0_VEN_ID_VALUE == ((tmp & MC_SEQ_MISC0_VEN_ID_MASK) >> MC_SEQ_MISC0_VEN_ID_SHIFT));
3668 
3669 	WREG32(MC_SEQ_IO_DEBUG_INDEX, 0xb);
3670 	width = ((RREG32(MC_SEQ_IO_DEBUG_DATA) >> 1) & 1) ? 16 : 32;
3671 
3672 	tmp = RREG32(MC_ARB_RAMCFG);
3673 	row = ((tmp & NOOFROWS_MASK) >> NOOFROWS_SHIFT) + 10;
3674 	column = ((tmp & NOOFCOLS_MASK) >> NOOFCOLS_SHIFT) + 8;
3675 	bank = ((tmp & NOOFBANK_MASK) >> NOOFBANK_SHIFT) + 2;
3676 
3677 	density = (1 << (row + column - 20 + bank)) * width;
3678 
3679 	if ((adev->pdev->device == 0x6819) &&
3680 	    is_memory_gddr5 && is_special && (density == 0x400))
3681 		ret = true;
3682 
3683 	return ret;
3684 }
3685 
3686 static void si_get_leakage_vddc(struct amdgpu_device *adev)
3687 {
3688 	struct si_power_info *si_pi = si_get_pi(adev);
3689 	u16 vddc, count = 0;
3690 	int i, ret;
3691 
3692 	for (i = 0; i < SISLANDS_MAX_LEAKAGE_COUNT; i++) {
3693 		ret = amdgpu_atombios_get_leakage_vddc_based_on_leakage_idx(adev, &vddc, SISLANDS_LEAKAGE_INDEX0 + i);
3694 
3695 		if (!ret && (vddc > 0) && (vddc != (SISLANDS_LEAKAGE_INDEX0 + i))) {
3696 			si_pi->leakage_voltage.entries[count].voltage = vddc;
3697 			si_pi->leakage_voltage.entries[count].leakage_index =
3698 				SISLANDS_LEAKAGE_INDEX0 + i;
3699 			count++;
3700 		}
3701 	}
3702 	si_pi->leakage_voltage.count = count;
3703 }
3704 
3705 static int si_get_leakage_voltage_from_leakage_index(struct amdgpu_device *adev,
3706 						     u32 index, u16 *leakage_voltage)
3707 {
3708 	struct si_power_info *si_pi = si_get_pi(adev);
3709 	int i;
3710 
3711 	if (leakage_voltage == NULL)
3712 		return -EINVAL;
3713 
3714 	if ((index & 0xff00) != 0xff00)
3715 		return -EINVAL;
3716 
3717 	if ((index & 0xff) > SISLANDS_MAX_LEAKAGE_COUNT + 1)
3718 		return -EINVAL;
3719 
3720 	if (index < SISLANDS_LEAKAGE_INDEX0)
3721 		return -EINVAL;
3722 
3723 	for (i = 0; i < si_pi->leakage_voltage.count; i++) {
3724 		if (si_pi->leakage_voltage.entries[i].leakage_index == index) {
3725 			*leakage_voltage = si_pi->leakage_voltage.entries[i].voltage;
3726 			return 0;
3727 		}
3728 	}
3729 	return -EAGAIN;
3730 }
3731 
3732 static void si_set_dpm_event_sources(struct amdgpu_device *adev, u32 sources)
3733 {
3734 	struct rv7xx_power_info *pi = rv770_get_pi(adev);
3735 	bool want_thermal_protection;
3736 	enum si_dpm_event_src dpm_event_src;
3737 
3738 	switch (sources) {
3739 	case 0:
3740 	default:
3741 		want_thermal_protection = false;
3742 		break;
3743 	case (1 << SI_DPM_AUTO_THROTTLE_SRC_THERMAL):
3744 		want_thermal_protection = true;
3745 		dpm_event_src = SI_DPM_EVENT_SRC_DIGITAL;
3746 		break;
3747 	case (1 << SI_DPM_AUTO_THROTTLE_SRC_EXTERNAL):
3748 		want_thermal_protection = true;
3749 		dpm_event_src = SI_DPM_EVENT_SRC_EXTERNAL;
3750 		break;
3751 	case ((1 << SI_DPM_AUTO_THROTTLE_SRC_EXTERNAL) |
3752 	      (1 << SI_DPM_AUTO_THROTTLE_SRC_THERMAL)):
3753 		want_thermal_protection = true;
3754 		dpm_event_src = SI_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL;
3755 		break;
3756 	}
3757 
3758 	if (want_thermal_protection) {
3759 		WREG32_P(CG_THERMAL_CTRL, DPM_EVENT_SRC(dpm_event_src), ~DPM_EVENT_SRC_MASK);
3760 		if (pi->thermal_protection)
3761 			WREG32_P(GENERAL_PWRMGT, 0, ~THERMAL_PROTECTION_DIS);
3762 	} else {
3763 		WREG32_P(GENERAL_PWRMGT, THERMAL_PROTECTION_DIS, ~THERMAL_PROTECTION_DIS);
3764 	}
3765 }
3766 
3767 static void si_enable_auto_throttle_source(struct amdgpu_device *adev,
3768 					   enum si_dpm_auto_throttle_src source,
3769 					   bool enable)
3770 {
3771 	struct rv7xx_power_info *pi = rv770_get_pi(adev);
3772 
3773 	if (enable) {
3774 		if (!(pi->active_auto_throttle_sources & (1 << source))) {
3775 			pi->active_auto_throttle_sources |= 1 << source;
3776 			si_set_dpm_event_sources(adev, pi->active_auto_throttle_sources);
3777 		}
3778 	} else {
3779 		if (pi->active_auto_throttle_sources & (1 << source)) {
3780 			pi->active_auto_throttle_sources &= ~(1 << source);
3781 			si_set_dpm_event_sources(adev, pi->active_auto_throttle_sources);
3782 		}
3783 	}
3784 }
3785 
3786 static void si_start_dpm(struct amdgpu_device *adev)
3787 {
3788 	WREG32_P(GENERAL_PWRMGT, GLOBAL_PWRMGT_EN, ~GLOBAL_PWRMGT_EN);
3789 }
3790 
3791 static void si_stop_dpm(struct amdgpu_device *adev)
3792 {
3793 	WREG32_P(GENERAL_PWRMGT, 0, ~GLOBAL_PWRMGT_EN);
3794 }
3795 
3796 static void si_enable_sclk_control(struct amdgpu_device *adev, bool enable)
3797 {
3798 	if (enable)
3799 		WREG32_P(SCLK_PWRMGT_CNTL, 0, ~SCLK_PWRMGT_OFF);
3800 	else
3801 		WREG32_P(SCLK_PWRMGT_CNTL, SCLK_PWRMGT_OFF, ~SCLK_PWRMGT_OFF);
3802 
3803 }
3804 
3805 #if 0
3806 static int si_notify_hardware_of_thermal_state(struct amdgpu_device *adev,
3807 					       u32 thermal_level)
3808 {
3809 	PPSMC_Result ret;
3810 
3811 	if (thermal_level == 0) {
3812 		ret = amdgpu_si_send_msg_to_smc(adev, PPSMC_MSG_EnableThermalInterrupt);
3813 		if (ret == PPSMC_Result_OK)
3814 			return 0;
3815 		else
3816 			return -EINVAL;
3817 	}
3818 	return 0;
3819 }
3820 
3821 static void si_notify_hardware_vpu_recovery_event(struct amdgpu_device *adev)
3822 {
3823 	si_write_smc_soft_register(adev, SI_SMC_SOFT_REGISTER_tdr_is_about_to_happen, true);
3824 }
3825 #endif
3826 
3827 #if 0
3828 static int si_notify_hw_of_powersource(struct amdgpu_device *adev, bool ac_power)
3829 {
3830 	if (ac_power)
3831 		return (amdgpu_si_send_msg_to_smc(adev, PPSMC_MSG_RunningOnAC) == PPSMC_Result_OK) ?
3832 			0 : -EINVAL;
3833 
3834 	return 0;
3835 }
3836 #endif
3837 
3838 static PPSMC_Result si_send_msg_to_smc_with_parameter(struct amdgpu_device *adev,
3839 						      PPSMC_Msg msg, u32 parameter)
3840 {
3841 	WREG32(SMC_SCRATCH0, parameter);
3842 	return amdgpu_si_send_msg_to_smc(adev, msg);
3843 }
3844 
3845 static int si_restrict_performance_levels_before_switch(struct amdgpu_device *adev)
3846 {
3847 	if (amdgpu_si_send_msg_to_smc(adev, PPSMC_MSG_NoForcedLevel) != PPSMC_Result_OK)
3848 		return -EINVAL;
3849 
3850 	return (si_send_msg_to_smc_with_parameter(adev, PPSMC_MSG_SetEnabledLevels, 1) == PPSMC_Result_OK) ?
3851 		0 : -EINVAL;
3852 }
3853 
3854 static int si_dpm_force_performance_level(void *handle,
3855 				   enum amd_dpm_forced_level level)
3856 {
3857 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
3858 	struct amdgpu_ps *rps = adev->pm.dpm.current_ps;
3859 	struct  si_ps *ps = si_get_ps(rps);
3860 	u32 levels = ps->performance_level_count;
3861 
3862 	if (level == AMD_DPM_FORCED_LEVEL_HIGH) {
3863 		if (si_send_msg_to_smc_with_parameter(adev, PPSMC_MSG_SetEnabledLevels, levels) != PPSMC_Result_OK)
3864 			return -EINVAL;
3865 
3866 		if (si_send_msg_to_smc_with_parameter(adev, PPSMC_MSG_SetForcedLevels, 1) != PPSMC_Result_OK)
3867 			return -EINVAL;
3868 	} else if (level == AMD_DPM_FORCED_LEVEL_LOW) {
3869 		if (si_send_msg_to_smc_with_parameter(adev, PPSMC_MSG_SetForcedLevels, 0) != PPSMC_Result_OK)
3870 			return -EINVAL;
3871 
3872 		if (si_send_msg_to_smc_with_parameter(adev, PPSMC_MSG_SetEnabledLevels, 1) != PPSMC_Result_OK)
3873 			return -EINVAL;
3874 	} else if (level == AMD_DPM_FORCED_LEVEL_AUTO) {
3875 		if (si_send_msg_to_smc_with_parameter(adev, PPSMC_MSG_SetForcedLevels, 0) != PPSMC_Result_OK)
3876 			return -EINVAL;
3877 
3878 		if (si_send_msg_to_smc_with_parameter(adev, PPSMC_MSG_SetEnabledLevels, levels) != PPSMC_Result_OK)
3879 			return -EINVAL;
3880 	}
3881 
3882 	adev->pm.dpm.forced_level = level;
3883 
3884 	return 0;
3885 }
3886 
3887 #if 0
3888 static int si_set_boot_state(struct amdgpu_device *adev)
3889 {
3890 	return (amdgpu_si_send_msg_to_smc(adev, PPSMC_MSG_SwitchToInitialState) == PPSMC_Result_OK) ?
3891 		0 : -EINVAL;
3892 }
3893 #endif
3894 
3895 static int si_set_powergating_by_smu(void *handle,
3896 				     uint32_t block_type,
3897 				     bool gate)
3898 {
3899 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
3900 
3901 	switch (block_type) {
3902 	case AMD_IP_BLOCK_TYPE_UVD:
3903 		if (!gate) {
3904 			adev->pm.dpm.uvd_active = true;
3905 			adev->pm.dpm.state = POWER_STATE_TYPE_INTERNAL_UVD;
3906 		} else {
3907 			adev->pm.dpm.uvd_active = false;
3908 		}
3909 
3910 		amdgpu_legacy_dpm_compute_clocks(handle);
3911 		break;
3912 	case AMD_IP_BLOCK_TYPE_VCE:
3913 		if (!gate) {
3914 			adev->pm.dpm.vce_active = true;
3915 			/* XXX select vce level based on ring/task */
3916 			adev->pm.dpm.vce_level = AMD_VCE_LEVEL_AC_ALL;
3917 		} else {
3918 			adev->pm.dpm.vce_active = false;
3919 		}
3920 
3921 		amdgpu_legacy_dpm_compute_clocks(handle);
3922 		break;
3923 	default:
3924 		break;
3925 	}
3926 	return 0;
3927 }
3928 
3929 static int si_set_sw_state(struct amdgpu_device *adev)
3930 {
3931 	return (amdgpu_si_send_msg_to_smc(adev, PPSMC_MSG_SwitchToSwState) == PPSMC_Result_OK) ?
3932 		0 : -EINVAL;
3933 }
3934 
3935 static int si_halt_smc(struct amdgpu_device *adev)
3936 {
3937 	if (amdgpu_si_send_msg_to_smc(adev, PPSMC_MSG_Halt) != PPSMC_Result_OK)
3938 		return -EINVAL;
3939 
3940 	return (amdgpu_si_wait_for_smc_inactive(adev) == PPSMC_Result_OK) ?
3941 		0 : -EINVAL;
3942 }
3943 
3944 static int si_resume_smc(struct amdgpu_device *adev)
3945 {
3946 	if (amdgpu_si_send_msg_to_smc(adev, PPSMC_FlushDataCache) != PPSMC_Result_OK)
3947 		return -EINVAL;
3948 
3949 	return (amdgpu_si_send_msg_to_smc(adev, PPSMC_MSG_Resume) == PPSMC_Result_OK) ?
3950 		0 : -EINVAL;
3951 }
3952 
3953 static void si_dpm_start_smc(struct amdgpu_device *adev)
3954 {
3955 	amdgpu_si_program_jump_on_start(adev);
3956 	amdgpu_si_start_smc(adev);
3957 	amdgpu_si_smc_clock(adev, true);
3958 }
3959 
3960 static void si_dpm_stop_smc(struct amdgpu_device *adev)
3961 {
3962 	amdgpu_si_reset_smc(adev);
3963 	amdgpu_si_smc_clock(adev, false);
3964 }
3965 
3966 static int si_process_firmware_header(struct amdgpu_device *adev)
3967 {
3968 	struct si_power_info *si_pi = si_get_pi(adev);
3969 	u32 tmp;
3970 	int ret;
3971 
3972 	ret = amdgpu_si_read_smc_sram_dword(adev,
3973 					    SISLANDS_SMC_FIRMWARE_HEADER_LOCATION +
3974 					    SISLANDS_SMC_FIRMWARE_HEADER_stateTable,
3975 					    &tmp, si_pi->sram_end);
3976 	if (ret)
3977 		return ret;
3978 
3979 	si_pi->state_table_start = tmp;
3980 
3981 	ret = amdgpu_si_read_smc_sram_dword(adev,
3982 					    SISLANDS_SMC_FIRMWARE_HEADER_LOCATION +
3983 					    SISLANDS_SMC_FIRMWARE_HEADER_softRegisters,
3984 					    &tmp, si_pi->sram_end);
3985 	if (ret)
3986 		return ret;
3987 
3988 	si_pi->soft_regs_start = tmp;
3989 
3990 	ret = amdgpu_si_read_smc_sram_dword(adev,
3991 					    SISLANDS_SMC_FIRMWARE_HEADER_LOCATION +
3992 					    SISLANDS_SMC_FIRMWARE_HEADER_mcRegisterTable,
3993 					    &tmp, si_pi->sram_end);
3994 	if (ret)
3995 		return ret;
3996 
3997 	si_pi->mc_reg_table_start = tmp;
3998 
3999 	ret = amdgpu_si_read_smc_sram_dword(adev,
4000 					    SISLANDS_SMC_FIRMWARE_HEADER_LOCATION +
4001 					    SISLANDS_SMC_FIRMWARE_HEADER_fanTable,
4002 					    &tmp, si_pi->sram_end);
4003 	if (ret)
4004 		return ret;
4005 
4006 	si_pi->fan_table_start = tmp;
4007 
4008 	ret = amdgpu_si_read_smc_sram_dword(adev,
4009 					    SISLANDS_SMC_FIRMWARE_HEADER_LOCATION +
4010 					    SISLANDS_SMC_FIRMWARE_HEADER_mcArbDramAutoRefreshTable,
4011 					    &tmp, si_pi->sram_end);
4012 	if (ret)
4013 		return ret;
4014 
4015 	si_pi->arb_table_start = tmp;
4016 
4017 	ret = amdgpu_si_read_smc_sram_dword(adev,
4018 					    SISLANDS_SMC_FIRMWARE_HEADER_LOCATION +
4019 					    SISLANDS_SMC_FIRMWARE_HEADER_CacConfigTable,
4020 					    &tmp, si_pi->sram_end);
4021 	if (ret)
4022 		return ret;
4023 
4024 	si_pi->cac_table_start = tmp;
4025 
4026 	ret = amdgpu_si_read_smc_sram_dword(adev,
4027 					    SISLANDS_SMC_FIRMWARE_HEADER_LOCATION +
4028 					    SISLANDS_SMC_FIRMWARE_HEADER_DteConfiguration,
4029 					    &tmp, si_pi->sram_end);
4030 	if (ret)
4031 		return ret;
4032 
4033 	si_pi->dte_table_start = tmp;
4034 
4035 	ret = amdgpu_si_read_smc_sram_dword(adev,
4036 					    SISLANDS_SMC_FIRMWARE_HEADER_LOCATION +
4037 					    SISLANDS_SMC_FIRMWARE_HEADER_spllTable,
4038 					    &tmp, si_pi->sram_end);
4039 	if (ret)
4040 		return ret;
4041 
4042 	si_pi->spll_table_start = tmp;
4043 
4044 	ret = amdgpu_si_read_smc_sram_dword(adev,
4045 					    SISLANDS_SMC_FIRMWARE_HEADER_LOCATION +
4046 					    SISLANDS_SMC_FIRMWARE_HEADER_PAPMParameters,
4047 					    &tmp, si_pi->sram_end);
4048 	if (ret)
4049 		return ret;
4050 
4051 	si_pi->papm_cfg_table_start = tmp;
4052 
4053 	return ret;
4054 }
4055 
4056 static void si_read_clock_registers(struct amdgpu_device *adev)
4057 {
4058 	struct si_power_info *si_pi = si_get_pi(adev);
4059 
4060 	si_pi->clock_registers.cg_spll_func_cntl = RREG32(CG_SPLL_FUNC_CNTL);
4061 	si_pi->clock_registers.cg_spll_func_cntl_2 = RREG32(CG_SPLL_FUNC_CNTL_2);
4062 	si_pi->clock_registers.cg_spll_func_cntl_3 = RREG32(CG_SPLL_FUNC_CNTL_3);
4063 	si_pi->clock_registers.cg_spll_func_cntl_4 = RREG32(CG_SPLL_FUNC_CNTL_4);
4064 	si_pi->clock_registers.cg_spll_spread_spectrum = RREG32(CG_SPLL_SPREAD_SPECTRUM);
4065 	si_pi->clock_registers.cg_spll_spread_spectrum_2 = RREG32(CG_SPLL_SPREAD_SPECTRUM_2);
4066 	si_pi->clock_registers.dll_cntl = RREG32(DLL_CNTL);
4067 	si_pi->clock_registers.mclk_pwrmgt_cntl = RREG32(MCLK_PWRMGT_CNTL);
4068 	si_pi->clock_registers.mpll_ad_func_cntl = RREG32(MPLL_AD_FUNC_CNTL);
4069 	si_pi->clock_registers.mpll_dq_func_cntl = RREG32(MPLL_DQ_FUNC_CNTL);
4070 	si_pi->clock_registers.mpll_func_cntl = RREG32(MPLL_FUNC_CNTL);
4071 	si_pi->clock_registers.mpll_func_cntl_1 = RREG32(MPLL_FUNC_CNTL_1);
4072 	si_pi->clock_registers.mpll_func_cntl_2 = RREG32(MPLL_FUNC_CNTL_2);
4073 	si_pi->clock_registers.mpll_ss1 = RREG32(MPLL_SS1);
4074 	si_pi->clock_registers.mpll_ss2 = RREG32(MPLL_SS2);
4075 }
4076 
4077 static void si_enable_thermal_protection(struct amdgpu_device *adev,
4078 					  bool enable)
4079 {
4080 	if (enable)
4081 		WREG32_P(GENERAL_PWRMGT, 0, ~THERMAL_PROTECTION_DIS);
4082 	else
4083 		WREG32_P(GENERAL_PWRMGT, THERMAL_PROTECTION_DIS, ~THERMAL_PROTECTION_DIS);
4084 }
4085 
4086 static void si_enable_acpi_power_management(struct amdgpu_device *adev)
4087 {
4088 	WREG32_P(GENERAL_PWRMGT, STATIC_PM_EN, ~STATIC_PM_EN);
4089 }
4090 
4091 #if 0
4092 static int si_enter_ulp_state(struct amdgpu_device *adev)
4093 {
4094 	WREG32(SMC_MESSAGE_0, PPSMC_MSG_SwitchToMinimumPower);
4095 
4096 	udelay(25000);
4097 
4098 	return 0;
4099 }
4100 
4101 static int si_exit_ulp_state(struct amdgpu_device *adev)
4102 {
4103 	int i;
4104 
4105 	WREG32(SMC_MESSAGE_0, PPSMC_MSG_ResumeFromMinimumPower);
4106 
4107 	udelay(7000);
4108 
4109 	for (i = 0; i < adev->usec_timeout; i++) {
4110 		if (RREG32(SMC_RESP_0) == 1)
4111 			break;
4112 		udelay(1000);
4113 	}
4114 
4115 	return 0;
4116 }
4117 #endif
4118 
4119 static int si_notify_smc_display_change(struct amdgpu_device *adev,
4120 				     bool has_display)
4121 {
4122 	PPSMC_Msg msg = has_display ?
4123 		PPSMC_MSG_HasDisplay : PPSMC_MSG_NoDisplay;
4124 
4125 	return (amdgpu_si_send_msg_to_smc(adev, msg) == PPSMC_Result_OK) ?
4126 		0 : -EINVAL;
4127 }
4128 
4129 static void si_program_response_times(struct amdgpu_device *adev)
4130 {
4131 	u32 voltage_response_time, acpi_delay_time, vbi_time_out;
4132 	u32 vddc_dly, acpi_dly, vbi_dly;
4133 	u32 reference_clock;
4134 
4135 	si_write_smc_soft_register(adev, SI_SMC_SOFT_REGISTER_mvdd_chg_time, 1);
4136 
4137 	voltage_response_time = (u32)adev->pm.dpm.voltage_response_time;
4138 
4139 	if (voltage_response_time == 0)
4140 		voltage_response_time = 1000;
4141 
4142 	acpi_delay_time = 15000;
4143 	vbi_time_out = 100000;
4144 
4145 	reference_clock = amdgpu_asic_get_xclk(adev);
4146 
4147 	vddc_dly = (voltage_response_time  * reference_clock) / 100;
4148 	acpi_dly = (acpi_delay_time * reference_clock) / 100;
4149 	vbi_dly  = (vbi_time_out * reference_clock) / 100;
4150 
4151 	si_write_smc_soft_register(adev, SI_SMC_SOFT_REGISTER_delay_vreg,  vddc_dly);
4152 	si_write_smc_soft_register(adev, SI_SMC_SOFT_REGISTER_delay_acpi,  acpi_dly);
4153 	si_write_smc_soft_register(adev, SI_SMC_SOFT_REGISTER_mclk_chg_timeout, vbi_dly);
4154 	si_write_smc_soft_register(adev, SI_SMC_SOFT_REGISTER_mc_block_delay, 0xAA);
4155 }
4156 
4157 static void si_program_ds_registers(struct amdgpu_device *adev)
4158 {
4159 	struct evergreen_power_info *eg_pi = evergreen_get_pi(adev);
4160 	u32 tmp;
4161 
4162 	/* DEEP_SLEEP_CLK_SEL field should be 0x10 on tahiti A0 */
4163 	if (adev->asic_type == CHIP_TAHITI && adev->rev_id == 0x0)
4164 		tmp = 0x10;
4165 	else
4166 		tmp = 0x1;
4167 
4168 	if (eg_pi->sclk_deep_sleep) {
4169 		WREG32_P(MISC_CLK_CNTL, DEEP_SLEEP_CLK_SEL(tmp), ~DEEP_SLEEP_CLK_SEL_MASK);
4170 		WREG32_P(CG_SPLL_AUTOSCALE_CNTL, AUTOSCALE_ON_SS_CLEAR,
4171 			 ~AUTOSCALE_ON_SS_CLEAR);
4172 	}
4173 }
4174 
4175 static void si_program_display_gap(struct amdgpu_device *adev)
4176 {
4177 	u32 tmp, pipe;
4178 	int i;
4179 
4180 	tmp = RREG32(CG_DISPLAY_GAP_CNTL) & ~(DISP1_GAP_MASK | DISP2_GAP_MASK);
4181 	if (adev->pm.dpm.new_active_crtc_count > 0)
4182 		tmp |= DISP1_GAP(R600_PM_DISPLAY_GAP_VBLANK_OR_WM);
4183 	else
4184 		tmp |= DISP1_GAP(R600_PM_DISPLAY_GAP_IGNORE);
4185 
4186 	if (adev->pm.dpm.new_active_crtc_count > 1)
4187 		tmp |= DISP2_GAP(R600_PM_DISPLAY_GAP_VBLANK_OR_WM);
4188 	else
4189 		tmp |= DISP2_GAP(R600_PM_DISPLAY_GAP_IGNORE);
4190 
4191 	WREG32(CG_DISPLAY_GAP_CNTL, tmp);
4192 
4193 	tmp = RREG32(DCCG_DISP_SLOW_SELECT_REG);
4194 	pipe = (tmp & DCCG_DISP1_SLOW_SELECT_MASK) >> DCCG_DISP1_SLOW_SELECT_SHIFT;
4195 
4196 	if ((adev->pm.dpm.new_active_crtc_count > 0) &&
4197 	    (!(adev->pm.dpm.new_active_crtcs & (1 << pipe)))) {
4198 		/* find the first active crtc */
4199 		for (i = 0; i < adev->mode_info.num_crtc; i++) {
4200 			if (adev->pm.dpm.new_active_crtcs & (1 << i))
4201 				break;
4202 		}
4203 		if (i == adev->mode_info.num_crtc)
4204 			pipe = 0;
4205 		else
4206 			pipe = i;
4207 
4208 		tmp &= ~DCCG_DISP1_SLOW_SELECT_MASK;
4209 		tmp |= DCCG_DISP1_SLOW_SELECT(pipe);
4210 		WREG32(DCCG_DISP_SLOW_SELECT_REG, tmp);
4211 	}
4212 
4213 	/* Setting this to false forces the performance state to low if the crtcs are disabled.
4214 	 * This can be a problem on PowerXpress systems or if you want to use the card
4215 	 * for offscreen rendering or compute if there are no crtcs enabled.
4216 	 */
4217 	si_notify_smc_display_change(adev, adev->pm.dpm.new_active_crtc_count > 0);
4218 }
4219 
4220 static void si_enable_spread_spectrum(struct amdgpu_device *adev, bool enable)
4221 {
4222 	struct rv7xx_power_info *pi = rv770_get_pi(adev);
4223 
4224 	if (enable) {
4225 		if (pi->sclk_ss)
4226 			WREG32_P(GENERAL_PWRMGT, DYN_SPREAD_SPECTRUM_EN, ~DYN_SPREAD_SPECTRUM_EN);
4227 	} else {
4228 		WREG32_P(CG_SPLL_SPREAD_SPECTRUM, 0, ~SSEN);
4229 		WREG32_P(GENERAL_PWRMGT, 0, ~DYN_SPREAD_SPECTRUM_EN);
4230 	}
4231 }
4232 
4233 static void si_setup_bsp(struct amdgpu_device *adev)
4234 {
4235 	struct rv7xx_power_info *pi = rv770_get_pi(adev);
4236 	u32 xclk = amdgpu_asic_get_xclk(adev);
4237 
4238 	r600_calculate_u_and_p(pi->asi,
4239 			       xclk,
4240 			       16,
4241 			       &pi->bsp,
4242 			       &pi->bsu);
4243 
4244 	r600_calculate_u_and_p(pi->pasi,
4245 			       xclk,
4246 			       16,
4247 			       &pi->pbsp,
4248 			       &pi->pbsu);
4249 
4250 
4251         pi->dsp = BSP(pi->bsp) | BSU(pi->bsu);
4252 	pi->psp = BSP(pi->pbsp) | BSU(pi->pbsu);
4253 
4254 	WREG32(CG_BSP, pi->dsp);
4255 }
4256 
4257 static void si_program_git(struct amdgpu_device *adev)
4258 {
4259 	WREG32_P(CG_GIT, CG_GICST(R600_GICST_DFLT), ~CG_GICST_MASK);
4260 }
4261 
4262 static void si_program_tp(struct amdgpu_device *adev)
4263 {
4264 	int i;
4265 	enum r600_td td = R600_TD_DFLT;
4266 
4267 	for (i = 0; i < R600_PM_NUMBER_OF_TC; i++)
4268 		WREG32(CG_FFCT_0 + i, (UTC_0(r600_utc[i]) | DTC_0(r600_dtc[i])));
4269 
4270 	if (td == R600_TD_AUTO)
4271 		WREG32_P(SCLK_PWRMGT_CNTL, 0, ~FIR_FORCE_TREND_SEL);
4272 	else
4273 		WREG32_P(SCLK_PWRMGT_CNTL, FIR_FORCE_TREND_SEL, ~FIR_FORCE_TREND_SEL);
4274 
4275 	if (td == R600_TD_UP)
4276 		WREG32_P(SCLK_PWRMGT_CNTL, 0, ~FIR_TREND_MODE);
4277 
4278 	if (td == R600_TD_DOWN)
4279 		WREG32_P(SCLK_PWRMGT_CNTL, FIR_TREND_MODE, ~FIR_TREND_MODE);
4280 }
4281 
4282 static void si_program_tpp(struct amdgpu_device *adev)
4283 {
4284 	WREG32(CG_TPC, R600_TPC_DFLT);
4285 }
4286 
4287 static void si_program_sstp(struct amdgpu_device *adev)
4288 {
4289 	WREG32(CG_SSP, (SSTU(R600_SSTU_DFLT) | SST(R600_SST_DFLT)));
4290 }
4291 
4292 static void si_enable_display_gap(struct amdgpu_device *adev)
4293 {
4294 	u32 tmp = RREG32(CG_DISPLAY_GAP_CNTL);
4295 
4296 	tmp &= ~(DISP1_GAP_MASK | DISP2_GAP_MASK);
4297 	tmp |= (DISP1_GAP(R600_PM_DISPLAY_GAP_IGNORE) |
4298 		DISP2_GAP(R600_PM_DISPLAY_GAP_IGNORE));
4299 
4300 	tmp &= ~(DISP1_GAP_MCHG_MASK | DISP2_GAP_MCHG_MASK);
4301 	tmp |= (DISP1_GAP_MCHG(R600_PM_DISPLAY_GAP_VBLANK) |
4302 		DISP2_GAP_MCHG(R600_PM_DISPLAY_GAP_IGNORE));
4303 	WREG32(CG_DISPLAY_GAP_CNTL, tmp);
4304 }
4305 
4306 static void si_program_vc(struct amdgpu_device *adev)
4307 {
4308 	struct rv7xx_power_info *pi = rv770_get_pi(adev);
4309 
4310 	WREG32(CG_FTV, pi->vrc);
4311 }
4312 
4313 static void si_clear_vc(struct amdgpu_device *adev)
4314 {
4315 	WREG32(CG_FTV, 0);
4316 }
4317 
4318 static u8 si_get_ddr3_mclk_frequency_ratio(u32 memory_clock)
4319 {
4320 	u8 mc_para_index;
4321 
4322 	if (memory_clock < 10000)
4323 		mc_para_index = 0;
4324 	else if (memory_clock >= 80000)
4325 		mc_para_index = 0x0f;
4326 	else
4327 		mc_para_index = (u8)((memory_clock - 10000) / 5000 + 1);
4328 	return mc_para_index;
4329 }
4330 
4331 static u8 si_get_mclk_frequency_ratio(u32 memory_clock, bool strobe_mode)
4332 {
4333 	u8 mc_para_index;
4334 
4335 	if (strobe_mode) {
4336 		if (memory_clock < 12500)
4337 			mc_para_index = 0x00;
4338 		else if (memory_clock > 47500)
4339 			mc_para_index = 0x0f;
4340 		else
4341 			mc_para_index = (u8)((memory_clock - 10000) / 2500);
4342 	} else {
4343 		if (memory_clock < 65000)
4344 			mc_para_index = 0x00;
4345 		else if (memory_clock > 135000)
4346 			mc_para_index = 0x0f;
4347 		else
4348 			mc_para_index = (u8)((memory_clock - 60000) / 5000);
4349 	}
4350 	return mc_para_index;
4351 }
4352 
4353 static u8 si_get_strobe_mode_settings(struct amdgpu_device *adev, u32 mclk)
4354 {
4355 	struct rv7xx_power_info *pi = rv770_get_pi(adev);
4356 	bool strobe_mode = false;
4357 	u8 result = 0;
4358 
4359 	if (mclk <= pi->mclk_strobe_mode_threshold)
4360 		strobe_mode = true;
4361 
4362 	if (adev->gmc.vram_type == AMDGPU_VRAM_TYPE_GDDR5)
4363 		result = si_get_mclk_frequency_ratio(mclk, strobe_mode);
4364 	else
4365 		result = si_get_ddr3_mclk_frequency_ratio(mclk);
4366 
4367 	if (strobe_mode)
4368 		result |= SISLANDS_SMC_STROBE_ENABLE;
4369 
4370 	return result;
4371 }
4372 
4373 static int si_upload_firmware(struct amdgpu_device *adev)
4374 {
4375 	struct si_power_info *si_pi = si_get_pi(adev);
4376 
4377 	amdgpu_si_reset_smc(adev);
4378 	amdgpu_si_smc_clock(adev, false);
4379 
4380 	return amdgpu_si_load_smc_ucode(adev, si_pi->sram_end);
4381 }
4382 
4383 static bool si_validate_phase_shedding_tables(struct amdgpu_device *adev,
4384 					      const struct atom_voltage_table *table,
4385 					      const struct amdgpu_phase_shedding_limits_table *limits)
4386 {
4387 	u32 data, num_bits, num_levels;
4388 
4389 	if ((table == NULL) || (limits == NULL))
4390 		return false;
4391 
4392 	data = table->mask_low;
4393 
4394 	num_bits = hweight32(data);
4395 
4396 	if (num_bits == 0)
4397 		return false;
4398 
4399 	num_levels = (1 << num_bits);
4400 
4401 	if (table->count != num_levels)
4402 		return false;
4403 
4404 	if (limits->count != (num_levels - 1))
4405 		return false;
4406 
4407 	return true;
4408 }
4409 
4410 static void si_trim_voltage_table_to_fit_state_table(struct amdgpu_device *adev,
4411 					      u32 max_voltage_steps,
4412 					      struct atom_voltage_table *voltage_table)
4413 {
4414 	unsigned int i, diff;
4415 
4416 	if (voltage_table->count <= max_voltage_steps)
4417 		return;
4418 
4419 	diff = voltage_table->count - max_voltage_steps;
4420 
4421 	for (i= 0; i < max_voltage_steps; i++)
4422 		voltage_table->entries[i] = voltage_table->entries[i + diff];
4423 
4424 	voltage_table->count = max_voltage_steps;
4425 }
4426 
4427 static int si_get_svi2_voltage_table(struct amdgpu_device *adev,
4428 				     struct amdgpu_clock_voltage_dependency_table *voltage_dependency_table,
4429 				     struct atom_voltage_table *voltage_table)
4430 {
4431 	u32 i;
4432 
4433 	if (voltage_dependency_table == NULL)
4434 		return -EINVAL;
4435 
4436 	voltage_table->mask_low = 0;
4437 	voltage_table->phase_delay = 0;
4438 
4439 	voltage_table->count = voltage_dependency_table->count;
4440 	for (i = 0; i < voltage_table->count; i++) {
4441 		voltage_table->entries[i].value = voltage_dependency_table->entries[i].v;
4442 		voltage_table->entries[i].smio_low = 0;
4443 	}
4444 
4445 	return 0;
4446 }
4447 
4448 static int si_construct_voltage_tables(struct amdgpu_device *adev)
4449 {
4450 	struct rv7xx_power_info *pi = rv770_get_pi(adev);
4451 	struct evergreen_power_info *eg_pi = evergreen_get_pi(adev);
4452 	struct si_power_info *si_pi = si_get_pi(adev);
4453 	int ret;
4454 
4455 	if (pi->voltage_control) {
4456 		ret = amdgpu_atombios_get_voltage_table(adev, VOLTAGE_TYPE_VDDC,
4457 						    VOLTAGE_OBJ_GPIO_LUT, &eg_pi->vddc_voltage_table);
4458 		if (ret)
4459 			return ret;
4460 
4461 		if (eg_pi->vddc_voltage_table.count > SISLANDS_MAX_NO_VREG_STEPS)
4462 			si_trim_voltage_table_to_fit_state_table(adev,
4463 								 SISLANDS_MAX_NO_VREG_STEPS,
4464 								 &eg_pi->vddc_voltage_table);
4465 	} else if (si_pi->voltage_control_svi2) {
4466 		ret = si_get_svi2_voltage_table(adev,
4467 						&adev->pm.dpm.dyn_state.vddc_dependency_on_mclk,
4468 						&eg_pi->vddc_voltage_table);
4469 		if (ret)
4470 			return ret;
4471 	} else {
4472 		return -EINVAL;
4473 	}
4474 
4475 	if (eg_pi->vddci_control) {
4476 		ret = amdgpu_atombios_get_voltage_table(adev, VOLTAGE_TYPE_VDDCI,
4477 						    VOLTAGE_OBJ_GPIO_LUT, &eg_pi->vddci_voltage_table);
4478 		if (ret)
4479 			return ret;
4480 
4481 		if (eg_pi->vddci_voltage_table.count > SISLANDS_MAX_NO_VREG_STEPS)
4482 			si_trim_voltage_table_to_fit_state_table(adev,
4483 								 SISLANDS_MAX_NO_VREG_STEPS,
4484 								 &eg_pi->vddci_voltage_table);
4485 	}
4486 	if (si_pi->vddci_control_svi2) {
4487 		ret = si_get_svi2_voltage_table(adev,
4488 						&adev->pm.dpm.dyn_state.vddci_dependency_on_mclk,
4489 						&eg_pi->vddci_voltage_table);
4490 		if (ret)
4491 			return ret;
4492 	}
4493 
4494 	if (pi->mvdd_control) {
4495 		ret = amdgpu_atombios_get_voltage_table(adev, VOLTAGE_TYPE_MVDDC,
4496 						    VOLTAGE_OBJ_GPIO_LUT, &si_pi->mvdd_voltage_table);
4497 
4498 		if (ret) {
4499 			pi->mvdd_control = false;
4500 			return ret;
4501 		}
4502 
4503 		if (si_pi->mvdd_voltage_table.count == 0) {
4504 			pi->mvdd_control = false;
4505 			return -EINVAL;
4506 		}
4507 
4508 		if (si_pi->mvdd_voltage_table.count > SISLANDS_MAX_NO_VREG_STEPS)
4509 			si_trim_voltage_table_to_fit_state_table(adev,
4510 								 SISLANDS_MAX_NO_VREG_STEPS,
4511 								 &si_pi->mvdd_voltage_table);
4512 	}
4513 
4514 	if (si_pi->vddc_phase_shed_control) {
4515 		ret = amdgpu_atombios_get_voltage_table(adev, VOLTAGE_TYPE_VDDC,
4516 						    VOLTAGE_OBJ_PHASE_LUT, &si_pi->vddc_phase_shed_table);
4517 		if (ret)
4518 			si_pi->vddc_phase_shed_control = false;
4519 
4520 		if ((si_pi->vddc_phase_shed_table.count == 0) ||
4521 		    (si_pi->vddc_phase_shed_table.count > SISLANDS_MAX_NO_VREG_STEPS))
4522 			si_pi->vddc_phase_shed_control = false;
4523 	}
4524 
4525 	return 0;
4526 }
4527 
4528 static void si_populate_smc_voltage_table(struct amdgpu_device *adev,
4529 					  const struct atom_voltage_table *voltage_table,
4530 					  SISLANDS_SMC_STATETABLE *table)
4531 {
4532 	unsigned int i;
4533 
4534 	for (i = 0; i < voltage_table->count; i++)
4535 		table->lowSMIO[i] |= cpu_to_be32(voltage_table->entries[i].smio_low);
4536 }
4537 
4538 static int si_populate_smc_voltage_tables(struct amdgpu_device *adev,
4539 					  SISLANDS_SMC_STATETABLE *table)
4540 {
4541 	struct rv7xx_power_info *pi = rv770_get_pi(adev);
4542 	struct evergreen_power_info *eg_pi = evergreen_get_pi(adev);
4543 	struct si_power_info *si_pi = si_get_pi(adev);
4544 	u8 i;
4545 
4546 	if (si_pi->voltage_control_svi2) {
4547 		si_write_smc_soft_register(adev, SI_SMC_SOFT_REGISTER_svi_rework_gpio_id_svc,
4548 			si_pi->svc_gpio_id);
4549 		si_write_smc_soft_register(adev, SI_SMC_SOFT_REGISTER_svi_rework_gpio_id_svd,
4550 			si_pi->svd_gpio_id);
4551 		si_write_smc_soft_register(adev, SI_SMC_SOFT_REGISTER_svi_rework_plat_type,
4552 					   2);
4553 	} else {
4554 		if (eg_pi->vddc_voltage_table.count) {
4555 			si_populate_smc_voltage_table(adev, &eg_pi->vddc_voltage_table, table);
4556 			table->voltageMaskTable.lowMask[SISLANDS_SMC_VOLTAGEMASK_VDDC] =
4557 				cpu_to_be32(eg_pi->vddc_voltage_table.mask_low);
4558 
4559 			for (i = 0; i < eg_pi->vddc_voltage_table.count; i++) {
4560 				if (pi->max_vddc_in_table <= eg_pi->vddc_voltage_table.entries[i].value) {
4561 					table->maxVDDCIndexInPPTable = i;
4562 					break;
4563 				}
4564 			}
4565 		}
4566 
4567 		if (eg_pi->vddci_voltage_table.count) {
4568 			si_populate_smc_voltage_table(adev, &eg_pi->vddci_voltage_table, table);
4569 
4570 			table->voltageMaskTable.lowMask[SISLANDS_SMC_VOLTAGEMASK_VDDCI] =
4571 				cpu_to_be32(eg_pi->vddci_voltage_table.mask_low);
4572 		}
4573 
4574 
4575 		if (si_pi->mvdd_voltage_table.count) {
4576 			si_populate_smc_voltage_table(adev, &si_pi->mvdd_voltage_table, table);
4577 
4578 			table->voltageMaskTable.lowMask[SISLANDS_SMC_VOLTAGEMASK_MVDD] =
4579 				cpu_to_be32(si_pi->mvdd_voltage_table.mask_low);
4580 		}
4581 
4582 		if (si_pi->vddc_phase_shed_control) {
4583 			if (si_validate_phase_shedding_tables(adev, &si_pi->vddc_phase_shed_table,
4584 							      &adev->pm.dpm.dyn_state.phase_shedding_limits_table)) {
4585 				si_populate_smc_voltage_table(adev, &si_pi->vddc_phase_shed_table, table);
4586 
4587 				table->phaseMaskTable.lowMask[SISLANDS_SMC_VOLTAGEMASK_VDDC_PHASE_SHEDDING] =
4588 					cpu_to_be32(si_pi->vddc_phase_shed_table.mask_low);
4589 
4590 				si_write_smc_soft_register(adev, SI_SMC_SOFT_REGISTER_phase_shedding_delay,
4591 							   (u32)si_pi->vddc_phase_shed_table.phase_delay);
4592 			} else {
4593 				si_pi->vddc_phase_shed_control = false;
4594 			}
4595 		}
4596 	}
4597 
4598 	return 0;
4599 }
4600 
4601 static int si_populate_voltage_value(struct amdgpu_device *adev,
4602 				     const struct atom_voltage_table *table,
4603 				     u16 value, SISLANDS_SMC_VOLTAGE_VALUE *voltage)
4604 {
4605 	unsigned int i;
4606 
4607 	for (i = 0; i < table->count; i++) {
4608 		if (value <= table->entries[i].value) {
4609 			voltage->index = (u8)i;
4610 			voltage->value = cpu_to_be16(table->entries[i].value);
4611 			break;
4612 		}
4613 	}
4614 
4615 	if (i >= table->count)
4616 		return -EINVAL;
4617 
4618 	return 0;
4619 }
4620 
4621 static int si_populate_mvdd_value(struct amdgpu_device *adev, u32 mclk,
4622 				  SISLANDS_SMC_VOLTAGE_VALUE *voltage)
4623 {
4624 	struct rv7xx_power_info *pi = rv770_get_pi(adev);
4625 	struct si_power_info *si_pi = si_get_pi(adev);
4626 
4627 	if (pi->mvdd_control) {
4628 		if (mclk <= pi->mvdd_split_frequency)
4629 			voltage->index = 0;
4630 		else
4631 			voltage->index = (u8)(si_pi->mvdd_voltage_table.count) - 1;
4632 
4633 		voltage->value = cpu_to_be16(si_pi->mvdd_voltage_table.entries[voltage->index].value);
4634 	}
4635 	return 0;
4636 }
4637 
4638 static int si_get_std_voltage_value(struct amdgpu_device *adev,
4639 				    SISLANDS_SMC_VOLTAGE_VALUE *voltage,
4640 				    u16 *std_voltage)
4641 {
4642 	u16 v_index;
4643 	bool voltage_found = false;
4644 	*std_voltage = be16_to_cpu(voltage->value);
4645 
4646 	if (adev->pm.dpm.dyn_state.cac_leakage_table.entries) {
4647 		if (adev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_NEW_CAC_VOLTAGE) {
4648 			if (adev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries == NULL)
4649 				return -EINVAL;
4650 
4651 			for (v_index = 0; (u32)v_index < adev->pm.dpm.dyn_state.vddc_dependency_on_sclk.count; v_index++) {
4652 				if (be16_to_cpu(voltage->value) ==
4653 				    (u16)adev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries[v_index].v) {
4654 					voltage_found = true;
4655 					if ((u32)v_index < adev->pm.dpm.dyn_state.cac_leakage_table.count)
4656 						*std_voltage =
4657 							adev->pm.dpm.dyn_state.cac_leakage_table.entries[v_index].vddc;
4658 					else
4659 						*std_voltage =
4660 							adev->pm.dpm.dyn_state.cac_leakage_table.entries[adev->pm.dpm.dyn_state.cac_leakage_table.count-1].vddc;
4661 					break;
4662 				}
4663 			}
4664 
4665 			if (!voltage_found) {
4666 				for (v_index = 0; (u32)v_index < adev->pm.dpm.dyn_state.vddc_dependency_on_sclk.count; v_index++) {
4667 					if (be16_to_cpu(voltage->value) <=
4668 					    (u16)adev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries[v_index].v) {
4669 						voltage_found = true;
4670 						if ((u32)v_index < adev->pm.dpm.dyn_state.cac_leakage_table.count)
4671 							*std_voltage =
4672 								adev->pm.dpm.dyn_state.cac_leakage_table.entries[v_index].vddc;
4673 						else
4674 							*std_voltage =
4675 								adev->pm.dpm.dyn_state.cac_leakage_table.entries[adev->pm.dpm.dyn_state.cac_leakage_table.count-1].vddc;
4676 						break;
4677 					}
4678 				}
4679 			}
4680 		} else {
4681 			if ((u32)voltage->index < adev->pm.dpm.dyn_state.cac_leakage_table.count)
4682 				*std_voltage = adev->pm.dpm.dyn_state.cac_leakage_table.entries[voltage->index].vddc;
4683 		}
4684 	}
4685 
4686 	return 0;
4687 }
4688 
4689 static int si_populate_std_voltage_value(struct amdgpu_device *adev,
4690 					 u16 value, u8 index,
4691 					 SISLANDS_SMC_VOLTAGE_VALUE *voltage)
4692 {
4693 	voltage->index = index;
4694 	voltage->value = cpu_to_be16(value);
4695 
4696 	return 0;
4697 }
4698 
4699 static int si_populate_phase_shedding_value(struct amdgpu_device *adev,
4700 					    const struct amdgpu_phase_shedding_limits_table *limits,
4701 					    u16 voltage, u32 sclk, u32 mclk,
4702 					    SISLANDS_SMC_VOLTAGE_VALUE *smc_voltage)
4703 {
4704 	unsigned int i;
4705 
4706 	for (i = 0; i < limits->count; i++) {
4707 		if ((voltage <= limits->entries[i].voltage) &&
4708 		    (sclk <= limits->entries[i].sclk) &&
4709 		    (mclk <= limits->entries[i].mclk))
4710 			break;
4711 	}
4712 
4713 	smc_voltage->phase_settings = (u8)i;
4714 
4715 	return 0;
4716 }
4717 
4718 static int si_init_arb_table_index(struct amdgpu_device *adev)
4719 {
4720 	struct si_power_info *si_pi = si_get_pi(adev);
4721 	u32 tmp;
4722 	int ret;
4723 
4724 	ret = amdgpu_si_read_smc_sram_dword(adev, si_pi->arb_table_start,
4725 					    &tmp, si_pi->sram_end);
4726 	if (ret)
4727 		return ret;
4728 
4729 	tmp &= 0x00FFFFFF;
4730 	tmp |= MC_CG_ARB_FREQ_F1 << 24;
4731 
4732 	return amdgpu_si_write_smc_sram_dword(adev, si_pi->arb_table_start,
4733 					      tmp, si_pi->sram_end);
4734 }
4735 
4736 static int si_initial_switch_from_arb_f0_to_f1(struct amdgpu_device *adev)
4737 {
4738 	return ni_copy_and_switch_arb_sets(adev, MC_CG_ARB_FREQ_F0, MC_CG_ARB_FREQ_F1);
4739 }
4740 
4741 static int si_reset_to_default(struct amdgpu_device *adev)
4742 {
4743 	return (amdgpu_si_send_msg_to_smc(adev, PPSMC_MSG_ResetToDefaults) == PPSMC_Result_OK) ?
4744 		0 : -EINVAL;
4745 }
4746 
4747 static int si_force_switch_to_arb_f0(struct amdgpu_device *adev)
4748 {
4749 	struct si_power_info *si_pi = si_get_pi(adev);
4750 	u32 tmp;
4751 	int ret;
4752 
4753 	ret = amdgpu_si_read_smc_sram_dword(adev, si_pi->arb_table_start,
4754 					    &tmp, si_pi->sram_end);
4755 	if (ret)
4756 		return ret;
4757 
4758 	tmp = (tmp >> 24) & 0xff;
4759 
4760 	if (tmp == MC_CG_ARB_FREQ_F0)
4761 		return 0;
4762 
4763 	return ni_copy_and_switch_arb_sets(adev, tmp, MC_CG_ARB_FREQ_F0);
4764 }
4765 
4766 static u32 si_calculate_memory_refresh_rate(struct amdgpu_device *adev,
4767 					    u32 engine_clock)
4768 {
4769 	u32 dram_rows;
4770 	u32 dram_refresh_rate;
4771 	u32 mc_arb_rfsh_rate;
4772 	u32 tmp = (RREG32(MC_ARB_RAMCFG) & NOOFROWS_MASK) >> NOOFROWS_SHIFT;
4773 
4774 	if (tmp >= 4)
4775 		dram_rows = 16384;
4776 	else
4777 		dram_rows = 1 << (tmp + 10);
4778 
4779 	dram_refresh_rate = 1 << ((RREG32(MC_SEQ_MISC0) & 0x3) + 3);
4780 	mc_arb_rfsh_rate = ((engine_clock * 10) * dram_refresh_rate / dram_rows - 32) / 64;
4781 
4782 	return mc_arb_rfsh_rate;
4783 }
4784 
4785 static int si_populate_memory_timing_parameters(struct amdgpu_device *adev,
4786 						struct rv7xx_pl *pl,
4787 						SMC_SIslands_MCArbDramTimingRegisterSet *arb_regs)
4788 {
4789 	u32 dram_timing;
4790 	u32 dram_timing2;
4791 	u32 burst_time;
4792 
4793 	arb_regs->mc_arb_rfsh_rate =
4794 		(u8)si_calculate_memory_refresh_rate(adev, pl->sclk);
4795 
4796 	amdgpu_atombios_set_engine_dram_timings(adev,
4797 					    pl->sclk,
4798 		                            pl->mclk);
4799 
4800 	dram_timing  = RREG32(MC_ARB_DRAM_TIMING);
4801 	dram_timing2 = RREG32(MC_ARB_DRAM_TIMING2);
4802 	burst_time = RREG32(MC_ARB_BURST_TIME) & STATE0_MASK;
4803 
4804 	arb_regs->mc_arb_dram_timing  = cpu_to_be32(dram_timing);
4805 	arb_regs->mc_arb_dram_timing2 = cpu_to_be32(dram_timing2);
4806 	arb_regs->mc_arb_burst_time = (u8)burst_time;
4807 
4808 	return 0;
4809 }
4810 
4811 static int si_do_program_memory_timing_parameters(struct amdgpu_device *adev,
4812 						  struct amdgpu_ps *amdgpu_state,
4813 						  unsigned int first_arb_set)
4814 {
4815 	struct si_power_info *si_pi = si_get_pi(adev);
4816 	struct  si_ps *state = si_get_ps(amdgpu_state);
4817 	SMC_SIslands_MCArbDramTimingRegisterSet arb_regs = { 0 };
4818 	int i, ret = 0;
4819 
4820 	for (i = 0; i < state->performance_level_count; i++) {
4821 		ret = si_populate_memory_timing_parameters(adev, &state->performance_levels[i], &arb_regs);
4822 		if (ret)
4823 			break;
4824 		ret = amdgpu_si_copy_bytes_to_smc(adev,
4825 						  si_pi->arb_table_start +
4826 						  offsetof(SMC_SIslands_MCArbDramTimingRegisters, data) +
4827 						  sizeof(SMC_SIslands_MCArbDramTimingRegisterSet) * (first_arb_set + i),
4828 						  (u8 *)&arb_regs,
4829 						  sizeof(SMC_SIslands_MCArbDramTimingRegisterSet),
4830 						  si_pi->sram_end);
4831 		if (ret)
4832 			break;
4833 	}
4834 
4835 	return ret;
4836 }
4837 
4838 static int si_program_memory_timing_parameters(struct amdgpu_device *adev,
4839 					       struct amdgpu_ps *amdgpu_new_state)
4840 {
4841 	return si_do_program_memory_timing_parameters(adev, amdgpu_new_state,
4842 						      SISLANDS_DRIVER_STATE_ARB_INDEX);
4843 }
4844 
4845 static int si_populate_initial_mvdd_value(struct amdgpu_device *adev,
4846 					  struct SISLANDS_SMC_VOLTAGE_VALUE *voltage)
4847 {
4848 	struct rv7xx_power_info *pi = rv770_get_pi(adev);
4849 	struct si_power_info *si_pi = si_get_pi(adev);
4850 
4851 	if (pi->mvdd_control)
4852 		return si_populate_voltage_value(adev, &si_pi->mvdd_voltage_table,
4853 						 si_pi->mvdd_bootup_value, voltage);
4854 
4855 	return 0;
4856 }
4857 
4858 static int si_populate_smc_initial_state(struct amdgpu_device *adev,
4859 					 struct amdgpu_ps *amdgpu_initial_state,
4860 					 SISLANDS_SMC_STATETABLE *table)
4861 {
4862 	struct  si_ps *initial_state = si_get_ps(amdgpu_initial_state);
4863 	struct rv7xx_power_info *pi = rv770_get_pi(adev);
4864 	struct evergreen_power_info *eg_pi = evergreen_get_pi(adev);
4865 	struct si_power_info *si_pi = si_get_pi(adev);
4866 	u32 reg;
4867 	int ret;
4868 
4869 	table->initialState.level.mclk.vDLL_CNTL =
4870 		cpu_to_be32(si_pi->clock_registers.dll_cntl);
4871 	table->initialState.level.mclk.vMCLK_PWRMGT_CNTL =
4872 		cpu_to_be32(si_pi->clock_registers.mclk_pwrmgt_cntl);
4873 	table->initialState.level.mclk.vMPLL_AD_FUNC_CNTL =
4874 		cpu_to_be32(si_pi->clock_registers.mpll_ad_func_cntl);
4875 	table->initialState.level.mclk.vMPLL_DQ_FUNC_CNTL =
4876 		cpu_to_be32(si_pi->clock_registers.mpll_dq_func_cntl);
4877 	table->initialState.level.mclk.vMPLL_FUNC_CNTL =
4878 		cpu_to_be32(si_pi->clock_registers.mpll_func_cntl);
4879 	table->initialState.level.mclk.vMPLL_FUNC_CNTL_1 =
4880 		cpu_to_be32(si_pi->clock_registers.mpll_func_cntl_1);
4881 	table->initialState.level.mclk.vMPLL_FUNC_CNTL_2 =
4882 		cpu_to_be32(si_pi->clock_registers.mpll_func_cntl_2);
4883 	table->initialState.level.mclk.vMPLL_SS =
4884 		cpu_to_be32(si_pi->clock_registers.mpll_ss1);
4885 	table->initialState.level.mclk.vMPLL_SS2 =
4886 		cpu_to_be32(si_pi->clock_registers.mpll_ss2);
4887 
4888 	table->initialState.level.mclk.mclk_value =
4889 		cpu_to_be32(initial_state->performance_levels[0].mclk);
4890 
4891 	table->initialState.level.sclk.vCG_SPLL_FUNC_CNTL =
4892 		cpu_to_be32(si_pi->clock_registers.cg_spll_func_cntl);
4893 	table->initialState.level.sclk.vCG_SPLL_FUNC_CNTL_2 =
4894 		cpu_to_be32(si_pi->clock_registers.cg_spll_func_cntl_2);
4895 	table->initialState.level.sclk.vCG_SPLL_FUNC_CNTL_3 =
4896 		cpu_to_be32(si_pi->clock_registers.cg_spll_func_cntl_3);
4897 	table->initialState.level.sclk.vCG_SPLL_FUNC_CNTL_4 =
4898 		cpu_to_be32(si_pi->clock_registers.cg_spll_func_cntl_4);
4899 	table->initialState.level.sclk.vCG_SPLL_SPREAD_SPECTRUM =
4900 		cpu_to_be32(si_pi->clock_registers.cg_spll_spread_spectrum);
4901 	table->initialState.level.sclk.vCG_SPLL_SPREAD_SPECTRUM_2  =
4902 		cpu_to_be32(si_pi->clock_registers.cg_spll_spread_spectrum_2);
4903 
4904 	table->initialState.level.sclk.sclk_value =
4905 		cpu_to_be32(initial_state->performance_levels[0].sclk);
4906 
4907 	table->initialState.level.arbRefreshState =
4908 		SISLANDS_INITIAL_STATE_ARB_INDEX;
4909 
4910 	table->initialState.level.ACIndex = 0;
4911 
4912 	ret = si_populate_voltage_value(adev, &eg_pi->vddc_voltage_table,
4913 					initial_state->performance_levels[0].vddc,
4914 					&table->initialState.level.vddc);
4915 
4916 	if (!ret) {
4917 		u16 std_vddc;
4918 
4919 		ret = si_get_std_voltage_value(adev,
4920 					       &table->initialState.level.vddc,
4921 					       &std_vddc);
4922 		if (!ret)
4923 			si_populate_std_voltage_value(adev, std_vddc,
4924 						      table->initialState.level.vddc.index,
4925 						      &table->initialState.level.std_vddc);
4926 	}
4927 
4928 	if (eg_pi->vddci_control)
4929 		si_populate_voltage_value(adev,
4930 					  &eg_pi->vddci_voltage_table,
4931 					  initial_state->performance_levels[0].vddci,
4932 					  &table->initialState.level.vddci);
4933 
4934 	if (si_pi->vddc_phase_shed_control)
4935 		si_populate_phase_shedding_value(adev,
4936 						 &adev->pm.dpm.dyn_state.phase_shedding_limits_table,
4937 						 initial_state->performance_levels[0].vddc,
4938 						 initial_state->performance_levels[0].sclk,
4939 						 initial_state->performance_levels[0].mclk,
4940 						 &table->initialState.level.vddc);
4941 
4942 	si_populate_initial_mvdd_value(adev, &table->initialState.level.mvdd);
4943 
4944 	reg = CG_R(0xffff) | CG_L(0);
4945 	table->initialState.level.aT = cpu_to_be32(reg);
4946 	table->initialState.level.bSP = cpu_to_be32(pi->dsp);
4947 	table->initialState.level.gen2PCIE = (u8)si_pi->boot_pcie_gen;
4948 
4949 	if (adev->gmc.vram_type == AMDGPU_VRAM_TYPE_GDDR5) {
4950 		table->initialState.level.strobeMode =
4951 			si_get_strobe_mode_settings(adev,
4952 						    initial_state->performance_levels[0].mclk);
4953 
4954 		if (initial_state->performance_levels[0].mclk > pi->mclk_edc_enable_threshold)
4955 			table->initialState.level.mcFlags = SISLANDS_SMC_MC_EDC_RD_FLAG | SISLANDS_SMC_MC_EDC_WR_FLAG;
4956 		else
4957 			table->initialState.level.mcFlags =  0;
4958 	}
4959 
4960 	table->initialState.levelCount = 1;
4961 
4962 	table->initialState.flags |= PPSMC_SWSTATE_FLAG_DC;
4963 
4964 	table->initialState.level.dpm2.MaxPS = 0;
4965 	table->initialState.level.dpm2.NearTDPDec = 0;
4966 	table->initialState.level.dpm2.AboveSafeInc = 0;
4967 	table->initialState.level.dpm2.BelowSafeInc = 0;
4968 	table->initialState.level.dpm2.PwrEfficiencyRatio = 0;
4969 
4970 	reg = MIN_POWER_MASK | MAX_POWER_MASK;
4971 	table->initialState.level.SQPowerThrottle = cpu_to_be32(reg);
4972 
4973 	reg = MAX_POWER_DELTA_MASK | STI_SIZE_MASK | LTI_RATIO_MASK;
4974 	table->initialState.level.SQPowerThrottle_2 = cpu_to_be32(reg);
4975 
4976 	return 0;
4977 }
4978 
4979 static enum si_pcie_gen si_gen_pcie_gen_support(struct amdgpu_device *adev,
4980 						u32 sys_mask,
4981 						enum si_pcie_gen asic_gen,
4982 						enum si_pcie_gen default_gen)
4983 {
4984 	switch (asic_gen) {
4985 	case SI_PCIE_GEN1:
4986 		return SI_PCIE_GEN1;
4987 	case SI_PCIE_GEN2:
4988 		return SI_PCIE_GEN2;
4989 	case SI_PCIE_GEN3:
4990 		return SI_PCIE_GEN3;
4991 	default:
4992 		if ((sys_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3) &&
4993 		    (default_gen == SI_PCIE_GEN3))
4994 			return SI_PCIE_GEN3;
4995 		else if ((sys_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2) &&
4996 			 (default_gen == SI_PCIE_GEN2))
4997 			return SI_PCIE_GEN2;
4998 		else
4999 			return SI_PCIE_GEN1;
5000 	}
5001 	return SI_PCIE_GEN1;
5002 }
5003 
5004 static int si_populate_smc_acpi_state(struct amdgpu_device *adev,
5005 				      SISLANDS_SMC_STATETABLE *table)
5006 {
5007 	struct rv7xx_power_info *pi = rv770_get_pi(adev);
5008 	struct evergreen_power_info *eg_pi = evergreen_get_pi(adev);
5009 	struct si_power_info *si_pi = si_get_pi(adev);
5010 	u32 spll_func_cntl = si_pi->clock_registers.cg_spll_func_cntl;
5011 	u32 spll_func_cntl_2 = si_pi->clock_registers.cg_spll_func_cntl_2;
5012 	u32 spll_func_cntl_3 = si_pi->clock_registers.cg_spll_func_cntl_3;
5013 	u32 spll_func_cntl_4 = si_pi->clock_registers.cg_spll_func_cntl_4;
5014 	u32 dll_cntl = si_pi->clock_registers.dll_cntl;
5015 	u32 mclk_pwrmgt_cntl = si_pi->clock_registers.mclk_pwrmgt_cntl;
5016 	u32 mpll_ad_func_cntl = si_pi->clock_registers.mpll_ad_func_cntl;
5017 	u32 mpll_dq_func_cntl = si_pi->clock_registers.mpll_dq_func_cntl;
5018 	u32 mpll_func_cntl = si_pi->clock_registers.mpll_func_cntl;
5019 	u32 mpll_func_cntl_1 = si_pi->clock_registers.mpll_func_cntl_1;
5020 	u32 mpll_func_cntl_2 = si_pi->clock_registers.mpll_func_cntl_2;
5021 	u32 reg;
5022 	int ret;
5023 
5024 	table->ACPIState = table->initialState;
5025 
5026 	table->ACPIState.flags &= ~PPSMC_SWSTATE_FLAG_DC;
5027 
5028 	if (pi->acpi_vddc) {
5029 		ret = si_populate_voltage_value(adev, &eg_pi->vddc_voltage_table,
5030 						pi->acpi_vddc, &table->ACPIState.level.vddc);
5031 		if (!ret) {
5032 			u16 std_vddc;
5033 
5034 			ret = si_get_std_voltage_value(adev,
5035 						       &table->ACPIState.level.vddc, &std_vddc);
5036 			if (!ret)
5037 				si_populate_std_voltage_value(adev, std_vddc,
5038 							      table->ACPIState.level.vddc.index,
5039 							      &table->ACPIState.level.std_vddc);
5040 		}
5041 		table->ACPIState.level.gen2PCIE = si_pi->acpi_pcie_gen;
5042 
5043 		if (si_pi->vddc_phase_shed_control) {
5044 			si_populate_phase_shedding_value(adev,
5045 							 &adev->pm.dpm.dyn_state.phase_shedding_limits_table,
5046 							 pi->acpi_vddc,
5047 							 0,
5048 							 0,
5049 							 &table->ACPIState.level.vddc);
5050 		}
5051 	} else {
5052 		ret = si_populate_voltage_value(adev, &eg_pi->vddc_voltage_table,
5053 						pi->min_vddc_in_table, &table->ACPIState.level.vddc);
5054 		if (!ret) {
5055 			u16 std_vddc;
5056 
5057 			ret = si_get_std_voltage_value(adev,
5058 						       &table->ACPIState.level.vddc, &std_vddc);
5059 
5060 			if (!ret)
5061 				si_populate_std_voltage_value(adev, std_vddc,
5062 							      table->ACPIState.level.vddc.index,
5063 							      &table->ACPIState.level.std_vddc);
5064 		}
5065 		table->ACPIState.level.gen2PCIE =
5066 			(u8)si_gen_pcie_gen_support(adev,
5067 						    si_pi->sys_pcie_mask,
5068 						    si_pi->boot_pcie_gen,
5069 						    SI_PCIE_GEN1);
5070 
5071 		if (si_pi->vddc_phase_shed_control)
5072 			si_populate_phase_shedding_value(adev,
5073 							 &adev->pm.dpm.dyn_state.phase_shedding_limits_table,
5074 							 pi->min_vddc_in_table,
5075 							 0,
5076 							 0,
5077 							 &table->ACPIState.level.vddc);
5078 	}
5079 
5080 	if (pi->acpi_vddc) {
5081 		if (eg_pi->acpi_vddci)
5082 			si_populate_voltage_value(adev, &eg_pi->vddci_voltage_table,
5083 						  eg_pi->acpi_vddci,
5084 						  &table->ACPIState.level.vddci);
5085 	}
5086 
5087 	mclk_pwrmgt_cntl |= MRDCK0_RESET | MRDCK1_RESET;
5088 	mclk_pwrmgt_cntl &= ~(MRDCK0_PDNB | MRDCK1_PDNB);
5089 
5090 	dll_cntl &= ~(MRDCK0_BYPASS | MRDCK1_BYPASS);
5091 
5092 	spll_func_cntl_2 &= ~SCLK_MUX_SEL_MASK;
5093 	spll_func_cntl_2 |= SCLK_MUX_SEL(4);
5094 
5095 	table->ACPIState.level.mclk.vDLL_CNTL =
5096 		cpu_to_be32(dll_cntl);
5097 	table->ACPIState.level.mclk.vMCLK_PWRMGT_CNTL =
5098 		cpu_to_be32(mclk_pwrmgt_cntl);
5099 	table->ACPIState.level.mclk.vMPLL_AD_FUNC_CNTL =
5100 		cpu_to_be32(mpll_ad_func_cntl);
5101 	table->ACPIState.level.mclk.vMPLL_DQ_FUNC_CNTL =
5102 		cpu_to_be32(mpll_dq_func_cntl);
5103 	table->ACPIState.level.mclk.vMPLL_FUNC_CNTL =
5104 		cpu_to_be32(mpll_func_cntl);
5105 	table->ACPIState.level.mclk.vMPLL_FUNC_CNTL_1 =
5106 		cpu_to_be32(mpll_func_cntl_1);
5107 	table->ACPIState.level.mclk.vMPLL_FUNC_CNTL_2 =
5108 		cpu_to_be32(mpll_func_cntl_2);
5109 	table->ACPIState.level.mclk.vMPLL_SS =
5110 		cpu_to_be32(si_pi->clock_registers.mpll_ss1);
5111 	table->ACPIState.level.mclk.vMPLL_SS2 =
5112 		cpu_to_be32(si_pi->clock_registers.mpll_ss2);
5113 
5114 	table->ACPIState.level.sclk.vCG_SPLL_FUNC_CNTL =
5115 		cpu_to_be32(spll_func_cntl);
5116 	table->ACPIState.level.sclk.vCG_SPLL_FUNC_CNTL_2 =
5117 		cpu_to_be32(spll_func_cntl_2);
5118 	table->ACPIState.level.sclk.vCG_SPLL_FUNC_CNTL_3 =
5119 		cpu_to_be32(spll_func_cntl_3);
5120 	table->ACPIState.level.sclk.vCG_SPLL_FUNC_CNTL_4 =
5121 		cpu_to_be32(spll_func_cntl_4);
5122 
5123 	table->ACPIState.level.mclk.mclk_value = 0;
5124 	table->ACPIState.level.sclk.sclk_value = 0;
5125 
5126 	si_populate_mvdd_value(adev, 0, &table->ACPIState.level.mvdd);
5127 
5128 	if (eg_pi->dynamic_ac_timing)
5129 		table->ACPIState.level.ACIndex = 0;
5130 
5131 	table->ACPIState.level.dpm2.MaxPS = 0;
5132 	table->ACPIState.level.dpm2.NearTDPDec = 0;
5133 	table->ACPIState.level.dpm2.AboveSafeInc = 0;
5134 	table->ACPIState.level.dpm2.BelowSafeInc = 0;
5135 	table->ACPIState.level.dpm2.PwrEfficiencyRatio = 0;
5136 
5137 	reg = MIN_POWER_MASK | MAX_POWER_MASK;
5138 	table->ACPIState.level.SQPowerThrottle = cpu_to_be32(reg);
5139 
5140 	reg = MAX_POWER_DELTA_MASK | STI_SIZE_MASK | LTI_RATIO_MASK;
5141 	table->ACPIState.level.SQPowerThrottle_2 = cpu_to_be32(reg);
5142 
5143 	return 0;
5144 }
5145 
5146 static int si_populate_ulv_state(struct amdgpu_device *adev,
5147 				 struct SISLANDS_SMC_SWSTATE_SINGLE *state)
5148 {
5149 	struct evergreen_power_info *eg_pi = evergreen_get_pi(adev);
5150 	struct si_power_info *si_pi = si_get_pi(adev);
5151 	struct si_ulv_param *ulv = &si_pi->ulv;
5152 	u32 sclk_in_sr = 1350; /* ??? */
5153 	int ret;
5154 
5155 	ret = si_convert_power_level_to_smc(adev, &ulv->pl,
5156 					    &state->level);
5157 	if (!ret) {
5158 		if (eg_pi->sclk_deep_sleep) {
5159 			if (sclk_in_sr <= SCLK_MIN_DEEPSLEEP_FREQ)
5160 				state->level.stateFlags |= PPSMC_STATEFLAG_DEEPSLEEP_BYPASS;
5161 			else
5162 				state->level.stateFlags |= PPSMC_STATEFLAG_DEEPSLEEP_THROTTLE;
5163 		}
5164 		if (ulv->one_pcie_lane_in_ulv)
5165 			state->flags |= PPSMC_SWSTATE_FLAG_PCIE_X1;
5166 		state->level.arbRefreshState = (u8)(SISLANDS_ULV_STATE_ARB_INDEX);
5167 		state->level.ACIndex = 1;
5168 		state->level.std_vddc = state->level.vddc;
5169 		state->levelCount = 1;
5170 
5171 		state->flags |= PPSMC_SWSTATE_FLAG_DC;
5172 	}
5173 
5174 	return ret;
5175 }
5176 
5177 static int si_program_ulv_memory_timing_parameters(struct amdgpu_device *adev)
5178 {
5179 	struct si_power_info *si_pi = si_get_pi(adev);
5180 	struct si_ulv_param *ulv = &si_pi->ulv;
5181 	SMC_SIslands_MCArbDramTimingRegisterSet arb_regs = { 0 };
5182 	int ret;
5183 
5184 	ret = si_populate_memory_timing_parameters(adev, &ulv->pl,
5185 						   &arb_regs);
5186 	if (ret)
5187 		return ret;
5188 
5189 	si_write_smc_soft_register(adev, SI_SMC_SOFT_REGISTER_ulv_volt_change_delay,
5190 				   ulv->volt_change_delay);
5191 
5192 	ret = amdgpu_si_copy_bytes_to_smc(adev,
5193 					  si_pi->arb_table_start +
5194 					  offsetof(SMC_SIslands_MCArbDramTimingRegisters, data) +
5195 					  sizeof(SMC_SIslands_MCArbDramTimingRegisterSet) * SISLANDS_ULV_STATE_ARB_INDEX,
5196 					  (u8 *)&arb_regs,
5197 					  sizeof(SMC_SIslands_MCArbDramTimingRegisterSet),
5198 					  si_pi->sram_end);
5199 
5200 	return ret;
5201 }
5202 
5203 static void si_get_mvdd_configuration(struct amdgpu_device *adev)
5204 {
5205 	struct rv7xx_power_info *pi = rv770_get_pi(adev);
5206 
5207 	pi->mvdd_split_frequency = 30000;
5208 }
5209 
5210 static int si_init_smc_table(struct amdgpu_device *adev)
5211 {
5212 	struct si_power_info *si_pi = si_get_pi(adev);
5213 	struct amdgpu_ps *amdgpu_boot_state = adev->pm.dpm.boot_ps;
5214 	const struct si_ulv_param *ulv = &si_pi->ulv;
5215 	SISLANDS_SMC_STATETABLE  *table = &si_pi->smc_statetable;
5216 	int ret;
5217 	u32 lane_width;
5218 	u32 vr_hot_gpio;
5219 
5220 	si_populate_smc_voltage_tables(adev, table);
5221 
5222 	switch (adev->pm.int_thermal_type) {
5223 	case THERMAL_TYPE_SI:
5224 	case THERMAL_TYPE_EMC2103_WITH_INTERNAL:
5225 		table->thermalProtectType = PPSMC_THERMAL_PROTECT_TYPE_INTERNAL;
5226 		break;
5227 	case THERMAL_TYPE_NONE:
5228 		table->thermalProtectType = PPSMC_THERMAL_PROTECT_TYPE_NONE;
5229 		break;
5230 	default:
5231 		table->thermalProtectType = PPSMC_THERMAL_PROTECT_TYPE_EXTERNAL;
5232 		break;
5233 	}
5234 
5235 	if (adev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_HARDWAREDC)
5236 		table->systemFlags |= PPSMC_SYSTEMFLAG_GPIO_DC;
5237 
5238 	if (adev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_REGULATOR_HOT) {
5239 		if ((adev->pdev->device != 0x6818) && (adev->pdev->device != 0x6819))
5240 			table->systemFlags |= PPSMC_SYSTEMFLAG_REGULATOR_HOT;
5241 	}
5242 
5243 	if (adev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_STEPVDDC)
5244 		table->systemFlags |= PPSMC_SYSTEMFLAG_STEPVDDC;
5245 
5246 	if (adev->gmc.vram_type == AMDGPU_VRAM_TYPE_GDDR5)
5247 		table->systemFlags |= PPSMC_SYSTEMFLAG_GDDR5;
5248 
5249 	if (adev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_REVERT_GPIO5_POLARITY)
5250 		table->extraFlags |= PPSMC_EXTRAFLAGS_AC2DC_GPIO5_POLARITY_HIGH;
5251 
5252 	if (adev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_VRHOT_GPIO_CONFIGURABLE) {
5253 		table->systemFlags |= PPSMC_SYSTEMFLAG_REGULATOR_HOT_PROG_GPIO;
5254 		vr_hot_gpio = adev->pm.dpm.backbias_response_time;
5255 		si_write_smc_soft_register(adev, SI_SMC_SOFT_REGISTER_vr_hot_gpio,
5256 					   vr_hot_gpio);
5257 	}
5258 
5259 	ret = si_populate_smc_initial_state(adev, amdgpu_boot_state, table);
5260 	if (ret)
5261 		return ret;
5262 
5263 	ret = si_populate_smc_acpi_state(adev, table);
5264 	if (ret)
5265 		return ret;
5266 
5267 	table->driverState.flags = table->initialState.flags;
5268 	table->driverState.levelCount = table->initialState.levelCount;
5269 	table->driverState.levels[0] = table->initialState.level;
5270 
5271 	ret = si_do_program_memory_timing_parameters(adev, amdgpu_boot_state,
5272 						     SISLANDS_INITIAL_STATE_ARB_INDEX);
5273 	if (ret)
5274 		return ret;
5275 
5276 	if (ulv->supported && ulv->pl.vddc) {
5277 		ret = si_populate_ulv_state(adev, &table->ULVState);
5278 		if (ret)
5279 			return ret;
5280 
5281 		ret = si_program_ulv_memory_timing_parameters(adev);
5282 		if (ret)
5283 			return ret;
5284 
5285 		WREG32(CG_ULV_CONTROL, ulv->cg_ulv_control);
5286 		WREG32(CG_ULV_PARAMETER, ulv->cg_ulv_parameter);
5287 
5288 		lane_width = amdgpu_get_pcie_lanes(adev);
5289 		si_write_smc_soft_register(adev, SI_SMC_SOFT_REGISTER_non_ulv_pcie_link_width, lane_width);
5290 	} else {
5291 		table->ULVState = table->initialState;
5292 	}
5293 
5294 	return amdgpu_si_copy_bytes_to_smc(adev, si_pi->state_table_start,
5295 					   (u8 *)table, sizeof(SISLANDS_SMC_STATETABLE),
5296 					   si_pi->sram_end);
5297 }
5298 
5299 static int si_calculate_sclk_params(struct amdgpu_device *adev,
5300 				    u32 engine_clock,
5301 				    SISLANDS_SMC_SCLK_VALUE *sclk)
5302 {
5303 	struct rv7xx_power_info *pi = rv770_get_pi(adev);
5304 	struct si_power_info *si_pi = si_get_pi(adev);
5305 	struct atom_clock_dividers dividers;
5306 	u32 spll_func_cntl = si_pi->clock_registers.cg_spll_func_cntl;
5307 	u32 spll_func_cntl_2 = si_pi->clock_registers.cg_spll_func_cntl_2;
5308 	u32 spll_func_cntl_3 = si_pi->clock_registers.cg_spll_func_cntl_3;
5309 	u32 spll_func_cntl_4 = si_pi->clock_registers.cg_spll_func_cntl_4;
5310 	u32 cg_spll_spread_spectrum = si_pi->clock_registers.cg_spll_spread_spectrum;
5311 	u32 cg_spll_spread_spectrum_2 = si_pi->clock_registers.cg_spll_spread_spectrum_2;
5312 	u64 tmp;
5313 	u32 reference_clock = adev->clock.spll.reference_freq;
5314 	u32 reference_divider;
5315 	u32 fbdiv;
5316 	int ret;
5317 
5318 	ret = amdgpu_atombios_get_clock_dividers(adev, COMPUTE_ENGINE_PLL_PARAM,
5319 					     engine_clock, false, &dividers);
5320 	if (ret)
5321 		return ret;
5322 
5323 	reference_divider = 1 + dividers.ref_div;
5324 
5325 	tmp = (u64) engine_clock * reference_divider * dividers.post_div * 16384;
5326 	do_div(tmp, reference_clock);
5327 	fbdiv = (u32) tmp;
5328 
5329 	spll_func_cntl &= ~(SPLL_PDIV_A_MASK | SPLL_REF_DIV_MASK);
5330 	spll_func_cntl |= SPLL_REF_DIV(dividers.ref_div);
5331 	spll_func_cntl |= SPLL_PDIV_A(dividers.post_div);
5332 
5333 	spll_func_cntl_2 &= ~SCLK_MUX_SEL_MASK;
5334 	spll_func_cntl_2 |= SCLK_MUX_SEL(2);
5335 
5336 	spll_func_cntl_3 &= ~SPLL_FB_DIV_MASK;
5337 	spll_func_cntl_3 |= SPLL_FB_DIV(fbdiv);
5338 	spll_func_cntl_3 |= SPLL_DITHEN;
5339 
5340 	if (pi->sclk_ss) {
5341 		struct amdgpu_atom_ss ss;
5342 		u32 vco_freq = engine_clock * dividers.post_div;
5343 
5344 		if (amdgpu_atombios_get_asic_ss_info(adev, &ss,
5345 						     ASIC_INTERNAL_ENGINE_SS, vco_freq)) {
5346 			u32 clk_s = reference_clock * 5 / (reference_divider * ss.rate);
5347 			u32 clk_v = 4 * ss.percentage * fbdiv / (clk_s * 10000);
5348 
5349 			cg_spll_spread_spectrum &= ~CLK_S_MASK;
5350 			cg_spll_spread_spectrum |= CLK_S(clk_s);
5351 			cg_spll_spread_spectrum |= SSEN;
5352 
5353 			cg_spll_spread_spectrum_2 &= ~CLK_V_MASK;
5354 			cg_spll_spread_spectrum_2 |= CLK_V(clk_v);
5355 		}
5356 	}
5357 
5358 	sclk->sclk_value = engine_clock;
5359 	sclk->vCG_SPLL_FUNC_CNTL = spll_func_cntl;
5360 	sclk->vCG_SPLL_FUNC_CNTL_2 = spll_func_cntl_2;
5361 	sclk->vCG_SPLL_FUNC_CNTL_3 = spll_func_cntl_3;
5362 	sclk->vCG_SPLL_FUNC_CNTL_4 = spll_func_cntl_4;
5363 	sclk->vCG_SPLL_SPREAD_SPECTRUM = cg_spll_spread_spectrum;
5364 	sclk->vCG_SPLL_SPREAD_SPECTRUM_2 = cg_spll_spread_spectrum_2;
5365 
5366 	return 0;
5367 }
5368 
5369 static int si_populate_sclk_value(struct amdgpu_device *adev,
5370 				  u32 engine_clock,
5371 				  SISLANDS_SMC_SCLK_VALUE *sclk)
5372 {
5373 	SISLANDS_SMC_SCLK_VALUE sclk_tmp;
5374 	int ret;
5375 
5376 	ret = si_calculate_sclk_params(adev, engine_clock, &sclk_tmp);
5377 	if (!ret) {
5378 		sclk->sclk_value = cpu_to_be32(sclk_tmp.sclk_value);
5379 		sclk->vCG_SPLL_FUNC_CNTL = cpu_to_be32(sclk_tmp.vCG_SPLL_FUNC_CNTL);
5380 		sclk->vCG_SPLL_FUNC_CNTL_2 = cpu_to_be32(sclk_tmp.vCG_SPLL_FUNC_CNTL_2);
5381 		sclk->vCG_SPLL_FUNC_CNTL_3 = cpu_to_be32(sclk_tmp.vCG_SPLL_FUNC_CNTL_3);
5382 		sclk->vCG_SPLL_FUNC_CNTL_4 = cpu_to_be32(sclk_tmp.vCG_SPLL_FUNC_CNTL_4);
5383 		sclk->vCG_SPLL_SPREAD_SPECTRUM = cpu_to_be32(sclk_tmp.vCG_SPLL_SPREAD_SPECTRUM);
5384 		sclk->vCG_SPLL_SPREAD_SPECTRUM_2 = cpu_to_be32(sclk_tmp.vCG_SPLL_SPREAD_SPECTRUM_2);
5385 	}
5386 
5387 	return ret;
5388 }
5389 
5390 static int si_populate_mclk_value(struct amdgpu_device *adev,
5391 				  u32 engine_clock,
5392 				  u32 memory_clock,
5393 				  SISLANDS_SMC_MCLK_VALUE *mclk,
5394 				  bool strobe_mode,
5395 				  bool dll_state_on)
5396 {
5397 	struct rv7xx_power_info *pi = rv770_get_pi(adev);
5398 	struct si_power_info *si_pi = si_get_pi(adev);
5399 	u32  dll_cntl = si_pi->clock_registers.dll_cntl;
5400 	u32  mclk_pwrmgt_cntl = si_pi->clock_registers.mclk_pwrmgt_cntl;
5401 	u32  mpll_ad_func_cntl = si_pi->clock_registers.mpll_ad_func_cntl;
5402 	u32  mpll_dq_func_cntl = si_pi->clock_registers.mpll_dq_func_cntl;
5403 	u32  mpll_func_cntl = si_pi->clock_registers.mpll_func_cntl;
5404 	u32  mpll_func_cntl_1 = si_pi->clock_registers.mpll_func_cntl_1;
5405 	u32  mpll_func_cntl_2 = si_pi->clock_registers.mpll_func_cntl_2;
5406 	u32  mpll_ss1 = si_pi->clock_registers.mpll_ss1;
5407 	u32  mpll_ss2 = si_pi->clock_registers.mpll_ss2;
5408 	struct atom_mpll_param mpll_param;
5409 	int ret;
5410 
5411 	ret = amdgpu_atombios_get_memory_pll_dividers(adev, memory_clock, strobe_mode, &mpll_param);
5412 	if (ret)
5413 		return ret;
5414 
5415 	mpll_func_cntl &= ~BWCTRL_MASK;
5416 	mpll_func_cntl |= BWCTRL(mpll_param.bwcntl);
5417 
5418 	mpll_func_cntl_1 &= ~(CLKF_MASK | CLKFRAC_MASK | VCO_MODE_MASK);
5419 	mpll_func_cntl_1 |= CLKF(mpll_param.clkf) |
5420 		CLKFRAC(mpll_param.clkfrac) | VCO_MODE(mpll_param.vco_mode);
5421 
5422 	mpll_ad_func_cntl &= ~YCLK_POST_DIV_MASK;
5423 	mpll_ad_func_cntl |= YCLK_POST_DIV(mpll_param.post_div);
5424 
5425 	if (adev->gmc.vram_type == AMDGPU_VRAM_TYPE_GDDR5) {
5426 		mpll_dq_func_cntl &= ~(YCLK_SEL_MASK | YCLK_POST_DIV_MASK);
5427 		mpll_dq_func_cntl |= YCLK_SEL(mpll_param.yclk_sel) |
5428 			YCLK_POST_DIV(mpll_param.post_div);
5429 	}
5430 
5431 	if (pi->mclk_ss) {
5432 		struct amdgpu_atom_ss ss;
5433 		u32 freq_nom;
5434 		u32 tmp;
5435 		u32 reference_clock = adev->clock.mpll.reference_freq;
5436 
5437 		if (adev->gmc.vram_type == AMDGPU_VRAM_TYPE_GDDR5)
5438 			freq_nom = memory_clock * 4;
5439 		else
5440 			freq_nom = memory_clock * 2;
5441 
5442 		tmp = freq_nom / reference_clock;
5443 		tmp = tmp * tmp;
5444 		if (amdgpu_atombios_get_asic_ss_info(adev, &ss,
5445 		                                     ASIC_INTERNAL_MEMORY_SS, freq_nom)) {
5446 			u32 clks = reference_clock * 5 / ss.rate;
5447 			u32 clkv = (u32)((((131 * ss.percentage * ss.rate) / 100) * tmp) / freq_nom);
5448 
5449 		        mpll_ss1 &= ~CLKV_MASK;
5450 		        mpll_ss1 |= CLKV(clkv);
5451 
5452 		        mpll_ss2 &= ~CLKS_MASK;
5453 		        mpll_ss2 |= CLKS(clks);
5454 		}
5455 	}
5456 
5457 	mclk_pwrmgt_cntl &= ~DLL_SPEED_MASK;
5458 	mclk_pwrmgt_cntl |= DLL_SPEED(mpll_param.dll_speed);
5459 
5460 	if (dll_state_on)
5461 		mclk_pwrmgt_cntl |= MRDCK0_PDNB | MRDCK1_PDNB;
5462 	else
5463 		mclk_pwrmgt_cntl &= ~(MRDCK0_PDNB | MRDCK1_PDNB);
5464 
5465 	mclk->mclk_value = cpu_to_be32(memory_clock);
5466 	mclk->vMPLL_FUNC_CNTL = cpu_to_be32(mpll_func_cntl);
5467 	mclk->vMPLL_FUNC_CNTL_1 = cpu_to_be32(mpll_func_cntl_1);
5468 	mclk->vMPLL_FUNC_CNTL_2 = cpu_to_be32(mpll_func_cntl_2);
5469 	mclk->vMPLL_AD_FUNC_CNTL = cpu_to_be32(mpll_ad_func_cntl);
5470 	mclk->vMPLL_DQ_FUNC_CNTL = cpu_to_be32(mpll_dq_func_cntl);
5471 	mclk->vMCLK_PWRMGT_CNTL = cpu_to_be32(mclk_pwrmgt_cntl);
5472 	mclk->vDLL_CNTL = cpu_to_be32(dll_cntl);
5473 	mclk->vMPLL_SS = cpu_to_be32(mpll_ss1);
5474 	mclk->vMPLL_SS2 = cpu_to_be32(mpll_ss2);
5475 
5476 	return 0;
5477 }
5478 
5479 static void si_populate_smc_sp(struct amdgpu_device *adev,
5480 			       struct amdgpu_ps *amdgpu_state,
5481 			       SISLANDS_SMC_SWSTATE *smc_state)
5482 {
5483 	struct  si_ps *ps = si_get_ps(amdgpu_state);
5484 	struct rv7xx_power_info *pi = rv770_get_pi(adev);
5485 	int i;
5486 
5487 	for (i = 0; i < ps->performance_level_count - 1; i++)
5488 		smc_state->levels[i].bSP = cpu_to_be32(pi->dsp);
5489 
5490 	smc_state->levels[ps->performance_level_count - 1].bSP =
5491 		cpu_to_be32(pi->psp);
5492 }
5493 
5494 static int si_convert_power_level_to_smc(struct amdgpu_device *adev,
5495 					 struct rv7xx_pl *pl,
5496 					 SISLANDS_SMC_HW_PERFORMANCE_LEVEL *level)
5497 {
5498 	struct rv7xx_power_info *pi = rv770_get_pi(adev);
5499 	struct evergreen_power_info *eg_pi = evergreen_get_pi(adev);
5500 	struct si_power_info *si_pi = si_get_pi(adev);
5501 	int ret;
5502 	bool dll_state_on;
5503 	u16 std_vddc;
5504 	bool gmc_pg = false;
5505 
5506 	if (eg_pi->pcie_performance_request &&
5507 	    (si_pi->force_pcie_gen != SI_PCIE_GEN_INVALID))
5508 		level->gen2PCIE = (u8)si_pi->force_pcie_gen;
5509 	else
5510 		level->gen2PCIE = (u8)pl->pcie_gen;
5511 
5512 	ret = si_populate_sclk_value(adev, pl->sclk, &level->sclk);
5513 	if (ret)
5514 		return ret;
5515 
5516 	level->mcFlags =  0;
5517 
5518 	if (pi->mclk_stutter_mode_threshold &&
5519 	    (pl->mclk <= pi->mclk_stutter_mode_threshold) &&
5520 	    !eg_pi->uvd_enabled &&
5521 	    (RREG32(DPG_PIPE_STUTTER_CONTROL) & STUTTER_ENABLE) &&
5522 	    (adev->pm.dpm.new_active_crtc_count <= 2)) {
5523 		level->mcFlags |= SISLANDS_SMC_MC_STUTTER_EN;
5524 
5525 		if (gmc_pg)
5526 			level->mcFlags |= SISLANDS_SMC_MC_PG_EN;
5527 	}
5528 
5529 	if (adev->gmc.vram_type == AMDGPU_VRAM_TYPE_GDDR5) {
5530 		if (pl->mclk > pi->mclk_edc_enable_threshold)
5531 			level->mcFlags |= SISLANDS_SMC_MC_EDC_RD_FLAG;
5532 
5533 		if (pl->mclk > eg_pi->mclk_edc_wr_enable_threshold)
5534 			level->mcFlags |= SISLANDS_SMC_MC_EDC_WR_FLAG;
5535 
5536 		level->strobeMode = si_get_strobe_mode_settings(adev, pl->mclk);
5537 
5538 		if (level->strobeMode & SISLANDS_SMC_STROBE_ENABLE) {
5539 			if (si_get_mclk_frequency_ratio(pl->mclk, true) >=
5540 			    ((RREG32(MC_SEQ_MISC7) >> 16) & 0xf))
5541 				dll_state_on = ((RREG32(MC_SEQ_MISC5) >> 1) & 0x1) ? true : false;
5542 			else
5543 				dll_state_on = ((RREG32(MC_SEQ_MISC6) >> 1) & 0x1) ? true : false;
5544 		} else {
5545 			dll_state_on = false;
5546 		}
5547 	} else {
5548 		level->strobeMode = si_get_strobe_mode_settings(adev,
5549 								pl->mclk);
5550 
5551 		dll_state_on = ((RREG32(MC_SEQ_MISC5) >> 1) & 0x1) ? true : false;
5552 	}
5553 
5554 	ret = si_populate_mclk_value(adev,
5555 				     pl->sclk,
5556 				     pl->mclk,
5557 				     &level->mclk,
5558 				     (level->strobeMode & SISLANDS_SMC_STROBE_ENABLE) != 0, dll_state_on);
5559 	if (ret)
5560 		return ret;
5561 
5562 	ret = si_populate_voltage_value(adev,
5563 					&eg_pi->vddc_voltage_table,
5564 					pl->vddc, &level->vddc);
5565 	if (ret)
5566 		return ret;
5567 
5568 
5569 	ret = si_get_std_voltage_value(adev, &level->vddc, &std_vddc);
5570 	if (ret)
5571 		return ret;
5572 
5573 	ret = si_populate_std_voltage_value(adev, std_vddc,
5574 					    level->vddc.index, &level->std_vddc);
5575 	if (ret)
5576 		return ret;
5577 
5578 	if (eg_pi->vddci_control) {
5579 		ret = si_populate_voltage_value(adev, &eg_pi->vddci_voltage_table,
5580 						pl->vddci, &level->vddci);
5581 		if (ret)
5582 			return ret;
5583 	}
5584 
5585 	if (si_pi->vddc_phase_shed_control) {
5586 		ret = si_populate_phase_shedding_value(adev,
5587 						       &adev->pm.dpm.dyn_state.phase_shedding_limits_table,
5588 						       pl->vddc,
5589 						       pl->sclk,
5590 						       pl->mclk,
5591 						       &level->vddc);
5592 		if (ret)
5593 			return ret;
5594 	}
5595 
5596 	level->MaxPoweredUpCU = si_pi->max_cu;
5597 
5598 	ret = si_populate_mvdd_value(adev, pl->mclk, &level->mvdd);
5599 
5600 	return ret;
5601 }
5602 
5603 static int si_populate_smc_t(struct amdgpu_device *adev,
5604 			     struct amdgpu_ps *amdgpu_state,
5605 			     SISLANDS_SMC_SWSTATE *smc_state)
5606 {
5607 	struct rv7xx_power_info *pi = rv770_get_pi(adev);
5608 	struct  si_ps *state = si_get_ps(amdgpu_state);
5609 	u32 a_t;
5610 	u32 t_l, t_h;
5611 	u32 high_bsp;
5612 	int i, ret;
5613 
5614 	if (state->performance_level_count >= 9)
5615 		return -EINVAL;
5616 
5617 	if (state->performance_level_count < 2) {
5618 		a_t = CG_R(0xffff) | CG_L(0);
5619 		smc_state->levels[0].aT = cpu_to_be32(a_t);
5620 		return 0;
5621 	}
5622 
5623 	smc_state->levels[0].aT = cpu_to_be32(0);
5624 
5625 	for (i = 0; i <= state->performance_level_count - 2; i++) {
5626 		ret = r600_calculate_at(
5627 			(50 / SISLANDS_MAX_HARDWARE_POWERLEVELS) * 100 * (i + 1),
5628 			100 * R600_AH_DFLT,
5629 			state->performance_levels[i + 1].sclk,
5630 			state->performance_levels[i].sclk,
5631 			&t_l,
5632 			&t_h);
5633 
5634 		if (ret) {
5635 			t_h = (i + 1) * 1000 - 50 * R600_AH_DFLT;
5636 			t_l = (i + 1) * 1000 + 50 * R600_AH_DFLT;
5637 		}
5638 
5639 		a_t = be32_to_cpu(smc_state->levels[i].aT) & ~CG_R_MASK;
5640 		a_t |= CG_R(t_l * pi->bsp / 20000);
5641 		smc_state->levels[i].aT = cpu_to_be32(a_t);
5642 
5643 		high_bsp = (i == state->performance_level_count - 2) ?
5644 			pi->pbsp : pi->bsp;
5645 		a_t = CG_R(0xffff) | CG_L(t_h * high_bsp / 20000);
5646 		smc_state->levels[i + 1].aT = cpu_to_be32(a_t);
5647 	}
5648 
5649 	return 0;
5650 }
5651 
5652 static int si_disable_ulv(struct amdgpu_device *adev)
5653 {
5654 	struct si_power_info *si_pi = si_get_pi(adev);
5655 	struct si_ulv_param *ulv = &si_pi->ulv;
5656 
5657 	if (ulv->supported)
5658 		return (amdgpu_si_send_msg_to_smc(adev, PPSMC_MSG_DisableULV) == PPSMC_Result_OK) ?
5659 			0 : -EINVAL;
5660 
5661 	return 0;
5662 }
5663 
5664 static bool si_is_state_ulv_compatible(struct amdgpu_device *adev,
5665 				       struct amdgpu_ps *amdgpu_state)
5666 {
5667 	const struct si_power_info *si_pi = si_get_pi(adev);
5668 	const struct si_ulv_param *ulv = &si_pi->ulv;
5669 	const struct  si_ps *state = si_get_ps(amdgpu_state);
5670 	int i;
5671 
5672 	if (state->performance_levels[0].mclk != ulv->pl.mclk)
5673 		return false;
5674 
5675 	/* XXX validate against display requirements! */
5676 
5677 	for (i = 0; i < adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.count; i++) {
5678 		if (adev->clock.current_dispclk <=
5679 		    adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[i].clk) {
5680 			if (ulv->pl.vddc <
5681 			    adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[i].v)
5682 				return false;
5683 		}
5684 	}
5685 
5686 	if ((amdgpu_state->vclk != 0) || (amdgpu_state->dclk != 0))
5687 		return false;
5688 
5689 	return true;
5690 }
5691 
5692 static int si_set_power_state_conditionally_enable_ulv(struct amdgpu_device *adev,
5693 						       struct amdgpu_ps *amdgpu_new_state)
5694 {
5695 	const struct si_power_info *si_pi = si_get_pi(adev);
5696 	const struct si_ulv_param *ulv = &si_pi->ulv;
5697 
5698 	if (ulv->supported) {
5699 		if (si_is_state_ulv_compatible(adev, amdgpu_new_state))
5700 			return (amdgpu_si_send_msg_to_smc(adev, PPSMC_MSG_EnableULV) == PPSMC_Result_OK) ?
5701 				0 : -EINVAL;
5702 	}
5703 	return 0;
5704 }
5705 
5706 static int si_convert_power_state_to_smc(struct amdgpu_device *adev,
5707 					 struct amdgpu_ps *amdgpu_state,
5708 					 SISLANDS_SMC_SWSTATE *smc_state)
5709 {
5710 	struct evergreen_power_info *eg_pi = evergreen_get_pi(adev);
5711 	struct ni_power_info *ni_pi = ni_get_pi(adev);
5712 	struct si_power_info *si_pi = si_get_pi(adev);
5713 	struct  si_ps *state = si_get_ps(amdgpu_state);
5714 	int i, ret;
5715 	u32 threshold;
5716 	u32 sclk_in_sr = 1350; /* ??? */
5717 
5718 	if (state->performance_level_count > SISLANDS_MAX_HARDWARE_POWERLEVELS)
5719 		return -EINVAL;
5720 
5721 	threshold = state->performance_levels[state->performance_level_count-1].sclk * 100 / 100;
5722 
5723 	if (amdgpu_state->vclk && amdgpu_state->dclk) {
5724 		eg_pi->uvd_enabled = true;
5725 		if (eg_pi->smu_uvd_hs)
5726 			smc_state->flags |= PPSMC_SWSTATE_FLAG_UVD;
5727 	} else {
5728 		eg_pi->uvd_enabled = false;
5729 	}
5730 
5731 	if (state->dc_compatible)
5732 		smc_state->flags |= PPSMC_SWSTATE_FLAG_DC;
5733 
5734 	smc_state->levelCount = 0;
5735 	for (i = 0; i < state->performance_level_count; i++) {
5736 		if (eg_pi->sclk_deep_sleep) {
5737 			if ((i == 0) || si_pi->sclk_deep_sleep_above_low) {
5738 				if (sclk_in_sr <= SCLK_MIN_DEEPSLEEP_FREQ)
5739 					smc_state->levels[i].stateFlags |= PPSMC_STATEFLAG_DEEPSLEEP_BYPASS;
5740 				else
5741 					smc_state->levels[i].stateFlags |= PPSMC_STATEFLAG_DEEPSLEEP_THROTTLE;
5742 			}
5743 		}
5744 
5745 		ret = si_convert_power_level_to_smc(adev, &state->performance_levels[i],
5746 						    &smc_state->levels[i]);
5747 		smc_state->levels[i].arbRefreshState =
5748 			(u8)(SISLANDS_DRIVER_STATE_ARB_INDEX + i);
5749 
5750 		if (ret)
5751 			return ret;
5752 
5753 		if (ni_pi->enable_power_containment)
5754 			smc_state->levels[i].displayWatermark =
5755 				(state->performance_levels[i].sclk < threshold) ?
5756 				PPSMC_DISPLAY_WATERMARK_LOW : PPSMC_DISPLAY_WATERMARK_HIGH;
5757 		else
5758 			smc_state->levels[i].displayWatermark = (i < 2) ?
5759 				PPSMC_DISPLAY_WATERMARK_LOW : PPSMC_DISPLAY_WATERMARK_HIGH;
5760 
5761 		if (eg_pi->dynamic_ac_timing)
5762 			smc_state->levels[i].ACIndex = SISLANDS_MCREGISTERTABLE_FIRST_DRIVERSTATE_SLOT + i;
5763 		else
5764 			smc_state->levels[i].ACIndex = 0;
5765 
5766 		smc_state->levelCount++;
5767 	}
5768 
5769 	si_write_smc_soft_register(adev,
5770 				   SI_SMC_SOFT_REGISTER_watermark_threshold,
5771 				   threshold / 512);
5772 
5773 	si_populate_smc_sp(adev, amdgpu_state, smc_state);
5774 
5775 	ret = si_populate_power_containment_values(adev, amdgpu_state, smc_state);
5776 	if (ret)
5777 		ni_pi->enable_power_containment = false;
5778 
5779 	ret = si_populate_sq_ramping_values(adev, amdgpu_state, smc_state);
5780 	if (ret)
5781 		ni_pi->enable_sq_ramping = false;
5782 
5783 	return si_populate_smc_t(adev, amdgpu_state, smc_state);
5784 }
5785 
5786 static int si_upload_sw_state(struct amdgpu_device *adev,
5787 			      struct amdgpu_ps *amdgpu_new_state)
5788 {
5789 	struct si_power_info *si_pi = si_get_pi(adev);
5790 	struct  si_ps *new_state = si_get_ps(amdgpu_new_state);
5791 	int ret;
5792 	u32 address = si_pi->state_table_start +
5793 		offsetof(SISLANDS_SMC_STATETABLE, driverState);
5794 	SISLANDS_SMC_SWSTATE *smc_state = &si_pi->smc_statetable.driverState;
5795 	size_t state_size = struct_size(smc_state, levels,
5796 					new_state->performance_level_count);
5797 	memset(smc_state, 0, state_size);
5798 
5799 	ret = si_convert_power_state_to_smc(adev, amdgpu_new_state, smc_state);
5800 	if (ret)
5801 		return ret;
5802 
5803 	return amdgpu_si_copy_bytes_to_smc(adev, address, (u8 *)smc_state,
5804 					   state_size, si_pi->sram_end);
5805 }
5806 
5807 static int si_upload_ulv_state(struct amdgpu_device *adev)
5808 {
5809 	struct si_power_info *si_pi = si_get_pi(adev);
5810 	struct si_ulv_param *ulv = &si_pi->ulv;
5811 	int ret = 0;
5812 
5813 	if (ulv->supported && ulv->pl.vddc) {
5814 		u32 address = si_pi->state_table_start +
5815 			offsetof(SISLANDS_SMC_STATETABLE, ULVState);
5816 		struct SISLANDS_SMC_SWSTATE_SINGLE *smc_state = &si_pi->smc_statetable.ULVState;
5817 		u32 state_size = sizeof(struct SISLANDS_SMC_SWSTATE_SINGLE);
5818 
5819 		memset(smc_state, 0, state_size);
5820 
5821 		ret = si_populate_ulv_state(adev, smc_state);
5822 		if (!ret)
5823 			ret = amdgpu_si_copy_bytes_to_smc(adev, address, (u8 *)smc_state,
5824 							  state_size, si_pi->sram_end);
5825 	}
5826 
5827 	return ret;
5828 }
5829 
5830 static int si_upload_smc_data(struct amdgpu_device *adev)
5831 {
5832 	struct amdgpu_crtc *amdgpu_crtc = NULL;
5833 	int i;
5834 
5835 	if (adev->pm.dpm.new_active_crtc_count == 0)
5836 		return 0;
5837 
5838 	for (i = 0; i < adev->mode_info.num_crtc; i++) {
5839 		if (adev->pm.dpm.new_active_crtcs & (1 << i)) {
5840 			amdgpu_crtc = adev->mode_info.crtcs[i];
5841 			break;
5842 		}
5843 	}
5844 
5845 	if (amdgpu_crtc == NULL)
5846 		return 0;
5847 
5848 	if (amdgpu_crtc->line_time <= 0)
5849 		return 0;
5850 
5851 	if (si_write_smc_soft_register(adev,
5852 				       SI_SMC_SOFT_REGISTER_crtc_index,
5853 				       amdgpu_crtc->crtc_id) != PPSMC_Result_OK)
5854 		return 0;
5855 
5856 	if (si_write_smc_soft_register(adev,
5857 				       SI_SMC_SOFT_REGISTER_mclk_change_block_cp_min,
5858 				       amdgpu_crtc->wm_high / amdgpu_crtc->line_time) != PPSMC_Result_OK)
5859 		return 0;
5860 
5861 	if (si_write_smc_soft_register(adev,
5862 				       SI_SMC_SOFT_REGISTER_mclk_change_block_cp_max,
5863 				       amdgpu_crtc->wm_low / amdgpu_crtc->line_time) != PPSMC_Result_OK)
5864 		return 0;
5865 
5866 	return 0;
5867 }
5868 
5869 static int si_set_mc_special_registers(struct amdgpu_device *adev,
5870 				       struct si_mc_reg_table *table)
5871 {
5872 	u8 i, j, k;
5873 	u32 temp_reg;
5874 
5875 	for (i = 0, j = table->last; i < table->last; i++) {
5876 		if (j >= SMC_SISLANDS_MC_REGISTER_ARRAY_SIZE)
5877 			return -EINVAL;
5878 		switch (table->mc_reg_address[i].s1) {
5879 		case MC_SEQ_MISC1:
5880 			temp_reg = RREG32(MC_PMG_CMD_EMRS);
5881 			table->mc_reg_address[j].s1 = MC_PMG_CMD_EMRS;
5882 			table->mc_reg_address[j].s0 = MC_SEQ_PMG_CMD_EMRS_LP;
5883 			for (k = 0; k < table->num_entries; k++)
5884 				table->mc_reg_table_entry[k].mc_data[j] =
5885 					((temp_reg & 0xffff0000)) |
5886 					((table->mc_reg_table_entry[k].mc_data[i] & 0xffff0000) >> 16);
5887 			j++;
5888 
5889 			if (j >= SMC_SISLANDS_MC_REGISTER_ARRAY_SIZE)
5890 				return -EINVAL;
5891 			temp_reg = RREG32(MC_PMG_CMD_MRS);
5892 			table->mc_reg_address[j].s1 = MC_PMG_CMD_MRS;
5893 			table->mc_reg_address[j].s0 = MC_SEQ_PMG_CMD_MRS_LP;
5894 			for (k = 0; k < table->num_entries; k++) {
5895 				table->mc_reg_table_entry[k].mc_data[j] =
5896 					(temp_reg & 0xffff0000) |
5897 					(table->mc_reg_table_entry[k].mc_data[i] & 0x0000ffff);
5898 				if (adev->gmc.vram_type != AMDGPU_VRAM_TYPE_GDDR5)
5899 					table->mc_reg_table_entry[k].mc_data[j] |= 0x100;
5900 			}
5901 			j++;
5902 
5903 			if (adev->gmc.vram_type != AMDGPU_VRAM_TYPE_GDDR5) {
5904 				if (j >= SMC_SISLANDS_MC_REGISTER_ARRAY_SIZE)
5905 					return -EINVAL;
5906 				table->mc_reg_address[j].s1 = MC_PMG_AUTO_CMD;
5907 				table->mc_reg_address[j].s0 = MC_PMG_AUTO_CMD;
5908 				for (k = 0; k < table->num_entries; k++)
5909 					table->mc_reg_table_entry[k].mc_data[j] =
5910 						(table->mc_reg_table_entry[k].mc_data[i] & 0xffff0000) >> 16;
5911 				j++;
5912 			}
5913 			break;
5914 		case MC_SEQ_RESERVE_M:
5915 			temp_reg = RREG32(MC_PMG_CMD_MRS1);
5916 			table->mc_reg_address[j].s1 = MC_PMG_CMD_MRS1;
5917 			table->mc_reg_address[j].s0 = MC_SEQ_PMG_CMD_MRS1_LP;
5918 			for(k = 0; k < table->num_entries; k++)
5919 				table->mc_reg_table_entry[k].mc_data[j] =
5920 					(temp_reg & 0xffff0000) |
5921 					(table->mc_reg_table_entry[k].mc_data[i] & 0x0000ffff);
5922 			j++;
5923 			break;
5924 		default:
5925 			break;
5926 		}
5927 	}
5928 
5929 	table->last = j;
5930 
5931 	return 0;
5932 }
5933 
5934 static bool si_check_s0_mc_reg_index(u16 in_reg, u16 *out_reg)
5935 {
5936 	bool result = true;
5937 	switch (in_reg) {
5938 	case  MC_SEQ_RAS_TIMING:
5939 		*out_reg = MC_SEQ_RAS_TIMING_LP;
5940 		break;
5941 	case MC_SEQ_CAS_TIMING:
5942 		*out_reg = MC_SEQ_CAS_TIMING_LP;
5943 		break;
5944 	case MC_SEQ_MISC_TIMING:
5945 		*out_reg = MC_SEQ_MISC_TIMING_LP;
5946 		break;
5947 	case MC_SEQ_MISC_TIMING2:
5948 		*out_reg = MC_SEQ_MISC_TIMING2_LP;
5949 		break;
5950 	case MC_SEQ_RD_CTL_D0:
5951 		*out_reg = MC_SEQ_RD_CTL_D0_LP;
5952 		break;
5953 	case MC_SEQ_RD_CTL_D1:
5954 		*out_reg = MC_SEQ_RD_CTL_D1_LP;
5955 		break;
5956 	case MC_SEQ_WR_CTL_D0:
5957 		*out_reg = MC_SEQ_WR_CTL_D0_LP;
5958 		break;
5959 	case MC_SEQ_WR_CTL_D1:
5960 		*out_reg = MC_SEQ_WR_CTL_D1_LP;
5961 		break;
5962 	case MC_PMG_CMD_EMRS:
5963 		*out_reg = MC_SEQ_PMG_CMD_EMRS_LP;
5964 		break;
5965 	case MC_PMG_CMD_MRS:
5966 		*out_reg = MC_SEQ_PMG_CMD_MRS_LP;
5967 		break;
5968 	case MC_PMG_CMD_MRS1:
5969 		*out_reg = MC_SEQ_PMG_CMD_MRS1_LP;
5970 		break;
5971 	case MC_SEQ_PMG_TIMING:
5972 		*out_reg = MC_SEQ_PMG_TIMING_LP;
5973 		break;
5974 	case MC_PMG_CMD_MRS2:
5975 		*out_reg = MC_SEQ_PMG_CMD_MRS2_LP;
5976 		break;
5977 	case MC_SEQ_WR_CTL_2:
5978 		*out_reg = MC_SEQ_WR_CTL_2_LP;
5979 		break;
5980 	default:
5981 		result = false;
5982 		break;
5983 	}
5984 
5985 	return result;
5986 }
5987 
5988 static void si_set_valid_flag(struct si_mc_reg_table *table)
5989 {
5990 	u8 i, j;
5991 
5992 	for (i = 0; i < table->last; i++) {
5993 		for (j = 1; j < table->num_entries; j++) {
5994 			if (table->mc_reg_table_entry[j-1].mc_data[i] != table->mc_reg_table_entry[j].mc_data[i]) {
5995 				table->valid_flag |= 1 << i;
5996 				break;
5997 			}
5998 		}
5999 	}
6000 }
6001 
6002 static void si_set_s0_mc_reg_index(struct si_mc_reg_table *table)
6003 {
6004 	u32 i;
6005 	u16 address;
6006 
6007 	for (i = 0; i < table->last; i++)
6008 		table->mc_reg_address[i].s0 = si_check_s0_mc_reg_index(table->mc_reg_address[i].s1, &address) ?
6009 			address : table->mc_reg_address[i].s1;
6010 
6011 }
6012 
6013 static int si_copy_vbios_mc_reg_table(struct atom_mc_reg_table *table,
6014 				      struct si_mc_reg_table *si_table)
6015 {
6016 	u8 i, j;
6017 
6018 	if (table->last > SMC_SISLANDS_MC_REGISTER_ARRAY_SIZE)
6019 		return -EINVAL;
6020 	if (table->num_entries > MAX_AC_TIMING_ENTRIES)
6021 		return -EINVAL;
6022 
6023 	for (i = 0; i < table->last; i++)
6024 		si_table->mc_reg_address[i].s1 = table->mc_reg_address[i].s1;
6025 	si_table->last = table->last;
6026 
6027 	for (i = 0; i < table->num_entries; i++) {
6028 		si_table->mc_reg_table_entry[i].mclk_max =
6029 			table->mc_reg_table_entry[i].mclk_max;
6030 		for (j = 0; j < table->last; j++) {
6031 			si_table->mc_reg_table_entry[i].mc_data[j] =
6032 				table->mc_reg_table_entry[i].mc_data[j];
6033 		}
6034 	}
6035 	si_table->num_entries = table->num_entries;
6036 
6037 	return 0;
6038 }
6039 
6040 static int si_initialize_mc_reg_table(struct amdgpu_device *adev)
6041 {
6042 	struct si_power_info *si_pi = si_get_pi(adev);
6043 	struct atom_mc_reg_table *table;
6044 	struct si_mc_reg_table *si_table = &si_pi->mc_reg_table;
6045 	u8 module_index = rv770_get_memory_module_index(adev);
6046 	int ret;
6047 
6048 	table = kzalloc(sizeof(struct atom_mc_reg_table), GFP_KERNEL);
6049 	if (!table)
6050 		return -ENOMEM;
6051 
6052 	WREG32(MC_SEQ_RAS_TIMING_LP, RREG32(MC_SEQ_RAS_TIMING));
6053 	WREG32(MC_SEQ_CAS_TIMING_LP, RREG32(MC_SEQ_CAS_TIMING));
6054 	WREG32(MC_SEQ_MISC_TIMING_LP, RREG32(MC_SEQ_MISC_TIMING));
6055 	WREG32(MC_SEQ_MISC_TIMING2_LP, RREG32(MC_SEQ_MISC_TIMING2));
6056 	WREG32(MC_SEQ_PMG_CMD_EMRS_LP, RREG32(MC_PMG_CMD_EMRS));
6057 	WREG32(MC_SEQ_PMG_CMD_MRS_LP, RREG32(MC_PMG_CMD_MRS));
6058 	WREG32(MC_SEQ_PMG_CMD_MRS1_LP, RREG32(MC_PMG_CMD_MRS1));
6059 	WREG32(MC_SEQ_WR_CTL_D0_LP, RREG32(MC_SEQ_WR_CTL_D0));
6060 	WREG32(MC_SEQ_WR_CTL_D1_LP, RREG32(MC_SEQ_WR_CTL_D1));
6061 	WREG32(MC_SEQ_RD_CTL_D0_LP, RREG32(MC_SEQ_RD_CTL_D0));
6062 	WREG32(MC_SEQ_RD_CTL_D1_LP, RREG32(MC_SEQ_RD_CTL_D1));
6063 	WREG32(MC_SEQ_PMG_TIMING_LP, RREG32(MC_SEQ_PMG_TIMING));
6064 	WREG32(MC_SEQ_PMG_CMD_MRS2_LP, RREG32(MC_PMG_CMD_MRS2));
6065 	WREG32(MC_SEQ_WR_CTL_2_LP, RREG32(MC_SEQ_WR_CTL_2));
6066 
6067 	ret = amdgpu_atombios_init_mc_reg_table(adev, module_index, table);
6068 	if (ret)
6069 		goto init_mc_done;
6070 
6071 	ret = si_copy_vbios_mc_reg_table(table, si_table);
6072 	if (ret)
6073 		goto init_mc_done;
6074 
6075 	si_set_s0_mc_reg_index(si_table);
6076 
6077 	ret = si_set_mc_special_registers(adev, si_table);
6078 	if (ret)
6079 		goto init_mc_done;
6080 
6081 	si_set_valid_flag(si_table);
6082 
6083 init_mc_done:
6084 	kfree(table);
6085 
6086 	return ret;
6087 
6088 }
6089 
6090 static void si_populate_mc_reg_addresses(struct amdgpu_device *adev,
6091 					 SMC_SIslands_MCRegisters *mc_reg_table)
6092 {
6093 	struct si_power_info *si_pi = si_get_pi(adev);
6094 	u32 i, j;
6095 
6096 	for (i = 0, j = 0; j < si_pi->mc_reg_table.last; j++) {
6097 		if (si_pi->mc_reg_table.valid_flag & (1 << j)) {
6098 			if (i >= SMC_SISLANDS_MC_REGISTER_ARRAY_SIZE)
6099 				break;
6100 			mc_reg_table->address[i].s0 =
6101 				cpu_to_be16(si_pi->mc_reg_table.mc_reg_address[j].s0);
6102 			mc_reg_table->address[i].s1 =
6103 				cpu_to_be16(si_pi->mc_reg_table.mc_reg_address[j].s1);
6104 			i++;
6105 		}
6106 	}
6107 	mc_reg_table->last = (u8)i;
6108 }
6109 
6110 static void si_convert_mc_registers(const struct si_mc_reg_entry *entry,
6111 				    SMC_SIslands_MCRegisterSet *data,
6112 				    u32 num_entries, u32 valid_flag)
6113 {
6114 	u32 i, j;
6115 
6116 	for(i = 0, j = 0; j < num_entries; j++) {
6117 		if (valid_flag & (1 << j)) {
6118 			data->value[i] = cpu_to_be32(entry->mc_data[j]);
6119 			i++;
6120 		}
6121 	}
6122 }
6123 
6124 static void si_convert_mc_reg_table_entry_to_smc(struct amdgpu_device *adev,
6125 						 struct rv7xx_pl *pl,
6126 						 SMC_SIslands_MCRegisterSet *mc_reg_table_data)
6127 {
6128 	struct si_power_info *si_pi = si_get_pi(adev);
6129 	u32 i = 0;
6130 
6131 	for (i = 0; i < si_pi->mc_reg_table.num_entries; i++) {
6132 		if (pl->mclk <= si_pi->mc_reg_table.mc_reg_table_entry[i].mclk_max)
6133 			break;
6134 	}
6135 
6136 	if ((i == si_pi->mc_reg_table.num_entries) && (i > 0))
6137 		--i;
6138 
6139 	si_convert_mc_registers(&si_pi->mc_reg_table.mc_reg_table_entry[i],
6140 				mc_reg_table_data, si_pi->mc_reg_table.last,
6141 				si_pi->mc_reg_table.valid_flag);
6142 }
6143 
6144 static void si_convert_mc_reg_table_to_smc(struct amdgpu_device *adev,
6145 					   struct amdgpu_ps *amdgpu_state,
6146 					   SMC_SIslands_MCRegisters *mc_reg_table)
6147 {
6148 	struct si_ps *state = si_get_ps(amdgpu_state);
6149 	int i;
6150 
6151 	for (i = 0; i < state->performance_level_count; i++) {
6152 		si_convert_mc_reg_table_entry_to_smc(adev,
6153 						     &state->performance_levels[i],
6154 						     &mc_reg_table->data[SISLANDS_MCREGISTERTABLE_FIRST_DRIVERSTATE_SLOT + i]);
6155 	}
6156 }
6157 
6158 static int si_populate_mc_reg_table(struct amdgpu_device *adev,
6159 				    struct amdgpu_ps *amdgpu_boot_state)
6160 {
6161 	struct  si_ps *boot_state = si_get_ps(amdgpu_boot_state);
6162 	struct si_power_info *si_pi = si_get_pi(adev);
6163 	struct si_ulv_param *ulv = &si_pi->ulv;
6164 	SMC_SIslands_MCRegisters *smc_mc_reg_table = &si_pi->smc_mc_reg_table;
6165 
6166 	memset(smc_mc_reg_table, 0, sizeof(SMC_SIslands_MCRegisters));
6167 
6168 	si_write_smc_soft_register(adev, SI_SMC_SOFT_REGISTER_seq_index, 1);
6169 
6170 	si_populate_mc_reg_addresses(adev, smc_mc_reg_table);
6171 
6172 	si_convert_mc_reg_table_entry_to_smc(adev, &boot_state->performance_levels[0],
6173 					     &smc_mc_reg_table->data[SISLANDS_MCREGISTERTABLE_INITIAL_SLOT]);
6174 
6175 	si_convert_mc_registers(&si_pi->mc_reg_table.mc_reg_table_entry[0],
6176 				&smc_mc_reg_table->data[SISLANDS_MCREGISTERTABLE_ACPI_SLOT],
6177 				si_pi->mc_reg_table.last,
6178 				si_pi->mc_reg_table.valid_flag);
6179 
6180 	if (ulv->supported && ulv->pl.vddc != 0)
6181 		si_convert_mc_reg_table_entry_to_smc(adev, &ulv->pl,
6182 						     &smc_mc_reg_table->data[SISLANDS_MCREGISTERTABLE_ULV_SLOT]);
6183 	else
6184 		si_convert_mc_registers(&si_pi->mc_reg_table.mc_reg_table_entry[0],
6185 					&smc_mc_reg_table->data[SISLANDS_MCREGISTERTABLE_ULV_SLOT],
6186 					si_pi->mc_reg_table.last,
6187 					si_pi->mc_reg_table.valid_flag);
6188 
6189 	si_convert_mc_reg_table_to_smc(adev, amdgpu_boot_state, smc_mc_reg_table);
6190 
6191 	return amdgpu_si_copy_bytes_to_smc(adev, si_pi->mc_reg_table_start,
6192 					   (u8 *)smc_mc_reg_table,
6193 					   sizeof(SMC_SIslands_MCRegisters), si_pi->sram_end);
6194 }
6195 
6196 static int si_upload_mc_reg_table(struct amdgpu_device *adev,
6197 				  struct amdgpu_ps *amdgpu_new_state)
6198 {
6199 	struct si_ps *new_state = si_get_ps(amdgpu_new_state);
6200 	struct si_power_info *si_pi = si_get_pi(adev);
6201 	u32 address = si_pi->mc_reg_table_start +
6202 		offsetof(SMC_SIslands_MCRegisters,
6203 			 data[SISLANDS_MCREGISTERTABLE_FIRST_DRIVERSTATE_SLOT]);
6204 	SMC_SIslands_MCRegisters *smc_mc_reg_table = &si_pi->smc_mc_reg_table;
6205 
6206 	memset(smc_mc_reg_table, 0, sizeof(SMC_SIslands_MCRegisters));
6207 
6208 	si_convert_mc_reg_table_to_smc(adev, amdgpu_new_state, smc_mc_reg_table);
6209 
6210 	return amdgpu_si_copy_bytes_to_smc(adev, address,
6211 					   (u8 *)&smc_mc_reg_table->data[SISLANDS_MCREGISTERTABLE_FIRST_DRIVERSTATE_SLOT],
6212 					   sizeof(SMC_SIslands_MCRegisterSet) * new_state->performance_level_count,
6213 					   si_pi->sram_end);
6214 }
6215 
6216 static void si_enable_voltage_control(struct amdgpu_device *adev, bool enable)
6217 {
6218 	if (enable)
6219 		WREG32_P(GENERAL_PWRMGT, VOLT_PWRMGT_EN, ~VOLT_PWRMGT_EN);
6220 	else
6221 		WREG32_P(GENERAL_PWRMGT, 0, ~VOLT_PWRMGT_EN);
6222 }
6223 
6224 static enum si_pcie_gen si_get_maximum_link_speed(struct amdgpu_device *adev,
6225 						  struct amdgpu_ps *amdgpu_state)
6226 {
6227 	struct si_ps *state = si_get_ps(amdgpu_state);
6228 	int i;
6229 	u16 pcie_speed, max_speed = 0;
6230 
6231 	for (i = 0; i < state->performance_level_count; i++) {
6232 		pcie_speed = state->performance_levels[i].pcie_gen;
6233 		if (max_speed < pcie_speed)
6234 			max_speed = pcie_speed;
6235 	}
6236 	return max_speed;
6237 }
6238 
6239 static u16 si_get_current_pcie_speed(struct amdgpu_device *adev)
6240 {
6241 	u32 speed_cntl;
6242 
6243 	speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL) & LC_CURRENT_DATA_RATE_MASK;
6244 	speed_cntl >>= LC_CURRENT_DATA_RATE_SHIFT;
6245 
6246 	return (u16)speed_cntl;
6247 }
6248 
6249 static void si_request_link_speed_change_before_state_change(struct amdgpu_device *adev,
6250 							     struct amdgpu_ps *amdgpu_new_state,
6251 							     struct amdgpu_ps *amdgpu_current_state)
6252 {
6253 	struct si_power_info *si_pi = si_get_pi(adev);
6254 	enum si_pcie_gen target_link_speed = si_get_maximum_link_speed(adev, amdgpu_new_state);
6255 	enum si_pcie_gen current_link_speed;
6256 
6257 	if (si_pi->force_pcie_gen == SI_PCIE_GEN_INVALID)
6258 		current_link_speed = si_get_maximum_link_speed(adev, amdgpu_current_state);
6259 	else
6260 		current_link_speed = si_pi->force_pcie_gen;
6261 
6262 	si_pi->force_pcie_gen = SI_PCIE_GEN_INVALID;
6263 	si_pi->pspp_notify_required = false;
6264 	if (target_link_speed > current_link_speed) {
6265 		switch (target_link_speed) {
6266 #if defined(CONFIG_ACPI)
6267 		case SI_PCIE_GEN3:
6268 			if (amdgpu_acpi_pcie_performance_request(adev, PCIE_PERF_REQ_PECI_GEN3, false) == 0)
6269 				break;
6270 			si_pi->force_pcie_gen = SI_PCIE_GEN2;
6271 			if (current_link_speed == SI_PCIE_GEN2)
6272 				break;
6273 			fallthrough;
6274 		case SI_PCIE_GEN2:
6275 			if (amdgpu_acpi_pcie_performance_request(adev, PCIE_PERF_REQ_PECI_GEN2, false) == 0)
6276 				break;
6277 			fallthrough;
6278 #endif
6279 		default:
6280 			si_pi->force_pcie_gen = si_get_current_pcie_speed(adev);
6281 			break;
6282 		}
6283 	} else {
6284 		if (target_link_speed < current_link_speed)
6285 			si_pi->pspp_notify_required = true;
6286 	}
6287 }
6288 
6289 static void si_notify_link_speed_change_after_state_change(struct amdgpu_device *adev,
6290 							   struct amdgpu_ps *amdgpu_new_state,
6291 							   struct amdgpu_ps *amdgpu_current_state)
6292 {
6293 	struct si_power_info *si_pi = si_get_pi(adev);
6294 	enum si_pcie_gen target_link_speed = si_get_maximum_link_speed(adev, amdgpu_new_state);
6295 	u8 request;
6296 
6297 	if (si_pi->pspp_notify_required) {
6298 		if (target_link_speed == SI_PCIE_GEN3)
6299 			request = PCIE_PERF_REQ_PECI_GEN3;
6300 		else if (target_link_speed == SI_PCIE_GEN2)
6301 			request = PCIE_PERF_REQ_PECI_GEN2;
6302 		else
6303 			request = PCIE_PERF_REQ_PECI_GEN1;
6304 
6305 		if ((request == PCIE_PERF_REQ_PECI_GEN1) &&
6306 		    (si_get_current_pcie_speed(adev) > 0))
6307 			return;
6308 
6309 #if defined(CONFIG_ACPI)
6310 		amdgpu_acpi_pcie_performance_request(adev, request, false);
6311 #endif
6312 	}
6313 }
6314 
6315 #if 0
6316 static int si_ds_request(struct amdgpu_device *adev,
6317 			 bool ds_status_on, u32 count_write)
6318 {
6319 	struct evergreen_power_info *eg_pi = evergreen_get_pi(adev);
6320 
6321 	if (eg_pi->sclk_deep_sleep) {
6322 		if (ds_status_on)
6323 			return (amdgpu_si_send_msg_to_smc(adev, PPSMC_MSG_CancelThrottleOVRDSCLKDS) ==
6324 				PPSMC_Result_OK) ?
6325 				0 : -EINVAL;
6326 		else
6327 			return (amdgpu_si_send_msg_to_smc(adev, PPSMC_MSG_ThrottleOVRDSCLKDS) ==
6328 				PPSMC_Result_OK) ? 0 : -EINVAL;
6329 	}
6330 	return 0;
6331 }
6332 #endif
6333 
6334 static void si_set_max_cu_value(struct amdgpu_device *adev)
6335 {
6336 	struct si_power_info *si_pi = si_get_pi(adev);
6337 
6338 	if (adev->asic_type == CHIP_VERDE) {
6339 		switch (adev->pdev->device) {
6340 		case 0x6820:
6341 		case 0x6825:
6342 		case 0x6821:
6343 		case 0x6823:
6344 		case 0x6827:
6345 			si_pi->max_cu = 10;
6346 			break;
6347 		case 0x682D:
6348 		case 0x6824:
6349 		case 0x682F:
6350 		case 0x6826:
6351 			si_pi->max_cu = 8;
6352 			break;
6353 		case 0x6828:
6354 		case 0x6830:
6355 		case 0x6831:
6356 		case 0x6838:
6357 		case 0x6839:
6358 		case 0x683D:
6359 			si_pi->max_cu = 10;
6360 			break;
6361 		case 0x683B:
6362 		case 0x683F:
6363 		case 0x6829:
6364 			si_pi->max_cu = 8;
6365 			break;
6366 		default:
6367 			si_pi->max_cu = 0;
6368 			break;
6369 		}
6370 	} else {
6371 		si_pi->max_cu = 0;
6372 	}
6373 }
6374 
6375 static int si_patch_single_dependency_table_based_on_leakage(struct amdgpu_device *adev,
6376 							     struct amdgpu_clock_voltage_dependency_table *table)
6377 {
6378 	u32 i;
6379 	int j;
6380 	u16 leakage_voltage;
6381 
6382 	if (table) {
6383 		for (i = 0; i < table->count; i++) {
6384 			switch (si_get_leakage_voltage_from_leakage_index(adev,
6385 									  table->entries[i].v,
6386 									  &leakage_voltage)) {
6387 			case 0:
6388 				table->entries[i].v = leakage_voltage;
6389 				break;
6390 			case -EAGAIN:
6391 				return -EINVAL;
6392 			case -EINVAL:
6393 			default:
6394 				break;
6395 			}
6396 		}
6397 
6398 		for (j = (table->count - 2); j >= 0; j--) {
6399 			table->entries[j].v = (table->entries[j].v <= table->entries[j + 1].v) ?
6400 				table->entries[j].v : table->entries[j + 1].v;
6401 		}
6402 	}
6403 	return 0;
6404 }
6405 
6406 static int si_patch_dependency_tables_based_on_leakage(struct amdgpu_device *adev)
6407 {
6408 	int ret = 0;
6409 
6410 	ret = si_patch_single_dependency_table_based_on_leakage(adev,
6411 								&adev->pm.dpm.dyn_state.vddc_dependency_on_sclk);
6412 	if (ret)
6413 		DRM_ERROR("Could not patch vddc_on_sclk leakage table\n");
6414 	ret = si_patch_single_dependency_table_based_on_leakage(adev,
6415 								&adev->pm.dpm.dyn_state.vddc_dependency_on_mclk);
6416 	if (ret)
6417 		DRM_ERROR("Could not patch vddc_on_mclk leakage table\n");
6418 	ret = si_patch_single_dependency_table_based_on_leakage(adev,
6419 								&adev->pm.dpm.dyn_state.vddci_dependency_on_mclk);
6420 	if (ret)
6421 		DRM_ERROR("Could not patch vddci_on_mclk leakage table\n");
6422 	return ret;
6423 }
6424 
6425 static void si_set_pcie_lane_width_in_smc(struct amdgpu_device *adev,
6426 					  struct amdgpu_ps *amdgpu_new_state,
6427 					  struct amdgpu_ps *amdgpu_current_state)
6428 {
6429 	u32 lane_width;
6430 	u32 new_lane_width =
6431 		((amdgpu_new_state->caps & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >> ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT) + 1;
6432 	u32 current_lane_width =
6433 		((amdgpu_current_state->caps & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >> ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT) + 1;
6434 
6435 	if (new_lane_width != current_lane_width) {
6436 		amdgpu_set_pcie_lanes(adev, new_lane_width);
6437 		lane_width = amdgpu_get_pcie_lanes(adev);
6438 		si_write_smc_soft_register(adev, SI_SMC_SOFT_REGISTER_non_ulv_pcie_link_width, lane_width);
6439 	}
6440 }
6441 
6442 static void si_dpm_setup_asic(struct amdgpu_device *adev)
6443 {
6444 	si_read_clock_registers(adev);
6445 	si_enable_acpi_power_management(adev);
6446 }
6447 
6448 static int si_thermal_enable_alert(struct amdgpu_device *adev,
6449 				   bool enable)
6450 {
6451 	u32 thermal_int = RREG32(CG_THERMAL_INT);
6452 
6453 	if (enable) {
6454 		PPSMC_Result result;
6455 
6456 		thermal_int &= ~(THERM_INT_MASK_HIGH | THERM_INT_MASK_LOW);
6457 		WREG32(CG_THERMAL_INT, thermal_int);
6458 		result = amdgpu_si_send_msg_to_smc(adev, PPSMC_MSG_EnableThermalInterrupt);
6459 		if (result != PPSMC_Result_OK) {
6460 			DRM_DEBUG_KMS("Could not enable thermal interrupts.\n");
6461 			return -EINVAL;
6462 		}
6463 	} else {
6464 		thermal_int |= THERM_INT_MASK_HIGH | THERM_INT_MASK_LOW;
6465 		WREG32(CG_THERMAL_INT, thermal_int);
6466 	}
6467 
6468 	return 0;
6469 }
6470 
6471 static int si_thermal_set_temperature_range(struct amdgpu_device *adev,
6472 					    int min_temp, int max_temp)
6473 {
6474 	int low_temp = 0 * 1000;
6475 	int high_temp = 255 * 1000;
6476 
6477 	if (low_temp < min_temp)
6478 		low_temp = min_temp;
6479 	if (high_temp > max_temp)
6480 		high_temp = max_temp;
6481 	if (high_temp < low_temp) {
6482 		DRM_ERROR("invalid thermal range: %d - %d\n", low_temp, high_temp);
6483 		return -EINVAL;
6484 	}
6485 
6486 	WREG32_P(CG_THERMAL_INT, DIG_THERM_INTH(high_temp / 1000), ~DIG_THERM_INTH_MASK);
6487 	WREG32_P(CG_THERMAL_INT, DIG_THERM_INTL(low_temp / 1000), ~DIG_THERM_INTL_MASK);
6488 	WREG32_P(CG_THERMAL_CTRL, DIG_THERM_DPM(high_temp / 1000), ~DIG_THERM_DPM_MASK);
6489 
6490 	adev->pm.dpm.thermal.min_temp = low_temp;
6491 	adev->pm.dpm.thermal.max_temp = high_temp;
6492 
6493 	return 0;
6494 }
6495 
6496 static void si_fan_ctrl_set_static_mode(struct amdgpu_device *adev, u32 mode)
6497 {
6498 	struct si_power_info *si_pi = si_get_pi(adev);
6499 	u32 tmp;
6500 
6501 	if (si_pi->fan_ctrl_is_in_default_mode) {
6502 		tmp = (RREG32(CG_FDO_CTRL2) & FDO_PWM_MODE_MASK) >> FDO_PWM_MODE_SHIFT;
6503 		si_pi->fan_ctrl_default_mode = tmp;
6504 		tmp = (RREG32(CG_FDO_CTRL2) & TMIN_MASK) >> TMIN_SHIFT;
6505 		si_pi->t_min = tmp;
6506 		si_pi->fan_ctrl_is_in_default_mode = false;
6507 	}
6508 
6509 	tmp = RREG32(CG_FDO_CTRL2) & ~TMIN_MASK;
6510 	tmp |= TMIN(0);
6511 	WREG32(CG_FDO_CTRL2, tmp);
6512 
6513 	tmp = RREG32(CG_FDO_CTRL2) & ~FDO_PWM_MODE_MASK;
6514 	tmp |= FDO_PWM_MODE(mode);
6515 	WREG32(CG_FDO_CTRL2, tmp);
6516 }
6517 
6518 static int si_thermal_setup_fan_table(struct amdgpu_device *adev)
6519 {
6520 	struct si_power_info *si_pi = si_get_pi(adev);
6521 	PP_SIslands_FanTable fan_table = { FDO_MODE_HARDWARE };
6522 	u32 duty100;
6523 	u32 t_diff1, t_diff2, pwm_diff1, pwm_diff2;
6524 	u16 fdo_min, slope1, slope2;
6525 	u32 reference_clock, tmp;
6526 	int ret;
6527 	u64 tmp64;
6528 
6529 	if (!si_pi->fan_table_start) {
6530 		adev->pm.dpm.fan.ucode_fan_control = false;
6531 		return 0;
6532 	}
6533 
6534 	duty100 = (RREG32(CG_FDO_CTRL1) & FMAX_DUTY100_MASK) >> FMAX_DUTY100_SHIFT;
6535 
6536 	if (duty100 == 0) {
6537 		adev->pm.dpm.fan.ucode_fan_control = false;
6538 		return 0;
6539 	}
6540 
6541 	tmp64 = (u64)adev->pm.dpm.fan.pwm_min * duty100;
6542 	do_div(tmp64, 10000);
6543 	fdo_min = (u16)tmp64;
6544 
6545 	t_diff1 = adev->pm.dpm.fan.t_med - adev->pm.dpm.fan.t_min;
6546 	t_diff2 = adev->pm.dpm.fan.t_high - adev->pm.dpm.fan.t_med;
6547 
6548 	pwm_diff1 = adev->pm.dpm.fan.pwm_med - adev->pm.dpm.fan.pwm_min;
6549 	pwm_diff2 = adev->pm.dpm.fan.pwm_high - adev->pm.dpm.fan.pwm_med;
6550 
6551 	slope1 = (u16)((50 + ((16 * duty100 * pwm_diff1) / t_diff1)) / 100);
6552 	slope2 = (u16)((50 + ((16 * duty100 * pwm_diff2) / t_diff2)) / 100);
6553 
6554 	fan_table.temp_min = cpu_to_be16((50 + adev->pm.dpm.fan.t_min) / 100);
6555 	fan_table.temp_med = cpu_to_be16((50 + adev->pm.dpm.fan.t_med) / 100);
6556 	fan_table.temp_max = cpu_to_be16((50 + adev->pm.dpm.fan.t_max) / 100);
6557 	fan_table.slope1 = cpu_to_be16(slope1);
6558 	fan_table.slope2 = cpu_to_be16(slope2);
6559 	fan_table.fdo_min = cpu_to_be16(fdo_min);
6560 	fan_table.hys_down = cpu_to_be16(adev->pm.dpm.fan.t_hyst);
6561 	fan_table.hys_up = cpu_to_be16(1);
6562 	fan_table.hys_slope = cpu_to_be16(1);
6563 	fan_table.temp_resp_lim = cpu_to_be16(5);
6564 	reference_clock = amdgpu_asic_get_xclk(adev);
6565 
6566 	fan_table.refresh_period = cpu_to_be32((adev->pm.dpm.fan.cycle_delay *
6567 						reference_clock) / 1600);
6568 	fan_table.fdo_max = cpu_to_be16((u16)duty100);
6569 
6570 	tmp = (RREG32(CG_MULT_THERMAL_CTRL) & TEMP_SEL_MASK) >> TEMP_SEL_SHIFT;
6571 	fan_table.temp_src = (uint8_t)tmp;
6572 
6573 	ret = amdgpu_si_copy_bytes_to_smc(adev,
6574 					  si_pi->fan_table_start,
6575 					  (u8 *)(&fan_table),
6576 					  sizeof(fan_table),
6577 					  si_pi->sram_end);
6578 
6579 	if (ret) {
6580 		DRM_ERROR("Failed to load fan table to the SMC.");
6581 		adev->pm.dpm.fan.ucode_fan_control = false;
6582 	}
6583 
6584 	return ret;
6585 }
6586 
6587 static int si_fan_ctrl_start_smc_fan_control(struct amdgpu_device *adev)
6588 {
6589 	struct si_power_info *si_pi = si_get_pi(adev);
6590 	PPSMC_Result ret;
6591 
6592 	ret = amdgpu_si_send_msg_to_smc(adev, PPSMC_StartFanControl);
6593 	if (ret == PPSMC_Result_OK) {
6594 		si_pi->fan_is_controlled_by_smc = true;
6595 		return 0;
6596 	} else {
6597 		return -EINVAL;
6598 	}
6599 }
6600 
6601 static int si_fan_ctrl_stop_smc_fan_control(struct amdgpu_device *adev)
6602 {
6603 	struct si_power_info *si_pi = si_get_pi(adev);
6604 	PPSMC_Result ret;
6605 
6606 	ret = amdgpu_si_send_msg_to_smc(adev, PPSMC_StopFanControl);
6607 
6608 	if (ret == PPSMC_Result_OK) {
6609 		si_pi->fan_is_controlled_by_smc = false;
6610 		return 0;
6611 	} else {
6612 		return -EINVAL;
6613 	}
6614 }
6615 
6616 static int si_dpm_get_fan_speed_pwm(void *handle,
6617 				      u32 *speed)
6618 {
6619 	u32 duty, duty100;
6620 	u64 tmp64;
6621 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
6622 
6623 	if (!speed)
6624 		return -EINVAL;
6625 
6626 	if (adev->pm.no_fan)
6627 		return -ENOENT;
6628 
6629 	duty100 = (RREG32(CG_FDO_CTRL1) & FMAX_DUTY100_MASK) >> FMAX_DUTY100_SHIFT;
6630 	duty = (RREG32(CG_THERMAL_STATUS) & FDO_PWM_DUTY_MASK) >> FDO_PWM_DUTY_SHIFT;
6631 
6632 	if (duty100 == 0)
6633 		return -EINVAL;
6634 
6635 	tmp64 = (u64)duty * 255;
6636 	do_div(tmp64, duty100);
6637 	*speed = MIN((u32)tmp64, 255);
6638 
6639 	return 0;
6640 }
6641 
6642 static int si_dpm_set_fan_speed_pwm(void *handle,
6643 				      u32 speed)
6644 {
6645 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
6646 	struct si_power_info *si_pi = si_get_pi(adev);
6647 	u32 tmp;
6648 	u32 duty, duty100;
6649 	u64 tmp64;
6650 
6651 	if (adev->pm.no_fan)
6652 		return -ENOENT;
6653 
6654 	if (si_pi->fan_is_controlled_by_smc)
6655 		return -EINVAL;
6656 
6657 	if (speed > 255)
6658 		return -EINVAL;
6659 
6660 	duty100 = (RREG32(CG_FDO_CTRL1) & FMAX_DUTY100_MASK) >> FMAX_DUTY100_SHIFT;
6661 
6662 	if (duty100 == 0)
6663 		return -EINVAL;
6664 
6665 	tmp64 = (u64)speed * duty100;
6666 	do_div(tmp64, 255);
6667 	duty = (u32)tmp64;
6668 
6669 	tmp = RREG32(CG_FDO_CTRL0) & ~FDO_STATIC_DUTY_MASK;
6670 	tmp |= FDO_STATIC_DUTY(duty);
6671 	WREG32(CG_FDO_CTRL0, tmp);
6672 
6673 	return 0;
6674 }
6675 
6676 static int si_dpm_set_fan_control_mode(void *handle, u32 mode)
6677 {
6678 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
6679 
6680 	if (mode == U32_MAX)
6681 		return -EINVAL;
6682 
6683 	if (mode) {
6684 		/* stop auto-manage */
6685 		if (adev->pm.dpm.fan.ucode_fan_control)
6686 			si_fan_ctrl_stop_smc_fan_control(adev);
6687 		si_fan_ctrl_set_static_mode(adev, mode);
6688 	} else {
6689 		/* restart auto-manage */
6690 		if (adev->pm.dpm.fan.ucode_fan_control)
6691 			si_thermal_start_smc_fan_control(adev);
6692 		else
6693 			si_fan_ctrl_set_default_mode(adev);
6694 	}
6695 
6696 	return 0;
6697 }
6698 
6699 static int si_dpm_get_fan_control_mode(void *handle, u32 *fan_mode)
6700 {
6701 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
6702 	struct si_power_info *si_pi = si_get_pi(adev);
6703 	u32 tmp;
6704 
6705 	if (!fan_mode)
6706 		return -EINVAL;
6707 
6708 	if (si_pi->fan_is_controlled_by_smc)
6709 		return 0;
6710 
6711 	tmp = RREG32(CG_FDO_CTRL2) & FDO_PWM_MODE_MASK;
6712 	*fan_mode = (tmp >> FDO_PWM_MODE_SHIFT);
6713 
6714 	return 0;
6715 }
6716 
6717 #if 0
6718 static int si_fan_ctrl_get_fan_speed_rpm(struct amdgpu_device *adev,
6719 					 u32 *speed)
6720 {
6721 	u32 tach_period;
6722 	u32 xclk = amdgpu_asic_get_xclk(adev);
6723 
6724 	if (adev->pm.no_fan)
6725 		return -ENOENT;
6726 
6727 	if (adev->pm.fan_pulses_per_revolution == 0)
6728 		return -ENOENT;
6729 
6730 	tach_period = (RREG32(CG_TACH_STATUS) & TACH_PERIOD_MASK) >> TACH_PERIOD_SHIFT;
6731 	if (tach_period == 0)
6732 		return -ENOENT;
6733 
6734 	*speed = 60 * xclk * 10000 / tach_period;
6735 
6736 	return 0;
6737 }
6738 
6739 static int si_fan_ctrl_set_fan_speed_rpm(struct amdgpu_device *adev,
6740 					 u32 speed)
6741 {
6742 	u32 tach_period, tmp;
6743 	u32 xclk = amdgpu_asic_get_xclk(adev);
6744 
6745 	if (adev->pm.no_fan)
6746 		return -ENOENT;
6747 
6748 	if (adev->pm.fan_pulses_per_revolution == 0)
6749 		return -ENOENT;
6750 
6751 	if ((speed < adev->pm.fan_min_rpm) ||
6752 	    (speed > adev->pm.fan_max_rpm))
6753 		return -EINVAL;
6754 
6755 	if (adev->pm.dpm.fan.ucode_fan_control)
6756 		si_fan_ctrl_stop_smc_fan_control(adev);
6757 
6758 	tach_period = 60 * xclk * 10000 / (8 * speed);
6759 	tmp = RREG32(CG_TACH_CTRL) & ~TARGET_PERIOD_MASK;
6760 	tmp |= TARGET_PERIOD(tach_period);
6761 	WREG32(CG_TACH_CTRL, tmp);
6762 
6763 	si_fan_ctrl_set_static_mode(adev, FDO_PWM_MODE_STATIC_RPM);
6764 
6765 	return 0;
6766 }
6767 #endif
6768 
6769 static void si_fan_ctrl_set_default_mode(struct amdgpu_device *adev)
6770 {
6771 	struct si_power_info *si_pi = si_get_pi(adev);
6772 	u32 tmp;
6773 
6774 	if (!si_pi->fan_ctrl_is_in_default_mode) {
6775 		tmp = RREG32(CG_FDO_CTRL2) & ~FDO_PWM_MODE_MASK;
6776 		tmp |= FDO_PWM_MODE(si_pi->fan_ctrl_default_mode);
6777 		WREG32(CG_FDO_CTRL2, tmp);
6778 
6779 		tmp = RREG32(CG_FDO_CTRL2) & ~TMIN_MASK;
6780 		tmp |= TMIN(si_pi->t_min);
6781 		WREG32(CG_FDO_CTRL2, tmp);
6782 		si_pi->fan_ctrl_is_in_default_mode = true;
6783 	}
6784 }
6785 
6786 static void si_thermal_start_smc_fan_control(struct amdgpu_device *adev)
6787 {
6788 	if (adev->pm.dpm.fan.ucode_fan_control) {
6789 		si_fan_ctrl_start_smc_fan_control(adev);
6790 		si_fan_ctrl_set_static_mode(adev, FDO_PWM_MODE_STATIC);
6791 	}
6792 }
6793 
6794 static void si_thermal_initialize(struct amdgpu_device *adev)
6795 {
6796 	u32 tmp;
6797 
6798 	if (adev->pm.fan_pulses_per_revolution) {
6799 		tmp = RREG32(CG_TACH_CTRL) & ~EDGE_PER_REV_MASK;
6800 		tmp |= EDGE_PER_REV(adev->pm.fan_pulses_per_revolution -1);
6801 		WREG32(CG_TACH_CTRL, tmp);
6802 	}
6803 
6804 	tmp = RREG32(CG_FDO_CTRL2) & ~TACH_PWM_RESP_RATE_MASK;
6805 	tmp |= TACH_PWM_RESP_RATE(0x28);
6806 	WREG32(CG_FDO_CTRL2, tmp);
6807 }
6808 
6809 static int si_thermal_start_thermal_controller(struct amdgpu_device *adev)
6810 {
6811 	int ret;
6812 
6813 	si_thermal_initialize(adev);
6814 	ret = si_thermal_set_temperature_range(adev, R600_TEMP_RANGE_MIN, R600_TEMP_RANGE_MAX);
6815 	if (ret)
6816 		return ret;
6817 	ret = si_thermal_enable_alert(adev, true);
6818 	if (ret)
6819 		return ret;
6820 	if (adev->pm.dpm.fan.ucode_fan_control) {
6821 		ret = si_halt_smc(adev);
6822 		if (ret)
6823 			return ret;
6824 		ret = si_thermal_setup_fan_table(adev);
6825 		if (ret)
6826 			return ret;
6827 		ret = si_resume_smc(adev);
6828 		if (ret)
6829 			return ret;
6830 		si_thermal_start_smc_fan_control(adev);
6831 	}
6832 
6833 	return 0;
6834 }
6835 
6836 static void si_thermal_stop_thermal_controller(struct amdgpu_device *adev)
6837 {
6838 	if (!adev->pm.no_fan) {
6839 		si_fan_ctrl_set_default_mode(adev);
6840 		si_fan_ctrl_stop_smc_fan_control(adev);
6841 	}
6842 }
6843 
6844 static int si_dpm_enable(struct amdgpu_device *adev)
6845 {
6846 	struct rv7xx_power_info *pi = rv770_get_pi(adev);
6847 	struct evergreen_power_info *eg_pi = evergreen_get_pi(adev);
6848 	struct si_power_info *si_pi = si_get_pi(adev);
6849 	struct amdgpu_ps *boot_ps = adev->pm.dpm.boot_ps;
6850 	int ret;
6851 
6852 	if (amdgpu_si_is_smc_running(adev))
6853 		return -EINVAL;
6854 	if (pi->voltage_control || si_pi->voltage_control_svi2)
6855 		si_enable_voltage_control(adev, true);
6856 	if (pi->mvdd_control)
6857 		si_get_mvdd_configuration(adev);
6858 	if (pi->voltage_control || si_pi->voltage_control_svi2) {
6859 		ret = si_construct_voltage_tables(adev);
6860 		if (ret) {
6861 			DRM_ERROR("si_construct_voltage_tables failed\n");
6862 			return ret;
6863 		}
6864 	}
6865 	if (eg_pi->dynamic_ac_timing) {
6866 		ret = si_initialize_mc_reg_table(adev);
6867 		if (ret)
6868 			eg_pi->dynamic_ac_timing = false;
6869 	}
6870 	if (pi->dynamic_ss)
6871 		si_enable_spread_spectrum(adev, true);
6872 	if (pi->thermal_protection)
6873 		si_enable_thermal_protection(adev, true);
6874 	si_setup_bsp(adev);
6875 	si_program_git(adev);
6876 	si_program_tp(adev);
6877 	si_program_tpp(adev);
6878 	si_program_sstp(adev);
6879 	si_enable_display_gap(adev);
6880 	si_program_vc(adev);
6881 	ret = si_upload_firmware(adev);
6882 	if (ret) {
6883 		DRM_ERROR("si_upload_firmware failed\n");
6884 		return ret;
6885 	}
6886 	ret = si_process_firmware_header(adev);
6887 	if (ret) {
6888 		DRM_ERROR("si_process_firmware_header failed\n");
6889 		return ret;
6890 	}
6891 	ret = si_initial_switch_from_arb_f0_to_f1(adev);
6892 	if (ret) {
6893 		DRM_ERROR("si_initial_switch_from_arb_f0_to_f1 failed\n");
6894 		return ret;
6895 	}
6896 	ret = si_init_smc_table(adev);
6897 	if (ret) {
6898 		DRM_ERROR("si_init_smc_table failed\n");
6899 		return ret;
6900 	}
6901 	ret = si_init_smc_spll_table(adev);
6902 	if (ret) {
6903 		DRM_ERROR("si_init_smc_spll_table failed\n");
6904 		return ret;
6905 	}
6906 	ret = si_init_arb_table_index(adev);
6907 	if (ret) {
6908 		DRM_ERROR("si_init_arb_table_index failed\n");
6909 		return ret;
6910 	}
6911 	if (eg_pi->dynamic_ac_timing) {
6912 		ret = si_populate_mc_reg_table(adev, boot_ps);
6913 		if (ret) {
6914 			DRM_ERROR("si_populate_mc_reg_table failed\n");
6915 			return ret;
6916 		}
6917 	}
6918 	ret = si_initialize_smc_cac_tables(adev);
6919 	if (ret) {
6920 		DRM_ERROR("si_initialize_smc_cac_tables failed\n");
6921 		return ret;
6922 	}
6923 	ret = si_initialize_hardware_cac_manager(adev);
6924 	if (ret) {
6925 		DRM_ERROR("si_initialize_hardware_cac_manager failed\n");
6926 		return ret;
6927 	}
6928 	ret = si_initialize_smc_dte_tables(adev);
6929 	if (ret) {
6930 		DRM_ERROR("si_initialize_smc_dte_tables failed\n");
6931 		return ret;
6932 	}
6933 	ret = si_populate_smc_tdp_limits(adev, boot_ps);
6934 	if (ret) {
6935 		DRM_ERROR("si_populate_smc_tdp_limits failed\n");
6936 		return ret;
6937 	}
6938 	ret = si_populate_smc_tdp_limits_2(adev, boot_ps);
6939 	if (ret) {
6940 		DRM_ERROR("si_populate_smc_tdp_limits_2 failed\n");
6941 		return ret;
6942 	}
6943 	si_program_response_times(adev);
6944 	si_program_ds_registers(adev);
6945 	si_dpm_start_smc(adev);
6946 	ret = si_notify_smc_display_change(adev, false);
6947 	if (ret) {
6948 		DRM_ERROR("si_notify_smc_display_change failed\n");
6949 		return ret;
6950 	}
6951 	si_enable_sclk_control(adev, true);
6952 	si_start_dpm(adev);
6953 
6954 	si_enable_auto_throttle_source(adev, SI_DPM_AUTO_THROTTLE_SRC_THERMAL, true);
6955 	si_thermal_start_thermal_controller(adev);
6956 
6957 	ni_update_current_ps(adev, boot_ps);
6958 
6959 	return 0;
6960 }
6961 
6962 static int si_set_temperature_range(struct amdgpu_device *adev)
6963 {
6964 	int ret;
6965 
6966 	ret = si_thermal_enable_alert(adev, false);
6967 	if (ret)
6968 		return ret;
6969 	ret = si_thermal_set_temperature_range(adev, R600_TEMP_RANGE_MIN, R600_TEMP_RANGE_MAX);
6970 	if (ret)
6971 		return ret;
6972 	ret = si_thermal_enable_alert(adev, true);
6973 	if (ret)
6974 		return ret;
6975 
6976 	return ret;
6977 }
6978 
6979 static void si_dpm_disable(struct amdgpu_device *adev)
6980 {
6981 	struct rv7xx_power_info *pi = rv770_get_pi(adev);
6982 	struct amdgpu_ps *boot_ps = adev->pm.dpm.boot_ps;
6983 
6984 	if (!amdgpu_si_is_smc_running(adev))
6985 		return;
6986 	si_thermal_stop_thermal_controller(adev);
6987 	si_disable_ulv(adev);
6988 	si_clear_vc(adev);
6989 	if (pi->thermal_protection)
6990 		si_enable_thermal_protection(adev, false);
6991 	si_enable_power_containment(adev, boot_ps, false);
6992 	si_enable_smc_cac(adev, boot_ps, false);
6993 	si_enable_spread_spectrum(adev, false);
6994 	si_enable_auto_throttle_source(adev, SI_DPM_AUTO_THROTTLE_SRC_THERMAL, false);
6995 	si_stop_dpm(adev);
6996 	si_reset_to_default(adev);
6997 	si_dpm_stop_smc(adev);
6998 	si_force_switch_to_arb_f0(adev);
6999 
7000 	ni_update_current_ps(adev, boot_ps);
7001 }
7002 
7003 static int si_dpm_pre_set_power_state(void *handle)
7004 {
7005 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
7006 	struct evergreen_power_info *eg_pi = evergreen_get_pi(adev);
7007 	struct amdgpu_ps requested_ps = *adev->pm.dpm.requested_ps;
7008 	struct amdgpu_ps *new_ps = &requested_ps;
7009 
7010 	ni_update_requested_ps(adev, new_ps);
7011 	si_apply_state_adjust_rules(adev, &eg_pi->requested_rps);
7012 
7013 	return 0;
7014 }
7015 
7016 static int si_power_control_set_level(struct amdgpu_device *adev)
7017 {
7018 	struct amdgpu_ps *new_ps = adev->pm.dpm.requested_ps;
7019 	int ret;
7020 
7021 	ret = si_restrict_performance_levels_before_switch(adev);
7022 	if (ret)
7023 		return ret;
7024 	ret = si_halt_smc(adev);
7025 	if (ret)
7026 		return ret;
7027 	ret = si_populate_smc_tdp_limits(adev, new_ps);
7028 	if (ret)
7029 		return ret;
7030 	ret = si_populate_smc_tdp_limits_2(adev, new_ps);
7031 	if (ret)
7032 		return ret;
7033 	ret = si_resume_smc(adev);
7034 	if (ret)
7035 		return ret;
7036 	return si_set_sw_state(adev);
7037 }
7038 
7039 static void si_set_vce_clock(struct amdgpu_device *adev,
7040 			     struct amdgpu_ps *new_rps,
7041 			     struct amdgpu_ps *old_rps)
7042 {
7043 	if ((old_rps->evclk != new_rps->evclk) ||
7044 	    (old_rps->ecclk != new_rps->ecclk)) {
7045 		/* Turn the clocks on when encoding, off otherwise */
7046 		if (new_rps->evclk || new_rps->ecclk) {
7047 			/* Place holder for future VCE1.0 porting to amdgpu
7048 			vce_v1_0_enable_mgcg(adev, false, false);*/
7049 		} else {
7050 			/* Place holder for future VCE1.0 porting to amdgpu
7051 			vce_v1_0_enable_mgcg(adev, true, false);
7052 			amdgpu_asic_set_vce_clocks(adev, new_rps->evclk, new_rps->ecclk);*/
7053 		}
7054 	}
7055 }
7056 
7057 static int si_dpm_set_power_state(void *handle)
7058 {
7059 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
7060 	struct evergreen_power_info *eg_pi = evergreen_get_pi(adev);
7061 	struct amdgpu_ps *new_ps = &eg_pi->requested_rps;
7062 	struct amdgpu_ps *old_ps = &eg_pi->current_rps;
7063 	int ret;
7064 
7065 	ret = si_disable_ulv(adev);
7066 	if (ret) {
7067 		DRM_ERROR("si_disable_ulv failed\n");
7068 		return ret;
7069 	}
7070 	ret = si_restrict_performance_levels_before_switch(adev);
7071 	if (ret) {
7072 		DRM_ERROR("si_restrict_performance_levels_before_switch failed\n");
7073 		return ret;
7074 	}
7075 	if (eg_pi->pcie_performance_request)
7076 		si_request_link_speed_change_before_state_change(adev, new_ps, old_ps);
7077 	ni_set_uvd_clock_before_set_eng_clock(adev, new_ps, old_ps);
7078 	ret = si_enable_power_containment(adev, new_ps, false);
7079 	if (ret) {
7080 		DRM_ERROR("si_enable_power_containment failed\n");
7081 		return ret;
7082 	}
7083 	ret = si_enable_smc_cac(adev, new_ps, false);
7084 	if (ret) {
7085 		DRM_ERROR("si_enable_smc_cac failed\n");
7086 		return ret;
7087 	}
7088 	ret = si_halt_smc(adev);
7089 	if (ret) {
7090 		DRM_ERROR("si_halt_smc failed\n");
7091 		return ret;
7092 	}
7093 	ret = si_upload_sw_state(adev, new_ps);
7094 	if (ret) {
7095 		DRM_ERROR("si_upload_sw_state failed\n");
7096 		return ret;
7097 	}
7098 	ret = si_upload_smc_data(adev);
7099 	if (ret) {
7100 		DRM_ERROR("si_upload_smc_data failed\n");
7101 		return ret;
7102 	}
7103 	ret = si_upload_ulv_state(adev);
7104 	if (ret) {
7105 		DRM_ERROR("si_upload_ulv_state failed\n");
7106 		return ret;
7107 	}
7108 	if (eg_pi->dynamic_ac_timing) {
7109 		ret = si_upload_mc_reg_table(adev, new_ps);
7110 		if (ret) {
7111 			DRM_ERROR("si_upload_mc_reg_table failed\n");
7112 			return ret;
7113 		}
7114 	}
7115 	ret = si_program_memory_timing_parameters(adev, new_ps);
7116 	if (ret) {
7117 		DRM_ERROR("si_program_memory_timing_parameters failed\n");
7118 		return ret;
7119 	}
7120 	si_set_pcie_lane_width_in_smc(adev, new_ps, old_ps);
7121 
7122 	ret = si_resume_smc(adev);
7123 	if (ret) {
7124 		DRM_ERROR("si_resume_smc failed\n");
7125 		return ret;
7126 	}
7127 	ret = si_set_sw_state(adev);
7128 	if (ret) {
7129 		DRM_ERROR("si_set_sw_state failed\n");
7130 		return ret;
7131 	}
7132 	ni_set_uvd_clock_after_set_eng_clock(adev, new_ps, old_ps);
7133 	si_set_vce_clock(adev, new_ps, old_ps);
7134 	if (eg_pi->pcie_performance_request)
7135 		si_notify_link_speed_change_after_state_change(adev, new_ps, old_ps);
7136 	ret = si_set_power_state_conditionally_enable_ulv(adev, new_ps);
7137 	if (ret) {
7138 		DRM_ERROR("si_set_power_state_conditionally_enable_ulv failed\n");
7139 		return ret;
7140 	}
7141 	ret = si_enable_smc_cac(adev, new_ps, true);
7142 	if (ret) {
7143 		DRM_ERROR("si_enable_smc_cac failed\n");
7144 		return ret;
7145 	}
7146 	ret = si_enable_power_containment(adev, new_ps, true);
7147 	if (ret) {
7148 		DRM_ERROR("si_enable_power_containment failed\n");
7149 		return ret;
7150 	}
7151 
7152 	ret = si_power_control_set_level(adev);
7153 	if (ret) {
7154 		DRM_ERROR("si_power_control_set_level failed\n");
7155 		return ret;
7156 	}
7157 
7158 	return 0;
7159 }
7160 
7161 static void si_dpm_post_set_power_state(void *handle)
7162 {
7163 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
7164 	struct evergreen_power_info *eg_pi = evergreen_get_pi(adev);
7165 	struct amdgpu_ps *new_ps = &eg_pi->requested_rps;
7166 
7167 	ni_update_current_ps(adev, new_ps);
7168 }
7169 
7170 #if 0
7171 void si_dpm_reset_asic(struct amdgpu_device *adev)
7172 {
7173 	si_restrict_performance_levels_before_switch(adev);
7174 	si_disable_ulv(adev);
7175 	si_set_boot_state(adev);
7176 }
7177 #endif
7178 
7179 static void si_dpm_display_configuration_changed(void *handle)
7180 {
7181 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
7182 
7183 	si_program_display_gap(adev);
7184 }
7185 
7186 
7187 static void si_parse_pplib_non_clock_info(struct amdgpu_device *adev,
7188 					  struct amdgpu_ps *rps,
7189 					  struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info,
7190 					  u8 table_rev)
7191 {
7192 	rps->caps = le32_to_cpu(non_clock_info->ulCapsAndSettings);
7193 	rps->class = le16_to_cpu(non_clock_info->usClassification);
7194 	rps->class2 = le16_to_cpu(non_clock_info->usClassification2);
7195 
7196 	if (ATOM_PPLIB_NONCLOCKINFO_VER1 < table_rev) {
7197 		rps->vclk = le32_to_cpu(non_clock_info->ulVCLK);
7198 		rps->dclk = le32_to_cpu(non_clock_info->ulDCLK);
7199 	} else if (r600_is_uvd_state(rps->class, rps->class2)) {
7200 		rps->vclk = RV770_DEFAULT_VCLK_FREQ;
7201 		rps->dclk = RV770_DEFAULT_DCLK_FREQ;
7202 	} else {
7203 		rps->vclk = 0;
7204 		rps->dclk = 0;
7205 	}
7206 
7207 	if (rps->class & ATOM_PPLIB_CLASSIFICATION_BOOT)
7208 		adev->pm.dpm.boot_ps = rps;
7209 	if (rps->class & ATOM_PPLIB_CLASSIFICATION_UVDSTATE)
7210 		adev->pm.dpm.uvd_ps = rps;
7211 }
7212 
7213 static void si_parse_pplib_clock_info(struct amdgpu_device *adev,
7214 				      struct amdgpu_ps *rps, int index,
7215 				      union pplib_clock_info *clock_info)
7216 {
7217 	struct rv7xx_power_info *pi = rv770_get_pi(adev);
7218 	struct evergreen_power_info *eg_pi = evergreen_get_pi(adev);
7219 	struct si_power_info *si_pi = si_get_pi(adev);
7220 	struct  si_ps *ps = si_get_ps(rps);
7221 	u16 leakage_voltage;
7222 	struct rv7xx_pl *pl = &ps->performance_levels[index];
7223 	int ret;
7224 
7225 	ps->performance_level_count = index + 1;
7226 
7227 	pl->sclk = le16_to_cpu(clock_info->si.usEngineClockLow);
7228 	pl->sclk |= clock_info->si.ucEngineClockHigh << 16;
7229 	pl->mclk = le16_to_cpu(clock_info->si.usMemoryClockLow);
7230 	pl->mclk |= clock_info->si.ucMemoryClockHigh << 16;
7231 
7232 	pl->vddc = le16_to_cpu(clock_info->si.usVDDC);
7233 	pl->vddci = le16_to_cpu(clock_info->si.usVDDCI);
7234 	pl->flags = le32_to_cpu(clock_info->si.ulFlags);
7235 	pl->pcie_gen = si_gen_pcie_gen_support(adev,
7236 					       si_pi->sys_pcie_mask,
7237 					       si_pi->boot_pcie_gen,
7238 					       clock_info->si.ucPCIEGen);
7239 
7240 	/* patch up vddc if necessary */
7241 	ret = si_get_leakage_voltage_from_leakage_index(adev, pl->vddc,
7242 							&leakage_voltage);
7243 	if (ret == 0)
7244 		pl->vddc = leakage_voltage;
7245 
7246 	if (rps->class & ATOM_PPLIB_CLASSIFICATION_ACPI) {
7247 		pi->acpi_vddc = pl->vddc;
7248 		eg_pi->acpi_vddci = pl->vddci;
7249 		si_pi->acpi_pcie_gen = pl->pcie_gen;
7250 	}
7251 
7252 	if ((rps->class2 & ATOM_PPLIB_CLASSIFICATION2_ULV) &&
7253 	    index == 0) {
7254 		/* XXX disable for A0 tahiti */
7255 		si_pi->ulv.supported = false;
7256 		si_pi->ulv.pl = *pl;
7257 		si_pi->ulv.one_pcie_lane_in_ulv = false;
7258 		si_pi->ulv.volt_change_delay = SISLANDS_ULVVOLTAGECHANGEDELAY_DFLT;
7259 		si_pi->ulv.cg_ulv_parameter = SISLANDS_CGULVPARAMETER_DFLT;
7260 		si_pi->ulv.cg_ulv_control = SISLANDS_CGULVCONTROL_DFLT;
7261 	}
7262 
7263 	if (pi->min_vddc_in_table > pl->vddc)
7264 		pi->min_vddc_in_table = pl->vddc;
7265 
7266 	if (pi->max_vddc_in_table < pl->vddc)
7267 		pi->max_vddc_in_table = pl->vddc;
7268 
7269 	/* patch up boot state */
7270 	if (rps->class & ATOM_PPLIB_CLASSIFICATION_BOOT) {
7271 		u16 vddc, vddci, mvdd;
7272 		amdgpu_atombios_get_default_voltages(adev, &vddc, &vddci, &mvdd);
7273 		pl->mclk = adev->clock.default_mclk;
7274 		pl->sclk = adev->clock.default_sclk;
7275 		pl->vddc = vddc;
7276 		pl->vddci = vddci;
7277 		si_pi->mvdd_bootup_value = mvdd;
7278 	}
7279 
7280 	if ((rps->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK) ==
7281 	    ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE) {
7282 		adev->pm.dpm.dyn_state.max_clock_voltage_on_ac.sclk = pl->sclk;
7283 		adev->pm.dpm.dyn_state.max_clock_voltage_on_ac.mclk = pl->mclk;
7284 		adev->pm.dpm.dyn_state.max_clock_voltage_on_ac.vddc = pl->vddc;
7285 		adev->pm.dpm.dyn_state.max_clock_voltage_on_ac.vddci = pl->vddci;
7286 	}
7287 }
7288 
7289 union pplib_power_state {
7290 	struct _ATOM_PPLIB_STATE v1;
7291 	struct _ATOM_PPLIB_STATE_V2 v2;
7292 };
7293 
7294 static int si_parse_power_table(struct amdgpu_device *adev)
7295 {
7296 	struct amdgpu_mode_info *mode_info = &adev->mode_info;
7297 	struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
7298 	union pplib_power_state *power_state;
7299 	int i, j, k, non_clock_array_index, clock_array_index;
7300 	union pplib_clock_info *clock_info;
7301 	struct _StateArray *state_array;
7302 	struct _ClockInfoArray *clock_info_array;
7303 	struct _NonClockInfoArray *non_clock_info_array;
7304 	union power_info *power_info;
7305 	int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
7306 	u16 data_offset;
7307 	u8 frev, crev;
7308 	u8 *power_state_offset;
7309 	struct  si_ps *ps;
7310 
7311 	if (!amdgpu_atom_parse_data_header(mode_info->atom_context, index, NULL,
7312 				   &frev, &crev, &data_offset))
7313 		return -EINVAL;
7314 	power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
7315 
7316 	amdgpu_add_thermal_controller(adev);
7317 
7318 	state_array = (struct _StateArray *)
7319 		(mode_info->atom_context->bios + data_offset +
7320 		 le16_to_cpu(power_info->pplib.usStateArrayOffset));
7321 	clock_info_array = (struct _ClockInfoArray *)
7322 		(mode_info->atom_context->bios + data_offset +
7323 		 le16_to_cpu(power_info->pplib.usClockInfoArrayOffset));
7324 	non_clock_info_array = (struct _NonClockInfoArray *)
7325 		(mode_info->atom_context->bios + data_offset +
7326 		 le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset));
7327 
7328 	adev->pm.dpm.ps = kcalloc(state_array->ucNumEntries,
7329 				  sizeof(struct amdgpu_ps),
7330 				  GFP_KERNEL);
7331 	if (!adev->pm.dpm.ps)
7332 		return -ENOMEM;
7333 	power_state_offset = (u8 *)state_array->states;
7334 	for (i = 0; i < state_array->ucNumEntries; i++) {
7335 		u8 *idx;
7336 		power_state = (union pplib_power_state *)power_state_offset;
7337 		non_clock_array_index = power_state->v2.nonClockInfoIndex;
7338 		non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
7339 			&non_clock_info_array->nonClockInfo[non_clock_array_index];
7340 		ps = kzalloc(sizeof(struct  si_ps), GFP_KERNEL);
7341 		if (ps == NULL) {
7342 			kfree(adev->pm.dpm.ps);
7343 			return -ENOMEM;
7344 		}
7345 		adev->pm.dpm.ps[i].ps_priv = ps;
7346 		si_parse_pplib_non_clock_info(adev, &adev->pm.dpm.ps[i],
7347 					      non_clock_info,
7348 					      non_clock_info_array->ucEntrySize);
7349 		k = 0;
7350 		idx = (u8 *)&power_state->v2.clockInfoIndex[0];
7351 		for (j = 0; j < power_state->v2.ucNumDPMLevels; j++) {
7352 			clock_array_index = idx[j];
7353 			if (clock_array_index >= clock_info_array->ucNumEntries)
7354 				continue;
7355 			if (k >= SISLANDS_MAX_HARDWARE_POWERLEVELS)
7356 				break;
7357 			clock_info = (union pplib_clock_info *)
7358 				((u8 *)&clock_info_array->clockInfo[0] +
7359 				 (clock_array_index * clock_info_array->ucEntrySize));
7360 			si_parse_pplib_clock_info(adev,
7361 						  &adev->pm.dpm.ps[i], k,
7362 						  clock_info);
7363 			k++;
7364 		}
7365 		power_state_offset += 2 + power_state->v2.ucNumDPMLevels;
7366 	}
7367 	adev->pm.dpm.num_ps = state_array->ucNumEntries;
7368 
7369 	/* fill in the vce power states */
7370 	for (i = 0; i < adev->pm.dpm.num_of_vce_states; i++) {
7371 		u32 sclk, mclk;
7372 		clock_array_index = adev->pm.dpm.vce_states[i].clk_idx;
7373 		clock_info = (union pplib_clock_info *)
7374 			&clock_info_array->clockInfo[clock_array_index * clock_info_array->ucEntrySize];
7375 		sclk = le16_to_cpu(clock_info->si.usEngineClockLow);
7376 		sclk |= clock_info->si.ucEngineClockHigh << 16;
7377 		mclk = le16_to_cpu(clock_info->si.usMemoryClockLow);
7378 		mclk |= clock_info->si.ucMemoryClockHigh << 16;
7379 		adev->pm.dpm.vce_states[i].sclk = sclk;
7380 		adev->pm.dpm.vce_states[i].mclk = mclk;
7381 	}
7382 
7383 	return 0;
7384 }
7385 
7386 static int si_dpm_init(struct amdgpu_device *adev)
7387 {
7388 	struct rv7xx_power_info *pi;
7389 	struct evergreen_power_info *eg_pi;
7390 	struct ni_power_info *ni_pi;
7391 	struct si_power_info *si_pi;
7392 	struct atom_clock_dividers dividers;
7393 	int ret;
7394 
7395 	si_pi = kzalloc(sizeof(struct si_power_info), GFP_KERNEL);
7396 	if (si_pi == NULL)
7397 		return -ENOMEM;
7398 	adev->pm.dpm.priv = si_pi;
7399 	ni_pi = &si_pi->ni;
7400 	eg_pi = &ni_pi->eg;
7401 	pi = &eg_pi->rv7xx;
7402 
7403 	si_pi->sys_pcie_mask =
7404 		adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_MASK;
7405 	si_pi->force_pcie_gen = SI_PCIE_GEN_INVALID;
7406 	si_pi->boot_pcie_gen = si_get_current_pcie_speed(adev);
7407 
7408 	si_set_max_cu_value(adev);
7409 
7410 	rv770_get_max_vddc(adev);
7411 	si_get_leakage_vddc(adev);
7412 	si_patch_dependency_tables_based_on_leakage(adev);
7413 
7414 	pi->acpi_vddc = 0;
7415 	eg_pi->acpi_vddci = 0;
7416 	pi->min_vddc_in_table = 0;
7417 	pi->max_vddc_in_table = 0;
7418 
7419 	ret = amdgpu_get_platform_caps(adev);
7420 	if (ret)
7421 		return ret;
7422 
7423 	ret = amdgpu_parse_extended_power_table(adev);
7424 	if (ret)
7425 		return ret;
7426 
7427 	ret = si_parse_power_table(adev);
7428 	if (ret)
7429 		return ret;
7430 
7431 	adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries =
7432 		kcalloc(4,
7433 			sizeof(struct amdgpu_clock_voltage_dependency_entry),
7434 			GFP_KERNEL);
7435 	if (!adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries) {
7436 		amdgpu_free_extended_power_table(adev);
7437 		return -ENOMEM;
7438 	}
7439 	adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.count = 4;
7440 	adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[0].clk = 0;
7441 	adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[0].v = 0;
7442 	adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[1].clk = 36000;
7443 	adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[1].v = 720;
7444 	adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[2].clk = 54000;
7445 	adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[2].v = 810;
7446 	adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[3].clk = 72000;
7447 	adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[3].v = 900;
7448 
7449 	if (adev->pm.dpm.voltage_response_time == 0)
7450 		adev->pm.dpm.voltage_response_time = R600_VOLTAGERESPONSETIME_DFLT;
7451 	if (adev->pm.dpm.backbias_response_time == 0)
7452 		adev->pm.dpm.backbias_response_time = R600_BACKBIASRESPONSETIME_DFLT;
7453 
7454 	ret = amdgpu_atombios_get_clock_dividers(adev, COMPUTE_ENGINE_PLL_PARAM,
7455 					     0, false, &dividers);
7456 	if (ret)
7457 		pi->ref_div = dividers.ref_div + 1;
7458 	else
7459 		pi->ref_div = R600_REFERENCEDIVIDER_DFLT;
7460 
7461 	eg_pi->smu_uvd_hs = false;
7462 
7463 	pi->mclk_strobe_mode_threshold = 40000;
7464 	if (si_is_special_1gb_platform(adev))
7465 		pi->mclk_stutter_mode_threshold = 0;
7466 	else
7467 		pi->mclk_stutter_mode_threshold = pi->mclk_strobe_mode_threshold;
7468 	pi->mclk_edc_enable_threshold = 40000;
7469 	eg_pi->mclk_edc_wr_enable_threshold = 40000;
7470 
7471 	ni_pi->mclk_rtt_mode_threshold = eg_pi->mclk_edc_wr_enable_threshold;
7472 
7473 	pi->voltage_control =
7474 		amdgpu_atombios_is_voltage_gpio(adev, SET_VOLTAGE_TYPE_ASIC_VDDC,
7475 					    VOLTAGE_OBJ_GPIO_LUT);
7476 	if (!pi->voltage_control) {
7477 		si_pi->voltage_control_svi2 =
7478 			amdgpu_atombios_is_voltage_gpio(adev, SET_VOLTAGE_TYPE_ASIC_VDDC,
7479 						    VOLTAGE_OBJ_SVID2);
7480 		if (si_pi->voltage_control_svi2)
7481 			amdgpu_atombios_get_svi2_info(adev, SET_VOLTAGE_TYPE_ASIC_VDDC,
7482 						  &si_pi->svd_gpio_id, &si_pi->svc_gpio_id);
7483 	}
7484 
7485 	pi->mvdd_control =
7486 		amdgpu_atombios_is_voltage_gpio(adev, SET_VOLTAGE_TYPE_ASIC_MVDDC,
7487 					    VOLTAGE_OBJ_GPIO_LUT);
7488 
7489 	eg_pi->vddci_control =
7490 		amdgpu_atombios_is_voltage_gpio(adev, SET_VOLTAGE_TYPE_ASIC_VDDCI,
7491 					    VOLTAGE_OBJ_GPIO_LUT);
7492 	if (!eg_pi->vddci_control)
7493 		si_pi->vddci_control_svi2 =
7494 			amdgpu_atombios_is_voltage_gpio(adev, SET_VOLTAGE_TYPE_ASIC_VDDCI,
7495 						    VOLTAGE_OBJ_SVID2);
7496 
7497 	si_pi->vddc_phase_shed_control =
7498 		amdgpu_atombios_is_voltage_gpio(adev, SET_VOLTAGE_TYPE_ASIC_VDDC,
7499 					    VOLTAGE_OBJ_PHASE_LUT);
7500 
7501 	rv770_get_engine_memory_ss(adev);
7502 
7503 	pi->asi = RV770_ASI_DFLT;
7504 	pi->pasi = CYPRESS_HASI_DFLT;
7505 	pi->vrc = SISLANDS_VRC_DFLT;
7506 
7507 	pi->gfx_clock_gating = true;
7508 
7509 	eg_pi->sclk_deep_sleep = true;
7510 	si_pi->sclk_deep_sleep_above_low = false;
7511 
7512 	if (adev->pm.int_thermal_type != THERMAL_TYPE_NONE)
7513 		pi->thermal_protection = true;
7514 	else
7515 		pi->thermal_protection = false;
7516 
7517 	eg_pi->dynamic_ac_timing = true;
7518 
7519 	eg_pi->light_sleep = true;
7520 #if defined(CONFIG_ACPI)
7521 	eg_pi->pcie_performance_request =
7522 		amdgpu_acpi_is_pcie_performance_request_supported(adev);
7523 #else
7524 	eg_pi->pcie_performance_request = false;
7525 #endif
7526 
7527 	si_pi->sram_end = SMC_RAM_END;
7528 
7529 	adev->pm.dpm.dyn_state.mclk_sclk_ratio = 4;
7530 	adev->pm.dpm.dyn_state.sclk_mclk_delta = 15000;
7531 	adev->pm.dpm.dyn_state.vddc_vddci_delta = 200;
7532 	adev->pm.dpm.dyn_state.valid_sclk_values.count = 0;
7533 	adev->pm.dpm.dyn_state.valid_sclk_values.values = NULL;
7534 	adev->pm.dpm.dyn_state.valid_mclk_values.count = 0;
7535 	adev->pm.dpm.dyn_state.valid_mclk_values.values = NULL;
7536 
7537 	si_initialize_powertune_defaults(adev);
7538 
7539 	/* make sure dc limits are valid */
7540 	if ((adev->pm.dpm.dyn_state.max_clock_voltage_on_dc.sclk == 0) ||
7541 	    (adev->pm.dpm.dyn_state.max_clock_voltage_on_dc.mclk == 0))
7542 		adev->pm.dpm.dyn_state.max_clock_voltage_on_dc =
7543 			adev->pm.dpm.dyn_state.max_clock_voltage_on_ac;
7544 
7545 	si_pi->fan_ctrl_is_in_default_mode = true;
7546 
7547 	return 0;
7548 }
7549 
7550 static void si_dpm_fini(struct amdgpu_device *adev)
7551 {
7552 	int i;
7553 
7554 	if (adev->pm.dpm.ps)
7555 		for (i = 0; i < adev->pm.dpm.num_ps; i++)
7556 			kfree(adev->pm.dpm.ps[i].ps_priv);
7557 	kfree(adev->pm.dpm.ps);
7558 	kfree(adev->pm.dpm.priv);
7559 	kfree(adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries);
7560 	amdgpu_free_extended_power_table(adev);
7561 }
7562 
7563 static void si_dpm_debugfs_print_current_performance_level(void *handle,
7564 						    struct seq_file *m)
7565 {
7566 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
7567 	struct evergreen_power_info *eg_pi = evergreen_get_pi(adev);
7568 	struct amdgpu_ps *rps = &eg_pi->current_rps;
7569 	struct  si_ps *ps = si_get_ps(rps);
7570 	struct rv7xx_pl *pl;
7571 	u32 current_index =
7572 		(RREG32(TARGET_AND_CURRENT_PROFILE_INDEX) & CURRENT_STATE_INDEX_MASK) >>
7573 		CURRENT_STATE_INDEX_SHIFT;
7574 
7575 	if (current_index >= ps->performance_level_count) {
7576 		seq_printf(m, "invalid dpm profile %d\n", current_index);
7577 	} else {
7578 		pl = &ps->performance_levels[current_index];
7579 		seq_printf(m, "uvd    vclk: %d dclk: %d\n", rps->vclk, rps->dclk);
7580 		seq_printf(m, "power level %d    sclk: %u mclk: %u vddc: %u vddci: %u pcie gen: %u\n",
7581 			   current_index, pl->sclk, pl->mclk, pl->vddc, pl->vddci, pl->pcie_gen + 1);
7582 	}
7583 }
7584 
7585 static int si_dpm_set_interrupt_state(struct amdgpu_device *adev,
7586 				      struct amdgpu_irq_src *source,
7587 				      unsigned type,
7588 				      enum amdgpu_interrupt_state state)
7589 {
7590 	u32 cg_thermal_int;
7591 
7592 	switch (type) {
7593 	case AMDGPU_THERMAL_IRQ_LOW_TO_HIGH:
7594 		switch (state) {
7595 		case AMDGPU_IRQ_STATE_DISABLE:
7596 			cg_thermal_int = RREG32_SMC(CG_THERMAL_INT);
7597 			cg_thermal_int |= THERM_INT_MASK_HIGH;
7598 			WREG32_SMC(CG_THERMAL_INT, cg_thermal_int);
7599 			break;
7600 		case AMDGPU_IRQ_STATE_ENABLE:
7601 			cg_thermal_int = RREG32_SMC(CG_THERMAL_INT);
7602 			cg_thermal_int &= ~THERM_INT_MASK_HIGH;
7603 			WREG32_SMC(CG_THERMAL_INT, cg_thermal_int);
7604 			break;
7605 		default:
7606 			break;
7607 		}
7608 		break;
7609 
7610 	case AMDGPU_THERMAL_IRQ_HIGH_TO_LOW:
7611 		switch (state) {
7612 		case AMDGPU_IRQ_STATE_DISABLE:
7613 			cg_thermal_int = RREG32_SMC(CG_THERMAL_INT);
7614 			cg_thermal_int |= THERM_INT_MASK_LOW;
7615 			WREG32_SMC(CG_THERMAL_INT, cg_thermal_int);
7616 			break;
7617 		case AMDGPU_IRQ_STATE_ENABLE:
7618 			cg_thermal_int = RREG32_SMC(CG_THERMAL_INT);
7619 			cg_thermal_int &= ~THERM_INT_MASK_LOW;
7620 			WREG32_SMC(CG_THERMAL_INT, cg_thermal_int);
7621 			break;
7622 		default:
7623 			break;
7624 		}
7625 		break;
7626 
7627 	default:
7628 		break;
7629 	}
7630 	return 0;
7631 }
7632 
7633 static int si_dpm_process_interrupt(struct amdgpu_device *adev,
7634 				    struct amdgpu_irq_src *source,
7635 				    struct amdgpu_iv_entry *entry)
7636 {
7637 	bool queue_thermal = false;
7638 
7639 	if (entry == NULL)
7640 		return -EINVAL;
7641 
7642 	switch (entry->src_id) {
7643 	case 230: /* thermal low to high */
7644 		DRM_DEBUG("IH: thermal low to high\n");
7645 		adev->pm.dpm.thermal.high_to_low = false;
7646 		queue_thermal = true;
7647 		break;
7648 	case 231: /* thermal high to low */
7649 		DRM_DEBUG("IH: thermal high to low\n");
7650 		adev->pm.dpm.thermal.high_to_low = true;
7651 		queue_thermal = true;
7652 		break;
7653 	default:
7654 		break;
7655 	}
7656 
7657 	if (queue_thermal)
7658 		schedule_work(&adev->pm.dpm.thermal.work);
7659 
7660 	return 0;
7661 }
7662 
7663 static int si_dpm_late_init(void *handle)
7664 {
7665 	int ret;
7666 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
7667 
7668 	if (!adev->pm.dpm_enabled)
7669 		return 0;
7670 
7671 	ret = si_set_temperature_range(adev);
7672 	if (ret)
7673 		return ret;
7674 #if 0 //TODO ?
7675 	si_dpm_powergate_uvd(adev, true);
7676 #endif
7677 	return 0;
7678 }
7679 
7680 /**
7681  * si_dpm_init_microcode - load ucode images from disk
7682  *
7683  * @adev: amdgpu_device pointer
7684  *
7685  * Use the firmware interface to load the ucode images into
7686  * the driver (not loaded into hw).
7687  * Returns 0 on success, error on failure.
7688  */
7689 static int si_dpm_init_microcode(struct amdgpu_device *adev)
7690 {
7691 	const char *chip_name;
7692 	char fw_name[30];
7693 	int err;
7694 
7695 	DRM_DEBUG("\n");
7696 	switch (adev->asic_type) {
7697 	case CHIP_TAHITI:
7698 		chip_name = "tahiti";
7699 		break;
7700 	case CHIP_PITCAIRN:
7701 		if ((adev->pdev->revision == 0x81) &&
7702 		    ((adev->pdev->device == 0x6810) ||
7703 		    (adev->pdev->device == 0x6811)))
7704 			chip_name = "pitcairn_k";
7705 		else
7706 			chip_name = "pitcairn";
7707 		break;
7708 	case CHIP_VERDE:
7709 		if (((adev->pdev->device == 0x6820) &&
7710 			((adev->pdev->revision == 0x81) ||
7711 			(adev->pdev->revision == 0x83))) ||
7712 		    ((adev->pdev->device == 0x6821) &&
7713 			((adev->pdev->revision == 0x83) ||
7714 			(adev->pdev->revision == 0x87))) ||
7715 		    ((adev->pdev->revision == 0x87) &&
7716 			((adev->pdev->device == 0x6823) ||
7717 			(adev->pdev->device == 0x682b))))
7718 			chip_name = "verde_k";
7719 		else
7720 			chip_name = "verde";
7721 		break;
7722 	case CHIP_OLAND:
7723 		if (((adev->pdev->revision == 0x81) &&
7724 			((adev->pdev->device == 0x6600) ||
7725 			(adev->pdev->device == 0x6604) ||
7726 			(adev->pdev->device == 0x6605) ||
7727 			(adev->pdev->device == 0x6610))) ||
7728 		    ((adev->pdev->revision == 0x83) &&
7729 			(adev->pdev->device == 0x6610)))
7730 			chip_name = "oland_k";
7731 		else
7732 			chip_name = "oland";
7733 		break;
7734 	case CHIP_HAINAN:
7735 		if (((adev->pdev->revision == 0x81) &&
7736 			(adev->pdev->device == 0x6660)) ||
7737 		    ((adev->pdev->revision == 0x83) &&
7738 			((adev->pdev->device == 0x6660) ||
7739 			(adev->pdev->device == 0x6663) ||
7740 			(adev->pdev->device == 0x6665) ||
7741 			 (adev->pdev->device == 0x6667))))
7742 			chip_name = "hainan_k";
7743 		else if ((adev->pdev->revision == 0xc3) &&
7744 			 (adev->pdev->device == 0x6665))
7745 			chip_name = "banks_k_2";
7746 		else
7747 			chip_name = "hainan";
7748 		break;
7749 	default: BUG();
7750 	}
7751 
7752 	snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_smc.bin", chip_name);
7753 	err = request_firmware(&adev->pm.fw, fw_name, adev->dev);
7754 	if (err)
7755 		goto out;
7756 	err = amdgpu_ucode_validate(adev->pm.fw);
7757 
7758 out:
7759 	if (err) {
7760 		DRM_ERROR("si_smc: Failed to load firmware. err = %d\"%s\"\n",
7761 			  err, fw_name);
7762 		release_firmware(adev->pm.fw);
7763 		adev->pm.fw = NULL;
7764 	}
7765 	return err;
7766 
7767 }
7768 
7769 static int si_dpm_sw_init(void *handle)
7770 {
7771 	int ret;
7772 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
7773 
7774 	ret = amdgpu_irq_add_id(adev, AMDGPU_IRQ_CLIENTID_LEGACY, 230, &adev->pm.dpm.thermal.irq);
7775 	if (ret)
7776 		return ret;
7777 
7778 	ret = amdgpu_irq_add_id(adev, AMDGPU_IRQ_CLIENTID_LEGACY, 231, &adev->pm.dpm.thermal.irq);
7779 	if (ret)
7780 		return ret;
7781 
7782 	/* default to balanced state */
7783 	adev->pm.dpm.state = POWER_STATE_TYPE_BALANCED;
7784 	adev->pm.dpm.user_state = POWER_STATE_TYPE_BALANCED;
7785 	adev->pm.dpm.forced_level = AMD_DPM_FORCED_LEVEL_AUTO;
7786 	adev->pm.default_sclk = adev->clock.default_sclk;
7787 	adev->pm.default_mclk = adev->clock.default_mclk;
7788 	adev->pm.current_sclk = adev->clock.default_sclk;
7789 	adev->pm.current_mclk = adev->clock.default_mclk;
7790 	adev->pm.int_thermal_type = THERMAL_TYPE_NONE;
7791 
7792 	if (amdgpu_dpm == 0)
7793 		return 0;
7794 
7795 	ret = si_dpm_init_microcode(adev);
7796 	if (ret)
7797 		return ret;
7798 
7799 	INIT_WORK(&adev->pm.dpm.thermal.work, amdgpu_dpm_thermal_work_handler);
7800 	ret = si_dpm_init(adev);
7801 	if (ret)
7802 		goto dpm_failed;
7803 	adev->pm.dpm.current_ps = adev->pm.dpm.requested_ps = adev->pm.dpm.boot_ps;
7804 	if (amdgpu_dpm == 1)
7805 		amdgpu_pm_print_power_states(adev);
7806 	DRM_INFO("amdgpu: dpm initialized\n");
7807 
7808 	return 0;
7809 
7810 dpm_failed:
7811 	si_dpm_fini(adev);
7812 	DRM_ERROR("amdgpu: dpm initialization failed\n");
7813 	return ret;
7814 }
7815 
7816 static int si_dpm_sw_fini(void *handle)
7817 {
7818 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
7819 
7820 	flush_work(&adev->pm.dpm.thermal.work);
7821 
7822 	si_dpm_fini(adev);
7823 
7824 	return 0;
7825 }
7826 
7827 static int si_dpm_hw_init(void *handle)
7828 {
7829 	int ret;
7830 
7831 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
7832 
7833 	if (!amdgpu_dpm)
7834 		return 0;
7835 
7836 	si_dpm_setup_asic(adev);
7837 	ret = si_dpm_enable(adev);
7838 	if (ret)
7839 		adev->pm.dpm_enabled = false;
7840 	else
7841 		adev->pm.dpm_enabled = true;
7842 	amdgpu_legacy_dpm_compute_clocks(adev);
7843 	return ret;
7844 }
7845 
7846 static int si_dpm_hw_fini(void *handle)
7847 {
7848 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
7849 
7850 	if (adev->pm.dpm_enabled)
7851 		si_dpm_disable(adev);
7852 
7853 	return 0;
7854 }
7855 
7856 static int si_dpm_suspend(void *handle)
7857 {
7858 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
7859 
7860 	if (adev->pm.dpm_enabled) {
7861 		/* disable dpm */
7862 		si_dpm_disable(adev);
7863 		/* reset the power state */
7864 		adev->pm.dpm.current_ps = adev->pm.dpm.requested_ps = adev->pm.dpm.boot_ps;
7865 	}
7866 	return 0;
7867 }
7868 
7869 static int si_dpm_resume(void *handle)
7870 {
7871 	int ret;
7872 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
7873 
7874 	if (adev->pm.dpm_enabled) {
7875 		/* asic init will reset to the boot state */
7876 		si_dpm_setup_asic(adev);
7877 		ret = si_dpm_enable(adev);
7878 		if (ret)
7879 			adev->pm.dpm_enabled = false;
7880 		else
7881 			adev->pm.dpm_enabled = true;
7882 		if (adev->pm.dpm_enabled)
7883 			amdgpu_legacy_dpm_compute_clocks(adev);
7884 	}
7885 	return 0;
7886 }
7887 
7888 static bool si_dpm_is_idle(void *handle)
7889 {
7890 	/* XXX */
7891 	return true;
7892 }
7893 
7894 static int si_dpm_wait_for_idle(void *handle)
7895 {
7896 	/* XXX */
7897 	return 0;
7898 }
7899 
7900 static int si_dpm_soft_reset(void *handle)
7901 {
7902 	return 0;
7903 }
7904 
7905 static int si_dpm_set_clockgating_state(void *handle,
7906 					enum amd_clockgating_state state)
7907 {
7908 	return 0;
7909 }
7910 
7911 static int si_dpm_set_powergating_state(void *handle,
7912 					enum amd_powergating_state state)
7913 {
7914 	return 0;
7915 }
7916 
7917 /* get temperature in millidegrees */
7918 static int si_dpm_get_temp(void *handle)
7919 {
7920 	u32 temp;
7921 	int actual_temp = 0;
7922 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
7923 
7924 	temp = (RREG32(CG_MULT_THERMAL_STATUS) & CTF_TEMP_MASK) >>
7925 		CTF_TEMP_SHIFT;
7926 
7927 	if (temp & 0x200)
7928 		actual_temp = 255;
7929 	else
7930 		actual_temp = temp & 0x1ff;
7931 
7932 	actual_temp = (actual_temp * 1000);
7933 
7934 	return actual_temp;
7935 }
7936 
7937 static u32 si_dpm_get_sclk(void *handle, bool low)
7938 {
7939 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
7940 	struct evergreen_power_info *eg_pi = evergreen_get_pi(adev);
7941 	struct  si_ps *requested_state = si_get_ps(&eg_pi->requested_rps);
7942 
7943 	if (low)
7944 		return requested_state->performance_levels[0].sclk;
7945 	else
7946 		return requested_state->performance_levels[requested_state->performance_level_count - 1].sclk;
7947 }
7948 
7949 static u32 si_dpm_get_mclk(void *handle, bool low)
7950 {
7951 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
7952 	struct evergreen_power_info *eg_pi = evergreen_get_pi(adev);
7953 	struct  si_ps *requested_state = si_get_ps(&eg_pi->requested_rps);
7954 
7955 	if (low)
7956 		return requested_state->performance_levels[0].mclk;
7957 	else
7958 		return requested_state->performance_levels[requested_state->performance_level_count - 1].mclk;
7959 }
7960 
7961 static void si_dpm_print_power_state(void *handle,
7962 				     void *current_ps)
7963 {
7964 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
7965 	struct amdgpu_ps *rps = (struct amdgpu_ps *)current_ps;
7966 	struct  si_ps *ps = si_get_ps(rps);
7967 	struct rv7xx_pl *pl;
7968 	int i;
7969 
7970 	amdgpu_dpm_print_class_info(rps->class, rps->class2);
7971 	amdgpu_dpm_print_cap_info(rps->caps);
7972 	DRM_INFO("\tuvd    vclk: %d dclk: %d\n", rps->vclk, rps->dclk);
7973 	for (i = 0; i < ps->performance_level_count; i++) {
7974 		pl = &ps->performance_levels[i];
7975 		if (adev->asic_type >= CHIP_TAHITI)
7976 			DRM_INFO("\t\tpower level %d    sclk: %u mclk: %u vddc: %u vddci: %u pcie gen: %u\n",
7977 				 i, pl->sclk, pl->mclk, pl->vddc, pl->vddci, pl->pcie_gen + 1);
7978 		else
7979 			DRM_INFO("\t\tpower level %d    sclk: %u mclk: %u vddc: %u vddci: %u\n",
7980 				 i, pl->sclk, pl->mclk, pl->vddc, pl->vddci);
7981 	}
7982 	amdgpu_dpm_print_ps_status(adev, rps);
7983 }
7984 
7985 static int si_dpm_early_init(void *handle)
7986 {
7987 
7988 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
7989 
7990 	adev->powerplay.pp_funcs = &si_dpm_funcs;
7991 	adev->powerplay.pp_handle = adev;
7992 	si_dpm_set_irq_funcs(adev);
7993 	return 0;
7994 }
7995 
7996 static inline bool si_are_power_levels_equal(const struct rv7xx_pl  *si_cpl1,
7997 						const struct rv7xx_pl *si_cpl2)
7998 {
7999 	return ((si_cpl1->mclk == si_cpl2->mclk) &&
8000 		  (si_cpl1->sclk == si_cpl2->sclk) &&
8001 		  (si_cpl1->pcie_gen == si_cpl2->pcie_gen) &&
8002 		  (si_cpl1->vddc == si_cpl2->vddc) &&
8003 		  (si_cpl1->vddci == si_cpl2->vddci));
8004 }
8005 
8006 static int si_check_state_equal(void *handle,
8007 				void *current_ps,
8008 				void *request_ps,
8009 				bool *equal)
8010 {
8011 	struct si_ps *si_cps;
8012 	struct si_ps *si_rps;
8013 	int i;
8014 	struct amdgpu_ps *cps = (struct amdgpu_ps *)current_ps;
8015 	struct amdgpu_ps *rps = (struct amdgpu_ps *)request_ps;
8016 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
8017 
8018 	if (adev == NULL || cps == NULL || rps == NULL || equal == NULL)
8019 		return -EINVAL;
8020 
8021 	si_cps = si_get_ps((struct amdgpu_ps *)cps);
8022 	si_rps = si_get_ps((struct amdgpu_ps *)rps);
8023 
8024 	if (si_cps == NULL) {
8025 		printk("si_cps is NULL\n");
8026 		*equal = false;
8027 		return 0;
8028 	}
8029 
8030 	if (si_cps->performance_level_count != si_rps->performance_level_count) {
8031 		*equal = false;
8032 		return 0;
8033 	}
8034 
8035 	for (i = 0; i < si_cps->performance_level_count; i++) {
8036 		if (!si_are_power_levels_equal(&(si_cps->performance_levels[i]),
8037 					&(si_rps->performance_levels[i]))) {
8038 			*equal = false;
8039 			return 0;
8040 		}
8041 	}
8042 
8043 	/* If all performance levels are the same try to use the UVD clocks to break the tie.*/
8044 	*equal = ((cps->vclk == rps->vclk) && (cps->dclk == rps->dclk));
8045 	*equal &= ((cps->evclk == rps->evclk) && (cps->ecclk == rps->ecclk));
8046 
8047 	return 0;
8048 }
8049 
8050 static int si_dpm_read_sensor(void *handle, int idx,
8051 			      void *value, int *size)
8052 {
8053 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
8054 	struct evergreen_power_info *eg_pi = evergreen_get_pi(adev);
8055 	struct amdgpu_ps *rps = &eg_pi->current_rps;
8056 	struct  si_ps *ps = si_get_ps(rps);
8057 	uint32_t sclk, mclk;
8058 	u32 pl_index =
8059 		(RREG32(TARGET_AND_CURRENT_PROFILE_INDEX) & CURRENT_STATE_INDEX_MASK) >>
8060 		CURRENT_STATE_INDEX_SHIFT;
8061 
8062 	/* size must be at least 4 bytes for all sensors */
8063 	if (*size < 4)
8064 		return -EINVAL;
8065 
8066 	switch (idx) {
8067 	case AMDGPU_PP_SENSOR_GFX_SCLK:
8068 		if (pl_index < ps->performance_level_count) {
8069 			sclk = ps->performance_levels[pl_index].sclk;
8070 			*((uint32_t *)value) = sclk;
8071 			*size = 4;
8072 			return 0;
8073 		}
8074 		return -EINVAL;
8075 	case AMDGPU_PP_SENSOR_GFX_MCLK:
8076 		if (pl_index < ps->performance_level_count) {
8077 			mclk = ps->performance_levels[pl_index].mclk;
8078 			*((uint32_t *)value) = mclk;
8079 			*size = 4;
8080 			return 0;
8081 		}
8082 		return -EINVAL;
8083 	case AMDGPU_PP_SENSOR_GPU_TEMP:
8084 		*((uint32_t *)value) = si_dpm_get_temp(adev);
8085 		*size = 4;
8086 		return 0;
8087 	default:
8088 		return -EOPNOTSUPP;
8089 	}
8090 }
8091 
8092 static const struct amd_ip_funcs si_dpm_ip_funcs = {
8093 	.name = "si_dpm",
8094 	.early_init = si_dpm_early_init,
8095 	.late_init = si_dpm_late_init,
8096 	.sw_init = si_dpm_sw_init,
8097 	.sw_fini = si_dpm_sw_fini,
8098 	.hw_init = si_dpm_hw_init,
8099 	.hw_fini = si_dpm_hw_fini,
8100 	.suspend = si_dpm_suspend,
8101 	.resume = si_dpm_resume,
8102 	.is_idle = si_dpm_is_idle,
8103 	.wait_for_idle = si_dpm_wait_for_idle,
8104 	.soft_reset = si_dpm_soft_reset,
8105 	.set_clockgating_state = si_dpm_set_clockgating_state,
8106 	.set_powergating_state = si_dpm_set_powergating_state,
8107 };
8108 
8109 const struct amdgpu_ip_block_version si_smu_ip_block =
8110 {
8111 	.type = AMD_IP_BLOCK_TYPE_SMC,
8112 	.major = 6,
8113 	.minor = 0,
8114 	.rev = 0,
8115 	.funcs = &si_dpm_ip_funcs,
8116 };
8117 
8118 static const struct amd_pm_funcs si_dpm_funcs = {
8119 	.pre_set_power_state = &si_dpm_pre_set_power_state,
8120 	.set_power_state = &si_dpm_set_power_state,
8121 	.post_set_power_state = &si_dpm_post_set_power_state,
8122 	.display_configuration_changed = &si_dpm_display_configuration_changed,
8123 	.get_sclk = &si_dpm_get_sclk,
8124 	.get_mclk = &si_dpm_get_mclk,
8125 	.print_power_state = &si_dpm_print_power_state,
8126 	.debugfs_print_current_performance_level = &si_dpm_debugfs_print_current_performance_level,
8127 	.force_performance_level = &si_dpm_force_performance_level,
8128 	.set_powergating_by_smu = &si_set_powergating_by_smu,
8129 	.vblank_too_short = &si_dpm_vblank_too_short,
8130 	.set_fan_control_mode = &si_dpm_set_fan_control_mode,
8131 	.get_fan_control_mode = &si_dpm_get_fan_control_mode,
8132 	.set_fan_speed_pwm = &si_dpm_set_fan_speed_pwm,
8133 	.get_fan_speed_pwm = &si_dpm_get_fan_speed_pwm,
8134 	.check_state_equal = &si_check_state_equal,
8135 	.get_vce_clock_state = amdgpu_get_vce_clock_state,
8136 	.read_sensor = &si_dpm_read_sensor,
8137 	.pm_compute_clocks = amdgpu_legacy_dpm_compute_clocks,
8138 };
8139 
8140 static const struct amdgpu_irq_src_funcs si_dpm_irq_funcs = {
8141 	.set = si_dpm_set_interrupt_state,
8142 	.process = si_dpm_process_interrupt,
8143 };
8144 
8145 static void si_dpm_set_irq_funcs(struct amdgpu_device *adev)
8146 {
8147 	adev->pm.dpm.thermal.irq.num_types = AMDGPU_THERMAL_IRQ_LAST;
8148 	adev->pm.dpm.thermal.irq.funcs = &si_dpm_irq_funcs;
8149 }
8150 
8151