tree: drop last paragraph of GPL copyright header
[coreboot.git] / src / mainboard / google / storm / chromeos.c
blob2640c6a253325e5b3d302afef9385aa5f653775b
1 /*
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.
16 #include <boardid.h>
17 #include <boot/coreboot_tables.h>
18 #include <console/console.h>
19 #include <delay.h>
20 #include <drivers/i2c/ww_ring/ww_ring.h>
21 #include <gpio.h>
22 #include <soc/cdp.h>
23 #include <soc/gsbi.h>
24 #include <string.h>
25 #include <timer.h>
26 #include <vendorcode/google/chromeos/chromeos.h>
28 #define DEV_SW 15
29 #define DEV_POL ACTIVE_LOW
30 #define REC_SW 16
31 #define REC_POL ACTIVE_LOW
32 #define WP_SW 17
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)
45 struct lb_gpio *gpio;
46 const int GPIO_COUNT = 5;
48 gpios->size = sizeof(*gpios) + (GPIO_COUNT * sizeof(struct lb_gpio));
49 gpios->count = GPIO_COUNT;
51 gpio = gpios->gpios;
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)
61 return 0;
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
71 * OS recovery.
73 * The state is read once and cached for following inquiries. The below enum
74 * lists possible states.
76 enum switch_state {
77 not_probed = -1,
78 no_req,
79 recovery_req,
80 wipeout_req
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)
94 struct stopwatch sw;
95 int sampled_value;
96 static enum switch_state saved_state = not_probed;
98 if (saved_state != not_probed)
99 return saved_state;
101 sampled_value = read_gpio(REC_SW) ^ !REC_POL;
103 if (!sampled_value) {
104 saved_state = no_req;
105 display_pattern(WWR_NORMAL_BOOT);
106 return saved_state;
109 display_pattern(WWR_RECOVERY_PUSHED);
110 printk(BIOS_INFO, "recovery button pressed\n");
112 stopwatch_init_msecs_expire(&sw, WIPEOUT_MODE_DELAY_MS);
114 do {
115 sampled_value = read_gpio(REC_SW) ^ !REC_POL;
116 if (!sampled_value)
117 break;
118 } while (!stopwatch_expired(&sw));
120 if (sampled_value) {
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);
124 do {
125 sampled_value = read_gpio(REC_SW) ^ !REC_POL;
126 if (!sampled_value)
127 break;
128 } while (!stopwatch_expired(&sw));
130 if (sampled_value) {
131 saved_state = recovery_req;
132 display_pattern(WWR_RECOVERY_REQUEST);
133 printk(BIOS_INFO, "recovery requested\n");
134 } else {
135 saved_state = wipeout_req;
137 } else {
138 saved_state = no_req;
139 display_pattern(WWR_NORMAL_BOOT);
142 return saved_state;
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;