]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.sbin/i2c/i2c.8
bsddialog: import version 0.1
[FreeBSD/FreeBSD.git] / usr.sbin / i2c / i2c.8
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
62 The
63 .Nm
64 utility can be used to perform raw data transfers (read or write) to devices
65 on an I2C bus.
66 It can also scan the bus for available devices and reset the I2C controller.
67 .Pp
68 The options are as follows:
69 .Bl -tag -width ".Fl d Ar direction"
70 .It Fl a Ar address
71 7-bit address on the I2C device to operate on (hex).
72 .It Fl b
73 binary mode - when performing a read operation, the data read from the device
74 is output in binary format on stdout.
75 .It Fl c Ar count
76 number of bytes to transfer (decimal).
77 .It Fl d Ar r|w
78 transfer direction: r - read, w - write.
79 Data to be written is read from stdin as binary bytes.
80 .It Fl f Ar device
81 I2C bus to use (default is /dev/iic0).
82 .It Fl i
83 Interpreted mode
84 .It Fl h
85 Help
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
89 operation.
90 .Bl -tag -compact -offset indent
91 .It Va tr
92 complete-transfer
93 .It Va ss
94 stop then start
95 .It Va rs
96 repeated start
97 .It Va no
98 none
99 .El
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.
104 The
105 .Va tr
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.
113 .It Fl o Ar offset
114 offset within the device for data transfer (hex).
115 The default is zero.
116 Use
117 .Dq -w 0
118 to disable writing of the offset to the slave.
119 .It Fl r
120 reset the controller.
121 .It Fl s
122 scan the bus for devices.
123 .It Fl v
124 be verbose.
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
128 .Ar offset
129 specified with
130 .Fl o
131 to the slave.
132 Zero means that the offset is ignored and not passed to the slave at all.
133 The endianess defaults to little-endian.
134 .El
135 .Sh INTERPRETED MODE
136 When started with
137 .Fl i
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.
141 .Pp
142 Available commands:
143 .Bl -tag -compact
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.
148 .It 'p' anything
149 Print command, the entire line is printed to stdout.  (This can be used
150 for synchronization.)
151 .El
152 .Pp
153 All numeric fields accept canonical decimal/octal/hex notation.
154 .Pp
155 Without the
156 .Fl v
157 option, all errors are fatal with non-zero exit status.
158 .Pp
159 With the
160 .Fl v
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.
164 .Pp
165 Blank lines and lines starting with '#' are ignored.
166 .Sh EXAMPLES
167 .Bl -bullet
168 .It
169 Scan the default bus (/dev/iic0) for devices:
170 .Pp
171 i2c -s
172 .It
173 Scan the default bus (/dev/iic0) for devices and skip addresses 
174 0x45 to 0x47 (inclusive) and 0x56.
175 .Pp
176 i2c -s -n 0x56,45-47
177 .It
178 Read 8 bytes of data from device at address 0x56 (e.g., an EEPROM):
179 .Pp
180 i2c -a 0x56 -d r -c 8
181 .It
182 Write 16 bytes of data from file data.bin to device 0x56 at offset 0x10:
183 .Pp
184 i2c -a 0x56 -d w -c 16 -o 0x10 -b < data.bin
185 .It
186 Copy 4 bytes between two EEPROMs (0x56 on /dev/iic1 to 0x57 on /dev/iic0):
187 .Pp
188 i2c -a 0x56 -f /dev/iic1 -d r -c 0x4 -b | i2c -a 0x57 -f /dev/iic0 -d w -c 4 -b
189 .It
190 Reset the controller:
191 .Pp
192 i2c -f /dev/iic1 -r
193 .It
194 Read 8 bytes at address 24 in an EEPROM:
195 .Pp
196 i2c -i 'r 0 0x50 16BE 24 8'
197 .It
198 Read 2x8 bytes at address 24 and 48 in an EEPROM:
199 .Pp
200 echo 'r 0 0x50 16BE 48 8' | i2c -i 'r 0 0x50 16BE 24 8' -
201 .El
202 .Sh WARNING
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.
207 .Sh SEE ALSO
208 .Xr iic 4 ,
209 .Xr iicbus 4
210 .Xr smbus 4
211 .Sh HISTORY
212 The
213 .Nm
214 utility appeared in
215 .Fx 8.0 .
216 .Sh AUTHORS
217 .An -nosplit
218 The
219 .Nm
220 utility and this manual page were written by
221 .An Bartlomiej Sieka Aq Mt tur@semihalf.com
222 and
223 .An Michal Hajduk Aq Mt mih@semihalf.com .
224 .Pp
225 .An Poul-Henning Kamp Aq Mt phk@FreeBSD.org
226 added interpreted mode.