diff options
author | Bruce <Bruce.Wan@quantatw.com> | 2016-11-22 09:03:08 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-11-27 22:00:51 -0800 |
commit | ba50aab90456504b0dc8d5f27baffd0f553dc251 (patch) | |
tree | 47851ffdb44e7e0b122b9cdf899fab95959d7584 /chip/npcx/keyboard_raw.c | |
parent | 09f27020665aa5b69cfde6c03f425f35696748d0 (diff) | |
download | chrome-ec-ba50aab90456504b0dc8d5f27baffd0f553dc251.tar.gz |
pyro/snappy: Support keyboard factory scanning
Add keyboard factory scanning tool.
BUG=none
BRANCH=none
TEST=check this tool work normal
Signed-off-by: Bruce.Wan <Bruce.Wan@quantatw.com>
Change-Id: Ifd6aa5c03ce668c4a44a5685fa721af11eb7a84e
Reviewed-on: https://chromium-review.googlesource.com/413764
Commit-Ready: Keith Tzeng <keith.tzeng@quantatw.com>
Tested-by: Keith Tzeng <keith.tzeng@quantatw.com>
Reviewed-by: Shawn N <shawnn@chromium.org>
Diffstat (limited to 'chip/npcx/keyboard_raw.c')
-rw-r--r-- | chip/npcx/keyboard_raw.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/chip/npcx/keyboard_raw.c b/chip/npcx/keyboard_raw.c index ddc797815e..743520a96a 100644 --- a/chip/npcx/keyboard_raw.c +++ b/chip/npcx/keyboard_raw.c @@ -147,3 +147,65 @@ void keyboard_raw_interrupt(void) task_wake(TASK_ID_KEYSCAN); } DECLARE_IRQ(NPCX_IRQ_KSI_WKINTC_1, keyboard_raw_interrupt, 4); + +#ifdef CONFIG_KEYBOARD_FACTORY_TEST + +/* Run keyboard factory testing, scan out KSO/KSI if any shorted. */ +int keyboard_factory_test_scan(void) +{ + int i, j; + uint16_t shorted = 0; + uint32_t port, id; + + /* Disable keyboard scan while testing */ + keyboard_scan_enable(0, KB_SCAN_DISABLE_LID_CLOSED); + + /* Set all of KSO/KSI pins to internal pull-up and input */ + for (i = 0; i < keyboard_factory_scan_pins_used; i++) { + + if (keyboard_factory_scan_pins[i][0] < 0) + continue; + + port = keyboard_factory_scan_pins[i][0]; + id = keyboard_factory_scan_pins[i][1]; + + gpio_set_alternate_function(port, 1 << id, -1); + gpio_set_flags_by_mask(port, 1 << id, + GPIO_INPUT | GPIO_PULL_UP); + } + + /* + * Set start pin to output low, then check other pins + * going to low level, it indicate the two pins are shorted. + */ + for (i = 0; i < keyboard_factory_scan_pins_used; i++) { + + if (keyboard_factory_scan_pins[i][0] < 0) + continue; + + port = keyboard_factory_scan_pins[i][0]; + id = keyboard_factory_scan_pins[i][1]; + + gpio_set_flags_by_mask(port, 1 << id, GPIO_OUT_LOW); + + for (j = 0; j < i; j++) { + + if (keyboard_factory_scan_pins[j][0] < 0) + continue; + + if ((NPCX_PDIN(keyboard_factory_scan_pins[j][0]) & + (1 << keyboard_factory_scan_pins[j][1])) == 0) { + shorted = i << 8 | j; + goto done; + } + } + gpio_set_flags_by_mask(port, 1 << id, + GPIO_INPUT | GPIO_PULL_UP); + } +done: + gpio_config_module(MODULE_KEYBOARD_SCAN, 1); + keyboard_scan_enable(1, KB_SCAN_DISABLE_LID_CLOSED); + + return shorted; +} +#endif |