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_BASE MST_FPGA_PHYS
18 #define MST_LEDDAT1 0x10
19 #define MST_LEDDAT2 0x14
20 #define MST_LEDCTRL 0x40
21 #define MST_GPSWR 0x60
22 #define MST_MSCWR1 0x80
23 #define MST_MSCWR2 0x84
24 #define MST_MSCWR3 0x88
25 #define MST_MSCRD 0x90
26 #define MST_INTMSKENA 0xc0
27 #define MST_INTSETCLR 0xd0
28 #define MST_PCMCIA0 0xe0
29 #define MST_PCMCIA1 0xe4
31 typedef struct mst_irq_state
{
32 target_phys_addr_t target_base
;
52 mst_fpga_update_gpio(mst_irq_state
*s
)
56 level
= s
->prev_level
^ s
->intsetclr
;
58 for (diff
= s
->prev_level
^ level
; diff
; diff
^= 1 << bit
) {
60 qemu_set_irq(s
->pins
[bit
], (level
>> bit
) & 1 );
62 s
->prev_level
= level
;
66 mst_fpga_set_irq(void *opaque
, int irq
, int level
)
68 mst_irq_state
*s
= (mst_irq_state
*)opaque
;
71 s
->prev_level
|= 1u << irq
;
73 s
->prev_level
&= ~(1u << irq
);
75 if(s
->intmskena
& (1u << irq
)) {
76 s
->intsetclr
= 1u << irq
;
77 qemu_set_irq(s
->parent
[0], level
);
83 mst_fpga_readb(void *opaque
, target_phys_addr_t addr
)
85 mst_irq_state
*s
= (mst_irq_state
*) opaque
;
86 addr
-= s
->target_base
;
114 printf("Mainstone - mst_fpga_readb: Bad register offset "
115 REG_FMT
" \n", addr
);
121 mst_fpga_writeb(void *opaque
, target_phys_addr_t addr
, uint32_t value
)
123 mst_irq_state
*s
= (mst_irq_state
*) opaque
;
124 addr
-= s
->target_base
;
152 case MST_INTMSKENA
: /* Mask interupt */
153 s
->intmskena
= (value
& 0xFEEFF);
154 mst_fpga_update_gpio(s
);
156 case MST_INTSETCLR
: /* clear or set interrupt */
157 s
->intsetclr
= (value
& 0xFEEFF);
166 printf("Mainstone - mst_fpga_writeb: Bad register offset "
167 REG_FMT
" \n", addr
);
171 CPUReadMemoryFunc
*mst_fpga_readfn
[] = {
176 CPUWriteMemoryFunc
*mst_fpga_writefn
[] = {
183 mst_fpga_save(QEMUFile
*f
, void *opaque
)
185 struct mst_irq_state
*s
= (mst_irq_state
*) opaque
;
187 qemu_put_be32s(f
, &s
->prev_level
);
188 qemu_put_be32s(f
, &s
->leddat1
);
189 qemu_put_be32s(f
, &s
->leddat2
);
190 qemu_put_be32s(f
, &s
->ledctrl
);
191 qemu_put_be32s(f
, &s
->gpswr
);
192 qemu_put_be32s(f
, &s
->mscwr1
);
193 qemu_put_be32s(f
, &s
->mscwr2
);
194 qemu_put_be32s(f
, &s
->mscwr3
);
195 qemu_put_be32s(f
, &s
->mscrd
);
196 qemu_put_be32s(f
, &s
->intmskena
);
197 qemu_put_be32s(f
, &s
->intsetclr
);
198 qemu_put_be32s(f
, &s
->pcmcia0
);
199 qemu_put_be32s(f
, &s
->pcmcia1
);
203 mst_fpga_load(QEMUFile
*f
, void *opaque
, int version_id
)
205 mst_irq_state
*s
= (mst_irq_state
*) opaque
;
207 qemu_get_be32s(f
, &s
->prev_level
);
208 qemu_get_be32s(f
, &s
->leddat1
);
209 qemu_get_be32s(f
, &s
->leddat2
);
210 qemu_get_be32s(f
, &s
->ledctrl
);
211 qemu_get_be32s(f
, &s
->gpswr
);
212 qemu_get_be32s(f
, &s
->mscwr1
);
213 qemu_get_be32s(f
, &s
->mscwr2
);
214 qemu_get_be32s(f
, &s
->mscwr3
);
215 qemu_get_be32s(f
, &s
->mscrd
);
216 qemu_get_be32s(f
, &s
->intmskena
);
217 qemu_get_be32s(f
, &s
->intsetclr
);
218 qemu_get_be32s(f
, &s
->pcmcia0
);
219 qemu_get_be32s(f
, &s
->pcmcia1
);
223 qemu_irq
*mst_irq_init(struct pxa2xx_state_s
*cpu
, uint32_t base
, int irq
)
229 s
= (mst_irq_state
*)
230 qemu_mallocz(sizeof(mst_irq_state
));
234 s
->target_base
= base
;
235 s
->parent
= &cpu
->pic
[irq
];
237 /* alloc the external 16 irqs */
238 qi
= qemu_allocate_irqs(mst_fpga_set_irq
, s
, MST_NUM_IRQS
);
241 iomemtype
= cpu_register_io_memory(0, mst_fpga_readfn
,
242 mst_fpga_writefn
, s
);
243 cpu_register_physical_memory(MST_BASE
, 0x00100000, iomemtype
);
244 register_savevm("mainstone_fpga", 0, 0, mst_fpga_save
, mst_fpga_load
, s
);