aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/devicetree/bindings/input/matrix-keymap.txt19
-rw-r--r--drivers/input/Kconfig4
-rw-r--r--drivers/input/Makefile1
-rw-r--r--drivers/input/keyboard/Kconfig1
-rw-r--r--drivers/input/of_keymap.c87
-rw-r--r--include/linux/input/matrix_keypad.h19
6 files changed, 131 insertions, 0 deletions
diff --git a/Documentation/devicetree/bindings/input/matrix-keymap.txt b/Documentation/devicetree/bindings/input/matrix-keymap.txt
new file mode 100644
index 000000000000..3cd8b98ccd2d
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/matrix-keymap.txt
@@ -0,0 +1,19 @@
1A simple common binding for matrix-connected key boards. Currently targeted at
2defining the keys in the scope of linux key codes since that is a stable and
3standardized interface at this time.
4
5Required properties:
6- linux,keymap: an array of packed 1-cell entries containing the equivalent
7 of row, column and linux key-code. The 32-bit big endian cell is packed
8 as:
9 row << 24 | column << 16 | key-code
10
11Optional properties:
12Some users of this binding might choose to specify secondary keymaps for
13cases where there is a modifier key such as a Fn key. Proposed names
14for said properties are "linux,fn-keymap" or with another descriptive
15word for the modifier other from "Fn".
16
17Example:
18 linux,keymap = < 0x00030012
19 0x0102003a >;
diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig
index 001b147c7f95..332597980817 100644
--- a/drivers/input/Kconfig
+++ b/drivers/input/Kconfig
@@ -25,6 +25,10 @@ config INPUT
25 25
26if INPUT 26if INPUT
27 27
28config INPUT_OF_MATRIX_KEYMAP
29 depends on USE_OF
30 bool
31
28config INPUT_FF_MEMLESS 32config INPUT_FF_MEMLESS
29 tristate "Support for memoryless force-feedback devices" 33 tristate "Support for memoryless force-feedback devices"
30 help 34 help
diff --git a/drivers/input/Makefile b/drivers/input/Makefile
index 0c789490e0b3..b173a13a73ca 100644
--- a/drivers/input/Makefile
+++ b/drivers/input/Makefile
@@ -24,3 +24,4 @@ obj-$(CONFIG_INPUT_TOUCHSCREEN) += touchscreen/
24obj-$(CONFIG_INPUT_MISC) += misc/ 24obj-$(CONFIG_INPUT_MISC) += misc/
25 25
26obj-$(CONFIG_INPUT_APMPOWER) += apm-power.o 26obj-$(CONFIG_INPUT_APMPOWER) += apm-power.o
27obj-$(CONFIG_INPUT_OF_MATRIX_KEYMAP) += of_keymap.o
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index cdc385b2cf7d..3371954c979b 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -394,6 +394,7 @@ config KEYBOARD_NOMADIK
394config KEYBOARD_TEGRA 394config KEYBOARD_TEGRA
395 tristate "NVIDIA Tegra internal matrix keyboard controller support" 395 tristate "NVIDIA Tegra internal matrix keyboard controller support"
396 depends on ARCH_TEGRA 396 depends on ARCH_TEGRA
397 select INPUT_OF_MATRIX_KEYMAP if USE_OF
397 help 398 help
398 Say Y here if you want to use a matrix keyboard connected directly 399 Say Y here if you want to use a matrix keyboard connected directly
399 to the internal keyboard controller on Tegra SoCs. 400 to the internal keyboard controller on Tegra SoCs.
diff --git a/drivers/input/of_keymap.c b/drivers/input/of_keymap.c
new file mode 100644
index 000000000000..061493d57682
--- /dev/null
+++ b/drivers/input/of_keymap.c
@@ -0,0 +1,87 @@
1/*
2 * Helpers for open firmware matrix keyboard bindings
3 *
4 * Copyright (C) 2012 Google, Inc
5 *
6 * Author:
7 * Olof Johansson <olof@lixom.net>
8 *
9 * This software is licensed under the terms of the GNU General Public
10 * License version 2, as published by the Free Software Foundation, and
11 * may be copied, distributed, and modified under those terms.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 */
19
20#include <linux/kernel.h>
21#include <linux/types.h>
22#include <linux/input.h>
23#include <linux/of.h>
24#include <linux/input/matrix_keypad.h>
25#include <linux/export.h>
26#include <linux/gfp.h>
27#include <linux/slab.h>
28
29struct matrix_keymap_data *
30matrix_keyboard_of_fill_keymap(struct device_node *np,
31 const char *propname)
32{
33 struct matrix_keymap_data *kd;
34 u32 *keymap;
35 int proplen, i;
36 const __be32 *prop;
37
38 if (!np)
39 return NULL;
40
41 if (!propname)
42 propname = "linux,keymap";
43
44 prop = of_get_property(np, propname, &proplen);
45 if (!prop)
46 return NULL;
47
48 if (proplen % sizeof(u32)) {
49 pr_warn("Malformed keymap property %s in %s\n",
50 propname, np->full_name);
51 return NULL;
52 }
53
54 kd = kzalloc(sizeof(*kd), GFP_KERNEL);
55 if (!kd)
56 return NULL;
57
58 kd->keymap = keymap = kzalloc(proplen, GFP_KERNEL);
59 if (!kd->keymap) {
60 kfree(kd);
61 return NULL;
62 }
63
64 kd->keymap_size = proplen / sizeof(u32);
65
66 for (i = 0; i < kd->keymap_size; i++) {
67 u32 tmp = be32_to_cpup(prop + i);
68 int key_code, row, col;
69
70 row = (tmp >> 24) & 0xff;
71 col = (tmp >> 16) & 0xff;
72 key_code = tmp & 0xffff;
73 keymap[i] = KEY(row, col, key_code);
74 }
75
76 return kd;
77}
78EXPORT_SYMBOL_GPL(matrix_keyboard_of_fill_keymap);
79
80void matrix_keyboard_of_free_keymap(const struct matrix_keymap_data *kd)
81{
82 if (kd) {
83 kfree(kd->keymap);
84 kfree(kd);
85 }
86}
87EXPORT_SYMBOL_GPL(matrix_keyboard_of_free_keymap);
diff --git a/include/linux/input/matrix_keypad.h b/include/linux/input/matrix_keypad.h
index fe7c4b9ae270..6c07ced0af81 100644
--- a/include/linux/input/matrix_keypad.h
+++ b/include/linux/input/matrix_keypad.h
@@ -3,6 +3,7 @@
3 3
4#include <linux/types.h> 4#include <linux/types.h>
5#include <linux/input.h> 5#include <linux/input.h>
6#include <linux/of.h>
6 7
7#define MATRIX_MAX_ROWS 32 8#define MATRIX_MAX_ROWS 32
8#define MATRIX_MAX_COLS 32 9#define MATRIX_MAX_COLS 32
@@ -106,4 +107,22 @@ matrix_keypad_build_keymap(const struct matrix_keymap_data *keymap_data,
106 __clear_bit(KEY_RESERVED, keybit); 107 __clear_bit(KEY_RESERVED, keybit);
107} 108}
108 109
110#ifdef CONFIG_INPUT_OF_MATRIX_KEYMAP
111struct matrix_keymap_data *
112matrix_keyboard_of_fill_keymap(struct device_node *np, const char *propname);
113
114void matrix_keyboard_of_free_keymap(const struct matrix_keymap_data *kd);
115#else
116static inline struct matrix_keymap_data *
117matrix_keyboard_of_fill_keymap(struct device_node *np, const char *propname)
118{
119 return NULL;
120}
121
122static inline void
123matrix_keyboard_of_free_keymap(const struct matrix_keymap_data *kd)
124{
125}
126#endif
127
109#endif /* _MATRIX_KEYPAD_H */ 128#endif /* _MATRIX_KEYPAD_H */