Changeset 6054
- Timestamp:
- 05/21/12 18:52:48 (12 months ago)
- Location:
- i2c-tools/trunk
- Files:
-
- 4 added
- 6 modified
-
. (modified) (1 prop)
-
CHANGES (modified) (1 diff)
-
Makefile (modified) (3 diffs)
-
README (modified) (3 diffs)
-
include/i2c/smbus.h (modified) (2 diffs)
-
lib (added)
-
lib/Module.mk (added)
-
lib/libi2c.map (added)
-
lib/smbus.c (added)
-
tools/Module.mk (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
i2c-tools/trunk
-
Property
svn:mergeinfo set
to
/i2c-tools/branches/i2c-tools-3.1 merged eligible
-
Property
svn:mergeinfo set
to
-
i2c-tools/trunk/CHANGES
r6048 r6054 8 8 Move SMBus helper functions to include/i2c/smbus.h 9 9 i2c-stub-from-dump: Be more tolerant on input dump format 10 library: New libi2c library 10 11 11 12 3.1.0 (2011-12-04) -
i2c-tools/trunk/Makefile
r5610 r6054 15 15 man8dir = $(mandir)/man8 16 16 incdir = $(prefix)/include 17 libdir = $(prefix)/lib 17 18 18 19 INSTALL := install … … 20 21 INSTALL_DIR := $(INSTALL) -m 755 -d 21 22 INSTALL_PROGRAM := $(INSTALL) -m 755 23 LN := ln -sf 22 24 RM := rm -f 23 25 24 26 CC ?= gcc 27 AR ?= ar 25 28 26 CFLAGS ?= -O229 CFLAGS ?= -O2 27 30 # When debugging, use the following instead 28 #CFLAGS := -O -g 29 CFLAGS += -Wall 31 #CFLAGS := -O -g 32 CFLAGS += -Wall 33 SOCFLAGS := -fpic -D_REENTRANT $(CFLAGS) 34 35 BUILD_STATIC_LIB ?= 1 30 36 31 37 KERNELVERSION := $(shell uname -r) … … 37 43 EXTRA := 38 44 #EXTRA += py-smbus 39 SRCDIRS := include eeprom stub tools $(EXTRA)45 SRCDIRS := include lib eeprom stub tools $(EXTRA) 40 46 include $(SRCDIRS:%=%/Module.mk) -
i2c-tools/trunk/README
r5882 r6054 2 2 =================== 3 3 4 This package contains an heterogeneous set of I2C tools for the Linux kernel. 5 These tools were originally part of the lm-sensors project but were finally 6 split into their own package for convenience. They compile, run and have been 7 tested on GNU/Linux. 4 This package contains an heterogeneous set of I2C tools for the Linux kernel 5 as well as an I2C library. The tools were originally part of the lm-sensors 6 project but were finally split into their own package for convenience. The 7 library is used by some of the tools, but can also be used by third-party 8 applications. The tools and library compile, run and have been tested on 9 GNU/Linux. 10 11 The latest version of the code can be downloaded from: 12 http://www.lm-sensors.org/wiki/I2CTools 8 13 9 14 … … 26 31 default. 27 32 33 * lib 34 The I2C library, used by eepromer, py-smbus and tools. Installed by 35 default. 36 28 37 * py-smbus 29 38 Python wrapper for SMBus access over i2c-dev. Not installed by default. … … 41 50 ------------ 42 51 43 There's no configure script, so simply run "make" to build the tools, and 44 "make install" to install them. You also can use "make uninstall" to remove 45 all the files you installed. By default, files are installed in /usr/local 46 but you can change this behavior by editing the Makefile file and setting 47 prefix to wherever you want. You may change the C compiler and the 48 compilation flags as well. 52 There's no configure script, so simply run "make" to build the library and 53 tools, and "make install" to install them. You also can use "make uninstall" 54 to remove all the files you installed. By default, files are installed in 55 /usr/local but you can change the location by editing the Makefile file and 56 setting prefix to wherever you want. You may change the C compiler and the 57 compilation flags as well, and also decide whether to build the static 58 library or not. 49 59 50 60 Optionally, you can run "make strip" prior to "make install" if you want 51 61 smaller binaries. However, be aware that this will prevent any further 52 attempt to debug the programs.62 attempt to debug the library and tools. 53 63 54 64 If you wish to include sub-directories that are not enabled by default, then -
i2c-tools/trunk/include/i2c/smbus.h
r6053 r6054 24 24 #define LIB_I2C_SMBUS_H 25 25 26 #include <sys/ioctl.h>27 26 #include <linux/types.h> 28 27 #include <linux/i2c.h> 29 #include <linux/i2c-dev.h>30 28 31 /* Compatibility defines */ 32 #ifndef I2C_SMBUS_I2C_BLOCK_BROKEN 33 #define I2C_SMBUS_I2C_BLOCK_BROKEN I2C_SMBUS_I2C_BLOCK_DATA 34 #endif 35 #ifndef I2C_FUNC_SMBUS_PEC 36 #define I2C_FUNC_SMBUS_PEC I2C_FUNC_SMBUS_HWPEC_CALC 37 #endif 29 extern __s32 i2c_smbus_access(int file, char read_write, __u8 command, 30 int size, union i2c_smbus_data *data); 38 31 39 static inline __s32 i2c_smbus_access(int file, char read_write, __u8 command, 40 int size, union i2c_smbus_data *data) 41 { 42 struct i2c_smbus_ioctl_data args; 43 44 args.read_write = read_write; 45 args.command = command; 46 args.size = size; 47 args.data = data; 48 return ioctl(file, I2C_SMBUS, &args); 49 } 50 51 52 static inline __s32 i2c_smbus_write_quick(int file, __u8 value) 53 { 54 return i2c_smbus_access(file, value, 0, I2C_SMBUS_QUICK, NULL); 55 } 56 57 static inline __s32 i2c_smbus_read_byte(int file) 58 { 59 union i2c_smbus_data data; 60 if (i2c_smbus_access(file, I2C_SMBUS_READ, 0, I2C_SMBUS_BYTE, &data)) 61 return -1; 62 else 63 return 0x0FF & data.byte; 64 } 65 66 static inline __s32 i2c_smbus_write_byte(int file, __u8 value) 67 { 68 return i2c_smbus_access(file, I2C_SMBUS_WRITE, value, 69 I2C_SMBUS_BYTE, NULL); 70 } 71 72 static inline __s32 i2c_smbus_read_byte_data(int file, __u8 command) 73 { 74 union i2c_smbus_data data; 75 if (i2c_smbus_access(file, I2C_SMBUS_READ, command, 76 I2C_SMBUS_BYTE_DATA, &data)) 77 return -1; 78 else 79 return 0x0FF & data.byte; 80 } 81 82 static inline __s32 i2c_smbus_write_byte_data(int file, __u8 command, 83 __u8 value) 84 { 85 union i2c_smbus_data data; 86 data.byte = value; 87 return i2c_smbus_access(file, I2C_SMBUS_WRITE, command, 88 I2C_SMBUS_BYTE_DATA, &data); 89 } 90 91 static inline __s32 i2c_smbus_read_word_data(int file, __u8 command) 92 { 93 union i2c_smbus_data data; 94 if (i2c_smbus_access(file, I2C_SMBUS_READ, command, 95 I2C_SMBUS_WORD_DATA, &data)) 96 return -1; 97 else 98 return 0x0FFFF & data.word; 99 } 100 101 static inline __s32 i2c_smbus_write_word_data(int file, __u8 command, 102 __u16 value) 103 { 104 union i2c_smbus_data data; 105 data.word = value; 106 return i2c_smbus_access(file, I2C_SMBUS_WRITE, command, 107 I2C_SMBUS_WORD_DATA, &data); 108 } 109 110 static inline __s32 i2c_smbus_process_call(int file, __u8 command, __u16 value) 111 { 112 union i2c_smbus_data data; 113 data.word = value; 114 if (i2c_smbus_access(file, I2C_SMBUS_WRITE, command, 115 I2C_SMBUS_PROC_CALL, &data)) 116 return -1; 117 else 118 return 0x0FFFF & data.word; 119 } 120 32 extern __s32 i2c_smbus_write_quick(int file, __u8 value); 33 extern __s32 i2c_smbus_read_byte(int file); 34 extern __s32 i2c_smbus_write_byte(int file, __u8 value); 35 extern __s32 i2c_smbus_read_byte_data(int file, __u8 command); 36 extern __s32 i2c_smbus_write_byte_data(int file, __u8 command, __u8 value); 37 extern __s32 i2c_smbus_read_word_data(int file, __u8 command); 38 extern __s32 i2c_smbus_write_word_data(int file, __u8 command, __u16 value); 39 extern __s32 i2c_smbus_process_call(int file, __u8 command, __u16 value); 121 40 122 41 /* Returns the number of read bytes */ 123 static inline __s32 i2c_smbus_read_block_data(int file, __u8 command, 124 __u8 *values) 125 { 126 union i2c_smbus_data data; 127 int i; 128 if (i2c_smbus_access(file, I2C_SMBUS_READ, command, 129 I2C_SMBUS_BLOCK_DATA, &data)) 130 return -1; 131 else { 132 for (i = 1; i <= data.block[0]; i++) 133 values[i-1] = data.block[i]; 134 return data.block[0]; 135 } 136 } 137 138 static inline __s32 i2c_smbus_write_block_data(int file, __u8 command, 139 __u8 length, const __u8 *values) 140 { 141 union i2c_smbus_data data; 142 int i; 143 if (length > 32) 144 length = 32; 145 for (i = 1; i <= length; i++) 146 data.block[i] = values[i-1]; 147 data.block[0] = length; 148 return i2c_smbus_access(file, I2C_SMBUS_WRITE, command, 149 I2C_SMBUS_BLOCK_DATA, &data); 150 } 42 extern __s32 i2c_smbus_read_block_data(int file, __u8 command, __u8 *values); 43 extern __s32 i2c_smbus_write_block_data(int file, __u8 command, __u8 length, 44 const __u8 *values); 151 45 152 46 /* Returns the number of read bytes */ … … 154 48 ask for less than 32 bytes, your code will only work with kernels 155 49 2.6.23 and later. */ 156 static inline __s32 i2c_smbus_read_i2c_block_data(int file, __u8 command, 157 __u8 length, __u8 *values) 158 { 159 union i2c_smbus_data data; 160 int i; 161 162 if (length > 32) 163 length = 32; 164 data.block[0] = length; 165 if (i2c_smbus_access(file, I2C_SMBUS_READ, command, 166 length == 32 ? I2C_SMBUS_I2C_BLOCK_BROKEN : 167 I2C_SMBUS_I2C_BLOCK_DATA, &data)) 168 return -1; 169 else { 170 for (i = 1; i <= data.block[0]; i++) 171 values[i-1] = data.block[i]; 172 return data.block[0]; 173 } 174 } 175 176 static inline __s32 i2c_smbus_write_i2c_block_data(int file, __u8 command, 177 __u8 length, 178 const __u8 *values) 179 { 180 union i2c_smbus_data data; 181 int i; 182 if (length > 32) 183 length = 32; 184 for (i = 1; i <= length; i++) 185 data.block[i] = values[i-1]; 186 data.block[0] = length; 187 return i2c_smbus_access(file, I2C_SMBUS_WRITE, command, 188 I2C_SMBUS_I2C_BLOCK_BROKEN, &data); 189 } 50 extern __s32 i2c_smbus_read_i2c_block_data(int file, __u8 command, __u8 length, 51 __u8 *values); 52 extern __s32 i2c_smbus_write_i2c_block_data(int file, __u8 command, __u8 length, 53 const __u8 *values); 190 54 191 55 /* Returns the number of read bytes */ 192 static inline __s32 i2c_smbus_block_process_call(int file, __u8 command, 193 __u8 length, __u8 *values) 194 { 195 union i2c_smbus_data data; 196 int i; 197 if (length > 32) 198 length = 32; 199 for (i = 1; i <= length; i++) 200 data.block[i] = values[i-1]; 201 data.block[0] = length; 202 if (i2c_smbus_access(file, I2C_SMBUS_WRITE, command, 203 I2C_SMBUS_BLOCK_PROC_CALL, &data)) 204 return -1; 205 else { 206 for (i = 1; i <= data.block[0]; i++) 207 values[i-1] = data.block[i]; 208 return data.block[0]; 209 } 210 } 56 extern __s32 i2c_smbus_block_process_call(int file, __u8 command, __u8 length, 57 __u8 *values); 211 58 212 59 #endif /* LIB_I2C_SMBUS_H */ -
i2c-tools/trunk/tools/Module.mk
r6049 r6054 13 13 -Wcast-align -Wwrite-strings -Wnested-externs -Winline \ 14 14 -W -Wundef -Wmissing-prototypes -Iinclude 15 TOOLS_LDFLAGS := -Llib -li2c 15 16 16 17 TOOLS_TARGETS := i2cdetect i2cdump i2cset i2cget … … 21 22 22 23 $(TOOLS_DIR)/i2cdetect: $(TOOLS_DIR)/i2cdetect.o $(TOOLS_DIR)/i2cbusses.o 23 $(CC) $(LDFLAGS) -o $@ $^24 $(CC) $(LDFLAGS) $(TOOLS_LDFLAGS) -o $@ $^ 24 25 25 26 $(TOOLS_DIR)/i2cdump: $(TOOLS_DIR)/i2cdump.o $(TOOLS_DIR)/i2cbusses.o $(TOOLS_DIR)/util.o 26 $(CC) $(LDFLAGS) -o $@ $^27 $(CC) $(LDFLAGS) $(TOOLS_LDFLAGS) -o $@ $^ 27 28 28 29 $(TOOLS_DIR)/i2cset: $(TOOLS_DIR)/i2cset.o $(TOOLS_DIR)/i2cbusses.o $(TOOLS_DIR)/util.o 29 $(CC) $(LDFLAGS) -o $@ $^30 $(CC) $(LDFLAGS) $(TOOLS_LDFLAGS) -o $@ $^ 30 31 31 32 $(TOOLS_DIR)/i2cget: $(TOOLS_DIR)/i2cget.o $(TOOLS_DIR)/i2cbusses.o $(TOOLS_DIR)/util.o 32 $(CC) $(LDFLAGS) -o $@ $^33 $(CC) $(LDFLAGS) $(TOOLS_LDFLAGS) -o $@ $^ 33 34 34 35 #
