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
{
57 mst_fpga_set_irq(void *opaque
, int irq
, int level
)
59 mst_irq_state
*s
= (mst_irq_state
*)opaque
;
60 uint32_t oldint
= s
->intsetclr
& s
->intmskena
;
63 s
->prev_level
|= 1u << irq
;
65 s
->prev_level
&= ~(1u << irq
);
68 case MST_PCMCIA_CD0_IRQ
:
70 s
->pcmcia0
&= ~MST_PCMCIAx_nCD
;
72 s
->pcmcia0
|= MST_PCMCIAx_nCD
;
74 case MST_PCMCIA_CD1_IRQ
:
76 s
->pcmcia1
&= ~MST_PCMCIAx_nCD
;
78 s
->pcmcia1
|= MST_PCMCIAx_nCD
;
82 if ((s
->intmskena
& (1u << irq
)) && level
)
83 s
->intsetclr
|= 1u << irq
;
85 if (oldint
!= (s
->intsetclr
& s
->intmskena
))
86 qemu_set_irq(s
->parent
, s
->intsetclr
& s
->intmskena
);
91 mst_fpga_readb(void *opaque
, target_phys_addr_t addr
, unsigned size
)
93 mst_irq_state
*s
= (mst_irq_state
*) opaque
;
121 printf("Mainstone - mst_fpga_readb: Bad register offset "
122 "0x" TARGET_FMT_plx
"\n", addr
);
128 mst_fpga_writeb(void *opaque
, target_phys_addr_t addr
, uint64_t value
,
131 mst_irq_state
*s
= (mst_irq_state
*) opaque
;
159 case MST_INTMSKENA
: /* Mask interrupt */
160 s
->intmskena
= (value
& 0xFEEFF);
161 qemu_set_irq(s
->parent
, s
->intsetclr
& s
->intmskena
);
163 case MST_INTSETCLR
: /* clear or set interrupt */
164 s
->intsetclr
= (value
& 0xFEEFF);
165 qemu_set_irq(s
->parent
, s
->intsetclr
& s
->intmskena
);
167 /* For PCMCIAx allow the to change only power and reset */
169 s
->pcmcia0
= (value
& 0x1f) | (s
->pcmcia0
& ~0x1f);
172 s
->pcmcia1
= (value
& 0x1f) | (s
->pcmcia1
& ~0x1f);
175 printf("Mainstone - mst_fpga_writeb: Bad register offset "
176 "0x" TARGET_FMT_plx
"\n", addr
);
180 static const MemoryRegionOps mst_fpga_ops
= {
181 .read
= mst_fpga_readb
,
182 .write
= mst_fpga_writeb
,
183 .endianness
= DEVICE_NATIVE_ENDIAN
,
186 static int mst_fpga_post_load(void *opaque
, int version_id
)
188 mst_irq_state
*s
= (mst_irq_state
*) opaque
;
190 qemu_set_irq(s
->parent
, s
->intsetclr
& s
->intmskena
);
194 static int mst_fpga_init(SysBusDevice
*dev
)
198 s
= FROM_SYSBUS(mst_irq_state
, dev
);
200 s
->pcmcia0
= MST_PCMCIAx_READY
| MST_PCMCIAx_nCD
;
201 s
->pcmcia1
= MST_PCMCIAx_READY
| MST_PCMCIAx_nCD
;
203 sysbus_init_irq(dev
, &s
->parent
);
205 /* alloc the external 16 irqs */
206 qdev_init_gpio_in(&dev
->qdev
, mst_fpga_set_irq
, MST_NUM_IRQS
);
208 memory_region_init_io(&s
->iomem
, &mst_fpga_ops
, s
,
210 sysbus_init_mmio(dev
, &s
->iomem
);
214 static VMStateDescription vmstate_mst_fpga_regs
= {
215 .name
= "mainstone_fpga",
217 .minimum_version_id
= 0,
218 .minimum_version_id_old
= 0,
219 .post_load
= mst_fpga_post_load
,
220 .fields
= (VMStateField
[]) {
221 VMSTATE_UINT32(prev_level
, mst_irq_state
),
222 VMSTATE_UINT32(leddat1
, mst_irq_state
),
223 VMSTATE_UINT32(leddat2
, mst_irq_state
),
224 VMSTATE_UINT32(ledctrl
, mst_irq_state
),
225 VMSTATE_UINT32(gpswr
, mst_irq_state
),
226 VMSTATE_UINT32(mscwr1
, mst_irq_state
),
227 VMSTATE_UINT32(mscwr2
, mst_irq_state
),
228 VMSTATE_UINT32(mscwr3
, mst_irq_state
),
229 VMSTATE_UINT32(mscrd
, mst_irq_state
),
230 VMSTATE_UINT32(intmskena
, mst_irq_state
),
231 VMSTATE_UINT32(intsetclr
, mst_irq_state
),
232 VMSTATE_UINT32(pcmcia0
, mst_irq_state
),
233 VMSTATE_UINT32(pcmcia1
, mst_irq_state
),
234 VMSTATE_END_OF_LIST(),
238 static SysBusDeviceInfo mst_fpga_info
= {
239 .init
= mst_fpga_init
,
240 .qdev
.name
= "mainstone-fpga",
241 .qdev
.desc
= "Mainstone II FPGA",
242 .qdev
.size
= sizeof(mst_irq_state
),
243 .qdev
.vmsd
= &vmstate_mst_fpga_regs
,
246 static void mst_fpga_register(void)
248 sysbus_register_withprop(&mst_fpga_info
);
250 device_init(mst_fpga_register
);