2 * Marvell PXA2xx/3xx timer driver
4 * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com>
6 * SPDX-License-Identifier: GPL-2.0+
9 #include <asm/arch/pxa-regs.h>
14 DECLARE_GLOBAL_DATA_PTR;
16 #define TIMER_LOAD_VAL 0xffffffff
18 #define timestamp (gd->arch.tbl)
19 #define lastinc (gd->arch.lastinc)
21 #if defined(CONFIG_CPU_PXA27X) || defined(CONFIG_CPU_MONAHANS)
22 #define TIMER_FREQ_HZ 3250000
23 #elif defined(CONFIG_CPU_PXA25X)
24 #define TIMER_FREQ_HZ 3686400
26 #error "Timer frequency unknown - please config PXA CPU type"
29 static unsigned long long tick_to_time(unsigned long long tick)
31 return tick * CONFIG_SYS_HZ / TIMER_FREQ_HZ;
34 static unsigned long long us_to_tick(unsigned long long us)
36 return (us * TIMER_FREQ_HZ) / 1000000;
45 unsigned long long get_ticks(void)
47 /* Current tick value */
48 uint32_t now = readl(OSCR);
52 * Normal mode (non roll)
53 * Move stamp forward with absolute diff ticks
55 timestamp += (now - lastinc);
57 /* We have rollover of incrementer */
58 timestamp += (TIMER_LOAD_VAL - lastinc) + now;
65 ulong get_timer(ulong base)
67 return tick_to_time(get_ticks()) - base;
70 void __udelay(unsigned long usec)
72 unsigned long long tmp;
75 tmo = us_to_tick(usec);
76 tmp = get_ticks() + tmo; /* get current timestamp */
78 while (get_ticks() < tmp) /* loop till event */