sb/intel/common: Add smbus_{read/write}_word() variants
Change-Id: I1a9432c901e7baa545d34c1d0f82212bf59f8e23 Signed-off-by: Kyösti Mälkki <kyosti.malkki@gmail.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/38141 Reviewed-by: Angel Pons <th3fanbus@gmail.com> Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
parent
265cd9a2ee
commit
7ca19b289e
2 changed files with 43 additions and 10 deletions
|
@ -175,22 +175,23 @@ static int complete_command(unsigned int smbus_base)
|
||||||
return cb_err_from_stat(status);
|
return cb_err_from_stat(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
int do_smbus_read_byte(unsigned int smbus_base, u8 device,
|
static int smbus_read_cmd(unsigned int smbus_base, u8 ctrl, u8 device,
|
||||||
unsigned int address)
|
unsigned int address)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
u8 byte;
|
u16 word;
|
||||||
|
|
||||||
/* Set up for a byte data read. */
|
/* Set up for a byte data read. */
|
||||||
ret = setup_command(smbus_base, I801_BYTE_DATA, XMIT_READ(device));
|
ret = setup_command(smbus_base, ctrl, XMIT_READ(device));
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
/* Set the command/address... */
|
/* Set the command/address... */
|
||||||
outb(address, smbus_base + SMBHSTCMD);
|
outb(address, smbus_base + SMBHSTCMD);
|
||||||
|
|
||||||
/* Clear the data byte... */
|
/* Clear the data bytes... */
|
||||||
outb(0, smbus_base + SMBHSTDAT0);
|
outb(0, smbus_base + SMBHSTDAT0);
|
||||||
|
outb(0, smbus_base + SMBHSTDAT1);
|
||||||
|
|
||||||
/* Start the command */
|
/* Start the command */
|
||||||
ret = execute_command(smbus_base);
|
ret = execute_command(smbus_base);
|
||||||
|
@ -203,25 +204,30 @@ int do_smbus_read_byte(unsigned int smbus_base, u8 device,
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
/* Read results of transaction */
|
/* Read results of transaction */
|
||||||
byte = inb(smbus_base + SMBHSTDAT0);
|
word = inb(smbus_base + SMBHSTDAT0);
|
||||||
return byte;
|
if (ctrl == I801_WORD_DATA)
|
||||||
|
word |= inb(smbus_base + SMBHSTDAT1) << 8;
|
||||||
|
|
||||||
|
return word;
|
||||||
}
|
}
|
||||||
|
|
||||||
int do_smbus_write_byte(unsigned int smbus_base, u8 device,
|
static int smbus_write_cmd(unsigned int smbus_base, u8 ctrl, u8 device,
|
||||||
unsigned int address, unsigned int data)
|
unsigned int address, unsigned int data)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* Set up for a byte data write. */
|
/* Set up for a byte data write. */
|
||||||
ret = setup_command(smbus_base, I801_BYTE_DATA, XMIT_WRITE(device));
|
ret = setup_command(smbus_base, ctrl, XMIT_WRITE(device));
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
/* Set the command/address... */
|
/* Set the command/address... */
|
||||||
outb(address, smbus_base + SMBHSTCMD);
|
outb(address, smbus_base + SMBHSTCMD);
|
||||||
|
|
||||||
/* Set the data byte... */
|
/* Set the data bytes... */
|
||||||
outb(data, smbus_base + SMBHSTDAT0);
|
outb(data & 0xff, smbus_base + SMBHSTDAT0);
|
||||||
|
if (ctrl == I801_WORD_DATA)
|
||||||
|
outb(data >> 8, smbus_base + SMBHSTDAT1);
|
||||||
|
|
||||||
/* Start the command */
|
/* Start the command */
|
||||||
ret = execute_command(smbus_base);
|
ret = execute_command(smbus_base);
|
||||||
|
@ -313,6 +319,28 @@ static int block_cmd_loop(unsigned int smbus_base,
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int do_smbus_read_byte(unsigned int smbus_base, u8 device, unsigned int address)
|
||||||
|
{
|
||||||
|
return smbus_read_cmd(smbus_base, I801_BYTE_DATA, device, address);
|
||||||
|
}
|
||||||
|
|
||||||
|
int do_smbus_read_word(unsigned int smbus_base, u8 device, unsigned int address)
|
||||||
|
{
|
||||||
|
return smbus_read_cmd(smbus_base, I801_WORD_DATA, device, address);
|
||||||
|
}
|
||||||
|
|
||||||
|
int do_smbus_write_byte(unsigned int smbus_base, u8 device, unsigned int address,
|
||||||
|
unsigned int data)
|
||||||
|
{
|
||||||
|
return smbus_write_cmd(smbus_base, I801_BYTE_DATA, device, address, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
int do_smbus_write_word(unsigned int smbus_base, u8 device, unsigned int address,
|
||||||
|
unsigned int data)
|
||||||
|
{
|
||||||
|
return smbus_write_cmd(smbus_base, I801_WORD_DATA, device, address, data);
|
||||||
|
}
|
||||||
|
|
||||||
int do_smbus_block_read(unsigned int smbus_base, u8 device, u8 cmd,
|
int do_smbus_block_read(unsigned int smbus_base, u8 device, u8 cmd,
|
||||||
unsigned int max_bytes, u8 *buf)
|
unsigned int max_bytes, u8 *buf)
|
||||||
{
|
{
|
||||||
|
|
|
@ -36,6 +36,11 @@ int do_smbus_read_byte(unsigned int smbus_base, u8 device,
|
||||||
unsigned int address);
|
unsigned int address);
|
||||||
int do_smbus_write_byte(unsigned int smbus_base, u8 device,
|
int do_smbus_write_byte(unsigned int smbus_base, u8 device,
|
||||||
unsigned int address, unsigned int data);
|
unsigned int address, unsigned int data);
|
||||||
|
int do_smbus_read_word(unsigned int smbus_base, u8 device,
|
||||||
|
unsigned int address);
|
||||||
|
int do_smbus_write_word(unsigned int smbus_base, u8 device,
|
||||||
|
unsigned int address, unsigned int data);
|
||||||
|
|
||||||
int do_smbus_block_read(unsigned int smbus_base, u8 device,
|
int do_smbus_block_read(unsigned int smbus_base, u8 device,
|
||||||
u8 cmd, unsigned int max_bytes, u8 *buf);
|
u8 cmd, unsigned int max_bytes, u8 *buf);
|
||||||
int do_smbus_block_write(unsigned int smbus_base, u8 device,
|
int do_smbus_block_write(unsigned int smbus_base, u8 device,
|
||||||
|
|
Loading…
Reference in a new issue