blob: da62502d6144e21ae375a935e4216bf06c211cc7 [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
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
wdenkcd0a9de2004-02-23 20:48:38 +000020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wdenkc6097192002-11-03 00:24:07 +000021 * 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 <clps7111.h>
wdenkc6097192002-11-03 00:24:07 +000031#include <asm/proc-armv/ptrace.h>
wdenk39539882004-07-01 16:30:44 +000032#include <asm/hardware.h>
wdenkc6097192002-11-03 00:24:07 +000033
wdenk2d1a5372004-02-23 19:30:57 +000034#ifndef CONFIG_NETARM
wdenkc6097192002-11-03 00:24:07 +000035/* we always count down the max. */
36#define TIMER_LOAD_VAL 0xffff
wdenkc6097192002-11-03 00:24:07 +000037/* macro to read the 16 bit timer */
38#define READ_TIMER (IO_TC1D & 0xffff)
wdenk2d1a5372004-02-23 19:30:57 +000039#else
40#define IRQEN (*(volatile unsigned int *)(NETARM_GEN_MODULE_BASE + NETARM_GEN_INTR_ENABLE))
wdenkcd0a9de2004-02-23 20:48:38 +000041#define TM2CTRL (*(volatile unsigned int *)(NETARM_GEN_MODULE_BASE + NETARM_GEN_TIMER2_CONTROL))
42#define TM2STAT (*(volatile unsigned int *)(NETARM_GEN_MODULE_BASE + NETARM_GEN_TIMER2_STATUS))
wdenk2d1a5372004-02-23 19:30:57 +000043#define TIMER_LOAD_VAL NETARM_GEN_TSTAT_CTC_MASK
44#define READ_TIMER (TM2STAT & NETARM_GEN_TSTAT_CTC_MASK)
45#endif
wdenkc6097192002-11-03 00:24:07 +000046
wdenka1f4a3d2004-07-11 22:19:26 +000047#ifdef CONFIG_S3C4510B
48/* require interrupts for the S3C4510B */
49# ifndef CONFIG_USE_IRQ
50# error CONFIG_USE_IRQ _must_ be defined when using CONFIG_S3C4510B
51# else
52static struct _irq_handler IRQ_HANDLER[N_IRQS];
53# endif
54#endif /* CONFIG_S3C4510B */
55
wdenkc6097192002-11-03 00:24:07 +000056#ifdef CONFIG_USE_IRQ
57/* enable IRQ/FIQ interrupts */
58void enable_interrupts (void)
59{
60 unsigned long temp;
61 __asm__ __volatile__("mrs %0, cpsr\n"
62 "bic %0, %0, #0x80\n"
63 "msr cpsr_c, %0"
64 : "=r" (temp)
65 :
66 : "memory");
67}
68
69
70/*
71 * disable IRQ/FIQ interrupts
72 * returns true if interrupts had been enabled before we disabled them
73 */
74int disable_interrupts (void)
75{
76 unsigned long old,temp;
77 __asm__ __volatile__("mrs %0, cpsr\n"
78 "orr %1, %0, #0x80\n"
79 "msr cpsr_c, %1"
80 : "=r" (old), "=r" (temp)
81 :
82 : "memory");
83 return (old & 0x80) == 0;
84}
wdenka1f4a3d2004-07-11 22:19:26 +000085#else /* CONFIG_USE_IRQ */
wdenkc6097192002-11-03 00:24:07 +000086void enable_interrupts (void)
87{
88 return;
89}
90int disable_interrupts (void)
91{
92 return 0;
93}
94#endif
95
wdenkc6097192002-11-03 00:24:07 +000096void bad_mode (void)
97{
98 panic ("Resetting CPU ...\n");
99 reset_cpu (0);
100}
101
102void show_regs (struct pt_regs *regs)
103{
104 unsigned long flags;
105 const char *processor_modes[] =
wdenk8bde7f72003-06-27 21:31:46 +0000106 { "USER_26", "FIQ_26", "IRQ_26", "SVC_26", "UK4_26", "UK5_26",
wdenkc6097192002-11-03 00:24:07 +0000107"UK6_26", "UK7_26",
108 "UK8_26", "UK9_26", "UK10_26", "UK11_26", "UK12_26", "UK13_26",
109 "UK14_26", "UK15_26",
110 "USER_32", "FIQ_32", "IRQ_32", "SVC_32", "UK4_32", "UK5_32",
111 "UK6_32", "ABT_32",
112 "UK8_32", "UK9_32", "UK10_32", "UND_32", "UK12_32", "UK13_32",
113 "UK14_32", "SYS_32"
114 };
115
116 flags = condition_codes (regs);
117
wdenkcd0a9de2004-02-23 20:48:38 +0000118 printf ("pc : [<%08lx>] lr : [<%08lx>]\n"
119 "sp : %08lx ip : %08lx fp : %08lx\n",
wdenkc6097192002-11-03 00:24:07 +0000120 instruction_pointer (regs),
121 regs->ARM_lr, regs->ARM_sp, regs->ARM_ip, regs->ARM_fp);
wdenkcd0a9de2004-02-23 20:48:38 +0000122 printf ("r10: %08lx r9 : %08lx r8 : %08lx\n",
wdenkc6097192002-11-03 00:24:07 +0000123 regs->ARM_r10, regs->ARM_r9, regs->ARM_r8);
wdenkcd0a9de2004-02-23 20:48:38 +0000124 printf ("r7 : %08lx r6 : %08lx r5 : %08lx r4 : %08lx\n",
wdenkc6097192002-11-03 00:24:07 +0000125 regs->ARM_r7, regs->ARM_r6, regs->ARM_r5, regs->ARM_r4);
wdenkcd0a9de2004-02-23 20:48:38 +0000126 printf ("r3 : %08lx r2 : %08lx r1 : %08lx r0 : %08lx\n",
wdenkc6097192002-11-03 00:24:07 +0000127 regs->ARM_r3, regs->ARM_r2, regs->ARM_r1, regs->ARM_r0);
128 printf ("Flags: %c%c%c%c",
129 flags & CC_N_BIT ? 'N' : 'n',
130 flags & CC_Z_BIT ? 'Z' : 'z',
131 flags & CC_C_BIT ? 'C' : 'c', flags & CC_V_BIT ? 'V' : 'v');
132 printf (" IRQs %s FIQs %s Mode %s%s\n",
133 interrupts_enabled (regs) ? "on" : "off",
134 fast_interrupts_enabled (regs) ? "on" : "off",
135 processor_modes[processor_mode (regs)],
136 thumb_mode (regs) ? " (T)" : "");
137}
138
139void do_undefined_instruction (struct pt_regs *pt_regs)
140{
141 printf ("undefined instruction\n");
142 show_regs (pt_regs);
143 bad_mode ();
144}
145
146void do_software_interrupt (struct pt_regs *pt_regs)
147{
148 printf ("software interrupt\n");
149 show_regs (pt_regs);
150 bad_mode ();
151}
152
153void do_prefetch_abort (struct pt_regs *pt_regs)
154{
155 printf ("prefetch abort\n");
156 show_regs (pt_regs);
157 bad_mode ();
158}
159
160void do_data_abort (struct pt_regs *pt_regs)
161{
162 printf ("data abort\n");
163 show_regs (pt_regs);
164 bad_mode ();
165}
166
167void do_not_used (struct pt_regs *pt_regs)
168{
169 printf ("not used\n");
170 show_regs (pt_regs);
171 bad_mode ();
172}
173
174void do_fiq (struct pt_regs *pt_regs)
175{
176 printf ("fast interrupt request\n");
177 show_regs (pt_regs);
178 bad_mode ();
179}
180
181void do_irq (struct pt_regs *pt_regs)
182{
Wolfgang Denkc570b2f2005-09-26 01:06:33 +0200183#if defined(CONFIG_IMPA7) || defined(CONFIG_EP7312) || defined(CONFIG_NETARM) || defined(CONFIG_ARMADILLO)
wdenkc6097192002-11-03 00:24:07 +0000184 printf ("interrupt request\n");
185 show_regs (pt_regs);
186 bad_mode ();
wdenka1f4a3d2004-07-11 22:19:26 +0000187#elif defined(CONFIG_S3C4510B)
188 unsigned int pending;
189
190 while ( (pending = GET_REG( REG_INTOFFSET)) != 0x54) { /* sentinal value for no pending interrutps */
191 IRQ_HANDLER[pending>>2].m_func( IRQ_HANDLER[pending>>2].m_data);
192
193 /* clear pending interrupt */
194 PUT_REG( REG_INTPEND, (1<<(pending>>2)));
195 }
Wolfgang Denk87cb6862005-10-06 17:08:18 +0200196#elif defined(CONFIG_INTEGRATOR) && defined(CONFIG_ARCH_INTEGRATOR)
197 /* No do_irq() for IntegratorAP/CM720T as yet */
wdenka1f4a3d2004-07-11 22:19:26 +0000198#else
199#error do_irq() not defined for this CPU type
200#endif
wdenkc6097192002-11-03 00:24:07 +0000201}
202
wdenka1f4a3d2004-07-11 22:19:26 +0000203
204#ifdef CONFIG_S3C4510B
205static void default_isr( void *data) {
206 printf ("default_isr(): called for IRQ %d\n", (int)data);
207}
208
209static void timer_isr( void *data) {
210 unsigned int *pTime = (unsigned int *)data;
211
212 (*pTime)++;
213 if ( !(*pTime % (CFG_HZ/4))) {
214 /* toggle LED 0 */
215 PUT_REG( REG_IOPDATA, GET_REG(REG_IOPDATA) ^ 0x1);
216 }
217
218}
219#endif
220
Wolfgang Denk87cb6862005-10-06 17:08:18 +0200221#if defined(CONFIG_INTEGRATOR) && defined(CONFIG_ARCH_INTEGRATOR)
222 /* Use IntegratorAP routines in board/integratorap.c */
223#else
224
Wolfgang Denk96782c62005-10-09 00:22:48 +0200225static ulong timestamp;
226static ulong lastdec;
227
wdenkc6097192002-11-03 00:24:07 +0000228int interrupt_init (void)
229{
wdenk39539882004-07-01 16:30:44 +0000230
231#if defined(CONFIG_NETARM)
wdenkcd0a9de2004-02-23 20:48:38 +0000232 /* disable all interrupts */
wdenk2d1a5372004-02-23 19:30:57 +0000233 IRQEN = 0;
234
235 /* operate timer 2 in non-prescale mode */
236 TM2CTRL = ( NETARM_GEN_TIMER_SET_HZ(CFG_HZ) |
237 NETARM_GEN_TCTL_ENABLE |
238 NETARM_GEN_TCTL_INIT_COUNT(TIMER_LOAD_VAL));
239
240 /* set timer 2 counter */
241 lastdec = TIMER_LOAD_VAL;
Wolfgang Denkc570b2f2005-09-26 01:06:33 +0200242#elif defined(CONFIG_IMPA7) || defined(CONFIG_EP7312) || defined(CONFIG_ARMADILLO)
wdenkc6097192002-11-03 00:24:07 +0000243 /* disable all interrupts */
244 IO_INTMR1 = 0;
245
246 /* operate timer 1 in prescale mode */
247 IO_SYSCON1 |= SYSCON1_TC1M;
248
249 /* select 2kHz clock source for timer 1 */
250 IO_SYSCON1 &= ~SYSCON1_TC1S;
251
252 /* set timer 1 counter */
253 lastdec = IO_TC1D = TIMER_LOAD_VAL;
wdenk39539882004-07-01 16:30:44 +0000254#elif defined(CONFIG_S3C4510B)
wdenka1f4a3d2004-07-11 22:19:26 +0000255 int i;
256
257 /* install default interrupt handlers */
258 for ( i = 0; i < N_IRQS; i++) {
259 IRQ_HANDLER[i].m_data = (void *)i;
260 IRQ_HANDLER[i].m_func = default_isr;
261 }
262
263 /* configure interrupts for IRQ mode */
264 PUT_REG( REG_INTMODE, 0x0);
265 /* clear any pending interrupts */
266 PUT_REG( REG_INTPEND, 0x1FFFFF);
267
wdenk39539882004-07-01 16:30:44 +0000268 lastdec = 0;
wdenka1f4a3d2004-07-11 22:19:26 +0000269
270 /* install interrupt handler for timer */
271 IRQ_HANDLER[INT_TIMER0].m_data = (void *)&timestamp;
272 IRQ_HANDLER[INT_TIMER0].m_func = timer_isr;
273
274 /* configure free running timer 0 */
275 PUT_REG( REG_TMOD, 0x0);
276 /* Stop timer 0 */
277 CLR_REG( REG_TMOD, TM0_RUN);
278
279 /* Configure for interval mode */
280 CLR_REG( REG_TMOD, TM1_TOGGLE);
281
282 /*
283 * Load Timer data register with count down value.
284 * count_down_val = CFG_SYS_CLK_FREQ/CFG_HZ
285 */
286 PUT_REG( REG_TDATA0, (CFG_SYS_CLK_FREQ / CFG_HZ));
287
288 /*
289 * Enable global interrupt
290 * Enable timer0 interrupt
291 */
292 CLR_REG( REG_INTMASK, ((1<<INT_GLOBAL) | (1<<INT_TIMER0)));
293
294 /* Start timer */
295 SET_REG( REG_TMOD, TM0_RUN);
296
wdenk39539882004-07-01 16:30:44 +0000297#else
298#error No interrupt_init() defined for this CPU type
wdenk2d1a5372004-02-23 19:30:57 +0000299#endif
wdenkc6097192002-11-03 00:24:07 +0000300 timestamp = 0;
301
302 return (0);
303}
304
Wolfgang Denk87cb6862005-10-06 17:08:18 +0200305#endif /* ! IntegratorAP */
306
wdenkc6097192002-11-03 00:24:07 +0000307/*
308 * timer without interrupts
309 */
310
wdenk39539882004-07-01 16:30:44 +0000311
Wolfgang Denkc570b2f2005-09-26 01:06:33 +0200312#if defined(CONFIG_IMPA7) || defined(CONFIG_EP7312) || defined(CONFIG_NETARM) || defined(CONFIG_ARMADILLO)
wdenk39539882004-07-01 16:30:44 +0000313
wdenkc6097192002-11-03 00:24:07 +0000314void reset_timer (void)
315{
316 reset_timer_masked ();
317}
318
319ulong get_timer (ulong base)
320{
321 return get_timer_masked () - base;
322}
323
324void set_timer (ulong t)
325{
326 timestamp = t;
327}
328
329void udelay (unsigned long usec)
330{
331 ulong tmo;
332
333 tmo = usec / 1000;
334 tmo *= CFG_HZ;
335 tmo /= 1000;
336
337 tmo += get_timer (0);
338
339 while (get_timer_masked () < tmo)
340 /*NOP*/;
341}
342
343void reset_timer_masked (void)
344{
345 /* reset time */
346 lastdec = READ_TIMER;
347 timestamp = 0;
348}
349
350ulong get_timer_masked (void)
351{
352 ulong now = READ_TIMER;
353
354 if (lastdec >= now) {
355 /* normal mode */
356 timestamp += lastdec - now;
357 } else {
358 /* we have an overflow ... */
359 timestamp += lastdec + TIMER_LOAD_VAL - now;
360 }
361 lastdec = now;
362
363 return timestamp;
364}
365
366void udelay_masked (unsigned long usec)
367{
368 ulong tmo;
wdenk101e8df2005-04-04 12:08:28 +0000369 ulong endtime;
370 signed long diff;
wdenkc6097192002-11-03 00:24:07 +0000371
wdenk101e8df2005-04-04 12:08:28 +0000372 if (usec >= 1000) {
373 tmo = usec / 1000;
374 tmo *= CFG_HZ;
375 tmo /= 1000;
376 } else {
377 tmo = usec * CFG_HZ;
378 tmo /= (1000*1000);
379 }
wdenkc6097192002-11-03 00:24:07 +0000380
wdenk101e8df2005-04-04 12:08:28 +0000381 endtime = get_timer_masked () + tmo;
wdenkc6097192002-11-03 00:24:07 +0000382
wdenk101e8df2005-04-04 12:08:28 +0000383 do {
384 ulong now = get_timer_masked ();
385 diff = endtime - now;
386 } while (diff >= 0);
wdenkc6097192002-11-03 00:24:07 +0000387}
wdenk39539882004-07-01 16:30:44 +0000388
389#elif defined(CONFIG_S3C4510B)
390
wdenka1f4a3d2004-07-11 22:19:26 +0000391ulong get_timer (ulong base)
392{
393 return timestamp - base;
394}
wdenk39539882004-07-01 16:30:44 +0000395
396void udelay (unsigned long usec)
397{
wdenka1f4a3d2004-07-11 22:19:26 +0000398 u32 ticks;
wdenk39539882004-07-01 16:30:44 +0000399
wdenka1f4a3d2004-07-11 22:19:26 +0000400 ticks = (usec * CFG_HZ) / 1000000;
wdenk39539882004-07-01 16:30:44 +0000401
wdenka1f4a3d2004-07-11 22:19:26 +0000402 ticks += get_timer (0);
wdenk39539882004-07-01 16:30:44 +0000403
wdenka1f4a3d2004-07-11 22:19:26 +0000404 while (get_timer (0) < ticks)
405 /*NOP*/;
wdenk39539882004-07-01 16:30:44 +0000406
wdenk39539882004-07-01 16:30:44 +0000407}
408
Wolfgang Denk87cb6862005-10-06 17:08:18 +0200409#elif defined(CONFIG_INTEGRATOR) && defined(CONFIG_ARCH_INTEGRATOR)
410 /* No timer routines for IntegratorAP/CM720T as yet */
wdenk39539882004-07-01 16:30:44 +0000411#else
412#error Timer routines not defined for this CPU type
413#endif