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 C7F3CC433FE for ; Tue, 22 Nov 2022 23:33:50 +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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=iQihVYhBs7RgbXWES3CaCFk+fwIUJYoclSGT7EQcdus=; b=bD69Kvc5JnKeoR OoBCpN52fGSHmXr1VhH5dGIIJbap/rChPwS7SSh7l3oZp9Gr1ccoDi6mG3DuwkAcF3ESZb9th0cd6 vnyYIF1EVElrtRVOdf6TA07Xv5nvHPoRFDb37TGk2t3tilW/fIANAAi0uC2PyrsECmoX3DmWNi/dZ q6F5r/VYRcQyrPnBZ5RLKjoGTA5XEHdu8SL0hD1Ds3GUENcEOkZvfv76u36yxrYB0fTKKWd8NLdlI i0nq4PENJDYK0eqN3mNtcBwQ4EFxkx0LKIcQUYYKPqeOI8GRkGBqlASoydh95+47cU+wjtzsnsBlR RUP4RXLuEYaXieDE6ssg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oxcky-00CKIn-Mj; Tue, 22 Nov 2022 23:32:48 +0000 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oxcku-00CKH2-RI for linux-arm-kernel@lists.infradead.org; Tue, 22 Nov 2022 23:32:46 +0000 Received: by mail-pj1-x102e.google.com with SMTP id 71-20020a17090a09cd00b00218adeb3549so337327pjo.1 for ; Tue, 22 Nov 2022 15:32:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=xR2vHmEP3Nm1DbSbyQP7SzQx10F473F5bKKnZx13bC0=; b=dYmVd2MiANTX0LOYuPpcczwqS//BPZShmSmN8WMbFWu3X1jZqGGvGFkCIWxbuOFe0U aTEhYrGuWgPc4pk+pxWyEFKONI3CGrbuk7UdjNdfYFhzg41OqYcjaYOJ+6h61JMPAqL/ QA2b4G4cGhTU6n7//d8ac4l8Ev9CVKkW+aDl/svzm2Ikmeu6C8TB+MbpNGjq1u9Gj5nl +fDpfJpkp1K1SwHsL5YdmW+yndPj9wZHzPP7KuI65MXDnm+SojS0e8wZ5kGaJOTKzFMF bXk7KiksmA2jVNb5pht9DpMRTe9PIlAEj8Gzz7qiqFgn4W6mIJCmeRuDkZA8OpKKriNt uM3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=xR2vHmEP3Nm1DbSbyQP7SzQx10F473F5bKKnZx13bC0=; b=yqjm/B41i5qBAyLwvpSflRx8/5hUKC2E9V+5FdF2wYtTZvLZTPdXbt/z5LMpQdtCP5 kr8PozF/maJT02Blm5CYpTu/E4cNjObyC/6XB5usp8pHhLdAQYUEMSHrpBvlNn/uVNqM QsPFdnFThg25fAeQFJ/Lqkti6oSYIGDH8WbHX9LHdyQUCUW9ficbK80WnAwwoV86XzNb MzkKsKKEbGZ2mfYcmzeWHJjstPCiaxl5mf+bqrOO1ddfoymlI9zl+xoQkKzJW44zJ0hy 4gbrI6v0JX+drjqdu5NZaNzjoJWoZtlIDyMEeZpXYTHzi8YhT1xoo5YArcjE67VMsayx t08w== X-Gm-Message-State: ANoB5pmEeRsgM4sS5bwRbVXaWfeRKTxRSE6dCmhH6QSdK5fZLUo06NRx UiD75dGW6tUwZgCdja1knzk= X-Google-Smtp-Source: AA0mqf7BQH0z+CMvDPYj7fa/bQtmFUxOcVZjiCz5f7v/omcTuMmZRP/HAhi3Gu4DHVM3HC4uWZAyzg== X-Received: by 2002:a17:903:1206:b0:186:a2ef:7a74 with SMTP id l6-20020a170903120600b00186a2ef7a74mr9959273plh.148.1669159957386; Tue, 22 Nov 2022 15:32:37 -0800 (PST) Received: from google.com ([2620:15c:9d:2:af8d:6047:29d5:446c]) by smtp.gmail.com with ESMTPSA id u15-20020a170902e80f00b001869581f7ecsm12712979plg.116.2022.11.22.15.32.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Nov 2022 15:32:36 -0800 (PST) Date: Tue, 22 Nov 2022 15:32:33 -0800 From: Dmitry Torokhov To: Jacky Bai Cc: lee@kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, shawnguo@kernel.org, s.hauer@pengutronix.de, a.zummo@towertech.it, alexandre.belloni@bootlin.com, 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 2/4] input: bbnsm_pwrkey: Add bbnsm power key support Message-ID: References: <20221121065144.3667658-1-ping.bai@nxp.com> <20221121065144.3667658-3-ping.bai@nxp.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20221121065144.3667658-3-ping.bai@nxp.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221122_153244_914610_962FB5D4 X-CRM114-Status: GOOD ( 39.28 ) 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 Hi Jacky, On Mon, Nov 21, 2022 at 02:51:42PM +0800, 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 > --- > drivers/input/keyboard/Kconfig | 11 ++ > drivers/input/keyboard/Makefile | 1 + > drivers/input/keyboard/bbnsm_pwrkey.c | 196 ++++++++++++++++++++++++++ > 3 files changed, 208 insertions(+) > create mode 100644 drivers/input/keyboard/bbnsm_pwrkey.c > > diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig > index 00292118b79b..8efcd95492b3 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..0bc101e004ae 100644 > --- a/drivers/input/keyboard/Makefile > +++ b/drivers/input/keyboard/Makefile > @@ -62,6 +62,7 @@ obj-$(CONFIG_KEYBOARD_QT2160) += qt2160.o > obj-$(CONFIG_KEYBOARD_SAMSUNG) += samsung-keypad.o > obj-$(CONFIG_KEYBOARD_SH_KEYSC) += sh_keysc.o > obj-$(CONFIG_KEYBOARD_SNVS_PWRKEY) += snvs_pwrkey.o > +obj-$(CONFIG_KEYBOARD_BBNSM_PWRKEY) += bbnsm_pwrkey.o > obj-$(CONFIG_KEYBOARD_SPEAR) += spear-keyboard.o > obj-$(CONFIG_KEYBOARD_STMPE) += stmpe-keypad.o > obj-$(CONFIG_KEYBOARD_STOWAWAY) += stowaway.o > diff --git a/drivers/input/keyboard/bbnsm_pwrkey.c b/drivers/input/keyboard/bbnsm_pwrkey.c > new file mode 100644 > index 000000000000..288ee6844000 > --- /dev/null > +++ b/drivers/input/keyboard/bbnsm_pwrkey.c > @@ -0,0 +1,196 @@ > +// 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); Can this fail? > + > + 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)); > + } So interrupt is only generated once when key is pressed, but not on release? > +} > + > +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_regmap_lookup_by_phandle(pdev->dev.of_node, "regmap"); > + 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)) { Please use device_property_read_u32() here. > + 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"); > + error = -ENOMEM; > + goto error_probe; Please return directly here and below, since there is not explicit cleanup. > + } > + > + 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"); > + goto error_probe; > + } > + > + 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"); > + goto error_probe; > + } > + > + error = input_register_device(input); > + if (error < 0) { > + dev_err(&pdev->dev, "failed to register input device\n"); > + goto error_probe; > + } > + > + device_init_wakeup(&pdev->dev, true); > + error = dev_pm_set_wake_irq(&pdev->dev, bbnsm->irq); > + if (error) > + dev_err(&pdev->dev, "irq wake enable failed.\n"); > + > + return 0; > + > +error_probe: > + return error; > +} > + > +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 > Thanks. -- Dmitry _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel