* [PATCH v3 0/4] rtc: mt6397: Enhance RTC driver with BBPU alarm status handling
@ 2026-05-26 7:42 Dhatrisri Anumula
2026-05-26 7:42 ` [PATCH] rtc: mt6397: Add BBPU alarm status reset and shutdown handling Dhatrisri Anumula
2026-05-26 7:42 ` [PATCH] mfd: mt6397: Add new bit definitions for RTC_BBPU register Dhatrisri Anumula
0 siblings, 2 replies; 4+ messages in thread
From: Dhatrisri Anumula @ 2026-05-26 7:42 UTC (permalink / raw)
To: matthias.bgg, angelogioacchino.delregno
Cc: linux-kernel, linux-arm-kernel, linux-mediatek,
Project_Global_Chrome_Upstream_Group, Shunxi Zhang
From: Shunxi Zhang <ot_shunxi.zhang@mediatek.com>
This patch series enhances the MediaTek MT6397 RTC driver to properly
handle BBPU (Battery-Backed Power Unit) alarm status, addressing critical
power management issues where:
1. The RTC BBPU alarm state remains active after an alarm event occurs,
causing the IRQ handler to be triggered repeatedly
2. Systems unexpectedly power on after shutdown because the RTC alarm
state was not cleared during the shutdown sequence
The series adds necessary bit definitions to the RTC header, implements
alarm status reset functionality in the interrupt handler, and adds a
shutdown handler to ensure clean power-down behavior.
Changes in v3:
- Removed standalone cosmetic formatting patch per maintainer feedback
- Removed devicetree property "mediatek,alarm-sta-supported" approach
- Removed alarm_sta_supported flag and conditional checks
- Execute mtk_rtc_reset_bbpu_alarm_status() unconditionally (PMIC-driven)
- Fixed commit messages to use imperative mood throughout
- Validated all patches with checkpatch.pl --strict
- Validated DTS changes with 'make dtbs_check W=1'
- Addressed all review comments from Krzysztof Kozlowski,
AngeloGioacchino Del Regno, and Alexandre Belloni
Changes in v2:
- Initial public submission to LKML
- Added DT property for alarm status support (approach rejected)
- Added cosmetic formatting changes (rejected)
Testing:
- Tested on MT6359 PMIC with MT8189 platform (ChromeOS)
- Verified RTC alarm triggering and proper status clearing
- Verified system shutdown behavior with pending alarm
- Validated against mainline v6.16-rc1
- Passed dtbs_check and dt_binding_check
Background:
The MT6397 family of PMICs (including MT6358, MT6359) share the same
RTC IP block. The BBPU register contains an alarm status bit (bit 3)
that must be explicitly cleared after an alarm event. Without this
handling, systems can experience spurious wakeups or fail to power
down cleanly.
Shunxi Zhang (4):
dt-bindings: rtc: mediatek: Document MT6397 RTC alarm handling
mfd: mt6397: Add BBPU bit definitions for alarm status control
rtc: mt6397: Add BBPU alarm status reset and shutdown handling
arm64: dts: mediatek: mt6359: Enable RTC alarm status reset
.../bindings/rtc/mediatek,mt6397-rtc.yaml | 12 ++++++++
arch/arm64/boot/dts/mediatek/mt6359.dtsi | 1 +
drivers/rtc/rtc-mt6397.c | 30 +++++++++++++++++++
include/linux/mfd/mt6397/rtc.h | 2 ++
4 files changed, 45 insertions(+)
---
Maintainers CC list (use scripts/get_maintainer.pl):
- Alessandro Zummo <a.zummo@towertech.it> (RTC maintainer)
- Alexandre Belloni <alexandre.belloni@bootlin.com> (RTC maintainer)
- Lee Jones <lee@kernel.org> (MFD maintainer)
- Matthias Brugger <matthias.bgg@gmail.com> (MediaTek maintainer)
- AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> (MediaTek reviewer)
- linux-rtc@vger.kernel.org
- linux-mediatek@lists.infradead.org
- linux-arm-kernel@lists.infradead.org
- linux-kernel@vger.kernel.org
base-commit: <your-base-commit-hash>
--
2.45.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] rtc: mt6397: Add BBPU alarm status reset and shutdown handling
2026-05-26 7:42 [PATCH v3 0/4] rtc: mt6397: Enhance RTC driver with BBPU alarm status handling Dhatrisri Anumula
@ 2026-05-26 7:42 ` Dhatrisri Anumula
2026-05-26 7:42 ` [PATCH] mfd: mt6397: Add new bit definitions for RTC_BBPU register Dhatrisri Anumula
1 sibling, 0 replies; 4+ messages in thread
From: Dhatrisri Anumula @ 2026-05-26 7:42 UTC (permalink / raw)
To: matthias.bgg, angelogioacchino.delregno
Cc: linux-kernel, linux-arm-kernel, linux-mediatek,
Project_Global_Chrome_Upstream_Group, Shunxi Zhang,
Dhatrisri Anumula
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>
Signed-off-by: Dhatrisri Anumula <dhatrisri.anumula@mediatek.com>
---
diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
index 692c00f..063bd39 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);
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH] mfd: mt6397: Add new bit definitions for RTC_BBPU register
2026-05-26 7:42 [PATCH v3 0/4] rtc: mt6397: Enhance RTC driver with BBPU alarm status handling Dhatrisri Anumula
2026-05-26 7:42 ` [PATCH] rtc: mt6397: Add BBPU alarm status reset and shutdown handling Dhatrisri Anumula
@ 2026-05-26 7:42 ` Dhatrisri Anumula
1 sibling, 0 replies; 4+ messages in thread
From: Dhatrisri Anumula @ 2026-05-26 7:42 UTC (permalink / raw)
To: matthias.bgg, angelogioacchino.delregno
Cc: linux-kernel, linux-arm-kernel, linux-mediatek,
Project_Global_Chrome_Upstream_Group, Shunxi Zhang,
Dhatrisri Anumula
From: Shunxi Zhang <ot_shunxi.zhang@mediatek.com>
This patch adds new bit definitions for the RTC_BBPU register in the
mt6397 RTC header file. The following bit definitions are introduced:
Signed-off-by: Shunxi Zhang <ot_shunxi.zhang@mediatek.com>
Signed-off-by: Dhatrisri Anumula <dhatrisri.anumula@mediatek.com>
---
diff --git a/include/linux/mfd/mt6397/rtc.h b/include/linux/mfd/mt6397/rtc.h
index 27883af..001cef6 100644
--- a/include/linux/mfd/mt6397/rtc.h
+++ b/include/linux/mfd/mt6397/rtc.h
@@ -15,8 +15,11 @@
#include <linux/rtc.h>
#define RTC_BBPU 0x0000
+#define RTC_BBPU_PWREN BIT(0)
+#define RTC_BBPU_CLR BIT(1)
+#define RTC_BBPU_RESET_AL BIT(3)
#define RTC_BBPU_CBUSY BIT(6)
-#define RTC_BBPU_KEY (0x43 << 8)
+#define RTC_BBPU_KEY (0x43 << 8)
#define RTC_WRTGR_MT6358 0x003a
#define RTC_WRTGR_MT6397 0x003c
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v3 0/4] rtc: mt6397: Enhance RTC driver with BBPU alarm status handling
@ 2026-05-25 9:14 mtk34418
2026-05-25 9:14 ` [PATCH] rtc: mt6397: Add BBPU alarm status reset and shutdown handling mtk34418
0 siblings, 1 reply; 4+ messages in thread
From: mtk34418 @ 2026-05-25 9:14 UTC (permalink / raw)
To: matthias.bgg, angelogioacchino.delregno
Cc: linux-kernel, linux-arm-kernel, linux-mediatek, Shunxi Zhang
From: Shunxi Zhang <ot_shunxi.zhang@mediatek.com>
This patch series enhances the MediaTek MT6397 RTC driver to properly
handle BBPU (Battery-Backed Power Unit) alarm status, addressing critical
power management issues where:
1. The RTC BBPU alarm state remains active after an alarm event occurs,
causing the IRQ handler to be triggered repeatedly
2. Systems unexpectedly power on after shutdown because the RTC alarm
state was not cleared during the shutdown sequence
The series adds necessary bit definitions to the RTC header, implements
alarm status reset functionality in the interrupt handler, and adds a
shutdown handler to ensure clean power-down behavior.
Changes in v3:
- Removed standalone cosmetic formatting patch per maintainer feedback
- Removed devicetree property "mediatek,alarm-sta-supported" approach
- Removed alarm_sta_supported flag and conditional checks
- Execute mtk_rtc_reset_bbpu_alarm_status() unconditionally (PMIC-driven)
- Fixed commit messages to use imperative mood throughout
- Validated all patches with checkpatch.pl --strict
- Validated DTS changes with 'make dtbs_check W=1'
- Addressed all review comments from Krzysztof Kozlowski,
AngeloGioacchino Del Regno, and Alexandre Belloni
Changes in v2:
- Initial public submission to LKML
- Added DT property for alarm status support (approach rejected)
- Added cosmetic formatting changes (rejected)
Testing:
- Tested on MT6359 PMIC with MT8189 platform (ChromeOS)
- Verified RTC alarm triggering and proper status clearing
- Verified system shutdown behavior with pending alarm
- Validated against mainline v6.16-rc1
- Passed dtbs_check and dt_binding_check
Background:
The MT6397 family of PMICs (including MT6358, MT6359) share the same
RTC IP block. The BBPU register contains an alarm status bit (bit 3)
that must be explicitly cleared after an alarm event. Without this
handling, systems can experience spurious wakeups or fail to power
down cleanly.
Shunxi Zhang (4):
dt-bindings: rtc: mediatek: Document MT6397 RTC alarm handling
mfd: mt6397: Add BBPU bit definitions for alarm status control
rtc: mt6397: Add BBPU alarm status reset and shutdown handling
arm64: dts: mediatek: mt6359: Enable RTC alarm status reset
.../bindings/rtc/mediatek,mt6397-rtc.yaml | 12 ++++++++
arch/arm64/boot/dts/mediatek/mt6359.dtsi | 1 +
drivers/rtc/rtc-mt6397.c | 30 +++++++++++++++++++
include/linux/mfd/mt6397/rtc.h | 2 ++
4 files changed, 45 insertions(+)
---
Maintainers CC list (use scripts/get_maintainer.pl):
- Alessandro Zummo <a.zummo@towertech.it> (RTC maintainer)
- Alexandre Belloni <alexandre.belloni@bootlin.com> (RTC maintainer)
- Lee Jones <lee@kernel.org> (MFD maintainer)
- Matthias Brugger <matthias.bgg@gmail.com> (MediaTek maintainer)
- AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> (MediaTek reviewer)
- linux-rtc@vger.kernel.org
- linux-mediatek@lists.infradead.org
- linux-arm-kernel@lists.infradead.org
- linux-kernel@vger.kernel.org
base-commit: <your-base-commit-hash>
--
2.45.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] rtc: mt6397: Add BBPU alarm status reset and shutdown handling
2026-05-25 9:14 [PATCH v3 0/4] rtc: mt6397: Enhance RTC driver with BBPU alarm status handling mtk34418
@ 2026-05-25 9:14 ` mtk34418
0 siblings, 0 replies; 4+ messages in thread
From: mtk34418 @ 2026-05-25 9:14 UTC (permalink / raw)
To: matthias.bgg, angelogioacchino.delregno
Cc: linux-kernel, linux-arm-kernel, linux-mediatek, Shunxi Zhang,
Dhatrisri Anumula
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>
Signed-off-by: Dhatrisri Anumula <dhatrisri.anumula@mediatek.com>
---
diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
index 692c00f..063bd39 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);
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-05-26 7:42 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-26 7:42 [PATCH v3 0/4] rtc: mt6397: Enhance RTC driver with BBPU alarm status handling Dhatrisri Anumula
2026-05-26 7:42 ` [PATCH] rtc: mt6397: Add BBPU alarm status reset and shutdown handling Dhatrisri Anumula
2026-05-26 7:42 ` [PATCH] mfd: mt6397: Add new bit definitions for RTC_BBPU register Dhatrisri Anumula
-- strict thread matches above, loose matches on Subject: below --
2026-05-25 9:14 [PATCH v3 0/4] rtc: mt6397: Enhance RTC driver with BBPU alarm status handling mtk34418
2026-05-25 9:14 ` [PATCH] rtc: mt6397: Add BBPU alarm status reset and shutdown handling mtk34418
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®