blob: 96fff3f683f892b816c598e03a2847f3b64fd7d3 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenk7ac16102004-08-01 22:48:16 +00002/*
3 * (C) Copyright 2002
4 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
5 * Marius Groeger <mgroeger@sysgo.de>
6 *
7 * (C) Copyright 2002
8 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
9 * Alex Zuepke <azu@sysgo.de>
10 *
11 * (C) Copyright 2002
Detlev Zundelf1b3f2b2009-05-13 10:54:10 +020012 * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de>
wdenk7ac16102004-08-01 22:48:16 +000013 */
14
15#include <common.h>
16#if defined (CONFIG_IMX)
17
wdenk7ac16102004-08-01 22:48:16 +000018#include <asm/arch/imx-regs.h>
19
Jean-Christophe PLAGNIOL-VILLARD8c9fc002009-05-15 23:47:02 +020020int timer_init (void)
wdenk7ac16102004-08-01 22:48:16 +000021{
22 int i;
23 /* setup GP Timer 1 */
24 TCTL1 = TCTL_SWR;
25 for ( i=0; i<100; i++) TCTL1 = 0; /* We have no udelay by now */
26 TPRER1 = get_PERCLK1() / 1000000; /* 1 MHz */
27 TCTL1 |= TCTL_FRR | (1<<1); /* Freerun Mode, PERCLK1 input */
28
Graeme Russ944a7fe2011-07-15 02:21:14 +000029 /* Reset the timer */
30 TCTL1 &= ~TCTL_TEN;
31 TCTL1 |= TCTL_TEN; /* Enable timer */
wdenk7ac16102004-08-01 22:48:16 +000032
33 return (0);
34}
35
36/*
37 * timer without interrupts
38 */
Patrick Delaunay9858a602018-10-05 11:33:52 +020039static ulong get_timer_masked (void)
wdenk7ac16102004-08-01 22:48:16 +000040{
Patrick Delaunay9858a602018-10-05 11:33:52 +020041 return TCN1;
wdenk7ac16102004-08-01 22:48:16 +000042}
43
Patrick Delaunay9858a602018-10-05 11:33:52 +020044ulong get_timer (ulong base)
wdenk7ac16102004-08-01 22:48:16 +000045{
Patrick Delaunay9858a602018-10-05 11:33:52 +020046 return get_timer_masked() - base;
wdenk7ac16102004-08-01 22:48:16 +000047}
48
Patrick Delaunay94a08592018-10-05 11:33:51 +020049void __udelay (unsigned long usec)
wdenk7ac16102004-08-01 22:48:16 +000050{
wdenk7af1f9d2005-04-04 12:08:28 +000051 ulong endtime = get_timer_masked() + usec;
52 signed long diff;
wdenk7ac16102004-08-01 22:48:16 +000053
wdenk7af1f9d2005-04-04 12:08:28 +000054 do {
55 ulong now = get_timer_masked ();
56 diff = endtime - now;
57 } while (diff >= 0);
wdenk7ac16102004-08-01 22:48:16 +000058}
59
wdenk7ac16102004-08-01 22:48:16 +000060/*
61 * This function is derived from PowerPC code (read timebase as long long).
62 * On ARM it just returns the timer value.
63 */
64unsigned long long get_ticks(void)
65{
66 return get_timer(0);
67}
68
69/*
70 * This function is derived from PowerPC code (timebase clock frequency).
71 * On ARM it returns the number of timer ticks per second.
72 */
73ulong get_tbclk (void)
74{
Masahiro Yamada04cfea52016-09-06 22:17:38 +090075 return CONFIG_SYS_HZ;
wdenk7ac16102004-08-01 22:48:16 +000076}
77
wdenk915b3762005-04-05 22:30:50 +000078/*
79 * Reset the cpu by setting up the watchdog timer and let him time out
80 */
81void reset_cpu (ulong ignored)
82{
83 /* Disable watchdog and set Time-Out field to 0 */
84 WCR = 0x00000000;
85
86 /* Write Service Sequence */
87 WSR = 0x00005555;
88 WSR = 0x0000AAAA;
89
90 /* Enable watchdog */
91 WCR = 0x00000001;
92
93 while (1);
94 /*NOTREACHED*/
95}
96
wdenk7ac16102004-08-01 22:48:16 +000097#endif /* defined (CONFIG_IMX) */