1 .\" Copyright (c) 1998, Nicolas Souchu All rights reserved.
2 .\" Copyright (c) 2006 M. Warner Losh <imp@FreeBSD.org>
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .Nd I2C generic I/O device driver
40 device driver provides generic I/O to any
43 In order to control I2C devices, use
47 .Bl -tag -width ".Dv I2CRPTSTART"
49 .Pq Vt "struct iiccmd"
50 Sends the start condition to the slave specified by the
55 element consists of a 7-bit address and a read/write bit
56 (that is, a 7-bit address << 1 | r/w).
57 A read operation is initiated when the read/write bit is set, or a write
58 operation when it is cleared.
59 All other elements are ignored.
60 If successful, the file descriptor receives exclusive
61 ownership of the underlying iicbus instance.
63 .Pq Vt "struct iiccmd"
64 Sends the repeated start condition to the slave specified by the
67 The slave address should be specified as in
69 All other elements are ignored.
71 must have previously been issued on the same file descriptor.
73 No argument is passed.
74 Sends the stop condition to the bus.
77 was previously issued on the file descriptor, the current transaction is
78 terminated and exclusive ownership of the underlying iicbus instance is
80 Otherwise, no action is performed.
82 .Pq Vt "struct iiccmd"
84 The argument is completely ignored.
85 This command does not require
87 to have been previously issued on the file descriptor.
88 If it was previously issued, exclusive ownership of the underlying iicbus
91 .Pq Vt "struct iiccmd"
94 The bus must already be started by a previous
96 on the file descriptor.
102 element is the number of bytes to write.
105 element is a boolean flag.
106 It must be zero when additional read commands will follow, or non-zero if this
110 element is a pointer to the data to write to the bus.
112 .Pq Vt "struct iiccmd"
115 The bus must already be started by a previous
117 on the file descriptor.
123 element is the number of bytes to read.
126 element is a boolean flag.
127 It must be zero when additional read commands will follow, or non-zero if this
131 element is a pointer to where to store the data read from the bus.
132 Short reads on the bus produce undefined results.
134 .Pq Vt "struct iic_rdwr_data"
135 Generic read/write interface.
136 Allows for an arbitrary number of commands to be sent to
137 an arbitrary number of devices on the bus.
138 Any previous transaction started by
140 must be terminated by
146 can be issued on the same file descriptor.
147 A read transfer is specified if
151 Otherwise the transfer is a write transfer.
154 element specifies the 7-bit address with the read/write bit for the transfer.
155 The read/write bit will be handled by the iicbus stack based on the specified
159 element is the number of
160 .Pq Vt "struct iic_msg"
162 .Pq Vt "struct iic_rdwr_data" .
165 element is a buffer for that data.
166 This ioctl is intended to be
171 Associate the specified address with the file descriptor for use by
177 The argument is an 8-bit address (that is, a 7-bit address << 1).
178 The read/write bit in the least-significant position is ignored.
179 Any subsequent read or write operation will set or clear that bit as needed.
182 The following data structures are defined in
184 and referenced above:
185 .Bd -literal -offset indent
193 /* Designed to be compatible with linux's struct i2c_msg */
198 #define IIC_M_WR 0 /* Fake flag for write */
199 #define IIC_M_RD 0x0001 /* read vs write */
200 #define IIC_M_NOSTOP 0x0002 /* do not send a I2C stop after message */
201 #define IIC_M_NOSTART 0x0004 /* do not send a I2C start before message */
202 uint16_t len; /* msg length */
206 struct iic_rdwr_data {
207 struct iic_msg *msgs;
212 It is also possible to use
216 in which case the I2C start/stop handshake is managed by
218 The address used for the read/write operation is the one passed to the most
228 Closing the file descriptor clears any addressing state established by a
233 stops any transaction established by a not-yet-terminated
235 and releases iicbus ownership.
236 Because addressing state is stored on a per-file-descriptor basis, it is
237 permissible for multiple file descriptors to be simultaneously open on the
241 Concurrent transactions on those descriptors are synchronized by the
242 exclusive-ownership requests issued to the underlying iicbus instance.
251 manual page first appeared in
256 manual page was written by