• Home
  • Raw
  • Download

Lines Matching full:i2c

2 Implementing I2C device drivers in userspace
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.
175 which is provided by the i2c-tools project. See:
176 https://git.kernel.org/pub/scm/utils/i2c-tools/i2c-tools.git/.
183 when you use the /dev interface to I2C:
185 1) Your program opens /dev/i2c-N and calls ioctl() on it, as described in
188 2) These open() and ioctl() calls are handled by the i2c-dev kernel
189 driver: see i2c-dev.c:i2cdev_open() and i2c-dev.c:i2cdev_ioctl(),
190 respectively. You can think of i2c-dev as a generic I2C chip driver
194 i2c-dev directly. Examples include I2C_SLAVE (set the address of the
199 i2c-dev. Examples include I2C_FUNCS, which queries the I2C adapter
200 functionality using i2c.h:i2c_get_functionality(), and I2C_SMBUS, which
201 performs an SMBus transaction using i2c-core-smbus.c:i2c_smbus_xfer().
203 The i2c-dev driver is responsible for checking all the parameters that
205 difference between these calls that came from user-space through i2c-dev
206 and calls that would have been performed by kernel I2C chip drivers
207 directly. This means that I2C bus drivers don't need to implement
210 5) These i2c.h functions are wrappers to the actual implementation of
211 your I2C bus driver. Each adapter must declare callback functions
212 implementing these standard calls. i2c.h:i2c_get_functionality() calls
214 i2c-core-smbus.c:i2c_smbus_xfer() calls either
216 i2c-core-smbus.c:i2c_smbus_xfer_emulated() which in turn calls
219 After your I2C bus driver has processed these requests, execution runs
220 up the call chain, with almost no processing done, except by i2c-dev to