1 /* SPDX-License-Identifier: GPL-2.0-only */
4 #include <console/console.h>
6 #include <soc/saradc.h>
8 static const int id_readings
[] = {
9 /* ID : Volts : ADC value : Bucket */
10 /* == ===== ========= ========== */
11 #if CONFIG(BOARD_GOOGLE_KEVIN)
12 /* 0 : 0.109V: 62 : 0 - 91 */ 91,
14 /* 0 : 0.074V: 42 : 0 - 81 */ 81,
16 /* 1 : 0.211V: 120 : 82 - 150 */ 150,
17 /* 2 : 0.319V: 181 : 151 - 211 */ 211,
18 /* 3 : 0.427V: 242 : 212 - 274 */ 274,
19 /* 4 : 0.542V: 307 : 275 - 342 */ 342,
20 /* 5 : 0.666V: 378 : 343 - 411 */ 411,
21 /* 6 : 0.781V: 444 : 412 - 477 */ 477,
22 /* 7 : 0.900V: 511 : 478 - 545 */ 545,
23 /* 8 : 1.023V: 581 : 546 - 613 */ 613,
24 /* 9 : 1.137V: 646 : 614 - 675 */ 675,
25 /* 10 : 1.240V: 704 : 676 - 733 */ 733,
26 /* 11 : 1.343V: 763 : 734 - 795 */ 795,
27 /* 12 : 1.457V: 828 : 796 - 861 */ 861,
28 /* 13 : 1.576V: 895 : 862 - 925 */ 925,
29 /* 14 : 1.684V: 956 : 926 - 989 */ 989,
30 /* 15 : 1.800V: 1023 : 990 - 1023 */ 1023
32 _Static_assert(ARRAY_SIZE(id_readings
) == 16, "Yo' messed up da table, bruh!");
33 static int cached_board_id
= -1;
34 static int cached_ram_id
= -1;
36 static uint32_t get_index(uint32_t channel
, int *cached_id
)
44 adc_reading
= get_saradc_value(channel
);
45 for (i
= 0; i
< ARRAY_SIZE(id_readings
); i
++) {
46 if (adc_reading
<= id_readings
[i
]) {
47 printk(BIOS_DEBUG
, "ADC reading %d, ID %d\n",
54 die("Read impossible value (> 1023) from 10-bit ADC!");
57 uint32_t board_id(void)
59 return get_index(1, &cached_board_id
);
62 uint32_t ram_code(void)
64 return get_index(0, &cached_ram_id
);
69 if (!CONFIG(GRU_BASEBOARD_SCARLET
))
70 return UNDEFINED_STRAPPING_ID
;
72 static uint32_t sku_id
= UNDEFINED_STRAPPING_ID
;
73 if (sku_id
!= UNDEFINED_STRAPPING_ID
)
76 gpio_t pins
[3] = {[2] = GPIO(3, D
, 6), [1] = GPIO(3, D
, 5),
77 [0] = GPIO(3, D
, 4)}; /* GPIO3_D4 is LSB */
79 sku_id
= gpio_pullup_base2_value(pins
, ARRAY_SIZE(pins
));