Skip to content

Commit 1932811

Browse files
committed
Input: matrix-keymap - uninline and prepare for device tree support
Change matrix-keymap helper to be out-of-line, like sparse keymap, allow the helper perform basic keymap validation and return errors, and prepare for device tree support. Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
1 parent d0a3457 commit 1932811

22 files changed

+265
-209
lines changed

drivers/input/Kconfig

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ config INPUT
2525

2626
if INPUT
2727

28-
config INPUT_OF_MATRIX_KEYMAP
29-
depends on USE_OF
30-
bool
31-
3228
config INPUT_FF_MEMLESS
3329
tristate "Support for memoryless force-feedback devices"
3430
help
@@ -68,6 +64,19 @@ config INPUT_SPARSEKMAP
6864
To compile this driver as a module, choose M here: the
6965
module will be called sparse-keymap.
7066

67+
config INPUT_MATRIXKMAP
68+
tristate "Matrix keymap support library"
69+
help
70+
Say Y here if you are using a driver for an input
71+
device that uses matrix keymap. This option is only
72+
useful for out-of-tree drivers since in-tree drivers
73+
select it automatically.
74+
75+
If unsure, say N.
76+
77+
To compile this driver as a module, choose M here: the
78+
module will be called matrix-keymap.
79+
7180
comment "Userland interfaces"
7281

7382
config INPUT_MOUSEDEV

drivers/input/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ input-core-y := input.o input-compat.o input-mt.o ff-core.o
1010
obj-$(CONFIG_INPUT_FF_MEMLESS) += ff-memless.o
1111
obj-$(CONFIG_INPUT_POLLDEV) += input-polldev.o
1212
obj-$(CONFIG_INPUT_SPARSEKMAP) += sparse-keymap.o
13+
obj-$(CONFIG_INPUT_MATRIXKMAP) += matrix-keymap.o
1314

1415
obj-$(CONFIG_INPUT_MOUSEDEV) += mousedev.o
1516
obj-$(CONFIG_INPUT_JOYDEV) += joydev.o
@@ -24,4 +25,3 @@ obj-$(CONFIG_INPUT_TOUCHSCREEN) += touchscreen/
2425
obj-$(CONFIG_INPUT_MISC) += misc/
2526

2627
obj-$(CONFIG_INPUT_APMPOWER) += apm-power.o
27-
obj-$(CONFIG_INPUT_OF_MATRIX_KEYMAP) += of_keymap.o

drivers/input/keyboard/Kconfig

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ config KEYBOARD_LKKBD
166166
config KEYBOARD_EP93XX
167167
tristate "EP93xx Matrix Keypad support"
168168
depends on ARCH_EP93XX
169+
select INPUT_MATRIXKMAP
169170
help
170171
Say Y here to enable the matrix keypad on the Cirrus EP93XX.
171172

@@ -224,6 +225,7 @@ config KEYBOARD_TCA6416
224225
config KEYBOARD_TCA8418
225226
tristate "TCA8418 Keypad Support"
226227
depends on I2C
228+
select INPUT_MATRIXKMAP
227229
help
228230
This driver implements basic keypad functionality
229231
for keys connected through TCA8418 keypad decoder.
@@ -240,6 +242,7 @@ config KEYBOARD_TCA8418
240242
config KEYBOARD_MATRIX
241243
tristate "GPIO driven matrix keypad support"
242244
depends on GENERIC_GPIO
245+
select INPUT_MATRIXKMAP
243246
help
244247
Enable support for GPIO driven matrix keypad.
245248

@@ -312,6 +315,7 @@ config KEYBOARD_LM8323
312315
config KEYBOARD_LM8333
313316
tristate "LM8333 keypad chip"
314317
depends on I2C
318+
select INPUT_MATRIXKMAP
315319
help
316320
If you say yes here you get support for the National Semiconductor
317321
LM8333 keypad controller.
@@ -376,6 +380,7 @@ config KEYBOARD_MPR121
376380
config KEYBOARD_IMX
377381
tristate "IMX keypad support"
378382
depends on ARCH_MXC
383+
select INPUT_MATRIXKMAP
379384
help
380385
Enable support for IMX keypad port.
381386

@@ -394,6 +399,7 @@ config KEYBOARD_NEWTON
394399
config KEYBOARD_NOMADIK
395400
tristate "ST-Ericsson Nomadik SKE keyboard"
396401
depends on PLAT_NOMADIK
402+
select INPUT_MATRIXKMAP
397403
help
398404
Say Y here if you want to use a keypad provided on the SKE controller
399405
used on the Ux500 and Nomadik platforms
@@ -404,7 +410,7 @@ config KEYBOARD_NOMADIK
404410
config KEYBOARD_TEGRA
405411
tristate "NVIDIA Tegra internal matrix keyboard controller support"
406412
depends on ARCH_TEGRA
407-
select INPUT_OF_MATRIX_KEYMAP if USE_OF
413+
select INPUT_MATRIXKMAP
408414
help
409415
Say Y here if you want to use a matrix keyboard connected directly
410416
to the internal keyboard controller on Tegra SoCs.
@@ -442,6 +448,7 @@ config KEYBOARD_PXA930_ROTARY
442448
config KEYBOARD_PMIC8XXX
443449
tristate "Qualcomm PMIC8XXX keypad support"
444450
depends on MFD_PM8XXX
451+
select INPUT_MATRIXKMAP
445452
help
446453
Say Y here if you want to enable the driver for the PMIC8XXX
447454
keypad provided as a reference design from Qualcomm. This is intended
@@ -453,6 +460,7 @@ config KEYBOARD_PMIC8XXX
453460
config KEYBOARD_SAMSUNG
454461
tristate "Samsung keypad support"
455462
depends on HAVE_CLK
463+
select INPUT_MATRIXKMAP
456464
help
457465
Say Y here if you want to use the keypad on your Samsung mobile
458466
device.
@@ -495,6 +503,7 @@ config KEYBOARD_SH_KEYSC
495503
config KEYBOARD_STMPE
496504
tristate "STMPE keypad support"
497505
depends on MFD_STMPE
506+
select INPUT_MATRIXKMAP
498507
help
499508
Say Y here if you want to use the keypad controller on STMPE I/O
500509
expanders.
@@ -515,6 +524,7 @@ config KEYBOARD_DAVINCI
515524
config KEYBOARD_OMAP
516525
tristate "TI OMAP keypad support"
517526
depends on (ARCH_OMAP1 || ARCH_OMAP2)
527+
select INPUT_MATRIXKMAP
518528
help
519529
Say Y here if you want to use the OMAP keypad.
520530

@@ -523,6 +533,7 @@ config KEYBOARD_OMAP
523533

524534
config KEYBOARD_OMAP4
525535
tristate "TI OMAP4+ keypad support"
536+
select INPUT_MATRIXKMAP
526537
help
527538
Say Y here if you want to use the OMAP4+ keypad.
528539

@@ -532,6 +543,7 @@ config KEYBOARD_OMAP4
532543
config KEYBOARD_SPEAR
533544
tristate "ST SPEAR keyboard support"
534545
depends on PLAT_SPEAR
546+
select INPUT_MATRIXKMAP
535547
help
536548
Say Y here if you want to use the SPEAR keyboard.
537549

@@ -541,6 +553,7 @@ config KEYBOARD_SPEAR
541553
config KEYBOARD_TC3589X
542554
tristate "TC3589X Keypad support"
543555
depends on MFD_TC3589X
556+
select INPUT_MATRIXKMAP
544557
help
545558
Say Y here if you want to use the keypad controller on
546559
TC35892/3 I/O expander.
@@ -551,6 +564,7 @@ config KEYBOARD_TC3589X
551564
config KEYBOARD_TNETV107X
552565
tristate "TI TNETV107X keypad support"
553566
depends on ARCH_DAVINCI_TNETV107X
567+
select INPUT_MATRIXKMAP
554568
help
555569
Say Y here if you want to use the TNETV107X keypad.
556570

@@ -560,6 +574,7 @@ config KEYBOARD_TNETV107X
560574
config KEYBOARD_TWL4030
561575
tristate "TI TWL4030/TWL5030/TPS659x0 keypad support"
562576
depends on TWL4030_CORE
577+
select INPUT_MATRIXKMAP
563578
help
564579
Say Y here if your board use the keypad controller on
565580
TWL4030 family chips. It's safe to say enable this
@@ -583,6 +598,7 @@ config KEYBOARD_XTKBD
583598
config KEYBOARD_W90P910
584599
tristate "W90P910 Matrix Keypad support"
585600
depends on ARCH_W90X900
601+
select INPUT_MATRIXKMAP
586602
help
587603
Say Y here to enable the matrix keypad on evaluation board
588604
based on W90P910.

drivers/input/keyboard/ep93xx_keypad.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -303,19 +303,16 @@ static int __devinit ep93xx_keypad_probe(struct platform_device *pdev)
303303
input_dev->open = ep93xx_keypad_open;
304304
input_dev->close = ep93xx_keypad_close;
305305
input_dev->dev.parent = &pdev->dev;
306-
input_dev->keycode = keypad->keycodes;
307-
input_dev->keycodesize = sizeof(keypad->keycodes[0]);
308-
input_dev->keycodemax = ARRAY_SIZE(keypad->keycodes);
309306

310-
input_set_drvdata(input_dev, keypad);
307+
err = matrix_keypad_build_keymap(keymap_data, NULL,
308+
EP93XX_MATRIX_ROWS, EP93XX_MATRIX_COLS,
309+
keypad->keycodes, input_dev);
310+
if (err)
311+
goto failed_free_dev;
311312

312-
input_dev->evbit[0] = BIT_MASK(EV_KEY);
313313
if (keypad->pdata->flags & EP93XX_KEYPAD_AUTOREPEAT)
314-
input_dev->evbit[0] |= BIT_MASK(EV_REP);
315-
316-
matrix_keypad_build_keymap(keymap_data, 3,
317-
input_dev->keycode, input_dev->keybit);
318-
platform_set_drvdata(pdev, keypad);
314+
__set_bit(EV_REP, input_dev->evbit);
315+
input_set_drvdata(input_dev, keypad);
319316

320317
err = request_irq(keypad->irq, ep93xx_keypad_irq_handler,
321318
0, pdev->name, keypad);
@@ -326,6 +323,7 @@ static int __devinit ep93xx_keypad_probe(struct platform_device *pdev)
326323
if (err)
327324
goto failed_free_irq;
328325

326+
platform_set_drvdata(pdev, keypad);
329327
device_init_wakeup(&pdev->dev, 1);
330328

331329
return 0;

drivers/input/keyboard/imx_keypad.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ static int __devinit imx_keypad_probe(struct platform_device *pdev)
481481
}
482482

483483
if (keypad->rows_en_mask > ((1 << MAX_MATRIX_KEY_ROWS) - 1) ||
484-
keypad->cols_en_mask > ((1 << MAX_MATRIX_KEY_COLS) - 1)) {
484+
keypad->cols_en_mask > ((1 << MAX_MATRIX_KEY_COLS) - 1)) {
485485
dev_err(&pdev->dev,
486486
"invalid key data (too many rows or colums)\n");
487487
error = -EINVAL;
@@ -496,14 +496,17 @@ static int __devinit imx_keypad_probe(struct platform_device *pdev)
496496
input_dev->dev.parent = &pdev->dev;
497497
input_dev->open = imx_keypad_open;
498498
input_dev->close = imx_keypad_close;
499-
input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
500-
input_dev->keycode = keypad->keycodes;
501-
input_dev->keycodesize = sizeof(keypad->keycodes[0]);
502-
input_dev->keycodemax = ARRAY_SIZE(keypad->keycodes);
503499

504-
matrix_keypad_build_keymap(keymap_data, MATRIX_ROW_SHIFT,
505-
keypad->keycodes, input_dev->keybit);
500+
error = matrix_keypad_build_keymap(keymap_data, NULL,
501+
MAX_MATRIX_KEY_ROWS,
502+
MAX_MATRIX_KEY_COLS,
503+
keypad->keycodes, input_dev);
504+
if (error) {
505+
dev_err(&pdev->dev, "failed to build keymap\n");
506+
goto failed_clock_put;
507+
}
506508

509+
__set_bit(EV_REP, input_dev->evbit);
507510
input_set_capability(input_dev, EV_MSC, MSC_SCAN);
508511
input_set_drvdata(input_dev, keypad);
509512

drivers/input/keyboard/lm8333.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929

3030
#define LM8333_FIFO_TRANSFER_SIZE 16
3131

32-
#define LM8333_ROW_SHIFT 4
3332
#define LM8333_NUM_ROWS 8
34-
33+
#define LM8333_NUM_COLS 16
34+
#define LM8333_ROW_SHIFT 4
3535

3636
struct lm8333 {
3737
struct i2c_client *client;
@@ -159,14 +159,13 @@ static int __devinit lm8333_probe(struct i2c_client *client,
159159
input->dev.parent = &client->dev;
160160
input->id.bustype = BUS_I2C;
161161

162-
input->keycode = lm8333->keycodes;
163-
input->keycodesize = sizeof(lm8333->keycodes[0]);
164-
input->keycodemax = ARRAY_SIZE(lm8333->keycodes);
165-
input->evbit[0] = BIT_MASK(EV_KEY);
166162
input_set_capability(input, EV_MSC, MSC_SCAN);
167163

168-
matrix_keypad_build_keymap(pdata->matrix_data, LM8333_ROW_SHIFT,
169-
input->keycode, input->keybit);
164+
err = matrix_keypad_build_keymap(pdata->matrix_data, NULL,
165+
LM8333_NUM_ROWS, LM8333_NUM_COLS,
166+
lm8333->keycodes, input);
167+
if (err)
168+
goto free_mem;
170169

171170
if (pdata->debounce_time) {
172171
err = lm8333_write8(lm8333, LM8333_DEBOUNCE,

drivers/input/keyboard/matrix_keypad.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -437,19 +437,18 @@ static int __devinit matrix_keypad_probe(struct platform_device *pdev)
437437
input_dev->name = pdev->name;
438438
input_dev->id.bustype = BUS_HOST;
439439
input_dev->dev.parent = &pdev->dev;
440-
input_dev->evbit[0] = BIT_MASK(EV_KEY);
441-
if (!pdata->no_autorepeat)
442-
input_dev->evbit[0] |= BIT_MASK(EV_REP);
443440
input_dev->open = matrix_keypad_start;
444441
input_dev->close = matrix_keypad_stop;
445442

446-
input_dev->keycode = keypad->keycodes;
447-
input_dev->keycodesize = sizeof(keypad->keycodes[0]);
448-
input_dev->keycodemax = pdata->num_row_gpios << row_shift;
449-
450-
matrix_keypad_build_keymap(keymap_data, row_shift,
451-
input_dev->keycode, input_dev->keybit);
443+
err = matrix_keypad_build_keymap(keymap_data, NULL,
444+
pdata->num_row_gpios,
445+
pdata->num_col_gpios,
446+
keypad->keycodes, input_dev);
447+
if (err)
448+
goto err_free_mem;
452449

450+
if (!pdata->no_autorepeat)
451+
__set_bit(EV_REP, input_dev->evbit);
453452
input_set_capability(input_dev, EV_MSC, MSC_SCAN);
454453
input_set_drvdata(input_dev, keypad);
455454

drivers/input/keyboard/nomadik-ske-keypad.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
#define SKE_KPRISA (0x1 << 2)
4040

4141
#define SKE_KEYPAD_ROW_SHIFT 3
42-
#define SKE_KPD_KEYMAP_SIZE (8 * 8)
42+
#define SKE_KPD_NUM_ROWS 8
43+
#define SKE_KPD_NUM_COLS 8
4344

4445
/* keypad auto scan registers */
4546
#define SKE_ASR0 0x20
@@ -63,7 +64,7 @@ struct ske_keypad {
6364
void __iomem *reg_base;
6465
struct input_dev *input;
6566
const struct ske_keypad_platform_data *board;
66-
unsigned short keymap[SKE_KPD_KEYMAP_SIZE];
67+
unsigned short keymap[SKE_KPD_NUM_ROWS * SKE_KPD_NUM_COLS];
6768
struct clk *clk;
6869
spinlock_t ske_keypad_lock;
6970
};
@@ -261,19 +262,18 @@ static int __init ske_keypad_probe(struct platform_device *pdev)
261262
input->name = "ux500-ske-keypad";
262263
input->dev.parent = &pdev->dev;
263264

264-
input->keycode = keypad->keymap;
265-
input->keycodesize = sizeof(keypad->keymap[0]);
266-
input->keycodemax = ARRAY_SIZE(keypad->keymap);
265+
error = matrix_keypad_build_keymap(plat->keymap_data, NULL,
266+
SKE_KPD_NUM_ROWS, SKE_KPD_NUM_COLS,
267+
keypad->keymap, input);
268+
if (error) {
269+
dev_err(&pdev->dev, "Failed to build keymap\n");
270+
goto err_iounmap;
271+
}
267272

268273
input_set_capability(input, EV_MSC, MSC_SCAN);
269-
270-
__set_bit(EV_KEY, input->evbit);
271274
if (!plat->no_autorepeat)
272275
__set_bit(EV_REP, input->evbit);
273276

274-
matrix_keypad_build_keymap(plat->keymap_data, SKE_KEYPAD_ROW_SHIFT,
275-
input->keycode, input->keybit);
276-
277277
clk_enable(keypad->clk);
278278

279279
/* go through board initialization helpers */

0 commit comments

Comments
 (0)