blob: aaff83cc50f06193aa15fd5327a46b9de5433259 [file] [log] [blame]
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001/*
Haavard Skinnemoenaa8e87c2008-02-24 14:26:03 +01002 * Copyright (C) 2006, 2008 Atmel Corporation
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07003 *
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.
7 */
8
9#include <linux/clk.h>
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>
Rafael J. Wysockif25f4f52011-04-26 19:14:35 +020015#include <linux/syscore_ops.h>
Paul Gortmaker09cf6a22011-08-01 12:55:26 -040016#include <linux/export.h>
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070017
18#include <asm/io.h>
19
20#include "intc.h"
21
22struct intc {
Haavard Skinnemoenaa8e87c2008-02-24 14:26:03 +010023 void __iomem *regs;
24 struct irq_chip chip;
Haavard Skinnemoen02a00cf2008-02-24 13:51:38 +010025#ifdef CONFIG_PM
26 unsigned long suspend_ipr;
27 unsigned long saved_ipr[64];
28#endif
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070029};
30
31extern struct platform_device at32_intc0_device;
32
33/*
34 * TODO: We may be able to implement mask/unmask by setting IxM flags
35 * in the status register.
36 */
Thomas Gleixner3972f692011-02-06 17:29:02 +010037static void intc_mask_irq(struct irq_data *d)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070038{
39
40}
41
Thomas Gleixner3972f692011-02-06 17:29:02 +010042static void intc_unmask_irq(struct irq_data *d)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070043{
44
45}
46
47static struct intc intc0 = {
48 .chip = {
49 .name = "intc",
Thomas Gleixner3972f692011-02-06 17:29:02 +010050 .irq_mask = intc_mask_irq,
51 .irq_unmask = intc_unmask_irq,
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070052 },
53};
54
55/*
56 * All interrupts go via intc at some point.
57 */
58asmlinkage void do_IRQ(int level, struct pt_regs *regs)
59{
Haavard Skinnemoen4e0fadf2006-10-11 01:20:37 -070060 struct pt_regs *old_regs;
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070061 unsigned int irq;
62 unsigned long status_reg;
63
64 local_irq_disable();
65
Haavard Skinnemoen4e0fadf2006-10-11 01:20:37 -070066 old_regs = set_irq_regs(regs);
67
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070068 irq_enter();
69
70 irq = intc_readl(&intc0, INTCAUSE0 - 4 * level);
Thomas Gleixner3972f692011-02-06 17:29:02 +010071 generic_handle_irq(irq);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070072
73 /*
74 * Clear all interrupt level masks so that we may handle
75 * interrupts during softirq processing. If this is a nested
76 * interrupt, interrupts must stay globally disabled until we
77 * return.
78 */
79 status_reg = sysreg_read(SR);
80 status_reg &= ~(SYSREG_BIT(I0M) | SYSREG_BIT(I1M)
81 | SYSREG_BIT(I2M) | SYSREG_BIT(I3M));
82 sysreg_write(SR, status_reg);
83
84 irq_exit();
Haavard Skinnemoen4e0fadf2006-10-11 01:20:37 -070085
86 set_irq_regs(old_regs);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070087}
88
89void __init init_IRQ(void)
90{
91 extern void _evba(void);
92 extern void irq_level0(void);
93 struct resource *regs;
94 struct clk *pclk;
95 unsigned int i;
96 u32 offset, readback;
97
98 regs = platform_get_resource(&at32_intc0_device, IORESOURCE_MEM, 0);
99 if (!regs) {
100 printk(KERN_EMERG "intc: no mmio resource defined\n");
101 goto fail;
102 }
103 pclk = clk_get(&at32_intc0_device.dev, "pclk");
104 if (IS_ERR(pclk)) {
105 printk(KERN_EMERG "intc: no clock defined\n");
106 goto fail;
107 }
108
109 clk_enable(pclk);
110
Joe Perches28f65c112011-06-09 09:13:32 -0700111 intc0.regs = ioremap(regs->start, resource_size(regs));
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700112 if (!intc0.regs) {
113 printk(KERN_EMERG "intc: failed to map registers (0x%08lx)\n",
114 (unsigned long)regs->start);
115 goto fail;
116 }
117
118 /*
119 * Initialize all interrupts to level 0 (lowest priority). The
120 * priority level may be changed by calling
121 * irq_set_priority().
122 *
123 */
124 offset = (unsigned long)&irq_level0 - (unsigned long)&_evba;
125 for (i = 0; i < NR_INTERNAL_IRQS; i++) {
126 intc_writel(&intc0, INTPR0 + 4 * i, offset);
127 readback = intc_readl(&intc0, INTPR0 + 4 * i);
128 if (readback == offset)
Thomas Gleixnerd75f1bf2011-03-24 16:39:32 +0100129 irq_set_chip_and_handler(i, &intc0.chip,
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -0700130 handle_simple_irq);
131 }
132
133 /* Unmask all interrupt levels */
134 sysreg_write(SR, (sysreg_read(SR)
135 & ~(SR_I3M | SR_I2M | SR_I1M | SR_I0M)));
136
137 return;
138
139fail:
140 panic("Interrupt controller initialization failed!\n");
141}
142
Haavard Skinnemoen02a00cf2008-02-24 13:51:38 +0100143#ifdef CONFIG_PM
144void intc_set_suspend_handler(unsigned long offset)
145{
146 intc0.suspend_ipr = offset;
147}
148
Rafael J. Wysockif25f4f52011-04-26 19:14:35 +0200149static int intc_suspend(void)
Haavard Skinnemoen02a00cf2008-02-24 13:51:38 +0100150{
Haavard Skinnemoen02a00cf2008-02-24 13:51:38 +0100151 int i;
152
153 if (unlikely(!irqs_disabled())) {
154 pr_err("intc_suspend: called with interrupts enabled\n");
155 return -EINVAL;
156 }
157
Rafael J. Wysockif25f4f52011-04-26 19:14:35 +0200158 if (unlikely(!intc0.suspend_ipr)) {
Haavard Skinnemoen02a00cf2008-02-24 13:51:38 +0100159 pr_err("intc_suspend: suspend_ipr not initialized\n");
160 return -EINVAL;
161 }
162
163 for (i = 0; i < 64; i++) {
Rafael J. Wysockif25f4f52011-04-26 19:14:35 +0200164 intc0.saved_ipr[i] = intc_readl(&intc0, INTPR0 + 4 * i);
165 intc_writel(&intc0, INTPR0 + 4 * i, intc0.suspend_ipr);
Haavard Skinnemoen02a00cf2008-02-24 13:51:38 +0100166 }
167
168 return 0;
169}
170
Hans-Christian Egtvedtc1627552011-06-06 18:19:20 +0200171static void intc_resume(void)
Haavard Skinnemoen02a00cf2008-02-24 13:51:38 +0100172{
Haavard Skinnemoen02a00cf2008-02-24 13:51:38 +0100173 int i;
174
Haavard Skinnemoen02a00cf2008-02-24 13:51:38 +0100175 for (i = 0; i < 64; i++)
Rafael J. Wysockif25f4f52011-04-26 19:14:35 +0200176 intc_writel(&intc0, INTPR0 + 4 * i, intc0.saved_ipr[i]);
Haavard Skinnemoen02a00cf2008-02-24 13:51:38 +0100177}
178#else
179#define intc_suspend NULL
180#define intc_resume NULL
181#endif
182
Rafael J. Wysockif25f4f52011-04-26 19:14:35 +0200183static struct syscore_ops intc_syscore_ops = {
Haavard Skinnemoen02a00cf2008-02-24 13:51:38 +0100184 .suspend = intc_suspend,
185 .resume = intc_resume,
Haavard Skinnemoenaa8e87c2008-02-24 14:26:03 +0100186};
187
Rafael J. Wysockif25f4f52011-04-26 19:14:35 +0200188static int __init intc_init_syscore(void)
Haavard Skinnemoenaa8e87c2008-02-24 14:26:03 +0100189{
Rafael J. Wysockif25f4f52011-04-26 19:14:35 +0200190 register_syscore_ops(&intc_syscore_ops);
Haavard Skinnemoenaa8e87c2008-02-24 14:26:03 +0100191
Rafael J. Wysockif25f4f52011-04-26 19:14:35 +0200192 return 0;
Haavard Skinnemoenaa8e87c2008-02-24 14:26:03 +0100193}
Rafael J. Wysockif25f4f52011-04-26 19:14:35 +0200194device_initcall(intc_init_syscore);
Haavard Skinnemoenaa8e87c2008-02-24 14:26:03 +0100195
Haavard Skinnemoen597702a2007-10-31 20:34:11 +0100196unsigned long intc_get_pending(unsigned int group)
Haavard Skinnemoen69562112006-12-08 11:04:19 +0100197{
198 return intc_readl(&intc0, INTREQ0 + 4 * group);
199}
Haavard Skinnemoen597702a2007-10-31 20:34:11 +0100200EXPORT_SYMBOL_GPL(intc_get_pending);