From: Philippe Mathieu-Daudé Date: Tue, 23 Jun 2020 07:27:15 +0000 (+0200) Subject: hw/i2c/core: Add i2c_try_create_slave() and i2c_realize_and_unref() X-Git-Tag: v5.1.0-rc0~45^2~53 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d88c42ff2c;p=thirdparty%2Fqemu.git hw/i2c/core: Add i2c_try_create_slave() and i2c_realize_and_unref() Extract i2c_try_create_slave() and i2c_realize_and_unref() from i2c_create_slave(). We can now set properties on a I2CSlave before it is realized. This is in line with the recent qdev/QOM changes merged in commit 6675a653d2e. Reviewed-by: Corey Minyard Reviewed-by: Cédric Le Goater Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Markus Armbruster Tested-by: Cédric Le Goater Message-id: 20200623072723.6324-2-f4bug@amsat.org Signed-off-by: Peter Maydell --- diff --git a/hw/i2c/core.c b/hw/i2c/core.c index 1aac457a2a0..acf34a12d6d 100644 --- a/hw/i2c/core.c +++ b/hw/i2c/core.c @@ -267,13 +267,27 @@ const VMStateDescription vmstate_i2c_slave = { } }; -DeviceState *i2c_create_slave(I2CBus *bus, const char *name, uint8_t addr) +DeviceState *i2c_try_create_slave(const char *name, uint8_t addr) { DeviceState *dev; dev = qdev_new(name); qdev_prop_set_uint8(dev, "address", addr); - qdev_realize_and_unref(dev, &bus->qbus, &error_fatal); + return dev; +} + +bool i2c_realize_and_unref(DeviceState *dev, I2CBus *bus, Error **errp) +{ + return qdev_realize_and_unref(dev, &bus->qbus, errp); +} + +DeviceState *i2c_create_slave(I2CBus *bus, const char *name, uint8_t addr) +{ + DeviceState *dev; + + dev = i2c_try_create_slave(name, addr); + i2c_realize_and_unref(dev, bus, &error_fatal); + return dev; } diff --git a/include/hw/i2c/i2c.h b/include/hw/i2c/i2c.h index 41172115652..d6e3d85faf0 100644 --- a/include/hw/i2c/i2c.h +++ b/include/hw/i2c/i2c.h @@ -80,6 +80,8 @@ int i2c_send(I2CBus *bus, uint8_t data); uint8_t i2c_recv(I2CBus *bus); DeviceState *i2c_create_slave(I2CBus *bus, const char *name, uint8_t addr); +DeviceState *i2c_try_create_slave(const char *name, uint8_t addr); +bool i2c_realize_and_unref(DeviceState *dev, I2CBus *bus, Error **errp); /* lm832x.c */ void lm832x_key_event(DeviceState *dev, int key, int state);