From patchwork Sat Aug 17 05:45:40 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Shiyan X-Patchwork-Id: 2845969 Return-Path: X-Original-To: patchwork-linux-input@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 656A49F2F5 for ; Sat, 17 Aug 2013 05:46:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4053620257 for ; Sat, 17 Aug 2013 05:46:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9651720256 for ; Sat, 17 Aug 2013 05:46:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751250Ab3HQFqc (ORCPT ); Sat, 17 Aug 2013 01:46:32 -0400 Received: from fallback1.mail.ru ([94.100.176.18]:54736 "EHLO fallback1.mail.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751077Ab3HQFqc (ORCPT ); Sat, 17 Aug 2013 01:46:32 -0400 Received: from smtp30.i.mail.ru (smtp30.i.mail.ru [94.100.177.90]) by fallback1.mail.ru (mPOP.Fallback_MX) with ESMTP id 76F29255D196 for ; Sat, 17 Aug 2013 09:46:30 +0400 (MSK) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mail.ru; s=mail2; h=Message-Id:Date:Subject:Cc:To:From; bh=mfIXk1lYzRle3GqIlbo4T2dJiazv6HU7mKLL8561LBg=; b=bMGCvlQMfXeJkUf0m173yh14p5gPF0Yygpn085bGCNWwHel+Ls+52nZi4JkEJZm9sJEnaS+j2ypIewOz8daT9iv3h47qUf9XcRs/3E1GvkI5fVoL+QSwlF/M0AWxbHL0hKhUKuBDQYVt68paTskOgaQFkKWFuRne+f7CnBjJeGA=; Received: from [188.134.40.128] (port=40478 helo=shc.zet) by smtp30.i.mail.ru with esmtpa (envelope-from ) id 1VAZKq-0006uT-TE; Sat, 17 Aug 2013 09:46:01 +0400 From: Alexander Shiyan To: linux-input@vger.kernel.org Cc: Dmitry Torokhov , Sascha Hauer , devicetree@vger.kernel.org, Rob Herring , Pawel Moll , Mark Rutland , Stephen Warren , Ian Campbell , Grant Likely , Alexander Shiyan Subject: [PATCH v3 RESEND 3/3] input: mc13783: Add DT probe support Date: Sat, 17 Aug 2013 09:45:40 +0400 Message-Id: <1376718340-16885-1-git-send-email-shc_work@mail.ru> X-Mailer: git-send-email 1.8.1.5 X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, FREEMAIL_FROM,RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Mras: Ok Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RDNS_NONE, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=no 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 | 61 +++++++++++++++++------ 2 files changed, 60 insertions(+), 14 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 2e21f19..3f9cfd1 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 @@ -77,21 +78,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; @@ -99,15 +107,36 @@ static int __init mc13xxx_pwrbutton_probe(struct platform_device *pdev) for (i = 0; i < MAX13XXX_NUM_BUTTONS; i++) { u16 code, invert, reset, debounce; - - 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; + const __be32 *prop; + char childname[5]; + + 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) @@ -155,6 +184,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; }