1 /* SPDX-License-Identifier: GPL-2.0-only */
4 #include <boot/coreboot_tables.h>
6 #include <variant/gpio.h>
8 #include <vendorcode/google/chromeos/chromeos.h>
9 #include <security/tpm/tss.h>
10 #include <device/device.h>
11 #include <intelblocks/pmclib.h>
13 #include <soc/pci_devs.h>
16 REC_MODE_UNINITIALIZED
,
17 REC_MODE_NOT_REQUESTED
,
21 void fill_lb_gpios(struct lb_gpios
*gpios
)
23 struct lb_gpio chromeos_gpios
[] = {
24 {-1, ACTIVE_HIGH
, get_lid_switch(), "lid"},
25 {-1, ACTIVE_HIGH
, 0, "power"},
26 {-1, ACTIVE_HIGH
, gfx_get_init_done(), "oprom"},
27 {-1, ACTIVE_HIGH
, 0, "EC in RW"},
29 lb_add_gpios(gpios
, chromeos_gpios
, ARRAY_SIZE(chromeos_gpios
));
32 int get_write_protect_state(void)
34 return gpio_get(GPP_E15
);
37 static bool raw_get_recovery_mode_switch(void)
39 return !gpio_get(GPP_E8
);
43 int get_recovery_mode_switch(void)
45 static enum rec_mode_state saved_rec_mode
= REC_MODE_UNINITIALIZED
;
46 enum rec_mode_state state
= REC_MODE_NOT_REQUESTED
;
47 uint8_t cr50_state
= 0;
49 /* Check cached state, since TPM will only tell us the first time */
50 if (saved_rec_mode
!= REC_MODE_UNINITIALIZED
)
51 return saved_rec_mode
== REC_MODE_REQUESTED
;
54 * Read one-time recovery request from cr50 in verstage only since
55 * the TPM driver won't be set up in time for other stages like romstage
56 * and the value from the TPM would be wrong anyway since the verstage
57 * read would have cleared the value on the TPM.
59 * The TPM recovery request is passed between stages through vboot data
60 * or cbmem depending on stage.
62 if (ENV_SEPARATE_VERSTAGE
&&
63 tlcl_cr50_get_recovery_button(&cr50_state
) == TPM_SUCCESS
&&
65 state
= REC_MODE_REQUESTED
;
67 /* Read state from the GPIO controlled by servo. */
68 if (raw_get_recovery_mode_switch())
69 state
= REC_MODE_REQUESTED
;
71 /* Store the state in case this is called again in verstage. */
72 saved_rec_mode
= state
;
74 return state
== REC_MODE_REQUESTED
;
77 int get_lid_switch(void)
82 void mainboard_prepare_cr50_reset(void)
85 /* Ensure system powers up after CR50 reset */
86 pmc_soc_set_afterg3_en(true);
90 int get_ec_is_trusted(void)
92 /* Do not have a Chrome EC involved in entering recovery mode;
93 Always return trusted. */