Angel Pons | 2712398 | 2020-04-05 13:22:30 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
amanda_hwang | b3b47e1 | 2018-03-08 11:04:40 +0800 | [diff] [blame] | 2 | |
Shelley Chen | 467cce4 | 2018-03-07 14:22:28 -0800 | [diff] [blame] | 3 | #include <arch/cpu.h> |
| 4 | #include <assert.h> |
| 5 | #include <baseboard/variants.h> |
Furquan Shaikh | f5b7e80 | 2018-05-07 14:42:27 -0700 | [diff] [blame] | 6 | #include <cbfs.h> |
amanda_hwang | b3b47e1 | 2018-03-08 11:04:40 +0800 | [diff] [blame] | 7 | #include <chip.h> |
Elyes HAOUAS | 20eaef0 | 2019-03-29 17:45:28 +0100 | [diff] [blame] | 8 | #include <console/console.h> |
amanda_hwang | b3b47e1 | 2018-03-08 11:04:40 +0800 | [diff] [blame] | 9 | #include <device/device.h> |
Furquan Shaikh | c6141b9 | 2018-05-10 21:58:39 -0700 | [diff] [blame] | 10 | #include <drivers/intel/gma/opregion.h> |
amanda_hwang | b3b47e1 | 2018-03-08 11:04:40 +0800 | [diff] [blame] | 11 | #include <ec/google/chromeec/ec.h> |
Furquan Shaikh | e301145 | 2018-05-23 21:27:33 -0700 | [diff] [blame] | 12 | #include <intelblocks/mp_init.h> |
Sumeet R Pawnikar | 97c5464 | 2020-05-10 01:24:11 +0530 | [diff] [blame] | 13 | #include <intelblocks/power_limit.h> |
Shelley Chen | 467cce4 | 2018-03-07 14:22:28 -0800 | [diff] [blame] | 14 | #include <smbios.h> |
| 15 | #include <soc/ramstage.h> |
| 16 | #include <string.h> |
amanda_hwang | 04ccd5f | 2018-03-16 13:43:52 +0800 | [diff] [blame] | 17 | #include <variant/sku.h> |
amanda_hwang | b3b47e1 | 2018-03-08 11:04:40 +0800 | [diff] [blame] | 18 | |
Furquan Shaikh | e301145 | 2018-05-23 21:27:33 -0700 | [diff] [blame] | 19 | #define PL2_I7_SKU 44 |
| 20 | #define PL2_DEFAULT 29 |
John Su | 2257a35 | 2018-10-25 19:21:15 +0800 | [diff] [blame] | 21 | #define PL2_KBL_U 25 |
| 22 | |
| 23 | /* PL2 ID define*/ |
| 24 | #define PL2_ID_DEFAULT 0 |
| 25 | #define PL2_ID_SONA_SYNDRA 1 |
Ren Kuo | a355b16 | 2018-12-12 14:39:36 +0800 | [diff] [blame] | 26 | #define PL2_ID_BARD_EKKO 2 |
John Su | 2257a35 | 2018-10-25 19:21:15 +0800 | [diff] [blame] | 27 | |
| 28 | static const struct pl2_config { |
| 29 | uint32_t cpuid_y0_pl2; |
| 30 | uint32_t cpuid_non_y0_pl2; |
| 31 | } pl2_config_table[] = { |
| 32 | [PL2_ID_DEFAULT] = { PL2_I7_SKU, PL2_DEFAULT }, |
| 33 | [PL2_ID_SONA_SYNDRA] = { PL2_DEFAULT, PL2_KBL_U }, |
Ren Kuo | a355b16 | 2018-12-12 14:39:36 +0800 | [diff] [blame] | 34 | [PL2_ID_BARD_EKKO] = { PL2_DEFAULT, PL2_KBL_U }, |
John Su | 2257a35 | 2018-10-25 19:21:15 +0800 | [diff] [blame] | 35 | }; |
Furquan Shaikh | e301145 | 2018-05-23 21:27:33 -0700 | [diff] [blame] | 36 | |
Gaggery Tsai | 7062777 | 2018-07-26 00:14:09 -0700 | [diff] [blame] | 37 | /* Variant for AKALI */ |
| 38 | #define AKALI_SA_AC_LOADLINE 1100 |
| 39 | #define AKALI_SA_DC_LOADLINE 1028 |
| 40 | #define AKALI_IA_AC_LOADLINE 272 |
| 41 | #define AKALI_IA_DC_LOADLINE 247 |
| 42 | #define AKALI_GT_AC_LOADLINE 314 |
| 43 | #define AKALI_GT_DC_LOADLINE 321 |
| 44 | |
| 45 | /* We only have Akali and Nami default settings so far */ |
| 46 | enum project_sku { |
| 47 | PRJ_AKALI = 1, |
| 48 | }; |
| 49 | |
| 50 | static const struct { |
| 51 | enum project_sku sku; |
| 52 | int ac_loadline[NUM_VR_DOMAINS]; |
| 53 | int dc_loadline[NUM_VR_DOMAINS]; |
| 54 | } sku_overwrite_mapping[] = { |
| 55 | { |
| 56 | .sku = PRJ_AKALI, |
| 57 | .ac_loadline = { |
| 58 | AKALI_SA_AC_LOADLINE, |
| 59 | AKALI_IA_AC_LOADLINE, |
| 60 | AKALI_GT_AC_LOADLINE, |
| 61 | AKALI_GT_AC_LOADLINE |
| 62 | }, |
| 63 | .dc_loadline = { |
| 64 | AKALI_SA_DC_LOADLINE, |
| 65 | AKALI_IA_DC_LOADLINE, |
| 66 | AKALI_GT_DC_LOADLINE, |
| 67 | AKALI_GT_DC_LOADLINE |
| 68 | } |
| 69 | }, |
| 70 | }; |
| 71 | |
John Su | 2257a35 | 2018-10-25 19:21:15 +0800 | [diff] [blame] | 72 | static uint32_t get_pl2(int pl2_id) |
Furquan Shaikh | e301145 | 2018-05-23 21:27:33 -0700 | [diff] [blame] | 73 | { |
John Su | 2257a35 | 2018-10-25 19:21:15 +0800 | [diff] [blame] | 74 | assert(pl2_id < ARRAY_SIZE(pl2_config_table)); |
Furquan Shaikh | e301145 | 2018-05-23 21:27:33 -0700 | [diff] [blame] | 75 | if (cpuid_eax(1) == CPUID_KABYLAKE_Y0) |
John Su | 2257a35 | 2018-10-25 19:21:15 +0800 | [diff] [blame] | 76 | return pl2_config_table[pl2_id].cpuid_y0_pl2; |
Furquan Shaikh | e301145 | 2018-05-23 21:27:33 -0700 | [diff] [blame] | 77 | |
John Su | 2257a35 | 2018-10-25 19:21:15 +0800 | [diff] [blame] | 78 | return pl2_config_table[pl2_id].cpuid_non_y0_pl2; |
Furquan Shaikh | e301145 | 2018-05-23 21:27:33 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Zhuohao Lee | f7b5955 | 2018-03-17 05:00:49 +0800 | [diff] [blame] | 81 | uint32_t variant_board_sku(void) |
amanda_hwang | b3b47e1 | 2018-03-08 11:04:40 +0800 | [diff] [blame] | 82 | { |
Zhuohao Lee | f7b5955 | 2018-03-17 05:00:49 +0800 | [diff] [blame] | 83 | static uint32_t sku_id = SKU_UNKNOWN; |
amanda_hwang | b3b47e1 | 2018-03-08 11:04:40 +0800 | [diff] [blame] | 84 | uint32_t id; |
Zhuohao Lee | f7b5955 | 2018-03-17 05:00:49 +0800 | [diff] [blame] | 85 | |
| 86 | if (sku_id != SKU_UNKNOWN) |
amanda_hwang | b3b47e1 | 2018-03-08 11:04:40 +0800 | [diff] [blame] | 87 | return sku_id; |
| 88 | if (google_chromeec_cbi_get_sku_id(&id)) |
| 89 | return SKU_UNKNOWN; |
| 90 | sku_id = id; |
Zhuohao Lee | f7b5955 | 2018-03-17 05:00:49 +0800 | [diff] [blame] | 91 | |
amanda_hwang | b3b47e1 | 2018-03-08 11:04:40 +0800 | [diff] [blame] | 92 | return sku_id; |
| 93 | } |
| 94 | |
Nico Huber | ebd8a4f | 2017-11-01 09:49:16 +0100 | [diff] [blame] | 95 | const char *smbios_system_sku(void) |
Shelley Chen | 467cce4 | 2018-03-07 14:22:28 -0800 | [diff] [blame] | 96 | { |
Zhuohao Lee | f7b5955 | 2018-03-17 05:00:49 +0800 | [diff] [blame] | 97 | static char sku_str[14]; /* sku{0..4294967295} */ |
Shelley Chen | 467cce4 | 2018-03-07 14:22:28 -0800 | [diff] [blame] | 98 | |
Zhuohao Lee | f7b5955 | 2018-03-17 05:00:49 +0800 | [diff] [blame] | 99 | snprintf(sku_str, sizeof(sku_str), "sku%u", variant_board_sku()); |
Shelley Chen | 467cce4 | 2018-03-07 14:22:28 -0800 | [diff] [blame] | 100 | |
| 101 | return sku_str; |
| 102 | } |
Furquan Shaikh | f5b7e80 | 2018-05-07 14:42:27 -0700 | [diff] [blame] | 103 | |
| 104 | #define OEM_UNKNOWN 0xff |
| 105 | |
| 106 | /* |
| 107 | * Read OEM ID from EC using cbi commands. |
| 108 | * Return value: |
| 109 | * Success = OEM ID read from EC |
| 110 | * Failure = OEM_UNKNOWN (0xff) |
| 111 | */ |
| 112 | static uint8_t read_oem_id(void) |
| 113 | { |
| 114 | static uint8_t oem_id = OEM_UNKNOWN; |
| 115 | uint32_t id; |
| 116 | |
| 117 | if (oem_id != OEM_UNKNOWN) |
| 118 | return oem_id; |
| 119 | |
| 120 | if (google_chromeec_cbi_get_oem_id(&id)) |
| 121 | return OEM_UNKNOWN; |
| 122 | |
| 123 | if (id > OEM_UNKNOWN) { |
| 124 | printk(BIOS_ERR, "%s: OEM ID too big %u!\n", __func__, id); |
| 125 | return OEM_UNKNOWN; |
| 126 | } |
| 127 | |
| 128 | oem_id = id; |
| 129 | printk(BIOS_DEBUG, "%s: OEM ID=%d\n", __func__, oem_id); |
| 130 | |
| 131 | return oem_id; |
| 132 | } |
| 133 | |
| 134 | /* "oem.bin" in cbfs contains array of records using the following structure. */ |
| 135 | struct oem_mapping { |
| 136 | uint8_t oem_id; |
| 137 | char oem_name[10]; |
| 138 | } __packed; |
| 139 | |
| 140 | /* Local buffer to read "oem.bin" */ |
| 141 | static char oem_bin_data[200]; |
| 142 | |
| 143 | const char *smbios_mainboard_manufacturer(void) |
| 144 | { |
| 145 | uint8_t oem_id = read_oem_id(); |
| 146 | const struct oem_mapping *oem_entry = (void *)&oem_bin_data; |
| 147 | size_t oem_data_size; |
| 148 | size_t curr = 0; |
| 149 | static const char *manuf; |
| 150 | |
| 151 | if (manuf) |
| 152 | return manuf; |
| 153 | |
| 154 | /* If OEM ID cannot be determined, return default manuf string. */ |
| 155 | if (oem_id == OEM_UNKNOWN) |
| 156 | return CONFIG_MAINBOARD_SMBIOS_MANUFACTURER; |
| 157 | |
Julius Werner | 834b3ec | 2020-03-04 16:52:08 -0800 | [diff] [blame^] | 158 | oem_data_size = cbfs_load("oem.bin", oem_bin_data, |
| 159 | sizeof(oem_bin_data)); |
Furquan Shaikh | f5b7e80 | 2018-05-07 14:42:27 -0700 | [diff] [blame] | 160 | |
| 161 | while ((curr < oem_data_size) && |
| 162 | ((oem_data_size - curr) >= sizeof(*oem_entry))) { |
| 163 | if (oem_id == oem_entry->oem_id) { |
| 164 | manuf = oem_entry->oem_name; |
| 165 | break; |
| 166 | } |
| 167 | curr += sizeof(*oem_entry); |
| 168 | oem_entry++; |
| 169 | } |
| 170 | |
| 171 | if (manuf == NULL) |
| 172 | manuf = CONFIG_MAINBOARD_SMBIOS_MANUFACTURER; |
| 173 | |
| 174 | return manuf; |
| 175 | } |
Furquan Shaikh | c6141b9 | 2018-05-10 21:58:39 -0700 | [diff] [blame] | 176 | |
| 177 | const char *mainboard_vbt_filename(void) |
| 178 | { |
| 179 | uint32_t sku_id = variant_board_sku(); |
| 180 | |
| 181 | switch (sku_id) { |
Ivy Jian | faafbfb | 2018-05-14 09:38:20 +0800 | [diff] [blame] | 182 | case SKU_0_PANTHEON: |
| 183 | case SKU_1_PANTHEON: |
Ivy Jian | 457253c | 2018-07-11 14:15:29 +0800 | [diff] [blame] | 184 | case SKU_2_PANTHEON: |
John Su | c2209e4 | 2019-03-05 10:41:46 +0800 | [diff] [blame] | 185 | case SKU_3_PANTHEON: |
| 186 | case SKU_4_PANTHEON: |
Ivy Jian | faafbfb | 2018-05-14 09:38:20 +0800 | [diff] [blame] | 187 | return "vbt-pantheon.bin"; |
Ivy Jian | 8bd5c5f | 2018-06-01 15:43:56 +0800 | [diff] [blame] | 188 | case SKU_0_VAYNE: |
| 189 | case SKU_1_VAYNE: |
| 190 | case SKU_2_VAYNE: |
| 191 | return "vbt-vayne.bin"; |
T.H. Lin | 770b034 | 2018-07-17 16:09:04 +0800 | [diff] [blame] | 192 | case SKU_0_AKALI: |
| 193 | case SKU_1_AKALI: |
| 194 | case SKU_0_AKALI360: |
| 195 | case SKU_1_AKALI360: |
| 196 | return "vbt-akali.bin"; |
Ren Kuo | 337afb0 | 2018-12-22 15:04:56 +0800 | [diff] [blame] | 197 | case SKU_0_BARD: |
| 198 | case SKU_1_BARD: |
| 199 | case SKU_2_BARD: |
| 200 | case SKU_3_BARD: |
Ren Kuo | deab64d | 2019-07-19 11:10:10 +0800 | [diff] [blame] | 201 | case SKU_4_BARD: |
| 202 | case SKU_5_BARD: |
Ren Kuo | 02240b7 | 2019-08-27 16:17:24 +0800 | [diff] [blame] | 203 | case SKU_6_BARD: |
| 204 | case SKU_7_BARD: |
Ren Kuo | 337afb0 | 2018-12-22 15:04:56 +0800 | [diff] [blame] | 205 | return "vbt-bard.bin"; |
Furquan Shaikh | c6141b9 | 2018-05-10 21:58:39 -0700 | [diff] [blame] | 206 | default: |
| 207 | return "vbt.bin"; |
Furquan Shaikh | c6141b9 | 2018-05-10 21:58:39 -0700 | [diff] [blame] | 208 | } |
| 209 | } |
Gaggery Tsai | 7062777 | 2018-07-26 00:14:09 -0700 | [diff] [blame] | 210 | |
| 211 | static int find_sku_mapping(const uint8_t oem_id) |
| 212 | { |
| 213 | /* Check if this OEM ID has a mapping table entry. */ |
| 214 | for (int i = 0; i < ARRAY_SIZE(sku_overwrite_mapping); i++) |
| 215 | if (oem_id == sku_overwrite_mapping[i].sku) |
| 216 | return i; |
| 217 | |
| 218 | return -1; |
| 219 | } |
| 220 | |
| 221 | /* Override dev tree settings per board */ |
| 222 | void variant_devtree_update(void) |
| 223 | { |
| 224 | uint32_t sku_id = variant_board_sku(); |
| 225 | uint32_t i; |
| 226 | int oem_index; |
John Su | 2257a35 | 2018-10-25 19:21:15 +0800 | [diff] [blame] | 227 | uint8_t pl2_id = PL2_ID_DEFAULT; |
Ivy Jian | b80d132 | 2019-05-27 11:19:44 +0800 | [diff] [blame] | 228 | struct device *spi_fpmcu = PCH_DEV_GSPI1; |
Gaggery Tsai | 7062777 | 2018-07-26 00:14:09 -0700 | [diff] [blame] | 229 | |
Kyösti Mälkki | d5f645c | 2019-09-28 00:20:27 +0300 | [diff] [blame] | 230 | config_t *cfg = config_of_soc(); |
Kyösti Mälkki | 28dc7dc | 2019-07-12 13:10:19 +0300 | [diff] [blame] | 231 | |
Gaggery Tsai | 7062777 | 2018-07-26 00:14:09 -0700 | [diff] [blame] | 232 | switch (sku_id) { |
Gaggery Tsai | 7062777 | 2018-07-26 00:14:09 -0700 | [diff] [blame] | 233 | case SKU_0_SONA: |
| 234 | case SKU_1_SONA: |
Amanda Huang | f7b57d0 | 2018-10-11 11:39:37 +0800 | [diff] [blame] | 235 | case SKU_0_SYNDRA: |
| 236 | case SKU_1_SYNDRA: |
| 237 | case SKU_2_SYNDRA: |
| 238 | case SKU_3_SYNDRA: |
Amanda Huang | 3080fe0 | 2018-12-17 13:25:03 +0800 | [diff] [blame] | 239 | case SKU_4_SYNDRA: |
| 240 | case SKU_5_SYNDRA: |
| 241 | case SKU_6_SYNDRA: |
| 242 | case SKU_7_SYNDRA: |
John Su | 2257a35 | 2018-10-25 19:21:15 +0800 | [diff] [blame] | 243 | pl2_id = PL2_ID_SONA_SYNDRA; |
Jacob Garber | 38b7445 | 2019-05-31 14:43:19 -0600 | [diff] [blame] | 244 | /* fallthrough */ |
John Su | 2257a35 | 2018-10-25 19:21:15 +0800 | [diff] [blame] | 245 | case SKU_0_VAYNE: |
| 246 | case SKU_1_VAYNE: |
| 247 | case SKU_2_VAYNE: |
| 248 | case SKU_0_PANTHEON: |
| 249 | case SKU_1_PANTHEON: |
| 250 | case SKU_2_PANTHEON: |
Frank Wu | d0cc3bc | 2018-12-24 11:25:36 +0800 | [diff] [blame] | 251 | case SKU_3_PANTHEON: |
| 252 | case SKU_4_PANTHEON: |
Gaggery Tsai | 7062777 | 2018-07-26 00:14:09 -0700 | [diff] [blame] | 253 | cfg->usb2_ports[5].enable = 0; |
Ivy Jian | b80d132 | 2019-05-27 11:19:44 +0800 | [diff] [blame] | 254 | spi_fpmcu->enabled = 0; |
Gaggery Tsai | 7062777 | 2018-07-26 00:14:09 -0700 | [diff] [blame] | 255 | break; |
Ren Kuo | a355b16 | 2018-12-12 14:39:36 +0800 | [diff] [blame] | 256 | case SKU_0_BARD: |
| 257 | case SKU_1_BARD: |
| 258 | case SKU_2_BARD: |
| 259 | case SKU_3_BARD: |
Ren Kuo | deab64d | 2019-07-19 11:10:10 +0800 | [diff] [blame] | 260 | case SKU_4_BARD: |
| 261 | case SKU_5_BARD: |
Ren Kuo | 02240b7 | 2019-08-27 16:17:24 +0800 | [diff] [blame] | 262 | case SKU_6_BARD: |
| 263 | case SKU_7_BARD: |
Ren Kuo | a355b16 | 2018-12-12 14:39:36 +0800 | [diff] [blame] | 264 | case SKU_0_EKKO: |
| 265 | case SKU_1_EKKO: |
| 266 | case SKU_2_EKKO: |
| 267 | case SKU_3_EKKO: |
Ren Kuo | 02240b7 | 2019-08-27 16:17:24 +0800 | [diff] [blame] | 268 | case SKU_4_EKKO: |
| 269 | case SKU_5_EKKO: |
| 270 | case SKU_6_EKKO: |
| 271 | case SKU_7_EKKO: |
Ren Kuo | a355b16 | 2018-12-12 14:39:36 +0800 | [diff] [blame] | 272 | pl2_id = PL2_ID_BARD_EKKO; |
Ren Kuo | 03f654c | 2019-01-18 17:12:33 +0800 | [diff] [blame] | 273 | cfg->usb2_ports[5].enable = 0; |
| 274 | cfg->usb2_ports[7].enable = 0; |
| 275 | cfg->usb2_ports[8].enable = 0; |
| 276 | cfg->usb2_ports[9].enable = 0; |
Ren Kuo | a355b16 | 2018-12-12 14:39:36 +0800 | [diff] [blame] | 277 | break; |
Gaggery Tsai | 7062777 | 2018-07-26 00:14:09 -0700 | [diff] [blame] | 278 | default: |
| 279 | break; |
| 280 | } |
| 281 | |
Sumeet R Pawnikar | 97c5464 | 2020-05-10 01:24:11 +0530 | [diff] [blame] | 282 | struct soc_power_limits_config *soc_conf; |
| 283 | soc_conf = &cfg->power_limits_config; |
| 284 | |
John Su | 2257a35 | 2018-10-25 19:21:15 +0800 | [diff] [blame] | 285 | /* Update PL2 based on SKU. */ |
Sumeet R Pawnikar | 97c5464 | 2020-05-10 01:24:11 +0530 | [diff] [blame] | 286 | soc_conf->tdp_pl2_override = get_pl2(pl2_id); |
John Su | 2257a35 | 2018-10-25 19:21:15 +0800 | [diff] [blame] | 287 | |
Gaggery Tsai | 7062777 | 2018-07-26 00:14:09 -0700 | [diff] [blame] | 288 | /* Overwrite settings for different projects based on OEM ID*/ |
| 289 | oem_index = find_sku_mapping(read_oem_id()); |
| 290 | |
| 291 | /* Return if the OEM ID is not supported or no changes are required */ |
| 292 | if (oem_index < 0) |
| 293 | return; |
| 294 | |
| 295 | for (i = 0; i < ARRAY_SIZE(cfg->domain_vr_config); i++) { |
| 296 | cfg->domain_vr_config[i].ac_loadline = |
| 297 | sku_overwrite_mapping[oem_index].ac_loadline[i]; |
| 298 | cfg->domain_vr_config[i].dc_loadline = |
| 299 | sku_overwrite_mapping[oem_index].dc_loadline[i]; |
| 300 | } |
| 301 | } |