From 490dba2a8b08b49ac7bce888a27666e9c3f8e25b Mon Sep 17 00:00:00 2001 From: Kapil Porwal Date: Fri, 30 Jan 2026 16:56:39 +0530 Subject: [PATCH] ec/google/chromeec: Implement host command to read lid state On non-LPC platforms (such as those using I2C or SPI for EC comms), the EC memory map is not directly accessible via memory-mapped I/O. Instead, these platforms must use the EC_CMD_READ_MEMMAP host command to retrieve system information. Implement google_chromeec_get_switches() using this host command for non-LPC systems. This enables get_lid_switch() to function correctly on eSPI-based and other non-LPC mainboards, allowing them to support lid-controlled logic. BUG=none TEST=Verify the LID state using get_lid_switch() on Google/Quartz. Change-Id: Ic7dbe1bcf6b528dfefc168e2f0de0357430dc84d Signed-off-by: Kapil Porwal Reviewed-on: https://review.coreboot.org/c/coreboot/+/91008 Tested-by: build bot (Jenkins) Reviewed-by: Subrata Banik Reviewed-by: Caveh Jalali Reviewed-by: Paul Menzel --- src/ec/google/chromeec/ec.c | 34 +++++++++++++++++++++++++++++++ src/ec/google/chromeec/switches.c | 2 -- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/ec/google/chromeec/ec.c b/src/ec/google/chromeec/ec.c index 804bda0c81..e6de2c9810 100644 --- a/src/ec/google/chromeec/ec.c +++ b/src/ec/google/chromeec/ec.c @@ -1992,3 +1992,37 @@ bool google_chromeec_is_critically_low_on_battery(void) return google_chromeec_is_below_critical_threshold() && !google_chromeec_is_charger_present(); } + +#if !CONFIG(EC_GOOGLE_CHROMEEC_LPC) +static int google_chromeec_read_memmap(uint8_t offset, uint8_t size, void *dest) +{ + struct ec_params_read_memmap params; + + params.offset = offset; + params.size = size; + + struct chromeec_command cmd = { + .cmd_code = EC_CMD_READ_MEMMAP, + .cmd_version = 0, + .cmd_data_in = ¶ms, + .cmd_data_out = dest, + .cmd_size_in = sizeof(params), + .cmd_size_out = size, + }; + + return google_chromeec_command(&cmd); +} + +/* + * Return the byte of EC switch states e.g. lid state + */ +uint8_t google_chromeec_get_switches(void) +{ + uint8_t flags; + + if (google_chromeec_read_memmap(EC_MEMMAP_SWITCHES, sizeof(flags), &flags)) + return 0; + + return flags; +} +#endif diff --git a/src/ec/google/chromeec/switches.c b/src/ec/google/chromeec/switches.c index e35e7722ea..066a788f71 100644 --- a/src/ec/google/chromeec/switches.c +++ b/src/ec/google/chromeec/switches.c @@ -5,7 +5,6 @@ #include #include -#if CONFIG(EC_GOOGLE_CHROMEEC_LPC) /* * Retrieves the state of the lid switch. * @@ -32,7 +31,6 @@ int get_lid_switch(void) return !!(google_chromeec_get_switches() & EC_SWITCH_LID_OPEN); } -#endif int get_recovery_mode_switch(void) {