Changeset 244
- Timestamp:
- 02/18/99 01:19:19 (14 years ago)
- Location:
- lm-sensors/trunk/prog/detect
- Files:
-
- 2 modified
-
detect.pl (modified) (10 diffs)
-
sensors-detect (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lm-sensors/trunk/prog/detect/detect.pl
r241 r244 27 27 use strict; 28 28 29 use vars qw(@pci_list @pci_adapters);30 31 29 ######################### 32 30 # CONSTANT DECLARATIONS # 33 31 ######################### 32 33 use vars qw(@pci_adapters @chip_ids); 34 34 35 35 # This is the list of SMBus or I2C adapters we recognize by their PCI … … 71 71 72 72 73 # This is a list of all recognized chips. 74 # Each entry must have a name (Full Chip Name), an array i2c_addrs (Valid 75 # I2C Addresses; may be omitted if this is a pure ISA chip), an array 76 # isa_addrs (Valid ISA Addresses; may be omitted if this is a pure I2C chip) 77 # ,... 78 # If no driver is written yet, omit the driver (Driver Name) field. 79 @chip_ids = ( 80 { 81 name => "National Semiconductors LM78", 82 driver => "lm78", 83 i2c_addrs => (0x00..0x7f), 84 isa_addrs => (0x290), # Theoretically anyway, but this will do 85 } , 86 { 87 name => "National Semiconductors LM78-J", 88 driver => "lm78", 89 i2c_addrs => (0x00..0x7f), 90 isa_addrs => (0x290), # Theoretically anyway, but this will do 91 } , 92 { 93 name => "National Semiconductors LM79", 94 driver => "lm78", 95 i2c_addrs => (0x00..0x7f), 96 isa_addrs => (0x290), # Theoretically anyway, but this will do 97 } , 98 { 99 name => "National Semiconductors LM75", 100 driver => "lm75", 101 i2c_addrs => (0x48..0x4f), 102 } , 103 { 104 name => "National Semiconductors LM80", 105 driver => "lm80", 106 i2c_addrs => (0x28..0x2f), 107 } 108 ); 109 110 111 ####################### 112 # AUXILIARY FUNCTIONS # 113 ####################### 114 115 sub swap_bytes 116 { 117 return (($_[0] & 0xff00) >> 8) + (($_[0] & 0x00ff) << 7) 118 } 119 120 73 121 ############## 74 122 # PCI ACCESS # 75 123 ############## 124 125 use vars qw(@pci_list); 76 126 77 127 # This function returns a list of hashes. Each hash has some PCI information … … 139 189 ##################### 140 190 141 142 191 sub adapter_pci_detection 143 192 { … … 173 222 ############################# 174 223 224 # This should really go into a separate module/package. 225 226 # To do: support i2c-level access (through sysread/syswrite, probably). 227 # I can't test this at all (PIIX4 does not support this), so I have not 228 # included it. 229 175 230 use vars qw($IOCTL_I2C_RETRIES $IOCTL_I2C_TIMEOUT $IOCTL_I2C_UDELAY 176 231 $IOCTL_I2C_MDELAY $IOCTL_I2C_SLAVE $IOCTL_I2C_TENBIT … … 226 281 # $_[4]: Reference to an array used for input/output of data 227 282 # Returns: 0 on failure, 1 on success. 228 # Note the "SS" pack, even though they are declared as chars in the C struct! 229 # This is very compiler-dependent; I wish there was some other way to do this. 283 # Note that we need to get back to Integer boundaries through the 'x2' 284 # in the pack. This is very compiler-dependent; I wish there was some other 285 # way to do this. 230 286 sub i2c_smbus_access 231 287 { 232 288 my ($file,$read_write,$command,$size,$data) = @_; 233 289 my $data_array = pack "C32", @$data; 234 my $ioctl_data = pack " SSIp", ($read_write,$command,$size,$data_array);290 my $ioctl_data = pack "C2x2Ip", ($read_write,$command,$size,$data_array); 235 291 ioctl $file, $IOCTL_I2C_SMBUS, $ioctl_data or return 0; 236 292 $_[4] = [ unpack "C32",$data_array ]; … … 296 352 or return -1; 297 353 return 0; 354 } 355 356 # $_[0]: Reference to an opened filehandle 357 # $_[1]: Command byte (usually register number) 358 # Returns: -1 on failure, the read word on success. 359 # Note: some devices use the wrong endiannes; use swap_bytes to correct for 360 # this. 361 sub i2c_smbus_read_word_data 362 { 363 my ($file,$command) = @_; 364 my $data = []; 365 i2c_smbus_access $file, $SMBUS_READ, $command, $SMBUS_WORD_DATA, $data 366 or return -1; 367 return $$data[0] + 256 * $$data[1]; 298 368 } 299 369 … … 311 381 or return -1; 312 382 return 0; 313 }314 315 # $_[0]: Reference to an opened filehandle316 # $_[1]: Command byte (usually register number)317 # Returns: -1 on failure, the read word on success.318 # Note: some devices use the wrong endiannes; use swap_bytes to correct for319 # this.320 sub i2c_smbus_read_word_data321 {322 my ($file,$command) = @_;323 my $data = [];324 i2c_smbus_access $file, $SMBUS_READ, $command, $SMBUS_WORD_DATA, $data325 or return -1;326 return $$data[0] + 256 * $$data[1];327 383 } 328 384 … … 363 419 # Note: some devices use the wrong endiannes; use swap_bytes to correct for 364 420 # this. 365 sub i2c_smbus_ read_block_data421 sub i2c_smbus_write_block_data 366 422 { 367 423 my ($file,$command,@data) = @_; … … 371 427 } 372 428 373 # $_[0]: Reference to an opened filehandle 374 ####################### 375 # AUXILIARY FUNCTIONS # 376 ####################### 377 378 sub swap_bytes 379 { 380 return (($_[0] & 0xff00) >> 8) + (($_[0] & 0x00ff) << 7) 381 } 382 429 #################### 430 # ADAPTER SCANNING # 431 #################### 432 433 # $_[0]: The number of the adapter to scan 434 sub scan_adapter 435 { 436 open FILE,"/dev/i2c-".$_[0] or die "Can't open /dev/i2c-".$_[0]; 437 foreach (0..0x7f) { 438 i2c_set_slave_addr(\*FILE,$_) or print("Can't set address to $_?!?\n"), 439 next; 440 printf ("Client found at address 0x%02x\n",$_) 441 if i2c_smbus_read_byte(\*FILE) >= 0; 442 } 443 } 444 445 ################## 446 # CHIP DETECTION # 447 ################## 448 449 # $_[0]: 0 for ISA, 1 for I2C 450 # $_[1]: Address 451 # $_[2]: For I2C, a reference to the file descriptor to access this chip. 452 # We may assume an i2c_set_slave_addr was aleady done. 453 #sub lm78_detect 454 #{ 455 # $@lm78_read = 383 456 384 457 ################ … … 386 459 ################ 387 460 388 my @hallo;389 390 461 intialize_proc_pci; 391 462 adapter_pci_detection; 392 463 464 393 465 # TEST! 394 #open FILE, "+>/dev/i2c-0" or die "Can't open /dev/i2c-0!"; 395 #i2c_set_slave_addr \*FILE, 0x49 or die "Couldn't set slave addr!"; 396 #print (i2c_read_word_data \*FILE, 0), "\n"; 466 #scan_adapter 0; -
lm-sensors/trunk/prog/detect/sensors-detect
r241 r244 27 27 use strict; 28 28 29 use vars qw(@pci_list @pci_adapters);30 31 29 ######################### 32 30 # CONSTANT DECLARATIONS # 33 31 ######################### 32 33 use vars qw(@pci_adapters @chip_ids); 34 34 35 35 # This is the list of SMBus or I2C adapters we recognize by their PCI … … 71 71 72 72 73 # This is a list of all recognized chips. 74 # Each entry must have a name (Full Chip Name), an array i2c_addrs (Valid 75 # I2C Addresses; may be omitted if this is a pure ISA chip), an array 76 # isa_addrs (Valid ISA Addresses; may be omitted if this is a pure I2C chip) 77 # ,... 78 # If no driver is written yet, omit the driver (Driver Name) field. 79 @chip_ids = ( 80 { 81 name => "National Semiconductors LM78", 82 driver => "lm78", 83 i2c_addrs => (0x00..0x7f), 84 isa_addrs => (0x290), # Theoretically anyway, but this will do 85 } , 86 { 87 name => "National Semiconductors LM78-J", 88 driver => "lm78", 89 i2c_addrs => (0x00..0x7f), 90 isa_addrs => (0x290), # Theoretically anyway, but this will do 91 } , 92 { 93 name => "National Semiconductors LM79", 94 driver => "lm78", 95 i2c_addrs => (0x00..0x7f), 96 isa_addrs => (0x290), # Theoretically anyway, but this will do 97 } , 98 { 99 name => "National Semiconductors LM75", 100 driver => "lm75", 101 i2c_addrs => (0x48..0x4f), 102 } , 103 { 104 name => "National Semiconductors LM80", 105 driver => "lm80", 106 i2c_addrs => (0x28..0x2f), 107 } 108 ); 109 110 111 ####################### 112 # AUXILIARY FUNCTIONS # 113 ####################### 114 115 sub swap_bytes 116 { 117 return (($_[0] & 0xff00) >> 8) + (($_[0] & 0x00ff) << 7) 118 } 119 120 73 121 ############## 74 122 # PCI ACCESS # 75 123 ############## 124 125 use vars qw(@pci_list); 76 126 77 127 # This function returns a list of hashes. Each hash has some PCI information … … 139 189 ##################### 140 190 141 142 191 sub adapter_pci_detection 143 192 { … … 173 222 ############################# 174 223 224 # This should really go into a separate module/package. 225 226 # To do: support i2c-level access (through sysread/syswrite, probably). 227 # I can't test this at all (PIIX4 does not support this), so I have not 228 # included it. 229 175 230 use vars qw($IOCTL_I2C_RETRIES $IOCTL_I2C_TIMEOUT $IOCTL_I2C_UDELAY 176 231 $IOCTL_I2C_MDELAY $IOCTL_I2C_SLAVE $IOCTL_I2C_TENBIT … … 226 281 # $_[4]: Reference to an array used for input/output of data 227 282 # Returns: 0 on failure, 1 on success. 228 # Note the "SS" pack, even though they are declared as chars in the C struct! 229 # This is very compiler-dependent; I wish there was some other way to do this. 283 # Note that we need to get back to Integer boundaries through the 'x2' 284 # in the pack. This is very compiler-dependent; I wish there was some other 285 # way to do this. 230 286 sub i2c_smbus_access 231 287 { 232 288 my ($file,$read_write,$command,$size,$data) = @_; 233 289 my $data_array = pack "C32", @$data; 234 my $ioctl_data = pack " SSIp", ($read_write,$command,$size,$data_array);290 my $ioctl_data = pack "C2x2Ip", ($read_write,$command,$size,$data_array); 235 291 ioctl $file, $IOCTL_I2C_SMBUS, $ioctl_data or return 0; 236 292 $_[4] = [ unpack "C32",$data_array ]; … … 296 352 or return -1; 297 353 return 0; 354 } 355 356 # $_[0]: Reference to an opened filehandle 357 # $_[1]: Command byte (usually register number) 358 # Returns: -1 on failure, the read word on success. 359 # Note: some devices use the wrong endiannes; use swap_bytes to correct for 360 # this. 361 sub i2c_smbus_read_word_data 362 { 363 my ($file,$command) = @_; 364 my $data = []; 365 i2c_smbus_access $file, $SMBUS_READ, $command, $SMBUS_WORD_DATA, $data 366 or return -1; 367 return $$data[0] + 256 * $$data[1]; 298 368 } 299 369 … … 311 381 or return -1; 312 382 return 0; 313 }314 315 # $_[0]: Reference to an opened filehandle316 # $_[1]: Command byte (usually register number)317 # Returns: -1 on failure, the read word on success.318 # Note: some devices use the wrong endiannes; use swap_bytes to correct for319 # this.320 sub i2c_smbus_read_word_data321 {322 my ($file,$command) = @_;323 my $data = [];324 i2c_smbus_access $file, $SMBUS_READ, $command, $SMBUS_WORD_DATA, $data325 or return -1;326 return $$data[0] + 256 * $$data[1];327 383 } 328 384 … … 363 419 # Note: some devices use the wrong endiannes; use swap_bytes to correct for 364 420 # this. 365 sub i2c_smbus_ read_block_data421 sub i2c_smbus_write_block_data 366 422 { 367 423 my ($file,$command,@data) = @_; … … 371 427 } 372 428 373 # $_[0]: Reference to an opened filehandle 374 ####################### 375 # AUXILIARY FUNCTIONS # 376 ####################### 377 378 sub swap_bytes 379 { 380 return (($_[0] & 0xff00) >> 8) + (($_[0] & 0x00ff) << 7) 381 } 382 429 #################### 430 # ADAPTER SCANNING # 431 #################### 432 433 # $_[0]: The number of the adapter to scan 434 sub scan_adapter 435 { 436 open FILE,"/dev/i2c-".$_[0] or die "Can't open /dev/i2c-".$_[0]; 437 foreach (0..0x7f) { 438 i2c_set_slave_addr(\*FILE,$_) or print("Can't set address to $_?!?\n"), 439 next; 440 printf ("Client found at address 0x%02x\n",$_) 441 if i2c_smbus_read_byte(\*FILE) >= 0; 442 } 443 } 444 445 ################## 446 # CHIP DETECTION # 447 ################## 448 449 # $_[0]: 0 for ISA, 1 for I2C 450 # $_[1]: Address 451 # $_[2]: For I2C, a reference to the file descriptor to access this chip. 452 # We may assume an i2c_set_slave_addr was aleady done. 453 #sub lm78_detect 454 #{ 455 # $@lm78_read = 383 456 384 457 ################ … … 386 459 ################ 387 460 388 my @hallo;389 390 461 intialize_proc_pci; 391 462 adapter_pci_detection; 392 463 464 393 465 # TEST! 394 #open FILE, "+>/dev/i2c-0" or die "Can't open /dev/i2c-0!"; 395 #i2c_set_slave_addr \*FILE, 0x49 or die "Couldn't set slave addr!"; 396 #print (i2c_read_word_data \*FILE, 0), "\n"; 466 #scan_adapter 0;
