From 9618ebae453f2492a60e741d40f5212103f48ad3 Mon Sep 17 00:00:00 2001 From: Peter Delevoryas Date: Tue, 7 Feb 2023 09:02:04 +0100 Subject: hw/arm: Extract at24c_eeprom_init helper from Aspeed and Nuvoton boards MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This helper is useful in board initialization because lets users initialize and realize an EEPROM on an I2C bus with a single function call. Signed-off-by: Peter Delevoryas Reviewed-by: Cédric Le Goater Reviewed-by: Joel Stanley Reviewed-by: Corey Minyard Link: https://lore.kernel.org/r/20230128060543.95582-2-peter@pjd.dev Signed-off-by: Cédric Le Goater --- hw/nvram/eeprom_at24c.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'hw/nvram') diff --git a/hw/nvram/eeprom_at24c.c b/hw/nvram/eeprom_at24c.c index 2d4d8b9..98857e3 100644 --- a/hw/nvram/eeprom_at24c.c +++ b/hw/nvram/eeprom_at24c.c @@ -12,6 +12,7 @@ #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" @@ -128,6 +129,17 @@ int at24c_eeprom_send(I2CSlave *s, uint8_t data) return 0; } +I2CSlave *at24c_eeprom_init(I2CBus *bus, uint8_t address, uint32_t rom_size) +{ + I2CSlave *i2c_dev = i2c_slave_new(TYPE_AT24C_EE, address); + DeviceState *dev = DEVICE(i2c_dev); + + qdev_prop_set_uint32(dev, "rom-size", rom_size); + i2c_slave_realize_and_unref(i2c_dev, bus, &error_abort); + + return i2c_dev; +} + static void at24c_eeprom_realize(DeviceState *dev, Error **errp) { EEPROMState *ee = AT24C_EE(dev); -- cgit v1.1