Commit 8327d41b19af08a331c62954fafd685426e617f4

Authored by Simon Glass
1 parent 2dd57f5e47

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>

Showing 4 changed files with 23 additions and 26 deletions Side-by-side Diff

drivers/input/cros_ec_keyb.c
... ... @@ -10,7 +10,6 @@
10 10 #include <cros_ec.h>
11 11 #include <dm.h>
12 12 #include <errno.h>
13   -#include <fdtdec.h>
14 13 #include <input.h>
15 14 #include <keyboard.h>
16 15 #include <key_matrix.h>
17 16  
... ... @@ -161,15 +160,15 @@
161 160 * @param config Configuration data read from fdt
162 161 * @return 0 if ok, -1 on error
163 162 */
164   -static int cros_ec_keyb_decode_fdt(const void *blob, int node,
165   - struct cros_ec_keyb_priv *config)
  163 +static int cros_ec_keyb_decode_fdt(struct udevice *dev,
  164 + struct cros_ec_keyb_priv *config)
166 165 {
167 166 /*
168 167 * Get keyboard rows and columns - at present we are limited to
169 168 * 8 columns by the protocol (one byte per row scan)
170 169 */
171   - config->key_rows = fdtdec_get_int(blob, node, "keypad,num-rows", 0);
172   - config->key_cols = fdtdec_get_int(blob, node, "keypad,num-columns", 0);
  170 + config->key_rows = dev_read_u32_default(dev, "keypad,num-rows", 0);
  171 + config->key_cols = dev_read_u32_default(dev, "keypad,num-columns", 0);
173 172 if (!config->key_rows || !config->key_cols ||
174 173 config->key_rows * config->key_cols / 8
175 174 > CROS_EC_KEYSCAN_COLS) {
... ... @@ -177,8 +176,8 @@
177 176 config->key_rows, config->key_cols);
178 177 return -1;
179 178 }
180   - config->ghost_filter = fdtdec_get_bool(blob, node,
181   - "google,needs-ghost-filter");
  179 + config->ghost_filter = dev_read_bool(dev, "google,needs-ghost-filter");
  180 +
182 181 return 0;
183 182 }
184 183  
185 184  
... ... @@ -188,12 +187,13 @@
188 187 struct keyboard_priv *uc_priv = dev_get_uclass_priv(dev);
189 188 struct stdio_dev *sdev = &uc_priv->sdev;
190 189 struct input_config *input = &uc_priv->input;
191   - const void *blob = gd->fdt_blob;
192   - int node = dev_of_offset(dev);
193 190 int ret;
194 191  
195   - if (cros_ec_keyb_decode_fdt(blob, node, priv))
196   - return -1;
  192 + ret = cros_ec_keyb_decode_fdt(dev, priv);
  193 + if (ret) {
  194 + debug("%s: Cannot decode node (ret=%d)\n", __func__, ret);
  195 + return -EINVAL;
  196 + }
197 197 input_set_delays(input, KBC_REPEAT_DELAY_MS, KBC_REPEAT_RATE_MS);
198 198 ret = key_matrix_init(&priv->matrix, priv->key_rows, priv->key_cols,
199 199 priv->ghost_filter);
... ... @@ -201,7 +201,7 @@
201 201 debug("%s: cannot init key matrix\n", __func__);
202 202 return ret;
203 203 }
204   - ret = key_matrix_decode_fdt(&priv->matrix, gd->fdt_blob, node);
  204 + ret = key_matrix_decode_fdt(dev, &priv->matrix);
205 205 if (ret) {
206 206 debug("%s: Could not decode key matrix from fdt\n", __func__);
207 207 return ret;
drivers/input/key_matrix.c
... ... @@ -8,7 +8,7 @@
8 8 */
9 9  
10 10 #include <common.h>
11   -#include <fdtdec.h>
  11 +#include <dm.h>
12 12 #include <key_matrix.h>
13 13 #include <malloc.h>
14 14 #include <linux/input.h>
... ... @@ -105,7 +105,7 @@
105 105 * @param pos Returns position of map_keycode, if found, else -1
106 106 * @return map Pointer to allocated map
107 107 */
108   -static uchar *create_keymap(struct key_matrix *config, u32 *data, int len,
  108 +static uchar *create_keymap(struct key_matrix *config, const u32 *data, int len,
109 109 int map_keycode, int *pos)
110 110 {
111 111 uchar *map;
112 112  
113 113  
114 114  
115 115  
116 116  
... ... @@ -138,33 +138,32 @@
138 138 return map;
139 139 }
140 140  
141   -int key_matrix_decode_fdt(struct key_matrix *config, const void *blob, int node)
  141 +int key_matrix_decode_fdt(struct udevice *dev, struct key_matrix *config)
142 142 {
143   - const struct fdt_property *prop;
  143 + const u32 *prop;
144 144 int proplen;
145 145 uchar *plain_keycode;
146 146  
147   - prop = fdt_get_property(blob, node, "linux,keymap", &proplen);
  147 + prop = dev_read_prop(dev, "linux,keymap", &proplen);
148 148 /* Basic keymap is required */
149 149 if (!prop) {
150 150 debug("%s: cannot find keycode-plain map\n", __func__);
151 151 return -1;
152 152 }
153 153  
154   - plain_keycode = create_keymap(config, (u32 *)prop->data,
155   - proplen, KEY_FN, &config->fn_pos);
  154 + plain_keycode = create_keymap(config, prop, proplen, KEY_FN,
  155 + &config->fn_pos);
156 156 config->plain_keycode = plain_keycode;
157 157 /* Conversion error -> fail */
158 158 if (!config->plain_keycode)
159 159 return -1;
160 160  
161   - prop = fdt_get_property(blob, node, "linux,fn-keymap", &proplen);
  161 + prop = dev_read_prop(dev, "linux,fn-keymap", &proplen);
162 162 /* fn keymap is optional */
163 163 if (!prop)
164 164 goto done;
165 165  
166   - config->fn_keycode = create_keymap(config, (u32 *)prop->data,
167   - proplen, -1, NULL);
  166 + config->fn_keycode = create_keymap(config, prop, proplen, -1, NULL);
168 167 /* Conversion error -> fail */
169 168 if (!config->fn_keycode) {
170 169 free(plain_keycode);
drivers/input/tegra-kbc.c
... ... @@ -290,7 +290,6 @@
290 290 struct keyboard_priv *uc_priv = dev_get_uclass_priv(dev);
291 291 struct stdio_dev *sdev = &uc_priv->sdev;
292 292 struct input_config *input = &uc_priv->input;
293   - int node = dev_of_offset(dev);
294 293 int ret;
295 294  
296 295 priv->kbc = (struct kbc_tegra *)devfdt_get_addr(dev);
... ... @@ -306,7 +305,7 @@
306 305 debug("%s: Could not init key matrix: %d\n", __func__, ret);
307 306 return ret;
308 307 }
309   - ret = key_matrix_decode_fdt(&priv->matrix, gd->fdt_blob, node);
  308 + ret = key_matrix_decode_fdt(dev, &priv->matrix);
310 309 if (ret) {
311 310 debug("%s: Could not decode key matrix from fdt: %d\n",
312 311 __func__, ret);
include/key_matrix.h
... ... @@ -69,8 +69,7 @@
69 69 * @param node Node containing compatible data
70 70 * @return 0 if ok, -1 on error
71 71 */
72   -int key_matrix_decode_fdt(struct key_matrix *config, const void *blob,
73   - int node);
  72 +int key_matrix_decode_fdt(struct udevice *dev, struct key_matrix *config);
74 73  
75 74 /**
76 75 * Set up a new key matrix.