blob: de5ad2ca5c5e2d8d82d1e26a0e76f88f67524d4e [file] [log] [blame]
Aaron Durbindf214402015-12-14 16:44:26 -06001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2015 Google Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16
Gaggery Tsaie1a75d42018-01-02 12:13:40 +080017#include <device/pci_ids.h>
Patrick Rudolphe56189c2018-04-18 10:11:59 +020018#include <device/pci_ops.h>
Rizwan Qureshi1222a732016-08-23 14:31:23 +053019#include <fsp/api.h>
20#include <soc/ramstage.h>
Aaron Durbindf214402015-12-14 16:44:26 -060021#include <soc/vr_config.h>
Patrick Rudolph50aebaf82019-08-14 10:07:38 +020022#include <console/console.h>
Patrick Rudolph69e826d2019-08-14 10:23:30 +020023#include <intelblocks/cpulib.h>
Gaggery Tsaie1a75d42018-01-02 12:13:40 +080024
Aaron Durbindf214402015-12-14 16:44:26 -060025/* Default values for domain configuration. PSI3 and PSI4 are disabled. */
26static const struct vr_config default_configs[NUM_VR_DOMAINS] = {
27 [VR_SYSTEM_AGENT] = {
28 .vr_config_enable = 1,
29 .psi1threshold = VR_CFG_AMP(20),
30 .psi2threshold = VR_CFG_AMP(4),
31 .psi3threshold = VR_CFG_AMP(1),
32 .psi3enable = 0,
33 .psi4enable = 0,
34 .imon_slope = 0x0,
35 .imon_offset = 0x0,
36 .icc_max = VR_CFG_AMP(7),
37 .voltage_limit = 1520,
38 },
39 [VR_IA_CORE] = {
40 .vr_config_enable = 1,
41 .psi1threshold = VR_CFG_AMP(20),
42 .psi2threshold = VR_CFG_AMP(5),
43 .psi3threshold = VR_CFG_AMP(1),
44 .psi3enable = 0,
45 .psi4enable = 0,
46 .imon_slope = 0x0,
47 .imon_offset = 0x0,
48 .icc_max = VR_CFG_AMP(34),
49 .voltage_limit = 1520,
50 },
Julius Wernercd49cce2019-03-05 16:53:33 -080051#if CONFIG(PLATFORM_USES_FSP1_1)
Aaron Durbindf214402015-12-14 16:44:26 -060052 [VR_RING] = {
53 .vr_config_enable = 1,
54 .psi1threshold = VR_CFG_AMP(20),
55 .psi2threshold = VR_CFG_AMP(5),
56 .psi3threshold = VR_CFG_AMP(1),
57 .psi3enable = 0,
58 .psi4enable = 0,
59 .imon_slope = 0x0,
60 .imon_offset = 0x0,
61 .icc_max = VR_CFG_AMP(34),
62 .voltage_limit = 1520,
63 },
Duncan Laurie4fa8a6f2017-03-14 16:37:55 -070064#endif
Aaron Durbindf214402015-12-14 16:44:26 -060065 [VR_GT_UNSLICED] = {
66 .vr_config_enable = 1,
67 .psi1threshold = VR_CFG_AMP(20),
68 .psi2threshold = VR_CFG_AMP(5),
69 .psi3threshold = VR_CFG_AMP(1),
70 .psi3enable = 0,
71 .psi4enable = 0,
72 .imon_slope = 0x0,
73 .imon_offset = 0x0,
74 .icc_max = VR_CFG_AMP(35),
75 .voltage_limit = 1520,
76 },
77 [VR_GT_SLICED] = {
78 .vr_config_enable = 1,
79 .psi1threshold = VR_CFG_AMP(20),
80 .psi2threshold = VR_CFG_AMP(5),
81 .psi3threshold = VR_CFG_AMP(1),
82 .psi3enable = 0,
83 .psi4enable = 0,
84 .imon_slope = 0x0,
85 .imon_offset = 0x0,
86 .icc_max = VR_CFG_AMP(35),
87 .voltage_limit = 1520,
88 },
89};
90
Patrick Rudolph50aebaf82019-08-14 10:07:38 +020091static uint16_t get_sku_icc_max(int domain)
Gaggery Tsaie1a75d42018-01-02 12:13:40 +080092{
Patrick Rudolph69e826d2019-08-14 10:23:30 +020093 const uint16_t tdp = cpu_get_power_max();
94
Patrick Rudolph50aebaf82019-08-14 10:07:38 +020095 static uint16_t mch_id = 0, igd_id = 0, lpc_id = 0;
96 if (!mch_id) {
97 struct device *dev = pcidev_path_on_root(SA_DEVFN_ROOT);
98 mch_id = pci_read_config16(dev, PCI_DEVICE_ID);
99 }
100 if (!igd_id) {
101 struct device *dev = pcidev_path_on_root(SA_DEVFN_IGD);
Patrick Rudolph69e826d2019-08-14 10:23:30 +0200102 if (dev)
103 igd_id = pci_read_config16(dev, PCI_DEVICE_ID);
104 else
105 igd_id = 0xffff;
Patrick Rudolph50aebaf82019-08-14 10:07:38 +0200106 }
107 if (!lpc_id) {
108 struct device *dev = pcidev_path_on_root(PCH_DEVFN_LPC);
109 lpc_id = pci_read_config16(dev, PCI_DEVICE_ID);
110 }
Gaggery Tsaie1a75d42018-01-02 12:13:40 +0800111
Patrick Rudolph50aebaf82019-08-14 10:07:38 +0200112 /*
Patrick Rudolph69e826d2019-08-14 10:23:30 +0200113 * Iccmax table from Doc #559100 Section 7.2 DC Specifications, the
114 * Iccmax is the same among KBL-Y but KBL-U/R.
115 * Addendum for AML-Y #594883, IccMax for IA core is 28A.
116 * KBL-S #335195, KBL-H #335190
117 * +----------------+-------------+---------------+------+-----+
118 * | Domain/Setting | SA | IA | GTUS | GTS |
119 * +----------------+-------------+---------------+------+-----+
Maxim Polyakovb4383fc2019-08-29 16:51:37 +0300120 * | IccMax(KBL-S) | 11.1A | 100A | 48A | 48A |
121 * | | | ... | 45A | 45A |
122 * | | | 40A | 35A | 35A |
Patrick Rudolph69e826d2019-08-14 10:23:30 +0200123 * +----------------+-------------+---------------+------+-----+
Maxim Polyakovb4383fc2019-08-29 16:51:37 +0300124 * | IccMax(KBL-H) | 11.1A (45W) | 68A | 55A | 55A |
125 * | | 6.6A (18W) | 60A | | |
Patrick Rudolph69e826d2019-08-14 10:23:30 +0200126 * +----------------+-------------+---------------+------+-----+
127 * | IccMax(KBL-U/R)| 6A(U42) | 64A(U42) | 31A | 31A |
128 * | | 4.5A(Others)| 29A(P/C) | | |
129 * | | | 32A(i3/i5) | | |
130 * +----------------+-------------+---------------+------+-----+
131 * | IccMax(KBL-Y) | 4.1A | 24A | 24A | 24A |
132 * +----------------+-------------+---------------+------+-----+
133 * | IccMax(AML-Y) | 4.1A | 28A | 24A | 24A |
134 * +----------------+-------------+---------------+------+-----+
135 */
Gaggery Tsaie1a75d42018-01-02 12:13:40 +0800136
Patrick Rudolph50aebaf82019-08-14 10:07:38 +0200137 switch (mch_id) {
Patrick Rudolph69e826d2019-08-14 10:23:30 +0200138 case PCI_DEVICE_ID_INTEL_KBL_ID_S: {
139 uint16_t icc_max[NUM_VR_DOMAINS] = {
140 VR_CFG_AMP(11.1),
141 VR_CFG_AMP(40),
Maxim Polyakovb4383fc2019-08-29 16:51:37 +0300142 VR_CFG_AMP(48),
143 VR_CFG_AMP(48),
Patrick Rudolph69e826d2019-08-14 10:23:30 +0200144 };
145 if (tdp >= 54)
146 icc_max[VR_IA_CORE] = VR_CFG_AMP(58);
147 else if (tdp >= 51)
148 icc_max[VR_IA_CORE] = VR_CFG_AMP(45);
149
150 return icc_max[domain];
151
152 }
153 case PCI_DEVICE_ID_INTEL_KBL_ID_DT_2: /* fallthrough */
154 case PCI_DEVICE_ID_INTEL_KBL_ID_DT: {
155 uint16_t icc_max[NUM_VR_DOMAINS] = {
156 VR_CFG_AMP(11.1),
157 VR_CFG_AMP(66),
Maxim Polyakovb4383fc2019-08-29 16:51:37 +0300158 VR_CFG_AMP(45),
159 VR_CFG_AMP(45),
Patrick Rudolph69e826d2019-08-14 10:23:30 +0200160 };
161 if (tdp >= 91)
162 icc_max[VR_IA_CORE] = VR_CFG_AMP(100);
163 else if (tdp >= 65)
164 icc_max[VR_IA_CORE] = VR_CFG_AMP(79);
Maxim Polyakovb4383fc2019-08-29 16:51:37 +0300165 else if (tdp >= 35) {
166 icc_max[VR_GT_UNSLICED] = VR_CFG_AMP(35);
167 icc_max[VR_GT_SLICED] = VR_CFG_AMP(35);
168 }
Patrick Rudolph69e826d2019-08-14 10:23:30 +0200169
170 return icc_max[domain];
171 }
172 case PCI_DEVICE_ID_INTEL_KBL_ID_H: {
173 uint16_t icc_max[NUM_VR_DOMAINS] = {
174 VR_CFG_AMP(6.6),
175 VR_CFG_AMP(60),
176 VR_CFG_AMP(55),
177 VR_CFG_AMP(55),
178 };
179 if (tdp >= 45) {
180 icc_max[VR_SYSTEM_AGENT] = VR_CFG_AMP(11.1);
181 icc_max[VR_IA_CORE] = VR_CFG_AMP(68);
182 }
183
184 return icc_max[domain];
185 }
Patrick Rudolph50aebaf82019-08-14 10:07:38 +0200186 case PCI_DEVICE_ID_INTEL_KBL_U_R: {
187 static const uint16_t icc_max[NUM_VR_DOMAINS] = {
188 VR_CFG_AMP(6),
189 VR_CFG_AMP(64),
190 VR_CFG_AMP(31),
191 VR_CFG_AMP(31),
192 };
193 return icc_max[domain];
194 }
195 case PCI_DEVICE_ID_INTEL_KBL_ID_Y: {
196 uint16_t icc_max[NUM_VR_DOMAINS] = {
197 VR_CFG_AMP(4.1),
198 VR_CFG_AMP(24),
199 VR_CFG_AMP(24),
200 VR_CFG_AMP(24),
201 };
Gaggery Tsaie1a75d42018-01-02 12:13:40 +0800202
Patrick Rudolph50aebaf82019-08-14 10:07:38 +0200203 if (igd_id == PCI_DEVICE_ID_INTEL_AML_GT2_ULX)
204 icc_max[VR_IA_CORE] = VR_CFG_AMP(28);
Gaggery Tsaie1a75d42018-01-02 12:13:40 +0800205
Patrick Rudolph50aebaf82019-08-14 10:07:38 +0200206 return icc_max[domain];
207 }
208 case PCI_DEVICE_ID_INTEL_KBL_ID_U: {
209 uint16_t icc_max[NUM_VR_DOMAINS] = {
210 VR_CFG_AMP(4.5),
211 VR_CFG_AMP(32),
212 VR_CFG_AMP(31),
213 VR_CFG_AMP(31),
214 };
Gaggery Tsaie1a75d42018-01-02 12:13:40 +0800215
Patrick Rudolph50aebaf82019-08-14 10:07:38 +0200216 if (igd_id == PCI_DEVICE_ID_INTEL_SPT_LP_U_BASE_HDCP22)
217 icc_max[VR_IA_CORE] = VR_CFG_AMP(29);
218
219 return icc_max[domain];
220 }
221 default:
222 printk(BIOS_ERR, "ERROR: Unknown MCH in VR-config\n");
223 }
224 return 0;
Gaggery Tsaie1a75d42018-01-02 12:13:40 +0800225}
226
Patrick Rudolph9a016232019-08-14 12:10:48 +0200227#if CONFIG(PLATFORM_USES_FSP2_0)
228static uint16_t get_sku_ac_dc_loadline(const int domain)
229{
230 static uint16_t mch_id = 0, igd_id = 0;
231 if (!mch_id) {
232 struct device *dev = pcidev_path_on_root(SA_DEVFN_ROOT);
233 mch_id = pci_read_config16(dev, PCI_DEVICE_ID);
234 }
235 if (!igd_id) {
236 struct device *dev = pcidev_path_on_root(SA_DEVFN_IGD);
237 if (dev)
238 igd_id = pci_read_config16(dev, PCI_DEVICE_ID);
239 else
240 igd_id = 0xffff;
241 }
242
243 switch (mch_id) {
244 case PCI_DEVICE_ID_INTEL_KBL_ID_S: /* fallthrough */
245 case PCI_DEVICE_ID_INTEL_KBL_ID_DT: /* fallthrough */
246 case PCI_DEVICE_ID_INTEL_KBL_ID_DT_2: {
247 static const uint16_t loadline[NUM_VR_DOMAINS] = {
248 VR_CFG_MOHMS(0), /* Not specified */
249 VR_CFG_MOHMS(2.1),
250 VR_CFG_MOHMS(3.1),
251 VR_CFG_MOHMS(3.1),
252 };
253
254 return loadline[domain];
255 }
256 case PCI_DEVICE_ID_INTEL_KBL_ID_H: {
257 static const uint16_t loadline[NUM_VR_DOMAINS] = {
258 VR_CFG_MOHMS(10),
259 VR_CFG_MOHMS(1.8),
260 VR_CFG_MOHMS(2.65),
261 VR_CFG_MOHMS(2.65),
262 };
263
264 return loadline[domain];
265 }
266 case PCI_DEVICE_ID_INTEL_KBL_ID_Y: {
267 uint16_t loadline[NUM_VR_DOMAINS] = {
268 VR_CFG_MOHMS(18),
269 VR_CFG_MOHMS(5.9),
270 VR_CFG_MOHMS(5.7),
271 VR_CFG_MOHMS(5.7),
272 };
273
274 if (igd_id == PCI_DEVICE_ID_INTEL_AML_GT2_ULX)
275 loadline[VR_IA_CORE] = VR_CFG_MOHMS(4);
276
277 return loadline[domain];
278 }
279 case PCI_DEVICE_ID_INTEL_KBL_U_R: /* fallthrough */
280 case PCI_DEVICE_ID_INTEL_KBL_ID_U: {
281 uint16_t loadline[NUM_VR_DOMAINS] = {
282 VR_CFG_MOHMS(10.3),
283 VR_CFG_MOHMS(2.4),
284 VR_CFG_MOHMS(3.1),
285 VR_CFG_MOHMS(3.1),
286 };
287
288 if (igd_id == PCI_DEVICE_ID_INTEL_SPT_LP_U_PREMIUM_HDCP22) {
Maxim Polyakov72359132019-10-03 16:50:04 +0300289 loadline[VR_GT_UNSLICED] = VR_CFG_MOHMS(2);
Patrick Rudolph9a016232019-08-14 12:10:48 +0200290 loadline[VR_GT_SLICED] = VR_CFG_MOHMS(6);
291 }
292
293 return loadline[domain];
294 }
295 default:
296 printk(BIOS_ERR, "ERROR: Unknown MCH in VR-config\n");
297 }
298 return 0;
299}
300#endif
301
Rizwan Qureshi1222a732016-08-23 14:31:23 +0530302void fill_vr_domain_config(void *params,
303 int domain, const struct vr_config *chip_cfg)
Aaron Durbindf214402015-12-14 16:44:26 -0600304{
Rizwan Qureshi1222a732016-08-23 14:31:23 +0530305 FSP_SIL_UPD *vr_params = (FSP_SIL_UPD *)params;
Aaron Durbindf214402015-12-14 16:44:26 -0600306 const struct vr_config *cfg;
307
308 if (domain < 0 || domain >= NUM_VR_DOMAINS)
309 return;
310
311 /* Use device tree override if requested. */
312 if (chip_cfg->vr_config_enable)
313 cfg = chip_cfg;
314 else
315 cfg = &default_configs[domain];
316
Rizwan Qureshi1222a732016-08-23 14:31:23 +0530317 vr_params->VrConfigEnable[domain] = cfg->vr_config_enable;
318 vr_params->Psi1Threshold[domain] = cfg->psi1threshold;
319 vr_params->Psi2Threshold[domain] = cfg->psi2threshold;
320 vr_params->Psi3Threshold[domain] = cfg->psi3threshold;
321 vr_params->Psi3Enable[domain] = cfg->psi3enable;
322 vr_params->Psi4Enable[domain] = cfg->psi4enable;
323 vr_params->ImonSlope[domain] = cfg->imon_slope;
324 vr_params->ImonOffset[domain] = cfg->imon_offset;
Patrick Rudolph50aebaf82019-08-14 10:07:38 +0200325 /* If board provided non-zero value, use it. */
326 if (cfg->icc_max)
327 vr_params->IccMax[domain] = cfg->icc_max;
328 else
329 vr_params->IccMax[domain] = get_sku_icc_max(domain);
Rizwan Qureshi1222a732016-08-23 14:31:23 +0530330 vr_params->VrVoltageLimit[domain] = cfg->voltage_limit;
Duncan Laurie86db4692017-03-14 16:40:06 -0700331
Julius Wernercd49cce2019-03-05 16:53:33 -0800332#if CONFIG(PLATFORM_USES_FSP2_0)
Patrick Rudolph9a016232019-08-14 12:10:48 +0200333 if (cfg->ac_loadline)
334 vr_params->AcLoadline[domain] = cfg->ac_loadline;
335 else
336 vr_params->AcLoadline[domain] = get_sku_ac_dc_loadline(domain);
337 if (cfg->dc_loadline)
338 vr_params->DcLoadline[domain] = cfg->dc_loadline;
339 else
340 vr_params->DcLoadline[domain] = get_sku_ac_dc_loadline(domain);
Duncan Laurie86db4692017-03-14 16:40:06 -0700341#endif
Aaron Durbindf214402015-12-14 16:44:26 -0600342}