blob: 01a91663b09eeda1b52b0c76e96505e100137aa2 [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>
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
Zhuohao Leef7b59552018-03-17 05:00:49 +080031uint32_t variant_board_sku(void)
amanda_hwangb3b47e12018-03-08 11:04:40 +080032{
Zhuohao Leef7b59552018-03-17 05:00:49 +080033 static uint32_t sku_id = SKU_UNKNOWN;
amanda_hwangb3b47e12018-03-08 11:04:40 +080034 uint32_t id;
Zhuohao Leef7b59552018-03-17 05:00:49 +080035
36 if (sku_id != SKU_UNKNOWN)
amanda_hwangb3b47e12018-03-08 11:04:40 +080037 return sku_id;
38 if (google_chromeec_cbi_get_sku_id(&id))
39 return SKU_UNKNOWN;
40 sku_id = id;
Zhuohao Leef7b59552018-03-17 05:00:49 +080041
amanda_hwangb3b47e12018-03-08 11:04:40 +080042 return sku_id;
43}
44
45void variant_devtree_update(void)
46{
47 /* Override dev tree settings per board */
Zhuohao Leef7b59552018-03-17 05:00:49 +080048 uint32_t sku_id = variant_board_sku();
Elyes HAOUASd129d432018-05-04 20:23:33 +020049 struct device *root = SA_DEV_ROOT;
amanda_hwangb3b47e12018-03-08 11:04:40 +080050 config_t *cfg = root->chip_info;
51 switch (sku_id) {
52 case SKU_1_VAYNE:
Amanda Huang7024e662018-04-10 14:09:36 +080053 case SKU_2_VAYNE:
amanda_hwangb3b47e12018-03-08 11:04:40 +080054 cfg->usb2_ports[5].enable = 0;//rear camera
55 break;
56 default:
57 break;
58 }
59}
Shelley Chen467cce42018-03-07 14:22:28 -080060
61const char *smbios_mainboard_sku(void)
62{
Zhuohao Leef7b59552018-03-17 05:00:49 +080063 static char sku_str[14]; /* sku{0..4294967295} */
Shelley Chen467cce42018-03-07 14:22:28 -080064
Zhuohao Leef7b59552018-03-17 05:00:49 +080065 snprintf(sku_str, sizeof(sku_str), "sku%u", variant_board_sku());
Shelley Chen467cce42018-03-07 14:22:28 -080066
67 return sku_str;
68}
Furquan Shaikhf5b7e802018-05-07 14:42:27 -070069
70#define OEM_UNKNOWN 0xff
71
72/*
73 * Read OEM ID from EC using cbi commands.
74 * Return value:
75 * Success = OEM ID read from EC
76 * Failure = OEM_UNKNOWN (0xff)
77 */
78static uint8_t read_oem_id(void)
79{
80 static uint8_t oem_id = OEM_UNKNOWN;
81 uint32_t id;
82
83 if (oem_id != OEM_UNKNOWN)
84 return oem_id;
85
86 if (google_chromeec_cbi_get_oem_id(&id))
87 return OEM_UNKNOWN;
88
89 if (id > OEM_UNKNOWN) {
90 printk(BIOS_ERR, "%s: OEM ID too big %u!\n", __func__, id);
91 return OEM_UNKNOWN;
92 }
93
94 oem_id = id;
95 printk(BIOS_DEBUG, "%s: OEM ID=%d\n", __func__, oem_id);
96
97 return oem_id;
98}
99
100/* "oem.bin" in cbfs contains array of records using the following structure. */
101struct oem_mapping {
102 uint8_t oem_id;
103 char oem_name[10];
104} __packed;
105
106/* Local buffer to read "oem.bin" */
107static char oem_bin_data[200];
108
109const char *smbios_mainboard_manufacturer(void)
110{
111 uint8_t oem_id = read_oem_id();
112 const struct oem_mapping *oem_entry = (void *)&oem_bin_data;
113 size_t oem_data_size;
114 size_t curr = 0;
115 static const char *manuf;
116
117 if (manuf)
118 return manuf;
119
120 /* If OEM ID cannot be determined, return default manuf string. */
121 if (oem_id == OEM_UNKNOWN)
122 return CONFIG_MAINBOARD_SMBIOS_MANUFACTURER;
123
124 oem_data_size = cbfs_boot_load_file("oem.bin", oem_bin_data,
125 sizeof(oem_bin_data),
126 CBFS_TYPE_RAW);
127
128 while ((curr < oem_data_size) &&
129 ((oem_data_size - curr) >= sizeof(*oem_entry))) {
130 if (oem_id == oem_entry->oem_id) {
131 manuf = oem_entry->oem_name;
132 break;
133 }
134 curr += sizeof(*oem_entry);
135 oem_entry++;
136 }
137
138 if (manuf == NULL)
139 manuf = CONFIG_MAINBOARD_SMBIOS_MANUFACTURER;
140
141 return manuf;
142}
Furquan Shaikhc6141b92018-05-10 21:58:39 -0700143
144const char *mainboard_vbt_filename(void)
145{
146 uint32_t sku_id = variant_board_sku();
147
148 switch (sku_id) {
149 default:
150 return "vbt.bin";
151 break;
152 }
153}