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>
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 */
17  /* SKU IDs */
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[] = {
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 
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 |
74  }
75  printk(BIOS_DEBUG, "SKU Code: %#02x\n", cached_sku_code);
76  }
77 
78  return cached_sku_code;
79 }
80 
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 |
88  printk(BIOS_DEBUG, "RAM Code: %#02x\n", cached_ram_code);
89  }
90 
91  return cached_ram_code;
92 }
pte_t value
Definition: mmu.c:91
#define assert(statement)
Definition: assert.h:74
unsigned int auxadc_get_voltage_uv(unsigned int channel)
Definition: auxadc.c:58
#define BOARD_ID_INIT
Definition: boardid.h:11
#define ARRAY_SIZE(a)
Definition: helpers.h:12
#define printk(level,...)
Definition: stdlib.h:16
#define CROS_SKU_UNKNOWN
Definition: ec.h:110
uint32_t google_chromeec_get_board_sku(void)
Definition: ec_skuid.c:6
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define BIOS_WARNING
BIOS_WARNING - Bad configuration.
Definition: loglevel.h:86
@ SKU_ID_HIGH_CHANNEL
Definition: boardid.c:17
@ SKU_ID_LOW_CHANNEL
Definition: boardid.c:18
@ RAM_ID_HIGH_CHANNEL
Definition: boardid.c:14
@ RAM_ID_LOW_CHANNEL
Definition: boardid.c:15
uint32_t sku_id(void)
Definition: boardid.c:65
uint32_t ram_code(void)
Definition: boardid.c:78
static const unsigned int ram_voltages[ADC_LEVELS]
Definition: boardid.c:22
static uint32_t get_adc_index(unsigned int channel)
Definition: boardid.c:45
static const unsigned int * adc_voltages[]
Definition: boardid.c:38
#define ADC_LEVELS
Definition: boardid.c:11
unsigned int uint32_t
Definition: stdint.h:14