qemu-devel
[Top][All Lists]
Advanced

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

Re: [PATCH 5/7] hw/nvram: Add a new auxiliary function to init at24c eep


From: Peter Maydell
Subject: Re: [PATCH 5/7] hw/nvram: Add a new auxiliary function to init at24c eeprom
Date: Thu, 19 Aug 2021 14:59:06 +0100

On Sat, 14 Aug 2021 at 00:34, Hao Wu <wuhaotsh@google.com> wrote:
>
> In NPCM7xx boards, at24c eeproms are backed by drives. However,
> these drives use unit number as unique identifier. So if we
> specify two drives with the same unit number, error will occured:
> `Device with id 'none85' exists`.
>
> Instead of using i2c address as unit number, we now assign unique
> unit numbers for each eeproms in each board. This avoids conflict
> in providing multiple eeprom contents with the same address.
>
> We add an auxiliary function in the at24c eeprom module for this.
> This allows it to easily add at24c eeprom to non-nuvoton boards
> like aspeed as well.
>
> Signed-off-by: Hao Wu <wuhaotsh@google.com>
> Reviewed-by: Patrick Venture<venture@google.com>
> ---
>  hw/nvram/eeprom_at24c.c         | 18 ++++++++++++++++++
>  include/hw/nvram/eeprom_at24c.h | 13 +++++++++++++
>  2 files changed, 31 insertions(+)
>  create mode 100644 include/hw/nvram/eeprom_at24c.h
>
> diff --git a/hw/nvram/eeprom_at24c.c b/hw/nvram/eeprom_at24c.c
> index af6f5dbb99..a9e3702b00 100644
> --- a/hw/nvram/eeprom_at24c.c
> +++ b/hw/nvram/eeprom_at24c.c
> @@ -12,9 +12,11 @@
>  #include "qapi/error.h"
>  #include "qemu/module.h"
>  #include "hw/i2c/i2c.h"
> +#include "hw/nvram/eeprom_at24c.h"
>  #include "hw/qdev-properties.h"
>  #include "hw/qdev-properties-system.h"
>  #include "sysemu/block-backend.h"
> +#include "sysemu/blockdev.h"
>  #include "qom/object.h"
>
>  /* #define DEBUG_AT24C */
> @@ -205,3 +207,19 @@ static void at24c_eeprom_register(void)
>  }
>
>  type_init(at24c_eeprom_register)
> +
> +void at24c_eeprom_init_one(I2CBus *i2c_bus, int bus, uint8_t addr,
> +                           uint32_t rsize, int unit_number)
> +{
> +    I2CSlave *i2c_dev = i2c_slave_new("at24c-eeprom", addr);
> +    DeviceState *dev = DEVICE(i2c_dev);
> +    BlockInterfaceType type = IF_NONE;
> +    DriveInfo *dinfo;
> +
> +    dinfo = drive_get(type, bus, unit_number);
> +    if (dinfo) {
> +        qdev_prop_set_drive(dev, "drive", blk_by_legacy_dinfo(dinfo));
> +    }
> +    qdev_prop_set_uint32(dev, "rom-size", rsize);
> +    i2c_slave_realize_and_unref(i2c_dev, i2c_bus, &error_abort);
> +}

This is just creating a device and configuring it, right?
We tend to prefer that this is just done directly in the
board or SoC code these days, rather than providing helper functions
for it.

If you don't like what hw/arm/npcm7xx_boards.c:at24c_eeprom_init()
is currently doing, you should just patch it to do something different.

thanks
-- PMM



reply via email to

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