Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp604508rwb; Tue, 27 Sep 2022 01:59:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM52EA5xsqHT/RZFmMsqjxOCDeKh8q7F62WcKqdWUwfVIwwjYV1f85wzG0+uYF67BrbZXqj2 X-Received: by 2002:a17:902:d509:b0:179:ee34:faaf with SMTP id b9-20020a170902d50900b00179ee34faafmr1342209plg.150.1664269143374; Tue, 27 Sep 2022 01:59:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664269143; cv=none; d=google.com; s=arc-20160816; b=pWn7xjsJvcapxg19l8VhNRDB9c4WaHLnPgiBWa9i5zjIB69RNGRfCZZB8laRMR6j1X GN+dXeCKaEoeulT4ZH0+kRLUzknGvsFObQIxkJOQzSooQFzfV0ggcTDWfbpgN0KL0xSK UVbLkmL/OqUPsoC7avTZqLYEcmZsxXBSY0x25033IzaOXTizNipVUYahNIDF7V6xM9KZ 52lBLanyMfd8+pd1JOQQcV1cb7CqIvpaW2YtInyg7KM+KJLF69oD6iSi25QRYVUUoGAb 2igJnYUgWCclw/hgUgGvfXaA7lS3AhH18Hc8IhXz8c/xGCyOjJiRVKQmUobPhM97VK99 y9Rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=vp1E6+QHVOYaULyPFbq5rR84CQlOPmMuTVNHG0IbfvI=; b=eA93dMncTVZrm9dBtk9v8raNEl+YMop/3eCjP2WHY2lNUrP+iQRoLGU+e++0/Lf8jE UfUBUFusNowLNAHSd0FsazlBRuPNlekDbj4Xhq7sYwA8Iv8codfBsqv9359QYMKM7aj7 5fatCld2XqHV0nfLF2FS3AzldMJ3eOnJFr7TfEw4R3PiGjYulNcTJa9CS4HawEqN1AQv PKEx3qsIbmYLFcRUlRoBAJNNdvPf14hsA0LTf3Lu/ax52A1cSA6rmgFwEfr3rfYB9KyF KFCaFX18F+vESCyMbAm55/BBMtOLkkcC9cvlZmc0wNS0quipxTuOhjXOFifrVsSriRi6 N9Ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=pR8wdq4e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v13-20020a63b94d000000b0043496fee126si1319646pgo.652.2022.09.27.01.58.51; Tue, 27 Sep 2022 01:59:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=pR8wdq4e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230096AbiI0Igp (ORCPT + 99 others); Tue, 27 Sep 2022 04:36:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231579AbiI0If7 (ORCPT ); Tue, 27 Sep 2022 04:35:59 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 094FD25D4 for ; Tue, 27 Sep 2022 01:35:45 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id c11so13792451wrp.11 for ; Tue, 27 Sep 2022 01:35:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date; bh=vp1E6+QHVOYaULyPFbq5rR84CQlOPmMuTVNHG0IbfvI=; b=pR8wdq4eTQv+sepVl/ZOD6bQKjQ1p4BNZwqMy1jpkJqPQxppAIcvi5KI2DKCWHz5ED WroA2OeC8zIqHwvxBUuyaTCcvLfsImoEyR1PV1HU+GRvu3nZg4UUEUmf5O8LJzBxXuaO jtfFsKfDSGFWEAl8wsK/7dwTVNxLVpikkqrg2jtmytPpdAMnLtdD/pMq+53oDEmHv8iZ 4h03rSNq7ADpJp9scadNddmPeSTQ8jtgakKLvEUKlHLOhRrDpGjLUqOojnGZwgyxlOgW ENrWGRpcgzMN9SyXx7oGxVTLHze99JjZkkAWSA8WUmKzquAOF2dfTZdRROW55j2W0CRt zqkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date; bh=vp1E6+QHVOYaULyPFbq5rR84CQlOPmMuTVNHG0IbfvI=; b=u//3Pzioru1ox6K4Fjx/TVbVExC2YnEWg6GEBIVmhfRgRp8+pZLjsfvRXPnpj0ev+9 H6ax8DJYteMV3crK9Z9MQeV9taGIgGxKPdvpOgDyt3851rtOPRk/H9iOfG1HrzW8+FHS zgL/Rv8+NIqDwRXcjlZLBczR+6wYDGNXXQZWU00vRfDGUQJMFK3E8i5SHl6Qv1GCub/Z 5CaBsDJiKAI+sh7jq9kMG4TXwYBQyz4EPTxfy4FuPBSN+S5jpQg7ZzGL2ZW4VPh/eZuf 5/9f5jjXhiMKHgdwkpapGInzDyuTXWxIqX9qtDZ0PrkBIp5ilmqfYkPCF8gsqiMt45BK zZfw== X-Gm-Message-State: ACrzQf0aNbUYeRNTgxQQ3O17/2kK8NhC0Fl5cTq45U8t/OzJ4BdkbimO PWiy3T2/S9pE/DZEsABPE4l77A== X-Received: by 2002:a5d:4bc3:0:b0:22a:4b7a:6f60 with SMTP id l3-20020a5d4bc3000000b0022a4b7a6f60mr15805408wrt.549.1664267745201; Tue, 27 Sep 2022 01:35:45 -0700 (PDT) Received: from localhost.localdomain (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.gmail.com with ESMTPSA id n30-20020a05600c501e00b003b492b30822sm1122120wmr.2.2022.09.27.01.35.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Sep 2022 01:35:44 -0700 (PDT) From: Jerome Neanne To: lgirdwood@gmail.com, broonie@kernel.org, robh+dt@kernel.org, nm@ti.com, kristo@kernel.org, dmitry.torokhov@gmail.com, krzysztof.kozlowski+dt@linaro.org, catalin.marinas@arm.com, will@kernel.org, lee@kernel.org, tony@atomide.com, vigneshr@ti.com, bjorn.andersson@linaro.org, shawnguo@kernel.org, geert+renesas@glider.be, dmitry.baryshkov@linaro.org, marcel.ziswiler@toradex.com, vkoul@kernel.org, biju.das.jz@bp.renesas.com, arnd@arndb.de, jeff@labundy.com Cc: afd@ti.com, khilman@baylibre.com, narmstrong@baylibre.com, msp@baylibre.com, j-keerthy@ti.com, jneanne@baylibre.com, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-input@vger.kernel.org, linux-omap@vger.kernel.org Subject: [PATCH v5 5/6] Input: Add tps65219 interrupt driven powerbutton Date: Tue, 27 Sep 2022 10:35:19 +0200 Message-Id: <20220927083520.15766-6-jneanne@baylibre.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220927083520.15766-1-jneanne@baylibre.com> References: <20220927083520.15766-1-jneanne@baylibre.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Markus Schneider-Pargmann TPS65219 has different interrupts compared to other TPS6521* chips. TPS65219 defines two interrupts for the powerbutton one for push and one for release. This driver is very simple in that it maps the push interrupt to a key input and the release interrupt to a key release. Signed-off-by: Markus Schneider-Pargmann Signed-off-by: Jerome Neanne --- drivers/input/misc/Kconfig | 10 ++ drivers/input/misc/Makefile | 1 + drivers/input/misc/tps65219-pwrbutton.c | 149 ++++++++++++++++++++++++ 3 files changed, 160 insertions(+) create mode 100644 drivers/input/misc/tps65219-pwrbutton.c diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig index a18ab7358d8f..18d4a321e7ff 100644 --- a/drivers/input/misc/Kconfig +++ b/drivers/input/misc/Kconfig @@ -468,6 +468,16 @@ config INPUT_TPS65218_PWRBUTTON To compile this driver as a module, choose M here. The module will be called tps65218-pwrbutton. +config INPUT_TPS65219_PWRBUTTON + tristate "TPS65219 Power button driver" + depends on MFD_TPS65219 + help + Say Y here if you want to enable power button reporting for + TPS65219 Power Management IC devices. + + To compile this driver as a module, choose M here. The module will + be called tps65219-pwrbutton. + config INPUT_AXP20X_PEK tristate "X-Powers AXP20X power button driver" depends on MFD_AXP20X diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile index 28dfc444f0a9..fe8f47402d12 100644 --- a/drivers/input/misc/Makefile +++ b/drivers/input/misc/Makefile @@ -78,6 +78,7 @@ obj-$(CONFIG_INPUT_SOC_BUTTON_ARRAY) += soc_button_array.o obj-$(CONFIG_INPUT_SPARCSPKR) += sparcspkr.o obj-$(CONFIG_INPUT_STPMIC1_ONKEY) += stpmic1_onkey.o obj-$(CONFIG_INPUT_TPS65218_PWRBUTTON) += tps65218-pwrbutton.o +obj-$(CONFIG_INPUT_TPS65219_PWRBUTTON) += tps65219-pwrbutton.o obj-$(CONFIG_INPUT_TWL4030_PWRBUTTON) += twl4030-pwrbutton.o obj-$(CONFIG_INPUT_TWL4030_VIBRA) += twl4030-vibra.o obj-$(CONFIG_INPUT_TWL6040_VIBRA) += twl6040-vibra.o diff --git a/drivers/input/misc/tps65219-pwrbutton.c b/drivers/input/misc/tps65219-pwrbutton.c new file mode 100644 index 000000000000..163b545d5a54 --- /dev/null +++ b/drivers/input/misc/tps65219-pwrbutton.c @@ -0,0 +1,149 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Driver for TPS65219 Push Button +// +// Copyright (C) 2022 BayLibre Incorporated - https://www.baylibre.com/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct tps65219_pwrbutton { + struct device *dev; + struct input_dev *idev; + char phys[32]; +}; + +static irqreturn_t tps65219_pb_push_irq(int irq, void *_pwr) +{ + struct tps65219_pwrbutton *pwr = _pwr; + + input_report_key(pwr->idev, KEY_POWER, 1); + pm_wakeup_event(pwr->dev, 0); + input_sync(pwr->idev); + + return IRQ_HANDLED; +} + +static irqreturn_t tps65219_pb_release_irq(int irq, void *_pwr) +{ + struct tps65219_pwrbutton *pwr = _pwr; + + input_report_key(pwr->idev, KEY_POWER, 0); + input_sync(pwr->idev); + + return IRQ_HANDLED; +} + +static int tps65219_pb_probe(struct platform_device *pdev) +{ + struct tps65219 *tps = dev_get_drvdata(pdev->dev.parent); + struct device *dev = &pdev->dev; + struct tps65219_pwrbutton *pwr; + struct input_dev *idev; + int error; + int push_irq; + int release_irq; + + pwr = devm_kzalloc(dev, sizeof(*pwr), GFP_KERNEL); + if (!pwr) + return -ENOMEM; + + idev = devm_input_allocate_device(dev); + if (!idev) + return -ENOMEM; + + idev->name = pdev->name; + snprintf(pwr->phys, sizeof(pwr->phys), "%s/input0", + pdev->name); + idev->phys = pwr->phys; + idev->dev.parent = dev; + idev->id.bustype = BUS_I2C; + + input_set_capability(idev, EV_KEY, KEY_POWER); + + pwr->dev = dev; + pwr->idev = idev; + device_init_wakeup(dev, true); + + push_irq = platform_get_irq(pdev, 0); + if (push_irq < 0) + return -EINVAL; + + release_irq = platform_get_irq(pdev, 1); + if (release_irq < 0) + return -EINVAL; + + error = devm_request_threaded_irq(dev, push_irq, NULL, + tps65219_pb_push_irq, + IRQF_ONESHOT, + dev->init_name, pwr); + if (error) { + dev_err(dev, "failed to request push IRQ #%d: %d\n", push_irq, + error); + return error; + } + + error = devm_request_threaded_irq(dev, release_irq, NULL, + tps65219_pb_release_irq, + IRQF_ONESHOT, + dev->init_name, pwr); + if (error) { + dev_err(dev, "failed to request release IRQ #%d: %d\n", + release_irq, error); + return error; + } + + error = input_register_device(idev); + if (error) { + dev_err(dev, "Can't register power button: %d\n", error); + return error; + } + + /* Enable interrupts for the pushbutton */ + regmap_clear_bits(tps->regmap, TPS65219_REG_MASK_CONFIG, + TPS65219_REG_MASK_INT_FOR_PB_MASK); + + /* Set PB/EN/VSENSE pin to be a pushbutton */ + regmap_update_bits(tps->regmap, TPS65219_REG_MFP_2_CONFIG, + TPS65219_MFP_2_EN_PB_VSENSE_MASK, TPS65219_MFP_2_PB); + + return 0; +} + +static int tps65219_pb_remove(struct platform_device *pdev) +{ + struct tps65219 *tps = dev_get_drvdata(pdev->dev.parent); + + /* Disable interrupt for the pushbutton */ + return regmap_update_bits(tps->regmap, TPS65219_REG_MASK_CONFIG, + TPS65219_REG_MASK_INT_FOR_PB_MASK, + TPS65219_REG_MASK_INT_FOR_PB_MASK); +} + +static const struct platform_device_id tps65219_pwrbtn_id_table[] = { + { "tps65219-pwrbutton", }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(platform, tps65219_pwrbtn_id_table); + +static struct platform_driver tps65219_pb_driver = { + .probe = tps65219_pb_probe, + .remove = tps65219_pb_remove, + .driver = { + .name = "tps65219_pwrbutton", + }, + .id_table = tps65219_pwrbtn_id_table, +}; +module_platform_driver(tps65219_pb_driver); + +MODULE_DESCRIPTION("TPS65219 Power Button"); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Markus Schneider-Pargmann