blob: 7362ba6340b50a5e136a06bc59ad57c466f5a696 [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>
amanda_hwangb3b47e12018-03-08 11:04:40 +080022#include <device/device.h>
Furquan Shaikhc6141b92018-05-10 21:58:39 -070023#include <drivers/intel/gma/opregion.h>
amanda_hwangb3b47e12018-03-08 11:04:40 +080024#include <ec/google/chromeec/ec.h>
Furquan Shaikhe3011452018-05-23 21:27:33 -070025#include <intelblocks/mp_init.h>
Shelley Chen467cce42018-03-07 14:22:28 -080026#include <smbios.h>
27#include <soc/ramstage.h>
28#include <string.h>
amanda_hwang04ccd5f2018-03-16 13:43:52 +080029#include <variant/sku.h>
amanda_hwangb3b47e12018-03-08 11:04:40 +080030
Furquan Shaikhe3011452018-05-23 21:27:33 -070031#define PL2_I7_SKU 44
32#define PL2_DEFAULT 29
John Subac90c02018-06-28 14:29:23 +080033#define PL2_KBL_R 25
Furquan Shaikhe3011452018-05-23 21:27:33 -070034
Gaggery Tsai70627772018-07-26 00:14:09 -070035/* Variant for AKALI */
36#define AKALI_SA_AC_LOADLINE 1100
37#define AKALI_SA_DC_LOADLINE 1028
38#define AKALI_IA_AC_LOADLINE 272
39#define AKALI_IA_DC_LOADLINE 247
40#define AKALI_GT_AC_LOADLINE 314
41#define AKALI_GT_DC_LOADLINE 321
42
43/* We only have Akali and Nami default settings so far */
44enum project_sku {
45 PRJ_AKALI = 1,
46};
47
48static const struct {
49 enum project_sku sku;
50 int ac_loadline[NUM_VR_DOMAINS];
51 int dc_loadline[NUM_VR_DOMAINS];
52} sku_overwrite_mapping[] = {
53 {
54 .sku = PRJ_AKALI,
55 .ac_loadline = {
56 AKALI_SA_AC_LOADLINE,
57 AKALI_IA_AC_LOADLINE,
58 AKALI_GT_AC_LOADLINE,
59 AKALI_GT_AC_LOADLINE
60 },
61 .dc_loadline = {
62 AKALI_SA_DC_LOADLINE,
63 AKALI_IA_DC_LOADLINE,
64 AKALI_GT_DC_LOADLINE,
65 AKALI_GT_DC_LOADLINE
66 }
67 },
68};
69
John Subac90c02018-06-28 14:29:23 +080070static uint32_t get_pl2(uint32_t sku_id)
Furquan Shaikhe3011452018-05-23 21:27:33 -070071{
John Subac90c02018-06-28 14:29:23 +080072 if ((sku_id == SKU_0_SONA) || (sku_id == SKU_1_SONA)) {
73 if (cpuid_eax(1) == CPUID_KABYLAKE_Y0)
74 return PL2_DEFAULT;
75
76 return PL2_KBL_R;
77 }
Furquan Shaikhe3011452018-05-23 21:27:33 -070078 if (cpuid_eax(1) == CPUID_KABYLAKE_Y0)
79 return PL2_I7_SKU;
80
81 return PL2_DEFAULT;
82}
83
Zhuohao Leef7b59552018-03-17 05:00:49 +080084uint32_t variant_board_sku(void)
amanda_hwangb3b47e12018-03-08 11:04:40 +080085{
Zhuohao Leef7b59552018-03-17 05:00:49 +080086 static uint32_t sku_id = SKU_UNKNOWN;
amanda_hwangb3b47e12018-03-08 11:04:40 +080087 uint32_t id;
Zhuohao Leef7b59552018-03-17 05:00:49 +080088
89 if (sku_id != SKU_UNKNOWN)
amanda_hwangb3b47e12018-03-08 11:04:40 +080090 return sku_id;
91 if (google_chromeec_cbi_get_sku_id(&id))
92 return SKU_UNKNOWN;
93 sku_id = id;
Zhuohao Leef7b59552018-03-17 05:00:49 +080094
amanda_hwangb3b47e12018-03-08 11:04:40 +080095 return sku_id;
96}
97
Shelley Chen467cce42018-03-07 14:22:28 -080098const char *smbios_mainboard_sku(void)
99{
Zhuohao Leef7b59552018-03-17 05:00:49 +0800100 static char sku_str[14]; /* sku{0..4294967295} */
Shelley Chen467cce42018-03-07 14:22:28 -0800101
Zhuohao Leef7b59552018-03-17 05:00:49 +0800102 snprintf(sku_str, sizeof(sku_str), "sku%u", variant_board_sku());
Shelley Chen467cce42018-03-07 14:22:28 -0800103
104 return sku_str;
105}
Furquan Shaikhf5b7e802018-05-07 14:42:27 -0700106
107#define OEM_UNKNOWN 0xff
108
109/*
110 * Read OEM ID from EC using cbi commands.
111 * Return value:
112 * Success = OEM ID read from EC
113 * Failure = OEM_UNKNOWN (0xff)
114 */
115static uint8_t read_oem_id(void)
116{
117 static uint8_t oem_id = OEM_UNKNOWN;
118 uint32_t id;
119
120 if (oem_id != OEM_UNKNOWN)
121 return oem_id;
122
123 if (google_chromeec_cbi_get_oem_id(&id))
124 return OEM_UNKNOWN;
125
126 if (id > OEM_UNKNOWN) {
127 printk(BIOS_ERR, "%s: OEM ID too big %u!\n", __func__, id);
128 return OEM_UNKNOWN;
129 }
130
131 oem_id = id;
132 printk(BIOS_DEBUG, "%s: OEM ID=%d\n", __func__, oem_id);
133
134 return oem_id;
135}
136
137/* "oem.bin" in cbfs contains array of records using the following structure. */
138struct oem_mapping {
139 uint8_t oem_id;
140 char oem_name[10];
141} __packed;
142
143/* Local buffer to read "oem.bin" */
144static char oem_bin_data[200];
145
146const char *smbios_mainboard_manufacturer(void)
147{
148 uint8_t oem_id = read_oem_id();
149 const struct oem_mapping *oem_entry = (void *)&oem_bin_data;
150 size_t oem_data_size;
151 size_t curr = 0;
152 static const char *manuf;
153
154 if (manuf)
155 return manuf;
156
157 /* If OEM ID cannot be determined, return default manuf string. */
158 if (oem_id == OEM_UNKNOWN)
159 return CONFIG_MAINBOARD_SMBIOS_MANUFACTURER;
160
161 oem_data_size = cbfs_boot_load_file("oem.bin", oem_bin_data,
162 sizeof(oem_bin_data),
163 CBFS_TYPE_RAW);
164
165 while ((curr < oem_data_size) &&
166 ((oem_data_size - curr) >= sizeof(*oem_entry))) {
167 if (oem_id == oem_entry->oem_id) {
168 manuf = oem_entry->oem_name;
169 break;
170 }
171 curr += sizeof(*oem_entry);
172 oem_entry++;
173 }
174
175 if (manuf == NULL)
176 manuf = CONFIG_MAINBOARD_SMBIOS_MANUFACTURER;
177
178 return manuf;
179}
Furquan Shaikhc6141b92018-05-10 21:58:39 -0700180
181const char *mainboard_vbt_filename(void)
182{
183 uint32_t sku_id = variant_board_sku();
184
185 switch (sku_id) {
Ivy Jianfaafbfb2018-05-14 09:38:20 +0800186 case SKU_0_PANTHEON:
187 case SKU_1_PANTHEON:
Ivy Jian457253c2018-07-11 14:15:29 +0800188 case SKU_2_PANTHEON:
Ivy Jianfaafbfb2018-05-14 09:38:20 +0800189 return "vbt-pantheon.bin";
Ivy Jian8bd5c5f2018-06-01 15:43:56 +0800190 case SKU_0_VAYNE:
191 case SKU_1_VAYNE:
192 case SKU_2_VAYNE:
193 return "vbt-vayne.bin";
T.H. Lin770b0342018-07-17 16:09:04 +0800194 case SKU_0_AKALI:
195 case SKU_1_AKALI:
196 case SKU_0_AKALI360:
197 case SKU_1_AKALI360:
198 return "vbt-akali.bin";
Furquan Shaikhc6141b92018-05-10 21:58:39 -0700199 default:
200 return "vbt.bin";
201 break;
202 }
203}
Gaggery Tsai70627772018-07-26 00:14:09 -0700204
205static int find_sku_mapping(const uint8_t oem_id)
206{
207 /* Check if this OEM ID has a mapping table entry. */
208 for (int i = 0; i < ARRAY_SIZE(sku_overwrite_mapping); i++)
209 if (oem_id == sku_overwrite_mapping[i].sku)
210 return i;
211
212 return -1;
213}
214
215/* Override dev tree settings per board */
216void variant_devtree_update(void)
217{
218 uint32_t sku_id = variant_board_sku();
219 uint32_t i;
220 int oem_index;
221 struct device *root = SA_DEV_ROOT;
222 config_t *cfg = root->chip_info;
223
224 /* Update PL2 based on SKU. */
225
226 cfg->tdp_pl2_override = get_pl2(sku_id);
227
228 switch (sku_id) {
229 case SKU_0_VAYNE:
230 case SKU_1_VAYNE:
231 case SKU_2_VAYNE:
232 case SKU_0_PANTHEON:
233 case SKU_1_PANTHEON:
234 case SKU_2_PANTHEON:
235 case SKU_0_SONA:
236 case SKU_1_SONA:
Amanda Huangf7b57d02018-10-11 11:39:37 +0800237 case SKU_0_SYNDRA:
238 case SKU_1_SYNDRA:
239 case SKU_2_SYNDRA:
240 case SKU_3_SYNDRA:
Gaggery Tsai70627772018-07-26 00:14:09 -0700241 /* Disable unused port USB port */
242 cfg->usb2_ports[5].enable = 0;
243 break;
244 default:
245 break;
246 }
247
248 /* Overwrite settings for different projects based on OEM ID*/
249 oem_index = find_sku_mapping(read_oem_id());
250
251 /* Return if the OEM ID is not supported or no changes are required */
252 if (oem_index < 0)
253 return;
254
255 for (i = 0; i < ARRAY_SIZE(cfg->domain_vr_config); i++) {
256 cfg->domain_vr_config[i].ac_loadline =
257 sku_overwrite_mapping[oem_index].ac_loadline[i];
258 cfg->domain_vr_config[i].dc_loadline =
259 sku_overwrite_mapping[oem_index].dc_loadline[i];
260 }
261}