2 * PXA270-based Intel Mainstone platforms.
5 * Copyright (c) 2007 by Armin Kuster <akuster@kama-aina.net> or
8 * This code is licensed under the GNU GPL v2.
10 * Contributions after 2012-01-13 are licensed under the terms of the
11 * GNU GPL, version 2 or (at your option) any later version.
13 #include "qemu/osdep.h"
15 #include "hw/sysbus.h"
17 /* Mainstone FPGA for extern irqs */
18 #define FPGA_GPIO_PIN 0
19 #define MST_NUM_IRQS 16
20 #define MST_LEDDAT1 0x10
21 #define MST_LEDDAT2 0x14
22 #define MST_LEDCTRL 0x40
23 #define MST_GPSWR 0x60
24 #define MST_MSCWR1 0x80
25 #define MST_MSCWR2 0x84
26 #define MST_MSCWR3 0x88
27 #define MST_MSCRD 0x90
28 #define MST_INTMSKENA 0xc0
29 #define MST_INTSETCLR 0xd0
30 #define MST_PCMCIA0 0xe0
31 #define MST_PCMCIA1 0xe4
33 #define MST_PCMCIAx_READY (1 << 10)
34 #define MST_PCMCIAx_nCD (1 << 5)
36 #define MST_PCMCIA_CD0_IRQ 9
37 #define MST_PCMCIA_CD1_IRQ 13
39 #define TYPE_MAINSTONE_FPGA "mainstone-fpga"
40 #define MAINSTONE_FPGA(obj) \
41 OBJECT_CHECK(mst_irq_state, (obj), TYPE_MAINSTONE_FPGA)
43 typedef struct mst_irq_state
{
44 SysBusDevice parent_obj
;
66 mst_fpga_set_irq(void *opaque
, int irq
, int level
)
68 mst_irq_state
*s
= (mst_irq_state
*)opaque
;
69 uint32_t oldint
= s
->intsetclr
& s
->intmskena
;
72 s
->prev_level
|= 1u << irq
;
74 s
->prev_level
&= ~(1u << irq
);
77 case MST_PCMCIA_CD0_IRQ
:
79 s
->pcmcia0
&= ~MST_PCMCIAx_nCD
;
81 s
->pcmcia0
|= MST_PCMCIAx_nCD
;
83 case MST_PCMCIA_CD1_IRQ
:
85 s
->pcmcia1
&= ~MST_PCMCIAx_nCD
;
87 s
->pcmcia1
|= MST_PCMCIAx_nCD
;
91 if ((s
->intmskena
& (1u << irq
)) && level
)
92 s
->intsetclr
|= 1u << irq
;
94 if (oldint
!= (s
->intsetclr
& s
->intmskena
))
95 qemu_set_irq(s
->parent
, s
->intsetclr
& s
->intmskena
);
100 mst_fpga_readb(void *opaque
, hwaddr addr
, unsigned size
)
102 mst_irq_state
*s
= (mst_irq_state
*) opaque
;
130 printf("Mainstone - mst_fpga_readb: Bad register offset "
131 "0x" TARGET_FMT_plx
"\n", addr
);
137 mst_fpga_writeb(void *opaque
, hwaddr addr
, uint64_t value
,
140 mst_irq_state
*s
= (mst_irq_state
*) opaque
;
168 case MST_INTMSKENA
: /* Mask interrupt */
169 s
->intmskena
= (value
& 0xFEEFF);
170 qemu_set_irq(s
->parent
, s
->intsetclr
& s
->intmskena
);
172 case MST_INTSETCLR
: /* clear or set interrupt */
173 s
->intsetclr
= (value
& 0xFEEFF);
174 qemu_set_irq(s
->parent
, s
->intsetclr
& s
->intmskena
);
176 /* For PCMCIAx allow the to change only power and reset */
178 s
->pcmcia0
= (value
& 0x1f) | (s
->pcmcia0
& ~0x1f);
181 s
->pcmcia1
= (value
& 0x1f) | (s
->pcmcia1
& ~0x1f);
184 printf("Mainstone - mst_fpga_writeb: Bad register offset "
185 "0x" TARGET_FMT_plx
"\n", addr
);
189 static const MemoryRegionOps mst_fpga_ops
= {
190 .read
= mst_fpga_readb
,
191 .write
= mst_fpga_writeb
,
192 .endianness
= DEVICE_NATIVE_ENDIAN
,
195 static int mst_fpga_post_load(void *opaque
, int version_id
)
197 mst_irq_state
*s
= (mst_irq_state
*) opaque
;
199 qemu_set_irq(s
->parent
, s
->intsetclr
& s
->intmskena
);
203 static void mst_fpga_init(Object
*obj
)
205 DeviceState
*dev
= DEVICE(obj
);
206 mst_irq_state
*s
= MAINSTONE_FPGA(obj
);
207 SysBusDevice
*sbd
= SYS_BUS_DEVICE(obj
);
209 s
->pcmcia0
= MST_PCMCIAx_READY
| MST_PCMCIAx_nCD
;
210 s
->pcmcia1
= MST_PCMCIAx_READY
| MST_PCMCIAx_nCD
;
212 sysbus_init_irq(sbd
, &s
->parent
);
214 /* alloc the external 16 irqs */
215 qdev_init_gpio_in(dev
, mst_fpga_set_irq
, MST_NUM_IRQS
);
217 memory_region_init_io(&s
->iomem
, obj
, &mst_fpga_ops
, s
,
219 sysbus_init_mmio(sbd
, &s
->iomem
);
222 static VMStateDescription vmstate_mst_fpga_regs
= {
223 .name
= "mainstone_fpga",
225 .minimum_version_id
= 0,
226 .post_load
= mst_fpga_post_load
,
227 .fields
= (VMStateField
[]) {
228 VMSTATE_UINT32(prev_level
, mst_irq_state
),
229 VMSTATE_UINT32(leddat1
, mst_irq_state
),
230 VMSTATE_UINT32(leddat2
, mst_irq_state
),
231 VMSTATE_UINT32(ledctrl
, mst_irq_state
),
232 VMSTATE_UINT32(gpswr
, mst_irq_state
),
233 VMSTATE_UINT32(mscwr1
, mst_irq_state
),
234 VMSTATE_UINT32(mscwr2
, mst_irq_state
),
235 VMSTATE_UINT32(mscwr3
, mst_irq_state
),
236 VMSTATE_UINT32(mscrd
, mst_irq_state
),
237 VMSTATE_UINT32(intmskena
, mst_irq_state
),
238 VMSTATE_UINT32(intsetclr
, mst_irq_state
),
239 VMSTATE_UINT32(pcmcia0
, mst_irq_state
),
240 VMSTATE_UINT32(pcmcia1
, mst_irq_state
),
241 VMSTATE_END_OF_LIST(),
245 static void mst_fpga_class_init(ObjectClass
*klass
, void *data
)
247 DeviceClass
*dc
= DEVICE_CLASS(klass
);
249 dc
->desc
= "Mainstone II FPGA";
250 dc
->vmsd
= &vmstate_mst_fpga_regs
;
253 static const TypeInfo mst_fpga_info
= {
254 .name
= TYPE_MAINSTONE_FPGA
,
255 .parent
= TYPE_SYS_BUS_DEVICE
,
256 .instance_size
= sizeof(mst_irq_state
),
257 .instance_init
= mst_fpga_init
,
258 .class_init
= mst_fpga_class_init
,
261 static void mst_fpga_register_types(void)
263 type_register_static(&mst_fpga_info
);
266 type_init(mst_fpga_register_types
)