1// SPDX-License-Identifier: GPL-2.0+ 2/* 3 * (C) Copyright 2007 4 * Sascha Hauer, Pengutronix 5 */ 6 7#include <common.h> 8#include <init.h> 9#include <asm/arch/imx-regs.h> 10#include <asm/io.h> 11 12#define TIMER_BASE 0x53f90000 /* General purpose timer 1 */ 13 14/* General purpose timers registers */ 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 */ 19 20/* General purpose timers bitfields */ 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 26/* The 32768Hz 32-bit timer overruns in 131072 seconds */ 27int timer_init(void) 28{ 29 int i; 30 31 /* setup GP Timer 1 */ 32 GPTCR = GPTCR_SWR; 33 for (i = 0; i < 100; i++) 34 GPTCR = 0; /* We have no udelay by now */ 35 GPTPR = 0; /* 32Khz */ 36 /* Freerun Mode, PERCLK1 input */ 37 GPTCR |= GPTCR_CLKSOURCE_32 | GPTCR_TEN; 38 39 return 0; 40} 41 42unsigned long timer_read_counter(void) 43{ 44 return GPTCNT; 45} 46