]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/man/man4/iic.4
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / share / man / man4 / iic.4
1 .\" Copyright (c) 1998, Nicolas Souchu All rights reserved.
2 .\" Copyright (c) 2006 M. Warner Losh <imp@FreeBSD.org>
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
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.
12 .\"
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
23 .\" SUCH DAMAGE.
24 .\"
25 .\" $FreeBSD$
26 .\"
27 .Dd May 15, 2015
28 .Dt IIC 4
29 .Os
30 .Sh NAME
31 .Nm iic
32 .Nd I2C generic I/O device driver
33 .Sh SYNOPSIS
34 .Cd "device iic"
35 .Pp
36 .In dev/iicbus/iic.h
37 .Sh DESCRIPTION
38 The
39 .Nm
40 device driver provides generic I/O to any
41 .Xr iicbus 4
42 instance.
43 In order to control I2C devices, use
44 .Pa /dev/iic?
45 with the
46 following ioctls:
47 .Bl -tag -width ".Dv I2CRPTSTART"
48 .It Dv I2CSTART
49 .Pq Vt "struct iiccmd"
50 Sends the start condition to the slave specified by the
51 .Va slave
52 element to the bus.
53 The
54 .Va slave
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.
62 .It Dv I2CRPTSTART
63 .Pq Vt "struct iiccmd"
64 Sends the repeated start condition to the slave specified by the
65 .Va slave
66 element to the bus.
67 The slave address should be specified as in
68 .Dv I2CSTART .
69 All other elements are ignored.
70 .Dv I2CSTART
71 must have previously been issued on the same file descriptor.
72 .It Dv I2CSTOP
73 No argument is passed.
74 Sends the stop condition to the bus.
75 If
76 .Dv I2CSTART
77 was previously issued on the file descriptor, the current transaction is
78 terminated and exclusive ownership of the underlying iicbus instance is
79 released.
80 Otherwise, no action is performed.
81 .It Dv I2CRSTCARD
82 .Pq Vt "struct iiccmd"
83 Resets the bus.
84 The argument is completely ignored.
85 This command does not require
86 .Dv I2CSTART
87 to have been previously issued on the file descriptor.
88 If it was previously issued, exclusive ownership of the underlying iicbus
89 instance is released.
90 .It Dv I2CWRITE
91 .Pq Vt "struct iiccmd"
92 Writes data to the
93 .Xr iicbus 4 .
94 The bus must already be started by a previous
95 .Dv I2CSTART
96 on the file descriptor.
97 The
98 .Va slave
99 element is ignored.
100 The
101 .Va count
102 element is the number of bytes to write.
103 The
104 .Va last
105 element is a boolean flag.
106 It must be zero when additional read commands will follow, or non-zero if this
107 is the last command.
108 The
109 .Va buf
110 element is a pointer to the data to write to the bus.
111 .It Dv I2CREAD
112 .Pq Vt "struct iiccmd"
113 Reads data from the
114 .Xr iicbus 4 .
115 The bus must already be started by a previous
116 .Dv I2CSTART
117 on the file descriptor.
118 The
119 .Va slave
120 element is ignored.
121 The
122 .Va count
123 element is the number of bytes to read.
124 The
125 .Va last
126 element is a boolean flag.
127 It must be zero when additional read commands will follow, or non-zero if this
128 is the last command.
129 The
130 .Va buf
131 element is a pointer to where to store the data read from the bus.
132 Short reads on the bus produce undefined results.
133 .It Dv I2CRDWR
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
139 .Dv I2CSTART
140 must be terminated by
141 .Dv I2CSTOP
142 or
143 .Dv I2CRSTCARD
144 before
145 .Dv I2CRDWR
146 can be issued on the same file descriptor.
147 A read transfer is specified if
148 .Dv IIC_M_RD
149 is set in
150 .Va flags .
151 Otherwise the transfer is a write transfer.
152 The
153 .Va slave
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
156 transfer operation.
157 The
158 .Va len
159 element is the number of
160 .Pq Vt "struct iic_msg"
161 messages encoded on
162 .Pq Vt "struct iic_rdwr_data" .
163 The
164 .Va buf
165 element is a buffer for that data.
166 This ioctl is intended to be
167 .Tn Linux
168 compatible.
169 .It Dv I2CSADDR
170 .Pq Vt "uint8_t"
171 Associate the specified address with the file descriptor for use by
172 subsequent
173 .Xr read 2
174 or
175 .Xr write 2
176 calls.
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.
180 .El
181 .Pp
182 The following data structures are defined in
183 .In dev/iicbus/iic.h
184 and referenced above:
185 .Bd -literal -offset indent
186 struct iiccmd {
187         u_char slave;
188         int count;
189         int last;
190         char *buf;
191 };
192
193 /* Designed to be compatible with linux's struct i2c_msg */
194 struct iic_msg
195 {
196         uint16_t        slave;
197         uint16_t        flags;
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 */
203         uint8_t *       buf;
204 };
205
206 struct iic_rdwr_data {
207         struct iic_msg *msgs;
208         uint32_t nmsgs;
209 };
210 .Ed
211 .Pp
212 It is also possible to use
213 .Xr read 2
214 or
215 .Xr write 2 ,
216 in which case the I2C start/stop handshake is managed by
217 .Xr iicbus 4 .
218 The address used for the read/write operation is the one passed to the most
219 recent
220 .Dv I2CSTART
221 .Xr ioctl 2
222 or
223 .Dv I2CSADDR
224 .Xr ioctl 2
225 on the open
226 .Pa /dev/iic?
227 file descriptor.
228 Closing the file descriptor clears any addressing state established by a
229 previous
230 .Dv I2CSTART
231 or
232 .Dv I2CSADDR ,
233 stops any transaction established by a not-yet-terminated
234 .Dv I2CSTART ,
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
238 same
239 .Pa /dev/iic?
240 device.
241 Concurrent transactions on those descriptors are synchronized by the
242 exclusive-ownership requests issued to the underlying iicbus instance.
243 .Sh SEE ALSO
244 .Xr ioctl 2 ,
245 .Xr read 2 ,
246 .Xr write 2 ,
247 .Xr iicbus 4
248 .Sh HISTORY
249 The
250 .Nm
251 manual page first appeared in
252 .Fx 3.0 .
253 .Sh AUTHORS
254 .An -nosplit
255 This
256 manual page was written by
257 .An Nicolas Souchu
258 and
259 .An M. Warner Losh .