summaryrefslogtreecommitdiff
path: root/chip/npcx/keyboard_raw.c
diff options
context:
space:
mode:
authorIan Chao <mlchao@nuvoton.com>2014-12-06 14:23:02 +0800
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-01-14 03:16:10 +0000
commit4ee50837a0263a5bfcb61e32a862797ede387c78 (patch)
treeaf86c4bd09ff9e4d364ff66444a26f9091b15d14 /chip/npcx/keyboard_raw.c
parent3951165fe9182cb6c9981d0a69c36765c7fe8916 (diff)
downloadchrome-ec-4ee50837a0263a5bfcb61e32a862797ede387c78.tar.gz
nuc: Add all IC specific drivers of NPCX5M5G
Add npcx_evb in board folder for testing Add shared-spi arch support in common layer. Modified drivers for 1. Fan.c: console command “pwmduty”. 2. Pwm.c: for the issue when set duty to 0. 3. System.c: for hw reset only during system reset. 4. Flash.c: Fixed access denied bug of the flash driver for host command. 5. Comments from Patch Set 1 6. Comments from Patch Set 3 (except sha256.c) 7. Add openocd and flash_ec support for npcx_evb 8. Add little FW and spi-flash upload FW in chip folder 9. Add optional make rules for PROJECT_EXTRA 10.Replace CONFIG_SHRSPI_ARCH with CONFIG_CODERAM_ARCH and remove changes in common layer sources for shared-spi arch. (except sysjump) 11.Find the root cause of JTAG issue and use workaround method with SUPPORT_JTAG in clock.c 12 Execute hibernate in low power RAM for better power consumption 13 Add workaround method for version console command 14 Modified coding style issues by checkpatch.pl tool BUG=chrome-os-partner:34346 TEST=make buildall -j; test nuvoton IC specific drivers BRANCH=none Change-Id: I5e383420642de1643e2bead837a55c8c58481786 Signed-off-by: Ian Chao <mlchao@nuvoton.com> Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/233742
Diffstat (limited to 'chip/npcx/keyboard_raw.c')
-rw-r--r--chip/npcx/keyboard_raw.c128
1 files changed, 128 insertions, 0 deletions
diff --git a/chip/npcx/keyboard_raw.c b/chip/npcx/keyboard_raw.c
new file mode 100644
index 0000000000..e6599a35e2
--- /dev/null
+++ b/chip/npcx/keyboard_raw.c
@@ -0,0 +1,128 @@
+/* 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.
+ */
+
+/* Functions needed by keyboard scanner module for Chrome EC */
+
+#include "common.h"
+#include "keyboard_raw.h"
+#include "keyboard_scan.h"
+#include "clock.h"
+#include "registers.h"
+#include "task.h"
+
+/**
+ * Initialize the raw keyboard interface.
+ */
+void keyboard_raw_init(void)
+{
+ /* Enable clock for KBS peripheral */
+ clock_enable_peripheral(CGC_OFFSET_KBS, CGC_KBS_MASK,
+ CGC_MODE_RUN | CGC_MODE_SLEEP);
+
+ /* Ensure top-level interrupt is disabled */
+ keyboard_raw_enable_interrupt(0);
+
+ /* pull-up KBSIN 0-7 internally */
+ NPCX_KBSINPU = 0xFF;
+
+ /* Disable automatic scan mode */
+ CLEAR_BIT(NPCX_KBSCTL, NPCX_KBSMODE);
+
+ /* Disable automatic interrupt enable */
+ CLEAR_BIT(NPCX_KBSCTL, NPCX_KBSIEN);
+
+ /* Disable increment enable */
+ CLEAR_BIT(NPCX_KBSCTL, NPCX_KBSINC);
+
+ /* Set KBSOUT to zero to detect key-press */
+ NPCX_KBSOUT0 = 0x00;
+ NPCX_KBSOUT1 = 0x00;
+
+ /*
+ * Enable interrupts for the inputs. The top-level interrupt is still
+ * masked off, so this won't trigger interrupts yet.
+ */
+
+ /* Clear pending input sources used by scanner */
+ NPCX_WKPCL(MIWU_TABLE_WKKEY, MIWU_GROUP_WKKEY) = 0xFF;
+
+ /* Enable Wake-up Button */
+ NPCX_WKEN(MIWU_TABLE_WKKEY, MIWU_GROUP_WKKEY) = 0xFF;
+
+ /* Select high to low transition (falling edge) */
+ NPCX_WKEDG(MIWU_TABLE_WKKEY, MIWU_GROUP_WKKEY) = 0xFF;
+
+ /* Enable interrupt of WK KBS */
+ keyboard_raw_enable_interrupt(1);
+}
+
+/**
+ * Finish initialization after task scheduling has started.
+ */
+void keyboard_raw_task_start(void)
+{
+ /* Enable MIWU to trigger KBS interrupt */
+ task_enable_irq(NPCX_IRQ_KSI_WKINTC_1);
+}
+
+/**
+ * Drive the specified column low.
+ */
+test_mockable void keyboard_raw_drive_column(int col)
+{
+ /*
+ * Nuvoton Keyboard Scan IP supports 18x8 Matrix
+ * It also support automatic scan functionality
+ */
+ uint32_t mask;
+
+ /* Drive all lines to high */
+ if (col == KEYBOARD_COLUMN_NONE)
+ mask = KB_COL_MASK;
+ /* Set KBSOUT to zero to detect key-press */
+ else if (col == KEYBOARD_COLUMN_ALL)
+ mask = 0;
+ /* Drive one line for detection */
+ else
+ mask = ((~(1 << col)) & KB_COL_MASK);
+
+ /* Set KBSOUT */
+ NPCX_KBSOUT0 = (mask & 0xFFFF);
+ NPCX_KBSOUT1 = ((mask >> 16) & 0x03);
+}
+
+/**
+ * Read raw row state.
+ * Bits are 1 if signal is present, 0 if not present.
+ */
+test_mockable int keyboard_raw_read_rows(void)
+{
+ /* Bits are active-low, so invert returned levels */
+ return (~NPCX_KBSIN) & KB_ROW_MASK;
+}
+
+/**
+ * Enable or disable keyboard interrupts.
+ */
+void keyboard_raw_enable_interrupt(int enable)
+{
+ if (enable)
+ task_enable_irq(NPCX_IRQ_KSI_WKINTC_1);
+ else
+ task_disable_irq(NPCX_IRQ_KSI_WKINTC_1);
+}
+
+/*
+ * Interrupt handler for the entire GPIO bank of keyboard rows.
+ */
+void keyboard_raw_interrupt(void)
+{
+ /* Clear pending input sources used by scanner */
+ NPCX_WKPCL(MIWU_TABLE_WKKEY, MIWU_GROUP_WKKEY) = 0xFF;
+
+ /* Wake the scan task */
+ task_wake(TASK_ID_KEYSCAN);
+}
+DECLARE_IRQ(NPCX_IRQ_KSI_WKINTC_1, keyboard_raw_interrupt, 3);