irq-gt641xx.c 3.4 KB
Newer Older
Y
Yoichi Yuasa 已提交
1 2 3
/*
 *  GT641xx IRQ routines.
 *
4
 *  Copyright (C) 2007  Yoichi Yuasa <yuasa@linux-mips.org>
Y
Yoichi Yuasa 已提交
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
 *
 *  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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
#include <linux/hardirq.h>
#include <linux/init.h>
#include <linux/irq.h>
#include <linux/spinlock.h>
#include <linux/types.h>

#include <asm/gt64120.h>

#define GT641XX_IRQ_TO_BIT(irq)	(1U << (irq - GT641XX_IRQ_BASE))

30
static DEFINE_RAW_SPINLOCK(gt641xx_irq_lock);
Y
Yoichi Yuasa 已提交
31

32
static void ack_gt641xx_irq(struct irq_data *d)
Y
Yoichi Yuasa 已提交
33 34 35 36
{
	unsigned long flags;
	u32 cause;

37
	raw_spin_lock_irqsave(&gt641xx_irq_lock, flags);
Y
Yoichi Yuasa 已提交
38
	cause = GT_READ(GT_INTRCAUSE_OFS);
39
	cause &= ~GT641XX_IRQ_TO_BIT(d->irq);
Y
Yoichi Yuasa 已提交
40
	GT_WRITE(GT_INTRCAUSE_OFS, cause);
41
	raw_spin_unlock_irqrestore(&gt641xx_irq_lock, flags);
Y
Yoichi Yuasa 已提交
42 43
}

44
static void mask_gt641xx_irq(struct irq_data *d)
Y
Yoichi Yuasa 已提交
45 46 47 48
{
	unsigned long flags;
	u32 mask;

49
	raw_spin_lock_irqsave(&gt641xx_irq_lock, flags);
Y
Yoichi Yuasa 已提交
50
	mask = GT_READ(GT_INTRMASK_OFS);
51
	mask &= ~GT641XX_IRQ_TO_BIT(d->irq);
Y
Yoichi Yuasa 已提交
52
	GT_WRITE(GT_INTRMASK_OFS, mask);
53
	raw_spin_unlock_irqrestore(&gt641xx_irq_lock, flags);
Y
Yoichi Yuasa 已提交
54 55
}

56
static void mask_ack_gt641xx_irq(struct irq_data *d)
Y
Yoichi Yuasa 已提交
57 58 59 60
{
	unsigned long flags;
	u32 cause, mask;

61
	raw_spin_lock_irqsave(&gt641xx_irq_lock, flags);
Y
Yoichi Yuasa 已提交
62
	mask = GT_READ(GT_INTRMASK_OFS);
63
	mask &= ~GT641XX_IRQ_TO_BIT(d->irq);
Y
Yoichi Yuasa 已提交
64 65 66
	GT_WRITE(GT_INTRMASK_OFS, mask);

	cause = GT_READ(GT_INTRCAUSE_OFS);
67
	cause &= ~GT641XX_IRQ_TO_BIT(d->irq);
Y
Yoichi Yuasa 已提交
68
	GT_WRITE(GT_INTRCAUSE_OFS, cause);
69
	raw_spin_unlock_irqrestore(&gt641xx_irq_lock, flags);
Y
Yoichi Yuasa 已提交
70 71
}

72
static void unmask_gt641xx_irq(struct irq_data *d)
Y
Yoichi Yuasa 已提交
73 74 75 76
{
	unsigned long flags;
	u32 mask;

77
	raw_spin_lock_irqsave(&gt641xx_irq_lock, flags);
Y
Yoichi Yuasa 已提交
78
	mask = GT_READ(GT_INTRMASK_OFS);
79
	mask |= GT641XX_IRQ_TO_BIT(d->irq);
Y
Yoichi Yuasa 已提交
80
	GT_WRITE(GT_INTRMASK_OFS, mask);
81
	raw_spin_unlock_irqrestore(&gt641xx_irq_lock, flags);
Y
Yoichi Yuasa 已提交
82 83 84 85
}

static struct irq_chip gt641xx_irq_chip = {
	.name		= "GT641xx",
86 87 88 89
	.irq_ack	= ack_gt641xx_irq,
	.irq_mask	= mask_gt641xx_irq,
	.irq_mask_ack	= mask_ack_gt641xx_irq,
	.irq_unmask	= unmask_gt641xx_irq,
Y
Yoichi Yuasa 已提交
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
};

void gt641xx_irq_dispatch(void)
{
	u32 cause, mask;
	int i;

	cause = GT_READ(GT_INTRCAUSE_OFS);
	mask = GT_READ(GT_INTRMASK_OFS);
	cause &= mask;

	/*
	 * bit0 : logical or of all the interrupt bits.
	 * bit30: logical or of bits[29:26,20:1].
	 * bit31: logical or of bits[25:1].
	 */
	for (i = 1; i < 30; i++) {
		if (cause & (1U << i)) {
			do_IRQ(GT641XX_IRQ_BASE + i);
			return;
		}
	}

	atomic_inc(&irq_err_count);
}

void __init gt641xx_irq_init(void)
{
	int i;

	GT_WRITE(GT_INTRMASK_OFS, 0);
	GT_WRITE(GT_INTRCAUSE_OFS, 0);

	/*
	 * bit0 : logical or of all the interrupt bits.
	 * bit30: logical or of bits[29:26,20:1].
	 * bit31: logical or of bits[25:1].
	 */
	for (i = 1; i < 30; i++)
		set_irq_chip_and_handler(GT641XX_IRQ_BASE + i,
		                         &gt641xx_irq_chip, handle_level_irq);
}