[U-Boot] [PATCH v3 63/72] cros_ec: Update the cros_ec keyboard driver to livetree
Simon Glass
sjg at chromium.org
Fri May 19 02:09:53 UTC 2017
Update this driver and key_matrix to support a live device tree.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
Changes in v3: None
Changes in v2: None
drivers/input/cros_ec_keyb.c | 24 ++++++++++++------------
drivers/input/key_matrix.c | 19 +++++++++----------
drivers/input/tegra-kbc.c | 3 +--
include/key_matrix.h | 3 +--
4 files changed, 23 insertions(+), 26 deletions(-)
diff --git a/drivers/input/cros_ec_keyb.c b/drivers/input/cros_ec_keyb.c
index 00381dcd72..6fa35a63dd 100644
--- a/drivers/input/cros_ec_keyb.c
+++ b/drivers/input/cros_ec_keyb.c
@@ -10,7 +10,6 @@
#include <cros_ec.h>
#include <dm.h>
#include <errno.h>
-#include <fdtdec.h>
#include <input.h>
#include <keyboard.h>
#include <key_matrix.h>
@@ -161,15 +160,15 @@ int cros_ec_kbc_check(struct input_config *input)
* @param config Configuration data read from fdt
* @return 0 if ok, -1 on error
*/
-static int cros_ec_keyb_decode_fdt(const void *blob, int node,
- struct cros_ec_keyb_priv *config)
+static int cros_ec_keyb_decode_fdt(struct udevice *dev,
+ struct cros_ec_keyb_priv *config)
{
/*
* Get keyboard rows and columns - at present we are limited to
* 8 columns by the protocol (one byte per row scan)
*/
- config->key_rows = fdtdec_get_int(blob, node, "keypad,num-rows", 0);
- config->key_cols = fdtdec_get_int(blob, node, "keypad,num-columns", 0);
+ config->key_rows = dev_read_u32_default(dev, "keypad,num-rows", 0);
+ config->key_cols = dev_read_u32_default(dev, "keypad,num-columns", 0);
if (!config->key_rows || !config->key_cols ||
config->key_rows * config->key_cols / 8
> CROS_EC_KEYSCAN_COLS) {
@@ -177,8 +176,8 @@ static int cros_ec_keyb_decode_fdt(const void *blob, int node,
config->key_rows, config->key_cols);
return -1;
}
- config->ghost_filter = fdtdec_get_bool(blob, node,
- "google,needs-ghost-filter");
+ config->ghost_filter = dev_read_bool(dev, "google,needs-ghost-filter");
+
return 0;
}
@@ -188,12 +187,13 @@ static int cros_ec_kbd_probe(struct udevice *dev)
struct keyboard_priv *uc_priv = dev_get_uclass_priv(dev);
struct stdio_dev *sdev = &uc_priv->sdev;
struct input_config *input = &uc_priv->input;
- const void *blob = gd->fdt_blob;
- int node = dev_of_offset(dev);
int ret;
- if (cros_ec_keyb_decode_fdt(blob, node, priv))
- return -1;
+ ret = cros_ec_keyb_decode_fdt(dev, priv);
+ if (ret) {
+ debug("%s: Cannot decode node (ret=%d)\n", __func__, ret);
+ return -EINVAL;
+ }
input_set_delays(input, KBC_REPEAT_DELAY_MS, KBC_REPEAT_RATE_MS);
ret = key_matrix_init(&priv->matrix, priv->key_rows, priv->key_cols,
priv->ghost_filter);
@@ -201,7 +201,7 @@ static int cros_ec_kbd_probe(struct udevice *dev)
debug("%s: cannot init key matrix\n", __func__);
return ret;
}
- ret = key_matrix_decode_fdt(&priv->matrix, gd->fdt_blob, node);
+ ret = key_matrix_decode_fdt(dev, &priv->matrix);
if (ret) {
debug("%s: Could not decode key matrix from fdt\n", __func__);
return ret;
diff --git a/drivers/input/key_matrix.c b/drivers/input/key_matrix.c
index 8867e4964e..cd5bce3613 100644
--- a/drivers/input/key_matrix.c
+++ b/drivers/input/key_matrix.c
@@ -8,7 +8,7 @@
*/
#include <common.h>
-#include <fdtdec.h>
+#include <dm.h>
#include <key_matrix.h>
#include <malloc.h>
#include <linux/input.h>
@@ -105,7 +105,7 @@ int key_matrix_decode(struct key_matrix *config, struct key_matrix_key keys[],
* @param pos Returns position of map_keycode, if found, else -1
* @return map Pointer to allocated map
*/
-static uchar *create_keymap(struct key_matrix *config, u32 *data, int len,
+static uchar *create_keymap(struct key_matrix *config, const u32 *data, int len,
int map_keycode, int *pos)
{
uchar *map;
@@ -138,33 +138,32 @@ 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 udevice *dev, struct key_matrix *config)
{
- const struct fdt_property *prop;
+ const u32 *prop;
int proplen;
uchar *plain_keycode;
- prop = fdt_get_property(blob, node, "linux,keymap", &proplen);
+ prop = dev_read_prop(dev, "linux,keymap", &proplen);
/* Basic keymap is required */
if (!prop) {
debug("%s: cannot find keycode-plain map\n", __func__);
return -1;
}
- plain_keycode = create_keymap(config, (u32 *)prop->data,
- proplen, KEY_FN, &config->fn_pos);
+ plain_keycode = create_keymap(config, prop, 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);
+ prop = dev_read_prop(dev, "linux,fn-keymap", &proplen);
/* fn keymap is optional */
if (!prop)
goto done;
- config->fn_keycode = create_keymap(config, (u32 *)prop->data,
- proplen, -1, NULL);
+ config->fn_keycode = create_keymap(config, prop, proplen, -1, NULL);
/* Conversion error -> fail */
if (!config->fn_keycode) {
free(plain_keycode);
diff --git a/drivers/input/tegra-kbc.c b/drivers/input/tegra-kbc.c
index 836aba1f1b..cb5695784e 100644
--- a/drivers/input/tegra-kbc.c
+++ b/drivers/input/tegra-kbc.c
@@ -290,7 +290,6 @@ static int tegra_kbd_probe(struct udevice *dev)
struct keyboard_priv *uc_priv = dev_get_uclass_priv(dev);
struct stdio_dev *sdev = &uc_priv->sdev;
struct input_config *input = &uc_priv->input;
- int node = dev_of_offset(dev);
int ret;
priv->kbc = (struct kbc_tegra *)devfdt_get_addr(dev);
@@ -306,7 +305,7 @@ static int tegra_kbd_probe(struct udevice *dev)
debug("%s: Could not init key matrix: %d\n", __func__, ret);
return ret;
}
- ret = key_matrix_decode_fdt(&priv->matrix, gd->fdt_blob, node);
+ ret = key_matrix_decode_fdt(dev, &priv->matrix);
if (ret) {
debug("%s: Could not decode key matrix from fdt: %d\n",
__func__, ret);
diff --git a/include/key_matrix.h b/include/key_matrix.h
index 8db686040d..8dfa44de13 100644
--- a/include/key_matrix.h
+++ b/include/key_matrix.h
@@ -69,8 +69,7 @@ int key_matrix_decode(struct key_matrix *config, struct key_matrix_key *keys,
* @param node Node containing compatible data
* @return 0 if ok, -1 on error
*/
-int key_matrix_decode_fdt(struct key_matrix *config, const void *blob,
- int node);
+int key_matrix_decode_fdt(struct udevice *dev, struct key_matrix *config);
/**
* Set up a new key matrix.
--
2.13.0.303.g4ebf302169-goog
More information about the U-Boot
mailing list