blob: 128ba594bf31bbf77943a5bcb57bf743107b4aa7 [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>
22
Gaggery Tsaie1a75d42018-01-02 12:13:40 +080023enum kbl_sku {
24 KBL_Y_SKU,
25 KBL_R_SKU,
26 KBL_U_BASE_SKU,
27 KBL_U_PREMIUM_SKU,
Gaggery Tsaic14307e2018-07-23 13:00:09 -070028 AML_Y_SKU,
Gaggery Tsaie1a75d42018-01-02 12:13:40 +080029};
30
31/*
32 * Iccmax table from Doc #559100 Section 7.2 DC Specifications, the
33 * Iccmax is the same among KBL-Y but KBL-U/R.
Gaggery Tsaic14307e2018-07-23 13:00:09 -070034 * Addendum for AML-Y #594883, IccMax for IA core is 28A.
Gaggery Tsaie1a75d42018-01-02 12:13:40 +080035 * +----------------+-------------+---------------+------+-----+
36 * | Domain/Setting | SA | IA | GTUS | GTS |
37 * +----------------+-------------+---------------+------+-----+
38 * | IccMax(KBL-U/R)| 6A(U42) | 64A(U42) | 31A | 31A |
39 * | | 4.5A(Others)| 29A(P/C) | | |
40 * | | | 32A(i3/i5) | | |
41 * +----------------+-------------+---------------+------+-----+
42 * | IccMax(KBL-Y) | 4.1A | 24A | 24A | 24A |
43 * +----------------+-------------+---------------+------+-----+
Gaggery Tsaic14307e2018-07-23 13:00:09 -070044 * | IccMax(AML-Y) | 4.1A | 28A | 24A | 24A |
45 * +----------------+-------------+---------------+------+-----+
Gaggery Tsaie1a75d42018-01-02 12:13:40 +080046 */
47
48static const struct {
Gaggery Tsaie1a75d42018-01-02 12:13:40 +080049 uint16_t icc_max[NUM_VR_DOMAINS];
50}sku_icc_max_mapping[] = {
51 [KBL_Y_SKU] = {
Gaggery Tsaie1a75d42018-01-02 12:13:40 +080052 .icc_max = {
Patrick Rudolph9ef977f2019-08-14 09:45:53 +020053 VR_CFG_AMP(4.1),
54 VR_CFG_AMP(24),
55 VR_CFG_AMP(24),
56 VR_CFG_AMP(24),
Gaggery Tsaie1a75d42018-01-02 12:13:40 +080057 }
58 },
59 [KBL_R_SKU] = {
Gaggery Tsaie1a75d42018-01-02 12:13:40 +080060 .icc_max = {
Patrick Rudolph9ef977f2019-08-14 09:45:53 +020061 VR_CFG_AMP(6),
62 VR_CFG_AMP(64),
63 VR_CFG_AMP(31),
64 VR_CFG_AMP(31),
Gaggery Tsaie1a75d42018-01-02 12:13:40 +080065 }
66 },
67 [KBL_U_BASE_SKU] = {
Gaggery Tsaie1a75d42018-01-02 12:13:40 +080068 .icc_max = {
Patrick Rudolph9ef977f2019-08-14 09:45:53 +020069 VR_CFG_AMP(4.5),
70 VR_CFG_AMP(29),
71 VR_CFG_AMP(31),
72 VR_CFG_AMP(31),
Gaggery Tsaie1a75d42018-01-02 12:13:40 +080073 }
74 },
75 [KBL_U_PREMIUM_SKU] = {
Gaggery Tsaie1a75d42018-01-02 12:13:40 +080076 .icc_max = {
Patrick Rudolph9ef977f2019-08-14 09:45:53 +020077 VR_CFG_AMP(4.5),
78 VR_CFG_AMP(32),
79 VR_CFG_AMP(31),
80 VR_CFG_AMP(31),
Gaggery Tsaie1a75d42018-01-02 12:13:40 +080081 }
82 },
Gaggery Tsaic14307e2018-07-23 13:00:09 -070083 [AML_Y_SKU] = {
84 .icc_max = {
Patrick Rudolph9ef977f2019-08-14 09:45:53 +020085 VR_CFG_AMP(4.1),
86 VR_CFG_AMP(28),
87 VR_CFG_AMP(24),
88 VR_CFG_AMP(24),
Gaggery Tsaic14307e2018-07-23 13:00:09 -070089 }
90 },
Gaggery Tsaie1a75d42018-01-02 12:13:40 +080091};
92
Aaron Durbindf214402015-12-14 16:44:26 -060093/* Default values for domain configuration. PSI3 and PSI4 are disabled. */
94static const struct vr_config default_configs[NUM_VR_DOMAINS] = {
95 [VR_SYSTEM_AGENT] = {
96 .vr_config_enable = 1,
97 .psi1threshold = VR_CFG_AMP(20),
98 .psi2threshold = VR_CFG_AMP(4),
99 .psi3threshold = VR_CFG_AMP(1),
100 .psi3enable = 0,
101 .psi4enable = 0,
102 .imon_slope = 0x0,
103 .imon_offset = 0x0,
104 .icc_max = VR_CFG_AMP(7),
105 .voltage_limit = 1520,
106 },
107 [VR_IA_CORE] = {
108 .vr_config_enable = 1,
109 .psi1threshold = VR_CFG_AMP(20),
110 .psi2threshold = VR_CFG_AMP(5),
111 .psi3threshold = VR_CFG_AMP(1),
112 .psi3enable = 0,
113 .psi4enable = 0,
114 .imon_slope = 0x0,
115 .imon_offset = 0x0,
116 .icc_max = VR_CFG_AMP(34),
117 .voltage_limit = 1520,
118 },
Julius Wernercd49cce2019-03-05 16:53:33 -0800119#if CONFIG(PLATFORM_USES_FSP1_1)
Aaron Durbindf214402015-12-14 16:44:26 -0600120 [VR_RING] = {
121 .vr_config_enable = 1,
122 .psi1threshold = VR_CFG_AMP(20),
123 .psi2threshold = VR_CFG_AMP(5),
124 .psi3threshold = VR_CFG_AMP(1),
125 .psi3enable = 0,
126 .psi4enable = 0,
127 .imon_slope = 0x0,
128 .imon_offset = 0x0,
129 .icc_max = VR_CFG_AMP(34),
130 .voltage_limit = 1520,
131 },
Duncan Laurie4fa8a6f2017-03-14 16:37:55 -0700132#endif
Aaron Durbindf214402015-12-14 16:44:26 -0600133 [VR_GT_UNSLICED] = {
134 .vr_config_enable = 1,
135 .psi1threshold = VR_CFG_AMP(20),
136 .psi2threshold = VR_CFG_AMP(5),
137 .psi3threshold = VR_CFG_AMP(1),
138 .psi3enable = 0,
139 .psi4enable = 0,
140 .imon_slope = 0x0,
141 .imon_offset = 0x0,
142 .icc_max = VR_CFG_AMP(35),
143 .voltage_limit = 1520,
144 },
145 [VR_GT_SLICED] = {
146 .vr_config_enable = 1,
147 .psi1threshold = VR_CFG_AMP(20),
148 .psi2threshold = VR_CFG_AMP(5),
149 .psi3threshold = VR_CFG_AMP(1),
150 .psi3enable = 0,
151 .psi4enable = 0,
152 .imon_slope = 0x0,
153 .imon_offset = 0x0,
154 .icc_max = VR_CFG_AMP(35),
155 .voltage_limit = 1520,
156 },
157};
158
Elyes HAOUAS143fb462018-05-25 12:56:45 +0200159static uint16_t get_dev_id(struct device *dev)
Gaggery Tsaie1a75d42018-01-02 12:13:40 +0800160{
161 return pci_read_config16(dev, PCI_DEVICE_ID);
162}
163
164static int get_kbl_sku(void)
165{
Kyösti Mälkki71756c212019-07-12 13:10:19 +0300166 struct device *sa_dev = pcidev_path_on_root(SA_DEVFN_ROOT);
Gaggery Tsaie1a75d42018-01-02 12:13:40 +0800167 static int sku = -1;
168 uint16_t id;
169
170 if (sku != -1)
171 return sku;
172
Kyösti Mälkki71756c212019-07-12 13:10:19 +0300173 id = get_dev_id(sa_dev);
Gaggery Tsaie1a75d42018-01-02 12:13:40 +0800174 if (id == PCI_DEVICE_ID_INTEL_KBL_U_R)
175 sku = KBL_R_SKU;
Gaggery Tsaic14307e2018-07-23 13:00:09 -0700176 else if (id == PCI_DEVICE_ID_INTEL_KBL_ID_Y) {
Kyösti Mälkki71756c212019-07-12 13:10:19 +0300177 struct device *igd_dev = pcidev_path_on_root(SA_DEVFN_IGD);
178 id = get_dev_id(igd_dev);
Gaggery Tsai8aee7f72018-08-03 11:40:55 -0700179 if (id == PCI_DEVICE_ID_INTEL_AML_GT2_ULX)
Gaggery Tsaic14307e2018-07-23 13:00:09 -0700180 sku = AML_Y_SKU;
181 else
182 sku = KBL_Y_SKU;
183 } else if (id == PCI_DEVICE_ID_INTEL_KBL_ID_U) {
Gaggery Tsaie1a75d42018-01-02 12:13:40 +0800184 id = get_dev_id(PCH_DEV_LPC);
185 if (id == PCI_DEVICE_ID_INTEL_SPT_LP_U_BASE_HDCP22)
186 sku = KBL_U_BASE_SKU;
187 else
188 sku = KBL_U_PREMIUM_SKU;
189 } else
190 /* Not one of the skus with available Icc max mapping. */
191 sku = -2;
192 return sku;
193}
194
195static uint16_t get_sku_icc_max(int domain, uint16_t board_icc_max)
196{
197 /* If board provided non-zero value, use it. */
198 if (board_icc_max)
199 return board_icc_max;
200
201 /* Check if this SKU has a mapping table entry. */
202 int sku_id = get_kbl_sku();
203 if (sku_id < 0)
204 return 0;
205 return sku_icc_max_mapping[sku_id].icc_max[domain];
206}
207
Rizwan Qureshi1222a732016-08-23 14:31:23 +0530208void fill_vr_domain_config(void *params,
209 int domain, const struct vr_config *chip_cfg)
Aaron Durbindf214402015-12-14 16:44:26 -0600210{
Rizwan Qureshi1222a732016-08-23 14:31:23 +0530211 FSP_SIL_UPD *vr_params = (FSP_SIL_UPD *)params;
Aaron Durbindf214402015-12-14 16:44:26 -0600212 const struct vr_config *cfg;
213
214 if (domain < 0 || domain >= NUM_VR_DOMAINS)
215 return;
216
217 /* Use device tree override if requested. */
218 if (chip_cfg->vr_config_enable)
219 cfg = chip_cfg;
220 else
221 cfg = &default_configs[domain];
222
Rizwan Qureshi1222a732016-08-23 14:31:23 +0530223 vr_params->VrConfigEnable[domain] = cfg->vr_config_enable;
224 vr_params->Psi1Threshold[domain] = cfg->psi1threshold;
225 vr_params->Psi2Threshold[domain] = cfg->psi2threshold;
226 vr_params->Psi3Threshold[domain] = cfg->psi3threshold;
227 vr_params->Psi3Enable[domain] = cfg->psi3enable;
228 vr_params->Psi4Enable[domain] = cfg->psi4enable;
229 vr_params->ImonSlope[domain] = cfg->imon_slope;
230 vr_params->ImonOffset[domain] = cfg->imon_offset;
Gaggery Tsaie1a75d42018-01-02 12:13:40 +0800231 vr_params->IccMax[domain] = get_sku_icc_max(domain, cfg->icc_max);
Rizwan Qureshi1222a732016-08-23 14:31:23 +0530232 vr_params->VrVoltageLimit[domain] = cfg->voltage_limit;
Duncan Laurie86db4692017-03-14 16:40:06 -0700233
Julius Wernercd49cce2019-03-05 16:53:33 -0800234#if CONFIG(PLATFORM_USES_FSP2_0)
Duncan Laurie86db4692017-03-14 16:40:06 -0700235 vr_params->AcLoadline[domain] = cfg->ac_loadline;
236 vr_params->DcLoadline[domain] = cfg->dc_loadline;
237#endif
Aaron Durbindf214402015-12-14 16:44:26 -0600238}