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 <matt.devillier@gmail.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/89827
Reviewed-by: Subrata Banik <subratabanik@google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Matt DeVillier 2025-10-19 17:26:07 -05:00
commit c3b5c8723e
2 changed files with 26 additions and 0 deletions

View file

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

View file

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