blob: 38260d5f849b3e482935e27e615d7364c909ff22 [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>
Russell Kinga09e64f2008-08-05 16:14:15 +010015#include <mach/regs-sys-common.h>
16#include <mach/irqs.h>
17#include <mach/board.h>
Uwe Kleine-König9918cda2007-02-16 15:36:55 +010018
19#include "generic.h"
20
Uwe Kleine-Königed6f5982007-12-11 16:52:50 +010021/* simple interrupt prio table: prio(x) < prio(y) <=> x < y */
22#define irq2prio(i) (i)
23#define prio2irq(p) (p)
24
Uwe Kleine-König9918cda2007-02-16 15:36:55 +010025static void ns9xxx_mask_irq(unsigned int irq)
26{
27 /* XXX: better use cpp symbols */
Uwe Kleine-Königed6f5982007-12-11 16:52:50 +010028 int prio = irq2prio(irq);
29 u32 ic = __raw_readl(SYS_IC(prio / 4));
30 ic &= ~(1 << (7 + 8 * (3 - (prio & 3))));
31 __raw_writel(ic, SYS_IC(prio / 4));
Uwe Kleine-König9918cda2007-02-16 15:36:55 +010032}
33
34static void ns9xxx_ack_irq(unsigned int irq)
35{
Uwe Kleine-König361c7ad2007-09-30 20:36:33 +010036 __raw_writel(0, SYS_ISRADDR);
Uwe Kleine-König9918cda2007-02-16 15:36:55 +010037}
38
39static void ns9xxx_maskack_irq(unsigned int irq)
40{
41 ns9xxx_mask_irq(irq);
42 ns9xxx_ack_irq(irq);
43}
44
45static void ns9xxx_unmask_irq(unsigned int irq)
46{
47 /* XXX: better use cpp symbols */
Uwe Kleine-Königed6f5982007-12-11 16:52:50 +010048 int prio = irq2prio(irq);
49 u32 ic = __raw_readl(SYS_IC(prio / 4));
50 ic |= 1 << (7 + 8 * (3 - (prio & 3)));
51 __raw_writel(ic, SYS_IC(prio / 4));
Uwe Kleine-König9918cda2007-02-16 15:36:55 +010052}
53
54static struct irq_chip ns9xxx_chip = {
55 .ack = ns9xxx_ack_irq,
56 .mask = ns9xxx_mask_irq,
57 .mask_ack = ns9xxx_maskack_irq,
58 .unmask = ns9xxx_unmask_irq,
59};
60
Uwe Kleine-König5e69b942008-02-29 13:27:53 +010061#if 0
62#define handle_irq handle_level_irq
63#else
Uwe Kleine-König21f20b62008-04-25 15:24:59 +020064static void handle_prio_irq(unsigned int irq, struct irq_desc *desc)
Uwe Kleine-König5e69b942008-02-29 13:27:53 +010065{
66 unsigned int cpu = smp_processor_id();
67 struct irqaction *action;
68 irqreturn_t action_ret;
69
70 spin_lock(&desc->lock);
71
Uwe Kleine-Königa13c8192008-04-25 15:03:18 +020072 BUG_ON(desc->status & IRQ_INPROGRESS);
Uwe Kleine-König5e69b942008-02-29 13:27:53 +010073
74 desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
75 kstat_cpu(cpu).irqs[irq]++;
76
77 action = desc->action;
78 if (unlikely(!action || (desc->status & IRQ_DISABLED)))
Uwe Kleine-Königa13c8192008-04-25 15:03:18 +020079 goto out_mask;
Uwe Kleine-König5e69b942008-02-29 13:27:53 +010080
81 desc->status |= IRQ_INPROGRESS;
82 spin_unlock(&desc->lock);
83
84 action_ret = handle_IRQ_event(irq, action);
85
Uwe Kleine-Königa57a0b12008-04-25 15:16:17 +020086 /* XXX: There is no direct way to access noirqdebug, so check
87 * unconditionally for spurious irqs...
88 * Maybe this function should go to kernel/irq/chip.c? */
89 note_interrupt(irq, desc, action_ret);
90
Uwe Kleine-König5e69b942008-02-29 13:27:53 +010091 spin_lock(&desc->lock);
92 desc->status &= ~IRQ_INPROGRESS;
Uwe Kleine-König5e69b942008-02-29 13:27:53 +010093
Uwe Kleine-Königa13c8192008-04-25 15:03:18 +020094 if (desc->status & IRQ_DISABLED)
95out_mask:
96 desc->chip->mask(irq);
97
98 /* ack unconditionally to unmask lower prio irqs */
99 desc->chip->ack(irq);
100
Uwe Kleine-König5e69b942008-02-29 13:27:53 +0100101 spin_unlock(&desc->lock);
102}
103#define handle_irq handle_prio_irq
104#endif
105
Uwe Kleine-König9918cda2007-02-16 15:36:55 +0100106void __init ns9xxx_init_irq(void)
107{
108 int i;
109
110 /* disable all IRQs */
111 for (i = 0; i < 8; ++i)
Uwe Kleine-Königed6f5982007-12-11 16:52:50 +0100112 __raw_writel(prio2irq(4 * i) << 24 |
113 prio2irq(4 * i + 1) << 16 |
114 prio2irq(4 * i + 2) << 8 |
115 prio2irq(4 * i + 3),
116 SYS_IC(i));
Uwe Kleine-König9918cda2007-02-16 15:36:55 +0100117
Uwe Kleine-König9918cda2007-02-16 15:36:55 +0100118 for (i = 0; i < 32; ++i)
Uwe Kleine-Königed6f5982007-12-11 16:52:50 +0100119 __raw_writel(prio2irq(i), SYS_IVA(i));
Uwe Kleine-König9918cda2007-02-16 15:36:55 +0100120
Uwe Kleine-König724ce5e2008-02-15 08:41:06 +0100121 for (i = 0; i <= 31; ++i) {
Uwe Kleine-König9918cda2007-02-16 15:36:55 +0100122 set_irq_chip(i, &ns9xxx_chip);
Uwe Kleine-König5e69b942008-02-29 13:27:53 +0100123 set_irq_handler(i, handle_irq);
Uwe Kleine-König9918cda2007-02-16 15:36:55 +0100124 set_irq_flags(i, IRQF_VALID);
125 }
126}