xref: /freebsd/usr.sbin/i2c/i2c.8 (revision c7c3ef8949021696029fb73a513678578a9f8a46)
1477f656bSRafal Jaworowski.\"
2477f656bSRafal Jaworowski.\" Copyright (C) 2008-2009 Semihalf, Michal Hajduk and Bartlomiej Sieka
3477f656bSRafal Jaworowski.\" All rights reserved.
4477f656bSRafal Jaworowski.\"
5477f656bSRafal Jaworowski.\" Redistribution and use in source and binary forms, with or without
6477f656bSRafal Jaworowski.\" modification, are permitted provided that the following conditions
7477f656bSRafal Jaworowski.\" are met:
8477f656bSRafal Jaworowski.\" 1. Redistributions of source code must retain the above copyright
9477f656bSRafal Jaworowski.\"    notice, this list of conditions and the following disclaimer.
10477f656bSRafal Jaworowski.\" 2. Redistributions in binary form must reproduce the above copyright
11477f656bSRafal Jaworowski.\"    notice, this list of conditions and the following disclaimer in the
12477f656bSRafal Jaworowski.\"    documentation and/or other materials provided with the distribution.
13477f656bSRafal Jaworowski.\"
14477f656bSRafal Jaworowski.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15477f656bSRafal Jaworowski.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16477f656bSRafal Jaworowski.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17477f656bSRafal Jaworowski.\" ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
18477f656bSRafal Jaworowski.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19477f656bSRafal Jaworowski.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20477f656bSRafal Jaworowski.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21477f656bSRafal Jaworowski.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22477f656bSRafal Jaworowski.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23477f656bSRafal Jaworowski.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24477f656bSRafal Jaworowski.\" SUCH DAMAGE.
25477f656bSRafal Jaworowski.\"
26a3055557SIan Lepore.Dd May 22, 2019
27477f656bSRafal Jaworowski.Dt I2C 8
28477f656bSRafal Jaworowski.Os
29477f656bSRafal Jaworowski.Sh NAME
30477f656bSRafal Jaworowski.Nm i2c
31477f656bSRafal Jaworowski.Nd test I2C bus and slave devices
32477f656bSRafal Jaworowski.Sh SYNOPSIS
33477f656bSRafal Jaworowski.Nm
34477f656bSRafal Jaworowski.Cm -a Ar address
35477f656bSRafal Jaworowski.Op Fl f Ar device
36477f656bSRafal Jaworowski.Op Fl d Ar r|w
37e06874f3SPoul-Henning Kamp.Op Fl w Ar 0|8|16|16LE|16BE
38477f656bSRafal Jaworowski.Op Fl o Ar offset
39477f656bSRafal Jaworowski.Op Fl c Ar count
40a3055557SIan Lepore.Op Fl m Ar tr|ss|rs|no
41477f656bSRafal Jaworowski.Op Fl b
42477f656bSRafal Jaworowski.Op Fl v
43477f656bSRafal Jaworowski.Nm
449c10d00bSPoul-Henning Kamp.Cm -h
459c10d00bSPoul-Henning Kamp.Nm
469c10d00bSPoul-Henning Kamp.Cm -i
47477f656bSRafal Jaworowski.Op Fl v
489c10d00bSPoul-Henning Kamp.Op Ar cmd ...
499c10d00bSPoul-Henning Kamp.Op Ar -
50477f656bSRafal Jaworowski.Nm
51477f656bSRafal Jaworowski.Cm -r
52477f656bSRafal Jaworowski.Op Fl f Ar device
53477f656bSRafal Jaworowski.Op Fl v
549c10d00bSPoul-Henning Kamp.Nm
559c10d00bSPoul-Henning Kamp.Cm -s
569c10d00bSPoul-Henning Kamp.Op Fl f Ar device
579c10d00bSPoul-Henning Kamp.Op Fl n Ar skip_addr
589c10d00bSPoul-Henning Kamp.Op Fl v
59477f656bSRafal Jaworowski.Sh DESCRIPTION
60477f656bSRafal JaworowskiThe
61477f656bSRafal Jaworowski.Nm
629c10d00bSPoul-Henning Kamputility can be used to perform raw data transfers (read or write) to devices
639c10d00bSPoul-Henning Kampon an I2C bus.
646d6d6c36SGordon BerglingIt can also scan the bus for available devices and reset the I2C controller.
65477f656bSRafal Jaworowski.Pp
66477f656bSRafal JaworowskiThe options are as follows:
67477f656bSRafal Jaworowski.Bl -tag -width ".Fl d Ar direction"
68477f656bSRafal Jaworowski.It Fl a Ar address
69477f656bSRafal Jaworowski7-bit address on the I2C device to operate on (hex).
70477f656bSRafal Jaworowski.It Fl b
71477f656bSRafal Jaworowskibinary mode - when performing a read operation, the data read from the device
725ab41ff8SPoul-Henning Kampis output in binary format on stdout.
73477f656bSRafal Jaworowski.It Fl c Ar count
745ab41ff8SPoul-Henning Kampnumber of bytes to transfer (decimal).
75477f656bSRafal Jaworowski.It Fl d Ar r|w
76477f656bSRafal Jaworowskitransfer direction: r - read, w - write.
775ab41ff8SPoul-Henning KampData to be written is read from stdin as binary bytes.
78477f656bSRafal Jaworowski.It Fl f Ar device
79477f656bSRafal JaworowskiI2C bus to use (default is /dev/iic0).
809c10d00bSPoul-Henning Kamp.It Fl i
819c10d00bSPoul-Henning KampInterpreted mode
829c10d00bSPoul-Henning Kamp.It Fl h
839c10d00bSPoul-Henning KampHelp
84a3055557SIan Lepore.It Fl m Ar tr|ss|rs|no
85477f656bSRafal Jaworowskiaddressing mode, i.e., I2C bus operations performed after the offset for the
86477f656bSRafal Jaworowskitransfer has been written to the device and before the actual read/write
87a3055557SIan Leporeoperation.
88a3055557SIan Lepore.Bl -tag -compact -offset indent
89a3055557SIan Lepore.It Va tr
90a3055557SIan Leporecomplete-transfer
91a3055557SIan Lepore.It Va ss
92a3055557SIan Leporestop then start
93a3055557SIan Lepore.It Va rs
94a3055557SIan Leporerepeated start
95a3055557SIan Lepore.It Va no
96a3055557SIan Leporenone
97a3055557SIan Lepore.El
98a3055557SIan LeporeSome I2C bus hardware does not provide control over the individual start,
99a3055557SIan Leporerepeat-start, and stop operations.
100a3055557SIan LeporeSuch hardware can only perform a complete transfer of the offset and the
101a3055557SIan Leporedata as a single operation.
102a3055557SIan LeporeThe
103a3055557SIan Lepore.Va tr
104a3055557SIan Leporemode creates control structures describing the transfer and submits them
105a3055557SIan Leporeto the driver as a single complete transaction.
106a3055557SIan LeporeThis mode works on all types of I2C hardware.
107477f656bSRafal Jaworowski.It Fl n Ar skip_addr
10863c8d31eSPoul-Henning Kampaddress(es) to be skipped during bus scan.
10963c8d31eSPoul-Henning KampOne or more addresses ([0x]xx) or ranges of addresses
11063c8d31eSPoul-Henning Kamp([0x]xx-[0x]xx or [0x]xx..[0x]xx) separated by commas or colons.
111477f656bSRafal Jaworowski.It Fl o Ar offset
112477f656bSRafal Jaworowskioffset within the device for data transfer (hex).
113668f9cbeSAndriy GaponThe default is zero.
114668f9cbeSAndriy GaponUse
115668f9cbeSAndriy Gapon.Dq -w 0
116668f9cbeSAndriy Gaponto disable writing of the offset to the slave.
117477f656bSRafal Jaworowski.It Fl r
118477f656bSRafal Jaworowskireset the controller.
119477f656bSRafal Jaworowski.It Fl s
120477f656bSRafal Jaworowskiscan the bus for devices.
121477f656bSRafal Jaworowski.It Fl v
122344c81a1SWarren Blockbe verbose.
123e06874f3SPoul-Henning Kamp.It Fl w Ar 0|8|16|16LE|16BE
1245ab41ff8SPoul-Henning Kampdevice offset width (in bits).
125668f9cbeSAndriy GaponThis is used to determine how to pass
126668f9cbeSAndriy Gapon.Ar offset
127668f9cbeSAndriy Gaponspecified with
128668f9cbeSAndriy Gapon.Fl o
129668f9cbeSAndriy Gaponto the slave.
130668f9cbeSAndriy GaponZero means that the offset is ignored and not passed to the slave at all.
13185dab3feSGordon BerglingThe endianness defaults to little-endian.
132477f656bSRafal Jaworowski.El
1339c10d00bSPoul-Henning Kamp.Sh INTERPRETED MODE
1349c10d00bSPoul-Henning KampWhen started with
1359c10d00bSPoul-Henning Kamp.Fl i
1369c10d00bSPoul-Henning Kampany remaining arguments are interpreted as commands, and
1379c10d00bSPoul-Henning Kampif the last argument is '-', or there are no arguments,
1389c10d00bSPoul-Henning Kampcommands will (also) be read from stdin.
1399c10d00bSPoul-Henning Kamp.Pp
1409c10d00bSPoul-Henning KampAvailable commands:
1419c10d00bSPoul-Henning Kamp.Bl -tag -compact
1429c10d00bSPoul-Henning Kamp.It 'r' bus address [0|8|16|16LE|16BE] offset count
1439c10d00bSPoul-Henning KampRead command, count bytes are read and hexdumped to stdout.
1449c10d00bSPoul-Henning Kamp.It 'w' bus address [0|8|16|16LE|16BE] offset hexstring
1459c10d00bSPoul-Henning KampWrite command, hexstring (white-space is allowed) is written to device.
1469c10d00bSPoul-Henning Kamp.It 'p' anything
1479c10d00bSPoul-Henning KampPrint command, the entire line is printed to stdout.  (This can be used
1489c10d00bSPoul-Henning Kampfor synchronization.)
1499c10d00bSPoul-Henning Kamp.El
1509c10d00bSPoul-Henning Kamp.Pp
1519c10d00bSPoul-Henning KampAll numeric fields accept canonical decimal/octal/hex notation.
1529c10d00bSPoul-Henning Kamp.Pp
1539c10d00bSPoul-Henning KampWithout the
1549c10d00bSPoul-Henning Kamp.Fl v
1559c10d00bSPoul-Henning Kampoption, all errors are fatal with non-zero exit status.
1569c10d00bSPoul-Henning Kamp.Pp
1579c10d00bSPoul-Henning KampWith the
1589c10d00bSPoul-Henning Kamp.Fl v
1599c10d00bSPoul-Henning Kampoption, no errors are fatal, and all commands will return
1609c10d00bSPoul-Henning Kampeither "OK\en" or "ERROR\en" on stdout.
1619c10d00bSPoul-Henning KampIn case of error, detailed diagnostics will precede that on stderr.
1629c10d00bSPoul-Henning Kamp.Pp
1639c10d00bSPoul-Henning KampBlank lines and lines starting with '#' are ignored.
164477f656bSRafal Jaworowski.Sh EXAMPLES
165477f656bSRafal Jaworowski.Bl -bullet
166477f656bSRafal Jaworowski.It
167477f656bSRafal JaworowskiScan the default bus (/dev/iic0) for devices:
168477f656bSRafal Jaworowski.Pp
169477f656bSRafal Jaworowskii2c -s
170477f656bSRafal Jaworowski.It
17163c8d31eSPoul-Henning KampScan the default bus (/dev/iic0) for devices and skip addresses
17263c8d31eSPoul-Henning Kamp0x45 to 0x47 (inclusive) and 0x56.
173477f656bSRafal Jaworowski.Pp
17463c8d31eSPoul-Henning Kampi2c -s -n 0x56,45-47
175477f656bSRafal Jaworowski.It
176477f656bSRafal JaworowskiRead 8 bytes of data from device at address 0x56 (e.g., an EEPROM):
177477f656bSRafal Jaworowski.Pp
178477f656bSRafal Jaworowskii2c -a 0x56 -d r -c 8
179477f656bSRafal Jaworowski.It
180477f656bSRafal JaworowskiWrite 16 bytes of data from file data.bin to device 0x56 at offset 0x10:
181477f656bSRafal Jaworowski.Pp
182477f656bSRafal Jaworowskii2c -a 0x56 -d w -c 16 -o 0x10 -b < data.bin
183477f656bSRafal Jaworowski.It
184477f656bSRafal JaworowskiCopy 4 bytes between two EEPROMs (0x56 on /dev/iic1 to 0x57 on /dev/iic0):
185477f656bSRafal Jaworowski.Pp
186477f656bSRafal Jaworowskii2c -a 0x56 -f /dev/iic1 -d r -c 0x4 -b | i2c -a 0x57 -f /dev/iic0 -d w -c 4 -b
187477f656bSRafal Jaworowski.It
188477f656bSRafal JaworowskiReset the controller:
189477f656bSRafal Jaworowski.Pp
190477f656bSRafal Jaworowskii2c -f /dev/iic1 -r
1919c10d00bSPoul-Henning Kamp.It
1929c10d00bSPoul-Henning KampRead 8 bytes at address 24 in an EEPROM:
1939c10d00bSPoul-Henning Kamp.Pp
1949c10d00bSPoul-Henning Kampi2c -i 'r 0 0x50 16BE 24 8'
1959c10d00bSPoul-Henning Kamp.It
1969c10d00bSPoul-Henning KampRead 2x8 bytes at address 24 and 48 in an EEPROM:
1979c10d00bSPoul-Henning Kamp.Pp
1989c10d00bSPoul-Henning Kampecho 'r 0 0x50 16BE 48 8' | i2c -i 'r 0 0x50 16BE 24 8' -
199477f656bSRafal Jaworowski.El
2005ab41ff8SPoul-Henning Kamp.Sh WARNING
2015ab41ff8SPoul-Henning KampMany systems store critical low-level information in I2C memories, and
2025ab41ff8SPoul-Henning Kampmay contain other I2C devices, such as temperature or voltage sensors.
2035ab41ff8SPoul-Henning KampReading these can disturb the firmware's operation and writing to them
2045ab41ff8SPoul-Henning Kampcan "brick" the hardware.
205477f656bSRafal Jaworowski.Sh SEE ALSO
206477f656bSRafal Jaworowski.Xr iic 4 ,
207*6e1fc011SGraham Percival.Xr iicbus 4 ,
2085ab41ff8SPoul-Henning Kamp.Xr smbus 4
209477f656bSRafal Jaworowski.Sh HISTORY
210477f656bSRafal JaworowskiThe
211477f656bSRafal Jaworowski.Nm
212477f656bSRafal Jaworowskiutility appeared in
213477f656bSRafal Jaworowski.Fx 8.0 .
214477f656bSRafal Jaworowski.Sh AUTHORS
215477f656bSRafal Jaworowski.An -nosplit
216477f656bSRafal JaworowskiThe
217477f656bSRafal Jaworowski.Nm
218477f656bSRafal Jaworowskiutility and this manual page were written by
21901c2b8acSBaptiste Daroussin.An Bartlomiej Sieka Aq Mt tur@semihalf.com
220477f656bSRafal Jaworowskiand
22101c2b8acSBaptiste Daroussin.An Michal Hajduk Aq Mt mih@semihalf.com .
2229c10d00bSPoul-Henning Kamp.Pp
2239c10d00bSPoul-Henning Kamp.An Poul-Henning Kamp Aq Mt phk@FreeBSD.org
2249c10d00bSPoul-Henning Kampadded interpreted mode.
225