]>
git.ipfire.org Git - people/ms/u-boot.git/blob - arch/arm/cpu/arm920t/a320/timer.c
2 * (C) Copyright 2009 Faraday Technology
3 * Po-Yu Chuang <ratbert@faraday-tech.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <faraday/ftpmu010.h>
23 #include <faraday/fttmr010.h>
25 static ulong timestamp
;
28 static struct fttmr010
*tmr
= (struct fttmr010
*)CONFIG_FTTMR010_BASE
;
30 #define TIMER_CLOCK 32768
31 #define TIMER_LOAD_VAL 0xffffffff
37 debug("%s()\n", __func__
);
42 /* use 32768Hz oscillator for RTC, WDT, TIMER */
43 ftpmu010_32768osc_enable();
46 writel(TIMER_LOAD_VAL
, &tmr
->timer3_load
);
47 writel(TIMER_LOAD_VAL
, &tmr
->timer3_counter
);
48 writel(0, &tmr
->timer3_match1
);
49 writel(0, &tmr
->timer3_match2
);
51 /* we don't want timer to issue interrupts */
52 writel(FTTMR010_TM3_MATCH1
|
54 FTTMR010_TM3_OVERFLOW
,
55 &tmr
->interrupt_mask
);
58 cr
|= FTTMR010_TM3_CLOCK
; /* use external clock */
59 cr
|= FTTMR010_TM3_ENABLE
;
62 /* init the timestamp and lastdec value */
69 * timer without interrupts
75 void reset_timer_masked(void)
77 /* capure current decrementer value time */
78 lastdec
= readl(&tmr
->timer3_counter
) / (TIMER_CLOCK
/ CONFIG_SYS_HZ
);
79 timestamp
= 0; /* start "advancing" time stamp from 0 */
81 debug("%s(): lastdec = %lx\n", __func__
, lastdec
);
84 void reset_timer(void)
86 debug("%s()\n", __func__
);
93 ulong
get_timer_masked(void)
95 /* current tick value */
96 ulong now
= readl(&tmr
->timer3_counter
) / (TIMER_CLOCK
/ CONFIG_SYS_HZ
);
98 debug("%s(): now = %lx, lastdec = %lx\n", __func__
, now
, lastdec
);
100 if (lastdec
>= now
) {
102 * normal mode (non roll)
103 * move stamp fordward with absoulte diff ticks
105 timestamp
+= lastdec
- now
;
108 * we have overflow of the count down timer
110 * nts = ts + ld + (TLV - now)
111 * ts=old stamp, ld=time that passed before passing through -1
112 * (TLV-now) amount of time after passing though -1
113 * nts = new "advancing time stamp"...it could also roll and
116 timestamp
+= lastdec
+ TIMER_LOAD_VAL
- now
;
121 debug("%s() returns %lx\n", __func__
, timestamp
);
127 * return difference between timer ticks and base
129 ulong
get_timer(ulong base
)
131 debug("%s(%lx)\n", __func__
, base
);
132 return get_timer_masked() - base
;
135 /* delay x useconds AND preserve advance timestamp value */
136 void __udelay(unsigned long usec
)
138 long tmo
= usec
* (TIMER_CLOCK
/ 1000) / 1000;
139 unsigned long now
, last
= readl(&tmr
->timer3_counter
);
141 debug("%s(%lu)\n", __func__
, usec
);
143 now
= readl(&tmr
->timer3_counter
);
144 if (now
> last
) /* count down timer overflow */
145 tmo
-= TIMER_LOAD_VAL
+ last
- now
;
153 * This function is derived from PowerPC code (read timebase as long long).
154 * On ARM it just returns the timer value.
156 unsigned long long get_ticks(void)
158 debug("%s()\n", __func__
);
163 * This function is derived from PowerPC code (timebase clock frequency).
164 * On ARM it returns the number of timer ticks per second.
166 ulong
get_tbclk(void)
168 debug("%s()\n", __func__
);
169 return CONFIG_SYS_HZ
;