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.
18 #include <soc/auxadc.h>
21 static uint32_t get_index(unsigned int channel
, uint32_t *cached_id
)
23 static const int voltages
[] = {
24 /* ID : Voltage (unit: uV) */
45 if (*cached_id
!= BOARD_ID_INIT
)
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)
54 const int tolerance
= 10000; /* 10,000 uV */
55 assert(ABS(value
- voltages
[id
]) < tolerance
);
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
);