From: "Shunxi Zhang (章顺喜)" <ot_shunxi.zhang@mediatek.com>
To: "Eddie Huang (黃智傑)" <eddie.huang@mediatek.com>,
"alexandre.belloni@bootlin.com" <alexandre.belloni@bootlin.com>,
"Vince-WL Liu (劉文龍)" <Vince-WL.Liu@mediatek.com>,
"Jh Hsu (許希孜)" <Jh.Hsu@mediatek.com>,
"Sean Wang" <Sean.Wang@mediatek.com>,
"conor+dt@kernel.org" <conor+dt@kernel.org>,
"robh@kernel.org" <robh@kernel.org>,
"lee@kernel.org" <lee@kernel.org>,
"matthias.bgg@gmail.com" <matthias.bgg@gmail.com>,
"Sirius Wang (王皓昱)" <Sirius.Wang@mediatek.com>,
"krzk+dt@kernel.org" <krzk+dt@kernel.org>,
"AngeloGioacchino Del Regno"
<angelogioacchino.delregno@collabora.com>
Cc: "linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-mediatek@lists.infradead.org"
<linux-mediatek@lists.infradead.org>,
"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>
Subject: Re: [PATCH v2 4/5] rtc: mt6397: Add BBPU alarm status reset and shutdown handling
Date: Fri, 21 Nov 2025 03:43:05 +0000 [thread overview]
Message-ID: <b577d8395885af0603710d2d83cab71707696568.camel@mediatek.com> (raw)
In-Reply-To: <76325c39-ea88-48fe-b32d-00c1e0d31024@collabora.com>
On Thu, 2025-11-20 at 15:42 +0100, AngeloGioacchino Del Regno wrote:
> External email : Please do not click links or open attachments until
> you have verified the sender or the content.
>
>
> Il 20/11/25 13:18, ot_shunxi.zhang@mediatek.com ha scritto:
> > From: Shunxi Zhang <ot_shunxi.zhang@mediatek.com>
> >
> > Function "mtk_rtc_reset_bbpu_alarm_status" is added to address the
> > issue that the RTC BBPU alarm state remains after the RTC alarm
> > has occurred.
> >
> > Additionally, function "mtk_rtc_shutdown" is added to address the
> > issue of the platform being powered on again after shutdown because
> > the RTC_BBPU alarm state was not cleared.
> >
> > Signed-off-by: Shunxi Zhang <ot_shunxi.zhang@mediatek.com>
> > ---
> > drivers/rtc/rtc-mt6397.c | 30 ++++++++++++++++++++++++++++++
> > 1 file changed, 30 insertions(+)
> >
> > diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
> > index b8f44a00de5d..8bf7e0822ef0 100644
> > --- a/drivers/rtc/rtc-mt6397.c
> > +++ b/drivers/rtc/rtc-mt6397.c
> > @@ -37,6 +37,21 @@ static int mtk_rtc_write_trigger(struct
> > mt6397_rtc *rtc)
> > return ret;
> > }
> >
> > +static void mtk_rtc_reset_bbpu_alarm_status(struct mt6397_rtc
> > *rtc)
> > +{
> > + u32 bbpu = RTC_BBPU_KEY | RTC_BBPU_PWREN | RTC_BBPU_RESET_AL;
> > + int ret;
> > +
> > + ret = regmap_write(rtc->regmap, rtc->addr_base + RTC_BBPU,
> > bbpu);
> > + if (ret < 0) {
> > + dev_err(rtc->rtc_dev->dev.parent, "%s: write rtc bbpu
> > error\n",
> > + __func__);
> > + return;
> > + }
> > +
> > + mtk_rtc_write_trigger(rtc);
> > +}
> > +
> > static irqreturn_t mtk_rtc_irq_handler_thread(int irq, void
> > *data)
> > {
> > struct mt6397_rtc *rtc = data;
> > @@ -51,6 +66,9 @@ static irqreturn_t mtk_rtc_irq_handler_thread(int
> > irq, void *data)
> > if (regmap_write(rtc->regmap, rtc->addr_base +
> > RTC_IRQ_EN,
> > irqen) == 0)
> > mtk_rtc_write_trigger(rtc);
> > +
> > + if (rtc->alarm_sta_supported)
> > + mtk_rtc_reset_bbpu_alarm_status(rtc);
> > mutex_unlock(&rtc->lock);
> >
> > return IRQ_HANDLED;
> > @@ -249,6 +267,7 @@ static int mtk_rtc_probe(struct platform_device
> > *pdev)
> > struct resource *res;
> > struct mt6397_chip *mt6397_chip = dev_get_drvdata(pdev-
> > >dev.parent);
> > struct mt6397_rtc *rtc;
> > + struct device_node *np = pdev->dev.of_node;
> > int ret;
> >
> > rtc = devm_kzalloc(&pdev->dev, sizeof(struct mt6397_rtc),
> > GFP_KERNEL);
> > @@ -275,6 +294,8 @@ static int mtk_rtc_probe(struct platform_device
> > *pdev)
> > if (IS_ERR(rtc->rtc_dev))
> > return PTR_ERR(rtc->rtc_dev);
> >
> > + rtc->alarm_sta_supported = of_property_read_bool(np,
> > "mediatek,alarm-sta-supported");
>
> You don't need a DT property - the PMIC dictates support for that,
> not the board.
>
> This means that you also don't need the alarm_sta_supported variable,
> and you
> don't need to check for it.
>
> Just execute the mtk_rtc_reset_bbpu_alarm_status() function when you
> have to,
> without any check.
>
> Cheers,
> Angelo
Dear sir,
Thanks for your comment. This check is base on the last comment(
https://patchwork.kernel.org/project/linux-mediatek/patch/20250811081543.4377-2-ot_shunxi.zhang@mediatek.com/#26517538
) reply:
"The MT6397 is an integration of several ICs and does not have a
separate IC specification. I will check the relevant IC datasheets
again. I will remove the useless define in next version".
Only the MT6359 has the "BBPU alarm status" function, so this attribute
needs to be added to the RTC function in MT6359.dtsi for judgment. This
ensures compatibility with other PMICs (MT6358, etc.) in rtc-mt6397.c.
Excuse me, do you have any further suggestions on better compatibility?
I will improve and modify it in the next version.
Best Regards
Shunxi Zhang
>
> > +
> > ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL,
> > mtk_rtc_irq_handler_thread,
> > IRQF_ONESHOT |
> > IRQF_TRIGGER_HIGH,
> > @@ -297,6 +318,14 @@ static int mtk_rtc_probe(struct
> > platform_device *pdev)
> > return devm_rtc_register_device(rtc->rtc_dev);
> > }
> >
> > +static void mtk_rtc_shutdown(struct platform_device *pdev)
> > +{
> > + struct mt6397_rtc *rtc = platform_get_drvdata(pdev);
> > +
> > + if (rtc->alarm_sta_supported)
> > + mtk_rtc_reset_bbpu_alarm_status(rtc);
> > +}
> > +
> > #ifdef CONFIG_PM_SLEEP
> > static int mt6397_rtc_suspend(struct device *dev)
> > {
> > @@ -346,6 +375,7 @@ static struct platform_driver mtk_rtc_driver =
> > {
> > .pm = &mt6397_pm_ops,
> > },
> > .probe = mtk_rtc_probe,
> > + .shutdown = mtk_rtc_shutdown,
> > };
> >
> > module_platform_driver(mtk_rtc_driver);
>
>
next prev parent reply other threads:[~2025-11-21 3:43 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-20 12:17 [PATCH v2 0/5] rtc: Enhance RTC driver with BBPU bit definitions " ot_shunxi.zhang
2025-11-20 12:17 ` [PATCH v2 1/5] mfd: mt6397: Fix formatting of RTC_BBPU_KEY definition ot_shunxi.zhang
2025-11-20 13:38 ` Krzysztof Kozlowski
2025-11-21 3:07 ` Shunxi Zhang (章顺喜)
2025-11-21 7:20 ` Krzysztof Kozlowski
2025-11-20 12:17 ` [PATCH v2 2/5] mfd: mt6397: Add bit definitions and struct members to support alarm status ot_shunxi.zhang
2025-11-20 12:17 ` [PATCH v2 3/5] rtc: mt6397: Fix formatting of platform driver structure ot_shunxi.zhang
2025-11-20 13:38 ` Krzysztof Kozlowski
2025-11-21 3:14 ` Shunxi Zhang (章顺喜)
2025-11-20 13:59 ` Alexandre Belloni
2025-11-20 12:18 ` [PATCH v2 4/5] rtc: mt6397: Add BBPU alarm status reset and shutdown handling ot_shunxi.zhang
2025-11-20 13:40 ` Krzysztof Kozlowski
2025-11-21 3:20 ` Shunxi Zhang (章顺喜)
2025-11-20 14:42 ` AngeloGioacchino Del Regno
2025-11-21 3:43 ` Shunxi Zhang (章顺喜) [this message]
2025-11-20 12:18 ` [PATCH v2 5/5] arm64: dts: mediatek: mt6359: Add alarm-sta-supported property to RTC node ot_shunxi.zhang
2025-11-20 13:39 ` Krzysztof Kozlowski
2025-11-21 3:25 ` Shunxi Zhang (章顺喜)
2025-11-20 14:14 ` [PATCH v2 0/5] rtc: Enhance RTC driver with BBPU bit definitions and shutdown handling Rob Herring
2025-11-21 2:45 ` Shunxi Zhang (章顺喜)
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=b577d8395885af0603710d2d83cab71707696568.camel@mediatek.com \
--to=ot_shunxi.zhang@mediatek.com \
--cc=Jh.Hsu@mediatek.com \
--cc=Sean.Wang@mediatek.com \
--cc=Sirius.Wang@mediatek.com \
--cc=Vince-WL.Liu@mediatek.com \
--cc=alexandre.belloni@bootlin.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=eddie.huang@mediatek.com \
--cc=krzk+dt@kernel.org \
--cc=lee@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=matthias.bgg@gmail.com \
--cc=robh@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
all inboxes | Powered by JetHome®