2 * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd.
3 * http://www.samsung.com
5 * Combiner irqchip for EXYNOS
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 #include <linux/err.h>
12 #include <linux/export.h>
13 #include <linux/init.h>
15 #include <linux/slab.h>
16 #include <linux/syscore_ops.h>
17 #include <linux/irqdomain.h>
18 #include <linux/irqchip.h>
19 #include <linux/irqchip/chained_irq.h>
20 #include <linux/interrupt.h>
21 #include <linux/of_address.h>
22 #include <linux/of_irq.h>
24 #define COMBINER_ENABLE_SET 0x0
25 #define COMBINER_ENABLE_CLEAR 0x4
26 #define COMBINER_INT_STATUS 0xC
28 #define IRQ_IN_COMBINER 8
30 static DEFINE_SPINLOCK(irq_controller_lock
);
32 struct combiner_chip_data
{
33 unsigned int hwirq_offset
;
34 unsigned int irq_mask
;
36 unsigned int parent_irq
;
42 static struct combiner_chip_data
*combiner_data
;
43 static struct irq_domain
*combiner_irq_domain
;
44 static unsigned int max_nr
= 20;
46 static inline void __iomem
*combiner_base(struct irq_data
*data
)
48 struct combiner_chip_data
*combiner_data
=
49 irq_data_get_irq_chip_data(data
);
51 return combiner_data
->base
;
54 static void combiner_mask_irq(struct irq_data
*data
)
56 u32 mask
= 1 << (data
->hwirq
% 32);
58 writel_relaxed(mask
, combiner_base(data
) + COMBINER_ENABLE_CLEAR
);
61 static void combiner_unmask_irq(struct irq_data
*data
)
63 u32 mask
= 1 << (data
->hwirq
% 32);
65 writel_relaxed(mask
, combiner_base(data
) + COMBINER_ENABLE_SET
);
68 static void combiner_handle_cascade_irq(struct irq_desc
*desc
)
70 struct combiner_chip_data
*chip_data
= irq_desc_get_handler_data(desc
);
71 struct irq_chip
*chip
= irq_desc_get_chip(desc
);
72 unsigned int cascade_irq
, combiner_irq
;
75 chained_irq_enter(chip
, desc
);
77 spin_lock(&irq_controller_lock
);
78 status
= readl_relaxed(chip_data
->base
+ COMBINER_INT_STATUS
);
79 spin_unlock(&irq_controller_lock
);
80 status
&= chip_data
->irq_mask
;
85 combiner_irq
= chip_data
->hwirq_offset
+ __ffs(status
);
86 cascade_irq
= irq_find_mapping(combiner_irq_domain
, combiner_irq
);
88 if (unlikely(!cascade_irq
))
91 generic_handle_irq(cascade_irq
);
94 chained_irq_exit(chip
, desc
);
98 static int combiner_set_affinity(struct irq_data
*d
,
99 const struct cpumask
*mask_val
, bool force
)
101 struct combiner_chip_data
*chip_data
= irq_data_get_irq_chip_data(d
);
102 struct irq_chip
*chip
= irq_get_chip(chip_data
->parent_irq
);
103 struct irq_data
*data
= irq_get_irq_data(chip_data
->parent_irq
);
105 if (chip
&& chip
->irq_set_affinity
)
106 return chip
->irq_set_affinity(data
, mask_val
, force
);
112 static struct irq_chip combiner_chip
= {
114 .irq_mask
= combiner_mask_irq
,
115 .irq_unmask
= combiner_unmask_irq
,
117 .irq_set_affinity
= combiner_set_affinity
,
121 static void __init
combiner_cascade_irq(struct combiner_chip_data
*combiner_data
,
124 irq_set_chained_handler_and_data(irq
, combiner_handle_cascade_irq
,
128 static void __init
combiner_init_one(struct combiner_chip_data
*combiner_data
,
129 unsigned int combiner_nr
,
130 void __iomem
*base
, unsigned int irq
)
132 combiner_data
->base
= base
;
133 combiner_data
->hwirq_offset
= (combiner_nr
& ~3) * IRQ_IN_COMBINER
;
134 combiner_data
->irq_mask
= 0xff << ((combiner_nr
% 4) << 3);
135 combiner_data
->parent_irq
= irq
;
137 /* Disable all interrupts */
138 writel_relaxed(combiner_data
->irq_mask
, base
+ COMBINER_ENABLE_CLEAR
);
141 static int combiner_irq_domain_xlate(struct irq_domain
*d
,
142 struct device_node
*controller
,
143 const u32
*intspec
, unsigned int intsize
,
144 unsigned long *out_hwirq
,
145 unsigned int *out_type
)
147 if (irq_domain_get_of_node(d
) != controller
)
153 *out_hwirq
= intspec
[0] * IRQ_IN_COMBINER
+ intspec
[1];
159 static int combiner_irq_domain_map(struct irq_domain
*d
, unsigned int irq
,
162 struct combiner_chip_data
*combiner_data
= d
->host_data
;
164 irq_set_chip_and_handler(irq
, &combiner_chip
, handle_level_irq
);
165 irq_set_chip_data(irq
, &combiner_data
[hw
>> 3]);
171 static const struct irq_domain_ops combiner_irq_domain_ops
= {
172 .xlate
= combiner_irq_domain_xlate
,
173 .map
= combiner_irq_domain_map
,
176 static void __init
combiner_init(void __iomem
*combiner_base
,
177 struct device_node
*np
)
182 nr_irq
= max_nr
* IRQ_IN_COMBINER
;
184 combiner_data
= kcalloc(max_nr
, sizeof (*combiner_data
), GFP_KERNEL
);
185 if (!combiner_data
) {
186 pr_warn("%s: could not allocate combiner data\n", __func__
);
190 combiner_irq_domain
= irq_domain_add_linear(np
, nr_irq
,
191 &combiner_irq_domain_ops
, combiner_data
);
192 if (WARN_ON(!combiner_irq_domain
)) {
193 pr_warn("%s: irq domain init failed\n", __func__
);
197 for (i
= 0; i
< max_nr
; i
++) {
198 irq
= irq_of_parse_and_map(np
, i
);
200 combiner_init_one(&combiner_data
[i
], i
,
201 combiner_base
+ (i
>> 2) * 0x10, irq
);
202 combiner_cascade_irq(&combiner_data
[i
], irq
);
209 * combiner_suspend - save interrupt combiner state before suspend
211 * Save the interrupt enable set register for all combiner groups since
212 * the state is lost when the system enters into a sleep state.
215 static int combiner_suspend(void)
219 for (i
= 0; i
< max_nr
; i
++)
220 combiner_data
[i
].pm_save
=
221 readl_relaxed(combiner_data
[i
].base
+ COMBINER_ENABLE_SET
);
227 * combiner_resume - restore interrupt combiner state after resume
229 * Restore the interrupt enable set register for all combiner groups since
230 * the state is lost when the system enters into a sleep state on suspend.
233 static void combiner_resume(void)
237 for (i
= 0; i
< max_nr
; i
++) {
238 writel_relaxed(combiner_data
[i
].irq_mask
,
239 combiner_data
[i
].base
+ COMBINER_ENABLE_CLEAR
);
240 writel_relaxed(combiner_data
[i
].pm_save
,
241 combiner_data
[i
].base
+ COMBINER_ENABLE_SET
);
246 #define combiner_suspend NULL
247 #define combiner_resume NULL
250 static struct syscore_ops combiner_syscore_ops
= {
251 .suspend
= combiner_suspend
,
252 .resume
= combiner_resume
,
255 static int __init
combiner_of_init(struct device_node
*np
,
256 struct device_node
*parent
)
258 void __iomem
*combiner_base
;
260 combiner_base
= of_iomap(np
, 0);
261 if (!combiner_base
) {
262 pr_err("%s: failed to map combiner registers\n", __func__
);
266 if (of_property_read_u32(np
, "samsung,combiner-nr", &max_nr
)) {
267 pr_info("%s: number of combiners not specified, "
268 "setting default as %d.\n",
272 combiner_init(combiner_base
, np
);
274 register_syscore_ops(&combiner_syscore_ops
);
278 IRQCHIP_DECLARE(exynos4210_combiner
, "samsung,exynos4210-combiner",