Skip to contentSkip to conversation

Apple M1 watchdog timer

PATCH In review Mark Kettenis 2 participants 5 messages Jan 12, 2022 – Jan 13, 2022

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v2 cover Apple M1 watchdog timer

This series adds a driver for the watchdog timer found on Apple's M1 SoC and replaces the reset_cpu() function in the board file with sysreset. The driver is based on the Linux binding proposed in [1].

[1] https://patchwork.ozlabs.org/project/devicetree-bindings/patch/[email protected]/

ChangeLog:

v2: - Adjust delay and add comment
- Explain dropped device tree node in commit message

Mark Kettenis (3):
watchdog: Add a driver for the Apple watchdog
arm: dts: apple: Add watchdog timer node
arm: apple: Use watchdog timer for system reset

 MAINTAINERS                  |   1 +
 arch/arm/Kconfig             |   3 +
 arch/arm/dts/t8103.dtsi      |  13 ++--
 arch/arm/mach-apple/board.c  |  24 --------
 drivers/watchdog/Kconfig     |   9 +++
 drivers/watchdog/Makefile    |   1 +
 drivers/watchdog/apple_wdt.c | 115 +++++++++++++++++++++++++++++++++++
 7 files changed, 137 insertions(+), 29 deletions(-)
 create mode 100644 drivers/watchdog/apple_wdt.c
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/3 watchdog: Add a driver for the Apple watchdog

This driver supports the watchdog timer found on Apple's M1 SoC. On systems that use these SoC, the watchdog timer is the primary way to reboot the system.

Tested-on: Apple M1 Macbook

---

ChangeLog:

v2: - Adjust delay and add comment

 MAINTAINERS                  |   1 +
 drivers/watchdog/Kconfig     |   9 +++
 drivers/watchdog/Makefile    |   1 +
 drivers/watchdog/apple_wdt.c | 115 +++++++++++++++++++++++++++++++++++
 4 files changed, 126 insertions(+)
 create mode 100644 drivers/watchdog/apple_wdt.c
MAINTAINERS +1 -0
index f4bd3d79e2..6ae81c5659 100644
@@ -116,6 +116,7 @@ F:	arch/arm/mach-apple/
 F:	configs/apple_m1_defconfig
 F:	drivers/iommu/apple_dart.c
 F:	drivers/pinctrl/pinctrl-apple.c
+F:	drivers/watchdog/apple_wdt.c
 F:	include/configs/apple.h
 
 ARM
drivers/watchdog/Kconfig +9 -0
index 1177f17fd8..cabac29053 100644
@@ -81,6 +81,15 @@ config WDT
 	  What exactly happens when the timer expires is up to a particular
 	  device/driver.
 
+config WDT_APPLE
+	bool "Apple watchdog timer support"
+	depends on WDT
+	default y if ARCH_APPLE
+	help
+	  Enable support for the watchdog timer on Apple SoCs.
+	  The watchdog will perform a full SoC reset resulting in a
+	  reboot of the entire system.
+
 config WDT_ARMADA_37XX
 	bool "Marvell Armada 37xx watchdog timer support"
 	depends on WDT && ARMADA_3700
drivers/watchdog/Makefile +1 -0
index fa7ce583ce..6d2b3822c0 100644
@@ -17,6 +17,7 @@ obj-$(CONFIG_DESIGNWARE_WATCHDOG) += designware_wdt.o
 obj-$(CONFIG_ULP_WATCHDOG) += ulp_wdog.o
 obj-$(CONFIG_$(SPL_TPL_)WDT) += wdt-uclass.o
 obj-$(CONFIG_WDT_SANDBOX) += sandbox_wdt.o
+obj-$(CONFIG_WDT_APPLE) += apple_wdt.o
 obj-$(CONFIG_WDT_ARMADA_37XX) += armada-37xx-wdt.o
 obj-$(CONFIG_WDT_ASPEED) += ast_wdt.o
 obj-$(CONFIG_WDT_AST2600) += ast2600_wdt.o
drivers/watchdog/apple_wdt.c new file +115 -0

115 lines not on this page · raw message

Signature · 1 line
2.34.1
#2 lore raw

PATCH v2 2/3 arm: dts: apple: Add watchdog timer node

In reply to Mark Kettenis

Add a node for the watchdog timer based on the proposed Linux device tree bindings.

Remove the old reboot node which was a watchdog timert node in disguise using a preliminary device tree binding.

Tested-on: Apple M1 Macbook

---

ChangeLog:

v2: - Explain dropped device tree node in commit message

 arch/arm/dts/t8103.dtsi | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
arch/arm/dts/t8103.dtsi +8 -5
index 7d9cb272f9..03d8436fec 100644
@@ -328,6 +328,14 @@
 				     <AIC_IRQ 336 IRQ_TYPE_LEVEL_HIGH>;
 		};
 
+		wdt: watchdog@23d2b0000 {
+			compatible = "apple,t8103-wdt", "apple,wdt";
+			reg = <0x2 0x3d2b0000 0x0 0x4000>;
+			clocks = <&clkref>;
+			interrupt-parent = <&aic>;
+			interrupts = <AIC_IRQ 338 IRQ_TYPE_LEVEL_HIGH>;
+		};
+
 		pinctrl_smc: pinctrl@23e820000 {
 			compatible = "apple,t8103-pinctrl", "apple,pinctrl";
 			reg = <0x2 0x3e820000 0x0 0x4000>;
@@ -529,11 +537,6 @@
 			status = "disabled";
 		};
 
-		reboot@23d2b0000 {
-			compatible = "apple,reboot-v0";
-			reg = <0x2 0x3d2b0000 0x0 0x4000>;
-		};
-
 		spi@23510c000 {
 			compatible = "apple,t8103-spi", "apple,spi";
 			reg = <0x2 0x3510c000 0x0 0x4000>;
Signature · 1 line
2.34.1
#3 lore raw

PATCH v2 3/3 arm: apple: Use watchdog timer for system reset

In reply to Mark Kettenis

Rely on the new watchdog timer driver and the sysreset uclass to reset the system. This gets rid of hard-coded addresses and should work on systems based on the new M1 Pro and M1 Max SoCs as well.

Tested-on: Apple M1 Macbook

---
 arch/arm/Kconfig            |  3 +++
 arch/arm/mach-apple/board.c | 24 ------------------------
 2 files changed, 3 insertions(+), 24 deletions(-)
arch/arm/Kconfig +3 -0
index 7264d72bde..78c6b2e92d 100644
@@ -942,6 +942,9 @@ config ARCH_APPLE
 	select OF_CONTROL
 	select PINCTRL
 	select POSITION_INDEPENDENT
+	select SYSRESET
+	select SYSRESET_WATCHDOG
+	select SYSRESET_WATCHDOG_AUTO
 	select USB
 	imply CMD_DM
 	imply CMD_GPT
arch/arm/mach-apple/board.c +0 -24
index 0bfbc473ec..b7e8d212f1 100644
@@ -119,30 +119,6 @@ int dram_init_banksize(void)
 	return fdtdec_setup_memory_banksize();
 }
 
-#define APPLE_WDT_BASE		0x23d2b0000ULL
-
-#define APPLE_WDT_SYS_CTL_ENABLE	BIT(2)
-
-typedef struct apple_wdt {
-	u32	reserved0[3];
-	u32	chip_ctl;
-	u32	sys_tmr;
-	u32	sys_cmp;
-	u32	reserved1;
-	u32	sys_ctl;
-} apple_wdt_t;
-
-void reset_cpu(void)
-{
-	apple_wdt_t *wdt = (apple_wdt_t *)APPLE_WDT_BASE;
-
-	writel(0, &wdt->sys_cmp);
-	writel(APPLE_WDT_SYS_CTL_ENABLE, &wdt->sys_ctl);
-
-	while(1)
-		wfi();
-}
-
 extern long fw_dtb_pointer;
 
 void *board_fdt_blob_setup(int *err)
Signature · 1 line
2.34.1
#4 lore raw
In reply to Mark Kettenis
Quoted 26 lines · Mark Kettenis

This series adds a driver for the watchdog timer found on Apple's M1 SoC and replaces the reset_cpu() function in the board file with sysreset. The driver is based on the Linux binding proposed in [1].

[1] https://patchwork.ozlabs.org/project/devicetree-bindings/patch/[email protected]/

ChangeLog:

v2: - Adjust delay and add comment
- Explain dropped device tree node in commit message

Mark Kettenis (3):
watchdog: Add a driver for the Apple watchdog
arm: dts: apple: Add watchdog timer node
arm: apple: Use watchdog timer for system reset

  MAINTAINERS                  |   1 +
  arch/arm/Kconfig             |   3 +
  arch/arm/dts/t8103.dtsi      |  13 ++--
  arch/arm/mach-apple/board.c  |  24 --------
  drivers/watchdog/Kconfig     |   9 +++
  drivers/watchdog/Makefile    |   1 +
  drivers/watchdog/apple_wdt.c | 115 +++++++++++++++++++++++++++++++++++
  7 files changed, 137 insertions(+), 29 deletions(-)
Quoted 2 lines

create mode 100644 drivers/watchdog/apple_wdt.c

Applied to u-boot-marvell/master

Thanks,
Stefan