3 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
4 * Marius Groeger <mgroeger@sysgo.de>
7 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
8 * Alex Zuepke <azu@sysgo.de>
10 * See file CREDITS for list of people who contributed to this
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.
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.
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,
31 #include <asm/proc-armv/ptrace.h>
32 #include <asm/hardware.h>
35 /* we always count down the max. */
36 #define TIMER_LOAD_VAL 0xffff
37 /* macro to read the 16 bit timer */
38 #define READ_TIMER (IO_TC1D & 0xffff)
40 #define IRQEN (*(volatile unsigned int *)(NETARM_GEN_MODULE_BASE + NETARM_GEN_INTR_ENABLE))
41 #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))
43 #define TIMER_LOAD_VAL NETARM_GEN_TSTAT_CTC_MASK
44 #define READ_TIMER (TM2STAT & NETARM_GEN_TSTAT_CTC_MASK)
47 #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
52 static struct _irq_handler IRQ_HANDLER[N_IRQS];
54 #endif /* CONFIG_S3C4510B */
57 /* enable IRQ/FIQ interrupts */
58 void enable_interrupts (void)
61 __asm__ __volatile__("mrs %0, cpsr\n"
71 * disable IRQ/FIQ interrupts
72 * returns true if interrupts had been enabled before we disabled them
74 int disable_interrupts (void)
76 unsigned long old,temp;
77 __asm__ __volatile__("mrs %0, cpsr\n"
80 : "=r" (old), "=r" (temp)
83 return (old & 0x80) == 0;
85 #else /* CONFIG_USE_IRQ */
86 void enable_interrupts (void)
90 int disable_interrupts (void)
98 panic ("Resetting CPU ...\n");
102 void show_regs (struct pt_regs *regs)
105 const char *processor_modes[] =
106 { "USER_26", "FIQ_26", "IRQ_26", "SVC_26", "UK4_26", "UK5_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",
112 "UK8_32", "UK9_32", "UK10_32", "UND_32", "UK12_32", "UK13_32",
116 flags = condition_codes (regs);
118 printf ("pc : [<%08lx>] lr : [<%08lx>]\n"
119 "sp : %08lx ip : %08lx fp : %08lx\n",
120 instruction_pointer (regs),
121 regs->ARM_lr, regs->ARM_sp, regs->ARM_ip, regs->ARM_fp);
122 printf ("r10: %08lx r9 : %08lx r8 : %08lx\n",
123 regs->ARM_r10, regs->ARM_r9, regs->ARM_r8);
124 printf ("r7 : %08lx r6 : %08lx r5 : %08lx r4 : %08lx\n",
125 regs->ARM_r7, regs->ARM_r6, regs->ARM_r5, regs->ARM_r4);
126 printf ("r3 : %08lx r2 : %08lx r1 : %08lx r0 : %08lx\n",
127 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)" : "");
139 void do_undefined_instruction (struct pt_regs *pt_regs)
141 printf ("undefined instruction\n");
146 void do_software_interrupt (struct pt_regs *pt_regs)
148 printf ("software interrupt\n");
153 void do_prefetch_abort (struct pt_regs *pt_regs)
155 printf ("prefetch abort\n");
160 void do_data_abort (struct pt_regs *pt_regs)
162 printf ("data abort\n");
167 void do_not_used (struct pt_regs *pt_regs)
169 printf ("not used\n");
174 void do_fiq (struct pt_regs *pt_regs)
176 printf ("fast interrupt request\n");
181 void do_irq (struct pt_regs *pt_regs)
183 #if defined(CONFIG_IMPA7) || defined(CONFIG_EP7312) || defined(CONFIG_NETARM) || defined(CONFIG_ARMADILLO)
184 printf ("interrupt request\n");
187 #elif defined(CONFIG_S3C4510B)
188 unsigned int pending;
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);
193 /* clear pending interrupt */
194 PUT_REG( REG_INTPEND, (1<<(pending>>2)));
196 #elif defined(CONFIG_INTEGRATOR) && defined(CONFIG_ARCH_INTEGRATOR)
197 /* No do_irq() for IntegratorAP/CM720T as yet */
199 #error do_irq() not defined for this CPU type
204 #ifdef CONFIG_S3C4510B
205 static void default_isr( void *data) {
206 printf ("default_isr(): called for IRQ %d\n", (int)data);
209 static void timer_isr( void *data) {
210 unsigned int *pTime = (unsigned int *)data;
213 if ( !(*pTime % (CFG_HZ/4))) {
215 PUT_REG( REG_IOPDATA, GET_REG(REG_IOPDATA) ^ 0x1);
221 static ulong timestamp;
222 static ulong lastdec;
224 #if defined(CONFIG_INTEGRATOR) && defined(CONFIG_ARCH_INTEGRATOR)
225 /* Use IntegratorAP routines in board/integratorap.c */
228 int interrupt_init (void)
231 #if defined(CONFIG_NETARM)
232 /* disable all interrupts */
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));
240 /* set timer 2 counter */
241 lastdec = TIMER_LOAD_VAL;
242 #elif defined(CONFIG_IMPA7) || defined(CONFIG_EP7312) || defined(CONFIG_ARMADILLO)
243 /* disable all interrupts */
246 /* operate timer 1 in prescale mode */
247 IO_SYSCON1 |= SYSCON1_TC1M;
249 /* select 2kHz clock source for timer 1 */
250 IO_SYSCON1 &= ~SYSCON1_TC1S;
252 /* set timer 1 counter */
253 lastdec = IO_TC1D = TIMER_LOAD_VAL;
254 #elif defined(CONFIG_S3C4510B)
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;
263 /* configure interrupts for IRQ mode */
264 PUT_REG( REG_INTMODE, 0x0);
265 /* clear any pending interrupts */
266 PUT_REG( REG_INTPEND, 0x1FFFFF);
270 /* install interrupt handler for timer */
271 IRQ_HANDLER[INT_TIMER0].m_data = (void *)×tamp;
272 IRQ_HANDLER[INT_TIMER0].m_func = timer_isr;
274 /* configure free running timer 0 */
275 PUT_REG( REG_TMOD, 0x0);
277 CLR_REG( REG_TMOD, TM0_RUN);
279 /* Configure for interval mode */
280 CLR_REG( REG_TMOD, TM1_TOGGLE);
283 * Load Timer data register with count down value.
284 * count_down_val = CFG_SYS_CLK_FREQ/CFG_HZ
286 PUT_REG( REG_TDATA0, (CFG_SYS_CLK_FREQ / CFG_HZ));
289 * Enable global interrupt
290 * Enable timer0 interrupt
292 CLR_REG( REG_INTMASK, ((1<<INT_GLOBAL) | (1<<INT_TIMER0)));
295 SET_REG( REG_TMOD, TM0_RUN);
298 #error No interrupt_init() defined for this CPU type
305 #endif /* ! IntegratorAP */
308 * timer without interrupts
312 #if defined(CONFIG_IMPA7) || defined(CONFIG_EP7312) || defined(CONFIG_NETARM) || defined(CONFIG_ARMADILLO)
314 void reset_timer (void)
316 reset_timer_masked ();
319 ulong get_timer (ulong base)
321 return get_timer_masked () - base;
324 void set_timer (ulong t)
329 void udelay (unsigned long usec)
337 tmo += get_timer (0);
339 while (get_timer_masked () < tmo)
343 void reset_timer_masked (void)
346 lastdec = READ_TIMER;
350 ulong get_timer_masked (void)
352 ulong now = READ_TIMER;
354 if (lastdec >= now) {
356 timestamp += lastdec - now;
358 /* we have an overflow ... */
359 timestamp += lastdec + TIMER_LOAD_VAL - now;
366 void udelay_masked (unsigned long usec)
381 endtime = get_timer_masked () + tmo;
384 ulong now = get_timer_masked ();
385 diff = endtime - now;
389 #elif defined(CONFIG_S3C4510B)
391 ulong get_timer (ulong base)
393 return timestamp - base;
396 void udelay (unsigned long usec)
400 ticks = (usec * CFG_HZ) / 1000000;
402 ticks += get_timer (0);
404 while (get_timer (0) < ticks)
409 #elif defined(CONFIG_INTEGRATOR) && defined(CONFIG_ARCH_INTEGRATOR)
410 /* No timer routines for IntegratorAP/CM720T as yet */
412 #error Timer routines not defined for this CPU type