]>
git.proxmox.com Git - qemu.git/blob - hw/mst_fpga.c
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.
12 #include "mainstone.h"
14 /* Mainstone FPGA for extern irqs */
15 #define FPGA_GPIO_PIN 0
16 #define MST_NUM_IRQS 16
17 #define MST_LEDDAT1 0x10
18 #define MST_LEDDAT2 0x14
19 #define MST_LEDCTRL 0x40
20 #define MST_GPSWR 0x60
21 #define MST_MSCWR1 0x80
22 #define MST_MSCWR2 0x84
23 #define MST_MSCWR3 0x88
24 #define MST_MSCRD 0x90
25 #define MST_INTMSKENA 0xc0
26 #define MST_INTSETCLR 0xd0
27 #define MST_PCMCIA0 0xe0
28 #define MST_PCMCIA1 0xe4
30 typedef struct mst_irq_state
{
50 mst_fpga_update_gpio(mst_irq_state
*s
)
54 level
= s
->prev_level
^ s
->intsetclr
;
56 for (diff
= s
->prev_level
^ level
; diff
; diff
^= 1 << bit
) {
58 qemu_set_irq(s
->pins
[bit
], (level
>> bit
) & 1 );
60 s
->prev_level
= level
;
64 mst_fpga_set_irq(void *opaque
, int irq
, int level
)
66 mst_irq_state
*s
= (mst_irq_state
*)opaque
;
69 s
->prev_level
|= 1u << irq
;
71 s
->prev_level
&= ~(1u << irq
);
73 if(s
->intmskena
& (1u << irq
)) {
74 s
->intsetclr
= 1u << irq
;
75 qemu_set_irq(s
->parent
[0], level
);
81 mst_fpga_readb(void *opaque
, target_phys_addr_t addr
)
83 mst_irq_state
*s
= (mst_irq_state
*) opaque
;
111 printf("Mainstone - mst_fpga_readb: Bad register offset "
112 REG_FMT
" \n", addr
);
118 mst_fpga_writeb(void *opaque
, target_phys_addr_t addr
, uint32_t value
)
120 mst_irq_state
*s
= (mst_irq_state
*) opaque
;
148 case MST_INTMSKENA
: /* Mask interupt */
149 s
->intmskena
= (value
& 0xFEEFF);
150 mst_fpga_update_gpio(s
);
152 case MST_INTSETCLR
: /* clear or set interrupt */
153 s
->intsetclr
= (value
& 0xFEEFF);
162 printf("Mainstone - mst_fpga_writeb: Bad register offset "
163 REG_FMT
" \n", addr
);
167 static CPUReadMemoryFunc
* const mst_fpga_readfn
[] = {
172 static CPUWriteMemoryFunc
* const mst_fpga_writefn
[] = {
179 mst_fpga_save(QEMUFile
*f
, void *opaque
)
181 struct mst_irq_state
*s
= (mst_irq_state
*) opaque
;
183 qemu_put_be32s(f
, &s
->prev_level
);
184 qemu_put_be32s(f
, &s
->leddat1
);
185 qemu_put_be32s(f
, &s
->leddat2
);
186 qemu_put_be32s(f
, &s
->ledctrl
);
187 qemu_put_be32s(f
, &s
->gpswr
);
188 qemu_put_be32s(f
, &s
->mscwr1
);
189 qemu_put_be32s(f
, &s
->mscwr2
);
190 qemu_put_be32s(f
, &s
->mscwr3
);
191 qemu_put_be32s(f
, &s
->mscrd
);
192 qemu_put_be32s(f
, &s
->intmskena
);
193 qemu_put_be32s(f
, &s
->intsetclr
);
194 qemu_put_be32s(f
, &s
->pcmcia0
);
195 qemu_put_be32s(f
, &s
->pcmcia1
);
199 mst_fpga_load(QEMUFile
*f
, void *opaque
, int version_id
)
201 mst_irq_state
*s
= (mst_irq_state
*) opaque
;
203 qemu_get_be32s(f
, &s
->prev_level
);
204 qemu_get_be32s(f
, &s
->leddat1
);
205 qemu_get_be32s(f
, &s
->leddat2
);
206 qemu_get_be32s(f
, &s
->ledctrl
);
207 qemu_get_be32s(f
, &s
->gpswr
);
208 qemu_get_be32s(f
, &s
->mscwr1
);
209 qemu_get_be32s(f
, &s
->mscwr2
);
210 qemu_get_be32s(f
, &s
->mscwr3
);
211 qemu_get_be32s(f
, &s
->mscrd
);
212 qemu_get_be32s(f
, &s
->intmskena
);
213 qemu_get_be32s(f
, &s
->intsetclr
);
214 qemu_get_be32s(f
, &s
->pcmcia0
);
215 qemu_get_be32s(f
, &s
->pcmcia1
);
219 qemu_irq
*mst_irq_init(PXA2xxState
*cpu
, uint32_t base
, int irq
)
225 s
= (mst_irq_state
*)
226 qemu_mallocz(sizeof(mst_irq_state
));
228 s
->parent
= &cpu
->pic
[irq
];
230 /* alloc the external 16 irqs */
231 qi
= qemu_allocate_irqs(mst_fpga_set_irq
, s
, MST_NUM_IRQS
);
234 iomemtype
= cpu_register_io_memory(mst_fpga_readfn
,
235 mst_fpga_writefn
, s
);
236 cpu_register_physical_memory(base
, 0x00100000, iomemtype
);
237 register_savevm(NULL
, "mainstone_fpga", 0, 0, mst_fpga_save
,