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

Go to the source code of this file.

Data Structures

struct  rk_i2c_regs
 

Macros

#define RETRY_COUNT   3
 
#define I2C_TIMEOUT_US   100000
 
#define I2C_BUS_MAX   6
 
#define I2C_NOACK   2
 
#define I2C_TIMEOUT   3
 
#define i2c_info(x...)   do {if (0) printk(BIOS_DEBUG, x); } while (0)
 
#define I2C_ACT2NAK   (1<<6)
 
#define I2C_NAK   (1<<5)
 
#define I2C_STOP   (1<<4)
 
#define I2C_START   (1<<3)
 
#define I2C_MODE_TX   (0<<1)
 
#define I2C_MODE_TRX   (1<<1)
 
#define I2C_MODE_RX   (2<<1)
 
#define I2C_EN   (1<<0)
 
#define I2C_8BIT   (1<<24)
 
#define I2C_16BIT   (3<<24)
 
#define I2C_24BIT   (7<<24)
 
#define I2C_CNT(cnt)   ((cnt) & 0x3F)
 
#define I2C_NAKRCVI   (1<<6)
 
#define I2C_STOPI   (1<<5)
 
#define I2C_STARTI   (1<<4)
 
#define I2C_MBRFI   (1<<3)
 
#define I2C_MBTFI   (1<<2)
 
#define I2C_BRFI   (1<<1)
 
#define I2C_BTFI   (1<<0)
 
#define I2C_CLEANI   0x7F
 

Functions

static int i2c_send_start (struct rk_i2c_regs *reg_addr)
 
static int i2c_send_stop (struct rk_i2c_regs *reg_addr)
 
static int i2c_read (struct rk_i2c_regs *reg_addr, struct i2c_msg segment)
 
static int i2c_write (struct rk_i2c_regs *reg_addr, struct i2c_msg segment)
 
static int i2c_do_xfer (void *reg_addr, struct i2c_msg segment)
 
int platform_i2c_transfer (unsigned int bus, struct i2c_msg *segments, int seg_count)
 
void i2c_init (unsigned int bus, unsigned int hz)
 

Variables

static const uintptr_t i2c_bus [] = IC_BASES
 

Macro Definition Documentation

◆ I2C_16BIT

#define I2C_16BIT   (3<<24)

Definition at line 54 of file i2c.c.

◆ I2C_24BIT

#define I2C_24BIT   (7<<24)

Definition at line 55 of file i2c.c.

◆ I2C_8BIT

#define I2C_8BIT   (1<<24)

Definition at line 53 of file i2c.c.

◆ I2C_ACT2NAK

#define I2C_ACT2NAK   (1<<6)

Definition at line 44 of file i2c.c.

◆ I2C_BRFI

#define I2C_BRFI   (1<<1)

Definition at line 65 of file i2c.c.

◆ I2C_BTFI

#define I2C_BTFI   (1<<0)

Definition at line 66 of file i2c.c.

◆ I2C_BUS_MAX

#define I2C_BUS_MAX   6

Definition at line 19 of file i2c.c.

◆ I2C_CLEANI

#define I2C_CLEANI   0x7F

Definition at line 67 of file i2c.c.

◆ I2C_CNT

#define I2C_CNT (   cnt)    ((cnt) & 0x3F)

Definition at line 58 of file i2c.c.

◆ I2C_EN

#define I2C_EN   (1<<0)

Definition at line 51 of file i2c.c.

◆ i2c_info

#define i2c_info (   x...)    do {if (0) printk(BIOS_DEBUG, x); } while (0)

Definition at line 23 of file i2c.c.

◆ I2C_MBRFI

#define I2C_MBRFI   (1<<3)

Definition at line 63 of file i2c.c.

◆ I2C_MBTFI

#define I2C_MBTFI   (1<<2)

Definition at line 64 of file i2c.c.

◆ I2C_MODE_RX

#define I2C_MODE_RX   (2<<1)

Definition at line 50 of file i2c.c.

◆ I2C_MODE_TRX

#define I2C_MODE_TRX   (1<<1)

Definition at line 49 of file i2c.c.

◆ I2C_MODE_TX

#define I2C_MODE_TX   (0<<1)

Definition at line 48 of file i2c.c.

◆ I2C_NAK

#define I2C_NAK   (1<<5)

Definition at line 45 of file i2c.c.

◆ I2C_NAKRCVI

#define I2C_NAKRCVI   (1<<6)

Definition at line 60 of file i2c.c.

◆ I2C_NOACK

#define I2C_NOACK   2

Definition at line 20 of file i2c.c.

◆ I2C_START

#define I2C_START   (1<<3)

Definition at line 47 of file i2c.c.

◆ I2C_STARTI

#define I2C_STARTI   (1<<4)

Definition at line 62 of file i2c.c.

◆ I2C_STOP

#define I2C_STOP   (1<<4)

Definition at line 46 of file i2c.c.

◆ I2C_STOPI

#define I2C_STOPI   (1<<5)

Definition at line 61 of file i2c.c.

◆ I2C_TIMEOUT

#define I2C_TIMEOUT   3

Definition at line 21 of file i2c.c.

◆ I2C_TIMEOUT_US

#define I2C_TIMEOUT_US   100000

Definition at line 18 of file i2c.c.

◆ RETRY_COUNT

#define RETRY_COUNT   3

Definition at line 16 of file i2c.c.

Function Documentation

◆ i2c_do_xfer()

static int i2c_do_xfer ( void reg_addr,
struct i2c_msg  segment 
)
static

Definition at line 207 of file i2c.c.

References i2c_msg::flags, I2C_M_RD, i2c_read(), i2c_send_start(), i2c_send_stop(), I2C_TIMEOUT, and i2c_write().

Referenced by platform_i2c_transfer().

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

◆ i2c_init()

void i2c_init ( unsigned int  bus,
unsigned int  hz 
)

Definition at line 236 of file i2c.c.

References assert, BIOS_DEBUG, DIV_ROUND_UP, KHz, printk, rkclk_i2c_clock_for_bus(), and write32().

Here is the call graph for this function:

◆ i2c_read()

static int i2c_read ( struct rk_i2c_regs reg_addr,
struct i2c_msg  segment 
)
static

◆ i2c_send_start()

static int i2c_send_start ( struct rk_i2c_regs reg_addr)
static

Definition at line 69 of file i2c.c.

References BIOS_ERR, I2C_CLEANI, rk_i2c_regs::i2c_con, I2C_EN, i2c_info, rk_i2c_regs::i2c_ipd, I2C_START, I2C_STARTI, I2C_TIMEOUT, I2C_TIMEOUT_US, printk, read32(), udelay(), and write32().

Referenced by i2c_do_xfer().

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

◆ i2c_send_stop()

static int i2c_send_stop ( struct rk_i2c_regs reg_addr)
static

Definition at line 91 of file i2c.c.

References BIOS_ERR, I2C_CLEANI, rk_i2c_regs::i2c_con, I2C_EN, i2c_info, rk_i2c_regs::i2c_ipd, I2C_STOP, I2C_STOPI, I2C_TIMEOUT, I2C_TIMEOUT_US, printk, read32(), udelay(), and write32().

Referenced by i2c_do_xfer().

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

◆ i2c_write()

static int i2c_write ( struct rk_i2c_regs reg_addr,
struct i2c_msg  segment 
)
static

◆ platform_i2c_transfer()

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

Definition at line 220 of file i2c.c.

References i2c_do_xfer().

Here is the call graph for this function:

Variable Documentation

◆ i2c_bus

const uintptr_t i2c_bus[] = IC_BASES
static

Definition at line 41 of file i2c.c.

Referenced by read_edid_from_ps8640(), and ww_ring_init().