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/clk.h>
#include <soc/i2c.h>
#include <soc/periph.h>
#include <soc/pinmux.h>
#include <timer.h>
Include dependency graph for i2c.c:

Go to the source code of this file.

Data Structures

struct  i2c_regs
 
struct  hsi2c_regs
 
struct  i2c_bus
 

Macros

#define I2C_TIMEOUT_US   (1000 * USECS_PER_MSEC)
 
#define HSI2C_SLV_ADDR_MAS(x)   ((x & 0x3ff) << 10)
 

Enumerations

enum  {
  Hsi2cFuncModeI2c = 1 << 0 , Hsi2cMaster = 1 << 3 , Hsi2cRxchon = 1 << 6 , Hsi2cTxchon = 1 << 7 ,
  Hsi2cSwRst = 1 << 31
}
 
enum  {
  Hsi2cTxFifoLevel = 0x7f << 0 , Hsi2cTxFifoFull = 1 << 7 , Hsi2cTxFifoEmpty = 1 << 8 , Hsi2cRxFifoLevel = 0x7f << 16 ,
  Hsi2cRxFifoFull = 1 << 23 , Hsi2cRxFifoEmpty = 1 << 24
}
 
enum  { Hsi2cRxfifoEn = 1 << 0 , Hsi2cTxfifoEn = 1 << 1 , Hsi2cTxfifoTriggerLevel = 0x20 << 16 , Hsi2cRxfifoTriggerLevel = 0x20 << 4 }
 
enum  { Hsi2cTrailingCount = 0xff }
 
enum  { Hsi2cIntTxAlmostemptyEn = 1 << 0 , Hsi2cIntRxAlmostfullEn = 1 << 1 , Hsi2cIntTrailingEn = 1 << 6 , Hsi2cIntI2cEn = 1 << 9 }
 
enum  { Hsi2cAutoMode = 1 << 31 , Hsi2c10bitAddrMode = 1 << 30 , Hsi2cHsMode = 1 << 29 }
 
enum  { Hsi2cReadWrite = 1 << 16 , Hsi2cStopAfterTrans = 1 << 17 , Hsi2cMasterRun = 1 << 31 }
 
enum  { Hsi2cTimeoutEn = 1 << 31 }
 
enum  {
  Hsi2cMasterBusy = 1 << 17 , Hsi2cSlaveBusy = 1 << 16 , Hsi2cTimeoutAuto = 1 << 4 , Hsi2cNoDev = 1 << 3 ,
  Hsi2cNoDevAck = 1 << 2 , Hsi2cTransAbort = 1 << 1 , Hsi2cTransDone = 1 << 0
}
 
enum  { Hsi2cTimeout = 100 }
 
enum  { I2cConIntPending = 0x1 << 4 , I2cConIntEn = 0x1 << 5 , I2cConAckGen = 0x1 << 7 }
 
enum  {
  I2cStatAck = 0x1 << 0 , I2cStatAddrZero = 0x1 << 1 , I2cStatAddrSlave = 0x1 << 2 , I2cStatArb = 0x1 << 3 ,
  I2cStatEnable = 0x1 << 4 , I2cStatStartStop = 0x1 << 5 , I2cStatBusy = 0x1 << 5 , I2cStatModeMask = 0x3 << 6 ,
  I2cStatSlaveRecv = 0x0 << 6 , I2cStatSlaveXmit = 0x1 << 6 , I2cStatMasterRecv = 0x2 << 6 , I2cStatMasterXmit = 0x3 << 6
}
 

Functions

 check_member (hsi2c_regs, i2c_addr, 0x70)
 
static int hsi2c_get_clk_details (struct i2c_bus *i2c, int *div, int *cycle, unsigned int op_clk)
 
static void hsi2c_ch_init (struct i2c_bus *i2c, unsigned int frequency)
 
static void hsi2c_reset (struct i2c_bus *i2c)
 
static void i2c_ch_init (struct i2c_bus *i2c, int speed)
 
void i2c_init (unsigned int bus, int speed, int slaveadd)
 
static int hsi2c_check_transfer (struct hsi2c_regs *regs)
 
static int hsi2c_wait_for_transfer (struct hsi2c_regs *i2c)
 
static int hsi2c_senddata (struct hsi2c_regs *regs, const uint8_t *data, int len)
 
static int hsi2c_recvdata (struct hsi2c_regs *regs, uint8_t *data, int len)
 
static int hsi2c_segment (struct i2c_msg *seg, struct hsi2c_regs *regs, int stop)
 
static int hsi2c_transfer (struct i2c_bus *i2c, struct i2c_msg *segments, int count)
 
static int i2c_int_pending (struct i2c_regs *regs)
 
static void i2c_clear_int (struct i2c_regs *regs)
 
static void i2c_ack_enable (struct i2c_regs *regs)
 
static void i2c_ack_disable (struct i2c_regs *regs)
 
static int i2c_got_ack (struct i2c_regs *regs)
 
static int i2c_wait_for_idle (struct i2c_regs *regs, int timeout_us)
 
static int i2c_wait_for_int (struct i2c_regs *regs, int timeout_us)
 
static int i2c_send_stop (struct i2c_regs *regs)
 
static int i2c_send_start (struct i2c_regs *regs, int read, int chip)
 
static int i2c_xmit_buf (struct i2c_regs *regs, uint8_t *data, int len)
 
static int i2c_recv_buf (struct i2c_regs *regs, uint8_t *data, int len)
 
int platform_i2c_transfer (unsigned int bus, struct i2c_msg *segments, int count)
 

Variables

static struct i2c_bus i2c_busses []
 

Macro Definition Documentation

◆ HSI2C_SLV_ADDR_MAS

#define HSI2C_SLV_ADDR_MAS (   x)    ((x & 0x3ff) << 10)

Definition at line 212 of file i2c.c.

◆ I2C_TIMEOUT_US

#define I2C_TIMEOUT_US   (1000 * USECS_PER_MSEC)

Definition at line 14 of file i2c.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
Hsi2cFuncModeI2c 
Hsi2cMaster 
Hsi2cRxchon 
Hsi2cTxchon 
Hsi2cSwRst 

Definition at line 143 of file i2c.c.

◆ anonymous enum

anonymous enum
Enumerator
Hsi2cTxFifoLevel 
Hsi2cTxFifoFull 
Hsi2cTxFifoEmpty 
Hsi2cRxFifoLevel 
Hsi2cRxFifoFull 
Hsi2cRxFifoEmpty 

Definition at line 152 of file i2c.c.

◆ anonymous enum

anonymous enum
Enumerator
Hsi2cRxfifoEn 
Hsi2cTxfifoEn 
Hsi2cTxfifoTriggerLevel 
Hsi2cRxfifoTriggerLevel 

Definition at line 162 of file i2c.c.

◆ anonymous enum

anonymous enum
Enumerator
Hsi2cTrailingCount 

Definition at line 170 of file i2c.c.

◆ anonymous enum

anonymous enum
Enumerator
Hsi2cIntTxAlmostemptyEn 
Hsi2cIntRxAlmostfullEn 
Hsi2cIntTrailingEn 
Hsi2cIntI2cEn 

Definition at line 175 of file i2c.c.

◆ anonymous enum

anonymous enum
Enumerator
Hsi2cAutoMode 
Hsi2c10bitAddrMode 
Hsi2cHsMode 

Definition at line 183 of file i2c.c.

◆ anonymous enum

anonymous enum
Enumerator
Hsi2cReadWrite 
Hsi2cStopAfterTrans 
Hsi2cMasterRun 

Definition at line 190 of file i2c.c.

◆ anonymous enum

anonymous enum
Enumerator
Hsi2cTimeoutEn 

Definition at line 197 of file i2c.c.

◆ anonymous enum

anonymous enum
Enumerator
Hsi2cMasterBusy 
Hsi2cSlaveBusy 
Hsi2cTimeoutAuto 
Hsi2cNoDev 
Hsi2cNoDevAck 
Hsi2cTransAbort 
Hsi2cTransDone 

Definition at line 202 of file i2c.c.

◆ anonymous enum

anonymous enum
Enumerator
Hsi2cTimeout 

Definition at line 214 of file i2c.c.

◆ anonymous enum

anonymous enum
Enumerator
I2cConIntPending 
I2cConIntEn 
I2cConAckGen 

Definition at line 218 of file i2c.c.

◆ anonymous enum

anonymous enum
Enumerator
I2cStatAck 
I2cStatAddrZero 
I2cStatAddrSlave 
I2cStatArb 
I2cStatEnable 
I2cStatStartStop 
I2cStatBusy 
I2cStatModeMask 
I2cStatSlaveRecv 
I2cStatSlaveXmit 
I2cStatMasterRecv 
I2cStatMasterXmit 

Definition at line 224 of file i2c.c.

Function Documentation

◆ check_member()

check_member ( hsi2c_regs  ,
i2c_addr  ,
0x70   
)

◆ hsi2c_ch_init()

static void hsi2c_ch_init ( struct i2c_bus i2c,
unsigned int  frequency 
)
static

Definition at line 269 of file i2c.c.

References hsi2c_get_clk_details(), Hsi2cAutoMode, Hsi2cRxfifoEn, Hsi2cTimeoutEn, Hsi2cTrailingCount, Hsi2cTxfifoEn, i2c_bus::hsregs, read32(), and write32().

Referenced by hsi2c_reset(), and i2c_init().

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

◆ hsi2c_check_transfer()

static int hsi2c_check_transfer ( struct hsi2c_regs regs)
static

Definition at line 366 of file i2c.c.

References BIOS_ERR, Hsi2cMasterBusy, Hsi2cNoDev, Hsi2cNoDevAck, Hsi2cTimeoutAuto, Hsi2cTransAbort, printk, and read32().

Referenced by hsi2c_recvdata(), hsi2c_senddata(), and hsi2c_wait_for_transfer().

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

◆ hsi2c_get_clk_details()

static int hsi2c_get_clk_details ( struct i2c_bus i2c,
int *  div,
int *  cycle,
unsigned int  op_clk 
)
static

Definition at line 240 of file i2c.c.

References BIOS_ERR, clock_get_periph_rate(), i2c_bus::hsregs, i2c_bus::periph_id, printk, and read32().

Referenced by hsi2c_ch_init().

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

◆ hsi2c_recvdata()

static int hsi2c_recvdata ( struct hsi2c_regs regs,
uint8_t data,
int  len 
)
static

Definition at line 419 of file i2c.c.

References hsi2c_check_transfer(), Hsi2cRxFifoEmpty, and read32().

Referenced by hsi2c_segment().

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

◆ hsi2c_reset()

static void hsi2c_reset ( struct i2c_bus i2c)
static

Definition at line 306 of file i2c.c.

References hsi2c_ch_init(), Hsi2cSwRst, i2c_bus::hsregs, read32(), and write32().

Referenced by hsi2c_transfer(), and i2c_init().

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

◆ hsi2c_segment()

static int hsi2c_segment ( struct i2c_msg seg,
struct hsi2c_regs regs,
int  stop 
)
static

Definition at line 430 of file i2c.c.

References i2c_msg::buf, i2c_msg::flags, hsi2c_recvdata(), hsi2c_senddata(), HSI2C_SLV_ADDR_MAS, hsi2c_wait_for_transfer(), Hsi2cFuncModeI2c, Hsi2cMaster, Hsi2cMasterRun, Hsi2cReadWrite, Hsi2cRxchon, Hsi2cStopAfterTrans, Hsi2cTxchon, I2C_M_RD, i2c_msg::len, i2c_msg::slave, and write32().

Referenced by hsi2c_transfer().

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

◆ hsi2c_senddata()

static int hsi2c_senddata ( struct hsi2c_regs regs,
const uint8_t data,
int  len 
)
static

Definition at line 408 of file i2c.c.

References hsi2c_check_transfer(), Hsi2cTxFifoFull, read32(), and write32().

Referenced by hsi2c_segment().

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

◆ hsi2c_transfer()

static int hsi2c_transfer ( struct i2c_bus i2c,
struct i2c_msg segments,
int  count 
)
static

Definition at line 468 of file i2c.c.

References count, hsi2c_reset(), hsi2c_segment(), hsi2c_wait_for_transfer(), and i2c_bus::hsregs.

Referenced by platform_i2c_transfer().

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

◆ hsi2c_wait_for_transfer()

static int hsi2c_wait_for_transfer ( struct hsi2c_regs i2c)
static

Definition at line 395 of file i2c.c.

References hsi2c_check_transfer(), Hsi2cTimeout, stopwatch_expired(), and stopwatch_init_msecs_expire().

Referenced by hsi2c_segment(), and hsi2c_transfer().

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

◆ i2c_ack_disable()

static void i2c_ack_disable ( struct i2c_regs regs)
static

Definition at line 503 of file i2c.c.

References I2cConAckGen, read8(), and write8().

Referenced by i2c_recv_buf().

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

◆ i2c_ack_enable()

static void i2c_ack_enable ( struct i2c_regs regs)
static

Definition at line 498 of file i2c.c.

References I2cConAckGen, read8(), and write8().

Referenced by i2c_recv_buf(), and i2c_xmit_buf().

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

◆ i2c_ch_init()

static void i2c_ch_init ( struct i2c_bus i2c,
int  speed 
)
static

Definition at line 318 of file i2c.c.

References clock_get_periph_rate(), I2cStatEnable, I2cStatMasterXmit, i2c_bus::periph_id, i2c_bus::regs, val, and write32().

Referenced by i2c_init().

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

◆ i2c_clear_int()

static void i2c_clear_int ( struct i2c_regs regs)
static

Definition at line 493 of file i2c.c.

References I2cConIntPending, read8(), and write8().

Referenced by i2c_recv_buf(), i2c_send_start(), i2c_send_stop(), and i2c_xmit_buf().

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

◆ i2c_got_ack()

static int i2c_got_ack ( struct i2c_regs regs)
static

Definition at line 508 of file i2c.c.

References I2cStatAck, and read8().

Referenced by i2c_send_start(), and i2c_xmit_buf().

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

◆ i2c_init()

void i2c_init ( unsigned int  bus,
int  speed,
int  slaveadd 
)

◆ i2c_int_pending()

static int i2c_int_pending ( struct i2c_regs regs)
static

Definition at line 488 of file i2c.c.

References I2cConIntPending, and read8().

Referenced by i2c_wait_for_int().

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

◆ i2c_recv_buf()

static int i2c_recv_buf ( struct i2c_regs regs,
uint8_t data,
int  len 
)
static

Definition at line 586 of file i2c.c.

References ASSERT, i2c_ack_disable(), i2c_ack_enable(), i2c_clear_int(), i2c_wait_for_int(), and read8().

Referenced by platform_i2c_transfer().

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

◆ i2c_send_start()

static int i2c_send_start ( struct i2c_regs regs,
int  read,
int  chip 
)
static

Definition at line 545 of file i2c.c.

References chip, i2c_clear_int(), i2c_got_ack(), I2C_TIMEOUT_US, i2c_wait_for_int(), I2cStatEnable, I2cStatMasterRecv, I2cStatMasterXmit, I2cStatStartStop, and write8().

Referenced by platform_i2c_transfer().

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 i2c_regs regs)
static

Definition at line 537 of file i2c.c.

References i2c_clear_int(), I2C_TIMEOUT_US, i2c_wait_for_idle(), I2cStatEnable, I2cStatModeMask, read8(), and write8().

Referenced by platform_i2c_transfer().

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

◆ i2c_wait_for_idle()

static int i2c_wait_for_idle ( struct i2c_regs regs,
int  timeout_us 
)
static

Definition at line 513 of file i2c.c.

References BIOS_ERR, I2cStatBusy, printk, read8(), and udelay().

Referenced by i2c_send_stop(), and platform_i2c_transfer().

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

◆ i2c_wait_for_int()

static int i2c_wait_for_int ( struct i2c_regs regs,
int  timeout_us 
)
static

Definition at line 525 of file i2c.c.

References BIOS_ERR, i2c_int_pending(), printk, and udelay().

Referenced by i2c_recv_buf(), i2c_send_start(), and i2c_xmit_buf().

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

◆ i2c_xmit_buf()

static int i2c_xmit_buf ( struct i2c_regs regs,
uint8_t data,
int  len 
)
static

Definition at line 563 of file i2c.c.

References ASSERT, BIOS_INFO, i2c_ack_enable(), i2c_clear_int(), i2c_got_ack(), i2c_wait_for_int(), printk, and write8().

Referenced by platform_i2c_transfer().

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

◆ platform_i2c_transfer()

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

Definition at line 607 of file i2c.c.

References i2c_msg::buf, count, i2c_msg::flags, hsi2c_transfer(), i2c_busses, I2C_M_RD, i2c_recv_buf(), i2c_send_start(), i2c_send_stop(), I2C_TIMEOUT_US, i2c_wait_for_idle(), i2c_xmit_buf(), I2cStatEnable, I2cStatMasterXmit, i2c_bus::is_highspeed, i2c_msg::len, i2c_bus::regs, i2c_msg::slave, and write8().

Referenced by i2c_transfer().

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

Variable Documentation

◆ i2c_busses

struct i2c_bus i2c_busses[]
static

Definition at line 62 of file i2c.c.

Referenced by i2c_init(), and platform_i2c_transfer().