diff --git a/hw/i2c/core.c b/hw/i2c/core.c
index abb3efb..53069dd 100644
--- a/hw/i2c/core.c
+++ b/hw/i2c/core.c
@@ -101,15 +101,17 @@ int i2c_start_transfer(I2CBus *bus, uint8_t address, int
recv)
bus->broadcast = true;
}
- QTAILQ_FOREACH(kid, &bus->qbus.children, sibling) {
- DeviceState *qdev = kid->child;
- I2CSlave *candidate = I2C_SLAVE(qdev);
- if ((candidate->address == address) || (bus->broadcast)) {
- node = g_malloc(sizeof(struct I2CNode));
- node->elt = candidate;
- QLIST_INSERT_HEAD(&bus->current_devs, node, next);
- if (!bus->broadcast) {
- break;
+ if (recv != I2C_START_CONTINUED_READ_TRANSFER) {
+ QTAILQ_FOREACH(kid, &bus->qbus.children, sibling) {
+ DeviceState *qdev = kid->child;
+ I2CSlave *candidate = I2C_SLAVE(qdev);
+ if ((candidate->address == address) || (bus->broadcast)) {
+ node = g_malloc(sizeof(struct I2CNode));
+ node->elt = candidate;
+ QLIST_INSERT_HEAD(&bus->current_devs, node, next);
+ if (!bus->broadcast) {
+ break;
+ }
}
}
}
@@ -134,10 +136,6 @@ void i2c_end_transfer(I2CBus *bus)
I2CSlaveClass *sc;
I2CNode *node, *next;
- if (QLIST_EMPTY(&bus->current_devs)) {
- return;
- }
-
QLIST_FOREACH_SAFE(node, &bus->current_devs, next, next) {
sc = I2C_SLAVE_GET_CLASS(node->elt);
if (sc->event) {
diff --git a/hw/i2c/smbus.c b/hw/i2c/smbus.c
index 3979b3d..f63799d 100644
--- a/hw/i2c/smbus.c
+++ b/hw/i2c/smbus.c
@@ -222,7 +222,7 @@ int smbus_receive_byte(I2CBus *bus, uint8_t addr)
{
uint8_t data;
- if (i2c_start_transfer(bus, addr, 1)) {
+ if (i2c_start_transfer(bus, addr, I2C_START_READ_TRANSFER)) {
return -1;
}
data = i2c_recv(bus);
@@ -233,7 +233,7 @@ int smbus_receive_byte(I2CBus *bus, uint8_t addr)
int smbus_send_byte(I2CBus *bus, uint8_t addr, uint8_t data)
{
- if (i2c_start_transfer(bus, addr, 0)) {
+ if (i2c_start_transfer(bus, addr, I2C_START_WRITE_TRANSFER)) {
return -1;
}
i2c_send(bus, data);
@@ -244,11 +244,11 @@ int smbus_send_byte(I2CBus *bus, uint8_t addr, uint8_t
data)
int smbus_read_byte(I2CBus *bus, uint8_t addr, uint8_t command)
{
uint8_t data;
- if (i2c_start_transfer(bus, addr, 0)) {
+ if (i2c_start_transfer(bus, addr, I2C_START_WRITE_TRANSFER)) {
return -1;
}
i2c_send(bus, command);
- i2c_start_transfer(bus, addr, 1);
+ i2c_start_transfer(bus, addr, I2C_START_CONTINUED_READ_TRANSFER);
data = i2c_recv(bus);
i2c_nack(bus);
i2c_end_transfer(bus);
@@ -257,7 +257,7 @@ int smbus_read_byte(I2CBus *bus, uint8_t addr, uint8_t
command)
int smbus_write_byte(I2CBus *bus, uint8_t addr, uint8_t command, uint8_t data)
{
- if (i2c_start_transfer(bus, addr, 0)) {
+ if (i2c_start_transfer(bus, addr, I2C_START_WRITE_TRANSFER)) {
return -1;
}
i2c_send(bus, command);
@@ -269,11 +269,11 @@ int smbus_write_byte(I2CBus *bus, uint8_t addr, uint8_t
command, uint8_t data)
int smbus_read_word(I2CBus *bus, uint8_t addr, uint8_t command)
{
uint16_t data;
- if (i2c_start_transfer(bus, addr, 0)) {
+ if (i2c_start_transfer(bus, addr, I2C_START_WRITE_TRANSFER)) {
return -1;
}
i2c_send(bus, command);
- i2c_start_transfer(bus, addr, 1);
+ i2c_start_transfer(bus, addr, I2C_START_CONTINUED_READ_TRANSFER);
data = i2c_recv(bus);
data |= i2c_recv(bus) << 8;
i2c_nack(bus);
@@ -283,7 +283,7 @@ int smbus_read_word(I2CBus *bus, uint8_t addr, uint8_t
command)
int smbus_write_word(I2CBus *bus, uint8_t addr, uint8_t command, uint16_t
data)
{
- if (i2c_start_transfer(bus, addr, 0)) {
+ if (i2c_start_transfer(bus, addr, I2C_START_WRITE_TRANSFER)) {
return -1;
}
i2c_send(bus, command);
@@ -298,11 +298,11 @@ int smbus_read_block(I2CBus *bus, uint8_t addr, uint8_t
command, uint8_t *data)
int len;
int i;
- if (i2c_start_transfer(bus, addr, 0)) {
+ if (i2c_start_transfer(bus, addr, I2C_START_WRITE_TRANSFER)) {
return -1;
}
i2c_send(bus, command);
- i2c_start_transfer(bus, addr, 1);
+ i2c_start_transfer(bus, addr, I2C_START_CONTINUED_READ_TRANSFER);
len = i2c_recv(bus);
if (len > 32) {
len = 0;
@@ -323,7 +323,7 @@ int smbus_write_block(I2CBus *bus, uint8_t addr, uint8_t
command, uint8_t *data,
if (len > 32)
len = 32;
- if (i2c_start_transfer(bus, addr, 0)) {
+ if (i2c_start_transfer(bus, addr, I2C_START_WRITE_TRANSFER)) {
return -1;
}
i2c_send(bus, command);
diff --git a/include/hw/i2c/i2c.h b/include/hw/i2c/i2c.h
index c4085aa..16c910e 100644
--- a/include/hw/i2c/i2c.h
+++ b/include/hw/i2c/i2c.h
@@ -50,6 +50,15 @@ struct I2CSlave
uint8_t address;
};
+/* For the recv value in i2c_start_transfer. The first two values
+ correspond to false and true for the recv value. The third is a
+ special value that is used to tell i2c_start_transfer that this is
+ a continuation of the previous transfer, so don't rescan the bus
+ for devices to send to, continue with the current set of devices. */