mb/google/nissa/var/rull: add ssd timing and modify ssd GPIO pins of rtd3
[coreboot2.git] / src / mainboard / google / asurada / boardid.c
blobe1b5b9eec8f4560d0e632a82791637ab695d6063
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <assert.h>
4 #include <boardid.h>
5 #include <console/console.h>
6 #include <soc/auxadc.h>
8 /* board_id is provided by ec/google/chromeec/ec_boardid.c */
10 #define ADC_LEVELS 15
12 enum {
13 /* RAM IDs */
14 RAM_ID_HIGH_CHANNEL = 4,
15 RAM_ID_LOW_CHANNEL = 3,
16 /* SKU IDs */
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) */
23 [0] = 74300,
24 [1] = 211700,
25 [2] = 318800,
26 [3] = 428600,
27 [4] = 541700,
28 [5] = 665800,
29 [6] = 781400,
30 [7] = 900000,
31 [8] = 1023100,
32 [9] = 1137000,
33 [10] = 1240000,
34 [11] = 1342600,
35 [12] = 1457500,
36 [13] = 1575600,
37 [14] = 1683600,
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];
53 assert(voltages);
55 /* Find the closest voltage */
56 uint32_t id;
57 for (id = 0; id < ADC_LEVELS - 1; id++)
58 if (value < (voltages[id] + voltages[id + 1]) / 2)
59 break;
61 printk(BIOS_DEBUG, "ADC[%u]: Raw value=%u ID=%u\n", channel, value, id);
62 return id;
65 uint32_t sku_id(void)
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;