aboutsummaryrefslogtreecommitdiffstats
path: root/arch/sh/cchips/voyagergx/irq.c
blob: 0dc1fb8f9687626a71d6e1905bd52dc049c9e1a3 (plain) (blame)
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/* -------------------------------------------------------------------- */
/* setup_voyagergx.c:                                                     */
/* -------------------------------------------------------------------- */
/*  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., 675 Mass Ave, Cambridge, MA 02139, USA.

    Copyright 2003 (c) Lineo uSolutions,Inc.
*/
/* -------------------------------------------------------------------- */

#undef DEBUG

#include <linux/sched.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/param.h>
#include <linux/ioport.h>
#include <linux/interrupt.h>
#include <linux/init.h>
#include <linux/irq.h>

#include <asm/io.h>
#include <asm/irq.h>
#include <asm/rts7751r2d/rts7751r2d.h>
#include <asm/rts7751r2d/voyagergx_reg.h>

static void disable_voyagergx_irq(unsigned int irq)
{
	unsigned long flags, val;
	unsigned long  mask = 1 << (irq - VOYAGER_IRQ_BASE);

    	pr_debug("disable_voyagergx_irq(%d): mask=%x\n", irq, mask);
	local_irq_save(flags);
        val = inl(VOYAGER_INT_MASK);
        val &= ~mask;
        outl(val, VOYAGER_INT_MASK);
	local_irq_restore(flags);
}


static void enable_voyagergx_irq(unsigned int irq)
{
        unsigned long flags, val;
        unsigned long  mask = 1 << (irq - VOYAGER_IRQ_BASE);

        pr_debug("disable_voyagergx_irq(%d): mask=%x\n", irq, mask);
        local_irq_save(flags);
        val = inl(VOYAGER_INT_MASK);
        val |= mask;
        outl(val, VOYAGER_INT_MASK);
        local_irq_restore(flags);
}


static void mask_and_ack_voyagergx(unsigned int irq)
{
	disable_voyagergx_irq(irq);
}

static void end_voyagergx_irq(unsigned int irq)
{
	if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
		enable_voyagergx_irq(irq);
}

static unsigned int startup_voyagergx_irq(unsigned int irq)
{
	enable_voyagergx_irq(irq);
	return 0;
}

static void shutdown_voyagergx_irq(unsigned int irq)
{
	disable_voyagergx_irq(irq);
}

static struct hw_interrupt_type voyagergx_irq_type = {
	.typename = "VOYAGERGX-IRQ",
	.startup = startup_voyagergx_irq,
	.shutdown = shutdown_voyagergx_irq,
	.enable = enable_voyagergx_irq,
	.disable = disable_voyagergx_irq,
	.ack = mask_and_ack_voyagergx,
	.end = end_voyagergx_irq,
};

static irqreturn_t voyagergx_interrupt(int irq, void *dev_id, struct pt_regs *regs)
{
	printk(KERN_INFO
	       "VoyagerGX: spurious interrupt, status: 0x%x\n",
	       		inl(INT_STATUS));
	return IRQ_HANDLED;
}


/*====================================================*/

static struct {
	int (*func)(int, void *);
	void *dev;
} voyagergx_demux[VOYAGER_IRQ_NUM];

void voyagergx_register_irq_demux(int irq,
		int (*demux)(int irq, void *dev), void *dev)
{
    	voyagergx_demux[irq - VOYAGER_IRQ_BASE].func = demux;
    	voyagergx_demux[irq - VOYAGER_IRQ_BASE].dev = dev;
}

void voyagergx_unregister_irq_demux(int irq)
{
    	voyagergx_demux[irq - VOYAGER_IRQ_BASE].func = 0;
}

int voyagergx_irq_demux(int irq)
{

	if (irq == IRQ_VOYAGER ) {
		unsigned long i = 0, bit __attribute__ ((unused));
		unsigned long val  = inl(INT_STATUS);
#if 1
		if ( val & ( 1 << 1 )){
			i = 1;
		} else if ( val & ( 1 << 2 )){
			i = 2;
		} else if ( val & ( 1 << 6 )){
			i = 6;
		} else if( val & ( 1 << 10 )){
			i = 10;
		} else if( val & ( 1 << 11 )){
			i = 11;
		} else if( val & ( 1 << 12 )){
			i = 12;
		} else if( val & ( 1 << 17 )){
			i = 17;
		} else {
			printk("Unexpected IRQ irq = %d status = 0x%08lx\n", irq, val);
		}
		pr_debug("voyagergx_irq_demux %d \n", i);
#else
		for (bit = 1, i = 0 ; i < VOYAGER_IRQ_NUM ; bit <<= 1, i++)
			if (val & bit)
				break;
#endif
    	    	if (i < VOYAGER_IRQ_NUM) {
			irq = VOYAGER_IRQ_BASE + i;
    	    		if (voyagergx_demux[i].func != 0)
				irq = voyagergx_demux[i].func(irq, voyagergx_demux[i].dev);
		}
	}
	return irq;
}

static struct irqaction irq0  = {
	.name		= "voyagergx",
	.handler	= voyagergx_interrupt,
	.flags		= IRQF_DISABLED,
	.mask		= CPU_MASK_NONE,
};

void __init setup_voyagergx_irq(void)
{
	int i, flag;

	printk(KERN_INFO "VoyagerGX configured at 0x%x on irq %d(mapped into %d to %d)\n",
	       VOYAGER_BASE,
	       IRQ_VOYAGER,
	       VOYAGER_IRQ_BASE,
	       VOYAGER_IRQ_BASE + VOYAGER_IRQ_NUM - 1);

	for (i=0; i<VOYAGER_IRQ_NUM; i++) {
		flag = 0;
		switch (VOYAGER_IRQ_BASE + i) {
		case VOYAGER_USBH_IRQ:
		case VOYAGER_8051_IRQ:
		case VOYAGER_UART0_IRQ:
		case VOYAGER_UART1_IRQ:
		case VOYAGER_AC97_IRQ:
			flag = 1;
		}
		if (flag == 1)
			irq_desc[VOYAGER_IRQ_BASE + i].chip = &voyagergx_irq_type;
	}

	setup_irq(IRQ_VOYAGER, &irq0);
}