@samitouri / QOSamiQemu / commits / c94d1459d4

tests: Check whether the I2C master flag is set

Replace the 'once' variable with a check for whether the master flag is set so that the flag can be set when needed. Reviewed-by: Arun Menon <armenon@redhat.com> Link: https://lore.kernel.org/qemu-devel/20260429121743.1346635-6-stefanb@linux.ibm.com Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>

Stefan Berger committed Apr 29, 2026 at 12:17 UTC c94d1459d4010f9f554740ef69e036c28560975b
1 file changed +6 -3
tests/qtest/qtest_aspeed.c
+6 -3
@@ -15,18 +15,21 @@
15 #include "qtest_aspeed.h"
16 #include "hw/i2c/aspeed_i2c.h"
17
18 +static bool aspeed_i2c_is_master_enabled(QTestState *s, uint32_t baseaddr)
19 +{
20 + return qtest_readl(s, baseaddr + A_I2CC_FUN_CTRL) & A_I2CD_MASTER_EN;
21 +}
22 +
23 static void aspeed_i2c_startup(QTestState *s, uint32_t baseaddr,
24 uint8_t slave_addr, uint8_t reg)
25 {
26 uint32_t v;
22 - static int once;
27
24 - if (!once) {
28 + if (!aspeed_i2c_is_master_enabled(s, baseaddr)) {
29 /* one time: enable master */
30 qtest_writel(s, baseaddr + A_I2CC_FUN_CTRL, 0);
31 v = qtest_readl(s, baseaddr + A_I2CC_FUN_CTRL) | A_I2CD_MASTER_EN;
32 qtest_writel(s, baseaddr + A_I2CC_FUN_CTRL, v);
29 - once = 1;
33 }
34
35 /* select device */