mb/google/hatch/var/dratini: Update DPTF parameters
[coreboot.git] / src / mainboard / google / gale / chromeos.c
blobd0bdbb0940096e939ca7f398a9ab7be8f1ab49aa
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/blsp.h>
24 #include <timer.h>
25 #include <vendorcode/google/chromeos/chromeos.h>
27 #define PP_SW 41
29 static int get_rec_sw_gpio_pin(void)
31 uint8_t board_rev = board_id();
33 switch (board_rev) {
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:
38 return 7;
39 case BOARD_ID_GALE_EVT3:
40 default:
41 return 57;
45 static int get_wp_status_gpio_pin(void)
47 uint8_t board_rev = board_id();
48 switch (board_rev) {
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:
53 return 6;
54 case BOARD_ID_GALE_EVT3:
55 default:
56 return 53;
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
86 * OS recovery.
88 * The state is read once and cached for following inquiries. The below enum
89 * lists possible states.
91 enum switch_state {
92 not_probed = -1,
93 no_req,
94 recovery_req,
95 wipeout_req
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)
108 struct stopwatch sw;
109 int sampled_value;
110 uint8_t rec_sw;
111 static enum switch_state saved_state = not_probed;
113 if (saved_state != not_probed)
114 return saved_state;
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);
122 return saved_state;
125 display_pattern(WWR_RECOVERY_PUSHED);
126 printk(BIOS_INFO, "recovery button pressed\n");
128 stopwatch_init_msecs_expire(&sw, WIPEOUT_MODE_DELAY_MS);
130 do {
131 sampled_value = !read_gpio(rec_sw);
132 if (!sampled_value)
133 break;
134 } while (!stopwatch_expired(&sw));
136 if (sampled_value) {
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);
140 do {
141 sampled_value = !read_gpio(rec_sw);
142 if (!sampled_value)
143 break;
144 } while (!stopwatch_expired(&sw));
146 if (sampled_value) {
147 saved_state = recovery_req;
148 display_pattern(WWR_RECOVERY_REQUEST);
149 printk(BIOS_INFO, "recovery requested\n");
150 } else {
151 saved_state = wipeout_req;
153 } else {
154 saved_state = no_req;
155 display_pattern(WWR_NORMAL_BOOT);
158 return saved_state;
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());