Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Liu Ying and committed by
Dmitry Torokhov
0e14235e 03c86ee1

+78 -18
+53
Documentation/devicetree/bindings/input/imx-keypad.txt
··· 1 + * Freescale i.MX Keypad Port(KPP) device tree bindings 2 + 3 + The KPP is designed to interface with a keypad matrix with 2-point contact 4 + or 3-point contact keys. The KPP is designed to simplify the software task 5 + of scanning a keypad matrix. The KPP is capable of detecting, debouncing, 6 + and decoding one or multiple keys pressed simultaneously on a keypad. 7 + 8 + Required 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 17 + clock(The clock for the KPP is provided by the SoCs automatically). 18 + 19 + Required Board Specific Properties: 20 + - pinctrl-names: The definition can be found at 21 + pinctrl/pinctrl-bindings.txt. 22 + 23 + - pinctrl-0: The definition can be found at 24 + pinctrl/pinctrl-bindings.txt. 25 + 26 + - linux,keymap: The definition can be found at 27 + bindings/input/matrix-keymap.txt. 28 + 29 + Example: 30 + kpp: 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 + };
+25 -18
drivers/input/keyboard/imx_keypad.c
··· 20 20 #include <linux/jiffies.h> 21 21 #include <linux/kernel.h> 22 22 #include <linux/module.h> 23 + #include <linux/of.h> 23 24 #include <linux/platform_device.h> 24 25 #include <linux/slab.h> 25 26 #include <linux/timer.h> ··· 415 414 return -EIO; 416 415 } 417 416 417 + #ifdef CONFIG_OF 418 + static struct of_device_id imx_keypad_of_match[] = { 419 + { .compatible = "fsl,imx21-kpp", }, 420 + { /* sentinel */ } 421 + }; 422 + MODULE_DEVICE_TABLE(of, imx_keypad_of_match); 423 + #endif 424 + 418 425 static int imx_keypad_probe(struct platform_device *pdev) 419 426 { 420 427 const struct matrix_keymap_data *keymap_data = pdev->dev.platform_data; 421 428 struct imx_keypad *keypad; 422 429 struct input_dev *input_dev; 423 430 struct resource *res; 424 - int irq, error, i; 431 + int irq, error, i, row, col; 425 432 426 - if (keymap_data == NULL) { 433 + if (!keymap_data && !pdev->dev.of_node) { 427 434 dev_err(&pdev->dev, "no keymap defined\n"); 428 435 return -EINVAL; 429 436 } ··· 489 480 goto failed_unmap; 490 481 } 491 482 492 - /* Search for rows and cols enabled */ 493 - for (i = 0; i < keymap_data->keymap_size; i++) { 494 - keypad->rows_en_mask |= 1 << KEY_ROW(keymap_data->keymap[i]); 495 - keypad->cols_en_mask |= 1 << KEY_COL(keymap_data->keymap[i]); 496 - } 497 - 498 - if (keypad->rows_en_mask > ((1 << MAX_MATRIX_KEY_ROWS) - 1) || 499 - keypad->cols_en_mask > ((1 << MAX_MATRIX_KEY_COLS) - 1)) { 500 - dev_err(&pdev->dev, 501 - "invalid key data (too many rows or colums)\n"); 502 - error = -EINVAL; 503 - goto failed_clock_put; 504 - } 505 - dev_dbg(&pdev->dev, "enabled rows mask: %x\n", keypad->rows_en_mask); 506 - dev_dbg(&pdev->dev, "enabled cols mask: %x\n", keypad->cols_en_mask); 507 - 508 483 /* Init the Input device */ 509 484 input_dev->name = pdev->name; 510 485 input_dev->id.bustype = BUS_HOST; ··· 504 511 dev_err(&pdev->dev, "failed to build keymap\n"); 505 512 goto failed_clock_put; 506 513 } 514 + 515 + /* Search for rows and cols enabled */ 516 + for (row = 0; row < MAX_MATRIX_KEY_ROWS; row++) { 517 + for (col = 0; col < MAX_MATRIX_KEY_COLS; col++) { 518 + i = MATRIX_SCAN_CODE(row, col, MATRIX_ROW_SHIFT); 519 + if (keypad->keycodes[i] != KEY_RESERVED) { 520 + keypad->rows_en_mask |= 1 << row; 521 + keypad->cols_en_mask |= 1 << col; 522 + } 523 + } 524 + } 525 + dev_dbg(&pdev->dev, "enabled rows mask: %x\n", keypad->rows_en_mask); 526 + dev_dbg(&pdev->dev, "enabled cols mask: %x\n", keypad->cols_en_mask); 507 527 508 528 __set_bit(EV_REP, input_dev->evbit); 509 529 input_set_capability(input_dev, EV_MSC, MSC_SCAN); ··· 637 631 .name = "imx-keypad", 638 632 .owner = THIS_MODULE, 639 633 .pm = &imx_kbd_pm_ops, 634 + .of_match_table = of_match_ptr(imx_keypad_of_match), 640 635 }, 641 636 .probe = imx_keypad_probe, 642 637 .remove = imx_keypad_remove,