2 * Samsung exynos4210 Interrupt Combiner
4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
7 * Evgeny Voevodin <e.voevodin@samsung.com>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 * See the GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, see <http://www.gnu.org/licenses/>.
24 * Exynos4210 Combiner represents an OR gate for SOC's IRQ lines. It combines
25 * IRQ sources into groups and provides signal output to GIC from each group. It
26 * is driven by common mask and enable/disable logic. Take a note that not all
27 * IRQs are passed to GIC through Combiner.
30 #include "qemu/osdep.h"
31 #include "hw/sysbus.h"
33 #include "hw/arm/exynos4210.h"
35 //#define DEBUG_COMBINER
38 #define DPRINTF(fmt, ...) \
39 do { fprintf(stdout, "COMBINER: [%s:%d] " fmt, __func__ , __LINE__, \
40 ## __VA_ARGS__); } while (0)
42 #define DPRINTF(fmt, ...) do {} while (0)
45 #define IIC_NGRP 64 /* Internal Interrupt Combiner
47 #define IIC_NIRQ (IIC_NGRP * 8)/* Internal Interrupt Combiner
49 #define IIC_REGION_SIZE 0x108 /* Size of memory mapped region */
50 #define IIC_REGSET_SIZE 0x41
53 * State for each output signal of internal combiner
55 typedef struct CombinerGroupState
{
56 uint8_t src_mask
; /* 1 - source enabled, 0 - disabled */
57 uint8_t src_pending
; /* Pending source interrupts before masking */
60 #define TYPE_EXYNOS4210_COMBINER "exynos4210.combiner"
61 #define EXYNOS4210_COMBINER(obj) \
62 OBJECT_CHECK(Exynos4210CombinerState, (obj), TYPE_EXYNOS4210_COMBINER)
64 typedef struct Exynos4210CombinerState
{
65 SysBusDevice parent_obj
;
69 struct CombinerGroupState group
[IIC_NGRP
];
70 uint32_t reg_set
[IIC_REGSET_SIZE
];
72 uint32_t external
; /* 1 means that this combiner is external */
74 qemu_irq output_irq
[IIC_NGRP
];
75 } Exynos4210CombinerState
;
77 static const VMStateDescription vmstate_exynos4210_combiner_group_state
= {
78 .name
= "exynos4210.combiner.groupstate",
80 .minimum_version_id
= 1,
81 .fields
= (VMStateField
[]) {
82 VMSTATE_UINT8(src_mask
, CombinerGroupState
),
83 VMSTATE_UINT8(src_pending
, CombinerGroupState
),
88 static const VMStateDescription vmstate_exynos4210_combiner
= {
89 .name
= "exynos4210.combiner",
91 .minimum_version_id
= 1,
92 .fields
= (VMStateField
[]) {
93 VMSTATE_STRUCT_ARRAY(group
, Exynos4210CombinerState
, IIC_NGRP
, 0,
94 vmstate_exynos4210_combiner_group_state
, CombinerGroupState
),
95 VMSTATE_UINT32_ARRAY(reg_set
, Exynos4210CombinerState
,
97 VMSTATE_UINT32_ARRAY(icipsr
, Exynos4210CombinerState
, 2),
98 VMSTATE_UINT32(external
, Exynos4210CombinerState
),
104 * Get Combiner input GPIO into irqs structure
106 void exynos4210_combiner_get_gpioin(Exynos4210Irq
*irqs
, DeviceState
*dev
,
114 max
= ext
? EXYNOS4210_MAX_EXT_COMBINER_IN_IRQ
:
115 EXYNOS4210_MAX_INT_COMBINER_IN_IRQ
;
116 irq
= ext
? irqs
->ext_combiner_irq
: irqs
->int_combiner_irq
;
119 * Some IRQs of Int/External Combiner are going to two Combiners groups,
122 for (n
= 0; n
< max
; n
++) {
124 bit
= EXYNOS4210_COMBINER_GET_BIT_NUM(n
);
127 /* MDNIE_LCD1 INTG1 */
128 case EXYNOS4210_COMBINER_GET_IRQ_NUM(1, 0) ...
129 EXYNOS4210_COMBINER_GET_IRQ_NUM(1, 3):
130 irq
[n
] = qemu_irq_split(qdev_get_gpio_in(dev
, n
),
131 irq
[EXYNOS4210_COMBINER_GET_IRQ_NUM(0, bit
+ 4)]);
135 case EXYNOS4210_COMBINER_GET_IRQ_NUM(3, 4):
136 irq
[n
] = qemu_irq_split(qdev_get_gpio_in(dev
, n
),
137 irq
[EXYNOS4210_COMBINER_GET_IRQ_NUM(2, bit
)]);
141 case EXYNOS4210_COMBINER_GET_IRQ_NUM(12, 0) ...
142 EXYNOS4210_COMBINER_GET_IRQ_NUM(12, 3):
143 irq
[n
] = qemu_irq_split(qdev_get_gpio_in(dev
, n
),
144 irq
[EXYNOS4210_COMBINER_GET_IRQ_NUM(11, bit
+ 4)]);
147 /* Multi-Core Timer INTG12 */
148 case EXYNOS4210_COMBINER_GET_IRQ_NUM(12, 4) ...
149 EXYNOS4210_COMBINER_GET_IRQ_NUM(12, 8):
150 irq
[n
] = qemu_irq_split(qdev_get_gpio_in(dev
, n
),
151 irq
[EXYNOS4210_COMBINER_GET_IRQ_NUM(1, bit
+ 4)]);
154 /* Multi-Core Timer INTG35 */
155 case EXYNOS4210_COMBINER_GET_IRQ_NUM(35, 4) ...
156 EXYNOS4210_COMBINER_GET_IRQ_NUM(35, 8):
157 irq
[n
] = qemu_irq_split(qdev_get_gpio_in(dev
, n
),
158 irq
[EXYNOS4210_COMBINER_GET_IRQ_NUM(1, bit
+ 4)]);
161 /* Multi-Core Timer INTG51 */
162 case EXYNOS4210_COMBINER_GET_IRQ_NUM(51, 4) ...
163 EXYNOS4210_COMBINER_GET_IRQ_NUM(51, 8):
164 irq
[n
] = qemu_irq_split(qdev_get_gpio_in(dev
, n
),
165 irq
[EXYNOS4210_COMBINER_GET_IRQ_NUM(1, bit
+ 4)]);
168 /* Multi-Core Timer INTG53 */
169 case EXYNOS4210_COMBINER_GET_IRQ_NUM(53, 4) ...
170 EXYNOS4210_COMBINER_GET_IRQ_NUM(53, 8):
171 irq
[n
] = qemu_irq_split(qdev_get_gpio_in(dev
, n
),
172 irq
[EXYNOS4210_COMBINER_GET_IRQ_NUM(1, bit
+ 4)]);
176 irq
[n
] = qdev_get_gpio_in(dev
, n
);
181 exynos4210_combiner_read(void *opaque
, hwaddr offset
, unsigned size
)
183 struct Exynos4210CombinerState
*s
=
184 (struct Exynos4210CombinerState
*)opaque
;
185 uint32_t req_quad_base_n
; /* Base of registers quad. Multiply it by 4 and
186 get a start of corresponding group quad */
187 uint32_t grp_quad_base_n
; /* Base of group quad */
188 uint32_t reg_n
; /* Register number inside the quad */
191 req_quad_base_n
= offset
>> 4;
192 grp_quad_base_n
= req_quad_base_n
<< 2;
193 reg_n
= (offset
- (req_quad_base_n
<< 4)) >> 2;
195 if (req_quad_base_n
>= IIC_NGRP
) {
196 /* Read of ICIPSR register */
197 return s
->icipsr
[reg_n
];
205 val
|= s
->group
[grp_quad_base_n
].src_pending
;
206 val
|= s
->group
[grp_quad_base_n
+ 1].src_pending
<< 8;
207 val
|= s
->group
[grp_quad_base_n
+ 2].src_pending
<< 16;
208 val
|= s
->group
[grp_quad_base_n
+ 3].src_pending
<< 24;
212 val
|= s
->group
[grp_quad_base_n
].src_mask
&
213 s
->group
[grp_quad_base_n
].src_pending
;
214 val
|= (s
->group
[grp_quad_base_n
+ 1].src_mask
&
215 s
->group
[grp_quad_base_n
+ 1].src_pending
) << 8;
216 val
|= (s
->group
[grp_quad_base_n
+ 2].src_mask
&
217 s
->group
[grp_quad_base_n
+ 2].src_pending
) << 16;
218 val
|= (s
->group
[grp_quad_base_n
+ 3].src_mask
&
219 s
->group
[grp_quad_base_n
+ 3].src_pending
) << 24;
222 if (offset
>> 2 >= IIC_REGSET_SIZE
) {
223 hw_error("exynos4210.combiner: overflow of reg_set by 0x"
224 TARGET_FMT_plx
"offset\n", offset
);
226 val
= s
->reg_set
[offset
>> 2];
232 static void exynos4210_combiner_update(void *opaque
, uint8_t group_n
)
234 struct Exynos4210CombinerState
*s
=
235 (struct Exynos4210CombinerState
*)opaque
;
237 /* Send interrupt if needed */
238 if (s
->group
[group_n
].src_mask
& s
->group
[group_n
].src_pending
) {
239 #ifdef DEBUG_COMBINER
242 DPRINTF("%s raise IRQ[%d]\n", s
->external
? "EXT" : "INT", group_n
);
246 /* Set Combiner interrupt pending status after masking */
248 s
->icipsr
[1] |= 1 << (group_n
- 32);
250 s
->icipsr
[0] |= 1 << group_n
;
253 qemu_irq_raise(s
->output_irq
[group_n
]);
255 #ifdef DEBUG_COMBINER
258 DPRINTF("%s lower IRQ[%d]\n", s
->external
? "EXT" : "INT", group_n
);
262 /* Set Combiner interrupt pending status after masking */
264 s
->icipsr
[1] &= ~(1 << (group_n
- 32));
266 s
->icipsr
[0] &= ~(1 << group_n
);
269 qemu_irq_lower(s
->output_irq
[group_n
]);
273 static void exynos4210_combiner_write(void *opaque
, hwaddr offset
,
274 uint64_t val
, unsigned size
)
276 struct Exynos4210CombinerState
*s
=
277 (struct Exynos4210CombinerState
*)opaque
;
278 uint32_t req_quad_base_n
; /* Base of registers quad. Multiply it by 4 and
279 get a start of corresponding group quad */
280 uint32_t grp_quad_base_n
; /* Base of group quad */
281 uint32_t reg_n
; /* Register number inside the quad */
283 req_quad_base_n
= offset
>> 4;
284 grp_quad_base_n
= req_quad_base_n
<< 2;
285 reg_n
= (offset
- (req_quad_base_n
<< 4)) >> 2;
287 if (req_quad_base_n
>= IIC_NGRP
) {
288 hw_error("exynos4210.combiner: unallowed write access at offset 0x"
289 TARGET_FMT_plx
"\n", offset
);
294 hw_error("exynos4210.combiner: unallowed write access at offset 0x"
295 TARGET_FMT_plx
"\n", offset
);
299 if (offset
>> 2 >= IIC_REGSET_SIZE
) {
300 hw_error("exynos4210.combiner: overflow of reg_set by 0x"
301 TARGET_FMT_plx
"offset\n", offset
);
303 s
->reg_set
[offset
>> 2] = val
;
308 /* FIXME: what if irq is pending, allowed by mask, and we allow it
309 * again. Interrupt will rise again! */
311 DPRINTF("%s enable IRQ for groups %d, %d, %d, %d\n",
312 s
->external
? "EXT" : "INT",
316 grp_quad_base_n
+ 3);
318 /* Enable interrupt sources */
319 s
->group
[grp_quad_base_n
].src_mask
|= val
& 0xFF;
320 s
->group
[grp_quad_base_n
+ 1].src_mask
|= (val
& 0xFF00) >> 8;
321 s
->group
[grp_quad_base_n
+ 2].src_mask
|= (val
& 0xFF0000) >> 16;
322 s
->group
[grp_quad_base_n
+ 3].src_mask
|= (val
& 0xFF000000) >> 24;
324 exynos4210_combiner_update(s
, grp_quad_base_n
);
325 exynos4210_combiner_update(s
, grp_quad_base_n
+ 1);
326 exynos4210_combiner_update(s
, grp_quad_base_n
+ 2);
327 exynos4210_combiner_update(s
, grp_quad_base_n
+ 3);
331 DPRINTF("%s disable IRQ for groups %d, %d, %d, %d\n",
332 s
->external
? "EXT" : "INT",
336 grp_quad_base_n
+ 3);
338 /* Disable interrupt sources */
339 s
->group
[grp_quad_base_n
].src_mask
&= ~(val
& 0xFF);
340 s
->group
[grp_quad_base_n
+ 1].src_mask
&= ~((val
& 0xFF00) >> 8);
341 s
->group
[grp_quad_base_n
+ 2].src_mask
&= ~((val
& 0xFF0000) >> 16);
342 s
->group
[grp_quad_base_n
+ 3].src_mask
&= ~((val
& 0xFF000000) >> 24);
344 exynos4210_combiner_update(s
, grp_quad_base_n
);
345 exynos4210_combiner_update(s
, grp_quad_base_n
+ 1);
346 exynos4210_combiner_update(s
, grp_quad_base_n
+ 2);
347 exynos4210_combiner_update(s
, grp_quad_base_n
+ 3);
350 hw_error("exynos4210.combiner: unallowed write access at offset 0x"
351 TARGET_FMT_plx
"\n", offset
);
356 /* Get combiner group and bit from irq number */
357 static uint8_t get_combiner_group_and_bit(int irq
, uint8_t *bit
)
359 *bit
= irq
- ((irq
>> 3) << 3);
363 /* Process a change in an external IRQ input. */
364 static void exynos4210_combiner_handler(void *opaque
, int irq
, int level
)
366 struct Exynos4210CombinerState
*s
=
367 (struct Exynos4210CombinerState
*)opaque
;
368 uint8_t bit_n
, group_n
;
370 group_n
= get_combiner_group_and_bit(irq
, &bit_n
);
372 if (s
->external
&& group_n
>= EXYNOS4210_MAX_EXT_COMBINER_OUT_IRQ
) {
373 DPRINTF("%s unallowed IRQ group 0x%x\n", s
->external
? "EXT" : "INT"
379 s
->group
[group_n
].src_pending
|= 1 << bit_n
;
381 s
->group
[group_n
].src_pending
&= ~(1 << bit_n
);
384 exynos4210_combiner_update(s
, group_n
);
387 static void exynos4210_combiner_reset(DeviceState
*d
)
389 struct Exynos4210CombinerState
*s
= (struct Exynos4210CombinerState
*)d
;
391 memset(&s
->group
, 0, sizeof(s
->group
));
392 memset(&s
->reg_set
, 0, sizeof(s
->reg_set
));
394 s
->reg_set
[0xC0 >> 2] = 0x01010101;
395 s
->reg_set
[0xC4 >> 2] = 0x01010101;
396 s
->reg_set
[0xD0 >> 2] = 0x01010101;
397 s
->reg_set
[0xD4 >> 2] = 0x01010101;
400 static const MemoryRegionOps exynos4210_combiner_ops
= {
401 .read
= exynos4210_combiner_read
,
402 .write
= exynos4210_combiner_write
,
403 .endianness
= DEVICE_NATIVE_ENDIAN
,
407 * Internal Combiner initialization.
409 static int exynos4210_combiner_init(SysBusDevice
*sbd
)
411 DeviceState
*dev
= DEVICE(sbd
);
412 Exynos4210CombinerState
*s
= EXYNOS4210_COMBINER(dev
);
415 /* Allocate general purpose input signals and connect a handler to each of
417 qdev_init_gpio_in(dev
, exynos4210_combiner_handler
, IIC_NIRQ
);
419 /* Connect SysBusDev irqs to device specific irqs */
420 for (i
= 0; i
< IIC_NGRP
; i
++) {
421 sysbus_init_irq(sbd
, &s
->output_irq
[i
]);
424 memory_region_init_io(&s
->iomem
, OBJECT(s
), &exynos4210_combiner_ops
, s
,
425 "exynos4210-combiner", IIC_REGION_SIZE
);
426 sysbus_init_mmio(sbd
, &s
->iomem
);
431 static Property exynos4210_combiner_properties
[] = {
432 DEFINE_PROP_UINT32("external", Exynos4210CombinerState
, external
, 0),
433 DEFINE_PROP_END_OF_LIST(),
436 static void exynos4210_combiner_class_init(ObjectClass
*klass
, void *data
)
438 DeviceClass
*dc
= DEVICE_CLASS(klass
);
439 SysBusDeviceClass
*k
= SYS_BUS_DEVICE_CLASS(klass
);
441 k
->init
= exynos4210_combiner_init
;
442 dc
->reset
= exynos4210_combiner_reset
;
443 dc
->props
= exynos4210_combiner_properties
;
444 dc
->vmsd
= &vmstate_exynos4210_combiner
;
447 static const TypeInfo exynos4210_combiner_info
= {
448 .name
= TYPE_EXYNOS4210_COMBINER
,
449 .parent
= TYPE_SYS_BUS_DEVICE
,
450 .instance_size
= sizeof(Exynos4210CombinerState
),
451 .class_init
= exynos4210_combiner_class_init
,
454 static void exynos4210_combiner_register_types(void)
456 type_register_static(&exynos4210_combiner_info
);
459 type_init(exynos4210_combiner_register_types
)