mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-11-27 20:48:22 +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 "i2c-dev.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
void print_i2c_busses();
|
void print_i2c_busses(int);
|
||||||
|
|
||||||
void help(void)
|
void help(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr,"Syntax: i2cdetect I2CBUS\n");
|
fprintf(stderr,"Syntax: i2cdetect I2CBUS\n");
|
||||||
fprintf(stderr," I2CBUS is an integer\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[])
|
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"))) {
|
if((!strcmp(argv[1], "-v")) || (!strcmp(argv[1], "-V"))) {
|
||||||
fprintf(stderr,"i2cdetect version %s\n", LM_VERSION);
|
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);
|
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
|
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.
|
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;
|
FILE *fptr;
|
||||||
char s[100];
|
char s[100];
|
||||||
@@ -46,9 +49,12 @@ void print_i2c_busses()
|
|||||||
/* look in /proc/bus/i2c */
|
/* look in /proc/bus/i2c */
|
||||||
if((fptr = fopen("/proc/bus/i2c", "r"))) {
|
if((fptr = fopen("/proc/bus/i2c", "r"))) {
|
||||||
while(fgets(s, 100, fptr)) {
|
while(fgets(s, 100, fptr)) {
|
||||||
if(count++ == 0)
|
if(count++ == 0 && !procfmt)
|
||||||
fprintf(stderr," Installed I2C busses:\n");
|
fprintf(stderr," Installed I2C busses:\n");
|
||||||
fprintf(stderr, " %s", s);
|
if(procfmt)
|
||||||
|
printf("%s", s);
|
||||||
|
else
|
||||||
|
fprintf(stderr, " %s", s);
|
||||||
}
|
}
|
||||||
fclose(fptr);
|
fclose(fptr);
|
||||||
goto done;
|
goto done;
|
||||||
@@ -114,24 +120,37 @@ found:
|
|||||||
fclose(f);
|
fclose(f);
|
||||||
if((border = index(x, '\n')) != NULL)
|
if((border = index(x, '\n')) != NULL)
|
||||||
*border = 0;
|
*border = 0;
|
||||||
if(count++ == 0)
|
if(count++ == 0 && !procfmt)
|
||||||
fprintf(stderr," Installed I2C busses:\n");
|
fprintf(stderr," Installed I2C busses:\n");
|
||||||
/* match 2.4 /proc/bus/i2c format as closely as possible */
|
/* match 2.4 /proc/bus/i2c format as closely as possible */
|
||||||
if(!strncmp(x, "ISA ", 4))
|
if(!strncmp(x, "ISA ", 4)) {
|
||||||
fprintf(stderr, " %s\t%-10s\t%-32s\t%s\n", de->d_name,
|
if(procfmt)
|
||||||
"dummy", x, "ISA bus algorithm");
|
printf("%s\t%-10s\t%-32s\t%s\n", de->d_name,
|
||||||
else if(!sscanf(de->d_name, "i2c-%d", &tmp))
|
"dummy", x, "ISA bus algorithm");
|
||||||
fprintf(stderr, " %s\t%-10s\t%-32s\t%s\n", de->d_name,
|
else
|
||||||
"dummy", x, "Dummy bus algorithm");
|
fprintf(stderr, " %s\t%-10s\t%-32s\t%s\n", de->d_name,
|
||||||
else
|
"dummy", x, "ISA bus algorithm");
|
||||||
fprintf(stderr, " %s\t%-10s\t%-32s\t%s\n", de->d_name,
|
} else if(!sscanf(de->d_name, "i2c-%d", &tmp)) {
|
||||||
"unknown", x, "Algorithm unavailable");
|
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);
|
closedir(dir);
|
||||||
|
|
||||||
done:
|
done:
|
||||||
if(count == 0)
|
if(count == 0 && !procfmt)
|
||||||
fprintf(stderr,"Error: No I2C busses found!\n"
|
fprintf(stderr,"Error: No I2C busses found!\n"
|
||||||
"Be sure you have done 'modprobe i2c-dev'\n"
|
"Be sure you have done 'modprobe i2c-dev'\n"
|
||||||
"and also modprobed your i2c bus drivers\n");
|
"and also modprobed your i2c bus drivers\n");
|
||||||
|
|||||||
+2
-2
@@ -42,7 +42,7 @@
|
|||||||
#define HAVE_PEC 1
|
#define HAVE_PEC 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void print_i2c_busses();
|
void print_i2c_busses(int);
|
||||||
|
|
||||||
void help(void)
|
void help(void)
|
||||||
{
|
{
|
||||||
@@ -54,7 +54,7 @@ void help(void)
|
|||||||
fprintf(stderr," ADDRESS is an integer 0x00 - 0x7f\n");
|
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 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");
|
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[])
|
int main(int argc, char *argv[])
|
||||||
|
|||||||
+2
-2
@@ -27,7 +27,7 @@
|
|||||||
#include "i2c-dev.h"
|
#include "i2c-dev.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
void print_i2c_busses();
|
void print_i2c_busses(int);
|
||||||
void help(void) __attribute__ ((noreturn));
|
void help(void) __attribute__ ((noreturn));
|
||||||
|
|
||||||
void help(void)
|
void help(void)
|
||||||
@@ -35,7 +35,7 @@ void help(void)
|
|||||||
fprintf(stderr,"Syntax: i2cset I2CBUS CHIP-ADDRESS DATA-ADDRESS VALUE [MODE]\n");
|
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," MODE is 'b[yte]' or 'w[ord]' (default b)\n");
|
||||||
fprintf(stderr," I2CBUS is an integer\n");
|
fprintf(stderr," I2CBUS is an integer\n");
|
||||||
print_i2c_busses();
|
print_i2c_busses(0);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user