summaryrefslogtreecommitdiff
path: root/drivers/input/key_matrix.c
diff options
context:
space:
mode:
authorStephen Warren <swarren@nvidia.com>2013-05-23 12:09:57 +0000
committerTom Rini <trini@ti.com>2013-06-04 16:06:32 -0400
commitdf637fa6da6e0f6b1d14d84f1afdd729bc2e2d1a (patch)
tree91ba619c3a16d645dc12cf6d164952a2a303f4b7 /drivers/input/key_matrix.c
parente573617c092eb49da2d67443725d755fca3e8b74 (diff)
downloadu-boot-imx-df637fa6da6e0f6b1d14d84f1afdd729bc2e2d1a.zip
u-boot-imx-df637fa6da6e0f6b1d14d84f1afdd729bc2e2d1a.tar.gz
u-boot-imx-df637fa6da6e0f6b1d14d84f1afdd729bc2e2d1a.tar.bz2
input: simplify key_matrix_decode_fdt()
We know the exact property names that the code wants to process. Look these up directly with fdt_get_property(), rather than iterating over all properties within the node, and checking each property's name, in a convoluted fashion, against the expected name. Signed-off-by: Stephen Warren <swarren@nvidia.com>
Diffstat (limited to 'drivers/input/key_matrix.c')
-rw-r--r--drivers/input/key_matrix.c66
1 files changed, 26 insertions, 40 deletions
diff --git a/drivers/input/key_matrix.c b/drivers/input/key_matrix.c
index c8b048e..ea05c77 100644
--- a/drivers/input/key_matrix.c
+++ b/drivers/input/key_matrix.c
@@ -154,54 +154,40 @@ static uchar *create_keymap(struct key_matrix *config, u32 *data, int len,
return map;
}
-int key_matrix_decode_fdt(struct key_matrix *config, const void *blob,
- int node)
+int key_matrix_decode_fdt(struct key_matrix *config, const void *blob, int node)
{
const struct fdt_property *prop;
- static const char prefix[] = "linux,";
- int plen = sizeof(prefix) - 1;
- int offset;
-
- /* Check each property name for ones that we understand */
- for (offset = fdt_first_property_offset(blob, node);
- offset > 0;
- offset = fdt_next_property_offset(blob, offset)) {
- const char *name;
- int len;
-
- prop = fdt_get_property_by_offset(blob, offset, NULL);
- name = fdt_string(blob, fdt32_to_cpu(prop->nameoff));
- len = strlen(name);
-
- /* Name needs to match "1,<type>keymap" */
- debug("%s: property '%s'\n", __func__, name);
- if (strncmp(name, prefix, plen) ||
- len < plen + 6 ||
- strcmp(name + len - 6, "keymap"))
- continue;
+ int proplen;
+ uchar *plain_keycode;
- len -= plen + 6;
- if (len == 0) {
- config->plain_keycode = create_keymap(config,
- (u32 *)prop->data, fdt32_to_cpu(prop->len),
- KEY_FN, &config->fn_pos);
- } else if (0 == strncmp(name + plen, "fn-", len)) {
- config->fn_keycode = create_keymap(config,
- (u32 *)prop->data, fdt32_to_cpu(prop->len),
- -1, NULL);
- } else {
- debug("%s: unrecognised property '%s'\n", __func__,
- name);
- }
- }
- debug("%s: Decoded key maps %p, %p from fdt\n", __func__,
- config->plain_keycode, config->fn_keycode);
+ prop = fdt_get_property(blob, node, "linux,keymap", &proplen);
+ /* Basic keymap is required */
+ if (!prop)
+ return -1;
+ plain_keycode = create_keymap(config, (u32 *)prop->data,
+ proplen, KEY_FN, &config->fn_pos);
+ config->plain_keycode = plain_keycode;
+ /* Conversion error -> fail */
+ if (!config->plain_keycode)
+ return -1;
+
+ prop = fdt_get_property(blob, node, "linux,fn-keymap", &proplen);
+ /* fn keymap is optional */
+ if (!prop)
+ goto done;
+
+ config->fn_keycode = create_keymap(config, (u32 *)prop->data,
+ proplen, -1, NULL);
+ /* Conversion error -> fail */
if (!config->plain_keycode) {
- debug("%s: cannot find keycode-plain map\n", __func__);
+ free(plain_keycode);
return -1;
}
+done:
+ debug("%s: Decoded key maps %p, %p from fdt\n", __func__,
+ config->plain_keycode, config->fn_keycode);
return 0;
}