xref: /aosp_15_r20/external/coreboot/src/include/device/i2c.h (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #ifndef _DEVICE_I2C_H_
4 #define _DEVICE_I2C_H_
5 
6 #include <stdint.h>
7 
8 /**
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  */
32 struct 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 
43 enum 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 
51 enum i2c_address_mode {
52 	I2C_MODE_7_BIT,
53 	I2C_MODE_10_BIT
54 };
55 
56 #endif	/* _DEVICE_I2C_H_ */
57