Changeset 71

Show
Ignore:
Timestamp:
12/13/98 09:43:14 (14 years ago)
Author:
phil
Message:

(Phil) Now functional serial eeprom interface! A couple limitations:

* Only first 64 bytes are read (enough for SDRAM EEPROM data) in 16 byte
blocks (separate proc files).

* No writing to EEPROMs. It's actually quite easy to add support for
writing, but I was being very paranoid about killing my DIMMs. I may add
write support, but make it only available when a #define is specified.

Now for a user app to decode the values...

Location:
lm-sensors/trunk
Files:
2 modified

Legend:

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

    r45 r71  
    2828/* Many constants specified below */ 
    2929 
     30/* EEPROM memory types: */ 
     31#define ONE_K           1 
     32#define TWO_K           2 
     33#define FOUR_K          3 
     34#define EIGHT_K         4 
     35#define SIXTEEN_K       5 
    3036 
    3137/* Conversions */ 
    32  
    33 /* Initial values */ 
     38/* Size of EEPROM in bytes */ 
     39#define EEPROM_SIZE 16 
    3440 
    3541/* Each client has this additional data */ 
     
    4147         unsigned long last_updated; /* In jiffies */ 
    4248 
    43 /* These need to change. (PAE) */ 
    44          u16 temp,temp_os,temp_hyst; /* Register values */ 
     49         u8 data[EEPROM_SIZE]; /* Register values */ 
     50         int memtype; 
    4551}; 
    4652 
     
    6672static int eeprom_write_value(struct i2c_client *client, u8 reg, u16 value); 
    6773 
    68 static void eeprom_data(struct i2c_client *client, int operation, int ctl_name, 
     74static void eeprom_contents(struct i2c_client *client, int operation, int ctl_name, 
    6975                      int *nrels_mag, long *results); 
    7076static void eeprom_update_client(struct i2c_client *client); 
     
    8995   when a new copy is allocated. */ 
    9096static ctl_table eeprom_dir_table_template[] = { 
    91   { EEPROM_SYSCTL, "EEPROM", NULL, 0, 0644, NULL, &sensors_proc_real, 
    92     &sensors_sysctl_real, NULL, &eeprom_data }, 
     97  { EEPROM_SYSCTL1, "data0-15", NULL, 0, 0644, NULL, &sensors_proc_real, 
     98    &sensors_sysctl_real, NULL, &eeprom_contents }, 
     99  { EEPROM_SYSCTL2, "data16-31", NULL, 0, 0644, NULL, &sensors_proc_real, 
     100    &sensors_sysctl_real, NULL, &eeprom_contents }, 
     101  { EEPROM_SYSCTL3, "data32-47", NULL, 0, 0644, NULL, &sensors_proc_real, 
     102    &sensors_sysctl_real, NULL, &eeprom_contents }, 
     103  { EEPROM_SYSCTL4, "data48-63", NULL, 0, 0644, NULL, &sensors_proc_real, 
     104    &sensors_sysctl_real, NULL, &eeprom_contents }, 
    93105  { 0 } 
    94106}; 
     
    117129     impossible too (like out-of-memory). */ 
    118130      
    119   /* Serial EEPROMs for SMBus use addresses from 0x28 to 0x2f */ 
    120   for (address = 0x28; (! err) && (address <= 0x2f); address ++) { 
     131  /* Serial EEPROMs for SMBus use addresses from 0x50 to 0x57 */ 
     132  for (address = 0x50; (! err) && (address <= 0x57); address ++) { 
    121133 
    122134    /* Later on, we will keep a list of registered addresses for each 
    123135       adapter, and check whether they are used here */ 
    124136     
    125     if (smbus_read_byte_data(adapter,address,0) < 0) 
     137    if (smbus_read_byte(adapter,address) < 0) { 
     138#ifdef DEBUG 
     139      printk("eeprom.o: No eeprom found at: 0x%X\n",address); 
     140#endif 
    126141      continue; 
     142    } 
    127143 
    128144    /* Real detection code goes here */ 
     
    130146    /* Allocate space for a new client structure */ 
    131147    if (! (new_client =  kmalloc(sizeof(struct i2c_client) + 
    132                                 sizeof(struct eeprom5_data), 
     148                                sizeof(struct eeprom_data), 
    133149                               GFP_KERNEL))) { 
    134150      err = -ENOMEM; 
     
    170186    err = 0; 
    171187 
    172     /* Initialize the chip -- No init needed for EEPROMs*/ 
    173  
    174188    continue; 
    175189/* OK, this is not exactly good programming practice, usually. But it is 
     
    216230} 
    217231 
    218 /* Nothing here yet */ 
    219232void eeprom_inc_use (struct i2c_client *client) 
    220233{ 
    221 } 
    222  
    223 /* Nothing here yet */ 
     234#ifdef MODULE 
     235  MOD_INC_USE_COUNT; 
     236#endif 
     237} 
     238 
    224239void eeprom_dec_use (struct i2c_client *client) 
    225240{ 
     241#ifdef MODULE 
     242  MOD_DEC_USE_COUNT; 
     243#endif 
    226244} 
    227245 
     
    229247{ 
    230248  return (val >> 8) | (val << 8); 
    231 } 
    232  
    233 /* All registers are word-sized, except for the configuration register. 
    234    For some reason, we must swap the low and high byte, but only on  
    235    reading words?!? */ 
    236 int eeprom_read_value(struct i2c_client *client, u8 reg) 
    237 { 
    238   if (reg == EEPROM_REG_CONF) 
    239     return smbus_read_byte_data(client->adapter,client->addr,reg); 
    240   else 
    241     return swap_bytes(smbus_read_word_data(client->adapter,client->addr,reg)); 
    242249} 
    243250 
    244251/* No swapping needed here! */ 
    245252int eeprom_write_value(struct i2c_client *client, u8 reg, u16 value) 
    246 { 
     253{/* 
    247254  if (reg == EEPROM_REG_CONF) 
    248255    return smbus_write_byte_data(client->adapter,client->addr,reg,value); 
    249256  else 
    250     return smbus_write_word_data(client->adapter,client->addr,reg,value); 
     257    return smbus_write_word_data(client->adapter,client->addr,reg,value); */ 
     258     
     259    /* No writes yet (PAE) */ 
     260    return 0; 
    251261} 
    252262 
     
    254264{ 
    255265  struct eeprom_data *data = client->data; 
     266  int i; 
    256267 
    257268  down(&data->update_lock); 
     
    264275#endif 
    265276 
    266 /* Need to read the data here (PAE) */ 
    267     data->eeprom = eeprom_read_value(client,EEPROM_REG_TEMP); 
     277   if (smbus_write_byte(client->adapter,client->addr,0)) { 
     278#ifdef DEBUG 
     279    printk("eeprom read start has failed!\n"); 
     280#endif           
     281   } 
     282    for (i=0;i<EEPROM_SIZE;i++) { 
     283      data->data[i] = smbus_read_byte(client->adapter,client->addr); 
     284    } 
    268285     
    269286    data->last_updated = jiffies; 
     
    274291} 
    275292 
    276 /* ? (PAE) */ 
    277 void eeprom_data(struct i2c_client *client, int operation, int ctl_name, 
     293 
     294void eeprom_contents(struct i2c_client *client, int operation, int ctl_name, 
    278295               int *nrels_mag, long *results) 
    279296{ 
     297  int i; 
     298  int base=0; 
    280299  struct eeprom_data *data = client->data; 
     300   
     301  if (ctl_name == EEPROM_SYSCTL2){ base=16; } 
     302  if (ctl_name == EEPROM_SYSCTL3){ base=32; } 
     303  if (ctl_name == EEPROM_SYSCTL4){ base=48; } 
     304   
    281305  if (operation == SENSORS_PROC_REAL_INFO) 
    282     *nrels_mag = 1; 
     306    *nrels_mag = 0; 
    283307  else if (operation == SENSORS_PROC_REAL_READ) { 
    284308    eeprom_update_client(client); 
    285     results[0] = DATA_FROM_REG(data->temp_os); 
    286     /* ... More needs to go here (PAE) */ 
    287     *nrels_mag = 3; 
     309    /* just for testing, we won't do the whole thing */ 
     310    for (i=0; i<EEPROM_SIZE; i++) { 
     311        results[i]=data->data[i + base]; 
     312    } 
     313#ifdef DEBUG 
     314    printk("eeprom.o: 0x%X EEPROM Contents (base %d): ",client->addr,base); 
     315    for (i=0; i<EEPROM_SIZE; i++) { 
     316      printk(" 0x%X",data->data[i + base]); 
     317    } 
     318    printk(" .\n"); 
     319#endif 
     320    *nrels_mag = EEPROM_SIZE; 
    288321  } else if (operation == SENSORS_PROC_REAL_WRITE) { 
    289322 
  • lm-sensors/trunk/src/eeprom.c

    r45 r71  
    2828/* Many constants specified below */ 
    2929 
     30/* EEPROM memory types: */ 
     31#define ONE_K           1 
     32#define TWO_K           2 
     33#define FOUR_K          3 
     34#define EIGHT_K         4 
     35#define SIXTEEN_K       5 
    3036 
    3137/* Conversions */ 
    32  
    33 /* Initial values */ 
     38/* Size of EEPROM in bytes */ 
     39#define EEPROM_SIZE 16 
    3440 
    3541/* Each client has this additional data */ 
     
    4147         unsigned long last_updated; /* In jiffies */ 
    4248 
    43 /* These need to change. (PAE) */ 
    44          u16 temp,temp_os,temp_hyst; /* Register values */ 
     49         u8 data[EEPROM_SIZE]; /* Register values */ 
     50         int memtype; 
    4551}; 
    4652 
     
    6672static int eeprom_write_value(struct i2c_client *client, u8 reg, u16 value); 
    6773 
    68 static void eeprom_data(struct i2c_client *client, int operation, int ctl_name, 
     74static void eeprom_contents(struct i2c_client *client, int operation, int ctl_name, 
    6975                      int *nrels_mag, long *results); 
    7076static void eeprom_update_client(struct i2c_client *client); 
     
    8995   when a new copy is allocated. */ 
    9096static ctl_table eeprom_dir_table_template[] = { 
    91   { EEPROM_SYSCTL, "EEPROM", NULL, 0, 0644, NULL, &sensors_proc_real, 
    92     &sensors_sysctl_real, NULL, &eeprom_data }, 
     97  { EEPROM_SYSCTL1, "data0-15", NULL, 0, 0644, NULL, &sensors_proc_real, 
     98    &sensors_sysctl_real, NULL, &eeprom_contents }, 
     99  { EEPROM_SYSCTL2, "data16-31", NULL, 0, 0644, NULL, &sensors_proc_real, 
     100    &sensors_sysctl_real, NULL, &eeprom_contents }, 
     101  { EEPROM_SYSCTL3, "data32-47", NULL, 0, 0644, NULL, &sensors_proc_real, 
     102    &sensors_sysctl_real, NULL, &eeprom_contents }, 
     103  { EEPROM_SYSCTL4, "data48-63", NULL, 0, 0644, NULL, &sensors_proc_real, 
     104    &sensors_sysctl_real, NULL, &eeprom_contents }, 
    93105  { 0 } 
    94106}; 
     
    117129     impossible too (like out-of-memory). */ 
    118130      
    119   /* Serial EEPROMs for SMBus use addresses from 0x28 to 0x2f */ 
    120   for (address = 0x28; (! err) && (address <= 0x2f); address ++) { 
     131  /* Serial EEPROMs for SMBus use addresses from 0x50 to 0x57 */ 
     132  for (address = 0x50; (! err) && (address <= 0x57); address ++) { 
    121133 
    122134    /* Later on, we will keep a list of registered addresses for each 
    123135       adapter, and check whether they are used here */ 
    124136     
    125     if (smbus_read_byte_data(adapter,address,0) < 0) 
     137    if (smbus_read_byte(adapter,address) < 0) { 
     138#ifdef DEBUG 
     139      printk("eeprom.o: No eeprom found at: 0x%X\n",address); 
     140#endif 
    126141      continue; 
     142    } 
    127143 
    128144    /* Real detection code goes here */ 
     
    130146    /* Allocate space for a new client structure */ 
    131147    if (! (new_client =  kmalloc(sizeof(struct i2c_client) + 
    132                                 sizeof(struct eeprom5_data), 
     148                                sizeof(struct eeprom_data), 
    133149                               GFP_KERNEL))) { 
    134150      err = -ENOMEM; 
     
    170186    err = 0; 
    171187 
    172     /* Initialize the chip -- No init needed for EEPROMs*/ 
    173  
    174188    continue; 
    175189/* OK, this is not exactly good programming practice, usually. But it is 
     
    216230} 
    217231 
    218 /* Nothing here yet */ 
    219232void eeprom_inc_use (struct i2c_client *client) 
    220233{ 
    221 } 
    222  
    223 /* Nothing here yet */ 
     234#ifdef MODULE 
     235  MOD_INC_USE_COUNT; 
     236#endif 
     237} 
     238 
    224239void eeprom_dec_use (struct i2c_client *client) 
    225240{ 
     241#ifdef MODULE 
     242  MOD_DEC_USE_COUNT; 
     243#endif 
    226244} 
    227245 
     
    229247{ 
    230248  return (val >> 8) | (val << 8); 
    231 } 
    232  
    233 /* All registers are word-sized, except for the configuration register. 
    234    For some reason, we must swap the low and high byte, but only on  
    235    reading words?!? */ 
    236 int eeprom_read_value(struct i2c_client *client, u8 reg) 
    237 { 
    238   if (reg == EEPROM_REG_CONF) 
    239     return smbus_read_byte_data(client->adapter,client->addr,reg); 
    240   else 
    241     return swap_bytes(smbus_read_word_data(client->adapter,client->addr,reg)); 
    242249} 
    243250 
    244251/* No swapping needed here! */ 
    245252int eeprom_write_value(struct i2c_client *client, u8 reg, u16 value) 
    246 { 
     253{/* 
    247254  if (reg == EEPROM_REG_CONF) 
    248255    return smbus_write_byte_data(client->adapter,client->addr,reg,value); 
    249256  else 
    250     return smbus_write_word_data(client->adapter,client->addr,reg,value); 
     257    return smbus_write_word_data(client->adapter,client->addr,reg,value); */ 
     258     
     259    /* No writes yet (PAE) */ 
     260    return 0; 
    251261} 
    252262 
     
    254264{ 
    255265  struct eeprom_data *data = client->data; 
     266  int i; 
    256267 
    257268  down(&data->update_lock); 
     
    264275#endif 
    265276 
    266 /* Need to read the data here (PAE) */ 
    267     data->eeprom = eeprom_read_value(client,EEPROM_REG_TEMP); 
     277   if (smbus_write_byte(client->adapter,client->addr,0)) { 
     278#ifdef DEBUG 
     279    printk("eeprom read start has failed!\n"); 
     280#endif           
     281   } 
     282    for (i=0;i<EEPROM_SIZE;i++) { 
     283      data->data[i] = smbus_read_byte(client->adapter,client->addr); 
     284    } 
    268285     
    269286    data->last_updated = jiffies; 
     
    274291} 
    275292 
    276 /* ? (PAE) */ 
    277 void eeprom_data(struct i2c_client *client, int operation, int ctl_name, 
     293 
     294void eeprom_contents(struct i2c_client *client, int operation, int ctl_name, 
    278295               int *nrels_mag, long *results) 
    279296{ 
     297  int i; 
     298  int base=0; 
    280299  struct eeprom_data *data = client->data; 
     300   
     301  if (ctl_name == EEPROM_SYSCTL2){ base=16; } 
     302  if (ctl_name == EEPROM_SYSCTL3){ base=32; } 
     303  if (ctl_name == EEPROM_SYSCTL4){ base=48; } 
     304   
    281305  if (operation == SENSORS_PROC_REAL_INFO) 
    282     *nrels_mag = 1; 
     306    *nrels_mag = 0; 
    283307  else if (operation == SENSORS_PROC_REAL_READ) { 
    284308    eeprom_update_client(client); 
    285     results[0] = DATA_FROM_REG(data->temp_os); 
    286     /* ... More needs to go here (PAE) */ 
    287     *nrels_mag = 3; 
     309    /* just for testing, we won't do the whole thing */ 
     310    for (i=0; i<EEPROM_SIZE; i++) { 
     311        results[i]=data->data[i + base]; 
     312    } 
     313#ifdef DEBUG 
     314    printk("eeprom.o: 0x%X EEPROM Contents (base %d): ",client->addr,base); 
     315    for (i=0; i<EEPROM_SIZE; i++) { 
     316      printk(" 0x%X",data->data[i + base]); 
     317    } 
     318    printk(" .\n"); 
     319#endif 
     320    *nrels_mag = EEPROM_SIZE; 
    288321  } else if (operation == SENSORS_PROC_REAL_WRITE) { 
    289322