Skip to contentSkip to conversation

fix I2C slave addressing

PATCH In review Juha Riihimäki 2 participants 2 messages Jun 8, 2009 – Oct 29, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix I2C slave addressing

With the recent device handling changes the I2C slave addressing code was broken. With current code, if a slave with the correct address is not found on the bus the last scanned slave on the bus will be addressed. This is wrong. Please find attached a patch to fix it.

---

hw/i2c.c +4 -2
index 8a0c4d7..e1dacef 100644
@@ -69,9 +69,11 @@ int i2c_start_transfer(i2c_bus *bus, int address, int recv)
     i2c_slave *slave = NULL;
 
     LIST_FOREACH(qdev, &bus->qbus.children, sibling) {
-        slave = I2C_SLAVE_FROM_QDEV(qdev);
-        if (slave->address == address)
+        i2c_slave *candidate = I2C_SLAVE_FROM_QDEV(qdev);
+        if (candidate->address == address) {
+            slave = candidate;
             break;
+        }
     }
 
     if (!slave)
hw/i2c.c +4 -2
index 8a0c4d7..e1dacef 100644
@@ -69,9 +69,11 @@ int i2c_start_transfer(i2c_bus *bus, int address, int recv)
     i2c_slave *slave = NULL;
 
     LIST_FOREACH(qdev, &bus->qbus.children, sibling) {
-        slave = I2C_SLAVE_FROM_QDEV(qdev);
-        if (slave->address == address)
+        i2c_slave *candidate = I2C_SLAVE_FROM_QDEV(qdev);
+        if (candidate->address == address) {
+            slave = candidate;
             break;
+        }
     }
 
     if (!slave)
Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Juha Riihimäki

With the recent device handling changes the I2C slave addressing code was broken. With current code, if a slave with the correct address is not found on the bus the last scanned slave on the bus will be addressed. This is wrong. Please find attached a patch to fix it.

Without this patch, n800/n810 emulation fails to boot.

Quoted 21 lines

---

hw/i2c.c +4 -2
index 8a0c4d7..e1dacef 100644
@@ -69,9 +69,11 @@ int i2c_start_transfer(i2c_bus *bus, int address, int 
 recv)
     i2c_slave *slave = NULL;
 
     LIST_FOREACH(qdev, &bus->qbus.children, sibling) {
-        slave = I2C_SLAVE_FROM_QDEV(qdev);
-        if (slave->address == address)
+        i2c_slave *candidate = I2C_SLAVE_FROM_QDEV(qdev);
+        if (candidate->address == address) {
+            slave = candidate;
             break;
+        }
     }
 
     if (!slave)