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