2 * This file is part of the coreboot project.
4 * Copyright 2014 Google Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
17 #include <boot/coreboot_tables.h>
18 #include <console/console.h>
20 #include <drivers/i2c/ww_ring/ww_ring.h>
25 #include <vendorcode/google/chromeos/chromeos.h>
29 static int get_rec_sw_gpio_pin(void)
31 uint8_t board_rev
= board_id();
34 case BOARD_ID_GALE_PROTO
:
35 case BOARD_ID_GALE_EVT
:
36 case BOARD_ID_GALE_EVT2_0
:
37 case BOARD_ID_GALE_EVT2_1
:
39 case BOARD_ID_GALE_EVT3
:
45 static int get_wp_status_gpio_pin(void)
47 uint8_t board_rev
= board_id();
49 case BOARD_ID_GALE_PROTO
:
50 case BOARD_ID_GALE_EVT
:
51 case BOARD_ID_GALE_EVT2_0
:
52 case BOARD_ID_GALE_EVT2_1
:
54 case BOARD_ID_GALE_EVT3
:
59 static int read_gpio(gpio_t gpio_num
)
61 gpio_tlmm_config_set(gpio_num
, GPIO_FUNC_DISABLE
,
62 GPIO_NO_PULL
, GPIO_2MA
, GPIO_DISABLE
);
63 udelay(10); /* Should be enough to settle. */
64 return gpio_get(gpio_num
);
67 void fill_lb_gpios(struct lb_gpios
*gpios
)
69 struct lb_gpio chromeos_gpios
[] = {
70 {PP_SW
, ACTIVE_LOW
, read_gpio(PP_SW
), "presence"},
71 {get_wp_status_gpio_pin(), ACTIVE_LOW
,
72 !get_write_protect_state(), "write protect"},
73 {-1, ACTIVE_LOW
, 1, "power"},
74 {-1, ACTIVE_LOW
, 0, "lid"},
76 lb_add_gpios(gpios
, chromeos_gpios
, ARRAY_SIZE(chromeos_gpios
));
80 * The recovery switch on storm is overloaded: it needs to be pressed for a
81 * certain duration at startup to signal different requests:
83 * - keeping it pressed for 8 to 16 seconds after startup signals the need for
84 * factory reset (wipeout);
85 * - keeping it pressed for longer than 16 seconds signals the need for Chrome
88 * The state is read once and cached for following inquiries. The below enum
89 * lists possible states.
98 static void display_pattern(int pattern
)
100 ww_ring_display_pattern(BLSP_QUP_ID_3
, pattern
);
103 #define WIPEOUT_MODE_DELAY_MS (8 * 1000)
104 #define RECOVERY_MODE_EXTRA_DELAY_MS (8 * 1000)
106 static enum switch_state
get_switch_state(void)
111 static enum switch_state saved_state
= not_probed
;
113 if (saved_state
!= not_probed
)
116 rec_sw
= get_rec_sw_gpio_pin();
117 sampled_value
= !read_gpio(rec_sw
);
119 if (!sampled_value
) {
120 saved_state
= no_req
;
121 display_pattern(WWR_NORMAL_BOOT
);
125 display_pattern(WWR_RECOVERY_PUSHED
);
126 printk(BIOS_INFO
, "recovery button pressed\n");
128 stopwatch_init_msecs_expire(&sw
, WIPEOUT_MODE_DELAY_MS
);
131 sampled_value
= !read_gpio(rec_sw
);
134 } while (!stopwatch_expired(&sw
));
137 display_pattern(WWR_WIPEOUT_REQUEST
);
138 printk(BIOS_INFO
, "wipeout requested, checking recovery\n");
139 stopwatch_init_msecs_expire(&sw
, RECOVERY_MODE_EXTRA_DELAY_MS
);
141 sampled_value
= !read_gpio(rec_sw
);
144 } while (!stopwatch_expired(&sw
));
147 saved_state
= recovery_req
;
148 display_pattern(WWR_RECOVERY_REQUEST
);
149 printk(BIOS_INFO
, "recovery requested\n");
151 saved_state
= wipeout_req
;
154 saved_state
= no_req
;
155 display_pattern(WWR_NORMAL_BOOT
);
161 int get_recovery_mode_switch(void)
163 return get_switch_state() == recovery_req
;
166 int get_wipeout_mode_switch(void)
168 return get_switch_state() == wipeout_req
;
171 int get_write_protect_state(void)
173 return !read_gpio(get_wp_status_gpio_pin());