From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=185.246.84.56 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796468727; b=1eaOLrJaKB6A0M1J/pHIzmhcmfKEyXwG8KG4YfeaPlLO241d1b4UMpVAxjmCpIJLbAng 01QuYjysYxmcumDlNAFS4IUiVrFHKB3V14EuWOL8xQbPiFQvavZ9fOwAiJd/F8qHbwZjL 1Ccv+tL9HodKCP7lNj4pneA/VMBQPIfLErYxTZ78alpXHvypQ7hF2YHE3xrmoDjRszYxv kPhUMr0kLLHyumYSUw5p49KWcHPpSFsyP+tULJzsgyzP0aHHAz4aEWVtzmGPKwlj51SJl rsUCeJqxjUdcTlMBdPIri2dW3DSr38NgzJ5Qg8s9YUF1Ve2otUzq7xhuhKLm4uCIj+A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796468727; h=DMARC-Filter:Received:Received:Received:DKIM-Signature:Date:From:To: Cc:Subject:Message-ID:References:MIME-Version:Content-Type: Content-Disposition:In-Reply-To:X-Last-TLS-Session-Version; bh=MEg7FvD3biGtooPxIZKGP+kH8JjBNSyB2fADEPeiUmQ=; b=ZsxS6BHexX1/T8Vp93UAJaaicL3UDOrEf30H60b8EIwRP5yYsgHkHBBJ4cLUJEqs7hF4 jsNRYj9aa6MCdaYXfwW63RsJU1GGMUgFGwZjHejJh9PYlIsa3RIqzG+AyU2bmmsErfRlw 31/N++Jk4VuyKtT6AHhDRoFSr0GS0219Uy0i9KP8kv06TxMJKHyEU9ojmqxUUjtIbApQx Bmcll0ubDh30dxXOq7ADAmRgbzk8XBxLbF/R/Cx/wqHx2K76jpuVje+pxzQNueAOfAy55 Hjt/YOzE4PtMe3rr73xc7Jf4AdO7OFF1hzjoYoSTrOy8ulaWsJljrr9O8mq+mvBUAhw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=dkim header.b=wa0C50B1; arc=none smtp.remote-ip=185.246.84.56 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3DD4E606A330 for ; Sat, 5 Dec 2026 11:05:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3DD4E606A330 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=dkim header.b=wa0C50B1 Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 56AE31A197D; Sat, 5 Dec 2026 11:05:23 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 16C4860766; Sat, 5 Dec 2026 11:05:23 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 42BFD11EA01A3; Sat, 05 Dec 2026 12:05:15 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1796468722; h=from:subject:date:message-id:to:cc:mime-version:content-type: in-reply-to:references; bh=MEg7FvD3biGtooPxIZKGP+kH8JjBNSyB2fADEPeiUmQ=; b=wa0C50B1ZulKSNzxXiC7ZXVqFWfALYJisknaFyA4AlHq8V9AT1LzKK1Stg/7YDmnMI4T/o WHSdbWq9I9JXFdfibtMok8lrEtqCuJMJ/ExkOiLOEUELyPm6sU5hI8szu6cTLX+F1tLR3n BKeW1LWU6643m/WUbpbvkzC9z1eaQhjOZZcf+hAfw/x6CZ2cc8tv0RH41p4qY5GWoZrywm xyDFAU/V68YT5qdsmXKBzXUUP9E/IIai4jYmFB8c0AAv9UlsHbKYdLDisoH7ycwGr0ficM a1OAoEthW3W/qX/TUwhdcBNvzMpPfRpKFR8jWbxeCbQ22JmoXxjR3MwvvwbrNA== Date: Sat, 5 Dec 2026 12:05:14 +0100 From: Alexandre Belloni To: Fenglin Wu Cc: linux-arm-msm@vger.kernel.org, Bjorn Andersson , Konrad Dybcio , Abel Vesa , David Collins , Subbaraman Narayanamurthy , Kamal Wadhwa , linux-kernel@vger.kernel.org, linux-rtc@vger.kernel.org, Konrad Dybcio Subject: Re: [PATCH v3 3/3] rtc: Add Qualcomm GIO RTC driver Message-ID: <20261205110514d8fe89b2@mail.local> References: <20261118-gio-framework-rtc-driver-2026-10-12-v3-0-52d78a8f43ee@oss.qualcomm.com> <20261118-gio-framework-rtc-driver-2026-10-12-v3-3-52d78a8f43ee@oss.qualcomm.com> X-Mailing-List: linux-rtc@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261118-gio-framework-rtc-driver-2026-10-12-v3-3-52d78a8f43ee@oss.qualcomm.com> X-Last-TLS-Session-Version: TLSv1.3 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 # Zenbook A16 > Signed-off-by: Fenglin Wu > --- > 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 > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +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