aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/keyboard/stmpe-keypad.c
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2014-11-03 19:51:26 -0500
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2014-12-16 00:46:12 -0500
commita4164863e150c4991d2ac965e3fc52f9d8df3d7e (patch)
treeeb6c186935b028730a2c440cb10121b6089dbdba /drivers/input/keyboard/stmpe-keypad.c
parent80e1dd82be59d247e899d8ce29389f84ed828994 (diff)
Input: stmpe - enforce device tree only mode
The STMPE keypad controller is only used with device tree configured systems, so force the configuration to come from device tree only, and now actually get the rows and cols from the device tree too. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Acked-by: Lee Jones <lee.jones@linaro.org> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input/keyboard/stmpe-keypad.c')
-rw-r--r--drivers/input/keyboard/stmpe-keypad.c104
1 files changed, 45 insertions, 59 deletions
diff --git a/drivers/input/keyboard/stmpe-keypad.c b/drivers/input/keyboard/stmpe-keypad.c
index c6727dda68f2..8d1e7af3c5b1 100644
--- a/drivers/input/keyboard/stmpe-keypad.c
+++ b/drivers/input/keyboard/stmpe-keypad.c
@@ -45,7 +45,7 @@
45#define STMPE_KEYPAD_MAX_ROWS 8 45#define STMPE_KEYPAD_MAX_ROWS 8
46#define STMPE_KEYPAD_MAX_COLS 8 46#define STMPE_KEYPAD_MAX_COLS 8
47#define STMPE_KEYPAD_ROW_SHIFT 3 47#define STMPE_KEYPAD_ROW_SHIFT 3
48#define STMPE_KEYPAD_KEYMAP_SIZE \ 48#define STMPE_KEYPAD_KEYMAP_MAX_SIZE \
49 (STMPE_KEYPAD_MAX_ROWS * STMPE_KEYPAD_MAX_COLS) 49 (STMPE_KEYPAD_MAX_ROWS * STMPE_KEYPAD_MAX_COLS)
50 50
51/** 51/**
@@ -99,16 +99,30 @@ static const struct stmpe_keypad_variant stmpe_keypad_variants[] = {
99 }, 99 },
100}; 100};
101 101
102/**
103 * struct stmpe_keypad - STMPE keypad state container
104 * @stmpe: pointer to parent STMPE device
105 * @input: spawned input device
106 * @variant: STMPE variant
107 * @debounce_ms: debounce interval, in ms. Maximum is
108 * %STMPE_KEYPAD_MAX_DEBOUNCE.
109 * @scan_count: number of key scanning cycles to confirm key data.
110 * Maximum is %STMPE_KEYPAD_MAX_SCAN_COUNT.
111 * @no_autorepeat: disable key autorepeat
112 * @rows: bitmask for the rows
113 * @cols: bitmask for the columns
114 * @keymap: the keymap
115 */
102struct stmpe_keypad { 116struct stmpe_keypad {
103 struct stmpe *stmpe; 117 struct stmpe *stmpe;
104 struct input_dev *input; 118 struct input_dev *input;
105 const struct stmpe_keypad_variant *variant; 119 const struct stmpe_keypad_variant *variant;
106 const struct stmpe_keypad_platform_data *plat; 120 unsigned int debounce_ms;
107 121 unsigned int scan_count;
122 bool no_autorepeat;
108 unsigned int rows; 123 unsigned int rows;
109 unsigned int cols; 124 unsigned int cols;
110 125 unsigned short keymap[STMPE_KEYPAD_KEYMAP_MAX_SIZE];
111 unsigned short keymap[STMPE_KEYPAD_KEYMAP_SIZE];
112}; 126};
113 127
114static int stmpe_keypad_read_data(struct stmpe_keypad *keypad, u8 *data) 128static int stmpe_keypad_read_data(struct stmpe_keypad *keypad, u8 *data)
@@ -208,15 +222,14 @@ static int stmpe_keypad_altfunc_init(struct stmpe_keypad *keypad)
208 222
209static int stmpe_keypad_chip_init(struct stmpe_keypad *keypad) 223static int stmpe_keypad_chip_init(struct stmpe_keypad *keypad)
210{ 224{
211 const struct stmpe_keypad_platform_data *plat = keypad->plat;
212 const struct stmpe_keypad_variant *variant = keypad->variant; 225 const struct stmpe_keypad_variant *variant = keypad->variant;
213 struct stmpe *stmpe = keypad->stmpe; 226 struct stmpe *stmpe = keypad->stmpe;
214 int ret; 227 int ret;
215 228
216 if (plat->debounce_ms > STMPE_KEYPAD_MAX_DEBOUNCE) 229 if (keypad->debounce_ms > STMPE_KEYPAD_MAX_DEBOUNCE)
217 return -EINVAL; 230 return -EINVAL;
218 231
219 if (plat->scan_count > STMPE_KEYPAD_MAX_SCAN_COUNT) 232 if (keypad->scan_count > STMPE_KEYPAD_MAX_SCAN_COUNT)
220 return -EINVAL; 233 return -EINVAL;
221 234
222 ret = stmpe_enable(stmpe, STMPE_BLOCK_KEYPAD); 235 ret = stmpe_enable(stmpe, STMPE_BLOCK_KEYPAD);
@@ -245,7 +258,7 @@ static int stmpe_keypad_chip_init(struct stmpe_keypad *keypad)
245 258
246 ret = stmpe_set_bits(stmpe, STMPE_KPC_CTRL_MSB, 259 ret = stmpe_set_bits(stmpe, STMPE_KPC_CTRL_MSB,
247 STMPE_KPC_CTRL_MSB_SCAN_COUNT, 260 STMPE_KPC_CTRL_MSB_SCAN_COUNT,
248 plat->scan_count << 4); 261 keypad->scan_count << 4);
249 if (ret < 0) 262 if (ret < 0)
250 return ret; 263 return ret;
251 264
@@ -253,17 +266,18 @@ static int stmpe_keypad_chip_init(struct stmpe_keypad *keypad)
253 STMPE_KPC_CTRL_LSB_SCAN | 266 STMPE_KPC_CTRL_LSB_SCAN |
254 STMPE_KPC_CTRL_LSB_DEBOUNCE, 267 STMPE_KPC_CTRL_LSB_DEBOUNCE,
255 STMPE_KPC_CTRL_LSB_SCAN | 268 STMPE_KPC_CTRL_LSB_SCAN |
256 (plat->debounce_ms << 1)); 269 (keypad->debounce_ms << 1));
257} 270}
258 271
259static void stmpe_keypad_fill_used_pins(struct stmpe_keypad *keypad) 272static void stmpe_keypad_fill_used_pins(struct stmpe_keypad *keypad,
273 u32 used_rows, u32 used_cols)
260{ 274{
261 int row, col; 275 int row, col;
262 276
263 for (row = 0; row < STMPE_KEYPAD_MAX_ROWS; row++) { 277 for (row = 0; row < used_rows; row++) {
264 for (col = 0; col < STMPE_KEYPAD_MAX_COLS; col++) { 278 for (col = 0; col < used_cols; col++) {
265 int code = MATRIX_SCAN_CODE(row, col, 279 int code = MATRIX_SCAN_CODE(row, col,
266 STMPE_KEYPAD_ROW_SHIFT); 280 STMPE_KEYPAD_ROW_SHIFT);
267 if (keypad->keymap[code] != KEY_RESERVED) { 281 if (keypad->keymap[code] != KEY_RESERVED) {
268 keypad->rows |= 1 << row; 282 keypad->rows |= 1 << row;
269 keypad->cols |= 1 << col; 283 keypad->cols |= 1 << col;
@@ -272,51 +286,17 @@ static void stmpe_keypad_fill_used_pins(struct stmpe_keypad *keypad)
272 } 286 }
273} 287}
274 288
275#ifdef CONFIG_OF
276static const struct stmpe_keypad_platform_data *
277stmpe_keypad_of_probe(struct device *dev)
278{
279 struct device_node *np = dev->of_node;
280 struct stmpe_keypad_platform_data *plat;
281
282 if (!np)
283 return ERR_PTR(-ENODEV);
284
285 plat = devm_kzalloc(dev, sizeof(*plat), GFP_KERNEL);
286 if (!plat)
287 return ERR_PTR(-ENOMEM);
288
289 of_property_read_u32(np, "debounce-interval", &plat->debounce_ms);
290 of_property_read_u32(np, "st,scan-count", &plat->scan_count);
291
292 plat->no_autorepeat = of_property_read_bool(np, "st,no-autorepeat");
293
294 return plat;
295}
296#else
297static inline const struct stmpe_keypad_platform_data *
298stmpe_keypad_of_probe(struct device *dev)
299{
300 return ERR_PTR(-EINVAL);
301}
302#endif
303
304static int stmpe_keypad_probe(struct platform_device *pdev) 289static int stmpe_keypad_probe(struct platform_device *pdev)
305{ 290{
306 struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent); 291 struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent);
307 const struct stmpe_keypad_platform_data *plat; 292 struct device_node *np = pdev->dev.of_node;
308 struct stmpe_keypad *keypad; 293 struct stmpe_keypad *keypad;
309 struct input_dev *input; 294 struct input_dev *input;
295 u32 rows;
296 u32 cols;
310 int error; 297 int error;
311 int irq; 298 int irq;
312 299
313 plat = stmpe->pdata->keypad;
314 if (!plat) {
315 plat = stmpe_keypad_of_probe(&pdev->dev);
316 if (IS_ERR(plat))
317 return PTR_ERR(plat);
318 }
319
320 irq = platform_get_irq(pdev, 0); 300 irq = platform_get_irq(pdev, 0);
321 if (irq < 0) 301 if (irq < 0)
322 return irq; 302 return irq;
@@ -326,6 +306,13 @@ static int stmpe_keypad_probe(struct platform_device *pdev)
326 if (!keypad) 306 if (!keypad)
327 return -ENOMEM; 307 return -ENOMEM;
328 308
309 keypad->stmpe = stmpe;
310 keypad->variant = &stmpe_keypad_variants[stmpe->partnum];
311
312 of_property_read_u32(np, "debounce-interval", &keypad->debounce_ms);
313 of_property_read_u32(np, "st,scan-count", &keypad->scan_count);
314 keypad->no_autorepeat = of_property_read_bool(np, "st,no-autorepeat");
315
329 input = devm_input_allocate_device(&pdev->dev); 316 input = devm_input_allocate_device(&pdev->dev);
330 if (!input) 317 if (!input)
331 return -ENOMEM; 318 return -ENOMEM;
@@ -334,23 +321,22 @@ static int stmpe_keypad_probe(struct platform_device *pdev)
334 input->id.bustype = BUS_I2C; 321 input->id.bustype = BUS_I2C;
335 input->dev.parent = &pdev->dev; 322 input->dev.parent = &pdev->dev;
336 323
337 error = matrix_keypad_build_keymap(plat->keymap_data, NULL, 324 error = matrix_keypad_parse_of_params(&pdev->dev, &rows, &cols);
338 STMPE_KEYPAD_MAX_ROWS, 325 if (error)
339 STMPE_KEYPAD_MAX_COLS, 326 return error;
327
328 error = matrix_keypad_build_keymap(NULL, NULL, rows, cols,
340 keypad->keymap, input); 329 keypad->keymap, input);
341 if (error) 330 if (error)
342 return error; 331 return error;
343 332
344 input_set_capability(input, EV_MSC, MSC_SCAN); 333 input_set_capability(input, EV_MSC, MSC_SCAN);
345 if (!plat->no_autorepeat) 334 if (!keypad->no_autorepeat)
346 __set_bit(EV_REP, input->evbit); 335 __set_bit(EV_REP, input->evbit);
347 336
348 stmpe_keypad_fill_used_pins(keypad); 337 stmpe_keypad_fill_used_pins(keypad, rows, cols);
349 338
350 keypad->stmpe = stmpe;
351 keypad->plat = plat;
352 keypad->input = input; 339 keypad->input = input;
353 keypad->variant = &stmpe_keypad_variants[stmpe->partnum];
354 340
355 error = stmpe_keypad_chip_init(keypad); 341 error = stmpe_keypad_chip_init(keypad);
356 if (error < 0) 342 if (error < 0)