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