[U-Boot] [PATCH v1 02/12] rockchip: implement rockchip timer init function

Lin Huang hl at rock-chips.com
Wed Oct 21 07:37:43 CEST 2015


now the timer init function implement in board-spl.c, but it may
not use SPL in other board or other rockchip SOC, so implement timer
init in common.c, we can call it if we need.

Signed-off-by: Lin Huang <hl at rock-chips.com>
---
Changes in v1: None

 arch/arm/include/asm/arch-rockchip/hardware.h |  2 +-
 arch/arm/include/asm/arch-rockchip/timer.h    | 18 ++++++++++++++++++
 arch/arm/mach-rockchip/board.c                |  8 +++++++-
 arch/arm/mach-rockchip/common.c               | 11 +++++++++++
 include/configs/rk3288_common.h               |  3 ++-
 5 files changed, 39 insertions(+), 3 deletions(-)
 create mode 100644 arch/arm/include/asm/arch-rockchip/timer.h

diff --git a/arch/arm/include/asm/arch-rockchip/hardware.h b/arch/arm/include/asm/arch-rockchip/hardware.h
index d5af5b8..44bd67a 100644
--- a/arch/arm/include/asm/arch-rockchip/hardware.h
+++ b/arch/arm/include/asm/arch-rockchip/hardware.h
@@ -11,7 +11,7 @@
 #define RK_SETBITS(set)			RK_CLRSETBITS(0, set)
 #define RK_CLRBITS(clr)			RK_CLRSETBITS(clr, 0)
 
-#define TIMER7_BASE		0xff810020
+#define TIMER_BASE			CONFIG_SYS_TIMER_BASE
 
 #define rk_clrsetreg(addr, clr, set)	writel((clr) << 16 | (set), addr)
 #define rk_clrreg(addr, clr)		writel((clr) << 16, addr)
diff --git a/arch/arm/include/asm/arch-rockchip/timer.h b/arch/arm/include/asm/arch-rockchip/timer.h
new file mode 100644
index 0000000..57269e9
--- /dev/null
+++ b/arch/arm/include/asm/arch-rockchip/timer.h
@@ -0,0 +1,18 @@
+#ifndef __ASM_ARCH_TIMER_H
+#define __ASM_ARCH_TIMER_H
+
+struct rk_timer {
+	unsigned int timer_load_count0;
+	unsigned int timer_load_count1;
+	unsigned int timer_curr_value0;
+	unsigned int timer_curr_value1;
+	unsigned int timer_ctrl_reg;
+	unsigned int timer_int_status;
+};
+
+/**
+ * timer_init() - rockchip timer init
+ */
+void rockchip_timer_init(void);
+
+#endif
diff --git a/arch/arm/mach-rockchip/board.c b/arch/arm/mach-rockchip/board.c
index 688bc0f..789a801 100644
--- a/arch/arm/mach-rockchip/board.c
+++ b/arch/arm/mach-rockchip/board.c
@@ -3,7 +3,7 @@
  *
  * SPDX-License-Identifier:     GPL-2.0+
  */
-
+#include <asm/arch/timer.h>
 #include <common.h>
 #include <dm.h>
 #include <ram.h>
@@ -12,6 +12,12 @@ DECLARE_GLOBAL_DATA_PTR;
 
 int board_init(void)
 {
+#ifdef CONFIG_SPL_BUILD
+
+	/* have been init in spl board */
+#else
+	rockchip_timer_init();
+#endif
 	return 0;
 }
 
diff --git a/arch/arm/mach-rockchip/common.c b/arch/arm/mach-rockchip/common.c
index fc7ac72..eaf8bc1 100644
--- a/arch/arm/mach-rockchip/common.c
+++ b/arch/arm/mach-rockchip/common.c
@@ -4,6 +4,8 @@
  * SPDX-License-Identifier:     GPL-2.0+
  */
 
+#include <asm/io.h>
+#include <asm/arch/timer.h>
 #include <common.h>
 #include <dm.h>
 #include <errno.h>
@@ -26,3 +28,12 @@ void *rockchip_get_cru(void)
 
 	return (void *)addr;
 }
+
+void rockchip_timer_init(void)
+{
+	struct rk_timer * const timer_ptr = (void *)TIMER_BASE;
+
+	writel(0xffffffff, &timer_ptr->timer_load_count0);
+	writel(0xffffffff, &timer_ptr->timer_load_count1);
+	writel(1, &timer_ptr->timer_ctrl_reg);
+}
diff --git a/include/configs/rk3288_common.h b/include/configs/rk3288_common.h
index e8aec28..b4d040e 100644
--- a/include/configs/rk3288_common.h
+++ b/include/configs/rk3288_common.h
@@ -24,7 +24,8 @@
 #define CONFIG_DISPLAY_BOARDINFO
 
 #define CONFIG_SYS_TIMER_RATE		(24 * 1000 * 1000)
-#define CONFIG_SYS_TIMER_COUNTER	(TIMER7_BASE + 8)
+#define CONFIG_SYS_TIMER_BASE		0xff810020 /* TIMER7 */
+#define CONFIG_SYS_TIMER_COUNTER	(CONFIG_SYS_TIMER_BASE + 8)
 
 #define CONFIG_SPL_FRAMEWORK
 #define CONFIG_SPL_LIBCOMMON_SUPPORT
-- 
1.9.1



More information about the U-Boot mailing list