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>
master
Simon Glass 7 years ago
parent 2dd57f5e47
commit 8327d41b19
  1. 24
      drivers/input/cros_ec_keyb.c
  2. 19
      drivers/input/key_matrix.c
  3. 3
      drivers/input/tegra-kbc.c
  4. 3
      include/key_matrix.h

@ -10,7 +10,6 @@
#include <cros_ec.h> #include <cros_ec.h>
#include <dm.h> #include <dm.h>
#include <errno.h> #include <errno.h>
#include <fdtdec.h>
#include <input.h> #include <input.h>
#include <keyboard.h> #include <keyboard.h>
#include <key_matrix.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 * @param config Configuration data read from fdt
* @return 0 if ok, -1 on error * @return 0 if ok, -1 on error
*/ */
static int cros_ec_keyb_decode_fdt(const void *blob, int node, static int cros_ec_keyb_decode_fdt(struct udevice *dev,
struct cros_ec_keyb_priv *config) struct cros_ec_keyb_priv *config)
{ {
/* /*
* Get keyboard rows and columns - at present we are limited to * Get keyboard rows and columns - at present we are limited to
* 8 columns by the protocol (one byte per row scan) * 8 columns by the protocol (one byte per row scan)
*/ */
config->key_rows = fdtdec_get_int(blob, node, "keypad,num-rows", 0); config->key_rows = dev_read_u32_default(dev, "keypad,num-rows", 0);
config->key_cols = fdtdec_get_int(blob, node, "keypad,num-columns", 0); config->key_cols = dev_read_u32_default(dev, "keypad,num-columns", 0);
if (!config->key_rows || !config->key_cols || if (!config->key_rows || !config->key_cols ||
config->key_rows * config->key_cols / 8 config->key_rows * config->key_cols / 8
> CROS_EC_KEYSCAN_COLS) { > 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); config->key_rows, config->key_cols);
return -1; return -1;
} }
config->ghost_filter = fdtdec_get_bool(blob, node, config->ghost_filter = dev_read_bool(dev, "google,needs-ghost-filter");
"google,needs-ghost-filter");
return 0; 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 keyboard_priv *uc_priv = dev_get_uclass_priv(dev);
struct stdio_dev *sdev = &uc_priv->sdev; struct stdio_dev *sdev = &uc_priv->sdev;
struct input_config *input = &uc_priv->input; struct input_config *input = &uc_priv->input;
const void *blob = gd->fdt_blob;
int node = dev_of_offset(dev);
int ret; int ret;
if (cros_ec_keyb_decode_fdt(blob, node, priv)) ret = cros_ec_keyb_decode_fdt(dev, priv);
return -1; 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); input_set_delays(input, KBC_REPEAT_DELAY_MS, KBC_REPEAT_RATE_MS);
ret = key_matrix_init(&priv->matrix, priv->key_rows, priv->key_cols, ret = key_matrix_init(&priv->matrix, priv->key_rows, priv->key_cols,
priv->ghost_filter); priv->ghost_filter);
@ -201,7 +201,7 @@ static int cros_ec_kbd_probe(struct udevice *dev)
debug("%s: cannot init key matrix\n", __func__); debug("%s: cannot init key matrix\n", __func__);
return ret; return ret;
} }
ret = key_matrix_decode_fdt(&priv->matrix, gd->fdt_blob, node); ret = key_matrix_decode_fdt(dev, &priv->matrix);
if (ret) { if (ret) {
debug("%s: Could not decode key matrix from fdt\n", __func__); debug("%s: Could not decode key matrix from fdt\n", __func__);
return ret; return ret;

@ -8,7 +8,7 @@
*/ */
#include <common.h> #include <common.h>
#include <fdtdec.h> #include <dm.h>
#include <key_matrix.h> #include <key_matrix.h>
#include <malloc.h> #include <malloc.h>
#include <linux/input.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 * @param pos Returns position of map_keycode, if found, else -1
* @return map Pointer to allocated map * @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) int map_keycode, int *pos)
{ {
uchar *map; uchar *map;
@ -138,33 +138,32 @@ static uchar *create_keymap(struct key_matrix *config, u32 *data, int len,
return map; 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; int proplen;
uchar *plain_keycode; uchar *plain_keycode;
prop = fdt_get_property(blob, node, "linux,keymap", &proplen); prop = dev_read_prop(dev, "linux,keymap", &proplen);
/* Basic keymap is required */ /* Basic keymap is required */
if (!prop) { if (!prop) {
debug("%s: cannot find keycode-plain map\n", __func__); debug("%s: cannot find keycode-plain map\n", __func__);
return -1; return -1;
} }
plain_keycode = create_keymap(config, (u32 *)prop->data, plain_keycode = create_keymap(config, prop, proplen, KEY_FN,
proplen, KEY_FN, &config->fn_pos); &config->fn_pos);
config->plain_keycode = plain_keycode; config->plain_keycode = plain_keycode;
/* Conversion error -> fail */ /* Conversion error -> fail */
if (!config->plain_keycode) if (!config->plain_keycode)
return -1; 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 */ /* fn keymap is optional */
if (!prop) if (!prop)
goto done; goto done;
config->fn_keycode = create_keymap(config, (u32 *)prop->data, config->fn_keycode = create_keymap(config, prop, proplen, -1, NULL);
proplen, -1, NULL);
/* Conversion error -> fail */ /* Conversion error -> fail */
if (!config->fn_keycode) { if (!config->fn_keycode) {
free(plain_keycode); free(plain_keycode);

@ -290,7 +290,6 @@ static int tegra_kbd_probe(struct udevice *dev)
struct keyboard_priv *uc_priv = dev_get_uclass_priv(dev); struct keyboard_priv *uc_priv = dev_get_uclass_priv(dev);
struct stdio_dev *sdev = &uc_priv->sdev; struct stdio_dev *sdev = &uc_priv->sdev;
struct input_config *input = &uc_priv->input; struct input_config *input = &uc_priv->input;
int node = dev_of_offset(dev);
int ret; int ret;
priv->kbc = (struct kbc_tegra *)devfdt_get_addr(dev); 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); debug("%s: Could not init key matrix: %d\n", __func__, ret);
return ret; return ret;
} }
ret = key_matrix_decode_fdt(&priv->matrix, gd->fdt_blob, node); ret = key_matrix_decode_fdt(dev, &priv->matrix);
if (ret) { if (ret) {
debug("%s: Could not decode key matrix from fdt: %d\n", debug("%s: Could not decode key matrix from fdt: %d\n",
__func__, ret); __func__, ret);

@ -69,8 +69,7 @@ int key_matrix_decode(struct key_matrix *config, struct key_matrix_key *keys,
* @param node Node containing compatible data * @param node Node containing compatible data
* @return 0 if ok, -1 on error * @return 0 if ok, -1 on error
*/ */
int key_matrix_decode_fdt(struct key_matrix *config, const void *blob, int key_matrix_decode_fdt(struct udevice *dev, struct key_matrix *config);
int node);
/** /**
* Set up a new key matrix. * Set up a new key matrix.

Loading…
Cancel
Save