Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2002 Momentum Computer |
| 3 | * Author: mdharm@momenco.com |
Ralf Baechle | 27f7681 | 2006-10-09 00:03:05 +0100 | [diff] [blame] | 4 | * Copyright (C) 2004, 06 Ralf Baechle <ralf@linux-mips.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License as published by the |
| 8 | * Free Software Foundation; either version 2 of the License, or (at your |
| 9 | * option) any later version. |
| 10 | */ |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/interrupt.h> |
| 13 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/kernel_stat.h> |
Ralf Baechle | 3367fd5 | 2006-03-08 14:22:27 +0000 | [diff] [blame] | 15 | #include <linux/mv643xx.h> |
| 16 | #include <linux/sched.h> |
| 17 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <asm/io.h> |
| 19 | #include <asm/irq.h> |
Ralf Baechle | 3367fd5 | 2006-03-08 14:22:27 +0000 | [diff] [blame] | 20 | #include <asm/marvell.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
| 22 | static unsigned int irq_base; |
| 23 | |
| 24 | static inline int ls1bit32(unsigned int x) |
| 25 | { |
| 26 | int b = 31, s; |
| 27 | |
| 28 | s = 16; if (x << 16 == 0) s = 0; b -= s; x <<= s; |
| 29 | s = 8; if (x << 8 == 0) s = 0; b -= s; x <<= s; |
| 30 | s = 4; if (x << 4 == 0) s = 0; b -= s; x <<= s; |
| 31 | s = 2; if (x << 2 == 0) s = 0; b -= s; x <<= s; |
| 32 | s = 1; if (x << 1 == 0) s = 0; b -= s; |
| 33 | |
| 34 | return b; |
| 35 | } |
| 36 | |
| 37 | /* mask off an interrupt -- 1 is enable, 0 is disable */ |
| 38 | static inline void mask_mv64340_irq(unsigned int irq) |
| 39 | { |
| 40 | uint32_t value; |
| 41 | |
| 42 | if (irq < (irq_base + 32)) { |
| 43 | value = MV_READ(MV64340_INTERRUPT0_MASK_0_LOW); |
| 44 | value &= ~(1 << (irq - irq_base)); |
| 45 | MV_WRITE(MV64340_INTERRUPT0_MASK_0_LOW, value); |
| 46 | } else { |
| 47 | value = MV_READ(MV64340_INTERRUPT0_MASK_0_HIGH); |
| 48 | value &= ~(1 << (irq - irq_base - 32)); |
| 49 | MV_WRITE(MV64340_INTERRUPT0_MASK_0_HIGH, value); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | /* unmask an interrupt -- 1 is enable, 0 is disable */ |
| 54 | static inline void unmask_mv64340_irq(unsigned int irq) |
| 55 | { |
| 56 | uint32_t value; |
| 57 | |
| 58 | if (irq < (irq_base + 32)) { |
| 59 | value = MV_READ(MV64340_INTERRUPT0_MASK_0_LOW); |
| 60 | value |= 1 << (irq - irq_base); |
| 61 | MV_WRITE(MV64340_INTERRUPT0_MASK_0_LOW, value); |
| 62 | } else { |
| 63 | value = MV_READ(MV64340_INTERRUPT0_MASK_0_HIGH); |
| 64 | value |= 1 << (irq - irq_base - 32); |
| 65 | MV_WRITE(MV64340_INTERRUPT0_MASK_0_HIGH, value); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | * End IRQ processing |
| 71 | */ |
| 72 | static void end_mv64340_irq(unsigned int irq) |
| 73 | { |
| 74 | if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS))) |
| 75 | unmask_mv64340_irq(irq); |
| 76 | } |
| 77 | |
| 78 | /* |
| 79 | * Interrupt handler for interrupts coming from the Marvell chip. |
| 80 | * It could be built in ethernet ports etc... |
| 81 | */ |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 82 | void ll_mv64340_irq(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | { |
| 84 | unsigned int irq_src_low, irq_src_high; |
| 85 | unsigned int irq_mask_low, irq_mask_high; |
| 86 | |
| 87 | /* read the interrupt status registers */ |
| 88 | irq_mask_low = MV_READ(MV64340_INTERRUPT0_MASK_0_LOW); |
| 89 | irq_mask_high = MV_READ(MV64340_INTERRUPT0_MASK_0_HIGH); |
| 90 | irq_src_low = MV_READ(MV64340_MAIN_INTERRUPT_CAUSE_LOW); |
| 91 | irq_src_high = MV_READ(MV64340_MAIN_INTERRUPT_CAUSE_HIGH); |
| 92 | |
| 93 | /* mask for just the interrupts we want */ |
| 94 | irq_src_low &= irq_mask_low; |
| 95 | irq_src_high &= irq_mask_high; |
| 96 | |
| 97 | if (irq_src_low) |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 98 | do_IRQ(ls1bit32(irq_src_low) + irq_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | else |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 100 | do_IRQ(ls1bit32(irq_src_high) + irq_base + 32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Ralf Baechle | 94dee17 | 2006-07-02 14:41:42 +0100 | [diff] [blame] | 103 | struct irq_chip mv64340_irq_type = { |
Ralf Baechle | 8ab00b9 | 2005-02-28 13:39:57 +0000 | [diff] [blame] | 104 | .typename = "MV-64340", |
Atsushi Nemoto | 1603b5a | 2006-11-02 02:08:36 +0900 | [diff] [blame] | 105 | .ack = mask_mv64340_irq, |
| 106 | .mask = mask_mv64340_irq, |
| 107 | .mask_ack = mask_mv64340_irq, |
| 108 | .unmask = unmask_mv64340_irq, |
Ralf Baechle | 8ab00b9 | 2005-02-28 13:39:57 +0000 | [diff] [blame] | 109 | .end = end_mv64340_irq, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | void __init mv64340_irq_init(unsigned int base) |
| 113 | { |
| 114 | int i; |
| 115 | |
Atsushi Nemoto | 1603b5a | 2006-11-02 02:08:36 +0900 | [diff] [blame] | 116 | for (i = base; i < base + 64; i++) |
Atsushi Nemoto | 1417836 | 2006-11-14 01:13:18 +0900 | [diff] [blame^] | 117 | set_irq_chip_and_handler(i, &mv64340_irq_type, |
| 118 | handle_level_irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
| 120 | irq_base = base; |
| 121 | } |