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