I2C APIs

This topic provides details for the I2C APIs.

i2c_add_adapter

Synopsis
int i2c_add_adapter(struct i2c_adapter *adapter)
Description Declares the I2C adapter by using a dynamic bus ID.
Parameter
  • adapter: The DMA applicant device.
Return
  • Success: 0
  • Failure: Error code

i2c_new_client_device

Synopsis
struct i2c_client *i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
Description Instantiates an I2C client device.
Parameter
  • adapter: The DMA applicant device.
  • info: The description of the I2C client device
Return
  • Success: The pointer to the new I2C client device
  • Failure: Error code

i2c_register_driver

Synopsis
int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
Description Registers the I2C driver.
Parameter
  • owner: The sub-module to which the I2C driver belongs
  • driver: The I2C driver to register
Return
  • Success: 0
  • Failure: Error code

i2c_transfer_buffer_flags

Synopsis
int i2c_transfer_buffer_flags(const struct i2c_client *client, char *buf, int count, u16 flags)
Description Issues a single I2C message which transfers data to/from a buffer.
Parameter
  • client: The handle to the client device
  • buf: The buffer in which data is stored
  • count: The count of bytes to transfer. Must be less than 64 K, as msg.len is u16.
  • flag: The flags to be used for the message, for example, I2C_M_RD for reads.
Return
  • Success: The count of bytes which are transferred successfully
  • Failure: Error code

i2c_transfer

Synopsis
int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
Description Executes a single or combined I2C message.
Parameter
  • adap: The handle to the I2C bus
  • msgs: The parameter includes one or more than one messages to execute before the flag of "STOP" is issued to terminate the operation; Each message begins with a flag of "START".
  • num: The total number of messages to be executed
Return
  • Success: The total number of messages which are executed successfully
  • Failure: Error code