blob: c396e15ec099dc05ac9a16025d95ebb338ea6411 [file] [log] [blame]
Stefano Babic1c2b3ac2011-01-20 07:49:52 +00001/*
2 * (C) Copyright 2007
3 * Sascha Hauer, Pengutronix
4 *
5 * (C) Copyright 2008-2009 Freescale Semiconductor, Inc.
6 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02007 * SPDX-License-Identifier: GPL-2.0+
Stefano Babic1c2b3ac2011-01-20 07:49:52 +00008 */
9
10#include <common.h>
11#include <asm/io.h>
12#include <asm/arch/imx-regs.h>
Benoît Thébaudeau6ce2db02012-08-21 11:07:54 +000013#include <asm/arch/crm_regs.h>
Stefano Babicb36049c2012-02-04 12:56:50 +010014
Stefano Babic1c2b3ac2011-01-20 07:49:52 +000015/* General purpose timers bitfields */
16#define GPTCR_SWR (1<<15) /* Software reset */
17#define GPTCR_FRR (1<<9) /* Freerun / restart */
Benoît Thébaudeau6ce2db02012-08-21 11:07:54 +000018#define GPTCR_CLKSOURCE_32 (4<<6) /* Clock source */
Stefano Babic1c2b3ac2011-01-20 07:49:52 +000019#define GPTCR_TEN (1) /* Timer enable */
Stefano Babicb36049c2012-02-04 12:56:50 +010020
Benoît Thébaudeau6ce2db02012-08-21 11:07:54 +000021/*
Benoît Thébaudeau6ce2db02012-08-21 11:07:54 +000022 * nothing really to do with interrupts, just starts up a counter.
23 * The 32KHz 32-bit timer overruns in 134217 seconds
24 */
Stefano Babic1c2b3ac2011-01-20 07:49:52 +000025int timer_init(void)
26{
27 int i;
28 struct gpt_regs *gpt = (struct gpt_regs *)GPT1_BASE_ADDR;
Benoît Thébaudeau6ce2db02012-08-21 11:07:54 +000029 struct ccm_regs *ccm = (struct ccm_regs *)CCM_BASE_ADDR;
Stefano Babic1c2b3ac2011-01-20 07:49:52 +000030
31 /* setup GP Timer 1 */
32 writel(GPTCR_SWR, &gpt->ctrl);
Stefano Babic1c2b3ac2011-01-20 07:49:52 +000033
Benoît Thébaudeau6ce2db02012-08-21 11:07:54 +000034 writel(readl(&ccm->cgr1) | 3 << MXC_CCM_CGR1_GPT_OFFSET, &ccm->cgr1);
35
36 for (i = 0; i < 100; i++)
37 writel(0, &gpt->ctrl); /* We have no udelay by now */
38 writel(0, &gpt->pre); /* prescaler = 1 */
39 /* Freerun Mode, 32KHz input */
40 writel(readl(&gpt->ctrl) | GPTCR_CLKSOURCE_32 | GPTCR_FRR,
41 &gpt->ctrl);
42 writel(readl(&gpt->ctrl) | GPTCR_TEN, &gpt->ctrl);
Stefano Babic1c2b3ac2011-01-20 07:49:52 +000043
44 return 0;
45}