2007-12-02 02:20:03 +00:00
|
|
|
/*
|
|
|
|
* PXA270-based Intel Mainstone platforms.
|
|
|
|
* FPGA driver
|
|
|
|
*
|
|
|
|
* Copyright (c) 2007 by Armin Kuster <akuster@kama-aina.net> or
|
|
|
|
* <akuster@mvista.com>
|
|
|
|
*
|
|
|
|
* This code is licensed under the GNU GPL v2.
|
2012-01-13 16:44:23 +00:00
|
|
|
*
|
|
|
|
* Contributions after 2012-01-13 are licensed under the terms of the
|
|
|
|
* GNU GPL, version 2 or (at your option) any later version.
|
2007-12-02 02:20:03 +00:00
|
|
|
*/
|
2013-02-04 14:40:22 +00:00
|
|
|
#include "hw/hw.h"
|
|
|
|
#include "hw/sysbus.h"
|
2007-12-02 02:20:03 +00:00
|
|
|
|
|
|
|
/* Mainstone FPGA for extern irqs */
|
|
|
|
#define FPGA_GPIO_PIN 0
|
|
|
|
#define MST_NUM_IRQS 16
|
|
|
|
#define MST_LEDDAT1 0x10
|
|
|
|
#define MST_LEDDAT2 0x14
|
|
|
|
#define MST_LEDCTRL 0x40
|
|
|
|
#define MST_GPSWR 0x60
|
|
|
|
#define MST_MSCWR1 0x80
|
|
|
|
#define MST_MSCWR2 0x84
|
|
|
|
#define MST_MSCWR3 0x88
|
|
|
|
#define MST_MSCRD 0x90
|
|
|
|
#define MST_INTMSKENA 0xc0
|
|
|
|
#define MST_INTSETCLR 0xd0
|
|
|
|
#define MST_PCMCIA0 0xe0
|
|
|
|
#define MST_PCMCIA1 0xe4
|
|
|
|
|
2011-03-04 00:54:59 +00:00
|
|
|
#define MST_PCMCIAx_READY (1 << 10)
|
|
|
|
#define MST_PCMCIAx_nCD (1 << 5)
|
|
|
|
|
|
|
|
#define MST_PCMCIA_CD0_IRQ 9
|
|
|
|
#define MST_PCMCIA_CD1_IRQ 13
|
|
|
|
|
2013-07-26 20:32:18 +00:00
|
|
|
#define TYPE_MAINSTONE_FPGA "mainstone-fpga"
|
|
|
|
#define MAINSTONE_FPGA(obj) \
|
|
|
|
OBJECT_CHECK(mst_irq_state, (obj), TYPE_MAINSTONE_FPGA)
|
|
|
|
|
2007-12-02 02:20:03 +00:00
|
|
|
typedef struct mst_irq_state{
|
2013-07-26 20:32:18 +00:00
|
|
|
SysBusDevice parent_obj;
|
|
|
|
|
|
|
|
MemoryRegion iomem;
|
|
|
|
|
|
|
|
qemu_irq parent;
|
|
|
|
|
|
|
|
uint32_t prev_level;
|
|
|
|
uint32_t leddat1;
|
|
|
|
uint32_t leddat2;
|
|
|
|
uint32_t ledctrl;
|
|
|
|
uint32_t gpswr;
|
|
|
|
uint32_t mscwr1;
|
|
|
|
uint32_t mscwr2;
|
|
|
|
uint32_t mscwr3;
|
|
|
|
uint32_t mscrd;
|
|
|
|
uint32_t intmskena;
|
|
|
|
uint32_t intsetclr;
|
|
|
|
uint32_t pcmcia0;
|
|
|
|
uint32_t pcmcia1;
|
2007-12-02 02:20:03 +00:00
|
|
|
}mst_irq_state;
|
|
|
|
|
|
|
|
static void
|
|
|
|
mst_fpga_set_irq(void *opaque, int irq, int level)
|
|
|
|
{
|
|
|
|
mst_irq_state *s = (mst_irq_state *)opaque;
|
2011-02-16 13:22:33 +00:00
|
|
|
uint32_t oldint = s->intsetclr & s->intmskena;
|
2007-12-02 02:20:03 +00:00
|
|
|
|
|
|
|
if (level)
|
|
|
|
s->prev_level |= 1u << irq;
|
|
|
|
else
|
|
|
|
s->prev_level &= ~(1u << irq);
|
|
|
|
|
2011-03-04 00:54:59 +00:00
|
|
|
switch(irq) {
|
|
|
|
case MST_PCMCIA_CD0_IRQ:
|
|
|
|
if (level)
|
|
|
|
s->pcmcia0 &= ~MST_PCMCIAx_nCD;
|
|
|
|
else
|
|
|
|
s->pcmcia0 |= MST_PCMCIAx_nCD;
|
|
|
|
break;
|
|
|
|
case MST_PCMCIA_CD1_IRQ:
|
|
|
|
if (level)
|
|
|
|
s->pcmcia1 &= ~MST_PCMCIAx_nCD;
|
|
|
|
else
|
|
|
|
s->pcmcia1 |= MST_PCMCIAx_nCD;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-02-12 00:15:23 +00:00
|
|
|
if ((s->intmskena & (1u << irq)) && level)
|
|
|
|
s->intsetclr |= 1u << irq;
|
|
|
|
|
|
|
|
if (oldint != (s->intsetclr & s->intmskena))
|
|
|
|
qemu_set_irq(s->parent, s->intsetclr & s->intmskena);
|
2007-12-02 02:20:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-24 20:38:20 +00:00
|
|
|
static uint64_t
|
2012-10-23 10:30:10 +00:00
|
|
|
mst_fpga_readb(void *opaque, hwaddr addr, unsigned size)
|
2007-12-02 02:20:03 +00:00
|
|
|
{
|
|
|
|
mst_irq_state *s = (mst_irq_state *) opaque;
|
|
|
|
|
|
|
|
switch (addr) {
|
|
|
|
case MST_LEDDAT1:
|
|
|
|
return s->leddat1;
|
|
|
|
case MST_LEDDAT2:
|
|
|
|
return s->leddat2;
|
|
|
|
case MST_LEDCTRL:
|
|
|
|
return s->ledctrl;
|
|
|
|
case MST_GPSWR:
|
|
|
|
return s->gpswr;
|
|
|
|
case MST_MSCWR1:
|
|
|
|
return s->mscwr1;
|
|
|
|
case MST_MSCWR2:
|
|
|
|
return s->mscwr2;
|
|
|
|
case MST_MSCWR3:
|
|
|
|
return s->mscwr3;
|
|
|
|
case MST_MSCRD:
|
|
|
|
return s->mscrd;
|
|
|
|
case MST_INTMSKENA:
|
|
|
|
return s->intmskena;
|
|
|
|
case MST_INTSETCLR:
|
|
|
|
return s->intsetclr;
|
|
|
|
case MST_PCMCIA0:
|
|
|
|
return s->pcmcia0;
|
|
|
|
case MST_PCMCIA1:
|
|
|
|
return s->pcmcia1;
|
|
|
|
default:
|
|
|
|
printf("Mainstone - mst_fpga_readb: Bad register offset "
|
2011-09-12 20:33:01 +00:00
|
|
|
"0x" TARGET_FMT_plx "\n", addr);
|
2007-12-02 02:20:03 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-10-23 10:30:10 +00:00
|
|
|
mst_fpga_writeb(void *opaque, hwaddr addr, uint64_t value,
|
2011-10-24 20:38:20 +00:00
|
|
|
unsigned size)
|
2007-12-02 02:20:03 +00:00
|
|
|
{
|
|
|
|
mst_irq_state *s = (mst_irq_state *) opaque;
|
|
|
|
value &= 0xffffffff;
|
|
|
|
|
|
|
|
switch (addr) {
|
|
|
|
case MST_LEDDAT1:
|
|
|
|
s->leddat1 = value;
|
|
|
|
break;
|
|
|
|
case MST_LEDDAT2:
|
|
|
|
s->leddat2 = value;
|
|
|
|
break;
|
|
|
|
case MST_LEDCTRL:
|
|
|
|
s->ledctrl = value;
|
|
|
|
break;
|
|
|
|
case MST_GPSWR:
|
|
|
|
s->gpswr = value;
|
|
|
|
break;
|
|
|
|
case MST_MSCWR1:
|
|
|
|
s->mscwr1 = value;
|
|
|
|
break;
|
|
|
|
case MST_MSCWR2:
|
|
|
|
s->mscwr2 = value;
|
|
|
|
break;
|
|
|
|
case MST_MSCWR3:
|
|
|
|
s->mscwr3 = value;
|
|
|
|
break;
|
|
|
|
case MST_MSCRD:
|
|
|
|
s->mscrd = value;
|
|
|
|
break;
|
2011-04-28 15:20:35 +00:00
|
|
|
case MST_INTMSKENA: /* Mask interrupt */
|
2007-12-02 02:20:03 +00:00
|
|
|
s->intmskena = (value & 0xFEEFF);
|
2011-02-12 00:15:23 +00:00
|
|
|
qemu_set_irq(s->parent, s->intsetclr & s->intmskena);
|
2007-12-02 02:20:03 +00:00
|
|
|
break;
|
|
|
|
case MST_INTSETCLR: /* clear or set interrupt */
|
|
|
|
s->intsetclr = (value & 0xFEEFF);
|
2011-02-16 13:22:33 +00:00
|
|
|
qemu_set_irq(s->parent, s->intsetclr & s->intmskena);
|
2007-12-02 02:20:03 +00:00
|
|
|
break;
|
2011-03-04 00:54:59 +00:00
|
|
|
/* For PCMCIAx allow the to change only power and reset */
|
2007-12-02 02:20:03 +00:00
|
|
|
case MST_PCMCIA0:
|
2011-03-04 00:54:59 +00:00
|
|
|
s->pcmcia0 = (value & 0x1f) | (s->pcmcia0 & ~0x1f);
|
2007-12-02 02:20:03 +00:00
|
|
|
break;
|
|
|
|
case MST_PCMCIA1:
|
2011-03-04 00:54:59 +00:00
|
|
|
s->pcmcia1 = (value & 0x1f) | (s->pcmcia1 & ~0x1f);
|
2007-12-02 02:20:03 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("Mainstone - mst_fpga_writeb: Bad register offset "
|
2011-09-12 20:33:01 +00:00
|
|
|
"0x" TARGET_FMT_plx "\n", addr);
|
2007-12-02 02:20:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-24 20:38:20 +00:00
|
|
|
static const MemoryRegionOps mst_fpga_ops = {
|
|
|
|
.read = mst_fpga_readb,
|
|
|
|
.write = mst_fpga_writeb,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2007-12-02 02:20:03 +00:00
|
|
|
};
|
|
|
|
|
2011-02-12 00:15:24 +00:00
|
|
|
static int mst_fpga_post_load(void *opaque, int version_id)
|
2007-12-02 02:20:03 +00:00
|
|
|
{
|
|
|
|
mst_irq_state *s = (mst_irq_state *) opaque;
|
|
|
|
|
2011-02-12 00:15:23 +00:00
|
|
|
qemu_set_irq(s->parent, s->intsetclr & s->intmskena);
|
2007-12-02 02:20:03 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-26 20:32:18 +00:00
|
|
|
static int mst_fpga_init(SysBusDevice *sbd)
|
2007-12-02 02:20:03 +00:00
|
|
|
{
|
2013-07-26 20:32:18 +00:00
|
|
|
DeviceState *dev = DEVICE(sbd);
|
|
|
|
mst_irq_state *s = MAINSTONE_FPGA(dev);
|
2007-12-02 02:20:03 +00:00
|
|
|
|
2013-07-26 20:32:18 +00:00
|
|
|
s->pcmcia0 = MST_PCMCIAx_READY | MST_PCMCIAx_nCD;
|
|
|
|
s->pcmcia1 = MST_PCMCIAx_READY | MST_PCMCIAx_nCD;
|
2011-03-04 00:54:59 +00:00
|
|
|
|
2013-07-26 20:32:18 +00:00
|
|
|
sysbus_init_irq(sbd, &s->parent);
|
2007-12-02 02:20:03 +00:00
|
|
|
|
2013-07-26 20:32:18 +00:00
|
|
|
/* alloc the external 16 irqs */
|
|
|
|
qdev_init_gpio_in(dev, mst_fpga_set_irq, MST_NUM_IRQS);
|
2007-12-02 02:20:03 +00:00
|
|
|
|
2013-07-26 20:32:18 +00:00
|
|
|
memory_region_init_io(&s->iomem, OBJECT(s), &mst_fpga_ops, s,
|
|
|
|
"fpga", 0x00100000);
|
|
|
|
sysbus_init_mmio(sbd, &s->iomem);
|
|
|
|
return 0;
|
2011-02-12 00:15:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static VMStateDescription vmstate_mst_fpga_regs = {
|
2014-05-13 15:09:35 +00:00
|
|
|
.name = "mainstone_fpga",
|
|
|
|
.version_id = 0,
|
|
|
|
.minimum_version_id = 0,
|
|
|
|
.post_load = mst_fpga_post_load,
|
|
|
|
.fields = (VMStateField[]) {
|
2011-02-12 00:15:24 +00:00
|
|
|
VMSTATE_UINT32(prev_level, mst_irq_state),
|
|
|
|
VMSTATE_UINT32(leddat1, mst_irq_state),
|
|
|
|
VMSTATE_UINT32(leddat2, mst_irq_state),
|
|
|
|
VMSTATE_UINT32(ledctrl, mst_irq_state),
|
|
|
|
VMSTATE_UINT32(gpswr, mst_irq_state),
|
|
|
|
VMSTATE_UINT32(mscwr1, mst_irq_state),
|
|
|
|
VMSTATE_UINT32(mscwr2, mst_irq_state),
|
|
|
|
VMSTATE_UINT32(mscwr3, mst_irq_state),
|
|
|
|
VMSTATE_UINT32(mscrd, mst_irq_state),
|
|
|
|
VMSTATE_UINT32(intmskena, mst_irq_state),
|
|
|
|
VMSTATE_UINT32(intsetclr, mst_irq_state),
|
|
|
|
VMSTATE_UINT32(pcmcia0, mst_irq_state),
|
|
|
|
VMSTATE_UINT32(pcmcia1, mst_irq_state),
|
|
|
|
VMSTATE_END_OF_LIST(),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2012-01-24 19:12:29 +00:00
|
|
|
static void mst_fpga_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 03:34:16 +00:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-01-24 19:12:29 +00:00
|
|
|
SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
|
|
|
|
|
|
|
|
k->init = mst_fpga_init;
|
2011-12-08 03:34:16 +00:00
|
|
|
dc->desc = "Mainstone II FPGA";
|
|
|
|
dc->vmsd = &vmstate_mst_fpga_regs;
|
2012-01-24 19:12:29 +00:00
|
|
|
}
|
|
|
|
|
2013-01-10 15:19:07 +00:00
|
|
|
static const TypeInfo mst_fpga_info = {
|
2013-07-26 20:32:18 +00:00
|
|
|
.name = TYPE_MAINSTONE_FPGA,
|
2011-12-08 03:34:16 +00:00
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(mst_irq_state),
|
|
|
|
.class_init = mst_fpga_class_init,
|
2011-02-12 00:15:24 +00:00
|
|
|
};
|
|
|
|
|
2012-02-09 14:20:55 +00:00
|
|
|
static void mst_fpga_register_types(void)
|
2011-02-12 00:15:24 +00:00
|
|
|
{
|
2011-12-08 03:34:16 +00:00
|
|
|
type_register_static(&mst_fpga_info);
|
2007-12-02 02:20:03 +00:00
|
|
|
}
|
2012-02-09 14:20:55 +00:00
|
|
|
|
|
|
|
type_init(mst_fpga_register_types)
|