Sascha Hauer | 1a7676f | 2008-03-26 20:40:42 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2007 |
| 3 | * Sascha Hauer, Pengutronix |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Sascha Hauer | 1a7676f | 2008-03-26 20:40:42 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Stefano Babic | 78129d9 | 2011-03-14 15:43:56 +0100 | [diff] [blame] | 9 | #include <asm/arch/imx-regs.h> |
Stefano Babic | e17e331 | 2011-02-02 00:49:36 +0000 | [diff] [blame] | 10 | #include <asm/io.h> |
Sascha Hauer | 1a7676f | 2008-03-26 20:40:42 +0100 | [diff] [blame] | 11 | |
| 12 | #define TIMER_BASE 0x53f90000 /* General purpose timer 1 */ |
| 13 | |
| 14 | /* General purpose timers registers */ |
Guennadi Liakhovetski | 4771a4c | 2008-09-25 20:54:37 +0200 | [diff] [blame] | 15 | #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 Hauer | 1a7676f | 2008-03-26 20:40:42 +0100 | [diff] [blame] | 19 | |
| 20 | /* General purpose timers bitfields */ |
Guennadi Liakhovetski | 4771a4c | 2008-09-25 20:54:37 +0200 | [diff] [blame] | 21 | #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 | |
Guennadi Liakhovetski | 4771a4c | 2008-09-25 20:54:37 +0200 | [diff] [blame] | 26 | /* The 32768Hz 32-bit timer overruns in 131072 seconds */ |
Fabio Estevam | f231efb | 2011-10-13 05:34:59 +0000 | [diff] [blame] | 27 | int timer_init(void) |
Sascha Hauer | 1a7676f | 2008-03-26 20:40:42 +0100 | [diff] [blame] | 28 | { |
| 29 | int i; |
| 30 | |
| 31 | /* setup GP Timer 1 */ |
| 32 | GPTCR = GPTCR_SWR; |
Guennadi Liakhovetski | 4771a4c | 2008-09-25 20:54:37 +0200 | [diff] [blame] | 33 | for (i = 0; i < 100; i++) |
| 34 | GPTCR = 0; /* We have no udelay by now */ |
Sascha Hauer | 1a7676f | 2008-03-26 20:40:42 +0100 | [diff] [blame] | 35 | GPTPR = 0; /* 32Khz */ |
Guennadi Liakhovetski | 4771a4c | 2008-09-25 20:54:37 +0200 | [diff] [blame] | 36 | /* Freerun Mode, PERCLK1 input */ |
| 37 | GPTCR |= GPTCR_CLKSOURCE_32 | GPTCR_TEN; |
Sascha Hauer | 1a7676f | 2008-03-26 20:40:42 +0100 | [diff] [blame] | 38 | |
| 39 | return 0; |
| 40 | } |
| 41 | |
Andrew Ruder | 4124920 | 2014-08-12 09:26:00 -0500 | [diff] [blame] | 42 | unsigned long timer_read_counter(void) |
Stefano Babic | ecb6e6e | 2012-02-04 13:02:01 +0100 | [diff] [blame] | 43 | { |
Andrew Ruder | 4124920 | 2014-08-12 09:26:00 -0500 | [diff] [blame] | 44 | return GPTCNT; |
Stefano Babic | ecb6e6e | 2012-02-04 13:02:01 +0100 | [diff] [blame] | 45 | } |