From: Titus Rwantare <titusr@google.com>
To: peter.maydell@linaro.org
Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, kfting@nuvoton.com,
imaginos32@gmail.com, wuhaotsh@google.com, philmd@mailo.com,
titusr <titusr@google.com>
Subject: [PATCH 3/5] hw/i2c: pmbus: clear output buffer on write
Date: Mon, 6 Jul 2026 23:00:52 +0000 [thread overview]
Message-ID: <20260706230056.1888992-4-titusr@google.com> (raw)
In-Reply-To: <20260706230056.1888992-1-titusr@google.com>
From: titusr <titusr@google.com>
Generally we expect a PMBus sensor to issue writes after all pending
reads have completed. If a data read needs to be resumed, this state can
be tracked in the device model and the pending data placed in the output
buffer.
Signed-off-by: Titus Rwantare <titusr@google.com>
---
hw/i2c/pmbus_device.c | 10 ++++++++++
tests/qtest/adm1266-test.c | 10 ++++++----
2 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/hw/i2c/pmbus_device.c b/hw/i2c/pmbus_device.c
index e2e1e0e945..8befc27895 100644
--- a/hw/i2c/pmbus_device.c
+++ b/hw/i2c/pmbus_device.c
@@ -1284,6 +1284,16 @@ static int pmbus_write_data(SMBusDevice *smd, uint8_t *buf, uint8_t len)
pmdev->in_buf_len = len;
pmdev->in_buf = buf;
+ /* clear the output buffer on any new write transaction */
+ if (pmdev->out_buf_len != 0) {
+ qemu_log_mask(LOG_GUEST_ERROR,
+ "%s: previous read was not completed, %d bytes dropped\n",
+ __func__, pmdev->out_buf_len);
+
+ pmdev->out_buf_len = 0;
+ memset(pmdev->out_buf, 0, sizeof(pmdev->out_buf));
+ }
+
pmdev->code = buf[0]; /* PMBus command code */
if (pmdev->code == PMBUS_CLEAR_FAULTS) {
diff --git a/tests/qtest/adm1266-test.c b/tests/qtest/adm1266-test.c
index 5ae8206234..726e475938 100644
--- a/tests/qtest/adm1266-test.c
+++ b/tests/qtest/adm1266-test.c
@@ -48,11 +48,13 @@
static void compare_string(QI2CDevice *i2cdev, uint8_t reg,
const char *test_str)
{
- uint8_t len = i2c_get8(i2cdev, reg);
- char i2c_str[SMBUS_DATA_MAX_LEN] = {0};
+ uint8_t expected_len = strlen(test_str);
+ uint8_t resp[SMBUS_DATA_MAX_LEN] = {0};
- i2c_read_block(i2cdev, reg, (uint8_t *)i2c_str, len);
- g_assert_cmpstr(i2c_str, ==, test_str);
+ g_assert(expected_len + 1 < SMBUS_DATA_MAX_LEN);
+ i2c_read_block(i2cdev, reg, resp, expected_len + 1);
+ g_assert_cmpint(resp[0], ==, expected_len);
+ g_assert_cmpstr((char *)resp + 1, ==, test_str);
}
static void write_and_compare_string(QI2CDevice *i2cdev, uint8_t reg,
--
2.55.0.rc2.803.g1fd1e6609c-goog
next prev parent reply other threads:[~2026-07-06 23:02 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-06 23:00 [PATCH 0/5] hw/i2c: PMBus updates Titus Rwantare
2026-07-06 23:00 ` [PATCH 1/5] osdep: add DIV_ROUND_CLOSEST Titus Rwantare
2026-07-09 11:09 ` Peter Maydell
2026-07-09 11:16 ` Peter Maydell
2026-07-06 23:00 ` [PATCH 2/5] hw/i2c: pmbus: add milliunits linear mode functions Titus Rwantare
2026-07-06 23:00 ` Titus Rwantare [this message]
2026-07-07 9:20 ` [PATCH 3/5] hw/i2c: pmbus: clear output buffer on write Philippe Mathieu-Daudé
2026-07-09 15:35 ` Peter Maydell
2026-07-06 23:00 ` [PATCH 4/5] hw/i2c: smbus: increase MAX_DATA_LEN Titus Rwantare
2026-07-07 9:18 ` Philippe Mathieu-Daudé
2026-07-09 11:25 ` Peter Maydell
2026-07-06 23:00 ` [PATCH 5/5] hw/i2c: pmbus: add Linear11 format helpers Titus Rwantare
2026-07-09 11:14 ` Peter Maydell
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=20260706230056.1888992-4-titusr@google.com \
--to=titusr@google.com \
--cc=imaginos32@gmail.com \
--cc=kfting@nuvoton.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@mailo.com \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--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 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.