Changeset 325

Show
Ignore:
Timestamp:
03/19/99 07:25:02 (14 years ago)
Author:
frodo
Message:

LM78 insmod parameters and better detection

Supported insmod parameters:

ignore, ignore_range
probe, probe_range
force, force_lm78, force_lm78j, force_lm79

force* overrules ignore* overrules probe*

The *_range parameters need three elements for each specification:

bus,start_addr,end_addr

The address ranges are inclusive.
The other parameters need two elements for each specification:

bus,addr

In each case, '-1' stands for 'any I2C bus', and 9191 stands for
'the ISA bus' (Bonus question: who can figure out why I choose 9191?)
In each case, just append if you want several specification, for example:

insmod lm78 probe=9191,0x2a0,1,0x56

force_* does no detection, not even chip detection; it blindly assumes
you know what you are doing. plain force does the chip detection, but
nothing else; but it can still fail if the register read-out does not
match a chip type.

Detection is done in exactly the same way as sensors-detect, except that
only the range 0x20-0x2f is examined by default. This needs to be
synchronized somehow with the detect script. I would rather scan the whole
I2C address range, but with those clueless PIIX4 hangs when clock chips
are read, that would simply give too much trouble.

The detect script has slightly better ISA detection now, too.

Location:
lm-sensors/trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/trunk/kernel/chips/lm78.c

    r219 r325  
    3434#include "compat.h" 
    3535 
     36/* Addresses to scan */ 
     37static unsigned short normal_i2c[] = {SENSORS_I2C_END}; 
     38static unsigned short normal_i2c_range[] = {0x20,0x2f,SENSORS_I2C_END}; 
     39static unsigned int normal_isa[] = {0x0290,SENSORS_ISA_END}; 
     40static unsigned int normal_isa_range[] = {SENSORS_ISA_END}; 
     41 
     42/* Insmod parameters */ 
     43SENSORS_INSMOD_3(lm78,lm78j,lm79); 
    3644/* Many LM78 constants specified below */ 
    3745 
     
    6270#define LM78_REG_CONFIG 0x40 
    6371#define LM78_REG_CHIPID 0x49 
     72#define LM78_REG_I2C_ADDR 0x48 
    6473 
    6574 
     
    150159   some corners. */ 
    151160 
    152 /* Types of chips supported */ 
    153 enum lm78_type { lm78, lm78j, lm79 }; 
    154  
    155161/* For each registered LM78, we need to keep some data in memory. That 
    156162   data is pointed to by lm78_list[NR]->data. The structure itself is 
     
    160166         struct semaphore lock; 
    161167         int sysctl_id; 
    162          enum lm78_type type; 
     168         enum chips type; 
    163169 
    164170         struct semaphore update_lock; 
     
    184190 
    185191static int lm78_attach_adapter(struct i2c_adapter *adapter); 
    186 static int lm78_detect_isa(struct isa_adapter *adapter); 
    187 static int lm78_detect_smbus(struct i2c_adapter *adapter); 
     192static int lm78_detect(struct i2c_adapter *adapter, int address, int kind); 
    188193static int lm78_detach_client(struct i2c_client *client); 
    189 static int lm78_detach_isa(struct isa_client *client); 
    190 static int lm78_detach_smbus(struct i2c_client *client); 
    191 static int lm78_new_client(struct i2c_adapter *adapter, 
    192                            struct i2c_client *new_client); 
    193 static void lm78_remove_client(struct i2c_client *client); 
    194194static int lm78_command(struct i2c_client *client, unsigned int cmd,  
    195195                        void *arg); 
     
    219219   allocation could also be used; the code needed for this would probably 
    220220   take more memory than the datastructure takes now. */ 
    221 #define MAX_LM78_NR 4 
     221#define MAX_LM78_NR 8 
    222222static struct i2c_client *lm78_list[MAX_LM78_NR]; 
    223223 
     
    283283int lm78_attach_adapter(struct i2c_adapter *adapter) 
    284284{ 
    285   if (i2c_is_isa_adapter(adapter)) 
    286     return lm78_detect_isa((struct isa_adapter *) adapter); 
    287   else 
    288     return lm78_detect_smbus(adapter); 
    289 } 
    290  
    291 /* This function is called whenever a client should be removed: 
    292     * lm78_driver is removed (when this module is unloaded) 
    293     * when an adapter is removed which has a lm78 client (and lm78_driver 
    294       is still present). */ 
    295 int lm78_detach_client(struct i2c_client *client) 
    296 { 
    297   if (i2c_is_isa_client(client)) 
    298     return lm78_detach_isa((struct isa_client *) client); 
    299   else 
    300     return lm78_detach_smbus(client); 
    301 } 
    302  
    303 /* Detect whether there is a LM78 on the ISA bus, register and initialize  
    304    it. */ 
    305 int lm78_detect_isa(struct isa_adapter *adapter) 
    306 { 
    307   int address,err; 
    308   struct isa_client *new_client; 
    309   enum lm78_type type; 
    310   const char *type_name; 
    311   const char *client_name; 
    312  
    313   /* OK, this is no detection. I know. It will do for now, though.  */ 
    314  
    315   err = 0; 
    316   for (address = 0x290; (! err) && (address <= 0x290); address += 0x08) { 
    317     if (check_region(address, LM78_EXTENT)) 
    318       continue; 
    319  
    320     if (inb_p(address + LM78_ADDR_REG_OFFSET) == 0xff) { 
    321       outb_p(0x00,address + LM78_ADDR_REG_OFFSET); 
    322       if (inb_p(address + LM78_ADDR_REG_OFFSET) == 0xff) 
    323         continue; 
     285  return sensors_detect(adapter,&addr_data,lm78_detect); 
     286} 
     287 
     288/* This function is called by sensors_detect */ 
     289int lm78_detect(struct i2c_adapter *adapter, int address, int kind) 
     290{ 
     291  int i; 
     292  struct i2c_client *new_client; 
     293  struct lm78_data *data; 
     294  int err=0; 
     295  const char *type_name = ""; 
     296  const char *client_name = ""; 
     297 
     298 
     299  if (kind < 0) { 
     300  /* We need address registration for the I2C bus too. That is not yet 
     301     implemented. */ 
     302    if (i2c_is_isa_adapter(adapter)) { 
     303 
     304#define REALLY_SLOW_IO 
     305      /* We need the timeouts for at least some LM78-like chips. But only 
     306         if we read 'undefined' registers. */ 
     307      if (check_region(address,LM78_EXTENT)) 
     308        goto ERROR0; 
     309      i = inb_p(address + 1); 
     310      if (inb_p(address + 2) != i) 
     311        goto ERROR0; 
     312      if (inb_p(address + 3) != i) 
     313        goto ERROR0; 
     314      if (inb_p(address + 7) != i) 
     315        goto ERROR0; 
     316#undef REALLY_SLOW_IO 
     317       
     318      /* Let's just hope nothing breaks here */ 
     319      i = inb_p(address + 5) & 0x7f; 
     320      outb_p(~i & 0x7f,address+5); 
     321      if ((inb_p(address + 5) & 0x7f) != (~i & 0x7f)) { 
     322        outb_p(i,address+5); 
     323        return 0; 
     324      } 
    324325    } 
     326  } 
     327 
     328  /* OK. For now, we presume we have a valid client. We now create the 
     329     client structure, even though we cannot fill it completely yet. 
     330     But it allows us to access lm78_{read,write}_value. */ 
     331 
     332  if (! (new_client = kmalloc((i2c_is_isa_adapter(adapter)? 
     333                                      sizeof(struct isa_client): 
     334                                      sizeof(struct i2c_client)) +  
     335                               sizeof(struct lm78_data), 
     336                              GFP_KERNEL))) { 
     337    err = -ENOMEM; 
     338    goto ERROR0; 
     339  } 
     340 
     341  if (i2c_is_isa_adapter(adapter)) { 
     342    data = (struct lm78_data *) (((struct isa_client *) new_client) + 1); 
     343    new_client->addr = 0; 
     344    ((struct isa_client *) new_client)->isa_addr = address; 
     345    data->lock = MUTEX; 
     346  } else { 
     347    data = (struct lm78_data *) (((struct i2c_client *) new_client) + 1); 
     348    new_client->addr = address; 
     349  } 
     350  new_client->data = data; 
     351  new_client->adapter = adapter; 
     352  new_client->driver = &lm78_driver; 
     353   
     354  /* Now, we do the remaining detection. */ 
     355 
     356  if (kind < 0) { 
     357    if (lm78_read_value(new_client,LM78_REG_CONFIG) & 0x80) 
     358      goto ERROR1; 
     359    if (!i2c_is_isa_adapter(adapter) &&  
     360        (lm78_read_value(new_client,LM78_REG_I2C_ADDR) != address)) 
     361      goto ERROR1; 
     362  } 
    325363     
    326     /* Real detection code goes here */ 
    327  
    328     /* Determine exact type */ 
    329     outb_p(LM78_REG_CHIPID,address + LM78_ADDR_REG_OFFSET); 
    330     err = inb_p(address + LM78_DATA_REG_OFFSET) & 0xfe; 
    331     if (err == 0x00) { 
    332       type = lm78; 
     364  /* Determine the chip type. */ 
     365  if (kind <= 0) { 
     366    i = lm78_read_value(new_client,LM78_REG_CHIPID); 
     367    if (i == 0x00) { 
     368      kind = lm78; 
    333369      type_name = "lm78"; 
    334370      client_name = "LM78 chip"; 
    335     } else if (err == 0x40) { 
    336       type = lm78j; 
     371    } else if (i == 0x40) { 
     372      kind = lm78j; 
    337373      type_name = "lm78-j"; 
    338374      client_name = "LM78-J chip"; 
    339     } else if (err == 0xc0) { 
    340       type = lm79; 
     375    } else if ((i & 0xfe) == 0xc0) { 
     376      kind = lm79; 
    341377      type_name = "lm79"; 
    342378      client_name = "LM79 chip"; 
    343     } else if (err == 0x02) { 
    344       printk("lm78.o: Warning: Winbond W83781D detected (treated as a LM79)\n"); 
    345       type = lm79; 
    346       type_name = "lm79"; 
    347       client_name = "LM79 chip"; 
    348     } else { 
    349 #ifdef DEBUG 
    350       printk("lm78.o: warning: probed non-lm78 chip?!? (%x)\n",err); 
    351 #endif 
    352       continue; 
    353     } 
    354  
     379    } else 
     380      goto ERROR1; 
     381  } 
     382 
     383  /* Reserve the ISA region */ 
     384  if i2c_is_isa_adapter(adapter) 
    355385    request_region(address, LM78_EXTENT, type_name); 
    356386 
    357     /* Allocate space for a new client structure */ 
    358     if (! (new_client = kmalloc(sizeof(struct isa_client) +  
    359                                 sizeof(struct lm78_data), 
    360                                GFP_KERNEL))) 
    361     { 
    362       err=-ENOMEM; 
    363       goto ERROR1; 
    364     }  
    365  
    366     /* Fill the new client structure with data */ 
    367     new_client->data = (struct lm78_data *) (new_client + 1); 
    368     new_client->addr = 0; 
    369     strcpy(new_client->name,client_name); 
    370     ((struct lm78_data *) (new_client->data))->type = type; 
    371     new_client->isa_addr = address; 
    372     if ((err = lm78_new_client((struct i2c_adapter *) adapter, 
    373                                (struct i2c_client *) new_client))) 
    374       goto ERROR2; 
    375  
    376     /* Tell i2c-core a new client has arrived */ 
    377     if ((err = isa_attach_client(new_client))) 
    378       goto ERROR3; 
    379      
    380     /* Register a new directory entry with module sensors */ 
    381     if ((err = sensors_register_entry((struct i2c_client *) new_client, 
    382                                       type_name, 
    383                                       lm78_dir_table_template)) < 0) 
    384       goto ERROR4; 
    385     ((struct lm78_data *) (new_client->data)) -> sysctl_id = err; 
    386     err = 0; 
    387  
    388     /* Initialize the LM78 chip */ 
    389     lm78_init_client((struct i2c_client *) new_client); 
    390     continue; 
     387  /* Fill in the remaining client fields and put it into the global list */ 
     388  strcpy(new_client->name,client_name); 
     389  data->type = kind; 
     390 
     391  for(i = 0; i < MAX_LM78_NR; i++) 
     392    if (! lm78_list[i]) 
     393      break; 
     394  if (i == MAX_LM78_NR) { 
     395    printk("lm78.o: No empty slots left, recompile and heighten " 
     396           "MAX_LM78_NR!\n"); 
     397    err = -ENOMEM; 
     398    goto ERROR2; 
     399  } 
     400  lm78_list[i] = new_client; 
     401  new_client->id = i; 
     402  data->valid = 0; 
     403  data->update_lock = MUTEX; 
     404 
     405  /* Tell the I2C layer a new client has arrived */ 
     406  if ((err = i2c_attach_client(new_client))) 
     407    goto ERROR3; 
     408 
     409  /* Register a new directory entry with module sensors */ 
     410  if ((i = sensors_register_entry((struct i2c_client *) new_client, 
     411                                  type_name, 
     412                                  lm78_dir_table_template)) < 0) { 
     413    err = i; 
     414    goto ERROR4; 
     415  } 
     416  data->sysctl_id = i; 
     417 
     418  /* Initialize the LM78 chip */ 
     419  lm78_init_client((struct i2c_client *) new_client); 
     420  return 0; 
    391421 
    392422/* OK, this is not exactly good programming practice, usually. But it is 
     
    394424 
    395425ERROR4: 
    396     isa_detach_client(new_client); 
     426  i2c_detach_client(new_client); 
    397427ERROR3: 
    398     lm78_remove_client((struct i2c_client *) new_client); 
     428  for (i = 0; i < MAX_LM78_NR; i++) 
     429    if (new_client == lm78_list[i])  
     430      lm78_list[i] = NULL; 
    399431ERROR2: 
    400     kfree(new_client); 
     432  if i2c_is_isa_adapter(adapter) 
     433    release_region(address,LM78_EXTENT); 
    401434ERROR1: 
    402     release_region(address, LM78_EXTENT); 
    403   } 
     435  kfree(new_client); 
     436ERROR0: 
    404437  return err; 
    405  
    406 } 
    407  
    408 /* Deregister and remove a LM78 client */ 
    409 int lm78_detach_isa(struct isa_client *client) 
     438} 
     439 
     440int lm78_detach_client(struct i2c_client *client) 
    410441{ 
    411442  int err,i; 
    412   for (i = 0; i < MAX_LM78_NR; i++) 
    413     if ((client == (struct isa_client *) (lm78_list[i]))) 
    414       break; 
    415   if (i == MAX_LM78_NR) { 
    416     printk("lm78.o: Client to detach not found.\n"); 
    417     return -ENOENT; 
    418   } 
    419443 
    420444  sensors_deregister_entry(((struct lm78_data *)(client->data))->sysctl_id); 
    421445 
    422   if ((err = isa_detach_client(client))) { 
     446  if ((err = i2c_detach_client(client))) { 
    423447    printk("lm78.o: Client deregistration failed, client not detached.\n"); 
    424448    return err; 
    425449  } 
    426   lm78_remove_client((struct i2c_client *) client); 
    427   release_region(client->isa_addr,LM78_EXTENT); 
    428   kfree(client); 
    429   return 0; 
    430 } 
    431  
    432 int lm78_detect_smbus(struct i2c_adapter *adapter) 
    433 { 
    434   int address,err; 
    435   struct i2c_client *new_client; 
    436   enum lm78_type type; 
    437   const char *type_name,*client_name; 
    438  
    439   /* OK, this is no detection. I know. It will do for now, though.  */ 
    440   err = 0; 
    441   for (address = 0x20; (! err) && (address <= 0x2f); address ++) { 
    442  
    443     /* Later on, we will keep a list of registered addresses for each 
    444        adapter, and check whether they are used here */ 
    445  
    446     if (smbus_read_byte_data(adapter,address,LM78_REG_CONFIG) < 0)  
    447       continue; 
    448  
    449     /* Real detection code goes here */ 
    450  
    451     /* Determine exact type */ 
    452     err = smbus_read_byte_data(adapter,address,LM78_REG_CHIPID) & 0xfe; 
    453     if (err == 0x00) { 
    454       type = lm78; 
    455       type_name = "lm78"; 
    456       client_name = "LM78 chip"; 
    457     } else if (err == 0x40) { 
    458       type = lm78j; 
    459       type_name = "lm78-j"; 
    460       client_name = "LM78-J chip"; 
    461     } else if (err == 0xc0) { 
    462       type = lm79; 
    463       type_name = "lm79"; 
    464       client_name = "LM79 chip"; 
    465     } else if (err == 0x02) { 
    466       printk("lm78.o: Warning: Winbond W83781D detected (treated as a LM79)\n"); 
    467       type = lm79; 
    468       type_name = "lm79"; 
    469       client_name = "LM79 chip"; 
    470     } else { 
    471 #ifdef DEBUG 
    472       printk("lm78.o: warning: probed non-lm78 chip?!? (%x)\n",err); 
    473 #endif 
    474       continue; 
    475     } 
    476  
    477  
    478     /* Allocate space for a new client structure. To counter memory 
    479        ragmentation somewhat, we only do one kmalloc. */ 
    480     if (! (new_client = kmalloc(sizeof(struct i2c_client) +  
    481                                 sizeof(struct lm78_data), 
    482                                GFP_KERNEL))) { 
    483       err = -ENOMEM; 
    484       continue; 
    485     } 
    486  
    487     /* Fill the new client structure with data */ 
    488     new_client->data = (struct lm78_data *) (new_client + 1); 
    489     new_client->addr = address; 
    490     strcpy(new_client->name,client_name); 
    491     ((struct lm78_data *) (new_client->data))->type = type; 
    492     if ((err = lm78_new_client(adapter,new_client))) 
    493       goto ERROR2; 
    494  
    495     /* Tell i2c-core a new client has arrived */ 
    496     if ((err = i2c_attach_client(new_client)))  
    497       goto ERROR3; 
    498  
    499     /* Register a new directory entry with module sensors */ 
    500     if ((err = sensors_register_entry(new_client,type_name, 
    501                                       lm78_dir_table_template)) < 0) 
    502       goto ERROR4; 
    503     ((struct lm78_data *) (new_client->data))->sysctl_id = err; 
    504     err = 0; 
    505  
    506     /* Initialize the LM78 chip */ 
    507     lm78_init_client(new_client); 
    508     continue; 
    509  
    510 /* OK, this is not exactly good programming practice, usually. But it is 
    511    very code-efficient in this case. */ 
    512 ERROR4: 
    513     i2c_detach_client(new_client); 
    514 ERROR3: 
    515     lm78_remove_client((struct i2c_client *) new_client); 
    516 ERROR2: 
    517     kfree(new_client); 
    518   } 
    519   return err; 
    520 } 
    521  
    522 int lm78_detach_smbus(struct i2c_client *client) 
    523 { 
    524   int err,i; 
     450 
    525451  for (i = 0; i < MAX_LM78_NR; i++) 
    526452    if (client == lm78_list[i]) 
     
    530456    return -ENOENT; 
    531457  } 
    532  
    533   sensors_deregister_entry(((struct lm78_data *)(client->data))->sysctl_id); 
    534  
    535   if ((err = i2c_detach_client(client))) { 
    536     printk("lm78.o: Client deregistration failed, client not detached.\n"); 
    537     return err; 
    538   } 
    539   lm78_remove_client(client); 
     458  lm78_list[i] = NULL; 
     459 
     460  if i2c_is_isa_client(client) 
     461    release_region(((struct isa_client *)client)->isa_addr,LM78_EXTENT); 
    540462  kfree(client); 
     463 
    541464  return 0; 
    542 } 
    543  
    544  
    545 /* Find a free slot, and initialize most of the fields */ 
    546 int lm78_new_client(struct i2c_adapter *adapter, 
    547                     struct i2c_client *new_client) 
    548 { 
    549   int i; 
    550   struct lm78_data *data; 
    551  
    552   /* First, seek out an empty slot */ 
    553   for(i = 0; i < MAX_LM78_NR; i++) 
    554     if (! lm78_list[i]) 
    555       break; 
    556   if (i == MAX_LM78_NR) { 
    557     printk("lm78.o: No empty slots left, recompile and heighten " 
    558            "MAX_LM78_NR!\n"); 
    559     return -ENOMEM; 
    560   } 
    561    
    562   lm78_list[i] = new_client; 
    563   new_client->id = i; 
    564   new_client->adapter = adapter; 
    565   new_client->driver = &lm78_driver; 
    566   data = new_client->data; 
    567   data->valid = 0; 
    568   data->lock = MUTEX; 
    569   data->update_lock = MUTEX; 
    570   return 0; 
    571 } 
    572  
    573 /* Inverse of lm78_new_client */ 
    574 void lm78_remove_client(struct i2c_client *client) 
    575 { 
    576   int i; 
    577   for (i = 0; i < MAX_LM78_NR; i++) 
    578     if (client == lm78_list[i])  
    579       lm78_list[i] = NULL; 
    580465} 
    581466 
     
    604489 
    605490/* The SMBus locks itself, but ISA access must be locked explicitely!  
     491   We don't want to lock the whole ISA bus, so we lock each client 
     492   separately. 
    606493   We ignore the LM78 BUSY flag at this moment - it could lead to deadlocks, 
    607494   would slow down the LM78 access and should not be necessary.  
     
    612499  int res; 
    613500  if (i2c_is_isa_client(client)) { 
    614     down((struct semaphore *) (client->data)); 
     501    down(& (((struct lm78_data *) (client->data)) -> lock)); 
    615502    outb_p(reg,(((struct isa_client *) client)->isa_addr) +  
    616503               LM78_ADDR_REG_OFFSET); 
    617504    res = inb_p((((struct isa_client *) client)->isa_addr) +  
    618505                LM78_DATA_REG_OFFSET); 
    619     up((struct semaphore *) (client->data)); 
     506    up( & (((struct lm78_data *) (client->data)) -> lock)); 
    620507    return res; 
    621508  } else 
     
    624511 
    625512/* The SMBus locks itself, but ISA access muse be locked explicitely!  
     513   We don't want to lock the whole ISA bus, so we lock each client 
     514   separately. 
    626515   We ignore the LM78 BUSY flag at this moment - it could lead to deadlocks, 
    627516   would slow down the LM78 access and should not be necessary.  
     
    631520{ 
    632521  if (i2c_is_isa_client(client)) { 
    633     down((struct semaphore *) (client->data)); 
     522    down(&(((struct lm78_data *) (client->data)) -> lock)); 
    634523    outb_p(reg,((struct isa_client *) client)->isa_addr + LM78_ADDR_REG_OFFSET); 
    635524    outb_p(value,((struct isa_client *) client)->isa_addr + LM78_DATA_REG_OFFSET); 
    636     up((struct semaphore *) (client->data)); 
     525    up(&(((struct lm78_data *) (client->data)) -> lock)); 
    637526    return 0; 
    638527  } else 
  • lm-sensors/trunk/kernel/include/sensors.h

    r324 r325  
    161161#define SENSORS_MAX_OPTS 48 
    162162 
    163 typedef void sensors_found_addr_proc (struct i2c_adapter *adapter,  
    164                                       int addr, int kind); 
     163/* Default fill of many variables */ 
     164#define SENSORS_DEFAULTS {SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \ 
     165                          SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \ 
     166                          SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \ 
     167                          SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \ 
     168                          SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \ 
     169                          SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \ 
     170                          SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \ 
     171                          SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \ 
     172                          SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \ 
     173                          SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \ 
     174                          SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \ 
     175                          SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \ 
     176                          SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \ 
     177                          SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \ 
     178                          SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \ 
     179                          SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END} 
     180 
     181#define SENSORS_MODPARM_AUX1(x) "1-" #x "h" 
     182#define SENSORS_MODPARM_AUX(x) SENSORS_MODPARM_AUX1(x) 
     183#define SENSORS_MODPARM SENSORS_MODPARM_AUX(SENSORS_MAX_OPTS) 
     184 
     185#define SENSORS_CONCAT(x,y) x ## y 
     186#define MODULE_PARM1(x,y) MODULE_PARM(x,y) 
     187 
     188/* This defines several insmod variables, and the addr_data structure */ 
     189#define SENSORS_INSMOD \ 
     190  MODULE_PARM(probe,SENSORS_MODPARM); \ 
     191  static unsigned short probe[SENSORS_MAX_OPTS] = SENSORS_DEFAULTS; \ 
     192  MODULE_PARM(probe_range,SENSORS_MODPARM); \ 
     193  static unsigned short probe_range[SENSORS_MAX_OPTS] = SENSORS_DEFAULTS; \ 
     194  MODULE_PARM(ignore,SENSORS_MODPARM); \ 
     195  static unsigned short ignore[SENSORS_MAX_OPTS] = SENSORS_DEFAULTS; \ 
     196  MODULE_PARM(ignore_range,SENSORS_MODPARM); \ 
     197  static unsigned short ignore_range [SENSORS_MAX_OPTS]  = SENSORS_DEFAULTS; \ 
     198  static struct sensors_address_data addr_data = \ 
     199                                       {normal_i2c, normal_i2c_range, \ 
     200                                        normal_isa, normal_isa_range, \ 
     201                                        probe, probe_range, \ 
     202                                        ignore, ignore_range, \ 
     203                                        forces} 
     204 
     205/* The following functions assume the existence of an enum with the chip 
     206   names as elements. The first element of the enum should be any_chip */ 
     207 
     208#define SENSORS_INSMOD_0 \ 
     209  enum chips { any_chip }; \ 
     210  MODULE_PARM(force,SENSORS_MODPARM); \ 
     211  static unsigned short force[SENSORS_MAX_OPTS] = SENSORS_DEFAULTS; \ 
     212  static struct sensors_force_data forces[] = {{force,any_chip},{NULL}}; \ 
     213  SENSORS_INSMOD 
     214 
     215#define SENSORS_INSMOD_1(chip1) \ 
     216  enum chips { any_chip, chip1 }; \ 
     217  MODULE_PARM(force,SENSORS_MODPARM); \ 
     218  static unsigned short force[SENSORS_MAX_OPTS] = SENSORS_DEFAULTS; \ 
     219  MODULE_PARM1(SENSORS_CONCAT(force_,chip1),SENSORS_MODPARM); \ 
     220  static unsigned short force_ ## chip1 [SENSORS_MAX_OPTS] = SENSORS_DEFAULTS; \ 
     221  static struct sensors_force_data forces[] = {{force,any_chip},\ 
     222                                                 {force_ ## chip1,chip1}, \ 
     223                                                 {NULL}}; \ 
     224  SENSORS_INSMOD 
     225 
     226#define SENSORS_INSMOD_2(chip1,chip2) \ 
     227  enum chips { any_chip, chip1, chip2 }; \ 
     228  MODULE_PARM(force,SENSORS_MODPARM); \ 
     229  static unsigned short force[SENSORS_MAX_OPTS] = SENSORS_DEFAULTS; \ 
     230  MODULE_PARM1(SENSORS_CONCAT(force_,chip1),SENSORS_MODPARM); \ 
     231  static unsigned short force_ ## chip1 [SENSORS_MAX_OPTS] = SENSORS_DEFAULTS; \ 
     232  MODULE_PARM1(SENSORS_CONCAT(force_,chip2),SENSORS_MODPARM); \ 
     233  static unsigned short force_ ## chip2 [SENSORS_MAX_OPTS] = SENSORS_DEFAULTS; \ 
     234  static struct sensors_force_data forces[] = {{force,any_chip}, \ 
     235                                                 {force_ ## chip1,chip2}, \ 
     236                                                 {force_ ## chip2,nr2}, \ 
     237                                                 {NULL}}; \ 
     238  SENSORS_INSMOD 
     239 
     240#define SENSORS_INSMOD_3(chip1,chip2,chip3) \ 
     241  enum chips { any_chip, chip1, chip2, chip3 }; \ 
     242  MODULE_PARM(force,SENSORS_MODPARM); \ 
     243  static unsigned short force[SENSORS_MAX_OPTS] = SENSORS_DEFAULTS; \ 
     244  MODULE_PARM1(SENSORS_CONCAT(force_,chip1),SENSORS_MODPARM); \ 
     245  static unsigned short force_ ## chip1 [SENSORS_MAX_OPTS] = SENSORS_DEFAULTS; \ 
     246  MODULE_PARM1(SENSORS_CONCAT(force_,chip2),SENSORS_MODPARM); \ 
     247  static unsigned short force_ ## chip2 [SENSORS_MAX_OPTS] = SENSORS_DEFAULTS; \ 
     248  MODULE_PARM1(SENSORS_CONCAT(force_,chip3),SENSORS_MODPARM); \ 
     249  static unsigned short force_ ## chip3 [SENSORS_MAX_OPTS] = SENSORS_DEFAULTS; \ 
     250  static struct sensors_force_data forces[] = {{force,any_chip}, \ 
     251                                                 {force_ ## chip1,chip1}, \ 
     252                                                 {force_ ## chip2,chip2}, \ 
     253                                                 {force_ ## chip3,chip3}, \ 
     254                                                 {NULL}}; \ 
     255  SENSORS_INSMOD 
     256 
     257typedef int sensors_found_addr_proc (struct i2c_adapter *adapter,  
     258                                     int addr, int kind); 
    165259 
    166260/* Detect function. It itterates over all possible addresses itself. For 
     
    168262   to the SMBus (unless a 'force' matched); for ISA detections, this is not 
    169263   done. */ 
    170 extern void sensors_detect(struct i2c_adapter *adapter, 
    171                            struct sensors_address_data *address_data, 
    172                            sensors_found_addr_proc *found_proc); 
     264extern int sensors_detect(struct i2c_adapter *adapter, 
     265                          struct sensors_address_data *address_data, 
     266                          sensors_found_addr_proc *found_proc); 
    173267 
    174268#endif /* def __KERNEL__ */ 
  • lm-sensors/trunk/kernel/sensors.c

    r324 r325  
    583583 
    584584/* Very inefficient for ISA detects! */ 
    585 void 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; 
     585int 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,err; 
    590590  struct sensors_force_data *this_force; 
    591   unsigned int end_marker = i2c_is_isa_adapter(adapter)?SENSORS_ISA_END: 
    592                                                         SENSORS_I2C_END; 
    593591  int adapter_id = i2c_is_isa_adapter(adapter)?SENSORS_ISA_BUS: 
    594592                                               i2c_adapter_id(adapter); 
    595593 
    596   for (addr = 0x00; addr <= i2c_is_isa_adapter(adapter)?0xfff:0x7f; addr ++) { 
     594printk("IGNORE: %04hx %04hx %04hx %04hx %04hx %04hx\n",address_data->ignore[0],address_data->ignore[1],address_data->ignore[2],address_data->ignore[3],address_data->ignore[4],address_data->ignore[5]); 
     595  for (addr = 0x00;  
     596       addr <= (i2c_is_isa_adapter(adapter)?0xffff:0x7f);  
     597       addr ++) { 
     598 
    597599    /* If it is in one of the force entries, we don't do any detection 
    598600       at all */ 
     
    601603         !found && (this_force = address_data->forces+i, this_force->force);  
    602604         i++) { 
    603       for (j = 0; !found && (this_force->force[j] != end_marker) ; i += 2) { 
     605      for (j = 0;  
     606           !found && (this_force->force[j] != SENSORS_I2C_END) ;  
     607           i += 2) { 
    604608        if (((adapter_id == this_force->force[j]) ||  
    605609             (this_force->force[j] == SENSORS_ANY_I2C_BUS)) && 
    606610            (addr == this_force->force[j+1])) { 
    607           found_proc(adapter,addr,this_force->kind); 
     611          if ((err = found_proc(adapter,addr,this_force->kind))) 
     612            return err; 
    608613          found = 1; 
    609614        } 
    610615      } 
    611616    } 
    612     if (found) 
     617    if (found)  
    613618      continue; 
    614619 
     
    616621       right now */ 
    617622    for (i = 0; 
    618          !found && (address_data->ignore[i] != end_marker);  
     623         !found && (address_data->ignore[i] != SENSORS_I2C_END);  
    619624         i += 2) { 
    620625      if (((adapter_id == address_data->ignore[i]) ||  
     
    625630    } 
    626631    for (i = 0; 
    627          !found && (address_data->ignore_range[i] != end_marker); 
     632         !found && (address_data->ignore_range[i] != SENSORS_I2C_END); 
    628633         i += 3) { 
    629634      if (((adapter_id == address_data->ignore_range[i]) || 
     
    633638        found = 1; 
    634639    } 
    635     if (found) 
     640    if (found)  
    636641      continue; 
    637642 
     
    646651      } 
    647652      for (i = 0; 
    648            !found && (address_data->normal_isa_range[i] != SENSORS_I2C_END); 
     653           !found && (address_data->normal_isa_range[i] != SENSORS_ISA_END); 
    649654           i += 3) { 
    650655         if ((addr >= address_data->normal_isa_range[i]) && 
     
    690695      } 
    691696    } 
    692     if (!found) 
     697    if (!found)  
    693698      continue; 
    694699 
    695700    /* OK, so we really should examine this address. First check 
    696701       whether there is some client here at all! */ 
    697     if (!i2c_is_isa_adapter(adapter) ||  
     702    if (i2c_is_isa_adapter(adapter) ||  
    698703        (smbus_read_byte(adapter,addr) >= 0)) 
    699       found_proc(adapter,addr,0); 
    700   } 
     704      if ((err = found_proc(adapter,addr,-1))) 
     705        return err; 
     706  } 
     707  return 0; 
    701708} 
    702709       
  • lm-sensors/trunk/prog/detect/sensors-detect

    r323 r325  
    10441044  return if inb ($addr + 2) != $val or inb ($addr + 3) != $val or  
    10451045            inb ($addr + 7) != $val; 
     1046 
     1047  $val = inb($addr + 5) & 0x7f; 
     1048  outb($addr+5,~ $val); 
     1049  if ((inb ($addr+5) & 0x7f) != (~ $val & 0x7f)) { 
     1050    outb($addr+5,$val); 
     1051    return; 
     1052  } 
    10461053  my $readproc = sub { isa_read_byte $addr + 5, $addr + 6, @_ }; 
    10471054  return unless (&$readproc(0x40) & 0x80) == 0x00; 
     
    11841191  return if inb ($addr + 2) != $val or inb ($addr + 3) != $val or  
    11851192            inb ($addr + 7) != $val; 
     1193 
     1194  $val = inb($addr + 5) & 0x7f; 
     1195  outb($addr+5,~ $val); 
     1196  if ((inb ($addr+5) & 0x7f) != (~ $val & 0x7f)) { 
     1197    outb($addr+5,$val); 
     1198    return; 
     1199  } 
     1200 
    11861201  my $read_proc = sub { isa_read_byte $addr + 5, $addr + 6, @_ }; 
    11871202  $reg1 = &$read_proc(0x4e);