summaryrefslogtreecommitdiff
path: root/src/southbridge/intel/common/smbus.c
diff options
context:
space:
mode:
authorKyösti Mälkki <kyosti.malkki@gmail.com>2017-08-20 23:48:23 +0300
committerKyösti Mälkki <kyosti.malkki@gmail.com>2017-09-09 12:58:49 +0000
commitc17e855da0ac5fb3d8b22f2a76ea899dfaed4c9e (patch)
treecbd13fbce64a8891c3c53b41c8fc88e63ecfad77 /src/southbridge/intel/common/smbus.c
parent916b331a8dbe90a2810d253a8b286ca9ee804fc5 (diff)
downloadcoreboot-c17e855da0ac5fb3d8b22f2a76ea899dfaed4c9e.tar.xz
sb/intel/common: Tidy up SMBus block commands
I forgot to push these changes before merging commit 1b04aa2 sb/intel/common: Fix SMBus block commands Change-Id: I7217f8c0cc78f2161faf31a4c49e3e9515026d15 Signed-off-by: Kyösti Mälkki <kyosti.malkki@gmail.com> Reviewed-on: https://review.coreboot.org/21115 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Nico Huber <nico.h@gmx.de>
Diffstat (limited to 'src/southbridge/intel/common/smbus.c')
-rw-r--r--src/southbridge/intel/common/smbus.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/southbridge/intel/common/smbus.c b/src/southbridge/intel/common/smbus.c
index ee58aab995..43d7d1901f 100644
--- a/src/southbridge/intel/common/smbus.c
+++ b/src/southbridge/intel/common/smbus.c
@@ -47,6 +47,7 @@
#define SMBHSTSTS_HOST_BUSY (1 << 0)
#define SMBUS_TIMEOUT (10 * 1000 * 100)
+#define SMBUS_BLOCK_MAXLEN 32
static void smbus_delay(void)
{
@@ -203,7 +204,7 @@ int do_smbus_block_read(unsigned int smbus_base, u8 device, u8 cmd,
if (smbus_wait_until_ready(smbus_base) < 0)
return SMBUS_WAIT_UNTIL_READY_TIMEOUT;
- max_bytes = MIN(32, max_bytes);
+ max_bytes = MIN(SMBUS_BLOCK_MAXLEN, max_bytes);
/* Set up transaction */
/* Disable interrupts */
@@ -243,8 +244,7 @@ int do_smbus_block_read(unsigned int smbus_base, u8 device, u8 cmd,
if (status & SMBHSTSTS_BYTE_DONE) { /* Byte done */
if (bytes_read < max_bytes) {
- *buf = inb(smbus_base + SMBBLKDAT);
- buf++;
+ *buf++ = inb(smbus_base + SMBBLKDAT);
bytes_read++;
}
@@ -271,7 +271,7 @@ int do_smbus_block_write(unsigned int smbus_base, u8 device, u8 cmd,
int bytes_sent = 0;
unsigned int loops = SMBUS_TIMEOUT;
- if (bytes > 32)
+ if (bytes > SMBUS_BLOCK_MAXLEN)
return SMBUS_ERROR;
if (smbus_wait_until_ready(smbus_base) < 0)
@@ -329,6 +329,9 @@ int do_smbus_block_write(unsigned int smbus_base, u8 device, u8 cmd,
}
} while ((status & SMBHSTSTS_HOST_BUSY) && loops);
+ if (bytes_sent < bytes)
+ return SMBUS_ERROR;
+
return bytes_sent;
}