]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
refactor timer_init
authorDuje Mihanović <duje.mihanovic@skole.hr>
Thu, 26 Dec 2024 12:41:50 +0000 (13:41 +0100)
committerDuje Mihanović <duje.mihanovic@skole.hr>
Thu, 26 Dec 2024 12:41:50 +0000 (13:41 +0100)
board/samsung/coreprimevelte/coreprimevelte.c

index 7a8fe71effcc865b6e3ab78db01f8bc74a4b70ad..170566df74494e64ae8b8b93e09b1b22c5d7880a 100644 (file)
@@ -1,15 +1,28 @@
-#include <debug_uart.h>
 #include <fdtdec.h>
 #include <asm/io.h>
+#include <asm/global_data.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+/* Timer constants */
+#define APBC_COUNTER_CLK_SEL   0xd4015064
+#define COUNTER_BASE           0xd4101000
+#define COUNTER_EN             BIT(0)
+#define COUNTER_HALT_ON_DEBUG  BIT(1)
 
 int timer_init(void)
 {
-       u32 tmp = readl(0xd4015064);
+       u32 tmp = readl(APBC_COUNTER_CLK_SEL);
+
        if ((tmp >> 16) != 0x319)
                return -1;
 
-       writel(tmp | 1, 0xd4015064);
-       writel(3, 0xd4101000);
+       /* Set timer frequency to 26MHz */
+       writel(tmp | 1, APBC_COUNTER_CLK_SEL);
+       writel(COUNTER_EN | COUNTER_HALT_ON_DEBUG, COUNTER_BASE);
+
+       gd->arch.timer_rate_hz = 26000000;
+
        return 0;
 }