2 * (C) Copyright 2004-2005, Greg Ungerer <greg.ungerer@opengear.com>
4 * See file CREDITS for list of people who contributed to this
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 #include <asm/arch/platform.h>
27 * Handy KS8695 register access functions.
29 #define ks8695_read(a) *((volatile ulong *) (KS8695_IO_BASE + (a)))
30 #define ks8695_write(a,v) *((volatile ulong *) (KS8695_IO_BASE + (a))) = (v)
42 * Initial timer set constants. Nothing complicated, just set for a 1ms
45 #define TIMER_INTERVAL (TICKS_PER_uSEC * mSEC_1)
46 #define TIMER_COUNT (TIMER_INTERVAL / 2)
47 #define TIMER_PULSE TIMER_COUNT
49 void reset_timer_masked(void)
51 /* Set the hadware timer for 1ms */
52 ks8695_write(KS8695_TIMER1, TIMER_COUNT);
53 ks8695_write(KS8695_TIMER1_PCOUNT, TIMER_PULSE);
54 ks8695_write(KS8695_TIMER_CTRL, 0x2);
58 void reset_timer(void)
63 ulong get_timer_masked(void)
65 /* Check for timer wrap */
66 if (ks8695_read(KS8695_INT_STATUS) & KS8695_INTMASK_TIMERINT1) {
67 /* Clear interrupt condition */
68 ks8695_write(KS8695_INT_STATUS, KS8695_INTMASK_TIMERINT1);
74 ulong get_timer(ulong base)
76 return (get_timer_masked() - base);
79 void set_timer(ulong t)
84 void __udelay(ulong usec)
86 ulong start = get_timer_masked();
89 /* Only 1ms resolution :-( */
91 while (get_timer(start) < end)
95 void reset_cpu (ulong ignored)
99 /* Set timer0 to watchdog, and let it timeout */
100 tc = ks8695_read(KS8695_TIMER_CTRL) & 0x2;
101 ks8695_write(KS8695_TIMER_CTRL, tc);
102 ks8695_write(KS8695_TIMER0, ((10 << 8) | 0xff));
103 ks8695_write(KS8695_TIMER_CTRL, (tc | 0x1));
105 /* Should only wait here till watchdog resets */