[PATCH] input: keyboard-matrix: add a function to reset input states

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In some cases, at open(), when matrix_keypad_start() schedules
matrix_keypad_scan(), some events may be fired, but they can't be
grabbed from the event queue by evtest later on, since this
condition causes a continuous event triggered.

Add a function to get (and align) button states at open without
firing events at open stage.

Signed-off-by: Angelo Dureghello <angelo.dureghello@xxxxxxxxxxx>
---
 drivers/input/keyboard/matrix_keypad.c | 37 ++++++++++++++++----------
 1 file changed, 23 insertions(+), 14 deletions(-)

diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c
index 30924b57058f..ce8cb09ee333 100644
--- a/drivers/input/keyboard/matrix_keypad.c
+++ b/drivers/input/keyboard/matrix_keypad.c
@@ -108,6 +108,24 @@ static void disable_row_irqs(struct matrix_keypad *keypad)
 	}
 }
 
+static inline void matrix_get_keys_state(struct matrix_keypad *keypad,
+					 uint32_t *states)
+{
+	int row, col;
+	const struct matrix_keypad_platform_data *pdata = keypad->pdata;
+
+	states = states ?: keypad->last_key_state;
+
+	/* assert each column and read the row status out */
+	for (col = 0; col < pdata->num_col_gpios; col++) {
+		activate_col(pdata, col, true);
+		for (row = 0; row < pdata->num_row_gpios; row++)
+			states[col] |=
+				row_asserted(pdata, row) ? (1 << row) : 0;
+		activate_col(pdata, col, false);
+	}
+}
+
 /*
  * This gets the keys from keyboard and reports it to input subsystem
  */
@@ -126,17 +144,7 @@ static void matrix_keypad_scan(struct work_struct *work)
 
 	memset(new_state, 0, sizeof(new_state));
 
-	/* assert each column and read the row status out */
-	for (col = 0; col < pdata->num_col_gpios; col++) {
-
-		activate_col(pdata, col, true);
-
-		for (row = 0; row < pdata->num_row_gpios; row++)
-			new_state[col] |=
-				row_asserted(pdata, row) ? (1 << row) : 0;
-
-		activate_col(pdata, col, false);
-	}
+	matrix_get_keys_state(keypad, new_state);
 
 	for (col = 0; col < pdata->num_col_gpios; col++) {
 		uint32_t bits_changed;
@@ -202,10 +210,11 @@ static int matrix_keypad_start(struct input_dev *dev)
 	mb();
 
 	/*
-	 * Schedule an immediate key scan to capture current key state;
-	 * columns will be activated and IRQs be enabled after the scan.
+	 * Reset current key state and activate columns and IRQs.
 	 */
-	schedule_delayed_work(&keypad->work, 0);
+	matrix_get_keys_state(keypad, NULL);
+	activate_all_cols(keypad->pdata, true);
+	enable_row_irqs(keypad);
 
 	return 0;
 }
-- 
2.32.0




[Index of Archives]     [Linux Media Devel]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Linux Wireless Networking]     [Linux Omap]

  Powered by Linux