1 /* SPDX-License-Identifier: GPL-2.0-only */
5 #include <console/console.h>
6 #include <soc/auxadc.h>
8 /* board_id is provided by ec/google/chromeec/ec_boardid.c */
14 RAM_ID_HIGH_CHANNEL
= 4,
15 RAM_ID_LOW_CHANNEL
= 3,
17 SKU_ID_HIGH_CHANNEL
= 6,
18 SKU_ID_LOW_CHANNEL
= 5,
21 static const unsigned int ram_voltages
[ADC_LEVELS
] = {
22 /* ID : Voltage (unit: uV) */
40 static const unsigned int *adc_voltages
[] = {
41 [RAM_ID_HIGH_CHANNEL
] = ram_voltages
,
42 [RAM_ID_LOW_CHANNEL
] = ram_voltages
,
43 [SKU_ID_HIGH_CHANNEL
] = ram_voltages
,
44 [SKU_ID_LOW_CHANNEL
] = ram_voltages
,
47 static uint32_t get_adc_index(unsigned int channel
)
49 unsigned int value
= auxadc_get_voltage_uv(channel
);
51 assert(channel
< ARRAY_SIZE(adc_voltages
));
52 const unsigned int *voltages
= adc_voltages
[channel
];
55 /* Find the closest voltage */
57 for (id
= 0; id
< ADC_LEVELS
- 1; id
++)
58 if (value
< (voltages
[id
] + voltages
[id
+ 1]) / 2)
61 printk(BIOS_DEBUG
, "ADC[%u]: Raw value=%u ID=%u\n", channel
, value
, id
);
67 static uint32_t cached_sku_code
= BOARD_ID_INIT
;
69 if (cached_sku_code
== BOARD_ID_INIT
) {
70 cached_sku_code
= (get_adc_index(SKU_ID_HIGH_CHANNEL
) << 4 |
71 get_adc_index(SKU_ID_LOW_CHANNEL
));
72 printk(BIOS_DEBUG
, "SKU Code: %#02x\n", cached_sku_code
);
75 return cached_sku_code
;
78 uint32_t ram_code(void)
80 static uint32_t cached_ram_code
= BOARD_ID_INIT
;
82 if (cached_ram_code
== BOARD_ID_INIT
) {
83 cached_ram_code
= (get_adc_index(RAM_ID_HIGH_CHANNEL
) << 4 |
84 get_adc_index(RAM_ID_LOW_CHANNEL
));
85 printk(BIOS_DEBUG
, "RAM Code: %#02x\n", cached_ram_code
);
88 return cached_ram_code
;