iPXE
|
I2C bit-bashing interface. More...
#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
#include <assert.h>
#include <unistd.h>
#include <ipxe/bitbash.h>
#include <ipxe/i2c.h>
Go to the source code of this file.
Functions | |
FILE_LICENCE (GPL2_OR_LATER_OR_UBDL) | |
static void | i2c_delay (void) |
Delay between output state changes. More... | |
static void | setscl (struct bit_basher *basher, int state) |
Set state of I2C SCL line. More... | |
static void | setsda (struct bit_basher *basher, int state) |
Set state of I2C SDA line. More... | |
static int | getsda (struct bit_basher *basher) |
Get state of I2C SDA line. More... | |
static void | i2c_start (struct bit_basher *basher) |
Send an I2C start condition. More... | |
static void | i2c_send_bit (struct bit_basher *basher, int bit) |
Send an I2C data bit. More... | |
static int | i2c_recv_bit (struct bit_basher *basher) |
Receive an I2C data bit. More... | |
static void | i2c_stop (struct bit_basher *basher) |
Send an I2C stop condition. More... | |
static int | i2c_send_byte (struct bit_basher *basher, uint8_t byte) |
Send byte via I2C bus and check for acknowledgement. More... | |
static uint8_t | i2c_recv_byte (struct bit_basher *basher) |
Receive byte via I2C bus. More... | |
static int | i2c_select (struct bit_basher *basher, struct i2c_device *i2cdev, unsigned int offset, unsigned int direction) |
Select I2C device for reading or writing. More... | |
static int | i2c_reset (struct bit_basher *basher) |
Reset I2C bus. More... | |
static int | i2c_bit_read (struct i2c_interface *i2c, struct i2c_device *i2cdev, unsigned int offset, uint8_t *data, unsigned int len) |
Read data from I2C device via bit-bashing interface. More... | |
static int | i2c_bit_write (struct i2c_interface *i2c, struct i2c_device *i2cdev, unsigned int offset, const uint8_t *data, unsigned int len) |
Write data to I2C device via bit-bashing interface. More... | |
int | init_i2c_bit_basher (struct i2c_bit_basher *i2cbit, struct bit_basher_operations *bash_op) |
Initialise I2C bit-bashing interface. More... | |
I2C bit-bashing interface.
This implements a simple I2C master via a bit-bashing interface that provides two lines: SCL (clock) and SDA (data).
Definition in file i2c_bit.c.
FILE_LICENCE | ( | GPL2_OR_LATER_OR_UBDL | ) |
|
static |
Delay between output state changes.
Max rated i2c speed (for the basic i2c protocol) is 100kbps, i.e. 200k clock transitions per second.
Definition at line 49 of file i2c_bit.c.
References I2C_UDELAY, and udelay().
|
static |
Set state of I2C SCL line.
basher | Bit-bashing interface |
state | New state of SCL |
Definition at line 59 of file i2c_bit.c.
References DBG2, I2C_BIT_SCL, i2c_delay(), state, and write_bit().
Referenced by i2c_recv_bit(), i2c_reset(), i2c_send_bit(), i2c_start(), and i2c_stop().
|
static |
Set state of I2C SDA line.
basher | Bit-bashing interface |
state | New state of SDA |
Definition at line 71 of file i2c_bit.c.
References DBG2, I2C_BIT_SDA, i2c_delay(), state, and write_bit().
Referenced by i2c_reset(), i2c_send_bit(), i2c_start(), and i2c_stop().
|
static |
Get state of I2C SDA line.
basher | Bit-bashing interface |
state | State of SDA |
Definition at line 83 of file i2c_bit.c.
References DBG2, I2C_BIT_SDA, read_bit(), and state.
Referenced by i2c_recv_bit(), and i2c_reset().
|
static |
Send an I2C start condition.
basher | Bit-bashing interface |
Definition at line 95 of file i2c_bit.c.
References setscl(), and setsda().
Referenced by i2c_reset(), and i2c_select().
|
static |
Send an I2C data bit.
basher | Bit-bashing interface |
bit | Bit to send |
Definition at line 108 of file i2c_bit.c.
References bit, setscl(), and setsda().
Referenced by i2c_recv_byte(), and i2c_send_byte().
|
static |
Receive an I2C data bit.
basher | Bit-bashing interface |
bit | Received bit |
Definition at line 121 of file i2c_bit.c.
References bit, getsda(), and setscl().
Referenced by i2c_recv_byte(), and i2c_send_byte().
|
static |
Send an I2C stop condition.
basher | Bit-bashing interface |
Definition at line 135 of file i2c_bit.c.
References setscl(), and setsda().
Referenced by i2c_bit_read(), i2c_bit_write(), and i2c_reset().
|
static |
Send byte via I2C bus and check for acknowledgement.
basher | Bit-bashing interface |
byte | Byte to send |
rc | Return status code |
Sends a byte via the I2C bus and checks for an acknowledgement from the slave device.
Definition at line 151 of file i2c_bit.c.
References DBG2, EIO, i2c_recv_bit(), and i2c_send_bit().
Referenced by i2c_bit_read(), i2c_bit_write(), and i2c_select().
|
static |
Receive byte via I2C bus.
basher | Bit-bashing interface |
byte | Received byte |
Receives a byte via the I2C bus and sends NACK to the slave device.
Definition at line 177 of file i2c_bit.c.
References DBG2, i2c_recv_bit(), and i2c_send_bit().
Referenced by i2c_bit_read().
|
static |
Select I2C device for reading or writing.
basher | Bit-bashing interface |
i2cdev | I2C device |
offset | Starting offset within the device |
direction | I2C_READ or I2C_WRITE |
rc | Return status code |
Definition at line 203 of file i2c_bit.c.
References address, i2c_device::dev_addr, i2c_device::dev_addr_len, direction, i2c_send_byte(), i2c_start(), offset, rc, and i2c_device::word_addr_len.
Referenced by i2c_bit_read(), and i2c_bit_write().
|
static |
Reset I2C bus.
basher | Bit-bashing interface |
rc | Return status code |
i2c devices often don't have a reset line, so even a reboot or system power cycle is sometimes not enough to bring them back to a known state.
Definition at line 238 of file i2c_bit.c.
References close_bit(), DBGC, ETIMEDOUT, getsda(), I2C_RESET_MAX_CYCLES, i2c_start(), i2c_stop(), open_bit(), setscl(), and setsda().
Referenced by init_i2c_bit_basher().
|
static |
Read data from I2C device via bit-bashing interface.
i2c | I2C interface |
i2cdev | I2C device |
offset | Starting offset within the device |
data | Data buffer |
len | Length of data buffer |
rc | Return status code |
Note that attempting to read zero bytes of data is a valid way to check for I2C device presence.
Definition at line 284 of file i2c_bit.c.
References i2c_bit_basher::basher, close_bit(), container_of, data, DBGC, i2c_device::dev_addr, i2c_bit_basher::i2c, I2C_READ, i2c_recv_byte(), i2c_select(), i2c_send_byte(), i2c_stop(), I2C_WRITE, len, offset, open_bit(), and rc.
Referenced by init_i2c_bit_basher().
|
static |
Write data to I2C device via bit-bashing interface.
i2c | I2C interface |
i2cdev | I2C device |
offset | Starting offset within the device |
data | Data buffer |
len | Length of data buffer |
rc | Return status code |
Note that attempting to write zero bytes of data is a valid way to check for I2C device presence.
Definition at line 341 of file i2c_bit.c.
References i2c_bit_basher::basher, close_bit(), container_of, data, DBGC, i2c_device::dev_addr, i2c_bit_basher::i2c, i2c_select(), i2c_send_byte(), i2c_stop(), I2C_WRITE, len, offset, open_bit(), and rc.
Referenced by init_i2c_bit_basher().
int init_i2c_bit_basher | ( | struct i2c_bit_basher * | i2cbit, |
struct bit_basher_operations * | bash_op | ||
) |
Initialise I2C bit-bashing interface.
i2cbit | I2C bit-bashing interface |
bash_op | Bit-basher operations |
Definition at line 387 of file i2c_bit.c.
References assert(), i2c_bit_basher::basher, DBGC, i2c_bit_basher::i2c, i2c_bit_read(), i2c_bit_write(), i2c_reset(), NULL, bit_basher::op, rc, bit_basher_operations::read, i2c_interface::read, strerror(), bit_basher_operations::write, and i2c_interface::write.
Referenced by exanic_try_init_eeprom(), falcon_probe_spi(), linda_init_i2c(), and qib7322_init_i2c().