Aaron Durbin | df21440 | 2015-12-14 16:44:26 -0600 | [diff] [blame] | 1 | /* |
| 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 Tsai | e1a75d4 | 2018-01-02 12:13:40 +0800 | [diff] [blame] | 17 | #include <device/pci_ids.h> |
Patrick Rudolph | e56189c | 2018-04-18 10:11:59 +0200 | [diff] [blame] | 18 | #include <device/pci_ops.h> |
Rizwan Qureshi | 1222a73 | 2016-08-23 14:31:23 +0530 | [diff] [blame] | 19 | #include <fsp/api.h> |
| 20 | #include <soc/ramstage.h> |
Aaron Durbin | df21440 | 2015-12-14 16:44:26 -0600 | [diff] [blame] | 21 | #include <soc/vr_config.h> |
| 22 | |
Gaggery Tsai | e1a75d4 | 2018-01-02 12:13:40 +0800 | [diff] [blame] | 23 | enum kbl_sku { |
| 24 | KBL_Y_SKU, |
| 25 | KBL_R_SKU, |
| 26 | KBL_U_BASE_SKU, |
| 27 | KBL_U_PREMIUM_SKU, |
Gaggery Tsai | c14307e | 2018-07-23 13:00:09 -0700 | [diff] [blame] | 28 | AML_Y_SKU, |
Gaggery Tsai | e1a75d4 | 2018-01-02 12:13:40 +0800 | [diff] [blame] | 29 | }; |
| 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 Tsai | c14307e | 2018-07-23 13:00:09 -0700 | [diff] [blame] | 34 | * Addendum for AML-Y #594883, IccMax for IA core is 28A. |
Gaggery Tsai | e1a75d4 | 2018-01-02 12:13:40 +0800 | [diff] [blame] | 35 | * +----------------+-------------+---------------+------+-----+ |
| 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 Tsai | c14307e | 2018-07-23 13:00:09 -0700 | [diff] [blame] | 44 | * | IccMax(AML-Y) | 4.1A | 28A | 24A | 24A | |
| 45 | * +----------------+-------------+---------------+------+-----+ |
Gaggery Tsai | e1a75d4 | 2018-01-02 12:13:40 +0800 | [diff] [blame] | 46 | */ |
| 47 | |
| 48 | static const struct { |
Gaggery Tsai | e1a75d4 | 2018-01-02 12:13:40 +0800 | [diff] [blame] | 49 | uint16_t icc_max[NUM_VR_DOMAINS]; |
| 50 | }sku_icc_max_mapping[] = { |
| 51 | [KBL_Y_SKU] = { |
Gaggery Tsai | e1a75d4 | 2018-01-02 12:13:40 +0800 | [diff] [blame] | 52 | .icc_max = { |
Patrick Rudolph | 9ef977f | 2019-08-14 09:45:53 +0200 | [diff] [blame^] | 53 | VR_CFG_AMP(4.1), |
| 54 | VR_CFG_AMP(24), |
| 55 | VR_CFG_AMP(24), |
| 56 | VR_CFG_AMP(24), |
Gaggery Tsai | e1a75d4 | 2018-01-02 12:13:40 +0800 | [diff] [blame] | 57 | } |
| 58 | }, |
| 59 | [KBL_R_SKU] = { |
Gaggery Tsai | e1a75d4 | 2018-01-02 12:13:40 +0800 | [diff] [blame] | 60 | .icc_max = { |
Patrick Rudolph | 9ef977f | 2019-08-14 09:45:53 +0200 | [diff] [blame^] | 61 | VR_CFG_AMP(6), |
| 62 | VR_CFG_AMP(64), |
| 63 | VR_CFG_AMP(31), |
| 64 | VR_CFG_AMP(31), |
Gaggery Tsai | e1a75d4 | 2018-01-02 12:13:40 +0800 | [diff] [blame] | 65 | } |
| 66 | }, |
| 67 | [KBL_U_BASE_SKU] = { |
Gaggery Tsai | e1a75d4 | 2018-01-02 12:13:40 +0800 | [diff] [blame] | 68 | .icc_max = { |
Patrick Rudolph | 9ef977f | 2019-08-14 09:45:53 +0200 | [diff] [blame^] | 69 | VR_CFG_AMP(4.5), |
| 70 | VR_CFG_AMP(29), |
| 71 | VR_CFG_AMP(31), |
| 72 | VR_CFG_AMP(31), |
Gaggery Tsai | e1a75d4 | 2018-01-02 12:13:40 +0800 | [diff] [blame] | 73 | } |
| 74 | }, |
| 75 | [KBL_U_PREMIUM_SKU] = { |
Gaggery Tsai | e1a75d4 | 2018-01-02 12:13:40 +0800 | [diff] [blame] | 76 | .icc_max = { |
Patrick Rudolph | 9ef977f | 2019-08-14 09:45:53 +0200 | [diff] [blame^] | 77 | VR_CFG_AMP(4.5), |
| 78 | VR_CFG_AMP(32), |
| 79 | VR_CFG_AMP(31), |
| 80 | VR_CFG_AMP(31), |
Gaggery Tsai | e1a75d4 | 2018-01-02 12:13:40 +0800 | [diff] [blame] | 81 | } |
| 82 | }, |
Gaggery Tsai | c14307e | 2018-07-23 13:00:09 -0700 | [diff] [blame] | 83 | [AML_Y_SKU] = { |
| 84 | .icc_max = { |
Patrick Rudolph | 9ef977f | 2019-08-14 09:45:53 +0200 | [diff] [blame^] | 85 | VR_CFG_AMP(4.1), |
| 86 | VR_CFG_AMP(28), |
| 87 | VR_CFG_AMP(24), |
| 88 | VR_CFG_AMP(24), |
Gaggery Tsai | c14307e | 2018-07-23 13:00:09 -0700 | [diff] [blame] | 89 | } |
| 90 | }, |
Gaggery Tsai | e1a75d4 | 2018-01-02 12:13:40 +0800 | [diff] [blame] | 91 | }; |
| 92 | |
Aaron Durbin | df21440 | 2015-12-14 16:44:26 -0600 | [diff] [blame] | 93 | /* Default values for domain configuration. PSI3 and PSI4 are disabled. */ |
| 94 | static 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 Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 119 | #if CONFIG(PLATFORM_USES_FSP1_1) |
Aaron Durbin | df21440 | 2015-12-14 16:44:26 -0600 | [diff] [blame] | 120 | [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 Laurie | 4fa8a6f | 2017-03-14 16:37:55 -0700 | [diff] [blame] | 132 | #endif |
Aaron Durbin | df21440 | 2015-12-14 16:44:26 -0600 | [diff] [blame] | 133 | [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 HAOUAS | 143fb46 | 2018-05-25 12:56:45 +0200 | [diff] [blame] | 159 | static uint16_t get_dev_id(struct device *dev) |
Gaggery Tsai | e1a75d4 | 2018-01-02 12:13:40 +0800 | [diff] [blame] | 160 | { |
| 161 | return pci_read_config16(dev, PCI_DEVICE_ID); |
| 162 | } |
| 163 | |
| 164 | static int get_kbl_sku(void) |
| 165 | { |
Kyösti Mälkki | 71756c21 | 2019-07-12 13:10:19 +0300 | [diff] [blame] | 166 | struct device *sa_dev = pcidev_path_on_root(SA_DEVFN_ROOT); |
Gaggery Tsai | e1a75d4 | 2018-01-02 12:13:40 +0800 | [diff] [blame] | 167 | static int sku = -1; |
| 168 | uint16_t id; |
| 169 | |
| 170 | if (sku != -1) |
| 171 | return sku; |
| 172 | |
Kyösti Mälkki | 71756c21 | 2019-07-12 13:10:19 +0300 | [diff] [blame] | 173 | id = get_dev_id(sa_dev); |
Gaggery Tsai | e1a75d4 | 2018-01-02 12:13:40 +0800 | [diff] [blame] | 174 | if (id == PCI_DEVICE_ID_INTEL_KBL_U_R) |
| 175 | sku = KBL_R_SKU; |
Gaggery Tsai | c14307e | 2018-07-23 13:00:09 -0700 | [diff] [blame] | 176 | else if (id == PCI_DEVICE_ID_INTEL_KBL_ID_Y) { |
Kyösti Mälkki | 71756c21 | 2019-07-12 13:10:19 +0300 | [diff] [blame] | 177 | struct device *igd_dev = pcidev_path_on_root(SA_DEVFN_IGD); |
| 178 | id = get_dev_id(igd_dev); |
Gaggery Tsai | 8aee7f7 | 2018-08-03 11:40:55 -0700 | [diff] [blame] | 179 | if (id == PCI_DEVICE_ID_INTEL_AML_GT2_ULX) |
Gaggery Tsai | c14307e | 2018-07-23 13:00:09 -0700 | [diff] [blame] | 180 | sku = AML_Y_SKU; |
| 181 | else |
| 182 | sku = KBL_Y_SKU; |
| 183 | } else if (id == PCI_DEVICE_ID_INTEL_KBL_ID_U) { |
Gaggery Tsai | e1a75d4 | 2018-01-02 12:13:40 +0800 | [diff] [blame] | 184 | 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 | |
| 195 | static 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 Qureshi | 1222a73 | 2016-08-23 14:31:23 +0530 | [diff] [blame] | 208 | void fill_vr_domain_config(void *params, |
| 209 | int domain, const struct vr_config *chip_cfg) |
Aaron Durbin | df21440 | 2015-12-14 16:44:26 -0600 | [diff] [blame] | 210 | { |
Rizwan Qureshi | 1222a73 | 2016-08-23 14:31:23 +0530 | [diff] [blame] | 211 | FSP_SIL_UPD *vr_params = (FSP_SIL_UPD *)params; |
Aaron Durbin | df21440 | 2015-12-14 16:44:26 -0600 | [diff] [blame] | 212 | 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 Qureshi | 1222a73 | 2016-08-23 14:31:23 +0530 | [diff] [blame] | 223 | 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 Tsai | e1a75d4 | 2018-01-02 12:13:40 +0800 | [diff] [blame] | 231 | vr_params->IccMax[domain] = get_sku_icc_max(domain, cfg->icc_max); |
Rizwan Qureshi | 1222a73 | 2016-08-23 14:31:23 +0530 | [diff] [blame] | 232 | vr_params->VrVoltageLimit[domain] = cfg->voltage_limit; |
Duncan Laurie | 86db469 | 2017-03-14 16:40:06 -0700 | [diff] [blame] | 233 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 234 | #if CONFIG(PLATFORM_USES_FSP2_0) |
Duncan Laurie | 86db469 | 2017-03-14 16:40:06 -0700 | [diff] [blame] | 235 | vr_params->AcLoadline[domain] = cfg->ac_loadline; |
| 236 | vr_params->DcLoadline[domain] = cfg->dc_loadline; |
| 237 | #endif |
Aaron Durbin | df21440 | 2015-12-14 16:44:26 -0600 | [diff] [blame] | 238 | } |