From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: Jacky Bai <ping.bai@nxp.com>
Cc: 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, 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 3/4] rtc: bbnsm: Add the bbnsm rtc support
Date: Tue, 22 Nov 2022 19:18:59 +0100 [thread overview]
Message-ID: <Y30Sk+ftJQ5XJQZF@mail.local> (raw)
In-Reply-To: <20221121065144.3667658-4-ping.bai@nxp.com>
On 21/11/2022 14:51:43+0800, Jacky Bai wrote:
> The BBNSM module includes a real time counter with alarm.
> Add a RTC driver for this function.
>
> Signed-off-by: Jacky Bai <ping.bai@nxp.com>
> Reviewed-by: Peng Fan <peng.fan@nxp.com>
> ---
> drivers/rtc/Kconfig | 12 +++
> drivers/rtc/Makefile | 1 +
> drivers/rtc/rtc-bbnsm.c | 223 ++++++++++++++++++++++++++++++++++++++++
I'd prefer that filename to include imx or mxc if this is only available
on those SoCs.
> diff --git a/drivers/rtc/rtc-bbnsm.c b/drivers/rtc/rtc-bbnsm.c
> new file mode 100644
> index 000000000000..4157b238ed9a
> --- /dev/null
> +++ b/drivers/rtc/rtc-bbnsm.c
> @@ -0,0 +1,223 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +//
> +// Copyright 2022 NXP.
> +
> +#include <linux/init.h>
> +#include <linux/io.h>
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <linux/platform_device.h>
> +#include <linux/pm_wakeirq.h>
> +#include <linux/rtc.h>
> +#include <linux/mfd/syscon.h>
> +#include <linux/regmap.h>
This list should be sorted alphabetically
> +
> +#define BBNSM_CTRL 0x8
> +#define BBNSM_INT_EN 0x10
> +#define BBNSM_EVENTS 0x14
> +#define BBNSM_RTC_LS 0x40
> +#define BBNSM_RTC_MS 0x44
> +#define BBNSM_TA 0x50
> +
> +#define RTC_EN 0x2
> +#define RTC_EN_MSK 0x3
> +#define TA_EN (0x2 << 2)
> +#define TA_DIS (0x1 << 2)
> +#define TA_EN_MSK (0x3 << 2)
> +#define RTC_INT_EN 0x2
> +#define TA_INT_EN (0x2 << 2)
> +
> +#define BBNSM_EVENT_TA TA_EN
> +
I'm not clear why this define is needed
> +static irqreturn_t bbnsm_rtc_irq_handler(int irq, void *dev_id)
> +{
> + struct device *dev = dev_id;
> + struct bbnsm_rtc *bbnsm = dev_get_drvdata(dev);
> + u32 val;
> + u32 event = 0;
You can rework this function to remove this variable because it is
either 0 or RTC_AF | RTC_IRQF
> +
> + regmap_read(bbnsm->regmap, BBNSM_EVENTS, &val);
> + if (val & BBNSM_EVENT_TA) {
> + event |= (RTC_AF | RTC_IRQF);
> + bbnsm_rtc_alarm_irq_enable(dev, false);
> + /* clear the alarm event */
> + regmap_write_bits(bbnsm->regmap, BBNSM_EVENTS, TA_EN_MSK, BBNSM_EVENT_TA);
> + rtc_update_irq(bbnsm->rtc, 1, event);
> + }
> +
> + return event ? IRQ_HANDLED : IRQ_NONE;
> +}
> +
> +static int bbnsm_rtc_probe(struct platform_device *pdev)
> +{
> + struct bbnsm_rtc *bbnsm;
> + int ret;
> +
> + bbnsm = devm_kzalloc(&pdev->dev, sizeof(*bbnsm), GFP_KERNEL);
> + if (!bbnsm)
> + return -ENOMEM;
> +
> + bbnsm->rtc = devm_rtc_allocate_device(&pdev->dev);
> +
> + bbnsm->regmap = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, "regmap");
> + if (IS_ERR(bbnsm->regmap)) {
> + dev_err(&pdev->dev, "bbnsm get regmap failed\n");
> + return PTR_ERR(bbnsm->regmap);
> + }
> +
> + bbnsm->irq = platform_get_irq(pdev, 0);
> + if (bbnsm->irq < 0)
> + return bbnsm->irq;
> +
> + platform_set_drvdata(pdev, bbnsm);
> +
> + /* clear all the pending events */
> + regmap_write(bbnsm->regmap, BBNSM_EVENTS, 0x7A);
> +
> + /* Enable the Real-Time counter */
> + regmap_update_bits(bbnsm->regmap, BBNSM_CTRL, RTC_EN_MSK, RTC_EN);
> +
Please don't do that, this removes an important piece of information.
Instead, let .set_time enable it and check it in .read_time as if this
is not set, you now you are out of PoR and the time is invalid
> + device_init_wakeup(&pdev->dev, true);
> + ret = dev_pm_set_wake_irq(&pdev->dev, bbnsm->irq);
> + if (ret)
> + dev_err(&pdev->dev, "Failed to enable the irq wakeup\n");
dev_err but the function is not failing. Maybe just dev_warn? Also, is
this message really necessary?
> +
> + ret = devm_request_irq(&pdev->dev, bbnsm->irq, bbnsm_rtc_irq_handler,
> + IRQF_SHARED, "rtc alarm", &pdev->dev);
> + if (ret) {
> + dev_err(&pdev->dev, "failed to request irq %d: %d\n",
> + bbnsm->irq, ret);
> + return ret;
> + }
> +
> + bbnsm->rtc->ops = &bbnsm_rtc_ops;
> + bbnsm->rtc->range_max = U32_MAX;
> +
> + return devm_rtc_register_device(bbnsm->rtc);
> +}
> +
> +static const struct of_device_id bbnsm_dt_ids[] = {
> + { .compatible = "nxp,bbnsm-rtc", },
> + { /* sentinel */ },
> +};
> +MODULE_DEVICE_TABLE(of, bbnsm_dt_ids);
> +
> +static struct platform_driver bbnsm_rtc_driver = {
> + .driver = {
> + .name = "bbnsm_rtc",
> + .of_match_table = bbnsm_dt_ids,
> + },
> + .probe = bbnsm_rtc_probe,
> +};
> +module_platform_driver(bbnsm_rtc_driver);
> +
> +MODULE_AUTHOR("Jacky Bai <ping.bai@nxp.com>");
> +MODULE_DESCRIPTION("NXP BBNSM RTC Driver");
> +MODULE_LICENSE("GPL");
> --
> 2.37.1
>
--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
next prev parent reply other threads:[~2022-11-22 18:19 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-21 6:51 [PATCH 0/4] Add nxp bbnsm module support Jacky Bai
2022-11-21 6:51 ` [PATCH 1/4] dt-bindings: mfd: nxp,bbnsm: Add binding for nxp bbnsm Jacky Bai
2022-11-21 9:09 ` Krzysztof Kozlowski
2022-11-21 9:27 ` Alexandre Belloni
2022-11-21 10:33 ` Jacky Bai
2022-11-21 11:10 ` Alexandre Belloni
2022-11-21 13:45 ` Jacky Bai
2022-11-22 13:16 ` Alexandre Belloni
2022-11-23 7:50 ` Jacky Bai
2022-11-21 10:26 ` Jacky Bai
2022-11-21 12:28 ` Lee Jones
2022-11-22 7:59 ` Krzysztof Kozlowski
2022-11-23 7:43 ` Jacky Bai
2022-11-23 7:58 ` Krzysztof Kozlowski
2022-11-21 9:18 ` Krzysztof Kozlowski
2022-11-21 10:30 ` Jacky Bai
2022-11-22 7:59 ` Krzysztof Kozlowski
2022-11-22 20:28 ` Rob Herring
2022-11-23 7:54 ` Jacky Bai
2022-11-23 9:31 ` Krzysztof Kozlowski
2022-11-23 9:35 ` Jacky Bai
2022-11-21 6:51 ` [PATCH 2/4] input: bbnsm_pwrkey: Add bbnsm power key support Jacky Bai
2022-11-22 23:32 ` Dmitry Torokhov
2022-11-23 9:39 ` Jacky Bai
2022-11-21 6:51 ` [PATCH 3/4] rtc: bbnsm: Add the bbnsm rtc support Jacky Bai
2022-11-22 18:18 ` Alexandre Belloni [this message]
2022-11-23 9:25 ` Jacky Bai
2022-11-21 6:51 ` [PATCH 4/4] arm64: dts: imx93: Add the bbnsm dts node Jacky Bai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y30Sk+ftJQ5XJQZF@mail.local \
--to=alexandre.belloni@bootlin.com \
--cc=a.zummo@towertech.it \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=festevam@gmail.com \
--cc=kernel@pengutronix.de \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=lee@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-imx@nxp.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-rtc@vger.kernel.org \
--cc=ping.bai@nxp.com \
--cc=robh+dt@kernel.org \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).