[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <76325c39-ea88-48fe-b32d-00c1e0d31024@collabora.com>
Date: Thu, 20 Nov 2025 15:42:10 +0100
From: AngeloGioacchino Del Regno <angelogioacchino.delregno@...labora.com>
To: ot_shunxi.zhang@...iatek.com, Rob Herring <robh@...nel.org>,
Krzysztof Kozlowski <krzk+dt@...nel.org>, Conor Dooley
<conor+dt@...nel.org>, Matthias Brugger <matthias.bgg@...il.com>,
Eddie Huang <eddie.huang@...iatek.com>, Sean Wang <sean.wang@...iatek.com>,
Alexandre Belloni <alexandre.belloni@...tlin.com>, Lee Jones
<lee@...nel.org>, Vince-WL.Liu@...iatek.com, sirius.wang@...iatek.com,
Jh.Hsu@...iatek.com
Cc: devicetree@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-arm-kernel@...ts.infradead.org, linux-mediatek@...ts.infradead.org
Subject: Re: [PATCH v2 4/5] rtc: mt6397: Add BBPU alarm status reset and
shutdown handling
Il 20/11/25 13:18, ot_shunxi.zhang@...iatek.com ha scritto:
> From: Shunxi Zhang <ot_shunxi.zhang@...iatek.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@...iatek.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
> +
> 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);
Powered by blists - more mailing lists