Re: [PATCH v3 3/3] rtc: Add Qualcomm GIO RTC driver
From: Alexandre Belloni
Date: Sat Dec 05 2026 - 06:05:32 EST
On 18/11/2026 22:55:46-0800, Fenglin Wu wrote:
> On the Glymur platform, the GIO (General I/O) interface communicates
> with the SoCCP battery-management firmware and provides a set of TAD
> (Time-Alarm-Device) registers for reading and writing RTC time. The
> platform also includes registers for configuring an alarm timer and
> initiating device boot-up into different power stages, such as:
> charging only or fully powered-on system, based on the applied power
> source (AC/DC). However, repurposing this alarm timer has very limited
> value for an RTC driver because it does not expose an interrupt when
> the timer expires.
>
> Add an auxiliary RTC driver that corresponds to the auxiliary device
> created by the GIO driver, "pmic_gio.rtc", which manages the RTC timer
> by accessing to the TAD real-time register block through the regmap
> interface exposed by the GIO device.
>
> Tested-by: Konrad Dybcio <konrad.dybcio@xxxxxxxxxxxxxxxx> # Zenbook A16
> Signed-off-by: Fenglin Wu <fenglin.wu@xxxxxxxxxxxxxxxx>
> ---
> drivers/rtc/Kconfig | 11 +++
> drivers/rtc/Makefile | 1 +
> drivers/rtc/rtc-qcom-gio.c | 153 ++++++++++++++++++++++++++++++++++++++
> drivers/soc/qcom/pmic_glink_gio.c | 14 ++++
> 4 files changed, 179 insertions(+)
>
> diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
> index 73ec9230edfd..a298f7ae68f9 100644
> --- a/drivers/rtc/Kconfig
> +++ b/drivers/rtc/Kconfig
> @@ -1863,6 +1863,17 @@ config RTC_DRV_PM8XXX
> To compile this driver as a module, choose M here: the
> module will be called rtc-pm8xxx.
>
> +config RTC_DRV_QCOM_GIO
> + tristate "Qualcomm GIO RTC driver"
> + depends on QCOM_PMIC_GLINK_GIO
> + help
> + Say y here to support the real-time clock exposed in Qualcomm
> + SoCCP battery management firmware through the GIO (General I/O)
> + interface.
> +
> + This driver can also be built as a module. If so, the module will
> + be called rtc-qcom-gio.
> +
> config RTC_DRV_TEGRA
> tristate "NVIDIA Tegra Internal RTC driver"
> depends on ARCH_TEGRA || COMPILE_TEST
> diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
> index 46f1a0fc2416..9cb76aac7897 100644
> --- a/drivers/rtc/Makefile
> +++ b/drivers/rtc/Makefile
> @@ -142,6 +142,7 @@ obj-$(CONFIG_RTC_DRV_PM8XXX) += rtc-pm8xxx.o
> obj-$(CONFIG_RTC_DRV_POLARFIRE_SOC) += rtc-mpfs.o
> obj-$(CONFIG_RTC_DRV_PS3) += rtc-ps3.o
> obj-$(CONFIG_RTC_DRV_PXA) += rtc-pxa.o
> +obj-$(CONFIG_RTC_DRV_QCOM_GIO) += rtc-qcom-gio.o
> obj-$(CONFIG_RTC_DRV_R7301) += rtc-r7301.o
> obj-$(CONFIG_RTC_DRV_R9701) += rtc-r9701.o
> obj-$(CONFIG_RTC_DRV_RPI) += rtc-raspberrypi.o
> diff --git a/drivers/rtc/rtc-qcom-gio.c b/drivers/rtc/rtc-qcom-gio.c
> new file mode 100644
> index 000000000000..679b24f2a190
> --- /dev/null
> +++ b/drivers/rtc/rtc-qcom-gio.c
> @@ -0,0 +1,153 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
> + */
> +
> +#include <linux/auxiliary_bus.h>
> +#include <linux/bitfield.h>
> +#include <linux/bits.h>
> +#include <linux/device.h>
> +#include <linux/module.h>
> +#include <linux/regmap.h>
> +#include <linux/rtc.h>
> +#include <linux/soc/qcom/pmic_gio.h>
> +#include <linux/soc/qcom/pmic_gio_regs.h>
> +
> +struct tad_rt {
> + u32 ymd;
> +#define RT_YMD_DAY GENMASK(31, 24)
> +#define RT_YMD_MONTH GENMASK(23, 16)
> +#define RT_YMD_YEAR GENMASK(15, 0)
> +
> + u32 hms;
> +#define RT_HMS_VALID GENMASK(31, 24)
> +#define RT_HMS_SEC GENMASK(23, 16)
> +#define RT_HMS_MINUTE GENMASK(15, 8)
> +#define RT_HMS_HOUR GENMASK(7, 0)
> +
> + u32 ms_tz;
> + u32 daylight;
> +} __packed;
> +
> +static_assert(sizeof(struct tad_rt) == GIO_SVC_TAD_RT_SIZE);
> +
> +struct rtc_qcom_gio {
> + struct regmap *regmap;
> + struct rtc_device *rtc;
> +};
> +
> +static int rtc_qcom_gio_read_time(struct device *dev, struct rtc_time *tm)
> +{
> + struct rtc_qcom_gio *rtc = dev_get_drvdata(dev);
> + struct tad_rt rt;
> + int ret;
> +
> + ret = regmap_bulk_read(rtc->regmap, GIO_SVC_TAD_RT_ADDR, &rt,
> + sizeof(rt) / PMIC_GIO_REG_GRANULARITY);
> + if (ret)
> + return ret;
> +
> + /*
> + * The firmware may return valid RTC values even when VALID is not set.
> + * Only print out register values for potential debug if it's needed.
> + */
> + if (!FIELD_GET(RT_HMS_VALID, rt.hms))
> + dev_dbg(dev, "RTC registers: ymd=%#010x hms=%#010x\n", rt.ymd, rt.hms);
Please elaborate on what is the meaning of RT_HMS_VALID.valid RTC values
doesn't mean the time is valid e.g. when the time has never been set, we
know it is not correct.
> +
> + tm->tm_year = FIELD_GET(RT_YMD_YEAR, rt.ymd) - 1900;
> + tm->tm_mon = FIELD_GET(RT_YMD_MONTH, rt.ymd) - 1;
> + tm->tm_mday = FIELD_GET(RT_YMD_DAY, rt.ymd);
> + tm->tm_hour = FIELD_GET(RT_HMS_HOUR, rt.hms);
> + tm->tm_min = FIELD_GET(RT_HMS_MINUTE, rt.hms);
> + tm->tm_sec = FIELD_GET(RT_HMS_SEC, rt.hms);
> +
> + return 0;
> +}
> +
> +static int rtc_qcom_gio_set_time(struct device *dev, struct rtc_time *tm)
> +{
> + struct rtc_qcom_gio *rtc = dev_get_drvdata(dev);
> + struct tad_rt rt;
> + int ret;
> +
> + /*
> + * The firmware requires the whole TAD_RT block to be written in a
> + * single transaction, so ms_tz/daylight (which this driver never
> + * changes) have to be read back and carried through unmodified
> + * rather than writing just the ymd/hms words we care about. This
> + * leaves a small window where a concurrent firmware-side update to
> + * ms_tz/daylight between the read and the write below is clobbered
> + * with a stale value; accepted given the firmware doesn't support
> + * partial-block writes.
> + */
But if we are never using ms_tz and daylight, do we actually care about
having them set correctly? Or rather, shouldn't we set them to know
values so we know the time is UTC?
> + ret = regmap_bulk_read(rtc->regmap, GIO_SVC_TAD_RT_ADDR, &rt,
> + sizeof(rt) / PMIC_GIO_REG_GRANULARITY);
> + if (ret)
> + return ret;
> +
> + rt.ymd = FIELD_PREP(RT_YMD_DAY, tm->tm_mday) |
> + FIELD_PREP(RT_YMD_MONTH, tm->tm_mon + 1) |
> + FIELD_PREP(RT_YMD_YEAR, tm->tm_year + 1900);
> +
> + rt.hms = FIELD_PREP(RT_HMS_VALID, 1) |
> + FIELD_PREP(RT_HMS_SEC, tm->tm_sec) |
> + FIELD_PREP(RT_HMS_MINUTE, tm->tm_min) |
> + FIELD_PREP(RT_HMS_HOUR, tm->tm_hour);
> +
> + return regmap_bulk_write(rtc->regmap, GIO_SVC_TAD_RT_ADDR, &rt,
> + sizeof(rt) / PMIC_GIO_REG_GRANULARITY);
> +}
> +
> +static const struct rtc_class_ops rtc_qcom_gio_ops = {
> + .read_time = rtc_qcom_gio_read_time,
> + .set_time = rtc_qcom_gio_set_time,
> +};
> +
> +static int rtc_qcom_gio_probe(struct auxiliary_device *adev,
> + const struct auxiliary_device_id *id)
> +{
> + struct device *dev = &adev->dev;
> + struct rtc_qcom_gio *rtc;
> + int ret;
> +
> + rtc = devm_kzalloc(dev, sizeof(*rtc), GFP_KERNEL);
> + if (!rtc)
> + return -ENOMEM;
> +
> + rtc->regmap = dev_get_regmap(dev->parent, NULL);
> + if (!rtc->regmap)
> + return -ENODEV;
> +
> + dev_set_drvdata(dev, rtc);
> +
> + rtc->rtc = devm_rtc_allocate_device(dev);
> + if (IS_ERR(rtc->rtc))
> + return PTR_ERR(rtc->rtc);
> +
> + rtc->rtc->ops = &rtc_qcom_gio_ops;
> + rtc->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
> + rtc->rtc->range_max = RTC_TIMESTAMP_END_2099;
> +
> + ret = devm_rtc_register_device(rtc->rtc);
> + if (ret)
> + return ret;
> +
> + return 0;
> +}
> +
> +static const struct auxiliary_device_id rtc_qcom_gio_id_table[] = {
> + { .name = "pmic_gio.rtc", },
> + {},
> +};
> +MODULE_DEVICE_TABLE(auxiliary, rtc_qcom_gio_id_table);
> +
> +static struct auxiliary_driver rtc_qcom_gio_driver = {
> + .name = "rtc_qcom_gio",
> + .probe = rtc_qcom_gio_probe,
> + .id_table = rtc_qcom_gio_id_table,
> +};
> +
> +module_auxiliary_driver(rtc_qcom_gio_driver);
> +
> +MODULE_DESCRIPTION("Qualcomm GIO RTC driver");
> +MODULE_LICENSE("GPL");
> diff --git a/drivers/soc/qcom/pmic_glink_gio.c b/drivers/soc/qcom/pmic_glink_gio.c
> index 0ea338518873..d00588a943d9 100644
> --- a/drivers/soc/qcom/pmic_glink_gio.c
> +++ b/drivers/soc/qcom/pmic_glink_gio.c
> @@ -113,6 +113,8 @@ struct pmic_glink_gio {
> bool service_up;
>
> struct gio_write_req write_req;
> +
> + struct auxiliary_device *rtc_aux;
> };
>
> /* Must be called with pgio->lock held. */
> @@ -338,6 +340,18 @@ static void pmic_glink_gio_init_work(struct work_struct *work)
>
> pmic_gio_set_state(pgio->gio, PMIC_GIO_STATE_UP);
> }
> +
> + /*
> + * Create GIO consumers after PDR to ensure the transport
> + * is up before consumers use the GIO regmap device.
> + */
> + if (!pgio->rtc_aux) {
> + pgio->rtc_aux = devm_pmic_gio_add_consumer(pgio->gio, "rtc");
> + if (!pgio->rtc_aux) {
> + dev_err(pgio->dev, "failed to add RTC consumer\n");
> + return;
> + }
> + }
> }
>
I guess this could be a separate patch so it is easier to apply.
> static void pmic_glink_gio_alert_work(struct work_struct *work)
>
> --
> 2.43.0
>
--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com