Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp2323681rwi; Tue, 11 Oct 2022 07:30:35 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4MGEMjk/GDV9I1ltM+uxFQl5P5+24PT3NdzyNUgEnuK4tyJiM1/dn+7hdBqzDVyYYP/XDg X-Received: by 2002:a17:902:70c4:b0:17c:f9fe:3200 with SMTP id l4-20020a17090270c400b0017cf9fe3200mr24748881plt.1.1665498634723; Tue, 11 Oct 2022 07:30:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665498634; cv=none; d=google.com; s=arc-20160816; b=WYTmM1C/zvWalE6CCUjRE1uM7Edr9XNGghOXSvXFG9mCE2vp3QS2RM+T++3gzKqjZn /ODGxzD/Mhdj8Otedzm4kfxAeawb8RH5Pj5aQafxbZ2I9sJbabm34qWr87YBEVbNKmHW /FgC/hH8EhCAOFF2SnyXE3rec063LfejLWi8QCq6K7/4993mz/0y1ZS9leWDYSeH3RL7 FBo0pCKfUEsmAxTJ0oI/RCmRd/Z6ZzXMCCWaqnPeJ3aMd5M8yFtjW2W/YZODGc97mFIv 2c2ZK9EDdbqQKPE9iUo5Fe9IBGZBWN9qdLxsYE36lYQ3/ajgikiqFLGR2Nq+9Bl2aRhX p8iQ== 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=WIzxr5nZexO1FxXGdVJNZa1N49u2iSyEWqopWkSvo2A=; b=055wyjhSK41y2dJFwRRp8JeBSTjY2B/39C0MLffNGj1n654gWDVBoaC81VIimwNMai UoWvnCLSTftZqKXVJOc7K/gCQ5DJTB9WspzDayiDvzwClHUvh0c4DanB/FnMR1NqaALW sW2ybwSc/lzeT07PpVX9KT26i/y9leTr9AvOj6dIBFyxU9X38deJfgvOYLYWV554SMJy XBbKtse77AO/dh+5M3jqqlgk5xTirjxFjubgPARCEyNvivZhwhWP0w1OHhc4E/DtgT1D AMAJSyCPNbo8vC7l//FE5CTuYH1cPphGWLreaKjNrtz4FSsMrNVGTb0wY20VpIlg2pjV i2bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=MgigEhGp; 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 a192-20020a6390c9000000b00434a6cb73eesi12846490pge.70.2022.10.11.07.30.19; Tue, 11 Oct 2022 07:30:34 -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=MgigEhGp; 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 S229710AbiJKOHH (ORCPT + 99 others); Tue, 11 Oct 2022 10:07:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229982AbiJKOGi (ORCPT ); Tue, 11 Oct 2022 10:06:38 -0400 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 401A992F76 for ; Tue, 11 Oct 2022 07:06:21 -0700 (PDT) Received: by mail-lf1-x134.google.com with SMTP id bp15so21249508lfb.13 for ; Tue, 11 Oct 2022 07:06:20 -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:message-id:reply-to; bh=WIzxr5nZexO1FxXGdVJNZa1N49u2iSyEWqopWkSvo2A=; b=MgigEhGpaKokMwdkMs7sJQO+ksJB5pJ4+ffIzaMtOC4tMDk+4fcRCo3kF+8eOalD9D UizVqpHyfGwT7SBfwtIez5tvkCeVp4dD+3ri6f5CvUpeer/AqCPN0tei6ZtXlX6MOwhk CJz5555i3YyL0CBG7xSfxrWG0CU6p2g4u+gJio8bpSng/yudRONkgjXQWFPRnseCuvMI cSgkTGPewcVLuddXtxdcqpCLtHkIoWs0O0yNnzm5Dj+IesiyGL4yJuEHWHicwpcTMTrw txBTr76SPYChdpg8yobja2Nuaio+yTIQLIsUOQ0np6Zzarf2AE8jRX2QL8xJkmnFT8gx sQXg== 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:message-id:reply-to; bh=WIzxr5nZexO1FxXGdVJNZa1N49u2iSyEWqopWkSvo2A=; b=N8MZHceKZxucaW3wogrf5mToyINpUpzIsEXZvLFMDx2mjc5snRk6ggPYIqN2TZgs/5 WQNxIiBm5tCb2Ei9/JkaG1yz7JdMPTz4GhpnQ1Mtm+dKDZhUl8v2IP65/5lC9qtmXn1G vundxVYRqTRXXKtTR7Hb0BOEAfbEDQLV4dFmyNAbdc1Qmtaa51J7gnxQWZG3scOgLHAC 4ypZa31CJ8I+Ne2DmDSUgq62RTaN8q4ggMU5sjGILJRy/5//5I8SuwuZN8FqTBAZZTWD 9ztN21IIdmFDfLGPDStgwk5/v/rjSa8IczymIKN0gWABZP0IAJDGPvmtDXFM6v+NsfuS MN8w== X-Gm-Message-State: ACrzQf0SjPqs/a6zqgD8X0qOfooa9SyT3RbZCvP2OD8QS5uIQswlGelv Y01Jigw5hdZp2iJFq1ATNUOUcOxhkaxy/HU0 X-Received: by 2002:a5d:64aa:0:b0:230:71e5:c540 with SMTP id m10-20020a5d64aa000000b0023071e5c540mr7452734wrp.625.1665497168765; Tue, 11 Oct 2022 07:06:08 -0700 (PDT) Received: from localhost.localdomain (192.201.68.85.rev.sfr.net. [85.68.201.192]) by smtp.gmail.com with ESMTPSA id z2-20020a5d44c2000000b0022e55f40bc7sm11437453wrr.82.2022.10.11.07.06.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Oct 2022 07:06:08 -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 v6 5/6] Input: Add tps65219 interrupt driven powerbutton Date: Tue, 11 Oct 2022 16:05:48 +0200 Message-Id: <20221011140549.16761-6-jneanne@baylibre.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221011140549.16761-1-jneanne@baylibre.com> References: <20221011140549.16761-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 | 148 ++++++++++++++++++++++++ 3 files changed, 159 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..245134bdb59e --- /dev/null +++ b/drivers/input/misc/tps65219-pwrbutton.c @@ -0,0 +1,148 @@ +// 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->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