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.\" 26477f656bSRafal Jaworowski.\" $FreeBSD$ 27477f656bSRafal Jaworowski.\" 28477f656bSRafal Jaworowski 29477f656bSRafal Jaworowski.Dd Jan 23, 2009 30477f656bSRafal Jaworowski.Dt I2C 8 31477f656bSRafal Jaworowski.Os 32477f656bSRafal Jaworowski.Sh NAME 33477f656bSRafal Jaworowski.Nm i2c 34477f656bSRafal Jaworowski.Nd test I2C bus and slave devices 35477f656bSRafal Jaworowski.Sh SYNOPSIS 36477f656bSRafal Jaworowski.Nm 37477f656bSRafal Jaworowski.Cm -a Ar address 38477f656bSRafal Jaworowski.Op Fl f Ar device 39477f656bSRafal Jaworowski.Op Fl d Ar r|w 40477f656bSRafal Jaworowski.Op Fl w Ar 0|8|16 41477f656bSRafal Jaworowski.Op Fl o Ar offset 42477f656bSRafal Jaworowski.Op Fl c Ar count 43477f656bSRafal Jaworowski.Op Fl m Ar ss|rs|no 44477f656bSRafal Jaworowski.Op Fl b 45477f656bSRafal Jaworowski.Op Fl v 46477f656bSRafal Jaworowski.Nm 47477f656bSRafal Jaworowski.Cm -s 48477f656bSRafal Jaworowski.Op Fl f Ar device 49477f656bSRafal Jaworowski.Op Fl n Ar skip_addr 50477f656bSRafal Jaworowski.Op Fl v 51477f656bSRafal Jaworowski.Nm 52477f656bSRafal Jaworowski.Cm -r 53477f656bSRafal Jaworowski.Op Fl f Ar device 54477f656bSRafal Jaworowski.Op Fl v 55477f656bSRafal Jaworowski.Sh DESCRIPTION 56477f656bSRafal JaworowskiThe 57477f656bSRafal Jaworowski.Nm 58477f656bSRafal Jaworowskiutility can be used to perform raw data transfers (read or write) with devices 59477f656bSRafal Jaworowskion the I2C bus. It can also scan the bus for available devices and reset the 60477f656bSRafal JaworowskiI2C controller. 61477f656bSRafal Jaworowski.Pp 62477f656bSRafal JaworowskiThe options are as follows: 63477f656bSRafal Jaworowski.Bl -tag -width ".Fl d Ar direction" 64477f656bSRafal Jaworowski.It Fl a Ar address 65477f656bSRafal Jaworowski7-bit address on the I2C device to operate on (hex). 66477f656bSRafal Jaworowski.It Fl b 67477f656bSRafal Jaworowskibinary mode - when performing a read operation, the data read from the device 68477f656bSRafal Jaworowskiis output in binary format on stdout; when doing a write, the binary data to 69477f656bSRafal Jaworowskibe written to the device is read from stdin. 70477f656bSRafal Jaworowski.It Fl c Ar count 71477f656bSRafal Jaworowskinumber of bytes to transfer (dec). 72477f656bSRafal Jaworowski.It Fl d Ar r|w 73477f656bSRafal Jaworowskitransfer direction: r - read, w - write. 74477f656bSRafal Jaworowski.It Fl f Ar device 75477f656bSRafal JaworowskiI2C bus to use (default is /dev/iic0). 76477f656bSRafal Jaworowski.It Fl m Ar ss|rs|no 77477f656bSRafal Jaworowskiaddressing mode, i.e., I2C bus operations performed after the offset for the 78477f656bSRafal Jaworowskitransfer has been written to the device and before the actual read/write 79477f656bSRafal Jaworowskioperation. rs - repeated start; ss - stop start; no - none. 80477f656bSRafal Jaworowski.It Fl n Ar skip_addr 81477f656bSRafal Jaworowskiskip address - address(es) to be skipped during bus scan. 82477f656bSRafal JaworowskiThe are two ways to specify addresses to ignore: by range 'a..b' or 83477f656bSRafal Jaworowskiusing selected addresses 'a:b:c'. This option is available only when "-s" is 84477f656bSRafal Jaworowskiused. 85477f656bSRafal Jaworowski.It Fl o Ar offset 86477f656bSRafal Jaworowskioffset within the device for data transfer (hex). 87477f656bSRafal Jaworowski.It Fl r 88477f656bSRafal Jaworowskireset the controller. 89477f656bSRafal Jaworowski.It Fl s 90477f656bSRafal Jaworowskiscan the bus for devices. 91477f656bSRafal Jaworowski.It Fl v 92477f656bSRafal Jaworowskibe verbose 93477f656bSRafal Jaworowski.It Fl w Ar 0|8|16 94477f656bSRafal Jaworowskidevice addressing width (in bits). 95477f656bSRafal Jaworowski.El 96477f656bSRafal Jaworowski.Sh WARNINGS 97477f656bSRafal JaworowskiGreat care must be taken when manipulating slave I2C devices with the 98477f656bSRafal Jaworowski.Nm 99477f656bSRafal Jaworowskiutility. Often times important configuration data for the system is kept in 100477f656bSRafal Jaworowskinon-volatile but write enabled memories located on the I2C bus, for example 101477f656bSRafal JaworowskiEthernet hardware addresses, RAM module parameters (SPD), processor reset 102477f656bSRafal Jaworowskiconfiguration word etc. 103477f656bSRafal Jaworowski.Pp 104477f656bSRafal JaworowskiIt is very easy to render the whole system unusable when such configuration 105477f656bSRafal Jaworowskidata is deleted or altered, so use the 106477f656bSRafal Jaworowski.Dq -d w 107477f656bSRafal Jaworowski(write) command only if you know exactly what you are doing. 108477f656bSRafal Jaworowski.Pp 109477f656bSRafal JaworowskiAlso avoid ungraceful interrupting of an ongoing transaction on the I2C bus, 110477f656bSRafal Jaworowskias it can lead to potentially dangerous effects. Consider the following 111477f656bSRafal Jaworowskiscenario: when the host CPU is reset (for whatever reason) in the middle of a 112477f656bSRafal Jaworowskistarted I2C transaction, the I2C slave device could be left in write mode 113477f656bSRafal Jaworowskiwaiting for data or offset to arrive. When the CPU reinitializes itself and 114477f656bSRafal Jaworowskitalks to this I2C slave device again, the commands and other control info it 115477f656bSRafal Jaworowskisends are treated by the slave device as data or offset it was waiting for, 116477f656bSRafal Jaworowskiand there's great potential for corruption if such a write is performed. 117477f656bSRafal Jaworowski.Sh EXAMPLES 118477f656bSRafal Jaworowski.Pp 119477f656bSRafal Jaworowski.Bl -bullet 120477f656bSRafal Jaworowski.It 121477f656bSRafal JaworowskiScan the default bus (/dev/iic0) for devices: 122477f656bSRafal Jaworowski.Pp 123477f656bSRafal Jaworowskii2c -s 124477f656bSRafal Jaworowski.It 125477f656bSRafal JaworowskiScan the default bus (/dev/iic0) for devices and skip addresses 0x56 and 126477f656bSRafal Jaworowski0x45. 127477f656bSRafal Jaworowski.Pp 128477f656bSRafal Jaworowskii2c -s -n 0x56:0x45 129477f656bSRafal Jaworowski.It 130477f656bSRafal JaworowskiScan the default bus (/dev/iic0) for devices and skip address range 131477f656bSRafal Jaworowski0x34 to 0x56. 132477f656bSRafal Jaworowski.Pp 133477f656bSRafal Jaworowskii2c -s -n 0x34..0x56 134477f656bSRafal Jaworowski.It 135477f656bSRafal JaworowskiRead 8 bytes of data from device at address 0x56 (e.g., an EEPROM): 136477f656bSRafal Jaworowski.Pp 137477f656bSRafal Jaworowskii2c -a 0x56 -d r -c 8 138477f656bSRafal Jaworowski.It 139477f656bSRafal JaworowskiWrite 16 bytes of data from file data.bin to device 0x56 at offset 0x10: 140477f656bSRafal Jaworowski.Pp 141477f656bSRafal Jaworowskii2c -a 0x56 -d w -c 16 -o 0x10 -b < data.bin 142477f656bSRafal Jaworowski.It 143477f656bSRafal JaworowskiCopy 4 bytes between two EEPROMs (0x56 on /dev/iic1 to 0x57 on /dev/iic0): 144477f656bSRafal Jaworowski.Pp 145477f656bSRafal Jaworowskii2c -a 0x56 -f /dev/iic1 -d r -c 0x4 -b | i2c -a 0x57 -f /dev/iic0 -d w -c 4 -b 146477f656bSRafal Jaworowski.It 147477f656bSRafal JaworowskiReset the controller: 148477f656bSRafal Jaworowski.Pp 149477f656bSRafal Jaworowskii2c -f /dev/iic1 -r 150477f656bSRafal Jaworowski.El 151477f656bSRafal Jaworowski.Sh SEE ALSO 152477f656bSRafal Jaworowski.Xr iic 4 , 153477f656bSRafal Jaworowski.Xr iicbus 4 154477f656bSRafal Jaworowski.Sh HISTORY 155477f656bSRafal JaworowskiThe 156477f656bSRafal Jaworowski.Nm 157477f656bSRafal Jaworowskiutility appeared in 158477f656bSRafal Jaworowski.Fx 8.0 . 159477f656bSRafal Jaworowski.Sh AUTHORS 160477f656bSRafal Jaworowski.An -nosplit 161477f656bSRafal JaworowskiThe 162477f656bSRafal Jaworowski.Nm 163477f656bSRafal Jaworowskiutility and this manual page were written by 164477f656bSRafal Jaworowski.An Bartlomiej Sieka 165477f656bSRafal Jaworowski.Aq tur@semihalf.com 166477f656bSRafal Jaworowskiand 167477f656bSRafal Jaworowski.An Michal Hajduk 168477f656bSRafal Jaworowski.Aq mih@semihalf.com . 169