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 | ed6f598 | 2007-12-11 16:52:50 +0100 | [diff] [blame^] | 22 | /* simple interrupt prio table: prio(x) < prio(y) <=> x < y */ |
| 23 | #define irq2prio(i) (i) |
| 24 | #define prio2irq(p) (p) |
| 25 | |
Uwe Kleine-König | 9918cda | 2007-02-16 15:36:55 +0100 | [diff] [blame] | 26 | static void ns9xxx_mask_irq(unsigned int irq) |
| 27 | { |
| 28 | /* XXX: better use cpp symbols */ |
Uwe Kleine-König | ed6f598 | 2007-12-11 16:52:50 +0100 | [diff] [blame^] | 29 | 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önig | 9918cda | 2007-02-16 15:36:55 +0100 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | static void ns9xxx_ack_irq(unsigned int irq) |
| 36 | { |
Uwe Kleine-König | 361c7ad | 2007-09-30 20:36:33 +0100 | [diff] [blame] | 37 | __raw_writel(0, SYS_ISRADDR); |
Uwe Kleine-König | 9918cda | 2007-02-16 15:36:55 +0100 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | static void ns9xxx_maskack_irq(unsigned int irq) |
| 41 | { |
| 42 | ns9xxx_mask_irq(irq); |
| 43 | ns9xxx_ack_irq(irq); |
| 44 | } |
| 45 | |
| 46 | static void ns9xxx_unmask_irq(unsigned int irq) |
| 47 | { |
| 48 | /* XXX: better use cpp symbols */ |
Uwe Kleine-König | ed6f598 | 2007-12-11 16:52:50 +0100 | [diff] [blame^] | 49 | 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önig | 9918cda | 2007-02-16 15:36:55 +0100 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | static 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önig | 5e69b94 | 2008-02-29 13:27:53 +0100 | [diff] [blame] | 62 | #if 0 |
| 63 | #define handle_irq handle_level_irq |
| 64 | #else |
| 65 | void handle_prio_irq(unsigned int irq, struct irq_desc *desc) |
| 66 | { |
| 67 | unsigned int cpu = smp_processor_id(); |
| 68 | struct irqaction *action; |
| 69 | irqreturn_t action_ret; |
| 70 | |
| 71 | spin_lock(&desc->lock); |
| 72 | |
| 73 | if (unlikely(desc->status & IRQ_INPROGRESS)) |
| 74 | goto out_unlock; |
| 75 | |
| 76 | desc->status &= ~(IRQ_REPLAY | IRQ_WAITING); |
| 77 | kstat_cpu(cpu).irqs[irq]++; |
| 78 | |
| 79 | action = desc->action; |
| 80 | if (unlikely(!action || (desc->status & IRQ_DISABLED))) |
| 81 | goto out_unlock; |
| 82 | |
| 83 | desc->status |= IRQ_INPROGRESS; |
| 84 | spin_unlock(&desc->lock); |
| 85 | |
| 86 | action_ret = handle_IRQ_event(irq, action); |
| 87 | |
| 88 | spin_lock(&desc->lock); |
| 89 | desc->status &= ~IRQ_INPROGRESS; |
| 90 | if (!(desc->status & IRQ_DISABLED) && desc->chip->ack) |
| 91 | desc->chip->ack(irq); |
| 92 | |
| 93 | out_unlock: |
| 94 | spin_unlock(&desc->lock); |
| 95 | } |
| 96 | #define handle_irq handle_prio_irq |
| 97 | #endif |
| 98 | |
Uwe Kleine-König | 9918cda | 2007-02-16 15:36:55 +0100 | [diff] [blame] | 99 | void __init ns9xxx_init_irq(void) |
| 100 | { |
| 101 | int i; |
| 102 | |
| 103 | /* disable all IRQs */ |
| 104 | for (i = 0; i < 8; ++i) |
Uwe Kleine-König | ed6f598 | 2007-12-11 16:52:50 +0100 | [diff] [blame^] | 105 | __raw_writel(prio2irq(4 * i) << 24 | |
| 106 | prio2irq(4 * i + 1) << 16 | |
| 107 | prio2irq(4 * i + 2) << 8 | |
| 108 | prio2irq(4 * i + 3), |
| 109 | SYS_IC(i)); |
Uwe Kleine-König | 9918cda | 2007-02-16 15:36:55 +0100 | [diff] [blame] | 110 | |
Uwe Kleine-König | 9918cda | 2007-02-16 15:36:55 +0100 | [diff] [blame] | 111 | for (i = 0; i < 32; ++i) |
Uwe Kleine-König | ed6f598 | 2007-12-11 16:52:50 +0100 | [diff] [blame^] | 112 | __raw_writel(prio2irq(i), SYS_IVA(i)); |
Uwe Kleine-König | 9918cda | 2007-02-16 15:36:55 +0100 | [diff] [blame] | 113 | |
Uwe Kleine-König | 724ce5e | 2008-02-15 08:41:06 +0100 | [diff] [blame] | 114 | for (i = 0; i <= 31; ++i) { |
Uwe Kleine-König | 9918cda | 2007-02-16 15:36:55 +0100 | [diff] [blame] | 115 | set_irq_chip(i, &ns9xxx_chip); |
Uwe Kleine-König | 5e69b94 | 2008-02-29 13:27:53 +0100 | [diff] [blame] | 116 | set_irq_handler(i, handle_irq); |
Uwe Kleine-König | 9918cda | 2007-02-16 15:36:55 +0100 | [diff] [blame] | 117 | set_irq_flags(i, IRQF_VALID); |
| 118 | } |
| 119 | } |