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/blsp.h>
12 #include <timer.h>
13 
14 #define PP_SW 41
15 
16 static int get_rec_sw_gpio_pin(void)
17 {
18  uint8_t board_rev = board_id();
19 
20  switch (board_rev) {
22  case BOARD_ID_GALE_EVT:
25  return 7;
26  case BOARD_ID_GALE_EVT3:
27  default:
28  return 57;
29  }
30 }
31 
32 static int get_wp_status_gpio_pin(void)
33 {
34  uint8_t board_rev = board_id();
35  switch (board_rev) {
37  case BOARD_ID_GALE_EVT:
40  return 6;
41  case BOARD_ID_GALE_EVT3:
42  default:
43  return 53;
44  }
45 }
46 static int read_gpio(gpio_t gpio_num)
47 {
50  udelay(10); /* Should be enough to settle. */
51  return gpio_get(gpio_num);
52 }
53 
54 void fill_lb_gpios(struct lb_gpios *gpios)
55 {
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"},
60  };
61  lb_add_gpios(gpios, chromeos_gpios, ARRAY_SIZE(chromeos_gpios));
62 }
63 
64 /*
65  * The recovery switch on storm is overloaded: it needs to be pressed for a
66  * certain duration at startup to signal different requests:
67  *
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
71  * OS recovery.
72  *
73  * The state is read once and cached for following inquiries. The below enum
74  * lists possible states.
75  */
77  not_probed = -1,
81 };
82 
83 static void display_pattern(int pattern)
84 {
86 }
87 
88 #define WIPEOUT_MODE_DELAY_MS (8 * 1000)
89 #define RECOVERY_MODE_EXTRA_DELAY_MS (8 * 1000)
90 
91 static enum switch_state get_switch_state(void)
92 {
93  struct stopwatch sw;
94  int sampled_value;
95  uint8_t rec_sw;
96  static enum switch_state saved_state = not_probed;
97 
98  if (saved_state != not_probed)
99  return saved_state;
100 
101  rec_sw = get_rec_sw_gpio_pin();
102  sampled_value = !read_gpio(rec_sw);
103 
104  if (!sampled_value) {
105  saved_state = no_req;
107  return saved_state;
108  }
109 
111  printk(BIOS_INFO, "recovery button pressed\n");
112 
114 
115  do {
116  sampled_value = !read_gpio(rec_sw);
117  if (!sampled_value)
118  break;
119  } while (!stopwatch_expired(&sw));
120 
121  if (sampled_value) {
123  printk(BIOS_INFO, "wipeout requested, checking recovery\n");
125  do {
126  sampled_value = !read_gpio(rec_sw);
127  if (!sampled_value)
128  break;
129  } while (!stopwatch_expired(&sw));
130 
131  if (sampled_value) {
132  saved_state = recovery_req;
134  printk(BIOS_INFO, "recovery requested\n");
135  } else {
136  saved_state = wipeout_req;
137  }
138  } else {
139  saved_state = no_req;
141  }
142 
143  return saved_state;
144 }
145 
147 {
148  return get_switch_state() == recovery_req;
149 }
150 
152 {
153  return get_switch_state() == wipeout_req;
154 }
155 
157 {
159 }
160 
162 {
163  /* Do not have a Chrome EC involved in entering recovery mode;
164  Always return trusted. */
165  return 1;
166 }
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
#define PP_SW
Definition: chromeos.c:14
static int read_gpio(gpio_t gpio_num)
Definition: chromeos.c:46
static enum switch_state get_switch_state(void)
Definition: chromeos.c:91
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
#define WIPEOUT_MODE_DELAY_MS
Definition: chromeos.c:88
static void display_pattern(int pattern)
Definition: chromeos.c:83
static int get_rec_sw_gpio_pin(void)
Definition: chromeos.c:16
#define RECOVERY_MODE_EXTRA_DELAY_MS
Definition: chromeos.c:89
int get_wipeout_mode_switch(void)
Definition: chromeos.c:151
static int get_wp_status_gpio_pin(void)
Definition: chromeos.c:32
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
@ BLSP_QUP_ID_3
Definition: blsp.h:10
@ BOARD_ID_GALE_EVT3
Definition: cdp.h:113
@ BOARD_ID_GALE_EVT2_0
Definition: cdp.h:111
@ BOARD_ID_GALE_PROTO
Definition: cdp.h:109
@ BOARD_ID_GALE_EVT2_1
Definition: cdp.h:112
@ BOARD_ID_GALE_EVT
Definition: cdp.h:110
#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
unsigned char uint8_t
Definition: stdint.h:8
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