diff mbox

[1/2] i2c: Add flag to NACK I2C transfers when busy

Message ID 20161123194605.94717-2-flus@cesar.org.br
State New
Headers show

Commit Message

Fabio Urquiza Nov. 23, 2016, 7:46 p.m. UTC
Add a busy flag on the I2CSlave struct which the device could set to NACK
I2C transfer requests during the execution of the event handling function.
If the busy flag is set, i2c_start_transfer() shall return 1.

Signed-off-by: Fabio Urquiza <flus@cesar.org.br>
---
 hw/i2c/core.c        | 3 +++
 include/hw/i2c/i2c.h | 1 +
 2 files changed, 4 insertions(+)
diff mbox

Patch

diff --git a/hw/i2c/core.c b/hw/i2c/core.c
index abd4c4c..438233c 100644
--- a/hw/i2c/core.c
+++ b/hw/i2c/core.c
@@ -142,6 +142,9 @@  int i2c_start_transfer(I2CBus *bus, uint8_t address, int recv)
            start condition.  */
         if (sc->event) {
             sc->event(node->elt, recv ? I2C_START_RECV : I2C_START_SEND);
+            if (node->elt->busy) {
+                return -1;
+            }
         }
     }
     return 0;
diff --git a/include/hw/i2c/i2c.h b/include/hw/i2c/i2c.h
index c4085aa..9c6b1ce 100644
--- a/include/hw/i2c/i2c.h
+++ b/include/hw/i2c/i2c.h
@@ -48,6 +48,7 @@  struct I2CSlave
 
     /* Remaining fields for internal use by the I2C code.  */
     uint8_t address;
+    uint8_t busy;
 };
 
 I2CBus *i2c_init_bus(DeviceState *parent, const char *name);