diff options
author | Randall Spangler <rspangler@chromium.org> | 2013-04-26 14:36:38 -0700 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-04-30 11:45:52 -0700 |
commit | 0a6b7620d6b4ba1a50500a75db3e76162eac5ce0 (patch) | |
tree | 8f55cf2a2ee6469981bd27924349bf80de0f295e /include/i2c.h | |
parent | c08e0ade765bf69fb9ab3f62305a84a4d3d34c1d (diff) | |
download | chrome-ec-0a6b7620d6b4ba1a50500a75db3e76162eac5ce0.tar.gz |
Move i2cread and i2cwrite functions to i2c_common
Also moves the handy i2cscan command to i2c_common. The
platform-dependent interface is now i2c_xfer().
Still more to do in follow-up CLs; for example, i2c_read_string() has
platform-dependent implementation, and the i2c/i2cread console
commands aren't common yet.
BUG=chrome-os-partner:18969
BRANCH=none
TEST=i2cscan on link, spring
Change-Id: Ia53d57beaa157bece293a4262257e20b4107589e
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/49492
Reviewed-by: Simon Glass <sjg@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
Commit-Queue: Simon Glass <sjg@chromium.org>
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); |