summaryrefslogtreecommitdiff
path: root/board/tigertail
diff options
context:
space:
mode:
authorNick Sanders <nsanders@chromium.org>2017-07-17 21:14:39 -0700
committerchrome-bot <chrome-bot@chromium.org>2017-07-21 21:24:12 -0700
commita6c34e183a70aabcef1cd4362303df475afc173e (patch)
tree441dd6918f59b2241762303a8ef8d4e79025daa4 /board/tigertail
parent3968c95e124c6a84ef57881a2058db3b754ab365 (diff)
downloadchrome-ec-a6c34e183a70aabcef1cd4362303df475afc173e.tar.gz
tigertail: support button toggle
Tigertail Rev. C has a button, we'll use it to toggle between A, B and off. BRANCH=None BUG=b:35849284 TEST=ran on tigertail w/rework, mux muxed. Signed-off-by: Nick Sanders <nsanders@chromium.org> Change-Id: I2a2a9ce0ba713c47e6f1196fac62a3804a78bf94 Reviewed-on: https://chromium-review.googlesource.com/575893 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'board/tigertail')
-rw-r--r--board/tigertail/board.c45
-rw-r--r--board/tigertail/board.h2
-rw-r--r--board/tigertail/gpio.inc4
3 files changed, 51 insertions, 0 deletions
diff --git a/board/tigertail/board.c b/board/tigertail/board.c
index 6dd2a2265c..c8f18c8315 100644
--- a/board/tigertail/board.c
+++ b/board/tigertail/board.c
@@ -312,6 +312,7 @@ static void set_led_b(int r, int g, int b)
/* State we intend the mux GPIOs to be set. */
static int mux_state = MUX_OFF;
+static int last_mux_state = MUX_OFF;
/* Set the state variable and GPIO configs to mux as requested. */
void set_mux_state(int state)
@@ -320,6 +321,9 @@ void set_mux_state(int state)
/* dir: 0 -> A, dir: 1 -> B */
int dir = (state == MUX_B);
+ if (mux_state != state)
+ last_mux_state = mux_state;
+
/* Disconnect first. */
gpio_set_level(GPIO_USB_C_OE_N, 1);
gpio_set_level(GPIO_SEL_RELAY_A, 0);
@@ -354,6 +358,45 @@ void set_mux_state(int state)
set_led_b(1, 0, 0);
}
+
+/* On button press, toggle between mux A, B, off. */
+static int button_ready = 1;
+void button_interrupt_deferred(void)
+{
+ switch (mux_state) {
+ case MUX_OFF:
+ if (last_mux_state == MUX_A)
+ set_mux_state(MUX_B);
+ else
+ set_mux_state(MUX_A);
+ break;
+
+ case MUX_A:
+ case MUX_B:
+ default:
+ set_mux_state(MUX_OFF);
+ break;
+ }
+
+ button_ready = 1;
+}
+DECLARE_DEFERRED(button_interrupt_deferred);
+
+/* On button press, toggle between mux A, B, off. */
+void button_interrupt(enum gpio_signal signal)
+{
+ if (!button_ready)
+ return;
+
+ button_ready = 0;
+ /*
+ * button_ready is not set until set_mux_state completes,
+ * which has ~100ms settle time for the mux, which also
+ * provides for debouncing.
+ */
+ hook_call_deferred(&button_interrupt_deferred_data, 0);
+}
+
static int command_mux(int argc, char **argv)
{
char *mux_state_str = "off";
@@ -406,5 +449,7 @@ static void board_init(void)
ina2xx_init(0, 0x8000, INA2XX_CALIB_1MA(15 /*mOhm*/));
ina2xx_init(1, 0x8000, INA2XX_CALIB_1MA(15 /*mOhm*/));
ina2xx_init(4, 0x8000, INA2XX_CALIB_1MA(15 /*mOhm*/));
+
+ gpio_enable_interrupt(GPIO_BUTTON_L);
}
DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
diff --git a/board/tigertail/board.h b/board/tigertail/board.h
index 1340398943..d1c55f4f64 100644
--- a/board/tigertail/board.h
+++ b/board/tigertail/board.h
@@ -132,5 +132,7 @@ enum mux_states {
MUX_B,
};
+void button_interrupt(enum gpio_signal signal);
+
#endif /* !__ASSEMBLER__ */
#endif /* __CROS_EC_BOARD_H */
diff --git a/board/tigertail/gpio.inc b/board/tigertail/gpio.inc
index de68fe1f92..8fcc46cd77 100644
--- a/board/tigertail/gpio.inc
+++ b/board/tigertail/gpio.inc
@@ -5,6 +5,10 @@
* found in the LICENSE file.
*/
+/* Interrupt enables. */
+GPIO_INT(BUTTON_L, PIN(C, 13), \
+ GPIO_INT_RISING | GPIO_PULL_UP, button_interrupt)
+
/* Outputs */
GPIO(SEL_CC2_A, PIN(A, 14), GPIO_OUT_LOW)
GPIO(SEL_VBUS_A, PIN(A, 15), GPIO_OUT_LOW)