rtc: mt6397: Enhance RTC driver with BBPU alarm status handling
Subsystems (4)
v3 cover rtc: mt6397: Enhance RTC driver with BBPU alarm status handling
From: Shunxi Zhang <[email protected]>
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 <[email protected]> (RTC maintainer)
- Alexandre Belloni <[email protected]> (RTC maintainer)
- Lee Jones <[email protected]> (MFD maintainer)
- Matthias Brugger <[email protected]> (MediaTek maintainer)
- AngeloGioacchino Del Regno <[email protected]> (MediaTek reviewer)
- [email protected]
- [email protected]
- [email protected]
- [email protected]
base-commit: <your-base-commit-hash>
--
2.45.2
PATCH 1/1 rtc: mt6397: Add BBPU alarm status reset and shutdown handling
From: Shunxi Zhang <[email protected]>
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.
---
drivers/rtc/rtc-mt6397.c +35 -1
@@ -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);
PATCH 1/1 mfd: mt6397: Add new bit definitions for RTC_BBPU register
In reply to Dhatrisri AnumulaFrom: Shunxi Zhang <[email protected]>
This patch adds new bit definitions for the RTC_BBPU register in the mt6397 RTC header file. The following bit definitions are introduced:
---
include/linux/mfd/mt6397/rtc.h +4 -1
@@ -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