ec/google/chromeec: Override Lid State for Factory Netboot

This patch modifies the get_lid_switch() function to allow faking the
lid switch state when the GBB_FLAG_DISABLE_LID_SHUTDOWN Kconfig option
is enabled.

When GBB_FLAG_DISABLE_LID_SHUTDOWN is enabled, the function will
always return 1 (lid open), bypassing the actual lid switch state
retrieval from the Embedded Controller (EC).

This functionality is specifically designed to facilitate factory
processes, such as netboot image downloads, where devices need to
remain operational regardless of the lid's closed state. This prevents
intended shutdowns triggered by a closed lid during manufacturing and
testing.

By setting GBB_FLAG_DISABLE_LID_SHUTDOWN, we override the actual
lid status with a simulated LID status is open, which is a
prerequisite for display initialization.

w/o this patch:

```
[ALERT]  Graphics hand-off block not found
...
[INFO ]              NAME |       PORT | POLARITY |     VALUE
[INFO ]               lid |  undefined |     high |       low
```

w/ this patch:

```
[INFO ]              NAME |       PORT | POLARITY |     VALUE
[INFO ]               lid |  undefined |     high |      high
...
[INFO ]  framebuffer_info: bytes_per_line: 7680, bits_per_pixel: 32
[INFO ]    x_res x y_res: 1920 x 1200, size: 9216000 at 0xd0000000
```

BUG=b:333982806
TEST=Verified lid switch behavior with and without
`GBB_FLAG_DISABLE_LID_SHUTDOWN` enabled.

Change-Id: I89d506ab50b421b93be13b0e5e36a7ef1247e2b9
Signed-off-by: Subrata Banik <subratabanik@google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/86807
Reviewed-by: Jayvik Desai <jayvik@google.com>
Reviewed-by: Caveh Jalali <caveh@chromium.org>
Reviewed-by: Ren Kuo <ren.kuo@quanta.corp-partner.google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Subrata Banik 2025-03-11 03:58:50 +00:00
commit e6a89935e9

View file

@ -3,13 +3,33 @@
#include <bootmode.h>
#include <ec/google/chromeec/ec.h>
#include <elog.h>
#include <security/vboot/misc.h>
#if CONFIG(EC_GOOGLE_CHROMEEC_LPC)
/*
* Retrieves the state of the lid switch.
*
* The get_lid_switch() function checks if lid switch functionality is enabled
* in the coreboot configuration. If the VBOOT_LID_SWITCH Kconfig option is
* enabled, it retrieves the lid switch state from the Embedded Controller (EC).
*
* If the GBB_FLAG_DISABLE_LID_SHUTDOWN Kconfig option is enabled, this function
* will always return 1 (lid open), effectively faking the lid status. This is
* intended for stages post-romstage, particularly during display-related
* initialization, where lid-based shutdown should be suppressed.
*
* @return 1 if the lid is open, 0 if the lid is closed, or -1 if the lid switch
* functionality is not configured (VBOOT_LID_SWITCH is disabled).
*/
int get_lid_switch(void)
{
if (!CONFIG(VBOOT_LID_SWITCH))
return -1;
/* If GBB_FLAG_DISABLE_LID_SHUTDOWN is enabled, fake the lid status as always open. */
if (!ENV_ROMSTAGE_OR_BEFORE && vboot_is_gbb_flag_set(VB2_GBB_FLAG_DISABLE_LID_SHUTDOWN))
return 1; /* Always return 1 (lid open) */
return !!(google_chromeec_get_switches() & EC_SWITCH_LID_OPEN);
}
#endif