Furquan Shaikh | cd2afc0 | 2016-11-15 20:33:29 -0800 | [diff] [blame] | 1 | /* |
| 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 Durbin | 8f9a5ff | 2016-12-14 14:46:20 -0600 | [diff] [blame] | 17 | #include <cbmem.h> |
Furquan Shaikh | cd2afc0 | 2016-11-15 20:33:29 -0800 | [diff] [blame] | 18 | #include <ec/google/chromeec/ec.h> |
| 19 | |
| 20 | #if IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC_LPC) |
| 21 | int get_lid_switch(void) |
| 22 | { |
Julius Werner | 58c3938 | 2017-02-13 17:53:29 -0800 | [diff] [blame] | 23 | if (!IS_ENABLED(CONFIG_VBOOT_LID_SWITCH)) |
Furquan Shaikh | cd2afc0 | 2016-11-15 20:33:29 -0800 | [diff] [blame] | 24 | return -1; |
| 25 | |
| 26 | return !!(google_chromeec_get_switches() & EC_SWITCH_LID_OPEN); |
| 27 | } |
| 28 | #endif |
| 29 | |
| 30 | int 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 | |
| 43 | int get_recovery_mode_retrain_switch(void) |
| 44 | { |
Furquan Shaikh | 8788fd6 | 2017-11-20 20:28:18 -0800 | [diff] [blame] | 45 | uint64_t events; |
| 46 | const uint64_t mask = |
Aaron Durbin | 8f9a5ff | 2016-12-14 14:46:20 -0600 | [diff] [blame] | 47 | EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT); |
| 48 | |
Furquan Shaikh | cd2afc0 | 2016-11-15 20:33:29 -0800 | [diff] [blame] | 49 | /* |
| 50 | * Check if the EC has posted the keyboard recovery event with memory |
| 51 | * retrain. |
| 52 | */ |
Aaron Durbin | 8f9a5ff | 2016-12-14 14:46:20 -0600 | [diff] [blame] | 53 | events = google_chromeec_get_events_b(); |
| 54 | |
| 55 | if (cbmem_possibly_online()) { |
Furquan Shaikh | 8788fd6 | 2017-11-20 20:28:18 -0800 | [diff] [blame] | 56 | const uint64_t *events_save; |
Aaron Durbin | 8f9a5ff | 2016-12-14 14:46:20 -0600 | [diff] [blame] | 57 | |
| 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 Shaikh | cd2afc0 | 2016-11-15 20:33:29 -0800 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | int 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 | } |