From: "Cédric Le Goater" <clg@kaod.org>
To: qemu-arm@nongnu.org, qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
"Joel Stanley" <joel@jms.id.au>,
"Andrew Jeffery" <andrew@aj.id.au>,
"Sittisak Sinprem" <ssinprem@celestica.com>,
"Peter Delevoryas" <peter@pjd.dev>,
"Cédric Le Goater" <clg@kaod.org>
Subject: [PATCH v2 07/11] hw/at24c : modify at24c to support 1 byte address mode
Date: Wed, 1 Mar 2023 17:56:15 +0100 [thread overview]
Message-ID: <20230301165619.2171090-8-clg@kaod.org> (raw)
In-Reply-To: <20230301165619.2171090-1-clg@kaod.org>
From: Sittisak Sinprem <ssinprem@celestica.com>
Signed-off-by: Sittisak Sinprem <ssinprem@celestica.com>
Reviewed-by: Peter Delevoryas <peter@pjd.dev>
[ clg: checkpatch issues ]
Message-Id: <167660539263.10409.9736070122710923479-1@git.sr.ht>
Signed-off-by: Cédric Le Goater <clg@kaod.org>
---
hw/nvram/eeprom_at24c.c | 30 +++++++++++++++++++++++++++---
1 file changed, 27 insertions(+), 3 deletions(-)
diff --git a/hw/nvram/eeprom_at24c.c b/hw/nvram/eeprom_at24c.c
index 3328c32814..613c4929e3 100644
--- a/hw/nvram/eeprom_at24c.c
+++ b/hw/nvram/eeprom_at24c.c
@@ -41,6 +41,13 @@ struct EEPROMState {
uint16_t cur;
/* total size in bytes */
uint32_t rsize;
+ /*
+ * address byte number
+ * for 24c01, 24c02 size <= 256 byte, use only 1 byte
+ * otherwise size > 256, use 2 byte
+ */
+ uint8_t asize;
+
bool writable;
/* cells changed since last START? */
bool changed;
@@ -91,7 +98,11 @@ uint8_t at24c_eeprom_recv(I2CSlave *s)
EEPROMState *ee = AT24C_EE(s);
uint8_t ret;
- if (ee->haveaddr == 1) {
+ /*
+ * If got the byte address but not completely with address size
+ * will return the invalid value
+ */
+ if (ee->haveaddr > 0 && ee->haveaddr < ee->asize) {
return 0xff;
}
@@ -108,11 +119,11 @@ int at24c_eeprom_send(I2CSlave *s, uint8_t data)
{
EEPROMState *ee = AT24C_EE(s);
- if (ee->haveaddr < 2) {
+ if (ee->haveaddr < ee->asize) {
ee->cur <<= 8;
ee->cur |= data;
ee->haveaddr++;
- if (ee->haveaddr == 2) {
+ if (ee->haveaddr == ee->asize) {
ee->cur %= ee->rsize;
DPRINTK("Set pointer %04x\n", ee->cur);
}
@@ -199,6 +210,18 @@ static void at24c_eeprom_realize(DeviceState *dev, Error **errp)
}
DPRINTK("Reset read backing file\n");
}
+
+ /*
+ * If address size didn't define with property set
+ * value is 0 as default, setting it by Rom size detecting.
+ */
+ if (ee->asize == 0) {
+ if (ee->rsize <= 256) {
+ ee->asize = 1;
+ } else {
+ ee->asize = 2;
+ }
+ }
}
static
@@ -213,6 +236,7 @@ void at24c_eeprom_reset(DeviceState *state)
static Property at24c_eeprom_props[] = {
DEFINE_PROP_UINT32("rom-size", EEPROMState, rsize, 0),
+ DEFINE_PROP_UINT8("address-size", EEPROMState, asize, 0),
DEFINE_PROP_BOOL("writable", EEPROMState, writable, true),
DEFINE_PROP_DRIVE("drive", EEPROMState, blk),
DEFINE_PROP_END_OF_LIST()
--
2.39.2
next prev parent reply other threads:[~2023-03-01 16:57 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-01 16:56 [PATCH v2 00/11] aspeed queue Cédric Le Goater
2023-03-01 16:56 ` [PATCH v2 01/11] readline: fix hmp completion issue Cédric Le Goater
2023-03-01 16:56 ` [PATCH v2 02/11] hw/i2c: only schedule pending master when bus is idle Cédric Le Goater
2023-03-01 16:56 ` [PATCH v2 03/11] hw/misc: add a toy i2c echo device Cédric Le Goater
2023-08-22 17:20 ` Thomas Huth
2023-08-23 7:14 ` Klaus Jensen
2023-03-01 16:56 ` [PATCH v2 04/11] tests/avocado/machine_aspeed.py: Add an I2C slave test Cédric Le Goater
2023-03-01 17:44 ` Philippe Mathieu-Daudé
2023-03-01 16:56 ` [PATCH v2 05/11] hw/arm/aspeed: Adding new machine Yosemitev2 in QEMU Cédric Le Goater
2023-03-01 16:56 ` [PATCH v2 06/11] hw/arm/aspeed: Adding new machine Tiogapass " Cédric Le Goater
2023-03-01 16:56 ` Cédric Le Goater [this message]
2023-03-01 16:56 ` [PATCH v2 08/11] aspeed/fuji : correct the eeprom size Cédric Le Goater
2023-03-01 16:56 ` [PATCH v2 09/11] aspeed: Introduce a spi_boot region under the SoC Cédric Le Goater
2023-03-01 17:52 ` Philippe Mathieu-Daudé
2023-03-02 9:02 ` Cédric Le Goater
2023-03-01 16:56 ` [PATCH v2 10/11] aspeed: Add a boot_rom overlap region in the SoC spi_boot container Cédric Le Goater
2023-03-01 16:56 ` [PATCH v2 11/11] aspeed/smc: Replace SysBus IRQs with GPIO lines Cédric Le Goater
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=20230301165619.2171090-8-clg@kaod.org \
--to=clg@kaod.org \
--cc=andrew@aj.id.au \
--cc=joel@jms.id.au \
--cc=peter.maydell@linaro.org \
--cc=peter@pjd.dev \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=ssinprem@celestica.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.