wdenk | 32fe287 | 2002-10-11 07:57:01 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
| 3 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 4 | * Marius Groeger <mgroeger@sysgo.de> |
| 5 | * |
| 6 | * (C) Copyright 2002 |
| 7 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 8 | * Alex Zuepke <azu@sysgo.de> |
| 9 | * |
| 10 | * See file CREDITS for list of people who contributed to this |
| 11 | * project. |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or |
| 14 | * modify it under the terms of the GNU General Public License as |
| 15 | * published by the Free Software Foundation; either version 2 of |
| 16 | * the License, or (at your option) any later version. |
| 17 | * |
| 18 | * This program is distributed in the hope that it will be useful, |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | * GNU General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU General Public License |
| 24 | * along with this program; if not, write to the Free Software |
| 25 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 26 | * MA 02111-1307 USA |
| 27 | */ |
| 28 | |
| 29 | #include <common.h> |
| 30 | #include <asm/arch/pxa-regs.h> |
| 31 | |
wdenk | 32fe287 | 2002-10-11 07:57:01 +0000 | [diff] [blame] | 32 | #ifdef CONFIG_USE_IRQ |
wdenk | 32fe287 | 2002-10-11 07:57:01 +0000 | [diff] [blame] | 33 | #error: interrupts not implemented yet |
wdenk | 32fe287 | 2002-10-11 07:57:01 +0000 | [diff] [blame] | 34 | #endif |
| 35 | |
Micha Kalfon | 8a75a5b | 2009-02-11 19:50:11 +0200 | [diff] [blame^] | 36 | #if defined(CONFIG_PXA27X) || defined(CONFIG_CPU_MONAHANS) |
| 37 | #define TIMER_FREQ_HZ 3250000 |
| 38 | #elif defined(CONFIG_PXA250) |
| 39 | #define TIMER_FREQ_HZ 3686400 |
| 40 | #else |
| 41 | #error "Timer frequency unknown - please config PXA CPU type" |
| 42 | #endif |
| 43 | |
wdenk | 32fe287 | 2002-10-11 07:57:01 +0000 | [diff] [blame] | 44 | int interrupt_init (void) |
| 45 | { |
| 46 | /* nothing happens here - we don't setup any IRQs */ |
| 47 | return (0); |
| 48 | } |
| 49 | |
| 50 | void reset_timer (void) |
| 51 | { |
| 52 | reset_timer_masked (); |
| 53 | } |
| 54 | |
| 55 | ulong get_timer (ulong base) |
| 56 | { |
wdenk | 3c71176 | 2004-06-09 13:37:52 +0000 | [diff] [blame] | 57 | return get_timer_masked () - base; |
wdenk | 32fe287 | 2002-10-11 07:57:01 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | void set_timer (ulong t) |
| 61 | { |
| 62 | /* nop */ |
| 63 | } |
| 64 | |
| 65 | void udelay (unsigned long usec) |
| 66 | { |
| 67 | udelay_masked (usec); |
| 68 | } |
| 69 | |
| 70 | |
| 71 | void reset_timer_masked (void) |
| 72 | { |
| 73 | OSCR = 0; |
| 74 | } |
| 75 | |
| 76 | ulong get_timer_masked (void) |
| 77 | { |
Micha Kalfon | 8a75a5b | 2009-02-11 19:50:11 +0200 | [diff] [blame^] | 78 | unsigned long long ticks = get_ticks(); |
| 79 | |
| 80 | return (((ticks / TIMER_FREQ_HZ) * 1000) + |
| 81 | ((ticks % TIMER_FREQ_HZ) * 1000) / TIMER_FREQ_HZ); |
wdenk | 32fe287 | 2002-10-11 07:57:01 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | void udelay_masked (unsigned long usec) |
| 85 | { |
| 86 | ulong tmo; |
wdenk | 7af1f9d | 2005-04-04 12:08:28 +0000 | [diff] [blame] | 87 | ulong endtime; |
| 88 | signed long diff; |
wdenk | 32fe287 | 2002-10-11 07:57:01 +0000 | [diff] [blame] | 89 | |
wdenk | ac40ade | 2004-11-24 23:35:19 +0000 | [diff] [blame] | 90 | if (usec >= 1000) { |
| 91 | tmo = usec / 1000; |
Micha Kalfon | 8a75a5b | 2009-02-11 19:50:11 +0200 | [diff] [blame^] | 92 | tmo *= TIMER_FREQ_HZ; |
wdenk | ac40ade | 2004-11-24 23:35:19 +0000 | [diff] [blame] | 93 | tmo /= 1000; |
| 94 | } else { |
Micha Kalfon | 8a75a5b | 2009-02-11 19:50:11 +0200 | [diff] [blame^] | 95 | tmo = usec * TIMER_FREQ_HZ; |
wdenk | ac40ade | 2004-11-24 23:35:19 +0000 | [diff] [blame] | 96 | tmo /= (1000*1000); |
| 97 | } |
wdenk | 32fe287 | 2002-10-11 07:57:01 +0000 | [diff] [blame] | 98 | |
Micha Kalfon | 8a75a5b | 2009-02-11 19:50:11 +0200 | [diff] [blame^] | 99 | endtime = get_ticks() + tmo; |
wdenk | 32fe287 | 2002-10-11 07:57:01 +0000 | [diff] [blame] | 100 | |
wdenk | 7af1f9d | 2005-04-04 12:08:28 +0000 | [diff] [blame] | 101 | do { |
Micha Kalfon | 8a75a5b | 2009-02-11 19:50:11 +0200 | [diff] [blame^] | 102 | ulong now = get_ticks(); |
wdenk | 7af1f9d | 2005-04-04 12:08:28 +0000 | [diff] [blame] | 103 | diff = endtime - now; |
| 104 | } while (diff >= 0); |
wdenk | 32fe287 | 2002-10-11 07:57:01 +0000 | [diff] [blame] | 105 | } |
wdenk | 49c3f67 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 106 | |
| 107 | /* |
| 108 | * This function is derived from PowerPC code (read timebase as long long). |
| 109 | * On ARM it just returns the timer value. |
| 110 | */ |
| 111 | unsigned long long get_ticks(void) |
| 112 | { |
Micha Kalfon | 8a75a5b | 2009-02-11 19:50:11 +0200 | [diff] [blame^] | 113 | return OSCR; |
wdenk | 49c3f67 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | /* |
| 117 | * This function is derived from PowerPC code (timebase clock frequency). |
| 118 | * On ARM it returns the number of timer ticks per second. |
| 119 | */ |
| 120 | ulong get_tbclk (void) |
| 121 | { |
| 122 | ulong tbclk; |
Micha Kalfon | 8a75a5b | 2009-02-11 19:50:11 +0200 | [diff] [blame^] | 123 | tbclk = TIMER_FREQ_HZ; |
wdenk | 49c3f67 | 2003-10-08 22:33:00 +0000 | [diff] [blame] | 124 | return tbclk; |
| 125 | } |