summaryrefslogtreecommitdiff
path: root/src/southbridge
diff options
context:
space:
mode:
authorKyösti Mälkki <kyosti.malkki@gmail.com>2017-08-20 21:36:03 +0300
committerKyösti Mälkki <kyosti.malkki@gmail.com>2017-09-09 12:58:58 +0000
commit1e39236f965427cbfc92d3938af4c0acc41a1ce7 (patch)
tree0e7234917c075322131b4a99e7b50c03b19884a3 /src/southbridge
parentc17e855da0ac5fb3d8b22f2a76ea899dfaed4c9e (diff)
sb/intel/common: Fix i2c block command
Coding style, sync implementation with SMBus counterpart. Change-Id: I75f24e2308de945fc03289636ae914bb87070838 Signed-off-by: Kyösti Mälkki <kyosti.malkki@gmail.com> Reviewed-on: https://review.coreboot.org/21116 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Nico Huber <nico.h@gmx.de> Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
Diffstat (limited to 'src/southbridge')
-rw-r--r--src/southbridge/intel/common/smbus.c17
-rw-r--r--src/southbridge/intel/common/smbus.h2
2 files changed, 13 insertions, 6 deletions
diff --git a/src/southbridge/intel/common/smbus.c b/src/southbridge/intel/common/smbus.c
index 43d7d1901f..90ef03ee12 100644
--- a/src/southbridge/intel/common/smbus.c
+++ b/src/southbridge/intel/common/smbus.c
@@ -337,7 +337,7 @@ int do_smbus_block_write(unsigned int smbus_base, u8 device, u8 cmd,
/* Only since ICH5 */
int do_i2c_block_read(unsigned int smbus_base, u8 device,
- unsigned int offset, u32 bytes, u8 *buf)
+ unsigned int offset, const unsigned int bytes, u8 *buf)
{
u8 status;
int bytes_read = 0;
@@ -379,18 +379,25 @@ int do_i2c_block_read(unsigned int smbus_base, u8 device,
return SMBUS_ERROR;
if (status & SMBHSTSTS_BYTE_DONE) {
- *buf = inb(smbus_base + SMBBLKDAT);
- buf++;
- bytes_read++;
- if (--bytes == 1) {
+
+ if (bytes_read < bytes) {
+ *buf++ = inb(smbus_base + SMBBLKDAT);
+ bytes_read++;
+ }
+
+ if (bytes_read + 1 >= bytes) {
/* indicate that next byte is the last one */
outb(inb(smbus_base + SMBHSTCTL)
| SMBHSTCNT_LAST_BYTE,
smbus_base + SMBHSTCTL);
}
+
outb(status, smbus_base + SMBHSTSTAT);
}
} while ((status & SMBHSTSTS_HOST_BUSY) && loops);
+ if (bytes_read < bytes)
+ return SMBUS_ERROR;
+
return bytes_read;
}
diff --git a/src/southbridge/intel/common/smbus.h b/src/southbridge/intel/common/smbus.h
index 3016a1726f..be1aa76c21 100644
--- a/src/southbridge/intel/common/smbus.h
+++ b/src/southbridge/intel/common/smbus.h
@@ -42,5 +42,5 @@ int do_smbus_block_write(unsigned int smbus_base, u8 device,
u8 cmd, unsigned int bytes, const u8 *buf);
/* Only since ICH5 */
int do_i2c_block_read(unsigned int smbus_base, u8 device,
- unsigned int offset, u32 bytes, u8 *buf);
+ unsigned int offset, unsigned int bytes, u8 *buf);
#endif