diff options
author | Corey Minyard | 2018-11-30 20:20:12 +0100 |
---|---|---|
committer | Corey Minyard | 2019-02-28 04:06:08 +0100 |
commit | 905cec6d11088e585fcedb3fd606510959ee50ff (patch) | |
tree | 72a23061b2a05e7fa89068afe89847c202ca6244 /hw/i2c/smbus_slave.c | |
parent | i2c: Don't check return value from i2c_recv() (diff) | |
download | qemu-905cec6d11088e585fcedb3fd606510959ee50ff.tar.gz qemu-905cec6d11088e585fcedb3fd606510959ee50ff.tar.xz qemu-905cec6d11088e585fcedb3fd606510959ee50ff.zip |
i2c:smbus: Correct the working of quick commands
The logic of handling quick SMBus commands was wrong. If you get a
finish event with no data, that's a quick command.
Document the quick command while we are at it.
Signed-off-by: Corey Minyard <cminyard@mvista.com>
Diffstat (limited to 'hw/i2c/smbus_slave.c')
-rw-r--r-- | hw/i2c/smbus_slave.c | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/hw/i2c/smbus_slave.c b/hw/i2c/smbus_slave.c index 6e4d542f51..6a89a286e3 100644 --- a/hw/i2c/smbus_slave.c +++ b/hw/i2c/smbus_slave.c @@ -54,9 +54,7 @@ static void smbus_do_write(SMBusDevice *dev) { SMBusDeviceClass *sc = SMBUS_DEVICE_GET_CLASS(dev); - if (dev->data_len == 0) { - smbus_do_quick_cmd(dev, 0); - } else if (dev->data_len == 1) { + if (dev->data_len == 1) { DPRINTF("Send Byte\n"); if (sc->send_byte) { sc->send_byte(dev, dev->data_buf[0]); @@ -120,19 +118,24 @@ static int smbus_i2c_event(I2CSlave *s, enum i2c_event event) break; case I2C_FINISH: - switch (dev->mode) { - case SMBUS_WRITE_DATA: - smbus_do_write(dev); - break; - case SMBUS_RECV_BYTE: - smbus_do_quick_cmd(dev, 1); - break; - case SMBUS_READ_DATA: - BADF("Unexpected stop during receive\n"); - break; - default: - /* Nothing to do. */ - break; + if (dev->data_len == 0) { + if (dev->mode == SMBUS_WRITE_DATA || dev->mode == SMBUS_READ_DATA) { + smbus_do_quick_cmd(dev, dev->mode == SMBUS_READ_DATA); + } + } else { + switch (dev->mode) { + case SMBUS_WRITE_DATA: + smbus_do_write(dev); + break; + + case SMBUS_READ_DATA: + BADF("Unexpected stop during receive\n"); + break; + + default: + /* Nothing to do. */ + break; + } } dev->mode = SMBUS_IDLE; dev->data_len = 0; |