diff options
author | Paul Kocialkowski <contact@paulk.fr> | 2015-07-20 15:17:09 +0200 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2015-08-12 20:47:36 -0400 |
commit | a4c8bbbc289e4f853b52ce9fe604079038e644cc (patch) | |
tree | 11d3a234d881e6ded9ce054c9671f69b49aca06e /drivers/input/twl4030.c | |
parent | 7d5ac91832918a5fda0277aacb8c62421efdeaa2 (diff) | |
download | u-boot-a4c8bbbc289e4f853b52ce9fe604079038e644cc.tar.gz u-boot-a4c8bbbc289e4f853b52ce9fe604079038e644cc.tar.bz2 u-boot-a4c8bbbc289e4f853b52ce9fe604079038e644cc.zip |
input: twl4030: Keypad scan and input
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>
Diffstat (limited to 'drivers/input/twl4030.c')
-rw-r--r-- | drivers/input/twl4030.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/drivers/input/twl4030.c b/drivers/input/twl4030.c index a5ded35d92..dc5868c0ab 100644 --- a/drivers/input/twl4030.c +++ b/drivers/input/twl4030.c @@ -47,3 +47,42 @@ int twl4030_input_usb(void) 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]; +} |