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 | #define KBLY_ICCMAX_SA VR_CFG_AMP(4.1) |
| 24 | #define KBLY_ICCMAX_CORE VR_CFG_AMP(24) |
Gaggery Tsai | c14307e | 2018-07-23 13:00:09 -0700 | [diff] [blame] | 25 | #define AMLY_ICCMAX_CORE VR_CFG_AMP(28) |
Gaggery Tsai | e1a75d4 | 2018-01-02 12:13:40 +0800 | [diff] [blame] | 26 | #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 | |
| 34 | enum kbl_sku { |
| 35 | KBL_Y_SKU, |
| 36 | KBL_R_SKU, |
| 37 | KBL_U_BASE_SKU, |
| 38 | KBL_U_PREMIUM_SKU, |
Gaggery Tsai | c14307e | 2018-07-23 13:00:09 -0700 | [diff] [blame] | 39 | AML_Y_SKU, |
Gaggery Tsai | e1a75d4 | 2018-01-02 12:13:40 +0800 | [diff] [blame] | 40 | }; |
| 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 Tsai | c14307e | 2018-07-23 13:00:09 -0700 | [diff] [blame] | 45 | * Addendum for AML-Y #594883, IccMax for IA core is 28A. |
Gaggery Tsai | e1a75d4 | 2018-01-02 12:13:40 +0800 | [diff] [blame] | 46 | * +----------------+-------------+---------------+------+-----+ |
| 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 Tsai | c14307e | 2018-07-23 13:00:09 -0700 | [diff] [blame] | 55 | * | IccMax(AML-Y) | 4.1A | 28A | 24A | 24A | |
| 56 | * +----------------+-------------+---------------+------+-----+ |
Gaggery Tsai | e1a75d4 | 2018-01-02 12:13:40 +0800 | [diff] [blame] | 57 | */ |
| 58 | |
| 59 | static const struct { |
Gaggery Tsai | e1a75d4 | 2018-01-02 12:13:40 +0800 | [diff] [blame] | 60 | uint16_t icc_max[NUM_VR_DOMAINS]; |
| 61 | }sku_icc_max_mapping[] = { |
| 62 | [KBL_Y_SKU] = { |
Gaggery Tsai | e1a75d4 | 2018-01-02 12:13:40 +0800 | [diff] [blame] | 63 | .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 Tsai | e1a75d4 | 2018-01-02 12:13:40 +0800 | [diff] [blame] | 71 | .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 Tsai | e1a75d4 | 2018-01-02 12:13:40 +0800 | [diff] [blame] | 79 | .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 Tsai | e1a75d4 | 2018-01-02 12:13:40 +0800 | [diff] [blame] | 87 | .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 Tsai | c14307e | 2018-07-23 13:00:09 -0700 | [diff] [blame] | 94 | [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 Tsai | e1a75d4 | 2018-01-02 12:13:40 +0800 | [diff] [blame] | 102 | }; |
| 103 | |
Aaron Durbin | df21440 | 2015-12-14 16:44:26 -0600 | [diff] [blame] | 104 | /* Default values for domain configuration. PSI3 and PSI4 are disabled. */ |
| 105 | static 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 Laurie | 4fa8a6f | 2017-03-14 16:37:55 -0700 | [diff] [blame] | 130 | #if IS_ENABLED(CONFIG_PLATFORM_USES_FSP1_1) |
Aaron Durbin | df21440 | 2015-12-14 16:44:26 -0600 | [diff] [blame] | 131 | [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 Laurie | 4fa8a6f | 2017-03-14 16:37:55 -0700 | [diff] [blame] | 143 | #endif |
Aaron Durbin | df21440 | 2015-12-14 16:44:26 -0600 | [diff] [blame] | 144 | [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 HAOUAS | 143fb46 | 2018-05-25 12:56:45 +0200 | [diff] [blame] | 170 | static uint16_t get_dev_id(struct device *dev) |
Gaggery Tsai | e1a75d4 | 2018-01-02 12:13:40 +0800 | [diff] [blame] | 171 | { |
| 172 | return pci_read_config16(dev, PCI_DEVICE_ID); |
| 173 | } |
| 174 | |
| 175 | static 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 Tsai | c14307e | 2018-07-23 13:00:09 -0700 | [diff] [blame] | 186 | else if (id == PCI_DEVICE_ID_INTEL_KBL_ID_Y) { |
| 187 | id = get_dev_id(SA_DEV_IGD); |
Gaggery Tsai | 8aee7f7 | 2018-08-03 11:40:55 -0700 | [diff] [blame] | 188 | if (id == PCI_DEVICE_ID_INTEL_AML_GT2_ULX) |
Gaggery Tsai | c14307e | 2018-07-23 13:00:09 -0700 | [diff] [blame] | 189 | sku = AML_Y_SKU; |
| 190 | else |
| 191 | sku = KBL_Y_SKU; |
| 192 | } else if (id == PCI_DEVICE_ID_INTEL_KBL_ID_U) { |
Gaggery Tsai | e1a75d4 | 2018-01-02 12:13:40 +0800 | [diff] [blame] | 193 | 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 | |
| 204 | static 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 Qureshi | 1222a73 | 2016-08-23 14:31:23 +0530 | [diff] [blame] | 217 | void fill_vr_domain_config(void *params, |
| 218 | int domain, const struct vr_config *chip_cfg) |
Aaron Durbin | df21440 | 2015-12-14 16:44:26 -0600 | [diff] [blame] | 219 | { |
Rizwan Qureshi | 1222a73 | 2016-08-23 14:31:23 +0530 | [diff] [blame] | 220 | FSP_SIL_UPD *vr_params = (FSP_SIL_UPD *)params; |
Aaron Durbin | df21440 | 2015-12-14 16:44:26 -0600 | [diff] [blame] | 221 | 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 Qureshi | 1222a73 | 2016-08-23 14:31:23 +0530 | [diff] [blame] | 232 | 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 Tsai | e1a75d4 | 2018-01-02 12:13:40 +0800 | [diff] [blame] | 240 | vr_params->IccMax[domain] = get_sku_icc_max(domain, cfg->icc_max); |
Rizwan Qureshi | 1222a73 | 2016-08-23 14:31:23 +0530 | [diff] [blame] | 241 | vr_params->VrVoltageLimit[domain] = cfg->voltage_limit; |
Duncan Laurie | 86db469 | 2017-03-14 16:40:06 -0700 | [diff] [blame] | 242 | |
| 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 Durbin | df21440 | 2015-12-14 16:44:26 -0600 | [diff] [blame] | 247 | } |