^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) ============================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) Implementing I2C device drivers in userspace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) ============================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) Usually, I2C devices are controlled by a kernel driver. But it is also
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) possible to access all devices on an adapter from userspace, through
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) the /dev interface. You need to load module i2c-dev for this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) Each registered I2C adapter gets a number, counting from 0. You can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) examine /sys/class/i2c-dev/ to see what number corresponds to which adapter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) Alternatively, you can run "i2cdetect -l" to obtain a formatted list of all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) I2C adapters present on your system at a given time. i2cdetect is part of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) the i2c-tools package.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) I2C device files are character device files with major device number 89
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) and a minor device number corresponding to the number assigned as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) explained above. They should be called "i2c-%d" (i2c-0, i2c-1, ...,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) i2c-10, ...). All 256 minor device numbers are reserved for I2C.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) C example
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) =========
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) So let's say you want to access an I2C adapter from a C program.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) First, you need to include these two headers::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/i2c-dev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <i2c/smbus.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) Now, you have to decide which adapter you want to access. You should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) inspect /sys/class/i2c-dev/ or run "i2cdetect -l" to decide this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) Adapter numbers are assigned somewhat dynamically, so you can not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) assume much about them. They can even change from one boot to the next.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) Next thing, open the device file, as follows::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) int file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) int adapter_nr = 2; /* probably dynamically determined */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) char filename[20];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) snprintf(filename, 19, "/dev/i2c-%d", adapter_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) file = open(filename, O_RDWR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) if (file < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) /* ERROR HANDLING; you can check errno to see what went wrong */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) exit(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) When you have opened the device, you must specify with what device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) address you want to communicate::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) int addr = 0x40; /* The I2C address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) if (ioctl(file, I2C_SLAVE, addr) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) /* ERROR HANDLING; you can check errno to see what went wrong */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) exit(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) Well, you are all set up now. You can now use SMBus commands or plain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) I2C to communicate with your device. SMBus commands are preferred if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) the device supports them. Both are illustrated below::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) __u8 reg = 0x10; /* Device register to access */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) __s32 res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) char buf[10];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) /* Using SMBus commands */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) res = i2c_smbus_read_word_data(file, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) if (res < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) /* ERROR HANDLING: I2C transaction failed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) /* res contains the read word */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * Using I2C Write, equivalent of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * i2c_smbus_write_word_data(file, reg, 0x6543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) buf[0] = reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) buf[1] = 0x43;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) buf[2] = 0x65;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) if (write(file, buf, 3) != 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) /* ERROR HANDLING: I2C transaction failed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) /* Using I2C Read, equivalent of i2c_smbus_read_byte(file) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) if (read(file, buf, 1) != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) /* ERROR HANDLING: I2C transaction failed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) /* buf[0] contains the read byte */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) Note that only a subset of the I2C and SMBus protocols can be achieved by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) the means of read() and write() calls. In particular, so-called combined
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) transactions (mixing read and write messages in the same transaction)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) aren't supported. For this reason, this interface is almost never used by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) user-space programs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) IMPORTANT: because of the use of inline functions, you *have* to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) '-O' or some variation when you compile your program!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) Full interface description
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) ==========================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) The following IOCTLs are defined:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) ``ioctl(file, I2C_SLAVE, long addr)``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) Change slave address. The address is passed in the 7 lower bits of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) argument (except for 10 bit addresses, passed in the 10 lower bits in this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) case).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) ``ioctl(file, I2C_TENBIT, long select)``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) Selects ten bit addresses if select not equals 0, selects normal 7 bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) addresses if select equals 0. Default 0. This request is only valid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) if the adapter has I2C_FUNC_10BIT_ADDR.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) ``ioctl(file, I2C_PEC, long select)``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) Selects SMBus PEC (packet error checking) generation and verification
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) if select not equals 0, disables if select equals 0. Default 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) Used only for SMBus transactions. This request only has an effect if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) the adapter has I2C_FUNC_SMBUS_PEC; it is still safe if not, it just
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) doesn't have any effect.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) ``ioctl(file, I2C_FUNCS, unsigned long *funcs)``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) Gets the adapter functionality and puts it in ``*funcs``.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) ``ioctl(file, I2C_RDWR, struct i2c_rdwr_ioctl_data *msgset)``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) Do combined read/write transaction without stop in between.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) Only valid if the adapter has I2C_FUNC_I2C. The argument is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) a pointer to a::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) struct i2c_rdwr_ioctl_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) struct i2c_msg *msgs; /* ptr to array of simple messages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) int nmsgs; /* number of messages to exchange */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) The msgs[] themselves contain further pointers into data buffers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) The function will write or read data to or from that buffers depending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) on whether the I2C_M_RD flag is set in a particular message or not.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) The slave address and whether to use ten bit address mode has to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) set in each message, overriding the values set with the above ioctl's.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) ``ioctl(file, I2C_SMBUS, struct i2c_smbus_ioctl_data *args)``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) If possible, use the provided ``i2c_smbus_*`` methods described below instead
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) of issuing direct ioctls.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) You can do plain I2C transactions by using read(2) and write(2) calls.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) You do not need to pass the address byte; instead, set it through
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) ioctl I2C_SLAVE before you try to access the device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) You can do SMBus level transactions (see documentation file smbus-protocol
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) for details) through the following functions::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) __s32 i2c_smbus_write_quick(int file, __u8 value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) __s32 i2c_smbus_read_byte(int file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) __s32 i2c_smbus_write_byte(int file, __u8 value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) __s32 i2c_smbus_read_byte_data(int file, __u8 command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) __s32 i2c_smbus_write_byte_data(int file, __u8 command, __u8 value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) __s32 i2c_smbus_read_word_data(int file, __u8 command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) __s32 i2c_smbus_write_word_data(int file, __u8 command, __u16 value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) __s32 i2c_smbus_process_call(int file, __u8 command, __u16 value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) __s32 i2c_smbus_block_process_call(int file, __u8 command, __u8 length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) __u8 *values);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) __s32 i2c_smbus_read_block_data(int file, __u8 command, __u8 *values);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) __s32 i2c_smbus_write_block_data(int file, __u8 command, __u8 length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) __u8 *values);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) All these transactions return -1 on failure; you can read errno to see
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) what happened. The 'write' transactions return 0 on success; the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 'read' transactions return the read value, except for read_block, which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) returns the number of values read. The block buffers need not be longer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) than 32 bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) The above functions are made available by linking against the libi2c library,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) which is provided by the i2c-tools project. See:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) https://git.kernel.org/pub/scm/utils/i2c-tools/i2c-tools.git/.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) Implementation details
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) ======================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) For the interested, here's the code flow which happens inside the kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) when you use the /dev interface to I2C:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 1) Your program opens /dev/i2c-N and calls ioctl() on it, as described in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) section "C example" above.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 2) These open() and ioctl() calls are handled by the i2c-dev kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) driver: see i2c-dev.c:i2cdev_open() and i2c-dev.c:i2cdev_ioctl(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) respectively. You can think of i2c-dev as a generic I2C chip driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) that can be programmed from user-space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 3) Some ioctl() calls are for administrative tasks and are handled by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) i2c-dev directly. Examples include I2C_SLAVE (set the address of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) device you want to access) and I2C_PEC (enable or disable SMBus error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) checking on future transactions.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 4) Other ioctl() calls are converted to in-kernel function calls by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) i2c-dev. Examples include I2C_FUNCS, which queries the I2C adapter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) functionality using i2c.h:i2c_get_functionality(), and I2C_SMBUS, which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) performs an SMBus transaction using i2c-core-smbus.c:i2c_smbus_xfer().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) The i2c-dev driver is responsible for checking all the parameters that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) come from user-space for validity. After this point, there is no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) difference between these calls that came from user-space through i2c-dev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) and calls that would have been performed by kernel I2C chip drivers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) directly. This means that I2C bus drivers don't need to implement
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) anything special to support access from user-space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 5) These i2c.h functions are wrappers to the actual implementation of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) your I2C bus driver. Each adapter must declare callback functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) implementing these standard calls. i2c.h:i2c_get_functionality() calls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) i2c_adapter.algo->functionality(), while
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) i2c-core-smbus.c:i2c_smbus_xfer() calls either
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) adapter.algo->smbus_xfer() if it is implemented, or if not,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) i2c-core-smbus.c:i2c_smbus_xfer_emulated() which in turn calls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) i2c_adapter.algo->master_xfer().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) After your I2C bus driver has processed these requests, execution runs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) up the call chain, with almost no processing done, except by i2c-dev to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) package the returned data, if any, in suitable format for the ioctl.