1 /* SPDX-License-Identifier: GPL-2.0-only */
5 #include <console/console.h>
6 #include <ec/google/chromeec/ec.h>
7 #include <soc/auxadc.h>
9 /* board_id is provided by ec/google/chromeec/ec_boardid.c */
15 RAM_ID_LOW_CHANNEL
= 2,
16 RAM_ID_HIGH_CHANNEL
= 3,
18 SKU_ID_LOW_CHANNEL
= 4,
19 SKU_ID_HIGH_CHANNEL
= 5,
22 static const unsigned int ram_voltages
[ADC_LEVELS
] = {
23 /* ID : Voltage (unit: uV) */
38 static const unsigned int *adc_voltages
[] = {
39 [RAM_ID_LOW_CHANNEL
] = ram_voltages
,
40 [RAM_ID_HIGH_CHANNEL
] = ram_voltages
,
41 [SKU_ID_LOW_CHANNEL
] = ram_voltages
,
42 [SKU_ID_HIGH_CHANNEL
] = ram_voltages
,
45 static uint32_t get_adc_index(unsigned int channel
)
47 unsigned int value
= auxadc_get_voltage_uv(channel
);
49 assert(channel
< ARRAY_SIZE(adc_voltages
));
50 const unsigned int *voltages
= adc_voltages
[channel
];
53 /* Find the closest voltage */
55 for (id
= 0; id
< ADC_LEVELS
- 1; id
++)
56 if (value
< (voltages
[id
] + voltages
[id
+ 1]) / 2)
59 printk(BIOS_DEBUG
, "ADC[%u]: Raw value=%u ID=%u\n", channel
, value
, id
);
65 static uint32_t cached_sku_code
= BOARD_ID_INIT
;
67 if (cached_sku_code
== BOARD_ID_INIT
) {
68 cached_sku_code
= google_chromeec_get_board_sku();
70 if (cached_sku_code
== CROS_SKU_UNKNOWN
) {
71 printk(BIOS_WARNING
, "Failed to get SKU code from EC\n");
72 cached_sku_code
= (get_adc_index(SKU_ID_HIGH_CHANNEL
) << 4 |
73 get_adc_index(SKU_ID_LOW_CHANNEL
));
75 printk(BIOS_DEBUG
, "SKU Code: %#02x\n", cached_sku_code
);
78 return cached_sku_code
;
81 uint32_t ram_code(void)
83 static uint32_t cached_ram_code
= BOARD_ID_INIT
;
85 if (cached_ram_code
== BOARD_ID_INIT
) {
86 cached_ram_code
= (get_adc_index(RAM_ID_HIGH_CHANNEL
) << 4 |
87 get_adc_index(RAM_ID_LOW_CHANNEL
));
88 printk(BIOS_DEBUG
, "RAM Code: %#02x\n", cached_ram_code
);
91 return cached_ram_code
;