iPXE
Data Structures | Defines | 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...

Defines

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

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.
int init_i2c_bit_basher (struct i2c_bit_basher *i2cbit, struct bit_basher_operations *bash_op)
 Initialise I2C bit-bashing interface.
static __always_inline void init_i2c_eeprom (struct i2c_device *i2cdev, unsigned int dev_addr)
 Initialise generic I2C EEPROM device.
static __always_inline void init_at24c11 (struct i2c_device *i2cdev)
 Initialise Atmel AT24C11.

Detailed Description

I2C interface.

Definition in file i2c.h.


Define Documentation

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

#define I2C_WRITE   0

An I2C write command.

Definition at line 106 of file i2c.h.

Referenced by i2c_bit_read(), and i2c_bit_write().

#define I2C_READ   1

An I2C read command.

Definition at line 109 of file i2c.h.

Referenced by i2c_bit_read().

#define I2C_UDELAY   5

Delay required for bit-bashing operation.

Definition at line 120 of file i2c.h.

Referenced by i2c_delay().

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

Referenced by i2c_reset().


Enumeration Type Documentation

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.

     {
        /** Serial clock */
        I2C_BIT_SCL = 0,
        /** Serial data */
        I2C_BIT_SDA,
};

Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static int i2c_check_presence ( struct i2c_interface i2c,
struct i2c_device i2cdev 
) [inline, static]

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.

References NULL, and i2c_interface::write.

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

                                                                   {
        return i2c->write ( i2c, i2cdev, 0, NULL, 0 );
}
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.

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

                                                                  {
        struct bit_basher *basher = &i2cbit->basher;
        int rc;

        /* Initialise data structures */
        basher->op = bash_op;
        assert ( basher->op->read != NULL );
        assert ( basher->op->write != NULL );
        i2cbit->i2c.read = i2c_bit_read;
        i2cbit->i2c.write = i2c_bit_write;

        /* Reset I2C bus */
        if ( ( rc = i2c_reset ( basher ) ) != 0 ) {
                DBGC ( basher, "I2CBIT %p could not reset I2C bus: %s\n",
                       basher, strerror ( rc ) );
                return rc;
        }

        return 0;
}
static __always_inline void init_i2c_eeprom ( struct i2c_device i2cdev,
unsigned int  dev_addr 
) [inline, static]

Initialise generic I2C EEPROM device.

Parameters:
i2cdevI2C device

Definition at line 149 of file i2c.h.

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

                                                                     {
        i2cdev->dev_addr = dev_addr;
        i2cdev->dev_addr_len = 1;
        i2cdev->word_addr_len = 1;
}
static __always_inline void init_at24c11 ( struct i2c_device i2cdev) [inline, static]

Initialise Atmel AT24C11.

Parameters:
i2cdevI2C device

Definition at line 161 of file i2c.h.

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

                                           {
        /* This chip has no device address; it must be the only chip
         * on the bus.  The word address is contained entirely within
         * the device address field.
         */
        i2cdev->dev_addr = 0;
        i2cdev->dev_addr_len = 1;
        i2cdev->word_addr_len = 0;
}