]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
input: twl4030: Keypad scan and input
authorPaul Kocialkowski <contact@paulk.fr>
Mon, 20 Jul 2015 13:17:09 +0000 (15:17 +0200)
committerLothar Waßmann <LW@KARO-electronics.de>
Thu, 10 Sep 2015 06:24:13 +0000 (08:24 +0200)
This allows scanning the twl4030 keypad, storing the result in a 64-byte long
matrix with the twl4030_keypad_scan function.

Detecting a key at a given column and row is made easier with the
twl4030_keypad_key function.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Reviewed-by: Tom Rini <trini@konsulko.com>
drivers/input/twl4030.c
include/twl4030.h

index a5ded35d9226bcc7bc3be46c972b9b9fc3c31d0f..dc5868c0ab9ac446ccb50cb87dbd9bf58074081d 100644 (file)
@@ -47,3 +47,42 @@ int twl4030_input_usb(void)
 
        return 0;
 }
 
        return 0;
 }
+
+int twl4030_keypad_scan(unsigned char *matrix)
+{
+       u8 data;
+       u8 c, r;
+
+       twl4030_i2c_read_u8(TWL4030_CHIP_KEYPAD,
+                           TWL4030_KEYPAD_KEYP_CTRL_REG, &data);
+
+       data |= TWL4030_KEYPAD_CTRL_SOFT_NRST | TWL4030_KEYPAD_CTRL_KBD_ON;
+       data &= ~TWL4030_KEYPAD_CTRL_SOFTMODEN;
+
+       twl4030_i2c_write_u8(TWL4030_CHIP_KEYPAD,
+                            TWL4030_KEYPAD_KEYP_CTRL_REG, data);
+
+       for (c = 0; c < 8; c++) {
+               data = 0xff & ~(1 << c);
+               twl4030_i2c_write_u8(TWL4030_CHIP_KEYPAD,
+                                    TWL4030_KEYPAD_KBC_REG, data);
+
+               data = 0xff;
+               twl4030_i2c_read_u8(TWL4030_CHIP_KEYPAD,
+                                   TWL4030_KEYPAD_KBR_REG, &data);
+
+               for (r = 0; r < 8; r++)
+                       matrix[c * 8 + r] = !(data & (1 << r));
+       }
+
+       data = 0xff & ~(TWL4030_KEYPAD_CTRL_SOFT_NRST);
+       twl4030_i2c_write_u8(TWL4030_CHIP_KEYPAD,
+                            TWL4030_KEYPAD_KEYP_CTRL_REG, data);
+
+       return 0;
+}
+
+int twl4030_keypad_key(unsigned char *matrix, u8 c, u8 r)
+{
+       return matrix[c * 8 + r];
+}
index a4d5fbdb617b52458d3e2ef23a817e40f9b0758c..103137372d309c2d2e906297d619d5841040e04f 100644 (file)
@@ -683,6 +683,9 @@ int twl4030_input_power_button(void);
 int twl4030_input_charger(void);
 int twl4030_input_usb(void);
 
 int twl4030_input_charger(void);
 int twl4030_input_usb(void);
 
+int twl4030_keypad_scan(unsigned char *matrix);
+int twl4030_keypad_key(unsigned char *matrix, u8 c, u8 r);
+
 /*
  * LED
  */
 /*
  * LED
  */