blob: b62558f92f47ae7b6a87c43955cd5c027379de15 [file] [log] [blame]
wdenk281e00a2004-08-01 22:48:16 +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 * (C) Copyright 2002
Detlev Zundel792a09e2009-05-13 10:54:10 +020011 * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de>
wdenk281e00a2004-08-01 22:48:16 +000012 *
Wolfgang Denk1a459662013-07-08 09:37:19 +020013 * SPDX-License-Identifier: GPL-2.0+
wdenk281e00a2004-08-01 22:48:16 +000014 */
15
16#include <common.h>
17#if defined (CONFIG_IMX)
18
wdenk281e00a2004-08-01 22:48:16 +000019#include <asm/arch/imx-regs.h>
20
Jean-Christophe PLAGNIOL-VILLARDb54384e2009-05-15 23:47:02 +020021int timer_init (void)
wdenk281e00a2004-08-01 22:48:16 +000022{
23 int i;
24 /* setup GP Timer 1 */
25 TCTL1 = TCTL_SWR;
26 for ( i=0; i<100; i++) TCTL1 = 0; /* We have no udelay by now */
27 TPRER1 = get_PERCLK1() / 1000000; /* 1 MHz */
28 TCTL1 |= TCTL_FRR | (1<<1); /* Freerun Mode, PERCLK1 input */
29
Graeme Russ17659d72011-07-15 02:21:14 +000030 /* Reset the timer */
31 TCTL1 &= ~TCTL_TEN;
32 TCTL1 |= TCTL_TEN; /* Enable timer */
wdenk281e00a2004-08-01 22:48:16 +000033
34 return (0);
35}
36
37/*
38 * timer without interrupts
39 */
wdenk281e00a2004-08-01 22:48:16 +000040ulong get_timer (ulong base)
41{
Andrew Dyer274737e2008-09-12 02:20:46 +020042 return get_timer_masked() - base;
wdenk281e00a2004-08-01 22:48:16 +000043}
44
wdenk281e00a2004-08-01 22:48:16 +000045ulong get_timer_masked (void)
46{
47 return TCN1;
48}
49
50void udelay_masked (unsigned long usec)
51{
wdenk101e8df2005-04-04 12:08:28 +000052 ulong endtime = get_timer_masked() + usec;
53 signed long diff;
wdenk281e00a2004-08-01 22:48:16 +000054
wdenk101e8df2005-04-04 12:08:28 +000055 do {
56 ulong now = get_timer_masked ();
57 diff = endtime - now;
58 } while (diff >= 0);
wdenk281e00a2004-08-01 22:48:16 +000059}
60
Ingo van Lil3eb90ba2009-11-24 14:09:21 +010061void __udelay (unsigned long usec)
wdenk281e00a2004-08-01 22:48:16 +000062{
63 udelay_masked(usec);
64}
65
66/*
67 * This function is derived from PowerPC code (read timebase as long long).
68 * On ARM it just returns the timer value.
69 */
70unsigned long long get_ticks(void)
71{
72 return get_timer(0);
73}
74
75/*
76 * This function is derived from PowerPC code (timebase clock frequency).
77 * On ARM it returns the number of timer ticks per second.
78 */
79ulong get_tbclk (void)
80{
81 ulong tbclk;
82
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020083 tbclk = CONFIG_SYS_HZ;
wdenk281e00a2004-08-01 22:48:16 +000084
85 return tbclk;
86}
87
wdenkb304c962005-04-05 22:30:50 +000088/*
89 * Reset the cpu by setting up the watchdog timer and let him time out
90 */
91void reset_cpu (ulong ignored)
92{
93 /* Disable watchdog and set Time-Out field to 0 */
94 WCR = 0x00000000;
95
96 /* Write Service Sequence */
97 WSR = 0x00005555;
98 WSR = 0x0000AAAA;
99
100 /* Enable watchdog */
101 WCR = 0x00000001;
102
103 while (1);
104 /*NOTREACHED*/
105}
106
wdenk281e00a2004-08-01 22:48:16 +0000107#endif /* defined (CONFIG_IMX) */