Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* -------------------------------------------------------------------- */ |
| 2 | /* setup_voyagergx.c: */ |
| 3 | /* -------------------------------------------------------------------- */ |
| 4 | /* This program is free software; you can redistribute it and/or modify |
| 5 | it under the terms of the GNU General Public License as published by |
| 6 | the Free Software Foundation; either version 2 of the License, or |
| 7 | (at your option) any later version. |
| 8 | |
| 9 | This program is distributed in the hope that it will be useful, |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | GNU General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU General Public License |
| 15 | along with this program; if not, write to the Free Software |
| 16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 17 | |
| 18 | Copyright 2003 (c) Lineo uSolutions,Inc. |
| 19 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/interrupt.h> |
| 21 | #include <linux/init.h> |
Paul Mundt | 082c44d | 2006-10-19 16:16:18 +0900 | [diff] [blame] | 22 | #include <linux/io.h> |
Paul Mundt | adf1890 | 2006-09-27 17:17:27 +0900 | [diff] [blame] | 23 | #include <asm/voyagergx.h> |
Paul Mundt | 082c44d | 2006-10-19 16:16:18 +0900 | [diff] [blame] | 24 | #include <asm/rts7751r2d.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
| 26 | static void disable_voyagergx_irq(unsigned int irq) |
| 27 | { |
Paul Mundt | 8599cf0 | 2006-09-27 18:03:34 +0900 | [diff] [blame] | 28 | unsigned long val; |
| 29 | unsigned long mask = 1 << (irq - VOYAGER_IRQ_BASE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
Paul Mundt | 63dfc3c | 2007-06-04 10:53:00 +0900 | [diff] [blame] | 31 | pr_debug("disable_voyagergx_irq(%d): mask=%lx\n", irq, mask); |
Paul Mundt | 9c57548 | 2007-02-15 18:20:52 +0900 | [diff] [blame] | 32 | val = readl((void __iomem *)VOYAGER_INT_MASK); |
| 33 | val &= ~mask; |
| 34 | writel(val, (void __iomem *)VOYAGER_INT_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | } |
| 36 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | static void enable_voyagergx_irq(unsigned int irq) |
| 38 | { |
Paul Mundt | 9c57548 | 2007-02-15 18:20:52 +0900 | [diff] [blame] | 39 | unsigned long val; |
| 40 | unsigned long mask = 1 << (irq - VOYAGER_IRQ_BASE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Paul Mundt | 63dfc3c | 2007-06-04 10:53:00 +0900 | [diff] [blame] | 42 | pr_debug("disable_voyagergx_irq(%d): mask=%lx\n", irq, mask); |
Paul Mundt | 9c57548 | 2007-02-15 18:20:52 +0900 | [diff] [blame] | 43 | val = readl((void __iomem *)VOYAGER_INT_MASK); |
| 44 | val |= mask; |
| 45 | writel(val, (void __iomem *)VOYAGER_INT_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | static void mask_and_ack_voyagergx(unsigned int irq) |
| 49 | { |
| 50 | disable_voyagergx_irq(irq); |
| 51 | } |
| 52 | |
| 53 | static void end_voyagergx_irq(unsigned int irq) |
| 54 | { |
| 55 | if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS))) |
| 56 | enable_voyagergx_irq(irq); |
| 57 | } |
| 58 | |
| 59 | static unsigned int startup_voyagergx_irq(unsigned int irq) |
| 60 | { |
| 61 | enable_voyagergx_irq(irq); |
| 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | static void shutdown_voyagergx_irq(unsigned int irq) |
| 66 | { |
| 67 | disable_voyagergx_irq(irq); |
| 68 | } |
| 69 | |
| 70 | static struct hw_interrupt_type voyagergx_irq_type = { |
Paul Mundt | 9c57548 | 2007-02-15 18:20:52 +0900 | [diff] [blame] | 71 | .typename = "VOYAGERGX-IRQ", |
| 72 | .startup = startup_voyagergx_irq, |
| 73 | .shutdown = shutdown_voyagergx_irq, |
| 74 | .enable = enable_voyagergx_irq, |
| 75 | .disable = disable_voyagergx_irq, |
| 76 | .ack = mask_and_ack_voyagergx, |
| 77 | .end = end_voyagergx_irq, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | }; |
| 79 | |
Paul Mundt | 35f3c51 | 2006-10-06 15:31:16 +0900 | [diff] [blame] | 80 | static irqreturn_t voyagergx_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | { |
| 82 | printk(KERN_INFO |
| 83 | "VoyagerGX: spurious interrupt, status: 0x%x\n", |
Paul Mundt | 9c57548 | 2007-02-15 18:20:52 +0900 | [diff] [blame] | 84 | (unsigned int)readl((void __iomem *)INT_STATUS)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | return IRQ_HANDLED; |
| 86 | } |
| 87 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | static struct { |
| 89 | int (*func)(int, void *); |
| 90 | void *dev; |
| 91 | } voyagergx_demux[VOYAGER_IRQ_NUM]; |
| 92 | |
| 93 | void voyagergx_register_irq_demux(int irq, |
| 94 | int (*demux)(int irq, void *dev), void *dev) |
| 95 | { |
Paul Mundt | 9c57548 | 2007-02-15 18:20:52 +0900 | [diff] [blame] | 96 | voyagergx_demux[irq - VOYAGER_IRQ_BASE].func = demux; |
| 97 | voyagergx_demux[irq - VOYAGER_IRQ_BASE].dev = dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | void voyagergx_unregister_irq_demux(int irq) |
| 101 | { |
Paul Mundt | 9c57548 | 2007-02-15 18:20:52 +0900 | [diff] [blame] | 102 | voyagergx_demux[irq - VOYAGER_IRQ_BASE].func = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | int voyagergx_irq_demux(int irq) |
| 106 | { |
| 107 | |
| 108 | if (irq == IRQ_VOYAGER ) { |
| 109 | unsigned long i = 0, bit __attribute__ ((unused)); |
Paul Mundt | 9c57548 | 2007-02-15 18:20:52 +0900 | [diff] [blame] | 110 | unsigned long val = readl((void __iomem *)INT_STATUS); |
| 111 | |
| 112 | if (val & (1 << 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | i = 1; |
Paul Mundt | 9c57548 | 2007-02-15 18:20:52 +0900 | [diff] [blame] | 114 | else if (val & (1 << 2)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | i = 2; |
Paul Mundt | 9c57548 | 2007-02-15 18:20:52 +0900 | [diff] [blame] | 116 | else if (val & (1 << 6)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | i = 6; |
Paul Mundt | 9c57548 | 2007-02-15 18:20:52 +0900 | [diff] [blame] | 118 | else if (val & (1 << 10)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | i = 10; |
Paul Mundt | 9c57548 | 2007-02-15 18:20:52 +0900 | [diff] [blame] | 120 | else if (val & (1 << 11)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | i = 11; |
Paul Mundt | 9c57548 | 2007-02-15 18:20:52 +0900 | [diff] [blame] | 122 | else if (val & (1 << 12)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | i = 12; |
Paul Mundt | 9c57548 | 2007-02-15 18:20:52 +0900 | [diff] [blame] | 124 | else if (val & (1 << 17)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | i = 17; |
Paul Mundt | 9c57548 | 2007-02-15 18:20:52 +0900 | [diff] [blame] | 126 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | printk("Unexpected IRQ irq = %d status = 0x%08lx\n", irq, val); |
Paul Mundt | 63dfc3c | 2007-06-04 10:53:00 +0900 | [diff] [blame] | 128 | pr_debug("voyagergx_irq_demux %ld \n", i); |
| 129 | if (i < VOYAGER_IRQ_NUM) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | irq = VOYAGER_IRQ_BASE + i; |
Paul Mundt | 63dfc3c | 2007-06-04 10:53:00 +0900 | [diff] [blame] | 131 | if (voyagergx_demux[i].func != 0) |
| 132 | irq = voyagergx_demux[i].func(irq, |
| 133 | voyagergx_demux[i].dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | } |
| 135 | } |
| 136 | return irq; |
| 137 | } |
| 138 | |
Paul Mundt | 37cc794 | 2006-02-01 03:06:05 -0800 | [diff] [blame] | 139 | static struct irqaction irq0 = { |
| 140 | .name = "voyagergx", |
| 141 | .handler = voyagergx_interrupt, |
Thomas Gleixner | 6d20819 | 2006-07-01 19:29:25 -0700 | [diff] [blame] | 142 | .flags = IRQF_DISABLED, |
Paul Mundt | 37cc794 | 2006-02-01 03:06:05 -0800 | [diff] [blame] | 143 | .mask = CPU_MASK_NONE, |
| 144 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
| 146 | void __init setup_voyagergx_irq(void) |
| 147 | { |
| 148 | int i, flag; |
| 149 | |
| 150 | printk(KERN_INFO "VoyagerGX configured at 0x%x on irq %d(mapped into %d to %d)\n", |
| 151 | VOYAGER_BASE, |
| 152 | IRQ_VOYAGER, |
| 153 | VOYAGER_IRQ_BASE, |
| 154 | VOYAGER_IRQ_BASE + VOYAGER_IRQ_NUM - 1); |
| 155 | |
| 156 | for (i=0; i<VOYAGER_IRQ_NUM; i++) { |
| 157 | flag = 0; |
| 158 | switch (VOYAGER_IRQ_BASE + i) { |
| 159 | case VOYAGER_USBH_IRQ: |
| 160 | case VOYAGER_8051_IRQ: |
| 161 | case VOYAGER_UART0_IRQ: |
| 162 | case VOYAGER_UART1_IRQ: |
| 163 | case VOYAGER_AC97_IRQ: |
| 164 | flag = 1; |
| 165 | } |
| 166 | if (flag == 1) |
Ingo Molnar | d1bef4e | 2006-06-29 02:24:36 -0700 | [diff] [blame] | 167 | irq_desc[VOYAGER_IRQ_BASE + i].chip = &voyagergx_irq_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | setup_irq(IRQ_VOYAGER, &irq0); |
| 171 | } |