summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2017-04-20 17:44:38 -0700
committerchrome-bot <chrome-bot@chromium.org>2017-05-09 23:20:08 -0700
commit9c488952251502b5f56e4b2d5181a332a27f8639 (patch)
tree5c382faeddba47af0f9b0039c3918e85ae92c4f0
parente8982ea3cd66941e518b829a37834a534e71b3bc (diff)
downloadchrome-ec-9c488952251502b5f56e4b2d5181a332a27f8639.tar.gz
button: Allow board to define recovery buttons
This patch declares recovery_buttons array, where each board lists recovery buttons. Pressing those while the board reboots makes the system enter recovery mode. BUG=none BRANCH=none TEST=buildall Change-Id: I1f204156efbd6d2a507d67ba90f75ce857b03559 Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/486944
-rw-r--r--board/fizz/board.h1
-rw-r--r--board/poppy/board.c6
-rw-r--r--board/rowan/board.c6
-rw-r--r--common/button.c19
-rw-r--r--include/button.h6
-rw-r--r--include/config.h5
6 files changed, 37 insertions, 6 deletions
diff --git a/board/fizz/board.h b/board/fizz/board.h
index b6135b681b..450dac3b90 100644
--- a/board/fizz/board.h
+++ b/board/fizz/board.h
@@ -18,7 +18,6 @@
#define CONFIG_ADC
#define CONFIG_BOARD_VERSION
#define CONFIG_BUTTON_COUNT 2
-#define CONFIG_BUTTON_RECOVERY
#define CONFIG_CASE_CLOSED_DEBUG_EXTERNAL
#define CONFIG_DPTF
#define CONFIG_FLASH_SIZE 0x80000
diff --git a/board/poppy/board.c b/board/poppy/board.c
index 09478521d4..510f0b8489 100644
--- a/board/poppy/board.c
+++ b/board/poppy/board.c
@@ -466,6 +466,12 @@ const struct button_config buttons[CONFIG_BUTTON_COUNT] = {
GPIO_VOLUME_UP_L, 30 * MSEC, 0},
};
+const struct button_config *recovery_buttons[] = {
+ &buttons[BUTTON_VOLUME_DOWN],
+ &buttons[BUTTON_VOLUME_UP],
+};
+const int recovery_buttons_count = ARRAY_SIZE(recovery_buttons);
+
static void board_pmic_init(void)
{
if (system_jumped_to_this_image())
diff --git a/board/rowan/board.c b/board/rowan/board.c
index 340e3b36bf..4a63261b10 100644
--- a/board/rowan/board.c
+++ b/board/rowan/board.c
@@ -163,6 +163,12 @@ const struct button_config buttons[CONFIG_BUTTON_COUNT] = {
GPIO_VOLUME_UP_L, 30 * MSEC, 0},
};
+const struct button_config *recovery_buttons[] = {
+ &buttons[BUTTON_VOLUME_DOWN],
+ &buttons[BUTTON_VOLUME_UP],
+};
+const int recovery_buttons_count = ARRAY_SIZE(recovery_buttons);
+
struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_COUNT] = {
{
.port_addr = 0, /* port idx */
diff --git a/common/button.c b/common/button.c
index 531467240b..079b26acdf 100644
--- a/common/button.c
+++ b/common/button.c
@@ -85,6 +85,19 @@ static void button_blink_hw_reinit_led(void)
#endif
/*
+ * Whether recovery button (or combination of equivalent buttons) is pressed
+ */
+static int is_recovery_button_pressed(void)
+{
+ int i;
+ for (i = 0; i < recovery_buttons_count; i++) {
+ if (!raw_button_pressed(recovery_buttons[i]))
+ return 0;
+ }
+ return 1;
+}
+
+/*
* If the EC is reset and recovery is requested, then check if HW_REINIT is
* requested as well. Since the EC reset occurs after volup+voldn+power buttons
* are held down for 10 seconds, check the state of these buttons for 20 more
@@ -102,8 +115,7 @@ static void button_check_hw_reinit_required(void)
CPRINTS("Checking for HW_REINIT request");
while (!timestamp_expired(deadline, &now)) {
- if (!raw_button_pressed(&buttons[BUTTON_VOLUME_UP]) ||
- !raw_button_pressed(&buttons[BUTTON_VOLUME_DOWN]) ||
+ if (!is_recovery_button_pressed() ||
!power_button_signal_asserted()) {
CPRINTS("No HW_REINIT request");
return;
@@ -139,8 +151,7 @@ void button_init(void)
#ifdef CONFIG_BUTTON_RECOVERY
if (!system_jumped_to_this_image() &&
(system_get_reset_flags() & RESET_FLAG_RESET_PIN) &&
- raw_button_pressed(&buttons[BUTTON_VOLUME_DOWN]) &&
- raw_button_pressed(&buttons[BUTTON_VOLUME_UP])) {
+ is_recovery_button_pressed()) {
host_set_single_event(EC_HOST_EVENT_KEYBOARD_RECOVERY);
button_check_hw_reinit_required();
}
diff --git a/include/button.h b/include/button.h
index 286565fdbc..8909ba5f11 100644
--- a/include/button.h
+++ b/include/button.h
@@ -43,6 +43,12 @@ struct button_config {
extern const struct button_config buttons[];
/*
+ * Buttons used to decide whether recovery is requested or not
+ */
+extern const struct button_config *recovery_buttons[];
+extern const int recovery_buttons_count;
+
+/*
* Button initialization, called from main.
*/
void button_init(void);
diff --git a/include/config.h b/include/config.h
index 9dbb5cd015..ec962a3bdc 100644
--- a/include/config.h
+++ b/include/config.h
@@ -362,7 +362,10 @@
*/
#undef CONFIG_BUTTON_COUNT
-/* Support for entering recovery mode using volume buttons. */
+/*
+ * Support for entering recovery mode using volume buttons. You need to
+ * list the buttons in recovery_buttons.
+ */
#undef CONFIG_BUTTON_RECOVERY
/*