* [PATCH v3 0/2] rtc: mt6397: provide the RTC's 32 kHz output as a clock
@ 2026-11-16 18:46 Ryan Brue
2026-11-16 18:46 ` [PATCH v3 1/2] rtc: mt6397: rename the write trigger register offset Ryan Brue
2026-11-16 18:46 ` [PATCH v3 2/2] rtc: mt6397: provide the 32 kHz output as a clock Ryan Brue
0 siblings, 2 replies; 5+ messages in thread
From: Ryan Brue @ 2026-11-16 18:46 UTC (permalink / raw)
To: Sen Chu, Sean Wang, Macpaul Lin, Lee Jones, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Matthias Brugger,
AngeloGioacchino Del Regno, Eddie Huang, Alexandre Belloni
Cc: linux-pm, mfd, devicetree, linux-kernel, linux-arm-kernel,
linux-mediatek, linux-rtc, Ryan Brue
The MT6397 RTC drives a 32 kHz clock out of the PMIC, which boards use as
the sleep clock of a Wi-Fi/Bluetooth combo chip. RTC_CON.F32KOB gates it,
and mainline never touches that bit, so the chip only works if the
bootloader happened to turn the output on.
On the Amazon Fire HD 10 (2017), which can boot through U-Boot instead of
the vendor's LK, nothing sets it in the former - LK sets the bit at every
boot, and the MT6630 combo chip's Wi-Fi and Bluetooth never come up.
Letting the RTC provide the output as a clock lets the chip's
mmc-pwrseq-simple enable it. With the clock wired up both came up on that
board in two boots out of two, and in none of three without it.
The driver registers the clock only when the RTC node has #clock-cells,
so no existing board changes. The MT6323 shares the MT6397's driver data
and gets it too; every MediaTek PMIC RTC whose registers I could read has
F32KOB at bit 5 of RTC_CON, but for the MT6323 that is inferred from the
shared driver data rather than read from a datasheet.
Lee has applied the binding to mfd [1], so v3 is the driver part only:
patch 1 gives the existing write trigger member a name that says what it
is, as Lee asked for the new one, and patch 2 adds the clock. Both are
for rtc.
The board's devicetree that uses the clock is not upstream yet and follows
separately.
This series was developed with the help of an LLM.
[1] https://lore.kernel.org/all/179459615032.87488.12726056214378307165.b4-ty@b4/
Signed-off-by: Ryan Brue <ryanbrue.dev@gmail.com>
---
Changes in v3:
- rtc: name the new struct mtk_rtc_data member control_reg, rename wrtgr
to write_trigger_reg in a patch of its own, and the local con to
control (Lee)
- dt-bindings: dropped, applied by Lee
- rebased onto v7.4-rc2
- Link to v2: https://lore.kernel.org/r/20261102-rbrue-suez-upstreaming-mt6397-rtc-32k-v2-0-19ca72815374@gmail.com
Changes in v2:
- rtc: check for #clock-cells before reading the driver data, which is
NULL when the PMIC has no RTC node, as on mt8173-evb (Sashiko)
- dt-bindings: add Krzysztof's Reviewed-by
- Link to v1: https://lore.kernel.org/r/20261101-rbrue-suez-upstreaming-mt6397-rtc-32k-v1-0-9758f38d7053@gmail.com
---
Ryan Brue (2):
rtc: mt6397: rename the write trigger register offset
rtc: mt6397: provide the 32 kHz output as a clock
drivers/rtc/rtc-mt6397.c | 95 ++++++++++++++++++++++++++++++++++++++++--
include/linux/mfd/mt6397/rtc.h | 8 +++-
2 files changed, 99 insertions(+), 4 deletions(-)
---
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
change-id: 20261024-rbrue-suez-upstreaming-mt6397-rtc-32k-0a1c16f63383
Best regards,
--
Ryan Brue <ryanbrue.dev@gmail.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v3 1/2] rtc: mt6397: rename the write trigger register offset
2026-11-16 18:46 [PATCH v3 0/2] rtc: mt6397: provide the RTC's 32 kHz output as a clock Ryan Brue
@ 2026-11-16 18:46 ` Ryan Brue
2026-11-16 18:49 ` sashiko-bot
2026-11-16 18:46 ` [PATCH v3 2/2] rtc: mt6397: provide the 32 kHz output as a clock Ryan Brue
1 sibling, 1 reply; 5+ messages in thread
From: Ryan Brue @ 2026-11-16 18:46 UTC (permalink / raw)
To: Sen Chu, Sean Wang, Macpaul Lin, Lee Jones, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Matthias Brugger,
AngeloGioacchino Del Regno, Eddie Huang, Alexandre Belloni
Cc: linux-pm, mfd, devicetree, linux-kernel, linux-arm-kernel,
linux-mediatek, linux-rtc, Ryan Brue
struct mtk_rtc_data holds the offset of the register that commits RTC
writes, in a member called wrtgr after the register's datasheet name.
Call it write_trigger_reg, so that the next member, the control
register's offset, can be named the same way.
No functional change.
Signed-off-by: Ryan Brue <ryanbrue.dev@gmail.com>
---
drivers/rtc/rtc-mt6397.c | 7 ++++---
include/linux/mfd/mt6397/rtc.h | 2 +-
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
index ab402f9f85c3..5afdb707a5b5 100644
--- a/drivers/rtc/rtc-mt6397.c
+++ b/drivers/rtc/rtc-mt6397.c
@@ -22,7 +22,8 @@ static int mtk_rtc_write_trigger(struct mt6397_rtc *rtc)
int ret;
u32 data;
- ret = regmap_write(rtc->regmap, rtc->addr_base + rtc->data->wrtgr, 1);
+ ret = regmap_write(rtc->regmap,
+ rtc->addr_base + rtc->data->write_trigger_reg, 1);
if (ret < 0)
return ret;
@@ -411,11 +412,11 @@ static SIMPLE_DEV_PM_OPS(mt6397_pm_ops, mt6397_rtc_suspend,
mt6397_rtc_resume);
static const struct mtk_rtc_data mt6358_rtc_data = {
- .wrtgr = RTC_WRTGR_MT6358,
+ .write_trigger_reg = RTC_WRTGR_MT6358,
};
static const struct mtk_rtc_data mt6397_rtc_data = {
- .wrtgr = RTC_WRTGR_MT6397,
+ .write_trigger_reg = RTC_WRTGR_MT6397,
};
static const struct of_device_id mt6397_rtc_of_match[] = {
diff --git a/include/linux/mfd/mt6397/rtc.h b/include/linux/mfd/mt6397/rtc.h
index f4da579ec638..44d2b2cb1ff7 100644
--- a/include/linux/mfd/mt6397/rtc.h
+++ b/include/linux/mfd/mt6397/rtc.h
@@ -71,7 +71,7 @@
#define MTK_RTC_POLL_TIMEOUT (jiffies_to_usecs(HZ))
struct mtk_rtc_data {
- u32 wrtgr;
+ u32 write_trigger_reg;
};
struct mt6397_rtc {
--
2.56.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v3 2/2] rtc: mt6397: provide the 32 kHz output as a clock
2026-11-16 18:46 [PATCH v3 0/2] rtc: mt6397: provide the RTC's 32 kHz output as a clock Ryan Brue
2026-11-16 18:46 ` [PATCH v3 1/2] rtc: mt6397: rename the write trigger register offset Ryan Brue
@ 2026-11-16 18:46 ` Ryan Brue
2026-11-16 18:58 ` sashiko-bot
1 sibling, 1 reply; 5+ messages in thread
From: Ryan Brue @ 2026-11-16 18:46 UTC (permalink / raw)
To: Sen Chu, Sean Wang, Macpaul Lin, Lee Jones, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Matthias Brugger,
AngeloGioacchino Del Regno, Eddie Huang, Alexandre Belloni
Cc: linux-pm, mfd, devicetree, linux-kernel, linux-arm-kernel,
linux-mediatek, linux-rtc, Ryan Brue
The RTC's 32 kHz output is gated by RTC_CON.F32KOB, which the vendor
kernel clears before it powers the Wi-Fi/Bluetooth combo chip. Mainline
never touches it, so on a board whose bootloader leaves it set, such a
chip has no sleep clock and does not come up.
Register the output as a clock when the RTC node has #clock-cells, so
the chip's power sequence can enable it.
Signed-off-by: Ryan Brue <ryanbrue.dev@gmail.com>
---
drivers/rtc/rtc-mt6397.c | 88 ++++++++++++++++++++++++++++++++++++++++++
include/linux/mfd/mt6397/rtc.h | 6 +++
2 files changed, 94 insertions(+)
diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
index 5afdb707a5b5..d24f0ccc132c 100644
--- a/drivers/rtc/rtc-mt6397.c
+++ b/drivers/rtc/rtc-mt6397.c
@@ -6,6 +6,7 @@
#include <linux/array_size.h>
#include <linux/bitfield.h>
+#include <linux/clk-provider.h>
#include <linux/err.h>
#include <linux/interrupt.h>
#include <linux/mfd/mt6397/core.h>
@@ -318,6 +319,87 @@ static int mtk_rtc_nvram_write(void *priv, unsigned int offset, void *val,
return ret;
}
+#ifdef CONFIG_COMMON_CLK
+static int mtk_rtc_clkout_set(struct clk_hw *hw, bool on)
+{
+ struct mt6397_rtc *rtc = container_of(hw, struct mt6397_rtc, clkout);
+ int ret;
+
+ mutex_lock(&rtc->lock);
+ ret = regmap_update_bits(rtc->regmap,
+ rtc->addr_base + rtc->data->control_reg,
+ RTC_CON_F32KOB, on ? 0 : RTC_CON_F32KOB);
+ if (!ret)
+ ret = mtk_rtc_write_trigger(rtc);
+ mutex_unlock(&rtc->lock);
+
+ return ret;
+}
+
+static int mtk_rtc_clkout_prepare(struct clk_hw *hw)
+{
+ return mtk_rtc_clkout_set(hw, true);
+}
+
+static void mtk_rtc_clkout_unprepare(struct clk_hw *hw)
+{
+ mtk_rtc_clkout_set(hw, false);
+}
+
+static int mtk_rtc_clkout_is_prepared(struct clk_hw *hw)
+{
+ struct mt6397_rtc *rtc = container_of(hw, struct mt6397_rtc, clkout);
+ u32 control;
+
+ if (regmap_read(rtc->regmap, rtc->addr_base + rtc->data->control_reg,
+ &control))
+ return 0;
+
+ return !(control & RTC_CON_F32KOB);
+}
+
+static unsigned long mtk_rtc_clkout_recalc_rate(struct clk_hw *hw,
+ unsigned long parent_rate)
+{
+ return 32768;
+}
+
+static const struct clk_ops mtk_rtc_clkout_ops = {
+ .prepare = mtk_rtc_clkout_prepare,
+ .unprepare = mtk_rtc_clkout_unprepare,
+ .is_prepared = mtk_rtc_clkout_is_prepared,
+ .recalc_rate = mtk_rtc_clkout_recalc_rate,
+};
+
+/* The 32 kHz output the PMIC drives to other chips, such as a combo chip */
+static int mtk_rtc_register_clkout(struct device *dev, struct mt6397_rtc *rtc)
+{
+ struct clk_init_data init = {
+ .name = "mt6397-rtc-32k",
+ .ops = &mtk_rtc_clkout_ops,
+ };
+ int ret;
+
+ if (!of_property_present(dev->of_node, "#clock-cells") ||
+ !rtc->data->control_reg)
+ return 0;
+
+ rtc->clkout.init = &init;
+
+ ret = devm_clk_hw_register(dev, &rtc->clkout);
+ if (ret)
+ return ret;
+
+ return devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get,
+ &rtc->clkout);
+}
+#else
+static int mtk_rtc_register_clkout(struct device *dev, struct mt6397_rtc *rtc)
+{
+ return 0;
+}
+#endif
+
static int mtk_rtc_probe(struct platform_device *pdev)
{
struct resource *res;
@@ -381,6 +463,11 @@ static int mtk_rtc_probe(struct platform_device *pdev)
if (ret)
return ret;
+ ret = mtk_rtc_register_clkout(&pdev->dev, rtc);
+ if (ret)
+ return dev_err_probe(&pdev->dev, ret,
+ "failed to register the 32k clock\n");
+
nvmem_cfg.priv = rtc;
return devm_rtc_nvmem_register(rtc->rtc_dev, &nvmem_cfg);
@@ -417,6 +504,7 @@ static const struct mtk_rtc_data mt6358_rtc_data = {
static const struct mtk_rtc_data mt6397_rtc_data = {
.write_trigger_reg = RTC_WRTGR_MT6397,
+ .control_reg = RTC_CON_MT6397,
};
static const struct of_device_id mt6397_rtc_of_match[] = {
diff --git a/include/linux/mfd/mt6397/rtc.h b/include/linux/mfd/mt6397/rtc.h
index 44d2b2cb1ff7..986b3aaaeb35 100644
--- a/include/linux/mfd/mt6397/rtc.h
+++ b/include/linux/mfd/mt6397/rtc.h
@@ -9,6 +9,7 @@
#ifndef _LINUX_MFD_MT6397_RTC_H_
#define _LINUX_MFD_MT6397_RTC_H_
+#include <linux/clk-provider.h>
#include <linux/jiffies.h>
#include <linux/mutex.h>
#include <linux/regmap.h>
@@ -22,6 +23,9 @@
#define RTC_WRTGR_MT6397 0x003c
#define RTC_WRTGR_MT6323 RTC_WRTGR_MT6397
+#define RTC_CON_MT6397 0x003e
+#define RTC_CON_F32KOB BIT(5)
+
#define RTC_IRQ_STA 0x0002
#define RTC_IRQ_STA_AL BIT(0)
#define RTC_IRQ_STA_LP BIT(3)
@@ -72,6 +76,7 @@
struct mtk_rtc_data {
u32 write_trigger_reg;
+ u32 control_reg;
};
struct mt6397_rtc {
@@ -83,6 +88,7 @@ struct mt6397_rtc {
int irq;
u32 addr_base;
const struct mtk_rtc_data *data;
+ struct clk_hw clkout;
};
#endif /* _LINUX_MFD_MT6397_RTC_H_ */
--
2.56.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v3 1/2] rtc: mt6397: rename the write trigger register offset
2026-11-16 18:46 ` [PATCH v3 1/2] rtc: mt6397: rename the write trigger register offset Ryan Brue
@ 2026-11-16 18:49 ` sashiko-bot
0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-16 18:49 UTC (permalink / raw)
To: Ryan Brue; +Cc: mfd, linux-rtc, Alexandre Belloni, lee
> struct mtk_rtc_data holds the offset of the register that commits RTC
> writes, in a member called wrtgr after the register's datasheet name.
> Call it write_trigger_reg, so that the next member, the control
> register's offset, can be named the same way.
>
> No functional change.
>
> Signed-off-by: Ryan Brue <ryanbrue.dev@gmail.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116-rbrue-suez-upstreaming-mt6397-rtc-32k-v3-0-179145eb7e89@gmail.com?part=1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3 2/2] rtc: mt6397: provide the 32 kHz output as a clock
2026-11-16 18:46 ` [PATCH v3 2/2] rtc: mt6397: provide the 32 kHz output as a clock Ryan Brue
@ 2026-11-16 18:58 ` sashiko-bot
0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-16 18:58 UTC (permalink / raw)
To: Ryan Brue; +Cc: mfd, linux-rtc, Alexandre Belloni, lee
> The RTC's 32 kHz output is gated by RTC_CON.F32KOB, which the vendor
> kernel clears before it powers the Wi-Fi/Bluetooth combo chip. Mainline
> never touches it, so on a board whose bootloader leaves it set, such a
> chip has no sleep clock and does not come up.
>
> Register the output as a clock when the RTC node has #clock-cells, so
> the chip's power sequence can enable it.
>
> Signed-off-by: Ryan Brue <ryanbrue.dev@gmail.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116-rbrue-suez-upstreaming-mt6397-rtc-32k-v3-0-179145eb7e89@gmail.com?part=2
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-16 18:58 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16 18:46 [PATCH v3 0/2] rtc: mt6397: provide the RTC's 32 kHz output as a clock Ryan Brue
2026-11-16 18:46 ` [PATCH v3 1/2] rtc: mt6397: rename the write trigger register offset Ryan Brue
2026-11-16 18:49 ` sashiko-bot
2026-11-16 18:46 ` [PATCH v3 2/2] rtc: mt6397: provide the 32 kHz output as a clock Ryan Brue
2026-11-16 18:58 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox