From patchwork Sat Jul 13 04:25:51 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Shiyan X-Patchwork-Id: 2827119 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3B0889F968 for ; Sat, 13 Jul 2013 04:27:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 336A22012C for ; Sat, 13 Jul 2013 04:27:49 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1ECAC2012B for ; Sat, 13 Jul 2013 04:27:48 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UxrQB-00084v-F4; Sat, 13 Jul 2013 04:27:00 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UxrQ2-0003Nm-4h; Sat, 13 Jul 2013 04:26:50 +0000 Received: from smtp2.mail.ru ([94.100.176.130]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UxrPp-0003M2-Np for linux-arm-kernel@lists.infradead.org; Sat, 13 Jul 2013 04:26:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mail.ru; s=mail2; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=Etz60fmQpRt/881Pm1yd6TUf6TU2wAEHglsIzfpgafE=; b=Rxg6VJugoyFuNF74GOw+BqyH/qsWIGKs5iWtmn5Ne7mWv2Las4Lslccpq2X/SObSh7iNondADDLQjpT2aiEejBOQcjAP6ZSEhmyuyva+YIzu5T5cdKKCSFNm7pIc7Qslp5fqanC4W5wQVFsstshvhFFSErsD4h2IeaJiSnZnv8Q=; Received: from [188.134.40.128] (port=30539 helo=shc.zet) by smtp2.mail.ru with esmtpa (envelope-from ) id 1UxrPY-00081b-Ps; Sat, 13 Jul 2013 08:26:21 +0400 From: Alexander Shiyan To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 3/3] input: mc13783: Add DT probe support Date: Sat, 13 Jul 2013 08:25:51 +0400 Message-Id: <1373689551-24375-3-git-send-email-shc_work@mail.ru> X-Mailer: git-send-email 1.8.1.5 In-Reply-To: <1373689551-24375-1-git-send-email-shc_work@mail.ru> References: <1373689551-24375-1-git-send-email-shc_work@mail.ru> X-Mras: Ok X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130713_002638_203937_97C87E4A X-CRM114-Status: GOOD ( 13.23 ) X-Spam-Score: -2.0 (--) Cc: Alexander Shiyan , Dmitry Torokhov , Rob Herring , Sascha Hauer , linux-input@vger.kernel.org, Grant Likely , Shawn Guo X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, FREEMAIL_FROM,RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Patch adds DT support for MC13783/MC13892 PMICs. Signed-off-by: Alexander Shiyan --- Documentation/devicetree/bindings/mfd/mc13xxx.txt | 13 +++++ drivers/input/misc/mc13783-pwrbutton.c | 59 ++++++++++++++++++----- 2 files changed, 59 insertions(+), 13 deletions(-) diff --git a/Documentation/devicetree/bindings/mfd/mc13xxx.txt b/Documentation/devicetree/bindings/mfd/mc13xxx.txt index abd9e3c..cf8b61c 100644 --- a/Documentation/devicetree/bindings/mfd/mc13xxx.txt +++ b/Documentation/devicetree/bindings/mfd/mc13xxx.txt @@ -10,6 +10,12 @@ Optional properties: - fsl,mc13xxx-uses-touch : Indicate the touchscreen controller is being used Sub-nodes: +- buttons : Contain power button nodes. Each button should be declared as + "button@" and contain code in "linux,code" property. + Optional properties: + active-high : Change active button level from 0 to 1. + enable-reset: Performs hadware reset through PMIC. + debounce : Debounce value which will be taken from PMIC datasheet. - regulators : Contain the regulator nodes. The regulators are bound using their names as listed below with their registers and bits for enabling. @@ -89,6 +95,13 @@ ecspi@70010000 { /* ECSPI1 */ interrupt-parent = <&gpio0>; interrupts = <8>; + buttons { + button@1 { + linux,code = <0x1f>; + debounce = <1>; + }; + }; + regulators { sw1_reg: mc13892__sw1 { regulator-min-microvolt = <600000>; diff --git a/drivers/input/misc/mc13783-pwrbutton.c b/drivers/input/misc/mc13783-pwrbutton.c index 855d576..2040eb2 100644 --- a/drivers/input/misc/mc13783-pwrbutton.c +++ b/drivers/input/misc/mc13783-pwrbutton.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -121,21 +122,28 @@ static int __init mc13xxx_pwrbutton_probe(struct platform_device *pdev) struct mc13xxx *mc13xxx = dev_get_drvdata(pdev->dev.parent); struct mc13xxx_pwrb_devtype *devtype = (struct mc13xxx_pwrb_devtype *)pdev->id_entry->driver_data; + struct device_node *parent, *child; struct mc13xxx_pwrb *priv; int i, reg = 0, ret = -EINVAL; - if (!pdata) { + of_node_get(pdev->dev.parent->of_node); + parent = of_find_node_by_name(pdev->dev.parent->of_node, "buttons"); + if (!pdata && !parent) { dev_err(&pdev->dev, "Missing platform data\n"); return -ENODEV; } priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); - if (!priv) - return -ENOMEM; + if (!priv) { + ret = -ENOMEM; + goto out_node_put; + } priv->input = devm_input_allocate_device(&pdev->dev); - if (!priv->input) - return -ENOMEM; + if (!priv->input) { + ret = -ENOMEM; + goto out_node_put; + } priv->mc13xxx = mc13xxx; priv->devtype = devtype; @@ -143,15 +151,36 @@ static int __init mc13xxx_pwrbutton_probe(struct platform_device *pdev) for (i = 0; i < MAX13XXX_NUM_BUTTONS; i++) { u16 code, invert, reset, debounce; + const __be32 *prop; + char childname[5]; - if (!(pdata->buttons[i].flags & MC13XXX_BUTTON_ENABLE)) - continue; - code = pdata->buttons[i].keycode; - invert = !!(pdata->buttons[i].flags & - MC13XXX_BUTTON_POL_INVERT); - reset = !!(pdata->buttons[i].flags & - MC13XXX_BUTTON_RESET_EN); - debounce = pdata->buttons[i].flags; + if (parent) { + sprintf(childname, "button@%i", i + 1); + child = of_get_child_by_name(parent, childname); + if (!child) + continue; + prop = of_get_property(child, "linux,code", NULL); + if (prop) + code = be32_to_cpu(*prop) & 0xffff; + else { + dev_err(&pdev->dev, + "Button %i: Missing key code\n", i + 1); + continue; + } + invert = of_property_read_bool(child, "active-high"); + reset = of_property_read_bool(child, "enable-reset"); + prop = of_get_property(child, "debounce", NULL); + debounce = prop ? be32_to_cpu(*prop) : 0; + } else { + if (!(pdata->buttons[i].flags & MC13XXX_BUTTON_ENABLE)) + continue; + code = pdata->buttons[i].keycode; + invert = !!(pdata->buttons[i].flags & + MC13XXX_BUTTON_POL_INVERT); + reset = !!(pdata->buttons[i].flags & + MC13XXX_BUTTON_RESET_EN); + debounce = pdata->buttons[i].flags; + } priv->btn_code[i] = code; if (code != KEY_RESERVED) @@ -186,6 +215,10 @@ static int __init mc13xxx_pwrbutton_probe(struct platform_device *pdev) if (ret) dev_err(&pdev->dev, "Can't register input device: %i\n", ret); +out_node_put: + if (parent) + of_node_put(parent); + return ret; }