blob: c1cdf35fb25bdd6dfb78be1c9bff24ee336bbf8f [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefano Babic1c2b3ac2011-01-20 07:49:52 +00002/*
3 * (C) Copyright 2007
4 * Sascha Hauer, Pengutronix
5 *
6 * (C) Copyright 2008-2009 Freescale Semiconductor, Inc.
Stefano Babic1c2b3ac2011-01-20 07:49:52 +00007 */
8
9#include <common.h>
10#include <asm/io.h>
11#include <asm/arch/imx-regs.h>
Benoît Thébaudeau6ce2db02012-08-21 11:07:54 +000012#include <asm/arch/crm_regs.h>
Stefano Babicb36049c2012-02-04 12:56:50 +010013
Stefano Babic1c2b3ac2011-01-20 07:49:52 +000014/* General purpose timers bitfields */
15#define GPTCR_SWR (1<<15) /* Software reset */
16#define GPTCR_FRR (1<<9) /* Freerun / restart */
Benoît Thébaudeau6ce2db02012-08-21 11:07:54 +000017#define GPTCR_CLKSOURCE_32 (4<<6) /* Clock source */
Stefano Babic1c2b3ac2011-01-20 07:49:52 +000018#define GPTCR_TEN (1) /* Timer enable */
Stefano Babicb36049c2012-02-04 12:56:50 +010019
Benoît Thébaudeau6ce2db02012-08-21 11:07:54 +000020/*
Benoît Thébaudeau6ce2db02012-08-21 11:07:54 +000021 * nothing really to do with interrupts, just starts up a counter.
22 * The 32KHz 32-bit timer overruns in 134217 seconds
23 */
Stefano Babic1c2b3ac2011-01-20 07:49:52 +000024int timer_init(void)
25{
26 int i;
27 struct gpt_regs *gpt = (struct gpt_regs *)GPT1_BASE_ADDR;
Benoît Thébaudeau6ce2db02012-08-21 11:07:54 +000028 struct ccm_regs *ccm = (struct ccm_regs *)CCM_BASE_ADDR;
Stefano Babic1c2b3ac2011-01-20 07:49:52 +000029
30 /* setup GP Timer 1 */
31 writel(GPTCR_SWR, &gpt->ctrl);
Stefano Babic1c2b3ac2011-01-20 07:49:52 +000032
Benoît Thébaudeau6ce2db02012-08-21 11:07:54 +000033 writel(readl(&ccm->cgr1) | 3 << MXC_CCM_CGR1_GPT_OFFSET, &ccm->cgr1);
34
35 for (i = 0; i < 100; i++)
36 writel(0, &gpt->ctrl); /* We have no udelay by now */
37 writel(0, &gpt->pre); /* prescaler = 1 */
38 /* Freerun Mode, 32KHz input */
39 writel(readl(&gpt->ctrl) | GPTCR_CLKSOURCE_32 | GPTCR_FRR,
40 &gpt->ctrl);
41 writel(readl(&gpt->ctrl) | GPTCR_TEN, &gpt->ctrl);
Stefano Babic1c2b3ac2011-01-20 07:49:52 +000042
43 return 0;
44}