blob: 1cf26a27293e34b38358b36299600c2cc9155fcc [file] [log] [blame]
Furquan Shaikhcd2afc02016-11-15 20:33:29 -08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2016 Google Inc.
5 *
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.
9 *
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.
14 */
15
16#include <bootmode.h>
Aaron Durbin8f9a5ff2016-12-14 14:46:20 -060017#include <cbmem.h>
Furquan Shaikhcd2afc02016-11-15 20:33:29 -080018#include <ec/google/chromeec/ec.h>
19
20#if IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC_LPC)
21int get_lid_switch(void)
22{
Julius Werner58c39382017-02-13 17:53:29 -080023 if (!IS_ENABLED(CONFIG_VBOOT_LID_SWITCH))
Furquan Shaikhcd2afc02016-11-15 20:33:29 -080024 return -1;
25
26 return !!(google_chromeec_get_switches() & EC_SWITCH_LID_OPEN);
27}
28#endif
29
30int get_recovery_mode_switch(void)
31{
32 /* Check for dedicated recovery switch first. */
33 if (IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC_LPC) &&
34 (google_chromeec_get_switches() & EC_SWITCH_DEDICATED_RECOVERY))
35 return 1;
36
37 /* Check if the EC has posted the keyboard recovery/fastboot event. */
38 return !!(google_chromeec_get_events_b() &
39 (EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY) |
40 EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_FASTBOOT)));
41}
42
43int get_recovery_mode_retrain_switch(void)
44{
Furquan Shaikh8788fd62017-11-20 20:28:18 -080045 uint64_t events;
46 const uint64_t mask =
Aaron Durbin8f9a5ff2016-12-14 14:46:20 -060047 EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT);
48
Furquan Shaikhcd2afc02016-11-15 20:33:29 -080049 /*
50 * Check if the EC has posted the keyboard recovery event with memory
51 * retrain.
52 */
Aaron Durbin8f9a5ff2016-12-14 14:46:20 -060053 events = google_chromeec_get_events_b();
54
55 if (cbmem_possibly_online()) {
Furquan Shaikh8788fd62017-11-20 20:28:18 -080056 const uint64_t *events_save;
Aaron Durbin8f9a5ff2016-12-14 14:46:20 -060057
58 events_save = cbmem_find(CBMEM_ID_EC_HOSTEVENT);
59 if (events_save != NULL)
60 events |= *events_save;
61 }
62
63 return !!(events & mask);
Furquan Shaikhcd2afc02016-11-15 20:33:29 -080064}
65
66int clear_recovery_mode_switch(void)
67{
68 /* Clear all host event bits requesting recovery mode. */
69 return google_chromeec_clear_events_b(
70 EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY) |
71 EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT) |
72 EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_FASTBOOT));
73}