Convert altera timer to driver model.
Signed-off-by: Thomas Chou
Acked-by: Chin Liang See
---
v2
fix coding style.
v3
doc dts binding.
v4
no change.
v5
revert to get_rate and use uclass priv to store the clock_rate.
v6
rename to CONFIG_TIMER as Simon suggested.
v7
fix string replacement error in v6.
v8
replace all dm_timer with timer.
arch/nios2/cpu/Makefile | 2 +-
arch/nios2/cpu/timer.c | 65 ---
common/board_f.c| 3 +-
configs/nios2-generic_defconfig | 2 +
doc/device-tree-bindings/timer/altera_timer.txt | 19 +
drivers/timer/Kconfig | 7 ++
drivers/timer/Makefile | 1 +
drivers/timer/altera_timer.c| 103
include/configs/nios2-generic.h | 5 --
9 files changed, 134 insertions(+), 73 deletions(-)
delete mode 100644 arch/nios2/cpu/timer.c
create mode 100644 doc/device-tree-bindings/timer/altera_timer.txt
create mode 100644 drivers/timer/altera_timer.c
diff --git a/arch/nios2/cpu/Makefile b/arch/nios2/cpu/Makefile
index c85e261..3fe7847 100644
--- a/arch/nios2/cpu/Makefile
+++ b/arch/nios2/cpu/Makefile
@@ -7,5 +7,5 @@
extra-y= start.o
obj-y = exceptions.o
-obj-y += cpu.o interrupts.o sysid.o timer.o traps.o
+obj-y += cpu.o interrupts.o sysid.o traps.o
obj-y += fdt.o
diff --git a/arch/nios2/cpu/timer.c b/arch/nios2/cpu/timer.c
deleted file mode 100644
index b8aa9dd..000
--- a/arch/nios2/cpu/timer.c
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * (C) Copyright 2000-2002
- * Wolfgang Denk, DENX Software Engineering, w...@denx.de.
- *
- * (C) Copyright 2004, Psyent Corporation
- * Scott McNutt
- *
- * SPDX-License-Identifier:GPL-2.0+
- */
-
-#include
-#include
-#include
-#include
-
-struct nios_timer {
- u32 status; /* Timer status reg */
- u32 control;/* Timer control reg */
- u32 periodl;/* Timeout period low */
- u32 periodh;/* Timeout period high */
- u32 snapl; /* Snapshot low */
- u32 snaph; /* Snapshot high */
-};
-
-/* status register */
-#define NIOS_TIMER_TO (1 << 0)/* Timeout */
-#define NIOS_TIMER_RUN (1 << 1)/* Timer running */
-
-/* control register */
-#define NIOS_TIMER_ITO (1 << 0)/* Timeout interrupt enable */
-#define NIOS_TIMER_CONT(1 << 1)/* Continuous mode */
-#define NIOS_TIMER_START (1 << 2)/* Start timer */
-#define NIOS_TIMER_STOP(1 << 3)/* Stop timer */
-
-/*/
-unsigned long notrace timer_read_counter(void)
-{
- struct nios_timer *tmr = (struct nios_timer *)CONFIG_SYS_TIMER_BASE;
- u32 val;
-
- /* Trigger update */
- writel(0x0, &tmr->snapl);
-
- /* Read timer value */
- val = readl(&tmr->snapl) & 0x;
- val |= (readl(&tmr->snaph) & 0x) << 16;
-
- return ~val;
-}
-
-int timer_init(void)
-{
- struct nios_timer *tmr = (struct nios_timer *)CONFIG_SYS_TIMER_BASE;
-
- writel(0, &tmr->status);
- writel(0, &tmr->control);
- writel(NIOS_TIMER_STOP, &tmr->control);
-
- writel(0x, &tmr->periodl);
- writel(0x, &tmr->periodh);
-
- writel(NIOS_TIMER_CONT | NIOS_TIMER_START, &tmr->control);
-
- return 0;
-}
diff --git a/common/board_f.c b/common/board_f.c
index 8bb8ded..613332e 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -795,8 +795,7 @@ static init_fnc_t init_sequence_f[] = {
init_timebase,
#endif
#if defined(CONFIG_ARM) || defined(CONFIG_MIPS) || \
- defined(CONFIG_BLACKFIN) || defined(CONFIG_NDS32) || \
- defined(CONFIG_NIOS2)
+ defined(CONFIG_BLACKFIN) || defined(CONFIG_NDS32)
timer_init, /* initialize timer */
#endif
#ifdef CONFIG_SYS_ALLOC_DPRAM
diff --git a/configs/nios2-generic_defconfig b/configs/nios2-generic_defconfig
index 707ee33..505a2cf 100644
--- a/configs/nios2-generic_defconfig
+++ b/configs/nios2-generic_defconfig
@@ -18,3 +18,5 @@ CONFIG_NET_RANDOM_ETHADDR=y
CONFIG_ALTERA_PIO=y
CONFIG_ALTERA_JTAG_UART=y
CONFIG_ALTERA_JTAG_UART_BYPASS=y
+CONFIG_TIMER=y
+CONFIG_ALTERA_TIMER=y
diff --git a/doc/device-tree-bindings/timer/altera_timer.txt
b/doc/device-tree-bindings/timer/altera_timer.txt
new file mode 100644
index 000..904a584
--- /dev/null
+++ b/doc/device-tree-bindings/timer/altera_timer.txt
@@ -0,0 +1,19 @@
+Altera Timer
+
+Required properties:
+
+- compatible : should be "altr,timer-1.0"
+- reg : Specifies base physical address and size of the registers.
+- interrupt-parent: phandle of the interrupt controller
+- interrupts : Should contain the timer interrupt number
+- clock-frequency : The frequency of the clo