1 .\" Copyright (c) 2006, M. Warner Losh
2 .\" Copyright (c) 1998, Nicolas Souchu
3 .\" All rights reserved.
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
14 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 .Nd I2C generic I/O device driver
41 device driver provides generic I/O to any
44 In order to control I2C devices, use
48 .Bl -tag -width ".Dv I2CRPTSTART"
50 .Pq Vt "struct iiccmd"
51 Sends the start condition to the slave specified by the
56 element consists of a 7-bit address and a read/write bit
57 (that is, a 7-bit address << 1 | r/w).
58 A read operation is initiated when the read/write bit is set, or a write
59 operation when it is cleared.
60 All other elements are ignored.
61 If successful, the file descriptor receives exclusive
62 ownership of the underlying iicbus instance.
64 .Pq Vt "struct iiccmd"
65 Sends the repeated start condition to the slave specified by the
68 The slave address should be specified as in
70 All other elements are ignored.
72 must have previously been issued on the same file descriptor.
74 No argument is passed.
75 Sends the stop condition to the bus.
78 was previously issued on the file descriptor, the current transaction is
79 terminated and exclusive ownership of the underlying iicbus instance is
81 Otherwise, no action is performed.
83 .Pq Vt "struct iiccmd"
85 The argument is completely ignored.
86 This command does not require
88 to have been previously issued on the file descriptor.
89 If it was previously issued, exclusive ownership of the underlying iicbus
92 .Pq Vt "struct iiccmd"
95 The bus must already be started by a previous
97 on the file descriptor.
103 element is the number of bytes to write.
106 element is a boolean flag.
107 It must be zero when additional read commands will follow, or non-zero if this
111 element is a pointer to the data to write to the bus.
113 .Pq Vt "struct iiccmd"
116 The bus must already be started by a previous
118 on the file descriptor.
124 element is the number of bytes to read.
127 element is a boolean flag.
128 It must be zero when additional read commands will follow, or non-zero if this
132 element is a pointer to where to store the data read from the bus.
133 Short reads on the bus produce undefined results.
135 .Pq Vt "struct iic_rdwr_data"
136 Generic read/write interface.
137 Allows for an arbitrary number of commands to be sent to
138 an arbitrary number of devices on the bus.
139 Any previous transaction started by
141 must be terminated by
147 can be issued on the same file descriptor.
148 A read transfer is specified if
152 Otherwise the transfer is a write transfer.
155 element specifies the 7-bit address with the read/write bit for the transfer.
156 The read/write bit will be handled by the iicbus stack based on the specified
160 element is the number of
161 .Pq Vt "struct iic_msg"
163 .Pq Vt "struct iic_rdwr_data" .
166 element is a buffer for that data.
167 This ioctl is intended to be
172 Associate the specified address with the file descriptor for use by
178 The argument is an 8-bit address (that is, a 7-bit address << 1).
179 The read/write bit in the least-significant position is ignored.
180 Any subsequent read or write operation will set or clear that bit as needed.
183 The following data structures are defined in
185 and referenced above:
186 .Bd -literal -offset indent
194 /* Designed to be compatible with linux's struct i2c_msg */
199 #define IIC_M_WR 0 /* Fake flag for write */
200 #define IIC_M_RD 0x0001 /* read vs write */
201 #define IIC_M_NOSTOP 0x0002 /* do not send a I2C stop after message */
202 #define IIC_M_NOSTART 0x0004 /* do not send a I2C start before message */
203 uint16_t len; /* msg length */
207 struct iic_rdwr_data {
208 struct iic_msg *msgs;
213 It is also possible to use
217 in which case the I2C start/stop handshake is managed by
219 The address used for the read/write operation is the one passed to the most
229 Closing the file descriptor clears any addressing state established by a
234 stops any transaction established by a not-yet-terminated
236 and releases iicbus ownership.
237 Because addressing state is stored on a per-file-descriptor basis, it is
238 permissible for multiple file descriptors to be simultaneously open on the
242 Concurrent transactions on those descriptors are synchronized by the
243 exclusive-ownership requests issued to the underlying iicbus instance.
252 manual page first appeared in
257 manual page was written by