diff options
Diffstat (limited to 'include/i2c.h')
-rw-r--r-- | include/i2c.h | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/include/i2c.h b/include/i2c.h index d14008a2d0..86535c1fa8 100644 --- a/include/i2c.h +++ b/include/i2c.h @@ -20,6 +20,47 @@ struct i2c_port_t { int kbps; /* Speed in kbps */ }; +/* Flags for i2c_xfer() */ +#define I2C_XFER_START (1 << 0) /* Start smbus session from idle state */ +#define I2C_XFER_STOP (1 << 1) /* Terminate smbus session with stop bit */ +#define I2C_XFER_SINGLE (I2C_XFER_START | I2C_XFER_STOP) /* One transaction */ + +/** + * 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). + * + * @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 i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_size, + uint8_t *in, int in_size, int flags); + +#define I2C_LINE_SCL_HIGH (1 << 0) +#define I2C_LINE_SDA_HIGH (1 << 1) +#define I2C_LINE_IDLE (I2C_LINE_SCL_HIGH | I2C_LINE_SDA_HIGH) + +/** + * Return raw I/O line levels (I2C_LINE_*) for a port. + * + * @param port Port to check + */ +int i2c_get_line_levels(int port); + +/** + * Lock / unlock an I2C port. + * @param port Port to lock + * @param lock 1 to lock, 0 to unlock + */ +void i2c_lock(int port, int lock); + /* Read a 16-bit register from the slave at 8-bit slave address <slaveaddr>, at * the specified 8-bit <offset> in the slave's address space. */ int i2c_read16(int port, int slave_addr, int offset, int* data); |