diff options
author | Andrew McRae <amcrae@google.com> | 2020-05-21 11:13:58 +1000 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-05-22 03:41:49 +0000 |
commit | a69d8010850bfe3860507df05d9754b38d757885 (patch) | |
tree | b1ca385bcf1b5fcc20797d6c0685040890e52a6a | |
parent | 288e1a5d8ea9be1e15829067969cc786d725a4a4 (diff) | |
download | chrome-ec-a69d8010850bfe3860507df05d9754b38d757885.tar.gz |
config.h: Add CONFIG_DEDICATED_RECOVERY_BUTTON_2
Puff has a second dedicated recovery button input, so
expand the common recovery button handler to include
a second recovery button signal. The signals are treated
as an OR, so that either signal will indicate recovery.
The reason a second input is required is that the signal from
the H1 for recovery is masked off if the power button is pressed,
so that recovery mode of pressing both power and recovery is not
possible.
BUG=b:157181336
TEST=Patched into puff, verified recovery mode.
BRANCH=none
Signed-off-by: Andrew McRae <amcrae@google.com>
Change-Id: I476b2e8b1f5ec0f91f39e9a568dac4f15a45438f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2208342
Commit-Queue: Andrew McRae <amcrae@chromium.org>
Tested-by: Andrew McRae <amcrae@chromium.org>
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
-rw-r--r-- | common/button.c | 54 | ||||
-rw-r--r-- | include/button.h | 17 | ||||
-rw-r--r-- | include/config.h | 3 |
3 files changed, 65 insertions, 9 deletions
diff --git a/common/button.c b/common/button.c index b800302d32..14c63e1ff7 100644 --- a/common/button.c +++ b/common/button.c @@ -70,12 +70,15 @@ static int simulated_button_pressed(const struct button_config *button) */ static int raw_button_pressed(const struct button_config *button) { - int physical_value = (!!gpio_get_level(button->gpio) == - !!(button->flags & BUTTON_FLAG_ACTIVE_HIGH)); + int physical_value = 0; int simulated_value = 0; + if (!(button->flags & BUTTON_FLAG_DISABLED)) { + physical_value = (!!gpio_get_level(button->gpio) == + !!(button->flags & BUTTON_FLAG_ACTIVE_HIGH)); #ifdef CONFIG_SIMULATED_BUTTON - simulated_value = simulated_button_pressed(button); + simulated_value = simulated_button_pressed(button); #endif + } return (simulated_value || physical_value); } @@ -107,15 +110,23 @@ static void button_blink_hw_reinit_led(void) /* * Whether recovery button (or combination of equivalent buttons) is pressed + * If a dedicated recovery button is used, any of the buttons can be pressed, + * otherwise, all the buttons must be pressed. */ static int is_recovery_button_pressed(void) { - int i; + int i, pressed; for (i = 0; i < recovery_buttons_count; i++) { - if (!raw_button_pressed(recovery_buttons[i])) - return 0; + pressed = raw_button_pressed(recovery_buttons[i]); + if (IS_ENABLED(CONFIG_DEDICATED_RECOVERY_BUTTON)) { + if (pressed) + return 1; + } else { + if (!pressed) + return 0; + } } - return 1; + return IS_ENABLED(CONFIG_DEDICATED_RECOVERY_BUTTON) ? 0 : 1; } /* @@ -227,6 +238,19 @@ int button_reassign_gpio(enum button button_type, enum gpio_signal gpio) return EC_SUCCESS; } + +int button_disable_gpio(enum button button_type) +{ + if (button_type >= BUTTON_COUNT) + return EC_ERROR_INVAL; + + /* Disable GPIO interrupt */ + gpio_disable_interrupt(buttons[button_type].gpio); + /* Mark button as disabled */ + buttons[button_type].flags |= BUTTON_FLAG_DISABLED; + + return EC_SUCCESS; +} #endif @@ -307,7 +331,8 @@ void button_interrupt(enum gpio_signal signal) uint64_t time_now = get_time().val; for (i = 0; i < BUTTON_COUNT; i++) { - if (buttons[i].gpio != signal) + if (buttons[i].gpio != signal || + (buttons[i].flags & BUTTON_FLAG_DISABLED)) continue; state[i].debounce_time = time_now + buttons[i].debounce_us; @@ -816,7 +841,16 @@ struct button_config buttons[BUTTON_COUNT] = { .gpio = GPIO_RECOVERY_L, .debounce_us = BUTTON_DEBOUNCE_US, .flags = 0, + }, +#ifdef CONFIG_DEDICATED_RECOVERY_BUTTON_2 + [BUTTON_RECOVERY_2] = { + .name = "Recovery2", + .type = KEYBOARD_BUTTON_RECOVERY, + .gpio = GPIO_RECOVERY_L_2, + .debounce_us = BUTTON_DEBOUNCE_US, + .flags = 0, } +#endif /* defined(CONFIG_DEDICATED_RECOVERY_BUTTON_2) */ #endif /* defined(CONFIG_DEDICATED_RECOVERY_BUTTON) */ }; @@ -825,6 +859,10 @@ const struct button_config *recovery_buttons[] = { #ifdef CONFIG_DEDICATED_RECOVERY_BUTTON &buttons[BUTTON_RECOVERY], +#ifdef CONFIG_DEDICATED_RECOVERY_BUTTON_2 + &buttons[BUTTON_RECOVERY_2], +#endif /* defined(CONFIG_BUTTON_TRIGGERED_RECOVERY_2) */ + #elif defined(CONFIG_VOLUME_BUTTONS) &buttons[BUTTON_VOLUME_DOWN], &buttons[BUTTON_VOLUME_UP], diff --git a/include/button.h b/include/button.h index bbe4cb44df..381e650550 100644 --- a/include/button.h +++ b/include/button.h @@ -13,7 +13,9 @@ #include "gpio.h" #include "ec_commands.h" -#define BUTTON_FLAG_ACTIVE_HIGH BIT(0) +#define BUTTON_FLAG_ACTIVE_HIGH BIT(0) +#define BUTTON_FLAG_DISABLED BIT(1) /* Button disabled */ + #define BUTTON_DEBOUNCE_US (30 * MSEC) @@ -32,6 +34,9 @@ enum button { #endif /* defined(CONFIG_VOLUME_BUTTONS) */ #ifdef CONFIG_DEDICATED_RECOVERY_BUTTON BUTTON_RECOVERY, +#ifdef CONFIG_DEDICATED_RECOVERY_BUTTON_2 + BUTTON_RECOVERY_2, +#endif /* defined(CONFIG_DEDICATED_RECOVERY_BUTTON_2) */ #endif /* defined(CONFIG_DEDICATED_RECOVERY_BUTTON) */ BUTTON_COUNT, }; @@ -66,6 +71,16 @@ void button_init(void); int button_reassign_gpio(enum button button_type, enum gpio_signal gpio); /* + * Disable a button GPIO signal at runtime. + * + * @param button_type Button type to reassign + * + * Returns EC_SUCCESS if the button is disabled, + * EC_ERROR_* otherwise. + */ +int button_disable_gpio(enum button button_type); + +/* * Interrupt handler for button. * * @param signal Signal which triggered the interrupt. diff --git a/include/config.h b/include/config.h index 0676d173ca..87d36b39c2 100644 --- a/include/config.h +++ b/include/config.h @@ -715,8 +715,11 @@ * volume buttons, a dedicated recovery button is not needed. This is intended * because if a board has volume buttons, they can do everything a dedicated * recovery button can do. + * For various reasons, on some platforms there may be multiple recovery inputs. + * See b/149967026. */ #undef CONFIG_DEDICATED_RECOVERY_BUTTON +#undef CONFIG_DEDICATED_RECOVERY_BUTTON_2 /* * The board has volume up and volume down buttons. Note, these are *buttons* |