blob: 78800611a3c49030f6c3a81c8bc15a0c82d8513a [file] [log] [blame]
Aubrey Li51185db2007-03-20 18:16:24 +08001/*
2 * U-boot - interrupts.c Interrupt related routines
3 *
Aubrey Li314d22f2007-04-05 18:31:18 +08004 * Copyright (c) 2005-2007 Analog Devices Inc.
Aubrey Li51185db2007-03-20 18:16:24 +08005 *
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>,
13 * BuyWays B.V. (www.buyways.nl)
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
Aubrey Li314d22f2007-04-05 18:31:18 +080033 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
34 * MA 02110-1301 USA
Aubrey Li51185db2007-03-20 18:16:24 +080035 */
36
37#include <common.h>
Aubrey Li51185db2007-03-20 18:16:24 +080038#include <config.h>
39#include <asm/blackfin.h>
40#include "cpu.h"
41
42static ulong timestamp;
43static ulong last_time;
44static int int_flag;
45
46int irq_flags; /* needed by asm-blackfin/system.h */
47
48/* Functions just to satisfy the linker */
49
50/*
51 * This function is derived from PowerPC code (read timebase as long long).
52 * On BF561 it just returns the timer value.
53 */
54unsigned long long get_ticks(void)
55{
56 return get_timer(0);
57}
58
59/*
60 * This function is derived from PowerPC code (timebase clock frequency).
61 * On BF561 it returns the number of timer ticks per second.
62 */
63ulong get_tbclk(void)
64{
65 ulong tbclk;
66
67 tbclk = CFG_HZ;
68 return tbclk;
69}
70
71void enable_interrupts(void)
72{
Aubrey Li51185db2007-03-20 18:16:24 +080073}
74
75int disable_interrupts(void)
76{
Aubrey Li51185db2007-03-20 18:16:24 +080077 return 1;
78}
79
80int interrupt_init(void)
81{
82 return (0);
83}
84
85void udelay(unsigned long usec)
86{
87 unsigned long delay, start, stop;
88 unsigned long cclk;
89 cclk = (CONFIG_CCLK_HZ);
90
91 while (usec > 1) {
92 /*
93 * how many clock ticks to delay?
94 * - request(in useconds) * clock_ticks(Hz) / useconds/second
95 */
96 if (usec < 1000) {
97 delay = (usec * (cclk / 244)) >> 12;
98 usec = 0;
99 } else {
100 delay = (1000 * (cclk / 244)) >> 12;
101 usec -= 1000;
102 }
103
104 asm volatile (" %0 = CYCLES;":"=r" (start));
105 do {
106 asm volatile (" %0 = CYCLES; ":"=r" (stop));
107 } while (stop - start < delay);
108 }
109
110 return;
111}
112
113void timer_init(void)
114{
115 *pTCNTL = 0x1;
116 *pTSCALE = 0x0;
117 *pTCOUNT = MAX_TIM_LOAD;
118 *pTPERIOD = MAX_TIM_LOAD;
119 *pTCNTL = 0x7;
120 asm("CSYNC;");
121
122 timestamp = 0;
123 last_time = 0;
124}
125
126/*
127 * Any network command or flash
128 * command is started get_timer shall
129 * be called before TCOUNT gets reset,
130 * to implement the accurate timeouts.
131 *
132 * How ever milliconds doesn't return
133 * the number that has been elapsed from
134 * the last reset.
135 *
136 * As get_timer is used in the u-boot
137 * only for timeouts this should be
138 * sufficient
139 */
140ulong get_timer(ulong base)
141{
142 ulong milisec;
143
144 /* Number of clocks elapsed */
145 ulong clocks = (MAX_TIM_LOAD - (*pTCOUNT));
146
147 /*
148 * Find if the TCOUNT is reset
149 * timestamp gives the number of times
150 * TCOUNT got reset
151 */
152 if (clocks < last_time)
153 timestamp++;
154 last_time = clocks;
155
156 /* Get the number of milliseconds */
157 milisec = clocks / (CONFIG_CCLK_HZ / 1000);
158
159 /*
160 * Find the number of millisonds
161 * that got elapsed before this TCOUNT
162 * cycle
163 */
164 milisec += timestamp * (MAX_TIM_LOAD / (CONFIG_CCLK_HZ / 1000));
165
166 return (milisec - base);
167}