Linux RTC
 help / color / mirror / Atom feed
From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: Fenglin Wu <fenglin.wu@oss.qualcomm.com>
Cc: linux-arm-msm@vger.kernel.org,
	Bjorn Andersson <andersson@kernel.org>,
	Konrad Dybcio <konradybcio@kernel.org>,
	Abel Vesa <abelvesa@kernel.org>,
	David Collins <david.collins@oss.qualcomm.com>,
	Subbaraman Narayanamurthy
	<subbaraman.narayanamurthy@oss.qualcomm.com>,
	Kamal Wadhwa <kamal.wadhwa@oss.qualcomm.com>,
	linux-kernel@vger.kernel.org, linux-rtc@vger.kernel.org,
	Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
Subject: Re: [PATCH v3 3/3] rtc: Add Qualcomm GIO RTC driver
Date: Sat, 5 Dec 2026 12:05:14 +0100	[thread overview]
Message-ID: <20261205110514d8fe89b2@mail.local> (raw)
In-Reply-To: <20261118-gio-framework-rtc-driver-2026-10-12-v3-3-52d78a8f43ee@oss.qualcomm.com>

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@oss.qualcomm.com> # Zenbook A16
> Signed-off-by: Fenglin Wu <fenglin.wu@oss.qualcomm.com>
> ---
>  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

      parent reply	other threads:[~2026-12-05 11:05 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19  6:55 [PATCH v3 0/3] soc: qcom: Add Qualcomm PMIC GIO framework and RTC driver using it Fenglin Wu
2026-11-19  6:55 ` [PATCH v3 1/3] soc: qcom: Add pmic-gio GIO framework driver Fenglin Wu
2026-11-19  7:09   ` sashiko-bot
2026-12-03 12:54   ` Konrad Dybcio
2026-12-03 12:56   ` Konrad Dybcio
2026-12-03 12:57   ` Konrad Dybcio
2026-11-19  6:55 ` [PATCH v3 2/3] soc: qcom: pmic_glink: Add GIO pmic_glink instance Fenglin Wu
2026-11-19  7:05   ` sashiko-bot
2026-12-03 12:59   ` Konrad Dybcio
2026-12-03 13:01   ` Konrad Dybcio
2026-11-19  6:55 ` [PATCH v3 3/3] rtc: Add Qualcomm GIO RTC driver Fenglin Wu
2026-11-19  7:04   ` sashiko-bot
2026-12-03 13:07   ` Konrad Dybcio
2026-12-05 11:05   ` Alexandre Belloni [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261205110514d8fe89b2@mail.local \
    --to=alexandre.belloni@bootlin.com \
    --cc=abelvesa@kernel.org \
    --cc=andersson@kernel.org \
    --cc=david.collins@oss.qualcomm.com \
    --cc=fenglin.wu@oss.qualcomm.com \
    --cc=kamal.wadhwa@oss.qualcomm.com \
    --cc=konrad.dybcio@oss.qualcomm.com \
    --cc=konradybcio@kernel.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=subbaraman.narayanamurthy@oss.qualcomm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox