Changeset 338

Show
Ignore:
Timestamp:
03/23/99 22:53:28 (14 years ago)
Author:
frodo
Message:

The lm75 module now understands the new insmod parameters.

Also fixed a few nasty sensors.c bugs, and a minor LM78 one. If the new
parameters give trouble, please recompile sensors.c with DEBUG=1 and
examine the dmesg output!

Location:
lm-sensors/trunk/kernel
Files:
3 modified

Legend:

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

    r283 r338  
    2727#include "version.h" 
    2828 
     29/* Addresses to scan */ 
     30static unsigned short normal_i2c[] = {SENSORS_I2C_END}; 
     31static unsigned short normal_i2c_range[] = {0x48,0x4f,SENSORS_I2C_END}; 
     32static unsigned int normal_isa[] = {SENSORS_ISA_END}; 
     33static unsigned int normal_isa_range[] = {SENSORS_ISA_END}; 
     34 
     35/* Insmod parameters */ 
     36SENSORS_INSMOD_1(lm75); 
     37 
    2938/* Many LM75 constants specified below */ 
    3039 
     
    6271static int lm75_cleanup(void); 
    6372static int lm75_attach_adapter(struct i2c_adapter *adapter); 
     73static int lm75_detect(struct i2c_adapter *adapter, int address, int kind); 
     74static void lm75_init_client(struct i2c_client *client); 
    6475static int lm75_detach_client(struct i2c_client *client); 
    6576static int lm75_command(struct i2c_client *client, unsigned int cmd, 
     
    101112static int lm75_initialized = 0; 
    102113 
    103 /* I choose here for semi-static LM78 allocation. Complete dynamic 
     114/* I choose here for semi-static LM75 allocation. Complete dynamic 
    104115   allocation could also be used; the code needed for this would probably 
    105116   take more memory than the datastructure takes now. */ 
    106 #define MAX_LM75_NR 8 
     117#define MAX_LM75_NR 16 
    107118static struct i2c_client *lm75_list[MAX_LM75_NR]; 
    108119 
     
    110121int lm75_attach_adapter(struct i2c_adapter *adapter) 
    111122{ 
    112   int address,err,i; 
     123  return sensors_detect(adapter,&addr_data,lm75_detect); 
     124} 
     125 
     126/* This function is called by sensors_detect */ 
     127int lm75_detect(struct i2c_adapter *adapter, int address, int kind) 
     128{ 
     129  int i,cur,conf,hyst,os; 
    113130  struct i2c_client *new_client; 
    114131  struct lm75_data *data; 
    115  
    116   err = 0; 
    117   /* Make sure we aren't probing the ISA bus!! */ 
    118   if (i2c_is_isa_adapter(adapter)) return 0; 
    119  
    120   /* OK, this is no detection. I know. It will do for now, though.  */ 
    121  
    122   /* Set err only if a global error would make registering other clients 
    123      impossible too (like out-of-memory). */ 
    124   for (address = 0x48; (! err) && (address <= 0x4f); address ++) { 
    125  
    126     /* Later on, we will keep a list of registered addresses for each 
    127        adapter, and check whether they are used here */ 
     132  int err=0; 
     133  const char *type_name,*client_name; 
     134 
     135  /* Make sure we aren't probing the ISA bus!! This is just a safety check 
     136     at this moment; sensors_detect really won't call us. */ 
     137#ifdef DEBUG 
     138  if (i2c_is_isa_adapter(adapter)) { 
     139    printk("lm75.o: lm75_detect called for an ISA bus adapter?!?\n"); 
     140    return 0; 
     141  } 
     142#endif 
     143 
     144  /* Here, we have to do the address registration check for the I2C bus. 
     145     But that is not yet implemented. */ 
     146 
     147  /* OK. For now, we presume we have a valid client. We now create the 
     148     client structure, even though we cannot fill it completely yet. 
     149     But it allows us to access lm75_{read,write}_value. */ 
     150  if (! (new_client = kmalloc(sizeof(struct i2c_client) + 
     151                              sizeof(struct lm75_data), 
     152                              GFP_KERNEL))) { 
     153    err = -ENOMEM; 
     154    goto ERROR0; 
     155  } 
     156 
     157  data = (struct lm75_data *) (((struct i2c_client *) new_client) + 1); 
     158  new_client->addr = address; 
     159  new_client->data = data; 
     160  new_client->adapter = adapter; 
     161  new_client->driver = &lm75_driver; 
     162 
     163  /* Now, we do the remaining detection. It is lousy. */ 
     164  cur = smbus_read_word_data(adapter,address,0); 
     165  conf = smbus_read_byte_data(adapter,address,1); 
     166  hyst = smbus_read_word_data(adapter,address,2); 
     167  os = smbus_read_word_data(adapter,address,3); 
     168  if ((hyst & 0x7f00) || (os & 0x7f00) || (cur & 0x7f00)) 
     169    goto ERROR1; 
     170  for (i = 0; i <= 0x1f; i++)  
     171    if ((smbus_read_byte_data(adapter,address,i*8+1) != conf) || 
     172        (smbus_read_word_data(adapter,address,i*8+2) != hyst) || 
     173        (smbus_read_word_data(adapter,address,i*8+3) != os)) 
     174      goto ERROR1; 
     175   
     176  /* Determine the chip type - only one kind supported! */ 
     177  if (kind <= 0) 
     178    kind = lm75; 
     179 
     180  if (kind == lm75) { 
     181    type_name = "lm75"; 
     182    client_name = "LM75 chip"; 
     183  } else { 
     184#ifdef DEBUG 
     185    printk("lm75.o: Internal error: unknown kind (%d)?!?",kind); 
     186#endif 
     187    goto ERROR1; 
     188  } 
     189   
     190  /* Fill in the remaining client fields and put it into the global list */ 
     191  strcpy(new_client->name,client_name); 
     192 
     193  /* Find a place in our global list */ 
     194  for (i = 0; i < MAX_LM75_NR; i++) 
     195    if (! lm75_list[i]) 
     196       break; 
     197  if (i == MAX_LM75_NR) { 
     198    err = -ENOMEM; 
     199    printk("lm75.o: No empty slots left, recompile and heighten " 
     200           "MAX_LM75_NR!\n"); 
     201    goto ERROR2; 
     202  } 
     203  lm75_list[i] = new_client; 
     204  new_client->id = i; 
     205  data->valid = 0; 
     206  data->update_lock = MUTEX; 
    128207     
    129     if (smbus_read_byte_data(adapter,address,LM75_REG_CONF) < 0) 
    130       continue; 
    131  
    132     /* Real detection code goes here */ 
    133  
    134     /* Allocate space for a new client structure */ 
    135     if (! (new_client =  kmalloc(sizeof(struct i2c_client) + 
    136                                 sizeof(struct lm75_data), 
    137                                GFP_KERNEL))) { 
    138       err = -ENOMEM; 
    139       continue; 
    140     } 
    141  
    142     /* Find a place in our global list */ 
    143     for (i = 0; i < MAX_LM75_NR; i++) 
    144       if (! lm75_list[i]) 
    145          break; 
    146     if (i == MAX_LM75_NR) { 
    147       err = -ENOMEM; 
    148       printk("lm75.o: No empty slots left, recompile and heighten " 
    149              "MAX_LM75_NR!\n"); 
    150       goto ERROR1; 
    151     } 
    152     lm75_list[i] = new_client; 
    153      
    154     /* Fill the new client structure with data */ 
    155     data = (struct lm75_data *) (new_client + 1); 
    156     new_client->data = data; 
    157     new_client->id = i; 
    158     new_client->addr = address; 
    159     new_client->adapter = adapter; 
    160     new_client->driver = &lm75_driver; 
    161     strcpy(new_client->name,"LM75 chip"); 
    162     data->valid = 0; 
    163     data->update_lock = MUTEX; 
    164      
    165     /* Tell i2c-core a new client has arrived */ 
    166     if ((err = i2c_attach_client(new_client))) 
    167       goto ERROR2; 
    168      
    169     /* Register a new directory entry with module sensors */ 
    170     if ((err = sensors_register_entry(new_client,"lm75", 
    171                                       lm75_dir_table_template)) < 0) 
    172       goto ERROR3; 
    173     data->sysctl_id = err; 
    174     err = 0; 
    175  
    176     /* Initialize the LM75 chip */ 
    177     lm75_write_value(new_client,LM75_REG_TEMP_OS, 
    178                      TEMP_TO_REG(LM75_INIT_TEMP_OS)); 
    179     lm75_write_value(new_client,LM75_REG_TEMP_HYST, 
    180                      TEMP_TO_REG(LM75_INIT_TEMP_HYST)); 
    181     lm75_write_value(new_client,LM75_REG_CONF,0); 
    182  
    183     continue; 
     208  /* Tell the I2C layer a new client has arrived */ 
     209  if ((err = i2c_attach_client(new_client))) 
     210    goto ERROR3; 
     211 
     212  /* Register a new directory entry with module sensors */ 
     213  if ((i = sensors_register_entry(new_client,type_name, 
     214                                  lm75_dir_table_template)) < 0) { 
     215    err = i; 
     216    goto ERROR4; 
     217  } 
     218  data->sysctl_id = i; 
     219 
     220  lm75_init_client((struct i2c_client *) new_client); 
     221  return 0; 
     222 
    184223/* OK, this is not exactly good programming practice, usually. But it is 
    185224   very code-efficient in this case. */ 
    186225 
     226ERROR4: 
     227  i2c_detach_client(new_client); 
    187228ERROR3: 
    188     i2c_detach_client(new_client); 
     229  for (i = 0; i < MAX_LM75_NR; i++) 
     230    if (new_client == lm75_list[i]) 
     231      lm75_list[i] = NULL; 
    189232ERROR2: 
    190     lm75_list[i] = NULL; 
    191233ERROR1: 
    192     kfree(new_client); 
    193   } 
     234  kfree(new_client); 
     235ERROR0: 
    194236  return err; 
    195237} 
     
    198240{ 
    199241  int err,i; 
     242 
     243  sensors_deregister_entry(((struct lm75_data *)(client->data))->sysctl_id); 
     244 
     245  if ((err = i2c_detach_client(client))) { 
     246    printk("lm75.o: Client deregistration failed, client not detached.\n"); 
     247    return err; 
     248  } 
     249 
    200250  for (i = 0; i < MAX_LM75_NR; i++) 
    201251    if (client == lm75_list[i]) 
     
    205255    return -ENOENT; 
    206256  } 
    207  
    208   sensors_deregister_entry(((struct lm75_data *)(client->data))->sysctl_id); 
    209  
    210   if ((err = i2c_detach_client(client))) { 
    211     printk("lm75.o: Client deregistration failed, client not detached.\n"); 
    212     return err; 
    213   } 
    214  
    215257  lm75_list[i] = NULL; 
     258 
    216259  kfree(client); 
     260 
    217261  return 0; 
    218262} 
     
    267311    return smbus_write_word_data(client->adapter,client->addr,reg, 
    268312           swap_bytes(value)); 
     313} 
     314 
     315void lm75_init_client(struct i2c_client *client) 
     316{ 
     317    /* Initialize the LM75 chip */ 
     318    lm75_write_value(client,LM75_REG_TEMP_OS, 
     319                     TEMP_TO_REG(LM75_INIT_TEMP_OS)); 
     320    lm75_write_value(client,LM75_REG_TEMP_HYST, 
     321                     TEMP_TO_REG(LM75_INIT_TEMP_HYST)); 
     322    lm75_write_value(client,LM75_REG_CONF,0); 
    269323} 
    270324 
  • lm-sensors/trunk/kernel/chips/lm78.c

    r333 r338  
    308308  int is_isa = i2c_is_isa_adapter(adapter); 
    309309 
    310  
    311   if (kind < 0) { 
    312310  /* We need address registration for the I2C bus too. That is not yet 
    313311     implemented. */ 
     312  if (is_isa) { 
     313    if (check_region(address,LM78_EXTENT)) 
     314      goto ERROR0; 
     315  } 
     316 
     317  /* Probe whether there is anything available on this address. Already 
     318     done for SMBus clients */ 
     319  if (kind < 0) { 
    314320    if (is_isa) { 
    315321 
     
    394400    type_name = "lm79"; 
    395401    client_name = "LM79 chip"; 
    396   } else 
     402  } else { 
     403#ifdef DEBUG 
     404    printk("lm78.o: Internal error: unknown kind (%d)?!?",kind); 
     405#endif 
    397406    goto ERROR1; 
     407  } 
    398408 
    399409  /* Reserve the ISA region */ 
  • lm-sensors/trunk/kernel/sensors.c

    r335 r338  
    608608             ((this_force->force[j] == SENSORS_ANY_I2C_BUS) && !is_isa)) && 
    609609            (addr == this_force->force[j+1])) { 
     610#ifdef DEBUG 
     611          printk("sensors.o: found force parameter for adapter %d, addr %04x\n", 
     612                 adapter_id,addr); 
     613#endif 
    610614          if ((err = found_proc(adapter,addr,this_force->kind))) 
    611615            return err; 
     
    625629           ((address_data->ignore[i] == SENSORS_ANY_I2C_BUS) && !is_isa)) && 
    626630          (addr == address_data->ignore[i+1])) { 
     631#ifdef DEBUG 
     632          printk("sensors.o: found ignore parameter for adapter %d, " 
     633                 "addr %04x\n", adapter_id,addr); 
     634#endif 
    627635        found = 1; 
    628636      } 
     
    634642           ((address_data->ignore_range[i]==SENSORS_ANY_I2C_BUS) & !is_isa)) && 
    635643          (addr >= address_data->ignore_range[i+1]) && 
    636           (addr <= address_data->ignore_range[i+2])) 
     644          (addr <= address_data->ignore_range[i+2])) { 
     645#ifdef DEBUG 
     646          printk("sensors.o: found ignore_range parameter for adapter %d, " 
     647                 "addr %04x\n", adapter_id,addr); 
     648#endif 
    637649        found = 1; 
     650      } 
    638651    } 
    639652    if (found)  
     
    647660           i += 1) { 
    648661        if (addr == address_data->normal_isa[i]) { 
     662#ifdef DEBUG 
     663          printk("sensors.o: found normal isa entry for adapter %d, "  
     664                 "addr %04x\n", adapter_id,addr); 
     665#endif 
    649666          found = 1; 
     667        } 
    650668      } 
    651669      for (i = 0; 
    652670           !found && (address_data->normal_isa_range[i] != SENSORS_ISA_END); 
    653671           i += 3) { 
    654          if ((addr >= address_data->normal_isa_range[i]) && 
    655              (addr <= address_data->normal_isa_range[i+1]) && 
    656              ((addr - address_data->normal_isa_range[i]) %  
    657                                   address_data->normal_isa_range[i+2] == 0)); 
     672        if ((addr >= address_data->normal_isa_range[i]) && 
     673            (addr <= address_data->normal_isa_range[i+1]) && 
     674            ((addr - address_data->normal_isa_range[i]) %  
     675                                 address_data->normal_isa_range[i+2] == 0)) { 
     676#ifdef DEBUG 
     677          printk("sensors.o: found normal isa_range entry for adapter %d, " 
     678                 "addr %04x", adapter_id,addr); 
     679#endif 
    658680          found = 1; 
    659681        } 
     
    665687        if (addr == address_data->normal_i2c[i]) { 
    666688          found = 1; 
     689#ifdef DEBUG 
     690          printk("sensors.o: found normal i2c entry for adapter %d, " 
     691                 "addr %02x", adapter_id,addr); 
     692#endif 
     693        } 
    667694      } 
    668695      for (i = 0; 
     
    670697           i += 2) { 
    671698         if ((addr >= address_data->normal_i2c_range[i]) && 
    672              (addr <= address_data->normal_i2c_range[i+1])) 
     699             (addr <= address_data->normal_i2c_range[i+1])) { 
     700#ifdef DEBUG 
     701          printk("sensors.o: found normal i2c_range entry for adapter %d, " 
     702                 "addr %04x\n", adapter_id,addr); 
     703#endif 
    673704          found = 1; 
    674705        } 
     
    682713           ((address_data->probe[i] == SENSORS_ANY_I2C_BUS) & !is_isa)) && 
    683714          (addr == address_data->probe[i+1])) { 
     715#ifdef DEBUG 
     716        printk("sensors.o: found probe parameter for adapter %d, " 
     717                 "addr %04x\n", adapter_id,addr); 
     718#endif 
    684719        found = 1; 
    685720      } 
     721    } 
    686722    for (i = 0; 
    687723         !found && (address_data->probe_range[i] != SENSORS_I2C_END); 
     
    690726           ((address_data->probe_range[i] == SENSORS_ANY_I2C_BUS) & !is_isa)) && 
    691727          (addr >= address_data->probe_range[i+1]) && 
    692           (addr <= address_data->probe_range[i+2]))  
     728          (addr <= address_data->probe_range[i+2])) { 
    693729        found = 1; 
     730#ifdef DEBUG 
     731        printk("sensors.o: found probe_range parameter for adapter %d, " 
     732                 "addr %04x\n", adapter_id,addr); 
     733#endif 
    694734      } 
    695735    }