From patchwork Thu Jan 3 12:37:32 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Ying X-Patchwork-Id: 1927661 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id 96D943FC33 for ; Thu, 3 Jan 2013 13:21:44 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TqkgW-0006wS-NF; Thu, 03 Jan 2013 13:18:12 +0000 Received: from co9ehsobe004.messaging.microsoft.com ([207.46.163.27] helo=co9outboundpool.messaging.microsoft.com) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1TqkgM-0006vR-GR for linux-arm-kernel@lists.infradead.org; Thu, 03 Jan 2013 13:18:03 +0000 Received: from mail55-co9-R.bigfish.com (10.236.132.240) by CO9EHSOBE017.bigfish.com (10.236.130.80) with Microsoft SMTP Server id 14.1.225.23; Thu, 3 Jan 2013 13:18:00 +0000 Received: from mail55-co9 (localhost [127.0.0.1]) by mail55-co9-R.bigfish.com (Postfix) with ESMTP id 2E02E940238; Thu, 3 Jan 2013 13:18:00 +0000 (UTC) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPV:NLI; H:mail.freescale.net; RD:none; EFVD:NLI X-SpamScore: 3 X-BigFish: VS3(zzzz1de0h1202h1e76h1d1ah1d2ahz70kz8275bhz2dh2a8h668h839he5bhf0ah107ah11b5h121eh1288h12a5h12a9h12bdh12e5h137ah139eh13b6h1441h14afh1504h1537h162dh1631h1758h1155h) Received: from mail55-co9 (localhost.localdomain [127.0.0.1]) by mail55-co9 (MessageSwitch) id 135721903849240_15120; Thu, 3 Jan 2013 13:17:18 +0000 (UTC) Received: from CO9EHSMHS030.bigfish.com (unknown [10.236.132.242]) by mail55-co9.bigfish.com (Postfix) with ESMTP id F1686DC004C; Thu, 3 Jan 2013 13:17:17 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by CO9EHSMHS030.bigfish.com (10.236.130.40) with Microsoft SMTP Server (TLS) id 14.1.225.23; Thu, 3 Jan 2013 13:17:17 +0000 Received: from tx30smr01.am.freescale.net (10.81.153.31) by 039-SN1MMR1-003.039d.mgd.msft.net (10.84.1.16) with Microsoft SMTP Server (TLS) id 14.2.318.3; Thu, 3 Jan 2013 13:17:16 +0000 Received: from shlinux1.ap.freescale.net (shlinux1.ap.freescale.net [10.192.225.216]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id r03DH8b6003919; Thu, 3 Jan 2013 06:17:09 -0700 Received: by shlinux1.ap.freescale.net (Postfix, from userid 1011) id BE4C61AE0C7; Thu, 3 Jan 2013 20:37:47 +0800 (CST) From: Liu Ying To: , , , , , , , , , Subject: [PATCH v3 1/3] Input: imx_keypad - Add device tree support Date: Thu, 3 Jan 2013 20:37:32 +0800 Message-ID: <1357216654-12651-1-git-send-email-Ying.Liu@freescale.com> X-Mailer: git-send-email 1.7.1 MIME-Version: 1.0 X-OriginatorOrg: freescale.net X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130103_081802_767469_E1BC4FC4 X-CRM114-Status: GOOD ( 21.06 ) X-Spam-Score: -4.2 (----) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-4.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [207.46.163.27 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: liu.y.victor@gmail.com, linux-doc@vger.kernel.org, Liu Ying , linux-arm-kernel@lists.infradead.org, linux-input@vger.kernel.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org This patch adds device tree support for imx keypad driver. Signed-off-by: Liu Ying --- Changes since v2: - Improve the logic in the probe function to check whether DT-supplied data is presented or not. Changes since v1: - Parse the array keypad->keycodes[] to get row and column mask value instead of parsing DT-supplied data again. - Remove the pinctrl related code which sets row and column key pins. - Leave matrix_keypad_build_keymap() to determine platform data and DT-supplied data precedence. - Change DT compatible string from 'fsl,imx-kpp' to 'fsl, -kpp'. --- .../devicetree/bindings/input/imx-keypad.txt | 53 ++++++++++++++++++++ drivers/input/keyboard/imx_keypad.c | 42 +++++++++------- 2 files changed, 77 insertions(+), 18 deletions(-) create mode 100644 Documentation/devicetree/bindings/input/imx-keypad.txt diff --git a/Documentation/devicetree/bindings/input/imx-keypad.txt b/Documentation/devicetree/bindings/input/imx-keypad.txt new file mode 100644 index 0000000..2ebaf7d --- /dev/null +++ b/Documentation/devicetree/bindings/input/imx-keypad.txt @@ -0,0 +1,53 @@ +* Freescale i.MX Keypad Port(KPP) device tree bindings + +The KPP is designed to interface with a keypad matrix with 2-point contact +or 3-point contact keys. The KPP is designed to simplify the software task +of scanning a keypad matrix. The KPP is capable of detecting, debouncing, +and decoding one or multiple keys pressed simultaneously on a keypad. + +Required SoC Specific Properties: +- compatible: Should be "fsl,-kpp". + +- reg: Physical base address of the KPP and length of memory mapped + region. + +- interrupts: The KPP interrupt number to the CPU(s). + +- clocks: The clock provided by the SoC to the KPP. Some SoCs use dummy +clock(The clock for the KPP is provided by the SoCs automatically). + +Required Board Specific Properties: +- pinctrl-names: The definition can be found at +pinctrl/pinctrl-bindings.txt. + +- pinctrl-0: The definition can be found at +pinctrl/pinctrl-bindings.txt. + +- linux,keymap: The definition can be found at +bindings/input/matrix-keymap.txt. + +Example: +kpp: kpp@73f94000 { + compatible = "fsl,imx51-kpp", "fsl,imx21-kpp"; + reg = <0x73f94000 0x4000>; + interrupts = <60>; + clocks = <&clks 0>; + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_kpp_1>; + linux,keymap = <0x00000067 /* KEY_UP */ + 0x0001006c /* KEY_DOWN */ + 0x00020072 /* KEY_VOLUMEDOWN */ + 0x00030066 /* KEY_HOME */ + 0x0100006a /* KEY_RIGHT */ + 0x01010069 /* KEY_LEFT */ + 0x0102001c /* KEY_ENTER */ + 0x01030073 /* KEY_VOLUMEUP */ + 0x02000040 /* KEY_F6 */ + 0x02010042 /* KEY_F8 */ + 0x02020043 /* KEY_F9 */ + 0x02030044 /* KEY_F10 */ + 0x0300003b /* KEY_F1 */ + 0x0301003c /* KEY_F2 */ + 0x0302003d /* KEY_F3 */ + 0x03030074>; /* KEY_POWER */ +}; diff --git a/drivers/input/keyboard/imx_keypad.c b/drivers/input/keyboard/imx_keypad.c index 6d150e3..83dc5cd 100644 --- a/drivers/input/keyboard/imx_keypad.c +++ b/drivers/input/keyboard/imx_keypad.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -414,15 +415,21 @@ open_err: return -EIO; } +static struct of_device_id imx_keypad_of_match[] = { + { .compatible = "fsl,imx21-kpp", }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, imx_keypad_of_match); + static int imx_keypad_probe(struct platform_device *pdev) { const struct matrix_keymap_data *keymap_data = pdev->dev.platform_data; struct imx_keypad *keypad; struct input_dev *input_dev; struct resource *res; - int irq, error, i; + int irq, error, i, row, col, row_shift; - if (keymap_data == NULL) { + if (keymap_data == NULL && pdev->dev.of_node == NULL) { dev_err(&pdev->dev, "no keymap defined\n"); return -EINVAL; } @@ -480,22 +487,6 @@ static int imx_keypad_probe(struct platform_device *pdev) goto failed_unmap; } - /* Search for rows and cols enabled */ - for (i = 0; i < keymap_data->keymap_size; i++) { - keypad->rows_en_mask |= 1 << KEY_ROW(keymap_data->keymap[i]); - keypad->cols_en_mask |= 1 << KEY_COL(keymap_data->keymap[i]); - } - - if (keypad->rows_en_mask > ((1 << MAX_MATRIX_KEY_ROWS) - 1) || - keypad->cols_en_mask > ((1 << MAX_MATRIX_KEY_COLS) - 1)) { - dev_err(&pdev->dev, - "invalid key data (too many rows or colums)\n"); - error = -EINVAL; - goto failed_clock_put; - } - dev_dbg(&pdev->dev, "enabled rows mask: %x\n", keypad->rows_en_mask); - dev_dbg(&pdev->dev, "enabled cols mask: %x\n", keypad->cols_en_mask); - /* Init the Input device */ input_dev->name = pdev->name; input_dev->id.bustype = BUS_HOST; @@ -512,6 +503,20 @@ static int imx_keypad_probe(struct platform_device *pdev) goto failed_clock_put; } + /* Search for rows and cols enabled */ + row_shift = get_count_order(MAX_MATRIX_KEY_COLS); + for (row = 0; row < MAX_MATRIX_KEY_ROWS; row++) { + for (col = 0; col < MAX_MATRIX_KEY_COLS; col++) { + i = (row << row_shift) + col; + if (keypad->keycodes[i]) { + keypad->rows_en_mask |= 1 << row; + keypad->cols_en_mask |= 1 << col; + } + } + } + dev_dbg(&pdev->dev, "enabled rows mask: %x\n", keypad->rows_en_mask); + dev_dbg(&pdev->dev, "enabled cols mask: %x\n", keypad->cols_en_mask); + __set_bit(EV_REP, input_dev->evbit); input_set_capability(input_dev, EV_MSC, MSC_SCAN); input_set_drvdata(input_dev, keypad); @@ -631,6 +636,7 @@ static struct platform_driver imx_keypad_driver = { .name = "imx-keypad", .owner = THIS_MODULE, .pm = &imx_kbd_pm_ops, + .of_match_table = of_match_ptr(imx_keypad_of_match), }, .probe = imx_keypad_probe, .remove = imx_keypad_remove,