Changeset 5267
- Timestamp:
- 05/28/08 11:32:41 (6 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
lm-sensors/branches/lm-sensors-3.0.0/prog/detect/sensors-detect
r5266 r5267 2167 2167 sub initialize_ioports 2168 2168 { 2169 sysopen (IOPORTS, "/dev/port", O_RDWR)2169 sysopen(IOPORTS, "/dev/port", O_RDWR) 2170 2170 or die "/dev/port: $!\n"; 2171 binmode IOPORTS;2171 binmode(IOPORTS); 2172 2172 } 2173 2173 2174 2174 sub close_ioports 2175 2175 { 2176 close (IOPORTS)2176 close(IOPORTS) 2177 2177 or print "Warning: $!\n"; 2178 2178 } … … 2183 2183 { 2184 2184 my ($res, $nrchars); 2185 sysseek IOPORTS, $_[0], 0or return -1;2186 $nrchars = sysread IOPORTS, $res, 1;2185 sysseek(IOPORTS, $_[0], 0) or return -1; 2186 $nrchars = sysread(IOPORTS, $res, 1); 2187 2187 return -1 if not defined $nrchars or $nrchars != 1; 2188 $res = unpack "C", $res;2188 $res = unpack("C", $res); 2189 2189 return $res; 2190 2190 } … … 2195 2195 sub outb 2196 2196 { 2197 my $towrite = pack "C", $_[1];2198 sysseek IOPORTS, $_[0], 0or return -1;2199 my $nrchars = syswrite IOPORTS, $towrite, 1;2197 my $towrite = pack("C", $_[1]); 2198 sysseek(IOPORTS, $_[0], 0) or return -1; 2199 my $nrchars = syswrite(IOPORTS, $towrite, 1); 2200 2200 return -1 if not defined $nrchars or $nrchars != 1; 2201 2201 return 0; … … 2208 2208 sub isa_read_byte 2209 2209 { 2210 outb $_[0], $_[2];2211 return inb $_[1];2210 outb($_[0], $_[2]); 2211 return inb($_[1]); 2212 2212 } 2213 2213 … … 2219 2219 sub isa_write_byte 2220 2220 { 2221 outb $_[0], $_[2];2222 outb $_[1], $_[3];2221 outb($_[0], $_[2]); 2222 outb($_[1], $_[3]); 2223 2223 } 2224 2224 … … 2243 2243 } 2244 2244 } 2245 close INPUTFILE;2245 close(INPUTFILE); 2246 2246 2247 2247 my $use_udev = 0; … … 2256 2256 } 2257 2257 } 2258 close INPUTFILE;2258 close(INPUTFILE); 2259 2259 } 2260 2260 … … 2342 2342 } 2343 2343 push @cpu, $entry if scalar keys(%{$entry}); # Last entry 2344 close INPUTFILE;2344 close(INPUTFILE); 2345 2345 } 2346 2346 … … 2525 2525 sub adapter_pci_detection_sis_96x 2526 2526 { 2527 my $driver ="";2527 my $driver = ""; 2528 2528 2529 2529 # first, determine which driver if any... … … 2676 2676 { 2677 2677 my $file = shift; 2678 my $funcs = pack "L", 0; # Allocate space2679 2680 ioctl $file, IOCTL_I2C_FUNCS, $funcsor return -1;2681 $funcs = unpack "L", $funcs;2678 my $funcs = pack("L", 0); # Allocate space 2679 2680 ioctl($file, IOCTL_I2C_FUNCS, $funcs) or return -1; 2681 $funcs = unpack("L", $funcs); 2682 2682 2683 2683 return $funcs; … … 2696 2696 2697 2697 $addr += 0; # Make sure it's a number not a string 2698 ioctl $file, IOCTL_I2C_SLAVE, $addror return 0;2698 ioctl($file, IOCTL_I2C_SLAVE, $addr) or return 0; 2699 2699 return 1; 2700 2700 } … … 2716 2716 { 2717 2717 my ($file, $read_write, $command, $size, $data) = @_; 2718 my $data_array = pack "C32", @$data;2719 my $ioctl_data = pack "C2x2Ip", ($read_write, $command, $size, $data_array);2720 ioctl $file, IOCTL_I2C_SMBUS, $ioctl_dataor return 0;2721 @{$_[4]} = unpack "C32", $data_array;2718 my $data_array = pack("C32", @$data); 2719 my $ioctl_data = pack("C2x2Ip", $read_write, $command, $size, $data_array); 2720 ioctl($file, IOCTL_I2C_SMBUS, $ioctl_data) or return 0; 2721 @{$_[4]} = unpack("C32", $data_array); 2722 2722 return 1; 2723 2723 } … … 2730 2730 my ($file, $value) = @_; 2731 2731 my @data; 2732 i2c_smbus_access $file, $value, 0, SMBUS_QUICK, \@data2732 i2c_smbus_access($file, $value, 0, SMBUS_QUICK, \@data) 2733 2733 or return -1; 2734 2734 return 0; … … 2741 2741 my ($file) = @_; 2742 2742 my @data; 2743 i2c_smbus_access $file, SMBUS_READ, 0, SMBUS_BYTE, \@data2743 i2c_smbus_access($file, SMBUS_READ, 0, SMBUS_BYTE, \@data) 2744 2744 or return -1; 2745 2745 return $data[0]; … … 2759 2759 return $i2c_byte_cache[$command]; 2760 2760 } 2761 i2c_smbus_access $file, SMBUS_READ, $command, SMBUS_BYTE_DATA, \@data2761 i2c_smbus_access($file, SMBUS_READ, $command, SMBUS_BYTE_DATA, \@data) 2762 2762 or return -1; 2763 2763 return ($i2c_byte_cache[$command] = $data[0]); … … 2777 2777 my ($file, $command) = @_; 2778 2778 my @data; 2779 i2c_smbus_access $file, SMBUS_READ, $command, SMBUS_WORD_DATA, \@data2779 i2c_smbus_access($file, SMBUS_READ, $command, SMBUS_WORD_DATA, \@data) 2780 2780 or return -1; 2781 2781 return $data[0] + 256 * $data[1]; … … 2920 2920 if exists $detected_entry->{i2c_sub_addrs}; 2921 2921 if ($detected_entry->{i2c_devnr} == $datahash->{i2c_devnr} and 2922 any_list_match \@entry_addrs, \@hash_addrs) {2922 any_list_match(\@entry_addrs, \@hash_addrs)) { 2923 2923 if ($detected_entry->{conf} >= $datahash->{conf}) { 2924 2924 $put_in_detected = 0; … … 2952 2952 if exists $detected_ref->[$i]->{i2c_sub_addrs}; 2953 2953 if ($detected_ref->[$i]->{i2c_devnr} == $datahash->{i2c_devnr} and 2954 any_list_match \@entry_addrs, \@hash_addrs) {2954 any_list_match(\@entry_addrs, \@hash_addrs)) { 2955 2955 push @$misdetected_ref, $detected_ref->[$i] 2956 2956 unless $chipdriver eq $main_entry->{driver}; … … 2982 2982 2983 2983 # First determine where the hash has to be added. 2984 $isalias =0;2984 $isalias = 0; 2985 2985 for ($i = 0; $i < @chips_detected; $i++) { 2986 2986 last if ($chips_detected[$i]->{driver} eq $chipdriver); … … 3009 3009 print("Can't open $dev_i2c$new_misdetected_ref->[$i]->{i2c_devnr}?!?\n"), 3010 3010 next; 3011 binmode FILE;3012 i2c_set_slave_addr \*FILE, $new_misdetected_ref->[$i]->{i2c_addr}or3011 binmode(FILE); 3012 i2c_set_slave_addr(\*FILE, $new_misdetected_ref->[$i]->{i2c_addr}) or 3013 3013 print("Can't set I2C address for ", 3014 3014 "$dev_i2c$new_misdetected_ref->[$i]->{i2c_devnr}?!?\n"), … … 3031 3031 print("Can't open $dev_i2c$new_detected_ref->[$i]->{i2c_devnr}?!?\n"), 3032 3032 next; 3033 binmode FILE;3034 i2c_set_slave_addr \*FILE, $new_detected_ref->[$i]->{i2c_addr}or3033 binmode(FILE); 3034 i2c_set_slave_addr(\*FILE, $new_detected_ref->[$i]->{i2c_addr}) or 3035 3035 print("Can't set I2C address for ", 3036 3036 "$dev_i2c$new_detected_ref->[$i]->{i2c_devnr}?!?\n"), … … 3040 3040 $new_detected_ref->[$i]->{isa_addr} = $datahash->{isa_addr}; 3041 3041 ($datahash) = splice (@$new_detected_ref, $i, 1); 3042 $isalias =1;3042 $isalias = 1; 3043 3043 last; 3044 3044 } … … 3123 3123 open(local *FILE, "$dev_i2c$adapter_nr") or 3124 3124 (print "Can't open $dev_i2c$adapter_nr\n"), return; 3125 binmode FILE;3125 binmode(FILE); 3126 3126 3127 3127 # Can we probe this adapter? … … 3198 3198 $| = 1; 3199 3199 foreach $chip (@chip_ids) { 3200 if (exists $chip->{i2c_addrs} and contains $addr, @{$chip->{i2c_addrs}}) {3200 if (exists $chip->{i2c_addrs} and contains($addr, @{$chip->{i2c_addrs}})) { 3201 3201 printf("\%-60s", sprintf("Probing for `\%s'... ", $chip->{name})); 3202 3202 if (($conf, @chips) = &{$chip->{i2c_detect}} (\*FILE, $addr)) { … … 3231 3231 $new_hash->{i2c_sub_addrs} = \@chips_copy; 3232 3232 } 3233 add_i2c_to_chips_detected $chip->{driver}, $new_hash;3233 add_i2c_to_chips_detected($chip->{driver}, $new_hash); 3234 3234 } else { 3235 3235 print "No\n"; … … 3258 3258 chipname => $chip->{name} 3259 3259 }; 3260 $new_hash = add_isa_to_chips_detected $chip->{alias_detect}, $chip->{driver},3261 $new_hash ;3260 $new_hash = add_isa_to_chips_detected($chip->{alias_detect}, $chip->{driver}, 3261 $new_hash); 3262 3262 if ($new_hash) { 3263 3263 printf " Alias of the chip on I2C bus `%s', address 0x%04x\n", … … 3378 3378 chipname => $chip->{name} 3379 3379 }; 3380 add_isa_to_chips_detected $chip->{alias_detect}, $chip->{driver},3381 $new_hash ;3380 add_isa_to_chips_detected($chip->{alias_detect}, $chip->{driver}, 3381 $new_hash); 3382 3382 } 3383 3383 … … 3536 3536 { 3537 3537 my ($file, $addr) = @_; 3538 return if (i2c_smbus_read_byte_data($file, 0x58)) != 0xac;3538 return if i2c_smbus_read_byte_data($file, 0x58) != 0xac; 3539 3539 return (8); 3540 3540 } … … 3568 3568 { 3569 3569 my ($chip, $addr) = @_; 3570 my $val = inb ($addr + 1);3571 return if inb ($addr + 2) != $val or inb($addr + 3) != $val or3572 inb ($addr + 7) != $val;3570 my $val = inb($addr + 1); 3571 return if inb($addr + 2) != $val or inb($addr + 3) != $val or 3572 inb($addr + 7) != $val; 3573 3573 3574 3574 $val = inb($addr + 5); 3575 3575 outb($addr + 5, ~$val & 0x7f); 3576 if ((inb ($addr+5) & 0x7f) != (~ $val & 0x7f)) {3576 if ((inb($addr+5) & 0x7f) != (~ $val & 0x7f)) { 3577 3577 outb($addr+5, $val); 3578 3578 return; 3579 3579 } 3580 my $readproc = sub { isa_read_byte $addr + 5, $addr + 6, @_};3580 my $readproc = sub { isa_read_byte($addr + 5, $addr + 6, @_) }; 3581 3581 return unless (&$readproc(0x40) & 0x80) == 0x00; 3582 3582 my $reg = &$readproc(0x49); … … 3605 3605 my ($chip, $isa_addr, $file, $i2c_addr) = @_; 3606 3606 my $i; 3607 my $readproc = sub { isa_read_byte $isa_addr + 5, $isa_addr + 6, @_};3607 my $readproc = sub { isa_read_byte($isa_addr + 5, $isa_addr + 6, @_) }; 3608 3608 return 0 unless &$readproc(0x48) == $i2c_addr; 3609 3609 for ($i = 0x2b; $i <= 0x3d; $i ++) { … … 4447 4447 { 4448 4448 my ($file, $addr) = @_; 4449 return if (i2c_smbus_read_byte_data($file, 0x3e)) != 0x02;4449 return if i2c_smbus_read_byte_data($file, 0x3e) != 0x02; 4450 4450 return if (i2c_smbus_read_byte_data($file, 0x3f) & 0xfc) != 0x04; 4451 4451 return (7); … … 4620 4620 my ($chip, $isa_addr, $file, $i2c_addr) = @_; 4621 4621 my $i; 4622 my $readproc = sub { isa_read_byte $isa_addr + 5, $isa_addr + 6, @_};4622 my $readproc = sub { isa_read_byte($isa_addr + 5, $isa_addr + 6, @_) }; 4623 4623 return 0 unless &$readproc(0x48) == $i2c_addr; 4624 4624 for ($i = 0x2b; $i <= 0x3d; $i ++) { … … 4635 4635 my ($chip, $addr) = @_; 4636 4636 my ($reg1, $reg2); 4637 my $val = inb ($addr + 1);4638 return if inb ($addr + 2) != $val or inb($addr + 3) != $val or4639 inb ($addr + 7) != $val;4637 my $val = inb($addr + 1); 4638 return if inb($addr + 2) != $val or inb($addr + 3) != $val or 4639 inb($addr + 7) != $val; 4640 4640 4641 4641 $val = inb($addr + 5); 4642 4642 outb($addr+5, ~$val & 0x7f); 4643 if ((inb ($addr+5) & 0x7f) != (~ $val & 0x7f)) {4643 if ((inb($addr+5) & 0x7f) != (~ $val & 0x7f)) { 4644 4644 outb($addr+5, $val); 4645 4645 return; 4646 4646 } 4647 4647 4648 my $read_proc = sub { isa_read_byte $addr + 5, $addr + 6, @_};4648 my $read_proc = sub { isa_read_byte($addr + 5, $addr + 6, @_) }; 4649 4649 $reg1 = &$read_proc(0x4e); 4650 4650 $reg2 = &$read_proc(0x4f); … … 4896 4896 # Low limits over high limits 4897 4897 if ($chip != 5) { # LM84 doesn't have low limits 4898 $llo -=256 if ($llo & 0x80);4899 $rlo -=256 if ($rlo & 0x80);4898 $llo -= 256 if ($llo & 0x80); 4899 $rlo -= 256 if ($rlo & 0x80); 4900 4900 return if ($llo > $lhi) or ($rlo > $rhi); 4901 4901 } … … 5008 5008 my ($chip, $isa_addr, $file, $i2c_addr) = @_; 5009 5009 my $i; 5010 my $readproc = sub { isa_read_byte $isa_addr + 5, $isa_addr + 6, @_};5010 my $readproc = sub { isa_read_byte($isa_addr + 5, $isa_addr + 6, @_) }; 5011 5011 return 0 unless &$readproc(0x48) == $i2c_addr; 5012 5012 for ($i = 0x30; $i <= 0x45; $i++) { … … 5346 5346 sub ipmi_kcs_detect 5347 5347 { 5348 return if inb (0x0ca3) == 0xff;5348 return if inb(0x0ca3) == 0xff; 5349 5349 return (4); 5350 5350 } … … 5352 5352 sub ipmi_smic_detect 5353 5353 { 5354 return if inb (0x0cab) == 0xff;5354 return if inb(0x0cab) == 0xff; 5355 5355 return (4); 5356 5356 } … … 5642 5642 } 5643 5643 if (exists $detection->{isa_addr}) { 5644 $isa =1;5644 $isa = 1; 5645 5645 } 5646 5646 if ($chip->{driver} eq "bmcsensors" || … … 5693 5693 } 5694 5694 } 5695 close INPUTFILE;5695 close(INPUTFILE); 5696 5696 #check return value from modprobe in case modprobe -l isn't supported 5697 5697 if ((($? >> 8) == 0) && ! $modulefound) { … … 5727 5727 $configfile = "# hwmon module options\n" unless defined $configfile; 5728 5728 $configfile .= "options $chip->{driver}"; 5729 $configfile .= sprintf " ignore=%d,0x%02x", shift @optionlist,5730 shift @optionlist 5729 $configfile .= sprintf(" ignore=%d,0x%02x", shift @optionlist, 5730 shift @optionlist) 5731 5731 if @optionlist; 5732 $configfile .= sprintf ",%d,0x%02x", shift @optionlist, shift @optionlist5732 $configfile .= sprintf(",%d,0x%02x", shift @optionlist, shift @optionlist) 5733 5733 while @optionlist; 5734 $configfile .= sprintf " probe=%d,0x%02x", shift @probelist,5735 shift @probelist 5734 $configfile .= sprintf(" probe=%d,0x%02x", shift @probelist, 5735 shift @probelist) 5736 5736 if @probelist; 5737 $configfile .= sprintf ",%d,0x%02x", shift @probelist, shift @probelist5737 $configfile .= sprintf(",%d,0x%02x", shift @probelist, shift @probelist) 5738 5738 while @probelist; 5739 5739 $configfile .= "\n"; … … 5760 5760 5761 5761 initialize_kernel_version(); 5762 initialize_conf ;5763 initialize_proc_pci ;5764 initialize_modules_list ;5762 initialize_conf(); 5763 initialize_proc_pci(); 5764 initialize_modules_list(); 5765 5765 # make sure any special case chips are added to the chip_ids list before 5766 5766 # making the support modules list 5767 5767 chip_special_cases(); 5768 initialize_modules_supported ;5768 initialize_modules_supported(); 5769 5769 initialize_cpu_list(); 5770 5770 … … 5782 5782 print "We can start with probing for (PCI) I2C or SMBus adapters.\n"; 5783 5783 print "Do you want to probe now? (YES/no): "; 5784 @adapters = adapter_pci_detection 5784 @adapters = adapter_pci_detection() 5785 5785 if ($did_adapter_detection = not <STDIN> =~ /\s*[Nn]/); 5786 5786 print "\n"; … … 5798 5798 print "Load `$adapter' (say NO if built into your kernel)? (YES/no): "; 5799 5799 unless (<STDIN> =~ /^\s*[Nn]/) { 5800 if (system ("modprobe", $adapter)) {5800 if (system("modprobe", $adapter)) { 5801 5801 print "Loading failed... skipping.\n"; 5802 5802 } else { … … 5820 5820 if (<STDIN> =~ /^\s*n/i) { 5821 5821 print "Well, you will know best.\n"; 5822 } elsif (system "modprobe", "i2c-dev") {5822 } elsif (system("modprobe", "i2c-dev")) { 5823 5823 print "Loading failed, expect problems later on.\n"; 5824 5824 } else { … … 5853 5853 "Addresses: "; 5854 5854 $inp2 = <STDIN>; 5855 chop $inp2;5855 chop($inp2); 5856 5856 @not_to_scan = parse_not_to_scan(0x03, 0x77, $inp2); 5857 5857 } 5858 scan_adapter $dev_nr, $adap, $i2c_adapters[$dev_nr]->{'driver'},5859 \@not_to_scan unless $inp =~ /^\s*[Nn]/;5858 scan_adapter($dev_nr, $adap, $i2c_adapters[$dev_nr]->{'driver'}, 5859 \@not_to_scan) unless $inp =~ /^\s*[Nn]/; 5860 5860 } 5861 5861 print "\n"; … … 5930 5930 if (@{$chip->{detected}}) { 5931 5931 print " Detects correctly:\n"; 5932 print_chips_report $chip->{detected};5932 print_chips_report($chip->{detected}); 5933 5933 } 5934 5934 if (@{$chip->{misdetected}}) { 5935 5935 print " Misdetects:\n"; 5936 print_chips_report $chip->{misdetected};5936 print_chips_report($chip->{misdetected}); 5937 5937 } 5938 5938 } … … 5949 5949 if (($have_modprobe_d and not m/^\s*n/i) or m/^\s*y/i) { 5950 5950 unless ($have_modprobe_d) { 5951 mkdir '/etc/modprobe.d', 07775951 mkdir('/etc/modprobe.d', 0777) 5952 5952 or die "Sorry, can't create /etc/modprobe.d ($!)"; 5953 5953 } … … 5974 5974 if (($have_sysconfig and not m/^\s*n/i) or m/^\s*y/i) { 5975 5975 unless ($have_sysconfig) { 5976 mkdir '/etc/sysconfig', 07775976 mkdir('/etc/sysconfig', 0777) 5977 5977 or die "Sorry, can't create /etc/sysconfig ($!)"; 5978 5978 }
