google/kukui: Complete board ID ADC values
[coreboot.git] / src / mainboard / google / kukui / boardid.c
blobd4b4b3e748982873515c766c3dae8b2a4c0a8897
1 /*
2 * This file is part of the coreboot project.
4 * Copyright 2018 MediaTek Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <assert.h>
17 #include <boardid.h>
18 #include <soc/auxadc.h>
19 #include <stddef.h>
21 static uint32_t get_index(unsigned int channel, uint32_t *cached_id)
23 static const int voltages[] = {
24 /* ID : Voltage (unit: uV) */
25 /* 0 : */ 74000,
26 /* 1 : */ 212000,
27 /* 2 : */ 319000,
28 /* 3 : */ 429000,
29 /* 4 : */ 542000,
30 /* 5 : */ 666000,
31 /* 6 : */ 781000,
32 /* 7 : */ 900000,
33 /* 8 : */ 1023000,
34 /* 9 : */ 1137000,
35 /* 10 : */ 1240000,
36 /* 11 : */ 1343000,
37 /* 12 : */ 1457000,
38 /* 13 : */ 1576000,
39 /* 14 : */ 1684000,
40 /* 15 : */ 1800000,
43 uint32_t id;
45 if (*cached_id != BOARD_ID_INIT)
46 return *cached_id;
48 int value = auxadc_get_voltage(channel);
49 /* Find the closest voltage */
50 for (id = 0; id < ARRAY_SIZE(voltages) - 1; id++)
51 if (value < (voltages[id] + voltages[id + 1]) / 2)
52 break;
54 const int tolerance = 10000; /* 10,000 uV */
55 assert(ABS(value - voltages[id]) < tolerance);
57 *cached_id = id;
58 return id;
61 uint32_t board_id(void)
63 static uint32_t cached_board_id = BOARD_ID_INIT;
64 return get_index(4, &cached_board_id);
67 uint32_t ram_code(void)
69 static uint32_t cached_ram_code = BOARD_ID_INIT;
70 return get_index(3, &cached_ram_code);