Simon Glass | bac075b | 2024-08-22 07:54:50 -0600 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * (C) Copyright 2019 Rockchip Electronics Co., Ltd |
| 4 | */ |
| 5 | |
| 6 | #include <asm/io.h> |
| 7 | #include <linux/bitops.h> |
| 8 | |
| 9 | #define TIMER_LOAD_COUNT_L 0x00 |
| 10 | #define TIMER_LOAD_COUNT_H 0x04 |
| 11 | #define TIMER_CONTROL_REG 0x10 |
| 12 | #define TIMER_EN 0x1 |
| 13 | #define TIMER_FMODE BIT(0) |
| 14 | #define TIMER_RMODE BIT(1) |
| 15 | |
| 16 | __weak void rockchip_stimer_init(void) |
| 17 | { |
| 18 | #if defined(CONFIG_ROCKCHIP_STIMER_BASE) |
| 19 | /* If Timer already enabled, don't re-init it */ |
| 20 | u32 reg = readl(CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG); |
| 21 | |
| 22 | if (reg & TIMER_EN) |
| 23 | return; |
| 24 | |
| 25 | #ifndef CONFIG_ARM64 |
| 26 | asm volatile("mcr p15, 0, %0, c14, c0, 0" |
| 27 | : : "r"(CONFIG_COUNTER_FREQUENCY)); |
| 28 | #endif |
| 29 | |
| 30 | writel(0, CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG); |
| 31 | writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE); |
| 32 | writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE + 4); |
| 33 | writel(TIMER_EN | TIMER_FMODE, CONFIG_ROCKCHIP_STIMER_BASE + |
| 34 | TIMER_CONTROL_REG); |
| 35 | #endif |
| 36 | } |