@@ -36,6 +36,19 @@ static const struct regmap_config mt6779_keypad_regmap_cfg = {
.max_register = 36,
};
+/*
+ * | hardware key code | col0 | col1 | col2|
+ * | ----------------- | -----| ---- | --- |
+ * | row0 | 0 | 1 | 2 |
+ * | row1 | 9 | 10 | 11 |
+ * | row2 | 18 | 19 | 20 |
+ */
+static void bitnr_to_col_row(int bit_nr, int *col, int *row)
+{
+ *row = bit_nr / 9;
+ *col = bit_nr % 3;
+}
+
static irqreturn_t mt6779_keypad_irq_handler(int irq, void *dev_id)
{
struct mt6779_keypad *keypad = dev_id;
@@ -61,8 +74,7 @@ static irqreturn_t mt6779_keypad_irq_handler(int irq, void *dev_id)
if (bit_nr % 32 >= 16)
continue;
- row = bit_nr / 32;
- col = bit_nr % 32;
+ bitnr_to_col_row(bit_nr, &col, &row);
scancode = MATRIX_SCAN_CODE(row, col, row_shift);
/* 1: not pressed, 0: pressed */
pressed = !test_bit(bit_nr, new_state);