blob: 3d07ee68094465dfb1c7a9c00d1d8094caf60992 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Sascha Hauer1a7676f2008-03-26 20:40:42 +01002/*
3 * (C) Copyright 2007
4 * Sascha Hauer, Pengutronix
Sascha Hauer1a7676f2008-03-26 20:40:42 +01005 */
6
7#include <common.h>
Stefano Babic78129d92011-03-14 15:43:56 +01008#include <asm/arch/imx-regs.h>
Stefano Babice17e3312011-02-02 00:49:36 +00009#include <asm/io.h>
Sascha Hauer1a7676f2008-03-26 20:40:42 +010010
11#define TIMER_BASE 0x53f90000 /* General purpose timer 1 */
12
13/* General purpose timers registers */
Guennadi Liakhovetski4771a4c2008-09-25 20:54:37 +020014#define GPTCR __REG(TIMER_BASE) /* Control register */
15#define GPTPR __REG(TIMER_BASE + 0x4) /* Prescaler register */
16#define GPTSR __REG(TIMER_BASE + 0x8) /* Status register */
17#define GPTCNT __REG(TIMER_BASE + 0x24) /* Counter register */
Sascha Hauer1a7676f2008-03-26 20:40:42 +010018
19/* General purpose timers bitfields */
Guennadi Liakhovetski4771a4c2008-09-25 20:54:37 +020020#define GPTCR_SWR (1 << 15) /* Software reset */
21#define GPTCR_FRR (1 << 9) /* Freerun / restart */
22#define GPTCR_CLKSOURCE_32 (4 << 6) /* Clock source */
23#define GPTCR_TEN 1 /* Timer enable */
24
Guennadi Liakhovetski4771a4c2008-09-25 20:54:37 +020025/* The 32768Hz 32-bit timer overruns in 131072 seconds */
Fabio Estevamf231efb2011-10-13 05:34:59 +000026int timer_init(void)
Sascha Hauer1a7676f2008-03-26 20:40:42 +010027{
28 int i;
29
30 /* setup GP Timer 1 */
31 GPTCR = GPTCR_SWR;
Guennadi Liakhovetski4771a4c2008-09-25 20:54:37 +020032 for (i = 0; i < 100; i++)
33 GPTCR = 0; /* We have no udelay by now */
Sascha Hauer1a7676f2008-03-26 20:40:42 +010034 GPTPR = 0; /* 32Khz */
Guennadi Liakhovetski4771a4c2008-09-25 20:54:37 +020035 /* Freerun Mode, PERCLK1 input */
36 GPTCR |= GPTCR_CLKSOURCE_32 | GPTCR_TEN;
Sascha Hauer1a7676f2008-03-26 20:40:42 +010037
38 return 0;
39}
40
Andrew Ruder41249202014-08-12 09:26:00 -050041unsigned long timer_read_counter(void)
Stefano Babicecb6e6e2012-02-04 13:02:01 +010042{
Andrew Ruder41249202014-08-12 09:26:00 -050043 return GPTCNT;
Stefano Babicecb6e6e2012-02-04 13:02:01 +010044}