1 /* SPDX-License-Identifier: GPL-2.0-only */
5 #include <boot/coreboot_tables.h>
6 #include <console/console.h>
8 #include <drivers/i2c/ww_ring/ww_ring.h>
16 static int get_rec_sw_gpio_pin(void)
18 uint8_t board_rev
= board_id();
21 case BOARD_ID_GALE_PROTO
:
22 case BOARD_ID_GALE_EVT
:
23 case BOARD_ID_GALE_EVT2_0
:
24 case BOARD_ID_GALE_EVT2_1
:
26 case BOARD_ID_GALE_EVT3
:
32 static int get_wp_status_gpio_pin(void)
34 uint8_t board_rev
= board_id();
36 case BOARD_ID_GALE_PROTO
:
37 case BOARD_ID_GALE_EVT
:
38 case BOARD_ID_GALE_EVT2_0
:
39 case BOARD_ID_GALE_EVT2_1
:
41 case BOARD_ID_GALE_EVT3
:
46 static int read_gpio(gpio_t gpio_num
)
48 gpio_tlmm_config_set(gpio_num
, GPIO_FUNC_DISABLE
,
49 GPIO_NO_PULL
, GPIO_2MA
, GPIO_DISABLE
);
50 udelay(10); /* Should be enough to settle. */
51 return gpio_get(gpio_num
);
54 void fill_lb_gpios(struct lb_gpios
*gpios
)
56 struct lb_gpio chromeos_gpios
[] = {
57 {PP_SW
, ACTIVE_LOW
, read_gpio(PP_SW
), "presence"},
58 {-1, ACTIVE_LOW
, 1, "power"},
59 {-1, ACTIVE_LOW
, 0, "lid"},
61 lb_add_gpios(gpios
, chromeos_gpios
, ARRAY_SIZE(chromeos_gpios
));
65 * The recovery switch on storm is overloaded: it needs to be pressed for a
66 * certain duration at startup to signal different requests:
68 * - keeping it pressed for 8 to 16 seconds after startup signals the need for
69 * factory reset (wipeout);
70 * - keeping it pressed for longer than 16 seconds signals the need for Chrome
73 * The state is read once and cached for following inquiries. The below enum
74 * lists possible states.
83 static void display_pattern(int pattern
)
85 ww_ring_display_pattern(BLSP_QUP_ID_3
, pattern
);
88 #define WIPEOUT_MODE_DELAY_MS (8 * 1000)
89 #define RECOVERY_MODE_EXTRA_DELAY_MS (8 * 1000)
91 static enum switch_state
get_switch_state(void)
96 static enum switch_state saved_state
= not_probed
;
98 if (saved_state
!= not_probed
)
101 rec_sw
= get_rec_sw_gpio_pin();
102 sampled_value
= !read_gpio(rec_sw
);
104 if (!sampled_value
) {
105 saved_state
= no_req
;
106 display_pattern(WWR_NORMAL_BOOT
);
110 display_pattern(WWR_RECOVERY_PUSHED
);
111 printk(BIOS_INFO
, "recovery button pressed\n");
113 stopwatch_init_msecs_expire(&sw
, WIPEOUT_MODE_DELAY_MS
);
116 sampled_value
= !read_gpio(rec_sw
);
119 } while (!stopwatch_expired(&sw
));
122 display_pattern(WWR_WIPEOUT_REQUEST
);
123 printk(BIOS_INFO
, "wipeout requested, checking recovery\n");
124 stopwatch_init_msecs_expire(&sw
, RECOVERY_MODE_EXTRA_DELAY_MS
);
126 sampled_value
= !read_gpio(rec_sw
);
129 } while (!stopwatch_expired(&sw
));
132 saved_state
= recovery_req
;
133 display_pattern(WWR_RECOVERY_REQUEST
);
134 printk(BIOS_INFO
, "recovery requested\n");
136 saved_state
= wipeout_req
;
139 saved_state
= no_req
;
140 display_pattern(WWR_NORMAL_BOOT
);
146 int get_recovery_mode_switch(void)
148 return get_switch_state() == recovery_req
;
151 int get_wipeout_mode_switch(void)
153 return get_switch_state() == wipeout_req
;
156 int get_write_protect_state(void)
158 return !read_gpio(get_wp_status_gpio_pin());
161 int get_ec_is_trusted(void)
163 /* Do not have a Chrome EC involved in entering recovery mode;
164 Always return trusted. */