Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp1625965rwb; Fri, 5 Aug 2022 05:23:41 -0700 (PDT) X-Google-Smtp-Source: AA6agR4NiY8cdrhsddlF27uIm960TSl3eEuDKe3FRaaSJ3ijXyYvUppOrlt+iyJdoZRqqtt/0URN X-Received: by 2002:a17:907:1b0e:b0:72f:9b43:b98c with SMTP id mp14-20020a1709071b0e00b0072f9b43b98cmr5093036ejc.710.1659702220931; Fri, 05 Aug 2022 05:23:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659702220; cv=none; d=google.com; s=arc-20160816; b=ciHwy5PkI8nUmGrgolBln5S64r5BVokNIfwfEIMy5cokvEVW1jE8hBvUNp6J5DuCOb In2fD+dnJkTleyMssEuFLJ2xwBFeNGTjHaeNxqEmqTi7Ui3GmbYrSOVV7joRWZGyBJB3 FJamra33FczQEs0fIW9UTZ6A9eA4hPQ1H3xyMG9SAkDdqy3PntpzioFJLPyBF3DVcMqs A9wrLqtnxDnKLMTEuGLtbDD26V2p4HFMnme7RIbkJCukR8x9JlpxWG7tboheYbkY2fFT AQXQcz9acFYRLnd62zuJlL8u4CplhWJsUXC+TNsrtSlOhAqQRiTSgdeS9pnKHj4+xPIE rHiw== 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=XdUXjfksZQ9iMFS15BrD7+WKE/NgfG2aT9cbNg97hXc=; b=Sa0KtYnyhRwvq4YNTX+TOw3TRGJBtQEF+fuNUc384eRg2dqtopMEK82ifcH0jN61XG MRUwvVIvsUEe0Q7e+Wna4AFm/urey8cepgpFRsJc7zN+K2BgWDXkg+grl4kRAQUjEla4 S8iOQsTUtU+SfeaaJrTsuLy2/jTvJCOqft81qHC+9Il5GoEMyy4A+89KYqeLaQkRsv7q uWn9PE55GaoufKm7LcAPwA/5h2QyopTkenXInUFoG5i7nMw/3krzFCWQ3B2+4RUSxx1x zwbrJW4NetdafPLL8ktT9gHxMTjOqKKoMwsV1AIyzzi0Bq3BCStm7IBOf/bG7zaUcHex aXHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=Ezz4AA2G; 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 qa40-20020a17090786a800b00730c9a41829si98618ejc.31.2022.08.05.05.23.15; Fri, 05 Aug 2022 05:23:40 -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=Ezz4AA2G; 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 S240867AbiHEMU1 (ORCPT + 99 others); Fri, 5 Aug 2022 08:20:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240789AbiHEMTw (ORCPT ); Fri, 5 Aug 2022 08:19:52 -0400 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A2C27A50B for ; Fri, 5 Aug 2022 05:19:36 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id y13so4647473ejp.13 for ; Fri, 05 Aug 2022 05:19:36 -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; bh=XdUXjfksZQ9iMFS15BrD7+WKE/NgfG2aT9cbNg97hXc=; b=Ezz4AA2GG/bTYXwH9nQgJElDJpqXHETdXSbgXflBuyAqkJNO8YkT9QfW/b0LK8pr0g J9VxGh5DGdwfXCCG16vEmACGaz5KIs3WjD4HZ0y/LjYjWgzVlwe8x7SV4o1Oa35WsCKU v2scxaINFByCNRuf3MqeikX+s9+yCJrhJFpy7qyGB+dg9/IKA+/HgaNqK1ihh90nl+KT CgfTxyiCMzHiJOPNhtAYEa8tUdU1wkLc9Go0BLcVUeS1PiTsePh2XhM0RFPqrAFE3u0O mxcdzXOHS0uBAHe8JusyjTdUBHSZjm5lzZosVLerEru5j+7HCmLa9yntM8BEDKCx6EBb WEnA== 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; bh=XdUXjfksZQ9iMFS15BrD7+WKE/NgfG2aT9cbNg97hXc=; b=qYM95tV4HHcWT/yXXL8QFfXasjYf1Pw6V3Cz1kSAwYXfvxCHdYHdtAjHK8UAZZD1LA Ei4QYcgRl0CbHYIAMwWWL5d/F0R4nu/m4LgW6j82gAaehoYtfcnUv1VNrU/5UKb1rcs4 puQuIXwvoPzGzWI12YF7vaO6AE8WXXuHsJ4gmv7mRadYerT1y9pCwD4AbhGSE8TOBNRm SgSoH6OGNqAhaXquKgFmh12QpONXDnFf9m2HD2E+18tO8Uxze5SltwOTTgvZ4KW/sjAs wMOajAI7SRqyHi07kFU5dpeXKD/JzPVIeRWPCJHZL4PQe7dSoC4ndnNYI65Vr3sP7iEc BK0A== X-Gm-Message-State: ACgBeo3tLwRjWhkexjJ35fDzW2+lO7BdB50wVOz+qVO80RC3xNyJnQy1 erwKmSyTP9nw1rIEBI2pF3kM6g== X-Received: by 2002:a17:907:2889:b0:730:b35c:d91f with SMTP id em9-20020a170907288900b00730b35cd91fmr4986318ejc.57.1659701974642; Fri, 05 Aug 2022 05:19:34 -0700 (PDT) Received: from localhost.localdomain (2a02-8440-5241-be09-b892-f882-607f-7a79.rev.sfr.net. [2a02:8440:5241:be09:b892:f882:607f:7a79]) by smtp.gmail.com with ESMTPSA id kx13-20020a170907774d00b0072b3464c043sm1506111ejc.116.2022.08.05.05.19.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Aug 2022 05:19:34 -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 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, linux-input@vger.kernel.org Subject: [PATCH v3 09/10] Input: Add tps65219 interrupt driven powerbutton Date: Fri, 5 Aug 2022 14:18:51 +0200 Message-Id: <20220805121852.21254-10-jneanne@baylibre.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220805121852.21254-1-jneanne@baylibre.com> References: <20220805121852.21254-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, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 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 | 150 ++++++++++++++++++++++++ 3 files changed, 161 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..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