]> git.ipfire.org Git - people/ms/u-boot.git/blame - arch/arm/cpu/pxa/timer.c
Add GPL-2.0+ SPDX-License-Identifier to source files
[people/ms/u-boot.git] / arch / arm / cpu / pxa / timer.c
CommitLineData
32fe2871 1/*
d1bb9443 2 * Marvell PXA2xx/3xx timer driver
32fe2871 3 *
d1bb9443 4 * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com>
32fe2871 5 *
1a459660 6 * SPDX-License-Identifier: GPL-2.0+
32fe2871
WD
7 */
8
32fe2871 9#include <asm/arch/pxa-regs.h>
3ba8bf7c
MV
10#include <asm/io.h>
11#include <common.h>
a922fdb8 12#include <div64.h>
32fe2871 13
d1bb9443
MV
14DECLARE_GLOBAL_DATA_PTR;
15
16#define TIMER_LOAD_VAL 0xffffffff
17
66ee6923 18#define timestamp (gd->arch.tbl)
582601da 19#define lastinc (gd->arch.lastinc)
32fe2871 20
abc20aba 21#if defined(CONFIG_CPU_PXA27X) || defined(CONFIG_CPU_MONAHANS)
d1bb9443 22#define TIMER_FREQ_HZ 3250000
abc20aba 23#elif defined(CONFIG_CPU_PXA25X)
d1bb9443 24#define TIMER_FREQ_HZ 3686400
94a33129
MK
25#else
26#error "Timer frequency unknown - please config PXA CPU type"
27#endif
28
d1bb9443 29static unsigned long long tick_to_time(unsigned long long tick)
a922fdb8 30{
d1bb9443 31 return tick * CONFIG_SYS_HZ / TIMER_FREQ_HZ;
a922fdb8
JCPV
32}
33
d1bb9443 34static unsigned long long us_to_tick(unsigned long long us)
a922fdb8 35{
d1bb9443 36 return (us * TIMER_FREQ_HZ) / 1000000;
a922fdb8
JCPV
37}
38
d1bb9443 39int timer_init(void)
32fe2871 40{
17659d7d 41 writel(0, OSCR);
b54384e3 42 return 0;
32fe2871
WD
43}
44
d1bb9443 45unsigned long long get_ticks(void)
32fe2871 46{
d1bb9443
MV
47 /* Current tick value */
48 uint32_t now = readl(OSCR);
49
50 if (now >= lastinc) {
51 /*
52 * Normal mode (non roll)
53 * Move stamp forward with absolute diff ticks
54 */
55 timestamp += (now - lastinc);
56 } else {
57 /* We have rollover of incrementer */
58 timestamp += (TIMER_LOAD_VAL - lastinc) + now;
59 }
60
61 lastinc = now;
62 return timestamp;
32fe2871
WD
63}
64
d1bb9443 65ulong get_timer(ulong base)
32fe2871 66{
d1bb9443 67 return tick_to_time(get_ticks()) - base;
32fe2871
WD
68}
69
d1bb9443 70void __udelay(unsigned long usec)
32fe2871 71{
a922fdb8 72 unsigned long long tmp;
32fe2871 73 ulong tmo;
a922fdb8
JCPV
74
75 tmo = us_to_tick(usec);
76 tmp = get_ticks() + tmo; /* get current timestamp */
77
78 while (get_ticks() < tmp) /* loop till event */
79 /*NOP*/;
fc3e2165 80}
30a14ea2
MV
81
82ulong get_tbclk(void)
83{
84 return TIMER_FREQ_HZ;
85}