blob: e95c5e74238deaecd03f149bafbb7951cc21ed9d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Lennert Buytenhekfa87ced2005-11-01 19:44:27 +00002 * arch/arm/mach-ixp2000/core.c
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * Common routines used by all IXP2400/2800 based platforms.
5 *
6 * Author: Deepak Saxena <dsaxena@plexity.net>
7 *
8 * Copyright 2004 (C) MontaVista Software, Inc.
9 *
10 * Based on work Copyright (C) 2002-2003 Intel Corporation
11 *
12 * This file is licensed under the terms of the GNU General Public
13 * License version 2. This program is licensed "as is" without any
14 * warranty of any kind, whether express or implied.
15 */
Russell King2f8163b2011-07-26 10:53:52 +010016#include <linux/gpio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/kernel.h>
18#include <linux/init.h>
19#include <linux/spinlock.h>
20#include <linux/sched.h>
21#include <linux/interrupt.h>
Thomas Gleixner64ffae82006-07-01 22:32:18 +010022#include <linux/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/serial.h>
24#include <linux/tty.h>
25#include <linux/bitops.h>
Lennert Buytenhek28187f22005-07-10 19:44:53 +010026#include <linux/serial_8250.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <linux/mm.h>
28
29#include <asm/types.h>
30#include <asm/setup.h>
31#include <asm/memory.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010032#include <mach/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <asm/irq.h>
34#include <asm/system.h>
35#include <asm/tlbflush.h>
36#include <asm/pgtable.h>
37
38#include <asm/mach/map.h>
39#include <asm/mach/time.h>
40#include <asm/mach/irq.h>
41
42static DEFINE_SPINLOCK(ixp2000_slowport_lock);
43static unsigned long ixp2000_slowport_irq_flags;
44
45/*************************************************************************
46 * Slowport access routines
47 *************************************************************************/
48void ixp2000_acquire_slowport(struct slowport_cfg *new_cfg, struct slowport_cfg *old_cfg)
49{
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 spin_lock_irqsave(&ixp2000_slowport_lock, ixp2000_slowport_irq_flags);
51
52 old_cfg->CCR = *IXP2000_SLOWPORT_CCR;
53 old_cfg->WTC = *IXP2000_SLOWPORT_WTC2;
54 old_cfg->RTC = *IXP2000_SLOWPORT_RTC2;
55 old_cfg->PCR = *IXP2000_SLOWPORT_PCR;
56 old_cfg->ADC = *IXP2000_SLOWPORT_ADC;
57
58 ixp2000_reg_write(IXP2000_SLOWPORT_CCR, new_cfg->CCR);
59 ixp2000_reg_write(IXP2000_SLOWPORT_WTC2, new_cfg->WTC);
60 ixp2000_reg_write(IXP2000_SLOWPORT_RTC2, new_cfg->RTC);
61 ixp2000_reg_write(IXP2000_SLOWPORT_PCR, new_cfg->PCR);
Lennert Buytenheke9b72e42005-11-01 19:44:26 +000062 ixp2000_reg_wrb(IXP2000_SLOWPORT_ADC, new_cfg->ADC);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063}
64
65void ixp2000_release_slowport(struct slowport_cfg *old_cfg)
66{
67 ixp2000_reg_write(IXP2000_SLOWPORT_CCR, old_cfg->CCR);
68 ixp2000_reg_write(IXP2000_SLOWPORT_WTC2, old_cfg->WTC);
69 ixp2000_reg_write(IXP2000_SLOWPORT_RTC2, old_cfg->RTC);
70 ixp2000_reg_write(IXP2000_SLOWPORT_PCR, old_cfg->PCR);
Lennert Buytenheke9b72e42005-11-01 19:44:26 +000071 ixp2000_reg_wrb(IXP2000_SLOWPORT_ADC, old_cfg->ADC);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
73 spin_unlock_irqrestore(&ixp2000_slowport_lock,
74 ixp2000_slowport_irq_flags);
75}
76
77/*************************************************************************
78 * Chip specific mappings shared by all IXP2000 systems
79 *************************************************************************/
80static struct map_desc ixp2000_io_desc[] __initdata = {
81 {
82 .virtual = IXP2000_CAP_VIRT_BASE,
Deepak Saxenadb0d0872005-10-28 15:18:58 +010083 .pfn = __phys_to_pfn(IXP2000_CAP_PHYS_BASE),
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 .length = IXP2000_CAP_SIZE,
Russell Kingdb5b7162008-09-07 12:42:51 +010085 .type = MT_DEVICE,
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 }, {
87 .virtual = IXP2000_INTCTL_VIRT_BASE,
Deepak Saxenadb0d0872005-10-28 15:18:58 +010088 .pfn = __phys_to_pfn(IXP2000_INTCTL_PHYS_BASE),
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 .length = IXP2000_INTCTL_SIZE,
Russell Kingdb5b7162008-09-07 12:42:51 +010090 .type = MT_DEVICE,
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 }, {
92 .virtual = IXP2000_PCI_CREG_VIRT_BASE,
Deepak Saxenadb0d0872005-10-28 15:18:58 +010093 .pfn = __phys_to_pfn(IXP2000_PCI_CREG_PHYS_BASE),
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 .length = IXP2000_PCI_CREG_SIZE,
Russell Kingdb5b7162008-09-07 12:42:51 +010095 .type = MT_DEVICE,
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 }, {
97 .virtual = IXP2000_PCI_CSR_VIRT_BASE,
Deepak Saxenadb0d0872005-10-28 15:18:58 +010098 .pfn = __phys_to_pfn(IXP2000_PCI_CSR_PHYS_BASE),
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 .length = IXP2000_PCI_CSR_SIZE,
Russell Kingdb5b7162008-09-07 12:42:51 +0100100 .type = MT_DEVICE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 }, {
Lennert Buytenhekbaaf7ed12005-06-26 22:24:17 +0100102 .virtual = IXP2000_MSF_VIRT_BASE,
Deepak Saxenadb0d0872005-10-28 15:18:58 +0100103 .pfn = __phys_to_pfn(IXP2000_MSF_PHYS_BASE),
Lennert Buytenhekbaaf7ed12005-06-26 22:24:17 +0100104 .length = IXP2000_MSF_SIZE,
Russell Kingdb5b7162008-09-07 12:42:51 +0100105 .type = MT_DEVICE,
Lennert Buytenhekbaaf7ed12005-06-26 22:24:17 +0100106 }, {
Lennert Buytenhekdd29c722006-01-13 20:51:43 +0000107 .virtual = IXP2000_SCRATCH_RING_VIRT_BASE,
108 .pfn = __phys_to_pfn(IXP2000_SCRATCH_RING_PHYS_BASE),
109 .length = IXP2000_SCRATCH_RING_SIZE,
Russell Kingdb5b7162008-09-07 12:42:51 +0100110 .type = MT_DEVICE,
Lennert Buytenhekdd29c722006-01-13 20:51:43 +0000111 }, {
112 .virtual = IXP2000_SRAM0_VIRT_BASE,
113 .pfn = __phys_to_pfn(IXP2000_SRAM0_PHYS_BASE),
114 .length = IXP2000_SRAM0_SIZE,
Russell Kingdb5b7162008-09-07 12:42:51 +0100115 .type = MT_DEVICE,
Lennert Buytenhekdd29c722006-01-13 20:51:43 +0000116 }, {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 .virtual = IXP2000_PCI_IO_VIRT_BASE,
Deepak Saxenadb0d0872005-10-28 15:18:58 +0100118 .pfn = __phys_to_pfn(IXP2000_PCI_IO_PHYS_BASE),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 .length = IXP2000_PCI_IO_SIZE,
Russell Kingdb5b7162008-09-07 12:42:51 +0100120 .type = MT_DEVICE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 }, {
122 .virtual = IXP2000_PCI_CFG0_VIRT_BASE,
Deepak Saxenadb0d0872005-10-28 15:18:58 +0100123 .pfn = __phys_to_pfn(IXP2000_PCI_CFG0_PHYS_BASE),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 .length = IXP2000_PCI_CFG0_SIZE,
Russell Kingdb5b7162008-09-07 12:42:51 +0100125 .type = MT_DEVICE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 }, {
127 .virtual = IXP2000_PCI_CFG1_VIRT_BASE,
Deepak Saxenadb0d0872005-10-28 15:18:58 +0100128 .pfn = __phys_to_pfn(IXP2000_PCI_CFG1_PHYS_BASE),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 .length = IXP2000_PCI_CFG1_SIZE,
Russell Kingdb5b7162008-09-07 12:42:51 +0100130 .type = MT_DEVICE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 }
132};
133
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134void __init ixp2000_map_io(void)
135{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 iotable_init(ixp2000_io_desc, ARRAY_SIZE(ixp2000_io_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
138 /* Set slowport to 8-bit mode. */
Lennert Buytenheke9b72e42005-11-01 19:44:26 +0000139 ixp2000_reg_wrb(IXP2000_SLOWPORT_FRM, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140}
141
Lennert Buytenhek28187f22005-07-10 19:44:53 +0100142
143/*************************************************************************
144 * Serial port support for IXP2000
145 *************************************************************************/
146static struct plat_serial8250_port ixp2000_serial_port[] = {
147 {
148 .mapbase = IXP2000_UART_PHYS_BASE,
149 .membase = (char *)(IXP2000_UART_VIRT_BASE + 3),
150 .irq = IRQ_IXP2000_UART,
151 .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
152 .iotype = UPIO_MEM,
153 .regshift = 2,
154 .uartclk = 50000000,
155 },
156 { },
157};
158
159static struct resource ixp2000_uart_resource = {
160 .start = IXP2000_UART_PHYS_BASE,
Deepak Saxena702c96d52005-09-30 16:20:22 -0700161 .end = IXP2000_UART_PHYS_BASE + 0x1f,
Lennert Buytenhek28187f22005-07-10 19:44:53 +0100162 .flags = IORESOURCE_MEM,
163};
164
165static struct platform_device ixp2000_serial_device = {
166 .name = "serial8250",
Russell King6df29de2005-09-08 16:04:41 +0100167 .id = PLAT8250_DEV_PLATFORM,
Lennert Buytenhek28187f22005-07-10 19:44:53 +0100168 .dev = {
169 .platform_data = ixp2000_serial_port,
170 },
171 .num_resources = 1,
172 .resource = &ixp2000_uart_resource,
173};
174
175void __init ixp2000_uart_init(void)
176{
177 platform_device_register(&ixp2000_serial_device);
178}
179
180
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181/*************************************************************************
182 * Timer-tick functions for IXP2000
183 *************************************************************************/
184static unsigned ticks_per_jiffy;
185static unsigned ticks_per_usec;
186static unsigned next_jiffy_time;
Lennert Buytenheke4fe1982005-06-20 18:51:07 +0100187static volatile unsigned long *missing_jiffy_timer_csr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
189unsigned long ixp2000_gettimeoffset (void)
190{
191 unsigned long offset;
192
Lennert Buytenheke4fe1982005-06-20 18:51:07 +0100193 offset = next_jiffy_time - *missing_jiffy_timer_csr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
195 return offset / ticks_per_usec;
196}
197
Uwe Kleine-Königd463f362010-10-19 09:43:59 +0100198static irqreturn_t ixp2000_timer_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 /* clear timer 1 */
Lennert Buytenheke9b72e42005-11-01 19:44:26 +0000201 ixp2000_reg_wrb(IXP2000_T1_CLR, 1);
Lennert Buytenhekc4982882005-06-24 20:54:35 +0100202
Lennert Buytenhekf869afa2006-06-22 10:30:53 +0100203 while ((signed long)(next_jiffy_time - *missing_jiffy_timer_csr)
204 >= ticks_per_jiffy) {
Linus Torvalds0cd61b62006-10-06 10:53:39 -0700205 timer_tick();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 next_jiffy_time -= ticks_per_jiffy;
207 }
208
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 return IRQ_HANDLED;
210}
211
212static struct irqaction ixp2000_timer_irq = {
213 .name = "IXP2000 Timer Tick",
Bernhard Walleb30faba2007-05-08 00:35:39 -0700214 .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
Russell King09b8b5f2005-06-26 17:06:36 +0100215 .handler = ixp2000_timer_interrupt,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216};
217
218void __init ixp2000_init_time(unsigned long tick_rate)
219{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 ticks_per_jiffy = (tick_rate + HZ/2) / HZ;
221 ticks_per_usec = tick_rate / 1000000;
222
Lennert Buytenheke4fe1982005-06-20 18:51:07 +0100223 /*
224 * We use timer 1 as our timer interrupt.
225 */
226 ixp2000_reg_write(IXP2000_T1_CLR, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 ixp2000_reg_write(IXP2000_T1_CLD, ticks_per_jiffy - 1);
228 ixp2000_reg_write(IXP2000_T1_CTL, (1 << 7));
229
230 /*
Lennert Buytenheke4fe1982005-06-20 18:51:07 +0100231 * We use a second timer as a monotonic counter for tracking
232 * missed jiffies. The IXP2000 has four timers, but if we're
233 * on an A-step IXP2800, timer 2 and 3 don't work, so on those
234 * chips we use timer 4. Timer 4 is the only timer that can
235 * be used for the watchdog, so we use timer 2 if we're on a
236 * non-buggy chip.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 */
Lennert Buytenheke4fe1982005-06-20 18:51:07 +0100238 if ((*IXP2000_PRODUCT_ID & 0x001ffef0) == 0x00000000) {
239 printk(KERN_INFO "Enabling IXP2800 erratum #25 workaround\n");
240
241 ixp2000_reg_write(IXP2000_T4_CLR, 0);
242 ixp2000_reg_write(IXP2000_T4_CLD, -1);
Lennert Buytenheke9b72e42005-11-01 19:44:26 +0000243 ixp2000_reg_wrb(IXP2000_T4_CTL, (1 << 7));
Lennert Buytenheke4fe1982005-06-20 18:51:07 +0100244 missing_jiffy_timer_csr = IXP2000_T4_CSR;
245 } else {
246 ixp2000_reg_write(IXP2000_T2_CLR, 0);
247 ixp2000_reg_write(IXP2000_T2_CLD, -1);
Lennert Buytenheke9b72e42005-11-01 19:44:26 +0000248 ixp2000_reg_wrb(IXP2000_T2_CTL, (1 << 7));
Lennert Buytenheke4fe1982005-06-20 18:51:07 +0100249 missing_jiffy_timer_csr = IXP2000_T2_CSR;
250 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 next_jiffy_time = 0xffffffff;
252
253 /* register for interrupt */
254 setup_irq(IRQ_IXP2000_TIMER1, &ixp2000_timer_irq);
255}
256
257/*************************************************************************
258 * GPIO helpers
259 *************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260static unsigned long GPIO_IRQ_falling_edge;
Lennert Buytenhekc4982882005-06-24 20:54:35 +0100261static unsigned long GPIO_IRQ_rising_edge;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262static unsigned long GPIO_IRQ_level_low;
263static unsigned long GPIO_IRQ_level_high;
264
Lennert Buytenhekc4982882005-06-24 20:54:35 +0100265static void update_gpio_int_csrs(void)
266{
267 ixp2000_reg_write(IXP2000_GPIO_FEDR, GPIO_IRQ_falling_edge);
268 ixp2000_reg_write(IXP2000_GPIO_REDR, GPIO_IRQ_rising_edge);
269 ixp2000_reg_write(IXP2000_GPIO_LSLR, GPIO_IRQ_level_low);
Lennert Buytenheke9b72e42005-11-01 19:44:26 +0000270 ixp2000_reg_wrb(IXP2000_GPIO_LSHR, GPIO_IRQ_level_high);
Lennert Buytenhekc4982882005-06-24 20:54:35 +0100271}
272
273void gpio_line_config(int line, int direction)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274{
275 unsigned long flags;
276
277 local_irq_save(flags);
Lennert Buytenhekc4982882005-06-24 20:54:35 +0100278 if (direction == GPIO_OUT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 /* if it's an output, it ain't an interrupt anymore */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 GPIO_IRQ_falling_edge &= ~(1 << line);
281 GPIO_IRQ_rising_edge &= ~(1 << line);
282 GPIO_IRQ_level_low &= ~(1 << line);
283 GPIO_IRQ_level_high &= ~(1 << line);
Lennert Buytenhekc4982882005-06-24 20:54:35 +0100284 update_gpio_int_csrs();
285
Lennert Buytenheke9b72e42005-11-01 19:44:26 +0000286 ixp2000_reg_wrb(IXP2000_GPIO_PDSR, 1 << line);
Lennert Buytenhekc4982882005-06-24 20:54:35 +0100287 } else if (direction == GPIO_IN) {
Lennert Buytenheke9b72e42005-11-01 19:44:26 +0000288 ixp2000_reg_wrb(IXP2000_GPIO_PDCR, 1 << line);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 local_irq_restore(flags);
Lennert Buytenhekc4982882005-06-24 20:54:35 +0100291}
Lennert Buytenhekfc8ea7a2006-06-24 09:57:14 +0100292EXPORT_SYMBOL(gpio_line_config);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
294
295/*************************************************************************
296 * IRQ handling IXP2000
297 *************************************************************************/
Russell King10dd5ce2006-11-23 11:41:32 +0000298static void ixp2000_GPIO_irq_handler(unsigned int irq, struct irq_desc *desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299{
300 int i;
301 unsigned long status = *IXP2000_GPIO_INST;
302
303 for (i = 0; i <= 7; i++) {
304 if (status & (1<<i)) {
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +0100305 generic_handle_irq(i + IRQ_IXP2000_GPIO0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 }
307 }
308}
309
Lennert Buytenhek6e8f54f2010-11-29 10:32:55 +0100310static int ixp2000_GPIO_irq_type(struct irq_data *d, unsigned int type)
Lennert Buytenhekc4982882005-06-24 20:54:35 +0100311{
Lennert Buytenhek6e8f54f2010-11-29 10:32:55 +0100312 int line = d->irq - IRQ_IXP2000_GPIO0;
Lennert Buytenhekc4982882005-06-24 20:54:35 +0100313
314 /*
315 * First, configure this GPIO line as an input.
316 */
317 ixp2000_reg_write(IXP2000_GPIO_PDCR, 1 << line);
318
319 /*
320 * Then, set the proper trigger type.
321 */
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100322 if (type & IRQ_TYPE_EDGE_FALLING)
Lennert Buytenhekc4982882005-06-24 20:54:35 +0100323 GPIO_IRQ_falling_edge |= 1 << line;
324 else
325 GPIO_IRQ_falling_edge &= ~(1 << line);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100326 if (type & IRQ_TYPE_EDGE_RISING)
Lennert Buytenhekc4982882005-06-24 20:54:35 +0100327 GPIO_IRQ_rising_edge |= 1 << line;
328 else
329 GPIO_IRQ_rising_edge &= ~(1 << line);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100330 if (type & IRQ_TYPE_LEVEL_LOW)
Lennert Buytenhekc4982882005-06-24 20:54:35 +0100331 GPIO_IRQ_level_low |= 1 << line;
332 else
333 GPIO_IRQ_level_low &= ~(1 << line);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100334 if (type & IRQ_TYPE_LEVEL_HIGH)
Lennert Buytenhekc4982882005-06-24 20:54:35 +0100335 GPIO_IRQ_level_high |= 1 << line;
336 else
337 GPIO_IRQ_level_high &= ~(1 << line);
338 update_gpio_int_csrs();
339
Lennert Buytenhekc4982882005-06-24 20:54:35 +0100340 return 0;
341}
342
Lennert Buytenhek6e8f54f2010-11-29 10:32:55 +0100343static void ixp2000_GPIO_irq_mask_ack(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344{
Lennert Buytenhek6e8f54f2010-11-29 10:32:55 +0100345 unsigned int irq = d->irq;
346
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 ixp2000_reg_write(IXP2000_GPIO_INCR, (1 << (irq - IRQ_IXP2000_GPIO0)));
Lennert Buytenhekc4982882005-06-24 20:54:35 +0100348
349 ixp2000_reg_write(IXP2000_GPIO_EDSR, (1 << (irq - IRQ_IXP2000_GPIO0)));
350 ixp2000_reg_write(IXP2000_GPIO_LDSR, (1 << (irq - IRQ_IXP2000_GPIO0)));
Lennert Buytenheke9b72e42005-11-01 19:44:26 +0000351 ixp2000_reg_wrb(IXP2000_GPIO_INST, (1 << (irq - IRQ_IXP2000_GPIO0)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352}
353
Lennert Buytenhek6e8f54f2010-11-29 10:32:55 +0100354static void ixp2000_GPIO_irq_mask(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355{
Lennert Buytenhek6e8f54f2010-11-29 10:32:55 +0100356 unsigned int irq = d->irq;
357
Lennert Buytenheke9b72e42005-11-01 19:44:26 +0000358 ixp2000_reg_wrb(IXP2000_GPIO_INCR, (1 << (irq - IRQ_IXP2000_GPIO0)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359}
360
Lennert Buytenhek6e8f54f2010-11-29 10:32:55 +0100361static void ixp2000_GPIO_irq_unmask(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362{
Lennert Buytenhek6e8f54f2010-11-29 10:32:55 +0100363 unsigned int irq = d->irq;
364
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 ixp2000_reg_write(IXP2000_GPIO_INSR, (1 << (irq - IRQ_IXP2000_GPIO0)));
366}
367
Russell King10dd5ce2006-11-23 11:41:32 +0000368static struct irq_chip ixp2000_GPIO_irq_chip = {
Lennert Buytenhek6e8f54f2010-11-29 10:32:55 +0100369 .irq_ack = ixp2000_GPIO_irq_mask_ack,
370 .irq_mask = ixp2000_GPIO_irq_mask,
371 .irq_unmask = ixp2000_GPIO_irq_unmask,
372 .irq_set_type = ixp2000_GPIO_irq_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373};
374
Lennert Buytenhek6e8f54f2010-11-29 10:32:55 +0100375static void ixp2000_pci_irq_mask(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376{
377 unsigned long temp = *IXP2000_PCI_XSCALE_INT_ENABLE;
Lennert Buytenhek6e8f54f2010-11-29 10:32:55 +0100378 if (d->irq == IRQ_IXP2000_PCIA)
Lennert Buytenheke9b72e42005-11-01 19:44:26 +0000379 ixp2000_reg_wrb(IXP2000_PCI_XSCALE_INT_ENABLE, (temp & ~(1 << 26)));
Lennert Buytenhek6e8f54f2010-11-29 10:32:55 +0100380 else if (d->irq == IRQ_IXP2000_PCIB)
Lennert Buytenheke9b72e42005-11-01 19:44:26 +0000381 ixp2000_reg_wrb(IXP2000_PCI_XSCALE_INT_ENABLE, (temp & ~(1 << 27)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382}
383
Lennert Buytenhek6e8f54f2010-11-29 10:32:55 +0100384static void ixp2000_pci_irq_unmask(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385{
386 unsigned long temp = *IXP2000_PCI_XSCALE_INT_ENABLE;
Lennert Buytenhek6e8f54f2010-11-29 10:32:55 +0100387 if (d->irq == IRQ_IXP2000_PCIA)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 ixp2000_reg_write(IXP2000_PCI_XSCALE_INT_ENABLE, (temp | (1 << 26)));
Lennert Buytenhek6e8f54f2010-11-29 10:32:55 +0100389 else if (d->irq == IRQ_IXP2000_PCIB)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 ixp2000_reg_write(IXP2000_PCI_XSCALE_INT_ENABLE, (temp | (1 << 27)));
391}
392
Dave Jiang7866f642005-11-04 17:15:44 +0000393/*
394 * Error interrupts. These are used extensively by the microengine drivers
395 */
Russell King10dd5ce2006-11-23 11:41:32 +0000396static void ixp2000_err_irq_handler(unsigned int irq, struct irq_desc *desc)
Dave Jiang7866f642005-11-04 17:15:44 +0000397{
398 int i;
399 unsigned long status = *IXP2000_IRQ_ERR_STATUS;
400
401 for(i = 31; i >= 0; i--) {
402 if(status & (1 << i)) {
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +0100403 generic_handle_irq(IRQ_IXP2000_DRAM0_MIN_ERR + i);
Dave Jiang7866f642005-11-04 17:15:44 +0000404 }
405 }
406}
407
Lennert Buytenhek6e8f54f2010-11-29 10:32:55 +0100408static void ixp2000_err_irq_mask(struct irq_data *d)
Dave Jiang7866f642005-11-04 17:15:44 +0000409{
410 ixp2000_reg_write(IXP2000_IRQ_ERR_ENABLE_CLR,
Lennert Buytenhek6e8f54f2010-11-29 10:32:55 +0100411 (1 << (d->irq - IRQ_IXP2000_DRAM0_MIN_ERR)));
Dave Jiang7866f642005-11-04 17:15:44 +0000412}
413
Lennert Buytenhek6e8f54f2010-11-29 10:32:55 +0100414static void ixp2000_err_irq_unmask(struct irq_data *d)
Dave Jiang7866f642005-11-04 17:15:44 +0000415{
416 ixp2000_reg_write(IXP2000_IRQ_ERR_ENABLE_SET,
Lennert Buytenhek6e8f54f2010-11-29 10:32:55 +0100417 (1 << (d->irq - IRQ_IXP2000_DRAM0_MIN_ERR)));
Dave Jiang7866f642005-11-04 17:15:44 +0000418}
419
Russell King10dd5ce2006-11-23 11:41:32 +0000420static struct irq_chip ixp2000_err_irq_chip = {
Lennert Buytenhek6e8f54f2010-11-29 10:32:55 +0100421 .irq_ack = ixp2000_err_irq_mask,
422 .irq_mask = ixp2000_err_irq_mask,
423 .irq_unmask = ixp2000_err_irq_unmask
Dave Jiang7866f642005-11-04 17:15:44 +0000424};
425
Russell King10dd5ce2006-11-23 11:41:32 +0000426static struct irq_chip ixp2000_pci_irq_chip = {
Lennert Buytenhek6e8f54f2010-11-29 10:32:55 +0100427 .irq_ack = ixp2000_pci_irq_mask,
428 .irq_mask = ixp2000_pci_irq_mask,
429 .irq_unmask = ixp2000_pci_irq_unmask
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430};
431
Lennert Buytenhek6e8f54f2010-11-29 10:32:55 +0100432static void ixp2000_irq_mask(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433{
Lennert Buytenhek6e8f54f2010-11-29 10:32:55 +0100434 ixp2000_reg_wrb(IXP2000_IRQ_ENABLE_CLR, (1 << d->irq));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435}
436
Lennert Buytenhek6e8f54f2010-11-29 10:32:55 +0100437static void ixp2000_irq_unmask(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438{
Lennert Buytenhek6e8f54f2010-11-29 10:32:55 +0100439 ixp2000_reg_write(IXP2000_IRQ_ENABLE_SET, (1 << d->irq));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440}
441
Russell King10dd5ce2006-11-23 11:41:32 +0000442static struct irq_chip ixp2000_irq_chip = {
Lennert Buytenhek6e8f54f2010-11-29 10:32:55 +0100443 .irq_ack = ixp2000_irq_mask,
444 .irq_mask = ixp2000_irq_mask,
445 .irq_unmask = ixp2000_irq_unmask
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446};
447
448void __init ixp2000_init_irq(void)
449{
450 int irq;
451
452 /*
453 * Mask all sources
454 */
455 ixp2000_reg_write(IXP2000_IRQ_ENABLE_CLR, 0xffffffff);
456 ixp2000_reg_write(IXP2000_FIQ_ENABLE_CLR, 0xffffffff);
457
458 /* clear all GPIO edge/level detects */
459 ixp2000_reg_write(IXP2000_GPIO_REDR, 0);
460 ixp2000_reg_write(IXP2000_GPIO_FEDR, 0);
461 ixp2000_reg_write(IXP2000_GPIO_LSHR, 0);
462 ixp2000_reg_write(IXP2000_GPIO_LSLR, 0);
463 ixp2000_reg_write(IXP2000_GPIO_INCR, -1);
464
465 /* clear PCI interrupt sources */
Lennert Buytenheke9b72e42005-11-01 19:44:26 +0000466 ixp2000_reg_wrb(IXP2000_PCI_XSCALE_INT_ENABLE, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
468 /*
469 * Certain bits in the IRQ status register of the
470 * IXP2000 are reserved. Instead of trying to map
471 * things non 1:1 from bit position to IRQ number,
472 * we mark the reserved IRQs as invalid. This makes
473 * our mask/unmask code much simpler.
474 */
475 for (irq = IRQ_IXP2000_SOFT_INT; irq <= IRQ_IXP2000_THDB3; irq++) {
Lennert Buytenhekc4982882005-06-24 20:54:35 +0100476 if ((1 << irq) & IXP2000_VALID_IRQ_MASK) {
Thomas Gleixnerf38c02f2011-03-24 13:35:09 +0100477 irq_set_chip_and_handler(irq, &ixp2000_irq_chip,
478 handle_level_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 set_irq_flags(irq, IRQF_VALID);
480 } else set_irq_flags(irq, 0);
481 }
Lennert Buytenhekc4982882005-06-24 20:54:35 +0100482
Dave Jiang7866f642005-11-04 17:15:44 +0000483 for (irq = IRQ_IXP2000_DRAM0_MIN_ERR; irq <= IRQ_IXP2000_SP_INT; irq++) {
484 if((1 << (irq - IRQ_IXP2000_DRAM0_MIN_ERR)) &
485 IXP2000_VALID_ERR_IRQ_MASK) {
Thomas Gleixnerf38c02f2011-03-24 13:35:09 +0100486 irq_set_chip_and_handler(irq, &ixp2000_err_irq_chip,
487 handle_level_irq);
Dave Jiang7866f642005-11-04 17:15:44 +0000488 set_irq_flags(irq, IRQF_VALID);
489 }
490 else
491 set_irq_flags(irq, 0);
492 }
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100493 irq_set_chained_handler(IRQ_IXP2000_ERRSUM, ixp2000_err_irq_handler);
Dave Jiang7866f642005-11-04 17:15:44 +0000494
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 for (irq = IRQ_IXP2000_GPIO0; irq <= IRQ_IXP2000_GPIO7; irq++) {
Thomas Gleixnerf38c02f2011-03-24 13:35:09 +0100496 irq_set_chip_and_handler(irq, &ixp2000_GPIO_irq_chip,
497 handle_level_irq);
Lennert Buytenhekbd115ea2006-03-22 20:14:09 +0000498 set_irq_flags(irq, IRQF_VALID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 }
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100500 irq_set_chained_handler(IRQ_IXP2000_GPIO, ixp2000_GPIO_irq_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501
502 /*
503 * Enable PCI irqs. The actual PCI[AB] decoding is done in
504 * entry-macro.S, so we don't need a chained handler for the
505 * PCI interrupt source.
506 */
507 ixp2000_reg_write(IXP2000_IRQ_ENABLE_SET, (1 << IRQ_IXP2000_PCI));
508 for (irq = IRQ_IXP2000_PCIA; irq <= IRQ_IXP2000_PCIB; irq++) {
Thomas Gleixnerf38c02f2011-03-24 13:35:09 +0100509 irq_set_chip_and_handler(irq, &ixp2000_pci_irq_chip,
510 handle_level_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 set_irq_flags(irq, IRQF_VALID);
512 }
513}
514