diff options
author | Vic (Chun-Ju) Yang <victoryang@chromium.org> | 2013-12-10 10:33:12 +0800 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2013-12-13 02:44:10 +0000 |
commit | 22f82e28dc0788debd10499f2c93ab392cbb09bf (patch) | |
tree | d66049fdcc2a861d1b5af3ae6b2d1e08d0972e0e /chip/mec1322/keyboard_raw.c | |
parent | d3fdf5e6f3243484328d3d954a1924b355ff9c21 (diff) | |
download | chrome-ec-22f82e28dc0788debd10499f2c93ab392cbb09bf.tar.gz |
mec1322: keyboard scan support
This adds keyboard scan module driver. Keyboard scan task is not enabled
yet as the LPC layer is not finished and thus i8042 protocol cannot be
enabled.
Since KSO00-KSO03 are used as JTAG, we use KSO04-KSO16 so as to preserve
JTAG functionality. Unfortunately we don't have enough KSO pins, so
trace debug port must be disabled, as done in this CL.
BUG=chrome-os-partner:24107
TEST=Set 'ksstate on'. Short KSI pins and KSO pins, and see
corresponding key shown as pressed.
TEST=Check keypress is detected when console shows 'KB wait'.
BRANCH=None
Change-Id: I366a27453ef95030d251e525313eb4627eb4340f
Signed-off-by: Vic (Chun-Ju) Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/179319
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'chip/mec1322/keyboard_raw.c')
-rw-r--r-- | chip/mec1322/keyboard_raw.c | 66 |
1 files changed, 66 insertions, 0 deletions
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); |