]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
imx: imx9: Add function to initialize timer
authorJian Li <jian.li@nxp.com>
Tue, 26 Jul 2022 08:40:46 +0000 (16:40 +0800)
committerStefano Babic <sbabic@denx.de>
Tue, 26 Jul 2022 09:29:00 +0000 (11:29 +0200)
Add timer_init to update ARM arch timer with correct frequency
from system counter and enable system counter.

Signed-off-by: Jian Li <jian.li@nxp.com>
Signed-off-by: Peng Fan <peng.fan@nxp.com>
arch/arm/include/asm/arch-imx9/imx-regs.h
arch/arm/mach-imx/imx9/soc.c

index 50ec902987d441024bf4d6316cdfb325cdec3f7c..32c76ce9c3bfd4980dd01efb5a8e8de3ea5aae3e 100644 (file)
@@ -11,6 +11,7 @@
 #define IOMUXC_BASE_ADDR       0x443C0000UL
 #define CCM_BASE_ADDR          0x44450000UL
 #define CCM_CCGR_BASE_ADDR     0x44458000UL
+#define SYSCNT_CTRL_BASE_ADDR  0x44290000
 
 #define ANATOP_BASE_ADDR    0x44480000UL
 
index d4a97729c673a3a9a69679a09c8231fd6938c6bf..4b8f1ca30d55855b4785aadf51c3eda0cc01eecd 100644 (file)
@@ -128,3 +128,22 @@ int arch_cpu_init(void)
 
        return 0;
 }
+
+int timer_init(void)
+{
+#ifdef CONFIG_SPL_BUILD
+       struct sctr_regs *sctr = (struct sctr_regs *)SYSCNT_CTRL_BASE_ADDR;
+       unsigned long freq = readl(&sctr->cntfid0);
+
+       /* Update with accurate clock frequency */
+       asm volatile("msr cntfrq_el0, %0" : : "r" (freq) : "memory");
+
+       clrsetbits_le32(&sctr->cntcr, SC_CNTCR_FREQ0 | SC_CNTCR_FREQ1,
+                       SC_CNTCR_FREQ0 | SC_CNTCR_ENABLE | SC_CNTCR_HDBG);
+#endif
+
+       gd->arch.tbl = 0;
+       gd->arch.tbu = 0;
+
+       return 0;
+}