Skip to content

Commit 7a204cb

Browse files
philmdcminyard
authored andcommitted
hw/i2c/aspeed_i2c: Simplify aspeed_i2c_get_bus()
All the callers of aspeed_i2c_get_bus() have a AspeedI2CState and cast it to a DeviceState with DEVICE(), then aspeed_i2c_get_bus() cast the DeviceState to an AspeedI2CState with ASPEED_I2C()... Simplify aspeed_i2c_get_bus() callers by using AspeedI2CState argument. Reviewed-by: Markus Armbruster <[email protected]> Reviewed-by: Andrew Jeffery <[email protected]> Reviewed-by: Cédric Le Goater <[email protected]> Signed-off-by: Philippe Mathieu-Daudé <[email protected]> Message-Id: <[email protected]> Signed-off-by: Corey Minyard <[email protected]>
1 parent ae163b8 commit 7a204cb

File tree

3 files changed

+37
-38
lines changed

3 files changed

+37
-38
lines changed

hw/arm/aspeed.c

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -385,13 +385,13 @@ static void palmetto_bmc_i2c_init(AspeedMachineState *bmc)
385385

386386
/* The palmetto platform expects a ds3231 RTC but a ds1338 is
387387
* enough to provide basic RTC features. Alarms will be missing */
388-
i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 0), "ds1338", 0x68);
388+
i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 0), "ds1338", 0x68);
389389

390-
smbus_eeprom_init_one(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 0), 0x50,
390+
smbus_eeprom_init_one(aspeed_i2c_get_bus(&soc->i2c, 0), 0x50,
391391
eeprom_buf);
392392

393393
/* add a TMP423 temperature sensor */
394-
dev = i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 2),
394+
dev = i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 2),
395395
"tmp423", 0x4c);
396396
object_property_set_int(OBJECT(dev), "temperature0", 31000, &error_abort);
397397
object_property_set_int(OBJECT(dev), "temperature1", 28000, &error_abort);
@@ -404,16 +404,16 @@ static void ast2500_evb_i2c_init(AspeedMachineState *bmc)
404404
AspeedSoCState *soc = &bmc->soc;
405405
uint8_t *eeprom_buf = g_malloc0(8 * 1024);
406406

407-
smbus_eeprom_init_one(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 3), 0x50,
407+
smbus_eeprom_init_one(aspeed_i2c_get_bus(&soc->i2c, 3), 0x50,
408408
eeprom_buf);
409409

410410
/* The AST2500 EVB expects a LM75 but a TMP105 is compatible */
411-
i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 7),
411+
i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 7),
412412
TYPE_TMP105, 0x4d);
413413

414414
/* The AST2500 EVB does not have an RTC. Let's pretend that one is
415415
* plugged on the I2C bus header */
416-
i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 11), "ds1338", 0x32);
416+
i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 11), "ds1338", 0x32);
417417
}
418418

419419
static void ast2600_evb_i2c_init(AspeedMachineState *bmc)
@@ -428,69 +428,69 @@ static void romulus_bmc_i2c_init(AspeedMachineState *bmc)
428428

429429
/* The romulus board expects Epson RX8900 I2C RTC but a ds1338 is
430430
* good enough */
431-
i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 11), "ds1338", 0x32);
431+
i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 11), "ds1338", 0x32);
432432
}
433433

434434
static void swift_bmc_i2c_init(AspeedMachineState *bmc)
435435
{
436436
AspeedSoCState *soc = &bmc->soc;
437437

438-
i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 3), "pca9552", 0x60);
438+
i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 3), "pca9552", 0x60);
439439

440440
/* The swift board expects a TMP275 but a TMP105 is compatible */
441-
i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 7), "tmp105", 0x48);
441+
i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 7), "tmp105", 0x48);
442442
/* The swift board expects a pca9551 but a pca9552 is compatible */
443-
i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 7), "pca9552", 0x60);
443+
i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 7), "pca9552", 0x60);
444444

445445
/* The swift board expects an Epson RX8900 RTC but a ds1338 is compatible */
446-
i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 8), "ds1338", 0x32);
447-
i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 8), "pca9552", 0x60);
446+
i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 8), "ds1338", 0x32);
447+
i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 8), "pca9552", 0x60);
448448

449-
i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 9), "tmp423", 0x4c);
449+
i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 9), "tmp423", 0x4c);
450450
/* The swift board expects a pca9539 but a pca9552 is compatible */
451-
i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 9), "pca9552", 0x74);
451+
i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 9), "pca9552", 0x74);
452452

453-
i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 10), "tmp423", 0x4c);
453+
i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 10), "tmp423", 0x4c);
454454
/* The swift board expects a pca9539 but a pca9552 is compatible */
455-
i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 10), "pca9552",
455+
i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 10), "pca9552",
456456
0x74);
457457

458458
/* The swift board expects a TMP275 but a TMP105 is compatible */
459-
i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 12), "tmp105", 0x48);
460-
i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 12), "tmp105", 0x4a);
459+
i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 12), "tmp105", 0x48);
460+
i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 12), "tmp105", 0x4a);
461461
}
462462

463463
static void sonorapass_bmc_i2c_init(AspeedMachineState *bmc)
464464
{
465465
AspeedSoCState *soc = &bmc->soc;
466466

467467
/* bus 2 : */
468-
i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 2), "tmp105", 0x48);
469-
i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 2), "tmp105", 0x49);
468+
i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 2), "tmp105", 0x48);
469+
i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 2), "tmp105", 0x49);
470470
/* bus 2 : pca9546 @ 0x73 */
471471

472472
/* bus 3 : pca9548 @ 0x70 */
473473

474474
/* bus 4 : */
475475
uint8_t *eeprom4_54 = g_malloc0(8 * 1024);
476-
smbus_eeprom_init_one(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 4), 0x54,
476+
smbus_eeprom_init_one(aspeed_i2c_get_bus(&soc->i2c, 4), 0x54,
477477
eeprom4_54);
478478
/* PCA9539 @ 0x76, but PCA9552 is compatible */
479-
i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 4), "pca9552", 0x76);
479+
i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 4), "pca9552", 0x76);
480480
/* PCA9539 @ 0x77, but PCA9552 is compatible */
481-
i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 4), "pca9552", 0x77);
481+
i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 4), "pca9552", 0x77);
482482

483483
/* bus 6 : */
484-
i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 6), "tmp105", 0x48);
485-
i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 6), "tmp105", 0x49);
484+
i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 6), "tmp105", 0x48);
485+
i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 6), "tmp105", 0x49);
486486
/* bus 6 : pca9546 @ 0x73 */
487487

488488
/* bus 8 : */
489489
uint8_t *eeprom8_56 = g_malloc0(8 * 1024);
490-
smbus_eeprom_init_one(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 8), 0x56,
490+
smbus_eeprom_init_one(aspeed_i2c_get_bus(&soc->i2c, 8), 0x56,
491491
eeprom8_56);
492-
i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 8), "pca9552", 0x60);
493-
i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 8), "pca9552", 0x61);
492+
i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 8), "pca9552", 0x60);
493+
i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 8), "pca9552", 0x61);
494494
/* bus 8 : adc128d818 @ 0x1d */
495495
/* bus 8 : adc128d818 @ 0x1f */
496496

@@ -515,25 +515,25 @@ static void witherspoon_bmc_i2c_init(AspeedMachineState *bmc)
515515
/* Bus 3: TODO dps310@76 */
516516
dev = i2c_try_create_slave(TYPE_PCA9552, 0x60);
517517
qdev_prop_set_string(dev, "description", "pca1");
518-
i2c_realize_and_unref(dev, aspeed_i2c_get_bus(DEVICE(&soc->i2c), 3),
518+
i2c_realize_and_unref(dev, aspeed_i2c_get_bus(&soc->i2c, 3),
519519
&error_fatal);
520520

521-
i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 4), "tmp423", 0x4c);
522-
i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 5), "tmp423", 0x4c);
521+
i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 4), "tmp423", 0x4c);
522+
i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 5), "tmp423", 0x4c);
523523

524524
/* The Witherspoon expects a TMP275 but a TMP105 is compatible */
525-
i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 9), TYPE_TMP105,
525+
i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 9), TYPE_TMP105,
526526
0x4a);
527527

528528
/* The witherspoon board expects Epson RX8900 I2C RTC but a ds1338 is
529529
* good enough */
530-
i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 11), "ds1338", 0x32);
530+
i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 11), "ds1338", 0x32);
531531

532-
smbus_eeprom_init_one(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 11), 0x51,
532+
smbus_eeprom_init_one(aspeed_i2c_get_bus(&soc->i2c, 11), 0x51,
533533
eeprom_buf);
534534
dev = i2c_try_create_slave(TYPE_PCA9552, 0x60);
535535
qdev_prop_set_string(dev, "description", "pca0");
536-
i2c_realize_and_unref(dev, aspeed_i2c_get_bus(DEVICE(&soc->i2c), 11),
536+
i2c_realize_and_unref(dev, aspeed_i2c_get_bus(&soc->i2c, 11),
537537
&error_fatal);
538538
/* Bus 11: TODO ucd90160@64 */
539539
}

hw/i2c/aspeed_i2c.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -959,9 +959,8 @@ static void aspeed_i2c_register_types(void)
959959
type_init(aspeed_i2c_register_types)
960960

961961

962-
I2CBus *aspeed_i2c_get_bus(DeviceState *dev, int busnr)
962+
I2CBus *aspeed_i2c_get_bus(AspeedI2CState *s, int busnr)
963963
{
964-
AspeedI2CState *s = ASPEED_I2C(dev);
965964
AspeedI2CClass *aic = ASPEED_I2C_GET_CLASS(s);
966965
I2CBus *bus = NULL;
967966

include/hw/i2c/aspeed_i2c.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,6 @@ typedef struct AspeedI2CClass {
9393

9494
} AspeedI2CClass;
9595

96-
I2CBus *aspeed_i2c_get_bus(DeviceState *dev, int busnr);
96+
I2CBus *aspeed_i2c_get_bus(AspeedI2CState *s, int busnr);
9797

9898
#endif /* ASPEED_I2C_H */

0 commit comments

Comments
 (0)