coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
software_i2c.c File Reference
#include <assert.h>
#include <timer.h>
#include <console/console.h>
#include <device/i2c_simple.h>
Include dependency graph for software_i2c.c:

Go to the source code of this file.

Macros

#define DEBUG   0 /* Set to 1 for per-byte output */
 
#define SPEW   0 /* Set to 1 for verbose bitwise/line-state output */
 
#define DELAY_US   5 /* Default setup delay: 4us (+1 for timer inaccuracy) */
 
#define TIMEOUT_US   50000 /* Maximum clock stretching time we want to allow */
 
#define spew(...)   do { if (SPEW) printk(BIOS_SPEW, ##__VA_ARGS__); } while (0)
 
#define ERR_NACK   -2
 
#define ERR_TIMEOUT   -3
 
#define ERR_ARB   -4
 
#define ERR_WEDGE   -5
 

Functions

static int __wait (unsigned int bus, int timeout_us, int for_scl)
 
static void wait (unsigned int bus)
 
static int wait_for_scl (unsigned int bus, const char *error_context)
 
static int start_cond (unsigned int bus)
 
static int stop_cond (unsigned int bus)
 
static int out_bit (unsigned int bus, int bit)
 
static int in_bit (unsigned int bus)
 
static int out_byte (unsigned int bus, u8 byte)
 
static int in_byte (unsigned int bus, int ack)
 
int software_i2c_transfer (unsigned int bus, struct i2c_msg *segments, int count)
 
void software_i2c_wedge_ack (unsigned int bus, u8 chip)
 
void software_i2c_wedge_read (unsigned int bus, u8 chip, u8 reg, int bits)
 
void software_i2c_wedge_write (unsigned int bus, u8 chip, u8 reg, int bits)
 

Variables

struct software_i2c_opssoftware_i2c [SOFTWARE_I2C_MAX_BUS]
 

Macro Definition Documentation

◆ DEBUG

#define DEBUG   0 /* Set to 1 for per-byte output */

Definition at line 12 of file software_i2c.c.

◆ DELAY_US

#define DELAY_US   5 /* Default setup delay: 4us (+1 for timer inaccuracy) */

Definition at line 14 of file software_i2c.c.

◆ ERR_ARB

#define ERR_ARB   -4

Definition at line 21 of file software_i2c.c.

◆ ERR_NACK

#define ERR_NACK   -2

Definition at line 19 of file software_i2c.c.

◆ ERR_TIMEOUT

#define ERR_TIMEOUT   -3

Definition at line 20 of file software_i2c.c.

◆ ERR_WEDGE

#define ERR_WEDGE   -5

Definition at line 22 of file software_i2c.c.

◆ SPEW

#define SPEW   0 /* Set to 1 for verbose bitwise/line-state output */

Definition at line 13 of file software_i2c.c.

◆ spew

#define spew (   ...)    do { if (SPEW) printk(BIOS_SPEW, ##__VA_ARGS__); } while (0)

Definition at line 17 of file software_i2c.c.

◆ TIMEOUT_US

#define TIMEOUT_US   50000 /* Maximum clock stretching time we want to allow */

Definition at line 15 of file software_i2c.c.

Function Documentation

◆ __wait()

static int __wait ( unsigned int  bus,
int  timeout_us,
int  for_scl 
)
static

Definition at line 30 of file software_i2c.c.

References get_scl(), software_i2c_ops::get_scl, get_sda(), software_i2c_ops::get_sda, scl, sda, software_i2c, spew, stopwatch_duration_usecs(), stopwatch_expired(), and stopwatch_init_usecs_expire().

Referenced by wait(), and wait_for_scl().

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

◆ in_bit()

static int in_bit ( unsigned int  bus)
static

Definition at line 166 of file software_i2c.c.

References assert, ERR_TIMEOUT, get_scl(), software_i2c_ops::get_sda, software_i2c_ops::set_scl, software_i2c_ops::set_sda, software_i2c, spew, wait(), and wait_for_scl().

Referenced by in_byte(), out_byte(), and software_i2c_wedge_read().

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

◆ in_byte()

static int in_byte ( unsigned int  bus,
int  ack 
)
static

Definition at line 212 of file software_i2c.c.

References BIOS_DEBUG, DEBUG, in_bit(), out_bit(), and printk.

Referenced by software_i2c_transfer(), and spi_bitbang_xfer().

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

◆ out_bit()

static int out_bit ( unsigned int  bus,
int  bit 
)
static

Definition at line 133 of file software_i2c.c.

References assert, BIOS_ERR, ERR_TIMEOUT, ERR_WEDGE, get_scl(), get_sda(), printk, software_i2c_ops::set_scl, software_i2c_ops::set_sda, software_i2c, spew, wait(), and wait_for_scl().

Referenced by in_byte(), out_byte(), software_i2c_wedge_ack(), and software_i2c_wedge_write().

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

◆ out_byte()

static int out_byte ( unsigned int  bus,
u8  byte 
)
static

Definition at line 194 of file software_i2c.c.

References BIOS_DEBUG, DEBUG, ERR_NACK, in_bit(), out_bit(), and printk.

Referenced by software_i2c_transfer(), software_i2c_wedge_read(), software_i2c_wedge_write(), and spi_bitbang_xfer().

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

◆ software_i2c_transfer()

int software_i2c_transfer ( unsigned int  bus,
struct i2c_msg segments,
int  count 
)

Definition at line 233 of file software_i2c.c.

References i2c_msg::buf, count, i2c_msg::flags, I2C_M_RD, in_byte(), i2c_msg::len, out_byte(), i2c_msg::slave, start_cond(), and stop_cond().

Referenced by i2c_transfer().

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

◆ software_i2c_wedge_ack()

void software_i2c_wedge_ack ( unsigned int  bus,
u8  chip 
)

Definition at line 261 of file software_i2c.c.

References BIOS_INFO, chip, get_scl(), get_sda(), out_bit(), printk, software_i2c_ops::set_scl, software_i2c_ops::set_sda, software_i2c, start_cond(), wait(), and wait_for_scl().

Here is the call graph for this function:

◆ software_i2c_wedge_read()

void software_i2c_wedge_read ( unsigned int  bus,
u8  chip,
u8  reg,
int  bits 
)

Definition at line 284 of file software_i2c.c.

References BIOS_INFO, chip, get_scl(), get_sda(), in_bit(), out_byte(), printk, software_i2c_ops::set_scl, software_i2c_ops::set_sda, software_i2c, start_cond(), wait(), and wait_for_scl().

Here is the call graph for this function:

◆ software_i2c_wedge_write()

void software_i2c_wedge_write ( unsigned int  bus,
u8  chip,
u8  reg,
int  bits 
)

Definition at line 313 of file software_i2c.c.

References BIOS_INFO, chip, get_scl(), get_sda(), out_bit(), out_byte(), printk, software_i2c_ops::set_scl, software_i2c_ops::set_sda, software_i2c, start_cond(), wait(), and wait_for_scl().

Here is the call graph for this function:

◆ start_cond()

static int start_cond ( unsigned int  bus)
static

Definition at line 72 of file software_i2c.c.

References assert, BIOS_ERR, ERR_ARB, ERR_TIMEOUT, get_scl(), get_sda(), printk, software_i2c_ops::set_scl, software_i2c_ops::set_sda, software_i2c, spew, wait(), and wait_for_scl().

Referenced by software_i2c_transfer(), software_i2c_wedge_ack(), software_i2c_wedge_read(), and software_i2c_wedge_write().

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

◆ stop_cond()

static int stop_cond ( unsigned int  bus)
static

Definition at line 104 of file software_i2c.c.

References assert, BIOS_WARNING, ERR_TIMEOUT, get_scl(), get_sda(), printk, software_i2c_ops::set_scl, software_i2c_ops::set_sda, software_i2c, spew, wait(), and wait_for_scl().

Referenced by software_i2c_transfer().

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

◆ wait()

static void wait ( unsigned int  bus)
static

◆ wait_for_scl()

static int wait_for_scl ( unsigned int  bus,
const char *  error_context 
)
static

Definition at line 61 of file software_i2c.c.

References __wait(), BIOS_ERR, ERR_TIMEOUT, printk, and TIMEOUT_US.

Referenced by in_bit(), out_bit(), software_i2c_wedge_ack(), software_i2c_wedge_read(), software_i2c_wedge_write(), start_cond(), and stop_cond().

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

Variable Documentation

◆ software_i2c