wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 1 | /* |
Wolfgang Denk | 4646d2a | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 2 | * (C) Copyright 2006 |
| 3 | * Stefan Roese, DENX Software Engineering, sr@denx.de. |
| 4 | * |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 5 | * (C) Copyright 2002 |
| 6 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 7 | * Marius Groeger <mgroeger@sysgo.de> |
| 8 | * |
| 9 | * (C) Copyright 2002 |
| 10 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 11 | * Alex Zuepke <azu@sysgo.de> |
| 12 | * |
| 13 | * See file CREDITS for list of people who contributed to this |
| 14 | * project. |
| 15 | * |
| 16 | * This program is free software; you can redistribute it and/or |
| 17 | * modify it under the terms of the GNU General Public License as |
| 18 | * published by the Free Software Foundation; either version 2 of |
| 19 | * the License, or (at your option) any later version. |
| 20 | * |
| 21 | * This program is distributed in the hope that it will be useful, |
| 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 | * GNU General Public License for more details. |
| 25 | * |
| 26 | * You should have received a copy of the GNU General Public License |
| 27 | * along with this program; if not, write to the Free Software |
| 28 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 29 | * MA 02111-1307 USA |
| 30 | */ |
| 31 | |
| 32 | #include <common.h> |
| 33 | #include <asm/arch/ixp425.h> |
| 34 | |
wdenk | 655a0f9 | 2003-10-30 21:49:38 +0000 | [diff] [blame] | 35 | ulong get_timer (ulong base) |
| 36 | { |
| 37 | return get_timer_masked () - base; |
| 38 | } |
| 39 | |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 40 | void ixp425_udelay(unsigned long usec) |
| 41 | { |
| 42 | /* |
| 43 | * This function has a max usec, but since it is called from udelay |
| 44 | * we should not have to worry... be happy |
| 45 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 46 | unsigned long usecs = CONFIG_SYS_HZ/1000000L & ~IXP425_OST_RELOAD_MASK; |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 47 | |
| 48 | *IXP425_OSST = IXP425_OSST_TIMER_1_PEND; |
| 49 | usecs |= IXP425_OST_ONE_SHOT | IXP425_OST_ENABLE; |
| 50 | *IXP425_OSRT1 = usecs; |
| 51 | while (!(*IXP425_OSST & IXP425_OSST_TIMER_1_PEND)); |
| 52 | } |
| 53 | |
| 54 | void udelay (unsigned long usec) |
| 55 | { |
| 56 | while (usec--) ixp425_udelay(1); |
| 57 | } |
| 58 | |
| 59 | static ulong reload_constant = 0xfffffff0; |
| 60 | |
| 61 | void reset_timer_masked (void) |
| 62 | { |
| 63 | ulong reload = reload_constant | IXP425_OST_ONE_SHOT | IXP425_OST_ENABLE; |
| 64 | |
| 65 | *IXP425_OSST = IXP425_OSST_TIMER_1_PEND; |
| 66 | *IXP425_OSRT1 = reload; |
| 67 | } |
| 68 | |
| 69 | ulong get_timer_masked (void) |
| 70 | { |
| 71 | /* |
| 72 | * Note that it is possible for this to wrap! |
| 73 | * In this case we return max. |
| 74 | */ |
| 75 | ulong current = *IXP425_OST1; |
| 76 | if (*IXP425_OSST & IXP425_OSST_TIMER_1_PEND) |
| 77 | { |
| 78 | return reload_constant; |
| 79 | } |
| 80 | return (reload_constant - current); |
| 81 | } |