2009-01-26 14:00:50 +00:00
|
|
|
.\"
|
|
|
|
.\" Copyright (C) 2008-2009 Semihalf, Michal Hajduk and Bartlomiej Sieka
|
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
.\" SUCH DAMAGE.
|
|
|
|
.\"
|
2012-03-29 05:02:12 +00:00
|
|
|
.\" $FreeBSD$
|
2009-01-26 14:00:50 +00:00
|
|
|
.\"
|
2019-05-22 21:06:10 +00:00
|
|
|
.Dd May 22, 2019
|
2009-01-26 14:00:50 +00:00
|
|
|
.Dt I2C 8
|
|
|
|
.Os
|
|
|
|
.Sh NAME
|
|
|
|
.Nm i2c
|
2012-03-29 05:02:12 +00:00
|
|
|
.Nd test I2C bus and slave devices
|
2009-01-26 14:00:50 +00:00
|
|
|
.Sh SYNOPSIS
|
|
|
|
.Nm
|
|
|
|
.Cm -a Ar address
|
|
|
|
.Op Fl f Ar device
|
|
|
|
.Op Fl d Ar r|w
|
2021-05-12 20:01:14 +00:00
|
|
|
.Op Fl w Ar 0|8|16|16LE|16BE
|
2009-01-26 14:00:50 +00:00
|
|
|
.Op Fl o Ar offset
|
|
|
|
.Op Fl c Ar count
|
2019-05-22 21:06:10 +00:00
|
|
|
.Op Fl m Ar tr|ss|rs|no
|
2009-01-26 14:00:50 +00:00
|
|
|
.Op Fl b
|
|
|
|
.Op Fl v
|
|
|
|
.Nm
|
2021-05-19 18:56:59 +00:00
|
|
|
.Cm -h
|
|
|
|
.Nm
|
|
|
|
.Cm -i
|
2009-01-26 14:00:50 +00:00
|
|
|
.Op Fl v
|
2021-05-19 18:56:59 +00:00
|
|
|
.Op Ar cmd ...
|
|
|
|
.Op Ar -
|
2009-01-26 14:00:50 +00:00
|
|
|
.Nm
|
|
|
|
.Cm -r
|
|
|
|
.Op Fl f Ar device
|
|
|
|
.Op Fl v
|
2021-05-19 18:56:59 +00:00
|
|
|
.Nm
|
|
|
|
.Cm -s
|
|
|
|
.Op Fl f Ar device
|
|
|
|
.Op Fl n Ar skip_addr
|
|
|
|
.Op Fl v
|
2009-01-26 14:00:50 +00:00
|
|
|
.Sh DESCRIPTION
|
|
|
|
The
|
|
|
|
.Nm
|
2021-05-19 18:56:59 +00:00
|
|
|
utility can be used to perform raw data transfers (read or write) to devices
|
|
|
|
on an I2C bus.
|
2020-10-09 14:03:45 +00:00
|
|
|
It can also scan the bus for available devices and reset the I2C controller.
|
2009-01-26 14:00:50 +00:00
|
|
|
.Pp
|
|
|
|
The options are as follows:
|
|
|
|
.Bl -tag -width ".Fl d Ar direction"
|
|
|
|
.It Fl a Ar address
|
|
|
|
7-bit address on the I2C device to operate on (hex).
|
|
|
|
.It Fl b
|
|
|
|
binary mode - when performing a read operation, the data read from the device
|
2021-05-12 21:34:58 +00:00
|
|
|
is output in binary format on stdout.
|
2009-01-26 14:00:50 +00:00
|
|
|
.It Fl c Ar count
|
2021-05-12 21:34:58 +00:00
|
|
|
number of bytes to transfer (decimal).
|
2009-01-26 14:00:50 +00:00
|
|
|
.It Fl d Ar r|w
|
|
|
|
transfer direction: r - read, w - write.
|
2021-05-12 21:34:58 +00:00
|
|
|
Data to be written is read from stdin as binary bytes.
|
2009-01-26 14:00:50 +00:00
|
|
|
.It Fl f Ar device
|
|
|
|
I2C bus to use (default is /dev/iic0).
|
2021-05-19 18:56:59 +00:00
|
|
|
.It Fl i
|
|
|
|
Interpreted mode
|
|
|
|
.It Fl h
|
|
|
|
Help
|
2019-05-22 21:06:10 +00:00
|
|
|
.It Fl m Ar tr|ss|rs|no
|
2009-01-26 14:00:50 +00:00
|
|
|
addressing mode, i.e., I2C bus operations performed after the offset for the
|
|
|
|
transfer has been written to the device and before the actual read/write
|
2019-05-22 21:06:10 +00:00
|
|
|
operation.
|
|
|
|
.Bl -tag -compact -offset indent
|
|
|
|
.It Va tr
|
|
|
|
complete-transfer
|
|
|
|
.It Va ss
|
|
|
|
stop then start
|
|
|
|
.It Va rs
|
|
|
|
repeated start
|
|
|
|
.It Va no
|
|
|
|
none
|
|
|
|
.El
|
|
|
|
Some I2C bus hardware does not provide control over the individual start,
|
|
|
|
repeat-start, and stop operations.
|
|
|
|
Such hardware can only perform a complete transfer of the offset and the
|
|
|
|
data as a single operation.
|
|
|
|
The
|
|
|
|
.Va tr
|
|
|
|
mode creates control structures describing the transfer and submits them
|
|
|
|
to the driver as a single complete transaction.
|
|
|
|
This mode works on all types of I2C hardware.
|
2009-01-26 14:00:50 +00:00
|
|
|
.It Fl n Ar skip_addr
|
2021-05-13 10:55:37 +00:00
|
|
|
address(es) to be skipped during bus scan.
|
|
|
|
One or more addresses ([0x]xx) or ranges of addresses
|
|
|
|
([0x]xx-[0x]xx or [0x]xx..[0x]xx) separated by commas or colons.
|
2009-01-26 14:00:50 +00:00
|
|
|
.It Fl o Ar offset
|
|
|
|
offset within the device for data transfer (hex).
|
2017-10-13 09:21:41 +00:00
|
|
|
The default is zero.
|
|
|
|
Use
|
|
|
|
.Dq -w 0
|
|
|
|
to disable writing of the offset to the slave.
|
2009-01-26 14:00:50 +00:00
|
|
|
.It Fl r
|
|
|
|
reset the controller.
|
|
|
|
.It Fl s
|
|
|
|
scan the bus for devices.
|
|
|
|
.It Fl v
|
2012-05-24 02:24:03 +00:00
|
|
|
be verbose.
|
2021-05-12 20:01:14 +00:00
|
|
|
.It Fl w Ar 0|8|16|16LE|16BE
|
2021-05-12 21:34:58 +00:00
|
|
|
device offset width (in bits).
|
2017-10-13 09:21:41 +00:00
|
|
|
This is used to determine how to pass
|
|
|
|
.Ar offset
|
|
|
|
specified with
|
|
|
|
.Fl o
|
|
|
|
to the slave.
|
|
|
|
Zero means that the offset is ignored and not passed to the slave at all.
|
2021-05-12 20:01:14 +00:00
|
|
|
The endianess defaults to little-endian.
|
2009-01-26 14:00:50 +00:00
|
|
|
.El
|
2021-05-19 18:56:59 +00:00
|
|
|
.Sh INTERPRETED MODE
|
|
|
|
When started with
|
|
|
|
.Fl i
|
|
|
|
any remaining arguments are interpreted as commands, and
|
|
|
|
if the last argument is '-', or there are no arguments,
|
|
|
|
commands will (also) be read from stdin.
|
|
|
|
.Pp
|
|
|
|
Available commands:
|
|
|
|
.Bl -tag -compact
|
|
|
|
.It 'r' bus address [0|8|16|16LE|16BE] offset count
|
|
|
|
Read command, count bytes are read and hexdumped to stdout.
|
|
|
|
.It 'w' bus address [0|8|16|16LE|16BE] offset hexstring
|
|
|
|
Write command, hexstring (white-space is allowed) is written to device.
|
|
|
|
.It 'p' anything
|
|
|
|
Print command, the entire line is printed to stdout. (This can be used
|
|
|
|
for synchronization.)
|
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
All numeric fields accept canonical decimal/octal/hex notation.
|
|
|
|
.Pp
|
|
|
|
Without the
|
|
|
|
.Fl v
|
|
|
|
option, all errors are fatal with non-zero exit status.
|
|
|
|
.Pp
|
|
|
|
With the
|
|
|
|
.Fl v
|
|
|
|
option, no errors are fatal, and all commands will return
|
|
|
|
either "OK\en" or "ERROR\en" on stdout.
|
|
|
|
In case of error, detailed diagnostics will precede that on stderr.
|
|
|
|
.Pp
|
|
|
|
Blank lines and lines starting with '#' are ignored.
|
2009-01-26 14:00:50 +00:00
|
|
|
.Sh EXAMPLES
|
|
|
|
.Bl -bullet
|
|
|
|
.It
|
|
|
|
Scan the default bus (/dev/iic0) for devices:
|
|
|
|
.Pp
|
|
|
|
i2c -s
|
|
|
|
.It
|
2021-05-13 10:55:37 +00:00
|
|
|
Scan the default bus (/dev/iic0) for devices and skip addresses
|
|
|
|
0x45 to 0x47 (inclusive) and 0x56.
|
2009-01-26 14:00:50 +00:00
|
|
|
.Pp
|
2021-05-13 10:55:37 +00:00
|
|
|
i2c -s -n 0x56,45-47
|
2009-01-26 14:00:50 +00:00
|
|
|
.It
|
|
|
|
Read 8 bytes of data from device at address 0x56 (e.g., an EEPROM):
|
|
|
|
.Pp
|
|
|
|
i2c -a 0x56 -d r -c 8
|
|
|
|
.It
|
|
|
|
Write 16 bytes of data from file data.bin to device 0x56 at offset 0x10:
|
|
|
|
.Pp
|
|
|
|
i2c -a 0x56 -d w -c 16 -o 0x10 -b < data.bin
|
|
|
|
.It
|
|
|
|
Copy 4 bytes between two EEPROMs (0x56 on /dev/iic1 to 0x57 on /dev/iic0):
|
|
|
|
.Pp
|
|
|
|
i2c -a 0x56 -f /dev/iic1 -d r -c 0x4 -b | i2c -a 0x57 -f /dev/iic0 -d w -c 4 -b
|
|
|
|
.It
|
|
|
|
Reset the controller:
|
|
|
|
.Pp
|
|
|
|
i2c -f /dev/iic1 -r
|
2021-05-19 18:56:59 +00:00
|
|
|
.It
|
|
|
|
Read 8 bytes at address 24 in an EEPROM:
|
|
|
|
.Pp
|
|
|
|
i2c -i 'r 0 0x50 16BE 24 8'
|
|
|
|
.It
|
|
|
|
Read 2x8 bytes at address 24 and 48 in an EEPROM:
|
|
|
|
.Pp
|
|
|
|
echo 'r 0 0x50 16BE 48 8' | i2c -i 'r 0 0x50 16BE 24 8' -
|
2009-01-26 14:00:50 +00:00
|
|
|
.El
|
2021-05-12 21:34:58 +00:00
|
|
|
.Sh WARNING
|
|
|
|
Many systems store critical low-level information in I2C memories, and
|
|
|
|
may contain other I2C devices, such as temperature or voltage sensors.
|
|
|
|
Reading these can disturb the firmware's operation and writing to them
|
|
|
|
can "brick" the hardware.
|
2009-01-26 14:00:50 +00:00
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr iic 4 ,
|
|
|
|
.Xr iicbus 4
|
2021-05-12 21:34:58 +00:00
|
|
|
.Xr smbus 4
|
2009-01-26 14:00:50 +00:00
|
|
|
.Sh HISTORY
|
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
utility appeared in
|
|
|
|
.Fx 8.0 .
|
|
|
|
.Sh AUTHORS
|
|
|
|
.An -nosplit
|
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
utility and this manual page were written by
|
2014-06-20 09:57:27 +00:00
|
|
|
.An Bartlomiej Sieka Aq Mt tur@semihalf.com
|
2012-03-29 05:02:12 +00:00
|
|
|
and
|
2014-06-20 09:57:27 +00:00
|
|
|
.An Michal Hajduk Aq Mt mih@semihalf.com .
|
2021-05-19 18:56:59 +00:00
|
|
|
.Pp
|
|
|
|
.An Poul-Henning Kamp Aq Mt phk@FreeBSD.org
|
|
|
|
added interpreted mode.
|