blob: dbdb273c1a69d23f68b22bb2182df5505218034e [file] [log] [blame]
Elyes HAOUASc4b70272020-05-13 11:42:12 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Bora Guvendik3a1a0372020-03-09 18:20:07 -07002
Furquan Shaikh76cedd22020-05-02 10:24:23 -07003#include <acpi/acpi.h>
Bora Guvendik3a1a0372020-03-09 18:20:07 -07004#include <baseboard/variants.h>
Tim Wawrzynczakd8bff382020-03-19 12:19:38 -06005#include <baseboard/gpio.h>
Kyösti Mälkkibe7692a2021-11-03 17:54:14 +02006#include <bootmode.h>
Bora Guvendik3a1a0372020-03-09 18:20:07 -07007#include <boot/coreboot_tables.h>
8#include <gpio.h>
9#include <soc/gpio.h>
10#include <variant/gpio.h>
11#include <vendorcode/google/chromeos/chromeos.h>
12#include <security/tpm/tss.h>
13#include <device/device.h>
14#include <intelblocks/pmclib.h>
15#include <soc/pmc.h>
16#include <soc/pci_devs.h>
17
Bora Guvendik3a1a0372020-03-09 18:20:07 -070018enum rec_mode_state {
19 REC_MODE_UNINITIALIZED,
20 REC_MODE_NOT_REQUESTED,
21 REC_MODE_REQUESTED,
22};
23
24void fill_lb_gpios(struct lb_gpios *gpios)
25{
26 struct lb_gpio chromeos_gpios[] = {
27 {-1, ACTIVE_HIGH, get_lid_switch(), "lid"},
28 {-1, ACTIVE_HIGH, 0, "power"},
29 {-1, ACTIVE_HIGH, gfx_get_init_done(), "oprom"},
30 {-1, ACTIVE_HIGH, 0, "EC in RW"},
31 };
32 lb_add_gpios(gpios, chromeos_gpios, ARRAY_SIZE(chromeos_gpios));
33}
34
35static int cros_get_gpio_value(int type)
36{
37 const struct cros_gpio *cros_gpios;
38 size_t i, num_gpios = 0;
39
40 cros_gpios = variant_cros_gpios(&num_gpios);
41
42 for (i = 0; i < num_gpios; i++) {
43 const struct cros_gpio *gpio = &cros_gpios[i];
44 if (gpio->type == type) {
45 int state = gpio_get(gpio->gpio_num);
46 if (gpio->polarity == CROS_GPIO_ACTIVE_LOW)
47 return !state;
48 else
49 return state;
50 }
51 }
52 return 0;
53}
54
55void mainboard_chromeos_acpi_generate(void)
56{
57 const struct cros_gpio *cros_gpios;
58 size_t num_gpios = 0;
59
60 cros_gpios = variant_cros_gpios(&num_gpios);
61
62 chromeos_acpi_gpio_generate(cros_gpios, num_gpios);
63}
64
65int get_write_protect_state(void)
66{
67 return cros_get_gpio_value(CROS_GPIO_WP);
68}
69
70int get_recovery_mode_switch(void)
71{
72 static enum rec_mode_state saved_rec_mode = REC_MODE_UNINITIALIZED;
73 enum rec_mode_state state = REC_MODE_NOT_REQUESTED;
74 uint8_t cr50_state = 0;
75
76 /* Check cached state, since TPM will only tell us the first time */
77 if (saved_rec_mode != REC_MODE_UNINITIALIZED)
78 return saved_rec_mode == REC_MODE_REQUESTED;
79
80 /*
81 * Read one-time recovery request from cr50 in verstage only since
82 * the TPM driver won't be set up in time for other stages like romstage
83 * and the value from the TPM would be wrong anyway since the verstage
84 * read would have cleared the value on the TPM.
85 *
86 * The TPM recovery request is passed between stages through vboot data
87 * or cbmem depending on stage.
88 */
Julius Werner21a40532020-04-21 16:03:53 -070089 if (ENV_SEPARATE_VERSTAGE &&
Bora Guvendik3a1a0372020-03-09 18:20:07 -070090 tlcl_cr50_get_recovery_button(&cr50_state) == TPM_SUCCESS &&
91 cr50_state)
92 state = REC_MODE_REQUESTED;
93
94 /* Read state from the GPIO controlled by servo. */
95 if (cros_get_gpio_value(CROS_GPIO_REC))
96 state = REC_MODE_REQUESTED;
97
98 /* Store the state in case this is called again in verstage. */
99 saved_rec_mode = state;
100
101 return state == REC_MODE_REQUESTED;
102}
103
104int get_lid_switch(void)
105{
106 return 1;
107}
108
109void mainboard_prepare_cr50_reset(void)
110{
111 /* Ensure system powers up after CR50 reset */
112 if (ENV_RAMSTAGE)
113 pmc_soc_set_afterg3_en(true);
114}