drivers/mipi: Add support for KD_KD110N11_51IE panel
[coreboot2.git] / src / mainboard / google / cherry / boardid.c
blob96031ef40839e249cdcfef18a15c87dc78490b89
1 /* SPDX-License-Identifier: GPL-2.0-only */
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>
9 /* board_id is provided by ec/google/chromeec/ec_boardid.c */
11 #define ADC_LEVELS 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,
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,
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,
45 static uint32_t get_adc_index(unsigned int channel)
47 unsigned int value = auxadc_get_voltage_uv(channel);
49 assert(channel < ARRAY_SIZE(adc_voltages));
50 const unsigned int *voltages = adc_voltages[channel];
51 assert(voltages);
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;
59 printk(BIOS_DEBUG, "ADC[%u]: Raw value=%u ID=%u\n", channel, value, id);
60 return id;
63 uint32_t sku_id(void)
65 static uint32_t cached_sku_code = BOARD_ID_INIT;
67 if (cached_sku_code == BOARD_ID_INIT) {
68 cached_sku_code = google_chromeec_get_board_sku();
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));
75 printk(BIOS_DEBUG, "SKU Code: %#02x\n", cached_sku_code);
78 return cached_sku_code;
81 uint32_t ram_code(void)
83 static uint32_t cached_ram_code = BOARD_ID_INIT;
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);
91 return cached_ram_code;