blob: 3a81ce427ca64566ab9f397c1e77cc4e5547b943 [file] [log] [blame]
Sascha Hauer1a7676f2008-03-26 20:40:42 +01001/*
2 * (C) Copyright 2007
3 * Sascha Hauer, Pengutronix
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Sascha Hauer1a7676f2008-03-26 20:40:42 +01006 */
7
8#include <common.h>
Stefano Babic78129d92011-03-14 15:43:56 +01009#include <asm/arch/imx-regs.h>
Stefano Babice17e3312011-02-02 00:49:36 +000010#include <asm/io.h>
Sascha Hauer1a7676f2008-03-26 20:40:42 +010011
12#define TIMER_BASE 0x53f90000 /* General purpose timer 1 */
13
14/* General purpose timers registers */
Guennadi Liakhovetski4771a4c2008-09-25 20:54:37 +020015#define GPTCR __REG(TIMER_BASE) /* Control register */
16#define GPTPR __REG(TIMER_BASE + 0x4) /* Prescaler register */
17#define GPTSR __REG(TIMER_BASE + 0x8) /* Status register */
18#define GPTCNT __REG(TIMER_BASE + 0x24) /* Counter register */
Sascha Hauer1a7676f2008-03-26 20:40:42 +010019
20/* General purpose timers bitfields */
Guennadi Liakhovetski4771a4c2008-09-25 20:54:37 +020021#define GPTCR_SWR (1 << 15) /* Software reset */
22#define GPTCR_FRR (1 << 9) /* Freerun / restart */
23#define GPTCR_CLKSOURCE_32 (4 << 6) /* Clock source */
24#define GPTCR_TEN 1 /* Timer enable */
25
Heiko Schocherf2015952010-12-09 22:01:15 +000026DECLARE_GLOBAL_DATA_PTR;
Tomohiro Masubuchi9a3393b2008-10-21 13:17:16 +090027
Guennadi Liakhovetski4771a4c2008-09-25 20:54:37 +020028/* The 32768Hz 32-bit timer overruns in 131072 seconds */
Fabio Estevamf231efb2011-10-13 05:34:59 +000029int timer_init(void)
Sascha Hauer1a7676f2008-03-26 20:40:42 +010030{
31 int i;
32
33 /* setup GP Timer 1 */
34 GPTCR = GPTCR_SWR;
Guennadi Liakhovetski4771a4c2008-09-25 20:54:37 +020035 for (i = 0; i < 100; i++)
36 GPTCR = 0; /* We have no udelay by now */
Sascha Hauer1a7676f2008-03-26 20:40:42 +010037 GPTPR = 0; /* 32Khz */
Guennadi Liakhovetski4771a4c2008-09-25 20:54:37 +020038 /* Freerun Mode, PERCLK1 input */
39 GPTCR |= GPTCR_CLKSOURCE_32 | GPTCR_TEN;
Sascha Hauer1a7676f2008-03-26 20:40:42 +010040
41 return 0;
42}
43
Andrew Ruder41249202014-08-12 09:26:00 -050044unsigned long timer_read_counter(void)
Stefano Babicecb6e6e2012-02-04 13:02:01 +010045{
Andrew Ruder41249202014-08-12 09:26:00 -050046 return GPTCNT;
Stefano Babicecb6e6e2012-02-04 13:02:01 +010047}