Uwe Kleine-König | 9918cda | 2007-02-16 15:36:55 +0100 | [diff] [blame] | 1 | /* |
| 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önig | 5e69b94 | 2008-02-29 13:27:53 +0100 | [diff] [blame] | 12 | #include <linux/kernel_stat.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 13 | #include <linux/io.h> |
Uwe Kleine-König | 9918cda | 2007-02-16 15:36:55 +0100 | [diff] [blame] | 14 | #include <asm/mach/irq.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 15 | #include <mach/regs-sys-common.h> |
| 16 | #include <mach/irqs.h> |
| 17 | #include <mach/board.h> |
Uwe Kleine-König | 9918cda | 2007-02-16 15:36:55 +0100 | [diff] [blame] | 18 | |
| 19 | #include "generic.h" |
| 20 | |
Uwe Kleine-König | ed6f598 | 2007-12-11 16:52:50 +0100 | [diff] [blame] | 21 | /* simple interrupt prio table: prio(x) < prio(y) <=> x < y */ |
| 22 | #define irq2prio(i) (i) |
| 23 | #define prio2irq(p) (p) |
| 24 | |
Uwe Kleine-König | 9918cda | 2007-02-16 15:36:55 +0100 | [diff] [blame] | 25 | static void ns9xxx_mask_irq(unsigned int irq) |
| 26 | { |
| 27 | /* XXX: better use cpp symbols */ |
Uwe Kleine-König | ed6f598 | 2007-12-11 16:52:50 +0100 | [diff] [blame] | 28 | 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önig | 9918cda | 2007-02-16 15:36:55 +0100 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | static void ns9xxx_ack_irq(unsigned int irq) |
| 35 | { |
Uwe Kleine-König | 361c7ad | 2007-09-30 20:36:33 +0100 | [diff] [blame] | 36 | __raw_writel(0, SYS_ISRADDR); |
Uwe Kleine-König | 9918cda | 2007-02-16 15:36:55 +0100 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | static void ns9xxx_maskack_irq(unsigned int irq) |
| 40 | { |
| 41 | ns9xxx_mask_irq(irq); |
| 42 | ns9xxx_ack_irq(irq); |
| 43 | } |
| 44 | |
| 45 | static void ns9xxx_unmask_irq(unsigned int irq) |
| 46 | { |
| 47 | /* XXX: better use cpp symbols */ |
Uwe Kleine-König | ed6f598 | 2007-12-11 16:52:50 +0100 | [diff] [blame] | 48 | 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önig | 9918cda | 2007-02-16 15:36:55 +0100 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | static 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önig | 5e69b94 | 2008-02-29 13:27:53 +0100 | [diff] [blame] | 61 | #if 0 |
| 62 | #define handle_irq handle_level_irq |
| 63 | #else |
Uwe Kleine-König | 21f20b6 | 2008-04-25 15:24:59 +0200 | [diff] [blame] | 64 | static void handle_prio_irq(unsigned int irq, struct irq_desc *desc) |
Uwe Kleine-König | 5e69b94 | 2008-02-29 13:27:53 +0100 | [diff] [blame] | 65 | { |
Uwe Kleine-König | 5e69b94 | 2008-02-29 13:27:53 +0100 | [diff] [blame] | 66 | struct irqaction *action; |
| 67 | irqreturn_t action_ret; |
| 68 | |
Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 69 | raw_spin_lock(&desc->lock); |
Uwe Kleine-König | 5e69b94 | 2008-02-29 13:27:53 +0100 | [diff] [blame] | 70 | |
Uwe Kleine-König | a13c819 | 2008-04-25 15:03:18 +0200 | [diff] [blame] | 71 | BUG_ON(desc->status & IRQ_INPROGRESS); |
Uwe Kleine-König | 5e69b94 | 2008-02-29 13:27:53 +0100 | [diff] [blame] | 72 | |
| 73 | desc->status &= ~(IRQ_REPLAY | IRQ_WAITING); |
Yinghai Lu | 0b0f0b1 | 2009-01-11 13:35:56 -0800 | [diff] [blame] | 74 | kstat_incr_irqs_this_cpu(irq, desc); |
Uwe Kleine-König | 5e69b94 | 2008-02-29 13:27:53 +0100 | [diff] [blame] | 75 | |
| 76 | action = desc->action; |
| 77 | if (unlikely(!action || (desc->status & IRQ_DISABLED))) |
Uwe Kleine-König | a13c819 | 2008-04-25 15:03:18 +0200 | [diff] [blame] | 78 | goto out_mask; |
Uwe Kleine-König | 5e69b94 | 2008-02-29 13:27:53 +0100 | [diff] [blame] | 79 | |
| 80 | desc->status |= IRQ_INPROGRESS; |
Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 81 | raw_spin_unlock(&desc->lock); |
Uwe Kleine-König | 5e69b94 | 2008-02-29 13:27:53 +0100 | [diff] [blame] | 82 | |
| 83 | action_ret = handle_IRQ_event(irq, action); |
| 84 | |
Uwe Kleine-König | a57a0b1 | 2008-04-25 15:16:17 +0200 | [diff] [blame] | 85 | /* XXX: There is no direct way to access noirqdebug, so check |
| 86 | * unconditionally for spurious irqs... |
| 87 | * Maybe this function should go to kernel/irq/chip.c? */ |
| 88 | note_interrupt(irq, desc, action_ret); |
| 89 | |
Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 90 | raw_spin_lock(&desc->lock); |
Uwe Kleine-König | 5e69b94 | 2008-02-29 13:27:53 +0100 | [diff] [blame] | 91 | desc->status &= ~IRQ_INPROGRESS; |
Uwe Kleine-König | 5e69b94 | 2008-02-29 13:27:53 +0100 | [diff] [blame] | 92 | |
Uwe Kleine-König | a13c819 | 2008-04-25 15:03:18 +0200 | [diff] [blame] | 93 | if (desc->status & IRQ_DISABLED) |
| 94 | out_mask: |
| 95 | desc->chip->mask(irq); |
| 96 | |
| 97 | /* ack unconditionally to unmask lower prio irqs */ |
| 98 | desc->chip->ack(irq); |
| 99 | |
Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 100 | raw_spin_unlock(&desc->lock); |
Uwe Kleine-König | 5e69b94 | 2008-02-29 13:27:53 +0100 | [diff] [blame] | 101 | } |
| 102 | #define handle_irq handle_prio_irq |
| 103 | #endif |
| 104 | |
Uwe Kleine-König | 9918cda | 2007-02-16 15:36:55 +0100 | [diff] [blame] | 105 | void __init ns9xxx_init_irq(void) |
| 106 | { |
| 107 | int i; |
| 108 | |
| 109 | /* disable all IRQs */ |
| 110 | for (i = 0; i < 8; ++i) |
Uwe Kleine-König | ed6f598 | 2007-12-11 16:52:50 +0100 | [diff] [blame] | 111 | __raw_writel(prio2irq(4 * i) << 24 | |
| 112 | prio2irq(4 * i + 1) << 16 | |
| 113 | prio2irq(4 * i + 2) << 8 | |
| 114 | prio2irq(4 * i + 3), |
| 115 | SYS_IC(i)); |
Uwe Kleine-König | 9918cda | 2007-02-16 15:36:55 +0100 | [diff] [blame] | 116 | |
Uwe Kleine-König | 9918cda | 2007-02-16 15:36:55 +0100 | [diff] [blame] | 117 | for (i = 0; i < 32; ++i) |
Uwe Kleine-König | ed6f598 | 2007-12-11 16:52:50 +0100 | [diff] [blame] | 118 | __raw_writel(prio2irq(i), SYS_IVA(i)); |
Uwe Kleine-König | 9918cda | 2007-02-16 15:36:55 +0100 | [diff] [blame] | 119 | |
Uwe Kleine-König | 724ce5e | 2008-02-15 08:41:06 +0100 | [diff] [blame] | 120 | for (i = 0; i <= 31; ++i) { |
Uwe Kleine-König | 9918cda | 2007-02-16 15:36:55 +0100 | [diff] [blame] | 121 | set_irq_chip(i, &ns9xxx_chip); |
Uwe Kleine-König | 5e69b94 | 2008-02-29 13:27:53 +0100 | [diff] [blame] | 122 | set_irq_handler(i, handle_irq); |
Uwe Kleine-König | 9918cda | 2007-02-16 15:36:55 +0100 | [diff] [blame] | 123 | set_irq_flags(i, IRQF_VALID); |
| 124 | } |
| 125 | } |