Changeset 371

Show
Ignore:
Timestamp:
04/08/99 20:31:08 (14 years ago)
Author:
frodo
Message:

Added insmod parameters to eeprom module, and fixed a typo in the

gl518sm module

Besides the usual parameters, eeprom.o understands insmod parameter 'checksum'.
Set it to one (ie. 'modprobe eeprom checksum=1') to make it ignore any
chips which do not come through the checksum.

Location:
lm-sensors/trunk/kernel/chips
Files:
2 modified

Legend:

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

    r333 r371  
    2828#include "version.h" 
    2929 
     30/* Addresses to scan */ 
     31static unsigned short normal_i2c[] = {SENSORS_I2C_END}; 
     32static unsigned short normal_i2c_range[] = {0x50,0x57,SENSORS_I2C_END}; 
     33static unsigned int normal_isa[] = {SENSORS_ISA_END}; 
     34static unsigned int normal_isa_range[] = {SENSORS_ISA_END}; 
     35 
     36/* Insmod parameters */ 
     37SENSORS_INSMOD_1(eeprom); 
     38 
     39static int checksum = 0; 
     40MODULE_PARM(checksum,"i"); 
     41MODULE_PARM_DESC(checksum,"Only accept eeproms whose checksum is correct"); 
     42 
     43 
    3044/* Many constants specified below */ 
     45 
     46/* EEPROM registers */ 
     47#define EEPROM_REG_CHECKSUM 0x3f 
    3148 
    3249/* EEPROM memory types: */ 
     
    6279 
    6380static int eeprom_attach_adapter(struct i2c_adapter *adapter); 
     81static int eeprom_detect(struct i2c_adapter *adapter, int address, int kind); 
    6482static int eeprom_detach_client(struct i2c_client *client); 
    6583static int eeprom_command(struct i2c_client *client, unsigned int cmd, 
     
    124142static struct i2c_client *eeprom_list[MAX_EEPROM_NR]; 
    125143 
    126  
    127144int eeprom_attach_adapter(struct i2c_adapter *adapter) 
    128145{ 
    129   int address,err,i; 
     146  return sensors_detect(adapter,&addr_data,eeprom_detect); 
     147} 
     148 
     149/* This function is called by sensors_detect */ 
     150int eeprom_detect(struct i2c_adapter *adapter, int address, int kind) 
     151{ 
     152  int i,cs; 
    130153  struct i2c_client *new_client; 
    131154  struct eeprom_data *data; 
    132  
    133   err = 0; 
    134   /* Make sure we aren't probing the ISA bus!! */ 
    135   if (i2c_is_isa_adapter(adapter)) return 0; 
     155  int err=0; 
     156  const char *type_name,*client_name; 
     157 
     158  /* Make sure we aren't probing the ISA bus!! This is just a safety check 
     159     at this moment; sensors_detect really won't call us. */ 
     160#ifdef DEBUG 
     161  if (i2c_is_isa_adapter(adapter)) { 
     162    printk("eeprom.o: eeprom_detect called for an ISA bus adapter?!?\n"); 
     163    return 0; 
     164  } 
     165#endif 
     166 
     167  /* Here, we have to do the address registration check for the I2C bus. 
     168     But that is not yet implemented. */ 
     169 
     170  /* OK. For now, we presume we have a valid client. We now create the 
     171     client structure, even though we cannot fill it completely yet. 
     172     But it allows us to access eeprom_{read,write}_value. */ 
     173  if (! (new_client = kmalloc(sizeof(struct i2c_client) + 
     174                              sizeof(struct eeprom_data), 
     175                              GFP_KERNEL))) { 
     176    err = -ENOMEM; 
     177    goto ERROR0; 
     178  } 
     179 
     180  data = (struct eeprom_data *) (((struct i2c_client *) new_client) + 1); 
     181  new_client->addr = address; 
     182  new_client->data = data; 
     183  new_client->adapter = adapter; 
     184  new_client->driver = &eeprom_driver; 
     185 
     186  /* Now, we do the remaining detection. It is not there, unless you force 
     187     the checksum to work out. */ 
     188  if (checksum) { 
     189    cs = 0; 
     190    for (i = 0; i <= 0x3e; i++) 
     191      cs += smbus_read_byte_data(adapter,address,i); 
     192    cs &= 0xff; 
     193    if (smbus_read_byte_data(adapter,address,EEPROM_REG_CHECKSUM) != cs) 
     194      goto ERROR1; 
     195  } 
    136196   
    137   /* OK, this is no detection. I know. It will do for now, though.  */ 
    138  
    139   /* Set err only if a global error would make registering other clients 
    140      impossible too (like out-of-memory). */ 
    141       
    142   /* Serial EEPROMs for SMBus use addresses from 0x50 to 0x57 */ 
    143   for (address = 0x50; (! err) && (address <= 0x57); address ++) { 
    144  
    145     /* Later on, we will keep a list of registered addresses for each 
    146        adapter, and check whether they are used here */ 
    147      
    148     if (smbus_read_byte(adapter,address) < 0) { 
     197  /* Determine the chip type - only one kind supported! */ 
     198  if (kind <= 0) 
     199    kind = eeprom; 
     200 
     201  if (kind == eeprom) { 
     202    type_name = "eeprom"; 
     203    client_name = "EEPROM chip"; 
     204  } else { 
    149205#ifdef DEBUG 
    150       printk("eeprom.o: No eeprom found at: 0x%X\n",address); 
    151 #endif 
    152       continue; 
    153     } 
    154  
    155     /* Real detection code goes here */ 
    156  
    157     /* Allocate space for a new client structure */ 
    158     if (! (new_client =  kmalloc(sizeof(struct i2c_client) + 
    159                                 sizeof(struct eeprom_data), 
    160                                GFP_KERNEL))) { 
    161       err = -ENOMEM; 
    162       continue; 
    163     } 
    164  
    165     /* Find a place in our global list */ 
    166     for (i = 0; i < MAX_EEPROM_NR; i++) 
    167       if (! eeprom_list[i]) 
    168          break; 
    169     if (i == MAX_EEPROM_NR) { 
    170       err = -ENOMEM; 
    171       printk("eeprom.o: No empty slots left, recompile and heighten " 
    172              "MAX_EEPROM_NR!\n"); 
    173       goto ERROR1; 
    174     } 
    175     eeprom_list[i] = new_client; 
    176      
    177     /* Fill the new client structure with data */ 
    178     data = (struct eeprom_data *) (new_client + 1); 
    179     new_client->data = data; 
    180     new_client->id = i; 
    181     new_client->addr = address; 
    182     new_client->adapter = adapter; 
    183     new_client->driver = &eeprom_driver; 
    184     strcpy(new_client->name,"EEPROM chip"); 
    185     data->valid = 0; 
    186     data->update_lock = MUTEX; 
    187      
    188     /* Tell i2c-core a new client has arrived */ 
    189     if ((err = i2c_attach_client(new_client))) 
    190       goto ERROR2; 
    191      
    192     /* Register a new directory entry with module sensors */ 
    193     if ((err = sensors_register_entry(new_client,"eeprom", 
    194                                       eeprom_dir_table_template)) < 0) 
    195       goto ERROR3; 
    196     data->sysctl_id = err; 
    197     err = 0; 
    198  
    199     continue; 
     206    printk("eeprom.o: Internal error: unknown kind (%d)?!?",kind); 
     207#endif 
     208    goto ERROR1; 
     209  } 
     210 
     211  /* Fill in the remaining client fields and put it into the global list */ 
     212  strcpy(new_client->name,client_name); 
     213 
     214  /* Find a place in our global list */ 
     215  for (i = 0; i < MAX_EEPROM_NR; i++) 
     216    if (! eeprom_list[i]) 
     217       break; 
     218  if (i == MAX_EEPROM_NR) { 
     219    err = -ENOMEM; 
     220    printk("eeprom.o: No empty slots left, recompile and heighten " 
     221           "MAX_EEPROM_NR!\n"); 
     222    goto ERROR2; 
     223  } 
     224  eeprom_list[i] = new_client; 
     225  new_client->id = i; 
     226  data->valid = 0; 
     227  data->update_lock = MUTEX; 
     228 
     229  /* Tell the I2C layer a new client has arrived */ 
     230  if ((err = i2c_attach_client(new_client))) 
     231    goto ERROR3; 
     232 
     233  /* Register a new directory entry with module sensors */ 
     234  if ((i = sensors_register_entry(new_client,type_name, 
     235                                  eeprom_dir_table_template)) < 0) { 
     236    err = i; 
     237    goto ERROR4; 
     238  } 
     239  data->sysctl_id = i; 
     240 
     241  return 0; 
     242 
    200243/* OK, this is not exactly good programming practice, usually. But it is 
    201244   very code-efficient in this case. */ 
    202245 
     246ERROR4: 
     247  i2c_detach_client(new_client); 
    203248ERROR3: 
    204     i2c_detach_client(new_client); 
     249  for (i = 0; i < MAX_EEPROM_NR; i++) 
     250    if (new_client == eeprom_list[i]) 
     251      eeprom_list[i] = NULL; 
    205252ERROR2: 
    206     eeprom_list[i] = NULL; 
    207253ERROR1: 
    208     kfree(new_client); 
    209   } 
     254  kfree(new_client); 
     255ERROR0: 
    210256  return err; 
    211257} 
     
    214260{ 
    215261  int err,i; 
     262 
     263  sensors_deregister_entry(((struct eeprom_data *)(client->data))->sysctl_id); 
     264 
     265  if ((err = i2c_detach_client(client))) { 
     266    printk("eeprom.o: Client deregistration failed, client not detached.\n"); 
     267    return err; 
     268  } 
     269 
    216270  for (i = 0; i < MAX_EEPROM_NR; i++) 
    217271    if (client == eeprom_list[i]) 
     
    221275    return -ENOENT; 
    222276  } 
    223  
    224   sensors_deregister_entry(((struct eeprom_data *)(client->data))->sysctl_id); 
    225  
    226   if ((err = i2c_detach_client(client))) { 
    227     printk("eeprom.o: Client deregistration failed, client not detached.\n"); 
    228     return err; 
    229   } 
    230  
    231277  eeprom_list[i] = NULL; 
     278 
    232279  kfree(client); 
     280 
    233281  return 0; 
    234282} 
  • lm-sensors/trunk/kernel/chips/gl518sm.c

    r368 r371  
    3030 
    3131/* Addresses to scan */ 
    32 static unsigned short normal_i2c[] = {0x4c,0x4d,SENSORS_I2C_END}; 
     32static unsigned short normal_i2c[] = {0x2c,0x2d,SENSORS_I2C_END}; 
    3333static unsigned short normal_i2c_range[] = {SENSORS_I2C_END}; 
    3434static unsigned int normal_isa[] = {SENSORS_ISA_END};