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 #define MST_PCMCIAx_READY (1 << 10)
30 #define MST_PCMCIAx_nCD (1 << 5)
32 #define MST_PCMCIA_CD0_IRQ 9
33 #define MST_PCMCIA_CD1_IRQ 13
35 typedef struct mst_irq_state
{
56 mst_fpga_set_irq(void *opaque
, int irq
, int level
)
58 mst_irq_state
*s
= (mst_irq_state
*)opaque
;
59 uint32_t oldint
= s
->intsetclr
& s
->intmskena
;
62 s
->prev_level
|= 1u << irq
;
64 s
->prev_level
&= ~(1u << irq
);
67 case MST_PCMCIA_CD0_IRQ
:
69 s
->pcmcia0
&= ~MST_PCMCIAx_nCD
;
71 s
->pcmcia0
|= MST_PCMCIAx_nCD
;
73 case MST_PCMCIA_CD1_IRQ
:
75 s
->pcmcia1
&= ~MST_PCMCIAx_nCD
;
77 s
->pcmcia1
|= MST_PCMCIAx_nCD
;
81 if ((s
->intmskena
& (1u << irq
)) && level
)
82 s
->intsetclr
|= 1u << irq
;
84 if (oldint
!= (s
->intsetclr
& s
->intmskena
))
85 qemu_set_irq(s
->parent
, s
->intsetclr
& s
->intmskena
);
90 mst_fpga_readb(void *opaque
, target_phys_addr_t addr
)
92 mst_irq_state
*s
= (mst_irq_state
*) opaque
;
120 printf("Mainstone - mst_fpga_readb: Bad register offset "
121 "0x" TARGET_FMT_plx
" \n", addr
);
127 mst_fpga_writeb(void *opaque
, target_phys_addr_t addr
, uint32_t value
)
129 mst_irq_state
*s
= (mst_irq_state
*) opaque
;
157 case MST_INTMSKENA
: /* Mask interupt */
158 s
->intmskena
= (value
& 0xFEEFF);
159 qemu_set_irq(s
->parent
, s
->intsetclr
& s
->intmskena
);
161 case MST_INTSETCLR
: /* clear or set interrupt */
162 s
->intsetclr
= (value
& 0xFEEFF);
163 qemu_set_irq(s
->parent
, s
->intsetclr
& s
->intmskena
);
165 /* For PCMCIAx allow the to change only power and reset */
167 s
->pcmcia0
= (value
& 0x1f) | (s
->pcmcia0
& ~0x1f);
170 s
->pcmcia1
= (value
& 0x1f) | (s
->pcmcia1
& ~0x1f);
173 printf("Mainstone - mst_fpga_writeb: Bad register offset "
174 "0x" TARGET_FMT_plx
" \n", addr
);
178 static CPUReadMemoryFunc
* const mst_fpga_readfn
[] = {
183 static CPUWriteMemoryFunc
* const mst_fpga_writefn
[] = {
190 static int mst_fpga_post_load(void *opaque
, int version_id
)
192 mst_irq_state
*s
= (mst_irq_state
*) opaque
;
194 qemu_set_irq(s
->parent
, s
->intsetclr
& s
->intmskena
);
198 static int mst_fpga_init(SysBusDevice
*dev
)
203 s
= FROM_SYSBUS(mst_irq_state
, dev
);
205 s
->pcmcia0
= MST_PCMCIAx_READY
| MST_PCMCIAx_nCD
;
206 s
->pcmcia1
= MST_PCMCIAx_READY
| MST_PCMCIAx_nCD
;
208 sysbus_init_irq(dev
, &s
->parent
);
210 /* alloc the external 16 irqs */
211 qdev_init_gpio_in(&dev
->qdev
, mst_fpga_set_irq
, MST_NUM_IRQS
);
213 iomemtype
= cpu_register_io_memory(mst_fpga_readfn
,
214 mst_fpga_writefn
, s
, DEVICE_NATIVE_ENDIAN
);
215 sysbus_init_mmio(dev
, 0x00100000, iomemtype
);
219 static VMStateDescription vmstate_mst_fpga_regs
= {
220 .name
= "mainstone_fpga",
222 .minimum_version_id
= 0,
223 .minimum_version_id_old
= 0,
224 .post_load
= mst_fpga_post_load
,
225 .fields
= (VMStateField
[]) {
226 VMSTATE_UINT32(prev_level
, mst_irq_state
),
227 VMSTATE_UINT32(leddat1
, mst_irq_state
),
228 VMSTATE_UINT32(leddat2
, mst_irq_state
),
229 VMSTATE_UINT32(ledctrl
, mst_irq_state
),
230 VMSTATE_UINT32(gpswr
, mst_irq_state
),
231 VMSTATE_UINT32(mscwr1
, mst_irq_state
),
232 VMSTATE_UINT32(mscwr2
, mst_irq_state
),
233 VMSTATE_UINT32(mscwr3
, mst_irq_state
),
234 VMSTATE_UINT32(mscrd
, mst_irq_state
),
235 VMSTATE_UINT32(intmskena
, mst_irq_state
),
236 VMSTATE_UINT32(intsetclr
, mst_irq_state
),
237 VMSTATE_UINT32(pcmcia0
, mst_irq_state
),
238 VMSTATE_UINT32(pcmcia1
, mst_irq_state
),
239 VMSTATE_END_OF_LIST(),
243 static SysBusDeviceInfo mst_fpga_info
= {
244 .init
= mst_fpga_init
,
245 .qdev
.name
= "mainstone-fpga",
246 .qdev
.desc
= "Mainstone II FPGA",
247 .qdev
.size
= sizeof(mst_irq_state
),
248 .qdev
.vmsd
= &vmstate_mst_fpga_regs
,
251 static void mst_fpga_register(void)
253 sysbus_register_withprop(&mst_fpga_info
);
255 device_init(mst_fpga_register
);