From a3923d678ffe45f0f3bade4a32a62336efdd19ba Mon Sep 17 00:00:00 2001 From: Sean Rhodes Date: Mon, 16 Feb 2026 21:06:29 +0000 Subject: [PATCH] ec/starlabs/merlin: fix ITE CMOS index mapping ACPI stores trackpad_state and kbl_brightness as small indices in CMOS (per cmos.layout and RPTS/RWAK). The ITE init path treated the CMOS byte as the EC's raw encoded value, so non-default settings would fall back (e.g. trackpad disabled, kbd backlight brightness). Treat CMOS-backed values as LUT indices and fix the kbl_brightness fallback to use an index. Change-Id: Id8d320c9544c9fa73b234817717c47f1fa169c64 Signed-off-by: Sean Rhodes Reviewed-on: https://review.coreboot.org/c/coreboot/+/91301 Reviewed-by: Angel Pons Reviewed-by: Matt DeVillier Tested-by: build bot (Jenkins) --- src/ec/starlabs/merlin/ite.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/ec/starlabs/merlin/ite.c b/src/ec/starlabs/merlin/ite.c index 953c9e3de6..8ce556a308 100644 --- a/src/ec/starlabs/merlin/ite.c +++ b/src/ec/starlabs/merlin/ite.c @@ -41,15 +41,26 @@ static uint8_t get_ec_value_from_option(const char *name, uint32_t cmos_start_bit, uint32_t cmos_length) { - uint8_t value; + /* + * CMOS-backed EC options store an index (see cmos.layout and ACPI + * RPTS/RWAK mappings), while the option backend stores the EC's raw + * values (e.g. 0xaa/0xbb/0xdd). + */ + if (cmos_start_bit != UINT_MAX) { + unsigned int index = get_cmos_value(cmos_start_bit, cmos_length); - if (cmos_start_bit != UINT_MAX) - value = get_cmos_value(cmos_start_bit, cmos_length); - else - value = get_uint_option(name, fallback); + if (index >= lut_size) + index = fallback; + if (index >= lut_size) + index = 0; + + return lut[index]; + } + + const uint8_t value = get_uint_option(name, fallback); /* Check if the value exists in the LUT array */ - for (int i = 0; i < lut_size; i++) + for (size_t i = 0; i < lut_size; i++) if (lut[i] == value) return value; @@ -265,7 +276,7 @@ static void merlin_init(struct device *dev) ec_write(ECRAM_KBL_BRIGHTNESS, get_ec_value_from_option("kbl_brightness", - CONFIG(EC_STARLABS_KBL_LEVELS) ? KBL_LOW : KBL_ON, + CONFIG(EC_STARLABS_KBL_LEVELS) ? 2 : 0, kbl_brightness, ARRAY_SIZE(kbl_brightness), CMOS_VSTART_kbl_brightness,