mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-10-19 11:19:31 +00:00
add -l option to i2cdetect so 'i2cdetect -l'
can be used as a replacement for 'cat /proc/bus/i2c' git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@2100 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
1 parent
0872117cb9
commit
82caa7986f
4 files changed
+46
-21
No files matched your search
@@ -28,13 +28,14 @@
|
||||
#include "i2c-dev.h"
|
||||
#include "version.h"
|
||||
|
||||
void print_i2c_busses();
|
||||
void print_i2c_busses(int);
|
||||
|
||||
void help(void)
|
||||
{
|
||||
fprintf(stderr,"Syntax: i2cdetect I2CBUS\n");
|
||||
fprintf(stderr," I2CBUS is an integer\n");
|
||||
print_i2c_busses();
|
||||
fprintf(stderr," i2cdetect -l lists installed busses only\n");
|
||||
print_i2c_busses(0);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
@@ -57,7 +58,12 @@ int main(int argc, char *argv[])
|
||||
|
||||
if((!strcmp(argv[1], "-v")) || (!strcmp(argv[1], "-V"))) {
|
||||
fprintf(stderr,"i2cdetect version %s\n", LM_VERSION);
|
||||
exit(1);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if(!strcmp(argv[1], "-l")) {
|
||||
print_i2c_busses(1);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
i2cbus = strtol(argv[1],&end,0);
|
||||
|
||||
+33
-14
@@ -28,8 +28,11 @@
|
||||
/*
|
||||
this just prints out the installed i2c busses in a consistent format, whether
|
||||
on a 2.4 kernel using /proc or a 2.6 kernel using /sys.
|
||||
If procfmt == 1, print out exactly /proc/bus/i2c format on stdout.
|
||||
This allows this to be used in a program to emulate /proc/bus/i2c on a
|
||||
sysfs system.
|
||||
*/
|
||||
void print_i2c_busses()
|
||||
void print_i2c_busses(int procfmt)
|
||||
{
|
||||
FILE *fptr;
|
||||
char s[100];
|
||||
@@ -46,9 +49,12 @@ void print_i2c_busses()
|
||||
/* look in /proc/bus/i2c */
|
||||
if((fptr = fopen("/proc/bus/i2c", "r"))) {
|
||||
while(fgets(s, 100, fptr)) {
|
||||
if(count++ == 0)
|
||||
if(count++ == 0 && !procfmt)
|
||||
fprintf(stderr," Installed I2C busses:\n");
|
||||
fprintf(stderr, " %s", s);
|
||||
if(procfmt)
|
||||
printf("%s", s);
|
||||
else
|
||||
fprintf(stderr, " %s", s);
|
||||
}
|
||||
fclose(fptr);
|
||||
goto done;
|
||||
@@ -114,24 +120,37 @@ found:
|
||||
fclose(f);
|
||||
if((border = index(x, '\n')) != NULL)
|
||||
*border = 0;
|
||||
if(count++ == 0)
|
||||
if(count++ == 0 && !procfmt)
|
||||
fprintf(stderr," Installed I2C busses:\n");
|
||||
/* match 2.4 /proc/bus/i2c format as closely as possible */
|
||||
if(!strncmp(x, "ISA ", 4))
|
||||
fprintf(stderr, " %s\t%-10s\t%-32s\t%s\n", de->d_name,
|
||||
"dummy", x, "ISA bus algorithm");
|
||||
else if(!sscanf(de->d_name, "i2c-%d", &tmp))
|
||||
fprintf(stderr, " %s\t%-10s\t%-32s\t%s\n", de->d_name,
|
||||
"dummy", x, "Dummy bus algorithm");
|
||||
else
|
||||
fprintf(stderr, " %s\t%-10s\t%-32s\t%s\n", de->d_name,
|
||||
"unknown", x, "Algorithm unavailable");
|
||||
if(!strncmp(x, "ISA ", 4)) {
|
||||
if(procfmt)
|
||||
printf("%s\t%-10s\t%-32s\t%s\n", de->d_name,
|
||||
"dummy", x, "ISA bus algorithm");
|
||||
else
|
||||
fprintf(stderr, " %s\t%-10s\t%-32s\t%s\n", de->d_name,
|
||||
"dummy", x, "ISA bus algorithm");
|
||||
} else if(!sscanf(de->d_name, "i2c-%d", &tmp)) {
|
||||
if(procfmt)
|
||||
printf("%s\t%-10s\t%-32s\t%s\n", de->d_name,
|
||||
"dummy", x, "Dummy bus algorithm");
|
||||
else
|
||||
fprintf(stderr, " %s\t%-10s\t%-32s\t%s\n", de->d_name,
|
||||
"dummy", x, "Dummy bus algorithm");
|
||||
} else {
|
||||
if(procfmt)
|
||||
printf("%s\t%-10s\t%-32s\t%s\n", de->d_name,
|
||||
"unknown", x, "Algorithm unavailable");
|
||||
else
|
||||
fprintf(stderr, " %s\t%-10s\t%-32s\t%s\n", de->d_name,
|
||||
"unknown", x, "Algorithm unavailable");
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
|
||||
done:
|
||||
if(count == 0)
|
||||
if(count == 0 && !procfmt)
|
||||
fprintf(stderr,"Error: No I2C busses found!\n"
|
||||
"Be sure you have done 'modprobe i2c-dev'\n"
|
||||
"and also modprobed your i2c bus drivers\n");
|
||||
|
||||
+2
-2
@@ -42,7 +42,7 @@
|
||||
#define HAVE_PEC 1
|
||||
#endif
|
||||
|
||||
void print_i2c_busses();
|
||||
void print_i2c_busses(int);
|
||||
|
||||
void help(void)
|
||||
{
|
||||
@@ -54,7 +54,7 @@ void help(void)
|
||||
fprintf(stderr," ADDRESS is an integer 0x00 - 0x7f\n");
|
||||
fprintf(stderr," BANK and BANKREG are for byte and word accesses (default bank 0, reg 0x4e)\n");
|
||||
fprintf(stderr," BANK is the command for smbusblock accesses (default 0)\n");
|
||||
print_i2c_busses();
|
||||
print_i2c_busses(0);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
||||
+2
-2
@@ -27,7 +27,7 @@
|
||||
#include "i2c-dev.h"
|
||||
#include "version.h"
|
||||
|
||||
void print_i2c_busses();
|
||||
void print_i2c_busses(int);
|
||||
void help(void) __attribute__ ((noreturn));
|
||||
|
||||
void help(void)
|
||||
@@ -35,7 +35,7 @@ void help(void)
|
||||
fprintf(stderr,"Syntax: i2cset I2CBUS CHIP-ADDRESS DATA-ADDRESS VALUE [MODE]\n");
|
||||
fprintf(stderr," MODE is 'b[yte]' or 'w[ord]' (default b)\n");
|
||||
fprintf(stderr," I2CBUS is an integer\n");
|
||||
print_i2c_busses();
|
||||
print_i2c_busses(0);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user