Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Stefano Babic | 1c2b3ac | 2011-01-20 07:49:52 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2007 |
| 4 | * Sascha Hauer, Pengutronix |
| 5 | * |
| 6 | * (C) Copyright 2008-2009 Freescale Semiconductor, Inc. |
Stefano Babic | 1c2b3ac | 2011-01-20 07:49:52 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 10 | #include <init.h> |
Stefano Babic | 1c2b3ac | 2011-01-20 07:49:52 +0000 | [diff] [blame] | 11 | #include <asm/io.h> |
| 12 | #include <asm/arch/imx-regs.h> |
Benoît Thébaudeau | 6ce2db0 | 2012-08-21 11:07:54 +0000 | [diff] [blame] | 13 | #include <asm/arch/crm_regs.h> |
Simon Glass | 6b9f010 | 2020-05-10 11:40:06 -0600 | [diff] [blame] | 14 | #include <asm/ptrace.h> |
Stefano Babic | b36049c | 2012-02-04 12:56:50 +0100 | [diff] [blame] | 15 | |
Stefano Babic | 1c2b3ac | 2011-01-20 07:49:52 +0000 | [diff] [blame] | 16 | /* General purpose timers bitfields */ |
| 17 | #define GPTCR_SWR (1<<15) /* Software reset */ |
| 18 | #define GPTCR_FRR (1<<9) /* Freerun / restart */ |
Benoît Thébaudeau | 6ce2db0 | 2012-08-21 11:07:54 +0000 | [diff] [blame] | 19 | #define GPTCR_CLKSOURCE_32 (4<<6) /* Clock source */ |
Stefano Babic | 1c2b3ac | 2011-01-20 07:49:52 +0000 | [diff] [blame] | 20 | #define GPTCR_TEN (1) /* Timer enable */ |
Stefano Babic | b36049c | 2012-02-04 12:56:50 +0100 | [diff] [blame] | 21 | |
Benoît Thébaudeau | 6ce2db0 | 2012-08-21 11:07:54 +0000 | [diff] [blame] | 22 | /* |
Benoît Thébaudeau | 6ce2db0 | 2012-08-21 11:07:54 +0000 | [diff] [blame] | 23 | * nothing really to do with interrupts, just starts up a counter. |
| 24 | * The 32KHz 32-bit timer overruns in 134217 seconds |
| 25 | */ |
Stefano Babic | 1c2b3ac | 2011-01-20 07:49:52 +0000 | [diff] [blame] | 26 | int timer_init(void) |
| 27 | { |
| 28 | int i; |
| 29 | struct gpt_regs *gpt = (struct gpt_regs *)GPT1_BASE_ADDR; |
Benoît Thébaudeau | 6ce2db0 | 2012-08-21 11:07:54 +0000 | [diff] [blame] | 30 | struct ccm_regs *ccm = (struct ccm_regs *)CCM_BASE_ADDR; |
Stefano Babic | 1c2b3ac | 2011-01-20 07:49:52 +0000 | [diff] [blame] | 31 | |
| 32 | /* setup GP Timer 1 */ |
| 33 | writel(GPTCR_SWR, &gpt->ctrl); |
Stefano Babic | 1c2b3ac | 2011-01-20 07:49:52 +0000 | [diff] [blame] | 34 | |
Benoît Thébaudeau | 6ce2db0 | 2012-08-21 11:07:54 +0000 | [diff] [blame] | 35 | writel(readl(&ccm->cgr1) | 3 << MXC_CCM_CGR1_GPT_OFFSET, &ccm->cgr1); |
| 36 | |
| 37 | for (i = 0; i < 100; i++) |
| 38 | writel(0, &gpt->ctrl); /* We have no udelay by now */ |
| 39 | writel(0, &gpt->pre); /* prescaler = 1 */ |
| 40 | /* Freerun Mode, 32KHz input */ |
| 41 | writel(readl(&gpt->ctrl) | GPTCR_CLKSOURCE_32 | GPTCR_FRR, |
| 42 | &gpt->ctrl); |
| 43 | writel(readl(&gpt->ctrl) | GPTCR_TEN, &gpt->ctrl); |
Stefano Babic | 1c2b3ac | 2011-01-20 07:49:52 +0000 | [diff] [blame] | 44 | |
| 45 | return 0; |
| 46 | } |