blob: 89169d0e7c90cb3cfa939b0538518a9d8d4071ab [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 +080023#define KBLY_ICCMAX_SA VR_CFG_AMP(4.1)
24#define KBLY_ICCMAX_CORE VR_CFG_AMP(24)
Gaggery Tsaic14307e2018-07-23 13:00:09 -070025#define AMLY_ICCMAX_CORE VR_CFG_AMP(28)
Gaggery Tsaie1a75d42018-01-02 12:13:40 +080026#define KBLY_ICCMAX_GTS_GTUS VR_CFG_AMP(24)
27#define KBLR_ICCMAX_SA_U42 VR_CFG_AMP(6)
28#define KBLU_ICCMAX_SA_U22 VR_CFG_AMP(4.5)
29#define KBLR_ICCMAX_CORE_U42 VR_CFG_AMP(64)
30#define KBLU_ICCMAX_CORE_U22_PREMIUM VR_CFG_AMP(32)
31#define KBLU_ICCMAX_CORE_U22_BASE VR_CFG_AMP(29)
32#define KBLUR_ICCMAX_GTS_GTUS VR_CFG_AMP(31)
33
34enum kbl_sku {
35 KBL_Y_SKU,
36 KBL_R_SKU,
37 KBL_U_BASE_SKU,
38 KBL_U_PREMIUM_SKU,
Gaggery Tsaic14307e2018-07-23 13:00:09 -070039 AML_Y_SKU,
Gaggery Tsaie1a75d42018-01-02 12:13:40 +080040};
41
42/*
43 * Iccmax table from Doc #559100 Section 7.2 DC Specifications, the
44 * Iccmax is the same among KBL-Y but KBL-U/R.
Gaggery Tsaic14307e2018-07-23 13:00:09 -070045 * Addendum for AML-Y #594883, IccMax for IA core is 28A.
Gaggery Tsaie1a75d42018-01-02 12:13:40 +080046 * +----------------+-------------+---------------+------+-----+
47 * | Domain/Setting | SA | IA | GTUS | GTS |
48 * +----------------+-------------+---------------+------+-----+
49 * | IccMax(KBL-U/R)| 6A(U42) | 64A(U42) | 31A | 31A |
50 * | | 4.5A(Others)| 29A(P/C) | | |
51 * | | | 32A(i3/i5) | | |
52 * +----------------+-------------+---------------+------+-----+
53 * | IccMax(KBL-Y) | 4.1A | 24A | 24A | 24A |
54 * +----------------+-------------+---------------+------+-----+
Gaggery Tsaic14307e2018-07-23 13:00:09 -070055 * | IccMax(AML-Y) | 4.1A | 28A | 24A | 24A |
56 * +----------------+-------------+---------------+------+-----+
Gaggery Tsaie1a75d42018-01-02 12:13:40 +080057 */
58
59static const struct {
Gaggery Tsaie1a75d42018-01-02 12:13:40 +080060 uint16_t icc_max[NUM_VR_DOMAINS];
61}sku_icc_max_mapping[] = {
62 [KBL_Y_SKU] = {
Gaggery Tsaie1a75d42018-01-02 12:13:40 +080063 .icc_max = {
64 KBLY_ICCMAX_SA,
65 KBLY_ICCMAX_CORE,
66 KBLY_ICCMAX_GTS_GTUS,
67 KBLY_ICCMAX_GTS_GTUS
68 }
69 },
70 [KBL_R_SKU] = {
Gaggery Tsaie1a75d42018-01-02 12:13:40 +080071 .icc_max = {
72 KBLR_ICCMAX_SA_U42,
73 KBLR_ICCMAX_CORE_U42,
74 KBLUR_ICCMAX_GTS_GTUS,
75 KBLUR_ICCMAX_GTS_GTUS
76 }
77 },
78 [KBL_U_BASE_SKU] = {
Gaggery Tsaie1a75d42018-01-02 12:13:40 +080079 .icc_max = {
80 KBLU_ICCMAX_SA_U22,
81 KBLU_ICCMAX_CORE_U22_BASE,
82 KBLUR_ICCMAX_GTS_GTUS,
83 KBLUR_ICCMAX_GTS_GTUS
84 }
85 },
86 [KBL_U_PREMIUM_SKU] = {
Gaggery Tsaie1a75d42018-01-02 12:13:40 +080087 .icc_max = {
88 KBLU_ICCMAX_SA_U22,
89 KBLU_ICCMAX_CORE_U22_PREMIUM,
90 KBLUR_ICCMAX_GTS_GTUS,
91 KBLUR_ICCMAX_GTS_GTUS
92 }
93 },
Gaggery Tsaic14307e2018-07-23 13:00:09 -070094 [AML_Y_SKU] = {
95 .icc_max = {
96 KBLY_ICCMAX_SA,
97 AMLY_ICCMAX_CORE,
98 KBLY_ICCMAX_GTS_GTUS,
99 KBLY_ICCMAX_GTS_GTUS
100 }
101 },
Gaggery Tsaie1a75d42018-01-02 12:13:40 +0800102};
103
Aaron Durbindf214402015-12-14 16:44:26 -0600104/* Default values for domain configuration. PSI3 and PSI4 are disabled. */
105static const struct vr_config default_configs[NUM_VR_DOMAINS] = {
106 [VR_SYSTEM_AGENT] = {
107 .vr_config_enable = 1,
108 .psi1threshold = VR_CFG_AMP(20),
109 .psi2threshold = VR_CFG_AMP(4),
110 .psi3threshold = VR_CFG_AMP(1),
111 .psi3enable = 0,
112 .psi4enable = 0,
113 .imon_slope = 0x0,
114 .imon_offset = 0x0,
115 .icc_max = VR_CFG_AMP(7),
116 .voltage_limit = 1520,
117 },
118 [VR_IA_CORE] = {
119 .vr_config_enable = 1,
120 .psi1threshold = VR_CFG_AMP(20),
121 .psi2threshold = VR_CFG_AMP(5),
122 .psi3threshold = VR_CFG_AMP(1),
123 .psi3enable = 0,
124 .psi4enable = 0,
125 .imon_slope = 0x0,
126 .imon_offset = 0x0,
127 .icc_max = VR_CFG_AMP(34),
128 .voltage_limit = 1520,
129 },
Duncan Laurie4fa8a6f2017-03-14 16:37:55 -0700130#if IS_ENABLED(CONFIG_PLATFORM_USES_FSP1_1)
Aaron Durbindf214402015-12-14 16:44:26 -0600131 [VR_RING] = {
132 .vr_config_enable = 1,
133 .psi1threshold = VR_CFG_AMP(20),
134 .psi2threshold = VR_CFG_AMP(5),
135 .psi3threshold = VR_CFG_AMP(1),
136 .psi3enable = 0,
137 .psi4enable = 0,
138 .imon_slope = 0x0,
139 .imon_offset = 0x0,
140 .icc_max = VR_CFG_AMP(34),
141 .voltage_limit = 1520,
142 },
Duncan Laurie4fa8a6f2017-03-14 16:37:55 -0700143#endif
Aaron Durbindf214402015-12-14 16:44:26 -0600144 [VR_GT_UNSLICED] = {
145 .vr_config_enable = 1,
146 .psi1threshold = VR_CFG_AMP(20),
147 .psi2threshold = VR_CFG_AMP(5),
148 .psi3threshold = VR_CFG_AMP(1),
149 .psi3enable = 0,
150 .psi4enable = 0,
151 .imon_slope = 0x0,
152 .imon_offset = 0x0,
153 .icc_max = VR_CFG_AMP(35),
154 .voltage_limit = 1520,
155 },
156 [VR_GT_SLICED] = {
157 .vr_config_enable = 1,
158 .psi1threshold = VR_CFG_AMP(20),
159 .psi2threshold = VR_CFG_AMP(5),
160 .psi3threshold = VR_CFG_AMP(1),
161 .psi3enable = 0,
162 .psi4enable = 0,
163 .imon_slope = 0x0,
164 .imon_offset = 0x0,
165 .icc_max = VR_CFG_AMP(35),
166 .voltage_limit = 1520,
167 },
168};
169
Elyes HAOUAS143fb462018-05-25 12:56:45 +0200170static uint16_t get_dev_id(struct device *dev)
Gaggery Tsaie1a75d42018-01-02 12:13:40 +0800171{
172 return pci_read_config16(dev, PCI_DEVICE_ID);
173}
174
175static int get_kbl_sku(void)
176{
177 static int sku = -1;
178 uint16_t id;
179
180 if (sku != -1)
181 return sku;
182
183 id = get_dev_id(SA_DEV_ROOT);
184 if (id == PCI_DEVICE_ID_INTEL_KBL_U_R)
185 sku = KBL_R_SKU;
Gaggery Tsaic14307e2018-07-23 13:00:09 -0700186 else if (id == PCI_DEVICE_ID_INTEL_KBL_ID_Y) {
187 id = get_dev_id(SA_DEV_IGD);
Gaggery Tsai8aee7f72018-08-03 11:40:55 -0700188 if (id == PCI_DEVICE_ID_INTEL_AML_GT2_ULX)
Gaggery Tsaic14307e2018-07-23 13:00:09 -0700189 sku = AML_Y_SKU;
190 else
191 sku = KBL_Y_SKU;
192 } else if (id == PCI_DEVICE_ID_INTEL_KBL_ID_U) {
Gaggery Tsaie1a75d42018-01-02 12:13:40 +0800193 id = get_dev_id(PCH_DEV_LPC);
194 if (id == PCI_DEVICE_ID_INTEL_SPT_LP_U_BASE_HDCP22)
195 sku = KBL_U_BASE_SKU;
196 else
197 sku = KBL_U_PREMIUM_SKU;
198 } else
199 /* Not one of the skus with available Icc max mapping. */
200 sku = -2;
201 return sku;
202}
203
204static uint16_t get_sku_icc_max(int domain, uint16_t board_icc_max)
205{
206 /* If board provided non-zero value, use it. */
207 if (board_icc_max)
208 return board_icc_max;
209
210 /* Check if this SKU has a mapping table entry. */
211 int sku_id = get_kbl_sku();
212 if (sku_id < 0)
213 return 0;
214 return sku_icc_max_mapping[sku_id].icc_max[domain];
215}
216
Rizwan Qureshi1222a732016-08-23 14:31:23 +0530217void fill_vr_domain_config(void *params,
218 int domain, const struct vr_config *chip_cfg)
Aaron Durbindf214402015-12-14 16:44:26 -0600219{
Rizwan Qureshi1222a732016-08-23 14:31:23 +0530220 FSP_SIL_UPD *vr_params = (FSP_SIL_UPD *)params;
Aaron Durbindf214402015-12-14 16:44:26 -0600221 const struct vr_config *cfg;
222
223 if (domain < 0 || domain >= NUM_VR_DOMAINS)
224 return;
225
226 /* Use device tree override if requested. */
227 if (chip_cfg->vr_config_enable)
228 cfg = chip_cfg;
229 else
230 cfg = &default_configs[domain];
231
Rizwan Qureshi1222a732016-08-23 14:31:23 +0530232 vr_params->VrConfigEnable[domain] = cfg->vr_config_enable;
233 vr_params->Psi1Threshold[domain] = cfg->psi1threshold;
234 vr_params->Psi2Threshold[domain] = cfg->psi2threshold;
235 vr_params->Psi3Threshold[domain] = cfg->psi3threshold;
236 vr_params->Psi3Enable[domain] = cfg->psi3enable;
237 vr_params->Psi4Enable[domain] = cfg->psi4enable;
238 vr_params->ImonSlope[domain] = cfg->imon_slope;
239 vr_params->ImonOffset[domain] = cfg->imon_offset;
Gaggery Tsaie1a75d42018-01-02 12:13:40 +0800240 vr_params->IccMax[domain] = get_sku_icc_max(domain, cfg->icc_max);
Rizwan Qureshi1222a732016-08-23 14:31:23 +0530241 vr_params->VrVoltageLimit[domain] = cfg->voltage_limit;
Duncan Laurie86db4692017-03-14 16:40:06 -0700242
243#if IS_ENABLED(CONFIG_PLATFORM_USES_FSP2_0)
244 vr_params->AcLoadline[domain] = cfg->ac_loadline;
245 vr_params->DcLoadline[domain] = cfg->dc_loadline;
246#endif
Aaron Durbindf214402015-12-14 16:44:26 -0600247}