Lines Matching full:i2c
2 I2C Device Interface
5 Usually, i2c devices are controlled by a kernel driver. But it is also
7 the /dev interface. You need to load module i2c-dev for this.
9 Each registered i2c adapter gets a number, counting from 0. You can
10 examine /sys/class/i2c-dev/ to see what number corresponds to which adapter.
12 i2c adapters present on your system at a given time. i2cdetect is part of
13 the i2c-tools package.
15 I2C device files are character device files with major device number 89
17 explained above. They should be called "i2c-%d" (i2c-0, i2c-1, ...,
18 i2c-10, ...). All 256 minor device numbers are reserved for i2c.
24 So let's say you want to access an i2c adapter from a C program.
27 #include <linux/i2c-dev.h>
28 #include <i2c/smbus.h>
31 inspect /sys/class/i2c-dev/ or run "i2cdetect -l" to decide this.
41 snprintf(filename, 19, "/dev/i2c-%d", adapter_nr);
51 int addr = 0x40; /* The I2C address */
59 I2C to communicate with your device. SMBus commands are preferred if
69 /* ERROR HANDLING: i2c transaction failed */
75 * Using I2C Write, equivalent of
82 /* ERROR HANDLING: i2c transaction failed */
85 /* Using I2C Read, equivalent of i2c_smbus_read_byte(file) */
87 /* ERROR HANDLING: i2c transaction failed */
92 Note that only a subset of the I2C and SMBus protocols can be achieved by
147 You can do plain i2c transactions by using read(2) and write(2) calls.
173 which is provided by the i2c-tools project. See:
174 https://git.kernel.org/pub/scm/utils/i2c-tools/i2c-tools.git/.
181 when you use the /dev interface to I2C:
183 1) Your program opens /dev/i2c-N and calls ioctl() on it, as described in
186 2) These open() and ioctl() calls are handled by the i2c-dev kernel
187 driver: see i2c-dev.c:i2cdev_open() and i2c-dev.c:i2cdev_ioctl(),
188 respectively. You can think of i2c-dev as a generic I2C chip driver
192 i2c-dev directly. Examples include I2C_SLAVE (set the address of the
197 i2c-dev. Examples include I2C_FUNCS, which queries the I2C adapter
198 functionality using i2c.h:i2c_get_functionality(), and I2C_SMBUS, which
199 performs an SMBus transaction using i2c-core-smbus.c:i2c_smbus_xfer().
201 The i2c-dev driver is responsible for checking all the parameters that
203 difference between these calls that came from user-space through i2c-dev
204 and calls that would have been performed by kernel I2C chip drivers
205 directly. This means that I2C bus drivers don't need to implement
208 5) These i2c.h functions are wrappers to the actual implementation of
209 your I2C bus driver. Each adapter must declare callback functions
210 implementing these standard calls. i2c.h:i2c_get_functionality() calls
212 i2c-core-smbus.c:i2c_smbus_xfer() calls either
214 i2c-core-smbus.c:i2c_smbus_xfer_emulated() which in turn calls
217 After your I2C bus driver has processed these requests, execution runs
218 up the call chain, with almost no processing done, except by i2c-dev to