blob: 33ce54ada506b539f41bc3c0dbe05982d63e9214 [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 * +----------------+-------------+---------------+------+-----+
120 * | IccMax(KBL-S) | 11.1A | 100A | 45A | 45A |
121 * | | | ... | | |
122 * | | | 40A | | |
123 * +----------------+-------------+---------------+------+-----+
124 * | IccMax(KBL-H) | 11.1A(45W) | 68A | 55A | 55A |
125 * | | 6.6A(Others)| 60A | | |
126 * +----------------+-------------+---------------+------+-----+
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),
142 VR_CFG_AMP(45),
143 VR_CFG_AMP(45),
144 };
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),
158 VR_CFG_AMP(55),
159 VR_CFG_AMP(55),
160 };
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);
165
166 return icc_max[domain];
167 }
168 case PCI_DEVICE_ID_INTEL_KBL_ID_H: {
169 uint16_t icc_max[NUM_VR_DOMAINS] = {
170 VR_CFG_AMP(6.6),
171 VR_CFG_AMP(60),
172 VR_CFG_AMP(55),
173 VR_CFG_AMP(55),
174 };
175 if (tdp >= 45) {
176 icc_max[VR_SYSTEM_AGENT] = VR_CFG_AMP(11.1);
177 icc_max[VR_IA_CORE] = VR_CFG_AMP(68);
178 }
179
180 return icc_max[domain];
181 }
Patrick Rudolph50aebaf82019-08-14 10:07:38 +0200182 case PCI_DEVICE_ID_INTEL_KBL_U_R: {
183 static const uint16_t icc_max[NUM_VR_DOMAINS] = {
184 VR_CFG_AMP(6),
185 VR_CFG_AMP(64),
186 VR_CFG_AMP(31),
187 VR_CFG_AMP(31),
188 };
189 return icc_max[domain];
190 }
191 case PCI_DEVICE_ID_INTEL_KBL_ID_Y: {
192 uint16_t icc_max[NUM_VR_DOMAINS] = {
193 VR_CFG_AMP(4.1),
194 VR_CFG_AMP(24),
195 VR_CFG_AMP(24),
196 VR_CFG_AMP(24),
197 };
Gaggery Tsaie1a75d42018-01-02 12:13:40 +0800198
Patrick Rudolph50aebaf82019-08-14 10:07:38 +0200199 if (igd_id == PCI_DEVICE_ID_INTEL_AML_GT2_ULX)
200 icc_max[VR_IA_CORE] = VR_CFG_AMP(28);
Gaggery Tsaie1a75d42018-01-02 12:13:40 +0800201
Patrick Rudolph50aebaf82019-08-14 10:07:38 +0200202 return icc_max[domain];
203 }
204 case PCI_DEVICE_ID_INTEL_KBL_ID_U: {
205 uint16_t icc_max[NUM_VR_DOMAINS] = {
206 VR_CFG_AMP(4.5),
207 VR_CFG_AMP(32),
208 VR_CFG_AMP(31),
209 VR_CFG_AMP(31),
210 };
Gaggery Tsaie1a75d42018-01-02 12:13:40 +0800211
Patrick Rudolph50aebaf82019-08-14 10:07:38 +0200212 if (igd_id == PCI_DEVICE_ID_INTEL_SPT_LP_U_BASE_HDCP22)
213 icc_max[VR_IA_CORE] = VR_CFG_AMP(29);
214
215 return icc_max[domain];
216 }
217 default:
218 printk(BIOS_ERR, "ERROR: Unknown MCH in VR-config\n");
219 }
220 return 0;
Gaggery Tsaie1a75d42018-01-02 12:13:40 +0800221}
222
Rizwan Qureshi1222a732016-08-23 14:31:23 +0530223void fill_vr_domain_config(void *params,
224 int domain, const struct vr_config *chip_cfg)
Aaron Durbindf214402015-12-14 16:44:26 -0600225{
Rizwan Qureshi1222a732016-08-23 14:31:23 +0530226 FSP_SIL_UPD *vr_params = (FSP_SIL_UPD *)params;
Aaron Durbindf214402015-12-14 16:44:26 -0600227 const struct vr_config *cfg;
228
229 if (domain < 0 || domain >= NUM_VR_DOMAINS)
230 return;
231
232 /* Use device tree override if requested. */
233 if (chip_cfg->vr_config_enable)
234 cfg = chip_cfg;
235 else
236 cfg = &default_configs[domain];
237
Rizwan Qureshi1222a732016-08-23 14:31:23 +0530238 vr_params->VrConfigEnable[domain] = cfg->vr_config_enable;
239 vr_params->Psi1Threshold[domain] = cfg->psi1threshold;
240 vr_params->Psi2Threshold[domain] = cfg->psi2threshold;
241 vr_params->Psi3Threshold[domain] = cfg->psi3threshold;
242 vr_params->Psi3Enable[domain] = cfg->psi3enable;
243 vr_params->Psi4Enable[domain] = cfg->psi4enable;
244 vr_params->ImonSlope[domain] = cfg->imon_slope;
245 vr_params->ImonOffset[domain] = cfg->imon_offset;
Patrick Rudolph50aebaf82019-08-14 10:07:38 +0200246 /* If board provided non-zero value, use it. */
247 if (cfg->icc_max)
248 vr_params->IccMax[domain] = cfg->icc_max;
249 else
250 vr_params->IccMax[domain] = get_sku_icc_max(domain);
Rizwan Qureshi1222a732016-08-23 14:31:23 +0530251 vr_params->VrVoltageLimit[domain] = cfg->voltage_limit;
Duncan Laurie86db4692017-03-14 16:40:06 -0700252
Julius Wernercd49cce2019-03-05 16:53:33 -0800253#if CONFIG(PLATFORM_USES_FSP2_0)
Duncan Laurie86db4692017-03-14 16:40:06 -0700254 vr_params->AcLoadline[domain] = cfg->ac_loadline;
255 vr_params->DcLoadline[domain] = cfg->dc_loadline;
256#endif
Aaron Durbindf214402015-12-14 16:44:26 -0600257}