]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
arm64: versal: Move board_early_init_r clock setup to mach code
authorMichal Simek <michal.simek@amd.com>
Tue, 23 Jun 2026 12:53:31 +0000 (14:53 +0200)
committerMichal Simek <michal.simek@amd.com>
Wed, 8 Jul 2026 06:55:51 +0000 (08:55 +0200)
board_early_init_r() programmed the IOU switch clock and the system
timestamp counter directly with readl()/writel() in board code. This is
SoC register setup rather than board policy, and the same block is
duplicated across the Xilinx SoCs.

Move it into versal_timer_setup() in arch/arm/mach-versal so the board
hook only keeps the EL3 guard and calls the helper.

Signed-off-by: Michal Simek <michal.simek@amd.com>
Link: https://patch.msgid.link/2234d746ab5b8240e88b1a629d51f93751ee3b60.1782219202.git.michal.simek@amd.com
arch/arm/mach-versal/cpu.c
arch/arm/mach-versal/include/mach/sys_proto.h
board/xilinx/versal/board.c

index 5cb013d5f2e7fd33af9a7586d9408f3227f06094..7521d45bc1a62ae1f550877fe43da9d0475d813d 100644 (file)
@@ -7,6 +7,8 @@
  */
 
 #include <init.h>
+#include <log.h>
+#include <time.h>
 #include <asm/armv8/mmu.h>
 #include <asm/cache.h>
 #include <asm/global_data.h>
@@ -120,6 +122,47 @@ u32 __weak versal_pmc_multi_boot(void)
        return versal_multi_boot_reg();
 }
 
+void versal_timer_setup(void)
+{
+       u32 val;
+
+       debug("iou_switch ctrl div0 %x\n",
+             readl(&crlapb_base->iou_switch_ctrl));
+
+       writel(IOU_SWITCH_CTRL_CLKACT_BIT |
+              (CONFIG_IOU_SWITCH_DIVISOR0 << IOU_SWITCH_CTRL_DIVISOR0_SHIFT),
+              &crlapb_base->iou_switch_ctrl);
+
+       /* Global timer init - Program time stamp reference clk */
+       val = readl(&crlapb_base->timestamp_ref_ctrl);
+       val |= CRL_APB_TIMESTAMP_REF_CTRL_CLKACT_BIT;
+       writel(val, &crlapb_base->timestamp_ref_ctrl);
+
+       debug("ref ctrl 0x%x\n",
+             readl(&crlapb_base->timestamp_ref_ctrl));
+
+       /* Clear reset of timestamp reg */
+       writel(0, &crlapb_base->rst_timestamp);
+
+       /*
+        * Program freq register in System counter and
+        * enable system counter.
+        */
+       writel(CONFIG_COUNTER_FREQUENCY,
+              &iou_scntr_secure->base_frequency_id_register);
+
+       debug("counter val 0x%x\n",
+             readl(&iou_scntr_secure->base_frequency_id_register));
+
+       writel(IOU_SCNTRS_CONTROL_EN,
+              &iou_scntr_secure->counter_control_register);
+
+       debug("scntrs control 0x%x\n",
+             readl(&iou_scntr_secure->counter_control_register));
+       debug("timer 0x%llx\n", get_ticks());
+       debug("timer 0x%llx\n", get_ticks());
+}
+
 u32 versal_bootmode_reg(void)
 {
        return readl(&crp_base->boot_mode_usr);
index f8836db5ef05727ff6fc7324a2483f4cf3bc64a1..cb373e6fad911215496a3a62415fb03f7045b3c5 100644 (file)
@@ -25,5 +25,7 @@ u32 versal_multi_boot_reg(void);
 u8 versal_get_bootmode(void);
 /* Direct MMIO read of the bootmode register (EL3 / no-firmware path) */
 u32 versal_bootmode_reg(void);
+/* EL3 clock/timer register setup, called from board_early_init_r() */
+void versal_timer_setup(void);
 
 #endif /* _ASM_ARCH_SYS_PROTO_H */
index d0c15fed1e93c7fc74a5a09fec74d1595506f518..0537517b1b2e82681a1d6a40b56ba48f1a68f591 100644 (file)
@@ -68,46 +68,10 @@ int board_init(void)
 
 int board_early_init_r(void)
 {
-       u32 val;
-
        if (current_el() != 3)
                return 0;
 
-       debug("iou_switch ctrl div0 %x\n",
-             readl(&crlapb_base->iou_switch_ctrl));
-
-       writel(IOU_SWITCH_CTRL_CLKACT_BIT |
-              (CONFIG_IOU_SWITCH_DIVISOR0 << IOU_SWITCH_CTRL_DIVISOR0_SHIFT),
-              &crlapb_base->iou_switch_ctrl);
-
-       /* Global timer init - Program time stamp reference clk */
-       val = readl(&crlapb_base->timestamp_ref_ctrl);
-       val |= CRL_APB_TIMESTAMP_REF_CTRL_CLKACT_BIT;
-       writel(val, &crlapb_base->timestamp_ref_ctrl);
-
-       debug("ref ctrl 0x%x\n",
-             readl(&crlapb_base->timestamp_ref_ctrl));
-
-       /* Clear reset of timestamp reg */
-       writel(0, &crlapb_base->rst_timestamp);
-
-       /*
-        * Program freq register in System counter and
-        * enable system counter.
-        */
-       writel(CONFIG_COUNTER_FREQUENCY,
-              &iou_scntr_secure->base_frequency_id_register);
-
-       debug("counter val 0x%x\n",
-             readl(&iou_scntr_secure->base_frequency_id_register));
-
-       writel(IOU_SCNTRS_CONTROL_EN,
-              &iou_scntr_secure->counter_control_register);
-
-       debug("scntrs control 0x%x\n",
-             readl(&iou_scntr_secure->counter_control_register));
-       debug("timer 0x%llx\n", get_ticks());
-       debug("timer 0x%llx\n", get_ticks());
+       versal_timer_setup();
 
        return 0;
 }