diff options
Diffstat (limited to 'miscutils/i2c_tools.c')
-rw-r--r-- | miscutils/i2c_tools.c | 109 |
1 files changed, 64 insertions, 45 deletions
diff --git a/miscutils/i2c_tools.c b/miscutils/i2c_tools.c index 30f606e8e..fc392d9dc 100644 --- a/miscutils/i2c_tools.c +++ b/miscutils/i2c_tools.c | |||
@@ -8,7 +8,6 @@ | |||
8 | * | 8 | * |
9 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. | 9 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
10 | */ | 10 | */ |
11 | |||
12 | //config:config I2CGET | 11 | //config:config I2CGET |
13 | //config: bool "i2cget (5.6 kb)" | 12 | //config: bool "i2cget (5.6 kb)" |
14 | //config: default y | 13 | //config: default y |
@@ -61,10 +60,8 @@ | |||
61 | */ | 60 | */ |
62 | 61 | ||
63 | #include "libbb.h" | 62 | #include "libbb.h" |
64 | #include "common_bufsiz.h" | ||
65 | 63 | ||
66 | #include <linux/i2c.h> | 64 | #include <linux/i2c.h> |
67 | #include <linux/i2c-dev.h> | ||
68 | 65 | ||
69 | #define I2CDUMP_NUM_REGS 256 | 66 | #define I2CDUMP_NUM_REGS 256 |
70 | 67 | ||
@@ -72,6 +69,25 @@ | |||
72 | #define I2CDETECT_MODE_QUICK 1 | 69 | #define I2CDETECT_MODE_QUICK 1 |
73 | #define I2CDETECT_MODE_READ 2 | 70 | #define I2CDETECT_MODE_READ 2 |
74 | 71 | ||
72 | /* linux/i2c-dev.h from i2c-tools overwrites the one from linux uapi | ||
73 | * and defines symbols already defined by linux/i2c.h. | ||
74 | * Also, it defines a bunch of static inlines which we would rather NOT | ||
75 | * inline. What a mess. | ||
76 | * We need only these definitions from linux/i2c-dev.h: | ||
77 | */ | ||
78 | #define I2C_SLAVE 0x0703 | ||
79 | #define I2C_SLAVE_FORCE 0x0706 | ||
80 | #define I2C_FUNCS 0x0705 | ||
81 | #define I2C_PEC 0x0708 | ||
82 | #define I2C_SMBUS 0x0720 | ||
83 | struct i2c_smbus_ioctl_data { | ||
84 | __u8 read_write; | ||
85 | __u8 command; | ||
86 | __u32 size; | ||
87 | union i2c_smbus_data *data; | ||
88 | }; | ||
89 | /* end linux/i2c-dev.h */ | ||
90 | |||
75 | /* | 91 | /* |
76 | * This is needed for ioctl_or_perror_and_die() since it only accepts pointers. | 92 | * This is needed for ioctl_or_perror_and_die() since it only accepts pointers. |
77 | */ | 93 | */ |
@@ -438,19 +454,20 @@ static void confirm_action(int bus_addr, int mode, int data_addr, int pec) | |||
438 | 454 | ||
439 | #if ENABLE_I2CGET | 455 | #if ENABLE_I2CGET |
440 | //usage:#define i2cget_trivial_usage | 456 | //usage:#define i2cget_trivial_usage |
441 | //usage: "[-f] [-y] BUS CHIP-ADDRESS [DATA-ADDRESS [MODE]]" | 457 | //usage: "[-fy] BUS CHIP-ADDRESS [DATA-ADDRESS [MODE]]" |
442 | //usage:#define i2cget_full_usage "\n\n" | 458 | //usage:#define i2cget_full_usage "\n\n" |
443 | //usage: "Read from I2C/SMBus chip registers\n" | 459 | //usage: "Read from I2C/SMBus chip registers" |
444 | //usage: "\n I2CBUS i2c bus number" | 460 | //usage: "\n" |
445 | //usage: "\n ADDRESS 0x03 - 0x77" | 461 | //usage: "\n I2CBUS I2C bus number" |
462 | //usage: "\n ADDRESS 0x03-0x77" | ||
446 | //usage: "\nMODE is:" | 463 | //usage: "\nMODE is:" |
447 | //usage: "\n b read byte data (default)" | 464 | //usage: "\n b Read byte data (default)" |
448 | //usage: "\n w read word data" | 465 | //usage: "\n w Read word data" |
449 | //usage: "\n c write byte/read byte" | 466 | //usage: "\n c Write byte/read byte" |
450 | //usage: "\n Append p for SMBus PEC" | 467 | //usage: "\n Append p for SMBus PEC" |
451 | //usage: "\n" | 468 | //usage: "\n" |
452 | //usage: "\n -f force access" | 469 | //usage: "\n -f Force access" |
453 | //usage: "\n -y disable interactive mode" | 470 | //usage: "\n -y Disable interactive mode" |
454 | int i2cget_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 471 | int i2cget_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
455 | int i2cget_main(int argc UNUSED_PARAM, char **argv) | 472 | int i2cget_main(int argc UNUSED_PARAM, char **argv) |
456 | { | 473 | { |
@@ -520,23 +537,24 @@ int i2cget_main(int argc UNUSED_PARAM, char **argv) | |||
520 | 537 | ||
521 | #if ENABLE_I2CSET | 538 | #if ENABLE_I2CSET |
522 | //usage:#define i2cset_trivial_usage | 539 | //usage:#define i2cset_trivial_usage |
523 | //usage: "[-f] [-y] [-m MASK] BUS CHIP-ADDR DATA-ADDR [VALUE] ... [MODE]" | 540 | //usage: "[-fy] [-m MASK] BUS CHIP-ADDRESS DATA-ADDRESS [VALUE] ... [MODE]" |
524 | //usage:#define i2cset_full_usage "\n\n" | 541 | //usage:#define i2cset_full_usage "\n\n" |
525 | //usage: "Set I2C registers\n" | 542 | //usage: "Set I2C registers" |
526 | //usage: "\n I2CBUS i2c bus number" | 543 | //usage: "\n" |
527 | //usage: "\n ADDRESS 0x03 - 0x77" | 544 | //usage: "\n I2CBUS I2C bus number" |
545 | //usage: "\n ADDRESS 0x03-0x77" | ||
528 | //usage: "\nMODE is:" | 546 | //usage: "\nMODE is:" |
529 | //usage: "\n c byte, no value" | 547 | //usage: "\n c Byte, no value" |
530 | //usage: "\n b byte data (default)" | 548 | //usage: "\n b Byte data (default)" |
531 | //usage: "\n w word data" | 549 | //usage: "\n w Word data" |
532 | //usage: "\n i I2C block data" | 550 | //usage: "\n i I2C block data" |
533 | //usage: "\n s SMBus block data" | 551 | //usage: "\n s SMBus block data" |
534 | //usage: "\n Append p for SMBus PEC" | 552 | //usage: "\n Append p for SMBus PEC" |
535 | //usage: "\n" | 553 | //usage: "\n" |
536 | //usage: "\n -f force access" | 554 | //usage: "\n -f Force access" |
537 | //usage: "\n -y disable interactive mode" | 555 | //usage: "\n -y Disable interactive mode" |
538 | //usage: "\n -r read back and compare the result" | 556 | //usage: "\n -r Read back and compare the result" |
539 | //usage: "\n -m MASK mask specifying which bits to write" | 557 | //usage: "\n -m MASK Mask specifying which bits to write" |
540 | int i2cset_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 558 | int i2cset_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
541 | int i2cset_main(int argc, char **argv) | 559 | int i2cset_main(int argc, char **argv) |
542 | { | 560 | { |
@@ -879,23 +897,24 @@ static void dump_word_data(int bus_fd, unsigned first, unsigned last) | |||
879 | } | 897 | } |
880 | 898 | ||
881 | //usage:#define i2cdump_trivial_usage | 899 | //usage:#define i2cdump_trivial_usage |
882 | //usage: "[-f] [-r FIRST-LAST] [-y] BUS ADDR [MODE]" | 900 | //usage: "[-fy] [-r FIRST-LAST] BUS ADDR [MODE]" |
883 | //usage:#define i2cdump_full_usage "\n\n" | 901 | //usage:#define i2cdump_full_usage "\n\n" |
884 | //usage: "Examine I2C registers\n" | 902 | //usage: "Examine I2C registers" |
885 | //usage: "\n I2CBUS i2c bus number" | 903 | //usage: "\n" |
886 | //usage: "\n ADDRESS 0x03 - 0x77" | 904 | //usage: "\n I2CBUS I2C bus number" |
905 | //usage: "\n ADDRESS 0x03-0x77" | ||
887 | //usage: "\nMODE is:" | 906 | //usage: "\nMODE is:" |
888 | //usage: "\n b byte (default)" | 907 | //usage: "\n b Byte (default)" |
889 | //usage: "\n w word" | 908 | //usage: "\n w Word" |
890 | //usage: "\n W word on even register addresses" | 909 | //usage: "\n W Word on even register addresses" |
891 | //usage: "\n i I2C block" | 910 | //usage: "\n i I2C block" |
892 | //usage: "\n s SMBus block" | 911 | //usage: "\n s SMBus block" |
893 | //usage: "\n c consecutive byte" | 912 | //usage: "\n c Consecutive byte" |
894 | //usage: "\n Append p for SMBus PEC" | 913 | //usage: "\n Append p for SMBus PEC" |
895 | //usage: "\n" | 914 | //usage: "\n" |
896 | //usage: "\n -f force access" | 915 | //usage: "\n -f Force access" |
897 | //usage: "\n -y disable interactive mode" | 916 | //usage: "\n -y Disable interactive mode" |
898 | //usage: "\n -r limit the number of registers being accessed" | 917 | //usage: "\n -r Limit the number of registers being accessed" |
899 | int i2cdump_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 918 | int i2cdump_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
900 | int i2cdump_main(int argc UNUSED_PARAM, char **argv) | 919 | int i2cdump_main(int argc UNUSED_PARAM, char **argv) |
901 | { | 920 | { |
@@ -1188,18 +1207,17 @@ static void will_skip(const char *cmd) | |||
1188 | } | 1207 | } |
1189 | 1208 | ||
1190 | //usage:#define i2cdetect_trivial_usage | 1209 | //usage:#define i2cdetect_trivial_usage |
1191 | //usage: "[-F I2CBUS] [-l] [-y] [-a] [-q|-r] I2CBUS [FIRST LAST]" | 1210 | //usage: "-l | -F I2CBUS | [-ya] [-q|-r] I2CBUS [FIRST LAST]" |
1192 | //usage:#define i2cdetect_full_usage "\n\n" | 1211 | //usage:#define i2cdetect_full_usage "\n\n" |
1193 | //usage: "Detect I2C chips.\n" | 1212 | //usage: "Detect I2C chips" |
1194 | //usage: "\n I2CBUS i2c bus number" | ||
1195 | //usage: "\n FIRST and LAST limit the probing range" | ||
1196 | //usage: "\n" | 1213 | //usage: "\n" |
1197 | //usage: "\n -l output list of installed busses" | 1214 | //usage: "\n -l List installed buses" |
1198 | //usage: "\n -y disable interactive mode" | 1215 | //usage: "\n -F BUS# List functionalities on this bus" |
1199 | //usage: "\n -a force scanning of non-regular addresses" | 1216 | //usage: "\n -y Disable interactive mode" |
1200 | //usage: "\n -q use smbus quick write commands for probing (default)" | 1217 | //usage: "\n -a Force scanning of non-regular addresses" |
1201 | //usage: "\n -r use smbus read byte commands for probing" | 1218 | //usage: "\n -q Use smbus quick write commands for probing (default)" |
1202 | //usage: "\n -F display list of functionalities" | 1219 | //usage: "\n -r Use smbus read byte commands for probing" |
1220 | //usage: "\n FIRST and LAST limit probing range" | ||
1203 | int i2cdetect_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 1221 | int i2cdetect_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
1204 | int i2cdetect_main(int argc UNUSED_PARAM, char **argv) | 1222 | int i2cdetect_main(int argc UNUSED_PARAM, char **argv) |
1205 | { | 1223 | { |
@@ -1214,7 +1232,8 @@ int i2cdetect_main(int argc UNUSED_PARAM, char **argv) | |||
1214 | opts = getopt32(argv, "^" | 1232 | opts = getopt32(argv, "^" |
1215 | "yaqrFl" | 1233 | "yaqrFl" |
1216 | "\0" | 1234 | "\0" |
1217 | "q--r:r--q:"/*mutually exclusive*/ "?3"/*up to 3 args*/ | 1235 | "q--r:r--q:"/*mutually exclusive*/ |
1236 | "?3"/*up to 3 args*/ | ||
1218 | ); | 1237 | ); |
1219 | argv += optind; | 1238 | argv += optind; |
1220 | 1239 | ||