Skip to contentSkip to conversation

rockchip: switch to use ARM arch/generic timer

PATCH New Kever Yang 1 participant 13 messages Jul 9, 2019

Subsystems (3)
lore
Share & tools
lore

Kever Yang

author
#0 lore raw

cover rockchip: switch to use ARM arch/generic timer

Rockchip SoCs other than rk3188, all with ARM arch/generic timer, which is also default used by kernel, switch to use the ARM arch/generic timer if the SoC have it.

Kever Yang (12):
rockchip: rk322x: sdram: use udelay instead of rockchip_udelay
rockchip: rk322x: use ARM arch timer instead of rk_timer
rockchip: rk3036: sdram: use udelay instead of rockchip_udelay
rockchip: rk3036: use ARM arch timer instead of rk_timer
rockchip: rk3288: use ARM arch timer instead of rk_timer
rockchip: rk3128: use ARM arch timer instead of rk_timer
rockchip: remove no use header file in board code
rockchip: remove rk_timer
rockchip: rk3368: move sgrf init to spl as arch_cpu_init()
rockchip: rk3368: enable stimer for rk3368
rockchip: rk3368-lion: switch to use ARM generic timer
rockchip: evb-px5: switch to use ARM generic timer

 arch/arm/dts/rk3368-lion-u-boot.dtsi         |  1 -
 arch/arm/dts/rk3368-px5-evb-u-boot.dtsi      |  1 -
 arch/arm/include/asm/arch-rockchip/timer.h   |  3 -
 arch/arm/mach-rockchip/Makefile              |  6 --
 arch/arm/mach-rockchip/rk3036-board-spl.c    | 29 ++++++-
 arch/arm/mach-rockchip/rk3036/sdram_rk3036.c | 19 +++--
 arch/arm/mach-rockchip/rk3128-board.c        |  3 -
 arch/arm/mach-rockchip/rk3188-board-spl.c    |  1 -
 arch/arm/mach-rockchip/rk322x-board-spl.c    | 30 ++++++++
 arch/arm/mach-rockchip/rk322x-board-tpl.c    | 33 +++++++-
 arch/arm/mach-rockchip/rk3288-board-spl.c    | 32 +++++++-
 arch/arm/mach-rockchip/rk3288-board-tpl.c    | 25 +++++-
 arch/arm/mach-rockchip/rk3368-board-spl.c    | 33 ++++++++
 arch/arm/mach-rockchip/rk3368-board-tpl.c    | 81 ++++----------------
 arch/arm/mach-rockchip/rk3368/rk3368.c       | 73 +++++++++++++++++-
 arch/arm/mach-rockchip/rk_timer.c            | 40 ----------
 configs/evb-px5_defconfig                    |  4 -
 configs/lion-rk3368_defconfig                |  4 -
 drivers/ram/rockchip/sdram_rk322x.c          | 29 ++++---
 include/configs/rk3036_common.h              |  7 +-
 include/configs/rk3128_common.h              |  7 +-
 include/configs/rk322x_common.h              |  7 +-
 include/configs/rk3288_common.h              |  7 +-
 include/configs/rk3368_common.h              |  3 +-
 scripts/config_whitelist.txt                 |  1 +
 25 files changed, 302 insertions(+), 177 deletions(-)
 delete mode 100644 arch/arm/mach-rockchip/rk_timer.c
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH 1/12 rockchip: rk322x: sdram: use udelay instead of rockchip_udelay

Use system api for udelay instead of vendor defined api, and rockchip_udelay() will be removed.

---

 drivers/ram/rockchip/sdram_rk322x.c | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)
drivers/ram/rockchip/sdram_rk322x.c +14 -15
index e96ac54c39..94893e17cf 100644
@@ -16,7 +16,6 @@
 #include <asm/arch-rockchip/grf_rk322x.h>
 #include <asm/arch-rockchip/hardware.h>
 #include <asm/arch-rockchip/sdram_rk322x.h>
-#include <asm/arch-rockchip/timer.h>
 #include <asm/arch-rockchip/uart.h>
 #include <asm/arch-rockchip/sdram_common.h>
 #include <asm/types.h>
@@ -96,26 +95,26 @@ void phy_pctrl_reset(struct rk322x_cru *cru,
 			1 << DDRCTRL_PSRST_SHIFT | 1 << DDRCTRL_SRST_SHIFT |
 			1 << DDRPHY_PSRST_SHIFT | 1 << DDRPHY_SRST_SHIFT);
 
-	rockchip_udelay(10);
+	udelay(10);
 
 	rk_clrreg(&cru->cru_softrst_con[5], 1 << DDRPHY_PSRST_SHIFT |
 						  1 << DDRPHY_SRST_SHIFT);
-	rockchip_udelay(10);
+	udelay(10);
 
 	rk_clrreg(&cru->cru_softrst_con[5], 1 << DDRCTRL_PSRST_SHIFT |
 						  1 << DDRCTRL_SRST_SHIFT);
-	rockchip_udelay(10);
+	udelay(10);
 
 	clrbits_le32(&ddr_phy->ddrphy_reg[0],
 		     SOFT_RESET_MASK << SOFT_RESET_SHIFT);
-	rockchip_udelay(10);
+	udelay(10);
 	setbits_le32(&ddr_phy->ddrphy_reg[0],
 		     SOFT_DERESET_ANALOG);
-	rockchip_udelay(5);
+	udelay(5);
 	setbits_le32(&ddr_phy->ddrphy_reg[0],
 		     SOFT_DERESET_DIGITAL);
 
-	rockchip_udelay(1);
+	udelay(1);
 }
 
 void phy_dll_bypass_set(struct rk322x_ddr_phy *ddr_phy, u32 freq)
@@ -154,7 +153,7 @@ static void send_command(struct rk322x_ddr_pctl *pctl,
 			 u32 rank, u32 cmd, u32 arg)
 {
 	writel((START_CMD | (rank << 20) | arg | cmd), &pctl->mcmd);
-	rockchip_udelay(1);
+	udelay(1);
 	while (readl(&pctl->mcmd) & START_CMD)
 		;
 }
@@ -167,7 +166,7 @@ static void memory_init(struct chan_info *chan,
 
 	if (dramtype == DDR3) {
 		send_command(pctl, 3, DESELECT_CMD, 0);
-		rockchip_udelay(1);
+		udelay(1);
 		send_command(pctl, 3, PREA_CMD, 0);
 		send_command(pctl, 3, MRS_CMD,
 			     (0x02 & BANK_ADDR_MASK) << BANK_ADDR_SHIFT |
@@ -196,17 +195,17 @@ static void memory_init(struct chan_info *chan,
 			     (0x63 & LPDDR23_MA_MASK) << LPDDR23_MA_SHIFT |
 			     (0 & LPDDR23_OP_MASK) <<
 			     LPDDR23_OP_SHIFT);
-		rockchip_udelay(10);
+		udelay(10);
 		send_command(pctl, 3, MRS_CMD,
 			     (0x10 & LPDDR23_MA_MASK) << LPDDR23_MA_SHIFT |
 			     (0xff & LPDDR23_OP_MASK) <<
 			     LPDDR23_OP_SHIFT);
-		rockchip_udelay(1);
+		udelay(1);
 		send_command(pctl, 3, MRS_CMD,
 			     (0x10 & LPDDR23_MA_MASK) << LPDDR23_MA_SHIFT |
 			     (0xff & LPDDR23_OP_MASK) <<
 			     LPDDR23_OP_SHIFT);
-		rockchip_udelay(1);
+		udelay(1);
 		send_command(pctl, 3, MRS_CMD,
 			     (1 & LPDDR23_MA_MASK) << LPDDR23_MA_SHIFT |
 			     (sdram_params->phy_timing.mr[1] &
@@ -243,7 +242,7 @@ static u32 data_training(struct chan_info *chan)
 			DQS_SQU_CAL_SEL_CS0);
 	setbits_le32(&ddr_phy->ddrphy_reg[2], DQS_SQU_CAL_START);
 
-	rockchip_udelay(30);
+	udelay(30);
 	ret = readl(&ddr_phy->ddrphy_reg[0xff]);
 
 	clrbits_le32(&ddr_phy->ddrphy_reg[2],
@@ -367,9 +366,9 @@ static void phy_softreset(struct dram_info *dram)
 
 	writel(GRF_DDRPHY_BUFFEREN_CORE_EN, &grf->soc_con[0]);
 	clrbits_le32(&ddr_phy->ddrphy_reg[0], 0x3 << 2);
-	rockchip_udelay(1);
+	udelay(1);
 	setbits_le32(&ddr_phy->ddrphy_reg[0], 1 << 2);
-	rockchip_udelay(5);
+	udelay(5);
 	setbits_le32(&ddr_phy->ddrphy_reg[0], 1 << 3);
 	writel(GRF_DDRPHY_BUFFEREN_CORE_DIS, &grf->soc_con[0]);
 }
Signature · 1 line
2.17.1
author
#2 lore raw

PATCH 2/12 rockchip: rk322x: use ARM arch timer instead of rk_timer

In reply to Kever Yang

We prefer to use ARM arch timer instead of rockchip timer, so that we are using the same timer for SPL, U-Boot and Kernel, which will make things simple and easy to track to boot time.

---

 arch/arm/mach-rockchip/Makefile           |  2 +-
 arch/arm/mach-rockchip/rk322x-board-spl.c | 30 +++++++++++++++++++++
 arch/arm/mach-rockchip/rk322x-board-tpl.c | 33 ++++++++++++++++++++---
 include/configs/rk322x_common.h           |  7 ++---
 scripts/config_whitelist.txt              |  1 +
 5 files changed, 66 insertions(+), 7 deletions(-)
arch/arm/mach-rockchip/Makefile +1 -1
index 0c169e9234..933b0a182a 100644
@@ -42,7 +42,7 @@ endif
 obj-$(CONFIG_$(SPL_TPL_)RAM) += sdram_common.o
 
 ifndef CONFIG_ARM64
-ifndef CONFIG_ROCKCHIP_RK3188
+ifeq ($(CONFIG_ROCKCHIP_RK3188)$(CONFIG_ROCKCHIP_RK322X),)
 obj-y += rk_timer.o
 endif
 endif
arch/arm/mach-rockchip/rk322x-board-spl.c +30 -0
index c9b41c62c0..c825e31c02 100644
@@ -19,6 +19,31 @@ u32 spl_boot_mode(const u32 boot_device)
 	return MMCSD_MODE_RAW;
 }
 
+#define TIMER_LOAD_COUNT_L	0x00
+#define TIMER_LOAD_COUNT_H	0x04
+#define TIMER_CONTROL_REG	0x10
+#define TIMER_EN	0x1
+#define	TIMER_FMODE	BIT(0)
+#define	TIMER_RMODE	BIT(1)
+
+void rockchip_stimer_init(void)
+{
+	/* If Timer already enabled, don't re-init it */
+	u32 reg = readl(CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG);
+
+	if (reg & TIMER_EN)
+		return;
+
+	asm volatile("mcr p15, 0, %0, c14, c0, 0"
+		     : : "r"(COUNTER_FREQUENCY));
+
+	writel(0, CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG);
+	writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE);
+	writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE + 4);
+	writel(TIMER_EN | TIMER_FMODE, CONFIG_ROCKCHIP_STIMER_BASE +
+	       TIMER_CONTROL_REG);
+}
+
 #define SGRF_DDR_CON0 0x10150000
 void board_init_f(ulong dummy)
 {
@@ -31,6 +56,11 @@ void board_init_f(ulong dummy)
 	}
 	preloader_console_init();
 
+	/* Init secure timer */
+	rockchip_stimer_init();
+	/* Init ARM arch timer in arch/arm/cpu/armv7/arch_timer.c */
+	timer_init();
+
 	/* Disable the ddr secure region setting to make it non-secure */
 	rk_clrreg(SGRF_DDR_CON0, 0x4000);
 }
arch/arm/mach-rockchip/rk322x-board-tpl.c +30 -3
index 92d40ee43a..a0d7bc9b05 100644
@@ -10,13 +10,37 @@
 #include <spl.h>
 #include <asm/io.h>
 #include <asm/arch-rockchip/bootrom.h>
-#include <asm/arch-rockchip/timer.h>
 
 u32 spl_boot_device(void)
 {
 	return BOOT_DEVICE_MMC1;
 }
 
+#define TIMER_LOAD_COUNT_L	0x00
+#define TIMER_LOAD_COUNT_H	0x04
+#define TIMER_CONTROL_REG	0x10
+#define TIMER_EN	0x1
+#define	TIMER_FMODE	BIT(0)
+#define	TIMER_RMODE	BIT(1)
+
+void rockchip_stimer_init(void)
+{
+	/* If Timer already enabled, don't re-init it */
+	u32 reg = readl(CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG);
+
+	if (reg & TIMER_EN)
+		return;
+
+	asm volatile("mcr p15, 0, %0, c14, c0, 0"
+		     : : "r"(COUNTER_FREQUENCY));
+
+	writel(0, CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG);
+	writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE);
+	writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE + 4);
+	writel(TIMER_EN | TIMER_FMODE, CONFIG_ROCKCHIP_STIMER_BASE +
+	       TIMER_CONTROL_REG);
+}
+
 void board_init_f(ulong dummy)
 {
 	struct udevice *dev;
@@ -39,8 +63,11 @@ void board_init_f(ulong dummy)
 		hang();
 	}
 
-	rockchip_timer_init();
-	printf("timer init done\n");
+	/* Init secure timer */
+	rockchip_stimer_init();
+	/* Init ARM arch timer in arch/arm/cpu/armv7/arch_timer.c */
+	timer_init();
+
 	ret = uclass_get_device(UCLASS_RAM, 0, &dev);
 	if (ret) {
 		printf("DRAM init failed: %d\n", ret);
include/configs/rk322x_common.h +4 -3
index 15bb8d63b8..cc08699944 100644
@@ -13,9 +13,10 @@
 #define CONFIG_SYS_CBSIZE		1024
 #define CONFIG_SYS_BOOTM_LEN	(64 << 20)	/*  64M */
 
-#define CONFIG_SYS_TIMER_RATE		(24 * 1000 * 1000)
-#define CONFIG_SYS_TIMER_BASE		0x110c00a0 /* TIMER5 */
-#define CONFIG_SYS_TIMER_COUNTER	(CONFIG_SYS_TIMER_BASE + 8)
+#define CONFIG_ROCKCHIP_STIMER_BASE	0x110d0020
+#define COUNTER_FREQUENCY		24000000
+#define CONFIG_SYS_ARCH_TIMER
+#define CONFIG_SYS_HZ_CLOCK		24000000
 
 #define CONFIG_SYS_INIT_SP_ADDR		0x61100000
 #define CONFIG_SYS_LOAD_ADDR		0x61800800
scripts/config_whitelist.txt +1 -0
index d252045d80..a69badb5d2 100644
@@ -1540,6 +1540,7 @@ CONFIG_RMSTP9_ENA
 CONFIG_ROCKCHIP_CHIP_TAG
 CONFIG_ROCKCHIP_MAX_INIT_SIZE
 CONFIG_ROCKCHIP_SDHCI_MAX_FREQ
+CONFIG_ROCKCHIP_STIMER_BASE
 CONFIG_ROM_STUBS
 CONFIG_ROOTFS_OFFSET
 CONFIG_ROOTPATH
Signature · 1 line
2.17.1
author
#3 lore raw

PATCH 3/12 rockchip: rk3036: sdram: use udelay instead of rockchip_udelay

In reply to Kever Yang

Use system api for udelay instead of vendor defined api, and rockchip_udelay() will be removed.

---

 arch/arm/mach-rockchip/rk3036/sdram_rk3036.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)
arch/arm/mach-rockchip/rk3036/sdram_rk3036.c +9 -10
index 1d940a0d77..c39cbb8111 100644
@@ -9,7 +9,6 @@
 #include <asm/arch-rockchip/grf_rk3036.h>
 #include <asm/arch-rockchip/hardware.h>
 #include <asm/arch-rockchip/sdram_rk3036.h>
-#include <asm/arch-rockchip/timer.h>
 #include <asm/arch-rockchip/uart.h>
 
 /*
@@ -345,7 +344,7 @@ static void rkdclk_init(struct rk3036_sdram_priv *priv)
 
 	/* waiting for pll lock */
 	while (readl(&pll->con1) & (1 << PLL_LOCK_STATUS_SHIFT))
-		rockchip_udelay(1);
+		udelay(1);
 
 	/* PLL enter normal-mode */
 	rk_clrsetreg(&priv->cru->cru_mode_con, DPLL_MODE_MASK,
@@ -373,25 +372,25 @@ void phy_pctrl_reset(struct rk3036_sdram_priv *priv)
 			1 << DDRCTRL_PSRST_SHIFT | 1 << DDRCTRL_SRST_SHIFT |
 			1 << DDRPHY_PSRST_SHIFT | 1 << DDRPHY_SRST_SHIFT);
 
-	rockchip_udelay(10);
+	udelay(10);
 
 	rk_clrreg(&priv->cru->cru_softrst_con[5], 1 << DDRPHY_PSRST_SHIFT |
 						  1 << DDRPHY_SRST_SHIFT);
-	rockchip_udelay(10);
+	udelay(10);
 
 	rk_clrreg(&priv->cru->cru_softrst_con[5], 1 << DDRCTRL_PSRST_SHIFT |
 						  1 << DDRCTRL_SRST_SHIFT);
-	rockchip_udelay(10);
+	udelay(10);
 
 	clrsetbits_le32(&ddr_phy->ddrphy_reg1,
 			SOFT_RESET_MASK << SOFT_RESET_SHIFT,
 			0 << SOFT_RESET_SHIFT);
-	rockchip_udelay(10);
+	udelay(10);
 	clrsetbits_le32(&ddr_phy->ddrphy_reg1,
 			SOFT_RESET_MASK << SOFT_RESET_SHIFT,
 			3 << SOFT_RESET_SHIFT);
 
-	rockchip_udelay(1);
+	udelay(1);
 }
 
 void phy_dll_bypass_set(struct rk3036_sdram_priv *priv, unsigned int freq)
@@ -444,7 +443,7 @@ static void send_command(struct rk3036_ddr_pctl *pctl,
 			 u32 rank, u32 cmd, u32 arg)
 {
 	writel((START_CMD | (rank << 20) | arg | cmd), &pctl->mcmd);
-	rockchip_udelay(1);
+	udelay(1);
 	while (readl(&pctl->mcmd) & START_CMD)
 		;
 }
@@ -454,7 +453,7 @@ static void memory_init(struct rk3036_sdram_priv *priv)
 	struct rk3036_ddr_pctl *pctl = priv->pctl;
 
 	send_command(pctl, 3, DESELECT_CMD, 0);
-	rockchip_udelay(1);
+	udelay(1);
 	send_command(pctl, 3, PREA_CMD, 0);
 	send_command(pctl, 3, MRS_CMD,
 		     (0x02 & BANK_ADDR_MASK) << BANK_ADDR_SHIFT |
@@ -492,7 +491,7 @@ static void data_training(struct rk3036_sdram_priv *priv)
 	clrsetbits_le32(&ddr_phy->ddrphy_reg2, 0x03,
 			DQS_SQU_CAL_NORMAL_MODE | DQS_SQU_CAL_START);
 
-	rockchip_udelay(1);
+	udelay(1);
 	while ((readl(&ddr_phy->ddrphy_reg62) & CAL_DONE_MASK) !=
 		(HIGH_8BIT_CAL_DONE | LOW_8BIT_CAL_DONE)) {
 		;
Signature · 1 line
2.17.1
author
#4 lore raw

PATCH 4/12 rockchip: rk3036: use ARM arch timer instead of rk_timer

In reply to Kever Yang

We prefer to use ARM arch timer instead of rockchip timer, so that we are using the same timer for SPL, U-Boot and Kernel, which will make things simple and easy to track the boot time.

---

 arch/arm/mach-rockchip/Makefile           |  2 +-
 arch/arm/mach-rockchip/rk3036-board-spl.c | 29 ++++++++++++++++++++---
 include/configs/rk3036_common.h           |  7 +++---
 3 files changed, 31 insertions(+), 7 deletions(-)
arch/arm/mach-rockchip/Makefile +1 -1
index 933b0a182a..2a0db0af80 100644
@@ -42,7 +42,7 @@ endif
 obj-$(CONFIG_$(SPL_TPL_)RAM) += sdram_common.o
 
 ifndef CONFIG_ARM64
-ifeq ($(CONFIG_ROCKCHIP_RK3188)$(CONFIG_ROCKCHIP_RK322X),)
+ifeq ($(CONFIG_ROCKCHIP_RK3188)$(CONFIG_ROCKCHIP_RK322X)$(CONFIG_ROCKCHIP_RK3036),)
 obj-y += rk_timer.o
 endif
 endif
arch/arm/mach-rockchip/rk3036-board-spl.c +26 -3
index 110d06dba5..fbc89b66c4 100644
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
- * (C) Copyright 2015 Rockchip Electronics Co., Ltd
+ * (C) Copyright 2015-2019 Rockchip Electronics Co., Ltd
  */
 
 #include <common.h>
@@ -8,14 +8,37 @@
 #include <asm/io.h>
 #include <asm/arch-rockchip/bootrom.h>
 #include <asm/arch-rockchip/sdram_rk3036.h>
-#include <asm/arch-rockchip/timer.h>
+
+#define TIMER_LOAD_COUNT_L	0x00
+#define TIMER_LOAD_COUNT_H	0x04
+#define TIMER_CONTROL_REG	0x10
+#define TIMER_EN	0x1
+#define	TIMER_FMODE	(0 << 1)
+#define	TIMER_RMODE	(1 << 1)
+
+void rockchip_stimer_init(void)
+{
+	asm volatile("mcr p15, 0, %0, c14, c0, 0"
+		     : : "r"(COUNTER_FREQUENCY));
+
+	writel(0, CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG);
+	writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE);
+	writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE + 4);
+	writel(TIMER_EN | TIMER_FMODE, CONFIG_ROCKCHIP_STIMER_BASE +
+	       TIMER_CONTROL_REG);
+}
 
 void board_init_f(ulong dummy)
 {
 #ifdef CONFIG_DEBUG_UART
 	debug_uart_init();
 #endif
-	rockchip_timer_init();
+
+	/* Init secure timer */
+	rockchip_stimer_init();
+	/* Init ARM arch timer in arch/arm/cpu/armv7/arch_timer.c */
+	timer_init();
+
 	sdram_init();
 
 	/* return to maskrom */
include/configs/rk3036_common.h +4 -3
index f5d09d18e5..73be079b20 100644
@@ -12,9 +12,10 @@
 #define CONFIG_SYS_CBSIZE		1024
 #define CONFIG_SKIP_LOWLEVEL_INIT
 
-#define CONFIG_SYS_TIMER_RATE		(24 * 1000 * 1000)
-#define CONFIG_SYS_TIMER_BASE		0x200440a0 /* TIMER5 */
-#define CONFIG_SYS_TIMER_COUNTER	(CONFIG_SYS_TIMER_BASE + 8)
+#define CONFIG_ROCKCHIP_STIMER_BASE	0x200440a0
+#define COUNTER_FREQUENCY		24000000
+#define CONFIG_SYS_ARCH_TIMER
+#define CONFIG_SYS_HZ_CLOCK		24000000
 
 #define CONFIG_SYS_INIT_SP_ADDR		0x60100000
 #define CONFIG_SYS_LOAD_ADDR		0x60800800
Signature · 1 line
2.17.1
author
#5 lore raw

PATCH 5/12 rockchip: rk3288: use ARM arch timer instead of rk_timer

In reply to Kever Yang

We prefer to use ARM arch timer instead of rockchip timer, so that we are using the same timer for SPL, U-Boot and Kernel, which will make things simple and easy to track to boot time.

---

 arch/arm/mach-rockchip/Makefile           |  2 +-
 arch/arm/mach-rockchip/rk3288-board-spl.c | 32 +++++++++++++++++++++--
 arch/arm/mach-rockchip/rk3288-board-tpl.c | 25 ++++++++++++++++--
 include/configs/rk3288_common.h           |  7 ++---
 4 files changed, 58 insertions(+), 8 deletions(-)
arch/arm/mach-rockchip/Makefile +1 -1
index 2a0db0af80..3e3aa1c421 100644
@@ -42,7 +42,7 @@ endif
 obj-$(CONFIG_$(SPL_TPL_)RAM) += sdram_common.o
 
 ifndef CONFIG_ARM64
-ifeq ($(CONFIG_ROCKCHIP_RK3188)$(CONFIG_ROCKCHIP_RK322X)$(CONFIG_ROCKCHIP_RK3036),)
+ifeq ($(CONFIG_ROCKCHIP_RK3188)$(CONFIG_ROCKCHIP_RK322X)$(CONFIG_ROCKCHIP_RK3036)$(CONFIG_ROCKCHIP_RK3288),)
 obj-y += rk_timer.o
 endif
 endif
arch/arm/mach-rockchip/rk3288-board-spl.c +30 -2
index 3869de9119..c2e168192c 100644
@@ -22,7 +22,6 @@
 #include <asm/arch-rockchip/sdram.h>
 #include <asm/arch-rockchip/sdram_common.h>
 #include <asm/arch-rockchip/sys_proto.h>
-#include <asm/arch-rockchip/timer.h>
 #include <dm/root.h>
 #include <dm/test.h>
 #include <dm/util.h>
@@ -108,6 +107,31 @@ __weak int arch_cpu_init(void)
 	return 0;
 }
 
+#define TIMER_LOAD_COUNT_L	0x00
+#define TIMER_LOAD_COUNT_H	0x04
+#define TIMER_CONTROL_REG	0x10
+#define TIMER_EN	0x1
+#define	TIMER_FMODE	BIT(0)
+#define	TIMER_RMODE	BIT(1)
+
+void rockchip_stimer_init(void)
+{
+	/* If Timer already enabled, don't re-init it */
+	u32 reg = readl(CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG);
+
+	if (reg & TIMER_EN)
+		return;
+
+	asm volatile("mcr p15, 0, %0, c14, c0, 0"
+		     : : "r"(COUNTER_FREQUENCY));
+
+	writel(0, CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG);
+	writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE);
+	writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE + 4);
+	writel(TIMER_EN | TIMER_FMODE, CONFIG_ROCKCHIP_STIMER_BASE +
+	       TIMER_CONTROL_REG);
+}
+
 void board_init_f(ulong dummy)
 {
 	struct udevice *dev;
@@ -131,7 +155,11 @@ void board_init_f(ulong dummy)
 		hang();
 	}
 
-	rockchip_timer_init();
+	/* Init secure timer */
+	rockchip_stimer_init();
+	/* Init ARM arch timer in arch/arm/cpu/armv7/arch_timer.c */
+	timer_init();
+
 	arch_cpu_init();
 
 	ret = rockchip_get_clk(&dev);
arch/arm/mach-rockchip/rk3288-board-tpl.c +23 -2
index 5adbe92185..96de7927f0 100644
@@ -12,7 +12,25 @@
 #include <asm/io.h>
 #include <asm/arch-rockchip/bootrom.h>
 #include <asm/arch-rockchip/clock.h>
-#include <asm/arch-rockchip/timer.h>
+
+#define TIMER_LOAD_COUNT_L	0x00
+#define TIMER_LOAD_COUNT_H	0x04
+#define TIMER_CONTROL_REG	0x10
+#define TIMER_EN	0x1
+#define	TIMER_FMODE	BIT(0)
+#define	TIMER_RMODE	BIT(1)
+
+void rockchip_stimer_init(void)
+{
+	asm volatile("mcr p15, 0, %0, c14, c0, 0"
+		     : : "r"(COUNTER_FREQUENCY));
+
+	writel(0, CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG);
+	writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE);
+	writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE + 4);
+	writel(TIMER_EN | TIMER_FMODE, CONFIG_ROCKCHIP_STIMER_BASE +
+	       TIMER_CONTROL_REG);
+}
 
 void board_init_f(ulong dummy)
 {
@@ -36,7 +54,10 @@ void board_init_f(ulong dummy)
 		hang();
 	}
 
-	rockchip_timer_init();
+	/* Init secure timer */
+	rockchip_stimer_init();
+	/* Init ARM arch timer in arch/arm/cpu/armv7/arch_timer.c */
+	timer_init();
 
 	ret = rockchip_get_clk(&dev);
 	if (ret) {
include/configs/rk3288_common.h +4 -3
index 06073cbb61..5472a90633 100644
@@ -13,9 +13,10 @@
 #define CONFIG_SYS_MALLOC_LEN		(32 << 20)
 #define CONFIG_SYS_CBSIZE		1024
 
-#define CONFIG_SYS_TIMER_RATE		(24 * 1000 * 1000)
-#define	CONFIG_SYS_TIMER_BASE		0xff810020 /* TIMER7 */
-#define CONFIG_SYS_TIMER_COUNTER	(CONFIG_SYS_TIMER_BASE + 8)
+#define CONFIG_ROCKCHIP_STIMER_BASE	0xff810020
+#define COUNTER_FREQUENCY		24000000
+#define CONFIG_SYS_ARCH_TIMER
+#define CONFIG_SYS_HZ_CLOCK		24000000
 
 #ifdef CONFIG_SPL_ROCKCHIP_BACK_TO_BROM
 /* Bootrom will load u-boot binary to 0x0 once return from SPL */
Signature · 1 line
2.17.1
author
#6 lore raw

PATCH 6/12 rockchip: rk3128: use ARM arch timer instead of rk_timer

In reply to Kever Yang

We prefer to use ARM arch timer instead of rockchip timer, so that we are using the same timer for SPL, U-Boot and Kernel, which will make things simple and easy to track to boot time.

---

 arch/arm/mach-rockchip/Makefile       | 6 ------
 arch/arm/mach-rockchip/rk3128-board.c | 3 ---
 include/configs/rk3128_common.h       | 7 ++++---
 3 files changed, 4 insertions(+), 12 deletions(-)
arch/arm/mach-rockchip/Makefile +0 -6
index 3e3aa1c421..9afbb055d5 100644
@@ -41,12 +41,6 @@ endif
 
 obj-$(CONFIG_$(SPL_TPL_)RAM) += sdram_common.o
 
-ifndef CONFIG_ARM64
-ifeq ($(CONFIG_ROCKCHIP_RK3188)$(CONFIG_ROCKCHIP_RK322X)$(CONFIG_ROCKCHIP_RK3036)$(CONFIG_ROCKCHIP_RK3288),)
-obj-y += rk_timer.o
-endif
-endif
-
 obj-$(CONFIG_ROCKCHIP_RK3036) += rk3036/
 obj-$(CONFIG_ROCKCHIP_RK3128) += rk3128/
 ifndef CONFIG_TPL_BUILD
arch/arm/mach-rockchip/rk3128-board.c +0 -3
index fa71685af8..0945829d0e 100644
@@ -12,7 +12,6 @@
 #include <asm/arch-rockchip/periph.h>
 #include <asm/arch-rockchip/grf_rk3128.h>
 #include <asm/arch-rockchip/boot_mode.h>
-#include <asm/arch-rockchip/timer.h>
 #include <power/regulator.h>
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -33,8 +32,6 @@ int board_init(void)
 {
 	int ret = 0;
 
-	rockchip_timer_init();
-
 	ret = regulators_enable_boot_on(false);
 	if (ret) {
 		debug("%s: Cannot enable boot on regulator\n", __func__);
include/configs/rk3128_common.h +4 -3
index 0c08d7af5b..20d62439fb 100644
@@ -14,9 +14,10 @@
 #define CONFIG_SYS_CBSIZE		1024
 #define CONFIG_SKIP_LOWLEVEL_INIT
 
-#define CONFIG_SYS_TIMER_RATE		(24 * 1000 * 1000)
-#define CONFIG_SYS_TIMER_BASE		0x200440a0 /* TIMER5 */
-#define CONFIG_SYS_TIMER_COUNTER	(CONFIG_SYS_TIMER_BASE + 8)
+#define CONFIG_ROCKCHIP_STIMER_BASE	0x200440a0
+#define COUNTER_FREQUENCY		24000000
+#define CONFIG_SYS_ARCH_TIMER
+#define CONFIG_SYS_HZ_CLOCK		24000000
 
 #define CONFIG_SYS_INIT_SP_ADDR		0x60100000
 #define CONFIG_SYS_LOAD_ADDR		0x60800800
Signature · 1 line
2.17.1
author
#7 lore raw

PATCH 7/12 rockchip: remove no use header file in board code

In reply to Kever Yang

The timer.h is no use any more, remove it from the board files.

---

 arch/arm/mach-rockchip/rk3188-board-spl.c | 1 -
 arch/arm/mach-rockchip/rk3368-board-tpl.c | 1 -
 2 files changed, 2 deletions(-)
arch/arm/mach-rockchip/rk3188-board-spl.c +0 -1
index 84c2a5756f..c3efe0d7a9 100644
@@ -22,7 +22,6 @@
 #include <asm/arch-rockchip/periph.h>
 #include <asm/arch-rockchip/pmu_rk3188.h>
 #include <asm/arch-rockchip/sdram.h>
-#include <asm/arch-rockchip/timer.h>
 #include <dm/root.h>
 #include <dm/test.h>
 #include <dm/util.h>
arch/arm/mach-rockchip/rk3368-board-tpl.c +0 -1
index dc65a021c8..42aeb2e91c 100644
@@ -14,7 +14,6 @@
 #include <asm/arch-rockchip/clock.h>
 #include <asm/arch-rockchip/cru_rk3368.h>
 #include <asm/arch-rockchip/hardware.h>
-#include <asm/arch-rockchip/timer.h>
 
 /*
  * The SPL (and also the full U-Boot stage on the RK3368) will run in
Signature · 1 line
2.17.1
author
#8 lore raw

PATCH 8/12 rockchip: remove rk_timer

In reply to Kever Yang

We have convert all SoC to use DM timer or ARM arch/generic timer, we can remove this rk_timer now.

---

 arch/arm/include/asm/arch-rockchip/timer.h |  3 --
 arch/arm/mach-rockchip/rk_timer.c          | 40 ----------------------
 2 files changed, 43 deletions(-)
 delete mode 100644 arch/arm/mach-rockchip/rk_timer.c
arch/arm/include/asm/arch-rockchip/timer.h +0 -3
index a8379be912..77b5422044 100644
@@ -15,7 +15,4 @@ struct rk_timer {
 	u32 timer_int_status;
 };
 
-void rockchip_timer_init(void);
-void rockchip_udelay(unsigned int usec);
-
 #endif
arch/arm/mach-rockchip/rk_timer.c deleted +0 -40
deleted file mode 100644
index 29d379fa0a..0000000000
@@ -1,40 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-/*
- * (C) Copyright 2015 Rockchip Electronics Co., Ltd
- */
-
-#include <common.h>
-#include <asm/arch-rockchip/timer.h>
-#include <asm/io.h>
-#include <linux/types.h>
-
-struct rk_timer * const timer_ptr = (void *)CONFIG_SYS_TIMER_BASE;
-
-static uint64_t rockchip_get_ticks(void)
-{
-	uint64_t timebase_h, timebase_l;
-
-	timebase_l = readl(&timer_ptr->timer_curr_value0);
-	timebase_h = readl(&timer_ptr->timer_curr_value1);
-
-	return timebase_h << 32 | timebase_l;
-}
-
-void rockchip_udelay(unsigned int usec)
-{
-	uint64_t tmp;
-
-	/* get timestamp */
-	tmp = rockchip_get_ticks() + usec_to_tick(usec);
-
-	/* loop till event */
-	while (rockchip_get_ticks() < tmp+1)
-		;
-}
-
-void rockchip_timer_init(void)
-{
-	writel(0xffffffff, &timer_ptr->timer_load_count0);
-	writel(0xffffffff, &timer_ptr->timer_load_count1);
-	writel(1, &timer_ptr->timer_ctrl_reg);
-}
Signature · 1 line
2.17.1
author
#9 lore raw

PATCH 9/12 rockchip: rk3368: move sgrf init to spl as arch_cpu_init()

In reply to Kever Yang

The SoC related init will move to SPL and keep TPL clean, so that we can reuse the common TPL board file.

---

 arch/arm/mach-rockchip/rk3368-board-spl.c |  6 ++
 arch/arm/mach-rockchip/rk3368-board-tpl.c | 69 ---------------------
 arch/arm/mach-rockchip/rk3368/rk3368.c    | 73 ++++++++++++++++++++++-
 3 files changed, 78 insertions(+), 70 deletions(-)
arch/arm/mach-rockchip/rk3368-board-spl.c +6 -0
index c651193712..3a7d0b640a 100644
@@ -11,6 +11,11 @@
 #include <asm/io.h>
 #include <asm/arch-rockchip/periph.h>
 
+__weak int arch_cpu_init(void)
+{
+	return 0;
+}
+
 void board_init_f(ulong dummy)
 {
 	struct udevice *dev;
@@ -22,6 +27,7 @@ void board_init_f(ulong dummy)
 		hang();
 	}
 
+	arch_cpu_init();
 	preloader_console_init();
 
 	ret = uclass_get_device(UCLASS_RAM, 0, &dev);
arch/arm/mach-rockchip/rk3368-board-tpl.c +0 -69

83 lines not on this page · raw message

arch/arm/mach-rockchip/rk3368/rk3368.c +72 -1

88 lines not on this page · raw message

Signature · 1 line
2.17.1
author
#10 lore raw

PATCH 10/12 rockchip: rk3368: enable stimer for rk3368

In reply to Kever Yang

Add stimer_init() for spl/tpl so that we able to switch to use arch timer.

---

 arch/arm/mach-rockchip/rk3368-board-spl.c | 27 +++++++++++++++++++++++
 arch/arm/mach-rockchip/rk3368-board-tpl.c | 21 ++++++++++++++++++
 include/configs/rk3368_common.h           |  3 ++-
 3 files changed, 50 insertions(+), 1 deletion(-)
arch/arm/mach-rockchip/rk3368-board-spl.c +27 -0
index 3a7d0b640a..6ba106c63b 100644
@@ -16,6 +16,28 @@ __weak int arch_cpu_init(void)
 	return 0;
 }
 
+#define TIMER_LOAD_COUNT_L	0x00
+#define TIMER_LOAD_COUNT_H	0x04
+#define TIMER_CONTROL_REG	0x10
+#define TIMER_EN	0x1
+#define	TIMER_FMODE	BIT(0)
+#define	TIMER_RMODE	BIT(1)
+
+void rockchip_stimer_init(void)
+{
+	/* If Timer already enabled, don't re-init it */
+	u32 reg = readl(CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG);
+
+	if (reg & TIMER_EN)
+		return;
+
+	writel(0, CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG);
+	writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE);
+	writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE + 4);
+	writel(TIMER_EN | TIMER_FMODE, CONFIG_ROCKCHIP_STIMER_BASE +
+	       TIMER_CONTROL_REG);
+}
+
 void board_init_f(ulong dummy)
 {
 	struct udevice *dev;
@@ -27,6 +49,11 @@ void board_init_f(ulong dummy)
 		hang();
 	}
 
+	/* Init secure timer */
+	rockchip_stimer_init();
+	/* Init ARM arch timer in arch/arm/cpu/armv7/arch_timer.c */
+	timer_init();
+
 	arch_cpu_init();
 	preloader_console_init();
 
arch/arm/mach-rockchip/rk3368-board-tpl.c +21 -0
index a1da8ccb0f..fdb1c3b365 100644
@@ -11,6 +11,22 @@
 #include <asm/io.h>
 #include <asm/arch-rockchip/bootrom.h>
 
+#define TIMER_LOAD_COUNT_L	0x00
+#define TIMER_LOAD_COUNT_H	0x04
+#define TIMER_CONTROL_REG	0x10
+#define TIMER_EN	0x1
+#define	TIMER_FMODE	BIT(0)
+#define	TIMER_RMODE	BIT(1)
+
+__weak void rockchip_stimer_init(void)
+{
+	writel(0, CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG);
+	writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE);
+	writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE + 4);
+	writel(TIMER_EN | TIMER_FMODE, CONFIG_ROCKCHIP_STIMER_BASE +
+	       TIMER_CONTROL_REG);
+}
+
 void board_init_f(ulong dummy)
 {
 	struct udevice *dev;
@@ -35,6 +51,11 @@ void board_init_f(ulong dummy)
 		hang();
 	}
 
+	/* Init secure timer */
+	rockchip_stimer_init();
+	/* Init ARM arch timer in arch/arm/cpu/ */
+	timer_init();
+
 	ret = uclass_get_device(UCLASS_RAM, 0, &dev);
 	if (ret) {
 		debug("DRAM init failed: %d\n", ret);
include/configs/rk3368_common.h +2 -1
index 13630ba386..c5a52d46c9 100644
@@ -20,7 +20,8 @@
 #define CONFIG_SYS_CBSIZE		1024
 #define CONFIG_SKIP_LOWLEVEL_INIT
 
-#define COUNTER_FREQUENCY               24000000
+#define CONFIG_ROCKCHIP_STIMER_BASE	0xff810020
+#define COUNTER_FREQUENCY		24000000
 
 #define CONFIG_SYS_NS16550_MEM32
 
Signature · 1 line
2.17.1
author
#11 lore raw

PATCH 11/12 rockchip: rk3368-lion: switch to use ARM generic timer

In reply to Kever Yang

Default to use ARM generic timer in ARM64, switch from rk timer to generic timer.

---

 arch/arm/dts/rk3368-lion-u-boot.dtsi | 1 -
 configs/lion-rk3368_defconfig        | 4 ----
 2 files changed, 5 deletions(-)
arch/arm/dts/rk3368-lion-u-boot.dtsi +0 -1
index fb4a4fb59c..edc93e438f 100644
@@ -12,7 +12,6 @@
 	chosen {
 		stdout-path = "serial0:115200n8";
 		u-boot,spl-boot-order = &emmc, &sdmmc;
-		tick-timer = "/timer at ff810000";
 	};
 
 };
configs/lion-rk3368_defconfig +0 -4
index ff3255be7a..2c4e11c4d4 100644
@@ -88,10 +88,6 @@ CONFIG_DEBUG_UART_ANNOUNCE=y
 CONFIG_DEBUG_UART_SKIP_INIT=y
 CONFIG_ROCKCHIP_SPI=y
 CONFIG_SYSRESET=y
-CONFIG_TIMER=y
-CONFIG_SPL_TIMER=y
-CONFIG_TPL_TIMER=y
-CONFIG_ROCKCHIP_TIMER=y
 CONFIG_USE_TINY_PRINTF=y
 CONFIG_SPL_TINY_MEMSET=y
 CONFIG_LZO=y
Signature · 1 line
2.17.1
author
#12 lore raw

PATCH 12/12 rockchip: evb-px5: switch to use ARM generic timer

In reply to Kever Yang

Default to use ARM generic timer in ARM64, switch from rk timer to generic timer.

---

 arch/arm/dts/rk3368-px5-evb-u-boot.dtsi | 1 -
 configs/evb-px5_defconfig               | 4 ----
 2 files changed, 5 deletions(-)
arch/arm/dts/rk3368-px5-evb-u-boot.dtsi +0 -1
index f5406d4c7e..002767a033 100644
@@ -5,7 +5,6 @@
 / {
 	chosen {
 		u-boot,spl-boot-order = &emmc;
-		tick-timer = "/timer at ff810000";
 	};
 };
 
configs/evb-px5_defconfig +0 -4
index 9afba9b873..a2b72c765d 100644
@@ -67,10 +67,6 @@ CONFIG_DM_RESET=y
 CONFIG_DEBUG_UART_SHIFT=2
 CONFIG_DEBUG_UART_SKIP_INIT=y
 CONFIG_SYSRESET=y
-CONFIG_TIMER=y
-CONFIG_SPL_TIMER=y
-CONFIG_TPL_TIMER=y
-CONFIG_ROCKCHIP_TIMER=y
 CONFIG_USE_TINY_PRINTF=y
 CONFIG_PANIC_HANG=y
 CONFIG_SPL_TINY_MEMSET=y
Signature · 1 line
2.17.1