Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Functions | Variables
i2c-core.c File Reference
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/slab.h>
#include <linux/i2c.h>
#include <linux/init.h>
#include <linux/idr.h>
#include <linux/mutex.h>
#include <linux/of_device.h>
#include <linux/completion.h>
#include <linux/hardirq.h>
#include <linux/irqflags.h>
#include <linux/rwsem.h>
#include <linux/pm_runtime.h>
#include <asm/uaccess.h>
#include "i2c-core.h"

Go to the source code of this file.

Data Structures

struct  i2c_cmd_arg
 

Macros

#define i2c_device_uevent   NULL
 
#define i2c_device_pm_suspend   NULL
 
#define i2c_device_pm_resume   NULL
 
#define i2c_device_pm_freeze   NULL
 
#define i2c_device_pm_thaw   NULL
 
#define i2c_device_pm_poweroff   NULL
 
#define i2c_device_pm_restore   NULL
 
#define POLY   (0x1070U << 3)
 

Functions

 EXPORT_SYMBOL_GPL (i2c_bus_type)
 
struct i2c_clienti2c_verify_client (struct device *dev)
 
 EXPORT_SYMBOL (i2c_verify_client)
 
void i2c_lock_adapter (struct i2c_adapter *adapter)
 
 EXPORT_SYMBOL_GPL (i2c_lock_adapter)
 
void i2c_unlock_adapter (struct i2c_adapter *adapter)
 
 EXPORT_SYMBOL_GPL (i2c_unlock_adapter)
 
struct i2c_clienti2c_new_device (struct i2c_adapter *adap, struct i2c_board_info const *info)
 
 EXPORT_SYMBOL_GPL (i2c_new_device)
 
void i2c_unregister_device (struct i2c_client *client)
 
 EXPORT_SYMBOL_GPL (i2c_unregister_device)
 
struct i2c_clienti2c_new_dummy (struct i2c_adapter *adapter, u16 address)
 
 EXPORT_SYMBOL_GPL (i2c_new_dummy)
 
 EXPORT_SYMBOL_GPL (i2c_adapter_type)
 
struct i2c_adapteri2c_verify_adapter (struct device *dev)
 
 EXPORT_SYMBOL (i2c_verify_adapter)
 
int i2c_add_adapter (struct i2c_adapter *adapter)
 
 EXPORT_SYMBOL (i2c_add_adapter)
 
int i2c_add_numbered_adapter (struct i2c_adapter *adap)
 
 EXPORT_SYMBOL_GPL (i2c_add_numbered_adapter)
 
int i2c_del_adapter (struct i2c_adapter *adap)
 
 EXPORT_SYMBOL (i2c_del_adapter)
 
int i2c_for_each_dev (void *data, int(*fn)(struct device *, void *))
 
 EXPORT_SYMBOL_GPL (i2c_for_each_dev)
 
int i2c_register_driver (struct module *owner, struct i2c_driver *driver)
 
 EXPORT_SYMBOL (i2c_register_driver)
 
void i2c_del_driver (struct i2c_driver *driver)
 
 EXPORT_SYMBOL (i2c_del_driver)
 
struct i2c_clienti2c_use_client (struct i2c_client *client)
 
 EXPORT_SYMBOL (i2c_use_client)
 
void i2c_release_client (struct i2c_client *client)
 
 EXPORT_SYMBOL (i2c_release_client)
 
void i2c_clients_command (struct i2c_adapter *adap, unsigned int cmd, void *arg)
 
 EXPORT_SYMBOL (i2c_clients_command)
 
 postcore_initcall (i2c_init)
 
 module_exit (i2c_exit)
 
int __i2c_transfer (struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
 
 EXPORT_SYMBOL (__i2c_transfer)
 
int i2c_transfer (struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
 
 EXPORT_SYMBOL (i2c_transfer)
 
int i2c_master_send (const struct i2c_client *client, const char *buf, int count)
 
 EXPORT_SYMBOL (i2c_master_send)
 
int i2c_master_recv (const struct i2c_client *client, char *buf, int count)
 
 EXPORT_SYMBOL (i2c_master_recv)
 
int i2c_probe_func_quick_read (struct i2c_adapter *adap, unsigned short addr)
 
 EXPORT_SYMBOL_GPL (i2c_probe_func_quick_read)
 
struct i2c_clienti2c_new_probed_device (struct i2c_adapter *adap, struct i2c_board_info *info, unsigned short const *addr_list, int(*probe)(struct i2c_adapter *, unsigned short addr))
 
 EXPORT_SYMBOL_GPL (i2c_new_probed_device)
 
struct i2c_adapteri2c_get_adapter (int nr)
 
 EXPORT_SYMBOL (i2c_get_adapter)
 
void i2c_put_adapter (struct i2c_adapter *adap)
 
 EXPORT_SYMBOL (i2c_put_adapter)
 
s32 i2c_smbus_read_byte (const struct i2c_client *client)
 
 EXPORT_SYMBOL (i2c_smbus_read_byte)
 
s32 i2c_smbus_write_byte (const struct i2c_client *client, u8 value)
 
 EXPORT_SYMBOL (i2c_smbus_write_byte)
 
s32 i2c_smbus_read_byte_data (const struct i2c_client *client, u8 command)
 
 EXPORT_SYMBOL (i2c_smbus_read_byte_data)
 
s32 i2c_smbus_write_byte_data (const struct i2c_client *client, u8 command, u8 value)
 
 EXPORT_SYMBOL (i2c_smbus_write_byte_data)
 
s32 i2c_smbus_read_word_data (const struct i2c_client *client, u8 command)
 
 EXPORT_SYMBOL (i2c_smbus_read_word_data)
 
s32 i2c_smbus_write_word_data (const struct i2c_client *client, u8 command, u16 value)
 
 EXPORT_SYMBOL (i2c_smbus_write_word_data)
 
s32 i2c_smbus_process_call (const struct i2c_client *client, u8 command, u16 value)
 
 EXPORT_SYMBOL (i2c_smbus_process_call)
 
s32 i2c_smbus_read_block_data (const struct i2c_client *client, u8 command, u8 *values)
 
 EXPORT_SYMBOL (i2c_smbus_read_block_data)
 
s32 i2c_smbus_write_block_data (const struct i2c_client *client, u8 command, u8 length, const u8 *values)
 
 EXPORT_SYMBOL (i2c_smbus_write_block_data)
 
s32 i2c_smbus_read_i2c_block_data (const struct i2c_client *client, u8 command, u8 length, u8 *values)
 
 EXPORT_SYMBOL (i2c_smbus_read_i2c_block_data)
 
s32 i2c_smbus_write_i2c_block_data (const struct i2c_client *client, u8 command, u8 length, const u8 *values)
 
 EXPORT_SYMBOL (i2c_smbus_write_i2c_block_data)
 
s32 i2c_smbus_xfer (struct i2c_adapter *adapter, u16 addr, unsigned short flags, char read_write, u8 command, int protocol, union i2c_smbus_data *data)
 
 EXPORT_SYMBOL (i2c_smbus_xfer)
 
 MODULE_AUTHOR ("Simon G. Vogl <[email protected]linz.ac.at>")
 
 MODULE_DESCRIPTION ("I2C-Bus main module")
 
 MODULE_LICENSE ("GPL")
 

Variables

struct bus_type i2c_bus_type
 
struct device_type i2c_adapter_type
 

Macro Definition Documentation

#define i2c_device_pm_freeze   NULL

Definition at line 258 of file i2c-core.c.

#define i2c_device_pm_poweroff   NULL

Definition at line 260 of file i2c-core.c.

#define i2c_device_pm_restore   NULL

Definition at line 261 of file i2c-core.c.

#define i2c_device_pm_resume   NULL

Definition at line 257 of file i2c-core.c.

#define i2c_device_pm_suspend   NULL

Definition at line 256 of file i2c-core.c.

#define i2c_device_pm_thaw   NULL

Definition at line 259 of file i2c-core.c.

#define i2c_device_uevent   NULL

Definition at line 104 of file i2c-core.c.

#define POLY   (0x1070U << 3)

Definition at line 1689 of file i2c-core.c.

Function Documentation

int __i2c_transfer ( struct i2c_adapter adap,
struct i2c_msg msgs,
int  num 
)

__i2c_transfer - unlocked flavor of i2c_transfer : Handle to I2C bus : One or more messages to execute before STOP is issued to terminate the operation; each message begins with a START. : Number of messages to be executed.

Returns negative errno, else the number of messages executed.

Adapter lock must be held when calling this function. No debug logging takes place. adap->algo->master_xfer existence isn't checked.

Definition at line 1344 of file i2c-core.c.

EXPORT_SYMBOL ( i2c_verify_client  )
EXPORT_SYMBOL ( i2c_verify_adapter  )
EXPORT_SYMBOL ( i2c_add_adapter  )
EXPORT_SYMBOL ( i2c_del_adapter  )
EXPORT_SYMBOL ( i2c_register_driver  )
EXPORT_SYMBOL ( i2c_del_driver  )
EXPORT_SYMBOL ( i2c_use_client  )
EXPORT_SYMBOL ( i2c_release_client  )
EXPORT_SYMBOL ( i2c_clients_command  )
EXPORT_SYMBOL ( __i2c_transfer  )
EXPORT_SYMBOL ( i2c_transfer  )
EXPORT_SYMBOL ( i2c_master_send  )
EXPORT_SYMBOL ( i2c_master_recv  )
EXPORT_SYMBOL ( i2c_get_adapter  )
EXPORT_SYMBOL ( i2c_put_adapter  )
EXPORT_SYMBOL ( i2c_smbus_read_byte  )
EXPORT_SYMBOL ( i2c_smbus_write_byte  )
EXPORT_SYMBOL ( i2c_smbus_read_byte_data  )
EXPORT_SYMBOL ( i2c_smbus_write_byte_data  )
EXPORT_SYMBOL ( i2c_smbus_read_word_data  )
EXPORT_SYMBOL ( i2c_smbus_write_word_data  )
EXPORT_SYMBOL ( i2c_smbus_process_call  )
EXPORT_SYMBOL ( i2c_smbus_read_block_data  )
EXPORT_SYMBOL ( i2c_smbus_write_block_data  )
EXPORT_SYMBOL ( i2c_smbus_read_i2c_block_data  )
EXPORT_SYMBOL ( i2c_smbus_write_i2c_block_data  )
EXPORT_SYMBOL ( i2c_smbus_xfer  )
EXPORT_SYMBOL_GPL ( i2c_bus_type  )
EXPORT_SYMBOL_GPL ( i2c_lock_adapter  )
EXPORT_SYMBOL_GPL ( i2c_unlock_adapter  )
EXPORT_SYMBOL_GPL ( i2c_new_device  )
EXPORT_SYMBOL_GPL ( i2c_unregister_device  )
EXPORT_SYMBOL_GPL ( i2c_new_dummy  )
EXPORT_SYMBOL_GPL ( i2c_adapter_type  )
EXPORT_SYMBOL_GPL ( i2c_add_numbered_adapter  )
EXPORT_SYMBOL_GPL ( i2c_for_each_dev  )
EXPORT_SYMBOL_GPL ( i2c_probe_func_quick_read  )
EXPORT_SYMBOL_GPL ( i2c_new_probed_device  )
int i2c_add_adapter ( struct i2c_adapter adapter)

i2c_add_adapter - declare i2c adapter, use dynamic bus number : the adapter to add Context: can sleep

This routine is used to declare an I2C adapter when its bus number doesn't matter. Examples: for I2C adapters dynamically added by USB links or PCI plugin cards.

When this returns zero, a new bus number was allocated and stored in adap->nr, and the specified adapter became available for clients. Otherwise, a negative errno value is returned.

Definition at line 930 of file i2c-core.c.

int i2c_add_numbered_adapter ( struct i2c_adapter adap)

i2c_add_numbered_adapter - declare i2c adapter, use static bus number : the adapter to register (with adap->nr initialized) Context: can sleep

This routine is used to declare an I2C adapter when its bus number matters. For example, use it for I2C adapters from system-on-chip CPUs, or otherwise built in to the system's mainboard, and where i2c_board_info is used to properly configure I2C devices.

If the requested bus number is set to -1, then this function will behave identically to i2c_add_adapter, and will dynamically assign a bus number.

If no devices have pre-been declared for this bus, then be sure to register the adapter before any dynamically allocated ones. Otherwise the required bus ID may not be available.

When this returns zero, the specified adapter became available for clients using the bus number provided in adap->nr. Also, the table of I2C devices pre-declared using i2c_register_board_info() is scanned, and the appropriate driver model device nodes are created. Otherwise, a negative errno value is returned.

Definition at line 978 of file i2c-core.c.

void i2c_clients_command ( struct i2c_adapter adap,
unsigned int  cmd,
void arg 
)

Definition at line 1274 of file i2c-core.c.

int i2c_del_adapter ( struct i2c_adapter adap)

i2c_del_adapter - unregister I2C adapter : the adapter being unregistered Context: can sleep

This unregisters an I2C adapter which was previously registered by or .

Definition at line 1068 of file i2c-core.c.

void i2c_del_driver ( struct i2c_driver driver)

i2c_del_driver - unregister I2C driver : the driver being unregistered Context: can sleep

Definition at line 1216 of file i2c-core.c.

int i2c_for_each_dev ( void data,
int(*)(struct device *, void *)  fn 
)

Definition at line 1143 of file i2c-core.c.

struct i2c_adapter* i2c_get_adapter ( int  nr)
read

Definition at line 1667 of file i2c-core.c.

void i2c_lock_adapter ( struct i2c_adapter adapter)

i2c_lock_adapter - Get exclusive access to an I2C bus segment : Target I2C bus segment

Definition at line 446 of file i2c-core.c.

int i2c_master_recv ( const struct i2c_client client,
char buf,
int  count 
)

i2c_master_recv - issue a single I2C message in master receive mode : Handle to slave device : Where to store data read from slave : How many bytes to read, must be less than 64k since msg.len is u16

Returns negative errno, or else the number of bytes read.

Definition at line 1463 of file i2c-core.c.

int i2c_master_send ( const struct i2c_client client,
const char buf,
int  count 
)

i2c_master_send - issue a single I2C message in master transmit mode : Handle to slave device : Data that will be written to the slave : How many bytes to write, must be less than 64k since msg.len is u16

Returns negative errno, or else the number of bytes written.

Definition at line 1434 of file i2c-core.c.

struct i2c_client* i2c_new_device ( struct i2c_adapter adap,
struct i2c_board_info const info 
)
read

i2c_new_device - instantiate an i2c device : the adapter managing the device : describes one I2C device; bus_num is ignored Context: can sleep

Create an i2c device. Binding is handled through driver model probe()/remove() methods. A driver may be bound to this device when we return from this function, or any later moment (e.g. maybe hotplugging will load the driver module). This call is not appropriate for use by mainboard initialization logic, which usually runs during an arch_initcall() long before any i2c_adapter could exist.

This returns the new i2c client, which may be saved for later use with i2c_unregister_device(); or NULL to indicate an error.

Definition at line 503 of file i2c-core.c.

struct i2c_client* i2c_new_dummy ( struct i2c_adapter adapter,
u16  address 
)
read

i2c_new_dummy - return a new i2c device bound to a dummy driver : the adapter managing the device : seven bit address to be used Context: can sleep

This returns an I2C client bound to the "dummy" driver, intended for use with devices that consume multiple addresses. Examples of such chips include various EEPROMS (like 24c04 and 24c08 models).

These dummy devices have two main uses. First, most I2C and SMBus calls except i2c_transfer() need a client handle; the dummy will be that handle. And second, this prevents the specified address from being bound to a different driver.

This returns the new i2c client, which should be saved for later use with i2c_unregister_device(); or NULL to indicate an error.

Definition at line 619 of file i2c-core.c.

struct i2c_client* i2c_new_probed_device ( struct i2c_adapter adap,
struct i2c_board_info info,
unsigned short const addr_list,
int(*)(struct i2c_adapter *, unsigned short addr probe 
)
read

Definition at line 1627 of file i2c-core.c.

int i2c_probe_func_quick_read ( struct i2c_adapter adap,
unsigned short  addr 
)

Definition at line 1619 of file i2c-core.c.

void i2c_put_adapter ( struct i2c_adapter adap)

Definition at line 1681 of file i2c-core.c.

int i2c_register_driver ( struct module owner,
struct i2c_driver driver 
)

Definition at line 1167 of file i2c-core.c.

void i2c_release_client ( struct i2c_client client)

i2c_release_client - release a use of the i2c client structure : the client being no longer referenced

Must be called when a user of a client is finished with it.

Definition at line 1252 of file i2c-core.c.

s32 i2c_smbus_process_call ( const struct i2c_client client,
u8  command,
u16  value 
)

i2c_smbus_process_call - SMBus "process call" protocol : Handle to slave device : Byte interpreted by slave : 16-bit "word" being written

This executes the SMBus "process call" protocol, returning negative errno else a 16-bit unsigned "word" received from the device.

Definition at line 1871 of file i2c-core.c.

s32 i2c_smbus_read_block_data ( const struct i2c_client client,
u8  command,
u8 values 
)

i2c_smbus_read_block_data - SMBus "block read" protocol : Handle to slave device : Byte interpreted by slave : Byte array into which data will be read; big enough to hold the data returned by the slave. SMBus allows at most 32 bytes.

This executes the SMBus "block read" protocol, returning negative errno else the number of data bytes in the slave's response.

Note that using this function requires that the client's adapter support the I2C_FUNC_SMBUS_READ_BLOCK_DATA functionality. Not all adapter drivers support this; its emulation through I2C messaging relies on a specific mechanism (I2C_M_RECV_LEN) which may not be implemented.

Definition at line 1900 of file i2c-core.c.

s32 i2c_smbus_read_byte ( const struct i2c_client client)

i2c_smbus_read_byte - SMBus "receive byte" protocol : Handle to slave device

This executes the SMBus "receive byte" protocol, returning negative errno else the byte received from the device.

Definition at line 1755 of file i2c-core.c.

s32 i2c_smbus_read_byte_data ( const struct i2c_client client,
u8  command 
)

i2c_smbus_read_byte_data - SMBus "read byte" protocol : Handle to slave device : Byte interpreted by slave

This executes the SMBus "read byte" protocol, returning negative errno else a data byte received from the device.

Definition at line 1790 of file i2c-core.c.

s32 i2c_smbus_read_i2c_block_data ( const struct i2c_client client,
u8  command,
u8  length,
u8 values 
)

Definition at line 1943 of file i2c-core.c.

s32 i2c_smbus_read_word_data ( const struct i2c_client client,
u8  command 
)

i2c_smbus_read_word_data - SMBus "read word" protocol : Handle to slave device : Byte interpreted by slave

This executes the SMBus "read word" protocol, returning negative errno else a 16-bit unsigned "word" received from the device.

Definition at line 1830 of file i2c-core.c.

s32 i2c_smbus_write_block_data ( const struct i2c_client client,
u8  command,
u8  length,
const u8 values 
)

i2c_smbus_write_block_data - SMBus "block write" protocol : Handle to slave device : Byte interpreted by slave : Size of data block; SMBus allows at most 32 bytes : Byte array which will be written.

This executes the SMBus "block write" protocol, returning negative errno else zero on success.

Definition at line 1927 of file i2c-core.c.

s32 i2c_smbus_write_byte ( const struct i2c_client client,
u8  value 
)

i2c_smbus_write_byte - SMBus "send byte" protocol : Handle to slave device : Byte to be sent

This executes the SMBus "send byte" protocol, returning negative errno else zero on success.

Definition at line 1775 of file i2c-core.c.

s32 i2c_smbus_write_byte_data ( const struct i2c_client client,
u8  command,
u8  value 
)

i2c_smbus_write_byte_data - SMBus "write byte" protocol : Handle to slave device : Byte interpreted by slave : Byte being written

This executes the SMBus "write byte" protocol, returning negative errno else zero on success.

Definition at line 1811 of file i2c-core.c.

s32 i2c_smbus_write_i2c_block_data ( const struct i2c_client client,
u8  command,
u8  length,
const u8 values 
)

Definition at line 1963 of file i2c-core.c.

s32 i2c_smbus_write_word_data ( const struct i2c_client client,
u8  command,
u16  value 
)

i2c_smbus_write_word_data - SMBus "write word" protocol : Handle to slave device : Byte interpreted by slave : 16-bit "word" being written

This executes the SMBus "write word" protocol, returning negative errno else zero on success.

Definition at line 1851 of file i2c-core.c.

s32 i2c_smbus_xfer ( struct i2c_adapter adapter,
u16  addr,
unsigned short  flags,
char  read_write,
u8  command,
int  protocol,
union i2c_smbus_data data 
)

Definition at line 2167 of file i2c-core.c.

int i2c_transfer ( struct i2c_adapter adap,
struct i2c_msg msgs,
int  num 
)

i2c_transfer - execute a single or combined I2C message : Handle to I2C bus : One or more messages to execute before STOP is issued to terminate the operation; each message begins with a START. : Number of messages to be executed.

Returns negative errno, else the number of messages executed.

Note that there is no requirement that each message be sent to the same slave address, although that is the most common model.

Definition at line 1375 of file i2c-core.c.

void i2c_unlock_adapter ( struct i2c_adapter adapter)

i2c_unlock_adapter - Release exclusive access to an I2C bus segment : Target I2C bus segment

Definition at line 475 of file i2c-core.c.

void i2c_unregister_device ( struct i2c_client client)

i2c_unregister_device - reverse effect of i2c_new_device() : value returned from i2c_new_device() Context: can sleep

Definition at line 571 of file i2c-core.c.

struct i2c_client* i2c_use_client ( struct i2c_client client)
read

i2c_use_client - increments the reference count of the i2c client structure : the client being referenced

Each live reference to a client should be refcounted. The driver model does that automatically as part of driver binding, so that most drivers don't need to do this explicitly: they hold a reference until they're unbound from the device.

A pointer to the client with the incremented reference counter is returned.

Definition at line 1238 of file i2c-core.c.

struct i2c_adapter* i2c_verify_adapter ( struct device dev)
read

i2c_verify_adapter - return parameter as i2c_adapter or NULL : device, probably from some driver model iterator

When traversing the driver model tree, perhaps using driver model iterators like (), you can't assume very much about the nodes you find. Use this function to avoid oopses caused by wrongly treating some non-I2C device as an i2c_adapter.

Definition at line 801 of file i2c-core.c.

struct i2c_client* i2c_verify_client ( struct device dev)
read

i2c_verify_client - return parameter as i2c_client, or NULL : device, probably from some driver model iterator

When traversing the driver model tree, perhaps using driver model iterators like (), you can't assume very much about the nodes you find. Use this function to avoid oopses caused by wrongly treating some non-I2C device as an i2c_client.

Definition at line 342 of file i2c-core.c.

MODULE_AUTHOR ( "Simon G. Vogl <[email protected]linz.ac.at>"  )
MODULE_DESCRIPTION ( "I2C-Bus main module )
module_exit ( i2c_exit  )
MODULE_LICENSE ( "GPL"  )
postcore_initcall ( i2c_init  )

Variable Documentation

struct device_type i2c_adapter_type
Initial value:
= {
.groups = i2c_adapter_attr_groups,
.release = i2c_adapter_dev_release,
}

Definition at line 786 of file i2c-core.c.

struct bus_type i2c_bus_type
Initial value:
= {
.name = "i2c",
.match = i2c_device_match,
.probe = i2c_device_probe,
.remove = i2c_device_remove,
.shutdown = i2c_device_shutdown,
.pm = &i2c_device_pm_ops,
}

Definition at line 316 of file i2c-core.c.