coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
chromeos.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <boardid.h>
4 #include <bootmode.h>
5 #include <boot/coreboot_tables.h>
6 #include <console/console.h>
7 #include <delay.h>
9 #include <gpio.h>
10 #include <soc/cdp.h>
11 #include <soc/gsbi.h>
12 #include <timer.h>
13 
14 #define DEV_SW 15
15 #define REC_SW 16
16 #define WP_SW 17
17 
18 static int read_gpio(gpio_t gpio_num)
19 {
22  udelay(10); /* Should be enough to settle. */
23  return gpio_get(gpio_num);
24 }
25 
26 void fill_lb_gpios(struct lb_gpios *gpios)
27 {
28  struct lb_gpio chromeos_gpios[] = {
29  {DEV_SW, ACTIVE_LOW, read_gpio(REC_SW), "presence"},
30  {-1, ACTIVE_LOW, 1, "power"},
31  {-1, ACTIVE_LOW, 0, "lid"},
32  };
33  lb_add_gpios(gpios, chromeos_gpios, ARRAY_SIZE(chromeos_gpios));
34 }
35 
36 /*
37  * The recovery switch on storm is overloaded: it needs to be pressed for a
38  * certain duration at startup to signal different requests:
39  *
40  * - keeping it pressed for 8 to 16 seconds after startup signals the need for
41  * factory reset (wipeout);
42  * - keeping it pressed for longer than 16 seconds signals the need for Chrome
43  * OS recovery.
44  *
45  * The state is read once and cached for following inquiries. The below enum
46  * lists possible states.
47  */
49  not_probed = -1,
53 };
54 
55 static void display_pattern(int pattern)
56 {
59 }
60 
61 #define WIPEOUT_MODE_DELAY_MS (8 * 1000)
62 #define RECOVERY_MODE_EXTRA_DELAY_MS (8 * 1000)
63 
64 static enum switch_state get_switch_state(void)
65 {
66  struct stopwatch sw;
67  int sampled_value;
68  static enum switch_state saved_state = not_probed;
69 
70  if (saved_state != not_probed)
71  return saved_state;
72 
73  sampled_value = !read_gpio(REC_SW);
74 
75  if (!sampled_value) {
76  saved_state = no_req;
78  return saved_state;
79  }
80 
82  printk(BIOS_INFO, "recovery button pressed\n");
83 
85 
86  do {
87  sampled_value = !read_gpio(REC_SW);
88  if (!sampled_value)
89  break;
90  } while (!stopwatch_expired(&sw));
91 
92  if (sampled_value) {
94  printk(BIOS_INFO, "wipeout requested, checking recovery\n");
96  do {
97  sampled_value = !read_gpio(REC_SW);
98  if (!sampled_value)
99  break;
100  } while (!stopwatch_expired(&sw));
101 
102  if (sampled_value) {
103  saved_state = recovery_req;
105  printk(BIOS_INFO, "recovery requested\n");
106  } else {
107  saved_state = wipeout_req;
108  }
109  } else {
110  saved_state = no_req;
112  }
113 
114  return saved_state;
115 }
116 
118 {
119  return get_switch_state() == recovery_req;
120 }
121 
123 {
124  return get_switch_state() == wipeout_req;
125 }
126 
128 {
129  return !read_gpio(WP_SW);
130 }
131 
133 {
134  /* Do not have a Chrome EC involved in entering recovery mode;
135  Always return trusted. */
136  return 1;
137 }
void fill_lb_gpios(struct lb_gpios *gpios)
Definition: chromeos.c:9
int get_write_protect_state(void)
Only used if CONFIG(CHROMEOS) is set.
Definition: chromeos.c:15
static const u32 pattern[8]
Definition: ast_post.c:428
#define ARRAY_SIZE(a)
Definition: helpers.h:12
#define printk(level,...)
Definition: stdlib.h:16
uint32_t board_id(void)
board_id() - Get the board version
Definition: ec_boardid.c:6
int get_ec_is_trusted(void)
Definition: chromeos.c:25
int get_recovery_mode_switch(void)
HACK: Use Fn-Key as recovery mode switch.
Definition: chromeos.c:29
#define ACTIVE_LOW
Definition: chromeos.c:17
switch_state
Definition: chromeos.c:76
@ no_req
Definition: chromeos.c:78
@ not_probed
Definition: chromeos.c:77
@ wipeout_req
Definition: chromeos.c:80
@ recovery_req
Definition: chromeos.c:79
int get_wipeout_mode_switch(void)
Definition: chromeos.c:151
#define REC_SW
Definition: chromeos.c:15
static int read_gpio(gpio_t gpio_num)
Definition: chromeos.c:18
static enum switch_state get_switch_state(void)
Definition: chromeos.c:64
#define WIPEOUT_MODE_DELAY_MS
Definition: chromeos.c:61
#define WP_SW
Definition: chromeos.c:16
static void display_pattern(int pattern)
Definition: chromeos.c:55
#define RECOVERY_MODE_EXTRA_DELAY_MS
Definition: chromeos.c:62
#define DEV_SW
Definition: chromeos.c:14
@ GSBI_ID_7
Definition: gsbi.h:25
void lb_add_gpios(struct lb_gpios *gpios, const struct lb_gpio *gpio_table, size_t count)
int gpio_get(gpio_t gpio)
Definition: gpio.c:166
static int stopwatch_expired(struct stopwatch *sw)
Definition: timer.h:152
static void stopwatch_init_msecs_expire(struct stopwatch *sw, long ms)
Definition: timer.h:133
@ BOARD_ID_WHIRLWIND_SP5
Definition: cdp.h:112
#define BIOS_INFO
BIOS_INFO - Expected events.
Definition: loglevel.h:113
@ GPIO_2MA
Definition: gpio_common.h:70
@ GPIO_NO_PULL
Definition: gpio_common.h:62
void gpio_tlmm_config_set(gpio_t gpio, unsigned int func, unsigned int pull, unsigned int drvstr, unsigned int enable)
Definition: gpio.c:32
#define GPIO_DISABLE
Definition: gpio.h:37
#define GPIO_FUNC_DISABLE
Definition: gpio.h:10
void udelay(uint32_t us)
Definition: udelay.c:15
int ww_ring_display_pattern(unsigned int i2c_bus, enum display_pattern pattern)
Definition: ww_ring.c:326
@ WWR_RECOVERY_REQUEST
Definition: ww_ring.h:14
@ WWR_RECOVERY_PUSHED
Definition: ww_ring.h:12
@ WWR_NORMAL_BOOT
Definition: ww_ring.h:15
@ WWR_WIPEOUT_REQUEST
Definition: ww_ring.h:13