2 * arch/ppc/kernel/gt64260_pic.c
4 * Interrupt controller support for Galileo's GT64260.
6 * Author: Chris Zankel <chris@mvista.com>
7 * Modified by: Mark A. Greer <mgreer@mvista.com>
9 * Based on sources from Rabeeh Khoury / Galileo Technology
11 * 2001-2002 (c) MontaVista, Software, Inc. This file is licensed under
12 * the terms of the GNU General Public License version 2.1. This program
13 * is licensed "as is" without any warranty of any kind, whether express
18 * This file contains the specific functions to support the GT64260
19 * interrupt controller.
21 * The GT64260 has two main interrupt registers (high and low) that
22 * summarizes the interrupts generated by the units of the GT64260.
23 * Each bit is assigned to an interrupt number, where the low register
24 * are assigned from IRQ0 to IRQ31 and the high cause register
26 * The GPP (General Purpose Port) interrupts are assigned from IRQ64 (GPP0)
28 * get_irq() returns the lowest interrupt number that is currently asserted.
31 * - This driver does not initialize the GPP when used as an interrupt
33 * - *** WARNING *** Only level sensitive GPP interrupts are supported
36 #include <linux/stddef.h>
37 #include <linux/init.h>
38 #include <linux/sched.h>
39 #include <linux/signal.h>
40 #include <linux/stddef.h>
41 #include <linux/delay.h>
42 #include <linux/irq.h>
45 #include <asm/processor.h>
46 #include <asm/system.h>
48 #include <asm/gt64260.h>
51 #define GPP_LEVEL_INTERRUPTS
53 /* #define ENABLE_ECC_INT_HANDLER */ /* currently broken.. causes deadlock of some kind */
54 /* #define ECC_DEBUG */
56 /* ========================== forward declaration ========================== */
58 static void gt64260_unmask_irq(unsigned int);
59 static void gt64260_mask_irq(unsigned int);
60 static void gt64260_end_irq(unsigned int irq);
62 /* ========================== local declarations =========================== */
64 struct hw_interrupt_type gt64260_pic = {
65 " GT64260_PIC ", /* typename */
68 gt64260_unmask_irq, /* enable */
69 gt64260_mask_irq, /* disable */
70 gt64260_mask_irq, /* mask and ack */
71 gt64260_end_irq, /* end */
72 NULL /* set_affinity */
75 u32 gt64260_irq_base = 0; /* GT64260 handles the next 96 IRQs from here */
77 #ifdef ENABLE_ECC_INT_HANDLER
81 /* NOTE: If ecc_irq_ack is called during mask_and_ack,
82 * we lose data_hi and data_lo if we get a new ECC error between
83 * the time ack gets called and gt_ecc_irq gets called since reading addr
84 * allows new data to get latched in. FIXME!!
85 * See GT PIC documentation. */
86 /* Currently, we DON'T have a mask_and_ack_irq, so this code is fine */
87 static u32 last_addr=0; /* store local copy since irq_ack overwrites */
88 u32 addr=gt_read(GT64260_SDRAM_ERR_ADDR);
89 gt_write(GT64260_SDRAM_ERR_ADDR,addr & (~3));
91 if(addr&3) last_addr=addr;
96 gt_ecc_irq(s32 irq, void *dev_id, struct pt_regs *regs)
101 u32 data_lo, data_hi,type;
102 printk("ecc ERR: NIP=%08x LINK=%08x\n", regs->nip, regs->link);
104 data_lo=gt_read(GT64260_SDRAM_ERR_DATA_LO);
105 data_hi=gt_read(GT64260_SDRAM_ERR_DATA_HI);
108 addr=gt_ecc_irq_ack();
113 printk("data:%08x:%08x addr:%08x type:%d\n", data_hi, data_lo, addr&(~3), type);
115 printk("rcvd:%08x calc:%08x cntl:%08x cnt:%08x\n",
116 gt_read(GT64260_SDRAM_ERR_ECC_RCVD),
117 gt_read(GT64260_SDRAM_ERR_ECC_CALC),
118 gt_read(GT64260_SDRAM_ERR_ECC_CNTL),
119 gt_read(GT64260_SDRAM_ERR_ECC_ERR_CNT));
121 gt_write(GT64260_SDRAM_ERR_ECC_ERR_CNT,0);
122 #endif /* ECC_DEBUG */
125 #endif /* ENABLE_ECC_INT_HANDLER */
128 /* gt64260_init_irq()
130 * This function initializes the interrupt controller. It assigns
131 * all interrupts from IRQ0 to IRQ95 to the gt64260 interrupt controller.
136 * Outpu. Variable(s):
143 * We register all GPP inputs as interrupt source, but disable them.
147 gt64260_init_irq(void)
151 if ( ppc_md.progress ) ppc_md.progress("gt64260_init_irq: enter", 0x0);
153 ppc_cached_irq_mask[0] = 0;
154 #if defined(CONFIG_MOT_MVP) || defined(CONFIG_HXEB100)
155 ppc_cached_irq_mask[1] = 0x07000000; /* Enable GPP intrs */
156 ppc_cached_irq_mask[2] = 0x08000020;
158 ppc_cached_irq_mask[1] = 0x0f000000; /* Enable GPP intrs */
159 ppc_cached_irq_mask[2] = 0;
162 /* disable all interrupts and clear current interrupts */
163 gt_write(GT64260_GPP_INTR_MASK, ppc_cached_irq_mask[2]);
164 gt_write(GT64260_GPP_INTR_CAUSE,0);
165 gt_write(GT64260_IC_CPU_INTR_MASK_LO, ppc_cached_irq_mask[0]);
166 gt_write(GT64260_IC_CPU_INTR_MASK_HI, ppc_cached_irq_mask[1]);
168 /* use the gt64260 for all (possible) interrupt sources */
169 for( i = gt64260_irq_base; i < (gt64260_irq_base + 96); i++ ) {
170 irq_desc[i].handler = >64260_pic;
173 #ifdef GPP_LEVEL_INTERRUPTS
174 if(gt64260_revision != GT64260) {
175 if ( ppc_md.progress )
176 ppc_md.progress("gt64260_init_irq: GPP -> levelint ", 0x0);
178 /* Mark GPP intrs level sensitive */
179 gt_set_bits(GT64260_COMM_ARBITER_CNTL, (1<<10));
181 for(i=gt64260_irq_base+64;i<gt64260_irq_base+64+32;i++)
182 irq_desc[i].status |= IRQ_LEVEL;
186 #ifdef ENABLE_ECC_INT_HANDLER
187 request_irq(gt64260_irq_base + 17, gt_ecc_irq, 0, "GT64260 SDRAM ECC Error", 0);
190 if ( ppc_md.progress ) ppc_md.progress("gt64260_init_irq: exit", 0x0);
197 * This function returns the lowest interrupt number of all interrupts that
198 * are currently asserted.
201 * struct pt_regs* not used
203 * Output Variable(s):
207 * int <interrupt number> or -2 (bogus interrupt)
211 gt64260_get_irq(struct pt_regs *regs)
217 cpu = smp_processor_id();
218 irq = gt_read(GT64260_IC_MAIN_CAUSE_LO);
219 irq = __ilog2((irq & 0x3dfffffe) & ppc_cached_irq_mask[0]);
222 irq = gt_read(GT64260_IC_MAIN_CAUSE_HI);
223 #if defined(CONFIG_MOT_MVP) || defined(CONFIG_HXEB100)
224 /* Okay, this whole irq mess needs a rewrite bad, but who
225 * am I to argue with a deadline? -- Troy
228 irq = __ilog2((irq & 0x08000000));
230 irq = __ilog2((irq & 0x07000db7) & ppc_cached_irq_mask[1]);
233 irq = __ilog2((irq & 0x0f000db7) & ppc_cached_irq_mask[1]);
237 irq = -2; /* bogus interrupt, should never happen */
243 irq_gpp = gt_read(GT64260_GPP_INTR_CAUSE);
244 #if defined(CONFIG_MOT_MVP) || defined(CONFIG_HXEB100)
246 irq_gpp = __ilog2((irq_gpp & 0x08000000));
248 irq_gpp = __ilog2(irq_gpp & ppc_cached_irq_mask[2] & ~0x08000000);
251 irq_gpp = __ilog2(irq_gpp & ppc_cached_irq_mask[2]);
265 return( gt64260_irq_base + irq );
269 /* gt64260_unmask_irq()
271 * This function enables an interrupt.
274 * unsigned int interrupt number (IRQ0...IRQ95).
276 * Output Variable(s):
284 gt64260_unmask_irq(unsigned int irq)
288 irq -= gt64260_irq_base;
289 spin_lock_irqsave(>64260_lock, flags);
294 set_bit(irq-64, &ppc_cached_irq_mask[2]);
295 gt_write(GT64260_GPP_INTR_MASK, ppc_cached_irq_mask[2]);
297 /* unmask high interrupt register */
298 set_bit(irq-32, &ppc_cached_irq_mask[1]);
299 gt_write(GT64260_IC_CPU_INTR_MASK_HI,
300 ppc_cached_irq_mask[1]);
303 /* unmask low interrupt register */
304 set_bit(irq, &ppc_cached_irq_mask[0]);
305 gt_write(GT64260_IC_CPU_INTR_MASK_LO, ppc_cached_irq_mask[0]);
307 spin_unlock_irqrestore(>64260_lock, flags);
311 /* gt64260_mask_irq()
313 * This function disables the requested interrupt.
316 * unsigned int interrupt number (IRQ0...IRQ95).
318 * Output Variable(s):
326 gt64260_mask_irq(unsigned int irq)
330 irq -= gt64260_irq_base;
331 spin_lock_irqsave(>64260_lock, flags);
335 clear_bit(irq-64, &ppc_cached_irq_mask[2]);
336 gt_write(GT64260_GPP_INTR_MASK, ppc_cached_irq_mask[2]);
338 /* mask high interrupt register */
339 clear_bit(irq-32, &ppc_cached_irq_mask[1]);
340 gt_write(GT64260_IC_CPU_INTR_MASK_HI,
341 ppc_cached_irq_mask[1]);
344 /* mask low interrupt register */
345 clear_bit(irq, &ppc_cached_irq_mask[0]);
346 gt_write(GT64260_IC_CPU_INTR_MASK_LO, ppc_cached_irq_mask[0]);
348 spin_unlock_irqrestore(>64260_lock, flags);
350 if (irq == 36) { /* Seems necessary for SDMA interrupts */
358 * This function unmasks the irq, if its not disabled or in progress
361 * unsigned int interrupt number (IRQ0...IRQ95).
363 * Output Variable(s):
370 gt64260_end_irq(unsigned int irq)
372 int local_irq = irq - gt64260_irq_base;
374 if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS))) {
376 if ((local_irq > 63) && (irq_desc[irq].status & IRQ_LEVEL)) {
377 gt_write(GT64260_GPP_INTR_CAUSE,
378 ~(1<<(local_irq-64)));
381 gt64260_unmask_irq(irq);