diff mbox

[17/19] i2c: Allow SMBus device to NAK start events

Message ID 1483111310-24808-18-git-send-email-minyard@acm.org
State New
Headers show

Commit Message

Corey Minyard Dec. 30, 2016, 3:21 p.m. UTC
From: Corey Minyard <cminyard@mvista.com>


The I2C code has been modified to allow devices to NAK start
events, the SMBus code should, too.

Signed-off-by: Corey Minyard <cminyard@mvista.com>

---
 hw/i2c/smbus.c         | 11 +++++++++++
 include/hw/i2c/smbus.h |  2 ++
 2 files changed, 13 insertions(+)

-- 
2.7.4
diff mbox

Patch

diff --git a/hw/i2c/smbus.c b/hw/i2c/smbus.c
index 4cb651e..87a1669 100644
--- a/hw/i2c/smbus.c
+++ b/hw/i2c/smbus.c
@@ -71,6 +71,17 @@  static int smbus_i2c_event(I2CSlave *s, enum i2c_event event)
 {
     SMBusDevice *dev = SMBUS_DEVICE(s);
 
+    if (event == I2C_START_SEND || event == I2C_START_RECV) {
+        /* Allow the device to NAK the start event. */
+        SMBusDeviceClass *sc = SMBUS_DEVICE_GET_CLASS(dev);
+
+        if (sc->event) {
+            int rv = sc->event(dev, event);
+            if (rv)
+                return rv;
+        }
+    }
+
     switch (event) {
     case I2C_START_SEND:
         switch (dev->mode) {
diff --git a/include/hw/i2c/smbus.h b/include/hw/i2c/smbus.h
index f1b8078..fc995eb 100644
--- a/include/hw/i2c/smbus.h
+++ b/include/hw/i2c/smbus.h
@@ -39,6 +39,8 @@  typedef struct SMBusDeviceClass
 {
     I2CSlaveClass parent_class;
     int (*init)(SMBusDevice *dev);
+    /* Allow the device to get start and stop events so they can NAK them. */
+    int (*event)(SMBusDevice *dev, enum i2c_event event);
     void (*quick_cmd)(SMBusDevice *dev, uint8_t read);
     void (*send_byte)(SMBusDevice *dev, uint8_t val);
     uint8_t (*receive_byte)(SMBusDevice *dev);