Message ID | 20230320221419.2225561-2-komlodi@google.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | hw/i2c: Reset fixes | expand |
On 20/3/23 23:14, Joe Komlodi wrote: > If a reset comes while the SMBus device is not in its idle state, it's > possible for it to get confused on valid transactions post-reset. > > Signed-off-by: Joe Komlodi <komlodi@google.com> > --- > hw/i2c/smbus_slave.c | 9 +++++++++ > 1 file changed, 9 insertions(+) Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
diff --git a/hw/i2c/smbus_slave.c b/hw/i2c/smbus_slave.c index feb3ec6333..7b9d8780ae 100644 --- a/hw/i2c/smbus_slave.c +++ b/hw/i2c/smbus_slave.c @@ -197,10 +197,19 @@ static int smbus_i2c_send(I2CSlave *s, uint8_t data) return 0; } +static void smbus_device_enter_reset(Object *obj, ResetType type) +{ + SMBusDevice *dev = SMBUS_DEVICE(obj); + dev->mode = SMBUS_IDLE; + dev->data_len = 0; +} + static void smbus_device_class_init(ObjectClass *klass, void *data) { I2CSlaveClass *sc = I2C_SLAVE_CLASS(klass); + ResettableClass *rc = RESETTABLE_CLASS(klass); + rc->phases.enter = smbus_device_enter_reset; sc->event = smbus_i2c_event; sc->recv = smbus_i2c_recv; sc->send = smbus_i2c_send;
If a reset comes while the SMBus device is not in its idle state, it's possible for it to get confused on valid transactions post-reset. Signed-off-by: Joe Komlodi <komlodi@google.com> --- hw/i2c/smbus_slave.c | 9 +++++++++ 1 file changed, 9 insertions(+)