From: Val Packett <val@packett.cool>
To: Alexandre Belloni <alexandre.belloni@bootlin.com>,
Maximilian Luz <luzmaximilian@gmail.com>,
Val Packett <val@packett.cool>
Cc: "Bjorn Andersson" <andersson@kernel.org>,
"Konrad Dybcio" <konradybcio@kernel.org>,
"Abel Vesa" <abelvesa@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Hans de Goede" <hansg@kernel.org>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-rtc@vger.kernel.org
Subject: [PATCH 4/5] rtc: Add basic support for RTC via Surface System Aggregator Module
Date: Wed, 4 Nov 2026 04:04:35 -0300 [thread overview]
Message-ID: <20261104070441.74127-5-val@packett.cool> (raw)
In-Reply-To: <20261104070441.74127-1-val@packett.cool>
From: Maximilian Luz <luzmaximilian@gmail.com>
The Surface Pro X uses an RTC provided by the SSAM. Add a driver for it.
Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
Signed-off-by: Val Packett <val@packett.cool>
---
MAINTAINERS | 8 +++
drivers/rtc/Kconfig | 9 +++
drivers/rtc/Makefile | 1 +
drivers/rtc/rtc-surface.c | 129 ++++++++++++++++++++++++++++++++++++++
4 files changed, 147 insertions(+)
create mode 100644 drivers/rtc/rtc-surface.c
diff --git a/MAINTAINERS b/MAINTAINERS
index d23f7d8c4c17..36b3abad50f4 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -18585,6 +18585,14 @@ L: platform-driver-x86@vger.kernel.org
S: Supported
F: drivers/platform/surface/surfacepro3_button.c
+MICROSOFT SURFACE PRO X RTC DRIVER
+M: Maximilian Luz <luzmaximilian@gmail.com>
+M: Val Packett <val@packett.cool>
+L: linux-rtc@vger.kernel.org
+L: linux-arm-msm@vger.kernel.org
+S: Maintained
+F: drivers/rtc/rtc-surface.c
+
MICROSOFT SURFACE SYSTEM AGGREGATOR HUB DRIVER
M: Maximilian Luz <luzmaximilian@gmail.com>
L: platform-driver-x86@vger.kernel.org
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 73ec9230edfd..6af1aa18724f 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1451,6 +1451,15 @@ config RTC_DRV_NTXEC
embedded controller found in certain e-book readers designed by the
original design manufacturer Netronix.
+config RTC_DRV_SURFACE
+ tristate "Microsoft Surface Aggregator RTC"
+ depends on SURFACE_AGGREGATOR
+ depends on SURFACE_AGGREGATOR_BUS
+ help
+ Say yes here if you want to support the RTC functionality of the
+ Surface Aggregator Module (embedded controller) found in the
+ Microsoft Surface Pro X tablet.
+
comment "on-CPU RTC drivers"
config RTC_DRV_ASM9260
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 46f1a0fc2416..f86e827c14e0 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -186,6 +186,7 @@ obj-$(CONFIG_RTC_DRV_SUN4V) += rtc-sun4v.o
obj-$(CONFIG_RTC_DRV_SUN6I) += rtc-sun6i.o
obj-$(CONFIG_RTC_DRV_SUNPLUS) += rtc-sunplus.o
obj-$(CONFIG_RTC_DRV_SUNXI) += rtc-sunxi.o
+obj-$(CONFIG_RTC_DRV_SURFACE) += rtc-surface.o
obj-$(CONFIG_RTC_DRV_TEGRA) += rtc-tegra.o
obj-$(CONFIG_RTC_DRV_TEST) += rtc-test.o
obj-$(CONFIG_RTC_DRV_TI_K3) += rtc-ti-k3.o
diff --git a/drivers/rtc/rtc-surface.c b/drivers/rtc/rtc-surface.c
new file mode 100644
index 000000000000..f6c17c4e98d5
--- /dev/null
+++ b/drivers/rtc/rtc-surface.c
@@ -0,0 +1,129 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * AC driver for 7th-generation Microsoft Surface devices via Surface System
+ * Aggregator Module (SSAM).
+ *
+ * Copyright (C) 2019-2021 Maximilian Luz <luzmaximilian@gmail.com>
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/rtc.h>
+#include <linux/slab.h>
+#include <linux/types.h>
+
+#include <linux/surface_aggregator/device.h>
+
+struct surface_rtc {
+ struct ssam_device *sdev;
+ struct rtc_device *rtc;
+};
+
+SSAM_DEFINE_SYNC_REQUEST_R(__ssam_rtc_get_unix_time, __le32, {
+ .target_category = SSAM_SSH_TC_SAM,
+ .target_id = SSAM_SSH_TID_SAM,
+ .instance_id = 0x00,
+ .command_id = 0x10,
+});
+
+SSAM_DEFINE_SYNC_REQUEST_W(__ssam_rtc_set_unix_time, __le32, {
+ .target_category = SSAM_SSH_TC_SAM,
+ .target_id = SSAM_SSH_TID_SAM,
+ .instance_id = 0x00,
+ .command_id = 0x0f,
+});
+
+static int ssam_rtc_get_unix_time(struct surface_rtc *srtc, u32 *time)
+{
+ __le32 time_le;
+ int status;
+
+ status = __ssam_rtc_get_unix_time(srtc->sdev->ctrl, &time_le);
+ if (status)
+ return status;
+
+ *time = le32_to_cpu(time_le);
+ return 0;
+}
+
+static int ssam_rtc_set_unix_time(struct surface_rtc *srtc, u32 time)
+{
+ __le32 time_le = cpu_to_le32(time);
+
+ return __ssam_rtc_set_unix_time(srtc->sdev->ctrl, &time_le);
+}
+
+static int surface_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+ struct surface_rtc *srtc = dev_get_drvdata(dev);
+ int status;
+ u32 time;
+
+ status = ssam_rtc_get_unix_time(srtc, &time);
+ if (status)
+ return status;
+
+ rtc_time64_to_tm(time, tm);
+ return 0;
+}
+
+static int surface_rtc_set_time(struct device *dev, struct rtc_time *tm)
+{
+ struct surface_rtc *srtc = dev_get_drvdata(dev);
+ time64_t time = rtc_tm_to_time64(tm);
+
+ return ssam_rtc_set_unix_time(srtc, (u32)time);
+}
+
+static const struct rtc_class_ops surface_rtc_ops = {
+ .read_time = surface_rtc_read_time,
+ .set_time = surface_rtc_set_time,
+};
+
+static int surface_rtc_probe(struct ssam_device *sdev)
+{
+ struct surface_rtc *srtc;
+
+ srtc = devm_kzalloc(&sdev->dev, sizeof(*srtc), GFP_KERNEL);
+ if (!srtc)
+ return -ENOMEM;
+
+ srtc->sdev = sdev;
+
+ srtc->rtc = devm_rtc_allocate_device(&sdev->dev);
+ if (IS_ERR(srtc->rtc))
+ return PTR_ERR(srtc->rtc);
+
+ srtc->rtc->ops = &surface_rtc_ops;
+ srtc->rtc->range_max = U32_MAX;
+
+ ssam_device_set_drvdata(sdev, srtc);
+
+ return devm_rtc_register_device(srtc->rtc);
+}
+
+static void surface_rtc_remove(struct ssam_device *sdev)
+{
+ /* Device-managed allocations take care of everything... */
+}
+
+static const struct ssam_device_id surface_rtc_match[] = {
+ { SSAM_SDEV(SAM, SAM, 0x00, 0x00) },
+ { },
+};
+MODULE_DEVICE_TABLE(ssam, surface_rtc_match);
+
+static struct ssam_device_driver surface_rtc_driver = {
+ .probe = surface_rtc_probe,
+ .remove = surface_rtc_remove,
+ .match_table = surface_rtc_match,
+ .driver = {
+ .name = "surface_rtc",
+ .probe_type = PROBE_PREFER_ASYNCHRONOUS,
+ },
+};
+module_ssam_device_driver(surface_rtc_driver);
+
+MODULE_AUTHOR("Maximilian Luz <luzmaximilian@gmail.com>");
+MODULE_DESCRIPTION("RTC driver for Surface System Aggregator Module");
+MODULE_LICENSE("GPL");
--
2.56.0
next prev parent reply other threads:[~2026-11-04 7:06 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 7:04 [PATCH 0/5] Add support for the Microsoft Surface Pro X Val Packett
2026-11-04 7:04 ` [PATCH 1/5] dt-bindings: arm: qcom: Document " Val Packett
2026-11-04 7:04 ` [PATCH 2/5] arm64: dts: qcom: sc8180x: Add " Val Packett
2026-11-04 8:36 ` Konrad Dybcio
2026-11-04 9:05 ` Val Packett
2026-11-04 7:04 ` [PATCH 3/5] firmware: qcom: scm: Allow QSEECOM on the " Val Packett
2026-11-04 7:04 ` Val Packett [this message]
2026-11-04 7:04 ` [PATCH 5/5] platform/surface: aggregator_registry: Add support for " Val Packett
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=20261104070441.74127-5-val@packett.cool \
--to=val@packett.cool \
--cc=abelvesa@kernel.org \
--cc=alexandre.belloni@bootlin.com \
--cc=andersson@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=hansg@kernel.org \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=konradybcio@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rtc@vger.kernel.org \
--cc=luzmaximilian@gmail.com \
--cc=robh@kernel.org \
/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
all inboxes | Powered by JetHome®