From c3b5c8723ed6af01db333c70f810c87817e67f9f Mon Sep 17 00:00:00 2001 From: Matt DeVillier Date: Sun, 19 Oct 2025 17:26:07 -0500 Subject: [PATCH] ec/google/chromeec: Add function to determine keyboard backlight presence Add a new function google_chromeec_has_kbbacklight() to check if the EC has keyboard backlight capability. The function first tries the EC feature flag (EC_FEATURE_PWM_KEYB), falling back to a read test if unavailable. The EC command ec_cmd_pwm_get_keyboard_backlight() returns -1 if the device does not have a keyboard backlight. This function will be used in subsequent commits to guard setting the keyboard backlight at boot and the visiblity of a CFR option setting. TEST=tested hooked up to a CFR option to set the keyboard backlight at boot, with visibility controlled by backlight presence, on a range of Chromebooks with and without keyboard backlight support. Change-Id: I74daf7a63f06239d2ba3915221555af494a9340f Signed-off-by: Matt DeVillier Reviewed-on: https://review.coreboot.org/c/coreboot/+/89827 Reviewed-by: Subrata Banik Tested-by: build bot (Jenkins) --- src/ec/google/chromeec/ec.c | 25 +++++++++++++++++++++++++ src/ec/google/chromeec/ec.h | 1 + 2 files changed, 26 insertions(+) diff --git a/src/ec/google/chromeec/ec.c b/src/ec/google/chromeec/ec.c index acba0dfefb..fb8a014d0a 100644 --- a/src/ec/google/chromeec/ec.c +++ b/src/ec/google/chromeec/ec.c @@ -107,6 +107,31 @@ int google_chromeec_kbbacklight(int percent) return 0; } +bool google_chromeec_has_kbbacklight(void) +{ + /* Try the feature flag (most reliable for modern ECs) */ + int feature_check = google_chromeec_check_feature(EC_FEATURE_PWM_KEYB); + + if (feature_check > 0) { + printk(BIOS_DEBUG, "Chrome EC: Keyboard backlight detected (feature flag)\n"); + return true; + } else if (feature_check == 0) { + printk(BIOS_DEBUG, "Chrome EC: No keyboard backlight (feature flag)\n"); + return false; + } + + printk(BIOS_DEBUG, "Chrome EC: Feature flag unavailable, testing backlight read\n"); + struct ec_response_pwm_get_keyboard_backlight resp = {}; + + if (ec_cmd_pwm_get_keyboard_backlight(PLAT_EC, &resp) == 0) { + printk(BIOS_DEBUG, "Chrome EC: Keyboard backlight detected (read test)\n"); + return true; + } else { + printk(BIOS_DEBUG, "Chrome EC: No keyboard backlight (read test)\n"); + return false; + } +} + void google_chromeec_post(uint8_t postcode) { /* backlight is a percent. postcode is a uint8_t. diff --git a/src/ec/google/chromeec/ec.h b/src/ec/google/chromeec/ec.h index febef6c1ab..3c77eeb459 100644 --- a/src/ec/google/chromeec/ec.h +++ b/src/ec/google/chromeec/ec.h @@ -80,6 +80,7 @@ int google_chromeec_set_sku_id(uint32_t skuid); uint64_t google_chromeec_get_events_b(void); int google_chromeec_clear_events_b(uint64_t mask); int google_chromeec_kbbacklight(int percent); +bool google_chromeec_has_kbbacklight(void); void google_chromeec_post(uint8_t postcode); uint8_t google_chromeec_get_switches(void); bool google_chromeec_get_ap_watchdog_flag(void);