source: rtems/cpukit/dev/include/linux/i2c.h @ 9598e737

5
Last change on this file since 9598e737 was 9598e737, checked in by Sebastian Huber <sebastian.huber@…>, on 07/17/17 at 06:23:22

i2c: Point to most relevant Linux documentation

  • Property mode set to 100644
File size: 5.9 KB
Line 
1/**
2 * @file
3 *
4 * @brief RTEMS Port of Linux I2C API
5 *
6 * @ingroup I2CLinux
7 */
8
9/*
10 * Copyright (c) 2014 embedded brains GmbH.  All rights reserved.
11 *
12 *  embedded brains GmbH
13 *  Dornierstr. 4
14 *  82178 Puchheim
15 *  Germany
16 *  <rtems@embedded-brains.de>
17 *
18 * The license and distribution terms for this file may be
19 * found in the file LICENSE in this distribution or at
20 * http://www.rtems.org/license/LICENSE.
21 */
22
23#ifndef _UAPI_LINUX_I2C_H
24#define _UAPI_LINUX_I2C_H
25
26#include <stdint.h>
27
28/**
29 * @defgroup I2CLinux Linux I2C User-Space API
30 *
31 * @ingroup I2C
32 *
33 * @brief RTEMS port of Linux I2C user-space API.
34 *
35 * Additional documentation is available through the Linux sources, see:
36 *
37 * - /usr/src/linux/include/uapi/linux/i2c.h,
38 * - /usr/src/linux/include/uapi/linux/i2c-dev.h
39 * - https://www.kernel.org/doc/Documentation/i2c/i2c-protocol
40 * - https://www.kernel.org/doc/Documentation/i2c/dev-interface
41 *
42 * @{
43 */
44
45/**
46 * @name I2C Message Flags
47 *
48 * @{
49 */
50
51/**
52 * @brief I2C message flag to indicate a 10-bit address.
53 *
54 * The controller must support this as indicated by the I2C_FUNC_10BIT_ADDR
55 * functionality.
56 *
57 * @see i2c_msg.
58 */
59#define I2C_M_TEN 0x0010
60
61/**
62 * @brief I2C message flag to indicate a read transfer (from slave to master).
63 *
64 * @see i2c_msg.
65 */
66#define I2C_M_RD 0x0001
67
68/**
69 * @brief I2C message flag to signal a stop condition even if this is not the
70 * last message.
71 *
72 * The controller must support this as indicated by the
73 * @ref I2C_FUNC_PROTOCOL_MANGLING functionality.
74 *
75 * @see i2c_msg.
76 */
77#define I2C_M_STOP 0x8000
78
79/**
80 * @brief I2C message flag to omit start condition and slave address.
81 *
82 * The controller must support this as indicated by the
83 * @ref I2C_FUNC_NOSTART functionality.
84 *
85 * @see i2c_msg.
86 */
87#define I2C_M_NOSTART 0x4000
88
89/**
90 * @brief I2C message flag to reverse the direction flag.
91 *
92 * The controller must support this as indicated by the
93 * @ref I2C_FUNC_PROTOCOL_MANGLING functionality.
94 *
95 * @see i2c_msg.
96 */
97#define I2C_M_REV_DIR_ADDR 0x2000
98
99/**
100 * @brief I2C message flag to ignore a non-acknowledge.
101 *
102 * The controller must support this as indicated by the
103 * @ref I2C_FUNC_PROTOCOL_MANGLING functionality.
104 *
105 * @see i2c_msg.
106 */
107#define I2C_M_IGNORE_NAK 0x1000
108
109/**
110 * @brief I2C message flag to omit a master acknowledge/non-acknowledge in a
111 * read transfer.
112 *
113 * The controller must support this as indicated by the
114 * @ref I2C_FUNC_PROTOCOL_MANGLING functionality.
115 *
116 * @see i2c_msg.
117 */
118#define I2C_M_NO_RD_ACK 0x0800
119
120/**
121 * @brief I2C message flag to indicate that the message data length is the
122 * first received byte.
123 *
124 * The message data buffer must be large enough to store up to 32 bytes, the
125 * initial length byte and the SMBus PEC (if used).  Initialize the message
126 * length to one.  The message length is incremented by the count of received
127 * data bytes.
128 *
129 * @see i2c_msg.
130 */
131#define I2C_M_RECV_LEN 0x0400
132
133/** @} */
134
135/**
136 * @brief I2C transfer message.
137 */
138struct i2c_msg {
139  /**
140   * @brief The slave address.
141   *
142   * In case the @ref I2C_M_TEN flag is set, then this is a 10-bit address,
143   * otherwise it is a 7-bit address.
144   */
145  uint16_t addr;
146
147  /**
148   * @brief The message flags.
149   *
150   * Valid flags are
151   * - @ref I2C_M_TEN,
152   * - @ref I2C_M_RD,
153   * - @ref I2C_M_STOP,
154   * - @ref I2C_M_NOSTART,
155   * - @ref I2C_M_REV_DIR_ADDR,
156   * - @ref I2C_M_IGNORE_NAK,
157   * - @ref I2C_M_NO_RD_ACK, and
158   * - @ref I2C_M_RECV_LEN.
159   */
160  uint16_t flags;
161
162  /**
163   * @brief The message data length in bytes.
164   */
165  uint16_t len;
166
167  /**
168   * @brief Pointer to the message data.
169   */
170  uint8_t *buf;
171};
172
173/**
174 * @name I2C Controller Functionality
175 *
176 * @{
177 */
178
179#define I2C_FUNC_I2C 0x00000001
180#define I2C_FUNC_10BIT_ADDR 0x00000002
181#define I2C_FUNC_PROTOCOL_MANGLING 0x00000004
182#define I2C_FUNC_SMBUS_PEC 0x00000008
183#define I2C_FUNC_NOSTART 0x00000010
184#define I2C_FUNC_SMBUS_BLOCK_PROC_CALL 0x00008000
185#define I2C_FUNC_SMBUS_QUICK 0x00010000
186#define I2C_FUNC_SMBUS_READ_BYTE 0x00020000
187#define I2C_FUNC_SMBUS_WRITE_BYTE 0x00040000
188#define I2C_FUNC_SMBUS_READ_BYTE_DATA 0x00080000
189#define I2C_FUNC_SMBUS_WRITE_BYTE_DATA 0x00100000
190#define I2C_FUNC_SMBUS_READ_WORD_DATA 0x00200000
191#define I2C_FUNC_SMBUS_WRITE_WORD_DATA 0x00400000
192#define I2C_FUNC_SMBUS_PROC_CALL 0x00800000
193#define I2C_FUNC_SMBUS_READ_BLOCK_DATA 0x01000000
194#define I2C_FUNC_SMBUS_WRITE_BLOCK_DATA 0x02000000
195#define I2C_FUNC_SMBUS_READ_I2C_BLOCK 0x04000000
196#define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK 0x08000000
197
198#define I2C_FUNC_SMBUS_BYTE \
199  (I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE)
200
201#define I2C_FUNC_SMBUS_BYTE_DATA \
202  (I2C_FUNC_SMBUS_READ_BYTE_DATA | I2C_FUNC_SMBUS_WRITE_BYTE_DATA)
203
204#define I2C_FUNC_SMBUS_WORD_DATA \
205  (I2C_FUNC_SMBUS_READ_WORD_DATA | I2C_FUNC_SMBUS_WRITE_WORD_DATA)
206
207#define I2C_FUNC_SMBUS_BLOCK_DATA \
208  (I2C_FUNC_SMBUS_READ_BLOCK_DATA | I2C_FUNC_SMBUS_WRITE_BLOCK_DATA)
209
210#define I2C_FUNC_SMBUS_I2C_BLOCK \
211  (I2C_FUNC_SMBUS_READ_I2C_BLOCK | I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)
212
213#define I2C_FUNC_SMBUS_EMUL \
214  (I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | I2C_FUNC_SMBUS_BYTE_DATA \
215    | I2C_FUNC_SMBUS_WORD_DATA | I2C_FUNC_SMBUS_PROC_CALL \
216    | I2C_FUNC_SMBUS_WRITE_BLOCK_DATA | I2C_FUNC_SMBUS_I2C_BLOCK \
217    | I2C_FUNC_SMBUS_PEC)
218
219/** @} */
220
221/**
222 * @brief Maximum SMBus data block count.
223 */
224#define I2C_SMBUS_BLOCK_MAX 32
225
226/**
227 * @brief SMBus data.
228 */
229union i2c_smbus_data {
230  uint8_t byte;
231  uint16_t word;
232  uint8_t block[I2C_SMBUS_BLOCK_MAX + 2];
233};
234
235/**
236 * @name SMBus Transfer Read and Write Markers
237 *
238 * @{
239 */
240
241#define I2C_SMBUS_READ 1
242
243#define I2C_SMBUS_WRITE 0
244
245/** @} */
246
247/**
248 * @name SMBus Transaction Types
249 *
250 * @{
251 */
252
253#define I2C_SMBUS_QUICK 0
254
255#define I2C_SMBUS_BYTE 1
256
257#define I2C_SMBUS_BYTE_DATA 2
258
259#define I2C_SMBUS_WORD_DATA 3
260
261#define I2C_SMBUS_PROC_CALL 4
262
263#define I2C_SMBUS_BLOCK_DATA 5
264
265#define I2C_SMBUS_I2C_BLOCK_BROKEN 6
266
267#define I2C_SMBUS_BLOCK_PROC_CALL 7
268
269#define I2C_SMBUS_I2C_BLOCK_DATA 8
270
271/** @} */
272
273/** @} */
274
275#endif /* _UAPI_LINUX_I2C_H */
Note: See TracBrowser for help on using the repository browser.