blob: 7ddc8fde7748dcb255e8d634278e4cd514422b94 [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önig9918cda2007-02-16 15:36:55 +010022static void ns9xxx_mask_irq(unsigned int irq)
23{
24 /* XXX: better use cpp symbols */
Uwe Kleine-König361c7ad2007-09-30 20:36:33 +010025 u32 ic = __raw_readl(SYS_IC(irq / 4));
26 ic &= ~(1 << (7 + 8 * (3 - (irq & 3))));
27 __raw_writel(ic, SYS_IC(irq / 4));
Uwe Kleine-König9918cda2007-02-16 15:36:55 +010028}
29
30static void ns9xxx_ack_irq(unsigned int irq)
31{
Uwe Kleine-König361c7ad2007-09-30 20:36:33 +010032 __raw_writel(0, SYS_ISRADDR);
Uwe Kleine-König9918cda2007-02-16 15:36:55 +010033}
34
35static void ns9xxx_maskack_irq(unsigned int irq)
36{
37 ns9xxx_mask_irq(irq);
38 ns9xxx_ack_irq(irq);
39}
40
41static void ns9xxx_unmask_irq(unsigned int irq)
42{
43 /* XXX: better use cpp symbols */
Uwe Kleine-König361c7ad2007-09-30 20:36:33 +010044 u32 ic = __raw_readl(SYS_IC(irq / 4));
45 ic |= 1 << (7 + 8 * (3 - (irq & 3)));
46 __raw_writel(ic, SYS_IC(irq / 4));
Uwe Kleine-König9918cda2007-02-16 15:36:55 +010047}
48
49static struct irq_chip ns9xxx_chip = {
50 .ack = ns9xxx_ack_irq,
51 .mask = ns9xxx_mask_irq,
52 .mask_ack = ns9xxx_maskack_irq,
53 .unmask = ns9xxx_unmask_irq,
54};
55
Uwe Kleine-König5e69b942008-02-29 13:27:53 +010056#if 0
57#define handle_irq handle_level_irq
58#else
59void handle_prio_irq(unsigned int irq, struct irq_desc *desc)
60{
61 unsigned int cpu = smp_processor_id();
62 struct irqaction *action;
63 irqreturn_t action_ret;
64
65 spin_lock(&desc->lock);
66
67 if (unlikely(desc->status & IRQ_INPROGRESS))
68 goto out_unlock;
69
70 desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
71 kstat_cpu(cpu).irqs[irq]++;
72
73 action = desc->action;
74 if (unlikely(!action || (desc->status & IRQ_DISABLED)))
75 goto out_unlock;
76
77 desc->status |= IRQ_INPROGRESS;
78 spin_unlock(&desc->lock);
79
80 action_ret = handle_IRQ_event(irq, action);
81
82 spin_lock(&desc->lock);
83 desc->status &= ~IRQ_INPROGRESS;
84 if (!(desc->status & IRQ_DISABLED) && desc->chip->ack)
85 desc->chip->ack(irq);
86
87out_unlock:
88 spin_unlock(&desc->lock);
89}
90#define handle_irq handle_prio_irq
91#endif
92
Uwe Kleine-König9918cda2007-02-16 15:36:55 +010093void __init ns9xxx_init_irq(void)
94{
95 int i;
96
97 /* disable all IRQs */
98 for (i = 0; i < 8; ++i)
Uwe Kleine-König361c7ad2007-09-30 20:36:33 +010099 __raw_writel((4 * i) << 24 | (4 * i + 1) << 16 |
100 (4 * i + 2) << 8 | (4 * i + 3), SYS_IC(i));
Uwe Kleine-König9918cda2007-02-16 15:36:55 +0100101
102 /* simple interrupt prio table:
103 * prio(x) < prio(y) <=> x < y
104 */
105 for (i = 0; i < 32; ++i)
Uwe Kleine-König361c7ad2007-09-30 20:36:33 +0100106 __raw_writel(i, SYS_IVA(i));
Uwe Kleine-König9918cda2007-02-16 15:36:55 +0100107
Uwe Kleine-König724ce5e2008-02-15 08:41:06 +0100108 for (i = 0; i <= 31; ++i) {
Uwe Kleine-König9918cda2007-02-16 15:36:55 +0100109 set_irq_chip(i, &ns9xxx_chip);
Uwe Kleine-König5e69b942008-02-29 13:27:53 +0100110 set_irq_handler(i, handle_irq);
Uwe Kleine-König9918cda2007-02-16 15:36:55 +0100111 set_irq_flags(i, IRQF_VALID);
112 }
113}