summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chip/lm4/i2c.c8
-rw-r--r--chip/mec1322/i2c.c16
-rw-r--r--chip/npcx/i2c.c4
-rw-r--r--chip/nrf51/i2c.c4
-rw-r--r--chip/stm32/i2c-stm32f.c4
-rw-r--r--chip/stm32/i2c-stm32f0.c4
-rw-r--r--chip/stm32/i2c-stm32l.c6
-rw-r--r--common/i2c.c7
-rw-r--r--include/i2c.h23
9 files changed, 51 insertions, 25 deletions
diff --git a/chip/lm4/i2c.c b/chip/lm4/i2c.c
index 5f3b9bfc74..72d02d2043 100644
--- a/chip/lm4/i2c.c
+++ b/chip/lm4/i2c.c
@@ -106,8 +106,8 @@ int i2c_do_work(int port)
/*
* Error after starting; abort transfer. Ignore errors at
* start because arbitration and timeout errors are taken care
- * of in i2c_xfer(), and slave ack failures will automatically
- * clear once we send a start condition.
+ * of in chip_i2c_xfer(), and slave ack failures will
+ * automatically clear once we send a start condition.
*/
pd->err = EC_ERROR_UNKNOWN;
return 0;
@@ -168,8 +168,8 @@ int i2c_do_work(int port)
return 0;
}
-int i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_size,
- uint8_t *in, int in_size, int flags)
+int chip_i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_size,
+ uint8_t *in, int in_size, int flags)
{
struct i2c_port_data *pd = pdata + port;
uint32_t reg_mcs = LM4_I2C_MCS(port);
diff --git a/chip/mec1322/i2c.c b/chip/mec1322/i2c.c
index e7254a01f9..e80d6cb5f8 100644
--- a/chip/mec1322/i2c.c
+++ b/chip/mec1322/i2c.c
@@ -212,8 +212,8 @@ static inline void push_in_buf(uint8_t **in, uint8_t val, int skip)
}
}
-int i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_size,
- uint8_t *in, int in_size, int flags)
+int chip_i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_size,
+ uint8_t *in, int in_size, int flags)
{
int i;
int controller;
@@ -267,11 +267,11 @@ int i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_size,
for (i = 0; i < out_size; ++i) {
if (wait_byte_done(controller))
- goto err_i2c_xfer;
+ goto err_chip_i2c_xfer;
MEC1322_I2C_DATA(controller) = out[i];
}
if (wait_byte_done(controller))
- goto err_i2c_xfer;
+ goto err_chip_i2c_xfer;
/*
* Send STOP bit if the stop flag is on, and caller
@@ -302,12 +302,12 @@ int i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_size,
for (i = 0; i < bytes_to_read; ++i) {
if (wait_byte_done(controller))
- goto err_i2c_xfer;
+ goto err_chip_i2c_xfer;
push_in_buf(&in, MEC1322_I2C_DATA(controller), skip);
skip = 0;
}
if (wait_byte_done(controller))
- goto err_i2c_xfer;
+ goto err_chip_i2c_xfer;
if (send_stop) {
/*
@@ -317,7 +317,7 @@ int i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_size,
MEC1322_I2C_CTRL(controller) = CTRL_ESO | CTRL_ENI;
push_in_buf(&in, MEC1322_I2C_DATA(controller), skip);
if (wait_byte_done(controller))
- goto err_i2c_xfer;
+ goto err_chip_i2c_xfer;
/* Send STOP */
MEC1322_I2C_CTRL(controller) =
@@ -339,7 +339,7 @@ int i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_size,
return EC_ERROR_UNKNOWN;
return EC_SUCCESS;
-err_i2c_xfer:
+err_chip_i2c_xfer:
/* Send STOP and return error */
MEC1322_I2C_CTRL(controller) = CTRL_PIN | CTRL_ESO |
CTRL_STO | CTRL_ACK;
diff --git a/chip/npcx/i2c.c b/chip/npcx/i2c.c
index a8002d7573..03b48c2864 100644
--- a/chip/npcx/i2c.c
+++ b/chip/npcx/i2c.c
@@ -374,8 +374,8 @@ DECLARE_IRQ(NPCX_IRQ_SMB4, i2c3_interrupt, 2);
/*****************************************************************************/
/* IC specific low-level driver */
-int i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_size,
- uint8_t *in, int in_size, int flags)
+int chip_i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_size,
+ uint8_t *in, int in_size, int flags)
{
volatile struct i2c_status *p_status = i2c_stsobjs + port;
diff --git a/chip/nrf51/i2c.c b/chip/nrf51/i2c.c
index 6ef109ea0e..668f4c6863 100644
--- a/chip/nrf51/i2c.c
+++ b/chip/nrf51/i2c.c
@@ -243,8 +243,8 @@ static int i2c_master_read(int port, int slave_addr, uint8_t *data, int size)
return EC_SUCCESS;
}
-int i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_bytes,
- uint8_t *in, int in_bytes, int flags)
+int chip_i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_bytes,
+ uint8_t *in, int in_bytes, int flags)
{
int rv = EC_SUCCESS;
diff --git a/chip/stm32/i2c-stm32f.c b/chip/stm32/i2c-stm32f.c
index 75d1587c76..1fab9c3b7c 100644
--- a/chip/stm32/i2c-stm32f.c
+++ b/chip/stm32/i2c-stm32f.c
@@ -703,8 +703,8 @@ static int i2c_master_receive(int port, int slave_addr, uint8_t *data,
return wait_until_stop_sent(port);
}
-int i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_bytes,
- uint8_t *in, int in_bytes, int flags)
+int chip_i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_bytes,
+ uint8_t *in, int in_bytes, int flags)
{
int rv;
diff --git a/chip/stm32/i2c-stm32f0.c b/chip/stm32/i2c-stm32f0.c
index b1b530e600..1dfe7d9b36 100644
--- a/chip/stm32/i2c-stm32f0.c
+++ b/chip/stm32/i2c-stm32f0.c
@@ -358,8 +358,8 @@ DECLARE_IRQ(IRQ_SLAVE, i2c2_event_interrupt, 2);
/*****************************************************************************/
/* Interface */
-int i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_bytes,
- uint8_t *in, int in_bytes, int flags)
+int chip_i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_bytes,
+ uint8_t *in, int in_bytes, int flags)
{
int rv = EC_SUCCESS;
int i;
diff --git a/chip/stm32/i2c-stm32l.c b/chip/stm32/i2c-stm32l.c
index 510c138410..90fe7aa0d7 100644
--- a/chip/stm32/i2c-stm32l.c
+++ b/chip/stm32/i2c-stm32l.c
@@ -165,8 +165,8 @@ static void i2c_init_port(const struct i2c_port_t *p)
/*****************************************************************************/
/* Interface */
-int i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_bytes,
- uint8_t *in, int in_bytes, int flags)
+int chip_i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_bytes,
+ uint8_t *in, int in_bytes, int flags)
{
int started = (flags & I2C_XFER_START) ? 0 : 1;
int rv = EC_SUCCESS;
@@ -302,7 +302,7 @@ int i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_bytes,
*/
if (rv == I2C_ERROR_FAILED_START) {
const struct i2c_port_t *p = i2c_ports;
- CPRINTS("i2c_xfer start error; "
+ CPRINTS("chip_i2c_xfer start error; "
"unwedging and resetting i2c %d", port);
i2c_unwedge(port);
diff --git a/common/i2c.c b/common/i2c.c
index 9659db59c3..189420c102 100644
--- a/common/i2c.c
+++ b/common/i2c.c
@@ -33,6 +33,13 @@
static struct mutex port_mutex[I2C_CONTROLLER_COUNT];
+int i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_size,
+ uint8_t *in, int in_size, int flags)
+{
+ return chip_i2c_xfer(port, slave_addr, out, out_size, in,
+ in_size, flags);
+}
+
void i2c_lock(int port, int lock)
{
#ifdef CONFIG_I2C_MULTI_PORT_CONTROLLER
diff --git a/include/i2c.h b/include/i2c.h
index 753efa0aec..f3495bac41 100644
--- a/include/i2c.h
+++ b/include/i2c.h
@@ -33,8 +33,8 @@ extern const unsigned int i2c_ports_used;
/**
* Transmit one block of raw data, then receive one block of raw data.
*
- * This is a low-level platform-dependent function used by the other functions
- * below. It must be called between i2c_lock(port, 1) and i2c_lock(port, 0).
+ * This is a wrapper function for chip_i2c_xfer(), a low-level chip-dependent
+ * function. It must be called between i2c_lock(port, 1) and i2c_lock(port, 0).
*
* @param port Port to access
* @param slave_addr Slave device address
@@ -53,6 +53,25 @@ int i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_size,
#define I2C_LINE_IDLE (I2C_LINE_SCL_HIGH | I2C_LINE_SDA_HIGH)
/**
+ * Chip-level function to transmit one block of raw data, then receive one
+ * block of raw data.
+ *
+ * This is a low-level chip-dependent function and should only be called by
+ * i2c_xfer().
+ *
+ * @param port Port to access
+ * @param slave_addr Slave device address
+ * @param out Data to send
+ * @param out_size Number of bytes to send
+ * @param in Destination buffer for received data
+ * @param in_size Number of bytes to receive
+ * @param flags Flags (see I2C_XFER_* above)
+ * @return EC_SUCCESS, or non-zero if error.
+ */
+int chip_i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_size,
+ uint8_t *in, int in_size, int flags);
+
+/**
* Return raw I/O line levels (I2C_LINE_*) for a port when port is in alternate
* function mode.
*