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.
13 /* Mainstone FPGA for extern irqs */
14 #define FPGA_GPIO_PIN 0
15 #define MST_NUM_IRQS 16
16 #define MST_LEDDAT1 0x10
17 #define MST_LEDDAT2 0x14
18 #define MST_LEDCTRL 0x40
19 #define MST_GPSWR 0x60
20 #define MST_MSCWR1 0x80
21 #define MST_MSCWR2 0x84
22 #define MST_MSCWR3 0x88
23 #define MST_MSCRD 0x90
24 #define MST_INTMSKENA 0xc0
25 #define MST_INTSETCLR 0xd0
26 #define MST_PCMCIA0 0xe0
27 #define MST_PCMCIA1 0xe4
29 typedef struct mst_irq_state
{
50 mst_fpga_set_irq(void *opaque
, int irq
, int level
)
52 mst_irq_state
*s
= (mst_irq_state
*)opaque
;
53 uint32_t oldint
= s
->intsetclr
;
56 s
->prev_level
|= 1u << irq
;
58 s
->prev_level
&= ~(1u << irq
);
60 if ((s
->intmskena
& (1u << irq
)) && level
)
61 s
->intsetclr
|= 1u << irq
;
63 if (oldint
!= (s
->intsetclr
& s
->intmskena
))
64 qemu_set_irq(s
->parent
, s
->intsetclr
& s
->intmskena
);
69 mst_fpga_readb(void *opaque
, target_phys_addr_t addr
)
71 mst_irq_state
*s
= (mst_irq_state
*) opaque
;
99 printf("Mainstone - mst_fpga_readb: Bad register offset "
100 "0x" TARGET_FMT_plx
" \n", addr
);
106 mst_fpga_writeb(void *opaque
, target_phys_addr_t addr
, uint32_t value
)
108 mst_irq_state
*s
= (mst_irq_state
*) opaque
;
136 case MST_INTMSKENA
: /* Mask interupt */
137 s
->intmskena
= (value
& 0xFEEFF);
138 qemu_set_irq(s
->parent
, s
->intsetclr
& s
->intmskena
);
140 case MST_INTSETCLR
: /* clear or set interrupt */
141 s
->intsetclr
= (value
& 0xFEEFF);
142 qemu_set_irq(s
->parent
, s
->intsetclr
);
151 printf("Mainstone - mst_fpga_writeb: Bad register offset "
152 "0x" TARGET_FMT_plx
" \n", addr
);
156 static CPUReadMemoryFunc
* const mst_fpga_readfn
[] = {
161 static CPUWriteMemoryFunc
* const mst_fpga_writefn
[] = {
168 static int mst_fpga_post_load(void *opaque
, int version_id
)
170 mst_irq_state
*s
= (mst_irq_state
*) opaque
;
172 qemu_set_irq(s
->parent
, s
->intsetclr
& s
->intmskena
);
176 static int mst_fpga_init(SysBusDevice
*dev
)
181 s
= FROM_SYSBUS(mst_irq_state
, dev
);
183 sysbus_init_irq(dev
, &s
->parent
);
185 /* alloc the external 16 irqs */
186 qdev_init_gpio_in(&dev
->qdev
, mst_fpga_set_irq
, MST_NUM_IRQS
);
188 iomemtype
= cpu_register_io_memory(mst_fpga_readfn
,
189 mst_fpga_writefn
, s
, DEVICE_NATIVE_ENDIAN
);
190 sysbus_init_mmio(dev
, 0x00100000, iomemtype
);
194 static VMStateDescription vmstate_mst_fpga_regs
= {
195 .name
= "mainstone_fpga",
197 .minimum_version_id
= 0,
198 .minimum_version_id_old
= 0,
199 .post_load
= mst_fpga_post_load
,
200 .fields
= (VMStateField
[]) {
201 VMSTATE_UINT32(prev_level
, mst_irq_state
),
202 VMSTATE_UINT32(leddat1
, mst_irq_state
),
203 VMSTATE_UINT32(leddat2
, mst_irq_state
),
204 VMSTATE_UINT32(ledctrl
, mst_irq_state
),
205 VMSTATE_UINT32(gpswr
, mst_irq_state
),
206 VMSTATE_UINT32(mscwr1
, mst_irq_state
),
207 VMSTATE_UINT32(mscwr2
, mst_irq_state
),
208 VMSTATE_UINT32(mscwr3
, mst_irq_state
),
209 VMSTATE_UINT32(mscrd
, mst_irq_state
),
210 VMSTATE_UINT32(intmskena
, mst_irq_state
),
211 VMSTATE_UINT32(intsetclr
, mst_irq_state
),
212 VMSTATE_UINT32(pcmcia0
, mst_irq_state
),
213 VMSTATE_UINT32(pcmcia1
, mst_irq_state
),
214 VMSTATE_END_OF_LIST(),
218 static SysBusDeviceInfo mst_fpga_info
= {
219 .init
= mst_fpga_init
,
220 .qdev
.name
= "mainstone-fpga",
221 .qdev
.desc
= "Mainstone II FPGA",
222 .qdev
.size
= sizeof(mst_irq_state
),
223 .qdev
.vmsd
= &vmstate_mst_fpga_regs
,
226 static void mst_fpga_register(void)
228 sysbus_register_withprop(&mst_fpga_info
);
230 device_init(mst_fpga_register
);