3 * Sascha Hauer, Pengutronix
5 * (C) Copyright 2008-2009 Freescale Semiconductor, Inc.
7 * See file CREDITS for list of people who contributed to this
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 #include <asm/arch/mx35.h>
29 /* General purpose timers registers */
30 #define GPTCR __REG(GPT1_BASE_ADDR) /* Control register */
31 #define GPTPR __REG(GPT1_BASE_ADDR + 0x4) /* Prescaler register */
32 #define GPTSR __REG(GPT1_BASE_ADDR + 0x8) /* Status register */
33 #define GPTCNT __REG(GPT1_BASE_ADDR + 0x24) /* Counter register */
35 /* General purpose timers bitfields */
36 #define GPTCR_SWR (1<<15) /* Software reset */
37 #define GPTCR_FRR (1<<9) /* Freerun / restart */
38 #define GPTCR_CLKSOURCE_32 (0x100<<6) /* Clock source */
39 #define GPTCR_CLKSOURCE_IPG (0x001<<6) /* Clock source */
40 #define GPTCR_TEN (1) /* Timer enable */
41 #define GPTPR_VAL (66)
43 static inline void setup_gpt()
53 /* setup GP Timer 1 */
55 for (i = 0; i < 100; i++)
56 GPTCR = 0; /* We have no udelay by now */
57 GPTPR = GPTPR_VAL; /* 66Mhz / 66 */
58 /* Freerun Mode, PERCLK1 input */
59 GPTCR |= GPTCR_CLKSOURCE_IPG | GPTCR_TEN;
69 void reset_timer_masked(void)
72 /* Freerun Mode, PERCLK1 input */
73 GPTCR = GPTCR_CLKSOURCE_IPG | GPTCR_TEN;
76 inline ulong get_timer_masked(void)
83 void reset_timer(void)
88 ulong get_timer(ulong base)
92 tmp = get_timer_masked();
94 if (tmp <= (base * 1000)) {
96 tmp += (0xffffffff - base);
99 return (tmp / 1000) - base;
102 void set_timer(ulong t)
106 /* delay x useconds AND perserve advance timstamp value */
107 /* GPTCNT is now supposed to tick 1 by 1 us. */
108 void udelay(unsigned long usec)
114 tmp = get_timer_masked(); /* get current timestamp */
116 /* if setting this forward will roll time stamp */
117 if ((usec + tmp + 1) < tmp) {
118 /* reset "advancing" timestamp to 0, set lastinc value */
119 reset_timer_masked();
121 /* else, set advancing stamp wake up time */
125 while (get_timer_masked() < tmp) /* loop till event */
129 void reset_cpu(ulong addr)
131 __REG16(WDOG_BASE_ADDR) = 4;