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 <
ec/google/chromeec/ec.h
>
7
#include <soc/auxadc.h>
8
9
/* board_id is provided by ec/google/chromeec/ec_boardid.c */
10
11
#define ADC_LEVELS 12
12
13
enum
{
14
/* RAM IDs */
15
RAM_ID_LOW_CHANNEL
= 2,
16
RAM_ID_HIGH_CHANNEL
= 3,
17
/* SKU IDs */
18
SKU_ID_LOW_CHANNEL
= 4,
19
SKU_ID_HIGH_CHANNEL
= 5,
20
};
21
22
static
const
unsigned
int
ram_voltages
[
ADC_LEVELS
] = {
23
/* ID : Voltage (unit: uV) */
24
[0] = 74300,
25
[1] = 211700,
26
[2] = 318800,
27
[3] = 428600,
28
[4] = 541700,
29
[5] = 665800,
30
[6] = 781400,
31
[7] = 900000,
32
[8] = 1023100,
33
[9] = 1137000,
34
[10] = 1240000,
35
[11] = 1342600,
36
};
37
38
static
const
unsigned
int
*
adc_voltages
[] = {
39
[
RAM_ID_LOW_CHANNEL
] =
ram_voltages
,
40
[
RAM_ID_HIGH_CHANNEL
] =
ram_voltages
,
41
[
SKU_ID_LOW_CHANNEL
] =
ram_voltages
,
42
[
SKU_ID_HIGH_CHANNEL
] =
ram_voltages
,
43
};
44
45
static
uint32_t
get_adc_index
(
unsigned
int
channel)
46
{
47
unsigned
int
value
=
auxadc_get_voltage_uv
(channel);
48
49
assert
(channel <
ARRAY_SIZE
(
adc_voltages
));
50
const
unsigned
int
*voltages =
adc_voltages
[channel];
51
assert
(voltages);
52
53
/* Find the closest voltage */
54
uint32_t
id;
55
for
(
id
= 0;
id
<
ADC_LEVELS
- 1;
id
++)
56
if
(
value
< (voltages[
id
] + voltages[
id
+ 1]) / 2)
57
break
;
58
59
printk
(
BIOS_DEBUG
,
"ADC[%u]: Raw value=%u ID=%u\n"
, channel,
value
,
id
);
60
return
id;
61
}
62
63
uint32_t
sku_id
(
void
)
64
{
65
static
uint32_t
cached_sku_code =
BOARD_ID_INIT
;
66
67
if
(cached_sku_code ==
BOARD_ID_INIT
) {
68
cached_sku_code =
google_chromeec_get_board_sku
();
69
70
if
(cached_sku_code ==
CROS_SKU_UNKNOWN
) {
71
printk
(
BIOS_WARNING
,
"Failed to get SKU code from EC\n"
);
72
cached_sku_code = (
get_adc_index
(
SKU_ID_HIGH_CHANNEL
) << 4 |
73
get_adc_index
(
SKU_ID_LOW_CHANNEL
));
74
}
75
printk
(
BIOS_DEBUG
,
"SKU Code: %#02x\n"
, cached_sku_code);
76
}
77
78
return
cached_sku_code;
79
}
80
81
uint32_t
ram_code
(
void
)
82
{
83
static
uint32_t
cached_ram_code =
BOARD_ID_INIT
;
84
85
if
(cached_ram_code ==
BOARD_ID_INIT
) {
86
cached_ram_code = (
get_adc_index
(
RAM_ID_HIGH_CHANNEL
) << 4 |
87
get_adc_index
(
RAM_ID_LOW_CHANNEL
));
88
printk
(
BIOS_DEBUG
,
"RAM Code: %#02x\n"
, cached_ram_code);
89
}
90
91
return
cached_ram_code;
92
}
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
ec.h
CROS_SKU_UNKNOWN
#define CROS_SKU_UNKNOWN
Definition:
ec.h:110
google_chromeec_get_board_sku
uint32_t google_chromeec_get_board_sku(void)
Definition:
ec_skuid.c:6
BIOS_DEBUG
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition:
loglevel.h:128
BIOS_WARNING
#define BIOS_WARNING
BIOS_WARNING - Bad configuration.
Definition:
loglevel.h:86
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_code
uint32_t ram_code(void)
Definition:
boardid.c:78
ram_voltages
static const unsigned int ram_voltages[ADC_LEVELS]
Definition:
boardid.c:22
get_adc_index
static uint32_t get_adc_index(unsigned int channel)
Definition:
boardid.c:45
adc_voltages
static const unsigned int * adc_voltages[]
Definition:
boardid.c:38
ADC_LEVELS
#define ADC_LEVELS
Definition:
boardid.c:11
uint32_t
unsigned int uint32_t
Definition:
stdint.h:14
src
mainboard
google
corsola
boardid.c
Generated by
1.9.1