xref: /freebsd/usr.sbin/i2c/i2c.8 (revision e67e85659c0de33e617e5fbf1028c6e8b49eee53)
1.\"
2.\" Copyright (C) 2008-2009 Semihalf, Michal Hajduk and Bartlomiej Sieka
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 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 22, 2019
29.Dt I2C 8
30.Os
31.Sh NAME
32.Nm i2c
33.Nd test I2C bus and slave devices
34.Sh SYNOPSIS
35.Nm
36.Cm -a Ar address
37.Op Fl f Ar device
38.Op Fl d Ar r|w
39.Op Fl w Ar 0|8|16|16LE|16BE
40.Op Fl o Ar offset
41.Op Fl c Ar count
42.Op Fl m Ar tr|ss|rs|no
43.Op Fl b
44.Op Fl v
45.Nm
46.Cm -h
47.Nm
48.Cm -i
49.Op Fl v
50.Op Ar cmd ...
51.Op Ar -
52.Nm
53.Cm -r
54.Op Fl f Ar device
55.Op Fl v
56.Nm
57.Cm -s
58.Op Fl f Ar device
59.Op Fl n Ar skip_addr
60.Op Fl v
61.Sh DESCRIPTION
62The
63.Nm
64utility can be used to perform raw data transfers (read or write) to devices
65on an I2C bus.
66It can also scan the bus for available devices and reset the I2C controller.
67.Pp
68The options are as follows:
69.Bl -tag -width ".Fl d Ar direction"
70.It Fl a Ar address
717-bit address on the I2C device to operate on (hex).
72.It Fl b
73binary mode - when performing a read operation, the data read from the device
74is output in binary format on stdout.
75.It Fl c Ar count
76number of bytes to transfer (decimal).
77.It Fl d Ar r|w
78transfer direction: r - read, w - write.
79Data to be written is read from stdin as binary bytes.
80.It Fl f Ar device
81I2C bus to use (default is /dev/iic0).
82.It Fl i
83Interpreted mode
84.It Fl h
85Help
86.It Fl m Ar tr|ss|rs|no
87addressing mode, i.e., I2C bus operations performed after the offset for the
88transfer has been written to the device and before the actual read/write
89operation.
90.Bl -tag -compact -offset indent
91.It Va tr
92complete-transfer
93.It Va ss
94stop then start
95.It Va rs
96repeated start
97.It Va no
98none
99.El
100Some I2C bus hardware does not provide control over the individual start,
101repeat-start, and stop operations.
102Such hardware can only perform a complete transfer of the offset and the
103data as a single operation.
104The
105.Va tr
106mode creates control structures describing the transfer and submits them
107to the driver as a single complete transaction.
108This mode works on all types of I2C hardware.
109.It Fl n Ar skip_addr
110address(es) to be skipped during bus scan.
111One or more addresses ([0x]xx) or ranges of addresses
112([0x]xx-[0x]xx or [0x]xx..[0x]xx) separated by commas or colons.
113.It Fl o Ar offset
114offset within the device for data transfer (hex).
115The default is zero.
116Use
117.Dq -w 0
118to disable writing of the offset to the slave.
119.It Fl r
120reset the controller.
121.It Fl s
122scan the bus for devices.
123.It Fl v
124be verbose.
125.It Fl w Ar 0|8|16|16LE|16BE
126device offset width (in bits).
127This is used to determine how to pass
128.Ar offset
129specified with
130.Fl o
131to the slave.
132Zero means that the offset is ignored and not passed to the slave at all.
133The endianess defaults to little-endian.
134.El
135.Sh INTERPRETED MODE
136When started with
137.Fl i
138any remaining arguments are interpreted as commands, and
139if the last argument is '-', or there are no arguments,
140commands will (also) be read from stdin.
141.Pp
142Available commands:
143.Bl -tag -compact
144.It 'r' bus address [0|8|16|16LE|16BE] offset count
145Read command, count bytes are read and hexdumped to stdout.
146.It 'w' bus address [0|8|16|16LE|16BE] offset hexstring
147Write command, hexstring (white-space is allowed) is written to device.
148.It 'p' anything
149Print command, the entire line is printed to stdout.  (This can be used
150for synchronization.)
151.El
152.Pp
153All numeric fields accept canonical decimal/octal/hex notation.
154.Pp
155Without the
156.Fl v
157option, all errors are fatal with non-zero exit status.
158.Pp
159With the
160.Fl v
161option, no errors are fatal, and all commands will return
162either "OK\en" or "ERROR\en" on stdout.
163In case of error, detailed diagnostics will precede that on stderr.
164.Pp
165Blank lines and lines starting with '#' are ignored.
166.Sh EXAMPLES
167.Bl -bullet
168.It
169Scan the default bus (/dev/iic0) for devices:
170.Pp
171i2c -s
172.It
173Scan the default bus (/dev/iic0) for devices and skip addresses
1740x45 to 0x47 (inclusive) and 0x56.
175.Pp
176i2c -s -n 0x56,45-47
177.It
178Read 8 bytes of data from device at address 0x56 (e.g., an EEPROM):
179.Pp
180i2c -a 0x56 -d r -c 8
181.It
182Write 16 bytes of data from file data.bin to device 0x56 at offset 0x10:
183.Pp
184i2c -a 0x56 -d w -c 16 -o 0x10 -b < data.bin
185.It
186Copy 4 bytes between two EEPROMs (0x56 on /dev/iic1 to 0x57 on /dev/iic0):
187.Pp
188i2c -a 0x56 -f /dev/iic1 -d r -c 0x4 -b | i2c -a 0x57 -f /dev/iic0 -d w -c 4 -b
189.It
190Reset the controller:
191.Pp
192i2c -f /dev/iic1 -r
193.It
194Read 8 bytes at address 24 in an EEPROM:
195.Pp
196i2c -i 'r 0 0x50 16BE 24 8'
197.It
198Read 2x8 bytes at address 24 and 48 in an EEPROM:
199.Pp
200echo 'r 0 0x50 16BE 48 8' | i2c -i 'r 0 0x50 16BE 24 8' -
201.El
202.Sh WARNING
203Many systems store critical low-level information in I2C memories, and
204may contain other I2C devices, such as temperature or voltage sensors.
205Reading these can disturb the firmware's operation and writing to them
206can "brick" the hardware.
207.Sh SEE ALSO
208.Xr iic 4 ,
209.Xr iicbus 4
210.Xr smbus 4
211.Sh HISTORY
212The
213.Nm
214utility appeared in
215.Fx 8.0 .
216.Sh AUTHORS
217.An -nosplit
218The
219.Nm
220utility and this manual page were written by
221.An Bartlomiej Sieka Aq Mt tur@semihalf.com
222and
223.An Michal Hajduk Aq Mt mih@semihalf.com .
224.Pp
225.An Poul-Henning Kamp Aq Mt phk@FreeBSD.org
226added interpreted mode.
227