diff options
author | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2012-11-05 13:32:55 -0500 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2012-11-14 11:35:07 -0500 |
commit | 5383116b86d8e877684770d05acd1dda62be102d (patch) | |
tree | 11346ce080a0d35509d827b50994e832a30175c3 | |
parent | 544a46c917fcf0a439cc0c428d76ba731a380cae (diff) |
Input: marix-keymap - automatically allocate memory for keymap
In device tree enabled setups requiring preallocated memory for storing keymap
is quite often awkward, so let's provide an option of allocating it directly
in matrix_keypad_build_keymap().
Reviewed-by: Alban Bedel <alban.bedel@avionic-design.de>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
-rw-r--r-- | drivers/input/matrix-keymap.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/drivers/input/matrix-keymap.c b/drivers/input/matrix-keymap.c index 443ad64b7f2a..419cb6b88e2a 100644 --- a/drivers/input/matrix-keymap.c +++ b/drivers/input/matrix-keymap.c | |||
@@ -18,6 +18,7 @@ | |||
18 | */ | 18 | */ |
19 | 19 | ||
20 | #include <linux/device.h> | 20 | #include <linux/device.h> |
21 | #include <linux/gfp.h> | ||
21 | #include <linux/kernel.h> | 22 | #include <linux/kernel.h> |
22 | #include <linux/types.h> | 23 | #include <linux/types.h> |
23 | #include <linux/input.h> | 24 | #include <linux/input.h> |
@@ -122,6 +123,11 @@ static int matrix_keypad_parse_of_keymap(const char *propname, | |||
122 | * it will attempt load the keymap from property specified by @keymap_name | 123 | * it will attempt load the keymap from property specified by @keymap_name |
123 | * argument (or "linux,keymap" if @keymap_name is %NULL). | 124 | * argument (or "linux,keymap" if @keymap_name is %NULL). |
124 | * | 125 | * |
126 | * If @keymap is %NULL the function will automatically allocate managed | ||
127 | * block of memory to store the keymap. This memory will be associated with | ||
128 | * the parent device and automatically freed when device unbinds from the | ||
129 | * driver. | ||
130 | * | ||
125 | * Callers are expected to set up input_dev->dev.parent before calling this | 131 | * Callers are expected to set up input_dev->dev.parent before calling this |
126 | * function. | 132 | * function. |
127 | */ | 133 | */ |
@@ -132,12 +138,27 @@ int matrix_keypad_build_keymap(const struct matrix_keymap_data *keymap_data, | |||
132 | struct input_dev *input_dev) | 138 | struct input_dev *input_dev) |
133 | { | 139 | { |
134 | unsigned int row_shift = get_count_order(cols); | 140 | unsigned int row_shift = get_count_order(cols); |
141 | size_t max_keys = rows << row_shift; | ||
135 | int i; | 142 | int i; |
136 | int error; | 143 | int error; |
137 | 144 | ||
145 | if (WARN_ON(!input_dev->dev.parent)) | ||
146 | return -EINVAL; | ||
147 | |||
148 | if (!keymap) { | ||
149 | keymap = devm_kzalloc(input_dev->dev.parent, | ||
150 | max_keys * sizeof(*keymap), | ||
151 | GFP_KERNEL); | ||
152 | if (!keymap) { | ||
153 | dev_err(input_dev->dev.parent, | ||
154 | "Unable to allocate memory for keymap"); | ||
155 | return -ENOMEM; | ||
156 | } | ||
157 | } | ||
158 | |||
138 | input_dev->keycode = keymap; | 159 | input_dev->keycode = keymap; |
139 | input_dev->keycodesize = sizeof(*keymap); | 160 | input_dev->keycodesize = sizeof(*keymap); |
140 | input_dev->keycodemax = rows << row_shift; | 161 | input_dev->keycodemax = max_keys; |
141 | 162 | ||
142 | __set_bit(EV_KEY, input_dev->evbit); | 163 | __set_bit(EV_KEY, input_dev->evbit); |
143 | 164 | ||