blob: bb77b6e9d282b4477582cd43ff1383176951efb0 [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>
24#include <ec/google/chromeec/ec.h>
Shelley Chen467cce42018-03-07 14:22:28 -080025#include <smbios.h>
26#include <soc/ramstage.h>
27#include <string.h>
amanda_hwang04ccd5f2018-03-16 13:43:52 +080028#include <variant/sku.h>
amanda_hwangb3b47e12018-03-08 11:04:40 +080029
Zhuohao Leef7b59552018-03-17 05:00:49 +080030uint32_t variant_board_sku(void)
amanda_hwangb3b47e12018-03-08 11:04:40 +080031{
Zhuohao Leef7b59552018-03-17 05:00:49 +080032 static uint32_t sku_id = SKU_UNKNOWN;
amanda_hwangb3b47e12018-03-08 11:04:40 +080033 uint32_t id;
Zhuohao Leef7b59552018-03-17 05:00:49 +080034
35 if (sku_id != SKU_UNKNOWN)
amanda_hwangb3b47e12018-03-08 11:04:40 +080036 return sku_id;
37 if (google_chromeec_cbi_get_sku_id(&id))
38 return SKU_UNKNOWN;
39 sku_id = id;
Zhuohao Leef7b59552018-03-17 05:00:49 +080040
amanda_hwangb3b47e12018-03-08 11:04:40 +080041 return sku_id;
42}
43
44void variant_devtree_update(void)
45{
46 /* Override dev tree settings per board */
Zhuohao Leef7b59552018-03-17 05:00:49 +080047 uint32_t sku_id = variant_board_sku();
Elyes HAOUASd129d432018-05-04 20:23:33 +020048 struct device *root = SA_DEV_ROOT;
amanda_hwangb3b47e12018-03-08 11:04:40 +080049 config_t *cfg = root->chip_info;
50 switch (sku_id) {
51 case SKU_1_VAYNE:
Amanda Huang7024e662018-04-10 14:09:36 +080052 case SKU_2_VAYNE:
amanda_hwangb3b47e12018-03-08 11:04:40 +080053 cfg->usb2_ports[5].enable = 0;//rear camera
54 break;
55 default:
56 break;
57 }
58}
Shelley Chen467cce42018-03-07 14:22:28 -080059
60const char *smbios_mainboard_sku(void)
61{
Zhuohao Leef7b59552018-03-17 05:00:49 +080062 static char sku_str[14]; /* sku{0..4294967295} */
Shelley Chen467cce42018-03-07 14:22:28 -080063
Zhuohao Leef7b59552018-03-17 05:00:49 +080064 snprintf(sku_str, sizeof(sku_str), "sku%u", variant_board_sku());
Shelley Chen467cce42018-03-07 14:22:28 -080065
66 return sku_str;
67}
Furquan Shaikhf5b7e802018-05-07 14:42:27 -070068
69#define OEM_UNKNOWN 0xff
70
71/*
72 * Read OEM ID from EC using cbi commands.
73 * Return value:
74 * Success = OEM ID read from EC
75 * Failure = OEM_UNKNOWN (0xff)
76 */
77static uint8_t read_oem_id(void)
78{
79 static uint8_t oem_id = OEM_UNKNOWN;
80 uint32_t id;
81
82 if (oem_id != OEM_UNKNOWN)
83 return oem_id;
84
85 if (google_chromeec_cbi_get_oem_id(&id))
86 return OEM_UNKNOWN;
87
88 if (id > OEM_UNKNOWN) {
89 printk(BIOS_ERR, "%s: OEM ID too big %u!\n", __func__, id);
90 return OEM_UNKNOWN;
91 }
92
93 oem_id = id;
94 printk(BIOS_DEBUG, "%s: OEM ID=%d\n", __func__, oem_id);
95
96 return oem_id;
97}
98
99/* "oem.bin" in cbfs contains array of records using the following structure. */
100struct oem_mapping {
101 uint8_t oem_id;
102 char oem_name[10];
103} __packed;
104
105/* Local buffer to read "oem.bin" */
106static char oem_bin_data[200];
107
108const char *smbios_mainboard_manufacturer(void)
109{
110 uint8_t oem_id = read_oem_id();
111 const struct oem_mapping *oem_entry = (void *)&oem_bin_data;
112 size_t oem_data_size;
113 size_t curr = 0;
114 static const char *manuf;
115
116 if (manuf)
117 return manuf;
118
119 /* If OEM ID cannot be determined, return default manuf string. */
120 if (oem_id == OEM_UNKNOWN)
121 return CONFIG_MAINBOARD_SMBIOS_MANUFACTURER;
122
123 oem_data_size = cbfs_boot_load_file("oem.bin", oem_bin_data,
124 sizeof(oem_bin_data),
125 CBFS_TYPE_RAW);
126
127 while ((curr < oem_data_size) &&
128 ((oem_data_size - curr) >= sizeof(*oem_entry))) {
129 if (oem_id == oem_entry->oem_id) {
130 manuf = oem_entry->oem_name;
131 break;
132 }
133 curr += sizeof(*oem_entry);
134 oem_entry++;
135 }
136
137 if (manuf == NULL)
138 manuf = CONFIG_MAINBOARD_SMBIOS_MANUFACTURER;
139
140 return manuf;
141}