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