Andrew Victor | c53c9cf | 2007-05-11 21:01:28 +0100 | [diff] [blame] | 1 | /* |
| 2 | * arch/arm/mach-ks8695/irq.c |
| 3 | * |
| 4 | * Copyright (C) 2006 Ben Dooks <ben@simtec.co.uk> |
| 5 | * Copyright (C) 2006 Simtec Electronics |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 | */ |
| 21 | |
| 22 | #include <linux/init.h> |
| 23 | #include <linux/module.h> |
| 24 | #include <linux/interrupt.h> |
| 25 | #include <linux/ioport.h> |
Kay Sievers | edbaa60 | 2011-12-21 16:26:03 -0800 | [diff] [blame] | 26 | #include <linux/device.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 27 | #include <linux/io.h> |
Andrew Victor | c53c9cf | 2007-05-11 21:01:28 +0100 | [diff] [blame] | 28 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 29 | #include <mach/hardware.h> |
Andrew Victor | c53c9cf | 2007-05-11 21:01:28 +0100 | [diff] [blame] | 30 | #include <asm/irq.h> |
Andrew Victor | c53c9cf | 2007-05-11 21:01:28 +0100 | [diff] [blame] | 31 | |
| 32 | #include <asm/mach/irq.h> |
| 33 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 34 | #include <mach/regs-irq.h> |
| 35 | #include <mach/regs-gpio.h> |
Andrew Victor | c53c9cf | 2007-05-11 21:01:28 +0100 | [diff] [blame] | 36 | |
Lennert Buytenhek | 3cdb791 | 2010-11-29 10:34:14 +0100 | [diff] [blame] | 37 | static void ks8695_irq_mask(struct irq_data *d) |
Andrew Victor | c53c9cf | 2007-05-11 21:01:28 +0100 | [diff] [blame] | 38 | { |
| 39 | unsigned long inten; |
| 40 | |
| 41 | inten = __raw_readl(KS8695_IRQ_VA + KS8695_INTEN); |
Lennert Buytenhek | 3cdb791 | 2010-11-29 10:34:14 +0100 | [diff] [blame] | 42 | inten &= ~(1 << d->irq); |
Andrew Victor | c53c9cf | 2007-05-11 21:01:28 +0100 | [diff] [blame] | 43 | |
| 44 | __raw_writel(inten, KS8695_IRQ_VA + KS8695_INTEN); |
| 45 | } |
| 46 | |
Lennert Buytenhek | 3cdb791 | 2010-11-29 10:34:14 +0100 | [diff] [blame] | 47 | static void ks8695_irq_unmask(struct irq_data *d) |
Andrew Victor | c53c9cf | 2007-05-11 21:01:28 +0100 | [diff] [blame] | 48 | { |
| 49 | unsigned long inten; |
| 50 | |
| 51 | inten = __raw_readl(KS8695_IRQ_VA + KS8695_INTEN); |
Lennert Buytenhek | 3cdb791 | 2010-11-29 10:34:14 +0100 | [diff] [blame] | 52 | inten |= (1 << d->irq); |
Andrew Victor | c53c9cf | 2007-05-11 21:01:28 +0100 | [diff] [blame] | 53 | |
| 54 | __raw_writel(inten, KS8695_IRQ_VA + KS8695_INTEN); |
| 55 | } |
| 56 | |
Lennert Buytenhek | 3cdb791 | 2010-11-29 10:34:14 +0100 | [diff] [blame] | 57 | static void ks8695_irq_ack(struct irq_data *d) |
Andrew Victor | c53c9cf | 2007-05-11 21:01:28 +0100 | [diff] [blame] | 58 | { |
Lennert Buytenhek | 3cdb791 | 2010-11-29 10:34:14 +0100 | [diff] [blame] | 59 | __raw_writel((1 << d->irq), KS8695_IRQ_VA + KS8695_INTST); |
Andrew Victor | c53c9cf | 2007-05-11 21:01:28 +0100 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | |
| 63 | static struct irq_chip ks8695_irq_level_chip; |
| 64 | static struct irq_chip ks8695_irq_edge_chip; |
| 65 | |
| 66 | |
Lennert Buytenhek | 3cdb791 | 2010-11-29 10:34:14 +0100 | [diff] [blame] | 67 | static int ks8695_irq_set_type(struct irq_data *d, unsigned int type) |
Andrew Victor | c53c9cf | 2007-05-11 21:01:28 +0100 | [diff] [blame] | 68 | { |
| 69 | unsigned long ctrl, mode; |
| 70 | unsigned short level_triggered = 0; |
| 71 | |
| 72 | ctrl = __raw_readl(KS8695_GPIO_VA + KS8695_IOPC); |
| 73 | |
| 74 | switch (type) { |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 75 | case IRQ_TYPE_LEVEL_HIGH: |
Andrew Victor | c53c9cf | 2007-05-11 21:01:28 +0100 | [diff] [blame] | 76 | mode = IOPC_TM_HIGH; |
| 77 | level_triggered = 1; |
| 78 | break; |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 79 | case IRQ_TYPE_LEVEL_LOW: |
Andrew Victor | c53c9cf | 2007-05-11 21:01:28 +0100 | [diff] [blame] | 80 | mode = IOPC_TM_LOW; |
| 81 | level_triggered = 1; |
| 82 | break; |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 83 | case IRQ_TYPE_EDGE_RISING: |
Andrew Victor | c53c9cf | 2007-05-11 21:01:28 +0100 | [diff] [blame] | 84 | mode = IOPC_TM_RISING; |
| 85 | break; |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 86 | case IRQ_TYPE_EDGE_FALLING: |
Andrew Victor | c53c9cf | 2007-05-11 21:01:28 +0100 | [diff] [blame] | 87 | mode = IOPC_TM_FALLING; |
| 88 | break; |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 89 | case IRQ_TYPE_EDGE_BOTH: |
Andrew Victor | c53c9cf | 2007-05-11 21:01:28 +0100 | [diff] [blame] | 90 | mode = IOPC_TM_EDGE; |
| 91 | break; |
| 92 | default: |
| 93 | return -EINVAL; |
| 94 | } |
| 95 | |
Lennert Buytenhek | 3cdb791 | 2010-11-29 10:34:14 +0100 | [diff] [blame] | 96 | switch (d->irq) { |
Andrew Victor | c53c9cf | 2007-05-11 21:01:28 +0100 | [diff] [blame] | 97 | case KS8695_IRQ_EXTERN0: |
| 98 | ctrl &= ~IOPC_IOEINT0TM; |
| 99 | ctrl |= IOPC_IOEINT0_MODE(mode); |
| 100 | break; |
| 101 | case KS8695_IRQ_EXTERN1: |
| 102 | ctrl &= ~IOPC_IOEINT1TM; |
| 103 | ctrl |= IOPC_IOEINT1_MODE(mode); |
| 104 | break; |
| 105 | case KS8695_IRQ_EXTERN2: |
| 106 | ctrl &= ~IOPC_IOEINT2TM; |
| 107 | ctrl |= IOPC_IOEINT2_MODE(mode); |
| 108 | break; |
| 109 | case KS8695_IRQ_EXTERN3: |
| 110 | ctrl &= ~IOPC_IOEINT3TM; |
| 111 | ctrl |= IOPC_IOEINT3_MODE(mode); |
| 112 | break; |
| 113 | default: |
| 114 | return -EINVAL; |
| 115 | } |
| 116 | |
| 117 | if (level_triggered) { |
Thomas Gleixner | f38c02f | 2011-03-24 13:35:09 +0100 | [diff] [blame] | 118 | irq_set_chip_and_handler(d->irq, &ks8695_irq_level_chip, |
| 119 | handle_level_irq); |
Andrew Victor | c53c9cf | 2007-05-11 21:01:28 +0100 | [diff] [blame] | 120 | } |
| 121 | else { |
Thomas Gleixner | f38c02f | 2011-03-24 13:35:09 +0100 | [diff] [blame] | 122 | irq_set_chip_and_handler(d->irq, &ks8695_irq_edge_chip, |
| 123 | handle_edge_irq); |
Andrew Victor | c53c9cf | 2007-05-11 21:01:28 +0100 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | __raw_writel(ctrl, KS8695_GPIO_VA + KS8695_IOPC); |
| 127 | return 0; |
| 128 | } |
| 129 | |
| 130 | static struct irq_chip ks8695_irq_level_chip = { |
Lennert Buytenhek | 3cdb791 | 2010-11-29 10:34:14 +0100 | [diff] [blame] | 131 | .irq_ack = ks8695_irq_mask, |
| 132 | .irq_mask = ks8695_irq_mask, |
| 133 | .irq_unmask = ks8695_irq_unmask, |
| 134 | .irq_set_type = ks8695_irq_set_type, |
Andrew Victor | c53c9cf | 2007-05-11 21:01:28 +0100 | [diff] [blame] | 135 | }; |
| 136 | |
| 137 | static struct irq_chip ks8695_irq_edge_chip = { |
Lennert Buytenhek | 3cdb791 | 2010-11-29 10:34:14 +0100 | [diff] [blame] | 138 | .irq_ack = ks8695_irq_ack, |
| 139 | .irq_mask = ks8695_irq_mask, |
| 140 | .irq_unmask = ks8695_irq_unmask, |
| 141 | .irq_set_type = ks8695_irq_set_type, |
Andrew Victor | c53c9cf | 2007-05-11 21:01:28 +0100 | [diff] [blame] | 142 | }; |
| 143 | |
| 144 | void __init ks8695_init_irq(void) |
| 145 | { |
| 146 | unsigned int irq; |
| 147 | |
| 148 | /* Disable all interrupts initially */ |
| 149 | __raw_writel(0, KS8695_IRQ_VA + KS8695_INTMC); |
| 150 | __raw_writel(0, KS8695_IRQ_VA + KS8695_INTEN); |
| 151 | |
| 152 | for (irq = 0; irq < NR_IRQS; irq++) { |
| 153 | switch (irq) { |
| 154 | /* Level-triggered interrupts */ |
| 155 | case KS8695_IRQ_BUS_ERROR: |
| 156 | case KS8695_IRQ_UART_MODEM_STATUS: |
| 157 | case KS8695_IRQ_UART_LINE_STATUS: |
| 158 | case KS8695_IRQ_UART_RX: |
| 159 | case KS8695_IRQ_COMM_TX: |
| 160 | case KS8695_IRQ_COMM_RX: |
Thomas Gleixner | f38c02f | 2011-03-24 13:35:09 +0100 | [diff] [blame] | 161 | irq_set_chip_and_handler(irq, |
| 162 | &ks8695_irq_level_chip, |
| 163 | handle_level_irq); |
Andrew Victor | c53c9cf | 2007-05-11 21:01:28 +0100 | [diff] [blame] | 164 | break; |
| 165 | |
| 166 | /* Edge-triggered interrupts */ |
| 167 | default: |
Lennert Buytenhek | 3cdb791 | 2010-11-29 10:34:14 +0100 | [diff] [blame] | 168 | /* clear pending bit */ |
| 169 | ks8695_irq_ack(irq_get_irq_data(irq)); |
Thomas Gleixner | f38c02f | 2011-03-24 13:35:09 +0100 | [diff] [blame] | 170 | irq_set_chip_and_handler(irq, |
| 171 | &ks8695_irq_edge_chip, |
| 172 | handle_edge_irq); |
Andrew Victor | c53c9cf | 2007-05-11 21:01:28 +0100 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | set_irq_flags(irq, IRQF_VALID); |
| 176 | } |
| 177 | } |