diff options
Diffstat (limited to 'src/soc/intel/common/block/smbus')
-rw-r--r-- | src/soc/intel/common/block/smbus/smbus_early.c | 5 | ||||
-rw-r--r-- | src/soc/intel/common/block/smbus/smbuslib.c | 41 | ||||
-rw-r--r-- | src/soc/intel/common/block/smbus/smbuslib.h | 2 |
3 files changed, 48 insertions, 0 deletions
diff --git a/src/soc/intel/common/block/smbus/smbus_early.c b/src/soc/intel/common/block/smbus/smbus_early.c index e0c4d9c649..9e6afc4563 100644 --- a/src/soc/intel/common/block/smbus/smbus_early.c +++ b/src/soc/intel/common/block/smbus/smbus_early.c @@ -36,6 +36,11 @@ static const struct reg_script smbus_init_script[] = { REG_SCRIPT_END, }; +u16 smbus_read_word(u32 smbus_dev, u8 addr, u8 offset) +{ + return smbus_read16(SMBUS_IO_BASE, addr, offset); +} + u8 smbus_read_byte(u32 smbus_dev, u8 addr, u8 offset) { return smbus_read8(SMBUS_IO_BASE, addr, offset); diff --git a/src/soc/intel/common/block/smbus/smbuslib.c b/src/soc/intel/common/block/smbus/smbuslib.c index 27b4ad5c5d..0d3901fa2b 100644 --- a/src/soc/intel/common/block/smbus/smbuslib.c +++ b/src/soc/intel/common/block/smbus/smbuslib.c @@ -135,3 +135,44 @@ int smbus_write8(unsigned int smbus_base, unsigned int device, return 0; } + +int smbus_read16(unsigned int smbus_base, unsigned int device, + unsigned int address) +{ + unsigned char global_status_register; + unsigned short data; + + if (smbus_wait_till_ready(smbus_base) < 0) + return SMBUS_WAIT_UNTIL_READY_TIMEOUT; + + /* Set up transaction */ + /* Disable interrupts */ + outb(inb(smbus_base + SMBHSTCTL) & ~1, smbus_base + SMBHSTCTL); + /* Set the device I'm talking to */ + outb(((device & 0x7f) << 1) | 1, smbus_base + SMBXMITADD); + /* Set the command/address... */ + outb(address & 0xff, smbus_base + SMBHSTCMD); + /* Set up for a word data read */ + outb((inb(smbus_base + SMBHSTCTL) & 0xe3) | (0x3 << 2), + (smbus_base + SMBHSTCTL)); + /* Clear any lingering errors, so the transaction will run */ + outb(inb(smbus_base + SMBHSTSTAT), smbus_base + SMBHSTSTAT); + + /* Start the command */ + outb((inb(smbus_base + SMBHSTCTL) | 0x40), + smbus_base + SMBHSTCTL); + + /* Poll for transaction completion */ + if (smbus_wait_till_done(smbus_base) < 0) + return SMBUS_WAIT_UNTIL_DONE_TIMEOUT; + + global_status_register = inb(smbus_base + SMBHSTSTAT); + /* Ignore the "In Use" status... */ + if ((global_status_register & ~(3 << 5)) != (1 << 1)) + return SMBUS_ERROR; + + /* Read results of transaction */ + data = inw(smbus_base + SMBHSTDAT0); + + return data; +} diff --git a/src/soc/intel/common/block/smbus/smbuslib.h b/src/soc/intel/common/block/smbus/smbuslib.h index b5be6ca84e..05dafe9947 100644 --- a/src/soc/intel/common/block/smbus/smbuslib.h +++ b/src/soc/intel/common/block/smbus/smbuslib.h @@ -34,5 +34,7 @@ int smbus_read8(unsigned int smbus_base, unsigned int device, unsigned int address); int smbus_write8(unsigned int smbus_base, unsigned int device, unsigned int address, unsigned int data); +int smbus_read16(unsigned int smbus_base, unsigned int device, + unsigned int address); #endif /* SOC_INTEL_COMMON_BLOCK_SMBUS__LIB_H */ |