Changeset 324

Show
Ignore:
Timestamp:
03/18/99 16:32:20 (10 years ago)
Author:
frodo
Message:

Introducing module parameter scanning in sensors.c

It is untested as of yet; but it compiled without problem. Next step: add
support to the chip modules.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • lm-sensors/trunk/TODO

    r301 r324  
    11Many, many things. Most notably: 
    22 
     3* Sensors program needs to print a + before lm75 temperatures 
     4* Timer chips - block read problems? 
    35* LM78 detection: bit 5 reg 0x49 may be one?!? 
    46* bit-lp increases module count stupidly 
  • lm-sensors/trunk/kernel/include/sensors.h

    r314 r324  
    8080                                  const char *prefix, ctl_table *ctl_template); 
    8181extern void sensors_deregister_entry(int id); 
     82 
     83 
     84/* A structure containing detect information. 
     85   Force variables overrule all other variables; they force a detection on 
     86   that place. If a specific chip is given, the module blindly assumes this 
     87   chip type is present; if a general force (kind == 0) is given, the module 
     88   will still try to figure out what type of chip is present. This is useful 
     89   if for some reasons the detect for SMBus or ISA address space filled 
     90   fails. 
     91   probe: insmod parameter. Initialize this list with SENSORS_I2C_END values. 
     92     A list of pairs. The first value is a bus number (SENSORS_ISA_BUS for 
     93     the ISA bus, -1 for any I2C bus), the second is the address.  
     94   kind: The kind of chip. 0 equals any chip. 
     95*/ 
     96struct sensors_force_data { 
     97  unsigned short *force; 
     98  unsigned short kind; 
     99}; 
     100 
     101/* A structure containing the detect information. 
     102   normal_i2c: filled in by the module writer. Terminated by SENSORS_I2C_END. 
     103     A list of I2C addresses which should normally be examined. 
     104   normal_i2c_range: filled in by the module writer. Terminated by  
     105     SENSORS_I2C_END 
     106     A list of pairs of I2C addresses, each pair being an inclusive range of 
     107     addresses which should normally be examined. 
     108   normal_isa: filled in by the module writer. Terminated by SENSORS_ISA_END. 
     109     A list of ISA addresses which should normally be examined. 
     110   normal_isa_range: filled in by the module writer. Terminated by  
     111     SENSORS_ISA_END 
     112     A list of triples. The first two elements are ISA addresses, being an 
     113     range of addresses which should normally be examined. The third is the 
     114     modulo parameter: only addresses which are 0 module this value relative 
     115     to the first address of the range are actually considered. 
     116   probe: insmod parameter. Initialize this list with SENSORS_I2C_END values. 
     117     A list of pairs. The first value is a bus number (SENSORS_ISA_BUS for 
     118     the ISA bus, -1 for any I2C bus), the second is the address. These 
     119     addresses are also probed, as if they were in the 'normal' list. 
     120   probe_range: insmod parameter. Initialize this list with SENSORS_I2C_END  
     121     values. 
     122     A list of triples. The first value is a bus number (SENSORS_ISA_BUS for 
     123     the ISA bus, -1 for any I2C bus), the second and third are addresses.  
     124     These form an inclusive range of addresses that are also probed, as 
     125     if they were in the 'normal' list. 
     126   ignore: insmod parameter. Initialize this list with SENSORS_I2C_END values. 
     127     A list of pairs. The first value is a bus number (SENSORS_ISA_BUS for 
     128     the ISA bus, -1 for any I2C bus), the second is the I2C address. These 
     129     addresses are never probed. This parameter overrules 'normal' and  
     130     'probe', but not the 'force' lists. 
     131   ignore_range: insmod parameter. Initialize this list with SENSORS_I2C_END  
     132      values. 
     133     A list of triples. The first value is a bus number (SENSORS_ISA_BUS for 
     134     the ISA bus, -1 for any I2C bus), the second and third are addresses.  
     135     These form an inclusive range of I2C addresses that are never probed. 
     136     This parameter overrules 'normal' and 'probe', but not the 'force' lists. 
     137   force_data: insmod parameters. A list, ending with an element of which 
     138     the force field is NULL. 
     139*/ 
     140struct sensors_address_data { 
     141  unsigned short *normal_i2c; 
     142  unsigned short *normal_i2c_range; 
     143  unsigned int *normal_isa; 
     144  unsigned int *normal_isa_range; 
     145  unsigned short *probe; 
     146  unsigned short *probe_range; 
     147  unsigned short *ignore; 
     148  unsigned short *ignore_range; 
     149  struct sensors_force_data *forces; 
     150}; 
     151 
     152/* Internal numbers to terminate lists */ 
     153#define SENSORS_I2C_END 0xfffe 
     154#define SENSORS_ISA_END 0xfffefffe 
     155 
     156/* The numbers to use to set an ISA or I2C bus address */ 
     157#define SENSORS_ISA_BUS 9191 
     158#define SENSORS_ANY_I2C_BUS 0xffff 
     159 
     160/* The length of the option lists */ 
     161#define SENSORS_MAX_OPTS 48 
     162 
     163typedef void sensors_found_addr_proc (struct i2c_adapter *adapter,  
     164                                      int addr, int kind); 
     165 
     166/* Detect function. It itterates over all possible addresses itself. For 
     167   SMBus addresses, it will only call found_proc if some client is connected 
     168   to the SMBus (unless a 'force' matched); for ISA detections, this is not 
     169   done. */ 
     170extern void sensors_detect(struct i2c_adapter *adapter, 
     171                           struct sensors_address_data *address_data, 
     172                           sensors_found_addr_proc *found_proc); 
    82173 
    83174#endif /* def __KERNEL__ */ 
  • lm-sensors/trunk/kernel/sensors.c

    r303 r324  
    3030#include "sensors.h" 
    3131#include "compat.h" 
     32#include "smbus.h" 
    3233 
    3334 
     
    114115 
    115116/* This rather complex function must be called when you want to add an entry 
    116    to /proc/sys/dev/sensors/chips (not yet implemented). It also creates 
    117    a new directory within /proc/sys/dev/sensors/. 
     117   to /proc/sys/dev/sensors/chips. It also creates a new directory within  
     118   /proc/sys/dev/sensors/. 
    118119   ctl_template should be a template of the newly created directory. It is 
    119120   copied in memory. The extra2 field of each file is set to point to client. 
     
    580581} 
    581582 
     583 
     584/* Very inefficient for ISA detects! */ 
     585void sensors_detect(struct i2c_adapter *adapter, 
     586                    struct sensors_address_data *address_data, 
     587                    sensors_found_addr_proc *found_proc) 
     588{ 
     589  int addr,i,found,j; 
     590  struct sensors_force_data *this_force; 
     591  unsigned int end_marker = i2c_is_isa_adapter(adapter)?SENSORS_ISA_END: 
     592                                                        SENSORS_I2C_END; 
     593  int adapter_id = i2c_is_isa_adapter(adapter)?SENSORS_ISA_BUS: 
     594                                               i2c_adapter_id(adapter); 
     595 
     596  for (addr = 0x00; addr <= i2c_is_isa_adapter(adapter)?0xfff:0x7f; addr ++) { 
     597    /* If it is in one of the force entries, we don't do any detection 
     598       at all */ 
     599    found = 0; 
     600    for (i = 0;  
     601         !found && (this_force = address_data->forces+i, this_force->force);  
     602         i++) { 
     603      for (j = 0; !found && (this_force->force[j] != end_marker) ; i += 2) { 
     604        if (((adapter_id == this_force->force[j]) ||  
     605             (this_force->force[j] == SENSORS_ANY_I2C_BUS)) && 
     606            (addr == this_force->force[j+1])) { 
     607          found_proc(adapter,addr,this_force->kind); 
     608          found = 1; 
     609        } 
     610      } 
     611    } 
     612    if (found) 
     613      continue; 
     614 
     615    /* If this address is in one of the ignores, we can forget about it 
     616       right now */ 
     617    for (i = 0; 
     618         !found && (address_data->ignore[i] != end_marker);  
     619         i += 2) { 
     620      if (((adapter_id == address_data->ignore[i]) ||  
     621           (address_data->ignore[i] == SENSORS_ANY_I2C_BUS)) && 
     622          (addr == address_data->ignore[i+1])) { 
     623        found = 1; 
     624      } 
     625    } 
     626    for (i = 0; 
     627         !found && (address_data->ignore_range[i] != end_marker); 
     628         i += 3) { 
     629      if (((adapter_id == address_data->ignore_range[i]) || 
     630           (address_data->ignore_range[i] == SENSORS_ANY_I2C_BUS)) && 
     631          (addr >= address_data->ignore_range[i+1]) && 
     632          (addr <= address_data->ignore_range[i+2])) 
     633        found = 1; 
     634    } 
     635    if (found) 
     636      continue; 
     637 
     638    /* Now, we will do a detection, but only if it is in the normal or  
     639       probe entries */ 
     640    if (i2c_is_isa_adapter(adapter)) { 
     641      for (i = 0; 
     642           !found && (address_data->normal_isa[i] != SENSORS_ISA_END); 
     643           i += 1) { 
     644        if (addr == address_data->normal_isa[i]) { 
     645          found = 1; 
     646      } 
     647      for (i = 0; 
     648           !found && (address_data->normal_isa_range[i] != SENSORS_I2C_END); 
     649           i += 3) { 
     650         if ((addr >= address_data->normal_isa_range[i]) && 
     651             (addr <= address_data->normal_isa_range[i+1]) && 
     652             ((addr - address_data->normal_isa_range[i]) %  
     653                                  address_data->normal_isa_range[i+2] == 0)); 
     654          found = 1; 
     655        } 
     656      } 
     657    } else { 
     658      for (i = 0; 
     659           !found && (address_data->normal_i2c[i] != SENSORS_I2C_END); 
     660           i += 1) { 
     661        if (addr == address_data->normal_i2c[i]) { 
     662          found = 1; 
     663      } 
     664      for (i = 0; 
     665           !found && (address_data->normal_i2c_range[i] != SENSORS_I2C_END); 
     666           i += 2) { 
     667         if ((addr >= address_data->normal_i2c_range[i]) && 
     668             (addr <= address_data->normal_i2c_range[i+1])) 
     669          found = 1; 
     670        } 
     671      } 
     672    } 
     673 
     674    for (i = 0; 
     675         !found && (address_data->probe[i] != SENSORS_I2C_END); 
     676         i += 2) { 
     677      if (((adapter_id == address_data->probe[i]) || 
     678           (address_data->probe[i] == SENSORS_ANY_I2C_BUS)) && 
     679          (addr == address_data->probe[i+1])) { 
     680        found = 1; 
     681      } 
     682    for (i = 0; 
     683         !found && (address_data->probe_range[i] != SENSORS_I2C_END); 
     684         i += 3) { 
     685      if (((adapter_id == address_data->probe_range[i]) || 
     686           (address_data->probe_range[i] == SENSORS_ANY_I2C_BUS)) && 
     687          (addr >= address_data->probe_range[i+1]) && 
     688          (addr <= address_data->probe_range[i+2]))  
     689        found = 1; 
     690      } 
     691    } 
     692    if (!found) 
     693      continue; 
     694 
     695    /* OK, so we really should examine this address. First check 
     696       whether there is some client here at all! */ 
     697    if (!i2c_is_isa_adapter(adapter) ||  
     698        (smbus_read_byte(adapter,addr) >= 0)) 
     699      found_proc(adapter,addr,0); 
     700  } 
     701} 
     702       
    582703int sensors_init(void)  
    583704{