summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--board/samus/board.c5
-rw-r--r--board/samus/board.h3
-rw-r--r--common/build.mk1
-rw-r--r--common/capsense.c86
-rw-r--r--common/keyboard_8042.c6
-rw-r--r--include/button.h8
-rw-r--r--include/capsense.h14
-rw-r--r--include/config.h5
8 files changed, 123 insertions, 5 deletions
diff --git a/board/samus/board.c b/board/samus/board.c
index de32c21c7f..c0a1325a45 100644
--- a/board/samus/board.c
+++ b/board/samus/board.c
@@ -8,6 +8,7 @@
#include "adc.h"
#include "adc_chip.h"
#include "backlight.h"
+#include "capsense.h"
#include "common.h"
#include "driver/temp_sensor/tmp006.h"
#include "driver/als_isl29035.h"
@@ -64,6 +65,8 @@ const struct gpio_info gpio_list[] = {
switch_interrupt},
{"PCH_BL_EN", LM4_GPIO_M, (1<<3), GPIO_INT_RISING,
backlight_interrupt},
+ {"CAPSENSE_INT_L", LM4_GPIO_N, (1<<0), GPIO_INT_FALLING,
+ capsense_interrupt},
/* Other inputs */
{"BOARD_VERSION1", LM4_GPIO_Q, (1<<5), GPIO_INPUT, NULL},
@@ -76,8 +79,6 @@ const struct gpio_info gpio_list[] = {
{"USB1_STATUS_L", LM4_GPIO_E, (1<<6), GPIO_INPUT, NULL},
{"USB2_OC_L", LM4_GPIO_E, (1<<0), GPIO_INPUT, NULL},
{"USB2_STATUS_L", LM4_GPIO_D, (1<<7), GPIO_INPUT, NULL},
- /* Not yet sure if this will need to be handled as an interrupt */
- {"CAPSENSE_INT_L", LM4_GPIO_N, (1<<0), GPIO_INPUT, NULL},
/* Outputs; all unasserted by default except for reset signals */
{"CPU_PROCHOT", LM4_GPIO_B, (1<<1), GPIO_OUT_LOW, NULL},
diff --git a/board/samus/board.h b/board/samus/board.h
index dc90f3b0cd..b892bd8d7c 100644
--- a/board/samus/board.h
+++ b/board/samus/board.h
@@ -18,6 +18,7 @@
#define CONFIG_ALS
#define CONFIG_ALS_ISL29035
#define CONFIG_BOARD_VERSION
+#define CONFIG_CAPSENSE
#define CONFIG_POWER_COMMON
#define CONFIG_CHIPSET_CAN_THROTTLE
#define CONFIG_KEYBOARD_BOARD_CONFIG
@@ -92,6 +93,7 @@ enum gpio_signal {
GPIO_RECOVERY_L, /* Recovery signal from servo */
GPIO_WP_L, /* Write protect input */
GPIO_PCH_BL_EN, /* PCH backlight input */
+ GPIO_CAPSENSE_INT_L, /* Capsense interrupt */
/* Other inputs */
GPIO_BOARD_VERSION1, /* Board version stuffing resistor 1 */
@@ -104,7 +106,6 @@ enum gpio_signal {
GPIO_USB1_STATUS_L, /* USB charger port 1 status output */
GPIO_USB2_OC_L, /* USB port overcurrent warning */
GPIO_USB2_STATUS_L, /* USB charger port 2 status output */
- GPIO_CAPSENSE_INT_L, /* Capsense interrupt (through EC_WAKE_L) */
/* Outputs */
GPIO_CPU_PROCHOT, /* Force CPU to think it's overheated */
diff --git a/common/build.mk b/common/build.mk
index dd1b592828..ea2546dbe9 100644
--- a/common/build.mk
+++ b/common/build.mk
@@ -21,6 +21,7 @@ common-$(CONFIG_BACKLIGHT_LID)+=backlight_lid.o
common-$(CONFIG_BATTERY_BQ27541)+=battery.o
common-$(CONFIG_BATTERY_SMART)+=battery.o
common-$(CONFIG_BUTTON_COUNT)+=button.o
+common-$(CONFIG_CAPSENSE)+=capsense.o
common-$(CONFIG_CHARGER)+=charge_state.o charger.o
# TODO(crosbug.com/p/23815): This is really the charge state machine
# for ARM, not the charger driver for the tps65090. Rename.
diff --git a/common/capsense.c b/common/capsense.c
new file mode 100644
index 0000000000..e0df749933
--- /dev/null
+++ b/common/capsense.c
@@ -0,0 +1,86 @@
+/* Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "common.h"
+#include "console.h"
+#include "gpio.h"
+#include "hooks.h"
+#include "i2c.h"
+#include "keyboard_protocol.h"
+#include "timer.h"
+
+/* Console output macro */
+#define CPRINTF(format, args...) cprintf(CC_KEYBOARD, format, ## args)
+
+#define CAPSENSE_I2C_ADDR 0x08
+#define CAPSENSE_MASK_BITS 8
+#define CAPSENSE_POLL_INTERVAL (20 * MSEC)
+
+static int capsense_read_bitmask(void)
+{
+ int rv;
+ uint8_t val = 0;
+
+ i2c_lock(I2C_PORT_CAPSENSE, 1);
+ rv = i2c_xfer(I2C_PORT_CAPSENSE, CAPSENSE_I2C_ADDR,
+ 0, 0, &val, 1, I2C_XFER_SINGLE);
+ i2c_lock(I2C_PORT_CAPSENSE, 0);
+
+ if (rv)
+ CPRINTF("[%T %s failed: error %d]\n", __func__, rv);
+
+ return val;
+}
+
+static void capsense_init(void)
+{
+ gpio_enable_interrupt(GPIO_CAPSENSE_INT_L);
+}
+DECLARE_HOOK(HOOK_INIT, capsense_init, HOOK_PRIO_DEFAULT);
+
+/*
+ * Keep checking polling the capsense until all the buttons are released.
+ * We're not worrying about debouncing, since the capsense module should do
+ * that for us.
+ */
+static void capsense_change_deferred(void)
+{
+ static uint8_t cur_val;
+ uint8_t new_val;
+ int i, n, c;
+
+ new_val = capsense_read_bitmask();
+ if (new_val != cur_val) {
+ CPRINTF("[%T capsense 0x%02x: ", new_val);
+ for (i = 0; i < CAPSENSE_MASK_BITS; i++) {
+ /* See what changed */
+ n = (new_val >> i) & 0x01;
+ c = (cur_val >> i) & 0x01;
+ CPRINTF("%s", n ? " X " : " _ ");
+ if (n == c)
+ continue;
+#ifdef HAS_TASK_KEYPROTO
+ /* Treat it as a keyboard event. */
+ keyboard_update_button(i + KEYBOARD_BUTTON_CAPSENSE_1,
+ n);
+#endif
+ }
+ CPRINTF("]\n");
+ cur_val = new_val;
+ }
+
+ if (cur_val)
+ hook_call_deferred(capsense_change_deferred,
+ CAPSENSE_POLL_INTERVAL);
+}
+DECLARE_DEFERRED(capsense_change_deferred);
+
+/*
+ * Somebody's poking at us.
+ */
+void capsense_interrupt(enum gpio_signal signal)
+{
+ hook_call_deferred(capsense_change_deferred, 0);
+}
diff --git a/common/keyboard_8042.c b/common/keyboard_8042.c
index 04488ab070..4c9df3044f 100644
--- a/common/keyboard_8042.c
+++ b/common/keyboard_8042.c
@@ -192,9 +192,11 @@ static const uint16_t scancode_set2[KEYBOARD_ROWS][KEYBOARD_COLS] = {
/* Button scancodes. Must be in the same order as defined in button_type */
static const uint16_t button_scancodes[2][KEYBOARD_BUTTON_COUNT] = {
/* Set 1 */
- {0xe05e, 0xe02e, 0xe030},
+ {0xe05e, 0xe02e, 0xe030,
+ 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009},
/* Set 2 */
- {0xe037, 0xe021, 0xe032},
+ {0xe037, 0xe021, 0xe032,
+ 0x0016, 0x001e, 0x0026, 0x0025, 0x002e, 0x0036, 0x003d, 0x003e},
};
/*****************************************************************************/
diff --git a/include/button.h b/include/button.h
index eedf7974f8..fbfd4f3879 100644
--- a/include/button.h
+++ b/include/button.h
@@ -17,6 +17,14 @@ enum keyboard_button_type {
KEYBOARD_BUTTON_POWER = 0,
KEYBOARD_BUTTON_VOLUME_DOWN,
KEYBOARD_BUTTON_VOLUME_UP,
+ KEYBOARD_BUTTON_CAPSENSE_1,
+ KEYBOARD_BUTTON_CAPSENSE_2,
+ KEYBOARD_BUTTON_CAPSENSE_3,
+ KEYBOARD_BUTTON_CAPSENSE_4,
+ KEYBOARD_BUTTON_CAPSENSE_5,
+ KEYBOARD_BUTTON_CAPSENSE_6,
+ KEYBOARD_BUTTON_CAPSENSE_7,
+ KEYBOARD_BUTTON_CAPSENSE_8,
KEYBOARD_BUTTON_COUNT
};
diff --git a/include/capsense.h b/include/capsense.h
new file mode 100644
index 0000000000..cc910385f1
--- /dev/null
+++ b/include/capsense.h
@@ -0,0 +1,14 @@
+/* Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef __CROS_EC_CAPSENSE_H
+#define __CROS_EC_CAPSENSE_H
+
+#include "common.h"
+#include "gpio.h"
+
+void capsense_interrupt(enum gpio_signal signal);
+
+#endif /* __CROS_EC_CAPSENSE_H */
diff --git a/include/config.h b/include/config.h
index 7bd77d0fa7..479a68e61a 100644
--- a/include/config.h
+++ b/include/config.h
@@ -145,6 +145,11 @@
*/
#undef CONFIG_BUTTON_COUNT
+/*
+ * Capsense chip has buttons, too.
+ */
+#undef CONFIG_CAPSENSE
+
/*****************************************************************************/
/* Charger config */