blob: 10386b676d8758b7f52bb8348f7cf321cc8db89a [file] [log] [blame]
Vitaly Bordugb0c110b2006-09-21 22:18:53 +04001/*
2 * Platform information definitions.
3 *
4 * Copied from arch/ppc/syslib/cpm2_pic.c with minor subsequent updates
5 * to make in work in arch/powerpc/. Original (c) belongs to Dan Malek.
6 *
7 * Author: Vitaly Bordug <vbordug@ru.mvista.com>
8 *
9 * 1999-2001 (c) Dan Malek <dan@embeddedalley.com>
10 * 2006 (c) MontaVista Software, Inc.
11 *
12 * This file is licensed under the terms of the GNU General Public License
13 * version 2. This program is licensed "as is" without any warranty of any
14 * kind, whether express or implied.
15 */
16
17/* The CPM2 internal interrupt controller. It is usually
18 * the only interrupt controller.
19 * There are two 32-bit registers (high/low) for up to 64
20 * possible interrupts.
21 *
22 * Now, the fun starts.....Interrupt Numbers DO NOT MAP
23 * in a simple arithmetic fashion to mask or pending registers.
24 * That is, interrupt 4 does not map to bit position 4.
25 * We create two tables, indexed by vector number, to indicate
26 * which register to use and which bit in the register to use.
27 */
28
29#include <linux/stddef.h>
30#include <linux/init.h>
31#include <linux/sched.h>
32#include <linux/signal.h>
33#include <linux/irq.h>
34
35#include <asm/immap_cpm2.h>
36#include <asm/mpc8260.h>
37#include <asm/io.h>
38#include <asm/prom.h>
Vitaly Bordug73844ec2007-01-31 02:08:54 +030039#include <asm/fs_pd.h>
Vitaly Bordugb0c110b2006-09-21 22:18:53 +040040
41#include "cpm2_pic.h"
42
Vitaly Bordug73844ec2007-01-31 02:08:54 +030043/* External IRQS */
44#define CPM2_IRQ_EXT1 19
45#define CPM2_IRQ_EXT7 25
46
47/* Port C IRQS */
48#define CPM2_IRQ_PORTC15 48
49#define CPM2_IRQ_PORTC0 63
50
Scott Wood449012d2007-09-14 15:30:44 -050051static intctl_cpm2_t __iomem *cpm2_intctl;
Vitaly Bordug73844ec2007-01-31 02:08:54 +030052
Grant Likelybae1d8f2012-02-14 14:06:50 -070053static struct irq_domain *cpm2_pic_host;
Grant Likely40133692012-04-23 12:30:02 +000054static unsigned long ppc_cached_irq_mask[2]; /* 2 32-bit registers */
Vitaly Bordugb0c110b2006-09-21 22:18:53 +040055
56static const u_char irq_to_siureg[] = {
57 1, 1, 1, 1, 1, 1, 1, 1,
58 1, 1, 1, 1, 1, 1, 1, 1,
59 0, 0, 0, 0, 0, 0, 0, 0,
60 0, 0, 0, 0, 0, 0, 0, 0,
61 1, 1, 1, 1, 1, 1, 1, 1,
62 1, 1, 1, 1, 1, 1, 1, 1,
63 0, 0, 0, 0, 0, 0, 0, 0,
64 0, 0, 0, 0, 0, 0, 0, 0
65};
66
67/* bit numbers do not match the docs, these are precomputed so the bit for
68 * a given irq is (1 << irq_to_siubit[irq]) */
69static const u_char irq_to_siubit[] = {
70 0, 15, 14, 13, 12, 11, 10, 9,
71 8, 7, 6, 5, 4, 3, 2, 1,
72 2, 1, 0, 14, 13, 12, 11, 10,
73 9, 8, 7, 6, 5, 4, 3, 0,
74 31, 30, 29, 28, 27, 26, 25, 24,
75 23, 22, 21, 20, 19, 18, 17, 16,
76 16, 17, 18, 19, 20, 21, 22, 23,
77 24, 25, 26, 27, 28, 29, 30, 31,
78};
79
Lennert Buytenhekc47eefa2011-03-07 13:59:51 +000080static void cpm2_mask_irq(struct irq_data *d)
Vitaly Bordugb0c110b2006-09-21 22:18:53 +040081{
82 int bit, word;
Grant Likely476eb492011-05-04 15:02:15 +100083 unsigned int irq_nr = irqd_to_hwirq(d);
Vitaly Bordugb0c110b2006-09-21 22:18:53 +040084
85 bit = irq_to_siubit[irq_nr];
86 word = irq_to_siureg[irq_nr];
87
Vitaly Bordugb0c110b2006-09-21 22:18:53 +040088 ppc_cached_irq_mask[word] &= ~(1 << bit);
Vitaly Bordug73844ec2007-01-31 02:08:54 +030089 out_be32(&cpm2_intctl->ic_simrh + word, ppc_cached_irq_mask[word]);
Vitaly Bordugb0c110b2006-09-21 22:18:53 +040090}
91
Lennert Buytenhekc47eefa2011-03-07 13:59:51 +000092static void cpm2_unmask_irq(struct irq_data *d)
Vitaly Bordugb0c110b2006-09-21 22:18:53 +040093{
94 int bit, word;
Grant Likely476eb492011-05-04 15:02:15 +100095 unsigned int irq_nr = irqd_to_hwirq(d);
Vitaly Bordugb0c110b2006-09-21 22:18:53 +040096
97 bit = irq_to_siubit[irq_nr];
98 word = irq_to_siureg[irq_nr];
99
Vitaly Bordugb0c110b2006-09-21 22:18:53 +0400100 ppc_cached_irq_mask[word] |= 1 << bit;
Vitaly Bordug73844ec2007-01-31 02:08:54 +0300101 out_be32(&cpm2_intctl->ic_simrh + word, ppc_cached_irq_mask[word]);
Vitaly Bordugb0c110b2006-09-21 22:18:53 +0400102}
103
Lennert Buytenhekc47eefa2011-03-07 13:59:51 +0000104static void cpm2_ack(struct irq_data *d)
Vitaly Bordugb0c110b2006-09-21 22:18:53 +0400105{
106 int bit, word;
Grant Likely476eb492011-05-04 15:02:15 +1000107 unsigned int irq_nr = irqd_to_hwirq(d);
Vitaly Bordugb0c110b2006-09-21 22:18:53 +0400108
109 bit = irq_to_siubit[irq_nr];
110 word = irq_to_siureg[irq_nr];
111
Vitaly Bordug73844ec2007-01-31 02:08:54 +0300112 out_be32(&cpm2_intctl->ic_sipnrh + word, 1 << bit);
Vitaly Bordugb0c110b2006-09-21 22:18:53 +0400113}
114
Lennert Buytenhekc47eefa2011-03-07 13:59:51 +0000115static void cpm2_end_irq(struct irq_data *d)
Vitaly Bordugb0c110b2006-09-21 22:18:53 +0400116{
117 int bit, word;
Grant Likely476eb492011-05-04 15:02:15 +1000118 unsigned int irq_nr = irqd_to_hwirq(d);
Vitaly Bordugb0c110b2006-09-21 22:18:53 +0400119
Thomas Gleixner7bf811a82011-03-25 16:13:38 +0100120 bit = irq_to_siubit[irq_nr];
121 word = irq_to_siureg[irq_nr];
Vitaly Bordugb0c110b2006-09-21 22:18:53 +0400122
Thomas Gleixner7bf811a82011-03-25 16:13:38 +0100123 ppc_cached_irq_mask[word] |= 1 << bit;
124 out_be32(&cpm2_intctl->ic_simrh + word, ppc_cached_irq_mask[word]);
Vitaly Bordugb0c110b2006-09-21 22:18:53 +0400125
Thomas Gleixner7bf811a82011-03-25 16:13:38 +0100126 /*
127 * Work around large numbers of spurious IRQs on PowerPC 82xx
128 * systems.
129 */
130 mb();
Vitaly Bordugb0c110b2006-09-21 22:18:53 +0400131}
132
Lennert Buytenhekc47eefa2011-03-07 13:59:51 +0000133static int cpm2_set_irq_type(struct irq_data *d, unsigned int flow_type)
Vitaly Bordug73844ec2007-01-31 02:08:54 +0300134{
Grant Likely476eb492011-05-04 15:02:15 +1000135 unsigned int src = irqd_to_hwirq(d);
Vitaly Bordug73844ec2007-01-31 02:08:54 +0300136 unsigned int vold, vnew, edibit;
137
Mark Wareb22b97c2009-12-10 22:14:34 +1100138 /* Port C interrupts are either IRQ_TYPE_EDGE_FALLING or
139 * IRQ_TYPE_EDGE_BOTH (default). All others are IRQ_TYPE_EDGE_FALLING
140 * or IRQ_TYPE_LEVEL_LOW (default)
141 */
142 if (src >= CPM2_IRQ_PORTC15 && src <= CPM2_IRQ_PORTC0) {
143 if (flow_type == IRQ_TYPE_NONE)
144 flow_type = IRQ_TYPE_EDGE_BOTH;
Vitaly Bordug73844ec2007-01-31 02:08:54 +0300145
Mark Wareb22b97c2009-12-10 22:14:34 +1100146 if (flow_type != IRQ_TYPE_EDGE_BOTH &&
147 flow_type != IRQ_TYPE_EDGE_FALLING)
148 goto err_sense;
149 } else {
150 if (flow_type == IRQ_TYPE_NONE)
151 flow_type = IRQ_TYPE_LEVEL_LOW;
152
153 if (flow_type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_LEVEL_HIGH))
154 goto err_sense;
Vitaly Bordug73844ec2007-01-31 02:08:54 +0300155 }
156
Thomas Gleixnera28ab382011-03-25 16:07:51 +0100157 irqd_set_trigger_type(d, flow_type);
158 if (flow_type & IRQ_TYPE_LEVEL_LOW)
Thomas Gleixnerec775d02011-03-25 16:45:20 +0100159 __irq_set_handler_locked(d->irq, handle_level_irq);
Thomas Gleixnera28ab382011-03-25 16:07:51 +0100160 else
Thomas Gleixnerec775d02011-03-25 16:45:20 +0100161 __irq_set_handler_locked(d->irq, handle_edge_irq);
Vitaly Bordug73844ec2007-01-31 02:08:54 +0300162
163 /* internal IRQ senses are LEVEL_LOW
164 * EXT IRQ and Port C IRQ senses are programmable
165 */
166 if (src >= CPM2_IRQ_EXT1 && src <= CPM2_IRQ_EXT7)
167 edibit = (14 - (src - CPM2_IRQ_EXT1));
168 else
169 if (src >= CPM2_IRQ_PORTC15 && src <= CPM2_IRQ_PORTC0)
paulfax7f3ea172009-01-27 02:44:07 -0600170 edibit = (31 - (CPM2_IRQ_PORTC0 - src));
Vitaly Bordug73844ec2007-01-31 02:08:54 +0300171 else
Thomas Gleixnera28ab382011-03-25 16:07:51 +0100172 return (flow_type & IRQ_TYPE_LEVEL_LOW) ?
173 IRQ_SET_MASK_OK_NOCOPY : -EINVAL;
Vitaly Bordug73844ec2007-01-31 02:08:54 +0300174
175 vold = in_be32(&cpm2_intctl->ic_siexr);
176
177 if ((flow_type & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_FALLING)
178 vnew = vold | (1 << edibit);
179 else
180 vnew = vold & ~(1 << edibit);
181
182 if (vold != vnew)
183 out_be32(&cpm2_intctl->ic_siexr, vnew);
Thomas Gleixnera28ab382011-03-25 16:07:51 +0100184 return IRQ_SET_MASK_OK_NOCOPY;
Mark Wareb22b97c2009-12-10 22:14:34 +1100185
186err_sense:
187 pr_err("CPM2 PIC: sense type 0x%x not supported\n", flow_type);
188 return -EINVAL;
Vitaly Bordug73844ec2007-01-31 02:08:54 +0300189}
190
Vitaly Bordugb0c110b2006-09-21 22:18:53 +0400191static struct irq_chip cpm2_pic = {
Anton Blanchardfc380c02010-01-31 20:33:41 +0000192 .name = "CPM2 SIU",
Lennert Buytenhekc47eefa2011-03-07 13:59:51 +0000193 .irq_mask = cpm2_mask_irq,
194 .irq_unmask = cpm2_unmask_irq,
195 .irq_ack = cpm2_ack,
196 .irq_eoi = cpm2_end_irq,
197 .irq_set_type = cpm2_set_irq_type,
Thomas Gleixner7bf811a82011-03-25 16:13:38 +0100198 .flags = IRQCHIP_EOI_IF_HANDLED,
Vitaly Bordugb0c110b2006-09-21 22:18:53 +0400199};
200
Olaf Hering35a84c22006-10-07 22:08:26 +1000201unsigned int cpm2_get_irq(void)
Vitaly Bordugb0c110b2006-09-21 22:18:53 +0400202{
203 int irq;
204 unsigned long bits;
205
Vitaly Bordugfc8e50e2006-09-21 22:37:58 +0400206 /* For CPM2, read the SIVEC register and shift the bits down
207 * to get the irq number. */
Vitaly Bordug73844ec2007-01-31 02:08:54 +0300208 bits = in_be32(&cpm2_intctl->ic_sivec);
Vitaly Bordugfc8e50e2006-09-21 22:37:58 +0400209 irq = bits >> 26;
Vitaly Bordugb0c110b2006-09-21 22:18:53 +0400210
211 if (irq == 0)
212 return(-1);
Vitaly Bordug73844ec2007-01-31 02:08:54 +0300213 return irq_linear_revmap(cpm2_pic_host, irq);
Vitaly Bordugb0c110b2006-09-21 22:18:53 +0400214}
215
Grant Likelybae1d8f2012-02-14 14:06:50 -0700216static int cpm2_pic_host_map(struct irq_domain *h, unsigned int virq,
Vitaly Bordugb0c110b2006-09-21 22:18:53 +0400217 irq_hw_number_t hw)
218{
219 pr_debug("cpm2_pic_host_map(%d, 0x%lx)\n", virq, hw);
220
Thomas Gleixner98488db2011-03-25 15:43:57 +0100221 irq_set_status_flags(virq, IRQ_LEVEL);
Thomas Gleixnerec775d02011-03-25 16:45:20 +0100222 irq_set_chip_and_handler(virq, &cpm2_pic, handle_level_irq);
Vitaly Bordugb0c110b2006-09-21 22:18:53 +0400223 return 0;
224}
225
Grant Likely9f70b8e2012-01-26 12:24:34 -0700226static const struct irq_domain_ops cpm2_pic_host_ops = {
Vitaly Bordugb0c110b2006-09-21 22:18:53 +0400227 .map = cpm2_pic_host_map,
Grant Likelyff8c3ab2012-01-24 17:09:13 -0700228 .xlate = irq_domain_xlate_onetwocell,
Vitaly Bordugb0c110b2006-09-21 22:18:53 +0400229};
230
231void cpm2_pic_init(struct device_node *node)
232{
233 int i;
234
Vitaly Bordug73844ec2007-01-31 02:08:54 +0300235 cpm2_intctl = cpm2_map(im_intctl);
236
Vitaly Bordugb0c110b2006-09-21 22:18:53 +0400237 /* Clear the CPM IRQ controller, in case it has any bits set
238 * from the bootloader
239 */
240
241 /* Mask out everything */
242
Vitaly Bordug73844ec2007-01-31 02:08:54 +0300243 out_be32(&cpm2_intctl->ic_simrh, 0x00000000);
244 out_be32(&cpm2_intctl->ic_simrl, 0x00000000);
Vitaly Bordugb0c110b2006-09-21 22:18:53 +0400245
246 wmb();
247
248 /* Ack everything */
Vitaly Bordug73844ec2007-01-31 02:08:54 +0300249 out_be32(&cpm2_intctl->ic_sipnrh, 0xffffffff);
250 out_be32(&cpm2_intctl->ic_sipnrl, 0xffffffff);
Vitaly Bordugb0c110b2006-09-21 22:18:53 +0400251 wmb();
252
253 /* Dummy read of the vector */
Vitaly Bordug73844ec2007-01-31 02:08:54 +0300254 i = in_be32(&cpm2_intctl->ic_sivec);
Vitaly Bordugb0c110b2006-09-21 22:18:53 +0400255 rmb();
256
257 /* Initialize the default interrupt mapping priorities,
258 * in case the boot rom changed something on us.
259 */
Vitaly Bordug73844ec2007-01-31 02:08:54 +0300260 out_be16(&cpm2_intctl->ic_sicr, 0);
261 out_be32(&cpm2_intctl->ic_scprrh, 0x05309770);
262 out_be32(&cpm2_intctl->ic_scprrl, 0x05309770);
Vitaly Bordugb0c110b2006-09-21 22:18:53 +0400263
264 /* create a legacy host */
Grant Likelya8db8cf2012-02-14 14:06:54 -0700265 cpm2_pic_host = irq_domain_add_linear(node, 64, &cpm2_pic_host_ops, NULL);
Vitaly Bordugb0c110b2006-09-21 22:18:53 +0400266 if (cpm2_pic_host == NULL) {
267 printk(KERN_ERR "CPM2 PIC: failed to allocate irq host!\n");
268 return;
269 }
270}