qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 1/5] hw/i2c/aspeed_i2c: Simplify aspeed_i2c_get_bus()


From: Cédric Le Goater
Subject: Re: [PATCH 1/5] hw/i2c/aspeed_i2c: Simplify aspeed_i2c_get_bus()
Date: Mon, 13 Jul 2020 14:23:33 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0

On 6/29/20 7:38 PM, Philippe Mathieu-Daudé wrote:
> Simplify aspeed_i2c_get_bus() by using a AspeedI2CState argument.
> 
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

Reviewed-by: Cédric Le Goater <clg@kaod.org>

> ---
>  include/hw/i2c/aspeed_i2c.h |  2 +-
>  hw/arm/aspeed.c             | 70 ++++++++++++++++++-------------------
>  hw/i2c/aspeed_i2c.c         |  3 +-
>  3 files changed, 37 insertions(+), 38 deletions(-)
> 
> diff --git a/include/hw/i2c/aspeed_i2c.h b/include/hw/i2c/aspeed_i2c.h
> index f1b9e5bf91..243789ae5d 100644
> --- a/include/hw/i2c/aspeed_i2c.h
> +++ b/include/hw/i2c/aspeed_i2c.h
> @@ -93,6 +93,6 @@ typedef struct AspeedI2CClass {
>  
>  } AspeedI2CClass;
>  
> -I2CBus *aspeed_i2c_get_bus(DeviceState *dev, int busnr);
> +I2CBus *aspeed_i2c_get_bus(AspeedI2CState *s, int busnr);
>  
>  #endif /* ASPEED_I2C_H */
> diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c
> index 379f9672a5..1285bf82c0 100644
> --- a/hw/arm/aspeed.c
> +++ b/hw/arm/aspeed.c
> @@ -385,13 +385,13 @@ static void palmetto_bmc_i2c_init(AspeedMachineState 
> *bmc)
>  
>      /* The palmetto platform expects a ds3231 RTC but a ds1338 is
>       * enough to provide basic RTC features. Alarms will be missing */
> -    i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 0), "ds1338", 
> 0x68);
> +    i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 0), "ds1338", 0x68);
>  
> -    smbus_eeprom_init_one(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 0), 0x50,
> +    smbus_eeprom_init_one(aspeed_i2c_get_bus(&soc->i2c, 0), 0x50,
>                            eeprom_buf);
>  
>      /* add a TMP423 temperature sensor */
> -    dev = i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 2),
> +    dev = i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 2),
>                             "tmp423", 0x4c);
>      object_property_set_int(OBJECT(dev), 31000, "temperature0", 
> &error_abort);
>      object_property_set_int(OBJECT(dev), 28000, "temperature1", 
> &error_abort);
> @@ -404,16 +404,16 @@ static void ast2500_evb_i2c_init(AspeedMachineState 
> *bmc)
>      AspeedSoCState *soc = &bmc->soc;
>      uint8_t *eeprom_buf = g_malloc0(8 * 1024);
>  
> -    smbus_eeprom_init_one(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 3), 0x50,
> +    smbus_eeprom_init_one(aspeed_i2c_get_bus(&soc->i2c, 3), 0x50,
>                            eeprom_buf);
>  
>      /* The AST2500 EVB expects a LM75 but a TMP105 is compatible */
> -    i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 7),
> +    i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 7),
>                       TYPE_TMP105, 0x4d);
>  
>      /* The AST2500 EVB does not have an RTC. Let's pretend that one is
>       * plugged on the I2C bus header */
> -    i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 11), "ds1338", 
> 0x32);
> +    i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 11), "ds1338", 0x32);
>  }
>  
>  static void ast2600_evb_i2c_init(AspeedMachineState *bmc)
> @@ -428,36 +428,36 @@ static void romulus_bmc_i2c_init(AspeedMachineState 
> *bmc)
>  
>      /* The romulus board expects Epson RX8900 I2C RTC but a ds1338 is
>       * good enough */
> -    i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 11), "ds1338", 
> 0x32);
> +    i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 11), "ds1338", 0x32);
>  }
>  
>  static void swift_bmc_i2c_init(AspeedMachineState *bmc)
>  {
>      AspeedSoCState *soc = &bmc->soc;
>  
> -    i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 3), "pca9552", 
> 0x60);
> +    i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 3), "pca9552", 0x60);
>  
>      /* The swift board expects a TMP275 but a TMP105 is compatible */
> -    i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 7), "tmp105", 
> 0x48);
> +    i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 7), "tmp105", 0x48);
>      /* The swift board expects a pca9551 but a pca9552 is compatible */
> -    i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 7), "pca9552", 
> 0x60);
> +    i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 7), "pca9552", 0x60);
>  
>      /* The swift board expects an Epson RX8900 RTC but a ds1338 is 
> compatible */
> -    i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 8), "ds1338", 
> 0x32);
> -    i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 8), "pca9552", 
> 0x60);
> +    i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 8), "ds1338", 0x32);
> +    i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 8), "pca9552", 0x60);
>  
> -    i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 9), "tmp423", 
> 0x4c);
> +    i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 9), "tmp423", 0x4c);
>      /* The swift board expects a pca9539 but a pca9552 is compatible */
> -    i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 9), "pca9552", 
> 0x74);
> +    i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 9), "pca9552", 0x74);
>  
> -    i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 10), "tmp423", 
> 0x4c);
> +    i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 10), "tmp423", 0x4c);
>      /* The swift board expects a pca9539 but a pca9552 is compatible */
> -    i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 10), "pca9552",
> +    i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 10), "pca9552",
>                       0x74);
>  
>      /* The swift board expects a TMP275 but a TMP105 is compatible */
> -    i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 12), "tmp105", 
> 0x48);
> -    i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 12), "tmp105", 
> 0x4a);
> +    i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 12), "tmp105", 0x48);
> +    i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 12), "tmp105", 0x4a);
>  }
>  
>  static void sonorapass_bmc_i2c_init(AspeedMachineState *bmc)
> @@ -465,32 +465,32 @@ static void sonorapass_bmc_i2c_init(AspeedMachineState 
> *bmc)
>      AspeedSoCState *soc = &bmc->soc;
>  
>      /* bus 2 : */
> -    i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 2), "tmp105", 
> 0x48);
> -    i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 2), "tmp105", 
> 0x49);
> +    i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 2), "tmp105", 0x48);
> +    i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 2), "tmp105", 0x49);
>      /* bus 2 : pca9546 @ 0x73 */
>  
>      /* bus 3 : pca9548 @ 0x70 */
>  
>      /* bus 4 : */
>      uint8_t *eeprom4_54 = g_malloc0(8 * 1024);
> -    smbus_eeprom_init_one(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 4), 0x54,
> +    smbus_eeprom_init_one(aspeed_i2c_get_bus(&soc->i2c, 4), 0x54,
>                            eeprom4_54);
>      /* PCA9539 @ 0x76, but PCA9552 is compatible */
> -    i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 4), "pca9552", 
> 0x76);
> +    i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 4), "pca9552", 0x76);
>      /* PCA9539 @ 0x77, but PCA9552 is compatible */
> -    i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 4), "pca9552", 
> 0x77);
> +    i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 4), "pca9552", 0x77);
>  
>      /* bus 6 : */
> -    i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 6), "tmp105", 
> 0x48);
> -    i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 6), "tmp105", 
> 0x49);
> +    i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 6), "tmp105", 0x48);
> +    i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 6), "tmp105", 0x49);
>      /* bus 6 : pca9546 @ 0x73 */
>  
>      /* bus 8 : */
>      uint8_t *eeprom8_56 = g_malloc0(8 * 1024);
> -    smbus_eeprom_init_one(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 8), 0x56,
> +    smbus_eeprom_init_one(aspeed_i2c_get_bus(&soc->i2c, 8), 0x56,
>                            eeprom8_56);
> -    i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 8), "pca9552", 
> 0x60);
> -    i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 8), "pca9552", 
> 0x61);
> +    i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 8), "pca9552", 0x60);
> +    i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 8), "pca9552", 0x61);
>      /* bus 8 : adc128d818 @ 0x1d */
>      /* bus 8 : adc128d818 @ 0x1f */
>  
> @@ -515,25 +515,25 @@ static void witherspoon_bmc_i2c_init(AspeedMachineState 
> *bmc)
>      /* Bus 3: TODO dps310@76 */
>      dev = i2c_try_create_slave(TYPE_PCA9552, 0x60);
>      qdev_prop_set_string(dev, "description", "pca1");
> -    i2c_realize_and_unref(dev, aspeed_i2c_get_bus(DEVICE(&soc->i2c), 3),
> +    i2c_realize_and_unref(dev, aspeed_i2c_get_bus(&soc->i2c, 3),
>                            &error_fatal);
>  
> -    i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 4), "tmp423", 
> 0x4c);
> -    i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 5), "tmp423", 
> 0x4c);
> +    i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 4), "tmp423", 0x4c);
> +    i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 5), "tmp423", 0x4c);
>  
>      /* The Witherspoon expects a TMP275 but a TMP105 is compatible */
> -    i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 9), TYPE_TMP105,
> +    i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 9), TYPE_TMP105,
>                       0x4a);
>  
>      /* The witherspoon board expects Epson RX8900 I2C RTC but a ds1338 is
>       * good enough */
> -    i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 11), "ds1338", 
> 0x32);
> +    i2c_create_slave(aspeed_i2c_get_bus(&soc->i2c, 11), "ds1338", 0x32);
>  
> -    smbus_eeprom_init_one(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 11), 0x51,
> +    smbus_eeprom_init_one(aspeed_i2c_get_bus(&soc->i2c, 11), 0x51,
>                            eeprom_buf);
>      dev = i2c_try_create_slave(TYPE_PCA9552, 0x60);
>      qdev_prop_set_string(dev, "description", "pca0");
> -    i2c_realize_and_unref(dev, aspeed_i2c_get_bus(DEVICE(&soc->i2c), 11),
> +    i2c_realize_and_unref(dev, aspeed_i2c_get_bus(&soc->i2c, 11),
>                            &error_fatal);
>      /* Bus 11: TODO ucd90160@64 */
>  }
> diff --git a/hw/i2c/aspeed_i2c.c b/hw/i2c/aspeed_i2c.c
> index fb973a983d..518a3f5c6f 100644
> --- a/hw/i2c/aspeed_i2c.c
> +++ b/hw/i2c/aspeed_i2c.c
> @@ -959,9 +959,8 @@ static void aspeed_i2c_register_types(void)
>  type_init(aspeed_i2c_register_types)
>  
>  
> -I2CBus *aspeed_i2c_get_bus(DeviceState *dev, int busnr)
> +I2CBus *aspeed_i2c_get_bus(AspeedI2CState *s, int busnr)
>  {
> -    AspeedI2CState *s = ASPEED_I2C(dev);
>      AspeedI2CClass *aic = ASPEED_I2C_GET_CLASS(s);
>      I2CBus *bus = NULL;
>  
> 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]