Skip to contentSkip to conversation

arm: mach-k3: am625_init: Add Erratum WA for RTC startup

PATCH Superseded Bryan Brattlof 2 participants 2 messages Apr 27, 2023 – May 1, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm: mach-k3: am625_init: Add Erratum WA for RTC startup

From: Nishanth Menon <[email protected]>

Add erratum i2327 work around for initialization for RTC interrupt where interrupt is stuck for ever at startup. Unfortunately, this workaround needs to be applied under 1 second of boot.

---
 arch/arm/mach-k3/am625_init.c | 44 +++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
arch/arm/mach-k3/am625_init.c +44 -0
index a91c15ca4e188..e90c18fdcc118 100644
@@ -15,6 +15,15 @@
 #include <dm/uclass-internal.h>
 #include <dm/pinctrl.h>
 
+#define RTC_BASE_ADDRESS		0x2b1f0000
+#define REG_K3RTC_S_CNT_LSW		(RTC_BASE_ADDRESS + 0x18)
+#define REG_K3RTC_KICK0			(RTC_BASE_ADDRESS + 0x70)
+#define REG_K3RTC_KICK1			(RTC_BASE_ADDRESS + 0x74)
+
+/* Magic values for lock/unlock */
+#define K3RTC_KICK0_UNLOCK_VALUE	0x83e70b13
+#define K3RTC_KICK1_UNLOCK_VALUE	0x95a4f1e0
+
 /*
  * This uninitialized global variable would normal end up in the .bss section,
  * but the .bss is cleared between writing and reading this variable, so move
@@ -71,6 +80,40 @@ static __maybe_unused void enable_mcu_esm_reset(void)
 	writel(stat, CTRLMMR_MCU_RST_CTRL);
 }
 
+#if defined(CONFIG_CPU_V7R)
+
+/*
+ * RTC Erratum i2327 Workaround
+ * Due to a bug in initial synchronization out of cold power on,
+ * IRQ status can get locked infinitely if we do not:
+ * a) unlock RTC
+ *
+ * This workaround *must* be applied within 1 second of power on,
+ * So, this is closest point to be able to guarantee the max
+ * timing.
+ */
+void rtc_erratumi2327_init(void)
+{
+	u32 counter;
+
+	/*
+	 * If counter has gone past 1, nothing we can do, leave
+	 * system locked! This is the only way we know if RTC
+	 * can be used for all practical purposes.
+	 */
+	counter = readl(REG_K3RTC_S_CNT_LSW);
+	if (counter > 1)
+		return;
+	/*
+	 * Need to set this up at the very start
+	 * MUST BE DONE under 1 second of boot.
+	 */
+	writel(K3RTC_KICK0_UNLOCK_VALUE, REG_K3RTC_KICK0);
+	writel(K3RTC_KICK1_UNLOCK_VALUE, REG_K3RTC_KICK1);
+	return;
+}
+#endif
+
 void board_init_f(ulong dummy)
 {
 	struct udevice *dev;
@@ -78,6 +121,7 @@ void board_init_f(ulong dummy)
 
 #if defined(CONFIG_CPU_V7R)
 	setup_k3_mpu_regions();
+	rtc_erratumi2327_init();
 #endif
 
 	/*

base-commit: a25dcda452bf6a6de72764a8d990d72e5def643d

Signature · 1 line
2.40.0
#1 lore raw
Quoted 10 lines · Bryan Brattlof

From: Nishanth Menon <[email protected]>

Add erratum i2327 work around for initialization for RTC interrupt where interrupt is stuck for ever at startup. Unfortunately, this workaround needs to be applied under 1 second of boot.

---

It will be good to state in the diffstat that am62a7 or other k3 SoCs are not impacted: am62a7 has the hardware fix and other SoCs do not have this rtc.

I dont think there is a need to respin the patch for that - just clarifying.

Quoted 77 lines
 arch/arm/mach-k3/am625_init.c | 44 +++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
arch/arm/mach-k3/am625_init.c +44 -0
index a91c15ca4e188..e90c18fdcc118 100644
@@ -15,6 +15,15 @@
 #include <dm/uclass-internal.h>
 #include <dm/pinctrl.h>
 
+#define RTC_BASE_ADDRESS		0x2b1f0000
+#define REG_K3RTC_S_CNT_LSW		(RTC_BASE_ADDRESS + 0x18)
+#define REG_K3RTC_KICK0			(RTC_BASE_ADDRESS + 0x70)
+#define REG_K3RTC_KICK1			(RTC_BASE_ADDRESS + 0x74)
+
+/* Magic values for lock/unlock */
+#define K3RTC_KICK0_UNLOCK_VALUE	0x83e70b13
+#define K3RTC_KICK1_UNLOCK_VALUE	0x95a4f1e0
+
 /*
  * This uninitialized global variable would normal end up in the .bss section,
  * but the .bss is cleared between writing and reading this variable, so move
@@ -71,6 +80,40 @@ static __maybe_unused void enable_mcu_esm_reset(void)
 	writel(stat, CTRLMMR_MCU_RST_CTRL);
 }
 
+#if defined(CONFIG_CPU_V7R)
+
+/*
+ * RTC Erratum i2327 Workaround
+ * Due to a bug in initial synchronization out of cold power on,
+ * IRQ status can get locked infinitely if we do not:
+ * a) unlock RTC
+ *
+ * This workaround *must* be applied within 1 second of power on,
+ * So, this is closest point to be able to guarantee the max
+ * timing.
+ */
+void rtc_erratumi2327_init(void)
+{
+	u32 counter;
+
+	/*
+	 * If counter has gone past 1, nothing we can do, leave
+	 * system locked! This is the only way we know if RTC
+	 * can be used for all practical purposes.
+	 */
+	counter = readl(REG_K3RTC_S_CNT_LSW);
+	if (counter > 1)
+		return;
+	/*
+	 * Need to set this up at the very start
+	 * MUST BE DONE under 1 second of boot.
+	 */
+	writel(K3RTC_KICK0_UNLOCK_VALUE, REG_K3RTC_KICK0);
+	writel(K3RTC_KICK1_UNLOCK_VALUE, REG_K3RTC_KICK1);
+	return;
+}
+#endif
+
 void board_init_f(ulong dummy)
 {
 	struct udevice *dev;
@@ -78,6 +121,7 @@ void board_init_f(ulong dummy)
 
 #if defined(CONFIG_CPU_V7R)
 	setup_k3_mpu_regions();
+	rtc_erratumi2327_init();
 #endif
 
 	/*

base-commit: a25dcda452bf6a6de72764a8d990d72e5def643d

Signature · 1 line
2.40.0
Signature · 3 lines
Regards,
Nishanth Menon
Key (0xDDB5849D1736249D) / Fingerprint: F8A2 8693 54EB 8232 17A3  1A34 DDB5 849D 1736 249D