Add new assembly function 'arch_very_early_init'

This functions setups the power supply for STM32H7 SoC's to
direct SMPS mode, which is required for some boards like
the STM32H747I-DISCO in the default configuration.

If this isn't done in an early stage it cause a deadlock and
also the SoC is running in a limited mode according to the
TRM from the SoC.

Signed-off-by: Johannes Krottmayer <johan...@krotti42.com>
Cc: Patrick Delaunay <patrick.delau...@foss.st.com>
Cc: Patrice Chotard <patrice.chot...@foss.st.com>
---
 arch/arm/mach-stm32/stm32h7/lowlevel.S | 45 ++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
 create mode 100644 arch/arm/mach-stm32/stm32h7/lowlevel.S

diff --git a/arch/arm/mach-stm32/stm32h7/lowlevel.S 
b/arch/arm/mach-stm32/stm32h7/lowlevel.S
new file mode 100644
index 00000000000..97f4e383e3b
--- /dev/null
+++ b/arch/arm/mach-stm32/stm32h7/lowlevel.S
@@ -0,0 +1,45 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2025, Johannes Krottmayer <johan...@krotti42.com>
+ */
+
+#include <linux/linkage.h>
+
+/*
+ * STM32H7 PWR registers
+ */
+#define PWR_CR3                        0x5802480C
+#define PWR_CR3_LDOEN          1
+
+#define PWR_CSR1                       0x58024804
+#define PWR_CSR1_ACTVOSRDY     13
+
+ENTRY(arch_very_early_init)
+       /*
+        * Setup power supply for STM32H7 to direct SMPS mode.
+        * This is the default configuration from some boards
+        * like the SMT32H747i-DISCO.
+        *
+        * If these steps will not be done, this cause a deadlock.
+        */
+       ldr r6, =PWR_CR3
+       /* Disable LDO */
+       movs r0, #1
+       lsl r1, r0, #PWR_CR3_LDOEN
+       mvn r2, r1
+       ldr r3, [r6]
+       and r3, r2
+       str r3, [r6]
+       lsl r1, r0, #PWR_CSR1_ACTVOSRDY
+
+       /* Loop until ACTVOSRDY is valid */
+1:
+       ldr r6, =PWR_CSR1
+       ldr r3, [r6]
+       and r3, r1
+       cmp r3, r1
+       bne 1b
+
+       /* Jump back to C runtime setup */
+       bx lr
+ENDPROC(arch_very_early_init)
-- 
2.39.5


Reply via email to