From: Shunxi Zhang <ot_shunxi.zhang@mediatek.com>
This patch introduces a new function, mtk_rtc_reset_bbpu_alarm_status,
to reset the BBPU alarm status in the MT6397 RTC driver. This function
writes the necessary bits to the RTC_BBPU register to clear the alarm
status and ensure proper operation.
Additionally, the mtk_rtc_shutdown function is added to handle RTC
shutdown events. It resets the BBPU alarm status and updates the
RTC_IRQ_EN register to disable the one-shot alarm interrupt,
ensuring a clean shutdown process.
Signed-off-by: Shunxi Zhang <ot_shunxi.zhang@mediatek.com>
---
drivers/rtc/rtc-mt6397.c | 36 +++++++++++++++++++++++++++++++++++-
1 file changed, 35 insertions(+), 1 deletion(-)
diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
index 692c00ff544b..063bd399de8c 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,8 @@ 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);
+
+ mtk_rtc_reset_bbpu_alarm_status(rtc);
mutex_unlock(&rtc->lock);
return IRQ_HANDLED;
@@ -297,6 +314,22 @@ 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);
+ int ret = 0;
+
+ mtk_rtc_reset_bbpu_alarm_status(rtc);
+
+ ret = regmap_update_bits(rtc->regmap,
+ rtc->addr_base + RTC_IRQ_EN,
+ RTC_IRQ_EN_ONESHOT_AL, 0);
+ if (ret < 0)
+ return;
+
+ mtk_rtc_write_trigger(rtc);
+}
+
#ifdef CONFIG_PM_SLEEP
static int mt6397_rtc_suspend(struct device *dev)
{
@@ -345,7 +378,8 @@ static struct platform_driver mtk_rtc_driver = {
.of_match_table = mt6397_rtc_of_match,
.pm = &mt6397_pm_ops,
},
- .probe = mtk_rtc_probe,
+ .probe = mtk_rtc_probe,
+ .shutdown = mtk_rtc_shutdown,
};
module_platform_driver(mtk_rtc_driver);
--
2.46.0
On 11/08/2025 16:15:34+0800, ot_shunxi.zhang@mediatek.com wrote: > From: Shunxi Zhang <ot_shunxi.zhang@mediatek.com> > > This patch introduces a new function, mtk_rtc_reset_bbpu_alarm_status, > to reset the BBPU alarm status in the MT6397 RTC driver. This function > writes the necessary bits to the RTC_BBPU register to clear the alarm > status and ensure proper operation. > > Additionally, the mtk_rtc_shutdown function is added to handle RTC > shutdown events. It resets the BBPU alarm status and updates the > RTC_IRQ_EN register to disable the one-shot alarm interrupt, > ensuring a clean shutdown process. > > Signed-off-by: Shunxi Zhang <ot_shunxi.zhang@mediatek.com> > --- > drivers/rtc/rtc-mt6397.c | 36 +++++++++++++++++++++++++++++++++++- > 1 file changed, 35 insertions(+), 1 deletion(-) > > diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c > index 692c00ff544b..063bd399de8c 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,8 @@ 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); > + > + mtk_rtc_reset_bbpu_alarm_status(rtc); > mutex_unlock(&rtc->lock); > > return IRQ_HANDLED; > @@ -297,6 +314,22 @@ 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); > + int ret = 0; > + > + mtk_rtc_reset_bbpu_alarm_status(rtc); > + > + ret = regmap_update_bits(rtc->regmap, > + rtc->addr_base + RTC_IRQ_EN, > + RTC_IRQ_EN_ONESHOT_AL, 0); > + if (ret < 0) > + return; > + > + mtk_rtc_write_trigger(rtc); The whole goal of the RTC is to wakeup the system, why would you disable the alarm on shutdown? > +} > + > #ifdef CONFIG_PM_SLEEP > static int mt6397_rtc_suspend(struct device *dev) > { > @@ -345,7 +378,8 @@ static struct platform_driver mtk_rtc_driver = { > .of_match_table = mt6397_rtc_of_match, > .pm = &mt6397_pm_ops, > }, > - .probe = mtk_rtc_probe, > + .probe = mtk_rtc_probe, > + .shutdown = mtk_rtc_shutdown, > }; > > module_platform_driver(mtk_rtc_driver); > -- > 2.46.0 > -- Alexandre Belloni, co-owner and COO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
On Mon, 2025-08-11 at 15:09 +0200, Alexandre Belloni wrote: > External email : Please do not click links or open attachments until > you have verified the sender or the content. > > > On 11/08/2025 16:15:34+0800, ot_shunxi.zhang@mediatek.com wrote: > > From: Shunxi Zhang <ot_shunxi.zhang@mediatek.com> > > > > This patch introduces a new function, > > mtk_rtc_reset_bbpu_alarm_status, > > to reset the BBPU alarm status in the MT6397 RTC driver. This > > function > > writes the necessary bits to the RTC_BBPU register to clear the > > alarm > > status and ensure proper operation. > > > > Additionally, the mtk_rtc_shutdown function is added to handle RTC > > shutdown events. It resets the BBPU alarm status and updates the > > RTC_IRQ_EN register to disable the one-shot alarm interrupt, > > ensuring a clean shutdown process. > > > > Signed-off-by: Shunxi Zhang <ot_shunxi.zhang@mediatek.com> > > --- > > drivers/rtc/rtc-mt6397.c | 36 +++++++++++++++++++++++++++++++++++- > > 1 file changed, 35 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c > > index 692c00ff544b..063bd399de8c 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,8 @@ 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); > > + > > + mtk_rtc_reset_bbpu_alarm_status(rtc); > > mutex_unlock(&rtc->lock); > > > > return IRQ_HANDLED; > > @@ -297,6 +314,22 @@ 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); > > + int ret = 0; > > + > > + mtk_rtc_reset_bbpu_alarm_status(rtc); > > + > > + ret = regmap_update_bits(rtc->regmap, > > + rtc->addr_base + RTC_IRQ_EN, > > + RTC_IRQ_EN_ONESHOT_AL, 0); > > + if (ret < 0) > > + return; > > + > > + mtk_rtc_write_trigger(rtc); > > The whole goal of the RTC is to wakeup the system, why would you > disable > the alarm on shutdown? Dear sir, I will remove the flow of "disable alarm shutdown" in next version. thanks for your comments. Best regards shunxi zhang > > > +} > > + > > #ifdef CONFIG_PM_SLEEP > > static int mt6397_rtc_suspend(struct device *dev) > > { > > @@ -345,7 +378,8 @@ static struct platform_driver mtk_rtc_driver = > > { > > .of_match_table = mt6397_rtc_of_match, > > .pm = &mt6397_pm_ops, > > }, > > - .probe = mtk_rtc_probe, > > + .probe = mtk_rtc_probe, > > + .shutdown = mtk_rtc_shutdown, > > }; > > > > module_platform_driver(mtk_rtc_driver); > > -- > > 2.46.0 > > > > -- > Alexandre Belloni, co-owner and COO, Bootlin > Embedded Linux and Kernel engineering > https://urldefense.com/v3/__https://bootlin.com__;!!CTRNKA9wMg0ARbw!hGMitEEUU-sbH-rcMCMQ4Vlsn7NQeHdUrg9nEKYPyDME5fkbgsVciZd8SURxkvWA9Z1qX3oyNVZEWvVatYExZ8D7cFvdiyS_3Q_6$
© 2016 - 2025 Red Hat, Inc.