coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
|
#include <console/console.h>
#include <soc/twsi.h>
#include <soc/clock.h>
#include <device/i2c.h>
#include <device/i2c_simple.h>
#include <delay.h>
#include <device/mmio.h>
#include <soc/addressmap.h>
#include <timer.h>
Go to the source code of this file.
Data Structures | |
union | twsx_sw_twsi |
union | twsx_sw_twsi_ext |
union | twsx_int |
Macros | |
#define | TWSI_THP 24 |
#define | TWSI_SW_TWSI 0x1000 |
#define | TWSI_TWSI_SW 0x1008 |
#define | TWSI_INT 0x1010 |
#define | TWSI_SW_TWSI_EXT 0x1018 |
#define | RST_BOOT_PNR_MUL(Val) ((Val >> 33) & 0x1F) |
Functions | |
static int | twsi_i2c_lost_arb (u8 code, int final_read) |
Returns true if we lost arbitration. More... | |
static u64 | twsi_write_sw (void *baseaddr, union twsx_sw_twsi sw_twsi) |
Writes to the MIO_TWS(0..5)_SW_TWSI register. More... | |
static u64 | twsi_read_sw (void *baseaddr, union twsx_sw_twsi sw_twsi) |
Reads the MIO_TWS(0..5)_SW_TWSI register. More... | |
static void | twsi_write_ctl (void *baseaddr, const u8 data) |
Write control register. More... | |
static u32 | twsi_read_ctl (void *baseaddr) |
Reads the TWSI Control Register. More... | |
static u8 | twsi_read_status (void *baseaddr) |
Read i2c status register. More... | |
static int | twsi_wait (void *baseaddr, struct stopwatch *timeout) |
Waits for an i2c operation to complete. More... | |
static int | twsi_stop (void *baseaddr) |
Sends an i2c stop condition. More... | |
static void | twsi_unblock (void *baseaddr) |
Manually clear the I2C bus and send a stop. More... | |
static int | twsi_start_unstick (void *baseaddr) |
Unsticks the i2c bus. More... | |
static int | twsi_start (void *baseaddr) |
Sends an i2c start condition. More... | |
static int | twsi_write_data (void *baseaddr, const u8 slave_addr, const u8 *buffer, const unsigned int length) |
Writes data to the i2c bus. More... | |
static int | twsi_read_data (void *baseaddr, const u8 slave_addr, u8 *buffer, const unsigned int length) |
Performs a read transaction on the i2c bus. More... | |
static int | twsi_set_speed (void *baseaddr, const unsigned int speed) |
int | twsi_init (unsigned int bus, enum i2c_speed hz) |
int | platform_i2c_transfer (unsigned int bus, struct i2c_msg *segments, int seg_count) |
anonymous enum |
anonymous enum |
anonymous enum |
anonymous enum |
Definition at line 664 of file twsi.c.
References BIOS_ERR, BIOS_SPEW, i2c_msg::buf, i2c_msg::flags, I2C_M_RD, i2c_msg::len, MIO_TWSx_PF_BAR0, printk, i2c_msg::slave, twsi_read_data(), and twsi_write_data().
|
static |
Returns true if we lost arbitration.
code | status code |
final_read | true if this is the final read operation |
Definition at line 180 of file twsi.c.
References TWSI_STAT_GEN_RXADDR_ACK, TWSI_STAT_GEN_RXADDR_NAK, TWSI_STAT_RX_GEN_ADDR_ACK, TWSI_STAT_RX_GEN_ADDR_ARB_LOST, TWSI_STAT_RXADDR_NAK, TWSI_STAT_RXDATA_ACK_ARB_LOST, TWSI_STAT_RXDATA_ACK_SENT, TWSI_STAT_RXDATA_NAK_SENT, TWSI_STAT_SLAVE_RXADDR2_ACK, TWSI_STAT_SLAVE_RXADDR_ACK, TWSI_STAT_SLAVE_RXDATA_ACK, TWSI_STAT_SLAVE_RXDATA_NAK, TWSI_STAT_SLAVE_TXDATA_ACK, TWSI_STAT_SLAVE_TXDATA_END_ACK, TWSI_STAT_SLAVE_TXDATA_NAK, TWSI_STAT_STOP_MULTI_START, TWSI_STAT_TX_ACK_ARB_LOST, TWSI_STAT_TX_ARB_LOST, TWSI_STAT_TXADDR2DATA_NAK, TWSI_STAT_TXADDR_NAK, and TWSI_STAT_TXDATA_NAK.
Referenced by twsi_read_data(), and twsi_write_data().
Definition at line 649 of file twsi.c.
References MIO_TWSx_PF_BAR0, TWSI_CTL_ENAB, twsi_set_speed(), and twsi_write_ctl().
Referenced by mainboard_enable().
Reads the TWSI Control Register.
[in] | baseaddr | Base address for i2c |
Definition at line 314 of file twsi.c.
References BIOS_SPEW, twsx_sw_twsi::data, twsx_sw_twsi::eop_ia, twsx_sw_twsi::op, printk, twsx_sw_twsi::s, TWSI_CTL, twsi_read_sw(), TWSI_SW_EOP_IA, and twsx_sw_twsi::u.
Referenced by twsi_wait().
|
static |
Performs a read transaction on the i2c bus.
baseaddr | Base address of twsi registers |
slave_addr | i2c bus address to read from |
buffer | buffer to read into |
length | number of bytes to read |
Definition at line 549 of file twsi.c.
References BIOS_ERR, BIOS_SPEW, buffer, twsx_sw_twsi::data, twsx_sw_twsi::eop_ia, length, twsx_sw_twsi::op, printk, twsx_sw_twsi::s, stopwatch_init_usecs_expire(), TWSI_CTL_AAK, TWSI_CTL_ENAB, TWSI_DATA, twsi_i2c_lost_arb(), TWSI_OP_READ, twsi_read_status(), twsi_read_sw(), twsi_start(), TWSI_STAT_RXADDR_ACK, twsi_stop(), TWSI_SW_EOP_IA, twsi_wait(), twsi_write_ctl(), twsi_write_sw(), and twsx_sw_twsi::u.
Referenced by platform_i2c_transfer().
Read i2c status register.
baseaddr | Base address of i2c registers |
Definition at line 334 of file twsi.c.
References twsx_sw_twsi::eop_ia, twsx_sw_twsi::op, twsx_sw_twsi::s, twsi_read_sw(), TWSI_STAT, TWSI_SW_EOP_IA, and twsx_sw_twsi::u.
Referenced by twsi_read_data(), twsi_start(), twsi_stop(), and twsi_write_data().
|
static |
Reads the MIO_TWS(0..5)_SW_TWSI register.
baseaddr | Base address of i2c registers |
sw_twsi | value for eia and op, etc. to read |
Definition at line 265 of file twsi.c.
References BIOS_ERR, BIOS_SPEW, printk, twsx_sw_twsi::r, read64(), twsx_sw_twsi::s, TWSI_SW_TWSI, twsx_sw_twsi::u, twsx_sw_twsi::v, and write64().
Referenced by twsi_read_ctl(), twsi_read_data(), and twsi_read_status().
Definition at line 614 of file twsi.c.
References twsx_sw_twsi::data, twsx_sw_twsi::eop_ia, twsx_sw_twsi::op, twsx_sw_twsi::r, twsx_sw_twsi::s, thunderx_get_io_clock(), TWSI_THP, twsi_write_sw(), twsx_sw_twsi::u, and twsx_sw_twsi::v.
Referenced by twsi_init().
|
static |
Sends an i2c start condition.
baseaddr | base address of registers |
Definition at line 436 of file twsi.c.
References BIOS_SPEW, printk, stopwatch_init_usecs_expire(), TWSI_CTL_ENAB, TWSI_CTL_STA, twsi_read_status(), twsi_start_unstick(), TWSI_STAT_RSTART, TWSI_STAT_RXADDR_ACK, TWSI_STAT_START, twsi_wait(), and twsi_write_ctl().
Referenced by twsi_read_data(), and twsi_write_data().
|
static |
Unsticks the i2c bus.
baseaddr | base address of registers |
Definition at line 420 of file twsi.c.
References twsi_stop(), and twsi_unblock().
Referenced by twsi_start().
|
static |
Sends an i2c stop condition.
baseaddr | register base address |
Definition at line 373 of file twsi.c.
References BIOS_ERR, printk, TWSI_CTL_ENAB, TWSI_CTL_STP, twsi_read_status(), TWSI_STAT_IDLE, and twsi_write_ctl().
Referenced by twsi_read_data(), twsi_start_unstick(), and twsi_write_data().
Manually clear the I2C bus and send a stop.
Definition at line 390 of file twsi.c.
References twsx_int::s, twsx_int::scl_ovr, twsx_int::sda_ovr, TWSI_INT, twsx_int::u, udelay(), and write64().
Referenced by twsi_start_unstick().
Waits for an i2c operation to complete.
baseaddr | Base address of registers |
Definition at line 352 of file twsi.c.
References BIOS_SPEW, printk, stopwatch_expired(), TWSI_CTL_IFLG, and twsi_read_ctl().
Referenced by twsi_read_data(), twsi_start(), and twsi_write_data().
Write control register.
baseaddr | Base address for i2c registers |
data | data to write |
Definition at line 293 of file twsi.c.
References BIOS_SPEW, twsx_sw_twsi::data, twsx_sw_twsi::eop_ia, twsx_sw_twsi::op, printk, twsx_sw_twsi::s, TWSI_CTL, TWSI_SW_EOP_IA, twsi_write_sw(), and twsx_sw_twsi::u.
Referenced by twsi_init(), twsi_read_data(), twsi_start(), twsi_stop(), and twsi_write_data().
|
static |
Writes data to the i2c bus.
baseraddr | register base address |
slave_addr | address of slave to write to |
buffer | Pointer to buffer to write |
length | Number of bytes in buffer to write |
Definition at line 473 of file twsi.c.
References BIOS_ERR, BIOS_SPEW, buffer, twsx_sw_twsi::data, twsx_sw_twsi::eop_ia, length, twsx_sw_twsi::op, printk, twsx_sw_twsi::s, stopwatch_init_usecs_expire(), TWSI_CTL_ENAB, TWSI_DATA, twsi_i2c_lost_arb(), TWSI_OP_WRITE, twsi_read_status(), twsi_start(), TWSI_STAT_TXADDR_ACK, twsi_stop(), TWSI_SW_EOP_IA, twsi_wait(), twsi_write_ctl(), twsi_write_sw(), and twsx_sw_twsi::u.
Referenced by platform_i2c_transfer().
|
static |
Writes to the MIO_TWS(0..5)_SW_TWSI register.
baseaddr | Base address of i2c registers |
sw_twsi | value to write |
Definition at line 238 of file twsi.c.
References BIOS_ERR, BIOS_SPEW, printk, twsx_sw_twsi::r, read64(), twsx_sw_twsi::s, TWSI_SW_TWSI, twsx_sw_twsi::u, twsx_sw_twsi::v, and write64().
Referenced by twsi_read_data(), twsi_set_speed(), twsi_write_ctl(), and twsi_write_data().