Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 1 | #include <linux/kernel.h> |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 2 | #include <linux/stddef.h> |
| 3 | #include <linux/init.h> |
| 4 | #include <linux/sched.h> |
| 5 | #include <linux/signal.h> |
| 6 | #include <linux/irq.h> |
| 7 | #include <linux/dma-mapping.h> |
| 8 | #include <asm/prom.h> |
| 9 | #include <asm/irq.h> |
| 10 | #include <asm/io.h> |
| 11 | #include <asm/8xx_immap.h> |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 12 | |
| 13 | #include "mpc8xx_pic.h" |
| 14 | |
| 15 | |
| 16 | #define PIC_VEC_SPURRIOUS 15 |
| 17 | |
| 18 | extern int cpm_get_irq(struct pt_regs *regs); |
| 19 | |
Grant Likely | bae1d8f | 2012-02-14 14:06:50 -0700 | [diff] [blame] | 20 | static struct irq_domain *mpc8xx_pic_host; |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 21 | #define NR_MASK_WORDS ((NR_IRQS + 31) / 32) |
| 22 | static unsigned long ppc_cached_irq_mask[NR_MASK_WORDS]; |
Scott Wood | fb533d0 | 2007-09-14 14:22:36 -0500 | [diff] [blame] | 23 | static sysconf8xx_t __iomem *siu_reg; |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 24 | |
| 25 | int cpm_get_irq(struct pt_regs *regs); |
| 26 | |
Lennert Buytenhek | febd401 | 2011-03-07 14:00:00 +0000 | [diff] [blame] | 27 | static void mpc8xx_unmask_irq(struct irq_data *d) |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 28 | { |
| 29 | int bit, word; |
Grant Likely | 476eb49 | 2011-05-04 15:02:15 +1000 | [diff] [blame] | 30 | unsigned int irq_nr = (unsigned int)irqd_to_hwirq(d); |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 31 | |
| 32 | bit = irq_nr & 0x1f; |
| 33 | word = irq_nr >> 5; |
| 34 | |
| 35 | ppc_cached_irq_mask[word] |= (1 << (31-bit)); |
| 36 | out_be32(&siu_reg->sc_simask, ppc_cached_irq_mask[word]); |
| 37 | } |
| 38 | |
Lennert Buytenhek | febd401 | 2011-03-07 14:00:00 +0000 | [diff] [blame] | 39 | static void mpc8xx_mask_irq(struct irq_data *d) |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 40 | { |
| 41 | int bit, word; |
Grant Likely | 476eb49 | 2011-05-04 15:02:15 +1000 | [diff] [blame] | 42 | unsigned int irq_nr = (unsigned int)irqd_to_hwirq(d); |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 43 | |
| 44 | bit = irq_nr & 0x1f; |
| 45 | word = irq_nr >> 5; |
| 46 | |
| 47 | ppc_cached_irq_mask[word] &= ~(1 << (31-bit)); |
| 48 | out_be32(&siu_reg->sc_simask, ppc_cached_irq_mask[word]); |
| 49 | } |
| 50 | |
Lennert Buytenhek | febd401 | 2011-03-07 14:00:00 +0000 | [diff] [blame] | 51 | static void mpc8xx_ack(struct irq_data *d) |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 52 | { |
| 53 | int bit; |
Grant Likely | 476eb49 | 2011-05-04 15:02:15 +1000 | [diff] [blame] | 54 | unsigned int irq_nr = (unsigned int)irqd_to_hwirq(d); |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 55 | |
| 56 | bit = irq_nr & 0x1f; |
| 57 | out_be32(&siu_reg->sc_sipend, 1 << (31-bit)); |
| 58 | } |
| 59 | |
Lennert Buytenhek | febd401 | 2011-03-07 14:00:00 +0000 | [diff] [blame] | 60 | static void mpc8xx_end_irq(struct irq_data *d) |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 61 | { |
| 62 | int bit, word; |
Grant Likely | 476eb49 | 2011-05-04 15:02:15 +1000 | [diff] [blame] | 63 | unsigned int irq_nr = (unsigned int)irqd_to_hwirq(d); |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 64 | |
| 65 | bit = irq_nr & 0x1f; |
| 66 | word = irq_nr >> 5; |
| 67 | |
| 68 | ppc_cached_irq_mask[word] |= (1 << (31-bit)); |
| 69 | out_be32(&siu_reg->sc_simask, ppc_cached_irq_mask[word]); |
| 70 | } |
| 71 | |
Lennert Buytenhek | febd401 | 2011-03-07 14:00:00 +0000 | [diff] [blame] | 72 | static int mpc8xx_set_irq_type(struct irq_data *d, unsigned int flow_type) |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 73 | { |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 74 | if (flow_type & IRQ_TYPE_EDGE_FALLING) { |
Grant Likely | 476eb49 | 2011-05-04 15:02:15 +1000 | [diff] [blame] | 75 | irq_hw_number_t hw = (unsigned int)irqd_to_hwirq(d); |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 76 | unsigned int siel = in_be32(&siu_reg->sc_siel); |
| 77 | |
| 78 | /* only external IRQ senses are programmable */ |
| 79 | if ((hw & 1) == 0) { |
| 80 | siel |= (0x80000000 >> hw); |
| 81 | out_be32(&siu_reg->sc_siel, siel); |
Benjamin Herrenschmidt | b3cf2bb | 2011-03-30 11:07:13 +1100 | [diff] [blame] | 82 | __irq_set_handler_locked(d->irq, handle_edge_irq); |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 83 | } |
| 84 | } |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | static struct irq_chip mpc8xx_pic = { |
Anton Blanchard | fc380c0 | 2010-01-31 20:33:41 +0000 | [diff] [blame] | 89 | .name = "MPC8XX SIU", |
Lennert Buytenhek | febd401 | 2011-03-07 14:00:00 +0000 | [diff] [blame] | 90 | .irq_unmask = mpc8xx_unmask_irq, |
| 91 | .irq_mask = mpc8xx_mask_irq, |
| 92 | .irq_ack = mpc8xx_ack, |
| 93 | .irq_eoi = mpc8xx_end_irq, |
| 94 | .irq_set_type = mpc8xx_set_irq_type, |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | unsigned int mpc8xx_get_irq(void) |
| 98 | { |
| 99 | int irq; |
| 100 | |
| 101 | /* For MPC8xx, read the SIVEC register and shift the bits down |
| 102 | * to get the irq number. |
| 103 | */ |
| 104 | irq = in_be32(&siu_reg->sc_sivec) >> 26; |
| 105 | |
| 106 | if (irq == PIC_VEC_SPURRIOUS) |
| 107 | irq = NO_IRQ; |
| 108 | |
| 109 | return irq_linear_revmap(mpc8xx_pic_host, irq); |
| 110 | |
| 111 | } |
| 112 | |
Grant Likely | bae1d8f | 2012-02-14 14:06:50 -0700 | [diff] [blame] | 113 | static int mpc8xx_pic_host_map(struct irq_domain *h, unsigned int virq, |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 114 | irq_hw_number_t hw) |
| 115 | { |
| 116 | pr_debug("mpc8xx_pic_host_map(%d, 0x%lx)\n", virq, hw); |
| 117 | |
| 118 | /* Set default irq handle */ |
Thomas Gleixner | ec775d0 | 2011-03-25 16:45:20 +0100 | [diff] [blame] | 119 | irq_set_chip_and_handler(virq, &mpc8xx_pic, handle_level_irq); |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 120 | return 0; |
| 121 | } |
| 122 | |
| 123 | |
Grant Likely | bae1d8f | 2012-02-14 14:06:50 -0700 | [diff] [blame] | 124 | static int mpc8xx_pic_host_xlate(struct irq_domain *h, struct device_node *ct, |
Roman Fietze | 40d50cf | 2009-12-08 02:39:50 +0000 | [diff] [blame] | 125 | const u32 *intspec, unsigned int intsize, |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 126 | irq_hw_number_t *out_hwirq, unsigned int *out_flags) |
| 127 | { |
| 128 | static unsigned char map_pic_senses[4] = { |
| 129 | IRQ_TYPE_EDGE_RISING, |
| 130 | IRQ_TYPE_LEVEL_LOW, |
| 131 | IRQ_TYPE_LEVEL_HIGH, |
| 132 | IRQ_TYPE_EDGE_FALLING, |
| 133 | }; |
| 134 | |
| 135 | *out_hwirq = intspec[0]; |
| 136 | if (intsize > 1 && intspec[1] < 4) |
| 137 | *out_flags = map_pic_senses[intspec[1]]; |
| 138 | else |
| 139 | *out_flags = IRQ_TYPE_NONE; |
| 140 | |
| 141 | return 0; |
| 142 | } |
| 143 | |
| 144 | |
Grant Likely | bae1d8f | 2012-02-14 14:06:50 -0700 | [diff] [blame] | 145 | static struct irq_domain_ops mpc8xx_pic_host_ops = { |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 146 | .map = mpc8xx_pic_host_map, |
| 147 | .xlate = mpc8xx_pic_host_xlate, |
| 148 | }; |
| 149 | |
| 150 | int mpc8xx_pic_init(void) |
| 151 | { |
| 152 | struct resource res; |
Scott Wood | fb533d0 | 2007-09-14 14:22:36 -0500 | [diff] [blame] | 153 | struct device_node *np; |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 154 | int ret; |
| 155 | |
Scott Wood | fb533d0 | 2007-09-14 14:22:36 -0500 | [diff] [blame] | 156 | np = of_find_compatible_node(NULL, NULL, "fsl,pq1-pic"); |
| 157 | if (np == NULL) |
| 158 | np = of_find_node_by_type(NULL, "mpc8xx-pic"); |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 159 | if (np == NULL) { |
Scott Wood | fb533d0 | 2007-09-14 14:22:36 -0500 | [diff] [blame] | 160 | printk(KERN_ERR "Could not find fsl,pq1-pic node\n"); |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 161 | return -ENOMEM; |
| 162 | } |
| 163 | |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 164 | ret = of_address_to_resource(np, 0, &res); |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 165 | if (ret) |
Michael Ellerman | 52964f8 | 2007-08-28 18:47:54 +1000 | [diff] [blame] | 166 | goto out; |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 167 | |
Joe Perches | 28f65c11 | 2011-06-09 09:13:32 -0700 | [diff] [blame] | 168 | siu_reg = ioremap(res.start, resource_size(&res)); |
Julia Lawall | b1725c9 | 2008-02-04 23:34:59 -0800 | [diff] [blame] | 169 | if (siu_reg == NULL) { |
| 170 | ret = -EINVAL; |
| 171 | goto out; |
| 172 | } |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 173 | |
Grant Likely | a8db8cf | 2012-02-14 14:06:54 -0700 | [diff] [blame] | 174 | mpc8xx_pic_host = irq_domain_add_linear(np, 64, &mpc8xx_pic_host_ops, NULL); |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 175 | if (mpc8xx_pic_host == NULL) { |
| 176 | printk(KERN_ERR "MPC8xx PIC: failed to allocate irq host!\n"); |
| 177 | ret = -ENOMEM; |
Julia Lawall | b1725c9 | 2008-02-04 23:34:59 -0800 | [diff] [blame] | 178 | goto out; |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 179 | } |
Julia Lawall | b1725c9 | 2008-02-04 23:34:59 -0800 | [diff] [blame] | 180 | return 0; |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 181 | |
Michael Ellerman | 52964f8 | 2007-08-28 18:47:54 +1000 | [diff] [blame] | 182 | out: |
| 183 | of_node_put(np); |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 184 | return ret; |
| 185 | } |