]>
git.ipfire.org Git - people/ms/u-boot.git/blob - arch/arm/cpu/ixp/timer.c
3 * Stefan Roese, DENX Software Engineering, sr@denx.de.
6 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
7 * Marius Groeger <mgroeger@sysgo.de>
10 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
11 * Alex Zuepke <azu@sysgo.de>
13 * See file CREDITS for list of people who contributed to this
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License as
18 * published by the Free Software Foundation; either version 2 of
19 * the License, or (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
33 #include <asm/arch/ixp425.h>
35 #ifdef CONFIG_TIMER_IRQ
38 #define CLOCK_TICK_RATE (((FREQ / CONFIG_SYS_HZ & ~IXP425_OST_RELOAD_MASK) + 1) * CONFIG_SYS_HZ)
39 #define LATCH ((CLOCK_TICK_RATE + CONFIG_SYS_HZ/2) / CONFIG_SYS_HZ) /* For divider */
42 * When interrupts are enabled, use timer 2 for time/delay generation...
45 static volatile ulong timestamp
;
47 static void timer_isr(void *data
)
49 unsigned int *pTime
= (unsigned int *)data
;
56 *IXP425_OSST
= IXP425_OSST_TIMER_2_PEND
;
59 ulong
get_timer (ulong base
)
61 return timestamp
- base
;
64 void reset_timer (void)
71 /* install interrupt handler for timer */
72 irq_install_handler(IXP425_TIMER_2_IRQ
, timer_isr
, (void *)×tamp
);
74 /* setup the Timer counter value */
75 *IXP425_OSRT2
= (LATCH
& ~IXP425_OST_RELOAD_MASK
) | IXP425_OST_ENABLE
;
77 /* enable timer irq */
78 *IXP425_ICMR
= (1 << IXP425_TIMER_2_IRQ
);
83 ulong
get_timer (ulong base
)
85 return get_timer_masked () - base
;
88 void ixp425_udelay(unsigned long usec
)
91 * This function has a max usec, but since it is called from udelay
92 * we should not have to worry... be happy
94 unsigned long usecs
= CONFIG_SYS_HZ
/1000000L & ~IXP425_OST_RELOAD_MASK
;
96 *IXP425_OSST
= IXP425_OSST_TIMER_1_PEND
;
97 usecs
|= IXP425_OST_ONE_SHOT
| IXP425_OST_ENABLE
;
98 *IXP425_OSRT1
= usecs
;
99 while (!(*IXP425_OSST
& IXP425_OSST_TIMER_1_PEND
));
102 void __udelay (unsigned long usec
)
104 while (usec
--) ixp425_udelay(1);
107 static ulong reload_constant
= 0xfffffff0;
109 void reset_timer_masked (void)
111 ulong reload
= reload_constant
| IXP425_OST_ONE_SHOT
| IXP425_OST_ENABLE
;
113 *IXP425_OSST
= IXP425_OSST_TIMER_1_PEND
;
114 *IXP425_OSRT1
= reload
;
117 ulong
get_timer_masked (void)
120 * Note that it is possible for this to wrap!
121 * In this case we return max.
123 ulong current
= *IXP425_OST1
;
124 if (*IXP425_OSST
& IXP425_OSST_TIMER_1_PEND
)
126 return reload_constant
;
128 return (reload_constant
- current
);