summaryrefslogtreecommitdiff
path: root/common/keyboard_scan.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/keyboard_scan.c')
-rw-r--r--common/keyboard_scan.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/common/keyboard_scan.c b/common/keyboard_scan.c
index f9a64eb806..24fc7bc73c 100644
--- a/common/keyboard_scan.c
+++ b/common/keyboard_scan.c
@@ -861,6 +861,69 @@ DECLARE_HOST_COMMAND(EC_CMD_MKBP_SIMULATE_KEY,
EC_VER_MASK(0));
#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, flags;
+ uint16_t shorted = 0;
+ int port, id;
+
+ /* Disable keyboard scan while testing */
+ keyboard_scan_enable(0, KB_SCAN_DISABLE_LID_CLOSED);
+ flags = gpio_get_default_flags(GPIO_KBD_KSO2);
+
+ /* 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 (keyboard_raw_is_input_low(
+ keyboard_factory_scan_pins[j][0],
+ keyboard_factory_scan_pins[j][1])) {
+ 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);
+ gpio_set_flags(GPIO_KBD_KSO2, flags);
+ keyboard_scan_enable(1, KB_SCAN_DISABLE_LID_CLOSED);
+
+ return shorted;
+}
+
static int keyboard_factory_test(struct host_cmd_handler_args *args)
{
struct ec_response_keyboard_factory_test *r = args->response;