qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 17/19] i2c: Allow SMBus device to NAK start events


From: minyard
Subject: [Qemu-devel] [PATCH 17/19] i2c: Allow SMBus device to NAK start events
Date: Fri, 30 Dec 2016 09:21:48 -0600

From: Corey Minyard <address@hidden>

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

Signed-off-by: Corey Minyard <address@hidden>
---
 hw/i2c/smbus.c         | 11 +++++++++++
 include/hw/i2c/smbus.h |  2 ++
 2 files changed, 13 insertions(+)

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);
-- 
2.7.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]