2 * linux/arch/m68k/coldfire/ints.c -- General interrupt handling code
4 * Copyright (C) 1999-2002 Greg Ungerer (gerg@snapgear.com)
5 * Copyright (C) 1998 D. Jeff Dionne <jeff@lineo.ca>,
6 * Kenneth Albanowski <kjahds@kjahds.com>,
7 * Copyright (C) 2000 Lineo Inc. (www.lineo.com)
9 * Copyright Freescale Semiconductor, Inc. 2007, 2008
10 * Kurt Mahan kmahan@freescale.com
11 * Matt Waddel Matt.Waddel@freescale.com
14 * linux/arch/m68k/kernel/ints.c &
15 * linux/arch/m68knommu/5307/ints.c
17 * This file is subject to the terms and conditions of the GNU General Public
18 * License. See the file COPYING in the main directory of this archive
22 #include <linux/module.h>
23 #include <linux/types.h>
24 #include <linux/init.h>
25 #include <linux/sched.h>
26 #include <linux/kernel_stat.h>
27 #include <linux/errno.h>
28 #include <linux/seq_file.h>
29 #include <linux/interrupt.h>
31 #include <asm/system.h>
33 #include <asm/traps.h>
35 #include <asm/machdep.h>
36 #include <asm/irq_regs.h>
38 #include <asm/mcfsim.h>
43 static struct irq_node *irq_list[NR_IRQS];
44 static struct irq_controller *irq_controller[NR_IRQS];
45 static int irq_depth[NR_IRQS];
50 #if defined(CONFIG_M5445X)
51 void m5445x_irq_enable(unsigned int irq);
52 void m5445x_irq_disable(unsigned int irq);
53 static struct irq_controller m5445x_irq_controller = {
55 .lock = SPIN_LOCK_UNLOCKED,
56 .enable = m5445x_irq_enable,
57 .disable = m5445x_irq_disable,
59 #elif defined(CONFIG_M547X_8X)
60 void m547x_8x_irq_enable(unsigned int irq);
61 void m547x_8x_irq_disable(unsigned int irq);
62 static struct irq_controller m547x_8x_irq_controller = {
64 .lock = SPIN_LOCK_UNLOCKED,
65 .enable = m547x_8x_irq_enable,
66 .disable = m547x_8x_irq_disable,
69 # error No IRQ controller defined
72 #define POOL_SIZE NR_IRQS
73 static struct irq_node pool[POOL_SIZE];
74 static struct irq_node *get_irq_node(void);
76 /* The number of spurious interrupts */
77 unsigned int num_spurious;
78 asmlinkage void handle_badint(struct pt_regs *regs);
83 * This function should be called during kernel startup to initialize
84 * the IRQ handling routines.
86 void __init init_IRQ(void)
90 #if defined(CONFIG_M5445X)
91 for (i = 0; i < NR_IRQS; i++)
92 irq_controller[i] = &m5445x_irq_controller;
93 #elif defined(CONFIG_M547X_8X)
94 for (i = 0; i < NR_IRQS; i++)
95 irq_controller[i] = &m547x_8x_irq_controller;
99 unsigned int irq_canonicalize(unsigned int irq)
104 EXPORT_SYMBOL(irq_canonicalize);
108 * __m68k_handle_int(unsigned long vec, struct pt_regs *fp)
110 * Process an interrupt. Called from entry.S.
112 asmlinkage void __m68k_handle_int(unsigned int irq, struct pt_regs *regs)
114 struct pt_regs *old_regs;
115 struct irq_node *node;
116 old_regs = set_irq_regs(regs);
117 kstat_cpu(0).irqs[irq]++;
119 node = irq_list[irq];
124 node->handler(irq, node->dev_id);
129 set_irq_regs(old_regs);
133 * show_interrupts( struct seq_file *p, void *v)
135 * Called to show all the current interrupt information.
137 int show_interrupts(struct seq_file *p, void *v)
139 struct irq_controller *contr;
140 struct irq_node *node;
141 int i = *(loff_t *) v;
143 if ((i < NR_IRQS) && (irq_list[i])) {
144 contr = irq_controller[i];
146 seq_printf(p, "%-8s %3u: %10u %s", contr->name, i,
147 kstat_cpu(0).irqs[i], node->devname);
148 while ((node = node->next))
149 seq_printf(p, ", %s", node->devname);
160 * Get an irq node from the pool.
162 struct irq_node *get_irq_node(void)
164 struct irq_node *p = pool;
167 for (i = 0; i < POOL_SIZE; i++, p++) {
169 memset(p, 0, sizeof(struct irq_node));
173 printk(KERN_INFO "%s(%s:%d): No more irq nodes, I suggest you \
174 increase POOL_SIZE", __FUNCTION__, __FILE__, __LINE__);
178 void init_irq_proc(void)
180 /* Insert /proc/irq driver here */
183 int setup_irq(unsigned int irq, struct irq_node *node)
185 struct irq_controller *contr;
186 struct irq_node **prev;
189 if (irq >= NR_IRQS || !irq_controller[irq]) {
190 printk("%s: Incorrect IRQ %d from %s\n",
191 __FUNCTION__, irq, node->devname);
195 contr = irq_controller[irq];
196 spin_lock_irqsave(&contr->lock, flags);
198 prev = irq_list + irq;
200 /* Can't share interrupts unless both agree to */
201 if (!((*prev)->flags & node->flags & IRQF_SHARED)) {
202 spin_unlock_irqrestore(&contr->lock, flags);
203 printk(KERN_INFO "%s: -BUSY-Incorrect IRQ %d \n",
208 prev = &(*prev)->next;
211 if (!irq_list[irq]) {
220 spin_unlock_irqrestore(&contr->lock, flags);
225 int request_irq(unsigned int irq,
226 irq_handler_t handler,
227 unsigned long flags, const char *devname, void *dev_id)
229 struct irq_node *node = get_irq_node();
233 printk(KERN_INFO "%s:get_irq_node error %x\n",
234 __FUNCTION__,(unsigned int) node);
237 node->handler = handler;
239 node->dev_id = dev_id;
240 node->devname = devname;
242 res = setup_irq(irq, node);
244 node->handler = NULL;
248 EXPORT_SYMBOL(request_irq);
250 void free_irq(unsigned int irq, void *dev_id)
252 struct irq_controller *contr;
253 struct irq_node **p, *node;
256 if (irq >= NR_IRQS || !irq_controller[irq]) {
257 printk(KERN_DEBUG "%s: Incorrect IRQ %d\n", __FUNCTION__, irq);
261 contr = irq_controller[irq];
262 spin_lock_irqsave(&contr->lock, flags);
265 while ((node = *p)) {
266 if (node->dev_id == dev_id)
273 node->handler = NULL;
275 printk(KERN_DEBUG "%s: Removing probably wrong IRQ %d\n",
278 if (!irq_list[irq]) {
280 contr->shutdown(irq);
285 spin_unlock_irqrestore(&contr->lock, flags);
287 EXPORT_SYMBOL(free_irq);
289 void enable_irq(unsigned int irq)
291 struct irq_controller *contr;
294 if (irq >= NR_IRQS || !irq_controller[irq]) {
295 printk(KERN_DEBUG "%s: Incorrect IRQ %d\n", __FUNCTION__, irq);
299 contr = irq_controller[irq];
300 spin_lock_irqsave(&contr->lock, flags);
301 if (irq_depth[irq]) {
302 if (!--irq_depth[irq]) {
308 spin_unlock_irqrestore(&contr->lock, flags);
310 EXPORT_SYMBOL(enable_irq);
312 void disable_irq(unsigned int irq)
314 struct irq_controller *contr;
317 if (irq >= NR_IRQS || !irq_controller[irq]) {
318 printk(KERN_DEBUG "%s: Incorrect IRQ %d\n", __FUNCTION__, irq);
322 contr = irq_controller[irq];
323 spin_lock_irqsave(&contr->lock, flags);
324 if (!irq_depth[irq]++) {
328 spin_unlock_irqrestore(&contr->lock, flags);
330 EXPORT_SYMBOL(disable_irq);
332 void disable_irq_nosync(unsigned int irq) __attribute__((alias("disable_irq")));
333 EXPORT_SYMBOL(disable_irq_nosync);
336 unsigned long probe_irq_on(void)
340 EXPORT_SYMBOL(probe_irq_on);
342 int probe_irq_off(unsigned long irqs)
346 EXPORT_SYMBOL(probe_irq_off);
348 asmlinkage void handle_badint(struct pt_regs *regs)
350 kstat_cpu(0).irqs[0]++;
352 printk(KERN_DEBUG "unexpected interrupt from %u\n", regs->vector);
354 EXPORT_SYMBOL(handle_badint);
358 * M5445X Implementation
360 void m5445x_irq_enable(unsigned int irq)
362 /* enable the interrupt hardware */
366 /* adjust past non-hardware ints */
369 /* check for eport */
370 if ((irq > 0) && (irq < 8)) {
372 MCF_EPORT_EPPAR &= ~(3 << (irq*2)); /* level */
373 MCF_EPORT_EPDDR &= ~(1 << irq); /* input */
374 MCF_EPORT_EPIER |= 1 << irq; /* irq enabled */
379 MCF_INTC0_ICR(irq) = 0x02;
380 MCF_INTC0_CIMR = irq;
384 MCF_INTC1_ICR(irq) = 0x02;
385 MCF_INTC1_CIMR = irq;
389 void m5445x_irq_disable(unsigned int irq)
391 /* disable the interrupt hardware */
395 /* adjust past non-hardware ints */
398 /* check for eport */
399 if ((irq > 0) && (irq < 8)) {
401 MCF_EPORT_EPIER &= ~(1 << irq);
406 MCF_INTC0_ICR(irq) = 0x00;
407 MCF_INTC0_SIMR = irq;
411 MCF_INTC1_ICR(irq) = 0x00;
412 MCF_INTC1_SIMR = irq;
415 #elif defined(CONFIG_M547X_8X)
417 * M547X_8X Implementation
419 void m547x_8x_irq_enable(unsigned int irq)
421 /* enable the interrupt hardware */
425 /* adjust past non-hardware ints */
428 /* JKM -- re-add EPORT later */
430 /* check for eport */
431 if ((irq > 0) && (irq < 8)) {
433 MCF_EPORT_EPPAR &= ~(3 << (irq*2)); /* level */
434 MCF_EPORT_EPDDR &= ~(1 << irq); /* input */
435 MCF_EPORT_EPIER |= 1 << irq; /* irq enabled */
440 /* *grumble* don't set low bit of IMRL */
441 MCF_IMRL &= (~(1 << irq) & 0xfffffffe);
444 MCF_IMRH &= ~(1 << (irq - 32));
448 void m547x_8x_irq_disable(unsigned int irq)
450 /* disable the interrupt hardware */
454 /* adjust past non-hardware ints */
457 /* JKM -- re-add EPORT later */
459 /* check for eport */
460 if ((irq > 0) && (irq < 8)) {
462 MCF_EPORT_EPIER &= ~(1 << irq);
467 MCF_IMRL |= (1 << irq);
469 MCF_IMRH |= (1 << (irq - 32));