USB: usb-storage: unusual_devs update for Super TOP SATA bridge
[linux/fpc-iii.git] / drivers / input / of_keymap.c
blob061493d57682d43a416d1d4344832d95ac0f7700
1 /*
2 * Helpers for open firmware matrix keyboard bindings
4 * Copyright (C) 2012 Google, Inc
6 * Author:
7 * Olof Johansson <olof@lixom.net>
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.
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.
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>
29 struct matrix_keymap_data *
30 matrix_keyboard_of_fill_keymap(struct device_node *np,
31 const char *propname)
33 struct matrix_keymap_data *kd;
34 u32 *keymap;
35 int proplen, i;
36 const __be32 *prop;
38 if (!np)
39 return NULL;
41 if (!propname)
42 propname = "linux,keymap";
44 prop = of_get_property(np, propname, &proplen);
45 if (!prop)
46 return NULL;
48 if (proplen % sizeof(u32)) {
49 pr_warn("Malformed keymap property %s in %s\n",
50 propname, np->full_name);
51 return NULL;
54 kd = kzalloc(sizeof(*kd), GFP_KERNEL);
55 if (!kd)
56 return NULL;
58 kd->keymap = keymap = kzalloc(proplen, GFP_KERNEL);
59 if (!kd->keymap) {
60 kfree(kd);
61 return NULL;
64 kd->keymap_size = proplen / sizeof(u32);
66 for (i = 0; i < kd->keymap_size; i++) {
67 u32 tmp = be32_to_cpup(prop + i);
68 int key_code, row, col;
70 row = (tmp >> 24) & 0xff;
71 col = (tmp >> 16) & 0xff;
72 key_code = tmp & 0xffff;
73 keymap[i] = KEY(row, col, key_code);
76 return kd;
78 EXPORT_SYMBOL_GPL(matrix_keyboard_of_fill_keymap);
80 void matrix_keyboard_of_free_keymap(const struct matrix_keymap_data *kd)
82 if (kd) {
83 kfree(kd->keymap);
84 kfree(kd);
87 EXPORT_SYMBOL_GPL(matrix_keyboard_of_free_keymap);