diff options
author | Kyösti Mälkki <kyosti.malkki@gmail.com> | 2017-08-20 21:36:24 +0300 |
---|---|---|
committer | Patrick Georgi <pgeorgi@google.com> | 2019-01-24 13:38:27 +0000 |
commit | d6c15d0c8c39015994a180da82c3e6f9538b42de (patch) | |
tree | 654ed4b81dfe4073a6dd5588b794e85b65285c48 /src/southbridge/intel/common/smbus.c | |
parent | 893edeebc6a84fea527ca63d9f4ef48ad2abdc15 (diff) |
sb/intel/common: More SMBus block_cmd_loop()
Setup to different block transactions are similar
enough to have common place to call execute_command()
in.
Change-Id: I671fed280f47e6bc673eb7506f09ed6ed36d2804
Signed-off-by: Kyösti Mälkki <kyosti.malkki@gmail.com>
Reviewed-on: https://review.coreboot.org/c/26763
Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'src/southbridge/intel/common/smbus.c')
-rw-r--r-- | src/southbridge/intel/common/smbus.c | 54 |
1 files changed, 24 insertions, 30 deletions
diff --git a/src/southbridge/intel/common/smbus.c b/src/southbridge/intel/common/smbus.c index 12fb9ea3c2..fd8b6aa8dd 100644 --- a/src/southbridge/intel/common/smbus.c +++ b/src/southbridge/intel/common/smbus.c @@ -239,6 +239,27 @@ static int block_cmd_loop(unsigned int smbus_base, if (flags == (BLOCK_WRITE | BLOCK_I2C)) return SMBUS_ERROR; + /* Set number of bytes to transfer. */ + /* Reset number of bytes to transfer so we notice later it + * was really updated with the transaction. */ + if (!sw_drives_nak) { + if (is_write_cmd) + outb(max_bytes, smbus_base + SMBHSTDAT0); + else + outb(0, smbus_base + SMBHSTDAT0); + } + + /* Send first byte from buffer, bytes_sent increments after + * hardware acknowledges it. + */ + if (is_write_cmd) + outb(*buf++, smbus_base + SMBBLKDAT); + + /* Start the command */ + ret = execute_command(smbus_base); + if (ret < 0) + return ret; + /* Poll for transaction completion */ do { status = inb(smbus_base + SMBHSTSTAT); @@ -301,16 +322,7 @@ int do_smbus_block_read(unsigned int smbus_base, u8 device, u8 cmd, /* Set the command/address... */ outb(cmd, smbus_base + SMBHSTCMD); - /* Reset number of bytes to transfer so we notice later it - * was really updated with the transaction. */ - outb(0, smbus_base + SMBHSTDAT0); - - /* Start the command */ - ret = execute_command(smbus_base); - if (ret < 0) - return ret; - - /* Poll for transaction completion */ + /* Execute block transaction. */ ret = block_cmd_loop(smbus_base, buf, max_bytes, BLOCK_READ); if (ret < 0) return ret; @@ -339,20 +351,7 @@ int do_smbus_block_write(unsigned int smbus_base, u8 device, u8 cmd, /* Set the command/address... */ outb(cmd, smbus_base + SMBHSTCMD); - /* Set number of bytes to transfer. */ - outb(bytes, smbus_base + SMBHSTDAT0); - - /* Send first byte from buffer, bytes_sent increments after - * hardware acknowledges it. - */ - outb(*buf++, smbus_base + SMBBLKDAT); - - /* Start the command */ - ret = execute_command(smbus_base); - if (ret < 0) - return ret; - - /* Poll for transaction completion */ + /* Execute block transaction. */ ret = block_cmd_loop(smbus_base, (u8 *)buf, bytes, BLOCK_WRITE); if (ret < 0) return ret; @@ -383,12 +382,7 @@ int do_i2c_block_read(unsigned int smbus_base, u8 device, /* device offset */ outb(offset, smbus_base + SMBHSTDAT1); - /* Start the command */ - ret = execute_command(smbus_base); - if (ret < 0) - return ret; - - /* Poll for transaction completion */ + /* Execute block transaction. */ ret = block_cmd_loop(smbus_base, buf, bytes, BLOCK_READ | BLOCK_I2C); if (ret < 0) return ret; |