1 .\" $NetBSD: iic.9,v 1.3 2007/02/02 07:37:06 wiz Exp $
2 .\" $OpenBSD: iic.9,v 1.3 2004/08/24 05:48:22 david Exp $
4 .\" Copyright (c) 2003 Wasabi Systems, Inc.
5 .\" All rights reserved.
7 .\" Written by Jason R. Thorpe for Wasabi Systems, Inc.
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
17 .\" 3. All advertising materials mentioning features or use of this software
18 .\" must display the following acknowledgement:
19 .\" This product includes software developed for the NetBSD Project by
20 .\" Wasabi Systems, Inc.
21 .\" 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 .\" or promote products derived from this software without specific prior
23 .\" written permission.
25 .\" THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 .\" POSSIBILITY OF SUCH DAMAGE.
44 .Nm iic_smbus_write_byte ,
45 .Nm iic_smbus_read_byte ,
46 .Nm iic_smbus_receive_byte
47 .Nd Inter IC (I2C) bus
65 .Fa "const void *cmdbuf"
72 .Fo iic_smbus_write_byte
80 .Fo iic_smbus_read_byte
88 .Fo iic_smbus_receive_byte
95 I2C is a two-wire bus developed by Philips used for connecting
97 It is commonly used for connecting devices such as EEPROMs,
98 temperature sensors, fan controllers, real-time clocks, tuners,
99 and other types of integrated circuits.
102 interface provides a means of communicating with I2C-connected devices.
103 The System Management Bus, or SMBus, is a variant of the I2C bus with
104 a simplified command protocol and some electrical differences.
106 Drivers for devices attached to the I2C bus will make use of the
107 following data types:
108 .Bl -tag -width i2c_addr_t
110 Controller tag for the I2C bus.
111 This is a pointer to a
112 .Fa struct i2c_controller ,
113 consisting of function pointers filled in by the I2C
117 The following I2C bus operations are defined:
120 Perform a read operation.
121 .It I2C_OP_READ_WITH_STOP
122 Perform a read operation and send a STOP condition on the I2C bus at
123 the conclusion of the read.
125 Perform a write operation.
126 .It I2C_OP_WRITE_WITH_STOP
127 Perform a write operation and send a STOP condition on the I2C bus at
128 the conclusion of the write.
132 .It Fa struct i2c_attach_args
133 Devices are attached to an I2C bus using this structure.
134 The structure is defined as follows:
136 struct i2c_attach_args {
137 i2c_tag_t ia_tag; /* controller */
138 i2c_addr_t ia_addr; /* address of device */
139 int ia_size; /* size (for EEPROMs) */
144 The following functions comprise the API provided to drivers of
145 I2C-connected devices:
146 .Bl -tag -width iic_exec
147 .It Fn iic_acquire_bus "ic" "flags"
148 Acquire an exclusive lock on the I2C bus.
149 This is required since only one device may communicate on the
151 Drivers should acquire the bus lock, perform the I2C bus operations
152 necessary, and then release the bus lock.
157 that sleeping is not permitted.
158 .It Fn iic_release_bus "ic" "flags"
159 Release an exclusive lock on the I2C bus.
163 .Fn iic_acquire_bus ,
164 it must also be passed to
165 .Fn iic_release_bus .
166 .It Fn iic_exec "ic" "op" "addr" "cmdbuf" "cmdlen" "buf" "buflen" "flags"
167 Perform a series of I2C transactions on the bus.
169 initiates the operation by sending a START condition on the I2C
170 bus and then transmitting the address of the target device along
171 with the transaction type.
174 is non-zero, the command pointed to by
176 is then sent to the device.
181 will then transmit or receive the data, as indicated by
185 indicates a read operation,
187 will send a REPEATED START before transferring the data.
190 so indicates, a STOP condition will be sent on the I2C
191 bus at the conclusion of the operation.
196 that sleeping is not permitted.
197 .It Fn iic_smbus_write_byte "ic" "addr" "cmd" "data" "flags"
198 Perform an SMBus WRITE BYTE operation.
199 This is equivalent to
200 I2C_OP_WRITE_WITH_STOP with
205 .It Fn iic_smbus_read_byte "ic" "addr" "cmd" "datap" "flags"
206 Perform an SMBus READ BYTE operation.
207 This is equivalent to
208 I2C_OP_READ_WITH_STOP with
213 .It Fn iic_smbus_receive_byte "ic" "addr" "datap" "flags"
214 Perform an SMBus RECEIVE BYTE operation.
215 This is equivalent to
216 I2C_OP_READ_WITH_STOP with
222 .Sh CONTROLLER INTERFACE
223 The I2C controller driver must fill in the function pointers of
226 structure, which is defined as follows:
228 struct i2c_controller {
229 void *ic_cookie; /* controller private */
231 int (*ic_acquire_bus)(void *, int);
232 void (*ic_release_bus)(void *, int);
234 int (*ic_exec)(void *, i2c_op_t, i2c_addr_t,
235 const void *, size_t, void *, size_t, int);
237 int (*ic_send_start)(void *, int);
238 int (*ic_send_stop)(void *, int);
239 int (*ic_initiate_xfer)(void *, i2c_addr_t, int);
240 int (*ic_read_byte)(void *, uint8_t *, int);
241 int (*ic_write_byte)(void *, uint8_t, int);
246 .Fn (*ic_acquire_bus)
248 .Fn (*ic_release_bus)
249 functions must always be provided.
251 The controller driver may elect to provide an
254 This function is intended for use by automated controllers
255 that do not provide manual control over I2C bus conditions
256 such as START and STOP.
260 function is not provided, the following 5 functions will be
263 in order to execute the I2C bus operation:
265 .It Fn (*ic_send_start) "cookie" "flags"
266 Send a START condition on the I2C bus.
269 flag indicates that sleeping is not permitted.
270 .It Fn (*ic_send_stop) "cookie" "flags"
271 Send a STOP condition on the I2C bus.
274 flag indicates that sleeping is not permitted.
275 .It Fn (*ic_initiate_xfer) "cookie" "addr" "flags"
276 Initiate a transfer on the I2C bus by sending a START condition and
277 then transmitting the I2C device address and transfer type.
280 flag indicates a read transfer; the lack of this flag indicates a
284 flag indicates that sleeping is not permitted.
287 should be returned if a timeout that would indicate that the
288 device is not present occurs.
289 .It Fn (*ic_read_byte) "cookie" "datap" "flags"
290 Read a byte from the I2C bus into the memory location referenced by
294 flag indicates that this is the final byte of the transfer, and that
295 a NACK condition should be sent on the I2C bus following the transfer
299 flag indicates that a STOP condition should be sent on the I2C bus following
300 the transfer of the byte.
303 flag indicates that sleeping is not permitted.
304 .It Fn (*ic_write_byte) "cookie" "data" "flags"
305 Write the byte contained in
310 flag indicates that a STOP condition should be sent on the I2C bus following
311 the transfer of the byte.
314 flag indicates that sleeping is not permitted.
321 API first appeared in
330 Steve C. Woodford and Jason R. Thorpe for
335 .An Alexander Yurchenko Aq grange@openbsd.org .