aboutsummaryrefslogtreecommitdiff
path: root/hw/nvram
diff options
context:
space:
mode:
authorPeter Delevoryas <peter@pjd.dev>2023-02-07 09:02:04 +0100
committerCédric Le Goater <clg@kaod.org>2023-02-07 09:02:04 +0100
commit9618ebae453f2492a60e741d40f5212103f48ad3 (patch)
tree58271d4186260f525d0b841d4a70390c86b71a67 /hw/nvram
parentddbf7bd73c9c79dc48f5981100876242df533d8e (diff)
downloadqemu-9618ebae453f2492a60e741d40f5212103f48ad3.zip
qemu-9618ebae453f2492a60e741d40f5212103f48ad3.tar.gz
qemu-9618ebae453f2492a60e741d40f5212103f48ad3.tar.bz2
hw/arm: Extract at24c_eeprom_init helper from Aspeed and Nuvoton boards
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 <peter@pjd.dev> Reviewed-by: Cédric Le Goater <clg@kaod.org> Reviewed-by: Joel Stanley <joel@jms.id.au> Reviewed-by: Corey Minyard <cminyard@mvista.com> Link: https://lore.kernel.org/r/20230128060543.95582-2-peter@pjd.dev Signed-off-by: Cédric Le Goater <clg@kaod.org>
Diffstat (limited to 'hw/nvram')
-rw-r--r--hw/nvram/eeprom_at24c.c12
1 files changed, 12 insertions, 0 deletions
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);