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

4.115
Last change on this file since b6f21886 was b6f21886, checked in by Sebastian Huber <sebastian.huber@…>, on 11/05/14 at 09:21:34

Add RTEMS port of Linux I2C user-space API

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