2 .\" Copyright (C) 2008-2009 Semihalf, Michal Hajduk and Bartlomiej Sieka
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 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 test I2C bus and slave devices
39 .Op Fl w Ar 0|8|16|16LE|16BE
42 .Op Fl m Ar tr|ss|rs|no
64 utility can be used to perform raw data transfers (read or write) to devices
66 It can also scan the bus for available devices and reset the I2C controller.
68 The options are as follows:
69 .Bl -tag -width ".Fl d Ar direction"
71 7-bit address on the I2C device to operate on (hex).
73 binary mode - when performing a read operation, the data read from the device
74 is output in binary format on stdout.
76 number of bytes to transfer (decimal).
78 transfer direction: r - read, w - write.
79 Data to be written is read from stdin as binary bytes.
81 I2C bus to use (default is /dev/iic0).
86 .It Fl m Ar tr|ss|rs|no
87 addressing mode, i.e., I2C bus operations performed after the offset for the
88 transfer has been written to the device and before the actual read/write
90 .Bl -tag -compact -offset indent
100 Some I2C bus hardware does not provide control over the individual start,
101 repeat-start, and stop operations.
102 Such hardware can only perform a complete transfer of the offset and the
103 data as a single operation.
106 mode creates control structures describing the transfer and submits them
107 to the driver as a single complete transaction.
108 This mode works on all types of I2C hardware.
109 .It Fl n Ar skip_addr
110 address(es) to be skipped during bus scan.
111 One or more addresses ([0x]xx) or ranges of addresses
112 ([0x]xx-[0x]xx or [0x]xx..[0x]xx) separated by commas or colons.
114 offset within the device for data transfer (hex).
118 to disable writing of the offset to the slave.
120 reset the controller.
122 scan the bus for devices.
125 .It Fl w Ar 0|8|16|16LE|16BE
126 device offset width (in bits).
127 This is used to determine how to pass
132 Zero means that the offset is ignored and not passed to the slave at all.
133 The endianess defaults to little-endian.
138 any remaining arguments are interpreted as commands, and
139 if the last argument is '-', or there are no arguments,
140 commands will (also) be read from stdin.
144 .It 'r' bus address [0|8|16|16LE|16BE] offset count
145 Read command, count bytes are read and hexdumped to stdout.
146 .It 'w' bus address [0|8|16|16LE|16BE] offset hexstring
147 Write command, hexstring (white-space is allowed) is written to device.
149 Print command, the entire line is printed to stdout. (This can be used
150 for synchronization.)
153 All numeric fields accept canonical decimal/octal/hex notation.
157 option, all errors are fatal with non-zero exit status.
161 option, no errors are fatal, and all commands will return
162 either "OK\en" or "ERROR\en" on stdout.
163 In case of error, detailed diagnostics will precede that on stderr.
165 Blank lines and lines starting with '#' are ignored.
169 Scan the default bus (/dev/iic0) for devices:
173 Scan the default bus (/dev/iic0) for devices and skip addresses
174 0x45 to 0x47 (inclusive) and 0x56.
178 Read 8 bytes of data from device at address 0x56 (e.g., an EEPROM):
180 i2c -a 0x56 -d r -c 8
182 Write 16 bytes of data from file data.bin to device 0x56 at offset 0x10:
184 i2c -a 0x56 -d w -c 16 -o 0x10 -b < data.bin
186 Copy 4 bytes between two EEPROMs (0x56 on /dev/iic1 to 0x57 on /dev/iic0):
188 i2c -a 0x56 -f /dev/iic1 -d r -c 0x4 -b | i2c -a 0x57 -f /dev/iic0 -d w -c 4 -b
190 Reset the controller:
194 Read 8 bytes at address 24 in an EEPROM:
196 i2c -i 'r 0 0x50 16BE 24 8'
198 Read 2x8 bytes at address 24 and 48 in an EEPROM:
200 echo 'r 0 0x50 16BE 48 8' | i2c -i 'r 0 0x50 16BE 24 8' -
203 Many systems store critical low-level information in I2C memories, and
204 may contain other I2C devices, such as temperature or voltage sensors.
205 Reading these can disturb the firmware's operation and writing to them
206 can "brick" the hardware.
220 utility and this manual page were written by
221 .An Bartlomiej Sieka Aq Mt tur@semihalf.com
223 .An Michal Hajduk Aq Mt mih@semihalf.com .
225 .An Poul-Henning Kamp Aq Mt phk@FreeBSD.org
226 added interpreted mode.