blob: 3bbd2c68e9b843738e151fa17c1acb312e78a347 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* irq.c: FRV IRQ handling
2 *
David Howells1bcbba32006-09-25 23:32:04 -07003 * Copyright (C) 2003, 2004, 2006 Red Hat, Inc. All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/ptrace.h>
13#include <linux/errno.h>
14#include <linux/signal.h>
15#include <linux/sched.h>
16#include <linux/ioport.h>
17#include <linux/interrupt.h>
18#include <linux/timex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/random.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/init.h>
21#include <linux/kernel_stat.h>
22#include <linux/irq.h>
23#include <linux/proc_fs.h>
24#include <linux/seq_file.h>
David Howells40234402006-01-08 01:01:19 -080025#include <linux/module.h>
Jiri Slaby1977f032007-10-18 23:40:25 -070026#include <linux/bitops.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28#include <asm/atomic.h>
29#include <asm/io.h>
30#include <asm/smp.h>
31#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <asm/uaccess.h>
33#include <asm/pgalloc.h>
34#include <asm/delay.h>
35#include <asm/irq.h>
36#include <asm/irc-regs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <asm/gdb-stub.h>
38
David Howells1bcbba32006-09-25 23:32:04 -070039#define set_IRR(N,A,B,C,D) __set_IRR(N, (A << 28) | (B << 24) | (C << 20) | (D << 16))
40
Linus Torvalds1da177e2005-04-16 15:20:36 -070041extern void __init fpga_init(void);
David Howells1bcbba32006-09-25 23:32:04 -070042#ifdef CONFIG_FUJITSU_MB93493
43extern void __init mb93493_init(void);
44#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
David Howells1bcbba32006-09-25 23:32:04 -070046#define __reg16(ADDR) (*(volatile unsigned short *)(ADDR))
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
48atomic_t irq_err_count;
49
50/*
51 * Generic, controller-independent functions:
52 */
53int show_interrupts(struct seq_file *p, void *v)
54{
David Howells1bcbba32006-09-25 23:32:04 -070055 int i = *(loff_t *) v, cpu;
56 struct irqaction * action;
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
David Howells1bcbba32006-09-25 23:32:04 -070059 if (i == 0) {
60 char cpuname[12];
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
David Howells1bcbba32006-09-25 23:32:04 -070062 seq_printf(p, " ");
63 for_each_present_cpu(cpu) {
64 sprintf(cpuname, "CPU%d", cpu);
65 seq_printf(p, " %10s", cpuname);
66 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 seq_putc(p, '\n');
David Howells1bcbba32006-09-25 23:32:04 -070068 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
David Howells1bcbba32006-09-25 23:32:04 -070070 if (i < NR_IRQS) {
Thomas Gleixner239007b2009-11-17 16:46:45 +010071 raw_spin_lock_irqsave(&irq_desc[i].lock, flags);
David Howells1bcbba32006-09-25 23:32:04 -070072 action = irq_desc[i].action;
73 if (action) {
74 seq_printf(p, "%3d: ", i);
75 for_each_present_cpu(cpu)
Yinghai Ludee41022009-01-11 00:29:15 -080076 seq_printf(p, "%10u ", kstat_irqs_cpu(i, cpu));
David Howells1bcbba32006-09-25 23:32:04 -070077 seq_printf(p, " %10s", irq_desc[i].chip->name ? : "-");
78 seq_printf(p, " %s", action->name);
79 for (action = action->next;
80 action;
81 action = action->next)
82 seq_printf(p, ", %s", action->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
David Howells1bcbba32006-09-25 23:32:04 -070084 seq_putc(p, '\n');
85 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Thomas Gleixner239007b2009-11-17 16:46:45 +010087 raw_spin_unlock_irqrestore(&irq_desc[i].lock, flags);
David Howells1bcbba32006-09-25 23:32:04 -070088 } else if (i == NR_IRQS) {
89 seq_printf(p, "Err: %10u\n", atomic_read(&irq_err_count));
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 }
91
92 return 0;
93}
94
Linus Torvalds1da177e2005-04-16 15:20:36 -070095/*
David Howells1bcbba32006-09-25 23:32:04 -070096 * on-CPU PIC operations
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 */
Thomas Gleixner380e3112011-02-06 20:20:38 +010098static void frv_cpupic_ack(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -070099{
Thomas Gleixner380e3112011-02-06 20:20:38 +0100100 __clr_RC(d->irq);
David Howells1bcbba32006-09-25 23:32:04 -0700101 __clr_IRL();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102}
103
Thomas Gleixner380e3112011-02-06 20:20:38 +0100104static void frv_cpupic_mask(struct irq_data *d)
David Howells1bcbba32006-09-25 23:32:04 -0700105{
Thomas Gleixner380e3112011-02-06 20:20:38 +0100106 __set_MASK(d->irq);
David Howells1bcbba32006-09-25 23:32:04 -0700107}
David Howells40234402006-01-08 01:01:19 -0800108
Thomas Gleixner380e3112011-02-06 20:20:38 +0100109static void frv_cpupic_mask_ack(struct irq_data *d)
David Howells1bcbba32006-09-25 23:32:04 -0700110{
Thomas Gleixner380e3112011-02-06 20:20:38 +0100111 __set_MASK(d->irq);
112 __clr_RC(d->irq);
David Howells1bcbba32006-09-25 23:32:04 -0700113 __clr_IRL();
114}
115
Thomas Gleixner380e3112011-02-06 20:20:38 +0100116static void frv_cpupic_unmask(struct irq_data *d)
David Howells1bcbba32006-09-25 23:32:04 -0700117{
Thomas Gleixner380e3112011-02-06 20:20:38 +0100118 __clr_MASK(d->irq);
David Howells1bcbba32006-09-25 23:32:04 -0700119}
120
David Howells1bcbba32006-09-25 23:32:04 -0700121static struct irq_chip frv_cpu_pic = {
122 .name = "cpu",
Thomas Gleixner380e3112011-02-06 20:20:38 +0100123 .irq_ack = frv_cpupic_ack,
124 .irq_mask = frv_cpupic_mask,
125 .irq_mask_ack = frv_cpupic_mask_ack,
126 .irq_unmask = frv_cpupic_unmask,
David Howells1bcbba32006-09-25 23:32:04 -0700127};
128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129/*
Simon Arlott761a7e32007-10-20 01:09:42 +0200130 * handles all normal device IRQs
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 * - registers are referred to by the __frame variable (GR28)
132 * - IRQ distribution is complicated in this arch because of the many PICs, the
133 * way they work and the way they cascade
134 */
135asmlinkage void do_IRQ(void)
136{
David Howells28baeba2006-02-14 13:53:20 -0800137 irq_enter();
David Howells7d12e782006-10-05 14:55:46 +0100138 generic_handle_irq(__get_IRL());
David Howells28baeba2006-02-14 13:53:20 -0800139 irq_exit();
David Howells1bcbba32006-09-25 23:32:04 -0700140}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142/*
143 * handles all NMIs when not co-opted by the debugger
144 * - registers are referred to by the __frame variable (GR28)
145 */
146asmlinkage void do_NMI(void)
147{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148}
149
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150/*
151 * initialise the interrupt system
152 */
153void __init init_IRQ(void)
154{
David Howells1bcbba32006-09-25 23:32:04 -0700155 int level;
156
157 for (level = 1; level <= 14; level++)
Thomas Gleixnerde2e95a2011-03-24 16:38:49 +0100158 irq_set_chip_and_handler(level, &frv_cpu_pic,
David Howells1bcbba32006-09-25 23:32:04 -0700159 handle_level_irq);
160
Thomas Gleixnerde2e95a2011-03-24 16:38:49 +0100161 irq_set_handler(IRQ_CPU_TIMER0, handle_edge_irq);
David Howells1bcbba32006-09-25 23:32:04 -0700162
163 /* set the trigger levels for internal interrupt sources
164 * - timers all falling-edge
165 * - ERR0 is rising-edge
166 * - all others are high-level
167 */
168 __set_IITMR(0, 0x003f0000); /* DMA0-3, TIMER0-2 */
169 __set_IITMR(1, 0x20000000); /* ERR0-1, UART0-1, DMA4-7 */
170
171 /* route internal interrupts */
172 set_IRR(4, IRQ_DMA3_LEVEL, IRQ_DMA2_LEVEL, IRQ_DMA1_LEVEL,
173 IRQ_DMA0_LEVEL);
174 set_IRR(5, 0, IRQ_TIMER2_LEVEL, IRQ_TIMER1_LEVEL, IRQ_TIMER0_LEVEL);
175 set_IRR(6, IRQ_GDBSTUB_LEVEL, IRQ_GDBSTUB_LEVEL,
176 IRQ_UART1_LEVEL, IRQ_UART0_LEVEL);
177 set_IRR(7, IRQ_DMA7_LEVEL, IRQ_DMA6_LEVEL, IRQ_DMA5_LEVEL,
178 IRQ_DMA4_LEVEL);
179
180 /* route external interrupts */
181 set_IRR(2, IRQ_XIRQ7_LEVEL, IRQ_XIRQ6_LEVEL, IRQ_XIRQ5_LEVEL,
182 IRQ_XIRQ4_LEVEL);
183 set_IRR(3, IRQ_XIRQ3_LEVEL, IRQ_XIRQ2_LEVEL, IRQ_XIRQ1_LEVEL,
184 IRQ_XIRQ0_LEVEL);
185
186#if defined(CONFIG_MB93091_VDK)
187 __set_TM1(0x55550000); /* XIRQ7-0 all active low */
188#elif defined(CONFIG_MB93093_PDK)
189 __set_TM1(0x15550000); /* XIRQ7 active high, 6-0 all active low */
190#else
191#error dont know external IRQ trigger levels for this setup
192#endif
193
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 fpga_init();
195#ifdef CONFIG_FUJITSU_MB93493
David Howells1bcbba32006-09-25 23:32:04 -0700196 mb93493_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197#endif
David Howells1bcbba32006-09-25 23:32:04 -0700198}