Changeset 244

Show
Ignore:
Timestamp:
02/18/99 01:19:19 (14 years ago)
Author:
frodo
Message:

Latest and greatest detect.pl. Still no user-visible things added; but
I am preparing for the real work now!

Location:
lm-sensors/trunk/prog/detect
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/trunk/prog/detect/detect.pl

    r241 r244  
    2727use strict; 
    2828 
    29 use vars qw(@pci_list @pci_adapters); 
    30  
    3129######################### 
    3230# CONSTANT DECLARATIONS # 
    3331######################### 
     32 
     33use vars qw(@pci_adapters @chip_ids); 
    3434 
    3535# This is the list of SMBus or I2C adapters we recognize by their PCI 
     
    7171 
    7272 
     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 
     115sub swap_bytes 
     116{ 
     117  return (($_[0] & 0xff00) >> 8) + (($_[0] & 0x00ff) << 7) 
     118} 
     119 
     120 
    73121############## 
    74122# PCI ACCESS # 
    75123############## 
     124 
     125use vars qw(@pci_list); 
    76126 
    77127# This function returns a list of hashes. Each hash has some PCI information  
     
    139189##################### 
    140190   
    141  
    142191sub adapter_pci_detection 
    143192{ 
     
    173222############################# 
    174223 
     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 
    175230use vars qw($IOCTL_I2C_RETRIES $IOCTL_I2C_TIMEOUT $IOCTL_I2C_UDELAY  
    176231            $IOCTL_I2C_MDELAY $IOCTL_I2C_SLAVE $IOCTL_I2C_TENBIT  
     
    226281# $_[4]: Reference to an array used for input/output of data 
    227282# 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. 
    230286sub i2c_smbus_access 
    231287{ 
    232288  my ($file,$read_write,$command,$size,$data) = @_; 
    233289  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); 
    235291  ioctl $file, $IOCTL_I2C_SMBUS, $ioctl_data or return 0; 
    236292  $_[4] = [ unpack "C32",$data_array ]; 
     
    296352         or return -1; 
    297353  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. 
     361sub 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]; 
    298368} 
    299369 
     
    311381         or return -1; 
    312382  return 0; 
    313 } 
    314  
    315 # $_[0]: Reference to an opened filehandle 
    316 # $_[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 for  
    319 # this. 
    320 sub i2c_smbus_read_word_data 
    321 { 
    322   my ($file,$command) = @_; 
    323   my $data = []; 
    324   i2c_smbus_access $file, $SMBUS_READ, $command, $SMBUS_WORD_DATA, $data  
    325          or return -1; 
    326   return $$data[0] + 256 * $$data[1]; 
    327383} 
    328384 
     
    363419# Note: some devices use the wrong endiannes; use swap_bytes to correct for  
    364420# this. 
    365 sub i2c_smbus_read_block_data 
     421sub i2c_smbus_write_block_data 
    366422{ 
    367423  my ($file,$command,@data) = @_; 
     
    371427} 
    372428 
    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 
     434sub 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 =  
    383456 
    384457################ 
     
    386459################ 
    387460 
    388 my @hallo; 
    389  
    390461intialize_proc_pci; 
    391462adapter_pci_detection; 
    392463 
     464 
    393465# 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  
    2727use strict; 
    2828 
    29 use vars qw(@pci_list @pci_adapters); 
    30  
    3129######################### 
    3230# CONSTANT DECLARATIONS # 
    3331######################### 
     32 
     33use vars qw(@pci_adapters @chip_ids); 
    3434 
    3535# This is the list of SMBus or I2C adapters we recognize by their PCI 
     
    7171 
    7272 
     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 
     115sub swap_bytes 
     116{ 
     117  return (($_[0] & 0xff00) >> 8) + (($_[0] & 0x00ff) << 7) 
     118} 
     119 
     120 
    73121############## 
    74122# PCI ACCESS # 
    75123############## 
     124 
     125use vars qw(@pci_list); 
    76126 
    77127# This function returns a list of hashes. Each hash has some PCI information  
     
    139189##################### 
    140190   
    141  
    142191sub adapter_pci_detection 
    143192{ 
     
    173222############################# 
    174223 
     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 
    175230use vars qw($IOCTL_I2C_RETRIES $IOCTL_I2C_TIMEOUT $IOCTL_I2C_UDELAY  
    176231            $IOCTL_I2C_MDELAY $IOCTL_I2C_SLAVE $IOCTL_I2C_TENBIT  
     
    226281# $_[4]: Reference to an array used for input/output of data 
    227282# 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. 
    230286sub i2c_smbus_access 
    231287{ 
    232288  my ($file,$read_write,$command,$size,$data) = @_; 
    233289  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); 
    235291  ioctl $file, $IOCTL_I2C_SMBUS, $ioctl_data or return 0; 
    236292  $_[4] = [ unpack "C32",$data_array ]; 
     
    296352         or return -1; 
    297353  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. 
     361sub 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]; 
    298368} 
    299369 
     
    311381         or return -1; 
    312382  return 0; 
    313 } 
    314  
    315 # $_[0]: Reference to an opened filehandle 
    316 # $_[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 for  
    319 # this. 
    320 sub i2c_smbus_read_word_data 
    321 { 
    322   my ($file,$command) = @_; 
    323   my $data = []; 
    324   i2c_smbus_access $file, $SMBUS_READ, $command, $SMBUS_WORD_DATA, $data  
    325          or return -1; 
    326   return $$data[0] + 256 * $$data[1]; 
    327383} 
    328384 
     
    363419# Note: some devices use the wrong endiannes; use swap_bytes to correct for  
    364420# this. 
    365 sub i2c_smbus_read_block_data 
     421sub i2c_smbus_write_block_data 
    366422{ 
    367423  my ($file,$command,@data) = @_; 
     
    371427} 
    372428 
    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 
     434sub 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 =  
    383456 
    384457################ 
     
    386459################ 
    387460 
    388 my @hallo; 
    389  
    390461intialize_proc_pci; 
    391462adapter_pci_detection; 
    392463 
     464 
    393465# 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;