intc2.c 2.3 KB
Newer Older
P
Paul Mundt 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13
/*
 * Interrupt handling for INTC2-based IRQ.
 *
 * Copyright (C) 2001 David J. Mckay (david.mckay@st.com)
 * Copyright (C) 2005, 2006 Paul Mundt (lethal@linux-sh.org)
 *
 * May be copied or modified under the terms of the GNU General Public
 * License.  See linux/COPYING for more information.
 *
 * These are the "new Hitachi style" interrupts, as present on the
 * Hitachi 7751, the STM ST40 STB1, SH7760, and SH7780.
 */
#include <linux/kernel.h>
P
Paul Mundt 已提交
14
#include <linux/interrupt.h>
15
#include <linux/io.h>
P
Paul Mundt 已提交
16

M
Magnus Damm 已提交
17 18 19 20 21
static inline struct intc2_desc *get_intc2_desc(unsigned int irq)
{
	struct irq_chip *chip = get_irq_chip(irq);
	return (void *)((char *)chip - offsetof(struct intc2_desc, chip));
}
P
Paul Mundt 已提交
22 23 24

static void disable_intc2_irq(unsigned int irq)
{
25
	struct intc2_data *p = get_irq_chip_data(irq);
M
Magnus Damm 已提交
26 27
	struct intc2_desc *d = get_intc2_desc(irq);
	ctrl_outl(1 << p->msk_shift, d->msk_base + p->msk_offset);
P
Paul Mundt 已提交
28 29 30 31
}

static void enable_intc2_irq(unsigned int irq)
{
32
	struct intc2_data *p = get_irq_chip_data(irq);
M
Magnus Damm 已提交
33 34
	struct intc2_desc *d = get_intc2_desc(irq);
	ctrl_outl(1 << p->msk_shift, d->mskclr_base + p->msk_offset);
P
Paul Mundt 已提交
35 36 37 38 39 40 41 42 43 44
}

/*
 * Setup an INTC2 style interrupt.
 * NOTE: Unlike IPR interrupts, parameters are not shifted by this code,
 * allowing the use of the numbers straight out of the datasheet.
 * For example:
 *    PIO1 which is INTPRI00[19,16] and INTMSK00[13]
 * would be:               ^     ^             ^  ^
 *                         |     |             |  |
45 46 47
 *     { 84,		   0,   16,            0, 13 },
 *
 * in the intc2_data table.
P
Paul Mundt 已提交
48
 */
M
Magnus Damm 已提交
49
void register_intc2_controller(struct intc2_desc *desc)
P
Paul Mundt 已提交
50
{
51
	int i;
P
Paul Mundt 已提交
52

M
Magnus Damm 已提交
53 54 55 56 57
	desc->chip.mask = disable_intc2_irq;
	desc->chip.unmask = enable_intc2_irq;
	desc->chip.mask_ack = disable_intc2_irq;

	for (i = 0; i < desc->nr_irqs; i++) {
58
		unsigned long ipr, flags;
M
Magnus Damm 已提交
59
		struct intc2_data *p = desc->intc2_data + i;
P
Paul Mundt 已提交
60

61
		disable_irq_nosync(p->irq);
P
Paul Mundt 已提交
62

M
Magnus Damm 已提交
63 64 65
		if (desc->prio_base) {
			/* Set the priority level */
			local_irq_save(flags);
P
Paul Mundt 已提交
66

M
Magnus Damm 已提交
67 68 69 70
			ipr = ctrl_inl(desc->prio_base + p->ipr_offset);
			ipr &= ~(0xf << p->ipr_shift);
			ipr |= p->priority << p->ipr_shift;
			ctrl_outl(ipr, desc->prio_base + p->ipr_offset);
P
Paul Mundt 已提交
71

M
Magnus Damm 已提交
72 73
			local_irq_restore(flags);
		}
P
Paul Mundt 已提交
74

M
Magnus Damm 已提交
75
		set_irq_chip_and_handler_name(p->irq, &desc->chip,
76 77
					      handle_level_irq, "level");
		set_irq_chip_data(p->irq, p);
P
Paul Mundt 已提交
78

M
Magnus Damm 已提交
79
		disable_intc2_irq(p->irq);
80
	}
P
Paul Mundt 已提交
81
}