cpu/x86/smm/pci_resource_store: Store DEV/VEN ID
[coreboot2.git] / src / mainboard / google / corsola / boardid.c
blob443c3d1149d43b263ae1d4fcef8b3033c3fc1a83
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <assert.h>
4 #include <boardid.h>
5 #include <console/console.h>
6 #include <ec/google/chromeec/ec.h>
7 #include <soc/auxadc.h>
9 #include "panel.h"
11 /* board_id is provided by ec/google/chromeec/ec_boardid.c */
13 #define ADC_LEVELS 12
15 enum {
16 /* RAM IDs */
17 RAM_ID_LOW_CHANNEL = 2,
18 RAM_ID_HIGH_CHANNEL = 3,
19 /* SKU IDs */
20 SKU_ID_LOW_CHANNEL = 4,
21 SKU_ID_HIGH_CHANNEL = 5,
24 static const unsigned int lcm_voltages[ADC_LEVELS] = {
25 /* ID : Voltage (unit: uV) */
26 [0] = 0,
27 [1] = 89191,
28 [2] = 148419,
29 [3] = 205240,
30 [4] = 282774,
31 [5] = 393556,
32 [6] = 495561,
33 [7] = 641944,
34 [8] = 798049,
35 [9] = 960054,
36 [10] = 1191264,
37 [11] = 1433691,
40 static const unsigned int ram_voltages[ADC_LEVELS] = {
41 /* ID : Voltage (unit: uV) */
42 [0] = 74300,
43 [1] = 211700,
44 [2] = 318800,
45 [3] = 428600,
46 [4] = 541700,
47 [5] = 665800,
48 [6] = 781400,
49 [7] = 900000,
50 [8] = 1023100,
51 [9] = 1137000,
52 [10] = 1240000,
53 [11] = 1342600,
56 static const unsigned int *adc_voltages[] = {
57 [RAM_ID_LOW_CHANNEL] = ram_voltages,
58 [RAM_ID_HIGH_CHANNEL] = ram_voltages,
59 [SKU_ID_LOW_CHANNEL] = ram_voltages,
60 [SKU_ID_HIGH_CHANNEL] = ram_voltages,
63 static const unsigned int *adc_voltages_detachable[] = {
64 [RAM_ID_LOW_CHANNEL] = ram_voltages,
65 [RAM_ID_HIGH_CHANNEL] = ram_voltages,
66 [SKU_ID_LOW_CHANNEL] = ram_voltages,
67 [SKU_ID_HIGH_CHANNEL] = lcm_voltages,
70 static uint32_t get_adc_index(unsigned int channel)
72 unsigned int value = auxadc_get_voltage_uv(channel);
73 const unsigned int *voltages;
75 if (CONFIG(BOARD_GOOGLE_STARYU_COMMON)) {
76 assert(channel < ARRAY_SIZE(adc_voltages_detachable));
77 voltages = adc_voltages_detachable[channel];
78 } else {
79 assert(channel < ARRAY_SIZE(adc_voltages));
80 voltages = adc_voltages[channel];
83 assert(voltages);
85 /* Find the closest voltage */
86 uint32_t id;
87 for (id = 0; id < ADC_LEVELS - 1; id++)
88 if (value < (voltages[id] + voltages[id + 1]) / 2)
89 break;
91 printk(BIOS_DEBUG, "ADC[%u]: Raw value=%u ID=%u\n", channel, value, id);
92 return id;
95 /* Detachables use ADC channel 5 for panel ID */
96 uint32_t panel_id(void)
98 static uint32_t cached_panel_id = BOARD_ID_INIT;
100 if (cached_panel_id == BOARD_ID_INIT)
101 cached_panel_id = get_adc_index(SKU_ID_HIGH_CHANNEL);
103 return cached_panel_id;
106 uint32_t sku_id(void)
108 static uint32_t cached_sku_code = BOARD_ID_INIT;
110 if (cached_sku_code != BOARD_ID_INIT)
111 return cached_sku_code;
113 cached_sku_code = google_chromeec_get_board_sku();
115 if (CONFIG(BOARD_GOOGLE_STARYU_COMMON)) {
116 if (cached_sku_code == CROS_SKU_UNPROVISIONED ||
117 cached_sku_code == CROS_SKU_UNKNOWN) {
118 printk(BIOS_WARNING, "SKU code from EC: %s\n",
119 (cached_sku_code == CROS_SKU_UNKNOWN) ?
120 "CROS_SKU_UNKNOWN" : "CROS_SKU_UNPROVISIONED");
121 /* Reserve last 4 bits to report PANEL_ID */
122 cached_sku_code = 0x7FFFFFF0UL | panel_id();
124 } else if (cached_sku_code == CROS_SKU_UNKNOWN) {
125 printk(BIOS_WARNING, "Failed to get SKU code from EC\n");
126 cached_sku_code = (get_adc_index(SKU_ID_HIGH_CHANNEL) << 4 |
127 get_adc_index(SKU_ID_LOW_CHANNEL));
130 printk(BIOS_DEBUG, "SKU Code: %#02x\n", cached_sku_code);
131 return cached_sku_code;
134 uint32_t ram_code(void)
136 static uint32_t cached_ram_code = BOARD_ID_INIT;
138 if (cached_ram_code == BOARD_ID_INIT) {
139 cached_ram_code = (get_adc_index(RAM_ID_HIGH_CHANNEL) << 4 |
140 get_adc_index(RAM_ID_LOW_CHANNEL));
141 printk(BIOS_DEBUG, "RAM Code: %#02x\n", cached_ram_code);
144 return cached_ram_code;