]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.sbin/i2c/i2c.8
cr_canseejailproc(): New privilege, no direct check for UID 0
[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 .Dd May 22, 2019
27 .Dt I2C 8
28 .Os
29 .Sh NAME
30 .Nm i2c
31 .Nd test I2C bus and slave devices
32 .Sh SYNOPSIS
33 .Nm
34 .Cm -a Ar address
35 .Op Fl f Ar device
36 .Op Fl d Ar r|w
37 .Op Fl w Ar 0|8|16
38 .Op Fl o Ar offset
39 .Op Fl c Ar count
40 .Op Fl m Ar tr|ss|rs|no
41 .Op Fl b
42 .Op Fl v
43 .Nm
44 .Cm -s
45 .Op Fl f Ar device
46 .Op Fl n Ar skip_addr
47 .Op Fl v
48 .Nm
49 .Cm -r
50 .Op Fl f Ar device
51 .Op Fl v
52 .Sh DESCRIPTION
53 The
54 .Nm
55 utility can be used to perform raw data transfers (read or write) with devices
56 on the I2C bus.
57 It can also scan the bus for available devices and reset the I2C controller.
58 .Pp
59 The options are as follows:
60 .Bl -tag -width ".Fl d Ar direction"
61 .It Fl a Ar address
62 7-bit address on the I2C device to operate on (hex).
63 .It Fl b
64 binary mode - when performing a read operation, the data read from the device
65 is output in binary format on stdout; when doing a write, the binary data to
66 be written to the device is read from stdin.
67 .It Fl c Ar count
68 number of bytes to transfer (dec).
69 .It Fl d Ar r|w
70 transfer direction: r - read, w - write.
71 .It Fl f Ar device
72 I2C bus to use (default is /dev/iic0).
73 .It Fl m Ar tr|ss|rs|no
74 addressing mode, i.e., I2C bus operations performed after the offset for the
75 transfer has been written to the device and before the actual read/write
76 operation.
77 .Bl -tag -compact -offset indent
78 .It Va tr
79 complete-transfer
80 .It Va ss
81 stop then start
82 .It Va rs
83 repeated start
84 .It Va no
85 none
86 .El
87 Some I2C bus hardware does not provide control over the individual start,
88 repeat-start, and stop operations.
89 Such hardware can only perform a complete transfer of the offset and the
90 data as a single operation.
91 The
92 .Va tr
93 mode creates control structures describing the transfer and submits them
94 to the driver as a single complete transaction.
95 This mode works on all types of I2C hardware.
96 .It Fl n Ar skip_addr
97 skip address - address(es) to be skipped during bus scan.
98 There are two ways to specify addresses to ignore: by range 'a..b' or
99 using selected addresses 'a:b:c'. This option is available only when "-s" is
100 used.
101 .It Fl o Ar offset
102 offset within the device for data transfer (hex).
103 The default is zero.
104 Use
105 .Dq -w 0
106 to disable writing of the offset to the slave.
107 .It Fl r
108 reset the controller.
109 .It Fl s
110 scan the bus for devices.
111 .It Fl v
112 be verbose.
113 .It Fl w Ar 0|8|16
114 device addressing width (in bits).
115 This is used to determine how to pass
116 .Ar offset
117 specified with
118 .Fl o
119 to the slave.
120 Zero means that the offset is ignored and not passed to the slave at all.
121 .El
122 .Sh WARNINGS
123 Great care must be taken when manipulating slave I2C devices with the
124 .Nm
125 utility.
126 Often times important configuration data for the system is kept in non-volatile
127 but write enabled memories located on the I2C bus, for example Ethernet hardware
128 addresses, RAM module parameters (SPD), processor reset configuration word etc.
129 .Pp
130 It is very easy to render the whole system unusable when such configuration
131 data is deleted or altered, so use the
132 .Dq -d w
133 (write) command only if you know exactly what you are doing.
134 .Pp
135 Also avoid ungraceful interrupting of an ongoing transaction on the I2C bus,
136 as it can lead to potentially dangerous effects.
137 Consider the following scenario: when the host CPU is reset (for whatever reason)
138 in the middle of a started I2C transaction, the I2C slave device could be left
139 in write mode waiting for data or offset to arrive.
140 When the CPU reinitializes itself and talks to this I2C slave device again,
141 the commands and other control info it sends are treated by the slave device
142 as data or offset it was waiting for, and there's great potential for
143 corruption if such a write is performed.
144 .Sh EXAMPLES
145 .Bl -bullet
146 .It
147 Scan the default bus (/dev/iic0) for devices:
148 .Pp
149 i2c -s
150 .It
151 Scan the default bus (/dev/iic0) for devices and skip addresses 0x56 and
152 0x45.
153 .Pp
154 i2c -s -n 0x56:0x45
155 .It
156 Scan the default bus (/dev/iic0) for devices and skip address range
157 0x34 to 0x56.
158 .Pp
159 i2c -s -n 0x34..0x56
160 .It
161 Read 8 bytes of data from device at address 0x56 (e.g., an EEPROM):
162 .Pp
163 i2c -a 0x56 -d r -c 8
164 .It
165 Write 16 bytes of data from file data.bin to device 0x56 at offset 0x10:
166 .Pp
167 i2c -a 0x56 -d w -c 16 -o 0x10 -b < data.bin
168 .It
169 Copy 4 bytes between two EEPROMs (0x56 on /dev/iic1 to 0x57 on /dev/iic0):
170 .Pp
171 i2c -a 0x56 -f /dev/iic1 -d r -c 0x4 -b | i2c -a 0x57 -f /dev/iic0 -d w -c 4 -b
172 .It
173 Reset the controller:
174 .Pp
175 i2c -f /dev/iic1 -r
176 .El
177 .Sh SEE ALSO
178 .Xr iic 4 ,
179 .Xr iicbus 4
180 .Sh HISTORY
181 The
182 .Nm
183 utility appeared in
184 .Fx 8.0 .
185 .Sh AUTHORS
186 .An -nosplit
187 The
188 .Nm
189 utility and this manual page were written by
190 .An Bartlomiej Sieka Aq Mt tur@semihalf.com
191 and
192 .An Michal Hajduk Aq Mt mih@semihalf.com .