intc.c 4.1 KB
Newer Older
H
Haavard Skinnemoen 已提交
1
/*
2
 * Copyright (C) 2006, 2008 Atmel Corporation
H
Haavard Skinnemoen 已提交
3 4 5 6 7 8 9 10 11 12 13 14
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#include <linux/clk.h>
#include <linux/err.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/platform_device.h>
15
#include <linux/syscore_ops.h>
16
#include <linux/export.h>
H
Haavard Skinnemoen 已提交
17 18 19 20 21 22

#include <asm/io.h>

#include "intc.h"

struct intc {
23 24
	void __iomem		*regs;
	struct irq_chip		chip;
25 26 27 28
#ifdef CONFIG_PM
	unsigned long		suspend_ipr;
	unsigned long		saved_ipr[64];
#endif
H
Haavard Skinnemoen 已提交
29 30 31 32 33 34 35 36
};

extern struct platform_device at32_intc0_device;

/*
 * TODO: We may be able to implement mask/unmask by setting IxM flags
 * in the status register.
 */
37
static void intc_mask_irq(struct irq_data *d)
H
Haavard Skinnemoen 已提交
38 39 40 41
{

}

42
static void intc_unmask_irq(struct irq_data *d)
H
Haavard Skinnemoen 已提交
43 44 45 46 47 48 49
{

}

static struct intc intc0 = {
	.chip = {
		.name		= "intc",
50 51
		.irq_mask	= intc_mask_irq,
		.irq_unmask	= intc_unmask_irq,
H
Haavard Skinnemoen 已提交
52 53 54 55 56 57 58 59
	},
};

/*
 * All interrupts go via intc at some point.
 */
asmlinkage void do_IRQ(int level, struct pt_regs *regs)
{
60
	struct pt_regs *old_regs;
H
Haavard Skinnemoen 已提交
61 62 63 64 65
	unsigned int irq;
	unsigned long status_reg;

	local_irq_disable();

66 67
	old_regs = set_irq_regs(regs);

H
Haavard Skinnemoen 已提交
68 69 70
	irq_enter();

	irq = intc_readl(&intc0, INTCAUSE0 - 4 * level);
71
	generic_handle_irq(irq);
H
Haavard Skinnemoen 已提交
72 73 74 75 76 77 78 79 80 81 82 83 84

	/*
	 * Clear all interrupt level masks so that we may handle
	 * interrupts during softirq processing.  If this is a nested
	 * interrupt, interrupts must stay globally disabled until we
	 * return.
	 */
	status_reg = sysreg_read(SR);
	status_reg &= ~(SYSREG_BIT(I0M) | SYSREG_BIT(I1M)
			| SYSREG_BIT(I2M) | SYSREG_BIT(I3M));
	sysreg_write(SR, status_reg);

	irq_exit();
85 86

	set_irq_regs(old_regs);
H
Haavard Skinnemoen 已提交
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
}

void __init init_IRQ(void)
{
	extern void _evba(void);
	extern void irq_level0(void);
	struct resource *regs;
	struct clk *pclk;
	unsigned int i;
	u32 offset, readback;

	regs = platform_get_resource(&at32_intc0_device, IORESOURCE_MEM, 0);
	if (!regs) {
		printk(KERN_EMERG "intc: no mmio resource defined\n");
		goto fail;
	}
	pclk = clk_get(&at32_intc0_device.dev, "pclk");
	if (IS_ERR(pclk)) {
		printk(KERN_EMERG "intc: no clock defined\n");
		goto fail;
	}

	clk_enable(pclk);

111
	intc0.regs = ioremap(regs->start, resource_size(regs));
H
Haavard Skinnemoen 已提交
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
	if (!intc0.regs) {
		printk(KERN_EMERG "intc: failed to map registers (0x%08lx)\n",
		       (unsigned long)regs->start);
		goto fail;
	}

	/*
	 * Initialize all interrupts to level 0 (lowest priority). The
	 * priority level may be changed by calling
	 * irq_set_priority().
	 *
	 */
	offset = (unsigned long)&irq_level0 - (unsigned long)&_evba;
	for (i = 0; i < NR_INTERNAL_IRQS; i++) {
		intc_writel(&intc0, INTPR0 + 4 * i, offset);
		readback = intc_readl(&intc0, INTPR0 + 4 * i);
		if (readback == offset)
T
Thomas Gleixner 已提交
129
			irq_set_chip_and_handler(i, &intc0.chip,
H
Haavard Skinnemoen 已提交
130 131 132 133 134 135 136 137 138 139 140 141 142
						 handle_simple_irq);
	}

	/* Unmask all interrupt levels */
	sysreg_write(SR, (sysreg_read(SR)
			  & ~(SR_I3M | SR_I2M | SR_I1M | SR_I0M)));

	return;

fail:
	panic("Interrupt controller initialization failed!\n");
}

143 144 145 146 147 148
#ifdef CONFIG_PM
void intc_set_suspend_handler(unsigned long offset)
{
	intc0.suspend_ipr = offset;
}

149
static int intc_suspend(void)
150 151 152 153 154 155 156 157
{
	int i;

	if (unlikely(!irqs_disabled())) {
		pr_err("intc_suspend: called with interrupts enabled\n");
		return -EINVAL;
	}

158
	if (unlikely(!intc0.suspend_ipr)) {
159 160 161 162 163
		pr_err("intc_suspend: suspend_ipr not initialized\n");
		return -EINVAL;
	}

	for (i = 0; i < 64; i++) {
164 165
		intc0.saved_ipr[i] = intc_readl(&intc0, INTPR0 + 4 * i);
		intc_writel(&intc0, INTPR0 + 4 * i, intc0.suspend_ipr);
166 167 168 169 170
	}

	return 0;
}

171
static void intc_resume(void)
172 173 174 175
{
	int i;

	for (i = 0; i < 64; i++)
176
		intc_writel(&intc0, INTPR0 + 4 * i, intc0.saved_ipr[i]);
177 178 179 180 181 182
}
#else
#define intc_suspend	NULL
#define intc_resume	NULL
#endif

183
static struct syscore_ops intc_syscore_ops = {
184 185
	.suspend	= intc_suspend,
	.resume		= intc_resume,
186 187
};

188
static int __init intc_init_syscore(void)
189
{
190
	register_syscore_ops(&intc_syscore_ops);
191

192
	return 0;
193
}
194
device_initcall(intc_init_syscore);
195

196
unsigned long intc_get_pending(unsigned int group)
197 198 199
{
	return intc_readl(&intc0, INTREQ0 + 4 * group);
}
200
EXPORT_SYMBOL_GPL(intc_get_pending);