]>
git.ipfire.org Git - people/ms/u-boot.git/blob - arch/arm/cpu/armv7/mx5/timer.c
3 * Sascha Hauer, Pengutronix
5 * (C) Copyright 2009 Freescale Semiconductor, Inc.
7 * See file CREDITS for list of people who contributed to this
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 #include <asm/arch/imx-regs.h>
30 /* General purpose timers registers */
33 unsigned int prescaler
;
35 unsigned int nouse
[6];
39 static struct mxc_gpt
*cur_gpt
= (struct mxc_gpt
*)GPT1_BASE_ADDR
;
41 /* General purpose timers bitfields */
42 #define GPTCR_SWR (1<<15) /* Software reset */
43 #define GPTCR_FRR (1<<9) /* Freerun / restart */
44 #define GPTCR_CLKSOURCE_32 (4<<6) /* Clock source */
45 #define GPTCR_TEN (1) /* Timer enable */
47 static ulong timestamp
;
54 /* setup GP Timer 1 */
55 __raw_writel(GPTCR_SWR
, &cur_gpt
->control
);
57 /* We have no udelay by now */
58 for (i
= 0; i
< 100; i
++)
59 __raw_writel(0, &cur_gpt
->control
);
61 __raw_writel(0, &cur_gpt
->prescaler
); /* 32Khz */
63 /* Freerun Mode, PERCLK1 input */
64 i
= __raw_readl(&cur_gpt
->control
);
65 __raw_writel(i
| GPTCR_CLKSOURCE_32
| GPTCR_TEN
, &cur_gpt
->control
);
70 void reset_timer(void)
75 void reset_timer_masked(void)
77 ulong val
= __raw_readl(&cur_gpt
->counter
);
78 lastinc
= val
/ (CONFIG_SYS_MX5_CLK32
/ CONFIG_SYS_HZ
);
82 ulong
get_timer_masked(void)
84 ulong val
= __raw_readl(&cur_gpt
->counter
);
85 val
/= (CONFIG_SYS_MX5_CLK32
/ CONFIG_SYS_HZ
);
87 timestamp
+= (val
- lastinc
);
89 timestamp
+= ((0xFFFFFFFF / (CONFIG_SYS_MX5_CLK32
/ CONFIG_SYS_HZ
))
95 ulong
get_timer(ulong base
)
97 return get_timer_masked() - base
;
100 void set_timer(ulong t
)
105 /* delay x useconds AND preserve advance timestamp value */
106 void __udelay(unsigned long usec
)
108 unsigned long now
, start
, tmo
;
109 tmo
= usec
* (CONFIG_SYS_MX5_CLK32
/ 1000) / 1000;
114 now
= start
= readl(&cur_gpt
->counter
);
116 while ((now
- start
) < tmo
)
117 now
= readl(&cur_gpt
->counter
);