cros_ec: Update the cros_ec keyboard driver to livetree
Update this driver and key_matrix to support a live device tree.
Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/drivers/input/cros_ec_keyb.c b/drivers/input/cros_ec_keyb.c
index 00381dc..6fa35a6 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 @@
* @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 @@
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 @@
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 @@
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 8867e49..cd5bce3 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 @@
* @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 @@
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 836aba1..cb56957 100644
--- a/drivers/input/tegra-kbc.c
+++ b/drivers/input/tegra-kbc.c
@@ -290,7 +290,6 @@
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 @@
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);