From patchwork Fri Mar 23 06:23:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tirupathi Reddy X-Patchwork-Id: 10302771 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A5A66600CC for ; Fri, 23 Mar 2018 06:23:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 95AAD2878F for ; Fri, 23 Mar 2018 06:23:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 89FDB28C19; Fri, 23 Mar 2018 06:23:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F194B2878F for ; Fri, 23 Mar 2018 06:23:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751393AbeCWGXm (ORCPT ); Fri, 23 Mar 2018 02:23:42 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:45020 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751288AbeCWGXl (ORCPT ); Fri, 23 Mar 2018 02:23:41 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id E9DB860817; Fri, 23 Mar 2018 06:23:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1521786220; bh=HTqiYCLD82ms+2fmnnksJ8ghXsfkAV1k+hL+oO+knk0=; h=From:To:Cc:Subject:Date:From; b=OIidBHtdTESeNEqIkDLe5aFFbLVpdq5MoZ9NEOaUxTEF4ProOi7jxkihyYeQxAE4z 0ba7gSVQUffyD3mwZVryIIWOZarFQIX8Pzg6oNv1TbUQA/+mdjJmO3LOKXa+YbahEy izp6iJSwLtRaTxOLyl30BlcrmBTS2BLpd/243TMM= Received: from tirupath-linux.qualcomm.com (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: tirupath@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 8FC6D6016D; Fri, 23 Mar 2018 06:23:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1521786219; bh=HTqiYCLD82ms+2fmnnksJ8ghXsfkAV1k+hL+oO+knk0=; h=From:To:Cc:Subject:Date:From; b=mro8tCLhiJ8BoD8WhtbQccTZZau54MRRLue9vuVuoMEgkPgThzI85MZtBPfVrrR8P WS4D6G7Z3ekPKVQsuQgPZfuAZypk4OWJGZopqkz2MrwBrI9J2JURyO5Tl4o80/telG Y96jjsswTMhHrKiG2Q52mbuHNmnNLEEpeJgLYxT4= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 8FC6D6016D Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=tirupath@codeaurora.org From: Tirupathi Reddy To: dmitry.torokhov@gmail.com, bjorn.andersson@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com Cc: tirupath@codeaurora.org, linux-input@vger.kernel.org, linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V3] Input: pm8941-pwrkey: add resin key capabilities Date: Fri, 23 Mar 2018 11:53:12 +0530 Message-Id: <1521786192-19487-1-git-send-email-tirupath@codeaurora.org> X-Mailer: git-send-email 1.9.1 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add resin key support to handle different types of key events defined in different platforms. Signed-off-by: Tirupathi Reddy Reviewed-by: Rob Herring --- .../bindings/input/qcom,pm8941-pwrkey.txt | 32 +++++++++ drivers/input/misc/pm8941-pwrkey.c | 81 ++++++++++++++++++++++ 2 files changed, 113 insertions(+) diff --git a/Documentation/devicetree/bindings/input/qcom,pm8941-pwrkey.txt b/Documentation/devicetree/bindings/input/qcom,pm8941-pwrkey.txt index 07bf55f..c671636 100644 --- a/Documentation/devicetree/bindings/input/qcom,pm8941-pwrkey.txt +++ b/Documentation/devicetree/bindings/input/qcom,pm8941-pwrkey.txt @@ -32,6 +32,32 @@ PROPERTIES Definition: presence of this property indicates that the KPDPWR_N pin should be configured for pull up. +RESIN SUBNODE + +The HW module can generate other optional key events like RESIN(reset-in pin). +The RESIN pin can be configured to support different key events on different +platforms. The resin key is described by the following properties. + +- interrupts: + Usage: required + Value type: + Definition: key change interrupt; The format of the specifier is + defined by the binding document describing the node's + interrupt parent. + +- linux,code: + Usage: required + Value type: + Definition: The input key-code associated with the resin key. + Use the linux event codes defined in + include/dt-bindings/input/linux-event-codes.h + +- bias-pull-up: + Usage: optional + Value type: + Definition: presence of this property indicates that the RESIN pin + should be configured for pull up. + EXAMPLE pwrkey@800 { @@ -40,4 +66,10 @@ EXAMPLE interrupts = <0x0 0x8 0 IRQ_TYPE_EDGE_BOTH>; debounce = <15625>; bias-pull-up; + + resin { + interrupts = <0x0 0x8 1 IRQ_TYPE_EDGE_BOTH>; + linux,code = ; + bias-pull-up; + }; }; diff --git a/drivers/input/misc/pm8941-pwrkey.c b/drivers/input/misc/pm8941-pwrkey.c index 18ad956..6e45d01 100644 --- a/drivers/input/misc/pm8941-pwrkey.c +++ b/drivers/input/misc/pm8941-pwrkey.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -28,6 +29,7 @@ #define PON_RT_STS 0x10 #define PON_KPDPWR_N_SET BIT(0) +#define PON_RESIN_N_SET BIT(1) #define PON_PS_HOLD_RST_CTL 0x5a #define PON_PS_HOLD_RST_CTL2 0x5b @@ -37,6 +39,7 @@ #define PON_PS_HOLD_TYPE_HARD_RESET 7 #define PON_PULL_CTL 0x70 +#define PON_RESIN_PULL_UP BIT(0) #define PON_KPDPWR_PULL_UP BIT(1) #define PON_DBC_CTL 0x71 @@ -46,6 +49,7 @@ struct pm8941_pwrkey { struct device *dev; int irq; + u32 resin_key_code; u32 baseaddr; struct regmap *regmap; struct input_dev *input; @@ -130,6 +134,24 @@ static irqreturn_t pm8941_pwrkey_irq(int irq, void *_data) return IRQ_HANDLED; } +static irqreturn_t pm8941_resinkey_irq(int irq, void *_data) +{ + struct pm8941_pwrkey *pwrkey = _data; + unsigned int sts; + int error; + u32 key_code = pwrkey->resin_key_code; + + error = regmap_read(pwrkey->regmap, + pwrkey->baseaddr + PON_RT_STS, &sts); + if (error) + return IRQ_HANDLED; + + input_report_key(pwrkey->input, key_code, !!(sts & PON_RESIN_N_SET)); + input_sync(pwrkey->input); + + return IRQ_HANDLED; +} + static int __maybe_unused pm8941_pwrkey_suspend(struct device *dev) { struct pm8941_pwrkey *pwrkey = dev_get_drvdata(dev); @@ -153,9 +175,56 @@ static int __maybe_unused pm8941_pwrkey_resume(struct device *dev) static SIMPLE_DEV_PM_OPS(pm8941_pwr_key_pm_ops, pm8941_pwrkey_suspend, pm8941_pwrkey_resume); +static int pm8941_resin_key_init(struct pm8941_pwrkey *pwrkey, + struct device_node *np) +{ + int error, irq; + bool pull_up; + + /* + * Get the standard-key parameters. This might not be + * specified if there is no key mapping on the reset line. + */ + error = of_property_read_u32(np, "linux,code", &pwrkey->resin_key_code); + if (error) { + dev_err(pwrkey->dev, "failed to read key-code for resin key\n"); + return error; + } + + pull_up = of_property_read_bool(np, "bias-pull-up"); + + irq = irq_of_parse_and_map(np, 0); + if (irq < 0) { + dev_err(pwrkey->dev, "failed to get resin irq\n"); + return -EINVAL; + } + + /* Register key configuration */ + input_set_capability(pwrkey->input, EV_KEY, pwrkey->resin_key_code); + + error = regmap_update_bits(pwrkey->regmap, + pwrkey->baseaddr + PON_PULL_CTL, + PON_RESIN_PULL_UP, + pull_up ? PON_RESIN_PULL_UP : 0); + if (error) { + dev_err(pwrkey->dev, "failed to set resin pull: %d\n", error); + return error; + } + + error = devm_request_threaded_irq(pwrkey->dev, irq, NULL, + pm8941_resinkey_irq, IRQF_ONESHOT, + "pm8941_resinkey", pwrkey); + if (error) + dev_err(pwrkey->dev, "failed requesting resin key IRQ: %d\n", + error); + + return error; +} + static int pm8941_pwrkey_probe(struct platform_device *pdev) { struct pm8941_pwrkey *pwrkey; + struct device_node *np = NULL; bool pull_up; u32 req_delay; int error; @@ -241,6 +310,18 @@ static int pm8941_pwrkey_probe(struct platform_device *pdev) return error; } + np = of_find_node_by_name(pdev->dev.of_node, "resin"); + if (np) { + /* resin key capabilities are defined in device node */ + error = pm8941_resin_key_init(pwrkey, np); + of_node_put(np); + if (error) { + dev_err(&pdev->dev, "failed resin key initialization: %d\n", + error); + return error; + } + } + error = input_register_device(pwrkey->input); if (error) { dev_err(&pdev->dev, "failed to register input device: %d\n",