i2c.h File Reference

I2C interface. More...

#include <stdint.h>
#include <gpxe/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)
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.

00112      {
00113         /** Serial clock */
00114         I2C_BIT_SCL = 0,
00115         /** Serial data */
00116         I2C_BIT_SDA,
00117 };


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER   ) 

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

Check presence of I2C device.

Parameters:
i2c I2C interface
i2cdev I2C device
Return values:
rc Return 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 linda_init_i2c().

00136                                                                    {
00137         return i2c->write ( i2c, i2cdev, 0, NULL, 0 );
00138 }

int init_i2c_bit_basher ( struct i2c_bit_basher i2cbit,
struct bit_basher_operations bash_op 
)

Initialise I2C bit-bashing interface.

Parameters:
i2cbit I2C bit-bashing interface
bash_op Bit-basher operations

Definition at line 373 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, i2c_interface::read, bit_basher_operations::read, strerror(), i2c_interface::write, and bit_basher_operations::write.

Referenced by falcon_probe_spi(), and linda_init_i2c().

00374                                                                   {
00375         struct bit_basher *basher = &i2cbit->basher;
00376         int rc;
00377 
00378         /* Initialise data structures */
00379         basher->op = bash_op;
00380         assert ( basher->op->read != NULL );
00381         assert ( basher->op->write != NULL );
00382         i2cbit->i2c.read = i2c_bit_read;
00383         i2cbit->i2c.write = i2c_bit_write;
00384 
00385         /* Reset I2C bus */
00386         if ( ( rc = i2c_reset ( basher ) ) != 0 ) {
00387                 DBGC ( basher, "I2CBIT %p could not reset I2C bus: %s\n",
00388                        basher, strerror ( rc ) );
00389                 return rc;
00390         }
00391 
00392         return 0;
00393 }

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

Initialise generic I2C EEPROM device.

Parameters:
i2cdev I2C 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 linda_init_i2c().

00149                                                                      {
00150         i2cdev->dev_addr = dev_addr;
00151         i2cdev->dev_addr_len = 1;
00152         i2cdev->word_addr_len = 1;
00153 }

static __always_inline void init_at24c11 ( struct i2c_device i2cdev  )  [inline, static]

Initialise Atmel AT24C11.

Parameters:
i2cdev I2C 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.

00161                                            {
00162         /* This chip has no device address; it must be the only chip
00163          * on the bus.  The word address is contained entirely within
00164          * the device address field.
00165          */
00166         i2cdev->dev_addr = 0;
00167         i2cdev->dev_addr_len = 1;
00168         i2cdev->word_addr_len = 0;
00169 }


Generated on Tue Apr 6 20:01:50 2010 for gPXE by  doxygen 1.5.7.1