2 * Copyright (C) 2006, 2008 Atmel Corporation
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
10 #include <linux/err.h>
11 #include <linux/init.h>
12 #include <linux/interrupt.h>
13 #include <linux/irq.h>
14 #include <linux/platform_device.h>
15 #include <linux/sysdev.h>
24 struct sys_device sysdev
;
26 unsigned long suspend_ipr
;
27 unsigned long saved_ipr
[64];
31 extern struct platform_device at32_intc0_device
;
34 * TODO: We may be able to implement mask/unmask by setting IxM flags
35 * in the status register.
37 static void intc_mask_irq(unsigned int irq
)
42 static void intc_unmask_irq(unsigned int irq
)
47 static struct intc intc0
= {
50 .mask
= intc_mask_irq
,
51 .unmask
= intc_unmask_irq
,
56 * All interrupts go via intc at some point.
58 asmlinkage
void do_IRQ(int level
, struct pt_regs
*regs
)
60 struct irq_desc
*desc
;
61 struct pt_regs
*old_regs
;
63 unsigned long status_reg
;
67 old_regs
= set_irq_regs(regs
);
71 irq
= intc_readl(&intc0
, INTCAUSE0
- 4 * level
);
72 desc
= irq_desc
+ irq
;
73 desc
->handle_irq(irq
, desc
);
76 * Clear all interrupt level masks so that we may handle
77 * interrupts during softirq processing. If this is a nested
78 * interrupt, interrupts must stay globally disabled until we
81 status_reg
= sysreg_read(SR
);
82 status_reg
&= ~(SYSREG_BIT(I0M
) | SYSREG_BIT(I1M
)
83 | SYSREG_BIT(I2M
) | SYSREG_BIT(I3M
));
84 sysreg_write(SR
, status_reg
);
88 set_irq_regs(old_regs
);
91 void __init
init_IRQ(void)
93 extern void _evba(void);
94 extern void irq_level0(void);
95 struct resource
*regs
;
100 regs
= platform_get_resource(&at32_intc0_device
, IORESOURCE_MEM
, 0);
102 printk(KERN_EMERG
"intc: no mmio resource defined\n");
105 pclk
= clk_get(&at32_intc0_device
.dev
, "pclk");
107 printk(KERN_EMERG
"intc: no clock defined\n");
113 intc0
.regs
= ioremap(regs
->start
, regs
->end
- regs
->start
+ 1);
115 printk(KERN_EMERG
"intc: failed to map registers (0x%08lx)\n",
116 (unsigned long)regs
->start
);
121 * Initialize all interrupts to level 0 (lowest priority). The
122 * priority level may be changed by calling
123 * irq_set_priority().
126 offset
= (unsigned long)&irq_level0
- (unsigned long)&_evba
;
127 for (i
= 0; i
< NR_INTERNAL_IRQS
; i
++) {
128 intc_writel(&intc0
, INTPR0
+ 4 * i
, offset
);
129 readback
= intc_readl(&intc0
, INTPR0
+ 4 * i
);
130 if (readback
== offset
)
131 set_irq_chip_and_handler(i
, &intc0
.chip
,
135 /* Unmask all interrupt levels */
136 sysreg_write(SR
, (sysreg_read(SR
)
137 & ~(SR_I3M
| SR_I2M
| SR_I1M
| SR_I0M
)));
142 panic("Interrupt controller initialization failed!\n");
146 void intc_set_suspend_handler(unsigned long offset
)
148 intc0
.suspend_ipr
= offset
;
151 static int intc_suspend(struct sys_device
*sdev
, pm_message_t state
)
153 struct intc
*intc
= container_of(sdev
, struct intc
, sysdev
);
156 if (unlikely(!irqs_disabled())) {
157 pr_err("intc_suspend: called with interrupts enabled\n");
161 if (unlikely(!intc
->suspend_ipr
)) {
162 pr_err("intc_suspend: suspend_ipr not initialized\n");
166 for (i
= 0; i
< 64; i
++) {
167 intc
->saved_ipr
[i
] = intc_readl(intc
, INTPR0
+ 4 * i
);
168 intc_writel(intc
, INTPR0
+ 4 * i
, intc
->suspend_ipr
);
174 static int intc_resume(struct sys_device
*sdev
)
176 struct intc
*intc
= container_of(sdev
, struct intc
, sysdev
);
179 WARN_ON(!irqs_disabled());
181 for (i
= 0; i
< 64; i
++)
182 intc_writel(intc
, INTPR0
+ 4 * i
, intc
->saved_ipr
[i
]);
187 #define intc_suspend NULL
188 #define intc_resume NULL
191 static struct sysdev_class intc_class
= {
193 .suspend
= intc_suspend
,
194 .resume
= intc_resume
,
197 static int __init
intc_init_sysdev(void)
201 ret
= sysdev_class_register(&intc_class
);
206 intc0
.sysdev
.cls
= &intc_class
;
207 ret
= sysdev_register(&intc0
.sysdev
);
211 device_initcall(intc_init_sysdev
);
213 unsigned long intc_get_pending(unsigned int group
)
215 return intc_readl(&intc0
, INTREQ0
+ 4 * group
);
217 EXPORT_SYMBOL_GPL(intc_get_pending
);