Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 1 | /* |
| 2 | * U-boot - interrupts.c Interrupt related routines |
| 3 | * |
| 4 | * Copyright (c) 2005 blackfin.uclinux.org |
| 5 | * |
| 6 | * This file is based on interrupts.c |
| 7 | * Copyright 1996 Roman Zippel |
| 8 | * Copyright 1999 D. Jeff Dionne <jeff@uclinux.org> |
| 9 | * Copyright 2000-2001 Lineo, Inc. D. Jefff Dionne <jeff@lineo.ca> |
| 10 | * Copyright 2002 Arcturus Networks Inc. MaTed <mated@sympatico.ca> |
| 11 | * Copyright 2003 Metrowerks/Motorola |
| 12 | * Copyright 2003 Bas Vermeulen <bas@buyways.nl>, |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame^] | 13 | * BuyWays B.V. (www.buyways.nl) |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 14 | * |
| 15 | * (C) Copyright 2000-2004 |
| 16 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 17 | |
| 18 | * See file CREDITS for list of people who contributed to this |
| 19 | * project. |
| 20 | * |
| 21 | * This program is free software; you can redistribute it and/or |
| 22 | * modify it under the terms of the GNU General Public License as |
| 23 | * published by the Free Software Foundation; either version 2 of |
| 24 | * the License, or (at your option) any later version. |
| 25 | * |
| 26 | * This program is distributed in the hope that it will be useful, |
| 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 29 | * GNU General Public License for more details. |
| 30 | * |
| 31 | * You should have received a copy of the GNU General Public License |
| 32 | * along with this program; if not, write to the Free Software |
| 33 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 34 | * MA 02111-1307 USA |
| 35 | */ |
| 36 | |
| 37 | #include <common.h> |
| 38 | #include <asm/machdep.h> |
| 39 | #include <asm/irq.h> |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame^] | 40 | #include <config.h> |
| 41 | #include <asm/blackfin.h> |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 42 | #include "cpu.h" |
| 43 | |
| 44 | static ulong timestamp; |
| 45 | static ulong last_time; |
| 46 | static int int_flag; |
| 47 | |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame^] | 48 | int irq_flags; /* needed by asm-blackfin/system.h */ |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 49 | |
| 50 | /* Functions just to satisfy the linker */ |
| 51 | |
| 52 | /* |
| 53 | * This function is derived from PowerPC code (read timebase as long long). |
| 54 | * On BF533 it just returns the timer value. |
| 55 | */ |
| 56 | unsigned long long get_ticks(void) |
| 57 | { |
| 58 | return get_timer(0); |
| 59 | } |
| 60 | |
| 61 | /* |
| 62 | * This function is derived from PowerPC code (timebase clock frequency). |
| 63 | * On BF533 it returns the number of timer ticks per second. |
| 64 | */ |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame^] | 65 | ulong get_tbclk(void) |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 66 | { |
| 67 | ulong tbclk; |
| 68 | |
| 69 | tbclk = CFG_HZ; |
| 70 | return tbclk; |
| 71 | } |
| 72 | |
| 73 | void enable_interrupts(void) |
| 74 | { |
| 75 | restore_flags(int_flag); |
| 76 | } |
| 77 | |
| 78 | int disable_interrupts(void) |
| 79 | { |
| 80 | save_and_cli(int_flag); |
| 81 | return 1; |
| 82 | } |
| 83 | |
| 84 | int interrupt_init(void) |
| 85 | { |
| 86 | return (0); |
| 87 | } |
| 88 | |
| 89 | void udelay(unsigned long usec) |
| 90 | { |
| 91 | unsigned long delay, start, stop; |
| 92 | unsigned long cclk; |
| 93 | cclk = (CONFIG_CCLK_HZ); |
| 94 | |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame^] | 95 | while (usec > 1) { |
| 96 | /* |
| 97 | * how many clock ticks to delay? |
| 98 | * - request(in useconds) * clock_ticks(Hz) / useconds/second |
| 99 | */ |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 100 | if (usec < 1000) { |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame^] | 101 | delay = (usec * (cclk / 244)) >> 12; |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 102 | usec = 0; |
| 103 | } else { |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame^] | 104 | delay = (1000 * (cclk / 244)) >> 12; |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 105 | usec -= 1000; |
| 106 | } |
| 107 | |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame^] | 108 | asm volatile (" %0 = CYCLES;":"=r" (start)); |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 109 | do { |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame^] | 110 | asm volatile (" %0 = CYCLES; ":"=r" (stop)); |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 111 | } while (stop - start < delay); |
| 112 | } |
| 113 | |
| 114 | return; |
| 115 | } |
| 116 | |
| 117 | void timer_init(void) |
| 118 | { |
| 119 | *pTCNTL = 0x1; |
| 120 | *pTSCALE = 0x0; |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame^] | 121 | *pTCOUNT = MAX_TIM_LOAD; |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 122 | *pTPERIOD = MAX_TIM_LOAD; |
| 123 | *pTCNTL = 0x7; |
| 124 | asm("CSYNC;"); |
| 125 | |
| 126 | timestamp = 0; |
| 127 | last_time = 0; |
| 128 | } |
| 129 | |
| 130 | /* Any network command or flash |
| 131 | * command is started get_timer shall |
| 132 | * be called before TCOUNT gets reset, |
| 133 | * to implement the accurate timeouts. |
| 134 | * |
| 135 | * How ever milliconds doesn't return |
| 136 | * the number that has been elapsed from |
| 137 | * the last reset. |
| 138 | * |
| 139 | * As get_timer is used in the u-boot |
| 140 | * only for timeouts this should be |
| 141 | * sufficient |
| 142 | */ |
| 143 | ulong get_timer(ulong base) |
| 144 | { |
| 145 | ulong milisec; |
| 146 | |
| 147 | /* Number of clocks elapsed */ |
| 148 | ulong clocks = (MAX_TIM_LOAD - (*pTCOUNT)); |
| 149 | |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame^] | 150 | /** |
| 151 | * Find if the TCOUNT is reset |
| 152 | * timestamp gives the number of times |
| 153 | * TCOUNT got reset |
| 154 | */ |
| 155 | if (clocks < last_time) |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 156 | timestamp++; |
| 157 | last_time = clocks; |
| 158 | |
| 159 | /* Get the number of milliseconds */ |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame^] | 160 | milisec = clocks / (CONFIG_CCLK_HZ / 1000); |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 161 | |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame^] | 162 | /** |
| 163 | * Find the number of millisonds |
| 164 | * that got elapsed before this TCOUNT cycle |
| 165 | */ |
| 166 | milisec += timestamp * (MAX_TIM_LOAD / (CONFIG_CCLK_HZ / 1000)); |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 167 | |
| 168 | return (milisec - base); |
| 169 | } |