xref: /linux/arch/powerpc/sysdev/ipic.c (revision ef24ba7091517d2bbf9ba2cb4256c0dccd51d248)
11cd8e506SKumar Gala /*
2f30c2269SUwe Zeisberger  * arch/powerpc/sysdev/ipic.c
31cd8e506SKumar Gala  *
41cd8e506SKumar Gala  * IPIC routines implementations.
51cd8e506SKumar Gala  *
61cd8e506SKumar Gala  * Copyright 2005 Freescale Semiconductor, Inc.
71cd8e506SKumar Gala  *
81cd8e506SKumar Gala  * This program is free software; you can redistribute  it and/or modify it
91cd8e506SKumar Gala  * under  the terms of  the GNU General  Public License as published by the
101cd8e506SKumar Gala  * Free Software Foundation;  either version 2 of the  License, or (at your
111cd8e506SKumar Gala  * option) any later version.
121cd8e506SKumar Gala  */
131cd8e506SKumar Gala #include <linux/kernel.h>
141cd8e506SKumar Gala #include <linux/init.h>
151cd8e506SKumar Gala #include <linux/errno.h>
161cd8e506SKumar Gala #include <linux/reboot.h>
171cd8e506SKumar Gala #include <linux/slab.h>
181cd8e506SKumar Gala #include <linux/stddef.h>
191cd8e506SKumar Gala #include <linux/sched.h>
201cd8e506SKumar Gala #include <linux/signal.h>
21f5a592f7SRafael J. Wysocki #include <linux/syscore_ops.h>
22b9f0f1bbSKim Phillips #include <linux/device.h>
23b9f0f1bbSKim Phillips #include <linux/spinlock.h>
24d49747bdSScott Wood #include <linux/fsl_devices.h>
251cd8e506SKumar Gala #include <asm/irq.h>
261cd8e506SKumar Gala #include <asm/io.h>
27b9f0f1bbSKim Phillips #include <asm/prom.h>
281cd8e506SKumar Gala #include <asm/ipic.h>
291cd8e506SKumar Gala 
301cd8e506SKumar Gala #include "ipic.h"
311cd8e506SKumar Gala 
321cd8e506SKumar Gala static struct ipic * primary_ipic;
3377d4309eSLi Yang static struct irq_chip ipic_level_irq_chip, ipic_edge_irq_chip;
34a9e8bf21SThomas Gleixner static DEFINE_RAW_SPINLOCK(ipic_lock);
351cd8e506SKumar Gala 
361cd8e506SKumar Gala static struct ipic_info ipic_info[] = {
37f03ca957SLi Yang 	[1] = {
38f03ca957SLi Yang 		.mask	= IPIC_SIMSR_H,
39f03ca957SLi Yang 		.prio	= IPIC_SIPRR_C,
40f03ca957SLi Yang 		.force	= IPIC_SIFCR_H,
41f03ca957SLi Yang 		.bit	= 16,
42f03ca957SLi Yang 		.prio_mask = 0,
43f03ca957SLi Yang 	},
44f03ca957SLi Yang 	[2] = {
45f03ca957SLi Yang 		.mask	= IPIC_SIMSR_H,
46f03ca957SLi Yang 		.prio	= IPIC_SIPRR_C,
47f03ca957SLi Yang 		.force	= IPIC_SIFCR_H,
48f03ca957SLi Yang 		.bit	= 17,
49f03ca957SLi Yang 		.prio_mask = 1,
50f03ca957SLi Yang 	},
51a7267d67SJohn Rigby 	[3] = {
52a7267d67SJohn Rigby 		.mask	= IPIC_SIMSR_H,
53a7267d67SJohn Rigby 		.prio	= IPIC_SIPRR_C,
54a7267d67SJohn Rigby 		.force	= IPIC_SIFCR_H,
55a7267d67SJohn Rigby 		.bit	= 18,
56a7267d67SJohn Rigby 		.prio_mask = 2,
57a7267d67SJohn Rigby 	},
58f03ca957SLi Yang 	[4] = {
59f03ca957SLi Yang 		.mask	= IPIC_SIMSR_H,
60f03ca957SLi Yang 		.prio	= IPIC_SIPRR_C,
61f03ca957SLi Yang 		.force	= IPIC_SIFCR_H,
62f03ca957SLi Yang 		.bit	= 19,
63f03ca957SLi Yang 		.prio_mask = 3,
64f03ca957SLi Yang 	},
65a7267d67SJohn Rigby 	[5] = {
66a7267d67SJohn Rigby 		.mask	= IPIC_SIMSR_H,
67a7267d67SJohn Rigby 		.prio	= IPIC_SIPRR_C,
68a7267d67SJohn Rigby 		.force	= IPIC_SIFCR_H,
69a7267d67SJohn Rigby 		.bit	= 20,
70a7267d67SJohn Rigby 		.prio_mask = 4,
71a7267d67SJohn Rigby 	},
72a7267d67SJohn Rigby 	[6] = {
73a7267d67SJohn Rigby 		.mask	= IPIC_SIMSR_H,
74a7267d67SJohn Rigby 		.prio	= IPIC_SIPRR_C,
75a7267d67SJohn Rigby 		.force	= IPIC_SIFCR_H,
76a7267d67SJohn Rigby 		.bit	= 21,
77a7267d67SJohn Rigby 		.prio_mask = 5,
78a7267d67SJohn Rigby 	},
79a7267d67SJohn Rigby 	[7] = {
80a7267d67SJohn Rigby 		.mask	= IPIC_SIMSR_H,
81a7267d67SJohn Rigby 		.prio	= IPIC_SIPRR_C,
82a7267d67SJohn Rigby 		.force	= IPIC_SIFCR_H,
83a7267d67SJohn Rigby 		.bit	= 22,
84a7267d67SJohn Rigby 		.prio_mask = 6,
85a7267d67SJohn Rigby 	},
86a7267d67SJohn Rigby 	[8] = {
87a7267d67SJohn Rigby 		.mask	= IPIC_SIMSR_H,
88a7267d67SJohn Rigby 		.prio	= IPIC_SIPRR_C,
89a7267d67SJohn Rigby 		.force	= IPIC_SIFCR_H,
90a7267d67SJohn Rigby 		.bit	= 23,
91a7267d67SJohn Rigby 		.prio_mask = 7,
92a7267d67SJohn Rigby 	},
931cd8e506SKumar Gala 	[9] = {
941cd8e506SKumar Gala 		.mask	= IPIC_SIMSR_H,
951cd8e506SKumar Gala 		.prio	= IPIC_SIPRR_D,
961cd8e506SKumar Gala 		.force	= IPIC_SIFCR_H,
971cd8e506SKumar Gala 		.bit	= 24,
981cd8e506SKumar Gala 		.prio_mask = 0,
991cd8e506SKumar Gala 	},
1001cd8e506SKumar Gala 	[10] = {
1011cd8e506SKumar Gala 		.mask	= IPIC_SIMSR_H,
1021cd8e506SKumar Gala 		.prio	= IPIC_SIPRR_D,
1031cd8e506SKumar Gala 		.force	= IPIC_SIFCR_H,
1041cd8e506SKumar Gala 		.bit	= 25,
1051cd8e506SKumar Gala 		.prio_mask = 1,
1061cd8e506SKumar Gala 	},
1071cd8e506SKumar Gala 	[11] = {
1081cd8e506SKumar Gala 		.mask	= IPIC_SIMSR_H,
1091cd8e506SKumar Gala 		.prio	= IPIC_SIPRR_D,
1101cd8e506SKumar Gala 		.force	= IPIC_SIFCR_H,
1111cd8e506SKumar Gala 		.bit	= 26,
1121cd8e506SKumar Gala 		.prio_mask = 2,
1131cd8e506SKumar Gala 	},
114f03ca957SLi Yang 	[12] = {
115f03ca957SLi Yang 		.mask	= IPIC_SIMSR_H,
116f03ca957SLi Yang 		.prio	= IPIC_SIPRR_D,
117f03ca957SLi Yang 		.force	= IPIC_SIFCR_H,
118f03ca957SLi Yang 		.bit	= 27,
119f03ca957SLi Yang 		.prio_mask = 3,
120f03ca957SLi Yang 	},
121f03ca957SLi Yang 	[13] = {
122f03ca957SLi Yang 		.mask	= IPIC_SIMSR_H,
123f03ca957SLi Yang 		.prio	= IPIC_SIPRR_D,
124f03ca957SLi Yang 		.force	= IPIC_SIFCR_H,
125f03ca957SLi Yang 		.bit	= 28,
126f03ca957SLi Yang 		.prio_mask = 4,
127f03ca957SLi Yang 	},
1281cd8e506SKumar Gala 	[14] = {
1291cd8e506SKumar Gala 		.mask	= IPIC_SIMSR_H,
1301cd8e506SKumar Gala 		.prio	= IPIC_SIPRR_D,
1311cd8e506SKumar Gala 		.force	= IPIC_SIFCR_H,
1321cd8e506SKumar Gala 		.bit	= 29,
1331cd8e506SKumar Gala 		.prio_mask = 5,
1341cd8e506SKumar Gala 	},
1351cd8e506SKumar Gala 	[15] = {
1361cd8e506SKumar Gala 		.mask	= IPIC_SIMSR_H,
1371cd8e506SKumar Gala 		.prio	= IPIC_SIPRR_D,
1381cd8e506SKumar Gala 		.force	= IPIC_SIFCR_H,
1391cd8e506SKumar Gala 		.bit	= 30,
1401cd8e506SKumar Gala 		.prio_mask = 6,
1411cd8e506SKumar Gala 	},
1421cd8e506SKumar Gala 	[16] = {
1431cd8e506SKumar Gala 		.mask	= IPIC_SIMSR_H,
1441cd8e506SKumar Gala 		.prio	= IPIC_SIPRR_D,
1451cd8e506SKumar Gala 		.force	= IPIC_SIFCR_H,
1461cd8e506SKumar Gala 		.bit	= 31,
1471cd8e506SKumar Gala 		.prio_mask = 7,
1481cd8e506SKumar Gala 	},
1491cd8e506SKumar Gala 	[17] = {
15077d4309eSLi Yang 		.ack	= IPIC_SEPNR,
1511cd8e506SKumar Gala 		.mask	= IPIC_SEMSR,
1521cd8e506SKumar Gala 		.prio	= IPIC_SMPRR_A,
1531cd8e506SKumar Gala 		.force	= IPIC_SEFCR,
1541cd8e506SKumar Gala 		.bit	= 1,
1551cd8e506SKumar Gala 		.prio_mask = 5,
1561cd8e506SKumar Gala 	},
1571cd8e506SKumar Gala 	[18] = {
15877d4309eSLi Yang 		.ack	= IPIC_SEPNR,
1591cd8e506SKumar Gala 		.mask	= IPIC_SEMSR,
1601cd8e506SKumar Gala 		.prio	= IPIC_SMPRR_A,
1611cd8e506SKumar Gala 		.force	= IPIC_SEFCR,
1621cd8e506SKumar Gala 		.bit	= 2,
1631cd8e506SKumar Gala 		.prio_mask = 6,
1641cd8e506SKumar Gala 	},
1651cd8e506SKumar Gala 	[19] = {
16677d4309eSLi Yang 		.ack	= IPIC_SEPNR,
1671cd8e506SKumar Gala 		.mask	= IPIC_SEMSR,
1681cd8e506SKumar Gala 		.prio	= IPIC_SMPRR_A,
1691cd8e506SKumar Gala 		.force	= IPIC_SEFCR,
1701cd8e506SKumar Gala 		.bit	= 3,
1711cd8e506SKumar Gala 		.prio_mask = 7,
1721cd8e506SKumar Gala 	},
1731cd8e506SKumar Gala 	[20] = {
17477d4309eSLi Yang 		.ack	= IPIC_SEPNR,
1751cd8e506SKumar Gala 		.mask	= IPIC_SEMSR,
1761cd8e506SKumar Gala 		.prio	= IPIC_SMPRR_B,
1771cd8e506SKumar Gala 		.force	= IPIC_SEFCR,
1781cd8e506SKumar Gala 		.bit	= 4,
1791cd8e506SKumar Gala 		.prio_mask = 4,
1801cd8e506SKumar Gala 	},
1811cd8e506SKumar Gala 	[21] = {
18277d4309eSLi Yang 		.ack	= IPIC_SEPNR,
1831cd8e506SKumar Gala 		.mask	= IPIC_SEMSR,
1841cd8e506SKumar Gala 		.prio	= IPIC_SMPRR_B,
1851cd8e506SKumar Gala 		.force	= IPIC_SEFCR,
1861cd8e506SKumar Gala 		.bit	= 5,
1871cd8e506SKumar Gala 		.prio_mask = 5,
1881cd8e506SKumar Gala 	},
1891cd8e506SKumar Gala 	[22] = {
19077d4309eSLi Yang 		.ack	= IPIC_SEPNR,
1911cd8e506SKumar Gala 		.mask	= IPIC_SEMSR,
1921cd8e506SKumar Gala 		.prio	= IPIC_SMPRR_B,
1931cd8e506SKumar Gala 		.force	= IPIC_SEFCR,
1941cd8e506SKumar Gala 		.bit	= 6,
1951cd8e506SKumar Gala 		.prio_mask = 6,
1961cd8e506SKumar Gala 	},
1971cd8e506SKumar Gala 	[23] = {
19877d4309eSLi Yang 		.ack	= IPIC_SEPNR,
1991cd8e506SKumar Gala 		.mask	= IPIC_SEMSR,
2001cd8e506SKumar Gala 		.prio	= IPIC_SMPRR_B,
2011cd8e506SKumar Gala 		.force	= IPIC_SEFCR,
2021cd8e506SKumar Gala 		.bit	= 7,
2031cd8e506SKumar Gala 		.prio_mask = 7,
2041cd8e506SKumar Gala 	},
2051cd8e506SKumar Gala 	[32] = {
2061cd8e506SKumar Gala 		.mask	= IPIC_SIMSR_H,
2071cd8e506SKumar Gala 		.prio	= IPIC_SIPRR_A,
2081cd8e506SKumar Gala 		.force	= IPIC_SIFCR_H,
2091cd8e506SKumar Gala 		.bit	= 0,
2101cd8e506SKumar Gala 		.prio_mask = 0,
2111cd8e506SKumar Gala 	},
2121cd8e506SKumar Gala 	[33] = {
2131cd8e506SKumar Gala 		.mask	= IPIC_SIMSR_H,
2141cd8e506SKumar Gala 		.prio	= IPIC_SIPRR_A,
2151cd8e506SKumar Gala 		.force	= IPIC_SIFCR_H,
2161cd8e506SKumar Gala 		.bit	= 1,
2171cd8e506SKumar Gala 		.prio_mask = 1,
2181cd8e506SKumar Gala 	},
2191cd8e506SKumar Gala 	[34] = {
2201cd8e506SKumar Gala 		.mask	= IPIC_SIMSR_H,
2211cd8e506SKumar Gala 		.prio	= IPIC_SIPRR_A,
2221cd8e506SKumar Gala 		.force	= IPIC_SIFCR_H,
2231cd8e506SKumar Gala 		.bit	= 2,
2241cd8e506SKumar Gala 		.prio_mask = 2,
2251cd8e506SKumar Gala 	},
2261cd8e506SKumar Gala 	[35] = {
2271cd8e506SKumar Gala 		.mask	= IPIC_SIMSR_H,
2281cd8e506SKumar Gala 		.prio	= IPIC_SIPRR_A,
2291cd8e506SKumar Gala 		.force	= IPIC_SIFCR_H,
2301cd8e506SKumar Gala 		.bit	= 3,
2311cd8e506SKumar Gala 		.prio_mask = 3,
2321cd8e506SKumar Gala 	},
2331cd8e506SKumar Gala 	[36] = {
2341cd8e506SKumar Gala 		.mask	= IPIC_SIMSR_H,
2351cd8e506SKumar Gala 		.prio	= IPIC_SIPRR_A,
2361cd8e506SKumar Gala 		.force	= IPIC_SIFCR_H,
2371cd8e506SKumar Gala 		.bit	= 4,
2381cd8e506SKumar Gala 		.prio_mask = 4,
2391cd8e506SKumar Gala 	},
2401cd8e506SKumar Gala 	[37] = {
2411cd8e506SKumar Gala 		.mask	= IPIC_SIMSR_H,
2421cd8e506SKumar Gala 		.prio	= IPIC_SIPRR_A,
2431cd8e506SKumar Gala 		.force	= IPIC_SIFCR_H,
2441cd8e506SKumar Gala 		.bit	= 5,
2451cd8e506SKumar Gala 		.prio_mask = 5,
2461cd8e506SKumar Gala 	},
2471cd8e506SKumar Gala 	[38] = {
2481cd8e506SKumar Gala 		.mask	= IPIC_SIMSR_H,
2491cd8e506SKumar Gala 		.prio	= IPIC_SIPRR_A,
2501cd8e506SKumar Gala 		.force	= IPIC_SIFCR_H,
2511cd8e506SKumar Gala 		.bit	= 6,
2521cd8e506SKumar Gala 		.prio_mask = 6,
2531cd8e506SKumar Gala 	},
2541cd8e506SKumar Gala 	[39] = {
2551cd8e506SKumar Gala 		.mask	= IPIC_SIMSR_H,
2561cd8e506SKumar Gala 		.prio	= IPIC_SIPRR_A,
2571cd8e506SKumar Gala 		.force	= IPIC_SIFCR_H,
2581cd8e506SKumar Gala 		.bit	= 7,
2591cd8e506SKumar Gala 		.prio_mask = 7,
2601cd8e506SKumar Gala 	},
261a7267d67SJohn Rigby 	[40] = {
262a7267d67SJohn Rigby 		.mask	= IPIC_SIMSR_H,
263a7267d67SJohn Rigby 		.prio	= IPIC_SIPRR_B,
264a7267d67SJohn Rigby 		.force	= IPIC_SIFCR_H,
265a7267d67SJohn Rigby 		.bit	= 8,
266a7267d67SJohn Rigby 		.prio_mask = 0,
267a7267d67SJohn Rigby 	},
268a7267d67SJohn Rigby 	[41] = {
269a7267d67SJohn Rigby 		.mask	= IPIC_SIMSR_H,
270a7267d67SJohn Rigby 		.prio	= IPIC_SIPRR_B,
271a7267d67SJohn Rigby 		.force	= IPIC_SIFCR_H,
272a7267d67SJohn Rigby 		.bit	= 9,
273a7267d67SJohn Rigby 		.prio_mask = 1,
274a7267d67SJohn Rigby 	},
275f03ca957SLi Yang 	[42] = {
276f03ca957SLi Yang 		.mask	= IPIC_SIMSR_H,
277f03ca957SLi Yang 		.prio	= IPIC_SIPRR_B,
278f03ca957SLi Yang 		.force	= IPIC_SIFCR_H,
279f03ca957SLi Yang 		.bit	= 10,
280f03ca957SLi Yang 		.prio_mask = 2,
281f03ca957SLi Yang 	},
282a7267d67SJohn Rigby 	[43] = {
283a7267d67SJohn Rigby 		.mask	= IPIC_SIMSR_H,
284a7267d67SJohn Rigby 		.prio	= IPIC_SIPRR_B,
285a7267d67SJohn Rigby 		.force	= IPIC_SIFCR_H,
286a7267d67SJohn Rigby 		.bit	= 11,
287a7267d67SJohn Rigby 		.prio_mask = 3,
288a7267d67SJohn Rigby 	},
289f03ca957SLi Yang 	[44] = {
290f03ca957SLi Yang 		.mask	= IPIC_SIMSR_H,
291f03ca957SLi Yang 		.prio	= IPIC_SIPRR_B,
292f03ca957SLi Yang 		.force	= IPIC_SIFCR_H,
293f03ca957SLi Yang 		.bit	= 12,
294f03ca957SLi Yang 		.prio_mask = 4,
295f03ca957SLi Yang 	},
296f03ca957SLi Yang 	[45] = {
297f03ca957SLi Yang 		.mask	= IPIC_SIMSR_H,
298f03ca957SLi Yang 		.prio	= IPIC_SIPRR_B,
299f03ca957SLi Yang 		.force	= IPIC_SIFCR_H,
300f03ca957SLi Yang 		.bit	= 13,
301f03ca957SLi Yang 		.prio_mask = 5,
302f03ca957SLi Yang 	},
303f03ca957SLi Yang 	[46] = {
304f03ca957SLi Yang 		.mask	= IPIC_SIMSR_H,
305f03ca957SLi Yang 		.prio	= IPIC_SIPRR_B,
306f03ca957SLi Yang 		.force	= IPIC_SIFCR_H,
307f03ca957SLi Yang 		.bit	= 14,
308f03ca957SLi Yang 		.prio_mask = 6,
309f03ca957SLi Yang 	},
310f03ca957SLi Yang 	[47] = {
311f03ca957SLi Yang 		.mask	= IPIC_SIMSR_H,
312f03ca957SLi Yang 		.prio	= IPIC_SIPRR_B,
313f03ca957SLi Yang 		.force	= IPIC_SIFCR_H,
314f03ca957SLi Yang 		.bit	= 15,
315f03ca957SLi Yang 		.prio_mask = 7,
316f03ca957SLi Yang 	},
3171cd8e506SKumar Gala 	[48] = {
3181cd8e506SKumar Gala 		.mask	= IPIC_SEMSR,
3191cd8e506SKumar Gala 		.prio	= IPIC_SMPRR_A,
3201cd8e506SKumar Gala 		.force	= IPIC_SEFCR,
3211cd8e506SKumar Gala 		.bit	= 0,
3221cd8e506SKumar Gala 		.prio_mask = 4,
3231cd8e506SKumar Gala 	},
3241cd8e506SKumar Gala 	[64] = {
3251cd8e506SKumar Gala 		.mask	= IPIC_SIMSR_L,
3261cd8e506SKumar Gala 		.prio	= IPIC_SMPRR_A,
3271cd8e506SKumar Gala 		.force	= IPIC_SIFCR_L,
3281cd8e506SKumar Gala 		.bit	= 0,
3291cd8e506SKumar Gala 		.prio_mask = 0,
3301cd8e506SKumar Gala 	},
3311cd8e506SKumar Gala 	[65] = {
3321cd8e506SKumar Gala 		.mask	= IPIC_SIMSR_L,
3331cd8e506SKumar Gala 		.prio	= IPIC_SMPRR_A,
3341cd8e506SKumar Gala 		.force	= IPIC_SIFCR_L,
3351cd8e506SKumar Gala 		.bit	= 1,
3361cd8e506SKumar Gala 		.prio_mask = 1,
3371cd8e506SKumar Gala 	},
3381cd8e506SKumar Gala 	[66] = {
3391cd8e506SKumar Gala 		.mask	= IPIC_SIMSR_L,
3401cd8e506SKumar Gala 		.prio	= IPIC_SMPRR_A,
3411cd8e506SKumar Gala 		.force	= IPIC_SIFCR_L,
3421cd8e506SKumar Gala 		.bit	= 2,
3431cd8e506SKumar Gala 		.prio_mask = 2,
3441cd8e506SKumar Gala 	},
3451cd8e506SKumar Gala 	[67] = {
3461cd8e506SKumar Gala 		.mask	= IPIC_SIMSR_L,
3471cd8e506SKumar Gala 		.prio	= IPIC_SMPRR_A,
3481cd8e506SKumar Gala 		.force	= IPIC_SIFCR_L,
3491cd8e506SKumar Gala 		.bit	= 3,
3501cd8e506SKumar Gala 		.prio_mask = 3,
3511cd8e506SKumar Gala 	},
3521cd8e506SKumar Gala 	[68] = {
3531cd8e506SKumar Gala 		.mask	= IPIC_SIMSR_L,
3541cd8e506SKumar Gala 		.prio	= IPIC_SMPRR_B,
3551cd8e506SKumar Gala 		.force	= IPIC_SIFCR_L,
3561cd8e506SKumar Gala 		.bit	= 4,
3571cd8e506SKumar Gala 		.prio_mask = 0,
3581cd8e506SKumar Gala 	},
3591cd8e506SKumar Gala 	[69] = {
3601cd8e506SKumar Gala 		.mask	= IPIC_SIMSR_L,
3611cd8e506SKumar Gala 		.prio	= IPIC_SMPRR_B,
3621cd8e506SKumar Gala 		.force	= IPIC_SIFCR_L,
3631cd8e506SKumar Gala 		.bit	= 5,
3641cd8e506SKumar Gala 		.prio_mask = 1,
3651cd8e506SKumar Gala 	},
3661cd8e506SKumar Gala 	[70] = {
3671cd8e506SKumar Gala 		.mask	= IPIC_SIMSR_L,
3681cd8e506SKumar Gala 		.prio	= IPIC_SMPRR_B,
3691cd8e506SKumar Gala 		.force	= IPIC_SIFCR_L,
3701cd8e506SKumar Gala 		.bit	= 6,
3711cd8e506SKumar Gala 		.prio_mask = 2,
3721cd8e506SKumar Gala 	},
3731cd8e506SKumar Gala 	[71] = {
3741cd8e506SKumar Gala 		.mask	= IPIC_SIMSR_L,
3751cd8e506SKumar Gala 		.prio	= IPIC_SMPRR_B,
3761cd8e506SKumar Gala 		.force	= IPIC_SIFCR_L,
3771cd8e506SKumar Gala 		.bit	= 7,
3781cd8e506SKumar Gala 		.prio_mask = 3,
3791cd8e506SKumar Gala 	},
3801cd8e506SKumar Gala 	[72] = {
3811cd8e506SKumar Gala 		.mask	= IPIC_SIMSR_L,
3821cd8e506SKumar Gala 		.prio	= 0,
3831cd8e506SKumar Gala 		.force	= IPIC_SIFCR_L,
3841cd8e506SKumar Gala 		.bit	= 8,
3851cd8e506SKumar Gala 	},
3861cd8e506SKumar Gala 	[73] = {
3871cd8e506SKumar Gala 		.mask	= IPIC_SIMSR_L,
3881cd8e506SKumar Gala 		.prio	= 0,
3891cd8e506SKumar Gala 		.force	= IPIC_SIFCR_L,
3901cd8e506SKumar Gala 		.bit	= 9,
3911cd8e506SKumar Gala 	},
3921cd8e506SKumar Gala 	[74] = {
3931cd8e506SKumar Gala 		.mask	= IPIC_SIMSR_L,
3941cd8e506SKumar Gala 		.prio	= 0,
3951cd8e506SKumar Gala 		.force	= IPIC_SIFCR_L,
3961cd8e506SKumar Gala 		.bit	= 10,
3971cd8e506SKumar Gala 	},
3981cd8e506SKumar Gala 	[75] = {
3991cd8e506SKumar Gala 		.mask	= IPIC_SIMSR_L,
4001cd8e506SKumar Gala 		.prio	= 0,
4011cd8e506SKumar Gala 		.force	= IPIC_SIFCR_L,
4021cd8e506SKumar Gala 		.bit	= 11,
4031cd8e506SKumar Gala 	},
4041cd8e506SKumar Gala 	[76] = {
4051cd8e506SKumar Gala 		.mask	= IPIC_SIMSR_L,
4061cd8e506SKumar Gala 		.prio	= 0,
4071cd8e506SKumar Gala 		.force	= IPIC_SIFCR_L,
4081cd8e506SKumar Gala 		.bit	= 12,
4091cd8e506SKumar Gala 	},
4101cd8e506SKumar Gala 	[77] = {
4111cd8e506SKumar Gala 		.mask	= IPIC_SIMSR_L,
4121cd8e506SKumar Gala 		.prio	= 0,
4131cd8e506SKumar Gala 		.force	= IPIC_SIFCR_L,
4141cd8e506SKumar Gala 		.bit	= 13,
4151cd8e506SKumar Gala 	},
4161cd8e506SKumar Gala 	[78] = {
4171cd8e506SKumar Gala 		.mask	= IPIC_SIMSR_L,
4181cd8e506SKumar Gala 		.prio	= 0,
4191cd8e506SKumar Gala 		.force	= IPIC_SIFCR_L,
4201cd8e506SKumar Gala 		.bit	= 14,
4211cd8e506SKumar Gala 	},
4221cd8e506SKumar Gala 	[79] = {
4231cd8e506SKumar Gala 		.mask	= IPIC_SIMSR_L,
4241cd8e506SKumar Gala 		.prio	= 0,
4251cd8e506SKumar Gala 		.force	= IPIC_SIFCR_L,
4261cd8e506SKumar Gala 		.bit	= 15,
4271cd8e506SKumar Gala 	},
4281cd8e506SKumar Gala 	[80] = {
4291cd8e506SKumar Gala 		.mask	= IPIC_SIMSR_L,
4301cd8e506SKumar Gala 		.prio	= 0,
4311cd8e506SKumar Gala 		.force	= IPIC_SIFCR_L,
4321cd8e506SKumar Gala 		.bit	= 16,
4331cd8e506SKumar Gala 	},
434f03ca957SLi Yang 	[81] = {
435f03ca957SLi Yang 		.mask	= IPIC_SIMSR_L,
436f03ca957SLi Yang 		.prio	= 0,
437f03ca957SLi Yang 		.force	= IPIC_SIFCR_L,
438f03ca957SLi Yang 		.bit	= 17,
439f03ca957SLi Yang 	},
440f03ca957SLi Yang 	[82] = {
441f03ca957SLi Yang 		.mask	= IPIC_SIMSR_L,
442f03ca957SLi Yang 		.prio	= 0,
443f03ca957SLi Yang 		.force	= IPIC_SIFCR_L,
444f03ca957SLi Yang 		.bit	= 18,
445f03ca957SLi Yang 	},
446a7267d67SJohn Rigby 	[83] = {
447a7267d67SJohn Rigby 		.mask	= IPIC_SIMSR_L,
448a7267d67SJohn Rigby 		.prio	= 0,
449a7267d67SJohn Rigby 		.force	= IPIC_SIFCR_L,
450a7267d67SJohn Rigby 		.bit	= 19,
451a7267d67SJohn Rigby 	},
4521cd8e506SKumar Gala 	[84] = {
4531cd8e506SKumar Gala 		.mask	= IPIC_SIMSR_L,
4541cd8e506SKumar Gala 		.prio	= 0,
4551cd8e506SKumar Gala 		.force	= IPIC_SIFCR_L,
4561cd8e506SKumar Gala 		.bit	= 20,
4571cd8e506SKumar Gala 	},
4581cd8e506SKumar Gala 	[85] = {
4591cd8e506SKumar Gala 		.mask	= IPIC_SIMSR_L,
4601cd8e506SKumar Gala 		.prio	= 0,
4611cd8e506SKumar Gala 		.force	= IPIC_SIFCR_L,
4621cd8e506SKumar Gala 		.bit	= 21,
4631cd8e506SKumar Gala 	},
464f03ca957SLi Yang 	[86] = {
465f03ca957SLi Yang 		.mask	= IPIC_SIMSR_L,
466f03ca957SLi Yang 		.prio	= 0,
467f03ca957SLi Yang 		.force	= IPIC_SIFCR_L,
468f03ca957SLi Yang 		.bit	= 22,
469f03ca957SLi Yang 	},
470f03ca957SLi Yang 	[87] = {
471f03ca957SLi Yang 		.mask	= IPIC_SIMSR_L,
472f03ca957SLi Yang 		.prio	= 0,
473f03ca957SLi Yang 		.force	= IPIC_SIFCR_L,
474f03ca957SLi Yang 		.bit	= 23,
475f03ca957SLi Yang 	},
476f03ca957SLi Yang 	[88] = {
477f03ca957SLi Yang 		.mask	= IPIC_SIMSR_L,
478f03ca957SLi Yang 		.prio	= 0,
479f03ca957SLi Yang 		.force	= IPIC_SIFCR_L,
480f03ca957SLi Yang 		.bit	= 24,
481f03ca957SLi Yang 	},
482f03ca957SLi Yang 	[89] = {
483f03ca957SLi Yang 		.mask	= IPIC_SIMSR_L,
484f03ca957SLi Yang 		.prio	= 0,
485f03ca957SLi Yang 		.force	= IPIC_SIFCR_L,
486f03ca957SLi Yang 		.bit	= 25,
487f03ca957SLi Yang 	},
4881cd8e506SKumar Gala 	[90] = {
4891cd8e506SKumar Gala 		.mask	= IPIC_SIMSR_L,
4901cd8e506SKumar Gala 		.prio	= 0,
4911cd8e506SKumar Gala 		.force	= IPIC_SIFCR_L,
4921cd8e506SKumar Gala 		.bit	= 26,
4931cd8e506SKumar Gala 	},
4941cd8e506SKumar Gala 	[91] = {
4951cd8e506SKumar Gala 		.mask	= IPIC_SIMSR_L,
4961cd8e506SKumar Gala 		.prio	= 0,
4971cd8e506SKumar Gala 		.force	= IPIC_SIFCR_L,
4981cd8e506SKumar Gala 		.bit	= 27,
4991cd8e506SKumar Gala 	},
5008cf6b195SKim Phillips 	[94] = {
5018cf6b195SKim Phillips 		.mask	= IPIC_SIMSR_L,
5028cf6b195SKim Phillips 		.prio	= 0,
5038cf6b195SKim Phillips 		.force	= IPIC_SIFCR_L,
5048cf6b195SKim Phillips 		.bit	= 30,
5058cf6b195SKim Phillips 	},
5061cd8e506SKumar Gala };
5071cd8e506SKumar Gala 
5081cd8e506SKumar Gala static inline u32 ipic_read(volatile u32 __iomem *base, unsigned int reg)
5091cd8e506SKumar Gala {
5101cd8e506SKumar Gala 	return in_be32(base + (reg >> 2));
5111cd8e506SKumar Gala }
5121cd8e506SKumar Gala 
5131cd8e506SKumar Gala static inline void ipic_write(volatile u32 __iomem *base, unsigned int reg, u32 value)
5141cd8e506SKumar Gala {
5151cd8e506SKumar Gala 	out_be32(base + (reg >> 2), value);
5161cd8e506SKumar Gala }
5171cd8e506SKumar Gala 
518b9f0f1bbSKim Phillips static inline struct ipic * ipic_from_irq(unsigned int virq)
5191cd8e506SKumar Gala {
5201cd8e506SKumar Gala 	return primary_ipic;
5211cd8e506SKumar Gala }
5221cd8e506SKumar Gala 
523687228adSLennert Buytenhek static void ipic_unmask_irq(struct irq_data *d)
5241cd8e506SKumar Gala {
525687228adSLennert Buytenhek 	struct ipic *ipic = ipic_from_irq(d->irq);
526476eb491SGrant Likely 	unsigned int src = irqd_to_hwirq(d);
527b9f0f1bbSKim Phillips 	unsigned long flags;
5281cd8e506SKumar Gala 	u32 temp;
5291cd8e506SKumar Gala 
530a9e8bf21SThomas Gleixner 	raw_spin_lock_irqsave(&ipic_lock, flags);
531b9f0f1bbSKim Phillips 
5321cd8e506SKumar Gala 	temp = ipic_read(ipic->regs, ipic_info[src].mask);
5331cd8e506SKumar Gala 	temp |= (1 << (31 - ipic_info[src].bit));
5341cd8e506SKumar Gala 	ipic_write(ipic->regs, ipic_info[src].mask, temp);
535b9f0f1bbSKim Phillips 
536a9e8bf21SThomas Gleixner 	raw_spin_unlock_irqrestore(&ipic_lock, flags);
5371cd8e506SKumar Gala }
5381cd8e506SKumar Gala 
539687228adSLennert Buytenhek static void ipic_mask_irq(struct irq_data *d)
5401cd8e506SKumar Gala {
541687228adSLennert Buytenhek 	struct ipic *ipic = ipic_from_irq(d->irq);
542476eb491SGrant Likely 	unsigned int src = irqd_to_hwirq(d);
543b9f0f1bbSKim Phillips 	unsigned long flags;
5441cd8e506SKumar Gala 	u32 temp;
5451cd8e506SKumar Gala 
546a9e8bf21SThomas Gleixner 	raw_spin_lock_irqsave(&ipic_lock, flags);
547b9f0f1bbSKim Phillips 
5481cd8e506SKumar Gala 	temp = ipic_read(ipic->regs, ipic_info[src].mask);
5491cd8e506SKumar Gala 	temp &= ~(1 << (31 - ipic_info[src].bit));
5501cd8e506SKumar Gala 	ipic_write(ipic->regs, ipic_info[src].mask, temp);
551b9f0f1bbSKim Phillips 
55277d4309eSLi Yang 	/* mb() can't guarantee that masking is finished.  But it does finish
55377d4309eSLi Yang 	 * for nearly all cases. */
55477d4309eSLi Yang 	mb();
55577d4309eSLi Yang 
556a9e8bf21SThomas Gleixner 	raw_spin_unlock_irqrestore(&ipic_lock, flags);
5571cd8e506SKumar Gala }
5581cd8e506SKumar Gala 
559687228adSLennert Buytenhek static void ipic_ack_irq(struct irq_data *d)
5601cd8e506SKumar Gala {
561687228adSLennert Buytenhek 	struct ipic *ipic = ipic_from_irq(d->irq);
562476eb491SGrant Likely 	unsigned int src = irqd_to_hwirq(d);
563b9f0f1bbSKim Phillips 	unsigned long flags;
5641cd8e506SKumar Gala 	u32 temp;
5651cd8e506SKumar Gala 
566a9e8bf21SThomas Gleixner 	raw_spin_lock_irqsave(&ipic_lock, flags);
5671cd8e506SKumar Gala 
56830c40469Sdayu@datangmobile.cn 	temp = 1 << (31 - ipic_info[src].bit);
56977d4309eSLi Yang 	ipic_write(ipic->regs, ipic_info[src].ack, temp);
57077d4309eSLi Yang 
57177d4309eSLi Yang 	/* mb() can't guarantee that ack is finished.  But it does finish
57277d4309eSLi Yang 	 * for nearly all cases. */
57377d4309eSLi Yang 	mb();
574b9f0f1bbSKim Phillips 
575a9e8bf21SThomas Gleixner 	raw_spin_unlock_irqrestore(&ipic_lock, flags);
5761cd8e506SKumar Gala }
5771cd8e506SKumar Gala 
578687228adSLennert Buytenhek static void ipic_mask_irq_and_ack(struct irq_data *d)
5791cd8e506SKumar Gala {
580687228adSLennert Buytenhek 	struct ipic *ipic = ipic_from_irq(d->irq);
581476eb491SGrant Likely 	unsigned int src = irqd_to_hwirq(d);
582b9f0f1bbSKim Phillips 	unsigned long flags;
583b9f0f1bbSKim Phillips 	u32 temp;
584b9f0f1bbSKim Phillips 
585a9e8bf21SThomas Gleixner 	raw_spin_lock_irqsave(&ipic_lock, flags);
586b9f0f1bbSKim Phillips 
587b9f0f1bbSKim Phillips 	temp = ipic_read(ipic->regs, ipic_info[src].mask);
588b9f0f1bbSKim Phillips 	temp &= ~(1 << (31 - ipic_info[src].bit));
589b9f0f1bbSKim Phillips 	ipic_write(ipic->regs, ipic_info[src].mask, temp);
590b9f0f1bbSKim Phillips 
59130c40469Sdayu@datangmobile.cn 	temp = 1 << (31 - ipic_info[src].bit);
59277d4309eSLi Yang 	ipic_write(ipic->regs, ipic_info[src].ack, temp);
59377d4309eSLi Yang 
59477d4309eSLi Yang 	/* mb() can't guarantee that ack is finished.  But it does finish
59577d4309eSLi Yang 	 * for nearly all cases. */
59677d4309eSLi Yang 	mb();
597b9f0f1bbSKim Phillips 
598a9e8bf21SThomas Gleixner 	raw_spin_unlock_irqrestore(&ipic_lock, flags);
5991cd8e506SKumar Gala }
6001cd8e506SKumar Gala 
601687228adSLennert Buytenhek static int ipic_set_irq_type(struct irq_data *d, unsigned int flow_type)
602b9f0f1bbSKim Phillips {
603687228adSLennert Buytenhek 	struct ipic *ipic = ipic_from_irq(d->irq);
604476eb491SGrant Likely 	unsigned int src = irqd_to_hwirq(d);
605b9f0f1bbSKim Phillips 	unsigned int vold, vnew, edibit;
606b9f0f1bbSKim Phillips 
607b9f0f1bbSKim Phillips 	if (flow_type == IRQ_TYPE_NONE)
608b9f0f1bbSKim Phillips 		flow_type = IRQ_TYPE_LEVEL_LOW;
609b9f0f1bbSKim Phillips 
610b9f0f1bbSKim Phillips 	/* ipic supports only low assertion and high-to-low change senses
611b9f0f1bbSKim Phillips 	 */
612b9f0f1bbSKim Phillips 	if (!(flow_type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_EDGE_FALLING))) {
613b9f0f1bbSKim Phillips 		printk(KERN_ERR "ipic: sense type 0x%x not supported\n",
614b9f0f1bbSKim Phillips 			flow_type);
615b9f0f1bbSKim Phillips 		return -EINVAL;
616b9f0f1bbSKim Phillips 	}
61777d4309eSLi Yang 	/* ipic supports only edge mode on external interrupts */
61877d4309eSLi Yang 	if ((flow_type & IRQ_TYPE_EDGE_FALLING) && !ipic_info[src].ack) {
61977d4309eSLi Yang 		printk(KERN_ERR "ipic: edge sense not supported on internal "
62077d4309eSLi Yang 				"interrupts\n");
62177d4309eSLi Yang 		return -EINVAL;
622ecf4b196SThomas Gleixner 
62377d4309eSLi Yang 	}
624b9f0f1bbSKim Phillips 
625ecf4b196SThomas Gleixner 	irqd_set_trigger_type(d, flow_type);
626b9f0f1bbSKim Phillips 	if (flow_type & IRQ_TYPE_LEVEL_LOW)  {
6279758a7b0SThomas Gleixner 		irq_set_handler_locked(d, handle_level_irq);
628ecf4b196SThomas Gleixner 		d->chip = &ipic_level_irq_chip;
629b9f0f1bbSKim Phillips 	} else {
6309758a7b0SThomas Gleixner 		irq_set_handler_locked(d, handle_edge_irq);
631ecf4b196SThomas Gleixner 		d->chip = &ipic_edge_irq_chip;
632b9f0f1bbSKim Phillips 	}
633b9f0f1bbSKim Phillips 
634b9f0f1bbSKim Phillips 	/* only EXT IRQ senses are programmable on ipic
635b9f0f1bbSKim Phillips 	 * internal IRQ senses are LEVEL_LOW
636b9f0f1bbSKim Phillips 	 */
637b9f0f1bbSKim Phillips 	if (src == IPIC_IRQ_EXT0)
638b9f0f1bbSKim Phillips 		edibit = 15;
639b9f0f1bbSKim Phillips 	else
640b9f0f1bbSKim Phillips 		if (src >= IPIC_IRQ_EXT1 && src <= IPIC_IRQ_EXT7)
641b9f0f1bbSKim Phillips 			edibit = (14 - (src - IPIC_IRQ_EXT1));
642b9f0f1bbSKim Phillips 		else
643b9f0f1bbSKim Phillips 			return (flow_type & IRQ_TYPE_LEVEL_LOW) ? 0 : -EINVAL;
644b9f0f1bbSKim Phillips 
645b9f0f1bbSKim Phillips 	vold = ipic_read(ipic->regs, IPIC_SECNR);
646b9f0f1bbSKim Phillips 	if ((flow_type & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_FALLING) {
647b9f0f1bbSKim Phillips 		vnew = vold | (1 << edibit);
648b9f0f1bbSKim Phillips 	} else {
649b9f0f1bbSKim Phillips 		vnew = vold & ~(1 << edibit);
650b9f0f1bbSKim Phillips 	}
651b9f0f1bbSKim Phillips 	if (vold != vnew)
652b9f0f1bbSKim Phillips 		ipic_write(ipic->regs, IPIC_SECNR, vnew);
653ecf4b196SThomas Gleixner 	return IRQ_SET_MASK_OK_NOCOPY;
654b9f0f1bbSKim Phillips }
655b9f0f1bbSKim Phillips 
65677d4309eSLi Yang /* level interrupts and edge interrupts have different ack operations */
65777d4309eSLi Yang static struct irq_chip ipic_level_irq_chip = {
658b27df672SThomas Gleixner 	.name		= "IPIC",
659687228adSLennert Buytenhek 	.irq_unmask	= ipic_unmask_irq,
660687228adSLennert Buytenhek 	.irq_mask	= ipic_mask_irq,
661687228adSLennert Buytenhek 	.irq_mask_ack	= ipic_mask_irq,
662687228adSLennert Buytenhek 	.irq_set_type	= ipic_set_irq_type,
66377d4309eSLi Yang };
66477d4309eSLi Yang 
66577d4309eSLi Yang static struct irq_chip ipic_edge_irq_chip = {
666b27df672SThomas Gleixner 	.name		= "IPIC",
667687228adSLennert Buytenhek 	.irq_unmask	= ipic_unmask_irq,
668687228adSLennert Buytenhek 	.irq_mask	= ipic_mask_irq,
669687228adSLennert Buytenhek 	.irq_mask_ack	= ipic_mask_irq_and_ack,
670687228adSLennert Buytenhek 	.irq_ack	= ipic_ack_irq,
671687228adSLennert Buytenhek 	.irq_set_type	= ipic_set_irq_type,
6721cd8e506SKumar Gala };
6731cd8e506SKumar Gala 
674ad3aedfbSMarc Zyngier static int ipic_host_match(struct irq_domain *h, struct device_node *node,
675ad3aedfbSMarc Zyngier 			   enum irq_domain_bus_token bus_token)
6761cd8e506SKumar Gala {
677b9f0f1bbSKim Phillips 	/* Exact match, unless ipic node is NULL */
6785d4c9bc7SMarc Zyngier 	struct device_node *of_node = irq_domain_get_of_node(h);
6795d4c9bc7SMarc Zyngier 	return of_node == NULL || of_node == node;
680b9f0f1bbSKim Phillips }
6811cd8e506SKumar Gala 
682bae1d8f1SGrant Likely static int ipic_host_map(struct irq_domain *h, unsigned int virq,
683b9f0f1bbSKim Phillips 			 irq_hw_number_t hw)
684b9f0f1bbSKim Phillips {
685b9f0f1bbSKim Phillips 	struct ipic *ipic = h->host_data;
686b9f0f1bbSKim Phillips 
687ec775d0eSThomas Gleixner 	irq_set_chip_data(virq, ipic);
688ec775d0eSThomas Gleixner 	irq_set_chip_and_handler(virq, &ipic_level_irq_chip, handle_level_irq);
689b9f0f1bbSKim Phillips 
690b9f0f1bbSKim Phillips 	/* Set default irq type */
691ec775d0eSThomas Gleixner 	irq_set_irq_type(virq, IRQ_TYPE_NONE);
692b9f0f1bbSKim Phillips 
693b9f0f1bbSKim Phillips 	return 0;
694b9f0f1bbSKim Phillips }
695b9f0f1bbSKim Phillips 
696202648a6SKrzysztof Kozlowski static const struct irq_domain_ops ipic_host_ops = {
697b9f0f1bbSKim Phillips 	.match	= ipic_host_match,
698b9f0f1bbSKim Phillips 	.map	= ipic_host_map,
699ff8c3ab8SGrant Likely 	.xlate	= irq_domain_xlate_onetwocell,
700b9f0f1bbSKim Phillips };
701b9f0f1bbSKim Phillips 
702126186a0SKumar Gala struct ipic * __init ipic_init(struct device_node *node, unsigned int flags)
703b9f0f1bbSKim Phillips {
704b9f0f1bbSKim Phillips 	struct ipic	*ipic;
705b9f0f1bbSKim Phillips 	struct resource res;
706b9f0f1bbSKim Phillips 	u32 temp = 0, ret;
707b9f0f1bbSKim Phillips 
70884f1c1e0SMichael Ellerman 	ret = of_address_to_resource(node, 0, &res);
70984f1c1e0SMichael Ellerman 	if (ret)
71084f1c1e0SMichael Ellerman 		return NULL;
71184f1c1e0SMichael Ellerman 
712ea96025aSAnton Vorontsov 	ipic = kzalloc(sizeof(*ipic), GFP_KERNEL);
713b9f0f1bbSKim Phillips 	if (ipic == NULL)
714126186a0SKumar Gala 		return NULL;
715b9f0f1bbSKim Phillips 
716a8db8cf0SGrant Likely 	ipic->irqhost = irq_domain_add_linear(node, NR_IPIC_INTS,
717a8db8cf0SGrant Likely 					      &ipic_host_ops, ipic);
7187a626b66SJulia Lawall 	if (ipic->irqhost == NULL) {
7197a626b66SJulia Lawall 		kfree(ipic);
720126186a0SKumar Gala 		return NULL;
7217a626b66SJulia Lawall 	}
722b9f0f1bbSKim Phillips 
72328f65c11SJoe Perches 	ipic->regs = ioremap(res.start, resource_size(&res));
724b9f0f1bbSKim Phillips 
725b9f0f1bbSKim Phillips 	/* init hw */
726b9f0f1bbSKim Phillips 	ipic_write(ipic->regs, IPIC_SICNR, 0x0);
7271cd8e506SKumar Gala 
7281cd8e506SKumar Gala 	/* default priority scheme is grouped. If spread mode is required
7291cd8e506SKumar Gala 	 * configure SICFR accordingly */
7301cd8e506SKumar Gala 	if (flags & IPIC_SPREADMODE_GRP_A)
7311cd8e506SKumar Gala 		temp |= SICFR_IPSA;
732f03ca957SLi Yang 	if (flags & IPIC_SPREADMODE_GRP_B)
733f03ca957SLi Yang 		temp |= SICFR_IPSB;
734f03ca957SLi Yang 	if (flags & IPIC_SPREADMODE_GRP_C)
735f03ca957SLi Yang 		temp |= SICFR_IPSC;
7361cd8e506SKumar Gala 	if (flags & IPIC_SPREADMODE_GRP_D)
7371cd8e506SKumar Gala 		temp |= SICFR_IPSD;
7381cd8e506SKumar Gala 	if (flags & IPIC_SPREADMODE_MIX_A)
7391cd8e506SKumar Gala 		temp |= SICFR_MPSA;
7401cd8e506SKumar Gala 	if (flags & IPIC_SPREADMODE_MIX_B)
7411cd8e506SKumar Gala 		temp |= SICFR_MPSB;
7421cd8e506SKumar Gala 
743f03ca957SLi Yang 	ipic_write(ipic->regs, IPIC_SICFR, temp);
7441cd8e506SKumar Gala 
7451cd8e506SKumar Gala 	/* handle MCP route */
7461cd8e506SKumar Gala 	temp = 0;
7471cd8e506SKumar Gala 	if (flags & IPIC_DISABLE_MCP_OUT)
7481cd8e506SKumar Gala 		temp = SERCR_MCPR;
749b9f0f1bbSKim Phillips 	ipic_write(ipic->regs, IPIC_SERCR, temp);
7501cd8e506SKumar Gala 
7511cd8e506SKumar Gala 	/* handle routing of IRQ0 to MCP */
752b9f0f1bbSKim Phillips 	temp = ipic_read(ipic->regs, IPIC_SEMSR);
7531cd8e506SKumar Gala 
7541cd8e506SKumar Gala 	if (flags & IPIC_IRQ0_MCP)
7551cd8e506SKumar Gala 		temp |= SEMSR_SIRQ0;
7561cd8e506SKumar Gala 	else
7571cd8e506SKumar Gala 		temp &= ~SEMSR_SIRQ0;
7581cd8e506SKumar Gala 
759b9f0f1bbSKim Phillips 	ipic_write(ipic->regs, IPIC_SEMSR, temp);
7601cd8e506SKumar Gala 
761b9f0f1bbSKim Phillips 	primary_ipic = ipic;
762b9f0f1bbSKim Phillips 	irq_set_default_host(primary_ipic->irqhost);
763b9f0f1bbSKim Phillips 
7648640d3bfSSebastian Andrzej Siewior 	ipic_write(ipic->regs, IPIC_SIMSR_H, 0);
7658640d3bfSSebastian Andrzej Siewior 	ipic_write(ipic->regs, IPIC_SIMSR_L, 0);
7668640d3bfSSebastian Andrzej Siewior 
767b9f0f1bbSKim Phillips 	printk ("IPIC (%d IRQ sources) at %p\n", NR_IPIC_INTS,
768b9f0f1bbSKim Phillips 			primary_ipic->regs);
769126186a0SKumar Gala 
770126186a0SKumar Gala 	return ipic;
7711cd8e506SKumar Gala }
7721cd8e506SKumar Gala 
773b9f0f1bbSKim Phillips int ipic_set_priority(unsigned int virq, unsigned int priority)
7741cd8e506SKumar Gala {
775b9f0f1bbSKim Phillips 	struct ipic *ipic = ipic_from_irq(virq);
776476eb491SGrant Likely 	unsigned int src = virq_to_hw(virq);
7771cd8e506SKumar Gala 	u32 temp;
7781cd8e506SKumar Gala 
7791cd8e506SKumar Gala 	if (priority > 7)
7801cd8e506SKumar Gala 		return -EINVAL;
7811cd8e506SKumar Gala 	if (src > 127)
7821cd8e506SKumar Gala 		return -EINVAL;
7831cd8e506SKumar Gala 	if (ipic_info[src].prio == 0)
7841cd8e506SKumar Gala 		return -EINVAL;
7851cd8e506SKumar Gala 
7861cd8e506SKumar Gala 	temp = ipic_read(ipic->regs, ipic_info[src].prio);
7871cd8e506SKumar Gala 
7881cd8e506SKumar Gala 	if (priority < 4) {
7891cd8e506SKumar Gala 		temp &= ~(0x7 << (20 + (3 - priority) * 3));
7901cd8e506SKumar Gala 		temp |= ipic_info[src].prio_mask << (20 + (3 - priority) * 3);
7911cd8e506SKumar Gala 	} else {
7921cd8e506SKumar Gala 		temp &= ~(0x7 << (4 + (7 - priority) * 3));
7931cd8e506SKumar Gala 		temp |= ipic_info[src].prio_mask << (4 + (7 - priority) * 3);
7941cd8e506SKumar Gala 	}
7951cd8e506SKumar Gala 
7961cd8e506SKumar Gala 	ipic_write(ipic->regs, ipic_info[src].prio, temp);
7971cd8e506SKumar Gala 
7981cd8e506SKumar Gala 	return 0;
7991cd8e506SKumar Gala }
8001cd8e506SKumar Gala 
801b9f0f1bbSKim Phillips void ipic_set_highest_priority(unsigned int virq)
8021cd8e506SKumar Gala {
803b9f0f1bbSKim Phillips 	struct ipic *ipic = ipic_from_irq(virq);
804476eb491SGrant Likely 	unsigned int src = virq_to_hw(virq);
8051cd8e506SKumar Gala 	u32 temp;
8061cd8e506SKumar Gala 
8071cd8e506SKumar Gala 	temp = ipic_read(ipic->regs, IPIC_SICFR);
8081cd8e506SKumar Gala 
8091cd8e506SKumar Gala 	/* clear and set HPI */
8101cd8e506SKumar Gala 	temp &= 0x7f000000;
8111cd8e506SKumar Gala 	temp |= (src & 0x7f) << 24;
8121cd8e506SKumar Gala 
8131cd8e506SKumar Gala 	ipic_write(ipic->regs, IPIC_SICFR, temp);
8141cd8e506SKumar Gala }
8151cd8e506SKumar Gala 
8161cd8e506SKumar Gala void ipic_set_default_priority(void)
8171cd8e506SKumar Gala {
818f03ca957SLi Yang 	ipic_write(primary_ipic->regs, IPIC_SIPRR_A, IPIC_PRIORITY_DEFAULT);
819f03ca957SLi Yang 	ipic_write(primary_ipic->regs, IPIC_SIPRR_B, IPIC_PRIORITY_DEFAULT);
820f03ca957SLi Yang 	ipic_write(primary_ipic->regs, IPIC_SIPRR_C, IPIC_PRIORITY_DEFAULT);
821f03ca957SLi Yang 	ipic_write(primary_ipic->regs, IPIC_SIPRR_D, IPIC_PRIORITY_DEFAULT);
822f03ca957SLi Yang 	ipic_write(primary_ipic->regs, IPIC_SMPRR_A, IPIC_PRIORITY_DEFAULT);
823f03ca957SLi Yang 	ipic_write(primary_ipic->regs, IPIC_SMPRR_B, IPIC_PRIORITY_DEFAULT);
8241cd8e506SKumar Gala }
8251cd8e506SKumar Gala 
8261cd8e506SKumar Gala void ipic_enable_mcp(enum ipic_mcp_irq mcp_irq)
8271cd8e506SKumar Gala {
8281cd8e506SKumar Gala 	struct ipic *ipic = primary_ipic;
8291cd8e506SKumar Gala 	u32 temp;
8301cd8e506SKumar Gala 
8311cd8e506SKumar Gala 	temp = ipic_read(ipic->regs, IPIC_SERMR);
8321cd8e506SKumar Gala 	temp |= (1 << (31 - mcp_irq));
8331cd8e506SKumar Gala 	ipic_write(ipic->regs, IPIC_SERMR, temp);
8341cd8e506SKumar Gala }
8351cd8e506SKumar Gala 
8361cd8e506SKumar Gala void ipic_disable_mcp(enum ipic_mcp_irq mcp_irq)
8371cd8e506SKumar Gala {
8381cd8e506SKumar Gala 	struct ipic *ipic = primary_ipic;
8391cd8e506SKumar Gala 	u32 temp;
8401cd8e506SKumar Gala 
8411cd8e506SKumar Gala 	temp = ipic_read(ipic->regs, IPIC_SERMR);
8421cd8e506SKumar Gala 	temp &= (1 << (31 - mcp_irq));
8431cd8e506SKumar Gala 	ipic_write(ipic->regs, IPIC_SERMR, temp);
8441cd8e506SKumar Gala }
8451cd8e506SKumar Gala 
8461cd8e506SKumar Gala u32 ipic_get_mcp_status(void)
8471cd8e506SKumar Gala {
8481cd8e506SKumar Gala 	return ipic_read(primary_ipic->regs, IPIC_SERMR);
8491cd8e506SKumar Gala }
8501cd8e506SKumar Gala 
8511cd8e506SKumar Gala void ipic_clear_mcp_status(u32 mask)
8521cd8e506SKumar Gala {
8531cd8e506SKumar Gala 	ipic_write(primary_ipic->regs, IPIC_SERMR, mask);
8541cd8e506SKumar Gala }
8551cd8e506SKumar Gala 
856*ef24ba70SMichael Ellerman /* Return an interrupt vector or 0 if no interrupt is pending. */
85735a84c2fSOlaf Hering unsigned int ipic_get_irq(void)
8581cd8e506SKumar Gala {
8591cd8e506SKumar Gala 	int irq;
8601cd8e506SKumar Gala 
861b9f0f1bbSKim Phillips 	BUG_ON(primary_ipic == NULL);
862b9f0f1bbSKim Phillips 
863b9f0f1bbSKim Phillips #define IPIC_SIVCR_VECTOR_MASK	0x7f
864b9f0f1bbSKim Phillips 	irq = ipic_read(primary_ipic->regs, IPIC_SIVCR) & IPIC_SIVCR_VECTOR_MASK;
8651cd8e506SKumar Gala 
8661cd8e506SKumar Gala 	if (irq == 0)    /* 0 --> no irq is pending */
867*ef24ba70SMichael Ellerman 		return 0;
8681cd8e506SKumar Gala 
869b9f0f1bbSKim Phillips 	return irq_linear_revmap(primary_ipic->irqhost, irq);
8701cd8e506SKumar Gala }
8711cd8e506SKumar Gala 
872e2a02ba6SMichael Neuling #ifdef CONFIG_SUSPEND
873d49747bdSScott Wood static struct {
874d49747bdSScott Wood 	u32 sicfr;
875d49747bdSScott Wood 	u32 siprr[2];
876d49747bdSScott Wood 	u32 simsr[2];
877d49747bdSScott Wood 	u32 sicnr;
878d49747bdSScott Wood 	u32 smprr[2];
879d49747bdSScott Wood 	u32 semsr;
880d49747bdSScott Wood 	u32 secnr;
881d49747bdSScott Wood 	u32 sermr;
882d49747bdSScott Wood 	u32 sercr;
883d49747bdSScott Wood } ipic_saved_state;
884d49747bdSScott Wood 
885f5a592f7SRafael J. Wysocki static int ipic_suspend(void)
886d49747bdSScott Wood {
887d49747bdSScott Wood 	struct ipic *ipic = primary_ipic;
888d49747bdSScott Wood 
889d49747bdSScott Wood 	ipic_saved_state.sicfr = ipic_read(ipic->regs, IPIC_SICFR);
890d49747bdSScott Wood 	ipic_saved_state.siprr[0] = ipic_read(ipic->regs, IPIC_SIPRR_A);
891d49747bdSScott Wood 	ipic_saved_state.siprr[1] = ipic_read(ipic->regs, IPIC_SIPRR_D);
892d49747bdSScott Wood 	ipic_saved_state.simsr[0] = ipic_read(ipic->regs, IPIC_SIMSR_H);
893d49747bdSScott Wood 	ipic_saved_state.simsr[1] = ipic_read(ipic->regs, IPIC_SIMSR_L);
894d49747bdSScott Wood 	ipic_saved_state.sicnr = ipic_read(ipic->regs, IPIC_SICNR);
895d49747bdSScott Wood 	ipic_saved_state.smprr[0] = ipic_read(ipic->regs, IPIC_SMPRR_A);
896d49747bdSScott Wood 	ipic_saved_state.smprr[1] = ipic_read(ipic->regs, IPIC_SMPRR_B);
897d49747bdSScott Wood 	ipic_saved_state.semsr = ipic_read(ipic->regs, IPIC_SEMSR);
898d49747bdSScott Wood 	ipic_saved_state.secnr = ipic_read(ipic->regs, IPIC_SECNR);
899d49747bdSScott Wood 	ipic_saved_state.sermr = ipic_read(ipic->regs, IPIC_SERMR);
900d49747bdSScott Wood 	ipic_saved_state.sercr = ipic_read(ipic->regs, IPIC_SERCR);
901d49747bdSScott Wood 
902d49747bdSScott Wood 	if (fsl_deep_sleep()) {
903d49747bdSScott Wood 		/* In deep sleep, make sure there can be no
904d49747bdSScott Wood 		 * pending interrupts, as this can cause
905d49747bdSScott Wood 		 * problems on 831x.
906d49747bdSScott Wood 		 */
907d49747bdSScott Wood 		ipic_write(ipic->regs, IPIC_SIMSR_H, 0);
908d49747bdSScott Wood 		ipic_write(ipic->regs, IPIC_SIMSR_L, 0);
909d49747bdSScott Wood 		ipic_write(ipic->regs, IPIC_SEMSR, 0);
910d49747bdSScott Wood 		ipic_write(ipic->regs, IPIC_SERMR, 0);
911d49747bdSScott Wood 	}
912d49747bdSScott Wood 
913d49747bdSScott Wood 	return 0;
914d49747bdSScott Wood }
915d49747bdSScott Wood 
916f5a592f7SRafael J. Wysocki static void ipic_resume(void)
917d49747bdSScott Wood {
918d49747bdSScott Wood 	struct ipic *ipic = primary_ipic;
919d49747bdSScott Wood 
920d49747bdSScott Wood 	ipic_write(ipic->regs, IPIC_SICFR, ipic_saved_state.sicfr);
921d49747bdSScott Wood 	ipic_write(ipic->regs, IPIC_SIPRR_A, ipic_saved_state.siprr[0]);
922d49747bdSScott Wood 	ipic_write(ipic->regs, IPIC_SIPRR_D, ipic_saved_state.siprr[1]);
923d49747bdSScott Wood 	ipic_write(ipic->regs, IPIC_SIMSR_H, ipic_saved_state.simsr[0]);
924d49747bdSScott Wood 	ipic_write(ipic->regs, IPIC_SIMSR_L, ipic_saved_state.simsr[1]);
925d49747bdSScott Wood 	ipic_write(ipic->regs, IPIC_SICNR, ipic_saved_state.sicnr);
926d49747bdSScott Wood 	ipic_write(ipic->regs, IPIC_SMPRR_A, ipic_saved_state.smprr[0]);
927d49747bdSScott Wood 	ipic_write(ipic->regs, IPIC_SMPRR_B, ipic_saved_state.smprr[1]);
928d49747bdSScott Wood 	ipic_write(ipic->regs, IPIC_SEMSR, ipic_saved_state.semsr);
929d49747bdSScott Wood 	ipic_write(ipic->regs, IPIC_SECNR, ipic_saved_state.secnr);
930d49747bdSScott Wood 	ipic_write(ipic->regs, IPIC_SERMR, ipic_saved_state.sermr);
931d49747bdSScott Wood 	ipic_write(ipic->regs, IPIC_SERCR, ipic_saved_state.sercr);
932d49747bdSScott Wood }
933d49747bdSScott Wood #else
934d49747bdSScott Wood #define ipic_suspend NULL
935d49747bdSScott Wood #define ipic_resume NULL
936d49747bdSScott Wood #endif
937d49747bdSScott Wood 
938f5a592f7SRafael J. Wysocki static struct syscore_ops ipic_syscore_ops = {
939d49747bdSScott Wood 	.suspend = ipic_suspend,
940d49747bdSScott Wood 	.resume = ipic_resume,
9411cd8e506SKumar Gala };
9421cd8e506SKumar Gala 
943f5a592f7SRafael J. Wysocki static int __init init_ipic_syscore(void)
9441cd8e506SKumar Gala {
9451428a9faSOlaf Hering 	if (!primary_ipic || !primary_ipic->regs)
9461cd8e506SKumar Gala 		return -ENODEV;
9471cd8e506SKumar Gala 
948f5a592f7SRafael J. Wysocki 	printk(KERN_DEBUG "Registering ipic system core operations\n");
949f5a592f7SRafael J. Wysocki 	register_syscore_ops(&ipic_syscore_ops);
950f5a592f7SRafael J. Wysocki 
9511cd8e506SKumar Gala 	return 0;
9521cd8e506SKumar Gala }
9531cd8e506SKumar Gala 
954f5a592f7SRafael J. Wysocki subsys_initcall(init_ipic_syscore);
955