From 7192007e7d1c6334fa87f3e5b11a79f6be38bf4c Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Fri, 11 Dec 2020 18:25:14 -0300 Subject: [PATCH] Reset I2C EEPROM address position on stop, fixes HWiNFO SPD reading --- src/mem/i2c_eeprom.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/mem/i2c_eeprom.c b/src/mem/i2c_eeprom.c index 62615db34..954d29bc3 100644 --- a/src/mem/i2c_eeprom.c +++ b/src/mem/i2c_eeprom.c @@ -33,7 +33,7 @@ typedef struct { uint8_t addr_len, addr_pos; } i2c_eeprom_t; - +#define ENABLE_I2C_EEPROM_LOG 1 #ifdef ENABLE_I2C_EEPROM_LOG int i2c_eeprom_do_log = ENABLE_I2C_EEPROM_LOG; @@ -110,6 +110,17 @@ i2c_eeprom_write(void *bus, uint8_t addr, uint8_t data, void *priv) } +static void +i2c_eeprom_stop(void *bus, uint8_t addr, void *priv) +{ + i2c_eeprom_t *dev = (i2c_eeprom_t *) priv; + + i2c_eeprom_log("I2C EEPROM %s %02X: stop()\n", i2c_getbusname(dev->i2c), dev->addr); + + dev->addr_pos = 0; +} + + uint8_t log2i(uint32_t i) { @@ -142,7 +153,7 @@ i2c_eeprom_init(void *i2c, uint8_t addr, uint8_t *data, uint32_t size, uint8_t w dev->addr_len = (size >= 4096) ? 16 : 8; /* use 16-bit addresses on 24C32 and above */ dev->addr_mask = size - 1; - i2c_sethandler(dev->i2c, dev->addr & ~(dev->addr_mask >> dev->addr_len), (dev->addr_mask >> dev->addr_len) + 1, i2c_eeprom_start, i2c_eeprom_read, i2c_eeprom_write, NULL, dev); + i2c_sethandler(dev->i2c, dev->addr & ~(dev->addr_mask >> dev->addr_len), (dev->addr_mask >> dev->addr_len) + 1, i2c_eeprom_start, i2c_eeprom_read, i2c_eeprom_write, i2c_eeprom_stop, dev); return dev; } @@ -155,7 +166,7 @@ i2c_eeprom_close(void *dev_handle) i2c_eeprom_log("I2C EEPROM %s %02X: close()\n", i2c_getbusname(dev->i2c), dev->addr); - i2c_removehandler(dev->i2c, dev->addr & ~(dev->addr_mask >> dev->addr_len), (dev->addr_mask >> dev->addr_len) + 1, i2c_eeprom_start, i2c_eeprom_read, i2c_eeprom_write, NULL, dev); + i2c_removehandler(dev->i2c, dev->addr & ~(dev->addr_mask >> dev->addr_len), (dev->addr_mask >> dev->addr_len) + 1, i2c_eeprom_start, i2c_eeprom_read, i2c_eeprom_write, i2c_eeprom_stop, dev); free(dev); }