iPXE
Data Structures | Macros | Enumerations | Functions
i2c.h File Reference

I2C interface. More...

#include <stdint.h>
#include <ipxe/bitbash.h>

Go to the source code of this file.

Data Structures

struct  i2c_device
 An I2C device. More...
 
struct  i2c_interface
 An I2C interface. More...
 
struct  i2c_bit_basher
 A bit-bashing I2C interface. More...
 

Macros

#define I2C_TENBIT_ADDRESS   0x7800
 Ten-bit address marker. More...
 
#define I2C_WRITE   0
 An I2C write command. More...
 
#define I2C_READ   1
 An I2C read command. More...
 
#define I2C_UDELAY   5
 Delay required for bit-bashing operation. More...
 
#define I2C_RESET_MAX_CYCLES   32
 Maximum number of cycles to use when attempting a bus reset. More...
 

Enumerations

enum  { I2C_BIT_SCL = 0, I2C_BIT_SDA }
 Bit indices used for I2C bit-bashing interface. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static int i2c_check_presence (struct i2c_interface *i2c, struct i2c_device *i2cdev)
 Check presence of I2C device. More...
 
int init_i2c_bit_basher (struct i2c_bit_basher *i2cbit, struct bit_basher_operations *bash_op)
 Initialise I2C bit-bashing interface. More...
 
static __always_inline void init_i2c_eeprom (struct i2c_device *i2cdev, unsigned int dev_addr)
 Initialise generic I2C EEPROM device. More...
 
static __always_inline void init_at24c11 (struct i2c_device *i2cdev)
 Initialise Atmel AT24C11. More...
 

Detailed Description

I2C interface.

Definition in file i2c.h.

Macro Definition Documentation

◆ I2C_TENBIT_ADDRESS

#define I2C_TENBIT_ADDRESS   0x7800

Ten-bit address marker.

This value is ORed with the I2C device address to indicate a ten-bit address format on the bus.

Definition at line 103 of file i2c.h.

◆ I2C_WRITE

#define I2C_WRITE   0

An I2C write command.

Definition at line 106 of file i2c.h.

◆ I2C_READ

#define I2C_READ   1

An I2C read command.

Definition at line 109 of file i2c.h.

◆ I2C_UDELAY

#define I2C_UDELAY   5

Delay required for bit-bashing operation.

Definition at line 120 of file i2c.h.

◆ I2C_RESET_MAX_CYCLES

#define I2C_RESET_MAX_CYCLES   32

Maximum number of cycles to use when attempting a bus reset.

Definition at line 123 of file i2c.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Bit indices used for I2C bit-bashing interface.

Enumerator
I2C_BIT_SCL 

Serial clock.

I2C_BIT_SDA 

Serial data.

Definition at line 112 of file i2c.h.

112  {
113  /** Serial clock */
114  I2C_BIT_SCL = 0,
115  /** Serial data */
116  I2C_BIT_SDA,
117 };
Serial clock.
Definition: i2c.h:114
Serial data.
Definition: i2c.h:116

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ i2c_check_presence()

static int i2c_check_presence ( struct i2c_interface i2c,
struct i2c_device i2cdev 
)
inlinestatic

Check presence of I2C device.

Parameters
i2cI2C interface
i2cdevI2C device
Return values
rcReturn status code

Checks for the presence of the device on the I2C bus by attempting a zero-length write.

Definition at line 135 of file i2c.h.

136  {
137  return i2c->write ( i2c, i2cdev, 0, NULL, 0 );
138 }
int(* write)(struct i2c_interface *i2c, struct i2c_device *i2cdev, unsigned int offset, const uint8_t *data, unsigned int len)
Write data to I2C device.
Definition: i2c.h:81
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References NULL, and i2c_interface::write.

Referenced by exanic_try_init_eeprom(), linda_init_i2c(), and qib7322_init_i2c().

◆ 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.

Parameters
i2cbitI2C bit-bashing interface
bash_opBit-basher operations

Definition at line 387 of file i2c_bit.c.

388  {
389  struct bit_basher *basher = &i2cbit->basher;
390  int rc;
391 
392  /* Initialise data structures */
393  basher->op = bash_op;
394  assert ( basher->op->read != NULL );
395  assert ( basher->op->write != NULL );
396  i2cbit->i2c.read = i2c_bit_read;
397  i2cbit->i2c.write = i2c_bit_write;
398 
399  /* Reset I2C bus */
400  if ( ( rc = i2c_reset ( basher ) ) != 0 ) {
401  DBGC ( basher, "I2CBIT %p could not reset I2C bus: %s\n",
402  basher, strerror ( rc ) );
403  return rc;
404  }
405 
406  return 0;
407 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int(* write)(struct i2c_interface *i2c, struct i2c_device *i2cdev, unsigned int offset, const uint8_t *data, unsigned int len)
Write data to I2C device.
Definition: i2c.h:81
static int i2c_reset(struct bit_basher *basher)
Reset I2C bus.
Definition: i2c_bit.c:238
#define DBGC(...)
Definition: compiler.h:505
struct bit_basher_operations * op
Bit-bashing operations.
Definition: bitbash.h:57
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
struct i2c_interface i2c
I2C interface.
Definition: i2c.h:93
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.
Definition: i2c_bit.c:341
struct bit_basher basher
Bit-bashing interface.
Definition: i2c.h:95
int(* read)(struct bit_basher *basher, unsigned int bit_id)
Read input bit.
Definition: bitbash.h:51
A bit-bashing interface.
Definition: bitbash.h:55
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
int(* read)(struct i2c_interface *i2c, struct i2c_device *i2cdev, unsigned int offset, uint8_t *data, unsigned int len)
Read data from I2C device.
Definition: i2c.h:68
void(* write)(struct bit_basher *basher, unsigned int bit_id, unsigned long data)
Set/clear output bit.
Definition: bitbash.h:41
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
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.
Definition: i2c_bit.c:284

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().

◆ init_i2c_eeprom()

static __always_inline void init_i2c_eeprom ( struct i2c_device i2cdev,
unsigned int  dev_addr 
)
inlinestatic

Initialise generic I2C EEPROM device.

Parameters
i2cdevI2C device

Definition at line 149 of file i2c.h.

149  {
150  i2cdev->dev_addr = dev_addr;
151  i2cdev->dev_addr_len = 1;
152  i2cdev->word_addr_len = 1;
153 }
unsigned int dev_addr
Address of this device.
Definition: i2c.h:31
unsigned int word_addr_len
Word adddress length, in bytes.
Definition: i2c.h:49
unsigned int dev_addr_len
Device address length, in bytes.
Definition: i2c.h:38

References i2c_device::dev_addr, i2c_device::dev_addr_len, and i2c_device::word_addr_len.

Referenced by exanic_try_init_eeprom(), linda_init_i2c(), and qib7322_init_i2c().

◆ init_at24c11()

static __always_inline void init_at24c11 ( struct i2c_device i2cdev)
inlinestatic

Initialise Atmel AT24C11.

Parameters
i2cdevI2C device

Definition at line 161 of file i2c.h.

161  {
162  /* This chip has no device address; it must be the only chip
163  * on the bus. The word address is contained entirely within
164  * the device address field.
165  */
166  i2cdev->dev_addr = 0;
167  i2cdev->dev_addr_len = 1;
168  i2cdev->word_addr_len = 0;
169 }
unsigned int dev_addr
Address of this device.
Definition: i2c.h:31
unsigned int word_addr_len
Word adddress length, in bytes.
Definition: i2c.h:49
unsigned int dev_addr_len
Device address length, in bytes.
Definition: i2c.h:38

References i2c_device::dev_addr, i2c_device::dev_addr_len, and i2c_device::word_addr_len.