From: Yubin Zou <yubinz@google.com>
To: qemu-devel@nongnu.org
Cc: "Cédric Le Goater" <clg@kaod.org>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Steven Lee" <steven_lee@aspeedtech.com>,
"Troy Lee" <leetroy@gmail.com>,
"Jamin Lin" <jamin_lin@aspeedtech.com>,
"Andrew Jeffery" <andrew@codeconstruct.com.au>,
"Joel Stanley" <joel@jms.id.au>,
qemu-arm@nongnu.org, "Yubin Zou" <yubinz@google.com>,
"Hao Wu" <wuhaotsh@google.com>
Subject: [PATCH v2 1/3] hw/nvram: Add a new auxiliary function to init at24c eeprom
Date: Thu, 13 Nov 2025 00:43:28 +0000 [thread overview]
Message-ID: <20251113-quanta-q71l-eeproms-v2-1-e72451b974b0@google.com> (raw)
In-Reply-To: <20251113-quanta-q71l-eeproms-v2-0-e72451b974b0@google.com>
From: Hao Wu <wuhaotsh@google.com>
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.
Change-Id: I2f056cc0507d39164335a03bc18b5c94015b4b11
Signed-off-by: Hao Wu <wuhaotsh@google.com>
---
hw/nvram/eeprom_at24c.c | 17 +++++++++++++++++
include/hw/nvram/eeprom_at24c.h | 4 ++++
2 files changed, 21 insertions(+)
diff --git a/hw/nvram/eeprom_at24c.c b/hw/nvram/eeprom_at24c.c
index 82ea97e552a15c8bcd38e38939b53545b01ad273..8542ca2b037d6e896c7b394e7ff4b6ec27297ad7 100644
--- a/hw/nvram/eeprom_at24c.c
+++ b/hw/nvram/eeprom_at24c.c
@@ -17,6 +17,7 @@
#include "hw/qdev-properties.h"
#include "hw/qdev-properties-system.h"
#include "system/block-backend.h"
+#include "system/blockdev.h"
#include "qom/object.h"
/* #define DEBUG_AT24C */
@@ -264,3 +265,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);
+}
diff --git a/include/hw/nvram/eeprom_at24c.h b/include/hw/nvram/eeprom_at24c.h
index acb9857b2adddd1fe5a924652f6ebae13b674b66..fdac7c1c022f9f73307bb3ecf761caa732e999bc 100644
--- a/include/hw/nvram/eeprom_at24c.h
+++ b/include/hw/nvram/eeprom_at24c.h
@@ -36,4 +36,8 @@ I2CSlave *at24c_eeprom_init(I2CBus *bus, uint8_t address, uint32_t rom_size);
I2CSlave *at24c_eeprom_init_rom(I2CBus *bus, uint8_t address, uint32_t rom_size,
const uint8_t *init_rom, uint32_t init_rom_size);
+/* Init one at24c eeprom device */
+void at24c_eeprom_init_one(I2CBus *i2c_bus, int bus, uint8_t addr,
+ uint32_t rsize, int unit_number);
+
#endif
--
2.51.2.1041.gc1ab5b90ca-goog
next prev parent reply other threads:[~2025-11-13 0:45 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-13 0:43 [PATCH v2 0/3] Add drive-backed EEPROM support to quanta-q71l Yubin Zou
2025-11-13 0:43 ` Yubin Zou [this message]
2025-11-13 11:09 ` [PATCH v2 1/3] hw/nvram: Add a new auxiliary function to init at24c eeprom Cédric Le Goater
2025-11-13 0:43 ` [PATCH v2 2/3] hw/arm: add eeproms to quanta-q7l1 board Yubin Zou
2025-11-13 0:43 ` [PATCH v2 3/3] hw/arm: enable eeproms for quanta-q71l Yubin Zou
2025-11-13 5:06 ` [PATCH v2 0/3] Add drive-backed EEPROM support to quanta-q71l Jamin Lin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251113-quanta-q71l-eeproms-v2-1-e72451b974b0@google.com \
--to=yubinz@google.com \
--cc=andrew@codeconstruct.com.au \
--cc=clg@kaod.org \
--cc=jamin_lin@aspeedtech.com \
--cc=joel@jms.id.au \
--cc=leetroy@gmail.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=steven_lee@aspeedtech.com \
--cc=wuhaotsh@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).