summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--board/mec1322_evb/board.c10
-rw-r--r--chip/mec1322/build.mk1
-rw-r--r--chip/mec1322/keyboard_raw.c66
-rw-r--r--chip/mec1322/registers.h11
-rw-r--r--chip/mec1322/system.c3
5 files changed, 91 insertions, 0 deletions
diff --git a/board/mec1322_evb/board.c b/board/mec1322_evb/board.c
index ced2c5ab27..f70fe5749d 100644
--- a/board/mec1322_evb/board.c
+++ b/board/mec1322_evb/board.c
@@ -10,6 +10,9 @@
#include "registers.h"
#include "util.h"
+#define GPIO_KB_INPUT GPIO_INPUT
+#define GPIO_KB_OUTPUT (GPIO_ODR_HIGH | GPIO_PULL_UP)
+
/* GPIO signal list. Must match order from enum gpio_signal. */
const struct gpio_info gpio_list[] = {
{"LED1", GPIO_PORT(15), (1 << 4), GPIO_ODR_LOW, NULL},
@@ -28,6 +31,13 @@ const struct gpio_alt_func gpio_alt_funcs[] = {
{GPIO_PORT(3), (1 << 4), 3, MODULE_PWM_FAN},
{GPIO_PORT(14), (1 << 0), 3, MODULE_PWM_FAN},
{GPIO_PORT(1), 0x60, 2, MODULE_I2C}, /* I2C0 */
+ {GPIO_PORT(0), 0xfe, 3, MODULE_KEYBOARD_SCAN, GPIO_KB_OUTPUT},
+ {GPIO_PORT(1), 0x03, 3, MODULE_KEYBOARD_SCAN, GPIO_KB_OUTPUT},
+ {GPIO_PORT(3), 0x04, 3, MODULE_KEYBOARD_SCAN, GPIO_KB_INPUT},
+ {GPIO_PORT(4), 0x0d, 3, MODULE_KEYBOARD_SCAN, GPIO_KB_INPUT},
+ {GPIO_PORT(10), 0xd8, 3, MODULE_KEYBOARD_SCAN, GPIO_KB_OUTPUT},
+ {GPIO_PORT(12), 0x60, 2, MODULE_KEYBOARD_SCAN, GPIO_KB_INPUT},
+ {GPIO_PORT(14), 0x14, 3, MODULE_KEYBOARD_SCAN, GPIO_KB_INPUT},
};
const int gpio_alt_funcs_count = ARRAY_SIZE(gpio_alt_funcs);
diff --git a/chip/mec1322/build.mk b/chip/mec1322/build.mk
index bbc040a284..60376d1a5f 100644
--- a/chip/mec1322/build.mk
+++ b/chip/mec1322/build.mk
@@ -18,3 +18,4 @@ chip-$(CONFIG_I2C)+=i2c.o
chip-$(CONFIG_LPC)+=lpc.o
chip-$(CONFIG_PWM)+=pwm.o
chip-$(CONFIG_WATCHDOG)+=watchdog.o
+chip-$(HAS_TASK_KEYSCAN)+=keyboard_raw.o
diff --git a/chip/mec1322/keyboard_raw.c b/chip/mec1322/keyboard_raw.c
new file mode 100644
index 0000000000..155ff839f2
--- /dev/null
+++ b/chip/mec1322/keyboard_raw.c
@@ -0,0 +1,66 @@
+/* Copyright (c) 2013 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.
+ *
+ * Raw keyboard I/O layer for MEC1322
+ */
+
+#include "gpio.h"
+#include "keyboard_config.h"
+#include "keyboard_raw.h"
+#include "keyboard_scan.h"
+#include "registers.h"
+#include "task.h"
+#include "util.h"
+
+void keyboard_raw_init(void)
+{
+ keyboard_raw_enable_interrupt(0);
+ gpio_config_module(MODULE_KEYBOARD_SCAN, 1);
+
+ /* Enable keyboard scan interrupt */
+ MEC1322_INT_ENABLE(17) |= 1 << 21;
+ MEC1322_INT_BLK_EN |= 1 << 17;
+ MEC1322_KS_KSI_INT_EN = 0xff;
+}
+
+void keyboard_raw_task_start(void)
+{
+ task_enable_irq(MEC1322_IRQ_KSC_INT);
+}
+
+test_mockable void keyboard_raw_drive_column(int out)
+{
+ if (out == KEYBOARD_COLUMN_ALL)
+ MEC1322_KS_KSO_SEL = 1 << 5; /* KSEN=0, KSALL=1 */
+ else if (out == KEYBOARD_COLUMN_NONE)
+ MEC1322_KS_KSO_SEL = 1 << 6; /* KSEN=1 */
+ else
+ MEC1322_KS_KSO_SEL = out + 4; /* KSO starts from KSO04 */
+}
+
+test_mockable int keyboard_raw_read_rows(void)
+{
+ /* Invert it so 0=not pressed, 1=pressed */
+ return (MEC1322_KS_KSI_INPUT & 0xff) ^ 0xff;
+}
+
+void keyboard_raw_enable_interrupt(int enable)
+{
+ if (enable) {
+ task_clear_pending_irq(MEC1322_IRQ_KSC_INT);
+ task_enable_irq(MEC1322_IRQ_KSC_INT);
+ } else {
+ task_disable_irq(MEC1322_IRQ_KSC_INT);
+ }
+}
+
+static void keyboard_raw_interrupt(void)
+{
+ /* Clear interrupt status bits */
+ MEC1322_KS_KSI_STATUS = 0xff;
+
+ /* Wake keyboard scan task to handle interrupt */
+ task_wake(TASK_ID_KEYSCAN);
+}
+DECLARE_IRQ(MEC1322_IRQ_KSC_INT, keyboard_raw_interrupt, 1);
diff --git a/chip/mec1322/registers.h b/chip/mec1322/registers.h
index 3f9c350c5c..4972681047 100644
--- a/chip/mec1322/registers.h
+++ b/chip/mec1322/registers.h
@@ -41,6 +41,8 @@
/* EC Subsystem */
#define MEC1322_EC_BASE 0x4000fc00
#define MEC1322_EC_INT_CTRL REG32(MEC1322_EC_BASE + 0x18)
+#define MEC1322_EC_TRACE_EN REG32(MEC1322_EC_BASE + 0x1c)
+#define MEC1322_EC_JTAG_EN REG32(MEC1322_EC_BASE + 0x20)
/* Interrupt aggregator */
@@ -240,6 +242,15 @@ static inline uintptr_t gpio_port_base(int port_id)
#define MEC1322_I2C_MASTER_RX_BUF(port) REG8(MEC1322_I2C_ADDR(port, 0x54))
+/* Keyboard scan matrix */
+#define MEC1322_KS_BASE 0x40009c00
+#define MEC1322_KS_KSO_SEL REG32(MEC1322_KS_BASE + 0x4)
+#define MEC1322_KS_KSI_INPUT REG32(MEC1322_KS_BASE + 0x8)
+#define MEC1322_KS_KSI_STATUS REG32(MEC1322_KS_BASE + 0xc)
+#define MEC1322_KS_KSI_INT_EN REG32(MEC1322_KS_BASE + 0x10)
+#define MEC1322_KS_EXT_CTRL REG32(MEC1322_KS_BASE + 0x14)
+
+
/* IRQ Numbers */
#define MEC1322_IRQ_I2C_0 0
#define MEC1322_IRQ_I2C_1 1
diff --git a/chip/mec1322/system.c b/chip/mec1322/system.c
index 7425ccc30f..aa7b36e459 100644
--- a/chip/mec1322/system.c
+++ b/chip/mec1322/system.c
@@ -47,6 +47,9 @@ void system_pre_init(void)
/* Enable direct NVIC */
MEC1322_EC_INT_CTRL |= 1;
+ /* Disable ARM TRACE debug port */
+ MEC1322_EC_TRACE_EN &= ~1;
+
/* Deassert nSIO_RESET */
MEC1322_PCR_PWR_RST_CTL &= ~(1 << 0);