coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
boardid.c
Go to the documentation of this file.
1
/* SPDX-License-Identifier: GPL-2.0-only */
2
3
#include <
assert.h
>
4
#include <
boardid.h
>
5
#include <
console/console.h
>
6
#include <soc/auxadc.h>
7
8
/* board_id is provided by ec/google/chromeec/ec_boardid.c */
9
10
#define ADC_LEVELS 15
11
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,
19
};
20
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,
38
};
39
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
,
45
};
46
47
static
uint32_t
get_adc_index
(
unsigned
int
channel)
48
{
49
unsigned
int
value
=
auxadc_get_voltage_uv
(channel);
50
51
assert
(channel <
ARRAY_SIZE
(
adc_voltages
));
52
const
unsigned
int
*voltages =
adc_voltages
[channel];
53
assert
(voltages);
54
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
;
60
61
printk
(
BIOS_DEBUG
,
"ADC[%u]: Raw value=%u ID=%u\n"
, channel,
value
,
id
);
62
return
id;
63
}
64
65
uint32_t
sku_id
(
void
)
66
{
67
static
uint32_t
cached_sku_code =
BOARD_ID_INIT
;
68
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);
73
}
74
75
return
cached_sku_code;
76
}
77
78
uint32_t
ram_code
(
void
)
79
{
80
static
uint32_t
cached_ram_code =
BOARD_ID_INIT
;
81
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);
86
}
87
88
return
cached_ram_code;
89
}
value
pte_t value
Definition:
mmu.c:91
assert.h
assert
#define assert(statement)
Definition:
assert.h:74
auxadc_get_voltage_uv
unsigned int auxadc_get_voltage_uv(unsigned int channel)
Definition:
auxadc.c:58
boardid.h
BOARD_ID_INIT
#define BOARD_ID_INIT
Definition:
boardid.h:11
ARRAY_SIZE
#define ARRAY_SIZE(a)
Definition:
helpers.h:12
printk
#define printk(level,...)
Definition:
stdlib.h:16
console.h
BIOS_DEBUG
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition:
loglevel.h:128
SKU_ID_HIGH_CHANNEL
@ SKU_ID_HIGH_CHANNEL
Definition:
boardid.c:17
SKU_ID_LOW_CHANNEL
@ SKU_ID_LOW_CHANNEL
Definition:
boardid.c:18
RAM_ID_HIGH_CHANNEL
@ RAM_ID_HIGH_CHANNEL
Definition:
boardid.c:14
RAM_ID_LOW_CHANNEL
@ RAM_ID_LOW_CHANNEL
Definition:
boardid.c:15
sku_id
uint32_t sku_id(void)
Definition:
boardid.c:65
ram_voltages
static const unsigned int ram_voltages[ADC_LEVELS]
Definition:
boardid.c:21
get_adc_index
static uint32_t get_adc_index(unsigned int channel)
Definition:
boardid.c:47
ram_code
uint32_t ram_code(void)
Definition:
boardid.c:78
adc_voltages
static const unsigned int * adc_voltages[]
Definition:
boardid.c:40
ADC_LEVELS
#define ADC_LEVELS
Definition:
boardid.c:10
uint32_t
unsigned int uint32_t
Definition:
stdint.h:14
src
mainboard
google
asurada
boardid.c
Generated by
1.9.1