mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
To: ot_shunxi.zhang@mediatek.com, Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	Eddie Huang <eddie.huang@mediatek.com>,
	Sean Wang <sean.wang@mediatek.com>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Lee Jones <lee@kernel.org>,
	Vince-WL.Liu@mediatek.com, sirius.wang@mediatek.com,
	Jh.Hsu@mediatek.com
Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org
Subject: Re: [PATCH v2 4/5] rtc: mt6397: Add BBPU alarm status reset and shutdown handling
Date: Thu, 20 Nov 2025 15:42:10 +0100	[thread overview]
Message-ID: <76325c39-ea88-48fe-b32d-00c1e0d31024@collabora.com> (raw)
In-Reply-To: <20251120121805.6775-5-ot_shunxi.zhang@mediatek.com>

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

> +
>   	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);



  parent reply	other threads:[~2025-11-20 14:42 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 [this message]
2025-11-21  3:43     ` Shunxi Zhang (章顺喜)
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=76325c39-ea88-48fe-b32d-00c1e0d31024@collabora.com \
    --to=angelogioacchino.delregno@collabora.com \
    --cc=Jh.Hsu@mediatek.com \
    --cc=Vince-WL.Liu@mediatek.com \
    --cc=alexandre.belloni@bootlin.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=ot_shunxi.zhang@mediatek.com \
    --cc=robh@kernel.org \
    --cc=sean.wang@mediatek.com \
    --cc=sirius.wang@mediatek.com \
    /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®