summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--board/pyro/board.c20
-rw-r--r--board/pyro/board.h6
-rw-r--r--board/snappy/board.c18
-rw-r--r--board/snappy/board.h6
-rw-r--r--chip/npcx/keyboard_raw.c62
5 files changed, 112 insertions, 0 deletions
diff --git a/board/pyro/board.c b/board/pyro/board.c
index 1fcad28023..fd8eaa4fcd 100644
--- a/board/pyro/board.c
+++ b/board/pyro/board.c
@@ -1007,3 +1007,23 @@ int board_get_version(void)
CPRINTS("Board version: %d\n", version);
return version;
}
+
+#ifdef CONFIG_KEYBOARD_FACTORY_TEST
+/*
+ * We have total 32 pins for keyboard connecter, {-1, -1} mean
+ * the N/A pin that don't consider it and reserve index 0 area
+ * that we don't have pin 0.
+ */
+const int keyboard_factory_scan_pins[][2] = {
+ {-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}, {-1, -1},
+ {-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}, {0, 5},
+ {1, 1}, {1, 0}, {0, 6}, {0, 7}, {-1, -1},
+ {-1, -1}, {1, 4}, {1, 3}, {-1, -1}, {1, 6},
+ {-1, -1}, {3, 1}, {2, 0}, {1, 5}, {2, 6},
+ {-1, -1}, {2, 1}, {2, 4}, {2, 5}, {1, 2},
+ {2, 3}, {2, 2}, {3, 0},
+};
+
+const int keyboard_factory_scan_pins_used =
+ ARRAY_SIZE(keyboard_factory_scan_pins);
+#endif
diff --git a/board/pyro/board.h b/board/pyro/board.h
index 5a8930744e..2871f85bff 100644
--- a/board/pyro/board.h
+++ b/board/pyro/board.h
@@ -128,6 +128,7 @@
#define CONFIG_I2C_MASTER
#define CONFIG_KEYBOARD_PROTOCOL_8042
#define CONFIG_KEYBOARD_COL2_INVERTED
+#define CONFIG_KEYBOARD_FACTORY_TEST
#define CONFIG_KEYBOARD_PWRBTN_ASSERTS_KSI2
#define CONFIG_LED_COMMON
#define CONFIG_LID_SWITCH
@@ -300,6 +301,11 @@ enum pyro_board_version {
/* The higher the input voltage, the higher the power efficiency. */
#define PD_PREFER_HIGH_VOLTAGE
+#ifdef CONFIG_KEYBOARD_FACTORY_TEST
+extern const int keyboard_factory_scan_pins[][2];
+extern const int keyboard_factory_scan_pins_used;
+#endif
+
/* Reset PD MCU */
void board_reset_pd_mcu(void);
diff --git a/board/snappy/board.c b/board/snappy/board.c
index 5987d6ef50..29b7b0f716 100644
--- a/board/snappy/board.c
+++ b/board/snappy/board.c
@@ -1007,3 +1007,21 @@ int board_get_version(void)
CPRINTS("Board version: %d\n", version);
return version;
}
+
+#ifdef CONFIG_KEYBOARD_FACTORY_TEST
+/*
+ * We have total 21 pins for keyboard connecter, {-1, -1} mean
+ * the N/A pin that don't consider it and reserve index 0 area
+ * that we don't have pin 0.
+ */
+const int keyboard_factory_scan_pins[][2] = {
+ {-1, -1}, {0, 5}, {1, 1}, {1, 0}, {0, 6},
+ {0, 7}, {1, 4}, {1, 3}, {1, 6}, {-1, -1},
+ {3, 1}, {2, 0}, {1, 5}, {2, 6}, {-1, -1},
+ {2, 1}, {2, 4}, {2, 5}, {1, 2}, {2, 3},
+ {2, 2}, {3, 0},
+};
+
+const int keyboard_factory_scan_pins_used =
+ ARRAY_SIZE(keyboard_factory_scan_pins);
+#endif
diff --git a/board/snappy/board.h b/board/snappy/board.h
index 6ca1adcae7..26f2dcd9ad 100644
--- a/board/snappy/board.h
+++ b/board/snappy/board.h
@@ -127,6 +127,7 @@
#define CONFIG_I2C_MASTER
#define CONFIG_KEYBOARD_PROTOCOL_8042
#define CONFIG_KEYBOARD_COL2_INVERTED
+#define CONFIG_KEYBOARD_FACTORY_TEST
#define CONFIG_KEYBOARD_PWRBTN_ASSERTS_KSI2
#define CONFIG_LED_COMMON
#define CONFIG_LID_SWITCH
@@ -295,6 +296,11 @@ enum snappy_board_version {
#define PD_MAX_CURRENT_MA 3000
#define PD_MAX_VOLTAGE_MV 20000
+#ifdef CONFIG_KEYBOARD_FACTORY_TEST
+extern const int keyboard_factory_scan_pins[][2];
+extern const int keyboard_factory_scan_pins_used;
+#endif
+
/* Reset PD MCU */
void board_reset_pd_mcu(void);
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