coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
smbus.c File Reference
#include <arch/io.h>
#include <console/console.h>
#include <device/smbus_def.h>
#include <device/smbus_host.h>
#include <types.h>
Include dependency graph for smbus.c:

Go to the source code of this file.

Macros

#define dprintk(args...)   do {} while (0)
 
#define SMBHSTSTAT   0x0
 
#define SMBHSTCTL   0x2
 
#define SMBHSTCMD   0x3
 
#define SMBXMITADD   0x4
 
#define SMBHSTDAT0   0x5
 
#define SMBHSTDAT1   0x6
 
#define SMBBLKDAT   0x7
 
#define SMBTRNSADD   0x9
 
#define SMBSLVDATA   0xa
 
#define SMLINK_PIN_CTL   0xe
 
#define SMBUS_PIN_CTL   0xf
 
#define SMBSLVCMD   0x11
 
#define SMB_RCV_SLVA   SMBTRNSADD
 
#define I801_QUICK   (0 << 2)
 
#define I801_BYTE   (1 << 2)
 
#define I801_BYTE_DATA   (2 << 2)
 
#define I801_WORD_DATA   (3 << 2)
 
#define I801_PROCESS_CALL   (4 << 2)
 
#define I801_BLOCK_DATA   (5 << 2)
 
#define I801_I2C_BLOCK_DATA   (6 << 2) /* ICH5 and later */
 
#define SMBHSTCNT_INTREN   (1 << 0)
 
#define SMBHSTCNT_KILL   (1 << 1)
 
#define SMBHSTCNT_LAST_BYTE   (1 << 5)
 
#define SMBHSTCNT_START   (1 << 6)
 
#define SMBHSTCNT_PEC_EN   (1 << 7) /* ICH3 and later */
 
#define SMBHSTSTS_BYTE_DONE   (1 << 7)
 
#define SMBHSTSTS_INUSE_STS   (1 << 6)
 
#define SMBHSTSTS_SMBALERT_STS   (1 << 5)
 
#define SMBHSTSTS_FAILED   (1 << 4)
 
#define SMBHSTSTS_BUS_ERR   (1 << 3)
 
#define SMBHSTSTS_DEV_ERR   (1 << 2)
 
#define SMBHSTSTS_INTR   (1 << 1)
 
#define SMBHSTSTS_HOST_BUSY   (1 << 0)
 
#define XMIT_WRITE(dev)   (((dev) << 1) | 0)
 
#define XMIT_READ(dev)   (((dev) << 1) | 1)
 
#define SMBUS_TIMEOUT   (10 * 1000 * 100)
 
#define SMBUS_BLOCK_MAXLEN   32
 
#define BLOCK_READ   0
 
#define BLOCK_WRITE   (1 << 0)
 
#define BLOCK_I2C   (1 << 1)
 

Functions

static void smbus_delay (void)
 
static void host_outb (uintptr_t base, u8 reg, u8 value)
 
static u8 host_inb (uintptr_t base, u8 reg)
 
static void host_and_or (uintptr_t base, u8 reg, u8 mask, u8 or)
 
void smbus_host_reset (uintptr_t base)
 
void smbus_set_slave_addr (uintptr_t base, u8 slave_address)
 
static int host_completed (u8 status)
 
static int recover_master (uintptr_t base, int ret)
 
static int cb_err_from_stat (u8 status)
 
static int setup_command (uintptr_t base, u8 ctrl, u8 xmitadd)
 
static int execute_command (uintptr_t base)
 
static int complete_command (uintptr_t base)
 
static int smbus_read_cmd (uintptr_t base, u8 ctrl, u8 device, u8 address)
 
static int smbus_write_cmd (uintptr_t base, u8 ctrl, u8 device, u8 address, u16 data)
 
static int block_cmd_loop (uintptr_t base, u8 *buf, size_t max_bytes, int flags)
 
int do_smbus_read_byte (uintptr_t base, u8 device, u8 address)
 
int do_smbus_read_word (uintptr_t base, u8 device, u8 address)
 
int do_smbus_write_byte (uintptr_t base, u8 device, u8 address, u8 data)
 
int do_smbus_write_word (uintptr_t base, u8 device, u8 address, u16 data)
 
int do_smbus_block_read (uintptr_t base, u8 device, u8 cmd, size_t max_bytes, u8 *buf)
 
int do_smbus_process_call (uintptr_t base, u8 device, u8 cmd, u16 data, u16 *buf)
 
int do_smbus_block_write (uintptr_t base, u8 device, u8 cmd, const size_t bytes, const u8 *buf)
 
static int has_i2c_read_command (void)
 
int do_i2c_eeprom_read (uintptr_t base, u8 device, u8 offset, const size_t bytes, u8 *buf)
 
int do_i2c_block_write (uintptr_t base, u8 device, size_t bytes, u8 *buf)
 

Macro Definition Documentation

◆ BLOCK_I2C

#define BLOCK_I2C   (1 << 1)

Definition at line 67 of file smbus.c.

◆ BLOCK_READ

#define BLOCK_READ   0

Definition at line 65 of file smbus.c.

◆ BLOCK_WRITE

#define BLOCK_WRITE   (1 << 0)

Definition at line 66 of file smbus.c.

◆ dprintk

#define dprintk (   args...)    do {} while (0)

Definition at line 12 of file smbus.c.

◆ I801_BLOCK_DATA

#define I801_BLOCK_DATA   (5 << 2)

Definition at line 37 of file smbus.c.

◆ I801_BYTE

#define I801_BYTE   (1 << 2)

Definition at line 33 of file smbus.c.

◆ I801_BYTE_DATA

#define I801_BYTE_DATA   (2 << 2)

Definition at line 34 of file smbus.c.

◆ I801_I2C_BLOCK_DATA

#define I801_I2C_BLOCK_DATA   (6 << 2) /* ICH5 and later */

Definition at line 38 of file smbus.c.

◆ I801_PROCESS_CALL

#define I801_PROCESS_CALL   (4 << 2)

Definition at line 36 of file smbus.c.

◆ I801_QUICK

#define I801_QUICK   (0 << 2)

Definition at line 32 of file smbus.c.

◆ I801_WORD_DATA

#define I801_WORD_DATA   (3 << 2)

Definition at line 35 of file smbus.c.

◆ SMB_RCV_SLVA

#define SMB_RCV_SLVA   SMBTRNSADD

Definition at line 29 of file smbus.c.

◆ SMBBLKDAT

#define SMBBLKDAT   0x7

Definition at line 22 of file smbus.c.

◆ SMBHSTCMD

#define SMBHSTCMD   0x3

Definition at line 18 of file smbus.c.

◆ SMBHSTCNT_INTREN

#define SMBHSTCNT_INTREN   (1 << 0)

Definition at line 41 of file smbus.c.

◆ SMBHSTCNT_KILL

#define SMBHSTCNT_KILL   (1 << 1)

Definition at line 42 of file smbus.c.

◆ SMBHSTCNT_LAST_BYTE

#define SMBHSTCNT_LAST_BYTE   (1 << 5)

Definition at line 43 of file smbus.c.

◆ SMBHSTCNT_PEC_EN

#define SMBHSTCNT_PEC_EN   (1 << 7) /* ICH3 and later */

Definition at line 45 of file smbus.c.

◆ SMBHSTCNT_START

#define SMBHSTCNT_START   (1 << 6)

Definition at line 44 of file smbus.c.

◆ SMBHSTCTL

#define SMBHSTCTL   0x2

Definition at line 17 of file smbus.c.

◆ SMBHSTDAT0

#define SMBHSTDAT0   0x5

Definition at line 20 of file smbus.c.

◆ SMBHSTDAT1

#define SMBHSTDAT1   0x6

Definition at line 21 of file smbus.c.

◆ SMBHSTSTAT

#define SMBHSTSTAT   0x0

Definition at line 16 of file smbus.c.

◆ SMBHSTSTS_BUS_ERR

#define SMBHSTSTS_BUS_ERR   (1 << 3)

Definition at line 52 of file smbus.c.

◆ SMBHSTSTS_BYTE_DONE

#define SMBHSTSTS_BYTE_DONE   (1 << 7)

Definition at line 48 of file smbus.c.

◆ SMBHSTSTS_DEV_ERR

#define SMBHSTSTS_DEV_ERR   (1 << 2)

Definition at line 53 of file smbus.c.

◆ SMBHSTSTS_FAILED

#define SMBHSTSTS_FAILED   (1 << 4)

Definition at line 51 of file smbus.c.

◆ SMBHSTSTS_HOST_BUSY

#define SMBHSTSTS_HOST_BUSY   (1 << 0)

Definition at line 55 of file smbus.c.

◆ SMBHSTSTS_INTR

#define SMBHSTSTS_INTR   (1 << 1)

Definition at line 54 of file smbus.c.

◆ SMBHSTSTS_INUSE_STS

#define SMBHSTSTS_INUSE_STS   (1 << 6)

Definition at line 49 of file smbus.c.

◆ SMBHSTSTS_SMBALERT_STS

#define SMBHSTSTS_SMBALERT_STS   (1 << 5)

Definition at line 50 of file smbus.c.

◆ SMBSLVCMD

#define SMBSLVCMD   0x11

Definition at line 27 of file smbus.c.

◆ SMBSLVDATA

#define SMBSLVDATA   0xa

Definition at line 24 of file smbus.c.

◆ SMBTRNSADD

#define SMBTRNSADD   0x9

Definition at line 23 of file smbus.c.

◆ SMBUS_BLOCK_MAXLEN

#define SMBUS_BLOCK_MAXLEN   32

Definition at line 62 of file smbus.c.

◆ SMBUS_PIN_CTL

#define SMBUS_PIN_CTL   0xf

Definition at line 26 of file smbus.c.

◆ SMBUS_TIMEOUT

#define SMBUS_TIMEOUT   (10 * 1000 * 100)

Definition at line 61 of file smbus.c.

◆ SMBXMITADD

#define SMBXMITADD   0x4

Definition at line 19 of file smbus.c.

◆ SMLINK_PIN_CTL

#define SMLINK_PIN_CTL   0xe

Definition at line 25 of file smbus.c.

◆ XMIT_READ

#define XMIT_READ (   dev)    (((dev) << 1) | 1)

Definition at line 59 of file smbus.c.

◆ XMIT_WRITE

#define XMIT_WRITE (   dev)    (((dev) << 1) | 0)

Definition at line 58 of file smbus.c.

Function Documentation

◆ block_cmd_loop()

static int block_cmd_loop ( uintptr_t  base,
u8 buf,
size_t  max_bytes,
int  flags 
)
static

◆ cb_err_from_stat()

static int cb_err_from_stat ( u8  status)
static

Definition at line 127 of file smbus.c.

References SMBHSTSTS_BYTE_DONE, SMBHSTSTS_INTR, SMBHSTSTS_INUSE_STS, SMBHSTSTS_SMBALERT_STS, and SMBUS_ERROR.

Referenced by block_cmd_loop(), and complete_command().

Here is the caller graph for this function:

◆ complete_command()

static int complete_command ( uintptr_t  base)
static

Definition at line 191 of file smbus.c.

References base, cb_err_from_stat(), host_completed(), host_inb(), recover_master(), SMBHSTSTAT, smbus_delay(), SMBUS_TIMEOUT, and SMBUS_WAIT_UNTIL_DONE_TIMEOUT.

Referenced by do_smbus_process_call(), smbus_read_cmd(), and smbus_write_cmd().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_i2c_block_write()

int do_i2c_block_write ( uintptr_t  base,
u8  device,
size_t  bytes,
u8 buf 
)

Definition at line 503 of file smbus.c.

References base, block_cmd_loop(), BLOCK_WRITE, buf, CONFIG, host_outb(), I801_BLOCK_DATA, setup_command(), SMBHSTCMD, SMBHSTDAT1, SMBUS_BLOCK_MAXLEN, SMBUS_ERROR, and XMIT_WRITE.

Referenced by smbus_i2c_block_write().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_i2c_eeprom_read()

int do_i2c_eeprom_read ( uintptr_t  base,
u8  device,
u8  offset,
const size_t  bytes,
u8 buf 
)

Definition at line 466 of file smbus.c.

References base, block_cmd_loop(), BLOCK_I2C, BLOCK_READ, buf, has_i2c_read_command(), host_outb(), I801_I2C_BLOCK_DATA, offset, setup_command(), SMBHSTDAT1, SMBUS_ERROR, and XMIT_WRITE.

Here is the call graph for this function:

◆ do_smbus_block_read()

int do_smbus_block_read ( uintptr_t  base,
u8  device,
u8  cmd,
size_t  max_bytes,
u8 buf 
)

Definition at line 368 of file smbus.c.

References base, block_cmd_loop(), BLOCK_READ, buf, host_inb(), host_outb(), I801_BLOCK_DATA, MIN, setup_command(), SMBHSTCMD, SMBHSTDAT0, SMBUS_BLOCK_MAXLEN, SMBUS_ERROR, and XMIT_READ.

Here is the call graph for this function:

◆ do_smbus_block_write()

int do_smbus_block_write ( uintptr_t  base,
u8  device,
u8  cmd,
const size_t  bytes,
const u8 buf 
)

Definition at line 431 of file smbus.c.

References base, block_cmd_loop(), BLOCK_WRITE, buf, host_outb(), I801_BLOCK_DATA, setup_command(), SMBHSTCMD, SMBUS_BLOCK_MAXLEN, SMBUS_ERROR, and XMIT_WRITE.

Referenced by eeprom_write_byte(), and lsmbus_block_write().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_smbus_process_call()

int do_smbus_process_call ( uintptr_t  base,
u8  device,
u8  cmd,
u16  data,
u16 buf 
)

Definition at line 399 of file smbus.c.

References base, buf, complete_command(), execute_command(), host_inb(), host_outb(), I801_PROCESS_CALL, setup_command(), SMBHSTCMD, SMBHSTDAT0, SMBHSTDAT1, and XMIT_WRITE.

Referenced by eeprom_read_buffer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_smbus_read_byte()

int do_smbus_read_byte ( uintptr_t  base,
u8  device,
u8  address 
)

Definition at line 348 of file smbus.c.

References address, base, controller_read8(), controller_write8(), I801_BYTE_DATA, SMBHST_CTRL_BDT_RW, SMBHST_CTRL_MODE_BITS, SMBHST_CTRL_STRT, SMBHSTADDR, SMBHSTCMD, SMBHSTCTRL, SMBHSTDAT0, smbus_read_cmd(), smbus_wait_until_done(), and smbus_wait_until_ready().

Referenced by lsmbus_read_byte(), and readspd().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_smbus_read_word()

int do_smbus_read_word ( uintptr_t  base,
u8  device,
u8  address 
)

Definition at line 353 of file smbus.c.

References address, base, I801_WORD_DATA, and smbus_read_cmd().

Here is the call graph for this function:

◆ do_smbus_write_byte()

int do_smbus_write_byte ( uintptr_t  base,
u8  device,
u8  address,
u8  data 
)

Definition at line 358 of file smbus.c.

References address, base, controller_read8(), controller_write8(), I801_BYTE_DATA, SMBHST_CTRL_BDT_RW, SMBHST_CTRL_MODE_BITS, SMBHST_CTRL_STRT, SMBHSTADDR, SMBHSTCMD, SMBHSTCTRL, SMBHSTDAT0, smbus_wait_until_done(), smbus_wait_until_ready(), smbus_write_cmd(), and val.

Referenced by board_BeforeAgesa(), and lsmbus_write_byte().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_smbus_write_word()

int do_smbus_write_word ( uintptr_t  base,
u8  device,
u8  address,
u16  data 
)

Definition at line 363 of file smbus.c.

References address, base, I801_WORD_DATA, and smbus_write_cmd().

Here is the call graph for this function:

◆ execute_command()

static int execute_command ( uintptr_t  base)
static

Definition at line 165 of file smbus.c.

References base, host_and_or(), host_inb(), recover_master(), SMBHSTCNT_START, SMBHSTCTL, SMBHSTSTAT, SMBHSTSTS_INUSE_STS, SMBHSTSTS_SMBALERT_STS, smbus_delay(), SMBUS_TIMEOUT, and SMBUS_WAIT_UNTIL_ACTIVE_TIMEOUT.

Referenced by block_cmd_loop(), do_smbus_process_call(), smbus_read_cmd(), and smbus_write_cmd().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ has_i2c_read_command()

static int has_i2c_read_command ( void  )
static

Definition at line 458 of file smbus.c.

References CONFIG.

Referenced by do_i2c_eeprom_read().

Here is the caller graph for this function:

◆ host_and_or()

static void host_and_or ( uintptr_t  base,
u8  reg,
u8  mask,
u8  or 
)
static

Definition at line 84 of file smbus.c.

References base, host_inb(), host_outb(), mask, and value.

Referenced by block_cmd_loop(), execute_command(), setup_command(), and smbus_host_reset().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ host_completed()

static int host_completed ( u8  status)
static

Definition at line 107 of file smbus.c.

References SMBHSTSTS_BYTE_DONE, SMBHSTSTS_HOST_BUSY, SMBHSTSTS_INUSE_STS, and SMBHSTSTS_SMBALERT_STS.

Referenced by block_cmd_loop(), and complete_command().

Here is the caller graph for this function:

◆ host_inb()

static u8 host_inb ( uintptr_t  base,
u8  reg 
)
static

Definition at line 79 of file smbus.c.

References base, and inb().

Referenced by block_cmd_loop(), complete_command(), do_smbus_block_read(), do_smbus_process_call(), execute_command(), host_and_or(), setup_command(), and smbus_read_cmd().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ host_outb()

static void host_outb ( uintptr_t  base,
u8  reg,
u8  value 
)
static

Definition at line 74 of file smbus.c.

References base, outb(), and value.

Referenced by block_cmd_loop(), do_i2c_block_write(), do_i2c_eeprom_read(), do_smbus_block_read(), do_smbus_block_write(), do_smbus_process_call(), host_and_or(), setup_command(), smbus_host_reset(), smbus_read_cmd(), smbus_set_slave_addr(), and smbus_write_cmd().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ recover_master()

static int recover_master ( uintptr_t  base,
int  ret 
)
static

Definition at line 118 of file smbus.c.

References BIOS_ERR, and printk.

Referenced by block_cmd_loop(), complete_command(), execute_command(), and setup_command().

Here is the caller graph for this function:

◆ setup_command()

static int setup_command ( uintptr_t  base,
u8  ctrl,
u8  xmitadd 
)
static

◆ smbus_delay()

static void smbus_delay ( void  )
static

Definition at line 69 of file smbus.c.

References inb().

Referenced by complete_command(), execute_command(), and setup_command().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ smbus_host_reset()

void smbus_host_reset ( uintptr_t  base)

Definition at line 93 of file smbus.c.

References base, host_and_or(), host_outb(), SMBHSTCTL, and SMBHSTSTAT.

Referenced by enable_smbus().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ smbus_read_cmd()

static int smbus_read_cmd ( uintptr_t  base,
u8  ctrl,
u8  device,
u8  address 
)
static

Definition at line 208 of file smbus.c.

References address, base, complete_command(), execute_command(), host_inb(), host_outb(), I801_WORD_DATA, setup_command(), SMBHSTCMD, SMBHSTDAT0, SMBHSTDAT1, word, and XMIT_READ.

Referenced by do_smbus_read_byte(), and do_smbus_read_word().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ smbus_set_slave_addr()

void smbus_set_slave_addr ( uintptr_t  base,
u8  slave_address 
)

Definition at line 102 of file smbus.c.

References base, host_outb(), and SMB_RCV_SLVA.

Referenced by pch_smbus_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ smbus_write_cmd()

static int smbus_write_cmd ( uintptr_t  base,
u8  ctrl,
u8  device,
u8  address,
u16  data 
)
static

Definition at line 243 of file smbus.c.

References address, base, complete_command(), execute_command(), host_outb(), I801_WORD_DATA, setup_command(), SMBHSTCMD, SMBHSTDAT0, SMBHSTDAT1, and XMIT_WRITE.

Referenced by do_smbus_write_byte(), and do_smbus_write_word().

Here is the call graph for this function:
Here is the caller graph for this function: