From 93f3a9f7acc9964447057417a22f5ba49f67d95b Mon Sep 17 00:00:00 2001 From: Frodo Looijaard Date: Sun, 2 Jul 2000 18:11:31 +0000 Subject: [PATCH] All tools now understand both /dev/i2c-* and /dev/i2c* git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@827 7894878c-1315-0410-8ee3-d5d059ff63e0 --- prog/detect/i2cdetect.c | 21 +++++++++++++++------ prog/detect/sensors-detect | 21 ++++++++++++--------- prog/dump/i2cdump.c | 21 +++++++++++++++------ 3 files changed, 42 insertions(+), 21 deletions(-) diff --git a/prog/detect/i2cdetect.c b/prog/detect/i2cdetect.c index 4ad873f1..5de5f49c 100644 --- a/prog/detect/i2cdetect.c +++ b/prog/detect/i2cdetect.c @@ -45,7 +45,9 @@ int main(int argc, char *argv[]) { char *end; int i,j,res,i2cbus,file; - char filename[20]; + char filename1[20]; + char filename2[20]; + char *filename; long funcs; @@ -66,11 +68,18 @@ int main(int argc, char *argv[]) help(); } - sprintf(filename,"/dev/i2c-%d",i2cbus); - if ((file = open(filename,O_RDWR)) < 0) { - fprintf(stderr,"Error: Could not open file `%s': %s\n",filename, - strerror(errno)); - exit(1); + sprintf(filename1,"/dev/i2c-%d",i2cbus); + sprintf(filename2,"/dev/i2c%d",i2cbus); + if ((file = open(filename1,O_RDWR)) < 0) { + if ((file = open(filename2,O_RDWR)) < 0) { + fprintf(stderr,"Error: Could not open file `%s' or `%s': %s\n",filename1, + filename2,strerror(errno)); + exit(1); + } else { + filename = filename2; + } + } else { + filename = filename1; } if (ioctl(file,I2C_FUNCS,&funcs) < 0) { diff --git a/prog/detect/sensors-detect b/prog/detect/sensors-detect index ec51d66f..2163fa7e 100755 --- a/prog/detect/sensors-detect +++ b/prog/detect/sensors-detect @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/perl -w # # sensors-detect - Detect PCI bus and chips @@ -1117,12 +1117,13 @@ sub add_isa_to_chips_detected defined $alias_detect and $new_misdetected_ref->[$i]->{chipname} eq $datahash->{chipname}) { open FILE,"/dev/i2c-$new_misdetected_ref->[$i]->{i2c_devnr}" or + open FILE,"/dev/i2c$new_misdetected_ref->[$i]->{i2c_devnr}" or print("Can't open ", - "/dev/i2c-$new_misdetected_ref->[$i]->{i2c_devnr}?!?\n"), + "/dev/i2c[-]$new_misdetected_ref->[$i]->{i2c_devnr}?!?\n"), next; i2c_set_slave_addr \*FILE,$new_misdetected_ref->[$i]->{i2c_addr} or print("Can't set I2C address for ", - "/dev/i2c-$new_misdetected_ref->[$i]->{i2c_devnr}?!?\n"), + "/dev/i2c[-]$new_misdetected_ref->[$i]->{i2c_devnr}?!?\n"), next; if (&$alias_detect ($datahash->{isa_addr},\*FILE, $new_misdetected_ref->[$i]->{i2c_addr})) { @@ -1143,12 +1144,13 @@ sub add_isa_to_chips_detected defined $alias_detect and $new_detected_ref->[$i]->{chipname} eq $datahash->{chipname}) { open FILE,"/dev/i2c-$new_detected_ref->[$i]->{i2c_devnr}" or + open FILE,"/dev/i2c$new_detected_ref->[$i]->{i2c_devnr}" or print("Can't open ", - "/dev/i2c-$new_detected_ref->[$i]->{i2c_devnr}?!?\n"), + "/dev/i2c[-]$new_detected_ref->[$i]->{i2c_devnr}?!?\n"), next; i2c_set_slave_addr \*FILE,$new_detected_ref->[$i]->{i2c_addr} or print("Can't set I2C address for ", - "/dev/i2c-$new_detected_ref->[$i]->{i2c_devnr}?!?\n"), + "/dev/i2c[-]$new_detected_ref->[$i]->{i2c_devnr}?!?\n"), next; if (&$alias_detect ($datahash->{isa_addr},\*FILE, $new_detected_ref->[$i]->{i2c_addr})) { @@ -1213,7 +1215,8 @@ sub scan_adapter my @not_to_scan = @$not_to_scan; open FILE,"/dev/i2c-$adapter_nr" or - (print "Can't open /dev/i2c-$adapter_nr ($!)\n"), return; + open FILE,"/dev/i2c$adapter_nr" or + (print "Can't open /dev/i2c[-]$adapter_nr ($!)\n"), return; # Now scan each address in turn foreach $addr (0..0x7f) { @@ -2024,7 +2027,7 @@ sub main "Read\n", " doc/modules for more information.\n"; print " Also, you need to be `root', or at least have access to the ", - "/dev/i2c-* files\n", + "/dev/i2c[-]* files\n", " for some things. You can use prog/mkdev/mkdev.sh to create these ", "/dev files\n", " if you do not have them already.\n"; @@ -2097,7 +2100,7 @@ sub main "you edited\n", " `/etc/conf.modules' (or `/etc/modules.conf') for automatic ", "loading of\n", - " this module. If not, you won't be able to open any /dev/i2c-* ", + " this module. If not, you won't be able to open any /dev/i2c[-]* ", "file.\n"; } else { print " i2c-dev is not loaded. Do you want to load it now? (YES/no): "; @@ -2106,7 +2109,7 @@ sub main "`/etc/conf.modules'\n", " (or `/etc/modules.conf') for automatic loading of this ", "module. If not,\n", - " you won't be able to open any /dev/i2c-* file (unless you", + " you won't be able to open any /dev/i2c[-]* file (unless you", "have it built-in\n", " into your kernel)\n"; } elsif (system "modprobe","i2c-dev") { diff --git a/prog/dump/i2cdump.c b/prog/dump/i2cdump.c index 2d67b718..2b4a5f0d 100644 --- a/prog/dump/i2cdump.c +++ b/prog/dump/i2cdump.c @@ -46,7 +46,9 @@ int main(int argc, char *argv[]) char *end; int i,j,res,i2cbus,address,size,file; int bank = 0, bankreg = 0x4E; - char filename[20]; + char filename1[20]; + char filename2[20]; + char *filename; if (argc < 2) { @@ -123,11 +125,18 @@ int main(int argc, char *argv[]) } } - sprintf(filename,"/dev/i2c-%d",i2cbus); - if ((file = open(filename,O_RDWR)) < 0) { - fprintf(stderr,"Error: Could not open file `%s': %s\n",filename, - strerror(errno)); - exit(1); + sprintf(filename1,"/dev/i2c-%d",i2cbus); + sprintf(filename2,"/dev/i2c-%d",i2cbus); + if ((file = open(filename1,O_RDWR)) < 0) { + if ((file = open(filename1,O_RDWR)) < 0) { + fprintf(stderr,"Error: Could not open file `%s' or `%s': %s\n",filename1, + filename2,strerror(errno)); + exit(1); + } else { + filename = filename2; + } + } else { + filename = filename1; } /* use FORCE so that we can look at registers even when