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 <kapilporwal@google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/91008
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Subrata Banik <subratabanik@google.com>
Reviewed-by: Caveh Jalali <caveh@chromium.org>
Reviewed-by: Paul Menzel <paulepanter@mailbox.org>
This commit is contained in:
Kapil Porwal 2026-01-30 16:56:39 +05:30 committed by Subrata Banik
commit 490dba2a8b
2 changed files with 34 additions and 2 deletions

View file

@ -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 = &params,
.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

View file

@ -5,7 +5,6 @@
#include <elog.h>
#include <security/vboot/misc.h>
#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)
{