wdenk | 32fe287 | 2002-10-11 07:57:01 +0000 | [diff] [blame] | 1 | /* |
Marek Vasut | ba2d9be | 2011-11-26 10:02:41 +0100 | [diff] [blame] | 2 | * Marvell PXA2xx/3xx timer driver |
wdenk | 32fe287 | 2002-10-11 07:57:01 +0000 | [diff] [blame] | 3 | * |
Marek Vasut | ba2d9be | 2011-11-26 10:02:41 +0100 | [diff] [blame] | 4 | * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com> |
wdenk | 32fe287 | 2002-10-11 07:57:01 +0000 | [diff] [blame] | 5 | * |
| 6 | * See file CREDITS for list of people who contributed to this |
| 7 | * project. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License as |
| 11 | * published by the Free Software Foundation; either version 2 of |
| 12 | * the License, or (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 22 | * MA 02111-1307 USA |
| 23 | */ |
| 24 | |
wdenk | 32fe287 | 2002-10-11 07:57:01 +0000 | [diff] [blame] | 25 | #include <asm/arch/pxa-regs.h> |
Marek Vasut | 2db1e96 | 2010-09-09 09:50:39 +0200 | [diff] [blame] | 26 | #include <asm/io.h> |
| 27 | #include <common.h> |
Jean-Christophe PLAGNIOL-VILLARD | e90368d | 2009-02-24 06:13:10 +0100 | [diff] [blame] | 28 | #include <div64.h> |
wdenk | 32fe287 | 2002-10-11 07:57:01 +0000 | [diff] [blame] | 29 | |
Marek Vasut | ba2d9be | 2011-11-26 10:02:41 +0100 | [diff] [blame] | 30 | DECLARE_GLOBAL_DATA_PTR; |
| 31 | |
| 32 | #define TIMER_LOAD_VAL 0xffffffff |
| 33 | |
| 34 | #define timestamp (gd->tbl) |
| 35 | #define lastinc (gd->lastinc) |
wdenk | 32fe287 | 2002-10-11 07:57:01 +0000 | [diff] [blame] | 36 | |
Marek Vasut | 85cc88a | 2011-11-26 07:20:07 +0100 | [diff] [blame] | 37 | #if defined(CONFIG_CPU_PXA27X) || defined(CONFIG_CPU_MONAHANS) |
Marek Vasut | ba2d9be | 2011-11-26 10:02:41 +0100 | [diff] [blame] | 38 | #define TIMER_FREQ_HZ 3250000 |
Marek Vasut | 85cc88a | 2011-11-26 07:20:07 +0100 | [diff] [blame] | 39 | #elif defined(CONFIG_CPU_PXA25X) |
Marek Vasut | ba2d9be | 2011-11-26 10:02:41 +0100 | [diff] [blame] | 40 | #define TIMER_FREQ_HZ 3686400 |
Micha Kalfon | 8a75a5b | 2009-02-11 19:50:11 +0200 | [diff] [blame] | 41 | #else |
| 42 | #error "Timer frequency unknown - please config PXA CPU type" |
| 43 | #endif |
| 44 | |
Marek Vasut | ba2d9be | 2011-11-26 10:02:41 +0100 | [diff] [blame] | 45 | static unsigned long long tick_to_time(unsigned long long tick) |
Jean-Christophe PLAGNIOL-VILLARD | e90368d | 2009-02-24 06:13:10 +0100 | [diff] [blame] | 46 | { |
Marek Vasut | ba2d9be | 2011-11-26 10:02:41 +0100 | [diff] [blame] | 47 | return tick * CONFIG_SYS_HZ / TIMER_FREQ_HZ; |
Jean-Christophe PLAGNIOL-VILLARD | e90368d | 2009-02-24 06:13:10 +0100 | [diff] [blame] | 48 | } |
| 49 | |
Marek Vasut | ba2d9be | 2011-11-26 10:02:41 +0100 | [diff] [blame] | 50 | static unsigned long long us_to_tick(unsigned long long us) |
Jean-Christophe PLAGNIOL-VILLARD | e90368d | 2009-02-24 06:13:10 +0100 | [diff] [blame] | 51 | { |
Marek Vasut | ba2d9be | 2011-11-26 10:02:41 +0100 | [diff] [blame] | 52 | return (us * TIMER_FREQ_HZ) / 1000000; |
Jean-Christophe PLAGNIOL-VILLARD | e90368d | 2009-02-24 06:13:10 +0100 | [diff] [blame] | 53 | } |
| 54 | |
Marek Vasut | ba2d9be | 2011-11-26 10:02:41 +0100 | [diff] [blame] | 55 | int timer_init(void) |
wdenk | 32fe287 | 2002-10-11 07:57:01 +0000 | [diff] [blame] | 56 | { |
Graeme Russ | 944a7fe | 2011-07-15 02:21:14 +0000 | [diff] [blame] | 57 | writel(0, OSCR); |
Jean-Christophe PLAGNIOL-VILLARD | 8c9fc00 | 2009-05-15 23:47:02 +0200 | [diff] [blame] | 58 | return 0; |
wdenk | 32fe287 | 2002-10-11 07:57:01 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Marek Vasut | ba2d9be | 2011-11-26 10:02:41 +0100 | [diff] [blame] | 61 | unsigned long long get_ticks(void) |
wdenk | 32fe287 | 2002-10-11 07:57:01 +0000 | [diff] [blame] | 62 | { |
Marek Vasut | ba2d9be | 2011-11-26 10:02:41 +0100 | [diff] [blame] | 63 | /* Current tick value */ |
| 64 | uint32_t now = readl(OSCR); |
wdenk | 32fe287 | 2002-10-11 07:57:01 +0000 | [diff] [blame] | 65 | |
Marek Vasut | ba2d9be | 2011-11-26 10:02:41 +0100 | [diff] [blame] | 66 | if (now >= lastinc) { |
| 67 | /* |
| 68 | * Normal mode (non roll) |
| 69 | * Move stamp forward with absolute diff ticks |
| 70 | */ |
| 71 | timestamp += (now - lastinc); |
| 72 | } else { |
| 73 | /* We have rollover of incrementer */ |
| 74 | timestamp += (TIMER_LOAD_VAL - lastinc) + now; |
| 75 | } |
| 76 | |
| 77 | lastinc = now; |
| 78 | return timestamp; |
wdenk | 32fe287 | 2002-10-11 07:57:01 +0000 | [diff] [blame] | 79 | } |
| 80 | |
Marek Vasut | ba2d9be | 2011-11-26 10:02:41 +0100 | [diff] [blame] | 81 | ulong get_timer(ulong base) |
wdenk | 32fe287 | 2002-10-11 07:57:01 +0000 | [diff] [blame] | 82 | { |
Marek Vasut | ba2d9be | 2011-11-26 10:02:41 +0100 | [diff] [blame] | 83 | return tick_to_time(get_ticks()) - base; |
wdenk | 32fe287 | 2002-10-11 07:57:01 +0000 | [diff] [blame] | 84 | } |
| 85 | |
Marek Vasut | ba2d9be | 2011-11-26 10:02:41 +0100 | [diff] [blame] | 86 | void __udelay(unsigned long usec) |
wdenk | 32fe287 | 2002-10-11 07:57:01 +0000 | [diff] [blame] | 87 | { |
Jean-Christophe PLAGNIOL-VILLARD | e90368d | 2009-02-24 06:13:10 +0100 | [diff] [blame] | 88 | unsigned long long tmp; |
wdenk | 32fe287 | 2002-10-11 07:57:01 +0000 | [diff] [blame] | 89 | ulong tmo; |
| 90 | |
Jean-Christophe PLAGNIOL-VILLARD | e90368d | 2009-02-24 06:13:10 +0100 | [diff] [blame] | 91 | tmo = us_to_tick(usec); |
| 92 | tmp = get_ticks() + tmo; /* get current timestamp */ |
wdenk | 32fe287 | 2002-10-11 07:57:01 +0000 | [diff] [blame] | 93 | |
Jean-Christophe PLAGNIOL-VILLARD | e90368d | 2009-02-24 06:13:10 +0100 | [diff] [blame] | 94 | while (get_ticks() < tmp) /* loop till event */ |
| 95 | /*NOP*/; |
wdenk | 49c3f67 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 96 | } |
Marek Vasut | 454afe7 | 2012-02-27 13:59:47 +0100 | [diff] [blame^] | 97 | |
| 98 | ulong get_tbclk(void) |
| 99 | { |
| 100 | return TIMER_FREQ_HZ; |
| 101 | } |