blob: 403cd8ae57568569e2f8e80531553d40b6dfbf90 [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>
Simon Glass495a5dc2019-11-14 12:57:30 -070016#include <time.h>
wdenk7ac16102004-08-01 22:48:16 +000017#if defined (CONFIG_IMX)
18
wdenk7ac16102004-08-01 22:48:16 +000019#include <asm/arch/imx-regs.h>
20
Jean-Christophe PLAGNIOL-VILLARD8c9fc002009-05-15 23:47:02 +020021int timer_init (void)
wdenk7ac16102004-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 Russ944a7fe2011-07-15 02:21:14 +000030 /* Reset the timer */
31 TCTL1 &= ~TCTL_TEN;
32 TCTL1 |= TCTL_TEN; /* Enable timer */
wdenk7ac16102004-08-01 22:48:16 +000033
34 return (0);
35}
36
37/*
38 * timer without interrupts
39 */
Patrick Delaunay9858a602018-10-05 11:33:52 +020040static ulong get_timer_masked (void)
wdenk7ac16102004-08-01 22:48:16 +000041{
Patrick Delaunay9858a602018-10-05 11:33:52 +020042 return TCN1;
wdenk7ac16102004-08-01 22:48:16 +000043}
44
Patrick Delaunay9858a602018-10-05 11:33:52 +020045ulong get_timer (ulong base)
wdenk7ac16102004-08-01 22:48:16 +000046{
Patrick Delaunay9858a602018-10-05 11:33:52 +020047 return get_timer_masked() - base;
wdenk7ac16102004-08-01 22:48:16 +000048}
49
Patrick Delaunay94a08592018-10-05 11:33:51 +020050void __udelay (unsigned long usec)
wdenk7ac16102004-08-01 22:48:16 +000051{
wdenk7af1f9d2005-04-04 12:08:28 +000052 ulong endtime = get_timer_masked() + usec;
53 signed long diff;
wdenk7ac16102004-08-01 22:48:16 +000054
wdenk7af1f9d2005-04-04 12:08:28 +000055 do {
56 ulong now = get_timer_masked ();
57 diff = endtime - now;
58 } while (diff >= 0);
wdenk7ac16102004-08-01 22:48:16 +000059}
60
wdenk7ac16102004-08-01 22:48:16 +000061/*
62 * This function is derived from PowerPC code (read timebase as long long).
63 * On ARM it just returns the timer value.
64 */
65unsigned long long get_ticks(void)
66{
67 return get_timer(0);
68}
69
70/*
71 * This function is derived from PowerPC code (timebase clock frequency).
72 * On ARM it returns the number of timer ticks per second.
73 */
Simon Glassa9dc0682019-12-28 10:44:59 -070074ulong get_tbclk(void)
wdenk7ac16102004-08-01 22:48:16 +000075{
Masahiro Yamada04cfea52016-09-06 22:17:38 +090076 return CONFIG_SYS_HZ;
wdenk7ac16102004-08-01 22:48:16 +000077}
78
wdenk915b3762005-04-05 22:30:50 +000079/*
80 * Reset the cpu by setting up the watchdog timer and let him time out
81 */
82void reset_cpu (ulong ignored)
83{
84 /* Disable watchdog and set Time-Out field to 0 */
85 WCR = 0x00000000;
86
87 /* Write Service Sequence */
88 WSR = 0x00005555;
89 WSR = 0x0000AAAA;
90
91 /* Enable watchdog */
92 WCR = 0x00000001;
93
94 while (1);
95 /*NOTREACHED*/
96}
97
wdenk7ac16102004-08-01 22:48:16 +000098#endif /* defined (CONFIG_IMX) */