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>
26 #include <vendorcode/google/chromeos/chromeos.h>
29 #define DEV_POL ACTIVE_LOW
31 #define REC_POL ACTIVE_LOW
33 #define WP_POL ACTIVE_LOW
35 static int read_gpio(gpio_t gpio_num
)
37 gpio_tlmm_config_set(gpio_num
, GPIO_FUNC_DISABLE
,
38 GPIO_NO_PULL
, GPIO_2MA
, GPIO_DISABLE
);
39 udelay(10); /* Should be enough to settle. */
40 return gpio_get(gpio_num
);
43 void fill_lb_gpios(struct lb_gpios
*gpios
)
46 const int GPIO_COUNT
= 5;
48 gpios
->size
= sizeof(*gpios
) + (GPIO_COUNT
* sizeof(struct lb_gpio
));
49 gpios
->count
= GPIO_COUNT
;
52 fill_lb_gpio(gpio
++, DEV_SW
, ACTIVE_LOW
, "developer", read_gpio(DEV_SW
));
53 fill_lb_gpio(gpio
++, REC_SW
, ACTIVE_LOW
, "recovery", read_gpio(REC_SW
));
54 fill_lb_gpio(gpio
++, WP_SW
, ACTIVE_LOW
, "write protect", read_gpio(WP_SW
));
55 fill_lb_gpio(gpio
++, -1, ACTIVE_LOW
, "power", 1);
56 fill_lb_gpio(gpio
++, -1, ACTIVE_LOW
, "lid", 0);
59 int get_developer_mode_switch(void)
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 if (board_id() == BOARD_ID_WHIRLWIND_SP5
)
86 ww_ring_display_pattern(GSBI_ID_7
, pattern
);
89 #define WIPEOUT_MODE_DELAY_MS (8 * 1000)
90 #define RECOVERY_MODE_EXTRA_DELAY_MS (8 * 1000)
92 static enum switch_state
get_switch_state(void)
96 static enum switch_state saved_state
= not_probed
;
98 if (saved_state
!= not_probed
)
101 sampled_value
= read_gpio(REC_SW
) ^ !REC_POL
;
103 if (!sampled_value
) {
104 saved_state
= no_req
;
105 display_pattern(WWR_NORMAL_BOOT
);
109 display_pattern(WWR_RECOVERY_PUSHED
);
110 printk(BIOS_INFO
, "recovery button pressed\n");
112 stopwatch_init_msecs_expire(&sw
, WIPEOUT_MODE_DELAY_MS
);
115 sampled_value
= read_gpio(REC_SW
) ^ !REC_POL
;
118 } while (!stopwatch_expired(&sw
));
121 display_pattern(WWR_WIPEOUT_REQUEST
);
122 printk(BIOS_INFO
, "wipeout requested, checking recovery\n");
123 stopwatch_init_msecs_expire(&sw
, RECOVERY_MODE_EXTRA_DELAY_MS
);
125 sampled_value
= read_gpio(REC_SW
) ^ !REC_POL
;
128 } while (!stopwatch_expired(&sw
));
131 saved_state
= recovery_req
;
132 display_pattern(WWR_RECOVERY_REQUEST
);
133 printk(BIOS_INFO
, "recovery requested\n");
135 saved_state
= wipeout_req
;
138 saved_state
= no_req
;
139 display_pattern(WWR_NORMAL_BOOT
);
145 int get_recovery_mode_switch(void)
147 return get_switch_state() == recovery_req
;
150 int get_wipeout_mode_switch(void)
152 return get_switch_state() == wipeout_req
;
155 int get_write_protect_state(void)
157 return read_gpio(WP_SW
) ^ !WP_POL
;