Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp570582imn; Tue, 26 Jul 2022 03:54:27 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tbn5sm+AdI2qVioqDXRRV8iXNIktJwh3HIgMYQivByYVg2Klj1Coqa/Ja91EzKQOb2ux3v X-Received: by 2002:a05:6402:90e:b0:43b:914e:f084 with SMTP id g14-20020a056402090e00b0043b914ef084mr18022401edz.144.1658832866846; Tue, 26 Jul 2022 03:54:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658832866; cv=none; d=google.com; s=arc-20160816; b=kyTSN4JEdIy5E7rk1mrkSeTJC46qQbHsjWwiCns6xitXHrQUFY9/TqvGDZd/aoNR44 d/BTjE5duOEqPCOUFrCq78/T2iMMUT8+kWLJQY3FAdP28ZMQnqWHRAjSuqaCPOqo9Igy eldvfG/mnKbj4nA3ScQbadSIPIH7PLbmX0SACoHVV3f+AwJcgGoM8cJ82uaPhVU36eBb XhH4qyEfh/uVXB9hYPNsAZTMlB7Ojy0s5fm2XpG4FxCLD7Q4itxLEzgIAAALXHzK206o MAB8anMlfaHMB2Ibbm8q7kP6fGz6yhJ9VyMUaHe2kIEIOvH+1vDJNVtsBUYtv4xdioZV A4vQ== 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=fwuObdKhl0wLQFLoV4lp8AQBoHjI+xXslw/mDTvI834=; b=zv2fLYihGCJUB/3R6reI+ivAKd/5lSCiX7UxpEijvZOlrdSZlmohg8gxJvvInYKZhg eDJ6cdkX0ZFVVoga8RtkVAymodzgIXv+HnPnsZMxywX0mcdnB9j6ncsoqDTqz05zPUVu Fuu+rVIvvfRBCIIsQMx+uFdCNGPpbiRsCRSXPYwGGpNNtzyNEMC/OQ6ff36gvRdaDbRz mbZquk9tFIIFhxGS2xXolzWxTkwYIJZMHTC8V8vhaZ1dBwEPKzFE3VGp+J+N3Wq5bI4p XCPUyg/to4XzfXMqIhindgKqw+HMq5b7u0gs6rcx6pMNOB7rQMqiZIKQTO+x54g4aTnS ASDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=2lG15SUX; 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 qk20-20020a1709077f9400b00711c8193ce8si18434323ejc.21.2022.07.26.03.54.02; Tue, 26 Jul 2022 03:54:26 -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=2lG15SUX; 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 S238868AbiGZKfZ (ORCPT + 99 others); Tue, 26 Jul 2022 06:35:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238769AbiGZKfA (ORCPT ); Tue, 26 Jul 2022 06:35:00 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1A1F32B9C for ; Tue, 26 Jul 2022 03:34:37 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id b26so19561720wrc.2 for ; Tue, 26 Jul 2022 03:34:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=fwuObdKhl0wLQFLoV4lp8AQBoHjI+xXslw/mDTvI834=; b=2lG15SUXNRpuWTuX61U9J/n+TUnAuUGlfFd/qj8NDMe3lvZ37kPgKJcFensoosksEj GNBQ0KLCk8BCBFjn448HCQekTzyHLd6fPUQGk35310E0Pd7QK1FoaexiV/QZ8Ypd8Ua4 f2xEA7nOSC4o+3nrBQVy0IFc3tD8+CXBmMRGo0jv17TKu6O3iaJJdt7U9kDtnb4zA7Pn YLcZ+8Sao8NtfbqcS0I53e7W3MrrYA+kzYIBDe0l4QJy5vpdNmm8GV7uoNKey4/2iQ/D G2mBmRjp1CmDcsR0jz3VZXmCcvYogb4pu0qBBMJgw+4O2lGrkl7X7HjZM7PO/cxqQ1Ra 86tQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=fwuObdKhl0wLQFLoV4lp8AQBoHjI+xXslw/mDTvI834=; b=OXx/JytOr+AoJU99qv2b3eEN3OcKVBvut6xw0Rl3XjAsBaGmfnop0vAHpY0eGr0WlJ lsMNGVWCo5qY/gWqHGaQEkHqtZDH5jZI4k5mQz4dXMzJnV+HfS/gHyTPTTql5MZGSE3z Cgokh9lvg2a6DZvpFJZrOrxmxATt6Cgy+Vsi8QX/SqtIhqU2eUmtKxdXDIn7xCTrnfRF NeiudbPbQnG7pQyyB3tc2tM7vopmE3kN1Pz+M+8Bb8smT6lIvOtw6C65ifIAd9X/x/U0 9gbEgAX4TRAknrlfV2rUrUpReV5uakAGlWF9gqj2TEtn9Pkrf502EKJGOxtryoyGc9ki HVSQ== X-Gm-Message-State: AJIora+KKPn/yvEdxcjtBbSziIx6mxfUnYY2iHyE7B+9hfU0DRJsdm3c 8QFf69W4vHtWsdrCLtQxmN0qXw== X-Received: by 2002:a5d:6b50:0:b0:21e:298c:caad with SMTP id x16-20020a5d6b50000000b0021e298ccaadmr10180082wrw.509.1658831675918; Tue, 26 Jul 2022 03:34:35 -0700 (PDT) Received: from localhost.localdomain (2a02-8440-4641-6f91-91b7-326a-5d27-a1c3.rev.sfr.net. [2a02:8440:4641:6f91:91b7:326a:5d27:a1c3]) by smtp.gmail.com with ESMTPSA id ay35-20020a05600c1e2300b003a2e42ae9a4sm20617121wmb.14.2022.07.26.03.34.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 03:34:35 -0700 (PDT) From: Jerome Neanne To: lgirdwood@gmail.com, broonie@kernel.org, robh+dt@kernel.org, nm@ti.com, kristo@kernel.org Cc: khilman@baylibre.com, narmstrong@baylibre.com, msp@baylibre.com, j-keerthy@ti.com, lee.jones@linaro.org, jneanne@baylibre.com, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 10/11] Input: Add tps65219 interrupt driven powerbutton Date: Tue, 26 Jul 2022 12:33:54 +0200 Message-Id: <20220726103355.17684-11-jneanne@baylibre.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220726103355.17684-1-jneanne@baylibre.com> References: <20220726103355.17684-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 --- MAINTAINERS | 1 + drivers/input/misc/Kconfig | 10 ++ drivers/input/misc/Makefile | 1 + drivers/input/misc/tps65219-pwrbutton.c | 150 ++++++++++++++++++++++++ 4 files changed, 162 insertions(+) create mode 100644 drivers/input/misc/tps65219-pwrbutton.c diff --git a/MAINTAINERS b/MAINTAINERS index c48663a59835..68959f75d607 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14705,6 +14705,7 @@ F: arch/arm/plat-omap/ F: drivers/bus/ti-sysc.c F: drivers/i2c/busses/i2c-omap.c F: drivers/input/misc/tps65218-pwrbutton.c +F: drivers/input/misc/tps65219-pwrbutton.c F: drivers/irqchip/irq-omap-intc.c F: drivers/mfd/*omap*.c F: drivers/mfd/menelaus.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..48ced7b63ec3 --- /dev/null +++ b/drivers/input/misc/tps65219-pwrbutton.c @@ -0,0 +1,150 @@ +// 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