From 716efd4eb50b5e364662705114b08b15cc254048 Mon Sep 17 00:00:00 2001 From: Tim Crawford Date: Wed, 24 Jul 2024 13:48:53 -0600 Subject: [PATCH] kbscan: Work around IT8587E hang IT8587E is hanging when reading the keyboard matrix. - Increasing the delay does not fix it - Placing delays between KSO* writes does not fix it - Code generated by SDCC looks valid to me Rewriting it like this does fix it, although I don't know why. Signed-off-by: Tim Crawford --- src/board/system76/common/kbscan.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/board/system76/common/kbscan.c b/src/board/system76/common/kbscan.c index a9001d637..f6e3a9a9a 100644 --- a/src/board/system76/common/kbscan.c +++ b/src/board/system76/common/kbscan.c @@ -45,10 +45,21 @@ static inline bool matrix_position_is_fn(uint8_t row, uint8_t col) { // Assert the specified column for reading the row. static void kbscan_set_column(uint8_t col) { // Assert the specific bit corresponding to the column. - uint32_t colbit = ~BIT(col); - KSOL = colbit & 0xFF; - KSOH1 = (colbit >> 8) & 0xFF; - KSOH2 = (colbit >> 16) & 0x03; + // XXX: IT8587E will hang if the column is determined with: + // uint32_t colbit = ~BIT(col); + if (col < 8) { + KSOL = ~BIT(col); + KSOH1 = 0xFF; + KSOH2 = 0xFF; + } else if (col < 16) { + KSOL = 0xFF; + KSOH1 = ~BIT(col - 8); + KSOH2 = 0xFF; + } else { + KSOL = 0xFF; + KSOH1 = 0xFF; + KSOH2 = ~BIT(col - 16); + } // Wait for matrix to stabilize delay_ticks(20); @@ -58,7 +69,7 @@ static void kbscan_set_column(uint8_t col) { static void kbscan_disable_reading(void) { KSOL = 0xFF; KSOH1 = 0xFF; - KSOH2 = 0x3; + KSOH2 = 0xFF; // No need to wait for matrix to stabilize as a read won't happen. }