3 * Michael Schwingen, michael@schwingen.org
6 * Stefan Roese, DENX Software Engineering, sr@denx.de.
9 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
10 * Marius Groeger <mgroeger@sysgo.de>
13 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
14 * Alex Zuepke <azu@sysgo.de>
16 * See file CREDITS for list of people who contributed to this
19 * This program is free software; you can redistribute it and/or
20 * modify it under the terms of the GNU General Public License as
21 * published by the Free Software Foundation; either version 2 of
22 * the License, or (at your option) any later version.
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
36 #include <asm/arch/ixp425.h>
40 DECLARE_GLOBAL_DATA_PTR
;
43 * The IXP42x time-stamp timer runs at 2*OSC_IN (66.666MHz when using a
46 static inline unsigned long long tick_to_time(unsigned long long tick
)
48 tick
*= CONFIG_SYS_HZ
;
49 do_div(tick
, CONFIG_IXP425_TIMER_CLK
);
53 static inline unsigned long long time_to_tick(unsigned long long time
)
55 time
*= CONFIG_IXP425_TIMER_CLK
;
56 do_div(time
, CONFIG_SYS_HZ
);
60 static inline unsigned long long us_to_tick(unsigned long long us
)
62 us
= us
* CONFIG_IXP425_TIMER_CLK
+ 999999;
67 unsigned long long get_ticks(void)
69 ulong now
= readl(IXP425_OSTS_B
);
71 if (readl(IXP425_OSST
) & IXP425_OSST_TIMER_TS_PEND
) {
72 /* rollover of timestamp timer register */
73 gd
->timestamp
+= (0xFFFFFFFF - gd
->lastinc
) + now
+ 1;
74 writel(IXP425_OSST_TIMER_TS_PEND
, IXP425_OSST
);
76 /* move stamp forward with absolut diff ticks */
77 gd
->timestamp
+= (now
- gd
->lastinc
);
84 void reset_timer_masked(void)
86 /* capture current timestamp counter */
87 gd
->lastinc
= readl(IXP425_OSTS_B
);
88 /* start "advancing" time stamp from 0 */
92 ulong
get_timer_masked(void)
94 return tick_to_time(get_ticks());
97 ulong
get_timer(ulong base
)
99 return get_timer_masked() - base
;
102 /* delay x useconds AND preserve advance timestamp value */
103 void __udelay(unsigned long usec
)
105 unsigned long long tmp
;
107 tmp
= get_ticks() + us_to_tick(usec
);
109 while (get_ticks() < tmp
)
115 writel(IXP425_OSST_TIMER_TS_PEND
, IXP425_OSST
);