drivers/uart: Replace 'unsigned long int' by 'unsigned long'
[coreboot2.git] / src / ec / google / chromeec / switches.c
blob15f4208c32567c3f371d26618467e20e1773b7f8
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <bootmode.h>
4 #include <ec/google/chromeec/ec.h>
5 #include <elog.h>
7 #if CONFIG(EC_GOOGLE_CHROMEEC_LPC)
8 int get_lid_switch(void)
10 if (!CONFIG(VBOOT_LID_SWITCH))
11 return -1;
13 return !!(google_chromeec_get_switches() & EC_SWITCH_LID_OPEN);
15 #endif
17 int get_recovery_mode_switch(void)
19 /* Check for dedicated recovery switch first. */
20 if (CONFIG(EC_GOOGLE_CHROMEEC_LPC) &&
21 (google_chromeec_get_switches() & EC_SWITCH_DEDICATED_RECOVERY))
22 return 1;
24 /* Check if the EC has posted the keyboard recovery event. */
25 return !!(google_chromeec_get_events_b() &
26 EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY));
29 int get_recovery_mode_retrain_switch(void)
32 * Check if the EC has posted the keyboard recovery event with memory
33 * retrain.
35 return !!(google_chromeec_get_events_b() &
36 EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT));
39 static void elog_add_recovery_mode_switch_event(void)
41 uint64_t events = google_chromeec_get_events_b();
42 uint8_t event_byte = EC_HOST_EVENT_KEYBOARD_RECOVERY;
44 if (!(events & EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY)))
45 return;
47 if (events & EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT))
48 event_byte = EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT;
50 elog_add_event_byte(ELOG_TYPE_EC_EVENT, event_byte);
53 int clear_recovery_mode_switch(void)
55 /* Log elog event before clearing */
56 elog_add_recovery_mode_switch_event();
58 /* Clear all host event bits requesting recovery mode. */
59 return google_chromeec_clear_events_b(
60 EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY) |
61 EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT));