hw/i2c: pmbus: clear output buffer on write
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> Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> Message-id: 20260706230056.1888992-4-titusr@google.com Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
titusr committed
Jul 13, 2026 at 12:34 UTC
79d586d021baf51dd4c6c1383cc53543c5fa957b
2 files changed
+16
-4
hw/i2c/pmbus_device.c
+10
@@ -1245,6 +1245,16 @@ static int pmbus_write_data(SMBusDevice *smd, uint8_t *buf, uint8_t len)
1245
pmdev->in_buf_len = len;
1246
pmdev->in_buf = buf;
1247
1248
+ /* clear the output buffer on any new write transaction */
1249
+ if (pmdev->out_buf_len != 0) {
1250
+ qemu_log_mask(LOG_GUEST_ERROR,
1251
+ "%s: previous read was not completed, %d bytes dropped\n",
1252
+ __func__, pmdev->out_buf_len);
1253
+
1254
+ pmdev->out_buf_len = 0;
1255
+ memset(pmdev->out_buf, 0, sizeof(pmdev->out_buf));
1256
+ }
1257
+
1258
pmdev->code = buf[0]; /* PMBus command code */
1259
1260
if (pmdev->code == PMBUS_CLEAR_FAULTS) {
tests/qtest/adm1266-test.c
+6
-4
@@ -48,11 +48,13 @@
48
static void compare_string(QI2CDevice *i2cdev, uint8_t reg,
49
const char *test_str)
50
{
51
- uint8_t len = i2c_get8(i2cdev, reg);
52
- char i2c_str[SMBUS_DATA_MAX_LEN] = {0};
51
+ uint8_t expected_len = strlen(test_str);
52
+ uint8_t resp[SMBUS_DATA_MAX_LEN] = {0};
53
54
- i2c_read_block(i2cdev, reg, (uint8_t *)i2c_str, len);
55
- g_assert_cmpstr(i2c_str, ==, test_str);
54
+ g_assert(expected_len + 1 < SMBUS_DATA_MAX_LEN);
55
+ i2c_read_block(i2cdev, reg, resp, expected_len + 1);
56
+ g_assert_cmpint(resp[0], ==, expected_len);
57
+ g_assert_cmpstr((char *)resp + 1, ==, test_str);
58
}
59
60
static void write_and_compare_string(QI2CDevice *i2cdev, uint8_t reg,