The I2C controller driver must fill in the function pointers of an
i2c_controller structure, which is defined as follows:
struct i2c_controller {
void *ic_cookie; /* controller private */
int (*ic_acquire_bus)(void *, int);
void (*ic_release_bus)(void *, int);
int (*ic_exec)(void *, i2c_op_t, i2c_addr_t,
const void *, size_t, void *, size_t, int);
int (*ic_send_start)(void *, int);
int (*ic_send_stop)(void *, int);
int (*ic_initiate_xfer)(void *, i2c_addr_t, int);
int (*ic_read_byte)(void *, uint8_t *, int);
int (*ic_write_byte)(void *, uint8_t, int);
};
The
(*ic_acquire_bus)() and
(*ic_release_bus)() functions must always be provided.
The controller driver may elect to provide an
(*ic_exec)() function. This function is intended for use by automated controllers that do not provide manual control over I2C bus conditions such as START and STOP.
If the
(*ic_exec)() function is not provided, the following 5 functions will be used by
iic_exec() in order to execute the I2C bus operation:
(*ic_send_start)(cookie, flags)
Send a START condition on the I2C bus. The I2C_F_POLL flag indicates that sleeping is not permitted.
(*ic_send_stop)(cookie, flags)
Send a STOP condition on the I2C bus. The I2C_F_POLL flag indicates that sleeping is not permitted.
(*ic_initiate_xfer)(cookie, addr, flags)
Initiate a transfer on the I2C bus by sending a START condition and then transmitting the I2C device address and transfer type. The I2C_F_READ flag indicates a read transfer; the lack of this flag indicates a write transfer. The I2C_F_POLL flag indicates that sleeping is not permitted. The error code ETIMEDOUT should be returned if a timeout that would indicate that the device is not present occurs.
(*ic_read_byte)(cookie, datap, flags)
Read a byte from the I2C bus into the memory location referenced by datap. The I2C_F_LAST flag indicates that this is the final byte of the transfer, and that a NACK condition should be sent on the I2C bus following the transfer of the byte. The I2C_F_STOP flag indicates that a STOP condition should be sent on the I2C bus following the transfer of the byte. The I2C_F_POLL flag indicates that sleeping is not permitted.
(*ic_write_byte)(cookie, data, flags)
Write the byte contained in data to the I2C bus. The I2C_F_STOP flag indicates that a STOP condition should be sent on the I2C bus following the transfer of the byte. The I2C_F_POLL flag indicates that sleeping is not permitted.