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

Go to the source code of this file.

Functions

__weak void mtk_i2c_dump_more_info (struct mt_i2c_regs *regs)
 
__weak void mtk_i2c_config_timing (struct mt_i2c_regs *regs, struct mtk_i2c *bus_ctrl)
 
const struct i2c_spec_valuesmtk_i2c_get_spec (uint32_t speed)
 
static void i2c_hw_reset (uint8_t bus)
 
static void mtk_i2c_dump_info (struct mt_i2c_regs *regs)
 
static int mtk_i2c_transfer (uint8_t bus, struct i2c_msg *seg, enum i2c_modes mode)
 
static bool mtk_i2c_should_combine (struct i2c_msg *seg, int left_count)
 
static int mtk_i2c_max_step_cnt (uint32_t target_speed)
 
int platform_i2c_transfer (unsigned int bus, struct i2c_msg *segments, int seg_count)
 
int mtk_i2c_check_ac_timing (uint8_t bus, uint32_t clk_src, uint32_t check_speed, uint32_t step_cnt, uint32_t sample_cnt)
 
int mtk_i2c_calculate_speed (uint8_t bus, uint32_t clk_src, uint32_t target_speed, uint32_t *timing_step_cnt, uint32_t *timing_sample_cnt)
 
void mtk_i2c_speed_init (uint8_t bus, uint32_t speed)
 

Variables

const struct i2c_spec_values standard_mode_spec
 
const struct i2c_spec_values fast_mode_spec
 
const struct i2c_spec_values fast_mode_plus_spec
 

Function Documentation

◆ i2c_hw_reset()

static void i2c_hw_reset ( uint8_t  bus)
inlinestatic

Definition at line 55 of file i2c.c.

References mt_i2c_dma_regs::dma_rst, I2C_APDMA_ASYNC, I2C_CLR_FLAG, I2C_DMA_CLR_FLAG, I2C_DMA_HANDSHAKE_RST, I2C_DMA_HARD_RST, mtk_i2c::i2c_dma_regs, I2C_DMA_WARM_RST, I2C_HANDSHAKE_RST, mtk_i2c::i2c_regs, I2C_SOFT_RST, mtk_i2c_bus_controller, regs, udelay(), and write32().

Referenced by mtk_i2c_transfer().

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

◆ mtk_i2c_calculate_speed()

int mtk_i2c_calculate_speed ( uint8_t  bus,
uint32_t  clk_src,
uint32_t  target_speed,
uint32_t timing_step_cnt,
uint32_t timing_sample_cnt 
)

Definition at line 408 of file i2c.c.

References mtk_i2c::ac_timing, DIV_ROUND_UP, I2C_SPEED_HIGH, mtk_i2c_ac_timing::inter_clk_div, MAX_SAMPLE_CNT_DIV, mtk_i2c_bus_controller, mtk_i2c_check_ac_timing(), and mtk_i2c_max_step_cnt().

Referenced by mtk_i2c_speed_init().

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

◆ mtk_i2c_check_ac_timing()

◆ mtk_i2c_config_timing()

__weak void mtk_i2c_config_timing ( struct mt_i2c_regs regs,
struct mtk_i2c bus_ctrl 
)

Definition at line 40 of file i2c.c.

Referenced by mtk_i2c_speed_init().

Here is the caller graph for this function:

◆ mtk_i2c_dump_info()

static void mtk_i2c_dump_info ( struct mt_i2c_regs regs)
inlinestatic

Definition at line 85 of file i2c.c.

References BIOS_DEBUG, mtk_i2c_dump_more_info(), printk, and read32().

Referenced by mtk_i2c_transfer().

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

◆ mtk_i2c_dump_more_info()

__weak void mtk_i2c_dump_more_info ( struct mt_i2c_regs regs)

Definition at line 35 of file i2c.c.

Referenced by mtk_i2c_dump_info().

Here is the caller graph for this function:

◆ mtk_i2c_get_spec()

const struct i2c_spec_values* mtk_i2c_get_spec ( uint32_t  speed)

Definition at line 45 of file i2c.c.

References fast_mode_plus_spec, fast_mode_spec, I2C_SPEED_FAST, I2C_SPEED_STANDARD, and standard_mode_spec.

Referenced by mtk_i2c_check_ac_timing().

Here is the caller graph for this function:

◆ mtk_i2c_max_step_cnt()

static int mtk_i2c_max_step_cnt ( uint32_t  target_speed)
static

Definition at line 293 of file i2c.c.

References I2C_SPEED_FAST_PLUS, MAX_HS_STEP_CNT_DIV, and MAX_STEP_CNT_DIV.

Referenced by mtk_i2c_calculate_speed(), and mtk_i2c_check_ac_timing().

Here is the caller graph for this function:

◆ mtk_i2c_should_combine()

static bool mtk_i2c_should_combine ( struct i2c_msg seg,
int  left_count 
)
static

Definition at line 285 of file i2c.c.

References I2C_M_RD, and slave.

Referenced by platform_i2c_transfer().

Here is the caller graph for this function:

◆ mtk_i2c_speed_init()

void mtk_i2c_speed_init ( uint8_t  bus,
uint32_t  speed 
)

◆ mtk_i2c_transfer()

◆ platform_i2c_transfer()

int platform_i2c_transfer ( unsigned int  bus,
struct i2c_msg segments,
int  seg_count 
)

Definition at line 301 of file i2c.c.

References i2c_msg::flags, I2C_M_RD, I2C_READ_MODE, I2C_WRITE_MODE, I2C_WRITE_READ_MODE, mtk_i2c_should_combine(), and mtk_i2c_transfer().

Here is the call graph for this function:

Variable Documentation

◆ fast_mode_plus_spec

const struct i2c_spec_values fast_mode_plus_spec
Initial value:
= {
.min_low_ns = 500 + I2C_FAST_MODE_PLUS_BUFFER,
.min_su_sta_ns = 260 + I2C_FAST_MODE_PLUS_BUFFER,
.max_hd_dat_ns = 400 - I2C_FAST_MODE_PLUS_BUFFER,
.min_su_dat_ns = 50 + I2C_FAST_MODE_PLUS_BUFFER,
}
#define I2C_FAST_MODE_PLUS_BUFFER
Definition: i2c_common.h:126

Definition at line 1 of file i2c.c.

Referenced by mtk_i2c_get_spec().

◆ fast_mode_spec

const struct i2c_spec_values fast_mode_spec
Initial value:
= {
.min_low_ns = 1300 + I2C_FAST_MODE_BUFFER,
.min_su_sta_ns = 600 + I2C_FAST_MODE_BUFFER,
.max_hd_dat_ns = 900 - I2C_FAST_MODE_BUFFER,
.min_su_dat_ns = 100 + I2C_FAST_MODE_BUFFER,
}
#define I2C_FAST_MODE_BUFFER
Definition: i2c_common.h:125

Definition at line 1 of file i2c.c.

Referenced by mtk_i2c_get_spec().

◆ standard_mode_spec

const struct i2c_spec_values standard_mode_spec
Initial value:
= {
.min_low_ns = 4700 + I2C_STANDARD_MODE_BUFFER,
.min_su_sta_ns = 4700 + I2C_STANDARD_MODE_BUFFER,
.max_hd_dat_ns = 3450 - I2C_STANDARD_MODE_BUFFER,
.min_su_dat_ns = 250 + I2C_STANDARD_MODE_BUFFER,
}
#define I2C_STANDARD_MODE_BUFFER
Definition: i2c_common.h:124

Definition at line 1 of file i2c.c.

Referenced by mtk_i2c_get_spec().