ipr.c 2.2 KB
Newer Older
P
Paul Mundt 已提交
1
/*
P
Paul Mundt 已提交
2
 * Interrupt handling for IPR-based IRQ.
L
Linus Torvalds 已提交
3 4 5
 *
 * Copyright (C) 1999  Niibe Yutaka & Takeshi Yaegashi
 * Copyright (C) 2000  Kazumoto Kojima
P
Paul Mundt 已提交
6 7
 * Copyright (C) 2003  Takashi Kusuda <kusuda-takashi@hitachi-ul.co.jp>
 * Copyright (C) 2006  Paul Mundt
L
Linus Torvalds 已提交
8 9 10
 *
 * Supported system:
 *	On-chip supporting modules (TMU, RTC, etc.).
11
 *	On-chip supporting modules for SH7709/SH7709A/SH7729.
L
Linus Torvalds 已提交
12 13 14
 *	Hitachi SolutionEngine external I/O:
 *		MS7709SE01, MS7709ASE01, and MS7750SE01
 *
P
Paul Mundt 已提交
15 16 17
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
L
Linus Torvalds 已提交
18 19 20 21
 */
#include <linux/init.h>
#include <linux/irq.h>
#include <linux/module.h>
P
Paul Mundt 已提交
22 23
#include <linux/io.h>
#include <linux/interrupt.h>
L
Linus Torvalds 已提交
24

M
Magnus Damm 已提交
25 26 27 28 29 30
static inline struct ipr_desc *get_ipr_desc(unsigned int irq)
{
	struct irq_chip *chip = get_irq_chip(irq);
	return (void *)((char *)chip - offsetof(struct ipr_desc, chip));
}

L
Linus Torvalds 已提交
31 32
static void disable_ipr_irq(unsigned int irq)
{
P
Paul Mundt 已提交
33
	struct ipr_data *p = get_irq_chip_data(irq);
M
Magnus Damm 已提交
34
	unsigned long addr = get_ipr_desc(irq)->ipr_offsets[p->ipr_idx];
L
Linus Torvalds 已提交
35
	/* Set the priority in IPR to 0 */
M
Magnus Damm 已提交
36
	ctrl_outw(ctrl_inw(addr) & (0xffff ^ (0xf << p->shift)), addr);
L
Linus Torvalds 已提交
37 38 39 40
}

static void enable_ipr_irq(unsigned int irq)
{
P
Paul Mundt 已提交
41
	struct ipr_data *p = get_irq_chip_data(irq);
M
Magnus Damm 已提交
42
	unsigned long addr = get_ipr_desc(irq)->ipr_offsets[p->ipr_idx];
L
Linus Torvalds 已提交
43
	/* Set priority in IPR back to original value */
M
Magnus Damm 已提交
44
	ctrl_outw(ctrl_inw(addr) | (p->priority << p->shift), addr);
L
Linus Torvalds 已提交
45 46
}

M
Magnus Damm 已提交
47 48 49 50 51 52
/*
 * The shift value is now the number of bits to shift, not the number of
 * bits/4. This is to make it easier to read the value directly from the
 * datasheets. The IPR address is calculated using the ipr_offset table.
 */
void register_ipr_controller(struct ipr_desc *desc)
L
Linus Torvalds 已提交
53
{
54
	int i;
P
Paul Mundt 已提交
55

M
Magnus Damm 已提交
56 57 58
	desc->chip.mask = disable_ipr_irq;
	desc->chip.unmask = enable_ipr_irq;
	desc->chip.mask_ack = disable_ipr_irq;
T
Takashi YOSHII 已提交
59

M
Magnus Damm 已提交
60 61
	for (i = 0; i < desc->nr_irqs; i++) {
		struct ipr_data *p = desc->ipr_data + i;
T
Takashi YOSHII 已提交
62

M
Magnus Damm 已提交
63 64
		BUG_ON(p->ipr_idx >= desc->nr_offsets);
		BUG_ON(!desc->ipr_offsets[p->ipr_idx]);
T
Takashi YOSHII 已提交
65

M
Magnus Damm 已提交
66 67
		disable_irq_nosync(p->irq);
		set_irq_chip_and_handler_name(p->irq, &desc->chip,
68
				      handle_level_irq, "level");
M
Magnus Damm 已提交
69 70
		set_irq_chip_data(p->irq, p);
		disable_ipr_irq(p->irq);
71
	}
L
Linus Torvalds 已提交
72
}
M
Magnus Damm 已提交
73
EXPORT_SYMBOL(register_ipr_controller);