From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC9D5C25B50 for ; Tue, 24 Jan 2023 11:19:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232064AbjAXLS7 (ORCPT ); Tue, 24 Jan 2023 06:18:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232166AbjAXLSt (ORCPT ); Tue, 24 Jan 2023 06:18:49 -0500 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D3EB113D7 for ; Tue, 24 Jan 2023 03:18:46 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id d14so9844014wrr.9 for ; Tue, 24 Jan 2023 03:18:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=2qK2A7F5wKZ8rhLeWq4L+8rVvDbisjlQ7qR2HWPTnjc=; b=8GkKs5DahXIcYNgIjCtM2BpCTC0GX7fbdkZWWXZ2cJ7w00DZu5ZmLRsOu3i2bEEE8I LOoqDDwzZawERSbTseb/+W9vixtTQAYdUcDcjYYEMQtwbKS1IcKJA1HVZrO30UjMU3U7 HExHLQp30gTa+dZqAplHnI4V6bME98KgTB9d7QeD9eMIsSl0v8DnJwN8RGQ0x5sXTDYp LlbPFisYnPkcosHqIWkBpDgLQ6HnNh02dkTG7AB9ynqZ7jloa3dNnldQQGuQFEwEheea +9ya6TIh1XR792HuYqbUU+wHk4K2esTxl8mK6Z4NFXsl55+zUWGE+ToRiTNQoNo/MK4z PIrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2qK2A7F5wKZ8rhLeWq4L+8rVvDbisjlQ7qR2HWPTnjc=; b=IniFwPzRJC2apDj9VAlBArUoRwcKkzdg3lgwws+oQ5ltxU2bAghWMXZlpPkBAspxEn iXOkq41v+jISQjq/BOTm7sDpWZj0Qwy8cGoa6H0L051oAjpK6P69UB43V+aJ4CPYLPpI XIpKMWNJIBj4MKbwh8qsvP1fylip3thmhLeYHTPvRIYaJtrPRcLuzFrjqYkWXonKhe6U RcnTnwDmVmEeEiaPX2MQbQgd8IpKcjbKl5XropF5wKqtBsTQ0SeiAr/w96+/L2LuJsOE DkSemxr/s2O6KmjmlYrYjbrHHU3R4IFaQoMy5wV3ycG8AZyRfZ09z/BTTLnz35b/sX3r klQg== X-Gm-Message-State: AFqh2kqxmXPGbFZXIlSnMI1POUf+1Acj3f40pzXKZua0muRlz20VUB/c hiFNnueL7gSlvMHUQLmRrWZM5btYeZUkyuUG X-Google-Smtp-Source: AMrXdXvIsmvUF4yEoKVS0/rjSGMgq1Icc3ay5/OyLgYCWJ7B4WfBq9y0ZBxKPPbUvESJ1z6PY5CR8A== X-Received: by 2002:adf:f90e:0:b0:2bc:aa67:28fb with SMTP id b14-20020adff90e000000b002bcaa6728fbmr21588839wrr.49.1674559124538; Tue, 24 Jan 2023 03:18:44 -0800 (PST) Received: from localhost ([82.66.159.240]) by smtp.gmail.com with ESMTPSA id a17-20020a5d53d1000000b0024274a5db0asm1682635wrw.2.2023.01.24.03.18.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Jan 2023 03:18:44 -0800 (PST) From: Mattijs Korpershoek To: Jacky Bai , lee@kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, shawnguo@kernel.org, s.hauer@pengutronix.de, dmitry.torokhov@gmail.com, a.zummo@towertech.it, alexandre.belloni@bootlin.com Cc: devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-input@vger.kernel.org, linux-rtc@vger.kernel.org, kernel@pengutronix.de, linux-imx@nxp.com, festevam@gmail.com Subject: Re: [PATCH v3 2/4] input: bbnsm_pwrkey: Add bbnsm power key support In-Reply-To: <20230103074742.2324924-3-ping.bai@nxp.com> References: <20230103074742.2324924-1-ping.bai@nxp.com> <20230103074742.2324924-3-ping.bai@nxp.com> Date: Tue, 24 Jan 2023 12:18:43 +0100 Message-ID: <87wn5c18q4.fsf@baylibre.com> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org On Tue, Jan 03, 2023 at 15:47, Jacky Bai wrote: > The ON/OFF logic inside the BBNSM allows for connecting directly > into a PMIC or other voltage regulator device. The module has an > button input signal and a wakeup request input signal. It also > has two interrupts (set_pwr_off_irq and set_pwr_on_irq) and an > active-low PMIC enable (pmic_en_b) output. > > Add the power key support for the ON/OFF button function found in > BBNSM module. > > Signed-off-by: Jacky Bai > Reviewed-by: Peng Fan > --- > - v2 changes: > - use device_property_read_u32() to read the property We state this in the changelog > - clean up the goto return, return directly > - sort the header file alphabetically > - rename the file to add 'nxp' prefix > > - v3 changes: > - get the regmap directly from the parent node > --- > drivers/input/keyboard/Kconfig | 11 ++ > drivers/input/keyboard/Makefile | 1 + > drivers/input/keyboard/nxp-bbnsm-pwrkey.c | 190 ++++++++++++++++++++++ > 3 files changed, 202 insertions(+) > create mode 100644 drivers/input/keyboard/nxp-bbnsm-pwrkey.c > > diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig > index 84490915ae4d..43827e34f276 100644 > --- a/drivers/input/keyboard/Kconfig > +++ b/drivers/input/keyboard/Kconfig > @@ -456,6 +456,17 @@ config KEYBOARD_SNVS_PWRKEY > To compile this driver as a module, choose M here; the > module will be called snvs_pwrkey. > > +config KEYBOARD_BBNSM_PWRKEY > + tristate "NXP BBNSM Power Key Driver" > + depends on ARCH_MXC || COMPILE_TEST > + depends on OF > + help > + This is the bbnsm powerkey driver for the NXP i.MX application > + processors. > + > + To compile this driver as a module, choose M here; the > + module will be called bbnsm_pwrkey. > + > config KEYBOARD_IMX > tristate "IMX keypad support" > depends on ARCH_MXC || COMPILE_TEST > diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile > index 5f67196bb2c1..e34dd65a34c3 100644 > --- a/drivers/input/keyboard/Makefile > +++ b/drivers/input/keyboard/Makefile > @@ -13,6 +13,7 @@ obj-$(CONFIG_KEYBOARD_AMIGA) += amikbd.o > obj-$(CONFIG_KEYBOARD_APPLESPI) += applespi.o > obj-$(CONFIG_KEYBOARD_ATARI) += atakbd.o > obj-$(CONFIG_KEYBOARD_ATKBD) += atkbd.o > +obj-$(CONFIG_KEYBOARD_BBNSM_PWRKEY) += nxp-bbnsm-pwrkey.o > obj-$(CONFIG_KEYBOARD_BCM) += bcm-keypad.o > obj-$(CONFIG_KEYBOARD_CAP11XX) += cap11xx.o > obj-$(CONFIG_KEYBOARD_CLPS711X) += clps711x-keypad.o > diff --git a/drivers/input/keyboard/nxp-bbnsm-pwrkey.c b/drivers/input/keyboard/nxp-bbnsm-pwrkey.c > new file mode 100644 > index 000000000000..dc937036c952 > --- /dev/null > +++ b/drivers/input/keyboard/nxp-bbnsm-pwrkey.c > @@ -0,0 +1,190 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +// > +// Copyright 2022 NXP. > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define BBNSM_CTRL 0x8 > +#define BBNSM_INT_EN 0x10 > +#define BBNSM_EVENTS 0x14 > +#define BBNSM_PAD_CTRL 0x24 > + > +#define BBNSM_BTN_PRESSED BIT(7) > +#define BBNSM_PWR_ON BIT(6) > +#define BBNSM_BTN_OFF BIT(5) > +#define BBNSM_EMG_OFF BIT(4) > +#define BBNSM_PWRKEY_EVENTS (BBNSM_PWR_ON | BBNSM_BTN_OFF | BBNSM_EMG_OFF) > +#define BBNSM_DP_EN BIT(24) > + > +#define DEBOUNCE_TIME 30 > +#define REPEAT_INTERVAL 60 > + > +struct bbnsm_pwrkey { > + struct regmap *regmap; > + int irq; > + int keycode; > + int keystate; /* 1:pressed */ > + struct timer_list check_timer; > + struct input_dev *input; > +}; > + > +static void bbnsm_pwrkey_check_for_events(struct timer_list *t) > +{ > + struct bbnsm_pwrkey *bbnsm = from_timer(bbnsm, t, check_timer); > + struct input_dev *input = bbnsm->input; > + u32 state; > + > + regmap_read(bbnsm->regmap, BBNSM_EVENTS, &state); > + > + state = state & BBNSM_BTN_PRESSED ? 1 : 0; > + > + /* only report new event if status changed */ > + if (state ^ bbnsm->keystate) { > + bbnsm->keystate = state; > + input_event(input, EV_KEY, bbnsm->keycode, state); > + input_sync(input); > + pm_relax(bbnsm->input->dev.parent); > + } > + > + /* repeat check if pressed long */ > + if (state) { > + mod_timer(&bbnsm->check_timer, > + jiffies + msecs_to_jiffies(REPEAT_INTERVAL)); > + } > +} > + > +static irqreturn_t bbnsm_pwrkey_interrupt(int irq, void *dev_id) > +{ > + struct platform_device *pdev = dev_id; > + struct bbnsm_pwrkey *bbnsm = platform_get_drvdata(pdev); > + struct input_dev *input = bbnsm->input; > + u32 event; > + > + regmap_read(bbnsm->regmap, BBNSM_EVENTS, &event); > + if (event & BBNSM_BTN_OFF) > + mod_timer(&bbnsm->check_timer, jiffies + msecs_to_jiffies(DEBOUNCE_TIME)); > + else > + return IRQ_NONE; > + > + pm_wakeup_event(input->dev.parent, 0); > + > + /* clear PWR OFF */ > + regmap_write(bbnsm->regmap, BBNSM_EVENTS, BBNSM_BTN_OFF); > + > + return IRQ_HANDLED; > +} > + > +static void bbnsm_pwrkey_act(void *pdata) > +{ > + struct bbnsm_pwrkey *bbnsm = pdata; > + > + del_timer_sync(&bbnsm->check_timer); > +} > + > +static int bbnsm_pwrkey_probe(struct platform_device *pdev) > +{ > + struct bbnsm_pwrkey *bbnsm; > + struct input_dev *input; > + struct device_node *np = pdev->dev.of_node; > + int error; > + > + bbnsm = devm_kzalloc(&pdev->dev, sizeof(*bbnsm), GFP_KERNEL); > + if (!bbnsm) > + return -ENOMEM; > + > + bbnsm->regmap = syscon_node_to_regmap(np->parent); > + if (IS_ERR(bbnsm->regmap)) { > + dev_err(&pdev->dev, "bbnsm pwerkey get regmap failed\n"); > + return PTR_ERR(bbnsm->regmap); > + } > + > + if (of_property_read_u32(np, "linux,code", &bbnsm->keycode)) { But of_property_read_u32() is still used > + bbnsm->keycode = KEY_POWER; > + dev_warn(&pdev->dev, "KEY_POWER without setting in dts\n"); > + } > + > + bbnsm->irq = platform_get_irq(pdev, 0); > + if (bbnsm->irq < 0) > + return -EINVAL; > + > + /* config the BBNSM power related register */ > + regmap_update_bits(bbnsm->regmap, BBNSM_CTRL, BBNSM_DP_EN, BBNSM_DP_EN); > + > + /* clear the unexpected interrupt before driver ready */ > + regmap_write_bits(bbnsm->regmap, BBNSM_EVENTS, BBNSM_PWRKEY_EVENTS, BBNSM_PWRKEY_EVENTS); > + > + timer_setup(&bbnsm->check_timer, bbnsm_pwrkey_check_for_events, 0); > + > + input = devm_input_allocate_device(&pdev->dev); > + if (!input) { > + dev_err(&pdev->dev, "failed to allocate the input device\n"); > + return -ENOMEM; > + } > + > + input->name = pdev->name; > + input->phys = "bbnsm-pwrkey/input0"; > + input->id.bustype = BUS_HOST; > + > + input_set_capability(input, EV_KEY, bbnsm->keycode); > + > + /* input customer action to cancel release timer */ > + error = devm_add_action(&pdev->dev, bbnsm_pwrkey_act, bbnsm); > + if (error) { > + dev_err(&pdev->dev, "failed to register remove action\n"); > + return error; > + } > + > + bbnsm->input = input; > + platform_set_drvdata(pdev, bbnsm); > + > + error = devm_request_irq(&pdev->dev, bbnsm->irq, bbnsm_pwrkey_interrupt, > + IRQF_SHARED, pdev->name, pdev); > + if (error) { > + dev_err(&pdev->dev, "interrupt not available.\n"); > + return error; > + } > + > + error = input_register_device(input); > + if (error < 0) { > + dev_err(&pdev->dev, "failed to register input device\n"); > + return error; > + } > + > + device_init_wakeup(&pdev->dev, true); > + dev_pm_set_wake_irq(&pdev->dev, bbnsm->irq); Can we add some error handling here? The legacy driver (snvs_pwrkey), which looks a lot like this one, warns whne irq wake enabling fails, and so do the other drivers keyboard drivers that call dev_pm_set_wake_irq(). > + > + return 0; > +} > + > +static const struct of_device_id bbnsm_pwrkey_ids[] = { > + { .compatible = "nxp,bbnsm-pwrkey" }, > + { /* sentinel */ } > +}; > +MODULE_DEVICE_TABLE(of, bbnsm_pwrkey_ids); > + > +static struct platform_driver bbnsm_pwrkey_driver = { > + .driver = { > + .name = "bbnsm_pwrkey", > + .of_match_table = bbnsm_pwrkey_ids, > + }, > + .probe = bbnsm_pwrkey_probe, > +}; > +module_platform_driver(bbnsm_pwrkey_driver); > + > +MODULE_AUTHOR("Jacky Bai "); > +MODULE_DESCRIPTION("NXP bbnsm power key Driver"); > +MODULE_LICENSE("GPL"); > -- > 2.37.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EA4D9C25B4E for ; Tue, 24 Jan 2023 11:20:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:References :In-Reply-To:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=f03fC2+9Eiy+djzsgkWXeT/vxCWkFMhFvwWKJrPkZNA=; b=XDoef7h8tTNA4N JlBr3TdIlFojTFFJhgKQpzDp136Q1z1BV2j5l5stpmQ7P04wldUe1fCjGjMVBCAtTmsLynDbRBS0Q aSeQKQOGM8uPrDyCHP/t7mMDtZZRT/QOZvPDAfGwrCvErImQ1D3Z5IVY75sWxbRanO5+dr+bSFWlZ xe0sW3EKgRt/z3/6YyKdVqpIxXPOZW+p6aKBE+aEIDGKOLJ5VgaJfvLm5oTpy7ET5iU4mvH89a0Lw G7lZg3brxWhJaQC8xGL57DEMMxOQ7H9QcFwZCqsA94g1Zl2x6tjrIhY8dUtR1inMeOVtoXnMW05Kz ocO7cuU5m1bFqfn/gmRw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pKHKO-003OiE-8w; Tue, 24 Jan 2023 11:19:00 +0000 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pKHKJ-003Ofv-RI for linux-arm-kernel@lists.infradead.org; Tue, 24 Jan 2023 11:18:58 +0000 Received: by mail-wr1-x432.google.com with SMTP id d2so13515392wrp.8 for ; Tue, 24 Jan 2023 03:18:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=2qK2A7F5wKZ8rhLeWq4L+8rVvDbisjlQ7qR2HWPTnjc=; b=8GkKs5DahXIcYNgIjCtM2BpCTC0GX7fbdkZWWXZ2cJ7w00DZu5ZmLRsOu3i2bEEE8I LOoqDDwzZawERSbTseb/+W9vixtTQAYdUcDcjYYEMQtwbKS1IcKJA1HVZrO30UjMU3U7 HExHLQp30gTa+dZqAplHnI4V6bME98KgTB9d7QeD9eMIsSl0v8DnJwN8RGQ0x5sXTDYp LlbPFisYnPkcosHqIWkBpDgLQ6HnNh02dkTG7AB9ynqZ7jloa3dNnldQQGuQFEwEheea +9ya6TIh1XR792HuYqbUU+wHk4K2esTxl8mK6Z4NFXsl55+zUWGE+ToRiTNQoNo/MK4z PIrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2qK2A7F5wKZ8rhLeWq4L+8rVvDbisjlQ7qR2HWPTnjc=; b=taPXNFjjelIvh9x/uLcEudi2+qFLmpzOXgtzzXAaKRmy7BewXkp01qLQulyg7liT1W XTsefg9KFdl9NGZSU8wIC30nX9oQO529dHXswhWp+pvJxjomMaLyAUpQmlT2XWrepMCY XcNaqpKmDxuS0650FekhrxEpX//o5qfJKFbCFDao2K7XYHrbRv6osvvVEUfhGzTzm1Uw OhimScC0FUhpC+2UtO8oQpNAC9KdQrCEtzVLeQDPT8JRr3nkpGmbyLke69AQn6UIrlqv +eZkICaeT7DLAkWqM1mNtPkgXFscqu6jqaXAafNxtgfB9dwpC4EZto1C1eulOsF8ACjN 7kYQ== X-Gm-Message-State: AFqh2kroQYK4oX+5VN01B0UlKHhAUKc2i1gDgz0PdTNfA00i7pSWn/PR 8ANAF05OljBByPGlVNQeFIru/A== X-Google-Smtp-Source: AMrXdXvIsmvUF4yEoKVS0/rjSGMgq1Icc3ay5/OyLgYCWJ7B4WfBq9y0ZBxKPPbUvESJ1z6PY5CR8A== X-Received: by 2002:adf:f90e:0:b0:2bc:aa67:28fb with SMTP id b14-20020adff90e000000b002bcaa6728fbmr21588839wrr.49.1674559124538; Tue, 24 Jan 2023 03:18:44 -0800 (PST) Received: from localhost ([82.66.159.240]) by smtp.gmail.com with ESMTPSA id a17-20020a5d53d1000000b0024274a5db0asm1682635wrw.2.2023.01.24.03.18.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Jan 2023 03:18:44 -0800 (PST) From: Mattijs Korpershoek To: Jacky Bai , lee@kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, shawnguo@kernel.org, s.hauer@pengutronix.de, dmitry.torokhov@gmail.com, a.zummo@towertech.it, alexandre.belloni@bootlin.com Cc: devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-input@vger.kernel.org, linux-rtc@vger.kernel.org, kernel@pengutronix.de, linux-imx@nxp.com, festevam@gmail.com Subject: Re: [PATCH v3 2/4] input: bbnsm_pwrkey: Add bbnsm power key support In-Reply-To: <20230103074742.2324924-3-ping.bai@nxp.com> References: <20230103074742.2324924-1-ping.bai@nxp.com> <20230103074742.2324924-3-ping.bai@nxp.com> Date: Tue, 24 Jan 2023 12:18:43 +0100 Message-ID: <87wn5c18q4.fsf@baylibre.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230124_031856_157000_8D53F472 X-CRM114-Status: GOOD ( 39.14 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Jan 03, 2023 at 15:47, Jacky Bai wrote: > The ON/OFF logic inside the BBNSM allows for connecting directly > into a PMIC or other voltage regulator device. The module has an > button input signal and a wakeup request input signal. It also > has two interrupts (set_pwr_off_irq and set_pwr_on_irq) and an > active-low PMIC enable (pmic_en_b) output. > > Add the power key support for the ON/OFF button function found in > BBNSM module. > > Signed-off-by: Jacky Bai > Reviewed-by: Peng Fan > --- > - v2 changes: > - use device_property_read_u32() to read the property We state this in the changelog > - clean up the goto return, return directly > - sort the header file alphabetically > - rename the file to add 'nxp' prefix > > - v3 changes: > - get the regmap directly from the parent node > --- > drivers/input/keyboard/Kconfig | 11 ++ > drivers/input/keyboard/Makefile | 1 + > drivers/input/keyboard/nxp-bbnsm-pwrkey.c | 190 ++++++++++++++++++++++ > 3 files changed, 202 insertions(+) > create mode 100644 drivers/input/keyboard/nxp-bbnsm-pwrkey.c > > diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig > index 84490915ae4d..43827e34f276 100644 > --- a/drivers/input/keyboard/Kconfig > +++ b/drivers/input/keyboard/Kconfig > @@ -456,6 +456,17 @@ config KEYBOARD_SNVS_PWRKEY > To compile this driver as a module, choose M here; the > module will be called snvs_pwrkey. > > +config KEYBOARD_BBNSM_PWRKEY > + tristate "NXP BBNSM Power Key Driver" > + depends on ARCH_MXC || COMPILE_TEST > + depends on OF > + help > + This is the bbnsm powerkey driver for the NXP i.MX application > + processors. > + > + To compile this driver as a module, choose M here; the > + module will be called bbnsm_pwrkey. > + > config KEYBOARD_IMX > tristate "IMX keypad support" > depends on ARCH_MXC || COMPILE_TEST > diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile > index 5f67196bb2c1..e34dd65a34c3 100644 > --- a/drivers/input/keyboard/Makefile > +++ b/drivers/input/keyboard/Makefile > @@ -13,6 +13,7 @@ obj-$(CONFIG_KEYBOARD_AMIGA) += amikbd.o > obj-$(CONFIG_KEYBOARD_APPLESPI) += applespi.o > obj-$(CONFIG_KEYBOARD_ATARI) += atakbd.o > obj-$(CONFIG_KEYBOARD_ATKBD) += atkbd.o > +obj-$(CONFIG_KEYBOARD_BBNSM_PWRKEY) += nxp-bbnsm-pwrkey.o > obj-$(CONFIG_KEYBOARD_BCM) += bcm-keypad.o > obj-$(CONFIG_KEYBOARD_CAP11XX) += cap11xx.o > obj-$(CONFIG_KEYBOARD_CLPS711X) += clps711x-keypad.o > diff --git a/drivers/input/keyboard/nxp-bbnsm-pwrkey.c b/drivers/input/keyboard/nxp-bbnsm-pwrkey.c > new file mode 100644 > index 000000000000..dc937036c952 > --- /dev/null > +++ b/drivers/input/keyboard/nxp-bbnsm-pwrkey.c > @@ -0,0 +1,190 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +// > +// Copyright 2022 NXP. > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define BBNSM_CTRL 0x8 > +#define BBNSM_INT_EN 0x10 > +#define BBNSM_EVENTS 0x14 > +#define BBNSM_PAD_CTRL 0x24 > + > +#define BBNSM_BTN_PRESSED BIT(7) > +#define BBNSM_PWR_ON BIT(6) > +#define BBNSM_BTN_OFF BIT(5) > +#define BBNSM_EMG_OFF BIT(4) > +#define BBNSM_PWRKEY_EVENTS (BBNSM_PWR_ON | BBNSM_BTN_OFF | BBNSM_EMG_OFF) > +#define BBNSM_DP_EN BIT(24) > + > +#define DEBOUNCE_TIME 30 > +#define REPEAT_INTERVAL 60 > + > +struct bbnsm_pwrkey { > + struct regmap *regmap; > + int irq; > + int keycode; > + int keystate; /* 1:pressed */ > + struct timer_list check_timer; > + struct input_dev *input; > +}; > + > +static void bbnsm_pwrkey_check_for_events(struct timer_list *t) > +{ > + struct bbnsm_pwrkey *bbnsm = from_timer(bbnsm, t, check_timer); > + struct input_dev *input = bbnsm->input; > + u32 state; > + > + regmap_read(bbnsm->regmap, BBNSM_EVENTS, &state); > + > + state = state & BBNSM_BTN_PRESSED ? 1 : 0; > + > + /* only report new event if status changed */ > + if (state ^ bbnsm->keystate) { > + bbnsm->keystate = state; > + input_event(input, EV_KEY, bbnsm->keycode, state); > + input_sync(input); > + pm_relax(bbnsm->input->dev.parent); > + } > + > + /* repeat check if pressed long */ > + if (state) { > + mod_timer(&bbnsm->check_timer, > + jiffies + msecs_to_jiffies(REPEAT_INTERVAL)); > + } > +} > + > +static irqreturn_t bbnsm_pwrkey_interrupt(int irq, void *dev_id) > +{ > + struct platform_device *pdev = dev_id; > + struct bbnsm_pwrkey *bbnsm = platform_get_drvdata(pdev); > + struct input_dev *input = bbnsm->input; > + u32 event; > + > + regmap_read(bbnsm->regmap, BBNSM_EVENTS, &event); > + if (event & BBNSM_BTN_OFF) > + mod_timer(&bbnsm->check_timer, jiffies + msecs_to_jiffies(DEBOUNCE_TIME)); > + else > + return IRQ_NONE; > + > + pm_wakeup_event(input->dev.parent, 0); > + > + /* clear PWR OFF */ > + regmap_write(bbnsm->regmap, BBNSM_EVENTS, BBNSM_BTN_OFF); > + > + return IRQ_HANDLED; > +} > + > +static void bbnsm_pwrkey_act(void *pdata) > +{ > + struct bbnsm_pwrkey *bbnsm = pdata; > + > + del_timer_sync(&bbnsm->check_timer); > +} > + > +static int bbnsm_pwrkey_probe(struct platform_device *pdev) > +{ > + struct bbnsm_pwrkey *bbnsm; > + struct input_dev *input; > + struct device_node *np = pdev->dev.of_node; > + int error; > + > + bbnsm = devm_kzalloc(&pdev->dev, sizeof(*bbnsm), GFP_KERNEL); > + if (!bbnsm) > + return -ENOMEM; > + > + bbnsm->regmap = syscon_node_to_regmap(np->parent); > + if (IS_ERR(bbnsm->regmap)) { > + dev_err(&pdev->dev, "bbnsm pwerkey get regmap failed\n"); > + return PTR_ERR(bbnsm->regmap); > + } > + > + if (of_property_read_u32(np, "linux,code", &bbnsm->keycode)) { But of_property_read_u32() is still used > + bbnsm->keycode = KEY_POWER; > + dev_warn(&pdev->dev, "KEY_POWER without setting in dts\n"); > + } > + > + bbnsm->irq = platform_get_irq(pdev, 0); > + if (bbnsm->irq < 0) > + return -EINVAL; > + > + /* config the BBNSM power related register */ > + regmap_update_bits(bbnsm->regmap, BBNSM_CTRL, BBNSM_DP_EN, BBNSM_DP_EN); > + > + /* clear the unexpected interrupt before driver ready */ > + regmap_write_bits(bbnsm->regmap, BBNSM_EVENTS, BBNSM_PWRKEY_EVENTS, BBNSM_PWRKEY_EVENTS); > + > + timer_setup(&bbnsm->check_timer, bbnsm_pwrkey_check_for_events, 0); > + > + input = devm_input_allocate_device(&pdev->dev); > + if (!input) { > + dev_err(&pdev->dev, "failed to allocate the input device\n"); > + return -ENOMEM; > + } > + > + input->name = pdev->name; > + input->phys = "bbnsm-pwrkey/input0"; > + input->id.bustype = BUS_HOST; > + > + input_set_capability(input, EV_KEY, bbnsm->keycode); > + > + /* input customer action to cancel release timer */ > + error = devm_add_action(&pdev->dev, bbnsm_pwrkey_act, bbnsm); > + if (error) { > + dev_err(&pdev->dev, "failed to register remove action\n"); > + return error; > + } > + > + bbnsm->input = input; > + platform_set_drvdata(pdev, bbnsm); > + > + error = devm_request_irq(&pdev->dev, bbnsm->irq, bbnsm_pwrkey_interrupt, > + IRQF_SHARED, pdev->name, pdev); > + if (error) { > + dev_err(&pdev->dev, "interrupt not available.\n"); > + return error; > + } > + > + error = input_register_device(input); > + if (error < 0) { > + dev_err(&pdev->dev, "failed to register input device\n"); > + return error; > + } > + > + device_init_wakeup(&pdev->dev, true); > + dev_pm_set_wake_irq(&pdev->dev, bbnsm->irq); Can we add some error handling here? The legacy driver (snvs_pwrkey), which looks a lot like this one, warns whne irq wake enabling fails, and so do the other drivers keyboard drivers that call dev_pm_set_wake_irq(). > + > + return 0; > +} > + > +static const struct of_device_id bbnsm_pwrkey_ids[] = { > + { .compatible = "nxp,bbnsm-pwrkey" }, > + { /* sentinel */ } > +}; > +MODULE_DEVICE_TABLE(of, bbnsm_pwrkey_ids); > + > +static struct platform_driver bbnsm_pwrkey_driver = { > + .driver = { > + .name = "bbnsm_pwrkey", > + .of_match_table = bbnsm_pwrkey_ids, > + }, > + .probe = bbnsm_pwrkey_probe, > +}; > +module_platform_driver(bbnsm_pwrkey_driver); > + > +MODULE_AUTHOR("Jacky Bai "); > +MODULE_DESCRIPTION("NXP bbnsm power key Driver"); > +MODULE_LICENSE("GPL"); > -- > 2.37.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel