11 #include <soc/ramstage.h>
24 timeout = 1 * 1000 * 1000;
25 status =
regs->ic_enable_status;
30 "ERROR - I2C failed to disable!\n");
31 status =
regs->ic_enable_status;
35 status =
regs->ic_clr_intr;
41 int bytes_transferred;
51 bytes_transferred = 0;
53 status =
regs->ic_raw_intr_stat;
61 "0x%08x: ic_raw_intr_stat, I2C write error!\n",
70 "0x%08x: ic_raw_intr_stat, I2C write timeout!\n",
76 status =
regs->ic_status;
77 if (rx_buffer !=
NULL) {
81 status =
regs->ic_status;
94 regs->ic_data_cmd = cmd;
100 return bytes_transferred;
106 int bytes_transferred;
117 status =
regs->ic_status;
120 status =
regs->ic_status;
125 bytes_transferred = 0;
127 status =
regs->ic_raw_intr_stat;
135 "0x%08x: ic_raw_intr_stat, I2C read error!\n",
144 "0x%08x: ic_raw_intr_stat, I2C read timeout!\n",
150 status =
regs->ic_status;
166 regs->ic_data_cmd = cmd;
173 return bytes_transferred;
179 int bytes_transferred;
196 for (index = 0; index < seg_count;) {
200 "I2C segment[%d]: %s 0x%02x %s %p, 0x%08x bytes\n",
202 (segment[index].flags &
I2C_M_RD) ?
"Read from" :
"Write to",
203 segment[index].
slave,
204 (segment[index].flags &
I2C_M_RD) ?
"to " :
"from",
208 (++index >= seg_count) ?
"Stop" :
"Restart");
222 status =
regs->ic_clr_start_det;
223 status =
regs->ic_clr_stop_det;
240 status =
regs->ic_clr_rx_under;
241 status =
regs->ic_clr_rx_over;
242 status =
regs->ic_clr_tx_over;
243 status =
regs->ic_clr_tx_abrt;
251 bytes_transferred = 0;
255 while (index++ < seg_count) {
268 rx_buffer = segment->
buf;
273 if (data_bytes < 0) {
276 "I2C segment[%d] failed\n",
280 bytes_transferred += data_bytes;
283 tx_buffer = segment->
buf;
286 length, stop, rx_buffer, &timeout);
289 if (data_bytes < 0) {
292 "I2C segment[%d] failed\n",
296 bytes_transferred += data_bytes;
303 if (rx_buffer !=
NULL)
304 rx_buffer += bytes_transferred - tx_bytes;
307 status =
regs->ic_status;
312 status =
regs->ic_raw_intr_stat;
313 if ((total_bytes == bytes_transferred)
323 "0x%08x: ic_raw_intr_stat, I2C read error!\n",
326 "I2C segment[%d] failed\n",
336 "0x%08x: ic_raw_intr_stat, I2C read timeout!\n",
339 "I2C segment[%d] failed\n",
356 return bytes_transferred;
#define printk(level,...)
#define die_with_post_code(value, fmt,...)
static struct tpm_chip chip
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 POST_HW_INIT_FAILURE
Hardware initialization failure.
int platform_i2c_transfer(unsigned int bus, struct i2c_msg *segment, int seg_count)
static int platform_i2c_read(uint32_t restart, uint8_t *rx_buffer, int length, uint32_t stop, struct stopwatch *timeout)
static int platform_i2c_write(uint32_t restart, uint8_t *tx_buffer, int length, uint32_t stop, uint8_t *rx_buffer, struct stopwatch *timeout)
static void i2c_disable(I2C_REGS *regs)
#define IC_DATA_CMD_RESTART
#define IC_CON_RESTART_EN
#define IC_CON_SPEED_400_KHz
volatile struct _I2C_REGS I2C_REGS
#define IC_CON_MASTER_MODE
#define IC_ENABLE_CONTROLLER
#define IC_DATA_CMD_WRITE
void * get_i2c_address(void)
static struct spi_slave slave
struct i2c_msg - an I2C transaction segment beginning with START @addr: Slave address,...
static struct am335x_pinmux_regs * regs
typedef void(X86APIP X86EMU_intrFuncs)(int num)