14 #include <soc/addressmap.h>
19 #define TWSI_SW_TWSI 0x1000
20 #define TWSI_TWSI_SW 0x1008
21 #define TWSI_INT 0x1010
22 #define TWSI_SW_TWSI_EXT 0x1018
228 #define RST_BOOT_PNR_MUL(Val) ((Val >> 33) & 0x1F)
240 unsigned long timeout = 500000;
250 }
while (sw_twsi.
s.
v != 0 && timeout > 0);
267 unsigned long timeout = 500000;
277 }
while (sw_twsi.
s.
v != 0 && timeout > 0);
324 return sw_twsi.
s.
data;
396 for (i = 0; i < 9; i++) {
477 unsigned int curr = 0;
509 __func__, slave_addr);
530 __func__, slave_addr);
553 unsigned int curr = 0;
584 printk(
BIOS_ERR,
"%s: waiting for sending addr failed\n", __func__);
628 for (n_div = 0; n_div < 8; n_div++) {
629 m_div = io_clock_hz / (20 * speed * (
TWSI_THP + 1));
643 sw_twsi.
s.
data = ((m_div & 0xf) << 3) | ((n_div & 0x7) << 0);
673 for (; seg_count > 0; seg_count--, segments++) {
676 segments->
buf, segments->
len);
679 segments->
buf, segments->
len);
void write64(void *addr, uint64_t val)
uint64_t read64(const void *addr)
#define printk(level,...)
static int stopwatch_expired(struct stopwatch *sw)
static void stopwatch_init_usecs_expire(struct stopwatch *sw, long us)
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
#define BIOS_SPEW
BIOS_SPEW - Excessively verbose output.
u8 buffer[C2P_BUFFER_MAXSIZE]
u64 thunderx_get_io_clock(void)
Returns the I/O clock speed in Hz.
#define MIO_TWSx_PF_BAR0(x)
struct i2c_msg - an I2C transaction segment beginning with START @addr: Slave address,...
static void twsi_unblock(void *baseaddr)
Manually clear the I2C bus and send a stop.
static int twsi_i2c_lost_arb(u8 code, int final_read)
Returns true if we lost arbitration.
int platform_i2c_transfer(unsigned int bus, struct i2c_msg *segments, int seg_count)
static u8 twsi_read_status(void *baseaddr)
Read i2c status register.
static u32 twsi_read_ctl(void *baseaddr)
Reads the TWSI Control Register.
static int twsi_stop(void *baseaddr)
Sends an i2c stop condition.
static int twsi_start_unstick(void *baseaddr)
Unsticks the i2c bus.
int twsi_init(unsigned int bus, enum i2c_speed hz)
@ TWSI_STAT_TXDATA_ACK
Data byte transmitted in master mode, ACK received.
@ TWSI_STAT_SLAVE_TXDATA_NAK
Data byte transmitted in slave mode, /ACK received.
@ TWSI_STAT_TXADDR2DATA_NAK
Second address byte + write bit transmitted, /ACK received.
@ TWSI_STAT_TXADDR_NAK
Address + write bit transmitted, /ACK received.
@ TWSI_STAT_RXDATA_NAK_SENT
Data byte received, NACK transmitted.
@ TWSI_STAT_RX_GEN_ADDR_ARB_LOST
Arbitration lost in address as master, general call address received, ACK transmitted.
@ TWSI_STAT_RXADDR_NAK
Address + read bit transmitted, /ACK received.
@ TWSI_STAT_TX_ACK_ARB_LOST
Arbitration lost in address as master, slave address + write bit received, ACK transmitted.
@ TWSI_STAT_TXADDR2DATA_ACK
Second address byte + write bit transmitted, ACK received.
@ TWSI_STAT_RX_GEN_ADDR_ACK
General call address received, ACK transmitted.
@ TWSI_STAT_SLAVE_RXADDR2_ACK
Slave address + read bit received, ACK transmitted.
@ TWSI_STAT_BUS_ERROR
Bus error.
@ TWSI_STAT_RSTART
Repeat start condition transmitted.
@ TWSI_STAT_SLAVE_TXDATA_ACK
Data byte transmitted in slave mode, ACK received.
@ TWSI_STAT_SLAVE_RXDATA_NAK
Data byte received after slave address received, /ACK transmitted.
@ TWSI_STAT_RXDATA_ACK_SENT
Data byte received in master mode, ACK transmitted.
@ TWSI_STAT_GEN_RXADDR_ACK
Data byte received after general call address received, ACK transmitted.
@ TWSI_STAT_TXADDR_ACK
Address + write bit transmitted, ACK received.
@ TWSI_STAT_SLAVE_RXDATA_ACK
Data byte received after slave address received, ACK transmitted.
@ TWSI_STAT_TXDATA_NAK
Data byte transmitted in master mode, ACK received.
@ TWSI_STAT_TX_ARB_LOST
Arbitration lost in address or data byte.
@ TWSI_STAT_SLAVE_TXDATA_END_ACK
Last byte transmitted in slave mode, ACK received.
@ TWSI_STAT_IDLE
No relevant status information.
@ TWSI_STAT_SLAVE_RXADDR_ACK
Slave address received, sent ACK.
@ TWSI_STAT_RXADDR_ACK
Address + read bit transmitted, ACK received.
@ TWSI_STAT_STOP_MULTI_START
STOP or repeated START condition received in slave mode.
@ TWSI_STAT_GEN_RXADDR_NAK
Data byte received after general call address received, /ACK transmitted.
@ TWSI_STAT_RXDATA_ACK_ARB_LOST
Arbitration lost in address as master, slave address + read bit received, ACK transmitted.
@ TWSI_STAT_START
Start condition transmitted.
static int twsi_set_speed(void *baseaddr, const unsigned int speed)
static u64 twsi_read_sw(void *baseaddr, union twsx_sw_twsi sw_twsi)
Reads the MIO_TWS(0..5)_SW_TWSI register.
static int twsi_start(void *baseaddr)
Sends an i2c start condition.
static u64 twsi_write_sw(void *baseaddr, union twsx_sw_twsi sw_twsi)
Writes to the MIO_TWS(0..5)_SW_TWSI register.
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.
static void twsi_write_ctl(void *baseaddr, const u8 data)
Write control register.
static int twsi_write_data(void *baseaddr, const u8 slave_addr, const u8 *buffer, const unsigned int length)
Writes data to the i2c bus.
static int twsi_wait(void *baseaddr, struct stopwatch *timeout)
Waits for an i2c operation to complete.
u64 scl_ovr
SDA testing override.
u64 core_int
TWSX_TWSI_SW register update int.
u64 ts_int
TWSX_SW_TWSI register update int.
u64 sda
SCL testing override.
struct twsx_sw_twsi_ext::@443 s
struct twsx_sw_twsi::@442 s