Changeset 266
- Timestamp:
- 02/23/99 21:28:05 (14 years ago)
- Location:
- lm-sensors/trunk/prog/detect
- Files:
-
- 2 modified
-
detect.pl (modified) (18 diffs)
-
sensors-detect (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lm-sensors/trunk/prog/detect/detect.pl
r265 r266 78 78 ); 79 79 80 use subs qw(lm78_detect lm78_isa_detect lm75_detect lm80_detect w83781d_detect 80 use subs qw(lm78_detect lm78_isa_detect lm78_alias_detect lm75_detect 81 lm80_detect w83781d_detect w83781d_alias_detect 81 82 w83781d_isa_detect gl518sm_detect gl520sm_detect adm9240_detect 82 83 adm1021_detect); … … 97 98 # this chip. The function should take one parameter: the ISA address 98 99 # to probe. 100 # alias_detect (optional): For chips which can be both on the ISA and the 101 # I2C bus, a function which detectes whether two entries are the same. 102 # The function should take three parameters: The ISA address, the 103 # I2C bus number, and the I2C address. 99 104 @chip_ids = ( 100 105 { … … 105 110 isa_addrs => [0x290], 106 111 isa_detect => sub { lm78_isa_detect 0, @_ }, 112 alias_detect => sub { lm78_alias_detect 0, @_ }, 107 113 } , 108 114 { … … 113 119 isa_addrs => [0x290], 114 120 isa_detect => sub { lm78_isa_detect 1, @_ }, 121 alias_detect => sub { lm78_alias_detect 1, @_ }, 115 122 } , 116 123 { … … 121 128 isa_addrs => [0x290], 122 129 isa_detect => sub { lm78_isa_detect 2, @_ }, 130 alias_detect => sub { lm78_alias_detect 2, @_ }, 123 131 } , 124 132 { … … 141 149 isa_addrs => [0x290], 142 150 isa_detect => sub { w83781d_isa_detect 0, @_ }, 151 alias_detect => sub { w83781d_alias_detect 0, @_ }, 143 152 } , 144 153 { … … 149 158 isa_addrs => [0x290], 150 159 isa_detect => sub { w83781d_isa_detect 1, @_ }, 160 alias_detect => sub { w83781d_alias_detect 1, @_ }, 151 161 } , 152 162 { … … 157 167 isa_addrs => [0x290], 158 168 isa_detect => sub { w83781d_isa_detect 2, @_ }, 169 alias_detect => sub { w83781d_alias_detect 2, @_ }, 159 170 } , 160 171 { … … 639 650 # with field 'algo' containing an algorithm string as appearing 640 651 # in /proc/bus/i2c 652 # with field 'devnr', contianing the /dev/i2c-* number of this 653 # adapter; 641 654 # with field 'driver', containing the driver name for this adapter; 642 655 # with field 'address', containing the I2C address of the detection; … … 659 672 # with field 'algo' containing an algorithm string as appearing 660 673 # in /proc/bus/i2c 674 # with field 'devnr', contianing the /dev/i2c-* number of this 675 # adapter; 661 676 # with field 'driver', containing the driver name for this adapter; 662 677 # with field 'address', containing the I2C address of the detection; … … 728 743 sub add_isa_to_chips_detected 729 744 { 730 my ($ chipdriver,$datahash) = @_;745 my ($alias_detect,$chipdriver,$datahash) = @_; 731 746 my ($detected_ref,$misdetected_ref, $new_detected_ref,$new_misdetected_ref, 732 747 $i,$j,$found_it); … … 740 755 push @chips_detected, { driver => $chipdriver, 741 756 detected => [], 742 misdetected => [] };757 misdetected => [], }; 743 758 } 744 759 $new_detected_ref = $chips_detected[$i]->{detected}; 745 760 $new_misdetected_ref = $chips_detected[$i]->{misdetected}; 746 747 # Now, we are looking for aliases. To be done.748 # If an alias is found, it is removed from the structure, and the data749 # is put in %$datahash. If not, nothing happens750 761 762 # Now, we are looking for aliases. An alias can only be the same chiptype. 763 # If an alias is found in the detected list, it is removed from the 764 # structure, and the data is put in %$datahash. If it is found in the 765 # misdetected list, the entry is modified, and this function aborted. 766 # If it is not found, nothing happens. 767 for ($j = 0; $j < @$new_misdetected_ref; $j++) { 768 if (exists $new_misdetected_ref->[$j]->{address} and 769 not exists $new_misdetected_ref->[$j]->{isa_addr} and 770 defined $alias_detect and 771 $new_misdetected_ref->[$j]->{chip_type} eq $datahash->{chip_type}) { 772 if (&$alias_detect ($datahash->{isa_addr}, 773 $new_misdetected_ref->[$j]->{devnr}, 774 $new_misdetected_ref->[$j]->{address})) { 775 $new_misdetected_ref->[$j] = { %$new_misdetected_ref->[$j], 776 isa_addr => $datahash->{isa_addr}}; 777 return; 778 } 779 } 780 } 781 782 for ($j = 0; $j < @$new_detected_ref; $j++) { 783 if (exists $new_detected_ref->[$j]->{address} and 784 not exists $new_detected_ref->[$j]->{isa_addr} and 785 $new_detected_ref->[$j]->{chip_type} eq $datahash->{chip_type}) { 786 if (&$alias_detect ($datahash->{isa_addr}, 787 $new_detected_ref->[$j]->{devnr}, 788 $new_detected_ref->[$j]->{address})) { 789 $new_detected_ref->[$j]->{isa_addr} = $datahash->{isa_addr}; 790 ($datahash) = splice (@$new_detected_ref, $j, 1); 791 last; 792 } 793 } 794 } 795 751 796 # At long last, we will insert the new reference, looking out whether 752 797 # some other chip has already claimed this ISA address. … … 791 836 printf "Client found at address 0x%02x\n",$addr; 792 837 foreach $chip (@chip_ids) { 793 if ( contains $addr, @{$$chip{i2c_addrs}}) {838 if (exists $$chip{i2c_addrs} and contains $addr, @{$$chip{i2c_addrs}}) { 794 839 print "Probing for $$chip{name}... "; 795 840 if (($conf,@chips) = &{$$chip{i2c_detect}} (\*FILE ,$addr)) { … … 808 853 algorithm => $algorithm_name, 809 854 driver => $adapter_driver, 855 devnr => $adapter_nr, 810 856 }; 811 857 foreach $add_addr(@chips) { … … 818 864 driver => $adapter_driver, 819 865 main => $addr, 866 devnr => $adapter_nr, 820 867 }; 821 868 } … … 840 887 print "Success!\n"; 841 888 printf " (confidence %d, driver `%s')\n", $conf, $$chip{driver}; 842 add_isa_to_chips_detected $$chip{ driver},889 add_isa_to_chips_detected $$chip{alias_detect},$$chip{driver}, 843 890 { confidence => $conf, 844 891 isa_addr => $addr, … … 910 957 ($chip == 2 and ($reg & 0xfe) == 0xc0); 911 958 return 7; 959 } 960 961 962 # $_[0]: Chip to detect (0 = LM78, 1 = LM78-J, 2 = LM79) 963 # $_[1]: ISA address 964 # $_[2]: I2C file handle 965 # $_[3]: I2C address 966 sub lm78_alias_detect 967 { 968 my ($chip,$isa_addr,$file,$i2c_addr) = @_; 969 my $i; 970 my $readproc = sub { isa_read_byte $isa_addr + 5, $isa_addr + 6, @_ }; 971 return 0 unless &$readproc(0x48) == $i2c_addr; 972 for ($i = 0x2b; $i <= 0x3d; $i ++) { 973 return 0 unless &$readproc($i) == i2c_smbus_read_byte_data($i); 974 } 975 return 1; 912 976 } 913 977 … … 996 1060 push @res, (($reg1 & 0x80) >> 4) + 0x48 unless $reg1 & 0x80; 997 1061 return @res; 1062 } 1063 1064 # $_[0]: Chip to detect (0 = W83781D, 1 = W83782D, 3 = W83783S) 1065 # $_[1]: ISA address 1066 # $_[2]: I2C file handle 1067 # $_[3]: I2C address 1068 sub w83781d_alias_detect 1069 { 1070 my ($chip,$isa_addr,$file,$i2c_addr) = @_; 1071 my $i; 1072 my $readproc = sub { isa_read_byte $isa_addr + 5, $isa_addr + 6, @_ }; 1073 return 0 unless &$readproc(0x48) == $i2c_addr; 1074 for ($i = 0x2b; $i <= 0x3d; $i ++) { 1075 return 0 unless &$readproc($i) == i2c_smbus_read_byte_data($i); 1076 } 1077 return 1; 998 1078 } 999 1079 -
lm-sensors/trunk/prog/detect/sensors-detect
r265 r266 78 78 ); 79 79 80 use subs qw(lm78_detect lm78_isa_detect lm75_detect lm80_detect w83781d_detect 80 use subs qw(lm78_detect lm78_isa_detect lm78_alias_detect lm75_detect 81 lm80_detect w83781d_detect w83781d_alias_detect 81 82 w83781d_isa_detect gl518sm_detect gl520sm_detect adm9240_detect 82 83 adm1021_detect); … … 97 98 # this chip. The function should take one parameter: the ISA address 98 99 # to probe. 100 # alias_detect (optional): For chips which can be both on the ISA and the 101 # I2C bus, a function which detectes whether two entries are the same. 102 # The function should take three parameters: The ISA address, the 103 # I2C bus number, and the I2C address. 99 104 @chip_ids = ( 100 105 { … … 105 110 isa_addrs => [0x290], 106 111 isa_detect => sub { lm78_isa_detect 0, @_ }, 112 alias_detect => sub { lm78_alias_detect 0, @_ }, 107 113 } , 108 114 { … … 113 119 isa_addrs => [0x290], 114 120 isa_detect => sub { lm78_isa_detect 1, @_ }, 121 alias_detect => sub { lm78_alias_detect 1, @_ }, 115 122 } , 116 123 { … … 121 128 isa_addrs => [0x290], 122 129 isa_detect => sub { lm78_isa_detect 2, @_ }, 130 alias_detect => sub { lm78_alias_detect 2, @_ }, 123 131 } , 124 132 { … … 141 149 isa_addrs => [0x290], 142 150 isa_detect => sub { w83781d_isa_detect 0, @_ }, 151 alias_detect => sub { w83781d_alias_detect 0, @_ }, 143 152 } , 144 153 { … … 149 158 isa_addrs => [0x290], 150 159 isa_detect => sub { w83781d_isa_detect 1, @_ }, 160 alias_detect => sub { w83781d_alias_detect 1, @_ }, 151 161 } , 152 162 { … … 157 167 isa_addrs => [0x290], 158 168 isa_detect => sub { w83781d_isa_detect 2, @_ }, 169 alias_detect => sub { w83781d_alias_detect 2, @_ }, 159 170 } , 160 171 { … … 639 650 # with field 'algo' containing an algorithm string as appearing 640 651 # in /proc/bus/i2c 652 # with field 'devnr', contianing the /dev/i2c-* number of this 653 # adapter; 641 654 # with field 'driver', containing the driver name for this adapter; 642 655 # with field 'address', containing the I2C address of the detection; … … 659 672 # with field 'algo' containing an algorithm string as appearing 660 673 # in /proc/bus/i2c 674 # with field 'devnr', contianing the /dev/i2c-* number of this 675 # adapter; 661 676 # with field 'driver', containing the driver name for this adapter; 662 677 # with field 'address', containing the I2C address of the detection; … … 728 743 sub add_isa_to_chips_detected 729 744 { 730 my ($ chipdriver,$datahash) = @_;745 my ($alias_detect,$chipdriver,$datahash) = @_; 731 746 my ($detected_ref,$misdetected_ref, $new_detected_ref,$new_misdetected_ref, 732 747 $i,$j,$found_it); … … 740 755 push @chips_detected, { driver => $chipdriver, 741 756 detected => [], 742 misdetected => [] };757 misdetected => [], }; 743 758 } 744 759 $new_detected_ref = $chips_detected[$i]->{detected}; 745 760 $new_misdetected_ref = $chips_detected[$i]->{misdetected}; 746 747 # Now, we are looking for aliases. To be done.748 # If an alias is found, it is removed from the structure, and the data749 # is put in %$datahash. If not, nothing happens750 761 762 # Now, we are looking for aliases. An alias can only be the same chiptype. 763 # If an alias is found in the detected list, it is removed from the 764 # structure, and the data is put in %$datahash. If it is found in the 765 # misdetected list, the entry is modified, and this function aborted. 766 # If it is not found, nothing happens. 767 for ($j = 0; $j < @$new_misdetected_ref; $j++) { 768 if (exists $new_misdetected_ref->[$j]->{address} and 769 not exists $new_misdetected_ref->[$j]->{isa_addr} and 770 defined $alias_detect and 771 $new_misdetected_ref->[$j]->{chip_type} eq $datahash->{chip_type}) { 772 if (&$alias_detect ($datahash->{isa_addr}, 773 $new_misdetected_ref->[$j]->{devnr}, 774 $new_misdetected_ref->[$j]->{address})) { 775 $new_misdetected_ref->[$j] = { %$new_misdetected_ref->[$j], 776 isa_addr => $datahash->{isa_addr}}; 777 return; 778 } 779 } 780 } 781 782 for ($j = 0; $j < @$new_detected_ref; $j++) { 783 if (exists $new_detected_ref->[$j]->{address} and 784 not exists $new_detected_ref->[$j]->{isa_addr} and 785 $new_detected_ref->[$j]->{chip_type} eq $datahash->{chip_type}) { 786 if (&$alias_detect ($datahash->{isa_addr}, 787 $new_detected_ref->[$j]->{devnr}, 788 $new_detected_ref->[$j]->{address})) { 789 $new_detected_ref->[$j]->{isa_addr} = $datahash->{isa_addr}; 790 ($datahash) = splice (@$new_detected_ref, $j, 1); 791 last; 792 } 793 } 794 } 795 751 796 # At long last, we will insert the new reference, looking out whether 752 797 # some other chip has already claimed this ISA address. … … 791 836 printf "Client found at address 0x%02x\n",$addr; 792 837 foreach $chip (@chip_ids) { 793 if ( contains $addr, @{$$chip{i2c_addrs}}) {838 if (exists $$chip{i2c_addrs} and contains $addr, @{$$chip{i2c_addrs}}) { 794 839 print "Probing for $$chip{name}... "; 795 840 if (($conf,@chips) = &{$$chip{i2c_detect}} (\*FILE ,$addr)) { … … 808 853 algorithm => $algorithm_name, 809 854 driver => $adapter_driver, 855 devnr => $adapter_nr, 810 856 }; 811 857 foreach $add_addr(@chips) { … … 818 864 driver => $adapter_driver, 819 865 main => $addr, 866 devnr => $adapter_nr, 820 867 }; 821 868 } … … 840 887 print "Success!\n"; 841 888 printf " (confidence %d, driver `%s')\n", $conf, $$chip{driver}; 842 add_isa_to_chips_detected $$chip{ driver},889 add_isa_to_chips_detected $$chip{alias_detect},$$chip{driver}, 843 890 { confidence => $conf, 844 891 isa_addr => $addr, … … 910 957 ($chip == 2 and ($reg & 0xfe) == 0xc0); 911 958 return 7; 959 } 960 961 962 # $_[0]: Chip to detect (0 = LM78, 1 = LM78-J, 2 = LM79) 963 # $_[1]: ISA address 964 # $_[2]: I2C file handle 965 # $_[3]: I2C address 966 sub lm78_alias_detect 967 { 968 my ($chip,$isa_addr,$file,$i2c_addr) = @_; 969 my $i; 970 my $readproc = sub { isa_read_byte $isa_addr + 5, $isa_addr + 6, @_ }; 971 return 0 unless &$readproc(0x48) == $i2c_addr; 972 for ($i = 0x2b; $i <= 0x3d; $i ++) { 973 return 0 unless &$readproc($i) == i2c_smbus_read_byte_data($i); 974 } 975 return 1; 912 976 } 913 977 … … 996 1060 push @res, (($reg1 & 0x80) >> 4) + 0x48 unless $reg1 & 0x80; 997 1061 return @res; 1062 } 1063 1064 # $_[0]: Chip to detect (0 = W83781D, 1 = W83782D, 3 = W83783S) 1065 # $_[1]: ISA address 1066 # $_[2]: I2C file handle 1067 # $_[3]: I2C address 1068 sub w83781d_alias_detect 1069 { 1070 my ($chip,$isa_addr,$file,$i2c_addr) = @_; 1071 my $i; 1072 my $readproc = sub { isa_read_byte $isa_addr + 5, $isa_addr + 6, @_ }; 1073 return 0 unless &$readproc(0x48) == $i2c_addr; 1074 for ($i = 0x2b; $i <= 0x3d; $i ++) { 1075 return 0 unless &$readproc($i) == i2c_smbus_read_byte_data($i); 1076 } 1077 return 1; 998 1078 } 999 1079
