[PATCH 4/5] rtc: Add basic support for RTC via Surface System Aggregator Module
From: Val Packett
Date: Wed Nov 04 2026 - 02:09:21 EST
From: Maximilian Luz <luzmaximilian@xxxxxxxxx>
The Surface Pro X uses an RTC provided by the SSAM. Add a driver for it.
Signed-off-by: Maximilian Luz <luzmaximilian@xxxxxxxxx>
Signed-off-by: Val Packett <val@xxxxxxxxxxxx>
---
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@xxxxxxxxxxxxxxx
S: Supported
F: drivers/platform/surface/surfacepro3_button.c
+MICROSOFT SURFACE PRO X RTC DRIVER
+M: Maximilian Luz <luzmaximilian@xxxxxxxxx>
+M: Val Packett <val@xxxxxxxxxxxx>
+L: linux-rtc@xxxxxxxxxxxxxxx
+L: linux-arm-msm@xxxxxxxxxxxxxxx
+S: Maintained
+F: drivers/rtc/rtc-surface.c
+
MICROSOFT SURFACE SYSTEM AGGREGATOR HUB DRIVER
M: Maximilian Luz <luzmaximilian@xxxxxxxxx>
L: platform-driver-x86@xxxxxxxxxxxxxxx
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@xxxxxxxxx>
+ */
+
+#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@xxxxxxxxx>");
+MODULE_DESCRIPTION("RTC driver for Surface System Aggregator Module");
+MODULE_LICENSE("GPL");
--
2.56.0