blob: 0ad64dd9439517887ba53dd89fbee7edc64eb66a [file] [log] [blame]
wdenk32fe2872002-10-11 07:57:01 +00001/*
2 * (C) Copyright 2002
3 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
4 * Marius Groeger <mgroeger@sysgo.de>
5 *
6 * (C) Copyright 2002
7 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
8 * Alex Zuepke <azu@sysgo.de>
9 *
10 * See file CREDITS for list of people who contributed to this
11 * project.
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation; either version 2 of
16 * the License, or (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 * MA 02111-1307 USA
27 */
28
wdenk32fe2872002-10-11 07:57:01 +000029#include <asm/arch/pxa-regs.h>
Marek Vasut2db1e962010-09-09 09:50:39 +020030#include <asm/io.h>
31#include <common.h>
Jean-Christophe PLAGNIOL-VILLARDe90368d2009-02-24 06:13:10 +010032#include <div64.h>
wdenk32fe2872002-10-11 07:57:01 +000033
wdenk32fe2872002-10-11 07:57:01 +000034#ifdef CONFIG_USE_IRQ
wdenk32fe2872002-10-11 07:57:01 +000035#error: interrupts not implemented yet
wdenk32fe2872002-10-11 07:57:01 +000036#endif
37
Marek Vasut85cc88a2011-11-26 07:20:07 +010038#if defined(CONFIG_CPU_PXA27X) || defined(CONFIG_CPU_MONAHANS)
Micha Kalfon8a75a5b2009-02-11 19:50:11 +020039#define TIMER_FREQ_HZ 3250000
Marek Vasut85cc88a2011-11-26 07:20:07 +010040#elif defined(CONFIG_CPU_PXA25X)
Micha Kalfon8a75a5b2009-02-11 19:50:11 +020041#define TIMER_FREQ_HZ 3686400
42#else
43#error "Timer frequency unknown - please config PXA CPU type"
44#endif
45
Jean-Christophe PLAGNIOL-VILLARDe90368d2009-02-24 06:13:10 +010046static inline unsigned long long tick_to_time(unsigned long long tick)
47{
48 tick *= CONFIG_SYS_HZ;
49 do_div(tick, TIMER_FREQ_HZ);
50 return tick;
51}
52
53static inline unsigned long long us_to_tick(unsigned long long us)
54{
55 us = us * TIMER_FREQ_HZ + 999999;
56 do_div(us, 1000000);
57 return us;
58}
59
Jean-Christophe PLAGNIOL-VILLARD8c9fc002009-05-15 23:47:02 +020060int timer_init (void)
wdenk32fe2872002-10-11 07:57:01 +000061{
Graeme Russ944a7fe2011-07-15 02:21:14 +000062 writel(0, OSCR);
Jean-Christophe PLAGNIOL-VILLARD8c9fc002009-05-15 23:47:02 +020063
64 return 0;
wdenk32fe2872002-10-11 07:57:01 +000065}
66
wdenk32fe2872002-10-11 07:57:01 +000067ulong get_timer (ulong base)
68{
wdenk3c711762004-06-09 13:37:52 +000069 return get_timer_masked () - base;
wdenk32fe2872002-10-11 07:57:01 +000070}
71
Ingo van Lilf0f778a2009-11-24 14:09:21 +010072void __udelay (unsigned long usec)
wdenk32fe2872002-10-11 07:57:01 +000073{
74 udelay_masked (usec);
75}
76
wdenk32fe2872002-10-11 07:57:01 +000077ulong get_timer_masked (void)
78{
Jean-Christophe PLAGNIOL-VILLARDe90368d2009-02-24 06:13:10 +010079 return tick_to_time(get_ticks());
wdenk32fe2872002-10-11 07:57:01 +000080}
81
82void udelay_masked (unsigned long usec)
83{
Jean-Christophe PLAGNIOL-VILLARDe90368d2009-02-24 06:13:10 +010084 unsigned long long tmp;
wdenk32fe2872002-10-11 07:57:01 +000085 ulong tmo;
86
Jean-Christophe PLAGNIOL-VILLARDe90368d2009-02-24 06:13:10 +010087 tmo = us_to_tick(usec);
88 tmp = get_ticks() + tmo; /* get current timestamp */
wdenk32fe2872002-10-11 07:57:01 +000089
Jean-Christophe PLAGNIOL-VILLARDe90368d2009-02-24 06:13:10 +010090 while (get_ticks() < tmp) /* loop till event */
91 /*NOP*/;
wdenk32fe2872002-10-11 07:57:01 +000092
wdenk32fe2872002-10-11 07:57:01 +000093}
wdenk49c3f672003-10-08 22:33:00 +000094
95/*
96 * This function is derived from PowerPC code (read timebase as long long).
97 * On ARM it just returns the timer value.
98 */
99unsigned long long get_ticks(void)
100{
Marek Vasut2db1e962010-09-09 09:50:39 +0200101 return readl(OSCR);
wdenk49c3f672003-10-08 22:33:00 +0000102}
103
104/*
105 * This function is derived from PowerPC code (timebase clock frequency).
106 * On ARM it returns the number of timer ticks per second.
107 */
108ulong get_tbclk (void)
109{
110 ulong tbclk;
Micha Kalfon8a75a5b2009-02-11 19:50:11 +0200111 tbclk = TIMER_FREQ_HZ;
wdenk49c3f672003-10-08 22:33:00 +0000112 return tbclk;
113}