Interface examples, Ktam3874/pitx software guide, Detection utility – Kontron KTAM3874-pITX User Manual
Page 46

KTD-S0057-I
Page 42 Linux® Programming Examples (DebianTM)
KTAM3874/pITX Software Guide
10.3 I
2
C
TM
Interface Examples
10.3.1 I
2
C
TM
Detection Utility
The following sourcecode represents an optimized lean version of the standard I
2
C
TM
detection program
without unnecessary overhead (compiled on Ubuntu
TM
distribution, needs root rights).
/*
i2cdetect.c - a user-space program to scan for I2C devices
Copyright (C) 1999-2004 Frodo Looijaard <[email protected]>, and
Mark D. Studebaker <[email protected]>
Copyright (C) 2004-2012 Jean Delvare <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301 USA.
*/
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <linux/types.h>
#define MODE_AUTO
0
#define MODE_QUICK
1
#define MODE_READ
2
#define MODE_FUNC
3
#define I2C_FUNC_I2C
0x00000001
#define I2C_FUNC_10BIT_ADDR
0x00000002
#define I2C_FUNC_PROTOCOL_MANGLING
0x00000004
#define I2C_FUNC_SMBUS_PEC
0x00000008
#define I2C_FUNC_SMBUS_BLOCK_PROC_CALL
0x00008000
#define I2C_FUNC_SMBUS_QUICK
0x00010000
#define I2C_FUNC_SMBUS_READ_BYTE
0x00020000
#define I2C_FUNC_SMBUS_WRITE_BYTE
0x00040000
#define I2C_FUNC_SMBUS_READ_BYTE_DATA
0x00080000
#define I2C_FUNC_SMBUS_WRITE_BYTE_DATA
0x00100000
#define I2C_FUNC_SMBUS_READ_WORD_DATA
0x00200000
#define I2C_FUNC_SMBUS_WRITE_WORD_DATA
0x00400000
#define I2C_FUNC_SMBUS_PROC_CALL
0x00800000