coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
dw_i2c.c File Reference
#include <acpi/acpigen.h>
#include <device/mmio.h>
#include <console/console.h>
#include <device/device.h>
#include <device/i2c_bus.h>
#include <device/i2c_simple.h>
#include <string.h>
#include <timer.h>
#include <types.h>
#include "dw_i2c.h"
Include dependency graph for dw_i2c.c:

Go to the source code of this file.

Data Structures

struct  freq
 
struct  dw_i2c_regs
 
struct  i2c_descriptor
 
struct  soc_clock
 

Macros

#define DW_I2C_TIMEOUT_US   10000
 
#define DW_I2C_FLUSH_TIMEOUT_US   160000
 
#define DW_I2C_COMP_TYPE   0x44570140
 

Enumerations

enum  {
  DEFAULT_SDA_HOLD_TIME = 300 , MIN_SS_SCL_HIGHTIME = 4000 , MIN_SS_SCL_LOWTIME = 4700 , MIN_FS_SCL_HIGHTIME = 600 ,
  MIN_FS_SCL_LOWTIME = 1300 , MIN_FP_SCL_HIGHTIME = 260 , MIN_FP_SCL_LOWTIME = 500 , MIN_HS_SCL_HIGHTIME = 60 ,
  MIN_HS_SCL_LOWTIME = 160
}
 
enum  {
  CONTROL_MASTER_MODE = (1 << 0) , CONTROL_SPEED_SS = (1 << 1) , CONTROL_SPEED_FS = (2 << 1) , CONTROL_SPEED_HS = (3 << 1) ,
  CONTROL_SPEED_MASK = (3 << 1) , CONTROL_10BIT_SLAVE = (1 << 3) , CONTROL_10BIT_MASTER = (1 << 4) , CONTROL_RESTART_ENABLE = (1 << 5) ,
  CONTROL_SLAVE_DISABLE = (1 << 6)
}
 
enum  { CMD_DATA_CMD = (1 << 8) , CMD_DATA_STOP = (1 << 9) }
 
enum  {
  STATUS_ACTIVITY = (1 << 0) , STATUS_TX_FIFO_NOT_FULL = (1 << 1) , STATUS_TX_FIFO_EMPTY = (1 << 2) , STATUS_RX_FIFO_NOT_EMPTY = (1 << 3) ,
  STATUS_RX_FIFO_FULL = (1 << 4) , STATUS_MASTER_ACTIVITY = (1 << 5) , STATUS_SLAVE_ACTIVITY = (1 << 6)
}
 
enum  { ENABLE_CONTROLLER = (1 << 0) }
 
enum  {
  INTR_STAT_RX_UNDER = (1 << 0) , INTR_STAT_RX_OVER = (1 << 1) , INTR_STAT_RX_FULL = (1 << 2) , INTR_STAT_TX_OVER = (1 << 3) ,
  INTR_STAT_TX_EMPTY = (1 << 4) , INTR_STAT_RD_REQ = (1 << 5) , INTR_STAT_TX_ABORT = (1 << 6) , INTR_STAT_RX_DONE = (1 << 7) ,
  INTR_STAT_ACTIVITY = (1 << 8) , INTR_STAT_STOP_DET = (1 << 9) , INTR_STAT_START_DET = (1 << 10) , INTR_STAT_GEN_CALL = (1 << 11)
}
 

Functions

static const struct i2c_descriptorget_bus_descriptor (enum i2c_speed speed)
 
static const struct soc_clockget_soc_descriptor (int ic_clk)
 
static int counts_from_time (const struct freq *f, int ns)
 
static int counts_from_freq (const struct freq *fast, const struct freq *slow)
 
static void dw_i2c_enable (struct dw_i2c_regs *regs)
 
static enum cb_err dw_i2c_disable (struct dw_i2c_regs *regs)
 
static enum cb_err dw_i2c_wait_for_bus_idle (struct dw_i2c_regs *regs)
 
static enum cb_err dw_i2c_transfer_byte (struct dw_i2c_regs *regs, const struct i2c_msg *segment, size_t byte, int send_stop)
 
static enum cb_err _dw_i2c_transfer (unsigned int bus, const struct i2c_msg *segments, size_t count)
 
static enum cb_err dw_i2c_transfer (unsigned int bus, const struct i2c_msg *msg, size_t count)
 
int platform_i2c_transfer (unsigned int bus, struct i2c_msg *msg, int count)
 
static enum cb_err dw_i2c_set_speed_config (unsigned int bus, const struct dw_i2c_speed_config *config)
 
static enum cb_err dw_i2c_gen_config_rise_fall_time (struct dw_i2c_regs *regs, enum i2c_speed speed, const struct dw_i2c_bus_config *bcfg, int ic_clk, struct dw_i2c_speed_config *config)
 
enum cb_err dw_i2c_gen_speed_config (uintptr_t dw_i2c_addr, enum i2c_speed speed, const struct dw_i2c_bus_config *bcfg, struct dw_i2c_speed_config *config)
 
static enum cb_err dw_i2c_set_speed (unsigned int bus, enum i2c_speed speed, const struct dw_i2c_bus_config *bcfg)
 
enum cb_err dw_i2c_init (unsigned int bus, const struct dw_i2c_bus_config *bcfg)
 
static void dw_i2c_acpi_write_speed_config (const struct dw_i2c_speed_config *config)
 
void dw_i2c_dev_init (struct device *dev)
 
void dw_i2c_acpi_fill_ssdt (const struct device *dev)
 
static int dw_i2c_dev_transfer (struct device *dev, const struct i2c_msg *msg, size_t count)
 

Variables

struct dw_i2c_regs __packed
 
static const struct i2c_descriptor speed_descriptors []
 
static const struct soc_clock soc_clocks []
 
const struct i2c_bus_operations dw_i2c_bus_ops
 

Macro Definition Documentation

◆ DW_I2C_COMP_TYPE

#define DW_I2C_COMP_TYPE   0x44570140

Definition at line 147 of file dw_i2c.c.

◆ DW_I2C_FLUSH_TIMEOUT_US

#define DW_I2C_FLUSH_TIMEOUT_US   160000

Definition at line 17 of file dw_i2c.c.

◆ DW_I2C_TIMEOUT_US

#define DW_I2C_TIMEOUT_US   10000

Definition at line 15 of file dw_i2c.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
DEFAULT_SDA_HOLD_TIME 
MIN_SS_SCL_HIGHTIME 
MIN_SS_SCL_LOWTIME 
MIN_FS_SCL_HIGHTIME 
MIN_FS_SCL_LOWTIME 
MIN_FP_SCL_HIGHTIME 
MIN_FP_SCL_LOWTIME 
MIN_HS_SCL_HIGHTIME 
MIN_HS_SCL_LOWTIME 

Definition at line 20 of file dw_i2c.c.

◆ anonymous enum

anonymous enum
Enumerator
CONTROL_MASTER_MODE 
CONTROL_SPEED_SS 
CONTROL_SPEED_FS 
CONTROL_SPEED_HS 
CONTROL_SPEED_MASK 
CONTROL_10BIT_SLAVE 
CONTROL_10BIT_MASTER 
CONTROL_RESTART_ENABLE 
CONTROL_SLAVE_DISABLE 

Definition at line 45 of file dw_i2c.c.

◆ anonymous enum

anonymous enum
Enumerator
CMD_DATA_CMD 
CMD_DATA_STOP 

Definition at line 58 of file dw_i2c.c.

◆ anonymous enum

anonymous enum
Enumerator
STATUS_ACTIVITY 
STATUS_TX_FIFO_NOT_FULL 
STATUS_TX_FIFO_EMPTY 
STATUS_RX_FIFO_NOT_EMPTY 
STATUS_RX_FIFO_FULL 
STATUS_MASTER_ACTIVITY 
STATUS_SLAVE_ACTIVITY 

Definition at line 64 of file dw_i2c.c.

◆ anonymous enum

anonymous enum
Enumerator
ENABLE_CONTROLLER 

Definition at line 75 of file dw_i2c.c.

◆ anonymous enum

anonymous enum
Enumerator
INTR_STAT_RX_UNDER 
INTR_STAT_RX_OVER 
INTR_STAT_RX_FULL 
INTR_STAT_TX_OVER 
INTR_STAT_TX_EMPTY 
INTR_STAT_RD_REQ 
INTR_STAT_TX_ABORT 
INTR_STAT_RX_DONE 
INTR_STAT_ACTIVITY 
INTR_STAT_STOP_DET 
INTR_STAT_START_DET 
INTR_STAT_GEN_CALL 

Definition at line 80 of file dw_i2c.c.

Function Documentation

◆ _dw_i2c_transfer()

static enum cb_err _dw_i2c_transfer ( unsigned int  bus,
const struct i2c_msg segments,
size_t  count 
)
static

Definition at line 261 of file dw_i2c.c.

References ENABLE_CONTROLLER, read32(), and write32().

Here is the call graph for this function:

◆ counts_from_freq()

static int counts_from_freq ( const struct freq fast,
const struct freq slow 
)
static

Definition at line 255 of file dw_i2c.c.

References DIV_ROUND_UP, freq::ns, and freq::ticks.

◆ counts_from_time()

static int counts_from_time ( const struct freq f,
int  ns 
)
static

Definition at line 250 of file dw_i2c.c.

References DIV_ROUND_UP, freq::ns, and freq::ticks.

◆ dw_i2c_acpi_fill_ssdt()

◆ dw_i2c_acpi_write_speed_config()

static void dw_i2c_acpi_write_speed_config ( const struct dw_i2c_speed_config config)
static

Definition at line 753 of file dw_i2c.c.

References acpigen_pop_len(), acpigen_write_dword(), acpigen_write_name(), acpigen_write_package(), acpigen_write_word(), config, I2C_SPEED_FAST, I2C_SPEED_FAST_PLUS, and I2C_SPEED_HIGH.

Referenced by dw_i2c_acpi_fill_ssdt().

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

◆ dw_i2c_dev_init()

void dw_i2c_dev_init ( struct device dev)

Definition at line 782 of file dw_i2c.c.

References config, dw_i2c_get_soc_cfg(), dw_i2c_init(), and dw_i2c_soc_dev_to_bus().

Here is the call graph for this function:

◆ dw_i2c_dev_transfer()

static int dw_i2c_dev_transfer ( struct device dev,
const struct i2c_msg msg,
size_t  count 
)
static

Definition at line 845 of file dw_i2c.c.

◆ dw_i2c_disable()

static enum cb_err dw_i2c_disable ( struct dw_i2c_regs regs)
static

Definition at line 261 of file dw_i2c.c.

◆ dw_i2c_enable()

static void dw_i2c_enable ( struct dw_i2c_regs regs)
static

Definition at line 261 of file dw_i2c.c.

◆ dw_i2c_gen_config_rise_fall_time()

static enum cb_err dw_i2c_gen_config_rise_fall_time ( struct dw_i2c_regs regs,
enum i2c_speed  speed,
const struct dw_i2c_bus_config bcfg,
int  ic_clk,
struct dw_i2c_speed_config config 
)
static

Definition at line 484 of file dw_i2c.c.

References CB_SUCCESS, count, and dw_i2c_transfer().

Here is the call graph for this function:

◆ dw_i2c_gen_speed_config()

enum cb_err dw_i2c_gen_speed_config ( uintptr_t  dw_i2c_addr,
enum i2c_speed  speed,
const struct dw_i2c_bus_config bcfg,
struct dw_i2c_speed_config config 
)

Definition at line 484 of file dw_i2c.c.

Referenced by dw_i2c_acpi_fill_ssdt().

Here is the caller graph for this function:

◆ dw_i2c_init()

enum cb_err dw_i2c_init ( unsigned int  bus,
const struct dw_i2c_bus_config bcfg 
)

Definition at line 484 of file dw_i2c.c.

Referenced by dw_i2c_dev_init(), dw_i2c_soc_init(), and lpss_i2c_early_init_bus().

Here is the caller graph for this function:

◆ dw_i2c_set_speed()

static enum cb_err dw_i2c_set_speed ( unsigned int  bus,
enum i2c_speed  speed,
const struct dw_i2c_bus_config bcfg 
)
static

Definition at line 484 of file dw_i2c.c.

◆ dw_i2c_set_speed_config()

static enum cb_err dw_i2c_set_speed_config ( unsigned int  bus,
const struct dw_i2c_speed_config config 
)
static

Definition at line 484 of file dw_i2c.c.

◆ dw_i2c_transfer()

static enum cb_err dw_i2c_transfer ( unsigned int  bus,
const struct i2c_msg msg,
size_t  count 
)
static

Definition at line 261 of file dw_i2c.c.

Referenced by dw_i2c_gen_config_rise_fall_time().

Here is the caller graph for this function:

◆ dw_i2c_transfer_byte()

static enum cb_err dw_i2c_transfer_byte ( struct dw_i2c_regs regs,
const struct i2c_msg segment,
size_t  byte,
int  send_stop 
)
static

Definition at line 261 of file dw_i2c.c.

◆ dw_i2c_wait_for_bus_idle()

static enum cb_err dw_i2c_wait_for_bus_idle ( struct dw_i2c_regs regs)
static

Definition at line 261 of file dw_i2c.c.

◆ get_bus_descriptor()

static const struct i2c_descriptor* get_bus_descriptor ( enum i2c_speed  speed)
static

Definition at line 228 of file dw_i2c.c.

References ARRAY_SIZE, NULL, i2c_descriptor::speed, and speed_descriptors.

◆ get_soc_descriptor()

static const struct soc_clock* get_soc_descriptor ( int  ic_clk)
static

Definition at line 239 of file dw_i2c.c.

References ARRAY_SIZE, soc_clock::clk_speed_mhz, NULL, and soc_clocks.

◆ platform_i2c_transfer()

int platform_i2c_transfer ( unsigned int  bus,
struct i2c_msg msg,
int  count 
)

Definition at line 484 of file dw_i2c.c.

Referenced by bdk_twsix_write_ia().

Here is the caller graph for this function:

Variable Documentation

◆ __packed

◆ dw_i2c_bus_ops

const struct i2c_bus_operations dw_i2c_bus_ops
Initial value:
= {
.transfer = dw_i2c_dev_transfer,
}
static int dw_i2c_dev_transfer(struct device *dev, const struct i2c_msg *msg, size_t count)
Definition: dw_i2c.c:845

Definition at line 845 of file dw_i2c.c.

◆ soc_clocks

const struct soc_clock soc_clocks[]
static
Initial value:
= {
{
.clk_speed_mhz = 120,
.freq = {
.ticks = 120,
.ns = 1000,
},
},
{
.clk_speed_mhz = 133,
.freq = {
.ticks = 400,
.ns = 3000,
},
},
{
.clk_speed_mhz = 150,
.freq = {
.ticks = 600,
.ns = 4000,
},
},
{
.clk_speed_mhz = 216,
.freq = {
.ticks = 1080,
.ns = 5000,
},
},
}

Referenced by get_soc_descriptor().

◆ speed_descriptors

const struct i2c_descriptor speed_descriptors[]
static

Referenced by get_bus_descriptor().