1/* ------------------------------------------------------------------------- */
2/*									     */
3/* i2c.h - definitions for the i2c-bus interface			     */
4/*									     */
5/* ------------------------------------------------------------------------- */
6/*   Copyright (C) 1995-2000 Simon G. Vogl
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.		     */
21/* ------------------------------------------------------------------------- */
22
23/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and
24   Frodo Looijaard <frodol@dds.nl> */
25
26#ifndef _LINUX_I2C_H
27#define _LINUX_I2C_H
28
29#include <linux/types.h>
30
31/**
32 * struct i2c_msg - an I2C transaction segment beginning with START
33 * @addr: Slave address, either seven or ten bits.  When this is a ten
34 *	bit address, I2C_M_TEN must be set in @flags and the adapter
35 *	must support I2C_FUNC_10BIT_ADDR.
36 * @flags: I2C_M_RD is handled by all adapters.  No other flags may be
37 *	provided unless the adapter exported the relevant I2C_FUNC_*
38 *	flags through i2c_check_functionality().
39 * @len: Number of data bytes in @buf being read from or written to the
40 *	I2C slave address.  For read transactions where I2C_M_RECV_LEN
41 *	is set, the caller guarantees that this buffer can hold up to
42 *	32 bytes in addition to the initial length byte sent by the
43 *	slave (plus, if used, the SMBus PEC); and this value will be
44 *	incremented by the number of block data bytes received.
45 * @buf: The buffer into which data is read, or from which it's written.
46 *
47 * An i2c_msg is the low level representation of one segment of an I2C
48 * transaction.  It is visible to drivers in the @i2c_transfer() procedure,
49 * to userspace from i2c-dev, and to I2C adapter drivers through the
50 * @i2c_adapter.@master_xfer() method.
51 *
52 * Except when I2C "protocol mangling" is used, all I2C adapters implement
53 * the standard rules for I2C transactions.  Each transaction begins with a
54 * START.  That is followed by the slave address, and a bit encoding read
55 * versus write.  Then follow all the data bytes, possibly including a byte
56 * with SMBus PEC.  The transfer terminates with a NAK, or when all those
57 * bytes have been transferred and ACKed.  If this is the last message in a
58 * group, it is followed by a STOP.  Otherwise it is followed by the next
59 * @i2c_msg transaction segment, beginning with a (repeated) START.
60 *
61 * Alternatively, when the adapter supports I2C_FUNC_PROTOCOL_MANGLING then
62 * passing certain @flags may have changed those standard protocol behaviors.
63 * Those flags are only for use with broken/nonconforming slaves, and with
64 * adapters which are known to support the specific mangling options they
65 * need (one or more of IGNORE_NAK, NO_RD_ACK, NOSTART, and REV_DIR_ADDR).
66 */
67struct i2c_msg {
68	__u16 addr;	/* slave address			*/
69	__u16 flags;
70#define I2C_M_TEN		0x0010	/* this is a ten bit chip address */
71#define I2C_M_RD		0x0001	/* read data, from slave to master */
72#define I2C_M_NOSTART		0x4000	/* if I2C_FUNC_PROTOCOL_MANGLING */
73#define I2C_M_REV_DIR_ADDR	0x2000	/* if I2C_FUNC_PROTOCOL_MANGLING */
74#define I2C_M_IGNORE_NAK	0x1000	/* if I2C_FUNC_PROTOCOL_MANGLING */
75#define I2C_M_NO_RD_ACK		0x0800	/* if I2C_FUNC_PROTOCOL_MANGLING */
76#define I2C_M_RECV_LEN		0x0400	/* length will be first received byte */
77	__u16 len;		/* msg length				*/
78	__u8 *buf;		/* pointer to msg data			*/
79};
80
81/* To determine what functionality is present */
82
83#define I2C_FUNC_I2C			0x00000001
84#define I2C_FUNC_10BIT_ADDR		0x00000002
85#define I2C_FUNC_PROTOCOL_MANGLING	0x00000004 /* I2C_M_{REV_DIR_ADDR,NOSTART,..} */
86#define I2C_FUNC_SMBUS_PEC		0x00000008
87#define I2C_FUNC_SMBUS_BLOCK_PROC_CALL	0x00008000 /* SMBus 2.0 */
88#define I2C_FUNC_SMBUS_QUICK		0x00010000
89#define I2C_FUNC_SMBUS_READ_BYTE	0x00020000
90#define I2C_FUNC_SMBUS_WRITE_BYTE	0x00040000
91#define I2C_FUNC_SMBUS_READ_BYTE_DATA	0x00080000
92#define I2C_FUNC_SMBUS_WRITE_BYTE_DATA	0x00100000
93#define I2C_FUNC_SMBUS_READ_WORD_DATA	0x00200000
94#define I2C_FUNC_SMBUS_WRITE_WORD_DATA	0x00400000
95#define I2C_FUNC_SMBUS_PROC_CALL	0x00800000
96#define I2C_FUNC_SMBUS_READ_BLOCK_DATA	0x01000000
97#define I2C_FUNC_SMBUS_WRITE_BLOCK_DATA 0x02000000
98#define I2C_FUNC_SMBUS_READ_I2C_BLOCK	0x04000000 /* I2C-like block xfer  */
99#define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK	0x08000000 /* w/ 1-byte reg. addr. */
100#define I2C_FUNC_SMBUS_READ_I2C_BLOCK_2	 0x10000000 /* I2C-like block xfer  */
101#define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK_2 0x20000000 /* w/ 2-byte reg. addr. */
102
103#define I2C_FUNC_SMBUS_BYTE (I2C_FUNC_SMBUS_READ_BYTE | \
104                             I2C_FUNC_SMBUS_WRITE_BYTE)
105#define I2C_FUNC_SMBUS_BYTE_DATA (I2C_FUNC_SMBUS_READ_BYTE_DATA | \
106                                  I2C_FUNC_SMBUS_WRITE_BYTE_DATA)
107#define I2C_FUNC_SMBUS_WORD_DATA (I2C_FUNC_SMBUS_READ_WORD_DATA | \
108                                  I2C_FUNC_SMBUS_WRITE_WORD_DATA)
109#define I2C_FUNC_SMBUS_BLOCK_DATA (I2C_FUNC_SMBUS_READ_BLOCK_DATA | \
110                                   I2C_FUNC_SMBUS_WRITE_BLOCK_DATA)
111#define I2C_FUNC_SMBUS_I2C_BLOCK (I2C_FUNC_SMBUS_READ_I2C_BLOCK | \
112                                  I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)
113#define I2C_FUNC_SMBUS_I2C_BLOCK_2 (I2C_FUNC_SMBUS_READ_I2C_BLOCK_2 | \
114                                    I2C_FUNC_SMBUS_WRITE_I2C_BLOCK_2)
115
116#define I2C_FUNC_SMBUS_EMUL (I2C_FUNC_SMBUS_QUICK | \
117                             I2C_FUNC_SMBUS_BYTE | \
118                             I2C_FUNC_SMBUS_BYTE_DATA | \
119                             I2C_FUNC_SMBUS_WORD_DATA | \
120                             I2C_FUNC_SMBUS_PROC_CALL | \
121                             I2C_FUNC_SMBUS_WRITE_BLOCK_DATA | \
122			     I2C_FUNC_SMBUS_I2C_BLOCK | \
123			     I2C_FUNC_SMBUS_PEC)
124
125/*
126 * Data for SMBus Messages
127 */
128#define I2C_SMBUS_BLOCK_MAX	32	/* As specified in SMBus standard */
129union i2c_smbus_data {
130	__u8 byte;
131	__u16 word;
132	__u8 block[I2C_SMBUS_BLOCK_MAX + 2]; /* block[0] is used for length */
133	                       /* and one more for user-space compatibility */
134};
135
136/* smbus_access read or write markers */
137#define I2C_SMBUS_READ	1
138#define I2C_SMBUS_WRITE	0
139
140/* SMBus transaction types (size parameter in the above functions)
141   Note: these no longer correspond to the (arbitrary) PIIX4 internal codes! */
142#define I2C_SMBUS_QUICK		    0
143#define I2C_SMBUS_BYTE		    1
144#define I2C_SMBUS_BYTE_DATA	    2
145#define I2C_SMBUS_WORD_DATA	    3
146#define I2C_SMBUS_PROC_CALL	    4
147#define I2C_SMBUS_BLOCK_DATA	    5
148#define I2C_SMBUS_I2C_BLOCK_BROKEN  6
149#define I2C_SMBUS_BLOCK_PROC_CALL   7		/* SMBus 2.0 */
150#define I2C_SMBUS_I2C_BLOCK_DATA    8
151
152
153#endif /* _LINUX_I2C_H */
154