blob: ca85d24cf39f1f11553c2ac856d08b71bb9a9ff9 [file] [log] [blame]
Uwe Kleine-König9918cda2007-02-16 15:36:55 +01001/*
2 * arch/arm/mach-ns9xxx/irq.c
3 *
4 * Copyright (C) 2006,2007 by Digi International Inc.
5 * All rights reserved.
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published by
9 * the Free Software Foundation.
10 */
11#include <linux/interrupt.h>
Uwe Kleine-König5e69b942008-02-29 13:27:53 +010012#include <linux/kernel_stat.h>
Uwe Kleine-König361c7ad2007-09-30 20:36:33 +010013#include <asm/io.h>
Uwe Kleine-König9918cda2007-02-16 15:36:55 +010014#include <asm/mach/irq.h>
15#include <asm/mach-types.h>
Uwe Kleine-König724ce5e2008-02-15 08:41:06 +010016#include <asm/arch-ns9xxx/regs-sys-common.h>
Uwe Kleine-König9918cda2007-02-16 15:36:55 +010017#include <asm/arch-ns9xxx/irqs.h>
18#include <asm/arch-ns9xxx/board.h>
19
20#include "generic.h"
21
Uwe Kleine-Königed6f5982007-12-11 16:52:50 +010022/* simple interrupt prio table: prio(x) < prio(y) <=> x < y */
23#define irq2prio(i) (i)
24#define prio2irq(p) (p)
25
Uwe Kleine-König9918cda2007-02-16 15:36:55 +010026static void ns9xxx_mask_irq(unsigned int irq)
27{
28 /* XXX: better use cpp symbols */
Uwe Kleine-Königed6f5982007-12-11 16:52:50 +010029 int prio = irq2prio(irq);
30 u32 ic = __raw_readl(SYS_IC(prio / 4));
31 ic &= ~(1 << (7 + 8 * (3 - (prio & 3))));
32 __raw_writel(ic, SYS_IC(prio / 4));
Uwe Kleine-König9918cda2007-02-16 15:36:55 +010033}
34
35static void ns9xxx_ack_irq(unsigned int irq)
36{
Uwe Kleine-König361c7ad2007-09-30 20:36:33 +010037 __raw_writel(0, SYS_ISRADDR);
Uwe Kleine-König9918cda2007-02-16 15:36:55 +010038}
39
40static void ns9xxx_maskack_irq(unsigned int irq)
41{
42 ns9xxx_mask_irq(irq);
43 ns9xxx_ack_irq(irq);
44}
45
46static void ns9xxx_unmask_irq(unsigned int irq)
47{
48 /* XXX: better use cpp symbols */
Uwe Kleine-Königed6f5982007-12-11 16:52:50 +010049 int prio = irq2prio(irq);
50 u32 ic = __raw_readl(SYS_IC(prio / 4));
51 ic |= 1 << (7 + 8 * (3 - (prio & 3)));
52 __raw_writel(ic, SYS_IC(prio / 4));
Uwe Kleine-König9918cda2007-02-16 15:36:55 +010053}
54
55static struct irq_chip ns9xxx_chip = {
56 .ack = ns9xxx_ack_irq,
57 .mask = ns9xxx_mask_irq,
58 .mask_ack = ns9xxx_maskack_irq,
59 .unmask = ns9xxx_unmask_irq,
60};
61
Uwe Kleine-König5e69b942008-02-29 13:27:53 +010062#if 0
63#define handle_irq handle_level_irq
64#else
Uwe Kleine-König21f20b62008-04-25 15:24:59 +020065static void handle_prio_irq(unsigned int irq, struct irq_desc *desc)
Uwe Kleine-König5e69b942008-02-29 13:27:53 +010066{
67 unsigned int cpu = smp_processor_id();
68 struct irqaction *action;
69 irqreturn_t action_ret;
70
71 spin_lock(&desc->lock);
72
Uwe Kleine-Königa13c8192008-04-25 15:03:18 +020073 BUG_ON(desc->status & IRQ_INPROGRESS);
Uwe Kleine-König5e69b942008-02-29 13:27:53 +010074
75 desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
76 kstat_cpu(cpu).irqs[irq]++;
77
78 action = desc->action;
79 if (unlikely(!action || (desc->status & IRQ_DISABLED)))
Uwe Kleine-Königa13c8192008-04-25 15:03:18 +020080 goto out_mask;
Uwe Kleine-König5e69b942008-02-29 13:27:53 +010081
82 desc->status |= IRQ_INPROGRESS;
83 spin_unlock(&desc->lock);
84
85 action_ret = handle_IRQ_event(irq, action);
86
Uwe Kleine-Königa57a0b12008-04-25 15:16:17 +020087 /* XXX: There is no direct way to access noirqdebug, so check
88 * unconditionally for spurious irqs...
89 * Maybe this function should go to kernel/irq/chip.c? */
90 note_interrupt(irq, desc, action_ret);
91
Uwe Kleine-König5e69b942008-02-29 13:27:53 +010092 spin_lock(&desc->lock);
93 desc->status &= ~IRQ_INPROGRESS;
Uwe Kleine-König5e69b942008-02-29 13:27:53 +010094
Uwe Kleine-Königa13c8192008-04-25 15:03:18 +020095 if (desc->status & IRQ_DISABLED)
96out_mask:
97 desc->chip->mask(irq);
98
99 /* ack unconditionally to unmask lower prio irqs */
100 desc->chip->ack(irq);
101
Uwe Kleine-König5e69b942008-02-29 13:27:53 +0100102 spin_unlock(&desc->lock);
103}
104#define handle_irq handle_prio_irq
105#endif
106
Uwe Kleine-König9918cda2007-02-16 15:36:55 +0100107void __init ns9xxx_init_irq(void)
108{
109 int i;
110
111 /* disable all IRQs */
112 for (i = 0; i < 8; ++i)
Uwe Kleine-Königed6f5982007-12-11 16:52:50 +0100113 __raw_writel(prio2irq(4 * i) << 24 |
114 prio2irq(4 * i + 1) << 16 |
115 prio2irq(4 * i + 2) << 8 |
116 prio2irq(4 * i + 3),
117 SYS_IC(i));
Uwe Kleine-König9918cda2007-02-16 15:36:55 +0100118
Uwe Kleine-König9918cda2007-02-16 15:36:55 +0100119 for (i = 0; i < 32; ++i)
Uwe Kleine-Königed6f5982007-12-11 16:52:50 +0100120 __raw_writel(prio2irq(i), SYS_IVA(i));
Uwe Kleine-König9918cda2007-02-16 15:36:55 +0100121
Uwe Kleine-König724ce5e2008-02-15 08:41:06 +0100122 for (i = 0; i <= 31; ++i) {
Uwe Kleine-König9918cda2007-02-16 15:36:55 +0100123 set_irq_chip(i, &ns9xxx_chip);
Uwe Kleine-König5e69b942008-02-29 13:27:53 +0100124 set_irq_handler(i, handle_irq);
Uwe Kleine-König9918cda2007-02-16 15:36:55 +0100125 set_irq_flags(i, IRQF_VALID);
126 }
127}