2 * linux/arch/m68k/coldfire/ints.c -- General interrupt handling code
4 * Copyright 2007-2009 Freescale Semiconductor, Inc. All Rights Reserved.
5 * Matt Waddel Matt.Waddel@freescale.com
6 * Kurt Mahan kmahan@freescale.com
7 * Jason Jin Jason.Jin@freescale.com
8 * Shrek Wu B16972@freescale.com
11 * linux/arch/m68k/kernel/ints.c &
12 * linux/arch/m68knommu/5307/ints.c
14 * This file is subject to the terms and conditions of the GNU General Public
15 * License. See the file COPYING in the main directory of this archive
19 #include <linux/module.h>
20 #include <linux/types.h>
21 #include <linux/init.h>
22 #include <linux/sched.h>
23 #include <linux/kernel_stat.h>
24 #include <linux/errno.h>
25 #include <linux/seq_file.h>
26 #include <linux/interrupt.h>
28 #include <asm/system.h>
30 #include <asm/traps.h>
32 #include <asm/machdep.h>
33 #include <asm/irq_regs.h>
35 #include <asm/mcfsim.h>
40 static struct irq_node
*irq_list
[SYS_IRQS
];
41 static struct irq_controller
*irq_controller
[SYS_IRQS
];
42 static int irq_depth
[SYS_IRQS
];
47 #if defined(CONFIG_M5445X)
48 void m5445x_irq_enable(unsigned int irq
);
49 void m5445x_irq_disable(unsigned int irq
);
50 static struct irq_controller m5445x_irq_controller
= {
52 .lock
= SPIN_LOCK_UNLOCKED
,
53 .enable
= m5445x_irq_enable
,
54 .disable
= m5445x_irq_disable
,
56 #elif defined(CONFIG_M547X_8X)
57 void m547x_8x_irq_enable(unsigned int irq
);
58 void m547x_8x_irq_disable(unsigned int irq
);
59 static struct irq_controller m547x_8x_irq_controller
= {
61 .lock
= SPIN_LOCK_UNLOCKED
,
62 .enable
= m547x_8x_irq_enable
,
63 .disable
= m547x_8x_irq_disable
,
66 # error No IRQ controller defined
69 #define POOL_SIZE SYS_IRQS
70 static struct irq_node pool
[POOL_SIZE
];
71 static struct irq_node
*get_irq_node(void);
73 /* The number of spurious interrupts */
74 unsigned int num_spurious
;
75 asmlinkage
void handle_badint(struct pt_regs
*regs
);
80 * This function should be called during kernel startup to initialize
81 * the IRQ handling routines.
83 void __init
init_IRQ(void)
87 #if defined(CONFIG_M5445X)
88 for (i
= 0; i
< SYS_IRQS
; i
++)
89 irq_controller
[i
] = &m5445x_irq_controller
;
90 #elif defined(CONFIG_M547X_8X)
91 for (i
= 0; i
< SYS_IRQS
; i
++)
92 irq_controller
[i
] = &m547x_8x_irq_controller
;
97 * process_int(unsigned long vec, struct pt_regs *fp)
99 * Process an interrupt. Called from entry.S.
101 asmlinkage
void process_int(unsigned long vec
, struct pt_regs
*fp
)
103 struct pt_regs
*old_regs
;
104 struct irq_node
*node
;
105 old_regs
= set_irq_regs(fp
);
106 kstat_cpu(0).irqs
[vec
]++;
108 node
= irq_list
[vec
];
113 node
->handler(vec
, node
->dev_id
);
118 set_irq_regs(old_regs
);
122 * show_interrupts( struct seq_file *p, void *v)
124 * Called to show all the current interrupt information.
126 int show_interrupts(struct seq_file
*p
, void *v
)
128 struct irq_controller
*contr
;
129 struct irq_node
*node
;
130 int i
= *(loff_t
*) v
;
132 if ((i
< NR_IRQS
) && (irq_list
[i
])) {
133 contr
= irq_controller
[i
];
135 seq_printf(p
, "%-8s %3u: %10u %s", contr
->name
, i
,
136 kstat_cpu(0).irqs
[i
], node
->devname
);
137 while ((node
= node
->next
))
138 seq_printf(p
, ", %s", node
->devname
);
149 * Get an irq node from the pool.
151 struct irq_node
*get_irq_node(void)
153 struct irq_node
*p
= pool
;
156 for (i
= 0; i
< POOL_SIZE
; i
++, p
++) {
158 memset(p
, 0, sizeof(struct irq_node
));
162 printk(KERN_INFO
"%s(%s:%d): No more irq nodes, I suggest you \
163 increase POOL_SIZE", __FUNCTION__
, __FILE__
, __LINE__
);
167 void init_irq_proc(void)
169 /* Insert /proc/irq driver here */
172 int setup_irq(unsigned int irq
, struct irq_node
*node
)
174 struct irq_controller
*contr
;
175 struct irq_node
**prev
;
178 if (irq
>= NR_IRQS
|| !irq_controller
[irq
]) {
179 printk("%s: Incorrect IRQ %d from %s\n",
180 __FUNCTION__
, irq
, node
->devname
);
184 contr
= irq_controller
[irq
];
185 spin_lock_irqsave(&contr
->lock
, flags
);
187 prev
= irq_list
+ irq
;
189 /* Can't share interrupts unless both agree to */
190 if (!((*prev
)->flags
& node
->flags
& IRQF_SHARED
)) {
191 spin_unlock_irqrestore(&contr
->lock
, flags
);
192 printk(KERN_INFO
"%s: -BUSY-Incorrect IRQ %d \n",
197 prev
= &(*prev
)->next
;
200 if (!irq_list
[irq
]) {
209 spin_unlock_irqrestore(&contr
->lock
, flags
);
214 int request_irq(unsigned int irq
,
215 irq_handler_t handler
,
216 unsigned long flags
, const char *devname
, void *dev_id
)
218 struct irq_node
*node
= get_irq_node();
222 printk(KERN_INFO
"%s:get_irq_node error %x\n",
223 __FUNCTION__
,(unsigned int) node
);
226 node
->handler
= handler
;
228 node
->dev_id
= dev_id
;
229 node
->devname
= devname
;
231 res
= setup_irq(irq
, node
);
233 node
->handler
= NULL
;
237 EXPORT_SYMBOL(request_irq
);
239 void free_irq(unsigned int irq
, void *dev_id
)
241 struct irq_controller
*contr
;
242 struct irq_node
**p
, *node
;
245 if (irq
>= NR_IRQS
|| !irq_controller
[irq
]) {
246 printk(KERN_DEBUG
"%s: Incorrect IRQ %d\n", __FUNCTION__
, irq
);
250 contr
= irq_controller
[irq
];
251 spin_lock_irqsave(&contr
->lock
, flags
);
254 while ((node
= *p
)) {
255 if (node
->dev_id
== dev_id
)
262 node
->handler
= NULL
;
264 printk(KERN_DEBUG
"%s: Removing probably wrong IRQ %d\n",
267 if (!irq_list
[irq
]) {
269 contr
->shutdown(irq
);
274 spin_unlock_irqrestore(&contr
->lock
, flags
);
276 EXPORT_SYMBOL(free_irq
);
278 void enable_irq(unsigned int irq
)
280 struct irq_controller
*contr
;
283 if (irq
>= NR_IRQS
|| !irq_controller
[irq
]) {
284 printk(KERN_DEBUG
"%s: Incorrect IRQ %d\n", __FUNCTION__
, irq
);
288 contr
= irq_controller
[irq
];
289 spin_lock_irqsave(&contr
->lock
, flags
);
290 if (irq_depth
[irq
]) {
291 if (!--irq_depth
[irq
]) {
297 spin_unlock_irqrestore(&contr
->lock
, flags
);
299 EXPORT_SYMBOL(enable_irq
);
301 void disable_irq(unsigned int irq
)
303 struct irq_controller
*contr
;
306 if (irq
>= NR_IRQS
|| !irq_controller
[irq
]) {
307 printk(KERN_DEBUG
"%s: Incorrect IRQ %d\n", __FUNCTION__
, irq
);
311 contr
= irq_controller
[irq
];
312 spin_lock_irqsave(&contr
->lock
, flags
);
313 if (!irq_depth
[irq
]++) {
317 spin_unlock_irqrestore(&contr
->lock
, flags
);
319 EXPORT_SYMBOL(disable_irq
);
321 void disable_irq_nosync(unsigned int irq
) __attribute__((alias("disable_irq")));
322 EXPORT_SYMBOL(disable_irq_nosync
);
325 unsigned long probe_irq_on(void)
329 EXPORT_SYMBOL(probe_irq_on
);
331 int probe_irq_off(unsigned long irqs
)
335 EXPORT_SYMBOL(probe_irq_off
);
337 asmlinkage
void handle_badint(struct pt_regs
*regs
)
339 kstat_cpu(0).irqs
[0]++;
341 printk(KERN_DEBUG
"unexpected interrupt from %u\n", regs
->vector
);
343 EXPORT_SYMBOL(handle_badint
);
345 unsigned int irq_canonicalize(unsigned int irq
)
348 if (MACH_IS_Q40
&& irq
== 11)
354 EXPORT_SYMBOL(irq_canonicalize
);
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 /* check for eport */
429 if ((irq
> 0) && (irq
< 8)) {
431 MCF_EPPAR
&= ~(3 << (irq
*2));
433 MCF_EPDDR
&= ~(1 << irq
);
435 MCF_EPIER
|= 1 << irq
;
440 /* *grumble* don't set low bit of IMRL */
441 MCF_IMRL
&= (~(1 << irq
) & 0xfffffffe);
443 MCF_IMRH
&= ~(1 << (irq
- 32));
447 void m547x_8x_irq_disable(unsigned int irq
)
449 /* disable the interrupt hardware */
453 /* adjust past non-hardware ints */
456 /* check for eport */
457 if ((irq
> 0) && (irq
< 8)) {
459 MCF_EPIER
&= ~(1 << irq
);
463 MCF_IMRL
|= (1 << irq
);
465 MCF_IMRH
|= (1 << (irq
- 32));