Skip to content

Commit db437ca

Browse files
philmdcminyard
authored andcommitted
hw/i2c: Rename i2c_try_create_slave() as i2c_slave_new()
We use "new" names for functions that allocate and initialize device objects: pci_new(), isa_new(), usb_new(). Let's call this one i2c_slave_new(). Since we have to update all the callers, also let it return a I2CSlave object. Suggested-by: Markus Armbruster <[email protected]> Reviewed-by: Markus Armbruster <[email protected]> Signed-off-by: Philippe Mathieu-Daudé <[email protected]> Message-Id: <[email protected]> Signed-off-by: Corey Minyard <[email protected]>
1 parent 7a204cb commit db437ca

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

hw/arm/aspeed.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ static void witherspoon_bmc_i2c_init(AspeedMachineState *bmc)
513513
/* Bus 3: TODO bmp280@77 */
514514
/* Bus 3: TODO max31785@52 */
515515
/* Bus 3: TODO dps310@76 */
516-
dev = i2c_try_create_slave(TYPE_PCA9552, 0x60);
516+
dev = DEVICE(i2c_slave_new(TYPE_PCA9552, 0x60));
517517
qdev_prop_set_string(dev, "description", "pca1");
518518
i2c_realize_and_unref(dev, aspeed_i2c_get_bus(&soc->i2c, 3),
519519
&error_fatal);
@@ -531,7 +531,7 @@ static void witherspoon_bmc_i2c_init(AspeedMachineState *bmc)
531531

532532
smbus_eeprom_init_one(aspeed_i2c_get_bus(&soc->i2c, 11), 0x51,
533533
eeprom_buf);
534-
dev = i2c_try_create_slave(TYPE_PCA9552, 0x60);
534+
dev = DEVICE(i2c_slave_new(TYPE_PCA9552, 0x60));
535535
qdev_prop_set_string(dev, "description", "pca0");
536536
i2c_realize_and_unref(dev, aspeed_i2c_get_bus(&soc->i2c, 11),
537537
&error_fatal);

hw/i2c/core.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,13 @@ const VMStateDescription vmstate_i2c_slave = {
267267
}
268268
};
269269

270-
DeviceState *i2c_try_create_slave(const char *name, uint8_t addr)
270+
I2CSlave *i2c_slave_new(const char *name, uint8_t addr)
271271
{
272272
DeviceState *dev;
273273

274274
dev = qdev_new(name);
275275
qdev_prop_set_uint8(dev, "address", addr);
276-
return dev;
276+
return I2C_SLAVE(dev);
277277
}
278278

279279
bool i2c_realize_and_unref(DeviceState *dev, I2CBus *bus, Error **errp)
@@ -283,12 +283,11 @@ bool i2c_realize_and_unref(DeviceState *dev, I2CBus *bus, Error **errp)
283283

284284
DeviceState *i2c_create_slave(I2CBus *bus, const char *name, uint8_t addr)
285285
{
286-
DeviceState *dev;
286+
I2CSlave *dev = i2c_slave_new(name, addr);
287287

288-
dev = i2c_try_create_slave(name, addr);
289-
i2c_realize_and_unref(dev, bus, &error_fatal);
288+
i2c_realize_and_unref(DEVICE(dev), bus, &error_fatal);
290289

291-
return dev;
290+
return DEVICE(dev);
292291
}
293292

294293
static void i2c_slave_class_init(ObjectClass *klass, void *data)

include/hw/i2c/i2c.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ int i2c_send_recv(I2CBus *bus, uint8_t *data, bool send);
7979
int i2c_send(I2CBus *bus, uint8_t data);
8080
uint8_t i2c_recv(I2CBus *bus);
8181

82+
I2CSlave *i2c_slave_new(const char *name, uint8_t addr);
8283
DeviceState *i2c_create_slave(I2CBus *bus, const char *name, uint8_t addr);
83-
DeviceState *i2c_try_create_slave(const char *name, uint8_t addr);
8484
bool i2c_realize_and_unref(DeviceState *dev, I2CBus *bus, Error **errp);
8585

8686
/* lm832x.c */

0 commit comments

Comments
 (0)