mb/google/skywalker: Add support for getting storage id

Add storage_id() to read the storage id from AUXADC.

BUG=b:379008996
BRANCH=none
TEST=check log on Skywalker SKU1
[DEBUG]  ADC[2]: Raw value=73782 ID=0

Signed-off-by: Vince Liu <vince-wl.liu@mediatek.corp-partner.google.com>
Change-Id: I83cb52df1f25c5106fbe213e8a0185ae764fd7dc
Reviewed-on: https://review.coreboot.org/c/coreboot/+/87921
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Yu-Ping Wu <yupingso@google.com>
Reviewed-by: Yidi Lin <yidilin@google.com>
This commit is contained in:
Vince Liu 2025-05-09 22:23:32 +08:00 committed by Yidi Lin
commit 3e6b47980a
3 changed files with 85 additions and 0 deletions

View file

@ -1,8 +1,66 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#include <assert.h>
#include <boardid.h>
#include <console/console.h>
#include <ec/google/chromeec/ec.h>
#include <soc/auxadc_common.h>
#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)
{

View file

@ -11,9 +11,11 @@
#include <soc/mt6359p.h>
#include <soc/mtcmos.h>
#include <soc/spm_common.h>
#include <soc/storage.h>
#include <soc/usb.h>
#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();

View file

@ -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