mb/google/brya: Create rull variant
[coreboot2.git] / src / mainboard / google / sarien / chromeos.c
blob93128b5c4459ab29489c9d0d5a496d5cf807da3b
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <bootmode.h>
4 #include <boot/coreboot_tables.h>
5 #include <gpio.h>
6 #include <variant/gpio.h>
7 #include <types.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 enum rec_mode_state {
14 REC_MODE_UNINITIALIZED,
15 REC_MODE_NOT_REQUESTED,
16 REC_MODE_REQUESTED,
19 void fill_lb_gpios(struct lb_gpios *gpios)
21 struct lb_gpio chromeos_gpios[] = {
22 {-1, ACTIVE_HIGH, get_lid_switch(), "lid"},
23 {-1, ACTIVE_HIGH, 0, "power"},
24 {-1, ACTIVE_HIGH, gfx_get_init_done(), "oprom"},
25 {-1, ACTIVE_HIGH, 0, "EC in RW"},
27 lb_add_gpios(gpios, chromeos_gpios, ARRAY_SIZE(chromeos_gpios));
30 int get_write_protect_state(void)
32 return gpio_get(GPP_E15);
35 static bool raw_get_recovery_mode_switch(void)
37 return !gpio_get(GPP_E8);
41 int get_recovery_mode_switch(void)
43 static enum rec_mode_state saved_rec_mode = REC_MODE_UNINITIALIZED;
44 enum rec_mode_state state = REC_MODE_NOT_REQUESTED;
45 uint8_t cr50_state = 0;
47 /* Check cached state, since TPM will only tell us the first time */
48 if (saved_rec_mode != REC_MODE_UNINITIALIZED)
49 return saved_rec_mode == REC_MODE_REQUESTED;
52 * Read one-time recovery request from cr50 in verstage only since
53 * the TPM driver won't be set up in time for other stages like romstage
54 * and the value from the TPM would be wrong anyway since the verstage
55 * read would have cleared the value on the TPM.
57 * The TPM recovery request is passed between stages through vboot data
58 * or cbmem depending on stage.
60 if (ENV_SEPARATE_VERSTAGE &&
61 tlcl_cr50_get_recovery_button(&cr50_state) == TPM_SUCCESS &&
62 cr50_state)
63 state = REC_MODE_REQUESTED;
65 /* Read state from the GPIO controlled by servo. */
66 if (raw_get_recovery_mode_switch())
67 state = REC_MODE_REQUESTED;
69 /* Store the state in case this is called again in verstage. */
70 saved_rec_mode = state;
72 return state == REC_MODE_REQUESTED;
75 int get_lid_switch(void)
77 return 1;
80 void mainboard_prepare_cr50_reset(void)
82 /* Ensure system powers up after CR50 reset */
83 if (ENV_RAMSTAGE)
84 pmc_soc_set_afterg3_en(true);
87 int get_ec_is_trusted(void)
89 /* Do not have a Chrome EC involved in entering recovery mode;
90 Always return trusted. */
91 return 1;