summaryrefslogtreecommitdiff
path: root/src/mainboard/google/poppy/variants/nami/mainboard.c
blob: e764523f3f509d57aa0c2acbc5dda5ce5d5dada9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
/* SPDX-License-Identifier: GPL-2.0-only */

#include <assert.h>
#include <baseboard/variants.h>
#include <cbfs.h>
#include <chip.h>
#include <console/console.h>
#include <cpu/cpu.h>
#include <cpu/intel/cpu_ids.h>
#include <device/device.h>
#include <drivers/intel/gma/opregion.h>
#include <ec/google/chromeec/ec.h>
#include <intelblocks/power_limit.h>
#include <smbios.h>
#include <soc/ramstage.h>
#include <string.h>
#include <variant/sku.h>
#include <gpio.h>
#include <delay.h>

#define PL2_I7_SKU	44
#define PL2_DEFAULT	29
#define PL2_KBL_U	25

/* PL2 ID define*/
#define PL2_ID_DEFAULT		0
#define PL2_ID_SONA_SYNDRA	1
#define PL2_ID_BARD_EKKO	2

static const struct pl2_config {
	uint32_t cpuid_y0_pl2;
	uint32_t cpuid_non_y0_pl2;
} pl2_config_table[] = {
	[PL2_ID_DEFAULT] = { PL2_I7_SKU, PL2_DEFAULT },
	[PL2_ID_SONA_SYNDRA] = { PL2_DEFAULT, PL2_KBL_U },
	[PL2_ID_BARD_EKKO] = { PL2_DEFAULT, PL2_KBL_U },
};

/* Variant for AKALI */
#define AKALI_SA_AC_LOADLINE	1100
#define AKALI_SA_DC_LOADLINE	1028
#define AKALI_IA_AC_LOADLINE	272
#define AKALI_IA_DC_LOADLINE	247
#define AKALI_GT_AC_LOADLINE	314
#define AKALI_GT_DC_LOADLINE	321

/* We only have Akali and Nami default settings so far */
enum project_sku {
	PRJ_AKALI = 1,
};

static const struct {
	enum project_sku sku;
	int ac_loadline[NUM_VR_DOMAINS];
	int dc_loadline[NUM_VR_DOMAINS];
} sku_overwrite_mapping[] = {
	{
		.sku = PRJ_AKALI,
		.ac_loadline = {
			AKALI_SA_AC_LOADLINE,
			AKALI_IA_AC_LOADLINE,
			AKALI_GT_AC_LOADLINE,
			AKALI_GT_AC_LOADLINE
		},
		.dc_loadline = {
			AKALI_SA_DC_LOADLINE,
			AKALI_IA_DC_LOADLINE,
			AKALI_GT_DC_LOADLINE,
			AKALI_GT_DC_LOADLINE
		}
	},
};

static uint32_t get_pl2(int pl2_id)
{
	assert(pl2_id < ARRAY_SIZE(pl2_config_table));
	if (cpuid_eax(1) == CPUID_KABYLAKE_Y0)
		return pl2_config_table[pl2_id].cpuid_y0_pl2;

	return pl2_config_table[pl2_id].cpuid_non_y0_pl2;
}

uint32_t variant_board_sku(void)
{
	static uint32_t sku_id = SKU_UNKNOWN;
	uint32_t id;

	if (sku_id != SKU_UNKNOWN)
		return sku_id;
	if (google_chromeec_cbi_get_sku_id(&id))
		return SKU_UNKNOWN;
	sku_id = id;

	return sku_id;
}

const char *smbios_system_sku(void)
{
	static char sku_str[14]; /* sku{0..4294967295} */

	snprintf(sku_str, sizeof(sku_str), "sku%u", variant_board_sku());

	return sku_str;
}

#define OEM_UNKNOWN	0xff

/*
 * Read OEM ID from EC using cbi commands.
 * Return value:
 * Success = OEM ID read from EC
 * Failure = OEM_UNKNOWN (0xff)
 */
static uint8_t read_oem_id(void)
{
	static uint8_t oem_id = OEM_UNKNOWN;
	uint32_t id;

	if (oem_id != OEM_UNKNOWN)
		return oem_id;

	if (google_chromeec_cbi_get_oem_id(&id))
		return OEM_UNKNOWN;

	if (id > OEM_UNKNOWN) {
		printk(BIOS_ERR, "%s: OEM ID too big %u!\n", __func__, id);
		return OEM_UNKNOWN;
	}

	oem_id = id;
	printk(BIOS_DEBUG, "%s: OEM ID=%d\n", __func__, oem_id);

	return oem_id;
}

/* "oem.bin" in cbfs contains array of records using the following structure. */
struct oem_mapping {
	uint8_t oem_id;
	char oem_name[10];
} __packed;

/* Local buffer to read "oem.bin" */
static char oem_bin_data[200];

const char *smbios_mainboard_manufacturer(void)
{
	uint8_t oem_id = read_oem_id();
	const struct oem_mapping *oem_entry = (void *)&oem_bin_data;
	size_t oem_data_size;
	size_t curr = 0;
	static const char *manuf;

	if (manuf)
		return manuf;

	/* If OEM ID cannot be determined, return default manuf string. */
	if (oem_id == OEM_UNKNOWN)
		return CONFIG_MAINBOARD_SMBIOS_MANUFACTURER;

	oem_data_size = cbfs_load("oem.bin", oem_bin_data,
				  sizeof(oem_bin_data));

	while ((curr < oem_data_size) &&
	       ((oem_data_size - curr) >= sizeof(*oem_entry))) {
		if (oem_id == oem_entry->oem_id) {
			manuf = oem_entry->oem_name;
			break;
		}
		curr += sizeof(*oem_entry);
		oem_entry++;
	}

	if (manuf == NULL)
		manuf = CONFIG_MAINBOARD_SMBIOS_MANUFACTURER;

	return manuf;
}

const char *smbios_mainboard_product_name(void)
{
	uint32_t sku_id = variant_board_sku();
	static char product[12];

	switch (sku_id) {
	case SKU_0_PANTHEON:
	case SKU_1_PANTHEON:
	case SKU_2_PANTHEON:
	case SKU_3_PANTHEON:
	case SKU_4_PANTHEON:
		snprintf(product, sizeof(product), "Pantheon"); break;
	case SKU_0_VAYNE:
	case SKU_1_VAYNE:
	case SKU_2_VAYNE:
		snprintf(product, sizeof(product), "Vayne"); break;
	case SKU_0_AKALI:
	case SKU_1_AKALI:
		snprintf(product, sizeof(product), "Akali"); break;
	case SKU_0_AKALI360:
	case SKU_1_AKALI360:
		snprintf(product, sizeof(product), "Akali 360"); break;
	case SKU_0_BARD:
	case SKU_1_BARD:
	case SKU_2_BARD:
	case SKU_3_BARD:
		snprintf(product, sizeof(product), "Bard"); break;
	case SKU_0_EKKO:
	case SKU_1_EKKO:
	case SKU_2_EKKO:
	case SKU_3_EKKO:
		snprintf(product, sizeof(product), "Ekko"); break;
	case SKU_0_SONA:
	case SKU_1_SONA:
		snprintf(product, sizeof(product), "Sona"); break;
	case SKU_0_SYNDRA:
	case SKU_1_SYNDRA:
	case SKU_2_SYNDRA:
	case SKU_3_SYNDRA:
	case SKU_4_SYNDRA:
	case SKU_5_SYNDRA:
	case SKU_6_SYNDRA:
	case SKU_7_SYNDRA:
		snprintf(product, sizeof(product), "Syndra"); break;
	default:
		snprintf(product, sizeof(product), "Nami"); break;
	}
	return product;
}

const char *mainboard_vbt_filename(void)
{
	uint32_t sku_id = variant_board_sku();

	switch (sku_id) {
	case SKU_0_PANTHEON:
	case SKU_1_PANTHEON:
	case SKU_2_PANTHEON:
	case SKU_3_PANTHEON:
	case SKU_4_PANTHEON:
		return "vbt-pantheon.bin";
	case SKU_0_VAYNE:
	case SKU_1_VAYNE:
	case SKU_2_VAYNE:
		return "vbt-vayne.bin";
	case SKU_0_AKALI:
	case SKU_1_AKALI:
	case SKU_0_AKALI360:
	case SKU_1_AKALI360:
		return "vbt-akali.bin";
	case SKU_0_BARD:
	case SKU_1_BARD:
	case SKU_2_BARD:
	case SKU_3_BARD:
	case SKU_4_BARD:
	case SKU_5_BARD:
	case SKU_6_BARD:
	case SKU_7_BARD:
		return "vbt-bard.bin";
	default:
		return "vbt.bin";
	}
}

static int find_sku_mapping(const uint8_t oem_id)
{
	/* Check if this OEM ID has a mapping table entry. */
	for (int i = 0; i < ARRAY_SIZE(sku_overwrite_mapping); i++)
		if (oem_id == sku_overwrite_mapping[i].sku)
			return i;

	return -1;
}

/* Override dev tree settings per board */
void variant_devtree_update(void)
{
	uint32_t sku_id = variant_board_sku();
	uint32_t i;
	int oem_index;
	uint8_t pl2_id = PL2_ID_DEFAULT;
	struct device *spi_fpmcu = PCH_DEV_GSPI1;

	config_t *cfg = config_of_soc();

	switch (sku_id) {
	case SKU_0_SONA:
	case SKU_1_SONA:
	case SKU_0_SYNDRA:
	case SKU_1_SYNDRA:
	case SKU_2_SYNDRA:
	case SKU_3_SYNDRA:
	case SKU_4_SYNDRA:
	case SKU_5_SYNDRA:
	case SKU_6_SYNDRA:
	case SKU_7_SYNDRA:
		pl2_id = PL2_ID_SONA_SYNDRA;
		__fallthrough;
	case SKU_0_VAYNE:
	case SKU_1_VAYNE:
	case SKU_2_VAYNE:
	case SKU_0_PANTHEON:
	case SKU_1_PANTHEON:
	case SKU_2_PANTHEON:
	case SKU_3_PANTHEON:
	case SKU_4_PANTHEON:
		cfg->usb2_ports[5].enable = 0;
		spi_fpmcu->enabled = 0;
		break;
	case SKU_0_BARD:
	case SKU_1_BARD:
	case SKU_2_BARD:
	case SKU_3_BARD:
	case SKU_4_BARD:
	case SKU_5_BARD:
	case SKU_6_BARD:
	case SKU_7_BARD:
	case SKU_0_EKKO:
	case SKU_1_EKKO:
	case SKU_2_EKKO:
	case SKU_3_EKKO:
	case SKU_4_EKKO:
	case SKU_5_EKKO:
	case SKU_6_EKKO:
	case SKU_7_EKKO:
		pl2_id = PL2_ID_BARD_EKKO;
		cfg->usb2_ports[5].enable = 0;
		cfg->usb2_ports[7].enable = 0;
		cfg->usb2_ports[8].enable = 0;
		cfg->usb2_ports[9].enable = 0;
		break;
	default:
		break;
	}

	struct soc_power_limits_config *soc_conf;
	soc_conf = &cfg->power_limits_config;

	/* Update PL2 based on SKU. */
	soc_conf->tdp_pl2_override = get_pl2(pl2_id);

	/* Overwrite settings for different projects based on OEM ID*/
	oem_index = find_sku_mapping(read_oem_id());

	/* Return if the OEM ID is not supported or no changes are required */
	if (oem_index < 0)
		return;

	for (i = 0; i < ARRAY_SIZE(cfg->domain_vr_config); i++) {
		cfg->domain_vr_config[i].ac_loadline =
				sku_overwrite_mapping[oem_index].ac_loadline[i];
		cfg->domain_vr_config[i].dc_loadline =
				sku_overwrite_mapping[oem_index].dc_loadline[i];
	}
}

void variant_final(void)
{
	uint32_t sku_id = variant_board_sku();

	switch (sku_id) {
	case SKU_0_BARD:
	case SKU_1_BARD:
	case SKU_2_BARD:
	case SKU_3_BARD:
	case SKU_4_BARD:
	case SKU_5_BARD:
	case SKU_6_BARD:
	case SKU_7_BARD:
	case SKU_0_EKKO:
	case SKU_1_EKKO:
	case SKU_2_EKKO:
	case SKU_3_EKKO:
	case SKU_4_EKKO:
	case SKU_5_EKKO:
	case SKU_6_EKKO:
	case SKU_7_EKKO:
		/* Enable FPMCU late in the boot process to achieve
		 * ~150ms of power off time in total.
		 */
		gpio_output(GPP_B11, 1);	/* PCH_FP_PWR_EN */
		mdelay(3);
		gpio_output(GPP_C9, 1);		/* FP_RST_ODL */
		break;
	default:
		break;
	}
}