Greg Ungerer | 2fba4f0 | 2009-04-27 15:38:03 +1000 | [diff] [blame] | 1 | /* |
Philippe De Muyter | 03cbc385 | 2010-08-19 19:04:58 +0200 | [diff] [blame] | 2 | * intc-2.c |
| 3 | * |
Philippe De Muyter | 8851338 | 2010-09-01 15:23:28 +0200 | [diff] [blame] | 4 | * General interrupt controller code for the many ColdFire cores that use |
| 5 | * interrupt controllers with 63 interrupt sources, organized as 56 fully- |
| 6 | * programmable + 7 fixed-level interrupt sources. This includes the 523x |
| 7 | * family, the 5270, 5271, 5274, 5275, and the 528x family which have two such |
| 8 | * controllers, and the 547x and 548x families which have only one of them. |
Greg Ungerer | 2fba4f0 | 2009-04-27 15:38:03 +1000 | [diff] [blame] | 9 | * |
| 10 | * (C) Copyright 2009, Greg Ungerer <gerg@snapgear.com> |
| 11 | * |
| 12 | * This file is subject to the terms and conditions of the GNU General Public |
| 13 | * License. See the file COPYING in the main directory of this archive |
| 14 | * for more details. |
| 15 | */ |
| 16 | |
| 17 | #include <linux/types.h> |
| 18 | #include <linux/init.h> |
| 19 | #include <linux/kernel.h> |
| 20 | #include <linux/interrupt.h> |
| 21 | #include <linux/irq.h> |
| 22 | #include <linux/io.h> |
| 23 | #include <asm/coldfire.h> |
| 24 | #include <asm/mcfsim.h> |
| 25 | #include <asm/traps.h> |
| 26 | |
| 27 | /* |
Philippe De Muyter | 8851338 | 2010-09-01 15:23:28 +0200 | [diff] [blame] | 28 | * Bit definitions for the ICR family of registers. |
Greg Ungerer | 2fba4f0 | 2009-04-27 15:38:03 +1000 | [diff] [blame] | 29 | */ |
Philippe De Muyter | 8851338 | 2010-09-01 15:23:28 +0200 | [diff] [blame] | 30 | #define MCFSIM_ICR_LEVEL(l) ((l)<<3) /* Level l intr */ |
| 31 | #define MCFSIM_ICR_PRI(p) (p) /* Priority p intr */ |
| 32 | |
| 33 | /* |
| 34 | * Each vector needs a unique priority and level associated with it. |
| 35 | * We don't really care so much what they are, we don't rely on the |
| 36 | * traditional priority interrupt scheme of the m68k/ColdFire. |
| 37 | */ |
| 38 | static u8 intc_intpri = MCFSIM_ICR_LEVEL(6) | MCFSIM_ICR_PRI(6); |
| 39 | |
| 40 | #ifdef MCFICM_INTC1 |
| 41 | #define NR_VECS 128 |
| 42 | #else |
| 43 | #define NR_VECS 64 |
| 44 | #endif |
Greg Ungerer | 2fba4f0 | 2009-04-27 15:38:03 +1000 | [diff] [blame] | 45 | |
Thomas Gleixner | 0bc0f3a | 2011-02-06 23:39:14 +0000 | [diff] [blame] | 46 | static void intc_irq_mask(struct irq_data *d) |
Greg Ungerer | 2fba4f0 | 2009-04-27 15:38:03 +1000 | [diff] [blame] | 47 | { |
Thomas Gleixner | 0bc0f3a | 2011-02-06 23:39:14 +0000 | [diff] [blame] | 48 | unsigned int irq = d->irq; |
| 49 | |
Philippe De Muyter | 8851338 | 2010-09-01 15:23:28 +0200 | [diff] [blame] | 50 | if ((irq >= MCFINT_VECBASE) && (irq <= MCFINT_VECBASE + NR_VECS)) { |
Greg Ungerer | 2fba4f0 | 2009-04-27 15:38:03 +1000 | [diff] [blame] | 51 | unsigned long imraddr; |
| 52 | u32 val, imrbit; |
| 53 | |
| 54 | irq -= MCFINT_VECBASE; |
Philippe De Muyter | 8851338 | 2010-09-01 15:23:28 +0200 | [diff] [blame] | 55 | #ifdef MCFICM_INTC1 |
Greg Ungerer | 254eef7 | 2011-03-05 22:17:17 +1000 | [diff] [blame^] | 56 | imraddr = (irq & 0x40) ? MCFICM_INTC1 : MCFICM_INTC0; |
Philippe De Muyter | 8851338 | 2010-09-01 15:23:28 +0200 | [diff] [blame] | 57 | #else |
Greg Ungerer | 254eef7 | 2011-03-05 22:17:17 +1000 | [diff] [blame^] | 58 | imraddr = MCFICM_INTC0; |
Philippe De Muyter | 8851338 | 2010-09-01 15:23:28 +0200 | [diff] [blame] | 59 | #endif |
Greg Ungerer | 2fba4f0 | 2009-04-27 15:38:03 +1000 | [diff] [blame] | 60 | imraddr += (irq & 0x20) ? MCFINTC_IMRH : MCFINTC_IMRL; |
| 61 | imrbit = 0x1 << (irq & 0x1f); |
| 62 | |
| 63 | val = __raw_readl(imraddr); |
| 64 | __raw_writel(val | imrbit, imraddr); |
| 65 | } |
| 66 | } |
| 67 | |
Thomas Gleixner | 0bc0f3a | 2011-02-06 23:39:14 +0000 | [diff] [blame] | 68 | static void intc_irq_unmask(struct irq_data *d) |
Greg Ungerer | 2fba4f0 | 2009-04-27 15:38:03 +1000 | [diff] [blame] | 69 | { |
Thomas Gleixner | 0bc0f3a | 2011-02-06 23:39:14 +0000 | [diff] [blame] | 70 | unsigned int irq = d->irq; |
| 71 | |
Philippe De Muyter | 8851338 | 2010-09-01 15:23:28 +0200 | [diff] [blame] | 72 | if ((irq >= MCFINT_VECBASE) && (irq <= MCFINT_VECBASE + NR_VECS)) { |
Greg Ungerer | 2fba4f0 | 2009-04-27 15:38:03 +1000 | [diff] [blame] | 73 | unsigned long intaddr, imraddr, icraddr; |
| 74 | u32 val, imrbit; |
| 75 | |
| 76 | irq -= MCFINT_VECBASE; |
Philippe De Muyter | 8851338 | 2010-09-01 15:23:28 +0200 | [diff] [blame] | 77 | #ifdef MCFICM_INTC1 |
Greg Ungerer | 254eef7 | 2011-03-05 22:17:17 +1000 | [diff] [blame^] | 78 | intaddr = (irq & 0x40) ? MCFICM_INTC1 : MCFICM_INTC0; |
Philippe De Muyter | 8851338 | 2010-09-01 15:23:28 +0200 | [diff] [blame] | 79 | #else |
Greg Ungerer | 254eef7 | 2011-03-05 22:17:17 +1000 | [diff] [blame^] | 80 | intaddr = MCFICM_INTC0; |
Philippe De Muyter | 8851338 | 2010-09-01 15:23:28 +0200 | [diff] [blame] | 81 | #endif |
Greg Ungerer | 2fba4f0 | 2009-04-27 15:38:03 +1000 | [diff] [blame] | 82 | imraddr = intaddr + ((irq & 0x20) ? MCFINTC_IMRH : MCFINTC_IMRL); |
| 83 | icraddr = intaddr + MCFINTC_ICR0 + (irq & 0x3f); |
| 84 | imrbit = 0x1 << (irq & 0x1f); |
| 85 | |
| 86 | /* Don't set the "maskall" bit! */ |
| 87 | if ((irq & 0x20) == 0) |
| 88 | imrbit |= 0x1; |
| 89 | |
| 90 | if (__raw_readb(icraddr) == 0) |
| 91 | __raw_writeb(intc_intpri--, icraddr); |
| 92 | |
| 93 | val = __raw_readl(imraddr); |
| 94 | __raw_writel(val & ~imrbit, imraddr); |
| 95 | } |
| 96 | } |
| 97 | |
Thomas Gleixner | 0bc0f3a | 2011-02-06 23:39:14 +0000 | [diff] [blame] | 98 | static int intc_irq_set_type(struct irq_data *d, unsigned int type) |
Greg Ungerer | 04570b4 | 2010-09-09 17:12:53 +1000 | [diff] [blame] | 99 | { |
| 100 | return 0; |
| 101 | } |
| 102 | |
Greg Ungerer | 2fba4f0 | 2009-04-27 15:38:03 +1000 | [diff] [blame] | 103 | static struct irq_chip intc_irq_chip = { |
| 104 | .name = "CF-INTC", |
Thomas Gleixner | 0bc0f3a | 2011-02-06 23:39:14 +0000 | [diff] [blame] | 105 | .irq_mask = intc_irq_mask, |
| 106 | .irq_unmask = intc_irq_unmask, |
| 107 | .irq_set_type = intc_irq_set_type, |
Greg Ungerer | 2fba4f0 | 2009-04-27 15:38:03 +1000 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | void __init init_IRQ(void) |
| 111 | { |
| 112 | int irq; |
| 113 | |
| 114 | init_vectors(); |
| 115 | |
| 116 | /* Mask all interrupt sources */ |
Greg Ungerer | 254eef7 | 2011-03-05 22:17:17 +1000 | [diff] [blame^] | 117 | __raw_writel(0x1, MCFICM_INTC0 + MCFINTC_IMRL); |
Philippe De Muyter | 8851338 | 2010-09-01 15:23:28 +0200 | [diff] [blame] | 118 | #ifdef MCFICM_INTC1 |
Greg Ungerer | 254eef7 | 2011-03-05 22:17:17 +1000 | [diff] [blame^] | 119 | __raw_writel(0x1, MCFICM_INTC1 + MCFINTC_IMRL); |
Philippe De Muyter | 8851338 | 2010-09-01 15:23:28 +0200 | [diff] [blame] | 120 | #endif |
Greg Ungerer | 2fba4f0 | 2009-04-27 15:38:03 +1000 | [diff] [blame] | 121 | |
| 122 | for (irq = 0; (irq < NR_IRQS); irq++) { |
Greg Ungerer | 04570b4 | 2010-09-09 17:12:53 +1000 | [diff] [blame] | 123 | set_irq_chip(irq, &intc_irq_chip); |
| 124 | set_irq_type(irq, IRQ_TYPE_LEVEL_HIGH); |
| 125 | set_irq_handler(irq, handle_level_irq); |
Greg Ungerer | 2fba4f0 | 2009-04-27 15:38:03 +1000 | [diff] [blame] | 126 | } |
| 127 | } |
| 128 | |