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