linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] Apple Silicon SMC RTC driver
@ 2025-08-12 18:25 Sven Peter
  2025-08-12 18:25 ` [PATCH 1/3] dt-bindings: rtc: Add Apple SMC RTC Sven Peter
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Sven Peter @ 2025-08-12 18:25 UTC (permalink / raw)
  To: Janne Grunau, Alyssa Rosenzweig, Neal Gompa, Lee Jones,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Alexandre Belloni
  Cc: asahi, linux-arm-kernel, devicetree, linux-kernel, linux-rtc,
	Sven Peter, Hector Martin

Hi,

Now that the core mfd device has been upstream I've prepared one of the
child drivers that is still missing: RTC support.
This driver is required to read and set the hardware clock and requires
a reference to an additional NVMEM cell to store the offset and thus
requires a device tree node.

The series applies cleanly to 6.17-rc1 but is based on a tree with three
additional commits to add the SMC nodes to the DTS which didn't make it
into 6.17. You can just ignore that and pretend this is based on
6.17-rc1 since I'll take the dts update through my tree anyway.

Next to this SMC child driver we're still working on an input/misc HID
driver for the powerbutton, a hwmon driver for the various sensors and a
power-supply driver to manage the batteries.

Best,

Sven

Signed-off-by: Sven Peter <sven@kernel.org>
---
Hector Martin (1):
      rtc: Add new rtc-macsmc driver for Apple Silicon Macs

Sven Peter (2):
      dt-bindings: rtc: Add Apple SMC RTC
      arm64: dts: apple: t8103,t600x,t8112: Add SMC RTC node

 .../devicetree/bindings/mfd/apple,smc.yaml         |   9 ++
 .../devicetree/bindings/rtc/apple,smc-rtc.yaml     |  35 +++++
 MAINTAINERS                                        |   2 +
 arch/arm64/boot/dts/apple/t600x-die0.dtsi          |   6 +
 arch/arm64/boot/dts/apple/t8103.dtsi               |   6 +
 arch/arm64/boot/dts/apple/t8112.dtsi               |   6 +
 drivers/mfd/macsmc.c                               |   1 +
 drivers/rtc/Kconfig                                |  11 ++
 drivers/rtc/Makefile                               |   1 +
 drivers/rtc/rtc-macsmc.c                           | 141 +++++++++++++++++++++
 10 files changed, 218 insertions(+)
---
base-commit: 772c260c9c7f916c9a2508839df4f03fc19f3773
change-id: 20250812-wip-smc-rtc-e856b6f24603

Best regards,
-- 
Sven Peter <sven@kernel.org>



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/3] dt-bindings: rtc: Add Apple SMC RTC
  2025-08-12 18:25 [PATCH 0/3] Apple Silicon SMC RTC driver Sven Peter
@ 2025-08-12 18:25 ` Sven Peter
  2025-08-12 18:40   ` Mark Kettenis
  2025-08-13  6:14   ` Krzysztof Kozlowski
  2025-08-12 18:25 ` [PATCH 2/3] rtc: Add new rtc-macsmc driver for Apple Silicon Macs Sven Peter
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 9+ messages in thread
From: Sven Peter @ 2025-08-12 18:25 UTC (permalink / raw)
  To: Janne Grunau, Alyssa Rosenzweig, Neal Gompa, Lee Jones,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Alexandre Belloni
  Cc: asahi, linux-arm-kernel, devicetree, linux-kernel, linux-rtc,
	Sven Peter

Apple Silicon Macs (M1, etc.) have an RTC that is part of the PMU IC,
but most of the PMU functionality is abstracted out by the SMC.
An additional RTC offset stored inside NVMEM is required to compute
the current date/time.

Signed-off-by: Sven Peter <sven@kernel.org>
---
 .../devicetree/bindings/mfd/apple,smc.yaml         |  9 ++++++
 .../devicetree/bindings/rtc/apple,smc-rtc.yaml     | 35 ++++++++++++++++++++++
 MAINTAINERS                                        |  1 +
 3 files changed, 45 insertions(+)

diff --git a/Documentation/devicetree/bindings/mfd/apple,smc.yaml b/Documentation/devicetree/bindings/mfd/apple,smc.yaml
index 8a10e270d421ecd703848f64af597de351fcfd74..38f077867bdeedba8a486a63e366e9c943a75681 100644
--- a/Documentation/devicetree/bindings/mfd/apple,smc.yaml
+++ b/Documentation/devicetree/bindings/mfd/apple,smc.yaml
@@ -41,6 +41,9 @@ properties:
   reboot:
     $ref: /schemas/power/reset/apple,smc-reboot.yaml
 
+  rtc:
+    $ref: /schemas/rtc/apple,smc-rtc.yaml
+
 additionalProperties: false
 
 required:
@@ -75,5 +78,11 @@ examples:
           nvmem-cell-names = "shutdown_flag", "boot_stage",
                              "boot_error_count", "panic_count";
         };
+
+        rtc {
+          compatible = "apple,smc-rtc";
+          nvmem-cells = <&rtc_offset>;
+          nvmem-cell-names = "rtc_offset";
+       };
       };
     };
diff --git a/Documentation/devicetree/bindings/rtc/apple,smc-rtc.yaml b/Documentation/devicetree/bindings/rtc/apple,smc-rtc.yaml
new file mode 100644
index 0000000000000000000000000000000000000000..607b610665a28b3ea2e86bd90cb5f3f28ebac726
--- /dev/null
+++ b/Documentation/devicetree/bindings/rtc/apple,smc-rtc.yaml
@@ -0,0 +1,35 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/rtc/apple,smc-rtc.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Apple SMC RTC
+
+description:
+  Apple Silicon Macs (M1, etc.) have an RTC that is part of the PMU IC,
+  but most of the PMU functionality is abstracted out by the SMC.
+  An additional RTC offset stored inside NVMEM is required to compute
+  the current date/time.
+
+maintainers:
+  - Sven Peter <sven@kernel.org>
+
+properties:
+  compatible:
+    const: apple,smc-rtc
+
+  nvmem-cells:
+    items:
+      - description: 48bit RTC offset, specified in 32768 (2^15) Hz clock ticks
+
+  nvmem-cell-names:
+    items:
+      - const: rtc_offset
+
+required:
+  - compatible
+  - nvmem-cells
+  - nvmem-cell-names
+
+additionalProperties: false
diff --git a/MAINTAINERS b/MAINTAINERS
index fe168477caa45799dfe07de2f54de6d6a1ce0615..aaef8634985b35f54de1123ebb4176602066d177 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2397,6 +2397,7 @@ F:	Documentation/devicetree/bindings/pinctrl/apple,pinctrl.yaml
 F:	Documentation/devicetree/bindings/power/apple*
 F:	Documentation/devicetree/bindings/power/reset/apple,smc-reboot.yaml
 F:	Documentation/devicetree/bindings/pwm/apple,s5l-fpwm.yaml
+F:	Documentation/devicetree/bindings/rtc/apple,smc-rtc.yaml
 F:	Documentation/devicetree/bindings/spi/apple,spi.yaml
 F:	Documentation/devicetree/bindings/spmi/apple,spmi.yaml
 F:	Documentation/devicetree/bindings/watchdog/apple,wdt.yaml

-- 
2.34.1



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/3] rtc: Add new rtc-macsmc driver for Apple Silicon Macs
  2025-08-12 18:25 [PATCH 0/3] Apple Silicon SMC RTC driver Sven Peter
  2025-08-12 18:25 ` [PATCH 1/3] dt-bindings: rtc: Add Apple SMC RTC Sven Peter
@ 2025-08-12 18:25 ` Sven Peter
  2025-08-12 18:25 ` [PATCH 3/3] arm64: dts: apple: t8103,t600x,t8112: Add SMC RTC node Sven Peter
  2025-08-14 13:06 ` [PATCH 0/3] Apple Silicon SMC RTC driver Neal Gompa
  3 siblings, 0 replies; 9+ messages in thread
From: Sven Peter @ 2025-08-12 18:25 UTC (permalink / raw)
  To: Janne Grunau, Alyssa Rosenzweig, Neal Gompa, Lee Jones,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Alexandre Belloni
  Cc: asahi, linux-arm-kernel, devicetree, linux-kernel, linux-rtc,
	Sven Peter, Hector Martin

From: Hector Martin <marcan@marcan.st>

Apple Silicon Macs (M1, etc.) have an RTC that is part of the PMU IC,
but most of the PMU functionality is abstracted out by the SMC.
On T600x machines, the RTC counter must be accessed via the SMC to
get full functionality, and it seems likely that future machines
will move towards making SMC handle all RTC functionality.

The SMC RTC counter access is implemented on all current machines
as of the time of this writing, on firmware 12.x. However, the RTC
offset (needed to set the time) is still only accessible via direct
PMU access. To handle this, we expose the RTC offset as an NVMEM
cell from the SPMI PMU device node, and this driver consumes that
cell and uses it to compute/set the current time.

Signed-off-by: Hector Martin <marcan@marcan.st>
Signed-off-by: Sven Peter <sven@kernel.org>
---
 MAINTAINERS              |   1 +
 drivers/mfd/macsmc.c     |   1 +
 drivers/rtc/Kconfig      |  11 ++++
 drivers/rtc/Makefile     |   1 +
 drivers/rtc/rtc-macsmc.c | 141 +++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 155 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index aaef8634985b35f54de1123ebb4176602066d177..029117b921ea97d1276f5496ea06a3f918929b20 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2421,6 +2421,7 @@ F:	drivers/nvmem/apple-spmi-nvmem.c
 F:	drivers/pinctrl/pinctrl-apple-gpio.c
 F:	drivers/power/reset/macsmc-reboot.c
 F:	drivers/pwm/pwm-apple.c
+F:	drivers/rtc/rtc-macsmc.c
 F:	drivers/soc/apple/*
 F:	drivers/spi/spi-apple.c
 F:	drivers/spmi/spmi-apple-controller.c
diff --git a/drivers/mfd/macsmc.c b/drivers/mfd/macsmc.c
index 870c8b2028a8fc0e905c8934c2636824cbe5d527..59be894460d33afa754927630881532b548b7ad8 100644
--- a/drivers/mfd/macsmc.c
+++ b/drivers/mfd/macsmc.c
@@ -47,6 +47,7 @@
 static const struct mfd_cell apple_smc_devs[] = {
 	MFD_CELL_OF("macsmc-gpio", NULL, NULL, 0, 0, "apple,smc-gpio"),
 	MFD_CELL_OF("macsmc-reboot", NULL, NULL, 0, 0, "apple,smc-reboot"),
+	MFD_CELL_OF("macsmc-rtc", NULL, NULL, 0, 0, "apple,smc-rtc"),
 };
 
 static int apple_smc_cmd_locked(struct apple_smc *smc, u64 cmd, u64 arg,
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 64f6e9756aff4a1f6f6c50f9b4fc2140f66a8578..d28a46a89c85e6b30b402aec155e8972ed2aaa8e 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -2068,6 +2068,17 @@ config RTC_DRV_WILCO_EC
 	  This can also be built as a module. If so, the module will
 	  be named "rtc_wilco_ec".
 
+config RTC_DRV_MACSMC
+	tristate "Apple Mac System Management Controller RTC"
+	depends on MFD_MACSMC
+	help
+	  If you say yes here you get support for RTC functions
+	  inside Apple SPMI PMUs accessed through the SoC's
+	  System Management Controller
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called rtc-macsmc.
+
 config RTC_DRV_MSC313
 	tristate "MStar MSC313 RTC"
         depends on ARCH_MSTARV7 || COMPILE_TEST
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 789bddfea99d8fcd024566891c37ee73e527cf93..bcb43b5878a562454986cbb9ab8cc45cec248dda 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -93,6 +93,7 @@ obj-$(CONFIG_RTC_DRV_M48T35)	+= rtc-m48t35.o
 obj-$(CONFIG_RTC_DRV_M48T59)	+= rtc-m48t59.o
 obj-$(CONFIG_RTC_DRV_M48T86)	+= rtc-m48t86.o
 obj-$(CONFIG_RTC_DRV_MA35D1)	+= rtc-ma35d1.o
+obj-$(CONFIG_RTC_DRV_MACSMC)	+= rtc-macsmc.o
 obj-$(CONFIG_RTC_DRV_MAX31335)	+= rtc-max31335.o
 obj-$(CONFIG_RTC_DRV_MAX6900)	+= rtc-max6900.o
 obj-$(CONFIG_RTC_DRV_MAX6902)	+= rtc-max6902.o
diff --git a/drivers/rtc/rtc-macsmc.c b/drivers/rtc/rtc-macsmc.c
new file mode 100644
index 0000000000000000000000000000000000000000..05e360277f630f3368b2856aadef1f2b96426c37
--- /dev/null
+++ b/drivers/rtc/rtc-macsmc.c
@@ -0,0 +1,141 @@
+// SPDX-License-Identifier: GPL-2.0-only OR MIT
+/*
+ * Apple SMC RTC driver
+ * Copyright The Asahi Linux Contributors
+ */
+
+#include <linux/bitops.h>
+#include <linux/mfd/core.h>
+#include <linux/mfd/macsmc.h>
+#include <linux/module.h>
+#include <linux/nvmem-consumer.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/rtc.h>
+#include <linux/slab.h>
+
+/* 48-bit RTC */
+#define RTC_BYTES 6
+#define RTC_BITS (8 * RTC_BYTES)
+
+/* 32768 Hz clock */
+#define RTC_SEC_SHIFT 15
+
+struct macsmc_rtc {
+	struct device *dev;
+	struct apple_smc *smc;
+	struct rtc_device *rtc_dev;
+	struct nvmem_cell *rtc_offset;
+};
+
+static int macsmc_rtc_get_time(struct device *dev, struct rtc_time *tm)
+{
+	struct macsmc_rtc *rtc = dev_get_drvdata(dev);
+	u64 ctr = 0, off = 0;
+	time64_t now;
+	void *p_off;
+	size_t len;
+	int ret;
+
+	ret = apple_smc_read(rtc->smc, SMC_KEY(CLKM), &ctr, RTC_BYTES);
+	if (ret < 0)
+		return ret;
+	if (ret != RTC_BYTES)
+		return -EIO;
+
+	p_off = nvmem_cell_read(rtc->rtc_offset, &len);
+	if (IS_ERR(p_off))
+		return PTR_ERR(p_off);
+	if (len < RTC_BYTES) {
+		kfree(p_off);
+		return -EIO;
+	}
+
+	memcpy(&off, p_off, RTC_BYTES);
+	kfree(p_off);
+
+	/* Sign extend from 48 to 64 bits, then arithmetic shift right 15 bits to get seconds */
+	now = sign_extend64(ctr + off, RTC_BITS - 1) >> RTC_SEC_SHIFT;
+	rtc_time64_to_tm(now, tm);
+
+	return ret;
+}
+
+static int macsmc_rtc_set_time(struct device *dev, struct rtc_time *tm)
+{
+	struct macsmc_rtc *rtc = dev_get_drvdata(dev);
+	u64 ctr = 0, off = 0;
+	int ret;
+
+	ret = apple_smc_read(rtc->smc, SMC_KEY(CLKM), &ctr, RTC_BYTES);
+	if (ret < 0)
+		return ret;
+	if (ret != RTC_BYTES)
+		return -EIO;
+
+	/* This sets the offset such that the set second begins now */
+	off = (rtc_tm_to_time64(tm) << RTC_SEC_SHIFT) - ctr;
+	return nvmem_cell_write(rtc->rtc_offset, &off, RTC_BYTES);
+}
+
+static const struct rtc_class_ops macsmc_rtc_ops = {
+	.read_time = macsmc_rtc_get_time,
+	.set_time = macsmc_rtc_set_time,
+};
+
+static int macsmc_rtc_probe(struct platform_device *pdev)
+{
+	struct apple_smc *smc = dev_get_drvdata(pdev->dev.parent);
+	struct macsmc_rtc *rtc;
+
+	/*
+	 * MFD will probe this device even without a node in the device tree,
+	 * thus bail out early if the SMC on the current machines does not
+	 * support RTC and has no node in the device tree.
+	 */
+	if (!pdev->dev.of_node)
+		return -ENODEV;
+
+	rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
+	if (!rtc)
+		return -ENOMEM;
+
+	rtc->dev = &pdev->dev;
+	rtc->smc = smc;
+
+	rtc->rtc_offset = devm_nvmem_cell_get(&pdev->dev, "rtc_offset");
+	if (IS_ERR(rtc->rtc_offset))
+		return dev_err_probe(&pdev->dev, PTR_ERR(rtc->rtc_offset),
+				     "Failed to get rtc_offset NVMEM cell\n");
+
+	rtc->rtc_dev = devm_rtc_allocate_device(&pdev->dev);
+	if (IS_ERR(rtc->rtc_dev))
+		return PTR_ERR(rtc->rtc_dev);
+
+	rtc->rtc_dev->ops = &macsmc_rtc_ops;
+	rtc->rtc_dev->range_min = S64_MIN >> (RTC_SEC_SHIFT + (64 - RTC_BITS));
+	rtc->rtc_dev->range_max = S64_MAX >> (RTC_SEC_SHIFT + (64 - RTC_BITS));
+
+	platform_set_drvdata(pdev, rtc);
+
+	return devm_rtc_register_device(rtc->rtc_dev);
+}
+
+static const struct of_device_id macsmc_rtc_of_table[] = {
+	{ .compatible = "apple,smc-rtc", },
+	{}
+};
+MODULE_DEVICE_TABLE(of, macsmc_rtc_of_table);
+
+static struct platform_driver macsmc_rtc_driver = {
+	.driver = {
+		.name = "macsmc-rtc",
+		.of_match_table = macsmc_rtc_of_table,
+	},
+	.probe = macsmc_rtc_probe,
+};
+module_platform_driver(macsmc_rtc_driver);
+
+MODULE_LICENSE("Dual MIT/GPL");
+MODULE_DESCRIPTION("Apple SMC RTC driver");
+MODULE_AUTHOR("Hector Martin <marcan@marcan.st>");

-- 
2.34.1



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/3] arm64: dts: apple: t8103,t600x,t8112: Add SMC RTC node
  2025-08-12 18:25 [PATCH 0/3] Apple Silicon SMC RTC driver Sven Peter
  2025-08-12 18:25 ` [PATCH 1/3] dt-bindings: rtc: Add Apple SMC RTC Sven Peter
  2025-08-12 18:25 ` [PATCH 2/3] rtc: Add new rtc-macsmc driver for Apple Silicon Macs Sven Peter
@ 2025-08-12 18:25 ` Sven Peter
  2025-08-14 13:06 ` [PATCH 0/3] Apple Silicon SMC RTC driver Neal Gompa
  3 siblings, 0 replies; 9+ messages in thread
From: Sven Peter @ 2025-08-12 18:25 UTC (permalink / raw)
  To: Janne Grunau, Alyssa Rosenzweig, Neal Gompa, Lee Jones,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Alexandre Belloni
  Cc: asahi, linux-arm-kernel, devicetree, linux-kernel, linux-rtc,
	Sven Peter

The System Manager Controller of all M1/M2 SoCs supports the RTC
sub-device.

Signed-off-by: Sven Peter <sven@kernel.org>
---
 arch/arm64/boot/dts/apple/t600x-die0.dtsi | 6 ++++++
 arch/arm64/boot/dts/apple/t8103.dtsi      | 6 ++++++
 arch/arm64/boot/dts/apple/t8112.dtsi      | 6 ++++++
 3 files changed, 18 insertions(+)

diff --git a/arch/arm64/boot/dts/apple/t600x-die0.dtsi b/arch/arm64/boot/dts/apple/t600x-die0.dtsi
index 3603b276a2abcfa6a730f58d5c6b9914f22f00b0..f715b19efd1679e5cd384a967d6e2a7c261ee679 100644
--- a/arch/arm64/boot/dts/apple/t600x-die0.dtsi
+++ b/arch/arm64/boot/dts/apple/t600x-die0.dtsi
@@ -44,6 +44,12 @@ smc_reboot: reboot {
 			nvmem-cell-names = "shutdown_flag", "boot_stage",
 				"boot_error_count", "panic_count";
 		};
+
+		rtc {
+			compatible = "apple,smc-rtc";
+			nvmem-cells = <&rtc_offset>;
+			nvmem-cell-names = "rtc_offset";
+		};
 	};
 
 	smc_mbox: mbox@290408000 {
diff --git a/arch/arm64/boot/dts/apple/t8103.dtsi b/arch/arm64/boot/dts/apple/t8103.dtsi
index 8b7b27887968741b745651e5133dffa7d8d20f6d..59f2678639cf47f469dc699c0ecb5b9e50a45ab1 100644
--- a/arch/arm64/boot/dts/apple/t8103.dtsi
+++ b/arch/arm64/boot/dts/apple/t8103.dtsi
@@ -916,6 +916,12 @@ smc_reboot: reboot {
 				nvmem-cell-names = "shutdown_flag", "boot_stage",
 					"boot_error_count", "panic_count";
 			};
+
+			rtc {
+				compatible = "apple,smc-rtc";
+				nvmem-cells = <&rtc_offset>;
+				nvmem-cell-names = "rtc_offset";
+			};
 		};
 
 		smc_mbox: mbox@23e408000 {
diff --git a/arch/arm64/boot/dts/apple/t8112.dtsi b/arch/arm64/boot/dts/apple/t8112.dtsi
index 3f79878b25af1f7760088aa552589494d67347fb..6bc3f58b06f703ed79578e89a030929a18d57796 100644
--- a/arch/arm64/boot/dts/apple/t8112.dtsi
+++ b/arch/arm64/boot/dts/apple/t8112.dtsi
@@ -919,6 +919,12 @@ smc_reboot: reboot {
 				nvmem-cell-names = "shutdown_flag", "boot_stage",
 					"boot_error_count", "panic_count";
 			};
+
+			rtc {
+				compatible = "apple,smc-rtc";
+				nvmem-cells = <&rtc_offset>;
+				nvmem-cell-names = "rtc_offset";
+			};
 		};
 
 		smc_mbox: mbox@23e408000 {

-- 
2.34.1



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/3] dt-bindings: rtc: Add Apple SMC RTC
  2025-08-12 18:25 ` [PATCH 1/3] dt-bindings: rtc: Add Apple SMC RTC Sven Peter
@ 2025-08-12 18:40   ` Mark Kettenis
  2025-08-13  6:14   ` Krzysztof Kozlowski
  1 sibling, 0 replies; 9+ messages in thread
From: Mark Kettenis @ 2025-08-12 18:40 UTC (permalink / raw)
  To: Sven Peter
  Cc: j, alyssa, neal, lee, robh, krzk+dt, conor+dt, alexandre.belloni,
	asahi, linux-arm-kernel, devicetree, linux-kernel, linux-rtc,
	sven

> From: Sven Peter <sven@kernel.org>
> Date: Tue, 12 Aug 2025 18:25:15 +0000
> 
> Apple Silicon Macs (M1, etc.) have an RTC that is part of the PMU IC,
> but most of the PMU functionality is abstracted out by the SMC.
> An additional RTC offset stored inside NVMEM is required to compute
> the current date/time.
> 
> Signed-off-by: Sven Peter <sven@kernel.org>

Reviewd-by: Mark Kettenis <kettenis@openbsd.org>

> ---
>  .../devicetree/bindings/mfd/apple,smc.yaml         |  9 ++++++
>  .../devicetree/bindings/rtc/apple,smc-rtc.yaml     | 35 ++++++++++++++++++++++
>  MAINTAINERS                                        |  1 +
>  3 files changed, 45 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/mfd/apple,smc.yaml b/Documentation/devicetree/bindings/mfd/apple,smc.yaml
> index 8a10e270d421ecd703848f64af597de351fcfd74..38f077867bdeedba8a486a63e366e9c943a75681 100644
> --- a/Documentation/devicetree/bindings/mfd/apple,smc.yaml
> +++ b/Documentation/devicetree/bindings/mfd/apple,smc.yaml
> @@ -41,6 +41,9 @@ properties:
>    reboot:
>      $ref: /schemas/power/reset/apple,smc-reboot.yaml
>  
> +  rtc:
> +    $ref: /schemas/rtc/apple,smc-rtc.yaml
> +
>  additionalProperties: false
>  
>  required:
> @@ -75,5 +78,11 @@ examples:
>            nvmem-cell-names = "shutdown_flag", "boot_stage",
>                               "boot_error_count", "panic_count";
>          };
> +
> +        rtc {
> +          compatible = "apple,smc-rtc";
> +          nvmem-cells = <&rtc_offset>;
> +          nvmem-cell-names = "rtc_offset";
> +       };
>        };
>      };
> diff --git a/Documentation/devicetree/bindings/rtc/apple,smc-rtc.yaml b/Documentation/devicetree/bindings/rtc/apple,smc-rtc.yaml
> new file mode 100644
> index 0000000000000000000000000000000000000000..607b610665a28b3ea2e86bd90cb5f3f28ebac726
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/rtc/apple,smc-rtc.yaml
> @@ -0,0 +1,35 @@
> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/rtc/apple,smc-rtc.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: Apple SMC RTC
> +
> +description:
> +  Apple Silicon Macs (M1, etc.) have an RTC that is part of the PMU IC,
> +  but most of the PMU functionality is abstracted out by the SMC.
> +  An additional RTC offset stored inside NVMEM is required to compute
> +  the current date/time.
> +
> +maintainers:
> +  - Sven Peter <sven@kernel.org>
> +
> +properties:
> +  compatible:
> +    const: apple,smc-rtc
> +
> +  nvmem-cells:
> +    items:
> +      - description: 48bit RTC offset, specified in 32768 (2^15) Hz clock ticks
> +
> +  nvmem-cell-names:
> +    items:
> +      - const: rtc_offset
> +
> +required:
> +  - compatible
> +  - nvmem-cells
> +  - nvmem-cell-names
> +
> +additionalProperties: false
> diff --git a/MAINTAINERS b/MAINTAINERS
> index fe168477caa45799dfe07de2f54de6d6a1ce0615..aaef8634985b35f54de1123ebb4176602066d177 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -2397,6 +2397,7 @@ F:	Documentation/devicetree/bindings/pinctrl/apple,pinctrl.yaml
>  F:	Documentation/devicetree/bindings/power/apple*
>  F:	Documentation/devicetree/bindings/power/reset/apple,smc-reboot.yaml
>  F:	Documentation/devicetree/bindings/pwm/apple,s5l-fpwm.yaml
> +F:	Documentation/devicetree/bindings/rtc/apple,smc-rtc.yaml
>  F:	Documentation/devicetree/bindings/spi/apple,spi.yaml
>  F:	Documentation/devicetree/bindings/spmi/apple,spmi.yaml
>  F:	Documentation/devicetree/bindings/watchdog/apple,wdt.yaml
> 
> -- 
> 2.34.1
> 
> 
> 
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/3] dt-bindings: rtc: Add Apple SMC RTC
  2025-08-12 18:25 ` [PATCH 1/3] dt-bindings: rtc: Add Apple SMC RTC Sven Peter
  2025-08-12 18:40   ` Mark Kettenis
@ 2025-08-13  6:14   ` Krzysztof Kozlowski
  2025-08-14 21:19     ` Rob Herring
  1 sibling, 1 reply; 9+ messages in thread
From: Krzysztof Kozlowski @ 2025-08-13  6:14 UTC (permalink / raw)
  To: Sven Peter, Janne Grunau, Alyssa Rosenzweig, Neal Gompa,
	Lee Jones, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Alexandre Belloni
  Cc: asahi, linux-arm-kernel, devicetree, linux-kernel, linux-rtc

On 12/08/2025 20:25, Sven Peter wrote:
> +maintainers:
> +  - Sven Peter <sven@kernel.org>
> +
> +properties:
> +  compatible:
> +    const: apple,smc-rtc
> +

No resources except nvmem? This should be folded into the parent. Don't
create device node to instantiate drivers.

> +  nvmem-cells:
> +    items:
> +      - description: 48bit RTC offset, specified in 32768 (2^15) Hz clock ticks
> +
> +  nvmem-cell-names:
> +    items:
> +      - const: rtc_offset
> +
> +required:
> +  - compatible
> +  - nvmem-cells
> +  - nvmem-cell-names
> +
> +additionalProperties: false

Missing example. If this is part of other device (like MFD), then the
one there should be extended here.

> 


Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/3] Apple Silicon SMC RTC driver
  2025-08-12 18:25 [PATCH 0/3] Apple Silicon SMC RTC driver Sven Peter
                   ` (2 preceding siblings ...)
  2025-08-12 18:25 ` [PATCH 3/3] arm64: dts: apple: t8103,t600x,t8112: Add SMC RTC node Sven Peter
@ 2025-08-14 13:06 ` Neal Gompa
  3 siblings, 0 replies; 9+ messages in thread
From: Neal Gompa @ 2025-08-14 13:06 UTC (permalink / raw)
  To: Sven Peter
  Cc: Janne Grunau, Alyssa Rosenzweig, Lee Jones, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Alexandre Belloni, asahi,
	linux-arm-kernel, devicetree, linux-kernel, linux-rtc,
	Hector Martin

On Tue, Aug 12, 2025 at 11:25 AM Sven Peter <sven@kernel.org> wrote:
>
> Hi,
>
> Now that the core mfd device has been upstream I've prepared one of the
> child drivers that is still missing: RTC support.
> This driver is required to read and set the hardware clock and requires
> a reference to an additional NVMEM cell to store the offset and thus
> requires a device tree node.
>
> The series applies cleanly to 6.17-rc1 but is based on a tree with three
> additional commits to add the SMC nodes to the DTS which didn't make it
> into 6.17. You can just ignore that and pretend this is based on
> 6.17-rc1 since I'll take the dts update through my tree anyway.
>
> Next to this SMC child driver we're still working on an input/misc HID
> driver for the powerbutton, a hwmon driver for the various sensors and a
> power-supply driver to manage the batteries.
>
> Best,
>
> Sven
>
> Signed-off-by: Sven Peter <sven@kernel.org>
> ---
> Hector Martin (1):
>       rtc: Add new rtc-macsmc driver for Apple Silicon Macs
>
> Sven Peter (2):
>       dt-bindings: rtc: Add Apple SMC RTC
>       arm64: dts: apple: t8103,t600x,t8112: Add SMC RTC node
>
>  .../devicetree/bindings/mfd/apple,smc.yaml         |   9 ++
>  .../devicetree/bindings/rtc/apple,smc-rtc.yaml     |  35 +++++
>  MAINTAINERS                                        |   2 +
>  arch/arm64/boot/dts/apple/t600x-die0.dtsi          |   6 +
>  arch/arm64/boot/dts/apple/t8103.dtsi               |   6 +
>  arch/arm64/boot/dts/apple/t8112.dtsi               |   6 +
>  drivers/mfd/macsmc.c                               |   1 +
>  drivers/rtc/Kconfig                                |  11 ++
>  drivers/rtc/Makefile                               |   1 +
>  drivers/rtc/rtc-macsmc.c                           | 141 +++++++++++++++++++++
>  10 files changed, 218 insertions(+)
> ---
> base-commit: 772c260c9c7f916c9a2508839df4f03fc19f3773
> change-id: 20250812-wip-smc-rtc-e856b6f24603
>

Series looks good to me, thanks for submitting them!

Reviewed-by: Neal Gompa <neal@gompa.dev>


-- 
真実はいつも一つ!/ Always, there's only one truth!

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/3] dt-bindings: rtc: Add Apple SMC RTC
  2025-08-13  6:14   ` Krzysztof Kozlowski
@ 2025-08-14 21:19     ` Rob Herring
  2025-08-16 12:46       ` Sven Peter
  0 siblings, 1 reply; 9+ messages in thread
From: Rob Herring @ 2025-08-14 21:19 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Sven Peter, Janne Grunau, Alyssa Rosenzweig, Neal Gompa,
	Lee Jones, Krzysztof Kozlowski, Conor Dooley, Alexandre Belloni,
	asahi, linux-arm-kernel, devicetree, linux-kernel, linux-rtc

On Wed, Aug 13, 2025 at 08:14:51AM +0200, Krzysztof Kozlowski wrote:
> On 12/08/2025 20:25, Sven Peter wrote:
> > +maintainers:
> > +  - Sven Peter <sven@kernel.org>
> > +
> > +properties:
> > +  compatible:
> > +    const: apple,smc-rtc
> > +
> 
> No resources except nvmem? This should be folded into the parent. Don't
> create device node to instantiate drivers.

Well, the reboot node has nvmem entries too, so probably better to keep 
this as child node.

Is there more functionality planned/needed here (for the mfd)? If so, 
please send it all at once. One child node at a time makes DT 
maintainers grumpy.

Rob

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/3] dt-bindings: rtc: Add Apple SMC RTC
  2025-08-14 21:19     ` Rob Herring
@ 2025-08-16 12:46       ` Sven Peter
  0 siblings, 0 replies; 9+ messages in thread
From: Sven Peter @ 2025-08-16 12:46 UTC (permalink / raw)
  To: Rob Herring, Krzysztof Kozlowski
  Cc: Janne Grunau, Alyssa Rosenzweig, Neal Gompa, Lee Jones,
	Krzysztof Kozlowski, Conor Dooley, Alexandre Belloni, asahi,
	linux-arm-kernel, devicetree, linux-kernel, linux-rtc

On 14.08.25 23:19, Rob Herring wrote:
> On Wed, Aug 13, 2025 at 08:14:51AM +0200, Krzysztof Kozlowski wrote:
>> On 12/08/2025 20:25, Sven Peter wrote:
>>> +maintainers:
>>> +  - Sven Peter <sven@kernel.org>
>>> +
>>> +properties:
>>> +  compatible:
>>> +    const: apple,smc-rtc
>>> +
>>
>> No resources except nvmem? This should be folded into the parent. Don't
>> create device node to instantiate drivers.
> 
> Well, the reboot node has nvmem entries too, so probably better to keep
> this as child node.
> 
> Is there more functionality planned/needed here (for the mfd)? If so,
> please send it all at once. One child node at a time makes DT
> maintainers grumpy.

I'd very much like to avoid that!

There's one more driver (hwmon) that needs another child node and two 
more sub-devices that don't need any or expose any resources (hid for 
the power button and power/supply for batteries). I've talked to James
(who wrote hwmon) and he's going to submit the hwmon series together 
with at least rtc (and hid) so that you can see all additional bindings 
at once.


Thanks,


Sven


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-08-16 12:46 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-12 18:25 [PATCH 0/3] Apple Silicon SMC RTC driver Sven Peter
2025-08-12 18:25 ` [PATCH 1/3] dt-bindings: rtc: Add Apple SMC RTC Sven Peter
2025-08-12 18:40   ` Mark Kettenis
2025-08-13  6:14   ` Krzysztof Kozlowski
2025-08-14 21:19     ` Rob Herring
2025-08-16 12:46       ` Sven Peter
2025-08-12 18:25 ` [PATCH 2/3] rtc: Add new rtc-macsmc driver for Apple Silicon Macs Sven Peter
2025-08-12 18:25 ` [PATCH 3/3] arm64: dts: apple: t8103,t600x,t8112: Add SMC RTC node Sven Peter
2025-08-14 13:06 ` [PATCH 0/3] Apple Silicon SMC RTC driver Neal Gompa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).