summaryrefslogtreecommitdiff
path: root/common/button.c
diff options
context:
space:
mode:
authorAndrew McRae <amcrae@google.com>2020-05-21 11:13:58 +1000
committerCommit Bot <commit-bot@chromium.org>2020-05-22 03:41:49 +0000
commita69d8010850bfe3860507df05d9754b38d757885 (patch)
treeb1ca385bcf1b5fcc20797d6c0685040890e52a6a /common/button.c
parent288e1a5d8ea9be1e15829067969cc786d725a4a4 (diff)
downloadchrome-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>
Diffstat (limited to 'common/button.c')
-rw-r--r--common/button.c54
1 files changed, 46 insertions, 8 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],