blob: 2052ae0fbde90269f618f6f48f961f6db75f12bc [file] [log] [blame]
amanda_hwangb3b47e12018-03-08 11:04:40 +08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2018 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
Shelley Chen467cce42018-03-07 14:22:28 -080016#include <arch/cpu.h>
17#include <assert.h>
18#include <baseboard/variants.h>
Furquan Shaikhf5b7e802018-05-07 14:42:27 -070019#include <cbfs.h>
amanda_hwangb3b47e12018-03-08 11:04:40 +080020#include <chip.h>
Furquan Shaikhf5b7e802018-05-07 14:42:27 -070021#include <commonlib/cbfs_serialized.h>
22#include <compiler.h>
amanda_hwangb3b47e12018-03-08 11:04:40 +080023#include <device/device.h>
Furquan Shaikhc6141b92018-05-10 21:58:39 -070024#include <drivers/intel/gma/opregion.h>
amanda_hwangb3b47e12018-03-08 11:04:40 +080025#include <ec/google/chromeec/ec.h>
Furquan Shaikhe3011452018-05-23 21:27:33 -070026#include <intelblocks/mp_init.h>
Shelley Chen467cce42018-03-07 14:22:28 -080027#include <smbios.h>
28#include <soc/ramstage.h>
29#include <string.h>
amanda_hwang04ccd5f2018-03-16 13:43:52 +080030#include <variant/sku.h>
amanda_hwangb3b47e12018-03-08 11:04:40 +080031
Furquan Shaikhe3011452018-05-23 21:27:33 -070032#define PL2_I7_SKU 44
33#define PL2_DEFAULT 29
John Subac90c02018-06-28 14:29:23 +080034#define PL2_KBL_R 25
Furquan Shaikhe3011452018-05-23 21:27:33 -070035
Gaggery Tsai70627772018-07-26 00:14:09 -070036/* Variant for AKALI */
37#define AKALI_SA_AC_LOADLINE 1100
38#define AKALI_SA_DC_LOADLINE 1028
39#define AKALI_IA_AC_LOADLINE 272
40#define AKALI_IA_DC_LOADLINE 247
41#define AKALI_GT_AC_LOADLINE 314
42#define AKALI_GT_DC_LOADLINE 321
43
44/* We only have Akali and Nami default settings so far */
45enum project_sku {
46 PRJ_AKALI = 1,
47};
48
49static const struct {
50 enum project_sku sku;
51 int ac_loadline[NUM_VR_DOMAINS];
52 int dc_loadline[NUM_VR_DOMAINS];
53} sku_overwrite_mapping[] = {
54 {
55 .sku = PRJ_AKALI,
56 .ac_loadline = {
57 AKALI_SA_AC_LOADLINE,
58 AKALI_IA_AC_LOADLINE,
59 AKALI_GT_AC_LOADLINE,
60 AKALI_GT_AC_LOADLINE
61 },
62 .dc_loadline = {
63 AKALI_SA_DC_LOADLINE,
64 AKALI_IA_DC_LOADLINE,
65 AKALI_GT_DC_LOADLINE,
66 AKALI_GT_DC_LOADLINE
67 }
68 },
69};
70
John Subac90c02018-06-28 14:29:23 +080071static uint32_t get_pl2(uint32_t sku_id)
Furquan Shaikhe3011452018-05-23 21:27:33 -070072{
John Subac90c02018-06-28 14:29:23 +080073 if ((sku_id == SKU_0_SONA) || (sku_id == SKU_1_SONA)) {
74 if (cpuid_eax(1) == CPUID_KABYLAKE_Y0)
75 return PL2_DEFAULT;
76
77 return PL2_KBL_R;
78 }
Furquan Shaikhe3011452018-05-23 21:27:33 -070079 if (cpuid_eax(1) == CPUID_KABYLAKE_Y0)
80 return PL2_I7_SKU;
81
82 return PL2_DEFAULT;
83}
84
Zhuohao Leef7b59552018-03-17 05:00:49 +080085uint32_t variant_board_sku(void)
amanda_hwangb3b47e12018-03-08 11:04:40 +080086{
Zhuohao Leef7b59552018-03-17 05:00:49 +080087 static uint32_t sku_id = SKU_UNKNOWN;
amanda_hwangb3b47e12018-03-08 11:04:40 +080088 uint32_t id;
Zhuohao Leef7b59552018-03-17 05:00:49 +080089
90 if (sku_id != SKU_UNKNOWN)
amanda_hwangb3b47e12018-03-08 11:04:40 +080091 return sku_id;
92 if (google_chromeec_cbi_get_sku_id(&id))
93 return SKU_UNKNOWN;
94 sku_id = id;
Zhuohao Leef7b59552018-03-17 05:00:49 +080095
amanda_hwangb3b47e12018-03-08 11:04:40 +080096 return sku_id;
97}
98
Shelley Chen467cce42018-03-07 14:22:28 -080099const char *smbios_mainboard_sku(void)
100{
Zhuohao Leef7b59552018-03-17 05:00:49 +0800101 static char sku_str[14]; /* sku{0..4294967295} */
Shelley Chen467cce42018-03-07 14:22:28 -0800102
Zhuohao Leef7b59552018-03-17 05:00:49 +0800103 snprintf(sku_str, sizeof(sku_str), "sku%u", variant_board_sku());
Shelley Chen467cce42018-03-07 14:22:28 -0800104
105 return sku_str;
106}
Furquan Shaikhf5b7e802018-05-07 14:42:27 -0700107
108#define OEM_UNKNOWN 0xff
109
110/*
111 * Read OEM ID from EC using cbi commands.
112 * Return value:
113 * Success = OEM ID read from EC
114 * Failure = OEM_UNKNOWN (0xff)
115 */
116static uint8_t read_oem_id(void)
117{
118 static uint8_t oem_id = OEM_UNKNOWN;
119 uint32_t id;
120
121 if (oem_id != OEM_UNKNOWN)
122 return oem_id;
123
124 if (google_chromeec_cbi_get_oem_id(&id))
125 return OEM_UNKNOWN;
126
127 if (id > OEM_UNKNOWN) {
128 printk(BIOS_ERR, "%s: OEM ID too big %u!\n", __func__, id);
129 return OEM_UNKNOWN;
130 }
131
132 oem_id = id;
133 printk(BIOS_DEBUG, "%s: OEM ID=%d\n", __func__, oem_id);
134
135 return oem_id;
136}
137
138/* "oem.bin" in cbfs contains array of records using the following structure. */
139struct oem_mapping {
140 uint8_t oem_id;
141 char oem_name[10];
142} __packed;
143
144/* Local buffer to read "oem.bin" */
145static char oem_bin_data[200];
146
147const char *smbios_mainboard_manufacturer(void)
148{
149 uint8_t oem_id = read_oem_id();
150 const struct oem_mapping *oem_entry = (void *)&oem_bin_data;
151 size_t oem_data_size;
152 size_t curr = 0;
153 static const char *manuf;
154
155 if (manuf)
156 return manuf;
157
158 /* If OEM ID cannot be determined, return default manuf string. */
159 if (oem_id == OEM_UNKNOWN)
160 return CONFIG_MAINBOARD_SMBIOS_MANUFACTURER;
161
162 oem_data_size = cbfs_boot_load_file("oem.bin", oem_bin_data,
163 sizeof(oem_bin_data),
164 CBFS_TYPE_RAW);
165
166 while ((curr < oem_data_size) &&
167 ((oem_data_size - curr) >= sizeof(*oem_entry))) {
168 if (oem_id == oem_entry->oem_id) {
169 manuf = oem_entry->oem_name;
170 break;
171 }
172 curr += sizeof(*oem_entry);
173 oem_entry++;
174 }
175
176 if (manuf == NULL)
177 manuf = CONFIG_MAINBOARD_SMBIOS_MANUFACTURER;
178
179 return manuf;
180}
Furquan Shaikhc6141b92018-05-10 21:58:39 -0700181
182const char *mainboard_vbt_filename(void)
183{
184 uint32_t sku_id = variant_board_sku();
185
186 switch (sku_id) {
Ivy Jianfaafbfb2018-05-14 09:38:20 +0800187 case SKU_0_PANTHEON:
188 case SKU_1_PANTHEON:
Ivy Jian457253c2018-07-11 14:15:29 +0800189 case SKU_2_PANTHEON:
Ivy Jianfaafbfb2018-05-14 09:38:20 +0800190 return "vbt-pantheon.bin";
Ivy Jian8bd5c5f2018-06-01 15:43:56 +0800191 case SKU_0_VAYNE:
192 case SKU_1_VAYNE:
193 case SKU_2_VAYNE:
194 return "vbt-vayne.bin";
T.H. Lin770b0342018-07-17 16:09:04 +0800195 case SKU_0_AKALI:
196 case SKU_1_AKALI:
197 case SKU_0_AKALI360:
198 case SKU_1_AKALI360:
199 return "vbt-akali.bin";
Furquan Shaikhc6141b92018-05-10 21:58:39 -0700200 default:
201 return "vbt.bin";
202 break;
203 }
204}
Gaggery Tsai70627772018-07-26 00:14:09 -0700205
206static int find_sku_mapping(const uint8_t oem_id)
207{
208 /* Check if this OEM ID has a mapping table entry. */
209 for (int i = 0; i < ARRAY_SIZE(sku_overwrite_mapping); i++)
210 if (oem_id == sku_overwrite_mapping[i].sku)
211 return i;
212
213 return -1;
214}
215
216/* Override dev tree settings per board */
217void variant_devtree_update(void)
218{
219 uint32_t sku_id = variant_board_sku();
220 uint32_t i;
221 int oem_index;
222 struct device *root = SA_DEV_ROOT;
223 config_t *cfg = root->chip_info;
224
225 /* Update PL2 based on SKU. */
226
227 cfg->tdp_pl2_override = get_pl2(sku_id);
228
229 switch (sku_id) {
230 case SKU_0_VAYNE:
231 case SKU_1_VAYNE:
232 case SKU_2_VAYNE:
233 case SKU_0_PANTHEON:
234 case SKU_1_PANTHEON:
235 case SKU_2_PANTHEON:
236 case SKU_0_SONA:
237 case SKU_1_SONA:
238 /* Disable unused port USB port */
239 cfg->usb2_ports[5].enable = 0;
240 break;
241 default:
242 break;
243 }
244
245 /* Overwrite settings for different projects based on OEM ID*/
246 oem_index = find_sku_mapping(read_oem_id());
247
248 /* Return if the OEM ID is not supported or no changes are required */
249 if (oem_index < 0)
250 return;
251
252 for (i = 0; i < ARRAY_SIZE(cfg->domain_vr_config); i++) {
253 cfg->domain_vr_config[i].ac_loadline =
254 sku_overwrite_mapping[oem_index].ac_loadline[i];
255 cfg->domain_vr_config[i].dc_loadline =
256 sku_overwrite_mapping[oem_index].dc_loadline[i];
257 }
258}