blob: b7605db4ffee30338b67971e43ca29dc447b5fc6 [file] [log] [blame]
Angel Pons32859fc2020-04-02 23:48:27 +02001/* SPDX-License-Identifier: GPL-2.0-only */
David Hendricksf4c35082012-12-27 14:15:51 -08002
David Hendrickscfb73602013-04-05 13:42:39 -07003#ifndef _DEVICE_I2C_H_
4#define _DEVICE_I2C_H_
David Hendricksf4c35082012-12-27 14:15:51 -08005
Gabe Blacka5dc0912013-06-30 03:47:33 -07006#include <stdint.h>
7
Nico Huber029dfff2017-07-12 17:59:16 +02008/**
9 * struct i2c_msg - an I2C transaction segment beginning with START
10 * @addr: Slave address, either seven or ten bits. When this is a ten
11 * bit address, I2C_M_TEN must be set in @flags.
12 * @flags: I2C_M_RD is handled by all adapters.
13 * @len: Number of data bytes in @buf being read from or written to the
14 * I2C slave address. For read transactions where I2C_M_RECV_LEN
15 * is set, the caller guarantees that this buffer can hold up to
16 * 32 bytes in addition to the initial length byte sent by the
17 * slave (plus, if used, the SMBus PEC).
18 * @buf: The buffer into which data is read, or from which it's written.
19 *
20 * An i2c_msg is the low level representation of one segment of an I2C
21 * transaction. It is visible to drivers in the @i2c_transfer() procedure.
22 *
23 * All I2C adapters implement the standard rules for I2C transactions. Each
24 * transaction begins with a START. That is followed by the slave address,
25 * and a bit encoding read versus write. Then follow all the data bytes,
26 * possibly including a byte with SMBus PEC. The transfer terminates with
27 * a NAK, or when all those bytes have been transferred and ACKed. If this
28 * is the last message in a group, it is followed by a STOP. Otherwise it
29 * is followed by the next @i2c_msg transaction segment, beginning with a
30 * (repeated) START.
31 */
32struct i2c_msg {
33 uint16_t flags;
34#define I2C_M_RD 0x0001 /* read data, from slave to master */
35#define I2C_M_TEN 0x0010 /* this is a ten bit chip address */
36#define I2C_M_RECV_LEN 0x0400 /* length will be first received byte */
37#define I2C_M_NOSTART 0x4000 /* don't send a repeated START */
38 uint16_t slave; /* slave address */
39 uint16_t len; /* msg length */
40 uint8_t *buf; /* pointer to msg data */
41};
42
Duncan Laurie1010b4a2016-05-09 20:10:47 -070043enum i2c_speed {
44 I2C_SPEED_STANDARD = 100000,
45 I2C_SPEED_FAST = 400000,
46 I2C_SPEED_FAST_PLUS = 1000000,
47 I2C_SPEED_HIGH = 3400000,
48 I2C_SPEED_FAST_ULTRA = 5000000,
49};
50
51enum i2c_address_mode {
52 I2C_MODE_7_BIT,
53 I2C_MODE_10_BIT
54};
55
David Hendrickscfb73602013-04-05 13:42:39 -070056#endif /* _DEVICE_I2C_H_ */