Changeset 361

Show
Ignore:
Timestamp:
04/04/99 23:13:55 (14 years ago)
Author:
frodo
Message:

Insmod parameters for the LM80 driver

Files:
1 modified

Legend:

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

    r333 r361  
    3434#include "i2c.h" 
    3535#include "compat.h" 
     36 
     37/* Addresses to scan */ 
     38static unsigned short normal_i2c[] = {SENSORS_I2C_END}; 
     39static unsigned short normal_i2c_range[] = {0x20,0x2f,SENSORS_I2C_END}; 
     40static unsigned int normal_isa[] = {SENSORS_ISA_END}; 
     41static unsigned int normal_isa_range[] = {SENSORS_ISA_END}; 
     42 
     43/* Insmod parameters */ 
     44SENSORS_INSMOD_1(lm80); 
    3645 
    3746/* Many LM80 constants specified below */ 
     
    176185 
    177186static int lm80_attach_adapter(struct i2c_adapter *adapter); 
     187static int lm80_detect(struct i2c_adapter *adapter, int address, int kind); 
    178188static int lm80_detach_client(struct i2c_client *client); 
    179 static int lm80_new_client(struct i2c_adapter *adapter, 
    180                            struct i2c_client *new_client); 
    181 static void lm80_remove_client(struct i2c_client *client); 
    182189static int lm80_command(struct i2c_client *client, unsigned int cmd,  
    183190                        void *arg); 
     
    260267}; 
    261268 
    262  
    263269int lm80_attach_adapter(struct i2c_adapter *adapter) 
    264270{ 
    265   int address,err; 
     271  return sensors_detect(adapter,&addr_data,lm80_detect); 
     272} 
     273 
     274int lm80_detect(struct i2c_adapter *adapter, int address, int kind) 
     275{ 
     276  int i,cur; 
    266277  struct i2c_client *new_client; 
     278  struct lm80_data *data; 
     279  int err=0; 
    267280  const char *type_name,*client_name; 
    268281 
    269   /* OK, this is no detection. I know. It will do for now, though.  */ 
    270   err = 0; 
    271    
    272   /* Make sure we aren't probing the ISA bus!! */ 
    273   if (i2c_is_isa_adapter(adapter)) return 0; 
    274    
    275   for (address = 0x20; (! err) && (address <= 0x2f); address ++) { 
    276  
    277     /* Later on, we will keep a list of registered addresses for each 
    278        adapter, and check whether they are used here */ 
    279  
    280     if (smbus_read_byte_data(adapter,address,LM80_REG_CONFIG) < 0)  
    281       continue; 
    282  
    283     /* Real detection code goes here */ 
    284  
    285     printk("lm80.o: LM80 detected\n"); 
     282  /* Make sure we aren't probing the ISA bus!! This is just a safety check 
     283     at this moment; sensors_detect really won't call us. */ 
     284#ifdef DEBUG 
     285  if (i2c_is_isa_adapter(adapter)) { 
     286    printk("lm80.o: lm80_detect called for an ISA bus adapter?!?\n"); 
     287    return 0; 
     288  } 
     289#endif 
     290 
     291  /* Here, we have to do the address registration check for the I2C bus. 
     292     But that is not yet implemented. */ 
     293 
     294  /* OK. For now, we presume we have a valid client. We now create the 
     295     client structure, even though we cannot fill it completely yet. 
     296     But it allows us to access lm80_{read,write}_value. */ 
     297  if (! (new_client = kmalloc(sizeof(struct i2c_client) + 
     298                              sizeof(struct lm80_data), 
     299                              GFP_KERNEL))) { 
     300    err = -ENOMEM; 
     301    goto ERROR0; 
     302  } 
     303 
     304  data = (struct lm80_data *) (((struct i2c_client *) new_client) + 1); 
     305  new_client->addr = address; 
     306  new_client->data = data; 
     307  new_client->adapter = adapter; 
     308  new_client->driver = &lm80_driver; 
     309 
     310  /* Now, we do the remaining detection. It is lousy. */ 
     311  if (lm80_read_value(new_client,LM80_REG_ALARM2) & 0xc0) 
     312    goto ERROR1; 
     313  for (i = 0x2a; i <= 0x3d; i++) { 
     314    cur = smbus_read_byte_data(adapter,address,i); 
     315    if ((smbus_read_byte_data(adapter,address,i+0x40) != cur) || 
     316        (smbus_read_byte_data(adapter,address,i+0x80) != cur) || 
     317        (smbus_read_byte_data(adapter,address,i+0xc0) != cur)) 
     318      goto ERROR1; 
     319  } 
     320 
     321  /* Determine the chip type - only one kind supported! */ 
     322  if (kind <= 0) 
     323    kind = lm80; 
     324 
     325  if (kind == lm80) { 
    286326    type_name = "lm80"; 
    287327    client_name = "LM80 chip"; 
    288  
    289  
    290     /* Allocate space for a new client structure. To counter memory 
    291        fragmentation somewhat, we only do one kmalloc. */ 
    292     if (! (new_client = kmalloc(sizeof(struct i2c_client) +  
    293                                 sizeof(struct lm80_data), 
    294                                GFP_KERNEL))) { 
    295       err = -ENOMEM; 
    296       continue; 
    297     } 
    298  
    299     /* Fill the new client structure with data */ 
    300     new_client->data = (struct lm80_data *) (new_client + 1); 
    301     new_client->addr = address; 
    302     strcpy(new_client->name,client_name); 
    303     if ((err = lm80_new_client(adapter,new_client))) 
    304       goto ERROR2; 
    305  
    306     /* Tell i2c-core a new client has arrived */ 
    307     if ((err = i2c_attach_client(new_client)))  
    308       goto ERROR3; 
    309  
    310     /* Register a new directory entry with module sensors */ 
    311     if ((err = sensors_register_entry(new_client,type_name, 
    312                                       lm80_dir_table_template)) < 0) 
    313       goto ERROR4; 
    314     ((struct lm80_data *) (new_client->data))->sysctl_id = err; 
    315     err = 0; 
    316  
    317     /* Initialize the LM80 chip */ 
    318     lm80_init_client(new_client); 
    319     continue; 
     328  } else { 
     329#ifdef DEBUG 
     330    printk("lm80.o: Internal error: unknown kind (%d)?!?",kind); 
     331#endif 
     332    goto ERROR1; 
     333  } 
     334 
     335  /* Fill in the remaining client fields and put it into the global list */ 
     336  strcpy(new_client->name,client_name); 
     337 
     338  /* Find a place in our global list */ 
     339  for (i = 0; i < MAX_LM80_NR; i++) 
     340    if (! lm80_list[i]) 
     341       break; 
     342  if (i == MAX_LM80_NR) { 
     343    err = -ENOMEM; 
     344    printk("lm80.o: No empty slots left, recompile and heighten " 
     345           "MAX_LM80_NR!\n"); 
     346    goto ERROR2; 
     347  } 
     348  lm80_list[i] = new_client; 
     349  new_client->id = i; 
     350  data->valid = 0; 
     351  data->update_lock = MUTEX; 
     352 
     353  /* Tell the I2C layer a new client has arrived */ 
     354  if ((err = i2c_attach_client(new_client))) 
     355    goto ERROR3; 
     356 
     357  /* Register a new directory entry with module sensors */ 
     358  if ((i = sensors_register_entry(new_client,type_name, 
     359                                  lm80_dir_table_template)) < 0) { 
     360    err = i; 
     361    goto ERROR4; 
     362  } 
     363  data->sysctl_id = i; 
     364 
     365  lm80_init_client(new_client); 
     366  return 0; 
    320367 
    321368/* OK, this is not exactly good programming practice, usually. But it is 
    322369   very code-efficient in this case. */ 
    323370ERROR4: 
    324     i2c_detach_client(new_client); 
     371  i2c_detach_client(new_client); 
    325372ERROR3: 
    326     lm80_remove_client((struct i2c_client *) new_client); 
     373  for (i = 0; i < MAX_LM80_NR; i++) 
     374    if (new_client == lm80_list[i]) 
     375      lm80_list[i] = NULL; 
    327376ERROR2: 
    328     kfree(new_client); 
    329   } 
     377ERROR1: 
     378  kfree(new_client); 
     379ERROR0: 
    330380  return err; 
    331381} 
     
    334384{ 
    335385  int err,i; 
     386 
     387  sensors_deregister_entry(((struct lm80_data *)(client->data))->sysctl_id); 
     388 
     389  if ((err = i2c_detach_client(client))) { 
     390    printk("lm80.o: Client deregistration failed, client not detached.\n"); 
     391    return err; 
     392  } 
     393 
    336394  for (i = 0; i < MAX_LM80_NR; i++) 
    337395    if (client == lm80_list[i]) 
     
    341399    return -ENOENT; 
    342400  } 
    343  
    344   sensors_deregister_entry(((struct lm80_data *)(client->data))->sysctl_id); 
    345  
    346   if ((err = i2c_detach_client(client))) { 
    347     printk("lm80.o: Client deregistration failed, client not detached.\n"); 
    348     return err; 
    349   } 
    350   lm80_remove_client(client); 
     401  lm80_list[i] = NULL; 
     402 
    351403  kfree(client); 
     404 
    352405  return 0; 
    353 } 
    354  
    355  
    356 /* Find a free slot, and initialize most of the fields */ 
    357 int lm80_new_client(struct i2c_adapter *adapter, 
    358                     struct i2c_client *new_client) 
    359 { 
    360   int i; 
    361   struct lm80_data *data; 
    362  
    363   /* First, seek out an empty slot */ 
    364   for(i = 0; i < MAX_LM80_NR; i++) 
    365     if (! lm80_list[i]) 
    366       break; 
    367   if (i == MAX_LM80_NR) { 
    368     printk("lm80.o: No empty slots left, recompile and heighten " 
    369            "MAX_LM80_NR!\n"); 
    370     return -ENOMEM; 
    371   } 
    372    
    373   lm80_list[i] = new_client; 
    374   new_client->id = i; 
    375   new_client->adapter = adapter; 
    376   new_client->driver = &lm80_driver; 
    377   data = new_client->data; 
    378   data->valid = 0; 
    379   data->update_lock = MUTEX; 
    380   return 0; 
    381 } 
    382  
    383 /* Inverse of lm80_new_client */ 
    384 void lm80_remove_client(struct i2c_client *client) 
    385 { 
    386   int i; 
    387   for (i = 0; i < MAX_LM80_NR; i++) 
    388     if (client == lm80_list[i])  
    389       lm80_list[i] = NULL; 
    390406} 
    391407