aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/adm5120/files-3.18/arch/mips/adm5120/common/irq.c
blob: a26e65176e27b9a79747e8142f9c46029061628d (plain)
1
2
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
 *  ADM5120 specific interrupt handlers
 *
 *  Copyright (C) 2007-2008 Gabor Juhos <juhosg@openwrt.org>
 *
 *  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/init.h>
#include <linux/kernel.h>
#include <linux/version.h>
#include <linux/irq.h>
#include <linux/interrupt.h>
#include <linux/ioport.h>
#include <linux/io.h>
#include <linux/bitops.h>

#include <asm/irq_cpu.h>
#include <asm/mipsregs.h>

#include <asm/mach-adm5120/adm5120_defs.h>

static void adm5120_intc_irq_unmask(struct irq_data *d);
static void adm5120_intc_irq_mask(struct irq_data *d);
static int  adm5120_intc_irq_set_type(struct irq_data *d, unsigned int flow_type);

static inline void intc_write_reg(unsigned int reg, u32 val)
{
	void __iomem *base = (void __iomem *)KSEG1ADDR(ADM5120_INTC_BASE);

	__raw_writel(val, base + reg);
}

static inline u32 intc_read_reg(unsigned int reg)
{
	void __iomem *base = (void __iomem *)KSEG1ADDR(ADM5120_INTC_BASE);

	return __raw_readl(base + reg);
}

static struct irq_chip adm5120_intc_irq_chip = {
	.name		= "INTC",
	.irq_unmask	= adm5120_intc_irq_unmask,
	.irq_mask	= adm5120_intc_irq_mask,
	.irq_mask_ack	= adm5120_intc_irq_mask,
	.irq_set_type	= adm5120_intc_irq_set_type
};

static struct irqaction adm5120_intc_irq_action = {
	.handler	= no_action,
	.name		= "cascade [INTC]"
};

static void adm5120_intc_irq_unmask(struct irq_data *d)
{
	intc_write_reg(INTC_REG_IRQ_ENABLE, 1 << (d->irq - ADM5120_INTC_IRQ_BASE));
}

static void adm5120_intc_irq_mask(struct irq_data *d)
{
	intc_write_reg(INTC_REG_IRQ_DISABLE, 1 << (d->irq - ADM5120_INTC_IRQ_BASE));
}

static int adm5120_intc_irq_set_type(struct irq_data *d, unsigned int flow_type)
{
	unsigned int irq = d->irq;
	unsigned int sense;
	unsigned long mode;
	int err = 0;

	sense = flow_type & (IRQ_TYPE_SENSE_MASK);
	switch (sense) {
	case IRQ_TYPE_NONE:
	case IRQ_TYPE_LEVEL_HIGH:
		break;
	case IRQ_TYPE_LEVEL_LOW:
		switch (irq) {
		case ADM5120_IRQ_GPIO2:
		case ADM5120_IRQ_GPIO4:
			break;
		default:
			err = -EINVAL;
			break;
		}
		break;
	default:
		err = -EINVAL;
		break;
	}

	if (err)
		return err;

	switch (irq) {
	case ADM5120_IRQ_GPIO2:
	case ADM5120_IRQ_GPIO4:
		mode = intc_read_reg(INTC_REG_INT_MODE);
		if (sense == IRQ_TYPE_LEVEL_LOW)
			mode |= (1 << (irq - ADM5120_INTC_IRQ_BASE));
		else
			mode &= ~(1 << (irq - ADM5120_INTC_IRQ_BASE));

		intc_write_reg(INTC_REG_INT_MODE, mode);
		break;
	}

	return 0;
}

static void adm5120_intc_irq_dispatch(void)
{
	unsigned long status;
	int irq;

	status = intc_read_reg(INTC_REG_IRQ_STATUS) & INTC_INT_ALL;
	if (status) {
		irq = ADM5120_INTC_IRQ_BASE + fls(status) - 1;
		do_IRQ(irq);
	} else
		spurious_interrupt();
}

asmlinkage void plat_irq_dispatch(void)
{
	unsigned long pending;

	pending = read_c0_status() & read_c0_cause() & ST0_IM;

	if (pending & STATUSF_IP7)
		do_IRQ(ADM5120_IRQ_COUNTER);
	else if (pending & STATUSF_IP2)
		adm5120_intc_irq_dispatch();
	else
		spurious_interrupt();
}

#define INTC_IRQ_STATUS (IRQ_LEVEL | IRQ_TYPE_LEVEL_HIGH | IRQ_DISABLED)
static void __init adm5120_intc_irq_init(void)
{
	int i;

	/* disable all interrupts */
	intc_write_reg(INTC_REG_IRQ_DISABLE, INTC_INT_ALL);

	/* setup all interrupts to generate IRQ instead of FIQ */
	intc_write_reg(INTC_REG_INT_MODE, 0);

	/* set active level for all external interrupts to HIGH */
	intc_write_reg(INTC_REG_INT_LEVEL, 0);

	/* disable usage of the TEST_SOURCE register */
	intc_write_reg(INTC_REG_IRQ_SOURCE_SELECT, 0);

	for (i = ADM5120_INTC_IRQ_BASE;
		i <= ADM5120_INTC_IRQ_BASE + INTC_IRQ_LAST;
		i++) {
		irq_set_chip_and_handler(i, &adm5120_intc_irq_chip,
			handle_level_irq);
	}

	setup_irq(ADM5120_IRQ_INTC, &adm5120_intc_irq_action);
}

void __init arch_init_irq(void)
{
	mips_cpu_irq_init();
	adm5120_intc_irq_init();
}