aboutsummaryrefslogtreecommitdiff
path: root/hw/i2c.c
diff options
context:
space:
mode:
authorpbrook <pbrook@c046a42c-6fe2-441c-8c8c-71466251a162>2008-07-01 23:16:53 +0000
committerpbrook <pbrook@c046a42c-6fe2-441c-8c8c-71466251a162>2008-07-01 23:16:53 +0000
commitc701b35b42d50537122486e47006d1c6ce952240 (patch)
tree4184adb750076dba546efe1bf8c3b80c216ac35d /hw/i2c.c
parent75f482aeeda361929262be918faf90fb75ab8e33 (diff)
downloadqemu-c701b35b42d50537122486e47006d1c6ce952240.zip
qemu-c701b35b42d50537122486e47006d1c6ce952240.tar.gz
qemu-c701b35b42d50537122486e47006d1c6ce952240.tar.bz2
Fix i2c save/restore.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4820 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'hw/i2c.c')
-rw-r--r--hw/i2c.c49
1 files changed, 27 insertions, 22 deletions
diff --git a/hw/i2c.c b/hw/i2c.c
index e590801..5d283fb 100644
--- a/hw/i2c.c
+++ b/hw/i2c.c
@@ -14,14 +14,38 @@ struct i2c_bus
{
i2c_slave *current_dev;
i2c_slave *dev;
+ int saved_address;
};
+static void i2c_bus_save(QEMUFile *f, void *opaque)
+{
+ i2c_bus *bus = (i2c_bus *)opaque;
+
+ qemu_put_byte(f, bus->current_dev ? bus->current_dev->address : -1);
+}
+
+static int i2c_bus_load(QEMUFile *f, void *opaque, int version_id)
+{
+ i2c_bus *bus = (i2c_bus *)opaque;
+
+ if (version_id != 1)
+ return -EINVAL;
+
+ /* The bus is loaded before attached devices, so load and save the
+ current device id. Devices will check themselves as loaded. */
+ bus->saved_address = qemu_get_be32(f);
+ bus->current_dev = NULL;
+
+ return 0;
+}
+
/* Create a new I2C bus. */
i2c_bus *i2c_init_bus(void)
{
i2c_bus *bus;
bus = (i2c_bus *)qemu_mallocz(sizeof(i2c_bus));
+ register_savevm("i2c_bus", -1, 1, i2c_bus_save, i2c_bus_load, bus);
return bus;
}
@@ -37,6 +61,7 @@ i2c_slave *i2c_slave_init(i2c_bus *bus, int address, int size)
dev->address = address;
dev->next = bus->dev;
bus->dev = dev;
+ dev->bus = bus;
return dev;
}
@@ -115,28 +140,6 @@ void i2c_nack(i2c_bus *bus)
dev->event(dev, I2C_NACK);
}
-void i2c_bus_save(QEMUFile *f, i2c_bus *bus)
-{
- qemu_put_byte(f, bus->current_dev ? bus->current_dev->address : 0x00);
-}
-
-void i2c_bus_load(QEMUFile *f, i2c_bus *bus)
-{
- i2c_slave *dev;
- uint8_t address = qemu_get_byte(f);
-
- if (address) {
- for (dev = bus->dev; dev; dev = dev->next)
- if (dev->address == address) {
- bus->current_dev = dev;
- return;
- }
-
- fprintf(stderr, "%s: I2C slave with address %02x disappeared\n",
- __FUNCTION__, address);
- }
-}
-
void i2c_slave_save(QEMUFile *f, i2c_slave *dev)
{
qemu_put_byte(f, dev->address);
@@ -145,4 +148,6 @@ void i2c_slave_save(QEMUFile *f, i2c_slave *dev)
void i2c_slave_load(QEMUFile *f, i2c_slave *dev)
{
dev->address = qemu_get_byte(f);
+ if (dev->bus->saved_address == dev->address)
+ dev->bus->current_dev = dev;
}