From 6639c98acc98ec2103c215800b4d63dbea843248 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Wed, 13 Jan 2016 11:12:58 +0100 Subject: input: move matrix_keypad_build_keymap() to C file Future additions will make the function too big to live as a static inline function. Move to a C file and while at it, move matrix_keypad.h to include/input/ where it belongs to. Signed-off-by: Sascha Hauer --- drivers/input/Kconfig | 4 ++++ drivers/input/Makefile | 1 + drivers/input/imx_keypad.c | 2 +- drivers/input/matrix-keymap.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 drivers/input/matrix-keymap.c (limited to 'drivers/input') diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig index b840df2ed5..24c3bd758c 100644 --- a/drivers/input/Kconfig +++ b/drivers/input/Kconfig @@ -8,6 +8,9 @@ menu "Input device support" config INPUT bool +config INPUT_MATRIXKMAP + bool + config KEYBOARD_GPIO bool "GPIO Buttons" depends on GENERIC_GPIO @@ -24,6 +27,7 @@ config KEYBOARD_GPIO config KEYBOARD_IMX_KEYPAD bool "IMX Keypad" depends on ARCH_IMX + select INPUT_MATRIXKMAP select POLLER help This driver implements support for buttons connected diff --git a/drivers/input/Makefile b/drivers/input/Makefile index b9e5a5db2f..7d2c1945f7 100644 --- a/drivers/input/Makefile +++ b/drivers/input/Makefile @@ -1,4 +1,5 @@ obj-$(CONFIG_INPUT) += input.o +obj-$(CONFIG_INPUT_MATRIXKMAP) += matrix-keymap.o obj-$(CONFIG_KEYBOARD_USB) += usb_kbd.o obj-$(CONFIG_KEYBOARD_GPIO) += gpio_keys.o obj-$(CONFIG_KEYBOARD_TWL6030) += twl6030_pwrbtn.o diff --git a/drivers/input/imx_keypad.c b/drivers/input/imx_keypad.c index 272b8367df..b0282f2f8c 100644 --- a/drivers/input/imx_keypad.c +++ b/drivers/input/imx_keypad.c @@ -46,7 +46,7 @@ #include #include #include -#include +#include #include /* diff --git a/drivers/input/matrix-keymap.c b/drivers/input/matrix-keymap.c new file mode 100644 index 0000000000..d56eccc29e --- /dev/null +++ b/drivers/input/matrix-keymap.c @@ -0,0 +1,42 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; version 2. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + */ + +#include +#include + +/** + * matrix_keypad_build_keymap - convert platform keymap into matrix keymap + * @keymap_data: keymap supplied by the platform code + * @row_shift: number of bits to shift row value by to advance to the next + * line in the keymap + * @keymap: expanded version of keymap that is suitable for use by + * matrix keyboad driver + * This function converts platform keymap (encoded with KEY() macro) into + * an array of keycodes that is suitable for using in a standard matrix + * keyboard driver that uses row and col as indices. + */ +int matrix_keypad_build_keymap(const struct matrix_keymap_data *keymap_data, + unsigned int row_shift, + unsigned short *keymap) +{ + int i; + + for (i = 0; i < keymap_data->keymap_size; i++) { + unsigned int key = keymap_data->keymap[i]; + unsigned int row = KEY_ROW(key); + unsigned int col = KEY_COL(key); + unsigned short code = KEY_VAL(key); + + keymap[MATRIX_SCAN_CODE(row, col, row_shift)] = code; + } + + return 0; +} -- cgit v1.2.3