diff --git a/src/mainboard/google/skywalker/boardid.c b/src/mainboard/google/skywalker/boardid.c index cfac4d5d4d..437f64e302 100644 --- a/src/mainboard/google/skywalker/boardid.c +++ b/src/mainboard/google/skywalker/boardid.c @@ -1,8 +1,66 @@ /* SPDX-License-Identifier: GPL-2.0-only */ +#include #include #include #include +#include + +#include "storage.h" + +#define ADC_LEVELS 8 + +enum { + /* STORAGE IDs */ + STORAGE_ID_CHANNEL = 2, +}; + +static const unsigned int storage_voltages[ADC_LEVELS] = { + /* ID : Voltage (unit: uV) */ + [0] = 74300, + [1] = 211400, + [2] = 365100, + [3] = 524300, + [4] = 706300, + [5] = 899100, + [6] = 1108900, + [7] = 1342600, +}; + +static const unsigned int *adc_voltages[] = { + [STORAGE_ID_CHANNEL] = storage_voltages, +}; + +static uint32_t get_adc_index(unsigned int channel) +{ + unsigned int value = auxadc_get_voltage_uv(channel); + const unsigned int *voltages; + + assert(channel < ARRAY_SIZE(adc_voltages)); + voltages = adc_voltages[channel]; + + assert(voltages); + + /* Find the closest voltage */ + uint32_t id; + for (id = 0; id < ADC_LEVELS - 1; id++) + if (value < (voltages[id] + voltages[id + 1]) / 2) + break; + + printk(BIOS_DEBUG, "ADC[%u]: Raw value=%u ID=%u\n", channel, value, id); + return id; +} + +uint32_t storage_id(void) +{ + static uint32_t cached_storage_id = BOARD_ID_INIT; + + if (cached_storage_id == BOARD_ID_INIT) + cached_storage_id = get_adc_index(STORAGE_ID_CHANNEL); + + printk(BIOS_DEBUG, "Storage ID: %#02x\n", cached_storage_id); + return cached_storage_id; +} uint32_t sku_id(void) { diff --git a/src/mainboard/google/skywalker/mainboard.c b/src/mainboard/google/skywalker/mainboard.c index 652d81253f..bf430bc497 100644 --- a/src/mainboard/google/skywalker/mainboard.c +++ b/src/mainboard/google/skywalker/mainboard.c @@ -11,9 +11,11 @@ #include #include #include +#include #include #include "gpio.h" +#include "storage.h" #define AFE_SE_SECURE_CON1 (AUDIO_BASE + 0x5634) @@ -65,6 +67,23 @@ static void power_on_fpmcu(void) gpio_output(GPIO_FP_RST_1V8_S3_L, 1); } +enum mtk_storage_type mainboard_get_storage_type(void) +{ + uint32_t index = storage_id(); + + switch (index) { + case 0: + return STORAGE_UFS_31; + case 1: + return STORAGE_UFS_22; + case 2: + return STORAGE_EMMC; + default: + printk(BIOS_WARNING, "unsupported storage id %u\n", index); + } + return STORAGE_UNKNOWN; +} + static void mainboard_init(struct device *dev) { dpm_init(); diff --git a/src/mainboard/google/skywalker/storage.h b/src/mainboard/google/skywalker/storage.h new file mode 100644 index 0000000000..dbdf2f3c54 --- /dev/null +++ b/src/mainboard/google/skywalker/storage.h @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0-only OR MIT */ + +#ifndef __MAINBOARD_GOOGLE_SKYWALKER_STORAGE_H__ +#define __MAINBOARD_GOOGLE_SKYWALKER_STORAGE_H__ + +uint32_t storage_id(void); + +#endif