3 * 2N Telekomunikace, <www.2n.cz>
6 * Texas Instruments, <www.ti.com>
9 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
10 * Marius Groeger <mgroeger@sysgo.de>
13 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
14 * Alex Zuepke <azu@sysgo.de>
17 * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de>
19 * SPDX-License-Identifier: GPL-2.0+
24 #include <configs/omap1510.h>
27 #define TIMER_LOAD_VAL 0xffffffff
28 #define TIMER_CLOCK (CONFIG_SYS_CLK_FREQ / (2 << CONFIG_SYS_PTV))
30 static uint32_t timestamp;
31 static uint32_t lastdec;
33 /* nothing really to do with interrupts, just starts up a counter. */
36 /* Start the decrementer ticking down from 0xffffffff */
37 __raw_writel(TIMER_LOAD_VAL, CONFIG_SYS_TIMERBASE + LOAD_TIM);
38 __raw_writel(MPUTIM_ST | MPUTIM_AR | MPUTIM_CLOCK_ENABLE |
39 (CONFIG_SYS_PTV << MPUTIM_PTV_BIT),
40 CONFIG_SYS_TIMERBASE + CNTL_TIMER);
42 /* init the timestamp and lastdec value */
43 lastdec = __raw_readl(CONFIG_SYS_TIMERBASE + READ_TIM) /
44 (TIMER_CLOCK / CONFIG_SYS_HZ);
45 timestamp = 0; /* start "advancing" time stamp from 0 */
51 * timer without interrupts
53 ulong get_timer (ulong base)
55 return get_timer_masked () - base;
58 /* delay x useconds AND preserve advance timestamp value */
59 void __udelay (unsigned long usec)
61 int32_t tmo = usec * (TIMER_CLOCK / 1000) / 1000;
62 uint32_t now, last = __raw_readl(CONFIG_SYS_TIMERBASE + READ_TIM);
65 now = __raw_readl(CONFIG_SYS_TIMERBASE + READ_TIM);
66 if (last < now) /* count down timer underflow */
67 tmo -= TIMER_LOAD_VAL - now + last;
74 ulong get_timer_masked (void)
76 uint32_t now = __raw_readl(CONFIG_SYS_TIMERBASE + READ_TIM) /
77 (TIMER_CLOCK / CONFIG_SYS_HZ);
78 if (lastdec < now) /* count down timer underflow */
79 timestamp += TIMER_LOAD_VAL / (TIMER_CLOCK / CONFIG_SYS_HZ) -
82 timestamp += lastdec - now;
89 * This function is derived from PowerPC code (read timebase as long long).
90 * On ARM it just returns the timer value.
92 unsigned long long get_ticks(void)
98 * This function is derived from PowerPC code (timebase clock frequency).
99 * On ARM it returns the number of timer ticks per second.
101 ulong get_tbclk (void)
103 return CONFIG_SYS_HZ;