aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiu Ying <Ying.Liu@freescale.com>2013-01-03 15:25:46 -0500
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2013-01-03 15:41:31 -0500
commit0e14235e6cfbc9b7a546d38b51c4e7ffdab41045 (patch)
tree54cdd6193b45b34b5c2595dee47de9ab0c3490ab
parent03c86ee1548a6ffecc65cf83b0a2d2774fed2f1d (diff)
Input: imx_keypad - add device tree support
This patch adds device tree support for imx keypad driver. Signed-off-by: Liu Ying <Ying.Liu@freescale.com> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
-rw-r--r--Documentation/devicetree/bindings/input/imx-keypad.txt53
-rw-r--r--drivers/input/keyboard/imx_keypad.c43
2 files changed, 78 insertions, 18 deletions
diff --git a/Documentation/devicetree/bindings/input/imx-keypad.txt b/Documentation/devicetree/bindings/input/imx-keypad.txt
new file mode 100644
index 000000000000..2ebaf7d26843
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/imx-keypad.txt
@@ -0,0 +1,53 @@
1* Freescale i.MX Keypad Port(KPP) device tree bindings
2
3The KPP is designed to interface with a keypad matrix with 2-point contact
4or 3-point contact keys. The KPP is designed to simplify the software task
5of scanning a keypad matrix. The KPP is capable of detecting, debouncing,
6and decoding one or multiple keys pressed simultaneously on a keypad.
7
8Required SoC Specific Properties:
9- compatible: Should be "fsl,<soc>-kpp".
10
11- reg: Physical base address of the KPP and length of memory mapped
12 region.
13
14- interrupts: The KPP interrupt number to the CPU(s).
15
16- clocks: The clock provided by the SoC to the KPP. Some SoCs use dummy
17clock(The clock for the KPP is provided by the SoCs automatically).
18
19Required Board Specific Properties:
20- pinctrl-names: The definition can be found at
21pinctrl/pinctrl-bindings.txt.
22
23- pinctrl-0: The definition can be found at
24pinctrl/pinctrl-bindings.txt.
25
26- linux,keymap: The definition can be found at
27bindings/input/matrix-keymap.txt.
28
29Example:
30kpp: kpp@73f94000 {
31 compatible = "fsl,imx51-kpp", "fsl,imx21-kpp";
32 reg = <0x73f94000 0x4000>;
33 interrupts = <60>;
34 clocks = <&clks 0>;
35 pinctrl-names = "default";
36 pinctrl-0 = <&pinctrl_kpp_1>;
37 linux,keymap = <0x00000067 /* KEY_UP */
38 0x0001006c /* KEY_DOWN */
39 0x00020072 /* KEY_VOLUMEDOWN */
40 0x00030066 /* KEY_HOME */
41 0x0100006a /* KEY_RIGHT */
42 0x01010069 /* KEY_LEFT */
43 0x0102001c /* KEY_ENTER */
44 0x01030073 /* KEY_VOLUMEUP */
45 0x02000040 /* KEY_F6 */
46 0x02010042 /* KEY_F8 */
47 0x02020043 /* KEY_F9 */
48 0x02030044 /* KEY_F10 */
49 0x0300003b /* KEY_F1 */
50 0x0301003c /* KEY_F2 */
51 0x0302003d /* KEY_F3 */
52 0x03030074>; /* KEY_POWER */
53};
diff --git a/drivers/input/keyboard/imx_keypad.c b/drivers/input/keyboard/imx_keypad.c
index 6d150e3e1f55..98f9113251d2 100644
--- a/drivers/input/keyboard/imx_keypad.c
+++ b/drivers/input/keyboard/imx_keypad.c
@@ -20,6 +20,7 @@
20#include <linux/jiffies.h> 20#include <linux/jiffies.h>
21#include <linux/kernel.h> 21#include <linux/kernel.h>
22#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/of.h>
23#include <linux/platform_device.h> 24#include <linux/platform_device.h>
24#include <linux/slab.h> 25#include <linux/slab.h>
25#include <linux/timer.h> 26#include <linux/timer.h>
@@ -414,15 +415,23 @@ open_err:
414 return -EIO; 415 return -EIO;
415} 416}
416 417
418#ifdef CONFIG_OF
419static struct of_device_id imx_keypad_of_match[] = {
420 { .compatible = "fsl,imx21-kpp", },
421 { /* sentinel */ }
422};
423MODULE_DEVICE_TABLE(of, imx_keypad_of_match);
424#endif
425
417static int imx_keypad_probe(struct platform_device *pdev) 426static int imx_keypad_probe(struct platform_device *pdev)
418{ 427{
419 const struct matrix_keymap_data *keymap_data = pdev->dev.platform_data; 428 const struct matrix_keymap_data *keymap_data = pdev->dev.platform_data;
420 struct imx_keypad *keypad; 429 struct imx_keypad *keypad;
421 struct input_dev *input_dev; 430 struct input_dev *input_dev;
422 struct resource *res; 431 struct resource *res;
423 int irq, error, i; 432 int irq, error, i, row, col;
424 433
425 if (keymap_data == NULL) { 434 if (!keymap_data && !pdev->dev.of_node) {
426 dev_err(&pdev->dev, "no keymap defined\n"); 435 dev_err(&pdev->dev, "no keymap defined\n");
427 return -EINVAL; 436 return -EINVAL;
428 } 437 }
@@ -480,22 +489,6 @@ static int imx_keypad_probe(struct platform_device *pdev)
480 goto failed_unmap; 489 goto failed_unmap;
481 } 490 }
482 491
483 /* Search for rows and cols enabled */
484 for (i = 0; i < keymap_data->keymap_size; i++) {
485 keypad->rows_en_mask |= 1 << KEY_ROW(keymap_data->keymap[i]);
486 keypad->cols_en_mask |= 1 << KEY_COL(keymap_data->keymap[i]);
487 }
488
489 if (keypad->rows_en_mask > ((1 << MAX_MATRIX_KEY_ROWS) - 1) ||
490 keypad->cols_en_mask > ((1 << MAX_MATRIX_KEY_COLS) - 1)) {
491 dev_err(&pdev->dev,
492 "invalid key data (too many rows or colums)\n");
493 error = -EINVAL;
494 goto failed_clock_put;
495 }
496 dev_dbg(&pdev->dev, "enabled rows mask: %x\n", keypad->rows_en_mask);
497 dev_dbg(&pdev->dev, "enabled cols mask: %x\n", keypad->cols_en_mask);
498
499 /* Init the Input device */ 492 /* Init the Input device */
500 input_dev->name = pdev->name; 493 input_dev->name = pdev->name;
501 input_dev->id.bustype = BUS_HOST; 494 input_dev->id.bustype = BUS_HOST;
@@ -512,6 +505,19 @@ static int imx_keypad_probe(struct platform_device *pdev)
512 goto failed_clock_put; 505 goto failed_clock_put;
513 } 506 }
514 507
508 /* Search for rows and cols enabled */
509 for (row = 0; row < MAX_MATRIX_KEY_ROWS; row++) {
510 for (col = 0; col < MAX_MATRIX_KEY_COLS; col++) {
511 i = MATRIX_SCAN_CODE(row, col, MATRIX_ROW_SHIFT);
512 if (keypad->keycodes[i] != KEY_RESERVED) {
513 keypad->rows_en_mask |= 1 << row;
514 keypad->cols_en_mask |= 1 << col;
515 }
516 }
517 }
518 dev_dbg(&pdev->dev, "enabled rows mask: %x\n", keypad->rows_en_mask);
519 dev_dbg(&pdev->dev, "enabled cols mask: %x\n", keypad->cols_en_mask);
520
515 __set_bit(EV_REP, input_dev->evbit); 521 __set_bit(EV_REP, input_dev->evbit);
516 input_set_capability(input_dev, EV_MSC, MSC_SCAN); 522 input_set_capability(input_dev, EV_MSC, MSC_SCAN);
517 input_set_drvdata(input_dev, keypad); 523 input_set_drvdata(input_dev, keypad);
@@ -631,6 +637,7 @@ static struct platform_driver imx_keypad_driver = {
631 .name = "imx-keypad", 637 .name = "imx-keypad",
632 .owner = THIS_MODULE, 638 .owner = THIS_MODULE,
633 .pm = &imx_kbd_pm_ops, 639 .pm = &imx_kbd_pm_ops,
640 .of_match_table = of_match_ptr(imx_keypad_of_match),
634 }, 641 },
635 .probe = imx_keypad_probe, 642 .probe = imx_keypad_probe,
636 .remove = imx_keypad_remove, 643 .remove = imx_keypad_remove,