]>
Commit | Line | Data |
---|---|---|
3a574cbe WD |
1 | /* |
2 | * (C) Copyright 2004-2005, Greg Ungerer <greg.ungerer@opengear.com> | |
3 | * | |
1a459660 | 4 | * SPDX-License-Identifier: GPL-2.0+ |
3a574cbe WD |
5 | */ |
6 | ||
7 | #include <common.h> | |
8 | #include <asm/arch/platform.h> | |
9 | ||
3a52cfa5 GU |
10 | /* |
11 | * Initial timer set constants. Nothing complicated, just set for a 1ms | |
12 | * tick. | |
13 | */ | |
14 | #define TIMER_INTERVAL (TICKS_PER_uSEC * mSEC_1) | |
15 | #define TIMER_COUNT (TIMER_INTERVAL / 2) | |
16 | #define TIMER_PULSE TIMER_COUNT | |
17 | ||
3a574cbe WD |
18 | /* |
19 | * Handy KS8695 register access functions. | |
20 | */ | |
21 | #define ks8695_read(a) *((volatile ulong *) (KS8695_IO_BASE + (a))) | |
22 | #define ks8695_write(a,v) *((volatile ulong *) (KS8695_IO_BASE + (a))) = (v) | |
23 | ||
3a574cbe WD |
24 | ulong timer_ticks; |
25 | ||
b54384e3 | 26 | int timer_init (void) |
3a574cbe | 27 | { |
17659d7d GR |
28 | /* Set the hadware timer for 1ms */ |
29 | ks8695_write(KS8695_TIMER1, TIMER_COUNT); | |
30 | ks8695_write(KS8695_TIMER1_PCOUNT, TIMER_PULSE); | |
31 | ks8695_write(KS8695_TIMER_CTRL, 0x2); | |
32 | timer_ticks = 0; | |
b54384e3 JCPV |
33 | |
34 | return 0; | |
3a574cbe WD |
35 | } |
36 | ||
3a574cbe WD |
37 | ulong get_timer_masked(void) |
38 | { | |
39 | /* Check for timer wrap */ | |
40 | if (ks8695_read(KS8695_INT_STATUS) & KS8695_INTMASK_TIMERINT1) { | |
41 | /* Clear interrupt condition */ | |
42 | ks8695_write(KS8695_INT_STATUS, KS8695_INTMASK_TIMERINT1); | |
43 | timer_ticks++; | |
44 | } | |
45 | return timer_ticks; | |
46 | } | |
47 | ||
48 | ulong get_timer(ulong base) | |
49 | { | |
50 | return (get_timer_masked() - base); | |
51 | } | |
52 | ||
3eb90bad | 53 | void __udelay(ulong usec) |
3a574cbe WD |
54 | { |
55 | ulong start = get_timer_masked(); | |
56 | ulong end; | |
57 | ||
3a574cbe WD |
58 | /* Only 1ms resolution :-( */ |
59 | end = usec / 1000; | |
60 | while (get_timer(start) < end) | |
61 | ; | |
62 | } | |
63 | ||
64 | void reset_cpu (ulong ignored) | |
65 | { | |
66 | ulong tc; | |
67 | ||
68 | /* Set timer0 to watchdog, and let it timeout */ | |
69 | tc = ks8695_read(KS8695_TIMER_CTRL) & 0x2; | |
70 | ks8695_write(KS8695_TIMER_CTRL, tc); | |
71 | ks8695_write(KS8695_TIMER0, ((10 << 8) | 0xff)); | |
72 | ks8695_write(KS8695_TIMER_CTRL, (tc | 0x1)); | |
73 | ||
74 | /* Should only wait here till watchdog resets */ | |
75 | for (;;) | |
76 | ; | |
77 | } |