irq.c 4.2 KB
Newer Older
1
/*
2
 * linux/arch/arm/mach-at91/irq.c
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
 *
 *  Copyright (C) 2004 SAN People
 *  Copyright (C) 2004 ATMEL
 *  Copyright (C) Rick Bronson
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <linux/init.h>
#include <linux/module.h>
#include <linux/mm.h>
#include <linux/types.h>

28
#include <mach/hardware.h>
29 30 31 32 33 34 35 36
#include <asm/irq.h>
#include <asm/setup.h>

#include <asm/mach/arch.h>
#include <asm/mach/irq.h>
#include <asm/mach/map.h>


37
static void at91_aic_mask_irq(struct irq_data *d)
38 39
{
	/* Disable interrupt on AIC */
40
	at91_sys_write(AT91_AIC_IDCR, 1 << d->irq);
41 42
}

43
static void at91_aic_unmask_irq(struct irq_data *d)
44 45
{
	/* Enable interrupt on AIC */
46
	at91_sys_write(AT91_AIC_IECR, 1 << d->irq);
47 48
}

49 50 51 52
unsigned int at91_extern_irq;

#define is_extern_irq(irq) ((1 << (irq)) & at91_extern_irq)

53
static int at91_aic_set_type(struct irq_data *d, unsigned type)
54 55 56 57
{
	unsigned int smr, srctype;

	switch (type) {
58
	case IRQ_TYPE_LEVEL_HIGH:
59 60
		srctype = AT91_AIC_SRCTYPE_HIGH;
		break;
61
	case IRQ_TYPE_EDGE_RISING:
62 63
		srctype = AT91_AIC_SRCTYPE_RISING;
		break;
64
	case IRQ_TYPE_LEVEL_LOW:
65
		if ((d->irq == AT91_ID_FIQ) || is_extern_irq(d->irq))		/* only supported on external interrupts */
66 67
			srctype = AT91_AIC_SRCTYPE_LOW;
		else
68
			return -EINVAL;
69
		break;
70
	case IRQ_TYPE_EDGE_FALLING:
71
		if ((d->irq == AT91_ID_FIQ) || is_extern_irq(d->irq))		/* only supported on external interrupts */
72 73
			srctype = AT91_AIC_SRCTYPE_FALLING;
		else
74
			return -EINVAL;
75 76 77 78 79
		break;
	default:
		return -EINVAL;
	}

80 81
	smr = at91_sys_read(AT91_AIC_SMR(d->irq)) & ~AT91_AIC_SRCTYPE;
	at91_sys_write(AT91_AIC_SMR(d->irq), smr | srctype);
82 83 84
	return 0;
}

85 86 87 88 89
#ifdef CONFIG_PM

static u32 wakeups;
static u32 backups;

90
static int at91_aic_set_wake(struct irq_data *d, unsigned value)
91
{
92
	if (unlikely(d->irq >= 32))
93 94 95
		return -EINVAL;

	if (value)
96
		wakeups |= (1 << d->irq);
97
	else
98
		wakeups &= ~(1 << d->irq);
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116

	return 0;
}

void at91_irq_suspend(void)
{
	backups = at91_sys_read(AT91_AIC_IMR);
	at91_sys_write(AT91_AIC_IDCR, backups);
	at91_sys_write(AT91_AIC_IECR, wakeups);
}

void at91_irq_resume(void)
{
	at91_sys_write(AT91_AIC_IDCR, wakeups);
	at91_sys_write(AT91_AIC_IECR, backups);
}

#else
A
Andrew Victor 已提交
117
#define at91_aic_set_wake	NULL
118 119
#endif

120 121
static struct irq_chip at91_aic_chip = {
	.name		= "AIC",
122 123 124 125 126
	.irq_ack	= at91_aic_mask_irq,
	.irq_mask	= at91_aic_mask_irq,
	.irq_unmask	= at91_aic_unmask_irq,
	.irq_set_type	= at91_aic_set_type,
	.irq_set_wake	= at91_aic_set_wake,
127 128 129 130 131
};

/*
 * Initialize the AIC interrupt controller.
 */
A
Andrew Victor 已提交
132
void __init at91_aic_init(unsigned int priority[NR_AIC_IRQS])
133 134 135 136 137 138 139 140 141 142
{
	unsigned int i;

	/*
	 * The IVR is used by macro get_irqnr_and_base to read and verify.
	 * The irq number is NR_AIC_IRQS when a spurious interrupt has occurred.
	 */
	for (i = 0; i < NR_AIC_IRQS; i++) {
		/* Put irq number in Source Vector Register: */
		at91_sys_write(AT91_AIC_SVR(i), i);
A
Andrew Victor 已提交
143
		/* Active Low interrupt, with the specified priority */
144 145
		at91_sys_write(AT91_AIC_SMR(i), AT91_AIC_SRCTYPE_LOW | priority[i]);

A
Andrew Victor 已提交
146
		set_irq_chip(i, &at91_aic_chip);
147
		set_irq_handler(i, handle_level_irq);
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
		set_irq_flags(i, IRQF_VALID | IRQF_PROBE);

		/* Perform 8 End Of Interrupt Command to make sure AIC will not Lock out nIRQ */
		if (i < 8)
			at91_sys_write(AT91_AIC_EOICR, 0);
	}

	/*
	 * Spurious Interrupt ID in Spurious Vector Register is NR_AIC_IRQS
	 * When there is no current interrupt, the IRQ Vector Register reads the value stored in AIC_SPU
	 */
	at91_sys_write(AT91_AIC_SPU, NR_AIC_IRQS);

	/* No debugging in AIC: Debug (Protect) Control Register */
	at91_sys_write(AT91_AIC_DCR, 0);

	/* Disable and clear all interrupts initially */
	at91_sys_write(AT91_AIC_IDCR, 0xFFFFFFFF);
	at91_sys_write(AT91_AIC_ICCR, 0xFFFFFFFF);
}