summaryrefslogtreecommitdiff
path: root/hw/arm
diff options
context:
space:
mode:
Diffstat (limited to 'hw/arm')
-rw-r--r--hw/arm/exynos4210.c2
-rw-r--r--hw/arm/musicpal.c4
-rw-r--r--hw/arm/nseries.c2
-rw-r--r--hw/arm/pxa2xx.c44
-rw-r--r--hw/arm/realview.c4
-rw-r--r--hw/arm/spitz.c2
-rw-r--r--hw/arm/stellaris.c8
-rw-r--r--hw/arm/tosa.c18
-rw-r--r--hw/arm/versatilepb.c4
-rw-r--r--hw/arm/z2.c22
10 files changed, 67 insertions, 43 deletions
diff --git a/hw/arm/exynos4210.c b/hw/arm/exynos4210.c
index 4ebb9381b0..9f137e9acd 100644
--- a/hw/arm/exynos4210.c
+++ b/hw/arm/exynos4210.c
@@ -326,7 +326,7 @@ Exynos4210State *exynos4210_init(MemoryRegion *system_mem,
busdev = SYS_BUS_DEVICE(dev);
sysbus_connect_irq(busdev, 0, i2c_irq);
sysbus_mmio_map(busdev, 0, addr);
- s->i2c_if[n] = (i2c_bus *)qdev_get_child_bus(dev, "i2c");
+ s->i2c_if[n] = (I2CBus *)qdev_get_child_bus(dev, "i2c");
}
diff --git a/hw/arm/musicpal.c b/hw/arm/musicpal.c
index 023e8756e2..50a3b8fe4f 100644
--- a/hw/arm/musicpal.c
+++ b/hw/arm/musicpal.c
@@ -1593,7 +1593,7 @@ static void musicpal_init(QEMUMachineInitArgs *args)
DeviceState *key_dev;
DeviceState *wm8750_dev;
SysBusDevice *s;
- i2c_bus *i2c;
+ I2CBus *i2c;
int i;
unsigned long flash_size;
DriveInfo *dinfo;
@@ -1687,7 +1687,7 @@ static void musicpal_init(QEMUMachineInitArgs *args)
dev = sysbus_create_simple(TYPE_MUSICPAL_GPIO, MP_GPIO_BASE,
pic[MP_GPIO_IRQ]);
i2c_dev = sysbus_create_simple("gpio_i2c", -1, NULL);
- i2c = (i2c_bus *)qdev_get_child_bus(i2c_dev, "i2c");
+ i2c = (I2CBus *)qdev_get_child_bus(i2c_dev, "i2c");
lcd_dev = sysbus_create_simple(TYPE_MUSICPAL_LCD, MP_LCD_BASE, NULL);
key_dev = sysbus_create_simple(TYPE_MUSICPAL_KEY, -1, NULL);
diff --git a/hw/arm/nseries.c b/hw/arm/nseries.c
index 9ef31ca37a..c28f895c7a 100644
--- a/hw/arm/nseries.c
+++ b/hw/arm/nseries.c
@@ -202,7 +202,7 @@ static void n8x0_i2c_setup(struct n800_s *s)
{
DeviceState *dev;
qemu_irq tmp_irq = qdev_get_gpio_in(s->mpu->gpio, N8X0_TMP105_GPIO);
- i2c_bus *i2c = omap_i2c_bus(s->mpu->i2c[0]);
+ I2CBus *i2c = omap_i2c_bus(s->mpu->i2c[0]);
/* Attach a menelaus PM chip */
dev = i2c_create_slave(i2c, "twl92230", N8X0_MENELAUS_ADDR);
diff --git a/hw/arm/pxa2xx.c b/hw/arm/pxa2xx.c
index 25ec549e71..66bc0dccc9 100644
--- a/hw/arm/pxa2xx.c
+++ b/hw/arm/pxa2xx.c
@@ -1222,8 +1222,14 @@ static const TypeInfo pxa2xx_rtc_sysbus_info = {
};
/* I2C Interface */
-typedef struct {
- I2CSlave i2c;
+
+#define TYPE_PXA2XX_I2C_SLAVE "pxa2xx-i2c-slave"
+#define PXA2XX_I2C_SLAVE(obj) \
+ OBJECT_CHECK(PXA2xxI2CSlaveState, (obj), TYPE_PXA2XX_I2C_SLAVE)
+
+typedef struct PXA2xxI2CSlaveState {
+ I2CSlave parent_obj;
+
PXA2xxI2CState *host;
} PXA2xxI2CSlaveState;
@@ -1238,7 +1244,7 @@ struct PXA2xxI2CState {
MemoryRegion iomem;
PXA2xxI2CSlaveState *slave;
- i2c_bus *bus;
+ I2CBus *bus;
qemu_irq irq;
uint32_t offset;
uint32_t region_size;
@@ -1268,7 +1274,7 @@ static void pxa2xx_i2c_update(PXA2xxI2CState *s)
/* These are only stubs now. */
static void pxa2xx_i2c_event(I2CSlave *i2c, enum i2c_event event)
{
- PXA2xxI2CSlaveState *slave = FROM_I2C_SLAVE(PXA2xxI2CSlaveState, i2c);
+ PXA2xxI2CSlaveState *slave = PXA2XX_I2C_SLAVE(i2c);
PXA2xxI2CState *s = slave->host;
switch (event) {
@@ -1292,10 +1298,12 @@ static void pxa2xx_i2c_event(I2CSlave *i2c, enum i2c_event event)
static int pxa2xx_i2c_rx(I2CSlave *i2c)
{
- PXA2xxI2CSlaveState *slave = FROM_I2C_SLAVE(PXA2xxI2CSlaveState, i2c);
+ PXA2xxI2CSlaveState *slave = PXA2XX_I2C_SLAVE(i2c);
PXA2xxI2CState *s = slave->host;
- if ((s->control & (1 << 14)) || !(s->control & (1 << 6)))
+
+ if ((s->control & (1 << 14)) || !(s->control & (1 << 6))) {
return 0;
+ }
if (s->status & (1 << 0)) { /* RWM */
s->status |= 1 << 6; /* set ITE */
@@ -1307,10 +1315,12 @@ static int pxa2xx_i2c_rx(I2CSlave *i2c)
static int pxa2xx_i2c_tx(I2CSlave *i2c, uint8_t data)
{
- PXA2xxI2CSlaveState *slave = FROM_I2C_SLAVE(PXA2xxI2CSlaveState, i2c);
+ PXA2xxI2CSlaveState *slave = PXA2XX_I2C_SLAVE(i2c);
PXA2xxI2CState *s = slave->host;
- if ((s->control & (1 << 14)) || !(s->control & (1 << 6)))
+
+ if ((s->control & (1 << 14)) || !(s->control & (1 << 6))) {
return 1;
+ }
if (!(s->status & (1 << 0))) { /* RWM */
s->status |= 1 << 7; /* set IRF */
@@ -1325,6 +1335,7 @@ static uint64_t pxa2xx_i2c_read(void *opaque, hwaddr addr,
unsigned size)
{
PXA2xxI2CState *s = (PXA2xxI2CState *) opaque;
+ I2CSlave *slave;
addr -= s->offset;
switch (addr) {
@@ -1333,7 +1344,8 @@ static uint64_t pxa2xx_i2c_read(void *opaque, hwaddr addr,
case ISR:
return s->status | (i2c_bus_busy(s->bus) << 2);
case ISAR:
- return s->slave->i2c.address;
+ slave = I2C_SLAVE(s->slave);
+ return slave->address;
case IDBR:
return s->data;
case IBMR:
@@ -1408,7 +1420,7 @@ static void pxa2xx_i2c_write(void *opaque, hwaddr addr,
break;
case ISAR:
- i2c_set_slave_address(&s->slave->i2c, value & 0x7f);
+ i2c_set_slave_address(I2C_SLAVE(s->slave), value & 0x7f);
break;
case IDBR:
@@ -1432,7 +1444,7 @@ static const VMStateDescription vmstate_pxa2xx_i2c_slave = {
.minimum_version_id = 1,
.minimum_version_id_old = 1,
.fields = (VMStateField []) {
- VMSTATE_I2C_SLAVE(i2c, PXA2xxI2CSlaveState),
+ VMSTATE_I2C_SLAVE(parent_obj, PXA2xxI2CSlaveState),
VMSTATE_END_OF_LIST()
}
};
@@ -1470,7 +1482,7 @@ static void pxa2xx_i2c_slave_class_init(ObjectClass *klass, void *data)
}
static const TypeInfo pxa2xx_i2c_slave_info = {
- .name = "pxa2xx-i2c-slave",
+ .name = TYPE_PXA2XX_I2C_SLAVE,
.parent = TYPE_I2C_SLAVE,
.instance_size = sizeof(PXA2xxI2CSlaveState),
.class_init = pxa2xx_i2c_slave_class_init,
@@ -1482,7 +1494,7 @@ PXA2xxI2CState *pxa2xx_i2c_init(hwaddr base,
DeviceState *dev;
SysBusDevice *i2c_dev;
PXA2xxI2CState *s;
- i2c_bus *i2cbus;
+ I2CBus *i2cbus;
dev = qdev_create(NULL, TYPE_PXA2XX_I2C);
qdev_prop_set_uint32(dev, "size", region_size + 1);
@@ -1496,8 +1508,8 @@ PXA2xxI2CState *pxa2xx_i2c_init(hwaddr base,
s = PXA2XX_I2C(i2c_dev);
/* FIXME: Should the slave device really be on a separate bus? */
i2cbus = i2c_init_bus(dev, "dummy");
- dev = i2c_create_slave(i2cbus, "pxa2xx-i2c-slave", 0);
- s->slave = FROM_I2C_SLAVE(PXA2xxI2CSlaveState, I2C_SLAVE(dev));
+ dev = i2c_create_slave(i2cbus, TYPE_PXA2XX_I2C_SLAVE, 0);
+ s->slave = PXA2XX_I2C_SLAVE(dev);
s->slave->host = s;
return s;
@@ -1518,7 +1530,7 @@ static int pxa2xx_i2c_initfn(SysBusDevice *sbd)
return 0;
}
-i2c_bus *pxa2xx_i2c_bus(PXA2xxI2CState *s)
+I2CBus *pxa2xx_i2c_bus(PXA2xxI2CState *s)
{
return s->bus;
}
diff --git a/hw/arm/realview.c b/hw/arm/realview.c
index 8d845ddb73..6ef7646002 100644
--- a/hw/arm/realview.c
+++ b/hw/arm/realview.c
@@ -60,7 +60,7 @@ static void realview_init(QEMUMachineInitArgs *args,
qemu_irq mmc_irq[2];
PCIBus *pci_bus = NULL;
NICInfo *nd;
- i2c_bus *i2c;
+ I2CBus *i2c;
int n;
int done_nic = 0;
qemu_irq cpu_irq[4];
@@ -255,7 +255,7 @@ static void realview_init(QEMUMachineInitArgs *args,
}
dev = sysbus_create_simple("versatile_i2c", 0x10002000, NULL);
- i2c = (i2c_bus *)qdev_get_child_bus(dev, "i2c");
+ i2c = (I2CBus *)qdev_get_child_bus(dev, "i2c");
i2c_create_slave(i2c, "ds1338", 0x68);
/* Memory map for RealView Emulation Baseboard: */
diff --git a/hw/arm/spitz.c b/hw/arm/spitz.c
index ba172835eb..2decff170f 100644
--- a/hw/arm/spitz.c
+++ b/hw/arm/spitz.c
@@ -734,7 +734,7 @@ static void spitz_wm8750_addr(void *opaque, int line, int level)
static void spitz_i2c_setup(PXA2xxState *cpu)
{
/* Attach the CPU on one end of our I2C bus. */
- i2c_bus *bus = pxa2xx_i2c_bus(cpu->i2c[0]);
+ I2CBus *bus = pxa2xx_i2c_bus(cpu->i2c[0]);
DeviceState *wm;
diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c
index 3170d69d42..d6cc77b458 100644
--- a/hw/arm/stellaris.c
+++ b/hw/arm/stellaris.c
@@ -692,7 +692,7 @@ static int stellaris_sys_init(uint32_t base, qemu_irq irq,
typedef struct {
SysBusDevice parent_obj;
- i2c_bus *bus;
+ I2CBus *bus;
qemu_irq irq;
MemoryRegion iomem;
uint32_t msa;
@@ -868,7 +868,7 @@ static int stellaris_i2c_init(SysBusDevice *sbd)
{
DeviceState *dev = DEVICE(sbd);
stellaris_i2c_state *s = STELLARIS_I2C(dev);
- i2c_bus *bus;
+ I2CBus *bus;
sysbus_init_irq(sbd, &s->irq);
bus = i2c_init_bus(dev, "i2c");
@@ -1213,7 +1213,7 @@ static void stellaris_init(const char *kernel_filename, const char *cpu_model,
qemu_irq adc;
int sram_size;
int flash_size;
- i2c_bus *i2c;
+ I2CBus *i2c;
DeviceState *dev;
int i;
int j;
@@ -1256,7 +1256,7 @@ static void stellaris_init(const char *kernel_filename, const char *cpu_model,
if (board->dc2 & (1 << 12)) {
dev = sysbus_create_simple(TYPE_STELLARIS_I2C, 0x40020000, pic[8]);
- i2c = (i2c_bus *)qdev_get_child_bus(dev, "i2c");
+ i2c = (I2CBus *)qdev_get_child_bus(dev, "i2c");
if (board->peripherals & BP_OLED_I2C) {
i2c_create_slave(i2c, "ssd0303", 0x3d);
}
diff --git a/hw/arm/tosa.c b/hw/arm/tosa.c
index c00d8c27cc..2069f55432 100644
--- a/hw/arm/tosa.c
+++ b/hw/arm/tosa.c
@@ -132,15 +132,20 @@ static int tosa_ssp_init(SSISlave *dev)
return 0;
}
+#define TYPE_TOSA_DAC "tosa_dac"
+#define TOSA_DAC(obj) OBJECT_CHECK(TosaDACState, (obj), TYPE_TOSA_DAC)
+
typedef struct {
- I2CSlave i2c;
+ I2CSlave parent_obj;
+
int len;
char buf[3];
} TosaDACState;
static int tosa_dac_send(I2CSlave *i2c, uint8_t data)
{
- TosaDACState *s = FROM_I2C_SLAVE(TosaDACState, i2c);
+ TosaDACState *s = TOSA_DAC(i2c);
+
s->buf[s->len] = data;
if (s->len ++ > 2) {
#ifdef VERBOSE
@@ -159,7 +164,8 @@ static int tosa_dac_send(I2CSlave *i2c, uint8_t data)
static void tosa_dac_event(I2CSlave *i2c, enum i2c_event event)
{
- TosaDACState *s = FROM_I2C_SLAVE(TosaDACState, i2c);
+ TosaDACState *s = TOSA_DAC(i2c);
+
s->len = 0;
switch (event) {
case I2C_START_SEND:
@@ -194,8 +200,8 @@ static int tosa_dac_init(I2CSlave *i2c)
static void tosa_tg_init(PXA2xxState *cpu)
{
- i2c_bus *bus = pxa2xx_i2c_bus(cpu->i2c[0]);
- i2c_create_slave(bus, "tosa_dac", DAC_BASE);
+ I2CBus *bus = pxa2xx_i2c_bus(cpu->i2c[0]);
+ i2c_create_slave(bus, TYPE_TOSA_DAC, DAC_BASE);
ssi_create_slave(cpu->ssp[1], "tosa-ssp");
}
@@ -271,7 +277,7 @@ static void tosa_dac_class_init(ObjectClass *klass, void *data)
}
static const TypeInfo tosa_dac_info = {
- .name = "tosa_dac",
+ .name = TYPE_TOSA_DAC,
.parent = TYPE_I2C_SLAVE,
.instance_size = sizeof(TosaDACState),
.class_init = tosa_dac_class_init,
diff --git a/hw/arm/versatilepb.c b/hw/arm/versatilepb.c
index aef2bde0c4..e5493b428f 100644
--- a/hw/arm/versatilepb.c
+++ b/hw/arm/versatilepb.c
@@ -185,7 +185,7 @@ static void versatile_init(QEMUMachineInitArgs *args, int board_id)
DeviceState *pl041;
PCIBus *pci_bus;
NICInfo *nd;
- i2c_bus *i2c;
+ I2CBus *i2c;
int n;
int done_smc = 0;
DriveInfo *dinfo;
@@ -288,7 +288,7 @@ static void versatile_init(QEMUMachineInitArgs *args, int board_id)
sysbus_create_simple("pl031", 0x101e8000, pic[10]);
dev = sysbus_create_simple("versatile_i2c", 0x10002000, NULL);
- i2c = (i2c_bus *)qdev_get_child_bus(dev, "i2c");
+ i2c = (I2CBus *)qdev_get_child_bus(dev, "i2c");
i2c_create_slave(i2c, "ds1338", 0x68);
/* Add PL041 AACI Interface to the LM4549 codec */
diff --git a/hw/arm/z2.c b/hw/arm/z2.c
index 97367b1f8b..67c1be84ac 100644
--- a/hw/arm/z2.c
+++ b/hw/arm/z2.c
@@ -193,15 +193,20 @@ static const TypeInfo zipit_lcd_info = {
.class_init = zipit_lcd_class_init,
};
-typedef struct {
- I2CSlave i2c;
+#define TYPE_AER915 "aer915"
+#define AER915(obj) OBJECT_CHECK(AER915State, (obj), TYPE_AER915)
+
+typedef struct AER915State {
+ I2CSlave parent_obj;
+
int len;
uint8_t buf[3];
} AER915State;
static int aer915_send(I2CSlave *i2c, uint8_t data)
{
- AER915State *s = FROM_I2C_SLAVE(AER915State, i2c);
+ AER915State *s = AER915(i2c);
+
s->buf[s->len] = data;
if (s->len++ > 2) {
DPRINTF("%s: message too long (%i bytes)\n",
@@ -219,7 +224,8 @@ static int aer915_send(I2CSlave *i2c, uint8_t data)
static void aer915_event(I2CSlave *i2c, enum i2c_event event)
{
- AER915State *s = FROM_I2C_SLAVE(AER915State, i2c);
+ AER915State *s = AER915(i2c);
+
switch (event) {
case I2C_START_SEND:
s->len = 0;
@@ -238,8 +244,8 @@ static void aer915_event(I2CSlave *i2c, enum i2c_event event)
static int aer915_recv(I2CSlave *slave)
{
+ AER915State *s = AER915(slave);
int retval = 0x00;
- AER915State *s = FROM_I2C_SLAVE(AER915State, slave);
switch (s->buf[0]) {
/* Return hardcoded battery voltage,
@@ -290,7 +296,7 @@ static void aer915_class_init(ObjectClass *klass, void *data)
}
static const TypeInfo aer915_info = {
- .name = "aer915",
+ .name = TYPE_AER915,
.parent = TYPE_I2C_SLAVE,
.instance_size = sizeof(AER915State),
.class_init = aer915_class_init,
@@ -308,7 +314,7 @@ static void z2_init(QEMUMachineInitArgs *args)
DriveInfo *dinfo;
int be;
void *z2_lcd;
- i2c_bus *bus;
+ I2CBus *bus;
DeviceState *wm;
if (!cpu_model) {
@@ -351,7 +357,7 @@ static void z2_init(QEMUMachineInitArgs *args)
type_register_static(&aer915_info);
z2_lcd = ssi_create_slave(mpu->ssp[1], "zipit-lcd");
bus = pxa2xx_i2c_bus(mpu->i2c[0]);
- i2c_create_slave(bus, "aer915", 0x55);
+ i2c_create_slave(bus, TYPE_AER915, 0x55);
wm = i2c_create_slave(bus, "wm8750", 0x1b);
mpu->i2s->opaque = wm;
mpu->i2s->codec_out = wm8750_dac_dat;